okmodel 0.6.0 → 0.7.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 (157) hide show
  1. package/README.md +100 -1131
  2. package/dist/adapters/capabilities.d.ts +3 -0
  3. package/dist/adapters/failure.d.ts +13 -2
  4. package/dist/adapters/lazy-errors.d.ts +22 -0
  5. package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
  6. package/dist/adapters/pg/bunsql.d.ts +14 -1
  7. package/dist/adapters/pg/cursor.d.ts +17 -0
  8. package/dist/adapters/pg/no-inflight-timeout.d.ts +11 -8
  9. package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
  10. package/dist/adapters/pg/nodepostgres.d.ts +12 -0
  11. package/dist/adapters/pg/pglite-wire.d.ts +24 -0
  12. package/dist/adapters/pg/pglite.d.ts +10 -0
  13. package/dist/adapters/pg/postgres-extra.d.ts +27 -11
  14. package/dist/adapters/pg/reserved.d.ts +42 -0
  15. package/dist/adapters/pg/session.d.ts +0 -18
  16. package/dist/contracts/connection.d.ts +7 -6
  17. package/dist/dialects/pg/floor.d.ts +68 -0
  18. package/dist/dialects/pg/index.d.ts +6 -1
  19. package/dist/dialects/pg/index.js +49 -159
  20. package/dist/dialects/pg/keys.d.ts +11 -8
  21. package/dist/dialects/pg/model.d.ts +40 -0
  22. package/dist/dialects/pg/morph.d.ts +43 -0
  23. package/dist/dialects/pg/operator-fit.d.ts +2 -2
  24. package/dist/dialects/pg/operators.d.ts +14 -7
  25. package/dist/dialects/pg/ops/bucket.d.ts +65 -0
  26. package/dist/dialects/pg/ops/inc.d.ts +2 -2
  27. package/dist/dialects/pg/ops/matches.d.ts +9 -12
  28. package/dist/dialects/pg/ops/relevance.d.ts +13 -0
  29. package/dist/dialects/pg/ops/search-query.d.ts +22 -0
  30. package/dist/dialects/pg/ops/window.d.ts +103 -0
  31. package/dist/dialects/pg/preset.d.ts +1 -1
  32. package/dist/dialects/pg/relations.d.ts +100 -3
  33. package/dist/dialects/pg/schema.d.ts +31 -3
  34. package/dist/dialects/pg/view/index.js +1 -1
  35. package/dist/runtime/aggregate.d.ts +8 -2
  36. package/dist/runtime/bucket-group.d.ts +70 -0
  37. package/dist/runtime/conflict.d.ts +22 -4
  38. package/dist/runtime/include.d.ts +0 -8
  39. package/dist/runtime/inflight.d.ts +1 -1
  40. package/dist/runtime/page.d.ts +4 -1
  41. package/dist/runtime/pg/bun.js +12 -6
  42. package/dist/runtime/pg/pg.js +5 -5
  43. package/dist/runtime/pg/pglite.d.ts +1 -0
  44. package/dist/runtime/pg/pglite.js +9 -9
  45. package/dist/runtime/pg/postgresjs.js +5 -5
  46. package/dist/runtime/plan.d.ts +95 -5
  47. package/dist/runtime/read-stream.d.ts +13 -16
  48. package/dist/runtime/result-name.d.ts +17 -0
  49. package/dist/runtime/server-check.d.ts +3 -3
  50. package/dist/runtime/sort-bind.d.ts +21 -0
  51. package/dist/runtime/sort.d.ts +56 -0
  52. package/dist/runtime/sync.d.ts +70 -0
  53. package/dist/runtime/tenancy/index.js +7 -5
  54. package/dist/runtime/text-search.d.ts +20 -0
  55. package/dist/runtime/traits/index.d.ts +80 -0
  56. package/dist/runtime/traits/index.js +175 -11
  57. package/dist/runtime/tree.d.ts +38 -0
  58. package/dist/runtime/types.d.ts +218 -22
  59. package/dist/runtime/validate/index.js +2 -2
  60. package/dist/runtime/version.d.ts +39 -0
  61. package/dist/runtime/window.d.ts +21 -0
  62. package/dist/runtime/write.d.ts +54 -2
  63. package/dist/shared/{wkme6tep.js → 14vx95q4.js} +8 -16
  64. package/dist/shared/1est4ezg.js +313 -0
  65. package/dist/shared/{4az561fn.js → 1qa0qajz.js} +8 -23
  66. package/dist/shared/{2cg3wnxc.js → 1w508jbr.js} +593 -130
  67. package/dist/shared/2c13q96h.js +18 -0
  68. package/dist/shared/{b4v57v3x.js → 2d3xq4ps.js} +2 -2
  69. package/dist/shared/{1nw1f3vs.js → 2shdbn8q.js} +7 -7
  70. package/dist/shared/3v7t1yrv.js +208 -0
  71. package/dist/shared/{x3jc53kg.js → 5e3tf63j.js} +2 -2
  72. package/dist/shared/5fe3kbsh.js +10 -0
  73. package/dist/shared/5v3xf80k.js +37 -0
  74. package/dist/shared/{c58secgj.js → 63qtkrca.js} +38 -4
  75. package/dist/shared/{2z7wv5tj.js → 67txcrcw.js} +55 -34
  76. package/dist/shared/79dt02vc.js +12 -0
  77. package/dist/shared/{8x72s86k.js → 7k9grvf6.js} +10 -4
  78. package/dist/shared/7kms6fvj.js +20 -0
  79. package/dist/shared/7mnme5tn.js +8 -0
  80. package/dist/shared/7n7ddwt4.js +6 -0
  81. package/dist/shared/{5j36z8dn.js → 81ebdx9p.js} +39 -70
  82. package/dist/shared/{knmes2kh.js → 8skf0cam.js} +1 -1
  83. package/dist/shared/9a4ae4p8.js +31 -0
  84. package/dist/shared/9y3mmmh1.js +436 -0
  85. package/dist/shared/ab9gmbwy.js +213 -0
  86. package/dist/shared/{f0f1n281.js → ax7qv55k.js} +2 -2
  87. package/dist/shared/{g90m9b0g.js → aytqh5y2.js} +6 -5
  88. package/dist/shared/{vjpnzwjz.js → b5pftnn2.js} +1 -1
  89. package/dist/shared/{ag4c7516.js → b76b8d95.js} +2 -2
  90. package/dist/shared/{vmfkhszw.js → bg3rym3g.js} +33 -26
  91. package/dist/shared/{mb2ycs1p.js → bm22fvzr.js} +15 -15
  92. package/dist/shared/{q3j1tq7a.js → bz84tkzm.js} +148 -23
  93. package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
  94. package/dist/shared/cn957f8d.js +179 -0
  95. package/dist/shared/{gwn6v667.js → cnkky55j.js} +25 -14
  96. package/dist/shared/{ys0xzyaj.js → dkxgzaqd.js} +224 -19
  97. package/dist/shared/dzj09cye.js +10 -0
  98. package/dist/shared/exn3sd90.js +359 -0
  99. package/dist/shared/g6evj1j3.js +66 -0
  100. package/dist/shared/ga9j92qj.js +25 -0
  101. package/dist/shared/{t3g0k88x.js → gs74dbj5.js} +16 -12
  102. package/dist/shared/gzaveazc.js +285 -0
  103. package/dist/shared/{2jd1sn0e.js → hyh73qk6.js} +1 -1
  104. package/dist/shared/{r1fdd0f6.js → je4axnm8.js} +5 -2
  105. package/dist/shared/{1f0xa3cb.js → jvd0mqag.js} +3 -3
  106. package/dist/shared/jznfax0y.js +155 -0
  107. package/dist/shared/{cgbamx3e.js → kb2sdhfb.js} +7 -4
  108. package/dist/shared/{wt5rzv1h.js → kr0jzbw2.js} +5 -5
  109. package/dist/shared/{p6bjzq9q.js → ktz42yez.js} +12 -4
  110. package/dist/shared/{p248q79y.js → m6p12kbr.js} +2 -2
  111. package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
  112. package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
  113. package/dist/shared/{929h19xp.js → mtaszv5a.js} +40 -10
  114. package/dist/shared/{b3awxn7h.js → n816peh1.js} +1 -1
  115. package/dist/shared/nbw1z4yd.js +18 -0
  116. package/dist/shared/{nx9hh281.js → p6qc5gcp.js} +12 -11
  117. package/dist/shared/{pjr6xrm5.js → pbp1ss85.js} +20 -17
  118. package/dist/shared/pt94kz7f.js +6 -0
  119. package/dist/shared/q5c6ngn3.js +13 -0
  120. package/dist/shared/{xq0mvhts.js → rs73fca9.js} +4 -4
  121. package/dist/shared/{r11n8grd.js → sfz1ksn6.js} +7 -4
  122. package/dist/shared/{wynzeggs.js → svncdeh5.js} +6 -6
  123. package/dist/shared/{j60w0dvr.js → tbrvgw6z.js} +57 -38
  124. package/dist/shared/te5as7z7.js +622 -0
  125. package/dist/shared/{ttmg09vd.js → tsvww22q.js} +1 -1
  126. package/dist/shared/{y2t3jktd.js → ttsqgp4p.js} +19 -12
  127. package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
  128. package/dist/shared/{sbdme3vy.js → vb6qfyve.js} +60 -10
  129. package/dist/shared/{5d8t84hg.js → vczs8gd4.js} +14 -14
  130. package/dist/shared/{5yv4k6a6.js → vqrjpcqn.js} +144 -2
  131. package/dist/shared/{3fqwmr09.js → w72kgg4q.js} +4 -4
  132. package/dist/shared/{1z04fa85.js → w79hsckn.js} +12 -57
  133. package/dist/shared/{09p049xa.js → wa07eas9.js} +42 -14
  134. package/dist/shared/{32cnm7kn.js → x933k9a3.js} +74 -38
  135. package/dist/shared/{n076ydsc.js → xhfsfkgk.js} +62 -28
  136. package/dist/shared/xjk7hnn5.js +272 -0
  137. package/dist/shared/{hazqqecq.js → xnxsed62.js} +50 -21
  138. package/dist/shared/y6njgyda.js +249 -0
  139. package/dist/shared/{8etn7d8w.js → z7s6fpxv.js} +1 -1
  140. package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
  141. package/dist/shared/zm0ptry0.js +40 -0
  142. package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
  143. package/dist/shared/zp9fmend.js +145 -0
  144. package/dist/tooling/cli.js +11 -11
  145. package/dist/tooling/migrate/engine.d.ts +3 -2
  146. package/dist/tooling/migrate/index.js +7 -7
  147. package/dist/tooling/testing/index.js +1 -1
  148. package/package.json +4 -2
  149. package/dist/shared/3qnhc7w5.js +0 -38
  150. package/dist/shared/7m88x3e9.js +0 -45
  151. package/dist/shared/8dqhth8c.js +0 -12
  152. package/dist/shared/d5azex6s.js +0 -6
  153. package/dist/shared/j3rkk835.js +0 -99
  154. package/dist/shared/k68eedmy.js +0 -85
  155. package/dist/shared/venqrjna.js +0 -216
  156. package/dist/shared/wxr8cwns.js +0 -6
  157. package/dist/shared/zm0mafk4.js +0 -92
@@ -0,0 +1,359 @@
1
+ import {
2
+ OkmError2,
3
+ catalogError2,
4
+ throwNamed2
5
+ } from "./52szzakm.js";
6
+
7
+ // src/dialects/pg/morph.ts
8
+ var refuseTo = (planner, schema, relation, child, sink, parent, alias, depth) => {
9
+ const morph = relation.morph;
10
+ const typeField = morph?.typeField ?? "type";
11
+ const idField = morph?.idField ?? "id";
12
+ throw new OkmError2("OKM1120", `Relation ${relation.name} is a morph. Filter ${typeField} and ${idField}, or include it. has, none, and every are not available on it.`);
13
+ };
14
+ function resolveMorph(scope, name, targets) {
15
+ const label = `${scope.owner}.${scope.name}`;
16
+ const owner = described(scope, scope.owner, label);
17
+ const typeField = `${name}Type`;
18
+ const idField = `${name}Id`;
19
+ const typeColumn = requireColumn(owner, typeField, label);
20
+ const idColumn = requireColumn(owner, idField, label);
21
+ if (typeColumn.nullable !== idColumn.nullable) {
22
+ catalogError2("OKM1021", `Relation ${label} columns ${owner.tsName}.${typeColumn.field} and ${owner.tsName}.${idColumn.field} must both be nullable, or neither.`);
23
+ }
24
+ if (!isTextType(typeColumn.dataType)) {
25
+ catalogError2("OKM1022", `Relation ${label} type column ${owner.tsName}.${typeColumn.field} is ${typeColumn.dataType}. Accepted type: text.`);
26
+ }
27
+ const seen = new Set;
28
+ const resolved = [];
29
+ for (const targetName of targets) {
30
+ if (seen.has(targetName)) {
31
+ catalogError2("OKM1023", `Relation ${label} lists ${targetName} twice.`);
32
+ }
33
+ seen.add(targetName);
34
+ if (!scope.tables.includes(targetName)) {
35
+ throwNamed2("OKM1020", targetName, scope.tables, `Relation ${label} names ${targetName}, which is not in the schema. Accepted names: ${scope.tables.join(", ")}.`);
36
+ }
37
+ const target = described(scope, targetName, label);
38
+ const key = requireKey(target, label, scope.scopeFields);
39
+ if (idColumn.dataType !== key.dataType) {
40
+ catalogError2("OKM1022", `Relation ${label} id column ${owner.tsName}.${idColumn.field} is ${idColumn.dataType} and ${target.tsName}.${key.field} is ${key.dataType}. Accepted type: ${key.dataType}.`);
41
+ }
42
+ const limit = textLimit(typeColumn.dataType);
43
+ if (limit !== undefined && targetName.length > limit) {
44
+ catalogError2("OKM1022", `Relation ${label} type column ${owner.tsName}.${typeColumn.field} is ${typeColumn.dataType} and ${target.tsName} does not fit. Accepted type: text.`);
45
+ }
46
+ resolved.push({
47
+ type: target.tsName,
48
+ table: target.tsName,
49
+ sql: target.sqlName,
50
+ keySql: key.sql
51
+ });
52
+ }
53
+ const first = resolved[0];
54
+ if (first === undefined) {
55
+ catalogError2("OKM1020", `Relation ${label} needs a target table.`);
56
+ }
57
+ const morph = {
58
+ direction: "to",
59
+ name,
60
+ typeField,
61
+ idField,
62
+ typeSql: typeColumn.sqlName,
63
+ idSql: idColumn.sqlName,
64
+ targets: resolved
65
+ };
66
+ return {
67
+ name: scope.name,
68
+ kind: "one",
69
+ table: first.table,
70
+ local: [idColumn.sqlName],
71
+ remote: [first.keySql],
72
+ morph,
73
+ through: {
74
+ table: first.table,
75
+ local: [idColumn.sqlName],
76
+ remote: [first.keySql],
77
+ emit: refuseTo
78
+ }
79
+ };
80
+ }
81
+ function resolveMorphMany(scope, table, name) {
82
+ const label = `${scope.owner}.${scope.name}`;
83
+ if (!scope.tables.includes(table)) {
84
+ throwNamed2("OKM1020", table, scope.tables, `Relation ${label} names ${table}, which is not in the schema. Accepted names: ${scope.tables.join(", ")}.`);
85
+ }
86
+ const owner = described(scope, table, label);
87
+ const here = described(scope, scope.owner, label);
88
+ const targets = declaredTargets(owner.relationOptions, name);
89
+ if (targets === undefined) {
90
+ catalogError2("OKM1021", `Relation ${label} needs morph("${name}", [...]) on ${owner.tsName}. ${owner.tsName} has no morph named ${name}.`);
91
+ }
92
+ if (!targets.includes(scope.owner)) {
93
+ catalogError2("OKM1020", `Relation ${label} is not a target of ${owner.tsName}.${name}. Accepted tables: ${targets.join(", ")}.`);
94
+ }
95
+ const typeField = `${name}Type`;
96
+ const idField = `${name}Id`;
97
+ const typeColumn = requireColumn(owner, typeField, label);
98
+ const idColumn = requireColumn(owner, idField, label);
99
+ const key = requireKey(here, label, scope.scopeFields);
100
+ if (idColumn.dataType !== key.dataType) {
101
+ catalogError2("OKM1022", `Relation ${label} id column ${owner.tsName}.${idColumn.field} is ${idColumn.dataType} and ${here.tsName}.${key.field} is ${key.dataType}. Accepted type: ${key.dataType}.`);
102
+ }
103
+ const morph = {
104
+ direction: "many",
105
+ name,
106
+ typeField,
107
+ idField,
108
+ typeSql: typeColumn.sqlName,
109
+ idSql: idColumn.sqlName,
110
+ typeValue: here.tsName,
111
+ targets: [
112
+ {
113
+ type: here.tsName,
114
+ table: here.tsName,
115
+ sql: here.sqlName,
116
+ keySql: key.sql
117
+ }
118
+ ]
119
+ };
120
+ return {
121
+ name: scope.name,
122
+ kind: "many",
123
+ table: owner.tsName,
124
+ local: [key.sql],
125
+ remote: [idColumn.sqlName],
126
+ morph,
127
+ through: {
128
+ table: owner.tsName,
129
+ local: [idColumn.sqlName],
130
+ remote: [key.sql],
131
+ emit: morphManyEmit(here.tsName)
132
+ }
133
+ };
134
+ }
135
+ function morphManyEmit(typeValue) {
136
+ return (planner, schema, relation, child, sink, parent, alias) => {
137
+ const pair = relation.morph;
138
+ const local = relation.local[0];
139
+ if (pair === undefined || local === undefined) {
140
+ throw new OkmError2("OKM1120", `Relation ${relation.name} is not a morph many.`);
141
+ }
142
+ const { quote } = planner;
143
+ sink.text(quote(child.model.sql));
144
+ sink.text(" ");
145
+ sink.text(alias);
146
+ sink.text(" where ");
147
+ sink.text(alias);
148
+ sink.text(".");
149
+ sink.text(quote(pair.typeSql));
150
+ sink.text(" = ");
151
+ sink.param(typeValue);
152
+ sink.text("::text");
153
+ sink.text(" and ");
154
+ sink.text(alias);
155
+ sink.text(".");
156
+ sink.text(quote(pair.idSql));
157
+ sink.text(" = ");
158
+ sink.text(parent);
159
+ sink.text(".");
160
+ sink.text(quote(local));
161
+ };
162
+ }
163
+ function described(scope, table, label) {
164
+ const found = scope.describe?.(table);
165
+ if (!isDescribed(found)) {
166
+ catalogError2("OKM1020", `Relation ${label} names ${table}, which is not in the schema.`);
167
+ }
168
+ return found;
169
+ }
170
+ function isDescribed(value) {
171
+ if (typeof value !== "object" || value === null)
172
+ return false;
173
+ if (!("tsName" in value) || typeof value.tsName !== "string")
174
+ return false;
175
+ if (!("sqlName" in value) || typeof value.sqlName !== "string")
176
+ return false;
177
+ if (!("primary" in value) || !Array.isArray(value.primary))
178
+ return false;
179
+ if (!("byField" in value) || !(value.byField instanceof Map))
180
+ return false;
181
+ if (!("bySql" in value) || !(value.bySql instanceof Map))
182
+ return false;
183
+ return "relationOptions" in value;
184
+ }
185
+ function requireColumn(table, field, label) {
186
+ const column = table.byField.get(field);
187
+ if (column === undefined) {
188
+ catalogError2("OKM1021", `Relation ${label} needs column ${field} on ${table.tsName}.`);
189
+ }
190
+ return column;
191
+ }
192
+ function requireKey(table, label, scopeFields) {
193
+ const skip = scopeFields ?? [];
194
+ const keys = [];
195
+ for (const sql of table.primary) {
196
+ const column = table.bySql.get(sql);
197
+ if (column === undefined || skip.includes(column.field))
198
+ continue;
199
+ keys.push({ field: column.field, sql, dataType: column.dataType });
200
+ }
201
+ const only = keys.length === 1 ? keys[0] : undefined;
202
+ if (only !== undefined)
203
+ return only;
204
+ const names = keys.map((key) => key.field);
205
+ catalogError2("OKM1021", `Relation ${label} cannot use ${table.tsName} as a target. Its primary key is ${names.length === 0 ? "(none)" : names.join(", ")}. A morph id matches one column.`);
206
+ }
207
+ function declaredTargets(options, name) {
208
+ if (typeof options !== "object" || options === null)
209
+ return;
210
+ for (const value of Object.values(options)) {
211
+ if (typeof value !== "object" || value === null || !("morph" in value))
212
+ continue;
213
+ const morph = value.morph;
214
+ if (morph === undefined || morph.name !== name || !Array.isArray(morph.targets))
215
+ continue;
216
+ const names = [];
217
+ for (const target of morph.targets) {
218
+ if (typeof target === "string")
219
+ names.push(target);
220
+ }
221
+ return names;
222
+ }
223
+ return;
224
+ }
225
+ function assertMorphTo(name, type, id) {
226
+ if (name === null || type === null || typeof id !== "string" || id.length === 0) {
227
+ throw new OkmError2("OKM1120", "morphTo() needs a morph name, a target table, and that table's id.");
228
+ }
229
+ if (typeof name !== "string" || name.length === 0 || typeof type !== "string" || type.length === 0) {
230
+ throw new OkmError2("OKM1020", "morphTo() needs a morph name and a target table.");
231
+ }
232
+ }
233
+ function isTextType(dataType) {
234
+ return dataType === "text" || dataType === "citext" || dataType.startsWith("varchar(") || dataType.startsWith("character varying(") || dataType.startsWith("char(") || dataType.startsWith("character(");
235
+ }
236
+ function textLimit(dataType) {
237
+ const match = /^(?:varchar|character varying|char|character)\((\d+)\)$/.exec(dataType);
238
+ if (match?.[1] === undefined)
239
+ return;
240
+ return Number(match[1]);
241
+ }
242
+
243
+ // src/dialects/pg/through.ts
244
+ var emit = (planner, schema, relation, child, sink, parent, alias, depth) => {
245
+ const through = relation.through;
246
+ const join = through === undefined ? undefined : planner.indexes(schema).get(through.table);
247
+ if (through === undefined || join === undefined) {
248
+ return catalogError2("OKM1020", `Relation ${relation.name} names a join table that is not in the schema.`);
249
+ }
250
+ const { quote } = planner;
251
+ const joinAlias = `j${alias}`;
252
+ sink.mark(`via:${through.table}`);
253
+ sink.text(`${quote(join.model.sql)} ${joinAlias} join ${quote(child.model.sql)} ${alias} on `);
254
+ for (let index = 0;index < through.local.length; index += 1) {
255
+ const local = through.local[index];
256
+ const remote = through.remote[index];
257
+ if (local === undefined || remote === undefined)
258
+ continue;
259
+ if (index > 0)
260
+ sink.text(" and ");
261
+ sink.text(`${alias}.${quote(remote)} = ${joinAlias}.${quote(local)}`);
262
+ }
263
+ sink.text(" where ");
264
+ planner.join(sink, parent, joinAlias, relation);
265
+ planner.where(schema, join, undefined, sink, joinAlias, depth + 1, true);
266
+ };
267
+ function resolveThrough(scope, table, through, from, to) {
268
+ for (const name of [table, through]) {
269
+ if (!scope.tables.includes(name)) {
270
+ throwNamed2("OKM1020", name, scope.tables, `Relation ${scope.owner}.${scope.name} names ${name}, which is not in the schema. Accepted names: ${scope.tables.join(", ")}.`);
271
+ }
272
+ }
273
+ const toOwner = pick(scope, through, scope.owner, from, `${scope.owner}.${scope.name}`, "from");
274
+ const toTable = pick(scope, through, table, to, `${scope.owner}.${scope.name}`, "to");
275
+ if (toOwner === toTable) {
276
+ catalogError2("OKM1021", `Relation ${scope.owner}.${scope.name} uses ${toOwner.fromField} on ${through} for both ends. Pass from and to.`);
277
+ }
278
+ return {
279
+ name: scope.name,
280
+ kind: "many",
281
+ table,
282
+ local: toOwner.remote,
283
+ remote: toOwner.local,
284
+ through: { table: through, local: toTable.local, remote: toTable.remote, emit }
285
+ };
286
+ }
287
+ function pick(scope, through, target, field, label, end) {
288
+ const matches = scope.edges.filter((edge) => edge.fromTable === through && edge.toTable === target && (field === undefined || edge.fromField === field));
289
+ const [only] = matches;
290
+ if (matches.length === 1 && only !== undefined)
291
+ return only;
292
+ const fields = matches.map((edge) => edge.fromField).sort();
293
+ catalogError2("OKM1021", `Relation ${label} through ${through} is ambiguous at ${end}. Accepted columns: ${fields.length === 0 ? "(none)" : fields.join(", ")}.`);
294
+ }
295
+
296
+ // src/dialects/pg/relations.ts
297
+ function one2(table, field) {
298
+ return { kind: "one", table, field };
299
+ }
300
+ function many2(table, field) {
301
+ return { kind: "many", table, field };
302
+ }
303
+ function isRelationCall(value) {
304
+ if (typeof value !== "object" || value === null)
305
+ return false;
306
+ if (!("kind" in value) || !("table" in value))
307
+ return false;
308
+ const kind = value.kind;
309
+ return (kind === "one" || kind === "many") && typeof value.table === "string";
310
+ }
311
+ function manyThrough2(table, options) {
312
+ const { through, from, to } = options;
313
+ return {
314
+ kind: "many",
315
+ table,
316
+ field: undefined,
317
+ through,
318
+ resolve: (scope) => resolveThrough(scope, table, through, from, to)
319
+ };
320
+ }
321
+ function morph2(name, targets) {
322
+ if (name.length === 0)
323
+ throw new OkmError2("OKM1020", "morph() needs a name.");
324
+ if (targets.length === 0)
325
+ throw new OkmError2("OKM1020", "morph() needs a target table.");
326
+ for (const target of targets) {
327
+ if (typeof target !== "string" || target.length === 0) {
328
+ throw new OkmError2("OKM1020", "morph() targets must be table names.");
329
+ }
330
+ }
331
+ const list = targets;
332
+ return {
333
+ kind: "one",
334
+ table: targets[0],
335
+ field: undefined,
336
+ morph: { name, targets, typeField: `${name}Type` },
337
+ resolve: (scope) => resolveMorph(scope, name, list)
338
+ };
339
+ }
340
+ function morphMany2(table, name) {
341
+ if (table.length === 0 || name.length === 0) {
342
+ throw new OkmError2("OKM1020", "morphMany() needs a table and a morph name.");
343
+ }
344
+ return {
345
+ kind: "many",
346
+ table,
347
+ field: undefined,
348
+ resolve: (scope) => resolveMorphMany(scope, table, name)
349
+ };
350
+ }
351
+ function morphTo2(name, type, id) {
352
+ assertMorphTo(name, type, id);
353
+ const row = {};
354
+ row[`${name}Type`] = type;
355
+ row[`${name}Id`] = id;
356
+ return row;
357
+ }
358
+
359
+ export { one2, many2, isRelationCall, manyThrough2, morph2, morphMany2, morphTo2 };
@@ -0,0 +1,66 @@
1
+ import {
2
+ mapFailure
3
+ } from "./kb2sdhfb.js";
4
+
5
+ // src/adapters/pg/pglite-wire.ts
6
+ var OIDS = [
7
+ 16,
8
+ 17,
9
+ 20,
10
+ 21,
11
+ 23,
12
+ 25,
13
+ 114,
14
+ 700,
15
+ 701,
16
+ 1043,
17
+ 1082,
18
+ 1114,
19
+ 1184,
20
+ 1700,
21
+ 2950,
22
+ 3802,
23
+ 1000,
24
+ 1005,
25
+ 1007,
26
+ 1009,
27
+ 1016,
28
+ 1115,
29
+ 1182,
30
+ 1185,
31
+ 1231,
32
+ 199,
33
+ 3807
34
+ ];
35
+ function identity(value) {
36
+ return value;
37
+ }
38
+ function serialize(value) {
39
+ if (typeof value === "number" || typeof value === "bigint")
40
+ return String(value);
41
+ if (typeof value === "boolean")
42
+ return value ? "t" : "f";
43
+ return value;
44
+ }
45
+ var parsers = {};
46
+ var serializers = {};
47
+ for (const oid of OIDS) {
48
+ parsers[oid] = identity;
49
+ serializers[oid] = serialize;
50
+ }
51
+ function fail(error) {
52
+ return mapFailure(protocol(error));
53
+ }
54
+ function protocol(error) {
55
+ if (typeof error !== "object" || error === null || !("code" in error))
56
+ return error;
57
+ if (error.code !== "08P01")
58
+ return error;
59
+ const message = error instanceof Error ? error.message : "";
60
+ return new Error(message.length > 0 ? message : "protocol error");
61
+ }
62
+ export {
63
+ fail,
64
+ parsers,
65
+ serializers
66
+ };
@@ -0,0 +1,25 @@
1
+ // src/dialects/pg/floor.ts
2
+ var POSTGRES_FLOOR = 15;
3
+ var UUIDV7_POSTGRES = 18;
4
+ function isPostgresMajor(value) {
5
+ return typeof value === "number" && (value | 0) === value && value >= 15 && value <= 18;
6
+ }
7
+ var FLOOR_TEXT = /^>=(\d+)$/;
8
+ function parsePostgresFloor(postgres) {
9
+ return Number(FLOOR_TEXT.exec(postgres ?? "")?.[1]);
10
+ }
11
+ function formatPostgresFloor(major) {
12
+ return `>=${major}`;
13
+ }
14
+ function minPostgresDefinition() {
15
+ return "minPostgres: 15-18.";
16
+ }
17
+ function uuidv7NeedsPostgres() {
18
+ const need = UUIDV7_POSTGRES;
19
+ return `uuidv7() needs PostgreSQL ${need} or higher. minPostgres: ${need}.`;
20
+ }
21
+ function serverNeedsPostgres(server, need) {
22
+ return `The server is PostgreSQL ${server}. This schema needs PostgreSQL ${need} or higher (minPostgres: ${need}).`;
23
+ }
24
+
25
+ export { POSTGRES_FLOOR, UUIDV7_POSTGRES, isPostgresMajor, parsePostgresFloor, formatPostgresFloor, minPostgresDefinition, uuidv7NeedsPostgres, serverNeedsPostgres };
@@ -14,7 +14,7 @@ import {
14
14
  } from "./qq3899ht.js";
15
15
  import {
16
16
  open2
17
- } from "./wkme6tep.js";
17
+ } from "./14vx95q4.js";
18
18
  import {
19
19
  sqlStatements,
20
20
  transactionControl,
@@ -35,7 +35,7 @@ import {
35
35
  assertTargetAlias,
36
36
  listTargets,
37
37
  selectTarget
38
- } from "./ttmg09vd.js";
38
+ } from "./tsvww22q.js";
39
39
  import {
40
40
  contributedFields
41
41
  } from "./n0dgs0pb.js";
@@ -47,6 +47,10 @@ import {
47
47
  tableOwner,
48
48
  stampOwnership
49
49
  } from "./xqve9598.js";
50
+ import {
51
+ POSTGRES_FLOOR,
52
+ uuidv7NeedsPostgres
53
+ } from "./ga9j92qj.js";
50
54
  import {
51
55
  catalog,
52
56
  isDomain
@@ -193,8 +197,8 @@ var ERROR_DOCS = [
193
197
  {
194
198
  code: "OKM1110",
195
199
  title: "Engine version",
196
- summary: "The feature needs a newer engine than schema({ requires }) allows.",
197
- fix: "Raise requires, or stop using the feature. The error names both versions."
200
+ summary: "A feature needs a newer PostgreSQL than minPostgres allows. The message names the feature, the version it needs, and this schema's minimum.",
201
+ fix: "Raise minPostgres, or stop using the feature. The error names both versions."
198
202
  },
199
203
  {
200
204
  code: "OKM1111",
@@ -230,7 +234,7 @@ var ERROR_DOCS = [
230
234
  code: "OKM1124",
231
235
  title: "Operator mismatch",
232
236
  summary: "An operator does not apply to the column type.",
233
- fix: "Use an operator the error lists for that column type. Text search needs a tsvector column."
237
+ fix: "Use an operator the error lists for that column type. Search needs a column built for search, not a plain text column."
234
238
  },
235
239
  {
236
240
  code: "OKM1130",
@@ -583,14 +587,14 @@ var ERROR_DOCS = [
583
587
  {
584
588
  code: "OKM1802",
585
589
  title: "Server version",
586
- summary: "The connected server does not satisfy schema({ requires }).",
587
- fix: "Upgrade the server, or lower requires to a version the server meets."
590
+ summary: "The connected server is older than this schema's minPostgres.",
591
+ fix: "Upgrade the server, or lower minPostgres to a major the server meets."
588
592
  },
589
593
  {
590
594
  code: "OKM1803",
591
595
  title: "Postgres floor",
592
- summary: "The connected server is older than PostgreSQL 15, and the schema does not set requires to that older major.",
593
- fix: "Upgrade the server to PostgreSQL 15 or newer, or set schema({ requires }) to the older major on purpose."
596
+ summary: `The connected server is older than PostgreSQL ${String(POSTGRES_FLOOR)}.`,
597
+ fix: `Upgrade the server to PostgreSQL ${String(POSTGRES_FLOOR)} or higher.`
594
598
  },
595
599
  {
596
600
  code: "OKM1810",
@@ -607,8 +611,8 @@ var ERROR_DOCS = [
607
611
  {
608
612
  code: "OKM1812",
609
613
  title: "Feature version",
610
- summary: "A feature needs a newer Postgres or extension version than the one declared or connected.",
611
- fix: 'Raise the declared version, or avoid the feature. uuidv7() below 18 can use t.id({ default: "uuidv4" }), defaults.id set to "uuidv4", or a client generator. Core features are never gated on an extension.'
614
+ summary: "A feature needs a newer PostgreSQL than minPostgres, or an extension version the server does not have. The message names the feature and the version.",
615
+ fix: `Raise minPostgres, or avoid the feature. ${uuidv7NeedsPostgres()} An extension pin names the version to install. Core features are never gated on an extension.`
612
616
  },
613
617
  {
614
618
  code: "OKM1813",
@@ -2382,7 +2386,7 @@ async function checkProject(cwd, flags) {
2382
2386
  const target = selectTarget(opened.config, named);
2383
2387
  assertTargetPolicy(target, "check", flags?.allowProtected ?? false);
2384
2388
  assertTargetPolicy(target, "drift", flags?.allowProtected ?? false);
2385
- const { assertAuthorDrift } = await import("./1f0xa3cb.js");
2389
+ const { assertAuthorDrift } = await import("./jvd0mqag.js");
2386
2390
  const allowPooler = flags?.allowPooler === true || opened.config.allowPooler === true;
2387
2391
  await assertAuthorDrift(target.url, opened.built.catalog, opened.config.roles, allowPooler);
2388
2392
  return findings;