@deessejs/functions 0.0.47 → 0.0.48

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.
@@ -1,30 +1,19 @@
1
- import { z } from "zod";
1
+ import z, { ZodType } from "zod";
2
+ import { Exception } from "../errors/types";
2
3
  import { AsyncResult } from "../types";
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
- };
29
- };
4
+ import { CommandsDefinition, MutationDefinition, QueryDefinition } from "../context/types";
5
+ export type APINode = CommandsDefinition | {
6
+ [key: string]: APINode;
30
7
  };
8
+ export declare const rpc: import("./types").Extension<undefined, Record<string, unknown>, <C>(context: C) => {
9
+ query: <TArgs extends ZodType<any, any, any>, TOutput, TError extends Exception>(options: {
10
+ args: TArgs;
11
+ handler: (ctx: C, // C sera ici { user: ... }
12
+ args: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
13
+ }) => QueryDefinition<C, TArgs, TOutput, TError>;
14
+ mutation: <TArgs extends ZodType<any, any, any>, TOutput_1, TError_1 extends Exception>(options: {
15
+ args: TArgs;
16
+ handler: (ctx: C, args: z.infer<TArgs>) => AsyncResult<TOutput_1, TError_1>;
17
+ }) => MutationDefinition<C, TArgs, TOutput_1, TError_1>;
18
+ group: <T extends Record<string, APINode>>(definitions: T) => T;
19
+ }>;
@@ -1,12 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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,
9
- on: (config) => config,
4
+ const _1 = require(".");
5
+ exports.rpc = (0, _1.extensions)({
6
+ name: "rpc",
7
+ schema: undefined, // Pas d'options pour le moment
8
+ context: undefined,
9
+ // On garde une signature ultra-clean : <C>(context: C) => ...
10
+ functions: (_options) => (context) => ({
11
+ query: (options) => {
12
+ return { _type: "query", ...options };
13
+ },
14
+ mutation: (options) => {
15
+ return { _type: "mutation", ...options };
16
+ },
17
+ group: (definitions) => definitions,
10
18
  }),
11
19
  });
12
- exports.rpc = rpc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.47",
3
+ "version": "0.0.48",
4
4
  "description": "A powerful utility library for building type-safe APIs and functions with context management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",