@deessejs/functions 0.0.17 → 0.0.19

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,8 +1,9 @@
1
1
  import { UnionToIntersection } from "../utils";
2
- type MergeExtensions<TContext, TExtensions extends any[]> = UnionToIntersection<ReturnType<TExtensions[number] extends (...args: any) => any ? (ctx: TContext) => ReturnType<ReturnType<TExtensions[number]>> : never>>;
3
- export declare function defineContext<TBaseContext extends Record<string, unknown>, TExtensions extends Array<(...args: any) => any>>(config: {
4
- extensions: TExtensions;
5
- }): MergeExtensions<TBaseContext, TExtensions> & {
6
- context: TBaseContext;
2
+ export type MergeExtensions<TContext, TExtensions extends Array<(...args: any) => any>> = UnionToIntersection<ReturnType<TExtensions[number]>>;
3
+ export declare function defineContext<TContext extends Record<string, unknown>>(): {
4
+ withExtensions: <TExtensions extends Array<(...args: any) => any>>(config: {
5
+ extensions: TExtensions;
6
+ }) => MergeExtensions<TContext, TExtensions> & {
7
+ context: TContext;
8
+ };
7
9
  };
8
- export {};
@@ -1,14 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineContext = defineContext;
4
- function defineContext(config) {
5
- const builder = {};
6
- for (const createExtension of config.extensions) {
7
- const extensionInstance = createExtension();
8
- Object.assign(builder, extensionInstance);
9
- }
4
+ function defineContext() {
10
5
  return {
11
- ...builder,
12
- context: {},
6
+ withExtensions: (config) => {
7
+ const builder = {};
8
+ for (const createExtension of config.extensions) {
9
+ const extensionInstance = createExtension();
10
+ Object.assign(builder, extensionInstance);
11
+ }
12
+ return {
13
+ ...builder,
14
+ context: {},
15
+ };
16
+ },
13
17
  };
14
18
  }
@@ -5,7 +5,7 @@ import { CommandsDefinition, MutationDefinition, QueryDefinition } from "../cont
5
5
  export type APINode = CommandsDefinition | {
6
6
  [key: string]: APINode;
7
7
  };
8
- export declare const rpc: () => <TContext>() => {
8
+ export declare const rpc: <TContext>() => () => {
9
9
  query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception>(options: {
10
10
  args: TArgs;
11
11
  handler: (ctx: TContext, // <--- Le contexte est injecté ici
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from "./api";
2
2
  export * from "./api/types";
3
3
  export * from "./functions";
4
4
  export * from "./types";
5
+ export * from './extensions/rpc';
5
6
  export * from "./context";
package/dist/index.js CHANGED
@@ -18,5 +18,6 @@ __exportStar(require("./api"), exports);
18
18
  __exportStar(require("./api/types"), exports);
19
19
  __exportStar(require("./functions"), exports);
20
20
  __exportStar(require("./types"), exports);
21
+ __exportStar(require("./extensions/rpc"), exports);
21
22
  // Context and typing exports
22
23
  __exportStar(require("./context"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
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",