@deessejs/functions 0.0.61 → 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.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { MergeExtensions } from "../extensions/types";
|
|
2
2
|
export declare function defineContext<TContext extends Record<string, any>>(): {
|
|
3
|
-
withExtensions: <TExtensions extends readonly {
|
|
4
|
-
functions: (ctx: TContext) => any;
|
|
5
|
-
}[]>(config: {
|
|
3
|
+
withExtensions: <TExtensions extends readonly any[]>(config: {
|
|
6
4
|
extensions: readonly [...TExtensions];
|
|
7
5
|
}) => MergeExtensions<TContext, TExtensions> & {
|
|
8
6
|
context: TContext;
|
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
|
-
// Comme 'rpc' (qui sort maintenant "propre" de extensions()) est générique <C>,
|
|
8
|
-
// TypeScript va remplacer <C> par <TContext> pour satisfaire cette contrainte.
|
|
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
|
-
|
|
11
|
+
// Cast runtime uniquement
|
|
12
|
+
const ext = extension;
|
|
13
|
+
if (ext && typeof ext.functions === "function") {
|
|
14
|
+
const extensionMethods = ext.functions(dummyContext);
|
|
15
15
|
Object.assign(runtimeBuilder, extensionMethods);
|
|
16
16
|
}
|
|
17
17
|
}
|
package/dist/context/types.d.ts
CHANGED
|
@@ -13,12 +13,3 @@ export type MutationDefinition<TContext, TArgs extends ZodType, TOutput, TError
|
|
|
13
13
|
_type: "mutation";
|
|
14
14
|
};
|
|
15
15
|
export type CommandsDefinition = QueryDefinition<any, any, any, any> | MutationDefinition<any, any, any, any>;
|
|
16
|
-
export type FunctionsForContext<C> = {
|
|
17
|
-
query: <TArgs extends ZodType, TOutput, TError extends Exception>(def: QueryDefinition<C, TArgs, TOutput, TError>) => QueryDefinition<C, TArgs, TOutput, TError>;
|
|
18
|
-
mutation: <TArgs extends ZodType, TOutput, TError extends Exception>(def: MutationDefinition<C, TArgs, TOutput, TError>) => MutationDefinition<C, TArgs, TOutput, TError>;
|
|
19
|
-
on?: <TEvent extends string, TPayload>(config: {
|
|
20
|
-
event: TEvent;
|
|
21
|
-
handler: (ctx: C, payload: TPayload) => AsyncResult<any, any>;
|
|
22
|
-
}) => any;
|
|
23
|
-
group?: <TGroup extends Record<string, CommandsDefinition>>(defs: TGroup) => TGroup;
|
|
24
|
-
};
|
package/dist/extensions/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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);
|
|
10
11
|
const contextPart = config.context ? config.context(options) : {};
|
|
11
|
-
// Ici, functionsBuilder garde son type générique <C>(c: C) => ...
|
|
12
12
|
const functionsBuilder = config.functions(options);
|
|
13
13
|
return {
|
|
14
14
|
context: contextPart,
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
+
/**
|
|
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.
|
|
7
|
+
*/
|
|
8
|
+
type ApplyContext<F, C> = F extends (context: C) => infer R ? R : never;
|
|
2
9
|
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
3
|
-
functions:
|
|
4
|
-
} ?
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
functions: TFunctionsFactory;
|
|
10
|
+
functions: infer F;
|
|
11
|
+
} ? ApplyContext<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
|
|
12
|
+
export type ExtensionBase = {
|
|
13
|
+
context: any;
|
|
14
|
+
functions: any;
|
|
9
15
|
};
|
|
16
|
+
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
17
|
+
export {};
|
package/package.json
CHANGED