@prisma-next/operations 0.3.0-dev.144 → 0.3.0-dev.146
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 +32 -33
- package/dist/index.d.mts +15 -27
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +12 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -5
- package/src/index.ts +29 -55
package/README.md
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
# @prisma-next/operations
|
|
2
2
|
|
|
3
|
-
Target-neutral operation registry
|
|
3
|
+
Target-neutral operation registry for Prisma Next.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
This package provides target-neutral operation registry
|
|
7
|
+
This package provides a generic, target-neutral operation registry. It's part of the core ring and has no dependencies on target-specific packages.
|
|
8
8
|
|
|
9
9
|
## Responsibilities
|
|
10
10
|
|
|
11
|
-
- **Operation Registry**:
|
|
12
|
-
- `OperationRegistry
|
|
13
|
-
- `createOperationRegistry()`: Factory function to create operation registries
|
|
14
|
-
- `
|
|
15
|
-
- `
|
|
16
|
-
|
|
17
|
-
- **Capability Checking**: Target-neutral capability validation
|
|
18
|
-
- `hasAllCapabilities()`: Checks if all required capabilities are present in a contract
|
|
11
|
+
- **Operation Registry**: Generic operation registry interface and implementation
|
|
12
|
+
- `OperationRegistry<T>`: Generic interface for registering and iterating operations, parameterized by entry type
|
|
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
|
|
16
|
+
- `ParamSpec`: Describes an operation parameter (`codecId`, `nullable`), used for both arguments and return values
|
|
19
17
|
|
|
20
18
|
## Dependencies
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
- **
|
|
20
|
+
|
|
21
|
+
- **Depends on**: Nothing (leaf package)
|
|
24
22
|
- **Depended on by**:
|
|
25
23
|
- `@prisma-next/sql-operations` (extends with SQL-specific lowering specs)
|
|
26
|
-
- `@prisma-next/sql-relational-core` (
|
|
27
|
-
- `@prisma-next/runtime` (uses for operation registry creation)
|
|
24
|
+
- `@prisma-next/sql-relational-core` (imports `ParamSpec` for AST and type definitions)
|
|
25
|
+
- `@prisma-next/runtime-executor` (uses for operation registry creation)
|
|
28
26
|
|
|
29
27
|
## Architecture
|
|
30
28
|
|
|
@@ -56,36 +54,37 @@ flowchart TD
|
|
|
56
54
|
### Creating an Operation Registry
|
|
57
55
|
|
|
58
56
|
```typescript
|
|
59
|
-
import { createOperationRegistry, type
|
|
57
|
+
import { createOperationRegistry, type OperationDescriptor } from '@prisma-next/operations';
|
|
60
58
|
|
|
61
59
|
const registry = createOperationRegistry();
|
|
62
60
|
|
|
63
|
-
const
|
|
64
|
-
forTypeId: 'pg/vector@1',
|
|
61
|
+
const descriptor: OperationDescriptor = {
|
|
65
62
|
method: 'cosineDistance',
|
|
66
|
-
args: [{
|
|
67
|
-
returns: {
|
|
63
|
+
args: [{ codecId: 'pg/vector@1', nullable: false }],
|
|
64
|
+
returns: { codecId: 'pg/float8@1', nullable: false },
|
|
68
65
|
};
|
|
69
66
|
|
|
70
|
-
registry.register(
|
|
71
|
-
const
|
|
67
|
+
registry.register(descriptor);
|
|
68
|
+
const entries = registry.entries(); // Record<string, OperationEntry>
|
|
72
69
|
```
|
|
73
70
|
|
|
74
|
-
###
|
|
71
|
+
### Using a Custom Entry Type
|
|
75
72
|
|
|
76
73
|
```typescript
|
|
77
|
-
import {
|
|
74
|
+
import { createOperationRegistry, type OperationEntry, type OperationDescriptor } from '@prisma-next/operations';
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
interface MyEntry extends OperationEntry {
|
|
77
|
+
readonly extra: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const registry = createOperationRegistry<MyEntry>();
|
|
84
81
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
registry.register({
|
|
83
|
+
method: 'myMethod',
|
|
84
|
+
args: [],
|
|
85
|
+
returns: { codecId: 'pg/int4@1', nullable: false },
|
|
86
|
+
extra: 'custom data',
|
|
87
|
+
});
|
|
89
88
|
```
|
|
90
89
|
|
|
91
90
|
## Package Location
|
|
@@ -94,7 +93,7 @@ This package is part of the **framework domain**, **core layer**, **shared plane
|
|
|
94
93
|
- **Domain**: framework (target-agnostic)
|
|
95
94
|
- **Layer**: core
|
|
96
95
|
- **Plane**: shared
|
|
97
|
-
- **Path**: `packages/1-framework/1-core/
|
|
96
|
+
- **Path**: `packages/1-framework/1-core/operations`
|
|
98
97
|
|
|
99
98
|
## Related Documentation
|
|
100
99
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
//#region src/index.d.ts
|
|
2
|
-
|
|
3
|
-
readonly
|
|
4
|
-
readonly
|
|
5
|
-
} | {
|
|
6
|
-
readonly kind: 'param';
|
|
7
|
-
} | {
|
|
8
|
-
readonly kind: 'literal';
|
|
9
|
-
};
|
|
10
|
-
type ReturnSpec = {
|
|
11
|
-
readonly kind: 'typeId';
|
|
12
|
-
readonly type: string;
|
|
13
|
-
} | {
|
|
14
|
-
readonly kind: 'builtin';
|
|
15
|
-
readonly type: 'number' | 'boolean' | 'string';
|
|
16
|
-
};
|
|
17
|
-
interface OperationSignature {
|
|
18
|
-
readonly forTypeId: string;
|
|
19
|
-
readonly method: string;
|
|
20
|
-
readonly args: ReadonlyArray<ArgSpec>;
|
|
21
|
-
readonly returns: ReturnSpec;
|
|
22
|
-
readonly capabilities?: ReadonlyArray<string>;
|
|
2
|
+
interface ParamSpec {
|
|
3
|
+
readonly codecId: string;
|
|
4
|
+
readonly nullable: boolean;
|
|
23
5
|
}
|
|
24
|
-
interface
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
interface OperationEntry {
|
|
7
|
+
readonly args: readonly ParamSpec[];
|
|
8
|
+
readonly returns: ParamSpec;
|
|
9
|
+
}
|
|
10
|
+
type OperationDescriptor<T extends OperationEntry = OperationEntry> = T & {
|
|
11
|
+
readonly method: string;
|
|
12
|
+
};
|
|
13
|
+
interface OperationRegistry<T extends OperationEntry = OperationEntry> {
|
|
14
|
+
register(descriptor: OperationDescriptor<T>): void;
|
|
15
|
+
entries(): Readonly<Record<string, T>>;
|
|
27
16
|
}
|
|
28
|
-
declare function createOperationRegistry<T extends
|
|
29
|
-
declare function hasAllCapabilities(capabilities: ReadonlyArray<string>, contractCapabilities?: Record<string, Record<string, boolean>>): boolean;
|
|
17
|
+
declare function createOperationRegistry<T extends OperationEntry = OperationEntry>(): OperationRegistry<T>;
|
|
30
18
|
//#endregion
|
|
31
|
-
export {
|
|
19
|
+
export { OperationDescriptor, OperationEntry, OperationRegistry, ParamSpec, createOperationRegistry };
|
|
32
20
|
//# 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"],"sourcesContent":[],"mappings":";
|
|
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"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
//#region src/index.ts
|
|
2
|
-
var OperationRegistryImpl = class {
|
|
3
|
-
operations = /* @__PURE__ */ new Map();
|
|
4
|
-
register(op) {
|
|
5
|
-
const existing = this.operations.get(op.forTypeId) ?? [];
|
|
6
|
-
if (existing.find((existingOp) => existingOp.method === op.method)) throw new Error(`Operation method "${op.method}" already registered for typeId "${op.forTypeId}"`);
|
|
7
|
-
existing.push(op);
|
|
8
|
-
this.operations.set(op.forTypeId, existing);
|
|
9
|
-
}
|
|
10
|
-
byType(typeId) {
|
|
11
|
-
return this.operations.get(typeId) ?? [];
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
2
|
function createOperationRegistry() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
3
|
+
const operations = Object.create(null);
|
|
4
|
+
return {
|
|
5
|
+
register(descriptor) {
|
|
6
|
+
if (descriptor.method in operations) throw new Error(`Operation "${descriptor.method}" is already registered`);
|
|
7
|
+
const { method: _method, ...entry } = descriptor;
|
|
8
|
+
operations[descriptor.method] = entry;
|
|
9
|
+
},
|
|
10
|
+
entries() {
|
|
11
|
+
return Object.freeze({ ...operations });
|
|
12
|
+
}
|
|
13
|
+
};
|
|
24
14
|
}
|
|
25
15
|
|
|
26
16
|
//#endregion
|
|
27
|
-
export { createOperationRegistry
|
|
17
|
+
export { createOperationRegistry };
|
|
28
18
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/operations",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.146",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Target-neutral operation registry and capability helpers for Prisma Next",
|
|
7
|
-
"dependencies": {
|
|
8
|
-
"@prisma-next/plan": "0.3.0-dev.144"
|
|
9
|
-
},
|
|
7
|
+
"dependencies": {},
|
|
10
8
|
"devDependencies": {
|
|
11
9
|
"tsdown": "0.18.4",
|
|
12
10
|
"typescript": "5.9.3",
|
|
@@ -32,7 +30,7 @@
|
|
|
32
30
|
"repository": {
|
|
33
31
|
"type": "git",
|
|
34
32
|
"url": "https://github.com/prisma/prisma-next.git",
|
|
35
|
-
"directory": "packages/1-framework/1-core/
|
|
33
|
+
"directory": "packages/1-framework/1-core/operations"
|
|
36
34
|
},
|
|
37
35
|
"scripts": {
|
|
38
36
|
"build": "tsdown",
|
package/src/index.ts
CHANGED
|
@@ -1,65 +1,39 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
| { readonly kind: 'literal' };
|
|
5
|
-
|
|
6
|
-
export type ReturnSpec =
|
|
7
|
-
| { readonly kind: 'typeId'; readonly type: string }
|
|
8
|
-
| { readonly kind: 'builtin'; readonly type: 'number' | 'boolean' | 'string' };
|
|
9
|
-
|
|
10
|
-
export interface OperationSignature {
|
|
11
|
-
readonly forTypeId: string;
|
|
12
|
-
readonly method: string;
|
|
13
|
-
readonly args: ReadonlyArray<ArgSpec>;
|
|
14
|
-
readonly returns: ReturnSpec;
|
|
15
|
-
readonly capabilities?: ReadonlyArray<string>;
|
|
1
|
+
export interface ParamSpec {
|
|
2
|
+
readonly codecId: string;
|
|
3
|
+
readonly nullable: boolean;
|
|
16
4
|
}
|
|
17
5
|
|
|
18
|
-
export interface
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
export interface OperationEntry {
|
|
7
|
+
readonly args: readonly ParamSpec[];
|
|
8
|
+
readonly returns: ParamSpec;
|
|
21
9
|
}
|
|
22
10
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private readonly operations = new Map<string, T[]>();
|
|
27
|
-
|
|
28
|
-
register(op: T): void {
|
|
29
|
-
const existing = this.operations.get(op.forTypeId) ?? [];
|
|
30
|
-
const duplicate = existing.find((existingOp) => existingOp.method === op.method);
|
|
31
|
-
if (duplicate) {
|
|
32
|
-
throw new Error(
|
|
33
|
-
`Operation method "${op.method}" already registered for typeId "${op.forTypeId}"`,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
existing.push(op);
|
|
37
|
-
this.operations.set(op.forTypeId, existing);
|
|
38
|
-
}
|
|
11
|
+
export type OperationDescriptor<T extends OperationEntry = OperationEntry> = T & {
|
|
12
|
+
readonly method: string;
|
|
13
|
+
};
|
|
39
14
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
15
|
+
export interface OperationRegistry<T extends OperationEntry = OperationEntry> {
|
|
16
|
+
register(descriptor: OperationDescriptor<T>): void;
|
|
17
|
+
entries(): Readonly<Record<string, T>>;
|
|
43
18
|
}
|
|
44
19
|
|
|
45
20
|
export function createOperationRegistry<
|
|
46
|
-
T extends
|
|
21
|
+
T extends OperationEntry = OperationEntry,
|
|
47
22
|
>(): OperationRegistry<T> {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
23
|
+
const operations: Record<string, T> = Object.create(null);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
register(descriptor: OperationDescriptor<T>) {
|
|
27
|
+
if (descriptor.method in operations) {
|
|
28
|
+
throw new Error(`Operation "${descriptor.method}" is already registered`);
|
|
29
|
+
}
|
|
30
|
+
const { method: _method, ...entry } = descriptor;
|
|
31
|
+
// OperationDescriptor<T> = T & { method }, so stripping method yields T.
|
|
32
|
+
// TypeScript can't prove Omit<T & { method }, 'method'> = T for generic T.
|
|
33
|
+
operations[descriptor.method] = entry as unknown as T;
|
|
34
|
+
},
|
|
35
|
+
entries() {
|
|
36
|
+
return Object.freeze({ ...operations });
|
|
37
|
+
},
|
|
38
|
+
};
|
|
65
39
|
}
|