@prisma/orm-target-mongo 8.0.0-rc.14-dev.5 → 8.0.0-rc.14-dev.7
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/adapter.mjs +1 -1
- package/dist/adapter.mjs.map +1 -1
- package/dist/adapter__control.mjs +1 -1
- package/dist/adapter__control.mjs.map +1 -1
- package/dist/adapter__runtime.mjs +2 -2
- package/dist/adapter__runtime.mjs.map +1 -1
- package/dist/{codecs-Dt4Q55gF-DDdyWx8-.mjs → codecs-DHo_Ei21-DHvEom71.mjs} +89 -50
- package/dist/codecs-DHo_Ei21-DHvEom71.mjs.map +1 -0
- package/dist/{control-Bg7Jaq6_.mjs → control-SXftFB8z.mjs} +3 -3
- package/dist/{control-Bg7Jaq6_.mjs.map → control-SXftFB8z.mjs.map} +1 -1
- package/dist/{descriptor-meta-DLXhalaq-mZXhO5bM.mjs → descriptor-meta-DqlqWWFC-ei2sStOs.mjs} +3 -3
- package/dist/{descriptor-meta-DLXhalaq-mZXhO5bM.mjs.map → descriptor-meta-DqlqWWFC-ei2sStOs.mjs.map} +1 -1
- package/dist/{descriptor-meta-runtime-C2pWx159-BLTObR45.mjs → descriptor-meta-runtime-DAabvKNm-CXYTUnQP.mjs} +3 -3
- package/dist/{descriptor-meta-runtime-C2pWx159-BLTObR45.mjs.map → descriptor-meta-runtime-DAabvKNm-CXYTUnQP.mjs.map} +1 -1
- package/dist/driver.mjs +1 -1
- package/dist/driver__control.mjs +1 -1
- package/dist/driver__control.mjs.map +1 -1
- package/dist/{mongo-adapter-BGuuu-r7-0OIt3FC4.mjs → mongo-adapter-BW-kRaXm-C3Sw9U9G.mjs} +8 -6
- package/dist/mongo-adapter-BW-kRaXm-C3Sw9U9G.mjs.map +1 -0
- package/dist/{mongo-driver-CPIxAKDF-Bk-Rv8on.mjs → mongo-driver-BtJ77prn-CI3a8jYk.mjs} +3 -3
- package/dist/{mongo-driver-CPIxAKDF-Bk-Rv8on.mjs.map → mongo-driver-BtJ77prn-CI3a8jYk.mjs.map} +1 -1
- package/dist/{prisma6-binding-CekUr7j1.mjs → prisma6-binding-CzV_iWP8.mjs} +2 -2
- package/dist/{prisma6-binding-CekUr7j1.mjs.map → prisma6-binding-CzV_iWP8.mjs.map} +1 -1
- package/dist/target.mjs +3 -3
- package/dist/target__codecs.mjs +1 -1
- package/dist/target__control.mjs +1 -1
- package/dist/target__pack.mjs +1 -1
- package/dist/target__pack.mjs.map +1 -1
- package/dist/target__prisma6-binding.mjs +1 -1
- package/dist/target__runtime.mjs +1 -1
- package/dist/target__runtime.mjs.map +1 -1
- package/package.json +9 -9
- package/dist/codecs-Dt4Q55gF-DDdyWx8-.mjs.map +0 -1
- package/dist/mongo-adapter-BGuuu-r7-0OIt3FC4.mjs.map +0 -1
package/dist/adapter.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { p as MONGO_VECTOR_CODEC_ID } from "./codec-ids-WdrumsYA-BkQfspmL.mjs";
|
|
2
|
-
import { a as lowerStage, i as lowerPipeline, n as lowerAggExpr, r as lowerFilter, t as createMongoAdapter } from "./mongo-adapter-
|
|
2
|
+
import { a as lowerStage, i as lowerPipeline, n as lowerAggExpr, r as lowerFilter, t as createMongoAdapter } from "./mongo-adapter-BW-kRaXm-C3Sw9U9G.mjs";
|
|
3
3
|
//#region ../../../3-mongo-target/2-mongo-adapter/dist/index.mjs
|
|
4
4
|
const mongoVectorNearOperation = Object.freeze({
|
|
5
5
|
self: { codecId: MONGO_VECTOR_CODEC_ID },
|
package/dist/adapter.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.mjs","names":[],"sources":["../../../../3-mongo-target/2-mongo-adapter/dist/index.mjs"],"sourcesContent":["import { a as lowerStage, i as lowerPipeline, n as lowerAggExpr, r as lowerFilter, t as createMongoAdapter } from \"./mongo-adapter-
|
|
1
|
+
{"version":3,"file":"adapter.mjs","names":[],"sources":["../../../../3-mongo-target/2-mongo-adapter/dist/index.mjs"],"sourcesContent":["import { a as lowerStage, i as lowerPipeline, n as lowerAggExpr, r as lowerFilter, t as createMongoAdapter } from \"./mongo-adapter-BW-kRaXm.mjs\";\nimport { MONGO_VECTOR_CODEC_ID } from \"@internal/target-mongo/codec-ids\";\n//#region src/core/operations.ts\nconst mongoVectorNearOperation = Object.freeze({\n\tself: { codecId: MONGO_VECTOR_CODEC_ID },\n\timpl: () => void 0\n});\nconst mongoVectorOperationDescriptors = { near: mongoVectorNearOperation };\n//#endregion\nexport { createMongoAdapter, lowerAggExpr, lowerFilter, lowerPipeline, lowerStage, mongoVectorNearOperation, mongoVectorOperationDescriptors };\n\n//# sourceMappingURL=index.mjs.map"],"mappings":";;;AAGA,MAAM,2BAA2B,OAAO,OAAO;CAC9C,MAAM,EAAE,SAAS,sBAAsB;CACvC,YAAY,KAAK;AAClB,CAAC;AACD,MAAM,kCAAkC,EAAE,MAAM,yBAAyB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as MONGO_DECIMAL128_CODEC_ID, c as MONGO_INT64_CODEC_ID, d as MONGO_OBJECTID_CODEC_ID, f as MONGO_STRING_CODEC_ID, i as MONGO_DATE_CODEC_ID, l as MONGO_INT64_NUMBER_CODEC_ID, n as MONGO_BOOLEAN_CODEC_ID, o as MONGO_DOUBLE_CODEC_ID, r as MONGO_BSON_CODEC_ID, s as MONGO_INT32_CODEC_ID, t as MONGO_BINARY_CODEC_ID, u as MONGO_JSON_CODEC_ID } from "./codec-ids-WdrumsYA-BkQfspmL.mjs";
|
|
2
|
-
import { t as createMongoAdapter } from "./mongo-adapter-
|
|
2
|
+
import { t as createMongoAdapter } from "./mongo-adapter-BW-kRaXm-C3Sw9U9G.mjs";
|
|
3
3
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
4
4
|
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
5
5
|
import { expr, fn } from "@prisma/orm-family-mongo/query-builder";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter__control.mjs","names":["#execute","#adapter","#markerLedgerCollection","#invariantMergeExpr"],"sources":["../../../../3-mongo-target/2-mongo-adapter/dist/control.mjs"],"sourcesContent":["import { t as createMongoAdapter } from \"./mongo-adapter-BGuuu-r7.mjs\";\nimport { MONGO_BINARY_CODEC_ID, MONGO_BOOLEAN_CODEC_ID, MONGO_BSON_CODEC_ID, MONGO_DATE_CODEC_ID, MONGO_DECIMAL128_CODEC_ID, MONGO_DOUBLE_CODEC_ID, MONGO_INT32_CODEC_ID, MONGO_INT64_CODEC_ID, MONGO_INT64_NUMBER_CODEC_ID, MONGO_JSON_CODEC_ID, MONGO_OBJECTID_CODEC_ID, MONGO_STRING_CODEC_ID } from \"@internal/target-mongo/codec-ids\";\nimport { MongoAggFieldRef, MongoAggLiteral, MongoAggOperator } from \"@internal/mongo-query-ast/execution\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { structuredError } from \"@internal/utils/structured-error\";\nimport { MongoServerError } from \"mongodb\";\nimport { MongoSchemaCollection, MongoSchemaCollectionOptions, MongoSchemaIR, MongoSchemaIndex, MongoSchemaValidator } from \"@internal/mongo-schema-ir\";\nimport { parseMarkerRowSafely, withMarkerReadErrorHandling } from \"@internal/errors/execution\";\nimport { ledgerOriginFromStored } from \"@internal/migration-tools/ledger-origin\";\nimport { expr, fn } from \"@internal/mongo-query-builder\";\nimport { collection } from \"@internal/mongo-query-builder/contract-free\";\nimport { type } from \"arktype\";\n//#region src/core/inspection-executor.ts\n/**\n* Executes the read-only catalog inspections (`listCollections` / `listIndexes`)\n* that migration prechecks/postchecks and operation preview evaluate, directly\n* against `db`. Routing these checks through the adapter's lowering seam is\n* deferred to the `typed-migration-verification-queries` slice.\n*/\nvar MongoInspectionExecutor = class {\n\tdb;\n\tconstructor(db) {\n\t\tthis.db = db;\n\t}\n\tasync listIndexes(cmd) {\n\t\ttry {\n\t\t\treturn await this.db.collection(cmd.collection).listIndexes().toArray();\n\t\t} catch (error) {\n\t\t\tif (error instanceof MongoServerError && error.code === 26) return [];\n\t\t\tthrow error;\n\t\t}\n\t}\n\tasync listCollections(_cmd) {\n\t\treturn this.db.listCollections().toArray();\n\t}\n};\n//#endregion\n//#region src/core/introspect-schema.ts\nconst PRISMA_MIGRATIONS_COLLECTION = \"_prisma_migrations\";\nfunction parseIndexKeys(keySpec) {\n\tconst keys = [];\n\tfor (const [field, direction] of Object.entries(keySpec)) keys.push({\n\t\tfield,\n\t\tdirection\n\t});\n\treturn keys;\n}\n/**\n* Exported for unit tests to exercise the defensive `!key` guard; not part of\n* the public API. Callers in this package use it via the `introspectSchema`\n* pipeline only.\n*/\nfunction isDefaultIdIndex(doc) {\n\tconst key = doc[\"key\"];\n\tif (!key) return false;\n\tconst entries = Object.entries(key);\n\treturn entries.length === 1 && entries[0]?.[0] === \"_id\" && entries[0]?.[1] === 1;\n}\nfunction parseIndex(doc) {\n\tconst keySpec = doc[\"key\"];\n\treturn new MongoSchemaIndex({\n\t\tkeys: parseIndexKeys(keySpec),\n\t\tunique: doc[\"unique\"],\n\t\tsparse: doc[\"sparse\"],\n\t\texpireAfterSeconds: doc[\"expireAfterSeconds\"],\n\t\tpartialFilterExpression: doc[\"partialFilterExpression\"],\n\t\twildcardProjection: doc[\"wildcardProjection\"],\n\t\tcollation: doc[\"collation\"] ? blindCast(doc[\"collation\"]) : void 0,\n\t\tweights: doc[\"weights\"],\n\t\tdefault_language: doc[\"default_language\"],\n\t\tlanguage_override: doc[\"language_override\"]\n\t});\n}\nfunction parseValidator(options) {\n\tconst validator = options[\"validator\"];\n\tif (!validator) return void 0;\n\tconst jsonSchema = validator[\"$jsonSchema\"];\n\tif (!jsonSchema) return void 0;\n\treturn new MongoSchemaValidator({\n\t\tjsonSchema,\n\t\tvalidationLevel: options[\"validationLevel\"] ?? \"strict\",\n\t\tvalidationAction: options[\"validationAction\"] ?? \"error\"\n\t});\n}\nfunction parseCollectionOptions(info) {\n\tconst options = info[\"options\"];\n\tif (!options) return void 0;\n\tconst capped = options[\"capped\"];\n\tconst size = options[\"size\"];\n\tconst max = options[\"max\"];\n\tconst timeseries = options[\"timeseries\"];\n\tconst collation = options[\"collation\"] ? blindCast(options[\"collation\"]) : void 0;\n\tconst changeStreamPreAndPostImages = options[\"changeStreamPreAndPostImages\"];\n\tconst clusteredIndex = options[\"clusteredIndex\"];\n\tif (!(capped || timeseries || collation || changeStreamPreAndPostImages || clusteredIndex)) return void 0;\n\treturn new MongoSchemaCollectionOptions({\n\t\t...capped ? { capped: {\n\t\t\tsize: size ?? 0,\n\t\t\t...max != null ? { max } : {}\n\t\t} } : {},\n\t\t...timeseries ? { timeseries } : {},\n\t\t...collation ? { collation } : {},\n\t\t...changeStreamPreAndPostImages ? { changeStreamPreAndPostImages } : {},\n\t\t...clusteredIndex ? { clusteredIndex } : {}\n\t});\n}\nasync function introspectSchema(db) {\n\tconst collectionInfos = await db.listCollections().toArray();\n\tconst collections = [];\n\tfor (const info of collectionInfos) {\n\t\tconst name = info[\"name\"];\n\t\tconst type = info[\"type\"];\n\t\tif (name === PRISMA_MIGRATIONS_COLLECTION) continue;\n\t\tif (name.startsWith(\"system.\")) continue;\n\t\tif (type === \"view\") continue;\n\t\tconst indexes = (await db.collection(name).listIndexes().toArray()).filter((doc) => !isDefaultIdIndex(doc)).map(parseIndex);\n\t\tconst validator = parseValidator(\"options\" in info ? info[\"options\"] : {});\n\t\tconst options = parseCollectionOptions(info);\n\t\tcollections.push(new MongoSchemaCollection({\n\t\t\tname,\n\t\t\tindexes,\n\t\t\t...validator ? { validator } : {},\n\t\t\t...options ? { options } : {}\n\t\t}));\n\t}\n\treturn new MongoSchemaIR(collections);\n}\n//#endregion\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/marker-ledger.ts\nconst COLLECTION = \"_prisma_migrations\";\nconst MONGO_MARKER_COLLECTION = `_prisma_migrations marker documents in ${COLLECTION}`;\nconst MONGO_LEDGER_COLLECTION = `_prisma_migrations ledger documents in ${COLLECTION}`;\nconst MongoMarkerDocSchema = type({\n\tspace: \"string\",\n\tstorageHash: \"string\",\n\tprofileHash: \"string\",\n\t\"contractJson?\": \"unknown | null\",\n\t\"canonicalVersion?\": \"number | null\",\n\t\"updatedAt?\": \"Date\",\n\t\"appTag?\": \"string | null\",\n\t\"meta?\": type({ \"[string]\": \"unknown\" }).or(\"null\"),\n\t\"invariants?\": type(\"string\").array(),\n\t\"+\": \"delete\"\n});\nfunction parseMongoMarkerDoc(doc) {\n\tconst result = MongoMarkerDocSchema(doc);\n\tif (result instanceof type.errors) throw mongoAdapterError(\"CONTRACT.MARKER_ROW_CORRUPT\", `Invalid marker doc on ${COLLECTION}: ${result.summary}`, { meta: {\n\t\tcollection: COLLECTION,\n\t\tdetail: result.summary\n\t} });\n\treturn {\n\t\tstorageHash: result.storageHash,\n\t\tprofileHash: result.profileHash,\n\t\tcontractJson: result.contractJson ?? null,\n\t\tcanonicalVersion: result.canonicalVersion ?? null,\n\t\tupdatedAt: result.updatedAt ?? /* @__PURE__ */ new Date(),\n\t\tappTag: result.appTag ?? null,\n\t\tmeta: result.meta ?? {},\n\t\tinvariants: result.invariants ?? []\n\t};\n}\nfunction parseMongoMarkerDocSafely(doc, space) {\n\treturn parseMarkerRowSafely(doc, parseMongoMarkerDoc, {\n\t\tspace,\n\t\tmarkerLocation: MONGO_MARKER_COLLECTION\n\t});\n}\n//#endregion\n//#region src/core/marker-ledger-collection.ts\nconst MARKER_LEDGER_COLLECTION = \"_prisma_migrations\";\n//#endregion\n//#region src/core/mongo-control-driver.ts\nfunction isMongoControlDriver(driver) {\n\treturn driver.familyId === \"mongo\" && driver.targetId === \"mongo\" && \"execute\" in driver && typeof driver.execute === \"function\";\n}\nfunction requireMongoControlDriver(driver) {\n\tif (!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) } });\n\treturn driver;\n}\nfunction extractDb(driver) {\n\treturn requireMongoControlDriver(driver).db;\n}\n//#endregion\n//#region src/core/mongo-control-adapter.ts\n/**\n* Mongo control adapter for control-plane operations like introspection\n* and marker-ledger CAS. Implements the family-level `MongoControlAdapter`\n* SPI. Every marker/ledger operation builds a canonical command inline via\n* the contract-free fluent builder and dispatches it through the family\n* adapter's lowering path (`createMongoAdapter().lower(plan, {})`) onto the\n* Mongo wire transport (`driver.execute(wireCommand)`) — the same route SQL\n* marker/ledger ops take through `adapter.lower()` → `driver.query()`.\n*/\nvar MongoControlAdapterImpl = class {\n\tfamilyId = \"mongo\";\n\ttargetId = \"mongo\";\n\t#adapter = createMongoAdapter();\n\t#markerLedgerCollection = collection(MARKER_LEDGER_COLLECTION);\n\tasync #execute(driver, command) {\n\t\tconst plan = {\n\t\t\tcollection: MARKER_LEDGER_COLLECTION,\n\t\t\tcommand,\n\t\t\tmeta: {\n\t\t\t\ttarget: \"mongo\",\n\t\t\t\ttargetFamily: \"mongo\",\n\t\t\t\tstorageHash: \"\",\n\t\t\t\tlane: \"control\"\n\t\t\t}\n\t\t};\n\t\tconst wireCommand = await this.#adapter.lower(plan, {});\n\t\tif (!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) } });\n\t\tconst rows = [];\n\t\tfor await (const row of driver.execute(wireCommand)) rows.push(row);\n\t\treturn rows;\n\t}\n\tasync executeDdl(driver, command) {\n\t\tconst wire = await this.#adapter.lower({ command }, {});\n\t\tawait driver.run(wire);\n\t}\n\t/**\n\t* Server-side invariant-merge aggregation expression:\n\t* `$sortArray({ input: $setUnion([$ifNull('$invariants', []), incoming]), sortBy: 1 })`.\n\t*\n\t* Built through the typed agg-expr layer — `fn.setUnion` plus the generic\n\t* `MongoAggOperator` for `$ifNull` / `$sortArray` (neither has a named `fn`\n\t* helper). Returns a `MongoAggOperator` that is passed directly to\n\t* `f.stage.set({ invariants: ... })` in the update pipeline.\n\t*/\n\t#invariantMergeExpr(incoming) {\n\t\tconst existingOrEmpty = MongoAggOperator.of(\"$ifNull\", [MongoAggFieldRef.of(\"invariants\"), MongoAggLiteral.of([])]);\n\t\tconst merged = fn.setUnion({\n\t\t\t_field: {\n\t\t\t\tcodecId: \"mongo/array@1\",\n\t\t\t\tnullable: false\n\t\t\t},\n\t\t\tnode: existingOrEmpty\n\t\t}, {\n\t\t\t_field: {\n\t\t\t\tcodecId: \"mongo/array@1\",\n\t\t\t\tnullable: false\n\t\t\t},\n\t\t\tnode: MongoAggLiteral.of([...incoming])\n\t\t});\n\t\treturn MongoAggOperator.of(\"$sortArray\", {\n\t\t\tinput: merged.node,\n\t\t\tsortBy: MongoAggLiteral.of(1)\n\t\t});\n\t}\n\tasync readMarker(driver, space) {\n\t\tconst doc = (await withMarkerReadErrorHandling(() => this.#execute(driver, this.#markerLedgerCollection.aggregate().match((f) => f._id.eq(space)).match((f) => f.space.eq(space)).limit(1).build()), {\n\t\t\tspace,\n\t\t\tmarkerLocation: MONGO_MARKER_COLLECTION\n\t\t}))[0];\n\t\tif (!doc) return null;\n\t\treturn parseMongoMarkerDocSafely(doc, space);\n\t}\n\tasync readAllMarkers(driver) {\n\t\tconst 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()), {\n\t\t\tspace: \"app\",\n\t\t\tmarkerLocation: MONGO_MARKER_COLLECTION\n\t\t});\n\t\tconst out = /* @__PURE__ */ new Map();\n\t\tfor (const doc of docs) {\n\t\t\tconst space = doc[\"space\"];\n\t\t\t/* 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`. */\n\t\t\tif (typeof space !== \"string\") continue;\n\t\t\tout.set(space, parseMongoMarkerDocSafely(doc, space));\n\t\t}\n\t\treturn out;\n\t}\n\tasync initMarker(driver, space, destination) {\n\t\tconst document = {\n\t\t\t_id: space,\n\t\t\tspace,\n\t\t\tstorageHash: destination.storageHash,\n\t\t\tprofileHash: destination.profileHash,\n\t\t\tcontractJson: null,\n\t\t\tcanonicalVersion: null,\n\t\t\tupdatedAt: /* @__PURE__ */ new Date(),\n\t\t\tappTag: null,\n\t\t\tmeta: {},\n\t\t\tinvariants: [...destination.invariants ?? []]\n\t\t};\n\t\tawait this.#execute(driver, this.#markerLedgerCollection.insertOne(document));\n\t}\n\tasync updateMarker(driver, space, expectedFrom, destination) {\n\t\tconst { invariants } = destination;\n\t\treturn (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 ? {\n\t\t\tstorageHash: MongoAggLiteral.of(destination.storageHash),\n\t\t\tprofileHash: MongoAggLiteral.of(destination.profileHash),\n\t\t\tupdatedAt: MongoAggLiteral.of(/* @__PURE__ */ new Date())\n\t\t} : {\n\t\t\tstorageHash: MongoAggLiteral.of(destination.storageHash),\n\t\t\tprofileHash: MongoAggLiteral.of(destination.profileHash),\n\t\t\tupdatedAt: MongoAggLiteral.of(/* @__PURE__ */ new Date()),\n\t\t\tinvariants: this.#invariantMergeExpr(invariants)\n\t\t})], { upsert: false }))).length > 0;\n\t}\n\tasync writeLedgerEntry(driver, space, entry) {\n\t\tconst document = {\n\t\t\ttype: \"ledger\",\n\t\t\tspace,\n\t\t\tedgeId: entry.edgeId,\n\t\t\tfrom: entry.from,\n\t\t\tto: entry.to,\n\t\t\tmigrationName: entry.migrationName,\n\t\t\tmigrationHash: entry.migrationHash,\n\t\t\toperations: blindCast(entry.operations),\n\t\t\tappliedAt: /* @__PURE__ */ new Date()\n\t\t};\n\t\tawait this.#execute(driver, this.#markerLedgerCollection.insertOne(document));\n\t}\n\tasync readLedger(driver, space) {\n\t\tconst ledgerContext = {\n\t\t\tspace: space ?? \"*\",\n\t\t\tmarkerLocation: MONGO_LEDGER_COLLECTION\n\t\t};\n\t\tconst chain = this.#markerLedgerCollection.aggregate().match((f) => f.type.eq(\"ledger\"));\n\t\tconst command = space === void 0 ? chain.sort({ _id: 1 }).build() : chain.match((f) => f.space.eq(space)).sort({ _id: 1 }).build();\n\t\tconst docs = await withMarkerReadErrorHandling(() => this.#execute(driver, command), ledgerContext);\n\t\tconst entries = [];\n\t\tfor (const doc of docs) {\n\t\t\tconst migrationName = doc[\"migrationName\"];\n\t\t\tconst migrationHash = doc[\"migrationHash\"];\n\t\t\tconst from = doc[\"from\"];\n\t\t\tconst to = doc[\"to\"];\n\t\t\tconst docSpace = doc[\"space\"];\n\t\t\tif (typeof migrationName !== \"string\" || typeof migrationHash !== \"string\") continue;\n\t\t\tif (typeof from !== \"string\" || typeof to !== \"string\") continue;\n\t\t\tif (typeof docSpace !== \"string\") continue;\n\t\t\tconst appliedAt = doc[\"appliedAt\"];\n\t\t\tconst appliedAtDate = appliedAt instanceof Date ? appliedAt : appliedAt !== void 0 ? new Date(String(appliedAt)) : /* @__PURE__ */ new Date();\n\t\t\tconst operations = doc[\"operations\"];\n\t\t\tconst opList = Array.isArray(operations) ? operations : [];\n\t\t\tentries.push({\n\t\t\t\tspace: docSpace,\n\t\t\t\tmigrationName,\n\t\t\t\tmigrationHash,\n\t\t\t\tfrom: ledgerOriginFromStored(from),\n\t\t\t\tto,\n\t\t\t\tappliedAt: appliedAtDate,\n\t\t\t\toperationCount: opList.length\n\t\t\t});\n\t\t}\n\t\treturn entries;\n\t}\n\tasync introspectSchema(driver) {\n\t\treturn introspectSchema(extractDb(driver));\n\t}\n\tcreateRunnerDependencies(driver) {\n\t\tconst controlDriver = requireMongoControlDriver(driver);\n\t\treturn {\n\t\t\tinspectionExecutor: new MongoInspectionExecutor(controlDriver.db),\n\t\t\tadapter: this.#adapter,\n\t\t\tdriver: controlDriver,\n\t\t\texecuteDdl: (command) => this.executeDdl(controlDriver, command),\n\t\t\tmarkerOps: {\n\t\t\t\treadMarker: (space) => this.readMarker(controlDriver, space),\n\t\t\t\tinitMarker: (space, destination) => this.initMarker(controlDriver, space, destination),\n\t\t\t\tupdateMarker: (space, expectedFrom, destination) => this.updateMarker(controlDriver, space, expectedFrom, destination),\n\t\t\t\twriteLedgerEntry: (space, entry) => this.writeLedgerEntry(controlDriver, space, entry)\n\t\t\t},\n\t\t\tintrospectSchema: () => this.introspectSchema(controlDriver)\n\t\t};\n\t}\n};\n//#endregion\n//#region src/exports/control.ts\n/**\n* The base PSL scalars as zero-arg type constructors in the unified authoring channel. For a codec with one BSON type, `nativeType` is that type (`codecLookup.targetTypesFor(codecId)[0]`). `Json` (several BSON types) and `Bson` (none) have a `nativeType` that names the codec instead; the validator reads the codec's `targetTypes` list, not this value.\n*/\nconst mongoScalarAuthoringTypes = {\n\tString: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Text, stored as BSON string.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_STRING_CODEC_ID,\n\t\t\tnativeType: \"string\"\n\t\t}\n\t},\n\tInt32: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A signed 32-bit integer, stored as BSON int.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_INT32_CODEC_ID,\n\t\t\tnativeType: \"int\"\n\t\t}\n\t},\n\tBool: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A true or false value, stored as BSON bool.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_BOOLEAN_CODEC_ID,\n\t\t\tnativeType: \"bool\"\n\t\t}\n\t},\n\tDate: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A date and time with millisecond precision, stored as BSON date.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_DATE_CODEC_ID,\n\t\t\tnativeType: \"date\"\n\t\t}\n\t},\n\tObjectId: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A 12-byte MongoDB identifier, stored as BSON objectId.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_OBJECTID_CODEC_ID,\n\t\t\tnativeType: \"objectId\"\n\t\t}\n\t},\n\tDouble: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A double-precision floating-point number, stored as BSON double.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_DOUBLE_CODEC_ID,\n\t\t\tnativeType: \"double\"\n\t\t}\n\t},\n\tInt64: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A signed 64-bit integer read as a bigint, stored as BSON long.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_INT64_CODEC_ID,\n\t\t\tnativeType: \"long\"\n\t\t}\n\t},\n\tInt64Number: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A signed 64-bit integer read as a JavaScript number within its safe integer range, stored as BSON long.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_INT64_NUMBER_CODEC_ID,\n\t\t\tnativeType: \"long\"\n\t\t}\n\t},\n\tDecimal128: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A 128-bit decimal read as decimal text without an exponent, stored as BSON decimal.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_DECIMAL128_CODEC_ID,\n\t\t\tnativeType: \"decimal\"\n\t\t}\n\t},\n\tBinary: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Bytes read as a Uint8Array, stored as BSON binData.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_BINARY_CODEC_ID,\n\t\t\tnativeType: \"binData\"\n\t\t}\n\t},\n\tJson: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A JSON value, stored as BSON object, array, string, double, int, long, bool or null; the collection validator admits only those types at the top level, and the codec refuses anything else at any depth.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_JSON_CODEC_ID,\n\t\t\tnativeType: \"json\"\n\t\t}\n\t},\n\tBson: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Any BSON value, read as BsonValue; the collection validator does not constrain it.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_BSON_CODEC_ID,\n\t\t\tnativeType: \"bson\"\n\t\t}\n\t},\n\tInt: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Deprecated: use Int32. A signed 32-bit integer, stored as BSON int.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_INT32_CODEC_ID,\n\t\t\tnativeType: \"int\"\n\t\t},\n\t\tdeprecated: { replacement: \"Int32\" }\n\t},\n\tFloat: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Deprecated: use Double. A double-precision floating-point number, stored as BSON double.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_DOUBLE_CODEC_ID,\n\t\t\tnativeType: \"double\"\n\t\t},\n\t\tdeprecated: { replacement: \"Double\" }\n\t},\n\tBoolean: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Deprecated: use Bool. A true or false value, stored as BSON bool.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_BOOLEAN_CODEC_ID,\n\t\t\tnativeType: \"bool\"\n\t\t},\n\t\tdeprecated: { replacement: \"Bool\" }\n\t},\n\tDateTime: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Deprecated: use Date. A date and time with millisecond precision, stored as BSON date.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_DATE_CODEC_ID,\n\t\t\tnativeType: \"date\"\n\t\t},\n\t\tdeprecated: { replacement: \"Date\" }\n\t}\n};\nconst mongoAdapterDescriptor = {\n\tkind: \"adapter\",\n\tid: \"mongo\",\n\tfamilyId: \"mongo\",\n\ttargetId: \"mongo\",\n\tversion: \"0.0.1\",\n\tauthoring: { type: mongoScalarAuthoringTypes },\n\ttypes: { codecTypes: {\n\t\timport: {\n\t\t\tpackage: \"@internal/target-mongo/codec-types\",\n\t\t\tnamed: \"CodecTypes\",\n\t\t\talias: \"MongoCodecTypes\"\n\t\t},\n\t\ttypeImports: [{\n\t\t\tpackage: \"@internal/target-mongo/codec-types\",\n\t\t\tnamed: \"Vector\",\n\t\t\talias: \"Vector\"\n\t\t}]\n\t} },\n\tcreate(_stack) {\n\t\treturn new MongoControlAdapterImpl();\n\t}\n};\n//#endregion\nexport { MongoControlAdapterImpl, MongoInspectionExecutor, createMongoAdapter, mongoAdapterDescriptor as default, mongoAdapterDescriptor, extractDb, introspectSchema, isMongoControlDriver, mongoScalarAuthoringTypes };\n\n//# sourceMappingURL=control.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,IAAI,0BAA0B,MAAM;CACnC;CACA,YAAY,IAAI;EACf,KAAK,KAAK;CACX;CACA,MAAM,YAAY,KAAK;EACtB,IAAI;GACH,OAAO,MAAM,KAAK,GAAG,WAAW,IAAI,UAAU,CAAC,CAAC,YAAY,CAAC,CAAC,QAAQ;EACvE,SAAS,OAAO;GACf,IAAI,iBAAiB,oBAAoB,MAAM,SAAS,IAAI,OAAO,CAAC;GACpE,MAAM;EACP;CACD;CACA,MAAM,gBAAgB,MAAM;EAC3B,OAAO,KAAK,GAAG,gBAAgB,CAAC,CAAC,QAAQ;CAC1C;AACD;AAGA,MAAM,+BAA+B;AACrC,SAAS,eAAe,SAAS;CAChC,MAAM,OAAO,CAAC;CACd,KAAK,MAAM,CAAC,OAAO,cAAc,OAAO,QAAQ,OAAO,GAAG,KAAK,KAAK;EACnE;EACA;CACD,CAAC;CACD,OAAO;AACR;;;;;;AAMA,SAAS,iBAAiB,KAAK;CAC9B,MAAM,MAAM,IAAI;CAChB,IAAI,CAAC,KAAK,OAAO;CACjB,MAAM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ACA,SAAS;EACR,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY;EACb;EACA,YAAY,EAAE,aAAa,OAAO;CACnC;CACA,UAAU;EACT,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY;EACb;EACA,YAAY,EAAE,aAAa,OAAO;CACnC;AACD;AACA,MAAM,yBAAyB;CAC9B,MAAM;CACN,IAAI;CACJ,UAAU;CACV,UAAU;CACV,SAAS;CACT,WAAW,EAAE,MAAM,0BAA0B;CAC7C,OAAO,EAAE,YAAY;EACpB,QAAQ;GACP,SAAS;GACT,OAAO;GACP,OAAO;EACR;EACA,aAAa,CAAC;GACb,SAAS;GACT,OAAO;GACP,OAAO;EACR,CAAC;CACF,EAAE;CACF,OAAO,QAAQ;EACd,OAAO,IAAI,wBAAwB;CACpC;AACD"}
|
|
1
|
+
{"version":3,"file":"adapter__control.mjs","names":["#execute","#adapter","#markerLedgerCollection","#invariantMergeExpr"],"sources":["../../../../3-mongo-target/2-mongo-adapter/dist/control.mjs"],"sourcesContent":["import { t as createMongoAdapter } from \"./mongo-adapter-BW-kRaXm.mjs\";\nimport { MONGO_BINARY_CODEC_ID, MONGO_BOOLEAN_CODEC_ID, MONGO_BSON_CODEC_ID, MONGO_DATE_CODEC_ID, MONGO_DECIMAL128_CODEC_ID, MONGO_DOUBLE_CODEC_ID, MONGO_INT32_CODEC_ID, MONGO_INT64_CODEC_ID, MONGO_INT64_NUMBER_CODEC_ID, MONGO_JSON_CODEC_ID, MONGO_OBJECTID_CODEC_ID, MONGO_STRING_CODEC_ID } from \"@internal/target-mongo/codec-ids\";\nimport { MongoAggFieldRef, MongoAggLiteral, MongoAggOperator } from \"@internal/mongo-query-ast/execution\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { structuredError } from \"@internal/utils/structured-error\";\nimport { MongoServerError } from \"mongodb\";\nimport { MongoSchemaCollection, MongoSchemaCollectionOptions, MongoSchemaIR, MongoSchemaIndex, MongoSchemaValidator } from \"@internal/mongo-schema-ir\";\nimport { parseMarkerRowSafely, withMarkerReadErrorHandling } from \"@internal/errors/execution\";\nimport { ledgerOriginFromStored } from \"@internal/migration-tools/ledger-origin\";\nimport { expr, fn } from \"@internal/mongo-query-builder\";\nimport { collection } from \"@internal/mongo-query-builder/contract-free\";\nimport { type } from \"arktype\";\n//#region src/core/inspection-executor.ts\n/**\n* Executes the read-only catalog inspections (`listCollections` / `listIndexes`)\n* that migration prechecks/postchecks and operation preview evaluate, directly\n* against `db`. Routing these checks through the adapter's lowering seam is\n* deferred to the `typed-migration-verification-queries` slice.\n*/\nvar MongoInspectionExecutor = class {\n\tdb;\n\tconstructor(db) {\n\t\tthis.db = db;\n\t}\n\tasync listIndexes(cmd) {\n\t\ttry {\n\t\t\treturn await this.db.collection(cmd.collection).listIndexes().toArray();\n\t\t} catch (error) {\n\t\t\tif (error instanceof MongoServerError && error.code === 26) return [];\n\t\t\tthrow error;\n\t\t}\n\t}\n\tasync listCollections(_cmd) {\n\t\treturn this.db.listCollections().toArray();\n\t}\n};\n//#endregion\n//#region src/core/introspect-schema.ts\nconst PRISMA_MIGRATIONS_COLLECTION = \"_prisma_migrations\";\nfunction parseIndexKeys(keySpec) {\n\tconst keys = [];\n\tfor (const [field, direction] of Object.entries(keySpec)) keys.push({\n\t\tfield,\n\t\tdirection\n\t});\n\treturn keys;\n}\n/**\n* Exported for unit tests to exercise the defensive `!key` guard; not part of\n* the public API. Callers in this package use it via the `introspectSchema`\n* pipeline only.\n*/\nfunction isDefaultIdIndex(doc) {\n\tconst key = doc[\"key\"];\n\tif (!key) return false;\n\tconst entries = Object.entries(key);\n\treturn entries.length === 1 && entries[0]?.[0] === \"_id\" && entries[0]?.[1] === 1;\n}\nfunction parseIndex(doc) {\n\tconst keySpec = doc[\"key\"];\n\treturn new MongoSchemaIndex({\n\t\tkeys: parseIndexKeys(keySpec),\n\t\tunique: doc[\"unique\"],\n\t\tsparse: doc[\"sparse\"],\n\t\texpireAfterSeconds: doc[\"expireAfterSeconds\"],\n\t\tpartialFilterExpression: doc[\"partialFilterExpression\"],\n\t\twildcardProjection: doc[\"wildcardProjection\"],\n\t\tcollation: doc[\"collation\"] ? blindCast(doc[\"collation\"]) : void 0,\n\t\tweights: doc[\"weights\"],\n\t\tdefault_language: doc[\"default_language\"],\n\t\tlanguage_override: doc[\"language_override\"]\n\t});\n}\nfunction parseValidator(options) {\n\tconst validator = options[\"validator\"];\n\tif (!validator) return void 0;\n\tconst jsonSchema = validator[\"$jsonSchema\"];\n\tif (!jsonSchema) return void 0;\n\treturn new MongoSchemaValidator({\n\t\tjsonSchema,\n\t\tvalidationLevel: options[\"validationLevel\"] ?? \"strict\",\n\t\tvalidationAction: options[\"validationAction\"] ?? \"error\"\n\t});\n}\nfunction parseCollectionOptions(info) {\n\tconst options = info[\"options\"];\n\tif (!options) return void 0;\n\tconst capped = options[\"capped\"];\n\tconst size = options[\"size\"];\n\tconst max = options[\"max\"];\n\tconst timeseries = options[\"timeseries\"];\n\tconst collation = options[\"collation\"] ? blindCast(options[\"collation\"]) : void 0;\n\tconst changeStreamPreAndPostImages = options[\"changeStreamPreAndPostImages\"];\n\tconst clusteredIndex = options[\"clusteredIndex\"];\n\tif (!(capped || timeseries || collation || changeStreamPreAndPostImages || clusteredIndex)) return void 0;\n\treturn new MongoSchemaCollectionOptions({\n\t\t...capped ? { capped: {\n\t\t\tsize: size ?? 0,\n\t\t\t...max != null ? { max } : {}\n\t\t} } : {},\n\t\t...timeseries ? { timeseries } : {},\n\t\t...collation ? { collation } : {},\n\t\t...changeStreamPreAndPostImages ? { changeStreamPreAndPostImages } : {},\n\t\t...clusteredIndex ? { clusteredIndex } : {}\n\t});\n}\nasync function introspectSchema(db) {\n\tconst collectionInfos = await db.listCollections().toArray();\n\tconst collections = [];\n\tfor (const info of collectionInfos) {\n\t\tconst name = info[\"name\"];\n\t\tconst type = info[\"type\"];\n\t\tif (name === PRISMA_MIGRATIONS_COLLECTION) continue;\n\t\tif (name.startsWith(\"system.\")) continue;\n\t\tif (type === \"view\") continue;\n\t\tconst indexes = (await db.collection(name).listIndexes().toArray()).filter((doc) => !isDefaultIdIndex(doc)).map(parseIndex);\n\t\tconst validator = parseValidator(\"options\" in info ? info[\"options\"] : {});\n\t\tconst options = parseCollectionOptions(info);\n\t\tcollections.push(new MongoSchemaCollection({\n\t\t\tname,\n\t\t\tindexes,\n\t\t\t...validator ? { validator } : {},\n\t\t\t...options ? { options } : {}\n\t\t}));\n\t}\n\treturn new MongoSchemaIR(collections);\n}\n//#endregion\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/marker-ledger.ts\nconst COLLECTION = \"_prisma_migrations\";\nconst MONGO_MARKER_COLLECTION = `_prisma_migrations marker documents in ${COLLECTION}`;\nconst MONGO_LEDGER_COLLECTION = `_prisma_migrations ledger documents in ${COLLECTION}`;\nconst MongoMarkerDocSchema = type({\n\tspace: \"string\",\n\tstorageHash: \"string\",\n\tprofileHash: \"string\",\n\t\"contractJson?\": \"unknown | null\",\n\t\"canonicalVersion?\": \"number | null\",\n\t\"updatedAt?\": \"Date\",\n\t\"appTag?\": \"string | null\",\n\t\"meta?\": type({ \"[string]\": \"unknown\" }).or(\"null\"),\n\t\"invariants?\": type(\"string\").array(),\n\t\"+\": \"delete\"\n});\nfunction parseMongoMarkerDoc(doc) {\n\tconst result = MongoMarkerDocSchema(doc);\n\tif (result instanceof type.errors) throw mongoAdapterError(\"CONTRACT.MARKER_ROW_CORRUPT\", `Invalid marker doc on ${COLLECTION}: ${result.summary}`, { meta: {\n\t\tcollection: COLLECTION,\n\t\tdetail: result.summary\n\t} });\n\treturn {\n\t\tstorageHash: result.storageHash,\n\t\tprofileHash: result.profileHash,\n\t\tcontractJson: result.contractJson ?? null,\n\t\tcanonicalVersion: result.canonicalVersion ?? null,\n\t\tupdatedAt: result.updatedAt ?? /* @__PURE__ */ new Date(),\n\t\tappTag: result.appTag ?? null,\n\t\tmeta: result.meta ?? {},\n\t\tinvariants: result.invariants ?? []\n\t};\n}\nfunction parseMongoMarkerDocSafely(doc, space) {\n\treturn parseMarkerRowSafely(doc, parseMongoMarkerDoc, {\n\t\tspace,\n\t\tmarkerLocation: MONGO_MARKER_COLLECTION\n\t});\n}\n//#endregion\n//#region src/core/marker-ledger-collection.ts\nconst MARKER_LEDGER_COLLECTION = \"_prisma_migrations\";\n//#endregion\n//#region src/core/mongo-control-driver.ts\nfunction isMongoControlDriver(driver) {\n\treturn driver.familyId === \"mongo\" && driver.targetId === \"mongo\" && \"execute\" in driver && typeof driver.execute === \"function\";\n}\nfunction requireMongoControlDriver(driver) {\n\tif (!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) } });\n\treturn driver;\n}\nfunction extractDb(driver) {\n\treturn requireMongoControlDriver(driver).db;\n}\n//#endregion\n//#region src/core/mongo-control-adapter.ts\n/**\n* Mongo control adapter for control-plane operations like introspection\n* and marker-ledger CAS. Implements the family-level `MongoControlAdapter`\n* SPI. Every marker/ledger operation builds a canonical command inline via\n* the contract-free fluent builder and dispatches it through the family\n* adapter's lowering path (`createMongoAdapter().lower(plan, {})`) onto the\n* Mongo wire transport (`driver.execute(wireCommand)`) — the same route SQL\n* marker/ledger ops take through `adapter.lower()` → `driver.query()`.\n*/\nvar MongoControlAdapterImpl = class {\n\tfamilyId = \"mongo\";\n\ttargetId = \"mongo\";\n\t#adapter = createMongoAdapter();\n\t#markerLedgerCollection = collection(MARKER_LEDGER_COLLECTION);\n\tasync #execute(driver, command) {\n\t\tconst plan = {\n\t\t\tcollection: MARKER_LEDGER_COLLECTION,\n\t\t\tcommand,\n\t\t\tmeta: {\n\t\t\t\ttarget: \"mongo\",\n\t\t\t\ttargetFamily: \"mongo\",\n\t\t\t\tstorageHash: \"\",\n\t\t\t\tlane: \"control\"\n\t\t\t}\n\t\t};\n\t\tconst wireCommand = await this.#adapter.lower(plan, {});\n\t\tif (!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) } });\n\t\tconst rows = [];\n\t\tfor await (const row of driver.execute(wireCommand)) rows.push(row);\n\t\treturn rows;\n\t}\n\tasync executeDdl(driver, command) {\n\t\tconst wire = await this.#adapter.lower({ command }, {});\n\t\tawait driver.run(wire);\n\t}\n\t/**\n\t* Server-side invariant-merge aggregation expression:\n\t* `$sortArray({ input: $setUnion([$ifNull('$invariants', []), incoming]), sortBy: 1 })`.\n\t*\n\t* Built through the typed agg-expr layer — `fn.setUnion` plus the generic\n\t* `MongoAggOperator` for `$ifNull` / `$sortArray` (neither has a named `fn`\n\t* helper). Returns a `MongoAggOperator` that is passed directly to\n\t* `f.stage.set({ invariants: ... })` in the update pipeline.\n\t*/\n\t#invariantMergeExpr(incoming) {\n\t\tconst existingOrEmpty = MongoAggOperator.of(\"$ifNull\", [MongoAggFieldRef.of(\"invariants\"), MongoAggLiteral.of([])]);\n\t\tconst merged = fn.setUnion({\n\t\t\t_field: {\n\t\t\t\tcodecId: \"mongo/array@1\",\n\t\t\t\tnullable: false\n\t\t\t},\n\t\t\tnode: existingOrEmpty\n\t\t}, {\n\t\t\t_field: {\n\t\t\t\tcodecId: \"mongo/array@1\",\n\t\t\t\tnullable: false\n\t\t\t},\n\t\t\tnode: MongoAggLiteral.of([...incoming])\n\t\t});\n\t\treturn MongoAggOperator.of(\"$sortArray\", {\n\t\t\tinput: merged.node,\n\t\t\tsortBy: MongoAggLiteral.of(1)\n\t\t});\n\t}\n\tasync readMarker(driver, space) {\n\t\tconst doc = (await withMarkerReadErrorHandling(() => this.#execute(driver, this.#markerLedgerCollection.aggregate().match((f) => f._id.eq(space)).match((f) => f.space.eq(space)).limit(1).build()), {\n\t\t\tspace,\n\t\t\tmarkerLocation: MONGO_MARKER_COLLECTION\n\t\t}))[0];\n\t\tif (!doc) return null;\n\t\treturn parseMongoMarkerDocSafely(doc, space);\n\t}\n\tasync readAllMarkers(driver) {\n\t\tconst 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()), {\n\t\t\tspace: \"app\",\n\t\t\tmarkerLocation: MONGO_MARKER_COLLECTION\n\t\t});\n\t\tconst out = /* @__PURE__ */ new Map();\n\t\tfor (const doc of docs) {\n\t\t\tconst space = doc[\"space\"];\n\t\t\t/* 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`. */\n\t\t\tif (typeof space !== \"string\") continue;\n\t\t\tout.set(space, parseMongoMarkerDocSafely(doc, space));\n\t\t}\n\t\treturn out;\n\t}\n\tasync initMarker(driver, space, destination) {\n\t\tconst document = {\n\t\t\t_id: space,\n\t\t\tspace,\n\t\t\tstorageHash: destination.storageHash,\n\t\t\tprofileHash: destination.profileHash,\n\t\t\tcontractJson: null,\n\t\t\tcanonicalVersion: null,\n\t\t\tupdatedAt: /* @__PURE__ */ new Date(),\n\t\t\tappTag: null,\n\t\t\tmeta: {},\n\t\t\tinvariants: [...destination.invariants ?? []]\n\t\t};\n\t\tawait this.#execute(driver, this.#markerLedgerCollection.insertOne(document));\n\t}\n\tasync updateMarker(driver, space, expectedFrom, destination) {\n\t\tconst { invariants } = destination;\n\t\treturn (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 ? {\n\t\t\tstorageHash: MongoAggLiteral.of(destination.storageHash),\n\t\t\tprofileHash: MongoAggLiteral.of(destination.profileHash),\n\t\t\tupdatedAt: MongoAggLiteral.of(/* @__PURE__ */ new Date())\n\t\t} : {\n\t\t\tstorageHash: MongoAggLiteral.of(destination.storageHash),\n\t\t\tprofileHash: MongoAggLiteral.of(destination.profileHash),\n\t\t\tupdatedAt: MongoAggLiteral.of(/* @__PURE__ */ new Date()),\n\t\t\tinvariants: this.#invariantMergeExpr(invariants)\n\t\t})], { upsert: false }))).length > 0;\n\t}\n\tasync writeLedgerEntry(driver, space, entry) {\n\t\tconst document = {\n\t\t\ttype: \"ledger\",\n\t\t\tspace,\n\t\t\tedgeId: entry.edgeId,\n\t\t\tfrom: entry.from,\n\t\t\tto: entry.to,\n\t\t\tmigrationName: entry.migrationName,\n\t\t\tmigrationHash: entry.migrationHash,\n\t\t\toperations: blindCast(entry.operations),\n\t\t\tappliedAt: /* @__PURE__ */ new Date()\n\t\t};\n\t\tawait this.#execute(driver, this.#markerLedgerCollection.insertOne(document));\n\t}\n\tasync readLedger(driver, space) {\n\t\tconst ledgerContext = {\n\t\t\tspace: space ?? \"*\",\n\t\t\tmarkerLocation: MONGO_LEDGER_COLLECTION\n\t\t};\n\t\tconst chain = this.#markerLedgerCollection.aggregate().match((f) => f.type.eq(\"ledger\"));\n\t\tconst command = space === void 0 ? chain.sort({ _id: 1 }).build() : chain.match((f) => f.space.eq(space)).sort({ _id: 1 }).build();\n\t\tconst docs = await withMarkerReadErrorHandling(() => this.#execute(driver, command), ledgerContext);\n\t\tconst entries = [];\n\t\tfor (const doc of docs) {\n\t\t\tconst migrationName = doc[\"migrationName\"];\n\t\t\tconst migrationHash = doc[\"migrationHash\"];\n\t\t\tconst from = doc[\"from\"];\n\t\t\tconst to = doc[\"to\"];\n\t\t\tconst docSpace = doc[\"space\"];\n\t\t\tif (typeof migrationName !== \"string\" || typeof migrationHash !== \"string\") continue;\n\t\t\tif (typeof from !== \"string\" || typeof to !== \"string\") continue;\n\t\t\tif (typeof docSpace !== \"string\") continue;\n\t\t\tconst appliedAt = doc[\"appliedAt\"];\n\t\t\tconst appliedAtDate = appliedAt instanceof Date ? appliedAt : appliedAt !== void 0 ? new Date(String(appliedAt)) : /* @__PURE__ */ new Date();\n\t\t\tconst operations = doc[\"operations\"];\n\t\t\tconst opList = Array.isArray(operations) ? operations : [];\n\t\t\tentries.push({\n\t\t\t\tspace: docSpace,\n\t\t\t\tmigrationName,\n\t\t\t\tmigrationHash,\n\t\t\t\tfrom: ledgerOriginFromStored(from),\n\t\t\t\tto,\n\t\t\t\tappliedAt: appliedAtDate,\n\t\t\t\toperationCount: opList.length\n\t\t\t});\n\t\t}\n\t\treturn entries;\n\t}\n\tasync introspectSchema(driver) {\n\t\treturn introspectSchema(extractDb(driver));\n\t}\n\tcreateRunnerDependencies(driver) {\n\t\tconst controlDriver = requireMongoControlDriver(driver);\n\t\treturn {\n\t\t\tinspectionExecutor: new MongoInspectionExecutor(controlDriver.db),\n\t\t\tadapter: this.#adapter,\n\t\t\tdriver: controlDriver,\n\t\t\texecuteDdl: (command) => this.executeDdl(controlDriver, command),\n\t\t\tmarkerOps: {\n\t\t\t\treadMarker: (space) => this.readMarker(controlDriver, space),\n\t\t\t\tinitMarker: (space, destination) => this.initMarker(controlDriver, space, destination),\n\t\t\t\tupdateMarker: (space, expectedFrom, destination) => this.updateMarker(controlDriver, space, expectedFrom, destination),\n\t\t\t\twriteLedgerEntry: (space, entry) => this.writeLedgerEntry(controlDriver, space, entry)\n\t\t\t},\n\t\t\tintrospectSchema: () => this.introspectSchema(controlDriver)\n\t\t};\n\t}\n};\n//#endregion\n//#region src/exports/control.ts\n/**\n* The base PSL scalars as zero-arg type constructors in the unified authoring channel. For a codec with one BSON type, `nativeType` is that type (`codecLookup.targetTypesFor(codecId)[0]`). `Json` (several BSON types) and `Bson` (none) have a `nativeType` that names the codec instead; the validator reads the codec's `targetTypes` list, not this value.\n*/\nconst mongoScalarAuthoringTypes = {\n\tString: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Text, stored as BSON string.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_STRING_CODEC_ID,\n\t\t\tnativeType: \"string\"\n\t\t}\n\t},\n\tInt32: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A signed 32-bit integer, stored as BSON int.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_INT32_CODEC_ID,\n\t\t\tnativeType: \"int\"\n\t\t}\n\t},\n\tBool: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A true or false value, stored as BSON bool.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_BOOLEAN_CODEC_ID,\n\t\t\tnativeType: \"bool\"\n\t\t}\n\t},\n\tDate: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A date and time with millisecond precision, stored as BSON date.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_DATE_CODEC_ID,\n\t\t\tnativeType: \"date\"\n\t\t}\n\t},\n\tObjectId: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A 12-byte MongoDB identifier, stored as BSON objectId.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_OBJECTID_CODEC_ID,\n\t\t\tnativeType: \"objectId\"\n\t\t}\n\t},\n\tDouble: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A double-precision floating-point number, stored as BSON double.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_DOUBLE_CODEC_ID,\n\t\t\tnativeType: \"double\"\n\t\t}\n\t},\n\tInt64: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A signed 64-bit integer read as a bigint, stored as BSON long.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_INT64_CODEC_ID,\n\t\t\tnativeType: \"long\"\n\t\t}\n\t},\n\tInt64Number: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A signed 64-bit integer read as a JavaScript number within its safe integer range, stored as BSON long.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_INT64_NUMBER_CODEC_ID,\n\t\t\tnativeType: \"long\"\n\t\t}\n\t},\n\tDecimal128: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A 128-bit decimal read as decimal text without an exponent, stored as BSON decimal.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_DECIMAL128_CODEC_ID,\n\t\t\tnativeType: \"decimal\"\n\t\t}\n\t},\n\tBinary: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Bytes read as a Uint8Array, stored as BSON binData.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_BINARY_CODEC_ID,\n\t\t\tnativeType: \"binData\"\n\t\t}\n\t},\n\tJson: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"A JSON value, stored as BSON object, array, string, double, int, long, bool or null; the collection validator admits only those types at the top level, and the codec refuses anything else at any depth.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_JSON_CODEC_ID,\n\t\t\tnativeType: \"json\"\n\t\t}\n\t},\n\tBson: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Any BSON value, read as BsonValue; the collection validator does not constrain it.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_BSON_CODEC_ID,\n\t\t\tnativeType: \"bson\"\n\t\t}\n\t},\n\tInt: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Deprecated: use Int32. A signed 32-bit integer, stored as BSON int.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_INT32_CODEC_ID,\n\t\t\tnativeType: \"int\"\n\t\t},\n\t\tdeprecated: { replacement: \"Int32\" }\n\t},\n\tFloat: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Deprecated: use Double. A double-precision floating-point number, stored as BSON double.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_DOUBLE_CODEC_ID,\n\t\t\tnativeType: \"double\"\n\t\t},\n\t\tdeprecated: { replacement: \"Double\" }\n\t},\n\tBoolean: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Deprecated: use Bool. A true or false value, stored as BSON bool.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_BOOLEAN_CODEC_ID,\n\t\t\tnativeType: \"bool\"\n\t\t},\n\t\tdeprecated: { replacement: \"Bool\" }\n\t},\n\tDateTime: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: \"Deprecated: use Date. A date and time with millisecond precision, stored as BSON date.\",\n\t\toutput: {\n\t\t\tcodecId: MONGO_DATE_CODEC_ID,\n\t\t\tnativeType: \"date\"\n\t\t},\n\t\tdeprecated: { replacement: \"Date\" }\n\t}\n};\nconst mongoAdapterDescriptor = {\n\tkind: \"adapter\",\n\tid: \"mongo\",\n\tfamilyId: \"mongo\",\n\ttargetId: \"mongo\",\n\tversion: \"0.0.1\",\n\tauthoring: { type: mongoScalarAuthoringTypes },\n\ttypes: { codecTypes: {\n\t\timport: {\n\t\t\tpackage: \"@internal/target-mongo/codec-types\",\n\t\t\tnamed: \"CodecTypes\",\n\t\t\talias: \"MongoCodecTypes\"\n\t\t},\n\t\ttypeImports: [{\n\t\t\tpackage: \"@internal/target-mongo/codec-types\",\n\t\t\tnamed: \"Vector\",\n\t\t\talias: \"Vector\"\n\t\t}]\n\t} },\n\tcreate(_stack) {\n\t\treturn new MongoControlAdapterImpl();\n\t}\n};\n//#endregion\nexport { MongoControlAdapterImpl, MongoInspectionExecutor, createMongoAdapter, mongoAdapterDescriptor as default, mongoAdapterDescriptor, extractDb, introspectSchema, isMongoControlDriver, mongoScalarAuthoringTypes };\n\n//# sourceMappingURL=control.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,IAAI,0BAA0B,MAAM;CACnC;CACA,YAAY,IAAI;EACf,KAAK,KAAK;CACX;CACA,MAAM,YAAY,KAAK;EACtB,IAAI;GACH,OAAO,MAAM,KAAK,GAAG,WAAW,IAAI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EACX,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY;EACb;CACD;CACA,QAAQ;EACP,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY;EACb;CACD;CACA,MAAM;EACL,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY;EACb;CACD;CACA,MAAM;EACL,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY;EACb;CACD;CACA,KAAK;EACJ,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY;EACb;EACA,YAAY,EAAE,aAAa,QAAQ;CACpC;CACA,OAAO;EACN,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY;EACb;EACA,YAAY,EAAE,aAAa,SAAS;CACrC;CACA,SAAS;EACR,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY;EACb;EACA,YAAY,EAAE,aAAa,OAAO;CACnC;CACA,UAAU;EACT,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY;EACb;EACA,YAAY,EAAE,aAAa,OAAO;CACnC;AACD;AACA,MAAM,yBAAyB;CAC9B,MAAM;CACN,IAAI;CACJ,UAAU;CACV,UAAU;CACV,SAAS;CACT,WAAW,EAAE,MAAM,0BAA0B;CAC7C,OAAO,EAAE,YAAY;EACpB,QAAQ;GACP,SAAS;GACT,OAAO;GACP,OAAO;EACR;EACA,aAAa,CAAC;GACb,SAAS;GACT,OAAO;GACP,OAAO;EACR,CAAC;CACF,EAAE;CACF,OAAO,QAAQ;EACd,OAAO,IAAI,wBAAwB;CACpC;AACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as buildStandardCodecRegistry } from "./codecs-
|
|
2
|
-
import { t as createMongoAdapter } from "./mongo-adapter-
|
|
1
|
+
import { t as buildStandardCodecRegistry } from "./codecs-DHo_Ei21-DHvEom71.mjs";
|
|
2
|
+
import { t as createMongoAdapter } from "./mongo-adapter-BW-kRaXm-C3Sw9U9G.mjs";
|
|
3
3
|
import { timestampNowRuntimeGenerator } from "@prisma/orm-family-mongo/family/runtime";
|
|
4
4
|
//#region ../../../3-mongo-target/2-mongo-adapter/dist/runtime.mjs
|
|
5
5
|
const mongoRuntimeAdapterDescriptor = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter__runtime.mjs","names":[],"sources":["../../../../3-mongo-target/2-mongo-adapter/dist/runtime.mjs"],"sourcesContent":["import { t as createMongoAdapter } from \"./mongo-adapter-
|
|
1
|
+
{"version":3,"file":"adapter__runtime.mjs","names":[],"sources":["../../../../3-mongo-target/2-mongo-adapter/dist/runtime.mjs"],"sourcesContent":["import { t as createMongoAdapter } from \"./mongo-adapter-BW-kRaXm.mjs\";\nimport { buildStandardCodecRegistry } from \"@internal/target-mongo/codecs\";\nimport { timestampNowRuntimeGenerator } from \"@internal/family-mongo/runtime\";\n//#region src/exports/runtime.ts\nconst mongoRuntimeAdapterDescriptor = {\n\tkind: \"adapter\",\n\tid: \"mongo\",\n\tfamilyId: \"mongo\",\n\ttargetId: \"mongo\",\n\tversion: \"0.0.1\",\n\tcodecs: buildStandardCodecRegistry,\n\tmutationDefaultGenerators: () => [timestampNowRuntimeGenerator()],\n\tcreate(_stack) {\n\t\tconst adapter = createMongoAdapter();\n\t\treturn {\n\t\t\tfamilyId: \"mongo\",\n\t\t\ttargetId: \"mongo\",\n\t\t\tlower: adapter.lower.bind(adapter),\n\t\t\tstructuralLower: adapter.structuralLower.bind(adapter),\n\t\t\tresolveParams: adapter.resolveParams.bind(adapter)\n\t\t};\n\t}\n};\n//#endregion\nexport { mongoRuntimeAdapterDescriptor as default };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;AAIA,MAAM,gCAAgC;CACrC,MAAM;CACN,IAAI;CACJ,UAAU;CACV,UAAU;CACV,SAAS;CACT,QAAQ;CACR,iCAAiC,CAAC,6BAA6B,CAAC;CAChE,OAAO,QAAQ;EACd,MAAM,UAAU,mBAAmB;EACnC,OAAO;GACN,UAAU;GACV,UAAU;GACV,OAAO,QAAQ,MAAM,KAAK,OAAO;GACjC,iBAAiB,QAAQ,gBAAgB,KAAK,OAAO;GACrD,eAAe,QAAQ,cAAc,KAAK,OAAO;EAClD;CACD;AACD"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { a as MONGO_DECIMAL128_CODEC_ID, c as MONGO_INT64_CODEC_ID, d as MONGO_OBJECTID_CODEC_ID, f as MONGO_STRING_CODEC_ID, i as MONGO_DATE_CODEC_ID, l as MONGO_INT64_NUMBER_CODEC_ID, n as MONGO_BOOLEAN_CODEC_ID, o as MONGO_DOUBLE_CODEC_ID, p as MONGO_VECTOR_CODEC_ID, r as MONGO_BSON_CODEC_ID, s as MONGO_INT32_CODEC_ID, t as MONGO_BINARY_CODEC_ID, u as MONGO_JSON_CODEC_ID } from "./codec-ids-WdrumsYA-BkQfspmL.mjs";
|
|
2
2
|
import { a as mongoDate, c as mongoInt32, d as mongoObjectId, f as mongoString, l as mongoInt64, n as mongoBool, o as mongoDecimal128, p as mongoVector, r as mongoBson, s as mongoDouble, t as mongoBinary, u as mongoJson } from "./data-types-qKwvSozp-De9Y09D3.mjs";
|
|
3
|
-
import { renderTsLiteral } from "@prisma/orm-framework/components/codec";
|
|
3
|
+
import { INT32_RANGE, INT64_RANGE, SAFE_INTEGER_BIGINT_RANGE, SAFE_INTEGER_RANGE, decodeJsonBoolean, decodeJsonFloat, decodeJsonInteger, decodeJsonIntegerText, decodeJsonMatching, decodeJsonString, encodeJsonFloat, isIntegerIn, refuseJsonValue, renderTsLiteral } from "@prisma/orm-framework/components/codec";
|
|
4
4
|
import { mongoCodec, newMongoCodecRegistry } from "@prisma/orm-family-mongo/codec";
|
|
5
5
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
6
6
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
7
|
+
import { isDeepStrictEqual } from "node:util";
|
|
7
8
|
import { Binary, Code, Decimal128, Double, EJSON, Long, MinKey, ObjectId } from "bson";
|
|
8
9
|
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
9
|
-
//#region ../../../3-mongo-target/1-mongo-target/dist/codecs-
|
|
10
|
+
//#region ../../../3-mongo-target/1-mongo-target/dist/codecs-DHo_Ei21.mjs
|
|
10
11
|
function where(path) {
|
|
11
12
|
return path === "" ? "the root" : path;
|
|
12
13
|
}
|
|
@@ -148,10 +149,8 @@ function decodeValue$1(value) {
|
|
|
148
149
|
function decodeBsonValue(wire) {
|
|
149
150
|
return blindCast(decodeValue$1(wire));
|
|
150
151
|
}
|
|
151
|
-
const INT32_MIN$1 = -(2 ** 31);
|
|
152
|
-
const INT32_MAX$1 = 2 ** 31 - 1;
|
|
153
152
|
function asDriverWrites(value) {
|
|
154
|
-
if (typeof value === "number") return Number.isInteger(value) && (value <
|
|
153
|
+
if (typeof value === "number") return Number.isInteger(value) && (value < INT32_RANGE.min || value > INT32_RANGE.max) ? new Double(value) : value;
|
|
155
154
|
if (typeof value !== "object" || value === null) return value;
|
|
156
155
|
if (value instanceof Uint8Array) return new Binary(value);
|
|
157
156
|
if (Array.isArray(value)) return value.map(asDriverWrites);
|
|
@@ -166,8 +165,18 @@ function asDriverWrites(value) {
|
|
|
166
165
|
function encodeBsonJson(value) {
|
|
167
166
|
return blindCast(EJSON.serialize(asDriverWrites(value), { relaxed: false }));
|
|
168
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Reads the canonical Extended JSON `encodeBsonJson` writes. The `bson` reader also takes forms that are not canonical, some of them silently wrong (`{ "$numberInt": "abc" }` reads as 0), so a value that does not write back to the same JSON is refused.
|
|
170
|
+
*/
|
|
169
171
|
function decodeBsonJson(json) {
|
|
170
|
-
|
|
172
|
+
let value;
|
|
173
|
+
try {
|
|
174
|
+
value = EJSON.deserialize(blindCast(json), { relaxed: false });
|
|
175
|
+
} catch {
|
|
176
|
+
return refuseJsonValue(MONGO_BSON_CODEC_ID, "canonical Extended JSON", json);
|
|
177
|
+
}
|
|
178
|
+
if (!isDeepStrictEqual(EJSON.serialize(value, { relaxed: false }), json)) return refuseJsonValue(MONGO_BSON_CODEC_ID, "canonical Extended JSON", json);
|
|
179
|
+
return value;
|
|
171
180
|
}
|
|
172
181
|
const DECIMAL_INTEGER = /^-?\d+$/;
|
|
173
182
|
const CANONICAL_DECIMAL_TEXT = /^(?:-?\d+(?:\.\d+)?|NaN|-?Infinity)$/;
|
|
@@ -228,12 +237,12 @@ function dateEncode(codecId, value) {
|
|
|
228
237
|
if (!(value instanceof Date) || Number.isNaN(value.getTime())) refuseType(codecId, "a valid Date", value);
|
|
229
238
|
return value;
|
|
230
239
|
}
|
|
231
|
-
const
|
|
240
|
+
const OBJECT_ID_TEXT = /^[0-9a-fA-F]{24}$/;
|
|
232
241
|
function hexStringOf(value) {
|
|
233
242
|
const toHexString = Reflect.get(value, "toHexString");
|
|
234
243
|
if (typeof toHexString !== "function") return void 0;
|
|
235
244
|
const hex = Reflect.apply(toHexString, value, []);
|
|
236
|
-
return typeof hex === "string" &&
|
|
245
|
+
return typeof hex === "string" && OBJECT_ID_TEXT.test(hex) ? hex : void 0;
|
|
237
246
|
}
|
|
238
247
|
/**
|
|
239
248
|
* `new ObjectId(...)` makes a fresh id from `null` or `undefined` and reads a number as a timestamp, so only a string, which the constructor accepts only as 24 hex digits, or an `ObjectId` is passed to it. An `ObjectId` is rebuilt from its hex string, so one from any major version of `bson` works.
|
|
@@ -261,19 +270,50 @@ function doubleEncode(codecId, value) {
|
|
|
261
270
|
if (typeof value !== "number") encodeFailed(codecId, `value must be a number; received ${describeReceived(value)}`, value);
|
|
262
271
|
return new Double(value);
|
|
263
272
|
}
|
|
264
|
-
const INT32_MIN = -(2 ** 31);
|
|
265
|
-
const INT32_MAX = 2 ** 31 - 1;
|
|
266
273
|
function int32Encode(codecId, value) {
|
|
267
|
-
if (
|
|
274
|
+
if (!isIntegerIn(value, INT32_RANGE)) encodeFailed(codecId, `value must be an integer from ${INT32_RANGE.min} to ${INT32_RANGE.max}; received ${describeReceived(value)}`, value);
|
|
275
|
+
return value;
|
|
276
|
+
}
|
|
277
|
+
function objectIdEncodeJson(codecId, value) {
|
|
278
|
+
if (typeof value !== "string" || !OBJECT_ID_TEXT.test(value)) encodeFailed(codecId, "value must be 24 hexadecimal digits", value);
|
|
279
|
+
return value;
|
|
280
|
+
}
|
|
281
|
+
function objectIdDecodeJson(codecId, json) {
|
|
282
|
+
return decodeJsonMatching(codecId, json, OBJECT_ID_TEXT, "24 hexadecimal digits");
|
|
283
|
+
}
|
|
284
|
+
function int32EncodeJson(codecId, value) {
|
|
285
|
+
if (!isIntegerIn(value, INT32_RANGE)) encodeFailed(codecId, `value must be an integer from ${INT32_RANGE.min} to ${INT32_RANGE.max}`, value);
|
|
268
286
|
return value;
|
|
269
287
|
}
|
|
270
|
-
|
|
271
|
-
|
|
288
|
+
function int32DecodeJson(codecId, json) {
|
|
289
|
+
return decodeJsonInteger(codecId, json, INT32_RANGE);
|
|
290
|
+
}
|
|
291
|
+
function dateEncodeJson(codecId, value) {
|
|
292
|
+
if (!(value instanceof Date) || Number.isNaN(value.getTime())) encodeFailed(codecId, "value must be a valid Date", value);
|
|
293
|
+
return value.toISOString();
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The JSON form is the text `Date.toISOString()` writes, so a string that does not read back to that same text is refused.
|
|
297
|
+
*/
|
|
298
|
+
function dateDecodeJson(codecId, json) {
|
|
299
|
+
const date = typeof json === "string" ? new Date(json) : void 0;
|
|
300
|
+
if (date === void 0 || Number.isNaN(date.getTime()) || date.toISOString() !== json) return refuseJsonValue(codecId, "a date and time in UTC as Date.toISOString writes it", json);
|
|
301
|
+
return date;
|
|
302
|
+
}
|
|
303
|
+
function vectorDecodeJson(codecId, json) {
|
|
304
|
+
if (!Array.isArray(json)) return refuseJsonValue(codecId, "an array of numbers", json);
|
|
305
|
+
const numbers = [];
|
|
306
|
+
for (const element of json) {
|
|
307
|
+
if (typeof element !== "number") return refuseJsonValue(codecId, "an array of numbers", element);
|
|
308
|
+
numbers.push(element);
|
|
309
|
+
}
|
|
310
|
+
return numbers;
|
|
311
|
+
}
|
|
272
312
|
/**
|
|
273
313
|
* `Long.fromBigInt` keeps the low 64 bits of any bigint, so an out-of-range value would be stored as a different number without error.
|
|
274
314
|
*/
|
|
275
315
|
function isInt64(value) {
|
|
276
|
-
return value >=
|
|
316
|
+
return value >= INT64_RANGE.min && value <= INT64_RANGE.max;
|
|
277
317
|
}
|
|
278
318
|
function requireInt64(codecId, value) {
|
|
279
319
|
if (!isInt64(value)) encodeFailed(codecId, "value is outside the signed 64-bit range", value);
|
|
@@ -308,36 +348,32 @@ function int64EncodeJson(codecId, value) {
|
|
|
308
348
|
return encodeFailed(codecId, "value must be a bigint or a safe integer", value);
|
|
309
349
|
}
|
|
310
350
|
function int64DecodeJson(codecId, json) {
|
|
311
|
-
|
|
312
|
-
const value = BigInt(json);
|
|
313
|
-
if (!isInt64(value)) return decodeFailed(codecId, "JSON value is outside the signed 64-bit range", json);
|
|
314
|
-
return value;
|
|
351
|
+
return decodeJsonIntegerText(codecId, json, INT64_RANGE);
|
|
315
352
|
}
|
|
316
|
-
const
|
|
353
|
+
const SAFE_INTEGERS = `from ${SAFE_INTEGER_RANGE.min} to ${SAFE_INTEGER_RANGE.max}`;
|
|
317
354
|
function int64NumberEncode(codecId, value) {
|
|
318
|
-
if (!
|
|
355
|
+
if (!isIntegerIn(value, SAFE_INTEGER_RANGE)) encodeFailed(codecId, `value must be an integer ${SAFE_INTEGERS}; received ${describeReceived(value)}`, value);
|
|
319
356
|
return Long.fromNumber(value);
|
|
320
357
|
}
|
|
321
|
-
function safeIntegerOf(codecId,
|
|
322
|
-
if (value <
|
|
358
|
+
function safeIntegerOf(codecId, value) {
|
|
359
|
+
if (value < SAFE_INTEGER_BIGINT_RANGE.min || value > SAFE_INTEGER_BIGINT_RANGE.max) decodeFailed(codecId, `wire value must be a whole number ${SAFE_INTEGERS}; received ${value}`, value);
|
|
323
360
|
return Number(value);
|
|
324
361
|
}
|
|
325
362
|
/**
|
|
326
363
|
* The driver hands a stored `long` over as a `number` when it fits in 53 bits (the default `promoteLongs`), as a `Long` otherwise or with `promoteLongs: false`, and as a `bigint` with `useBigInt64`.
|
|
327
364
|
*/
|
|
328
365
|
function int64NumberDecode(codecId, wire) {
|
|
329
|
-
if (typeof wire === "bigint") return safeIntegerOf(codecId,
|
|
330
|
-
if (isLong(wire)) return safeIntegerOf(codecId,
|
|
331
|
-
if (
|
|
366
|
+
if (typeof wire === "bigint") return safeIntegerOf(codecId, wire);
|
|
367
|
+
if (isLong(wire)) return safeIntegerOf(codecId, wire.toBigInt());
|
|
368
|
+
if (isIntegerIn(wire, SAFE_INTEGER_RANGE)) return wire;
|
|
332
369
|
if (typeof wire === "number" && Number.isFinite(wire) && !Number.isInteger(wire)) return refuseFractionalDouble(codecId, wire);
|
|
333
|
-
return decodeFailed(codecId, `wire value must be a whole number ${
|
|
370
|
+
return decodeFailed(codecId, `wire value must be a whole number ${SAFE_INTEGERS}; received ${describeReceived(wire)}`, wire);
|
|
334
371
|
}
|
|
335
372
|
function int64NumberEncodeJson(codecId, value) {
|
|
336
373
|
return int64NumberEncode(codecId, value).toString();
|
|
337
374
|
}
|
|
338
375
|
function int64NumberDecodeJson(codecId, json) {
|
|
339
|
-
|
|
340
|
-
return safeIntegerOf(codecId, "JSON value", BigInt(json));
|
|
376
|
+
return Number(decodeJsonIntegerText(codecId, json, SAFE_INTEGER_BIGINT_RANGE));
|
|
341
377
|
}
|
|
342
378
|
function decimalTextNumberLiteral(value) {
|
|
343
379
|
return typeof value === "string" && DECIMAL_INTEGER.test(value) ? value : void 0;
|
|
@@ -396,13 +432,14 @@ function decimal128EncodeJson(codecId, value) {
|
|
|
396
432
|
* The JSON form is what `encodeJson` writes, so it follows the encode rule: canonical decimal text (no exponent), or `NaN`, `Infinity` or `-Infinity`, that a Decimal128 holds exactly.
|
|
397
433
|
*/
|
|
398
434
|
function decimal128DecodeJson(codecId, json) {
|
|
399
|
-
|
|
435
|
+
const expected = "decimal text without an exponent that a Decimal128 holds exactly, or NaN, Infinity or -Infinity";
|
|
436
|
+
const text = decodeJsonMatching(codecId, json, CANONICAL_DECIMAL_TEXT, expected);
|
|
400
437
|
try {
|
|
401
|
-
Decimal128.fromString(
|
|
438
|
+
Decimal128.fromString(text);
|
|
402
439
|
} catch {
|
|
403
|
-
return
|
|
440
|
+
return refuseJsonValue(codecId, expected, json);
|
|
404
441
|
}
|
|
405
|
-
return
|
|
442
|
+
return text;
|
|
406
443
|
}
|
|
407
444
|
function binaryEncode(codecId, value) {
|
|
408
445
|
if (!(value instanceof Uint8Array)) encodeFailed(codecId, "value must be a Uint8Array", value);
|
|
@@ -420,8 +457,7 @@ function binaryEncodeJson(value) {
|
|
|
420
457
|
return Buffer.from(value).toString("base64");
|
|
421
458
|
}
|
|
422
459
|
function binaryDecodeJson(codecId, json) {
|
|
423
|
-
|
|
424
|
-
return new Uint8Array(Buffer.from(json, "base64"));
|
|
460
|
+
return new Uint8Array(Buffer.from(decodeJsonMatching(codecId, json, BASE64_TEXT, "base64 text"), "base64"));
|
|
425
461
|
}
|
|
426
462
|
const BSON_TYPE_BY_TAG = {
|
|
427
463
|
ObjectId: "objectId",
|
|
@@ -562,45 +598,48 @@ function decodeJsonValue(wire) {
|
|
|
562
598
|
const mongoObjectIdCodec = mongoCodec({
|
|
563
599
|
typeId: MONGO_OBJECTID_CODEC_ID,
|
|
564
600
|
decode: (wire) => wire.toHexString(),
|
|
565
|
-
encode: (value) => objectIdEncode(MONGO_OBJECTID_CODEC_ID, value)
|
|
601
|
+
encode: (value) => objectIdEncode(MONGO_OBJECTID_CODEC_ID, value),
|
|
602
|
+
encodeJson: (value) => objectIdEncodeJson(MONGO_OBJECTID_CODEC_ID, value),
|
|
603
|
+
decodeJson: (json) => objectIdDecodeJson(MONGO_OBJECTID_CODEC_ID, json)
|
|
566
604
|
});
|
|
567
605
|
const mongoStringCodec = mongoCodec({
|
|
568
606
|
typeId: MONGO_STRING_CODEC_ID,
|
|
569
607
|
decode: (wire) => wire,
|
|
570
|
-
encode: (value) => stringEncode(MONGO_STRING_CODEC_ID, value)
|
|
608
|
+
encode: (value) => stringEncode(MONGO_STRING_CODEC_ID, value),
|
|
609
|
+
decodeJson: (json) => decodeJsonString(MONGO_STRING_CODEC_ID, json)
|
|
571
610
|
});
|
|
572
611
|
const mongoDoubleCodec = mongoCodec({
|
|
573
612
|
typeId: MONGO_DOUBLE_CODEC_ID,
|
|
574
613
|
decode: (wire) => Number(wire),
|
|
575
|
-
encode: (value) => doubleEncode(MONGO_DOUBLE_CODEC_ID, value)
|
|
614
|
+
encode: (value) => doubleEncode(MONGO_DOUBLE_CODEC_ID, value),
|
|
615
|
+
encodeJson: encodeJsonFloat,
|
|
616
|
+
decodeJson: (json) => decodeJsonFloat(MONGO_DOUBLE_CODEC_ID, json)
|
|
576
617
|
});
|
|
577
618
|
const mongoInt32Codec = mongoCodec({
|
|
578
619
|
typeId: MONGO_INT32_CODEC_ID,
|
|
579
620
|
decode: (wire) => wire,
|
|
580
|
-
encode: (value) => int32Encode(MONGO_INT32_CODEC_ID, value)
|
|
621
|
+
encode: (value) => int32Encode(MONGO_INT32_CODEC_ID, value),
|
|
622
|
+
encodeJson: (value) => int32EncodeJson(MONGO_INT32_CODEC_ID, value),
|
|
623
|
+
decodeJson: (json) => int32DecodeJson(MONGO_INT32_CODEC_ID, json)
|
|
581
624
|
});
|
|
582
625
|
const mongoBooleanCodec = mongoCodec({
|
|
583
626
|
typeId: MONGO_BOOLEAN_CODEC_ID,
|
|
584
627
|
decode: (wire) => wire,
|
|
585
|
-
encode: (value) => booleanEncode(MONGO_BOOLEAN_CODEC_ID, value)
|
|
628
|
+
encode: (value) => booleanEncode(MONGO_BOOLEAN_CODEC_ID, value),
|
|
629
|
+
decodeJson: (json) => decodeJsonBoolean(MONGO_BOOLEAN_CODEC_ID, json)
|
|
586
630
|
});
|
|
587
631
|
const mongoDateCodec = mongoCodec({
|
|
588
632
|
typeId: MONGO_DATE_CODEC_ID,
|
|
589
633
|
decode: (wire) => wire,
|
|
590
634
|
encode: (value) => dateEncode(MONGO_DATE_CODEC_ID, value),
|
|
591
|
-
encodeJson: (value) => value
|
|
592
|
-
decodeJson: (json) =>
|
|
593
|
-
if (typeof json !== "string") throw mongoTargetError("RUNTIME.DECODE_FAILED", "expected ISO date string", { meta: {
|
|
594
|
-
codecId: MONGO_DATE_CODEC_ID,
|
|
595
|
-
received: typeof json
|
|
596
|
-
} });
|
|
597
|
-
return new Date(json);
|
|
598
|
-
}
|
|
635
|
+
encodeJson: (value) => dateEncodeJson(MONGO_DATE_CODEC_ID, value),
|
|
636
|
+
decodeJson: (json) => dateDecodeJson(MONGO_DATE_CODEC_ID, json)
|
|
599
637
|
});
|
|
600
638
|
const mongoVectorCodec = mongoCodec({
|
|
601
639
|
typeId: MONGO_VECTOR_CODEC_ID,
|
|
602
640
|
decode: (wire) => wire,
|
|
603
|
-
encode: (value) => vectorEncode(MONGO_VECTOR_CODEC_ID, value)
|
|
641
|
+
encode: (value) => vectorEncode(MONGO_VECTOR_CODEC_ID, value),
|
|
642
|
+
decodeJson: (json) => vectorDecodeJson(MONGO_VECTOR_CODEC_ID, json)
|
|
604
643
|
});
|
|
605
644
|
/**
|
|
606
645
|
* A BSON `long`. The application value is a `bigint`, because a `number` cannot hold the full 64-bit range; its JSON form is decimal text.
|
|
@@ -736,7 +775,7 @@ const mongoCodecDescriptors = [
|
|
|
736
775
|
"numeric"
|
|
737
776
|
],
|
|
738
777
|
targetTypes: ["double"],
|
|
739
|
-
renderValueLiteral:
|
|
778
|
+
renderValueLiteral: (value) => typeof value === "number" ? String(value) : void 0
|
|
740
779
|
}),
|
|
741
780
|
descriptorFor(mongoInt32Codec, {
|
|
742
781
|
dataType: mongoInt32.id,
|
|
@@ -838,4 +877,4 @@ function buildStandardCodecRegistry() {
|
|
|
838
877
|
//#endregion
|
|
839
878
|
export { mongoTargetError as a, mongoStandardCodecs as i, mongoCodecDescriptors as n, mongoDescriptorById as r, buildStandardCodecRegistry as t };
|
|
840
879
|
|
|
841
|
-
//# sourceMappingURL=codecs-
|
|
880
|
+
//# sourceMappingURL=codecs-DHo_Ei21-DHvEom71.mjs.map
|