@deessejs/functions 0.0.37 → 0.0.39

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.
@@ -7,16 +7,24 @@ function defineContext() {
7
7
  withExtensions: (config) => {
8
8
  // runtime builder (inchangé)
9
9
  const runtimeBuilder = {};
10
- const dummyContext = {};
10
+ // Utiliser un contexte runtime vide, mais conserver le type complet
11
+ const runtimeContext = {};
11
12
  for (const extension of config.extensions) {
12
- // appele runtime, pour construire les méthodes effectives
13
- const extensionMethods = extension.functions(dummyContext);
13
+ // Passer le contexte runtime complet (même vide) pour conserver les types
14
+ const extensionMethods = extension.functions(runtimeContext);
14
15
  Object.assign(runtimeBuilder, extensionMethods);
15
16
  }
16
- // On retourne runtimeBuilder mais on force le type public attendu.
17
+ // Créer un objet context qui préserve les types pour l'inférence
18
+ const contextProxy = new Proxy({}, {
19
+ get(_, prop) {
20
+ // Retourner undefined pour les propriétés inconnues, mais préserver le type
21
+ return runtimeContext[prop];
22
+ }
23
+ });
24
+ // On retourne runtimeBuilder avec un contexte qui préserve les types
17
25
  return {
18
26
  ...runtimeBuilder,
19
- context: {},
27
+ context: contextProxy,
20
28
  };
21
29
  },
22
30
  };
@@ -13,3 +13,12 @@ export type MutationDefinition<TContext, TArgs extends ZodType, TOutput, TError
13
13
  _type: "mutation";
14
14
  };
15
15
  export type CommandsDefinition = QueryDefinition<any, any, any, any> | MutationDefinition<any, any, any, any>;
16
+ export type FunctionsForContext<C> = {
17
+ query: <TArgs extends ZodType, TOutput, TError extends Exception>(def: QueryDefinition<C, TArgs, TOutput, TError>) => any;
18
+ mutation: <TArgs extends ZodType, TOutput, TError extends Exception>(def: MutationDefinition<C, TArgs, TOutput, TError>) => any;
19
+ on?: <TEvent extends string, TPayload>(config: {
20
+ event: TEvent;
21
+ handler: (ctx: C, payload: TPayload) => AsyncResult<any, any>;
22
+ }) => any;
23
+ group?: <TGroup extends Record<string, CommandsDefinition>>(defs: TGroup) => any;
24
+ };
@@ -1,6 +1,7 @@
1
1
  import { ZodType } from "zod";
2
2
  import { Extension, InferOptions } from "./types";
3
- export declare function extensions<TSchema extends ZodType | undefined = undefined, TContextAddon extends Record<string, unknown> = Record<string, unknown>, TFunctionsFactory extends (<C>(context: C) => any) = (<C>(context: C) => any)>(config: {
3
+ import { FunctionsForContext } from "../context";
4
+ export declare function extensions<TSchema extends ZodType | undefined = undefined, TContextAddon extends Record<string, unknown> = Record<string, unknown>, TFunctionsFactory extends (<C>(context: C) => FunctionsForContext<C>) = (<C>(context: C) => FunctionsForContext<C>)>(config: {
4
5
  name: string;
5
6
  schema?: TSchema;
6
7
  context?: (options: InferOptions<TSchema>) => TContextAddon;
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // extensions/index.ts (ou extensions.ts)
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.extensions = extensions;
4
5
  function extensions(config) {
@@ -16,4 +16,5 @@ export declare const rpc: import("./types").Extension<undefined, Record<string,
16
16
  handler: (ctx: C, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
17
17
  }) => MutationDefinition<C, TArgs, TOutput_1, TError_1>;
18
18
  group: <T extends Record<string, APINode>>(definitions: T) => T;
19
+ context: C;
19
20
  }>;
@@ -15,5 +15,7 @@ exports.rpc = (0, _1.extensions)({
15
15
  return { _type: "mutation", ...options };
16
16
  },
17
17
  group: (definitions) => definitions,
18
+ // Pour le typing, on expose le type de contexte
19
+ context: context,
18
20
  }),
19
21
  });
@@ -1,4 +1,5 @@
1
1
  import z, { ZodType } from "zod";
2
+ import { FunctionsForContext } from "../context";
2
3
  /** Utilitaire d'inférence d'appel générique (déjà présent chez toi) */
3
4
  type FnCallSignatureMatchesWith<C, F> = F extends {
4
5
  (context: C): infer R;
@@ -12,7 +13,7 @@ export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExt
12
13
  /** Ici : functions est *explicitement* une call signature générique */
13
14
  export type ExtensionBase = {
14
15
  context: any;
15
- functions: <C>(context: C) => any;
16
+ functions: <C>(context: C) => FunctionsForContext<C>;
16
17
  };
17
18
  /** Helpers pour extensions/InferOptions et définition d'Extension */
18
19
  export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
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",