@prisma-next/operations 0.5.0-dev.9 → 0.5.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/README.md CHANGED
@@ -9,10 +9,11 @@ This package provides a generic, target-neutral operation registry. It's part of
9
9
  ## Responsibilities
10
10
 
11
11
  - **Operation Registry**: Generic operation registry interface and implementation
12
- - `OperationRegistry<T>`: Generic interface for registering and iterating operations, parameterized by entry type
12
+ - `OperationRegistry<T>`: Generic interface for registering and iterating operations, parameterized by entry type. `register(name, descriptor)` keys each entry by an explicit method name supplied at the call site.
13
13
  - `createOperationRegistry<T>()`: Factory function to create operation registries
14
- - `OperationEntry`: Base entry type with `args` and `returns`
15
- - `OperationDescriptor<T>`: Entry plus a `method` name, used for registration
14
+ - `OperationEntry`: Base entry type with `self` and `impl`
15
+ - `OperationDescriptor<T>`: Alias for the entry shape used at registration sites
16
+ - `OperationDescriptors<T>`: `Readonly<Record<string, OperationDescriptor<T>>>` — the natural shape contributors return, where the record key IS the method name
16
17
  - `ParamSpec`: Describes an operation parameter (`codecId`, `nullable`), used for both arguments and return values
17
18
 
18
19
  ## Dependencies
@@ -59,19 +60,18 @@ import { createOperationRegistry, type OperationDescriptor } from '@prisma-next/
59
60
  const registry = createOperationRegistry();
60
61
 
61
62
  const descriptor: OperationDescriptor = {
62
- method: 'cosineDistance',
63
- args: [{ codecId: 'pg/vector@1', nullable: false }],
64
- returns: { codecId: 'pg/float8@1', nullable: false },
63
+ self: { codecId: 'pg/vector@1' },
64
+ impl: () => ({ returnType: { codecId: 'pg/float8@1', nullable: false } }),
65
65
  };
66
66
 
67
- registry.register(descriptor);
67
+ registry.register('cosineDistance', descriptor);
68
68
  const entries = registry.entries(); // Record<string, OperationEntry>
69
69
  ```
70
70
 
71
71
  ### Using a Custom Entry Type
72
72
 
73
73
  ```typescript
74
- import { createOperationRegistry, type OperationEntry, type OperationDescriptor } from '@prisma-next/operations';
74
+ import { createOperationRegistry, type OperationEntry } from '@prisma-next/operations';
75
75
 
76
76
  interface MyEntry extends OperationEntry {
77
77
  readonly extra: string;
@@ -79,10 +79,9 @@ interface MyEntry extends OperationEntry {
79
79
 
80
80
  const registry = createOperationRegistry<MyEntry>();
81
81
 
82
- registry.register({
83
- method: 'myMethod',
84
- args: [],
85
- returns: { codecId: 'pg/int4@1', nullable: false },
82
+ registry.register('myMethod', {
83
+ self: { codecId: 'pg/int4@1' },
84
+ impl: () => undefined as never,
86
85
  extra: 'custom data',
87
86
  });
88
87
  ```
package/dist/index.d.mts CHANGED
@@ -8,18 +8,24 @@ interface ReturnSpec {
8
8
  readonly codecId: string;
9
9
  readonly nullable: boolean;
10
10
  }
11
+ type SelfSpec = {
12
+ readonly codecId: string;
13
+ readonly traits?: never;
14
+ } | {
15
+ readonly traits: readonly string[];
16
+ readonly codecId?: never;
17
+ };
11
18
  interface OperationEntry {
12
- readonly args: readonly ParamSpec[];
13
- readonly returns: ReturnSpec;
19
+ readonly self?: SelfSpec;
20
+ readonly impl: (...args: never[]) => unknown;
14
21
  }
15
- type OperationDescriptor<T extends OperationEntry = OperationEntry> = T & {
16
- readonly method: string;
17
- };
22
+ type OperationDescriptor<T extends OperationEntry = OperationEntry> = T;
23
+ type OperationDescriptors<T extends OperationEntry = OperationEntry> = Readonly<Record<string, OperationDescriptor<T>>>;
18
24
  interface OperationRegistry<T extends OperationEntry = OperationEntry> {
19
- register(descriptor: OperationDescriptor<T>): void;
25
+ register(name: string, descriptor: OperationDescriptor<T>): void;
20
26
  entries(): Readonly<Record<string, T>>;
21
27
  }
22
28
  declare function createOperationRegistry<T extends OperationEntry = OperationEntry>(): OperationRegistry<T>;
23
29
  //#endregion
24
- export { OperationDescriptor, OperationEntry, OperationRegistry, ParamSpec, ReturnSpec, createOperationRegistry };
30
+ export { OperationDescriptor, OperationDescriptors, OperationEntry, OperationRegistry, ParamSpec, ReturnSpec, SelfSpec, createOperationRegistry };
25
31
  //# 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,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"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";UAAiB,SAAA;EAAA,SACN,OAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA;AAAA;AAAA,UAGM,UAAA;EAAA,SACN,OAAA;EAAA,SACA,QAAA;AAAA;AAAA,KAGC,QAAA;EAAA,SACG,OAAA;EAAA,SAA0B,MAAA;AAAA;EAAA,SAC1B,MAAA;EAAA,SAAoC,OAAA;AAAA;AAAA,UAElC,cAAA;EAAA,SACN,IAAA,GAAO,QAAA;EAAA,SACP,IAAA,MAAU,IAAA;AAAA;AAAA,KAGT,mBAAA,WAA8B,cAAA,GAAiB,cAAA,IAAkB,CAAA;AAAA,KAEjE,oBAAA,WAA+B,cAAA,GAAiB,cAAA,IAAkB,QAAA,CAC5E,MAAA,SAAe,mBAAA,CAAoB,CAAA;AAAA,UAGpB,iBAAA,WAA4B,cAAA,GAAiB,cAAA;EAC5D,QAAA,CAAS,IAAA,UAAc,UAAA,EAAY,mBAAA,CAAoB,CAAA;EACvD,OAAA,IAAW,QAAA,CAAS,MAAA,SAAe,CAAA;AAAA;AAAA,iBAGrB,uBAAA,WACJ,cAAA,GAAiB,cAAA,CAAA,CAAA,GACxB,iBAAA,CAAkB,CAAA"}
package/dist/index.mjs CHANGED
@@ -2,23 +2,22 @@
2
2
  function createOperationRegistry() {
3
3
  const operations = Object.create(null);
4
4
  return {
5
- register(descriptor) {
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
- });
13
- const { method: _method, ...entry } = descriptor;
14
- operations[descriptor.method] = entry;
5
+ register(name, descriptor) {
6
+ if (name in operations) throw new Error(`Operation "${name}" is already registered`);
7
+ if (descriptor.self) {
8
+ const hasCodecId = descriptor.self.codecId !== void 0;
9
+ const hasTraits = descriptor.self.traits !== void 0 && descriptor.self.traits.length > 0;
10
+ if (!hasCodecId && !hasTraits) throw new Error(`Operation "${name}" self has neither codecId nor traits`);
11
+ if (hasCodecId && hasTraits) throw new Error(`Operation "${name}" self has both codecId and traits`);
12
+ }
13
+ operations[name] = descriptor;
15
14
  },
16
15
  entries() {
17
16
  return Object.freeze({ ...operations });
18
17
  }
19
18
  };
20
19
  }
21
-
22
20
  //#endregion
23
21
  export { createOperationRegistry };
22
+
24
23
  //# sourceMappingURL=index.mjs.map
@@ -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 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"}
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,KAAK;CAEzD,OAAO;EACL,SAAS,MAAc,YAAoC;GACzD,IAAI,QAAQ,YACV,MAAM,IAAI,MAAM,cAAc,KAAK,yBAAyB;GAE9D,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,uCAAuC;IAE5E,IAAI,cAAc,WAChB,MAAM,IAAI,MAAM,cAAc,KAAK,oCAAoC;;GAG3E,WAAW,QAAQ;;EAErB,UAAU;GACR,OAAO,OAAO,OAAO,EAAE,GAAG,YAAY,CAAC;;EAE1C"}
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@prisma-next/operations",
3
- "version": "0.5.0-dev.9",
3
+ "version": "0.5.1",
4
+ "license": "Apache-2.0",
4
5
  "type": "module",
5
6
  "sideEffects": false,
6
7
  "description": "Target-neutral operation registry and capability helpers for Prisma Next",
7
8
  "dependencies": {},
8
9
  "devDependencies": {
9
- "tsdown": "0.18.4",
10
+ "tsdown": "0.22.0",
10
11
  "typescript": "5.9.3",
11
- "vitest": "4.0.17",
12
- "@prisma-next/tsconfig": "0.0.0",
12
+ "vitest": "4.1.5",
13
13
  "@prisma-next/test-utils": "0.0.1",
14
+ "@prisma-next/tsconfig": "0.0.0",
14
15
  "@prisma-next/tsdown": "0.0.0"
15
16
  },
16
17
  "files": [
package/src/index.ts CHANGED
@@ -9,17 +9,23 @@ export interface ReturnSpec {
9
9
  readonly nullable: boolean;
10
10
  }
11
11
 
12
+ export type SelfSpec =
13
+ | { readonly codecId: string; readonly traits?: never }
14
+ | { readonly traits: readonly string[]; readonly codecId?: never };
15
+
12
16
  export interface OperationEntry {
13
- readonly args: readonly ParamSpec[];
14
- readonly returns: ReturnSpec;
17
+ readonly self?: SelfSpec;
18
+ readonly impl: (...args: never[]) => unknown;
15
19
  }
16
20
 
17
- export type OperationDescriptor<T extends OperationEntry = OperationEntry> = T & {
18
- readonly method: string;
19
- };
21
+ export type OperationDescriptor<T extends OperationEntry = OperationEntry> = T;
22
+
23
+ export type OperationDescriptors<T extends OperationEntry = OperationEntry> = Readonly<
24
+ Record<string, OperationDescriptor<T>>
25
+ >;
20
26
 
21
27
  export interface OperationRegistry<T extends OperationEntry = OperationEntry> {
22
- register(descriptor: OperationDescriptor<T>): void;
28
+ register(name: string, descriptor: OperationDescriptor<T>): void;
23
29
  entries(): Readonly<Record<string, T>>;
24
30
  }
25
31
 
@@ -29,26 +35,21 @@ export function createOperationRegistry<
29
35
  const operations: Record<string, T> = Object.create(null);
30
36
 
31
37
  return {
32
- register(descriptor: OperationDescriptor<T>) {
33
- if (descriptor.method in operations) {
34
- throw new Error(`Operation "${descriptor.method}" is already registered`);
38
+ register(name: string, descriptor: OperationDescriptor<T>) {
39
+ if (name in operations) {
40
+ throw new Error(`Operation "${name}" is already registered`);
35
41
  }
36
- descriptor.args.forEach((arg, i) => {
37
- const hasCodecId = arg.codecId !== undefined;
38
- const hasTraits = arg.traits !== undefined && arg.traits.length > 0;
42
+ if (descriptor.self) {
43
+ const hasCodecId = descriptor.self.codecId !== undefined;
44
+ const hasTraits = descriptor.self.traits !== undefined && descriptor.self.traits.length > 0;
39
45
  if (!hasCodecId && !hasTraits) {
40
- throw new Error(
41
- `Operation "${descriptor.method}" arg[${i}] has neither codecId nor traits`,
42
- );
46
+ throw new Error(`Operation "${name}" self has neither codecId nor traits`);
43
47
  }
44
48
  if (hasCodecId && hasTraits) {
45
- throw new Error(`Operation "${descriptor.method}" arg[${i}] has both codecId and traits`);
49
+ throw new Error(`Operation "${name}" self has both codecId and traits`);
46
50
  }
47
- });
48
- const { method: _method, ...entry } = descriptor;
49
- // OperationDescriptor<T> = T & { method }, so stripping method yields T.
50
- // TypeScript can't prove Omit<T & { method }, 'method'> = T for generic T.
51
- operations[descriptor.method] = entry as unknown as T;
51
+ }
52
+ operations[name] = descriptor;
52
53
  },
53
54
  entries() {
54
55
  return Object.freeze({ ...operations });