@deessejs/functions 0.0.5 → 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,2 +1,13 @@
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 { Exception } from "../errors/types";
3
+ import type { AsyncResult } from "../types";
4
+ export type QueryFn<TArgs, TOutput, TError> = (input: TArgs) => AsyncResult<TOutput, TError>;
5
+ export declare const createAPI: <TContext extends Record<string, unknown>>(config: {
6
+ context: TContext;
7
+ }) => {
8
+ readonly query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception = Exception>(options: {
9
+ args: TArgs;
10
+ handler: (args: z.infer<TArgs>, ctx: TContext) => AsyncResult<TOutput, TError>;
11
+ }) => QueryFn<z.infer<TArgs>, TOutput, TError>;
12
+ readonly context: TContext;
13
+ };
package/dist/api/index.js CHANGED
@@ -1,18 +1,31 @@
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;
9
- };
4
+ const query_1 = require("../functions/query");
5
+ const createAPI = (config) => {
6
+ const ctx = { ...config.context };
7
+ // API interne
10
8
  const api = {
11
- context,
12
- addContext,
13
- commands: config.commands,
14
- events: config.events,
9
+ context: ctx,
10
+ };
11
+ 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
+ });
25
+ };
26
+ return {
27
+ ...api,
28
+ query,
15
29
  };
16
- return api;
17
30
  };
18
31
  exports.createAPI = createAPI;
@@ -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.5",
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",