@prisma-next/target-mongo 0.5.0-dev.5 → 0.5.0-dev.6
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/README.md +2 -0
- package/dist/control.d.mts +17 -13
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +16 -45
- package/dist/control.mjs.map +1 -1
- package/dist/{migration-factories-gwi81C8u.mjs → migration-factories-Dbk5afMU.mjs} +1 -1
- package/dist/{migration-factories-gwi81C8u.mjs.map → migration-factories-Dbk5afMU.mjs.map} +1 -1
- package/dist/migration.d.mts +1 -1
- package/dist/migration.mjs +1 -1
- package/dist/{op-factory-call-BjNAcPSF.d.mts → op-factory-call-CVgzmLJh.d.mts} +1 -1
- package/dist/{op-factory-call-BjNAcPSF.d.mts.map → op-factory-call-CVgzmLJh.d.mts.map} +1 -1
- package/dist/schema-verify.d.mts +22 -0
- package/dist/schema-verify.d.mts.map +1 -0
- package/dist/schema-verify.mjs +3 -0
- package/dist/verify-mongo-schema-P0TRBJNs.mjs +582 -0
- package/dist/verify-mongo-schema-P0TRBJNs.mjs.map +1 -0
- package/package.json +15 -14
- package/src/core/mongo-runner.ts +38 -26
- package/src/core/schema-diff.ts +402 -0
- package/src/core/schema-verify/canonicalize-introspection.ts +389 -0
- package/src/core/schema-verify/verify-mongo-schema.ts +60 -0
- package/src/exports/schema-verify.ts +2 -0
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ MongoDB target pack for Prisma Next.
|
|
|
14
14
|
- `./pack`: pure target pack ref used by `@prisma-next/family-mongo` and `@prisma-next/mongo-contract-ts`
|
|
15
15
|
- `./codec-types`: base Mongo codec type map
|
|
16
16
|
- `./migration`: factory functions (the `Migration` base class is in `@prisma-next/family-mongo/migration`)
|
|
17
|
+
- `./control`: `MongoMigrationRunner` and `createMongoRunnerDeps` for runtime migration execution
|
|
18
|
+
- `./schema-verify`: pure `verifyMongoSchema(...)` (no DB I/O); composes `contractToMongoSchemaIR` and `diffMongoSchemas` so the runner's post-apply verify step and `MongoFamilyInstance.schemaVerify` agree on "matches the contract" by construction
|
|
17
19
|
|
|
18
20
|
## Usage
|
|
19
21
|
|
package/dist/control.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as DropCollectionCall, c as schemaCollectionToCreateCollectionOptions, i as CreateIndexCall, l as schemaIndexToCreateIndexOptions, n as CollModMeta, o as DropIndexCall, r as CreateCollectionCall, s as OpFactoryCall, t as CollModCall } from "./op-factory-call-
|
|
1
|
+
import { a as DropCollectionCall, c as schemaCollectionToCreateCollectionOptions, i as CreateIndexCall, l as schemaIndexToCreateIndexOptions, n as CollModMeta, o as DropIndexCall, r as CreateCollectionCall, s as OpFactoryCall, t as CollModCall } from "./op-factory-call-CVgzmLJh.mjs";
|
|
2
2
|
import { MongoSchemaIR } from "@prisma-next/mongo-schema-ir";
|
|
3
3
|
import { MongoQueryPlan } from "@prisma-next/mongo-query-ast/execution";
|
|
4
4
|
import { AnyMongoMigrationOperation, MongoAndExpr, MongoDdlCommandVisitor, MongoExistsExpr, MongoExprFilter, MongoFieldFilter, MongoFilterExpr, MongoFilterVisitor, MongoInspectionCommandVisitor, MongoMigrationPlanOperation, MongoNotExpr, MongoOrExpr } from "@prisma-next/mongo-query-ast/control";
|
|
5
5
|
import { Migration, MigrationMeta } from "@prisma-next/migration-tools/migration";
|
|
6
|
+
import { MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlanWithAuthoringSurface, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerResult, MigrationRunnerExecutionChecks, MigrationRunnerResult, MigrationScaffoldContext, OperationContext } from "@prisma-next/framework-components/control";
|
|
6
7
|
import { MongoContract } from "@prisma-next/mongo-contract";
|
|
7
|
-
import { MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlanWithAuthoringSurface, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerResult, MigrationRunnerExecutionChecks, MigrationRunnerResult, MigrationScaffoldContext } from "@prisma-next/framework-components/control";
|
|
8
8
|
import { ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
9
9
|
import { Db } from "mongodb";
|
|
10
10
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
@@ -106,21 +106,25 @@ interface MongoRunnerDependencies {
|
|
|
106
106
|
readonly adapter: MongoAdapter;
|
|
107
107
|
readonly driver: MongoDriver;
|
|
108
108
|
readonly markerOps: MarkerOperations;
|
|
109
|
+
readonly introspectSchema: () => Promise<MongoSchemaIR>;
|
|
110
|
+
}
|
|
111
|
+
interface MongoMigrationRunnerExecuteOptions {
|
|
112
|
+
readonly plan: MigrationPlan;
|
|
113
|
+
readonly destinationContract: MongoContract;
|
|
114
|
+
readonly policy: MigrationOperationPolicy;
|
|
115
|
+
readonly callbacks?: {
|
|
116
|
+
onOperationStart?(op: MigrationPlanOperation): void;
|
|
117
|
+
onOperationComplete?(op: MigrationPlanOperation): void;
|
|
118
|
+
};
|
|
119
|
+
readonly executionChecks?: MigrationRunnerExecutionChecks;
|
|
120
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'mongo', 'mongo'>>;
|
|
121
|
+
readonly strictVerification?: boolean;
|
|
122
|
+
readonly context?: OperationContext;
|
|
109
123
|
}
|
|
110
124
|
declare class MongoMigrationRunner {
|
|
111
125
|
private readonly deps;
|
|
112
126
|
constructor(deps: MongoRunnerDependencies);
|
|
113
|
-
execute(options:
|
|
114
|
-
readonly plan: MigrationPlan;
|
|
115
|
-
readonly destinationContract: unknown;
|
|
116
|
-
readonly policy: MigrationOperationPolicy;
|
|
117
|
-
readonly callbacks?: {
|
|
118
|
-
onOperationStart?(op: MigrationPlanOperation): void;
|
|
119
|
-
onOperationComplete?(op: MigrationPlanOperation): void;
|
|
120
|
-
};
|
|
121
|
-
readonly executionChecks?: MigrationRunnerExecutionChecks;
|
|
122
|
-
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'mongo', 'mongo'>>;
|
|
123
|
-
}): Promise<MigrationRunnerResult>;
|
|
127
|
+
execute(options: MongoMigrationRunnerExecuteOptions): Promise<MigrationRunnerResult>;
|
|
124
128
|
private executeDataTransform;
|
|
125
129
|
private evaluateDataTransformChecks;
|
|
126
130
|
private evaluateChecks;
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/contract-to-schema.ts","../src/core/ddl-formatter.ts","../src/core/filter-evaluator.ts","../src/core/marker-ledger.ts","../src/core/mongo-ops-serializer.ts","../src/core/mongo-planner.ts","../src/core/mongo-runner.ts","../src/core/planner-produced-migration.ts","../src/core/render-ops.ts","../src/core/render-typescript.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;iBAoDgB,uBAAA,WAAkC,uBAAuB;;;iBC6CzD,qBAAA,sBAA2C;;;cC/C9C,eAAA,YAA2B;;mBAGrB,sBAAsB;cAK3B;YAKF;WAID;YAIC;eAIG;cAKD;;;;iBCjDQ,UAAA,KAAe,KAAK,QAAQ;iBAgB5B,UAAA,KAChB;;;IAEH;iBAcmB,YAAA,KAChB;;;IAGH;iBAiBmB,gBAAA,KAChB;;EHlCU,SAAA,IAAA,EAAA,MAAA;;IGoCb;;;iBC8ea,kBAAA,iBAAmC;iBAOnC,mBAAA,4BAA+C;iBAI/C,iBAAA,eAAgC;;;KC7epC,eAAA;;kBACoC;;;sBACI;;cAEvC,qBAAA,YAAiC;;;ILpD9B,SAAA,MAAA,EAAA,OAAuB;qBKwDlB;kCACa,cAAc;MAC1C;EJbU,IAAA,CAAA,OAAA,EAAA;;;qBIiIK;IHhLR,SAAA,QAAgB,EAAA,MAAA;IAGV,SAAA,mBAAA,EG+Ke,aH/Kf,CG+K6B,8BH/K7B,CAAA,OAAA,EAAA,OAAA,CAAA,CAAA;EAAsB,CAAA,CAAA,EGgLnC,sBHhLmC;EAK3B;;;;;;;;;0BGiMY,2BAA2B;;;;
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/contract-to-schema.ts","../src/core/ddl-formatter.ts","../src/core/filter-evaluator.ts","../src/core/marker-ledger.ts","../src/core/mongo-ops-serializer.ts","../src/core/mongo-planner.ts","../src/core/mongo-runner.ts","../src/core/planner-produced-migration.ts","../src/core/render-ops.ts","../src/core/render-typescript.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;iBAoDgB,uBAAA,WAAkC,uBAAuB;;;iBC6CzD,qBAAA,sBAA2C;;;cC/C9C,eAAA,YAA2B;;mBAGrB,sBAAsB;cAK3B;YAKF;WAID;YAIC;eAIG;cAKD;;;;iBCjDQ,UAAA,KAAe,KAAK,QAAQ;iBAgB5B,UAAA,KAChB;;;IAEH;iBAcmB,YAAA,KAChB;;;IAGH;iBAiBmB,gBAAA,KAChB;;EHlCU,SAAA,IAAA,EAAA,MAAA;;IGoCb;;;iBC8ea,kBAAA,iBAAmC;iBAOnC,mBAAA,4BAA+C;iBAI/C,iBAAA,eAAgC;;;KC7epC,eAAA;;kBACoC;;;sBACI;;cAEvC,qBAAA,YAAiC;;;ILpD9B,SAAA,MAAA,EAAA,OAAuB;qBKwDlB;kCACa,cAAc;MAC1C;EJbU,IAAA,CAAA,OAAA,EAAA;;;qBIiIK;IHhLR,SAAA,QAAgB,EAAA,MAAA;IAGV,SAAA,mBAAA,EG+Ke,aH/Kf,CG+K6B,8BH/K7B,CAAA,OAAA,EAAA,OAAA,CAAA,CAAA;EAAsB,CAAA,CAAA,EGgLnC,sBHhLmC;EAK3B;;;;;;;;;0BGiMY,2BAA2B;;;;UC5NpC,gBAAA;gBACD,QAAQ;;;;MAIlB;ENgBU,YAAA,CAAA,YAAA,EAAuB,MAAA,EAAA,WAAW,EAAA;;;MMZ7C;ELyDW,gBAAA,CAAA,KAAA,EAAqB;;;;EC/CxB,CAAA,CAAA,EILP,OJKO,CAAA,IAAA,CAAA;;AAG4B,UILxB,uBAAA,CJKwB;EAK3B,SAAA,eA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B0B,0BL0B1B,EAAA;EAID,QAAA,CAAA,CAAA,EK1BY,aL0BZ;EAIC,gBAAA,CAAA,CAAA,EAAA,MAAA;;;;iBMpEI,SAAA,QAAiB,cAAc,iBAAiB;;;UCC/C,mBAAA;;;;;;;;;;;;ATgDjB;;;;AC6CA;;;;AC/CA;;;AAQc,iBOTE,uBAAA,CPSF,KAAA,EORL,aPQK,CORS,aPQT,CAAA,EAAA,IAAA,EOPN,mBPOM,CAAA,EAAA,MAAA"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { n as contractToMongoSchemaIR, t as verifyMongoSchema } from "./verify-mongo-schema-P0TRBJNs.mjs";
|
|
2
|
+
import { a as dropCollection, n as createCollection, o as dropIndex, r as createIndex, t as collMod } from "./migration-factories-Dbk5afMU.mjs";
|
|
3
|
+
import { canonicalize, deepEqual } from "@prisma-next/mongo-schema-ir";
|
|
3
4
|
import { AggregateCommand, MongoAddFieldsStage, MongoLimitStage, MongoLookupStage, MongoMatchStage, MongoMergeStage, MongoProjectStage, MongoSortStage, RawAggregateCommand, RawDeleteManyCommand, RawDeleteOneCommand, RawFindOneAndDeleteCommand, RawFindOneAndUpdateCommand, RawInsertManyCommand, RawInsertOneCommand, RawUpdateManyCommand, RawUpdateOneCommand } from "@prisma-next/mongo-query-ast/execution";
|
|
4
5
|
import { CollModCommand, CreateCollectionCommand, CreateIndexCommand, DropCollectionCommand, DropIndexCommand, ListCollectionsCommand, ListIndexesCommand, MongoAndExpr, MongoExistsExpr, MongoFieldFilter, MongoNotExpr, MongoOrExpr } from "@prisma-next/mongo-query-ast/control";
|
|
5
6
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
@@ -10,45 +11,6 @@ import { detectScaffoldRuntime, shebangLineFor } from "@prisma-next/migration-to
|
|
|
10
11
|
import { errorRunnerFailed } from "@prisma-next/errors/execution";
|
|
11
12
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
12
13
|
|
|
13
|
-
//#region src/core/contract-to-schema.ts
|
|
14
|
-
function convertIndex(index) {
|
|
15
|
-
return new MongoSchemaIndex({
|
|
16
|
-
keys: index.keys,
|
|
17
|
-
unique: index.unique,
|
|
18
|
-
sparse: index.sparse,
|
|
19
|
-
expireAfterSeconds: index.expireAfterSeconds,
|
|
20
|
-
partialFilterExpression: index.partialFilterExpression,
|
|
21
|
-
wildcardProjection: index.wildcardProjection,
|
|
22
|
-
collation: index.collation,
|
|
23
|
-
weights: index.weights,
|
|
24
|
-
default_language: index.default_language,
|
|
25
|
-
language_override: index.language_override
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function convertValidator(v) {
|
|
29
|
-
return new MongoSchemaValidator({
|
|
30
|
-
jsonSchema: v.jsonSchema,
|
|
31
|
-
validationLevel: v.validationLevel,
|
|
32
|
-
validationAction: v.validationAction
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function convertOptions(o) {
|
|
36
|
-
return new MongoSchemaCollectionOptions(o);
|
|
37
|
-
}
|
|
38
|
-
function convertCollection(name, def) {
|
|
39
|
-
return new MongoSchemaCollection({
|
|
40
|
-
name,
|
|
41
|
-
indexes: (def.indexes ?? []).map(convertIndex),
|
|
42
|
-
...def.validator != null && { validator: convertValidator(def.validator) },
|
|
43
|
-
...def.options != null && { options: convertOptions(def.options) }
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
function contractToMongoSchemaIR(contract) {
|
|
47
|
-
if (!contract) return new MongoSchemaIR([]);
|
|
48
|
-
return new MongoSchemaIR(Object.entries(contract.storage.collections).map(([name, def]) => convertCollection(name, def)));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//#endregion
|
|
52
14
|
//#region src/core/ddl-formatter.ts
|
|
53
15
|
function formatKeySpec(keys) {
|
|
54
16
|
return `{ ${keys.map((k) => `${JSON.stringify(k.field)}: ${JSON.stringify(k.direction)}`).join(", ")} }`;
|
|
@@ -1128,9 +1090,6 @@ function planMutableOptionsDiffCall(collName, origin, dest) {
|
|
|
1128
1090
|
//#endregion
|
|
1129
1091
|
//#region src/core/mongo-runner.ts
|
|
1130
1092
|
const READ_ONLY_CHECK_COMMAND_KINDS = new Set(["aggregate", "rawAggregate"]);
|
|
1131
|
-
function hasProfileHash(value) {
|
|
1132
|
-
return typeof value === "object" && value !== null && Object.hasOwn(value, "profileHash") && typeof value.profileHash === "string";
|
|
1133
|
-
}
|
|
1134
1093
|
function runnerFailure(code, summary, opts) {
|
|
1135
1094
|
return notOk({
|
|
1136
1095
|
code,
|
|
@@ -1182,11 +1141,23 @@ var MongoMigrationRunner = class {
|
|
|
1182
1141
|
}
|
|
1183
1142
|
}
|
|
1184
1143
|
const destination = options.plan.destination;
|
|
1185
|
-
const profileHash =
|
|
1144
|
+
const profileHash = options.destinationContract.profileHash ?? destination.storageHash;
|
|
1186
1145
|
if (operationsExecuted === 0 && existingMarker?.storageHash === destination.storageHash && existingMarker.profileHash === profileHash) return ok({
|
|
1187
1146
|
operationsPlanned: operations.length,
|
|
1188
1147
|
operationsExecuted
|
|
1189
1148
|
});
|
|
1149
|
+
const liveSchema = await this.deps.introspectSchema();
|
|
1150
|
+
const verifyResult = verifyMongoSchema({
|
|
1151
|
+
contract: options.destinationContract,
|
|
1152
|
+
schema: liveSchema,
|
|
1153
|
+
strict: options.strictVerification ?? true,
|
|
1154
|
+
frameworkComponents: options.frameworkComponents,
|
|
1155
|
+
...options.context ? { context: options.context } : {}
|
|
1156
|
+
});
|
|
1157
|
+
if (!verifyResult.ok) return runnerFailure("SCHEMA_VERIFY_FAILED", verifyResult.summary, {
|
|
1158
|
+
why: "The resulting database schema does not satisfy the destination contract.",
|
|
1159
|
+
meta: { issues: verifyResult.schema.issues }
|
|
1160
|
+
});
|
|
1190
1161
|
if (existingMarker) {
|
|
1191
1162
|
if (!await markerOps.updateMarker(existingMarker.storageHash, {
|
|
1192
1163
|
storageHash: destination.storageHash,
|