zitejs 0.9.63 → 0.9.65

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.
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCaller = void 0;
4
+ var index_js_1 = require("../caller/index.js");
5
+ Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTableClient = void 0;
4
+ var index_js_1 = require("../runtime/index.js");
5
+ Object.defineProperty(exports, "createTableClient", { enumerable: true, get: function () { return index_js_1.createTableClient; } });
@@ -1,5 +1,13 @@
1
1
  import type { NotificationsCreateParams, NotificationsCreateResult } from "../notifications/index.js";
2
2
  import type { MetaListUsersResult } from "../meta/index.js";
3
+ export interface BulkCreateResult<T> {
4
+ success: boolean;
5
+ records: T[];
6
+ }
7
+ export interface DeleteResult {
8
+ success: boolean;
9
+ id: string;
10
+ }
3
11
  export interface TableClient<T> {
4
12
  findAll(options?: {
5
13
  limit?: number;
@@ -9,23 +17,20 @@ export interface TableClient<T> {
9
17
  filters?: unknown;
10
18
  }): Promise<{
11
19
  records: T[];
12
- total: number;
13
20
  hasMore: boolean;
14
21
  }>;
15
22
  findOne(recordId: string | {
16
23
  filters?: unknown;
17
24
  filter?: unknown;
18
- }): Promise<T>;
25
+ }): Promise<T | undefined>;
19
26
  create(data: {
20
27
  record: Partial<T>;
21
28
  }): Promise<T>;
22
29
  update(id: string, data: {
23
30
  record: Partial<T>;
24
31
  }): Promise<T>;
25
- delete(id: string): Promise<{
26
- deleted: true;
27
- }>;
28
- bulkCreate(records: Partial<T>[]): Promise<T[]>;
32
+ delete(id: string): Promise<DeleteResult>;
33
+ bulkCreate(records: Partial<T>[]): Promise<BulkCreateResult<T>>;
29
34
  }
30
35
  export declare function createTableClient<T>(className: string): TableClient<T>;
31
36
  export interface SqlResult {
@@ -57,14 +62,15 @@ export interface AirtableTableClient<T> {
57
62
  }): Promise<T | undefined>;
58
63
  create(data: {
59
64
  record: Partial<T>;
60
- }): Promise<T>;
65
+ }): Promise<T | undefined>;
61
66
  bulkCreate(records: Partial<T>[]): Promise<T[]>;
62
67
  update(id: string, data: {
63
68
  record: Partial<T>;
64
- }): Promise<T>;
65
- delete(id: string): Promise<{
66
- deleted: true;
67
- }>;
69
+ }): Promise<{
70
+ id: string;
71
+ fields: T;
72
+ } | undefined>;
73
+ delete(id: string): Promise<DeleteResult>;
68
74
  }
69
75
  export declare function createAirtableClient<T>(integrationId: string, className: string, implicitParams: Record<string, unknown>): AirtableTableClient<T>;
70
76
  export declare function createNotificationsClient(): {
@@ -240,6 +240,53 @@ function generateSentinelSdkTypes() {
240
240
  "",
241
241
  ];
242
242
  }
243
+ function buildLinkTableComments(schema) {
244
+ const tablesById = new Map();
245
+ for (const t of schema.tables)
246
+ tablesById.set(t.id, t);
247
+ const seen = new Set();
248
+ const entries = [];
249
+ for (const table of schema.tables) {
250
+ for (const field of table.fields) {
251
+ if (field.definition.type !== "linked_record")
252
+ continue;
253
+ const tpl = field.definition.template;
254
+ if (tpl.isInverse)
255
+ continue;
256
+ const targetId = tpl.tableId;
257
+ if (!targetId)
258
+ continue;
259
+ const target = tablesById.get(targetId);
260
+ if (!target)
261
+ continue;
262
+ const sourceSdk = toPascalCase(table.sdkName);
263
+ const targetSdk = toPascalCase(target.sdkName);
264
+ const [first, second] = [sourceSdk, targetSdk].sort();
265
+ const linkName = `${first}${second}`;
266
+ if (seen.has(linkName))
267
+ continue;
268
+ seen.add(linkName);
269
+ const isSelf = table.id === targetId;
270
+ const col1 = isSelf
271
+ ? `source${first}Id`
272
+ : `${first.charAt(0).toLowerCase()}${first.slice(1)}Id`;
273
+ const col2 = isSelf
274
+ ? `target${second}Id`
275
+ : `${second.charAt(0).toLowerCase()}${second.slice(1)}Id`;
276
+ entries.push({ name: linkName, cols: [col1, col2] });
277
+ }
278
+ }
279
+ if (entries.length === 0)
280
+ return [];
281
+ const lines = [
282
+ "//",
283
+ "// Link tables for zite.sql() JOINs (use these exact names):",
284
+ ];
285
+ for (const e of entries) {
286
+ lines.push(`// "${e.name}" — columns: "${e.cols[0]}", "${e.cols[1]}"`);
287
+ }
288
+ return lines;
289
+ }
243
290
  /**
244
291
  * Generate .zite/db.ts purely from ZiteSchema.
245
292
  * Pure function — no external data needed beyond what's in the schema file.
@@ -255,13 +302,13 @@ function generateDbTs(schema) {
255
302
  lines.push("// The tsconfig aliases resolve zitejs/* imports to the correct .zite/ files.");
256
303
  lines.push("//");
257
304
  lines.push("// Table client methods:");
258
- lines.push("// .findAll(opts?) → { records: T[], total: number, hasMore: boolean }");
305
+ lines.push("// .findAll(opts?) → { records: T[], hasMore: boolean }");
259
306
  lines.push("// opts: { limit?, offset?, sort?, filter?, filters? }");
260
- lines.push("// .findOne(id | { filters }) → T");
307
+ lines.push("// .findOne(id | { filters }) → T | undefined");
261
308
  lines.push("// .create({ record }) → T");
262
309
  lines.push("// .update(id, { record }) → T");
263
- lines.push("// .delete(id) → { deleted: true }");
264
- lines.push("// .bulkCreate(records) → T[]");
310
+ lines.push("// .delete(id) → { success: boolean, id: string }");
311
+ lines.push("// .bulkCreate(records) → { success: boolean, records: T[] }");
265
312
  lines.push("//");
266
313
  lines.push("// Raw SQL (read-only SELECTs for aggregates, joins, multi-table queries):");
267
314
  lines.push('// zite.sql({ query: "SELECT ...", params?: [...] })');
@@ -271,11 +318,10 @@ function generateDbTs(schema) {
271
318
  lines.push("// - Use SDK names for tables (PascalCase) and fields (camelCase)");
272
319
  lines.push('// - ALWAYS double-quote every identifier: FROM "Orders", WHERE "status" = $1');
273
320
  lines.push("// - Use params array for user input ($1, $2, ...): never interpolate into SQL");
274
- lines.push('// - Link tables: alphabetical PascalCase concat (Items+Orders → "ItemsOrders")');
275
- lines.push('// with id columns: "itemsId", "ordersId"');
276
321
  lines.push("// - Soft-deleted rows are excluded automatically — no WHERE deleted_at IS NULL");
277
322
  lines.push("// - SELECT only — use .create/.update/.delete for writes");
278
323
  lines.push('// - Load the "zite:sql" skill for full SQL reference (formulas, lookups, etc.)');
324
+ lines.push(...buildLinkTableComments(schema));
279
325
  lines.push("import { createTableClient, createSqlClient, createNotificationsClient, createMetaClient } from 'zitejs/runtime';");
280
326
  lines.push("");
281
327
  for (const table of schema.tables) {
@@ -597,10 +643,10 @@ function generateAirtableTs(lock) {
597
643
  "// findAll(options?: { offset?: string; limit?: number; filters?: unknown })",
598
644
  "// => Promise<{ records: T[]; offset: string | undefined; hasMore: boolean }>",
599
645
  "// findOne(params: { id?: string; filters?: unknown }) => Promise<T | undefined>",
600
- "// create(data: { record: Partial<T> }) => Promise<T>",
646
+ "// create(data: { record: Partial<T> }) => Promise<T | undefined>",
601
647
  "// bulkCreate(records: Partial<T>[]) => Promise<T[]>",
602
- "// update(id: string, data: { record: Partial<T> }) => Promise<T>",
603
- "// delete(id: string) => Promise<{ deleted: true }>",
648
+ "// update(id: string, data: { record: Partial<T> }) => Promise<{ id: string, fields: T } | undefined>",
649
+ "// delete(id: string) => Promise<{ success: boolean, id: string }>",
604
650
  "//",
605
651
  "// Usage tips:",
606
652
  "// - Airtable has a strict rate limit of 5 requests/second per base",
@@ -0,0 +1,2 @@
1
+ export { createCaller } from '../caller/index.js';
2
+ export type { EndpointConfig } from '../caller/index.js';
@@ -0,0 +1 @@
1
+ export { createCaller } from '../caller/index.js';
package/dist/esm/cli.js CHANGED
File without changes
@@ -0,0 +1,2 @@
1
+ export { createTableClient } from '../runtime/index.js';
2
+ export type { TableClient } from '../runtime/index.js';
@@ -0,0 +1 @@
1
+ export { createTableClient } from '../runtime/index.js';
@@ -1,5 +1,13 @@
1
1
  import type { NotificationsCreateParams, NotificationsCreateResult } from "../notifications/index.js";
2
2
  import type { MetaListUsersResult } from "../meta/index.js";
3
+ export interface BulkCreateResult<T> {
4
+ success: boolean;
5
+ records: T[];
6
+ }
7
+ export interface DeleteResult {
8
+ success: boolean;
9
+ id: string;
10
+ }
3
11
  export interface TableClient<T> {
4
12
  findAll(options?: {
5
13
  limit?: number;
@@ -9,23 +17,20 @@ export interface TableClient<T> {
9
17
  filters?: unknown;
10
18
  }): Promise<{
11
19
  records: T[];
12
- total: number;
13
20
  hasMore: boolean;
14
21
  }>;
15
22
  findOne(recordId: string | {
16
23
  filters?: unknown;
17
24
  filter?: unknown;
18
- }): Promise<T>;
25
+ }): Promise<T | undefined>;
19
26
  create(data: {
20
27
  record: Partial<T>;
21
28
  }): Promise<T>;
22
29
  update(id: string, data: {
23
30
  record: Partial<T>;
24
31
  }): Promise<T>;
25
- delete(id: string): Promise<{
26
- deleted: true;
27
- }>;
28
- bulkCreate(records: Partial<T>[]): Promise<T[]>;
32
+ delete(id: string): Promise<DeleteResult>;
33
+ bulkCreate(records: Partial<T>[]): Promise<BulkCreateResult<T>>;
29
34
  }
30
35
  export declare function createTableClient<T>(className: string): TableClient<T>;
31
36
  export interface SqlResult {
@@ -57,14 +62,15 @@ export interface AirtableTableClient<T> {
57
62
  }): Promise<T | undefined>;
58
63
  create(data: {
59
64
  record: Partial<T>;
60
- }): Promise<T>;
65
+ }): Promise<T | undefined>;
61
66
  bulkCreate(records: Partial<T>[]): Promise<T[]>;
62
67
  update(id: string, data: {
63
68
  record: Partial<T>;
64
- }): Promise<T>;
65
- delete(id: string): Promise<{
66
- deleted: true;
67
- }>;
69
+ }): Promise<{
70
+ id: string;
71
+ fields: T;
72
+ } | undefined>;
73
+ delete(id: string): Promise<DeleteResult>;
68
74
  }
69
75
  export declare function createAirtableClient<T>(integrationId: string, className: string, implicitParams: Record<string, unknown>): AirtableTableClient<T>;
70
76
  export declare function createNotificationsClient(): {
@@ -229,6 +229,53 @@ function generateSentinelSdkTypes() {
229
229
  "",
230
230
  ];
231
231
  }
232
+ function buildLinkTableComments(schema) {
233
+ const tablesById = new Map();
234
+ for (const t of schema.tables)
235
+ tablesById.set(t.id, t);
236
+ const seen = new Set();
237
+ const entries = [];
238
+ for (const table of schema.tables) {
239
+ for (const field of table.fields) {
240
+ if (field.definition.type !== "linked_record")
241
+ continue;
242
+ const tpl = field.definition.template;
243
+ if (tpl.isInverse)
244
+ continue;
245
+ const targetId = tpl.tableId;
246
+ if (!targetId)
247
+ continue;
248
+ const target = tablesById.get(targetId);
249
+ if (!target)
250
+ continue;
251
+ const sourceSdk = toPascalCase(table.sdkName);
252
+ const targetSdk = toPascalCase(target.sdkName);
253
+ const [first, second] = [sourceSdk, targetSdk].sort();
254
+ const linkName = `${first}${second}`;
255
+ if (seen.has(linkName))
256
+ continue;
257
+ seen.add(linkName);
258
+ const isSelf = table.id === targetId;
259
+ const col1 = isSelf
260
+ ? `source${first}Id`
261
+ : `${first.charAt(0).toLowerCase()}${first.slice(1)}Id`;
262
+ const col2 = isSelf
263
+ ? `target${second}Id`
264
+ : `${second.charAt(0).toLowerCase()}${second.slice(1)}Id`;
265
+ entries.push({ name: linkName, cols: [col1, col2] });
266
+ }
267
+ }
268
+ if (entries.length === 0)
269
+ return [];
270
+ const lines = [
271
+ "//",
272
+ "// Link tables for zite.sql() JOINs (use these exact names):",
273
+ ];
274
+ for (const e of entries) {
275
+ lines.push(`// "${e.name}" — columns: "${e.cols[0]}", "${e.cols[1]}"`);
276
+ }
277
+ return lines;
278
+ }
232
279
  /**
233
280
  * Generate .zite/db.ts purely from ZiteSchema.
234
281
  * Pure function — no external data needed beyond what's in the schema file.
@@ -244,13 +291,13 @@ export function generateDbTs(schema) {
244
291
  lines.push("// The tsconfig aliases resolve zitejs/* imports to the correct .zite/ files.");
245
292
  lines.push("//");
246
293
  lines.push("// Table client methods:");
247
- lines.push("// .findAll(opts?) → { records: T[], total: number, hasMore: boolean }");
294
+ lines.push("// .findAll(opts?) → { records: T[], hasMore: boolean }");
248
295
  lines.push("// opts: { limit?, offset?, sort?, filter?, filters? }");
249
- lines.push("// .findOne(id | { filters }) → T");
296
+ lines.push("// .findOne(id | { filters }) → T | undefined");
250
297
  lines.push("// .create({ record }) → T");
251
298
  lines.push("// .update(id, { record }) → T");
252
- lines.push("// .delete(id) → { deleted: true }");
253
- lines.push("// .bulkCreate(records) → T[]");
299
+ lines.push("// .delete(id) → { success: boolean, id: string }");
300
+ lines.push("// .bulkCreate(records) → { success: boolean, records: T[] }");
254
301
  lines.push("//");
255
302
  lines.push("// Raw SQL (read-only SELECTs for aggregates, joins, multi-table queries):");
256
303
  lines.push('// zite.sql({ query: "SELECT ...", params?: [...] })');
@@ -260,11 +307,10 @@ export function generateDbTs(schema) {
260
307
  lines.push("// - Use SDK names for tables (PascalCase) and fields (camelCase)");
261
308
  lines.push('// - ALWAYS double-quote every identifier: FROM "Orders", WHERE "status" = $1');
262
309
  lines.push("// - Use params array for user input ($1, $2, ...): never interpolate into SQL");
263
- lines.push('// - Link tables: alphabetical PascalCase concat (Items+Orders → "ItemsOrders")');
264
- lines.push('// with id columns: "itemsId", "ordersId"');
265
310
  lines.push("// - Soft-deleted rows are excluded automatically — no WHERE deleted_at IS NULL");
266
311
  lines.push("// - SELECT only — use .create/.update/.delete for writes");
267
312
  lines.push('// - Load the "zite:sql" skill for full SQL reference (formulas, lookups, etc.)');
313
+ lines.push(...buildLinkTableComments(schema));
268
314
  lines.push("import { createTableClient, createSqlClient, createNotificationsClient, createMetaClient } from 'zitejs/runtime';");
269
315
  lines.push("");
270
316
  for (const table of schema.tables) {
@@ -586,10 +632,10 @@ export function generateAirtableTs(lock) {
586
632
  "// findAll(options?: { offset?: string; limit?: number; filters?: unknown })",
587
633
  "// => Promise<{ records: T[]; offset: string | undefined; hasMore: boolean }>",
588
634
  "// findOne(params: { id?: string; filters?: unknown }) => Promise<T | undefined>",
589
- "// create(data: { record: Partial<T> }) => Promise<T>",
635
+ "// create(data: { record: Partial<T> }) => Promise<T | undefined>",
590
636
  "// bulkCreate(records: Partial<T>[]) => Promise<T[]>",
591
- "// update(id: string, data: { record: Partial<T> }) => Promise<T>",
592
- "// delete(id: string) => Promise<{ deleted: true }>",
637
+ "// update(id: string, data: { record: Partial<T> }) => Promise<{ id: string, fields: T } | undefined>",
638
+ "// delete(id: string) => Promise<{ success: boolean, id: string }>",
593
639
  "//",
594
640
  "// Usage tips:",
595
641
  "// - Airtable has a strict rate limit of 5 requests/second per base",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.63",
3
+ "version": "0.9.65",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",