@deessejs/functions 0.0.21 → 0.0.23
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 +6 -2
- package/dist/context/define.js +3 -3
- package/dist/extensions/index.d.ts +3 -2
- package/dist/extensions/index.js +14 -2
- package/dist/extensions/rpc.d.ts +8 -9
- package/dist/extensions/rpc.js +19 -23
- package/dist/extensions/types.d.ts +10 -3
- package/package.json +1 -1
package/dist/context/define.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { UnionToIntersection } from "../utils";
|
|
2
|
-
export type
|
|
2
|
+
export type ExtensionInstance = {
|
|
3
|
+
context: Record<string, any>;
|
|
4
|
+
functions: (...args: any[]) => any;
|
|
5
|
+
};
|
|
6
|
+
export type MergeExtensions<TContext, TExtensions extends Array<ExtensionInstance>> = UnionToIntersection<ReturnType<TExtensions[number]["functions"]>>;
|
|
3
7
|
export declare function defineContext<TContext extends Record<string, unknown>>(): {
|
|
4
|
-
withExtensions: <TExtensions extends Array<
|
|
8
|
+
withExtensions: <TExtensions extends Array<ExtensionInstance>>(config: {
|
|
5
9
|
extensions: TExtensions;
|
|
6
10
|
}) => MergeExtensions<TContext, TExtensions> & {
|
|
7
11
|
context: TContext;
|
package/dist/context/define.js
CHANGED
|
@@ -5,9 +5,9 @@ function defineContext() {
|
|
|
5
5
|
return {
|
|
6
6
|
withExtensions: (config) => {
|
|
7
7
|
const builder = {};
|
|
8
|
-
for (const
|
|
9
|
-
const
|
|
10
|
-
Object.assign(builder,
|
|
8
|
+
for (const extension of config.extensions) {
|
|
9
|
+
const extensionMethods = extension.functions();
|
|
10
|
+
Object.assign(builder, extensionMethods);
|
|
11
11
|
}
|
|
12
12
|
return {
|
|
13
13
|
...builder,
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ZodType } from "zod";
|
|
2
|
+
import { Extension, ExtensionConfig } from "./types";
|
|
3
|
+
export declare function extensions<TSchema extends ZodType | undefined = undefined, TContextAddon extends Record<string, unknown> = Record<string, unknown>, TFunctions extends Record<string, unknown> = Record<string, unknown>>(config: ExtensionConfig<TSchema, TContextAddon, TFunctions>): Extension<TSchema, TContextAddon, TFunctions>;
|
package/dist/extensions/index.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extensions = void 0;
|
|
4
|
-
const extensions = (config) => { };
|
|
5
3
|
exports.extensions = extensions;
|
|
4
|
+
function extensions(config) {
|
|
5
|
+
return (...args) => {
|
|
6
|
+
const optionsInput = args[0];
|
|
7
|
+
const options = (config.schema ? config.schema.parse(optionsInput) : undefined);
|
|
8
|
+
const contextPart = config.context
|
|
9
|
+
? config.context(options)
|
|
10
|
+
: {};
|
|
11
|
+
const functionsBuilder = config.functions(options);
|
|
12
|
+
return {
|
|
13
|
+
context: contextPart,
|
|
14
|
+
functions: functionsBuilder,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
package/dist/extensions/rpc.d.ts
CHANGED
|
@@ -5,15 +5,14 @@ import { CommandsDefinition, MutationDefinition, QueryDefinition } from "../cont
|
|
|
5
5
|
export type APINode = CommandsDefinition | {
|
|
6
6
|
[key: string]: APINode;
|
|
7
7
|
};
|
|
8
|
-
export declare const rpc:
|
|
9
|
-
query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception
|
|
8
|
+
export declare const rpc: import("./types").Extension<undefined, Record<string, unknown>, {
|
|
9
|
+
query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception>(options: {
|
|
10
10
|
args: TArgs;
|
|
11
|
-
handler: (ctx:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
mutation: <TArgs extends ZodType<any, any, any>, TOutput_1, TError_1 extends Exception = Exception>(options: {
|
|
11
|
+
handler: (ctx: unknown, args: z.core.output<TArgs>) => AsyncResult<TOutput, TError>;
|
|
12
|
+
}) => QueryDefinition<unknown, TArgs, TOutput, TError>;
|
|
13
|
+
mutation: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception>(options: {
|
|
15
14
|
args: TArgs;
|
|
16
|
-
handler: (ctx:
|
|
17
|
-
}) => MutationDefinition<
|
|
15
|
+
handler: (ctx: unknown, args: z.core.output<TArgs>) => AsyncResult<TOutput, TError>;
|
|
16
|
+
}) => MutationDefinition<unknown, TArgs, TOutput, TError>;
|
|
18
17
|
group: <T extends Record<string, APINode>>(definitions: T) => T;
|
|
19
|
-
}
|
|
18
|
+
}>;
|
package/dist/extensions/rpc.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rpc = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
exports.rpc = rpc;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
exports.rpc = (0, _1.extensions)({
|
|
6
|
+
// Pas d'options, pas de contexte ajouté
|
|
7
|
+
schema: undefined,
|
|
8
|
+
context: undefined,
|
|
9
|
+
// Définition des fonctions
|
|
10
|
+
functions: (_options) => {
|
|
11
|
+
// On retourne la fonction générique
|
|
12
|
+
return () => ({
|
|
13
|
+
query: (options) => {
|
|
14
|
+
return { _type: "query", ...options };
|
|
15
|
+
},
|
|
16
|
+
mutation: (options) => {
|
|
17
|
+
return { _type: "mutation", ...options };
|
|
18
|
+
},
|
|
19
|
+
group: (definitions) => definitions,
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import z, { ZodType } from "zod";
|
|
2
|
+
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
3
|
+
export type ExtensionConfig<TSchema extends ZodType | undefined, TContext extends Record<string, unknown>, TFunctions extends Record<string, unknown>> = {
|
|
4
|
+
schema: TSchema;
|
|
5
|
+
context?: (options: InferOptions<TSchema>) => TContext;
|
|
6
|
+
functions: (options: InferOptions<TSchema>) => <TAppContext extends TContext>() => TFunctions;
|
|
7
|
+
};
|
|
8
|
+
export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctions extends Record<string, unknown>> = (...args: TSchema extends ZodType ? [options: z.input<TSchema>] : [options?: undefined]) => {
|
|
9
|
+
context: TContextAddon;
|
|
10
|
+
functions: <TAppContext>() => TFunctions;
|
|
4
11
|
};
|
package/package.json
CHANGED