@prisma-next/mongo-codec 0.0.1 → 0.3.0-dev.147
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 +33 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +44 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -5
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { JsonValue } from "@prisma-next/contract/types";
|
|
2
|
+
import { Codec, CodecTrait } from "@prisma-next/framework-components/codec";
|
|
3
|
+
|
|
4
|
+
//#region src/codecs.d.ts
|
|
5
|
+
type MongoCodecTrait = CodecTrait;
|
|
6
|
+
interface MongoCodec<Id extends string = string, TTraits$1 extends readonly MongoCodecTrait[] = readonly MongoCodecTrait[], TWire = unknown, TJs = unknown> extends Codec<Id, TTraits$1, TWire, TJs> {
|
|
7
|
+
readonly traits: TTraits$1;
|
|
8
|
+
}
|
|
9
|
+
declare function mongoCodec<Id extends string, const TTraits$1 extends readonly MongoCodecTrait[] = readonly [], TWire = unknown, TJs = unknown>(config: {
|
|
10
|
+
typeId: Id;
|
|
11
|
+
targetTypes: readonly string[];
|
|
12
|
+
traits?: TTraits$1;
|
|
13
|
+
encode: (value: TJs) => TWire;
|
|
14
|
+
decode: (wire: TWire) => TJs;
|
|
15
|
+
encodeJson?: (value: TJs) => JsonValue;
|
|
16
|
+
decodeJson?: (json: JsonValue) => TJs;
|
|
17
|
+
renderOutputType?: (typeParams: Record<string, unknown>) => string | undefined;
|
|
18
|
+
}): MongoCodec<Id, TTraits$1, TWire, TJs>;
|
|
19
|
+
type MongoCodecJsType<T> = T extends MongoCodec<string, readonly MongoCodecTrait[], unknown, infer TJs> ? TJs : never;
|
|
20
|
+
type MongoCodecTraits<T> = T extends MongoCodec<string, infer TTraits> ? TTraits[number] & MongoCodecTrait : never;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/codec-registry.d.ts
|
|
23
|
+
interface MongoCodecRegistry {
|
|
24
|
+
get(id: string): MongoCodec<string> | undefined;
|
|
25
|
+
has(id: string): boolean;
|
|
26
|
+
register(codec: MongoCodec<string>): void;
|
|
27
|
+
[Symbol.iterator](): Iterator<MongoCodec<string>>;
|
|
28
|
+
values(): IterableIterator<MongoCodec<string>>;
|
|
29
|
+
}
|
|
30
|
+
declare function createMongoCodecRegistry(): MongoCodecRegistry;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { type MongoCodec, type MongoCodecJsType, type MongoCodecRegistry, type MongoCodecTrait, type MongoCodecTraits, createMongoCodecRegistry, mongoCodec };
|
|
33
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/codecs.ts","../src/codec-registry.ts"],"sourcesContent":[],"mappings":";;;;KAGY,eAAA,GAAkB;UAEb,kEAEU,6BAA6B,2DAG9C,MAAU,IAAI,WAAS,OAAO;EAP5B,SAAA,MAAA,EAQO,SARQ;AAE3B;AAE2B,iBAOX,UAPW,CAAA,WAAA,MAAA,EAAA,wBAAA,SASM,eATN,EAAA,GAAA,SAAA,EAAA,EAAA,QAAA,OAAA,EAAA,MAAA,OAAA,CAAA,CAAA,MAAA,EAAA;EAA6B,MAAA,EAa9C,EAb8C;EAGpC,WAAA,EAAA,SAAA,MAAA,EAAA;EAAI,MAAA,CAAA,EAYb,SAZa;EAAS,MAAA,EAAA,CAAA,KAAA,EAaf,GAbe,EAAA,GAaP,KAbO;EAAO,MAAA,EAAA,CAAA,IAAA,EAcvB,KAduB,EAAA,GAcb,GAda;EACrB,UAAA,CAAA,EAAA,CAAA,KAAA,EAcI,GAdJ,EAAA,GAcY,SAdZ;EADT,UAAA,CAAA,EAAA,CAAA,IAAA,EAgBY,SAhBZ,EAAA,GAgB0B,GAhB1B;EAAS,gBAAA,CAAA,EAAA,CAAA,UAAA,EAiBe,MAjBf,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,GAAA,MAAA,GAAA,SAAA;AAInB,CAAA,CAAA,EAcI,UAdY,CAcD,EAdW,EAcP,SAdO,EAcE,KAdF,EAcS,GAdT,CAAA;AAEO,KA6BrB,gBA7BqB,CAAA,CAAA,CAAA,GA8B/B,CA9B+B,SA8BrB,UA9BqB,CAAA,MAAA,EAAA,SA8BO,eA9BP,EAAA,EAAA,OAAA,EAAA,KAAA,IAAA,CAAA,GAAA,GAAA,GAAA,KAAA;AAIvB,KA4BE,gBA5BF,CAAA,CAAA,CAAA,GA6BR,CA7BQ,SA6BE,UA7BF,CAAA,MAAA,EAAA,KAAA,QAAA,CAAA,GA6BsC,OA7BtC,CAAA,MAAA,CAAA,GA6BwD,eA7BxD,GAAA,KAAA;;;UClBO,kBAAA;mBACE;;EDAP,QAAA,CAAA,KAAA,ECEM,UDFS,CAAA,MAAG,CAAA,CAAA,EAAA,IAAU;EAEvB,CAAA,MAAA,CAAA,QAAU,GAAA,ECCJ,QDDI,CCCK,UDDL,CAAA,MAAA,CAAA,CAAA;EAEA,MAAA,EAAA,ECAf,gBDAe,CCAE,UDAF,CAAA,MAAA,CAAA,CAAA;;AAGP,iBC2BJ,wBAAA,CAAA,CD3BI,EC2BwB,kBD3BxB"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/codec-registry.ts
|
|
2
|
+
var MongoCodecRegistryImpl = class {
|
|
3
|
+
#byId = /* @__PURE__ */ new Map();
|
|
4
|
+
get(id) {
|
|
5
|
+
return this.#byId.get(id);
|
|
6
|
+
}
|
|
7
|
+
has(id) {
|
|
8
|
+
return this.#byId.has(id);
|
|
9
|
+
}
|
|
10
|
+
register(codec) {
|
|
11
|
+
if (this.#byId.has(codec.id)) throw new Error(`Codec with ID '${codec.id}' is already registered`);
|
|
12
|
+
this.#byId.set(codec.id, codec);
|
|
13
|
+
}
|
|
14
|
+
*[Symbol.iterator]() {
|
|
15
|
+
yield* this.#byId.values();
|
|
16
|
+
}
|
|
17
|
+
values() {
|
|
18
|
+
return this.#byId.values();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
function createMongoCodecRegistry() {
|
|
22
|
+
return new MongoCodecRegistryImpl();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/codecs.ts
|
|
27
|
+
function mongoCodec(config) {
|
|
28
|
+
const traits = config.traits ? Object.freeze([...config.traits]) : Object.freeze([]);
|
|
29
|
+
const identity = (v) => v;
|
|
30
|
+
return {
|
|
31
|
+
id: config.typeId,
|
|
32
|
+
targetTypes: config.targetTypes,
|
|
33
|
+
traits,
|
|
34
|
+
decode: config.decode,
|
|
35
|
+
encode: config.encode,
|
|
36
|
+
encodeJson: config.encodeJson ?? identity,
|
|
37
|
+
decodeJson: config.decodeJson ?? identity,
|
|
38
|
+
...config.renderOutputType ? { renderOutputType: config.renderOutputType } : {}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { createMongoCodecRegistry, mongoCodec };
|
|
44
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#byId"],"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\nclass MongoCodecRegistryImpl implements MongoCodecRegistry {\n readonly #byId = new Map<string, MongoCodec<string>>();\n\n get(id: string): MongoCodec<string> | undefined {\n return this.#byId.get(id);\n }\n\n has(id: string): boolean {\n return this.#byId.has(id);\n }\n\n register(codec: MongoCodec<string>): void {\n if (this.#byId.has(codec.id)) {\n throw new Error(`Codec with ID '${codec.id}' is already registered`);\n }\n this.#byId.set(codec.id, codec);\n }\n\n *[Symbol.iterator](): Iterator<MongoCodec<string>> {\n yield* this.#byId.values();\n }\n\n values(): IterableIterator<MongoCodec<string>> {\n return this.#byId.values();\n }\n}\n\nexport function createMongoCodecRegistry(): MongoCodecRegistry {\n return new MongoCodecRegistryImpl();\n}\n","import type { JsonValue } from '@prisma-next/contract/types';\nimport type { Codec as BaseCodec, CodecTrait } from '@prisma-next/framework-components/codec';\n\nexport type MongoCodecTrait = CodecTrait;\n\nexport interface MongoCodec<\n Id extends string = string,\n TTraits extends readonly MongoCodecTrait[] = readonly MongoCodecTrait[],\n TWire = unknown,\n TJs = unknown,\n> extends BaseCodec<Id, TTraits, TWire, TJs> {\n readonly traits: TTraits;\n}\n\nexport function mongoCodec<\n Id extends string,\n const TTraits extends readonly MongoCodecTrait[] = readonly [],\n TWire = unknown,\n TJs = unknown,\n>(config: {\n typeId: Id;\n targetTypes: readonly string[];\n traits?: TTraits;\n encode: (value: TJs) => TWire;\n decode: (wire: TWire) => TJs;\n encodeJson?: (value: TJs) => JsonValue;\n decodeJson?: (json: JsonValue) => TJs;\n renderOutputType?: (typeParams: Record<string, unknown>) => string | undefined;\n}): MongoCodec<Id, TTraits, TWire, TJs> {\n const traits = config.traits\n ? (Object.freeze([...config.traits]) as TTraits)\n : (Object.freeze([] as const) as unknown as TTraits);\n const identity = (v: unknown) => v;\n return {\n id: config.typeId,\n targetTypes: config.targetTypes,\n traits,\n decode: config.decode,\n encode: config.encode,\n encodeJson: (config.encodeJson ?? identity) as (value: TJs) => JsonValue,\n decodeJson: (config.decodeJson ?? identity) as (json: JsonValue) => TJs,\n ...(config.renderOutputType ? { renderOutputType: config.renderOutputType } : {}),\n };\n}\n\nexport type MongoCodecJsType<T> =\n T extends MongoCodec<string, readonly MongoCodecTrait[], unknown, infer TJs> ? TJs : never;\n\nexport type MongoCodecTraits<T> =\n T extends MongoCodec<string, infer TTraits> ? TTraits[number] & MongoCodecTrait : never;\n"],"mappings":";AAUA,IAAM,yBAAN,MAA2D;CACzD,CAASA,uBAAQ,IAAI,KAAiC;CAEtD,IAAI,IAA4C;AAC9C,SAAO,MAAKA,KAAM,IAAI,GAAG;;CAG3B,IAAI,IAAqB;AACvB,SAAO,MAAKA,KAAM,IAAI,GAAG;;CAG3B,SAAS,OAAiC;AACxC,MAAI,MAAKA,KAAM,IAAI,MAAM,GAAG,CAC1B,OAAM,IAAI,MAAM,kBAAkB,MAAM,GAAG,yBAAyB;AAEtE,QAAKA,KAAM,IAAI,MAAM,IAAI,MAAM;;CAGjC,EAAE,OAAO,YAA0C;AACjD,SAAO,MAAKA,KAAM,QAAQ;;CAG5B,SAA+C;AAC7C,SAAO,MAAKA,KAAM,QAAQ;;;AAI9B,SAAgB,2BAA+C;AAC7D,QAAO,IAAI,wBAAwB;;;;;ACxBrC,SAAgB,WAKd,QASsC;CACtC,MAAM,SAAS,OAAO,SACjB,OAAO,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC,GACjC,OAAO,OAAO,EAAE,CAAU;CAC/B,MAAM,YAAY,MAAe;AACjC,QAAO;EACL,IAAI,OAAO;EACX,aAAa,OAAO;EACpB;EACA,QAAQ,OAAO;EACf,QAAQ,OAAO;EACf,YAAa,OAAO,cAAc;EAClC,YAAa,OAAO,cAAc;EAClC,GAAI,OAAO,mBAAmB,EAAE,kBAAkB,OAAO,kBAAkB,GAAG,EAAE;EACjF"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/mongo-codec",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.3.0-dev.147",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Codec interface and registry for Prisma Next MongoDB support",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/contract": "0.0.
|
|
9
|
-
"@prisma-next/framework-components": "0.0.
|
|
8
|
+
"@prisma-next/contract": "0.3.0-dev.147",
|
|
9
|
+
"@prisma-next/framework-components": "0.3.0-dev.147"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"tsdown": "0.18.4",
|
|
13
13
|
"typescript": "5.9.3",
|
|
14
14
|
"vitest": "4.0.17",
|
|
15
15
|
"@prisma-next/tsconfig": "0.0.0",
|
|
16
|
-
"@prisma-next/
|
|
17
|
-
"@prisma-next/
|
|
16
|
+
"@prisma-next/test-utils": "0.0.1",
|
|
17
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|