@prisma-next/operations 0.16.0-dev.30 → 0.16.0-dev.31
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 +9 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -5
- package/src/contract-errors.ts +14 -0
- package/src/index.ts +17 -3
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";UAEiB;WACN;WACA;WACA;;UAGM;WACN;WACA;;KAGC;WACG;WAA0B;;WAC1B;WAAoC;;UAElC;WACN,OAAO;WACP,UAAU;;KAGT,oBAAoB,UAAU,iBAAiB,kBAAkB;KAEjE,qBAAqB,UAAU,iBAAiB,kBAAkB,SAC5E,eAAe,oBAAoB;UAGpB,kBAAkB,UAAU,iBAAiB;EAC5D,SAAS,cAAc,YAAY,oBAAoB;EACvD,WAAW,SAAS,eAAe;;iBAGrB,wBACd,UAAU,iBAAiB,mBACxB,kBAAkB"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import { structuredError } from "@prisma-next/utils/structured-error";
|
|
2
|
+
//#region src/contract-errors.ts
|
|
3
|
+
function contractError(code, message, options) {
|
|
4
|
+
return structuredError(code, message, options);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
1
7
|
//#region src/index.ts
|
|
2
8
|
function createOperationRegistry() {
|
|
3
9
|
const operations = Object.create(null);
|
|
4
10
|
return {
|
|
5
11
|
register(name, descriptor) {
|
|
6
|
-
if (name in operations) throw
|
|
12
|
+
if (name in operations) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Operation "${name}" is already registered`, { meta: { operation: name } });
|
|
7
13
|
if (descriptor.self) {
|
|
8
14
|
const hasCodecId = descriptor.self.codecId !== void 0;
|
|
9
15
|
const hasTraits = descriptor.self.traits !== void 0 && descriptor.self.traits.length > 0;
|
|
10
|
-
if (!hasCodecId && !hasTraits) throw
|
|
11
|
-
if (hasCodecId && hasTraits) throw
|
|
16
|
+
if (!hasCodecId && !hasTraits) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Operation "${name}" self has neither codecId nor traits`, { meta: { operation: name } });
|
|
17
|
+
if (hasCodecId && hasTraits) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Operation "${name}" self has both codecId and traits`, { meta: { operation: name } });
|
|
12
18
|
}
|
|
13
19
|
operations[name] = descriptor;
|
|
14
20
|
},
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/contract-errors.ts","../src/index.ts"],"sourcesContent":["import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error';\nimport { structuredError } from '@prisma-next/utils/structured-error';\n\nexport type ContractCode = `CONTRACT.${ContractSubcode}`;\n\ntype ContractSubcode = 'PACK_CONTRIBUTION_INVALID';\n\nexport function contractError(\n code: ContractCode,\n message: string,\n options?: StructuredErrorOptions,\n): StructuredError {\n return structuredError(code, message, options);\n}\n","import { contractError } from './contract-errors';\n\nexport interface ParamSpec {\n readonly codecId?: string;\n readonly traits?: readonly string[];\n readonly nullable: boolean;\n}\n\nexport interface ReturnSpec {\n readonly codecId: string;\n readonly nullable: boolean;\n}\n\nexport type SelfSpec =\n | { readonly codecId: string; readonly traits?: never }\n | { readonly traits: readonly string[]; readonly codecId?: never };\n\nexport interface OperationEntry {\n readonly self?: SelfSpec;\n readonly impl: (...args: never[]) => unknown;\n}\n\nexport type OperationDescriptor<T extends OperationEntry = OperationEntry> = T;\n\nexport type OperationDescriptors<T extends OperationEntry = OperationEntry> = Readonly<\n Record<string, OperationDescriptor<T>>\n>;\n\nexport interface OperationRegistry<T extends OperationEntry = OperationEntry> {\n register(name: string, descriptor: OperationDescriptor<T>): void;\n entries(): Readonly<Record<string, T>>;\n}\n\nexport function createOperationRegistry<\n T extends OperationEntry = OperationEntry,\n>(): OperationRegistry<T> {\n const operations: Record<string, T> = Object.create(null);\n\n return {\n register(name: string, descriptor: OperationDescriptor<T>) {\n if (name in operations) {\n throw contractError(\n 'CONTRACT.PACK_CONTRIBUTION_INVALID',\n `Operation \"${name}\" is already registered`,\n { meta: { operation: name } },\n );\n }\n if (descriptor.self) {\n const hasCodecId = descriptor.self.codecId !== undefined;\n const hasTraits = descriptor.self.traits !== undefined && descriptor.self.traits.length > 0;\n if (!hasCodecId && !hasTraits) {\n throw contractError(\n 'CONTRACT.PACK_CONTRIBUTION_INVALID',\n `Operation \"${name}\" self has neither codecId nor traits`,\n { meta: { operation: name } },\n );\n }\n if (hasCodecId && hasTraits) {\n throw contractError(\n 'CONTRACT.PACK_CONTRIBUTION_INVALID',\n `Operation \"${name}\" self has both codecId and traits`,\n { meta: { operation: name } },\n );\n }\n }\n operations[name] = descriptor;\n },\n entries() {\n return Object.freeze({ ...operations });\n },\n };\n}\n"],"mappings":";;AAOA,SAAgB,cACd,MACA,SACA,SACiB;CACjB,OAAO,gBAAgB,MAAM,SAAS,OAAO;AAC/C;;;ACoBA,SAAgB,0BAEU;CACxB,MAAM,aAAgC,OAAO,OAAO,IAAI;CAExD,OAAO;EACL,SAAS,MAAc,YAAoC;GACzD,IAAI,QAAQ,YACV,MAAM,cACJ,sCACA,cAAc,KAAK,0BACnB,EAAE,MAAM,EAAE,WAAW,KAAK,EAAE,CAC9B;GAEF,IAAI,WAAW,MAAM;IACnB,MAAM,aAAa,WAAW,KAAK,YAAY,KAAA;IAC/C,MAAM,YAAY,WAAW,KAAK,WAAW,KAAA,KAAa,WAAW,KAAK,OAAO,SAAS;IAC1F,IAAI,CAAC,cAAc,CAAC,WAClB,MAAM,cACJ,sCACA,cAAc,KAAK,wCACnB,EAAE,MAAM,EAAE,WAAW,KAAK,EAAE,CAC9B;IAEF,IAAI,cAAc,WAChB,MAAM,cACJ,sCACA,cAAc,KAAK,qCACnB,EAAE,MAAM,EAAE,WAAW,KAAK,EAAE,CAC9B;GAEJ;GACA,WAAW,QAAQ;EACrB;EACA,UAAU;GACR,OAAO,OAAO,OAAO,EAAE,GAAG,WAAW,CAAC;EACxC;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/operations",
|
|
3
|
-
"version": "0.16.0-dev.
|
|
3
|
+
"version": "0.16.0-dev.31",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Target-neutral operation registry and capability helpers for Prisma Next",
|
|
8
|
-
"dependencies": {
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@prisma-next/utils": "0.16.0-dev.31"
|
|
10
|
+
},
|
|
9
11
|
"devDependencies": {
|
|
10
|
-
"@prisma-next/test-utils": "0.16.0-dev.
|
|
11
|
-
"@prisma-next/tsconfig": "0.16.0-dev.
|
|
12
|
-
"@prisma-next/tsdown": "0.16.0-dev.
|
|
12
|
+
"@prisma-next/test-utils": "0.16.0-dev.31",
|
|
13
|
+
"@prisma-next/tsconfig": "0.16.0-dev.31",
|
|
14
|
+
"@prisma-next/tsdown": "0.16.0-dev.31",
|
|
13
15
|
"tsdown": "0.22.8",
|
|
14
16
|
"typescript": "5.9.3",
|
|
15
17
|
"vitest": "4.1.10"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error';
|
|
2
|
+
import { structuredError } from '@prisma-next/utils/structured-error';
|
|
3
|
+
|
|
4
|
+
export type ContractCode = `CONTRACT.${ContractSubcode}`;
|
|
5
|
+
|
|
6
|
+
type ContractSubcode = 'PACK_CONTRIBUTION_INVALID';
|
|
7
|
+
|
|
8
|
+
export function contractError(
|
|
9
|
+
code: ContractCode,
|
|
10
|
+
message: string,
|
|
11
|
+
options?: StructuredErrorOptions,
|
|
12
|
+
): StructuredError {
|
|
13
|
+
return structuredError(code, message, options);
|
|
14
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { contractError } from './contract-errors';
|
|
2
|
+
|
|
1
3
|
export interface ParamSpec {
|
|
2
4
|
readonly codecId?: string;
|
|
3
5
|
readonly traits?: readonly string[];
|
|
@@ -37,16 +39,28 @@ export function createOperationRegistry<
|
|
|
37
39
|
return {
|
|
38
40
|
register(name: string, descriptor: OperationDescriptor<T>) {
|
|
39
41
|
if (name in operations) {
|
|
40
|
-
throw
|
|
42
|
+
throw contractError(
|
|
43
|
+
'CONTRACT.PACK_CONTRIBUTION_INVALID',
|
|
44
|
+
`Operation "${name}" is already registered`,
|
|
45
|
+
{ meta: { operation: name } },
|
|
46
|
+
);
|
|
41
47
|
}
|
|
42
48
|
if (descriptor.self) {
|
|
43
49
|
const hasCodecId = descriptor.self.codecId !== undefined;
|
|
44
50
|
const hasTraits = descriptor.self.traits !== undefined && descriptor.self.traits.length > 0;
|
|
45
51
|
if (!hasCodecId && !hasTraits) {
|
|
46
|
-
throw
|
|
52
|
+
throw contractError(
|
|
53
|
+
'CONTRACT.PACK_CONTRIBUTION_INVALID',
|
|
54
|
+
`Operation "${name}" self has neither codecId nor traits`,
|
|
55
|
+
{ meta: { operation: name } },
|
|
56
|
+
);
|
|
47
57
|
}
|
|
48
58
|
if (hasCodecId && hasTraits) {
|
|
49
|
-
throw
|
|
59
|
+
throw contractError(
|
|
60
|
+
'CONTRACT.PACK_CONTRIBUTION_INVALID',
|
|
61
|
+
`Operation "${name}" self has both codecId and traits`,
|
|
62
|
+
{ meta: { operation: name } },
|
|
63
|
+
);
|
|
50
64
|
}
|
|
51
65
|
}
|
|
52
66
|
operations[name] = descriptor;
|