@prisma/orm-target-mongo 0.16.0-dev.36
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/LICENSE +201 -0
- package/README.md +23 -0
- package/dist/adapter.d.mts +19 -0
- package/dist/adapter.d.mts.map +1 -0
- package/dist/adapter.mjs +12 -0
- package/dist/adapter.mjs.map +1 -0
- package/dist/adapter__codec-ids.d.mts +12 -0
- package/dist/adapter__codec-ids.d.mts.map +1 -0
- package/dist/adapter__codec-ids.mjs +2 -0
- package/dist/adapter__codec-types.d.mts +38 -0
- package/dist/adapter__codec-types.d.mts.map +1 -0
- package/dist/adapter__codec-types.mjs +1 -0
- package/dist/adapter__codecs.d.mts +14 -0
- package/dist/adapter__codecs.d.mts.map +1 -0
- package/dist/adapter__codecs.mjs +2 -0
- package/dist/adapter__control.d.mts +3 -0
- package/dist/adapter__control.mjs +3 -0
- package/dist/adapter__runtime.d.mts +16 -0
- package/dist/adapter__runtime.d.mts.map +1 -0
- package/dist/adapter__runtime.mjs +25 -0
- package/dist/adapter__runtime.mjs.map +1 -0
- package/dist/codec-ids-BennPcpQ-Btzz3ILV.mjs +12 -0
- package/dist/codec-ids-BennPcpQ-Btzz3ILV.mjs.map +1 -0
- package/dist/codec-types-Bx2fHyq_.d.mts +35 -0
- package/dist/codec-types-Bx2fHyq_.d.mts.map +1 -0
- package/dist/codecs-DLWO-Cjc-CWfQj0bY.mjs +170 -0
- package/dist/codecs-DLWO-Cjc-CWfQj0bY.mjs.map +1 -0
- package/dist/control-BOc5lrQg.mjs +437 -0
- package/dist/control-BOc5lrQg.mjs.map +1 -0
- package/dist/control-CEXmcht7.mjs +1563 -0
- package/dist/control-CEXmcht7.mjs.map +1 -0
- package/dist/control-CxXmTy_h.d.mts +312 -0
- package/dist/control-CxXmTy_h.d.mts.map +1 -0
- package/dist/control-rPM2HNxW.d.mts +170 -0
- package/dist/control-rPM2HNxW.d.mts.map +1 -0
- package/dist/descriptor-meta-CBiaTwe5-HX742pZh.mjs +17 -0
- package/dist/descriptor-meta-CBiaTwe5-HX742pZh.mjs.map +1 -0
- package/dist/driver.d.mts +2 -0
- package/dist/driver.mjs +2 -0
- package/dist/driver__control.d.mts +16 -0
- package/dist/driver__control.d.mts.map +1 -0
- package/dist/driver__control.mjs +46 -0
- package/dist/driver__control.mjs.map +1 -0
- package/dist/migration-BkqcE2Uv.d.mts +42 -0
- package/dist/migration-BkqcE2Uv.d.mts.map +1 -0
- package/dist/migration-C-jfTsGU.mjs +4 -0
- package/dist/migration-factories-CCJFG_3e-75oJ8xn2.mjs +201 -0
- package/dist/migration-factories-CCJFG_3e-75oJ8xn2.mjs.map +1 -0
- package/dist/mongo-adapter-BkVYI6jn-ChXldtpg.mjs +807 -0
- package/dist/mongo-adapter-BkVYI6jn-ChXldtpg.mjs.map +1 -0
- package/dist/mongo-adapter-CjJU3S9o-BIJruFYW.d.mts +16 -0
- package/dist/mongo-adapter-CjJU3S9o-BIJruFYW.d.mts.map +1 -0
- package/dist/mongo-driver-C7zThOjZ-BcMrlirh.mjs +161 -0
- package/dist/mongo-driver-C7zThOjZ-BcMrlirh.mjs.map +1 -0
- package/dist/mongo-driver-D1lEf5Kl-KPfGUVXK.d.mts +33 -0
- package/dist/mongo-driver-D1lEf5Kl-KPfGUVXK.d.mts.map +1 -0
- package/dist/op-factory-call-B7EKa4Ri-B2Lb6W68.d.mts +76 -0
- package/dist/op-factory-call-B7EKa4Ri-B2Lb6W68.d.mts.map +1 -0
- package/dist/pack-MK8ZQfrL.d.mts +22 -0
- package/dist/pack-MK8ZQfrL.d.mts.map +1 -0
- package/dist/runtime-B9_-kjBX.d.mts +15 -0
- package/dist/runtime-B9_-kjBX.d.mts.map +1 -0
- package/dist/target.d.mts +8 -0
- package/dist/target.mjs +4 -0
- package/dist/target__codec-types.d.mts +2 -0
- package/dist/target__codec-types.mjs +1 -0
- package/dist/target__control.d.mts +4 -0
- package/dist/target__control.mjs +2 -0
- package/dist/target__migration.d.mts +2 -0
- package/dist/target__migration.mjs +3 -0
- package/dist/target__pack.d.mts +2 -0
- package/dist/target__pack.mjs +7 -0
- package/dist/target__pack.mjs.map +1 -0
- package/dist/target__runtime.d.mts +2 -0
- package/dist/target__runtime.mjs +21 -0
- package/dist/target__runtime.mjs.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { a as MONGO_OBJECTID_CODEC_ID, i as MONGO_INT32_CODEC_ID, n as MONGO_DATE_CODEC_ID, o as MONGO_STRING_CODEC_ID, r as MONGO_DOUBLE_CODEC_ID, s as MONGO_VECTOR_CODEC_ID, t as MONGO_BOOLEAN_CODEC_ID } from "./codec-ids-BennPcpQ-Btzz3ILV.mjs";
|
|
2
|
+
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
3
|
+
import { renderTsLiteral, voidParamsSchema } from "@prisma/orm-framework/components/codec";
|
|
4
|
+
import { mongoCodec, newMongoCodecRegistry } from "@prisma/orm-family-mongo/codec";
|
|
5
|
+
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
6
|
+
import { ObjectId } from "bson";
|
|
7
|
+
//#region ../../../3-mongo-target/2-mongo-adapter/dist/codecs-DLWO-Cjc.mjs
|
|
8
|
+
function mongoAdapterError(code, message, options) {
|
|
9
|
+
return structuredError(code, message, options);
|
|
10
|
+
}
|
|
11
|
+
function describeReceivedValue(value) {
|
|
12
|
+
if (value === null) return "null";
|
|
13
|
+
if (typeof value !== "object") return typeof value;
|
|
14
|
+
return `object with keys [${Object.keys(value).join(", ")}]`;
|
|
15
|
+
}
|
|
16
|
+
const mongoObjectIdCodec = mongoCodec({
|
|
17
|
+
typeId: MONGO_OBJECTID_CODEC_ID,
|
|
18
|
+
decode: (wire) => wire.toHexString(),
|
|
19
|
+
encode: (value) => new ObjectId(value)
|
|
20
|
+
});
|
|
21
|
+
const mongoStringCodec = mongoCodec({
|
|
22
|
+
typeId: MONGO_STRING_CODEC_ID,
|
|
23
|
+
decode: (wire) => wire,
|
|
24
|
+
encode: (value) => value
|
|
25
|
+
});
|
|
26
|
+
const mongoDoubleCodec = mongoCodec({
|
|
27
|
+
typeId: MONGO_DOUBLE_CODEC_ID,
|
|
28
|
+
decode: (wire) => wire,
|
|
29
|
+
encode: (value) => value
|
|
30
|
+
});
|
|
31
|
+
const mongoInt32Codec = mongoCodec({
|
|
32
|
+
typeId: MONGO_INT32_CODEC_ID,
|
|
33
|
+
decode: (wire) => wire,
|
|
34
|
+
encode: (value) => value
|
|
35
|
+
});
|
|
36
|
+
const mongoBooleanCodec = mongoCodec({
|
|
37
|
+
typeId: MONGO_BOOLEAN_CODEC_ID,
|
|
38
|
+
decode: (wire) => wire,
|
|
39
|
+
encode: (value) => value
|
|
40
|
+
});
|
|
41
|
+
const mongoDateCodec = mongoCodec({
|
|
42
|
+
typeId: MONGO_DATE_CODEC_ID,
|
|
43
|
+
decode: (wire) => wire,
|
|
44
|
+
encode: (value) => value,
|
|
45
|
+
encodeJson: (value) => value.toISOString(),
|
|
46
|
+
decodeJson: (json) => {
|
|
47
|
+
if (typeof json !== "string") throw mongoAdapterError("RUNTIME.DECODE_FAILED", "expected ISO date string", { meta: {
|
|
48
|
+
codecId: MONGO_DATE_CODEC_ID,
|
|
49
|
+
received: typeof json
|
|
50
|
+
} });
|
|
51
|
+
return new Date(json);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const mongoVectorCodec = mongoCodec({
|
|
55
|
+
typeId: MONGO_VECTOR_CODEC_ID,
|
|
56
|
+
decode: (wire) => wire,
|
|
57
|
+
encode: (value) => value
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* The canonical set of Mongo wire-type codecs.
|
|
61
|
+
*
|
|
62
|
+
* Single source of truth for both control- and runtime-plane adapter descriptors. Don't duplicate this list — import it.
|
|
63
|
+
*/
|
|
64
|
+
const mongoStandardCodecs = [
|
|
65
|
+
mongoObjectIdCodec,
|
|
66
|
+
mongoStringCodec,
|
|
67
|
+
mongoDoubleCodec,
|
|
68
|
+
mongoInt32Codec,
|
|
69
|
+
mongoBooleanCodec,
|
|
70
|
+
mongoDateCodec,
|
|
71
|
+
mongoVectorCodec
|
|
72
|
+
];
|
|
73
|
+
/**
|
|
74
|
+
* Build a {@link CodecDescriptor} for a Mongo wire-type codec.
|
|
75
|
+
*
|
|
76
|
+
* Wraps an existing {@link MongoCodec} instance into a descriptor whose factory hands out the same shared codec. Mongo's full migration to descriptor-first authoring is tracked under TML-2324; for now the descriptor view is composed from the existing `mongoCodec()` outputs.
|
|
77
|
+
*/
|
|
78
|
+
function descriptorFor(codec, metadata) {
|
|
79
|
+
const renderOutputType = metadata.renderOutputType;
|
|
80
|
+
return {
|
|
81
|
+
codecId: codec.id,
|
|
82
|
+
traits: metadata.traits,
|
|
83
|
+
targetTypes: metadata.targetTypes,
|
|
84
|
+
paramsSchema: voidParamsSchema,
|
|
85
|
+
isParameterized: false,
|
|
86
|
+
factory: (() => () => codec),
|
|
87
|
+
...ifDefined("renderOutputType", renderOutputType),
|
|
88
|
+
...ifDefined("renderValueLiteral", metadata.renderValueLiteral)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const renderVectorOutputType = (typeParams) => {
|
|
92
|
+
const length = typeParams["length"];
|
|
93
|
+
if (length === void 0) return void 0;
|
|
94
|
+
if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length) || length <= 0) throw mongoAdapterError("RUNTIME.TYPE_PARAMS_INVALID", "renderOutputType: expected positive integer \"length\" for Vector", { meta: {
|
|
95
|
+
nativeType: "Vector",
|
|
96
|
+
param: "length",
|
|
97
|
+
received: length
|
|
98
|
+
} });
|
|
99
|
+
return `Vector<${length}>`;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Mongo wire-type codec descriptors. Static metadata for `traits`, `targetTypes`, and `renderOutputType` lives here (the descriptor shape) — `MongoCodec` itself is narrow and only carries the four conversion methods (TML-2357).
|
|
103
|
+
*/
|
|
104
|
+
const mongoCodecDescriptors = [
|
|
105
|
+
descriptorFor(mongoObjectIdCodec, {
|
|
106
|
+
traits: ["equality"],
|
|
107
|
+
targetTypes: ["objectId"]
|
|
108
|
+
}),
|
|
109
|
+
descriptorFor(mongoStringCodec, {
|
|
110
|
+
traits: [
|
|
111
|
+
"equality",
|
|
112
|
+
"order",
|
|
113
|
+
"textual"
|
|
114
|
+
],
|
|
115
|
+
targetTypes: ["string"],
|
|
116
|
+
renderValueLiteral: renderTsLiteral
|
|
117
|
+
}),
|
|
118
|
+
descriptorFor(mongoDoubleCodec, {
|
|
119
|
+
traits: [
|
|
120
|
+
"equality",
|
|
121
|
+
"order",
|
|
122
|
+
"numeric"
|
|
123
|
+
],
|
|
124
|
+
targetTypes: ["double"],
|
|
125
|
+
renderValueLiteral: renderTsLiteral
|
|
126
|
+
}),
|
|
127
|
+
descriptorFor(mongoInt32Codec, {
|
|
128
|
+
traits: [
|
|
129
|
+
"equality",
|
|
130
|
+
"order",
|
|
131
|
+
"numeric"
|
|
132
|
+
],
|
|
133
|
+
targetTypes: ["int"],
|
|
134
|
+
renderValueLiteral: renderTsLiteral
|
|
135
|
+
}),
|
|
136
|
+
descriptorFor(mongoBooleanCodec, {
|
|
137
|
+
traits: ["equality", "boolean"],
|
|
138
|
+
targetTypes: ["bool"],
|
|
139
|
+
renderValueLiteral: renderTsLiteral
|
|
140
|
+
}),
|
|
141
|
+
descriptorFor(mongoDateCodec, {
|
|
142
|
+
traits: ["equality", "order"],
|
|
143
|
+
targetTypes: ["date"]
|
|
144
|
+
}),
|
|
145
|
+
descriptorFor(mongoVectorCodec, {
|
|
146
|
+
traits: ["equality"],
|
|
147
|
+
targetTypes: ["vector"],
|
|
148
|
+
renderOutputType: renderVectorOutputType
|
|
149
|
+
})
|
|
150
|
+
];
|
|
151
|
+
/**
|
|
152
|
+
* Lookup descriptor metadata by codec id — used by tests and for descriptor-side reads of static metadata.
|
|
153
|
+
*/
|
|
154
|
+
function mongoDescriptorById(codecId) {
|
|
155
|
+
return mongoCodecDescriptors.find((d) => d.codecId === codecId);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Build a {@link MongoCodecRegistry} preloaded with the standard Mongo wire-type codecs.
|
|
159
|
+
*
|
|
160
|
+
* Single point of truth for adapter-side codec construction: used by the legacy synchronous `createMongoAdapter()` factory and by the runtime adapter descriptor's `codecs()` getter. Userland code obtains a registry via the framework's execution-stack composition (see `createMongoExecutionContext`) instead of calling this directly.
|
|
161
|
+
*/
|
|
162
|
+
function buildStandardCodecRegistry() {
|
|
163
|
+
const registry = newMongoCodecRegistry();
|
|
164
|
+
for (const codec of mongoStandardCodecs) registry.register(codec);
|
|
165
|
+
return registry;
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
export { mongoDescriptorById as a, mongoCodecDescriptors as i, describeReceivedValue as n, mongoAdapterError as r, buildStandardCodecRegistry as t };
|
|
169
|
+
|
|
170
|
+
//# sourceMappingURL=codecs-DLWO-Cjc-CWfQj0bY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codecs-DLWO-Cjc-CWfQj0bY.mjs","names":[],"sources":["../../../../3-mongo-target/2-mongo-adapter/dist/codecs-DLWO-Cjc.mjs"],"sourcesContent":["import { a as MONGO_OBJECTID_CODEC_ID, i as MONGO_INT32_CODEC_ID, n as MONGO_DATE_CODEC_ID, o as MONGO_STRING_CODEC_ID, r as MONGO_DOUBLE_CODEC_ID, s as MONGO_VECTOR_CODEC_ID, t as MONGO_BOOLEAN_CODEC_ID } from \"./codec-ids-BennPcpQ.mjs\";\nimport { structuredError } from \"@internal/utils/structured-error\";\nimport { renderTsLiteral, voidParamsSchema } from \"@internal/framework-components/codec\";\nimport { mongoCodec, newMongoCodecRegistry } from \"@internal/mongo-codec\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { ObjectId } from \"bson\";\n//#region src/core/errors.ts\nfunction mongoAdapterError(code, message, options) {\n\treturn structuredError(code, message, options);\n}\nfunction describeReceivedValue(value) {\n\tif (value === null) return \"null\";\n\tif (typeof value !== \"object\") return typeof value;\n\treturn `object with keys [${Object.keys(value).join(\", \")}]`;\n}\n//#endregion\n//#region src/core/codecs.ts\nconst mongoObjectIdCodec = mongoCodec({\n\ttypeId: MONGO_OBJECTID_CODEC_ID,\n\tdecode: (wire) => wire.toHexString(),\n\tencode: (value) => new ObjectId(value)\n});\nconst mongoStringCodec = mongoCodec({\n\ttypeId: MONGO_STRING_CODEC_ID,\n\tdecode: (wire) => wire,\n\tencode: (value) => value\n});\nconst mongoDoubleCodec = mongoCodec({\n\ttypeId: MONGO_DOUBLE_CODEC_ID,\n\tdecode: (wire) => wire,\n\tencode: (value) => value\n});\nconst mongoInt32Codec = mongoCodec({\n\ttypeId: MONGO_INT32_CODEC_ID,\n\tdecode: (wire) => wire,\n\tencode: (value) => value\n});\nconst mongoBooleanCodec = mongoCodec({\n\ttypeId: MONGO_BOOLEAN_CODEC_ID,\n\tdecode: (wire) => wire,\n\tencode: (value) => value\n});\nconst mongoDateCodec = mongoCodec({\n\ttypeId: MONGO_DATE_CODEC_ID,\n\tdecode: (wire) => wire,\n\tencode: (value) => value,\n\tencodeJson: (value) => value.toISOString(),\n\tdecodeJson: (json) => {\n\t\tif (typeof json !== \"string\") throw mongoAdapterError(\"RUNTIME.DECODE_FAILED\", \"expected ISO date string\", { meta: {\n\t\t\tcodecId: MONGO_DATE_CODEC_ID,\n\t\t\treceived: typeof json\n\t\t} });\n\t\treturn new Date(json);\n\t}\n});\nconst mongoVectorCodec = mongoCodec({\n\ttypeId: MONGO_VECTOR_CODEC_ID,\n\tdecode: (wire) => wire,\n\tencode: (value) => value\n});\n/**\n* The canonical set of Mongo wire-type codecs.\n*\n* Single source of truth for both control- and runtime-plane adapter descriptors. Don't duplicate this list — import it.\n*/\nconst mongoStandardCodecs = [\n\tmongoObjectIdCodec,\n\tmongoStringCodec,\n\tmongoDoubleCodec,\n\tmongoInt32Codec,\n\tmongoBooleanCodec,\n\tmongoDateCodec,\n\tmongoVectorCodec\n];\n/**\n* Build a {@link CodecDescriptor} for a Mongo wire-type codec.\n*\n* Wraps an existing {@link MongoCodec} instance into a descriptor whose factory hands out the same shared codec. Mongo's full migration to descriptor-first authoring is tracked under TML-2324; for now the descriptor view is composed from the existing `mongoCodec()` outputs.\n*/\nfunction descriptorFor(codec, metadata) {\n\tconst renderOutputType = metadata.renderOutputType;\n\treturn {\n\t\tcodecId: codec.id,\n\t\ttraits: metadata.traits,\n\t\ttargetTypes: metadata.targetTypes,\n\t\tparamsSchema: voidParamsSchema,\n\t\tisParameterized: false,\n\t\tfactory: (() => () => codec),\n\t\t...ifDefined(\"renderOutputType\", renderOutputType),\n\t\t...ifDefined(\"renderValueLiteral\", metadata.renderValueLiteral)\n\t};\n}\nconst renderVectorOutputType = (typeParams) => {\n\tconst length = typeParams[\"length\"];\n\tif (length === void 0) return void 0;\n\tif (typeof length !== \"number\" || !Number.isFinite(length) || !Number.isInteger(length) || length <= 0) throw mongoAdapterError(\"RUNTIME.TYPE_PARAMS_INVALID\", \"renderOutputType: expected positive integer \\\"length\\\" for Vector\", { meta: {\n\t\tnativeType: \"Vector\",\n\t\tparam: \"length\",\n\t\treceived: length\n\t} });\n\treturn `Vector<${length}>`;\n};\n/**\n* Mongo wire-type codec descriptors. Static metadata for `traits`, `targetTypes`, and `renderOutputType` lives here (the descriptor shape) — `MongoCodec` itself is narrow and only carries the four conversion methods (TML-2357).\n*/\nconst mongoCodecDescriptors = [\n\tdescriptorFor(mongoObjectIdCodec, {\n\t\ttraits: [\"equality\"],\n\t\ttargetTypes: [\"objectId\"]\n\t}),\n\tdescriptorFor(mongoStringCodec, {\n\t\ttraits: [\n\t\t\t\"equality\",\n\t\t\t\"order\",\n\t\t\t\"textual\"\n\t\t],\n\t\ttargetTypes: [\"string\"],\n\t\trenderValueLiteral: renderTsLiteral\n\t}),\n\tdescriptorFor(mongoDoubleCodec, {\n\t\ttraits: [\n\t\t\t\"equality\",\n\t\t\t\"order\",\n\t\t\t\"numeric\"\n\t\t],\n\t\ttargetTypes: [\"double\"],\n\t\trenderValueLiteral: renderTsLiteral\n\t}),\n\tdescriptorFor(mongoInt32Codec, {\n\t\ttraits: [\n\t\t\t\"equality\",\n\t\t\t\"order\",\n\t\t\t\"numeric\"\n\t\t],\n\t\ttargetTypes: [\"int\"],\n\t\trenderValueLiteral: renderTsLiteral\n\t}),\n\tdescriptorFor(mongoBooleanCodec, {\n\t\ttraits: [\"equality\", \"boolean\"],\n\t\ttargetTypes: [\"bool\"],\n\t\trenderValueLiteral: renderTsLiteral\n\t}),\n\tdescriptorFor(mongoDateCodec, {\n\t\ttraits: [\"equality\", \"order\"],\n\t\ttargetTypes: [\"date\"]\n\t}),\n\tdescriptorFor(mongoVectorCodec, {\n\t\ttraits: [\"equality\"],\n\t\ttargetTypes: [\"vector\"],\n\t\trenderOutputType: renderVectorOutputType\n\t})\n];\n/**\n* Lookup descriptor metadata by codec id — used by tests and for descriptor-side reads of static metadata.\n*/\nfunction mongoDescriptorById(codecId) {\n\treturn mongoCodecDescriptors.find((d) => d.codecId === codecId);\n}\n/**\n* Build a {@link MongoCodecRegistry} preloaded with the standard Mongo wire-type codecs.\n*\n* Single point of truth for adapter-side codec construction: used by the legacy synchronous `createMongoAdapter()` factory and by the runtime adapter descriptor's `codecs()` getter. Userland code obtains a registry via the framework's execution-stack composition (see `createMongoExecutionContext`) instead of calling this directly.\n*/\nfunction buildStandardCodecRegistry() {\n\tconst registry = newMongoCodecRegistry();\n\tfor (const codec of mongoStandardCodecs) registry.register(codec);\n\treturn registry;\n}\n//#endregion\nexport { mongoAdapterError as a, describeReceivedValue as i, mongoCodecDescriptors as n, mongoDescriptorById as r, buildStandardCodecRegistry as t };\n\n//# sourceMappingURL=codecs-DLWO-Cjc.mjs.map"],"mappings":"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"}
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import { n as describeReceivedValue, r as mongoAdapterError } from "./codecs-DLWO-Cjc-CWfQj0bY.mjs";
|
|
2
|
+
import { t as createMongoAdapter } from "./mongo-adapter-BkVYI6jn-ChXldtpg.mjs";
|
|
3
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
4
|
+
import { expr, fn } from "@prisma/orm-family-mongo/query-builder";
|
|
5
|
+
import { collection } from "@prisma/orm-family-mongo/query-builder/contract-free";
|
|
6
|
+
import { MongoAggFieldRef, MongoAggLiteral, MongoAggOperator } from "@prisma/orm-family-mongo/query-ast/execution";
|
|
7
|
+
import { MongoServerError } from "mongodb";
|
|
8
|
+
import { MongoSchemaCollection, MongoSchemaCollectionOptions, MongoSchemaIR, MongoSchemaIndex, MongoSchemaValidator } from "@prisma/orm-family-mongo/schema-ir";
|
|
9
|
+
import { parseMarkerRowSafely, withMarkerReadErrorHandling } from "@prisma/orm-framework/errors/execution";
|
|
10
|
+
import { ledgerOriginFromStored } from "@prisma/orm-toolchain/migration-tools/ledger-origin";
|
|
11
|
+
import { type } from "arktype";
|
|
12
|
+
//#region ../../../3-mongo-target/2-mongo-adapter/dist/control.mjs
|
|
13
|
+
/**
|
|
14
|
+
* Executes the read-only catalog inspections (`listCollections` / `listIndexes`)
|
|
15
|
+
* that migration prechecks/postchecks and operation preview evaluate, directly
|
|
16
|
+
* against `db`. Routing these checks through the adapter's lowering seam is
|
|
17
|
+
* deferred to the `typed-migration-verification-queries` slice.
|
|
18
|
+
*/
|
|
19
|
+
var MongoInspectionExecutor = class {
|
|
20
|
+
db;
|
|
21
|
+
constructor(db) {
|
|
22
|
+
this.db = db;
|
|
23
|
+
}
|
|
24
|
+
async listIndexes(cmd) {
|
|
25
|
+
try {
|
|
26
|
+
return await this.db.collection(cmd.collection).listIndexes().toArray();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (error instanceof MongoServerError && error.code === 26) return [];
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async listCollections(_cmd) {
|
|
33
|
+
return this.db.listCollections().toArray();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const PRISMA_MIGRATIONS_COLLECTION = "_prisma_migrations";
|
|
37
|
+
function parseIndexKeys(keySpec) {
|
|
38
|
+
const keys = [];
|
|
39
|
+
for (const [field, direction] of Object.entries(keySpec)) keys.push({
|
|
40
|
+
field,
|
|
41
|
+
direction
|
|
42
|
+
});
|
|
43
|
+
return keys;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Exported for unit tests to exercise the defensive `!key` guard; not part of
|
|
47
|
+
* the public API. Callers in this package use it via the `introspectSchema`
|
|
48
|
+
* pipeline only.
|
|
49
|
+
*/
|
|
50
|
+
function isDefaultIdIndex(doc) {
|
|
51
|
+
const key = doc["key"];
|
|
52
|
+
if (!key) return false;
|
|
53
|
+
const entries = Object.entries(key);
|
|
54
|
+
return entries.length === 1 && entries[0]?.[0] === "_id" && entries[0]?.[1] === 1;
|
|
55
|
+
}
|
|
56
|
+
function parseIndex(doc) {
|
|
57
|
+
const keySpec = doc["key"];
|
|
58
|
+
return new MongoSchemaIndex({
|
|
59
|
+
keys: parseIndexKeys(keySpec),
|
|
60
|
+
unique: doc["unique"],
|
|
61
|
+
sparse: doc["sparse"],
|
|
62
|
+
expireAfterSeconds: doc["expireAfterSeconds"],
|
|
63
|
+
partialFilterExpression: doc["partialFilterExpression"],
|
|
64
|
+
wildcardProjection: doc["wildcardProjection"],
|
|
65
|
+
collation: doc["collation"] ? blindCast(doc["collation"]) : void 0,
|
|
66
|
+
weights: doc["weights"],
|
|
67
|
+
default_language: doc["default_language"],
|
|
68
|
+
language_override: doc["language_override"]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function parseValidator(options) {
|
|
72
|
+
const validator = options["validator"];
|
|
73
|
+
if (!validator) return void 0;
|
|
74
|
+
const jsonSchema = validator["$jsonSchema"];
|
|
75
|
+
if (!jsonSchema) return void 0;
|
|
76
|
+
return new MongoSchemaValidator({
|
|
77
|
+
jsonSchema,
|
|
78
|
+
validationLevel: options["validationLevel"] ?? "strict",
|
|
79
|
+
validationAction: options["validationAction"] ?? "error"
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function parseCollectionOptions(info) {
|
|
83
|
+
const options = info["options"];
|
|
84
|
+
if (!options) return void 0;
|
|
85
|
+
const capped = options["capped"];
|
|
86
|
+
const size = options["size"];
|
|
87
|
+
const max = options["max"];
|
|
88
|
+
const timeseries = options["timeseries"];
|
|
89
|
+
const collation = options["collation"] ? blindCast(options["collation"]) : void 0;
|
|
90
|
+
const changeStreamPreAndPostImages = options["changeStreamPreAndPostImages"];
|
|
91
|
+
const clusteredIndex = options["clusteredIndex"];
|
|
92
|
+
if (!(capped || timeseries || collation || changeStreamPreAndPostImages || clusteredIndex)) return void 0;
|
|
93
|
+
return new MongoSchemaCollectionOptions({
|
|
94
|
+
...capped ? { capped: {
|
|
95
|
+
size: size ?? 0,
|
|
96
|
+
...max != null ? { max } : {}
|
|
97
|
+
} } : {},
|
|
98
|
+
...timeseries ? { timeseries } : {},
|
|
99
|
+
...collation ? { collation } : {},
|
|
100
|
+
...changeStreamPreAndPostImages ? { changeStreamPreAndPostImages } : {},
|
|
101
|
+
...clusteredIndex ? { clusteredIndex } : {}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async function introspectSchema(db) {
|
|
105
|
+
const collectionInfos = await db.listCollections().toArray();
|
|
106
|
+
const collections = [];
|
|
107
|
+
for (const info of collectionInfos) {
|
|
108
|
+
const name = info["name"];
|
|
109
|
+
const type = info["type"];
|
|
110
|
+
if (name === PRISMA_MIGRATIONS_COLLECTION) continue;
|
|
111
|
+
if (name.startsWith("system.")) continue;
|
|
112
|
+
if (type === "view") continue;
|
|
113
|
+
const indexes = (await db.collection(name).listIndexes().toArray()).filter((doc) => !isDefaultIdIndex(doc)).map(parseIndex);
|
|
114
|
+
const validator = parseValidator("options" in info ? info["options"] : {});
|
|
115
|
+
const options = parseCollectionOptions(info);
|
|
116
|
+
collections.push(new MongoSchemaCollection({
|
|
117
|
+
name,
|
|
118
|
+
indexes,
|
|
119
|
+
...validator ? { validator } : {},
|
|
120
|
+
...options ? { options } : {}
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
return new MongoSchemaIR(collections);
|
|
124
|
+
}
|
|
125
|
+
const COLLECTION = "_prisma_migrations";
|
|
126
|
+
const MONGO_MARKER_COLLECTION = `_prisma_migrations marker documents in ${COLLECTION}`;
|
|
127
|
+
const MONGO_LEDGER_COLLECTION = `_prisma_migrations ledger documents in ${COLLECTION}`;
|
|
128
|
+
const MongoMarkerDocSchema = type({
|
|
129
|
+
space: "string",
|
|
130
|
+
storageHash: "string",
|
|
131
|
+
profileHash: "string",
|
|
132
|
+
"contractJson?": "unknown | null",
|
|
133
|
+
"canonicalVersion?": "number | null",
|
|
134
|
+
"updatedAt?": "Date",
|
|
135
|
+
"appTag?": "string | null",
|
|
136
|
+
"meta?": type({ "[string]": "unknown" }).or("null"),
|
|
137
|
+
"invariants?": type("string").array(),
|
|
138
|
+
"+": "delete"
|
|
139
|
+
});
|
|
140
|
+
function parseMongoMarkerDoc(doc) {
|
|
141
|
+
const result = MongoMarkerDocSchema(doc);
|
|
142
|
+
if (result instanceof type.errors) throw mongoAdapterError("CONTRACT.MARKER_ROW_CORRUPT", `Invalid marker doc on ${COLLECTION}: ${result.summary}`, { meta: {
|
|
143
|
+
collection: COLLECTION,
|
|
144
|
+
detail: result.summary
|
|
145
|
+
} });
|
|
146
|
+
return {
|
|
147
|
+
storageHash: result.storageHash,
|
|
148
|
+
profileHash: result.profileHash,
|
|
149
|
+
contractJson: result.contractJson ?? null,
|
|
150
|
+
canonicalVersion: result.canonicalVersion ?? null,
|
|
151
|
+
updatedAt: result.updatedAt ?? /* @__PURE__ */ new Date(),
|
|
152
|
+
appTag: result.appTag ?? null,
|
|
153
|
+
meta: result.meta ?? {},
|
|
154
|
+
invariants: result.invariants ?? []
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function parseMongoMarkerDocSafely(doc, space) {
|
|
158
|
+
return parseMarkerRowSafely(doc, parseMongoMarkerDoc, {
|
|
159
|
+
space,
|
|
160
|
+
markerLocation: MONGO_MARKER_COLLECTION
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
const MARKER_LEDGER_COLLECTION = "_prisma_migrations";
|
|
164
|
+
function isMongoControlDriver(driver) {
|
|
165
|
+
return driver.familyId === "mongo" && driver.targetId === "mongo" && "execute" in driver && typeof driver.execute === "function";
|
|
166
|
+
}
|
|
167
|
+
function extractDb(driver) {
|
|
168
|
+
if (!isMongoControlDriver(driver)) throw mongoAdapterError("CONFIG.VALIDATION_FAILED", "Expected a Mongo control driver created by mongoControlDriver.create() from `@internal/driver-mongo/control`.", { meta: { received: describeReceivedValue(driver) } });
|
|
169
|
+
return driver.db;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Build the runner-dependencies envelope. `controlAdapter` is the
|
|
173
|
+
* dispatch surface for wire-level Mongo CAS operations (marker reads,
|
|
174
|
+
* marker advances, ledger appends, introspection); the envelope's
|
|
175
|
+
* `markerOps` shim simply forwards each call through it. When the
|
|
176
|
+
* caller already has a `MongoControlAdapter` on the control stack it
|
|
177
|
+
* can pass it in; otherwise a default `MongoControlAdapterImpl` is
|
|
178
|
+
* constructed locally.
|
|
179
|
+
*/
|
|
180
|
+
function createMongoRunnerDeps(controlDriver, driver, _family, controlAdapter = new MongoControlAdapterImpl()) {
|
|
181
|
+
const adapter = createMongoAdapter();
|
|
182
|
+
return {
|
|
183
|
+
inspectionExecutor: new MongoInspectionExecutor(extractDb(controlDriver)),
|
|
184
|
+
adapter,
|
|
185
|
+
driver,
|
|
186
|
+
executeDdl: (command) => adapter.lower({ command }, {}).then((wire) => driver.run(wire)),
|
|
187
|
+
markerOps: {
|
|
188
|
+
readMarker: (space) => controlAdapter.readMarker(controlDriver, space),
|
|
189
|
+
initMarker: (space, dest) => controlAdapter.initMarker(controlDriver, space, dest),
|
|
190
|
+
updateMarker: (space, expectedFrom, dest) => controlAdapter.updateMarker(controlDriver, space, expectedFrom, dest),
|
|
191
|
+
writeLedgerEntry: (space, entry) => controlAdapter.writeLedgerEntry(controlDriver, space, entry)
|
|
192
|
+
},
|
|
193
|
+
introspectSchema: () => controlAdapter.introspectSchema(controlDriver)
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Mongo control adapter for control-plane operations like introspection
|
|
198
|
+
* and marker-ledger CAS. Implements the family-level `MongoControlAdapter`
|
|
199
|
+
* SPI. Every marker/ledger operation builds a canonical command inline via
|
|
200
|
+
* the contract-free fluent builder and dispatches it through the family
|
|
201
|
+
* adapter's lowering path (`createMongoAdapter().lower(plan, {})`) onto the
|
|
202
|
+
* Mongo wire transport (`driver.execute(wireCommand)`) — the same route SQL
|
|
203
|
+
* marker/ledger ops take through `adapter.lower()` → `driver.query()`.
|
|
204
|
+
*/
|
|
205
|
+
var MongoControlAdapterImpl = class {
|
|
206
|
+
familyId = "mongo";
|
|
207
|
+
targetId = "mongo";
|
|
208
|
+
#adapter = createMongoAdapter();
|
|
209
|
+
#markerLedgerCollection = collection(MARKER_LEDGER_COLLECTION);
|
|
210
|
+
async #execute(driver, command) {
|
|
211
|
+
const plan = {
|
|
212
|
+
collection: MARKER_LEDGER_COLLECTION,
|
|
213
|
+
command,
|
|
214
|
+
meta: {
|
|
215
|
+
target: "mongo",
|
|
216
|
+
targetFamily: "mongo",
|
|
217
|
+
storageHash: "",
|
|
218
|
+
lane: "control"
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const wireCommand = await this.#adapter.lower(plan, {});
|
|
222
|
+
if (!isMongoControlDriver(driver)) throw mongoAdapterError("CONFIG.VALIDATION_FAILED", "Mongo control adapter requires a Mongo control driver with an execute() transport. Provide a MongoControlDriver from `@internal/driver-mongo/control`.", { meta: { received: describeReceivedValue(driver) } });
|
|
223
|
+
const rows = [];
|
|
224
|
+
for await (const row of driver.execute(wireCommand)) rows.push(row);
|
|
225
|
+
return rows;
|
|
226
|
+
}
|
|
227
|
+
async executeDdl(driver, command) {
|
|
228
|
+
const wire = await this.#adapter.lower({ command }, {});
|
|
229
|
+
await driver.run(wire);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Server-side invariant-merge aggregation expression:
|
|
233
|
+
* `$sortArray({ input: $setUnion([$ifNull('$invariants', []), incoming]), sortBy: 1 })`.
|
|
234
|
+
*
|
|
235
|
+
* Built through the typed agg-expr layer — `fn.setUnion` plus the generic
|
|
236
|
+
* `MongoAggOperator` for `$ifNull` / `$sortArray` (neither has a named `fn`
|
|
237
|
+
* helper). Returns a `MongoAggOperator` that is passed directly to
|
|
238
|
+
* `f.stage.set({ invariants: ... })` in the update pipeline.
|
|
239
|
+
*/
|
|
240
|
+
#invariantMergeExpr(incoming) {
|
|
241
|
+
const existingOrEmpty = MongoAggOperator.of("$ifNull", [MongoAggFieldRef.of("invariants"), MongoAggLiteral.of([])]);
|
|
242
|
+
const merged = fn.setUnion({
|
|
243
|
+
_field: {
|
|
244
|
+
codecId: "mongo/array@1",
|
|
245
|
+
nullable: false
|
|
246
|
+
},
|
|
247
|
+
node: existingOrEmpty
|
|
248
|
+
}, {
|
|
249
|
+
_field: {
|
|
250
|
+
codecId: "mongo/array@1",
|
|
251
|
+
nullable: false
|
|
252
|
+
},
|
|
253
|
+
node: MongoAggLiteral.of([...incoming])
|
|
254
|
+
});
|
|
255
|
+
return MongoAggOperator.of("$sortArray", {
|
|
256
|
+
input: merged.node,
|
|
257
|
+
sortBy: MongoAggLiteral.of(1)
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
async readMarker(driver, space) {
|
|
261
|
+
const doc = (await withMarkerReadErrorHandling(() => this.#execute(driver, this.#markerLedgerCollection.aggregate().match((f) => f._id.eq(space)).match((f) => f.space.eq(space)).limit(1).build()), {
|
|
262
|
+
space,
|
|
263
|
+
markerLocation: MONGO_MARKER_COLLECTION
|
|
264
|
+
}))[0];
|
|
265
|
+
if (!doc) return null;
|
|
266
|
+
return parseMongoMarkerDocSafely(doc, space);
|
|
267
|
+
}
|
|
268
|
+
async readAllMarkers(driver) {
|
|
269
|
+
const docs = await withMarkerReadErrorHandling(() => this.#execute(driver, this.#markerLedgerCollection.aggregate().match((f) => f._id.type("string")).match((f) => f.space.type("string")).match((f) => expr(fn.eq(f._id, f.space))).build()), {
|
|
270
|
+
space: "app",
|
|
271
|
+
markerLocation: MONGO_MARKER_COLLECTION
|
|
272
|
+
});
|
|
273
|
+
const out = /* @__PURE__ */ new Map();
|
|
274
|
+
for (const doc of docs) {
|
|
275
|
+
const space = doc["space"];
|
|
276
|
+
/* v8 ignore next -- @preserve type-narrowing guard: the $match stage above filters on `space: { $type: 'string' }`, so this branch is unreachable at runtime. The check exists so the `out.set(space, ...)` call below can accept `string`. */
|
|
277
|
+
if (typeof space !== "string") continue;
|
|
278
|
+
out.set(space, parseMongoMarkerDocSafely(doc, space));
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
async initMarker(driver, space, destination) {
|
|
283
|
+
const document = {
|
|
284
|
+
_id: space,
|
|
285
|
+
space,
|
|
286
|
+
storageHash: destination.storageHash,
|
|
287
|
+
profileHash: destination.profileHash,
|
|
288
|
+
contractJson: null,
|
|
289
|
+
canonicalVersion: null,
|
|
290
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
291
|
+
appTag: null,
|
|
292
|
+
meta: {},
|
|
293
|
+
invariants: [...destination.invariants ?? []]
|
|
294
|
+
};
|
|
295
|
+
await this.#execute(driver, this.#markerLedgerCollection.insertOne(document));
|
|
296
|
+
}
|
|
297
|
+
async updateMarker(driver, space, expectedFrom, destination) {
|
|
298
|
+
const { invariants } = destination;
|
|
299
|
+
return (await this.#execute(driver, this.#markerLedgerCollection.match((f) => f._id.eq(space)).match((f) => f.space.eq(space)).match((f) => f.storageHash.eq(expectedFrom)).findOneAndUpdate((f) => [f.stage.set(invariants === void 0 ? {
|
|
300
|
+
storageHash: MongoAggLiteral.of(destination.storageHash),
|
|
301
|
+
profileHash: MongoAggLiteral.of(destination.profileHash),
|
|
302
|
+
updatedAt: MongoAggLiteral.of(/* @__PURE__ */ new Date())
|
|
303
|
+
} : {
|
|
304
|
+
storageHash: MongoAggLiteral.of(destination.storageHash),
|
|
305
|
+
profileHash: MongoAggLiteral.of(destination.profileHash),
|
|
306
|
+
updatedAt: MongoAggLiteral.of(/* @__PURE__ */ new Date()),
|
|
307
|
+
invariants: this.#invariantMergeExpr(invariants)
|
|
308
|
+
})], { upsert: false }))).length > 0;
|
|
309
|
+
}
|
|
310
|
+
async writeLedgerEntry(driver, space, entry) {
|
|
311
|
+
const document = {
|
|
312
|
+
type: "ledger",
|
|
313
|
+
space,
|
|
314
|
+
edgeId: entry.edgeId,
|
|
315
|
+
from: entry.from,
|
|
316
|
+
to: entry.to,
|
|
317
|
+
migrationName: entry.migrationName,
|
|
318
|
+
migrationHash: entry.migrationHash,
|
|
319
|
+
operations: blindCast(entry.operations),
|
|
320
|
+
appliedAt: /* @__PURE__ */ new Date()
|
|
321
|
+
};
|
|
322
|
+
await this.#execute(driver, this.#markerLedgerCollection.insertOne(document));
|
|
323
|
+
}
|
|
324
|
+
async readLedger(driver, space) {
|
|
325
|
+
const ledgerContext = {
|
|
326
|
+
space: space ?? "*",
|
|
327
|
+
markerLocation: MONGO_LEDGER_COLLECTION
|
|
328
|
+
};
|
|
329
|
+
const chain = this.#markerLedgerCollection.aggregate().match((f) => f.type.eq("ledger"));
|
|
330
|
+
const command = space === void 0 ? chain.sort({ _id: 1 }).build() : chain.match((f) => f.space.eq(space)).sort({ _id: 1 }).build();
|
|
331
|
+
const docs = await withMarkerReadErrorHandling(() => this.#execute(driver, command), ledgerContext);
|
|
332
|
+
const entries = [];
|
|
333
|
+
for (const doc of docs) {
|
|
334
|
+
const migrationName = doc["migrationName"];
|
|
335
|
+
const migrationHash = doc["migrationHash"];
|
|
336
|
+
const from = doc["from"];
|
|
337
|
+
const to = doc["to"];
|
|
338
|
+
const docSpace = doc["space"];
|
|
339
|
+
if (typeof migrationName !== "string" || typeof migrationHash !== "string") continue;
|
|
340
|
+
if (typeof from !== "string" || typeof to !== "string") continue;
|
|
341
|
+
if (typeof docSpace !== "string") continue;
|
|
342
|
+
const appliedAt = doc["appliedAt"];
|
|
343
|
+
const appliedAtDate = appliedAt instanceof Date ? appliedAt : appliedAt !== void 0 ? new Date(String(appliedAt)) : /* @__PURE__ */ new Date();
|
|
344
|
+
const operations = doc["operations"];
|
|
345
|
+
const opList = Array.isArray(operations) ? operations : [];
|
|
346
|
+
entries.push({
|
|
347
|
+
space: docSpace,
|
|
348
|
+
migrationName,
|
|
349
|
+
migrationHash,
|
|
350
|
+
from: ledgerOriginFromStored(from),
|
|
351
|
+
to,
|
|
352
|
+
appliedAt: appliedAtDate,
|
|
353
|
+
operationCount: opList.length
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
return entries;
|
|
357
|
+
}
|
|
358
|
+
async introspectSchema(driver) {
|
|
359
|
+
return introspectSchema(extractDb(driver));
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* The base PSL scalars as zero-arg type constructors in the unified authoring
|
|
364
|
+
* channel, with explicit `nativeType` values pinned to the codec manifests
|
|
365
|
+
* (`codecLookup.targetTypesFor(codecId)[0]`).
|
|
366
|
+
*/
|
|
367
|
+
const mongoScalarAuthoringTypes = {
|
|
368
|
+
String: {
|
|
369
|
+
kind: "typeConstructor",
|
|
370
|
+
output: {
|
|
371
|
+
codecId: "mongo/string@1",
|
|
372
|
+
nativeType: "string"
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
Int: {
|
|
376
|
+
kind: "typeConstructor",
|
|
377
|
+
output: {
|
|
378
|
+
codecId: "mongo/int32@1",
|
|
379
|
+
nativeType: "int"
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
Boolean: {
|
|
383
|
+
kind: "typeConstructor",
|
|
384
|
+
output: {
|
|
385
|
+
codecId: "mongo/bool@1",
|
|
386
|
+
nativeType: "bool"
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
DateTime: {
|
|
390
|
+
kind: "typeConstructor",
|
|
391
|
+
output: {
|
|
392
|
+
codecId: "mongo/date@1",
|
|
393
|
+
nativeType: "date"
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
ObjectId: {
|
|
397
|
+
kind: "typeConstructor",
|
|
398
|
+
output: {
|
|
399
|
+
codecId: "mongo/objectId@1",
|
|
400
|
+
nativeType: "objectId"
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
Float: {
|
|
404
|
+
kind: "typeConstructor",
|
|
405
|
+
output: {
|
|
406
|
+
codecId: "mongo/double@1",
|
|
407
|
+
nativeType: "double"
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
const mongoAdapterDescriptor = {
|
|
412
|
+
kind: "adapter",
|
|
413
|
+
id: "mongo",
|
|
414
|
+
familyId: "mongo",
|
|
415
|
+
targetId: "mongo",
|
|
416
|
+
version: "0.0.1",
|
|
417
|
+
authoring: { type: mongoScalarAuthoringTypes },
|
|
418
|
+
types: { codecTypes: {
|
|
419
|
+
import: {
|
|
420
|
+
package: "@internal/adapter-mongo/codec-types",
|
|
421
|
+
named: "CodecTypes",
|
|
422
|
+
alias: "MongoCodecTypes"
|
|
423
|
+
},
|
|
424
|
+
typeImports: [{
|
|
425
|
+
package: "@internal/adapter-mongo/codec-types",
|
|
426
|
+
named: "Vector",
|
|
427
|
+
alias: "Vector"
|
|
428
|
+
}]
|
|
429
|
+
} },
|
|
430
|
+
create(_stack) {
|
|
431
|
+
return new MongoControlAdapterImpl();
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
//#endregion
|
|
435
|
+
export { introspectSchema as a, mongoScalarAuthoringTypes as c, extractDb as i, MongoInspectionExecutor as n, isMongoControlDriver as o, createMongoRunnerDeps as r, mongoAdapterDescriptor as s, MongoControlAdapterImpl as t };
|
|
436
|
+
|
|
437
|
+
//# sourceMappingURL=control-BOc5lrQg.mjs.map
|