@prisma-next/target-sqlite 0.12.0-dev.17 → 0.12.0-dev.3
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.
- package/dist/{codec-ids-yG2RRHnw.d.mts → codec-ids-C4UfWqAE.d.mts} +1 -1
- package/dist/{codec-ids-yG2RRHnw.d.mts.map → codec-ids-C4UfWqAE.d.mts.map} +1 -1
- package/dist/codec-ids.d.mts +1 -1
- package/dist/{codec-types-CM7OkQLM.d.mts → codec-types-B2ci-b_W.d.mts} +2 -2
- package/dist/{codec-types-CM7OkQLM.d.mts.map → codec-types-B2ci-b_W.d.mts.map} +1 -1
- package/dist/codec-types.d.mts +2 -2
- package/dist/{codecs-t6YnHZkK.d.mts → codecs-DqDWNIKq.d.mts} +2 -2
- package/dist/{codecs-t6YnHZkK.d.mts.map → codecs-DqDWNIKq.d.mts.map} +1 -1
- package/dist/codecs.d.mts +1 -1
- package/dist/control.d.mts +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +89 -37
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-rKforwQA.mjs → descriptor-meta-DIbCXU65.mjs} +1 -3
- package/dist/descriptor-meta-DIbCXU65.mjs.map +1 -0
- package/dist/migration.d.mts +2 -2
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/pack.d.mts +1 -2
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-Cygvz9Wp.mjs → planner-BBvwGy0f.mjs} +3 -3
- package/dist/{planner-Cygvz9Wp.mjs.map → planner-BBvwGy0f.mjs.map} +1 -1
- package/dist/{planner-produced-sqlite-migration-BwFkd0br.d.mts → planner-produced-sqlite-migration-D4FSvPE4.d.mts} +3 -3
- package/dist/{planner-produced-sqlite-migration-BwFkd0br.d.mts.map → planner-produced-sqlite-migration-D4FSvPE4.d.mts.map} +1 -1
- package/dist/planner-produced-sqlite-migration.d.mts +1 -1
- package/dist/{planner-target-details-RVPqF2ug.d.mts → planner-target-details-B-VJkUsu.d.mts} +1 -1
- package/dist/{planner-target-details-RVPqF2ug.d.mts.map → planner-target-details-B-VJkUsu.d.mts.map} +1 -1
- package/dist/planner-target-details.d.mts +1 -1
- package/dist/planner.d.mts +2 -2
- package/dist/planner.mjs +1 -1
- package/dist/render-ops.d.mts +1 -1
- package/dist/runtime.d.mts +1 -17
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +1 -2
- package/dist/runtime.mjs.map +1 -1
- package/dist/{shared-Bw5G0I-c.d.mts → shared-DDOJntxk.d.mts} +2 -2
- package/dist/{shared-Bw5G0I-c.d.mts.map → shared-DDOJntxk.d.mts.map} +1 -1
- package/dist/{sqlite-migration-D-O3Glz1.d.mts → sqlite-migration-Feio34n3.d.mts} +2 -2
- package/dist/{sqlite-migration-D-O3Glz1.d.mts.map → sqlite-migration-Feio34n3.d.mts.map} +1 -1
- package/dist/{statement-builders-D1Q_i4sb.mjs → statement-builders-BiRmeyJM.mjs} +2 -14
- package/dist/statement-builders-BiRmeyJM.mjs.map +1 -0
- package/dist/statement-builders.d.mts +0 -3
- package/dist/statement-builders.d.mts.map +1 -1
- package/dist/statement-builders.mjs +1 -1
- package/package.json +18 -20
- package/src/core/descriptor-meta.ts +0 -2
- package/src/core/migrations/runner.ts +25 -53
- package/src/core/migrations/statement-builders.ts +1 -16
- package/src/core/sqlite-contract-serializer.ts +9 -38
- package/src/core/sqlite-unbound-database.ts +0 -30
- package/src/exports/runtime.ts +0 -1
- package/dist/contract-free.d.mts +0 -27
- package/dist/contract-free.d.mts.map +0 -1
- package/dist/contract-free.mjs +0 -80
- package/dist/contract-free.mjs.map +0 -1
- package/dist/ddl.d.mts +0 -2
- package/dist/ddl.mjs +0 -2
- package/dist/descriptor-meta-rKforwQA.mjs.map +0 -1
- package/dist/nodes-09ul6DNV.mjs +0 -28
- package/dist/nodes-09ul6DNV.mjs.map +0 -1
- package/dist/nodes-D8LGV4Yk.d.mts +0 -27
- package/dist/nodes-D8LGV4Yk.d.mts.map +0 -1
- package/dist/sqlite-contract-serializer-Hy7WQPea.mjs +0 -100
- package/dist/sqlite-contract-serializer-Hy7WQPea.mjs.map +0 -1
- package/dist/statement-builders-D1Q_i4sb.mjs.map +0 -1
- package/src/contract-free/control-bootstrap.ts +0 -54
- package/src/contract-free/ddl.ts +0 -21
- package/src/core/ddl/nodes.ts +0 -41
- package/src/exports/contract-free.ts +0 -5
- package/src/exports/ddl.ts +0 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ContractMarkerRecord } from '@prisma-next/contract/types';
|
|
2
2
|
import type {
|
|
3
3
|
MigrationOperationPolicy,
|
|
4
4
|
SqlControlFamilyInstance,
|
|
@@ -19,7 +19,6 @@ import type {
|
|
|
19
19
|
MigrationRunnerResult,
|
|
20
20
|
} from '@prisma-next/framework-components/control';
|
|
21
21
|
import { APP_SPACE_ID } from '@prisma-next/framework-components/control';
|
|
22
|
-
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
23
22
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
24
23
|
import type { Result } from '@prisma-next/utils/result';
|
|
25
24
|
import { notOk, ok, okVoid } from '@prisma-next/utils/result';
|
|
@@ -29,6 +28,8 @@ import type { SqlitePlanTargetDetails } from './planner-target-details';
|
|
|
29
28
|
import {
|
|
30
29
|
buildLedgerInsertStatement,
|
|
31
30
|
buildWriteMarkerStatements,
|
|
31
|
+
ensureLedgerTableStatement,
|
|
32
|
+
ensureMarkerTableStatement,
|
|
32
33
|
MARKER_TABLE_NAME,
|
|
33
34
|
readMarkerStatement,
|
|
34
35
|
type SqlStatement,
|
|
@@ -69,7 +70,7 @@ class SqliteMigrationRunner implements SqlMigrationRunner<SqlitePlanTargetDetail
|
|
|
69
70
|
const policyCheck = this.enforcePolicyCompatibility(options.policy, options.plan.operations);
|
|
70
71
|
if (!policyCheck.ok) return policyCheck;
|
|
71
72
|
|
|
72
|
-
const ensureResult = await this.ensureControlTables(driver
|
|
73
|
+
const ensureResult = await this.ensureControlTables(driver);
|
|
73
74
|
if (!ensureResult.ok) return ensureResult;
|
|
74
75
|
const existingMarker = await this.readMarker(driver, space);
|
|
75
76
|
|
|
@@ -126,7 +127,7 @@ class SqliteMigrationRunner implements SqlMigrationRunner<SqlitePlanTargetDetail
|
|
|
126
127
|
|
|
127
128
|
if (!isSelfEdgeNoOp) {
|
|
128
129
|
await this.upsertMarker(driver, options, existingMarker, space);
|
|
129
|
-
await this.
|
|
130
|
+
await this.recordLedgerEntry(driver, options, existingMarker, executedOperations);
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
return runnerSuccess({
|
|
@@ -305,16 +306,17 @@ class SqliteMigrationRunner implements SqlMigrationRunner<SqlitePlanTargetDetail
|
|
|
305
306
|
|
|
306
307
|
private async ensureControlTables(
|
|
307
308
|
driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],
|
|
308
|
-
contract: Contract<SqlStorage>,
|
|
309
309
|
): Promise<Result<void, SqlMigrationRunnerFailure>> {
|
|
310
|
+
// Pre-1.0 zero-range guardrail: detect a pre-cleanup single-row
|
|
311
|
+
// marker table (no `space` column) and surface a structured failure
|
|
312
|
+
// rather than silently rebuilding the table into the per-space
|
|
313
|
+
// shape. See `specs/framework-mechanism.spec.md § 2`.
|
|
310
314
|
const legacyDetection = await this.detectLegacyMarkerShape(driver);
|
|
311
315
|
if (!legacyDetection.ok) {
|
|
312
316
|
return legacyDetection;
|
|
313
317
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
await this.executeStatement(driver, this.family.lowerAst(query, lowererContext));
|
|
317
|
-
}
|
|
318
|
+
await this.executeStatement(driver, ensureMarkerTableStatement);
|
|
319
|
+
await this.executeStatement(driver, ensureLedgerTableStatement);
|
|
318
320
|
return okVoid();
|
|
319
321
|
}
|
|
320
322
|
|
|
@@ -621,55 +623,25 @@ class SqliteMigrationRunner implements SqlMigrationRunner<SqlitePlanTargetDetail
|
|
|
621
623
|
await this.executeStatement(driver, statement);
|
|
622
624
|
}
|
|
623
625
|
|
|
624
|
-
private async
|
|
626
|
+
private async recordLedgerEntry(
|
|
625
627
|
driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],
|
|
626
628
|
options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,
|
|
627
629
|
existingMarker: ContractMarkerRecord | null,
|
|
628
630
|
executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],
|
|
629
631
|
): Promise<void> {
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
plan.destination.
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
// The ledger records the operations as executed — idempotency-skipped ops
|
|
644
|
-
// are substituted with skip records (empty `execute`) by `applyPlan`, so the
|
|
645
|
-
// journal reflects what actually ran rather than the raw plan.
|
|
646
|
-
let offset = 0;
|
|
647
|
-
const lastIndex = edges.length - 1;
|
|
648
|
-
for (const [i, edge] of edges.entries()) {
|
|
649
|
-
const edgeOps = executedOperations.slice(offset, offset + edge.operationCount);
|
|
650
|
-
offset += edge.operationCount;
|
|
651
|
-
const isFirst = i === 0;
|
|
652
|
-
const isLast = i === lastIndex;
|
|
653
|
-
await this.executeStatement(
|
|
654
|
-
driver,
|
|
655
|
-
buildLedgerInsertStatement({
|
|
656
|
-
space,
|
|
657
|
-
migrationName: edge.dirName,
|
|
658
|
-
migrationHash: edge.migrationHash,
|
|
659
|
-
originStorageHash: edge.from === '' ? null : edge.from,
|
|
660
|
-
originProfileHash:
|
|
661
|
-
isFirst && existingMarker?.storageHash === edge.from
|
|
662
|
-
? (existingMarker.profileHash ?? null)
|
|
663
|
-
: null,
|
|
664
|
-
destinationStorageHash: edge.to,
|
|
665
|
-
destinationProfileHash:
|
|
666
|
-
isLast && edge.to === plan.destination.storageHash ? destinationProfileHash : null,
|
|
667
|
-
contractJsonBefore: isFirst ? (existingMarker?.contractJson ?? null) : null,
|
|
668
|
-
contractJsonAfter: isLast ? options.destinationContract : null,
|
|
669
|
-
operations: edgeOps,
|
|
670
|
-
}),
|
|
671
|
-
);
|
|
672
|
-
}
|
|
632
|
+
const ledgerStatement = buildLedgerInsertStatement({
|
|
633
|
+
originStorageHash: existingMarker?.storageHash ?? null,
|
|
634
|
+
originProfileHash: existingMarker?.profileHash ?? null,
|
|
635
|
+
destinationStorageHash: options.plan.destination.storageHash,
|
|
636
|
+
destinationProfileHash:
|
|
637
|
+
options.plan.destination.profileHash ??
|
|
638
|
+
options.destinationContract.profileHash ??
|
|
639
|
+
options.plan.destination.storageHash,
|
|
640
|
+
contractJsonBefore: existingMarker?.contractJson ?? null,
|
|
641
|
+
contractJsonAfter: options.destinationContract,
|
|
642
|
+
operations: executedOperations,
|
|
643
|
+
});
|
|
644
|
+
await this.executeStatement(driver, ledgerStatement);
|
|
673
645
|
}
|
|
674
646
|
|
|
675
647
|
private async beginExclusiveTransaction(
|
|
@@ -46,10 +46,7 @@ export const ensureMarkerTableStatement: SqlStatement = {
|
|
|
46
46
|
export const ensureLedgerTableStatement: SqlStatement = {
|
|
47
47
|
sql: `CREATE TABLE IF NOT EXISTS _prisma_ledger (
|
|
48
48
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
49
|
-
created_at TEXT NOT NULL DEFAULT (
|
|
50
|
-
space TEXT NOT NULL,
|
|
51
|
-
migration_name TEXT NOT NULL,
|
|
52
|
-
migration_hash TEXT NOT NULL,
|
|
49
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
53
50
|
origin_core_hash TEXT,
|
|
54
51
|
origin_profile_hash TEXT,
|
|
55
52
|
destination_core_hash TEXT NOT NULL,
|
|
@@ -170,9 +167,6 @@ export function buildWriteMarkerStatements(input: WriteMarkerInput): {
|
|
|
170
167
|
}
|
|
171
168
|
|
|
172
169
|
export interface LedgerInsertInput {
|
|
173
|
-
readonly space: string;
|
|
174
|
-
readonly migrationName: string;
|
|
175
|
-
readonly migrationHash: string;
|
|
176
170
|
readonly originStorageHash?: string | null;
|
|
177
171
|
readonly originProfileHash?: string | null;
|
|
178
172
|
readonly destinationStorageHash: string;
|
|
@@ -185,9 +179,6 @@ export interface LedgerInsertInput {
|
|
|
185
179
|
export function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement {
|
|
186
180
|
return {
|
|
187
181
|
sql: `INSERT INTO _prisma_ledger (
|
|
188
|
-
space,
|
|
189
|
-
migration_name,
|
|
190
|
-
migration_hash,
|
|
191
182
|
origin_core_hash,
|
|
192
183
|
origin_profile_hash,
|
|
193
184
|
destination_core_hash,
|
|
@@ -202,15 +193,9 @@ export function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStateme
|
|
|
202
193
|
?,
|
|
203
194
|
?,
|
|
204
195
|
?,
|
|
205
|
-
?,
|
|
206
|
-
?,
|
|
207
|
-
?,
|
|
208
196
|
?
|
|
209
197
|
)`,
|
|
210
198
|
params: [
|
|
211
|
-
input.space,
|
|
212
|
-
input.migrationName,
|
|
213
|
-
input.migrationHash,
|
|
214
199
|
input.originStorageHash ?? null,
|
|
215
200
|
input.originProfileHash ?? null,
|
|
216
201
|
input.destinationStorageHash,
|
|
@@ -1,49 +1,20 @@
|
|
|
1
1
|
import type { Contract } from '@prisma-next/contract/types';
|
|
2
2
|
import { SqlContractSerializerBase } from '@prisma-next/family-sql/ir';
|
|
3
|
-
import {
|
|
4
|
-
type Namespace,
|
|
5
|
-
NamespaceBase,
|
|
6
|
-
UNBOUND_NAMESPACE_ID,
|
|
7
|
-
} from '@prisma-next/framework-components/ir';
|
|
8
|
-
import type {
|
|
9
|
-
SqlNamespaceTablesInput,
|
|
10
|
-
SqlStorage,
|
|
11
|
-
StorageTable,
|
|
12
|
-
} from '@prisma-next/sql-contract/types';
|
|
13
|
-
import { SqliteDatabase, SqliteUnboundDatabase } from './sqlite-unbound-database';
|
|
3
|
+
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
14
4
|
|
|
15
5
|
/**
|
|
16
6
|
* SQLite target `ContractSerializer` concretion. Mirrors the Postgres
|
|
17
|
-
* shape: inherits the full SQL-family deserialization pipeline
|
|
18
|
-
*
|
|
19
|
-
*
|
|
7
|
+
* shape: inherits the full SQL-family deserialization pipeline. Today's
|
|
8
|
+
* SQLite contract shape is the family-shared shape; no target-specific
|
|
9
|
+
* polymorphic `storage.types` factories are registered yet.
|
|
10
|
+
*
|
|
11
|
+
* `serializeContract` falls through to the family-base default —
|
|
12
|
+
* SQLite's contract is JSON-clean today. Once target-only fields land
|
|
13
|
+
* (e.g. per-target derived storage fields) this is the home for
|
|
14
|
+
* stripping them from the persisted envelope.
|
|
20
15
|
*/
|
|
21
16
|
export class SqliteContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {
|
|
22
17
|
constructor() {
|
|
23
18
|
super(new Map());
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
protected override hydrateSqlNamespaceEntry(
|
|
27
|
-
nsId: string,
|
|
28
|
-
raw: Namespace | Record<string, unknown>,
|
|
29
|
-
): Namespace | SqlNamespaceTablesInput {
|
|
30
|
-
if (raw instanceof NamespaceBase) {
|
|
31
|
-
return raw;
|
|
32
|
-
}
|
|
33
|
-
const hydrated = super.hydrateSqlNamespaceEntry(nsId, raw) as {
|
|
34
|
-
id: string;
|
|
35
|
-
tables: Readonly<Record<string, StorageTable>>;
|
|
36
|
-
};
|
|
37
|
-
const { id, tables } = hydrated;
|
|
38
|
-
const emptyTables = Object.keys(tables).length === 0;
|
|
39
|
-
if (id === UNBOUND_NAMESPACE_ID && emptyTables) {
|
|
40
|
-
return SqliteUnboundDatabase.instance;
|
|
41
|
-
}
|
|
42
|
-
if (id !== UNBOUND_NAMESPACE_ID) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
`SqliteContractSerializer: SQLite has no schema concept; the only valid namespace id is "${UNBOUND_NAMESPACE_ID}" (received "${id}").`,
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
return new SqliteDatabase({ id, tables });
|
|
48
|
-
}
|
|
49
20
|
}
|
|
@@ -5,36 +5,6 @@ import {
|
|
|
5
5
|
} from '@prisma-next/framework-components/ir';
|
|
6
6
|
import type { StorageTable } from '@prisma-next/sql-contract/types';
|
|
7
7
|
|
|
8
|
-
export type SqliteDatabaseInput = {
|
|
9
|
-
readonly id: string;
|
|
10
|
-
readonly tables: Readonly<Record<string, StorageTable>>;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* SQLite namespace concretion carrying table metadata and unqualified
|
|
15
|
-
* `qualifyTable()` emission for runtime SQL rendering.
|
|
16
|
-
*/
|
|
17
|
-
export class SqliteDatabase extends NamespaceBase {
|
|
18
|
-
readonly kind = 'database' as const;
|
|
19
|
-
readonly id: string;
|
|
20
|
-
readonly tables: Readonly<Record<string, StorageTable>>;
|
|
21
|
-
|
|
22
|
-
constructor(input: SqliteDatabaseInput) {
|
|
23
|
-
super();
|
|
24
|
-
this.id = input.id;
|
|
25
|
-
this.tables = Object.freeze({ ...input.tables });
|
|
26
|
-
freezeNode(this);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
qualifier(): string {
|
|
30
|
-
return '';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
qualifyTable(tableName: string): string {
|
|
34
|
-
return `"${tableName}"`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
8
|
/**
|
|
39
9
|
* SQLite target `Namespace` concretion. SQLite has no schema or
|
|
40
10
|
* database-namespacing concept at the SQL level — there is exactly one
|
package/src/exports/runtime.ts
CHANGED
package/dist/contract-free.d.mts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { n as SqliteCreateTable } from "./nodes-D8LGV4Yk.mjs";
|
|
2
|
-
import { DdlColumn, DdlNode } from "@prisma-next/sql-relational-core/ast";
|
|
3
|
-
|
|
4
|
-
//#region src/contract-free/control-bootstrap.d.ts
|
|
5
|
-
declare function buildSignMarkerBootstrapQueries(): readonly DdlNode[];
|
|
6
|
-
declare function buildControlTableBootstrapQueries(): readonly DdlNode[];
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/contract-free/ddl.d.ts
|
|
9
|
-
/**
|
|
10
|
-
* Build a SQLite `CREATE TABLE` query node.
|
|
11
|
-
*
|
|
12
|
-
* Precondition: identifiers (`table`, column names/types) are emitted to SQL
|
|
13
|
-
* verbatim — they are not quoted or escaped, so callers must pass pre-trusted
|
|
14
|
-
* values (e.g. fixed control-plane identifiers). String-literal default values,
|
|
15
|
-
* by contrast, are single-quote-escaped (embedded `'` doubled) by the renderer.
|
|
16
|
-
* Identifier quoting for untrusted identifiers is added when the migration
|
|
17
|
-
* planner adopts this lowering path.
|
|
18
|
-
*/
|
|
19
|
-
declare function createTable(options: {
|
|
20
|
-
readonly table: string;
|
|
21
|
-
readonly schema?: string;
|
|
22
|
-
readonly ifNotExists?: boolean;
|
|
23
|
-
readonly columns: readonly DdlColumn[];
|
|
24
|
-
}): SqliteCreateTable;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { buildControlTableBootstrapQueries, buildSignMarkerBootstrapQueries, createTable };
|
|
27
|
-
//# sourceMappingURL=contract-free.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contract-free.d.mts","names":[],"sources":["../src/contract-free/control-bootstrap.ts","../src/contract-free/ddl.ts"],"mappings":";;;;iBA+CgB,+BAAA,CAAA,YAA4C,OAAO;AAAA,iBAInD,iCAAA,CAAA,YAA8C,OAAO;;;;;AAJrE;;;;AAAmE;AAInE;;;iBCtCgB,WAAA,CAAY,OAAA;EAAA,SACjB,KAAA;EAAA,SACA,MAAA;EAAA,SACA,WAAA;EAAA,SACA,OAAA,WAAkB,SAAA;AAAA,IACzB,iBAAiB"}
|
package/dist/contract-free.mjs
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { t as SqliteCreateTable } from "./nodes-09ul6DNV.mjs";
|
|
2
|
-
import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
|
|
3
|
-
import { col, fn, lit } from "@prisma-next/sql-relational-core/contract-free";
|
|
4
|
-
//#region src/contract-free/ddl.ts
|
|
5
|
-
/**
|
|
6
|
-
* Build a SQLite `CREATE TABLE` query node.
|
|
7
|
-
*
|
|
8
|
-
* Precondition: identifiers (`table`, column names/types) are emitted to SQL
|
|
9
|
-
* verbatim — they are not quoted or escaped, so callers must pass pre-trusted
|
|
10
|
-
* values (e.g. fixed control-plane identifiers). String-literal default values,
|
|
11
|
-
* by contrast, are single-quote-escaped (embedded `'` doubled) by the renderer.
|
|
12
|
-
* Identifier quoting for untrusted identifiers is added when the migration
|
|
13
|
-
* planner adopts this lowering path.
|
|
14
|
-
*/
|
|
15
|
-
function createTable(options) {
|
|
16
|
-
return new SqliteCreateTable(options);
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/contract-free/control-bootstrap.ts
|
|
20
|
-
const markerColumns = [
|
|
21
|
-
col("space", "TEXT", {
|
|
22
|
-
notNull: true,
|
|
23
|
-
primaryKey: true,
|
|
24
|
-
default: lit(APP_SPACE_ID)
|
|
25
|
-
}),
|
|
26
|
-
col("core_hash", "TEXT", { notNull: true }),
|
|
27
|
-
col("profile_hash", "TEXT", { notNull: true }),
|
|
28
|
-
col("contract_json", "TEXT"),
|
|
29
|
-
col("canonical_version", "INTEGER"),
|
|
30
|
-
col("updated_at", "TEXT", {
|
|
31
|
-
notNull: true,
|
|
32
|
-
default: fn("datetime('now')")
|
|
33
|
-
}),
|
|
34
|
-
col("app_tag", "TEXT"),
|
|
35
|
-
col("meta", "TEXT", {
|
|
36
|
-
notNull: true,
|
|
37
|
-
default: lit("{}")
|
|
38
|
-
}),
|
|
39
|
-
col("invariants", "TEXT", {
|
|
40
|
-
notNull: true,
|
|
41
|
-
default: lit("[]")
|
|
42
|
-
})
|
|
43
|
-
];
|
|
44
|
-
const ledgerColumns = [
|
|
45
|
-
col("id", "INTEGER PRIMARY KEY AUTOINCREMENT"),
|
|
46
|
-
col("created_at", "TEXT", {
|
|
47
|
-
notNull: true,
|
|
48
|
-
default: fn("strftime('%Y-%m-%dT%H:%M:%fZ','now')")
|
|
49
|
-
}),
|
|
50
|
-
col("space", "TEXT", { notNull: true }),
|
|
51
|
-
col("migration_name", "TEXT", { notNull: true }),
|
|
52
|
-
col("migration_hash", "TEXT", { notNull: true }),
|
|
53
|
-
col("origin_core_hash", "TEXT"),
|
|
54
|
-
col("origin_profile_hash", "TEXT"),
|
|
55
|
-
col("destination_core_hash", "TEXT", { notNull: true }),
|
|
56
|
-
col("destination_profile_hash", "TEXT"),
|
|
57
|
-
col("contract_json_before", "TEXT"),
|
|
58
|
-
col("contract_json_after", "TEXT"),
|
|
59
|
-
col("operations", "TEXT", { notNull: true })
|
|
60
|
-
];
|
|
61
|
-
const markerTable = createTable({
|
|
62
|
-
table: "_prisma_marker",
|
|
63
|
-
ifNotExists: true,
|
|
64
|
-
columns: markerColumns
|
|
65
|
-
});
|
|
66
|
-
const ledgerTable = createTable({
|
|
67
|
-
table: "_prisma_ledger",
|
|
68
|
-
ifNotExists: true,
|
|
69
|
-
columns: ledgerColumns
|
|
70
|
-
});
|
|
71
|
-
function buildSignMarkerBootstrapQueries() {
|
|
72
|
-
return [markerTable];
|
|
73
|
-
}
|
|
74
|
-
function buildControlTableBootstrapQueries() {
|
|
75
|
-
return [markerTable, ledgerTable];
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
|
-
export { buildControlTableBootstrapQueries, buildSignMarkerBootstrapQueries, createTable };
|
|
79
|
-
|
|
80
|
-
//# sourceMappingURL=contract-free.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contract-free.mjs","names":[],"sources":["../src/contract-free/ddl.ts","../src/contract-free/control-bootstrap.ts"],"sourcesContent":["import type { DdlColumn } from '@prisma-next/sql-relational-core/ast';\nimport { SqliteCreateTable } from '../core/ddl/nodes';\n\n/**\n * Build a SQLite `CREATE TABLE` query node.\n *\n * Precondition: identifiers (`table`, column names/types) are emitted to SQL\n * verbatim — they are not quoted or escaped, so callers must pass pre-trusted\n * values (e.g. fixed control-plane identifiers). String-literal default values,\n * by contrast, are single-quote-escaped (embedded `'` doubled) by the renderer.\n * Identifier quoting for untrusted identifiers is added when the migration\n * planner adopts this lowering path.\n */\nexport function createTable(options: {\n readonly table: string;\n readonly schema?: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n}): SqliteCreateTable {\n return new SqliteCreateTable(options);\n}\n","import { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport type { DdlNode } from '@prisma-next/sql-relational-core/ast';\nimport { col, fn, lit } from '@prisma-next/sql-relational-core/contract-free';\nimport { createTable } from './ddl';\n\nconst markerColumns = [\n col('space', 'TEXT', { notNull: true, primaryKey: true, default: lit(APP_SPACE_ID) }),\n col('core_hash', 'TEXT', { notNull: true }),\n col('profile_hash', 'TEXT', { notNull: true }),\n col('contract_json', 'TEXT'),\n col('canonical_version', 'INTEGER'),\n col('updated_at', 'TEXT', { notNull: true, default: fn(\"datetime('now')\") }),\n col('app_tag', 'TEXT'),\n col('meta', 'TEXT', { notNull: true, default: lit('{}') }),\n col('invariants', 'TEXT', { notNull: true, default: lit('[]') }),\n] as const;\n\nconst ledgerColumns = [\n col('id', 'INTEGER PRIMARY KEY AUTOINCREMENT'),\n col('created_at', 'TEXT', {\n notNull: true,\n default: fn(\"strftime('%Y-%m-%dT%H:%M:%fZ','now')\"),\n }),\n col('space', 'TEXT', { notNull: true }),\n col('migration_name', 'TEXT', { notNull: true }),\n col('migration_hash', 'TEXT', { notNull: true }),\n col('origin_core_hash', 'TEXT'),\n col('origin_profile_hash', 'TEXT'),\n col('destination_core_hash', 'TEXT', { notNull: true }),\n col('destination_profile_hash', 'TEXT'),\n col('contract_json_before', 'TEXT'),\n col('contract_json_after', 'TEXT'),\n col('operations', 'TEXT', { notNull: true }),\n] as const;\n\nconst markerTable = createTable({\n table: '_prisma_marker',\n ifNotExists: true,\n columns: markerColumns,\n});\n\nconst ledgerTable = createTable({\n table: '_prisma_ledger',\n ifNotExists: true,\n columns: ledgerColumns,\n});\n\nexport function buildSignMarkerBootstrapQueries(): readonly DdlNode[] {\n return [markerTable];\n}\n\nexport function buildControlTableBootstrapQueries(): readonly DdlNode[] {\n return [markerTable, ledgerTable];\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,YAAY,SAKN;CACpB,OAAO,IAAI,kBAAkB,OAAO;AACtC;;;ACfA,MAAM,gBAAgB;CACpB,IAAI,SAAS,QAAQ;EAAE,SAAS;EAAM,YAAY;EAAM,SAAS,IAAI,YAAY;CAAE,CAAC;CACpF,IAAI,aAAa,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC1C,IAAI,gBAAgB,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC7C,IAAI,iBAAiB,MAAM;CAC3B,IAAI,qBAAqB,SAAS;CAClC,IAAI,cAAc,QAAQ;EAAE,SAAS;EAAM,SAAS,GAAG,iBAAiB;CAAE,CAAC;CAC3E,IAAI,WAAW,MAAM;CACrB,IAAI,QAAQ,QAAQ;EAAE,SAAS;EAAM,SAAS,IAAI,IAAI;CAAE,CAAC;CACzD,IAAI,cAAc,QAAQ;EAAE,SAAS;EAAM,SAAS,IAAI,IAAI;CAAE,CAAC;AACjE;AAEA,MAAM,gBAAgB;CACpB,IAAI,MAAM,mCAAmC;CAC7C,IAAI,cAAc,QAAQ;EACxB,SAAS;EACT,SAAS,GAAG,sCAAsC;CACpD,CAAC;CACD,IAAI,SAAS,QAAQ,EAAE,SAAS,KAAK,CAAC;CACtC,IAAI,kBAAkB,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC/C,IAAI,kBAAkB,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC/C,IAAI,oBAAoB,MAAM;CAC9B,IAAI,uBAAuB,MAAM;CACjC,IAAI,yBAAyB,QAAQ,EAAE,SAAS,KAAK,CAAC;CACtD,IAAI,4BAA4B,MAAM;CACtC,IAAI,wBAAwB,MAAM;CAClC,IAAI,uBAAuB,MAAM;CACjC,IAAI,cAAc,QAAQ,EAAE,SAAS,KAAK,CAAC;AAC7C;AAEA,MAAM,cAAc,YAAY;CAC9B,OAAO;CACP,aAAa;CACb,SAAS;AACX,CAAC;AAED,MAAM,cAAc,YAAY;CAC9B,OAAO;CACP,aAAa;CACb,SAAS;AACX,CAAC;AAED,SAAgB,kCAAsD;CACpE,OAAO,CAAC,WAAW;AACrB;AAEA,SAAgB,oCAAwD;CACtE,OAAO,CAAC,aAAa,WAAW;AAClC"}
|
package/dist/ddl.d.mts
DELETED
package/dist/ddl.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-rKforwQA.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"}
|
package/dist/nodes-09ul6DNV.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { DdlNode } from "@prisma-next/sql-relational-core/ast";
|
|
2
|
-
//#region src/core/ddl/nodes.ts
|
|
3
|
-
var SqliteDdlNode = class extends DdlNode {};
|
|
4
|
-
function freezeDdlColumns(columns) {
|
|
5
|
-
return Object.freeze([...columns]);
|
|
6
|
-
}
|
|
7
|
-
var SqliteCreateTable = class extends SqliteDdlNode {
|
|
8
|
-
kind = "create-table";
|
|
9
|
-
table;
|
|
10
|
-
schema;
|
|
11
|
-
ifNotExists;
|
|
12
|
-
columns;
|
|
13
|
-
constructor(options) {
|
|
14
|
-
super();
|
|
15
|
-
this.table = options.table;
|
|
16
|
-
this.schema = options.schema;
|
|
17
|
-
this.ifNotExists = options.ifNotExists;
|
|
18
|
-
this.columns = freezeDdlColumns(options.columns);
|
|
19
|
-
this.freeze();
|
|
20
|
-
}
|
|
21
|
-
accept(visitor) {
|
|
22
|
-
return visitor.createTable(this);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
//#endregion
|
|
26
|
-
export { SqliteDdlNode as n, SqliteCreateTable as t };
|
|
27
|
-
|
|
28
|
-
//# sourceMappingURL=nodes-09ul6DNV.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodes-09ul6DNV.mjs","names":[],"sources":["../src/core/ddl/nodes.ts"],"sourcesContent":["import { type DdlColumn, DdlNode } from '@prisma-next/sql-relational-core/ast';\n\nexport interface SqliteDdlVisitor<R> {\n createTable(node: SqliteCreateTable): R;\n}\n\nexport abstract class SqliteDdlNode extends DdlNode {\n abstract accept<R>(visitor: SqliteDdlVisitor<R>): R;\n}\n\nfunction freezeDdlColumns(columns: readonly DdlColumn[]): ReadonlyArray<DdlColumn> {\n return Object.freeze([...columns]);\n}\n\nexport class SqliteCreateTable extends SqliteDdlNode {\n readonly kind = 'create-table' as const;\n readonly table: string;\n readonly schema: string | undefined;\n readonly ifNotExists: boolean | undefined;\n readonly columns: ReadonlyArray<DdlColumn>;\n\n constructor(options: {\n readonly table: string;\n readonly schema?: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n }) {\n super();\n this.table = options.table;\n this.schema = options.schema;\n this.ifNotExists = options.ifNotExists;\n this.columns = freezeDdlColumns(options.columns);\n this.freeze();\n }\n\n override accept<R>(visitor: SqliteDdlVisitor<R>): R {\n return visitor.createTable(this);\n }\n}\n\nexport type AnySqliteDdlNode = SqliteCreateTable;\n"],"mappings":";;AAMA,IAAsB,gBAAtB,cAA4C,QAAQ,CAEpD;AAEA,SAAS,iBAAiB,SAAyD;CACjF,OAAO,OAAO,OAAO,CAAC,GAAG,OAAO,CAAC;AACnC;AAEA,IAAa,oBAAb,cAAuC,cAAc;CACnD,OAAgB;CAChB;CACA;CACA;CACA;CAEA,YAAY,SAKT;EACD,MAAM;EACN,KAAK,QAAQ,QAAQ;EACrB,KAAK,SAAS,QAAQ;EACtB,KAAK,cAAc,QAAQ;EAC3B,KAAK,UAAU,iBAAiB,QAAQ,OAAO;EAC/C,KAAK,OAAO;CACd;CAEA,OAAmB,SAAiC;EAClD,OAAO,QAAQ,YAAY,IAAI;CACjC;AACF"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { DdlColumn, DdlNode } from "@prisma-next/sql-relational-core/ast";
|
|
2
|
-
|
|
3
|
-
//#region src/core/ddl/nodes.d.ts
|
|
4
|
-
interface SqliteDdlVisitor<R> {
|
|
5
|
-
createTable(node: SqliteCreateTable): R;
|
|
6
|
-
}
|
|
7
|
-
declare abstract class SqliteDdlNode extends DdlNode {
|
|
8
|
-
abstract accept<R>(visitor: SqliteDdlVisitor<R>): R;
|
|
9
|
-
}
|
|
10
|
-
declare class SqliteCreateTable extends SqliteDdlNode {
|
|
11
|
-
readonly kind: "create-table";
|
|
12
|
-
readonly table: string;
|
|
13
|
-
readonly schema: string | undefined;
|
|
14
|
-
readonly ifNotExists: boolean | undefined;
|
|
15
|
-
readonly columns: ReadonlyArray<DdlColumn>;
|
|
16
|
-
constructor(options: {
|
|
17
|
-
readonly table: string;
|
|
18
|
-
readonly schema?: string;
|
|
19
|
-
readonly ifNotExists?: boolean;
|
|
20
|
-
readonly columns: readonly DdlColumn[];
|
|
21
|
-
});
|
|
22
|
-
accept<R>(visitor: SqliteDdlVisitor<R>): R;
|
|
23
|
-
}
|
|
24
|
-
type AnySqliteDdlNode = SqliteCreateTable;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { SqliteDdlVisitor as i, SqliteCreateTable as n, SqliteDdlNode as r, AnySqliteDdlNode as t };
|
|
27
|
-
//# sourceMappingURL=nodes-D8LGV4Yk.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodes-D8LGV4Yk.d.mts","names":[],"sources":["../src/core/ddl/nodes.ts"],"mappings":";;;UAEiB,gBAAA;EACf,WAAA,CAAY,IAAA,EAAM,iBAAA,GAAoB,CAAC;AAAA;AAAA,uBAGnB,aAAA,SAAsB,OAAA;EAAA,SACjC,MAAA,GAAA,CAAU,OAAA,EAAS,gBAAA,CAAiB,CAAA,IAAK,CAAA;AAAA;AAAA,cAOvC,iBAAA,SAA0B,aAAA;EAAA,SAC5B,IAAA;EAAA,SACA,KAAA;EAAA,SACA,MAAA;EAAA,SACA,WAAA;EAAA,SACA,OAAA,EAAS,aAAA,CAAc,SAAA;cAEpB,OAAA;IAAA,SACD,KAAA;IAAA,SACA,MAAA;IAAA,SACA,WAAA;IAAA,SACA,OAAA,WAAkB,SAAA;EAAA;EAUpB,MAAA,GAAA,CAAU,OAAA,EAAS,gBAAA,CAAiB,CAAA,IAAK,CAAA;AAAA;AAAA,KAKxC,gBAAA,GAAmB,iBAAiB"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { NamespaceBase, UNBOUND_NAMESPACE_ID, freezeNode } from "@prisma-next/framework-components/ir";
|
|
2
|
-
import { SqlContractSerializerBase } from "@prisma-next/family-sql/ir";
|
|
3
|
-
//#region src/core/sqlite-unbound-database.ts
|
|
4
|
-
/**
|
|
5
|
-
* SQLite namespace concretion carrying table metadata and unqualified
|
|
6
|
-
* `qualifyTable()` emission for runtime SQL rendering.
|
|
7
|
-
*/
|
|
8
|
-
var SqliteDatabase = class extends NamespaceBase {
|
|
9
|
-
kind = "database";
|
|
10
|
-
id;
|
|
11
|
-
tables;
|
|
12
|
-
constructor(input) {
|
|
13
|
-
super();
|
|
14
|
-
this.id = input.id;
|
|
15
|
-
this.tables = Object.freeze({ ...input.tables });
|
|
16
|
-
freezeNode(this);
|
|
17
|
-
}
|
|
18
|
-
qualifier() {
|
|
19
|
-
return "";
|
|
20
|
-
}
|
|
21
|
-
qualifyTable(tableName) {
|
|
22
|
-
return `"${tableName}"`;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* SQLite target `Namespace` concretion. SQLite has no schema or
|
|
27
|
-
* database-namespacing concept at the SQL level — there is exactly one
|
|
28
|
-
* effective namespace per connection, so the target ships a single
|
|
29
|
-
* singleton bound to the framework's `UNBOUND_NAMESPACE_ID` slot.
|
|
30
|
-
*
|
|
31
|
-
* Qualifier emission elides the prefix entirely: rendered DDL and
|
|
32
|
-
* queries look unqualified (`CREATE TABLE "users" (...)`), matching
|
|
33
|
-
* SQLite's native dialect. Call sites stay polymorphic — they ask the
|
|
34
|
-
* namespace for its qualifier and consume the empty/unqualified result
|
|
35
|
-
* the same way Postgres consumes a `"schema"` prefix.
|
|
36
|
-
*
|
|
37
|
-
* The SQLite PSL interpreter rejects every explicit `namespace { … }`
|
|
38
|
-
* block with a diagnostic naming SQLite; only the implicit
|
|
39
|
-
* `__unspecified__` AST bucket reaches the SQLite interpreter, which
|
|
40
|
-
* lowers it to this singleton.
|
|
41
|
-
*/
|
|
42
|
-
var SqliteUnboundDatabase = class SqliteUnboundDatabase extends NamespaceBase {
|
|
43
|
-
static instance = new SqliteUnboundDatabase();
|
|
44
|
-
kind = "database";
|
|
45
|
-
id = UNBOUND_NAMESPACE_ID;
|
|
46
|
-
tables;
|
|
47
|
-
constructor() {
|
|
48
|
-
super();
|
|
49
|
-
this.tables = Object.freeze({});
|
|
50
|
-
freezeNode(this);
|
|
51
|
-
}
|
|
52
|
-
qualifier() {
|
|
53
|
-
return "";
|
|
54
|
-
}
|
|
55
|
-
qualifyTable(tableName) {
|
|
56
|
-
return `"${tableName}"`;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Target-supplied `Namespace` factory the SQLite target plumbs through
|
|
61
|
-
* `defineContract({ createNamespace })`. SQLite has only one
|
|
62
|
-
* effective namespace slot — the framework `UNBOUND_NAMESPACE_ID`
|
|
63
|
-
* sentinel — so the factory always returns the singleton and rejects
|
|
64
|
-
* any other coordinate. The SQL family's defensive validation in
|
|
65
|
-
* `defineContract` already rejects user-declared SQLite namespaces, so
|
|
66
|
-
* this throw is a structural safety net rather than a user-facing
|
|
67
|
-
* surface.
|
|
68
|
-
*/
|
|
69
|
-
function sqliteCreateNamespace(id) {
|
|
70
|
-
if (id === UNBOUND_NAMESPACE_ID) return SqliteUnboundDatabase.instance;
|
|
71
|
-
throw new Error(`sqliteCreateNamespace: SQLite has no schema concept; the only valid namespace id is "${UNBOUND_NAMESPACE_ID}" (received "${id}").`);
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/core/sqlite-contract-serializer.ts
|
|
75
|
-
/**
|
|
76
|
-
* SQLite target `ContractSerializer` concretion. Mirrors the Postgres
|
|
77
|
-
* shape: inherits the full SQL-family deserialization pipeline and
|
|
78
|
-
* materialises namespace entries as SQLite database concretions that
|
|
79
|
-
* expose `qualifyTable()` for runtime SQL rendering.
|
|
80
|
-
*/
|
|
81
|
-
var SqliteContractSerializer = class extends SqlContractSerializerBase {
|
|
82
|
-
constructor() {
|
|
83
|
-
super(/* @__PURE__ */ new Map());
|
|
84
|
-
}
|
|
85
|
-
hydrateSqlNamespaceEntry(nsId, raw) {
|
|
86
|
-
if (raw instanceof NamespaceBase) return raw;
|
|
87
|
-
const { id, tables } = super.hydrateSqlNamespaceEntry(nsId, raw);
|
|
88
|
-
const emptyTables = Object.keys(tables).length === 0;
|
|
89
|
-
if (id === UNBOUND_NAMESPACE_ID && emptyTables) return SqliteUnboundDatabase.instance;
|
|
90
|
-
if (id !== UNBOUND_NAMESPACE_ID) throw new Error(`SqliteContractSerializer: SQLite has no schema concept; the only valid namespace id is "${UNBOUND_NAMESPACE_ID}" (received "${id}").`);
|
|
91
|
-
return new SqliteDatabase({
|
|
92
|
-
id,
|
|
93
|
-
tables
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
//#endregion
|
|
98
|
-
export { SqliteUnboundDatabase as n, sqliteCreateNamespace as r, SqliteContractSerializer as t };
|
|
99
|
-
|
|
100
|
-
//# sourceMappingURL=sqlite-contract-serializer-Hy7WQPea.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-contract-serializer-Hy7WQPea.mjs","names":[],"sources":["../src/core/sqlite-unbound-database.ts","../src/core/sqlite-contract-serializer.ts"],"sourcesContent":["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\nexport type SqliteDatabaseInput = {\n readonly id: string;\n readonly tables: Readonly<Record<string, StorageTable>>;\n};\n\n/**\n * SQLite namespace concretion carrying table metadata and unqualified\n * `qualifyTable()` emission for runtime SQL rendering.\n */\nexport class SqliteDatabase extends NamespaceBase {\n readonly kind = 'database' as const;\n readonly id: string;\n readonly tables: Readonly<Record<string, StorageTable>>;\n\n constructor(input: SqliteDatabaseInput) {\n super();\n this.id = input.id;\n this.tables = Object.freeze({ ...input.tables });\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 * 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","import type { Contract } from '@prisma-next/contract/types';\nimport { SqlContractSerializerBase } from '@prisma-next/family-sql/ir';\nimport {\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport type {\n SqlNamespaceTablesInput,\n SqlStorage,\n StorageTable,\n} from '@prisma-next/sql-contract/types';\nimport { SqliteDatabase, SqliteUnboundDatabase } from './sqlite-unbound-database';\n\n/**\n * SQLite target `ContractSerializer` concretion. Mirrors the Postgres\n * shape: inherits the full SQL-family deserialization pipeline and\n * materialises namespace entries as SQLite database concretions that\n * expose `qualifyTable()` for runtime SQL rendering.\n */\nexport class SqliteContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor() {\n super(new Map());\n }\n\n protected override hydrateSqlNamespaceEntry(\n nsId: string,\n raw: Namespace | Record<string, unknown>,\n ): Namespace | SqlNamespaceTablesInput {\n if (raw instanceof NamespaceBase) {\n return raw;\n }\n const hydrated = super.hydrateSqlNamespaceEntry(nsId, raw) as {\n id: string;\n tables: Readonly<Record<string, StorageTable>>;\n };\n const { id, tables } = hydrated;\n const emptyTables = Object.keys(tables).length === 0;\n if (id === UNBOUND_NAMESPACE_ID && emptyTables) {\n return SqliteUnboundDatabase.instance;\n }\n if (id !== UNBOUND_NAMESPACE_ID) {\n throw new Error(\n `SqliteContractSerializer: SQLite has no schema concept; the only valid namespace id is \"${UNBOUND_NAMESPACE_ID}\" (received \"${id}\").`,\n );\n }\n return new SqliteDatabase({ id, tables });\n }\n}\n"],"mappings":";;;;;;;AAgBA,IAAa,iBAAb,cAAoC,cAAc;CAChD,OAAgB;CAChB;CACA;CAEA,YAAY,OAA4B;EACtC,MAAM;EACN,KAAK,KAAK,MAAM;EAChB,KAAK,SAAS,OAAO,OAAO,EAAE,GAAG,MAAM,OAAO,CAAC;EAC/C,WAAW,IAAI;CACjB;CAEA,YAAoB;EAClB,OAAO;CACT;CAEA,aAAa,WAA2B;EACtC,OAAO,IAAI,UAAU;CACvB;AACF;;;;;;;;;;;;;;;;;;AAmBA,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;;;;;;;;;ACzEA,IAAa,2BAAb,cAA8C,0BAAgD;CAC5F,cAAc;EACZ,sBAAM,IAAI,IAAI,CAAC;CACjB;CAEA,yBACE,MACA,KACqC;EACrC,IAAI,eAAe,eACjB,OAAO;EAMT,MAAM,EAAE,IAAI,WAJK,MAAM,yBAAyB,MAAM,GAIxB;EAC9B,MAAM,cAAc,OAAO,KAAK,MAAM,EAAE,WAAW;EACnD,IAAI,OAAO,wBAAwB,aACjC,OAAO,sBAAsB;EAE/B,IAAI,OAAO,sBACT,MAAM,IAAI,MACR,2FAA2F,qBAAqB,eAAe,GAAG,IACpI;EAEF,OAAO,IAAI,eAAe;GAAE;GAAI;EAAO,CAAC;CAC1C;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"statement-builders-D1Q_i4sb.mjs","names":["APP_SPACE_ID"],"sources":["../src/core/migrations/statement-builders.ts"],"sourcesContent":["import { APP_SPACE_ID } from '@prisma-next/framework-components/control';\n\nexport { APP_SPACE_ID };\n\nexport interface SqlStatement {\n readonly sql: string;\n readonly params: readonly unknown[];\n}\n\nexport const MARKER_TABLE_NAME = '_prisma_marker';\nexport const LEDGER_TABLE_NAME = '_prisma_ledger';\n\n/**\n * Control tables the runner creates/manages. The planner must not drop these\n * when reconciling \"extra\" tables against the contract.\n */\nexport const CONTROL_TABLE_NAMES: ReadonlySet<string> = new Set([\n MARKER_TABLE_NAME,\n LEDGER_TABLE_NAME,\n]);\n\n/**\n * Schema for `_prisma_marker`. The `space TEXT PRIMARY KEY` shape\n * supports one row per loaded contract space (`'app'`,\n * `'<extension-id>'`, …); brand-new databases create this shape\n * directly. The migration runner detects pre-1.0 single-row markers\n * (no `space` column) at boot and fails with a structured\n * `LEGACY_MARKER_SHAPE` error rather than auto-rebuilding the table —\n * see `specs/framework-mechanism.spec.md § 2`.\n */\nexport const ensureMarkerTableStatement: SqlStatement = {\n sql: `CREATE TABLE IF NOT EXISTS _prisma_marker (\n space TEXT NOT NULL PRIMARY KEY DEFAULT '${APP_SPACE_ID}',\n core_hash TEXT NOT NULL,\n profile_hash TEXT NOT NULL,\n contract_json TEXT,\n canonical_version INTEGER,\n updated_at TEXT NOT NULL DEFAULT (datetime('now')),\n app_tag TEXT,\n meta TEXT NOT NULL DEFAULT '{}',\n invariants TEXT NOT NULL DEFAULT '[]'\n )`,\n params: [],\n};\n\nexport const ensureLedgerTableStatement: SqlStatement = {\n sql: `CREATE TABLE IF NOT EXISTS _prisma_ledger (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),\n space TEXT NOT NULL,\n migration_name TEXT NOT NULL,\n migration_hash TEXT NOT NULL,\n origin_core_hash TEXT,\n origin_profile_hash TEXT,\n destination_core_hash TEXT NOT NULL,\n destination_profile_hash TEXT,\n contract_json_before TEXT,\n contract_json_after TEXT,\n operations TEXT NOT NULL\n )`,\n params: [],\n};\n\nexport function readMarkerStatement(space: string): SqlStatement {\n return {\n sql: `SELECT\n core_hash,\n profile_hash,\n contract_json,\n canonical_version,\n updated_at,\n app_tag,\n meta,\n invariants\n FROM _prisma_marker\n WHERE space = ?`,\n params: [space],\n };\n}\n\nexport interface WriteMarkerInput {\n /**\n * Logical space identifier for this marker row. Required at every\n * call site so the type system surfaces every place that needs to\n * thread the value (rather than letting an `?? APP_SPACE_ID`\n * fall-through silently collapse per-space markers onto the\n * `'app'` row). App-plan callers pass {@link APP_SPACE_ID}\n * (`'app'`); per-extension callers pass the extension's space id.\n */\n readonly space: string;\n readonly storageHash: string;\n readonly profileHash: string;\n readonly contractJson?: unknown;\n readonly canonicalVersion?: number | null;\n readonly appTag?: string | null;\n readonly meta?: Record<string, unknown>;\n /**\n * Invariants to write into `marker.invariants`. Stored as a JSON-encoded\n * TEXT array — SQLite has no native array type. The runner is responsible\n * for merging with the existing column (no SQL-side merge here, unlike\n * Postgres) before passing them in: BEGIN EXCLUSIVE on the migration\n * transaction makes the read-then-merge-then-write sequence safe.\n */\n readonly invariants: readonly string[];\n}\n\nexport function buildWriteMarkerStatements(input: WriteMarkerInput): {\n readonly insert: SqlStatement;\n readonly update: SqlStatement;\n} {\n const params: readonly unknown[] = [\n input.space,\n input.storageHash,\n input.profileHash,\n jsonParam(input.contractJson),\n input.canonicalVersion ?? null,\n input.appTag ?? null,\n jsonParam(input.meta ?? {}),\n jsonParam(input.invariants),\n ];\n\n return {\n insert: {\n sql: `INSERT INTO _prisma_marker (\n space,\n core_hash,\n profile_hash,\n contract_json,\n canonical_version,\n updated_at,\n app_tag,\n meta,\n invariants\n ) VALUES (\n ?,\n ?,\n ?,\n ?,\n ?,\n datetime('now'),\n ?,\n ?,\n ?\n )`,\n params,\n },\n update: {\n sql: `UPDATE _prisma_marker SET\n core_hash = ?,\n profile_hash = ?,\n contract_json = ?,\n canonical_version = ?,\n updated_at = datetime('now'),\n app_tag = ?,\n meta = ?,\n invariants = ?\n WHERE space = ?`,\n params: [\n input.storageHash,\n input.profileHash,\n jsonParam(input.contractJson),\n input.canonicalVersion ?? null,\n input.appTag ?? null,\n jsonParam(input.meta ?? {}),\n jsonParam(input.invariants),\n input.space,\n ],\n },\n };\n}\n\nexport interface LedgerInsertInput {\n readonly space: string;\n readonly migrationName: string;\n readonly migrationHash: string;\n readonly originStorageHash?: string | null;\n readonly originProfileHash?: string | null;\n readonly destinationStorageHash: string;\n readonly destinationProfileHash?: string | null;\n readonly contractJsonBefore?: unknown;\n readonly contractJsonAfter?: unknown;\n readonly operations: unknown;\n}\n\nexport function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement {\n return {\n sql: `INSERT INTO _prisma_ledger (\n space,\n migration_name,\n migration_hash,\n origin_core_hash,\n origin_profile_hash,\n destination_core_hash,\n destination_profile_hash,\n contract_json_before,\n contract_json_after,\n operations\n ) VALUES (\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?\n )`,\n params: [\n input.space,\n input.migrationName,\n input.migrationHash,\n input.originStorageHash ?? null,\n input.originProfileHash ?? null,\n input.destinationStorageHash,\n input.destinationProfileHash ?? null,\n jsonParam(input.contractJsonBefore),\n jsonParam(input.contractJsonAfter),\n jsonParam(input.operations),\n ],\n };\n}\n\nfunction jsonParam(value: unknown): string {\n return JSON.stringify(value ?? null);\n}\n"],"mappings":";;AASA,MAAa,oBAAoB;AACjC,MAAa,oBAAoB;;;;;AAMjC,MAAa,sBAA2C,IAAI,IAAI,CAC9D,mBACA,iBACF,CAAC;;;;;;;;;;AAWD,MAAa,6BAA2C;CACtD,KAAK;+CACwCA,eAAa;;;;;;;;;;CAU1D,QAAQ,CAAC;AACX;AAEA,MAAa,6BAA2C;CACtD,KAAK;;;;;;;;;;;;;;CAcL,QAAQ,CAAC;AACX;AAEA,SAAgB,oBAAoB,OAA6B;CAC/D,OAAO;EACL,KAAK;;;;;;;;;;;EAWL,QAAQ,CAAC,KAAK;CAChB;AACF;AA4BA,SAAgB,2BAA2B,OAGzC;CAYA,OAAO;EACL,QAAQ;GACN,KAAK;;;;;;;;;;;;;;;;;;;;;GAqBL,QAAA;IAjCF,MAAM;IACN,MAAM;IACN,MAAM;IACN,UAAU,MAAM,YAAY;IAC5B,MAAM,oBAAoB;IAC1B,MAAM,UAAU;IAChB,UAAU,MAAM,QAAQ,CAAC,CAAC;IAC1B,UAAU,MAAM,UAAU;GA0BnB;EACP;EACA,QAAQ;GACN,KAAK;;;;;;;;;;GAUL,QAAQ;IACN,MAAM;IACN,MAAM;IACN,UAAU,MAAM,YAAY;IAC5B,MAAM,oBAAoB;IAC1B,MAAM,UAAU;IAChB,UAAU,MAAM,QAAQ,CAAC,CAAC;IAC1B,UAAU,MAAM,UAAU;IAC1B,MAAM;GACR;EACF;CACF;AACF;AAeA,SAAgB,2BAA2B,OAAwC;CACjF,OAAO;EACL,KAAK;;;;;;;;;;;;;;;;;;;;;;;EAuBL,QAAQ;GACN,MAAM;GACN,MAAM;GACN,MAAM;GACN,MAAM,qBAAqB;GAC3B,MAAM,qBAAqB;GAC3B,MAAM;GACN,MAAM,0BAA0B;GAChC,UAAU,MAAM,kBAAkB;GAClC,UAAU,MAAM,iBAAiB;GACjC,UAAU,MAAM,UAAU;EAC5B;CACF;AACF;AAEA,SAAS,UAAU,OAAwB;CACzC,OAAO,KAAK,UAAU,SAAS,IAAI;AACrC"}
|