@deessejs/functions 0.0.25 → 0.0.27
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,6 +1,6 @@
|
|
|
1
1
|
import { ExtensionInstance, MergeExtensions } from "../extensions/types";
|
|
2
2
|
export declare function defineContext<TContext extends Record<string, any>>(): {
|
|
3
|
-
withExtensions: <TExtensions extends
|
|
3
|
+
withExtensions: <TExtensions extends ExtensionInstance[]>(config: {
|
|
4
4
|
extensions: TExtensions;
|
|
5
5
|
}) => MergeExtensions<TContext, TExtensions> & {
|
|
6
6
|
context: TContext;
|
package/dist/context/define.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
|
-
// Utiliser 'any'
|
|
4
|
+
// Utiliser 'Record<string, any>' aide à satisfaire les contraintes génériques des extensions
|
|
5
5
|
function defineContext() {
|
|
6
6
|
return {
|
|
7
|
+
// L'utilisation de 'const' (TS 5.0) ou juste la structure permet de bien inférer le Tuple
|
|
7
8
|
withExtensions: (config) => {
|
|
8
9
|
const builder = {};
|
|
9
10
|
const dummyContext = {};
|
|
10
11
|
for (const extension of config.extensions) {
|
|
11
|
-
// Runtime : On appelle la factory
|
|
12
12
|
const extensionMethods = extension.functions(dummyContext);
|
|
13
13
|
Object.assign(builder, extensionMethods);
|
|
14
14
|
}
|
|
@@ -3,15 +3,15 @@ import { UnionToIntersection } from "../utils";
|
|
|
3
3
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
4
4
|
type ApplyContext<TFunc, TContext> = TFunc extends (context: TContext) => infer R ? R : never;
|
|
5
5
|
export type ExtensionInstance = {
|
|
6
|
-
context: Record<string,
|
|
7
|
-
functions: (context: any) =>
|
|
6
|
+
context: Record<string, any>;
|
|
7
|
+
functions: (context: any) => any;
|
|
8
8
|
};
|
|
9
9
|
export type MergeExtensions<TContext, TExtensions extends Array<ExtensionInstance>> = UnionToIntersection<ApplyContext<TExtensions[number]["functions"], TContext>>;
|
|
10
10
|
export type ExtensionConfig<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>> = {
|
|
11
11
|
name: string;
|
|
12
12
|
schema?: TSchema;
|
|
13
13
|
context?: (options: InferOptions<TSchema>) => TContextAddon;
|
|
14
|
-
functions: (options: InferOptions<TSchema>) => (context: any) =>
|
|
14
|
+
functions: (options: InferOptions<TSchema>) => (context: any) => any;
|
|
15
15
|
};
|
|
16
16
|
export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctionsFactory extends (context: any) => any> = (...args: TSchema extends ZodType ? [options: z.input<TSchema>] : [options?: undefined]) => {
|
|
17
17
|
context: TContextAddon;
|
package/package.json
CHANGED