@voltro/database 0.84.0 → 0.86.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 (170) hide show
  1. package/CHANGELOG.md +1215 -0
  2. package/THIRD-PARTY-NOTICES.md +5 -89
  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 +22 -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 +98 -0
  27. package/dist/frameworkTables.js +130 -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 +122 -64
  33. package/dist/index.js +81 -2080
  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 +624 -0
  43. package/dist/migration.js +18 -0
  44. package/dist/migrations/appliedAtValue.js +8 -0
  45. package/dist/migrations/applier.js +1085 -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/declaredSchema.js +162 -0
  51. package/dist/migrations/deployLedger.js +19 -0
  52. package/dist/migrations/fileBased.js +57 -0
  53. package/dist/migrations/fileContext.js +482 -0
  54. package/dist/migrations/fileDiscovery.js +318 -0
  55. package/dist/migrations/fileSkipProbes.js +117 -0
  56. package/dist/migrations/fingerprint.js +46 -0
  57. package/dist/migrations/fkCycles.js +13 -0
  58. package/dist/migrations/frameworkLiveTables.js +25 -0
  59. package/dist/migrations/idempotentDdl.js +37 -0
  60. package/dist/migrations/indexPredicate.js +50 -0
  61. package/dist/migrations/introspect.js +799 -0
  62. package/dist/migrations/ledgerRows.js +4 -0
  63. package/dist/migrations/lock.js +91 -0
  64. package/dist/migrations/migrationTableExists.js +9 -0
  65. package/dist/migrations/mssqlColumnDependencies.js +76 -0
  66. package/dist/migrations/mysqlEngine.js +11 -0
  67. package/dist/migrations/namespaceCharset.js +51 -0
  68. package/dist/migrations/planner.js +775 -0
  69. package/dist/migrations/postgresEnumCheck.js +19 -0
  70. package/dist/migrations/reactiveTriggerDrift.js +58 -0
  71. package/dist/migrations/reactiveTriggerName.js +7 -0
  72. package/dist/migrations/renameMssqlCheck.js +21 -0
  73. package/dist/migrations/restoreSnapshots.js +206 -0
  74. package/dist/migrations/resumeLedger.js +86 -0
  75. package/dist/migrations/rollingDeploy.js +106 -0
  76. package/dist/migrations/schemaOwner.js +46 -0
  77. package/dist/migrations/schemaOwnerTable.js +4 -0
  78. package/dist/migrations/softDropSnapshot.js +20 -0
  79. package/dist/migrations/sqlLimit.js +8 -0
  80. package/dist/migrations/sqliteConstraintIdentity.js +97 -0
  81. package/dist/migrations/sqliteDecimalBoot.js +22 -0
  82. package/dist/migrations/sqliteDecimalPublication.js +257 -0
  83. package/dist/migrations/sqliteDecimalReview.js +30 -0
  84. package/dist/migrations/sqliteDecimalReviewStore.js +188 -0
  85. package/dist/migrations/sqliteDecimalReviewWitness.js +38 -0
  86. package/dist/migrations/sqliteDecimalSource.js +69 -0
  87. package/dist/migrations/sqliteDecimalStage.js +135 -0
  88. package/dist/migrations/sqliteForeignKeys.js +38 -0
  89. package/dist/migrations/sqliteMigrationBatch.js +37 -0
  90. package/dist/migrations/sqliteRetainedSource.js +106 -0
  91. package/dist/migrations/sqliteRowIdentity.js +63 -0
  92. package/dist/migrations/sqliteSchemaEpoch.js +12 -0
  93. package/dist/migrations/sqliteSnapshotGuard.js +10 -0
  94. package/dist/migrations/sqliteTableContents.js +34 -0
  95. package/dist/migrations/sqliteTableCopy.js +25 -0
  96. package/dist/migrations/sqliteTableSchema.js +19 -0
  97. package/dist/migrations/sqliteWitnessProtection.js +8 -0
  98. package/dist/migrations/squash.js +81 -0
  99. package/dist/migrations/storeCharset.js +66 -0
  100. package/dist/migrations/transactionCause.js +10 -0
  101. package/dist/migrations/undeclaredCharset.js +40 -0
  102. package/dist/migrations/uniqueActiveLowering.js +39 -0
  103. package/dist/mixins.js +22 -0
  104. package/dist/mssqlDecimalDistinct.js +51 -0
  105. package/dist/mssqlJsonValueCheck.js +42 -0
  106. package/dist/mssqlTextStorage.js +9 -0
  107. package/dist/namespace.js +21 -0
  108. package/dist/{wire-B28cPjEp.js → optimisticVersion.js} +2 -2
  109. package/dist/pendingAttribution.js +79 -0
  110. package/dist/pluginRef.js +17 -0
  111. package/dist/predicate.js +266 -0
  112. package/dist/predicateCoercion.js +13 -0
  113. package/dist/projectedColumn.js +37 -0
  114. package/dist/queryBuilder.js +382 -0
  115. package/dist/rawSql.js +8 -0
  116. package/dist/relations.js +69 -0
  117. package/dist/relationsRegistry.js +38 -0
  118. package/dist/replaceInProgress.js +53 -0
  119. package/dist/requiredColumns.js +26 -0
  120. package/dist/residency.js +52 -0
  121. package/dist/retention.js +62 -0
  122. package/dist/rowDecoder.js +123 -0
  123. package/dist/rowKey.js +8 -0
  124. package/dist/rowSchema.js +31 -0
  125. package/dist/scopeKey.js +8 -0
  126. package/dist/seed.js +33 -0
  127. package/dist/snowflake.js +26 -0
  128. package/dist/sql.d.ts +58 -29
  129. package/dist/sql.js +41 -6661
  130. package/dist/sqlCompiler.js +343 -0
  131. package/dist/sqlError.js +8 -0
  132. package/dist/sqlPoolCapacity.js +12 -0
  133. package/dist/sqliteDecimal.js +22 -0
  134. package/dist/sqliteDecimalAggregateSql.js +61 -0
  135. package/dist/sqliteDecimalColumnSql.js +108 -0
  136. package/dist/sqliteDecimalConversion.js +15 -0
  137. package/dist/sqliteDecimalCte.js +154 -0
  138. package/dist/sqliteDecimalEncodeSql.js +32 -0
  139. package/dist/sqliteDecimalOutputs.js +74 -0
  140. package/dist/sqliteDecimalPredicate.js +66 -0
  141. package/dist/sqliteDecimalQuery.js +183 -0
  142. package/dist/sqliteDecimalQueryPlan.js +37 -0
  143. package/dist/sqliteDecimalResultSql.js +44 -0
  144. package/dist/sqliteDecimalRowQuery.js +63 -0
  145. package/dist/sqliteDecimalSetQuery.js +50 -0
  146. package/dist/sqliteDecimalSource.js +63 -0
  147. package/dist/sqliteDecimalStorage.js +29 -0
  148. package/dist/sqliteDecimalSubquery.js +19 -0
  149. package/dist/sqliteDecimalWindowQuery.js +196 -0
  150. package/dist/sqliteValueCoercion.js +4 -0
  151. package/dist/stampId.js +21 -0
  152. package/dist/storeErrors.js +9 -0
  153. package/dist/storeRefusal.js +20 -0
  154. package/dist/stream.js +36 -0
  155. package/dist/subjectGraph.js +175 -0
  156. package/dist/table.js +394 -0
  157. package/dist/tableRegistry.js +16 -0
  158. package/dist/tenantSelection.js +27 -0
  159. package/dist/transactionOutcome.js +97 -0
  160. package/dist/transientContention.js +36 -0
  161. package/dist/typedStore.js +16 -0
  162. package/dist/upsertUpdate.js +20 -0
  163. package/dist/vectorEmbedding.js +31 -0
  164. package/dist/view.js +39 -0
  165. package/dist/wire.d.ts +9 -10
  166. package/dist/wire.js +6 -2
  167. package/dist/writeAttribution.js +16 -0
  168. package/dist/writeRecorder.js +37 -0
  169. package/package.json +4 -6
  170. package/dist/replaceInProgress-DUHl5JEz.js +0 -3557
@@ -0,0 +1,266 @@
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, n = null, r = {}) => z(e, t, n, r) === !0, L = (e, t = null, n = {}) => {
133
+ let r = /* @__PURE__ */ new Map(), i = (e) => {
134
+ if ("not" in e) {
135
+ i(e.not);
136
+ return;
137
+ }
138
+ if ("and" in e) {
139
+ e.and.forEach(i);
140
+ return;
141
+ }
142
+ if ("or" in e) {
143
+ e.or.forEach(i);
144
+ return;
145
+ }
146
+ if (e.op !== "in" && e.op !== "notIn" || n[e.column]?.type === "decimal") return;
147
+ let t = Object.getOwnPropertyDescriptor(e, "value");
148
+ if (t === void 0 || !("value" in t)) return;
149
+ let a = t.value;
150
+ if (!Array.isArray(a) || a.length < 16 || Object.getPrototypeOf(a) !== Array.prototype) return;
151
+ let o = Object.getOwnPropertyDescriptor(a, "some");
152
+ if (o !== void 0 && (!("value" in o) || o.value !== Array.prototype.some)) return;
153
+ for (let e = 0; e < a.length; e++) {
154
+ let t = Object.getOwnPropertyDescriptor(a, e);
155
+ if (t !== void 0 && !("value" in t)) return;
156
+ }
157
+ if (a.some((e) => typeof e == "object" && !!e)) return;
158
+ let s = Array.prototype.filter.call(a, (e) => !(typeof e == "number" && Number.isNaN(e)));
159
+ r.set(e, new Set(s));
160
+ };
161
+ return i(e), (i) => z(e, i, t, n, r) === !0;
162
+ }, R = (e, t, n) => {
163
+ 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;
164
+ for (let n of [e, t]) for (let e = 0; e < n.length; e += 1) {
165
+ let t = Object.getOwnPropertyDescriptor(n, String(e));
166
+ if (t === void 0 || !("value" in t)) return;
167
+ }
168
+ let r = /* @__PURE__ */ new Set();
169
+ for (let t = 0; t < e.length; t += 1) r.add(e[t]);
170
+ return r;
171
+ }, z = (t, a, o = null, s = {}, c) => {
172
+ if (!a) return !1;
173
+ if ("not" in t) {
174
+ let e = z(t.not, a, o, s, c);
175
+ return e === null ? null : !e;
176
+ }
177
+ if ("and" in t) {
178
+ let e = !1;
179
+ for (let n of t.and) {
180
+ let t = z(n, a, o, s, c);
181
+ if (t === !1) return !1;
182
+ t === null && (e = !0);
183
+ }
184
+ return !e || null;
185
+ }
186
+ if ("or" in t) {
187
+ let e = !1;
188
+ for (let n of t.or) {
189
+ let t = z(n, a, o, s, c);
190
+ if (t === !0) return !0;
191
+ t === null && (e = !0);
192
+ }
193
+ return e ? null : !1;
194
+ }
195
+ if (t.op === "subquery-in" || t.op === "subquery-not-in") {
196
+ if (!o) return !1;
197
+ let e = o.get(t.subquery);
198
+ if (!(e instanceof Set)) return !1;
199
+ let n = a[t.column], r = s[t.column]?.type === "decimal" ? [...e].some((e) => i(n, e) === 0) : e.has(n);
200
+ return t.op === "subquery-in" ? r : !r;
201
+ }
202
+ if (t.op === "exists" || t.op === "not-exists") {
203
+ if (!o) return !1;
204
+ let e = o.get(t.subquery), n = typeof e == "number" ? e > 0 : e instanceof Set && e.size > 0;
205
+ return t.op === "exists" ? n : !n;
206
+ }
207
+ let l = t, u = a[l.column], d = n(l.value) ? l.value : void 0;
208
+ 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");
209
+ let f = d === void 0 ? l.value : a[d.column];
210
+ if (d !== void 0 && (u == null || f == null)) return null;
211
+ let p = s[l.column]?.type === "decimal", m = c?.get(t);
212
+ if (m !== void 0 && !(u instanceof Date) && !(u instanceof Uint8Array)) {
213
+ let e = typeof u == "number" && Number.isNaN(u) ? !1 : m.has(u);
214
+ return l.op === "in" ? e : !e;
215
+ }
216
+ let h = (e, t) => p && e != null && t != null ? i(e, t) === 0 : P(e, t), g = p ? i : F;
217
+ switch (l.op) {
218
+ case "eq": return h(u, f);
219
+ case "neq": return !h(u, f);
220
+ case "gt": return (g(u, f) ?? -1) > 0;
221
+ case "gte": return (g(u, f) ?? -1) >= 0;
222
+ case "lt": return (g(u, f) ?? 1) < 0;
223
+ case "lte": return (g(u, f) ?? 1) <= 0;
224
+ case "in": return Array.isArray(f) && f.some((e) => h(u, e));
225
+ case "notIn": return Array.isArray(f) && !f.some((e) => h(u, e));
226
+ case "contains": return typeof u == "string" && typeof f == "string" && u.toLowerCase().includes(f.toLowerCase());
227
+ case "startsWith": return typeof u == "string" && typeof f == "string" && u.startsWith(f);
228
+ case "arrayContains": {
229
+ let e = Array.isArray(u) ? u : [], t = Array.isArray(f) ? f : [];
230
+ if (e.length < 128 || t.length < 16) return t.every((t) => e.includes(t));
231
+ let n, r = 0;
232
+ return t.every((i) => (++r === 5 && (n = R(e, t, "every")), n === void 0 ? e.includes(i) : n.has(i)));
233
+ }
234
+ case "arrayOverlaps": {
235
+ let e = Array.isArray(u) ? u : [], t = Array.isArray(f) ? f : [];
236
+ if (e.length < 128 || t.length < 16) return t.some((t) => e.includes(t));
237
+ let n, r = 0;
238
+ return t.some((i) => (++r === 5 && (n = R(e, t, "some")), n === void 0 ? e.includes(i) : n.has(i)));
239
+ }
240
+ case "arrayHas": return Array.isArray(u) && u.includes(f);
241
+ case "isNull": return u == null;
242
+ case "isNotNull": return u != null;
243
+ 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.");
244
+ }
245
+ }, B = function* (e) {
246
+ if ("not" in e) yield* B(e.not);
247
+ else if ("and" in e) for (let t of e.and) yield* B(t);
248
+ else if ("or" in e) for (let t of e.or) yield* B(t);
249
+ else e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
250
+ kind: "in",
251
+ descriptor: e.subquery
252
+ } : (e.op === "exists" || e.op === "not-exists") && (yield {
253
+ kind: "exists",
254
+ descriptor: e.subquery
255
+ });
256
+ }, V = function* (e, t = !0) {
257
+ if ("not" in e) yield* V(e.not, !1);
258
+ else if ("and" in e) for (let n of e.and) yield* V(n, t);
259
+ else if ("or" in e) for (let t of e.or) yield* V(t, !1);
260
+ else e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
261
+ ...e,
262
+ conjunctive: t && !n(e.value)
263
+ });
264
+ };
265
+ //#endregion
266
+ export { v as MATCHES_NO_ROWS, S as and, h as arrayContains, _ as arrayHas, g as arrayOverlaps, B as collectSubqueries, t as columnRef, p as contains, a as eq, I 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, L as preparePredicate, x as spatialPredicate, m as startsWith, V 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,382 @@
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
+ unscoped() {
137
+ return w({
138
+ ...e,
139
+ crossTenant: !0
140
+ });
141
+ },
142
+ with(t) {
143
+ let n = {
144
+ ...e.eager ?? {},
145
+ ...t
146
+ };
147
+ return w({
148
+ ...e,
149
+ eager: n
150
+ });
151
+ },
152
+ count() {
153
+ return w({
154
+ ...e,
155
+ projection: void 0,
156
+ aggregations: [{
157
+ op: "count",
158
+ alias: "count"
159
+ }]
160
+ });
161
+ },
162
+ aggregate(t) {
163
+ let n = Object.entries(t).map(([e, t]) => ({
164
+ ...t,
165
+ alias: e
166
+ }));
167
+ return w({
168
+ ...e,
169
+ projection: void 0,
170
+ aggregations: n
171
+ });
172
+ },
173
+ matching(t, n, r) {
174
+ let i = C(e.table, t, e.fullTextIndexes);
175
+ return w({
176
+ ...e,
177
+ fullTextSearch: {
178
+ indexName: t,
179
+ query: n,
180
+ columns: i.columns,
181
+ ...r?.prefix === !0 ? { prefix: !0 } : {},
182
+ ...i.config === void 0 ? {} : { config: i.config },
183
+ ...i.weights === void 0 ? {} : { weights: i.weights }
184
+ }
185
+ });
186
+ },
187
+ rankBy(t) {
188
+ let n = e.fullTextSearch;
189
+ if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
190
+ return w({
191
+ ...e,
192
+ fullTextSearch: {
193
+ ...n,
194
+ rank: {
195
+ alias: t?.alias ?? "rank",
196
+ order: t?.order ?? !0
197
+ }
198
+ }
199
+ });
200
+ },
201
+ nearestNeighbours(t, n, r) {
202
+ if (typeof t == "string" && Array.isArray(n)) {
203
+ let i = {
204
+ column: t,
205
+ queryVector: n,
206
+ distance: r?.distance ?? "cosine",
207
+ ...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
208
+ };
209
+ return w({
210
+ ...e,
211
+ annClause: i
212
+ });
213
+ }
214
+ if (typeof t == "string" && typeof n == "number") {
215
+ let r = {
216
+ column: "",
217
+ queryText: t,
218
+ distance: "cosine",
219
+ ...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
220
+ };
221
+ return w({
222
+ ...e,
223
+ annClause: r,
224
+ take: n
225
+ });
226
+ }
227
+ throw Error("nearestNeighbours: call as (column, queryVector, options?) or (queryString, k).");
228
+ },
229
+ efSearch(t) {
230
+ let n = e.annClause ?? {
231
+ column: "",
232
+ distance: "cosine"
233
+ };
234
+ return w({
235
+ ...e,
236
+ annClause: {
237
+ ...n,
238
+ ef: t
239
+ }
240
+ });
241
+ },
242
+ use(t) {
243
+ return w({ ...t(e) });
244
+ },
245
+ distinct() {
246
+ return w({
247
+ ...e,
248
+ distinct: !0
249
+ });
250
+ },
251
+ distinctOn(t) {
252
+ return w({
253
+ ...e,
254
+ distinctOn: [...t]
255
+ });
256
+ },
257
+ as(t) {
258
+ return w({
259
+ ...e,
260
+ alias: t
261
+ });
262
+ },
263
+ innerJoin(t, n, r) {
264
+ let i = typeof t == "string" ? t : t.tableName, a = [...e.joins ?? [], {
265
+ kind: "inner",
266
+ table: i,
267
+ alias: n,
268
+ on: r,
269
+ ...typeof t == "string" ? {} : { sourceTable: t }
270
+ }];
271
+ return w({
272
+ ...e,
273
+ joins: a
274
+ });
275
+ },
276
+ leftJoin(t, n, r) {
277
+ let i = typeof t == "string" ? t : t.tableName, a = [...e.joins ?? [], {
278
+ kind: "left",
279
+ table: i,
280
+ alias: n,
281
+ on: r,
282
+ ...typeof t == "string" ? {} : { sourceTable: t }
283
+ }];
284
+ return w({
285
+ ...e,
286
+ joins: a
287
+ });
288
+ },
289
+ selectJoined(t) {
290
+ let n = Object.entries(t).map(([e, t]) => ({
291
+ outputKey: e,
292
+ source: t
293
+ }));
294
+ return w({
295
+ ...e,
296
+ projection: void 0,
297
+ joinedProjection: n
298
+ });
299
+ },
300
+ withCte(t, n) {
301
+ let r = e.ctes ?? [];
302
+ if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
303
+ return w({
304
+ ...e,
305
+ ctes: [...r, {
306
+ name: t,
307
+ descriptor: n
308
+ }]
309
+ });
310
+ },
311
+ recursiveCte(t, n) {
312
+ let r = e.ctes ?? [];
313
+ if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
314
+ return w({
315
+ ...e,
316
+ ctes: [...r, {
317
+ name: t,
318
+ descriptor: n,
319
+ recursive: !0
320
+ }]
321
+ });
322
+ },
323
+ groupBy(t) {
324
+ let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
325
+ return w({
326
+ ...e,
327
+ groupBy: n
328
+ });
329
+ },
330
+ having(t) {
331
+ let n = e.having ? { and: [e.having, t] } : t;
332
+ return w({
333
+ ...e,
334
+ having: n
335
+ });
336
+ },
337
+ exists() {
338
+ return w({
339
+ ...e,
340
+ projection: void 0,
341
+ aggregations: [{
342
+ op: "count",
343
+ alias: "__exists__"
344
+ }],
345
+ take: 1
346
+ });
347
+ }
348
+ });
349
+ function T(e) {
350
+ return w({
351
+ table: e.tableName,
352
+ predicate: void 0,
353
+ order: [],
354
+ take: void 0,
355
+ skip: void 0,
356
+ projection: void 0,
357
+ fullTextIndexes: e.appliedFullText,
358
+ sourceTable: e
359
+ });
360
+ }
361
+ var E = (e, t, n) => D(e, "id", t, n), D = (e, t, n, r, i = "asc") => {
362
+ let a = [...e.order.filter((e) => e.column !== t), {
363
+ column: t,
364
+ direction: i
365
+ }], o = n === void 0 ? void 0 : {
366
+ column: t,
367
+ op: i === "desc" ? "lt" : "gt",
368
+ value: n
369
+ }, s = o === void 0 ? e.predicate : e.predicate === void 0 ? o : { and: [e.predicate, o] };
370
+ return {
371
+ ...e,
372
+ predicate: s,
373
+ order: a,
374
+ take: r
375
+ };
376
+ }, O = (e) => {
377
+ let n = {};
378
+ for (let [r, i] of Object.entries(e)) t(i), n[r] = T(i);
379
+ return n;
380
+ };
381
+ //#endregion
382
+ 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 };
package/dist/rawSql.js ADDED
@@ -0,0 +1,8 @@
1
+ //#region src/rawSql.ts
2
+ var e = (e, ...t) => ({
3
+ _tag: "RawSqlFragment",
4
+ strings: [...e],
5
+ values: [...t]
6
+ }), t = (e) => typeof e == "object" && !!e && e._tag === "RawSqlFragment";
7
+ //#endregion
8
+ export { t as isRawSqlFragment, e as sql };