@deessejs/functions 0.0.65 → 0.0.67
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/functions/extension.d.ts +29 -0
- package/dist/functions/extension.js +31 -0
- package/package.json +110 -111
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import z, { ZodType } from "zod";
|
|
2
|
+
import { Exception } from "../errors/types";
|
|
3
|
+
import { AsyncResult } from "../types";
|
|
4
|
+
import { HKT } from "../utils/hkt";
|
|
5
|
+
type CoreAPI<C> = {
|
|
6
|
+
mutation: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception>(options: {
|
|
7
|
+
args: TArgs;
|
|
8
|
+
handler: (ctx: C, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
9
|
+
}) => (contextProvider: () => Promise<C>) => (input: z.input<TArgs>) => AsyncResult<TOutput, TError>;
|
|
10
|
+
query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception>(options: {
|
|
11
|
+
args: TArgs;
|
|
12
|
+
handler: (ctx: C, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
13
|
+
}) => (contextProvider: () => Promise<C>) => (input: z.input<TArgs>) => AsyncResult<TOutput, TError>;
|
|
14
|
+
};
|
|
15
|
+
interface MutationHKT extends HKT {
|
|
16
|
+
new: CoreAPI<this["_C"]>;
|
|
17
|
+
}
|
|
18
|
+
export declare const rpc: {
|
|
19
|
+
readonly name: "core";
|
|
20
|
+
readonly functions: <C>() => {
|
|
21
|
+
mutation: (options: any) => (contextProvider: () => Promise<C>) => (input: any) => Promise<any>;
|
|
22
|
+
query: (options: any) => (contextProvider: () => Promise<C>) => (input: any) => Promise<any>;
|
|
23
|
+
};
|
|
24
|
+
} & {
|
|
25
|
+
readonly _HKT: import("../extensions/types").DefaultHKT;
|
|
26
|
+
} & {
|
|
27
|
+
readonly _HKT: MutationHKT;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rpc = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const parse_1 = require("../functions/parse");
|
|
6
|
+
const extensions_1 = require("../extensions");
|
|
7
|
+
exports.rpc = (0, extensions_1.withKind)()((0, extensions_1.extension)({
|
|
8
|
+
name: "core",
|
|
9
|
+
functions: () => ({
|
|
10
|
+
mutation: (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
|
+
},
|
|
20
|
+
query: (options) => (contextProvider) => async (input) => {
|
|
21
|
+
const parsed = (0, parse_1.parseArgs)(options.args, input);
|
|
22
|
+
return parsed.match({
|
|
23
|
+
onSuccess: async (data) => {
|
|
24
|
+
const ctx = await contextProvider();
|
|
25
|
+
return options.handler(ctx, data);
|
|
26
|
+
},
|
|
27
|
+
onFailure: (error) => Promise.resolve((0, types_1.failure)(error)),
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,111 +1,110 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@deessejs/functions",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "A powerful utility library for building type-safe APIs and functions with context management",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"module": "dist/index.esm.js",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"test": "vitest",
|
|
60
|
-
"test:
|
|
61
|
-
"test:
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"@
|
|
97
|
-
"@
|
|
98
|
-
"@types/
|
|
99
|
-
"@
|
|
100
|
-
"@
|
|
101
|
-
"@
|
|
102
|
-
"@
|
|
103
|
-
"@vitest/
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@deessejs/functions",
|
|
3
|
+
"version": "0.0.67",
|
|
4
|
+
"description": "A powerful utility library for building type-safe APIs and functions with context management",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/index.esm.js",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"registry": "https://registry.npmjs.org/"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.esm.js",
|
|
15
|
+
"require": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./checks": {
|
|
18
|
+
"types": "./dist/checks.d.ts",
|
|
19
|
+
"import": "./dist/checks.esm.js",
|
|
20
|
+
"require": "./dist/checks.js"
|
|
21
|
+
},
|
|
22
|
+
"./context": {
|
|
23
|
+
"types": "./dist/context.d.ts",
|
|
24
|
+
"import": "./dist/context.esm.js",
|
|
25
|
+
"require": "./dist/context.js"
|
|
26
|
+
},
|
|
27
|
+
"./errors": {
|
|
28
|
+
"types": "./dist/errors.d.ts",
|
|
29
|
+
"import": "./dist/errors.esm.js",
|
|
30
|
+
"require": "./dist/errors.js"
|
|
31
|
+
},
|
|
32
|
+
"./events": {
|
|
33
|
+
"types": "./dist/events.d.ts",
|
|
34
|
+
"import": "./dist/events.esm.js",
|
|
35
|
+
"require": "./dist/events.js"
|
|
36
|
+
},
|
|
37
|
+
"./functions": {
|
|
38
|
+
"types": "./dist/functions.d.ts",
|
|
39
|
+
"import": "./dist/functions.esm.js",
|
|
40
|
+
"require": "./dist/functions.js"
|
|
41
|
+
},
|
|
42
|
+
"./types": {
|
|
43
|
+
"types": "./dist/types.d.ts",
|
|
44
|
+
"import": "./dist/types.esm.js",
|
|
45
|
+
"require": "./dist/types.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist/**/*",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE"
|
|
52
|
+
],
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsc",
|
|
55
|
+
"build:watch": "tsc --watch",
|
|
56
|
+
"prepublishOnly": "npm run build",
|
|
57
|
+
"test": "vitest",
|
|
58
|
+
"test:ui": "vitest --ui",
|
|
59
|
+
"test:run": "vitest run",
|
|
60
|
+
"test:coverage": "vitest run --coverage",
|
|
61
|
+
"test:watch": "vitest watch",
|
|
62
|
+
"lint": "eslint src --ext .ts",
|
|
63
|
+
"lint:fix": "eslint src --ext .ts --fix"
|
|
64
|
+
},
|
|
65
|
+
"keywords": [
|
|
66
|
+
"typescript",
|
|
67
|
+
"api",
|
|
68
|
+
"functions",
|
|
69
|
+
"context",
|
|
70
|
+
"validation",
|
|
71
|
+
"zod",
|
|
72
|
+
"type-safe",
|
|
73
|
+
"utility"
|
|
74
|
+
],
|
|
75
|
+
"author": "Votre Nom",
|
|
76
|
+
"license": "MIT",
|
|
77
|
+
"repository": {
|
|
78
|
+
"type": "git",
|
|
79
|
+
"url": "https://github.com/votre-organisation/deesse-api.git",
|
|
80
|
+
"directory": "packages/functions"
|
|
81
|
+
},
|
|
82
|
+
"bugs": {
|
|
83
|
+
"url": "https://github.com/votre-organisation/deesse-api/issues"
|
|
84
|
+
},
|
|
85
|
+
"homepage": "https://github.com/votre-organisation/deesse-api#readme",
|
|
86
|
+
"engines": {
|
|
87
|
+
"node": ">=16.0.0"
|
|
88
|
+
},
|
|
89
|
+
"packageManager": "pnpm@10.11.1",
|
|
90
|
+
"dependencies": {
|
|
91
|
+
"zod": "^4.1.12"
|
|
92
|
+
},
|
|
93
|
+
"devDependencies": {
|
|
94
|
+
"@testing-library/dom": "^10.4.1",
|
|
95
|
+
"@testing-library/user-event": "^14.6.1",
|
|
96
|
+
"@types/jsdom": "^27.0.0",
|
|
97
|
+
"@types/node": "^20.0.0",
|
|
98
|
+
"@types/sinon": "^21.0.0",
|
|
99
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
100
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
101
|
+
"@vitest/coverage-istanbul": "^4.0.14",
|
|
102
|
+
"@vitest/coverage-v8": "^4.0.13",
|
|
103
|
+
"@vitest/ui": "^4.0.13",
|
|
104
|
+
"eslint": "^8.0.0",
|
|
105
|
+
"jsdom": "^27.2.0",
|
|
106
|
+
"sinon": "^21.0.0",
|
|
107
|
+
"typescript": "^5.0.0",
|
|
108
|
+
"vitest": "^4.0.13"
|
|
109
|
+
}
|
|
110
|
+
}
|