@prisma-next/adapter-mongo 0.3.0-dev.147 → 0.3.0-dev.162

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.
@@ -0,0 +1,85 @@
1
+ import { mongoCodec } from "@prisma-next/mongo-codec";
2
+ import { ObjectId } from "mongodb";
3
+
4
+ //#region src/core/codec-ids.ts
5
+ const MONGO_OBJECTID_CODEC_ID = "mongo/objectId@1";
6
+ const MONGO_STRING_CODEC_ID = "mongo/string@1";
7
+ const MONGO_DOUBLE_CODEC_ID = "mongo/double@1";
8
+ const MONGO_INT32_CODEC_ID = "mongo/int32@1";
9
+ const MONGO_BOOLEAN_CODEC_ID = "mongo/bool@1";
10
+ const MONGO_DATE_CODEC_ID = "mongo/date@1";
11
+ const MONGO_VECTOR_CODEC_ID = "mongo/vector@1";
12
+
13
+ //#endregion
14
+ //#region src/core/codecs.ts
15
+ const mongoObjectIdCodec = mongoCodec({
16
+ typeId: MONGO_OBJECTID_CODEC_ID,
17
+ targetTypes: ["objectId"],
18
+ traits: ["equality"],
19
+ decode: (wire) => wire.toHexString(),
20
+ encode: (value) => new ObjectId(value)
21
+ });
22
+ const mongoStringCodec = mongoCodec({
23
+ typeId: MONGO_STRING_CODEC_ID,
24
+ targetTypes: ["string"],
25
+ traits: [
26
+ "equality",
27
+ "order",
28
+ "textual"
29
+ ],
30
+ decode: (wire) => wire,
31
+ encode: (value) => value
32
+ });
33
+ const mongoDoubleCodec = mongoCodec({
34
+ typeId: MONGO_DOUBLE_CODEC_ID,
35
+ targetTypes: ["float"],
36
+ traits: [
37
+ "equality",
38
+ "order",
39
+ "numeric"
40
+ ],
41
+ decode: (wire) => wire,
42
+ encode: (value) => value
43
+ });
44
+ const mongoInt32Codec = mongoCodec({
45
+ typeId: MONGO_INT32_CODEC_ID,
46
+ targetTypes: ["int"],
47
+ traits: [
48
+ "equality",
49
+ "order",
50
+ "numeric"
51
+ ],
52
+ decode: (wire) => wire,
53
+ encode: (value) => value
54
+ });
55
+ const mongoBooleanCodec = mongoCodec({
56
+ typeId: MONGO_BOOLEAN_CODEC_ID,
57
+ targetTypes: ["bool"],
58
+ traits: ["equality", "boolean"],
59
+ decode: (wire) => wire,
60
+ encode: (value) => value
61
+ });
62
+ const mongoDateCodec = mongoCodec({
63
+ typeId: MONGO_DATE_CODEC_ID,
64
+ targetTypes: ["date"],
65
+ traits: ["equality", "order"],
66
+ decode: (wire) => wire,
67
+ encode: (value) => value
68
+ });
69
+ const mongoVectorCodec = mongoCodec({
70
+ typeId: MONGO_VECTOR_CODEC_ID,
71
+ targetTypes: ["vector"],
72
+ traits: ["equality"],
73
+ decode: (wire) => wire,
74
+ encode: (value) => value,
75
+ renderOutputType: (typeParams) => {
76
+ const length = typeParams["length"];
77
+ if (length === void 0) return void 0;
78
+ if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length)) throw new Error("renderOutputType: expected positive integer \"length\" for Vector");
79
+ return `Vector<${length}>`;
80
+ }
81
+ });
82
+
83
+ //#endregion
84
+ export { mongoObjectIdCodec as a, MONGO_INT32_CODEC_ID as c, mongoInt32Codec as i, MONGO_VECTOR_CODEC_ID as l, mongoDateCodec as n, mongoStringCodec as o, mongoDoubleCodec as r, mongoVectorCodec as s, mongoBooleanCodec as t };
85
+ //# sourceMappingURL=codecs-9xSaT_DN.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codecs-9xSaT_DN.mjs","names":[],"sources":["../src/core/codec-ids.ts","../src/core/codecs.ts"],"sourcesContent":["export const MONGO_OBJECTID_CODEC_ID = 'mongo/objectId@1' as const;\nexport const MONGO_STRING_CODEC_ID = 'mongo/string@1' as const;\nexport const MONGO_DOUBLE_CODEC_ID = 'mongo/double@1' as const;\nexport const MONGO_INT32_CODEC_ID = 'mongo/int32@1' as const;\nexport const MONGO_BOOLEAN_CODEC_ID = 'mongo/bool@1' as const;\nexport const MONGO_DATE_CODEC_ID = 'mongo/date@1' as const;\nexport const MONGO_VECTOR_CODEC_ID = 'mongo/vector@1' as const;\n","import { mongoCodec } from '@prisma-next/mongo-codec';\nimport { ObjectId } from 'mongodb';\nimport {\n MONGO_BOOLEAN_CODEC_ID,\n MONGO_DATE_CODEC_ID,\n MONGO_DOUBLE_CODEC_ID,\n MONGO_INT32_CODEC_ID,\n MONGO_OBJECTID_CODEC_ID,\n MONGO_STRING_CODEC_ID,\n MONGO_VECTOR_CODEC_ID,\n} from './codec-ids';\n\nexport const mongoObjectIdCodec = mongoCodec({\n typeId: MONGO_OBJECTID_CODEC_ID,\n targetTypes: ['objectId'],\n traits: ['equality'],\n decode: (wire: ObjectId) => wire.toHexString(),\n encode: (value: string) => new ObjectId(value),\n});\n\nexport const mongoStringCodec = mongoCodec({\n typeId: MONGO_STRING_CODEC_ID,\n targetTypes: ['string'],\n traits: ['equality', 'order', 'textual'],\n decode: (wire: string) => wire,\n encode: (value: string) => value,\n});\n\nexport const mongoDoubleCodec = mongoCodec({\n typeId: MONGO_DOUBLE_CODEC_ID,\n targetTypes: ['float'],\n traits: ['equality', 'order', 'numeric'],\n decode: (wire: number) => wire,\n encode: (value: number) => value,\n});\n\nexport const mongoInt32Codec = mongoCodec({\n typeId: MONGO_INT32_CODEC_ID,\n targetTypes: ['int'],\n traits: ['equality', 'order', 'numeric'],\n decode: (wire: number) => wire,\n encode: (value: number) => value,\n});\n\nexport const mongoBooleanCodec = mongoCodec({\n typeId: MONGO_BOOLEAN_CODEC_ID,\n targetTypes: ['bool'],\n traits: ['equality', 'boolean'],\n decode: (wire: boolean) => wire,\n encode: (value: boolean) => value,\n});\n\nexport const mongoDateCodec = mongoCodec({\n typeId: MONGO_DATE_CODEC_ID,\n targetTypes: ['date'],\n traits: ['equality', 'order'],\n decode: (wire: Date) => wire,\n encode: (value: Date) => value,\n});\n\nexport const mongoVectorCodec = mongoCodec({\n typeId: MONGO_VECTOR_CODEC_ID,\n targetTypes: ['vector'],\n traits: ['equality'],\n decode: (wire: readonly number[]) => wire,\n encode: (value: readonly number[]) => value,\n renderOutputType: (typeParams) => {\n const length = typeParams['length'];\n if (length === undefined) return undefined;\n if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {\n throw new Error('renderOutputType: expected positive integer \"length\" for Vector');\n }\n return `Vector<${length}>`;\n },\n});\n"],"mappings":";;;;AAAA,MAAa,0BAA0B;AACvC,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;AACrC,MAAa,uBAAuB;AACpC,MAAa,yBAAyB;AACtC,MAAa,sBAAsB;AACnC,MAAa,wBAAwB;;;;ACMrC,MAAa,qBAAqB,WAAW;CAC3C,QAAQ;CACR,aAAa,CAAC,WAAW;CACzB,QAAQ,CAAC,WAAW;CACpB,SAAS,SAAmB,KAAK,aAAa;CAC9C,SAAS,UAAkB,IAAI,SAAS,MAAM;CAC/C,CAAC;AAEF,MAAa,mBAAmB,WAAW;CACzC,QAAQ;CACR,aAAa,CAAC,SAAS;CACvB,QAAQ;EAAC;EAAY;EAAS;EAAU;CACxC,SAAS,SAAiB;CAC1B,SAAS,UAAkB;CAC5B,CAAC;AAEF,MAAa,mBAAmB,WAAW;CACzC,QAAQ;CACR,aAAa,CAAC,QAAQ;CACtB,QAAQ;EAAC;EAAY;EAAS;EAAU;CACxC,SAAS,SAAiB;CAC1B,SAAS,UAAkB;CAC5B,CAAC;AAEF,MAAa,kBAAkB,WAAW;CACxC,QAAQ;CACR,aAAa,CAAC,MAAM;CACpB,QAAQ;EAAC;EAAY;EAAS;EAAU;CACxC,SAAS,SAAiB;CAC1B,SAAS,UAAkB;CAC5B,CAAC;AAEF,MAAa,oBAAoB,WAAW;CAC1C,QAAQ;CACR,aAAa,CAAC,OAAO;CACrB,QAAQ,CAAC,YAAY,UAAU;CAC/B,SAAS,SAAkB;CAC3B,SAAS,UAAmB;CAC7B,CAAC;AAEF,MAAa,iBAAiB,WAAW;CACvC,QAAQ;CACR,aAAa,CAAC,OAAO;CACrB,QAAQ,CAAC,YAAY,QAAQ;CAC7B,SAAS,SAAe;CACxB,SAAS,UAAgB;CAC1B,CAAC;AAEF,MAAa,mBAAmB,WAAW;CACzC,QAAQ;CACR,aAAa,CAAC,SAAS;CACvB,QAAQ,CAAC,WAAW;CACpB,SAAS,SAA4B;CACrC,SAAS,UAA6B;CACtC,mBAAmB,eAAe;EAChC,MAAM,SAAS,WAAW;AAC1B,MAAI,WAAW,OAAW,QAAO;AACjC,MAAI,OAAO,WAAW,YAAY,CAAC,OAAO,SAAS,OAAO,IAAI,CAAC,OAAO,UAAU,OAAO,CACrF,OAAM,IAAI,MAAM,oEAAkE;AAEpF,SAAO,UAAU,OAAO;;CAE3B,CAAC"}
@@ -1,7 +1,79 @@
1
- import { ControlAdapterDescriptor } from "@prisma-next/framework-components/control";
1
+ import { Db, Document, MongoClient } from "mongodb";
2
+ import { initMarker, readMarker, updateMarker, writeLedgerEntry } from "@prisma-next/target-mongo/control";
3
+ import { CollModCommand, CreateCollectionCommand, CreateIndexCommand, DropCollectionCommand, DropIndexCommand, ListCollectionsCommand, ListIndexesCommand, MongoDdlCommandVisitor, MongoInspectionCommandVisitor, MongoMigrationPlanOperation } from "@prisma-next/mongo-query-ast/control";
4
+ import { MongoSchemaIR } from "@prisma-next/mongo-schema-ir";
5
+ import { ControlAdapterDescriptor, ControlDriverInstance, MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlanner, MigrationPlannerResult, MigrationRunner, MigrationRunnerExecutionChecks, MigrationRunnerResult } from "@prisma-next/framework-components/control";
6
+ import { MongoContract } from "@prisma-next/mongo-contract";
7
+ import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
2
8
 
9
+ //#region src/core/command-executor.d.ts
10
+ declare class MongoCommandExecutor implements MongoDdlCommandVisitor<Promise<void>> {
11
+ private readonly db;
12
+ constructor(db: Db);
13
+ createIndex(cmd: CreateIndexCommand): Promise<void>;
14
+ dropIndex(cmd: DropIndexCommand): Promise<void>;
15
+ createCollection(cmd: CreateCollectionCommand): Promise<void>;
16
+ dropCollection(cmd: DropCollectionCommand): Promise<void>;
17
+ collMod(cmd: CollModCommand): Promise<void>;
18
+ }
19
+ declare class MongoInspectionExecutor implements MongoInspectionCommandVisitor<Promise<Document[]>> {
20
+ private readonly db;
21
+ constructor(db: Db);
22
+ listIndexes(cmd: ListIndexesCommand): Promise<Document[]>;
23
+ listCollections(_cmd: ListCollectionsCommand): Promise<Document[]>;
24
+ }
25
+ //#endregion
26
+ //#region src/core/contract-to-schema.d.ts
27
+ declare function contractToMongoSchemaIR(contract: MongoContract | null): MongoSchemaIR;
28
+ //#endregion
29
+ //#region src/core/ddl-formatter.d.ts
30
+ declare function formatMongoOperations(operations: readonly MigrationPlanOperation[]): string[];
31
+ //#endregion
32
+ //#region src/core/introspect-schema.d.ts
33
+ declare function introspectSchema(db: Db): Promise<MongoSchemaIR>;
34
+ //#endregion
35
+ //#region src/core/mongo-control-driver.d.ts
36
+ interface MongoControlDriverInstance extends ControlDriverInstance<'mongo', 'mongo'> {
37
+ readonly db: Db;
38
+ }
39
+ declare function createMongoControlDriver(db: Db, client: MongoClient): MongoControlDriverInstance;
40
+ //#endregion
41
+ //#region src/core/mongo-ops-serializer.d.ts
42
+ declare function deserializeMongoOps(json: readonly unknown[]): MongoMigrationPlanOperation[];
43
+ declare function serializeMongoOps(ops: readonly MongoMigrationPlanOperation[]): string;
44
+ //#endregion
45
+ //#region src/core/mongo-planner.d.ts
46
+ declare class MongoMigrationPlanner implements MigrationPlanner<'mongo', 'mongo'> {
47
+ plan(options: {
48
+ readonly contract: unknown;
49
+ readonly schema: unknown;
50
+ readonly policy: MigrationOperationPolicy;
51
+ readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'mongo', 'mongo'>>;
52
+ }): MigrationPlannerResult;
53
+ }
54
+ //#endregion
55
+ //#region src/core/mongo-runner.d.ts
56
+ declare class MongoMigrationRunner implements MigrationRunner<'mongo', 'mongo'> {
57
+ execute(options: {
58
+ readonly plan: MigrationPlan;
59
+ readonly driver: ControlDriverInstance<'mongo', 'mongo'>;
60
+ readonly destinationContract: unknown;
61
+ readonly policy: MigrationOperationPolicy;
62
+ readonly callbacks?: {
63
+ onOperationStart?(op: MigrationPlanOperation): void;
64
+ onOperationComplete?(op: MigrationPlanOperation): void;
65
+ };
66
+ readonly executionChecks?: MigrationRunnerExecutionChecks;
67
+ readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'mongo', 'mongo'>>;
68
+ }): Promise<MigrationRunnerResult>;
69
+ private evaluateChecks;
70
+ private allChecksSatisfied;
71
+ private enforcePolicyCompatibility;
72
+ private ensureMarkerCompatibility;
73
+ }
74
+ //#endregion
3
75
  //#region src/exports/control.d.ts
4
76
  declare const mongoAdapterDescriptor: ControlAdapterDescriptor<'mongo', 'mongo'>;
5
77
  //#endregion
6
- export { mongoAdapterDescriptor as default };
78
+ export { MongoCommandExecutor, type MongoControlDriverInstance, MongoInspectionExecutor, MongoMigrationPlanner, MongoMigrationRunner, contractToMongoSchemaIR, createMongoControlDriver, mongoAdapterDescriptor as default, deserializeMongoOps, formatMongoOperations, initMarker, introspectSchema, readMarker, serializeMongoOps, updateMarker, writeLedgerEntry };
7
79
  //# sourceMappingURL=control.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"sourcesContent":[],"mappings":";;;cAWM,wBAAwB"}
1
+ {"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/command-executor.ts","../src/core/contract-to-schema.ts","../src/core/ddl-formatter.ts","../src/core/introspect-schema.ts","../src/core/mongo-control-driver.ts","../src/core/mongo-ops-serializer.ts","../src/core/mongo-planner.ts","../src/core/mongo-runner.ts","../src/exports/control.ts"],"sourcesContent":[],"mappings":";;;;;;;;;cAca,oBAAA,YAAgC,uBAAuB;;kBACjC;mBAEV,qBAAqB;iBAmBvB,mBAAmB;wBAIZ,0BAA0B;sBAgB5B,wBAAwB;EA1CvC,OAAA,CAAA,GAAA,EA8CQ,cA9Ca,CA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