@deessejs/functions 0.0.5 → 0.0.6

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,2 +1,11 @@
1
- import { API, APIConfig } from "./types";
2
- export declare const createAPI: <TContext extends Record<string, unknown>>(config: APIConfig<TContext>, contextName?: string) => API<TContext>;
1
+ import { z, ZodType } from "zod";
2
+ import { AsyncResult } from "../types";
3
+ export declare const createAPI: <TContext extends Record<string, unknown>>(config: {
4
+ context: TContext;
5
+ }) => {
6
+ readonly context: TContext;
7
+ readonly query: <TArgs extends ZodType, TOutput, TError = Error>(options: {
8
+ args: TArgs;
9
+ handler: (args: z.infer<TArgs>, ctx: TContext) => AsyncResult<TOutput, TError>;
10
+ }) => (input: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
11
+ };
package/dist/api/index.js CHANGED
@@ -1,18 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createAPI = void 0;
4
- const createAPI = (config, contextName = 'App') => {
5
- let context = { ...config.context };
6
- const addContext = (key, value) => {
7
- context = { ...context, [key]: value };
8
- return api;
4
+ const createAPI = (config) => {
5
+ const ctx = { ...config.context };
6
+ const query = (options) => {
7
+ 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);
13
+ };
14
+ Object.defineProperty(fn, "name", {
15
+ value: options.handler.name || "query",
16
+ });
17
+ return fn;
9
18
  };
10
- const api = {
11
- context,
12
- addContext,
13
- commands: config.commands,
14
- events: config.events,
19
+ return {
20
+ context: ctx,
21
+ query,
15
22
  };
16
- return api;
17
23
  };
18
24
  exports.createAPI = createAPI;
@@ -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: "error" | "info" | "warning" | "critical";
5
+ severity: "info" | "warning" | "error" | "critical";
6
6
  name: string;
7
7
  };
8
8
  export declare const raise: (exception: Exception) => Exception;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
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",