@deessejs/functions 0.0.45 → 0.0.46
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,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function defineContext<TContext
|
|
3
|
-
withExtensions: <TExts extends readonly
|
|
1
|
+
import { Extension } from "../extensions/types";
|
|
2
|
+
export declare function defineContext<TContext extends Record<string, any>>(): {
|
|
3
|
+
withExtensions: <TExts extends readonly Extension<any>[]>(config: {
|
|
4
4
|
extensions: [...TExts];
|
|
5
|
-
}) =>
|
|
5
|
+
}) => MergeExtensions<TContext, TExts> & {
|
|
6
6
|
context: TContext;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
type
|
|
10
|
-
[K in keyof TExts]: TExts[K] extends
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}[number];
|
|
9
|
+
type MergeExtensions<TContext, TExts extends readonly Extension<any>[]> = UnionToIntersection<{
|
|
10
|
+
[K in keyof TExts]: TExts[K] extends Extension<infer F> ? F extends (ctx: TContext) => infer R ? R : never : never;
|
|
11
|
+
}[number]>;
|
|
12
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
14
13
|
export {};
|
package/dist/context/define.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineContext = defineContext;
|
|
4
|
+
// defineContext.ts
|
|
4
5
|
function defineContext() {
|
|
5
6
|
return {
|
|
6
7
|
withExtensions: (config) => {
|
|
7
8
|
const builder = {};
|
|
8
9
|
for (const ext of config.extensions) {
|
|
9
|
-
const
|
|
10
|
-
Object.assign(builder,
|
|
10
|
+
const { functions } = ext(); // ← chaque extension sait maintenant recevoir TContext
|
|
11
|
+
Object.assign(builder, functions);
|
|
11
12
|
}
|
|
13
|
+
// On ajoute la propriété context (runtime value = null, mais type correct)
|
|
14
|
+
Object.defineProperty(builder, "context", {
|
|
15
|
+
get() { return null; },
|
|
16
|
+
enumerable: true,
|
|
17
|
+
});
|
|
12
18
|
return builder;
|
|
13
19
|
},
|
|
14
20
|
};
|
package/dist/extensions/rpc.d.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { Exception } from "../errors/types";
|
|
3
2
|
import { AsyncResult } from "../types";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
3
|
+
export declare const rpc: () => {
|
|
4
|
+
functions: <TContext>() => {
|
|
5
|
+
query: <TArgs extends z.ZodType, TOutput, TError = never>(def: {
|
|
6
|
+
args: TArgs;
|
|
7
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
8
|
+
}) => {
|
|
9
|
+
args: TArgs;
|
|
10
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
11
|
+
_type: "query";
|
|
12
|
+
};
|
|
13
|
+
mutation: <TArgs extends z.ZodType, TOutput_1, TError_1 = never>(def: {
|
|
14
|
+
args: TArgs;
|
|
15
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
16
|
+
}) => {
|
|
17
|
+
args: TArgs;
|
|
18
|
+
handler: (ctx: TContext, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
|
|
19
|
+
_type: "mutation";
|
|
20
|
+
};
|
|
21
|
+
group: <G>(group: G) => G;
|
|
22
|
+
on: <TPayload>(config: {
|
|
23
|
+
event: string;
|
|
24
|
+
handler: (ctx: TContext, payload: TPayload) => AsyncResult<any, any>;
|
|
25
|
+
}) => {
|
|
26
|
+
event: string;
|
|
27
|
+
handler: (ctx: TContext, payload: TPayload) => AsyncResult<any, any>;
|
|
28
|
+
};
|
|
28
29
|
};
|
|
29
30
|
};
|
package/dist/extensions/rpc.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rpc =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
group: (g) => g,
|
|
3
|
+
exports.rpc = void 0;
|
|
4
|
+
const rpc = () => ({
|
|
5
|
+
functions: () => ({
|
|
6
|
+
query: (def) => ({ _type: "query", ...def }),
|
|
7
|
+
mutation: (def) => ({ _type: "mutation", ...def }),
|
|
8
|
+
group: (group) => group,
|
|
10
9
|
on: (config) => config,
|
|
11
|
-
}
|
|
12
|
-
}
|
|
10
|
+
}),
|
|
11
|
+
});
|
|
12
|
+
exports.rpc = rpc;
|
|
@@ -21,10 +21,9 @@ export type ExtensionConfig<TSchema extends ZodType | undefined, TContextAddon e
|
|
|
21
21
|
name: string;
|
|
22
22
|
schema?: TSchema;
|
|
23
23
|
context?: (options: InferOptions<TSchema>) => TContextAddon;
|
|
24
|
-
functions: (options: InferOptions<TSchema>) =>
|
|
24
|
+
functions: (options: InferOptions<TSchema>) => <C>(context: C) => any;
|
|
25
25
|
};
|
|
26
|
-
export type Extension<
|
|
27
|
-
|
|
28
|
-
functions: TFunctionsFactory;
|
|
26
|
+
export type Extension<F extends (ctx: any) => any> = () => {
|
|
27
|
+
functions: F;
|
|
29
28
|
};
|
|
30
29
|
export {};
|
package/package.json
CHANGED