@deessejs/functions 0.0.6 → 0.0.7

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,11 +1,13 @@
1
- import { z, ZodType } from "zod";
2
- import { AsyncResult } from "../types";
1
+ import z, { ZodType } from "zod";
2
+ import { Exception } from "../errors/types";
3
+ import type { AsyncResult } from "../types";
4
+ export type QueryFn<TArgs, TOutput, TError> = (input: TArgs) => AsyncResult<TOutput, TError>;
3
5
  export declare const createAPI: <TContext extends Record<string, unknown>>(config: {
4
6
  context: TContext;
5
7
  }) => {
6
- readonly context: TContext;
7
- readonly query: <TArgs extends ZodType, TOutput, TError = Error>(options: {
8
+ readonly query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception>(options: {
8
9
  args: TArgs;
9
10
  handler: (args: z.infer<TArgs>, ctx: TContext) => AsyncResult<TOutput, TError>;
10
- }) => (input: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
11
+ }) => QueryFn<z.infer<TArgs>, TOutput, TError>;
12
+ readonly context: TContext;
11
13
  };
package/dist/api/index.js CHANGED
@@ -1,23 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createAPI = void 0;
4
+ const query_1 = require("../functions/query");
4
5
  const createAPI = (config) => {
5
6
  const ctx = { ...config.context };
7
+ // API interne
8
+ const api = {
9
+ context: ctx,
10
+ };
6
11
  const query = (options) => {
12
+ const raw = (0, query_1.query)(options);
7
13
  const fn = (input) => {
8
- const parsed = options.args.safeParse(input);
9
- if (!parsed.success) {
10
- return Promise.resolve({ error: parsed.error });
11
- }
12
- return options.handler(parsed.data, ctx);
14
+ return raw(input, ctx);
13
15
  };
14
- Object.defineProperty(fn, "name", {
15
- value: options.handler.name || "query",
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
+ },
16
24
  });
17
- return fn;
18
25
  };
19
26
  return {
20
- context: ctx,
27
+ ...api,
21
28
  query,
22
29
  };
23
30
  };
@@ -2,7 +2,7 @@ import { Exception, ExceptionConfig, ExceptionSpaceConfig, ExceptionGroup } from
2
2
  export declare const exception: (config: ExceptionConfig) => Exception;
3
3
  export declare const exceptionSpace: (space: ExceptionSpaceConfig) => {
4
4
  define: (config: Omit<ExceptionConfig, "namespace">) => Exception;
5
- severity: "info" | "warning" | "error" | "critical";
5
+ severity: "error" | "info" | "warning" | "critical";
6
6
  name: string;
7
7
  };
8
8
  export declare const raise: (exception: Exception) => Exception;
@@ -1,7 +1,7 @@
1
1
  import { z, ZodType } from "zod";
2
+ import type { AppContext } from "../context/typing";
2
3
  import { Exception } from "../errors/types";
3
4
  import { AsyncResult } from "../types";
4
- import type { AppContext } from "../context/typing";
5
5
  export declare function query<TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception, TContext extends AppContext = AppContext>(options: {
6
6
  args: TArgs;
7
7
  handler: (args: z.infer<TArgs>, ctx: TContext) => AsyncResult<TOutput, TError>;
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createQuery = void 0;
4
4
  exports.query = query;
5
+ const typing_1 = require("../context/typing");
5
6
  const errors_1 = require("../errors");
6
7
  const types_1 = require("../types");
7
8
  const parse_1 = require("./parse");
8
- const typing_1 = require("../context/typing");
9
9
  // Implementation
10
10
  function query(options) {
11
11
  return (input, context) => {
package/dist/index.d.ts CHANGED
@@ -4,4 +4,3 @@ export * from "./functions";
4
4
  export * from "./types";
5
5
  export * from "./context";
6
6
  export * from "./context/typing";
7
- export * from "./context/generator";
package/dist/index.js CHANGED
@@ -21,4 +21,3 @@ __exportStar(require("./types"), exports);
21
21
  // Context and typing exports
22
22
  __exportStar(require("./context"), exports);
23
23
  __exportStar(require("./context/typing"), exports);
24
- __exportStar(require("./context/generator"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
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",