okmodel 0.1.1 → 0.3.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 (228) hide show
  1. package/README.md +727 -37
  2. package/dist/adapters/capabilities.d.ts +34 -0
  3. package/dist/adapters/pg/bunsql-extra.d.ts +17 -0
  4. package/dist/adapters/pg/bunsql.d.ts +60 -0
  5. package/dist/adapters/pg/call.d.ts +2 -12
  6. package/dist/adapters/pg/nodepostgres-extra.d.ts +18 -0
  7. package/dist/adapters/pg/nodepostgres.d.ts +57 -0
  8. package/dist/adapters/pg/postgres-extra.d.ts +50 -1
  9. package/dist/adapters/pg/postgresjs.d.ts +0 -4
  10. package/dist/adapters/pg/session.d.ts +94 -0
  11. package/dist/adapters/pg/watch.d.ts +18 -0
  12. package/dist/contracts/catalog/enum.d.ts +31 -4
  13. package/dist/contracts/catalog/extension.d.ts +61 -0
  14. package/dist/contracts/catalog/object.d.ts +1 -0
  15. package/dist/contracts/catalog/privilege.d.ts +64 -0
  16. package/dist/contracts/catalog/routine.d.ts +56 -0
  17. package/dist/contracts/catalog/types.d.ts +179 -18
  18. package/dist/contracts/catalog/view.d.ts +73 -0
  19. package/dist/contracts/connection.d.ts +13 -0
  20. package/dist/contracts/driver.d.ts +18 -5
  21. package/dist/contracts/error.d.ts +17 -1
  22. package/dist/contracts/generator.d.ts +63 -0
  23. package/dist/contracts/index.d.ts +2 -2
  24. package/dist/contracts/index.js +1 -1
  25. package/dist/contracts/internal.js +11 -9
  26. package/dist/contracts/location.d.ts +24 -0
  27. package/dist/contracts/rows.d.ts +15 -0
  28. package/dist/dialects/pg/archive-bind.d.ts +22 -0
  29. package/dist/dialects/pg/column.d.ts +129 -10
  30. package/dist/dialects/pg/compile.d.ts +1 -0
  31. package/dist/dialects/pg/custom.d.ts +6 -0
  32. package/dist/dialects/pg/ddl.d.ts +65 -1
  33. package/dist/dialects/pg/enum.d.ts +10 -8
  34. package/dist/dialects/pg/ext/citext.d.ts +14 -0
  35. package/dist/dialects/pg/ext/citext.js +11 -0
  36. package/dist/dialects/pg/ext/index.d.ts +52 -0
  37. package/dist/dialects/pg/ext/index.js +6 -0
  38. package/dist/dialects/pg/ext/pg-trgm.d.ts +53 -0
  39. package/dist/dialects/pg/ext/pg-trgm.js +42 -0
  40. package/dist/dialects/pg/filter-parse.d.ts +19 -0
  41. package/dist/dialects/pg/filters.d.ts +19 -0
  42. package/dist/dialects/pg/fn/index.d.ts +107 -0
  43. package/dist/dialects/pg/fn/index.js +175 -0
  44. package/dist/dialects/pg/fn/touch.d.ts +14 -0
  45. package/dist/dialects/pg/index.d.ts +11 -2
  46. package/dist/dialects/pg/index.js +243 -1062
  47. package/dist/dialects/pg/introspect.d.ts +10 -1
  48. package/dist/dialects/pg/keys.d.ts +19 -3
  49. package/dist/dialects/pg/model.d.ts +223 -2
  50. package/dist/dialects/pg/operator-fit.d.ts +86 -0
  51. package/dist/dialects/pg/operators.d.ts +46 -1
  52. package/dist/dialects/pg/ops/arr-append.d.ts +9 -0
  53. package/dist/dialects/pg/ops/arr-ns.d.ts +7 -0
  54. package/dist/dialects/pg/ops/arr-remove.d.ts +9 -0
  55. package/dist/dialects/pg/ops/containedBy.d.ts +9 -0
  56. package/dist/dialects/pg/ops/contains.d.ts +8 -4
  57. package/dist/dialects/pg/ops/hasAnyKey.d.ts +8 -0
  58. package/dist/dialects/pg/ops/hasKey.d.ts +8 -0
  59. package/dist/dialects/pg/ops/json-ns.d.ts +6 -0
  60. package/dist/dialects/pg/ops/json-set.d.ts +12 -0
  61. package/dist/dialects/pg/ops/matches.d.ts +16 -0
  62. package/dist/dialects/pg/ops/overlaps.d.ts +9 -0
  63. package/dist/dialects/pg/ops/path.d.ts +13 -0
  64. package/dist/dialects/pg/preset.d.ts +76 -0
  65. package/dist/dialects/pg/relations.d.ts +59 -2
  66. package/dist/dialects/pg/role/check.d.ts +45 -0
  67. package/dist/dialects/pg/role/index.d.ts +50 -0
  68. package/dist/dialects/pg/role/sql.d.ts +44 -0
  69. package/dist/dialects/pg/schema.d.ts +109 -5
  70. package/dist/dialects/pg/table.d.ts +137 -11
  71. package/dist/dialects/pg/temporal.d.ts +9 -7
  72. package/dist/dialects/pg/tenancy.d.ts +103 -0
  73. package/dist/dialects/pg/through.d.ts +21 -0
  74. package/dist/dialects/pg/trait.d.ts +141 -0
  75. package/dist/dialects/pg/view/client.d.ts +30 -0
  76. package/dist/dialects/pg/view/depend.d.ts +35 -0
  77. package/dist/dialects/pg/view/index.d.ts +114 -0
  78. package/dist/dialects/pg/view/index.js +289 -0
  79. package/dist/dialects/pg/view/scratch.d.ts +21 -0
  80. package/dist/dialects/pg/where.d.ts +37 -0
  81. package/dist/runtime/aggregate.d.ts +25 -0
  82. package/dist/runtime/archive-handle.d.ts +18 -0
  83. package/dist/runtime/archive-rules.d.ts +12 -0
  84. package/dist/runtime/archive.d.ts +73 -0
  85. package/dist/runtime/batch.d.ts +20 -0
  86. package/dist/runtime/client.d.ts +114 -5
  87. package/dist/runtime/conflict.d.ts +2 -1
  88. package/dist/runtime/exposure.d.ts +27 -0
  89. package/dist/runtime/hookm.d.ts +39 -0
  90. package/dist/runtime/ids/index.d.ts +11 -0
  91. package/dist/runtime/ids/index.js +193 -0
  92. package/dist/runtime/ids/okid-extended.d.ts +19 -0
  93. package/dist/runtime/ids/okid-generator.d.ts +21 -0
  94. package/dist/runtime/ids/okid-shared.d.ts +89 -0
  95. package/dist/runtime/ids/okid.d.ts +24 -0
  96. package/dist/runtime/ids/uuid.d.ts +21 -0
  97. package/dist/runtime/lock.d.ts +22 -0
  98. package/dist/runtime/operator-sql.d.ts +8 -0
  99. package/dist/runtime/page.d.ts +25 -0
  100. package/dist/runtime/pg/bun.d.ts +30 -0
  101. package/dist/runtime/pg/bun.js +52 -0
  102. package/dist/runtime/pg/pg.d.ts +29 -0
  103. package/dist/runtime/pg/pg.js +52 -0
  104. package/dist/runtime/pg/pglite.js +16 -17
  105. package/dist/runtime/pg/postgresjs.js +14 -24
  106. package/dist/runtime/plan.d.ts +146 -7
  107. package/dist/runtime/preset-stack.d.ts +17 -0
  108. package/dist/runtime/presets.d.ts +48 -0
  109. package/dist/runtime/read-stream.d.ts +26 -0
  110. package/dist/runtime/safety/index.d.ts +159 -0
  111. package/dist/runtime/safety/index.js +294 -0
  112. package/dist/runtime/safety-hook.d.ts +42 -0
  113. package/dist/runtime/server-check.d.ts +34 -0
  114. package/dist/runtime/tenancy/index.d.ts +37 -0
  115. package/dist/runtime/tenancy/index.js +368 -0
  116. package/dist/runtime/trait-read.d.ts +30 -0
  117. package/dist/runtime/traits/index.d.ts +133 -0
  118. package/dist/runtime/traits/index.js +646 -0
  119. package/dist/runtime/transaction.d.ts +19 -0
  120. package/dist/runtime/tx.d.ts +22 -7
  121. package/dist/runtime/types.d.ts +376 -27
  122. package/dist/runtime/validate/bind.d.ts +11 -0
  123. package/dist/runtime/validate/closed.d.ts +16 -0
  124. package/dist/runtime/validate/engine.d.ts +41 -0
  125. package/dist/runtime/validate/hook.d.ts +17 -0
  126. package/dist/runtime/validate/index.d.ts +21 -0
  127. package/dist/runtime/validate/index.js +175 -0
  128. package/dist/runtime/validate/load.d.ts +13 -0
  129. package/dist/runtime/validate/places.d.ts +41 -0
  130. package/dist/runtime/validate/rules.d.ts +108 -0
  131. package/dist/runtime/validate/surface.d.ts +102 -0
  132. package/dist/runtime/write.d.ts +30 -5
  133. package/dist/shared/01yr20s5.js +149 -0
  134. package/dist/shared/0jc3ffzf.js +154 -0
  135. package/dist/shared/0v1g424p.js +26 -0
  136. package/dist/shared/1g0drakv.js +225 -0
  137. package/dist/shared/{kprcwaha.js → 1tfdfvhh.js} +5 -3
  138. package/dist/shared/{05w44d8g.js → 2ssqrv66.js} +767 -715
  139. package/dist/shared/3ekj9x92.js +210 -0
  140. package/dist/shared/49ypnfwt.js +1122 -0
  141. package/dist/shared/4e4c6vq2.js +62 -0
  142. package/dist/shared/4m9fn52z.js +70 -0
  143. package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
  144. package/dist/shared/5nmdenb6.js +1229 -0
  145. package/dist/shared/672t5vym.js +12 -0
  146. package/dist/shared/6bazvqwm.js +86 -0
  147. package/dist/shared/6w5j844a.js +201 -0
  148. package/dist/shared/{fgqgsb5z.js → 75xkjv0t.js} +2 -2
  149. package/dist/shared/7fvtrkwr.js +84 -0
  150. package/dist/shared/7m88x3e9.js +45 -0
  151. package/dist/shared/{mtkwv8wx.js → 7p2wbz7f.js} +1 -1
  152. package/dist/shared/83eaefwr.js +10 -0
  153. package/dist/shared/94ez8kzh.js +19 -0
  154. package/dist/shared/96ps4g1z.js +32 -0
  155. package/dist/shared/{xqbhg6cn.js → 999ade2q.js} +95 -10
  156. package/dist/shared/9m80mkac.js +158 -0
  157. package/dist/shared/9x25fxhc.js +150 -0
  158. package/dist/shared/a5sxz52y.js +13 -0
  159. package/dist/shared/axhk06q1.js +156 -0
  160. package/dist/shared/{dynq16vb.js → b066g80h.js} +8 -6
  161. package/dist/shared/bqha5cg6.js +229 -0
  162. package/dist/shared/bryqk9k9.js +31 -0
  163. package/dist/shared/c8aghh05.js +442 -0
  164. package/dist/shared/c9z5g0fm.js +309 -0
  165. package/dist/shared/{m3ypagh5.js → dbjej1tw.js} +124 -15
  166. package/dist/shared/dyj86cmj.js +69 -0
  167. package/dist/shared/e6wg00wd.js +164 -0
  168. package/dist/shared/{hadrfb9h.js → edwqqryd.js} +17 -14
  169. package/dist/shared/{qk3hxfja.js → fptpmvxp.js} +5 -5
  170. package/dist/shared/fs0ex00p.js +76 -0
  171. package/dist/shared/{jjb7yht9.js → g4f5kcx9.js} +3 -3
  172. package/dist/shared/gjthds9j.js +48 -0
  173. package/dist/shared/hcmdtwgh.js +102 -0
  174. package/dist/shared/{g5fhqmwe.js → jkc6ws1p.js} +6 -56
  175. package/dist/shared/{yd1kzwn2.js → jns2wx4t.js} +55 -12
  176. package/dist/shared/k34e0xf2.js +450 -0
  177. package/dist/shared/k3ted12y.js +33 -0
  178. package/dist/shared/k7dwkhvq.js +31 -0
  179. package/dist/shared/{8b04d28c.js → kgnc8grt.js} +2 -2
  180. package/dist/shared/{hd293j9g.js → kyxb62mc.js} +14 -2
  181. package/dist/shared/m78s7898.js +376 -0
  182. package/dist/shared/m9tv7xn7.js +404 -0
  183. package/dist/shared/meck53jv.js +99 -0
  184. package/dist/shared/mt5wswjz.js +90 -0
  185. package/dist/shared/n0dgs0pb.js +75 -0
  186. package/dist/shared/n442h54c.js +14 -0
  187. package/dist/shared/n4jqhpqz.js +27 -0
  188. package/dist/shared/n7mcc1gk.js +132 -0
  189. package/dist/shared/ne02ng5c.js +68 -0
  190. package/dist/shared/{mkjmqjv4.js → nfzc5z0w.js} +2 -104
  191. package/dist/shared/nsva2a6b.js +42 -0
  192. package/dist/shared/p24x2334.js +195 -0
  193. package/dist/shared/qbxzvwwc.js +88 -0
  194. package/dist/shared/{w8samvk1.js → qybh48nd.js} +1 -1
  195. package/dist/shared/r6nwkxnt.js +86 -0
  196. package/dist/shared/{xy79j5hq.js → rrstp3kb.js} +25 -36
  197. package/dist/shared/rwmrejjz.js +26 -0
  198. package/dist/shared/{zhc5vmgf.js → s6gqfn5j.js} +2 -2
  199. package/dist/shared/{523ft3e8.js → scwxrpx2.js} +7 -5
  200. package/dist/shared/{j5cn2963.js → t4tbsy9h.js} +13 -64
  201. package/dist/shared/{y9m15dfv.js → t616ynfn.js} +544 -32
  202. package/dist/shared/{ngk8gj61.js → tbszx8mz.js} +15 -1
  203. package/dist/shared/th14ygv2.js +69 -0
  204. package/dist/shared/tmbdywx0.js +178 -0
  205. package/dist/shared/ty3v3hfk.js +64 -0
  206. package/dist/shared/wekze34d.js +246 -0
  207. package/dist/shared/x6wysh83.js +1132 -0
  208. package/dist/shared/{rgs0st28.js → xrfnq5k8.js} +237 -434
  209. package/dist/shared/{x5x59srr.js → xva8v7qk.js} +416 -83
  210. package/dist/shared/{dkn3y60a.js → xw1d69vd.js} +76 -112
  211. package/dist/shared/y005b761.js +112 -0
  212. package/dist/shared/ydaz1sv3.js +55 -0
  213. package/dist/shared/{p0cbr3g2.js → zwmqxb0g.js} +1 -1
  214. package/dist/tooling/cli.js +40 -12
  215. package/dist/tooling/migrate/apply.d.ts +16 -0
  216. package/dist/tooling/migrate/commands.d.ts +12 -1
  217. package/dist/tooling/migrate/config.d.ts +8 -0
  218. package/dist/tooling/migrate/doctor.d.ts +25 -0
  219. package/dist/tooling/migrate/drift.d.ts +19 -0
  220. package/dist/tooling/migrate/engine.d.ts +36 -0
  221. package/dist/tooling/migrate/ext.d.ts +17 -0
  222. package/dist/tooling/migrate/extensions.d.ts +51 -0
  223. package/dist/tooling/migrate/managed.d.ts +17 -0
  224. package/dist/tooling/migrate/plan.d.ts +14 -1
  225. package/dist/tooling/migrate/project.d.ts +25 -1
  226. package/dist/tooling/migrate/type-name.d.ts +19 -0
  227. package/package.json +61 -4
  228. package/dist/shared/gk7cs7sp.js +0 -566
@@ -0,0 +1,12 @@
1
+ import {
2
+ tag
3
+ } from "./cn0n68ft.js";
4
+
5
+ // src/runtime/preset-stack.ts
6
+ function stack(where, presets) {
7
+ if (presets === undefined || presets.length === 0)
8
+ return where;
9
+ return tag("and", where === undefined ? presets : [where, ...presets]);
10
+ }
11
+
12
+ export { stack };
@@ -0,0 +1,86 @@
1
+ import {
2
+ send,
3
+ connectClient
4
+ } from "./bqha5cg6.js";
5
+ import {
6
+ isConnectionLost
7
+ } from "./tbszx8mz.js";
8
+ import {
9
+ WireSession
10
+ } from "./0jc3ffzf.js";
11
+ import {
12
+ rejectClosed,
13
+ runCall
14
+ } from "./rrstp3kb.js";
15
+
16
+ // src/adapters/pg/nodepostgres-extra.ts
17
+ var RESET_ALL = "RESET ALL";
18
+ var UNLOCK = "SELECT pg_advisory_unlock_all()";
19
+ async function checkout(held) {
20
+ const { pool, counters, named, isClosed } = held;
21
+ if (isClosed())
22
+ return rejectClosed();
23
+ const client = await connectClient(pool, held.acquireMs, counters);
24
+ counters.reserved += 1;
25
+ let lost = false;
26
+ const onError = () => {
27
+ lost = true;
28
+ };
29
+ const events = client;
30
+ events.on("error", onError);
31
+ const local = new Set;
32
+ const session = new WireSession((text, params) => send(client, text, params, named, client), held.notices, isClosed, true, () => {
33
+ counters.reservedBusy += 1;
34
+ }, () => {
35
+ counters.reservedBusy = Math.max(0, counters.reservedBusy - 1);
36
+ }, local);
37
+ const guard = (run) => lost ? rejectClosed("The connection was lost.") : run().catch((error) => {
38
+ if (isConnectionLost(error))
39
+ lost = true;
40
+ throw error;
41
+ });
42
+ let released = false;
43
+ return {
44
+ execute: (text, params, options) => guard(() => runCall(isClosed(), options, (watch) => session.query(text, params, watch))),
45
+ batch: (statements, options) => guard(() => runCall(isClosed(), options, async (watch) => {
46
+ const { runAtomicBatch } = await import("./b066g80h.js");
47
+ return runAtomicBatch(session, statements, watch);
48
+ })),
49
+ cancel() {
50
+ session.cancel();
51
+ },
52
+ async release() {
53
+ if (released)
54
+ return;
55
+ released = true;
56
+ try {
57
+ if (!lost)
58
+ await reset(session, client);
59
+ } finally {
60
+ counters.reserved = Math.max(0, counters.reserved - 1);
61
+ events.removeListener("error", onError);
62
+ client.release(lost);
63
+ }
64
+ }
65
+ };
66
+ }
67
+ async function reset(session, client) {
68
+ const run = (text) => client.query(text);
69
+ if (session.depth() > 0)
70
+ await run("ROLLBACK").catch(() => {
71
+ return;
72
+ });
73
+ try {
74
+ await run(RESET_ALL);
75
+ await run(UNLOCK);
76
+ } catch {
77
+ await run("ROLLBACK").catch(() => {
78
+ return;
79
+ });
80
+ await run(RESET_ALL);
81
+ await run(UNLOCK);
82
+ }
83
+ }
84
+ export {
85
+ checkout
86
+ };
@@ -0,0 +1,201 @@
1
+ import {
2
+ callerLocation,
3
+ withLocation
4
+ } from "./k7dwkhvq.js";
5
+ import {
6
+ definition,
7
+ unavailable
8
+ } from "./tmbdywx0.js";
9
+ import {
10
+ OkmError2,
11
+ throwNamed2
12
+ } from "./52szzakm.js";
13
+
14
+ // src/dialects/pg/filters.ts
15
+ function openFilters(table, relations, spec, hiddenFields) {
16
+ const allow = spec.allow ?? {};
17
+ const sort = spec.sort ?? [];
18
+ for (const field of Object.keys(allow))
19
+ deny(hiddenFields, table, field);
20
+ for (const field of sort)
21
+ deny(hiddenFields, table, field);
22
+ const nested = spec.relations;
23
+ if (nested !== undefined) {
24
+ for (const name of Object.keys(nested)) {
25
+ const target = relationTable(relations, name);
26
+ for (const field of nested[name] ?? [])
27
+ deny(hiddenFields, target, field);
28
+ }
29
+ }
30
+ return {
31
+ parse(query) {
32
+ return import("./0v1g424p.js").then((mod) => mod.parseQuery(allow, sort, query));
33
+ }
34
+ };
35
+ }
36
+ function deny(hiddenFields, table, field) {
37
+ if (!hiddenFields.has(`${table}.${field}`))
38
+ return;
39
+ throw new OkmError2("OKM1123", `Field ${table}.${field} is hidden.`, {
40
+ fix: {
41
+ summary: "Remove the hidden field from the allowlist. Hidden fields stay out of caller filters and sorts."
42
+ }
43
+ });
44
+ }
45
+ function relationTable(relations, name) {
46
+ if (typeof relations !== "object" || relations === null)
47
+ return name;
48
+ const call = relations[name];
49
+ if (typeof call !== "object" || call === null || !("table" in call))
50
+ return name;
51
+ const table = call.table;
52
+ return typeof table === "string" ? table : name;
53
+ }
54
+
55
+ // src/dialects/pg/table.ts
56
+ var TABLE_KNOWN = new Set([
57
+ "checks",
58
+ "comment",
59
+ "indexes",
60
+ "omitDefaults",
61
+ "presets",
62
+ "primaryKey",
63
+ "relations",
64
+ "renamedFrom",
65
+ "sqlName",
66
+ "tenancy",
67
+ "traits",
68
+ "unique",
69
+ "validate",
70
+ "validation"
71
+ ]);
72
+ var TABLE_LATER = {
73
+ computed: "later",
74
+ policies: "later",
75
+ reference: "0.4"
76
+ };
77
+ function table2(name, columns, options) {
78
+ const source = callerLocation(1);
79
+ if (name.length === 0) {
80
+ definition(withLocation("table() needs a name.", source));
81
+ }
82
+ if (options !== undefined) {
83
+ rejectLater(options, TABLE_KNOWN, TABLE_LATER, `Table ${name}`);
84
+ }
85
+ remember(name, columns);
86
+ return {
87
+ name,
88
+ columns,
89
+ filters(spec) {
90
+ return openFilters(name, options?.relations, spec, hiddenFields);
91
+ },
92
+ ...options !== undefined ? { options } : {},
93
+ ...source !== undefined ? { source } : {}
94
+ };
95
+ }
96
+ function index2(...columns) {
97
+ return indexCall(columns.map((column) => column.name), false);
98
+ }
99
+ function sql2(strings, ...values) {
100
+ let text = strings[0] ?? "";
101
+ for (let index = 0;index < values.length; index += 1) {
102
+ text += sqlValue(values[index]);
103
+ text += strings[index + 1] ?? "";
104
+ }
105
+ return { text };
106
+ }
107
+ function snakeCase(name) {
108
+ let out = "";
109
+ for (let index = 0;index < name.length; index += 1) {
110
+ const char = name[index] ?? "";
111
+ const lower = char.toLowerCase();
112
+ if (lower !== char && char.toUpperCase() === char && out.length > 0 && !out.endsWith("_")) {
113
+ out += "_";
114
+ }
115
+ out += lower;
116
+ }
117
+ return out;
118
+ }
119
+ function emittedTypeName(name) {
120
+ let out = "";
121
+ let capitalize = true;
122
+ for (const char of name) {
123
+ const letter = char >= "a" && char <= "z" || char >= "A" && char <= "Z";
124
+ const digit = char >= "0" && char <= "9";
125
+ if (!letter && !digit) {
126
+ capitalize = true;
127
+ continue;
128
+ }
129
+ if (capitalize && letter) {
130
+ out += char.toUpperCase();
131
+ capitalize = false;
132
+ continue;
133
+ }
134
+ out += char;
135
+ capitalize = false;
136
+ }
137
+ if (out.length === 0) {
138
+ return "Table";
139
+ }
140
+ const first = out[0] ?? "";
141
+ if (first >= "0" && first <= "9") {
142
+ return `T${out}`;
143
+ }
144
+ return out;
145
+ }
146
+ function rejectLater(options, known, later, where) {
147
+ const record = options;
148
+ for (const key of Object.keys(record)) {
149
+ const prompt = later[key];
150
+ if (prompt !== undefined) {
151
+ if (record[key] !== undefined) {
152
+ const when = prompt === "later" ? "later" : `in ${prompt}`;
153
+ unavailable(`${where} option ${key} is not available yet. It arrives ${when}.`);
154
+ }
155
+ continue;
156
+ }
157
+ if (!known.has(key)) {
158
+ const accepted = [...known].sort().join(", ");
159
+ const candidates = [...known, ...Object.keys(later)];
160
+ throwNamed2("OKM1060", key, candidates, `${where} option ${key} is not supported. Accepted options: ${accepted}.`);
161
+ }
162
+ }
163
+ }
164
+ function indexCall(columns, isUnique, predicate) {
165
+ return {
166
+ columns,
167
+ isUnique,
168
+ ...predicate !== undefined ? { predicate } : {},
169
+ unique() {
170
+ return indexCall(columns, true, predicate);
171
+ }
172
+ };
173
+ }
174
+ function sqlValue(value) {
175
+ if (typeof value === "string") {
176
+ return value;
177
+ }
178
+ if (typeof value === "number" || typeof value === "boolean") {
179
+ return String(value);
180
+ }
181
+ if (value === null || value === undefined) {
182
+ return "null";
183
+ }
184
+ if ("text" in value && typeof value.text === "string") {
185
+ return value.text;
186
+ }
187
+ if ("name" in value && typeof value.name === "string") {
188
+ return value.name;
189
+ }
190
+ definition("sql accepts a column, a string, a number, a boolean, or null.");
191
+ }
192
+ var hiddenFields = new Set;
193
+ function remember(name, columns) {
194
+ for (const field of Object.keys(columns)) {
195
+ const column = columns[field];
196
+ if (column?.state?.hidden === true)
197
+ hiddenFields.add(`${name}.${field}`);
198
+ }
199
+ }
200
+
201
+ export { table2, index2, sql2, snakeCase, emittedTypeName, rejectLater };
@@ -9,7 +9,7 @@ import {
9
9
  runCall,
10
10
  EMPTY_NOTICES,
11
11
  resultFrom
12
- } from "./xy79j5hq.js";
12
+ } from "./rrstp3kb.js";
13
13
 
14
14
  // src/adapters/pg/pglite.ts
15
15
  import { PGlite } from "@electric-sql/pglite";
@@ -48,7 +48,7 @@ async function open3(config = {}) {
48
48
  return {
49
49
  execute: (text, params, options) => runCall(closed, options, (watch) => session.query(text, params, watch)),
50
50
  batch: (statements, options) => runCall(closed, options, async (watch) => {
51
- const { runAtomicBatch } = await import("./dynq16vb.js");
51
+ const { runAtomicBatch } = await import("./b066g80h.js");
52
52
  return runAtomicBatch(session, statements, watch);
53
53
  }),
54
54
  async release() {
@@ -0,0 +1,84 @@
1
+ import {
2
+ extensionObject
3
+ } from "./th14ygv2.js";
4
+ import {
5
+ OkmError2
6
+ } from "./52szzakm.js";
7
+
8
+ // src/dialects/pg/ext/index.ts
9
+ function extension2(name, options = {}) {
10
+ const schema = options.schema ?? "public";
11
+ const relocatable = options.relocatable ?? true;
12
+ const version = options.version;
13
+ const record = extensionObject({
14
+ name,
15
+ schema,
16
+ relocatable,
17
+ ...version !== undefined ? { version } : {},
18
+ provenance: { origin: "extension", name }
19
+ });
20
+ return {
21
+ name,
22
+ schema,
23
+ relocatable,
24
+ ...version !== undefined ? { version } : {},
25
+ contribute(peers, built) {
26
+ const names = peerNames(peers);
27
+ assertDeclared(names, built);
28
+ return [record];
29
+ }
30
+ };
31
+ }
32
+ function peerNames(peers) {
33
+ if (!Array.isArray(peers)) {
34
+ extensionError("OKM1810", "schema({ extensions }) must be a list of extensions.");
35
+ }
36
+ const counts = new Map;
37
+ for (const peer of peers) {
38
+ if (!isPeer(peer)) {
39
+ extensionError("OKM1810", "schema({ extensions }) must be a list of extensions.");
40
+ }
41
+ counts.set(peer.name, (counts.get(peer.name) ?? 0) + 1);
42
+ }
43
+ for (const [name, count] of counts) {
44
+ if (count > 1)
45
+ extensionError("OKM1813", `Extension ${name} is defined twice.`);
46
+ }
47
+ return counts;
48
+ }
49
+ function assertDeclared(names, built) {
50
+ if (!Array.isArray(built))
51
+ return;
52
+ for (const object of built) {
53
+ if (typeof object !== "object" || object === null || !("dependencies" in object))
54
+ continue;
55
+ const dependencies = object.dependencies;
56
+ if (!Array.isArray(dependencies))
57
+ continue;
58
+ for (const edge of dependencies) {
59
+ if (typeof edge !== "object" || edge === null || !("target" in edge))
60
+ continue;
61
+ const target = edge.target;
62
+ if (typeof target !== "object" || target === null)
63
+ continue;
64
+ if (!("kind" in target) || !("name" in target))
65
+ continue;
66
+ if (target.kind === "extension" && typeof target.name === "string" && !names.has(target.name)) {
67
+ extensionError("OKM1810", `Extension ${target.name} is used but not declared.`);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ function isPeer(value) {
73
+ if (typeof value !== "object" || value === null)
74
+ return false;
75
+ if (!("name" in value) || !("contribute" in value))
76
+ return false;
77
+ return typeof value.name === "string" && value.name.length > 0 && typeof value.contribute === "function";
78
+ }
79
+ function extensionError(code, message) {
80
+ const summary = code === "OKM1813" ? "Keep one definition. A second copy fails at build." : "Declare the extension next to the schema that uses it.";
81
+ throw new OkmError2(code, message, { fix: { summary } });
82
+ }
83
+
84
+ export { extension2 };
@@ -0,0 +1,45 @@
1
+ // src/runtime/trait-read.ts
2
+ function touchFields(model) {
3
+ const traits = model.traits;
4
+ if (traits === undefined)
5
+ return;
6
+ const names = [];
7
+ for (const trait of traits) {
8
+ const touch = trait.touch;
9
+ if (touch === undefined)
10
+ continue;
11
+ for (const field of touch)
12
+ names.push(field);
13
+ }
14
+ return names.length === 0 ? undefined : names;
15
+ }
16
+ function fieldSealed(model, field) {
17
+ const traits = model.traits;
18
+ if (traits === undefined)
19
+ return false;
20
+ for (const trait of traits) {
21
+ const sealed = trait.sealed;
22
+ if (sealed === undefined)
23
+ continue;
24
+ for (const name of sealed)
25
+ if (name === field)
26
+ return true;
27
+ }
28
+ return false;
29
+ }
30
+ function sealingTrait(model, field) {
31
+ const traits = model.traits;
32
+ if (traits === undefined)
33
+ return;
34
+ for (const trait of traits) {
35
+ const sealed = trait.sealed;
36
+ if (sealed === undefined)
37
+ continue;
38
+ for (const name of sealed)
39
+ if (name === field)
40
+ return trait.name;
41
+ }
42
+ return;
43
+ }
44
+
45
+ export { touchFields, fieldSealed, sealingTrait };
@@ -6,7 +6,7 @@ import {
6
6
  acquireTimeout2,
7
7
  errorField2,
8
8
  mapDriverError2
9
- } from "./hd293j9g.js";
9
+ } from "./kyxb62mc.js";
10
10
  export {
11
11
  DriverError2 as DriverError,
12
12
  acquireTimeout2 as acquireTimeout,
@@ -0,0 +1,10 @@
1
+ import {
2
+ VALIDATION_NOT_IMPORTED2,
3
+ VALIDATION_NOT_IMPORTED_FIX2,
4
+ refuseMissingValidation2
5
+ } from "./n442h54c.js";
6
+ export {
7
+ VALIDATION_NOT_IMPORTED2 as VALIDATION_NOT_IMPORTED,
8
+ VALIDATION_NOT_IMPORTED_FIX2 as VALIDATION_NOT_IMPORTED_FIX,
9
+ refuseMissingValidation2 as refuseMissingValidation
10
+ };
@@ -0,0 +1,19 @@
1
+ // src/dialects/pg/quote.ts
2
+ function quoteLiteral(value) {
3
+ return `'${value.replaceAll("'", "''")}'`;
4
+ }
5
+ function arrayElement(encoded, raw) {
6
+ if (raw && (encoded === "true" || encoded === "false" || isBareNumber(encoded))) {
7
+ return encoded;
8
+ }
9
+ return `"${encoded.replaceAll("\\", "\\\\").replaceAll('"', "\\\"")}"`;
10
+ }
11
+ function isBareNumber(encoded) {
12
+ let pattern = bareNumber;
13
+ pattern ??= /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
14
+ bareNumber = pattern;
15
+ return pattern.test(encoded);
16
+ }
17
+ var bareNumber;
18
+
19
+ export { quoteLiteral, arrayElement };
@@ -0,0 +1,32 @@
1
+ // src/runtime/hookm.ts
2
+ function notices(hookm, notices) {
3
+ if (hookm === undefined)
4
+ return;
5
+ for (const notice of notices) {
6
+ for (const hook of hookm)
7
+ call(() => hook.onNotice?.(notice));
8
+ }
9
+ }
10
+ function phase(hookm, phase, depth) {
11
+ if (hookm === undefined)
12
+ return;
13
+ const event = { phase, depth };
14
+ for (const hook of hookm)
15
+ call(() => hook.onTransaction?.(event));
16
+ }
17
+ function report(session, error) {
18
+ for (const hook of session.hookm ?? [])
19
+ call(() => hook.onError?.(error));
20
+ const entry = error instanceof Error ? { code: "code" in error ? String(error.code) : error.name, summary: error.message } : { code: "error", summary: String(error) };
21
+ call(() => session.logger?.error?.(entry));
22
+ }
23
+ function call(fn) {
24
+ try {
25
+ fn();
26
+ } catch {}
27
+ }
28
+ export {
29
+ notices,
30
+ phase,
31
+ report
32
+ };
@@ -1,13 +1,17 @@
1
1
  import {
2
2
  PgSession
3
- } from "./dkn3y60a.js";
3
+ } from "./xw1d69vd.js";
4
+ import {
5
+ isConnectionLost
6
+ } from "./tbszx8mz.js";
4
7
  import {
5
8
  driverErrors,
6
9
  rejectClosed,
7
10
  mapFailure,
8
11
  runCall,
9
- rowsFrom
10
- } from "./xy79j5hq.js";
12
+ rowsFrom,
13
+ resultFrom
14
+ } from "./rrstp3kb.js";
11
15
 
12
16
  // src/adapters/pg/postgres-extra.ts
13
17
  var RESET_ALL = "RESET ALL";
@@ -20,12 +24,18 @@ async function checkout(pool) {
20
24
  const local = new Set;
21
25
  const session = new PgSession(reserved, pool.counters, "reserved", local, pool.isClosed, pool.poolInflight, pool.notices, pool.named);
22
26
  let released = false;
27
+ let lost = false;
28
+ const guard = (run) => lost ? rejectClosed("The connection was lost.") : run().catch((error) => {
29
+ if (isConnectionLost(error))
30
+ lost = true;
31
+ throw error;
32
+ });
23
33
  return {
24
- execute: (text, params, options) => runCall(pool.isClosed(), options, (watch) => session.query(text, params, watch)),
25
- batch: (statements, options) => runCall(pool.isClosed(), options, async (watch) => {
26
- const { runAtomicBatch } = await import("./dynq16vb.js");
34
+ execute: (text, params, options) => guard(() => runCall(pool.isClosed(), options, (watch) => session.query(text, params, watch))),
35
+ batch: (statements, options) => guard(() => runCall(pool.isClosed(), options, async (watch) => {
36
+ const { runAtomicBatch } = await import("./b066g80h.js");
27
37
  return runAtomicBatch(session, statements, watch);
28
- }),
38
+ })),
29
39
  cancel() {
30
40
  session.cancel();
31
41
  },
@@ -34,10 +44,12 @@ async function checkout(pool) {
34
44
  return;
35
45
  released = true;
36
46
  try {
37
- await resetConnection(reserved, session.depth());
47
+ if (!lost)
48
+ await resetConnection(reserved, session.depth());
38
49
  } finally {
39
50
  pool.counters.reserved = Math.max(0, pool.counters.reserved - 1);
40
- reserved.release();
51
+ if (!lost)
52
+ reserved.release();
41
53
  }
42
54
  }
43
55
  };
@@ -112,8 +124,81 @@ function asParams(params) {
112
124
  return [];
113
125
  return params;
114
126
  }
127
+ async function holdCheckout(gate, checkout) {
128
+ try {
129
+ const connection = await checkout();
130
+ let released = false;
131
+ const release = connection.release.bind(connection);
132
+ connection.release = () => {
133
+ if (released)
134
+ return Promise.resolve();
135
+ released = true;
136
+ return release().finally(() => {
137
+ gate.leave();
138
+ });
139
+ };
140
+ return connection;
141
+ } catch (error) {
142
+ gate.leave();
143
+ throw error;
144
+ }
145
+ }
146
+ async function holdListener(gate, start) {
147
+ try {
148
+ const stop = await start();
149
+ let stopped = false;
150
+ return async () => {
151
+ if (stopped)
152
+ return;
153
+ stopped = true;
154
+ try {
155
+ await stop();
156
+ } finally {
157
+ gate.leave();
158
+ }
159
+ };
160
+ } catch (error) {
161
+ gate.leave();
162
+ throw error;
163
+ }
164
+ }
165
+ function watchQuery(pending, watch, onAbort, ctx) {
166
+ return pending.then((result) => {
167
+ finishWatch(pending, watch, onAbort, ctx);
168
+ const why = watch.reason();
169
+ if (why === "timeout" || why === "cancelled")
170
+ return classify(why, watch);
171
+ ctx.note(ctx.text);
172
+ return resultFrom(result, ctx.notices.since(ctx.start));
173
+ }, (error) => {
174
+ finishWatch(pending, watch, onAbort, ctx);
175
+ return classify(error, watch);
176
+ });
177
+ }
178
+ function finishWatch(pending, watch, onAbort, ctx) {
179
+ ctx.leave();
180
+ ctx.untrack(pending);
181
+ watch.signal.removeEventListener("abort", onAbort);
182
+ }
183
+ async function classify(error, watch) {
184
+ const errors = await driverErrors();
185
+ if (error instanceof errors.DriverError)
186
+ return Promise.reject(error);
187
+ const why = typeof error === "string" ? error : watch.reason();
188
+ if (why === "timeout") {
189
+ return Promise.reject(errors.timedOut(typeof error === "string" ? undefined : error));
190
+ }
191
+ const code = errors.errorField(error, "code");
192
+ if (why === "cancelled" || code === "57014") {
193
+ return Promise.reject(errors.cancelled(typeof error === "string" ? undefined : error));
194
+ }
195
+ return Promise.reject(errors.mapDriverError(error));
196
+ }
115
197
  export {
116
198
  checkout,
117
199
  describe,
118
- stream
200
+ holdCheckout,
201
+ holdListener,
202
+ stream,
203
+ watchQuery
119
204
  };