@prisma-next/target-sqlite 0.12.0 → 0.13.0-dev.10

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 (126) hide show
  1. package/dist/{codec-ids-CYwMu3-4.d.mts → codec-ids-BfPkjMmk.d.mts} +1 -1
  2. package/dist/{codec-ids-CYwMu3-4.d.mts.map → codec-ids-BfPkjMmk.d.mts.map} +1 -1
  3. package/dist/{codec-ids-CuUxYcd0.mjs → codec-ids-DSU7S2Li.mjs} +1 -1
  4. package/dist/{codec-ids-CuUxYcd0.mjs.map → codec-ids-DSU7S2Li.mjs.map} +1 -1
  5. package/dist/codec-ids.d.mts +1 -1
  6. package/dist/codec-ids.mjs +1 -1
  7. package/dist/{codec-types-DNauB5UT.d.mts → codec-types-izdPhp_9.d.mts} +6 -7
  8. package/dist/codec-types-izdPhp_9.d.mts.map +1 -0
  9. package/dist/codec-types.d.mts +3 -3
  10. package/dist/{codecs-BAlEiSeP.d.mts → codecs-BGeJavlQ.d.mts} +16 -18
  11. package/dist/codecs-BGeJavlQ.d.mts.map +1 -0
  12. package/dist/{codecs-DVnHtVWW.mjs → codecs-DsC4OGmU.mjs} +2 -2
  13. package/dist/{codecs-DVnHtVWW.mjs.map → codecs-DsC4OGmU.mjs.map} +1 -1
  14. package/dist/codecs.d.mts +2 -2
  15. package/dist/codecs.mjs +1 -1
  16. package/dist/contract-free.d.mts +55 -0
  17. package/dist/contract-free.d.mts.map +1 -0
  18. package/dist/contract-free.mjs +111 -0
  19. package/dist/contract-free.mjs.map +1 -0
  20. package/dist/control-tables-7KwMyJ6i.mjs +12 -0
  21. package/dist/control-tables-7KwMyJ6i.mjs.map +1 -0
  22. package/dist/control-tables.d.mts +11 -0
  23. package/dist/control-tables.d.mts.map +1 -0
  24. package/dist/control-tables.mjs +2 -0
  25. package/dist/control.d.mts +31 -15
  26. package/dist/control.d.mts.map +1 -1
  27. package/dist/control.mjs +66 -124
  28. package/dist/control.mjs.map +1 -1
  29. package/dist/ddl.d.mts +2 -0
  30. package/dist/ddl.mjs +2 -0
  31. package/dist/{default-normalizer-3Fccw7yw.mjs → default-normalizer-DuoHj9-O.mjs} +1 -1
  32. package/dist/{default-normalizer-3Fccw7yw.mjs.map → default-normalizer-DuoHj9-O.mjs.map} +1 -1
  33. package/dist/default-normalizer.mjs +1 -1
  34. package/dist/descriptor-meta-Dxx2A6PT.mjs +17 -0
  35. package/dist/descriptor-meta-Dxx2A6PT.mjs.map +1 -0
  36. package/dist/descriptor-meta-runtime-BkXK3OjD.mjs +12 -0
  37. package/dist/descriptor-meta-runtime-BkXK3OjD.mjs.map +1 -0
  38. package/dist/migration.d.mts +2 -2
  39. package/dist/migration.mjs +3 -3
  40. package/dist/{native-type-normalizer-BlN5XfD-.mjs → native-type-normalizer-CiSyVmMP.mjs} +1 -1
  41. package/dist/{native-type-normalizer-BlN5XfD-.mjs.map → native-type-normalizer-CiSyVmMP.mjs.map} +1 -1
  42. package/dist/native-type-normalizer.mjs +1 -1
  43. package/dist/nodes-D0k4z7NL.mjs +33 -0
  44. package/dist/nodes-D0k4z7NL.mjs.map +1 -0
  45. package/dist/nodes-VzaaeUTb.d.mts +29 -0
  46. package/dist/nodes-VzaaeUTb.d.mts.map +1 -0
  47. package/dist/{op-factory-call-BnPhI25-.mjs → op-factory-call-DymqdXQW.mjs} +2 -2
  48. package/dist/{op-factory-call-BnPhI25-.mjs.map → op-factory-call-DymqdXQW.mjs.map} +1 -1
  49. package/dist/op-factory-call.d.mts +2 -2
  50. package/dist/op-factory-call.d.mts.map +1 -1
  51. package/dist/op-factory-call.mjs +1 -1
  52. package/dist/pack.d.mts +9 -7
  53. package/dist/pack.d.mts.map +1 -1
  54. package/dist/pack.mjs +1 -1
  55. package/dist/{planner-CEKTRydl.mjs → planner-DSNDwQy9.mjs} +9 -9
  56. package/dist/planner-DSNDwQy9.mjs.map +1 -0
  57. package/dist/{planner-produced-sqlite-migration-CI9LdXPr.d.mts → planner-produced-sqlite-migration-C1yqJAiM.d.mts} +3 -3
  58. package/dist/{planner-produced-sqlite-migration-CI9LdXPr.d.mts.map → planner-produced-sqlite-migration-C1yqJAiM.d.mts.map} +1 -1
  59. package/dist/{planner-produced-sqlite-migration-DCsg3RDZ.mjs → planner-produced-sqlite-migration-DowV_vHw.mjs} +3 -3
  60. package/dist/{planner-produced-sqlite-migration-DCsg3RDZ.mjs.map → planner-produced-sqlite-migration-DowV_vHw.mjs.map} +1 -1
  61. package/dist/planner-produced-sqlite-migration.d.mts +1 -1
  62. package/dist/planner-produced-sqlite-migration.mjs +1 -1
  63. package/dist/{planner-target-details-Bm71XPKb.mjs → planner-target-details-H8z9TFDg.mjs} +1 -1
  64. package/dist/{planner-target-details-Bm71XPKb.mjs.map → planner-target-details-H8z9TFDg.mjs.map} +1 -1
  65. package/dist/{planner-target-details-vhvZDWK1.d.mts → planner-target-details-xR6UfIcz.d.mts} +1 -1
  66. package/dist/{planner-target-details-vhvZDWK1.d.mts.map → planner-target-details-xR6UfIcz.d.mts.map} +1 -1
  67. package/dist/planner-target-details.d.mts +1 -1
  68. package/dist/planner-target-details.mjs +1 -1
  69. package/dist/planner.d.mts +2 -2
  70. package/dist/planner.d.mts.map +1 -1
  71. package/dist/planner.mjs +1 -1
  72. package/dist/{render-ops-CSRDT4YL.mjs → render-ops-CFRbJ3Yb.mjs} +1 -1
  73. package/dist/{render-ops-CSRDT4YL.mjs.map → render-ops-CFRbJ3Yb.mjs.map} +1 -1
  74. package/dist/render-ops.d.mts +1 -1
  75. package/dist/render-ops.mjs +1 -1
  76. package/dist/runtime.d.mts +17 -1
  77. package/dist/runtime.d.mts.map +1 -1
  78. package/dist/runtime.mjs +4 -3
  79. package/dist/runtime.mjs.map +1 -1
  80. package/dist/{shared-qLsgTOZs.d.mts → shared-Dhc8mLK1.d.mts} +2 -2
  81. package/dist/{shared-qLsgTOZs.d.mts.map → shared-Dhc8mLK1.d.mts.map} +1 -1
  82. package/dist/{sql-utils-DhevMgef.mjs → sql-utils-CV8Bdgtc.mjs} +1 -1
  83. package/dist/{sql-utils-DhevMgef.mjs.map → sql-utils-CV8Bdgtc.mjs.map} +1 -1
  84. package/dist/sql-utils.mjs +1 -1
  85. package/dist/sqlite-contract-serializer-jcRu8aHh.mjs +101 -0
  86. package/dist/sqlite-contract-serializer-jcRu8aHh.mjs.map +1 -0
  87. package/dist/{sqlite-migration-BBJktVVw.mjs → sqlite-migration-CUqgmzQH.mjs} +1 -1
  88. package/dist/{sqlite-migration-BBJktVVw.mjs.map → sqlite-migration-CUqgmzQH.mjs.map} +1 -1
  89. package/dist/{sqlite-migration-DAb2NEX6.d.mts → sqlite-migration-D4XGYzgQ.d.mts} +2 -2
  90. package/dist/{sqlite-migration-DAb2NEX6.d.mts.map → sqlite-migration-D4XGYzgQ.d.mts.map} +1 -1
  91. package/dist/{tables-DGRRJasz.mjs → tables-CjB7vXCr.mjs} +5 -11
  92. package/dist/tables-CjB7vXCr.mjs.map +1 -0
  93. package/package.json +23 -21
  94. package/src/contract-free/columns.ts +44 -0
  95. package/src/contract-free/control-bootstrap.ts +54 -0
  96. package/src/contract-free/ddl.ts +26 -0
  97. package/src/core/authoring.ts +1 -1
  98. package/src/core/control-tables.ts +11 -0
  99. package/src/core/control-target.ts +4 -6
  100. package/src/core/ddl/nodes.ts +54 -0
  101. package/src/core/descriptor-meta-runtime.ts +28 -0
  102. package/src/core/descriptor-meta.ts +4 -6
  103. package/src/core/migrations/issue-planner.ts +1 -1
  104. package/src/core/migrations/operations/shared.ts +1 -8
  105. package/src/core/migrations/planner-strategies.ts +1 -1
  106. package/src/core/migrations/runner.ts +78 -83
  107. package/src/core/runtime-target.ts +2 -2
  108. package/src/core/sqlite-contract-serializer.ts +21 -9
  109. package/src/core/sqlite-unbound-database.ts +113 -26
  110. package/src/exports/contract-free.ts +6 -0
  111. package/src/exports/control-tables.ts +5 -0
  112. package/src/exports/ddl.ts +6 -0
  113. package/src/exports/runtime.ts +1 -0
  114. package/dist/codec-types-DNauB5UT.d.mts.map +0 -1
  115. package/dist/codecs-BAlEiSeP.d.mts.map +0 -1
  116. package/dist/descriptor-meta-CE2Kbn9b.mjs +0 -17
  117. package/dist/descriptor-meta-CE2Kbn9b.mjs.map +0 -1
  118. package/dist/planner-CEKTRydl.mjs.map +0 -1
  119. package/dist/statement-builders-Dne-LkAV.mjs +0 -158
  120. package/dist/statement-builders-Dne-LkAV.mjs.map +0 -1
  121. package/dist/statement-builders.d.mts +0 -68
  122. package/dist/statement-builders.d.mts.map +0 -1
  123. package/dist/statement-builders.mjs +0 -2
  124. package/dist/tables-DGRRJasz.mjs.map +0 -1
  125. package/src/core/migrations/statement-builders.ts +0 -212
  126. package/src/exports/statement-builders.ts +0 -12
package/dist/control.mjs CHANGED
@@ -1,18 +1,17 @@
1
- import { t as sqliteTargetDescriptorMeta } from "./descriptor-meta-CE2Kbn9b.mjs";
2
- import { t as parseSqliteDefault } from "./default-normalizer-3Fccw7yw.mjs";
3
- import { t as normalizeSqliteNativeType } from "./native-type-normalizer-BlN5XfD-.mjs";
4
- import { d as renderDefaultLiteral } from "./tables-DGRRJasz.mjs";
5
- import { n as createSqliteMigrationPlanner } from "./planner-CEKTRydl.mjs";
6
- import { a as buildLedgerInsertStatement, c as ensureMarkerTableStatement, i as MARKER_TABLE_NAME, l as readMarkerStatement, o as buildWriteMarkerStatements, s as ensureLedgerTableStatement } from "./statement-builders-Dne-LkAV.mjs";
1
+ import { t as sqliteTargetDescriptorMeta } from "./descriptor-meta-Dxx2A6PT.mjs";
2
+ import { t as parseSqliteDefault } from "./default-normalizer-DuoHj9-O.mjs";
3
+ import { t as normalizeSqliteNativeType } from "./native-type-normalizer-CiSyVmMP.mjs";
4
+ import { r as MARKER_TABLE_NAME } from "./control-tables-7KwMyJ6i.mjs";
5
+ import { d as renderDefaultLiteral } from "./tables-CjB7vXCr.mjs";
6
+ import { n as createSqliteMigrationPlanner } from "./planner-DSNDwQy9.mjs";
7
+ import { n as SqliteUnboundDatabase, r as sqliteCreateNamespace, t as SqliteContractSerializer } from "./sqlite-contract-serializer-jcRu8aHh.mjs";
7
8
  import { contractToSchemaIR, runnerFailure, runnerSuccess } from "@prisma-next/family-sql/control";
8
9
  import { SqlStorage } from "@prisma-next/sql-contract/types";
9
10
  import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
10
11
  import { notOk, ok, okVoid } from "@prisma-next/utils/result";
11
12
  import { ifDefined } from "@prisma-next/utils/defined";
12
- import { NamespaceBase, UNBOUND_NAMESPACE_ID, freezeNode } from "@prisma-next/framework-components/ir";
13
13
  import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
14
- import { parseContractMarkerRow } from "@prisma-next/family-sql/verify";
15
- import { SqlContractSerializerBase, SqlSchemaVerifierBase } from "@prisma-next/family-sql/ir";
14
+ import { SqlSchemaVerifierBase } from "@prisma-next/family-sql/ir";
16
15
  //#region src/core/migrations/runner.ts
17
16
  function createSqliteMigrationRunner(family) {
18
17
  return new SqliteMigrationRunner(family);
@@ -36,9 +35,12 @@ var SqliteMigrationRunner = class {
36
35
  if (!destinationCheck.ok) return destinationCheck;
37
36
  const policyCheck = this.enforcePolicyCompatibility(options.policy, options.plan.operations);
38
37
  if (!policyCheck.ok) return policyCheck;
39
- const ensureResult = await this.ensureControlTables(driver);
38
+ const ensureResult = await this.ensureControlTables(driver, options.destinationContract);
40
39
  if (!ensureResult.ok) return ensureResult;
41
- const existingMarker = await this.readMarker(driver, space);
40
+ const existingMarker = await this.family.readMarker({
41
+ driver,
42
+ space
43
+ });
42
44
  const markerCheck = this.ensureMarkerCompatibility(existingMarker, options.plan);
43
45
  if (!markerCheck.ok) return markerCheck;
44
46
  const markerAtDestination = this.markerMatchesDestination(existingMarker, options.plan);
@@ -79,8 +81,9 @@ var SqliteMigrationRunner = class {
79
81
  const existingInvariants = new Set(existingMarker?.invariants ?? []);
80
82
  const incomingIsSubsetOfExisting = incomingInvariants.every((id) => existingInvariants.has(id));
81
83
  if (!(isSelfEdge && operationsExecuted === 0 && incomingIsSubsetOfExisting)) {
82
- await this.upsertMarker(driver, options, existingMarker, space);
83
- await this.recordLedgerEntry(driver, options, existingMarker, executedOperations);
84
+ const markerResult = await this.upsertMarker(driver, options, existingMarker, space);
85
+ if (!markerResult.ok) return markerResult;
86
+ await this.recordLedgerEntries(driver, options, executedOperations);
84
87
  }
85
88
  return runnerSuccess({
86
89
  operationsPlanned: options.plan.operations.length,
@@ -181,11 +184,11 @@ var SqliteMigrationRunner = class {
181
184
  executedOperations
182
185
  });
183
186
  }
184
- async ensureControlTables(driver) {
187
+ async ensureControlTables(driver, contract) {
185
188
  const legacyDetection = await this.detectLegacyMarkerShape(driver);
186
189
  if (!legacyDetection.ok) return legacyDetection;
187
- await this.executeStatement(driver, ensureMarkerTableStatement);
188
- await this.executeStatement(driver, ensureLedgerTableStatement);
190
+ const lowererContext = { contract };
191
+ for (const query of this.family.bootstrapControlTableQueries()) await this.executeStatement(driver, this.family.lowerAst(query, lowererContext));
189
192
  return okVoid();
190
193
  }
191
194
  async detectLegacyMarkerShape(driver) {
@@ -198,21 +201,6 @@ var SqliteMigrationRunner = class {
198
201
  columns: [...columns].sort()
199
202
  } });
200
203
  }
201
- async readMarker(driver, space) {
202
- const stmt = readMarkerStatement(space);
203
- try {
204
- const row = (await driver.query(stmt.sql, stmt.params)).rows[0];
205
- if (!row) return null;
206
- const invariants = typeof row.invariants === "string" ? JSON.parse(row.invariants) : row.invariants;
207
- return parseContractMarkerRow({
208
- ...row,
209
- invariants
210
- });
211
- } catch (error) {
212
- if (error instanceof Error && error.message.includes("no such table")) return null;
213
- throw error;
214
- }
215
- }
216
204
  async runExpectationSteps(driver, steps, operation, phase) {
217
205
  for (const step of steps) {
218
206
  const result = await driver.query(step.sql, step.params ?? []);
@@ -325,32 +313,54 @@ var SqliteMigrationRunner = class {
325
313
  return okVoid();
326
314
  }
327
315
  async upsertMarker(driver, options, existingMarker, space) {
328
- const merged = new Set(existingMarker?.invariants ?? []);
329
- for (const inv of options.plan.providedInvariants) merged.add(inv);
330
- const invariants = Array.from(merged).sort();
331
- const writeStatements = buildWriteMarkerStatements({
332
- space,
316
+ const destination = {
333
317
  storageHash: options.plan.destination.storageHash,
334
318
  profileHash: options.plan.destination.profileHash ?? options.destinationContract.profileHash ?? options.plan.destination.storageHash,
335
- contractJson: options.destinationContract,
336
- canonicalVersion: null,
337
- meta: {},
338
- invariants
339
- });
340
- const statement = existingMarker ? writeStatements.update : writeStatements.insert;
341
- await this.executeStatement(driver, statement);
319
+ invariants: options.plan.providedInvariants ?? []
320
+ };
321
+ if (!existingMarker) {
322
+ await this.family.initMarker({
323
+ driver,
324
+ space,
325
+ destination
326
+ });
327
+ return okVoid();
328
+ }
329
+ if (!await this.family.updateMarker({
330
+ driver,
331
+ space,
332
+ expectedFrom: existingMarker.storageHash,
333
+ destination
334
+ })) return runnerFailure("MARKER_CAS_FAILURE", "Marker was modified by another process during migration execution.", { meta: {
335
+ space,
336
+ expectedStorageHash: existingMarker.storageHash,
337
+ destinationStorageHash: options.plan.destination.storageHash
338
+ } });
339
+ return okVoid();
342
340
  }
343
- async recordLedgerEntry(driver, options, existingMarker, executedOperations) {
344
- const ledgerStatement = buildLedgerInsertStatement({
345
- originStorageHash: existingMarker?.storageHash ?? null,
346
- originProfileHash: existingMarker?.profileHash ?? null,
347
- destinationStorageHash: options.plan.destination.storageHash,
348
- destinationProfileHash: options.plan.destination.profileHash ?? options.destinationContract.profileHash ?? options.plan.destination.storageHash,
349
- contractJsonBefore: existingMarker?.contractJson ?? null,
350
- contractJsonAfter: options.destinationContract,
351
- operations: executedOperations
352
- });
353
- await this.executeStatement(driver, ledgerStatement);
341
+ async recordLedgerEntries(driver, options, executedOperations) {
342
+ const plan = options.plan;
343
+ const space = plan.spaceId;
344
+ const edges = options.migrationEdges;
345
+ const totalEdgeOps = edges.reduce((sum, edge) => sum + edge.operationCount, 0);
346
+ if (totalEdgeOps !== plan.operations.length) throw new Error(`Ledger write: plan.operations length (${plan.operations.length}) does not match sum of migrationEdges operationCount (${totalEdgeOps})`);
347
+ let offset = 0;
348
+ for (const edge of edges) {
349
+ const edgeOps = executedOperations.slice(offset, offset + edge.operationCount);
350
+ offset += edge.operationCount;
351
+ await this.family.writeLedgerEntry({
352
+ driver,
353
+ space,
354
+ entry: {
355
+ edgeId: `${edge.from}->${edge.to}`,
356
+ from: edge.from,
357
+ to: edge.to,
358
+ migrationName: edge.dirName,
359
+ migrationHash: edge.migrationHash,
360
+ operations: edgeOps
361
+ }
362
+ });
363
+ }
354
364
  }
355
365
  async beginExclusiveTransaction(driver) {
356
366
  await driver.query("BEGIN EXCLUSIVE");
@@ -370,24 +380,6 @@ var SqliteMigrationRunner = class {
370
380
  }
371
381
  };
372
382
  //#endregion
373
- //#region src/core/sqlite-contract-serializer.ts
374
- /**
375
- * SQLite target `ContractSerializer` concretion. Mirrors the Postgres
376
- * shape: inherits the full SQL-family deserialization pipeline. Today's
377
- * SQLite contract shape is the family-shared shape; no target-specific
378
- * polymorphic `storage.types` factories are registered yet.
379
- *
380
- * `serializeContract` falls through to the family-base default —
381
- * SQLite's contract is JSON-clean today. Once target-only fields land
382
- * (e.g. per-target derived storage fields) this is the home for
383
- * stripping them from the persisted envelope.
384
- */
385
- var SqliteContractSerializer = class extends SqlContractSerializerBase {
386
- constructor() {
387
- super(/* @__PURE__ */ new Map());
388
- }
389
- };
390
- //#endregion
391
383
  //#region src/core/sqlite-schema-verifier.ts
392
384
  /**
393
385
  * SQLite target `SchemaVerifier` concretion. Mirrors the Postgres
@@ -419,7 +411,7 @@ const sqliteControlTargetDescriptor = {
419
411
  contractSerializer: new SqliteContractSerializer(),
420
412
  schemaVerifier: new SqliteSchemaVerifier(),
421
413
  migrations: {
422
- createPlanner(_family) {
414
+ createPlanner(_adapter) {
423
415
  return createSqliteMigrationPlanner();
424
416
  },
425
417
  createRunner(family) {
@@ -439,7 +431,7 @@ const sqliteControlTargetDescriptor = {
439
431
  targetId: "sqlite"
440
432
  };
441
433
  },
442
- createPlanner(_family) {
434
+ createPlanner(_adapter) {
443
435
  return createSqliteMigrationPlanner();
444
436
  },
445
437
  createRunner(family) {
@@ -447,56 +439,6 @@ const sqliteControlTargetDescriptor = {
447
439
  }
448
440
  };
449
441
  //#endregion
450
- //#region src/core/sqlite-unbound-database.ts
451
- /**
452
- * SQLite target `Namespace` concretion. SQLite has no schema or
453
- * database-namespacing concept at the SQL level — there is exactly one
454
- * effective namespace per connection, so the target ships a single
455
- * singleton bound to the framework's `UNBOUND_NAMESPACE_ID` slot.
456
- *
457
- * Qualifier emission elides the prefix entirely: rendered DDL and
458
- * queries look unqualified (`CREATE TABLE "users" (...)`), matching
459
- * SQLite's native dialect. Call sites stay polymorphic — they ask the
460
- * namespace for its qualifier and consume the empty/unqualified result
461
- * the same way Postgres consumes a `"schema"` prefix.
462
- *
463
- * The SQLite PSL interpreter rejects every explicit `namespace { … }`
464
- * block with a diagnostic naming SQLite; only the implicit
465
- * `__unspecified__` AST bucket reaches the SQLite interpreter, which
466
- * lowers it to this singleton.
467
- */
468
- var SqliteUnboundDatabase = class SqliteUnboundDatabase extends NamespaceBase {
469
- static instance = new SqliteUnboundDatabase();
470
- kind = "database";
471
- id = UNBOUND_NAMESPACE_ID;
472
- tables;
473
- constructor() {
474
- super();
475
- this.tables = Object.freeze({});
476
- freezeNode(this);
477
- }
478
- qualifier() {
479
- return "";
480
- }
481
- qualifyTable(tableName) {
482
- return `"${tableName}"`;
483
- }
484
- };
485
- /**
486
- * Target-supplied `Namespace` factory the SQLite target plumbs through
487
- * `defineContract({ createNamespace })`. SQLite has only one
488
- * effective namespace slot — the framework `UNBOUND_NAMESPACE_ID`
489
- * sentinel — so the factory always returns the singleton and rejects
490
- * any other coordinate. The SQL family's defensive validation in
491
- * `defineContract` already rejects user-declared SQLite namespaces, so
492
- * this throw is a structural safety net rather than a user-facing
493
- * surface.
494
- */
495
- function sqliteCreateNamespace(id) {
496
- if (id === UNBOUND_NAMESPACE_ID) return SqliteUnboundDatabase.instance;
497
- throw new Error(`sqliteCreateNamespace: SQLite has no schema concept; the only valid namespace id is "${UNBOUND_NAMESPACE_ID}" (received "${id}").`);
498
- }
499
- //#endregion
500
442
  export { SqliteUnboundDatabase, sqliteControlTargetDescriptor as default, sqliteCreateNamespace };
501
443
 
502
444
  //# sourceMappingURL=control.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"control.mjs","names":[],"sources":["../src/core/migrations/runner.ts","../src/core/sqlite-contract-serializer.ts","../src/core/sqlite-schema-verifier.ts","../src/core/control-target.ts","../src/core/sqlite-unbound-database.ts"],"sourcesContent":["import type { ContractMarkerRecord } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlControlFamilyInstance,\n SqlMigrationPlanContractInfo,\n SqlMigrationPlanOperation,\n SqlMigrationPlanOperationStep,\n SqlMigrationRunner,\n SqlMigrationRunnerExecuteOptions,\n SqlMigrationRunnerFailure,\n SqlMigrationRunnerResult,\n SqlMigrationRunnerSuccessValue,\n} from '@prisma-next/family-sql/control';\nimport { runnerFailure, runnerSuccess } from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport { type ContractMarkerRow, parseContractMarkerRow } from '@prisma-next/family-sql/verify';\nimport type {\n ControlDriverInstance,\n MigrationRunnerResult,\n} from '@prisma-next/framework-components/control';\nimport { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok, okVoid } from '@prisma-next/utils/result';\nimport { parseSqliteDefault } from '../default-normalizer';\nimport { normalizeSqliteNativeType } from '../native-type-normalizer';\nimport type { SqlitePlanTargetDetails } from './planner-target-details';\nimport {\n buildLedgerInsertStatement,\n buildWriteMarkerStatements,\n ensureLedgerTableStatement,\n ensureMarkerTableStatement,\n MARKER_TABLE_NAME,\n readMarkerStatement,\n type SqlStatement,\n} from './statement-builders';\n\nexport function createSqliteMigrationRunner(\n family: SqlControlFamilyInstance,\n): SqlMigrationRunner<SqlitePlanTargetDetails> {\n return new SqliteMigrationRunner(family);\n}\n\nclass SqliteMigrationRunner implements SqlMigrationRunner<SqlitePlanTargetDetails> {\n constructor(private readonly family: SqlControlFamilyInstance) {}\n\n /**\n * Apply the plan against an already-open connection without managing\n * the transaction lifecycle. The caller ({@link SqliteMigrationRunner.execute})\n * owns BEGIN/COMMIT/ROLLBACK and any connection-level setup (FK pragma\n * toggle, FK integrity check).\n */\n async executeOnConnection(\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n ): Promise<SqlMigrationRunnerResult> {\n const driver = options.driver;\n if (options.space !== undefined && options.space !== options.plan.spaceId) {\n throw new Error(\n `SqlMigrationRunner: options.space (${options.space}) does not match plan.spaceId (${options.plan.spaceId})`,\n );\n }\n const space = options.plan.spaceId;\n\n const destinationCheck = this.ensurePlanMatchesDestinationContract(\n options.plan.destination,\n options.destinationContract,\n );\n if (!destinationCheck.ok) return destinationCheck;\n\n const policyCheck = this.enforcePolicyCompatibility(options.policy, options.plan.operations);\n if (!policyCheck.ok) return policyCheck;\n\n const ensureResult = await this.ensureControlTables(driver);\n if (!ensureResult.ok) return ensureResult;\n const existingMarker = await this.readMarker(driver, space);\n\n const markerCheck = this.ensureMarkerCompatibility(existingMarker, options.plan);\n if (!markerCheck.ok) return markerCheck;\n\n const markerAtDestination = this.markerMatchesDestination(existingMarker, options.plan);\n const isSelfEdge = options.plan.origin?.storageHash === options.plan.destination.storageHash;\n const skipOperations = markerAtDestination && options.plan.origin != null && !isSelfEdge;\n\n let operationsExecuted: number;\n let executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[];\n\n if (skipOperations) {\n operationsExecuted = 0;\n executedOperations = [];\n } else {\n const applyResult = await this.applyPlan(driver, options);\n if (!applyResult.ok) return applyResult;\n operationsExecuted = applyResult.value.operationsExecuted;\n executedOperations = applyResult.value.executedOperations;\n }\n\n if (space === APP_SPACE_ID) {\n const schemaIR = await this.family.introspect({\n driver,\n contract: options.destinationContract,\n });\n\n const schemaVerifyResult = verifySqlSchema({\n contract: options.destinationContract,\n schema: schemaIR,\n strict: options.strictVerification ?? true,\n context: options.context ?? {},\n typeMetadataRegistry: this.family.typeMetadataRegistry,\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parseSqliteDefault,\n normalizeNativeType: normalizeSqliteNativeType,\n });\n if (!schemaVerifyResult.ok) {\n return runnerFailure('SCHEMA_VERIFY_FAILED', schemaVerifyResult.summary, {\n why: 'The resulting database schema does not satisfy the destination contract.',\n meta: { issues: schemaVerifyResult.schema.issues },\n });\n }\n }\n\n // Self-edge no-op detection: see Postgres runner for the rationale\n // (kept symmetric across both targets).\n const incomingInvariants = options.plan.providedInvariants;\n const existingInvariants = new Set(existingMarker?.invariants ?? []);\n const incomingIsSubsetOfExisting = incomingInvariants.every((id) => existingInvariants.has(id));\n const isSelfEdgeNoOp = isSelfEdge && operationsExecuted === 0 && incomingIsSubsetOfExisting;\n\n if (!isSelfEdgeNoOp) {\n await this.upsertMarker(driver, options, existingMarker, space);\n await this.recordLedgerEntry(driver, options, existingMarker, executedOperations);\n }\n\n return runnerSuccess({\n operationsPlanned: options.plan.operations.length,\n operationsExecuted,\n });\n }\n\n async execute(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly perSpaceOptions: ReadonlyArray<\n SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>\n >;\n }): Promise<MigrationRunnerResult> {\n const driver = options.driver;\n const perSpaceOptions = options.perSpaceOptions;\n\n if (perSpaceOptions.length === 0) {\n return ok({ perSpaceResults: [] });\n }\n\n // FK pragma toggle and the FK integrity check both span the outer\n // transaction: PRAGMA foreign_keys is a no-op inside a transaction, so the\n // toggle has to wrap BEGIN/COMMIT.\n const fkWasEnabled = await this.readForeignKeysEnabled(driver);\n if (fkWasEnabled) {\n await driver.query('PRAGMA foreign_keys = OFF');\n }\n\n try {\n await this.beginExclusiveTransaction(driver);\n let committed = false;\n try {\n const perSpaceResults: Array<{\n space: string;\n value: SqlMigrationRunnerSuccessValue;\n }> = [];\n let lastProcessedSpace: string | undefined;\n for (const spaceOptions of perSpaceOptions) {\n const space = spaceOptions.space ?? spaceOptions.plan.spaceId;\n const result = await this.executeOnConnection({ ...spaceOptions, driver, space });\n if (!result.ok) {\n return notOk({ ...result.failure, failingSpace: space });\n }\n perSpaceResults.push({ space, value: result.value });\n lastProcessedSpace = space;\n }\n\n if (fkWasEnabled) {\n const fkIntegrityCheck = await this.verifyForeignKeyIntegrity(driver);\n if (!fkIntegrityCheck.ok) {\n // Post-loop integrity violations cannot be attributed to a\n // single per-space step (the cumulative effect of all\n // applied plans was needed to reveal the broken\n // reference). Surface the last successfully-applied space\n // so operators can investigate from the most recent\n // migration first.\n return notOk({\n ...fkIntegrityCheck.failure,\n failingSpace: lastProcessedSpace ?? APP_SPACE_ID,\n });\n }\n }\n\n await this.commitTransaction(driver);\n committed = true;\n return ok({ perSpaceResults });\n } finally {\n if (!committed) {\n await this.rollbackTransaction(driver);\n }\n }\n } finally {\n if (fkWasEnabled) {\n await driver.query('PRAGMA foreign_keys = ON');\n }\n }\n }\n\n private async readForeignKeysEnabled(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<boolean> {\n const result = await driver.query<{ foreign_keys: number }>('PRAGMA foreign_keys');\n const row = result.rows[0];\n return row?.foreign_keys === 1;\n }\n\n private async verifyForeignKeyIntegrity(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const result = await driver.query<Record<string, unknown>>('PRAGMA foreign_key_check');\n if (result.rows.length === 0) {\n return okVoid();\n }\n return runnerFailure(\n 'FOREIGN_KEY_VIOLATION',\n `Foreign key integrity check failed after migration: ${result.rows.length} violation(s).`,\n {\n why: 'PRAGMA foreign_key_check reported violations after applying recreate-table operations.',\n meta: { violations: result.rows },\n },\n );\n }\n\n private async applyPlan(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n ): Promise<\n Result<\n {\n readonly operationsExecuted: number;\n readonly executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[];\n },\n SqlMigrationRunnerFailure\n >\n > {\n const checks = options.executionChecks;\n const runPrechecks = checks?.prechecks !== false;\n const runPostchecks = checks?.postchecks !== false;\n const runIdempotency = checks?.idempotencyChecks !== false;\n\n let operationsExecuted = 0;\n const executedOperations: Array<SqlMigrationPlanOperation<SqlitePlanTargetDetails>> = [];\n\n for (const operation of options.plan.operations) {\n options.callbacks?.onOperationStart?.(operation);\n try {\n if (runPostchecks && runIdempotency) {\n const postcheckAlreadySatisfied = await this.expectationsAreSatisfied(\n driver,\n operation.postcheck,\n );\n if (postcheckAlreadySatisfied) {\n executedOperations.push(this.createSkipRecord(operation));\n continue;\n }\n }\n\n if (runPrechecks) {\n const precheckResult = await this.runExpectationSteps(\n driver,\n operation.precheck,\n operation,\n 'precheck',\n );\n if (!precheckResult.ok) {\n return precheckResult;\n }\n }\n\n const executeResult = await this.runExecuteSteps(driver, operation.execute, operation);\n if (!executeResult.ok) {\n return executeResult;\n }\n\n if (runPostchecks) {\n const postcheckResult = await this.runExpectationSteps(\n driver,\n operation.postcheck,\n operation,\n 'postcheck',\n );\n if (!postcheckResult.ok) {\n return postcheckResult;\n }\n }\n\n executedOperations.push(operation);\n operationsExecuted += 1;\n } finally {\n options.callbacks?.onOperationComplete?.(operation);\n }\n }\n return ok({ operationsExecuted, executedOperations });\n }\n\n private async ensureControlTables(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n // Pre-1.0 zero-range guardrail: detect a pre-cleanup single-row\n // marker table (no `space` column) and surface a structured failure\n // rather than silently rebuilding the table into the per-space\n // shape. See `specs/framework-mechanism.spec.md § 2`.\n const legacyDetection = await this.detectLegacyMarkerShape(driver);\n if (!legacyDetection.ok) {\n return legacyDetection;\n }\n await this.executeStatement(driver, ensureMarkerTableStatement);\n await this.executeStatement(driver, ensureLedgerTableStatement);\n return okVoid();\n }\n\n private async detectLegacyMarkerShape(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const tableInfo = await driver.query<{ name: string }>(\n `PRAGMA table_info(\"${MARKER_TABLE_NAME}\")`,\n );\n if (tableInfo.rows.length === 0) {\n return okVoid();\n }\n const columns = new Set(tableInfo.rows.map((row) => row.name));\n if (columns.has('space')) {\n return okVoid();\n }\n return runnerFailure(\n 'LEGACY_MARKER_SHAPE',\n `Legacy marker-table shape detected on ${MARKER_TABLE_NAME} (no \\`space\\` column). ` +\n 'Prisma Next is in pre-1.0; the previous transitional auto-migration to the per-space-row schema has been removed. ' +\n `Drop \\`${MARKER_TABLE_NAME}\\` and re-run \\`dbInit\\` to reinitialise from a clean baseline.`,\n {\n meta: {\n table: MARKER_TABLE_NAME,\n columns: [...columns].sort(),\n },\n },\n );\n }\n\n private async readMarker(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n space: string,\n ): Promise<ContractMarkerRecord | null> {\n const stmt = readMarkerStatement(space);\n try {\n const result = await driver.query<ContractMarkerRow>(stmt.sql, stmt.params);\n const row = result.rows[0];\n if (!row) return null;\n // SQLite stores arrays as JSON-encoded TEXT (no native array type), so\n // the driver returns `invariants` as a string. Decode before delegating\n // to the shared row schema, which expects `string[]`.\n const invariants =\n typeof row.invariants === 'string'\n ? (JSON.parse(row.invariants) as unknown)\n : row.invariants;\n return parseContractMarkerRow({ ...row, invariants });\n } catch (error) {\n // Table might not exist yet\n if (error instanceof Error && error.message.includes('no such table')) {\n return null;\n }\n throw error;\n }\n }\n\n private async runExpectationSteps(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n phase: 'precheck' | 'postcheck',\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n for (const step of steps) {\n const result = await driver.query(step.sql, step.params ?? []);\n if (!this.stepResultIsTrue(result.rows)) {\n const code = phase === 'precheck' ? 'PRECHECK_FAILED' : 'POSTCHECK_FAILED';\n return runnerFailure(\n code,\n `Operation ${operation.id} failed during ${phase}: ${step.description}`,\n {\n meta: {\n operationId: operation.id,\n phase,\n stepDescription: step.description,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private async runExecuteSteps(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n for (const step of steps) {\n try {\n await driver.query(step.sql, step.params ?? []);\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n return runnerFailure(\n 'EXECUTION_FAILED',\n `Operation ${operation.id} failed during execution: ${step.description}`,\n {\n why: message,\n meta: {\n operationId: operation.id,\n stepDescription: step.description,\n sql: step.sql,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private stepResultIsTrue(rows: readonly Record<string, unknown>[]): boolean {\n if (!rows || rows.length === 0) {\n return false;\n }\n const firstRow = rows[0];\n const firstValue = firstRow ? Object.values(firstRow)[0] : undefined;\n if (typeof firstValue === 'number') {\n return firstValue !== 0;\n }\n if (typeof firstValue === 'boolean') {\n return firstValue;\n }\n if (typeof firstValue === 'string') {\n const lower = firstValue.toLowerCase();\n if (lower === 'true' || lower === '1') return true;\n if (lower === 'false' || lower === '0') return false;\n return firstValue.length > 0;\n }\n return Boolean(firstValue);\n }\n\n private async expectationsAreSatisfied(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n ): Promise<boolean> {\n if (steps.length === 0) {\n return false;\n }\n for (const step of steps) {\n const result = await driver.query(step.sql, step.params ?? []);\n if (!this.stepResultIsTrue(result.rows)) {\n return false;\n }\n }\n return true;\n }\n\n private createSkipRecord(\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n ): SqlMigrationPlanOperation<SqlitePlanTargetDetails> {\n return Object.freeze({\n id: operation.id,\n label: operation.label,\n ...ifDefined('summary', operation.summary),\n operationClass: operation.operationClass,\n target: operation.target,\n precheck: Object.freeze([]),\n execute: Object.freeze([]),\n postcheck: Object.freeze([...operation.postcheck]),\n meta: Object.freeze({\n ...(operation.meta ?? {}),\n runner: Object.freeze({ skipped: true, reason: 'postcheck_pre_satisfied' }),\n }),\n });\n }\n\n private markerMatchesDestination(\n marker: ContractMarkerRecord | null,\n plan: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['plan'],\n ): boolean {\n if (!marker) return false;\n if (marker.storageHash !== plan.destination.storageHash) return false;\n if (plan.destination.profileHash && marker.profileHash !== plan.destination.profileHash) {\n return false;\n }\n return true;\n }\n\n private enforcePolicyCompatibility(\n policy: MigrationOperationPolicy,\n operations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Result<void, SqlMigrationRunnerFailure> {\n const allowedClasses = new Set(policy.allowedOperationClasses);\n for (const operation of operations) {\n if (!allowedClasses.has(operation.operationClass)) {\n return runnerFailure(\n 'POLICY_VIOLATION',\n `Operation ${operation.id} has class \"${operation.operationClass}\" which is not allowed by policy.`,\n {\n why: `Policy only allows: ${policy.allowedOperationClasses.join(', ')}.`,\n meta: {\n operationId: operation.id,\n operationClass: operation.operationClass,\n allowedClasses: policy.allowedOperationClasses,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private ensureMarkerCompatibility(\n marker: ContractMarkerRecord | null,\n plan: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['plan'],\n ): Result<void, SqlMigrationRunnerFailure> {\n const origin = plan.origin ?? null;\n if (!origin) {\n return okVoid();\n }\n if (!marker) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Missing contract marker: expected origin storage hash ${origin.storageHash}.`,\n { meta: { expectedOriginStorageHash: origin.storageHash } },\n );\n }\n if (marker.storageHash !== origin.storageHash) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Existing contract marker (${marker.storageHash}) does not match plan origin (${origin.storageHash}).`,\n {\n meta: {\n markerStorageHash: marker.storageHash,\n expectedOriginStorageHash: origin.storageHash,\n },\n },\n );\n }\n if (origin.profileHash && marker.profileHash !== origin.profileHash) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Existing contract marker profile hash (${marker.profileHash}) does not match plan origin profile hash (${origin.profileHash}).`,\n {\n meta: {\n markerProfileHash: marker.profileHash,\n expectedOriginProfileHash: origin.profileHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private ensurePlanMatchesDestinationContract(\n destination: SqlMigrationPlanContractInfo,\n contract: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['destinationContract'],\n ): Result<void, SqlMigrationRunnerFailure> {\n if (destination.storageHash !== contract.storage.storageHash) {\n return runnerFailure(\n 'DESTINATION_CONTRACT_MISMATCH',\n `Plan destination storage hash (${destination.storageHash}) does not match provided contract storage hash (${contract.storage.storageHash}).`,\n {\n meta: {\n planStorageHash: destination.storageHash,\n contractStorageHash: contract.storage.storageHash,\n },\n },\n );\n }\n if (\n destination.profileHash &&\n contract.profileHash &&\n destination.profileHash !== contract.profileHash\n ) {\n return runnerFailure(\n 'DESTINATION_CONTRACT_MISMATCH',\n `Plan destination profile hash (${destination.profileHash}) does not match provided contract profile hash (${contract.profileHash}).`,\n {\n meta: {\n planProfileHash: destination.profileHash,\n contractProfileHash: contract.profileHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private async upsertMarker(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n existingMarker: ContractMarkerRecord | null,\n space: string,\n ): Promise<void> {\n // SQLite has no native array type, so we can't merge invariants in SQL\n // the way Postgres does. Merge client-side under the runner's\n // BEGIN EXCLUSIVE — sort + dedupe so the JSON-encoded value is stable.\n const merged = new Set<string>(existingMarker?.invariants ?? []);\n for (const inv of options.plan.providedInvariants) merged.add(inv);\n const invariants = Array.from(merged).sort();\n const writeStatements = buildWriteMarkerStatements({\n space,\n storageHash: options.plan.destination.storageHash,\n profileHash:\n options.plan.destination.profileHash ??\n options.destinationContract.profileHash ??\n options.plan.destination.storageHash,\n contractJson: options.destinationContract,\n canonicalVersion: null,\n meta: {},\n invariants,\n });\n const statement = existingMarker ? writeStatements.update : writeStatements.insert;\n await this.executeStatement(driver, statement);\n }\n\n private async recordLedgerEntry(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n existingMarker: ContractMarkerRecord | null,\n executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Promise<void> {\n const ledgerStatement = buildLedgerInsertStatement({\n originStorageHash: existingMarker?.storageHash ?? null,\n originProfileHash: existingMarker?.profileHash ?? null,\n destinationStorageHash: options.plan.destination.storageHash,\n destinationProfileHash:\n options.plan.destination.profileHash ??\n options.destinationContract.profileHash ??\n options.plan.destination.storageHash,\n contractJsonBefore: existingMarker?.contractJson ?? null,\n contractJsonAfter: options.destinationContract,\n operations: executedOperations,\n });\n await this.executeStatement(driver, ledgerStatement);\n }\n\n private async beginExclusiveTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('BEGIN EXCLUSIVE');\n }\n\n private async commitTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('COMMIT');\n }\n\n private async rollbackTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('ROLLBACK');\n }\n\n private async executeStatement(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n statement: SqlStatement,\n ): Promise<void> {\n if (statement.params.length > 0) {\n await driver.query(statement.sql, statement.params);\n return;\n }\n await driver.query(statement.sql);\n }\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport { SqlContractSerializerBase } from '@prisma-next/family-sql/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\n\n/**\n * SQLite target `ContractSerializer` concretion. Mirrors the Postgres\n * shape: inherits the full SQL-family deserialization pipeline. Today's\n * SQLite contract shape is the family-shared shape; no target-specific\n * polymorphic `storage.types` factories are registered yet.\n *\n * `serializeContract` falls through to the family-base default —\n * SQLite's contract is JSON-clean today. Once target-only fields land\n * (e.g. per-target derived storage fields) this is the home for\n * stripping them from the persisted envelope.\n */\nexport class SqliteContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor() {\n super(new Map());\n }\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport { SqlSchemaVerifierBase } from '@prisma-next/family-sql/ir';\nimport type { SchemaIssue, SchemaVerifyOptions } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\n\n/**\n * SQLite target `SchemaVerifier` concretion. Mirrors the Postgres\n * shape: hooks return the empty list pending the call-site migration\n * that routes the existing verifier behaviour through the SPI.\n */\nexport class SqliteSchemaVerifier extends SqlSchemaVerifierBase<Contract<SqlStorage>, SqlSchemaIR> {\n protected verifyCommonSqlSchema(\n _options: SchemaVerifyOptions<Contract<SqlStorage>, SqlSchemaIR>,\n ): readonly SchemaIssue[] {\n return [];\n }\n\n protected verifyTargetExtensions(\n _options: SchemaVerifyOptions<Contract<SqlStorage>, SqlSchemaIR>,\n ): readonly SchemaIssue[] {\n return [];\n }\n}\n","import type { ColumnDefault, Contract } from '@prisma-next/contract/types';\nimport type {\n SqlControlFamilyInstance,\n SqlControlTargetDescriptor,\n} from '@prisma-next/family-sql/control';\nimport { contractToSchemaIR } from '@prisma-next/family-sql/control';\nimport type {\n ControlTargetInstance,\n MigrationPlanner,\n MigrationRunner,\n} from '@prisma-next/framework-components/control';\nimport { SqlStorage, type StorageColumn } from '@prisma-next/sql-contract/types';\nimport { sqliteTargetDescriptorMeta } from './descriptor-meta';\nimport { createSqliteMigrationPlanner } from './migrations/planner';\nimport { renderDefaultLiteral } from './migrations/planner-ddl-builders';\nimport type { SqlitePlanTargetDetails } from './migrations/planner-target-details';\nimport { createSqliteMigrationRunner } from './migrations/runner';\nimport { SqliteContractSerializer } from './sqlite-contract-serializer';\nimport { SqliteSchemaVerifier } from './sqlite-schema-verifier';\n\nfunction isSqlContract(contract: Contract | null): contract is Contract<SqlStorage> | null {\n return contract === null || contract.storage instanceof SqlStorage;\n}\n\nfunction sqliteRenderDefault(def: ColumnDefault, _column: StorageColumn): string {\n if (def.kind === 'function') {\n if (def.expression === 'now()') {\n return \"datetime('now')\";\n }\n return def.expression;\n }\n return renderDefaultLiteral(def.value);\n}\n\nconst sqliteControlTargetDescriptor: SqlControlTargetDescriptor<'sqlite', SqlitePlanTargetDetails> =\n {\n ...sqliteTargetDescriptorMeta,\n contractSerializer: new SqliteContractSerializer(),\n schemaVerifier: new SqliteSchemaVerifier(),\n migrations: {\n createPlanner(_family: SqlControlFamilyInstance): MigrationPlanner<'sql', 'sqlite'> {\n return createSqliteMigrationPlanner();\n },\n createRunner(family) {\n return createSqliteMigrationRunner(family) as MigrationRunner<'sql', 'sqlite'>;\n },\n contractToSchema(contract, _frameworkComponents) {\n // The framework SPI types `contract` as the generic\n // `Contract | null`. Any contract reaching the sqlite\n // target descriptor is SQL-family by construction (the\n // family contract resolver would have refused to bind a\n // sqlite target otherwise); the `isSqlContract` predicate\n // encodes that invariant at runtime + narrows the generic\n // to `Contract<SqlStorage>` without a blind cast.\n if (!isSqlContract(contract)) {\n throw new Error(\n 'sqliteControlTargetDescriptor.contractToSchema received a non-SQL contract; expected Contract<SqlStorage>',\n );\n }\n return contractToSchemaIR(contract, {\n annotationNamespace: 'sqlite',\n renderDefault: sqliteRenderDefault,\n });\n },\n },\n create(): ControlTargetInstance<'sql', 'sqlite'> {\n return {\n familyId: 'sql',\n targetId: 'sqlite',\n };\n },\n createPlanner(_family: SqlControlFamilyInstance) {\n return createSqliteMigrationPlanner();\n },\n createRunner(family) {\n return createSqliteMigrationRunner(family);\n },\n };\n\nexport default sqliteControlTargetDescriptor;\n","import {\n freezeNode,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport type { StorageTable } from '@prisma-next/sql-contract/types';\n\n/**\n * SQLite target `Namespace` concretion. SQLite has no schema or\n * database-namespacing concept at the SQL level — there is exactly one\n * effective namespace per connection, so the target ships a single\n * singleton bound to the framework's `UNBOUND_NAMESPACE_ID` slot.\n *\n * Qualifier emission elides the prefix entirely: rendered DDL and\n * queries look unqualified (`CREATE TABLE \"users\" (...)`), matching\n * SQLite's native dialect. Call sites stay polymorphic — they ask the\n * namespace for its qualifier and consume the empty/unqualified result\n * the same way Postgres consumes a `\"schema\"` prefix.\n *\n * The SQLite PSL interpreter rejects every explicit `namespace { … }`\n * block with a diagnostic naming SQLite; only the implicit\n * `__unspecified__` AST bucket reaches the SQLite interpreter, which\n * lowers it to this singleton.\n */\nexport class SqliteUnboundDatabase extends NamespaceBase {\n static readonly instance: SqliteUnboundDatabase = new SqliteUnboundDatabase();\n\n readonly kind = 'database' as const;\n readonly id = UNBOUND_NAMESPACE_ID;\n readonly tables: Readonly<Record<string, StorageTable>>;\n\n private constructor() {\n super();\n this.tables = Object.freeze({});\n freezeNode(this);\n }\n\n qualifier(): string {\n return '';\n }\n\n qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n}\n\n/**\n * Target-supplied `Namespace` factory the SQLite target plumbs through\n * `defineContract({ createNamespace })`. SQLite has only one\n * effective namespace slot — the framework `UNBOUND_NAMESPACE_ID`\n * sentinel — so the factory always returns the singleton and rejects\n * any other coordinate. The SQL family's defensive validation in\n * `defineContract` already rejects user-declared SQLite namespaces, so\n * this throw is a structural safety net rather than a user-facing\n * surface.\n */\nexport function sqliteCreateNamespace(id: string): SqliteUnboundDatabase {\n if (id === UNBOUND_NAMESPACE_ID) {\n return SqliteUnboundDatabase.instance;\n }\n throw new Error(\n `sqliteCreateNamespace: SQLite has no schema concept; the only valid namespace id is \"${UNBOUND_NAMESPACE_ID}\" (received \"${id}\").`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,SAAgB,4BACd,QAC6C;CAC7C,OAAO,IAAI,sBAAsB,MAAM;AACzC;AAEA,IAAM,wBAAN,MAAmF;CACpD;CAA7B,YAAY,QAAmD;EAAlC,KAAA,SAAA;CAAmC;;;;;;;CAQhE,MAAM,oBACJ,SACmC;EACnC,MAAM,SAAS,QAAQ;EACvB,IAAI,QAAQ,UAAU,KAAA,KAAa,QAAQ,UAAU,QAAQ,KAAK,SAChE,MAAM,IAAI,MACR,sCAAsC,QAAQ,MAAM,iCAAiC,QAAQ,KAAK,QAAQ,EAC5G;EAEF,MAAM,QAAQ,QAAQ,KAAK;EAE3B,MAAM,mBAAmB,KAAK,qCAC5B,QAAQ,KAAK,aACb,QAAQ,mBACV;EACA,IAAI,CAAC,iBAAiB,IAAI,OAAO;EAEjC,MAAM,cAAc,KAAK,2BAA2B,QAAQ,QAAQ,QAAQ,KAAK,UAAU;EAC3F,IAAI,CAAC,YAAY,IAAI,OAAO;EAE5B,MAAM,eAAe,MAAM,KAAK,oBAAoB,MAAM;EAC1D,IAAI,CAAC,aAAa,IAAI,OAAO;EAC7B,MAAM,iBAAiB,MAAM,KAAK,WAAW,QAAQ,KAAK;EAE1D,MAAM,cAAc,KAAK,0BAA0B,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CACA,OAAO,qBAAqB,IAAI,KAAK;AACvC;AAEA,MAAM,gCACJ;CACE,GAAG;CACH,oBAAoB,IAAI,yBAAyB;CACjD,gBAAgB,IAAI,qBAAqB;CACzC,YAAY;EACV,cAAc,SAAsE;GAClF,OAAO,6BAA6B;EACtC;EACA,aAAa,QAAQ;GACnB,OAAO,4BAA4B,MAAM;EAC3C;EACA,iBAAiB,UAAU,sBAAsB;GAQ/C,IAAI,CAAC,cAAc,QAAQ,GACzB,MAAM,IAAI,MACR,2GACF;GAEF,OAAO,mBAAmB,UAAU;IAClC,qBAAqB;IACrB,eAAe;GACjB,CAAC;EACH;CACF;CACA,SAAiD;EAC/C,OAAO;GACL,UAAU;GACV,UAAU;EACZ;CACF;CACA,cAAc,SAAmC;EAC/C,OAAO,6BAA6B;CACtC;CACA,aAAa,QAAQ;EACnB,OAAO,4BAA4B,MAAM;CAC3C;AACF;;;;;;;;;;;;;;;;;;;;ACrDF,IAAa,wBAAb,MAAa,8BAA8B,cAAc;CACvD,OAAgB,WAAkC,IAAI,sBAAsB;CAE5E,OAAgB;CAChB,KAAc;CACd;CAEA,cAAsB;EACpB,MAAM;EACN,KAAK,SAAS,OAAO,OAAO,CAAC,CAAC;EAC9B,WAAW,IAAI;CACjB;CAEA,YAAoB;EAClB,OAAO;CACT;CAEA,aAAa,WAA2B;EACtC,OAAO,IAAI,UAAU;CACvB;AACF;;;;;;;;;;;AAYA,SAAgB,sBAAsB,IAAmC;CACvE,IAAI,OAAO,sBACT,OAAO,sBAAsB;CAE/B,MAAM,IAAI,MACR,wFAAwF,qBAAqB,eAAe,GAAG,IACjI;AACF"}
1
+ {"version":3,"file":"control.mjs","names":[],"sources":["../src/core/migrations/runner.ts","../src/core/sqlite-schema-verifier.ts","../src/core/control-target.ts"],"sourcesContent":["import type { Contract, ContractMarkerRecord } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlControlFamilyInstance,\n SqlMigrationPlanContractInfo,\n SqlMigrationPlanOperation,\n SqlMigrationPlanOperationStep,\n SqlMigrationRunner,\n SqlMigrationRunnerExecuteOptions,\n SqlMigrationRunnerFailure,\n SqlMigrationRunnerResult,\n SqlMigrationRunnerSuccessValue,\n} from '@prisma-next/family-sql/control';\nimport { runnerFailure, runnerSuccess } from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport type { MigrationRunnerResult } from '@prisma-next/framework-components/control';\nimport { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport type { SqlControlDriverInstance, SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { LoweredStatement } from '@prisma-next/sql-relational-core/ast';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok, okVoid } from '@prisma-next/utils/result';\nimport { MARKER_TABLE_NAME } from '../control-tables';\nimport { parseSqliteDefault } from '../default-normalizer';\nimport { normalizeSqliteNativeType } from '../native-type-normalizer';\nimport type { SqlitePlanTargetDetails } from './planner-target-details';\n\nexport function createSqliteMigrationRunner(\n family: SqlControlFamilyInstance,\n): SqlMigrationRunner<SqlitePlanTargetDetails> {\n return new SqliteMigrationRunner(family);\n}\n\nclass SqliteMigrationRunner implements SqlMigrationRunner<SqlitePlanTargetDetails> {\n constructor(private readonly family: SqlControlFamilyInstance) {}\n\n /**\n * Apply the plan against an already-open connection without managing\n * the transaction lifecycle. The caller ({@link SqliteMigrationRunner.execute})\n * owns BEGIN/COMMIT/ROLLBACK and any connection-level setup (FK pragma\n * toggle, FK integrity check).\n */\n async executeOnConnection(\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n ): Promise<SqlMigrationRunnerResult> {\n const driver = options.driver;\n if (options.space !== undefined && options.space !== options.plan.spaceId) {\n throw new Error(\n `SqlMigrationRunner: options.space (${options.space}) does not match plan.spaceId (${options.plan.spaceId})`,\n );\n }\n const space = options.plan.spaceId;\n\n const destinationCheck = this.ensurePlanMatchesDestinationContract(\n options.plan.destination,\n options.destinationContract,\n );\n if (!destinationCheck.ok) return destinationCheck;\n\n const policyCheck = this.enforcePolicyCompatibility(options.policy, options.plan.operations);\n if (!policyCheck.ok) return policyCheck;\n\n const ensureResult = await this.ensureControlTables(driver, options.destinationContract);\n if (!ensureResult.ok) return ensureResult;\n const existingMarker = await this.family.readMarker({ driver, space });\n\n const markerCheck = this.ensureMarkerCompatibility(existingMarker, options.plan);\n if (!markerCheck.ok) return markerCheck;\n\n const markerAtDestination = this.markerMatchesDestination(existingMarker, options.plan);\n const isSelfEdge = options.plan.origin?.storageHash === options.plan.destination.storageHash;\n const skipOperations = markerAtDestination && options.plan.origin != null && !isSelfEdge;\n\n let operationsExecuted: number;\n let executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[];\n\n if (skipOperations) {\n operationsExecuted = 0;\n executedOperations = [];\n } else {\n const applyResult = await this.applyPlan(driver, options);\n if (!applyResult.ok) return applyResult;\n operationsExecuted = applyResult.value.operationsExecuted;\n executedOperations = applyResult.value.executedOperations;\n }\n\n if (space === APP_SPACE_ID) {\n const schemaIR = await this.family.introspect({\n driver,\n contract: options.destinationContract,\n });\n\n const schemaVerifyResult = verifySqlSchema({\n contract: options.destinationContract,\n schema: schemaIR,\n strict: options.strictVerification ?? true,\n context: options.context ?? {},\n typeMetadataRegistry: this.family.typeMetadataRegistry,\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parseSqliteDefault,\n normalizeNativeType: normalizeSqliteNativeType,\n });\n if (!schemaVerifyResult.ok) {\n return runnerFailure('SCHEMA_VERIFY_FAILED', schemaVerifyResult.summary, {\n why: 'The resulting database schema does not satisfy the destination contract.',\n meta: { issues: schemaVerifyResult.schema.issues },\n });\n }\n }\n\n // Self-edge no-op detection: see Postgres runner for the rationale\n // (kept symmetric across both targets).\n const incomingInvariants = options.plan.providedInvariants;\n const existingInvariants = new Set(existingMarker?.invariants ?? []);\n const incomingIsSubsetOfExisting = incomingInvariants.every((id) => existingInvariants.has(id));\n const isSelfEdgeNoOp = isSelfEdge && operationsExecuted === 0 && incomingIsSubsetOfExisting;\n\n if (!isSelfEdgeNoOp) {\n const markerResult = await this.upsertMarker(driver, options, existingMarker, space);\n if (!markerResult.ok) return markerResult;\n await this.recordLedgerEntries(driver, options, executedOperations);\n }\n\n return runnerSuccess({\n operationsPlanned: options.plan.operations.length,\n operationsExecuted,\n });\n }\n\n async execute(options: {\n readonly driver: SqlControlDriverInstance<string>;\n readonly perSpaceOptions: ReadonlyArray<\n SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>\n >;\n }): Promise<MigrationRunnerResult> {\n const driver = options.driver;\n const perSpaceOptions = options.perSpaceOptions;\n\n if (perSpaceOptions.length === 0) {\n return ok({ perSpaceResults: [] });\n }\n\n // FK pragma toggle and the FK integrity check both span the outer\n // transaction: PRAGMA foreign_keys is a no-op inside a transaction, so the\n // toggle has to wrap BEGIN/COMMIT.\n const fkWasEnabled = await this.readForeignKeysEnabled(driver);\n if (fkWasEnabled) {\n await driver.query('PRAGMA foreign_keys = OFF');\n }\n\n try {\n await this.beginExclusiveTransaction(driver);\n let committed = false;\n try {\n const perSpaceResults: Array<{\n space: string;\n value: SqlMigrationRunnerSuccessValue;\n }> = [];\n let lastProcessedSpace: string | undefined;\n for (const spaceOptions of perSpaceOptions) {\n const space = spaceOptions.space ?? spaceOptions.plan.spaceId;\n const result = await this.executeOnConnection({ ...spaceOptions, driver, space });\n if (!result.ok) {\n return notOk({ ...result.failure, failingSpace: space });\n }\n perSpaceResults.push({ space, value: result.value });\n lastProcessedSpace = space;\n }\n\n if (fkWasEnabled) {\n const fkIntegrityCheck = await this.verifyForeignKeyIntegrity(driver);\n if (!fkIntegrityCheck.ok) {\n // Post-loop integrity violations cannot be attributed to a\n // single per-space step (the cumulative effect of all\n // applied plans was needed to reveal the broken\n // reference). Surface the last successfully-applied space\n // so operators can investigate from the most recent\n // migration first.\n return notOk({\n ...fkIntegrityCheck.failure,\n failingSpace: lastProcessedSpace ?? APP_SPACE_ID,\n });\n }\n }\n\n await this.commitTransaction(driver);\n committed = true;\n return ok({ perSpaceResults });\n } finally {\n if (!committed) {\n await this.rollbackTransaction(driver);\n }\n }\n } finally {\n if (fkWasEnabled) {\n await driver.query('PRAGMA foreign_keys = ON');\n }\n }\n }\n\n private async readForeignKeysEnabled(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<boolean> {\n const result = await driver.query<{ foreign_keys: number }>('PRAGMA foreign_keys');\n const row = result.rows[0];\n return row?.foreign_keys === 1;\n }\n\n private async verifyForeignKeyIntegrity(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const result = await driver.query<Record<string, unknown>>('PRAGMA foreign_key_check');\n if (result.rows.length === 0) {\n return okVoid();\n }\n return runnerFailure(\n 'FOREIGN_KEY_VIOLATION',\n `Foreign key integrity check failed after migration: ${result.rows.length} violation(s).`,\n {\n why: 'PRAGMA foreign_key_check reported violations after applying recreate-table operations.',\n meta: { violations: result.rows },\n },\n );\n }\n\n private async applyPlan(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n ): Promise<\n Result<\n {\n readonly operationsExecuted: number;\n readonly executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[];\n },\n SqlMigrationRunnerFailure\n >\n > {\n const checks = options.executionChecks;\n const runPrechecks = checks?.prechecks !== false;\n const runPostchecks = checks?.postchecks !== false;\n const runIdempotency = checks?.idempotencyChecks !== false;\n\n let operationsExecuted = 0;\n const executedOperations: Array<SqlMigrationPlanOperation<SqlitePlanTargetDetails>> = [];\n\n for (const operation of options.plan.operations) {\n options.callbacks?.onOperationStart?.(operation);\n try {\n if (runPostchecks && runIdempotency) {\n const postcheckAlreadySatisfied = await this.expectationsAreSatisfied(\n driver,\n operation.postcheck,\n );\n if (postcheckAlreadySatisfied) {\n executedOperations.push(this.createSkipRecord(operation));\n continue;\n }\n }\n\n if (runPrechecks) {\n const precheckResult = await this.runExpectationSteps(\n driver,\n operation.precheck,\n operation,\n 'precheck',\n );\n if (!precheckResult.ok) {\n return precheckResult;\n }\n }\n\n const executeResult = await this.runExecuteSteps(driver, operation.execute, operation);\n if (!executeResult.ok) {\n return executeResult;\n }\n\n if (runPostchecks) {\n const postcheckResult = await this.runExpectationSteps(\n driver,\n operation.postcheck,\n operation,\n 'postcheck',\n );\n if (!postcheckResult.ok) {\n return postcheckResult;\n }\n }\n\n executedOperations.push(operation);\n operationsExecuted += 1;\n } finally {\n options.callbacks?.onOperationComplete?.(operation);\n }\n }\n return ok({ operationsExecuted, executedOperations });\n }\n\n private async ensureControlTables(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n contract: Contract<SqlStorage>,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const legacyDetection = await this.detectLegacyMarkerShape(driver);\n if (!legacyDetection.ok) {\n return legacyDetection;\n }\n const lowererContext = { contract };\n for (const query of this.family.bootstrapControlTableQueries()) {\n await this.executeStatement(driver, this.family.lowerAst(query, lowererContext));\n }\n return okVoid();\n }\n\n private async detectLegacyMarkerShape(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const tableInfo = await driver.query<{ name: string }>(\n `PRAGMA table_info(\"${MARKER_TABLE_NAME}\")`,\n );\n if (tableInfo.rows.length === 0) {\n return okVoid();\n }\n const columns = new Set(tableInfo.rows.map((row) => row.name));\n if (columns.has('space')) {\n return okVoid();\n }\n return runnerFailure(\n 'LEGACY_MARKER_SHAPE',\n `Legacy marker-table shape detected on ${MARKER_TABLE_NAME} (no \\`space\\` column). ` +\n 'Prisma Next is in pre-1.0; the previous transitional auto-migration to the per-space-row schema has been removed. ' +\n `Drop \\`${MARKER_TABLE_NAME}\\` and re-run \\`dbInit\\` to reinitialise from a clean baseline.`,\n {\n meta: {\n table: MARKER_TABLE_NAME,\n columns: [...columns].sort(),\n },\n },\n );\n }\n\n private async runExpectationSteps(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n phase: 'precheck' | 'postcheck',\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n for (const step of steps) {\n const result = await driver.query(step.sql, step.params ?? []);\n if (!this.stepResultIsTrue(result.rows)) {\n const code = phase === 'precheck' ? 'PRECHECK_FAILED' : 'POSTCHECK_FAILED';\n return runnerFailure(\n code,\n `Operation ${operation.id} failed during ${phase}: ${step.description}`,\n {\n meta: {\n operationId: operation.id,\n phase,\n stepDescription: step.description,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private async runExecuteSteps(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n for (const step of steps) {\n try {\n await driver.query(step.sql, step.params ?? []);\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n return runnerFailure(\n 'EXECUTION_FAILED',\n `Operation ${operation.id} failed during execution: ${step.description}`,\n {\n why: message,\n meta: {\n operationId: operation.id,\n stepDescription: step.description,\n sql: step.sql,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private stepResultIsTrue(rows: readonly Record<string, unknown>[]): boolean {\n if (!rows || rows.length === 0) {\n return false;\n }\n const firstRow = rows[0];\n const firstValue = firstRow ? Object.values(firstRow)[0] : undefined;\n if (typeof firstValue === 'number') {\n return firstValue !== 0;\n }\n if (typeof firstValue === 'boolean') {\n return firstValue;\n }\n if (typeof firstValue === 'string') {\n const lower = firstValue.toLowerCase();\n if (lower === 'true' || lower === '1') return true;\n if (lower === 'false' || lower === '0') return false;\n return firstValue.length > 0;\n }\n return Boolean(firstValue);\n }\n\n private async expectationsAreSatisfied(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n ): Promise<boolean> {\n if (steps.length === 0) {\n return false;\n }\n for (const step of steps) {\n const result = await driver.query(step.sql, step.params ?? []);\n if (!this.stepResultIsTrue(result.rows)) {\n return false;\n }\n }\n return true;\n }\n\n private createSkipRecord(\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n ): SqlMigrationPlanOperation<SqlitePlanTargetDetails> {\n return Object.freeze({\n id: operation.id,\n label: operation.label,\n ...ifDefined('summary', operation.summary),\n operationClass: operation.operationClass,\n target: operation.target,\n precheck: Object.freeze([]),\n execute: Object.freeze([]),\n postcheck: Object.freeze([...operation.postcheck]),\n meta: Object.freeze({\n ...(operation.meta ?? {}),\n runner: Object.freeze({ skipped: true, reason: 'postcheck_pre_satisfied' }),\n }),\n });\n }\n\n private markerMatchesDestination(\n marker: ContractMarkerRecord | null,\n plan: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['plan'],\n ): boolean {\n if (!marker) return false;\n if (marker.storageHash !== plan.destination.storageHash) return false;\n if (plan.destination.profileHash && marker.profileHash !== plan.destination.profileHash) {\n return false;\n }\n return true;\n }\n\n private enforcePolicyCompatibility(\n policy: MigrationOperationPolicy,\n operations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Result<void, SqlMigrationRunnerFailure> {\n const allowedClasses = new Set(policy.allowedOperationClasses);\n for (const operation of operations) {\n if (!allowedClasses.has(operation.operationClass)) {\n return runnerFailure(\n 'POLICY_VIOLATION',\n `Operation ${operation.id} has class \"${operation.operationClass}\" which is not allowed by policy.`,\n {\n why: `Policy only allows: ${policy.allowedOperationClasses.join(', ')}.`,\n meta: {\n operationId: operation.id,\n operationClass: operation.operationClass,\n allowedClasses: policy.allowedOperationClasses,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private ensureMarkerCompatibility(\n marker: ContractMarkerRecord | null,\n plan: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['plan'],\n ): Result<void, SqlMigrationRunnerFailure> {\n const origin = plan.origin ?? null;\n if (!origin) {\n return okVoid();\n }\n if (!marker) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Missing contract marker: expected origin storage hash ${origin.storageHash}.`,\n { meta: { expectedOriginStorageHash: origin.storageHash } },\n );\n }\n if (marker.storageHash !== origin.storageHash) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Existing contract marker (${marker.storageHash}) does not match plan origin (${origin.storageHash}).`,\n {\n meta: {\n markerStorageHash: marker.storageHash,\n expectedOriginStorageHash: origin.storageHash,\n },\n },\n );\n }\n if (origin.profileHash && marker.profileHash !== origin.profileHash) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Existing contract marker profile hash (${marker.profileHash}) does not match plan origin profile hash (${origin.profileHash}).`,\n {\n meta: {\n markerProfileHash: marker.profileHash,\n expectedOriginProfileHash: origin.profileHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private ensurePlanMatchesDestinationContract(\n destination: SqlMigrationPlanContractInfo,\n contract: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['destinationContract'],\n ): Result<void, SqlMigrationRunnerFailure> {\n if (destination.storageHash !== contract.storage.storageHash) {\n return runnerFailure(\n 'DESTINATION_CONTRACT_MISMATCH',\n `Plan destination storage hash (${destination.storageHash}) does not match provided contract storage hash (${contract.storage.storageHash}).`,\n {\n meta: {\n planStorageHash: destination.storageHash,\n contractStorageHash: contract.storage.storageHash,\n },\n },\n );\n }\n if (\n destination.profileHash &&\n contract.profileHash &&\n destination.profileHash !== contract.profileHash\n ) {\n return runnerFailure(\n 'DESTINATION_CONTRACT_MISMATCH',\n `Plan destination profile hash (${destination.profileHash}) does not match provided contract profile hash (${contract.profileHash}).`,\n {\n meta: {\n planProfileHash: destination.profileHash,\n contractProfileHash: contract.profileHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private async upsertMarker(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n existingMarker: ContractMarkerRecord | null,\n space: string,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n // Pass the plan's incoming invariants verbatim; `updateMarker` unions them\n // with the stored set (TS-side, dialect-uniform) under the runner's\n // BEGIN EXCLUSIVE — no client-side pre-merge here, so there is no\n // double-merge with the SPI's internal accumulate-dedupe.\n const destination = {\n storageHash: options.plan.destination.storageHash,\n profileHash:\n options.plan.destination.profileHash ??\n options.destinationContract.profileHash ??\n options.plan.destination.storageHash,\n invariants: options.plan.providedInvariants ?? [],\n };\n if (!existingMarker) {\n await this.family.initMarker({ driver, space, destination });\n return okVoid();\n }\n const updated = await this.family.updateMarker({\n driver,\n space,\n expectedFrom: existingMarker.storageHash,\n destination,\n });\n if (!updated) {\n return runnerFailure(\n 'MARKER_CAS_FAILURE',\n 'Marker was modified by another process during migration execution.',\n {\n meta: {\n space,\n expectedStorageHash: existingMarker.storageHash,\n destinationStorageHash: options.plan.destination.storageHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private async recordLedgerEntries(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Promise<void> {\n const plan = options.plan;\n const space = plan.spaceId;\n const edges = options.migrationEdges;\n const totalEdgeOps = edges.reduce((sum, edge) => sum + edge.operationCount, 0);\n if (totalEdgeOps !== plan.operations.length) {\n throw new Error(\n `Ledger write: plan.operations length (${plan.operations.length}) does not match sum of migrationEdges operationCount (${totalEdgeOps})`,\n );\n }\n // The ledger records the operations as executed — idempotency-skipped ops\n // are substituted with skip records (empty `execute`) by `applyPlan`, so the\n // journal reflects what actually ran rather than the raw plan.\n let offset = 0;\n for (const edge of edges) {\n const edgeOps = executedOperations.slice(offset, offset + edge.operationCount);\n offset += edge.operationCount;\n await this.family.writeLedgerEntry({\n driver,\n space,\n entry: {\n edgeId: `${edge.from}->${edge.to}`,\n from: edge.from,\n to: edge.to,\n migrationName: edge.dirName,\n migrationHash: edge.migrationHash,\n operations: edgeOps,\n },\n });\n }\n }\n\n private async beginExclusiveTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('BEGIN EXCLUSIVE');\n }\n\n private async commitTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('COMMIT');\n }\n\n private async rollbackTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('ROLLBACK');\n }\n\n private async executeStatement(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n statement: LoweredStatement,\n ): Promise<void> {\n if (statement.params.length > 0) {\n await driver.query(statement.sql, statement.params);\n return;\n }\n await driver.query(statement.sql);\n }\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport { SqlSchemaVerifierBase } from '@prisma-next/family-sql/ir';\nimport type { SchemaIssue, SchemaVerifyOptions } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\n\n/**\n * SQLite target `SchemaVerifier` concretion. Mirrors the Postgres\n * shape: hooks return the empty list pending the call-site migration\n * that routes the existing verifier behaviour through the SPI.\n */\nexport class SqliteSchemaVerifier extends SqlSchemaVerifierBase<Contract<SqlStorage>, SqlSchemaIR> {\n protected verifyCommonSqlSchema(\n _options: SchemaVerifyOptions<Contract<SqlStorage>, SqlSchemaIR>,\n ): readonly SchemaIssue[] {\n return [];\n }\n\n protected verifyTargetExtensions(\n _options: SchemaVerifyOptions<Contract<SqlStorage>, SqlSchemaIR>,\n ): readonly SchemaIssue[] {\n return [];\n }\n}\n","import type { ColumnDefault, Contract } from '@prisma-next/contract/types';\nimport type { SqlControlTargetDescriptor } from '@prisma-next/family-sql/control';\nimport { contractToSchemaIR } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport type {\n ControlTargetInstance,\n MigrationPlanner,\n MigrationRunner,\n} from '@prisma-next/framework-components/control';\nimport { SqlStorage, type StorageColumn } from '@prisma-next/sql-contract/types';\nimport { sqliteTargetDescriptorMeta } from './descriptor-meta';\nimport { createSqliteMigrationPlanner } from './migrations/planner';\nimport { renderDefaultLiteral } from './migrations/planner-ddl-builders';\nimport type { SqlitePlanTargetDetails } from './migrations/planner-target-details';\nimport { createSqliteMigrationRunner } from './migrations/runner';\nimport { SqliteContractSerializer } from './sqlite-contract-serializer';\nimport { SqliteSchemaVerifier } from './sqlite-schema-verifier';\n\nfunction isSqlContract(contract: Contract | null): contract is Contract<SqlStorage> | null {\n return contract === null || contract.storage instanceof SqlStorage;\n}\n\nfunction sqliteRenderDefault(def: ColumnDefault, _column: StorageColumn): string {\n if (def.kind === 'function') {\n if (def.expression === 'now()') {\n return \"datetime('now')\";\n }\n return def.expression;\n }\n return renderDefaultLiteral(def.value);\n}\n\nconst sqliteControlTargetDescriptor: SqlControlTargetDescriptor<'sqlite', SqlitePlanTargetDetails> =\n {\n ...sqliteTargetDescriptorMeta,\n contractSerializer: new SqliteContractSerializer(),\n schemaVerifier: new SqliteSchemaVerifier(),\n migrations: {\n createPlanner(_adapter: SqlControlAdapter<'sqlite'>): MigrationPlanner<'sql', 'sqlite'> {\n return createSqliteMigrationPlanner();\n },\n createRunner(family) {\n return createSqliteMigrationRunner(family) as MigrationRunner<'sql', 'sqlite'>;\n },\n contractToSchema(contract, _frameworkComponents) {\n // The framework SPI types `contract` as the generic\n // `Contract | null`. Any contract reaching the sqlite\n // target descriptor is SQL-family by construction (the\n // family contract resolver would have refused to bind a\n // sqlite target otherwise); the `isSqlContract` predicate\n // encodes that invariant at runtime + narrows the generic\n // to `Contract<SqlStorage>` without a blind cast.\n if (!isSqlContract(contract)) {\n throw new Error(\n 'sqliteControlTargetDescriptor.contractToSchema received a non-SQL contract; expected Contract<SqlStorage>',\n );\n }\n return contractToSchemaIR(contract, {\n annotationNamespace: 'sqlite',\n renderDefault: sqliteRenderDefault,\n });\n },\n },\n create(): ControlTargetInstance<'sql', 'sqlite'> {\n return {\n familyId: 'sql',\n targetId: 'sqlite',\n };\n },\n createPlanner(_adapter: SqlControlAdapter<'sqlite'>) {\n return createSqliteMigrationPlanner();\n },\n createRunner(family) {\n return createSqliteMigrationRunner(family);\n },\n };\n\nexport default sqliteControlTargetDescriptor;\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,SAAgB,4BACd,QAC6C;CAC7C,OAAO,IAAI,sBAAsB,MAAM;AACzC;AAEA,IAAM,wBAAN,MAAmF;CACpD;CAA7B,YAAY,QAAmD;EAAlC,KAAA,SAAA;CAAmC;;;;;;;CAQhE,MAAM,oBACJ,SACmC;EACnC,MAAM,SAAS,QAAQ;EACvB,IAAI,QAAQ,UAAU,KAAA,KAAa,QAAQ,UAAU,QAAQ,KAAK,SAChE,MAAM,IAAI,MACR,sCAAsC,QAAQ,MAAM,iCAAiC,QAAQ,KAAK,QAAQ,EAC5G;EAEF,MAAM,QAAQ,QAAQ,KAAK;EAE3B,MAAM,mBAAmB,KAAK,qCAC5B,QAAQ,KAAK,aACb,QAAQ,mBACV;EACA,IAAI,CAAC,iBAAiB,IAAI,OAAO;EAEjC,MAAM,cAAc,KAAK,2BAA2B,QAAQ,QAAQ,QAAQ,KAAK,UAAU;EAC3F,IAAI,CAAC,YAAY,IAAI,OAAO;EAE5B,MAAM,eAAe,MAAM,KAAK,oBAAoB,QAA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;EAC3B,IAAI,IAAI,eAAe,SACrB,OAAO;EAET,OAAO,IAAI;CACb;CACA,OAAO,qBAAqB,IAAI,KAAK;AACvC;AAEA,MAAM,gCACJ;CACE,GAAG;CACH,oBAAoB,IAAI,yBAAyB;CACjD,gBAAgB,IAAI,qBAAqB;CACzC,YAAY;EACV,cAAc,UAA0E;GACtF,OAAO,6BAA6B;EACtC;EACA,aAAa,QAAQ;GACnB,OAAO,4BAA4B,MAAM;EAC3C;EACA,iBAAiB,UAAU,sBAAsB;GAQ/C,IAAI,CAAC,cAAc,QAAQ,GACzB,MAAM,IAAI,MACR,2GACF;GAEF,OAAO,mBAAmB,UAAU;IAClC,qBAAqB;IACrB,eAAe;GACjB,CAAC;EACH;CACF;CACA,SAAiD;EAC/C,OAAO;GACL,UAAU;GACV,UAAU;EACZ;CACF;CACA,cAAc,UAAuC;EACnD,OAAO,6BAA6B;CACtC;CACA,aAAa,QAAQ;EACnB,OAAO,4BAA4B,MAAM;CAC3C;AACF"}
package/dist/ddl.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ import { i as SqliteDdlVisitor, n as SqliteCreateTable, r as SqliteDdlNode, t as AnySqliteDdlNode } from "./nodes-VzaaeUTb.mjs";
2
+ export { type AnySqliteDdlNode, SqliteCreateTable, SqliteDdlNode, type SqliteDdlVisitor };
package/dist/ddl.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { n as SqliteDdlNode, t as SqliteCreateTable } from "./nodes-D0k4z7NL.mjs";
2
+ export { SqliteCreateTable, SqliteDdlNode };
@@ -66,4 +66,4 @@ function parseSqliteDefault(rawDefault, nativeType) {
66
66
  //#endregion
67
67
  export { stripOuterParens as n, parseSqliteDefault as t };
68
68
 
69
- //# sourceMappingURL=default-normalizer-3Fccw7yw.mjs.map
69
+ //# sourceMappingURL=default-normalizer-DuoHj9-O.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"default-normalizer-3Fccw7yw.mjs","names":[],"sources":["../src/core/default-normalizer.ts"],"sourcesContent":["/**\n * Normalizes SQLite's stored default expressions back into the\n * `ColumnDefault` shape the verifier compares against. Lives target-side\n * (mirroring Postgres's `target-postgres/src/core/default-normalizer.ts`)\n * so both the control adapter (`SqliteControlAdapter.introspect`) and the\n * planner / runner schema-verify path can consume it without\n * `target-sqlite` reaching into `adapter-sqlite`.\n */\n\nimport type { ColumnDefault } from '@prisma-next/contract/types';\n\nconst NULL_PATTERN = /^NULL$/i;\nconst INTEGER_PATTERN = /^-?\\d+$/;\nconst REAL_PATTERN = /^-?\\d+\\.\\d+(?:[eE][+-]?\\d+)?$/;\nconst HEX_PATTERN = /^0[xX][\\dA-Fa-f]+$/;\nconst STRING_LITERAL_PATTERN = /^'((?:[^']|'')*)'$/;\n\nfunction isNumericLiteral(value: string): boolean {\n return INTEGER_PATTERN.test(value) || REAL_PATTERN.test(value) || HEX_PATTERN.test(value);\n}\n\n/**\n * Strips a single matched wrapping pair of outer parens from `s`. Conservative:\n * only strips when the leading `(` is matched by the trailing `)` (so\n * `(a) + (b)` is returned unchanged). Mirrors SQLite's own\n * `pragma_table_info.dflt_value` normalization for expression defaults, and\n * is shared with the recreate-table postcheck builder so both sides agree\n * on the canonical form.\n */\nexport function stripOuterParens(s: string): string {\n if (!s.startsWith('(') || !s.endsWith(')')) return s;\n let depth = 0;\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '(') depth += 1;\n else if (s[i] === ')') {\n depth -= 1;\n if (depth === 0 && i < s.length - 1) return s;\n }\n }\n return s.slice(1, -1);\n}\n\nexport function parseSqliteDefault(\n rawDefault: string,\n nativeType?: string,\n): ColumnDefault | undefined {\n let trimmed = rawDefault.trim();\n\n // Strip outer parentheses that SQLite adds around expressions. Iterate to\n // fixpoint so accidental double-wrapping (e.g. `((expr))`) collapses too.\n while (true) {\n const stripped = stripOuterParens(trimmed).trim();\n if (stripped === trimmed) break;\n trimmed = stripped;\n }\n\n // SQLite has several spellings for \"current timestamp\" — `CURRENT_TIMESTAMP`\n // (keyword) and `datetime('now')` / `datetime(\"now\")` (function call). The\n // contract authoring side canonicalizes `dbgenerated(\"CURRENT_TIMESTAMP\")`\n // (and friends) to `now()` via `lowerDbgenerated`; mirror that here so a\n // schema produced by either spelling round-trips to the same canonical\n // form for verification.\n const lower = trimmed.toLowerCase();\n if (lower === 'current_timestamp' || lower === \"datetime('now')\" || lower === 'datetime(\"now\")') {\n return { kind: 'function', expression: 'now()' };\n }\n\n if (NULL_PATTERN.test(trimmed)) {\n return { kind: 'literal', value: null };\n }\n\n // SQLite integers are 64-bit, so values outside the JS safe-integer range can't\n // be faithfully represented as `number`. Mirror `parsePostgresDefault`'s bigint\n // handling: parse as JS `number` when safe, fall back to the raw text otherwise.\n if (isNumericLiteral(trimmed)) {\n const num = Number(trimmed);\n if (!Number.isFinite(num)) return undefined;\n if (nativeType?.toLowerCase() === 'integer' && !Number.isSafeInteger(num)) {\n return { kind: 'literal', value: trimmed };\n }\n return { kind: 'literal', value: num };\n }\n\n const stringMatch = trimmed.match(STRING_LITERAL_PATTERN);\n if (stringMatch?.[1] !== undefined) {\n const unescaped = stringMatch[1].replace(/''/g, \"'\");\n return { kind: 'literal', value: unescaped };\n }\n\n // Unrecognized expression — preserve as function\n return { kind: 'function', expression: trimmed };\n}\n"],"mappings":";AAWA,MAAM,eAAe;AACrB,MAAM,kBAAkB;AACxB,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,yBAAyB;AAE/B,SAAS,iBAAiB,OAAwB;CAChD,OAAO,gBAAgB,KAAK,KAAK,KAAK,aAAa,KAAK,KAAK,KAAK,YAAY,KAAK,KAAK;AAC1F;;;;;;;;;AAUA,SAAgB,iBAAiB,GAAmB;CAClD,IAAI,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC,EAAE,SAAS,GAAG,GAAG,OAAO;CACnD,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAC5B,IAAI,EAAE,OAAO,KAAK,SAAS;MACtB,IAAI,EAAE,OAAO,KAAK;EACrB,SAAS;EACT,IAAI,UAAU,KAAK,IAAI,EAAE,SAAS,GAAG,OAAO;CAC9C;CAEF,OAAO,EAAE,MAAM,GAAG,EAAE;AACtB;AAEA,SAAgB,mBACd,YACA,YAC2B;CAC3B,IAAI,UAAU,WAAW,KAAK;CAI9B,OAAO,MAAM;EACX,MAAM,WAAW,iBAAiB,OAAO,EAAE,KAAK;EAChD,IAAI,aAAa,SAAS;EAC1B,UAAU;CACZ;CAQA,MAAM,QAAQ,QAAQ,YAAY;CAClC,IAAI,UAAU,uBAAuB,UAAU,qBAAqB,UAAU,qBAC5E,OAAO;EAAE,MAAM;EAAY,YAAY;CAAQ;CAGjD,IAAI,aAAa,KAAK,OAAO,GAC3B,OAAO;EAAE,MAAM;EAAW,OAAO;CAAK;CAMxC,IAAI,iBAAiB,OAAO,GAAG;EAC7B,MAAM,MAAM,OAAO,OAAO;EAC1B,IAAI,CAAC,OAAO,SAAS,GAAG,GAAG,OAAO,KAAA;EAClC,IAAI,YAAY,YAAY,MAAM,aAAa,CAAC,OAAO,cAAc,GAAG,GACtE,OAAO;GAAE,MAAM;GAAW,OAAO;EAAQ;EAE3C,OAAO;GAAE,MAAM;GAAW,OAAO;EAAI;CACvC;CAEA,MAAM,cAAc,QAAQ,MAAM,sBAAsB;CACxD,IAAI,cAAc,OAAO,KAAA,GAEvB,OAAO;EAAE,MAAM;EAAW,OADR,YAAY,GAAG,QAAQ,OAAO,GACP;CAAE;CAI7C,OAAO;EAAE,MAAM;EAAY,YAAY;CAAQ;AACjD"}
1
+ {"version":3,"file":"default-normalizer-DuoHj9-O.mjs","names":[],"sources":["../src/core/default-normalizer.ts"],"sourcesContent":["/**\n * Normalizes SQLite's stored default expressions back into the\n * `ColumnDefault` shape the verifier compares against. Lives target-side\n * (mirroring Postgres's `target-postgres/src/core/default-normalizer.ts`)\n * so both the control adapter (`SqliteControlAdapter.introspect`) and the\n * planner / runner schema-verify path can consume it without\n * `target-sqlite` reaching into `adapter-sqlite`.\n */\n\nimport type { ColumnDefault } from '@prisma-next/contract/types';\n\nconst NULL_PATTERN = /^NULL$/i;\nconst INTEGER_PATTERN = /^-?\\d+$/;\nconst REAL_PATTERN = /^-?\\d+\\.\\d+(?:[eE][+-]?\\d+)?$/;\nconst HEX_PATTERN = /^0[xX][\\dA-Fa-f]+$/;\nconst STRING_LITERAL_PATTERN = /^'((?:[^']|'')*)'$/;\n\nfunction isNumericLiteral(value: string): boolean {\n return INTEGER_PATTERN.test(value) || REAL_PATTERN.test(value) || HEX_PATTERN.test(value);\n}\n\n/**\n * Strips a single matched wrapping pair of outer parens from `s`. Conservative:\n * only strips when the leading `(` is matched by the trailing `)` (so\n * `(a) + (b)` is returned unchanged). Mirrors SQLite's own\n * `pragma_table_info.dflt_value` normalization for expression defaults, and\n * is shared with the recreate-table postcheck builder so both sides agree\n * on the canonical form.\n */\nexport function stripOuterParens(s: string): string {\n if (!s.startsWith('(') || !s.endsWith(')')) return s;\n let depth = 0;\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '(') depth += 1;\n else if (s[i] === ')') {\n depth -= 1;\n if (depth === 0 && i < s.length - 1) return s;\n }\n }\n return s.slice(1, -1);\n}\n\nexport function parseSqliteDefault(\n rawDefault: string,\n nativeType?: string,\n): ColumnDefault | undefined {\n let trimmed = rawDefault.trim();\n\n // Strip outer parentheses that SQLite adds around expressions. Iterate to\n // fixpoint so accidental double-wrapping (e.g. `((expr))`) collapses too.\n while (true) {\n const stripped = stripOuterParens(trimmed).trim();\n if (stripped === trimmed) break;\n trimmed = stripped;\n }\n\n // SQLite has several spellings for \"current timestamp\" — `CURRENT_TIMESTAMP`\n // (keyword) and `datetime('now')` / `datetime(\"now\")` (function call). The\n // contract authoring side canonicalizes `dbgenerated(\"CURRENT_TIMESTAMP\")`\n // (and friends) to `now()` via `lowerDbgenerated`; mirror that here so a\n // schema produced by either spelling round-trips to the same canonical\n // form for verification.\n const lower = trimmed.toLowerCase();\n if (lower === 'current_timestamp' || lower === \"datetime('now')\" || lower === 'datetime(\"now\")') {\n return { kind: 'function', expression: 'now()' };\n }\n\n if (NULL_PATTERN.test(trimmed)) {\n return { kind: 'literal', value: null };\n }\n\n // SQLite integers are 64-bit, so values outside the JS safe-integer range can't\n // be faithfully represented as `number`. Mirror `parsePostgresDefault`'s bigint\n // handling: parse as JS `number` when safe, fall back to the raw text otherwise.\n if (isNumericLiteral(trimmed)) {\n const num = Number(trimmed);\n if (!Number.isFinite(num)) return undefined;\n if (nativeType?.toLowerCase() === 'integer' && !Number.isSafeInteger(num)) {\n return { kind: 'literal', value: trimmed };\n }\n return { kind: 'literal', value: num };\n }\n\n const stringMatch = trimmed.match(STRING_LITERAL_PATTERN);\n if (stringMatch?.[1] !== undefined) {\n const unescaped = stringMatch[1].replace(/''/g, \"'\");\n return { kind: 'literal', value: unescaped };\n }\n\n // Unrecognized expression — preserve as function\n return { kind: 'function', expression: trimmed };\n}\n"],"mappings":";AAWA,MAAM,eAAe;AACrB,MAAM,kBAAkB;AACxB,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,yBAAyB;AAE/B,SAAS,iBAAiB,OAAwB;CAChD,OAAO,gBAAgB,KAAK,KAAK,KAAK,aAAa,KAAK,KAAK,KAAK,YAAY,KAAK,KAAK;AAC1F;;;;;;;;;AAUA,SAAgB,iBAAiB,GAAmB;CAClD,IAAI,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC,EAAE,SAAS,GAAG,GAAG,OAAO;CACnD,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAC5B,IAAI,EAAE,OAAO,KAAK,SAAS;MACtB,IAAI,EAAE,OAAO,KAAK;EACrB,SAAS;EACT,IAAI,UAAU,KAAK,IAAI,EAAE,SAAS,GAAG,OAAO;CAC9C;CAEF,OAAO,EAAE,MAAM,GAAG,EAAE;AACtB;AAEA,SAAgB,mBACd,YACA,YAC2B;CAC3B,IAAI,UAAU,WAAW,KAAK;CAI9B,OAAO,MAAM;EACX,MAAM,WAAW,iBAAiB,OAAO,CAAC,CAAC,KAAK;EAChD,IAAI,aAAa,SAAS;EAC1B,UAAU;CACZ;CAQA,MAAM,QAAQ,QAAQ,YAAY;CAClC,IAAI,UAAU,uBAAuB,UAAU,qBAAqB,UAAU,qBAC5E,OAAO;EAAE,MAAM;EAAY,YAAY;CAAQ;CAGjD,IAAI,aAAa,KAAK,OAAO,GAC3B,OAAO;EAAE,MAAM;EAAW,OAAO;CAAK;CAMxC,IAAI,iBAAiB,OAAO,GAAG;EAC7B,MAAM,MAAM,OAAO,OAAO;EAC1B,IAAI,CAAC,OAAO,SAAS,GAAG,GAAG,OAAO,KAAA;EAClC,IAAI,YAAY,YAAY,MAAM,aAAa,CAAC,OAAO,cAAc,GAAG,GACtE,OAAO;GAAE,MAAM;GAAW,OAAO;EAAQ;EAE3C,OAAO;GAAE,MAAM;GAAW,OAAO;EAAI;CACvC;CAEA,MAAM,cAAc,QAAQ,MAAM,sBAAsB;CACxD,IAAI,cAAc,OAAO,KAAA,GAEvB,OAAO;EAAE,MAAM;EAAW,OADR,YAAY,EAAE,CAAC,QAAQ,OAAO,GACP;CAAE;CAI7C,OAAO;EAAE,MAAM;EAAY,YAAY;CAAQ;AACjD"}
@@ -1,2 +1,2 @@
1
- import { t as parseSqliteDefault } from "./default-normalizer-3Fccw7yw.mjs";
1
+ import { t as parseSqliteDefault } from "./default-normalizer-DuoHj9-O.mjs";
2
2
  export { parseSqliteDefault };
@@ -0,0 +1,17 @@
1
+ import { t as sqliteTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-BkXK3OjD.mjs";
2
+ import { temporalAuthoringPresets } from "@prisma-next/family-sql/control";
3
+ import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
4
+ //#region src/core/authoring.ts
5
+ const sqliteAuthoringFieldPresets = { temporal: /* @__PURE__ */ temporalAuthoringPresets({
6
+ codecId: "sqlite/datetime@1",
7
+ nativeType: "text"
8
+ }) };
9
+ const sqliteTargetDescriptorMeta = {
10
+ ...sqliteTargetDescriptorMetaRuntime,
11
+ defaultNamespaceId: UNBOUND_NAMESPACE_ID,
12
+ authoring: { field: sqliteAuthoringFieldPresets }
13
+ };
14
+ //#endregion
15
+ export { sqliteTargetDescriptorMeta as t };
16
+
17
+ //# sourceMappingURL=descriptor-meta-Dxx2A6PT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-meta-Dxx2A6PT.mjs","names":[],"sources":["../src/core/authoring.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import { temporalAuthoringPresets } from '@prisma-next/family-sql/control';\nimport type { AuthoringFieldNamespace } from '@prisma-next/framework-components/authoring';\n\nexport const sqliteAuthoringFieldPresets = {\n temporal: /* @__PURE__ */ temporalAuthoringPresets({\n codecId: 'sqlite/datetime@1',\n nativeType: 'text',\n }),\n} as const satisfies AuthoringFieldNamespace;\n","import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { CodecTypes } from '../exports/codec-types';\nimport { sqliteAuthoringFieldPresets } from './authoring';\nimport { sqliteTargetDescriptorMetaRuntime } from './descriptor-meta-runtime';\n\nconst sqliteTargetDescriptorMetaBase = {\n ...sqliteTargetDescriptorMetaRuntime,\n defaultNamespaceId: UNBOUND_NAMESPACE_ID,\n authoring: {\n field: sqliteAuthoringFieldPresets,\n },\n} as const;\n\nexport const sqliteTargetDescriptorMeta: typeof sqliteTargetDescriptorMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = sqliteTargetDescriptorMetaBase;\n"],"mappings":";;;;AAGA,MAAa,8BAA8B,EACzC,UAA0B,yCAAyB;CACjD,SAAS;CACT,YAAY;AACd,CAAC,EACH;ACKA,MAAa,6BAET;CATF,GAAG;CACH,oBAAoB;CACpB,WAAW,EACT,OAAO,4BACT;AAKE"}
@@ -0,0 +1,12 @@
1
+ const sqliteTargetDescriptorMetaRuntime = {
2
+ kind: "target",
3
+ familyId: "sql",
4
+ targetId: "sqlite",
5
+ id: "sqlite",
6
+ version: "0.0.1",
7
+ capabilities: {}
8
+ };
9
+ //#endregion
10
+ export { sqliteTargetDescriptorMetaRuntime as t };
11
+
12
+ //# sourceMappingURL=descriptor-meta-runtime-BkXK3OjD.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-meta-runtime-BkXK3OjD.mjs","names":[],"sources":["../src/core/descriptor-meta-runtime.ts"],"sourcesContent":["// Runtime-safe slice of the sqlite target descriptor metadata.\n//\n// This file exists separately from ./descriptor-meta on purpose: the runtime\n// plane reads only `kind/familyId/targetId/id/version/capabilities` (plus the\n// `__codecTypes` phantom). The `authoring` slot lives on the pack/control\n// descriptor only, because authoring contributions are consumed at\n// contract-construction time by `assembleAuthoringContributions` (control\n// plane) and the PSL interpreter — never at runtime.\n//\n// Keeping the runtime closure free of the `./authoring` import is what lets\n// the bundler tree-shake `@prisma-next/family-sql/control` (and its\n// transitive `verify-sql-schema` chunk) out of the runtime entry. Do not\n// add an `authoring` field here — if you need to, the pack/control meta in\n// `./descriptor-meta` is the right place. See TML-2766 for context.\nimport type { CodecTypes } from '../exports/codec-types';\n\nconst sqliteTargetDescriptorMetaRuntimeBase = {\n kind: 'target',\n familyId: 'sql',\n targetId: 'sqlite',\n id: 'sqlite',\n version: '0.0.1',\n capabilities: {},\n} as const;\n\nexport const sqliteTargetDescriptorMetaRuntime: typeof sqliteTargetDescriptorMetaRuntimeBase & {\n readonly __codecTypes?: CodecTypes;\n} = sqliteTargetDescriptorMetaRuntimeBase;\n"],"mappings":"AAyBA,MAAa,oCAET;CAVF,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS;CACT,cAAc,CAAC;AAKb"}
@@ -1,5 +1,5 @@
1
- import { i as SqliteTableSpec, n as SqliteColumnSpec, r as SqliteIndexSpec, t as Op } from "./shared-qLsgTOZs.mjs";
2
- import { t as SqliteMigration } from "./sqlite-migration-DAb2NEX6.mjs";
1
+ import { i as SqliteTableSpec, n as SqliteColumnSpec, r as SqliteIndexSpec, t as Op } from "./shared-Dhc8mLK1.mjs";
2
+ import { t as SqliteMigration } from "./sqlite-migration-D4XGYzgQ.mjs";
3
3
  import { MigrationOperationClass } from "@prisma-next/family-sql/control";
4
4
  import { placeholder } from "@prisma-next/errors/migration";
5
5
  import { MigrationCLI } from "@prisma-next/cli/migration-cli";
@@ -1,6 +1,6 @@
1
- import { t as buildTargetDetails } from "./planner-target-details-Bm71XPKb.mjs";
2
- import { a as recreateTable, f as addColumn, i as dropTable, m as step, o as createIndex, p as dropColumn, r as createTable, s as dropIndex } from "./tables-DGRRJasz.mjs";
3
- import { t as SqliteMigration } from "./sqlite-migration-BBJktVVw.mjs";
1
+ import { t as buildTargetDetails } from "./planner-target-details-H8z9TFDg.mjs";
2
+ import { a as recreateTable, f as addColumn, i as dropTable, m as step, o as createIndex, p as dropColumn, r as createTable, s as dropIndex } from "./tables-CjB7vXCr.mjs";
3
+ import { t as SqliteMigration } from "./sqlite-migration-CUqgmzQH.mjs";
4
4
  import { placeholder } from "@prisma-next/errors/migration";
5
5
  import { MigrationCLI } from "@prisma-next/cli/migration-cli";
6
6
  //#region src/core/migrations/operations/data-transform.ts
@@ -11,4 +11,4 @@ function normalizeSqliteNativeType(nativeType) {
11
11
  //#endregion
12
12
  export { normalizeSqliteNativeType as t };
13
13
 
14
- //# sourceMappingURL=native-type-normalizer-BlN5XfD-.mjs.map
14
+ //# sourceMappingURL=native-type-normalizer-CiSyVmMP.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"native-type-normalizer-BlN5XfD-.mjs","names":[],"sources":["../src/core/native-type-normalizer.ts"],"sourcesContent":["/**\n * Canonicalizes SQLite native-type tokens for verifier comparison.\n * Lives target-side so the planner / runner / adapter all share the same\n * normalization without crossing the `target-sqlite` ↔ `adapter-sqlite`\n * boundary.\n */\nexport function normalizeSqliteNativeType(nativeType: string): string {\n return nativeType.trim().toLowerCase();\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,0BAA0B,YAA4B;CACpE,OAAO,WAAW,KAAK,EAAE,YAAY;AACvC"}
1
+ {"version":3,"file":"native-type-normalizer-CiSyVmMP.mjs","names":[],"sources":["../src/core/native-type-normalizer.ts"],"sourcesContent":["/**\n * Canonicalizes SQLite native-type tokens for verifier comparison.\n * Lives target-side so the planner / runner / adapter all share the same\n * normalization without crossing the `target-sqlite` ↔ `adapter-sqlite`\n * boundary.\n */\nexport function normalizeSqliteNativeType(nativeType: string): string {\n return nativeType.trim().toLowerCase();\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,0BAA0B,YAA4B;CACpE,OAAO,WAAW,KAAK,CAAC,CAAC,YAAY;AACvC"}
@@ -1,2 +1,2 @@
1
- import { t as normalizeSqliteNativeType } from "./native-type-normalizer-BlN5XfD-.mjs";
1
+ import { t as normalizeSqliteNativeType } from "./native-type-normalizer-CiSyVmMP.mjs";
2
2
  export { normalizeSqliteNativeType };