@palbase/backend 34.0.0 → 34.1.1

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 (52) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bin/palbase-backend.cjs +275 -30
  3. package/dist/bin/palbase-backend.cjs.map +1 -1
  4. package/dist/bin/palbase-backend.js +4 -4
  5. package/dist/{chunk-SEM36BWY.js → chunk-5UGPXKMJ.js} +60 -12
  6. package/dist/chunk-5UGPXKMJ.js.map +1 -0
  7. package/dist/{chunk-FOWA7PF4.js → chunk-P7MGSAFT.js} +6 -1
  8. package/dist/{chunk-FOWA7PF4.js.map → chunk-P7MGSAFT.js.map} +1 -1
  9. package/dist/{chunk-YX7UA7VC.js → chunk-X2UYIXDS.js} +8 -2
  10. package/dist/chunk-X2UYIXDS.js.map +1 -0
  11. package/dist/{chunk-MNGZE2MM.js → chunk-XZPDPYVY.js} +279 -34
  12. package/dist/chunk-XZPDPYVY.js.map +1 -0
  13. package/dist/{chunk-LOGL2ZHD.js → chunk-YO5GYM73.js} +2 -2
  14. package/dist/db/index.cjs +34 -10
  15. package/dist/db/index.cjs.map +1 -1
  16. package/dist/db/index.d.cts +2 -2
  17. package/dist/db/index.d.ts +2 -2
  18. package/dist/db/index.js +2 -2
  19. package/dist/{endpoint-DpNUx-ON.d.ts → endpoint-BXPdsTA5.d.ts} +56 -2
  20. package/dist/{endpoint-kYgEHrrV.d.cts → endpoint-DqhUP7RT.d.cts} +56 -2
  21. package/dist/engine/index.cjs +275 -30
  22. package/dist/engine/index.cjs.map +1 -1
  23. package/dist/engine/index.d.cts +3 -3
  24. package/dist/engine/index.d.ts +3 -3
  25. package/dist/engine/index.js +4 -4
  26. package/dist/{index-pnDsEfxJ.d.cts → index-Co0Hj_aO.d.cts} +2 -2
  27. package/dist/{index-JrHqNsjQ.d.ts → index-MhCL7ll4.d.ts} +2 -2
  28. package/dist/index.cjs +79 -21
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +6 -6
  31. package/dist/index.d.ts +6 -6
  32. package/dist/index.js +6 -4
  33. package/dist/index.js.map +1 -1
  34. package/dist/openapi/index.d.cts +2 -2
  35. package/dist/openapi/index.d.ts +2 -2
  36. package/dist/{registry-BcOd8Zhf.d.cts → registry-BkIVHPzB.d.cts} +1 -1
  37. package/dist/{registry-BoX5iNyY.d.ts → registry-CvGLR5j1.d.ts} +1 -1
  38. package/dist/test/index.cjs.map +1 -1
  39. package/dist/test/index.d.cts +1 -1
  40. package/dist/test/index.d.ts +1 -1
  41. package/dist/test/index.js +2 -2
  42. package/dist/test/index.js.map +1 -1
  43. package/docs/auth.md +58 -0
  44. package/docs/llms-full.txt +73 -0
  45. package/docs/schema.md +15 -0
  46. package/package.json +15 -15
  47. package/template/db/public.ts +12 -0
  48. package/template/scripts/test.sh +0 -0
  49. package/dist/chunk-MNGZE2MM.js.map +0 -1
  50. package/dist/chunk-SEM36BWY.js.map +0 -1
  51. package/dist/chunk-YX7UA7VC.js.map +0 -1
  52. /package/dist/{chunk-LOGL2ZHD.js.map → chunk-YO5GYM73.js.map} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  assertPlanRetry,
4
4
  qualifiedTableKey,
5
5
  runTxPlan
6
- } from "./chunk-FOWA7PF4.js";
6
+ } from "./chunk-P7MGSAFT.js";
7
7
  import {
8
8
  __name
9
9
  } from "./chunk-VXPNPVAG.js";
@@ -417,4 +417,4 @@ export {
417
417
  Flags,
418
418
  Realtime
419
419
  };
420
- //# sourceMappingURL=chunk-LOGL2ZHD.js.map
420
+ //# sourceMappingURL=chunk-YO5GYM73.js.map
package/dist/db/index.cjs CHANGED
@@ -63,6 +63,7 @@ function qualifiedTableKey(schemaName, tableName) {
63
63
  __name(qualifiedTableKey, "qualifiedTableKey");
64
64
 
65
65
  // src/db/policy.ts
66
+ var import_zod = require("zod");
66
67
  var PolicyExprRef = class _PolicyExprRef {
67
68
  static {
68
69
  __name(this, "PolicyExprRef");
@@ -295,6 +296,24 @@ function policy(name) {
295
296
  return new PolicyBuilder(name);
296
297
  }
297
298
  __name(policy, "policy");
299
+ function reservedCanRelation(tableName, columns) {
300
+ if (tableName === "can") {
301
+ return `a table named "can" would put a relation named "can" on every parent it references \u2014 rename the table`;
302
+ }
303
+ for (const [col, b] of Object.entries(columns)) {
304
+ const def = b._def;
305
+ if (def.referencesThunk === void 0 && def.selfRefColumn === void 0) continue;
306
+ if (def.reverseAs === "can") {
307
+ return `column "${col}" names its reverse relation "can" \u2014 the parent's rows would carry a relation where can is reserved; pick another reverseAs`;
308
+ }
309
+ const forward = def.owns === true ? "owner" : def.refAs ?? (col.endsWith("_id") ? col.slice(0, -3) : col);
310
+ if (forward === "can") {
311
+ return `column "${col}" would be read as a relation named "can" (${def.refAs === void 0 ? "derived from the column name" : "its as: option"}) \u2014 can is reserved for the policy echo; rename it`;
312
+ }
313
+ }
314
+ return null;
315
+ }
316
+ __name(reservedCanRelation, "reservedCanRelation");
298
317
 
299
318
  // src/db/schema.ts
300
319
  var IndexBuilder = class {
@@ -368,6 +387,10 @@ function defineTable(name, input) {
368
387
  if (name.trim() === "") {
369
388
  throw new Error("defineTable(name, \u2026): name must not be empty");
370
389
  }
390
+ {
391
+ const reserved = reservedCanRelation(name, input.columns);
392
+ if (reserved !== null) throw new Error(`defineTable(${JSON.stringify(name)}): ${reserved}`);
393
+ }
371
394
  const policies = (input.policies?.(exprCtx(Object.keys(input.columns), 0, name)) ?? []).map(toPolicyDef);
372
395
  const rls = policies.length > 0 || input.rls !== false;
373
396
  const owned = {};
@@ -396,6 +419,7 @@ function defineTable(name, input) {
396
419
  const declaredIndexes = (input.indexes?.(exprCtx(Object.keys(input.columns), 0, name)) ?? []).map((i) => i instanceof IndexBuilder ? i._def : i);
397
420
  if (declaredIndexes.length > 0) def.indexes = declaredIndexes;
398
421
  if (input.appendOnly === true) def.appendOnly = true;
422
+ if (input.ignored === true) def.ignored = true;
399
423
  if (input.search !== void 0) {
400
424
  const s = input.search;
401
425
  if (s.from !== void 0) {
@@ -553,7 +577,7 @@ function defineSchema(name, input) {
553
577
  __name(defineSchema, "defineSchema");
554
578
 
555
579
  // src/db/query.ts
556
- var import_zod = require("zod");
580
+ var import_zod2 = require("zod");
557
581
  var import_zod_to_openapi = require("@asteasolutions/zod-to-openapi");
558
582
 
559
583
  // src/db/query-contract.ts
@@ -586,27 +610,27 @@ function stableContract(value) {
586
610
  __name(stableContract, "stableContract");
587
611
 
588
612
  // src/db/query.ts
589
- (0, import_zod_to_openapi.extendZodWithOpenApi)(import_zod.z);
613
+ (0, import_zod_to_openapi.extendZodWithOpenApi)(import_zod2.z);
590
614
  function responseColumn(column, validator) {
591
615
  const contract = queryColumnContract(column);
592
616
  let schema;
593
617
  if (validator) return validator;
594
- if (contract.codec === "number") schema = import_zod.z.number().finite();
595
- else if (contract.codec === "decimal") schema = import_zod.z.string();
618
+ if (contract.codec === "number") schema = import_zod2.z.number().finite();
619
+ else if (contract.codec === "decimal") schema = import_zod2.z.string();
596
620
  else switch (contract.type) {
597
621
  case "integer":
598
- schema = import_zod.z.number().int().min(-2147483648).max(2147483647);
622
+ schema = import_zod2.z.number().int().min(-2147483648).max(2147483647);
599
623
  break;
600
624
  case "boolean":
601
- schema = import_zod.z.boolean();
625
+ schema = import_zod2.z.boolean();
602
626
  break;
603
627
  case "vector":
604
- schema = import_zod.z.array(import_zod.z.number().finite());
628
+ schema = import_zod2.z.array(import_zod2.z.number().finite());
605
629
  break;
606
630
  case "enum": {
607
631
  const values = contract.enumValues;
608
632
  if (!values?.length) throw new Error("Query response requires declared enum values");
609
- schema = import_zod.z.enum(values);
633
+ schema = import_zod2.z.enum(values);
610
634
  break;
611
635
  }
612
636
  case "uuid":
@@ -614,7 +638,7 @@ function responseColumn(column, validator) {
614
638
  case "timestamp":
615
639
  case "numeric":
616
640
  case "bigint":
617
- schema = import_zod.z.string();
641
+ schema = import_zod2.z.string();
618
642
  break;
619
643
  case "jsonb":
620
644
  throw new Error("Query response requires a fields validator for a selected jsonb column: its TypeScript payload is erased at runtime");
@@ -637,7 +661,7 @@ function defineQuery(name, options) {
637
661
  columns[key] = queryColumnContract(options.table[key]);
638
662
  shape[key] = responseColumn(options.table[key], options.fields?.[key]);
639
663
  }
640
- const response = import_zod.z.array(import_zod.z.object(shape).strict());
664
+ const response = import_zod2.z.array(import_zod2.z.object(shape).strict());
641
665
  const queryInput = options.input, where = options.where, limit = options.limit;
642
666
  const orderBy = options.orderBy === void 0 ? void 0 : JSON.parse(JSON.stringify(options.orderBy));
643
667
  const prepare = /* @__PURE__ */ __name((input) => {