@deessejs/functions 0.0.56 → 0.0.57
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,8 +1,8 @@
|
|
|
1
|
-
import { MergeExtensions } from "../extensions/types";
|
|
1
|
+
import { ExtensionBase, MergeExtensions } from "../extensions/types";
|
|
2
2
|
export declare function defineContext<TContext extends Record<string, any>>(): {
|
|
3
|
-
withExtensions: <
|
|
4
|
-
extensions: readonly [...
|
|
5
|
-
}) => MergeExtensions<TContext,
|
|
3
|
+
withExtensions: <E extends readonly ExtensionBase<TContext, any>[]>(config: {
|
|
4
|
+
extensions: readonly [...E];
|
|
5
|
+
}) => MergeExtensions<TContext, E> & {
|
|
6
6
|
context: TContext;
|
|
7
7
|
};
|
|
8
8
|
};
|
package/dist/context/define.js
CHANGED
|
@@ -3,16 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
4
|
function defineContext() {
|
|
5
5
|
return {
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// CHANGEMENT CRITIQUE :
|
|
7
|
+
// On demande à TS d'inférer E comme étant des extensions qui acceptent TContext.
|
|
8
|
+
// TS va automatiquement calculer le type de retour spécifique pour TContext.
|
|
9
9
|
withExtensions: (config) => {
|
|
10
10
|
const runtimeBuilder = {};
|
|
11
11
|
const dummyContext = {};
|
|
12
12
|
for (const extension of config.extensions) {
|
|
13
|
-
//
|
|
13
|
+
// Le cast est safe car on sait que ça match ExtensionBase au runtime
|
|
14
14
|
const ext = extension;
|
|
15
|
-
if (ext && typeof ext.functions ===
|
|
15
|
+
if (ext && typeof ext.functions === "function") {
|
|
16
16
|
const extensionMethods = ext.functions(dummyContext);
|
|
17
17
|
Object.assign(runtimeBuilder, extensionMethods);
|
|
18
18
|
}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
-
type
|
|
3
|
-
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
4
|
-
functions: infer F;
|
|
5
|
-
} ? F extends (c: any) => any ? ApplyContext<F, TContext> : {} : {}) & MergeExtensions<TContext, Tail> : {};
|
|
6
|
-
export type ExtensionBase = {
|
|
2
|
+
export type ExtensionBase<Context = any, Output = any> = {
|
|
7
3
|
context: any;
|
|
8
|
-
functions: (context:
|
|
4
|
+
functions: (context: Context) => Output;
|
|
9
5
|
};
|
|
6
|
+
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends ExtensionBase<any, infer Out> ? Out : {}) & MergeExtensions<TContext, Tail> : {};
|
|
10
7
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
11
8
|
export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctionsFactory extends <C>(context: C) => any> = (...args: TSchema extends ZodType ? [options: z.input<TSchema>] : [options?: undefined]) => {
|
|
12
9
|
context: TContextAddon;
|
|
13
10
|
functions: TFunctionsFactory;
|
|
14
11
|
};
|
|
15
|
-
export {};
|
package/package.json
CHANGED