okmodel 0.5.1 → 0.6.0

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 (155) hide show
  1. package/README.md +29 -14
  2. package/dist/adapters/pg/no-inflight-timeout.d.ts +17 -0
  3. package/dist/adapters/pg/postgres-extra.d.ts +22 -0
  4. package/dist/contracts/catalog/document.d.ts +19 -5
  5. package/dist/contracts/catalog/object.d.ts +2 -1
  6. package/dist/contracts/catalog/policy.d.ts +48 -0
  7. package/dist/contracts/catalog/types.d.ts +25 -1
  8. package/dist/contracts/catalog/view.d.ts +2 -0
  9. package/dist/contracts/internal.js +1 -1
  10. package/dist/contracts/location.d.ts +10 -0
  11. package/dist/dialects/pg/column.d.ts +13 -2
  12. package/dist/dialects/pg/ddl.d.ts +37 -1
  13. package/dist/dialects/pg/emit.d.ts +19 -1
  14. package/dist/dialects/pg/errors.d.ts +32 -1
  15. package/dist/dialects/pg/ext/citext.js +1 -1
  16. package/dist/dialects/pg/ext/index.js +1 -1
  17. package/dist/dialects/pg/ext/pg-trgm.js +1 -1
  18. package/dist/dialects/pg/filter-parse.d.ts +5 -4
  19. package/dist/dialects/pg/fn/index.js +2 -2
  20. package/dist/dialects/pg/index.d.ts +2 -1
  21. package/dist/dialects/pg/index.js +23 -17
  22. package/dist/dialects/pg/introspect.d.ts +7 -0
  23. package/dist/dialects/pg/model.d.ts +7 -2
  24. package/dist/dialects/pg/owner.d.ts +42 -0
  25. package/dist/dialects/pg/path-endpoint.d.ts +20 -0
  26. package/dist/dialects/pg/role/check.d.ts +3 -0
  27. package/dist/dialects/pg/role/index.d.ts +71 -6
  28. package/dist/dialects/pg/role/sql.d.ts +11 -0
  29. package/dist/dialects/pg/schema.d.ts +2 -0
  30. package/dist/dialects/pg/table.d.ts +25 -3
  31. package/dist/dialects/pg/tenancy.d.ts +45 -3
  32. package/dist/dialects/pg/view/client.d.ts +19 -1
  33. package/dist/dialects/pg/view/index.d.ts +4 -0
  34. package/dist/dialects/pg/view/index.js +21 -178
  35. package/dist/dialects/pg/view/refresh.d.ts +24 -0
  36. package/dist/runtime/batch.d.ts +1 -1
  37. package/dist/runtime/conflict.d.ts +2 -2
  38. package/dist/runtime/drift.d.ts +9 -0
  39. package/dist/runtime/inflight.d.ts +14 -0
  40. package/dist/runtime/pg/bun.js +4 -3
  41. package/dist/runtime/pg/pg.js +3 -3
  42. package/dist/runtime/pg/pglite.js +4 -3
  43. package/dist/runtime/pg/postgresjs.js +3 -3
  44. package/dist/runtime/plan.d.ts +18 -10
  45. package/dist/runtime/predicate.d.ts +19 -0
  46. package/dist/runtime/safety/index.js +1 -1
  47. package/dist/runtime/tenancy/composite.d.ts +26 -0
  48. package/dist/runtime/tenancy/context.d.ts +16 -0
  49. package/dist/runtime/tenancy/index.d.ts +9 -5
  50. package/dist/runtime/tenancy/index.js +1508 -37
  51. package/dist/runtime/tenancy/path.d.ts +87 -0
  52. package/dist/runtime/tenancy/rls.d.ts +67 -0
  53. package/dist/runtime/tenancy/via.d.ts +22 -0
  54. package/dist/runtime/traits/index.js +17 -11
  55. package/dist/runtime/types.d.ts +13 -1
  56. package/dist/runtime/validate/index.js +4 -4
  57. package/dist/runtime/write.d.ts +1 -1
  58. package/dist/shared/09p049xa.js +702 -0
  59. package/dist/shared/{6qd27mx0.js → 1f0xa3cb.js} +5 -5
  60. package/dist/shared/1nw1f3vs.js +23 -0
  61. package/dist/shared/{96qcj21c.js → 1z04fa85.js} +19 -9
  62. package/dist/shared/{qm7cdtvr.js → 2cg3wnxc.js} +296 -60
  63. package/dist/shared/{dyj86cmj.js → 2jd1sn0e.js} +2 -2
  64. package/dist/shared/{gbtcc2d7.js → 2z7wv5tj.js} +10 -35
  65. package/dist/shared/{k8v5v5wj.js → 32cnm7kn.js} +6 -1
  66. package/dist/shared/{t4tbsy9h.js → 358zsv4r.js} +1 -1
  67. package/dist/shared/{2pqx26h8.js → 3fqwmr09.js} +31 -22
  68. package/dist/shared/{zqrnhwsq.js → 3qnhc7w5.js} +16 -9
  69. package/dist/shared/{r2sp8hrc.js → 5d8t84hg.js} +12 -3
  70. package/dist/shared/{87jvvhnt.js → 5j36z8dn.js} +16 -5
  71. package/dist/shared/{1g0drakv.js → 5yv4k6a6.js} +1 -1
  72. package/dist/shared/8dqhth8c.js +12 -0
  73. package/dist/shared/8etn7d8w.js +62 -0
  74. package/dist/shared/{v36c5g6p.js → 8x72s86k.js} +400 -13
  75. package/dist/shared/{nxdp2ze3.js → 929h19xp.js} +107 -5
  76. package/dist/shared/{gjthds9j.js → 9628a9xt.js} +1 -1
  77. package/dist/shared/{8xsbagad.js → 9s0ypp87.js} +88 -7
  78. package/dist/shared/{efmy2gcg.js → ag4c7516.js} +1 -1
  79. package/dist/shared/b3awxn7h.js +45 -0
  80. package/dist/shared/b4v57v3x.js +9 -0
  81. package/dist/shared/bdk4sty6.js +58 -0
  82. package/dist/shared/{51mvgj8w.js → c58secgj.js} +100 -7
  83. package/dist/shared/d5azex6s.js +6 -0
  84. package/dist/shared/{5fqx9yh4.js → dk8v79p3.js} +3 -1
  85. package/dist/shared/{4m9fn52z.js → ed0b8k4s.js} +1 -1
  86. package/dist/shared/{z2rnngj4.js → ek2wt2dz.js} +8 -5
  87. package/dist/shared/{sycnx8gt.js → f0f1n281.js} +18 -8
  88. package/dist/shared/{f5cw5q5r.js → g90m9b0g.js} +2 -1
  89. package/dist/shared/{pf0d8f77.js → gwn6v667.js} +1 -1
  90. package/dist/shared/{8rsy3hxz.js → h15jx9bc.js} +1 -1
  91. package/dist/shared/{5enne4ma.js → hazqqecq.js} +17 -93
  92. package/dist/shared/{jwtxdj06.js → j3rkk835.js} +32 -9
  93. package/dist/shared/{hf22e0wt.js → j60w0dvr.js} +19 -18
  94. package/dist/shared/{ycatkxmq.js → jgqj11w4.js} +1 -1
  95. package/dist/shared/k68eedmy.js +85 -0
  96. package/dist/shared/{szm0cksa.js → knmes2kh.js} +34 -6
  97. package/dist/shared/{0t22wwh1.js → mb2ycs1p.js} +4 -2
  98. package/dist/shared/{cr74e96e.js → n076ydsc.js} +1 -1
  99. package/dist/shared/{cctw17hj.js → nx9hh281.js} +31 -28
  100. package/dist/shared/{gde73es6.js → p248q79y.js} +56 -55
  101. package/dist/shared/{janx09m5.js → p6bjzq9q.js} +11 -7
  102. package/dist/shared/{6rk2gen5.js → pjr6xrm5.js} +2 -2
  103. package/dist/shared/{wq9n6pwr.js → pz6rj8ay.js} +82 -9
  104. package/dist/shared/{caw8b9d8.js → q3j1tq7a.js} +35 -22
  105. package/dist/shared/{8bwbwy8h.js → qq3899ht.js} +128 -18
  106. package/dist/shared/{tm5ab8we.js → r11n8grd.js} +2 -2
  107. package/dist/shared/r1fdd0f6.js +19 -0
  108. package/dist/shared/{8ktwd3rh.js → r3j8s5y0.js} +1 -1
  109. package/dist/shared/rhs3xe4k.js +7 -0
  110. package/dist/shared/{ntneex2a.js → rpycarcr.js} +6 -6
  111. package/dist/shared/{aj2qxyhj.js → sbdme3vy.js} +14 -2
  112. package/dist/shared/{qv2ydck9.js → t3g0k88x.js} +638 -67
  113. package/dist/shared/{ga3sfy93.js → ttmg09vd.js} +535 -200
  114. package/dist/shared/{kfjp0gck.js → venqrjna.js} +8 -4
  115. package/dist/shared/{fancm5pt.js → vjpnzwjz.js} +138 -15
  116. package/dist/shared/{32zqc1dw.js → vmfkhszw.js} +31 -7
  117. package/dist/shared/{krxx77g0.js → wkme6tep.js} +10 -8
  118. package/dist/shared/{ps7a6h14.js → wt5rzv1h.js} +12 -8
  119. package/dist/shared/wxr8cwns.js +6 -0
  120. package/dist/shared/{6mnp99hx.js → wynzeggs.js} +16 -12
  121. package/dist/shared/x3jc53kg.js +220 -0
  122. package/dist/shared/{sdc7r2ww.js → xq0mvhts.js} +8 -8
  123. package/dist/shared/xqve9598.js +53 -0
  124. package/dist/shared/{47x8x9ze.js → y2t3jktd.js} +2 -2
  125. package/dist/shared/{9x25fxhc.js → y34a8714.js} +1 -1
  126. package/dist/shared/{k7dwkhvq.js → y6jdds7g.js} +4 -1
  127. package/dist/shared/{nkaxvt9q.js → ys0xzyaj.js} +1 -1
  128. package/dist/shared/{c9z5g0fm.js → ywr8hmey.js} +5 -2
  129. package/dist/shared/{g7ez901n.js → ywspezzx.js} +1 -1
  130. package/dist/shared/{9m80mkac.js → ze4hxsmy.js} +1 -1
  131. package/dist/shared/{r8x5qhd7.js → zm0mafk4.js} +10 -4
  132. package/dist/shared/{y005b761.js → zy8r7qvz.js} +6 -2
  133. package/dist/tooling/cli.js +41 -15
  134. package/dist/tooling/migrate/apply.d.ts +14 -0
  135. package/dist/tooling/migrate/check.d.ts +3 -4
  136. package/dist/tooling/migrate/classify.d.ts +4 -0
  137. package/dist/tooling/migrate/config.d.ts +3 -2
  138. package/dist/tooling/migrate/files.d.ts +11 -1
  139. package/dist/tooling/migrate/index.js +14 -14
  140. package/dist/tooling/migrate/lint.d.ts +1 -1
  141. package/dist/tooling/migrate/lost.d.ts +28 -0
  142. package/dist/tooling/migrate/paths.d.ts +14 -0
  143. package/dist/tooling/migrate/plan.d.ts +6 -3
  144. package/dist/tooling/migrate/runner.d.ts +25 -0
  145. package/dist/tooling/migrate/sandbox.d.ts +57 -0
  146. package/dist/tooling/migrate/sql-lex.d.ts +20 -3
  147. package/dist/tooling/migrate/text.d.ts +42 -0
  148. package/dist/tooling/node-version.d.ts +21 -0
  149. package/dist/tooling/testing/facts.d.ts +33 -5
  150. package/dist/tooling/testing/index.d.ts +1 -1
  151. package/dist/tooling/testing/index.js +3 -3
  152. package/dist/tooling/testing/isolation.d.ts +11 -5
  153. package/package.json +5 -2
  154. package/dist/shared/7zwwyh0v.js +0 -448
  155. package/dist/shared/q58y17hy.js +0 -21
@@ -416,6 +416,7 @@ function emitPredicate(schema, table, key, value, sink, alias, depth) {
416
416
  if (column === undefined) {
417
417
  throwNamed2("OKM1120", key, table.names, `Field ${key} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
418
418
  }
419
+ refuseHidden(column);
419
420
  sink.mark(`w:${key}`);
420
421
  emitOperand(schema, table, column, value, sink, alias, depth);
421
422
  }
@@ -614,6 +615,7 @@ function emitOrder(table, orderBy, sink, alias) {
614
615
  if (column === undefined) {
615
616
  throwNamed2("OKM1120", key, table.names, `Field ${key} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
616
617
  }
618
+ refuseHidden(column);
617
619
  const parsed = parseOrder(key, orderBy[key]);
618
620
  if (index > 0)
619
621
  sink.text(", ");
@@ -642,6 +644,11 @@ function emitPrimaryOrder(table, sink, alias) {
642
644
  sink.text(" asc");
643
645
  }
644
646
  }
647
+ function refuseHidden(column) {
648
+ if (column.hidden !== true)
649
+ return;
650
+ fail("OKM1120", `Field ${column.field} is hidden.`, "Call hidden({ filterable: true }).");
651
+ }
645
652
  function emitLimit(call, sink) {
646
653
  if (call.op === "one") {
647
654
  const ordered = call.orderBy !== undefined && isRecord(call.orderBy) && Object.keys(call.orderBy).length > 0;
@@ -846,38 +853,6 @@ function list(names) {
846
853
  function isRecord(value) {
847
854
  return typeof value === "object" && value !== null && !Array.isArray(value) && !isOperator(value);
848
855
  }
849
- function effectivePredicate(where) {
850
- if (where === undefined)
851
- return false;
852
- if (isOperator(where)) {
853
- const name = operatorName(where);
854
- const value = operatorValue(where);
855
- if (name === "or") {
856
- if (!Array.isArray(value))
857
- orFail(false);
858
- if (value.length === 0)
859
- return true;
860
- for (const branch of value) {
861
- if (!effectivePredicate(branch))
862
- orFail(true);
863
- }
864
- return true;
865
- }
866
- if (name === "and") {
867
- return Array.isArray(value) && value.some((part) => effectivePredicate(part));
868
- }
869
- if (name === "not")
870
- return effectivePredicate(value);
871
- return true;
872
- }
873
- if (!isRecord(where))
874
- return true;
875
- for (const key of Object.keys(where)) {
876
- if (where[key] !== undefined)
877
- return true;
878
- }
879
- return false;
880
- }
881
856
  function orFail(empty) {
882
857
  throw new OkmError2("OKM1121", empty ? "or() branch is empty." : "Pass an array: or([a, b]).", {
883
858
  fix: {
@@ -892,8 +867,8 @@ var FAIL_FIX = {
892
867
  function registerFailFix(code, summary) {
893
868
  FAIL_FIX[code] = summary;
894
869
  }
895
- function fail(code, message) {
896
- const summary = FAIL_FIX[code];
870
+ function fail(code, message, fix) {
871
+ const summary = fix ?? FAIL_FIX[code];
897
872
  throw new OkmError2(code, message, summary === undefined ? undefined : { fix: { summary } });
898
873
  }
899
874
  function plain(value) {
@@ -916,4 +891,4 @@ function hasMany(include) {
916
891
  return Object.keys(include).length > 0;
917
892
  }
918
893
 
919
- export { withRowFilters, installArchiveInspect, archiveRules, readOptionNames, installOperatorSql, readNeedsOperatorSql, emitRelationFrom, bindCall, compileCall, decodeResult, logicalIntent, appliedRules, emitJoin, emitWhere, emitOrder, emitPrimaryOrder, selectedColumns, parseOrder, rejectKeys, readLimit, takeObject, projectExpr, jsonExpr, decodeRow, cell, indexes, quote, list, isRecord, effectivePredicate, registerFailFix, fail };
894
+ export { withRowFilters, installArchiveInspect, archiveRules, readOptionNames, installOperatorSql, readNeedsOperatorSql, emitRelationFrom, bindCall, compileCall, decodeResult, logicalIntent, appliedRules, emitJoin, emitWhere, emitOrder, emitPrimaryOrder, refuseHidden, selectedColumns, parseOrder, rejectKeys, readLimit, takeObject, projectExpr, jsonExpr, decodeRow, cell, indexes, quote, list, isRecord, orFail, registerFailFix, fail };
@@ -1,3 +1,6 @@
1
+ import {
2
+ noTimeout2
3
+ } from "./8dqhth8c.js";
1
4
  import {
2
5
  noticeBuffer,
3
6
  WireSession,
@@ -41,16 +44,18 @@ function open5(config) {
41
44
  counters.busy = Math.max(0, counters.busy - 1);
42
45
  });
43
46
  const held = { sql, parked, acquireMs, counters, notices, isClosed };
44
- const checkout = () => closed ? rejectClosed() : import("./jwtxdj06.js").then((mod) => mod.checkout(held));
47
+ const checkout = () => closed ? rejectClosed() : import("./j3rkk835.js").then((mod) => mod.checkout(held));
45
48
  return {
46
49
  capabilities: BUNSQL_CAPABILITIES,
47
50
  execute(text, params, options) {
51
+ noTimeout2(options);
48
52
  return runCall(closed, options, async (watch) => {
49
53
  await releaseParked(parked);
50
54
  return root.query(text, params, watch);
51
55
  });
52
56
  },
53
57
  async batch(statements, options) {
58
+ noTimeout2(options);
54
59
  const connection = await checkout();
55
60
  try {
56
61
  return await connection.batch(statements, options);
@@ -503,7 +503,7 @@ function constraint2(input) {
503
503
  const name = input.name === undefined ? deterministicName2({
504
504
  parent: input.parent.name,
505
505
  purpose: input.constraintKind,
506
- nameKey
506
+ nameKey: input.constraintKind === "check" ? nameKey : defaultNameKey(input.constraintKind, columns)
507
507
  }) : fitIdentifier2(input.name);
508
508
  const identity = {
509
509
  kind: "constraint",
@@ -1,36 +1,38 @@
1
1
  import {
2
2
  open2
3
- } from "./krxx77g0.js";
4
- import"./8bwbwy8h.js";
3
+ } from "./wkme6tep.js";
4
+ import"./qq3899ht.js";
5
5
  import {
6
6
  createdOf,
7
7
  testing2
8
- } from "./v36c5g6p.js";
8
+ } from "./8x72s86k.js";
9
9
  import"./n442h54c.js";
10
10
  import {
11
+ projectPath,
11
12
  loadConfig,
12
13
  loadSchema
13
- } from "./qv2ydck9.js";
14
+ } from "./t3g0k88x.js";
14
15
  import {
16
+ sessionFailure,
17
+ finishQuiet,
15
18
  assertTargetPolicy,
16
19
  assertDirectConnection,
17
20
  assertStableBackend,
18
21
  selectTarget
19
- } from "./ga3sfy93.js";
20
- import"./8xsbagad.js";
22
+ } from "./ttmg09vd.js";
23
+ import"./9s0ypp87.js";
21
24
  import {
22
25
  OkmError2
23
26
  } from "./52szzakm.js";
24
27
 
25
28
  // src/tooling/migrate/seed.ts
26
29
  import { existsSync } from "node:fs";
27
- import { join } from "node:path";
28
30
  import { pathToFileURL } from "node:url";
29
31
  async function seedProject(cwd, file, flags) {
30
32
  const config = await loadConfig(cwd);
31
33
  const target = selectTarget(config, flags.target);
32
34
  assertTargetPolicy(target, "seed", flags.allowProtected);
33
- const path = join(cwd, file);
35
+ const path = projectPath(cwd, file);
34
36
  if (!existsSync(path)) {
35
37
  throw new OkmError2("invalid", `Seed file ${file} was not found.`, {
36
38
  fix: { summary: "Pass okm seed <file> a module in this project." }
@@ -40,20 +42,21 @@ async function seedProject(cwd, file, flags) {
40
42
  assertDirectConnection(target.url, allowPooler);
41
43
  const schema = await loadSchema(cwd, config.schema);
42
44
  const pool = open2({ url: target.url, max: 1 });
43
- const held = await pool.reserve?.();
44
- if (held !== undefined) {
45
- try {
46
- await assertStableBackend(async () => {
47
- const result = await held.execute("select pg_backend_pid()::text");
48
- const cell = result.rows[0]?.[0];
49
- return cell === null || cell === undefined ? "" : String(cell);
50
- }, allowPooler);
51
- } finally {
52
- await held.release();
53
- }
54
- }
55
- const harness = await testing2(schema, { driver: pool, migrate: false });
45
+ let harness;
56
46
  try {
47
+ const held = await pool.reserve?.();
48
+ if (held !== undefined) {
49
+ try {
50
+ await assertStableBackend(async () => {
51
+ const result = await held.execute("select pg_backend_pid()::text");
52
+ const cell = result.rows[0]?.[0];
53
+ return cell === null || cell === undefined ? "" : String(cell);
54
+ }, allowPooler);
55
+ } finally {
56
+ await finishQuiet(() => held.release());
57
+ }
58
+ }
59
+ harness = await testing2(schema, { driver: pool, migrate: false });
57
60
  const imported = await import(`${pathToFileURL(path).href}?okm=${Date.now()}`);
58
61
  const seed = isRecord(imported) ? imported.default : undefined;
59
62
  if (typeof seed !== "function") {
@@ -63,8 +66,14 @@ async function seedProject(cwd, file, flags) {
63
66
  }
64
67
  await seed(harness);
65
68
  return formatCreated(target.name, createdOf(harness));
69
+ } catch (error) {
70
+ throw sessionFailure(error) ?? error;
66
71
  } finally {
67
- await harness.close();
72
+ const opened = harness;
73
+ if (opened !== undefined)
74
+ await finishQuiet(() => opened.close());
75
+ else
76
+ await finishQuiet(() => pool.close());
68
77
  }
69
78
  }
70
79
  function formatCreated(target, counts) {
@@ -1,9 +1,12 @@
1
+ import {
2
+ mapPostgresError2
3
+ } from "./c58secgj.js";
1
4
  import {
2
5
  withHttp
3
- } from "./hf22e0wt.js";
6
+ } from "./j60w0dvr.js";
4
7
  import {
5
8
  decodeResult
6
- } from "./gbtcc2d7.js";
9
+ } from "./2z7wv5tj.js";
7
10
  import {
8
11
  OkmError2
9
12
  } from "./52szzakm.js";
@@ -17,13 +20,17 @@ async function* streamRows(session, call, prepare, log) {
17
20
  })));
18
21
  }
19
22
  const { plan, params } = await prepare();
20
- const decode = plan.outputs.includes.length === 0 ? decodeResult : (await import("./nkaxvt9q.js")).decodeIncluded;
21
- for await (const chunk of session.pool.stream(plan.text, params)) {
22
- const decoded = decode(plan, chunk, call.table);
23
- if (!Array.isArray(decoded))
24
- continue;
25
- for (const row of decoded)
26
- yield row;
23
+ const decode = plan.outputs.includes.length === 0 ? decodeResult : (await import("./ys0xzyaj.js")).decodeIncluded;
24
+ try {
25
+ for await (const chunk of session.pool.stream(plan.text, params)) {
26
+ const decoded = decode(plan, chunk, call.table);
27
+ if (!Array.isArray(decoded))
28
+ continue;
29
+ for (const row of decoded)
30
+ yield row;
31
+ }
32
+ } catch (error) {
33
+ throw log(session.http === undefined ? mapPostgresError2(error) : mapPostgresError2(error, { http: session.http }));
27
34
  }
28
35
  }
29
36
  export {
@@ -1,16 +1,19 @@
1
+ import {
2
+ refuseUncancellableTimeout
3
+ } from "./b4v57v3x.js";
1
4
  import {
2
5
  isConnectionLost
3
- } from "./pf0d8f77.js";
6
+ } from "./gwn6v667.js";
4
7
  import {
5
8
  openClient,
6
9
  withHttp,
7
10
  settleCall
8
- } from "./hf22e0wt.js";
11
+ } from "./j60w0dvr.js";
9
12
  import {
10
13
  rejectKeys,
11
14
  isRecord,
12
15
  fail
13
- } from "./gbtcc2d7.js";
16
+ } from "./2z7wv5tj.js";
14
17
  import {
15
18
  OkmError2
16
19
  } from "./52szzakm.js";
@@ -105,6 +108,7 @@ async function tx(session, args) {
105
108
  rejectKeys(given, ["isolation", "retry", "signal", "timeout"], "tx");
106
109
  const options = given;
107
110
  check(options);
111
+ await refuseUncancellableTimeout(session.pool, options.timeout);
108
112
  const call = fn;
109
113
  return session.tx === undefined ? await outer(session, call, options) : await nested(session, call, options);
110
114
  } catch (error) {
@@ -275,6 +279,10 @@ async function nested(session, fn, options) {
275
279
  const saved = frame.failed;
276
280
  const after = [];
277
281
  let released = false;
282
+ const hooks = session.pool;
283
+ const pending = hooks.okmScopePending?.();
284
+ if (pending !== undefined)
285
+ await pending;
278
286
  try {
279
287
  await step(session, frame, `SAVEPOINT ${name}`);
280
288
  hear?.phase(session.hookm, "start", depth + 1);
@@ -293,6 +301,7 @@ async function nested(session, fn, options) {
293
301
  await frame.conn.execute(`ROLLBACK TO SAVEPOINT ${name}`).catch(() => {
294
302
  return;
295
303
  });
304
+ hooks.okmForgetScope?.();
296
305
  frame.failed = saved;
297
306
  hear?.phase(session.hookm, "rollback", depth + 1);
298
307
  }
@@ -1,3 +1,6 @@
1
+ import {
2
+ noTimeout2
3
+ } from "./8dqhth8c.js";
1
4
  import {
2
5
  PGLITE_CAPABILITIES,
3
6
  driverErrors,
@@ -46,11 +49,17 @@ async function open3(config = {}) {
46
49
  await slot.acquire(acquireMs);
47
50
  let released = false;
48
51
  return {
49
- execute: (text, params, options) => runCall(closed, options, (watch) => session.query(text, params, watch)),
50
- batch: (statements, options) => runCall(closed, options, async (watch) => {
51
- const { runAtomicBatch } = await import("./efmy2gcg.js");
52
- return runAtomicBatch(session, statements, watch);
53
- }),
52
+ execute: (text, params, options) => {
53
+ noTimeout2(options);
54
+ return runCall(closed, options, (watch) => session.query(text, params, watch));
55
+ },
56
+ batch: (statements, options) => {
57
+ noTimeout2(options);
58
+ return runCall(closed, options, async (watch) => {
59
+ const { runAtomicBatch } = await import("./ag4c7516.js");
60
+ return runAtomicBatch(session, statements, watch);
61
+ });
62
+ },
54
63
  async release() {
55
64
  if (released)
56
65
  return;
@@ -66,6 +75,7 @@ async function open3(config = {}) {
66
75
  return {
67
76
  capabilities: PGLITE_CAPABILITIES,
68
77
  execute(text, params, options) {
78
+ noTimeout2(options);
69
79
  return runCall(closed, options, async (watch) => {
70
80
  await slot.acquire(acquireMs);
71
81
  try {
@@ -76,6 +86,7 @@ async function open3(config = {}) {
76
86
  });
77
87
  },
78
88
  async batch(statements, options) {
89
+ noTimeout2(options);
79
90
  const connection = await lease();
80
91
  try {
81
92
  return await connection.batch(statements, options);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  required
3
- } from "./c9z5g0fm.js";
3
+ } from "./ywr8hmey.js";
4
4
  import {
5
5
  definition,
6
6
  rejected
@@ -0,0 +1,12 @@
1
+ import {
2
+ OkmError2
3
+ } from "./52szzakm.js";
4
+
5
+ // src/adapters/pg/no-inflight-timeout.ts
6
+ function noTimeout2(options) {
7
+ if ((options?.timeout ?? 0) <= 0)
8
+ return;
9
+ throw new OkmError2("OKM1120", "timeout");
10
+ }
11
+
12
+ export { noTimeout2 };
@@ -0,0 +1,62 @@
1
+ import {
2
+ OkmError2
3
+ } from "./52szzakm.js";
4
+
5
+ // src/dialects/pg/view/refresh.ts
6
+ async function refreshView(session, name, concurrently) {
7
+ const host = asHost(session);
8
+ await host.connected;
9
+ const timeout = host.timeouts?.statement;
10
+ const options = timeout === undefined ? undefined : { timeout };
11
+ const text = `refresh materialized view${concurrently ? " concurrently" : ""} ${quote(name)}`;
12
+ const connection = await host.pool.reserve?.();
13
+ if (connection === undefined) {
14
+ throw new OkmError2("OKM1111", "Refresh needs a driver that can reserve a connection.", {
15
+ fix: { summary: "Use a Postgres driver that supports interactive transactions." }
16
+ });
17
+ }
18
+ try {
19
+ if (concurrently) {
20
+ await connection.execute("select set_config('app.unscoped', 'on', false)");
21
+ try {
22
+ await connection.execute(text, undefined, options);
23
+ } finally {
24
+ await connection.execute("select set_config('app.unscoped', '', false)").catch(() => {
25
+ return;
26
+ });
27
+ }
28
+ return;
29
+ }
30
+ await connection.execute("begin");
31
+ try {
32
+ await connection.execute("select set_config('app.unscoped', 'on', true)");
33
+ await connection.execute(text, undefined, options);
34
+ await connection.execute("commit");
35
+ } catch (error) {
36
+ await connection.execute("rollback").catch(() => {
37
+ return;
38
+ });
39
+ throw error;
40
+ }
41
+ } catch (error) {
42
+ const { mapPostgresError } = await import("./d5azex6s.js");
43
+ const mapped = mapPostgresError(error, {
44
+ ...host.http !== undefined ? { http: host.http } : {},
45
+ ...host.includeValues === true ? { includeValues: true } : {},
46
+ ...host.schema !== undefined ? { schema: host.schema } : {}
47
+ });
48
+ host.logger?.error?.({ code: mapped.code, summary: mapped.summary });
49
+ throw mapped;
50
+ } finally {
51
+ await connection.release();
52
+ }
53
+ }
54
+ function asHost(session) {
55
+ return session;
56
+ }
57
+ function quote(name) {
58
+ return `"${name.replaceAll('"', '""')}"`;
59
+ }
60
+ export {
61
+ refreshView
62
+ };