@seam-rpc/server 5.0.1 → 5.1.0

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +16 -23
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Result, ApiError, ApiErrorInterface } from "@seam-rpc/core";
1
+ import { Result, ApiError } from "@seam-rpc/core";
2
2
  import EventEmitter from "events";
3
3
  import express, { Express, NextFunction, Request, RequestHandler, Response } from "express";
4
4
  import * as z from "zod";
@@ -29,14 +29,14 @@ export interface SeamEvents {
29
29
  inputValidationError: [error: unknown, context: SeamErrorContext];
30
30
  outputValidationError: [error: unknown, context: SeamErrorContext];
31
31
  }
32
- type ProcedureHandler<Input extends ProcedureInput, Output extends ProcedureOutput> = (options: ProcedureOptions<Input>) => Result<z.infer<Output>, ApiError> | Promise<Result<z.infer<Output>, ApiError>>;
32
+ type ProcedureHandler<Input extends ProcedureInput, Output extends ProcedureOutput> = (options: ProcedureOptions<Input>) => Result<z.infer<Output>, ApiError<any, any>> | Promise<Result<z.infer<Output>, ApiError<any, any>>>;
33
33
  interface ProcedureOptions<Input extends ProcedureInput> {
34
34
  input: Simplify<ProcedureInputData<Input>>;
35
35
  ctx: SeamContext;
36
36
  }
37
37
  type ProcedureInput = Record<string, z.ZodType>;
38
38
  type ProcedureOutput = z.ZodType;
39
- type ProcedureErrors = Record<string, z.ZodType | undefined>;
39
+ type ProcedureErrors = Record<string, any | undefined>;
40
40
  type ProcedureInputData<T extends ProcedureInput> = {
41
41
  [K in keyof T]: z.infer<T[K]>;
42
42
  };
@@ -46,10 +46,12 @@ interface SeamProcedure<Input extends ProcedureInput = {}, Output extends Proced
46
46
  errors?: Errors;
47
47
  handler?: ProcedureHandler<Input, Output>;
48
48
  }
49
- type ExtractResultError<T> = Awaited<T> extends Result<any, infer E> ? E : never;
50
- type ErrorUnionToMap<E> = {
51
- [K in E extends ApiErrorInterface<any, infer Code> ? Code : never]: Extract<E, ApiErrorInterface<any, K>> extends ApiErrorInterface<infer Map, K> ? Map[K] : never;
52
- };
49
+ type ExtractResultError<T> = Awaited<T> extends Result<any, undefined> ? never : Awaited<T> extends Result<any, infer E> ? E : never;
50
+ type ErrorUnionToMap<T> = [
51
+ T
52
+ ] extends [never] ? {} : [T] extends [ApiError<infer ErrorMap, infer Code>] ? {
53
+ [K in Code]: ErrorMap[K];
54
+ } : never;
53
55
  export type ProcedureBuilder<Input extends ProcedureInput = {}, Output extends ProcedureOutput = z.ZodUndefined, Errors extends ProcedureErrors = {}> = {
54
56
  _def: SeamProcedure<Input, Output, Errors>;
55
57
  input: <T extends ProcedureInput>(schema: T) => ProcedureBuilder<T, Output, Errors>;
@@ -69,24 +71,15 @@ export declare class SeamSpace extends EventEmitter<SeamEvents> {
69
71
  get jsonParser(): import("connect").NextHandleFunction;
70
72
  get fileHandler(): express.RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
71
73
  }
72
- type ErrorMapToUnion<E extends Record<string, any>> = {
73
- [K in keyof E]: ApiError<{
74
- [P in K]: E[K];
75
- }, K>;
76
- }[keyof E];
77
- type ResultFromErrors<Data, Errors extends Record<string, any>> = {
78
- ok: true;
79
- data: Data;
80
- } | (ErrorMapToUnion<Errors> extends infer E ? E extends ApiError<any, any> ? {
81
- ok: false;
82
- error: E;
83
- } : never : never);
84
74
  type InferInput<P> = P extends ProcedureBuilder<infer I, any, any> ? {
85
75
  [K in keyof I]: I[K] extends z.ZodType ? z.infer<I[K]> : never;
86
76
  } : never;
87
77
  type InferOutput<P> = P extends ProcedureBuilder<any, infer O, any> ? O extends z.ZodType ? z.infer<O> : never : never;
88
- type InferErrors<P> = P extends ProcedureBuilder<any, any, infer E> ? E : never;
89
- type ProcedureToFn<P> = P extends ProcedureBuilder<any, any, any> ? (input: InferInput<P>) => Promise<ResultFromErrors<InferOutput<P>, InferErrors<P>>> : never;
90
- type RouterToClient<T> = {
91
- [K in keyof T]: T[K] extends ProcedureBuilder<any, any, any> ? ProcedureToFn<T[K]> : RouterToClient<T[K]>;
78
+ type InferErrors<P> = P extends ProcedureBuilder<any, any, infer E> ? [keyof E] extends [never] ? undefined : {
79
+ [K in keyof E]: ApiError<E, K>;
80
+ }[keyof E] : never;
81
+ export type RouterToClient<RouterList extends Record<string, Record<string, ProcedureBuilder<any, any, any>>>> = {
82
+ [R in keyof RouterList]: {
83
+ [P in keyof RouterList[R]]: (input: InferInput<RouterList[R][P]>) => Promise<Result<InferOutput<RouterList[R][P]>, InferErrors<RouterList[R][P]>>>;
84
+ };
92
85
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seam-rpc/server",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",