@deessejs/functions 0.0.44 → 0.0.45
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/context/define.d.ts +11 -5
- package/dist/context/define.js +5 -13
- package/dist/context/types.d.ts +6 -2
- package/dist/extensions/index.d.ts +8 -7
- package/dist/extensions/index.js +3 -11
- package/dist/extensions/rpc.d.ts +26 -16
- package/dist/extensions/rpc.js +10 -17
- package/package.json +18 -5
package/dist/context/define.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { ExtensionBase
|
|
2
|
-
export declare function defineContext<TContext
|
|
3
|
-
withExtensions: <
|
|
4
|
-
extensions:
|
|
5
|
-
}) =>
|
|
1
|
+
import { ExtensionBase } from "../extensions";
|
|
2
|
+
export declare function defineContext<TContext>(): {
|
|
3
|
+
withExtensions: <TExts extends readonly ExtensionBase[]>(config: {
|
|
4
|
+
extensions: [...TExts];
|
|
5
|
+
}) => MergeAllExtensions<TContext, TExts> & {
|
|
6
6
|
context: TContext;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
+
type MergeAllExtensions<TContext, TExts extends readonly any[]> = {
|
|
10
|
+
[K in keyof TExts]: TExts[K] extends {
|
|
11
|
+
functions: infer F;
|
|
12
|
+
} ? F extends (ctx: TContext) => infer R ? R : never : never;
|
|
13
|
+
}[number];
|
|
14
|
+
export {};
|
package/dist/context/define.js
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// defineContext.ts
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.defineContext = defineContext;
|
|
5
4
|
function defineContext() {
|
|
6
5
|
return {
|
|
7
6
|
withExtensions: (config) => {
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// appele runtime, pour construire les méthodes effectives
|
|
13
|
-
const extensionMethods = extension.functions(dummyContext);
|
|
14
|
-
Object.assign(runtimeBuilder, extensionMethods);
|
|
7
|
+
const builder = {};
|
|
8
|
+
for (const ext of config.extensions) {
|
|
9
|
+
const result = ext();
|
|
10
|
+
Object.assign(builder, result.functions);
|
|
15
11
|
}
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
...runtimeBuilder,
|
|
19
|
-
context: {},
|
|
20
|
-
};
|
|
12
|
+
return builder;
|
|
21
13
|
},
|
|
22
14
|
};
|
|
23
15
|
}
|
package/dist/context/types.d.ts
CHANGED
|
@@ -6,11 +6,15 @@ export type CommandDefinition<TContext, TArgs extends ZodType, TOutput, TError e
|
|
|
6
6
|
args: TArgs;
|
|
7
7
|
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
8
8
|
};
|
|
9
|
-
export type QueryDefinition<TContext, TArgs extends ZodType, TOutput, TError extends Exception> =
|
|
9
|
+
export type QueryDefinition<TContext, TArgs extends z.ZodType, TOutput, TError extends Exception> = {
|
|
10
10
|
_type: "query";
|
|
11
|
+
args: TArgs;
|
|
12
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
11
13
|
};
|
|
12
|
-
export type MutationDefinition<TContext, TArgs extends ZodType, TOutput, TError extends Exception> =
|
|
14
|
+
export type MutationDefinition<TContext, TArgs extends z.ZodType, TOutput, TError extends Exception> = {
|
|
13
15
|
_type: "mutation";
|
|
16
|
+
args: TArgs;
|
|
17
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
14
18
|
};
|
|
15
19
|
export type CommandsDefinition = QueryDefinition<any, any, any, any> | MutationDefinition<any, any, any, any>;
|
|
16
20
|
export type FunctionsForContext<C> = {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ZodType } from "zod";
|
|
2
|
-
import { Extension, InferOptions } from "./types";
|
|
3
1
|
import { FunctionsForContext } from "../context";
|
|
4
|
-
export
|
|
2
|
+
export type ExtensionBase = {
|
|
3
|
+
(): {
|
|
4
|
+
functions: FunctionsForContext<any>;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export declare function extensions<TFunctions extends FunctionsForContext<any>>(config: {
|
|
5
8
|
name: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
functions: (options: InferOptions<TSchema>) => TFunctionsFactory;
|
|
9
|
-
}): Extension<TSchema, TContextAddon, TFunctionsFactory>;
|
|
9
|
+
functions: () => TFunctions;
|
|
10
|
+
}): ExtensionBase;
|
package/dist/extensions/index.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// extensions/index.ts (ou extensions.ts)
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.extensions = extensions;
|
|
5
4
|
function extensions(config) {
|
|
6
|
-
return (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const contextPart = config.context ? config.context(options) : {};
|
|
10
|
-
const functionsBuilder = config.functions(options);
|
|
11
|
-
return {
|
|
12
|
-
context: contextPart,
|
|
13
|
-
functions: functionsBuilder,
|
|
14
|
-
};
|
|
15
|
-
};
|
|
5
|
+
return () => ({
|
|
6
|
+
functions: config.functions(),
|
|
7
|
+
});
|
|
16
8
|
}
|
package/dist/extensions/rpc.d.ts
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
import { Exception } from "../errors/types";
|
|
3
3
|
import { AsyncResult } from "../types";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export type QueryDef<TContext, TArgs extends z.ZodType, TOutput, TError extends Exception = never> = {
|
|
5
|
+
_type: "query";
|
|
6
|
+
args: TArgs;
|
|
7
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
8
|
+
};
|
|
9
|
+
export type MutationDef<TContext, TArgs extends z.ZodType, TOutput, TError extends Exception = never> = {
|
|
10
|
+
_type: "mutation";
|
|
11
|
+
args: TArgs;
|
|
12
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
13
|
+
};
|
|
14
|
+
export type EventHandler<TContext, TPayload> = {
|
|
15
|
+
event: string;
|
|
16
|
+
handler: (ctx: TContext, payload: TPayload) => AsyncResult<any, any>;
|
|
17
|
+
};
|
|
18
|
+
export declare function rpc<TContext>(): {
|
|
19
|
+
query: <TArgs extends z.ZodType, TOutput, TError extends Exception = never>(def: QueryDef<TContext, TArgs, TOutput, TError>) => QueryDef<TContext, TArgs, TOutput, TError>;
|
|
20
|
+
mutation: <TArgs extends z.ZodType, TOutput, TError extends Exception = never>(def: MutationDef<TContext, TArgs, TOutput, TError>) => MutationDef<TContext, TArgs, TOutput, TError>;
|
|
21
|
+
group: <T extends Record<string, any>>(g: T) => T;
|
|
22
|
+
on: <TPayload>(config: {
|
|
23
|
+
event: string;
|
|
24
|
+
handler: (ctx: TContext, payload: TPayload) => AsyncResult<any, any>;
|
|
25
|
+
}) => {
|
|
26
|
+
event: string;
|
|
27
|
+
handler: (ctx: TContext, payload: TPayload) => AsyncResult<any, any>;
|
|
28
|
+
};
|
|
7
29
|
};
|
|
8
|
-
export declare const rpc: import("./types").Extension<undefined, Record<string, unknown>, <C>(context: C) => {
|
|
9
|
-
query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception>(options: {
|
|
10
|
-
args: TArgs;
|
|
11
|
-
handler: (ctx: C, // C sera ici { user: ... }
|
|
12
|
-
args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
13
|
-
}) => QueryDefinition<C, TArgs, TOutput, TError>;
|
|
14
|
-
mutation: <TArgs extends ZodType<any, any, any>, TOutput_1, TError_1 extends Exception>(options: {
|
|
15
|
-
args: TArgs;
|
|
16
|
-
handler: (ctx: C, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
17
|
-
}) => MutationDefinition<C, TArgs, TOutput_1, TError_1>;
|
|
18
|
-
group: <T extends Record<string, APINode>>(definitions: T) => T;
|
|
19
|
-
}>;
|
package/dist/extensions/rpc.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rpc =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
mutation: (options) => {
|
|
15
|
-
return { _type: "mutation", ...options };
|
|
16
|
-
},
|
|
17
|
-
group: (definitions) => definitions,
|
|
18
|
-
}),
|
|
19
|
-
});
|
|
3
|
+
exports.rpc = rpc;
|
|
4
|
+
// Fonction générique : on passe le type du contexte ici !
|
|
5
|
+
function rpc() {
|
|
6
|
+
return {
|
|
7
|
+
query: (def) => def,
|
|
8
|
+
mutation: (def) => def,
|
|
9
|
+
group: (g) => g,
|
|
10
|
+
on: (config) => config,
|
|
11
|
+
};
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deessejs/functions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.45",
|
|
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",
|
|
@@ -56,7 +56,11 @@
|
|
|
56
56
|
"build": "tsc",
|
|
57
57
|
"build:watch": "tsc --watch",
|
|
58
58
|
"prepublishOnly": "npm run build",
|
|
59
|
-
"test": "
|
|
59
|
+
"test": "vitest",
|
|
60
|
+
"test:ui": "vitest --ui",
|
|
61
|
+
"test:run": "vitest run",
|
|
62
|
+
"test:coverage": "vitest run --coverage",
|
|
63
|
+
"test:watch": "vitest watch",
|
|
60
64
|
"lint": "eslint src --ext .ts",
|
|
61
65
|
"lint:fix": "eslint src --ext .ts --fix"
|
|
62
66
|
},
|
|
@@ -89,10 +93,19 @@
|
|
|
89
93
|
"zod": "^4.1.12"
|
|
90
94
|
},
|
|
91
95
|
"devDependencies": {
|
|
96
|
+
"@testing-library/dom": "^10.4.1",
|
|
97
|
+
"@testing-library/user-event": "^14.6.1",
|
|
98
|
+
"@types/jsdom": "^27.0.0",
|
|
92
99
|
"@types/node": "^20.0.0",
|
|
93
|
-
"
|
|
94
|
-
"eslint": "^8.0.0",
|
|
100
|
+
"@types/sinon": "^21.0.0",
|
|
95
101
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
96
|
-
"@typescript-eslint/parser": "^6.0.0"
|
|
102
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
103
|
+
"@vitest/coverage-v8": "^4.0.13",
|
|
104
|
+
"@vitest/ui": "^4.0.13",
|
|
105
|
+
"eslint": "^8.0.0",
|
|
106
|
+
"jsdom": "^27.2.0",
|
|
107
|
+
"sinon": "^21.0.0",
|
|
108
|
+
"typescript": "^5.0.0",
|
|
109
|
+
"vitest": "^4.0.13"
|
|
97
110
|
}
|
|
98
111
|
}
|