@deessejs/functions 0.0.49 → 0.0.51
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
|
-
import {
|
|
1
|
+
import { MergeExtensions } from "../extensions/types";
|
|
2
2
|
export declare function defineContext<TContext extends Record<string, any>>(): {
|
|
3
|
-
withExtensions: <TExtensions extends readonly
|
|
3
|
+
withExtensions: <TExtensions extends readonly any[]>(config: {
|
|
4
4
|
extensions: readonly [...TExtensions];
|
|
5
5
|
}) => MergeExtensions<TContext, TExtensions> & {
|
|
6
6
|
context: TContext;
|
package/dist/context/define.js
CHANGED
|
@@ -3,15 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
4
|
function defineContext() {
|
|
5
5
|
return {
|
|
6
|
+
// CHANGEMENT ICI : Remplace "ExtensionBase[]" par "any[]"
|
|
7
|
+
// Cela empêche TypeScript de "simplifier" ton extension rpc en un type générique vide.
|
|
6
8
|
withExtensions: (config) => {
|
|
7
|
-
// runtime builder (inchangé)
|
|
8
9
|
const runtimeBuilder = {};
|
|
9
10
|
const dummyContext = {};
|
|
10
11
|
for (const extension of config.extensions) {
|
|
11
|
-
//
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// Cast as ExtensionBase juste pour le runtime, sans impacter l'inférence
|
|
13
|
+
const ext = extension;
|
|
14
|
+
if (ext.functions) {
|
|
15
|
+
const extensionMethods = ext.functions(dummyContext);
|
|
16
|
+
Object.assign(runtimeBuilder, extensionMethods);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
return {
|
|
16
20
|
...runtimeBuilder,
|
|
17
21
|
context: {},
|
|
@@ -1,29 +1,19 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
-
|
|
3
|
-
/** Utilitaire d'inférence d'appel générique (déjà présent chez toi) */
|
|
4
|
-
type FnCallSignatureMatchesWith<C, F> = F extends {
|
|
5
|
-
(context: C): infer R;
|
|
6
|
-
} ? R : F extends {
|
|
7
|
-
<U>(context: U): infer RGeneric;
|
|
8
|
-
} ? RGeneric : F extends (context: any) => infer R ? R : never;
|
|
9
|
-
/** MergeExtensions : applique la logique d'inférence sur une tuple d'extensions */
|
|
10
|
-
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
11
|
-
functions: infer F;
|
|
12
|
-
} ? FnCallSignatureMatchesWith<TContext, F> : {}) & MergeExtensions<TContext, Tail> : {};
|
|
13
|
-
/** Ici : functions est *explicitement* une call signature générique */
|
|
2
|
+
type ApplyContext<F, C> = F extends (context: C) => infer R ? R : never;
|
|
14
3
|
export type ExtensionBase = {
|
|
15
4
|
context: any;
|
|
16
|
-
functions:
|
|
5
|
+
functions: any;
|
|
17
6
|
};
|
|
18
|
-
|
|
7
|
+
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
8
|
+
functions: infer F;
|
|
9
|
+
} ? ApplyContext<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
|
|
10
|
+
/**
|
|
11
|
+
* 3. FIX MAJEUR : ExtensionBase
|
|
12
|
+
* On met 'any' pour éviter que TypeScript ne simplifie le type de ton extension
|
|
13
|
+
* avant qu'on ait pu l'analyser. Ça débloque l'inférence.
|
|
14
|
+
*/
|
|
19
15
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
20
|
-
export type
|
|
21
|
-
name: string;
|
|
22
|
-
schema?: TSchema;
|
|
23
|
-
context?: (options: InferOptions<TSchema>) => TContextAddon;
|
|
24
|
-
functions: (options: InferOptions<TSchema>) => (<C>(context: C) => any);
|
|
25
|
-
};
|
|
26
|
-
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]) => {
|
|
16
|
+
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]) => {
|
|
27
17
|
context: TContextAddon;
|
|
28
18
|
functions: TFunctionsFactory;
|
|
29
19
|
};
|
package/dist/extensions/types.js
CHANGED
package/package.json
CHANGED