@deessejs/functions 0.0.59 → 0.0.60

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,6 +1,8 @@
1
1
  import { MergeExtensions } from "../extensions/types";
2
2
  export declare function defineContext<TContext extends Record<string, any>>(): {
3
- withExtensions: <TExtensions extends readonly any[]>(config: {
3
+ withExtensions: <TExtensions extends readonly {
4
+ functions: (ctx: TContext) => any;
5
+ }[]>(config: {
4
6
  extensions: readonly [...TExtensions];
5
7
  }) => MergeExtensions<TContext, TExtensions> & {
6
8
  context: TContext;
@@ -3,16 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineContext = defineContext;
4
4
  function defineContext() {
5
5
  return {
6
- // ON NE MET AUCUNE CONTRAINTE ICI.
7
- // TExtensions capture le type brut et exact (ex: le générique <C> de rpc).
6
+ // FIX CRUCIAL :
7
+ // On contraint TExtensions pour que chaque extension ait une méthode 'functions'
8
+ // qui accepte TContext. Cela force TS à instancier le générique <C> de rpc immédiatement.
8
9
  withExtensions: (config) => {
9
10
  const runtimeBuilder = {};
10
11
  const dummyContext = {};
11
12
  for (const extension of config.extensions) {
12
- // Cast runtime uniquement pour éviter les erreurs TS dans la boucle
13
- const ext = extension;
14
- if (ext && typeof ext.functions === "function") {
15
- const extensionMethods = ext.functions(dummyContext);
13
+ // Au runtime, on vérifie juste que c'est une fonction
14
+ if (extension && typeof extension.functions === "function") {
15
+ const extensionMethods = extension.functions(dummyContext);
16
16
  Object.assign(runtimeBuilder, extensionMethods);
17
17
  }
18
18
  }
@@ -1,26 +1,13 @@
1
1
  import z, { ZodType } from "zod";
2
- /**
3
- * LA SOLUTION MATHÉMATIQUE.
4
- * On ne demande pas "Est-ce que ça marche ?" (extends), on dit "Fais-le marcher !" (&).
5
- *
6
- * On crée une intersection entre :
7
- * 1. Ta fonction générique F: <C>(c: C) => API<C>
8
- * 2. Une fonction factice: (c: TContext) => unknown
9
- *
10
- * Pour calculer le ReturnType de cette intersection, TypeScript DOIT instancier
11
- * le générique <C> de F avec TContext.
12
- */
13
- type ApplyContext<F, C> = F extends (c: any) => any ? ReturnType<F & ((c: C) => unknown)> : never;
14
- export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
15
- functions: infer F;
16
- } ? ApplyContext<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
17
- export type ExtensionBase = {
2
+ export type ExtensionBase<C = any> = {
18
3
  context: any;
19
- functions: any;
4
+ functions: (context: C) => any;
20
5
  };
6
+ export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
7
+ functions: (ctx: any) => infer R;
8
+ } ? R : {}) & MergeExtensions<TContext, Tail> : {};
21
9
  export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
22
10
  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]) => {
23
11
  context: TContextAddon;
24
12
  functions: TFunctionsFactory;
25
13
  };
26
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
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",