-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[RFC & POC] Hiding Wasp's private API from users #1922
base: main
Are you sure you want to change the base?
Changes from all commits
7635266
e765e8c
0b19844
0a98ae9
6532167
392ef1f
da039f2
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ const defaultViteConfig = { | |
outDir: "build", | ||
}, | ||
resolve: { | ||
conditions: ["client-runtime"], | ||
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. This is where we set the framework runtime's condition string, thus gaining access to the SDK's private API. |
||
// These packages rely on a single instance per page. Not dedpuing them | ||
// causes runtime errors (e.g., hook rule violation in react, QueryClient | ||
// instance error in react-query, Invariant Error in react-router-dom). | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{{={= =}=}} | ||
import { deserialize as superjsonDeserialize } from 'superjson' | ||
import { useQuery, addMetadataToQuery } from 'wasp/client/operations' | ||
import { useQuery } from '../client/operations' | ||
import { addMetadataToQuery } from '../client/operations/queries/core' | ||
Comment on lines
+3
to
+4
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. I've updated all the import paths inside the SDK have been converted from package imports to relative imports (also accounting for the updated paths). |
||
import { api, handleApiError } from 'wasp/client/api' | ||
import { HttpMethod } from 'wasp/client' | ||
import type { AuthUser } from './types' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
"types": "tsc --declaration --emitDeclarationOnly --stripInternal --declarationDir dist" | ||
}, | ||
"exports": { | ||
"./client/operations/queryClient": { | ||
"client-runtime": "./dist/client/operations/queryClient.js" | ||
}, | ||
Comment on lines
+12
to
+14
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. This how we expose the SDK's private API to the framework, while hiding it from the user. Unfortunately, we can't do: "exports": {
"client-runtime": {
// private API
},
"default": {
// public API
} Because once Vite finds an object with a matching condition, it won't trace back if it doesn't find a required symbol inside it:
Which means we would have to repeat the entire public API twice. "exports": {
"client-runtime": {
// private API
// public API
},
"default": {
// public API
} It isn't quite as nice, but works. We can still decide which approach do we want to take. 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. Great stuff! I didn't know that |
||
{=! todo(filip): Check all exports when done with SDK generation =} | ||
{=! Some of the statements in the comments might become incorrect. =} | ||
{=! "our code" means: "web-app", "server" or "SDK", or "some combination of the three". =} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
All SDK imports in the framework code have been updated according to the new code organization.