@voltro/database 0.85.0 → 0.87.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 (173) hide show
  1. package/CHANGELOG.md +5987 -0
  2. package/THIRD-PARTY-NOTICES.md +5 -257
  3. package/dist/actorSnapshot.js +24 -0
  4. package/dist/arrayCodec.js +32 -0
  5. package/dist/branchExecute.js +92 -0
  6. package/dist/branching.js +106 -0
  7. package/dist/bulkInsertLimits.js +25 -0
  8. package/dist/cdcOffsetsTables.js +19 -0
  9. package/dist/changeEvent.js +41 -0
  10. package/dist/changeIdentity.js +65 -0
  11. package/dist/changeListenerCeiling.js +6 -0
  12. package/dist/columnReference.js +17 -0
  13. package/dist/columns.js +326 -0
  14. package/dist/committedChanges.js +12 -0
  15. package/dist/connectionIdentity.js +36 -0
  16. package/dist/coreTables.js +16 -0
  17. package/dist/coreTablesRegistry.js +10 -0
  18. package/dist/dataTransfers.js +23 -0
  19. package/dist/dbCause.js +222 -0
  20. package/dist/dbMetrics.js +65 -0
  21. package/dist/decimalComparison.js +27 -0
  22. package/dist/derivedRowId.js +5 -0
  23. package/dist/dialect.js +13 -0
  24. package/dist/enumRenames.js +14 -0
  25. package/dist/expiresMixin.js +10 -0
  26. package/dist/fieldEncryption.js +121 -0
  27. package/dist/frameworkTables.js +143 -0
  28. package/dist/ginIndex.js +10 -0
  29. package/dist/hybridSearch.js +32 -0
  30. package/dist/idGenerator.js +57 -0
  31. package/dist/identifierLimits.js +32 -0
  32. package/dist/index.d.ts +166 -22
  33. package/dist/index.js +82 -2183
  34. package/dist/indexAudit.js +61 -0
  35. package/dist/indexStorage.js +58 -0
  36. package/dist/joinCompiler.js +160 -0
  37. package/dist/jsonEagerCompiler.js +436 -0
  38. package/dist/jsonPatch.js +78 -0
  39. package/dist/jsonPatchAssignments.js +13 -0
  40. package/dist/jsonPath.js +31 -0
  41. package/dist/localFirstMixin.js +12 -0
  42. package/dist/migrate.js +644 -0
  43. package/dist/migration.js +18 -0
  44. package/dist/migrations/appliedAtValue.js +8 -0
  45. package/dist/migrations/applier.js +1100 -0
  46. package/dist/migrations/boot.js +196 -0
  47. package/dist/migrations/branchRehearsal.js +122 -0
  48. package/dist/migrations/columnEquivalence.js +85 -0
  49. package/dist/migrations/ddlError.js +63 -0
  50. package/dist/migrations/ddlStatements.js +9 -0
  51. package/dist/migrations/declaredSchema.js +162 -0
  52. package/dist/migrations/deployLedger.js +19 -0
  53. package/dist/migrations/fileBased.js +57 -0
  54. package/dist/migrations/fileContext.js +482 -0
  55. package/dist/migrations/fileDiscovery.js +332 -0
  56. package/dist/migrations/fileSkipProbes.js +117 -0
  57. package/dist/migrations/fingerprint.js +46 -0
  58. package/dist/migrations/fkCycles.js +13 -0
  59. package/dist/migrations/frameworkLiveTables.js +25 -0
  60. package/dist/migrations/idempotentDdl.js +37 -0
  61. package/dist/migrations/indexPredicate.js +50 -0
  62. package/dist/migrations/introspect.js +801 -0
  63. package/dist/migrations/ledgerRows.js +4 -0
  64. package/dist/migrations/lock.js +91 -0
  65. package/dist/migrations/migrationTableExists.js +9 -0
  66. package/dist/migrations/mssqlColumnDependencies.js +76 -0
  67. package/dist/migrations/mysqlEngine.js +11 -0
  68. package/dist/migrations/namespaceCharset.js +51 -0
  69. package/dist/migrations/planner.js +785 -0
  70. package/dist/migrations/postgresEnumCheck.js +22 -0
  71. package/dist/migrations/reactiveTriggerDrift.js +58 -0
  72. package/dist/migrations/reactiveTriggerName.js +7 -0
  73. package/dist/migrations/renameMssqlCheck.js +21 -0
  74. package/dist/migrations/restoreSnapshots.js +206 -0
  75. package/dist/migrations/resumeLedger.js +86 -0
  76. package/dist/migrations/rollingDeploy.js +106 -0
  77. package/dist/migrations/schemaOwner.js +46 -0
  78. package/dist/migrations/schemaOwnerTable.js +4 -0
  79. package/dist/migrations/softDropSnapshot.js +20 -0
  80. package/dist/migrations/sqlLimit.js +8 -0
  81. package/dist/migrations/sqliteCatalogName.js +13 -0
  82. package/dist/migrations/sqliteConstraintIdentity.js +97 -0
  83. package/dist/migrations/sqliteDecimalBoot.js +22 -0
  84. package/dist/migrations/sqliteDecimalPublication.js +257 -0
  85. package/dist/migrations/sqliteDecimalReview.js +30 -0
  86. package/dist/migrations/sqliteDecimalReviewStore.js +188 -0
  87. package/dist/migrations/sqliteDecimalReviewWitness.js +38 -0
  88. package/dist/migrations/sqliteDecimalSource.js +69 -0
  89. package/dist/migrations/sqliteDecimalStage.js +135 -0
  90. package/dist/migrations/sqliteForeignKeys.js +38 -0
  91. package/dist/migrations/sqliteMigrationBatch.js +37 -0
  92. package/dist/migrations/sqliteRetainedSource.js +106 -0
  93. package/dist/migrations/sqliteRowIdentity.js +63 -0
  94. package/dist/migrations/sqliteSchemaEpoch.js +12 -0
  95. package/dist/migrations/sqliteSnapshotGuard.js +10 -0
  96. package/dist/migrations/sqliteTableContents.js +34 -0
  97. package/dist/migrations/sqliteTableCopy.js +25 -0
  98. package/dist/migrations/sqliteTableSchema.js +19 -0
  99. package/dist/migrations/sqliteWitnessProtection.js +8 -0
  100. package/dist/migrations/squash.js +81 -0
  101. package/dist/migrations/storeCharset.js +66 -0
  102. package/dist/migrations/transactionCause.js +10 -0
  103. package/dist/migrations/undeclaredCharset.js +40 -0
  104. package/dist/migrations/uniqueActiveLowering.js +39 -0
  105. package/dist/mixins.js +22 -0
  106. package/dist/mssqlDecimalDistinct.js +51 -0
  107. package/dist/mssqlJsonValueCheck.js +42 -0
  108. package/dist/mssqlTextStorage.js +9 -0
  109. package/dist/namespace.js +21 -0
  110. package/dist/{wire-CG2j7J3f.js → optimisticVersion.js} +2 -2
  111. package/dist/pendingAttribution.js +79 -0
  112. package/dist/pluginRef.js +17 -0
  113. package/dist/predicate.js +273 -0
  114. package/dist/predicateCoercion.js +13 -0
  115. package/dist/projectedColumn.js +37 -0
  116. package/dist/queryBuilder.js +388 -0
  117. package/dist/rawSql.js +8 -0
  118. package/dist/relations.js +69 -0
  119. package/dist/relationsRegistry.js +38 -0
  120. package/dist/replaceInProgress.js +53 -0
  121. package/dist/requiredColumns.js +26 -0
  122. package/dist/residency.js +52 -0
  123. package/dist/retention.js +62 -0
  124. package/dist/rowDecoder.js +173 -0
  125. package/dist/rowKey.js +8 -0
  126. package/dist/rowSchema.js +31 -0
  127. package/dist/scopeKey.js +8 -0
  128. package/dist/seed.js +33 -0
  129. package/dist/snowflake.js +26 -0
  130. package/dist/sql.d.ts +2792 -3773
  131. package/dist/sql.js +42 -6905
  132. package/dist/sqlCompiler.js +360 -0
  133. package/dist/sqlError.js +8 -0
  134. package/dist/sqlMutation.js +55 -0
  135. package/dist/sqlPoolCapacity.js +12 -0
  136. package/dist/sqliteDecimal.js +22 -0
  137. package/dist/sqliteDecimalAggregateSql.js +61 -0
  138. package/dist/sqliteDecimalColumnSql.js +108 -0
  139. package/dist/sqliteDecimalConversion.js +15 -0
  140. package/dist/sqliteDecimalCte.js +154 -0
  141. package/dist/sqliteDecimalEncodeSql.js +32 -0
  142. package/dist/sqliteDecimalOutputs.js +74 -0
  143. package/dist/sqliteDecimalPredicate.js +66 -0
  144. package/dist/sqliteDecimalQuery.js +183 -0
  145. package/dist/sqliteDecimalQueryPlan.js +37 -0
  146. package/dist/sqliteDecimalResultSql.js +44 -0
  147. package/dist/sqliteDecimalRowQuery.js +63 -0
  148. package/dist/sqliteDecimalSetQuery.js +50 -0
  149. package/dist/sqliteDecimalSource.js +63 -0
  150. package/dist/sqliteDecimalStorage.js +29 -0
  151. package/dist/sqliteDecimalSubquery.js +19 -0
  152. package/dist/sqliteDecimalWindowQuery.js +196 -0
  153. package/dist/sqliteValueCoercion.js +4 -0
  154. package/dist/stampId.js +21 -0
  155. package/dist/storeErrors.js +9 -0
  156. package/dist/storeRefusal.js +20 -0
  157. package/dist/stream.js +36 -0
  158. package/dist/subjectGraph.js +175 -0
  159. package/dist/table.js +394 -0
  160. package/dist/tableRegistry.js +16 -0
  161. package/dist/tenantSelection.js +27 -0
  162. package/dist/transactionOutcome.js +100 -0
  163. package/dist/transientContention.js +36 -0
  164. package/dist/typeId.js +51 -0
  165. package/dist/typedStore.js +16 -0
  166. package/dist/upsertUpdate.js +20 -0
  167. package/dist/vectorEmbedding.js +31 -0
  168. package/dist/view.js +39 -0
  169. package/dist/wire.js +6 -2
  170. package/dist/writeAttribution.js +16 -0
  171. package/dist/writeRecorder.js +38 -0
  172. package/package.json +3 -4
  173. package/dist/replaceInProgress-DC88Pdiy.js +0 -3735
@@ -0,0 +1,273 @@
1
+ import { columnComparisonOperators as e, columnRef as t, isColumnReference as n } from "./columnReference.js";
2
+ import { authoredError as r } from "./dbCause.js";
3
+ import { compareDecimal as i } from "./decimalComparison.js";
4
+ //#region src/predicate.ts
5
+ var a = (e, t) => ({
6
+ column: e,
7
+ op: "eq",
8
+ value: t
9
+ }), o = (e, t) => ({
10
+ column: e,
11
+ op: "neq",
12
+ value: t
13
+ }), s = (e, t) => ({
14
+ column: e,
15
+ op: "gt",
16
+ value: t
17
+ }), c = (e, t) => ({
18
+ column: e,
19
+ op: "gte",
20
+ value: t
21
+ }), l = (e, t) => ({
22
+ column: e,
23
+ op: "lt",
24
+ value: t
25
+ }), u = (e, t) => ({
26
+ column: e,
27
+ op: "lte",
28
+ value: t
29
+ }), d = (e, t) => ({
30
+ column: e,
31
+ op: "in",
32
+ value: t
33
+ }), f = (e, t) => ({
34
+ column: e,
35
+ op: "notIn",
36
+ value: t
37
+ }), p = (e, t) => ({
38
+ column: e,
39
+ op: "contains",
40
+ value: t
41
+ }), m = (e, t) => ({
42
+ column: e,
43
+ op: "startsWith",
44
+ value: t
45
+ }), h = (e, t) => ({
46
+ column: e,
47
+ op: "arrayContains",
48
+ value: t
49
+ }), g = (e, t) => ({
50
+ column: e,
51
+ op: "arrayOverlaps",
52
+ value: t
53
+ }), _ = (e, t) => ({
54
+ column: e,
55
+ op: "arrayHas",
56
+ value: t
57
+ }), v = {
58
+ column: "id",
59
+ op: "in",
60
+ value: []
61
+ }, y = (e) => ({
62
+ column: e,
63
+ op: "isNull"
64
+ }), b = (e) => ({
65
+ column: e,
66
+ op: "isNotNull"
67
+ }), x = (e, t) => ({
68
+ column: e,
69
+ op: "spatial",
70
+ value: t
71
+ }), S = (...e) => ({ and: e }), C = (...e) => ({ or: e }), w = (e) => ({ not: e }), T = (e, ...t) => {
72
+ if (t.length === 0) throw r(`jsonField("${e}"): at least one path segment is required`);
73
+ let n = (n, r) => ({
74
+ column: e,
75
+ path: t,
76
+ op: n,
77
+ value: r
78
+ });
79
+ return {
80
+ eq: (e) => n("eq", e),
81
+ neq: (e) => n("neq", e),
82
+ gt: (e) => n("gt", e),
83
+ gte: (e) => n("gte", e),
84
+ lt: (e) => n("lt", e),
85
+ lte: (e) => n("lte", e),
86
+ inSet: (e) => n("in", e),
87
+ notInSet: (e) => n("notIn", e),
88
+ contains: (e) => n("contains", e),
89
+ startsWith: (e) => n("startsWith", e),
90
+ isNull: () => n("isNull"),
91
+ isNotNull: () => n("isNotNull")
92
+ };
93
+ }, E = (e) => "descriptor" in e ? e.descriptor : e, D = (e, t) => ({
94
+ column: e,
95
+ op: "subquery-in",
96
+ subquery: E(t)
97
+ }), O = (e, t) => ({
98
+ column: e,
99
+ op: "subquery-not-in",
100
+ subquery: E(t)
101
+ }), k = (e) => ({
102
+ op: "exists",
103
+ subquery: E(e)
104
+ }), A = (e) => ({
105
+ op: "not-exists",
106
+ subquery: E(e)
107
+ }), j = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/, M = (e) => {
108
+ if (e instanceof Date) return e.getTime();
109
+ if (typeof e == "string" && j.test(e)) {
110
+ let t = Date.parse(e);
111
+ return Number.isNaN(t) ? void 0 : t;
112
+ }
113
+ }, N = (e, t) => {
114
+ if (!(e instanceof Date) && !(t instanceof Date)) return;
115
+ let n = M(e), r = M(t);
116
+ return n === void 0 || r === void 0 ? void 0 : [n, r];
117
+ }, P = (e, t) => {
118
+ if (e === t) return !0;
119
+ if (e instanceof Uint8Array && t instanceof Uint8Array) {
120
+ if (e.length !== t.length) return !1;
121
+ for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
122
+ return !0;
123
+ }
124
+ let n = N(e, t);
125
+ return n !== void 0 && n[0] === n[1];
126
+ }, F = (e, t) => {
127
+ if (e == null || t == null) return null;
128
+ let n = N(e, t);
129
+ if (n !== void 0) return n[0] === n[1] ? 0 : n[0] > n[1] ? 1 : -1;
130
+ let r = e instanceof Date ? e.getTime() : e, i = t instanceof Date ? t.getTime() : t;
131
+ return typeof r == typeof i ? r === i ? 0 : r > i ? 1 : -1 : null;
132
+ }, I = (e, t) => {
133
+ let n = e;
134
+ for (let e of t) {
135
+ if (n == null) return;
136
+ n = typeof e == "number" ? Array.isArray(n) ? n[e] : void 0 : typeof n == "object" && !Array.isArray(n) && Object.hasOwn(n, e) ? n[e] : void 0;
137
+ }
138
+ return n;
139
+ }, L = (e, t) => e != null && t != null ? i(e, t) === 0 : P(e, t), R = (e, t, n = null, r = {}) => V(e, t, n, r) === !0, z = (e, t = null, n = {}) => {
140
+ let r = /* @__PURE__ */ new Map(), i = (e) => {
141
+ if ("not" in e) {
142
+ i(e.not);
143
+ return;
144
+ }
145
+ if ("and" in e) {
146
+ e.and.forEach(i);
147
+ return;
148
+ }
149
+ if ("or" in e) {
150
+ e.or.forEach(i);
151
+ return;
152
+ }
153
+ if (e.op !== "in" && e.op !== "notIn" || n[e.column]?.type === "decimal") return;
154
+ let t = Object.getOwnPropertyDescriptor(e, "value");
155
+ if (t === void 0 || !("value" in t)) return;
156
+ let a = t.value;
157
+ if (!Array.isArray(a) || a.length < 16 || Object.getPrototypeOf(a) !== Array.prototype) return;
158
+ let o = Object.getOwnPropertyDescriptor(a, "some");
159
+ if (o !== void 0 && (!("value" in o) || o.value !== Array.prototype.some)) return;
160
+ for (let e = 0; e < a.length; e++) {
161
+ let t = Object.getOwnPropertyDescriptor(a, e);
162
+ if (t !== void 0 && !("value" in t)) return;
163
+ }
164
+ if (a.some((e) => typeof e == "object" && !!e)) return;
165
+ let s = Array.prototype.filter.call(a, (e) => !(typeof e == "number" && Number.isNaN(e)));
166
+ r.set(e, new Set(s));
167
+ };
168
+ return i(e), (i) => V(e, i, t, n, r) === !0;
169
+ }, B = (e, t, n) => {
170
+ if (e.length < 128 || t.length < 16 || Object.getPrototypeOf(e) !== Array.prototype || Object.getPrototypeOf(t) !== Array.prototype || Object.getOwnPropertyDescriptor(e, "includes") !== void 0 || Object.getOwnPropertyDescriptor(t, n) !== void 0) return;
171
+ for (let n of [e, t]) for (let e = 0; e < n.length; e += 1) {
172
+ let t = Object.getOwnPropertyDescriptor(n, String(e));
173
+ if (t === void 0 || !("value" in t)) return;
174
+ }
175
+ let r = /* @__PURE__ */ new Set();
176
+ for (let t = 0; t < e.length; t += 1) r.add(e[t]);
177
+ return r;
178
+ }, V = (t, a, o = null, s = {}, c) => {
179
+ if (!a) return !1;
180
+ if ("not" in t) {
181
+ let e = V(t.not, a, o, s, c);
182
+ return e === null ? null : !e;
183
+ }
184
+ if ("and" in t) {
185
+ let e = !1;
186
+ for (let n of t.and) {
187
+ let t = V(n, a, o, s, c);
188
+ if (t === !1) return !1;
189
+ t === null && (e = !0);
190
+ }
191
+ return !e || null;
192
+ }
193
+ if ("or" in t) {
194
+ let e = !1;
195
+ for (let n of t.or) {
196
+ let t = V(n, a, o, s, c);
197
+ if (t === !0) return !0;
198
+ t === null && (e = !0);
199
+ }
200
+ return e ? null : !1;
201
+ }
202
+ if (t.op === "subquery-in" || t.op === "subquery-not-in") {
203
+ if (!o) return !1;
204
+ let e = o.get(t.subquery);
205
+ if (!(e instanceof Set)) return !1;
206
+ let n = a[t.column], r = s[t.column]?.type === "decimal" ? [...e].some((e) => i(n, e) === 0) : e.has(n);
207
+ return t.op === "subquery-in" ? r : !r;
208
+ }
209
+ if (t.op === "exists" || t.op === "not-exists") {
210
+ if (!o) return !1;
211
+ let e = o.get(t.subquery), n = typeof e == "number" ? e > 0 : e instanceof Set && e.size > 0;
212
+ return t.op === "exists" ? n : !n;
213
+ }
214
+ let l = t, u = l.path === void 0 ? a[l.column] : I(a[l.column], l.path), d = n(l.value) ? l.value : void 0;
215
+ if (d !== void 0 && (!e.some((e) => e === l.op) || l.path !== void 0)) throw r("Column references require a scalar comparison without a JSON path");
216
+ let f = d === void 0 ? l.value : a[d.column];
217
+ if (d !== void 0 && (u == null || f == null)) return null;
218
+ let p = s[l.column]?.type === "decimal", m = c?.get(t);
219
+ if (m !== void 0 && !(u instanceof Date) && !(u instanceof Uint8Array)) {
220
+ let e = typeof u == "number" && Number.isNaN(u) ? !1 : m.has(u);
221
+ return l.op === "in" ? e : !e;
222
+ }
223
+ let h = p ? L : P, g = p ? i : F;
224
+ switch (l.op) {
225
+ case "eq": return h(u, f);
226
+ case "neq": return !h(u, f);
227
+ case "gt": return (g(u, f) ?? -1) > 0;
228
+ case "gte": return (g(u, f) ?? -1) >= 0;
229
+ case "lt": return (g(u, f) ?? 1) < 0;
230
+ case "lte": return (g(u, f) ?? 1) <= 0;
231
+ case "in": return Array.isArray(f) && f.some((e) => h(u, e));
232
+ case "notIn": return Array.isArray(f) && !f.some((e) => h(u, e));
233
+ case "contains": return typeof u == "string" && typeof f == "string" && u.toLowerCase().includes(f.toLowerCase());
234
+ case "startsWith": return typeof u == "string" && typeof f == "string" && u.startsWith(f);
235
+ case "arrayContains": {
236
+ let e = Array.isArray(u) ? u : [], t = Array.isArray(f) ? f : [];
237
+ if (e.length < 128 || t.length < 16) return t.every((t) => e.includes(t));
238
+ let n, r = 0;
239
+ return t.every((i) => (++r === 5 && (n = B(e, t, "every")), n === void 0 ? e.includes(i) : n.has(i)));
240
+ }
241
+ case "arrayOverlaps": {
242
+ let e = Array.isArray(u) ? u : [], t = Array.isArray(f) ? f : [];
243
+ if (e.length < 128 || t.length < 16) return t.some((t) => e.includes(t));
244
+ let n, r = 0;
245
+ return t.some((i) => (++r === 5 && (n = B(e, t, "some")), n === void 0 ? e.includes(i) : n.has(i)));
246
+ }
247
+ case "arrayHas": return Array.isArray(u) && u.includes(f);
248
+ case "isNull": return u == null;
249
+ case "isNotNull": return u != null;
250
+ case "spatial": throw r("@voltro/plugin-postgis: spatial predicates (ST_DWithin / ST_Contains / ST_Within / ST_Intersects / bbox &&) are not evaluable in-memory — use them in one-shot ctx.store.query reads, not reactive subscriptions.");
251
+ }
252
+ }, H = function* (e) {
253
+ if ("not" in e) yield* H(e.not);
254
+ else if ("and" in e) for (let t of e.and) yield* H(t);
255
+ else if ("or" in e) for (let t of e.or) yield* H(t);
256
+ else e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
257
+ kind: "in",
258
+ descriptor: e.subquery
259
+ } : (e.op === "exists" || e.op === "not-exists") && (yield {
260
+ kind: "exists",
261
+ descriptor: e.subquery
262
+ });
263
+ }, U = function* (e, t = !0) {
264
+ if ("not" in e) yield* U(e.not, !1);
265
+ else if ("and" in e) for (let n of e.and) yield* U(n, t);
266
+ else if ("or" in e) for (let t of e.or) yield* U(t, !1);
267
+ else e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
268
+ ...e,
269
+ conjunctive: t && !n(e.value)
270
+ });
271
+ };
272
+ //#endregion
273
+ export { v as MATCHES_NO_ROWS, S as and, h as arrayContains, _ as arrayHas, g as arrayOverlaps, H as collectSubqueries, t as columnRef, p as contains, a as eq, R as evaluatePredicate, k as exists, s as gt, c as gte, d as inSet, D as inSubquery, n as isColumnReference, b as isNotNull, y as isNull, T as jsonField, l as lt, u as lte, o as neq, w as not, A as notExists, f as notInSet, O as notInSubquery, C as or, z as preparePredicate, x as spatialPredicate, m as startsWith, U as walkLeaves };
@@ -0,0 +1,13 @@
1
+ //#region src/predicateCoercion.ts
2
+ var e = /* @__PURE__ */ new Set(["timestamp", "date"]), t = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, n = (n, r) => {
3
+ if (n === void 0 || r == null || !e.has(n) || r instanceof Date) return r;
4
+ if (typeof r == "number" && Number.isFinite(r)) return new Date(r);
5
+ if (typeof r == "string" && t.test(r)) {
6
+ if (/:\d{2}\.\d{4,}/.test(r)) return r;
7
+ let e = new Date(r);
8
+ return Number.isNaN(e.getTime()) ? r : e;
9
+ }
10
+ return r;
11
+ }, r = (t, r) => t === void 0 || !e.has(t) ? r : r.map((e) => n(t, e));
12
+ //#endregion
13
+ export { n as coercePredicateValue, r as coercePredicateValues };
@@ -0,0 +1,37 @@
1
+ import { getTable as e } from "./tableRegistry.js";
2
+ //#region src/projectedColumn.ts
3
+ var t = (t, n) => {
4
+ let r = t.lastIndexOf("."), i = r < 0 ? t : t.slice(r + 1), a = r < 0 ? void 0 : t.slice(0, r), o = a === void 0 || a === n.alias || a === n.table, s = o ? void 0 : n.joins?.find((e) => e.alias === a), c = o ? n.table : s?.table, l = o ? n.sourceTable : s?.sourceTable;
5
+ return (l?.tableName === c ? l : c === void 0 ? void 0 : e(c))?.fields[i];
6
+ }, n = (n) => {
7
+ for (let e of [
8
+ "joins",
9
+ "alias",
10
+ "table",
11
+ "sourceTable"
12
+ ]) {
13
+ let r = Object.getOwnPropertyDescriptor(n, e);
14
+ if (r === void 0 ? e in n : !("value" in r)) return (e) => t(e, n);
15
+ }
16
+ let r = n.joins;
17
+ if (r === void 0 || r.length < 8 || Object.getPrototypeOf(r) !== Array.prototype || r.find !== Array.prototype.find || r[Symbol.iterator] !== Array.prototype[Symbol.iterator]) return (e) => t(e, n);
18
+ let i = /* @__PURE__ */ new Map();
19
+ for (let e = 0; e < r.length; e++) {
20
+ let a = Object.getOwnPropertyDescriptor(r, e);
21
+ if (a === void 0 || !("value" in a)) return (e) => t(e, n);
22
+ let o = a.value;
23
+ for (let e of ["table", "sourceTable"]) {
24
+ let r = Object.getOwnPropertyDescriptor(o, e);
25
+ if (r === void 0 ? e in o : !("value" in r)) return (e) => t(e, n);
26
+ }
27
+ let s = Object.getOwnPropertyDescriptor(o, "alias");
28
+ if (s === void 0 || !("value" in s) || typeof s.value != "string") return (e) => t(e, n);
29
+ i.has(s.value) || i.set(s.value, o);
30
+ }
31
+ return (t) => {
32
+ let r = t.lastIndexOf("."), a = r < 0 ? t : t.slice(r + 1), o = r < 0 ? void 0 : t.slice(0, r), s = o === void 0 || o === n.alias || o === n.table, c = s ? void 0 : i.get(o), l = s ? n.table : c?.table, u = s ? n.sourceTable : c?.sourceTable;
33
+ return (u?.tableName === l ? u : l === void 0 ? void 0 : e(l))?.fields[a];
34
+ };
35
+ };
36
+ //#endregion
37
+ export { n as prepareProjectedColumn, t as projectedColumn };
@@ -0,0 +1,388 @@
1
+ import { getTable as e, registerTable as t } from "./tableRegistry.js";
2
+ //#region src/queryBuilder.ts
3
+ var n = (e) => e.order ?? [], r = (e) => ({
4
+ op: "count",
5
+ alias: e ?? "count"
6
+ }), i = (e, t) => ({
7
+ op: "count-distinct",
8
+ column: e,
9
+ alias: t ?? `count_distinct_${e}`
10
+ }), a = (e, t) => ({
11
+ op: "sum",
12
+ column: e,
13
+ alias: t ?? `sum_${e}`
14
+ }), o = (e, t) => ({
15
+ op: "avg",
16
+ column: e,
17
+ alias: t ?? `avg_${e}`
18
+ }), s = (e, t) => ({
19
+ op: "min",
20
+ column: e,
21
+ alias: t ?? `min_${e}`
22
+ }), c = (e, t) => ({
23
+ op: "max",
24
+ column: e,
25
+ alias: t ?? `max_${e}`
26
+ }), l = (e, t) => ({
27
+ op: "column",
28
+ column: e,
29
+ alias: t ?? e
30
+ }), u = (e) => (...t) => {
31
+ if (t.length < 2) throw Error(`${e}: requires at least two queries`);
32
+ return w({
33
+ table: t[0].descriptor.table,
34
+ predicate: void 0,
35
+ order: [],
36
+ take: void 0,
37
+ skip: void 0,
38
+ projection: void 0,
39
+ setOp: {
40
+ kind: e,
41
+ queries: t.map((e) => e.descriptor)
42
+ }
43
+ });
44
+ }, d = u("union"), f = u("union-all"), p = u("intersect"), m = u("except"), h = (e) => ({ over: (t) => ({
45
+ ...e,
46
+ window: t
47
+ }) }), g = (e = "rowNumber") => h({
48
+ op: "window-row-number",
49
+ alias: e
50
+ }), _ = (e = "rank") => h({
51
+ op: "window-rank",
52
+ alias: e
53
+ }), v = (e = "denseRank") => h({
54
+ op: "window-dense-rank",
55
+ alias: e
56
+ }), y = (e, t = 1, n) => h({
57
+ op: "window-lag",
58
+ column: e,
59
+ alias: n ?? `lag_${e}`,
60
+ offset: t
61
+ }), b = (e, t = 1, n) => h({
62
+ op: "window-lead",
63
+ column: e,
64
+ alias: n ?? `lead_${e}`,
65
+ offset: t
66
+ }), x = (e, t) => h({
67
+ op: "window-sum-over",
68
+ column: e,
69
+ alias: t ?? `sum_${e}_over`
70
+ }), S = (e, t) => h({
71
+ op: "window-avg-over",
72
+ column: e,
73
+ alias: t ?? `avg_${e}_over`
74
+ }), C = (t, n, r) => {
75
+ let i = r?.find((e) => e.name === n) ?? e(t)?.appliedFullText?.find((e) => e.name === n);
76
+ if (i === void 0) throw Error(`.matching('${n}', ...): no full-text index named '${n}' is declared on table '${t}'. Declare it with \`table(...).fullTextIndex('${n}', [columns])\` first.`);
77
+ return {
78
+ columns: i.columns,
79
+ ...i.config === void 0 ? {} : { config: i.config },
80
+ ...i.weights === void 0 ? {} : { weights: i.weights }
81
+ };
82
+ }, w = (e) => ({
83
+ descriptor: e,
84
+ where(t) {
85
+ let n = e.predicate ? { and: [e.predicate, t] } : t;
86
+ return w({
87
+ ...e,
88
+ predicate: n
89
+ });
90
+ },
91
+ orderBy(t, n = "asc") {
92
+ return w({
93
+ ...e,
94
+ order: [...e.order, {
95
+ column: t,
96
+ direction: n
97
+ }]
98
+ });
99
+ },
100
+ limit(t) {
101
+ return w({
102
+ ...e,
103
+ take: t
104
+ });
105
+ },
106
+ offset(t) {
107
+ return w({
108
+ ...e,
109
+ skip: t
110
+ });
111
+ },
112
+ select(...t) {
113
+ return w({
114
+ ...e,
115
+ projection: t
116
+ });
117
+ },
118
+ using(t) {
119
+ return w({
120
+ ...e,
121
+ usingIndex: t
122
+ });
123
+ },
124
+ withDeleted() {
125
+ return w({
126
+ ...e,
127
+ includeDeleted: !0
128
+ });
129
+ },
130
+ forUpdate() {
131
+ return w({
132
+ ...e,
133
+ lock: "update"
134
+ });
135
+ },
136
+ forShare() {
137
+ return w({
138
+ ...e,
139
+ lock: "share"
140
+ });
141
+ },
142
+ unscoped() {
143
+ return w({
144
+ ...e,
145
+ crossTenant: !0
146
+ });
147
+ },
148
+ with(t) {
149
+ let n = {
150
+ ...e.eager ?? {},
151
+ ...t
152
+ };
153
+ return w({
154
+ ...e,
155
+ eager: n
156
+ });
157
+ },
158
+ count() {
159
+ return w({
160
+ ...e,
161
+ projection: void 0,
162
+ aggregations: [{
163
+ op: "count",
164
+ alias: "count"
165
+ }]
166
+ });
167
+ },
168
+ aggregate(t) {
169
+ let n = Object.entries(t).map(([e, t]) => ({
170
+ ...t,
171
+ alias: e
172
+ }));
173
+ return w({
174
+ ...e,
175
+ projection: void 0,
176
+ aggregations: n
177
+ });
178
+ },
179
+ matching(t, n, r) {
180
+ let i = C(e.table, t, e.fullTextIndexes);
181
+ return w({
182
+ ...e,
183
+ fullTextSearch: {
184
+ indexName: t,
185
+ query: n,
186
+ columns: i.columns,
187
+ ...r?.prefix === !0 ? { prefix: !0 } : {},
188
+ ...i.config === void 0 ? {} : { config: i.config },
189
+ ...i.weights === void 0 ? {} : { weights: i.weights }
190
+ }
191
+ });
192
+ },
193
+ rankBy(t) {
194
+ let n = e.fullTextSearch;
195
+ if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
196
+ return w({
197
+ ...e,
198
+ fullTextSearch: {
199
+ ...n,
200
+ rank: {
201
+ alias: t?.alias ?? "rank",
202
+ order: t?.order ?? !0
203
+ }
204
+ }
205
+ });
206
+ },
207
+ nearestNeighbours(t, n, r) {
208
+ if (typeof t == "string" && Array.isArray(n)) {
209
+ let i = {
210
+ column: t,
211
+ queryVector: n,
212
+ distance: r?.distance ?? "cosine",
213
+ ...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
214
+ };
215
+ return w({
216
+ ...e,
217
+ annClause: i
218
+ });
219
+ }
220
+ if (typeof t == "string" && typeof n == "number") {
221
+ let r = {
222
+ column: "",
223
+ queryText: t,
224
+ distance: "cosine",
225
+ ...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
226
+ };
227
+ return w({
228
+ ...e,
229
+ annClause: r,
230
+ take: n
231
+ });
232
+ }
233
+ throw Error("nearestNeighbours: call as (column, queryVector, options?) or (queryString, k).");
234
+ },
235
+ efSearch(t) {
236
+ let n = e.annClause ?? {
237
+ column: "",
238
+ distance: "cosine"
239
+ };
240
+ return w({
241
+ ...e,
242
+ annClause: {
243
+ ...n,
244
+ ef: t
245
+ }
246
+ });
247
+ },
248
+ use(t) {
249
+ return w({ ...t(e) });
250
+ },
251
+ distinct() {
252
+ return w({
253
+ ...e,
254
+ distinct: !0
255
+ });
256
+ },
257
+ distinctOn(t) {
258
+ return w({
259
+ ...e,
260
+ distinctOn: [...t]
261
+ });
262
+ },
263
+ as(t) {
264
+ return w({
265
+ ...e,
266
+ alias: t
267
+ });
268
+ },
269
+ innerJoin(t, n, r) {
270
+ let i = typeof t == "string" ? t : t.tableName, a = [...e.joins ?? [], {
271
+ kind: "inner",
272
+ table: i,
273
+ alias: n,
274
+ on: r,
275
+ ...typeof t == "string" ? {} : { sourceTable: t }
276
+ }];
277
+ return w({
278
+ ...e,
279
+ joins: a
280
+ });
281
+ },
282
+ leftJoin(t, n, r) {
283
+ let i = typeof t == "string" ? t : t.tableName, a = [...e.joins ?? [], {
284
+ kind: "left",
285
+ table: i,
286
+ alias: n,
287
+ on: r,
288
+ ...typeof t == "string" ? {} : { sourceTable: t }
289
+ }];
290
+ return w({
291
+ ...e,
292
+ joins: a
293
+ });
294
+ },
295
+ selectJoined(t) {
296
+ let n = Object.entries(t).map(([e, t]) => ({
297
+ outputKey: e,
298
+ source: t
299
+ }));
300
+ return w({
301
+ ...e,
302
+ projection: void 0,
303
+ joinedProjection: n
304
+ });
305
+ },
306
+ withCte(t, n) {
307
+ let r = e.ctes ?? [];
308
+ if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
309
+ return w({
310
+ ...e,
311
+ ctes: [...r, {
312
+ name: t,
313
+ descriptor: n
314
+ }]
315
+ });
316
+ },
317
+ recursiveCte(t, n) {
318
+ let r = e.ctes ?? [];
319
+ if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
320
+ return w({
321
+ ...e,
322
+ ctes: [...r, {
323
+ name: t,
324
+ descriptor: n,
325
+ recursive: !0
326
+ }]
327
+ });
328
+ },
329
+ groupBy(t) {
330
+ let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
331
+ return w({
332
+ ...e,
333
+ groupBy: n
334
+ });
335
+ },
336
+ having(t) {
337
+ let n = e.having ? { and: [e.having, t] } : t;
338
+ return w({
339
+ ...e,
340
+ having: n
341
+ });
342
+ },
343
+ exists() {
344
+ return w({
345
+ ...e,
346
+ projection: void 0,
347
+ aggregations: [{
348
+ op: "count",
349
+ alias: "__exists__"
350
+ }],
351
+ take: 1
352
+ });
353
+ }
354
+ });
355
+ function T(e) {
356
+ return w({
357
+ table: e.tableName,
358
+ predicate: void 0,
359
+ order: [],
360
+ take: void 0,
361
+ skip: void 0,
362
+ projection: void 0,
363
+ fullTextIndexes: e.appliedFullText,
364
+ sourceTable: e
365
+ });
366
+ }
367
+ var E = (e, t, n) => D(e, "id", t, n), D = (e, t, n, r, i = "asc") => {
368
+ let a = [...e.order.filter((e) => e.column !== t), {
369
+ column: t,
370
+ direction: i
371
+ }], o = n === void 0 ? void 0 : {
372
+ column: t,
373
+ op: i === "desc" ? "lt" : "gt",
374
+ value: n
375
+ }, s = o === void 0 ? e.predicate : e.predicate === void 0 ? o : { and: [e.predicate, o] };
376
+ return {
377
+ ...e,
378
+ predicate: s,
379
+ order: a,
380
+ take: r
381
+ };
382
+ }, O = (e) => {
383
+ let n = {};
384
+ for (let [r, i] of Object.entries(e)) t(i), n[r] = T(i);
385
+ return n;
386
+ };
387
+ //#endregion
388
+ export { o as avg, S as avgOver, l as column, r as count, i as countDistinct, O as databaseHandle, v as denseRank, m as except, p as intersect, y as lag, b as lead, c as max, s as min, n as orderClausesOf, D as paginateBy, E as paginateById, T as queryFor, _ as rank, C as resolveFullTextIndex, g as rowNumber, a as sum, x as sumOver, d as union, f as unionAll };