@voltro/database 0.85.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 (169) hide show
  1. package/CHANGELOG.md +666 -0
  2. package/THIRD-PARTY-NOTICES.md +5 -33
  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 +18 -7
  33. package/dist/index.js +81 -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 +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-CG2j7J3f.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 +27 -6
  129. package/dist/sql.js +41 -6905
  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.js +6 -2
  166. package/dist/writeAttribution.js +16 -0
  167. package/dist/writeRecorder.js +37 -0
  168. package/package.json +3 -3
  169. package/dist/replaceInProgress-DC88Pdiy.js +0 -3735
@@ -1,42 +1,14 @@
1
1
  # Third-Party Notices — @voltro/database
2
2
 
3
- This package depends on the open-source software listed below. Each is the
3
+ This package uses the open-source software listed below. Each is the
4
4
  property of its respective copyright holders and is used under the terms of
5
5
  its license. This file is provided for attribution; it grants no rights in
6
6
  @voltro/database itself, which is proprietary (see LICENSE).
7
7
 
8
- Generated from the resolved runtime dependency closure (4 packages).
8
+ Generated from the resolved runtime dependency closure (3 packages).
9
9
 
10
10
  ---
11
11
 
12
- ## layerr@3.0.0
13
-
14
- License: MIT
15
-
16
- ```
17
- MIT License
18
-
19
- Copyright (c) 2020 Perry Mitchell
20
-
21
- Permission is hereby granted, free of charge, to any person obtaining a copy
22
- of this software and associated documentation files (the "Software"), to deal
23
- in the Software without restriction, including without limitation the rights
24
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
- copies of the Software, and to permit persons to whom the Software is
26
- furnished to do so, subject to the following conditions:
27
-
28
- The above copyright notice and this permission notice shall be included in all
29
- copies or substantial portions of the Software.
30
-
31
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
- SOFTWARE.
38
- ```
39
-
40
12
  ## typeid-js@1.2.0
41
13
 
42
14
  License: Apache-2.0
@@ -245,14 +217,14 @@ Apache License
245
217
  limitations under the License.
246
218
  ```
247
219
 
248
- ## ulidx@2.4.1
220
+ ## ulid@3.0.2
249
221
 
250
222
  License: MIT
251
223
 
252
224
  ```
253
- MIT License
225
+ The MIT License (MIT)
254
226
 
255
- Copyright (c) 2021 Perry Mitchell
227
+ Copyright (c) 2017 Alizain Feerasta
256
228
 
257
229
  Permission is hereby granted, free of charge, to any person obtaining a copy
258
230
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,24 @@
1
+ import { eq as e } from "./predicate.js";
2
+ //#region src/actorSnapshot.ts
3
+ var t = (e) => typeof e == "string" && e !== "" ? e : null, n = async (n, r, i) => {
4
+ if (r != null && r !== "") try {
5
+ let a = (await n.query({
6
+ table: "actors",
7
+ predicate: e("id", r),
8
+ order: [],
9
+ take: 1,
10
+ skip: void 0,
11
+ projection: void 0
12
+ }))[0];
13
+ return a === void 0 ? void 0 : {
14
+ id: r,
15
+ type: t(a.kind) ?? i,
16
+ displayName: t(a.displayName),
17
+ email: t(a.email)
18
+ };
19
+ } catch {
20
+ return;
21
+ }
22
+ };
23
+ //#endregion
24
+ export { n as resolveActorSnapshot };
@@ -0,0 +1,32 @@
1
+ //#region src/arrayCodec.ts
2
+ var e = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", t = (e) => {
3
+ let t = [];
4
+ for (let [n, r] of Object.entries(e.fields)) r.type === "array" && t.push(n);
5
+ return t;
6
+ }, n = (n, r, i) => {
7
+ if (!e(i) || !r) return n;
8
+ let a = t(r);
9
+ if (a.length === 0) return n;
10
+ let o = { ...n };
11
+ for (let e of a) {
12
+ let t = o[e];
13
+ Array.isArray(t) && (o[e] = JSON.stringify(t));
14
+ }
15
+ return o;
16
+ }, r = (n, r, i) => {
17
+ if (!e(i) || !r) return n;
18
+ let a = t(r);
19
+ return a.length === 0 ? n : n.map((e) => {
20
+ let t;
21
+ for (let n of a) {
22
+ let r = e[n];
23
+ if (r != null && !Array.isArray(r) && typeof r == "string") try {
24
+ let i = JSON.parse(r);
25
+ Array.isArray(i) && (t ||= { ...e }, t[n] = i);
26
+ } catch {}
27
+ }
28
+ return t ?? e;
29
+ });
30
+ };
31
+ //#endregion
32
+ export { r as deserializeArraysOnRead, n as serializeArraysForWrite };
@@ -0,0 +1,92 @@
1
+ import { branchNamespaceName as e, enforceBranchLimits as t, planBranch as n, planBranchTeardownFor as r, resolveBranchMechanism as i } from "./branching.js";
2
+ //#region src/branchExecute.ts
3
+ var a = async (t, r) => {
4
+ let a = e(t.appSlug, t.prNumber), o = i({
5
+ seed: t.seed,
6
+ ...t.dbUrl === void 0 ? {} : { dbUrl: t.dbUrl },
7
+ ...t.prefer === void 0 ? {} : { prefer: t.prefer }
8
+ }), s = n({
9
+ mechanism: o,
10
+ branchId: a,
11
+ tableNames: t.tableNames,
12
+ seed: t.seed,
13
+ ...t.parentNamespace === void 0 ? {} : { parentNamespace: t.parentNamespace },
14
+ ...t.foreignKeys === void 0 ? {} : { foreignKeys: t.foreignKeys },
15
+ ...t.indexNames === void 0 ? {} : { indexNames: t.indexNames },
16
+ ...t.neonParentBranch === void 0 ? {} : { neonParentBranch: t.neonParentBranch }
17
+ });
18
+ if (o === "neon-cow") return {
19
+ branchId: a,
20
+ mechanism: o,
21
+ steps: s,
22
+ connectionString: await r.neonBranchCreate(a, t.neonParentBranch ?? "main")
23
+ };
24
+ await r.createNamespace(a);
25
+ for (let e of t.tableNames) await r.createTable(a, e);
26
+ for (let e of t.indexNames ?? []) await r.restoreIndexName(a, e);
27
+ if (t.seed === "copy") {
28
+ if (t.parentNamespace === void 0 || t.parentNamespace === "") throw Error("provisionBranch: seed 'copy' requires parentNamespace");
29
+ for (let e of t.tableNames) await r.copyTable(t.parentNamespace, a, e);
30
+ }
31
+ for (let e of t.foreignKeys ?? []) await r.addForeignKey(a, e);
32
+ return {
33
+ branchId: a,
34
+ mechanism: o,
35
+ steps: s
36
+ };
37
+ }, o = async (e, t, n) => {
38
+ let i = r(t, e);
39
+ return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), i;
40
+ }, s = (e, n, r) => t(e, n, r), c = (e) => `"${e.replace(/"/g, "\"\"")}"`, l = {
41
+ cascade: "CASCADE",
42
+ restrict: "RESTRICT",
43
+ setNull: "SET NULL",
44
+ noAction: "NO ACTION"
45
+ }, u = (e) => `'${e.replace(/'/g, "''")}'`, d = (e, t) => {
46
+ let n = t.columns.map(u).join(", ");
47
+ return `DO $voltro_branch$
48
+ DECLARE derived name;
49
+ BEGIN
50
+ SELECT i.relname INTO derived
51
+ FROM pg_index x
52
+ JOIN pg_class i ON i.oid = x.indexrelid
53
+ JOIN pg_class c ON c.oid = x.indrelid
54
+ JOIN pg_namespace nsp ON nsp.oid = c.relnamespace
55
+ WHERE nsp.nspname = ${u(e)}
56
+ AND c.relname = ${u(t.table)}
57
+ AND NOT x.indisprimary
58
+ AND x.indisunique = ${t.unique ? "true" : "false"}
59
+ AND i.relname <> ${u(t.name)}
60
+ AND pg_get_expr(x.indpred, x.indrelid) IS NOT DISTINCT FROM ${t.where === void 0 ? "NULL" : u(t.where)}
61
+ AND (
62
+ SELECT array_agg(att.attname::text ORDER BY k.ord)
63
+ FROM unnest(x.indkey::int2[]) WITH ORDINALITY AS k(attnum, ord)
64
+ JOIN pg_attribute att ON att.attrelid = c.oid AND att.attnum = k.attnum
65
+ ) = ARRAY[${n}]::text[]
66
+ LIMIT 1;
67
+ IF derived IS NOT NULL THEN
68
+ EXECUTE format('ALTER INDEX %I.%I RENAME TO %I',
69
+ ${u(e)}, derived, ${u(t.name)});
70
+ END IF;
71
+ END
72
+ $voltro_branch$`;
73
+ }, f = (e, t) => {
74
+ let n = t.onDelete === void 0 ? "" : ` ON DELETE ${l[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${l[t.onUpdate]}`;
75
+ return `ALTER TABLE ${c(e)}.${c(t.table)} ADD FOREIGN KEY (${c(t.column)}) REFERENCES ${c(e)}.${c(t.targetTable)} (${c(t.targetColumn)})${n}${r}`;
76
+ }, p = (e) => {
77
+ let t = () => {
78
+ throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
79
+ };
80
+ return {
81
+ createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${c(t)}`),
82
+ createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${c(t)}.${c(n)} (LIKE ${c(n)} INCLUDING ALL)`),
83
+ copyTable: (t, n, r) => e.run(`INSERT INTO ${c(n)}.${c(r)} SELECT * FROM ${c(t)}.${c(r)}`),
84
+ addForeignKey: (t, n) => e.run(f(t, n)),
85
+ restoreIndexName: (t, n) => e.run(d(t, n)),
86
+ dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${c(t)} CASCADE`),
87
+ neonBranchCreate: t,
88
+ neonBranchDelete: t
89
+ };
90
+ };
91
+ //#endregion
92
+ export { s as admitBranch, p as makeNamespaceBranchExecutor, a as provisionBranch, o as teardownBranch };
@@ -0,0 +1,106 @@
1
+ import { sanitizeIdentifierFragment as e } from "./namespace.js";
2
+ //#region src/branching.ts
3
+ var t = 63, n = "br_pr", r = class extends Error {
4
+ _tag = "BranchNameInvalid";
5
+ constructor(e) {
6
+ super(e), this.name = "BranchNameInvalid";
7
+ }
8
+ }, i = (i, a) => {
9
+ if (!Number.isInteger(a) || a < 0) throw new r(`prNumber must be a non-negative integer, got ${String(a)}`);
10
+ let o = e(i);
11
+ if (o.replace(/_/g, "") === "") throw new r(`app slug '${i}' has no usable identifier characters`);
12
+ let s = `${n}${a}_${o}`;
13
+ if (s.length > t) throw new r(`branch namespace '${s}' exceeds the ${t}-byte identifier limit — use a shorter app slug`);
14
+ return s;
15
+ }, a = (e) => e.startsWith(n), o = {
16
+ requested: {
17
+ provision: "provisioning",
18
+ destroy: "destroying"
19
+ },
20
+ provisioning: {
21
+ provisioned: "ready",
22
+ fail: "failed"
23
+ },
24
+ ready: { destroy: "destroying" },
25
+ failed: {
26
+ provision: "provisioning",
27
+ destroy: "destroying"
28
+ },
29
+ destroying: {
30
+ destroyed: "destroyed",
31
+ fail: "failed"
32
+ },
33
+ destroyed: {}
34
+ }, s = class extends Error {
35
+ from;
36
+ event;
37
+ _tag = "BranchTransitionInvalid";
38
+ constructor(e, t) {
39
+ super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
40
+ }
41
+ }, c = (e, t) => {
42
+ let n = o[e][t];
43
+ if (n === void 0) throw new s(e, t);
44
+ return n;
45
+ }, l = (e, t, n, i, a = [], o = []) => {
46
+ if (n === "copy" && (i === void 0 || i === "")) throw new r("seed 'copy' requires a parentNamespace to snapshot from");
47
+ let s = [{
48
+ kind: "create-namespace",
49
+ detail: e
50
+ }];
51
+ for (let n of t) s.push({
52
+ kind: "create-table",
53
+ table: n,
54
+ detail: `${e}.${n}`
55
+ });
56
+ for (let t of o) s.push({
57
+ kind: "restore-index-name",
58
+ table: t.table,
59
+ detail: `${e}.${t.table} ${t.unique ? "UNIQUE " : ""}(${t.columns.join(", ")}) → ${t.name}`
60
+ });
61
+ if (n === "copy") for (let n of t) s.push({
62
+ kind: "copy-table",
63
+ table: n,
64
+ detail: `${i}.${n} → ${e}.${n}`
65
+ });
66
+ for (let t of a) s.push({
67
+ kind: "copy-foreign-key",
68
+ table: t.table,
69
+ detail: `${e}.${t.table}.${t.column} → ${e}.${t.targetTable}.${t.targetColumn}`
70
+ });
71
+ return n === "fresh" && s.push({
72
+ kind: "seed",
73
+ detail: `run boot seeds into ${e}`
74
+ }), s;
75
+ }, u = (e) => {
76
+ if (!a(e)) throw new r(`refusing to plan teardown of '${e}' — not a branch namespace`);
77
+ return [{
78
+ kind: "drop-namespace",
79
+ detail: e
80
+ }];
81
+ }, d = (e) => {
82
+ if (e === void 0 || e === "") return !1;
83
+ try {
84
+ let t = new URL(e).hostname.toLowerCase();
85
+ return /(^|\.)neon\.(tech|build)$/.test(t);
86
+ } catch {
87
+ return /\bneon\.(tech|build)\b/i.test(e);
88
+ }
89
+ }, f = (e) => e.prefer === void 0 ? e.seed === "copy" && d(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, p = (e, t = {}) => [{
90
+ kind: "neon-branch-create",
91
+ detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
92
+ }], m = (e) => {
93
+ if (!a(e)) throw new r(`refusing to plan teardown of '${e}' — not a branch namespace`);
94
+ return [{
95
+ kind: "neon-branch-delete",
96
+ detail: e
97
+ }];
98
+ }, h = (e) => e.mechanism === "neon-cow" ? p(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : l(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), g = (e, t) => e === "neon-cow" ? m(t) : u(t), _ = (e, t, n) => {
99
+ let r = e.filter((e) => e.state !== "destroyed" && e.state !== "destroying"), i = r.filter((e) => n - e.createdAtMs > t.ttlMs).map((e) => e.namespace), a = new Set(i);
100
+ return {
101
+ evict: i,
102
+ rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
103
+ };
104
+ };
105
+ //#endregion
106
+ export { r as BranchNameInvalid, s as BranchTransitionInvalid, i as branchNamespaceName, _ as enforceBranchLimits, a as isBranchNamespace, d as isNeonConnection, c as nextBranchState, h as planBranch, l as planBranchProvision, u as planBranchTeardown, g as planBranchTeardownFor, p as planNeonBranchProvision, m as planNeonBranchTeardown, f as resolveBranchMechanism };
@@ -0,0 +1,25 @@
1
+ //#region src/bulkInsertLimits.ts
2
+ var e = {
3
+ postgres: { maxBindParameters: 32767 },
4
+ mysql: { maxBindParameters: 65535 },
5
+ mariadb: { maxBindParameters: 65535 },
6
+ mssql: {
7
+ maxBindParameters: 2098,
8
+ maxRowsPerStatement: 1e3
9
+ },
10
+ sqlite: { maxBindParameters: 32766 },
11
+ turso: { maxBindParameters: 32766 }
12
+ }, t = (t) => e[t], n = (e) => {
13
+ let t = /* @__PURE__ */ new Set();
14
+ for (let n of e) for (let e of Object.keys(n)) t.add(e);
15
+ return t.size;
16
+ }, r = (e, t) => {
17
+ if (t === void 0 || e.length === 0) return [e];
18
+ let r = Math.max(1, n(e)), i = Math.floor(t.maxBindParameters / r), a = t.maxRowsPerStatement ?? Infinity, o = Math.max(1, Math.min(i, a));
19
+ if (e.length <= o) return [e];
20
+ let s = [];
21
+ for (let t = 0; t < e.length; t += o) s.push(e.slice(t, t + o));
22
+ return s;
23
+ };
24
+ //#endregion
25
+ export { e as BULK_INSERT_LIMITS, t as bulkInsertLimitsFor, r as chunkRowsForInsert, n as columnsPerRow };
@@ -0,0 +1,19 @@
1
+ import { id as e, text as t, timestamp as n } from "./columns.js";
2
+ import { table as r } from "./table.js";
3
+ //#region src/cdcOffsetsTables.ts
4
+ var i = "_voltro_cdc_offsets", a = r(i, {
5
+ id: e({ prefix: "cdcoff" }),
6
+ replicaId: t(),
7
+ streamName: t(),
8
+ binlogFile: t(),
9
+ binlogPosition: t(),
10
+ updatedAt: n()
11
+ }).index(["replicaId"]), o = r(i, {
12
+ id: e({ prefix: "cdcoff" }),
13
+ replicaId: t(),
14
+ streamName: t(),
15
+ ctVersion: t(),
16
+ updatedAt: n()
17
+ }).index(["replicaId"]);
18
+ //#endregion
19
+ export { i as CDC_OFFSETS_TABLE, a as _voltroCdcOffsetsTable, o as _voltroMssqlCdcOffsetsTable };
@@ -0,0 +1,41 @@
1
+ //#region src/changeEvent.ts
2
+ var e = (e, t) => ({
3
+ ...t,
4
+ ...e,
5
+ origin: e.origin ?? "injected"
6
+ }), t = (e, t, n = {}) => ({
7
+ table: e,
8
+ op: "insert",
9
+ old: null,
10
+ new: t,
11
+ ...n
12
+ }), n = (e, t, n, r = {}) => ({
13
+ table: e,
14
+ op: "update",
15
+ old: t,
16
+ new: n,
17
+ ...r
18
+ }), r = (e, t, n = {}) => ({
19
+ table: e,
20
+ op: "delete",
21
+ old: t,
22
+ new: null,
23
+ ...n
24
+ }), i = (e, t, n = {}) => {
25
+ let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
26
+ return {
27
+ table: e,
28
+ op: "update",
29
+ old: {
30
+ ...t,
31
+ [i]: null
32
+ },
33
+ new: {
34
+ ...t,
35
+ [i]: r
36
+ },
37
+ ...a
38
+ };
39
+ };
40
+ //#endregion
41
+ export { r as changeDelete, t as changeInsert, i as changeSoftDelete, n as changeUpdate, e as externalChangeEvent };
@@ -0,0 +1,65 @@
1
+ import { createHash as e } from "node:crypto";
2
+ //#region src/changeIdentity.ts
3
+ var t = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(t).join(",")}]` : typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, n]) => `${JSON.stringify(e)}:${t(n)}`).join(",")}}` : JSON.stringify(e) ?? "null", n = (n) => e("sha256").update([
4
+ n.pipe,
5
+ n.op,
6
+ n.key,
7
+ t(n.next),
8
+ t(n.prev)
9
+ ].join("\0")).digest("hex").slice(0, 32), r = (e, t) => `${e}:${t}`, i = (e) => {
10
+ let t = e.lastIndexOf(":");
11
+ if (t <= 0) return null;
12
+ let n = Number(e.slice(t + 1));
13
+ return !Number.isInteger(n) || n < 0 ? null : {
14
+ digest: e.slice(0, t),
15
+ occurrence: n
16
+ };
17
+ }, a = class {
18
+ #e = /* @__PURE__ */ new Map();
19
+ #t;
20
+ #n;
21
+ constructor(e) {
22
+ this.#t = e.windowMs, this.#n = Math.max(1, e.maxEntries);
23
+ }
24
+ get size() {
25
+ return this.#e.size;
26
+ }
27
+ next(e, t) {
28
+ let n = this.#e.get(e);
29
+ if (n === void 0) return this.#e.set(e, {
30
+ count: 1,
31
+ lastMs: t
32
+ }), this.#r(), 0;
33
+ n.lastMs = t;
34
+ let r = n.count;
35
+ return n.count += 1, this.#e.delete(e), this.#e.set(e, n), r;
36
+ }
37
+ seedFromChangeKeys(e, t) {
38
+ for (let n of e) {
39
+ let e = i(n);
40
+ if (e === null) continue;
41
+ let r = this.#e.get(e.digest), a = Math.max(r?.count ?? 0, e.occurrence + 1);
42
+ this.#e.set(e.digest, {
43
+ count: a,
44
+ lastMs: r?.lastMs ?? t
45
+ });
46
+ }
47
+ this.#r();
48
+ }
49
+ prune(e) {
50
+ let t = e - this.#t;
51
+ for (let [e, n] of this.#e) n.lastMs < t && this.#e.delete(e);
52
+ }
53
+ #r() {
54
+ for (; this.#e.size > this.#n;) {
55
+ let e = this.#e.keys().next();
56
+ if (e.done === !0) return;
57
+ this.#e.delete(e.value);
58
+ }
59
+ }
60
+ }, o = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", s = 1, c = (e = process.env) => {
61
+ let t = Number(e[o]);
62
+ return (Number.isFinite(t) && t > 0 ? t : 1) * 2 * 36e5;
63
+ };
64
+ //#endregion
65
+ export { o as CHANGE_CLAIM_TTL_ENV, s as DEFAULT_CHANGE_CLAIM_TTL_HOURS, a as OccurrenceCounter, t as canonicalJson, n as changeDigest, r as composeChangeKey, c as occurrenceWindowMs, i as parseChangeKey };
@@ -0,0 +1,6 @@
1
+ //#region src/changeListenerCeiling.ts
2
+ var e = 512, t = (e) => {
3
+ e.setMaxListeners(512);
4
+ };
5
+ //#endregion
6
+ export { e as CHANGE_LISTENER_CEILING, t as raiseChangeListenerCeiling };
@@ -0,0 +1,17 @@
1
+ //#region src/columnReference.ts
2
+ var e = (e) => {
3
+ if (e.length === 0) throw RangeError("Column reference must not be empty");
4
+ return {
5
+ _tag: "ColumnReference",
6
+ column: e
7
+ };
8
+ }, t = (e) => typeof e == "object" && !!e && "_tag" in e && e._tag === "ColumnReference" && "column" in e && typeof e.column == "string", n = [
9
+ "eq",
10
+ "neq",
11
+ "gt",
12
+ "gte",
13
+ "lt",
14
+ "lte"
15
+ ];
16
+ //#endregion
17
+ export { n as columnComparisonOperators, e as columnRef, t as isColumnReference };