@prisma-next/family-sql 0.12.0-dev.31 → 0.12.0-dev.32
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/{control-adapter-CKCfVhTd.d.mts → control-adapter-uYnmu04p.d.mts} +49 -1
- package/dist/control-adapter-uYnmu04p.d.mts.map +1 -0
- package/dist/control-adapter.d.mts +1 -1
- package/dist/control.d.mts +1 -1
- package/dist/control.mjs +14 -14
- package/dist/control.mjs.map +1 -1
- package/dist/migration.d.mts +1 -1
- package/dist/runtime.d.mts +1 -1
- package/dist/{types-B084B5kI.d.mts → types-DxNgxFkF.d.mts} +47 -3
- package/dist/types-DxNgxFkF.d.mts.map +1 -0
- package/package.json +21 -21
- package/src/core/control-adapter.ts +69 -0
- package/src/core/control-instance.ts +102 -14
- package/src/core/migrations/types.ts +1 -0
- package/dist/control-adapter-CKCfVhTd.d.mts.map +0 -1
- package/dist/types-B084B5kI.d.mts.map +0 -1
|
@@ -42,6 +42,54 @@ interface SqlControlAdapter<TTarget extends string = string> extends ControlAdap
|
|
|
42
42
|
* omitted, returns rows for every space.
|
|
43
43
|
*/
|
|
44
44
|
readLedger(driver: ControlDriverInstance<'sql', TTarget>, space?: string): Promise<readonly LedgerEntryRecord[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Inserts the initial marker row for `space` (`INSERT` only). Fails when a
|
|
47
|
+
* row for that space already exists. Used by `sign()` so concurrent first-time
|
|
48
|
+
* stamps cannot silently overwrite each other. `updated_at` is DB-side
|
|
49
|
+
* (`now()` / `datetime('now')`). Mirrors `MongoControlAdapter.initMarker`.
|
|
50
|
+
*/
|
|
51
|
+
insertMarker(driver: ControlDriverInstance<'sql', TTarget>, space: string, destination: {
|
|
52
|
+
readonly storageHash: string;
|
|
53
|
+
readonly profileHash: string;
|
|
54
|
+
readonly invariants?: readonly string[];
|
|
55
|
+
}): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Writes the initial marker row for `space` as an upsert (`INSERT … ON
|
|
58
|
+
* CONFLICT (space) DO UPDATE SET …`), so re-stamping a space overwrites the
|
|
59
|
+
* existing row rather than failing. `updated_at` is stamped with a DB-side
|
|
60
|
+
* time expression (`now()` / `datetime('now')`), never an app-side clock.
|
|
61
|
+
*/
|
|
62
|
+
initMarker(driver: ControlDriverInstance<'sql', TTarget>, space: string, destination: {
|
|
63
|
+
readonly storageHash: string;
|
|
64
|
+
readonly profileHash: string;
|
|
65
|
+
readonly invariants?: readonly string[];
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Atomically advances the marker row for `space` (compare-and-swap on
|
|
69
|
+
* `core_hash = expectedFrom`). Returns `true` when the swap matched a row,
|
|
70
|
+
* `false` when another process advanced the marker first. `destination.invariants`
|
|
71
|
+
* is written verbatim when supplied (the union/dedupe policy lives upstream)
|
|
72
|
+
* and left untouched when omitted. Mirrors `MongoControlAdapter.updateMarker`.
|
|
73
|
+
*/
|
|
74
|
+
updateMarker(driver: ControlDriverInstance<'sql', TTarget>, space: string, expectedFrom: string, destination: {
|
|
75
|
+
readonly storageHash: string;
|
|
76
|
+
readonly profileHash: string;
|
|
77
|
+
readonly invariants?: readonly string[];
|
|
78
|
+
}): Promise<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* Appends a ledger entry for `space`. Mirrors `MongoControlAdapter.writeLedgerEntry`.
|
|
81
|
+
* The SQL ledger table keys rows by an autoincrement id and partitions reads
|
|
82
|
+
* by `space`, so `entry.edgeId` carries no dedicated column; `from` / `to`
|
|
83
|
+
* land in `origin_core_hash` / `destination_core_hash`.
|
|
84
|
+
*/
|
|
85
|
+
writeLedgerEntry(driver: ControlDriverInstance<'sql', TTarget>, space: string, entry: {
|
|
86
|
+
readonly edgeId: string;
|
|
87
|
+
readonly from: string;
|
|
88
|
+
readonly to: string;
|
|
89
|
+
readonly migrationName: string;
|
|
90
|
+
readonly migrationHash: string;
|
|
91
|
+
readonly operations: readonly unknown[];
|
|
92
|
+
}): Promise<void>;
|
|
45
93
|
/**
|
|
46
94
|
* Introspects a database schema and returns a raw SqlSchemaIR.
|
|
47
95
|
*
|
|
@@ -130,4 +178,4 @@ interface SqlControlAdapterDescriptor<TTarget extends string = string> {
|
|
|
130
178
|
}
|
|
131
179
|
//#endregion
|
|
132
180
|
export { SqlControlAdapterDescriptor as n, SqlControlAdapter as t };
|
|
133
|
-
//# sourceMappingURL=control-adapter-
|
|
181
|
+
//# sourceMappingURL=control-adapter-uYnmu04p.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-adapter-uYnmu04p.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"mappings":";;;;;;;;;;AA8BA;;;;UAAiB,iBAAA,0CACP,sBAAA,QAA8B,OAAA;EAiB5B;;;;;;;;;;;;;;;EADV,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,WACC,OAAA,CAAQ,oBAAA;EA6CD;;;;;;;EApCV,cAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,IACpC,OAAA,CAAQ,WAAA,SAAoB,oBAAA;EA6FQ;;;;EAvFvC,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,YACC,OAAA,UAAiB,iBAAA;EAqGW;;;;;;EA7F/B,YAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,UACA,WAAA;IAAA,SACW,WAAA;IAAA,SACA,WAAA;IAAA,SACA,UAAA;EAAA,IAEV,OAAA;EAiJsB;;;;;;EAzIzB,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,UACA,WAAA;IAAA,SACW,WAAA;IAAA,SACA,WAAA;IAAA,SACA,UAAA;EAAA,IAEV,OAAA;EAtDoC;;;;;;;EA+DvC,YAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,UACA,YAAA,UACA,WAAA;IAAA,SACW,WAAA;IAAA,SACA,WAAA;IAAA,SACA,UAAA;EAAA,IAEV,OAAA;EArDH;;;;;;EA6DA,gBAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,UACA,KAAA;IAAA,SACW,MAAA;IAAA,SACA,IAAA;IAAA,SACA,EAAA;IAAA,SACA,aAAA;IAAA,SACA,aAAA;IAAA,SACA,UAAA;EAAA,IAEV,OAAA;EAvDU;;;;;;;;;;;;EAqEb,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,QAAA,YACA,MAAA,YACC,OAAA,CAAQ,WAAA;EA9CX;;;;;EAAA,SAqDS,gBAAA,GAAmB,iBAAA;EAhDf;;;;;EAAA,SAuDJ,mBAAA,GAAsB,oBAAA;EA1CrB;;;;;;;;EAAA,SAoDD,iBAAA,GAAoB,iBAAA;EA5ChB;;;;;;;;EAAA,SAsDJ,yBAAA,IACP,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;EArCC;;;;;;EAAA,SA6CM,oCAAA,IACP,QAAA,EAAU,QAAA,CAAS,UAAA,OAEnB,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;EA1B2B;;;;EAiC7B,4BAAA,aAAyC,OAAA;EArBvC;;;;EA2BF,0BAAA,aAAuC,OAAA;EAjBrC;;;;;;;;;EA4BF,KAAA,CAAM,GAAA,EAAK,WAAA,GAAc,OAAA,EAAS,OAAA,EAAS,cAAA,YAA0B,gBAAA;AAAA;;;;;;;UAStD,2BAAA;EATsE;AASvF;;;;;EAOE,MAAA,CAAO,KAAA,EAAO,YAAA,QAAoB,OAAA,IAAW,iBAAA,CAAkB,OAAA;AAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SqlControlAdapterDescriptor, t as SqlControlAdapter } from "./control-adapter-
|
|
1
|
+
import { n as SqlControlAdapterDescriptor, t as SqlControlAdapter } from "./control-adapter-uYnmu04p.mjs";
|
|
2
2
|
export { type SqlControlAdapter, type SqlControlAdapterDescriptor };
|
package/dist/control.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as SqlPlannerResult, C as SqlMigrationRunnerResult, D as SqlPlannerConflictKind, E as SqlPlannerConflict, M as StorageTypePlanResult, N as SqlControlFamilyInstance, O as SqlPlannerConflictLocation, S as SqlMigrationRunnerFailure, T as SqlPlanTargetDetails, _ as SqlMigrationPlannerPlanOptions, a as FieldEvent, b as SqlMigrationRunnerExecuteCallbacks, c as SqlControlAdapterDescriptor, d as SqlMigrationPlan, f as SqlMigrationPlanContractInfo, g as SqlMigrationPlanner, h as SqlMigrationPlanOperationTarget, i as ExpandNativeTypeInput, j as SqlPlannerSuccessResult, k as SqlPlannerFailureResult, l as SqlControlExtensionDescriptor, m as SqlMigrationPlanOperationStep, n as CodecControlHooks, o as FieldEventContext, p as SqlMigrationPlanOperation, r as CreateSqlMigrationPlanOptions, s as ResolveIdentityValueInput, t as AnyRecord, u as SqlControlTargetDescriptor, v as SqlMigrationRunner, w as SqlMigrationRunnerSuccessValue, x as SqlMigrationRunnerExecuteOptions, y as SqlMigrationRunnerErrorCode } from "./types-
|
|
1
|
+
import { A as SqlPlannerResult, C as SqlMigrationRunnerResult, D as SqlPlannerConflictKind, E as SqlPlannerConflict, M as StorageTypePlanResult, N as SqlControlFamilyInstance, O as SqlPlannerConflictLocation, S as SqlMigrationRunnerFailure, T as SqlPlanTargetDetails, _ as SqlMigrationPlannerPlanOptions, a as FieldEvent, b as SqlMigrationRunnerExecuteCallbacks, c as SqlControlAdapterDescriptor, d as SqlMigrationPlan, f as SqlMigrationPlanContractInfo, g as SqlMigrationPlanner, h as SqlMigrationPlanOperationTarget, i as ExpandNativeTypeInput, j as SqlPlannerSuccessResult, k as SqlPlannerFailureResult, l as SqlControlExtensionDescriptor, m as SqlMigrationPlanOperationStep, n as CodecControlHooks, o as FieldEventContext, p as SqlMigrationPlanOperation, r as CreateSqlMigrationPlanOptions, s as ResolveIdentityValueInput, t as AnyRecord, u as SqlControlTargetDescriptor, v as SqlMigrationRunner, w as SqlMigrationRunnerSuccessValue, x as SqlMigrationRunnerExecuteOptions, y as SqlMigrationRunnerErrorCode } from "./types-DxNgxFkF.mjs";
|
|
2
2
|
import { ControlFamilyDescriptor, ControlStack, MigrationOperationClass, MigrationOperationPolicy, MigrationOperationPolicy as MigrationOperationPolicy$1, MigrationPlan, MigrationPlanOperation, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerConflict as MigrationPlannerConflict$1, MigrationPlannerResult, MutationDefaultGeneratorDescriptor, OpFactoryCall, TargetMigrationsCapability, assembleAuthoringContributions } from "@prisma-next/framework-components/control";
|
|
3
3
|
import { SqlStorage, StorageColumn } from "@prisma-next/sql-contract/types";
|
|
4
4
|
import { ColumnDefault, Contract, ControlPolicy } from "@prisma-next/contract/types";
|
package/dist/control.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import { sqlEmission } from "@prisma-next/sql-contract-emitter";
|
|
|
7
7
|
import { APP_SPACE_ID, SchemaTreeNode, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_TARGET_MISMATCH, assembleAuthoringContributions } from "@prisma-next/framework-components/control";
|
|
8
8
|
import { assertDescriptorSelfConsistency } from "@prisma-next/migration-tools/spaces";
|
|
9
9
|
import { sqlContractCanonicalizationHooks } from "@prisma-next/sql-contract/canonicalization-hooks";
|
|
10
|
-
import { writeContractMarker } from "@prisma-next/sql-runtime";
|
|
11
10
|
import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
|
|
12
11
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
13
12
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
@@ -1239,14 +1238,10 @@ function createSqlFamilyInstance(stack) {
|
|
|
1239
1238
|
let markerUpdated = false;
|
|
1240
1239
|
let previousHashes;
|
|
1241
1240
|
if (!existingMarker) {
|
|
1242
|
-
|
|
1243
|
-
space: APP_SPACE_ID,
|
|
1241
|
+
await controlAdapter.insertMarker(driver, APP_SPACE_ID, {
|
|
1244
1242
|
storageHash: contractStorageHash,
|
|
1245
|
-
profileHash: contractProfileHash
|
|
1246
|
-
contractJson: contractInput,
|
|
1247
|
-
canonicalVersion: 1
|
|
1243
|
+
profileHash: contractProfileHash
|
|
1248
1244
|
});
|
|
1249
|
-
await driver.query(write.insert.sql, write.insert.params);
|
|
1250
1245
|
markerCreated = true;
|
|
1251
1246
|
} else {
|
|
1252
1247
|
const existingStorageHash = existingMarker.storageHash;
|
|
@@ -1256,14 +1251,10 @@ function createSqlFamilyInstance(stack) {
|
|
|
1256
1251
|
storageHash: existingStorageHash,
|
|
1257
1252
|
profileHash: existingProfileHash
|
|
1258
1253
|
};
|
|
1259
|
-
|
|
1260
|
-
space: APP_SPACE_ID,
|
|
1254
|
+
if (!await controlAdapter.updateMarker(driver, APP_SPACE_ID, existingStorageHash, {
|
|
1261
1255
|
storageHash: contractStorageHash,
|
|
1262
|
-
profileHash: contractProfileHash
|
|
1263
|
-
|
|
1264
|
-
canonicalVersion: existingMarker.canonicalVersion ?? 1
|
|
1265
|
-
});
|
|
1266
|
-
await driver.query(write.update.sql, write.update.params);
|
|
1256
|
+
profileHash: contractProfileHash
|
|
1257
|
+
})) throw new Error("CAS conflict: marker was modified by another process during sign");
|
|
1267
1258
|
markerUpdated = true;
|
|
1268
1259
|
}
|
|
1269
1260
|
}
|
|
@@ -1304,6 +1295,15 @@ function createSqlFamilyInstance(stack) {
|
|
|
1304
1295
|
async readLedger(options) {
|
|
1305
1296
|
return getControlAdapter().readLedger(options.driver, options.space);
|
|
1306
1297
|
},
|
|
1298
|
+
async initMarker(options) {
|
|
1299
|
+
return getControlAdapter().initMarker(options.driver, options.space, options.destination);
|
|
1300
|
+
},
|
|
1301
|
+
async updateMarker(options) {
|
|
1302
|
+
return getControlAdapter().updateMarker(options.driver, options.space, options.expectedFrom, options.destination);
|
|
1303
|
+
},
|
|
1304
|
+
async writeLedgerEntry(options) {
|
|
1305
|
+
return getControlAdapter().writeLedgerEntry(options.driver, options.space, options.entry);
|
|
1306
|
+
},
|
|
1307
1307
|
async introspect(options) {
|
|
1308
1308
|
return getControlAdapter().introspect(options.driver, options.contract);
|
|
1309
1309
|
},
|