zitejs 0.10.0-start.21 → 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/auth/client.d.ts +2 -2
- package/dist/cjs/check/start/sourceRules.js +3 -0
- package/dist/cjs/cli.js +6 -0
- package/dist/cjs/dev/index.js +15 -0
- package/dist/cjs/dev/signin.d.ts +16 -0
- package/dist/cjs/dev/signin.js +76 -0
- package/dist/cjs/internal/appMode.d.ts +11 -0
- package/dist/cjs/internal/appMode.js +4 -1
- package/dist/cjs/internal/appToken.d.ts +17 -0
- package/dist/cjs/internal/appToken.js +26 -0
- package/dist/cjs/internal/platformFetch.d.ts +2 -0
- package/dist/cjs/internal/platformFetch.js +13 -0
- package/dist/cjs/internal/serviceUrls.d.ts +7 -0
- package/dist/cjs/internal/serviceUrls.js +16 -0
- package/dist/cjs/runtime/index.d.ts +1 -1
- package/dist/cjs/start/aiUsage.d.ts +23 -0
- package/dist/cjs/start/aiUsage.js +151 -0
- package/dist/cjs/start/devApp.d.ts +1 -0
- package/dist/cjs/start/devApp.js +6 -0
- package/dist/cjs/start/entries.js +4 -0
- package/dist/cjs/start/provider.d.ts +24 -0
- package/dist/cjs/start/provider.js +159 -0
- package/dist/cjs/start/types.d.ts +302 -0
- package/dist/cjs/start/types.js +2 -0
- 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/cjs/upload/index.js +73 -22
- package/dist/cjs/upload/index.test.js +35 -2
- package/dist/esm/auth/client.d.ts +2 -2
- package/dist/esm/check/start/sourceRules.js +3 -0
- package/dist/esm/cli.js +6 -0
- package/dist/esm/dev/index.js +15 -0
- package/dist/esm/dev/signin.d.ts +16 -0
- package/dist/esm/dev/signin.js +72 -0
- package/dist/esm/internal/appMode.d.ts +11 -0
- package/dist/esm/internal/appMode.js +2 -0
- package/dist/esm/internal/appToken.d.ts +17 -0
- package/dist/esm/internal/appToken.js +22 -0
- package/dist/esm/internal/platformFetch.d.ts +2 -0
- package/dist/esm/internal/platformFetch.js +8 -0
- package/dist/esm/internal/serviceUrls.d.ts +7 -0
- package/dist/esm/internal/serviceUrls.js +12 -0
- package/dist/esm/runtime/index.d.ts +1 -1
- package/dist/esm/signin/conformance.d.ts +100 -0
- package/dist/esm/signin/conformance.js +471 -0
- package/dist/esm/signin/cookies.d.ts +28 -0
- package/dist/esm/signin/cookies.js +59 -0
- package/dist/esm/signin/encoding.d.ts +9 -0
- package/dist/esm/signin/encoding.js +39 -0
- package/dist/esm/signin/endpoints.d.ts +12 -0
- package/dist/esm/signin/endpoints.js +29 -0
- package/dist/esm/signin/http.d.ts +25 -0
- package/dist/esm/signin/http.js +69 -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 +39 -0
- package/dist/esm/signin/keys.js +80 -0
- package/dist/esm/signin/paths.d.ts +2 -0
- package/dist/esm/signin/paths.js +2 -0
- package/dist/esm/signin/seal.d.ts +8 -0
- package/dist/esm/signin/seal.js +35 -0
- package/dist/esm/signin/signin.d.ts +60 -0
- package/dist/esm/signin/signin.js +340 -0
- package/dist/esm/signin/transport.d.ts +111 -0
- package/dist/esm/signin/transport.js +1 -0
- package/dist/esm/signin/verify.d.ts +77 -0
- package/dist/esm/signin/verify.js +155 -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/analytics.d.ts +5 -0
- package/dist/esm/start/analytics.js +77 -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/devApp.d.ts +1 -0
- package/dist/esm/start/devApp.js +3 -0
- package/dist/esm/start/devSignIn.d.ts +1 -0
- package/dist/esm/start/devSignIn.js +3 -0
- package/dist/esm/start/direct.d.ts +44 -0
- package/dist/esm/start/direct.js +442 -0
- package/dist/esm/start/entries.js +4 -0
- package/dist/esm/start/fetch.d.ts +1 -0
- package/dist/esm/start/fetch.js +4 -0
- package/dist/esm/start/instance.js +6 -2
- package/dist/esm/start/localSignIn.d.ts +18 -0
- package/dist/esm/start/localSignIn.js +73 -0
- package/dist/esm/start/outbound.d.ts +9 -1
- package/dist/esm/start/outbound.js +130 -31
- package/dist/esm/start/pageHead.d.ts +36 -0
- package/dist/esm/start/pageHead.js +178 -0
- package/dist/esm/start/provider.d.ts +24 -0
- package/dist/esm/start/provider.js +150 -0
- package/dist/esm/start/router.d.ts +6 -2
- package/dist/esm/start/router.js +41 -2
- package/dist/esm/start/server.d.ts +23 -12
- package/dist/esm/start/server.js +185 -56
- package/dist/esm/start/telemetry.d.ts +13 -0
- package/dist/esm/start/telemetry.js +71 -0
- package/dist/esm/start/types.d.ts +141 -44
- package/dist/esm/start/uploads.d.ts +2 -0
- package/dist/esm/start/uploads.js +52 -0
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/dist/esm/start/vite.d.ts +18 -1
- package/dist/esm/start/vite.js +163 -4
- package/dist/esm/start/workspaceSchema.d.ts +2 -0
- package/dist/esm/start/workspaceSchema.js +3 -0
- 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/dist/esm/upload/index.js +74 -23
- package/dist/esm/upload/index.test.js +35 -2
- package/package.json +22 -12
- package/dist/cjs/auth-server/index.d.ts +0 -369
- package/dist/cjs/auth-server/index.js +0 -119
- package/dist/esm/auth-server/index.d.ts +0 -369
- package/dist/esm/auth-server/index.js +0 -116
- package/dist/esm/start/problems.d.ts +0 -19
- package/dist/esm/start/problems.js +0 -8
|
@@ -79,20 +79,28 @@ export declare class SdkNameAllocator {
|
|
|
79
79
|
private readonly taken;
|
|
80
80
|
private readonly reserved;
|
|
81
81
|
private readonly derive;
|
|
82
|
+
private readonly fold?;
|
|
83
|
+
private readonly folded;
|
|
82
84
|
constructor(opts?: {
|
|
83
85
|
reserved?: readonly string[];
|
|
84
86
|
derive?: (name: string) => string[];
|
|
87
|
+
/**
|
|
88
|
+
* The key under which two names are the same to something downstream,
|
|
89
|
+
* which a fresh name must not share with one already claimed.
|
|
90
|
+
*/
|
|
91
|
+
fold?: (name: string) => string;
|
|
85
92
|
});
|
|
86
93
|
private keysFor;
|
|
87
94
|
private isFree;
|
|
88
95
|
/** Free right now, without claiming it. */
|
|
89
|
-
available(name: string): boolean;
|
|
96
|
+
available(name: string, fresh?: boolean): boolean;
|
|
90
97
|
private claim;
|
|
91
98
|
/**
|
|
92
99
|
* `name`, or the first `name2`, `name3`… that is free. Suffixes start at 2
|
|
93
100
|
* because that is what the name means: the second table called Notifications.
|
|
101
|
+
* A `fresh` name also steers clear of every claimed name's `fold`.
|
|
94
102
|
*/
|
|
95
|
-
allocate(preferred: string): string;
|
|
103
|
+
allocate(preferred: string, fresh?: boolean): string;
|
|
96
104
|
}
|
|
97
105
|
/**
|
|
98
106
|
* Existing sdkNames are preserved across syncs so user code keeps compiling,
|
|
@@ -113,23 +121,38 @@ interface NameDraft {
|
|
|
113
121
|
*/
|
|
114
122
|
locked: boolean;
|
|
115
123
|
}
|
|
116
|
-
export interface
|
|
117
|
-
table:
|
|
124
|
+
export interface NameDraftOf<T, F> {
|
|
125
|
+
table: T;
|
|
118
126
|
draft: NameDraft;
|
|
119
127
|
fields: Array<{
|
|
120
|
-
field:
|
|
128
|
+
field: F;
|
|
121
129
|
draft: NameDraft;
|
|
122
130
|
}>;
|
|
123
131
|
}
|
|
132
|
+
export type SchemaNameDraft = NameDraftOf<ZiteSchemaTable, ZiteSchemaField>;
|
|
124
133
|
/**
|
|
125
134
|
* Resolve every drafted name to a unique, unreserved one.
|
|
126
135
|
*
|
|
127
136
|
* Two passes per namespace: locked names claim first in declaration order, then
|
|
128
137
|
* fresh ones fill in around them. Without that ordering a new table could take
|
|
129
138
|
* an accessor an existing app already imports.
|
|
139
|
+
*
|
|
140
|
+
* A fresh name also differs from every other name ignoring case, as base-runner's
|
|
141
|
+
* SQL resolver tells names apart: it refuses a whole base when two differ only
|
|
142
|
+
* by case. Fields compare by their sdkName, tables by the class name the client
|
|
143
|
+
* sends. Locked names keep theirs even when they already clash.
|
|
130
144
|
*/
|
|
131
|
-
export declare function allocateSchemaNames
|
|
132
|
-
|
|
145
|
+
export declare function allocateSchemaNames<T extends {
|
|
146
|
+
id: string;
|
|
147
|
+
}, F extends {
|
|
148
|
+
id: string;
|
|
149
|
+
}>(drafts: NameDraftOf<T, F>[]): {
|
|
150
|
+
tables: Array<Omit<T, "sdkName" | "fields"> & {
|
|
151
|
+
sdkName: string;
|
|
152
|
+
fields: Array<Omit<F, "sdkName"> & {
|
|
153
|
+
sdkName: string;
|
|
154
|
+
}>;
|
|
155
|
+
}>;
|
|
133
156
|
renames: SdkNameRename[];
|
|
134
157
|
};
|
|
135
158
|
/**
|
|
@@ -141,6 +164,41 @@ export declare function normalizeSchemaNames(schema: ZiteSchema): {
|
|
|
141
164
|
schema: ZiteSchema;
|
|
142
165
|
renames: SdkNameRename[];
|
|
143
166
|
};
|
|
167
|
+
/** A schema's SDK names alone, keyed by id, as a server build carries them. */
|
|
168
|
+
export interface SchemaNames {
|
|
169
|
+
tables: Array<{
|
|
170
|
+
id: string;
|
|
171
|
+
sdkName: string;
|
|
172
|
+
fields: Array<{
|
|
173
|
+
id: string;
|
|
174
|
+
sdkName: string;
|
|
175
|
+
}>;
|
|
176
|
+
}>;
|
|
177
|
+
}
|
|
178
|
+
/** The names `generateDbTs` emits for a schema, without its definitions. */
|
|
179
|
+
export declare function schemaNamesOf(schema: ZiteSchema): SchemaNames;
|
|
180
|
+
/** The table `generateDbTs` never emits a client for: Zite's own users, read through `zite.auth`. */
|
|
181
|
+
export declare const AUTH_USERS_TABLE_ID = "zite_user";
|
|
182
|
+
/** A table as base-runner lists it, which both `zitejs generate` and a running build read. */
|
|
183
|
+
export interface LiveTable {
|
|
184
|
+
id: string;
|
|
185
|
+
name: string;
|
|
186
|
+
deletedAt?: unknown;
|
|
187
|
+
fields: ReadonlyArray<{
|
|
188
|
+
id: string;
|
|
189
|
+
name: string;
|
|
190
|
+
deletedAt?: unknown;
|
|
191
|
+
}>;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The SDK names for a base's tables as they are now: `existing`'s name for every id it knows, locked, and a fresh one
|
|
195
|
+
* from `toSdkName` for each table or field it doesn't. `zitejs generate` writes these into zite.schema.json, and a
|
|
196
|
+
* running build fills in what was added since it was built with the same, so the two can't drift.
|
|
197
|
+
*/
|
|
198
|
+
export declare function allocateLiveNames(live: readonly LiveTable[], existing?: SchemaNames): {
|
|
199
|
+
names: SchemaNames;
|
|
200
|
+
renames: SdkNameRename[];
|
|
201
|
+
};
|
|
144
202
|
/** One line per rename, for a generator that has no logger of its own. */
|
|
145
203
|
export declare function describeRenames(renames: SdkNameRename[]): string[];
|
|
146
204
|
export {};
|
|
@@ -111,39 +111,46 @@ export class SdkNameAllocator {
|
|
|
111
111
|
taken = new Set();
|
|
112
112
|
reserved;
|
|
113
113
|
derive;
|
|
114
|
+
fold;
|
|
115
|
+
folded = new Set();
|
|
114
116
|
constructor(opts = {}) {
|
|
115
117
|
this.reserved = new Set([
|
|
116
118
|
...RESERVED_IDENTIFIERS,
|
|
117
119
|
...(opts.reserved ?? []),
|
|
118
120
|
]);
|
|
119
121
|
this.derive = opts.derive ?? (() => []);
|
|
122
|
+
this.fold = opts.fold;
|
|
120
123
|
}
|
|
121
124
|
keysFor(name) {
|
|
122
125
|
return [name, ...this.derive(name)];
|
|
123
126
|
}
|
|
124
|
-
isFree(name) {
|
|
125
|
-
return this.keysFor(name).every((key) => !this.taken.has(key) && !this.reserved.has(key))
|
|
127
|
+
isFree(name, fresh) {
|
|
128
|
+
return (this.keysFor(name).every((key) => !this.taken.has(key) && !this.reserved.has(key)) &&
|
|
129
|
+
!(fresh && this.fold && this.folded.has(this.fold(name))));
|
|
126
130
|
}
|
|
127
131
|
/** Free right now, without claiming it. */
|
|
128
|
-
available(name) {
|
|
129
|
-
return this.isFree(name);
|
|
132
|
+
available(name, fresh = false) {
|
|
133
|
+
return this.isFree(name, fresh);
|
|
130
134
|
}
|
|
131
135
|
claim(name) {
|
|
132
136
|
for (const key of this.keysFor(name))
|
|
133
137
|
this.taken.add(key);
|
|
138
|
+
if (this.fold)
|
|
139
|
+
this.folded.add(this.fold(name));
|
|
134
140
|
return name;
|
|
135
141
|
}
|
|
136
142
|
/**
|
|
137
143
|
* `name`, or the first `name2`, `name3`… that is free. Suffixes start at 2
|
|
138
144
|
* because that is what the name means: the second table called Notifications.
|
|
145
|
+
* A `fresh` name also steers clear of every claimed name's `fold`.
|
|
139
146
|
*/
|
|
140
|
-
allocate(preferred) {
|
|
147
|
+
allocate(preferred, fresh = false) {
|
|
141
148
|
const base = preferred || "_";
|
|
142
|
-
if (this.isFree(base))
|
|
149
|
+
if (this.isFree(base, fresh))
|
|
143
150
|
return this.claim(base);
|
|
144
151
|
for (let suffix = 2; suffix <= MAX_SUFFIX_ATTEMPTS; suffix++) {
|
|
145
152
|
const candidate = `${base}${suffix}`;
|
|
146
|
-
if (this.isFree(candidate))
|
|
153
|
+
if (this.isFree(candidate, fresh))
|
|
147
154
|
return this.claim(candidate);
|
|
148
155
|
}
|
|
149
156
|
// Unreachable: each attempt blocks at most two keys, so a free candidate
|
|
@@ -169,6 +176,11 @@ export function keepValidSdkName(sdkName) {
|
|
|
169
176
|
* Two passes per namespace: locked names claim first in declaration order, then
|
|
170
177
|
* fresh ones fill in around them. Without that ordering a new table could take
|
|
171
178
|
* an accessor an existing app already imports.
|
|
179
|
+
*
|
|
180
|
+
* A fresh name also differs from every other name ignoring case, as base-runner's
|
|
181
|
+
* SQL resolver tells names apart: it refuses a whole base when two differ only
|
|
182
|
+
* by case. Fields compare by their sdkName, tables by the class name the client
|
|
183
|
+
* sends. Locked names keep theirs even when they already clash.
|
|
172
184
|
*/
|
|
173
185
|
export function allocateSchemaNames(drafts) {
|
|
174
186
|
const renames = [];
|
|
@@ -176,6 +188,7 @@ export function allocateSchemaNames(drafts) {
|
|
|
176
188
|
reserved: RESERVED_TABLE_ACCESSORS,
|
|
177
189
|
// The PascalCase form is its own pair of exported declarations.
|
|
178
190
|
derive: (name) => [`type:${toPascalCase(name)}`],
|
|
191
|
+
fold: (name) => toPascalCase(name).toLowerCase(),
|
|
179
192
|
});
|
|
180
193
|
const resolved = new Map();
|
|
181
194
|
for (const pass of [true, false]) {
|
|
@@ -184,7 +197,7 @@ export function allocateSchemaNames(drafts) {
|
|
|
184
197
|
continue;
|
|
185
198
|
if (pass && !tableNames.available(entry.draft.preferred))
|
|
186
199
|
continue;
|
|
187
|
-
const sdkName = tableNames.allocate(entry.draft.preferred);
|
|
200
|
+
const sdkName = tableNames.allocate(entry.draft.preferred, !pass);
|
|
188
201
|
resolved.set(entry.table.id, sdkName);
|
|
189
202
|
if (sdkName !== entry.draft.preferred) {
|
|
190
203
|
renames.push({
|
|
@@ -201,7 +214,7 @@ export function allocateSchemaNames(drafts) {
|
|
|
201
214
|
for (const entry of drafts) {
|
|
202
215
|
if (resolved.has(entry.table.id))
|
|
203
216
|
continue;
|
|
204
|
-
const sdkName = tableNames.allocate(entry.draft.preferred);
|
|
217
|
+
const sdkName = tableNames.allocate(entry.draft.preferred, true);
|
|
205
218
|
resolved.set(entry.table.id, sdkName);
|
|
206
219
|
renames.push({
|
|
207
220
|
kind: "table",
|
|
@@ -213,6 +226,7 @@ export function allocateSchemaNames(drafts) {
|
|
|
213
226
|
const tables = drafts.map((entry) => {
|
|
214
227
|
const fieldNames = new SdkNameAllocator({
|
|
215
228
|
reserved: RESERVED_FIELD_ACCESSORS,
|
|
229
|
+
fold: (name) => name.toLowerCase(),
|
|
216
230
|
});
|
|
217
231
|
const resolvedFields = new Map();
|
|
218
232
|
for (const pass of [true, false]) {
|
|
@@ -221,7 +235,7 @@ export function allocateSchemaNames(drafts) {
|
|
|
221
235
|
continue;
|
|
222
236
|
if (pass && !fieldNames.available(draft.preferred))
|
|
223
237
|
continue;
|
|
224
|
-
const sdkName = fieldNames.allocate(draft.preferred);
|
|
238
|
+
const sdkName = fieldNames.allocate(draft.preferred, !pass);
|
|
225
239
|
resolvedFields.set(field.id, sdkName);
|
|
226
240
|
if (sdkName !== draft.preferred) {
|
|
227
241
|
renames.push({
|
|
@@ -237,7 +251,7 @@ export function allocateSchemaNames(drafts) {
|
|
|
237
251
|
for (const { field, draft } of entry.fields) {
|
|
238
252
|
if (resolvedFields.has(field.id))
|
|
239
253
|
continue;
|
|
240
|
-
const sdkName = fieldNames.allocate(draft.preferred);
|
|
254
|
+
const sdkName = fieldNames.allocate(draft.preferred, true);
|
|
241
255
|
resolvedFields.set(field.id, sdkName);
|
|
242
256
|
renames.push({
|
|
243
257
|
kind: "field",
|
|
@@ -280,6 +294,54 @@ export function normalizeSchemaNames(schema) {
|
|
|
280
294
|
})));
|
|
281
295
|
return { schema: { tables }, renames };
|
|
282
296
|
}
|
|
297
|
+
/** The names `generateDbTs` emits for a schema, without its definitions. */
|
|
298
|
+
export function schemaNamesOf(schema) {
|
|
299
|
+
return {
|
|
300
|
+
tables: normalizeSchemaNames(schema).schema.tables.map((table) => ({
|
|
301
|
+
id: table.id,
|
|
302
|
+
sdkName: table.sdkName,
|
|
303
|
+
fields: table.fields.map((field) => ({
|
|
304
|
+
id: field.id,
|
|
305
|
+
sdkName: field.sdkName,
|
|
306
|
+
})),
|
|
307
|
+
})),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/** The table `generateDbTs` never emits a client for: Zite's own users, read through `zite.auth`. */
|
|
311
|
+
export const AUTH_USERS_TABLE_ID = "zite_user";
|
|
312
|
+
/**
|
|
313
|
+
* The SDK names for a base's tables as they are now: `existing`'s name for every id it knows, locked, and a fresh one
|
|
314
|
+
* from `toSdkName` for each table or field it doesn't. `zitejs generate` writes these into zite.schema.json, and a
|
|
315
|
+
* running build fills in what was added since it was built with the same, so the two can't drift.
|
|
316
|
+
*/
|
|
317
|
+
export function allocateLiveNames(live, existing) {
|
|
318
|
+
const known = new Map(existing?.tables.map((table) => [table.id, table]));
|
|
319
|
+
const drafts = live
|
|
320
|
+
.filter((table) => table.id !== AUTH_USERS_TABLE_ID && !table.deletedAt)
|
|
321
|
+
.map((table) => {
|
|
322
|
+
const knownTable = known.get(table.id);
|
|
323
|
+
const knownFields = new Map(knownTable?.fields.map((field) => [field.id, field.sdkName]));
|
|
324
|
+
const kept = keepValidSdkName(knownTable?.sdkName);
|
|
325
|
+
return {
|
|
326
|
+
table: { id: table.id },
|
|
327
|
+
draft: { preferred: kept ?? toSdkName(table.name), locked: kept !== undefined },
|
|
328
|
+
fields: table.fields
|
|
329
|
+
.filter((field) => !field.deletedAt)
|
|
330
|
+
.map((field) => {
|
|
331
|
+
const keptField = keepValidSdkName(knownFields.get(field.id));
|
|
332
|
+
return {
|
|
333
|
+
field: { id: field.id },
|
|
334
|
+
draft: {
|
|
335
|
+
preferred: keptField ?? toSdkName(field.name),
|
|
336
|
+
locked: keptField !== undefined,
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}),
|
|
340
|
+
};
|
|
341
|
+
});
|
|
342
|
+
const { tables, renames } = allocateSchemaNames(drafts);
|
|
343
|
+
return { names: { tables }, renames };
|
|
344
|
+
}
|
|
283
345
|
/** One line per rename, for a generator that has no logger of its own. */
|
|
284
346
|
export function describeRenames(renames) {
|
|
285
347
|
return renames.map((r) => r.kind === "table"
|
|
@@ -170,6 +170,44 @@ describe("name stability", () => {
|
|
|
170
170
|
expect(schema.tables[0].fields[0].sdkName).toBe("time");
|
|
171
171
|
});
|
|
172
172
|
});
|
|
173
|
+
// base-runner's SQL resolver refuses a whole base when two names differ only by
|
|
174
|
+
// case, so a fresh name must not match an existing one ignoring case.
|
|
175
|
+
describe("names that differ only by case", () => {
|
|
176
|
+
const locked = (tables) => ({
|
|
177
|
+
tables: tables.map((table) => ({
|
|
178
|
+
...table,
|
|
179
|
+
fields: table.fields.map(([id, sdkName]) => ({ id, sdkName, definition: { type: "single_line_text" } })),
|
|
180
|
+
})),
|
|
181
|
+
});
|
|
182
|
+
const fieldsOf = (schema) => Object.fromEntries(schema.tables[0].fields.map((f) => [f.id, f.sdkName]));
|
|
183
|
+
it("step a fresh field around a baked one, so aPIKey and a new API Key don't break SQL", () => {
|
|
184
|
+
const schema = generateSchema(database([{ id: "tbl_1", name: "Keys", fields: [field("fld_old", "API Key"), field("fld_new", "API Key")] }]), locked([{ id: "tbl_1", sdkName: "keys", fields: [["fld_old", "aPIKey"]] }]));
|
|
185
|
+
expect(fieldsOf(schema)).toEqual({ fld_old: "aPIKey", fld_new: "apiKey2" });
|
|
186
|
+
});
|
|
187
|
+
it("step a fresh field around another fresh one", () => {
|
|
188
|
+
const schema = generateSchema(database([{ id: "tbl_1", name: "Keys", fields: [field("fld_1", "API Key"), field("fld_2", "A PI Key")] }]));
|
|
189
|
+
expect(fieldsOf(schema)).toEqual({ fld_1: "apiKey", fld_2: "aPiKey2" });
|
|
190
|
+
});
|
|
191
|
+
it("step a fresh table around a baked one by the class name the client sends", () => {
|
|
192
|
+
const schema = generateSchema(database([
|
|
193
|
+
{ id: "tbl_old", name: "VIP Customers", fields: [] },
|
|
194
|
+
{ id: "tbl_new", name: "VIP Customers", fields: [] },
|
|
195
|
+
]), locked([{ id: "tbl_old", sdkName: "vIPCustomers", fields: [] }]));
|
|
196
|
+
expect(schema.tables.map((t) => t.sdkName)).toEqual(["vIPCustomers", "vipCustomers2"]);
|
|
197
|
+
});
|
|
198
|
+
it("never move a baked name, even two that already clash", () => {
|
|
199
|
+
const schema = generateSchema(database([{ id: "tbl_1", name: "Keys", fields: [field("fld_1", "API Key"), field("fld_2", "Api key")] }]), locked([{ id: "tbl_1", sdkName: "keys", fields: [["fld_1", "aPIKey"], ["fld_2", "apiKey"]] }]));
|
|
200
|
+
expect(fieldsOf(schema)).toEqual({ fld_1: "aPIKey", fld_2: "apiKey" });
|
|
201
|
+
expect(normalizeSchemaNames(schema).renames).toEqual([]);
|
|
202
|
+
});
|
|
203
|
+
it("leave a fresh name alone when it matches one only in another table", () => {
|
|
204
|
+
const schema = generateSchema(database([
|
|
205
|
+
{ id: "tbl_1", name: "Keys", fields: [field("fld_1", "API Key")] },
|
|
206
|
+
{ id: "tbl_2", name: "Other", fields: [field("fld_2", "API Key")] },
|
|
207
|
+
]), locked([{ id: "tbl_1", sdkName: "keys", fields: [["fld_1", "aPIKey"]] }]));
|
|
208
|
+
expect(schema.tables[1].fields[0].sdkName).toBe("apiKey");
|
|
209
|
+
});
|
|
210
|
+
});
|
|
173
211
|
describe("normalizeSchemaNames", () => {
|
|
174
212
|
it("is a no-op on a well-formed schema", () => {
|
|
175
213
|
const schema = {
|
package/dist/esm/upload/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useCallback, useState } from 'react';
|
|
2
2
|
import { getApiUrl, getFlowId } from '../auth/config.js';
|
|
3
|
-
import { platformMode } from '../internal/appMode.js';
|
|
3
|
+
import { platformMode, platformProvider } from '../internal/appMode.js';
|
|
4
|
+
import { platformFetch } from '../internal/platformFetch.js';
|
|
5
|
+
import { serviceUrl, UPLOAD_SESSION_PATH } from '../internal/serviceUrls.js';
|
|
4
6
|
import { ZITE_APP_ACTION_HOSTNAME_PREFIX, ZITE_APP_EDITOR_HOSTNAME_PREFIX, ZITE_SANDBOX_DOMAINS, } from '../auth/constants.js';
|
|
5
7
|
export class FileUploadError extends Error {
|
|
6
8
|
constructor(message) {
|
|
@@ -83,22 +85,76 @@ function authHeaders() {
|
|
|
83
85
|
: null;
|
|
84
86
|
return token ? { Authorization: 'Bearer ' + token } : {};
|
|
85
87
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
// On Start the session's answer says whether to complete, and where. No credential goes with it, so the app token never
|
|
89
|
+
// reaches an origin the platform didn't name in the app's props.
|
|
90
|
+
const startCompletion = session => session.completeUrl ? { url: session.completeUrl, headers: {} } : undefined;
|
|
91
|
+
/** On a Start server holding an app token: the platform's uploads service, which reads the app and mode from the token. */
|
|
92
|
+
async function tokenRoutes() {
|
|
93
|
+
const provider = platformProvider();
|
|
94
|
+
const urls = provider?.urls;
|
|
95
|
+
const token = urls ? await provider?.token() : undefined;
|
|
96
|
+
if (!urls || !token)
|
|
97
|
+
return undefined;
|
|
98
|
+
return {
|
|
99
|
+
session: body => platformFetch(new Request(serviceUrl(urls, 'uploads'), {
|
|
100
|
+
method: 'POST',
|
|
101
|
+
headers: {
|
|
102
|
+
'Content-Type': 'application/json',
|
|
103
|
+
Authorization: 'Bearer ' + token,
|
|
104
|
+
},
|
|
105
|
+
body,
|
|
106
|
+
})),
|
|
107
|
+
completion: startCompletion,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** In a Start page: the app's own server, which asks the platform on its request's token, in the mode it was served. */
|
|
111
|
+
function pageRoutes() {
|
|
112
|
+
if (typeof window === 'undefined' || !platformMode())
|
|
113
|
+
return undefined;
|
|
114
|
+
return {
|
|
115
|
+
session: body => fetch(UPLOAD_SESSION_PATH, {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
headers: { 'Content-Type': 'application/json' },
|
|
118
|
+
body,
|
|
119
|
+
}),
|
|
120
|
+
completion: startCompletion,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** A classic app's, and a Start server's on a host that sent no token. */
|
|
124
|
+
function publicRoutes() {
|
|
88
125
|
const mode = getZiteAppMode();
|
|
89
126
|
const flowId = getFlowId();
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
uploadLength: blob.size,
|
|
99
|
-
contentType: blob.type || 'application/octet-stream',
|
|
127
|
+
return {
|
|
128
|
+
session: body => fetch(getApiUrl() + '/v1/zite/public/' + flowId + '/upload-session?mode=' + mode, {
|
|
129
|
+
method: 'POST',
|
|
130
|
+
headers: {
|
|
131
|
+
'Content-Type': 'application/json',
|
|
132
|
+
...authHeaders(),
|
|
133
|
+
},
|
|
134
|
+
body,
|
|
100
135
|
}),
|
|
101
|
-
|
|
136
|
+
// Gateways that predate the storage ledger omit the token. The file is
|
|
137
|
+
// already at fileUrl, so those uploads still succeed.
|
|
138
|
+
completion: session => session.completionToken
|
|
139
|
+
? {
|
|
140
|
+
url: getApiUrl() +
|
|
141
|
+
'/v1/zite/public/' +
|
|
142
|
+
flowId +
|
|
143
|
+
'/complete-upload?mode=' +
|
|
144
|
+
mode,
|
|
145
|
+
headers: authHeaders(),
|
|
146
|
+
}
|
|
147
|
+
: undefined,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async function performUpload(data, filename) {
|
|
151
|
+
const blob = toUploadBlob(data);
|
|
152
|
+
const routes = (await tokenRoutes()) ?? pageRoutes() ?? publicRoutes();
|
|
153
|
+
const sessionRes = await routes.session(JSON.stringify({
|
|
154
|
+
filename,
|
|
155
|
+
uploadLength: blob.size,
|
|
156
|
+
contentType: blob.type || 'application/octet-stream',
|
|
157
|
+
}));
|
|
102
158
|
if (!sessionRes.ok) {
|
|
103
159
|
throw new FileUploadError(await readErrorMessage(sessionRes, 'Upload failed'));
|
|
104
160
|
}
|
|
@@ -116,18 +172,13 @@ async function performUpload(data, filename) {
|
|
|
116
172
|
if (!putRes.ok) {
|
|
117
173
|
throw new FileUploadError('Upload failed');
|
|
118
174
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const completeRes = await fetch(getApiUrl() +
|
|
123
|
-
'/v1/zite/public/' +
|
|
124
|
-
flowId +
|
|
125
|
-
'/complete-upload?mode=' +
|
|
126
|
-
mode, {
|
|
175
|
+
const completion = routes.completion(session);
|
|
176
|
+
if (completion) {
|
|
177
|
+
const completeRes = await fetch(completion.url, {
|
|
127
178
|
method: 'POST',
|
|
128
179
|
headers: {
|
|
129
180
|
'Content-Type': 'application/json',
|
|
130
|
-
...
|
|
181
|
+
...completion.headers,
|
|
131
182
|
},
|
|
132
183
|
body: JSON.stringify({ completionToken: session.completionToken }),
|
|
133
184
|
});
|
|
@@ -93,6 +93,39 @@ describe('uploadFile', () => {
|
|
|
93
93
|
await expect(upload).rejects.toThrow('File size exceeds maximum of 20 MB');
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
|
+
describe("a Start page's upload", () => {
|
|
97
|
+
afterEach(() => keepRenderedMode(undefined));
|
|
98
|
+
const answer = (session) => {
|
|
99
|
+
fetchMock
|
|
100
|
+
.mockResolvedValueOnce({ ok: true, json: async () => ({ success: true, presignedUrl: 'https://s3.example.com/put', fileUrl: 'https://uploads.zite.com/f.txt', ...session }) })
|
|
101
|
+
.mockResolvedValueOnce({ ok: true })
|
|
102
|
+
.mockResolvedValueOnce({ ok: true, json: async () => ({ success: true }) });
|
|
103
|
+
};
|
|
104
|
+
it("asks the page's own origin, with no credential, and never the API host", async () => {
|
|
105
|
+
vi.stubGlobal('localStorage', { getItem: () => 'classic-session-token' });
|
|
106
|
+
keepRenderedMode('live');
|
|
107
|
+
answer({});
|
|
108
|
+
await uploadFile({ data: 'hello', filename: 'a.txt' });
|
|
109
|
+
expect(fetchMock.mock.calls.map(([url]) => String(url))).toEqual(['/__zite/uploads/session', 'https://s3.example.com/put']);
|
|
110
|
+
const [, init] = fetchMock.mock.calls[0];
|
|
111
|
+
expect(init.headers).toEqual({ 'Content-Type': 'application/json' });
|
|
112
|
+
expect(JSON.parse(init.body)).toEqual({ filename: 'a.txt', uploadLength: 5, contentType: 'text/plain' });
|
|
113
|
+
});
|
|
114
|
+
it('completes only where the answer names, with its completion token and no other credential', async () => {
|
|
115
|
+
vi.stubGlobal('localStorage', { getItem: () => 'classic-session-token' });
|
|
116
|
+
keepRenderedMode('live');
|
|
117
|
+
answer({ completeUrl: 'https://uploads.example.com/complete', completionToken: 'ct1' });
|
|
118
|
+
await uploadFile({ data: 'hello', filename: 'a.txt' });
|
|
119
|
+
const [url, init] = fetchMock.mock.calls[2];
|
|
120
|
+
expect(url).toBe('https://uploads.example.com/complete');
|
|
121
|
+
expect(init.headers).toEqual({ 'Content-Type': 'application/json' });
|
|
122
|
+
expect(JSON.parse(init.body)).toEqual({ completionToken: 'ct1' });
|
|
123
|
+
fetchMock.mockReset();
|
|
124
|
+
answer({ completionToken: 'ct2' });
|
|
125
|
+
await uploadFile({ data: 'hello', filename: 'a.txt' });
|
|
126
|
+
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
96
129
|
// SDK-10: a Start app's mode is the platform's, never guessed from where the page is served.
|
|
97
130
|
describe('the mode an upload goes under', () => {
|
|
98
131
|
const sessionUrl = async () => {
|
|
@@ -105,9 +138,9 @@ describe('the mode an upload goes under', () => {
|
|
|
105
138
|
return String(fetchMock.mock.calls[0][0]);
|
|
106
139
|
};
|
|
107
140
|
afterEach(() => keepRenderedMode(undefined));
|
|
108
|
-
it(
|
|
141
|
+
it("in a Start page, is the one the app's own server is asked in, not a query the page writes", async () => {
|
|
109
142
|
keepRenderedMode('preview');
|
|
110
|
-
expect(await sessionUrl()).
|
|
143
|
+
expect(await sessionUrl()).toBe('/__zite/uploads/session');
|
|
111
144
|
});
|
|
112
145
|
it("is the request's own on the server, where there's no page", async () => {
|
|
113
146
|
vi.stubGlobal('window', undefined);
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zitejs",
|
|
3
|
-
"version": "0.10.0-start.
|
|
3
|
+
"version": "0.10.0-start.23",
|
|
4
4
|
"description": "The Zite framework — build apps on Zite Database",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"sideEffects":
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"./dist/esm/start/fetch.js"
|
|
8
|
+
],
|
|
7
9
|
"main": "./dist/cjs/index.js",
|
|
8
10
|
"module": "./dist/esm/index.js",
|
|
9
11
|
"types": "./dist/esm/index.d.ts",
|
|
@@ -54,12 +56,6 @@
|
|
|
54
56
|
"require": "./dist/cjs/auth/server.js",
|
|
55
57
|
"default": "./dist/esm/auth/server.js"
|
|
56
58
|
},
|
|
57
|
-
"./auth-server": {
|
|
58
|
-
"types": "./dist/esm/auth-server/index.d.ts",
|
|
59
|
-
"import": "./dist/esm/auth-server/index.js",
|
|
60
|
-
"require": "./dist/cjs/auth-server/index.js",
|
|
61
|
-
"default": "./dist/esm/auth-server/index.js"
|
|
62
|
-
},
|
|
63
59
|
"./upload": {
|
|
64
60
|
"types": "./dist/esm/upload/index.d.ts",
|
|
65
61
|
"import": "./dist/esm/upload/index.js",
|
|
@@ -106,6 +102,11 @@
|
|
|
106
102
|
"import": "./dist/esm/start/server.js",
|
|
107
103
|
"default": "./dist/esm/start/server.js"
|
|
108
104
|
},
|
|
105
|
+
"./start/fetch": {
|
|
106
|
+
"types": "./dist/esm/start/fetch.d.ts",
|
|
107
|
+
"import": "./dist/esm/start/fetch.js",
|
|
108
|
+
"default": "./dist/esm/start/fetch.js"
|
|
109
|
+
},
|
|
109
110
|
"./start/worker": {
|
|
110
111
|
"types": "./dist/esm/start/worker.d.ts",
|
|
111
112
|
"import": "./dist/esm/start/worker.js",
|
|
@@ -125,6 +126,16 @@
|
|
|
125
126
|
"types": "./dist/esm/start/vite.d.ts",
|
|
126
127
|
"import": "./dist/esm/start/vite.js",
|
|
127
128
|
"default": "./dist/esm/start/vite.js"
|
|
129
|
+
},
|
|
130
|
+
"./signin": {
|
|
131
|
+
"types": "./dist/esm/signin/index.d.ts",
|
|
132
|
+
"import": "./dist/esm/signin/index.js",
|
|
133
|
+
"default": "./dist/esm/signin/index.js"
|
|
134
|
+
},
|
|
135
|
+
"./signin/conformance": {
|
|
136
|
+
"types": "./dist/esm/signin/conformance.d.ts",
|
|
137
|
+
"import": "./dist/esm/signin/conformance.js",
|
|
138
|
+
"default": "./dist/esm/signin/conformance.js"
|
|
128
139
|
}
|
|
129
140
|
},
|
|
130
141
|
"scripts": {
|
|
@@ -135,7 +146,7 @@
|
|
|
135
146
|
"typecheck": "tsc --noEmit",
|
|
136
147
|
"version": "node scripts/write-version.mjs && git add src/start/version.ts",
|
|
137
148
|
"release": "node ./scripts/release.mjs",
|
|
138
|
-
"prepublishOnly": "npm run build"
|
|
149
|
+
"prepublishOnly": "node scripts/check-publish-tag.mjs && npm run build"
|
|
139
150
|
},
|
|
140
151
|
"files": [
|
|
141
152
|
"dist"
|
|
@@ -151,9 +162,6 @@
|
|
|
151
162
|
"caller": [
|
|
152
163
|
"dist/esm/caller/index.d.ts"
|
|
153
164
|
],
|
|
154
|
-
"auth-server": [
|
|
155
|
-
"dist/esm/auth-server/index.d.ts"
|
|
156
|
-
],
|
|
157
165
|
"backend": [
|
|
158
166
|
"dist/esm/backend/index.d.ts"
|
|
159
167
|
],
|
|
@@ -227,6 +235,7 @@
|
|
|
227
235
|
}
|
|
228
236
|
},
|
|
229
237
|
"devDependencies": {
|
|
238
|
+
"@anthropic-ai/sdk": "0.88.0",
|
|
230
239
|
"@tanstack/query-core": "5.104.0",
|
|
231
240
|
"@tanstack/react-query": "5.104.0",
|
|
232
241
|
"@tanstack/react-router": "1.170.45",
|
|
@@ -236,6 +245,7 @@
|
|
|
236
245
|
"@types/node": "^25.9.1",
|
|
237
246
|
"@types/react": "^19.0.0",
|
|
238
247
|
"@vitejs/plugin-react": "^5.2.0",
|
|
248
|
+
"openai": "6.16.0",
|
|
239
249
|
"react": "^19.0.0",
|
|
240
250
|
"typescript": "^5.4.0",
|
|
241
251
|
"vite": "^8.3.4",
|