@deessejs/functions 0.0.16 → 0.0.17
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/context/define.d.ts +7 -17
- package/dist/context/define.js +8 -18
- package/dist/extensions/index.d.ts +2 -0
- package/dist/extensions/index.js +5 -0
- package/dist/extensions/rpc.d.ts +19 -0
- package/dist/extensions/rpc.js +26 -0
- package/dist/extensions/types.d.ts +4 -0
- package/dist/extensions/types.js +2 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +2 -0
- package/package.json +1 -1
package/dist/context/define.d.ts
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export declare function defineContext<TContext extends Record<string, unknown>>(): {
|
|
9
|
-
query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception>(options: {
|
|
10
|
-
args: TArgs;
|
|
11
|
-
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
12
|
-
}) => QueryDefinition<TContext, TArgs, TOutput, TError>;
|
|
13
|
-
mutation: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception>(options: {
|
|
14
|
-
args: TArgs;
|
|
15
|
-
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
16
|
-
}) => MutationDefinition<TContext, TArgs, TOutput, TError>;
|
|
17
|
-
group: <T extends Record<string, APINode>>(definitions: T) => T;
|
|
1
|
+
import { UnionToIntersection } from "../utils";
|
|
2
|
+
type MergeExtensions<TContext, TExtensions extends any[]> = UnionToIntersection<ReturnType<TExtensions[number] extends (...args: any) => any ? (ctx: TContext) => ReturnType<ReturnType<TExtensions[number]>> : never>>;
|
|
3
|
+
export declare function defineContext<TBaseContext extends Record<string, unknown>, TExtensions extends Array<(...args: any) => any>>(config: {
|
|
4
|
+
extensions: TExtensions;
|
|
5
|
+
}): MergeExtensions<TBaseContext, TExtensions> & {
|
|
6
|
+
context: TBaseContext;
|
|
18
7
|
};
|
|
8
|
+
export {};
|
package/dist/context/define.js
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
|
-
function defineContext() {
|
|
4
|
+
function defineContext(config) {
|
|
5
|
+
const builder = {};
|
|
6
|
+
for (const createExtension of config.extensions) {
|
|
7
|
+
const extensionInstance = createExtension();
|
|
8
|
+
Object.assign(builder, extensionInstance);
|
|
9
|
+
}
|
|
5
10
|
return {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
_type: "query",
|
|
9
|
-
args: options.args,
|
|
10
|
-
handler: options.handler,
|
|
11
|
-
};
|
|
12
|
-
},
|
|
13
|
-
mutation: (options) => {
|
|
14
|
-
return {
|
|
15
|
-
_type: "mutation",
|
|
16
|
-
args: options.args,
|
|
17
|
-
handler: options.handler,
|
|
18
|
-
};
|
|
19
|
-
},
|
|
20
|
-
group: (definitions) => {
|
|
21
|
-
return definitions;
|
|
22
|
-
},
|
|
11
|
+
...builder,
|
|
12
|
+
context: {},
|
|
23
13
|
};
|
|
24
14
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import z, { ZodType } from "zod";
|
|
2
|
+
import { Exception } from "../errors/types";
|
|
3
|
+
import { AsyncResult } from "../types";
|
|
4
|
+
import { CommandsDefinition, MutationDefinition, QueryDefinition } from "../context/types";
|
|
5
|
+
export type APINode = CommandsDefinition | {
|
|
6
|
+
[key: string]: APINode;
|
|
7
|
+
};
|
|
8
|
+
export declare const rpc: () => <TContext>() => {
|
|
9
|
+
query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception>(options: {
|
|
10
|
+
args: TArgs;
|
|
11
|
+
handler: (ctx: TContext, // <--- Le contexte est injecté ici
|
|
12
|
+
args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
13
|
+
}) => QueryDefinition<TContext, TArgs, TOutput, TError>;
|
|
14
|
+
mutation: <TArgs extends ZodType<any, any, any>, TOutput_1, TError_1 extends Exception = Exception>(options: {
|
|
15
|
+
args: TArgs;
|
|
16
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
17
|
+
}) => MutationDefinition<TContext, TArgs, TOutput_1, TError_1>;
|
|
18
|
+
group: <T extends Record<string, APINode>>(definitions: T) => T;
|
|
19
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rpc = void 0;
|
|
4
|
+
// Cette fonction retourne une "ExtensionFn"
|
|
5
|
+
const rpc = () => {
|
|
6
|
+
return () => ({
|
|
7
|
+
query: (options) => {
|
|
8
|
+
return {
|
|
9
|
+
_type: "query",
|
|
10
|
+
args: options.args,
|
|
11
|
+
handler: options.handler,
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
mutation: (options) => {
|
|
15
|
+
return {
|
|
16
|
+
_type: "mutation",
|
|
17
|
+
args: options.args,
|
|
18
|
+
handler: options.handler,
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
group: (definitions) => {
|
|
22
|
+
return definitions;
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
exports.rpc = rpc;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
package/package.json
CHANGED