okmodel 0.4.0 → 0.5.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 (102) hide show
  1. package/README.md +95 -12
  2. package/dist/contracts/catalog/document.d.ts +20 -0
  3. package/dist/contracts/driver.d.ts +7 -0
  4. package/dist/dialects/pg/filter-parse.d.ts +8 -2
  5. package/dist/dialects/pg/fn/index.js +8 -0
  6. package/dist/dialects/pg/index.js +8 -2
  7. package/dist/dialects/pg/introspect.d.ts +6 -0
  8. package/dist/dialects/pg/ops/or.d.ts +1 -1
  9. package/dist/dialects/pg/role/sql.d.ts +10 -0
  10. package/dist/dialects/pg/schema.d.ts +15 -6
  11. package/dist/dialects/pg/temporal.d.ts +5 -76
  12. package/dist/dialects/pg/view/index.d.ts +20 -6
  13. package/dist/dialects/pg/view/index.js +1 -1
  14. package/dist/dialects/pg/view/scratch.d.ts +2 -2
  15. package/dist/runtime/client.d.ts +6 -1
  16. package/dist/runtime/conflict.d.ts +2 -1
  17. package/dist/runtime/pg/bun.d.ts +12 -7
  18. package/dist/runtime/pg/bun.js +7 -4
  19. package/dist/runtime/pg/pg.d.ts +12 -6
  20. package/dist/runtime/pg/pg.js +7 -4
  21. package/dist/runtime/pg/pglite.d.ts +11 -3
  22. package/dist/runtime/pg/pglite.js +7 -4
  23. package/dist/runtime/pg/postgresjs.d.ts +12 -6
  24. package/dist/runtime/pg/postgresjs.js +7 -4
  25. package/dist/runtime/plan.d.ts +16 -1
  26. package/dist/runtime/tenancy/index.js +1 -1
  27. package/dist/runtime/topology.d.ts +191 -0
  28. package/dist/runtime/traits/index.js +7 -7
  29. package/dist/runtime/types.d.ts +57 -2
  30. package/dist/runtime/validate/index.js +3 -3
  31. package/dist/shared/{radd3z4g.js → 0t22wwh1.js} +5 -9
  32. package/dist/shared/{ady1ms74.js → 2pqx26h8.js} +25 -10
  33. package/dist/shared/{kyxb62mc.js → 31vm914h.js} +9 -1
  34. package/dist/shared/{jns2wx4t.js → 32zqc1dw.js} +18 -7
  35. package/dist/shared/{nxb42q7h.js → 47x8x9ze.js} +2 -2
  36. package/dist/shared/{zvbjc949.js → 4az561fn.js} +1 -1
  37. package/dist/shared/{s6gqfn5j.js → 51mvgj8w.js} +27 -3
  38. package/dist/shared/{k3ted12y.js → 54tqkxja.js} +20 -2
  39. package/dist/shared/{3p4b1fg0.js → 5enne4ma.js} +1 -1
  40. package/dist/shared/{6693j9rs.js → 5fqx9yh4.js} +6 -2
  41. package/dist/shared/{c5g81ngb.js → 6mnp99hx.js} +11 -8
  42. package/dist/shared/{hqjsxnz7.js → 6qd27mx0.js} +5 -4
  43. package/dist/shared/{v7tpnhnz.js → 6rk2gen5.js} +5 -3
  44. package/dist/shared/{2321avmn.js → 7zwwyh0v.js} +46 -16
  45. package/dist/shared/{fa9vt245.js → 87jvvhnt.js} +2 -2
  46. package/dist/shared/{8jb4ymh2.js → 8bwbwy8h.js} +12 -1
  47. package/dist/shared/{c8aghh05.js → 8rsy3hxz.js} +7 -1
  48. package/dist/shared/{41kv2xdm.js → 8xsbagad.js} +1 -1
  49. package/dist/shared/{6p5k20sm.js → 96qcj21c.js} +3 -3
  50. package/dist/shared/{jgxzjzcz.js → aj2qxyhj.js} +2 -2
  51. package/dist/shared/{5vdm4sgp.js → caw8b9d8.js} +4 -4
  52. package/dist/shared/{s4mb6a4b.js → cctw17hj.js} +74 -15
  53. package/dist/shared/{rrstp3kb.js → cgbamx3e.js} +2 -2
  54. package/dist/shared/{axhk06q1.js → cr74e96e.js} +1 -1
  55. package/dist/shared/{b066g80h.js → efmy2gcg.js} +2 -2
  56. package/dist/shared/{gdh9mrtp.js → f5cw5q5r.js} +2 -2
  57. package/dist/shared/{xghkt7a9.js → fancm5pt.js} +6 -233
  58. package/dist/shared/{n5y9zyj1.js → ga3sfy93.js} +369 -14
  59. package/dist/shared/{xrfnq5k8.js → gbtcc2d7.js} +55 -5
  60. package/dist/shared/{7nk68fj8.js → gde73es6.js} +20 -15
  61. package/dist/shared/{kkzwp3d2.js → hf22e0wt.js} +55 -19
  62. package/dist/shared/{tny2t3sm.js → janx09m5.js} +8 -7
  63. package/dist/shared/{4ef7mmqf.js → jwtxdj06.js} +5 -5
  64. package/dist/shared/{sf8m6tfy.js → k8v5v5wj.js} +3 -3
  65. package/dist/shared/{qn0srwwq.js → kfjp0gck.js} +5 -3
  66. package/dist/shared/{wqem4jed.js → krxx77g0.js} +7 -7
  67. package/dist/shared/{edwqqryd.js → nkaxvt9q.js} +1 -1
  68. package/dist/shared/{jsd07prz.js → ntneex2a.js} +1 -1
  69. package/dist/shared/nxdp2ze3.js +1197 -0
  70. package/dist/shared/{tbszx8mz.js → pf0d8f77.js} +1 -1
  71. package/dist/shared/{84ptn35q.js → ps7a6h14.js} +10 -9
  72. package/dist/shared/{kj680nxv.js → q58y17hy.js} +9 -7
  73. package/dist/shared/{awrsqrn7.js → qm7cdtvr.js} +22 -9
  74. package/dist/shared/{q6zsyh31.js → qv2ydck9.js} +156 -205
  75. package/dist/shared/{kafaa5zv.js → r2sp8hrc.js} +28 -8
  76. package/dist/shared/{fb00y8fp.js → r8x5qhd7.js} +5 -5
  77. package/dist/shared/{yjw02enp.js → sdc7r2ww.js} +8 -7
  78. package/dist/shared/sycnx8gt.js +289 -0
  79. package/dist/shared/{hcmdtwgh.js → szm0cksa.js} +4 -1
  80. package/dist/shared/{zg24x0hm.js → tm5ab8we.js} +10 -2
  81. package/dist/shared/{ygem90rn.js → v36c5g6p.js} +85 -21
  82. package/dist/shared/wq9n6pwr.js +139 -0
  83. package/dist/shared/{7p2wbz7f.js → x72jb7ad.js} +1 -1
  84. package/dist/shared/{q795afwa.js → z2rnngj4.js} +3 -3
  85. package/dist/shared/{sr5ms7b3.js → zqrnhwsq.js} +3 -3
  86. package/dist/tooling/cli.js +70 -23
  87. package/dist/tooling/migrate/apply.d.ts +2 -0
  88. package/dist/tooling/migrate/commands.d.ts +1 -2
  89. package/dist/tooling/migrate/drift.d.ts +1 -1
  90. package/dist/tooling/migrate/estimate.d.ts +14 -1
  91. package/dist/tooling/migrate/files.d.ts +7 -0
  92. package/dist/tooling/migrate/index.js +12 -9
  93. package/dist/tooling/migrate/lint.d.ts +3 -3
  94. package/dist/tooling/migrate/plan.d.ts +7 -3
  95. package/dist/tooling/migrate/policy.d.ts +11 -0
  96. package/dist/tooling/migrate/sql-lex.d.ts +22 -0
  97. package/dist/tooling/testing/factories.d.ts +10 -0
  98. package/dist/tooling/testing/facts.d.ts +3 -0
  99. package/dist/tooling/testing/index.js +3 -3
  100. package/dist/tooling/testing/isolation.d.ts +4 -3
  101. package/package.json +6 -5
  102. package/dist/shared/0v1g424p.js +0 -26
@@ -51,4 +51,4 @@ function readCode(error, key) {
51
51
  return typeof value === "string" && value.length > 0 ? value : undefined;
52
52
  }
53
53
 
54
- export { isConnectionSqlstate, isConnectionFailure, isConnectionLost };
54
+ export { isConnectionSqlstate, isConnectionErrno, isConnectionFailure, isConnectionLost };
@@ -1,21 +1,22 @@
1
1
  import {
2
2
  open2
3
- } from "./wqem4jed.js";
3
+ } from "./krxx77g0.js";
4
+ import"./8bwbwy8h.js";
4
5
  import"./n442h54c.js";
5
- import"./8jb4ymh2.js";
6
6
  import {
7
7
  assertRoleHealth
8
- } from "./hcmdtwgh.js";
8
+ } from "./szm0cksa.js";
9
+ import"./fancm5pt.js";
9
10
  import {
10
11
  errorDoc,
11
- assertTargetPolicy,
12
- selectTarget,
13
12
  openProject
14
- } from "./q6zsyh31.js";
13
+ } from "./qv2ydck9.js";
15
14
  import {
16
- omitManagedObjects
17
- } from "./n5y9zyj1.js";
18
- import"./41kv2xdm.js";
15
+ omitManagedObjects,
16
+ assertTargetPolicy,
17
+ selectTarget
18
+ } from "./ga3sfy93.js";
19
+ import"./8xsbagad.js";
19
20
  import {
20
21
  OkmError2
21
22
  } from "./52szzakm.js";
@@ -3,14 +3,16 @@ import {
3
3
  applyProject2,
4
4
  pushProject2,
5
5
  backfillTiming2
6
- } from "./s4mb6a4b.js";
7
- import"./7nk68fj8.js";
8
- import"./q6zsyh31.js";
9
- import"./n5y9zyj1.js";
6
+ } from "./cctw17hj.js";
7
+ import"./gde73es6.js";
8
+ import"./szm0cksa.js";
9
+ import"./fancm5pt.js";
10
+ import"./qv2ydck9.js";
11
+ import"./ga3sfy93.js";
10
12
  import"./n442h54c.js";
11
- import"./41kv2xdm.js";
12
- import"./8jb4ymh2.js";
13
- import"./wqem4jed.js";
13
+ import"./8xsbagad.js";
14
+ import"./8bwbwy8h.js";
15
+ import"./krxx77g0.js";
14
16
  export {
15
17
  applyProject2 as applyProject,
16
18
  applyTarget2 as applyTarget,
@@ -32,9 +32,10 @@ import {
32
32
  indexes,
33
33
  quote,
34
34
  isRecord,
35
+ effectivePredicate,
35
36
  registerFailFix,
36
37
  fail
37
- } from "./xrfnq5k8.js";
38
+ } from "./gbtcc2d7.js";
38
39
  import {
39
40
  safetyInstalled,
40
41
  runSafety
@@ -45,7 +46,8 @@ import {
45
46
  operatorValue
46
47
  } from "./cn0n68ft.js";
47
48
  import {
48
- OkmError2
49
+ OkmError2,
50
+ throwNamed2
49
51
  } from "./52szzakm.js";
50
52
 
51
53
  // src/runtime/write.ts
@@ -98,6 +100,8 @@ var INSERT_OPTIONS = [
98
100
  "validate"
99
101
  ];
100
102
  var FILTER_OPTIONS = ["allow", "expect", "returning", "signal", "timeout", "validate"];
103
+ var UPDATE_KEYS = ["set", "where"];
104
+ var UPDATE_ROW_KEYS = ["id", "set", "where"];
101
105
  var NO_ALLOW = new Set;
102
106
  async function executeWrite(host, op, table, input, options, mods, scope, plan) {
103
107
  const prepared = await prepareWrite(host, op, table, input, options, mods, scope);
@@ -179,8 +183,8 @@ async function planInsert(table, input, options, mods, generators, scope, tenanc
179
183
  keyFields: undefined
180
184
  };
181
185
  }
182
- const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./jns2wx4t.js");
183
- const conflict = conflictMod?.readConflict(table, options.onConflict, allow);
186
+ const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./32zqc1dw.js");
187
+ const conflict = conflictMod?.readConflict(table, options.onConflict, allow, tenancy?.key);
184
188
  const chunks = chunkRows(rows.map((row) => cellsFor(columns, row)));
185
189
  const statements = [];
186
190
  const keys = [];
@@ -216,6 +220,7 @@ function planUpdate(schema, table, input, options, mods) {
216
220
  if (Array.isArray(input)) {
217
221
  const rows = input.map((item) => {
218
222
  const row = updateItem(table, item, allow, schema.tenancy);
223
+ requireFilter(table, row.where, mods, "update");
219
224
  return { ...row, where: stack(row.where, mods.presets) };
220
225
  });
221
226
  return {
@@ -229,6 +234,7 @@ function planUpdate(schema, table, input, options, mods) {
229
234
  }
230
235
  if (!isRecord(input))
231
236
  fail("OKM1121", "update expects { where, set } or a list of rows.");
237
+ rejectUpdateKeys(input, false);
232
238
  const set = writeSet(table, input.set, allow, schema.tenancy);
233
239
  requireFilter(table, input.where, mods, "update");
234
240
  if (Object.keys(set).length === 0)
@@ -637,6 +643,7 @@ function writeSet(table, value, allow, tenancy) {
637
643
  function updateItem(table, value, allow, tenancy) {
638
644
  if (!isRecord(value))
639
645
  fail("OKM1121", "update expects { where, set } or a list of rows.");
646
+ rejectUpdateKeys(value, true);
640
647
  const set = writeSet(table, value.set, allow, tenancy);
641
648
  if (value.where !== undefined)
642
649
  return { where: value.where, set };
@@ -644,6 +651,14 @@ function updateItem(table, value, allow, tenancy) {
644
651
  return { where: { id: value.id }, set };
645
652
  fail("OKM1102", `update on ${table.model.name} needs id or where for each row.`);
646
653
  }
654
+ function rejectUpdateKeys(input, row) {
655
+ const accepted = row ? UPDATE_ROW_KEYS : UPDATE_KEYS;
656
+ for (const key of Object.keys(input)) {
657
+ if (accepted.includes(key))
658
+ continue;
659
+ throwNamed2("OKM1120", key, [...accepted, ...FILTER_OPTIONS], `Option ${key} is not accepted by update. Accepted options: ${accepted.join(", ")}. timeout and signal go in the second argument.`);
660
+ }
661
+ }
647
662
  function requireFilter(table, where, mods, op) {
648
663
  if (mods.all !== undefined) {
649
664
  if (mods.all.trim().length === 0) {
@@ -651,11 +666,9 @@ function requireFilter(table, where, mods, op) {
651
666
  }
652
667
  return;
653
668
  }
654
- if (isOperator(where))
655
- return;
656
- if (isRecord(where) && Object.keys(where).length > 0)
657
- return;
658
- fail("OKM1102", `${op} on ${table.model.name} needs a where. Pass a filter, or .all(reason).`);
669
+ if (!effectivePredicate(where)) {
670
+ fail("OKM1102", `${op} on ${table.model.name} needs a where. Pass a filter, or .all(reason).`);
671
+ }
659
672
  }
660
673
  function chunkRows(rows) {
661
674
  const chunks = [];