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
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var mutationLifecycle_exports = {};
|
|
26
|
+
__export(mutationLifecycle_exports, {
|
|
27
|
+
MutationResultError: () => MutationResultError,
|
|
28
|
+
MutationTimeoutError: () => MutationTimeoutError,
|
|
29
|
+
StaleGenerationError: () => StaleGenerationError,
|
|
30
|
+
createMutationLifecycle: () => createMutationLifecycle,
|
|
31
|
+
isStaleGenerationError: () => isStaleGenerationError,
|
|
32
|
+
mutationErrorMessage: () => mutationErrorMessage
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(mutationLifecycle_exports);
|
|
35
|
+
function _assert_this_initialized(self) {
|
|
36
|
+
if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
37
|
+
return self;
|
|
38
|
+
}
|
|
39
|
+
function _call_super(_this, derived, args) {
|
|
40
|
+
derived = _get_prototype_of(derived);
|
|
41
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
42
|
+
}
|
|
43
|
+
function _class_call_check(instance, Constructor) {
|
|
44
|
+
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
|
|
45
|
+
}
|
|
46
|
+
function _construct(Parent, args, Class) {
|
|
47
|
+
if (_is_native_reflect_construct()) _construct = Reflect.construct;else {
|
|
48
|
+
_construct = function construct(Parent2, args2, Class2) {
|
|
49
|
+
var a = [null];
|
|
50
|
+
a.push.apply(a, args2);
|
|
51
|
+
var Constructor = Function.bind.apply(Parent2, a);
|
|
52
|
+
var instance = new Constructor();
|
|
53
|
+
if (Class2) _set_prototype_of(instance, Class2.prototype);
|
|
54
|
+
return instance;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return _construct.apply(null, arguments);
|
|
58
|
+
}
|
|
59
|
+
function _define_property(obj, key, value) {
|
|
60
|
+
if (key in obj) {
|
|
61
|
+
Object.defineProperty(obj, key, {
|
|
62
|
+
value,
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true
|
|
66
|
+
});
|
|
67
|
+
} else obj[key] = value;
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
function _get_prototype_of(o) {
|
|
71
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o2) {
|
|
72
|
+
return o2.__proto__ || Object.getPrototypeOf(o2);
|
|
73
|
+
};
|
|
74
|
+
return _get_prototype_of(o);
|
|
75
|
+
}
|
|
76
|
+
function _inherits(subClass, superClass) {
|
|
77
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
78
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
79
|
+
}
|
|
80
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
81
|
+
constructor: {
|
|
82
|
+
value: subClass,
|
|
83
|
+
writable: true,
|
|
84
|
+
configurable: true
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
88
|
+
}
|
|
89
|
+
function _instanceof(left, right) {
|
|
90
|
+
"@swc/helpers - instanceof";
|
|
91
|
+
|
|
92
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
93
|
+
return !!right[Symbol.hasInstance](left);
|
|
94
|
+
} else return left instanceof right;
|
|
95
|
+
}
|
|
96
|
+
function _is_native_function(fn) {
|
|
97
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
98
|
+
}
|
|
99
|
+
function _is_native_reflect_construct() {
|
|
100
|
+
try {
|
|
101
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
102
|
+
} catch (_) {}
|
|
103
|
+
return (_is_native_reflect_construct = function () {
|
|
104
|
+
return !!result;
|
|
105
|
+
})();
|
|
106
|
+
}
|
|
107
|
+
function _possible_constructor_return(self, call) {
|
|
108
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
|
|
109
|
+
return _assert_this_initialized(self);
|
|
110
|
+
}
|
|
111
|
+
function _set_prototype_of(o, p) {
|
|
112
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o2, p2) {
|
|
113
|
+
o2.__proto__ = p2;
|
|
114
|
+
return o2;
|
|
115
|
+
};
|
|
116
|
+
return _set_prototype_of(o, p);
|
|
117
|
+
}
|
|
118
|
+
function _type_of(obj) {
|
|
119
|
+
"@swc/helpers - typeof";
|
|
120
|
+
|
|
121
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
122
|
+
}
|
|
123
|
+
function _wrap_native_super(Class) {
|
|
124
|
+
var _cache = typeof Map === "function" ? /* @__PURE__ */new Map() : void 0;
|
|
125
|
+
_wrap_native_super = function (Class2) {
|
|
126
|
+
if (Class2 === null || !_is_native_function(Class2)) return Class2;
|
|
127
|
+
if (typeof Class2 !== "function") throw new TypeError("Super expression must either be null or a function");
|
|
128
|
+
if (typeof _cache !== "undefined") {
|
|
129
|
+
if (_cache.has(Class2)) return _cache.get(Class2);
|
|
130
|
+
_cache.set(Class2, Wrapper);
|
|
131
|
+
}
|
|
132
|
+
function Wrapper() {
|
|
133
|
+
return _construct(Class2, arguments, _get_prototype_of(this).constructor);
|
|
134
|
+
}
|
|
135
|
+
Wrapper.prototype = Object.create(Class2.prototype, {
|
|
136
|
+
constructor: {
|
|
137
|
+
value: Wrapper,
|
|
138
|
+
enumerable: false,
|
|
139
|
+
writable: true,
|
|
140
|
+
configurable: true
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return _set_prototype_of(Wrapper, Class2);
|
|
144
|
+
};
|
|
145
|
+
return _wrap_native_super(Class);
|
|
146
|
+
}
|
|
147
|
+
var StaleGenerationError = /* @__PURE__ */function (Error1) {
|
|
148
|
+
"use strict";
|
|
149
|
+
|
|
150
|
+
_inherits(StaleGenerationError2, Error1);
|
|
151
|
+
function StaleGenerationError2(label) {
|
|
152
|
+
_class_call_check(this, StaleGenerationError2);
|
|
153
|
+
var _this;
|
|
154
|
+
_this = _call_super(this, StaleGenerationError2, [`${label} stopped because its Zero instance was replaced or recovered`]), _define_property(_this, "label", void 0);
|
|
155
|
+
_this.name = "StaleGenerationError";
|
|
156
|
+
_this.label = label;
|
|
157
|
+
return _this;
|
|
158
|
+
}
|
|
159
|
+
return StaleGenerationError2;
|
|
160
|
+
}(_wrap_native_super(Error));
|
|
161
|
+
var MutationTimeoutError = /* @__PURE__ */function (Error1) {
|
|
162
|
+
"use strict";
|
|
163
|
+
|
|
164
|
+
_inherits(MutationTimeoutError2, Error1);
|
|
165
|
+
function MutationTimeoutError2(label, phase, timeoutMs) {
|
|
166
|
+
_class_call_check(this, MutationTimeoutError2);
|
|
167
|
+
var _this;
|
|
168
|
+
_this = _call_super(this, MutationTimeoutError2, [phase === "server" ? `${label} server acknowledgement did not complete within ${timeoutMs}ms` : `${label} did not complete within ${timeoutMs}ms`]), _define_property(_this, "label", void 0), _define_property(_this, "phase", void 0), _define_property(_this, "timeoutMs", void 0);
|
|
169
|
+
_this.name = "MutationTimeoutError";
|
|
170
|
+
_this.label = label;
|
|
171
|
+
_this.phase = phase;
|
|
172
|
+
_this.timeoutMs = timeoutMs;
|
|
173
|
+
return _this;
|
|
174
|
+
}
|
|
175
|
+
return MutationTimeoutError2;
|
|
176
|
+
}(_wrap_native_super(Error));
|
|
177
|
+
var MutationResultError = /* @__PURE__ */function (Error1) {
|
|
178
|
+
"use strict";
|
|
179
|
+
|
|
180
|
+
_inherits(MutationResultError2, Error1);
|
|
181
|
+
function MutationResultError2(label, phase, result, message) {
|
|
182
|
+
_class_call_check(this, MutationResultError2);
|
|
183
|
+
var _this;
|
|
184
|
+
_this = _call_super(this, MutationResultError2, [`${label} failed${phase === "server" ? " on server" : ""}: ${message}`]), _define_property(_this, "label", void 0), _define_property(_this, "phase", void 0), _define_property(_this, "result", void 0);
|
|
185
|
+
_this.name = "MutationResultError";
|
|
186
|
+
_this.label = label;
|
|
187
|
+
_this.phase = phase;
|
|
188
|
+
_this.result = result;
|
|
189
|
+
return _this;
|
|
190
|
+
}
|
|
191
|
+
return MutationResultError2;
|
|
192
|
+
}(_wrap_native_super(Error));
|
|
193
|
+
function isStaleGenerationError(error) {
|
|
194
|
+
return _instanceof(error, StaleGenerationError);
|
|
195
|
+
}
|
|
196
|
+
function mutationErrorMessage(result) {
|
|
197
|
+
if (!result || (typeof result === "undefined" ? "undefined" : _type_of(result)) !== "object") return null;
|
|
198
|
+
var typed = result;
|
|
199
|
+
if (typed.type !== "error") return null;
|
|
200
|
+
return describeMutationError(typed.error);
|
|
201
|
+
}
|
|
202
|
+
function describeMutationError(error) {
|
|
203
|
+
if (_instanceof(error, Error)) return error.message;
|
|
204
|
+
if (error && (typeof error === "undefined" ? "undefined" : _type_of(error)) === "object") {
|
|
205
|
+
var typed = error;
|
|
206
|
+
var parts = [typed.type, typed.message].filter(function (part) {
|
|
207
|
+
return typeof part === "string" && part.length > 0;
|
|
208
|
+
});
|
|
209
|
+
if (parts.length) return parts.join(": ");
|
|
210
|
+
}
|
|
211
|
+
return String(error);
|
|
212
|
+
}
|
|
213
|
+
function createMutationLifecycle(options) {
|
|
214
|
+
var queue = {
|
|
215
|
+
tail: Promise.resolve(),
|
|
216
|
+
lastErrorMessage: null,
|
|
217
|
+
coalesceSequence: /* @__PURE__ */new Map()
|
|
218
|
+
};
|
|
219
|
+
var waiters = /* @__PURE__ */new Set();
|
|
220
|
+
var generation = 0;
|
|
221
|
+
var active = false;
|
|
222
|
+
var consecutiveServerAckTimeouts = 0;
|
|
223
|
+
function stale(label) {
|
|
224
|
+
return new StaleGenerationError(label);
|
|
225
|
+
}
|
|
226
|
+
function fence() {
|
|
227
|
+
if (!active) return;
|
|
228
|
+
active = false;
|
|
229
|
+
generation += 1;
|
|
230
|
+
consecutiveServerAckTimeouts = 0;
|
|
231
|
+
queue.coalesceSequence.clear();
|
|
232
|
+
for (var _i = 0, _iter = [...waiters]; _i < _iter.length; _i++) {
|
|
233
|
+
var waiter = _iter[_i];
|
|
234
|
+
waiters.delete(waiter);
|
|
235
|
+
waiter.reject();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function activate() {
|
|
239
|
+
if (active) return;
|
|
240
|
+
generation += 1;
|
|
241
|
+
active = true;
|
|
242
|
+
consecutiveServerAckTimeouts = 0;
|
|
243
|
+
queue.lastErrorMessage = null;
|
|
244
|
+
}
|
|
245
|
+
function observeGeneration(capturedGeneration, label) {
|
|
246
|
+
var waiter;
|
|
247
|
+
var promise = new Promise(function (_, reject) {
|
|
248
|
+
if (!active || capturedGeneration !== generation) {
|
|
249
|
+
reject(stale(label));
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
waiter = {
|
|
253
|
+
reject: function reject1() {
|
|
254
|
+
return reject(stale(label));
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
waiters.add(waiter);
|
|
258
|
+
if (!active || capturedGeneration !== generation) {
|
|
259
|
+
waiters.delete(waiter);
|
|
260
|
+
waiter = void 0;
|
|
261
|
+
reject(stale(label));
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
return {
|
|
265
|
+
promise,
|
|
266
|
+
dispose() {
|
|
267
|
+
if (waiter) waiters.delete(waiter);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
async function awaitInGeneration(input) {
|
|
272
|
+
if (!active || input.generation !== generation) throw stale(input.label);
|
|
273
|
+
var timer;
|
|
274
|
+
var generationChange = observeGeneration(input.generation, input.label);
|
|
275
|
+
try {
|
|
276
|
+
return await Promise.race([input.promise, generationChange.promise, new Promise(function (_, reject) {
|
|
277
|
+
timer = setTimeout(function () {
|
|
278
|
+
return reject(new MutationTimeoutError(input.label, input.phase, input.timeoutMs));
|
|
279
|
+
}, input.timeoutMs);
|
|
280
|
+
})]);
|
|
281
|
+
} finally {
|
|
282
|
+
generationChange.dispose();
|
|
283
|
+
if (timer) clearTimeout(timer);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async function settleMutationClient(mutation, label, timeoutMs, capturedGeneration, observeServerFailure) {
|
|
287
|
+
var result = await awaitInGeneration({
|
|
288
|
+
promise: mutation.client,
|
|
289
|
+
label,
|
|
290
|
+
phase: "client",
|
|
291
|
+
timeoutMs,
|
|
292
|
+
generation: capturedGeneration
|
|
293
|
+
});
|
|
294
|
+
var message = mutationErrorMessage(result);
|
|
295
|
+
if (message) throw new MutationResultError(label, "client", result, message);
|
|
296
|
+
if (observeServerFailure) {
|
|
297
|
+
var _mutation_server;
|
|
298
|
+
(_mutation_server = mutation.server) === null || _mutation_server === void 0 ? void 0 : _mutation_server.catch(function (error) {
|
|
299
|
+
if (!active || capturedGeneration !== generation) return;
|
|
300
|
+
console.warn(`[on-zero] ${label} server replication failed:`, error);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
function awaitMutationClient(mutation, label) {
|
|
306
|
+
var timeoutMs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 3e4;
|
|
307
|
+
return settleMutationClient(mutation, label, timeoutMs, generation, true);
|
|
308
|
+
}
|
|
309
|
+
async function awaitMutationServer(mutation, label) {
|
|
310
|
+
var timeoutMs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 3e4;
|
|
311
|
+
var capturedGeneration = generation;
|
|
312
|
+
var clientResult = await settleMutationClient(mutation, label, timeoutMs, capturedGeneration, false);
|
|
313
|
+
if (!mutation.server) return clientResult;
|
|
314
|
+
try {
|
|
315
|
+
var serverResult = await awaitInGeneration({
|
|
316
|
+
promise: mutation.server,
|
|
317
|
+
label,
|
|
318
|
+
phase: "server",
|
|
319
|
+
timeoutMs,
|
|
320
|
+
generation: capturedGeneration
|
|
321
|
+
});
|
|
322
|
+
consecutiveServerAckTimeouts = 0;
|
|
323
|
+
var message = mutationErrorMessage(serverResult);
|
|
324
|
+
if (message) throw new MutationResultError(label, "server", serverResult, message);
|
|
325
|
+
return serverResult;
|
|
326
|
+
} catch (error) {
|
|
327
|
+
if (_instanceof(error, MutationTimeoutError) && error.phase === "server") {
|
|
328
|
+
consecutiveServerAckTimeouts += 1;
|
|
329
|
+
if (consecutiveServerAckTimeouts >= options.ackTimeoutRecoveryThreshold) {
|
|
330
|
+
options.recoverFromAckTimeout({
|
|
331
|
+
label,
|
|
332
|
+
timeoutMs,
|
|
333
|
+
consecutiveTimeouts: consecutiveServerAckTimeouts
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
throw error;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function enqueueBackgroundMutation(label, create) {
|
|
341
|
+
var mutationOptions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
342
|
+
var _queue_coalesceSequence_get;
|
|
343
|
+
var capturedGeneration = generation;
|
|
344
|
+
var {
|
|
345
|
+
coalesceKey = "",
|
|
346
|
+
settle = "client",
|
|
347
|
+
timeoutMs = 12e4
|
|
348
|
+
} = mutationOptions;
|
|
349
|
+
var sequence = coalesceKey ? ((_queue_coalesceSequence_get = queue.coalesceSequence.get(coalesceKey)) !== null && _queue_coalesceSequence_get !== void 0 ? _queue_coalesceSequence_get : 0) + 1 : 0;
|
|
350
|
+
if (coalesceKey) queue.coalesceSequence.set(coalesceKey, sequence);
|
|
351
|
+
var queued = queue.tail.then(async function () {
|
|
352
|
+
if (!active || capturedGeneration !== generation) throw stale(label);
|
|
353
|
+
if (coalesceKey) {
|
|
354
|
+
if (queue.coalesceSequence.get(coalesceKey) !== sequence) return;
|
|
355
|
+
queue.coalesceSequence.delete(coalesceKey);
|
|
356
|
+
}
|
|
357
|
+
var result2 = await create();
|
|
358
|
+
if (result2 && (typeof result2 === "undefined" ? "undefined" : _type_of(result2)) === "object" && "client" in result2) {
|
|
359
|
+
var mutation = result2;
|
|
360
|
+
if (settle === "server" && mutation.server) {
|
|
361
|
+
await awaitMutationServer(mutation, label, timeoutMs);
|
|
362
|
+
} else {
|
|
363
|
+
await settleMutationClient(mutation, label, timeoutMs, capturedGeneration, true);
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
await result2;
|
|
367
|
+
}
|
|
368
|
+
queue.lastErrorMessage = null;
|
|
369
|
+
});
|
|
370
|
+
var result = queued.catch(function (error) {
|
|
371
|
+
if (isStaleGenerationError(error)) return;
|
|
372
|
+
if (!active || capturedGeneration !== generation) return;
|
|
373
|
+
var message = describeMutationError(error);
|
|
374
|
+
var alreadyLogged = queue.lastErrorMessage === message;
|
|
375
|
+
queue.lastErrorMessage = message;
|
|
376
|
+
if (!alreadyLogged) {
|
|
377
|
+
console.warn(`[on-zero] ${label} background mutation failed:`, error);
|
|
378
|
+
}
|
|
379
|
+
throw error;
|
|
380
|
+
});
|
|
381
|
+
queue.tail = result.catch(function () {});
|
|
382
|
+
return result;
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
activate,
|
|
386
|
+
fence,
|
|
387
|
+
enqueueBackgroundMutation,
|
|
388
|
+
awaitMutationClient,
|
|
389
|
+
awaitMutationServer
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
//# sourceMappingURL=mutationLifecycle.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","mutationLifecycle_exports","__export","MutationResultError","MutationTimeoutError","StaleGenerationError","createMutationLifecycle","isStaleGenerationError","mutationErrorMessage","module","exports","_assert_this_initialized","self","ReferenceError","_call_super","_this","derived","args","_get_prototype_of","_possible_constructor_return","_is_native_reflect_construct","Reflect","construct","constructor","apply","_class_call_check","instance","Constructor","TypeError","_construct","Parent","Class","Parent2","args2","Class2","a","push","Function","bind","_set_prototype_of","prototype","arguments","_define_property","obj","key","Object","defineProperty","enumerable","configurable","writable","o","setPrototypeOf","getPrototypeOf","o2","__proto__","_inherits","subClass","superClass","create","_instanceof","left","right","Symbol","hasInstance","_is_native_function","fn","toString","call","indexOf","result","Boolean","valueOf","_","_type_of","p","p2","_wrap_native_super","_cache","Map","has","get","set","Wrapper","Error1","StaleGenerationError2","label","name","Error","MutationTimeoutError2","phase","timeoutMs","MutationResultError2","message","error","typed","type","describeMutationError","parts","filter","part","length","join","String","options","queue","tail","Promise","resolve","lastErrorMessage","coalesceSequence","waiters","Set","generation","active","consecutiveServerAckTimeouts","stale","fence","clear","_i","_iter","waiter","delete","reject","activate","observeGeneration","capturedGeneration","promise","reject1"],"sources":["../../../src/helpers/mutationLifecycle.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,yBAAA;AAA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EAAAkB,EAAA;MAED,IAAME,MAAA,GAASD,KAAA,CAAAD,EAAO;MACpBR,OAAI,CAAAW,MAAA,CAAAD,MAAA;MACJA,MAAK,CAAAE,MAAA,EAAU;IACf;EACA;EACA,SAAAC,QAAMA,CAAA;IACN,IAAAV,MAAK;IACHD,UAAA,IAAQ;IAA4DC,MACtE;IACAC,4BAAM;IACRV,KAAC,CAAAI,gBAAA;EACD;EAAgC,SAAEgB,kBAAAC,kBAAA,EAAAxC,KAAA;IAClC,IAAAmC,MAAO;IACT,IAAAM,OAAA,OAAApB,OAAA,WAAAlC,CAAA,EAAAkD,MAAA;MAEA,IAAO,CAAAT,MAAA,IAAAY,kBAAA,KAAAb,UAAA;QACLU,MAAA,CAAAP,KAAA,CAAA9B,KAAA;QACA;MACA;MACAmC,MAAA;QACAE,MAAA,WAAAK,QAAA;UACF,OAAAL,MAAA,CAAAP,KAAA,CAAA9B,KAAA;QACF","ignoreList":[]}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
var import_vitest = require("vitest");
|
|
2
|
+
var import_mutationLifecycle = require("./mutationLifecycle.cjs");
|
|
3
|
+
function deferred() {
|
|
4
|
+
let resolve;
|
|
5
|
+
let reject;
|
|
6
|
+
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
7
|
+
resolve = resolvePromise;
|
|
8
|
+
reject = rejectPromise;
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
promise,
|
|
12
|
+
reject,
|
|
13
|
+
resolve
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function setup(threshold = 2) {
|
|
17
|
+
const recoverFromAckTimeout = import_vitest.vi.fn();
|
|
18
|
+
const lifecycle = (0, import_mutationLifecycle.createMutationLifecycle)({
|
|
19
|
+
ackTimeoutRecoveryThreshold: threshold,
|
|
20
|
+
recoverFromAckTimeout
|
|
21
|
+
});
|
|
22
|
+
lifecycle.activate();
|
|
23
|
+
return {
|
|
24
|
+
lifecycle,
|
|
25
|
+
recoverFromAckTimeout
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
(0, import_vitest.beforeEach)(() => {
|
|
29
|
+
import_vitest.vi.restoreAllMocks();
|
|
30
|
+
});
|
|
31
|
+
(0, import_vitest.describe)("mutation lifecycle", () => {
|
|
32
|
+
(0, import_vitest.test)("extracts typed mutation errors and times out each settlement phase", async () => {
|
|
33
|
+
import_vitest.vi.useFakeTimers();
|
|
34
|
+
try {
|
|
35
|
+
const {
|
|
36
|
+
lifecycle
|
|
37
|
+
} = setup();
|
|
38
|
+
await (0, import_vitest.expect)(lifecycle.awaitMutationClient({
|
|
39
|
+
client: Promise.resolve({
|
|
40
|
+
type: "error",
|
|
41
|
+
error: {
|
|
42
|
+
message: "denied"
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}, "save note")).rejects.toMatchObject({
|
|
46
|
+
name: "MutationResultError",
|
|
47
|
+
label: "save note",
|
|
48
|
+
phase: "client"
|
|
49
|
+
});
|
|
50
|
+
const waiting = lifecycle.awaitMutationClient({
|
|
51
|
+
client: new Promise(() => {})
|
|
52
|
+
}, "stuck note", 20);
|
|
53
|
+
const timedOut = (0, import_vitest.expect)(waiting).rejects.toMatchObject({
|
|
54
|
+
name: "MutationTimeoutError",
|
|
55
|
+
phase: "client",
|
|
56
|
+
timeoutMs: 20
|
|
57
|
+
});
|
|
58
|
+
await import_vitest.vi.advanceTimersByTimeAsync(20);
|
|
59
|
+
await timedOut;
|
|
60
|
+
} finally {
|
|
61
|
+
import_vitest.vi.useRealTimers();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
(0, import_vitest.test)("serializes work and skips superseded coalesced writes", async () => {
|
|
65
|
+
const {
|
|
66
|
+
lifecycle
|
|
67
|
+
} = setup();
|
|
68
|
+
const blocker = deferred();
|
|
69
|
+
const first = lifecycle.enqueueBackgroundMutation("blocker", () => blocker.promise);
|
|
70
|
+
const superseded = import_vitest.vi.fn();
|
|
71
|
+
const latest = import_vitest.vi.fn(async () => {});
|
|
72
|
+
const oldWrite = lifecycle.enqueueBackgroundMutation("old row", superseded, {
|
|
73
|
+
coalesceKey: "message:1"
|
|
74
|
+
});
|
|
75
|
+
const newWrite = lifecycle.enqueueBackgroundMutation("new row", latest, {
|
|
76
|
+
coalesceKey: "message:1"
|
|
77
|
+
});
|
|
78
|
+
blocker.resolve();
|
|
79
|
+
await Promise.all([first, oldWrite, newWrite]);
|
|
80
|
+
(0, import_vitest.expect)(superseded).not.toHaveBeenCalled();
|
|
81
|
+
(0, import_vitest.expect)(latest).toHaveBeenCalledOnce();
|
|
82
|
+
});
|
|
83
|
+
(0, import_vitest.test)("one failed background mutation does not poison later work", async () => {
|
|
84
|
+
const {
|
|
85
|
+
lifecycle
|
|
86
|
+
} = setup();
|
|
87
|
+
import_vitest.vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
88
|
+
const denied = lifecycle.enqueueBackgroundMutation("stamp", async () => {
|
|
89
|
+
throw new Error("PermissionError: stale task");
|
|
90
|
+
});
|
|
91
|
+
await (0, import_vitest.expect)(denied).rejects.toThrow("PermissionError");
|
|
92
|
+
const next = import_vitest.vi.fn(async () => {});
|
|
93
|
+
await lifecycle.enqueueBackgroundMutation("clear stamp", next);
|
|
94
|
+
(0, import_vitest.expect)(next).toHaveBeenCalledOnce();
|
|
95
|
+
});
|
|
96
|
+
(0, import_vitest.test)("recovery or close quietly drops in-flight and queued background work", async () => {
|
|
97
|
+
const {
|
|
98
|
+
lifecycle
|
|
99
|
+
} = setup();
|
|
100
|
+
const client = deferred();
|
|
101
|
+
const queuedCreate = import_vitest.vi.fn(async () => {});
|
|
102
|
+
const inFlight = lifecycle.enqueueBackgroundMutation("in flight", () => ({
|
|
103
|
+
client: client.promise
|
|
104
|
+
}));
|
|
105
|
+
const queued = lifecycle.enqueueBackgroundMutation("queued", queuedCreate);
|
|
106
|
+
lifecycle.fence();
|
|
107
|
+
await (0, import_vitest.expect)(inFlight).resolves.toBeUndefined();
|
|
108
|
+
await (0, import_vitest.expect)(queued).resolves.toBeUndefined();
|
|
109
|
+
(0, import_vitest.expect)(queuedCreate).not.toHaveBeenCalled();
|
|
110
|
+
const direct = lifecycle.awaitMutationClient({
|
|
111
|
+
client: Promise.resolve({})
|
|
112
|
+
}, "direct after close");
|
|
113
|
+
await (0, import_vitest.expect)(direct).rejects.toBeInstanceOf(import_mutationLifecycle.StaleGenerationError);
|
|
114
|
+
});
|
|
115
|
+
(0, import_vitest.test)("recovers only after consecutive server acknowledgement timeouts", async () => {
|
|
116
|
+
import_vitest.vi.useFakeTimers();
|
|
117
|
+
try {
|
|
118
|
+
const {
|
|
119
|
+
lifecycle,
|
|
120
|
+
recoverFromAckTimeout
|
|
121
|
+
} = setup();
|
|
122
|
+
const timeout = async label => {
|
|
123
|
+
const result = lifecycle.awaitMutationServer({
|
|
124
|
+
client: Promise.resolve({}),
|
|
125
|
+
server: new Promise(() => {})
|
|
126
|
+
}, label, 10);
|
|
127
|
+
const timedOut = (0, import_vitest.expect)(result).rejects.toMatchObject({
|
|
128
|
+
name: "MutationTimeoutError",
|
|
129
|
+
phase: "server"
|
|
130
|
+
});
|
|
131
|
+
await import_vitest.vi.advanceTimersByTimeAsync(10);
|
|
132
|
+
await timedOut;
|
|
133
|
+
};
|
|
134
|
+
await timeout("first");
|
|
135
|
+
(0, import_vitest.expect)(recoverFromAckTimeout).not.toHaveBeenCalled();
|
|
136
|
+
await timeout("second");
|
|
137
|
+
(0, import_vitest.expect)(recoverFromAckTimeout).toHaveBeenCalledOnce();
|
|
138
|
+
(0, import_vitest.expect)(recoverFromAckTimeout).toHaveBeenCalledWith({
|
|
139
|
+
label: "second",
|
|
140
|
+
timeoutMs: 10,
|
|
141
|
+
consecutiveTimeouts: 2
|
|
142
|
+
});
|
|
143
|
+
} finally {
|
|
144
|
+
import_vitest.vi.useRealTimers();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
(0, import_vitest.test)("a server response resets the consecutive timeout count", async () => {
|
|
148
|
+
import_vitest.vi.useFakeTimers();
|
|
149
|
+
try {
|
|
150
|
+
const {
|
|
151
|
+
lifecycle,
|
|
152
|
+
recoverFromAckTimeout
|
|
153
|
+
} = setup();
|
|
154
|
+
const timeout = async () => {
|
|
155
|
+
const result = lifecycle.awaitMutationServer({
|
|
156
|
+
client: Promise.resolve({}),
|
|
157
|
+
server: new Promise(() => {})
|
|
158
|
+
}, "write", 10);
|
|
159
|
+
const timedOut = (0, import_vitest.expect)(result).rejects.toBeInstanceOf(import_mutationLifecycle.MutationTimeoutError);
|
|
160
|
+
await import_vitest.vi.advanceTimersByTimeAsync(10);
|
|
161
|
+
await timedOut;
|
|
162
|
+
};
|
|
163
|
+
await timeout();
|
|
164
|
+
await (0, import_vitest.expect)(lifecycle.awaitMutationServer({
|
|
165
|
+
client: Promise.resolve({}),
|
|
166
|
+
server: Promise.resolve({})
|
|
167
|
+
}, "acked write", 10)).resolves.toEqual({});
|
|
168
|
+
await timeout();
|
|
169
|
+
(0, import_vitest.expect)(recoverFromAckTimeout).not.toHaveBeenCalled();
|
|
170
|
+
} finally {
|
|
171
|
+
import_vitest.vi.useRealTimers();
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|