-
Notifications
You must be signed in to change notification settings - Fork 14
feat: FileCollection uses proxy for shared drives #1604
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: FileCollection uses proxy for shared drives #1604
Conversation
I like it like this. It implies that shared drives have exactly same route except the prefix but if it is what will happen 👍 |
I think it's a good idea to avoid creating a new collection 👍
About the first point, maybe we could pass the prefix to the collection methods options, and do |
|
I think it's better to avoid this (that's one of the main advantages of cozy-client to avoid the need to know route pathes). I would like that the user of cozy client (using a collection or a query) only has to know and pass a So we would do something like :
And then maybe inside cozy-client inside the file collection, we convert the sharedDriveId to a prefix to keep the code clean and generic inside cozy-client. About the 2. (using a query), I do not know what is best between passing it:
It makes sense for me that it is inside the query definition because it changes the data fetched and not the way we fetch data but I do not know what it implies/if it is possible. edit: In every case for using a query, to not break Pouch, Pouch (cozy-pouch-link) should have a notion of shared drive :
We need to persist data (the shared drive id) that does not exist in io.cozy.files document on stack side |
150847b
to
218538b
Compare
1cfb8b1
to
92d7a89
Compare
I think we are close to finish this PR 🎉 What I did in last commits : It seems to work because when doing a Two questions :
|
92d7a89
to
758d712
Compare
What about
I used |
sharingId, | ||
...rawOptions | ||
} = query | ||
let options = { ...rawOptions, driveId: undefined } |
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.
Why do you need to set the driveId
here? I would prefer to make it appear only when necessary
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.
From memory it was to satisfy the type checker.
* Options that can be passed to FileCollection's constructor | ||
* | ||
* @typedef {object} FileCollectionOptions | ||
* @property {string} [driveId] - ID of the shared drive targeted by the collection |
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.
Do we have some doc about the shared drive somewhere? Typically from the stack side?
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.
We do have documentation in cozy-stack
about shared drives.
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 is inside the PR for the moment cozy/cozy-stack#4511
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.
I was wondering why I didn't find any code :)
Ok, so the stack's doc link could be added to the jsdoc eventually
expect(stackClient.collection).toHaveBeenCalledWith( | ||
'io.cozy.todos', | ||
expect.anything() | ||
) |
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.
Since this commit actually fix tests from previous commit, it should be rebased within the commit where it breaks
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.
I would even say squashed.
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.
Yes, I meant squashed 👍
* @returns {QueryDefinition} The QueryDefinition object. | ||
*/ | ||
sharingId(id) { | ||
setSharingId(id) { |
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.
I don't really like this naming TBH. I understand that we technically set the sharingId to the QueryDefinition, but here the semantic should not be on the technical set, but rather from the querying perspective. As a developer, I would not understand doing Q('io.cozy.files').setById(id)
to query a file by its id.
Likewise, I would prefer sharingById
here
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.
I suggested inSharing(id)
.
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.
I'm not a big fan of the in
, that sounds a bit too functional to me.
Should we settle the final decision with a trial by combat? Or maybe let @zatteo have the final word?
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.
Oh @zatteo already called it
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.
Sorry I answered before seeing @taratatach comment...
I think inSharing
is more explicit but like you said it is more "functional", and cozy-client API and naming is not functional so maybe we should stick with sharingById
.
To make changes to files on a shared drive, clients have to call their stack via proxied routes (e.g. `/sharings/drives/:id/_changes` for the changes feed of the given shared drive). Instead of creating a separate collection for that we enable passing options to a collection and specifically a `driveId` option to the `FileCollection`. This presence of a `driveId` option will change the prefix of all routes called by the `FileCollection` from `/files` to `/sharings/drives/${driveId}`. Since `uri` encodes the content of template literals placeholders, passing the prefix via a placeholder would result in an invalid path. Therefore we prepend the prefix out of routes literals.
758d712
to
79990f4
Compare
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.
can be squashed, otherwise, ok for me, thanks for the work!
With the contribution of @paultranvan for the PouchLink part. We add a new method to the QueryDefinition dsl so we can scope queries to documents targeted by a given sharing. This will be used for `io.cozy.files` documents in shared drives at first. e.g.: `client.query(Q('io.cozy.files').sharingId('xyz'))` Since `cozy-stack` returns the shared drive id of `io.cozy.files` documents in their `driveId` attribute, we can use it to query local documents via PouchLink. They're not saved in CouchDB though so StackLink passes the id as argument to the file collection which will target the shared drives' API.
dsl method was called sharingId and QueryDefinition class attribute was also called sharingId.
So we can chain setSharingId in whatever order we want we writing a query.
79990f4
to
9ed3e6a
Compare
To make changes to files on a shared drive, clients have to call their
stack via proxied routes (e.g.
/sharings/drives/:id/_changes
for thechanges feed of the given shared drive).
Instead of creating a separate collection for that we enable passing
options to a collection and specifically a
driveId
option to theFileCollection
.This presence of a
driveId
option will change the prefix of allroutes called by the
FileCollection
from/files
to/sharings/drives/${driveId}
.