@deessejs/functions 0.0.36 → 0.0.37

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,17 +1,21 @@
1
1
  "use strict";
2
+ // defineContext.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.defineContext = defineContext;
4
5
  function defineContext() {
5
6
  return {
6
7
  withExtensions: (config) => {
7
- const builder = {};
8
+ // runtime builder (inchangé)
9
+ const runtimeBuilder = {};
8
10
  const dummyContext = {};
9
11
  for (const extension of config.extensions) {
12
+ // appele runtime, pour construire les méthodes effectives
10
13
  const extensionMethods = extension.functions(dummyContext);
11
- Object.assign(builder, extensionMethods);
14
+ Object.assign(runtimeBuilder, extensionMethods);
12
15
  }
16
+ // On retourne runtimeBuilder mais on force le type public attendu.
13
17
  return {
14
- ...builder,
18
+ ...runtimeBuilder,
15
19
  context: {},
16
20
  };
17
21
  },
@@ -5,9 +5,7 @@ function extensions(config) {
5
5
  return (...args) => {
6
6
  const optionsInput = args[0];
7
7
  const options = (config.schema ? config.schema.parse(optionsInput) : undefined);
8
- const contextPart = config.context
9
- ? config.context(options)
10
- : {};
8
+ const contextPart = config.context ? config.context(options) : {};
11
9
  const functionsBuilder = config.functions(options);
12
10
  return {
13
11
  context: contextPart,
@@ -1,24 +1,28 @@
1
1
  import z, { ZodType } from "zod";
2
- export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
3
- export type ExtensionBase = {
4
- context: any;
5
- functions: <C>(context: C) => any;
6
- };
2
+ /** Utilitaire d'inférence d'appel générique (déjà présent chez toi) */
7
3
  type FnCallSignatureMatchesWith<C, F> = F extends {
8
4
  (context: C): infer R;
9
5
  } ? R : F extends {
10
6
  <U>(context: U): infer RGeneric;
11
7
  } ? RGeneric : F extends (context: any) => infer R ? R : never;
8
+ /** MergeExtensions : applique la logique d'inférence sur une tuple d'extensions */
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
  } ? FnCallSignatureMatchesWith<TContext, F> : {}) & MergeExtensions<TContext, Tail> : {};
12
+ /** Ici : functions est *explicitement* une call signature générique */
13
+ export type ExtensionBase = {
14
+ context: any;
15
+ functions: <C>(context: C) => any;
16
+ };
17
+ /** Helpers pour extensions/InferOptions et définition d'Extension */
18
+ export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
15
19
  export type ExtensionConfig<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>> = {
16
20
  name: string;
17
21
  schema?: TSchema;
18
22
  context?: (options: InferOptions<TSchema>) => TContextAddon;
19
- functions: (options: InferOptions<TSchema>) => (context: any) => any;
23
+ functions: (options: InferOptions<TSchema>) => (<C>(context: C) => any);
20
24
  };
21
- export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctionsFactory extends (context: any) => 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]) => {
22
26
  context: TContextAddon;
23
27
  functions: TFunctionsFactory;
24
28
  };
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // types.ts (ou fichier équivalent)
2
3
  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.36",
3
+ "version": "0.0.37",
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",