@deessejs/functions 0.0.57 → 0.0.59
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 {
|
|
1
|
+
import { 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: <TExtensions extends readonly any[]>(config: {
|
|
4
|
+
extensions: readonly [...TExtensions];
|
|
5
|
+
}) => MergeExtensions<TContext, TExtensions> & {
|
|
6
6
|
context: TContext;
|
|
7
7
|
};
|
|
8
8
|
};
|
package/dist/context/define.js
CHANGED
|
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
4
|
function defineContext() {
|
|
5
5
|
return {
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// TS va automatiquement calculer le type de retour spécifique pour TContext.
|
|
6
|
+
// ON NE MET AUCUNE CONTRAINTE ICI.
|
|
7
|
+
// TExtensions capture le type brut et exact (ex: le générique <C> de rpc).
|
|
9
8
|
withExtensions: (config) => {
|
|
10
9
|
const runtimeBuilder = {};
|
|
11
10
|
const dummyContext = {};
|
|
12
11
|
for (const extension of config.extensions) {
|
|
13
|
-
//
|
|
12
|
+
// Cast runtime uniquement pour éviter les erreurs TS dans la boucle
|
|
14
13
|
const ext = extension;
|
|
15
14
|
if (ext && typeof ext.functions === "function") {
|
|
16
15
|
const extensionMethods = ext.functions(dummyContext);
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* LA SOLUTION MATHÉMATIQUE.
|
|
4
|
+
* On ne demande pas "Est-ce que ça marche ?" (extends), on dit "Fais-le marcher !" (&).
|
|
5
|
+
*
|
|
6
|
+
* On crée une intersection entre :
|
|
7
|
+
* 1. Ta fonction générique F: <C>(c: C) => API<C>
|
|
8
|
+
* 2. Une fonction factice: (c: TContext) => unknown
|
|
9
|
+
*
|
|
10
|
+
* Pour calculer le ReturnType de cette intersection, TypeScript DOIT instancier
|
|
11
|
+
* le générique <C> de F avec TContext.
|
|
12
|
+
*/
|
|
13
|
+
type ApplyContext<F, C> = F extends (c: any) => any ? ReturnType<F & ((c: C) => unknown)> : never;
|
|
14
|
+
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
15
|
+
functions: infer F;
|
|
16
|
+
} ? ApplyContext<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
|
|
17
|
+
export type ExtensionBase = {
|
|
3
18
|
context: any;
|
|
4
|
-
functions:
|
|
19
|
+
functions: any;
|
|
5
20
|
};
|
|
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> : {};
|
|
7
21
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
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]) => {
|
|
22
|
+
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]) => {
|
|
9
23
|
context: TContextAddon;
|
|
10
24
|
functions: TFunctionsFactory;
|
|
11
25
|
};
|
|
26
|
+
export {};
|
package/package.json
CHANGED