🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@prisma-next/operations

Package Overview
Dependencies
Maintainers
4
Versions
1123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prisma-next/operations - npm Package Compare versions

Comparing version
0.16.0-dev.30
to
0.16.0-dev.31
+14
src/contract-errors.ts
import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error';
import { structuredError } from '@prisma-next/utils/structured-error';
export type ContractCode = `CONTRACT.${ContractSubcode}`;
type ContractSubcode = 'PACK_CONTRIBUTION_INVALID';
export function contractError(
code: ContractCode,
message: string,
options?: StructuredErrorOptions,
): StructuredError {
return structuredError(code, message, options);
}
+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";UAAiB;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"}
{"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"}

@@ -0,1 +1,7 @@

import { structuredError } from "@prisma-next/utils/structured-error";
//#region src/contract-errors.ts
function contractError(code, message, options) {
return structuredError(code, message, options);
}
//#endregion
//#region src/index.ts

@@ -6,8 +12,8 @@ function createOperationRegistry() {

register(name, descriptor) {
if (name in operations) throw new Error(`Operation "${name}" is already registered`);
if (name in operations) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Operation "${name}" is already registered`, { meta: { operation: name } });
if (descriptor.self) {
const hasCodecId = descriptor.self.codecId !== void 0;
const hasTraits = descriptor.self.traits !== void 0 && descriptor.self.traits.length > 0;
if (!hasCodecId && !hasTraits) throw new Error(`Operation "${name}" self has neither codecId nor traits`);
if (hasCodecId && hasTraits) throw new Error(`Operation "${name}" self has both codecId and traits`);
if (!hasCodecId && !hasTraits) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Operation "${name}" self has neither codecId nor traits`, { meta: { operation: name } });
if (hasCodecId && hasTraits) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Operation "${name}" self has both codecId and traits`, { meta: { operation: name } });
}

@@ -14,0 +20,0 @@ operations[name] = descriptor;

@@ -1,1 +0,1 @@

{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export 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 new Error(`Operation \"${name}\" is already registered`);\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 new Error(`Operation \"${name}\" self has neither codecId nor traits`);\n }\n if (hasCodecId && hasTraits) {\n throw new Error(`Operation \"${name}\" self has both codecId and traits`);\n }\n }\n operations[name] = descriptor;\n },\n entries() {\n return Object.freeze({ ...operations });\n },\n };\n}\n"],"mappings":";AA+BA,SAAgB,0BAEU;CACxB,MAAM,aAAgC,OAAO,OAAO,IAAI;CAExD,OAAO;EACL,SAAS,MAAc,YAAoC;GACzD,IAAI,QAAQ,YACV,MAAM,IAAI,MAAM,cAAc,KAAK,wBAAwB;GAE7D,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,IAAI,MAAM,cAAc,KAAK,sCAAsC;IAE3E,IAAI,cAAc,WAChB,MAAM,IAAI,MAAM,cAAc,KAAK,mCAAmC;GAE1E;GACA,WAAW,QAAQ;EACrB;EACA,UAAU;GACR,OAAO,OAAO,OAAO,EAAE,GAAG,WAAW,CAAC;EACxC;CACF;AACF"}
{"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"}
{
"name": "@prisma-next/operations",
"version": "0.16.0-dev.30",
"version": "0.16.0-dev.31",
"license": "Apache-2.0",

@@ -8,7 +8,9 @@ "type": "module",

"description": "Target-neutral operation registry and capability helpers for Prisma Next",
"dependencies": {},
"dependencies": {
"@prisma-next/utils": "0.16.0-dev.31"
},
"devDependencies": {
"@prisma-next/test-utils": "0.16.0-dev.30",
"@prisma-next/tsconfig": "0.16.0-dev.30",
"@prisma-next/tsdown": "0.16.0-dev.30",
"@prisma-next/test-utils": "0.16.0-dev.31",
"@prisma-next/tsconfig": "0.16.0-dev.31",
"@prisma-next/tsdown": "0.16.0-dev.31",
"tsdown": "0.22.8",

@@ -15,0 +17,0 @@ "typescript": "5.9.3",

@@ -0,1 +1,3 @@

import { contractError } from './contract-errors';
export interface ParamSpec {

@@ -40,3 +42,7 @@ readonly codecId?: string;

if (name in operations) {
throw new Error(`Operation "${name}" is already registered`);
throw contractError(
'CONTRACT.PACK_CONTRIBUTION_INVALID',
`Operation "${name}" is already registered`,
{ meta: { operation: name } },
);
}

@@ -47,6 +53,14 @@ if (descriptor.self) {

if (!hasCodecId && !hasTraits) {
throw new Error(`Operation "${name}" self has neither codecId nor traits`);
throw contractError(
'CONTRACT.PACK_CONTRIBUTION_INVALID',
`Operation "${name}" self has neither codecId nor traits`,
{ meta: { operation: name } },
);
}
if (hasCodecId && hasTraits) {
throw new Error(`Operation "${name}" self has both codecId and traits`);
throw contractError(
'CONTRACT.PACK_CONTRIBUTION_INVALID',
`Operation "${name}" self has both codecId and traits`,
{ meta: { operation: name } },
);
}

@@ -53,0 +67,0 @@ }