@deessejs/functions 0.0.37 → 0.0.39
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
|
@@ -7,16 +7,24 @@ function defineContext() {
|
|
|
7
7
|
withExtensions: (config) => {
|
|
8
8
|
// runtime builder (inchangé)
|
|
9
9
|
const runtimeBuilder = {};
|
|
10
|
-
|
|
10
|
+
// Utiliser un contexte runtime vide, mais conserver le type complet
|
|
11
|
+
const runtimeContext = {};
|
|
11
12
|
for (const extension of config.extensions) {
|
|
12
|
-
//
|
|
13
|
-
const extensionMethods = extension.functions(
|
|
13
|
+
// Passer le contexte runtime complet (même vide) pour conserver les types
|
|
14
|
+
const extensionMethods = extension.functions(runtimeContext);
|
|
14
15
|
Object.assign(runtimeBuilder, extensionMethods);
|
|
15
16
|
}
|
|
16
|
-
//
|
|
17
|
+
// Créer un objet context qui préserve les types pour l'inférence
|
|
18
|
+
const contextProxy = new Proxy({}, {
|
|
19
|
+
get(_, prop) {
|
|
20
|
+
// Retourner undefined pour les propriétés inconnues, mais préserver le type
|
|
21
|
+
return runtimeContext[prop];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
// On retourne runtimeBuilder avec un contexte qui préserve les types
|
|
17
25
|
return {
|
|
18
26
|
...runtimeBuilder,
|
|
19
|
-
context:
|
|
27
|
+
context: contextProxy,
|
|
20
28
|
};
|
|
21
29
|
},
|
|
22
30
|
};
|
package/dist/context/types.d.ts
CHANGED
|
@@ -13,3 +13,12 @@ export type MutationDefinition<TContext, TArgs extends ZodType, TOutput, TError
|
|
|
13
13
|
_type: "mutation";
|
|
14
14
|
};
|
|
15
15
|
export type CommandsDefinition = QueryDefinition<any, any, any, any> | MutationDefinition<any, any, any, any>;
|
|
16
|
+
export type FunctionsForContext<C> = {
|
|
17
|
+
query: <TArgs extends ZodType, TOutput, TError extends Exception>(def: QueryDefinition<C, TArgs, TOutput, TError>) => any;
|
|
18
|
+
mutation: <TArgs extends ZodType, TOutput, TError extends Exception>(def: MutationDefinition<C, TArgs, TOutput, TError>) => any;
|
|
19
|
+
on?: <TEvent extends string, TPayload>(config: {
|
|
20
|
+
event: TEvent;
|
|
21
|
+
handler: (ctx: C, payload: TPayload) => AsyncResult<any, any>;
|
|
22
|
+
}) => any;
|
|
23
|
+
group?: <TGroup extends Record<string, CommandsDefinition>>(defs: TGroup) => any;
|
|
24
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ZodType } from "zod";
|
|
2
2
|
import { Extension, InferOptions } from "./types";
|
|
3
|
-
|
|
3
|
+
import { FunctionsForContext } from "../context";
|
|
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: {
|
|
4
5
|
name: string;
|
|
5
6
|
schema?: TSchema;
|
|
6
7
|
context?: (options: InferOptions<TSchema>) => TContextAddon;
|
package/dist/extensions/index.js
CHANGED
package/dist/extensions/rpc.d.ts
CHANGED
|
@@ -16,4 +16,5 @@ export declare const rpc: import("./types").Extension<undefined, Record<string,
|
|
|
16
16
|
handler: (ctx: C, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
17
17
|
}) => MutationDefinition<C, TArgs, TOutput_1, TError_1>;
|
|
18
18
|
group: <T extends Record<string, APINode>>(definitions: T) => T;
|
|
19
|
+
context: C;
|
|
19
20
|
}>;
|
package/dist/extensions/rpc.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
+
import { FunctionsForContext } from "../context";
|
|
2
3
|
/** Utilitaire d'inférence d'appel générique (déjà présent chez toi) */
|
|
3
4
|
type FnCallSignatureMatchesWith<C, F> = F extends {
|
|
4
5
|
(context: C): infer R;
|
|
@@ -12,7 +13,7 @@ export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExt
|
|
|
12
13
|
/** Ici : functions est *explicitement* une call signature générique */
|
|
13
14
|
export type ExtensionBase = {
|
|
14
15
|
context: any;
|
|
15
|
-
functions: <C>(context: C) =>
|
|
16
|
+
functions: <C>(context: C) => FunctionsForContext<C>;
|
|
16
17
|
};
|
|
17
18
|
/** Helpers pour extensions/InferOptions et définition d'Extension */
|
|
18
19
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
package/package.json
CHANGED