zitejs 0.9.63 → 0.9.64

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; } });
@@ -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.
@@ -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) {
@@ -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';
@@ -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.
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.63",
3
+ "version": "0.9.64",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",