@orpc/server 0.14.0 → 0.16.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.
@@ -108,26 +108,32 @@ function isProcedure(item) {
108
108
 
109
109
  // src/procedure-caller.ts
110
110
  function createProcedureCaller(options) {
111
- const caller = async (input) => {
111
+ const caller = async (...args) => {
112
+ const [input, callerOptions] = args;
112
113
  const path = options.path ?? [];
113
114
  const procedure = await loadProcedure(options.procedure);
114
115
  const context = await value(options.context);
115
116
  const execute = async () => {
116
- const validInput = (() => {
117
+ const validInput = await (async () => {
117
118
  const schema = procedure.zz$p.contract.zz$cp.InputSchema;
118
119
  if (!schema) {
119
120
  return input;
120
121
  }
121
- try {
122
- return schema.parse(input);
123
- } catch (e) {
122
+ const result = await schema["~standard"].validate(input);
123
+ if (result.issues) {
124
124
  throw new ORPCError({
125
125
  message: "Validation input failed",
126
126
  code: "BAD_REQUEST",
127
- cause: e
127
+ issues: result.issues
128
128
  });
129
129
  }
130
+ return result.value;
130
131
  })();
132
+ const meta = {
133
+ path,
134
+ procedure,
135
+ signal: callerOptions?.signal
136
+ };
131
137
  const middlewares = procedure.zz$p.middlewares ?? [];
132
138
  let currentMidIndex = 0;
133
139
  let currentContext = context;
@@ -137,17 +143,13 @@ function createProcedureCaller(options) {
137
143
  currentContext = mergeContext(currentContext, nextOptions.context);
138
144
  if (mid) {
139
145
  return await mid(validInput, currentContext, {
140
- path,
141
- procedure,
146
+ ...meta,
142
147
  next,
143
148
  output: (output3) => ({ output: output3, context: void 0 })
144
149
  });
145
150
  } else {
146
151
  return {
147
- output: await await procedure.zz$p.func(validInput, currentContext, {
148
- path,
149
- procedure
150
- }),
152
+ output: await await procedure.zz$p.func(validInput, currentContext, meta),
151
153
  context: currentContext
152
154
  };
153
155
  }
@@ -158,15 +160,14 @@ function createProcedureCaller(options) {
158
160
  if (!schema) {
159
161
  return output2;
160
162
  }
161
- const result = await schema.safeParseAsync(output2);
162
- if (result.error) {
163
+ const result = await schema["~standard"].validate(output2);
164
+ if (result.issues) {
163
165
  throw new ORPCError({
164
166
  message: "Validation output failed",
165
- code: "INTERNAL_SERVER_ERROR",
166
- cause: result.error
167
+ code: "INTERNAL_SERVER_ERROR"
167
168
  });
168
169
  }
169
- return result.data;
170
+ return result.value;
170
171
  })();
171
172
  return validOutput;
172
173
  };
@@ -269,4 +270,4 @@ export {
269
270
  decorateProcedure,
270
271
  isProcedure
271
272
  };
272
- //# sourceMappingURL=chunk-MZXEMHFS.js.map
273
+ //# sourceMappingURL=chunk-Z2PQ6UAM.js.map
package/dist/fetch.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  createProcedureCaller,
3
3
  isLazy,
4
4
  isProcedure
5
- } from "./chunk-MZXEMHFS.js";
5
+ } from "./chunk-Z2PQ6UAM.js";
6
6
 
7
7
  // src/fetch/handle.ts
8
8
  import { ORPCError } from "@orpc/shared/error";
@@ -48,7 +48,7 @@ function createORPCHandler() {
48
48
  procedure: match.procedure,
49
49
  path: match.path
50
50
  });
51
- const output = await caller(input);
51
+ const output = await caller(input, { signal: options.signal });
52
52
  const { body, headers } = serializer.serialize(output);
53
53
  return new Response(body, {
54
54
  status: 200,
@@ -61,7 +61,9 @@ function createORPCHandler() {
61
61
  context,
62
62
  execute: handler,
63
63
  input: options.request,
64
- meta: void 0
64
+ meta: {
65
+ signal: options.signal
66
+ }
65
67
  });
66
68
  } catch (e) {
67
69
  const error = e instanceof ORPCError2 ? e : new ORPCError2({
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  loadLazy,
13
13
  loadProcedure,
14
14
  mergeContext
15
- } from "./chunk-MZXEMHFS.js";
15
+ } from "./chunk-Z2PQ6UAM.js";
16
16
 
17
17
  // src/builder.ts
18
18
  import {
@@ -1,5 +1,6 @@
1
1
  import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared';
2
2
  import type { Router } from '../router';
3
+ import type { CallerOptions } from '../types';
3
4
  export type FetchHandlerOptions<TRouter extends Router<any>> = {
4
5
  /**
5
6
  * The `router` used for handling the request and routing,
@@ -22,6 +23,6 @@ export type FetchHandlerOptions<TRouter extends Router<any>> = {
22
23
  * The context used to handle the request.
23
24
  */
24
25
  context: Value<TRouter extends Router<infer UContext> ? UContext : never>;
25
- }> & Hooks<Request, Response, TRouter extends Router<infer UContext> ? UContext : never, undefined>;
26
+ }> & CallerOptions & Hooks<Request, Response, TRouter extends Router<infer UContext> ? UContext : never, CallerOptions>;
26
27
  export type FetchHandler = <TRouter extends Router<any>>(options: FetchHandlerOptions<TRouter>) => Promise<Response | undefined>;
27
28
  //# sourceMappingURL=types.d.ts.map
@@ -2,6 +2,7 @@ import type { SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared';
3
3
  import type { Lazy } from './lazy';
4
4
  import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Procedure } from './procedure';
5
+ import type { Caller } from './types';
5
6
  export type CreateProcedureCallerOptions<T extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = T extends Procedure<infer UContext, any, any, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<infer UContext, any, any, infer UOutputSchema, infer UFuncOutput>> ? {
6
7
  procedure: T;
7
8
  /**
@@ -19,7 +20,7 @@ export type CreateProcedureCallerOptions<T extends ANY_PROCEDURE | ANY_LAZY_PROC
19
20
  path: string[];
20
21
  procedure: ANY_PROCEDURE;
21
22
  }> : never;
22
- export type ProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = TProcedure extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>> ? (...input: [input: SchemaInput<UInputSchema>] | (undefined extends SchemaInput<UInputSchema> ? [] : never)) => Promise<SchemaOutput<UOutputSchema, UFuncOutput>> : never;
23
+ export type ProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = TProcedure extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>> ? Caller<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>> : never;
23
24
  export declare function createProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE>(options: CreateProcedureCallerOptions<TProcedure>): ProcedureCaller<TProcedure>;
24
25
  export declare function loadProcedure(procedure: ANY_PROCEDURE | ANY_LAZY_PROCEDURE): Promise<ANY_PROCEDURE>;
25
26
  //# sourceMappingURL=procedure-caller.d.ts.map
@@ -12,10 +12,10 @@ export declare class RouterImplementer<TContext extends Context, TContract exten
12
12
  constructor(zz$ri: {
13
13
  contract: TContract;
14
14
  });
15
- router(router: RouterWithContract<TContext, TContract>): HandledRouter<RouterWithContract<TContext, TContract>>;
16
- lazy(loader: () => Promise<{
17
- default: RouterWithContract<TContext, TContract>;
18
- }>): DecoratedLazy<RouterWithContract<TContext, TContract>>;
15
+ router<U extends RouterWithContract<TContext, TContract>>(router: U): HandledRouter<U>;
16
+ lazy<U extends RouterWithContract<TContext, TContract>>(loader: () => Promise<{
17
+ default: U;
18
+ }>): DecoratedLazy<U>;
19
19
  }
20
20
  export type ChainedRouterImplementer<TContext extends Context, TContract extends ContractRouter, TExtraContext extends Context> = {
21
21
  [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : TContract[K] extends ContractRouter ? ChainedRouterImplementer<TContext, TContract[K], TExtraContext> : never;
@@ -9,7 +9,7 @@ export type HandledRouter<TRouter extends Router<any>> = {
9
9
  [K in keyof TRouter]: TRouter[K] extends Procedure<infer UContext, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? DecoratedProcedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput> : TRouter[K] extends ANY_LAZY ? DecoratedLazy<TRouter[K]> : TRouter[K] extends Router<any> ? HandledRouter<TRouter[K]> : never;
10
10
  };
11
11
  export type RouterWithContract<TContext extends Context, TContract extends ContractRouter> = {
12
- [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any> | Lazy<Procedure<TContext, any, UInputSchema, UOutputSchema, any>> : TContract[K] extends ContractRouter ? RouterWithContract<TContext, TContract[K]> | Lazy<RouterWithContract<TContext, TContract[K]>> : never;
12
+ [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any> | Lazy<Procedure<TContext, any, UInputSchema, UOutputSchema, any>> : TContract[K] extends ContractRouter ? RouterWithContract<TContext, TContract[K]> : never;
13
13
  };
14
14
  export declare function toContractRouter(router: ContractRouter | Router<any>): ContractRouter;
15
15
  export type InferRouterInputs<T extends Router<any>> = {
@@ -1,7 +1,13 @@
1
1
  import type { WELL_DEFINED_PROCEDURE } from './procedure';
2
2
  export type Context = Record<string, unknown> | undefined;
3
3
  export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
4
- export interface Meta {
4
+ export interface CallerOptions {
5
+ signal?: AbortSignal;
6
+ }
7
+ export interface Caller<TInput, TOutput> {
8
+ (...opts: [input: TInput, options?: CallerOptions] | (undefined extends TInput ? [] : never)): Promise<TOutput>;
9
+ }
10
+ export interface Meta extends CallerOptions {
5
11
  path: string[];
6
12
  procedure: WELL_DEFINED_PROCEDURE;
7
13
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.14.0",
4
+ "version": "0.16.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,16 +34,15 @@
34
34
  "dist"
35
35
  ],
36
36
  "peerDependencies": {
37
- "zod": ">=3.23.0",
38
- "@orpc/zod": "0.14.0"
37
+ "@orpc/zod": "0.16.0"
39
38
  },
40
39
  "dependencies": {
41
- "@orpc/shared": "0.14.0",
42
- "@orpc/transformer": "0.14.0",
43
- "@orpc/contract": "0.14.0"
40
+ "@orpc/contract": "0.16.0",
41
+ "@orpc/shared": "0.16.0",
42
+ "@orpc/transformer": "0.16.0"
44
43
  },
45
44
  "devDependencies": {
46
- "@orpc/openapi": "0.14.0"
45
+ "@orpc/openapi": "0.16.0"
47
46
  },
48
47
  "scripts": {
49
48
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",