@deessejs/functions 0.0.29 → 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
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// src/context/index.ts (ou defineContext.ts)
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.defineContext = defineContext;
|
|
5
4
|
function defineContext() {
|
|
6
5
|
return {
|
|
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"
|
|
7
8
|
withExtensions: (config) => {
|
|
8
9
|
const builder = {};
|
|
9
10
|
const dummyContext = {};
|
|
10
11
|
for (const extension of config.extensions) {
|
|
11
|
-
//
|
|
12
|
-
// mais au runtime c'est bien la fonction.
|
|
12
|
+
// Runtime : on exécute et on fusionne
|
|
13
13
|
const extensionMethods = extension.functions(dummyContext);
|
|
14
14
|
Object.assign(builder, extensionMethods);
|
|
15
15
|
}
|
|
16
|
+
// Typage : On utilise la fusion récursive
|
|
16
17
|
return {
|
|
17
18
|
...builder,
|
|
18
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,10 +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
|
-
// C'est ApplyContext qui se chargera d'injecter le bon type (celui de defineContext).
|
|
9
|
+
// On garde une signature ultra-clean : <C>(context: C) => ...
|
|
11
10
|
functions: (_options) => (context) => ({
|
|
12
11
|
query: (options) => {
|
|
13
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
|
-
functions: any;
|
|
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