@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.
- package/dist/api/index.d.ts +11 -2
- package/dist/api/index.js +17 -11
- package/dist/errors/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/api/index.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
context,
|
|
12
|
-
|
|
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;
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -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: "
|
|
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