-
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
Conversation
3b397e6
to
4de4b1a
Compare
4aba700
to
a47af8c
Compare
0d2969b
to
b3815e2
Compare
b8c1989
to
d233213
Compare
b3815e2
to
c41c4a6
Compare
d233213
to
7f3835c
Compare
c41c4a6
to
2ecef7a
Compare
7f3835c
to
71f2363
Compare
2ecef7a
to
95729c0
Compare
71f2363
to
7de1401
Compare
95729c0
to
13bb965
Compare
7de1401
to
11c1865
Compare
if (this.isOnline && !(await this.isOnline())) { | ||
return forward(operation) | ||
async request(operation, options, result, forward) { | ||
if (this.isOnline && !(await this.isOnline()) && !options?.forceStack) { |
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.
It might be worth it to reverse the conditions here, by evaluation forceStack
first: if the options?.forceStack
is true, there is no need to call the this.isOnline()
, and thus we save a network call
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
async request(operation, result, forward) { | ||
if (this.isOnline && !(await this.isOnline())) { | ||
return forward(operation) | ||
async request(operation, options, result, forward) { |
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
@@ -410,7 +410,7 @@ 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 comment
The reason will be displayed to describe this comment to others. Learn more.
If the forceStack: true
option is given here, we should forward the request
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
ee1b801
to
fabe643
Compare
11c1865
to
c6fda04
Compare
fabe643
to
2d7973e
Compare
c6fda04
to
99d56c8
Compare
When doing a backup, we don't want instable network to make the CozyClient use local PouchLink for some queries that need to read files paths In cozy/cozy-client#1575 we implemented the `forceStack` option that allows to enforce the usage of StackLink instead of other links that may retrieve local incomplete data This commit enforce the stack on backup related queries Related PR: cozy/cozy-client#1575
8007276
to
d1b66bb
Compare
In previous commits we implemented supports for offline mode through CozyPouchLink and FlagshipLink Since this feature, the StackLink is able to check for internet reachability by using the `isOnline()` method. When no internet is detected, then the request is forwarded to the next link (i.e. the CozyPouchLink) In some scenario we may want to prevent that behavior. This is the case when we are working on a feature that cannot work without internet access, or when the query's result is expected to contain data that is injected by the cozy-stack (and so that is not available in the local Pouch database) To make this possible we introduce the `forceStack` parameter that can be set in the query options When set to `true` then the StackLink will not attempt to forward the request when offline, instead it will still attempt to do the request and throw We chose to attempt the request instead of directly throwing an error in order to prevent hypothetical scenario where `isOnline()` method returns false even if internet is reachable BREAKING CHANGE: CozyLink's request methods now takes an additional `options` argument that can be used to enforce usage of Stack link. Although `.request()` is meant to be an internal API, if your code calls it, you'll want to introduce a new argument for `options`. This is also the case if you instanciate a new CozyLink with a handler argument for `request` Before: ``` // Initialization new CozyLink((operation, result = '', forward) => { return forward(operation, result + 'foo') }) // Call link.request(operation) // Call with result and forward link.request(operation, null, () => { /* do stuff */ }) ``` After: ``` // Initialization new CozyLink((operation, options, result = '', forward) => { return forward(operation, options, result + 'foo') }) // Call link.request(operation, options) // Call with result and forward link.request(operation, options, null, () => { /* do stuff */ }) ```
d1b66bb
to
e00d74d
Compare
`cozy-client` and `cozy-pouch-link` has been upgraded to `52.0.0` in order to retrieve the ability to enforce StackLink usage for a query Related PR: cozy/cozy-client#1575
When doing a backup, we don't want instable network to make the CozyClient use local PouchLink for some queries that need to read files paths In cozy/cozy-client#1575 we implemented the `forceStack` option that allows to enforce the usage of StackLink instead of other links that may retrieve local incomplete data This commit enforce the stack on backup related queries Related PR: cozy/cozy-client#1575
`cozy-client` and `cozy-pouch-link` has been upgraded to `52.0.0` in order to retrieve the ability to enforce StackLink usage for a query Related PR: cozy/cozy-client#1575
When doing a backup, we don't want instable network to make the CozyClient use local PouchLink for some queries that need to read files paths In cozy/cozy-client#1575 we implemented the `forceStack` option that allows to enforce the usage of StackLink instead of other links that may retrieve local incomplete data This commit enforce the stack on backup related queries Related PR: cozy/cozy-client#1575
`cozy-client` and `cozy-pouch-link` has been upgraded to `52.0.0` in order to retrieve the ability to enforce StackLink usage for a query Related PR: cozy/cozy-client#1575
When doing a backup, we don't want instable network to make the CozyClient use local PouchLink for some queries that need to read files paths In cozy/cozy-client#1575 we implemented the `forceStack` option that allows to enforce the usage of StackLink instead of other links that may retrieve local incomplete data This commit enforce the stack on backup related queries Related PR: cozy/cozy-client#1575
`cozy-client` and `cozy-pouch-link` has been upgraded to `52.0.0` in order to retrieve the ability to enforce StackLink usage for a query Related PR: cozy/cozy-client#1575
When doing a backup, we don't want instable network to make the CozyClient use local PouchLink for some queries that need to read files paths In cozy/cozy-client#1575 we implemented the `forceStack` option that allows to enforce the usage of StackLink instead of other links that may retrieve local incomplete data This commit enforce the stack on backup related queries Related PR: cozy/cozy-client#1575
`cozy-client` and `cozy-pouch-link` has been upgraded to `52.0.0` in order to retrieve the ability to enforce StackLink usage for a query Related PR: cozy/cozy-client#1575
When doing a backup, we don't want instable network to make the CozyClient use local PouchLink for some queries that need to read files paths In cozy/cozy-client#1575 we implemented the `forceStack` option that allows to enforce the usage of StackLink instead of other links that may retrieve local incomplete data This commit enforce the stack on backup related queries Related PR: cozy/cozy-client#1575
`cozy-client` and `cozy-pouch-link` has been upgraded to `52.0.0` in order to retrieve the ability to enforce StackLink usage for a query Related PR: cozy/cozy-client#1575
When doing a backup, we don't want instable network to make the CozyClient use local PouchLink for some queries that need to read files paths In cozy/cozy-client#1575 we implemented the `forceStack` option that allows to enforce the usage of StackLink instead of other links that may retrieve local incomplete data This commit enforce the stack on backup related queries Related PR: cozy/cozy-client#1575
`cozy-client` and `cozy-pouch-link` has been upgraded to `52.0.0` in order to retrieve the ability to enforce StackLink usage for a query Related PR: cozy/cozy-client#1575
When doing a backup, we don't want instable network to make the CozyClient use local PouchLink for some queries that need to read files paths In cozy/cozy-client#1575 we implemented the `forceStack` option that allows to enforce the usage of StackLink instead of other links that may retrieve local incomplete data This commit enforce the stack on backup related queries Related PR: cozy/cozy-client#1575
`cozy-client` and `cozy-pouch-link` has been upgraded to `52.0.0` in order to retrieve the ability to enforce StackLink usage for a query Related PR: cozy/cozy-client#1575
When doing a backup, we don't want instable network to make the CozyClient use local PouchLink for some queries that need to read files paths In cozy/cozy-client#1575 we implemented the `forceStack` option that allows to enforce the usage of StackLink instead of other links that may retrieve local incomplete data This commit enforce the stack on backup related queries Related PR: cozy/cozy-client#1575
In previous commits we implemented supports for offline mode through CozyPouchLink and FlagshipLink
Since this feature, the StackLink is able to check for internet reachability by using the
isOnline()
method. When no internet is detected, then the request is forwarded to the next link (i.e. the CozyPouchLink)In some scenario we may want to prevent that behavior. This is the case when we are working on a feature that cannot work without internet access, or when the query's result is expected to contain data that is injected by the cozy-stack (and so that is not available in the local Pouch database)
To make this possible we introduce the
forceStack
parameter that can be set in the query optionsWhen set to
true
then the StackLink will not attempt to forward the request when offline, instead it will still attempt to do the request and throwWe chose to attempt the request instead of directly throwing an error in order to prevent hypothetical scenario where
isOnline()
method returns false even if internet is reachableBREAKING CHANGE: CozyLink's request methods now takes an additional
options
argument that can be used to enforce usage of Stack link. Although.request()
is meant to be an internal API, if your code calls it, you'll want to introduce a new argument foroptions
. This is also the case if you instanciate a new CozyLink with a handler argument forrequest
Before:
After:
Related PR: cozy/cozy-flagship-app#1269