@deessejs/functions 0.0.59 → 0.0.61
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,8 @@
|
|
|
1
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 {
|
|
4
|
+
functions: (ctx: TContext) => any;
|
|
5
|
+
}[]>(config: {
|
|
4
6
|
extensions: readonly [...TExtensions];
|
|
5
7
|
}) => MergeExtensions<TContext, TExtensions> & {
|
|
6
8
|
context: TContext;
|
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
|
-
//
|
|
6
|
+
// On demande des extensions dont la fonction 'functions' accepte TContext.
|
|
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.
|
|
8
9
|
withExtensions: (config) => {
|
|
9
10
|
const runtimeBuilder = {};
|
|
10
11
|
const dummyContext = {};
|
|
11
12
|
for (const extension of config.extensions) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (ext && typeof ext.functions === "function") {
|
|
15
|
-
const extensionMethods = ext.functions(dummyContext);
|
|
13
|
+
if (extension && typeof extension.functions === "function") {
|
|
14
|
+
const extensionMethods = extension.functions(dummyContext);
|
|
16
15
|
Object.assign(runtimeBuilder, extensionMethods);
|
|
17
16
|
}
|
|
18
17
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ZodType } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare function extensions<TSchema extends ZodType | undefined = undefined, TContextAddon extends Record<string, unknown> = Record<string, unknown>, TFunctionsFactory extends (<C>(context: C) => FunctionsForContext<C>) = (<C>(context: C) => FunctionsForContext<C>)>(config: {
|
|
2
|
+
import { InferOptions } from "./types";
|
|
3
|
+
export declare function extensions<TSchema extends ZodType | undefined = undefined, TContextAddon extends Record<string, unknown> = Record<string, unknown>, TFunctionsFactory = any>(config: {
|
|
5
4
|
name: string;
|
|
6
5
|
schema?: TSchema;
|
|
7
6
|
context?: (options: InferOptions<TSchema>) => TContextAddon;
|
|
8
7
|
functions: (options: InferOptions<TSchema>) => TFunctionsFactory;
|
|
9
|
-
}):
|
|
8
|
+
}): (...args: any[]) => {
|
|
9
|
+
context: TContextAddon;
|
|
10
|
+
functions: TFunctionsFactory;
|
|
11
|
+
};
|
package/dist/extensions/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// extensions/index.ts (ou extensions.ts)
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.extensions = extensions;
|
|
4
|
+
// On n'importe plus FunctionsForContext ici pour ne pas brider le type
|
|
5
5
|
function extensions(config) {
|
|
6
|
+
// Cela permet à TS de renvoyer l'objet exact avec la fonction générique intacte.
|
|
6
7
|
return (...args) => {
|
|
7
8
|
const optionsInput = args[0];
|
|
8
9
|
const options = (config.schema ? config.schema.parse(optionsInput) : undefined);
|
|
9
10
|
const contextPart = config.context ? config.context(options) : {};
|
|
11
|
+
// Ici, functionsBuilder garde son type générique <C>(c: C) => ...
|
|
10
12
|
const functionsBuilder = config.functions(options);
|
|
11
13
|
return {
|
|
12
14
|
context: contextPart,
|
package/dist/extensions/rpc.d.ts
CHANGED
|
@@ -5,15 +5,18 @@ import { CommandsDefinition, MutationDefinition, QueryDefinition } from "../cont
|
|
|
5
5
|
export type APINode = CommandsDefinition | {
|
|
6
6
|
[key: string]: APINode;
|
|
7
7
|
};
|
|
8
|
-
export declare const rpc:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}>;
|
|
8
|
+
export declare const rpc: (...args: any[]) => {
|
|
9
|
+
context: Record<string, unknown>;
|
|
10
|
+
functions: <C>(context: C) => {
|
|
11
|
+
query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception>(options: {
|
|
12
|
+
args: TArgs;
|
|
13
|
+
handler: (ctx: C, // C sera ici { user: ... }
|
|
14
|
+
args: z.core.output<TArgs>) => AsyncResult<TOutput, TError>;
|
|
15
|
+
}) => QueryDefinition<C, TArgs, TOutput, TError>;
|
|
16
|
+
mutation: <TArgs extends ZodType<any, any, any>, TOutput_1, TError_1 extends Exception>(options: {
|
|
17
|
+
args: TArgs;
|
|
18
|
+
handler: (ctx: C, args: z.core.output<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
19
|
+
}) => MutationDefinition<C, TArgs, TOutput_1, TError_1>;
|
|
20
|
+
group: <T extends Record<string, APINode>>(definitions: T) => T;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
* LA SOLUTION MATHÉMATIQUE.
|
|
4
|
-
* On ne demande pas "Est-ce que ça marche ?" (extends), on dit "Fais-le marcher !" (&).
|
|
5
|
-
*
|
|
6
|
-
* On crée une intersection entre :
|
|
7
|
-
* 1. Ta fonction générique F: <C>(c: C) => API<C>
|
|
8
|
-
* 2. Une fonction factice: (c: TContext) => unknown
|
|
9
|
-
*
|
|
10
|
-
* Pour calculer le ReturnType de cette intersection, TypeScript DOIT instancier
|
|
11
|
-
* le générique <C> de F avec TContext.
|
|
12
|
-
*/
|
|
13
|
-
type ApplyContext<F, C> = F extends (c: any) => any ? ReturnType<F & ((c: C) => unknown)> : never;
|
|
14
2
|
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
15
|
-
functions: infer
|
|
16
|
-
} ?
|
|
17
|
-
export type ExtensionBase = {
|
|
18
|
-
context: any;
|
|
19
|
-
functions: any;
|
|
20
|
-
};
|
|
3
|
+
functions: (ctx: any) => infer R;
|
|
4
|
+
} ? R : {}) & MergeExtensions<TContext, Tail> : {};
|
|
21
5
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
22
|
-
export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctionsFactory
|
|
6
|
+
export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctionsFactory> = (...args: TSchema extends ZodType ? [options: z.input<TSchema>] : [options?: undefined]) => {
|
|
23
7
|
context: TContextAddon;
|
|
24
8
|
functions: TFunctionsFactory;
|
|
25
9
|
};
|
|
26
|
-
export {};
|
package/package.json
CHANGED