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