@deessejs/functions 0.0.7 → 0.0.8

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.
@@ -6,8 +6,9 @@ export declare const createAPI: <TContext extends Record<string, unknown>>(confi
6
6
  context: TContext;
7
7
  }) => {
8
8
  readonly query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception>(options: {
9
+ name: string;
9
10
  args: TArgs;
10
11
  handler: (args: z.infer<TArgs>, ctx: TContext) => AsyncResult<TOutput, TError>;
11
- }) => QueryFn<z.infer<TArgs>, TOutput, TError>;
12
+ }) => (input: z.core.output<TArgs>, context?: TContext | undefined) => AsyncResult<TOutput, TError>;
12
13
  readonly context: TContext;
13
14
  };
package/dist/api/index.js CHANGED
@@ -4,24 +4,13 @@ exports.createAPI = void 0;
4
4
  const query_1 = require("../functions/query");
5
5
  const createAPI = (config) => {
6
6
  const ctx = { ...config.context };
7
- // API interne
8
7
  const api = {
9
8
  context: ctx,
10
9
  };
11
10
  const query = (options) => {
12
- const raw = (0, query_1.query)(options);
13
- const fn = (input) => {
14
- return raw(input, ctx);
15
- };
16
- return new Proxy(fn, {
17
- set(_, prop, value) {
18
- api[String(prop)] = value;
19
- return true;
20
- },
21
- get(target, prop) {
22
- return Reflect.get(target, prop);
23
- },
24
- });
11
+ const result = (0, query_1.query)(options);
12
+ api[options.name] = result;
13
+ return result;
25
14
  };
26
15
  return {
27
16
  ...api,
@@ -3,15 +3,7 @@ import type { AppContext } from "../context/typing";
3
3
  import { Exception } from "../errors/types";
4
4
  import { AsyncResult } from "../types";
5
5
  export declare function query<TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception, TContext extends AppContext = AppContext>(options: {
6
+ name: string;
6
7
  args: TArgs;
7
8
  handler: (args: z.infer<TArgs>, ctx: TContext) => AsyncResult<TOutput, TError>;
8
- contextName?: string;
9
- }): (input: z.infer<TArgs>, context?: TContext) => AsyncResult<TOutput, TError>;
10
- export declare function query<TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception>(options: {
11
- args: TArgs;
12
- handler: (args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
13
- }): (input: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
14
- export declare const createQuery: <TContext extends AppContext = AppContext>() => <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception>(options: {
15
- args: TArgs;
16
- handler: (args: z.infer<TArgs>, ctx: TContext) => AsyncResult<TOutput, TError>;
17
- }) => (input: z.core.output<TArgs>, context?: TContext | undefined) => AsyncResult<TOutput, TError>;
9
+ }): (input: z.core.output<TArgs>, context?: TContext) => AsyncResult<TOutput, TError>;
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createQuery = void 0;
4
3
  exports.query = query;
5
4
  const typing_1 = require("../context/typing");
6
5
  const errors_1 = require("../errors");
7
6
  const types_1 = require("../types");
8
7
  const parse_1 = require("./parse");
9
- // Implementation
10
8
  function query(options) {
11
9
  return (input, context) => {
12
10
  const parsed = (0, parse_1.parseArgs)(options.args, input);
@@ -25,10 +23,3 @@ function query(options) {
25
23
  });
26
24
  };
27
25
  }
28
- // Query builder
29
- const createQuery = () => {
30
- return (options) => {
31
- return query(options);
32
- };
33
- };
34
- exports.createQuery = createQuery;
@@ -23,6 +23,7 @@ export type GroupFromConfig<C extends CommandGroupConfig> = {
23
23
  [K in Extract<C["children"][number], CommandGroupConfig> as K["name"]]: GroupFromConfig<K>;
24
24
  };
25
25
  export type Query<TArgs extends ZodType = ZodType, TError extends Exception = Exception, TOutput = Unit, TContext = {}> = (options: {
26
+ name: string;
26
27
  args: TArgs;
27
28
  handler: (args: z.infer<TArgs>, ctx: TContext) => AsyncResult<TOutput, TError>;
28
29
  }) => (args: z.infer<TArgs>, ctx: TContext) => AsyncResult<TOutput, TError>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
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",