@deessejs/functions 0.0.28 → 0.0.29

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 { ExtensionInstance, MergeExtensions } from "../extensions/types";
2
2
  export declare function defineContext<TContext extends Record<string, any>>(): {
3
3
  withExtensions: <TExtensions extends ExtensionInstance[]>(config: {
4
- extensions: TExtensions;
4
+ extensions: [...TExtensions];
5
5
  }) => MergeExtensions<TContext, TExtensions> & {
6
6
  context: TContext;
7
7
  };
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
+ // src/context/index.ts (ou defineContext.ts)
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.defineContext = defineContext;
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
8
7
  withExtensions: (config) => {
9
8
  const builder = {};
10
9
  const dummyContext = {};
11
10
  for (const extension of config.extensions) {
11
+ // extension.functions est maintenant 'any' au niveau du type,
12
+ // mais au runtime c'est bien la fonction.
12
13
  const extensionMethods = extension.functions(dummyContext);
13
14
  Object.assign(builder, extensionMethods);
14
15
  }
@@ -6,6 +6,8 @@ exports.rpc = (0, _1.extensions)({
6
6
  name: "rpc",
7
7
  schema: undefined,
8
8
  context: undefined,
9
+ // La fonction accepte N'IMPORTE QUEL TContext.
10
+ // C'est ApplyContext qui se chargera d'injecter le bon type (celui de defineContext).
9
11
  functions: (_options) => (context) => ({
10
12
  query: (options) => {
11
13
  return { _type: "query", ...options };
@@ -4,7 +4,7 @@ export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.
4
4
  type ApplyContext<TFunc, TContext> = TFunc extends (context: TContext) => infer R ? R : never;
5
5
  export type ExtensionInstance = {
6
6
  context: any;
7
- functions: (context: any) => any;
7
+ functions: 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>> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
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",