okmodel 0.0.0 → 0.1.1

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 (147) hide show
  1. package/README.md +246 -1
  2. package/dist/adapters/capabilities.d.ts +62 -0
  3. package/dist/adapters/error.d.ts +91 -0
  4. package/dist/adapters/failure.d.ts +39 -0
  5. package/dist/adapters/pg/batch.d.ts +36 -0
  6. package/dist/adapters/pg/call.d.ts +59 -0
  7. package/dist/adapters/pg/pglite.d.ts +21 -0
  8. package/dist/adapters/pg/postgres-extra.d.ts +43 -0
  9. package/dist/adapters/pg/postgresjs.d.ts +95 -0
  10. package/dist/adapters/pg/result.d.ts +30 -0
  11. package/dist/contracts/catalog/build.d.ts +18 -0
  12. package/dist/contracts/catalog/document.d.ts +79 -0
  13. package/dist/contracts/catalog/enum.d.ts +35 -0
  14. package/dist/contracts/catalog/identifier.d.ts +71 -0
  15. package/dist/contracts/catalog/identity.d.ts +98 -0
  16. package/dist/contracts/catalog/index.d.ts +11 -0
  17. package/dist/contracts/catalog/json.d.ts +17 -0
  18. package/dist/contracts/catalog/object.d.ts +142 -0
  19. package/dist/contracts/catalog/order.d.ts +43 -0
  20. package/dist/contracts/catalog/rewrite.d.ts +18 -0
  21. package/dist/contracts/catalog/types.d.ts +292 -0
  22. package/dist/contracts/catalog/words.d.ts +13 -0
  23. package/dist/contracts/connection.d.ts +33 -0
  24. package/dist/contracts/driver.d.ts +163 -0
  25. package/dist/contracts/error.d.ts +298 -0
  26. package/dist/contracts/index.d.ts +11 -0
  27. package/dist/contracts/index.js +16 -0
  28. package/dist/contracts/internal.d.ts +15 -0
  29. package/dist/contracts/internal.js +68 -0
  30. package/dist/contracts/nearest.d.ts +15 -0
  31. package/dist/contracts/rows.d.ts +84 -0
  32. package/dist/contracts/sha256.d.ts +14 -0
  33. package/dist/contracts/utf8.d.ts +33 -0
  34. package/dist/dialects/pg/array-literal.d.ts +25 -0
  35. package/dist/dialects/pg/bool.d.ts +46 -0
  36. package/dist/dialects/pg/column.d.ts +386 -0
  37. package/dist/dialects/pg/compile.d.ts +81 -0
  38. package/dist/dialects/pg/custom.d.ts +21 -0
  39. package/dist/dialects/pg/ddl.d.ts +70 -0
  40. package/dist/dialects/pg/decimal.d.ts +62 -0
  41. package/dist/dialects/pg/declarations.d.ts +34 -0
  42. package/dist/dialects/pg/emit.d.ts +18 -0
  43. package/dist/dialects/pg/enum.d.ts +30 -0
  44. package/dist/dialects/pg/errors.d.ts +30 -0
  45. package/dist/dialects/pg/finite.d.ts +15 -0
  46. package/dist/dialects/pg/geometry.d.ts +55 -0
  47. package/dist/dialects/pg/index.d.ts +45 -0
  48. package/dist/dialects/pg/index.js +1821 -0
  49. package/dist/dialects/pg/integer.d.ts +96 -0
  50. package/dist/dialects/pg/introspect.d.ts +43 -0
  51. package/dist/dialects/pg/json.d.ts +43 -0
  52. package/dist/dialects/pg/keys.d.ts +32 -0
  53. package/dist/dialects/pg/misuse.d.ts +31 -0
  54. package/dist/dialects/pg/model.d.ts +71 -0
  55. package/dist/dialects/pg/namespace.d.ts +63 -0
  56. package/dist/dialects/pg/network.d.ts +28 -0
  57. package/dist/dialects/pg/operators.d.ts +71 -0
  58. package/dist/dialects/pg/ops/between.d.ts +10 -0
  59. package/dist/dialects/pg/ops/contains.d.ts +8 -0
  60. package/dist/dialects/pg/ops/endsWith.d.ts +8 -0
  61. package/dist/dialects/pg/ops/eq.d.ts +9 -0
  62. package/dist/dialects/pg/ops/every.d.ts +9 -0
  63. package/dist/dialects/pg/ops/gt.d.ts +9 -0
  64. package/dist/dialects/pg/ops/gte.d.ts +9 -0
  65. package/dist/dialects/pg/ops/has.d.ts +9 -0
  66. package/dist/dialects/pg/ops/ilike.d.ts +8 -0
  67. package/dist/dialects/pg/ops/inList.d.ts +9 -0
  68. package/dist/dialects/pg/ops/inc.d.ts +13 -0
  69. package/dist/dialects/pg/ops/like.d.ts +8 -0
  70. package/dist/dialects/pg/ops/lt.d.ts +9 -0
  71. package/dist/dialects/pg/ops/lte.d.ts +9 -0
  72. package/dist/dialects/pg/ops/none.d.ts +9 -0
  73. package/dist/dialects/pg/ops/not.d.ts +9 -0
  74. package/dist/dialects/pg/ops/notIn.d.ts +9 -0
  75. package/dist/dialects/pg/ops/or.d.ts +9 -0
  76. package/dist/dialects/pg/ops/startsWith.d.ts +8 -0
  77. package/dist/dialects/pg/quote.d.ts +24 -0
  78. package/dist/dialects/pg/range.d.ts +50 -0
  79. package/dist/dialects/pg/relations.d.ts +45 -0
  80. package/dist/dialects/pg/schema.d.ts +77 -0
  81. package/dist/dialects/pg/search.d.ts +23 -0
  82. package/dist/dialects/pg/table.d.ts +201 -0
  83. package/dist/dialects/pg/temporal.d.ts +211 -0
  84. package/dist/dialects/pg/text.d.ts +44 -0
  85. package/dist/dialects/pg/time.d.ts +46 -0
  86. package/dist/okm.js +2 -0
  87. package/dist/okmodel.js +2 -0
  88. package/dist/runtime/client.d.ts +47 -0
  89. package/dist/runtime/conflict.d.ts +38 -0
  90. package/dist/runtime/drift-detail.d.ts +32 -0
  91. package/dist/runtime/drift.d.ts +29 -0
  92. package/dist/runtime/include.d.ts +15 -0
  93. package/dist/runtime/pg/pglite.d.ts +25 -0
  94. package/dist/runtime/pg/pglite.js +48 -0
  95. package/dist/runtime/pg/postgresjs.d.ts +29 -0
  96. package/dist/runtime/pg/postgresjs.js +62 -0
  97. package/dist/runtime/plan.d.ts +167 -0
  98. package/dist/runtime/tx.d.ts +29 -0
  99. package/dist/runtime/types.d.ts +385 -0
  100. package/dist/runtime/write.d.ts +48 -0
  101. package/dist/shared/05w44d8g.js +1524 -0
  102. package/dist/shared/523ft3e8.js +171 -0
  103. package/dist/shared/8b04d28c.js +14 -0
  104. package/dist/shared/cn0n68ft.js +16 -0
  105. package/dist/shared/dkn3y60a.js +374 -0
  106. package/dist/shared/dynq16vb.js +81 -0
  107. package/dist/shared/fgqgsb5z.js +281 -0
  108. package/dist/shared/g5fhqmwe.js +188 -0
  109. package/dist/shared/gk7cs7sp.js +566 -0
  110. package/dist/shared/hadrfb9h.js +398 -0
  111. package/dist/shared/hd293j9g.js +98 -0
  112. package/dist/shared/j5cn2963.js +701 -0
  113. package/dist/shared/jjb7yht9.js +37 -0
  114. package/dist/shared/kprcwaha.js +30 -0
  115. package/dist/shared/m3ypagh5.js +347 -0
  116. package/dist/shared/mkjmqjv4.js +456 -0
  117. package/dist/shared/mtkwv8wx.js +18 -0
  118. package/dist/shared/ngk8gj61.js +40 -0
  119. package/dist/shared/p0cbr3g2.js +79 -0
  120. package/dist/shared/qk3hxfja.js +83 -0
  121. package/dist/shared/rgs0st28.js +1066 -0
  122. package/dist/shared/w8samvk1.js +18 -0
  123. package/dist/shared/x5x59srr.js +566 -0
  124. package/dist/shared/xqbhg6cn.js +119 -0
  125. package/dist/shared/xy79j5hq.js +177 -0
  126. package/dist/shared/y9m15dfv.js +888 -0
  127. package/dist/shared/ycwz42az.js +412 -0
  128. package/dist/shared/yd1kzwn2.js +148 -0
  129. package/dist/shared/zhc5vmgf.js +257 -0
  130. package/dist/tooling/cli.d.ts +1 -0
  131. package/dist/tooling/cli.js +193 -0
  132. package/dist/tooling/errors/registry.d.ts +33 -0
  133. package/dist/tooling/migrate/apply.d.ts +86 -0
  134. package/dist/tooling/migrate/commands.d.ts +21 -0
  135. package/dist/tooling/migrate/config.d.ts +48 -0
  136. package/dist/tooling/migrate/dev.d.ts +16 -0
  137. package/dist/tooling/migrate/equal.d.ts +15 -0
  138. package/dist/tooling/migrate/files.d.ts +19 -0
  139. package/dist/tooling/migrate/index.d.ts +7 -0
  140. package/dist/tooling/migrate/index.js +7 -0
  141. package/dist/tooling/migrate/plan.d.ts +76 -0
  142. package/dist/tooling/migrate/policy.d.ts +78 -0
  143. package/dist/tooling/migrate/project.d.ts +69 -0
  144. package/dist/tooling/migrate/status.d.ts +74 -0
  145. package/dist/tooling/migrate/values.d.ts +29 -0
  146. package/package.json +109 -7
  147. package/dist/index.js +0 -0
@@ -0,0 +1,398 @@
1
+ import {
2
+ decodeResult,
3
+ emitJoin,
4
+ emitWhere,
5
+ emitOrder,
6
+ emitPrimaryOrder,
7
+ selectedColumns,
8
+ rejectKeys,
9
+ readLimit,
10
+ projectExpr,
11
+ jsonExpr,
12
+ cell,
13
+ indexes,
14
+ quote,
15
+ list,
16
+ isRecord,
17
+ fail
18
+ } from "./rgs0st28.js";
19
+ import {
20
+ throwNamed2
21
+ } from "./ycwz42az.js";
22
+
23
+ // src/runtime/include.ts
24
+ var INCLUDE_OPTIONS = ["all", "include", "limit", "orderBy", "select", "where"];
25
+ function emitIncludeSelect(include, alias, sink, outputs, column) {
26
+ const selected = include.columns;
27
+ sink.mark(`i:${include.name}:${include.relation.kind}`);
28
+ if (include.relation.kind === "many") {
29
+ if (column > 0 || outputs?.fields.length)
30
+ sink.text(", ");
31
+ sink.text(alias);
32
+ sink.text(".rows");
33
+ outputs?.includes.push({
34
+ name: include.name,
35
+ kind: "many",
36
+ at: column,
37
+ fields: selected.map((item, index) => ({
38
+ key: item.field,
39
+ at: index,
40
+ decode: item.decode
41
+ })),
42
+ nested: include.nested.map((nested, index) => ({
43
+ name: nested.name,
44
+ kind: nested.relation.kind,
45
+ at: selected.length + index,
46
+ fields: nested.columns.map((item, at) => ({
47
+ key: item.field,
48
+ at,
49
+ decode: item.decode
50
+ })),
51
+ nested: []
52
+ }))
53
+ });
54
+ return column + 1;
55
+ }
56
+ const projected = include.presence === undefined ? selected : [...selected, include.presence];
57
+ const start = column;
58
+ for (let index = 0;index < projected.length; index += 1) {
59
+ if (start + index > 0)
60
+ sink.text(", ");
61
+ sink.text(alias);
62
+ sink.text(".c");
63
+ sink.text(String(index));
64
+ sink.mark(`s:${projected[index]?.field ?? ""}`);
65
+ }
66
+ const nestedStart = start + projected.length;
67
+ let cursor = nestedStart;
68
+ const nestedOut = [];
69
+ for (let index = 0;index < include.nested.length; index += 1) {
70
+ const nested = include.nested[index];
71
+ if (nested === undefined)
72
+ continue;
73
+ const width = nested.relation.kind === "many" ? 1 : nested.presence === undefined ? nested.columns.length : nested.columns.length + 1;
74
+ for (let slot = 0;slot < width; slot += 1) {
75
+ sink.text(", ");
76
+ sink.text(alias);
77
+ sink.text(".n");
78
+ sink.text(String(index));
79
+ sink.text("_");
80
+ sink.text(String(slot));
81
+ }
82
+ nestedOut.push({
83
+ name: nested.name,
84
+ kind: nested.relation.kind,
85
+ at: nested.relation.kind === "many" ? cursor : nested.presence === undefined ? cursor : cursor + nested.columns.length,
86
+ fields: nested.columns.map((item, at) => ({
87
+ key: item.field,
88
+ at: nested.relation.kind === "many" ? at : cursor + at,
89
+ decode: item.decode
90
+ })),
91
+ nested: []
92
+ });
93
+ cursor += width;
94
+ }
95
+ outputs?.includes.push({
96
+ name: include.name,
97
+ kind: "one",
98
+ at: start + include.anchor,
99
+ fields: selected.map((item, index) => ({
100
+ key: item.field,
101
+ at: start + index,
102
+ decode: item.decode
103
+ })),
104
+ nested: nestedOut
105
+ });
106
+ return cursor;
107
+ }
108
+ function emitIncludeJoin(schema, include, sink, parentAlias, alias, depth) {
109
+ const child = indexes(schema).get(include.relation.table);
110
+ if (child === undefined) {
111
+ fail("OKM1120", `Relation ${include.name} names ${include.relation.table}, which is not in the schema.`);
112
+ }
113
+ const childAlias = `r${String(depth)}_${include.name}`;
114
+ sink.text(" left join lateral (");
115
+ if (include.relation.kind === "many") {
116
+ sink.text("select coalesce(json_agg(item order by ord), '[]'::json) as rows from (select item, row_number() over () as ord from (select json_build_array(");
117
+ const selected = include.columns;
118
+ for (let index = 0;index < selected.length; index += 1) {
119
+ const item = selected[index];
120
+ if (item === undefined)
121
+ continue;
122
+ if (index > 0)
123
+ sink.text(", ");
124
+ sink.text(jsonExpr(`${childAlias}.${quote(item.sql)}`, item.dataType));
125
+ }
126
+ if (selected.length === 0)
127
+ sink.text("1");
128
+ for (const nested of include.nested) {
129
+ sink.text(", ");
130
+ emitNestedAggregate(schema, nested, sink, childAlias, depth + 1);
131
+ }
132
+ sink.text(") as item from ");
133
+ sink.text(quote(child.model.sql));
134
+ sink.text(" ");
135
+ sink.text(childAlias);
136
+ sink.text(" where ");
137
+ emitJoin(sink, parentAlias, childAlias, include.relation);
138
+ emitWhere(schema, child, include.where, sink, childAlias, depth + 1, true);
139
+ emitOrder(child, include.orderBy, sink, childAlias);
140
+ if (include.orderBy === undefined && child.model.primary.length > 0) {
141
+ emitPrimaryOrder(child, sink, childAlias);
142
+ }
143
+ if (include.limit !== undefined) {
144
+ sink.text(" limit ");
145
+ sink.param(String(include.limit));
146
+ sink.mark(`l:${String(include.limit)}`);
147
+ }
148
+ sink.text(") limited) ordered) ");
149
+ sink.text(alias);
150
+ sink.text(" on true");
151
+ return;
152
+ }
153
+ sink.text("select ");
154
+ const projected = include.presence === undefined ? include.columns : [...include.columns, include.presence];
155
+ for (let index = 0;index < projected.length; index += 1) {
156
+ const item = projected[index];
157
+ if (item === undefined)
158
+ continue;
159
+ if (index > 0)
160
+ sink.text(", ");
161
+ sink.text(projectExpr(`${childAlias}.${quote(item.sql)}`, item.dataType));
162
+ sink.text(" as c");
163
+ sink.text(String(index));
164
+ }
165
+ if (projected.length === 0)
166
+ sink.text("1 as c0");
167
+ for (let index = 0;index < include.nested.length; index += 1) {
168
+ const nested = include.nested[index];
169
+ if (nested === undefined)
170
+ continue;
171
+ if (nested.relation.kind === "many") {
172
+ sink.text(", ");
173
+ sink.text("n");
174
+ sink.text(String(index));
175
+ sink.text(".rows as n");
176
+ sink.text(String(index));
177
+ sink.text("_0");
178
+ continue;
179
+ }
180
+ const width = nested.presence === undefined ? nested.columns.length : nested.columns.length + 1;
181
+ for (let slot = 0;slot < width; slot += 1) {
182
+ sink.text(", ");
183
+ sink.text("n");
184
+ sink.text(String(index));
185
+ sink.text(".c");
186
+ sink.text(String(slot));
187
+ sink.text(" as n");
188
+ sink.text(String(index));
189
+ sink.text("_");
190
+ sink.text(String(slot));
191
+ }
192
+ }
193
+ sink.text(" from ");
194
+ sink.text(quote(child.model.sql));
195
+ sink.text(" ");
196
+ sink.text(childAlias);
197
+ for (let index = 0;index < include.nested.length; index += 1) {
198
+ const nested = include.nested[index];
199
+ if (nested === undefined)
200
+ continue;
201
+ emitIncludeJoin(schema, nested, sink, childAlias, `n${String(index)}`, depth + 1);
202
+ }
203
+ sink.text(" where ");
204
+ emitJoin(sink, parentAlias, childAlias, include.relation);
205
+ emitWhere(schema, child, include.where, sink, childAlias, depth + 1, true);
206
+ sink.text(" limit 1) ");
207
+ sink.text(alias);
208
+ sink.text(" on true");
209
+ }
210
+ function emitNestedAggregate(schema, include, sink, alias, depth) {
211
+ const child = indexes(schema).get(include.relation.table);
212
+ if (child === undefined) {
213
+ fail("OKM1120", `Relation ${include.name} names ${include.relation.table}, which is not in the schema.`);
214
+ }
215
+ const childAlias = `n${String(depth)}_${include.name}`;
216
+ sink.text("(select coalesce(json_agg(item order by ord), '[]'::json) from (select item, row_number() over () as ord from (select json_build_array(");
217
+ for (let index = 0;index < include.columns.length; index += 1) {
218
+ const item = include.columns[index];
219
+ if (item === undefined)
220
+ continue;
221
+ if (index > 0)
222
+ sink.text(", ");
223
+ sink.text(jsonExpr(`${childAlias}.${quote(item.sql)}`, item.dataType));
224
+ }
225
+ if (include.columns.length === 0)
226
+ sink.text("1");
227
+ sink.text(") as item from ");
228
+ sink.text(quote(child.model.sql));
229
+ sink.text(" ");
230
+ sink.text(childAlias);
231
+ sink.text(" where ");
232
+ emitJoin(sink, alias, childAlias, include.relation);
233
+ emitWhere(schema, child, include.where, sink, childAlias, depth, true);
234
+ emitOrder(child, include.orderBy, sink, childAlias);
235
+ if (include.orderBy === undefined && child.model.primary.length > 0) {
236
+ emitPrimaryOrder(child, sink, childAlias);
237
+ }
238
+ if (include.limit !== undefined) {
239
+ sink.text(" limit ");
240
+ sink.param(String(include.limit));
241
+ sink.mark(`l:${String(include.limit)}`);
242
+ }
243
+ sink.text(") limited) ordered)");
244
+ }
245
+ function readIncludes(schema, table, include, all) {
246
+ if (include === undefined)
247
+ return [];
248
+ if (!isRecord(include)) {
249
+ fail("OKM1120", "include must be an object of relations.");
250
+ }
251
+ const parsed = [];
252
+ for (const name of Object.keys(include)) {
253
+ const relation = table.relations.get(name);
254
+ if (relation === undefined) {
255
+ throwNamed2("OKM1120", name, [...table.relations.keys()], `Include ${name} is not a relation of ${table.model.name}. Accepted names: ${list([...table.relations.keys()])}.`);
256
+ }
257
+ parsed.push(parseInclude(schema, name, relation, include[name], all));
258
+ }
259
+ return parsed;
260
+ }
261
+ function parseInclude(schema, name, relation, value, all) {
262
+ if (value === true) {
263
+ if (relation.kind === "many" && all === undefined) {
264
+ fail("OKM1105", `Include ${name} is to-many and has no limit. Pass limit, or call .all(reason).`);
265
+ }
266
+ const child = childIndex(schema, relation);
267
+ const columns = selectedColumns(child, undefined);
268
+ return {
269
+ name,
270
+ relation,
271
+ where: undefined,
272
+ orderBy: undefined,
273
+ limit: undefined,
274
+ columns,
275
+ ...anchored(child, columns),
276
+ nested: []
277
+ };
278
+ }
279
+ if (!isRecord(value)) {
280
+ fail("OKM1120", `Include ${name} must be true or an object.`);
281
+ }
282
+ rejectKeys(value, INCLUDE_OPTIONS, `include ${name}`);
283
+ const reason = typeof value.all === "string" ? value.all : all;
284
+ let limit;
285
+ if (value.limit !== undefined)
286
+ limit = readLimit(value.limit);
287
+ if (relation.kind === "many" && limit === undefined && reason === undefined) {
288
+ fail("OKM1105", `Include ${name} is to-many and has no limit. Pass limit, or call .all(reason).`);
289
+ }
290
+ const child = childIndex(schema, relation);
291
+ const columns = selectedColumns(child, value.select);
292
+ const nestedValue = value.include;
293
+ const nested = nestedValue === undefined ? [] : readIncludes(schema, child, nestedValue, reason);
294
+ return {
295
+ name,
296
+ relation,
297
+ where: value.where,
298
+ orderBy: value.orderBy,
299
+ limit,
300
+ columns,
301
+ ...anchored(child, columns),
302
+ nested
303
+ };
304
+ }
305
+ function anchored(table, columns) {
306
+ const pk = table.model.primary[0];
307
+ if (pk === undefined)
308
+ return { presence: undefined, anchor: 0 };
309
+ const selected = columns.findIndex((column) => column.field === pk);
310
+ if (selected >= 0)
311
+ return { presence: undefined, anchor: selected };
312
+ return { presence: table.columns.get(pk), anchor: columns.length };
313
+ }
314
+ function childIndex(schema, relation) {
315
+ const child = indexes(schema).get(relation.table);
316
+ if (child === undefined) {
317
+ fail("OKM1120", `Relation ${relation.name} names ${relation.table}, which is not in the schema.`);
318
+ }
319
+ return child;
320
+ }
321
+ function decodeIncluded(plan, rows, table) {
322
+ return decodeResult(plan, rows, table, decodeRowIncluded);
323
+ }
324
+ function decodeRowIncluded(outputs, row) {
325
+ const result = {};
326
+ for (const field of outputs.fields) {
327
+ result[field.key] = cell(row[field.at], field.decode);
328
+ }
329
+ for (const include of outputs.includes) {
330
+ result[include.name] = decodeInclude(include, row);
331
+ }
332
+ return result;
333
+ }
334
+ function decodeInclude(include, row) {
335
+ if (include.kind === "many") {
336
+ const raw = row[include.at];
337
+ if (raw === null || raw === undefined)
338
+ return [];
339
+ const parsed = JSON.parse(raw);
340
+ if (!Array.isArray(parsed))
341
+ return [];
342
+ const rows = [];
343
+ for (const item of parsed) {
344
+ if (!Array.isArray(item))
345
+ continue;
346
+ const child = {};
347
+ for (const field of include.fields) {
348
+ child[field.key] = jsonCell(item[field.at], field.decode);
349
+ }
350
+ for (const nested of include.nested) {
351
+ child[nested.name] = decodeJsonInclude(nested, item[nested.at]);
352
+ }
353
+ rows.push(child);
354
+ }
355
+ return rows;
356
+ }
357
+ const presence = row[include.at];
358
+ if (presence === null || presence === undefined)
359
+ return null;
360
+ const child = {};
361
+ for (const field of include.fields) {
362
+ child[field.key] = cell(row[field.at], field.decode);
363
+ }
364
+ for (const nested of include.nested) {
365
+ child[nested.name] = decodeInclude(nested, row);
366
+ }
367
+ return child;
368
+ }
369
+ function decodeJsonInclude(include, value) {
370
+ if (!Array.isArray(value))
371
+ return include.kind === "many" ? [] : null;
372
+ const rows = [];
373
+ for (const item of value) {
374
+ if (!Array.isArray(item))
375
+ continue;
376
+ const child = {};
377
+ for (const field of include.fields) {
378
+ child[field.key] = jsonCell(item[field.at], field.decode);
379
+ }
380
+ rows.push(child);
381
+ }
382
+ return include.kind === "one" ? rows[0] ?? null : rows;
383
+ }
384
+ function jsonCell(value, decode) {
385
+ if (value === null || value === undefined)
386
+ return null;
387
+ const wire = typeof value === "string" ? value : JSON.stringify(value);
388
+ return decode === undefined ? wire : decode(wire);
389
+ }
390
+ var includeHooks = {
391
+ read: readIncludes,
392
+ select: emitIncludeSelect,
393
+ join: emitIncludeJoin
394
+ };
395
+ export {
396
+ decodeIncluded,
397
+ includeHooks
398
+ };
@@ -0,0 +1,98 @@
1
+ import {
2
+ OkmError2
3
+ } from "./ycwz42az.js";
4
+
5
+ // src/adapters/error.ts
6
+ class DriverError2 extends Error {
7
+ sqlstate;
8
+ constraint;
9
+ table;
10
+ column;
11
+ detail;
12
+ cause;
13
+ batchIndex;
14
+ kind;
15
+ constructor(message, fields = {}) {
16
+ super(message);
17
+ this.name = "DriverError";
18
+ this.sqlstate = fields.sqlstate;
19
+ this.constraint = fields.constraint;
20
+ this.table = fields.table;
21
+ this.column = fields.column;
22
+ this.detail = fields.detail;
23
+ this.cause = fields.cause;
24
+ this.batchIndex = fields.batchIndex === undefined ? null : fields.batchIndex;
25
+ this.kind = fields.kind;
26
+ }
27
+ at(batchIndex) {
28
+ if (this.batchIndex === batchIndex)
29
+ return this;
30
+ return new DriverError2(this.message, driverFields({
31
+ sqlstate: this.sqlstate,
32
+ constraint: this.constraint,
33
+ table: this.table,
34
+ column: this.column,
35
+ detail: this.detail,
36
+ cause: this.cause,
37
+ kind: this.kind,
38
+ batchIndex
39
+ }));
40
+ }
41
+ }
42
+ function cancelled2(cause) {
43
+ return new DriverError2("The call was cancelled.", driverFields({ kind: "cancelled", cause }));
44
+ }
45
+ function timedOut2(cause) {
46
+ return new DriverError2("The call timed out.", driverFields({ kind: "timeout", cause }));
47
+ }
48
+ function outcomeUnknown2(cause) {
49
+ return new DriverError2("The commit outcome is unknown. The result never arrived.", driverFields({ kind: "outcome_unknown", cause, batchIndex: null }));
50
+ }
51
+ function acquireTimeout2() {
52
+ return new OkmError2("OKM1846", "Timed out waiting for a connection. This pool did not hand one out within timeouts.acquire.");
53
+ }
54
+ function errorField2(error, key) {
55
+ if (typeof error !== "object" || error === null || !(key in error))
56
+ return;
57
+ const value = Reflect.get(error, key);
58
+ return typeof value === "string" && value.length > 0 ? value : undefined;
59
+ }
60
+ function mapDriverError2(error, batchIndex) {
61
+ if (error instanceof OkmError2)
62
+ return error;
63
+ if (error instanceof DriverError2) {
64
+ return batchIndex === undefined ? error : error.at(batchIndex);
65
+ }
66
+ const message = error instanceof Error ? error.message : "driver error";
67
+ return new DriverError2(message, driverFields({
68
+ sqlstate: errorField2(error, "code") ?? errorField2(error, "sqlstate"),
69
+ constraint: errorField2(error, "constraint_name") ?? errorField2(error, "constraint"),
70
+ table: errorField2(error, "table_name") ?? errorField2(error, "table"),
71
+ column: errorField2(error, "column_name") ?? errorField2(error, "column"),
72
+ detail: errorField2(error, "detail"),
73
+ cause: error,
74
+ batchIndex
75
+ }));
76
+ }
77
+ function driverFields(input) {
78
+ const fields = {};
79
+ if (input.sqlstate !== undefined)
80
+ fields.sqlstate = input.sqlstate;
81
+ if (input.constraint !== undefined)
82
+ fields.constraint = input.constraint;
83
+ if (input.table !== undefined)
84
+ fields.table = input.table;
85
+ if (input.column !== undefined)
86
+ fields.column = input.column;
87
+ if (input.detail !== undefined)
88
+ fields.detail = input.detail;
89
+ if (input.cause !== undefined)
90
+ fields.cause = input.cause;
91
+ if (input.batchIndex !== undefined)
92
+ fields.batchIndex = input.batchIndex;
93
+ if (input.kind !== undefined)
94
+ fields.kind = input.kind;
95
+ return fields;
96
+ }
97
+
98
+ export { DriverError2, cancelled2, timedOut2, outcomeUnknown2, acquireTimeout2, errorField2, mapDriverError2 };