@deessejs/functions 0.0.60 → 0.0.62
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 +1 -3
- package/dist/context/define.js +4 -4
- package/dist/context/types.d.ts +0 -9
- package/dist/extensions/index.d.ts +6 -4
- package/dist/extensions/index.js +2 -1
- package/dist/extensions/rpc.d.ts +15 -12
- package/dist/extensions/types.d.ts +14 -7
- package/package.json +1 -1
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,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
4
|
function defineContext() {
|
|
5
5
|
return {
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// ON UTILISE 'readonly any[]'.
|
|
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.
|
|
9
9
|
withExtensions: (config) => {
|
|
10
10
|
const runtimeBuilder = {};
|
|
11
11
|
const dummyContext = {};
|
|
12
12
|
for (const extension of config.extensions) {
|
|
13
|
-
//
|
|
13
|
+
// Runtime only
|
|
14
14
|
if (extension && typeof extension.functions === "function") {
|
|
15
15
|
const extensionMethods = extension.functions(dummyContext);
|
|
16
16
|
Object.assign(runtimeBuilder, extensionMethods);
|
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
|
-
};
|
|
@@ -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,8 +1,9 @@
|
|
|
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
|
+
// N'importe PAS FunctionsForContext ici pour le typage, ça brise la généricité.
|
|
5
5
|
function extensions(config) {
|
|
6
|
+
// On laisse TypeScript retourner l'objet tel quel.
|
|
6
7
|
return (...args) => {
|
|
7
8
|
const optionsInput = args[0];
|
|
8
9
|
const options = (config.schema ? config.schema.parse(optionsInput) : undefined);
|
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,13 +1,20 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
/**
|
|
3
|
+
* LA SOLUTION ULTIME : Intersection de ReturnType.
|
|
4
|
+
*
|
|
5
|
+
* 1. F & ((c: C) => unknown) : On crée une fonction hybride qui doit satisfaire
|
|
6
|
+
* TA fonction générique ET une fonction qui prend ton Contexte.
|
|
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).
|
|
10
|
+
*/
|
|
11
|
+
type ApplyContext<F, C> = F extends (c: any) => any ? ReturnType<F & ((c: C) => unknown)> : never;
|
|
6
12
|
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
7
|
-
functions:
|
|
8
|
-
} ?
|
|
13
|
+
functions: infer F;
|
|
14
|
+
} ? ApplyContext<F, TContext> : {}) & MergeExtensions<TContext, Tail> : {};
|
|
9
15
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
10
|
-
export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctionsFactory
|
|
16
|
+
export type Extension<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>, TFunctionsFactory> = (...args: TSchema extends ZodType ? [options: z.input<TSchema>] : [options?: undefined]) => {
|
|
11
17
|
context: TContextAddon;
|
|
12
18
|
functions: TFunctionsFactory;
|
|
13
19
|
};
|
|
20
|
+
export {};
|
package/package.json
CHANGED