-
-
Notifications
You must be signed in to change notification settings - Fork 160
Transition to TypeScript #93
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
Conversation
Implementation is in, all that's left to do is tests (+fixes) and docs.
Amazing PR Bobbie - will take me a while to go through but I'll get through this asap to make sure you're not blocked by anything |
The But yes, it's safe to use
Overall I agree. On the postgrest docs we recommend using pg-safeupdate to prevent whole table UPDATEs/DELETEs. However there's some value on doing this client-side(if for some reason the pg instance doesn't have safeupdate enabled). Perhaps |
👍 Good to know. Thanks Steve!
Interesting, I didn't know pg-safeupdate was created because of destructive UPDATE/DELETE on PostgREST. I feel slightly more open to adding the prevention, though I prefer to do it here instead of supabase-js. The solution I prefer, if we go the preventing route, is to add pg-safeupdate to supabase/postgres. |
Love this. Amazing.
I originally started with this and pulled back - can't remember why, but if you have it working and you're happy then let's go ahead
Yes let's remove
Such a good find. Nice one
These convenience functions - they improve DX. The filter especially when you want to build readable nested filters. eg.
Yes you can either URI encode it or make it
Sounds good. I do like Steve's approach of keeping it out of I like the model of making the peripheral libraries (postgrest, auth, realtime) utilities, then sprinkling some opinions, enrichments, and best practices to More editsAnt & I did a long session on friday with @thorwebdev. We decided that we will from now on return errors rather than throwing errors: There's no right or wrong here, we've chose one that fits our style. This will be a breaking change, but one that we should make now since there are other breaking changes. |
Gotcha 👍.
I don't think we can handle this exclusively on the supabase-js side, but I can add an option in postgrest-js's
Will reply in the linked issue. |
Hmm.. no, that would give a parse error. What's the use case of |
That was the plan, but on second thought that wasn't necessary. |
f61429b
to
dd40349
Compare
It's ready! Some notes: |
wooo! 🎉 I'll get into this today Re: Typedoc - I will consolidate all of the Typedocs into our main docs (and add enrichments): https://supabase-spec.netlify.app/ref/gotrue/signup/ Basically I use TypeDoc -> output to JSON, then I add a complementary YAML file for enrichments (examples in different languages). The typedoc is great, but doesn't really help newbies to understand how to actually use the library. Also I would prefer a single source of truth for our docs so the community doesn't have to maintain separate docs |
@soedirgo can you please add this command to run on whenever the docs are built too?
|
👌Updated the test runner & docs (spec.json). |
That worked surprisingly well. OK I'm really happy with the work you've done here - it's the perfect baseline to start implementing gotrue-js. What are the next steps after merging in? There are breaking changes right? |
Yep, we'll have to squash this PR into a One note though: as the docs is deployed using GitHub Pages, the first commit will fail, then we need to select the |
OK great - let's pull the trigger on this one. Can you handle this? Let me know if you need any help ⚡ Amazing work as usual Bobbie |
@kiwicopple in hindsight, these are a lot to go through at once, so I should've gone through them one by one as they come up 🤦♂️. Sorry!
What kind of change does this PR introduce?
As per title. Closes #84.
Additional context
This PR introduces a rewrite of postgrest-js in TypeScript. There are some decisions I made that warrants a second opinion, so I'm listing all the important changes here:
Use Fetch polyfill in place of Superagent
Main discussion here.
Target CommonJS & ES6 for builds (no UMD, no bundlers)
The goal of targeting UMD is for easy import with
<script>
in browsers. Apparently, this job is already done for us: jspm provides npm packages as fully optimized ES6 modules (with source maps, code-splitting, etc.). Here's an example using their sandbox, or alternatively you can serve an HTML file with the following content:Use Jest for testing in place of Mocha & doctests-js
The main argument is it has snapshot testing built-in, which plays really well for data-oriented libraries like this. It allows easy testing of whole responses instead of single properties, keeping tests concise.
As for doctests-js, I really like the idea, and it's present in Rust's doc comments which I use in postgrest-rs, but I don't think it plays well with TypeScript.
Use TypeDoc for docs in the
gh-pages
branchWe previously used JSDoc, and TypeDoc is just that, but for TypeScript. It'll live in a separate branch to keep the repo clean, and automated with
semantic-release
.Enforce method chaining order: CRUD (e.g.
select
), filters (e.g.eq
), transforms (e.g.single
)Arguments for this can be found here.
Remove guard for using
update
/delete
without filters & "type error" responsesThis one is opiniated, but I think we should operate on the principle of least surprise, and not add "surprising" behaviors on top of PostgREST. Following PostgREST's approach, destructive operations should be mentioned in the docs (and made to stand out), but not prevented.
Standardize optional parameters
I'm taking the approach used by
insert
: required parameters are individual arguments, "options" live in a single object which becomes an optional last parameter. Example:insert({ name: 'Supabase', location: 'Singapore' }, { upsert: true, ... })
. Affected methods:order
:ascending
,nullsFirst
,foreignTable
(for foreign table columns)limit
:foreignTable
range
:foreignTable
fts
,plfts
,phfts
,wfts
:config
Remove handling of the
%
characterPostgREST docs instructs using
*
to escape%
. Apparently this isn't necessary? The following line works:P.S. %25 is the percent-encoding for
%
. Need to confirm this with @steve-chavez.On
filter
andmatch
I'm keeping these for backward compatibility, but they don't do anything beyond what filter methods already do, so I'm not sure what to do with them.