@deessejs/functions 0.0.24 → 0.0.25

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,10 +1,5 @@
1
- import { UnionToIntersection } from "../utils";
2
- export type ExtensionInstance = {
3
- context: Record<string, any>;
4
- functions: (...args: any[]) => any;
5
- };
6
- export type MergeExtensions<TContext, TExtensions extends Array<ExtensionInstance>> = UnionToIntersection<ReturnType<TExtensions[number]["functions"]>>;
7
- export declare function defineContext<TContext extends Record<string, unknown>>(): {
1
+ import { ExtensionInstance, MergeExtensions } from "../extensions/types";
2
+ export declare function defineContext<TContext extends Record<string, any>>(): {
8
3
  withExtensions: <TExtensions extends Array<ExtensionInstance>>(config: {
9
4
  extensions: TExtensions;
10
5
  }) => MergeExtensions<TContext, TExtensions> & {
@@ -1,12 +1,15 @@
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
5
  function defineContext() {
5
6
  return {
6
7
  withExtensions: (config) => {
7
8
  const builder = {};
9
+ const dummyContext = {};
8
10
  for (const extension of config.extensions) {
9
- const extensionMethods = extension.functions({});
11
+ // Runtime : On appelle la factory
12
+ const extensionMethods = extension.functions(dummyContext);
10
13
  Object.assign(builder, extensionMethods);
11
14
  }
12
15
  return {
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extensions = extensions;
4
- function extensions(
5
- // config ne prend plus TFunctionsFactory en générique explicite sur ExtensionConfig
6
- // On le type "à la main" ici pour l'inférence
7
- config) {
4
+ function extensions(config) {
8
5
  return (...args) => {
9
6
  const optionsInput = args[0];
10
7
  const options = (config.schema ? config.schema.parse(optionsInput) : undefined);
@@ -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: import("./types").Extension<undefined, Record<string, unknown>, <TContext>(context: TContext) => {
8
+ export declare const rpc: import("./types").Extension<undefined, Record<string, unknown>, <TContext extends Record<string, any>>(context: TContext) => {
9
9
  query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception>(options: {
10
10
  args: TArgs;
11
11
  handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
@@ -6,7 +6,8 @@ exports.rpc = (0, _1.extensions)({
6
6
  name: "rpc",
7
7
  schema: undefined,
8
8
  context: undefined,
9
- // Ici, TS va inférer que TFunctionsFactory est : <TContext>(context: TContext) => { ... }
9
+ // FIX CRUCIAL : <TContext extends Record<string, any>>
10
+ // Cela garantit à TypeScript que TContext est bien un objet compatible
10
11
  functions: (_options) => (context) => ({
11
12
  query: (options) => {
12
13
  return { _type: "query", ...options };
@@ -1,7 +1,7 @@
1
1
  import z, { ZodType } from "zod";
2
2
  import { UnionToIntersection } from "../utils";
3
3
  export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
4
- type ApplyContext<TFunc, TContext> = TFunc extends (ctx: TContext) => infer R ? R : never;
4
+ type ApplyContext<TFunc, TContext> = TFunc extends (context: TContext) => infer R ? R : never;
5
5
  export type ExtensionInstance = {
6
6
  context: Record<string, unknown>;
7
7
  functions: (context: any) => Record<string, unknown>;
@@ -11,7 +11,7 @@ export type ExtensionConfig<TSchema extends ZodType | undefined, TContextAddon e
11
11
  name: string;
12
12
  schema?: TSchema;
13
13
  context?: (options: InferOptions<TSchema>) => TContextAddon;
14
- functions: (options: InferOptions<TSchema>) => (context: any) => any;
14
+ functions: (options: InferOptions<TSchema>) => (context: any) => Record<string, 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.24",
3
+ "version": "0.0.25",
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",