-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allow to enforce Stack link on request chain #1575
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -974,7 +974,7 @@ | |
Promise.resolve( | ||
executeQueryFromState(this.store.getState(), queryDefinition) | ||
) | ||
: () => this.requestQuery(queryDefinition) | ||
: () => this.requestQuery(queryDefinition, options) | ||
const response = await this._promiseCache.exec(requestFn, () => | ||
stringify(queryDefinition) | ||
) | ||
|
@@ -1083,7 +1083,7 @@ | |
options.as || this.queryIdGenerator.generateId(mutationDefinition) | ||
this.dispatch(initMutation(mutationId, mutationDefinition)) | ||
try { | ||
const response = await this.requestMutation(mutationDefinition) | ||
const response = await this.requestMutation(mutationDefinition, options) | ||
this.dispatch( | ||
receiveMutationResult( | ||
mutationId, | ||
|
@@ -1109,8 +1109,8 @@ | |
* @param {QueryDefinition} definition QueryDefinition to be executed | ||
* @returns {Promise<import("./types").ClientResponse>} | ||
*/ | ||
async requestQuery(definition) { | ||
const mainResponse = await this.chain.request(definition) | ||
async requestQuery(definition, options) { | ||
const mainResponse = await this.chain.request(definition, options) | ||
|
||
await this.persistVirtualDocuments(definition, mainResponse.data) | ||
|
||
|
@@ -1128,7 +1128,7 @@ | |
* Save the document or array of documents into the persisted storage (if any) | ||
* | ||
* @private | ||
* @param {CozyClientDocument | Array<CozyClientDocument>} data - Document or array of documents to be saved | ||
Check warning on line 1131 in packages/cozy-client/src/CozyClient.js GitHub Actions / Build and publish
|
||
* @returns {Promise<void>} | ||
*/ | ||
async persistVirtualDocuments(definition, data) { | ||
|
@@ -1260,7 +1260,7 @@ | |
} | ||
} | ||
|
||
async requestMutation(definition) { | ||
async requestMutation(definition, options) { | ||
if (Array.isArray(definition)) { | ||
const [first, ...rest] = definition | ||
const firstResponse = await this.requestMutation(first) | ||
|
@@ -1273,7 +1273,7 @@ | |
) | ||
return firstResponse | ||
} | ||
return this.chain.request(definition) | ||
return this.chain.request(definition, options) | ||
} | ||
|
||
getIncludesRelationships(queryDefinition) { | ||
|
@@ -1877,8 +1877,8 @@ | |
* @template {string} T | ||
* | ||
* @param {string} slug - the cozy-app's slug containing the setting (can be 'instance' for global settings) | ||
* @param {T[]} keys - The names of the settings to retrieve | ||
* @returns {Promise<Record<T, any>>} - The value of the requested setting | ||
*/ | ||
async getSettings(slug, keys) { | ||
return getSettings(this, slug, keys) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,7 +410,11 @@ class PouchLink extends CozyLink { | |
return !!this.getPouch(impactedDoctype) | ||
} | ||
|
||
async request(operation, result = null, forward = doNothing) { | ||
async request(operation, options, result = null, forward = doNothing) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed here |
||
if (options?.forceStack) { | ||
return forward(operation, options) | ||
} | ||
|
||
const doctype = getDoctypeFromOperation(operation) | ||
|
||
if (!this.pouches) { | ||
|
@@ -420,7 +424,7 @@ class PouchLink extends CozyLink { | |
) | ||
} | ||
|
||
return forward(operation) | ||
return forward(operation, options) | ||
} | ||
|
||
if (this.pouches.getSyncStatus(doctype) === 'not_synced') { | ||
|
@@ -429,7 +433,7 @@ class PouchLink extends CozyLink { | |
`Tried to access local ${doctype} but Cozy Pouch is not synced yet. Forwarding the operation to next link` | ||
) | ||
} | ||
return forward(operation) | ||
return forward(operation, options) | ||
} | ||
|
||
if (await this.needsToWaitWarmup(doctype)) { | ||
|
@@ -438,7 +442,7 @@ class PouchLink extends CozyLink { | |
`Tried to access local ${doctype} but not warmuped yet. Forwarding the operation to next link` | ||
) | ||
} | ||
return forward(operation) | ||
return forward(operation, options) | ||
} | ||
|
||
// Forwards if doctype not supported | ||
|
@@ -448,11 +452,11 @@ class PouchLink extends CozyLink { | |
`The doctype '${doctype}' is not supported. Forwarding the operation to next link` | ||
) | ||
} | ||
return forward(operation) | ||
return forward(operation, options) | ||
} | ||
|
||
if (operation.mutationType) { | ||
return this.executeMutation(operation, result, forward) | ||
return this.executeMutation(operation, options, result, forward) | ||
} else { | ||
return this.executeQuery(operation) | ||
} | ||
|
@@ -753,7 +757,7 @@ class PouchLink extends CozyLink { | |
return jsonResult | ||
} | ||
|
||
async executeMutation(mutation, result, forward) { | ||
async executeMutation(mutation, options, result, forward) { | ||
const markName = this.performanceApi.mark('executeMutation') | ||
let pouchRes | ||
switch (mutation.mutationType) { | ||
|
@@ -773,7 +777,7 @@ class PouchLink extends CozyLink { | |
pouchRes = await this.addReferencesTo(mutation) | ||
break | ||
default: | ||
return forward(mutation, result) | ||
return forward(mutation, options, result) | ||
} | ||
|
||
const jsonResult = jsonapi.fromPouchResult({ | ||
|
Unchanged files with check annotations Beta
* | ||
* @param {CozyClient} client - Cozy client instance | ||
* @param {string} slug - the cozy-app's slug containing the setting (can be 'instance' for global settings) | ||
* @param {T[]} keys - The names of the settings to retrieve | ||
* @returns {Promise<Record<T, any>>} - The values of the requested settings | ||
*/ | ||
export const getSettings = async (client, slug, keys) => { | ||
const query = getQuery(slug) | ||
* | ||
* @param {string} slug - the cozy-app's slug containing the setting (can be 'instance' for global settings) | ||
* @param {Object} currentSettings - the Setting object (ideally from a `client.query()` or a `useQuery()` and normalized using `normalizeSettings`) | ||
* @param {Record<string, unknown>} items - The new values for the settings | ||
* @returns {Object} a new Setting object containing the new value | ||
*/ | ||
export const editSettings = (slug, currentSettings, items) => { | ||
* | ||
* @template {string} T | ||
* | ||
* @param {Record<T, any>} settings - the Setting object (ideally from a `client.query()` or a `useQuery()` and normalized using `normalizeSettings`) | ||
* @param {T[]} keys - The names of the settings to extract | ||
* @returns {Record<T, any>} - Dictionnary containing the values for the requested keys | ||
*/ | ||
export const extractKeys = (settings, keys) => { | ||
let result = {} |
* @param {object=} Options.queryDefinition custom Querydef | ||
* @param {object=} Options.queryOptions custom QueryOpts | ||
* @param {object=} Options.storeQueries custome StoreQueries | ||
* @returns | ||
Check warning on line 17 in packages/cozy-client/src/hooks/useQuery.spec.jsx GitHub Actions / Build and publish
|
||
*/ | ||
const setupQuery = ({ | ||
customClient, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No jsdoc for the
options
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed here