zitejs 0.10.0-start.9 → 0.10.1-device.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/dist/cjs/auth/actions.d.ts +28 -0
- package/dist/cjs/auth/actions.js +95 -0
- package/dist/cjs/auth/client.d.ts +357 -0
- package/dist/cjs/auth/client.js +71 -0
- package/dist/cjs/auth/config.js +9 -3
- package/dist/cjs/auth/index.d.ts +2 -249
- package/dist/cjs/auth/index.js +11 -108
- package/dist/cjs/auth/index.test.js +60 -0
- package/dist/cjs/auth/previewClaim.d.ts +7 -0
- package/dist/cjs/auth/previewClaim.js +16 -0
- package/dist/cjs/auth/profileUpdates.d.ts +9 -0
- package/dist/cjs/auth/profileUpdates.js +11 -0
- package/dist/cjs/auth/useAuth.test.js +1 -0
- package/dist/cjs/backend/index.d.ts +15 -9
- package/dist/cjs/backend/index.js +13 -13
- package/dist/cjs/backend/index.test.js +102 -102
- package/dist/cjs/bundle/index.d.ts +8 -0
- package/dist/cjs/bundle/index.js +38 -24
- package/dist/cjs/caller/index.js +37 -48
- package/dist/cjs/check/index.d.ts +20 -9
- package/dist/cjs/check/index.js +113 -88
- package/dist/cjs/check/start/routeTree.d.ts +8 -0
- package/dist/cjs/check/start/routeTree.js +118 -0
- package/dist/cjs/check/start/tsgo.d.ts +2 -0
- package/dist/cjs/check/start/tsgo.js +35 -0
- package/dist/cjs/cli.js +10 -4
- package/dist/cjs/client/index.d.ts +26 -2
- package/dist/cjs/client/index.js +25 -25
- package/dist/cjs/dev/index.js +79 -54
- package/dist/cjs/dev/signin.d.ts +16 -0
- package/dist/cjs/dev/signin.js +84 -0
- package/dist/cjs/index.d.ts +5 -5
- package/dist/cjs/integrations/client.d.ts +3 -3
- package/dist/cjs/integrations/client.js +5 -4
- package/dist/cjs/integrations/client.test-d.js +15 -15
- package/dist/cjs/integrations/index.d.ts +2 -2
- package/dist/cjs/integrations/rules.d.ts +1 -0
- package/dist/cjs/integrations/rules.js +48 -43
- package/dist/cjs/integrations/rules.test.js +60 -54
- package/dist/cjs/internal/appMode.d.ts +14 -0
- package/dist/cjs/internal/appMode.js +19 -0
- package/dist/cjs/internal/browserMode.d.ts +2 -0
- package/dist/cjs/internal/browserMode.js +18 -0
- package/dist/cjs/internal/deviceCache.d.ts +11 -0
- package/dist/cjs/internal/deviceCache.js +29 -0
- package/dist/cjs/internal/env.js +3 -2
- package/dist/cjs/internal/platformFetch.d.ts +2 -0
- package/dist/cjs/internal/platformFetch.js +14 -0
- package/dist/cjs/internal/reservedIds.d.ts +8 -0
- package/dist/cjs/internal/reservedIds.js +14 -0
- package/dist/cjs/internal/serviceUrls.d.ts +5 -0
- package/dist/cjs/internal/serviceUrls.js +14 -0
- package/dist/cjs/pdf/index.js +2 -1
- package/dist/cjs/query/deviceCache.d.ts +14 -0
- package/dist/cjs/query/deviceCache.js +304 -0
- package/dist/cjs/query/index.d.ts +19 -0
- package/dist/cjs/query/index.js +369 -0
- package/dist/cjs/runtime/filterConditionTypes.test-d.js +11 -11
- package/dist/cjs/runtime/index.d.ts +126 -39
- package/dist/cjs/runtime/index.js +32 -26
- package/dist/cjs/runtime/index.test.js +34 -34
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +50 -0
- package/dist/cjs/runtime/writeResultTypes.test-d.js +8 -8
- package/dist/cjs/sourceRoots.js +15 -15
- package/dist/cjs/sourceRoots.test.js +29 -27
- package/dist/cjs/start/{entries.d.ts → build/entries.d.ts} +9 -4
- package/dist/cjs/start/{entries.js → build/entries.js} +38 -21
- package/dist/cjs/start/build/placeholders/devApp.d.ts +1 -0
- package/dist/cjs/start/build/placeholders/devApp.js +6 -0
- package/dist/cjs/start/{describeBuilt.d.ts → describe/describeBuilt.d.ts} +2 -0
- package/dist/cjs/start/{describeBuilt.js → describe/describeBuilt.js} +55 -17
- package/dist/cjs/start/platform/aiUsage.d.ts +29 -0
- package/dist/cjs/start/platform/aiUsage.js +215 -0
- package/dist/cjs/start/platform/airtable/cache.d.ts +17 -0
- package/dist/cjs/start/platform/airtable/cache.js +93 -0
- package/dist/cjs/start/protocol.d.ts +19 -0
- package/dist/cjs/start/protocol.js +33 -0
- package/dist/cjs/start/serve/local/provider.d.ts +25 -0
- package/dist/cjs/start/serve/local/provider.js +196 -0
- package/dist/cjs/start/serve/provider.d.ts +19 -0
- package/dist/cjs/start/serve/provider.js +86 -0
- package/dist/cjs/start/types.d.ts +373 -0
- package/dist/cjs/start/types.js +2 -0
- package/dist/cjs/steps/index.d.ts +78 -0
- package/dist/cjs/steps/index.js +507 -0
- package/dist/cjs/steps/index.test.js +635 -0
- package/dist/cjs/sync/index.d.ts +1 -1
- package/dist/cjs/sync/index.js +28 -27
- package/dist/cjs/sync/lib.d.ts +15 -8
- package/dist/cjs/sync/lib.js +655 -655
- package/dist/cjs/sync/lib.test.js +177 -46
- package/dist/cjs/sync/sdkNames.d.ts +67 -9
- package/dist/cjs/sync/sdkNames.js +97 -31
- package/dist/cjs/sync/sdkNames.test.js +189 -113
- package/dist/cjs/types/fields.d.ts +9 -2
- package/dist/cjs/types/fields.js +110 -96
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/tables.d.ts +17 -1
- package/dist/cjs/upload/index.js +89 -24
- package/dist/cjs/upload/index.test.js +104 -1
- package/dist/cjs/vite/domTagNames.js +252 -252
- package/dist/cjs/vite/index.d.ts +1 -1
- package/dist/cjs/vite/index.js +87 -42
- package/dist/cjs/vite/index.test.js +36 -0
- package/dist/esm/auth/actions.d.ts +28 -0
- package/dist/esm/auth/actions.js +57 -0
- package/dist/esm/auth/client.d.ts +357 -0
- package/dist/esm/auth/client.js +67 -0
- package/dist/esm/auth/config.js +9 -3
- package/dist/esm/auth/index.d.ts +2 -249
- package/dist/esm/auth/index.js +2 -103
- package/dist/esm/auth/index.test.js +60 -0
- package/dist/esm/auth/previewClaim.d.ts +7 -0
- package/dist/esm/auth/previewClaim.js +12 -0
- package/dist/esm/auth/profileUpdates.d.ts +9 -0
- package/dist/esm/auth/profileUpdates.js +6 -0
- package/dist/esm/auth/useAuth.test.js +1 -0
- package/dist/esm/backend/index.d.ts +15 -9
- package/dist/esm/backend/index.js +13 -13
- package/dist/esm/backend/index.test.js +106 -106
- package/dist/esm/bundle/index.d.ts +8 -0
- package/dist/esm/bundle/index.js +37 -24
- package/dist/esm/caller/index.js +37 -48
- package/dist/esm/check/index.d.ts +20 -9
- package/dist/esm/check/index.js +117 -93
- package/dist/esm/check/start/routeTree.d.ts +8 -0
- package/dist/esm/check/start/routeTree.js +77 -0
- package/dist/esm/check/start/tsgo.d.ts +2 -0
- package/dist/esm/check/start/tsgo.js +29 -0
- package/dist/esm/cli.js +10 -4
- package/dist/esm/client/index.d.ts +26 -2
- package/dist/esm/client/index.js +25 -25
- package/dist/esm/dev/index.js +86 -61
- package/dist/esm/dev/signin.d.ts +16 -0
- package/dist/esm/dev/signin.js +80 -0
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +3 -3
- package/dist/esm/integrations/client.d.ts +3 -3
- package/dist/esm/integrations/client.js +6 -5
- package/dist/esm/integrations/client.test-d.js +19 -19
- package/dist/esm/integrations/index.d.ts +2 -2
- package/dist/esm/integrations/index.js +1 -1
- package/dist/esm/integrations/rules.d.ts +1 -0
- package/dist/esm/integrations/rules.js +48 -43
- package/dist/esm/integrations/rules.test.js +62 -56
- package/dist/esm/internal/appMode.d.ts +14 -0
- package/dist/esm/internal/appMode.js +13 -0
- package/dist/esm/internal/browserMode.d.ts +2 -0
- package/dist/esm/internal/browserMode.js +15 -0
- package/dist/esm/internal/deviceCache.d.ts +11 -0
- package/dist/esm/internal/deviceCache.js +24 -0
- package/dist/esm/internal/env.js +3 -2
- package/dist/esm/internal/platformFetch.d.ts +2 -0
- package/dist/esm/internal/platformFetch.js +9 -0
- package/dist/esm/internal/reservedIds.d.ts +8 -0
- package/dist/esm/internal/reservedIds.js +10 -0
- package/dist/esm/internal/serviceUrls.d.ts +5 -0
- package/dist/esm/internal/serviceUrls.js +10 -0
- package/dist/esm/pdf/index.js +2 -1
- package/dist/esm/query/deviceCache.d.ts +14 -0
- package/dist/esm/query/deviceCache.js +301 -0
- package/dist/esm/query/index.d.ts +19 -0
- package/dist/esm/query/index.js +366 -0
- package/dist/esm/runtime/filterConditionTypes.test-d.js +12 -12
- package/dist/esm/runtime/index.d.ts +126 -39
- package/dist/esm/runtime/index.js +35 -29
- package/dist/esm/runtime/index.test.js +36 -36
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +48 -0
- package/dist/esm/runtime/writeResultTypes.test-d.js +9 -9
- package/dist/esm/signin/conformance.d.ts +100 -0
- package/dist/esm/signin/conformance.js +616 -0
- package/dist/esm/signin/cookies.d.ts +28 -0
- package/dist/esm/signin/cookies.js +67 -0
- package/dist/esm/signin/encoding.d.ts +1 -0
- package/dist/esm/signin/encoding.js +12 -0
- package/dist/esm/signin/endpoints.d.ts +12 -0
- package/dist/esm/signin/endpoints.js +32 -0
- package/dist/esm/signin/http.d.ts +25 -0
- package/dist/esm/signin/http.js +106 -0
- package/dist/esm/signin/index.d.ts +8 -0
- package/dist/esm/signin/index.js +9 -0
- package/dist/esm/signin/keys.d.ts +35 -0
- package/dist/esm/signin/keys.js +230 -0
- package/dist/esm/signin/paths.d.ts +2 -0
- package/dist/esm/signin/paths.js +5 -0
- package/dist/esm/signin/seal.d.ts +19 -0
- package/dist/esm/signin/seal.js +47 -0
- package/dist/esm/signin/signin.d.ts +60 -0
- package/dist/esm/signin/signin.js +447 -0
- package/dist/esm/signin/transport.d.ts +112 -0
- package/dist/esm/signin/transport.js +1 -0
- package/dist/esm/signin/verifier.d.ts +2 -0
- package/dist/esm/signin/verifier.js +4 -0
- package/dist/esm/signin/verify.d.ts +83 -0
- package/dist/esm/signin/verify.js +142 -0
- package/dist/esm/sourceRoots.js +17 -17
- package/dist/esm/sourceRoots.test.js +34 -32
- package/dist/esm/start/access.d.ts +19 -0
- package/dist/esm/start/access.js +43 -0
- package/dist/esm/start/auth.d.ts +28 -0
- package/dist/esm/start/auth.js +33 -0
- package/dist/esm/start/automations/quiet.d.ts +2 -0
- package/dist/esm/start/automations/quiet.js +36 -0
- package/dist/esm/start/{registration.d.ts → automations/registration.d.ts} +1 -1
- package/dist/esm/start/{registration.js → automations/registration.js} +11 -7
- package/dist/esm/start/automations/steps.d.ts +29 -0
- package/dist/esm/start/automations/steps.js +95 -0
- package/dist/esm/start/automations/workflow.d.ts +83 -0
- package/dist/esm/start/automations/workflow.js +36 -0
- package/dist/esm/start/automations/workflow.test-d.d.ts +1 -0
- package/dist/esm/start/automations/workflow.test-d.js +130 -0
- package/dist/esm/start/automations/workflowRun.d.ts +130 -0
- package/dist/esm/start/automations/workflowRun.js +185 -0
- package/dist/esm/start/barrel.test-d.d.ts +10 -0
- package/dist/esm/start/barrel.test-d.js +6 -0
- package/dist/esm/start/{entries.d.ts → build/entries.d.ts} +9 -4
- package/dist/esm/start/{entries.js → build/entries.js} +38 -22
- package/dist/esm/start/build/placeholders/devApp.d.ts +1 -0
- package/dist/esm/start/build/placeholders/devApp.js +3 -0
- package/dist/esm/start/build/placeholders/devSignIn.d.ts +1 -0
- package/dist/esm/start/build/placeholders/devSignIn.js +3 -0
- package/dist/esm/start/build/placeholders/siteHead.d.ts +2 -0
- package/dist/esm/start/build/placeholders/siteHead.js +3 -0
- package/dist/esm/start/{workflowModules.js → build/placeholders/workflowModules.js} +1 -1
- package/dist/esm/start/build/placeholders/workspaceSchema.d.ts +2 -0
- package/dist/esm/start/build/placeholders/workspaceSchema.js +3 -0
- package/dist/esm/start/build/registrationHash.d.ts +11 -0
- package/dist/esm/start/build/registrationHash.js +88 -0
- package/dist/esm/start/build/sdk/axios.d.ts +76 -0
- package/dist/esm/start/build/sdk/axios.js +253 -0
- package/dist/esm/start/build/sdk/nodeFetch.d.ts +41 -0
- package/dist/esm/start/build/sdk/nodeFetch.js +35 -0
- package/dist/esm/start/build/sdk/undici.d.ts +34 -0
- package/dist/esm/start/build/sdk/undici.js +18 -0
- package/dist/esm/start/build/sdkPatches.d.ts +22 -0
- package/dist/esm/start/build/sdkPatches.js +430 -0
- package/dist/esm/start/build/siteHead.d.ts +26 -0
- package/dist/esm/start/build/siteHead.js +88 -0
- package/dist/esm/start/build/vite.d.ts +50 -0
- package/dist/esm/start/build/vite.js +491 -0
- package/dist/esm/start/classicOnly.d.ts +1 -0
- package/dist/esm/start/classicOnly.js +4 -0
- package/dist/esm/start/{describe.d.ts → describe/describe.d.ts} +44 -9
- package/dist/esm/start/describe/describe.js +372 -0
- package/dist/esm/start/{describeBuilt.d.ts → describe/describeBuilt.d.ts} +2 -0
- package/dist/esm/start/describe/describeBuilt.js +102 -0
- package/dist/esm/start/{descriptions.js → describe/descriptions.js} +17 -10
- package/dist/esm/start/errors.d.ts +15 -4
- package/dist/esm/start/errors.js +87 -28
- package/dist/esm/start/errors.test.js +47 -16
- package/dist/esm/start/factories.d.ts +14 -0
- package/dist/esm/start/factories.js +23 -0
- package/dist/esm/start/factories.test-d.d.ts +2 -1
- package/dist/esm/start/factories.test-d.js +52 -12
- package/dist/esm/start/failures.d.ts +7 -0
- package/dist/esm/start/failures.js +62 -0
- package/dist/esm/start/fnFactory.d.ts +16 -0
- package/dist/esm/start/fnFactory.js +1 -0
- package/dist/esm/start/host.d.ts +2 -2
- package/dist/esm/start/host.js +3 -3
- package/dist/esm/start/index.d.ts +10 -66
- package/dist/esm/start/index.js +7 -146
- package/dist/esm/start/login.d.ts +5 -0
- package/dist/esm/start/login.js +29 -0
- package/dist/esm/start/middlewareKind.d.ts +13 -0
- package/dist/esm/start/middlewareKind.js +9 -0
- package/dist/esm/start/platform/aiUsage.d.ts +29 -0
- package/dist/esm/start/platform/aiUsage.js +210 -0
- package/dist/esm/start/platform/airtable/built.d.ts +2 -0
- package/dist/esm/start/platform/airtable/built.js +3 -0
- package/dist/esm/start/platform/airtable/cache.d.ts +17 -0
- package/dist/esm/start/platform/airtable/cache.js +89 -0
- package/dist/esm/start/{airtable → platform/airtable}/dispatch.d.ts +5 -2
- package/dist/esm/start/{airtable → platform/airtable}/dispatch.js +195 -119
- package/dist/esm/start/{airtable → platform/airtable}/formulas.d.ts +2 -1
- package/dist/esm/start/{airtable → platform/airtable}/formulas.js +51 -25
- package/dist/esm/start/platform/airtable/index.d.ts +6 -0
- package/dist/esm/start/platform/airtable/index.js +51 -0
- package/dist/esm/start/platform/airtable/settings.d.ts +37 -0
- package/dist/esm/start/platform/airtable/settings.js +138 -0
- package/dist/esm/start/platform/analytics.d.ts +3 -0
- package/dist/esm/start/platform/analytics.js +59 -0
- package/dist/esm/start/platform/calls.d.ts +5 -0
- package/dist/esm/start/platform/calls.js +104 -0
- package/dist/esm/start/platform/caps.d.ts +9 -0
- package/dist/esm/start/platform/caps.js +35 -0
- package/dist/esm/start/platform/connections.d.ts +25 -0
- package/dist/esm/start/platform/connections.js +198 -0
- package/dist/esm/start/{data → platform/data}/baseRunner.d.ts +11 -6
- package/dist/esm/start/platform/data/baseRunner.js +117 -0
- package/dist/esm/start/{data → platform/data}/dispatch.d.ts +3 -2
- package/dist/esm/start/{data → platform/data}/dispatch.js +69 -51
- package/dist/esm/start/platform/data/fetch.d.ts +7 -0
- package/dist/esm/start/platform/data/fetch.js +9 -0
- package/dist/esm/start/platform/data/index.d.ts +27 -0
- package/dist/esm/start/platform/data/index.js +75 -0
- package/dist/esm/start/platform/data/names.d.ts +7 -0
- package/dist/esm/start/platform/data/names.js +18 -0
- package/dist/esm/start/{data → platform/data}/transformations.d.ts +0 -31
- package/dist/esm/start/{data → platform/data}/transformations.js +0 -56
- package/dist/esm/start/{data → platform/data}/types.d.ts +4 -1
- package/dist/esm/start/{data → platform/data}/types.js +2 -2
- package/dist/esm/start/platform/local.d.ts +6 -0
- package/dist/esm/start/platform/local.js +18 -0
- package/dist/esm/start/platform/meta.d.ts +3 -0
- package/dist/esm/start/platform/meta.js +33 -0
- package/dist/esm/start/platform/outbound.d.ts +17 -0
- package/dist/esm/start/platform/outbound.js +510 -0
- package/dist/esm/start/platform/redactSecrets.d.ts +13 -0
- package/dist/esm/start/{redactSecrets.js → platform/redactSecrets.js} +32 -7
- package/dist/esm/start/platform/redactSecrets.test.d.ts +1 -0
- package/dist/esm/start/platform/requestSecrets.d.ts +15 -0
- package/dist/esm/start/platform/requestSecrets.js +41 -0
- package/dist/esm/start/platform/runLog.d.ts +40 -0
- package/dist/esm/start/platform/runLog.js +149 -0
- package/dist/esm/start/platform/services.d.ts +7 -0
- package/dist/esm/start/platform/services.js +46 -0
- package/dist/esm/start/platform/steps.d.ts +9 -0
- package/dist/esm/start/platform/steps.js +60 -0
- package/dist/esm/start/platform/telemetry.d.ts +13 -0
- package/dist/esm/start/platform/telemetry.js +71 -0
- package/dist/esm/start/platform/transport.d.ts +28 -0
- package/dist/esm/start/platform/transport.js +59 -0
- package/dist/esm/start/platformHead.d.ts +23 -0
- package/dist/esm/start/platformHead.js +133 -0
- package/dist/esm/start/previewClaim.d.ts +3 -7
- package/dist/esm/start/previewClaim.js +9 -17
- package/dist/esm/start/protocol.d.ts +19 -0
- package/dist/esm/start/protocol.js +27 -0
- package/dist/esm/start/roles.d.ts +12 -0
- package/dist/esm/start/roles.js +27 -0
- package/dist/esm/start/router.d.ts +27 -4
- package/dist/esm/start/router.js +221 -22
- package/dist/esm/start/serve/authHooks.js +18 -0
- package/dist/esm/start/serve/demo.d.ts +9 -0
- package/dist/esm/start/serve/demo.js +24 -0
- package/dist/esm/start/serve/fetch.d.ts +1 -0
- package/dist/esm/start/serve/fetch.js +6 -0
- package/dist/esm/start/{instance.d.ts → serve/instance.d.ts} +6 -5
- package/dist/esm/start/serve/instance.js +134 -0
- package/dist/esm/start/serve/invoke.d.ts +13 -0
- package/dist/esm/start/serve/invoke.js +126 -0
- package/dist/esm/start/serve/local/load.d.ts +8 -0
- package/dist/esm/start/serve/local/load.js +44 -0
- package/dist/esm/start/serve/local/provider.d.ts +25 -0
- package/dist/esm/start/serve/local/provider.js +188 -0
- package/dist/esm/start/serve/local/signIn.d.ts +28 -0
- package/dist/esm/start/serve/local/signIn.js +123 -0
- package/dist/esm/start/serve/pageHead.d.ts +20 -0
- package/dist/esm/start/serve/pageHead.js +34 -0
- package/dist/esm/start/serve/provider.d.ts +19 -0
- package/dist/esm/start/serve/provider.js +78 -0
- package/dist/esm/start/serve/requestEnv.d.ts +2 -0
- package/dist/esm/start/serve/requestEnv.js +84 -0
- package/dist/esm/start/serve/scope.d.ts +18 -0
- package/dist/esm/start/serve/scope.js +67 -0
- package/dist/esm/start/serve/server.d.ts +56 -0
- package/dist/esm/start/serve/server.js +297 -0
- package/dist/esm/start/serve/uploads.d.ts +2 -0
- package/dist/esm/start/serve/uploads.js +49 -0
- package/dist/esm/start/serve/worker.d.ts +6 -0
- package/dist/esm/start/serve/worker.js +12 -0
- package/dist/esm/start/types.d.ts +270 -56
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/dist/esm/steps/index.d.ts +78 -0
- package/dist/esm/steps/index.js +502 -0
- package/dist/esm/steps/index.test.d.ts +1 -0
- package/dist/esm/steps/index.test.js +633 -0
- package/dist/esm/sync/index.d.ts +1 -1
- package/dist/esm/sync/index.js +32 -31
- package/dist/esm/sync/lib.d.ts +15 -8
- package/dist/esm/sync/lib.js +659 -659
- package/dist/esm/sync/lib.test.js +177 -46
- package/dist/esm/sync/sdkNames.d.ts +67 -9
- package/dist/esm/sync/sdkNames.js +94 -30
- package/dist/esm/sync/sdkNames.test.js +192 -116
- package/dist/esm/types/fields.d.ts +9 -2
- package/dist/esm/types/fields.js +110 -96
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/index.js +2 -2
- package/dist/esm/types/tables.d.ts +17 -1
- package/dist/esm/types/tables.js +2 -2
- package/dist/esm/upload/index.js +89 -24
- package/dist/esm/upload/index.test.js +104 -1
- package/dist/esm/vite/domTagNames.js +252 -252
- package/dist/esm/vite/index.d.ts +1 -1
- package/dist/esm/vite/index.js +92 -47
- package/dist/esm/vite/index.test.js +36 -0
- package/package.json +106 -38
- package/dist/cjs/auth-server/index.d.ts +0 -369
- package/dist/cjs/auth-server/index.js +0 -119
- package/dist/cjs/check/start/describeRules.d.ts +0 -35
- package/dist/cjs/check/start/describeRules.js +0 -89
- package/dist/cjs/check/start/problem.d.ts +0 -11
- package/dist/cjs/check/start/problem.js +0 -5
- package/dist/cjs/check/start/sourceRules.d.ts +0 -3
- package/dist/cjs/check/start/sourceRules.js +0 -441
- package/dist/cjs/start/problems.d.ts +0 -19
- package/dist/cjs/start/problems.js +0 -11
- package/dist/esm/auth-server/index.d.ts +0 -369
- package/dist/esm/auth-server/index.js +0 -116
- package/dist/esm/check/start/describeRules.d.ts +0 -35
- package/dist/esm/check/start/describeRules.js +0 -86
- package/dist/esm/check/start/problem.d.ts +0 -11
- package/dist/esm/check/start/problem.js +0 -1
- package/dist/esm/check/start/sourceRules.d.ts +0 -3
- package/dist/esm/check/start/sourceRules.js +0 -438
- package/dist/esm/start/airtable/index.d.ts +0 -11
- package/dist/esm/start/airtable/index.js +0 -70
- package/dist/esm/start/authHooks.js +0 -10
- package/dist/esm/start/data/baseRunner.js +0 -83
- package/dist/esm/start/data/index.d.ts +0 -18
- package/dist/esm/start/data/index.js +0 -76
- package/dist/esm/start/describe.js +0 -204
- package/dist/esm/start/describeBuilt.js +0 -66
- package/dist/esm/start/instance.js +0 -80
- package/dist/esm/start/problems.d.ts +0 -19
- package/dist/esm/start/problems.js +0 -8
- package/dist/esm/start/redactSecrets.d.ts +0 -7
- package/dist/esm/start/runLog.d.ts +0 -8
- package/dist/esm/start/runLog.js +0 -76
- package/dist/esm/start/scope.d.ts +0 -15
- package/dist/esm/start/scope.js +0 -58
- package/dist/esm/start/server.d.ts +0 -55
- package/dist/esm/start/server.js +0 -317
- package/dist/esm/start/vite.d.ts +0 -9
- package/dist/esm/start/vite.js +0 -173
- package/dist/esm/start/worker.d.ts +0 -11
- package/dist/esm/start/worker.js +0 -20
- package/dist/esm/start/workflow.d.ts +0 -53
- package/dist/esm/start/workflow.js +0 -13
- package/dist/esm/start/workflow.test-d.js +0 -44
- package/dist/esm/start/workflowRun.d.ts +0 -80
- package/dist/esm/start/workflowRun.js +0 -108
- /package/dist/{esm/start/redactSecrets.test.d.ts → cjs/runtime/sendEmailParamsTypes.test-d.d.ts} +0 -0
- /package/dist/{esm/start/workflow.test-d.d.ts → cjs/steps/index.test.d.ts} +0 -0
- /package/dist/esm/start/{authHooksModule.d.ts → build/placeholders/authHooksModule.d.ts} +0 -0
- /package/dist/esm/start/{authHooksModule.js → build/placeholders/authHooksModule.js} +0 -0
- /package/dist/esm/start/{workflowModules.d.ts → build/placeholders/workflowModules.d.ts} +0 -0
- /package/dist/esm/start/{descriptions.d.ts → describe/descriptions.d.ts} +0 -0
- /package/dist/esm/start/{airtable → platform/airtable}/arrayFields.d.ts +0 -0
- /package/dist/esm/start/{airtable → platform/airtable}/arrayFields.js +0 -0
- /package/dist/esm/start/{data → platform/data}/sqlNameMappings.d.ts +0 -0
- /package/dist/esm/start/{data → platform/data}/sqlNameMappings.js +0 -0
- /package/dist/esm/start/{redactSecrets.test.js → platform/redactSecrets.test.js} +0 -0
- /package/dist/esm/start/{authHooks.d.ts → serve/authHooks.d.ts} +0 -0
package/dist/esm/sync/lib.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { parse } from
|
|
2
|
-
import {
|
|
3
|
-
import { CREDENTIAL_FIELDS, OPTIONAL_CREDENTIAL_FIELDS, } from
|
|
4
|
-
const AUTH_USERS_TABLE_ID = "zite_user";
|
|
1
|
+
import { parse } from '@babel/parser';
|
|
2
|
+
import { allocateLiveNames, AUTH_USERS_TABLE_ID, describeRenames, normalizeSchemaNames, SdkNameAllocator, toCamelCase, toPascalCase, } from './sdkNames.js';
|
|
3
|
+
import { CREDENTIAL_FIELDS, OPTIONAL_CREDENTIAL_FIELDS, } from '../integrations/rules.js';
|
|
5
4
|
/**
|
|
6
5
|
* What a field's value looks like when a record is READ back.
|
|
7
6
|
*
|
|
@@ -32,65 +31,65 @@ const AUTH_USERS_TABLE_ID = "zite_user";
|
|
|
32
31
|
*/
|
|
33
32
|
const FIELD_TYPE_MAP = {
|
|
34
33
|
// Text: NULL is rewritten to '' on read, so these are never even absent.
|
|
35
|
-
single_line_text:
|
|
36
|
-
long_text:
|
|
37
|
-
rich_text:
|
|
38
|
-
email:
|
|
39
|
-
url:
|
|
40
|
-
phone_number:
|
|
41
|
-
number:
|
|
42
|
-
currency:
|
|
43
|
-
percent:
|
|
44
|
-
rating:
|
|
34
|
+
single_line_text: 'string',
|
|
35
|
+
long_text: 'string',
|
|
36
|
+
rich_text: 'string',
|
|
37
|
+
email: 'string',
|
|
38
|
+
url: 'string',
|
|
39
|
+
phone_number: 'string',
|
|
40
|
+
number: 'number',
|
|
41
|
+
currency: 'number',
|
|
42
|
+
percent: 'number',
|
|
43
|
+
rating: 'number',
|
|
45
44
|
// DECIMAL seconds, unlike Airtable's, which is formatted to "HH:mm:ss".
|
|
46
45
|
// 1.0 typed this `string`, which was simply wrong — base-runner groups it
|
|
47
46
|
// with the numeric types — so it stays a number rather than reverting.
|
|
48
|
-
duration:
|
|
49
|
-
checkbox:
|
|
50
|
-
single_select:
|
|
51
|
-
multiple_select:
|
|
52
|
-
date:
|
|
53
|
-
datetime:
|
|
54
|
-
attachments:
|
|
47
|
+
duration: 'number',
|
|
48
|
+
checkbox: 'boolean',
|
|
49
|
+
single_select: 'string',
|
|
50
|
+
multiple_select: 'string[]',
|
|
51
|
+
date: 'string',
|
|
52
|
+
datetime: 'string',
|
|
53
|
+
attachments: 'ZiteAttachment[]',
|
|
55
54
|
// `string | string[]`, matching the pre-monorepo type. base-runner does force
|
|
56
55
|
// an array on read today, but 1.0 code is written with `typeof x === 'string'`
|
|
57
56
|
// guards — narrowing to `string[]` turns those branches into `never` and
|
|
58
57
|
// fails the app's typecheck for no gain.
|
|
59
|
-
linked_record:
|
|
60
|
-
user:
|
|
58
|
+
linked_record: 'string | string[]',
|
|
59
|
+
user: 'string | string[]',
|
|
61
60
|
// `any`, not `unknown`, and deliberately: these are values the platform
|
|
62
61
|
// cannot type — a lookup is whatever the far side holds. 1.0 said `any`, and
|
|
63
62
|
// `unknown` buys nothing because there is no narrowing an app could have
|
|
64
63
|
// written in advance: `sum + (x || 0)` is a TS2365 on `unknown`, and the
|
|
65
64
|
// guarded spellings already narrowed fine under `any`.
|
|
66
|
-
lookup:
|
|
67
|
-
rollup:
|
|
68
|
-
autonumber:
|
|
65
|
+
lookup: 'any',
|
|
66
|
+
rollup: 'any',
|
|
67
|
+
autonumber: 'number',
|
|
69
68
|
// JSONB change metadata (`{ type: "PublicAPI", apiKeyId: 3 }`), not a string.
|
|
70
|
-
source:
|
|
71
|
-
formula:
|
|
72
|
-
created_at:
|
|
73
|
-
updated_at:
|
|
74
|
-
created_by:
|
|
75
|
-
updated_by:
|
|
69
|
+
source: 'any',
|
|
70
|
+
formula: 'any',
|
|
71
|
+
created_at: 'string',
|
|
72
|
+
updated_at: 'string',
|
|
73
|
+
created_by: 'string',
|
|
74
|
+
updated_by: 'string',
|
|
76
75
|
};
|
|
77
76
|
/**
|
|
78
77
|
* Field types whose WRITE shape differs from their read shape — the API accepts
|
|
79
78
|
* looser input than it stores.
|
|
80
79
|
*/
|
|
81
80
|
const FIELD_INPUT_TYPE_MAP = {
|
|
82
|
-
attachments:
|
|
83
|
-
linked_record:
|
|
84
|
-
user:
|
|
85
|
-
multiple_select:
|
|
86
|
-
date:
|
|
87
|
-
datetime:
|
|
88
|
-
number:
|
|
89
|
-
currency:
|
|
90
|
-
percent:
|
|
91
|
-
rating:
|
|
92
|
-
duration:
|
|
93
|
-
checkbox:
|
|
81
|
+
attachments: 'ZiteAttachmentInput[] | ZiteAttachmentInput',
|
|
82
|
+
linked_record: 'string | string[]',
|
|
83
|
+
user: 'string | string[]',
|
|
84
|
+
multiple_select: 'string | string[]',
|
|
85
|
+
date: 'string | Date',
|
|
86
|
+
datetime: 'string | Date',
|
|
87
|
+
number: 'string | number',
|
|
88
|
+
currency: 'string | number',
|
|
89
|
+
percent: 'string | number',
|
|
90
|
+
rating: 'string | number',
|
|
91
|
+
duration: 'string | number',
|
|
92
|
+
checkbox: 'string | boolean',
|
|
94
93
|
};
|
|
95
94
|
/**
|
|
96
95
|
* Computed and system-managed fields, omitted from the generated input type
|
|
@@ -104,15 +103,15 @@ const FIELD_INPUT_TYPE_MAP = {
|
|
|
104
103
|
* leave typed as writable.
|
|
105
104
|
*/
|
|
106
105
|
const READ_ONLY_FIELD_TYPES = new Set([
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
'lookup',
|
|
107
|
+
'rollup',
|
|
108
|
+
'source',
|
|
109
|
+
'formula',
|
|
110
|
+
'autonumber',
|
|
111
|
+
'created_by',
|
|
112
|
+
'updated_by',
|
|
113
|
+
'created_at',
|
|
114
|
+
'updated_at',
|
|
116
115
|
]);
|
|
117
116
|
/**
|
|
118
117
|
* Emitted once per `db.ts`. The old inline `{ url: string; name?: string }` was
|
|
@@ -120,28 +119,28 @@ const READ_ONLY_FIELD_TYPES = new Set([
|
|
|
120
119
|
* `filename` / `originalName`), and the other six read properties were missing.
|
|
121
120
|
*/
|
|
122
121
|
const ATTACHMENT_TYPES = [
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
122
|
+
'/** An attachment as returned when reading a record. */',
|
|
123
|
+
'export type ZiteAttachment = {',
|
|
124
|
+
' /** Original filename as uploaded. */',
|
|
125
|
+
' filename: string;',
|
|
126
|
+
' /** Display name — may differ from `filename`. */',
|
|
127
|
+
' originalName: string;',
|
|
128
|
+
' /** File size in bytes. */',
|
|
129
|
+
' size: number;',
|
|
130
|
+
' mimeType: string;',
|
|
131
|
+
' /** Publicly accessible URL. */',
|
|
132
|
+
' url: string;',
|
|
133
|
+
' /** ISO timestamp of the upload. */',
|
|
134
|
+
' uploadedAt: string;',
|
|
135
|
+
' metadata?: Record<string, unknown>;',
|
|
136
|
+
'};',
|
|
137
|
+
'',
|
|
138
|
+
'/** What you may write to an attachments field: a URL, a URL with a name, or an attachment you read earlier. */',
|
|
139
|
+
'export type ZiteAttachmentInput =',
|
|
140
|
+
' | string',
|
|
141
|
+
' | { url: string; filename?: string }',
|
|
142
|
+
' | ZiteAttachment;',
|
|
143
|
+
'',
|
|
145
144
|
];
|
|
146
145
|
const MAX_SELECT_OPTIONS = 100;
|
|
147
146
|
/**
|
|
@@ -168,30 +167,30 @@ const tsSingleQuoted = (value) => `'${JSON.stringify(value).slice(1, -1).replace
|
|
|
168
167
|
* Applied where the comment is written rather than at each contributor, so
|
|
169
168
|
* anything added to one later is covered by default.
|
|
170
169
|
*/
|
|
171
|
-
const commentSafe = (value) => value.replace(/\*\//g,
|
|
170
|
+
const commentSafe = (value) => value.replace(/\*\//g, '* /').replace(/\s+/g, ' ').trim();
|
|
172
171
|
const NUMBER_FORMAT_EXAMPLES = {
|
|
173
|
-
local:
|
|
174
|
-
comma_period:
|
|
175
|
-
period_comma:
|
|
176
|
-
space_comma:
|
|
177
|
-
space_period:
|
|
178
|
-
no_separator:
|
|
172
|
+
local: '1,000,000.50',
|
|
173
|
+
comma_period: '1,000,000.50',
|
|
174
|
+
period_comma: '1.000.000,50',
|
|
175
|
+
space_comma: '1 000 000,50',
|
|
176
|
+
space_period: '1 000 000.50',
|
|
177
|
+
no_separator: '1000000.50',
|
|
179
178
|
};
|
|
180
179
|
const DURATION_FORMAT_EXAMPLES = {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
180
|
+
'h:mm': '1:23',
|
|
181
|
+
'h:mm:ss': '1:23:03',
|
|
182
|
+
'h:mm:ss.s': '1:23:03.0',
|
|
183
|
+
'h:mm:ss.ss': '1:23:03.00',
|
|
184
|
+
'h:mm:ss.sss': '1:23:03.000',
|
|
186
185
|
};
|
|
187
186
|
// Naming the format alone ("display as `european` format") doesn't say what to
|
|
188
187
|
// render — these mirror the pickers in the database UI, which is what the user
|
|
189
188
|
// chose from. `local` is the viewer's system locale, so it has no fixed example.
|
|
190
189
|
const DATE_FORMAT_EXAMPLES = {
|
|
191
|
-
long:
|
|
192
|
-
us:
|
|
193
|
-
european:
|
|
194
|
-
iso:
|
|
190
|
+
long: 'January 15, 2024',
|
|
191
|
+
us: '1/15/2024',
|
|
192
|
+
european: '15/01/2024',
|
|
193
|
+
iso: '2024-01-15',
|
|
195
194
|
};
|
|
196
195
|
const withDateFormatExample = (format) => {
|
|
197
196
|
const example = DATE_FORMAT_EXAMPLES[format];
|
|
@@ -201,36 +200,36 @@ const withDateFormatExample = (format) => {
|
|
|
201
200
|
};
|
|
202
201
|
// Owned by ./sdkNames.ts (which must not import back into this module);
|
|
203
202
|
// re-exported so the published surface is unchanged.
|
|
204
|
-
export { toPascalCase, toCamelCase, toSdkName } from
|
|
203
|
+
export { toPascalCase, toCamelCase, toSdkName } from './sdkNames.js';
|
|
205
204
|
/**
|
|
206
205
|
* `null` is how you CLEAR a cell — every scalar write schema in
|
|
207
206
|
* `flexible-inputs.ts` ends in `.nullable()` and update runs with
|
|
208
207
|
* `allowExplicitNull`. A write type without it makes the documented way to
|
|
209
208
|
* empty a field a compile error.
|
|
210
209
|
*/
|
|
211
|
-
const withNull = (type) => type.includes(
|
|
212
|
-
function tsTypeForSchemaField(def, variant =
|
|
213
|
-
if (def.type ===
|
|
210
|
+
const withNull = (type) => type.includes('null') ? type : `${type} | null`;
|
|
211
|
+
function tsTypeForSchemaField(def, variant = 'read') {
|
|
212
|
+
if (def.type === 'single_select' || def.type === 'multiple_select') {
|
|
214
213
|
const options = def.template
|
|
215
214
|
?.options;
|
|
216
215
|
if (options && options.length > 0) {
|
|
217
216
|
const literals = options
|
|
218
217
|
.slice(0, MAX_SELECT_OPTIONS)
|
|
219
|
-
.map(
|
|
220
|
-
.join(
|
|
218
|
+
.map(o => tsStringLiteral(o.label))
|
|
219
|
+
.join(' | ');
|
|
221
220
|
const union = `${literals} | string`;
|
|
222
221
|
// No `| null` on the read side — see FIELD_TYPE_MAP. The write side keeps
|
|
223
222
|
// it below, since null is how a select cell is cleared.
|
|
224
|
-
const read = def.type ===
|
|
225
|
-
if (variant ===
|
|
226
|
-
return def.type ===
|
|
223
|
+
const read = def.type === 'multiple_select' ? `(${union})[]` : union;
|
|
224
|
+
if (variant === 'write') {
|
|
225
|
+
return def.type === 'multiple_select'
|
|
227
226
|
? `${union} | (${union})[] | null`
|
|
228
227
|
: `${union} | null`;
|
|
229
228
|
}
|
|
230
229
|
return read;
|
|
231
230
|
}
|
|
232
231
|
}
|
|
233
|
-
if (variant ===
|
|
232
|
+
if (variant === 'write') {
|
|
234
233
|
const write = FIELD_INPUT_TYPE_MAP[def.type] ?? FIELD_TYPE_MAP[def.type];
|
|
235
234
|
if (write)
|
|
236
235
|
return withNull(write);
|
|
@@ -240,38 +239,38 @@ function tsTypeForSchemaField(def, variant = "read") {
|
|
|
240
239
|
// Not `string`. A field type this generator doesn't know about is not a
|
|
241
240
|
// string just because most of them are — asserting one lets `record.value`
|
|
242
241
|
// silently pass as `string` everywhere it flows.
|
|
243
|
-
return
|
|
242
|
+
return 'unknown';
|
|
244
243
|
}
|
|
245
244
|
function fieldJsdoc(schemaField, table, schema) {
|
|
246
245
|
const def = schemaField.definition;
|
|
247
246
|
const parts = [];
|
|
248
247
|
if (table.primaryFieldId === schemaField.id)
|
|
249
|
-
parts.push(
|
|
248
|
+
parts.push('Primary field');
|
|
250
249
|
if (READ_ONLY_FIELD_TYPES.has(def.type))
|
|
251
|
-
parts.push(
|
|
252
|
-
if (def.type ===
|
|
250
|
+
parts.push('Read-only');
|
|
251
|
+
if (def.type === 'linked_record') {
|
|
253
252
|
const tpl = def.template;
|
|
254
253
|
if (tpl.tableId) {
|
|
255
254
|
// The SDK name, not the raw `tbl...` id — the id appears nowhere the
|
|
256
255
|
// reader can act on, while the SDK name is the property on `zite`. Its
|
|
257
256
|
// display name rides along, since after a rename the two differ.
|
|
258
|
-
const linked = schema?.tables.find(
|
|
257
|
+
const linked = schema?.tables.find(t => t.id === tpl.tableId);
|
|
259
258
|
parts.push(linked
|
|
260
|
-
? `Links to ${linked.sdkName}${linked.name ? ` ("${linked.name}")` :
|
|
259
|
+
? `Links to ${linked.sdkName}${linked.name ? ` ("${linked.name}")` : ''}`
|
|
261
260
|
: `Links to ${tpl.tableId}`);
|
|
262
261
|
}
|
|
263
262
|
if (tpl.allowMultiple === false)
|
|
264
|
-
parts.push(
|
|
263
|
+
parts.push('Single record only');
|
|
265
264
|
}
|
|
266
265
|
parts.push(`"${def.name}"`);
|
|
267
|
-
if (def.type ===
|
|
266
|
+
if (def.type === 'date') {
|
|
268
267
|
const tpl = def.template;
|
|
269
268
|
if (tpl.dateFormat)
|
|
270
269
|
parts.push(`Date-only field (YYYY-MM-DD string), null when unset, display as ${withDateFormatExample(tpl.dateFormat)}`);
|
|
271
270
|
}
|
|
272
|
-
if (def.type ===
|
|
271
|
+
if (def.type === 'datetime') {
|
|
273
272
|
const tpl = def.template;
|
|
274
|
-
const timeParts = [
|
|
273
|
+
const timeParts = ['Date+time field (ISO 8601 timestamp), null when unset'];
|
|
275
274
|
if (tpl.dateFormat)
|
|
276
275
|
timeParts.push(`date: ${withDateFormatExample(tpl.dateFormat)}`);
|
|
277
276
|
if (tpl.timeFormat)
|
|
@@ -279,45 +278,45 @@ function fieldJsdoc(schemaField, table, schema) {
|
|
|
279
278
|
if (tpl.timezone)
|
|
280
279
|
timeParts.push(`tz: ${tpl.timezone}`);
|
|
281
280
|
if (tpl.displayTimeZone)
|
|
282
|
-
timeParts.push(
|
|
283
|
-
parts.push(timeParts.join(
|
|
281
|
+
timeParts.push('timezone displayed to user');
|
|
282
|
+
parts.push(timeParts.join(', '));
|
|
284
283
|
}
|
|
285
|
-
if (def.type ===
|
|
284
|
+
if (def.type === 'currency') {
|
|
286
285
|
const tpl = def.template;
|
|
287
286
|
if (tpl.currencySymbol) {
|
|
288
|
-
const formatHint = NUMBER_FORMAT_EXAMPLES[tpl.numberFormat ??
|
|
289
|
-
parts.push(`Value is a raw number; display as currency with symbol "${tpl.currencySymbol}", ${tpl.decimalPlaces ?? 2} decimal places, format: ${tpl.numberFormat ??
|
|
287
|
+
const formatHint = NUMBER_FORMAT_EXAMPLES[tpl.numberFormat ?? 'local'] ?? '';
|
|
288
|
+
parts.push(`Value is a raw number; display as currency with symbol "${tpl.currencySymbol}", ${tpl.decimalPlaces ?? 2} decimal places, format: ${tpl.numberFormat ?? 'local'} (e.g. ${formatHint})`);
|
|
290
289
|
}
|
|
291
290
|
}
|
|
292
|
-
if (def.type ===
|
|
291
|
+
if (def.type === 'number') {
|
|
293
292
|
const tpl = def.template;
|
|
294
|
-
const formatHint = NUMBER_FORMAT_EXAMPLES[tpl.numberFormat ??
|
|
295
|
-
parts.push(`${tpl.decimalPlaces ?? 0} decimal places, format: ${tpl.numberFormat ??
|
|
293
|
+
const formatHint = NUMBER_FORMAT_EXAMPLES[tpl.numberFormat ?? 'local'] ?? '';
|
|
294
|
+
parts.push(`${tpl.decimalPlaces ?? 0} decimal places, format: ${tpl.numberFormat ?? 'local'} (e.g. ${formatHint})`);
|
|
296
295
|
}
|
|
297
|
-
if (def.type ===
|
|
296
|
+
if (def.type === 'percent') {
|
|
298
297
|
const tpl = def.template;
|
|
299
298
|
if (tpl.decimalPlaces !== undefined)
|
|
300
299
|
parts.push(`${tpl.decimalPlaces} decimal places`);
|
|
301
300
|
}
|
|
302
|
-
if (def.type ===
|
|
301
|
+
if (def.type === 'duration') {
|
|
303
302
|
const tpl = def.template;
|
|
304
303
|
if (tpl.format) {
|
|
305
|
-
const example = DURATION_FORMAT_EXAMPLES[tpl.format] ??
|
|
304
|
+
const example = DURATION_FORMAT_EXAMPLES[tpl.format] ?? '';
|
|
306
305
|
parts.push(`Value is in seconds; display in "${tpl.format}" format (${example})`);
|
|
307
306
|
}
|
|
308
307
|
}
|
|
309
|
-
if (def.type ===
|
|
308
|
+
if (def.type === 'rating') {
|
|
310
309
|
const tpl = def.template;
|
|
311
310
|
if (tpl.maxRating)
|
|
312
311
|
parts.push(`Max rating: ${tpl.maxRating}`);
|
|
313
312
|
}
|
|
314
|
-
if (def.type ===
|
|
315
|
-
parts.push(
|
|
313
|
+
if (def.type === 'created_at') {
|
|
314
|
+
parts.push('Auto-set when record was created (ISO 8601)');
|
|
316
315
|
}
|
|
317
|
-
if (def.type ===
|
|
318
|
-
parts.push(
|
|
316
|
+
if (def.type === 'updated_at') {
|
|
317
|
+
parts.push('Auto-set when record was last modified (ISO 8601)');
|
|
319
318
|
}
|
|
320
|
-
if ((def.type ===
|
|
319
|
+
if ((def.type === 'single_select' || def.type === 'multiple_select') &&
|
|
321
320
|
def.template?.options) {
|
|
322
321
|
const count = (def.template.options ?? [])
|
|
323
322
|
.length;
|
|
@@ -327,7 +326,7 @@ function fieldJsdoc(schemaField, table, schema) {
|
|
|
327
326
|
}
|
|
328
327
|
if (parts.length <= 1)
|
|
329
328
|
return undefined;
|
|
330
|
-
return parts.join(
|
|
329
|
+
return parts.join('. ');
|
|
331
330
|
}
|
|
332
331
|
/**
|
|
333
332
|
* Build a ZiteSchema from a Database API response.
|
|
@@ -338,75 +337,49 @@ function fieldJsdoc(schemaField, table, schema) {
|
|
|
338
337
|
* name stability across schema changes.
|
|
339
338
|
*/
|
|
340
339
|
export function generateSchema(database, existingSchema) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const existingTable = existingTableById.get(table.id);
|
|
350
|
-
const existingFieldById = new Map();
|
|
351
|
-
for (const f of existingTable?.fields ?? []) {
|
|
352
|
-
existingFieldById.set(f.id, f);
|
|
340
|
+
// A name from the existing schema is locked: it is what the app is compiling
|
|
341
|
+
// against, and only moves if it is reserved or collides.
|
|
342
|
+
const { names, renames } = allocateLiveNames(database.tables, existingSchema);
|
|
343
|
+
if (renames.length > 0) {
|
|
344
|
+
// Never silent: a rename means the accessor a developer would reach for is
|
|
345
|
+
// not the one that got emitted.
|
|
346
|
+
for (const line of describeRenames(renames)) {
|
|
347
|
+
console.warn(`[zitejs] SDK name collision resolved: ${line}`);
|
|
353
348
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const
|
|
360
|
-
const { id: _id, order: _order, ...definition } = field;
|
|
349
|
+
}
|
|
350
|
+
const liveTables = new Map(database.tables.map(table => [table.id, table]));
|
|
351
|
+
return {
|
|
352
|
+
tables: names.tables.map(named => {
|
|
353
|
+
const table = liveTables.get(named.id);
|
|
354
|
+
const liveFields = new Map(table.fields.map(field => [field.id, field]));
|
|
361
355
|
return {
|
|
362
|
-
field: { id: field.id, sdkName: "", definition },
|
|
363
|
-
draft: {
|
|
364
|
-
preferred: existing ?? toSdkName(field.name),
|
|
365
|
-
locked: existing !== undefined,
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
});
|
|
369
|
-
const existingName = keepValidSdkName(existingTable?.sdkName);
|
|
370
|
-
drafts.push({
|
|
371
|
-
table: {
|
|
372
356
|
id: table.id,
|
|
373
|
-
sdkName:
|
|
357
|
+
sdkName: named.sdkName,
|
|
374
358
|
// Always the live name — never `existingTable?.name`. Locking it the way
|
|
375
359
|
// `sdkName` is locked would freeze it at the first name the table ever
|
|
376
360
|
// had, which is the one thing this is here to avoid.
|
|
377
361
|
name: table.name,
|
|
378
362
|
primaryFieldId: table.primaryFieldId,
|
|
379
|
-
fields:
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
const { tables, renames } = allocateSchemaNames(drafts);
|
|
389
|
-
if (renames.length > 0) {
|
|
390
|
-
// Never silent: a rename means the accessor a developer would reach for is
|
|
391
|
-
// not the one that got emitted.
|
|
392
|
-
for (const line of describeRenames(renames)) {
|
|
393
|
-
console.warn(`[zitejs] SDK name collision resolved: ${line}`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return { tables };
|
|
363
|
+
fields: named.fields.map(namedField => {
|
|
364
|
+
const { id, order: _order, ...definition } = liveFields.get(namedField.id);
|
|
365
|
+
return { id, sdkName: namedField.sdkName, definition };
|
|
366
|
+
}),
|
|
367
|
+
};
|
|
368
|
+
}),
|
|
369
|
+
};
|
|
397
370
|
}
|
|
398
371
|
function generateSentinelSdkTypes() {
|
|
399
372
|
return [
|
|
400
373
|
// Must match `AuthUser` in zitejs/runtime and `User` in zitejs/auth.
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
374
|
+
'export interface ZiteAuthUser {',
|
|
375
|
+
' id: string;',
|
|
376
|
+
' name: string;',
|
|
377
|
+
' email: string;',
|
|
378
|
+
' firstName?: string;',
|
|
379
|
+
' lastName?: string;',
|
|
380
|
+
' image: string | null;',
|
|
381
|
+
'}',
|
|
382
|
+
'',
|
|
410
383
|
];
|
|
411
384
|
}
|
|
412
385
|
function buildLinkTableComments(schema) {
|
|
@@ -424,7 +397,7 @@ function buildLinkTableComments(schema) {
|
|
|
424
397
|
const entries = [];
|
|
425
398
|
for (const table of schema.tables) {
|
|
426
399
|
for (const field of table.fields) {
|
|
427
|
-
if (field.definition.type !==
|
|
400
|
+
if (field.definition.type !== 'linked_record')
|
|
428
401
|
continue;
|
|
429
402
|
const tpl = field.definition.template;
|
|
430
403
|
if (tpl.isInverse)
|
|
@@ -463,12 +436,12 @@ function buildLinkTableComments(schema) {
|
|
|
463
436
|
if (entries.length === 0)
|
|
464
437
|
return [];
|
|
465
438
|
const lines = [
|
|
466
|
-
|
|
467
|
-
|
|
439
|
+
'//',
|
|
440
|
+
'// Link tables for zite.sql() JOINs (use these exact names):',
|
|
468
441
|
];
|
|
469
442
|
for (const e of entries) {
|
|
470
443
|
lines.push(`// "${commentSafe(e.name)}" — columns: "${commentSafe(e.cols[0])}", "${commentSafe(e.cols[1])}"` +
|
|
471
|
-
(e.gloss ? ` (${commentSafe(e.gloss)})` :
|
|
444
|
+
(e.gloss ? ` (${commentSafe(e.gloss)})` : ''));
|
|
472
445
|
}
|
|
473
446
|
return lines;
|
|
474
447
|
}
|
|
@@ -476,7 +449,12 @@ function buildLinkTableComments(schema) {
|
|
|
476
449
|
* Generate .zite/db.ts purely from ZiteSchema.
|
|
477
450
|
* Pure function — no external data needed beyond what's in the schema file.
|
|
478
451
|
*/
|
|
479
|
-
|
|
452
|
+
/**
|
|
453
|
+
* `hasStartApps` rewords the usage notes for a workspace where the code using
|
|
454
|
+
* the client isn't only classic endpoints. A classic-only workspace keeps the
|
|
455
|
+
* old wording, so its committed db.ts doesn't change.
|
|
456
|
+
*/
|
|
457
|
+
export function generateDbTs(inputSchema, { hasStartApps = false } = {}) {
|
|
480
458
|
const lines = [];
|
|
481
459
|
// Defensive, and idempotent: a schema whose names are already unique and
|
|
482
460
|
// unreserved normalizes to itself. It matters for a `zite.schema.json`
|
|
@@ -490,68 +468,77 @@ export function generateDbTs(inputSchema) {
|
|
|
490
468
|
console.warn(`[zitejs] Repaired SDK name in zite.schema.json: ${line}`);
|
|
491
469
|
}
|
|
492
470
|
}
|
|
493
|
-
const tables = schema.tables.filter(
|
|
494
|
-
lines.push(
|
|
495
|
-
lines.push(
|
|
496
|
-
|
|
471
|
+
const tables = schema.tables.filter(table => table.id !== AUTH_USERS_TABLE_ID);
|
|
472
|
+
lines.push('// Auto-generated by zitejs generate. Do not edit manually.');
|
|
473
|
+
lines.push('//');
|
|
474
|
+
if (hasStartApps) {
|
|
475
|
+
lines.push("// Usage in server code: a classic app's endpoints (src/api/*.ts), or a Start");
|
|
476
|
+
lines.push("// app's server functions and *.server.ts files:");
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
lines.push('// Usage in endpoint files (src/api/*.ts):');
|
|
480
|
+
}
|
|
497
481
|
lines.push('// import { zite } from "zitejs/db";');
|
|
498
|
-
lines.push(
|
|
482
|
+
lines.push('//');
|
|
499
483
|
lines.push('// Always use "zitejs/db" — never use relative paths like "../../.zite/db".');
|
|
500
|
-
lines.push(
|
|
501
|
-
lines.push(
|
|
502
|
-
lines.push(
|
|
503
|
-
lines.push(
|
|
504
|
-
lines.push(
|
|
505
|
-
lines.push(
|
|
506
|
-
lines.push('// `not: null` means "is set". An empty `in: []` matches nothing; an',
|
|
507
|
-
lines.push(
|
|
508
|
-
lines.push(
|
|
509
|
-
lines.push("// a filter value of `undefined`
|
|
510
|
-
lines.push(
|
|
511
|
-
lines.push(
|
|
512
|
-
lines.push(
|
|
513
|
-
lines.push(
|
|
514
|
-
lines.push(
|
|
515
|
-
lines.push(
|
|
516
|
-
lines.push(
|
|
517
|
-
lines.push(
|
|
518
|
-
lines.push(
|
|
484
|
+
lines.push('// The tsconfig aliases resolve zitejs/* imports to the correct .zite/ files.');
|
|
485
|
+
lines.push('//');
|
|
486
|
+
lines.push('// Table client methods (all take a single params object):');
|
|
487
|
+
lines.push('// .findAll({ filters?, sort?, offset?, limit?, fields? }) → { records: T[], hasMore: boolean }');
|
|
488
|
+
lines.push('// filters: { fieldName: value } for equality, or { fieldName: { <op>: value } }');
|
|
489
|
+
lines.push('// operators: contains, not, in, notIn, lt, lte, gt, gte');
|
|
490
|
+
lines.push('// `not: null` means "is set". An empty `in: []` matches nothing; an', '// empty `notIn: []` applies no filter.');
|
|
491
|
+
lines.push('// sort: [{ field: "fieldName", direction: "asc" | "desc" }]');
|
|
492
|
+
lines.push('// limit defaults to 500, max 2000; offset is a row count (a number)');
|
|
493
|
+
lines.push("// a filter value of `undefined` drops that filter and reads as if it weren't", '// there. Check the value first: `{ owner: user?.id }` signed out reads every row.');
|
|
494
|
+
lines.push('// .findOne({ id?, filters?, fields? }) → T | undefined');
|
|
495
|
+
lines.push('// a filter value of `undefined`, or an `undefined` id with no filters, matches', '// no record and returns undefined');
|
|
496
|
+
lines.push('// .create({ record }) → T');
|
|
497
|
+
lines.push('// .update({ id, record }) → { id: string, fields: Partial<T> }');
|
|
498
|
+
lines.push('// .delete({ id }) → { success: true, id: string }');
|
|
499
|
+
lines.push('// .bulkCreate({ records, matchOn? }) → { success: boolean, records: T[] }');
|
|
500
|
+
lines.push('// up to 100 records per call; matchOn upserts on those fields');
|
|
501
|
+
lines.push('//');
|
|
502
|
+
lines.push('// Reading these types:');
|
|
503
|
+
lines.push('// SDK names are stable identifiers — they do NOT change when a table or field is');
|
|
519
504
|
lines.push('// renamed. Each carries its current user-facing name in quotes (// "Task Name").');
|
|
520
|
-
lines.push(
|
|
521
|
-
lines.push(
|
|
522
|
-
lines.push(
|
|
505
|
+
lines.push('// Where the two differ the field was renamed, and the quoted name is what it means');
|
|
506
|
+
lines.push('// now — treat it as the source of truth.');
|
|
507
|
+
lines.push('// Values are RAW: dates are ISO strings, durations are seconds. Format them for');
|
|
523
508
|
lines.push("// display yourself, following the display config in each field's comment.");
|
|
524
|
-
lines.push(
|
|
525
|
-
lines.push(
|
|
526
|
-
lines.push(
|
|
527
|
-
lines.push(
|
|
528
|
-
lines.push(
|
|
529
|
-
lines.push(
|
|
530
|
-
lines.push(
|
|
531
|
-
lines.push(
|
|
532
|
-
lines.push(
|
|
533
|
-
lines.push(
|
|
534
|
-
lines.push(
|
|
535
|
-
lines.push(
|
|
536
|
-
lines.push(
|
|
537
|
-
lines.push(
|
|
509
|
+
lines.push('// PERCENT fields are stored as decimals — 0.5 is 50%, 1.0 is 100%.');
|
|
510
|
+
lines.push('// LINKED RECORD fields hold UUID record ids from findOne/findAll — never invent one.');
|
|
511
|
+
lines.push('// Computed and system-managed fields (formula, rollup, lookup, autonumber,');
|
|
512
|
+
lines.push('// created/updated timestamps and more) are absent from the *Input types —');
|
|
513
|
+
lines.push('// a write to one is rejected or silently dropped.');
|
|
514
|
+
lines.push('//');
|
|
515
|
+
lines.push('// Zite auth users:');
|
|
516
|
+
lines.push('// zite.auth.findAllUsers({ appIds?, filter?, filters?, sort?, limit?, offset? })');
|
|
517
|
+
lines.push('// Supports the same filter, sort, and pagination options as table .findAll()');
|
|
518
|
+
lines.push('// appIds restricts results to users belonging to any listed app');
|
|
519
|
+
lines.push('// zite.auth.updateUserProfile(userId, { firstName?, lastName?, image? })');
|
|
520
|
+
lines.push('// User email addresses cannot be updated through this API');
|
|
521
|
+
lines.push('//');
|
|
522
|
+
lines.push('// Raw SQL (read-only SELECTs for aggregates, joins, multi-table queries):');
|
|
538
523
|
lines.push('// zite.sql({ query: "SELECT ...", params?: [...] })');
|
|
539
|
-
lines.push(
|
|
540
|
-
lines.push(
|
|
541
|
-
lines.push(
|
|
542
|
-
lines.push(
|
|
543
|
-
lines.push(
|
|
544
|
-
lines.push(
|
|
545
|
-
lines.push(
|
|
524
|
+
lines.push('// → { rows: Record<string, unknown>[], columns, rowCount, truncated }');
|
|
525
|
+
lines.push('// Capped at 2000 rows — `truncated: true` means there were more, so paginate in');
|
|
526
|
+
lines.push('// SQL rather than assuming you got everything. Queries time out after 10s.');
|
|
527
|
+
lines.push('// columns[].name is the SDK name; columns[].originalName is the underlying', '// database column (or your own SQL alias).');
|
|
528
|
+
lines.push('//');
|
|
529
|
+
lines.push('// SQL guidelines:');
|
|
530
|
+
lines.push('// - Use SDK names for tables (PascalCase) and fields (camelCase)');
|
|
546
531
|
lines.push('// - ALWAYS double-quote every identifier: FROM "Orders", WHERE "status" = $1');
|
|
547
|
-
lines.push(
|
|
532
|
+
lines.push('// - Use params array for user input ($1, $2, ...): never interpolate into SQL');
|
|
548
533
|
lines.push('// - Auth users are available as "ziteUsers" with id, name, email, firstName, lastName, and image');
|
|
549
|
-
lines.push(
|
|
550
|
-
lines.push(
|
|
551
|
-
lines.push(
|
|
534
|
+
lines.push('// - Soft-deleted rows are excluded automatically — no WHERE deleted_at IS NULL');
|
|
535
|
+
lines.push('// - SELECT only — use .create/.update/.delete for writes');
|
|
536
|
+
lines.push(hasStartApps
|
|
537
|
+
? '// - In the Zite editor, the "zite:sql" skill is the full SQL reference (formulas, lookups, etc.)'
|
|
538
|
+
: '// - Load the "zite:sql" skill for full SQL reference (formulas, lookups, etc.)');
|
|
552
539
|
lines.push(...buildLinkTableComments(schema));
|
|
553
540
|
lines.push("import { createTableClient, createSqlClient, createAuthClient } from 'zitejs/runtime';");
|
|
554
|
-
lines.push(
|
|
541
|
+
lines.push('');
|
|
555
542
|
lines.push(...ATTACHMENT_TYPES);
|
|
556
543
|
for (const table of tables) {
|
|
557
544
|
const className = toPascalCase(table.sdkName);
|
|
@@ -563,9 +550,9 @@ export function generateDbTs(inputSchema) {
|
|
|
563
550
|
? `/** A record in the "${commentSafe(table.name)}" table, as it is read back. */`
|
|
564
551
|
: `/** A ${table.sdkName} record as it is read back. */`);
|
|
565
552
|
lines.push(`export type ${recordType} = {`);
|
|
566
|
-
lines.push(
|
|
553
|
+
lines.push(' id: string;');
|
|
567
554
|
for (const field of table.fields) {
|
|
568
|
-
if (field.sdkName ===
|
|
555
|
+
if (field.sdkName === 'id')
|
|
569
556
|
continue;
|
|
570
557
|
const tsType = tsTypeForSchemaField(field.definition);
|
|
571
558
|
const jsdoc = fieldJsdoc(field, table, schema);
|
|
@@ -578,35 +565,35 @@ export function generateDbTs(inputSchema) {
|
|
|
578
565
|
// be absent on a read.
|
|
579
566
|
lines.push(` ${field.sdkName}?: ${tsType};`);
|
|
580
567
|
}
|
|
581
|
-
lines.push(
|
|
582
|
-
lines.push(
|
|
568
|
+
lines.push('};');
|
|
569
|
+
lines.push('');
|
|
583
570
|
// The write shape is a separate type, not `Partial<RecordType>`: computed
|
|
584
571
|
// fields can't be written at all, and several field types accept looser
|
|
585
572
|
// input than they store (an attachments field takes a URL string; a linked
|
|
586
573
|
// record takes one id or many).
|
|
587
|
-
const writableFields = table.fields.filter(
|
|
574
|
+
const writableFields = table.fields.filter(f => f.sdkName !== 'id' && !READ_ONLY_FIELD_TYPES.has(f.definition.type));
|
|
588
575
|
lines.push(table.name
|
|
589
576
|
? `/** What you may write when creating or updating a record in the "${commentSafe(table.name)}" table. */`
|
|
590
577
|
: `/** What you may write when creating or updating a ${table.sdkName}. */`);
|
|
591
578
|
lines.push(`export type ${className}RecordInput = {`);
|
|
592
579
|
for (const field of writableFields) {
|
|
593
|
-
lines.push(` ${field.sdkName}: ${tsTypeForSchemaField(field.definition,
|
|
580
|
+
lines.push(` ${field.sdkName}: ${tsTypeForSchemaField(field.definition, 'write')};`);
|
|
594
581
|
}
|
|
595
|
-
lines.push(
|
|
596
|
-
lines.push(
|
|
582
|
+
lines.push('};');
|
|
583
|
+
lines.push('');
|
|
597
584
|
}
|
|
598
585
|
lines.push(...generateSentinelSdkTypes());
|
|
599
|
-
lines.push(
|
|
586
|
+
lines.push('export const zite = {');
|
|
600
587
|
for (const table of tables) {
|
|
601
588
|
const className = toPascalCase(table.sdkName);
|
|
602
589
|
lines.push(` ${table.sdkName}: createTableClient<${className}RecordType, ${className}RecordInput>('${className}'),` +
|
|
603
|
-
(table.name ? ` // "${commentSafe(table.name)}"` :
|
|
590
|
+
(table.name ? ` // "${commentSafe(table.name)}"` : ''));
|
|
604
591
|
}
|
|
605
592
|
lines.push(` sql: createSqlClient(),`);
|
|
606
593
|
lines.push(` auth: createAuthClient<ZiteAuthUser>(),`);
|
|
607
|
-
lines.push(
|
|
608
|
-
lines.push(
|
|
609
|
-
return lines.join(
|
|
594
|
+
lines.push('};');
|
|
595
|
+
lines.push('');
|
|
596
|
+
return lines.join('\n');
|
|
610
597
|
}
|
|
611
598
|
const NOT_AN_ENDPOINT = {
|
|
612
599
|
isEndpoint: false,
|
|
@@ -615,23 +602,23 @@ const NOT_AN_ENDPOINT = {
|
|
|
615
602
|
};
|
|
616
603
|
/** `createEndpoint(...)` anywhere in the expression, through wrappers. */
|
|
617
604
|
function callsCreateEndpoint(node) {
|
|
618
|
-
if (!node || typeof node !==
|
|
605
|
+
if (!node || typeof node !== 'object')
|
|
619
606
|
return false;
|
|
620
607
|
const n = node;
|
|
621
|
-
if (n.type ===
|
|
608
|
+
if (n.type === 'CallExpression' &&
|
|
622
609
|
n.callee?.name ===
|
|
623
|
-
|
|
610
|
+
'createEndpoint') {
|
|
624
611
|
return true;
|
|
625
612
|
}
|
|
626
|
-
return Object.values(n).some(
|
|
613
|
+
return Object.values(n).some(v => Array.isArray(v) ? v.some(callsCreateEndpoint) : callsCreateEndpoint(v));
|
|
627
614
|
}
|
|
628
615
|
/** Unwrap `x satisfies T` / `x as const` to the expression underneath. */
|
|
629
616
|
function unwrapExpression(node) {
|
|
630
617
|
let current = node;
|
|
631
|
-
while ((current?.type ===
|
|
632
|
-
current?.type ===
|
|
633
|
-
current?.type ===
|
|
634
|
-
current?.type ===
|
|
618
|
+
while ((current?.type === 'TSAsExpression' ||
|
|
619
|
+
current?.type === 'TSSatisfiesExpression' ||
|
|
620
|
+
current?.type === 'TSNonNullExpression' ||
|
|
621
|
+
current?.type === 'ParenthesizedExpression') &&
|
|
635
622
|
current.expression) {
|
|
636
623
|
current = current.expression;
|
|
637
624
|
}
|
|
@@ -640,7 +627,7 @@ function unwrapExpression(node) {
|
|
|
640
627
|
function inspectEndpointFile(source) {
|
|
641
628
|
let ast;
|
|
642
629
|
try {
|
|
643
|
-
ast = parse(source, { sourceType:
|
|
630
|
+
ast = parse(source, { sourceType: 'module', plugins: ['typescript'] });
|
|
644
631
|
}
|
|
645
632
|
catch {
|
|
646
633
|
// Unparseable with a TS-only plugin set — most likely TSX, which is still
|
|
@@ -649,31 +636,31 @@ function inspectEndpointFile(source) {
|
|
|
649
636
|
return { isEndpoint: true, hasDefaultExport: true, stream: false };
|
|
650
637
|
}
|
|
651
638
|
const body = ast.program.body;
|
|
652
|
-
const hasDefaultExport = body.some(
|
|
653
|
-
(n.type ===
|
|
654
|
-
n.specifiers?.some(
|
|
655
|
-
(spec.exported.type ===
|
|
639
|
+
const hasDefaultExport = body.some(n => n.type === 'ExportDefaultDeclaration' ||
|
|
640
|
+
(n.type === 'ExportNamedDeclaration' &&
|
|
641
|
+
n.specifiers?.some(spec => spec.type === 'ExportSpecifier' &&
|
|
642
|
+
(spec.exported.type === 'Identifier'
|
|
656
643
|
? spec.exported.name
|
|
657
|
-
: spec.exported.value) ===
|
|
644
|
+
: spec.exported.value) === 'default')));
|
|
658
645
|
const isEndpoint = hasDefaultExport || body.some(callsCreateEndpoint);
|
|
659
646
|
if (!isEndpoint)
|
|
660
647
|
return NOT_AN_ENDPOINT;
|
|
661
648
|
// Stream detection is best-effort on the literal config: it is the only
|
|
662
649
|
// shape we can read `stream: true` out of statically.
|
|
663
|
-
const defaultExport = body.find(
|
|
650
|
+
const defaultExport = body.find(n => n.type === 'ExportDefaultDeclaration');
|
|
664
651
|
const call = defaultExport
|
|
665
652
|
? unwrapExpression(defaultExport.declaration)
|
|
666
653
|
: undefined;
|
|
667
|
-
const arg = call?.type ===
|
|
654
|
+
const arg = call?.type === 'CallExpression'
|
|
668
655
|
? unwrapExpression(call.arguments?.[0] ?? {})
|
|
669
656
|
: undefined;
|
|
670
|
-
if (arg?.type !==
|
|
657
|
+
if (arg?.type !== 'ObjectExpression') {
|
|
671
658
|
return { isEndpoint, hasDefaultExport, stream: false };
|
|
672
659
|
}
|
|
673
|
-
const streamProp = arg.properties.find(
|
|
674
|
-
((prop.key?.type ===
|
|
675
|
-
(prop.key?.type ===
|
|
676
|
-
const stream = streamProp?.value?.type ===
|
|
660
|
+
const streamProp = arg.properties.find(prop => prop.type === 'ObjectProperty' &&
|
|
661
|
+
((prop.key?.type === 'Identifier' && prop.key.name === 'stream') ||
|
|
662
|
+
(prop.key?.type === 'StringLiteral' && prop.key.value === 'stream')));
|
|
663
|
+
const stream = streamProp?.value?.type === 'BooleanLiteral' &&
|
|
677
664
|
streamProp.value.value === true;
|
|
678
665
|
return { isEndpoint, hasDefaultExport, stream };
|
|
679
666
|
}
|
|
@@ -684,52 +671,52 @@ function inspectEndpointFile(source) {
|
|
|
684
671
|
* words are legal object keys.
|
|
685
672
|
*/
|
|
686
673
|
const RESERVED_IDENTIFIERS = new Set([
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
674
|
+
'await',
|
|
675
|
+
'break',
|
|
676
|
+
'case',
|
|
677
|
+
'catch',
|
|
678
|
+
'class',
|
|
679
|
+
'const',
|
|
680
|
+
'continue',
|
|
681
|
+
'debugger',
|
|
682
|
+
'default',
|
|
683
|
+
'delete',
|
|
684
|
+
'do',
|
|
685
|
+
'else',
|
|
686
|
+
'enum',
|
|
687
|
+
'export',
|
|
688
|
+
'extends',
|
|
689
|
+
'false',
|
|
690
|
+
'finally',
|
|
691
|
+
'for',
|
|
692
|
+
'function',
|
|
693
|
+
'if',
|
|
694
|
+
'implements',
|
|
695
|
+
'import',
|
|
696
|
+
'in',
|
|
697
|
+
'instanceof',
|
|
698
|
+
'interface',
|
|
699
|
+
'let',
|
|
700
|
+
'new',
|
|
701
|
+
'null',
|
|
702
|
+
'package',
|
|
703
|
+
'private',
|
|
704
|
+
'protected',
|
|
705
|
+
'public',
|
|
706
|
+
'return',
|
|
707
|
+
'static',
|
|
708
|
+
'super',
|
|
709
|
+
'switch',
|
|
710
|
+
'this',
|
|
711
|
+
'throw',
|
|
712
|
+
'true',
|
|
713
|
+
'try',
|
|
714
|
+
'typeof',
|
|
715
|
+
'var',
|
|
716
|
+
'void',
|
|
717
|
+
'while',
|
|
718
|
+
'with',
|
|
719
|
+
'yield',
|
|
733
720
|
]);
|
|
734
721
|
const toSafeIdentifier = (camelName) => RESERVED_IDENTIFIERS.has(camelName) ? `_${camelName}` : camelName;
|
|
735
722
|
export function generateApiTs(endpointFiles) {
|
|
@@ -739,11 +726,11 @@ export function generateApiTs(endpointFiles) {
|
|
|
739
726
|
const seenIdents = new Set();
|
|
740
727
|
const skipped = [];
|
|
741
728
|
for (const file of endpointFiles) {
|
|
742
|
-
const fileName = typeof file ===
|
|
743
|
-
const content = typeof file ===
|
|
729
|
+
const fileName = typeof file === 'string' ? file : file.fileName;
|
|
730
|
+
const content = typeof file === 'string' ? undefined : file.content;
|
|
744
731
|
// `foo.d.ts` -> baseName `foo.d`, which imports nothing and camelCases to
|
|
745
732
|
// `fooD`. Declaration files are never endpoints.
|
|
746
|
-
if (fileName.endsWith(
|
|
733
|
+
if (fileName.endsWith('.d.ts'))
|
|
747
734
|
continue;
|
|
748
735
|
// Callers that pass bare filenames can't be filtered — every in-tree caller
|
|
749
736
|
// passes content, and so does the backend's migration assembler.
|
|
@@ -752,7 +739,7 @@ export function generateApiTs(endpointFiles) {
|
|
|
752
739
|
skipped.push(fileName);
|
|
753
740
|
continue;
|
|
754
741
|
}
|
|
755
|
-
const baseName = fileName.replace(/\.(ts|js)$/,
|
|
742
|
+
const baseName = fileName.replace(/\.(ts|js)$/, '');
|
|
756
743
|
const key = toCamelCase(baseName);
|
|
757
744
|
const ident = toSafeIdentifier(key);
|
|
758
745
|
// Distinct files can collide on one identifier (`send-email.ts` and
|
|
@@ -778,27 +765,27 @@ export function generateApiTs(endpointFiles) {
|
|
|
778
765
|
}
|
|
779
766
|
if (endpoints.length === 0)
|
|
780
767
|
return null;
|
|
781
|
-
const hasStreaming = endpoints.some(
|
|
768
|
+
const hasStreaming = endpoints.some(e => e.stream);
|
|
782
769
|
const lines = [
|
|
783
|
-
|
|
784
|
-
|
|
770
|
+
'// Auto-generated by zitejs generate. Do not edit manually.',
|
|
771
|
+
'',
|
|
785
772
|
hasStreaming
|
|
786
773
|
? "import { createCaller, createStreamingCaller } from 'zitejs/caller';"
|
|
787
774
|
: "import { createCaller } from 'zitejs/caller';",
|
|
788
|
-
|
|
775
|
+
'',
|
|
789
776
|
];
|
|
790
777
|
if (skipped.length > 0) {
|
|
791
|
-
lines.push(
|
|
778
|
+
lines.push('// Not endpoints, so no callers were generated for them:');
|
|
792
779
|
for (const name of skipped)
|
|
793
780
|
lines.push(`// ${commentSafe(name)}`);
|
|
794
|
-
lines.push(
|
|
781
|
+
lines.push('');
|
|
795
782
|
}
|
|
796
783
|
for (const { pascal, baseName, typed } of endpoints) {
|
|
797
784
|
if (!typed)
|
|
798
785
|
continue;
|
|
799
786
|
lines.push(`import type { default as _${pascal}Ep } from ${tsSingleQuoted(`../src/api/${baseName}`)};`);
|
|
800
787
|
}
|
|
801
|
-
lines.push(
|
|
788
|
+
lines.push('');
|
|
802
789
|
for (const { baseName, ident, pascal, stream, typed } of endpoints) {
|
|
803
790
|
if (!typed) {
|
|
804
791
|
// Declared with `export const x = createEndpoint(...)` — the 1.0 shape.
|
|
@@ -807,8 +794,8 @@ export function generateApiTs(endpointFiles) {
|
|
|
807
794
|
lines.push(`// ${commentSafe(`'${baseName}'`)} has no default export, so its input/output are untyped.`);
|
|
808
795
|
lines.push(`export type ${pascal}InputType = unknown;`);
|
|
809
796
|
lines.push(`export type ${pascal}OutputType = unknown;`);
|
|
810
|
-
lines.push(`export const ${ident} = ${stream ?
|
|
811
|
-
lines.push(
|
|
797
|
+
lines.push(`export const ${ident} = ${stream ? 'createStreamingCaller' : 'createCaller'}<${pascal}InputType, ${pascal}OutputType>(${tsSingleQuoted(baseName)});`);
|
|
798
|
+
lines.push('');
|
|
812
799
|
continue;
|
|
813
800
|
}
|
|
814
801
|
lines.push(`type _${pascal}Cfg = typeof _${pascal}Ep;`);
|
|
@@ -825,65 +812,65 @@ export function generateApiTs(endpointFiles) {
|
|
|
825
812
|
// against those keys, so `send-email.ts` is reachable at `/api/send-email`.
|
|
826
813
|
// Calling it `sendEmail` here made every hyphenated or snake_cased endpoint
|
|
827
814
|
// a 404.
|
|
828
|
-
const caller = stream ?
|
|
815
|
+
const caller = stream ? 'createStreamingCaller' : 'createCaller';
|
|
829
816
|
lines.push(`export const ${ident} = ${caller}<${pascal}InputType, ${pascal}OutputType>(${tsSingleQuoted(baseName)});`);
|
|
830
|
-
lines.push(
|
|
817
|
+
lines.push('');
|
|
831
818
|
}
|
|
832
|
-
lines.push(
|
|
833
|
-
lines.push(
|
|
819
|
+
lines.push('');
|
|
820
|
+
lines.push('export const api = {');
|
|
834
821
|
for (const { key, ident } of endpoints) {
|
|
835
822
|
lines.push(key === ident ? ` ${ident},` : ` ${key}: ${ident},`);
|
|
836
823
|
}
|
|
837
|
-
lines.push(
|
|
838
|
-
lines.push(
|
|
839
|
-
return lines.join(
|
|
824
|
+
lines.push('};');
|
|
825
|
+
lines.push('');
|
|
826
|
+
return lines.join('\n');
|
|
840
827
|
}
|
|
841
828
|
function tsTypeForField(field) {
|
|
842
829
|
if (FIELD_TYPE_MAP[field.type])
|
|
843
830
|
return FIELD_TYPE_MAP[field.type];
|
|
844
|
-
return
|
|
831
|
+
return 'string';
|
|
845
832
|
}
|
|
846
833
|
const AIRTABLE_FIELD_TYPE_MAP = {
|
|
847
834
|
// Writable fields
|
|
848
|
-
singleLineText:
|
|
849
|
-
multilineText:
|
|
850
|
-
richText:
|
|
851
|
-
email:
|
|
852
|
-
url:
|
|
853
|
-
phoneNumber:
|
|
854
|
-
barcode:
|
|
855
|
-
number:
|
|
856
|
-
currency:
|
|
857
|
-
percent:
|
|
858
|
-
rating:
|
|
835
|
+
singleLineText: 'string',
|
|
836
|
+
multilineText: 'string',
|
|
837
|
+
richText: 'string',
|
|
838
|
+
email: 'string',
|
|
839
|
+
url: 'string',
|
|
840
|
+
phoneNumber: 'string',
|
|
841
|
+
barcode: 'string',
|
|
842
|
+
number: 'number',
|
|
843
|
+
currency: 'number',
|
|
844
|
+
percent: 'number',
|
|
845
|
+
rating: 'number',
|
|
859
846
|
// Formatted to "HH:mm:ss" before it reaches the app — `formatAirtableDuration`
|
|
860
847
|
// in BOTH dispatches. Unlike the Zite DB's, which is DECIMAL seconds.
|
|
861
|
-
duration:
|
|
862
|
-
checkbox:
|
|
863
|
-
date:
|
|
864
|
-
dateTime:
|
|
865
|
-
singleSelect:
|
|
866
|
-
multipleSelects:
|
|
867
|
-
multipleAttachments:
|
|
848
|
+
duration: 'string',
|
|
849
|
+
checkbox: 'boolean',
|
|
850
|
+
date: 'string',
|
|
851
|
+
dateTime: 'string',
|
|
852
|
+
singleSelect: 'string',
|
|
853
|
+
multipleSelects: 'string[]',
|
|
854
|
+
multipleAttachments: 'AirtableAttachment[]',
|
|
868
855
|
// `string | string[]`, matching the pre-monorepo type — see the note on the
|
|
869
856
|
// Zite DB's `linked_record`.
|
|
870
|
-
multipleRecordLinks:
|
|
871
|
-
singleCollaborator:
|
|
872
|
-
multipleCollaborators:
|
|
857
|
+
multipleRecordLinks: 'string | string[]',
|
|
858
|
+
singleCollaborator: '{ id: string; email: string; name?: string }',
|
|
859
|
+
multipleCollaborators: 'Array<{ id: string; email: string; name?: string }>',
|
|
873
860
|
// Read-only fields
|
|
874
|
-
autoNumber:
|
|
875
|
-
count:
|
|
876
|
-
formula:
|
|
877
|
-
rollup:
|
|
878
|
-
multipleLookupValues:
|
|
879
|
-
createdTime:
|
|
880
|
-
lastModifiedTime:
|
|
881
|
-
createdBy:
|
|
882
|
-
lastModifiedBy:
|
|
861
|
+
autoNumber: 'number',
|
|
862
|
+
count: 'number',
|
|
863
|
+
formula: 'unknown',
|
|
864
|
+
rollup: 'unknown',
|
|
865
|
+
multipleLookupValues: 'unknown',
|
|
866
|
+
createdTime: 'string',
|
|
867
|
+
lastModifiedTime: 'string',
|
|
868
|
+
createdBy: '{ id: string; email: string; name?: string }',
|
|
869
|
+
lastModifiedBy: '{ id: string; email: string; name?: string }',
|
|
883
870
|
// Both dispatches extract the URL string off the button object.
|
|
884
|
-
button:
|
|
885
|
-
externalSyncSource:
|
|
886
|
-
aiText:
|
|
871
|
+
button: 'string',
|
|
872
|
+
externalSyncSource: 'unknown',
|
|
873
|
+
aiText: 'string',
|
|
887
874
|
};
|
|
888
875
|
/**
|
|
889
876
|
* Field types whose WRITE shape is looser than what Airtable returns.
|
|
@@ -891,10 +878,10 @@ const AIRTABLE_FIELD_TYPE_MAP = {
|
|
|
891
878
|
* `{ url, filename? }`; a link field returns an array but accepts one id.
|
|
892
879
|
*/
|
|
893
880
|
const AIRTABLE_FIELD_INPUT_TYPE_MAP = {
|
|
894
|
-
multipleAttachments:
|
|
895
|
-
multipleRecordLinks:
|
|
896
|
-
singleCollaborator:
|
|
897
|
-
multipleCollaborators:
|
|
881
|
+
multipleAttachments: 'Array<{ url: string; filename?: string }>',
|
|
882
|
+
multipleRecordLinks: 'string | string[]',
|
|
883
|
+
singleCollaborator: '{ id: string } | { email: string }',
|
|
884
|
+
multipleCollaborators: 'Array<{ id: string } | { email: string }>',
|
|
898
885
|
};
|
|
899
886
|
/**
|
|
900
887
|
* Airtable's attachment object as the REST API really returns it.
|
|
@@ -905,34 +892,34 @@ const AIRTABLE_FIELD_INPUT_TYPE_MAP = {
|
|
|
905
892
|
* migration type error. Optional, because a non-image attachment has neither.
|
|
906
893
|
*/
|
|
907
894
|
const AIRTABLE_ATTACHMENT_TYPE = [
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
895
|
+
'export type AirtableAttachment = {',
|
|
896
|
+
' id: string;',
|
|
897
|
+
' url: string;',
|
|
898
|
+
' filename: string;',
|
|
899
|
+
' /** Size in bytes. */',
|
|
900
|
+
' size: number;',
|
|
901
|
+
' /** MIME type. */',
|
|
902
|
+
' type: string;',
|
|
903
|
+
' /** Pixel width — images only. */',
|
|
904
|
+
' width?: number;',
|
|
905
|
+
' /** Pixel height — images only. */',
|
|
906
|
+
' height?: number;',
|
|
907
|
+
' thumbnails?: {',
|
|
908
|
+
' small: { url: string; width: number; height: number };',
|
|
909
|
+
' large: { url: string; width: number; height: number };',
|
|
910
|
+
' full: { url: string; width: number; height: number };',
|
|
911
|
+
' };',
|
|
912
|
+
'};',
|
|
913
|
+
'',
|
|
927
914
|
];
|
|
928
|
-
function airtableTsType(field, lock, depth, variant =
|
|
929
|
-
if (variant ===
|
|
915
|
+
function airtableTsType(field, lock, depth, variant = 'read') {
|
|
916
|
+
if (variant === 'write' && AIRTABLE_FIELD_INPUT_TYPE_MAP[field.type]) {
|
|
930
917
|
return AIRTABLE_FIELD_INPUT_TYPE_MAP[field.type];
|
|
931
918
|
}
|
|
932
919
|
// A formula or rollup's cell type is whatever its expression produces, and
|
|
933
920
|
// Airtable reports that in the field's `result`. Reading it turns `unknown`
|
|
934
921
|
// — which forces a cast at every use — into the actual type.
|
|
935
|
-
if ((field.type ===
|
|
922
|
+
if ((field.type === 'formula' || field.type === 'rollup') &&
|
|
936
923
|
(depth ?? 0) < 5) {
|
|
937
924
|
const result = field.config?.result;
|
|
938
925
|
if (result?.type && result.type !== field.type) {
|
|
@@ -940,28 +927,28 @@ function airtableTsType(field, lock, depth, variant = "read") {
|
|
|
940
927
|
}
|
|
941
928
|
}
|
|
942
929
|
const choices = field.config?.choices;
|
|
943
|
-
if ((field.type ===
|
|
930
|
+
if ((field.type === 'singleSelect' || field.type === 'multipleSelects') &&
|
|
944
931
|
choices &&
|
|
945
932
|
choices.length > 0) {
|
|
946
933
|
const literals = choices
|
|
947
934
|
.slice(0, MAX_SELECT_OPTIONS)
|
|
948
|
-
.map(
|
|
949
|
-
.join(
|
|
935
|
+
.map(o => tsStringLiteral(o))
|
|
936
|
+
.join(' | ');
|
|
950
937
|
const union = `${literals} | string`;
|
|
951
|
-
if (field.type ===
|
|
938
|
+
if (field.type === 'multipleSelects')
|
|
952
939
|
return `(${union})[]`;
|
|
953
940
|
return union;
|
|
954
941
|
}
|
|
955
|
-
if (field.type ===
|
|
942
|
+
if (field.type === 'multipleLookupValues' && lock && (depth ?? 0) < 5) {
|
|
956
943
|
const linkFieldId = field.config?.recordLinkFieldId;
|
|
957
944
|
const targetFieldId = field.config?.fieldIdInLinkedTable;
|
|
958
945
|
if (linkFieldId && targetFieldId) {
|
|
959
|
-
const table = lock.tables.find(
|
|
960
|
-
const linkField = table?.fields.find(
|
|
946
|
+
const table = lock.tables.find(t => t.fields.some(f => f.id === linkFieldId));
|
|
947
|
+
const linkField = table?.fields.find(f => f.id === linkFieldId);
|
|
961
948
|
const linkedTableId = linkField?.config?.linkedTableId;
|
|
962
949
|
if (linkedTableId) {
|
|
963
|
-
const linkedTable = lock.tables.find(
|
|
964
|
-
const targetField = linkedTable?.fields.find(
|
|
950
|
+
const linkedTable = lock.tables.find(t => t.id === linkedTableId);
|
|
951
|
+
const targetField = linkedTable?.fields.find(f => f.id === targetFieldId);
|
|
965
952
|
if (targetField) {
|
|
966
953
|
const resolved = airtableTsType(targetField, lock, (depth ?? 0) + 1);
|
|
967
954
|
return `${resolved}[] | undefined`;
|
|
@@ -969,90 +956,90 @@ function airtableTsType(field, lock, depth, variant = "read") {
|
|
|
969
956
|
}
|
|
970
957
|
}
|
|
971
958
|
}
|
|
972
|
-
return AIRTABLE_FIELD_TYPE_MAP[field.type] ??
|
|
959
|
+
return AIRTABLE_FIELD_TYPE_MAP[field.type] ?? 'unknown';
|
|
973
960
|
}
|
|
974
961
|
const READ_ONLY_AIRTABLE_FIELDS = new Set([
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
962
|
+
'autoNumber',
|
|
963
|
+
'count',
|
|
964
|
+
'formula',
|
|
965
|
+
'rollup',
|
|
966
|
+
'multipleLookupValues',
|
|
967
|
+
'createdTime',
|
|
968
|
+
'lastModifiedTime',
|
|
969
|
+
'createdBy',
|
|
970
|
+
'lastModifiedBy',
|
|
971
|
+
'button',
|
|
972
|
+
'externalSyncSource',
|
|
973
|
+
'aiText',
|
|
987
974
|
]);
|
|
988
975
|
function airtableFieldJsdoc(field, table, lock) {
|
|
989
976
|
const parts = [];
|
|
990
977
|
if (table.primaryFieldId === field.id)
|
|
991
|
-
parts.push(
|
|
978
|
+
parts.push('Primary field');
|
|
992
979
|
if (READ_ONLY_AIRTABLE_FIELDS.has(field.type))
|
|
993
|
-
parts.push(
|
|
994
|
-
if (field.type ===
|
|
980
|
+
parts.push('Read-only; do not write');
|
|
981
|
+
if (field.type === 'multipleRecordLinks') {
|
|
995
982
|
const linkedTableId = field.config?.linkedTableId;
|
|
996
983
|
if (linkedTableId) {
|
|
997
|
-
const linked = lock?.tables.find(
|
|
984
|
+
const linked = lock?.tables.find(t => t.id === linkedTableId);
|
|
998
985
|
parts.push(linked
|
|
999
|
-
? `Links to ${linked.sdkName}${linked.name ? ` ("${linked.name}")` :
|
|
986
|
+
? `Links to ${linked.sdkName}${linked.name ? ` ("${linked.name}")` : ''}`
|
|
1000
987
|
: `Links to ${linkedTableId}`);
|
|
1001
988
|
}
|
|
1002
989
|
if (field.config?.prefersSingleRecordLink)
|
|
1003
|
-
parts.push(
|
|
990
|
+
parts.push('Single record only');
|
|
1004
991
|
}
|
|
1005
|
-
if (field.type ===
|
|
1006
|
-
parts.push(
|
|
1007
|
-
if (field.type ===
|
|
1008
|
-
parts.push(
|
|
992
|
+
if (field.type === 'multipleLookupValues')
|
|
993
|
+
parts.push('Lookup: value is an array — index or aggregate when displaying');
|
|
994
|
+
if (field.type === 'percent')
|
|
995
|
+
parts.push('Raw decimal — multiply by 100 for display percentage');
|
|
1009
996
|
parts.push(`"${field.name}"`);
|
|
1010
|
-
if (field.type ===
|
|
997
|
+
if (field.type === 'currency') {
|
|
1011
998
|
const symbol = field.config?.symbol;
|
|
1012
999
|
const precision = field.config?.precision;
|
|
1013
1000
|
if (symbol)
|
|
1014
1001
|
parts.push(`Display as currency with "${symbol}", ${precision ?? 2} decimals`);
|
|
1015
1002
|
}
|
|
1016
|
-
if (field.type ===
|
|
1003
|
+
if (field.type === 'date') {
|
|
1017
1004
|
const fmt = field.config?.dateFormat;
|
|
1018
1005
|
if (fmt)
|
|
1019
1006
|
parts.push(`Date-only (ISO string), display as "${fmt}"`);
|
|
1020
1007
|
}
|
|
1021
|
-
if (field.type ===
|
|
1008
|
+
if (field.type === 'dateTime') {
|
|
1022
1009
|
const dateFmt = field.config?.dateFormat;
|
|
1023
1010
|
const timeFmt = field.config?.timeFormat;
|
|
1024
1011
|
const tz = field.config?.timeZone;
|
|
1025
|
-
const fmtParts = [
|
|
1012
|
+
const fmtParts = ['Date+time (ISO string)'];
|
|
1026
1013
|
if (dateFmt)
|
|
1027
1014
|
fmtParts.push(`date: ${dateFmt}`);
|
|
1028
1015
|
if (timeFmt)
|
|
1029
1016
|
fmtParts.push(`time: ${timeFmt}`);
|
|
1030
1017
|
if (tz)
|
|
1031
1018
|
fmtParts.push(`tz: ${tz}`);
|
|
1032
|
-
parts.push(fmtParts.join(
|
|
1019
|
+
parts.push(fmtParts.join(', '));
|
|
1033
1020
|
}
|
|
1034
|
-
if (field.type ===
|
|
1021
|
+
if (field.type === 'rating') {
|
|
1035
1022
|
const max = field.config?.max;
|
|
1036
1023
|
if (max)
|
|
1037
1024
|
parts.push(`Max: ${max}`);
|
|
1038
1025
|
}
|
|
1039
|
-
if (field.type ===
|
|
1026
|
+
if (field.type === 'duration') {
|
|
1040
1027
|
const fmt = field.config?.format;
|
|
1041
1028
|
if (fmt)
|
|
1042
1029
|
parts.push(`Value in seconds, display as "${fmt}"`);
|
|
1043
1030
|
}
|
|
1044
|
-
if (field.type ===
|
|
1031
|
+
if (field.type === 'number' || field.type === 'percent') {
|
|
1045
1032
|
const precision = field.config?.precision;
|
|
1046
1033
|
if (precision != null)
|
|
1047
1034
|
parts.push(`${precision} decimal places`);
|
|
1048
1035
|
}
|
|
1049
1036
|
if (parts.length <= 1)
|
|
1050
1037
|
return undefined;
|
|
1051
|
-
return parts.join(
|
|
1038
|
+
return parts.join('. ');
|
|
1052
1039
|
}
|
|
1053
1040
|
// A table client is a `const`, so only value-space bindings can collide with
|
|
1054
1041
|
// one. `AirtableAttachment` is a type, and types and consts coexist.
|
|
1055
|
-
const RESERVED_AIRTABLE_NAMES = [
|
|
1042
|
+
const RESERVED_AIRTABLE_NAMES = ['createAirtableClient'];
|
|
1056
1043
|
/**
|
|
1057
1044
|
* Make every table sdkName in the lock unique, so a duplicated lock can't emit
|
|
1058
1045
|
* a file that cannot compile (TS2300/TS2451) and that no app can edit or
|
|
@@ -1088,7 +1075,7 @@ export function normalizeAirtableLockNames(lock) {
|
|
|
1088
1075
|
});
|
|
1089
1076
|
// Sole owners claim their names before any contender is suffixed, so a
|
|
1090
1077
|
// contender can never displace a table legitimately named `GroupCalls2`.
|
|
1091
|
-
const kept = lock.tables.map(
|
|
1078
|
+
const kept = lock.tables.map(table => owners.get(table.sdkName) === 1 && tableNames.available(table.sdkName)
|
|
1092
1079
|
? tableNames.allocate(table.sdkName)
|
|
1093
1080
|
: undefined);
|
|
1094
1081
|
const renames = [];
|
|
@@ -1096,7 +1083,7 @@ export function normalizeAirtableLockNames(lock) {
|
|
|
1096
1083
|
const sdkName = kept[i] ?? tableNames.allocate(table.sdkName);
|
|
1097
1084
|
if (sdkName !== table.sdkName) {
|
|
1098
1085
|
renames.push({
|
|
1099
|
-
kind:
|
|
1086
|
+
kind: 'table',
|
|
1100
1087
|
tableId: table.id,
|
|
1101
1088
|
from: table.sdkName,
|
|
1102
1089
|
to: sdkName,
|
|
@@ -1106,7 +1093,11 @@ export function normalizeAirtableLockNames(lock) {
|
|
|
1106
1093
|
});
|
|
1107
1094
|
return { lock: { ...lock, tables }, renames };
|
|
1108
1095
|
}
|
|
1109
|
-
|
|
1096
|
+
/** Where an app keeps the server code a generated client is used from. */
|
|
1097
|
+
const serverCodeIn = (runtime) => runtime === 'start'
|
|
1098
|
+
? 'server functions and *.server.ts files'
|
|
1099
|
+
: 'endpoint files (src/api/*.ts)';
|
|
1100
|
+
export function generateAirtableTs(inputLock, runtime = 'classic') {
|
|
1110
1101
|
if (inputLock.tables.length === 0)
|
|
1111
1102
|
return null;
|
|
1112
1103
|
const { lock, renames } = normalizeAirtableLockNames(inputLock);
|
|
@@ -1116,48 +1107,48 @@ export function generateAirtableTs(inputLock) {
|
|
|
1116
1107
|
}
|
|
1117
1108
|
}
|
|
1118
1109
|
const lines = [
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
`// import { ${lock.tables[0]?.sdkName ??
|
|
1124
|
-
|
|
1110
|
+
'// Auto-generated by zitejs generate from zite.lock. Do not edit manually.',
|
|
1111
|
+
'// Airtable SDK — uses createAirtableClient from zitejs/runtime.',
|
|
1112
|
+
'//',
|
|
1113
|
+
`// Usage in ${serverCodeIn(runtime)} — one client is exported per table:`,
|
|
1114
|
+
`// import { ${lock.tables[0]?.sdkName ?? 'TableName'} } from 'zitejs/integrations';`,
|
|
1115
|
+
'//',
|
|
1125
1116
|
"// Always use 'zitejs/integrations' — never a relative path like",
|
|
1126
1117
|
"// '../../.zite/integrations/airtable'. The tsconfig aliases resolve zitejs/*",
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1118
|
+
'// imports to the correct .zite/ files.',
|
|
1119
|
+
'//',
|
|
1120
|
+
'// Each exported table client has these methods (all take a single params object):',
|
|
1121
|
+
'// findAll({ offset?, limit?, filters? }) => { records: T[], offset: string | undefined, hasMore: boolean }',
|
|
1122
|
+
'// findOne({ id?, filters? }) => T | undefined',
|
|
1123
|
+
'// create({ record }) => T | undefined',
|
|
1124
|
+
'// bulkCreate({ records }) => T[]',
|
|
1125
|
+
'// update({ id, record }) => { id: string, fields: T } | undefined',
|
|
1126
|
+
'// delete({ id }) => { id: string }',
|
|
1127
|
+
'//',
|
|
1128
|
+
'// Reading these types:',
|
|
1129
|
+
'// Every field is OPTIONAL. Airtable omits an empty cell from the response',
|
|
1130
|
+
'// entirely rather than sending null, so any field can be undefined on any row.',
|
|
1131
|
+
'// SDK names are stable identifiers and do not change when a field is renamed —',
|
|
1141
1132
|
'// each carries its current user-facing name in quotes (// "Task Name"), which is',
|
|
1142
|
-
|
|
1133
|
+
'// the source of truth for what it means.',
|
|
1143
1134
|
"// Values are RAW; format them for display using each field's comment.",
|
|
1144
1135
|
'// Fields marked "Links to X" hold Airtable record ids (rec...) from',
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1136
|
+
'// findOne/findAll — never invent one.',
|
|
1137
|
+
'// Read-only fields are absent from the *RecordInput types: Airtable rejects a',
|
|
1138
|
+
'// write to a computed one (formula, rollup, lookup, autonumber, the created/',
|
|
1139
|
+
'// modified metadata, button, aiText) with a 422.',
|
|
1140
|
+
'//',
|
|
1141
|
+
'// Usage tips:',
|
|
1142
|
+
'// - Airtable has a strict rate limit of 5 requests/second per base',
|
|
1143
|
+
'// - Use bulkCreate() instead of calling create() in a loop, but chunk it',
|
|
1144
|
+
'// yourself: Airtable rejects more than 10 records in one create request',
|
|
1145
|
+
'// with a 422, and not every runtime path batches for you',
|
|
1146
|
+
'// - findAll() offsets are opaque cursor strings from a previous call, NOT row',
|
|
1147
|
+
'// counts (unlike zite.<table>.findAll, whose offset IS a number)',
|
|
1148
|
+
'// - Always destructure record properties individually in create/update calls',
|
|
1149
|
+
'',
|
|
1159
1150
|
"import { createAirtableClient } from 'zitejs/runtime';",
|
|
1160
|
-
|
|
1151
|
+
'',
|
|
1161
1152
|
];
|
|
1162
1153
|
lines.push(...AIRTABLE_ATTACHMENT_TYPE);
|
|
1163
1154
|
for (const table of lock.tables) {
|
|
@@ -1166,9 +1157,9 @@ export function generateAirtableTs(inputLock) {
|
|
|
1166
1157
|
? `/** A record in the "${commentSafe(table.name)}" table, as it is read back. */`
|
|
1167
1158
|
: `/** A ${commentSafe(table.sdkName)} record as it is read back. */`);
|
|
1168
1159
|
lines.push(`export type ${recordType} = {`);
|
|
1169
|
-
lines.push(
|
|
1160
|
+
lines.push(' id: string;');
|
|
1170
1161
|
for (const field of table.fields) {
|
|
1171
|
-
if (field.sdkName ===
|
|
1162
|
+
if (field.sdkName === 'id')
|
|
1172
1163
|
continue;
|
|
1173
1164
|
const jsdoc = airtableFieldJsdoc(field, table, lock);
|
|
1174
1165
|
if (jsdoc) {
|
|
@@ -1181,172 +1172,172 @@ export function generateAirtableTs(inputLock) {
|
|
|
1181
1172
|
// typed `string` is `undefined` at runtime on the first blank row.
|
|
1182
1173
|
lines.push(` ${field.sdkName}?: ${tsType};`);
|
|
1183
1174
|
}
|
|
1184
|
-
lines.push(
|
|
1185
|
-
lines.push(
|
|
1175
|
+
lines.push('};');
|
|
1176
|
+
lines.push('');
|
|
1186
1177
|
// Read-only fields are omitted rather than typed: Airtable rejects a write
|
|
1187
1178
|
// to a formula, rollup, lookup or autonumber with a 422.
|
|
1188
|
-
const writableFields = table.fields.filter(
|
|
1179
|
+
const writableFields = table.fields.filter(f => f.sdkName !== 'id' && !READ_ONLY_AIRTABLE_FIELDS.has(f.type));
|
|
1189
1180
|
lines.push(table.name
|
|
1190
1181
|
? `/** What you may write when creating or updating a record in the "${commentSafe(table.name)}" table. */`
|
|
1191
1182
|
: `/** What you may write when creating or updating a ${commentSafe(table.sdkName)}. */`);
|
|
1192
1183
|
lines.push(`export type ${table.sdkName}RecordInput = {`);
|
|
1193
1184
|
for (const field of writableFields) {
|
|
1194
|
-
lines.push(` ${field.sdkName}: ${airtableTsType(field, lock, 0,
|
|
1185
|
+
lines.push(` ${field.sdkName}: ${airtableTsType(field, lock, 0, 'write')};`);
|
|
1195
1186
|
}
|
|
1196
|
-
lines.push(
|
|
1197
|
-
lines.push(
|
|
1187
|
+
lines.push('};');
|
|
1188
|
+
lines.push('');
|
|
1198
1189
|
lines.push(`export const ${table.sdkName} = createAirtableClient<${recordType}, ${table.sdkName}RecordInput>(`);
|
|
1199
1190
|
lines.push(` '${lock.integrationId}',`);
|
|
1200
1191
|
lines.push(` '${table.sdkName}',`);
|
|
1201
1192
|
lines.push(` { tableId: '${table.id}' },` +
|
|
1202
|
-
(table.name ? ` // "${commentSafe(table.name)}"` :
|
|
1193
|
+
(table.name ? ` // "${commentSafe(table.name)}"` : ''));
|
|
1203
1194
|
lines.push(`);`);
|
|
1204
|
-
lines.push(
|
|
1195
|
+
lines.push('');
|
|
1205
1196
|
}
|
|
1206
|
-
return lines.join(
|
|
1197
|
+
return lines.join('\n');
|
|
1207
1198
|
}
|
|
1208
1199
|
export function generateBackendWrapperTs(envVarNames = []) {
|
|
1209
1200
|
const names = [
|
|
1210
|
-
|
|
1211
|
-
...envVarNames.filter(
|
|
1201
|
+
'ZITE_APP_URL',
|
|
1202
|
+
...envVarNames.filter(n => n !== 'ZITE_APP_URL'),
|
|
1212
1203
|
];
|
|
1213
1204
|
return [
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1205
|
+
'// Auto-generated type-narrowing wrapper. Do not edit manually.',
|
|
1206
|
+
'// Re-exports createEndpoint with context.user typed to the app User.',
|
|
1207
|
+
'',
|
|
1217
1208
|
"import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext, ZiteErrorCode, ZiteSchedule, ZiteStep, ZiteStreamInterface, ZiteTrigger, ZiteTriggerContext, ZiteEndpointInput, ZiteWebhook } from 'zitejs/backend/base';",
|
|
1218
1209
|
"import type { User } from 'zitejs/auth';",
|
|
1219
|
-
|
|
1220
|
-
|
|
1210
|
+
'',
|
|
1211
|
+
'export type { ZiteErrorCode, ZiteSchedule, ZiteScheduledContext, ZiteStep, ZiteStreamInterface, ZiteTrigger, ZiteWebhook };',
|
|
1221
1212
|
// A trigger's registration exports are typed against these, and they
|
|
1222
1213
|
// only reach app code through this file.
|
|
1223
1214
|
"export type { ZiteDatabaseTriggerEvent, ZiteDatabaseTriggerInput, ZiteFormTriggerInput, ZiteTriggerContext, ZiteTriggerDeliveryInfo, ZiteTriggerDeliveryRun, ZiteTriggerRun, ZiteTriggerSubscribe, ZiteTriggerSubscribeInput, ZiteTriggerSubscribeResult, ZiteTriggerUnsubscribe, ZiteTriggerUnsubscribeInput } from 'zitejs/backend/base';",
|
|
1224
1215
|
// The pre-monorepo SDK put this in scope for every endpoint, so migrated
|
|
1225
1216
|
// code can name it. `createEndpoint` infers the same thing without it.
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1217
|
+
'export type InferSchemaType<T> = T extends { _output: infer U } ? U : T;',
|
|
1218
|
+
'',
|
|
1219
|
+
'export class ZiteError extends Error {',
|
|
1220
|
+
' code: ZiteErrorCode;',
|
|
1221
|
+
' /** Short, non-technical message suitable for showing to an end user. */',
|
|
1222
|
+
' userFacingMessage?: string;',
|
|
1232
1223
|
" // Both shapes, mirroring the worker's own class: object form preferred,",
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1224
|
+
' // positional form is what pre-monorepo app code was written against.',
|
|
1225
|
+
' constructor(options: { code: ZiteErrorCode; message: string; userFacingMessage?: string });',
|
|
1226
|
+
' constructor(message: string, code?: ZiteErrorCode);',
|
|
1227
|
+
' constructor(',
|
|
1228
|
+
' optionsOrMessage: { code: ZiteErrorCode; message: string; userFacingMessage?: string } | string,',
|
|
1229
|
+
' legacyCode?: ZiteErrorCode,',
|
|
1230
|
+
' ) {',
|
|
1240
1231
|
" if (typeof optionsOrMessage === 'string') {",
|
|
1241
|
-
|
|
1232
|
+
' super(optionsOrMessage);',
|
|
1242
1233
|
" this.code = legacyCode ?? 'INTERNAL_ERROR';",
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1234
|
+
' } else {',
|
|
1235
|
+
' super(optionsOrMessage.message);',
|
|
1236
|
+
' this.code = optionsOrMessage.code;',
|
|
1237
|
+
' this.userFacingMessage = optionsOrMessage.userFacingMessage;',
|
|
1238
|
+
' }',
|
|
1248
1239
|
" this.name = 'ZiteError';",
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1240
|
+
' }',
|
|
1241
|
+
'}',
|
|
1242
|
+
'',
|
|
1252
1243
|
// Narrows `user` to this app's generated User. ZiteScheduledContext is
|
|
1253
1244
|
// re-exported unchanged — a scheduled fire has no user at all, so there is
|
|
1254
1245
|
// nothing to narrow.
|
|
1255
|
-
|
|
1256
|
-
|
|
1246
|
+
'/**',
|
|
1247
|
+
' * The user an endpoint sees. NOT the full `User` from zitejs/auth — that is',
|
|
1257
1248
|
" * the browser's better-auth session, and the runtime never sends its",
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1249
|
+
' * `name`, `emailVerified`, `image`, `createdAt` or `updatedAt` to an',
|
|
1250
|
+
' * endpoint. Typing those here let `context.user.createdAt.getFullYear()`',
|
|
1251
|
+
' * compile and throw. `Omit` keeps any index signature merged in by',
|
|
1252
|
+
' * `.zite/user-extensions.d.ts`, so a migrated user-sync app still reads its',
|
|
1253
|
+
' * synced columns off this.',
|
|
1254
|
+
' *',
|
|
1255
|
+
' * The `Pick` intersection is not redundant. On an app that DOES merge in',
|
|
1256
|
+
' * `[key: string]: any`, `keyof User` widens to `string`, `Exclude` then',
|
|
1257
|
+
' * removes nothing, and the `Omit` collapses to a bare index signature —',
|
|
1258
|
+
' * which would silently degrade `user.id` from `string` to `any`. The `Pick`',
|
|
1259
|
+
' * names those members explicitly, so they survive the collapse.',
|
|
1260
|
+
' *',
|
|
1261
|
+
' * Only `id` and `email` are pinned that way, deliberately. On a user-sync',
|
|
1262
|
+
' * app `context.user` IS the synced row (`buildUserContext` returns it',
|
|
1263
|
+
' * whole), and only those two are guaranteed by the runtime: the id is the',
|
|
1264
|
+
' * record id and the email is merged in explicitly. `firstName`/`lastName`',
|
|
1265
|
+
' * come from whatever the app mapped those columns to, so pinning them to',
|
|
1266
|
+
' * `string` would reject a legitimate read on a table that types them',
|
|
1267
|
+
' * differently. Non-widened apps get both from the `Omit` regardless.',
|
|
1268
|
+
' *',
|
|
1269
|
+
' * On such an app `user.createdAt` still compiles, as `any`. That is',
|
|
1270
|
+
' * deliberate: a synced user table may legitimately have its own',
|
|
1271
|
+
' * `createdAt` column, and typing it `never` to close the hole would break',
|
|
1272
|
+
' * exactly the legacy apps `user-extensions.d.ts` exists to keep compiling.',
|
|
1273
|
+
' */',
|
|
1274
|
+
'export type ZiteEndpointUser = Omit<',
|
|
1275
|
+
' User,',
|
|
1285
1276
|
" 'name' | 'emailVerified' | 'image' | 'createdAt' | 'updatedAt'",
|
|
1286
|
-
|
|
1277
|
+
'> &',
|
|
1287
1278
|
" Pick<User, 'id' | 'email'> &",
|
|
1288
1279
|
" Pick<_ZiteRequestContext['user'], 'roles'>;",
|
|
1289
|
-
|
|
1280
|
+
'',
|
|
1290
1281
|
'export interface ZiteRequestContext extends Omit<_ZiteRequestContext, "user"> {',
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1282
|
+
' user: ZiteEndpointUser;',
|
|
1283
|
+
'}',
|
|
1284
|
+
'',
|
|
1285
|
+
'type SchemaLike<TOut, TIn = TOut> = { _output: TOut; _input: TIn; parse: (data: unknown) => TOut };',
|
|
1286
|
+
'',
|
|
1296
1287
|
// TStream mirrors zitejs/backend/base. Without it `stream: true` endpoints
|
|
1297
1288
|
// get no `stream` argument here — and this wrapper, not the base module, is
|
|
1298
1289
|
// what `zitejs/backend` resolves to in every app.
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1290
|
+
'export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream extends boolean = false, TSchedule extends ZiteSchedule | undefined = undefined, TWebhook extends ZiteWebhook | undefined = undefined, TRawInput = TInput, TTrigger extends ZiteTrigger | undefined = undefined> {',
|
|
1291
|
+
' description?: string;',
|
|
1292
|
+
' inputSchema?: SchemaLike<TInput, TRawInput>;',
|
|
1302
1293
|
// Apps compile against this copy, not the base module's.
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1294
|
+
' /** Documentation only. Never validated, and not an inference site for TOutput. */',
|
|
1295
|
+
' outputSchema?: SchemaLike<unknown>;',
|
|
1296
|
+
' stream?: TStream;',
|
|
1297
|
+
' authenticated?: boolean;',
|
|
1298
|
+
' /** When set, the endpoint also fires on this cron schedule. It stays request-callable — declaring one widens `context`, so `context.user` must be null-checked. */',
|
|
1299
|
+
' schedule?: TSchedule;',
|
|
1300
|
+
' /** When set, an inbound webhook can also trigger this endpoint. Like `schedule`, it widens `context` — a webhook fire has no session. */',
|
|
1301
|
+
' webhook?: TWebhook;',
|
|
1311
1302
|
" /** When set, a connection's events (registered by this file's own `subscribe` export), a poll (`every`), a change to one of the project's tables (`table`) or a submission to one of its forms (`form`) also fire this endpoint. Like `webhook`, it widens `context` — a trigger fire has no session. */",
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1303
|
+
' trigger?: TTrigger;',
|
|
1304
|
+
' execute: (',
|
|
1305
|
+
' params: {',
|
|
1306
|
+
' input: ZiteEndpointInput<TInput, TTrigger>;',
|
|
1307
|
+
' /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. In a run fired by a schedule, webhook or trigger, step.sleep(name, "2d") pauses the run and a failed step is tried again. Provided by the platform; never define a local stand-in. */',
|
|
1308
|
+
' step: ZiteStep;',
|
|
1309
|
+
' context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;',
|
|
1319
1310
|
// Mirrors the base module: a trigger's run gets `trigger`.
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1311
|
+
' } & (TStream extends true ? { stream: ZiteStreamInterface } : {}) & (TTrigger extends ZiteTrigger ? { trigger?: ZiteTriggerContext<TTrigger> } : {}),',
|
|
1312
|
+
' ) => Promise<TOutput> | TOutput;',
|
|
1313
|
+
'}',
|
|
1314
|
+
'',
|
|
1315
|
+
'export function createEndpoint<TInput = unknown, TOutput = unknown, TStream extends boolean = false, TSchedule extends ZiteSchedule | undefined = undefined, TWebhook extends ZiteWebhook | undefined = undefined, TRawInput = TInput, TTrigger extends ZiteTrigger | undefined = undefined>(',
|
|
1316
|
+
' config: EndpointConfig<TInput, TOutput, TStream, TSchedule, TWebhook, TRawInput, TTrigger>,',
|
|
1317
|
+
'): EndpointConfig<TInput, TOutput, TStream, TSchedule, TWebhook, TRawInput, TTrigger> {',
|
|
1318
|
+
' return config;',
|
|
1319
|
+
'}',
|
|
1320
|
+
'',
|
|
1321
|
+
'/**',
|
|
1322
|
+
' * Checks if a user has a specific role. Returns true if the user has the role, false',
|
|
1323
|
+
' * otherwise. If the user is not logged in, returns false.',
|
|
1324
|
+
' */',
|
|
1325
|
+
'export const hasRole = (context: ZiteRequestContext, roleId: string) => {',
|
|
1326
|
+
' return context.user?.roles?.some((r) => r.id === roleId);',
|
|
1327
|
+
'};',
|
|
1328
|
+
'',
|
|
1338
1329
|
// Declared in the wrapper (not a standalone .d.ts) so the merge is
|
|
1339
1330
|
// guaranteed to be in the program — every endpoint imports this file,
|
|
1340
1331
|
// while tsconfig `include` does not reliably pick up dot-directories.
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
...names.map(
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
].join(
|
|
1332
|
+
'declare global {',
|
|
1333
|
+
' namespace NodeJS {',
|
|
1334
|
+
' interface ProcessEnv {',
|
|
1335
|
+
...names.map(name => ` ${JSON.stringify(name)}: string;`),
|
|
1336
|
+
' }',
|
|
1337
|
+
' }',
|
|
1338
|
+
'}',
|
|
1339
|
+
'',
|
|
1340
|
+
].join('\n');
|
|
1350
1341
|
}
|
|
1351
1342
|
/**
|
|
1352
1343
|
* The key of the email integration an app sends through, which is the
|
|
@@ -1356,9 +1347,9 @@ export function generateBackendWrapperTs(envVarNames = []) {
|
|
|
1356
1347
|
export function findEmailIntegrationId(appConfig, workspaceConfig) {
|
|
1357
1348
|
const app = (appConfig ?? {});
|
|
1358
1349
|
const workspace = (workspaceConfig ?? {});
|
|
1359
|
-
const isEmail = (config, id) => config.integrations?.[id]?.type ===
|
|
1360
|
-
return (Object.keys(app.integrations ?? {}).find(
|
|
1361
|
-
Object.keys(app.integrationSettings ?? {}).find(
|
|
1350
|
+
const isEmail = (config, id) => config.integrations?.[id]?.type === 'email';
|
|
1351
|
+
return (Object.keys(app.integrations ?? {}).find(id => isEmail(app, id)) ??
|
|
1352
|
+
Object.keys(app.integrationSettings ?? {}).find(id => isEmail(workspace, id)));
|
|
1362
1353
|
}
|
|
1363
1354
|
/**
|
|
1364
1355
|
* Generate `.zite/integrations/email.ts` — the `Email` client for an app with
|
|
@@ -1367,43 +1358,52 @@ export function findEmailIntegrationId(appConfig, workspaceConfig) {
|
|
|
1367
1358
|
* SDK bridge, resolved via the `zitejs/email` alias. `integrationId` is the
|
|
1368
1359
|
* connected integration's key.
|
|
1369
1360
|
*/
|
|
1370
|
-
export function generateEmailSdk(integrationId) {
|
|
1361
|
+
export function generateEmailSdk(integrationId, runtime = 'classic') {
|
|
1371
1362
|
return [
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1363
|
+
'// Auto-generated by zitejs generate from zite.config.json. Do not edit manually.',
|
|
1364
|
+
'// Email SDK — sends through the Zite email gateway via the runtime bridge.',
|
|
1365
|
+
'//',
|
|
1366
|
+
`// Usage in ${serverCodeIn(runtime)}:`,
|
|
1376
1367
|
"// import { Email } from 'zitejs/email';",
|
|
1377
|
-
|
|
1368
|
+
'//',
|
|
1378
1369
|
"// Always use 'zitejs/email' — never a relative path like '../../.zite/integrations/email'.",
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
"// await Email.send({ to, subject,
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1370
|
+
'// The tsconfig aliases resolve zitejs/* imports to the correct .zite/ files.',
|
|
1371
|
+
'//',
|
|
1372
|
+
"// await Email.send({ to, subject, html: '<p>...</p>' })",
|
|
1373
|
+
'// => { success: boolean; messageId: string; warnings?: string[] }',
|
|
1374
|
+
'//',
|
|
1375
|
+
'// Emails written before html support pass `body` (blocks) instead; they',
|
|
1376
|
+
'// keep working.',
|
|
1377
|
+
'//',
|
|
1378
|
+
"// RTL languages (Hebrew, Arabic): pass direction: 'rtl'.",
|
|
1379
|
+
'//',
|
|
1380
|
+
'// await Email.sendBatch([...]) // up to 100, results in order',
|
|
1381
|
+
"// await Email.get(messageId) // delivery status (Zite's sender only)",
|
|
1382
|
+
'',
|
|
1387
1383
|
"import { createEmailClient } from 'zitejs/runtime';",
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1384
|
+
'',
|
|
1385
|
+
'export type {',
|
|
1386
|
+
' EmailBlock,',
|
|
1387
|
+
' EmailStatus,',
|
|
1388
|
+
' SendBatchResult,',
|
|
1389
|
+
' SendBlocksEmailParams,',
|
|
1390
|
+
' SendEmailParams,',
|
|
1391
|
+
' SendEmailResult,',
|
|
1392
|
+
' SendHtmlEmailParams,',
|
|
1393
1393
|
"} from 'zitejs/runtime';",
|
|
1394
|
-
|
|
1394
|
+
'',
|
|
1395
1395
|
`export const Email = createEmailClient(${tsSingleQuoted(integrationId)});`,
|
|
1396
|
-
|
|
1397
|
-
].join(
|
|
1396
|
+
'',
|
|
1397
|
+
].join('\n');
|
|
1398
1398
|
}
|
|
1399
1399
|
const connectedTypeFor = (serviceType) => {
|
|
1400
1400
|
const extraLabels = CREDENTIAL_FIELDS[serviceType].slice(1);
|
|
1401
1401
|
const optional = OPTIONAL_CREDENTIAL_FIELDS[serviceType] ?? [];
|
|
1402
1402
|
return extraLabels.length === 0
|
|
1403
|
-
?
|
|
1403
|
+
? 'Connected'
|
|
1404
1404
|
: `Connected<{ ${extraLabels
|
|
1405
|
-
.map(
|
|
1406
|
-
.join(
|
|
1405
|
+
.map(label => `${label}${optional.includes(label) ? '?' : ''}: string`)
|
|
1406
|
+
.join('; ')} }>`;
|
|
1407
1407
|
};
|
|
1408
1408
|
/**
|
|
1409
1409
|
* `.zite/integrations/index.ts`: `zitejs/integrations` for one source dir. The
|
|
@@ -1413,42 +1413,42 @@ const connectedTypeFor = (serviceType) => {
|
|
|
1413
1413
|
export function generateIntegrationsIndex(entries, opts) {
|
|
1414
1414
|
const sorted = [...entries].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
1415
1415
|
const nameUnion = sorted.length === 0
|
|
1416
|
-
?
|
|
1417
|
-
: sorted.map(({ name }) => tsSingleQuoted(name)).join(
|
|
1416
|
+
? 'never'
|
|
1417
|
+
: sorted.map(({ name }) => tsSingleQuoted(name)).join(' | ');
|
|
1418
1418
|
const byName = sorted.length === 0
|
|
1419
|
-
? [
|
|
1419
|
+
? ['export type IntegrationByName = {};']
|
|
1420
1420
|
: [
|
|
1421
|
-
|
|
1422
|
-
...sorted.map(({ name, serviceType, perUser }) => ` ${tsSingleQuoted(name)}: ${connectedTypeFor(serviceType)}${perUser ?
|
|
1423
|
-
|
|
1421
|
+
'export type IntegrationByName = {',
|
|
1422
|
+
...sorted.map(({ name, serviceType, perUser }) => ` ${tsSingleQuoted(name)}: ${connectedTypeFor(serviceType)}${perUser ? ' | NeedsConnect' : ''};`),
|
|
1423
|
+
'};',
|
|
1424
1424
|
];
|
|
1425
1425
|
return [
|
|
1426
|
-
|
|
1426
|
+
'// Auto-generated by zitejs generate from zite.config.json. Do not edit manually.',
|
|
1427
1427
|
"// zitejs/integrations — an integration's credentials by its zite.config.json entry name.",
|
|
1428
|
-
|
|
1429
|
-
|
|
1428
|
+
'//',
|
|
1429
|
+
'// Usage in endpoints (src/api/*.ts) and automations (src/index.ts):',
|
|
1430
1430
|
"// import { integrations } from 'zitejs/integrations';",
|
|
1431
|
-
|
|
1431
|
+
'//',
|
|
1432
1432
|
"// const { accessToken } = await integrations.get('<entry name>');",
|
|
1433
|
-
|
|
1433
|
+
'//',
|
|
1434
1434
|
"// A workspace connection that isn't connected throws a ZiteError. A per-user",
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1435
|
+
'// entry answers `missing`/`expired` with a connectUrl for the signed-in user.',
|
|
1436
|
+
'//',
|
|
1437
|
+
'// Call get where the value is used, not once at module scope: a token refreshed',
|
|
1438
|
+
'// mid-run is what the next call returns.',
|
|
1439
|
+
'',
|
|
1440
1440
|
// Not 'zitejs/integrations': apps alias that specifier to this very file.
|
|
1441
1441
|
"import { createIntegrationsClient } from 'zitejs/runtime';",
|
|
1442
1442
|
"import type { Connected, NeedsConnect } from 'zitejs/runtime';",
|
|
1443
|
-
|
|
1444
|
-
...(opts.reexportAirtable ? ["export * from './airtable';",
|
|
1445
|
-
|
|
1446
|
-
|
|
1443
|
+
'',
|
|
1444
|
+
...(opts.reexportAirtable ? ["export * from './airtable';", ''] : []),
|
|
1445
|
+
'export type { Connected, NeedsConnect };',
|
|
1446
|
+
'',
|
|
1447
1447
|
`export type IntegrationName = ${nameUnion};`,
|
|
1448
|
-
|
|
1448
|
+
'',
|
|
1449
1449
|
...byName,
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
].join(
|
|
1450
|
+
'',
|
|
1451
|
+
'export const integrations = createIntegrationsClient<IntegrationByName>();',
|
|
1452
|
+
'',
|
|
1453
|
+
].join('\n');
|
|
1454
1454
|
}
|