@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.
@@ -1,29 +1,28 @@
1
1
  import z, { ZodType } from "zod";
2
- import { FunctionsForContext } from "../context";
3
- /** Utilitaire d'inférence d'appel générique (déjà présent chez toi) */
4
- type FnCallSignatureMatchesWith<C, F> = F extends {
5
- (context: C): infer R;
6
- } ? R : F extends {
7
- <U>(context: U): infer RGeneric;
8
- } ? RGeneric : F extends (context: any) => infer R ? R : never;
9
- /** MergeExtensions : applique la logique d'inférence sur une tuple d'extensions */
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
- } ? FnCallSignatureMatchesWith<TContext, F> : {}) & MergeExtensions<TContext, Tail> : {};
13
- /** Ici : functions est *explicitement* une call signature générique */
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: <C>(context: C) => FunctionsForContext<C>;
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 ExtensionConfig<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>> = {
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
  };
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // types.ts (ou fichier équivalent)
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "description": "A powerful utility library for building type-safe APIs and functions with context management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",