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 {};
|
|
@@ -22,13 +22,15 @@
|
|
|
22
22
|
* cannot compile.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.SdkNameAllocator = exports.RESERVED_FIELD_ACCESSORS = exports.RESERVED_IDENTIFIERS = exports.RESERVED_TABLE_ACCESSORS = void 0;
|
|
25
|
+
exports.AUTH_USERS_TABLE_ID = exports.SdkNameAllocator = exports.RESERVED_FIELD_ACCESSORS = exports.RESERVED_IDENTIFIERS = exports.RESERVED_TABLE_ACCESSORS = void 0;
|
|
26
26
|
exports.toPascalCase = toPascalCase;
|
|
27
27
|
exports.toCamelCase = toCamelCase;
|
|
28
28
|
exports.toSdkName = toSdkName;
|
|
29
29
|
exports.keepValidSdkName = keepValidSdkName;
|
|
30
30
|
exports.allocateSchemaNames = allocateSchemaNames;
|
|
31
31
|
exports.normalizeSchemaNames = normalizeSchemaNames;
|
|
32
|
+
exports.schemaNamesOf = schemaNamesOf;
|
|
33
|
+
exports.allocateLiveNames = allocateLiveNames;
|
|
32
34
|
exports.describeRenames = describeRenames;
|
|
33
35
|
// The case helpers live here rather than in lib.ts so this module has no import
|
|
34
36
|
// back into it — `lib.ts` needs the allocator, and a cycle between the two is
|
|
@@ -121,39 +123,46 @@ class SdkNameAllocator {
|
|
|
121
123
|
taken = new Set();
|
|
122
124
|
reserved;
|
|
123
125
|
derive;
|
|
126
|
+
fold;
|
|
127
|
+
folded = new Set();
|
|
124
128
|
constructor(opts = {}) {
|
|
125
129
|
this.reserved = new Set([
|
|
126
130
|
...exports.RESERVED_IDENTIFIERS,
|
|
127
131
|
...(opts.reserved ?? []),
|
|
128
132
|
]);
|
|
129
133
|
this.derive = opts.derive ?? (() => []);
|
|
134
|
+
this.fold = opts.fold;
|
|
130
135
|
}
|
|
131
136
|
keysFor(name) {
|
|
132
137
|
return [name, ...this.derive(name)];
|
|
133
138
|
}
|
|
134
|
-
isFree(name) {
|
|
135
|
-
return this.keysFor(name).every((key) => !this.taken.has(key) && !this.reserved.has(key))
|
|
139
|
+
isFree(name, fresh) {
|
|
140
|
+
return (this.keysFor(name).every((key) => !this.taken.has(key) && !this.reserved.has(key)) &&
|
|
141
|
+
!(fresh && this.fold && this.folded.has(this.fold(name))));
|
|
136
142
|
}
|
|
137
143
|
/** Free right now, without claiming it. */
|
|
138
|
-
available(name) {
|
|
139
|
-
return this.isFree(name);
|
|
144
|
+
available(name, fresh = false) {
|
|
145
|
+
return this.isFree(name, fresh);
|
|
140
146
|
}
|
|
141
147
|
claim(name) {
|
|
142
148
|
for (const key of this.keysFor(name))
|
|
143
149
|
this.taken.add(key);
|
|
150
|
+
if (this.fold)
|
|
151
|
+
this.folded.add(this.fold(name));
|
|
144
152
|
return name;
|
|
145
153
|
}
|
|
146
154
|
/**
|
|
147
155
|
* `name`, or the first `name2`, `name3`… that is free. Suffixes start at 2
|
|
148
156
|
* because that is what the name means: the second table called Notifications.
|
|
157
|
+
* A `fresh` name also steers clear of every claimed name's `fold`.
|
|
149
158
|
*/
|
|
150
|
-
allocate(preferred) {
|
|
159
|
+
allocate(preferred, fresh = false) {
|
|
151
160
|
const base = preferred || "_";
|
|
152
|
-
if (this.isFree(base))
|
|
161
|
+
if (this.isFree(base, fresh))
|
|
153
162
|
return this.claim(base);
|
|
154
163
|
for (let suffix = 2; suffix <= MAX_SUFFIX_ATTEMPTS; suffix++) {
|
|
155
164
|
const candidate = `${base}${suffix}`;
|
|
156
|
-
if (this.isFree(candidate))
|
|
165
|
+
if (this.isFree(candidate, fresh))
|
|
157
166
|
return this.claim(candidate);
|
|
158
167
|
}
|
|
159
168
|
// Unreachable: each attempt blocks at most two keys, so a free candidate
|
|
@@ -180,6 +189,11 @@ function keepValidSdkName(sdkName) {
|
|
|
180
189
|
* Two passes per namespace: locked names claim first in declaration order, then
|
|
181
190
|
* fresh ones fill in around them. Without that ordering a new table could take
|
|
182
191
|
* an accessor an existing app already imports.
|
|
192
|
+
*
|
|
193
|
+
* A fresh name also differs from every other name ignoring case, as base-runner's
|
|
194
|
+
* SQL resolver tells names apart: it refuses a whole base when two differ only
|
|
195
|
+
* by case. Fields compare by their sdkName, tables by the class name the client
|
|
196
|
+
* sends. Locked names keep theirs even when they already clash.
|
|
183
197
|
*/
|
|
184
198
|
function allocateSchemaNames(drafts) {
|
|
185
199
|
const renames = [];
|
|
@@ -187,6 +201,7 @@ function allocateSchemaNames(drafts) {
|
|
|
187
201
|
reserved: exports.RESERVED_TABLE_ACCESSORS,
|
|
188
202
|
// The PascalCase form is its own pair of exported declarations.
|
|
189
203
|
derive: (name) => [`type:${toPascalCase(name)}`],
|
|
204
|
+
fold: (name) => toPascalCase(name).toLowerCase(),
|
|
190
205
|
});
|
|
191
206
|
const resolved = new Map();
|
|
192
207
|
for (const pass of [true, false]) {
|
|
@@ -195,7 +210,7 @@ function allocateSchemaNames(drafts) {
|
|
|
195
210
|
continue;
|
|
196
211
|
if (pass && !tableNames.available(entry.draft.preferred))
|
|
197
212
|
continue;
|
|
198
|
-
const sdkName = tableNames.allocate(entry.draft.preferred);
|
|
213
|
+
const sdkName = tableNames.allocate(entry.draft.preferred, !pass);
|
|
199
214
|
resolved.set(entry.table.id, sdkName);
|
|
200
215
|
if (sdkName !== entry.draft.preferred) {
|
|
201
216
|
renames.push({
|
|
@@ -212,7 +227,7 @@ function allocateSchemaNames(drafts) {
|
|
|
212
227
|
for (const entry of drafts) {
|
|
213
228
|
if (resolved.has(entry.table.id))
|
|
214
229
|
continue;
|
|
215
|
-
const sdkName = tableNames.allocate(entry.draft.preferred);
|
|
230
|
+
const sdkName = tableNames.allocate(entry.draft.preferred, true);
|
|
216
231
|
resolved.set(entry.table.id, sdkName);
|
|
217
232
|
renames.push({
|
|
218
233
|
kind: "table",
|
|
@@ -224,6 +239,7 @@ function allocateSchemaNames(drafts) {
|
|
|
224
239
|
const tables = drafts.map((entry) => {
|
|
225
240
|
const fieldNames = new SdkNameAllocator({
|
|
226
241
|
reserved: exports.RESERVED_FIELD_ACCESSORS,
|
|
242
|
+
fold: (name) => name.toLowerCase(),
|
|
227
243
|
});
|
|
228
244
|
const resolvedFields = new Map();
|
|
229
245
|
for (const pass of [true, false]) {
|
|
@@ -232,7 +248,7 @@ function allocateSchemaNames(drafts) {
|
|
|
232
248
|
continue;
|
|
233
249
|
if (pass && !fieldNames.available(draft.preferred))
|
|
234
250
|
continue;
|
|
235
|
-
const sdkName = fieldNames.allocate(draft.preferred);
|
|
251
|
+
const sdkName = fieldNames.allocate(draft.preferred, !pass);
|
|
236
252
|
resolvedFields.set(field.id, sdkName);
|
|
237
253
|
if (sdkName !== draft.preferred) {
|
|
238
254
|
renames.push({
|
|
@@ -248,7 +264,7 @@ function allocateSchemaNames(drafts) {
|
|
|
248
264
|
for (const { field, draft } of entry.fields) {
|
|
249
265
|
if (resolvedFields.has(field.id))
|
|
250
266
|
continue;
|
|
251
|
-
const sdkName = fieldNames.allocate(draft.preferred);
|
|
267
|
+
const sdkName = fieldNames.allocate(draft.preferred, true);
|
|
252
268
|
resolvedFields.set(field.id, sdkName);
|
|
253
269
|
renames.push({
|
|
254
270
|
kind: "field",
|
|
@@ -291,6 +307,54 @@ function normalizeSchemaNames(schema) {
|
|
|
291
307
|
})));
|
|
292
308
|
return { schema: { tables }, renames };
|
|
293
309
|
}
|
|
310
|
+
/** The names `generateDbTs` emits for a schema, without its definitions. */
|
|
311
|
+
function schemaNamesOf(schema) {
|
|
312
|
+
return {
|
|
313
|
+
tables: normalizeSchemaNames(schema).schema.tables.map((table) => ({
|
|
314
|
+
id: table.id,
|
|
315
|
+
sdkName: table.sdkName,
|
|
316
|
+
fields: table.fields.map((field) => ({
|
|
317
|
+
id: field.id,
|
|
318
|
+
sdkName: field.sdkName,
|
|
319
|
+
})),
|
|
320
|
+
})),
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/** The table `generateDbTs` never emits a client for: Zite's own users, read through `zite.auth`. */
|
|
324
|
+
exports.AUTH_USERS_TABLE_ID = "zite_user";
|
|
325
|
+
/**
|
|
326
|
+
* 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
|
|
327
|
+
* from `toSdkName` for each table or field it doesn't. `zitejs generate` writes these into zite.schema.json, and a
|
|
328
|
+
* running build fills in what was added since it was built with the same, so the two can't drift.
|
|
329
|
+
*/
|
|
330
|
+
function allocateLiveNames(live, existing) {
|
|
331
|
+
const known = new Map(existing?.tables.map((table) => [table.id, table]));
|
|
332
|
+
const drafts = live
|
|
333
|
+
.filter((table) => table.id !== exports.AUTH_USERS_TABLE_ID && !table.deletedAt)
|
|
334
|
+
.map((table) => {
|
|
335
|
+
const knownTable = known.get(table.id);
|
|
336
|
+
const knownFields = new Map(knownTable?.fields.map((field) => [field.id, field.sdkName]));
|
|
337
|
+
const kept = keepValidSdkName(knownTable?.sdkName);
|
|
338
|
+
return {
|
|
339
|
+
table: { id: table.id },
|
|
340
|
+
draft: { preferred: kept ?? toSdkName(table.name), locked: kept !== undefined },
|
|
341
|
+
fields: table.fields
|
|
342
|
+
.filter((field) => !field.deletedAt)
|
|
343
|
+
.map((field) => {
|
|
344
|
+
const keptField = keepValidSdkName(knownFields.get(field.id));
|
|
345
|
+
return {
|
|
346
|
+
field: { id: field.id },
|
|
347
|
+
draft: {
|
|
348
|
+
preferred: keptField ?? toSdkName(field.name),
|
|
349
|
+
locked: keptField !== undefined,
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
}),
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
const { tables, renames } = allocateSchemaNames(drafts);
|
|
356
|
+
return { names: { tables }, renames };
|
|
357
|
+
}
|
|
294
358
|
/** One line per rename, for a generator that has no logger of its own. */
|
|
295
359
|
function describeRenames(renames) {
|
|
296
360
|
return renames.map((r) => r.kind === "table"
|
|
@@ -172,6 +172,44 @@ const recordTypeKeys = (source, typeName) => {
|
|
|
172
172
|
(0, vitest_1.expect)(schema.tables[0].fields[0].sdkName).toBe("time");
|
|
173
173
|
});
|
|
174
174
|
});
|
|
175
|
+
// base-runner's SQL resolver refuses a whole base when two names differ only by
|
|
176
|
+
// case, so a fresh name must not match an existing one ignoring case.
|
|
177
|
+
(0, vitest_1.describe)("names that differ only by case", () => {
|
|
178
|
+
const locked = (tables) => ({
|
|
179
|
+
tables: tables.map((table) => ({
|
|
180
|
+
...table,
|
|
181
|
+
fields: table.fields.map(([id, sdkName]) => ({ id, sdkName, definition: { type: "single_line_text" } })),
|
|
182
|
+
})),
|
|
183
|
+
});
|
|
184
|
+
const fieldsOf = (schema) => Object.fromEntries(schema.tables[0].fields.map((f) => [f.id, f.sdkName]));
|
|
185
|
+
(0, vitest_1.it)("step a fresh field around a baked one, so aPIKey and a new API Key don't break SQL", () => {
|
|
186
|
+
const schema = (0, lib_js_1.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"]] }]));
|
|
187
|
+
(0, vitest_1.expect)(fieldsOf(schema)).toEqual({ fld_old: "aPIKey", fld_new: "apiKey2" });
|
|
188
|
+
});
|
|
189
|
+
(0, vitest_1.it)("step a fresh field around another fresh one", () => {
|
|
190
|
+
const schema = (0, lib_js_1.generateSchema)(database([{ id: "tbl_1", name: "Keys", fields: [field("fld_1", "API Key"), field("fld_2", "A PI Key")] }]));
|
|
191
|
+
(0, vitest_1.expect)(fieldsOf(schema)).toEqual({ fld_1: "apiKey", fld_2: "aPiKey2" });
|
|
192
|
+
});
|
|
193
|
+
(0, vitest_1.it)("step a fresh table around a baked one by the class name the client sends", () => {
|
|
194
|
+
const schema = (0, lib_js_1.generateSchema)(database([
|
|
195
|
+
{ id: "tbl_old", name: "VIP Customers", fields: [] },
|
|
196
|
+
{ id: "tbl_new", name: "VIP Customers", fields: [] },
|
|
197
|
+
]), locked([{ id: "tbl_old", sdkName: "vIPCustomers", fields: [] }]));
|
|
198
|
+
(0, vitest_1.expect)(schema.tables.map((t) => t.sdkName)).toEqual(["vIPCustomers", "vipCustomers2"]);
|
|
199
|
+
});
|
|
200
|
+
(0, vitest_1.it)("never move a baked name, even two that already clash", () => {
|
|
201
|
+
const schema = (0, lib_js_1.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"]] }]));
|
|
202
|
+
(0, vitest_1.expect)(fieldsOf(schema)).toEqual({ fld_1: "aPIKey", fld_2: "apiKey" });
|
|
203
|
+
(0, vitest_1.expect)((0, sdkNames_js_1.normalizeSchemaNames)(schema).renames).toEqual([]);
|
|
204
|
+
});
|
|
205
|
+
(0, vitest_1.it)("leave a fresh name alone when it matches one only in another table", () => {
|
|
206
|
+
const schema = (0, lib_js_1.generateSchema)(database([
|
|
207
|
+
{ id: "tbl_1", name: "Keys", fields: [field("fld_1", "API Key")] },
|
|
208
|
+
{ id: "tbl_2", name: "Other", fields: [field("fld_2", "API Key")] },
|
|
209
|
+
]), locked([{ id: "tbl_1", sdkName: "keys", fields: [["fld_1", "aPIKey"]] }]));
|
|
210
|
+
(0, vitest_1.expect)(schema.tables[1].fields[0].sdkName).toBe("apiKey");
|
|
211
|
+
});
|
|
212
|
+
});
|
|
175
213
|
(0, vitest_1.describe)("normalizeSchemaNames", () => {
|
|
176
214
|
(0, vitest_1.it)("is a no-op on a well-formed schema", () => {
|
|
177
215
|
const schema = {
|
package/dist/cjs/upload/index.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.useUpload = useUpload;
|
|
|
7
7
|
const react_1 = require("react");
|
|
8
8
|
const config_js_1 = require("../auth/config.js");
|
|
9
9
|
const appMode_js_1 = require("../internal/appMode.js");
|
|
10
|
+
const platformFetch_js_1 = require("../internal/platformFetch.js");
|
|
11
|
+
const serviceUrls_js_1 = require("../internal/serviceUrls.js");
|
|
10
12
|
const constants_js_1 = require("../auth/constants.js");
|
|
11
13
|
class FileUploadError extends Error {
|
|
12
14
|
constructor(message) {
|
|
@@ -90,22 +92,76 @@ function authHeaders() {
|
|
|
90
92
|
: null;
|
|
91
93
|
return token ? { Authorization: 'Bearer ' + token } : {};
|
|
92
94
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
// On Start the session's answer says whether to complete, and where. No credential goes with it, so the app token never
|
|
96
|
+
// reaches an origin the platform didn't name in the app's props.
|
|
97
|
+
const startCompletion = session => session.completeUrl ? { url: session.completeUrl, headers: {} } : undefined;
|
|
98
|
+
/** On a Start server holding an app token: the platform's uploads service, which reads the app and mode from the token. */
|
|
99
|
+
async function tokenRoutes() {
|
|
100
|
+
const provider = (0, appMode_js_1.platformProvider)();
|
|
101
|
+
const urls = provider?.urls;
|
|
102
|
+
const token = urls ? await provider?.token() : undefined;
|
|
103
|
+
if (!urls || !token)
|
|
104
|
+
return undefined;
|
|
105
|
+
return {
|
|
106
|
+
session: body => (0, platformFetch_js_1.platformFetch)(new Request((0, serviceUrls_js_1.serviceUrl)(urls, 'uploads'), {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
Authorization: 'Bearer ' + token,
|
|
111
|
+
},
|
|
112
|
+
body,
|
|
113
|
+
})),
|
|
114
|
+
completion: startCompletion,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** In a Start page: the app's own server, which asks the platform on its request's token, in the mode it was served. */
|
|
118
|
+
function pageRoutes() {
|
|
119
|
+
if (typeof window === 'undefined' || !(0, appMode_js_1.platformMode)())
|
|
120
|
+
return undefined;
|
|
121
|
+
return {
|
|
122
|
+
session: body => fetch(serviceUrls_js_1.UPLOAD_SESSION_PATH, {
|
|
123
|
+
method: 'POST',
|
|
124
|
+
headers: { 'Content-Type': 'application/json' },
|
|
125
|
+
body,
|
|
126
|
+
}),
|
|
127
|
+
completion: startCompletion,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** A classic app's, and a Start server's on a host that sent no token. */
|
|
131
|
+
function publicRoutes() {
|
|
95
132
|
const mode = getZiteAppMode();
|
|
96
133
|
const flowId = (0, config_js_1.getFlowId)();
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
uploadLength: blob.size,
|
|
106
|
-
contentType: blob.type || 'application/octet-stream',
|
|
134
|
+
return {
|
|
135
|
+
session: body => fetch((0, config_js_1.getApiUrl)() + '/v1/zite/public/' + flowId + '/upload-session?mode=' + mode, {
|
|
136
|
+
method: 'POST',
|
|
137
|
+
headers: {
|
|
138
|
+
'Content-Type': 'application/json',
|
|
139
|
+
...authHeaders(),
|
|
140
|
+
},
|
|
141
|
+
body,
|
|
107
142
|
}),
|
|
108
|
-
|
|
143
|
+
// Gateways that predate the storage ledger omit the token. The file is
|
|
144
|
+
// already at fileUrl, so those uploads still succeed.
|
|
145
|
+
completion: session => session.completionToken
|
|
146
|
+
? {
|
|
147
|
+
url: (0, config_js_1.getApiUrl)() +
|
|
148
|
+
'/v1/zite/public/' +
|
|
149
|
+
flowId +
|
|
150
|
+
'/complete-upload?mode=' +
|
|
151
|
+
mode,
|
|
152
|
+
headers: authHeaders(),
|
|
153
|
+
}
|
|
154
|
+
: undefined,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async function performUpload(data, filename) {
|
|
158
|
+
const blob = toUploadBlob(data);
|
|
159
|
+
const routes = (await tokenRoutes()) ?? pageRoutes() ?? publicRoutes();
|
|
160
|
+
const sessionRes = await routes.session(JSON.stringify({
|
|
161
|
+
filename,
|
|
162
|
+
uploadLength: blob.size,
|
|
163
|
+
contentType: blob.type || 'application/octet-stream',
|
|
164
|
+
}));
|
|
109
165
|
if (!sessionRes.ok) {
|
|
110
166
|
throw new FileUploadError(await readErrorMessage(sessionRes, 'Upload failed'));
|
|
111
167
|
}
|
|
@@ -123,18 +179,13 @@ async function performUpload(data, filename) {
|
|
|
123
179
|
if (!putRes.ok) {
|
|
124
180
|
throw new FileUploadError('Upload failed');
|
|
125
181
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const completeRes = await fetch((0, config_js_1.getApiUrl)() +
|
|
130
|
-
'/v1/zite/public/' +
|
|
131
|
-
flowId +
|
|
132
|
-
'/complete-upload?mode=' +
|
|
133
|
-
mode, {
|
|
182
|
+
const completion = routes.completion(session);
|
|
183
|
+
if (completion) {
|
|
184
|
+
const completeRes = await fetch(completion.url, {
|
|
134
185
|
method: 'POST',
|
|
135
186
|
headers: {
|
|
136
187
|
'Content-Type': 'application/json',
|
|
137
|
-
...
|
|
188
|
+
...completion.headers,
|
|
138
189
|
},
|
|
139
190
|
body: JSON.stringify({ completionToken: session.completionToken }),
|
|
140
191
|
});
|
|
@@ -95,6 +95,39 @@ const fetchMock = vitest_1.vi.fn();
|
|
|
95
95
|
await (0, vitest_1.expect)(upload).rejects.toThrow('File size exceeds maximum of 20 MB');
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
|
+
(0, vitest_1.describe)("a Start page's upload", () => {
|
|
99
|
+
(0, vitest_1.afterEach)(() => (0, appMode_js_1.keepRenderedMode)(undefined));
|
|
100
|
+
const answer = (session) => {
|
|
101
|
+
fetchMock
|
|
102
|
+
.mockResolvedValueOnce({ ok: true, json: async () => ({ success: true, presignedUrl: 'https://s3.example.com/put', fileUrl: 'https://uploads.zite.com/f.txt', ...session }) })
|
|
103
|
+
.mockResolvedValueOnce({ ok: true })
|
|
104
|
+
.mockResolvedValueOnce({ ok: true, json: async () => ({ success: true }) });
|
|
105
|
+
};
|
|
106
|
+
(0, vitest_1.it)("asks the page's own origin, with no credential, and never the API host", async () => {
|
|
107
|
+
vitest_1.vi.stubGlobal('localStorage', { getItem: () => 'classic-session-token' });
|
|
108
|
+
(0, appMode_js_1.keepRenderedMode)('live');
|
|
109
|
+
answer({});
|
|
110
|
+
await (0, index_js_1.uploadFile)({ data: 'hello', filename: 'a.txt' });
|
|
111
|
+
(0, vitest_1.expect)(fetchMock.mock.calls.map(([url]) => String(url))).toEqual(['/__zite/uploads/session', 'https://s3.example.com/put']);
|
|
112
|
+
const [, init] = fetchMock.mock.calls[0];
|
|
113
|
+
(0, vitest_1.expect)(init.headers).toEqual({ 'Content-Type': 'application/json' });
|
|
114
|
+
(0, vitest_1.expect)(JSON.parse(init.body)).toEqual({ filename: 'a.txt', uploadLength: 5, contentType: 'text/plain' });
|
|
115
|
+
});
|
|
116
|
+
(0, vitest_1.it)('completes only where the answer names, with its completion token and no other credential', async () => {
|
|
117
|
+
vitest_1.vi.stubGlobal('localStorage', { getItem: () => 'classic-session-token' });
|
|
118
|
+
(0, appMode_js_1.keepRenderedMode)('live');
|
|
119
|
+
answer({ completeUrl: 'https://uploads.example.com/complete', completionToken: 'ct1' });
|
|
120
|
+
await (0, index_js_1.uploadFile)({ data: 'hello', filename: 'a.txt' });
|
|
121
|
+
const [url, init] = fetchMock.mock.calls[2];
|
|
122
|
+
(0, vitest_1.expect)(url).toBe('https://uploads.example.com/complete');
|
|
123
|
+
(0, vitest_1.expect)(init.headers).toEqual({ 'Content-Type': 'application/json' });
|
|
124
|
+
(0, vitest_1.expect)(JSON.parse(init.body)).toEqual({ completionToken: 'ct1' });
|
|
125
|
+
fetchMock.mockReset();
|
|
126
|
+
answer({ completionToken: 'ct2' });
|
|
127
|
+
await (0, index_js_1.uploadFile)({ data: 'hello', filename: 'a.txt' });
|
|
128
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledTimes(2);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
98
131
|
// SDK-10: a Start app's mode is the platform's, never guessed from where the page is served.
|
|
99
132
|
(0, vitest_1.describe)('the mode an upload goes under', () => {
|
|
100
133
|
const sessionUrl = async () => {
|
|
@@ -107,9 +140,9 @@ const fetchMock = vitest_1.vi.fn();
|
|
|
107
140
|
return String(fetchMock.mock.calls[0][0]);
|
|
108
141
|
};
|
|
109
142
|
(0, vitest_1.afterEach)(() => (0, appMode_js_1.keepRenderedMode)(undefined));
|
|
110
|
-
(0, vitest_1.it)(
|
|
143
|
+
(0, vitest_1.it)("in a Start page, is the one the app's own server is asked in, not a query the page writes", async () => {
|
|
111
144
|
(0, appMode_js_1.keepRenderedMode)('preview');
|
|
112
|
-
(0, vitest_1.expect)(await sessionUrl()).
|
|
145
|
+
(0, vitest_1.expect)(await sessionUrl()).toBe('/__zite/uploads/session');
|
|
113
146
|
});
|
|
114
147
|
(0, vitest_1.it)("is the request's own on the server, where there's no page", async () => {
|
|
115
148
|
vitest_1.vi.stubGlobal('window', undefined);
|
|
@@ -5,7 +5,7 @@ export declare const authClient: import("better-auth/react").ReactAuthClient<{
|
|
|
5
5
|
plugins: ({
|
|
6
6
|
id: "magic-link";
|
|
7
7
|
version: string;
|
|
8
|
-
$InferServerPlugin: ReturnType<(options: import("better-auth/plugins").MagicLinkOptions) => {
|
|
8
|
+
$InferServerPlugin: ReturnType<(options: import("better-auth/plugins/magic-link").MagicLinkOptions) => {
|
|
9
9
|
id: "magic-link";
|
|
10
10
|
version: string;
|
|
11
11
|
endpoints: {
|
|
@@ -110,7 +110,7 @@ export declare const authClient: import("better-auth/react").ReactAuthClient<{
|
|
|
110
110
|
window: number;
|
|
111
111
|
max: number;
|
|
112
112
|
}[];
|
|
113
|
-
options: import("better-auth/plugins").MagicLinkOptions;
|
|
113
|
+
options: import("better-auth/plugins/magic-link").MagicLinkOptions;
|
|
114
114
|
}>;
|
|
115
115
|
} | {
|
|
116
116
|
id: "additional-fields-client";
|
|
@@ -963,6 +963,9 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
|
|
|
963
963
|
if (source === "cloudflare:workers") {
|
|
964
964
|
report("cloudflare-env", "error", path, statement, "read the app's environment from process.env, not cloudflare:workers");
|
|
965
965
|
}
|
|
966
|
+
if (importsModule(source, "zitejs/signin")) {
|
|
967
|
+
report("platform-import", "error", path, statement, "zitejs/signin is the platform's sign-in client, which runs for you; send people to sign in with loginWithRedirect() from zitejs/auth, or a link to loginHref() from zitejs/start");
|
|
968
|
+
}
|
|
966
969
|
const typeOnly = values !== "all" && values.length === 0;
|
|
967
970
|
// Loading a module is fine without a request; only calling one of its server functions isn't.
|
|
968
971
|
const target = callsWorkflow ? resolveImport(path, source, paths) : undefined;
|
package/dist/esm/cli.js
CHANGED
|
@@ -48,6 +48,12 @@ async function main() {
|
|
|
48
48
|
console.error(' check Typecheck and build every app and automation; a Start app is typechecked with tsgo against its regenerated route tree and its source checked by rule (--json for a report)');
|
|
49
49
|
console.error(' bundle Bundle endpoints (src/api/*.ts, or an automation\'s src/index.ts) for cloudflare-lambda');
|
|
50
50
|
console.error(' describe Print what a built TanStack Start app declares: functions, routes, access');
|
|
51
|
+
console.error('');
|
|
52
|
+
console.error("A Start app under `vite dev` reaches Zite's data and services with these, from the app's .env:");
|
|
53
|
+
console.error(" ZITE_DEV_API_KEY Your Zite API key, as the MCP takes it: mints dev tokens for the app zite.config.json's id names; each lasts 15 minutes and is renewed before it expires");
|
|
54
|
+
console.error(' ZITE_DEV_TOKEN A dev token to use as it is instead, never renewed');
|
|
55
|
+
console.error(' ZITE_URLS JSON naming the platform: {"baseRunner","backend","aiGateway"?,"runs"?,"email"?,"pdf"?,"uploads"?,"steps"?}; a service it doesn\'t name is the backend\'s');
|
|
56
|
+
console.error(' ZITE_DEV_USER JSON of the signed-in stand-in: {"id","email","name"?,"roles"?,"isInternal"?}; unset, nobody is');
|
|
51
57
|
process.exit(1);
|
|
52
58
|
}
|
|
53
59
|
}
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { dirname, join, resolve } from "path";
|
|
|
4
4
|
import { findWorkspaceRoot, listSourceDirs, } from "../sourceRoots.js";
|
|
5
5
|
import { isStartAppDir, regenerateStartEntries, workspaceHasStartApps, } from "../start/entries.js";
|
|
6
6
|
import { runSync } from "../sync/index.js";
|
|
7
|
+
import { writeDevSignIn } from "./signin.js";
|
|
7
8
|
import { generateDbTs, generateApiTs, generateBackendWrapperTs, generateAirtableTs, findEmailIntegrationId, generateEmailSdk, generateIntegrationsIndex, } from "../sync/lib.js";
|
|
8
9
|
import { gettableIntegrations, } from "../integrations/rules.js";
|
|
9
10
|
const debounceTimers = new Map();
|
|
@@ -235,6 +236,20 @@ export async function runDev() {
|
|
|
235
236
|
regenerateAppIntegrationsIndex(app);
|
|
236
237
|
regenerateStartEntries(app);
|
|
237
238
|
}
|
|
239
|
+
// Sign-in under `vite dev`: each Start app's issuer, dev client and session secret.
|
|
240
|
+
for (const app of appDirs) {
|
|
241
|
+
if (!isStartAppDir(app.path))
|
|
242
|
+
continue;
|
|
243
|
+
try {
|
|
244
|
+
const result = await writeDevSignIn(app.path);
|
|
245
|
+
console.log(result.written
|
|
246
|
+
? `Sign-in for ${app.path} under vite dev: ${result.clientId} at ${result.issuer}`
|
|
247
|
+
: `No sign-in for ${app.path} under vite dev: ${result.reason}`);
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
console.warn(`Couldn't set up sign-in for ${app.path}:`, err instanceof Error ? err.message : err);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
238
253
|
// 3. Watch each dir's src/api/ for endpoint changes
|
|
239
254
|
let watchingAny = false;
|
|
240
255
|
for (const app of appDirs) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const DEV_ENV_FILE: string;
|
|
2
|
+
type Env = Record<string, string | undefined>;
|
|
3
|
+
export type DevSignInResult = {
|
|
4
|
+
written: true;
|
|
5
|
+
issuer: string;
|
|
6
|
+
clientId: string;
|
|
7
|
+
} | {
|
|
8
|
+
written: false;
|
|
9
|
+
reason: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Writes the app's `.zite/dev.env` from its dev token's `appUrl`: issuer `<appUrl>/auth`, client `<app>:dev`. Keeps
|
|
13
|
+
* the secret a previous run wrote, so sessions outlive a restart.
|
|
14
|
+
*/
|
|
15
|
+
export declare function writeDevSignIn(appDir: string, shell?: Env): Promise<DevSignInResult>;
|
|
16
|
+
export {};
|