@deessejs/functions 0.0.25 → 0.0.27

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,6 @@
1
1
  import { ExtensionInstance, MergeExtensions } from "../extensions/types";
2
2
  export declare function defineContext<TContext extends Record<string, any>>(): {
3
- withExtensions: <TExtensions extends Array<ExtensionInstance>>(config: {
3
+ withExtensions: <TExtensions extends ExtensionInstance[]>(config: {
4
4
  extensions: TExtensions;
5
5
  }) => MergeExtensions<TContext, TExtensions> & {
6
6
  context: TContext;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineContext = defineContext;
4
- // Utiliser 'any' ici évite des conflits de variance avec 'unknown'
4
+ // Utiliser 'Record<string, any>' aide à satisfaire les contraintes génériques des extensions
5
5
  function defineContext() {
6
6
  return {
7
+ // L'utilisation de 'const' (TS 5.0) ou juste la structure permet de bien inférer le Tuple
7
8
  withExtensions: (config) => {
8
9
  const builder = {};
9
10
  const dummyContext = {};
10
11
  for (const extension of config.extensions) {
11
- // Runtime : On appelle la factory
12
12
  const extensionMethods = extension.functions(dummyContext);
13
13
  Object.assign(builder, extensionMethods);
14
14
  }
@@ -3,15 +3,15 @@ import { UnionToIntersection } from "../utils";
3
3
  export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
4
4
  type ApplyContext<TFunc, TContext> = TFunc extends (context: TContext) => infer R ? R : never;
5
5
  export type ExtensionInstance = {
6
- context: Record<string, unknown>;
7
- functions: (context: any) => Record<string, unknown>;
6
+ context: Record<string, any>;
7
+ functions: (context: any) => any;
8
8
  };
9
9
  export type MergeExtensions<TContext, TExtensions extends Array<ExtensionInstance>> = UnionToIntersection<ApplyContext<TExtensions[number]["functions"], TContext>>;
10
10
  export type ExtensionConfig<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>> = {
11
11
  name: string;
12
12
  schema?: TSchema;
13
13
  context?: (options: InferOptions<TSchema>) => TContextAddon;
14
- functions: (options: InferOptions<TSchema>) => (context: any) => Record<string, any>;
14
+ functions: (options: InferOptions<TSchema>) => (context: any) => any;
15
15
  };
16
16
  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]) => {
17
17
  context: TContextAddon;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
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",