@deessejs/functions 0.0.30 → 0.0.31
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,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExtensionBase, MergeExtensions } from "../extensions/types";
|
|
2
2
|
export declare function defineContext<TContext extends Record<string, any>>(): {
|
|
3
|
-
withExtensions: <TExtensions extends
|
|
4
|
-
extensions:
|
|
3
|
+
withExtensions: <const TExtensions extends readonly ExtensionBase[]>(config: {
|
|
4
|
+
extensions: TExtensions;
|
|
5
5
|
}) => MergeExtensions<TContext, TExtensions> & {
|
|
6
6
|
context: TContext;
|
|
7
7
|
};
|
package/dist/context/define.js
CHANGED
|
@@ -3,15 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
4
|
function defineContext() {
|
|
5
5
|
return {
|
|
6
|
-
//
|
|
7
|
-
//
|
|
6
|
+
// <const TExtensions> (TS 5.0) ou readonly permet de dire à TS :
|
|
7
|
+
// "Ne traite pas ça comme un tableau générique, mais comme une suite précise d'éléments"
|
|
8
8
|
withExtensions: (config) => {
|
|
9
9
|
const builder = {};
|
|
10
10
|
const dummyContext = {};
|
|
11
11
|
for (const extension of config.extensions) {
|
|
12
|
+
// Runtime : on exécute et on fusionne
|
|
12
13
|
const extensionMethods = extension.functions(dummyContext);
|
|
13
14
|
Object.assign(builder, extensionMethods);
|
|
14
15
|
}
|
|
16
|
+
// Typage : On utilise la fusion récursive
|
|
15
17
|
return {
|
|
16
18
|
...builder,
|
|
17
19
|
context: {},
|
package/dist/extensions/rpc.d.ts
CHANGED
|
@@ -5,14 +5,15 @@ import { CommandsDefinition, MutationDefinition, QueryDefinition } from "../cont
|
|
|
5
5
|
export type APINode = CommandsDefinition | {
|
|
6
6
|
[key: string]: APINode;
|
|
7
7
|
};
|
|
8
|
-
export declare const rpc: import("./types").Extension<undefined, Record<string, unknown>, <
|
|
8
|
+
export declare const rpc: import("./types").Extension<undefined, Record<string, unknown>, <C>(context: C) => {
|
|
9
9
|
query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception>(options: {
|
|
10
10
|
args: TArgs;
|
|
11
|
-
handler: (ctx:
|
|
12
|
-
|
|
11
|
+
handler: (ctx: C, // C sera ici { user: ... }
|
|
12
|
+
args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
13
|
+
}) => QueryDefinition<C, TArgs, TOutput, TError>;
|
|
13
14
|
mutation: <TArgs extends ZodType<any, any, any>, TOutput_1, TError_1 extends Exception>(options: {
|
|
14
15
|
args: TArgs;
|
|
15
|
-
handler: (ctx:
|
|
16
|
-
}) => MutationDefinition<
|
|
16
|
+
handler: (ctx: C, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
17
|
+
}) => MutationDefinition<C, TArgs, TOutput_1, TError_1>;
|
|
17
18
|
group: <T extends Record<string, APINode>>(definitions: T) => T;
|
|
18
19
|
}>;
|
package/dist/extensions/rpc.js
CHANGED
|
@@ -4,13 +4,9 @@ exports.rpc = void 0;
|
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
exports.rpc = (0, _1.extensions)({
|
|
6
6
|
name: "rpc",
|
|
7
|
-
schema: undefined,
|
|
7
|
+
schema: undefined, // Pas d'options pour le moment
|
|
8
8
|
context: undefined,
|
|
9
|
-
//
|
|
10
|
-
// Grâce à la correction de l'étape 1, cela passera.
|
|
11
|
-
// Si votre TContext (dans defineContext) n'a pas d'index signature,
|
|
12
|
-
// TypeScript pourrait râler. Dans ce cas, retirez simplement 'extends Record...'
|
|
13
|
-
// et gardez juste <TContext>. Le plus sûr est sans contrainte :
|
|
9
|
+
// On garde une signature ultra-clean : <C>(context: C) => ...
|
|
14
10
|
functions: (_options) => (context) => ({
|
|
15
11
|
query: (options) => {
|
|
16
12
|
return { _type: "query", ...options };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import z, { ZodType } from "zod";
|
|
2
|
-
import { UnionToIntersection } from "../utils";
|
|
3
2
|
export type InferOptions<T extends ZodType | undefined> = T extends ZodType ? z.infer<T> : undefined;
|
|
4
|
-
type
|
|
5
|
-
export type ExtensionInstance = {
|
|
3
|
+
export type ExtensionBase = {
|
|
6
4
|
context: any;
|
|
7
5
|
functions: (context: any) => any;
|
|
8
6
|
};
|
|
9
|
-
export type MergeExtensions<TContext, TExtensions extends
|
|
7
|
+
export type MergeExtensions<TContext, TExtensions extends readonly any[]> = TExtensions extends readonly [infer Head, ...infer Tail] ? (Head extends {
|
|
8
|
+
functions: (ctx: TContext) => infer R;
|
|
9
|
+
} ? R : {}) & MergeExtensions<TContext, Tail> : {};
|
|
10
10
|
export type ExtensionConfig<TSchema extends ZodType | undefined, TContextAddon extends Record<string, unknown>> = {
|
|
11
11
|
name: string;
|
|
12
12
|
schema?: TSchema;
|
|
@@ -17,4 +17,3 @@ export type Extension<TSchema extends ZodType | undefined, TContextAddon extends
|
|
|
17
17
|
context: TContextAddon;
|
|
18
18
|
functions: TFunctionsFactory;
|
|
19
19
|
};
|
|
20
|
-
export {};
|
package/package.json
CHANGED