@prisma-next/target-mongo 0.4.0-dev.1 → 0.4.0-dev.2
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 +3 -2
- package/dist/control.d.mts +107 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +905 -1
- package/dist/control.mjs.map +1 -1
- package/dist/migration-factories-Brzz-QGG.mjs +154 -0
- package/dist/migration-factories-Brzz-QGG.mjs.map +1 -0
- package/dist/migration.d.mts +4 -2
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +2 -125
- package/dist/op-factory-call-CfPGebEH.d.mts +76 -0
- package/dist/op-factory-call-CfPGebEH.d.mts.map +1 -0
- package/package.json +9 -4
- package/src/core/contract-to-schema.ts +63 -0
- package/src/core/ddl-formatter.ts +112 -0
- package/src/core/filter-evaluator.ts +84 -0
- package/src/core/migration-factories.ts +51 -0
- package/src/core/mongo-ops-serializer.ts +277 -0
- package/src/core/mongo-planner.ts +306 -0
- package/src/core/mongo-runner.ts +275 -0
- package/src/core/op-factory-call.ts +196 -0
- package/src/core/render-ops.ts +39 -0
- package/src/core/render-typescript.ts +137 -0
- package/src/exports/control.ts +25 -0
- package/src/exports/migration.ts +1 -0
- package/dist/migration.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ const contract = defineContract({
|
|
|
36
36
|
import { Migration } from '@prisma-next/family-mongo/migration';
|
|
37
37
|
import { createIndex, createCollection } from '@prisma-next/target-mongo/migration';
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
class UsersMigration extends Migration {
|
|
40
40
|
plan() {
|
|
41
41
|
return [
|
|
42
42
|
createCollection("users", {
|
|
@@ -48,7 +48,8 @@ export default class extends Migration {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
export default UsersMigration;
|
|
52
|
+
Migration.run(import.meta.url, UsersMigration)
|
|
52
53
|
```
|
|
53
54
|
|
|
54
55
|
Run `tsx migration.ts` to produce `ops.json` and `migration.json` (when `describe()` is implemented). Use `--dry-run` to preview without writing.
|
package/dist/control.d.mts
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
+
import { a as DropCollectionCall, c as OpFactoryCallVisitor, i as CreateIndexCall, l as schemaCollectionToCreateCollectionOptions, n as CollModMeta, o as DropIndexCall, r as CreateCollectionCall, s as OpFactoryCall, t as CollModCall, u as schemaIndexToCreateIndexOptions } from "./op-factory-call-CfPGebEH.mjs";
|
|
2
|
+
import { MongoSchemaIR } from "@prisma-next/mongo-schema-ir";
|
|
3
|
+
import { MongoAndExpr, MongoDdlCommandVisitor, MongoExistsExpr, MongoExprFilter, MongoFieldFilter, MongoFilterExpr, MongoFilterVisitor, MongoInspectionCommandVisitor, MongoMigrationPlanOperation, MongoNotExpr, MongoOrExpr } from "@prisma-next/mongo-query-ast/control";
|
|
4
|
+
import { MongoContract } from "@prisma-next/mongo-contract";
|
|
5
|
+
import { MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerResult, MigrationRunnerExecutionChecks, MigrationRunnerResult } from "@prisma-next/framework-components/control";
|
|
1
6
|
import { ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
2
7
|
import { Db } from "mongodb";
|
|
8
|
+
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
3
9
|
|
|
10
|
+
//#region src/core/contract-to-schema.d.ts
|
|
11
|
+
declare function contractToMongoSchemaIR(contract: MongoContract | null): MongoSchemaIR;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/core/ddl-formatter.d.ts
|
|
14
|
+
declare function formatMongoOperations(operations: readonly MigrationPlanOperation[]): string[];
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/core/filter-evaluator.d.ts
|
|
17
|
+
declare class FilterEvaluator implements MongoFilterVisitor<boolean> {
|
|
18
|
+
private doc;
|
|
19
|
+
evaluate(filter: MongoFilterExpr, doc: Record<string, unknown>): boolean;
|
|
20
|
+
field(expr: MongoFieldFilter): boolean;
|
|
21
|
+
and(expr: MongoAndExpr): boolean;
|
|
22
|
+
or(expr: MongoOrExpr): boolean;
|
|
23
|
+
not(expr: MongoNotExpr): boolean;
|
|
24
|
+
exists(expr: MongoExistsExpr): boolean;
|
|
25
|
+
expr(_expr: MongoExprFilter): boolean;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
4
28
|
//#region src/core/marker-ledger.d.ts
|
|
5
29
|
declare function readMarker(db: Db): Promise<ContractMarkerRecord | null>;
|
|
6
30
|
declare function initMarker(db: Db, destination: {
|
|
@@ -17,5 +41,87 @@ declare function writeLedgerEntry(db: Db, entry: {
|
|
|
17
41
|
readonly to: string;
|
|
18
42
|
}): Promise<void>;
|
|
19
43
|
//#endregion
|
|
20
|
-
|
|
44
|
+
//#region src/core/mongo-ops-serializer.d.ts
|
|
45
|
+
declare function deserializeMongoOp(json: unknown): MongoMigrationPlanOperation;
|
|
46
|
+
declare function deserializeMongoOps(json: readonly unknown[]): MongoMigrationPlanOperation[];
|
|
47
|
+
declare function serializeMongoOps(ops: readonly MongoMigrationPlanOperation[]): string;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/core/mongo-planner.d.ts
|
|
50
|
+
type PlanCallsResult = {
|
|
51
|
+
readonly kind: 'success';
|
|
52
|
+
readonly calls: OpFactoryCall[];
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: 'failure';
|
|
55
|
+
readonly conflicts: MigrationPlannerConflict[];
|
|
56
|
+
};
|
|
57
|
+
declare class MongoMigrationPlanner implements MigrationPlanner<'mongo', 'mongo'> {
|
|
58
|
+
planCalls(options: {
|
|
59
|
+
readonly contract: unknown;
|
|
60
|
+
readonly schema: unknown;
|
|
61
|
+
readonly policy: MigrationOperationPolicy;
|
|
62
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'mongo', 'mongo'>>;
|
|
63
|
+
}): PlanCallsResult;
|
|
64
|
+
plan(options: {
|
|
65
|
+
readonly contract: unknown;
|
|
66
|
+
readonly schema: unknown;
|
|
67
|
+
readonly policy: MigrationOperationPolicy;
|
|
68
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'mongo', 'mongo'>>;
|
|
69
|
+
}): MigrationPlannerResult;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/core/mongo-runner.d.ts
|
|
73
|
+
interface MarkerOperations {
|
|
74
|
+
readMarker(): Promise<ContractMarkerRecord | null>;
|
|
75
|
+
initMarker(destination: {
|
|
76
|
+
readonly storageHash: string;
|
|
77
|
+
readonly profileHash: string;
|
|
78
|
+
}): Promise<void>;
|
|
79
|
+
updateMarker(expectedFrom: string, destination: {
|
|
80
|
+
readonly storageHash: string;
|
|
81
|
+
readonly profileHash: string;
|
|
82
|
+
}): Promise<boolean>;
|
|
83
|
+
writeLedgerEntry(entry: {
|
|
84
|
+
readonly edgeId: string;
|
|
85
|
+
readonly from: string;
|
|
86
|
+
readonly to: string;
|
|
87
|
+
}): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
interface MongoRunnerDependencies {
|
|
90
|
+
readonly commandExecutor: MongoDdlCommandVisitor<Promise<void>>;
|
|
91
|
+
readonly inspectionExecutor: MongoInspectionCommandVisitor<Promise<Record<string, unknown>[]>>;
|
|
92
|
+
readonly markerOps: MarkerOperations;
|
|
93
|
+
}
|
|
94
|
+
declare class MongoMigrationRunner {
|
|
95
|
+
private readonly deps;
|
|
96
|
+
constructor(deps: MongoRunnerDependencies);
|
|
97
|
+
execute(options: {
|
|
98
|
+
readonly plan: MigrationPlan;
|
|
99
|
+
readonly destinationContract: unknown;
|
|
100
|
+
readonly policy: MigrationOperationPolicy;
|
|
101
|
+
readonly callbacks?: {
|
|
102
|
+
onOperationStart?(op: MigrationPlanOperation): void;
|
|
103
|
+
onOperationComplete?(op: MigrationPlanOperation): void;
|
|
104
|
+
};
|
|
105
|
+
readonly executionChecks?: MigrationRunnerExecutionChecks;
|
|
106
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'mongo', 'mongo'>>;
|
|
107
|
+
}): Promise<MigrationRunnerResult>;
|
|
108
|
+
private evaluateChecks;
|
|
109
|
+
private allChecksSatisfied;
|
|
110
|
+
private enforcePolicyCompatibility;
|
|
111
|
+
private ensureMarkerCompatibility;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/core/render-ops.d.ts
|
|
115
|
+
declare function renderOps(calls: ReadonlyArray<OpFactoryCall>): MongoMigrationPlanOperation[];
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/core/render-typescript.d.ts
|
|
118
|
+
interface RenderMigrationMeta {
|
|
119
|
+
readonly from: string;
|
|
120
|
+
readonly to: string;
|
|
121
|
+
readonly kind?: string;
|
|
122
|
+
readonly labels?: readonly string[];
|
|
123
|
+
}
|
|
124
|
+
declare function renderTypeScript(calls: ReadonlyArray<OpFactoryCall>, meta?: RenderMigrationMeta): string;
|
|
125
|
+
//#endregion
|
|
126
|
+
export { CollModCall, type CollModMeta, CreateCollectionCall, CreateIndexCall, DropCollectionCall, DropIndexCall, FilterEvaluator, type MarkerOperations, MongoMigrationPlanner, MongoMigrationRunner, type MongoRunnerDependencies, type OpFactoryCall, type OpFactoryCallVisitor, type PlanCallsResult, type RenderMigrationMeta, contractToMongoSchemaIR, deserializeMongoOp, deserializeMongoOps, formatMongoOperations, initMarker, readMarker, renderOps, renderTypeScript, schemaCollectionToCreateCollectionOptions, schemaIndexToCreateIndexOptions, serializeMongoOps, updateMarker, writeLedgerEntry };
|
|
21
127
|
//# sourceMappingURL=control.d.mts.map
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/marker-ledger.ts"],"sourcesContent":[],"mappings":"
|
|
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/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;AF5Bd;;;iBGrBsB,UAAA,KAAe,KAAK,QAAQ;iBAgB5B,UAAA,KAChB;;;IAEH;iBAcmB,YAAA,KAChB;;;AHbN,CAAA,CAAA,EGgBG,OHhBa,CAAA,OAAA,CAAA;iBGiCM,gBAAA,KAChB;;;EFWU,SAAA,EAAA,EAAA,MAAA;IETb;;;iBC0Ka,kBAAA,iBAAmC;iBAYnC,mBAAA,4BAA+C;iBAI/C,iBAAA,eAAgC;;;KChLpC,eAAA;;kBACoC;;;sBACI;;ALhDpC,cKkDH,qBAAA,YAAiC,gBLlD2B,CAAa,OAAA,EAAA,OAAA,CAAA,CAAA;;;;IC6CtE,SAAA,MAAA,EISK,wBJTsC;kCIUzB,cAAc;MAC1C;;IH1DO,SAAA,QAAgB,EAAA,OAAA;IAGV,SAAA,MAAA,EAAA,OAAA;IAAsB,SAAA,MAAA,EG2KpB,wBH3KoB;IAK3B,SAAA,mBAAA,EGuKoB,aHvKpB,CGuKkC,8BHvKlC,CAAA,OAAA,EAAA,OAAA,CAAA,CAAA;EAKF,CAAA,CAAA,EGmKN,sBHnKM;;;;UI3CK,gBAAA;gBACD,QAAQ;;;;MAIlB;EN2BU,YAAA,CAAA,YAAA,EAAuB,MAAA,EAAA,WAAW,EAAA;;;MMvB7C;ELoEW,gBAAA,CAAA,KAAA,EAAqB;;;;EC/CxB,CAAA,CAAA,EIhBP,OJgBO,CAAA,IAAA,CAAA;;AAG4B,UIhBxB,uBAAA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