okmodel 0.7.0 → 0.8.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 (195) hide show
  1. package/dist/adapters/capabilities.d.ts +32 -0
  2. package/dist/adapters/failure.d.ts +1 -1
  3. package/dist/adapters/pg/bun-sql.d.ts +53 -0
  4. package/dist/adapters/pg/bunsql-extra.d.ts +1 -1
  5. package/dist/adapters/pg/bunsql.d.ts +1 -1
  6. package/dist/adapters/pg/neon-extra.d.ts +18 -0
  7. package/dist/adapters/pg/neon.d.ts +104 -0
  8. package/dist/adapters/pg/no-inflight-timeout.d.ts +1 -1
  9. package/dist/contracts/error.d.ts +1 -1
  10. package/dist/dialects/pg/fn/index.d.ts +39 -1
  11. package/dist/dialects/pg/fn/index.js +118 -26
  12. package/dist/dialects/pg/index.d.ts +2 -0
  13. package/dist/dialects/pg/index.js +393 -18
  14. package/dist/dialects/pg/introspect.d.ts +11 -0
  15. package/dist/dialects/pg/operators.d.ts +1 -1
  16. package/dist/dialects/pg/ops/fragment.d.ts +119 -0
  17. package/dist/dialects/pg/ops/lane.d.ts +49 -0
  18. package/dist/dialects/pg/view/client.d.ts +14 -6
  19. package/dist/dialects/pg/view/index.d.ts +73 -1
  20. package/dist/dialects/pg/view/index.js +156 -5
  21. package/dist/dialects/pg/view/scratch.d.ts +8 -5
  22. package/dist/runtime/otel.d.ts +105 -0
  23. package/dist/runtime/otel.js +97 -0
  24. package/dist/runtime/pg/bun.js +4 -4
  25. package/dist/runtime/pg/neon.d.ts +38 -0
  26. package/dist/runtime/pg/neon.js +64 -0
  27. package/dist/runtime/pg/pg.js +4 -4
  28. package/dist/runtime/pg/pglite.js +4 -4
  29. package/dist/runtime/pg/postgresjs.js +4 -4
  30. package/dist/runtime/plan.d.ts +1 -1
  31. package/dist/runtime/sql-fragment.d.ts +43 -0
  32. package/dist/runtime/tenancy/index.js +10 -10
  33. package/dist/runtime/topology.d.ts +1 -1
  34. package/dist/runtime/traits/index.js +15 -16
  35. package/dist/runtime/types.d.ts +15 -1
  36. package/dist/runtime/validate/index.js +4 -4
  37. package/dist/shared/{mtaszv5a.js → 0wrea3jq.js} +102 -4
  38. package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
  39. package/dist/shared/{w79hsckn.js → 14x60fbf.js} +5 -5
  40. package/dist/shared/{ek2wt2dz.js → 16kvjebh.js} +4 -4
  41. package/dist/shared/{svncdeh5.js → 195pzzzz.js} +8 -8
  42. package/dist/shared/{gzaveazc.js → 1d9q9cv2.js} +29 -2
  43. package/dist/shared/{jvd0mqag.js → 3449rcae.js} +5 -5
  44. package/dist/shared/{14vx95q4.js → 35q0n9tz.js} +7 -7
  45. package/dist/shared/3bb7wsqt.js +99 -0
  46. package/dist/shared/{y6njgyda.js → 3t6kw83m.js} +2 -2
  47. package/dist/shared/{81ebdx9p.js → 4m6hskg8.js} +4 -4
  48. package/dist/shared/{xhfsfkgk.js → 4vbf83xx.js} +9 -2
  49. package/dist/shared/{bg3rym3g.js → 63f4ksbz.js} +2 -2
  50. package/dist/shared/{pt94kz7f.js → 6m78c8ss.js} +1 -1
  51. package/dist/shared/{5e3tf63j.js → 760ppr76.js} +14 -6
  52. package/dist/shared/{zm0ptry0.js → 7ghwamrf.js} +1 -1
  53. package/dist/shared/{xnxsed62.js → 9dr2qnx7.js} +14 -14
  54. package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
  55. package/dist/shared/{q5c6ngn3.js → a62rb2da.js} +1 -1
  56. package/dist/shared/{kb2sdhfb.js → ae4j5f42.js} +17 -1
  57. package/dist/shared/agsfb86s.js +233 -0
  58. package/dist/shared/{7k9grvf6.js → b6d6p0zc.js} +5 -5
  59. package/dist/shared/{tbrvgw6z.js → bah9nbg3.js} +17 -16
  60. package/dist/shared/{5fe3kbsh.js → bnby0esn.js} +1 -1
  61. package/dist/shared/bsek72fg.js +225 -0
  62. package/dist/shared/{1w508jbr.js → bxas03mq.js} +21 -17
  63. package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
  64. package/dist/shared/{tsvww22q.js → dpc2r7rb.js} +7 -7
  65. package/dist/shared/{vb6qfyve.js → e8zyaqvj.js} +2 -2
  66. package/dist/shared/{hyh73qk6.js → ecn8mfdq.js} +5 -5
  67. package/dist/shared/{gs74dbj5.js → f4jy1j7x.js} +27 -14
  68. package/dist/shared/{ttsqgp4p.js → fjpnhqan.js} +2 -2
  69. package/dist/shared/{xjk7hnn5.js → g5yc06ka.js} +2 -2
  70. package/dist/shared/{w72kgg4q.js → hfqmpasr.js} +6 -6
  71. package/dist/shared/{kr0jzbw2.js → hm5f8jby.js} +7 -7
  72. package/dist/shared/{dkxgzaqd.js → hqpxf4a4.js} +1 -1
  73. package/dist/shared/{cn957f8d.js → jebgrkeq.js} +3 -3
  74. package/dist/shared/{wa07eas9.js → jp36k7dp.js} +11 -11
  75. package/dist/shared/jx2m62cs.js +96 -0
  76. package/dist/shared/{sfz1ksn6.js → k86n8vq3.js} +2 -2
  77. package/dist/shared/{67txcrcw.js → kgwp4jdd.js} +4 -4
  78. package/dist/shared/{8skf0cam.js → kj9d8maq.js} +1 -1
  79. package/dist/shared/{aytqh5y2.js → m4xff2a6.js} +2 -2
  80. package/dist/shared/{zp9fmend.js → mfedzr74.js} +4 -4
  81. package/dist/shared/{ax7qv55k.js → mkrn359n.js} +60 -11
  82. package/dist/shared/{m6p12kbr.js → mnvjvqyp.js} +10 -10
  83. package/dist/shared/{1qa0qajz.js → mtw6jz76.js} +1 -1
  84. package/dist/shared/{1est4ezg.js → n05z9nwz.js} +3 -3
  85. package/dist/shared/{pbp1ss85.js → n0jmpgj1.js} +2 -2
  86. package/dist/shared/{ktz42yez.js → n41w4fbz.js} +5 -5
  87. package/dist/shared/{n816peh1.js → n454kcnw.js} +1 -1
  88. package/dist/shared/n7kg8mmx.js +61 -0
  89. package/dist/shared/{g6evj1j3.js → needfe47.js} +1 -1
  90. package/dist/shared/{2shdbn8q.js → njga14v4.js} +9 -9
  91. package/dist/shared/{vqrjpcqn.js → nmnsgj7x.js} +1 -1
  92. package/dist/shared/{b5pftnn2.js → p3xbdcvt.js} +14 -18
  93. package/dist/shared/{te5as7z7.js → p5nh3r8q.js} +3 -3
  94. package/dist/shared/{p6qc5gcp.js → pan0370z.js} +6 -6
  95. package/dist/shared/{79dt02vc.js → q0cqt2sp.js} +1 -1
  96. package/dist/shared/{5v3xf80k.js → qd9hhd8f.js} +1 -1
  97. package/dist/shared/{bm22fvzr.js → qfw14tna.js} +2 -2
  98. package/dist/shared/{9s0ypp87.js → sjk86yrx.js} +1 -1
  99. package/dist/shared/{3v7t1yrv.js → th3be82n.js} +2 -2
  100. package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
  101. package/dist/shared/{vczs8gd4.js → v1wad97q.js} +2 -2
  102. package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
  103. package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
  104. package/dist/shared/{bz84tkzm.js → wcrheftc.js} +2 -2
  105. package/dist/shared/{ab9gmbwy.js → wvdjznah.js} +5 -5
  106. package/dist/shared/{7mnme5tn.js → wz2a78mp.js} +1 -1
  107. package/dist/shared/{9y3mmmh1.js → xfhe73sb.js} +1 -1
  108. package/dist/shared/{je4axnm8.js → z581d7ny.js} +2 -2
  109. package/dist/shared/{x933k9a3.js → zbqbmmrp.js} +10 -10
  110. package/dist/shared/{rs73fca9.js → zgex00fd.js} +6 -6
  111. package/dist/shared/{jznfax0y.js → zq1he88x.js} +4 -4
  112. package/dist/tooling/cli.js +26 -13
  113. package/dist/tooling/driver-run.js +4971 -0
  114. package/dist/tooling/driver-test.d.ts +36 -0
  115. package/dist/tooling/migrate/commands.d.ts +2 -2
  116. package/dist/tooling/migrate/index.js +9 -9
  117. package/dist/tooling/migrate/project.d.ts +3 -0
  118. package/dist/tooling/shared/03k6res6.js +210 -0
  119. package/dist/tooling/shared/08kemxjd.js +10 -0
  120. package/dist/tooling/shared/2revefqt.js +209 -0
  121. package/dist/tooling/shared/2wtvc7rw.js +1425 -0
  122. package/dist/tooling/shared/345tbc2k.js +16 -0
  123. package/dist/tooling/shared/3m1hkg7z.js +344 -0
  124. package/dist/tooling/shared/3rrw5w8f.js +81 -0
  125. package/dist/tooling/shared/3tq8pnb8.js +131 -0
  126. package/dist/tooling/shared/417zdsk7.js +194 -0
  127. package/dist/tooling/shared/4d2w25vw.js +40 -0
  128. package/dist/tooling/shared/54tqkxja.js +51 -0
  129. package/dist/tooling/shared/5bvw2nev.js +12 -0
  130. package/dist/tooling/shared/6nyfyw70.js +231 -0
  131. package/dist/tooling/shared/72fyg4zv.js +160 -0
  132. package/dist/tooling/shared/733a1tq3.js +38 -0
  133. package/dist/tooling/shared/7ae7rjmn.js +20 -0
  134. package/dist/tooling/shared/7kms6fvj.js +20 -0
  135. package/dist/tooling/shared/8sqrsw3s.js +49 -0
  136. package/dist/tooling/shared/96ps4g1z.js +32 -0
  137. package/dist/tooling/shared/9kazs5p6.js +195 -0
  138. package/dist/tooling/shared/9xzm7hjg.js +38 -0
  139. package/dist/tooling/shared/a6pp9d12.js +49 -0
  140. package/dist/tooling/shared/a7q7t4n3.js +22 -0
  141. package/dist/tooling/shared/aftb2mwr.js +18 -0
  142. package/dist/tooling/shared/bz2dqhab.js +311 -0
  143. package/dist/tooling/shared/cmptmb4f.js +12 -0
  144. package/dist/tooling/shared/ddjtfgnx.js +177 -0
  145. package/dist/tooling/shared/djydjpqt.js +261 -0
  146. package/dist/tooling/shared/dw08f3m8.js +9 -0
  147. package/dist/tooling/shared/dy672fz6.js +16 -0
  148. package/dist/tooling/shared/dzx85q70.js +66 -0
  149. package/dist/tooling/shared/ec71zqgt.js +270 -0
  150. package/dist/tooling/shared/ep8zh3bk.js +6 -0
  151. package/dist/tooling/shared/f9mphxej.js +3789 -0
  152. package/dist/tooling/shared/fb9k2qwd.js +89 -0
  153. package/dist/tooling/shared/g9ad4n80.js +211 -0
  154. package/dist/tooling/shared/gfvtj6d0.js +94 -0
  155. package/dist/tooling/shared/gmcf9cxf.js +294 -0
  156. package/dist/tooling/shared/htnaj77v.js +17 -0
  157. package/dist/tooling/shared/j9t5s12a.js +7 -0
  158. package/dist/tooling/shared/jne7b93p.js +42 -0
  159. package/dist/tooling/shared/ma2340rx.js +118 -0
  160. package/dist/tooling/shared/mtrqn2hn.js +505 -0
  161. package/dist/tooling/shared/n4jqhpqz.js +27 -0
  162. package/dist/tooling/shared/nf7jmhfa.js +20 -0
  163. package/dist/tooling/shared/p7f08ktn.js +332 -0
  164. package/dist/tooling/shared/ppnnnvj8.js +13 -0
  165. package/dist/tooling/shared/pqy21k24.js +312 -0
  166. package/dist/tooling/shared/pw8fgahx.js +69 -0
  167. package/dist/tooling/shared/pwsytxm5.js +17 -0
  168. package/dist/tooling/shared/rf83gr2d.js +94 -0
  169. package/dist/tooling/shared/rq5kk8j6.js +401 -0
  170. package/dist/tooling/shared/rs1jb051.js +12 -0
  171. package/dist/tooling/shared/smn6kz1p.js +157 -0
  172. package/dist/tooling/shared/spk1jg3r.js +1696 -0
  173. package/dist/tooling/shared/tn8gay14.js +143 -0
  174. package/dist/tooling/shared/vraj6d74.js +42 -0
  175. package/dist/tooling/shared/vs0t6qt8.js +64 -0
  176. package/dist/tooling/shared/vx86qjv8.js +150 -0
  177. package/dist/tooling/shared/w7qe8sj1.js +140 -0
  178. package/dist/tooling/shared/wt7j7nf6.js +15 -0
  179. package/dist/tooling/shared/wwnekq5n.js +6 -0
  180. package/dist/tooling/shared/xhrnjch9.js +185 -0
  181. package/dist/tooling/shared/xjs6zqtc.js +190 -0
  182. package/dist/tooling/shared/y031jct9.js +16 -0
  183. package/dist/tooling/shared/y5656f0e.js +233 -0
  184. package/dist/tooling/shared/yfr8hzhm.js +604 -0
  185. package/dist/tooling/shared/yk9mp7vb.js +250 -0
  186. package/dist/tooling/shared/yw30vnq2.js +139 -0
  187. package/dist/tooling/shared/z8d7ptht.js +618 -0
  188. package/dist/tooling/shared/zhwnfyb2.js +9 -0
  189. package/dist/tooling/shared/zvnhh1n0.js +198 -0
  190. package/dist/tooling/testing/index.js +3 -3
  191. package/package.json +14 -2
  192. package/dist/shared/y34a8714.js +0 -150
  193. package/dist/shared/zy8r7qvz.js +0 -116
  194. package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
  195. package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
@@ -1,18 +1,6 @@
1
1
  import {
2
2
  policyObject
3
3
  } from "./bdk4sty6.js";
4
- import {
5
- functionObject,
6
- triggerObject
7
- } from "./y34a8714.js";
8
- import {
9
- viewObject,
10
- materializedViewObject,
11
- materializedViewIndex
12
- } from "./zy8r7qvz.js";
13
- import {
14
- extensionObject
15
- } from "./r3j8s5y0.js";
16
4
  import {
17
5
  dependencyOrder,
18
6
  catalog,
@@ -20,10 +8,14 @@ import {
20
8
  domainType,
21
9
  isDomain
22
10
  } from "./ywspezzx.js";
11
+ import {
12
+ extensionObject
13
+ } from "./r3j8s5y0.js";
23
14
  import {
24
15
  canonicalJson,
25
16
  staticNamespace2,
26
17
  templateNamespace2,
18
+ assertNamespace2,
27
19
  identityKey2,
28
20
  identityLabel2,
29
21
  sameRef2,
@@ -48,7 +40,8 @@ import {
48
40
  import {
49
41
  sha2562,
50
42
  assertIdentifier2,
51
- fitIdentifier2
43
+ fitIdentifier2,
44
+ deterministicName2
52
45
  } from "./nfzc5z0w.js";
53
46
  import {
54
47
  catalogError2
@@ -164,6 +157,242 @@ function defaultPrivilegeObject(input) {
164
157
  };
165
158
  }
166
159
 
160
+ // src/contracts/catalog/routine.ts
161
+ var VOLATILITY = new Set(["volatile", "stable", "immutable"]);
162
+ var SECURITY = new Set(["invoker", "definer"]);
163
+ var TIMING = new Set(["before", "after", "instead"]);
164
+ var LEVEL = new Set(["row", "statement"]);
165
+ var EVENT_ORDER = ["insert", "update", "delete", "truncate"];
166
+ var TYPE_TEXT = /^[A-Za-z][A-Za-z0-9_ ]*(\(\d+(,\s*\d+)?\))?(\[\])*$/;
167
+ function functionObject(input) {
168
+ assertIdentifier2(input.name, "function");
169
+ const namespace = input.namespace ?? staticNamespace2("public");
170
+ assertNamespace2(namespace);
171
+ assertProvenance(input.provenance);
172
+ if (input.language !== "sql" && input.language !== "plpgsql") {
173
+ catalogError2("OKM1020", `Function ${input.name} language must be sql or plpgsql.`);
174
+ }
175
+ const volatility = input.volatility ?? "volatile";
176
+ if (!VOLATILITY.has(volatility)) {
177
+ catalogError2("OKM1020", `Function ${input.name} volatility ${volatility} is not supported.`);
178
+ }
179
+ const security = input.security ?? "invoker";
180
+ if (!SECURITY.has(security)) {
181
+ catalogError2("OKM1020", `Function ${input.name} security ${security} is not supported.`);
182
+ }
183
+ assertTypeName(input.returns, `function ${input.name} return type`);
184
+ const args = (input.arguments ?? []).map((argument) => readArgument(input.name, argument));
185
+ if (input.body.length === 0) {
186
+ catalogError2("OKM1020", `Function ${input.name} needs a body.`);
187
+ }
188
+ const atomic = input.atomic === true;
189
+ if (atomic && input.language !== "sql") {
190
+ catalogError2("OKM1020", `Function ${input.name} BEGIN ATOMIC needs language sql.`);
191
+ }
192
+ if (input.searchPath !== undefined && input.searchPath.trim().length === 0) {
193
+ catalogError2("OKM1020", `Function ${input.name} search_path is empty.`);
194
+ }
195
+ const definition = {
196
+ arguments: args,
197
+ returns: input.returns,
198
+ language: input.language,
199
+ volatility,
200
+ security,
201
+ body: input.body,
202
+ ...input.searchPath !== undefined ? { searchPath: input.searchPath } : {},
203
+ ...atomic ? { atomic: true } : {}
204
+ };
205
+ return {
206
+ kind: "function",
207
+ identity: {
208
+ kind: "function",
209
+ namespace,
210
+ name: input.name,
211
+ argTypes: args.map((arg) => arg.type)
212
+ },
213
+ owner: input.owner ?? "managed",
214
+ definition,
215
+ dependencies: normaliseEdges(input.dependencies ?? []),
216
+ provenance: input.provenance
217
+ };
218
+ }
219
+ function triggerObject(input) {
220
+ assertIdentifier2(input.name, "trigger");
221
+ assertNamespace2(input.parent.namespace);
222
+ assertIdentifier2(input.parent.name, "trigger table");
223
+ assertProvenance(input.provenance);
224
+ if (!TIMING.has(input.timing)) {
225
+ catalogError2("OKM1020", `Trigger ${input.name} timing ${input.timing} is not supported.`);
226
+ }
227
+ if (!LEVEL.has(input.level)) {
228
+ catalogError2("OKM1020", `Trigger ${input.name} level ${input.level} is not supported.`);
229
+ }
230
+ const events = EVENT_ORDER.filter((event) => input.events.includes(event));
231
+ if (events.length === 0) {
232
+ catalogError2("OKM1020", `Trigger ${input.name} needs an event.`);
233
+ }
234
+ const updateOf = input.updateOf === undefined ? undefined : [...input.updateOf];
235
+ if (updateOf !== undefined) {
236
+ if (!events.includes("update")) {
237
+ catalogError2("OKM1020", `Trigger ${input.name} lists UPDATE OF columns without an update event.`);
238
+ }
239
+ if (input.level !== "row") {
240
+ catalogError2("OKM1020", `Trigger ${input.name} UPDATE OF columns need level row.`);
241
+ }
242
+ for (const column of updateOf)
243
+ assertIdentifier2(column, "trigger column");
244
+ }
245
+ assertIdentifier2(input.calls.name, "trigger function");
246
+ assertNamespace2(input.calls.namespace);
247
+ for (const typeName of input.calls.argTypes)
248
+ assertTypeName(typeName, `trigger ${input.name}`);
249
+ const edges = [
250
+ { kind: "table", namespace: input.parent.namespace, name: input.parent.name },
251
+ {
252
+ kind: "function",
253
+ namespace: input.calls.namespace,
254
+ name: input.calls.name,
255
+ argTypes: input.calls.argTypes
256
+ },
257
+ ...(updateOf ?? []).map((column) => ({
258
+ kind: "column",
259
+ parent: input.parent,
260
+ name: column
261
+ })),
262
+ ...input.dependencies ?? []
263
+ ];
264
+ const definition = {
265
+ timing: input.timing,
266
+ events,
267
+ level: input.level,
268
+ calls: {
269
+ namespace: input.calls.namespace,
270
+ name: input.calls.name,
271
+ argTypes: [...input.calls.argTypes]
272
+ },
273
+ ...updateOf !== undefined && updateOf.length > 0 ? { updateOf } : {},
274
+ ...input.when !== undefined && input.when.length > 0 ? { when: input.when } : {}
275
+ };
276
+ return {
277
+ kind: "trigger",
278
+ identity: { kind: "trigger", parent: input.parent, name: input.name },
279
+ owner: input.owner ?? "managed",
280
+ definition,
281
+ dependencies: normaliseEdges(edges),
282
+ provenance: input.provenance
283
+ };
284
+ }
285
+ function readArgument(fn, argument) {
286
+ assertIdentifier2(argument.name, `function ${fn} argument`);
287
+ assertTypeName(argument.type, `function ${fn} argument ${argument.name}`);
288
+ return { name: argument.name, type: argument.type };
289
+ }
290
+ function assertTypeName(typeName, role) {
291
+ if (!TYPE_TEXT.test(typeName)) {
292
+ catalogError2("OKM1020", `${role} ${typeName} is not a type name.`);
293
+ }
294
+ }
295
+
296
+ // src/contracts/catalog/view.ts
297
+ function normaliseViewQuery(query) {
298
+ return query.trim().replace(/;\s*$/, "");
299
+ }
300
+ function viewObject(input) {
301
+ const namespace = input.namespace ?? staticNamespace2("public");
302
+ const columns = readColumns(input.name, input.columns);
303
+ const query = readQuery(input.name, input.query);
304
+ assertNamespace2(namespace);
305
+ assertProvenance(input.provenance);
306
+ const definition = {
307
+ columns,
308
+ query,
309
+ ...input.securityInvoker === true ? { securityInvoker: true } : {}
310
+ };
311
+ return {
312
+ kind: "view",
313
+ identity: { kind: "view", namespace, name: input.name },
314
+ owner: input.owner ?? "managed",
315
+ definition,
316
+ dependencies: normaliseEdges(input.dependencies ?? []),
317
+ provenance: input.provenance
318
+ };
319
+ }
320
+ function materializedViewObject(input) {
321
+ const namespace = input.namespace ?? staticNamespace2("public");
322
+ const columns = readColumns(input.name, input.columns);
323
+ const query = readQuery(input.name, input.query);
324
+ assertNamespace2(namespace);
325
+ assertProvenance(input.provenance);
326
+ const definition = {
327
+ columns,
328
+ query,
329
+ ...input.refresh === "concurrently" ? { refresh: "concurrently" } : {}
330
+ };
331
+ return {
332
+ kind: "materializedView",
333
+ identity: { kind: "materializedView", namespace, name: input.name },
334
+ owner: input.owner ?? "managed",
335
+ definition,
336
+ dependencies: normaliseEdges(input.dependencies ?? []),
337
+ provenance: input.provenance
338
+ };
339
+ }
340
+ function materializedViewIndex(input) {
341
+ assertNamespace2(input.parent.namespace);
342
+ assertIdentifier2(input.parent.name, "index parent");
343
+ assertProvenance(input.provenance);
344
+ const columns = [...input.columns];
345
+ for (const name of columns)
346
+ assertIdentifier2(name, "index column");
347
+ if (columns.length === 0 && input.expression === undefined) {
348
+ catalogError2("OKM1020", `Index on ${input.parent.name} needs a column or an expression.`);
349
+ }
350
+ const nameKey = input.nameKey ?? (columns.length > 0 ? columns.join("_") : "expr");
351
+ const name = input.name === undefined ? deterministicName2({ parent: input.parent.name, purpose: "index", nameKey }) : fitIdentifier2(input.name);
352
+ const parentView = {
353
+ kind: "materializedView",
354
+ namespace: input.parent.namespace,
355
+ name: input.parent.name
356
+ };
357
+ return {
358
+ kind: "index",
359
+ identity: { kind: "index", parent: input.parent, name },
360
+ owner: input.owner ?? "managed",
361
+ definition: {
362
+ columns,
363
+ unique: input.unique === true,
364
+ nameKey,
365
+ ...input.expression !== undefined ? { expression: input.expression } : {},
366
+ ...input.predicate !== undefined ? { predicate: input.predicate } : {}
367
+ },
368
+ dependencies: normaliseEdges(input.dependencies ?? [parentView]),
369
+ provenance: input.provenance
370
+ };
371
+ }
372
+ function readColumns(view, columns) {
373
+ assertIdentifier2(view, "view");
374
+ if (columns.length === 0)
375
+ catalogError2("OKM1020", `View ${view} needs a column.`);
376
+ const seen = new Set;
377
+ return columns.map((column) => {
378
+ assertIdentifier2(column.name, `view ${view} column`);
379
+ if (seen.has(column.name)) {
380
+ catalogError2("OKM1020", `View ${view} lists column ${column.name} twice.`);
381
+ }
382
+ seen.add(column.name);
383
+ if (column.dataType.length === 0 || /[;'"\\]/.test(column.dataType)) {
384
+ catalogError2("OKM1020", `View ${view} column ${column.name} type is not a type name.`);
385
+ }
386
+ return { name: column.name, dataType: column.dataType };
387
+ });
388
+ }
389
+ function readQuery(view, query) {
390
+ const text = normaliseViewQuery(query);
391
+ if (text.length === 0)
392
+ catalogError2("OKM1020", `View ${view} needs a query.`);
393
+ return text;
394
+ }
395
+
167
396
  // src/contracts/catalog/document.ts
168
397
  function creationOrder2(source) {
169
398
  return dependencyOrder(source.objects);
@@ -1565,4 +1794,4 @@ function assertNeverKind(value) {
1565
1794
  return catalogError2("OKM1020", `Unexpected kind ${JSON.stringify(value)}.`);
1566
1795
  }
1567
1796
 
1568
- export { roleObject, grantObject, defaultPrivilegeObject, creationOrder2, renameColumn2, renameTable2, serializeCatalog2, catalogHash2, startupCatalog2, startupHash2, loadTrustedCatalog2, catalogFileText2, parseCatalog2 };
1797
+ export { roleObject, grantObject, defaultPrivilegeObject, functionObject, triggerObject, normaliseViewQuery, viewObject, materializedViewObject, materializedViewIndex, creationOrder2, renameColumn2, renameTable2, serializeCatalog2, catalogHash2, startupCatalog2, startupHash2, loadTrustedCatalog2, catalogFileText2, parseCatalog2 };
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  noticeBuffer,
3
3
  WireSession
4
- } from "./1qa0qajz.js";
4
+ } from "./mtw6jz76.js";
5
5
  import {
6
6
  NODE_POSTGRES_CAPABILITIES,
7
7
  driverErrors,
8
8
  rejectClosed,
9
9
  mapFailure,
10
10
  runCall
11
- } from "./kb2sdhfb.js";
11
+ } from "./ae4j5f42.js";
12
12
 
13
13
  // src/adapters/pg/nodepostgres.ts
14
14
  import net from "node:net";
@@ -55,7 +55,7 @@ function open4(config) {
55
55
  counters.busy = Math.max(0, counters.busy - 1);
56
56
  }, inflight);
57
57
  const held = { pool, acquireMs, counters, notices, named, isClosed };
58
- const checkout = () => closed ? rejectClosed() : import("./zp9fmend.js").then((mod) => mod.checkout(held));
58
+ const checkout = () => closed ? rejectClosed() : import("./mfedzr74.js").then((mod) => mod.checkout(held));
59
59
  return {
60
60
  capabilities: NODE_POSTGRES_CAPABILITIES,
61
61
  execute(text, params, options) {
@@ -88,14 +88,14 @@ function open4(config) {
88
88
  reserve: () => checkout(),
89
89
  stream(text, params) {
90
90
  return async function* () {
91
- const { streamRows } = await import("./zp9fmend.js");
91
+ const { streamRows } = await import("./mfedzr74.js");
92
92
  yield* streamRows(checkout, text, params);
93
93
  }();
94
94
  },
95
95
  listen(channel, onNotify) {
96
96
  if (closed)
97
97
  return rejectClosed();
98
- return import("./zp9fmend.js").then((mod) => mod.listen(held, channel, onNotify));
98
+ return import("./mfedzr74.js").then((mod) => mod.listen(held, channel, onNotify));
99
99
  },
100
100
  cancel() {
101
101
  for (const pending of inflight)
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  catalogFileText2
3
- } from "./qq3899ht.js";
3
+ } from "./12z7aznj.js";
4
4
  import {
5
5
  OkmError2
6
6
  } from "./52szzakm.js";
@@ -14,7 +14,7 @@ async function assertCompatible(pool, schema, recordedHash, source, options) {
14
14
  if (code.artifact !== undefined) {
15
15
  const artifact = code.artifact;
16
16
  await loadOnce(`text\x00${artifact.hash}`, async () => {
17
- const { loadTrustedCatalog } = await import("./dk8v79p3.js");
17
+ const { loadTrustedCatalog } = await import("./d5nmj7vv.js");
18
18
  loadTrustedCatalog(artifact.text, artifact.hash);
19
19
  });
20
20
  } else if (code.fromFile) {
@@ -28,7 +28,7 @@ async function assertCompatible(pool, schema, recordedHash, source, options) {
28
28
  }
29
29
  });
30
30
  }
31
- const { loadTrustedCatalog } = await import("./dk8v79p3.js");
31
+ const { loadTrustedCatalog } = await import("./d5nmj7vv.js");
32
32
  loadTrustedCatalog(text, code.hash);
33
33
  });
34
34
  }
@@ -42,7 +42,7 @@ async function codeHash(schema, source) {
42
42
  const listed = await readHashFile(source.catalogDir);
43
43
  if (listed !== undefined)
44
44
  return { hash: listed, fromFile: true };
45
- const { catalogHash } = await import("./dk8v79p3.js");
45
+ const { catalogHash } = await import("./d5nmj7vv.js");
46
46
  return { hash: catalogHash(schemaCatalog(schema)), fromFile: false };
47
47
  }
48
48
  function schemaCatalog(schema) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  open2
3
- } from "./14vx95q4.js";
4
- import"./qq3899ht.js";
3
+ } from "./35q0n9tz.js";
4
+ import"./12z7aznj.js";
5
5
  import"./n442h54c.js";
6
6
  import {
7
7
  CURRENT,
@@ -14,21 +14,21 @@ import {
14
14
  import {
15
15
  expandProvisioned,
16
16
  provisionHistoryIsKnown
17
- } from "./m6p12kbr.js";
18
- import"./8skf0cam.js";
19
- import"./b5pftnn2.js";
17
+ } from "./mnvjvqyp.js";
18
+ import"./kj9d8maq.js";
19
+ import"./p3xbdcvt.js";
20
20
  import {
21
21
  projectPath,
22
22
  loadMigrations,
23
23
  loadConfig
24
- } from "./gs74dbj5.js";
24
+ } from "./f4jy1j7x.js";
25
25
  import {
26
26
  sessionFailure,
27
27
  finishQuiet,
28
28
  assertTargetPolicy,
29
29
  listTargets
30
- } from "./tsvww22q.js";
31
- import"./9s0ypp87.js";
30
+ } from "./dpc2r7rb.js";
31
+ import"./sjk86yrx.js";
32
32
  import {
33
33
  OkmError2
34
34
  } from "./52szzakm.js";
@@ -1,9 +1,16 @@
1
+ import {
2
+ emitSqlSelect,
3
+ decodeSqlNumber
4
+ } from "./3bb7wsqt.js";
1
5
  import {
2
6
  refusePrototypeKey
3
- } from "./q5c6ngn3.js";
7
+ } from "./a62rb2da.js";
4
8
  import {
5
9
  isWindow
6
10
  } from "./9a4ae4p8.js";
11
+ import {
12
+ readSelectFragment
13
+ } from "./bsek72fg.js";
7
14
  import {
8
15
  emitWhere,
9
16
  emitOrder,
@@ -16,7 +23,7 @@ import {
16
23
  list,
17
24
  isRecord,
18
25
  fail2
19
- } from "./67txcrcw.js";
26
+ } from "./kgwp4jdd.js";
20
27
  import {
21
28
  throwNamed2
22
29
  } from "./52szzakm.js";
@@ -46,6 +53,15 @@ function statement(spec) {
46
53
  sink.text(projectExpr(`t.${quote(item.column.sql)}`, item.column.dataType));
47
54
  sink.mark(`s:${item.column.field}`);
48
55
  outputs?.fields.push({ key: item.column.field, at: column, decode: item.column.decode });
56
+ } else if (item.kind === "sql") {
57
+ emitSqlSelect(table, item.parts, sink, "t");
58
+ sink.text("::text");
59
+ sink.mark(`s:${item.as}`);
60
+ outputs?.fields.push({
61
+ key: item.as,
62
+ at: column,
63
+ decode: item.textual === true ? AS_TEXT : decodeSqlNumber
64
+ });
49
65
  } else {
50
66
  emitWindow(table, item.window, sink);
51
67
  sink.text("::text");
@@ -171,6 +187,17 @@ function readSpec(table, select) {
171
187
  items.push({ kind: "column", column });
172
188
  continue;
173
189
  }
190
+ const sql = readSelectFragment(entry);
191
+ if (sql !== undefined) {
192
+ const as = readAs(sql.as, "fragment");
193
+ if (names.has(as) || table.columns.has(as)) {
194
+ fail2("OKM1120", `fragment as ${as} clashes with a column of ${table.model.name}.`, "Pick an as name that is not a column.");
195
+ }
196
+ names.add(as);
197
+ ordinals.set(as, String(items.length + 1));
198
+ items.push(sql.textual === true ? { kind: "sql", as, parts: sql.parts, textual: true } : { kind: "sql", as, parts: sql.parts });
199
+ continue;
200
+ }
174
201
  if (!isWindow(entry)) {
175
202
  fail2("OKM1120", "select takes field names or a window helper. A plain object is not a window.", "Pass rowNumber, rank, denseRank, or runningTotal.");
176
203
  }
@@ -2,11 +2,11 @@ import {
2
2
  assertAuthorDrift2,
3
3
  catalogQuery2,
4
4
  managedRoleOptions2
5
- } from "./ax7qv55k.js";
6
- import"./b5pftnn2.js";
7
- import"./tsvww22q.js";
8
- import"./9s0ypp87.js";
9
- import"./qq3899ht.js";
5
+ } from "./mkrn359n.js";
6
+ import"./p3xbdcvt.js";
7
+ import"./dpc2r7rb.js";
8
+ import"./sjk86yrx.js";
9
+ import"./12z7aznj.js";
10
10
  export {
11
11
  assertAuthorDrift2 as assertAuthorDrift,
12
12
  catalogQuery2 as catalogQuery,
@@ -6,7 +6,7 @@ import {
6
6
  runCall,
7
7
  EMPTY_NOTICES,
8
8
  resultFrom
9
- } from "./kb2sdhfb.js";
9
+ } from "./ae4j5f42.js";
10
10
 
11
11
  // src/adapters/pg/postgresjs.ts
12
12
  import net from "node:net";
@@ -118,17 +118,17 @@ function open2(config) {
118
118
  return sockets.occupy(() => runCall(closed, options, (watch) => root.query(text, params, watch)));
119
119
  },
120
120
  batch(statements, options) {
121
- return sockets.occupy(() => import("./je4axnm8.js").then((mod) => mod.runBatch(held, statements, options)));
121
+ return sockets.occupy(() => import("./z581d7ny.js").then((mod) => mod.runBatch(held, statements, options)));
122
122
  },
123
123
  reserve() {
124
124
  const gate = sockets.busyGate();
125
125
  gate.enter();
126
- return import("./je4axnm8.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
126
+ return import("./z581d7ny.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
127
127
  gate.leave();
128
128
  throw error;
129
129
  });
130
130
  },
131
- describe: (text, params) => sockets.occupy(() => import("./je4axnm8.js").then((mod) => mod.describe(sql, text, params))),
131
+ describe: (text, params) => sockets.occupy(() => import("./z581d7ny.js").then((mod) => mod.describe(sql, text, params))),
132
132
  stream(text, params) {
133
133
  const gate = sockets.busyGate();
134
134
  return async function* () {
@@ -143,7 +143,7 @@ function open2(config) {
143
143
  listen(channel, onNotify) {
144
144
  const gate = sockets.listenerGate();
145
145
  gate.enter();
146
- return import("./je4axnm8.js").then((mod) => mod.holdListener(gate, async () => {
146
+ return import("./z581d7ny.js").then((mod) => mod.holdListener(gate, async () => {
147
147
  const listening = await sql.listen(channel, onNotify);
148
148
  return async () => {
149
149
  await listening.unlisten();
@@ -213,7 +213,7 @@ class PgSession {
213
213
  onAbort();
214
214
  else
215
215
  watch.signal.addEventListener("abort", onAbort, { once: true });
216
- return import("./je4axnm8.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
216
+ return import("./z581d7ny.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
217
217
  start,
218
218
  text,
219
219
  notices: this.notices,
@@ -265,7 +265,7 @@ class PgSession {
265
265
  }
266
266
  }
267
267
  async function* loadStream(sql, text, params) {
268
- const { stream } = await import("./je4axnm8.js");
268
+ const { stream } = await import("./z581d7ny.js");
269
269
  yield* stream(sql, text, params);
270
270
  }
271
271
  function send(sql, text, params, named) {
@@ -0,0 +1,99 @@
1
+ import {
2
+ isFragmentParts
3
+ } from "./bsek72fg.js";
4
+ import {
5
+ refuseHidden,
6
+ quote,
7
+ list,
8
+ fail2
9
+ } from "./kgwp4jdd.js";
10
+ import {
11
+ OkmError2,
12
+ throwNamed2
13
+ } from "./52szzakm.js";
14
+
15
+ // src/runtime/sql-fragment.ts
16
+ function emitSqlValue(table, ref, value, sink) {
17
+ const dot = ref.indexOf(".");
18
+ const alias = dot < 0 ? ref : ref.slice(0, dot);
19
+ writeFragment(requireParts(value), sink, alias, ref, table, "where");
20
+ }
21
+ function emitSqlSelect(table, parts, sink, alias) {
22
+ writeFragment(parts, sink, alias, undefined, table, "select");
23
+ }
24
+ function decodeSqlNumber(wire) {
25
+ const parsed = Number(wire);
26
+ if (!Number.isFinite(parsed)) {
27
+ throw new OkmError2("OKM1125", "A select fragment must be a number.", {
28
+ fix: { summary: "Use a numeric expression, such as length(title). Text stays in where." }
29
+ });
30
+ }
31
+ return parsed;
32
+ }
33
+ function requireParts(value) {
34
+ if (!isFragmentParts(value)) {
35
+ throw new OkmError2("OKM1125", "A fragment was not created by fragment``.", {
36
+ fix: { summary: "Call fragment`...`." }
37
+ });
38
+ }
39
+ return value;
40
+ }
41
+ function writeFragment(parts, sink, alias, ref, table, place) {
42
+ sink.mark(":g");
43
+ sink.text("(");
44
+ for (const part of parts)
45
+ writePart(part, sink, alias, ref, table, place);
46
+ sink.mark(":g");
47
+ sink.text(")");
48
+ }
49
+ function writePart(part, sink, alias, ref, table, place) {
50
+ if (part.k === "t") {
51
+ sink.mark(`:t:${String(part.s.length)}:${part.s}`);
52
+ sink.text(part.s);
53
+ return;
54
+ }
55
+ if (part.k === "p") {
56
+ sink.mark(":p");
57
+ sink.param(part.v);
58
+ return;
59
+ }
60
+ if (part.k === "n") {
61
+ sink.mark(":n");
62
+ sink.text("null");
63
+ return;
64
+ }
65
+ if (part.k === "i") {
66
+ writeIdent(part.n, table, sink, alias, place);
67
+ return;
68
+ }
69
+ if (part.k === "c") {
70
+ if (ref === undefined) {
71
+ throw new OkmError2("OKM1125", "fragment.column belongs on a where field.", {
72
+ fix: { summary: "Use ident(name) in select, or put fragment.column on a where field." }
73
+ });
74
+ }
75
+ sink.mark(":c");
76
+ sink.text(ref);
77
+ return;
78
+ }
79
+ writeFragment(part.parts, sink, alias, ref, table, place);
80
+ }
81
+ function writeIdent(name, table, sink, alias, place) {
82
+ const column = table.columns.get(name);
83
+ if (column === undefined) {
84
+ throwNamed2("OKM1120", name, table.names, `Field ${name} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
85
+ }
86
+ if (place === "select") {
87
+ if (column.hidden) {
88
+ fail2("OKM1120", `Field ${column.field} is hidden.`, "A select fragment cannot name a hidden field.");
89
+ }
90
+ } else {
91
+ refuseHidden(column);
92
+ }
93
+ sink.mark(`:i:${String(column.field.length)}:${column.field}`);
94
+ sink.text(alias);
95
+ sink.text(".");
96
+ sink.text(quote(column.sql));
97
+ }
98
+
99
+ export { emitSqlValue, emitSqlSelect, decodeSqlNumber };
@@ -15,14 +15,14 @@ import {
15
15
  expectOf2,
16
16
  allowSet2,
17
17
  noteGuarded2
18
- } from "./1w508jbr.js";
18
+ } from "./bxas03mq.js";
19
19
  import {
20
20
  emitWhere,
21
21
  projectExpr,
22
22
  quote,
23
23
  isRecord,
24
24
  fail2
25
- } from "./67txcrcw.js";
25
+ } from "./kgwp4jdd.js";
26
26
 
27
27
  // src/runtime/version.ts
28
28
  function planVersioned(schema, table, input, options, mods) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  noTimeout
3
- } from "./79dt02vc.js";
3
+ } from "./q0cqt2sp.js";
4
4
  import {
5
5
  PGLITE_CAPABILITIES,
6
6
  driverErrors,
@@ -11,12 +11,12 @@ import {
11
11
  runCall,
12
12
  EMPTY_NOTICES,
13
13
  resultFrom
14
- } from "./kb2sdhfb.js";
14
+ } from "./ae4j5f42.js";
15
15
 
16
16
  // src/adapters/pg/pglite.ts
17
17
  import { PGlite } from "@electric-sql/pglite";
18
18
  async function open3(config = {}) {
19
- const wire = await import("./g6evj1j3.js");
19
+ const wire = await import("./needfe47.js");
20
20
  const db = new PGlite({
21
21
  dataDir: config.dataDir ?? "memory://",
22
22
  parsers: wire.parsers,
@@ -67,7 +67,7 @@ async function open3(config = {}) {
67
67
  return;
68
68
  released = true;
69
69
  try {
70
- const { resetQueried } = await import("./5fe3kbsh.js");
70
+ const { resetQueried } = await import("./bnby0esn.js");
71
71
  await resetQueried(session);
72
72
  } finally {
73
73
  slot.release();