@deessejs/functions 0.0.51 → 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.js
CHANGED
|
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
4
|
function defineContext() {
|
|
5
5
|
return {
|
|
6
|
-
//
|
|
7
|
-
//
|
|
6
|
+
// IMPORTANT : <TExtensions extends readonly any[]>
|
|
7
|
+
// Ne mets PAS ExtensionBase[] ici, ça tue l'inférence précise de rpc.
|
|
8
8
|
withExtensions: (config) => {
|
|
9
9
|
const runtimeBuilder = {};
|
|
10
10
|
const dummyContext = {};
|
|
11
11
|
for (const extension of config.extensions) {
|
|
12
|
-
//
|
|
12
|
+
// Au runtime, on s'en fiche des types, on cast pour éviter les erreurs TS
|
|
13
13
|
const ext = extension;
|
|
14
|
-
if (ext.functions) {
|
|
14
|
+
if (ext && typeof ext.functions === 'function') {
|
|
15
15
|
const extensionMethods = ext.functions(dummyContext);
|
|
16
16
|
Object.assign(runtimeBuilder, extensionMethods);
|
|
17
17
|
}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
-
type ApplyContext<F, C> = F extends (context: C) => infer R ? R : never;
|
|
2
|
+
type ApplyContext<F, C> = F extends (context: C) => infer R ? R : F extends (context: any) => infer RLoose ? RLoose : never;
|
|
3
|
+
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
4
|
+
functions: infer F;
|
|
5
|
+
} ? ApplyContext<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
|
|
3
6
|
export type ExtensionBase = {
|
|
4
7
|
context: any;
|
|
5
8
|
functions: any;
|
|
6
9
|
};
|
|
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
|
-
*/
|
|
15
10
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
16
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]) => {
|
|
17
12
|
context: TContextAddon;
|
package/package.json
CHANGED