@deessejs/functions 0.0.65 → 0.0.68
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/extensions/rpc.d.ts +1 -0
- package/dist/extensions/rpc.js +10 -0
- package/package.json +2 -1
- package/dist/api/index.d.ts +0 -5
- package/dist/api/index.js +0 -20
- package/dist/api/types.d.ts +0 -8
- package/dist/api/types.js +0 -2
package/dist/extensions/rpc.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface MutationHKT extends HKT {
|
|
|
14
14
|
export declare const rpc: {
|
|
15
15
|
readonly name: "core";
|
|
16
16
|
readonly functions: <C>() => {
|
|
17
|
+
query: (options: any) => (contextProvider: () => Promise<C>) => (input: any) => Promise<any>;
|
|
17
18
|
mutation: (options: any) => (contextProvider: () => Promise<C>) => (input: any) => Promise<any>;
|
|
18
19
|
};
|
|
19
20
|
} & {
|
package/dist/extensions/rpc.js
CHANGED
|
@@ -7,6 +7,16 @@ const parse_1 = require("../functions/parse");
|
|
|
7
7
|
exports.rpc = (0, _1.withKind)()((0, _1.extension)({
|
|
8
8
|
name: "core",
|
|
9
9
|
functions: () => ({
|
|
10
|
+
query: (options) => (contextProvider) => async (input) => {
|
|
11
|
+
const parsed = (0, parse_1.parseArgs)(options.args, input);
|
|
12
|
+
return parsed.match({
|
|
13
|
+
onSuccess: async (data) => {
|
|
14
|
+
const ctx = await contextProvider();
|
|
15
|
+
return options.handler(ctx, data);
|
|
16
|
+
},
|
|
17
|
+
onFailure: (error) => Promise.resolve((0, types_1.failure)(error)),
|
|
18
|
+
});
|
|
19
|
+
},
|
|
10
20
|
mutation: (options) => (contextProvider) => async (input) => {
|
|
11
21
|
const parsed = (0, parse_1.parseArgs)(options.args, input);
|
|
12
22
|
return parsed.match({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deessejs/functions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.68",
|
|
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",
|
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
"@types/sinon": "^21.0.0",
|
|
101
101
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
102
102
|
"@typescript-eslint/parser": "^6.0.0",
|
|
103
|
+
"@vitest/coverage-istanbul": "^4.0.14",
|
|
103
104
|
"@vitest/coverage-v8": "^4.0.13",
|
|
104
105
|
"@vitest/ui": "^4.0.13",
|
|
105
106
|
"eslint": "^8.0.0",
|
package/dist/api/index.d.ts
DELETED
package/dist/api/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAPI = createAPI;
|
|
4
|
-
const query_1 = require("../functions/query");
|
|
5
|
-
function createAPI(config) {
|
|
6
|
-
const hydrate = (node) => {
|
|
7
|
-
if (node &&
|
|
8
|
-
typeof node === "object" &&
|
|
9
|
-
(node._type === "query" || node._type === "mutation")) {
|
|
10
|
-
const def = node;
|
|
11
|
-
const api = { context: ctx };
|
|
12
|
-
const query = () => {
|
|
13
|
-
return (options) => {
|
|
14
|
-
return (0, query_1.query)(options);
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
return hydrate(config.root);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
package/dist/api/types.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import z from "zod";
|
|
2
|
-
import { MutationDefinition, QueryDefinition } from "../context";
|
|
3
|
-
import { AsyncResult } from "../types";
|
|
4
|
-
type InferOperationFn<T> = T extends QueryDefinition<any, infer TArgs, infer TOutput, infer TError> | MutationDefinition<any, infer TArgs, infer TOutput, infer TError> ? (input: z.input<TArgs>) => AsyncResult<TOutput, TError> : never;
|
|
5
|
-
export type ApiRouter<T> = {
|
|
6
|
-
[K in keyof T]: T[K] extends QueryDefinition<any, any, any, any> | MutationDefinition<any, any, any, any> ? InferOperationFn<T[K]> : T[K] extends Record<string, any> ? ApiRouter<T[K]> : never;
|
|
7
|
-
};
|
|
8
|
-
export {};
|
package/dist/api/types.js
DELETED