on-zero 0.7.10 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{readme.md → README.md} +172 -231
- package/dist/cjs/cli.cjs +5 -2
- package/dist/cjs/cli.native.js +5 -2
- package/dist/cjs/cli.native.js.map +1 -1
- package/dist/cjs/combineZeroClients.cjs +2 -2
- package/dist/cjs/combineZeroClients.native.js +6 -6
- package/dist/cjs/combineZeroClients.native.js.map +1 -1
- package/dist/cjs/config.cjs +30 -0
- package/dist/cjs/config.native.js +33 -0
- package/dist/cjs/config.native.js.map +1 -0
- package/dist/cjs/createPermissions.cjs +2 -2
- package/dist/cjs/createPermissions.native.js +17 -27
- package/dist/cjs/createPermissions.native.js.map +1 -1
- package/dist/cjs/createUseQuery.cjs +3 -3
- package/dist/cjs/createUseQuery.native.js +4 -4
- package/dist/cjs/createUseQuery.native.js.map +1 -1
- package/dist/cjs/createUseQueryDirect.cjs +4 -3
- package/dist/cjs/createUseQueryDirect.native.js +14 -18
- package/dist/cjs/createUseQueryDirect.native.js.map +1 -1
- package/dist/cjs/createZeroClient.cjs +29 -9
- package/dist/cjs/createZeroClient.connection.test.cjs +11 -0
- package/dist/cjs/createZeroClient.connection.test.native.js +14 -7
- package/dist/cjs/createZeroClient.connection.test.native.js.map +1 -1
- package/dist/cjs/createZeroClient.native.js +58 -32
- package/dist/cjs/createZeroClient.native.js.map +1 -1
- package/dist/cjs/createZeroClient.recovery.test.cjs +90 -3
- package/dist/cjs/createZeroClient.recovery.test.native.js +109 -19
- package/dist/cjs/createZeroClient.recovery.test.native.js.map +1 -1
- package/dist/cjs/generate-helpers.cjs +70 -17
- package/dist/cjs/generate-helpers.native.js +110 -23
- package/dist/cjs/generate-helpers.native.js.map +1 -1
- package/dist/cjs/generate-layout.cjs +586 -0
- package/dist/cjs/generate-layout.native.js +1275 -0
- package/dist/cjs/generate-layout.native.js.map +1 -0
- package/dist/cjs/generate-lite.cjs +295 -27
- package/dist/cjs/generate-lite.native.js +854 -102
- package/dist/cjs/generate-lite.native.js.map +1 -1
- package/dist/cjs/generate-lite.test.cjs +433 -41
- package/dist/cjs/generate-lite.test.native.js +446 -41
- package/dist/cjs/generate-lite.test.native.js.map +1 -1
- package/dist/cjs/generate.cjs +172 -94
- package/dist/cjs/generate.native.js +324 -148
- package/dist/cjs/generate.native.js.map +1 -1
- package/dist/cjs/generate.test.cjs +362 -45
- package/dist/cjs/generate.test.native.js +374 -45
- package/dist/cjs/generate.test.native.js.map +1 -1
- package/dist/cjs/helpers/NullToOptional.cjs +18 -0
- package/dist/cjs/helpers/NullToOptional.native.js +21 -0
- package/dist/cjs/helpers/NullToOptional.native.js.map +1 -0
- package/dist/cjs/helpers/asyncContext.cjs +128 -0
- package/dist/cjs/helpers/asyncContext.native.js +87 -0
- package/dist/cjs/helpers/asyncContext.native.js.map +1 -0
- package/dist/cjs/helpers/batchQuery.cjs +2 -2
- package/dist/cjs/helpers/batchQuery.native.js +2 -2
- package/dist/cjs/helpers/batchQuery.native.js.map +1 -1
- package/dist/cjs/helpers/createMutators.cjs +7 -4
- package/dist/cjs/helpers/createMutators.native.js +12 -9
- package/dist/cjs/helpers/createMutators.native.js.map +1 -1
- package/dist/cjs/helpers/createMutators.test.native.js +2 -2
- package/dist/cjs/helpers/createMutators.test.native.js.map +1 -1
- package/dist/cjs/helpers/ellipsis.cjs +35 -0
- package/dist/cjs/helpers/ellipsis.native.js +38 -0
- package/dist/cjs/helpers/ellipsis.native.js.map +1 -0
- package/dist/cjs/helpers/emitter.cjs +99 -0
- package/dist/cjs/helpers/emitter.native.js +125 -0
- package/dist/cjs/helpers/emitter.native.js.map +1 -0
- package/dist/cjs/helpers/ensure.cjs +33 -0
- package/dist/cjs/helpers/ensure.native.js +37 -0
- package/dist/cjs/helpers/ensure.native.js.map +1 -0
- package/dist/cjs/helpers/ensureLoggedIn.cjs +2 -2
- package/dist/cjs/helpers/ensureLoggedIn.native.js +3 -3
- package/dist/cjs/helpers/ensureLoggedIn.native.js.map +1 -1
- package/dist/cjs/helpers/errors.cjs +40 -0
- package/dist/cjs/helpers/errors.native.js +152 -0
- package/dist/cjs/helpers/errors.native.js.map +1 -0
- package/dist/cjs/helpers/getCurrentComponentStack.cjs +71 -0
- package/dist/cjs/helpers/getCurrentComponentStack.native.js +93 -0
- package/dist/cjs/helpers/getCurrentComponentStack.native.js.map +1 -0
- package/dist/cjs/helpers/globalValue.cjs +39 -0
- package/dist/cjs/helpers/globalValue.native.js +42 -0
- package/dist/cjs/helpers/globalValue.native.js.map +1 -0
- package/dist/cjs/helpers/mapObject.cjs +36 -0
- package/dist/cjs/helpers/mapObject.native.js +39 -0
- package/dist/cjs/helpers/mapObject.native.js.map +1 -0
- package/dist/cjs/helpers/mutationLifecycle.cjs +251 -0
- package/dist/cjs/helpers/mutationLifecycle.native.js +392 -0
- package/dist/cjs/helpers/mutationLifecycle.native.js.map +1 -0
- package/dist/cjs/helpers/mutationLifecycle.test.cjs +174 -0
- package/dist/cjs/helpers/mutationLifecycle.test.native.js +182 -0
- package/dist/cjs/helpers/mutationLifecycle.test.native.js.map +1 -0
- package/dist/cjs/helpers/mutatorContext.cjs +3 -3
- package/dist/cjs/helpers/mutatorContext.native.js +5 -5
- package/dist/cjs/helpers/mutatorContext.native.js.map +1 -1
- package/dist/cjs/helpers/platform.cjs +31 -0
- package/dist/cjs/helpers/platform.native.js +33 -0
- package/dist/cjs/helpers/platform.native.js.map +1 -0
- package/dist/cjs/helpers/prettyFormatZeroQuery.cjs +2 -2
- package/dist/cjs/helpers/prettyFormatZeroQuery.native.js +7 -7
- package/dist/cjs/helpers/prettyFormatZeroQuery.native.js.map +1 -1
- package/dist/cjs/helpers/queryContext.cjs +2 -2
- package/dist/cjs/helpers/queryContext.native.js +4 -4
- package/dist/cjs/helpers/queryContext.native.js.map +1 -1
- package/dist/cjs/helpers/recoverZeroClient.cjs +14 -15
- package/dist/cjs/helpers/recoverZeroClient.native.js +26 -23
- package/dist/cjs/helpers/recoverZeroClient.native.js.map +1 -1
- package/dist/cjs/helpers/recoverZeroClient.test.cjs +10 -8
- package/dist/cjs/helpers/recoverZeroClient.test.native.js +17 -21
- package/dist/cjs/helpers/recoverZeroClient.test.native.js.map +1 -1
- package/dist/cjs/helpers/sleep.cjs +34 -0
- package/dist/cjs/helpers/sleep.native.js +39 -0
- package/dist/cjs/helpers/sleep.native.js.map +1 -0
- package/dist/cjs/helpers/time.cjs +47 -0
- package/dist/cjs/helpers/time.native.js +80 -0
- package/dist/cjs/helpers/time.native.js.map +1 -0
- package/dist/cjs/helpers/tuple.cjs +18 -0
- package/dist/cjs/helpers/tuple.native.js +21 -0
- package/dist/cjs/helpers/tuple.native.js.map +1 -0
- package/dist/cjs/helpers/useMutation.native.js +5 -5
- package/dist/cjs/helpers/useMutation.native.js.map +1 -1
- package/dist/cjs/helpers/useMutation.test.native.js +1 -1
- package/dist/cjs/helpers/useMutation.test.native.js.map +1 -1
- package/dist/cjs/helpers/useZeroDebug.cjs +2 -2
- package/dist/cjs/helpers/useZeroDebug.native.js +7 -8
- package/dist/cjs/helpers/useZeroDebug.native.js.map +1 -1
- package/dist/cjs/index.cjs +9 -1
- package/dist/cjs/index.native.js +8 -0
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/instanceRegistry.cjs +16 -4
- package/dist/cjs/instanceRegistry.native.js +56 -6
- package/dist/cjs/instanceRegistry.native.js.map +1 -1
- package/dist/cjs/multi.cjs +34 -13
- package/dist/cjs/multi.native.js +39 -17
- package/dist/cjs/multi.native.js.map +1 -1
- package/dist/cjs/multiInstance.test.cjs +6 -2
- package/dist/cjs/multiInstance.test.native.js +13 -9
- package/dist/cjs/multiInstance.test.native.js.map +1 -1
- package/dist/cjs/multiInstanceNested.test.native.js +10 -10
- package/dist/cjs/multiInstanceNested.test.native.js.map +1 -1
- package/dist/cjs/multiPartition.test.cjs +85 -36
- package/dist/cjs/multiPartition.test.native.js +102 -39
- package/dist/cjs/multiPartition.test.native.js.map +1 -1
- package/dist/cjs/mutations.cjs +2 -2
- package/dist/cjs/mutations.native.js +4 -4
- package/dist/cjs/mutations.native.js.map +1 -1
- package/dist/cjs/mutations.test.native.js +3 -3
- package/dist/cjs/mutations.test.native.js.map +1 -1
- package/dist/cjs/provideZero.hydration.test.cjs +3 -3
- package/dist/cjs/provideZero.hydration.test.native.js +4 -4
- package/dist/cjs/provideZero.hydration.test.native.js.map +1 -1
- package/dist/cjs/run.cjs +1 -1
- package/dist/cjs/run.native.js +3 -3
- package/dist/cjs/run.native.js.map +1 -1
- package/dist/cjs/server.cjs +20 -16
- package/dist/cjs/server.native.js +50 -57
- package/dist/cjs/server.native.js.map +1 -1
- package/dist/cjs/server.test.cjs +129 -6
- package/dist/cjs/server.test.native.js +141 -10
- package/dist/cjs/server.test.native.js.map +1 -1
- package/dist/cjs/serverWhere.test.native.js +3 -3
- package/dist/cjs/serverWhere.test.native.js.map +1 -1
- package/dist/cjs/state.cjs +2 -2
- package/dist/cjs/state.native.js +10 -10
- package/dist/cjs/state.native.js.map +1 -1
- package/dist/cjs/usePermission.test.native.js +3 -3
- package/dist/cjs/usePermission.test.native.js.map +1 -1
- package/dist/cjs/useQuery.empty.test.cjs +3 -3
- package/dist/cjs/useQuery.empty.test.native.js +6 -6
- package/dist/cjs/useQuery.empty.test.native.js.map +1 -1
- package/dist/cjs/useQuery.ssr.test.native.js +2 -2
- package/dist/cjs/useQuery.ssr.test.native.js.map +1 -1
- package/dist/cjs/vite-plugin.cjs +7 -8
- package/dist/cjs/vite-plugin.native.js +11 -11
- package/dist/cjs/vite-plugin.native.js.map +1 -1
- package/dist/cjs/where.cjs +3 -3
- package/dist/cjs/where.native.js +4 -4
- package/dist/cjs/where.native.js.map +1 -1
- package/dist/esm/cli.mjs +6 -3
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/cli.native.js +6 -3
- package/dist/esm/cli.native.js.map +1 -1
- package/dist/esm/combineZeroClients.mjs +1 -1
- package/dist/esm/combineZeroClients.mjs.map +1 -1
- package/dist/esm/combineZeroClients.native.js +5 -5
- package/dist/esm/combineZeroClients.native.js.map +1 -1
- package/dist/esm/config.mjs +5 -0
- package/dist/esm/config.mjs.map +1 -0
- package/dist/esm/config.native.js +5 -0
- package/dist/esm/config.native.js.map +1 -0
- package/dist/esm/createPermissions.mjs +1 -1
- package/dist/esm/createPermissions.mjs.map +1 -1
- package/dist/esm/createPermissions.native.js +16 -26
- package/dist/esm/createPermissions.native.js.map +1 -1
- package/dist/esm/createUseQuery.mjs +2 -2
- package/dist/esm/createUseQuery.mjs.map +1 -1
- package/dist/esm/createUseQuery.native.js +3 -3
- package/dist/esm/createUseQuery.native.js.map +1 -1
- package/dist/esm/createUseQueryDirect.mjs +2 -1
- package/dist/esm/createUseQueryDirect.mjs.map +1 -1
- package/dist/esm/createUseQueryDirect.native.js +12 -16
- package/dist/esm/createUseQueryDirect.native.js.map +1 -1
- package/dist/esm/createZeroClient.connection.test.mjs +11 -0
- package/dist/esm/createZeroClient.connection.test.mjs.map +1 -1
- package/dist/esm/createZeroClient.connection.test.native.js +14 -7
- package/dist/esm/createZeroClient.connection.test.native.js.map +1 -1
- package/dist/esm/createZeroClient.mjs +25 -5
- package/dist/esm/createZeroClient.mjs.map +1 -1
- package/dist/esm/createZeroClient.native.js +54 -28
- package/dist/esm/createZeroClient.native.js.map +1 -1
- package/dist/esm/createZeroClient.recovery.test.mjs +90 -3
- package/dist/esm/createZeroClient.recovery.test.mjs.map +1 -1
- package/dist/esm/createZeroClient.recovery.test.native.js +109 -19
- package/dist/esm/createZeroClient.recovery.test.native.js.map +1 -1
- package/dist/esm/generate-helpers.mjs +70 -18
- package/dist/esm/generate-helpers.mjs.map +1 -1
- package/dist/esm/generate-helpers.native.js +110 -24
- package/dist/esm/generate-helpers.native.js.map +1 -1
- package/dist/esm/generate-layout.mjs +560 -0
- package/dist/esm/generate-layout.mjs.map +1 -0
- package/dist/esm/generate-layout.native.js +1246 -0
- package/dist/esm/generate-layout.native.js.map +1 -0
- package/dist/esm/generate-lite.mjs +296 -28
- package/dist/esm/generate-lite.mjs.map +1 -1
- package/dist/esm/generate-lite.native.js +855 -103
- package/dist/esm/generate-lite.native.js.map +1 -1
- package/dist/esm/generate-lite.test.mjs +434 -42
- package/dist/esm/generate-lite.test.mjs.map +1 -1
- package/dist/esm/generate-lite.test.native.js +447 -42
- package/dist/esm/generate-lite.test.native.js.map +1 -1
- package/dist/esm/generate.mjs +172 -96
- package/dist/esm/generate.mjs.map +1 -1
- package/dist/esm/generate.native.js +324 -150
- package/dist/esm/generate.native.js.map +1 -1
- package/dist/esm/generate.test.mjs +366 -49
- package/dist/esm/generate.test.mjs.map +1 -1
- package/dist/esm/generate.test.native.js +378 -49
- package/dist/esm/generate.test.native.js.map +1 -1
- package/dist/esm/helpers/NullToOptional.mjs +2 -0
- package/dist/esm/helpers/NullToOptional.mjs.map +1 -0
- package/dist/esm/helpers/NullToOptional.native.js +2 -0
- package/dist/esm/helpers/NullToOptional.native.js.map +1 -0
- package/dist/esm/helpers/asyncContext.mjs +102 -0
- package/dist/esm/helpers/asyncContext.mjs.map +1 -0
- package/dist/esm/helpers/asyncContext.native.js +58 -0
- package/dist/esm/helpers/asyncContext.native.js.map +1 -0
- package/dist/esm/helpers/batchQuery.mjs +1 -1
- package/dist/esm/helpers/batchQuery.native.js +1 -1
- package/dist/esm/helpers/createMutators.mjs +5 -2
- package/dist/esm/helpers/createMutators.mjs.map +1 -1
- package/dist/esm/helpers/createMutators.native.js +10 -7
- package/dist/esm/helpers/createMutators.native.js.map +1 -1
- package/dist/esm/helpers/createMutators.test.native.js +2 -2
- package/dist/esm/helpers/createMutators.test.native.js.map +1 -1
- package/dist/esm/helpers/ellipsis.mjs +10 -0
- package/dist/esm/helpers/ellipsis.mjs.map +1 -0
- package/dist/esm/helpers/ellipsis.native.js +10 -0
- package/dist/esm/helpers/ellipsis.native.js.map +1 -0
- package/dist/esm/helpers/emitter.mjs +72 -0
- package/dist/esm/helpers/emitter.mjs.map +1 -0
- package/dist/esm/helpers/emitter.native.js +95 -0
- package/dist/esm/helpers/emitter.native.js.map +1 -0
- package/dist/esm/helpers/ensure.mjs +8 -0
- package/dist/esm/helpers/ensure.mjs.map +1 -0
- package/dist/esm/helpers/ensure.native.js +9 -0
- package/dist/esm/helpers/ensure.native.js.map +1 -0
- package/dist/esm/helpers/ensureLoggedIn.mjs +1 -1
- package/dist/esm/helpers/ensureLoggedIn.mjs.map +1 -1
- package/dist/esm/helpers/ensureLoggedIn.native.js +2 -2
- package/dist/esm/helpers/ensureLoggedIn.native.js.map +1 -1
- package/dist/esm/helpers/errors.mjs +14 -0
- package/dist/esm/helpers/errors.mjs.map +1 -0
- package/dist/esm/helpers/errors.native.js +123 -0
- package/dist/esm/helpers/errors.native.js.map +1 -0
- package/dist/esm/helpers/getCurrentComponentStack.mjs +35 -0
- package/dist/esm/helpers/getCurrentComponentStack.mjs.map +1 -0
- package/dist/esm/helpers/getCurrentComponentStack.native.js +54 -0
- package/dist/esm/helpers/getCurrentComponentStack.native.js.map +1 -0
- package/dist/esm/helpers/globalValue.mjs +14 -0
- package/dist/esm/helpers/globalValue.mjs.map +1 -0
- package/dist/esm/helpers/globalValue.native.js +14 -0
- package/dist/esm/helpers/globalValue.native.js.map +1 -0
- package/dist/esm/helpers/mapObject.mjs +11 -0
- package/dist/esm/helpers/mapObject.mjs.map +1 -0
- package/dist/esm/helpers/mapObject.native.js +11 -0
- package/dist/esm/helpers/mapObject.native.js.map +1 -0
- package/dist/esm/helpers/mutationLifecycle.mjs +221 -0
- package/dist/esm/helpers/mutationLifecycle.mjs.map +1 -0
- package/dist/esm/helpers/mutationLifecycle.native.js +359 -0
- package/dist/esm/helpers/mutationLifecycle.native.js.map +1 -0
- package/dist/esm/helpers/mutationLifecycle.test.mjs +175 -0
- package/dist/esm/helpers/mutationLifecycle.test.mjs.map +1 -0
- package/dist/esm/helpers/mutationLifecycle.test.native.js +180 -0
- package/dist/esm/helpers/mutationLifecycle.test.native.js.map +1 -0
- package/dist/esm/helpers/mutatorContext.mjs +1 -1
- package/dist/esm/helpers/mutatorContext.native.js +4 -4
- package/dist/esm/helpers/mutatorContext.native.js.map +1 -1
- package/dist/esm/helpers/platform.mjs +5 -0
- package/dist/esm/helpers/platform.mjs.map +1 -0
- package/dist/esm/helpers/platform.native.js +4 -0
- package/dist/esm/helpers/platform.native.js.map +1 -0
- package/dist/esm/helpers/prettyFormatZeroQuery.mjs +1 -1
- package/dist/esm/helpers/prettyFormatZeroQuery.native.js +6 -6
- package/dist/esm/helpers/prettyFormatZeroQuery.native.js.map +1 -1
- package/dist/esm/helpers/queryContext.mjs +1 -1
- package/dist/esm/helpers/queryContext.native.js +3 -3
- package/dist/esm/helpers/queryContext.native.js.map +1 -1
- package/dist/esm/helpers/recoverZeroClient.mjs +14 -15
- package/dist/esm/helpers/recoverZeroClient.mjs.map +1 -1
- package/dist/esm/helpers/recoverZeroClient.native.js +26 -23
- package/dist/esm/helpers/recoverZeroClient.native.js.map +1 -1
- package/dist/esm/helpers/recoverZeroClient.test.mjs +8 -6
- package/dist/esm/helpers/recoverZeroClient.test.mjs.map +1 -1
- package/dist/esm/helpers/recoverZeroClient.test.native.js +15 -19
- package/dist/esm/helpers/recoverZeroClient.test.native.js.map +1 -1
- package/dist/esm/helpers/sleep.mjs +9 -0
- package/dist/esm/helpers/sleep.mjs.map +1 -0
- package/dist/esm/helpers/sleep.native.js +11 -0
- package/dist/esm/helpers/sleep.native.js.map +1 -0
- package/dist/esm/helpers/time.mjs +22 -0
- package/dist/esm/helpers/time.mjs.map +1 -0
- package/dist/esm/helpers/time.native.js +52 -0
- package/dist/esm/helpers/time.native.js.map +1 -0
- package/dist/esm/helpers/tuple.mjs +2 -0
- package/dist/esm/helpers/tuple.mjs.map +1 -0
- package/dist/esm/helpers/tuple.native.js +2 -0
- package/dist/esm/helpers/tuple.native.js.map +1 -0
- package/dist/esm/helpers/useMutation.native.js +5 -5
- package/dist/esm/helpers/useMutation.native.js.map +1 -1
- package/dist/esm/helpers/useMutation.test.native.js +1 -1
- package/dist/esm/helpers/useMutation.test.native.js.map +1 -1
- package/dist/esm/helpers/useZeroDebug.mjs +1 -1
- package/dist/esm/helpers/useZeroDebug.mjs.map +1 -1
- package/dist/esm/helpers/useZeroDebug.native.js +6 -7
- package/dist/esm/helpers/useZeroDebug.native.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +3 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +3 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/instanceRegistry.mjs +13 -2
- package/dist/esm/instanceRegistry.mjs.map +1 -1
- package/dist/esm/instanceRegistry.native.js +53 -4
- package/dist/esm/instanceRegistry.native.js.map +1 -1
- package/dist/esm/multi.mjs +33 -12
- package/dist/esm/multi.mjs.map +1 -1
- package/dist/esm/multi.native.js +38 -16
- package/dist/esm/multi.native.js.map +1 -1
- package/dist/esm/multiInstance.test.mjs +5 -1
- package/dist/esm/multiInstance.test.mjs.map +1 -1
- package/dist/esm/multiInstance.test.native.js +12 -8
- package/dist/esm/multiInstance.test.native.js.map +1 -1
- package/dist/esm/multiInstanceNested.test.native.js +10 -10
- package/dist/esm/multiInstanceNested.test.native.js.map +1 -1
- package/dist/esm/multiPartition.test.mjs +86 -37
- package/dist/esm/multiPartition.test.mjs.map +1 -1
- package/dist/esm/multiPartition.test.native.js +103 -40
- package/dist/esm/multiPartition.test.native.js.map +1 -1
- package/dist/esm/mutations.mjs +1 -1
- package/dist/esm/mutations.mjs.map +1 -1
- package/dist/esm/mutations.native.js +3 -3
- package/dist/esm/mutations.native.js.map +1 -1
- package/dist/esm/mutations.test.native.js +3 -3
- package/dist/esm/mutations.test.native.js.map +1 -1
- package/dist/esm/provideZero.hydration.test.mjs +1 -1
- package/dist/esm/provideZero.hydration.test.mjs.map +1 -1
- package/dist/esm/provideZero.hydration.test.native.js +2 -2
- package/dist/esm/provideZero.hydration.test.native.js.map +1 -1
- package/dist/esm/run.mjs +1 -1
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/run.native.js +3 -3
- package/dist/esm/run.native.js.map +1 -1
- package/dist/esm/server.mjs +20 -15
- package/dist/esm/server.mjs.map +1 -1
- package/dist/esm/server.native.js +50 -56
- package/dist/esm/server.native.js.map +1 -1
- package/dist/esm/server.test.mjs +130 -7
- package/dist/esm/server.test.mjs.map +1 -1
- package/dist/esm/server.test.native.js +142 -11
- package/dist/esm/server.test.native.js.map +1 -1
- package/dist/esm/serverWhere.test.mjs.map +1 -1
- package/dist/esm/serverWhere.test.native.js +3 -3
- package/dist/esm/serverWhere.test.native.js.map +1 -1
- package/dist/esm/state.mjs +1 -1
- package/dist/esm/state.mjs.map +1 -1
- package/dist/esm/state.native.js +9 -9
- package/dist/esm/state.native.js.map +1 -1
- package/dist/esm/usePermission.test.native.js +3 -3
- package/dist/esm/usePermission.test.native.js.map +1 -1
- package/dist/esm/useQuery.empty.test.mjs +1 -1
- package/dist/esm/useQuery.empty.test.mjs.map +1 -1
- package/dist/esm/useQuery.empty.test.native.js +4 -4
- package/dist/esm/useQuery.empty.test.native.js.map +1 -1
- package/dist/esm/useQuery.ssr.test.native.js +2 -2
- package/dist/esm/useQuery.ssr.test.native.js.map +1 -1
- package/dist/esm/vite-plugin.mjs +7 -8
- package/dist/esm/vite-plugin.mjs.map +1 -1
- package/dist/esm/vite-plugin.native.js +11 -11
- package/dist/esm/vite-plugin.native.js.map +1 -1
- package/dist/esm/where.mjs +1 -1
- package/dist/esm/where.mjs.map +1 -1
- package/dist/esm/where.native.js +2 -2
- package/dist/esm/where.native.js.map +1 -1
- package/package.json +18 -6
- package/src/cli.ts +11 -3
- package/src/combineZeroClients.tsx +18 -10
- package/src/config.ts +72 -0
- package/src/createPermissions.ts +3 -4
- package/src/createUseQuery.tsx +8 -8
- package/src/createUseQueryDirect.tsx +11 -10
- package/src/createZeroClient.authData.test.tsx +1 -1
- package/src/createZeroClient.connection.test.tsx +13 -2
- package/src/createZeroClient.recovery.test.tsx +100 -4
- package/src/createZeroClient.tsx +87 -30
- package/src/generate-helpers.ts +108 -31
- package/src/generate-layout.ts +841 -0
- package/src/generate-lite.test.ts +421 -42
- package/src/generate-lite.ts +479 -43
- package/src/generate.test.ts +552 -90
- package/src/generate.ts +360 -163
- package/src/helpers/NullToOptional.ts +5 -0
- package/src/helpers/asyncContext.native.ts +90 -0
- package/src/helpers/asyncContext.ts +159 -0
- package/src/helpers/batchQuery.ts +2 -2
- package/src/helpers/createMutators.ts +11 -8
- package/src/helpers/ellipsis.ts +9 -0
- package/src/helpers/emitter.tsx +106 -0
- package/src/helpers/ensure.ts +10 -0
- package/src/helpers/ensureLoggedIn.ts +1 -2
- package/src/helpers/errors.ts +13 -0
- package/src/helpers/getCurrentComponentStack.ts +56 -0
- package/src/helpers/globalValue.ts +40 -0
- package/src/helpers/mapObject.ts +14 -0
- package/src/helpers/mutationLifecycle.test.ts +180 -0
- package/src/helpers/mutationLifecycle.ts +313 -0
- package/src/helpers/mutatorContext.ts +3 -3
- package/src/helpers/platform.native.ts +2 -0
- package/src/helpers/platform.ts +16 -0
- package/src/helpers/prettyFormatZeroQuery.ts +2 -2
- package/src/helpers/queryContext.ts +2 -2
- package/src/helpers/recoverZeroClient.test.ts +23 -21
- package/src/helpers/recoverZeroClient.ts +56 -49
- package/src/helpers/sleep.ts +8 -0
- package/src/helpers/time.ts +51 -0
- package/src/helpers/tuple.ts +1 -0
- package/src/helpers/useMutation.tsx +3 -3
- package/src/helpers/useZeroDebug.ts +3 -3
- package/src/index.ts +13 -1
- package/src/instanceRegistry.ts +19 -6
- package/src/multi.ts +75 -31
- package/src/multiInstance.test.tsx +31 -13
- package/src/multiInstanceNested.test.tsx +2 -2
- package/src/multiPartition.test.ts +62 -27
- package/src/mutations.ts +10 -10
- package/src/provideZero.hydration.test.tsx +1 -1
- package/src/resolveQuery.ts +2 -2
- package/src/run.ts +7 -7
- package/src/server.test.ts +117 -18
- package/src/server.ts +70 -43
- package/src/serverWhere.ts +2 -2
- package/src/state.ts +2 -2
- package/src/types.ts +47 -6
- package/src/useQuery.empty.test.tsx +3 -3
- package/src/useQuery.ssr.test.ts +1 -1
- package/src/vite-plugin.ts +12 -9
- package/src/where.ts +6 -7
- package/src/zeroRunner.ts +2 -2
- package/types/combineZeroClients.d.ts +11 -5
- package/types/combineZeroClients.d.ts.map +1 -1
- package/types/config.d.ts +62 -0
- package/types/config.d.ts.map +1 -0
- package/types/createPermissions.d.ts.map +1 -1
- package/types/createUseQuery.d.ts.map +1 -1
- package/types/createUseQueryDirect.d.ts +1 -1
- package/types/createUseQueryDirect.d.ts.map +1 -1
- package/types/createZeroClient.d.ts +22 -12
- package/types/createZeroClient.d.ts.map +1 -1
- package/types/createZeroClient.recovery.test.d.ts.map +1 -1
- package/types/generate-helpers.d.ts +17 -2
- package/types/generate-helpers.d.ts.map +1 -1
- package/types/generate-layout.d.ts +26 -0
- package/types/generate-layout.d.ts.map +1 -0
- package/types/generate-lite.d.ts +29 -1
- package/types/generate-lite.d.ts.map +1 -1
- package/types/generate.d.ts +20 -0
- package/types/generate.d.ts.map +1 -1
- package/types/helpers/NullToOptional.d.ts +6 -0
- package/types/helpers/NullToOptional.d.ts.map +1 -0
- package/types/helpers/asyncContext.d.ts +15 -0
- package/types/helpers/asyncContext.d.ts.map +1 -0
- package/types/helpers/asyncContext.native.d.ts +8 -0
- package/types/helpers/asyncContext.native.d.ts.map +1 -0
- package/types/helpers/createMutators.d.ts +2 -1
- package/types/helpers/createMutators.d.ts.map +1 -1
- package/types/helpers/ellipsis.d.ts +2 -0
- package/types/helpers/ellipsis.d.ts.map +1 -0
- package/types/helpers/emitter.d.ts +21 -0
- package/types/helpers/emitter.d.ts.map +1 -0
- package/types/helpers/ensure.d.ts +2 -0
- package/types/helpers/ensure.d.ts.map +1 -0
- package/types/helpers/ensureLoggedIn.d.ts.map +1 -1
- package/types/helpers/errors.d.ts +7 -0
- package/types/helpers/errors.d.ts.map +1 -0
- package/types/helpers/getCurrentComponentStack.d.ts +2 -0
- package/types/helpers/getCurrentComponentStack.d.ts.map +1 -0
- package/types/helpers/globalValue.d.ts +23 -0
- package/types/helpers/globalValue.d.ts.map +1 -0
- package/types/helpers/mapObject.d.ts +4 -0
- package/types/helpers/mapObject.d.ts.map +1 -0
- package/types/helpers/mutationLifecycle.d.ts +44 -0
- package/types/helpers/mutationLifecycle.d.ts.map +1 -0
- package/types/helpers/mutationLifecycle.test.d.ts +2 -0
- package/types/helpers/mutationLifecycle.test.d.ts.map +1 -0
- package/types/helpers/platform.d.ts +3 -0
- package/types/helpers/platform.d.ts.map +1 -0
- package/types/helpers/platform.native.d.ts +3 -0
- package/types/helpers/platform.native.d.ts.map +1 -0
- package/types/helpers/recoverZeroClient.d.ts +13 -9
- package/types/helpers/recoverZeroClient.d.ts.map +1 -1
- package/types/helpers/sleep.d.ts +2 -0
- package/types/helpers/sleep.d.ts.map +1 -0
- package/types/helpers/time.d.ts +28 -0
- package/types/helpers/time.d.ts.map +1 -0
- package/types/helpers/tuple.d.ts +2 -0
- package/types/helpers/tuple.d.ts.map +1 -0
- package/types/index.d.ts +3 -1
- package/types/index.d.ts.map +1 -1
- package/types/instanceRegistry.d.ts +1 -0
- package/types/instanceRegistry.d.ts.map +1 -1
- package/types/multi.d.ts +23 -1
- package/types/multi.d.ts.map +1 -1
- package/types/mutations.d.ts +1 -1
- package/types/mutations.d.ts.map +1 -1
- package/types/run.d.ts.map +1 -1
- package/types/server.d.ts +12 -8
- package/types/server.d.ts.map +1 -1
- package/types/state.d.ts +1 -1
- package/types/state.d.ts.map +1 -1
- package/types/types.d.ts +23 -1
- package/types/types.d.ts.map +1 -1
- package/types/vite-plugin.d.ts.map +1 -1
- package/types/where.d.ts.map +1 -1
- package/lint/ssr-guards.js +0 -165
- package/test-fixtures/server-return-types.ts +0 -58
- package/test-fixtures/tsconfig.json +0 -13
- package/tsconfig.json +0 -26
- package/vitest.config.ts +0 -8
package/src/generate.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'
|
|
3
3
|
import { basename, dirname, resolve } from 'node:path'
|
|
4
|
+
|
|
4
5
|
import {
|
|
5
6
|
formatObjectKey,
|
|
6
7
|
generateGroupedQueriesFile,
|
|
8
|
+
generateInstancesFile,
|
|
7
9
|
generateModelsFile,
|
|
8
10
|
generateReadmeFile,
|
|
9
11
|
generateSyncedMutationsFile,
|
|
@@ -14,10 +16,13 @@ import {
|
|
|
14
16
|
parseTypeString,
|
|
15
17
|
shouldSkipObjectKey,
|
|
16
18
|
} from './generate-helpers'
|
|
19
|
+
import { discoverDataLayout, namespaceImportPath } from './generate-layout'
|
|
20
|
+
|
|
17
21
|
import type { ExtractedMutation, ModelMutations, SchemaColumn } from './generate-helpers'
|
|
22
|
+
import type { DataLayout } from './generate-layout'
|
|
18
23
|
|
|
19
24
|
const hash = (s: string) => createHash('sha256').update(s).digest('hex')
|
|
20
|
-
const GENERATOR_CACHE_VERSION = '
|
|
25
|
+
const GENERATOR_CACHE_VERSION = '5'
|
|
21
26
|
|
|
22
27
|
const isGeneratorSourceFile = (name: string) =>
|
|
23
28
|
name.endsWith('.ts') &&
|
|
@@ -31,24 +36,32 @@ const isGeneratorSourceFile = (name: string) =>
|
|
|
31
36
|
// and building a TS program per query/model for type resolution — runs every
|
|
32
37
|
// boot otherwise, even when the output is already current (the configureServer
|
|
33
38
|
// watcher re-runs it on real edits, so the boot-time pass is pure redundancy).
|
|
34
|
-
function hashInputTree(
|
|
39
|
+
function hashInputTree(sourceRoots: string[], generatedDir: string): string {
|
|
35
40
|
const parts: string[] = []
|
|
41
|
+
const seen = new Set<string>()
|
|
36
42
|
const walk = (dir: string) => {
|
|
37
43
|
if (!existsSync(dir)) return
|
|
38
44
|
const entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) =>
|
|
39
|
-
a.name < b.name ? -1 : 1
|
|
45
|
+
a.name < b.name ? -1 : 1
|
|
40
46
|
)
|
|
41
47
|
for (const entry of entries) {
|
|
42
48
|
const full = resolve(dir, entry.name)
|
|
43
49
|
if (entry.isDirectory()) {
|
|
44
|
-
if (
|
|
50
|
+
if (
|
|
51
|
+
entry.name === 'node_modules' ||
|
|
52
|
+
entry.name === 'generated' ||
|
|
53
|
+
full === generatedDir
|
|
54
|
+
)
|
|
55
|
+
continue
|
|
45
56
|
walk(full)
|
|
46
57
|
} else if (entry.isFile() && isGeneratorSourceFile(entry.name)) {
|
|
58
|
+
if (seen.has(full)) continue
|
|
59
|
+
seen.add(full)
|
|
47
60
|
parts.push(`${full}\0${readFileSync(full, 'utf-8')}`)
|
|
48
61
|
}
|
|
49
62
|
}
|
|
50
63
|
}
|
|
51
|
-
walk(
|
|
64
|
+
for (const root of sourceRoots) walk(root)
|
|
52
65
|
return hash(parts.join('\0'))
|
|
53
66
|
}
|
|
54
67
|
|
|
@@ -108,7 +121,7 @@ function writeFileIfChanged(filePath: string, content: string): boolean {
|
|
|
108
121
|
function createTypeResolver(
|
|
109
122
|
ts: typeof import('typescript'),
|
|
110
123
|
files: Array<{ path: string; content: string }>,
|
|
111
|
-
dir: string
|
|
124
|
+
dir: string
|
|
112
125
|
) {
|
|
113
126
|
// find tsconfig if it exists for path alias resolution
|
|
114
127
|
const configPath = ts.findConfigFile(dir, ts.sys.fileExists, 'tsconfig.json')
|
|
@@ -128,7 +141,7 @@ function createTypeResolver(
|
|
|
128
141
|
const parsed = ts.parseJsonConfigFileContent(
|
|
129
142
|
configFile.config,
|
|
130
143
|
ts.sys,
|
|
131
|
-
dirname(configPath)
|
|
144
|
+
dirname(configPath)
|
|
132
145
|
)
|
|
133
146
|
compilerOptions = { ...compilerOptions, ...parsed.options }
|
|
134
147
|
}
|
|
@@ -155,7 +168,7 @@ function createTypeResolver(
|
|
|
155
168
|
const program = ts.createProgram(
|
|
156
169
|
files.map((f) => f.path),
|
|
157
170
|
compilerOptions,
|
|
158
|
-
host
|
|
171
|
+
host
|
|
159
172
|
)
|
|
160
173
|
const checker = program.getTypeChecker()
|
|
161
174
|
|
|
@@ -183,7 +196,7 @@ function resolveParamType(
|
|
|
183
196
|
resolver: ReturnType<typeof createTypeResolver>,
|
|
184
197
|
sourceFile: import('typescript').SourceFile,
|
|
185
198
|
exportName: string,
|
|
186
|
-
paramIndex: number
|
|
199
|
+
paramIndex: number
|
|
187
200
|
): import('typescript').Type | null {
|
|
188
201
|
let result: import('typescript').Type | null = null
|
|
189
202
|
|
|
@@ -212,7 +225,7 @@ function resolveParamType(
|
|
|
212
225
|
function resolveMutationParamTypes(
|
|
213
226
|
ts: typeof import('typescript'),
|
|
214
227
|
resolver: ReturnType<typeof createTypeResolver>,
|
|
215
|
-
sourceFile: import('typescript').SourceFile
|
|
228
|
+
sourceFile: import('typescript').SourceFile
|
|
216
229
|
): Map<string, import('typescript').Type> {
|
|
217
230
|
const resolved = new Map<string, import('typescript').Type>()
|
|
218
231
|
|
|
@@ -276,7 +289,7 @@ function extractMutationsFromModel(
|
|
|
276
289
|
silent: boolean,
|
|
277
290
|
typeToValibot: (typeString: string) => string | null,
|
|
278
291
|
resolvedTypes?: Map<string, import('typescript').Type>,
|
|
279
|
-
resolvedTypeToValibot?: (type: import('typescript').Type) => string
|
|
292
|
+
resolvedTypeToValibot?: (type: import('typescript').Type) => string
|
|
280
293
|
): ModelMutations | null {
|
|
281
294
|
let mutateNode: import('typescript').CallExpression | null = null
|
|
282
295
|
|
|
@@ -406,7 +419,7 @@ function extractSchemaColumns(
|
|
|
406
419
|
ts: typeof import('typescript'),
|
|
407
420
|
sourceFile: ReturnType<typeof ts.createSourceFile>,
|
|
408
421
|
columns: Record<string, SchemaColumn>,
|
|
409
|
-
primaryKeys: string[]
|
|
422
|
+
primaryKeys: string[]
|
|
410
423
|
) {
|
|
411
424
|
// walk AST to find table(...).columns({...}).primaryKey(...)
|
|
412
425
|
function visit(node: import('typescript').Node) {
|
|
@@ -446,7 +459,7 @@ function extractSchemaColumns(
|
|
|
446
459
|
function getInstantiatedPropertyType(
|
|
447
460
|
checker: import('typescript').TypeChecker,
|
|
448
461
|
parent: import('typescript').Type,
|
|
449
|
-
name: string
|
|
462
|
+
name: string
|
|
450
463
|
) {
|
|
451
464
|
const resolveProperty: unknown = Reflect.get(checker, 'getTypeOfPropertyOfType')
|
|
452
465
|
if (typeof resolveProperty !== 'function') return undefined
|
|
@@ -461,7 +474,7 @@ function tsTypeToValibot(
|
|
|
461
474
|
ts: typeof import('typescript'),
|
|
462
475
|
checker: import('typescript').TypeChecker,
|
|
463
476
|
type: import('typescript').Type,
|
|
464
|
-
seen?: Set<import('typescript').Type
|
|
477
|
+
seen?: Set<import('typescript').Type>
|
|
465
478
|
): string {
|
|
466
479
|
// prevent infinite recursion on circular types
|
|
467
480
|
// only track structured types (objects, intersections) — not primitives/unions
|
|
@@ -510,14 +523,11 @@ function tsTypeToValibot(
|
|
|
510
523
|
const members = type.types
|
|
511
524
|
const hasNull = members.some((t) => t.getFlags() & ts.TypeFlags.Null)
|
|
512
525
|
const hasUndefined = members.some(
|
|
513
|
-
(t) => t.getFlags() & (ts.TypeFlags.Undefined | ts.TypeFlags.Void)
|
|
526
|
+
(t) => t.getFlags() & (ts.TypeFlags.Undefined | ts.TypeFlags.Void)
|
|
514
527
|
)
|
|
515
528
|
const rest = members.filter(
|
|
516
529
|
(t) =>
|
|
517
|
-
!(
|
|
518
|
-
t.getFlags() &
|
|
519
|
-
(ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.Void)
|
|
520
|
-
),
|
|
530
|
+
!(t.getFlags() & (ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.Void))
|
|
521
531
|
)
|
|
522
532
|
if (
|
|
523
533
|
rest.length === 2 &&
|
|
@@ -544,7 +554,7 @@ function tsTypeToValibot(
|
|
|
544
554
|
// resolve symbol property type with fallbacks
|
|
545
555
|
const resolveSymbolType = (
|
|
546
556
|
parent: import('typescript').Type,
|
|
547
|
-
prop: import('typescript').Symbol
|
|
557
|
+
prop: import('typescript').Symbol
|
|
548
558
|
) => {
|
|
549
559
|
// mapped and conditional types can expose transient symbols with no
|
|
550
560
|
// declaration, so resolve each property against its concrete parent.
|
|
@@ -659,7 +669,7 @@ function serializeColumn(col: SchemaColumn): string {
|
|
|
659
669
|
parts.push(`type: '${col.type}'`)
|
|
660
670
|
parts.push(`optional: ${col.optional}`)
|
|
661
671
|
parts.push(
|
|
662
|
-
`customType: null as unknown as ${col.type === 'json' ? 'ReadonlyJSONValue' : col.type}
|
|
672
|
+
`customType: null as unknown as ${col.type === 'json' ? 'ReadonlyJSONValue' : col.type}`
|
|
663
673
|
)
|
|
664
674
|
if (col.serverName) {
|
|
665
675
|
parts.push(`serverName: '${col.serverName}'`)
|
|
@@ -740,7 +750,7 @@ export function generateDrizzleSchemaFile(schema: DrizzleZeroSchema): string {
|
|
|
740
750
|
// many-to-many (2 hops)
|
|
741
751
|
if (hops.length !== 2) {
|
|
742
752
|
throw new Error(
|
|
743
|
-
`Relationship ${tableName}.${relName} must have one or two hops
|
|
753
|
+
`Relationship ${tableName}.${relName} must have one or two hops`
|
|
744
754
|
)
|
|
745
755
|
}
|
|
746
756
|
const cardinality = hops[0]!.cardinality
|
|
@@ -760,7 +770,7 @@ export function generateDrizzleSchemaFile(schema: DrizzleZeroSchema): string {
|
|
|
760
770
|
.join(',\n')
|
|
761
771
|
|
|
762
772
|
lines.push(
|
|
763
|
-
`const ${tableName}Relationships = relationships(${tableName}Table, ({ one, many }) => ({
|
|
773
|
+
`const ${tableName}Relationships = relationships(${tableName}Table, ({ one, many }) => ({`
|
|
764
774
|
)
|
|
765
775
|
lines.push(relBody)
|
|
766
776
|
lines.push(`}))`)
|
|
@@ -790,6 +800,8 @@ export function generateDrizzleSchemaFile(schema: DrizzleZeroSchema): string {
|
|
|
790
800
|
export interface GenerateOptions {
|
|
791
801
|
/** base data directory */
|
|
792
802
|
dir: string
|
|
803
|
+
/** explicit on-zero.config.ts path; auto-discovered in `dir` when omitted */
|
|
804
|
+
config?: string
|
|
793
805
|
/** run after generation */
|
|
794
806
|
after?: string
|
|
795
807
|
/** suppress output */
|
|
@@ -811,16 +823,152 @@ export interface GenerateResult {
|
|
|
811
823
|
mutationCount: number
|
|
812
824
|
}
|
|
813
825
|
|
|
826
|
+
export type DataMembership = {
|
|
827
|
+
instances: Record<
|
|
828
|
+
string,
|
|
829
|
+
{
|
|
830
|
+
tables: string[]
|
|
831
|
+
syncTables: string[]
|
|
832
|
+
supportTables: string[]
|
|
833
|
+
scope: string | null
|
|
834
|
+
}
|
|
835
|
+
>
|
|
836
|
+
allTables: string[]
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
function dataMembershipFromLayout(layout: DataLayout): DataMembership {
|
|
840
|
+
return {
|
|
841
|
+
instances: Object.fromEntries(
|
|
842
|
+
layout.instances.map((instance) => [
|
|
843
|
+
instance.name,
|
|
844
|
+
{
|
|
845
|
+
tables: instance.namespaces.map((namespace) => namespace.name).sort(),
|
|
846
|
+
syncTables: [...instance.syncTables],
|
|
847
|
+
supportTables: [...instance.supportTables],
|
|
848
|
+
scope: instance.scope,
|
|
849
|
+
},
|
|
850
|
+
])
|
|
851
|
+
),
|
|
852
|
+
allTables: [
|
|
853
|
+
...new Set(
|
|
854
|
+
layout.instances.flatMap((instance) => [
|
|
855
|
+
...instance.syncTables,
|
|
856
|
+
...instance.supportTables,
|
|
857
|
+
])
|
|
858
|
+
),
|
|
859
|
+
].sort(),
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
export async function deriveDataMembership(options: {
|
|
864
|
+
dir: string
|
|
865
|
+
config?: string
|
|
866
|
+
}): Promise<DataMembership> {
|
|
867
|
+
const ts = await import('typescript')
|
|
868
|
+
const layout = discoverDataLayout(
|
|
869
|
+
ts,
|
|
870
|
+
resolve(options.dir),
|
|
871
|
+
options.config ? resolve(options.config) : undefined
|
|
872
|
+
)
|
|
873
|
+
return dataMembershipFromLayout(layout)
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
export async function generateDrizzleSchemaInputFile(options: {
|
|
877
|
+
dir: string
|
|
878
|
+
schemaImportPath: string
|
|
879
|
+
config?: string
|
|
880
|
+
}): Promise<string> {
|
|
881
|
+
const ts = await import('typescript')
|
|
882
|
+
const baseDir = resolve(options.dir)
|
|
883
|
+
const layout = discoverDataLayout(
|
|
884
|
+
ts,
|
|
885
|
+
baseDir,
|
|
886
|
+
options.config ? resolve(options.config) : undefined
|
|
887
|
+
)
|
|
888
|
+
const tableNames = dataMembershipFromLayout(layout).allTables
|
|
889
|
+
const relationsPath =
|
|
890
|
+
layout.metadataPaths.find(
|
|
891
|
+
(path) =>
|
|
892
|
+
basename(path) === 'relations.ts' &&
|
|
893
|
+
dirname(path) === resolve(dirname(baseDir), 'database')
|
|
894
|
+
) ?? layout.metadataPaths.find((path) => basename(path) === 'relations.ts')
|
|
895
|
+
const relationEntries: string[] = []
|
|
896
|
+
|
|
897
|
+
if (relationsPath) {
|
|
898
|
+
const source = ts.createSourceFile(
|
|
899
|
+
relationsPath,
|
|
900
|
+
readFileSync(relationsPath, 'utf8'),
|
|
901
|
+
ts.ScriptTarget.Latest,
|
|
902
|
+
true
|
|
903
|
+
)
|
|
904
|
+
const included = new Set(tableNames)
|
|
905
|
+
const visit = (node: import('typescript').Node) => {
|
|
906
|
+
if (
|
|
907
|
+
!ts.isCallExpression(node) ||
|
|
908
|
+
node.expression.getText(source) !== 'defineRelations'
|
|
909
|
+
) {
|
|
910
|
+
ts.forEachChild(node, visit)
|
|
911
|
+
return
|
|
912
|
+
}
|
|
913
|
+
const factory = node.arguments[1]
|
|
914
|
+
if (
|
|
915
|
+
!factory ||
|
|
916
|
+
(!ts.isArrowFunction(factory) && !ts.isFunctionExpression(factory))
|
|
917
|
+
) {
|
|
918
|
+
return
|
|
919
|
+
}
|
|
920
|
+
const body = ts.isParenthesizedExpression(factory.body)
|
|
921
|
+
? factory.body.expression
|
|
922
|
+
: factory.body
|
|
923
|
+
if (!ts.isObjectLiteralExpression(body)) return
|
|
924
|
+
|
|
925
|
+
for (const tableProperty of body.properties) {
|
|
926
|
+
if (
|
|
927
|
+
!ts.isPropertyAssignment(tableProperty) ||
|
|
928
|
+
!ts.isObjectLiteralExpression(tableProperty.initializer)
|
|
929
|
+
) {
|
|
930
|
+
continue
|
|
931
|
+
}
|
|
932
|
+
const table = tableProperty.name.getText(source).replace(/^['"]|['"]$/g, '')
|
|
933
|
+
if (!included.has(table)) continue
|
|
934
|
+
const relations: string[] = []
|
|
935
|
+
for (const relationProperty of tableProperty.initializer.properties) {
|
|
936
|
+
if (
|
|
937
|
+
!ts.isPropertyAssignment(relationProperty) ||
|
|
938
|
+
!ts.isCallExpression(relationProperty.initializer) ||
|
|
939
|
+
!ts.isPropertyAccessExpression(relationProperty.initializer.expression)
|
|
940
|
+
) {
|
|
941
|
+
continue
|
|
942
|
+
}
|
|
943
|
+
const target = relationProperty.initializer.expression.name.text
|
|
944
|
+
if (included.has(target)) relations.push(relationProperty.getText(source))
|
|
945
|
+
}
|
|
946
|
+
relationEntries.push(
|
|
947
|
+
` ${tableProperty.name.getText(source)}: {${relations.length ? `\n${relations.map((relation) => ` ${relation},`).join('\n')}\n ` : ''}},`
|
|
948
|
+
)
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
visit(source)
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
const schemaImportPath = JSON.stringify(options.schemaImportPath)
|
|
955
|
+
return [
|
|
956
|
+
'// auto-generated from the on-zero data layout',
|
|
957
|
+
`import { defineRelations } from 'drizzle-orm'`,
|
|
958
|
+
`import * as schema from ${schemaImportPath}`,
|
|
959
|
+
'',
|
|
960
|
+
`export { ${tableNames.join(', ')} } from ${schemaImportPath}`,
|
|
961
|
+
`export const relations = defineRelations(schema, (r) => ({`,
|
|
962
|
+
...relationEntries,
|
|
963
|
+
`}))`,
|
|
964
|
+
'',
|
|
965
|
+
].join('\n')
|
|
966
|
+
}
|
|
967
|
+
|
|
814
968
|
export async function generate(options: GenerateOptions): Promise<GenerateResult> {
|
|
815
|
-
const { dir, after, silent, force } = options
|
|
969
|
+
const { dir, after, silent, force, config } = options
|
|
816
970
|
const baseDir = resolve(dir)
|
|
817
|
-
// support both mutations/ (new) and models/ (legacy) directories
|
|
818
|
-
const mutationsDir = resolve(baseDir, 'mutations')
|
|
819
|
-
const usesMutationsDir = existsSync(mutationsDir)
|
|
820
|
-
const modelsDir = usesMutationsDir ? mutationsDir : resolve(baseDir, 'models')
|
|
821
|
-
const modelsDirName = usesMutationsDir ? 'mutations' : 'models'
|
|
822
971
|
const generatedDir = resolve(baseDir, 'generated')
|
|
823
|
-
const queriesDir = resolve(baseDir, 'queries')
|
|
824
972
|
|
|
825
973
|
if (!existsSync(generatedDir)) {
|
|
826
974
|
mkdirSync(generatedDir, { recursive: true })
|
|
@@ -828,12 +976,24 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
828
976
|
|
|
829
977
|
loadCache()
|
|
830
978
|
|
|
979
|
+
// the layout pass is intentionally first: config, filenames, and related()
|
|
980
|
+
// calls determine schema membership before any type program exists.
|
|
981
|
+
const ts = await import('typescript')
|
|
982
|
+
const layout = discoverDataLayout(ts, baseDir, config ? resolve(config) : undefined)
|
|
983
|
+
const metadataHash = hash(
|
|
984
|
+
layout.metadataPaths
|
|
985
|
+
.map((path) => `${path}\0${readFileSync(path, 'utf8')}`)
|
|
986
|
+
.join('\0')
|
|
987
|
+
)
|
|
988
|
+
|
|
831
989
|
// input-freshness gate: if nothing under baseDir changed since the last
|
|
832
990
|
// COMPLETED generate (the input hash is only stored at the end, after
|
|
833
991
|
// saveCache), the outputs are already current — skip the typescript-program
|
|
834
992
|
// build entirely and return the cached counts. the configureServer watcher
|
|
835
993
|
// still re-runs generate on real model/query edits.
|
|
836
|
-
const inputHash =
|
|
994
|
+
const inputHash = hash(
|
|
995
|
+
`${hashInputTree(layout.sourceRoots, generatedDir)}\0${metadataHash}`
|
|
996
|
+
)
|
|
837
997
|
if (
|
|
838
998
|
!force &&
|
|
839
999
|
generateCache.__generatorVersion === GENERATOR_CACHE_VERSION &&
|
|
@@ -853,19 +1013,26 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
853
1013
|
}
|
|
854
1014
|
}
|
|
855
1015
|
|
|
856
|
-
const
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
readFileSync(resolve(modelsDir, f), 'utf-8').includes('export const schema = table('),
|
|
1016
|
+
const modelNamespaces = layout.namespaces.filter(
|
|
1017
|
+
(namespace): namespace is typeof namespace & { modelPath: string } =>
|
|
1018
|
+
namespace.modelPath !== null
|
|
860
1019
|
)
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
1020
|
+
const filesWithSchema = modelNamespaces.filter((namespace) =>
|
|
1021
|
+
readFileSync(namespace.modelPath, 'utf-8').includes('export const schema = table(')
|
|
1022
|
+
)
|
|
1023
|
+
const modelModules = modelNamespaces.map((namespace) => ({
|
|
1024
|
+
name: namespace.name,
|
|
1025
|
+
importPath: namespaceImportPath(baseDir, namespace.modelPath),
|
|
1026
|
+
}))
|
|
1027
|
+
const schemaModules = filesWithSchema.map((namespace) => ({
|
|
1028
|
+
name: namespace.name,
|
|
1029
|
+
importPath: namespaceImportPath(baseDir, namespace.modelPath),
|
|
1030
|
+
}))
|
|
864
1031
|
|
|
865
1032
|
const writeResults = [
|
|
866
1033
|
writeFileIfChanged(
|
|
867
1034
|
resolve(generatedDir, 'models.ts'),
|
|
868
|
-
generateModelsFile(
|
|
1035
|
+
generateModelsFile(modelModules)
|
|
869
1036
|
),
|
|
870
1037
|
// only generate types.ts and tables.ts when model files define schemas.
|
|
871
1038
|
// when using drizzle-zero CLI for schema generation, these files are
|
|
@@ -874,11 +1041,11 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
874
1041
|
? [
|
|
875
1042
|
writeFileIfChanged(
|
|
876
1043
|
resolve(generatedDir, 'types.ts'),
|
|
877
|
-
generateTypesFile(
|
|
1044
|
+
generateTypesFile(schemaModules.map((module) => module.name))
|
|
878
1045
|
),
|
|
879
1046
|
writeFileIfChanged(
|
|
880
1047
|
resolve(generatedDir, 'tables.ts'),
|
|
881
|
-
generateTablesFile(
|
|
1048
|
+
generateTablesFile(schemaModules)
|
|
882
1049
|
),
|
|
883
1050
|
]
|
|
884
1051
|
: []),
|
|
@@ -889,9 +1056,6 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
889
1056
|
let queryCount = 0
|
|
890
1057
|
let mutationCount = 0
|
|
891
1058
|
|
|
892
|
-
// lazy-load typescript
|
|
893
|
-
const ts = await import('typescript')
|
|
894
|
-
|
|
895
1059
|
// lightweight string-based parser for inline type annotations from source text
|
|
896
1060
|
// handles simple cases: primitives, inline objects, arrays
|
|
897
1061
|
// returns null for type references that need the checker to resolve
|
|
@@ -903,119 +1067,134 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
903
1067
|
}
|
|
904
1068
|
}
|
|
905
1069
|
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
const allFiles = readdirSync(queriesDir)
|
|
922
|
-
.filter(isGeneratorSourceFile)
|
|
923
|
-
.map((f) => ({
|
|
924
|
-
path: resolve(queriesDir, f),
|
|
925
|
-
content: readFileSync(resolve(queriesDir, f), 'utf-8'),
|
|
926
|
-
}))
|
|
927
|
-
queryResolver = createTypeResolver(ts, allFiles, queriesDir)
|
|
928
|
-
}
|
|
929
|
-
return queryResolver
|
|
1070
|
+
const allQueries: Array<{
|
|
1071
|
+
name: string
|
|
1072
|
+
params: string
|
|
1073
|
+
valibotCode: string
|
|
1074
|
+
sourceFile: string
|
|
1075
|
+
importPath: string
|
|
1076
|
+
}> = []
|
|
1077
|
+
|
|
1078
|
+
let queryResolver: ReturnType<typeof createTypeResolver> | null = null
|
|
1079
|
+
const getQueryResolver = () => {
|
|
1080
|
+
if (!queryResolver) {
|
|
1081
|
+
const allFiles = [
|
|
1082
|
+
...new Set(layout.namespaces.flatMap((namespace) => namespace.sourcePaths)),
|
|
1083
|
+
].map((path) => ({ path, content: readFileSync(path, 'utf-8') }))
|
|
1084
|
+
queryResolver = createTypeResolver(ts, allFiles, baseDir)
|
|
930
1085
|
}
|
|
1086
|
+
return queryResolver
|
|
1087
|
+
}
|
|
931
1088
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
1089
|
+
for (const namespace of layout.namespaces.filter(
|
|
1090
|
+
(namespace): namespace is typeof namespace & { queryPath: string } =>
|
|
1091
|
+
namespace.queryPath !== null
|
|
1092
|
+
)) {
|
|
1093
|
+
const filePath = namespace.queryPath
|
|
935
1094
|
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1095
|
+
try {
|
|
1096
|
+
const content = readFileSync(filePath, 'utf-8')
|
|
1097
|
+
const sourceFile = ts.createSourceFile(
|
|
1098
|
+
filePath,
|
|
1099
|
+
content,
|
|
1100
|
+
ts.ScriptTarget.Latest,
|
|
1101
|
+
true
|
|
1102
|
+
)
|
|
944
1103
|
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1104
|
+
ts.forEachChild(sourceFile, (node) => {
|
|
1105
|
+
if (ts.isVariableStatement(node)) {
|
|
1106
|
+
const exportModifier = node.modifiers?.find(
|
|
1107
|
+
(m) => m.kind === ts.SyntaxKind.ExportKeyword
|
|
1108
|
+
)
|
|
1109
|
+
if (!exportModifier) return
|
|
951
1110
|
|
|
952
|
-
|
|
953
|
-
|
|
1111
|
+
const declaration = node.declarationList.declarations[0]
|
|
1112
|
+
if (!declaration || !ts.isVariableDeclaration(declaration)) return
|
|
954
1113
|
|
|
955
|
-
|
|
956
|
-
|
|
1114
|
+
const name = declaration.name.getText(sourceFile)
|
|
1115
|
+
if (['mutate', 'permission', 'schema', 'where'].includes(name)) return
|
|
957
1116
|
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1117
|
+
if (declaration.initializer && ts.isArrowFunction(declaration.initializer)) {
|
|
1118
|
+
const params = declaration.initializer.parameters
|
|
1119
|
+
let paramType = 'void'
|
|
961
1120
|
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1121
|
+
if (params.length > 0) {
|
|
1122
|
+
const param = params[0]!
|
|
1123
|
+
paramType = param.type?.getText(sourceFile) || 'unknown'
|
|
1124
|
+
}
|
|
966
1125
|
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
}
|
|
1126
|
+
let valibotCode = typeToValibot(paramType)
|
|
1127
|
+
|
|
1128
|
+
// if direct parse failed (unresolved reference), use TypeChecker
|
|
1129
|
+
if (!valibotCode && params.length > 0 && params[0]!.type) {
|
|
1130
|
+
const resolver = getQueryResolver()
|
|
1131
|
+
const resolverSourceFile = resolver.program.getSourceFile(filePath)
|
|
1132
|
+
if (resolverSourceFile) {
|
|
1133
|
+
const resolvedType = resolveParamType(
|
|
1134
|
+
ts,
|
|
1135
|
+
resolver,
|
|
1136
|
+
resolverSourceFile,
|
|
1137
|
+
name,
|
|
1138
|
+
0
|
|
1139
|
+
)
|
|
1140
|
+
if (resolvedType) {
|
|
1141
|
+
valibotCode = resolver.typeToValibot(resolvedType)
|
|
984
1142
|
}
|
|
985
1143
|
}
|
|
1144
|
+
}
|
|
986
1145
|
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
}
|
|
1146
|
+
if (valibotCode) {
|
|
1147
|
+
allQueries.push({
|
|
1148
|
+
name,
|
|
1149
|
+
params: paramType,
|
|
1150
|
+
valibotCode,
|
|
1151
|
+
sourceFile: namespace.name,
|
|
1152
|
+
importPath: namespaceImportPath(baseDir, filePath),
|
|
1153
|
+
})
|
|
1154
|
+
} else if (!silent && paramType !== 'void') {
|
|
1155
|
+
console.error(`✗ ${name}: could not resolve type "${paramType}"`)
|
|
997
1156
|
}
|
|
998
1157
|
}
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
}
|
|
1158
|
+
}
|
|
1159
|
+
})
|
|
1160
|
+
} catch (err) {
|
|
1161
|
+
if (!silent) console.error(`Error processing ${filePath}:`, err)
|
|
1003
1162
|
}
|
|
1163
|
+
}
|
|
1004
1164
|
|
|
1005
|
-
|
|
1165
|
+
queryCount = allQueries.length
|
|
1006
1166
|
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1167
|
+
const groupedChanged = writeFileIfChanged(
|
|
1168
|
+
resolve(generatedDir, 'groupedQueries.ts'),
|
|
1169
|
+
generateGroupedQueriesFile(allQueries)
|
|
1170
|
+
)
|
|
1171
|
+
const syncedChanged = writeFileIfChanged(
|
|
1172
|
+
resolve(generatedDir, 'syncedQueries.ts'),
|
|
1173
|
+
generateSyncedQueriesFile(allQueries)
|
|
1174
|
+
)
|
|
1015
1175
|
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1176
|
+
if (groupedChanged) filesChanged++
|
|
1177
|
+
if (syncedChanged) filesChanged++
|
|
1178
|
+
|
|
1179
|
+
const instancesChanged = writeFileIfChanged(
|
|
1180
|
+
resolve(generatedDir, 'instances.ts'),
|
|
1181
|
+
generateInstancesFile(
|
|
1182
|
+
layout.instances.map((instance) => ({
|
|
1183
|
+
name: instance.name,
|
|
1184
|
+
scope: instance.scope,
|
|
1185
|
+
queryNames: instance.namespaces
|
|
1186
|
+
.map((namespace) => namespace.name)
|
|
1187
|
+
.filter((name) => allQueries.some((query) => query.sourceFile === name)),
|
|
1188
|
+
modelNames: instance.namespaces
|
|
1189
|
+
.filter((namespace) => namespace.modelPath)
|
|
1190
|
+
.map((namespace) => namespace.name),
|
|
1191
|
+
tables: instance.namespaces.map((namespace) => namespace.name),
|
|
1192
|
+
syncTables: instance.syncTables,
|
|
1193
|
+
supportTables: instance.supportTables,
|
|
1194
|
+
}))
|
|
1195
|
+
)
|
|
1196
|
+
)
|
|
1197
|
+
if (instancesChanged) filesChanged++
|
|
1019
1198
|
|
|
1020
1199
|
// generate mutation validators from model files
|
|
1021
1200
|
const allModelMutations: ModelMutations[] = []
|
|
@@ -1024,9 +1203,9 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1024
1203
|
const mutationFiles: Array<{ path: string; content: string; baseName: string }> = []
|
|
1025
1204
|
const unresolvedModels: Array<{ baseName: string; filePath: string }> = []
|
|
1026
1205
|
|
|
1027
|
-
for (const
|
|
1028
|
-
const filePath =
|
|
1029
|
-
const fileBaseName =
|
|
1206
|
+
for (const namespace of modelNamespaces) {
|
|
1207
|
+
const filePath = namespace.modelPath
|
|
1208
|
+
const fileBaseName = namespace.name
|
|
1030
1209
|
|
|
1031
1210
|
try {
|
|
1032
1211
|
const content = readFileSync(filePath, 'utf-8')
|
|
@@ -1037,7 +1216,7 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1037
1216
|
filePath,
|
|
1038
1217
|
content,
|
|
1039
1218
|
ts.ScriptTarget.Latest,
|
|
1040
|
-
true
|
|
1219
|
+
true
|
|
1041
1220
|
)
|
|
1042
1221
|
const result = extractMutationsFromModel(
|
|
1043
1222
|
ts,
|
|
@@ -1045,7 +1224,7 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1045
1224
|
content,
|
|
1046
1225
|
filePath,
|
|
1047
1226
|
!!silent,
|
|
1048
|
-
typeToValibot
|
|
1227
|
+
typeToValibot
|
|
1049
1228
|
)
|
|
1050
1229
|
|
|
1051
1230
|
if (result) {
|
|
@@ -1054,14 +1233,14 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1054
1233
|
|
|
1055
1234
|
// check if any custom mutations have unresolved types
|
|
1056
1235
|
const hasUnresolved = result.custom.some(
|
|
1057
|
-
(m) => m.paramType !== 'void' && m.paramType !== 'unknown' && !m.valibotCode
|
|
1236
|
+
(m) => m.paramType !== 'void' && m.paramType !== 'unknown' && !m.valibotCode
|
|
1058
1237
|
)
|
|
1059
1238
|
if (hasUnresolved) {
|
|
1060
1239
|
unresolvedModels.push({ baseName: fileBaseName, filePath })
|
|
1061
1240
|
}
|
|
1062
1241
|
}
|
|
1063
1242
|
} catch (err) {
|
|
1064
|
-
if (!silent) console.error(`Error extracting mutations from ${
|
|
1243
|
+
if (!silent) console.error(`Error extracting mutations from ${filePath}:`, err)
|
|
1065
1244
|
}
|
|
1066
1245
|
}
|
|
1067
1246
|
|
|
@@ -1081,7 +1260,13 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1081
1260
|
}
|
|
1082
1261
|
return results
|
|
1083
1262
|
}
|
|
1084
|
-
const allFiles =
|
|
1263
|
+
const allFiles = [
|
|
1264
|
+
...new Map(
|
|
1265
|
+
layout.sourceRoots
|
|
1266
|
+
.flatMap(collectTsFiles)
|
|
1267
|
+
.map((file) => [file.path, file] as const)
|
|
1268
|
+
).values(),
|
|
1269
|
+
]
|
|
1085
1270
|
const modelResolver = createTypeResolver(ts, allFiles, baseDir)
|
|
1086
1271
|
|
|
1087
1272
|
for (const { baseName, filePath } of unresolvedModels) {
|
|
@@ -1091,7 +1276,7 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1091
1276
|
const resolvedTypes = resolveMutationParamTypes(
|
|
1092
1277
|
ts,
|
|
1093
1278
|
modelResolver,
|
|
1094
|
-
resolverSourceFile
|
|
1279
|
+
resolverSourceFile
|
|
1095
1280
|
)
|
|
1096
1281
|
if (resolvedTypes.size === 0) continue
|
|
1097
1282
|
|
|
@@ -1101,7 +1286,7 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1101
1286
|
filePath,
|
|
1102
1287
|
content,
|
|
1103
1288
|
ts.ScriptTarget.Latest,
|
|
1104
|
-
true
|
|
1289
|
+
true
|
|
1105
1290
|
)
|
|
1106
1291
|
const result = extractMutationsFromModel(
|
|
1107
1292
|
ts,
|
|
@@ -1111,7 +1296,7 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1111
1296
|
!!silent,
|
|
1112
1297
|
typeToValibot,
|
|
1113
1298
|
resolvedTypes,
|
|
1114
|
-
modelResolver.typeToValibot
|
|
1299
|
+
modelResolver.typeToValibot
|
|
1115
1300
|
)
|
|
1116
1301
|
|
|
1117
1302
|
if (result) {
|
|
@@ -1127,21 +1312,21 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1127
1312
|
for (const model of allModelMutations) {
|
|
1128
1313
|
if (model.hasCRUD) mutationCount += 3 // insert, update, delete
|
|
1129
1314
|
mutationCount += model.custom.filter(
|
|
1130
|
-
(m) => !model.hasCRUD || !['insert', 'update', 'delete', 'upsert'].includes(m.name)
|
|
1315
|
+
(m) => !model.hasCRUD || !['insert', 'update', 'delete', 'upsert'].includes(m.name)
|
|
1131
1316
|
).length
|
|
1132
1317
|
}
|
|
1133
1318
|
|
|
1134
1319
|
if (allModelMutations.length > 0) {
|
|
1135
1320
|
const mutationsChanged = writeFileIfChanged(
|
|
1136
1321
|
resolve(generatedDir, 'syncedMutations.ts'),
|
|
1137
|
-
generateSyncedMutationsFile(allModelMutations)
|
|
1322
|
+
generateSyncedMutationsFile(allModelMutations)
|
|
1138
1323
|
)
|
|
1139
1324
|
if (mutationsChanged) filesChanged++
|
|
1140
1325
|
}
|
|
1141
1326
|
|
|
1142
1327
|
if (filesChanged > 0 && !silent) {
|
|
1143
1328
|
console.info(
|
|
1144
|
-
`✓ ${
|
|
1329
|
+
`✓ ${modelNamespaces.length} models (${filesWithSchema.length} schemas)${queryCount ? `, ${queryCount} queries` : ''}${mutationCount ? `, ${mutationCount} mutations` : ''}`
|
|
1145
1330
|
)
|
|
1146
1331
|
}
|
|
1147
1332
|
|
|
@@ -1162,7 +1347,7 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1162
1347
|
generateCache.__generatorVersion = GENERATOR_CACHE_VERSION
|
|
1163
1348
|
generateCache.__inputHash = inputHash
|
|
1164
1349
|
generateCache.__counts = JSON.stringify({
|
|
1165
|
-
modelCount:
|
|
1350
|
+
modelCount: modelNamespaces.length,
|
|
1166
1351
|
schemaCount: filesWithSchema.length,
|
|
1167
1352
|
queryCount,
|
|
1168
1353
|
mutationCount,
|
|
@@ -1171,7 +1356,7 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1171
1356
|
|
|
1172
1357
|
return {
|
|
1173
1358
|
filesChanged,
|
|
1174
|
-
modelCount:
|
|
1359
|
+
modelCount: modelNamespaces.length,
|
|
1175
1360
|
schemaCount: filesWithSchema.length,
|
|
1176
1361
|
queryCount,
|
|
1177
1362
|
mutationCount,
|
|
@@ -1181,9 +1366,6 @@ export async function generate(options: GenerateOptions): Promise<GenerateResult
|
|
|
1181
1366
|
export async function watch(options: WatchOptions) {
|
|
1182
1367
|
const { dir, debounce = 1000 } = options
|
|
1183
1368
|
const baseDir = resolve(dir)
|
|
1184
|
-
const mutationsDir = resolve(baseDir, 'mutations')
|
|
1185
|
-
const modelsDir = existsSync(mutationsDir) ? mutationsDir : resolve(baseDir, 'models')
|
|
1186
|
-
const queriesDir = resolve(baseDir, 'queries')
|
|
1187
1369
|
const generatedDir = resolve(baseDir, 'generated')
|
|
1188
1370
|
|
|
1189
1371
|
// initial run (silent)
|
|
@@ -1202,11 +1384,26 @@ export async function watch(options: WatchOptions) {
|
|
|
1202
1384
|
}, debounce)
|
|
1203
1385
|
}
|
|
1204
1386
|
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1387
|
+
const databaseDir = resolve(dirname(baseDir), 'database')
|
|
1388
|
+
const ts = await import('typescript')
|
|
1389
|
+
const layout = discoverDataLayout(
|
|
1390
|
+
ts,
|
|
1391
|
+
baseDir,
|
|
1392
|
+
options.config ? resolve(options.config) : undefined
|
|
1393
|
+
)
|
|
1394
|
+
const watcher = chokidar.watch(
|
|
1395
|
+
[
|
|
1396
|
+
...new Set([
|
|
1397
|
+
...layout.sourceRoots,
|
|
1398
|
+
...(existsSync(databaseDir) ? [databaseDir] : []),
|
|
1399
|
+
]),
|
|
1400
|
+
],
|
|
1401
|
+
{
|
|
1402
|
+
persistent: true,
|
|
1403
|
+
ignoreInitial: true,
|
|
1404
|
+
ignored: [generatedDir, /node_modules/],
|
|
1405
|
+
}
|
|
1406
|
+
)
|
|
1210
1407
|
|
|
1211
1408
|
watcher.on('change', (path) => debouncedRegenerate(path, '📝'))
|
|
1212
1409
|
watcher.on('add', (path) => debouncedRegenerate(path, '➕'))
|