@deessejs/functions 0.0.49 → 0.0.50
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/extensions/types.d.ts +18 -19
- package/dist/extensions/types.js +0 -1
- package/package.json +1 -1
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
/**
|
|
3
|
+
* 1. FIX MAJEUR : ApplyContext
|
|
4
|
+
* Au lieu de deviner le type générique, on force TypeScript à appliquer
|
|
5
|
+
* ton TContext (ex: { user: ... }) à la fonction de l'extension.
|
|
6
|
+
*/
|
|
7
|
+
type ApplyContext<F, C> = F extends (context: C) => infer R ? R : never;
|
|
8
|
+
/**
|
|
9
|
+
* 2. FIX MAJEUR : MergeExtensions
|
|
10
|
+
* On utilise ApplyContext pour résoudre le type de retour précis avec le contexte injecté.
|
|
11
|
+
*/
|
|
10
12
|
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
11
13
|
functions: infer F;
|
|
12
|
-
} ?
|
|
13
|
-
/**
|
|
14
|
+
} ? ApplyContext<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
|
|
15
|
+
/**
|
|
16
|
+
* 3. FIX MAJEUR : ExtensionBase
|
|
17
|
+
* On met 'any' pour éviter que TypeScript ne simplifie le type de ton extension
|
|
18
|
+
* avant qu'on ait pu l'analyser. Ça débloque l'inférence.
|
|
19
|
+
*/
|
|
14
20
|
export type ExtensionBase = {
|
|
15
21
|
context: any;
|
|
16
|
-
functions:
|
|
22
|
+
functions: (context: any) => any;
|
|
17
23
|
};
|
|
18
|
-
/** Helpers pour extensions/InferOptions et définition d'Extension */
|
|
19
24
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
20
|
-
export type
|
|
21
|
-
name: string;
|
|
22
|
-
schema?: TSchema;
|
|
23
|
-
context?: (options: InferOptions<TSchema>) => TContextAddon;
|
|
24
|
-
functions: (options: InferOptions<TSchema>) => (<C>(context: C) => any);
|
|
25
|
-
};
|
|
26
|
-
export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctionsFactory extends (<C>(context: C) => any)> = (...args: TSchema extends ZodType ? [options: z.input<TSchema>] : [options?: undefined]) => {
|
|
25
|
+
export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctionsFactory extends <C>(context: C) => any> = (...args: TSchema extends ZodType ? [options: z.input<TSchema>] : [options?: undefined]) => {
|
|
27
26
|
context: TContextAddon;
|
|
28
27
|
functions: TFunctionsFactory;
|
|
29
28
|
};
|
package/dist/extensions/types.js
CHANGED
package/package.json
CHANGED