@deessejs/functions 0.0.67 → 0.0.69

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