@deessejs/functions 0.0.32 → 0.0.33

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,14 @@ 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
10
+ // runtime : on appelle la factory avec le contexte (dummy)
13
11
  const extensionMethods = extension.functions(dummyContext);
14
12
  Object.assign(builder, extensionMethods);
15
13
  }
16
- // Typage : On utilise la fusion récursive
17
14
  return {
18
15
  ...builder,
19
16
  context: {},
@@ -5,10 +5,10 @@ export type ExtensionBase = {
5
5
  functions: (context: any) => any;
6
6
  };
7
7
  export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
8
- functions: (ctx: TContext) => infer R;
8
+ functions: (context: TContext) => infer R;
9
9
  } ? R : Head extends {
10
- functions: (ctx: any) => infer R;
11
- } ? (R extends (ctx: TContext) => infer U ? U : R) : {}) & MergeExtensions<TContext, Tail> : {};
10
+ functions: (context: any) => infer R;
11
+ } ? R : {}) & 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
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",