@prisma-next/operations 0.5.0-dev.9 → 0.6.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/README.md +11 -12
- package/dist/index.d.mts +13 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +10 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
- package/src/index.ts +22 -21
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 `
|
|
15
|
-
- `OperationDescriptor<T>`:
|
|
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
|
-
|
|
63
|
-
|
|
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
|
|
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
|
-
|
|
84
|
-
|
|
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
|
|
13
|
-
readonly
|
|
19
|
+
readonly self?: SelfSpec;
|
|
20
|
+
readonly impl: (...args: never[]) => unknown;
|
|
14
21
|
}
|
|
15
|
-
type OperationDescriptor<T extends OperationEntry = OperationEntry> = T
|
|
16
|
-
|
|
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
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"
|
|
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 (
|
|
7
|
-
descriptor.
|
|
8
|
-
const hasCodecId =
|
|
9
|
-
const hasTraits =
|
|
10
|
-
if (!hasCodecId && !hasTraits) throw new Error(`Operation "${
|
|
11
|
-
if (hasCodecId && hasTraits) throw new Error(`Operation "${
|
|
12
|
-
}
|
|
13
|
-
|
|
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
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[
|
|
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,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/operations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-dev.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.
|
|
10
|
+
"tsdown": "0.22.0",
|
|
10
11
|
"typescript": "5.9.3",
|
|
11
|
-
"vitest": "4.
|
|
12
|
+
"vitest": "4.1.5",
|
|
12
13
|
"@prisma-next/tsconfig": "0.0.0",
|
|
13
14
|
"@prisma-next/test-utils": "0.0.1",
|
|
14
15
|
"@prisma-next/tsdown": "0.0.0"
|
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
|
|
14
|
-
readonly
|
|
17
|
+
readonly self?: SelfSpec;
|
|
18
|
+
readonly impl: (...args: never[]) => unknown;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
export type OperationDescriptor<T extends OperationEntry = OperationEntry> = T
|
|
18
|
-
|
|
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 (
|
|
34
|
-
throw new Error(`Operation "${
|
|
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.
|
|
37
|
-
const hasCodecId =
|
|
38
|
-
const hasTraits =
|
|
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 "${
|
|
49
|
+
throw new Error(`Operation "${name}" self has both codecId and traits`);
|
|
46
50
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
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 });
|