@orpc/server 0.0.0-next.aa57fb6 → 0.0.0-next.ad0709a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/dist/chunk-6RSW63UJ.js +136 -0
  2. package/dist/chunk-JHLUGXCM.js +294 -0
  3. package/dist/chunk-NOA3GBJQ.js +380 -0
  4. package/dist/fetch.js +13 -103
  5. package/dist/hono.js +31 -0
  6. package/dist/index.js +313 -377
  7. package/dist/next.js +38 -0
  8. package/dist/node.js +173 -0
  9. package/dist/src/adapters/fetch/index.d.ts +4 -0
  10. package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
  11. package/dist/src/adapters/fetch/types.d.ts +13 -0
  12. package/dist/src/adapters/fetch/utils.d.ts +6 -0
  13. package/dist/src/adapters/hono/index.d.ts +3 -0
  14. package/dist/src/adapters/hono/middleware.d.ts +13 -0
  15. package/dist/src/adapters/next/index.d.ts +3 -0
  16. package/dist/src/adapters/next/serve.d.ts +20 -0
  17. package/dist/src/adapters/node/index.d.ts +4 -0
  18. package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
  19. package/dist/src/adapters/node/types.d.ts +21 -0
  20. package/dist/src/adapters/node/utils.d.ts +5 -0
  21. package/dist/src/adapters/standard/handler.d.ts +33 -0
  22. package/dist/src/adapters/standard/index.d.ts +7 -0
  23. package/dist/src/adapters/standard/rpc-codec.d.ts +15 -0
  24. package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
  25. package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
  26. package/dist/src/adapters/standard/rpc-serializer.d.ts +16 -0
  27. package/dist/src/adapters/standard/types.d.ts +44 -0
  28. package/dist/src/builder-variants.d.ts +74 -0
  29. package/dist/src/builder.d.ts +46 -42
  30. package/dist/src/config.d.ts +6 -0
  31. package/dist/src/context.d.ts +9 -0
  32. package/dist/src/hidden.d.ts +8 -0
  33. package/dist/src/implementer-procedure.d.ts +30 -0
  34. package/dist/src/implementer-variants.d.ts +17 -0
  35. package/dist/src/implementer.d.ts +28 -0
  36. package/dist/src/index.d.ts +16 -10
  37. package/dist/src/lazy-utils.d.ts +6 -0
  38. package/dist/src/lazy.d.ts +13 -14
  39. package/dist/src/middleware-decorated.d.ts +10 -0
  40. package/dist/src/middleware-utils.d.ts +5 -0
  41. package/dist/src/middleware.d.ts +28 -17
  42. package/dist/src/procedure-client.d.ts +20 -0
  43. package/dist/src/procedure-decorated.d.ts +21 -0
  44. package/dist/src/procedure-utils.d.ts +17 -0
  45. package/dist/src/procedure.d.ts +25 -28
  46. package/dist/src/router-accessible-lazy.d.ts +8 -0
  47. package/dist/src/router-client.d.ts +22 -0
  48. package/dist/src/router.d.ts +25 -17
  49. package/dist/src/utils.d.ts +23 -2
  50. package/dist/standard.js +16 -0
  51. package/package.json +29 -9
  52. package/dist/chunk-FL4ZAGNE.js +0 -267
  53. package/dist/src/fetch/handle.d.ts +0 -7
  54. package/dist/src/fetch/handler.d.ts +0 -3
  55. package/dist/src/fetch/index.d.ts +0 -4
  56. package/dist/src/fetch/types.d.ts +0 -35
  57. package/dist/src/procedure-builder.d.ts +0 -31
  58. package/dist/src/procedure-caller.d.ts +0 -20
  59. package/dist/src/procedure-implementer.d.ts +0 -22
  60. package/dist/src/router-builder.d.ts +0 -27
  61. package/dist/src/router-caller.d.ts +0 -22
  62. package/dist/src/router-implementer.d.ts +0 -24
  63. package/dist/src/types.d.ts +0 -8
@@ -1,21 +1,29 @@
1
- import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { ANY_LAZY, DecoratedLazy, Lazy } from './lazy';
3
- import type { Context } from './types';
4
- import { type DecoratedProcedure, type Procedure } from './procedure';
5
- export interface Router<TContext extends Context> {
6
- [k: string]: Procedure<TContext, any, any, any, any> | Lazy<Procedure<TContext, any, any, any, any>> | Router<TContext> | Lazy<Router<TContext>>;
7
- }
8
- export type HandledRouter<TRouter extends Router<any>> = {
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
- };
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;
1
+ import type { AnyContractRouter, ContractProcedure, ErrorMap, HTTPPath, MergedErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { Context } from './context';
3
+ import type { Lazy, Lazyable } from './lazy';
4
+ import type { AnyMiddleware } from './middleware';
5
+ import type { AnyProcedure } from './procedure';
6
+ import { Procedure } from './procedure';
7
+ import { type AccessibleLazyRouter } from './router-accessible-lazy';
8
+ export type Router<TInitialContext extends Context, TContract extends AnyContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, any, UErrorMap, UMeta> : {
9
+ [K in keyof TContract]: TContract[K] extends AnyContractRouter ? Router<TInitialContext, TContract[K]> : never;
10
+ }>;
11
+ export type AnyRouter = Router<any, any>;
12
+ export type InferRouterInputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any, any> ? SchemaInput<UInputSchema> : {
13
+ [K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
13
14
  };
14
- export declare function toContractRouter(router: ContractRouter | Router<any>): ContractRouter;
15
- export type InferRouterInputs<T extends Router<any>> = {
16
- [K in keyof T]: T[K] extends Procedure<any, any, infer UInputSchema, any, any> ? SchemaInput<UInputSchema> : T[K] extends Router<any> ? InferRouterInputs<T[K]> : never;
15
+ export type InferRouterOutputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
16
+ [K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
17
17
  };
18
- export type InferRouterOutputs<T extends Router<any>> = {
19
- [K in keyof T]: T[K] extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput> ? SchemaOutput<UOutputSchema, UFuncOutput> : T[K] extends Router<any> ? InferRouterOutputs<T[K]> : never;
18
+ export type AdaptedRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap> = TRouter extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<AdaptedRouter<U, TInitialContext, TErrorMap>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
19
+ [K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
20
20
  };
21
+ export interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
22
+ middlewares: AnyMiddleware[];
23
+ tags?: readonly string[];
24
+ prefix?: HTTPPath;
25
+ errorMap: TErrorMap;
26
+ }
27
+ export declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
28
+ export declare function getRouterChild<T extends AnyRouter | Lazy<undefined>>(router: T, ...path: string[]): T extends Lazy<any> ? Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter>> | Lazy<undefined> : AnyRouter | Lazy<undefined> | undefined;
21
29
  //# sourceMappingURL=router.d.ts.map
@@ -1,3 +1,24 @@
1
- import type { Context, MergeContext } from './types';
2
- export declare function mergeContext<A extends Context, B extends Context>(a: A, b: B): MergeContext<A, B>;
1
+ import type { AnyContractProcedure, AnyContractRouter, HTTPPath } from '@orpc/contract';
2
+ import type { Lazy } from './lazy';
3
+ import type { AnyProcedure } from './procedure';
4
+ import type { AnyRouter } from './router';
5
+ export interface EachContractProcedureOptions {
6
+ router: AnyRouter | AnyContractRouter;
7
+ path: string[];
8
+ }
9
+ export interface EachContractProcedureCallbackOptions {
10
+ contract: AnyContractProcedure;
11
+ path: string[];
12
+ }
13
+ export interface EachContractProcedureLaziedOptions {
14
+ lazied: Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter> | AnyProcedure>;
15
+ path: string[];
16
+ }
17
+ export declare function eachContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void, laziedOptions?: EachContractProcedureLaziedOptions[]): EachContractProcedureLaziedOptions[];
18
+ export declare function eachAllContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void): Promise<void>;
19
+ export declare function convertPathToHttpPath(path: string[]): HTTPPath;
20
+ /**
21
+ * Create a new procedure that ensure the contract is applied to the procedure.
22
+ */
23
+ export declare function createContractedProcedure(contract: AnyContractProcedure, procedure: AnyProcedure): AnyProcedure;
3
24
  //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,16 @@
1
+ import {
2
+ RPCCodec,
3
+ RPCMatcher,
4
+ RPCSerializer,
5
+ StandardHandler,
6
+ serializeRPCJson
7
+ } from "./chunk-JHLUGXCM.js";
8
+ import "./chunk-NOA3GBJQ.js";
9
+ export {
10
+ RPCCodec,
11
+ RPCMatcher,
12
+ RPCSerializer,
13
+ StandardHandler,
14
+ serializeRPCJson
15
+ };
16
+ //# sourceMappingURL=standard.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.aa57fb6",
4
+ "version": "0.0.0-next.ad0709a",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -19,11 +19,31 @@
19
19
  "import": "./dist/index.js",
20
20
  "default": "./dist/index.js"
21
21
  },
22
+ "./standard": {
23
+ "types": "./dist/src/adapters/standard/index.d.ts",
24
+ "import": "./dist/standard.js",
25
+ "default": "./dist/standard.js"
26
+ },
22
27
  "./fetch": {
23
- "types": "./dist/src/fetch/index.d.ts",
28
+ "types": "./dist/src/adapters/fetch/index.d.ts",
24
29
  "import": "./dist/fetch.js",
25
30
  "default": "./dist/fetch.js"
26
31
  },
32
+ "./hono": {
33
+ "types": "./dist/src/adapters/hono/index.d.ts",
34
+ "import": "./dist/hono.js",
35
+ "default": "./dist/hono.js"
36
+ },
37
+ "./next": {
38
+ "types": "./dist/src/adapters/next/index.d.ts",
39
+ "import": "./dist/next.js",
40
+ "default": "./dist/next.js"
41
+ },
42
+ "./node": {
43
+ "types": "./dist/src/adapters/node/index.d.ts",
44
+ "import": "./dist/node.js",
45
+ "default": "./dist/node.js"
46
+ },
27
47
  "./🔒/*": {
28
48
  "types": "./dist/src/*.d.ts"
29
49
  }
@@ -34,19 +54,19 @@
34
54
  "dist"
35
55
  ],
36
56
  "peerDependencies": {
37
- "zod": ">=3.23.0",
38
- "@orpc/zod": "0.0.0-next.aa57fb6"
57
+ "hono": ">=4.6.0",
58
+ "next": ">=14.0.0"
39
59
  },
40
60
  "dependencies": {
41
- "@orpc/contract": "0.0.0-next.aa57fb6",
42
- "@orpc/shared": "0.0.0-next.aa57fb6",
43
- "@orpc/transformer": "0.0.0-next.aa57fb6"
61
+ "content-disposition": "^0.5.4",
62
+ "@orpc/contract": "0.0.0-next.ad0709a",
63
+ "@orpc/shared": "0.0.0-next.ad0709a"
44
64
  },
45
65
  "devDependencies": {
46
- "@orpc/openapi": "0.0.0-next.aa57fb6"
66
+ "light-my-request": "^6.5.1"
47
67
  },
48
68
  "scripts": {
49
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
69
+ "build": "tsup --onSuccess='tsc -b --noCheck'",
50
70
  "build:watch": "pnpm run build --watch",
51
71
  "type:check": "tsc -b"
52
72
  }
@@ -1,267 +0,0 @@
1
- // src/utils.ts
2
- function mergeContext(a, b) {
3
- if (!a)
4
- return b;
5
- if (!b)
6
- return a;
7
- return {
8
- ...a,
9
- ...b
10
- };
11
- }
12
-
13
- // src/middleware.ts
14
- var decoratedMiddlewareSymbol = Symbol("\u{1F512}decoratedMiddleware");
15
- function decorateMiddleware(middleware) {
16
- if (Reflect.get(middleware, decoratedMiddlewareSymbol)) {
17
- return middleware;
18
- }
19
- const concat = (concatMiddleware, mapInput2) => {
20
- const concatMiddleware_ = mapInput2 ? decorateMiddleware(concatMiddleware).mapInput(mapInput2) : concatMiddleware;
21
- return decorateMiddleware(async (input, context, meta, ...rest) => {
22
- const input_ = input;
23
- const context_ = context;
24
- const meta_ = meta;
25
- const next = async (options) => {
26
- return concatMiddleware_(input_, mergeContext(context_, options.context), meta_, ...rest);
27
- };
28
- const m1 = await middleware(input_, context_, {
29
- ...meta_,
30
- next
31
- }, ...rest);
32
- return m1;
33
- });
34
- };
35
- const mapInput = (map) => {
36
- return decorateMiddleware(
37
- (input, ...rest) => middleware(map(input), ...rest)
38
- );
39
- };
40
- return Object.assign(middleware, {
41
- [decoratedMiddlewareSymbol]: true,
42
- concat,
43
- mapInput
44
- });
45
- }
46
-
47
- // src/procedure-caller.ts
48
- import { trim, value } from "@orpc/shared";
49
- import { ORPCError } from "@orpc/shared/error";
50
- import { OpenAPIDeserializer } from "@orpc/transformer";
51
-
52
- // src/procedure.ts
53
- import {
54
- DecoratedContractProcedure,
55
- isContractProcedure
56
- } from "@orpc/contract";
57
- var Procedure = class {
58
- constructor(zz$p) {
59
- this.zz$p = zz$p;
60
- }
61
- };
62
- var DECORATED_PROCEDURE_SYMBOL = Symbol("DECORATED_PROCEDURE");
63
- function decorateProcedure(procedure) {
64
- if (DECORATED_PROCEDURE_SYMBOL in procedure) {
65
- return procedure;
66
- }
67
- return Object.assign(createProcedureCaller({
68
- procedure,
69
- context: void 0
70
- }), {
71
- [DECORATED_PROCEDURE_SYMBOL]: true,
72
- zz$p: procedure.zz$p,
73
- prefix(prefix) {
74
- return decorateProcedure({
75
- zz$p: {
76
- ...procedure.zz$p,
77
- contract: DecoratedContractProcedure.decorate(
78
- procedure.zz$p.contract
79
- ).prefix(prefix)
80
- }
81
- });
82
- },
83
- route(opts) {
84
- return decorateProcedure({
85
- zz$p: {
86
- ...procedure.zz$p,
87
- contract: DecoratedContractProcedure.decorate(
88
- procedure.zz$p.contract
89
- ).route(opts)
90
- }
91
- });
92
- },
93
- use(middleware, mapInput) {
94
- const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
95
- return decorateProcedure({
96
- zz$p: {
97
- ...procedure.zz$p,
98
- middlewares: [middleware_, ...procedure.zz$p.middlewares ?? []]
99
- }
100
- });
101
- }
102
- });
103
- }
104
- function isProcedure(item) {
105
- if (item instanceof Procedure)
106
- return true;
107
- return (typeof item === "object" || typeof item === "function") && item !== null && "zz$p" in item && typeof item.zz$p === "object" && item.zz$p !== null && "contract" in item.zz$p && isContractProcedure(item.zz$p.contract) && "func" in item.zz$p && typeof item.zz$p.func === "function";
108
- }
109
-
110
- // src/procedure-caller.ts
111
- function createProcedureCaller(options) {
112
- const loadProcedure = async () => {
113
- let procedure;
114
- if (isLazy(options.procedure)) {
115
- procedure = (await loadLazy(options.procedure)).default;
116
- } else {
117
- procedure = options.procedure;
118
- }
119
- if (!isProcedure(procedure)) {
120
- throw new ORPCError({
121
- code: "NOT_FOUND",
122
- message: "Not found",
123
- cause: new Error(trim(`
124
- This error should be caught by the typescript compiler.
125
- But if you still see this error, it means that you trying to call a lazy router (expected to be a lazy procedure).
126
- `))
127
- });
128
- }
129
- return procedure;
130
- };
131
- const caller = async (input) => {
132
- const path = options.path ?? [];
133
- const procedure = await loadProcedure();
134
- const input_ = (() => {
135
- if (!(input instanceof FormData)) {
136
- return input;
137
- }
138
- const transformer = new OpenAPIDeserializer({
139
- schema: procedure.zz$p.contract.zz$cp.InputSchema
140
- });
141
- return transformer.deserializeAsFormData(input);
142
- })();
143
- const validInput = (() => {
144
- const schema = procedure.zz$p.contract.zz$cp.InputSchema;
145
- if (!schema) {
146
- return input_;
147
- }
148
- try {
149
- return schema.parse(input_);
150
- } catch (e) {
151
- throw new ORPCError({
152
- message: "Validation input failed",
153
- code: "BAD_REQUEST",
154
- cause: e
155
- });
156
- }
157
- })();
158
- const middlewares = procedure.zz$p.middlewares ?? [];
159
- let currentMidIndex = 0;
160
- let currentContext = await value(options.context);
161
- const next = async (nextOptions) => {
162
- const mid = middlewares[currentMidIndex];
163
- currentMidIndex += 1;
164
- currentContext = mergeContext(currentContext, nextOptions.context);
165
- if (mid) {
166
- return await mid(validInput, currentContext, {
167
- path,
168
- procedure,
169
- next,
170
- output: (output2) => ({ output: output2, context: void 0 })
171
- });
172
- } else {
173
- return {
174
- output: await await procedure.zz$p.func(validInput, currentContext, {
175
- path,
176
- procedure
177
- }),
178
- context: currentContext
179
- };
180
- }
181
- };
182
- const output = (await next({})).output;
183
- const validOutput = await (async () => {
184
- const schema = procedure.zz$p.contract.zz$cp.OutputSchema;
185
- if (!schema) {
186
- return output;
187
- }
188
- const result = await schema.safeParseAsync(output);
189
- if (result.error) {
190
- throw new ORPCError({
191
- message: "Validation output failed",
192
- code: "INTERNAL_SERVER_ERROR",
193
- cause: result.error
194
- });
195
- }
196
- return result.data;
197
- })();
198
- return validOutput;
199
- };
200
- return caller;
201
- }
202
-
203
- // src/lazy.ts
204
- var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
205
- function createLazy(loader) {
206
- return {
207
- [LAZY_LOADER_SYMBOL]: loader
208
- };
209
- }
210
- function loadLazy(lazy) {
211
- return lazy[LAZY_LOADER_SYMBOL]();
212
- }
213
- function isLazy(item) {
214
- return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
215
- }
216
- function createFlattenLazy(lazy) {
217
- const flattenLoader = async () => {
218
- let current = await loadLazy(lazy);
219
- while (true) {
220
- if (!isLazy(current.default)) {
221
- break;
222
- }
223
- current = await loadLazy(current.default);
224
- }
225
- return current;
226
- };
227
- const flattenLazy = {
228
- [LAZY_LOADER_SYMBOL]: flattenLoader
229
- };
230
- return flattenLazy;
231
- }
232
- function decorateLazy(lazy) {
233
- const flattenLazy = createFlattenLazy(lazy);
234
- const procedureCaller = createProcedureCaller({
235
- procedure: flattenLazy,
236
- context: void 0
237
- });
238
- Object.assign(procedureCaller, flattenLazy);
239
- const recursive = new Proxy(procedureCaller, {
240
- get(target, key) {
241
- if (typeof key !== "string") {
242
- return Reflect.get(target, key);
243
- }
244
- return decorateLazy(createLazy(async () => {
245
- const current = await loadLazy(flattenLazy);
246
- return { default: current.default[key] };
247
- }));
248
- }
249
- });
250
- return recursive;
251
- }
252
-
253
- export {
254
- mergeContext,
255
- decorateMiddleware,
256
- LAZY_LOADER_SYMBOL,
257
- createLazy,
258
- loadLazy,
259
- isLazy,
260
- createFlattenLazy,
261
- decorateLazy,
262
- createProcedureCaller,
263
- Procedure,
264
- decorateProcedure,
265
- isProcedure
266
- };
267
- //# sourceMappingURL=chunk-FL4ZAGNE.js.map
@@ -1,7 +0,0 @@
1
- import type { Router } from '../router';
2
- import type { FetchHandler, FetchHandlerOptions } from './types';
3
- export type HandleFetchRequestOptions<TRouter extends Router<any>> = FetchHandlerOptions<TRouter> & {
4
- handlers: readonly [FetchHandler, ...FetchHandler[]];
5
- };
6
- export declare function handleFetchRequest<TRouter extends Router<any>>(options: HandleFetchRequestOptions<TRouter>): Promise<Response>;
7
- //# sourceMappingURL=handle.d.ts.map
@@ -1,3 +0,0 @@
1
- import type { FetchHandler } from './types';
2
- export declare function createORPCHandler(): FetchHandler;
3
- //# sourceMappingURL=handler.d.ts.map
@@ -1,4 +0,0 @@
1
- export * from './handle';
2
- export * from './handler';
3
- export * from './types';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1,35 +0,0 @@
1
- import type { PartialOnUndefinedDeep, Promisable, Value } from '@orpc/shared';
2
- import type { Router } from '../router';
3
- export interface FetchHandlerHooks {
4
- next: () => Promise<Response>;
5
- response: (response: Response) => Response;
6
- }
7
- export type FetchHandlerOptions<TRouter extends Router<any>> = {
8
- /**
9
- * The `router` used for handling the request and routing,
10
- *
11
- */
12
- router: TRouter;
13
- /**
14
- * The request need to be handled.
15
- */
16
- request: Request;
17
- /**
18
- * Remove the prefix from the request path.
19
- *
20
- * @example /orpc
21
- * @example /api
22
- */
23
- prefix?: string;
24
- /**
25
- * Hooks for executing logics on lifecycle events.
26
- */
27
- hooks?: (context: TRouter extends Router<infer UContext> ? UContext : never, hooks: FetchHandlerHooks) => Promisable<Response>;
28
- } & PartialOnUndefinedDeep<{
29
- /**
30
- * The context used to handle the request.
31
- */
32
- context: Value<TRouter extends Router<infer UContext> ? UContext : never>;
33
- }>;
34
- export type FetchHandler = <TRouter extends Router<any>>(options: FetchHandlerOptions<TRouter>) => Promise<Response | undefined>;
35
- //# sourceMappingURL=types.d.ts.map
@@ -1,31 +0,0 @@
1
- import type { MapInputMiddleware, Middleware } from './middleware';
2
- import type { Context, MergeContext } from './types';
3
- import { type ContractProcedure, type RouteOptions, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
4
- import { type DecoratedProcedure, type ProcedureFunc } from './procedure';
5
- import { ProcedureImplementer } from './procedure-implementer';
6
- export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
7
- zz$pb: {
8
- contract: ContractProcedure<TInputSchema, TOutputSchema>;
9
- middlewares?: Middleware<any, any, any, any>[];
10
- };
11
- constructor(zz$pb: {
12
- contract: ContractProcedure<TInputSchema, TOutputSchema>;
13
- middlewares?: Middleware<any, any, any, any>[];
14
- });
15
- /**
16
- * Self chainable
17
- */
18
- route(opts: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema>;
19
- input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, TOutputSchema>;
20
- output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, USchema>;
21
- /**
22
- * Convert to ProcedureBuilder
23
- */
24
- use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
25
- use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UMappedInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
26
- /**
27
- * Convert to Procedure
28
- */
29
- func<UFuncOutput extends SchemaOutput<TOutputSchema>>(func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
30
- }
31
- //# sourceMappingURL=procedure-builder.d.ts.map
@@ -1,20 +0,0 @@
1
- import type { SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { Lazy } from './lazy';
3
- import { type Value } from '@orpc/shared';
4
- import { type ANY_LAZY_PROCEDURE, type ANY_PROCEDURE, type Procedure } from './procedure';
5
- export interface CreateProcedureCallerOptions<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> {
6
- procedure: TProcedure;
7
- /**
8
- * The context used when calling the procedure.
9
- */
10
- context: Value<TProcedure extends Procedure<infer UContext, any, any, any, any> | Lazy<Procedure<infer UContext, any, any, any, any>> ? UContext : never>;
11
- /**
12
- * This is helpful for logging and analytics.
13
- *
14
- * @internal
15
- */
16
- path?: string[];
17
- }
18
- 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> | FormData] | (undefined extends SchemaInput<UInputSchema> ? [] : never)) => Promise<SchemaOutput<UOutputSchema, UFuncOutput>> : never;
19
- export declare function createProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE>(options: CreateProcedureCallerOptions<TProcedure>): ProcedureCaller<TProcedure>;
20
- //# sourceMappingURL=procedure-caller.d.ts.map
@@ -1,22 +0,0 @@
1
- import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { DecoratedLazy } from './lazy';
3
- import type { DecoratedProcedure, Procedure, ProcedureFunc } from './procedure';
4
- import type { Context, MergeContext } from './types';
5
- import { type MapInputMiddleware, type Middleware } from './middleware';
6
- export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
7
- zz$pi: {
8
- contract: ContractProcedure<TInputSchema, TOutputSchema>;
9
- middlewares?: Middleware<any, any, any, any>[];
10
- };
11
- constructor(zz$pi: {
12
- contract: ContractProcedure<TInputSchema, TOutputSchema>;
13
- middlewares?: Middleware<any, any, any, any>[];
14
- });
15
- use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
16
- use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UMappedInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
17
- func<UFuncOutput extends SchemaOutput<TOutputSchema>>(func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
18
- lazy<U extends Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, SchemaOutput<TOutputSchema>>>(loader: () => Promise<{
19
- default: U;
20
- }>): DecoratedLazy<U>;
21
- }
22
- //# sourceMappingURL=procedure-implementer.d.ts.map
@@ -1,27 +0,0 @@
1
- import type { DecoratedLazy } from './lazy';
2
- import type { HandledRouter, Router } from './router';
3
- import type { Context, MergeContext } from './types';
4
- import { type HTTPPath } from '@orpc/contract';
5
- import { type MapInputMiddleware, type Middleware } from './middleware';
6
- export declare const LAZY_ROUTER_PREFIX_SYMBOL: unique symbol;
7
- export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context> {
8
- zz$rb: {
9
- prefix?: HTTPPath;
10
- tags?: string[];
11
- middlewares?: Middleware<any, any, any, any>[];
12
- };
13
- constructor(zz$rb: {
14
- prefix?: HTTPPath;
15
- tags?: string[];
16
- middlewares?: Middleware<any, any, any, any>[];
17
- });
18
- prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
19
- tags(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
20
- use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, unknown, unknown>): RouterBuilder<TContext, MergeContext<TExtraContext, UExtraContext>>;
21
- use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, unknown>, mapInput: MapInputMiddleware<unknown, UMappedInput>): RouterBuilder<TContext, MergeContext<TExtraContext, UExtraContext>>;
22
- router<URouter extends Router<TContext>>(router: URouter): HandledRouter<URouter>;
23
- lazy<U extends Router<TContext>>(loader: () => Promise<{
24
- default: U;
25
- }>): DecoratedLazy<U>;
26
- }
27
- //# sourceMappingURL=router-builder.d.ts.map
@@ -1,22 +0,0 @@
1
- import type { Value } from '@orpc/shared';
2
- import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE } from './procedure';
3
- import type { Router } from './router';
4
- import { type ProcedureCaller } from './procedure-caller';
5
- export interface CreateRouterCallerOptions<TRouter extends Router<any>> {
6
- router: TRouter;
7
- /**
8
- * The context used when calling the procedure.
9
- */
10
- context: Value<TRouter extends Router<infer UContext> ? UContext : never>;
11
- /**
12
- * This is helpful for logging and analytics.
13
- *
14
- * @internal
15
- */
16
- basePath?: string[];
17
- }
18
- export type RouterCaller<TRouter extends Router<any>> = {
19
- [K in keyof TRouter]: TRouter[K] extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE ? ProcedureCaller<TRouter[K]> : TRouter[K] extends Router<any> ? RouterCaller<TRouter[K]> : never;
20
- };
21
- export declare function createRouterCaller<TRouter extends Router<any>>(options: CreateRouterCallerOptions<TRouter>): RouterCaller<TRouter>;
22
- //# sourceMappingURL=router-caller.d.ts.map
@@ -1,24 +0,0 @@
1
- import type { DecoratedLazy } from './lazy';
2
- import type { Middleware } from './middleware';
3
- import type { HandledRouter, RouterWithContract } from './router';
4
- import type { Context } from './types';
5
- import { type ContractProcedure, type ContractRouter } from '@orpc/contract';
6
- import { ProcedureImplementer } from './procedure-implementer';
7
- export declare const ROUTER_CONTRACT_SYMBOL: unique symbol;
8
- export declare class RouterImplementer<TContext extends Context, TContract extends ContractRouter> {
9
- zz$ri: {
10
- contract: TContract;
11
- };
12
- constructor(zz$ri: {
13
- contract: TContract;
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>>;
19
- }
20
- export type ChainedRouterImplementer<TContext extends Context, TContract extends ContractRouter, TExtraContext extends Context> = {
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;
22
- } & RouterImplementer<TContext, TContract>;
23
- export declare function chainRouterImplementer<TContext extends Context, TContract extends ContractRouter, TExtraContext extends Context>(contract: TContract, middlewares?: Middleware<any, any, any, any>[]): ChainedRouterImplementer<TContext, TContract, TExtraContext>;
24
- //# sourceMappingURL=router-implementer.d.ts.map
@@ -1,8 +0,0 @@
1
- import type { WELL_DEFINED_PROCEDURE } from './procedure';
2
- export type Context = Record<string, unknown> | undefined;
3
- export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
4
- export interface Meta {
5
- path: string[];
6
- procedure: WELL_DEFINED_PROCEDURE;
7
- }
8
- //# sourceMappingURL=types.d.ts.map