@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.
- package/dist/api/index.d.ts +13 -2
- package/dist/api/index.js +24 -11
- package/dist/functions/query.d.ts +1 -1
- package/dist/functions/query.js +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +1 -1
package/dist/api/index.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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>;
|
package/dist/functions/query.js
CHANGED
|
@@ -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
package/dist/index.js
CHANGED
package/package.json
CHANGED