@deessejs/functions 0.0.41 → 0.0.43
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.js
CHANGED
|
@@ -4,16 +4,15 @@ exports.defineContext = defineContext;
|
|
|
4
4
|
function defineContext() {
|
|
5
5
|
return {
|
|
6
6
|
withExtensions: (config) => {
|
|
7
|
-
// Créer un contexte
|
|
7
|
+
// Créer un contexte qui préserve le type TContext
|
|
8
8
|
const runtimeContext = {};
|
|
9
9
|
// Appliquer les extensions en préservant les types
|
|
10
10
|
const result = {
|
|
11
11
|
context: runtimeContext,
|
|
12
12
|
};
|
|
13
13
|
for (const extension of config.extensions) {
|
|
14
|
-
//
|
|
15
|
-
const
|
|
16
|
-
const methods = methodsFactory(runtimeContext);
|
|
14
|
+
// Passer le contexte avec son type complet pour que l'inférence fonctionne
|
|
15
|
+
const methods = extension.functions(runtimeContext);
|
|
17
16
|
Object.assign(result, methods);
|
|
18
17
|
}
|
|
19
18
|
return result;
|
package/dist/context/types.d.ts
CHANGED
|
@@ -14,11 +14,11 @@ export type MutationDefinition<TContext, TArgs extends ZodType, TOutput, TError
|
|
|
14
14
|
};
|
|
15
15
|
export type CommandsDefinition = QueryDefinition<any, any, any, any> | MutationDefinition<any, any, any, any>;
|
|
16
16
|
export type FunctionsForContext<C> = {
|
|
17
|
-
query: <TArgs extends ZodType, TOutput, TError extends Exception>(def: QueryDefinition<C, TArgs, TOutput, TError>) =>
|
|
18
|
-
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>;
|
|
19
19
|
on?: <TEvent extends string, TPayload>(config: {
|
|
20
20
|
event: TEvent;
|
|
21
21
|
handler: (ctx: C, payload: TPayload) => AsyncResult<any, any>;
|
|
22
22
|
}) => any;
|
|
23
|
-
group?: <TGroup extends Record<string, CommandsDefinition>>(defs: TGroup) =>
|
|
23
|
+
group?: <TGroup extends Record<string, CommandsDefinition>>(defs: TGroup) => TGroup;
|
|
24
24
|
};
|
|
@@ -10,10 +10,10 @@ type FnCallSignatureMatchesWith<C, F> = F extends {
|
|
|
10
10
|
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
11
11
|
functions: infer F;
|
|
12
12
|
} ? FnCallSignatureMatchesWith<TContext, F> : {}) & MergeExtensions<TContext, Tail> : {};
|
|
13
|
-
/** Ici : functions est
|
|
13
|
+
/** Ici : functions est une fonction qui retourne les méthodes pour un contexte donné */
|
|
14
14
|
export type ExtensionBase = {
|
|
15
15
|
context: any;
|
|
16
|
-
functions: <C>(context: C) => FunctionsForContext<C>;
|
|
16
|
+
functions: <TOptions>(options: TOptions) => <C>(context: C) => FunctionsForContext<C>;
|
|
17
17
|
};
|
|
18
18
|
/** Helpers pour extensions/InferOptions et définition d'Extension */
|
|
19
19
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
package/package.json
CHANGED