@prisma-next/operations 0.4.0-dev.9 → 0.5.0-dev.1

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 CHANGED
@@ -1,11 +1,16 @@
1
1
  //#region src/index.d.ts
2
2
  interface ParamSpec {
3
+ readonly codecId?: string;
4
+ readonly traits?: readonly string[];
5
+ readonly nullable: boolean;
6
+ }
7
+ interface ReturnSpec {
3
8
  readonly codecId: string;
4
9
  readonly nullable: boolean;
5
10
  }
6
11
  interface OperationEntry {
7
12
  readonly args: readonly ParamSpec[];
8
- readonly returns: ParamSpec;
13
+ readonly returns: ReturnSpec;
9
14
  }
10
15
  type OperationDescriptor<T extends OperationEntry = OperationEntry> = T & {
11
16
  readonly method: string;
@@ -16,5 +21,5 @@ interface OperationRegistry<T extends OperationEntry = OperationEntry> {
16
21
  }
17
22
  declare function createOperationRegistry<T extends OperationEntry = OperationEntry>(): OperationRegistry<T>;
18
23
  //#endregion
19
- export { OperationDescriptor, OperationEntry, OperationRegistry, ParamSpec, createOperationRegistry };
24
+ export { OperationDescriptor, OperationEntry, OperationRegistry, ParamSpec, ReturnSpec, createOperationRegistry };
20
25
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";UAAiB,SAAA;EAAA,SAAA,OAAS,EAAA,MAAA;EAKT,SAAA,QAAc,EAAA,OAAA;AAK/B;AAA0C,UALzB,cAAA,CAKyB;EAAiB,SAAA,IAAA,EAAA,SAJjC,SAIiC,EAAA;EAAkB,SAAA,OAAA,EAHzD,SAGyD;;AAI5D,KAJL,mBAIsB,CAAA,UAJQ,cAIR,GAJyB,cAIzB,CAAA,GAJ2C,CAI3C,GAAA;EAAW,SAAA,MAAA,EAAA,MAAA;CAAiB;AACnB,UAD1B,iBAC0B,CAAA,UADE,cACF,GADmB,cACnB,CAAA,CAAA;EAApB,QAAA,CAAA,UAAA,EAAA,mBAAA,CAAoB,CAApB,CAAA,CAAA,EAAA,IAAA;EACc,OAAA,EAAA,EAAxB,QAAwB,CAAf,MAAe,CAAA,MAAA,EAAA,CAAA,CAAA,CAAA;;AAAxB,iBAGG,uBAHH,CAAA,UAID,cAJC,GAIgB,cAJhB,CAAA,CAAA,CAAA,EAKR,iBALQ,CAKU,CALV,CAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";UAAiB,SAAA;EAAA,SAAA,OAAS,CAAA,EAAA,MAAA;EAMT,SAAA,MAAU,CAAA,EAAA,SAAA,MAAA,EAAA;EAKV,SAAA,QAAc,EAAA,OAAA;AAK/B;AAA0C,UAVzB,UAAA,CAUyB;EAAiB,SAAA,OAAA,EAAA,MAAA;EAAkB,SAAA,QAAA,EAAA,OAAA;;AAI5D,UATA,cAAA,CASiB;EAAW,SAAA,IAAA,EAAA,SARnB,SAQmB,EAAA;EAAiB,SAAA,OAAA,EAP1C,UAO0C;;AACvC,KALX,mBAKW,CAAA,UALmB,cAKnB,GALoC,cAKpC,CAAA,GALsD,CAKtD,GAAA;EACc,SAAA,MAAA,EAAA,MAAA;CAAf;AAAT,UAFI,iBAEJ,CAAA,UAFgC,cAEhC,GAFiD,cAEjD,CAAA,CAAA;EAAQ,QAAA,CAAA,UAAA,EADE,mBACF,CADsB,CACtB,CAAA,CAAA,EAAA,IAAA;EAGL,OAAA,EAAA,EAHH,QAGG,CAHM,MAGiB,CAAA,MAAA,EAHF,CAGE,CAAA,CAAA;;AACV,iBADb,uBACa,CAAA,UAAjB,cAAiB,GAAA,cAAA,CAAA,CAAA,CAAA,EACxB,iBADwB,CACN,CADM,CAAA"}
package/dist/index.mjs CHANGED
@@ -4,6 +4,12 @@ function createOperationRegistry() {
4
4
  return {
5
5
  register(descriptor) {
6
6
  if (descriptor.method in operations) throw new Error(`Operation "${descriptor.method}" is already registered`);
7
+ descriptor.args.forEach((arg, i) => {
8
+ const hasCodecId = arg.codecId !== void 0;
9
+ const hasTraits = arg.traits !== void 0 && arg.traits.length > 0;
10
+ if (!hasCodecId && !hasTraits) throw new Error(`Operation "${descriptor.method}" arg[${i}] has neither codecId nor traits`);
11
+ if (hasCodecId && hasTraits) throw new Error(`Operation "${descriptor.method}" arg[${i}] has both codecId and traits`);
12
+ });
7
13
  const { method: _method, ...entry } = descriptor;
8
14
  operations[descriptor.method] = entry;
9
15
  },
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["operations: Record<string, T>"],"sources":["../src/index.ts"],"sourcesContent":["export interface ParamSpec {\n readonly codecId: string;\n readonly nullable: boolean;\n}\n\nexport interface OperationEntry {\n readonly args: readonly ParamSpec[];\n readonly returns: ParamSpec;\n}\n\nexport type OperationDescriptor<T extends OperationEntry = OperationEntry> = T & {\n readonly method: string;\n};\n\nexport interface OperationRegistry<T extends OperationEntry = OperationEntry> {\n register(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(descriptor: OperationDescriptor<T>) {\n if (descriptor.method in operations) {\n throw new Error(`Operation \"${descriptor.method}\" is already registered`);\n }\n const { method: _method, ...entry } = descriptor;\n // OperationDescriptor<T> = T & { method }, so stripping method yields T.\n // TypeScript can't prove Omit<T & { method }, 'method'> = T for generic T.\n operations[descriptor.method] = entry as unknown as T;\n },\n entries() {\n return Object.freeze({ ...operations });\n },\n };\n}\n"],"mappings":";AAmBA,SAAgB,0BAEU;CACxB,MAAMA,aAAgC,OAAO,OAAO,KAAK;AAEzD,QAAO;EACL,SAAS,YAAoC;AAC3C,OAAI,WAAW,UAAU,WACvB,OAAM,IAAI,MAAM,cAAc,WAAW,OAAO,yBAAyB;GAE3E,MAAM,EAAE,QAAQ,SAAS,GAAG,UAAU;AAGtC,cAAW,WAAW,UAAU;;EAElC,UAAU;AACR,UAAO,OAAO,OAAO,EAAE,GAAG,YAAY,CAAC;;EAE1C"}
1
+ {"version":3,"file":"index.mjs","names":["operations: Record<string, T>"],"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 interface OperationEntry {\n readonly args: readonly ParamSpec[];\n readonly returns: ReturnSpec;\n}\n\nexport type OperationDescriptor<T extends OperationEntry = OperationEntry> = T & {\n readonly method: string;\n};\n\nexport interface OperationRegistry<T extends OperationEntry = OperationEntry> {\n register(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(descriptor: OperationDescriptor<T>) {\n if (descriptor.method in operations) {\n throw new Error(`Operation \"${descriptor.method}\" is already registered`);\n }\n descriptor.args.forEach((arg, i) => {\n const hasCodecId = arg.codecId !== undefined;\n const hasTraits = arg.traits !== undefined && arg.traits.length > 0;\n if (!hasCodecId && !hasTraits) {\n throw new Error(\n `Operation \"${descriptor.method}\" arg[${i}] has neither codecId nor traits`,\n );\n }\n if (hasCodecId && hasTraits) {\n throw new Error(`Operation \"${descriptor.method}\" arg[${i}] has both codecId and traits`);\n }\n });\n const { method: _method, ...entry } = descriptor;\n // OperationDescriptor<T> = T & { method }, so stripping method yields T.\n // TypeScript can't prove Omit<T & { method }, 'method'> = T for generic T.\n operations[descriptor.method] = entry as unknown as T;\n },\n entries() {\n return Object.freeze({ ...operations });\n },\n };\n}\n"],"mappings":";AAyBA,SAAgB,0BAEU;CACxB,MAAMA,aAAgC,OAAO,OAAO,KAAK;AAEzD,QAAO;EACL,SAAS,YAAoC;AAC3C,OAAI,WAAW,UAAU,WACvB,OAAM,IAAI,MAAM,cAAc,WAAW,OAAO,yBAAyB;AAE3E,cAAW,KAAK,SAAS,KAAK,MAAM;IAClC,MAAM,aAAa,IAAI,YAAY;IACnC,MAAM,YAAY,IAAI,WAAW,UAAa,IAAI,OAAO,SAAS;AAClE,QAAI,CAAC,cAAc,CAAC,UAClB,OAAM,IAAI,MACR,cAAc,WAAW,OAAO,QAAQ,EAAE,kCAC3C;AAEH,QAAI,cAAc,UAChB,OAAM,IAAI,MAAM,cAAc,WAAW,OAAO,QAAQ,EAAE,+BAA+B;KAE3F;GACF,MAAM,EAAE,QAAQ,SAAS,GAAG,UAAU;AAGtC,cAAW,WAAW,UAAU;;EAElC,UAAU;AACR,UAAO,OAAO,OAAO,EAAE,GAAG,YAAY,CAAC;;EAE1C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/operations",
3
- "version": "0.4.0-dev.9",
3
+ "version": "0.5.0-dev.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Target-neutral operation registry and capability helpers for Prisma Next",
package/src/index.ts CHANGED
@@ -1,11 +1,17 @@
1
1
  export interface ParamSpec {
2
+ readonly codecId?: string;
3
+ readonly traits?: readonly string[];
4
+ readonly nullable: boolean;
5
+ }
6
+
7
+ export interface ReturnSpec {
2
8
  readonly codecId: string;
3
9
  readonly nullable: boolean;
4
10
  }
5
11
 
6
12
  export interface OperationEntry {
7
13
  readonly args: readonly ParamSpec[];
8
- readonly returns: ParamSpec;
14
+ readonly returns: ReturnSpec;
9
15
  }
10
16
 
11
17
  export type OperationDescriptor<T extends OperationEntry = OperationEntry> = T & {
@@ -27,6 +33,18 @@ export function createOperationRegistry<
27
33
  if (descriptor.method in operations) {
28
34
  throw new Error(`Operation "${descriptor.method}" is already registered`);
29
35
  }
36
+ descriptor.args.forEach((arg, i) => {
37
+ const hasCodecId = arg.codecId !== undefined;
38
+ const hasTraits = arg.traits !== undefined && arg.traits.length > 0;
39
+ if (!hasCodecId && !hasTraits) {
40
+ throw new Error(
41
+ `Operation "${descriptor.method}" arg[${i}] has neither codecId nor traits`,
42
+ );
43
+ }
44
+ if (hasCodecId && hasTraits) {
45
+ throw new Error(`Operation "${descriptor.method}" arg[${i}] has both codecId and traits`);
46
+ }
47
+ });
30
48
  const { method: _method, ...entry } = descriptor;
31
49
  // OperationDescriptor<T> = T & { method }, so stripping method yields T.
32
50
  // TypeScript can't prove Omit<T & { method }, 'method'> = T for generic T.