diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/files.manifest b/waspc/e2e-test/test-outputs/waspBuild-golden/files.manifest index e9b129701a..ecf07831c5 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/files.manifest +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/files.manifest @@ -5,13 +5,13 @@ waspBuild/.wasp/build/db/schema.prisma waspBuild/.wasp/build/installedFullStackNpmDependencies.json waspBuild/.wasp/build/server/.npmrc waspBuild/.wasp/build/server/README.md +waspBuild/.wasp/build/server/nodemon.json waspBuild/.wasp/build/server/package.json waspBuild/.wasp/build/server/src/app.js waspBuild/.wasp/build/server/src/config.js waspBuild/.wasp/build/server/src/core/AuthError.js waspBuild/.wasp/build/server/src/core/HttpError.js waspBuild/.wasp/build/server/src/dbClient.js -waspBuild/.wasp/build/server/src/ext-src/jsconfig.json waspBuild/.wasp/build/server/src/jobs/core/Job.js waspBuild/.wasp/build/server/src/jobs/core/SubmittedJob.js waspBuild/.wasp/build/server/src/jobs/core/allJobs.js @@ -20,9 +20,9 @@ waspBuild/.wasp/build/server/src/jobs/core/pgBoss/pgBossJob.js waspBuild/.wasp/build/server/src/jobs/core/simpleJob.js waspBuild/.wasp/build/server/src/routes/index.js waspBuild/.wasp/build/server/src/routes/operations/index.js -waspBuild/.wasp/build/server/src/server.js -waspBuild/.wasp/build/server/src/shared/jsconfig.json +waspBuild/.wasp/build/server/src/server.ts waspBuild/.wasp/build/server/src/utils.js +waspBuild/.wasp/build/server/tsconfig.json waspBuild/.wasp/build/web-app/.npmrc waspBuild/.wasp/build/web-app/README.md waspBuild/.wasp/build/web-app/netlify.toml @@ -30,32 +30,36 @@ waspBuild/.wasp/build/web-app/package.json waspBuild/.wasp/build/web-app/public/favicon.ico waspBuild/.wasp/build/web-app/public/index.html waspBuild/.wasp/build/web-app/public/manifest.json +waspBuild/.wasp/build/web-app/src/actions/core.d.ts waspBuild/.wasp/build/web-app/src/actions/core.js -waspBuild/.wasp/build/web-app/src/actions/index.js +waspBuild/.wasp/build/web-app/src/actions/index.ts waspBuild/.wasp/build/web-app/src/api.js waspBuild/.wasp/build/web-app/src/config.js waspBuild/.wasp/build/web-app/src/ext-src/Main.css -waspBuild/.wasp/build/web-app/src/ext-src/MainPage.js -waspBuild/.wasp/build/web-app/src/ext-src/jsconfig.json +waspBuild/.wasp/build/web-app/src/ext-src/MainPage.tsx +waspBuild/.wasp/build/web-app/src/ext-src/react-app-env.d.ts waspBuild/.wasp/build/web-app/src/ext-src/waspLogo.png waspBuild/.wasp/build/web-app/src/index.js waspBuild/.wasp/build/web-app/src/logo.png waspBuild/.wasp/build/web-app/src/operations/index.js waspBuild/.wasp/build/web-app/src/operations/resources.js waspBuild/.wasp/build/web-app/src/operations/updateHandlersMap.js +waspBuild/.wasp/build/web-app/src/queries/core.d.ts waspBuild/.wasp/build/web-app/src/queries/core.js +waspBuild/.wasp/build/web-app/src/queries/index.d.ts waspBuild/.wasp/build/web-app/src/queries/index.js waspBuild/.wasp/build/web-app/src/queryClient.js waspBuild/.wasp/build/web-app/src/router.js waspBuild/.wasp/build/web-app/src/serviceWorker.js -waspBuild/.wasp/build/web-app/src/shared/jsconfig.json waspBuild/.wasp/build/web-app/src/utils.js +waspBuild/.wasp/build/web-app/tsconfig.json waspBuild/.wasproot waspBuild/main.wasp waspBuild/src/.waspignore waspBuild/src/client/Main.css -waspBuild/src/client/MainPage.js -waspBuild/src/client/jsconfig.json +waspBuild/src/client/MainPage.tsx +waspBuild/src/client/react-app-env.d.ts +waspBuild/src/client/tsconfig.json waspBuild/src/client/waspLogo.png -waspBuild/src/server/jsconfig.json -waspBuild/src/shared/jsconfig.json +waspBuild/src/server/tsconfig.json +waspBuild/src/shared/tsconfig.json diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums index d12f5aa1d3..1a1e0387ff 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/.waspchecksums @@ -41,12 +41,19 @@ ], "e14514b8b152dd2160a217d8fc66a710c8607c4ed1441a2148a0770701818249" ], + [ + [ + "file", + "server/nodemon.json" + ], + "5d0e1103bbe7c29a7b3137a57345f8eeb4ccd8a2128d636cc1b2bd81cf348a86" + ], [ [ "file", "server/package.json" ], - "15dfb8bf4e0dd58b9964cbcab2f02b0c977a802c88c4140861755f969d5697f9" + "597461e990d47093b89e2cdd239c6e9bc6bedef29b9cdf51b357ff3ee5217de2" ], [ [ @@ -83,13 +90,6 @@ ], "20c67ca197da3de2d37528ceaff2e40af910be8177f346c6d5c2b2f983810c43" ], - [ - [ - "file", - "server/src/ext-src/jsconfig.json" - ], - "4130060d02d39d5fdc11bdb288cfe08d36dc89be29ade017b16db6477e63c47a" - ], [ [ "file", @@ -123,7 +123,7 @@ "file", "server/src/jobs/core/pgBoss/pgBossJob.js" ], - "532ed0f34a2011cff2a9c43b712a513ba505e77d896455d6c7f36add6f88741d" + "ff6040d051c916eb080a2f2c37fd5135f588782387faeae51115d1a7abd1ad8b" ], [ [ @@ -149,23 +149,23 @@ [ [ "file", - "server/src/server.js" + "server/src/server.ts" ], - "e19bdae598265cbe2457ff1e2d8524aa821666482cb7d21644e290a68daf94a5" + "c6114654819216004f0ef4a8771a0c1213c655cfd41760fbd835077c53a6b6ba" ], [ [ "file", - "server/src/shared/jsconfig.json" + "server/src/utils.js" ], - "6972bc64315755788fd02be62c44ea8ffb60dd874b863fca2878f6160ab4b0e2" + "68a5794f55e24b303d81456a1181a3a2cd70773f6ebc4e7a63dac064834aa8e9" ], [ [ "file", - "server/src/utils.js" + "server/tsconfig.json" ], - "68a5794f55e24b303d81456a1181a3a2cd70773f6ebc4e7a63dac064834aa8e9" + "3038f152754646d2c46de78e099e9e6129bfb2541e4dccd37a05a5632ab4d838" ], [ [ @@ -200,7 +200,7 @@ "file", "web-app/package.json" ], - "228080234154d37b357013646aff651c65a415e3870054929f2fd2cc66af0f8c" + "26c45eb78e59df9f2c9e1779106e8b444087a4ab7865c8a1d0209d0e4023f030" ], [ [ @@ -223,6 +223,13 @@ ], "696886c4dd2bb66df380e2a9ebf07d54fe39b25af968aeea090ed6fb528d402e" ], + [ + [ + "file", + "web-app/src/actions/core.d.ts" + ], + "c18e166c8f43bd3a6a8d78f8fc2f51fe82e956cd71b3464c59076f8dec660b24" + ], [ [ "file", @@ -233,9 +240,9 @@ [ [ "file", - "web-app/src/actions/index.js" + "web-app/src/actions/index.ts" ], - "7da2524a6920c46aada7e60e29fbe24d0e45e4bfcf7bf3044d16d11ab89a965e" + "bc520b1d83577c6640472dd5c110228a3617b050d3a4d091495ec065c57011bc" ], [ [ @@ -261,16 +268,16 @@ [ [ "file", - "web-app/src/ext-src/MainPage.js" + "web-app/src/ext-src/MainPage.tsx" ], "c9ed9b5271f648715373095f43d60a2ab3e47f159c6dd6f3337ed22e5b73e80c" ], [ [ "file", - "web-app/src/ext-src/jsconfig.json" + "web-app/src/ext-src/react-app-env.d.ts" ], - "06804c81fa3b227c1b3a04e950f8db9ed85bf41d042b90e8e8332856016e113f" + "c9e89cb25e83121c0c451125de7a0b0569161e2bf18f83bc5f69836403910744" ], [ [ @@ -314,6 +321,13 @@ ], "07a9933a771853585fd2fc49c3dcb9f1cad947acb2168580c835fae25620fa9f" ], + [ + [ + "file", + "web-app/src/queries/core.d.ts" + ], + "f0b289140e92738451be386ca73a2fd1c84e9951eb2f1b9c6c09dfa3079d0c74" + ], [ [ "file", @@ -321,6 +335,13 @@ ], "2daf5b414722204281d65e954ce862a6fc586e8907b202800694909d23957c5e" ], + [ + [ + "file", + "web-app/src/queries/index.d.ts" + ], + "3eb32c063fc77fa5aa3f3b3a12c51ca8a52fc3cd0de21f4e9463a56cc374003c" + ], [ [ "file", @@ -340,7 +361,7 @@ "file", "web-app/src/router.js" ], - "dd6f5f5c6981df1935c02437d7a6ae343841300c3f7e99b0ad6ca62e95071421" + "65a91308a13f2c8444e3ad7372c1fca85a194b85e8f8f7d11613f78fcfe7af6f" ], [ [ @@ -352,15 +373,15 @@ [ [ "file", - "web-app/src/shared/jsconfig.json" + "web-app/src/utils.js" ], - "6972bc64315755788fd02be62c44ea8ffb60dd874b863fca2878f6160ab4b0e2" + "0ae6e53a050dbc6b7166aedfd5b076c2cab524c4d6aff884dc6902b178148815" ], [ [ "file", - "web-app/src/utils.js" + "web-app/tsconfig.json" ], - "0ae6e53a050dbc6b7166aedfd5b076c2cab524c4d6aff884dc6902b178148815" + "0612639442958ae18a96d651a6c385fba1a682f04d09e293efd380006fc4df99" ] ] \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedFullStackNpmDependencies.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedFullStackNpmDependencies.json index 0da1a29518..69a7a39ba5 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedFullStackNpmDependencies.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/installedFullStackNpmDependencies.json @@ -1 +1 @@ -{"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"express","version":"~4.18.1"},{"name":"morgan","version":"~1.10.0"},{"name":"@prisma/client","version":"4.5.0"},{"name":"jsonwebtoken","version":"^8.5.1"},{"name":"secure-password","version":"^4.0.0"},{"name":"dotenv","version":"16.0.2"},{"name":"helmet","version":"^6.0.0"},{"name":"patch-package","version":"^6.4.7"},{"name":"uuid","version":"^9.0.0"},{"name":"lodash","version":"^4.17.21"}],"devDependencies":[{"name":"nodemon","version":"^2.0.19"},{"name":"standard","version":"^17.0.0"},{"name":"prisma","version":"4.5.0"}]},"npmDepsForWebApp":{"dependencies":[{"name":"axios","version":"^0.27.2"},{"name":"react","version":"^17.0.2"},{"name":"react-dom","version":"^17.0.2"},{"name":"@tanstack/react-query","version":"^4.13.0"},{"name":"react-router-dom","version":"^5.3.3"},{"name":"react-scripts","version":"5.0.1"}],"devDependencies":[]}} \ No newline at end of file +{"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"express","version":"~4.18.1"},{"name":"morgan","version":"~1.10.0"},{"name":"@prisma/client","version":"4.5.0"},{"name":"jsonwebtoken","version":"^8.5.1"},{"name":"secure-password","version":"^4.0.0"},{"name":"dotenv","version":"16.0.2"},{"name":"helmet","version":"^6.0.0"},{"name":"patch-package","version":"^6.4.7"},{"name":"uuid","version":"^9.0.0"},{"name":"lodash","version":"^4.17.21"}],"devDependencies":[{"name":"nodemon","version":"^2.0.19"},{"name":"standard","version":"^17.0.0"},{"name":"prisma","version":"4.5.0"},{"name":"typescript","version":"^4.8.4"},{"name":"@types/node","version":"^18.11.9"}]},"npmDepsForWebApp":{"dependencies":[{"name":"axios","version":"^0.27.2"},{"name":"react","version":"^17.0.2"},{"name":"react-dom","version":"^17.0.2"},{"name":"@tanstack/react-query","version":"^4.13.0"},{"name":"react-router-dom","version":"^5.3.3"},{"name":"react-scripts","version":"5.0.1"}],"devDependencies":[{"name":"typescript","version":"^4.8.4"},{"name":"@types/react","version":"^18.0.25"},{"name":"@types/react-dom","version":"^18.0.8"},{"name":"@types/react-router-dom","version":"^5.3.3"}]}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/nodemon.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/nodemon.json new file mode 100644 index 0000000000..92d00152d9 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/nodemon.json @@ -0,0 +1,9 @@ +{ + "env": { + "NODE_ENV": "development" + }, + "watch": [ + "src/" + ], + "ext": "ts,mts,js,mjs,json" +} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/package.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/package.json index 9b25d4cb40..e37ba66de1 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/package.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/package.json @@ -14,9 +14,11 @@ "uuid": "^9.0.0" }, "devDependencies": { + "@types/node": "^18.11.9", "nodemon": "^2.0.19", "prisma": "4.5.0", - "standard": "^17.0.0" + "standard": "^17.0.0", + "typescript": "^4.8.4" }, "engineStrict": true, "engines": { @@ -34,13 +36,15 @@ }, "private": true, "scripts": { + "build": "npx tsc", + "build-and-start": "npm run build && npm run start", "db-migrate-dev": "prisma migrate dev --schema=../db/schema.prisma", "db-migrate-prod": "prisma migrate deploy --schema=../db/schema.prisma", "postinstall": "patch-package", "standard": "standard", - "start": "nodemon -r dotenv/config ./src/server.js", - "start-production": "NODE_ENV=production node ./src/server.js" + "start": "NODE_PATH=dist node dist/server.js", + "start-production": "NODE_ENV=production npm run start", + "watch": "nodemon -r dotenv/config --exec 'npm run build-and-start || exit 1'" }, - "type": "module", "version": "0.0.0" } diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/ext-src/jsconfig.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/ext-src/jsconfig.json deleted file mode 100644 index 9e996fc5df..0000000000 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/ext-src/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, Try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/jobs/core/pgBoss/pgBossJob.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/jobs/core/pgBoss/pgBossJob.js index a9ac57c367..b9267c967a 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/jobs/core/pgBoss/pgBossJob.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/jobs/core/pgBoss/pgBossJob.js @@ -55,7 +55,7 @@ class PgBossJob extends Job { * @param {object} jobArgs - The job arguments supplied by the user for their perform callback. * @param {object} jobOptions - pg-boss specific options for `boss.send()`, which can override their defaultJobOptions. */ - async submit(jobArgs, jobOptions) { + async submit(jobArgs, jobOptions = {}) { const boss = await pgBossStarted const jobId = await boss.send(this.jobName, jobArgs, { ...this.#defaultJobOptions, ...(this.#startAfter && { startAfter: this.#startAfter }), ...jobOptions }) diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/server.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/server.ts similarity index 95% rename from waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/server.js rename to waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/server.ts index 747b00a051..e4b32230de 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/server.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/server.ts @@ -15,7 +15,7 @@ const startServer = async () => { server.listen(port) - server.on('error', (error) => { + server.on('error', (error: NodeJS.ErrnoException) => { if (error.syscall !== 'listen') throw error const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port // handle specific listen errors with friendly messages diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/tsconfig.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/tsconfig.json new file mode 100644 index 0000000000..97afa9c21e --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + // Enable default imports in TypeScript. + "esModuleInterop": true, + "module": "commonjs", + "moduleResolution": "node", + "outDir": "dist", + "allowJs": true, + // Enable source map for debugging + "sourceMap": true + } +} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/package.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/package.json index 13db738e73..98c5dcbdd7 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/package.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/package.json @@ -19,7 +19,12 @@ "react-router-dom": "^5.3.3", "react-scripts": "5.0.1" }, - "devDependencies": {}, + "devDependencies": { + "@types/react": "^18.0.25", + "@types/react-dom": "^18.0.8", + "@types/react-router-dom": "^5.3.3", + "typescript": "^4.8.4" + }, "engineStrict": true, "engines": { "node": "^18.12.0", diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/actions/core.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/actions/core.d.ts new file mode 100644 index 0000000000..1171c7e1b4 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/actions/core.d.ts @@ -0,0 +1,3 @@ +export type Action = (args?: Input) => Promise; + +export function createAction(actionRoute: string, entitiesUsed: unknown[]): Action diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/actions/index.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/actions/index.ts similarity index 62% rename from waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/actions/index.js rename to waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/actions/index.ts index cf97f19264..85dba33baa 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/actions/index.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/actions/index.ts @@ -1,93 +1,57 @@ import { + QueryClient, + QueryKey, useMutation, + UseMutationOptions, useQueryClient, } from '@tanstack/react-query' - -export { configureQueryClient } from '../queryClient' +import { Action } from './core'; /** * An options object passed into the `useAction` hook and used to enhance the * action with extra options. * - * @typedef {Object} ActionOptions - * @property {PublicOptimisticUpdateDefinition[]} optimisticUpdates */ +export type ActionOptions = { + optimisticUpdates: OptimisticUpdateDefinition[]; +} /** * A documented (public) way to define optimistic updates. - * - * @typedef {Object} PublicOptimisticUpdateDefinition - * @property {GetQuerySpecifier} querySpecifier - * @property {UpdateQuery} updateQuery */ +export type OptimisticUpdateDefinition = { + getQuerySpecifier: GetQuerySpecifier; + updateQuery: UpdateQuery; +} /** * A function that takes an item and returns a Wasp Query specifier. - * - * @callback GetQuerySpecifier - * @param {T} item - * @returns {QuerySpecifier} */ +export type GetQuerySpecifier = (item: Item) => QuerySpecifier /** * A function that takes an item and the previous state of the cache, and returns * the desired (new) state of the cache. - * - * @callback UpdateQuery - * @param {T} item - * @param {T[]} oldData - * @returns {T[]} */ +export type UpdateQuery = (item: ActionInput, oldData: CacheItem[]) => CacheItem[] /** * A public query specifier used for addressing Wasp queries. See our docs for details: * https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * - * @typedef {any[]} QuerySpecifier - */ - -/** - * An internal (undocumented, private, desugared) way of defining optimistic updates. - * - * @typedef {Object} InternalOptimisticUpdateDefinition - * @property {GetQuerySpecifier} querySpecifier - * @property {UpdateQuery} updateQuery - */ - -/** - * An UpdateQuery function "instantiated" with a specific item. It only takes - * the current state of the cache and returns the desired (new) state of the - * cache. - * - * @callback SpecificUpdateQuery - * @param {any[]} oldData - */ - -/** - * A specific, "instantiated" optimistic update definition which contains a - * fully-constructed query key and a specific update function. - * - * @typedef {Object} SpecificOptimisticUpdateDefinition - * @property {QueryKey} queryKey - * @property {SpecificUpdateQuery} updateQuery -*/ - -/** - * An array React Query uses to address queries. See their docs for details: - * https://react-query-v3.tanstack.com/guides/query-keys#array-keys. - * - * @typedef {any[]} QueryKey */ - +export type QuerySpecifier = any[] /** * A hook for adding extra behavior to a Wasp Action (e.g., optimistic updates). * * @param actionFn The Wasp Action you wish to enhance/decorate. - * @param {ActionOptions} actionOptions An options object for enhancing/decorating the given Action. + * @param actionOptions An options object for enhancing/decorating the given Action. * @returns A decorated Action with added behavior but an unchanged API. */ -export function useAction(actionFn, actionOptions) { +export function useAction( + actionFn: (item: ActionInput) => Promise, + actionOptions: ActionOptions +): typeof actionFn { const queryClient = useQueryClient(); let mutationFn = actionFn @@ -110,14 +74,49 @@ export function useAction(actionFn, actionOptions) { } /** - * Translates/Desugars a public optimistic update definition object into a definition object our - * system uses internally. + * An internal (undocumented, private, desugared) way of defining optimistic updates. + */ +type InternalOptimisticUpdateDefinition = { + getQueryKey: (item: ActionInput) => QueryKey, + updateQuery: UpdateQuery; + +} + +/** + * An UpdateQuery function "instantiated" with a specific item. It only takes + * the current state of the cache and returns the desired (new) state of the + * cache. + */ +type SpecificUpdateQuery = (oldData: Item[]) => Item[] + +/** + * A specific, "instantiated" optimistic update definition which contains a + * fully-constructed query key and a specific update function. + */ +type SpecificOptimisticUpdateDefinition = { + queryKey: QueryKey; + updateQuery: SpecificUpdateQuery; +} + +type InternalAction = Action & { + internal( + item: Input, + optimisticUpdateDefinitions: SpecificOptimisticUpdateDefinition[] + ): Promise +} + +/** + * Translates/Desugars a public optimistic update definition object into a + * definition object our system uses internally. * - * @param {PublicOptimisticUpdateDefinition} publicOptimisticUpdateDefinition An optimistic update definition - * object that's a part of the public API: https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * @returns {InternalOptimisticUpdateDefinition} An internally-used optimistic update definition object. + * @param publicOptimisticUpdateDefinition An optimistic update definition + * object that's a part of the public API: + * https://wasp-lang.dev/docs/language/features#the-useaction-hook. + * @returns An internally-used optimistic update definition object. */ -function translateToInternalDefinition(publicOptimisticUpdateDefinition) { +function translateToInternalDefinition( + publicOptimisticUpdateDefinition: OptimisticUpdateDefinition +): InternalOptimisticUpdateDefinition { const { getQuerySpecifier, updateQuery } = publicOptimisticUpdateDefinition const definitionErrors = [] @@ -141,17 +140,19 @@ function translateToInternalDefinition(publicOptimisticUpdateDefinition) { * Creates a function that performs an action while telling it about the * optimistic updates it caused. * - * @param actionFn - The Wasp Action. - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinitions - The optimisitc updates the - * action causes. - * @returns A + * @param actionFn The Wasp Action. + * @param optimisticUpdateDefinitions The optimisitc updates the action causes. + * @returns An decorated action which performs optimistic updates. */ -function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) { +function makeOptimisticUpdateMutationFn( + actionFn: Action, + optimisticUpdateDefinitions: InternalOptimisticUpdateDefinition[] +): typeof actionFn { return function performActionWithOptimisticUpdates(item) { const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map( generalDefinition => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item) ) - return actionFn.internal(item, specificOptimisticUpdateDefinitions) + return (actionFn as InternalAction).internal(item, specificOptimisticUpdateDefinitions) } } @@ -163,13 +164,18 @@ function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) { * optimistic updates definition. Check their docs for details: * https://tanstack.com/query/v4/docs/guides/optimistic-updates?from=reactQueryV3&original=https://react-query-v3.tanstack.com/guides/optimistic-updates * - * @param {Object} queryClient The QueryClient instance used by React Query. - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinitions A list containing internal optimistic updates definition objects - * (i.e., a list where each object carries the instructions for performing particular optimistic update). - * @returns {Object} An object containing 'onMutate' and 'onError' functions corresponding to the given optimistic update - * definitions (check the docs linked above for details). + * @param queryClient The QueryClient instance used by React Query. + * @param optimisticUpdateDefinitions A list containing internal optimistic + * updates definition objects (i.e., a list where each object carries the + * instructions for performing particular optimistic update). + * @returns An object containing 'onMutate' and 'onError' functions + * corresponding to the given optimistic update definitions (check the docs + * linked above for details). */ -function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) { +function makeRqOptimisticUpdateOptions( + queryClient: QueryClient, + optimisticUpdateDefinitions: InternalOptimisticUpdateDefinition[] +): Pick { async function onMutate(item) { const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map( generalDefinition => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item) @@ -187,7 +193,7 @@ function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) const previousData = new Map() specificOptimisticUpdateDefinitions.forEach(({ queryKey, updateQuery }) => { // Snapshot the currently cached value. - const previousDataForQuery = queryClient.getQueryData(queryKey) + const previousDataForQuery: CacheItem[] = queryClient.getQueryData(queryKey) // Attempt to optimistically update the cache using the new value. try { @@ -227,13 +233,16 @@ function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) * uses a closure over the updated item to construct an item-specific query key * (e.g., useful when the query key depends on an ID). * - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinition The general, "uninstantiated" optimistic + * @param optimisticUpdateDefinition The general, "uninstantiated" optimistic * update definition with a function for constructing the query key. - * @param item The item triggering the Action/optimistic update (i.e., the argument passed to the Action). - * @returns {SpecificOptimisticUpdateDefinition} A specific optimistic update definition - * which corresponds to the provided definition and closes over the provided item. + * @param item The item triggering the Action/optimistic update (i.e., the + * argument passed to the Action). + * @returns A specific optimistic update definition which corresponds to the + * provided definition and closes over the provided item. */ -function getOptimisticUpdateDefinitionForSpecificItem(optimisticUpdateDefinition, item) { +function getOptimisticUpdateDefinitionForSpecificItem( + optimisticUpdateDefinition: InternalOptimisticUpdateDefinition, item: ActionInput +): SpecificOptimisticUpdateDefinition { const { getQueryKey, updateQuery } = optimisticUpdateDefinition return { queryKey: getQueryKey(item), @@ -244,11 +253,11 @@ function getOptimisticUpdateDefinitionForSpecificItem(optimisticUpdateDefinition /** * Translates a Wasp query specifier to a query cache key used by React Query. * - * @param {QuerySpecifier} querySpecifier A query specifier that's a part of the public API: + * @param querySpecifier A query specifier that's a part of the public API: * https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * @returns {QueryKey} A cache key React Query internally uses for addressing queries. + * @returns A cache key React Query internally uses for addressing queries. */ -function getRqQueryKeyFromSpecifier(querySpecifier) { +function getRqQueryKeyFromSpecifier(querySpecifier: QuerySpecifier): QueryKey { const [queryFn, ...otherKeys] = querySpecifier return [...queryFn.queryCacheKey, ...otherKeys] } diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/ext-src/MainPage.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/ext-src/MainPage.tsx similarity index 100% rename from waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/ext-src/MainPage.js rename to waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/ext-src/MainPage.tsx diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/ext-src/react-app-env.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/ext-src/react-app-env.d.ts new file mode 100644 index 0000000000..e80934ce3a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/ext-src/react-app-env.d.ts @@ -0,0 +1,60 @@ +declare module '*.avif' { + const src: string; + export default src; +} + +declare module '*.bmp' { + const src: string; + export default src; +} + +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + import * as React from 'react'; + + export const ReactComponent: React.FunctionComponent & { title?: string }>; + + const src: string; + export default src; +} + +declare module '*.module.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/queries/core.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/queries/core.d.ts new file mode 100644 index 0000000000..edde495db4 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/queries/core.d.ts @@ -0,0 +1,3 @@ +export type Query = (args: Input) => Promise + +export function createQuery(queryRoute: string, entitiesUsed: any[]): Query diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/queries/index.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/queries/index.d.ts new file mode 100644 index 0000000000..a331fa9d73 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/queries/index.d.ts @@ -0,0 +1,8 @@ +import { UseQueryResult } from "@tanstack/react-query"; +import { OutputHTMLAttributes } from "react"; +import { Query } from "./core"; + +export function useQuery( + queryFn: Query, + queryFnArgs?: Input, options?: any +): UseQueryResult diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/router.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/router.js index c783ed20ac..7d3f45f130 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/router.js +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/router.js @@ -2,7 +2,7 @@ import React from 'react' import { Route, BrowserRouter as Router } from 'react-router-dom' -import MainPage from "./ext-src/MainPage.js" +import MainPage from "./ext-src/MainPage" const router = ( diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/tsconfig.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/tsconfig.json new file mode 100644 index 0000000000..3fab473aae --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es2018", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx" + }, + "include": [ + "src" + ] +} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/main.wasp b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/main.wasp index fca91dfa57..bacfd82077 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/main.wasp +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/main.wasp @@ -8,5 +8,5 @@ app waspBuild { route RootRoute { path: "/", to: MainPage } page MainPage { - component: import Main from "@client/MainPage.js" + component: import Main from "@client/MainPage" } diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/MainPage.js b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/MainPage.tsx similarity index 100% rename from waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/MainPage.js rename to waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/MainPage.tsx diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/react-app-env.d.ts b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/react-app-env.d.ts new file mode 100644 index 0000000000..e80934ce3a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/react-app-env.d.ts @@ -0,0 +1,60 @@ +declare module '*.avif' { + const src: string; + export default src; +} + +declare module '*.bmp' { + const src: string; + export default src; +} + +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + import * as React from 'react'; + + export const ReactComponent: React.FunctionComponent & { title?: string }>; + + const src: string; + export default src; +} + +declare module '*.module.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/tsconfig.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/tsconfig.json new file mode 100644 index 0000000000..34c23b30ce --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/tsconfig.json @@ -0,0 +1,39 @@ +{ + "compilerOptions": { + // JSX support + "jsx": "preserve", + // Enable default imports in TypeScript. + "esModuleInterop": true, + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + // The following settings enable IDE support in user-provided source files. + // Editing them might break features like import autocompletion and + // definition lookup. Don't change them unless you know what you're doing. + // + // The relative path to the generated web app's root directory. This must be + // set to define the "paths" option. + "baseUrl": "../../.wasp/out/web-app/", + "paths": { + // Resolve all "@wasp" imports to the generated source code. + "@wasp/*": [ + "src/*" + ], + // Resolve all non-relative imports to the correct node module. Source: + // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping + "*": [ + // Start by looking for the definiton inside the node modules root + // directory... + "node_modules/*", + // ... If that fails, try to find it inside definitely-typed type + // definitions. + "node_modules/@types/*" + ] + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/web-app/node_modules/@types"] + } +} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/server/jsconfig.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/server/jsconfig.json deleted file mode 100644 index 9e996fc5df..0000000000 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/server/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, Try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/ext-src/jsconfig.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/server/tsconfig.json similarity index 75% rename from waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/ext-src/jsconfig.json rename to waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/server/tsconfig.json index e9b5551fd7..8d313c4516 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/ext-src/jsconfig.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/server/tsconfig.json @@ -1,12 +1,15 @@ { "compilerOptions": { - // The following settings enable IDE support in user-provided source files. + // Enable default imports in TypeScript. + "esModuleInterop": true, + "allowJs": true, + // The following settings enable IDE support in user-provided source files. // Editing them might break features like import autocompletion and // definition lookup. Don't change them unless you know what you're doing. // // The relative path to the generated web app's root directory. This must be // set to define the "paths" option. - "baseUrl": "../../.wasp/out/web-app/", + "baseUrl": "../../.wasp/out/server/", "paths": { // Resolve all "@wasp" imports to the generated source code. "@wasp/*": [ @@ -22,6 +25,8 @@ // definitions. "node_modules/@types/*" ] - } + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/server/node_modules/@types"] } } diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/shared/tsconfig.json similarity index 74% rename from waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/shared/jsconfig.json rename to waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/shared/tsconfig.json index 0c4e7f7eb1..20fcac8431 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/shared/jsconfig.json +++ b/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/shared/tsconfig.json @@ -1,12 +1,15 @@ { "compilerOptions": { + // Enable default imports in TypeScript. + "esModuleInterop": true, + "allowJs": true, // The following settings enable IDE support in user-provided source files. // Editing them might break features like import autocompletion and // definition lookup. Don't change them unless you know what you're doing. // // The relative path to the generated web app's root directory. This must be // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", + "baseUrl": "../../.wasp/out/server/", "paths": { // Resolve all non-relative imports to the correct node module. Source: // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping @@ -18,6 +21,8 @@ // definitions. "node_modules/@types/*" ] - } + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/server/node_modules/@types"] } } diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/files.manifest b/waspc/e2e-test/test-outputs/waspCompile-golden/files.manifest index d9afa537f1..81da44be9f 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/files.manifest +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/files.manifest @@ -5,13 +5,13 @@ waspCompile/.wasp/out/db/schema.prisma waspCompile/.wasp/out/installedFullStackNpmDependencies.json waspCompile/.wasp/out/server/.npmrc waspCompile/.wasp/out/server/README.md +waspCompile/.wasp/out/server/nodemon.json waspCompile/.wasp/out/server/package.json waspCompile/.wasp/out/server/src/app.js waspCompile/.wasp/out/server/src/config.js waspCompile/.wasp/out/server/src/core/AuthError.js waspCompile/.wasp/out/server/src/core/HttpError.js waspCompile/.wasp/out/server/src/dbClient.js -waspCompile/.wasp/out/server/src/ext-src/jsconfig.json waspCompile/.wasp/out/server/src/jobs/core/Job.js waspCompile/.wasp/out/server/src/jobs/core/SubmittedJob.js waspCompile/.wasp/out/server/src/jobs/core/allJobs.js @@ -20,9 +20,9 @@ waspCompile/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js waspCompile/.wasp/out/server/src/jobs/core/simpleJob.js waspCompile/.wasp/out/server/src/routes/index.js waspCompile/.wasp/out/server/src/routes/operations/index.js -waspCompile/.wasp/out/server/src/server.js -waspCompile/.wasp/out/server/src/shared/jsconfig.json +waspCompile/.wasp/out/server/src/server.ts waspCompile/.wasp/out/server/src/utils.js +waspCompile/.wasp/out/server/tsconfig.json waspCompile/.wasp/out/web-app/.npmrc waspCompile/.wasp/out/web-app/README.md waspCompile/.wasp/out/web-app/netlify.toml @@ -30,32 +30,36 @@ waspCompile/.wasp/out/web-app/package.json waspCompile/.wasp/out/web-app/public/favicon.ico waspCompile/.wasp/out/web-app/public/index.html waspCompile/.wasp/out/web-app/public/manifest.json +waspCompile/.wasp/out/web-app/src/actions/core.d.ts waspCompile/.wasp/out/web-app/src/actions/core.js -waspCompile/.wasp/out/web-app/src/actions/index.js +waspCompile/.wasp/out/web-app/src/actions/index.ts waspCompile/.wasp/out/web-app/src/api.js waspCompile/.wasp/out/web-app/src/config.js waspCompile/.wasp/out/web-app/src/ext-src/Main.css -waspCompile/.wasp/out/web-app/src/ext-src/MainPage.js -waspCompile/.wasp/out/web-app/src/ext-src/jsconfig.json +waspCompile/.wasp/out/web-app/src/ext-src/MainPage.tsx +waspCompile/.wasp/out/web-app/src/ext-src/react-app-env.d.ts waspCompile/.wasp/out/web-app/src/ext-src/waspLogo.png waspCompile/.wasp/out/web-app/src/index.js waspCompile/.wasp/out/web-app/src/logo.png waspCompile/.wasp/out/web-app/src/operations/index.js waspCompile/.wasp/out/web-app/src/operations/resources.js waspCompile/.wasp/out/web-app/src/operations/updateHandlersMap.js +waspCompile/.wasp/out/web-app/src/queries/core.d.ts waspCompile/.wasp/out/web-app/src/queries/core.js +waspCompile/.wasp/out/web-app/src/queries/index.d.ts waspCompile/.wasp/out/web-app/src/queries/index.js waspCompile/.wasp/out/web-app/src/queryClient.js waspCompile/.wasp/out/web-app/src/router.js waspCompile/.wasp/out/web-app/src/serviceWorker.js -waspCompile/.wasp/out/web-app/src/shared/jsconfig.json waspCompile/.wasp/out/web-app/src/utils.js +waspCompile/.wasp/out/web-app/tsconfig.json waspCompile/.wasproot waspCompile/main.wasp waspCompile/src/.waspignore waspCompile/src/client/Main.css -waspCompile/src/client/MainPage.js -waspCompile/src/client/jsconfig.json +waspCompile/src/client/MainPage.tsx +waspCompile/src/client/react-app-env.d.ts +waspCompile/src/client/tsconfig.json waspCompile/src/client/waspLogo.png -waspCompile/src/server/jsconfig.json -waspCompile/src/shared/jsconfig.json +waspCompile/src/server/tsconfig.json +waspCompile/src/shared/tsconfig.json diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums index e9f745f006..66eefa8749 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/.waspchecksums @@ -41,12 +41,19 @@ ], "e14514b8b152dd2160a217d8fc66a710c8607c4ed1441a2148a0770701818249" ], + [ + [ + "file", + "server/nodemon.json" + ], + "5d0e1103bbe7c29a7b3137a57345f8eeb4ccd8a2128d636cc1b2bd81cf348a86" + ], [ [ "file", "server/package.json" ], - "15dfb8bf4e0dd58b9964cbcab2f02b0c977a802c88c4140861755f969d5697f9" + "597461e990d47093b89e2cdd239c6e9bc6bedef29b9cdf51b357ff3ee5217de2" ], [ [ @@ -83,13 +90,6 @@ ], "20c67ca197da3de2d37528ceaff2e40af910be8177f346c6d5c2b2f983810c43" ], - [ - [ - "file", - "server/src/ext-src/jsconfig.json" - ], - "4130060d02d39d5fdc11bdb288cfe08d36dc89be29ade017b16db6477e63c47a" - ], [ [ "file", @@ -123,7 +123,7 @@ "file", "server/src/jobs/core/pgBoss/pgBossJob.js" ], - "532ed0f34a2011cff2a9c43b712a513ba505e77d896455d6c7f36add6f88741d" + "ff6040d051c916eb080a2f2c37fd5135f588782387faeae51115d1a7abd1ad8b" ], [ [ @@ -149,23 +149,23 @@ [ [ "file", - "server/src/server.js" + "server/src/server.ts" ], - "e19bdae598265cbe2457ff1e2d8524aa821666482cb7d21644e290a68daf94a5" + "c6114654819216004f0ef4a8771a0c1213c655cfd41760fbd835077c53a6b6ba" ], [ [ "file", - "server/src/shared/jsconfig.json" + "server/src/utils.js" ], - "6972bc64315755788fd02be62c44ea8ffb60dd874b863fca2878f6160ab4b0e2" + "68a5794f55e24b303d81456a1181a3a2cd70773f6ebc4e7a63dac064834aa8e9" ], [ [ "file", - "server/src/utils.js" + "server/tsconfig.json" ], - "68a5794f55e24b303d81456a1181a3a2cd70773f6ebc4e7a63dac064834aa8e9" + "3038f152754646d2c46de78e099e9e6129bfb2541e4dccd37a05a5632ab4d838" ], [ [ @@ -200,7 +200,7 @@ "file", "web-app/package.json" ], - "f2fa10158fbdff6cea6339d1620515d9c10d56c5db43f9b061c4e74e83e405b0" + "a5532eb64f2d21f643eb96e66807acc54345782c228995cfd0dff7bebc9fcf80" ], [ [ @@ -223,6 +223,13 @@ ], "434b67f4ee148d6a5c8d88879b616d0af36d71abf193e84ef247e5ab959a13bd" ], + [ + [ + "file", + "web-app/src/actions/core.d.ts" + ], + "c18e166c8f43bd3a6a8d78f8fc2f51fe82e956cd71b3464c59076f8dec660b24" + ], [ [ "file", @@ -233,9 +240,9 @@ [ [ "file", - "web-app/src/actions/index.js" + "web-app/src/actions/index.ts" ], - "7da2524a6920c46aada7e60e29fbe24d0e45e4bfcf7bf3044d16d11ab89a965e" + "bc520b1d83577c6640472dd5c110228a3617b050d3a4d091495ec065c57011bc" ], [ [ @@ -261,16 +268,16 @@ [ [ "file", - "web-app/src/ext-src/MainPage.js" + "web-app/src/ext-src/MainPage.tsx" ], "c9ed9b5271f648715373095f43d60a2ab3e47f159c6dd6f3337ed22e5b73e80c" ], [ [ "file", - "web-app/src/ext-src/jsconfig.json" + "web-app/src/ext-src/react-app-env.d.ts" ], - "06804c81fa3b227c1b3a04e950f8db9ed85bf41d042b90e8e8332856016e113f" + "c9e89cb25e83121c0c451125de7a0b0569161e2bf18f83bc5f69836403910744" ], [ [ @@ -314,6 +321,13 @@ ], "07a9933a771853585fd2fc49c3dcb9f1cad947acb2168580c835fae25620fa9f" ], + [ + [ + "file", + "web-app/src/queries/core.d.ts" + ], + "f0b289140e92738451be386ca73a2fd1c84e9951eb2f1b9c6c09dfa3079d0c74" + ], [ [ "file", @@ -321,6 +335,13 @@ ], "2daf5b414722204281d65e954ce862a6fc586e8907b202800694909d23957c5e" ], + [ + [ + "file", + "web-app/src/queries/index.d.ts" + ], + "3eb32c063fc77fa5aa3f3b3a12c51ca8a52fc3cd0de21f4e9463a56cc374003c" + ], [ [ "file", @@ -340,7 +361,7 @@ "file", "web-app/src/router.js" ], - "dd6f5f5c6981df1935c02437d7a6ae343841300c3f7e99b0ad6ca62e95071421" + "65a91308a13f2c8444e3ad7372c1fca85a194b85e8f8f7d11613f78fcfe7af6f" ], [ [ @@ -352,15 +373,15 @@ [ [ "file", - "web-app/src/shared/jsconfig.json" + "web-app/src/utils.js" ], - "6972bc64315755788fd02be62c44ea8ffb60dd874b863fca2878f6160ab4b0e2" + "0ae6e53a050dbc6b7166aedfd5b076c2cab524c4d6aff884dc6902b178148815" ], [ [ "file", - "web-app/src/utils.js" + "web-app/tsconfig.json" ], - "0ae6e53a050dbc6b7166aedfd5b076c2cab524c4d6aff884dc6902b178148815" + "0612639442958ae18a96d651a6c385fba1a682f04d09e293efd380006fc4df99" ] ] \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedFullStackNpmDependencies.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedFullStackNpmDependencies.json index 0da1a29518..69a7a39ba5 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedFullStackNpmDependencies.json +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/installedFullStackNpmDependencies.json @@ -1 +1 @@ -{"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"express","version":"~4.18.1"},{"name":"morgan","version":"~1.10.0"},{"name":"@prisma/client","version":"4.5.0"},{"name":"jsonwebtoken","version":"^8.5.1"},{"name":"secure-password","version":"^4.0.0"},{"name":"dotenv","version":"16.0.2"},{"name":"helmet","version":"^6.0.0"},{"name":"patch-package","version":"^6.4.7"},{"name":"uuid","version":"^9.0.0"},{"name":"lodash","version":"^4.17.21"}],"devDependencies":[{"name":"nodemon","version":"^2.0.19"},{"name":"standard","version":"^17.0.0"},{"name":"prisma","version":"4.5.0"}]},"npmDepsForWebApp":{"dependencies":[{"name":"axios","version":"^0.27.2"},{"name":"react","version":"^17.0.2"},{"name":"react-dom","version":"^17.0.2"},{"name":"@tanstack/react-query","version":"^4.13.0"},{"name":"react-router-dom","version":"^5.3.3"},{"name":"react-scripts","version":"5.0.1"}],"devDependencies":[]}} \ No newline at end of file +{"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"express","version":"~4.18.1"},{"name":"morgan","version":"~1.10.0"},{"name":"@prisma/client","version":"4.5.0"},{"name":"jsonwebtoken","version":"^8.5.1"},{"name":"secure-password","version":"^4.0.0"},{"name":"dotenv","version":"16.0.2"},{"name":"helmet","version":"^6.0.0"},{"name":"patch-package","version":"^6.4.7"},{"name":"uuid","version":"^9.0.0"},{"name":"lodash","version":"^4.17.21"}],"devDependencies":[{"name":"nodemon","version":"^2.0.19"},{"name":"standard","version":"^17.0.0"},{"name":"prisma","version":"4.5.0"},{"name":"typescript","version":"^4.8.4"},{"name":"@types/node","version":"^18.11.9"}]},"npmDepsForWebApp":{"dependencies":[{"name":"axios","version":"^0.27.2"},{"name":"react","version":"^17.0.2"},{"name":"react-dom","version":"^17.0.2"},{"name":"@tanstack/react-query","version":"^4.13.0"},{"name":"react-router-dom","version":"^5.3.3"},{"name":"react-scripts","version":"5.0.1"}],"devDependencies":[{"name":"typescript","version":"^4.8.4"},{"name":"@types/react","version":"^18.0.25"},{"name":"@types/react-dom","version":"^18.0.8"},{"name":"@types/react-router-dom","version":"^5.3.3"}]}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/nodemon.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/nodemon.json new file mode 100644 index 0000000000..92d00152d9 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/nodemon.json @@ -0,0 +1,9 @@ +{ + "env": { + "NODE_ENV": "development" + }, + "watch": [ + "src/" + ], + "ext": "ts,mts,js,mjs,json" +} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/package.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/package.json index 9b25d4cb40..e37ba66de1 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/package.json +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/package.json @@ -14,9 +14,11 @@ "uuid": "^9.0.0" }, "devDependencies": { + "@types/node": "^18.11.9", "nodemon": "^2.0.19", "prisma": "4.5.0", - "standard": "^17.0.0" + "standard": "^17.0.0", + "typescript": "^4.8.4" }, "engineStrict": true, "engines": { @@ -34,13 +36,15 @@ }, "private": true, "scripts": { + "build": "npx tsc", + "build-and-start": "npm run build && npm run start", "db-migrate-dev": "prisma migrate dev --schema=../db/schema.prisma", "db-migrate-prod": "prisma migrate deploy --schema=../db/schema.prisma", "postinstall": "patch-package", "standard": "standard", - "start": "nodemon -r dotenv/config ./src/server.js", - "start-production": "NODE_ENV=production node ./src/server.js" + "start": "NODE_PATH=dist node dist/server.js", + "start-production": "NODE_ENV=production npm run start", + "watch": "nodemon -r dotenv/config --exec 'npm run build-and-start || exit 1'" }, - "type": "module", "version": "0.0.0" } diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/ext-src/jsconfig.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/ext-src/jsconfig.json deleted file mode 100644 index 9e996fc5df..0000000000 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/ext-src/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, Try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js index a9ac57c367..b9267c967a 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js @@ -55,7 +55,7 @@ class PgBossJob extends Job { * @param {object} jobArgs - The job arguments supplied by the user for their perform callback. * @param {object} jobOptions - pg-boss specific options for `boss.send()`, which can override their defaultJobOptions. */ - async submit(jobArgs, jobOptions) { + async submit(jobArgs, jobOptions = {}) { const boss = await pgBossStarted const jobId = await boss.send(this.jobName, jobArgs, { ...this.#defaultJobOptions, ...(this.#startAfter && { startAfter: this.#startAfter }), ...jobOptions }) diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/server.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/server.ts similarity index 95% rename from waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/server.js rename to waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/server.ts index 747b00a051..e4b32230de 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/server.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/server.ts @@ -15,7 +15,7 @@ const startServer = async () => { server.listen(port) - server.on('error', (error) => { + server.on('error', (error: NodeJS.ErrnoException) => { if (error.syscall !== 'listen') throw error const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port // handle specific listen errors with friendly messages diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/tsconfig.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/tsconfig.json new file mode 100644 index 0000000000..97afa9c21e --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + // Enable default imports in TypeScript. + "esModuleInterop": true, + "module": "commonjs", + "moduleResolution": "node", + "outDir": "dist", + "allowJs": true, + // Enable source map for debugging + "sourceMap": true + } +} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/package.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/package.json index b26ddfda6a..f21ceb45c7 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/package.json +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/package.json @@ -19,7 +19,12 @@ "react-router-dom": "^5.3.3", "react-scripts": "5.0.1" }, - "devDependencies": {}, + "devDependencies": { + "@types/react": "^18.0.25", + "@types/react-dom": "^18.0.8", + "@types/react-router-dom": "^5.3.3", + "typescript": "^4.8.4" + }, "engineStrict": true, "engines": { "node": "^18.12.0", diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/actions/core.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/actions/core.d.ts new file mode 100644 index 0000000000..1171c7e1b4 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/actions/core.d.ts @@ -0,0 +1,3 @@ +export type Action = (args?: Input) => Promise; + +export function createAction(actionRoute: string, entitiesUsed: unknown[]): Action diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/actions/index.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/actions/index.ts similarity index 62% rename from waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/actions/index.js rename to waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/actions/index.ts index cf97f19264..85dba33baa 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/actions/index.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/actions/index.ts @@ -1,93 +1,57 @@ import { + QueryClient, + QueryKey, useMutation, + UseMutationOptions, useQueryClient, } from '@tanstack/react-query' - -export { configureQueryClient } from '../queryClient' +import { Action } from './core'; /** * An options object passed into the `useAction` hook and used to enhance the * action with extra options. * - * @typedef {Object} ActionOptions - * @property {PublicOptimisticUpdateDefinition[]} optimisticUpdates */ +export type ActionOptions = { + optimisticUpdates: OptimisticUpdateDefinition[]; +} /** * A documented (public) way to define optimistic updates. - * - * @typedef {Object} PublicOptimisticUpdateDefinition - * @property {GetQuerySpecifier} querySpecifier - * @property {UpdateQuery} updateQuery */ +export type OptimisticUpdateDefinition = { + getQuerySpecifier: GetQuerySpecifier; + updateQuery: UpdateQuery; +} /** * A function that takes an item and returns a Wasp Query specifier. - * - * @callback GetQuerySpecifier - * @param {T} item - * @returns {QuerySpecifier} */ +export type GetQuerySpecifier = (item: Item) => QuerySpecifier /** * A function that takes an item and the previous state of the cache, and returns * the desired (new) state of the cache. - * - * @callback UpdateQuery - * @param {T} item - * @param {T[]} oldData - * @returns {T[]} */ +export type UpdateQuery = (item: ActionInput, oldData: CacheItem[]) => CacheItem[] /** * A public query specifier used for addressing Wasp queries. See our docs for details: * https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * - * @typedef {any[]} QuerySpecifier - */ - -/** - * An internal (undocumented, private, desugared) way of defining optimistic updates. - * - * @typedef {Object} InternalOptimisticUpdateDefinition - * @property {GetQuerySpecifier} querySpecifier - * @property {UpdateQuery} updateQuery - */ - -/** - * An UpdateQuery function "instantiated" with a specific item. It only takes - * the current state of the cache and returns the desired (new) state of the - * cache. - * - * @callback SpecificUpdateQuery - * @param {any[]} oldData - */ - -/** - * A specific, "instantiated" optimistic update definition which contains a - * fully-constructed query key and a specific update function. - * - * @typedef {Object} SpecificOptimisticUpdateDefinition - * @property {QueryKey} queryKey - * @property {SpecificUpdateQuery} updateQuery -*/ - -/** - * An array React Query uses to address queries. See their docs for details: - * https://react-query-v3.tanstack.com/guides/query-keys#array-keys. - * - * @typedef {any[]} QueryKey */ - +export type QuerySpecifier = any[] /** * A hook for adding extra behavior to a Wasp Action (e.g., optimistic updates). * * @param actionFn The Wasp Action you wish to enhance/decorate. - * @param {ActionOptions} actionOptions An options object for enhancing/decorating the given Action. + * @param actionOptions An options object for enhancing/decorating the given Action. * @returns A decorated Action with added behavior but an unchanged API. */ -export function useAction(actionFn, actionOptions) { +export function useAction( + actionFn: (item: ActionInput) => Promise, + actionOptions: ActionOptions +): typeof actionFn { const queryClient = useQueryClient(); let mutationFn = actionFn @@ -110,14 +74,49 @@ export function useAction(actionFn, actionOptions) { } /** - * Translates/Desugars a public optimistic update definition object into a definition object our - * system uses internally. + * An internal (undocumented, private, desugared) way of defining optimistic updates. + */ +type InternalOptimisticUpdateDefinition = { + getQueryKey: (item: ActionInput) => QueryKey, + updateQuery: UpdateQuery; + +} + +/** + * An UpdateQuery function "instantiated" with a specific item. It only takes + * the current state of the cache and returns the desired (new) state of the + * cache. + */ +type SpecificUpdateQuery = (oldData: Item[]) => Item[] + +/** + * A specific, "instantiated" optimistic update definition which contains a + * fully-constructed query key and a specific update function. + */ +type SpecificOptimisticUpdateDefinition = { + queryKey: QueryKey; + updateQuery: SpecificUpdateQuery; +} + +type InternalAction = Action & { + internal( + item: Input, + optimisticUpdateDefinitions: SpecificOptimisticUpdateDefinition[] + ): Promise +} + +/** + * Translates/Desugars a public optimistic update definition object into a + * definition object our system uses internally. * - * @param {PublicOptimisticUpdateDefinition} publicOptimisticUpdateDefinition An optimistic update definition - * object that's a part of the public API: https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * @returns {InternalOptimisticUpdateDefinition} An internally-used optimistic update definition object. + * @param publicOptimisticUpdateDefinition An optimistic update definition + * object that's a part of the public API: + * https://wasp-lang.dev/docs/language/features#the-useaction-hook. + * @returns An internally-used optimistic update definition object. */ -function translateToInternalDefinition(publicOptimisticUpdateDefinition) { +function translateToInternalDefinition( + publicOptimisticUpdateDefinition: OptimisticUpdateDefinition +): InternalOptimisticUpdateDefinition { const { getQuerySpecifier, updateQuery } = publicOptimisticUpdateDefinition const definitionErrors = [] @@ -141,17 +140,19 @@ function translateToInternalDefinition(publicOptimisticUpdateDefinition) { * Creates a function that performs an action while telling it about the * optimistic updates it caused. * - * @param actionFn - The Wasp Action. - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinitions - The optimisitc updates the - * action causes. - * @returns A + * @param actionFn The Wasp Action. + * @param optimisticUpdateDefinitions The optimisitc updates the action causes. + * @returns An decorated action which performs optimistic updates. */ -function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) { +function makeOptimisticUpdateMutationFn( + actionFn: Action, + optimisticUpdateDefinitions: InternalOptimisticUpdateDefinition[] +): typeof actionFn { return function performActionWithOptimisticUpdates(item) { const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map( generalDefinition => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item) ) - return actionFn.internal(item, specificOptimisticUpdateDefinitions) + return (actionFn as InternalAction).internal(item, specificOptimisticUpdateDefinitions) } } @@ -163,13 +164,18 @@ function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) { * optimistic updates definition. Check their docs for details: * https://tanstack.com/query/v4/docs/guides/optimistic-updates?from=reactQueryV3&original=https://react-query-v3.tanstack.com/guides/optimistic-updates * - * @param {Object} queryClient The QueryClient instance used by React Query. - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinitions A list containing internal optimistic updates definition objects - * (i.e., a list where each object carries the instructions for performing particular optimistic update). - * @returns {Object} An object containing 'onMutate' and 'onError' functions corresponding to the given optimistic update - * definitions (check the docs linked above for details). + * @param queryClient The QueryClient instance used by React Query. + * @param optimisticUpdateDefinitions A list containing internal optimistic + * updates definition objects (i.e., a list where each object carries the + * instructions for performing particular optimistic update). + * @returns An object containing 'onMutate' and 'onError' functions + * corresponding to the given optimistic update definitions (check the docs + * linked above for details). */ -function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) { +function makeRqOptimisticUpdateOptions( + queryClient: QueryClient, + optimisticUpdateDefinitions: InternalOptimisticUpdateDefinition[] +): Pick { async function onMutate(item) { const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map( generalDefinition => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item) @@ -187,7 +193,7 @@ function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) const previousData = new Map() specificOptimisticUpdateDefinitions.forEach(({ queryKey, updateQuery }) => { // Snapshot the currently cached value. - const previousDataForQuery = queryClient.getQueryData(queryKey) + const previousDataForQuery: CacheItem[] = queryClient.getQueryData(queryKey) // Attempt to optimistically update the cache using the new value. try { @@ -227,13 +233,16 @@ function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) * uses a closure over the updated item to construct an item-specific query key * (e.g., useful when the query key depends on an ID). * - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinition The general, "uninstantiated" optimistic + * @param optimisticUpdateDefinition The general, "uninstantiated" optimistic * update definition with a function for constructing the query key. - * @param item The item triggering the Action/optimistic update (i.e., the argument passed to the Action). - * @returns {SpecificOptimisticUpdateDefinition} A specific optimistic update definition - * which corresponds to the provided definition and closes over the provided item. + * @param item The item triggering the Action/optimistic update (i.e., the + * argument passed to the Action). + * @returns A specific optimistic update definition which corresponds to the + * provided definition and closes over the provided item. */ -function getOptimisticUpdateDefinitionForSpecificItem(optimisticUpdateDefinition, item) { +function getOptimisticUpdateDefinitionForSpecificItem( + optimisticUpdateDefinition: InternalOptimisticUpdateDefinition, item: ActionInput +): SpecificOptimisticUpdateDefinition { const { getQueryKey, updateQuery } = optimisticUpdateDefinition return { queryKey: getQueryKey(item), @@ -244,11 +253,11 @@ function getOptimisticUpdateDefinitionForSpecificItem(optimisticUpdateDefinition /** * Translates a Wasp query specifier to a query cache key used by React Query. * - * @param {QuerySpecifier} querySpecifier A query specifier that's a part of the public API: + * @param querySpecifier A query specifier that's a part of the public API: * https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * @returns {QueryKey} A cache key React Query internally uses for addressing queries. + * @returns A cache key React Query internally uses for addressing queries. */ -function getRqQueryKeyFromSpecifier(querySpecifier) { +function getRqQueryKeyFromSpecifier(querySpecifier: QuerySpecifier): QueryKey { const [queryFn, ...otherKeys] = querySpecifier return [...queryFn.queryCacheKey, ...otherKeys] } diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/ext-src/MainPage.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/ext-src/MainPage.tsx similarity index 100% rename from waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/ext-src/MainPage.js rename to waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/ext-src/MainPage.tsx diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/ext-src/react-app-env.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/ext-src/react-app-env.d.ts new file mode 100644 index 0000000000..e80934ce3a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/ext-src/react-app-env.d.ts @@ -0,0 +1,60 @@ +declare module '*.avif' { + const src: string; + export default src; +} + +declare module '*.bmp' { + const src: string; + export default src; +} + +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + import * as React from 'react'; + + export const ReactComponent: React.FunctionComponent & { title?: string }>; + + const src: string; + export default src; +} + +declare module '*.module.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/queries/core.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/queries/core.d.ts new file mode 100644 index 0000000000..edde495db4 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/queries/core.d.ts @@ -0,0 +1,3 @@ +export type Query = (args: Input) => Promise + +export function createQuery(queryRoute: string, entitiesUsed: any[]): Query diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/queries/index.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/queries/index.d.ts new file mode 100644 index 0000000000..a331fa9d73 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/queries/index.d.ts @@ -0,0 +1,8 @@ +import { UseQueryResult } from "@tanstack/react-query"; +import { OutputHTMLAttributes } from "react"; +import { Query } from "./core"; + +export function useQuery( + queryFn: Query, + queryFnArgs?: Input, options?: any +): UseQueryResult diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/router.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/router.js index c783ed20ac..7d3f45f130 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/router.js +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/router.js @@ -2,7 +2,7 @@ import React from 'react' import { Route, BrowserRouter as Router } from 'react-router-dom' -import MainPage from "./ext-src/MainPage.js" +import MainPage from "./ext-src/MainPage" const router = ( diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/shared/jsconfig.json deleted file mode 100644 index 0c4e7f7eb1..0000000000 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/src/shared/jsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", - "paths": { - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/tsconfig.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/tsconfig.json new file mode 100644 index 0000000000..3fab473aae --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/web-app/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es2018", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx" + }, + "include": [ + "src" + ] +} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/main.wasp b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/main.wasp index c573407c21..1b548ce50b 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/main.wasp +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/main.wasp @@ -7,5 +7,5 @@ app waspCompile { route RootRoute { path: "/", to: MainPage } page MainPage { - component: import Main from "@client/MainPage.js" + component: import Main from "@client/MainPage" } diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/MainPage.js b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/MainPage.tsx similarity index 100% rename from waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/MainPage.js rename to waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/MainPage.tsx diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/react-app-env.d.ts b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/react-app-env.d.ts new file mode 100644 index 0000000000..e80934ce3a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/react-app-env.d.ts @@ -0,0 +1,60 @@ +declare module '*.avif' { + const src: string; + export default src; +} + +declare module '*.bmp' { + const src: string; + export default src; +} + +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + import * as React from 'react'; + + export const ReactComponent: React.FunctionComponent & { title?: string }>; + + const src: string; + export default src; +} + +declare module '*.module.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/tsconfig.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/tsconfig.json new file mode 100644 index 0000000000..34c23b30ce --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/tsconfig.json @@ -0,0 +1,39 @@ +{ + "compilerOptions": { + // JSX support + "jsx": "preserve", + // Enable default imports in TypeScript. + "esModuleInterop": true, + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + // The following settings enable IDE support in user-provided source files. + // Editing them might break features like import autocompletion and + // definition lookup. Don't change them unless you know what you're doing. + // + // The relative path to the generated web app's root directory. This must be + // set to define the "paths" option. + "baseUrl": "../../.wasp/out/web-app/", + "paths": { + // Resolve all "@wasp" imports to the generated source code. + "@wasp/*": [ + "src/*" + ], + // Resolve all non-relative imports to the correct node module. Source: + // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping + "*": [ + // Start by looking for the definiton inside the node modules root + // directory... + "node_modules/*", + // ... If that fails, try to find it inside definitely-typed type + // definitions. + "node_modules/@types/*" + ] + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/web-app/node_modules/@types"] + } +} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/server/jsconfig.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/server/jsconfig.json deleted file mode 100644 index 9e996fc5df..0000000000 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/server/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, Try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/jsconfig.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/server/tsconfig.json similarity index 75% rename from waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/jsconfig.json rename to waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/server/tsconfig.json index e9b5551fd7..8d313c4516 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/src/client/jsconfig.json +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/server/tsconfig.json @@ -1,12 +1,15 @@ { "compilerOptions": { - // The following settings enable IDE support in user-provided source files. + // Enable default imports in TypeScript. + "esModuleInterop": true, + "allowJs": true, + // The following settings enable IDE support in user-provided source files. // Editing them might break features like import autocompletion and // definition lookup. Don't change them unless you know what you're doing. // // The relative path to the generated web app's root directory. This must be // set to define the "paths" option. - "baseUrl": "../../.wasp/out/web-app/", + "baseUrl": "../../.wasp/out/server/", "paths": { // Resolve all "@wasp" imports to the generated source code. "@wasp/*": [ @@ -22,6 +25,8 @@ // definitions. "node_modules/@types/*" ] - } + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/server/node_modules/@types"] } } diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/shared/jsconfig.json deleted file mode 100644 index 0c4e7f7eb1..0000000000 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/shared/jsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", - "paths": { - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/shared/tsconfig.json similarity index 74% rename from waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/shared/jsconfig.json rename to waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/shared/tsconfig.json index 0c4e7f7eb1..20fcac8431 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/shared/jsconfig.json +++ b/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/shared/tsconfig.json @@ -1,12 +1,15 @@ { "compilerOptions": { + // Enable default imports in TypeScript. + "esModuleInterop": true, + "allowJs": true, // The following settings enable IDE support in user-provided source files. // Editing them might break features like import autocompletion and // definition lookup. Don't change them unless you know what you're doing. // // The relative path to the generated web app's root directory. This must be // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", + "baseUrl": "../../.wasp/out/server/", "paths": { // Resolve all non-relative imports to the correct node module. Source: // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping @@ -18,6 +21,8 @@ // definitions. "node_modules/@types/*" ] - } + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/server/node_modules/@types"] } } diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/files.manifest b/waspc/e2e-test/test-outputs/waspJob-golden/files.manifest index 68ed4aceb9..f3b71f358f 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/files.manifest +++ b/waspc/e2e-test/test-outputs/waspJob-golden/files.manifest @@ -5,6 +5,7 @@ waspJob/.wasp/out/db/schema.prisma waspJob/.wasp/out/installedFullStackNpmDependencies.json waspJob/.wasp/out/server/.npmrc waspJob/.wasp/out/server/README.md +waspJob/.wasp/out/server/nodemon.json waspJob/.wasp/out/server/package.json waspJob/.wasp/out/server/src/app.js waspJob/.wasp/out/server/src/config.js @@ -12,7 +13,6 @@ waspJob/.wasp/out/server/src/core/AuthError.js waspJob/.wasp/out/server/src/core/HttpError.js waspJob/.wasp/out/server/src/dbClient.js waspJob/.wasp/out/server/src/ext-src/jobs/bar.js -waspJob/.wasp/out/server/src/ext-src/jsconfig.json waspJob/.wasp/out/server/src/jobs/MySpecialJob.js waspJob/.wasp/out/server/src/jobs/core/Job.js waspJob/.wasp/out/server/src/jobs/core/SubmittedJob.js @@ -22,9 +22,9 @@ waspJob/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js waspJob/.wasp/out/server/src/jobs/core/simpleJob.js waspJob/.wasp/out/server/src/routes/index.js waspJob/.wasp/out/server/src/routes/operations/index.js -waspJob/.wasp/out/server/src/server.js -waspJob/.wasp/out/server/src/shared/jsconfig.json +waspJob/.wasp/out/server/src/server.ts waspJob/.wasp/out/server/src/utils.js +waspJob/.wasp/out/server/tsconfig.json waspJob/.wasp/out/web-app/.npmrc waspJob/.wasp/out/web-app/README.md waspJob/.wasp/out/web-app/netlify.toml @@ -32,33 +32,37 @@ waspJob/.wasp/out/web-app/package.json waspJob/.wasp/out/web-app/public/favicon.ico waspJob/.wasp/out/web-app/public/index.html waspJob/.wasp/out/web-app/public/manifest.json +waspJob/.wasp/out/web-app/src/actions/core.d.ts waspJob/.wasp/out/web-app/src/actions/core.js -waspJob/.wasp/out/web-app/src/actions/index.js +waspJob/.wasp/out/web-app/src/actions/index.ts waspJob/.wasp/out/web-app/src/api.js waspJob/.wasp/out/web-app/src/config.js waspJob/.wasp/out/web-app/src/ext-src/Main.css -waspJob/.wasp/out/web-app/src/ext-src/MainPage.js -waspJob/.wasp/out/web-app/src/ext-src/jsconfig.json +waspJob/.wasp/out/web-app/src/ext-src/MainPage.tsx +waspJob/.wasp/out/web-app/src/ext-src/react-app-env.d.ts waspJob/.wasp/out/web-app/src/ext-src/waspLogo.png waspJob/.wasp/out/web-app/src/index.js waspJob/.wasp/out/web-app/src/logo.png waspJob/.wasp/out/web-app/src/operations/index.js waspJob/.wasp/out/web-app/src/operations/resources.js waspJob/.wasp/out/web-app/src/operations/updateHandlersMap.js +waspJob/.wasp/out/web-app/src/queries/core.d.ts waspJob/.wasp/out/web-app/src/queries/core.js +waspJob/.wasp/out/web-app/src/queries/index.d.ts waspJob/.wasp/out/web-app/src/queries/index.js waspJob/.wasp/out/web-app/src/queryClient.js waspJob/.wasp/out/web-app/src/router.js waspJob/.wasp/out/web-app/src/serviceWorker.js -waspJob/.wasp/out/web-app/src/shared/jsconfig.json waspJob/.wasp/out/web-app/src/utils.js +waspJob/.wasp/out/web-app/tsconfig.json waspJob/.wasproot waspJob/main.wasp waspJob/src/.waspignore waspJob/src/client/Main.css -waspJob/src/client/MainPage.js -waspJob/src/client/jsconfig.json +waspJob/src/client/MainPage.tsx +waspJob/src/client/react-app-env.d.ts +waspJob/src/client/tsconfig.json waspJob/src/client/waspLogo.png waspJob/src/server/jobs/bar.js -waspJob/src/server/jsconfig.json -waspJob/src/shared/jsconfig.json +waspJob/src/server/tsconfig.json +waspJob/src/shared/tsconfig.json diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums index 3b579ceb8f..302a1d9a9d 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/.waspchecksums @@ -41,12 +41,19 @@ ], "e14514b8b152dd2160a217d8fc66a710c8607c4ed1441a2148a0770701818249" ], + [ + [ + "file", + "server/nodemon.json" + ], + "5d0e1103bbe7c29a7b3137a57345f8eeb4ccd8a2128d636cc1b2bd81cf348a86" + ], [ [ "file", "server/package.json" ], - "8ec67fe68b2e2d1e469a5a6e405db1f67ea2bd201e18bb7a7b088c267781ccb1" + "d9e1c5b4349eee43dea8f321e16ff49229f428978c578549cfebed973756364d" ], [ [ @@ -90,13 +97,6 @@ ], "2e126f35b3a3e9a289e0dcfd8707fe903c6a053e0cf85899fb5f686d77dd3eb5" ], - [ - [ - "file", - "server/src/ext-src/jsconfig.json" - ], - "4130060d02d39d5fdc11bdb288cfe08d36dc89be29ade017b16db6477e63c47a" - ], [ [ "file", @@ -137,7 +137,7 @@ "file", "server/src/jobs/core/pgBoss/pgBossJob.js" ], - "532ed0f34a2011cff2a9c43b712a513ba505e77d896455d6c7f36add6f88741d" + "ff6040d051c916eb080a2f2c37fd5135f588782387faeae51115d1a7abd1ad8b" ], [ [ @@ -163,23 +163,23 @@ [ [ "file", - "server/src/server.js" + "server/src/server.ts" ], - "6287f825b427f4a4ada5cc5a99c2d0a3379a7c59cea474653e22129df7d2ad39" + "3680f7afaf38fb9e32cb3bc9c64641224e2d2867bdc912730114cbf9360bf9f0" ], [ [ "file", - "server/src/shared/jsconfig.json" + "server/src/utils.js" ], - "6972bc64315755788fd02be62c44ea8ffb60dd874b863fca2878f6160ab4b0e2" + "68a5794f55e24b303d81456a1181a3a2cd70773f6ebc4e7a63dac064834aa8e9" ], [ [ "file", - "server/src/utils.js" + "server/tsconfig.json" ], - "68a5794f55e24b303d81456a1181a3a2cd70773f6ebc4e7a63dac064834aa8e9" + "3038f152754646d2c46de78e099e9e6129bfb2541e4dccd37a05a5632ab4d838" ], [ [ @@ -214,7 +214,7 @@ "file", "web-app/package.json" ], - "ef46ceee543774353403dc2e725387bed4e82158dbb54afb795ed684c81c9908" + "2bb07bf2e36d105da57cf0ff21ef830d6aa7018555d9701cfd636e9a2aba34c8" ], [ [ @@ -237,6 +237,13 @@ ], "f223cbdd7db93d51c3ecf8282a06801449b29bfb6821313c383c1b18ad8c1479" ], + [ + [ + "file", + "web-app/src/actions/core.d.ts" + ], + "c18e166c8f43bd3a6a8d78f8fc2f51fe82e956cd71b3464c59076f8dec660b24" + ], [ [ "file", @@ -247,9 +254,9 @@ [ [ "file", - "web-app/src/actions/index.js" + "web-app/src/actions/index.ts" ], - "7da2524a6920c46aada7e60e29fbe24d0e45e4bfcf7bf3044d16d11ab89a965e" + "bc520b1d83577c6640472dd5c110228a3617b050d3a4d091495ec065c57011bc" ], [ [ @@ -275,16 +282,16 @@ [ [ "file", - "web-app/src/ext-src/MainPage.js" + "web-app/src/ext-src/MainPage.tsx" ], "c9ed9b5271f648715373095f43d60a2ab3e47f159c6dd6f3337ed22e5b73e80c" ], [ [ "file", - "web-app/src/ext-src/jsconfig.json" + "web-app/src/ext-src/react-app-env.d.ts" ], - "06804c81fa3b227c1b3a04e950f8db9ed85bf41d042b90e8e8332856016e113f" + "c9e89cb25e83121c0c451125de7a0b0569161e2bf18f83bc5f69836403910744" ], [ [ @@ -328,6 +335,13 @@ ], "07a9933a771853585fd2fc49c3dcb9f1cad947acb2168580c835fae25620fa9f" ], + [ + [ + "file", + "web-app/src/queries/core.d.ts" + ], + "f0b289140e92738451be386ca73a2fd1c84e9951eb2f1b9c6c09dfa3079d0c74" + ], [ [ "file", @@ -335,6 +349,13 @@ ], "2daf5b414722204281d65e954ce862a6fc586e8907b202800694909d23957c5e" ], + [ + [ + "file", + "web-app/src/queries/index.d.ts" + ], + "3eb32c063fc77fa5aa3f3b3a12c51ca8a52fc3cd0de21f4e9463a56cc374003c" + ], [ [ "file", @@ -354,7 +375,7 @@ "file", "web-app/src/router.js" ], - "dd6f5f5c6981df1935c02437d7a6ae343841300c3f7e99b0ad6ca62e95071421" + "65a91308a13f2c8444e3ad7372c1fca85a194b85e8f8f7d11613f78fcfe7af6f" ], [ [ @@ -366,15 +387,15 @@ [ [ "file", - "web-app/src/shared/jsconfig.json" + "web-app/src/utils.js" ], - "6972bc64315755788fd02be62c44ea8ffb60dd874b863fca2878f6160ab4b0e2" + "0ae6e53a050dbc6b7166aedfd5b076c2cab524c4d6aff884dc6902b178148815" ], [ [ "file", - "web-app/src/utils.js" + "web-app/tsconfig.json" ], - "0ae6e53a050dbc6b7166aedfd5b076c2cab524c4d6aff884dc6902b178148815" + "0612639442958ae18a96d651a6c385fba1a682f04d09e293efd380006fc4df99" ] ] \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedFullStackNpmDependencies.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedFullStackNpmDependencies.json index c162b8d624..cc98c1d6d8 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedFullStackNpmDependencies.json +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/installedFullStackNpmDependencies.json @@ -1 +1 @@ -{"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"express","version":"~4.18.1"},{"name":"morgan","version":"~1.10.0"},{"name":"@prisma/client","version":"4.5.0"},{"name":"jsonwebtoken","version":"^8.5.1"},{"name":"secure-password","version":"^4.0.0"},{"name":"dotenv","version":"16.0.2"},{"name":"helmet","version":"^6.0.0"},{"name":"patch-package","version":"^6.4.7"},{"name":"uuid","version":"^9.0.0"},{"name":"lodash","version":"^4.17.21"},{"name":"pg-boss","version":"^8.0.0"}],"devDependencies":[{"name":"nodemon","version":"^2.0.19"},{"name":"standard","version":"^17.0.0"},{"name":"prisma","version":"4.5.0"}]},"npmDepsForWebApp":{"dependencies":[{"name":"axios","version":"^0.27.2"},{"name":"react","version":"^17.0.2"},{"name":"react-dom","version":"^17.0.2"},{"name":"@tanstack/react-query","version":"^4.13.0"},{"name":"react-router-dom","version":"^5.3.3"},{"name":"react-scripts","version":"5.0.1"}],"devDependencies":[]}} \ No newline at end of file +{"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"express","version":"~4.18.1"},{"name":"morgan","version":"~1.10.0"},{"name":"@prisma/client","version":"4.5.0"},{"name":"jsonwebtoken","version":"^8.5.1"},{"name":"secure-password","version":"^4.0.0"},{"name":"dotenv","version":"16.0.2"},{"name":"helmet","version":"^6.0.0"},{"name":"patch-package","version":"^6.4.7"},{"name":"uuid","version":"^9.0.0"},{"name":"lodash","version":"^4.17.21"},{"name":"pg-boss","version":"^8.0.0"}],"devDependencies":[{"name":"nodemon","version":"^2.0.19"},{"name":"standard","version":"^17.0.0"},{"name":"prisma","version":"4.5.0"},{"name":"typescript","version":"^4.8.4"},{"name":"@types/node","version":"^18.11.9"}]},"npmDepsForWebApp":{"dependencies":[{"name":"axios","version":"^0.27.2"},{"name":"react","version":"^17.0.2"},{"name":"react-dom","version":"^17.0.2"},{"name":"@tanstack/react-query","version":"^4.13.0"},{"name":"react-router-dom","version":"^5.3.3"},{"name":"react-scripts","version":"5.0.1"}],"devDependencies":[{"name":"typescript","version":"^4.8.4"},{"name":"@types/react","version":"^18.0.25"},{"name":"@types/react-dom","version":"^18.0.8"},{"name":"@types/react-router-dom","version":"^5.3.3"}]}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/nodemon.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/nodemon.json new file mode 100644 index 0000000000..92d00152d9 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/nodemon.json @@ -0,0 +1,9 @@ +{ + "env": { + "NODE_ENV": "development" + }, + "watch": [ + "src/" + ], + "ext": "ts,mts,js,mjs,json" +} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/package.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/package.json index a5ad681c98..70a84992b9 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/package.json +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/package.json @@ -15,9 +15,11 @@ "uuid": "^9.0.0" }, "devDependencies": { + "@types/node": "^18.11.9", "nodemon": "^2.0.19", "prisma": "4.5.0", - "standard": "^17.0.0" + "standard": "^17.0.0", + "typescript": "^4.8.4" }, "engineStrict": true, "engines": { @@ -35,13 +37,15 @@ }, "private": true, "scripts": { + "build": "npx tsc", + "build-and-start": "npm run build && npm run start", "db-migrate-dev": "prisma migrate dev --schema=../db/schema.prisma", "db-migrate-prod": "prisma migrate deploy --schema=../db/schema.prisma", "postinstall": "patch-package", "standard": "standard", - "start": "nodemon -r dotenv/config ./src/server.js", - "start-production": "NODE_ENV=production node ./src/server.js" + "start": "NODE_PATH=dist node dist/server.js", + "start-production": "NODE_ENV=production npm run start", + "watch": "nodemon -r dotenv/config --exec 'npm run build-and-start || exit 1'" }, - "type": "module", "version": "0.0.0" } diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/ext-src/jsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/ext-src/jsconfig.json deleted file mode 100644 index 9e996fc5df..0000000000 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/ext-src/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, Try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js index a9ac57c367..b9267c967a 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js @@ -55,7 +55,7 @@ class PgBossJob extends Job { * @param {object} jobArgs - The job arguments supplied by the user for their perform callback. * @param {object} jobOptions - pg-boss specific options for `boss.send()`, which can override their defaultJobOptions. */ - async submit(jobArgs, jobOptions) { + async submit(jobArgs, jobOptions = {}) { const boss = await pgBossStarted const jobId = await boss.send(this.jobName, jobArgs, { ...this.#defaultJobOptions, ...(this.#startAfter && { startAfter: this.#startAfter }), ...jobOptions }) diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/server.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/server.ts similarity index 95% rename from waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/server.js rename to waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/server.ts index 0e41e66c98..9ef6d0859c 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/server.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/server.ts @@ -18,7 +18,7 @@ const startServer = async () => { server.listen(port) - server.on('error', (error) => { + server.on('error', (error: NodeJS.ErrnoException) => { if (error.syscall !== 'listen') throw error const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port // handle specific listen errors with friendly messages diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/shared/jsconfig.json deleted file mode 100644 index 0c4e7f7eb1..0000000000 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/src/shared/jsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", - "paths": { - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/tsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/tsconfig.json new file mode 100644 index 0000000000..97afa9c21e --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/server/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + // Enable default imports in TypeScript. + "esModuleInterop": true, + "module": "commonjs", + "moduleResolution": "node", + "outDir": "dist", + "allowJs": true, + // Enable source map for debugging + "sourceMap": true + } +} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/package.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/package.json index e0cc7c9436..e7508abae2 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/package.json +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/package.json @@ -19,7 +19,12 @@ "react-router-dom": "^5.3.3", "react-scripts": "5.0.1" }, - "devDependencies": {}, + "devDependencies": { + "@types/react": "^18.0.25", + "@types/react-dom": "^18.0.8", + "@types/react-router-dom": "^5.3.3", + "typescript": "^4.8.4" + }, "engineStrict": true, "engines": { "node": "^18.12.0", diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/actions/core.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/actions/core.d.ts new file mode 100644 index 0000000000..1171c7e1b4 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/actions/core.d.ts @@ -0,0 +1,3 @@ +export type Action = (args?: Input) => Promise; + +export function createAction(actionRoute: string, entitiesUsed: unknown[]): Action diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/actions/index.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/actions/index.ts similarity index 62% rename from waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/actions/index.js rename to waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/actions/index.ts index cf97f19264..85dba33baa 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/actions/index.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/actions/index.ts @@ -1,93 +1,57 @@ import { + QueryClient, + QueryKey, useMutation, + UseMutationOptions, useQueryClient, } from '@tanstack/react-query' - -export { configureQueryClient } from '../queryClient' +import { Action } from './core'; /** * An options object passed into the `useAction` hook and used to enhance the * action with extra options. * - * @typedef {Object} ActionOptions - * @property {PublicOptimisticUpdateDefinition[]} optimisticUpdates */ +export type ActionOptions = { + optimisticUpdates: OptimisticUpdateDefinition[]; +} /** * A documented (public) way to define optimistic updates. - * - * @typedef {Object} PublicOptimisticUpdateDefinition - * @property {GetQuerySpecifier} querySpecifier - * @property {UpdateQuery} updateQuery */ +export type OptimisticUpdateDefinition = { + getQuerySpecifier: GetQuerySpecifier; + updateQuery: UpdateQuery; +} /** * A function that takes an item and returns a Wasp Query specifier. - * - * @callback GetQuerySpecifier - * @param {T} item - * @returns {QuerySpecifier} */ +export type GetQuerySpecifier = (item: Item) => QuerySpecifier /** * A function that takes an item and the previous state of the cache, and returns * the desired (new) state of the cache. - * - * @callback UpdateQuery - * @param {T} item - * @param {T[]} oldData - * @returns {T[]} */ +export type UpdateQuery = (item: ActionInput, oldData: CacheItem[]) => CacheItem[] /** * A public query specifier used for addressing Wasp queries. See our docs for details: * https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * - * @typedef {any[]} QuerySpecifier - */ - -/** - * An internal (undocumented, private, desugared) way of defining optimistic updates. - * - * @typedef {Object} InternalOptimisticUpdateDefinition - * @property {GetQuerySpecifier} querySpecifier - * @property {UpdateQuery} updateQuery - */ - -/** - * An UpdateQuery function "instantiated" with a specific item. It only takes - * the current state of the cache and returns the desired (new) state of the - * cache. - * - * @callback SpecificUpdateQuery - * @param {any[]} oldData - */ - -/** - * A specific, "instantiated" optimistic update definition which contains a - * fully-constructed query key and a specific update function. - * - * @typedef {Object} SpecificOptimisticUpdateDefinition - * @property {QueryKey} queryKey - * @property {SpecificUpdateQuery} updateQuery -*/ - -/** - * An array React Query uses to address queries. See their docs for details: - * https://react-query-v3.tanstack.com/guides/query-keys#array-keys. - * - * @typedef {any[]} QueryKey */ - +export type QuerySpecifier = any[] /** * A hook for adding extra behavior to a Wasp Action (e.g., optimistic updates). * * @param actionFn The Wasp Action you wish to enhance/decorate. - * @param {ActionOptions} actionOptions An options object for enhancing/decorating the given Action. + * @param actionOptions An options object for enhancing/decorating the given Action. * @returns A decorated Action with added behavior but an unchanged API. */ -export function useAction(actionFn, actionOptions) { +export function useAction( + actionFn: (item: ActionInput) => Promise, + actionOptions: ActionOptions +): typeof actionFn { const queryClient = useQueryClient(); let mutationFn = actionFn @@ -110,14 +74,49 @@ export function useAction(actionFn, actionOptions) { } /** - * Translates/Desugars a public optimistic update definition object into a definition object our - * system uses internally. + * An internal (undocumented, private, desugared) way of defining optimistic updates. + */ +type InternalOptimisticUpdateDefinition = { + getQueryKey: (item: ActionInput) => QueryKey, + updateQuery: UpdateQuery; + +} + +/** + * An UpdateQuery function "instantiated" with a specific item. It only takes + * the current state of the cache and returns the desired (new) state of the + * cache. + */ +type SpecificUpdateQuery = (oldData: Item[]) => Item[] + +/** + * A specific, "instantiated" optimistic update definition which contains a + * fully-constructed query key and a specific update function. + */ +type SpecificOptimisticUpdateDefinition = { + queryKey: QueryKey; + updateQuery: SpecificUpdateQuery; +} + +type InternalAction = Action & { + internal( + item: Input, + optimisticUpdateDefinitions: SpecificOptimisticUpdateDefinition[] + ): Promise +} + +/** + * Translates/Desugars a public optimistic update definition object into a + * definition object our system uses internally. * - * @param {PublicOptimisticUpdateDefinition} publicOptimisticUpdateDefinition An optimistic update definition - * object that's a part of the public API: https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * @returns {InternalOptimisticUpdateDefinition} An internally-used optimistic update definition object. + * @param publicOptimisticUpdateDefinition An optimistic update definition + * object that's a part of the public API: + * https://wasp-lang.dev/docs/language/features#the-useaction-hook. + * @returns An internally-used optimistic update definition object. */ -function translateToInternalDefinition(publicOptimisticUpdateDefinition) { +function translateToInternalDefinition( + publicOptimisticUpdateDefinition: OptimisticUpdateDefinition +): InternalOptimisticUpdateDefinition { const { getQuerySpecifier, updateQuery } = publicOptimisticUpdateDefinition const definitionErrors = [] @@ -141,17 +140,19 @@ function translateToInternalDefinition(publicOptimisticUpdateDefinition) { * Creates a function that performs an action while telling it about the * optimistic updates it caused. * - * @param actionFn - The Wasp Action. - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinitions - The optimisitc updates the - * action causes. - * @returns A + * @param actionFn The Wasp Action. + * @param optimisticUpdateDefinitions The optimisitc updates the action causes. + * @returns An decorated action which performs optimistic updates. */ -function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) { +function makeOptimisticUpdateMutationFn( + actionFn: Action, + optimisticUpdateDefinitions: InternalOptimisticUpdateDefinition[] +): typeof actionFn { return function performActionWithOptimisticUpdates(item) { const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map( generalDefinition => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item) ) - return actionFn.internal(item, specificOptimisticUpdateDefinitions) + return (actionFn as InternalAction).internal(item, specificOptimisticUpdateDefinitions) } } @@ -163,13 +164,18 @@ function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) { * optimistic updates definition. Check their docs for details: * https://tanstack.com/query/v4/docs/guides/optimistic-updates?from=reactQueryV3&original=https://react-query-v3.tanstack.com/guides/optimistic-updates * - * @param {Object} queryClient The QueryClient instance used by React Query. - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinitions A list containing internal optimistic updates definition objects - * (i.e., a list where each object carries the instructions for performing particular optimistic update). - * @returns {Object} An object containing 'onMutate' and 'onError' functions corresponding to the given optimistic update - * definitions (check the docs linked above for details). + * @param queryClient The QueryClient instance used by React Query. + * @param optimisticUpdateDefinitions A list containing internal optimistic + * updates definition objects (i.e., a list where each object carries the + * instructions for performing particular optimistic update). + * @returns An object containing 'onMutate' and 'onError' functions + * corresponding to the given optimistic update definitions (check the docs + * linked above for details). */ -function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) { +function makeRqOptimisticUpdateOptions( + queryClient: QueryClient, + optimisticUpdateDefinitions: InternalOptimisticUpdateDefinition[] +): Pick { async function onMutate(item) { const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map( generalDefinition => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item) @@ -187,7 +193,7 @@ function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) const previousData = new Map() specificOptimisticUpdateDefinitions.forEach(({ queryKey, updateQuery }) => { // Snapshot the currently cached value. - const previousDataForQuery = queryClient.getQueryData(queryKey) + const previousDataForQuery: CacheItem[] = queryClient.getQueryData(queryKey) // Attempt to optimistically update the cache using the new value. try { @@ -227,13 +233,16 @@ function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) * uses a closure over the updated item to construct an item-specific query key * (e.g., useful when the query key depends on an ID). * - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinition The general, "uninstantiated" optimistic + * @param optimisticUpdateDefinition The general, "uninstantiated" optimistic * update definition with a function for constructing the query key. - * @param item The item triggering the Action/optimistic update (i.e., the argument passed to the Action). - * @returns {SpecificOptimisticUpdateDefinition} A specific optimistic update definition - * which corresponds to the provided definition and closes over the provided item. + * @param item The item triggering the Action/optimistic update (i.e., the + * argument passed to the Action). + * @returns A specific optimistic update definition which corresponds to the + * provided definition and closes over the provided item. */ -function getOptimisticUpdateDefinitionForSpecificItem(optimisticUpdateDefinition, item) { +function getOptimisticUpdateDefinitionForSpecificItem( + optimisticUpdateDefinition: InternalOptimisticUpdateDefinition, item: ActionInput +): SpecificOptimisticUpdateDefinition { const { getQueryKey, updateQuery } = optimisticUpdateDefinition return { queryKey: getQueryKey(item), @@ -244,11 +253,11 @@ function getOptimisticUpdateDefinitionForSpecificItem(optimisticUpdateDefinition /** * Translates a Wasp query specifier to a query cache key used by React Query. * - * @param {QuerySpecifier} querySpecifier A query specifier that's a part of the public API: + * @param querySpecifier A query specifier that's a part of the public API: * https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * @returns {QueryKey} A cache key React Query internally uses for addressing queries. + * @returns A cache key React Query internally uses for addressing queries. */ -function getRqQueryKeyFromSpecifier(querySpecifier) { +function getRqQueryKeyFromSpecifier(querySpecifier: QuerySpecifier): QueryKey { const [queryFn, ...otherKeys] = querySpecifier return [...queryFn.queryCacheKey, ...otherKeys] } diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/ext-src/MainPage.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/ext-src/MainPage.tsx similarity index 100% rename from waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/ext-src/MainPage.js rename to waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/ext-src/MainPage.tsx diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/ext-src/jsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/ext-src/jsconfig.json deleted file mode 100644 index e9b5551fd7..0000000000 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/ext-src/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/web-app/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/ext-src/react-app-env.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/ext-src/react-app-env.d.ts new file mode 100644 index 0000000000..e80934ce3a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/ext-src/react-app-env.d.ts @@ -0,0 +1,60 @@ +declare module '*.avif' { + const src: string; + export default src; +} + +declare module '*.bmp' { + const src: string; + export default src; +} + +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + import * as React from 'react'; + + export const ReactComponent: React.FunctionComponent & { title?: string }>; + + const src: string; + export default src; +} + +declare module '*.module.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/queries/core.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/queries/core.d.ts new file mode 100644 index 0000000000..edde495db4 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/queries/core.d.ts @@ -0,0 +1,3 @@ +export type Query = (args: Input) => Promise + +export function createQuery(queryRoute: string, entitiesUsed: any[]): Query diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/queries/index.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/queries/index.d.ts new file mode 100644 index 0000000000..a331fa9d73 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/queries/index.d.ts @@ -0,0 +1,8 @@ +import { UseQueryResult } from "@tanstack/react-query"; +import { OutputHTMLAttributes } from "react"; +import { Query } from "./core"; + +export function useQuery( + queryFn: Query, + queryFnArgs?: Input, options?: any +): UseQueryResult diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/router.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/router.js index c783ed20ac..7d3f45f130 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/router.js +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/router.js @@ -2,7 +2,7 @@ import React from 'react' import { Route, BrowserRouter as Router } from 'react-router-dom' -import MainPage from "./ext-src/MainPage.js" +import MainPage from "./ext-src/MainPage" const router = ( diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/shared/jsconfig.json deleted file mode 100644 index 0c4e7f7eb1..0000000000 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/src/shared/jsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", - "paths": { - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/tsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/tsconfig.json new file mode 100644 index 0000000000..3fab473aae --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/.wasp/out/web-app/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es2018", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx" + }, + "include": [ + "src" + ] +} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/main.wasp b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/main.wasp index 0da6b25a52..d22b6a3b28 100644 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/main.wasp +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/main.wasp @@ -8,7 +8,7 @@ app waspJob { route RootRoute { path: "/", to: MainPage } page MainPage { - component: import Main from "@client/MainPage.js" + component: import Main from "@client/MainPage" } job MySpecialJob { executor: PgBoss, diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/MainPage.js b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/MainPage.tsx similarity index 100% rename from waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/MainPage.js rename to waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/MainPage.tsx diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/jsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/jsconfig.json deleted file mode 100644 index e9b5551fd7..0000000000 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/web-app/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/react-app-env.d.ts b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/react-app-env.d.ts new file mode 100644 index 0000000000..e80934ce3a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/react-app-env.d.ts @@ -0,0 +1,60 @@ +declare module '*.avif' { + const src: string; + export default src; +} + +declare module '*.bmp' { + const src: string; + export default src; +} + +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + import * as React from 'react'; + + export const ReactComponent: React.FunctionComponent & { title?: string }>; + + const src: string; + export default src; +} + +declare module '*.module.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/tsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/tsconfig.json new file mode 100644 index 0000000000..34c23b30ce --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/client/tsconfig.json @@ -0,0 +1,39 @@ +{ + "compilerOptions": { + // JSX support + "jsx": "preserve", + // Enable default imports in TypeScript. + "esModuleInterop": true, + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + // The following settings enable IDE support in user-provided source files. + // Editing them might break features like import autocompletion and + // definition lookup. Don't change them unless you know what you're doing. + // + // The relative path to the generated web app's root directory. This must be + // set to define the "paths" option. + "baseUrl": "../../.wasp/out/web-app/", + "paths": { + // Resolve all "@wasp" imports to the generated source code. + "@wasp/*": [ + "src/*" + ], + // Resolve all non-relative imports to the correct node module. Source: + // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping + "*": [ + // Start by looking for the definiton inside the node modules root + // directory... + "node_modules/*", + // ... If that fails, try to find it inside definitely-typed type + // definitions. + "node_modules/@types/*" + ] + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/web-app/node_modules/@types"] + } +} diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/server/jsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/server/jsconfig.json deleted file mode 100644 index 9e996fc5df..0000000000 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/server/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, Try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/jsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/server/tsconfig.json similarity index 75% rename from waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/jsconfig.json rename to waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/server/tsconfig.json index e9b5551fd7..8d313c4516 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/src/client/jsconfig.json +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/server/tsconfig.json @@ -1,12 +1,15 @@ { "compilerOptions": { - // The following settings enable IDE support in user-provided source files. + // Enable default imports in TypeScript. + "esModuleInterop": true, + "allowJs": true, + // The following settings enable IDE support in user-provided source files. // Editing them might break features like import autocompletion and // definition lookup. Don't change them unless you know what you're doing. // // The relative path to the generated web app's root directory. This must be // set to define the "paths" option. - "baseUrl": "../../.wasp/out/web-app/", + "baseUrl": "../../.wasp/out/server/", "paths": { // Resolve all "@wasp" imports to the generated source code. "@wasp/*": [ @@ -22,6 +25,8 @@ // definitions. "node_modules/@types/*" ] - } + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/server/node_modules/@types"] } } diff --git a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/shared/jsconfig.json deleted file mode 100644 index 0c4e7f7eb1..0000000000 --- a/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/shared/jsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", - "paths": { - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/shared/tsconfig.json similarity index 74% rename from waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/shared/jsconfig.json rename to waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/shared/tsconfig.json index 0c4e7f7eb1..20fcac8431 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/server/src/shared/jsconfig.json +++ b/waspc/e2e-test/test-outputs/waspJob-golden/waspJob/src/shared/tsconfig.json @@ -1,12 +1,15 @@ { "compilerOptions": { + // Enable default imports in TypeScript. + "esModuleInterop": true, + "allowJs": true, // The following settings enable IDE support in user-provided source files. // Editing them might break features like import autocompletion and // definition lookup. Don't change them unless you know what you're doing. // // The relative path to the generated web app's root directory. This must be // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", + "baseUrl": "../../.wasp/out/server/", "paths": { // Resolve all non-relative imports to the correct node module. Source: // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping @@ -18,6 +21,8 @@ // definitions. "node_modules/@types/*" ] - } + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/server/node_modules/@types"] } } diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/files.manifest b/waspc/e2e-test/test-outputs/waspMigrate-golden/files.manifest index 1f66cfceae..8d68519672 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/files.manifest +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/files.manifest @@ -10,13 +10,13 @@ waspMigrate/.wasp/out/db/schema.prisma.wasp-last-db-concurrence-checksum waspMigrate/.wasp/out/installedFullStackNpmDependencies.json waspMigrate/.wasp/out/server/.npmrc waspMigrate/.wasp/out/server/README.md +waspMigrate/.wasp/out/server/nodemon.json waspMigrate/.wasp/out/server/package.json waspMigrate/.wasp/out/server/src/app.js waspMigrate/.wasp/out/server/src/config.js waspMigrate/.wasp/out/server/src/core/AuthError.js waspMigrate/.wasp/out/server/src/core/HttpError.js waspMigrate/.wasp/out/server/src/dbClient.js -waspMigrate/.wasp/out/server/src/ext-src/jsconfig.json waspMigrate/.wasp/out/server/src/jobs/core/Job.js waspMigrate/.wasp/out/server/src/jobs/core/SubmittedJob.js waspMigrate/.wasp/out/server/src/jobs/core/allJobs.js @@ -25,9 +25,9 @@ waspMigrate/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js waspMigrate/.wasp/out/server/src/jobs/core/simpleJob.js waspMigrate/.wasp/out/server/src/routes/index.js waspMigrate/.wasp/out/server/src/routes/operations/index.js -waspMigrate/.wasp/out/server/src/server.js -waspMigrate/.wasp/out/server/src/shared/jsconfig.json +waspMigrate/.wasp/out/server/src/server.ts waspMigrate/.wasp/out/server/src/utils.js +waspMigrate/.wasp/out/server/tsconfig.json waspMigrate/.wasp/out/web-app/.npmrc waspMigrate/.wasp/out/web-app/README.md waspMigrate/.wasp/out/web-app/netlify.toml @@ -35,34 +35,38 @@ waspMigrate/.wasp/out/web-app/package.json waspMigrate/.wasp/out/web-app/public/favicon.ico waspMigrate/.wasp/out/web-app/public/index.html waspMigrate/.wasp/out/web-app/public/manifest.json +waspMigrate/.wasp/out/web-app/src/actions/core.d.ts waspMigrate/.wasp/out/web-app/src/actions/core.js -waspMigrate/.wasp/out/web-app/src/actions/index.js +waspMigrate/.wasp/out/web-app/src/actions/index.ts waspMigrate/.wasp/out/web-app/src/api.js waspMigrate/.wasp/out/web-app/src/config.js waspMigrate/.wasp/out/web-app/src/ext-src/Main.css -waspMigrate/.wasp/out/web-app/src/ext-src/MainPage.js -waspMigrate/.wasp/out/web-app/src/ext-src/jsconfig.json +waspMigrate/.wasp/out/web-app/src/ext-src/MainPage.tsx +waspMigrate/.wasp/out/web-app/src/ext-src/react-app-env.d.ts waspMigrate/.wasp/out/web-app/src/ext-src/waspLogo.png waspMigrate/.wasp/out/web-app/src/index.js waspMigrate/.wasp/out/web-app/src/logo.png waspMigrate/.wasp/out/web-app/src/operations/index.js waspMigrate/.wasp/out/web-app/src/operations/resources.js waspMigrate/.wasp/out/web-app/src/operations/updateHandlersMap.js +waspMigrate/.wasp/out/web-app/src/queries/core.d.ts waspMigrate/.wasp/out/web-app/src/queries/core.js +waspMigrate/.wasp/out/web-app/src/queries/index.d.ts waspMigrate/.wasp/out/web-app/src/queries/index.js waspMigrate/.wasp/out/web-app/src/queryClient.js waspMigrate/.wasp/out/web-app/src/router.js waspMigrate/.wasp/out/web-app/src/serviceWorker.js -waspMigrate/.wasp/out/web-app/src/shared/jsconfig.json waspMigrate/.wasp/out/web-app/src/utils.js +waspMigrate/.wasp/out/web-app/tsconfig.json waspMigrate/.wasproot waspMigrate/main.wasp waspMigrate/migrations/migration_lock.toml waspMigrate/migrations/no-date-foo/migration.sql waspMigrate/src/.waspignore waspMigrate/src/client/Main.css -waspMigrate/src/client/MainPage.js -waspMigrate/src/client/jsconfig.json +waspMigrate/src/client/MainPage.tsx +waspMigrate/src/client/react-app-env.d.ts +waspMigrate/src/client/tsconfig.json waspMigrate/src/client/waspLogo.png -waspMigrate/src/server/jsconfig.json -waspMigrate/src/shared/jsconfig.json +waspMigrate/src/server/tsconfig.json +waspMigrate/src/shared/tsconfig.json diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums index 4a8c2fdda4..a963299055 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/.waspchecksums @@ -41,12 +41,19 @@ ], "e14514b8b152dd2160a217d8fc66a710c8607c4ed1441a2148a0770701818249" ], + [ + [ + "file", + "server/nodemon.json" + ], + "5d0e1103bbe7c29a7b3137a57345f8eeb4ccd8a2128d636cc1b2bd81cf348a86" + ], [ [ "file", "server/package.json" ], - "d8a937105f14d01810f5e90bc082ffa8647d9c24944eacedbe403125b19f4524" + "bce6e00bd69704487cd1affd859918d28cf1849b39a2f071b71008b559dd901d" ], [ [ @@ -83,13 +90,6 @@ ], "20c67ca197da3de2d37528ceaff2e40af910be8177f346c6d5c2b2f983810c43" ], - [ - [ - "file", - "server/src/ext-src/jsconfig.json" - ], - "4130060d02d39d5fdc11bdb288cfe08d36dc89be29ade017b16db6477e63c47a" - ], [ [ "file", @@ -123,7 +123,7 @@ "file", "server/src/jobs/core/pgBoss/pgBossJob.js" ], - "532ed0f34a2011cff2a9c43b712a513ba505e77d896455d6c7f36add6f88741d" + "ff6040d051c916eb080a2f2c37fd5135f588782387faeae51115d1a7abd1ad8b" ], [ [ @@ -149,23 +149,23 @@ [ [ "file", - "server/src/server.js" + "server/src/server.ts" ], - "e19bdae598265cbe2457ff1e2d8524aa821666482cb7d21644e290a68daf94a5" + "c6114654819216004f0ef4a8771a0c1213c655cfd41760fbd835077c53a6b6ba" ], [ [ "file", - "server/src/shared/jsconfig.json" + "server/src/utils.js" ], - "6972bc64315755788fd02be62c44ea8ffb60dd874b863fca2878f6160ab4b0e2" + "68a5794f55e24b303d81456a1181a3a2cd70773f6ebc4e7a63dac064834aa8e9" ], [ [ "file", - "server/src/utils.js" + "server/tsconfig.json" ], - "68a5794f55e24b303d81456a1181a3a2cd70773f6ebc4e7a63dac064834aa8e9" + "3038f152754646d2c46de78e099e9e6129bfb2541e4dccd37a05a5632ab4d838" ], [ [ @@ -200,7 +200,7 @@ "file", "web-app/package.json" ], - "d85f92e70846628060835b637c590a1ea40d881c2abbd530a2850dd9ad5aae87" + "ee671ff487639300e333505c68bb11fe705068c5214c0debd7c74e1b5d8452da" ], [ [ @@ -223,6 +223,13 @@ ], "c91b7ea515a4889c4abfd355500c8260210602093a94c0beee302450272c3737" ], + [ + [ + "file", + "web-app/src/actions/core.d.ts" + ], + "c18e166c8f43bd3a6a8d78f8fc2f51fe82e956cd71b3464c59076f8dec660b24" + ], [ [ "file", @@ -233,9 +240,9 @@ [ [ "file", - "web-app/src/actions/index.js" + "web-app/src/actions/index.ts" ], - "7da2524a6920c46aada7e60e29fbe24d0e45e4bfcf7bf3044d16d11ab89a965e" + "bc520b1d83577c6640472dd5c110228a3617b050d3a4d091495ec065c57011bc" ], [ [ @@ -261,16 +268,16 @@ [ [ "file", - "web-app/src/ext-src/MainPage.js" + "web-app/src/ext-src/MainPage.tsx" ], "c9ed9b5271f648715373095f43d60a2ab3e47f159c6dd6f3337ed22e5b73e80c" ], [ [ "file", - "web-app/src/ext-src/jsconfig.json" + "web-app/src/ext-src/react-app-env.d.ts" ], - "06804c81fa3b227c1b3a04e950f8db9ed85bf41d042b90e8e8332856016e113f" + "c9e89cb25e83121c0c451125de7a0b0569161e2bf18f83bc5f69836403910744" ], [ [ @@ -314,6 +321,13 @@ ], "07a9933a771853585fd2fc49c3dcb9f1cad947acb2168580c835fae25620fa9f" ], + [ + [ + "file", + "web-app/src/queries/core.d.ts" + ], + "f0b289140e92738451be386ca73a2fd1c84e9951eb2f1b9c6c09dfa3079d0c74" + ], [ [ "file", @@ -321,6 +335,13 @@ ], "2daf5b414722204281d65e954ce862a6fc586e8907b202800694909d23957c5e" ], + [ + [ + "file", + "web-app/src/queries/index.d.ts" + ], + "3eb32c063fc77fa5aa3f3b3a12c51ca8a52fc3cd0de21f4e9463a56cc374003c" + ], [ [ "file", @@ -340,7 +361,7 @@ "file", "web-app/src/router.js" ], - "dd6f5f5c6981df1935c02437d7a6ae343841300c3f7e99b0ad6ca62e95071421" + "65a91308a13f2c8444e3ad7372c1fca85a194b85e8f8f7d11613f78fcfe7af6f" ], [ [ @@ -352,15 +373,15 @@ [ [ "file", - "web-app/src/shared/jsconfig.json" + "web-app/src/utils.js" ], - "6972bc64315755788fd02be62c44ea8ffb60dd874b863fca2878f6160ab4b0e2" + "0ae6e53a050dbc6b7166aedfd5b076c2cab524c4d6aff884dc6902b178148815" ], [ [ "file", - "web-app/src/utils.js" + "web-app/tsconfig.json" ], - "0ae6e53a050dbc6b7166aedfd5b076c2cab524c4d6aff884dc6902b178148815" + "0612639442958ae18a96d651a6c385fba1a682f04d09e293efd380006fc4df99" ] ] \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedFullStackNpmDependencies.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedFullStackNpmDependencies.json index 0da1a29518..69a7a39ba5 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedFullStackNpmDependencies.json +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/installedFullStackNpmDependencies.json @@ -1 +1 @@ -{"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"express","version":"~4.18.1"},{"name":"morgan","version":"~1.10.0"},{"name":"@prisma/client","version":"4.5.0"},{"name":"jsonwebtoken","version":"^8.5.1"},{"name":"secure-password","version":"^4.0.0"},{"name":"dotenv","version":"16.0.2"},{"name":"helmet","version":"^6.0.0"},{"name":"patch-package","version":"^6.4.7"},{"name":"uuid","version":"^9.0.0"},{"name":"lodash","version":"^4.17.21"}],"devDependencies":[{"name":"nodemon","version":"^2.0.19"},{"name":"standard","version":"^17.0.0"},{"name":"prisma","version":"4.5.0"}]},"npmDepsForWebApp":{"dependencies":[{"name":"axios","version":"^0.27.2"},{"name":"react","version":"^17.0.2"},{"name":"react-dom","version":"^17.0.2"},{"name":"@tanstack/react-query","version":"^4.13.0"},{"name":"react-router-dom","version":"^5.3.3"},{"name":"react-scripts","version":"5.0.1"}],"devDependencies":[]}} \ No newline at end of file +{"npmDepsForServer":{"dependencies":[{"name":"cookie-parser","version":"~1.4.6"},{"name":"cors","version":"^2.8.5"},{"name":"express","version":"~4.18.1"},{"name":"morgan","version":"~1.10.0"},{"name":"@prisma/client","version":"4.5.0"},{"name":"jsonwebtoken","version":"^8.5.1"},{"name":"secure-password","version":"^4.0.0"},{"name":"dotenv","version":"16.0.2"},{"name":"helmet","version":"^6.0.0"},{"name":"patch-package","version":"^6.4.7"},{"name":"uuid","version":"^9.0.0"},{"name":"lodash","version":"^4.17.21"}],"devDependencies":[{"name":"nodemon","version":"^2.0.19"},{"name":"standard","version":"^17.0.0"},{"name":"prisma","version":"4.5.0"},{"name":"typescript","version":"^4.8.4"},{"name":"@types/node","version":"^18.11.9"}]},"npmDepsForWebApp":{"dependencies":[{"name":"axios","version":"^0.27.2"},{"name":"react","version":"^17.0.2"},{"name":"react-dom","version":"^17.0.2"},{"name":"@tanstack/react-query","version":"^4.13.0"},{"name":"react-router-dom","version":"^5.3.3"},{"name":"react-scripts","version":"5.0.1"}],"devDependencies":[{"name":"typescript","version":"^4.8.4"},{"name":"@types/react","version":"^18.0.25"},{"name":"@types/react-dom","version":"^18.0.8"},{"name":"@types/react-router-dom","version":"^5.3.3"}]}} \ No newline at end of file diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/nodemon.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/nodemon.json new file mode 100644 index 0000000000..92d00152d9 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/nodemon.json @@ -0,0 +1,9 @@ +{ + "env": { + "NODE_ENV": "development" + }, + "watch": [ + "src/" + ], + "ext": "ts,mts,js,mjs,json" +} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/package.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/package.json index 5a82436e47..d0b0bdf1c1 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/package.json +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/package.json @@ -14,9 +14,11 @@ "uuid": "^9.0.0" }, "devDependencies": { + "@types/node": "^18.11.9", "nodemon": "^2.0.19", "prisma": "4.5.0", - "standard": "^17.0.0" + "standard": "^17.0.0", + "typescript": "^4.8.4" }, "engineStrict": true, "engines": { @@ -34,13 +36,15 @@ }, "private": true, "scripts": { + "build": "npx tsc", + "build-and-start": "npm run build && npm run start", "db-migrate-dev": "prisma migrate dev --schema=../db/schema.prisma", "db-migrate-prod": "prisma migrate deploy --schema=../db/schema.prisma", "postinstall": "patch-package", "standard": "standard", - "start": "nodemon -r dotenv/config ./src/server.js", - "start-production": "npm run db-migrate-prod && NODE_ENV=production node ./src/server.js" + "start": "NODE_PATH=dist node dist/server.js", + "start-production": "npm run db-migrate-prod && NODE_ENV=production npm run start", + "watch": "nodemon -r dotenv/config --exec 'npm run build-and-start || exit 1'" }, - "type": "module", "version": "0.0.0" } diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/ext-src/jsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/ext-src/jsconfig.json deleted file mode 100644 index 9e996fc5df..0000000000 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/ext-src/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, Try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js index a9ac57c367..b9267c967a 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/jobs/core/pgBoss/pgBossJob.js @@ -55,7 +55,7 @@ class PgBossJob extends Job { * @param {object} jobArgs - The job arguments supplied by the user for their perform callback. * @param {object} jobOptions - pg-boss specific options for `boss.send()`, which can override their defaultJobOptions. */ - async submit(jobArgs, jobOptions) { + async submit(jobArgs, jobOptions = {}) { const boss = await pgBossStarted const jobId = await boss.send(this.jobName, jobArgs, { ...this.#defaultJobOptions, ...(this.#startAfter && { startAfter: this.#startAfter }), ...jobOptions }) diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/server.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/server.ts similarity index 95% rename from waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/server.js rename to waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/server.ts index 747b00a051..e4b32230de 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/server.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/server.ts @@ -15,7 +15,7 @@ const startServer = async () => { server.listen(port) - server.on('error', (error) => { + server.on('error', (error: NodeJS.ErrnoException) => { if (error.syscall !== 'listen') throw error const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port // handle specific listen errors with friendly messages diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/shared/jsconfig.json deleted file mode 100644 index 0c4e7f7eb1..0000000000 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/src/shared/jsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", - "paths": { - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/tsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/tsconfig.json new file mode 100644 index 0000000000..97afa9c21e --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/server/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + // Enable default imports in TypeScript. + "esModuleInterop": true, + "module": "commonjs", + "moduleResolution": "node", + "outDir": "dist", + "allowJs": true, + // Enable source map for debugging + "sourceMap": true + } +} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/package.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/package.json index 7ab34aea58..efee59a547 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/package.json +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/package.json @@ -19,7 +19,12 @@ "react-router-dom": "^5.3.3", "react-scripts": "5.0.1" }, - "devDependencies": {}, + "devDependencies": { + "@types/react": "^18.0.25", + "@types/react-dom": "^18.0.8", + "@types/react-router-dom": "^5.3.3", + "typescript": "^4.8.4" + }, "engineStrict": true, "engines": { "node": "^18.12.0", diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/actions/core.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/actions/core.d.ts new file mode 100644 index 0000000000..1171c7e1b4 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/actions/core.d.ts @@ -0,0 +1,3 @@ +export type Action = (args?: Input) => Promise; + +export function createAction(actionRoute: string, entitiesUsed: unknown[]): Action diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/actions/index.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/actions/index.ts similarity index 62% rename from waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/actions/index.js rename to waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/actions/index.ts index cf97f19264..85dba33baa 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/actions/index.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/actions/index.ts @@ -1,93 +1,57 @@ import { + QueryClient, + QueryKey, useMutation, + UseMutationOptions, useQueryClient, } from '@tanstack/react-query' - -export { configureQueryClient } from '../queryClient' +import { Action } from './core'; /** * An options object passed into the `useAction` hook and used to enhance the * action with extra options. * - * @typedef {Object} ActionOptions - * @property {PublicOptimisticUpdateDefinition[]} optimisticUpdates */ +export type ActionOptions = { + optimisticUpdates: OptimisticUpdateDefinition[]; +} /** * A documented (public) way to define optimistic updates. - * - * @typedef {Object} PublicOptimisticUpdateDefinition - * @property {GetQuerySpecifier} querySpecifier - * @property {UpdateQuery} updateQuery */ +export type OptimisticUpdateDefinition = { + getQuerySpecifier: GetQuerySpecifier; + updateQuery: UpdateQuery; +} /** * A function that takes an item and returns a Wasp Query specifier. - * - * @callback GetQuerySpecifier - * @param {T} item - * @returns {QuerySpecifier} */ +export type GetQuerySpecifier = (item: Item) => QuerySpecifier /** * A function that takes an item and the previous state of the cache, and returns * the desired (new) state of the cache. - * - * @callback UpdateQuery - * @param {T} item - * @param {T[]} oldData - * @returns {T[]} */ +export type UpdateQuery = (item: ActionInput, oldData: CacheItem[]) => CacheItem[] /** * A public query specifier used for addressing Wasp queries. See our docs for details: * https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * - * @typedef {any[]} QuerySpecifier - */ - -/** - * An internal (undocumented, private, desugared) way of defining optimistic updates. - * - * @typedef {Object} InternalOptimisticUpdateDefinition - * @property {GetQuerySpecifier} querySpecifier - * @property {UpdateQuery} updateQuery - */ - -/** - * An UpdateQuery function "instantiated" with a specific item. It only takes - * the current state of the cache and returns the desired (new) state of the - * cache. - * - * @callback SpecificUpdateQuery - * @param {any[]} oldData - */ - -/** - * A specific, "instantiated" optimistic update definition which contains a - * fully-constructed query key and a specific update function. - * - * @typedef {Object} SpecificOptimisticUpdateDefinition - * @property {QueryKey} queryKey - * @property {SpecificUpdateQuery} updateQuery -*/ - -/** - * An array React Query uses to address queries. See their docs for details: - * https://react-query-v3.tanstack.com/guides/query-keys#array-keys. - * - * @typedef {any[]} QueryKey */ - +export type QuerySpecifier = any[] /** * A hook for adding extra behavior to a Wasp Action (e.g., optimistic updates). * * @param actionFn The Wasp Action you wish to enhance/decorate. - * @param {ActionOptions} actionOptions An options object for enhancing/decorating the given Action. + * @param actionOptions An options object for enhancing/decorating the given Action. * @returns A decorated Action with added behavior but an unchanged API. */ -export function useAction(actionFn, actionOptions) { +export function useAction( + actionFn: (item: ActionInput) => Promise, + actionOptions: ActionOptions +): typeof actionFn { const queryClient = useQueryClient(); let mutationFn = actionFn @@ -110,14 +74,49 @@ export function useAction(actionFn, actionOptions) { } /** - * Translates/Desugars a public optimistic update definition object into a definition object our - * system uses internally. + * An internal (undocumented, private, desugared) way of defining optimistic updates. + */ +type InternalOptimisticUpdateDefinition = { + getQueryKey: (item: ActionInput) => QueryKey, + updateQuery: UpdateQuery; + +} + +/** + * An UpdateQuery function "instantiated" with a specific item. It only takes + * the current state of the cache and returns the desired (new) state of the + * cache. + */ +type SpecificUpdateQuery = (oldData: Item[]) => Item[] + +/** + * A specific, "instantiated" optimistic update definition which contains a + * fully-constructed query key and a specific update function. + */ +type SpecificOptimisticUpdateDefinition = { + queryKey: QueryKey; + updateQuery: SpecificUpdateQuery; +} + +type InternalAction = Action & { + internal( + item: Input, + optimisticUpdateDefinitions: SpecificOptimisticUpdateDefinition[] + ): Promise +} + +/** + * Translates/Desugars a public optimistic update definition object into a + * definition object our system uses internally. * - * @param {PublicOptimisticUpdateDefinition} publicOptimisticUpdateDefinition An optimistic update definition - * object that's a part of the public API: https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * @returns {InternalOptimisticUpdateDefinition} An internally-used optimistic update definition object. + * @param publicOptimisticUpdateDefinition An optimistic update definition + * object that's a part of the public API: + * https://wasp-lang.dev/docs/language/features#the-useaction-hook. + * @returns An internally-used optimistic update definition object. */ -function translateToInternalDefinition(publicOptimisticUpdateDefinition) { +function translateToInternalDefinition( + publicOptimisticUpdateDefinition: OptimisticUpdateDefinition +): InternalOptimisticUpdateDefinition { const { getQuerySpecifier, updateQuery } = publicOptimisticUpdateDefinition const definitionErrors = [] @@ -141,17 +140,19 @@ function translateToInternalDefinition(publicOptimisticUpdateDefinition) { * Creates a function that performs an action while telling it about the * optimistic updates it caused. * - * @param actionFn - The Wasp Action. - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinitions - The optimisitc updates the - * action causes. - * @returns A + * @param actionFn The Wasp Action. + * @param optimisticUpdateDefinitions The optimisitc updates the action causes. + * @returns An decorated action which performs optimistic updates. */ -function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) { +function makeOptimisticUpdateMutationFn( + actionFn: Action, + optimisticUpdateDefinitions: InternalOptimisticUpdateDefinition[] +): typeof actionFn { return function performActionWithOptimisticUpdates(item) { const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map( generalDefinition => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item) ) - return actionFn.internal(item, specificOptimisticUpdateDefinitions) + return (actionFn as InternalAction).internal(item, specificOptimisticUpdateDefinitions) } } @@ -163,13 +164,18 @@ function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) { * optimistic updates definition. Check their docs for details: * https://tanstack.com/query/v4/docs/guides/optimistic-updates?from=reactQueryV3&original=https://react-query-v3.tanstack.com/guides/optimistic-updates * - * @param {Object} queryClient The QueryClient instance used by React Query. - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinitions A list containing internal optimistic updates definition objects - * (i.e., a list where each object carries the instructions for performing particular optimistic update). - * @returns {Object} An object containing 'onMutate' and 'onError' functions corresponding to the given optimistic update - * definitions (check the docs linked above for details). + * @param queryClient The QueryClient instance used by React Query. + * @param optimisticUpdateDefinitions A list containing internal optimistic + * updates definition objects (i.e., a list where each object carries the + * instructions for performing particular optimistic update). + * @returns An object containing 'onMutate' and 'onError' functions + * corresponding to the given optimistic update definitions (check the docs + * linked above for details). */ -function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) { +function makeRqOptimisticUpdateOptions( + queryClient: QueryClient, + optimisticUpdateDefinitions: InternalOptimisticUpdateDefinition[] +): Pick { async function onMutate(item) { const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map( generalDefinition => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item) @@ -187,7 +193,7 @@ function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) const previousData = new Map() specificOptimisticUpdateDefinitions.forEach(({ queryKey, updateQuery }) => { // Snapshot the currently cached value. - const previousDataForQuery = queryClient.getQueryData(queryKey) + const previousDataForQuery: CacheItem[] = queryClient.getQueryData(queryKey) // Attempt to optimistically update the cache using the new value. try { @@ -227,13 +233,16 @@ function makeRqOptimisticUpdateOptions(queryClient, optimisticUpdateDefinitions) * uses a closure over the updated item to construct an item-specific query key * (e.g., useful when the query key depends on an ID). * - * @param {InternalOptimisticUpdateDefinition} optimisticUpdateDefinition The general, "uninstantiated" optimistic + * @param optimisticUpdateDefinition The general, "uninstantiated" optimistic * update definition with a function for constructing the query key. - * @param item The item triggering the Action/optimistic update (i.e., the argument passed to the Action). - * @returns {SpecificOptimisticUpdateDefinition} A specific optimistic update definition - * which corresponds to the provided definition and closes over the provided item. + * @param item The item triggering the Action/optimistic update (i.e., the + * argument passed to the Action). + * @returns A specific optimistic update definition which corresponds to the + * provided definition and closes over the provided item. */ -function getOptimisticUpdateDefinitionForSpecificItem(optimisticUpdateDefinition, item) { +function getOptimisticUpdateDefinitionForSpecificItem( + optimisticUpdateDefinition: InternalOptimisticUpdateDefinition, item: ActionInput +): SpecificOptimisticUpdateDefinition { const { getQueryKey, updateQuery } = optimisticUpdateDefinition return { queryKey: getQueryKey(item), @@ -244,11 +253,11 @@ function getOptimisticUpdateDefinitionForSpecificItem(optimisticUpdateDefinition /** * Translates a Wasp query specifier to a query cache key used by React Query. * - * @param {QuerySpecifier} querySpecifier A query specifier that's a part of the public API: + * @param querySpecifier A query specifier that's a part of the public API: * https://wasp-lang.dev/docs/language/features#the-useaction-hook. - * @returns {QueryKey} A cache key React Query internally uses for addressing queries. + * @returns A cache key React Query internally uses for addressing queries. */ -function getRqQueryKeyFromSpecifier(querySpecifier) { +function getRqQueryKeyFromSpecifier(querySpecifier: QuerySpecifier): QueryKey { const [queryFn, ...otherKeys] = querySpecifier return [...queryFn.queryCacheKey, ...otherKeys] } diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/ext-src/MainPage.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/ext-src/MainPage.tsx similarity index 100% rename from waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/ext-src/MainPage.js rename to waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/ext-src/MainPage.tsx diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/ext-src/jsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/ext-src/jsconfig.json deleted file mode 100644 index e9b5551fd7..0000000000 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/ext-src/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/web-app/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/ext-src/react-app-env.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/ext-src/react-app-env.d.ts new file mode 100644 index 0000000000..e80934ce3a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/ext-src/react-app-env.d.ts @@ -0,0 +1,60 @@ +declare module '*.avif' { + const src: string; + export default src; +} + +declare module '*.bmp' { + const src: string; + export default src; +} + +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + import * as React from 'react'; + + export const ReactComponent: React.FunctionComponent & { title?: string }>; + + const src: string; + export default src; +} + +declare module '*.module.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/queries/core.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/queries/core.d.ts new file mode 100644 index 0000000000..edde495db4 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/queries/core.d.ts @@ -0,0 +1,3 @@ +export type Query = (args: Input) => Promise + +export function createQuery(queryRoute: string, entitiesUsed: any[]): Query diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/queries/index.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/queries/index.d.ts new file mode 100644 index 0000000000..a331fa9d73 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/queries/index.d.ts @@ -0,0 +1,8 @@ +import { UseQueryResult } from "@tanstack/react-query"; +import { OutputHTMLAttributes } from "react"; +import { Query } from "./core"; + +export function useQuery( + queryFn: Query, + queryFnArgs?: Input, options?: any +): UseQueryResult diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/router.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/router.js index c783ed20ac..7d3f45f130 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/router.js +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/router.js @@ -2,7 +2,7 @@ import React from 'react' import { Route, BrowserRouter as Router } from 'react-router-dom' -import MainPage from "./ext-src/MainPage.js" +import MainPage from "./ext-src/MainPage" const router = ( diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/shared/jsconfig.json deleted file mode 100644 index 0c4e7f7eb1..0000000000 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/src/shared/jsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", - "paths": { - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/tsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/tsconfig.json new file mode 100644 index 0000000000..3fab473aae --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/.wasp/out/web-app/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es2018", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx" + }, + "include": [ + "src" + ] +} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/main.wasp b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/main.wasp index 7d05ec6757..c02a2e5faa 100644 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/main.wasp +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/main.wasp @@ -7,7 +7,7 @@ app waspMigrate { route RootRoute { path: "/", to: MainPage } page MainPage { - component: import Main from "@client/MainPage.js" + component: import Main from "@client/MainPage" } entity Task {=psl id Int @id @default(autoincrement()) diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/MainPage.js b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/MainPage.tsx similarity index 100% rename from waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/MainPage.js rename to waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/MainPage.tsx diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/jsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/jsconfig.json deleted file mode 100644 index e9b5551fd7..0000000000 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/web-app/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/react-app-env.d.ts b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/react-app-env.d.ts new file mode 100644 index 0000000000..e80934ce3a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/react-app-env.d.ts @@ -0,0 +1,60 @@ +declare module '*.avif' { + const src: string; + export default src; +} + +declare module '*.bmp' { + const src: string; + export default src; +} + +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + import * as React from 'react'; + + export const ReactComponent: React.FunctionComponent & { title?: string }>; + + const src: string; + export default src; +} + +declare module '*.module.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/tsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/tsconfig.json new file mode 100644 index 0000000000..34c23b30ce --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/client/tsconfig.json @@ -0,0 +1,39 @@ +{ + "compilerOptions": { + // JSX support + "jsx": "preserve", + // Enable default imports in TypeScript. + "esModuleInterop": true, + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + // The following settings enable IDE support in user-provided source files. + // Editing them might break features like import autocompletion and + // definition lookup. Don't change them unless you know what you're doing. + // + // The relative path to the generated web app's root directory. This must be + // set to define the "paths" option. + "baseUrl": "../../.wasp/out/web-app/", + "paths": { + // Resolve all "@wasp" imports to the generated source code. + "@wasp/*": [ + "src/*" + ], + // Resolve all non-relative imports to the correct node module. Source: + // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping + "*": [ + // Start by looking for the definiton inside the node modules root + // directory... + "node_modules/*", + // ... If that fails, try to find it inside definitely-typed type + // definitions. + "node_modules/@types/*" + ] + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/web-app/node_modules/@types"] + } +} diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/server/jsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/server/jsconfig.json deleted file mode 100644 index 9e996fc5df..0000000000 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/server/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, Try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/ext-src/jsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/server/tsconfig.json similarity index 75% rename from waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/ext-src/jsconfig.json rename to waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/server/tsconfig.json index e9b5551fd7..8d313c4516 100644 --- a/waspc/e2e-test/test-outputs/waspBuild-golden/waspBuild/.wasp/build/web-app/src/ext-src/jsconfig.json +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/server/tsconfig.json @@ -1,12 +1,15 @@ { "compilerOptions": { - // The following settings enable IDE support in user-provided source files. + // Enable default imports in TypeScript. + "esModuleInterop": true, + "allowJs": true, + // The following settings enable IDE support in user-provided source files. // Editing them might break features like import autocompletion and // definition lookup. Don't change them unless you know what you're doing. // // The relative path to the generated web app's root directory. This must be // set to define the "paths" option. - "baseUrl": "../../.wasp/out/web-app/", + "baseUrl": "../../.wasp/out/server/", "paths": { // Resolve all "@wasp" imports to the generated source code. "@wasp/*": [ @@ -22,6 +25,8 @@ // definitions. "node_modules/@types/*" ] - } + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/server/node_modules/@types"] } } diff --git a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/shared/jsconfig.json deleted file mode 100644 index 0c4e7f7eb1..0000000000 --- a/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/shared/jsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", - "paths": { - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/shared/tsconfig.json similarity index 74% rename from waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/shared/jsconfig.json rename to waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/shared/tsconfig.json index 0c4e7f7eb1..20fcac8431 100644 --- a/waspc/e2e-test/test-outputs/waspCompile-golden/waspCompile/.wasp/out/server/src/shared/jsconfig.json +++ b/waspc/e2e-test/test-outputs/waspMigrate-golden/waspMigrate/src/shared/tsconfig.json @@ -1,12 +1,15 @@ { "compilerOptions": { + // Enable default imports in TypeScript. + "esModuleInterop": true, + "allowJs": true, // The following settings enable IDE support in user-provided source files. // Editing them might break features like import autocompletion and // definition lookup. Don't change them unless you know what you're doing. // // The relative path to the generated web app's root directory. This must be // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", + "baseUrl": "../../.wasp/out/server/", "paths": { // Resolve all non-relative imports to the correct node module. Source: // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping @@ -18,6 +21,8 @@ // definitions. "node_modules/@types/*" ] - } + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/server/node_modules/@types"] } } diff --git a/waspc/e2e-test/test-outputs/waspNew-golden/files.manifest b/waspc/e2e-test/test-outputs/waspNew-golden/files.manifest index 733afa0d13..4eb89e5e47 100644 --- a/waspc/e2e-test/test-outputs/waspNew-golden/files.manifest +++ b/waspc/e2e-test/test-outputs/waspNew-golden/files.manifest @@ -2,8 +2,9 @@ waspNew/.wasproot waspNew/main.wasp waspNew/src/.waspignore waspNew/src/client/Main.css -waspNew/src/client/MainPage.js -waspNew/src/client/jsconfig.json +waspNew/src/client/MainPage.tsx +waspNew/src/client/react-app-env.d.ts +waspNew/src/client/tsconfig.json waspNew/src/client/waspLogo.png -waspNew/src/server/jsconfig.json -waspNew/src/shared/jsconfig.json +waspNew/src/server/tsconfig.json +waspNew/src/shared/tsconfig.json diff --git a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/main.wasp b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/main.wasp index f6df3a1d61..7ed02e0d04 100644 --- a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/main.wasp +++ b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/main.wasp @@ -7,5 +7,5 @@ app waspNew { route RootRoute { path: "/", to: MainPage } page MainPage { - component: import Main from "@client/MainPage.js" + component: import Main from "@client/MainPage" } diff --git a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/MainPage.js b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/MainPage.tsx similarity index 100% rename from waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/MainPage.js rename to waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/MainPage.tsx diff --git a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/jsconfig.json b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/jsconfig.json deleted file mode 100644 index e9b5551fd7..0000000000 --- a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/web-app/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/react-app-env.d.ts b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/react-app-env.d.ts new file mode 100644 index 0000000000..e80934ce3a --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/react-app-env.d.ts @@ -0,0 +1,60 @@ +declare module '*.avif' { + const src: string; + export default src; +} + +declare module '*.bmp' { + const src: string; + export default src; +} + +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + import * as React from 'react'; + + export const ReactComponent: React.FunctionComponent & { title?: string }>; + + const src: string; + export default src; +} + +declare module '*.module.css' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { readonly [key: string]: string }; + export default classes; +} + +declare module '*.module.sass' { + const classes: { readonly [key: string]: string }; + export default classes; +} diff --git a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/tsconfig.json b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/tsconfig.json new file mode 100644 index 0000000000..34c23b30ce --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/client/tsconfig.json @@ -0,0 +1,39 @@ +{ + "compilerOptions": { + // JSX support + "jsx": "preserve", + // Enable default imports in TypeScript. + "esModuleInterop": true, + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + // The following settings enable IDE support in user-provided source files. + // Editing them might break features like import autocompletion and + // definition lookup. Don't change them unless you know what you're doing. + // + // The relative path to the generated web app's root directory. This must be + // set to define the "paths" option. + "baseUrl": "../../.wasp/out/web-app/", + "paths": { + // Resolve all "@wasp" imports to the generated source code. + "@wasp/*": [ + "src/*" + ], + // Resolve all non-relative imports to the correct node module. Source: + // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping + "*": [ + // Start by looking for the definiton inside the node modules root + // directory... + "node_modules/*", + // ... If that fails, try to find it inside definitely-typed type + // definitions. + "node_modules/@types/*" + ] + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/web-app/node_modules/@types"] + } +} diff --git a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/server/jsconfig.json b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/server/jsconfig.json deleted file mode 100644 index 9e996fc5df..0000000000 --- a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/server/jsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server/", - "paths": { - // Resolve all "@wasp" imports to the generated source code. - "@wasp/*": [ - "src/*" - ], - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, Try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/server/tsconfig.json b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/server/tsconfig.json new file mode 100644 index 0000000000..8d313c4516 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/server/tsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + // Enable default imports in TypeScript. + "esModuleInterop": true, + "allowJs": true, + // The following settings enable IDE support in user-provided source files. + // Editing them might break features like import autocompletion and + // definition lookup. Don't change them unless you know what you're doing. + // + // The relative path to the generated web app's root directory. This must be + // set to define the "paths" option. + "baseUrl": "../../.wasp/out/server/", + "paths": { + // Resolve all "@wasp" imports to the generated source code. + "@wasp/*": [ + "src/*" + ], + // Resolve all non-relative imports to the correct node module. Source: + // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping + "*": [ + // Start by looking for the definiton inside the node modules root + // directory... + "node_modules/*", + // ... If that fails, try to find it inside definitely-typed type + // definitions. + "node_modules/@types/*" + ] + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/server/node_modules/@types"] + } +} diff --git a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/shared/jsconfig.json b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/shared/jsconfig.json deleted file mode 100644 index 0c4e7f7eb1..0000000000 --- a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/shared/jsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - // The following settings enable IDE support in user-provided source files. - // Editing them might break features like import autocompletion and - // definition lookup. Don't change them unless you know what you're doing. - // - // The relative path to the generated web app's root directory. This must be - // set to define the "paths" option. - "baseUrl": "../../.wasp/out/server", - "paths": { - // Resolve all non-relative imports to the correct node module. Source: - // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping - "*": [ - // Start by looking for the definiton inside the node modules root - // directory... - "node_modules/*", - // ... If that fails, try to find it inside definitely-typed type - // definitions. - "node_modules/@types/*" - ] - } - } -} diff --git a/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/shared/tsconfig.json b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/shared/tsconfig.json new file mode 100644 index 0000000000..20fcac8431 --- /dev/null +++ b/waspc/e2e-test/test-outputs/waspNew-golden/waspNew/src/shared/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + // Enable default imports in TypeScript. + "esModuleInterop": true, + "allowJs": true, + // The following settings enable IDE support in user-provided source files. + // Editing them might break features like import autocompletion and + // definition lookup. Don't change them unless you know what you're doing. + // + // The relative path to the generated web app's root directory. This must be + // set to define the "paths" option. + "baseUrl": "../../.wasp/out/server/", + "paths": { + // Resolve all non-relative imports to the correct node module. Source: + // https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping + "*": [ + // Start by looking for the definiton inside the node modules root + // directory... + "node_modules/*", + // ... If that fails, try to find it inside definitely-typed type + // definitions. + "node_modules/@types/*" + ] + }, + // Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots + "typeRoots": ["../../.wasp/out/server/node_modules/@types"] + } +}