zitejs 0.10.0-start.22 → 0.10.0-start.23
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/start/provider.d.ts +2 -2
- package/dist/cjs/start/provider.js +3 -3
- package/dist/cjs/start/types.d.ts +29 -47
- package/dist/cjs/sync/lib.js +23 -50
- package/dist/cjs/sync/sdkNames.d.ts +65 -7
- package/dist/cjs/sync/sdkNames.js +76 -12
- package/dist/cjs/sync/sdkNames.test.js +38 -0
- package/dist/esm/start/airtable/built.d.ts +2 -0
- package/dist/esm/start/airtable/built.js +3 -0
- package/dist/esm/start/airtable/index.d.ts +3 -5
- package/dist/esm/start/airtable/index.js +4 -25
- package/dist/esm/start/airtable/settings.d.ts +31 -0
- package/dist/esm/start/airtable/settings.js +110 -0
- package/dist/esm/start/data/index.d.ts +21 -9
- package/dist/esm/start/data/index.js +26 -20
- package/dist/esm/start/data/names.d.ts +7 -0
- package/dist/esm/start/data/names.js +15 -0
- package/dist/esm/start/data/types.d.ts +4 -1
- package/dist/esm/start/direct.d.ts +16 -12
- package/dist/esm/start/direct.js +185 -56
- package/dist/esm/start/outbound.d.ts +1 -2
- package/dist/esm/start/outbound.js +8 -19
- package/dist/esm/start/provider.d.ts +2 -2
- package/dist/esm/start/provider.js +3 -3
- package/dist/esm/start/server.d.ts +17 -13
- package/dist/esm/start/server.js +41 -43
- package/dist/esm/start/telemetry.d.ts +4 -1
- package/dist/esm/start/telemetry.js +13 -16
- package/dist/esm/start/types.d.ts +29 -47
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/dist/esm/start/vite.d.ts +7 -1
- package/dist/esm/start/vite.js +68 -21
- package/dist/esm/start/workspaceSchema.d.ts +2 -1
- package/dist/esm/start/workspaceSchema.js +3 -3
- package/dist/esm/sync/lib.js +23 -50
- package/dist/esm/sync/sdkNames.d.ts +65 -7
- package/dist/esm/sync/sdkNames.js +73 -11
- package/dist/esm/sync/sdkNames.test.js +38 -0
- package/package.json +2 -2
package/dist/esm/start/server.js
CHANGED
|
@@ -7,12 +7,12 @@ import { describeApp } from "./describe.js";
|
|
|
7
7
|
import { runRegistration } from "./registration.js";
|
|
8
8
|
import { isAuthHookName, loadAuthHooks } from "./authHooks.js";
|
|
9
9
|
import { errorOf, preview } from "./runLog.js";
|
|
10
|
-
import { DATA_INTEGRATION_ID,
|
|
10
|
+
import { DATA_INTEGRATION_ID, runDataCall } from "./data/index.js";
|
|
11
11
|
import { airtableSettingsOf, runAirtableCall } from "./airtable/index.js";
|
|
12
12
|
import { withoutConsole } from "./quiet.js";
|
|
13
13
|
import { rememberConnection, watchOutboundFetches, withAiGatewayUrl, withRefreshedTokens } from "./outbound.js";
|
|
14
14
|
import { INTEGRATIONS_PLATFORM_ID } from "./credentials.js";
|
|
15
|
-
import { directAccess, directCall, directDataFetch,
|
|
15
|
+
import { connectionsOnToken, directAccess, directCall, directDataFetch, localPagePlan, NoPlatformError } from "./direct.js";
|
|
16
16
|
import { takeAnalytics } from "./analytics.js";
|
|
17
17
|
import { takeUploadSession } from "./uploads.js";
|
|
18
18
|
import { UPLOAD_SESSION_PATH } from "../internal/serviceUrls.js";
|
|
@@ -23,22 +23,18 @@ import { localSignIn, userOfIdentity } from "./localSignIn.js";
|
|
|
23
23
|
import { isSignInPath } from "../signin/paths.js";
|
|
24
24
|
import { appTokenClaims } from "../internal/appToken.js";
|
|
25
25
|
import { getHost, requireScope, runInScope, runWithHost } from "./scope.js";
|
|
26
|
-
import {
|
|
26
|
+
import { workspaceSchemaNames } from "./workspaceSchema.js";
|
|
27
27
|
import { ZITEJS_VERSION } from "./version.js";
|
|
28
28
|
import { loadUnfinishedWorkflows, loadWorkflows, loggedInput, runWorkflow } from "./workflowRun.js";
|
|
29
29
|
export { runWithHost } from "./scope.js";
|
|
30
30
|
export { describeApp } from "./describe.js";
|
|
31
|
-
const relaySession = async (host) => {
|
|
32
|
-
const session = await sessionOf(host);
|
|
33
|
-
if (!session)
|
|
34
|
-
throw new Error("The Zite platform binding is missing");
|
|
35
|
-
return session;
|
|
36
|
-
};
|
|
37
31
|
/**
|
|
38
32
|
* Routes every zitejs data, integration and email call to this request's
|
|
39
|
-
* platform
|
|
40
|
-
*
|
|
41
|
-
*
|
|
33
|
+
* platform on its app token, and only inside an access scope. The access kind
|
|
34
|
+
* travels with the call so the platform can record what a page read and
|
|
35
|
+
* narrow anonymous reads. A request with no token or URLs fails each call
|
|
36
|
+
* that would leave the app loudly: there is nowhere else for it to go. What
|
|
37
|
+
* props already answer, integrations.get and ZiteMeta.getWorkspace, needs none.
|
|
42
38
|
*/
|
|
43
39
|
export function installPlatformTransport() {
|
|
44
40
|
const sdkCall = async (integrationId, className, methodName, params) => {
|
|
@@ -46,27 +42,27 @@ export function installPlatformTransport() {
|
|
|
46
42
|
const host = getHost();
|
|
47
43
|
const getsConnection = integrationId === INTEGRATIONS_PLATFORM_ID && methodName === "get";
|
|
48
44
|
const name = String(params?.name ?? "");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
throw new Error("The Zite platform binding is missing");
|
|
45
|
+
if (!host)
|
|
46
|
+
throw new NoPlatformError();
|
|
52
47
|
if (integrationId === DATA_INTEGRATION_ID) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
const transport = (await directAccess(host)) ? { dataFetch: directDataFetch(host) } : await relaySession(host);
|
|
59
|
-
return recordCall(host, { integrationId, className, methodName, params }, () => runDataCall(transport, found, host.mode, methodName, params));
|
|
48
|
+
const access = await directAccess(host);
|
|
49
|
+
if (!access)
|
|
50
|
+
throw new NoPlatformError();
|
|
51
|
+
const target = { baseId: host.baseId ?? appTokenClaims(access.token)?.base ?? null, names: workspaceSchemaNames };
|
|
52
|
+
return recordCall(host, { integrationId, className, methodName, params }, () => runDataCall({ dataFetch: directDataFetch(host) }, target, host.mode, methodName, params));
|
|
60
53
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
const airtable = integrationId.startsWith("__") ? undefined : airtableSettingsOf(integrationId);
|
|
55
|
+
if (airtable) {
|
|
56
|
+
const connectionOf = () => directCall(host, {
|
|
57
|
+
integrationId: INTEGRATIONS_PLATFORM_ID,
|
|
58
|
+
className: "Connections",
|
|
59
|
+
methodName: "get",
|
|
60
|
+
params: { name: integrationId },
|
|
61
|
+
access: scope.kind,
|
|
62
|
+
});
|
|
63
|
+
return recordCall(host, { integrationId, className, methodName, params }, () => runAirtableCall(host, connectionOf, integrationId, airtable, methodName, params));
|
|
67
64
|
}
|
|
68
|
-
const
|
|
69
|
-
const result = (await directCall(host, input)) ?? (await (await relaySession(host)).call(input));
|
|
65
|
+
const result = await directCall(host, { integrationId, className, methodName, params, access: scope.kind });
|
|
70
66
|
if (getsConnection)
|
|
71
67
|
return connectionAnswer(host, name, result);
|
|
72
68
|
if ("value" in result)
|
|
@@ -128,9 +124,10 @@ export function hostContextFromProps(request, props) {
|
|
|
128
124
|
connectionServices: props.connectionServices,
|
|
129
125
|
runRoot: props.runRoot,
|
|
130
126
|
runs: [],
|
|
131
|
-
|
|
127
|
+
workspace: props.workspace,
|
|
128
|
+
connections: props.connections,
|
|
129
|
+
provider: ziteProvider(props),
|
|
132
130
|
};
|
|
133
|
-
host.provider = ziteProvider(props, () => sessionOf(host));
|
|
134
131
|
if (props.page)
|
|
135
132
|
host.head = platformHeadOf(props.page, { url: request.url, mode: props.mode, token: props.appToken });
|
|
136
133
|
return host;
|
|
@@ -160,12 +157,13 @@ const setRequestEnv = ({ appUrl, baseId, env: connectionEnv }) => {
|
|
|
160
157
|
};
|
|
161
158
|
/**
|
|
162
159
|
* A request the host didn't dispatch: the host's warm-up, `zitejs describe` under `vite preview`, and tests. Only the
|
|
163
|
-
* host can set props, so without them a build answers warm and describe
|
|
164
|
-
* its own
|
|
160
|
+
* host can set props, so without them a build answers warm and describe, nobody is signed in and nothing reaches the
|
|
161
|
+
* platform. An entry that passes its own provider (tests) owns its requests: it may say who is calling in `x-zite-*`
|
|
162
|
+
* headers, and its provider's token and URLs reach the platform.
|
|
165
163
|
*/
|
|
166
|
-
export function hostContextFromRequest(request,
|
|
164
|
+
export function hostContextFromRequest(request, provider) {
|
|
167
165
|
const { headers } = request;
|
|
168
|
-
const trusted =
|
|
166
|
+
const trusted = provider !== undefined;
|
|
169
167
|
const user = trusted ? headers.get("x-zite-user") : null;
|
|
170
168
|
return {
|
|
171
169
|
requestId: (trusted && headers.get("x-zite-request-id")) || crypto.randomUUID(),
|
|
@@ -174,7 +172,7 @@ export function hostContextFromRequest(request, platform) {
|
|
|
174
172
|
mode: "live",
|
|
175
173
|
invoke: invokeOf(headers, trusted ? INVOKE_KINDS : UNHOSTED_INVOKE_KINDS),
|
|
176
174
|
runs: [],
|
|
177
|
-
|
|
175
|
+
provider,
|
|
178
176
|
};
|
|
179
177
|
}
|
|
180
178
|
const invokeOf = (headers, kinds) => {
|
|
@@ -222,7 +220,7 @@ const loadLocal = async (host, request) => {
|
|
|
222
220
|
if (!access)
|
|
223
221
|
return;
|
|
224
222
|
const [connections, plan] = await Promise.all([
|
|
225
|
-
|
|
223
|
+
connectionsOnToken(access).catch((error) => {
|
|
226
224
|
console.error("[zite] couldn't load the app's connections", error);
|
|
227
225
|
return undefined;
|
|
228
226
|
}),
|
|
@@ -400,10 +398,10 @@ const pageStatus = (host) => {
|
|
|
400
398
|
};
|
|
401
399
|
/**
|
|
402
400
|
* The handlers of a Start app's server entry. A request the host dispatched
|
|
403
|
-
* carries its identity and platform in props. Without props, a
|
|
404
|
-
* dev token or API key in env selects the `local` provider;
|
|
405
|
-
* `vite preview`, tests) reads `x-zite-*`
|
|
406
|
-
* is given.
|
|
401
|
+
* carries its identity, app token and platform URLs in props. Without props, a
|
|
402
|
+
* developer's dev token or API key in env selects the `local` provider;
|
|
403
|
+
* anything else (describe under `vite preview`, tests) reads `x-zite-*`
|
|
404
|
+
* headers and uses `provider` if one is given.
|
|
407
405
|
*/
|
|
408
406
|
export function createZiteHandlers(options) {
|
|
409
407
|
installPlatformTransport();
|
|
@@ -420,7 +418,7 @@ export function createZiteHandlers(options) {
|
|
|
420
418
|
? hostContextFromProps(request, ctx.props)
|
|
421
419
|
: local
|
|
422
420
|
? hostContextFromLocal(request, local)
|
|
423
|
-
: hostContextFromRequest(request, options.
|
|
421
|
+
: hostContextFromRequest(request, options.provider);
|
|
424
422
|
if (mounted)
|
|
425
423
|
host.user = userOfIdentity(mounted.signedIn.user);
|
|
426
424
|
// The platform walls internal apps before dispatch; this is the same wall again, before any app code.
|
|
@@ -6,5 +6,8 @@ export type RunReport = {
|
|
|
6
6
|
};
|
|
7
7
|
/** The report in as few sends as fit under the runs service's limit, each record whole. */
|
|
8
8
|
export declare const reportSends: (report: RunReport) => RunReport[];
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* One report of the request's run; the caller keeps it going past the response with `waitUntil`. A request the host
|
|
11
|
+
* dispatched without a runs URL or a token has nowhere to send it, which the throw says.
|
|
12
|
+
*/
|
|
10
13
|
export declare const sendRunReport: (host: HostRequestState, report: RunReport) => Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// What a request reports of its own run: what ran, the platform calls it made and its outbound fetches with what its
|
|
2
2
|
// own AI keys used. On the app token to the platform's runs service, which stamps the org, app and request from the
|
|
3
|
-
// token, never from the report
|
|
4
|
-
//
|
|
3
|
+
// token, never from the report. `local` keeps none: only the platform writes a run's row, and a dev token names no
|
|
4
|
+
// request of its own.
|
|
5
5
|
import { platformFetch } from "../internal/platformFetch.js";
|
|
6
6
|
// Half of what the runs service reads in one send; each record is capped far below it.
|
|
7
7
|
const MAX_SEND_BYTES = 512 * 1024;
|
|
@@ -55,20 +55,17 @@ const toRunsService = async (host, runs, token, report) => {
|
|
|
55
55
|
if (refused)
|
|
56
56
|
throw new Error(`the runs service answered ${refused.status}`);
|
|
57
57
|
};
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* One report of the request's run; the caller keeps it going past the response with `waitUntil`. A request the host
|
|
60
|
+
* dispatched without a runs URL or a token has nowhere to send it, which the throw says.
|
|
61
|
+
*/
|
|
59
62
|
export const sendRunReport = async (host, report) => {
|
|
60
|
-
const { provider
|
|
61
|
-
if (provider
|
|
63
|
+
const { provider } = host;
|
|
64
|
+
if (!provider || provider.kind === "local")
|
|
62
65
|
return;
|
|
63
|
-
const runs = provider
|
|
64
|
-
const token = runs ? await provider
|
|
65
|
-
if (runs
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return;
|
|
69
|
-
// Only a session takes calls and fetches, which a request on the app token may have made without opening one.
|
|
70
|
-
if (report.calls?.length || report.fetches?.length)
|
|
71
|
-
host.session ??= Promise.resolve(platform.session());
|
|
72
|
-
const session = host.session ? await host.session : undefined;
|
|
73
|
-
await (session ? session.runs(report) : platform.runs(report));
|
|
66
|
+
const runs = provider.urls?.runs;
|
|
67
|
+
const token = runs ? await provider.token() : undefined;
|
|
68
|
+
if (!runs || !token)
|
|
69
|
+
throw new Error("This request has no runs URL or app token to send its run's detail with");
|
|
70
|
+
return toRunsService(host, runs, token, report);
|
|
74
71
|
};
|
|
@@ -50,10 +50,7 @@ export type PlatformCallInput = {
|
|
|
50
50
|
/** The access decision the call ran under; the platform may narrow on it but never widens. */
|
|
51
51
|
access: AccessKind;
|
|
52
52
|
};
|
|
53
|
-
/**
|
|
54
|
-
* A call's answer. Errors come back as values: Workers RPC keeps a thrown
|
|
55
|
-
* error's message but drops its code.
|
|
56
|
-
*/
|
|
53
|
+
/** A call's answer. Errors come back as values, so the one the app sees keeps its code. */
|
|
57
54
|
export type PlatformCallResult = {
|
|
58
55
|
value: unknown;
|
|
59
56
|
} | {
|
|
@@ -96,38 +93,6 @@ export type FetchRecord = {
|
|
|
96
93
|
/** What a call on the org's own AI key used, for analytics. */
|
|
97
94
|
ai?: AiUsageRecord;
|
|
98
95
|
};
|
|
99
|
-
export type PlatformSession = {
|
|
100
|
-
call(call: PlatformCallInput): Promise<PlatformCallResult>;
|
|
101
|
-
/** As `PlatformBinding.runs`, on a session the request already holds, with its data calls and fetches. */
|
|
102
|
-
runs(batch: {
|
|
103
|
-
runs: RunRecord[];
|
|
104
|
-
calls?: CallRecord[];
|
|
105
|
-
fetches?: FetchRecord[];
|
|
106
|
-
}): Promise<void>;
|
|
107
|
-
/** After a provider answered 401: the connection refreshed, as `integrations.get` now answers it. */
|
|
108
|
-
refreshConnection(name: string): Promise<PlatformCallResult>;
|
|
109
|
-
/** A call on Zite's own AI key, which the host makes with the real key: for a request with no token or gateway. */
|
|
110
|
-
aiFetch(request: Request): Promise<Response>;
|
|
111
|
-
/** The build's base and SDK names, which the app's data dispatch translates against. */
|
|
112
|
-
dataContext(): Promise<{
|
|
113
|
-
baseId: string | null;
|
|
114
|
-
nameMappings: unknown;
|
|
115
|
-
}>;
|
|
116
|
-
/** One base-runner request; the host holds it to the build's base and adds the key and acting user. */
|
|
117
|
-
dataFetch(request: {
|
|
118
|
-
method: string;
|
|
119
|
-
path: string;
|
|
120
|
-
body?: string;
|
|
121
|
-
}): Promise<Response>;
|
|
122
|
-
/** An integration's settings as the build declares them; null for one it doesn't, or that runs on the platform. */
|
|
123
|
-
integrationSettings(integrationId: string): Promise<{
|
|
124
|
-
serviceType: string;
|
|
125
|
-
baseId?: string;
|
|
126
|
-
nameMappings?: unknown;
|
|
127
|
-
} | null>;
|
|
128
|
-
/** A new app token for this request, when the one it holds is about to expire. */
|
|
129
|
-
appToken?(): Promise<string>;
|
|
130
|
-
};
|
|
131
96
|
/**
|
|
132
97
|
* Where the platform's services answer this app: `aiGateway` takes calls on Zite's AI key, `runs` a live page's
|
|
133
98
|
* analytics and each request's run detail. `email`, `pdf`, `uploads` (the upload session) and `steps` (a workflow
|
|
@@ -155,14 +120,13 @@ export type PlatformProvider = {
|
|
|
155
120
|
user(): User | null;
|
|
156
121
|
urls: PlatformUrls | undefined;
|
|
157
122
|
};
|
|
158
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* What the host hands each request beside its app token: the token's renewal, for an answer that outlives the one it
|
|
125
|
+
* was dispatched with. Its presence in props is what marks a request the host dispatched.
|
|
126
|
+
*/
|
|
159
127
|
export type PlatformBinding = {
|
|
160
|
-
/**
|
|
161
|
-
|
|
162
|
-
/** One batch per request, after its response has ended. */
|
|
163
|
-
runs(batch: {
|
|
164
|
-
runs: RunRecord[];
|
|
165
|
-
}): Promise<void>;
|
|
128
|
+
/** The request's app token, signed again when it's about to expire; null once it can't be. */
|
|
129
|
+
appToken(): Promise<string | null>;
|
|
166
130
|
};
|
|
167
131
|
/** A demo is the published build serving a read-only visitor: as live, but every write is refused. */
|
|
168
132
|
export type HostMode = "live" | "preview" | "demo" | "validate";
|
|
@@ -189,6 +153,13 @@ export type PagePlan = {
|
|
|
189
153
|
short_name: string;
|
|
190
154
|
} | null;
|
|
191
155
|
};
|
|
156
|
+
/** `ZiteMeta.getWorkspace()`'s answer: where the app and its workspace are in Zite. */
|
|
157
|
+
export type ZiteWorkspace = {
|
|
158
|
+
workspaceHomeUrl: string;
|
|
159
|
+
editorUrl: string;
|
|
160
|
+
appPublicIdentifier: string;
|
|
161
|
+
projectPublicIdentifier: string;
|
|
162
|
+
};
|
|
192
163
|
/** A marketplace demo's listing, which the platform's runtime shows the visitor. */
|
|
193
164
|
export type DemoListing = {
|
|
194
165
|
listingSlug: string;
|
|
@@ -262,6 +233,13 @@ export type HostProps = {
|
|
|
262
233
|
page?: HostPage;
|
|
263
234
|
/** The app's access mode, from the platform's records: an internal app serves no page or call to nobody. */
|
|
264
235
|
accessMode?: "internal" | "external";
|
|
236
|
+
/** `ZiteMeta.getWorkspace()`'s answer, from the build's config; absent for a build published before it was kept. */
|
|
237
|
+
workspace?: ZiteWorkspace;
|
|
238
|
+
/**
|
|
239
|
+
* `integrations.get`'s answers, by connection name, real as classic's, when the host already loaded them for the
|
|
240
|
+
* request: a registration's one connection, and none for a demo. Without them the app asks the backend on its token.
|
|
241
|
+
*/
|
|
242
|
+
connections?: Record<string, Record<string, unknown>>;
|
|
265
243
|
};
|
|
266
244
|
/** What the host resolved for this request. Set by the generated server entry, never by the browser. */
|
|
267
245
|
export type HostRequestState = {
|
|
@@ -301,20 +279,24 @@ export type HostRequestState = {
|
|
|
301
279
|
airtableReads?: Map<string, Promise<unknown>>;
|
|
302
280
|
/** Records still reading a copy of a body; the flush waits for them. */
|
|
303
281
|
pending?: Promise<void>[];
|
|
304
|
-
platform?: PlatformBinding;
|
|
305
|
-
session?: Promise<PlatformSession>;
|
|
306
282
|
provider?: PlatformProvider;
|
|
307
283
|
/** The request context's, which keeps a send going after the response. */
|
|
308
284
|
waitUntil?: (promise: Promise<unknown>) => void;
|
|
309
|
-
/** This request's
|
|
285
|
+
/** This request's base-runner calls in flight, capped as the host once capped them; base-runner's per-app bucket bounds the app. */
|
|
310
286
|
dataSlots?: {
|
|
311
287
|
data: () => Promise<() => void>;
|
|
312
288
|
sql: () => Promise<() => void>;
|
|
313
289
|
};
|
|
314
|
-
/** This request's calls on Zite's AI key waiting on the gateway's answer, capped as the host
|
|
290
|
+
/** This request's calls on Zite's AI key waiting on the gateway's answer, capped as the host once capped them. */
|
|
315
291
|
aiSlots?: () => Promise<() => void>;
|
|
316
292
|
/** This request's router, so a page's status can follow the error it rendered. */
|
|
317
293
|
router?: unknown;
|
|
318
294
|
/** The platform's head entries for its pages; unset when the host writes them itself. */
|
|
319
295
|
head?: PlatformHead;
|
|
296
|
+
workspace?: ZiteWorkspace;
|
|
297
|
+
connections?: Record<string, Record<string, unknown>>;
|
|
298
|
+
/** The backend's connections, asked once this request when the host didn't hand them over. */
|
|
299
|
+
connectionsLoad?: Promise<{
|
|
300
|
+
connections: Record<string, Record<string, unknown>>;
|
|
301
|
+
}>;
|
|
320
302
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ZITEJS_VERSION = "0.10.0-start.
|
|
1
|
+
export declare const ZITEJS_VERSION = "0.10.0-start.23";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Written by scripts/write-version.mjs from package.json.
|
|
2
|
-
export const ZITEJS_VERSION = "0.10.0-start.
|
|
2
|
+
export const ZITEJS_VERSION = "0.10.0-start.23";
|
package/dist/esm/start/vite.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { type PluginOption } from "vite";
|
|
2
2
|
import type { ZiteSchema } from "../sync/lib.js";
|
|
3
|
+
import { type SchemaNames } from "../sync/sdkNames.js";
|
|
4
|
+
import { type BuiltAirtableSettings } from "./airtable/settings.js";
|
|
3
5
|
import type { DataNameMappings } from "./data/types.js";
|
|
4
|
-
/** @internal
|
|
6
|
+
/** @internal The workspace's zite.schema.json as a server build carries it; null without one, a throw for one it can't read. */
|
|
7
|
+
export declare const workspaceSchemaNamesOf: (appDir: string) => SchemaNames | null;
|
|
8
|
+
/** @internal The app's Airtable integrations, from its own and its workspace's zite.config.json and zite.lock. */
|
|
9
|
+
export declare const builtAirtableSettingsOf: (appDir: string) => Record<string, BuiltAirtableSettings>;
|
|
10
|
+
/** @internal A workspace's zite.schema.json as the platform's `nameMappings`: the SDK names `.zite/db.ts` was generated with. */
|
|
5
11
|
export declare const workspaceNameMappingsOf: (raw: ZiteSchema) => DataNameMappings;
|
|
6
12
|
/**
|
|
7
13
|
* @internal The sign-in settings `zitejs dev` wrote for the app, for the module `local` mounts; null without them, or
|
package/dist/esm/start/vite.js
CHANGED
|
@@ -5,7 +5,9 @@ import { parse as parseEnv } from "dotenv";
|
|
|
5
5
|
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
|
|
6
6
|
import viteReact from "@vitejs/plugin-react";
|
|
7
7
|
import { ziteId } from "../vite/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { schemaNamesOf } from "../sync/sdkNames.js";
|
|
9
|
+
import { nameMappingsOf } from "./data/names.js";
|
|
10
|
+
import { airtableSettingsFrom } from "./airtable/settings.js";
|
|
9
11
|
import { factoryDescriptions } from "./descriptions.js";
|
|
10
12
|
import { registrationHashes } from "./registrationHash.js";
|
|
11
13
|
import { hasAppStart, renderStartInstance, renderStartServerEntry, renderWorkflowModules, START_INSTANCE_ENTRY, START_SERVER_ENTRY, workflowFiles, writeIfChanged, } from "./entries.js";
|
|
@@ -21,9 +23,15 @@ const WORKFLOW_REGISTRY = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]workflowMo
|
|
|
21
23
|
// zitejs's null auth-hooks module, which the build points at the app's `zite.auth.ts`.
|
|
22
24
|
const AUTH_HOOKS_REGISTRY = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]authHooksModule\.js$/;
|
|
23
25
|
const AUTH_HOOKS_FILE = "zite.auth.ts";
|
|
24
|
-
// zitejs's null workspace names, which `vite dev`
|
|
26
|
+
// zitejs's null workspace names, which a server build and `vite dev` fill from the workspace root, where `zitejs/db`
|
|
27
|
+
// comes from too.
|
|
25
28
|
const WORKSPACE_SCHEMA_MODULE = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]workspaceSchema\.js$/;
|
|
26
29
|
const WORKSPACE_SCHEMA_FILE = "../../zite.schema.json";
|
|
30
|
+
// zitejs's null Airtable settings, which a server build and `vite dev` fill from the app's and the workspace's config.
|
|
31
|
+
const AIRTABLE_SETTINGS_MODULE = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]airtable[\\/]built\.js$/;
|
|
32
|
+
const APP_LOCK_FILE = "zite.lock";
|
|
33
|
+
const WORKSPACE_CONFIG_FILE = "../../zite.config.json";
|
|
34
|
+
const WORKSPACE_LOCK_FILE = "../../zite.lock";
|
|
27
35
|
// zitejs's null app id, which `vite dev` fills from the app's zite.config.json.
|
|
28
36
|
const DEV_APP_MODULE = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]devApp\.js$/;
|
|
29
37
|
// zitejs's null sign-in settings, which `vite dev` fills from the `.zite/dev.env` that `zitejs dev` writes.
|
|
@@ -41,16 +49,37 @@ const SOURCE_LANGS = {
|
|
|
41
49
|
".cjs": "js",
|
|
42
50
|
".jsx": "jsx",
|
|
43
51
|
};
|
|
44
|
-
/** @internal
|
|
45
|
-
export const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
/** @internal The workspace's zite.schema.json as a server build carries it; null without one, a throw for one it can't read. */
|
|
53
|
+
export const workspaceSchemaNamesOf = (appDir) => {
|
|
54
|
+
const file = path.join(appDir, WORKSPACE_SCHEMA_FILE);
|
|
55
|
+
if (!existsSync(file))
|
|
56
|
+
return null;
|
|
57
|
+
try {
|
|
58
|
+
return schemaNamesOf(JSON.parse(readFileSync(file, "utf-8")));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new Error(`[zite] the workspace's zite.schema.json can't be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
// As the platform reads them: a file that isn't there or isn't JSON is none.
|
|
65
|
+
const readJson = (file) => {
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(readFileSync(file, "utf-8"));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/** @internal The app's Airtable integrations, from its own and its workspace's zite.config.json and zite.lock. */
|
|
74
|
+
export const builtAirtableSettingsOf = (appDir) => airtableSettingsFrom({
|
|
75
|
+
appConfig: readJson(path.join(appDir, APP_CONFIG_FILE)),
|
|
76
|
+
appLock: readJson(path.join(appDir, APP_LOCK_FILE)),
|
|
77
|
+
workspaceConfig: readJson(path.join(appDir, WORKSPACE_CONFIG_FILE)),
|
|
78
|
+
workspaceLock: readJson(path.join(appDir, WORKSPACE_LOCK_FILE)),
|
|
79
|
+
hasSchema: existsSync(path.join(appDir, WORKSPACE_SCHEMA_FILE)),
|
|
53
80
|
});
|
|
81
|
+
/** @internal A workspace's zite.schema.json as the platform's `nameMappings`: the SDK names `.zite/db.ts` was generated with. */
|
|
82
|
+
export const workspaceNameMappingsOf = (raw) => nameMappingsOf(schemaNamesOf(raw));
|
|
54
83
|
/**
|
|
55
84
|
* @internal The sign-in settings `zitejs dev` wrote for the app, for the module `local` mounts; null without them, or
|
|
56
85
|
* when the app's env sets `ZITE_DEV_USER`, whose stand-in wins.
|
|
@@ -235,24 +264,41 @@ export function zite(options = {}) {
|
|
|
235
264
|
: "export const authHooksModule = null;\n";
|
|
236
265
|
},
|
|
237
266
|
};
|
|
238
|
-
//
|
|
267
|
+
// The names the build's `zitejs/db` was generated with, from the same commit's schema. Only the server's: a browser
|
|
268
|
+
// never translates a data call, and its bundle carries no table or field id.
|
|
269
|
+
let serving = false;
|
|
239
270
|
const workspaceSchema = {
|
|
240
271
|
name: "zite:workspace-schema",
|
|
241
|
-
|
|
272
|
+
configResolved(config) {
|
|
273
|
+
serving = config.command === "serve";
|
|
274
|
+
},
|
|
242
275
|
load(id) {
|
|
243
276
|
if (!WORKSPACE_SCHEMA_MODULE.test(id.split("?")[0]))
|
|
244
277
|
return undefined;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
let mappings = null;
|
|
278
|
+
this.addWatchFile(path.join(appDir, WORKSPACE_SCHEMA_FILE));
|
|
279
|
+
let names = null;
|
|
248
280
|
try {
|
|
249
|
-
if (
|
|
250
|
-
|
|
281
|
+
if (this.environment?.config.consumer === "server")
|
|
282
|
+
names = workspaceSchemaNamesOf(appDir);
|
|
251
283
|
}
|
|
252
|
-
catch {
|
|
253
|
-
//
|
|
284
|
+
catch (error) {
|
|
285
|
+
// A build fails rather than ship names its client wasn't written against; `vite dev` carries on mid-edit.
|
|
286
|
+
if (!serving)
|
|
287
|
+
throw error;
|
|
254
288
|
}
|
|
255
|
-
return `export const
|
|
289
|
+
return `export const workspaceSchemaNames = ${JSON.stringify(names)};\n`;
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
// The integrations the app runs itself, from the same commit's config, and only on the server, which calls them.
|
|
293
|
+
const airtableSettings = {
|
|
294
|
+
name: "zite:airtable-settings",
|
|
295
|
+
load(id) {
|
|
296
|
+
if (!AIRTABLE_SETTINGS_MODULE.test(id.split("?")[0]))
|
|
297
|
+
return undefined;
|
|
298
|
+
for (const file of [APP_CONFIG_FILE, APP_LOCK_FILE, WORKSPACE_CONFIG_FILE, WORKSPACE_LOCK_FILE])
|
|
299
|
+
this.addWatchFile(path.join(appDir, file));
|
|
300
|
+
const settings = this.environment?.config.consumer === "server" ? builtAirtableSettingsOf(appDir) : null;
|
|
301
|
+
return `export const builtAirtableSettings = ${JSON.stringify(settings)};\n`;
|
|
256
302
|
},
|
|
257
303
|
};
|
|
258
304
|
// Under `vite dev` only: a published build is never `local`'s to mint for.
|
|
@@ -323,6 +369,7 @@ export function zite(options = {}) {
|
|
|
323
369
|
workflowRegistry,
|
|
324
370
|
authHooksRegistry,
|
|
325
371
|
workspaceSchema,
|
|
372
|
+
airtableSettings,
|
|
326
373
|
devApp,
|
|
327
374
|
devSignIn,
|
|
328
375
|
];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { SchemaNames } from "../sync/sdkNames.js";
|
|
2
|
+
export declare const workspaceSchemaNames: SchemaNames | null;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
// Null as published.
|
|
2
|
-
// zite.schema.json
|
|
3
|
-
export const
|
|
1
|
+
// Null as published. `zite()` replaces this module, in a server build and under `vite dev`, with the names in the
|
|
2
|
+
// workspace's zite.schema.json: the ones the build's generated client was written against.
|
|
3
|
+
export const workspaceSchemaNames = null;
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { parse } from "@babel/parser";
|
|
2
|
-
import {
|
|
2
|
+
import { allocateLiveNames, AUTH_USERS_TABLE_ID, describeRenames, normalizeSchemaNames, SdkNameAllocator, toCamelCase, toPascalCase, } from "./sdkNames.js";
|
|
3
3
|
import { CREDENTIAL_FIELDS, OPTIONAL_CREDENTIAL_FIELDS, } from "../integrations/rules.js";
|
|
4
|
-
const AUTH_USERS_TABLE_ID = "zite_user";
|
|
5
4
|
/**
|
|
6
5
|
* What a field's value looks like when a record is READ back.
|
|
7
6
|
*
|
|
@@ -338,62 +337,36 @@ function fieldJsdoc(schemaField, table, schema) {
|
|
|
338
337
|
* name stability across schema changes.
|
|
339
338
|
*/
|
|
340
339
|
export function generateSchema(database, existingSchema) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const existingTable = existingTableById.get(table.id);
|
|
350
|
-
const existingFieldById = new Map();
|
|
351
|
-
for (const f of existingTable?.fields ?? []) {
|
|
352
|
-
existingFieldById.set(f.id, f);
|
|
340
|
+
// A name from the existing schema is locked: it is what the app is compiling
|
|
341
|
+
// against, and only moves if it is reserved or collides.
|
|
342
|
+
const { names, renames } = allocateLiveNames(database.tables, existingSchema);
|
|
343
|
+
if (renames.length > 0) {
|
|
344
|
+
// Never silent: a rename means the accessor a developer would reach for is
|
|
345
|
+
// not the one that got emitted.
|
|
346
|
+
for (const line of describeRenames(renames)) {
|
|
347
|
+
console.warn(`[zitejs] SDK name collision resolved: ${line}`);
|
|
353
348
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const
|
|
360
|
-
const { id: _id, order: _order, ...definition } = field;
|
|
349
|
+
}
|
|
350
|
+
const liveTables = new Map(database.tables.map((table) => [table.id, table]));
|
|
351
|
+
return {
|
|
352
|
+
tables: names.tables.map((named) => {
|
|
353
|
+
const table = liveTables.get(named.id);
|
|
354
|
+
const liveFields = new Map(table.fields.map((field) => [field.id, field]));
|
|
361
355
|
return {
|
|
362
|
-
field: { id: field.id, sdkName: "", definition },
|
|
363
|
-
draft: {
|
|
364
|
-
preferred: existing ?? toSdkName(field.name),
|
|
365
|
-
locked: existing !== undefined,
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
});
|
|
369
|
-
const existingName = keepValidSdkName(existingTable?.sdkName);
|
|
370
|
-
drafts.push({
|
|
371
|
-
table: {
|
|
372
356
|
id: table.id,
|
|
373
|
-
sdkName:
|
|
357
|
+
sdkName: named.sdkName,
|
|
374
358
|
// Always the live name — never `existingTable?.name`. Locking it the way
|
|
375
359
|
// `sdkName` is locked would freeze it at the first name the table ever
|
|
376
360
|
// had, which is the one thing this is here to avoid.
|
|
377
361
|
name: table.name,
|
|
378
362
|
primaryFieldId: table.primaryFieldId,
|
|
379
|
-
fields:
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
const { tables, renames } = allocateSchemaNames(drafts);
|
|
389
|
-
if (renames.length > 0) {
|
|
390
|
-
// Never silent: a rename means the accessor a developer would reach for is
|
|
391
|
-
// not the one that got emitted.
|
|
392
|
-
for (const line of describeRenames(renames)) {
|
|
393
|
-
console.warn(`[zitejs] SDK name collision resolved: ${line}`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return { tables };
|
|
363
|
+
fields: named.fields.map((namedField) => {
|
|
364
|
+
const { id, order: _order, ...definition } = liveFields.get(namedField.id);
|
|
365
|
+
return { id, sdkName: namedField.sdkName, definition };
|
|
366
|
+
}),
|
|
367
|
+
};
|
|
368
|
+
}),
|
|
369
|
+
};
|
|
397
370
|
}
|
|
398
371
|
function generateSentinelSdkTypes() {
|
|
399
372
|
return [
|