zitejs 0.9.147 → 0.9.149

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.
Files changed (37) hide show
  1. package/dist/cjs/backend/index.d.ts +7 -1
  2. package/dist/cjs/bundle/index.d.ts +8 -0
  3. package/dist/cjs/bundle/index.js +9 -8
  4. package/dist/cjs/check/index.js +41 -25
  5. package/dist/cjs/client/index.d.ts +24 -0
  6. package/dist/cjs/integrations/rules.js +5 -3
  7. package/dist/cjs/runtime/index.d.ts +49 -19
  8. package/dist/cjs/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
  9. package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +32 -0
  10. package/dist/cjs/steps/index.d.ts +78 -0
  11. package/dist/cjs/steps/index.js +507 -0
  12. package/dist/cjs/steps/index.test.d.ts +1 -0
  13. package/dist/cjs/steps/index.test.js +635 -0
  14. package/dist/cjs/sync/lib.js +10 -6
  15. package/dist/cjs/sync/lib.test.js +100 -36
  16. package/dist/cjs/types/fields.d.ts +8 -1
  17. package/dist/cjs/types/fields.js +7 -1
  18. package/dist/cjs/types/tables.d.ts +16 -0
  19. package/dist/esm/backend/index.d.ts +7 -1
  20. package/dist/esm/bundle/index.d.ts +8 -0
  21. package/dist/esm/bundle/index.js +8 -8
  22. package/dist/esm/check/index.js +10 -27
  23. package/dist/esm/client/index.d.ts +24 -0
  24. package/dist/esm/integrations/rules.js +5 -3
  25. package/dist/esm/runtime/index.d.ts +49 -19
  26. package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
  27. package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +30 -0
  28. package/dist/esm/steps/index.d.ts +78 -0
  29. package/dist/esm/steps/index.js +502 -0
  30. package/dist/esm/steps/index.test.d.ts +1 -0
  31. package/dist/esm/steps/index.test.js +633 -0
  32. package/dist/esm/sync/lib.js +10 -6
  33. package/dist/esm/sync/lib.test.js +100 -36
  34. package/dist/esm/types/fields.d.ts +8 -1
  35. package/dist/esm/types/fields.js +6 -0
  36. package/dist/esm/types/tables.d.ts +16 -0
  37. package/package.json +9 -1
@@ -71,6 +71,7 @@ const FIELD_TYPE_MAP = {
71
71
  formula: "any",
72
72
  created_at: "string",
73
73
  updated_at: "string",
74
+ created_by: "string",
74
75
  updated_by: "string",
75
76
  };
76
77
  /**
@@ -96,7 +97,7 @@ const FIELD_INPUT_TYPE_MAP = {
96
97
  * rather than typed and then refused at runtime.
97
98
  *
98
99
  * Mirrors `COMPUTED_FIELD_TYPES` in the product's own `shared/bases/fields`.
99
- * The first six are rejected by `createRecordDataSchema` — each has a
100
+ * The first seven are rejected by `createRecordDataSchema` — each has a
100
101
  * `refine(val => val == null)`, so a non-null write errors (null is a no-op
101
102
  * clear). `created_at` / `updated_at` are refused differently: they have no
102
103
  * column at all, so a write is silently dropped, which is the worse outcome to
@@ -108,6 +109,7 @@ const READ_ONLY_FIELD_TYPES = new Set([
108
109
  "source",
109
110
  "formula",
110
111
  "autonumber",
112
+ "created_by",
111
113
  "updated_by",
112
114
  "created_at",
113
115
  "updated_at",
@@ -507,7 +509,7 @@ export function generateDbTs(inputSchema) {
507
509
  lines.push("// filters: { fieldName: value } for equality, or { fieldName: { <op>: value } }");
508
510
  lines.push("// operators: contains, not, in, notIn, lt, lte, gt, gte");
509
511
  lines.push('// `not: null` means "is set". An empty `in: []` matches nothing; an', "// empty `notIn: []` applies no filter.");
510
- lines.push("// sort is currently IGNORED here — it is stripped before the request.", "// (it does work on zite.auth.findAllUsers). Order in SQL instead.");
512
+ lines.push('// sort: [{ field: "fieldName", direction: "asc" | "desc" }]');
511
513
  lines.push("// limit defaults to 500, max 2000; offset is a row count (a number)");
512
514
  lines.push("// a filter value of `undefined` is REJECTED (it would query unfiltered", "// and match an arbitrary record). Check the value first.");
513
515
  lines.push("// .findOne({ id?, filters?, fields? }) → T | undefined");
@@ -1316,7 +1318,7 @@ export function generateBackendWrapperTs(envVarNames = []) {
1316
1318
  " execute: (",
1317
1319
  " params: {",
1318
1320
  " input: ZiteEndpointInput<TInput, TTrigger>;",
1319
- " /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. In a run fired by a schedule, webhook or trigger, step.sleep(name, \"2d\") pauses the run and a failed step is tried again. Provided by the platform; never define a local stand-in. */",
1321
+ ' /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. In a run fired by a schedule, webhook or trigger, step.sleep(name, "2d") pauses the run and a failed step is tried again. Provided by the platform; never define a local stand-in. */',
1320
1322
  " step: ZiteStep;",
1321
1323
  " context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;",
1322
1324
  // Mirrors the base module: a trigger's run gets `trigger`.
@@ -1381,18 +1383,20 @@ export function generateEmailSdk(integrationId) {
1381
1383
  "// Always use 'zitejs/email' — never a relative path like '../../.zite/integrations/email'.",
1382
1384
  "// The tsconfig aliases resolve zitejs/* imports to the correct .zite/ files.",
1383
1385
  "//",
1386
+ "// await Email.send({ to, subject, html: '<p>...</p>' })",
1384
1387
  "// await Email.send({ to, subject, body: [{ type: 'text', content: '...' }] })",
1385
- "// => { success: boolean; messageId: string }",
1388
+ "// => { success: boolean; messageId: string; warnings?: string[] }",
1386
1389
  "//",
1387
- "// RTL languages (Hebrew, Arabic): pass direction: 'rtl' — dir attributes",
1388
- "// inside body text are stripped by the sanitizer and will not work.",
1390
+ "// RTL languages (Hebrew, Arabic): pass direction: 'rtl'.",
1389
1391
  "",
1390
1392
  "import { createEmailClient } from 'zitejs/runtime';",
1391
1393
  "",
1392
1394
  "export type {",
1393
1395
  " EmailBlock,",
1396
+ " SendBlocksEmailParams,",
1394
1397
  " SendEmailParams,",
1395
1398
  " SendEmailResult,",
1399
+ " SendHtmlEmailParams,",
1396
1400
  "} from 'zitejs/runtime';",
1397
1401
  "",
1398
1402
  `export const Email = createEmailClient(${tsSingleQuoted(integrationId)});`,
@@ -422,44 +422,98 @@ describe('findEmailIntegrationId', () => {
422
422
  expect(findEmailIntegrationId(undefined, undefined)).toBeUndefined();
423
423
  });
424
424
  });
425
- describe('generateIntegrationsIndex', () => {
426
- // Not import.meta: this file also compiles to CommonJS. Vitest runs from the repo root.
427
- const runtimePath = resolve('src/runtime/index.ts');
428
- /** Type errors in `usage` compiled beside the generated file, `zitejs/runtime` mapped to this source. */
429
- const typeErrorsIn = (generated, usage, airtable) => {
430
- const files = {
431
- '/app/.zite/integrations/index.ts': generated,
432
- ...(airtable ? { '/app/.zite/integrations/airtable.ts': airtable } : {}),
433
- '/app/src/usage.ts': usage,
434
- };
435
- const options = {
436
- strict: true,
437
- noEmit: true,
438
- target: ts.ScriptTarget.ES2022,
439
- module: ts.ModuleKind.ESNext,
440
- moduleResolution: ts.ModuleResolutionKind.Bundler,
441
- skipLibCheck: true,
442
- baseUrl: '/app',
443
- paths: {
444
- 'zitejs/runtime': [runtimePath],
445
- 'zitejs/integrations': ['/app/.zite/integrations/index.ts'],
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 },
@@ -507,6 +561,16 @@ describe('generateIntegrationsIndex', () => {
507
561
  const jira = await integrations.get('tickets');
508
562
  const cloudId: string = jira.cloudId;
509
563
  const siteUrl: string = jira.siteUrl;
564
+ `)).toEqual([
565
+ expect.stringContaining("Type 'string | undefined' is not assignable"),
566
+ ]);
567
+ });
568
+ it('types the Shopify storefront URL as always present and only its token as optional', () => {
569
+ const generated = generateIntegrationsIndex([{ name: 'shopify', serviceType: 'shopify', perUser: false }], { reexportAirtable: false });
570
+ expect(typeErrorsIn(generated, `import { integrations } from 'zitejs/integrations';
571
+ const shop = await integrations.get('shopify');
572
+ const storefrontApiUrl: string = shop.storefrontApiUrl;
573
+ const storefrontAccessToken: string = shop.storefrontAccessToken;
510
574
  `)).toEqual([
511
575
  expect.stringContaining("Type 'string | undefined' is not assignable"),
512
576
  ]);
@@ -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>;
@@ -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.147",
3
+ "version": "0.9.149",
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
  ],