@orpc/server 1.0.0-beta.6 → 1.0.3

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 (34) hide show
  1. package/README.md +13 -17
  2. package/dist/adapters/fetch/index.d.mts +17 -5
  3. package/dist/adapters/fetch/index.d.ts +17 -5
  4. package/dist/adapters/fetch/index.mjs +101 -7
  5. package/dist/adapters/node/index.d.mts +17 -5
  6. package/dist/adapters/node/index.d.ts +17 -5
  7. package/dist/adapters/node/index.mjs +2 -2
  8. package/dist/adapters/standard/index.d.mts +4 -4
  9. package/dist/adapters/standard/index.d.ts +4 -4
  10. package/dist/adapters/standard/index.mjs +2 -2
  11. package/dist/index.d.mts +545 -7
  12. package/dist/index.d.ts +545 -7
  13. package/dist/index.mjs +114 -6
  14. package/dist/plugins/index.d.mts +35 -3
  15. package/dist/plugins/index.d.ts +35 -3
  16. package/dist/plugins/index.mjs +9 -1
  17. package/dist/shared/{server.DCQgF_JR.d.mts → server.CN0534_m.d.mts} +4 -3
  18. package/dist/shared/{server._2UufoXA.d.ts → server.CjlA3NKP.d.ts} +2 -2
  19. package/dist/shared/{server.C8NkqxHo.d.ts → server.CuD15qZB.d.ts} +4 -3
  20. package/dist/shared/{server.DFFT_EZo.d.ts → server.D5fBlF9j.d.ts} +13 -12
  21. package/dist/shared/{server.C37gDhSZ.mjs → server.DG7Tamti.mjs} +3 -0
  22. package/dist/shared/{server.DLt5njUb.d.mts → server.DPWk5pjW.d.mts} +54 -5
  23. package/dist/shared/{server.DLt5njUb.d.ts → server.DPWk5pjW.d.ts} +54 -5
  24. package/dist/shared/{server.DOYDVeMX.d.mts → server.DY7OKEoj.d.mts} +13 -12
  25. package/dist/shared/{server.CGCwEAt_.d.mts → server.DjgtLwKi.d.mts} +2 -2
  26. package/dist/shared/{server.DFuJLDuo.mjs → server.qf03T-Xn.mjs} +1 -1
  27. package/package.json +8 -22
  28. package/dist/adapters/hono/index.d.mts +0 -22
  29. package/dist/adapters/hono/index.d.ts +0 -22
  30. package/dist/adapters/hono/index.mjs +0 -35
  31. package/dist/adapters/next/index.d.mts +0 -29
  32. package/dist/adapters/next/index.d.ts +0 -29
  33. package/dist/adapters/next/index.mjs +0 -32
  34. package/dist/shared/server.Bm0UqHzd.mjs +0 -103
@@ -1,6 +1,6 @@
1
1
  import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
2
- import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
2
  import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
3
+ import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
4
4
 
5
5
  type Context = Record<PropertyKey, any>;
6
6
  type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
@@ -28,6 +28,9 @@ interface Lazy<T> {
28
28
  };
29
29
  }
30
30
  type Lazyable<T> = T | Lazy<T>;
31
+ /**
32
+ * Create a lazy thing.
33
+ */
31
34
  declare function lazy<T>(loader: () => Promise<{
32
35
  default: T;
33
36
  }>, meta?: LazyMeta): Lazy<T>;
@@ -56,7 +59,15 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
56
59
  outputValidationIndex: number;
57
60
  handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
58
61
  }
62
+ /**
63
+ * This class represents a procedure.
64
+ *
65
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
66
+ */
59
67
  declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
68
+ /**
69
+ * This property holds the defined options.
70
+ */
60
71
  '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
61
72
  constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
62
73
  }
@@ -87,6 +98,11 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
87
98
  next: MiddlewareNextFn<TOutput>;
88
99
  errors: TErrorConstructorMap;
89
100
  }
101
+ /**
102
+ * A function that represents a middleware.
103
+ *
104
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
105
+ */
90
106
  interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
91
107
  (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
92
108
  }
@@ -106,9 +122,6 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TEr
106
122
  signal?: AbortSignal;
107
123
  lastEventId: string | undefined;
108
124
  }
109
- /**
110
- * Options for creating a procedure caller with comprehensive type safety
111
- */
112
125
  type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
113
126
  /**
114
127
  * This is helpful for logging and analytics.
@@ -120,24 +133,60 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
120
133
  } : {
121
134
  context: Value<TInitialContext, [clientContext: TClientContext]>;
122
135
  });
136
+ /**
137
+ * Create Server-side client from a procedure.
138
+ *
139
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
140
+ */
123
141
  declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
124
142
 
143
+ /**
144
+ * Represents a router, which defines a hierarchical structure of procedures.
145
+ *
146
+ * @info A procedure is a router too.
147
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
148
+ */
125
149
  type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
126
150
  [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
127
151
  };
128
152
  type AnyRouter = Router<any, any>;
129
153
  type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
154
+ /**
155
+ * Infer all initial context of the router.
156
+ *
157
+ * @info A procedure is a router too.
158
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
159
+ */
130
160
  type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
131
161
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
132
162
  };
163
+ /**
164
+ * Infer all current context of the router.
165
+ *
166
+ * @info A procedure is a router too.
167
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
168
+ */
133
169
  type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
134
170
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
135
171
  };
172
+ /**
173
+ * Infer all router inputs
174
+ *
175
+ * @info A procedure is a router too.
176
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
177
+ */
136
178
  type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
137
179
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
138
180
  };
181
+ /**
182
+ * Infer all router outputs
183
+ *
184
+ * @info A procedure is a router too.
185
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
186
+ */
139
187
  type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
140
188
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
189
  };
142
190
 
143
- export { type AnyProcedure as A, middlewareOutputFn as B, type Context as C, type ProcedureHandlerOptions as D, type ProcedureDef as E, isProcedure as F, createProcedureClient as G, type InferRouterInitialContexts as H, type InferRouterInitialContext as I, type InferRouterCurrentContexts as J, type InferRouterInputs as K, type Lazyable as L, type Middleware as M, type InferRouterOutputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type MergedInitialContext as c, type MergedCurrentContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, type ORPCErrorConstructorMapItemOptions as k, type ORPCErrorConstructorMapItem as l, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, type LazyMeta as p, lazy as q, isLazy as r, getLazyMeta as s, type MiddlewareResult as t, unlazy as u, validateORPCError as v, type MiddlewareNextFnOptions as w, type MiddlewareNextFn as x, type MiddlewareOutputFn as y, type MiddlewareOptions as z };
191
+ export { isProcedure as E, createProcedureClient as G, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, validateORPCError as v, middlewareOutputFn as z };
192
+ export type { AnyMiddleware as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, ProcedureClientInterceptorOptions as F, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, Middleware as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, Router as R, MergedInitialContext as a, MergedCurrentContext as b, MapInputMiddleware as c, CreateProcedureClientOptions as d, ProcedureClient as e, AnyRouter as f, Lazy as g, AnyProcedure as h, ProcedureHandler as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
@@ -2,7 +2,17 @@ import { HTTPPath, ORPCError } from '@orpc/client';
2
2
  import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
3
  import { Interceptor, ThrowableError } from '@orpc/shared';
4
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.mjs';
5
+ import { C as Context, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions, R as Router } from './server.DPWk5pjW.mjs';
6
+
7
+ interface StandardHandlerPlugin<TContext extends Context> {
8
+ order?: number;
9
+ init?(options: StandardHandlerOptions<TContext>): void;
10
+ }
11
+ declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
12
+ protected readonly plugins: TPlugin[];
13
+ constructor(plugins?: readonly TPlugin[]);
14
+ init(options: StandardHandlerOptions<T>): void;
15
+ }
6
16
 
7
17
  type StandardParams = Record<string, string>;
8
18
  type StandardMatchResult = {
@@ -20,16 +30,6 @@ interface StandardCodec {
20
30
  decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
31
  }
22
32
 
23
- interface StandardHandlerPlugin<TContext extends Context> {
24
- order?: number;
25
- init?(options: StandardHandlerOptions<TContext>): void;
26
- }
27
- declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
28
- protected readonly plugins: TPlugin[];
29
- constructor(plugins?: readonly TPlugin[]);
30
- init(options: StandardHandlerOptions<T>): void;
31
- }
32
-
33
33
  interface StandardHandleOptions<T extends Context> {
34
34
  prefix?: HTTPPath;
35
35
  context: T;
@@ -70,4 +70,5 @@ declare class StandardHandler<T extends Context> {
70
70
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
71
71
  }
72
72
 
73
- export { CompositeStandardHandlerPlugin as C, type StandardHandleOptions as S, type StandardHandlerOptions as a, StandardHandler as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, type StandardHandlerInterceptorOptions as h, type StandardHandlerPlugin as i };
73
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as i };
74
+ export type { StandardHandlerInterceptorOptions as S, StandardHandlerPlugin as a, StandardHandlerOptions as b, StandardCodec as c, StandardParams as d, StandardMatcher as e, StandardMatchResult as f, StandardHandleOptions as g, StandardHandleResult as h };
@@ -1,5 +1,5 @@
1
- import { C as Context } from './server.DLt5njUb.mjs';
2
- import { S as StandardHandleOptions } from './server.DOYDVeMX.mjs';
1
+ import { C as Context } from './server.DPWk5pjW.mjs';
2
+ import { g as StandardHandleOptions } from './server.DY7OKEoj.mjs';
3
3
 
4
4
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
5
  context?: T;
@@ -3,7 +3,7 @@ import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
3
3
  import '@orpc/standard-server/batch';
4
4
  import { ORPCError, toORPCError } from '@orpc/client';
5
5
  import { S as StrictGetMethodPlugin } from './server.BW-nUGgA.mjs';
6
- import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.C37gDhSZ.mjs';
6
+ import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.DG7Tamti.mjs';
7
7
 
8
8
  class CompositeStandardHandlerPlugin {
9
9
  plugins;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.6",
4
+ "version": "1.0.3",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,16 +34,6 @@
34
34
  "import": "./dist/adapters/fetch/index.mjs",
35
35
  "default": "./dist/adapters/fetch/index.mjs"
36
36
  },
37
- "./hono": {
38
- "types": "./dist/adapters/hono/index.d.mts",
39
- "import": "./dist/adapters/hono/index.mjs",
40
- "default": "./dist/adapters/hono/index.mjs"
41
- },
42
- "./next": {
43
- "types": "./dist/adapters/next/index.d.mts",
44
- "import": "./dist/adapters/next/index.mjs",
45
- "default": "./dist/adapters/next/index.mjs"
46
- },
47
37
  "./node": {
48
38
  "types": "./dist/adapters/node/index.d.mts",
49
39
  "import": "./dist/adapters/node/index.mjs",
@@ -53,20 +43,16 @@
53
43
  "files": [
54
44
  "dist"
55
45
  ],
56
- "peerDependencies": {
57
- "hono": ">=4.6.0",
58
- "next": ">=14.0.0"
59
- },
60
46
  "dependencies": {
61
- "@orpc/contract": "1.0.0-beta.6",
62
- "@orpc/shared": "1.0.0-beta.6",
63
- "@orpc/standard-server-fetch": "1.0.0-beta.6",
64
- "@orpc/standard-server": "1.0.0-beta.6",
65
- "@orpc/standard-server-node": "1.0.0-beta.6",
66
- "@orpc/client": "1.0.0-beta.6"
47
+ "@orpc/contract": "1.0.3",
48
+ "@orpc/shared": "1.0.3",
49
+ "@orpc/standard-server": "1.0.3",
50
+ "@orpc/standard-server-fetch": "1.0.3",
51
+ "@orpc/client": "1.0.3",
52
+ "@orpc/standard-server-node": "1.0.3"
67
53
  },
68
54
  "devDependencies": {
69
- "supertest": "^7.0.0"
55
+ "supertest": "^7.1.0"
70
56
  },
71
57
  "scripts": {
72
58
  "build": "unbuild",
@@ -1,22 +0,0 @@
1
- import { FetchHandler } from '../fetch/index.mjs';
2
- export { BodyLimitPlugin, BodyLimitPluginOptions, CompositeFetchHandlerPlugin, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
3
- import { Value, MaybeOptionalOptions } from '@orpc/shared';
4
- import { Context as Context$1, MiddlewareHandler } from 'hono';
5
- import { C as Context } from '../../shared/server.DLt5njUb.mjs';
6
- import { S as StandardHandleOptions } from '../../shared/server.DOYDVeMX.mjs';
7
- import '../../shared/server.CGCwEAt_.mjs';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.DCQgF_JR.mjs';
10
- import '@orpc/client/standard';
11
- import '@orpc/client';
12
- import '@orpc/contract';
13
- import '@orpc/standard-server';
14
-
15
- type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
16
- context?: Value<T, [Context$1]>;
17
- } : {
18
- context: Value<T, [Context$1]>;
19
- });
20
- declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...rest: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
21
-
22
- export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };
@@ -1,22 +0,0 @@
1
- import { FetchHandler } from '../fetch/index.js';
2
- export { BodyLimitPlugin, BodyLimitPluginOptions, CompositeFetchHandlerPlugin, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
3
- import { Value, MaybeOptionalOptions } from '@orpc/shared';
4
- import { Context as Context$1, MiddlewareHandler } from 'hono';
5
- import { C as Context } from '../../shared/server.DLt5njUb.js';
6
- import { S as StandardHandleOptions } from '../../shared/server.DFFT_EZo.js';
7
- import '../../shared/server._2UufoXA.js';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.C8NkqxHo.js';
10
- import '@orpc/client/standard';
11
- import '@orpc/client';
12
- import '@orpc/contract';
13
- import '@orpc/standard-server';
14
-
15
- type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
16
- context?: Value<T, [Context$1]>;
17
- } : {
18
- context: Value<T, [Context$1]>;
19
- });
20
- declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...rest: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
21
-
22
- export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };
@@ -1,35 +0,0 @@
1
- export { B as BodyLimitPlugin, C as CompositeFetchHandlerPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.Bm0UqHzd.mjs';
2
- import { resolveMaybeOptionalOptions, value } from '@orpc/shared';
3
- import '@orpc/client';
4
- import '@orpc/contract';
5
- import '../../shared/server.DFuJLDuo.mjs';
6
- import '@orpc/client/standard';
7
- import '@orpc/standard-server/batch';
8
- import '../../shared/server.BW-nUGgA.mjs';
9
- import '../../shared/server.C37gDhSZ.mjs';
10
- import '@orpc/standard-server-fetch';
11
- import '../../shared/server.BVwwTHyO.mjs';
12
-
13
- function createMiddleware(handler, ...rest) {
14
- const options = resolveMaybeOptionalOptions(rest);
15
- return async (c, next) => {
16
- const bodyProps = /* @__PURE__ */ new Set(["arrayBuffer", "blob", "formData", "json", "text"]);
17
- const request = c.req.method === "GET" || c.req.method === "HEAD" ? c.req.raw : new Proxy(c.req.raw, {
18
- // https://github.com/honojs/middleware/blob/main/packages/trpc-server/src/index.ts#L39
19
- get(target, prop) {
20
- if (bodyProps.has(prop)) {
21
- return () => c.req[prop]();
22
- }
23
- return Reflect.get(target, prop, target);
24
- }
25
- });
26
- const context = await value(options.context ?? {}, c);
27
- const { matched, response } = await handler.handle(request, { ...options, context });
28
- if (matched) {
29
- return c.newResponse(response.body, response);
30
- }
31
- await next();
32
- };
33
- }
34
-
35
- export { createMiddleware };
@@ -1,29 +0,0 @@
1
- import { FetchHandler } from '../fetch/index.mjs';
2
- export { BodyLimitPlugin, BodyLimitPluginOptions, CompositeFetchHandlerPlugin, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
3
- import { Value, MaybeOptionalOptions } from '@orpc/shared';
4
- import { NextRequest } from 'next/server';
5
- import { C as Context } from '../../shared/server.DLt5njUb.mjs';
6
- import { S as StandardHandleOptions } from '../../shared/server.DOYDVeMX.mjs';
7
- import '../../shared/server.CGCwEAt_.mjs';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.DCQgF_JR.mjs';
10
- import '@orpc/client/standard';
11
- import '@orpc/client';
12
- import '@orpc/contract';
13
- import '@orpc/standard-server';
14
-
15
- type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
16
- context?: Value<T, [NextRequest]>;
17
- } : {
18
- context: Value<T, [NextRequest]>;
19
- });
20
- interface ServeResult {
21
- GET(req: NextRequest): Promise<Response>;
22
- POST(req: NextRequest): Promise<Response>;
23
- PUT(req: NextRequest): Promise<Response>;
24
- PATCH(req: NextRequest): Promise<Response>;
25
- DELETE(req: NextRequest): Promise<Response>;
26
- }
27
- declare function serve<T extends Context>(handler: FetchHandler<T>, ...rest: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
28
-
29
- export { FetchHandler, type ServeOptions, type ServeResult, serve };
@@ -1,29 +0,0 @@
1
- import { FetchHandler } from '../fetch/index.js';
2
- export { BodyLimitPlugin, BodyLimitPluginOptions, CompositeFetchHandlerPlugin, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
3
- import { Value, MaybeOptionalOptions } from '@orpc/shared';
4
- import { NextRequest } from 'next/server';
5
- import { C as Context } from '../../shared/server.DLt5njUb.js';
6
- import { S as StandardHandleOptions } from '../../shared/server.DFFT_EZo.js';
7
- import '../../shared/server._2UufoXA.js';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.C8NkqxHo.js';
10
- import '@orpc/client/standard';
11
- import '@orpc/client';
12
- import '@orpc/contract';
13
- import '@orpc/standard-server';
14
-
15
- type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
16
- context?: Value<T, [NextRequest]>;
17
- } : {
18
- context: Value<T, [NextRequest]>;
19
- });
20
- interface ServeResult {
21
- GET(req: NextRequest): Promise<Response>;
22
- POST(req: NextRequest): Promise<Response>;
23
- PUT(req: NextRequest): Promise<Response>;
24
- PATCH(req: NextRequest): Promise<Response>;
25
- DELETE(req: NextRequest): Promise<Response>;
26
- }
27
- declare function serve<T extends Context>(handler: FetchHandler<T>, ...rest: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
28
-
29
- export { FetchHandler, type ServeOptions, type ServeResult, serve };
@@ -1,32 +0,0 @@
1
- export { B as BodyLimitPlugin, C as CompositeFetchHandlerPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.Bm0UqHzd.mjs';
2
- import { resolveMaybeOptionalOptions, value } from '@orpc/shared';
3
- import '@orpc/client';
4
- import '@orpc/contract';
5
- import '../../shared/server.DFuJLDuo.mjs';
6
- import '@orpc/client/standard';
7
- import '@orpc/standard-server/batch';
8
- import '../../shared/server.BW-nUGgA.mjs';
9
- import '../../shared/server.C37gDhSZ.mjs';
10
- import '@orpc/standard-server-fetch';
11
- import '../../shared/server.BVwwTHyO.mjs';
12
-
13
- function serve(handler, ...rest) {
14
- const options = resolveMaybeOptionalOptions(rest);
15
- const main = async (req) => {
16
- const context = await value(options.context ?? {}, req);
17
- const { matched, response } = await handler.handle(req, { ...options, context });
18
- if (matched) {
19
- return response;
20
- }
21
- return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
22
- };
23
- return {
24
- GET: main,
25
- POST: main,
26
- PUT: main,
27
- PATCH: main,
28
- DELETE: main
29
- };
30
- }
31
-
32
- export { serve };
@@ -1,103 +0,0 @@
1
- import { ORPCError } from '@orpc/client';
2
- import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
3
- import '@orpc/contract';
4
- import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from './server.DFuJLDuo.mjs';
5
- import '@orpc/client/standard';
6
- import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
7
- import { r as resolveFriendlyStandardHandleOptions } from './server.BVwwTHyO.mjs';
8
- import '@orpc/standard-server/batch';
9
-
10
- class BodyLimitPlugin {
11
- maxBodySize;
12
- constructor(options) {
13
- this.maxBodySize = options.maxBodySize;
14
- }
15
- initRuntimeAdapter(options) {
16
- options.adapterInterceptors ??= [];
17
- options.adapterInterceptors.push(async (options2) => {
18
- if (!options2.request.body) {
19
- return options2.next();
20
- }
21
- let currentBodySize = 0;
22
- const rawReader = options2.request.body.getReader();
23
- const reader = new ReadableStream({
24
- start: async (controller) => {
25
- try {
26
- if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
27
- controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
28
- return;
29
- }
30
- while (true) {
31
- const { done, value } = await rawReader.read();
32
- if (done) {
33
- break;
34
- }
35
- currentBodySize += value.length;
36
- if (currentBodySize > this.maxBodySize) {
37
- controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
38
- break;
39
- }
40
- controller.enqueue(value);
41
- }
42
- } finally {
43
- controller.close();
44
- }
45
- }
46
- });
47
- const requestInit = { body: reader, duplex: "half" };
48
- return options2.next({
49
- ...options2,
50
- request: new Request(options2.request, requestInit)
51
- });
52
- });
53
- }
54
- }
55
-
56
- class CompositeFetchHandlerPlugin extends CompositeStandardHandlerPlugin {
57
- initRuntimeAdapter(options) {
58
- for (const plugin of this.plugins) {
59
- plugin.initRuntimeAdapter?.(options);
60
- }
61
- }
62
- }
63
-
64
- class FetchHandler {
65
- constructor(standardHandler, options = {}) {
66
- this.standardHandler = standardHandler;
67
- const plugin = new CompositeFetchHandlerPlugin(options.plugins);
68
- plugin.initRuntimeAdapter(options);
69
- this.adapterInterceptors = toArray(options.adapterInterceptors);
70
- this.toFetchResponseOptions = options;
71
- }
72
- toFetchResponseOptions;
73
- adapterInterceptors;
74
- async handle(request, ...rest) {
75
- return intercept(
76
- this.adapterInterceptors,
77
- {
78
- ...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
79
- request,
80
- toFetchResponseOptions: this.toFetchResponseOptions
81
- },
82
- async ({ request: request2, toFetchResponseOptions, ...options }) => {
83
- const standardRequest = toStandardLazyRequest(request2);
84
- const result = await this.standardHandler.handle(standardRequest, options);
85
- if (!result.matched) {
86
- return result;
87
- }
88
- return {
89
- matched: true,
90
- response: toFetchResponse(result.response, toFetchResponseOptions)
91
- };
92
- }
93
- );
94
- }
95
- }
96
-
97
- class RPCHandler extends FetchHandler {
98
- constructor(router, options = {}) {
99
- super(new StandardRPCHandler(router, options), options);
100
- }
101
- }
102
-
103
- export { BodyLimitPlugin as B, CompositeFetchHandlerPlugin as C, FetchHandler as F, RPCHandler as R };