-
Notifications
You must be signed in to change notification settings - Fork 27
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
Initial file storage support #52
base: main
Are you sure you want to change the base?
Conversation
9c64bc1
to
a471c0e
Compare
Thank you for this contribution @kav ! 🙏 We need to keep in mind that
Based on @slax57 comment, we could implement it as follow: Expose a helper method to upload files: export const storeInSupabase = async ({
supabaseClient,
bucket,
data,
}: {
supabaseClient: SupabaseClient;
bucket: string;
data: any;
}) => {
// Upload file to the bucket
return Promise.resolve('newFiles');
}; With this in place, the user can use this method in the export const dataProvider = withLifecycleCallbacks(
supabaseDataProvider({
instanceUrl: REACT_APP_SUPABASE_URL,
apiKey: REACT_APP_SUPABASE_KEY,
supabaseClient,
}),
[
{
resource: 'posts',
beforeSave: async (data: any, dataProvider: any) => {
const newFiles = await storeInSupabase({
supabaseClient,
bucket: 'my-bucket',
data,
});
return { ...data, ...newFiles };
},
},
]
); We could even go further by exposing another helper to directly improve the export const addUploadCapabilities = ({
supabaseClient,
dataProvider,
resource,
}: {
supabaseClient: SupabaseClient;
dataProvider: DataProvider;
resource: string;
}) =>
withLifecycleCallbacks(dataProvider, [
{
resource,
beforeUpdate: async params => {
await storeInSupabase({
supabaseClient,
bucket: 'my-bucket',
data: params,
});
return params;
},
},
]); With this in place the user can add the capabilities to upload file as follow to their const dataProvider = addUploadCapabilities({
supabaseClient,
dataProvider,
resource: 'posts',
}); What do you think about that? This code is not irrevocable, feel free to update it. Do not forget to document it as well please 😄 Thanks again for contributing! |
@@ -36,7 +45,50 @@ export const supabaseDataProvider = ({ | |||
primaryKeys, | |||
schema, | |||
}; | |||
return postgrestRestProvider(config); | |||
return withLifecycleCallbacks(postgrestRestProvider(config), [ |
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.
polish: We should provide some customization to users who use this library. This implementation does not allow this.
See this PR discussion for more information.
Yes, I am deeply aware of the necessary thought that must go into building libraries and frameworks for a wide range of use cases. This was the point of my initial issue and this draft. Namely; discussing the areas where we need to allow customization to make it both easy and flexible enough for all use cases of supabase storage while note interfering with folks not using supabase storage at all. I think a key goal here for me is that users of the
It's a no-op if they don't provide the That said I'm with you that a user might want to handle some files via this mechanism and some via some other file management system so further granularity on which files to upload is definitely needed. It's possible a user could handle that by wrapping the existing implentation with a
Good point, given the user might want to handle different resources with a different mechanism, I suspect this is the best point to handle the attachment of the hooks. I can add the ability to set resources to use the file upload. I suspect this will justify the Counter argument to all that is as the last stop before
This is an excellent point, I'll look at a good place to put this but I suspect something similar to the existing functions makes sense. Do you have any further thoughts there? To the opening objective; I don't know that the I think allowing composition of One key bit of missing functionality, and unfortunately I think it's intrinsic to the existing LifecycleHooks implementation is that we don't offer any ability to handle the previous file when a user changes it. Obviously the user can structure their files in such a way that it can be inferred but that's something to consider. Related question is upsert, likely we'll need an option with a sensible default there. |
Don't use the |
Initial implementation for review. @slax57 what do you think about something like this?
adds options methods
Fixes: #51