@deessejs/functions 0.0.32 → 0.0.33
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExtensionBase, MergeExtensions } from "../extensions/types";
|
|
2
2
|
export declare function defineContext<TContext extends Record<string, any>>(): {
|
|
3
|
-
withExtensions: <
|
|
4
|
-
extensions: TExtensions;
|
|
3
|
+
withExtensions: <TExtensions extends readonly ExtensionBase[]>(config: {
|
|
4
|
+
extensions: readonly [...TExtensions];
|
|
5
5
|
}) => MergeExtensions<TContext, TExtensions> & {
|
|
6
6
|
context: TContext;
|
|
7
7
|
};
|
package/dist/context/define.js
CHANGED
|
@@ -3,17 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
4
|
function defineContext() {
|
|
5
5
|
return {
|
|
6
|
-
// <const TExtensions> (TS 5.0) ou readonly permet de dire à TS :
|
|
7
|
-
// "Ne traite pas ça comme un tableau générique, mais comme une suite précise d'éléments"
|
|
8
6
|
withExtensions: (config) => {
|
|
9
7
|
const builder = {};
|
|
10
8
|
const dummyContext = {};
|
|
11
9
|
for (const extension of config.extensions) {
|
|
12
|
-
//
|
|
10
|
+
// runtime : on appelle la factory avec le contexte (dummy)
|
|
13
11
|
const extensionMethods = extension.functions(dummyContext);
|
|
14
12
|
Object.assign(builder, extensionMethods);
|
|
15
13
|
}
|
|
16
|
-
// Typage : On utilise la fusion récursive
|
|
17
14
|
return {
|
|
18
15
|
...builder,
|
|
19
16
|
context: {},
|
|
@@ -5,10 +5,10 @@ export type ExtensionBase = {
|
|
|
5
5
|
functions: (context: any) => any;
|
|
6
6
|
};
|
|
7
7
|
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
8
|
-
functions: (
|
|
8
|
+
functions: (context: TContext) => infer R;
|
|
9
9
|
} ? R : Head extends {
|
|
10
|
-
functions: (
|
|
11
|
-
} ?
|
|
10
|
+
functions: (context: any) => infer R;
|
|
11
|
+
} ? R : {}) & MergeExtensions<TContext, Tail> : {};
|
|
12
12
|
export type ExtensionConfig<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>> = {
|
|
13
13
|
name: string;
|
|
14
14
|
schema?: TSchema;
|
package/package.json
CHANGED