@deessejs/functions 0.0.50 → 0.0.52
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
|
+
// IMPORTANT : <TExtensions extends readonly any[]>
|
|
7
|
+
// Ne mets PAS ExtensionBase[] ici, ça tue l'inférence précise de rpc.
|
|
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
|
+
// Au runtime, on s'en fiche des types, on cast pour éviter les erreurs TS
|
|
13
|
+
const ext = extension;
|
|
14
|
+
if (ext && typeof ext.functions === 'function') {
|
|
15
|
+
const extensionMethods = ext.functions(dummyContext);
|
|
16
|
+
Object.assign(runtimeBuilder, extensionMethods);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
return {
|
|
16
20
|
...runtimeBuilder,
|
|
17
21
|
context: {},
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
-
|
|
3
|
-
* 1. FIX MAJEUR : ApplyContext
|
|
4
|
-
* Au lieu de deviner le type générique, on force TypeScript à appliquer
|
|
5
|
-
* ton TContext (ex: { user: ... }) à la fonction de l'extension.
|
|
6
|
-
*/
|
|
7
|
-
type ApplyContext<F, C> = F extends (context: C) => infer R ? R : never;
|
|
8
|
-
/**
|
|
9
|
-
* 2. FIX MAJEUR : MergeExtensions
|
|
10
|
-
* On utilise ApplyContext pour résoudre le type de retour précis avec le contexte injecté.
|
|
11
|
-
*/
|
|
2
|
+
type ApplyContext<F, C> = F extends (context: C) => infer R ? R : F extends (context: any) => infer RLoose ? RLoose : never;
|
|
12
3
|
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
13
4
|
functions: infer F;
|
|
14
5
|
} ? ApplyContext<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
|
|
15
|
-
/**
|
|
16
|
-
* 3. FIX MAJEUR : ExtensionBase
|
|
17
|
-
* On met 'any' pour éviter que TypeScript ne simplifie le type de ton extension
|
|
18
|
-
* avant qu'on ait pu l'analyser. Ça débloque l'inférence.
|
|
19
|
-
*/
|
|
20
6
|
export type ExtensionBase = {
|
|
21
7
|
context: any;
|
|
22
|
-
functions:
|
|
8
|
+
functions: any;
|
|
23
9
|
};
|
|
24
10
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
25
11
|
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]) => {
|
package/package.json
CHANGED