@deessejs/functions 0.0.62 → 0.0.63

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.
@@ -3,16 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineContext = defineContext;
4
4
  function defineContext() {
5
5
  return {
6
- // ON UTILISE 'readonly any[]'.
7
- // C'est vital. Si on met un type plus précis ici, TypeScript risque
8
- // de simplifier le générique de 'rpc' avant qu'on puisse l'injecter.
6
+ // any[] préserve la généricité de rpc jusqu'au bout
9
7
  withExtensions: (config) => {
10
8
  const runtimeBuilder = {};
11
9
  const dummyContext = {};
12
10
  for (const extension of config.extensions) {
13
- // Runtime only
14
- if (extension && typeof extension.functions === "function") {
15
- const extensionMethods = extension.functions(dummyContext);
11
+ // Cast runtime uniquement
12
+ const ext = extension;
13
+ if (ext && typeof ext.functions === "function") {
14
+ const extensionMethods = ext.functions(dummyContext);
16
15
  Object.assign(runtimeBuilder, extensionMethods);
17
16
  }
18
17
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extensions = extensions;
4
- // N'importe PAS FunctionsForContext ici pour le typage, ça brise la généricité.
4
+ // Retirez l'import de Extension et FunctionsForContext s'ils ne servent qu'au typage de retour
5
5
  function extensions(config) {
6
- // On laisse TypeScript retourner l'objet tel quel.
6
+ // SUPPRESSION DU TYPE DE RETOUR EXPLICITE ": Extension<...>"
7
+ // C'est ça qui causait le "unknown". On laisse TS inférer le type réel.
7
8
  return (...args) => {
8
9
  const optionsInput = args[0];
9
10
  const options = (config.schema ? config.schema.parse(optionsInput) : undefined);
@@ -1,20 +1,17 @@
1
1
  import z, { ZodType } from "zod";
2
2
  /**
3
- * LA SOLUTION ULTIME : Intersection de ReturnType.
4
- *
5
- * 1. F & ((c: C) => unknown) : On crée une fonction hybride qui doit satisfaire
6
- * TA fonction générique ET une fonction qui prend ton Contexte.
7
- * 2. ReturnType<...> : Pour résoudre le type de retour de cette hybride,
8
- * TypeScript est obligé de remplacer le générique de F par C.
9
- * 3. Le "& unknown" assure qu'on ne pollue pas le type de retour (R & unknown = R).
3
+ * Maintenant que F est une fonction générique "propre" (grâce à l'étape 1),
4
+ * l'inférence directe fonctionne parfaitement.
5
+ * TS va voir : <C>(c: C) => ... extends (c: TContext) => infer R
6
+ * Il va mathématiquement remplacer C par TContext.
10
7
  */
11
- type ApplyContext<F, C> = F extends (c: any) => any ? ReturnType<F & ((c: C) => unknown)> : never;
8
+ type ApplyContext<F, C> = F extends (context: C) => infer R ? R : never;
12
9
  export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
13
10
  functions: infer F;
14
11
  } ? ApplyContext<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
15
- export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
16
- export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctionsFactory> = (...args: TSchema extends ZodType ? [options: z.input<TSchema>] : [options?: undefined]) => {
17
- context: TContextAddon;
18
- functions: TFunctionsFactory;
12
+ export type ExtensionBase = {
13
+ context: any;
14
+ functions: any;
19
15
  };
16
+ export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
20
17
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.62",
3
+ "version": "0.0.63",
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",