@deessejs/functions 0.0.44 → 0.0.46
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 +9 -4
- package/dist/context/define.js +11 -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 +28 -17
- package/dist/extensions/rpc.js +7 -14
- package/dist/extensions/types.d.ts +3 -4
- package/package.json +18 -5
package/dist/context/define.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Extension } from "../extensions/types";
|
|
2
2
|
export declare function defineContext<TContext extends Record<string, any>>(): {
|
|
3
|
-
withExtensions: <
|
|
4
|
-
extensions:
|
|
5
|
-
}) => MergeExtensions<TContext,
|
|
3
|
+
withExtensions: <TExts extends readonly Extension<any>[]>(config: {
|
|
4
|
+
extensions: [...TExts];
|
|
5
|
+
}) => MergeExtensions<TContext, TExts> & {
|
|
6
6
|
context: TContext;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
+
type MergeExtensions<TContext, TExts extends readonly Extension<any>[]> = UnionToIntersection<{
|
|
10
|
+
[K in keyof TExts]: TExts[K] extends Extension<infer F> ? F extends (ctx: TContext) => infer R ? R : never : never;
|
|
11
|
+
}[number]>;
|
|
12
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
13
|
+
export {};
|
package/dist/context/define.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// defineContext.ts
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.defineContext = defineContext;
|
|
4
|
+
// defineContext.ts
|
|
5
5
|
function defineContext() {
|
|
6
6
|
return {
|
|
7
7
|
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);
|
|
8
|
+
const builder = {};
|
|
9
|
+
for (const ext of config.extensions) {
|
|
10
|
+
const { functions } = ext(); // ← chaque extension sait maintenant recevoir TContext
|
|
11
|
+
Object.assign(builder, functions);
|
|
15
12
|
}
|
|
16
|
-
// On
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
13
|
+
// On ajoute la propriété context (runtime value = null, mais type correct)
|
|
14
|
+
Object.defineProperty(builder, "context", {
|
|
15
|
+
get() { return null; },
|
|
16
|
+
enumerable: true,
|
|
17
|
+
});
|
|
18
|
+
return builder;
|
|
21
19
|
},
|
|
22
20
|
};
|
|
23
21
|
}
|
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,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Exception } from "../errors/types";
|
|
1
|
+
import { z } from "zod";
|
|
3
2
|
import { AsyncResult } from "../types";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export declare const rpc: () => {
|
|
4
|
+
functions: <TContext>() => {
|
|
5
|
+
query: <TArgs extends z.ZodType, TOutput, TError = never>(def: {
|
|
6
|
+
args: TArgs;
|
|
7
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
8
|
+
}) => {
|
|
9
|
+
args: TArgs;
|
|
10
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
11
|
+
_type: "query";
|
|
12
|
+
};
|
|
13
|
+
mutation: <TArgs extends z.ZodType, TOutput_1, TError_1 = never>(def: {
|
|
14
|
+
args: TArgs;
|
|
15
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
16
|
+
}) => {
|
|
17
|
+
args: TArgs;
|
|
18
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
19
|
+
_type: "mutation";
|
|
20
|
+
};
|
|
21
|
+
group: <G>(group: G) => G;
|
|
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
|
+
};
|
|
29
|
+
};
|
|
7
30
|
};
|
|
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
3
|
exports.rpc = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
functions: (_options) => (context) => ({
|
|
11
|
-
query: (options) => {
|
|
12
|
-
return { _type: "query", ...options };
|
|
13
|
-
},
|
|
14
|
-
mutation: (options) => {
|
|
15
|
-
return { _type: "mutation", ...options };
|
|
16
|
-
},
|
|
17
|
-
group: (definitions) => definitions,
|
|
4
|
+
const rpc = () => ({
|
|
5
|
+
functions: () => ({
|
|
6
|
+
query: (def) => ({ _type: "query", ...def }),
|
|
7
|
+
mutation: (def) => ({ _type: "mutation", ...def }),
|
|
8
|
+
group: (group) => group,
|
|
9
|
+
on: (config) => config,
|
|
18
10
|
}),
|
|
19
11
|
});
|
|
12
|
+
exports.rpc = rpc;
|
|
@@ -21,10 +21,9 @@ export type ExtensionConfig<TSchema extends ZodType | undefined, TContextAddon e
|
|
|
21
21
|
name: string;
|
|
22
22
|
schema?: TSchema;
|
|
23
23
|
context?: (options: InferOptions<TSchema>) => TContextAddon;
|
|
24
|
-
functions: (options: InferOptions<TSchema>) =>
|
|
24
|
+
functions: (options: InferOptions<TSchema>) => <C>(context: C) => any;
|
|
25
25
|
};
|
|
26
|
-
export type Extension<
|
|
27
|
-
|
|
28
|
-
functions: TFunctionsFactory;
|
|
26
|
+
export type Extension<F extends (ctx: any) => any> = () => {
|
|
27
|
+
functions: F;
|
|
29
28
|
};
|
|
30
29
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deessejs/functions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.46",
|
|
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
|
}
|