@prisma-next/adapter-mongo 0.5.0-dev.5 → 0.5.0-dev.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/control.d.mts +2 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +5 -12
- package/dist/control.mjs.map +1 -1
- package/dist/index.d.mts +16 -10
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -9
- package/dist/index.mjs.map +1 -1
- package/dist/{mongo-adapter-aVo8aZrf.mjs → mongo-adapter-ByNtvoHK.mjs} +164 -54
- package/dist/mongo-adapter-ByNtvoHK.mjs.map +1 -0
- package/dist/runtime.d.mts +26 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +25 -0
- package/dist/runtime.mjs.map +1 -0
- package/package.json +20 -17
- package/src/core/codecs.ts +44 -1
- package/src/core/operations.ts +3 -3
- package/src/core/runner-deps.ts +7 -1
- package/src/exports/control.ts +2 -18
- package/src/exports/runtime.ts +57 -0
- package/src/lowering.ts +46 -17
- package/src/mongo-adapter.ts +78 -58
- package/src/resolve-value.ts +97 -6
- package/dist/mongo-adapter-aVo8aZrf.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-adapter-ByNtvoHK.mjs","names":["result: Record<string, unknown>","entries: Array<[string, unknown]>","aggExprLoweringVisitor: MongoAggExprVisitor<unknown>","loweredArgs: unknown","vars: Record<string, unknown>","_exhaustive: never","result: Record<string, unknown>","projection: Record<string, unknown>","lookup: Record<string, unknown>","unwind: Record<string, unknown>","group: Record<string, unknown>","unionWith: Record<string, unknown>","bucket: Record<string, unknown>","bucketAuto: Record<string, unknown>","geoNear: Record<string, unknown>","facet: Record<string, unknown>","graphLookup: Record<string, unknown>","merge: Record<string, unknown>","swf: Record<string, unknown>","output: Record<string, unknown>","densify: Record<string, unknown>","fill: Record<string, unknown>","entry: Record<string, unknown>","search: Record<string, unknown>","searchMeta: Record<string, unknown>","vs: Record<string, unknown>","#codecs","#resolveDocument","result: Record<string, unknown>","#lowerUpdate","_exhaustive: never"],"sources":["../src/core/codec-ids.ts","../src/resolve-value.ts","../src/lowering.ts","../src/core/codecs.ts","../src/mongo-adapter.ts"],"sourcesContent":["export const MONGO_OBJECTID_CODEC_ID = 'mongo/objectId@1' as const;\nexport const MONGO_STRING_CODEC_ID = 'mongo/string@1' as const;\nexport const MONGO_DOUBLE_CODEC_ID = 'mongo/double@1' as const;\nexport const MONGO_INT32_CODEC_ID = 'mongo/int32@1' as const;\nexport const MONGO_BOOLEAN_CODEC_ID = 'mongo/bool@1' as const;\nexport const MONGO_DATE_CODEC_ID = 'mongo/date@1' as const;\nexport const MONGO_VECTOR_CODEC_ID = 'mongo/vector@1' as const;\n","import type { CodecCallContext } from '@prisma-next/framework-components/codec';\nimport {\n checkAborted,\n raceAgainstAbort,\n runtimeError,\n} from '@prisma-next/framework-components/runtime';\nimport type { MongoCodecRegistry } from '@prisma-next/mongo-codec';\nimport type { MongoValue } from '@prisma-next/mongo-value';\nimport { MongoParamRef } from '@prisma-next/mongo-value';\n\n/**\n * Resolves a `MongoValue` (which may contain `MongoParamRef` leaves) into the\n * driver-ready wire shape. When a leaf has a `codecId` and the registry has a\n * codec for it, the codec's async `encode` is awaited so codecs may perform\n * asynchronous work (e.g. lookups, key derivations).\n *\n * Object/array nodes dispatch their child resolutions concurrently via\n * `Promise.all` so independent leaves encode in parallel.\n *\n * Codec encode failures are wrapped in a `RUNTIME.ENCODE_FAILED` envelope\n * (mirroring SQL's `wrapEncodeFailure` shape) with `{ label, codec }` details\n * and the original error attached on `cause`. An already-wrapped envelope is\n * re-thrown verbatim so nested resolvers don't double-wrap.\n *\n * `ctx: CodecCallContext` is forwarded verbatim to every\n * `codec.encode(value, ctx)` call. The same `ctx` reference is also passed\n * to nested `resolveValue` invocations so codec authors observe **signal\n * identity** across the entire recursive walk for one `runtime.execute()`.\n *\n * Abort observation (only when `ctx.signal` is provided):\n *\n * - **Already-aborted at entry** — every recursive call pre-checks\n * `ctx.signal.aborted` and short-circuits with\n * `RUNTIME.ABORTED { phase: 'encode' }` before any codec is invoked.\n * - **Mid-flight abort** — each per-level `Promise.all` races against the\n * signal via `raceAgainstAbort`. The runtime returns\n * `RUNTIME.ABORTED { phase: 'encode' }` promptly even if codec bodies\n * ignore the signal; in-flight bodies run to completion in the background\n * (cooperative cancellation, see ADR 204).\n * - `RUNTIME.ENCODE_FAILED` envelopes thrown by a codec body before the\n * runtime sees the abort pass through unchanged (AC-ERR4).\n */\nexport async function resolveValue(\n value: MongoValue,\n codecs: MongoCodecRegistry,\n ctx: CodecCallContext,\n): Promise<unknown> {\n checkAborted(ctx, 'encode');\n const signal = ctx.signal;\n\n if (value instanceof MongoParamRef) {\n if (value.codecId) {\n const codec = codecs.get(value.codecId);\n if (codec?.encode) {\n try {\n // Race even leaf scalar encodes against the signal so a leaf\n // `MongoParamRef` (e.g. a simple field filter, or any leaf reached\n // from `MongoAdapterImpl.#resolveDocument()` outside an enclosing\n // `Promise.all`) surfaces `RUNTIME.ABORTED` promptly instead of\n // blocking on a slow codec body.\n const encoded = codec.encode(value.value, ctx);\n return await raceAgainstAbort(encoded, signal, 'encode');\n } catch (error) {\n wrapEncodeFailure(error, value, codec.id);\n }\n }\n }\n return value.value;\n }\n if (value === null || typeof value !== 'object') {\n return value;\n }\n if (value instanceof Date) {\n return value;\n }\n if (Array.isArray(value)) {\n const tasks = Promise.all(value.map((v) => resolveValue(v, codecs, ctx)));\n return raceAgainstAbort(tasks, signal, 'encode');\n }\n const entries = Object.entries(value);\n const all = Promise.all(entries.map(([, val]) => resolveValue(val, codecs, ctx)));\n const resolved = await raceAgainstAbort(all, signal, 'encode');\n const result: Record<string, unknown> = {};\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n if (entry) {\n result[entry[0]] = resolved[i];\n }\n }\n return result;\n}\n\nfunction paramRefLabel(ref: MongoParamRef, codecId: string): string {\n return ref.name ?? codecId;\n}\n\nfunction isAlreadyEncodeFailure(error: unknown): boolean {\n return (\n error instanceof Error &&\n 'code' in error &&\n (error as Error & { code?: unknown }).code === 'RUNTIME.ENCODE_FAILED'\n );\n}\n\nfunction wrapEncodeFailure(error: unknown, ref: MongoParamRef, codecId: string): never {\n if (isAlreadyEncodeFailure(error)) {\n throw error;\n }\n const label = paramRefLabel(ref, codecId);\n const message = error instanceof Error ? error.message : String(error);\n const wrapped = runtimeError(\n 'RUNTIME.ENCODE_FAILED',\n `Failed to encode parameter ${label} with codec '${codecId}': ${message}`,\n { label, codec: codecId },\n );\n wrapped.cause = error;\n throw wrapped;\n}\n","import type { CodecCallContext } from '@prisma-next/framework-components/codec';\nimport type { MongoCodecRegistry } from '@prisma-next/mongo-codec';\nimport type {\n MongoAggExpr,\n MongoAggExprVisitor,\n MongoFilterExpr,\n MongoGroupId,\n MongoPipelineStage,\n MongoProjectionValue,\n MongoWindowField,\n} from '@prisma-next/mongo-query-ast/execution';\nimport { isExprArray, isRecordArgs } from '@prisma-next/mongo-query-ast/execution';\nimport type { Document } from '@prisma-next/mongo-value';\nimport { resolveValue } from './resolve-value';\n\n// Biome flags `{ then: ... }` as a thenable object (noThenProperty). Build via Object.fromEntries to avoid.\nconst THEN_KEY = 'then';\n\nfunction condBranch(\n caseOrIf: MongoAggExpr,\n thenExpr: MongoAggExpr,\n elseExpr?: MongoAggExpr,\n): Record<string, unknown> {\n const entries: Array<[string, unknown]> = [\n [elseExpr ? 'if' : 'case', lowerAggExpr(caseOrIf)],\n [THEN_KEY, lowerAggExpr(thenExpr)],\n ];\n if (elseExpr) {\n entries.push(['else', lowerAggExpr(elseExpr)]);\n }\n return Object.fromEntries(entries);\n}\n\nconst aggExprLoweringVisitor: MongoAggExprVisitor<unknown> = {\n fieldRef(expr) {\n return `$${expr.path}`;\n },\n\n literal(expr) {\n return needsLiteralWrap(expr.value) ? { $literal: expr.value } : expr.value;\n },\n\n operator(expr) {\n const { args } = expr;\n let loweredArgs: unknown;\n if (isExprArray(args)) {\n loweredArgs = args.map((a) => lowerAggExpr(a));\n } else if (isRecordArgs(args)) {\n loweredArgs = lowerExprRecord(args);\n } else {\n loweredArgs = lowerAggExpr(args);\n }\n return { [expr.op]: loweredArgs };\n },\n\n accumulator(expr) {\n if (expr.arg === null) {\n return { [expr.op]: {} };\n }\n if (isRecordArgs(expr.arg)) {\n return { [expr.op]: lowerExprRecord(expr.arg) };\n }\n return { [expr.op]: lowerAggExpr(expr.arg) };\n },\n\n cond(expr) {\n return { $cond: condBranch(expr.condition, expr.then_, expr.else_) };\n },\n\n switch_(expr) {\n return {\n $switch: {\n branches: expr.branches.map((b) => condBranch(b.case_, b.then_)),\n default: lowerAggExpr(expr.default_),\n },\n };\n },\n\n filter(expr) {\n return {\n $filter: {\n input: lowerAggExpr(expr.input),\n cond: lowerAggExpr(expr.cond),\n as: expr.as,\n },\n };\n },\n\n map(expr) {\n return {\n $map: {\n input: lowerAggExpr(expr.input),\n in: lowerAggExpr(expr.in_),\n as: expr.as,\n },\n };\n },\n\n reduce(expr) {\n return {\n $reduce: {\n input: lowerAggExpr(expr.input),\n initialValue: lowerAggExpr(expr.initialValue),\n in: lowerAggExpr(expr.in_),\n },\n };\n },\n\n let_(expr) {\n const vars: Record<string, unknown> = {};\n for (const [key, val] of Object.entries(expr.vars)) {\n vars[key] = lowerAggExpr(val);\n }\n return { $let: { vars, in: lowerAggExpr(expr.in_) } };\n },\n\n mergeObjects(expr) {\n return { $mergeObjects: expr.exprs.map((e) => lowerAggExpr(e)) };\n },\n};\n\nfunction needsLiteralWrap(value: unknown): boolean {\n if (typeof value === 'string' && value.startsWith('$')) {\n return true;\n }\n if (Array.isArray(value)) {\n return value.some((v) => needsLiteralWrap(v));\n }\n if (value !== null && typeof value === 'object') {\n return Object.entries(value as Record<string, unknown>).some(\n ([k, v]) => k.startsWith('$') || needsLiteralWrap(v),\n );\n }\n return false;\n}\n\nexport function lowerAggExpr(expr: MongoAggExpr): unknown {\n return expr.accept(aggExprLoweringVisitor);\n}\n\nexport async function lowerFilter(\n filter: MongoFilterExpr,\n codecs: MongoCodecRegistry,\n ctx: CodecCallContext,\n): Promise<Document> {\n switch (filter.kind) {\n case 'field':\n return { [filter.field]: { [filter.op]: await resolveValue(filter.value, codecs, ctx) } };\n case 'and':\n return { $and: await Promise.all(filter.exprs.map((e) => lowerFilter(e, codecs, ctx))) };\n case 'or':\n return { $or: await Promise.all(filter.exprs.map((e) => lowerFilter(e, codecs, ctx))) };\n case 'not':\n return { $nor: [await lowerFilter(filter.expr, codecs, ctx)] };\n case 'exists':\n return { [filter.field]: { $exists: filter.exists } };\n case 'expr':\n return { $expr: lowerAggExpr(filter.aggExpr) };\n default: {\n const _exhaustive: never = filter;\n throw new Error(`Unhandled filter kind: ${(_exhaustive as MongoFilterExpr).kind}`);\n }\n }\n}\n\nfunction isAggExprNode(value: object): value is MongoAggExpr {\n return 'accept' in value && typeof value.accept === 'function';\n}\n\nfunction lowerGroupId(groupId: MongoGroupId): unknown {\n if (groupId === null) return null;\n if (isAggExprNode(groupId)) return lowerAggExpr(groupId);\n return lowerExprRecord(groupId);\n}\n\nfunction lowerExprRecord(\n fields: Readonly<Record<string, MongoAggExpr | ReadonlyArray<MongoAggExpr>>>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, val] of Object.entries(fields)) {\n if (Array.isArray(val)) {\n result[key] = val.map((v: MongoAggExpr) => lowerAggExpr(v));\n } else {\n result[key] = lowerAggExpr(val as MongoAggExpr);\n }\n }\n return result;\n}\n\nfunction lowerProjectionValue(value: MongoProjectionValue): unknown {\n if (typeof value === 'number') return value;\n return lowerAggExpr(value);\n}\n\nfunction lowerWindowField(wf: MongoWindowField): Record<string, unknown> {\n const lowered = lowerAggExpr(wf.operator);\n if (typeof lowered !== 'object' || lowered === null) {\n throw new Error('Window field operator must lower to an object');\n }\n const result: Record<string, unknown> = { ...lowered };\n if (wf.window) {\n result['window'] = { ...wf.window };\n }\n return result;\n}\n\nexport async function lowerStage(\n stage: MongoPipelineStage,\n codecs: MongoCodecRegistry,\n ctx: CodecCallContext,\n): Promise<Record<string, unknown>> {\n switch (stage.kind) {\n case 'match':\n return { $match: await lowerFilter(stage.filter, codecs, ctx) };\n case 'project': {\n const projection: Record<string, unknown> = {};\n for (const [key, val] of Object.entries(stage.projection)) {\n projection[key] = lowerProjectionValue(val);\n }\n return { $project: projection };\n }\n case 'sort':\n return { $sort: { ...stage.sort } };\n case 'limit':\n return { $limit: stage.limit };\n case 'skip':\n return { $skip: stage.skip };\n case 'lookup': {\n const lookup: Record<string, unknown> = {\n from: stage.from,\n as: stage.as,\n };\n if (stage.localField !== undefined) lookup['localField'] = stage.localField;\n if (stage.foreignField !== undefined) lookup['foreignField'] = stage.foreignField;\n if (stage.pipeline) {\n lookup['pipeline'] = await Promise.all(\n stage.pipeline.map((s) => lowerStage(s, codecs, ctx)),\n );\n }\n if (stage.let_) {\n lookup['let'] = lowerExprRecord(stage.let_);\n }\n return { $lookup: lookup };\n }\n case 'unwind': {\n const unwind: Record<string, unknown> = {\n path: stage.path,\n preserveNullAndEmptyArrays: stage.preserveNullAndEmptyArrays,\n };\n if (stage.includeArrayIndex !== undefined) {\n unwind['includeArrayIndex'] = stage.includeArrayIndex;\n }\n return { $unwind: unwind };\n }\n case 'group': {\n const group: Record<string, unknown> = { _id: lowerGroupId(stage.groupId) };\n for (const [key, acc] of Object.entries(stage.accumulators)) {\n group[key] = lowerAggExpr(acc);\n }\n return { $group: group };\n }\n case 'addFields':\n return { $addFields: lowerExprRecord(stage.fields) };\n case 'replaceRoot':\n return { $replaceRoot: { newRoot: lowerAggExpr(stage.newRoot) } };\n case 'count':\n return { $count: stage.field };\n case 'sortByCount':\n return { $sortByCount: lowerAggExpr(stage.expr) };\n case 'sample':\n return { $sample: { size: stage.size } };\n case 'redact':\n return { $redact: lowerAggExpr(stage.expr) };\n case 'out':\n return { $out: stage.db ? { db: stage.db, coll: stage.collection } : stage.collection };\n case 'unionWith': {\n const unionWith: Record<string, unknown> = { coll: stage.collection };\n if (stage.pipeline) {\n unionWith['pipeline'] = await Promise.all(\n stage.pipeline.map((s) => lowerStage(s, codecs, ctx)),\n );\n }\n return { $unionWith: unionWith };\n }\n case 'bucket': {\n const bucket: Record<string, unknown> = {\n groupBy: lowerAggExpr(stage.groupBy),\n boundaries: [...stage.boundaries],\n };\n if (stage.default_ !== undefined) bucket['default'] = stage.default_;\n if (stage.output) bucket['output'] = lowerExprRecord(stage.output);\n return { $bucket: bucket };\n }\n case 'bucketAuto': {\n const bucketAuto: Record<string, unknown> = {\n groupBy: lowerAggExpr(stage.groupBy),\n buckets: stage.buckets,\n };\n if (stage.output) bucketAuto['output'] = lowerExprRecord(stage.output);\n if (stage.granularity !== undefined) bucketAuto['granularity'] = stage.granularity;\n return { $bucketAuto: bucketAuto };\n }\n case 'geoNear': {\n const geoNear: Record<string, unknown> = {\n near: stage.near,\n distanceField: stage.distanceField,\n };\n if (stage.spherical !== undefined) geoNear['spherical'] = stage.spherical;\n if (stage.maxDistance !== undefined) geoNear['maxDistance'] = stage.maxDistance;\n if (stage.minDistance !== undefined) geoNear['minDistance'] = stage.minDistance;\n if (stage.query) geoNear['query'] = await lowerFilter(stage.query, codecs, ctx);\n if (stage.key !== undefined) geoNear['key'] = stage.key;\n if (stage.distanceMultiplier !== undefined)\n geoNear['distanceMultiplier'] = stage.distanceMultiplier;\n if (stage.includeLocs !== undefined) geoNear['includeLocs'] = stage.includeLocs;\n return { $geoNear: geoNear };\n }\n case 'facet': {\n const facetEntries = Object.entries(stage.facets);\n const facetPipelines = await Promise.all(\n facetEntries.map(([, pipeline]) =>\n Promise.all(pipeline.map((s) => lowerStage(s, codecs, ctx))),\n ),\n );\n const facet: Record<string, unknown> = {};\n for (let i = 0; i < facetEntries.length; i++) {\n const entry = facetEntries[i];\n if (entry) {\n facet[entry[0]] = facetPipelines[i];\n }\n }\n return { $facet: facet };\n }\n case 'graphLookup': {\n const graphLookup: Record<string, unknown> = {\n from: stage.from,\n startWith: lowerAggExpr(stage.startWith),\n connectFromField: stage.connectFromField,\n connectToField: stage.connectToField,\n as: stage.as,\n };\n if (stage.maxDepth !== undefined) graphLookup['maxDepth'] = stage.maxDepth;\n if (stage.depthField !== undefined) graphLookup['depthField'] = stage.depthField;\n if (stage.restrictSearchWithMatch)\n graphLookup['restrictSearchWithMatch'] = await lowerFilter(\n stage.restrictSearchWithMatch,\n codecs,\n ctx,\n );\n return { $graphLookup: graphLookup };\n }\n case 'merge': {\n const merge: Record<string, unknown> = { into: stage.into };\n if (stage.on !== undefined) merge['on'] = stage.on;\n if (stage.whenMatched !== undefined) {\n merge['whenMatched'] = Array.isArray(stage.whenMatched)\n ? await Promise.all(stage.whenMatched.map((s) => lowerStage(s, codecs, ctx)))\n : stage.whenMatched;\n }\n if (stage.whenNotMatched !== undefined) merge['whenNotMatched'] = stage.whenNotMatched;\n return { $merge: merge };\n }\n case 'setWindowFields': {\n const swf: Record<string, unknown> = {};\n if (stage.partitionBy) swf['partitionBy'] = lowerAggExpr(stage.partitionBy);\n if (stage.sortBy) swf['sortBy'] = { ...stage.sortBy };\n const output: Record<string, unknown> = {};\n for (const [key, wf] of Object.entries(stage.output)) {\n output[key] = lowerWindowField(wf);\n }\n swf['output'] = output;\n return { $setWindowFields: swf };\n }\n case 'densify': {\n const densify: Record<string, unknown> = {\n field: stage.field,\n range: { ...stage.range },\n };\n if (stage.partitionByFields) densify['partitionByFields'] = [...stage.partitionByFields];\n return { $densify: densify };\n }\n case 'fill': {\n const fill: Record<string, unknown> = {};\n if (stage.partitionBy) fill['partitionBy'] = lowerAggExpr(stage.partitionBy);\n if (stage.partitionByFields) fill['partitionByFields'] = [...stage.partitionByFields];\n if (stage.sortBy) fill['sortBy'] = { ...stage.sortBy };\n const output: Record<string, unknown> = {};\n for (const [key, fo] of Object.entries(stage.output)) {\n const entry: Record<string, unknown> = {};\n if (fo.method !== undefined) entry['method'] = fo.method;\n if (fo.value !== undefined) entry['value'] = lowerAggExpr(fo.value);\n output[key] = entry;\n }\n fill['output'] = output;\n return { $fill: fill };\n }\n case 'search': {\n const search: Record<string, unknown> = { ...stage.config };\n if (stage.index !== undefined) search['index'] = stage.index;\n return { $search: search };\n }\n case 'searchMeta': {\n const searchMeta: Record<string, unknown> = { ...stage.config };\n if (stage.index !== undefined) searchMeta['index'] = stage.index;\n return { $searchMeta: searchMeta };\n }\n case 'vectorSearch': {\n const vs: Record<string, unknown> = {\n index: stage.index,\n path: stage.path,\n queryVector: [...stage.queryVector],\n numCandidates: stage.numCandidates,\n limit: stage.limit,\n };\n if (stage.filter) vs['filter'] = { ...stage.filter };\n return { $vectorSearch: vs };\n }\n default: {\n const _exhaustive: never = stage;\n throw new Error(`Unhandled stage kind: ${(_exhaustive as MongoPipelineStage).kind}`);\n }\n }\n}\n\nexport async function lowerPipeline(\n stages: ReadonlyArray<MongoPipelineStage>,\n codecs: MongoCodecRegistry,\n ctx: CodecCallContext,\n): Promise<Array<Record<string, unknown>>> {\n return Promise.all(stages.map((s) => lowerStage(s, codecs, ctx)));\n}\n","import {\n createMongoCodecRegistry,\n type MongoCodecRegistry,\n mongoCodec,\n} from '@prisma-next/mongo-codec';\nimport { ObjectId } from 'mongodb';\nimport {\n MONGO_BOOLEAN_CODEC_ID,\n MONGO_DATE_CODEC_ID,\n MONGO_DOUBLE_CODEC_ID,\n MONGO_INT32_CODEC_ID,\n MONGO_OBJECTID_CODEC_ID,\n MONGO_STRING_CODEC_ID,\n MONGO_VECTOR_CODEC_ID,\n} from './codec-ids';\n\nexport const mongoObjectIdCodec = mongoCodec({\n typeId: MONGO_OBJECTID_CODEC_ID,\n targetTypes: ['objectId'],\n traits: ['equality'],\n decode: (wire: ObjectId) => wire.toHexString(),\n encode: (value: string) => new ObjectId(value),\n});\n\nexport const mongoStringCodec = mongoCodec({\n typeId: MONGO_STRING_CODEC_ID,\n targetTypes: ['string'],\n traits: ['equality', 'order', 'textual'],\n decode: (wire: string) => wire,\n encode: (value: string) => value,\n});\n\nexport const mongoDoubleCodec = mongoCodec({\n typeId: MONGO_DOUBLE_CODEC_ID,\n targetTypes: ['double'],\n traits: ['equality', 'order', 'numeric'],\n decode: (wire: number) => wire,\n encode: (value: number) => value,\n});\n\nexport const mongoInt32Codec = mongoCodec({\n typeId: MONGO_INT32_CODEC_ID,\n targetTypes: ['int'],\n traits: ['equality', 'order', 'numeric'],\n decode: (wire: number) => wire,\n encode: (value: number) => value,\n});\n\nexport const mongoBooleanCodec = mongoCodec({\n typeId: MONGO_BOOLEAN_CODEC_ID,\n targetTypes: ['bool'],\n traits: ['equality', 'boolean'],\n decode: (wire: boolean) => wire,\n encode: (value: boolean) => value,\n});\n\nexport const mongoDateCodec = mongoCodec({\n typeId: MONGO_DATE_CODEC_ID,\n targetTypes: ['date'],\n traits: ['equality', 'order'],\n decode: (wire: Date) => wire,\n encode: (value: Date) => value,\n encodeJson: (value: Date) => value.toISOString(),\n decodeJson: (json) => {\n if (typeof json !== 'string') throw new Error('expected ISO date string');\n return new Date(json);\n },\n});\n\nexport const mongoVectorCodec = mongoCodec({\n typeId: MONGO_VECTOR_CODEC_ID,\n targetTypes: ['vector'],\n traits: ['equality'],\n decode: (wire: readonly number[]) => wire,\n encode: (value: readonly number[]) => value,\n renderOutputType: (typeParams) => {\n const length = typeParams['length'];\n if (length === undefined) return undefined;\n if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {\n throw new Error('renderOutputType: expected positive integer \"length\" for Vector');\n }\n return `Vector<${length}>`;\n },\n});\n\n/**\n * The canonical set of Mongo wire-type codecs.\n *\n * Single source of truth for both control- and runtime-plane adapter\n * descriptors. Don't duplicate this list — import it.\n */\nexport const mongoStandardCodecs = [\n mongoObjectIdCodec,\n mongoStringCodec,\n mongoDoubleCodec,\n mongoInt32Codec,\n mongoBooleanCodec,\n mongoDateCodec,\n mongoVectorCodec,\n] as const;\n\n/**\n * Build a {@link MongoCodecRegistry} preloaded with the standard Mongo\n * wire-type codecs.\n *\n * Single point of truth for adapter-side codec construction: used by the\n * legacy synchronous `createMongoAdapter()` factory and by the runtime\n * adapter descriptor's `codecs()` getter. Userland code obtains a registry\n * via the framework's execution-stack composition (see\n * `createMongoExecutionContext`) instead of calling this directly.\n */\nexport function buildStandardCodecRegistry(): MongoCodecRegistry {\n const registry = createMongoCodecRegistry();\n for (const codec of mongoStandardCodecs) {\n registry.register(codec);\n }\n return registry;\n}\n","import type { CodecCallContext } from '@prisma-next/framework-components/codec';\nimport type { MongoCodecRegistry } from '@prisma-next/mongo-codec';\nimport type { MongoAdapter } from '@prisma-next/mongo-lowering';\nimport type {\n MongoQueryPlan,\n MongoUpdatePipelineStage,\n MongoUpdateSpec,\n} from '@prisma-next/mongo-query-ast/execution';\nimport type { Document, MongoExpr } from '@prisma-next/mongo-value';\nimport type { AnyMongoWireCommand } from '@prisma-next/mongo-wire';\nimport {\n AggregateWireCommand,\n DeleteManyWireCommand,\n DeleteOneWireCommand,\n FindOneAndDeleteWireCommand,\n FindOneAndUpdateWireCommand,\n InsertManyWireCommand,\n InsertOneWireCommand,\n UpdateManyWireCommand,\n UpdateOneWireCommand,\n} from '@prisma-next/mongo-wire';\nimport { buildStandardCodecRegistry } from './core/codecs';\nimport { lowerFilter, lowerPipeline, lowerStage } from './lowering';\nimport { resolveValue } from './resolve-value';\n\nfunction isUpdatePipeline(\n update: MongoUpdateSpec,\n): update is ReadonlyArray<MongoUpdatePipelineStage> {\n return Array.isArray(update);\n}\n\nclass MongoAdapterImpl implements MongoAdapter {\n readonly #codecs: MongoCodecRegistry;\n\n constructor(codecs: MongoCodecRegistry) {\n this.#codecs = codecs;\n }\n\n async #resolveDocument(expr: MongoExpr, ctx: CodecCallContext): Promise<Document> {\n const entries = Object.entries(expr);\n const resolved = await Promise.all(\n entries.map(([, val]) => resolveValue(val, this.#codecs, ctx)),\n );\n const result: Record<string, unknown> = {};\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n if (entry) {\n result[entry[0]] = resolved[i];\n }\n }\n return result;\n }\n\n async #lowerUpdate(\n update: MongoUpdateSpec,\n ctx: CodecCallContext,\n ): Promise<Document | ReadonlyArray<Document>> {\n if (isUpdatePipeline(update)) {\n return Promise.all(update.map((stage) => lowerStage(stage, this.#codecs, ctx)));\n }\n return this.#resolveDocument(update, ctx);\n }\n\n async lower(plan: MongoQueryPlan, ctx: CodecCallContext): Promise<AnyMongoWireCommand> {\n const { command } = plan;\n switch (command.kind) {\n case 'insertOne':\n return new InsertOneWireCommand(\n command.collection,\n await this.#resolveDocument(command.document, ctx),\n );\n case 'updateOne': {\n const [filter, update] = await Promise.all([\n lowerFilter(command.filter, this.#codecs, ctx),\n this.#lowerUpdate(command.update, ctx),\n ]);\n return new UpdateOneWireCommand(command.collection, filter, update, command.upsert);\n }\n case 'insertMany':\n return new InsertManyWireCommand(\n command.collection,\n await Promise.all(command.documents.map((doc) => this.#resolveDocument(doc, ctx))),\n );\n case 'updateMany': {\n const [filter, update] = await Promise.all([\n lowerFilter(command.filter, this.#codecs, ctx),\n this.#lowerUpdate(command.update, ctx),\n ]);\n return new UpdateManyWireCommand(command.collection, filter, update, command.upsert);\n }\n case 'deleteOne':\n return new DeleteOneWireCommand(\n command.collection,\n await lowerFilter(command.filter, this.#codecs, ctx),\n );\n case 'deleteMany':\n return new DeleteManyWireCommand(\n command.collection,\n await lowerFilter(command.filter, this.#codecs, ctx),\n );\n case 'findOneAndUpdate': {\n const [filter, update] = await Promise.all([\n lowerFilter(command.filter, this.#codecs, ctx),\n this.#lowerUpdate(command.update, ctx),\n ]);\n return new FindOneAndUpdateWireCommand(\n command.collection,\n filter,\n update,\n command.upsert,\n command.sort,\n command.returnDocument,\n );\n }\n case 'findOneAndDelete':\n return new FindOneAndDeleteWireCommand(\n command.collection,\n await lowerFilter(command.filter, this.#codecs, ctx),\n command.sort,\n );\n case 'aggregate':\n return new AggregateWireCommand(\n command.collection,\n await lowerPipeline(command.pipeline, this.#codecs, ctx),\n );\n case 'rawAggregate':\n return new AggregateWireCommand(command.collection, command.pipeline);\n case 'rawInsertOne':\n return new InsertOneWireCommand(command.collection, command.document);\n case 'rawInsertMany':\n return new InsertManyWireCommand(command.collection, command.documents);\n case 'rawUpdateOne':\n return new UpdateOneWireCommand(command.collection, command.filter, command.update);\n case 'rawUpdateMany':\n return new UpdateManyWireCommand(command.collection, command.filter, command.update);\n case 'rawDeleteOne':\n return new DeleteOneWireCommand(command.collection, command.filter);\n case 'rawDeleteMany':\n return new DeleteManyWireCommand(command.collection, command.filter);\n case 'rawFindOneAndUpdate':\n return new FindOneAndUpdateWireCommand(\n command.collection,\n command.filter,\n command.update,\n command.upsert,\n command.sort,\n command.returnDocument,\n );\n case 'rawFindOneAndDelete':\n return new FindOneAndDeleteWireCommand(command.collection, command.filter, command.sort);\n // v8 ignore next 4\n default: {\n const _exhaustive: never = command;\n throw new Error(`Unknown command kind: ${(_exhaustive as { kind: string }).kind}`);\n }\n }\n }\n}\n\n/**\n * Construct a Mongo adapter with the standard wire-type codecs registered\n * for encode-side dispatch (`MongoParamRef.codecId` lookups).\n *\n * The runtime-side codec registry the runtime decodes against is composed\n * separately by `createMongoExecutionContext`. This factory exists for\n * direct adapter use (the runtime descriptor's `create(stack)` calls\n * through it). User code should compose a stack/context instead.\n */\nexport function createMongoAdapter(): MongoAdapter {\n return new MongoAdapterImpl(buildStandardCodecRegistry());\n}\n\n/**\n * Internal escape hatch — direct adapter construction with a caller-supplied\n * codec registry, used only by adapter unit tests that exercise the\n * encode-side codec-dispatch path with synthetic codecs. Not re-exported\n * from the package's public surface and not for production use; production\n * callers compose a `MongoExecutionStack` and `MongoExecutionContext`.\n */\nexport function _unstable_createMongoAdapterWithCodecs(codecs: MongoCodecRegistry): MongoAdapter {\n return new MongoAdapterImpl(codecs);\n}\n"],"mappings":";;;;;;;;AAAA,MAAa,0BAA0B;AACvC,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;AACrC,MAAa,uBAAuB;AACpC,MAAa,yBAAyB;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AAI,qBAAqB,QAAQ,YAAY,QAAQ,SAAS;GACvE,KAAK,eACH,QAAO,IAAI,qBAAqB,QAAQ,YAAY,QAAQ,SAAS;GACvE,KAAK,gBACH,QAAO,IAAI,sBAAsB,QAAQ,YAAY,QAAQ,UAAU;GACzE,KAAK,eACH,QAAO,IAAI,qBAAqB,QAAQ,YAAY,QAAQ,QAAQ,QAAQ,OAAO;GACrF,KAAK,gBACH,QAAO,IAAI,sBAAsB,QAAQ,YAAY,QAAQ,QAAQ,QAAQ,OAAO;GACtF,KAAK,eACH,QAAO,IAAI,qBAAqB,QAAQ,YAAY,QAAQ,OAAO;GACrE,KAAK,gBACH,QAAO,IAAI,sBAAsB,QAAQ,YAAY,QAAQ,OAAO;GACtE,KAAK,sBACH,QAAO,IAAI,4BACT,QAAQ,YACR,QAAQ,QACR,QAAQ,QACR,QAAQ,QACR,QAAQ,MACR,QAAQ,eACT;GACH,KAAK,sBACH,QAAO,IAAI,4BAA4B,QAAQ,YAAY,QAAQ,QAAQ,QAAQ,KAAK;GAE1F,SAAS;IACP,MAAMI,cAAqB;AAC3B,UAAM,IAAI,MAAM,yBAA0B,YAAiC,OAAO;;;;;;;;;;;;;;AAe1F,SAAgB,qBAAmC;AACjD,QAAO,IAAI,iBAAiB,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MongoCodecRegistry } from "@prisma-next/mongo-codec";
|
|
2
|
+
import { MongoAdapter } from "@prisma-next/mongo-lowering";
|
|
3
|
+
import { RuntimeAdapterDescriptor, RuntimeAdapterInstance } from "@prisma-next/framework-components/execution";
|
|
4
|
+
|
|
5
|
+
//#region src/exports/runtime.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* adapter-mongo deliberately does NOT import the
|
|
9
|
+
* `MongoRuntimeAdapterDescriptor` type alias from
|
|
10
|
+
* `@prisma-next/mongo-runtime`. The adapter package is downstream of the
|
|
11
|
+
* Mongo runtime package only conceptually; introducing a hard import would
|
|
12
|
+
* create a workspace dependency cycle (`mongo-runtime` consumes the runtime
|
|
13
|
+
* descriptor's `create(stack)` factory; `adapter-mongo` would then need
|
|
14
|
+
* `mongo-runtime` to type the descriptor). The descriptor is shaped to
|
|
15
|
+
* satisfy the framework's `RuntimeAdapterDescriptor` plus the structural
|
|
16
|
+
* `MongoStaticContributions` (`codecs()`) that `@prisma-next/mongo-runtime`
|
|
17
|
+
* narrows to at composition time. This mirrors the `target-postgres` ↔
|
|
18
|
+
* `sql-runtime` decoupling pattern.
|
|
19
|
+
*/
|
|
20
|
+
interface MongoRuntimeAdapterInstance extends RuntimeAdapterInstance<'mongo', 'mongo'>, MongoAdapter {}
|
|
21
|
+
declare const mongoRuntimeAdapterDescriptor: RuntimeAdapterDescriptor<'mongo', 'mongo', MongoRuntimeAdapterInstance> & {
|
|
22
|
+
readonly codecs: () => MongoCodecRegistry;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { mongoRuntimeAdapterDescriptor as default };
|
|
26
|
+
//# sourceMappingURL=runtime.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAMgE;AAoBhD;;;;;;;;;;UAFN,2BAAA,SACA,0CACN;cAEE,+BAA+B,2CAGnC;yBAEuB"}
|
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { n as buildStandardCodecRegistry, r as mongoStandardCodecs, t as createMongoAdapter } from "./mongo-adapter-ByNtvoHK.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/exports/runtime.ts
|
|
4
|
+
const mongoRuntimeAdapterDescriptor = {
|
|
5
|
+
kind: "adapter",
|
|
6
|
+
id: "mongo",
|
|
7
|
+
familyId: "mongo",
|
|
8
|
+
targetId: "mongo",
|
|
9
|
+
version: "0.0.1",
|
|
10
|
+
types: { codecTypes: { codecInstances: [...mongoStandardCodecs] } },
|
|
11
|
+
codecs: buildStandardCodecRegistry,
|
|
12
|
+
create(_stack) {
|
|
13
|
+
const adapter = createMongoAdapter();
|
|
14
|
+
return {
|
|
15
|
+
familyId: "mongo",
|
|
16
|
+
targetId: "mongo",
|
|
17
|
+
lower: adapter.lower.bind(adapter)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var runtime_default = mongoRuntimeAdapterDescriptor;
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { runtime_default as default };
|
|
25
|
+
//# sourceMappingURL=runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":["mongoRuntimeAdapterDescriptor: RuntimeAdapterDescriptor<\n 'mongo',\n 'mongo',\n MongoRuntimeAdapterInstance\n> & {\n readonly codecs: () => MongoCodecRegistry;\n}"],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type {\n ExecutionStack,\n RuntimeAdapterDescriptor,\n RuntimeAdapterInstance,\n} from '@prisma-next/framework-components/execution';\nimport type { MongoCodecRegistry } from '@prisma-next/mongo-codec';\nimport type { MongoAdapter } from '@prisma-next/mongo-lowering';\nimport { buildStandardCodecRegistry, mongoStandardCodecs } from '../core/codecs';\nimport { createMongoAdapter } from '../mongo-adapter';\n\n/**\n * adapter-mongo deliberately does NOT import the\n * `MongoRuntimeAdapterDescriptor` type alias from\n * `@prisma-next/mongo-runtime`. The adapter package is downstream of the\n * Mongo runtime package only conceptually; introducing a hard import would\n * create a workspace dependency cycle (`mongo-runtime` consumes the runtime\n * descriptor's `create(stack)` factory; `adapter-mongo` would then need\n * `mongo-runtime` to type the descriptor). The descriptor is shaped to\n * satisfy the framework's `RuntimeAdapterDescriptor` plus the structural\n * `MongoStaticContributions` (`codecs()`) that `@prisma-next/mongo-runtime`\n * narrows to at composition time. This mirrors the `target-postgres` ↔\n * `sql-runtime` decoupling pattern.\n */\n\ninterface MongoRuntimeAdapterInstance\n extends RuntimeAdapterInstance<'mongo', 'mongo'>,\n MongoAdapter {}\n\nconst mongoRuntimeAdapterDescriptor: RuntimeAdapterDescriptor<\n 'mongo',\n 'mongo',\n MongoRuntimeAdapterInstance\n> & {\n readonly codecs: () => MongoCodecRegistry;\n} = {\n kind: 'adapter',\n id: 'mongo',\n familyId: 'mongo',\n targetId: 'mongo',\n version: '0.0.1',\n types: {\n codecTypes: {\n codecInstances: [...mongoStandardCodecs],\n },\n },\n codecs: buildStandardCodecRegistry,\n create(_stack: ExecutionStack<'mongo', 'mongo'>): MongoRuntimeAdapterInstance {\n const adapter = createMongoAdapter();\n return {\n familyId: 'mongo' as const,\n targetId: 'mongo' as const,\n lower: adapter.lower.bind(adapter),\n };\n },\n};\n\nexport default mongoRuntimeAdapterDescriptor;\n"],"mappings":";;;AA4BA,MAAMA,gCAMF;CACF,MAAM;CACN,IAAI;CACJ,UAAU;CACV,UAAU;CACV,SAAS;CACT,OAAO,EACL,YAAY,EACV,gBAAgB,CAAC,GAAG,oBAAoB,EACzC,EACF;CACD,QAAQ;CACR,OAAO,QAAuE;EAC5E,MAAM,UAAU,oBAAoB;AACpC,SAAO;GACL,UAAU;GACV,UAAU;GACV,OAAO,QAAQ,MAAM,KAAK,QAAQ;GACnC;;CAEJ;AAED,sBAAe"}
|
package/package.json
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/adapter-mongo",
|
|
3
|
-
"version": "0.5.0-dev.
|
|
3
|
+
"version": "0.5.0-dev.50",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "MongoDB adapter for Prisma Next (lowers commands to wire format)",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"arktype": "^2.1.29",
|
|
9
9
|
"mongodb": "^6.16.0",
|
|
10
|
-
"@prisma-next/config": "0.5.0-dev.
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/
|
|
14
|
-
"@prisma-next/
|
|
15
|
-
"@prisma-next/mongo-contract": "0.5.0-dev.
|
|
16
|
-
"@prisma-next/mongo-
|
|
17
|
-
"@prisma-next/mongo-
|
|
18
|
-
"@prisma-next/mongo-schema-ir": "0.5.0-dev.
|
|
19
|
-
"@prisma-next/mongo-
|
|
20
|
-
"@prisma-next/
|
|
21
|
-
"@prisma-next/utils": "0.5.0-dev.
|
|
22
|
-
"@prisma-next/
|
|
10
|
+
"@prisma-next/config": "0.5.0-dev.50",
|
|
11
|
+
"@prisma-next/target-mongo": "0.5.0-dev.50",
|
|
12
|
+
"@prisma-next/contract": "0.5.0-dev.50",
|
|
13
|
+
"@prisma-next/mongo-codec": "0.5.0-dev.50",
|
|
14
|
+
"@prisma-next/framework-components": "0.5.0-dev.50",
|
|
15
|
+
"@prisma-next/mongo-contract": "0.5.0-dev.50",
|
|
16
|
+
"@prisma-next/mongo-lowering": "0.5.0-dev.50",
|
|
17
|
+
"@prisma-next/mongo-query-ast": "0.5.0-dev.50",
|
|
18
|
+
"@prisma-next/mongo-schema-ir": "0.5.0-dev.50",
|
|
19
|
+
"@prisma-next/mongo-value": "0.5.0-dev.50",
|
|
20
|
+
"@prisma-next/operations": "0.5.0-dev.50",
|
|
21
|
+
"@prisma-next/utils": "0.5.0-dev.50",
|
|
22
|
+
"@prisma-next/mongo-wire": "0.5.0-dev.50"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"mongodb-memory-server": "10.4.3",
|
|
26
26
|
"tsdown": "0.18.4",
|
|
27
27
|
"typescript": "5.9.3",
|
|
28
28
|
"vitest": "4.0.17",
|
|
29
|
-
"@prisma-next/driver-mongo": "0.5.0-dev.
|
|
29
|
+
"@prisma-next/driver-mongo": "0.5.0-dev.50",
|
|
30
|
+
"@prisma-next/psl-parser": "0.5.0-dev.50",
|
|
31
|
+
"@prisma-next/mongo-contract-psl": "0.5.0-dev.50",
|
|
30
32
|
"@prisma-next/test-utils": "0.0.1",
|
|
31
|
-
"@prisma-next/
|
|
32
|
-
"@prisma-next/
|
|
33
|
+
"@prisma-next/tsdown": "0.0.0",
|
|
34
|
+
"@prisma-next/tsconfig": "0.0.0"
|
|
33
35
|
},
|
|
34
36
|
"files": [
|
|
35
37
|
"dist",
|
|
@@ -39,6 +41,7 @@
|
|
|
39
41
|
".": "./dist/index.mjs",
|
|
40
42
|
"./codec-types": "./dist/codec-types.mjs",
|
|
41
43
|
"./control": "./dist/control.mjs",
|
|
44
|
+
"./runtime": "./dist/runtime.mjs",
|
|
42
45
|
"./package.json": "./package.json"
|
|
43
46
|
},
|
|
44
47
|
"main": "./dist/index.mjs",
|
package/src/core/codecs.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createMongoCodecRegistry,
|
|
3
|
+
type MongoCodecRegistry,
|
|
4
|
+
mongoCodec,
|
|
5
|
+
} from '@prisma-next/mongo-codec';
|
|
2
6
|
import { ObjectId } from 'mongodb';
|
|
3
7
|
import {
|
|
4
8
|
MONGO_BOOLEAN_CODEC_ID,
|
|
@@ -56,6 +60,11 @@ export const mongoDateCodec = mongoCodec({
|
|
|
56
60
|
traits: ['equality', 'order'],
|
|
57
61
|
decode: (wire: Date) => wire,
|
|
58
62
|
encode: (value: Date) => value,
|
|
63
|
+
encodeJson: (value: Date) => value.toISOString(),
|
|
64
|
+
decodeJson: (json) => {
|
|
65
|
+
if (typeof json !== 'string') throw new Error('expected ISO date string');
|
|
66
|
+
return new Date(json);
|
|
67
|
+
},
|
|
59
68
|
});
|
|
60
69
|
|
|
61
70
|
export const mongoVectorCodec = mongoCodec({
|
|
@@ -73,3 +82,37 @@ export const mongoVectorCodec = mongoCodec({
|
|
|
73
82
|
return `Vector<${length}>`;
|
|
74
83
|
},
|
|
75
84
|
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The canonical set of Mongo wire-type codecs.
|
|
88
|
+
*
|
|
89
|
+
* Single source of truth for both control- and runtime-plane adapter
|
|
90
|
+
* descriptors. Don't duplicate this list — import it.
|
|
91
|
+
*/
|
|
92
|
+
export const mongoStandardCodecs = [
|
|
93
|
+
mongoObjectIdCodec,
|
|
94
|
+
mongoStringCodec,
|
|
95
|
+
mongoDoubleCodec,
|
|
96
|
+
mongoInt32Codec,
|
|
97
|
+
mongoBooleanCodec,
|
|
98
|
+
mongoDateCodec,
|
|
99
|
+
mongoVectorCodec,
|
|
100
|
+
] as const;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Build a {@link MongoCodecRegistry} preloaded with the standard Mongo
|
|
104
|
+
* wire-type codecs.
|
|
105
|
+
*
|
|
106
|
+
* Single point of truth for adapter-side codec construction: used by the
|
|
107
|
+
* legacy synchronous `createMongoAdapter()` factory and by the runtime
|
|
108
|
+
* adapter descriptor's `codecs()` getter. Userland code obtains a registry
|
|
109
|
+
* via the framework's execution-stack composition (see
|
|
110
|
+
* `createMongoExecutionContext`) instead of calling this directly.
|
|
111
|
+
*/
|
|
112
|
+
export function buildStandardCodecRegistry(): MongoCodecRegistry {
|
|
113
|
+
const registry = createMongoCodecRegistry();
|
|
114
|
+
for (const codec of mongoStandardCodecs) {
|
|
115
|
+
registry.register(codec);
|
|
116
|
+
}
|
|
117
|
+
return registry;
|
|
118
|
+
}
|
package/src/core/operations.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { OperationDescriptor } from '@prisma-next/operations';
|
|
2
|
-
import {
|
|
2
|
+
import { MONGO_VECTOR_CODEC_ID } from './codec-ids';
|
|
3
3
|
|
|
4
4
|
export const mongoVectorNearOperation = Object.freeze({
|
|
5
5
|
method: 'near',
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
self: { codecId: MONGO_VECTOR_CODEC_ID },
|
|
7
|
+
impl: () => undefined as never,
|
|
8
8
|
}) satisfies OperationDescriptor;
|
|
9
9
|
|
|
10
10
|
export const mongoVectorOperationDescriptors: readonly OperationDescriptor[] = [
|
package/src/core/runner-deps.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ControlDriverInstance,
|
|
3
|
+
ControlFamilyInstance,
|
|
4
|
+
} from '@prisma-next/framework-components/control';
|
|
2
5
|
import type { MongoDriver } from '@prisma-next/mongo-lowering';
|
|
6
|
+
import type { MongoSchemaIR } from '@prisma-next/mongo-schema-ir';
|
|
3
7
|
import {
|
|
4
8
|
initMarker,
|
|
5
9
|
type MongoRunnerDependencies,
|
|
@@ -25,6 +29,7 @@ export function extractDb(driver: ControlDriverInstance<'mongo', 'mongo'>): Db {
|
|
|
25
29
|
export function createMongoRunnerDeps(
|
|
26
30
|
controlDriver: ControlDriverInstance<'mongo', 'mongo'>,
|
|
27
31
|
driver: MongoDriver,
|
|
32
|
+
family: ControlFamilyInstance<'mongo', MongoSchemaIR>,
|
|
28
33
|
): MongoRunnerDependencies {
|
|
29
34
|
const db = extractDb(controlDriver);
|
|
30
35
|
return {
|
|
@@ -38,5 +43,6 @@ export function createMongoRunnerDeps(
|
|
|
38
43
|
updateMarker: (expectedFrom, dest) => updateMarker(db, expectedFrom, dest),
|
|
39
44
|
writeLedgerEntry: (entry) => writeLedgerEntry(db, entry),
|
|
40
45
|
},
|
|
46
|
+
introspectSchema: () => family.introspect({ driver: controlDriver }),
|
|
41
47
|
};
|
|
42
48
|
}
|
package/src/exports/control.ts
CHANGED
|
@@ -8,15 +8,7 @@ export {
|
|
|
8
8
|
} from '../core/mongo-control-driver';
|
|
9
9
|
export { createMongoRunnerDeps, extractDb } from '../core/runner-deps';
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
mongoBooleanCodec,
|
|
13
|
-
mongoDateCodec,
|
|
14
|
-
mongoDoubleCodec,
|
|
15
|
-
mongoInt32Codec,
|
|
16
|
-
mongoObjectIdCodec,
|
|
17
|
-
mongoStringCodec,
|
|
18
|
-
mongoVectorCodec,
|
|
19
|
-
} from '../core/codecs';
|
|
11
|
+
import { mongoStandardCodecs } from '../core/codecs';
|
|
20
12
|
|
|
21
13
|
const mongoAdapterDescriptor: ControlAdapterDescriptor<'mongo', 'mongo'> = {
|
|
22
14
|
kind: 'adapter',
|
|
@@ -34,15 +26,7 @@ const mongoAdapterDescriptor: ControlAdapterDescriptor<'mongo', 'mongo'> = {
|
|
|
34
26
|
]),
|
|
35
27
|
types: {
|
|
36
28
|
codecTypes: {
|
|
37
|
-
codecInstances: [
|
|
38
|
-
mongoObjectIdCodec,
|
|
39
|
-
mongoStringCodec,
|
|
40
|
-
mongoDoubleCodec,
|
|
41
|
-
mongoInt32Codec,
|
|
42
|
-
mongoBooleanCodec,
|
|
43
|
-
mongoDateCodec,
|
|
44
|
-
mongoVectorCodec,
|
|
45
|
-
],
|
|
29
|
+
codecInstances: [...mongoStandardCodecs],
|
|
46
30
|
import: {
|
|
47
31
|
package: '@prisma-next/adapter-mongo/codec-types',
|
|
48
32
|
named: 'CodecTypes',
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExecutionStack,
|
|
3
|
+
RuntimeAdapterDescriptor,
|
|
4
|
+
RuntimeAdapterInstance,
|
|
5
|
+
} from '@prisma-next/framework-components/execution';
|
|
6
|
+
import type { MongoCodecRegistry } from '@prisma-next/mongo-codec';
|
|
7
|
+
import type { MongoAdapter } from '@prisma-next/mongo-lowering';
|
|
8
|
+
import { buildStandardCodecRegistry, mongoStandardCodecs } from '../core/codecs';
|
|
9
|
+
import { createMongoAdapter } from '../mongo-adapter';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* adapter-mongo deliberately does NOT import the
|
|
13
|
+
* `MongoRuntimeAdapterDescriptor` type alias from
|
|
14
|
+
* `@prisma-next/mongo-runtime`. The adapter package is downstream of the
|
|
15
|
+
* Mongo runtime package only conceptually; introducing a hard import would
|
|
16
|
+
* create a workspace dependency cycle (`mongo-runtime` consumes the runtime
|
|
17
|
+
* descriptor's `create(stack)` factory; `adapter-mongo` would then need
|
|
18
|
+
* `mongo-runtime` to type the descriptor). The descriptor is shaped to
|
|
19
|
+
* satisfy the framework's `RuntimeAdapterDescriptor` plus the structural
|
|
20
|
+
* `MongoStaticContributions` (`codecs()`) that `@prisma-next/mongo-runtime`
|
|
21
|
+
* narrows to at composition time. This mirrors the `target-postgres` ↔
|
|
22
|
+
* `sql-runtime` decoupling pattern.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
interface MongoRuntimeAdapterInstance
|
|
26
|
+
extends RuntimeAdapterInstance<'mongo', 'mongo'>,
|
|
27
|
+
MongoAdapter {}
|
|
28
|
+
|
|
29
|
+
const mongoRuntimeAdapterDescriptor: RuntimeAdapterDescriptor<
|
|
30
|
+
'mongo',
|
|
31
|
+
'mongo',
|
|
32
|
+
MongoRuntimeAdapterInstance
|
|
33
|
+
> & {
|
|
34
|
+
readonly codecs: () => MongoCodecRegistry;
|
|
35
|
+
} = {
|
|
36
|
+
kind: 'adapter',
|
|
37
|
+
id: 'mongo',
|
|
38
|
+
familyId: 'mongo',
|
|
39
|
+
targetId: 'mongo',
|
|
40
|
+
version: '0.0.1',
|
|
41
|
+
types: {
|
|
42
|
+
codecTypes: {
|
|
43
|
+
codecInstances: [...mongoStandardCodecs],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
codecs: buildStandardCodecRegistry,
|
|
47
|
+
create(_stack: ExecutionStack<'mongo', 'mongo'>): MongoRuntimeAdapterInstance {
|
|
48
|
+
const adapter = createMongoAdapter();
|
|
49
|
+
return {
|
|
50
|
+
familyId: 'mongo' as const,
|
|
51
|
+
targetId: 'mongo' as const,
|
|
52
|
+
lower: adapter.lower.bind(adapter),
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default mongoRuntimeAdapterDescriptor;
|
package/src/lowering.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { CodecCallContext } from '@prisma-next/framework-components/codec';
|
|
2
|
+
import type { MongoCodecRegistry } from '@prisma-next/mongo-codec';
|
|
1
3
|
import type {
|
|
2
4
|
MongoAggExpr,
|
|
3
5
|
MongoAggExprVisitor,
|
|
@@ -136,16 +138,20 @@ export function lowerAggExpr(expr: MongoAggExpr): unknown {
|
|
|
136
138
|
return expr.accept(aggExprLoweringVisitor);
|
|
137
139
|
}
|
|
138
140
|
|
|
139
|
-
export function lowerFilter(
|
|
141
|
+
export async function lowerFilter(
|
|
142
|
+
filter: MongoFilterExpr,
|
|
143
|
+
codecs: MongoCodecRegistry,
|
|
144
|
+
ctx: CodecCallContext,
|
|
145
|
+
): Promise<Document> {
|
|
140
146
|
switch (filter.kind) {
|
|
141
147
|
case 'field':
|
|
142
|
-
return { [filter.field]: { [filter.op]: resolveValue(filter.value) } };
|
|
148
|
+
return { [filter.field]: { [filter.op]: await resolveValue(filter.value, codecs, ctx) } };
|
|
143
149
|
case 'and':
|
|
144
|
-
return { $and: filter.exprs.map((e) => lowerFilter(e)) };
|
|
150
|
+
return { $and: await Promise.all(filter.exprs.map((e) => lowerFilter(e, codecs, ctx))) };
|
|
145
151
|
case 'or':
|
|
146
|
-
return { $or: filter.exprs.map((e) => lowerFilter(e)) };
|
|
152
|
+
return { $or: await Promise.all(filter.exprs.map((e) => lowerFilter(e, codecs, ctx))) };
|
|
147
153
|
case 'not':
|
|
148
|
-
return { $nor: [lowerFilter(filter.expr)] };
|
|
154
|
+
return { $nor: [await lowerFilter(filter.expr, codecs, ctx)] };
|
|
149
155
|
case 'exists':
|
|
150
156
|
return { [filter.field]: { $exists: filter.exists } };
|
|
151
157
|
case 'expr':
|
|
@@ -198,10 +204,14 @@ function lowerWindowField(wf: MongoWindowField): Record<string, unknown> {
|
|
|
198
204
|
return result;
|
|
199
205
|
}
|
|
200
206
|
|
|
201
|
-
export function lowerStage(
|
|
207
|
+
export async function lowerStage(
|
|
208
|
+
stage: MongoPipelineStage,
|
|
209
|
+
codecs: MongoCodecRegistry,
|
|
210
|
+
ctx: CodecCallContext,
|
|
211
|
+
): Promise<Record<string, unknown>> {
|
|
202
212
|
switch (stage.kind) {
|
|
203
213
|
case 'match':
|
|
204
|
-
return { $match: lowerFilter(stage.filter) };
|
|
214
|
+
return { $match: await lowerFilter(stage.filter, codecs, ctx) };
|
|
205
215
|
case 'project': {
|
|
206
216
|
const projection: Record<string, unknown> = {};
|
|
207
217
|
for (const [key, val] of Object.entries(stage.projection)) {
|
|
@@ -223,7 +233,9 @@ export function lowerStage(stage: MongoPipelineStage): Record<string, unknown> {
|
|
|
223
233
|
if (stage.localField !== undefined) lookup['localField'] = stage.localField;
|
|
224
234
|
if (stage.foreignField !== undefined) lookup['foreignField'] = stage.foreignField;
|
|
225
235
|
if (stage.pipeline) {
|
|
226
|
-
lookup['pipeline'] =
|
|
236
|
+
lookup['pipeline'] = await Promise.all(
|
|
237
|
+
stage.pipeline.map((s) => lowerStage(s, codecs, ctx)),
|
|
238
|
+
);
|
|
227
239
|
}
|
|
228
240
|
if (stage.let_) {
|
|
229
241
|
lookup['let'] = lowerExprRecord(stage.let_);
|
|
@@ -264,7 +276,9 @@ export function lowerStage(stage: MongoPipelineStage): Record<string, unknown> {
|
|
|
264
276
|
case 'unionWith': {
|
|
265
277
|
const unionWith: Record<string, unknown> = { coll: stage.collection };
|
|
266
278
|
if (stage.pipeline) {
|
|
267
|
-
unionWith['pipeline'] =
|
|
279
|
+
unionWith['pipeline'] = await Promise.all(
|
|
280
|
+
stage.pipeline.map((s) => lowerStage(s, codecs, ctx)),
|
|
281
|
+
);
|
|
268
282
|
}
|
|
269
283
|
return { $unionWith: unionWith };
|
|
270
284
|
}
|
|
@@ -294,7 +308,7 @@ export function lowerStage(stage: MongoPipelineStage): Record<string, unknown> {
|
|
|
294
308
|
if (stage.spherical !== undefined) geoNear['spherical'] = stage.spherical;
|
|
295
309
|
if (stage.maxDistance !== undefined) geoNear['maxDistance'] = stage.maxDistance;
|
|
296
310
|
if (stage.minDistance !== undefined) geoNear['minDistance'] = stage.minDistance;
|
|
297
|
-
if (stage.query) geoNear['query'] = lowerFilter(stage.query);
|
|
311
|
+
if (stage.query) geoNear['query'] = await lowerFilter(stage.query, codecs, ctx);
|
|
298
312
|
if (stage.key !== undefined) geoNear['key'] = stage.key;
|
|
299
313
|
if (stage.distanceMultiplier !== undefined)
|
|
300
314
|
geoNear['distanceMultiplier'] = stage.distanceMultiplier;
|
|
@@ -302,9 +316,18 @@ export function lowerStage(stage: MongoPipelineStage): Record<string, unknown> {
|
|
|
302
316
|
return { $geoNear: geoNear };
|
|
303
317
|
}
|
|
304
318
|
case 'facet': {
|
|
319
|
+
const facetEntries = Object.entries(stage.facets);
|
|
320
|
+
const facetPipelines = await Promise.all(
|
|
321
|
+
facetEntries.map(([, pipeline]) =>
|
|
322
|
+
Promise.all(pipeline.map((s) => lowerStage(s, codecs, ctx))),
|
|
323
|
+
),
|
|
324
|
+
);
|
|
305
325
|
const facet: Record<string, unknown> = {};
|
|
306
|
-
for (
|
|
307
|
-
|
|
326
|
+
for (let i = 0; i < facetEntries.length; i++) {
|
|
327
|
+
const entry = facetEntries[i];
|
|
328
|
+
if (entry) {
|
|
329
|
+
facet[entry[0]] = facetPipelines[i];
|
|
330
|
+
}
|
|
308
331
|
}
|
|
309
332
|
return { $facet: facet };
|
|
310
333
|
}
|
|
@@ -319,7 +342,11 @@ export function lowerStage(stage: MongoPipelineStage): Record<string, unknown> {
|
|
|
319
342
|
if (stage.maxDepth !== undefined) graphLookup['maxDepth'] = stage.maxDepth;
|
|
320
343
|
if (stage.depthField !== undefined) graphLookup['depthField'] = stage.depthField;
|
|
321
344
|
if (stage.restrictSearchWithMatch)
|
|
322
|
-
graphLookup['restrictSearchWithMatch'] = lowerFilter(
|
|
345
|
+
graphLookup['restrictSearchWithMatch'] = await lowerFilter(
|
|
346
|
+
stage.restrictSearchWithMatch,
|
|
347
|
+
codecs,
|
|
348
|
+
ctx,
|
|
349
|
+
);
|
|
323
350
|
return { $graphLookup: graphLookup };
|
|
324
351
|
}
|
|
325
352
|
case 'merge': {
|
|
@@ -327,7 +354,7 @@ export function lowerStage(stage: MongoPipelineStage): Record<string, unknown> {
|
|
|
327
354
|
if (stage.on !== undefined) merge['on'] = stage.on;
|
|
328
355
|
if (stage.whenMatched !== undefined) {
|
|
329
356
|
merge['whenMatched'] = Array.isArray(stage.whenMatched)
|
|
330
|
-
? stage.whenMatched.map((s) => lowerStage(s))
|
|
357
|
+
? await Promise.all(stage.whenMatched.map((s) => lowerStage(s, codecs, ctx)))
|
|
331
358
|
: stage.whenMatched;
|
|
332
359
|
}
|
|
333
360
|
if (stage.whenNotMatched !== undefined) merge['whenNotMatched'] = stage.whenNotMatched;
|
|
@@ -395,8 +422,10 @@ export function lowerStage(stage: MongoPipelineStage): Record<string, unknown> {
|
|
|
395
422
|
}
|
|
396
423
|
}
|
|
397
424
|
|
|
398
|
-
export function lowerPipeline(
|
|
425
|
+
export async function lowerPipeline(
|
|
399
426
|
stages: ReadonlyArray<MongoPipelineStage>,
|
|
400
|
-
|
|
401
|
-
|
|
427
|
+
codecs: MongoCodecRegistry,
|
|
428
|
+
ctx: CodecCallContext,
|
|
429
|
+
): Promise<Array<Record<string, unknown>>> {
|
|
430
|
+
return Promise.all(stages.map((s) => lowerStage(s, codecs, ctx)));
|
|
402
431
|
}
|