zitejs 0.9.146 → 0.9.148
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/backend/index.d.ts +9 -3
- package/dist/cjs/bundle/index.d.ts +8 -0
- package/dist/cjs/bundle/index.js +9 -8
- package/dist/cjs/check/index.js +41 -25
- package/dist/cjs/client/index.d.ts +24 -0
- package/dist/cjs/runtime/index.d.ts +5 -11
- package/dist/cjs/steps/index.d.ts +78 -0
- package/dist/cjs/steps/index.js +507 -0
- package/dist/cjs/steps/index.test.d.ts +1 -0
- package/dist/cjs/steps/index.test.js +635 -0
- package/dist/cjs/sync/lib.js +5 -3
- package/dist/cjs/sync/lib.test.js +90 -36
- package/dist/cjs/types/fields.d.ts +8 -1
- package/dist/cjs/types/fields.js +7 -1
- package/dist/cjs/types/tables.d.ts +16 -0
- package/dist/esm/backend/index.d.ts +9 -3
- package/dist/esm/bundle/index.d.ts +8 -0
- package/dist/esm/bundle/index.js +8 -8
- package/dist/esm/check/index.js +10 -27
- package/dist/esm/client/index.d.ts +24 -0
- package/dist/esm/runtime/index.d.ts +5 -11
- package/dist/esm/steps/index.d.ts +78 -0
- package/dist/esm/steps/index.js +502 -0
- package/dist/esm/steps/index.test.d.ts +1 -0
- package/dist/esm/steps/index.test.js +633 -0
- package/dist/esm/sync/lib.js +5 -3
- package/dist/esm/sync/lib.test.js +90 -36
- package/dist/esm/types/fields.d.ts +8 -1
- package/dist/esm/types/fields.js +6 -0
- package/dist/esm/types/tables.d.ts +16 -0
- package/package.json +9 -1
|
@@ -422,44 +422,98 @@ describe('findEmailIntegrationId', () => {
|
|
|
422
422
|
expect(findEmailIntegrationId(undefined, undefined)).toBeUndefined();
|
|
423
423
|
});
|
|
424
424
|
});
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
425
|
+
// Not import.meta: this file also compiles to CommonJS. Vitest runs from the repo root.
|
|
426
|
+
const runtimePath = resolve('src/runtime/index.ts');
|
|
427
|
+
/** Type errors in the `/app/` files, `zitejs/runtime` mapped to this source. */
|
|
428
|
+
const appTypeErrors = (files, paths) => {
|
|
429
|
+
const options = {
|
|
430
|
+
strict: true,
|
|
431
|
+
noEmit: true,
|
|
432
|
+
target: ts.ScriptTarget.ES2022,
|
|
433
|
+
module: ts.ModuleKind.ESNext,
|
|
434
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
435
|
+
skipLibCheck: true,
|
|
436
|
+
baseUrl: '/app',
|
|
437
|
+
paths: { 'zitejs/runtime': [runtimePath], ...paths },
|
|
438
|
+
};
|
|
439
|
+
const host = ts.createCompilerHost(options);
|
|
440
|
+
const { getSourceFile, fileExists, readFile, directoryExists } = host;
|
|
441
|
+
host.fileExists = f => f in files || fileExists(f);
|
|
442
|
+
host.directoryExists = d => Object.keys(files).some(f => f.startsWith(`${d}/`)) ||
|
|
443
|
+
(directoryExists?.(d) ?? false);
|
|
444
|
+
host.readFile = f => files[f] ?? readFile(f);
|
|
445
|
+
host.getSourceFile = (f, lang, ...rest) => f in files
|
|
446
|
+
? ts.createSourceFile(f, files[f], lang)
|
|
447
|
+
: getSourceFile(f, lang, ...rest);
|
|
448
|
+
const program = ts.createProgram(Object.keys(files), options, host);
|
|
449
|
+
return ts
|
|
450
|
+
.getPreEmitDiagnostics(program)
|
|
451
|
+
.filter(d => d.file?.fileName.startsWith('/app/'))
|
|
452
|
+
.map(d => ts.flattenDiagnosticMessageText(d.messageText, ' '));
|
|
453
|
+
};
|
|
454
|
+
describe('generateDbTs created_by and updated_by', () => {
|
|
455
|
+
const schema = {
|
|
456
|
+
tables: [
|
|
457
|
+
{
|
|
458
|
+
id: 'tbl1',
|
|
459
|
+
sdkName: 'tasks',
|
|
460
|
+
fields: [
|
|
461
|
+
{
|
|
462
|
+
id: 'fld1',
|
|
463
|
+
sdkName: 'title',
|
|
464
|
+
definition: { name: 'Title', type: 'single_line_text', template: {} },
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
id: 'fld2',
|
|
468
|
+
sdkName: 'createdBy',
|
|
469
|
+
definition: { name: 'Created By', type: 'created_by', template: {} },
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
id: 'fld3',
|
|
473
|
+
sdkName: 'updatedBy',
|
|
474
|
+
definition: { name: 'Last Modified By', type: 'updated_by', template: {} },
|
|
475
|
+
},
|
|
476
|
+
],
|
|
446
477
|
},
|
|
447
|
-
|
|
448
|
-
const host = ts.createCompilerHost(options);
|
|
449
|
-
const { getSourceFile, fileExists, readFile, directoryExists } = host;
|
|
450
|
-
host.fileExists = f => f in files || fileExists(f);
|
|
451
|
-
host.directoryExists = d => Object.keys(files).some(f => f.startsWith(`${d}/`)) ||
|
|
452
|
-
(directoryExists?.(d) ?? false);
|
|
453
|
-
host.readFile = f => files[f] ?? readFile(f);
|
|
454
|
-
host.getSourceFile = (f, lang, ...rest) => f in files
|
|
455
|
-
? ts.createSourceFile(f, files[f], lang)
|
|
456
|
-
: getSourceFile(f, lang, ...rest);
|
|
457
|
-
const program = ts.createProgram(Object.keys(files), options, host);
|
|
458
|
-
return ts
|
|
459
|
-
.getPreEmitDiagnostics(program)
|
|
460
|
-
.filter(d => d.file?.fileName.startsWith('/app/'))
|
|
461
|
-
.map(d => ts.flattenDiagnosticMessageText(d.messageText, ' '));
|
|
478
|
+
],
|
|
462
479
|
};
|
|
480
|
+
const typeErrorsIn = (usage) => appTypeErrors({ '/app/.zite/db.ts': generateDbTs(schema), '/app/src/usage.ts': usage }, { 'zitejs/db': ['/app/.zite/db.ts'] });
|
|
481
|
+
const EQUAL = 'type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;';
|
|
482
|
+
// TanStack Start's serializability check rejects `unknown`, so a server
|
|
483
|
+
// function returning a raw row failed typecheck while created_by fell through.
|
|
484
|
+
it('reads both as a user id', () => {
|
|
485
|
+
expect(typeErrorsIn([
|
|
486
|
+
"import type { TasksRecordType } from 'zitejs/db';",
|
|
487
|
+
EQUAL,
|
|
488
|
+
"export const createdBy: Equal<TasksRecordType['createdBy'], string | undefined> = true;",
|
|
489
|
+
"export const updatedBy: Equal<TasksRecordType['updatedBy'], string | undefined> = true;",
|
|
490
|
+
].join('\n'))).toEqual([]);
|
|
491
|
+
});
|
|
492
|
+
it('leaves both out of the input type', () => {
|
|
493
|
+
expect(typeErrorsIn([
|
|
494
|
+
"import type { TasksRecordInput } from 'zitejs/db';",
|
|
495
|
+
EQUAL,
|
|
496
|
+
"export const writable: Equal<keyof TasksRecordInput, 'title'> = true;",
|
|
497
|
+
].join('\n'))).toEqual([]);
|
|
498
|
+
});
|
|
499
|
+
it('filters both by a user id', () => {
|
|
500
|
+
expect(typeErrorsIn([
|
|
501
|
+
"import { zite } from 'zitejs/db';",
|
|
502
|
+
'export const mine = (userId: string) => [',
|
|
503
|
+
' zite.tasks.findAll({ filters: { createdBy: userId } }),',
|
|
504
|
+
' zite.tasks.findAll({ filters: { updatedBy: { in: [userId] } } }),',
|
|
505
|
+
' zite.tasks.findOne({ filters: { createdBy: { not: null } } }),',
|
|
506
|
+
'];',
|
|
507
|
+
].join('\n'))).toEqual([]);
|
|
508
|
+
expect(typeErrorsIn("import { zite } from 'zitejs/db';\nvoid zite.tasks.findAll({ filters: { createdBy: 42 } });")).toHaveLength(1);
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
describe('generateIntegrationsIndex', () => {
|
|
512
|
+
const typeErrorsIn = (generated, usage, airtable) => appTypeErrors({
|
|
513
|
+
'/app/.zite/integrations/index.ts': generated,
|
|
514
|
+
...(airtable ? { '/app/.zite/integrations/airtable.ts': airtable } : {}),
|
|
515
|
+
'/app/src/usage.ts': usage,
|
|
516
|
+
}, { 'zitejs/integrations': ['/app/.zite/integrations/index.ts'] });
|
|
463
517
|
it('emits the client typed by name', () => {
|
|
464
518
|
expect(generateIntegrationsIndex([
|
|
465
519
|
{ name: 'team', serviceType: 'slack', perUser: false },
|
|
@@ -7,7 +7,7 @@ export declare const timeFormatEnum: readonly ["12h", "24h"];
|
|
|
7
7
|
export type TimeFormat = (typeof timeFormatEnum)[number];
|
|
8
8
|
export declare const durationFormatEnum: readonly ["h:mm", "h:mm:ss", "h:mm:ss.s", "h:mm:ss.ss", "h:mm:ss.sss"];
|
|
9
9
|
export type DurationFormat = (typeof durationFormatEnum)[number];
|
|
10
|
-
export declare const fieldTypeEnum: readonly ["currency", "single_line_text", "long_text", "rich_text", "number", "single_select", "multiple_select", "date", "datetime", "checkbox", "attachments", "email", "url", "phone_number", "rating", "duration", "percent", "linked_record", "lookup", "source", "formula", "autonumber", "created_at", "updated_at", "rollup", "updated_by", "user"];
|
|
10
|
+
export declare const fieldTypeEnum: readonly ["currency", "single_line_text", "long_text", "rich_text", "number", "single_select", "multiple_select", "date", "datetime", "checkbox", "attachments", "email", "url", "phone_number", "rating", "duration", "percent", "linked_record", "lookup", "source", "formula", "autonumber", "created_at", "updated_at", "rollup", "created_by", "updated_by", "user"];
|
|
11
11
|
export type FieldType = (typeof fieldTypeEnum)[number];
|
|
12
12
|
export declare const fieldTypeSchema: z.ZodEnum<{
|
|
13
13
|
number: "number";
|
|
@@ -35,6 +35,7 @@ export declare const fieldTypeSchema: z.ZodEnum<{
|
|
|
35
35
|
created_at: "created_at";
|
|
36
36
|
updated_at: "updated_at";
|
|
37
37
|
rollup: "rollup";
|
|
38
|
+
created_by: "created_by";
|
|
38
39
|
updated_by: "updated_by";
|
|
39
40
|
user: "user";
|
|
40
41
|
}>;
|
|
@@ -240,6 +241,7 @@ export declare const rollupTemplateSchema: z.ZodObject<{
|
|
|
240
241
|
text: "text";
|
|
241
242
|
}>>;
|
|
242
243
|
}, z.core.$strip>;
|
|
244
|
+
export declare const createdByTemplateSchema: z.ZodObject<{}, z.core.$strip>;
|
|
243
245
|
export declare const updatedByTemplateSchema: z.ZodObject<{}, z.core.$strip>;
|
|
244
246
|
export declare const userTemplateSchema: z.ZodObject<{
|
|
245
247
|
allowMultiple: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, z.ZodTransform<boolean, boolean | null | undefined>>;
|
|
@@ -554,6 +556,10 @@ export declare const publicFieldDefinitionSchema: z.ZodDiscriminatedUnion<[z.Zod
|
|
|
554
556
|
text: "text";
|
|
555
557
|
}>>;
|
|
556
558
|
}, z.core.$strip>;
|
|
559
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
560
|
+
name: z.ZodString;
|
|
561
|
+
type: z.ZodLiteral<"created_by">;
|
|
562
|
+
template: z.ZodObject<{}, z.core.$strip>;
|
|
557
563
|
}, z.core.$strip>, z.ZodObject<{
|
|
558
564
|
name: z.ZodString;
|
|
559
565
|
type: z.ZodLiteral<"updated_by">;
|
|
@@ -661,6 +667,7 @@ export type FieldTemplateMap = {
|
|
|
661
667
|
linked_record: z.infer<typeof linkedRecordTemplateSchema>;
|
|
662
668
|
lookup: z.infer<typeof lookupTemplateSchema>;
|
|
663
669
|
rollup: z.infer<typeof rollupTemplateSchema>;
|
|
670
|
+
created_by: z.infer<typeof createdByTemplateSchema>;
|
|
664
671
|
updated_by: z.infer<typeof updatedByTemplateSchema>;
|
|
665
672
|
user: z.infer<typeof userTemplateSchema>;
|
|
666
673
|
source: z.infer<typeof sourceTemplateSchema>;
|
package/dist/esm/types/fields.js
CHANGED
|
@@ -42,6 +42,7 @@ export const fieldTypeEnum = [
|
|
|
42
42
|
"created_at",
|
|
43
43
|
"updated_at",
|
|
44
44
|
"rollup",
|
|
45
|
+
"created_by",
|
|
45
46
|
"updated_by",
|
|
46
47
|
"user",
|
|
47
48
|
];
|
|
@@ -180,6 +181,7 @@ export const rollupTemplateSchema = z.object({
|
|
|
180
181
|
.enum(["text", "number", "date", "boolean", "array"])
|
|
181
182
|
.optional(),
|
|
182
183
|
});
|
|
184
|
+
export const createdByTemplateSchema = z.object({});
|
|
183
185
|
export const updatedByTemplateSchema = z.object({});
|
|
184
186
|
export const userTemplateSchema = z.object({
|
|
185
187
|
allowMultiple: z
|
|
@@ -326,6 +328,10 @@ export const publicFieldDefinitionSchema = z.discriminatedUnion("type", [
|
|
|
326
328
|
type: z.literal("rollup"),
|
|
327
329
|
template: rollupTemplateSchema,
|
|
328
330
|
}),
|
|
331
|
+
basePublicFieldSchema.extend({
|
|
332
|
+
type: z.literal("created_by"),
|
|
333
|
+
template: createdByTemplateSchema,
|
|
334
|
+
}),
|
|
329
335
|
basePublicFieldSchema.extend({
|
|
330
336
|
type: z.literal("updated_by"),
|
|
331
337
|
template: updatedByTemplateSchema,
|
|
@@ -253,6 +253,10 @@ export declare const fieldSchema: z.ZodIntersection<z.ZodObject<{
|
|
|
253
253
|
text: "text";
|
|
254
254
|
}>>;
|
|
255
255
|
}, z.core.$strip>;
|
|
256
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
257
|
+
name: z.ZodString;
|
|
258
|
+
type: z.ZodLiteral<"created_by">;
|
|
259
|
+
template: z.ZodObject<{}, z.core.$strip>;
|
|
256
260
|
}, z.core.$strip>, z.ZodObject<{
|
|
257
261
|
name: z.ZodString;
|
|
258
262
|
type: z.ZodLiteral<"updated_by">;
|
|
@@ -605,6 +609,10 @@ export declare const tableSchema: z.ZodObject<{
|
|
|
605
609
|
text: "text";
|
|
606
610
|
}>>;
|
|
607
611
|
}, z.core.$strip>;
|
|
612
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
613
|
+
name: z.ZodString;
|
|
614
|
+
type: z.ZodLiteral<"created_by">;
|
|
615
|
+
template: z.ZodObject<{}, z.core.$strip>;
|
|
608
616
|
}, z.core.$strip>, z.ZodObject<{
|
|
609
617
|
name: z.ZodString;
|
|
610
618
|
type: z.ZodLiteral<"updated_by">;
|
|
@@ -952,6 +960,10 @@ export declare const publicTableDefinitionSchema: z.ZodObject<{
|
|
|
952
960
|
text: "text";
|
|
953
961
|
}>>;
|
|
954
962
|
}, z.core.$strip>;
|
|
963
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
964
|
+
name: z.ZodString;
|
|
965
|
+
type: z.ZodLiteral<"created_by">;
|
|
966
|
+
template: z.ZodObject<{}, z.core.$strip>;
|
|
955
967
|
}, z.core.$strip>, z.ZodObject<{
|
|
956
968
|
name: z.ZodString;
|
|
957
969
|
type: z.ZodLiteral<"updated_by">;
|
|
@@ -1301,6 +1313,10 @@ export declare const databaseSchema: z.ZodObject<{
|
|
|
1301
1313
|
text: "text";
|
|
1302
1314
|
}>>;
|
|
1303
1315
|
}, z.core.$strip>;
|
|
1316
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1317
|
+
name: z.ZodString;
|
|
1318
|
+
type: z.ZodLiteral<"created_by">;
|
|
1319
|
+
template: z.ZodObject<{}, z.core.$strip>;
|
|
1304
1320
|
}, z.core.$strip>, z.ZodObject<{
|
|
1305
1321
|
name: z.ZodString;
|
|
1306
1322
|
type: z.ZodLiteral<"updated_by">;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zitejs",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.148",
|
|
4
4
|
"description": "The Zite framework — build apps on Zite Database",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -75,6 +75,11 @@
|
|
|
75
75
|
"import": "./dist/esm/schedules/index.js",
|
|
76
76
|
"require": "./dist/cjs/schedules/index.js"
|
|
77
77
|
},
|
|
78
|
+
"./steps": {
|
|
79
|
+
"types": "./dist/esm/steps/index.d.ts",
|
|
80
|
+
"import": "./dist/esm/steps/index.js",
|
|
81
|
+
"require": "./dist/cjs/steps/index.js"
|
|
82
|
+
},
|
|
78
83
|
"./integrations": {
|
|
79
84
|
"types": "./dist/esm/integrations/index.d.ts",
|
|
80
85
|
"import": "./dist/esm/integrations/index.js",
|
|
@@ -138,6 +143,9 @@
|
|
|
138
143
|
"schedules": [
|
|
139
144
|
"dist/esm/schedules/index.d.ts"
|
|
140
145
|
],
|
|
146
|
+
"steps": [
|
|
147
|
+
"dist/esm/steps/index.d.ts"
|
|
148
|
+
],
|
|
141
149
|
"integrations": [
|
|
142
150
|
"dist/esm/integrations/index.d.ts"
|
|
143
151
|
],
|