@deessejs/functions 0.0.45 → 0.0.47
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 +5 -11
- package/dist/context/define.js +12 -6
- package/dist/context/types.d.ts +5 -9
- package/dist/extensions/index.d.ts +8 -9
- package/dist/extensions/index.js +11 -3
- package/dist/extensions/rpc.d.ts +26 -25
- package/dist/extensions/rpc.js +9 -9
- package/package.json +1 -1
package/dist/context/define.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { ExtensionBase } from "../extensions";
|
|
2
|
-
export declare function defineContext<TContext
|
|
3
|
-
withExtensions: <
|
|
4
|
-
extensions: [...
|
|
5
|
-
}) =>
|
|
1
|
+
import { ExtensionBase, MergeExtensions } from "../extensions/types";
|
|
2
|
+
export declare function defineContext<TContext extends Record<string, any>>(): {
|
|
3
|
+
withExtensions: <TExtensions extends readonly ExtensionBase[]>(config: {
|
|
4
|
+
extensions: readonly [...TExtensions];
|
|
5
|
+
}) => MergeExtensions<TContext, TExtensions> & {
|
|
6
6
|
context: TContext;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
type MergeAllExtensions<TContext, TExts extends readonly any[]> = {
|
|
10
|
-
[K in keyof TExts]: TExts[K] extends {
|
|
11
|
-
functions: infer F;
|
|
12
|
-
} ? F extends (ctx: TContext) => infer R ? R : never : never;
|
|
13
|
-
}[number];
|
|
14
|
-
export {};
|
package/dist/context/define.js
CHANGED
|
@@ -4,12 +4,18 @@ exports.defineContext = defineContext;
|
|
|
4
4
|
function defineContext() {
|
|
5
5
|
return {
|
|
6
6
|
withExtensions: (config) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
// runtime builder (inchangé)
|
|
8
|
+
const runtimeBuilder = {};
|
|
9
|
+
const dummyContext = {};
|
|
10
|
+
for (const extension of config.extensions) {
|
|
11
|
+
// appele runtime, pour construire les méthodes effectives
|
|
12
|
+
const extensionMethods = extension.functions(dummyContext);
|
|
13
|
+
Object.assign(runtimeBuilder, extensionMethods);
|
|
14
|
+
} // Typage public : MergeExtensions instancié avec le TContext exact
|
|
15
|
+
return {
|
|
16
|
+
...runtimeBuilder,
|
|
17
|
+
context: {},
|
|
18
|
+
};
|
|
13
19
|
},
|
|
14
20
|
};
|
|
15
21
|
}
|
package/dist/context/types.d.ts
CHANGED
|
@@ -6,23 +6,19 @@ export type CommandDefinition<TContext, TArgs extends ZodType, TOutput, TError e
|
|
|
6
6
|
args: TArgs;
|
|
7
7
|
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
8
8
|
};
|
|
9
|
-
export type QueryDefinition<TContext, TArgs extends
|
|
9
|
+
export type QueryDefinition<TContext, TArgs extends ZodType, TOutput, TError extends Exception> = CommandDefinition<TContext, TArgs, TOutput, TError> & {
|
|
10
10
|
_type: "query";
|
|
11
|
-
args: TArgs;
|
|
12
|
-
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
13
11
|
};
|
|
14
|
-
export type MutationDefinition<TContext, TArgs extends
|
|
12
|
+
export type MutationDefinition<TContext, TArgs extends ZodType, TOutput, TError extends Exception> = CommandDefinition<TContext, TArgs, TOutput, TError> & {
|
|
15
13
|
_type: "mutation";
|
|
16
|
-
args: TArgs;
|
|
17
|
-
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
18
14
|
};
|
|
19
15
|
export type CommandsDefinition = QueryDefinition<any, any, any, any> | MutationDefinition<any, any, any, any>;
|
|
20
16
|
export type FunctionsForContext<C> = {
|
|
21
|
-
query: <TArgs extends ZodType, TOutput, TError extends Exception>(def: QueryDefinition<C, TArgs, TOutput, TError>) =>
|
|
22
|
-
mutation: <TArgs extends ZodType, TOutput, TError extends Exception>(def: MutationDefinition<C, TArgs, TOutput, TError>) =>
|
|
17
|
+
query: <TArgs extends ZodType, TOutput, TError extends Exception>(def: QueryDefinition<C, TArgs, TOutput, TError>) => QueryDefinition<C, TArgs, TOutput, TError>;
|
|
18
|
+
mutation: <TArgs extends ZodType, TOutput, TError extends Exception>(def: MutationDefinition<C, TArgs, TOutput, TError>) => MutationDefinition<C, TArgs, TOutput, TError>;
|
|
23
19
|
on?: <TEvent extends string, TPayload>(config: {
|
|
24
20
|
event: TEvent;
|
|
25
21
|
handler: (ctx: C, payload: TPayload) => AsyncResult<any, any>;
|
|
26
22
|
}) => any;
|
|
27
|
-
group?: <TGroup extends Record<string, CommandsDefinition>>(defs: TGroup) =>
|
|
23
|
+
group?: <TGroup extends Record<string, CommandsDefinition>>(defs: TGroup) => TGroup;
|
|
28
24
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
export declare function extensions<TFunctions extends FunctionsForContext<any>>(config: {
|
|
1
|
+
import { ZodType } from "zod";
|
|
2
|
+
import { Extension, InferOptions } from "./types";
|
|
3
|
+
import { FunctionsForContext } from "..";
|
|
4
|
+
export declare function extensions<TSchema extends ZodType | undefined = undefined, TContextAddon extends Record<string, unknown> = Record<string, unknown>, TFunctionsFactory extends (<C>(context: C) => FunctionsForContext<C>) = (<C>(context: C) => FunctionsForContext<C>)>(config: {
|
|
8
5
|
name: string;
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
schema?: TSchema;
|
|
7
|
+
context?: (options: InferOptions<TSchema>) => TContextAddon;
|
|
8
|
+
functions: (options: InferOptions<TSchema>) => TFunctionsFactory;
|
|
9
|
+
}): Extension<TSchema, TContextAddon, TFunctionsFactory>;
|
package/dist/extensions/index.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// extensions/index.ts (ou extensions.ts)
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.extensions = extensions;
|
|
4
5
|
function extensions(config) {
|
|
5
|
-
return () =>
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
return (...args) => {
|
|
7
|
+
const optionsInput = args[0];
|
|
8
|
+
const options = (config.schema ? config.schema.parse(optionsInput) : undefined);
|
|
9
|
+
const contextPart = config.context ? config.context(options) : {};
|
|
10
|
+
const functionsBuilder = config.functions(options);
|
|
11
|
+
return {
|
|
12
|
+
context: contextPart,
|
|
13
|
+
functions: functionsBuilder,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
8
16
|
}
|
package/dist/extensions/rpc.d.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { Exception } from "../errors/types";
|
|
3
2
|
import { AsyncResult } from "../types";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
3
|
+
export declare const rpc: () => {
|
|
4
|
+
functions: <TContext>() => {
|
|
5
|
+
query: <TArgs extends z.ZodType, TOutput, TError = never>(def: {
|
|
6
|
+
args: TArgs;
|
|
7
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
8
|
+
}) => {
|
|
9
|
+
args: TArgs;
|
|
10
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
11
|
+
_type: "query";
|
|
12
|
+
};
|
|
13
|
+
mutation: <TArgs extends z.ZodType, TOutput_1, TError_1 = never>(def: {
|
|
14
|
+
args: TArgs;
|
|
15
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
16
|
+
}) => {
|
|
17
|
+
args: TArgs;
|
|
18
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
19
|
+
_type: "mutation";
|
|
20
|
+
};
|
|
21
|
+
group: <G>(group: G) => G;
|
|
22
|
+
on: <TPayload>(config: {
|
|
23
|
+
event: string;
|
|
24
|
+
handler: (ctx: TContext, payload: TPayload) => AsyncResult<any, any>;
|
|
25
|
+
}) => {
|
|
26
|
+
event: string;
|
|
27
|
+
handler: (ctx: TContext, payload: TPayload) => AsyncResult<any, any>;
|
|
28
|
+
};
|
|
28
29
|
};
|
|
29
30
|
};
|
package/dist/extensions/rpc.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rpc =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
group: (g) => g,
|
|
3
|
+
exports.rpc = void 0;
|
|
4
|
+
const rpc = () => ({
|
|
5
|
+
functions: () => ({
|
|
6
|
+
query: (def) => ({ _type: "query", ...def }),
|
|
7
|
+
mutation: (def) => ({ _type: "mutation", ...def }),
|
|
8
|
+
group: (group) => group,
|
|
10
9
|
on: (config) => config,
|
|
11
|
-
}
|
|
12
|
-
}
|
|
10
|
+
}),
|
|
11
|
+
});
|
|
12
|
+
exports.rpc = rpc;
|
package/package.json
CHANGED