@deessejs/functions 0.0.32 → 0.0.34

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,7 +1,7 @@
1
1
  import { ExtensionBase, MergeExtensions } from "../extensions/types";
2
2
  export declare function defineContext<TContext extends Record<string, any>>(): {
3
- withExtensions: <const TExtensions extends readonly ExtensionBase[]>(config: {
4
- extensions: TExtensions;
3
+ withExtensions: <TExtensions extends readonly ExtensionBase[]>(config: {
4
+ extensions: readonly [...TExtensions];
5
5
  }) => MergeExtensions<TContext, TExtensions> & {
6
6
  context: TContext;
7
7
  };
@@ -3,17 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineContext = defineContext;
4
4
  function defineContext() {
5
5
  return {
6
- // <const TExtensions> (TS 5.0) ou readonly permet de dire à TS :
7
- // "Ne traite pas ça comme un tableau générique, mais comme une suite précise d'éléments"
8
6
  withExtensions: (config) => {
9
7
  const builder = {};
10
8
  const dummyContext = {};
11
9
  for (const extension of config.extensions) {
12
- // Runtime : on exécute et on fusionne
13
10
  const extensionMethods = extension.functions(dummyContext);
14
11
  Object.assign(builder, extensionMethods);
15
12
  }
16
- // Typage : On utilise la fusion récursive
17
13
  return {
18
14
  ...builder,
19
15
  context: {},
@@ -4,11 +4,11 @@ export type ExtensionBase = {
4
4
  context: any;
5
5
  functions: (context: any) => any;
6
6
  };
7
- export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
8
- functions: (ctx: TContext) => infer R;
9
- } ? R : Head extends {
10
- functions: (ctx: any) => infer R;
11
- } ? (R extends (ctx: TContext) => infer U ? U : R) : {}) & MergeExtensions<TContext, Tail> : {};
7
+ type ExtractFunctionsReturn<F, C> = F extends (context: C) => infer R ? R : F extends (context: any) => infer R ? R : never;
8
+ export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? // On récupère 'functions' du Head (s'il existe) et on l'instancie avec TContext
9
+ (Head extends {
10
+ functions: infer F;
11
+ } ? ExtractFunctionsReturn<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
12
12
  export type ExtensionConfig<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>> = {
13
13
  name: string;
14
14
  schema?: TSchema;
@@ -19,3 +19,4 @@ export type Extension<TSchema extends ZodType | undefined, TContextAddon extends
19
19
  context: TContextAddon;
20
20
  functions: TFunctionsFactory;
21
21
  };
22
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
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",