@prisma-next/mongo-codec 0.5.0-dev.66 → 0.5.0-dev.67
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/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/codecs.ts","../src/codec-registry.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/codecs.ts","../src/codec-registry.ts"],"mappings":";;;;KAOY,eAAA,GAAkB,UAAA;;AAA9B;;;;UAOiB,UAAA,sDAEU,eAAA,cAA6B,eAAA,+CAG9C,KAAA,CAAU,EAAA,EAAI,OAAA,EAAS,KAAA,EAAO,MAAA;;;;KAKnC,mBAAA,YAA+B,MAAA,WAAiB,SAAA;EAE/C,UAAA,IAAc,KAAA,EAAO,MAAA,KAAW,SAAA;EAChC,UAAA,IAAc,IAAA,EAAM,SAAA,KAAc,MAAA;AAAA;EAGlC,UAAA,GAAa,KAAA,EAAO,MAAA,KAAW,SAAA;EAC/B,UAAA,GAAa,IAAA,EAAM,SAAA,KAAc,MAAA;AAAA;;;;;;;;;;iBAYvB,UAAA,mDAEiB,eAAA,oDAAA,CAI/B,MAAA;EACE,MAAA,EAAQ,EAAA;EACR,MAAA,GAAS,KAAA,EAAO,MAAA,EAAQ,GAAA,EAAK,gBAAA,KAAqB,KAAA,GAAQ,OAAA,CAAQ,KAAA;EAClE,MAAA,GAAS,IAAA,EAAM,KAAA,EAAO,GAAA,EAAK,gBAAA,KAAqB,MAAA,GAAS,OAAA,CAAQ,MAAA;AAAA,IAC/D,mBAAA,CAAoB,MAAA,IACvB,UAAA,CAAW,EAAA,EAAI,OAAA,EAAS,KAAA,EAAO,MAAA;AAnCgB;AAAA,KAkEtC,eAAA,MACV,CAAA,SAAU,UAAA,kBAA4B,eAAA,6BAA4C,MAAA;;;UCpFnE,kBAAA;EACf,GAAA,CAAI,EAAA,WAAa,UAAA;EACjB,GAAA,CAAI,EAAA;EACJ,QAAA,CAAS,KAAA,EAAO,UAAA;EAAA,CACf,MAAA,CAAO,QAAP,KAAoB,QAAA,CAAS,UAAA;EAC9B,MAAA,IAAU,gBAAA,CAAiB,UAAA;AAAA;;ADO7B;;iBCDgB,qBAAA,CAAA,GAAyB,kBAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -17,7 +17,6 @@ function newMongoCodecRegistry() {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
|
|
21
20
|
//#endregion
|
|
22
21
|
//#region src/codecs.ts
|
|
23
22
|
/**
|
|
@@ -54,7 +53,7 @@ function mongoCodec(config) {
|
|
|
54
53
|
decodeJson: widenedConfig.decodeJson ?? identity
|
|
55
54
|
};
|
|
56
55
|
}
|
|
57
|
-
|
|
58
56
|
//#endregion
|
|
59
57
|
export { mongoCodec, newMongoCodecRegistry };
|
|
58
|
+
|
|
60
59
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/codec-registry.ts","../src/codecs.ts"],"sourcesContent":["import type { MongoCodec } from './codecs';\n\nexport interface MongoCodecRegistry {\n get(id: string): MongoCodec<string> | undefined;\n has(id: string): boolean;\n register(codec: MongoCodec<string>): void;\n [Symbol.iterator](): Iterator<MongoCodec<string>>;\n values(): IterableIterator<MongoCodec<string>>;\n}\n\n/**\n * Create a new Mongo codec registry. Inline object literal — no class implementation; the registry is just a private `Map` with the documented surface methods.\n */\nexport function newMongoCodecRegistry(): MongoCodecRegistry {\n const byId = new Map<string, MongoCodec<string>>();\n return {\n get: (id) => byId.get(id),\n has: (id) => byId.has(id),\n register: (codec) => {\n if (byId.has(codec.id)) {\n throw new Error(`Codec with ID '${codec.id}' is already registered`);\n }\n byId.set(codec.id, codec);\n },\n values: () => byId.values(),\n [Symbol.iterator]: function* () {\n yield* byId.values();\n },\n };\n}\n","import type { JsonValue } from '@prisma-next/contract/types';\nimport type {\n Codec as BaseCodec,\n CodecCallContext,\n CodecTrait,\n} from '@prisma-next/framework-components/codec';\n\nexport type MongoCodecTrait = CodecTrait;\n\n/**\n * A codec for the Mongo target. Translates between an application value and the BSON-shaped wire form the Mongo driver exchanges, and between an application value and the JSON form stored in contract artifacts.\n *\n * Same shape as the framework codec base — see `Codec` in `@prisma-next/framework-components/codec` for the contract. Codec-id-keyed static metadata (`traits`, `targetTypes`, `renderOutputType`) lives on the unified {@link import('@prisma-next/framework-components/codec').CodecDescriptor}; Mongo's full migration to descriptor-side registration is tracked under TML-2324.\n */\nexport interface MongoCodec<\n Id extends string = string,\n TTraits extends readonly MongoCodecTrait[] = readonly MongoCodecTrait[],\n TWire = unknown,\n TInput = unknown,\n> extends BaseCodec<Id, TTraits, TWire, TInput> {}\n\n/**\n * Conditional bundle for `encodeJson`/`decodeJson`: when `TInput` is structurally assignable to `JsonValue` the identity defaults are sound and both fields are optional; otherwise both fields are required so an author cannot silently produce a non-JSON-safe contract artifact.\n */\ntype JsonRoundTripConfig<TInput> = [TInput] extends [JsonValue]\n ? {\n encodeJson?: (value: TInput) => JsonValue;\n decodeJson?: (json: JsonValue) => TInput;\n }\n : {\n encodeJson: (value: TInput) => JsonValue;\n decodeJson: (json: JsonValue) => TInput;\n };\n\n/**\n * Construct a Mongo codec from author functions.\n *\n * Author `encode` and `decode` as sync or async functions; the factory produces a {@link MongoCodec} whose query-time methods follow the boundary contract documented on the framework {@link BaseCodec}. Authors receive a second `ctx` options argument carrying the per-call context; ignore it if you don't need it.\n *\n * Both `encode` and `decode` are required so `TInput` and `TWire` are always covered by an explicit author function — the factory installs no identity fallback. `encodeJson` and `decodeJson` default to identity **only when `TInput` is assignable to `JsonValue`**; otherwise both are required so the contract artifact stays JSON-safe.\n *\n * Codec-id-keyed static metadata (`traits`, `targetTypes`, `renderOutputType`) lives on the unified `CodecDescriptor` rather than on the codec instance itself (TML-2357).\n */\nexport function mongoCodec<\n Id extends string,\n const TTraits extends readonly MongoCodecTrait[] = readonly [],\n TWire = unknown,\n TInput = unknown,\n>(\n config: {\n typeId: Id;\n encode: (value: TInput, ctx: CodecCallContext) => TWire | Promise<TWire>;\n decode: (wire: TWire, ctx: CodecCallContext) => TInput | Promise<TInput>;\n } & JsonRoundTripConfig<TInput>,\n): MongoCodec<Id, TTraits, TWire, TInput> {\n const identity = (v: unknown) => v;\n // The runtime allocates one `CodecCallContext` per `runtime.execute()` call (no caller-supplied `signal` produces `{}` instead of `undefined`) and threads it as a non-optional reference to every codec call. The author surface keeps the second parameter optional so single-arg `(value) => …` authors continue to satisfy the signature via TypeScript's bivariance for trailing parameters.\n const userEncode = config.encode;\n const userDecode = config.decode;\n const widenedConfig = config as {\n encodeJson?: (value: TInput) => JsonValue;\n decodeJson?: (json: JsonValue) => TInput;\n };\n return {\n id: config.typeId,\n encode: (value, ctx) => {\n try {\n return Promise.resolve(userEncode(value, ctx));\n } catch (error) {\n return Promise.reject(error);\n }\n },\n decode: (wire, ctx) => {\n try {\n return Promise.resolve(userDecode(wire, ctx));\n } catch (error) {\n return Promise.reject(error);\n }\n },\n encodeJson: (widenedConfig.encodeJson ?? identity) as (value: TInput) => JsonValue,\n decodeJson: (widenedConfig.decodeJson ?? identity) as (json: JsonValue) => TInput,\n };\n}\n\n/** Extract the JS application type carried by a Mongo codec — used both as `encode` input and as `decode` output. */\nexport type MongoCodecInput<T> =\n T extends MongoCodec<string, readonly MongoCodecTrait[], unknown, infer TInput> ? TInput : never;\n"],"mappings":";;;;AAaA,SAAgB,wBAA4C;CAC1D,MAAM,uBAAO,IAAI,KAAiC;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/codec-registry.ts","../src/codecs.ts"],"sourcesContent":["import type { MongoCodec } from './codecs';\n\nexport interface MongoCodecRegistry {\n get(id: string): MongoCodec<string> | undefined;\n has(id: string): boolean;\n register(codec: MongoCodec<string>): void;\n [Symbol.iterator](): Iterator<MongoCodec<string>>;\n values(): IterableIterator<MongoCodec<string>>;\n}\n\n/**\n * Create a new Mongo codec registry. Inline object literal — no class implementation; the registry is just a private `Map` with the documented surface methods.\n */\nexport function newMongoCodecRegistry(): MongoCodecRegistry {\n const byId = new Map<string, MongoCodec<string>>();\n return {\n get: (id) => byId.get(id),\n has: (id) => byId.has(id),\n register: (codec) => {\n if (byId.has(codec.id)) {\n throw new Error(`Codec with ID '${codec.id}' is already registered`);\n }\n byId.set(codec.id, codec);\n },\n values: () => byId.values(),\n [Symbol.iterator]: function* () {\n yield* byId.values();\n },\n };\n}\n","import type { JsonValue } from '@prisma-next/contract/types';\nimport type {\n Codec as BaseCodec,\n CodecCallContext,\n CodecTrait,\n} from '@prisma-next/framework-components/codec';\n\nexport type MongoCodecTrait = CodecTrait;\n\n/**\n * A codec for the Mongo target. Translates between an application value and the BSON-shaped wire form the Mongo driver exchanges, and between an application value and the JSON form stored in contract artifacts.\n *\n * Same shape as the framework codec base — see `Codec` in `@prisma-next/framework-components/codec` for the contract. Codec-id-keyed static metadata (`traits`, `targetTypes`, `renderOutputType`) lives on the unified {@link import('@prisma-next/framework-components/codec').CodecDescriptor}; Mongo's full migration to descriptor-side registration is tracked under TML-2324.\n */\nexport interface MongoCodec<\n Id extends string = string,\n TTraits extends readonly MongoCodecTrait[] = readonly MongoCodecTrait[],\n TWire = unknown,\n TInput = unknown,\n> extends BaseCodec<Id, TTraits, TWire, TInput> {}\n\n/**\n * Conditional bundle for `encodeJson`/`decodeJson`: when `TInput` is structurally assignable to `JsonValue` the identity defaults are sound and both fields are optional; otherwise both fields are required so an author cannot silently produce a non-JSON-safe contract artifact.\n */\ntype JsonRoundTripConfig<TInput> = [TInput] extends [JsonValue]\n ? {\n encodeJson?: (value: TInput) => JsonValue;\n decodeJson?: (json: JsonValue) => TInput;\n }\n : {\n encodeJson: (value: TInput) => JsonValue;\n decodeJson: (json: JsonValue) => TInput;\n };\n\n/**\n * Construct a Mongo codec from author functions.\n *\n * Author `encode` and `decode` as sync or async functions; the factory produces a {@link MongoCodec} whose query-time methods follow the boundary contract documented on the framework {@link BaseCodec}. Authors receive a second `ctx` options argument carrying the per-call context; ignore it if you don't need it.\n *\n * Both `encode` and `decode` are required so `TInput` and `TWire` are always covered by an explicit author function — the factory installs no identity fallback. `encodeJson` and `decodeJson` default to identity **only when `TInput` is assignable to `JsonValue`**; otherwise both are required so the contract artifact stays JSON-safe.\n *\n * Codec-id-keyed static metadata (`traits`, `targetTypes`, `renderOutputType`) lives on the unified `CodecDescriptor` rather than on the codec instance itself (TML-2357).\n */\nexport function mongoCodec<\n Id extends string,\n const TTraits extends readonly MongoCodecTrait[] = readonly [],\n TWire = unknown,\n TInput = unknown,\n>(\n config: {\n typeId: Id;\n encode: (value: TInput, ctx: CodecCallContext) => TWire | Promise<TWire>;\n decode: (wire: TWire, ctx: CodecCallContext) => TInput | Promise<TInput>;\n } & JsonRoundTripConfig<TInput>,\n): MongoCodec<Id, TTraits, TWire, TInput> {\n const identity = (v: unknown) => v;\n // The runtime allocates one `CodecCallContext` per `runtime.execute()` call (no caller-supplied `signal` produces `{}` instead of `undefined`) and threads it as a non-optional reference to every codec call. The author surface keeps the second parameter optional so single-arg `(value) => …` authors continue to satisfy the signature via TypeScript's bivariance for trailing parameters.\n const userEncode = config.encode;\n const userDecode = config.decode;\n const widenedConfig = config as {\n encodeJson?: (value: TInput) => JsonValue;\n decodeJson?: (json: JsonValue) => TInput;\n };\n return {\n id: config.typeId,\n encode: (value, ctx) => {\n try {\n return Promise.resolve(userEncode(value, ctx));\n } catch (error) {\n return Promise.reject(error);\n }\n },\n decode: (wire, ctx) => {\n try {\n return Promise.resolve(userDecode(wire, ctx));\n } catch (error) {\n return Promise.reject(error);\n }\n },\n encodeJson: (widenedConfig.encodeJson ?? identity) as (value: TInput) => JsonValue,\n decodeJson: (widenedConfig.decodeJson ?? identity) as (json: JsonValue) => TInput,\n };\n}\n\n/** Extract the JS application type carried by a Mongo codec — used both as `encode` input and as `decode` output. */\nexport type MongoCodecInput<T> =\n T extends MongoCodec<string, readonly MongoCodecTrait[], unknown, infer TInput> ? TInput : never;\n"],"mappings":";;;;AAaA,SAAgB,wBAA4C;CAC1D,MAAM,uBAAO,IAAI,KAAiC;CAClD,OAAO;EACL,MAAM,OAAO,KAAK,IAAI,GAAG;EACzB,MAAM,OAAO,KAAK,IAAI,GAAG;EACzB,WAAW,UAAU;GACnB,IAAI,KAAK,IAAI,MAAM,GAAG,EACpB,MAAM,IAAI,MAAM,kBAAkB,MAAM,GAAG,yBAAyB;GAEtE,KAAK,IAAI,MAAM,IAAI,MAAM;;EAE3B,cAAc,KAAK,QAAQ;EAC3B,CAAC,OAAO,WAAW,aAAa;GAC9B,OAAO,KAAK,QAAQ;;EAEvB;;;;;;;;;;;;;ACeH,SAAgB,WAMd,QAKwC;CACxC,MAAM,YAAY,MAAe;CAEjC,MAAM,aAAa,OAAO;CAC1B,MAAM,aAAa,OAAO;CAC1B,MAAM,gBAAgB;CAItB,OAAO;EACL,IAAI,OAAO;EACX,SAAS,OAAO,QAAQ;GACtB,IAAI;IACF,OAAO,QAAQ,QAAQ,WAAW,OAAO,IAAI,CAAC;YACvC,OAAO;IACd,OAAO,QAAQ,OAAO,MAAM;;;EAGhC,SAAS,MAAM,QAAQ;GACrB,IAAI;IACF,OAAO,QAAQ,QAAQ,WAAW,MAAM,IAAI,CAAC;YACtC,OAAO;IACd,OAAO,QAAQ,OAAO,MAAM;;;EAGhC,YAAa,cAAc,cAAc;EACzC,YAAa,cAAc,cAAc;EAC1C"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/mongo-codec",
|
|
3
|
-
"version": "0.5.0-dev.
|
|
3
|
+
"version": "0.5.0-dev.67",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Codec interface and registry for Prisma Next MongoDB support",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/utils": "0.5.0-dev.
|
|
9
|
+
"@prisma-next/framework-components": "0.5.0-dev.67",
|
|
10
|
+
"@prisma-next/contract": "0.5.0-dev.67",
|
|
11
|
+
"@prisma-next/utils": "0.5.0-dev.67"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"tsdown": "0.
|
|
14
|
+
"tsdown": "0.22.0",
|
|
15
15
|
"typescript": "5.9.3",
|
|
16
|
-
"vitest": "4.
|
|
17
|
-
"@prisma-next/tsconfig": "0.0.0",
|
|
16
|
+
"vitest": "4.1.5",
|
|
18
17
|
"@prisma-next/test-utils": "0.0.1",
|
|
18
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
19
19
|
"@prisma-next/tsdown": "0.0.0"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|