@deessejs/functions 0.0.62 → 0.0.63
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,16 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
4
|
function defineContext() {
|
|
5
5
|
return {
|
|
6
|
-
//
|
|
7
|
-
// C'est vital. Si on met un type plus précis ici, TypeScript risque
|
|
8
|
-
// de simplifier le générique de 'rpc' avant qu'on puisse l'injecter.
|
|
6
|
+
// any[] préserve la généricité de rpc jusqu'au bout
|
|
9
7
|
withExtensions: (config) => {
|
|
10
8
|
const runtimeBuilder = {};
|
|
11
9
|
const dummyContext = {};
|
|
12
10
|
for (const extension of config.extensions) {
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
// Cast runtime uniquement
|
|
12
|
+
const ext = extension;
|
|
13
|
+
if (ext && typeof ext.functions === "function") {
|
|
14
|
+
const extensionMethods = ext.functions(dummyContext);
|
|
16
15
|
Object.assign(runtimeBuilder, extensionMethods);
|
|
17
16
|
}
|
|
18
17
|
}
|
package/dist/extensions/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extensions = extensions;
|
|
4
|
-
//
|
|
4
|
+
// Retirez l'import de Extension et FunctionsForContext s'ils ne servent qu'au typage de retour
|
|
5
5
|
function extensions(config) {
|
|
6
|
-
//
|
|
6
|
+
// SUPPRESSION DU TYPE DE RETOUR EXPLICITE ": Extension<...>"
|
|
7
|
+
// C'est ça qui causait le "unknown". On laisse TS inférer le type réel.
|
|
7
8
|
return (...args) => {
|
|
8
9
|
const optionsInput = args[0];
|
|
9
10
|
const options = (config.schema ? config.schema.parse(optionsInput) : undefined);
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* 2. ReturnType<...> : Pour résoudre le type de retour de cette hybride,
|
|
8
|
-
* TypeScript est obligé de remplacer le générique de F par C.
|
|
9
|
-
* 3. Le "& unknown" assure qu'on ne pollue pas le type de retour (R & unknown = R).
|
|
3
|
+
* Maintenant que F est une fonction générique "propre" (grâce à l'étape 1),
|
|
4
|
+
* l'inférence directe fonctionne parfaitement.
|
|
5
|
+
* TS va voir : <C>(c: C) => ... extends (c: TContext) => infer R
|
|
6
|
+
* Il va mathématiquement remplacer C par TContext.
|
|
10
7
|
*/
|
|
11
|
-
type ApplyContext<F, C> = F extends (
|
|
8
|
+
type ApplyContext<F, C> = F extends (context: C) => infer R ? R : never;
|
|
12
9
|
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
13
10
|
functions: infer F;
|
|
14
11
|
} ? ApplyContext<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
|
|
15
|
-
export type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
functions: TFunctionsFactory;
|
|
12
|
+
export type ExtensionBase = {
|
|
13
|
+
context: any;
|
|
14
|
+
functions: any;
|
|
19
15
|
};
|
|
16
|
+
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
20
17
|
export {};
|
package/package.json
CHANGED