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
@@ -0,0 +1,198 @@
1
+ import {
2
+ decodeRows,
3
+ readHandle,
4
+ readCall,
5
+ attachHttp
6
+ } from "./mtrqn2hn.js";
7
+ import {
8
+ OkmError,
9
+ throwNamed,
10
+ selectedColumns,
11
+ parseOrder,
12
+ rejectKeys,
13
+ readLimit,
14
+ indexes,
15
+ quote,
16
+ list,
17
+ isRecord,
18
+ registerFailFix,
19
+ fail2
20
+ } from "./f9mphxej.js";
21
+
22
+ // src/runtime/page.ts
23
+ registerFailFix("OKM1130", "Request the next page with the same orderBy and the exact next value the previous page returned. The cursor encodes that order.");
24
+ var OPTIONS = [
25
+ "where",
26
+ "select",
27
+ "orderBy",
28
+ "limit",
29
+ "include",
30
+ "after",
31
+ "route",
32
+ "signal",
33
+ "timeout"
34
+ ];
35
+ function build3(session, table, options, mods, view, pin) {
36
+ try {
37
+ return plan(session, table, options, mods, view, pin);
38
+ } catch (error) {
39
+ throw error instanceof OkmError ? attachHttp(session.http, error) : error;
40
+ }
41
+ }
42
+ function plan(session, table, options, mods, view, pin) {
43
+ const record = isRecord(options) ? options : {};
44
+ if (Object.hasOwn(record, "search")) {
45
+ fail2("OKM1120", "page() does not take search in this version. Use find({ search, limit }) for a ranked list.", "Ranked pages are later. find({ search, limit }) returns one ranked list.");
46
+ }
47
+ rejectKeys(record, OPTIONS, "page");
48
+ const indexed = indexes(session.schema).get(table);
49
+ if (indexed === undefined)
50
+ fail2("OKM1120", `Table ${table} is not in the schema.`);
51
+ if (record.limit === undefined)
52
+ fail2("OKM1101", "page() needs a limit.");
53
+ const size = readLimit(record.limit);
54
+ if (size < 1) {
55
+ throw new OkmError("invalid", "page() limit must be at least 1.", { kind: "invalid" });
56
+ }
57
+ const keys = orderKeys(indexed, record.orderBy);
58
+ const signature = `${table}:${keys.map((key) => `${key.column.field}.${key.dir}.${key.nulls}`).join(",")}`;
59
+ const after = record.after === undefined || record.after === null ? undefined : keyset(keys, signature, record.after);
60
+ const wanted = selectedColumns(indexed, record.select);
61
+ const extra = keys.filter((key) => !wanted.includes(key.column)).map((key) => key.column.field);
62
+ const select = extra.length === 0 ? record.select : [...wanted.map((column) => column.field), ...extra];
63
+ const orderBy = {};
64
+ for (const key of keys)
65
+ orderBy[key.column.field] = { dir: key.dir, nulls: key.nulls };
66
+ const call = {
67
+ ...readCall("find", table, {
68
+ where: record.where,
69
+ select,
70
+ orderBy,
71
+ limit: size + 1,
72
+ include: record.include,
73
+ signal: record.signal,
74
+ timeout: record.timeout,
75
+ route: record.route
76
+ }, undefined, session.scope, session.schema.model[table], session.schema, view),
77
+ ...after !== undefined ? { after } : {},
78
+ ...pin !== undefined ? { pin } : {}
79
+ };
80
+ return readHandle(session, table, call, mods, async (compiled, rows) => {
81
+ const items = await decodeRows(compiled, rows, table);
82
+ const more = items.length > size;
83
+ const kept = more ? items.slice(0, size) : items;
84
+ const last = rows[size - 1];
85
+ const next = more && last !== undefined ? makeCursor(compiled, last, keys, signature) : null;
86
+ if (extra.length > 0) {
87
+ for (const item of kept) {
88
+ for (const field of extra)
89
+ delete item[field];
90
+ }
91
+ }
92
+ return { items: kept, next };
93
+ });
94
+ }
95
+ function orderKeys(table, orderBy) {
96
+ if (orderBy !== undefined && !isRecord(orderBy)) {
97
+ fail2("OKM1120", "orderBy must be an object of fields.");
98
+ }
99
+ const keys = [];
100
+ for (const field of Object.keys(orderBy ?? {})) {
101
+ const column = table.columns.get(field);
102
+ if (column === undefined) {
103
+ throwNamed("OKM1120", field, table.names, `Field ${field} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
104
+ }
105
+ keys.push({ column, ...parseOrder(field, orderBy?.[field]) });
106
+ }
107
+ if (table.model.primary.length === 0) {
108
+ fail2("OKM1120", `page() needs a primary key on ${table.model.name} to break ties.`);
109
+ }
110
+ for (const field of table.model.primary) {
111
+ const column = table.columns.get(field);
112
+ if (column === undefined || keys.some((key) => key.column === column))
113
+ continue;
114
+ keys.push({ column, dir: "asc", nulls: "last" });
115
+ }
116
+ return keys;
117
+ }
118
+ function keyset(keys, signature, token) {
119
+ const values = readCursor(token, signature, keys.length);
120
+ return (sink, alias) => {
121
+ sink.mark(`k:${signature}:${values.map((value) => value === null ? "n" : "v").join("")}`);
122
+ let wrote = false;
123
+ for (let index = 0;index < keys.length; index += 1) {
124
+ const key = keys[index];
125
+ const value = values[index];
126
+ if (key === undefined || value === undefined)
127
+ continue;
128
+ if (value === null && key.nulls === "last")
129
+ continue;
130
+ sink.text(wrote ? " or (" : "(");
131
+ wrote = true;
132
+ for (let before = 0;before < index; before += 1) {
133
+ const prior = keys[before];
134
+ const held = values[before];
135
+ if (prior === undefined || held === undefined)
136
+ continue;
137
+ const ref = `${alias}.${quote(prior.column.sql)}`;
138
+ if (held === null) {
139
+ sink.text(`${ref} is null and `);
140
+ } else {
141
+ sink.text(`${ref} = `);
142
+ sink.param(held);
143
+ sink.text(" and ");
144
+ }
145
+ }
146
+ const ref = `${alias}.${quote(key.column.sql)}`;
147
+ if (value === null) {
148
+ sink.text(`${ref} is not null`);
149
+ } else {
150
+ sink.text(key.nulls === "last" ? `(${ref} ${compare(key)} ` : `${ref} ${compare(key)} `);
151
+ sink.param(value);
152
+ sink.text(key.nulls === "last" ? ` or ${ref} is null)` : "");
153
+ }
154
+ sink.text(")");
155
+ }
156
+ if (!wrote)
157
+ sink.text("false");
158
+ };
159
+ }
160
+ function compare(key) {
161
+ return key.dir === "asc" ? ">" : "<";
162
+ }
163
+ function makeCursor(plan, row, keys, signature) {
164
+ const values = keys.map((key) => {
165
+ const at = plan.outputs.fields.find((field) => field.key === key.column.field)?.at;
166
+ return at === undefined ? null : row[at] ?? null;
167
+ });
168
+ const bytes = new TextEncoder().encode(JSON.stringify([signature, ...values]));
169
+ let binary = "";
170
+ for (const byte of bytes)
171
+ binary += String.fromCharCode(byte);
172
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
173
+ }
174
+ function readCursor(token, signature, count) {
175
+ let parsed;
176
+ if (typeof token === "string") {
177
+ try {
178
+ const binary = atob(token.replaceAll("-", "+").replaceAll("_", "/"));
179
+ const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
180
+ parsed = JSON.parse(new TextDecoder().decode(bytes));
181
+ } catch {
182
+ parsed = undefined;
183
+ }
184
+ }
185
+ if (!Array.isArray(parsed) || typeof parsed[0] !== "string") {
186
+ fail2("OKM1130", "after is not a cursor that page() returned.");
187
+ }
188
+ if (parsed[0] !== signature) {
189
+ fail2("OKM1130", `The cursor was made for another order: ${parsed[0]}. This page orders by ${signature}.`);
190
+ }
191
+ const values = parsed.slice(1);
192
+ if (values.length !== count || !values.every((value) => value === null || typeof value === "string")) {
193
+ fail2("OKM1130", "after is not a cursor that page() returned.");
194
+ }
195
+ return values;
196
+ }
197
+
198
+ export { build3 };
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  testing2
3
- } from "../../shared/7k9grvf6.js";
4
- import"../../shared/9s0ypp87.js";
5
- import"../../shared/qq3899ht.js";
3
+ } from "../../shared/b6d6p0zc.js";
4
+ import"../../shared/sjk86yrx.js";
5
+ import"../../shared/12z7aznj.js";
6
6
  export {
7
7
  testing2 as testing
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "okmodel",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "okmodel is a catalog-first TypeScript ORM, PostgreSQL first.",
5
5
  "keywords": [
6
6
  "migrations",
@@ -63,6 +63,10 @@
63
63
  "types": "./dist/runtime/pg/bun.d.ts",
64
64
  "import": "./dist/runtime/pg/bun.js"
65
65
  },
66
+ "./pg/neon": {
67
+ "types": "./dist/runtime/pg/neon.d.ts",
68
+ "import": "./dist/runtime/pg/neon.js"
69
+ },
66
70
  "./ids": {
67
71
  "types": "./dist/runtime/ids/index.d.ts",
68
72
  "import": "./dist/runtime/ids/index.js"
@@ -87,6 +91,10 @@
87
91
  "types": "./dist/runtime/validate/index.d.ts",
88
92
  "import": "./dist/runtime/validate/index.js"
89
93
  },
94
+ "./otel": {
95
+ "types": "./dist/runtime/otel.d.ts",
96
+ "import": "./dist/runtime/otel.js"
97
+ },
90
98
  "./ext": {
91
99
  "types": "./dist/dialects/pg/ext/index.d.ts",
92
100
  "import": "./dist/dialects/pg/ext/index.js"
@@ -109,7 +117,7 @@
109
117
  }
110
118
  },
111
119
  "scripts": {
112
- "build": "rm -rf dist && bun build ./src/contracts/index.ts ./src/contracts/internal.ts ./src/dialects/pg/index.ts ./src/runtime/pg/postgresjs.ts ./src/runtime/pg/pglite.ts ./src/runtime/pg/pg.ts ./src/runtime/pg/bun.ts ./src/runtime/ids/index.ts ./src/runtime/safety/index.ts ./src/runtime/traits/index.ts ./src/runtime/tenancy/index.ts ./src/runtime/validate/index.ts ./src/dialects/pg/ext/index.ts ./src/dialects/pg/fn/index.ts ./src/dialects/pg/view/index.ts ./src/dialects/pg/ext/citext.ts ./src/dialects/pg/ext/pg-trgm.ts ./src/tooling/migrate/index.ts ./src/tooling/testing/index.ts ./src/tooling/cli.ts --outdir ./dist --root ./src --format esm --target node --splitting --chunk-naming=shared/[hash].js --external postgres --external @electric-sql/pglite --external pg --external bun && bunx tsc -p tsconfig.build.json && rm -f ./dist/dialects/pg/temporal.local.d.ts && bun ./scripts/write-bin-wrappers.ts",
120
+ "build": "rm -rf dist && bun build ./src/contracts/index.ts ./src/contracts/internal.ts ./src/dialects/pg/index.ts ./src/runtime/pg/postgresjs.ts ./src/runtime/pg/pglite.ts ./src/runtime/pg/pg.ts ./src/runtime/pg/bun.ts ./src/runtime/pg/neon.ts ./src/runtime/ids/index.ts ./src/runtime/safety/index.ts ./src/runtime/traits/index.ts ./src/runtime/tenancy/index.ts ./src/runtime/validate/index.ts ./src/runtime/otel.ts ./src/dialects/pg/ext/index.ts ./src/dialects/pg/fn/index.ts ./src/dialects/pg/view/index.ts ./src/dialects/pg/ext/citext.ts ./src/dialects/pg/ext/pg-trgm.ts ./src/tooling/migrate/index.ts ./src/tooling/testing/index.ts ./src/tooling/cli.ts --outdir ./dist --root ./src --format esm --target node --splitting --chunk-naming=shared/[hash].js --external postgres --external @electric-sql/pglite --external pg --external bun --external @neondatabase/serverless && bunx tsc -p tsconfig.build.json && rm -f ./dist/dialects/pg/temporal.local.d.ts && bun build ./packages/harness/src/driver-run.ts --outdir ./dist/tooling --format esm --target node --splitting --chunk-naming=shared/[hash].js --external postgres --external @electric-sql/pglite --external pg --external bun --external @neondatabase/serverless && bun ./scripts/write-bin-wrappers.ts",
113
121
  "driver-bench": "bun ./scripts/driver-bench.ts",
114
122
  "typecheck": "bunx tsc --noEmit -p tsconfig.json",
115
123
  "editor-check": "bun ./scripts/editor-check.ts",
@@ -168,6 +176,7 @@
168
176
  },
169
177
  "peerDependencies": {
170
178
  "@electric-sql/pglite": "^0.5.8",
179
+ "@neondatabase/serverless": "^1.2.0",
171
180
  "pg": "^8.16.0",
172
181
  "postgres": "^3.4.9"
173
182
  },
@@ -175,6 +184,9 @@
175
184
  "@electric-sql/pglite": {
176
185
  "optional": true
177
186
  },
187
+ "@neondatabase/serverless": {
188
+ "optional": true
189
+ },
178
190
  "pg": {
179
191
  "optional": true
180
192
  },
@@ -1,150 +0,0 @@
1
- import {
2
- staticNamespace2,
3
- assertNamespace2,
4
- normaliseEdges,
5
- assertProvenance
6
- } from "./358zsv4r.js";
7
- import {
8
- assertIdentifier2
9
- } from "./nfzc5z0w.js";
10
- import {
11
- catalogError2
12
- } from "./52szzakm.js";
13
-
14
- // src/contracts/catalog/routine.ts
15
- var VOLATILITY = new Set(["volatile", "stable", "immutable"]);
16
- var SECURITY = new Set(["invoker", "definer"]);
17
- var TIMING = new Set(["before", "after", "instead"]);
18
- var LEVEL = new Set(["row", "statement"]);
19
- var EVENT_ORDER = ["insert", "update", "delete", "truncate"];
20
- var TYPE_TEXT = /^[A-Za-z][A-Za-z0-9_ ]*(\(\d+(,\s*\d+)?\))?(\[\])*$/;
21
- function functionObject(input) {
22
- assertIdentifier2(input.name, "function");
23
- const namespace = input.namespace ?? staticNamespace2("public");
24
- assertNamespace2(namespace);
25
- assertProvenance(input.provenance);
26
- if (input.language !== "sql" && input.language !== "plpgsql") {
27
- catalogError2("OKM1020", `Function ${input.name} language must be sql or plpgsql.`);
28
- }
29
- const volatility = input.volatility ?? "volatile";
30
- if (!VOLATILITY.has(volatility)) {
31
- catalogError2("OKM1020", `Function ${input.name} volatility ${volatility} is not supported.`);
32
- }
33
- const security = input.security ?? "invoker";
34
- if (!SECURITY.has(security)) {
35
- catalogError2("OKM1020", `Function ${input.name} security ${security} is not supported.`);
36
- }
37
- assertTypeName(input.returns, `function ${input.name} return type`);
38
- const args = (input.arguments ?? []).map((argument) => readArgument(input.name, argument));
39
- if (input.body.length === 0) {
40
- catalogError2("OKM1020", `Function ${input.name} needs a body.`);
41
- }
42
- const atomic = input.atomic === true;
43
- if (atomic && input.language !== "sql") {
44
- catalogError2("OKM1020", `Function ${input.name} BEGIN ATOMIC needs language sql.`);
45
- }
46
- if (input.searchPath !== undefined && input.searchPath.trim().length === 0) {
47
- catalogError2("OKM1020", `Function ${input.name} search_path is empty.`);
48
- }
49
- const definition = {
50
- arguments: args,
51
- returns: input.returns,
52
- language: input.language,
53
- volatility,
54
- security,
55
- body: input.body,
56
- ...input.searchPath !== undefined ? { searchPath: input.searchPath } : {},
57
- ...atomic ? { atomic: true } : {}
58
- };
59
- return {
60
- kind: "function",
61
- identity: {
62
- kind: "function",
63
- namespace,
64
- name: input.name,
65
- argTypes: args.map((arg) => arg.type)
66
- },
67
- owner: input.owner ?? "managed",
68
- definition,
69
- dependencies: normaliseEdges(input.dependencies ?? []),
70
- provenance: input.provenance
71
- };
72
- }
73
- function triggerObject(input) {
74
- assertIdentifier2(input.name, "trigger");
75
- assertNamespace2(input.parent.namespace);
76
- assertIdentifier2(input.parent.name, "trigger table");
77
- assertProvenance(input.provenance);
78
- if (!TIMING.has(input.timing)) {
79
- catalogError2("OKM1020", `Trigger ${input.name} timing ${input.timing} is not supported.`);
80
- }
81
- if (!LEVEL.has(input.level)) {
82
- catalogError2("OKM1020", `Trigger ${input.name} level ${input.level} is not supported.`);
83
- }
84
- const events = EVENT_ORDER.filter((event) => input.events.includes(event));
85
- if (events.length === 0) {
86
- catalogError2("OKM1020", `Trigger ${input.name} needs an event.`);
87
- }
88
- const updateOf = input.updateOf === undefined ? undefined : [...input.updateOf];
89
- if (updateOf !== undefined) {
90
- if (!events.includes("update")) {
91
- catalogError2("OKM1020", `Trigger ${input.name} lists UPDATE OF columns without an update event.`);
92
- }
93
- if (input.level !== "row") {
94
- catalogError2("OKM1020", `Trigger ${input.name} UPDATE OF columns need level row.`);
95
- }
96
- for (const column of updateOf)
97
- assertIdentifier2(column, "trigger column");
98
- }
99
- assertIdentifier2(input.calls.name, "trigger function");
100
- assertNamespace2(input.calls.namespace);
101
- for (const typeName of input.calls.argTypes)
102
- assertTypeName(typeName, `trigger ${input.name}`);
103
- const edges = [
104
- { kind: "table", namespace: input.parent.namespace, name: input.parent.name },
105
- {
106
- kind: "function",
107
- namespace: input.calls.namespace,
108
- name: input.calls.name,
109
- argTypes: input.calls.argTypes
110
- },
111
- ...(updateOf ?? []).map((column) => ({
112
- kind: "column",
113
- parent: input.parent,
114
- name: column
115
- })),
116
- ...input.dependencies ?? []
117
- ];
118
- const definition = {
119
- timing: input.timing,
120
- events,
121
- level: input.level,
122
- calls: {
123
- namespace: input.calls.namespace,
124
- name: input.calls.name,
125
- argTypes: [...input.calls.argTypes]
126
- },
127
- ...updateOf !== undefined && updateOf.length > 0 ? { updateOf } : {},
128
- ...input.when !== undefined && input.when.length > 0 ? { when: input.when } : {}
129
- };
130
- return {
131
- kind: "trigger",
132
- identity: { kind: "trigger", parent: input.parent, name: input.name },
133
- owner: input.owner ?? "managed",
134
- definition,
135
- dependencies: normaliseEdges(edges),
136
- provenance: input.provenance
137
- };
138
- }
139
- function readArgument(fn, argument) {
140
- assertIdentifier2(argument.name, `function ${fn} argument`);
141
- assertTypeName(argument.type, `function ${fn} argument ${argument.name}`);
142
- return { name: argument.name, type: argument.type };
143
- }
144
- function assertTypeName(typeName, role) {
145
- if (!TYPE_TEXT.test(typeName)) {
146
- catalogError2("OKM1020", `${role} ${typeName} is not a type name.`);
147
- }
148
- }
149
-
150
- export { functionObject, triggerObject };
@@ -1,116 +0,0 @@
1
- import {
2
- staticNamespace2,
3
- assertNamespace2,
4
- normaliseEdges,
5
- assertProvenance
6
- } from "./358zsv4r.js";
7
- import {
8
- assertIdentifier2,
9
- fitIdentifier2,
10
- deterministicName2
11
- } from "./nfzc5z0w.js";
12
- import {
13
- catalogError2
14
- } from "./52szzakm.js";
15
-
16
- // src/contracts/catalog/view.ts
17
- function normaliseViewQuery(query) {
18
- return query.trim().replace(/;\s*$/, "");
19
- }
20
- function viewObject(input) {
21
- const namespace = input.namespace ?? staticNamespace2("public");
22
- const columns = readColumns(input.name, input.columns);
23
- const query = readQuery(input.name, input.query);
24
- assertNamespace2(namespace);
25
- assertProvenance(input.provenance);
26
- const definition = {
27
- columns,
28
- query,
29
- ...input.securityInvoker === true ? { securityInvoker: true } : {}
30
- };
31
- return {
32
- kind: "view",
33
- identity: { kind: "view", namespace, name: input.name },
34
- owner: input.owner ?? "managed",
35
- definition,
36
- dependencies: normaliseEdges(input.dependencies ?? []),
37
- provenance: input.provenance
38
- };
39
- }
40
- function materializedViewObject(input) {
41
- const namespace = input.namespace ?? staticNamespace2("public");
42
- const columns = readColumns(input.name, input.columns);
43
- const query = readQuery(input.name, input.query);
44
- assertNamespace2(namespace);
45
- assertProvenance(input.provenance);
46
- const definition = {
47
- columns,
48
- query,
49
- ...input.refresh === "concurrently" ? { refresh: "concurrently" } : {}
50
- };
51
- return {
52
- kind: "materializedView",
53
- identity: { kind: "materializedView", namespace, name: input.name },
54
- owner: input.owner ?? "managed",
55
- definition,
56
- dependencies: normaliseEdges(input.dependencies ?? []),
57
- provenance: input.provenance
58
- };
59
- }
60
- function materializedViewIndex(input) {
61
- assertNamespace2(input.parent.namespace);
62
- assertIdentifier2(input.parent.name, "index parent");
63
- assertProvenance(input.provenance);
64
- const columns = [...input.columns];
65
- for (const name of columns)
66
- assertIdentifier2(name, "index column");
67
- if (columns.length === 0 && input.expression === undefined) {
68
- catalogError2("OKM1020", `Index on ${input.parent.name} needs a column or an expression.`);
69
- }
70
- const nameKey = input.nameKey ?? (columns.length > 0 ? columns.join("_") : "expr");
71
- const name = input.name === undefined ? deterministicName2({ parent: input.parent.name, purpose: "index", nameKey }) : fitIdentifier2(input.name);
72
- const parentView = {
73
- kind: "materializedView",
74
- namespace: input.parent.namespace,
75
- name: input.parent.name
76
- };
77
- return {
78
- kind: "index",
79
- identity: { kind: "index", parent: input.parent, name },
80
- owner: input.owner ?? "managed",
81
- definition: {
82
- columns,
83
- unique: input.unique === true,
84
- nameKey,
85
- ...input.expression !== undefined ? { expression: input.expression } : {},
86
- ...input.predicate !== undefined ? { predicate: input.predicate } : {}
87
- },
88
- dependencies: normaliseEdges(input.dependencies ?? [parentView]),
89
- provenance: input.provenance
90
- };
91
- }
92
- function readColumns(view, columns) {
93
- assertIdentifier2(view, "view");
94
- if (columns.length === 0)
95
- catalogError2("OKM1020", `View ${view} needs a column.`);
96
- const seen = new Set;
97
- return columns.map((column) => {
98
- assertIdentifier2(column.name, `view ${view} column`);
99
- if (seen.has(column.name)) {
100
- catalogError2("OKM1020", `View ${view} lists column ${column.name} twice.`);
101
- }
102
- seen.add(column.name);
103
- if (column.dataType.length === 0 || /[;'"\\]/.test(column.dataType)) {
104
- catalogError2("OKM1020", `View ${view} column ${column.name} type is not a type name.`);
105
- }
106
- return { name: column.name, dataType: column.dataType };
107
- });
108
- }
109
- function readQuery(view, query) {
110
- const text = normaliseViewQuery(query);
111
- if (text.length === 0)
112
- catalogError2("OKM1020", `View ${view} needs a query.`);
113
- return text;
114
- }
115
-
116
- export { normaliseViewQuery, viewObject, materializedViewObject, materializedViewIndex };
@@ -1,3 +1,6 @@
1
+ import {
2
+ readClientGenerator
3
+ } from "./rwmrejjz.js";
1
4
  import {
2
5
  definition,
3
6
  rejected,
@@ -11,9 +14,6 @@ import {
11
14
  REFERENTIAL_ACTIONS,
12
15
  referentialAction
13
16
  } from "./4e4c6vq2.js";
14
- import {
15
- readClientGenerator
16
- } from "./rwmrejjz.js";
17
17
 
18
18
  // src/dialects/pg/column.ts
19
19
  class ColumnBuilder2 {
@@ -1,11 +1,11 @@
1
- import {
2
- definition,
3
- unavailable
4
- } from "./tmbdywx0.js";
5
1
  import {
6
2
  callerLocation,
7
3
  withLocation
8
4
  } from "./y6jdds7g.js";
5
+ import {
6
+ definition,
7
+ unavailable
8
+ } from "./tmbdywx0.js";
9
9
  import {
10
10
  OkmError2,
11
11
  throwNamed2