@prisma-next/operations 0.3.0-dev.3 → 0.3.0-dev.5
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.ts +7 -8
- package/dist/index.d.ts.map +1 -0
- package/package.json +9 -8
- package/src/index.ts +61 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type ArgSpec = {
|
|
1
|
+
export type ArgSpec = {
|
|
2
2
|
readonly kind: 'typeId';
|
|
3
3
|
readonly type: string;
|
|
4
4
|
} | {
|
|
@@ -6,25 +6,24 @@ type ArgSpec = {
|
|
|
6
6
|
} | {
|
|
7
7
|
readonly kind: 'literal';
|
|
8
8
|
};
|
|
9
|
-
type ReturnSpec = {
|
|
9
|
+
export type ReturnSpec = {
|
|
10
10
|
readonly kind: 'typeId';
|
|
11
11
|
readonly type: string;
|
|
12
12
|
} | {
|
|
13
13
|
readonly kind: 'builtin';
|
|
14
14
|
readonly type: 'number' | 'boolean' | 'string';
|
|
15
15
|
};
|
|
16
|
-
interface OperationSignature {
|
|
16
|
+
export interface OperationSignature {
|
|
17
17
|
readonly forTypeId: string;
|
|
18
18
|
readonly method: string;
|
|
19
19
|
readonly args: ReadonlyArray<ArgSpec>;
|
|
20
20
|
readonly returns: ReturnSpec;
|
|
21
21
|
readonly capabilities?: ReadonlyArray<string>;
|
|
22
22
|
}
|
|
23
|
-
interface OperationRegistry {
|
|
23
|
+
export interface OperationRegistry {
|
|
24
24
|
register(op: OperationSignature): void;
|
|
25
25
|
byType(typeId: string): ReadonlyArray<OperationSignature>;
|
|
26
26
|
}
|
|
27
|
-
declare function createOperationRegistry(): OperationRegistry;
|
|
28
|
-
declare function hasAllCapabilities(capabilities: ReadonlyArray<string>, contractCapabilities?: Record<string, Record<string, boolean>>): boolean;
|
|
29
|
-
|
|
30
|
-
export { type ArgSpec, type OperationRegistry, type OperationSignature, type ReturnSpec, createOperationRegistry, hasAllCapabilities };
|
|
27
|
+
export declare function createOperationRegistry(): OperationRegistry;
|
|
28
|
+
export declare function hasAllCapabilities(capabilities: ReadonlyArray<string>, contractCapabilities?: Record<string, Record<string, boolean>>): boolean;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GACf;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAEjC,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAA;CAAE,CAAC;AAEjF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACvC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,kBAAkB,CAAC,CAAC;CAC3D;AAsBD,wBAAgB,uBAAuB,IAAI,iBAAiB,CAE3D;AAED,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,EACnC,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC7D,OAAO,CAWT"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/operations",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Target-neutral operation registry and capability helpers for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/plan": "0.3.0-dev.
|
|
8
|
+
"@prisma-next/plan": "0.3.0-dev.5"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@vitest/coverage-v8": "
|
|
12
|
-
"tsup": "
|
|
13
|
-
"typescript": "
|
|
14
|
-
"vitest": "
|
|
11
|
+
"@vitest/coverage-v8": "4.0.16",
|
|
12
|
+
"tsup": "8.5.1",
|
|
13
|
+
"typescript": "5.9.3",
|
|
14
|
+
"vitest": "4.0.16",
|
|
15
15
|
"@prisma-next/test-utils": "0.0.1"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
19
20
|
],
|
|
20
21
|
"exports": {
|
|
21
22
|
".": {
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
}
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
|
-
"build": "tsup --config tsup.config.ts",
|
|
28
|
+
"build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
|
|
28
29
|
"test": "vitest run --passWithNoTests",
|
|
29
30
|
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
30
31
|
"typecheck": "tsc --project tsconfig.json --noEmit",
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type ArgSpec =
|
|
2
|
+
| { readonly kind: 'typeId'; readonly type: string }
|
|
3
|
+
| { readonly kind: 'param' }
|
|
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>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface OperationRegistry {
|
|
19
|
+
register(op: OperationSignature): void;
|
|
20
|
+
byType(typeId: string): ReadonlyArray<OperationSignature>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class OperationRegistryImpl implements OperationRegistry {
|
|
24
|
+
private readonly operations = new Map<string, OperationSignature[]>();
|
|
25
|
+
|
|
26
|
+
register(op: OperationSignature): void {
|
|
27
|
+
const existing = this.operations.get(op.forTypeId) ?? [];
|
|
28
|
+
const duplicate = existing.find((existingOp) => existingOp.method === op.method);
|
|
29
|
+
if (duplicate) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Operation method "${op.method}" already registered for typeId "${op.forTypeId}"`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
existing.push(op);
|
|
35
|
+
this.operations.set(op.forTypeId, existing);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
byType(typeId: string): ReadonlyArray<OperationSignature> {
|
|
39
|
+
return this.operations.get(typeId) ?? [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function createOperationRegistry(): OperationRegistry {
|
|
44
|
+
return new OperationRegistryImpl();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function hasAllCapabilities(
|
|
48
|
+
capabilities: ReadonlyArray<string>,
|
|
49
|
+
contractCapabilities?: Record<string, Record<string, boolean>>,
|
|
50
|
+
): boolean {
|
|
51
|
+
if (!contractCapabilities) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return capabilities.every((cap) => {
|
|
56
|
+
const [namespace, ...rest] = cap.split('.');
|
|
57
|
+
const key = rest.join('.');
|
|
58
|
+
const namespaceCaps = namespace ? contractCapabilities[namespace] : undefined;
|
|
59
|
+
return namespaceCaps?.[key] === true;
|
|
60
|
+
});
|
|
61
|
+
}
|