@orpc/server 0.0.0-next.9adcd05 → 0.0.0-next.9af314c
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.
- package/README.md +29 -21
- package/dist/adapters/aws-lambda/index.d.mts +46 -0
- package/dist/adapters/aws-lambda/index.d.ts +46 -0
- package/dist/adapters/aws-lambda/index.mjs +42 -0
- package/dist/adapters/bun-ws/index.d.mts +36 -0
- package/dist/adapters/bun-ws/index.d.ts +36 -0
- package/dist/adapters/bun-ws/index.mjs +47 -0
- package/dist/adapters/crossws/index.d.mts +33 -0
- package/dist/adapters/crossws/index.d.ts +33 -0
- package/dist/adapters/crossws/index.mjs +47 -0
- package/dist/adapters/fetch/index.d.mts +63 -10
- package/dist/adapters/fetch/index.d.ts +63 -10
- package/dist/adapters/fetch/index.mjs +109 -8
- package/dist/adapters/message-port/index.d.mts +31 -0
- package/dist/adapters/message-port/index.d.ts +31 -0
- package/dist/adapters/message-port/index.mjs +41 -0
- package/dist/adapters/node/index.d.mts +65 -21
- package/dist/adapters/node/index.d.ts +65 -21
- package/dist/adapters/node/index.mjs +88 -23
- package/dist/adapters/standard/index.d.mts +11 -15
- package/dist/adapters/standard/index.d.ts +11 -15
- package/dist/adapters/standard/index.mjs +5 -3
- package/dist/adapters/standard-peer/index.d.mts +14 -0
- package/dist/adapters/standard-peer/index.d.ts +14 -0
- package/dist/adapters/standard-peer/index.mjs +7 -0
- package/dist/adapters/websocket/index.d.mts +54 -0
- package/dist/adapters/websocket/index.d.ts +54 -0
- package/dist/adapters/websocket/index.mjs +69 -0
- package/dist/adapters/ws/index.d.mts +31 -0
- package/dist/adapters/ws/index.d.ts +31 -0
- package/dist/adapters/ws/index.mjs +39 -0
- package/dist/helpers/index.d.mts +130 -0
- package/dist/helpers/index.d.ts +130 -0
- package/dist/helpers/index.mjs +182 -0
- package/dist/hibernation/index.d.mts +44 -0
- package/dist/hibernation/index.d.ts +44 -0
- package/dist/hibernation/index.mjs +65 -0
- package/dist/index.d.mts +634 -95
- package/dist/index.d.ts +634 -95
- package/dist/index.mjs +193 -37
- package/dist/plugins/index.d.mts +157 -19
- package/dist/plugins/index.d.ts +157 -19
- package/dist/plugins/index.mjs +190 -17
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.C6Q5sqYw.mjs +20 -0
- package/dist/shared/server.CC8z0B3U.d.mts +32 -0
- package/dist/shared/{server.3cSam35R.mjs → server.CIL9uKTN.mjs} +68 -32
- package/dist/shared/server.CNZgPgce.d.ts +12 -0
- package/dist/shared/server.Cu-7se50.d.mts +12 -0
- package/dist/shared/server.Cwq7K86l.d.mts +42 -0
- package/dist/shared/server.DHgXKx3q.d.mts +74 -0
- package/dist/shared/server.DOwaI1le.d.ts +32 -0
- package/dist/shared/server.DVBSOxWU.d.ts +74 -0
- package/dist/shared/server.DZ5BIITo.mjs +9 -0
- package/dist/shared/{server.BFBhsdJr.mjs → server.NeumLVdS.mjs} +66 -41
- package/dist/shared/server.a_VzWVCm.d.ts +42 -0
- package/dist/shared/{server.CPteJIPP.d.mts → server.wMv480px.d.mts} +73 -24
- package/dist/shared/{server.CPteJIPP.d.ts → server.wMv480px.d.ts} +73 -24
- package/package.json +70 -20
- package/dist/adapters/hono/index.d.mts +0 -19
- package/dist/adapters/hono/index.d.ts +0 -19
- package/dist/adapters/hono/index.mjs +0 -32
- package/dist/adapters/next/index.d.mts +0 -26
- package/dist/adapters/next/index.d.ts +0 -26
- package/dist/adapters/next/index.mjs +0 -29
- package/dist/shared/server.BZRSVRDu.d.ts +0 -77
- package/dist/shared/server.CjB_m7jG.mjs +0 -28
- package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
- package/dist/shared/server.iM8li30u.d.mts +0 -77
package/dist/index.mjs
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
-
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
|
1
|
+
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter, fallbackContractConfig } from '@orpc/contract';
|
2
2
|
export { ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
-
import { P as Procedure,
|
4
|
-
export { L as LAZY_SYMBOL,
|
3
|
+
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, u as unlazy, g as getRouter, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure } from './shared/server.NeumLVdS.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures, x as unlazyRouter, v as validateORPCError } from './shared/server.NeumLVdS.mjs';
|
5
|
+
import { toORPCError } from '@orpc/client';
|
5
6
|
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
6
|
-
|
7
|
+
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
8
|
+
export { EventPublisher, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
|
7
9
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
8
10
|
|
9
11
|
const DEFAULT_CONFIG = {
|
10
12
|
initialInputValidationIndex: 0,
|
11
|
-
initialOutputValidationIndex: 0
|
13
|
+
initialOutputValidationIndex: 0,
|
14
|
+
dedupeLeadingMiddlewares: true
|
12
15
|
};
|
13
16
|
function fallbackConfig(key, value) {
|
14
17
|
if (value === void 0) {
|
@@ -18,7 +21,7 @@ function fallbackConfig(key, value) {
|
|
18
21
|
}
|
19
22
|
|
20
23
|
function decorateMiddleware(middleware) {
|
21
|
-
const decorated = middleware;
|
24
|
+
const decorated = (...args) => middleware(...args);
|
22
25
|
decorated.mapInput = (mapInput) => {
|
23
26
|
const mapped = decorateMiddleware(
|
24
27
|
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
@@ -43,19 +46,53 @@ function decorateMiddleware(middleware) {
|
|
43
46
|
return decorated;
|
44
47
|
}
|
45
48
|
|
49
|
+
function createActionableClient(client) {
|
50
|
+
const action = async (input) => {
|
51
|
+
try {
|
52
|
+
return [null, await client(input)];
|
53
|
+
} catch (error) {
|
54
|
+
if (error instanceof Error && "digest" in error && typeof error.digest === "string" && error.digest.startsWith("NEXT_")) {
|
55
|
+
throw error;
|
56
|
+
}
|
57
|
+
return [toORPCError(error).toJSON(), void 0];
|
58
|
+
}
|
59
|
+
};
|
60
|
+
return action;
|
61
|
+
}
|
62
|
+
|
46
63
|
class DecoratedProcedure extends Procedure {
|
64
|
+
/**
|
65
|
+
* Adds type-safe custom errors.
|
66
|
+
* The provided errors are spared-merged with any existing errors.
|
67
|
+
*
|
68
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
69
|
+
*/
|
47
70
|
errors(errors) {
|
48
71
|
return new DecoratedProcedure({
|
49
72
|
...this["~orpc"],
|
50
73
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
51
74
|
});
|
52
75
|
}
|
76
|
+
/**
|
77
|
+
* Sets or updates the metadata.
|
78
|
+
* The provided metadata is spared-merged with any existing metadata.
|
79
|
+
*
|
80
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
81
|
+
*/
|
53
82
|
meta(meta) {
|
54
83
|
return new DecoratedProcedure({
|
55
84
|
...this["~orpc"],
|
56
85
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
57
86
|
});
|
58
87
|
}
|
88
|
+
/**
|
89
|
+
* Sets or updates the route definition.
|
90
|
+
* The provided route is spared-merged with any existing route.
|
91
|
+
* This option is typically relevant when integrating with OpenAPI.
|
92
|
+
*
|
93
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
94
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
95
|
+
*/
|
59
96
|
route(route) {
|
60
97
|
return new DecoratedProcedure({
|
61
98
|
...this["~orpc"],
|
@@ -71,28 +108,51 @@ class DecoratedProcedure extends Procedure {
|
|
71
108
|
}
|
72
109
|
/**
|
73
110
|
* Make this procedure callable (works like a function while still being a procedure).
|
111
|
+
*
|
112
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
74
113
|
*/
|
75
114
|
callable(...rest) {
|
76
|
-
|
77
|
-
|
78
|
-
|
115
|
+
const client = createProcedureClient(this, ...rest);
|
116
|
+
return new Proxy(client, {
|
117
|
+
get: (target, key) => {
|
118
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
119
|
+
},
|
120
|
+
has: (target, key) => {
|
121
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
122
|
+
}
|
79
123
|
});
|
80
124
|
}
|
81
125
|
/**
|
82
|
-
* Make this procedure compatible with server action
|
126
|
+
* Make this procedure compatible with server action.
|
127
|
+
*
|
128
|
+
* @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
|
83
129
|
*/
|
84
130
|
actionable(...rest) {
|
85
|
-
|
131
|
+
const action = createActionableClient(createProcedureClient(this, ...rest));
|
132
|
+
return new Proxy(action, {
|
133
|
+
get: (target, key) => {
|
134
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
135
|
+
},
|
136
|
+
has: (target, key) => {
|
137
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
138
|
+
}
|
139
|
+
});
|
86
140
|
}
|
87
141
|
}
|
88
142
|
|
89
143
|
class Builder {
|
144
|
+
/**
|
145
|
+
* This property holds the defined options.
|
146
|
+
*/
|
90
147
|
"~orpc";
|
91
148
|
constructor(def) {
|
92
149
|
this["~orpc"] = def;
|
93
150
|
}
|
94
151
|
/**
|
95
|
-
*
|
152
|
+
* Sets or overrides the config.
|
153
|
+
*
|
154
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
155
|
+
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
96
156
|
*/
|
97
157
|
$config(config) {
|
98
158
|
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
@@ -100,12 +160,15 @@ class Builder {
|
|
100
160
|
return new Builder({
|
101
161
|
...this["~orpc"],
|
102
162
|
config,
|
163
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
|
103
164
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
104
165
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
105
166
|
});
|
106
167
|
}
|
107
168
|
/**
|
108
|
-
*
|
169
|
+
* Set or override the initial context.
|
170
|
+
*
|
171
|
+
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
109
172
|
*/
|
110
173
|
$context() {
|
111
174
|
return new Builder({
|
@@ -116,7 +179,9 @@ class Builder {
|
|
116
179
|
});
|
117
180
|
}
|
118
181
|
/**
|
119
|
-
*
|
182
|
+
* Sets or overrides the initial meta.
|
183
|
+
*
|
184
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
120
185
|
*/
|
121
186
|
$meta(initialMeta) {
|
122
187
|
return new Builder({
|
@@ -125,7 +190,11 @@ class Builder {
|
|
125
190
|
});
|
126
191
|
}
|
127
192
|
/**
|
128
|
-
*
|
193
|
+
* Sets or overrides the initial route.
|
194
|
+
* This option is typically relevant when integrating with OpenAPI.
|
195
|
+
*
|
196
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
197
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
129
198
|
*/
|
130
199
|
$route(initialRoute) {
|
131
200
|
return new Builder({
|
@@ -133,9 +202,31 @@ class Builder {
|
|
133
202
|
route: initialRoute
|
134
203
|
});
|
135
204
|
}
|
205
|
+
/**
|
206
|
+
* Sets or overrides the initial input schema.
|
207
|
+
*
|
208
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
209
|
+
*/
|
210
|
+
$input(initialInputSchema) {
|
211
|
+
return new Builder({
|
212
|
+
...this["~orpc"],
|
213
|
+
inputSchema: initialInputSchema
|
214
|
+
});
|
215
|
+
}
|
216
|
+
/**
|
217
|
+
* Creates a middleware.
|
218
|
+
*
|
219
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
220
|
+
*/
|
136
221
|
middleware(middleware) {
|
137
222
|
return decorateMiddleware(middleware);
|
138
223
|
}
|
224
|
+
/**
|
225
|
+
* Adds type-safe custom errors.
|
226
|
+
* The provided errors are spared-merged with any existing errors.
|
227
|
+
*
|
228
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
229
|
+
*/
|
139
230
|
errors(errors) {
|
140
231
|
return new Builder({
|
141
232
|
...this["~orpc"],
|
@@ -149,18 +240,37 @@ class Builder {
|
|
149
240
|
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
150
241
|
});
|
151
242
|
}
|
243
|
+
/**
|
244
|
+
* Sets or updates the metadata.
|
245
|
+
* The provided metadata is spared-merged with any existing metadata.
|
246
|
+
*
|
247
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
248
|
+
*/
|
152
249
|
meta(meta) {
|
153
250
|
return new Builder({
|
154
251
|
...this["~orpc"],
|
155
252
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
156
253
|
});
|
157
254
|
}
|
255
|
+
/**
|
256
|
+
* Sets or updates the route definition.
|
257
|
+
* The provided route is spared-merged with any existing route.
|
258
|
+
* This option is typically relevant when integrating with OpenAPI.
|
259
|
+
*
|
260
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
261
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
262
|
+
*/
|
158
263
|
route(route) {
|
159
264
|
return new Builder({
|
160
265
|
...this["~orpc"],
|
161
266
|
route: mergeRoute(this["~orpc"].route, route)
|
162
267
|
});
|
163
268
|
}
|
269
|
+
/**
|
270
|
+
* Defines the input validation schema.
|
271
|
+
*
|
272
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
273
|
+
*/
|
164
274
|
input(schema) {
|
165
275
|
return new Builder({
|
166
276
|
...this["~orpc"],
|
@@ -168,6 +278,11 @@ class Builder {
|
|
168
278
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
169
279
|
});
|
170
280
|
}
|
281
|
+
/**
|
282
|
+
* Defines the output validation schema.
|
283
|
+
*
|
284
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
285
|
+
*/
|
171
286
|
output(schema) {
|
172
287
|
return new Builder({
|
173
288
|
...this["~orpc"],
|
@@ -175,27 +290,57 @@ class Builder {
|
|
175
290
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
176
291
|
});
|
177
292
|
}
|
293
|
+
/**
|
294
|
+
* Defines the handler of the procedure.
|
295
|
+
*
|
296
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
297
|
+
*/
|
178
298
|
handler(handler) {
|
179
299
|
return new DecoratedProcedure({
|
180
300
|
...this["~orpc"],
|
181
301
|
handler
|
182
302
|
});
|
183
303
|
}
|
304
|
+
/**
|
305
|
+
* Prefixes all procedures in the router.
|
306
|
+
* The provided prefix is post-appended to any existing router prefix.
|
307
|
+
*
|
308
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
309
|
+
*
|
310
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
311
|
+
*/
|
184
312
|
prefix(prefix) {
|
185
313
|
return new Builder({
|
186
314
|
...this["~orpc"],
|
187
315
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
188
316
|
});
|
189
317
|
}
|
318
|
+
/**
|
319
|
+
* Adds tags to all procedures in the router.
|
320
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
321
|
+
*
|
322
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
323
|
+
*/
|
190
324
|
tag(...tags) {
|
191
325
|
return new Builder({
|
192
326
|
...this["~orpc"],
|
193
327
|
tags: mergeTags(this["~orpc"].tags, tags)
|
194
328
|
});
|
195
329
|
}
|
330
|
+
/**
|
331
|
+
* Applies all of the previously defined options to the specified router.
|
332
|
+
*
|
333
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
334
|
+
*/
|
196
335
|
router(router) {
|
197
336
|
return enhanceRouter(router, this["~orpc"]);
|
198
337
|
}
|
338
|
+
/**
|
339
|
+
* Create a lazy router
|
340
|
+
* And applies all of the previously defined options to the specified router.
|
341
|
+
*
|
342
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
343
|
+
*/
|
199
344
|
lazy(loader) {
|
200
345
|
return enhanceRouter(lazy(loader), this["~orpc"]);
|
201
346
|
}
|
@@ -207,13 +352,10 @@ const os = new Builder({
|
|
207
352
|
errorMap: {},
|
208
353
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
209
354
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
210
|
-
middlewares: []
|
355
|
+
middlewares: [],
|
356
|
+
dedupeLeadingMiddlewares: true
|
211
357
|
});
|
212
358
|
|
213
|
-
function mergeContext(context, other) {
|
214
|
-
return { ...context, ...other };
|
215
|
-
}
|
216
|
-
|
217
359
|
function implementerInternal(contract, config, middlewares) {
|
218
360
|
if (isContractProcedure(contract)) {
|
219
361
|
const impl2 = new Builder({
|
@@ -221,7 +363,8 @@ function implementerInternal(contract, config, middlewares) {
|
|
221
363
|
config,
|
222
364
|
middlewares,
|
223
365
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
224
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
366
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
|
367
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
225
368
|
});
|
226
369
|
return impl2;
|
227
370
|
}
|
@@ -247,7 +390,8 @@ function implementerInternal(contract, config, middlewares) {
|
|
247
390
|
middlewares,
|
248
391
|
errorMap: {},
|
249
392
|
prefix: void 0,
|
250
|
-
tags: void 0
|
393
|
+
tags: void 0,
|
394
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
251
395
|
});
|
252
396
|
return setHiddenRouterContract(adapted, contract);
|
253
397
|
};
|
@@ -257,7 +401,8 @@ function implementerInternal(contract, config, middlewares) {
|
|
257
401
|
middlewares,
|
258
402
|
errorMap: {},
|
259
403
|
prefix: void 0,
|
260
|
-
tags: void 0
|
404
|
+
tags: void 0,
|
405
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
261
406
|
});
|
262
407
|
return setHiddenRouterContract(adapted, contract);
|
263
408
|
};
|
@@ -290,23 +435,34 @@ function implement(contract, config = {}) {
|
|
290
435
|
method = (config2) => implement(contract, config2);
|
291
436
|
}
|
292
437
|
const next = Reflect.get(target, key);
|
293
|
-
if (!next || typeof next !== "function" && typeof next !== "object") {
|
294
|
-
return method
|
295
|
-
}
|
296
|
-
if (method) {
|
297
|
-
return new Proxy(method, {
|
298
|
-
get(_, key2) {
|
299
|
-
return Reflect.get(next, key2);
|
300
|
-
}
|
301
|
-
});
|
438
|
+
if (!method || !next || typeof next !== "function" && typeof next !== "object") {
|
439
|
+
return method || next;
|
302
440
|
}
|
303
|
-
return
|
441
|
+
return new Proxy(method, {
|
442
|
+
get(_, key2) {
|
443
|
+
return Reflect.get(next, key2);
|
444
|
+
}
|
445
|
+
});
|
304
446
|
}
|
305
447
|
});
|
306
448
|
return impl;
|
307
449
|
}
|
308
450
|
|
309
|
-
function
|
451
|
+
function inferRPCMethodFromRouter(router) {
|
452
|
+
return async (_, path) => {
|
453
|
+
const { default: procedure } = await unlazy(getRouter(router, path));
|
454
|
+
if (!isProcedure(procedure)) {
|
455
|
+
throw new Error(
|
456
|
+
`[inferRPCMethodFromRouter] No valid procedure found at path "${path.join(".")}". This may happen when the router is not properly configured.`
|
457
|
+
);
|
458
|
+
}
|
459
|
+
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
460
|
+
return method === "HEAD" ? "GET" : method;
|
461
|
+
};
|
462
|
+
}
|
463
|
+
|
464
|
+
function createRouterClient(router, ...rest) {
|
465
|
+
const options = resolveMaybeOptionalOptions(rest);
|
310
466
|
if (isProcedure(router)) {
|
311
467
|
const caller = createProcedureClient(router, options);
|
312
468
|
return caller;
|
@@ -322,12 +478,12 @@ function createRouterClient(router, ...[options]) {
|
|
322
478
|
return Reflect.get(target, key);
|
323
479
|
}
|
324
480
|
return createRouterClient(next, {
|
325
|
-
...
|
326
|
-
path: [...
|
481
|
+
...rest[0],
|
482
|
+
path: [...rest[0]?.path ?? [], key]
|
327
483
|
});
|
328
484
|
}
|
329
485
|
});
|
330
486
|
return recursive;
|
331
487
|
}
|
332
488
|
|
333
|
-
export { Builder, DecoratedProcedure, Procedure, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy,
|
489
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isLazy, isProcedure, lazy, os, setHiddenRouterContract, unlazy };
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,31 +1,169 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import '
|
6
|
-
import '@orpc/
|
7
|
-
import '@orpc/client';
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
2
|
+
import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
|
3
|
+
import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
|
4
|
+
import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.DHgXKx3q.mjs';
|
5
|
+
import { C as Context, d as ProcedureClientInterceptorOptions } from '../shared/server.wMv480px.mjs';
|
6
|
+
import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
|
7
|
+
import { ORPCError } from '@orpc/client';
|
8
8
|
|
9
|
-
interface
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
interface BatchHandlerOptions<T extends Context> {
|
10
|
+
/**
|
11
|
+
* The max size of the batch allowed.
|
12
|
+
*
|
13
|
+
* @default 10
|
14
|
+
*/
|
15
|
+
maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
|
16
|
+
/**
|
17
|
+
* Map the request before processing it.
|
18
|
+
*
|
19
|
+
* @default merged back batch request headers into the request
|
20
|
+
*/
|
21
|
+
mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
|
22
|
+
/**
|
23
|
+
* Success batch response status code.
|
24
|
+
*
|
25
|
+
* @default 207
|
26
|
+
*/
|
27
|
+
successStatus?: Value<Promisable<number>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
|
28
|
+
/**
|
29
|
+
* success batch response headers.
|
30
|
+
*
|
31
|
+
* @default {}
|
32
|
+
*/
|
33
|
+
headers?: Value<Promisable<StandardHeaders>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
|
34
|
+
}
|
35
|
+
/**
|
36
|
+
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
37
|
+
* reducing the overhead of sending each one separately.
|
38
|
+
*
|
39
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
40
|
+
*/
|
41
|
+
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
42
|
+
private readonly maxSize;
|
43
|
+
private readonly mapRequestItem;
|
44
|
+
private readonly successStatus;
|
45
|
+
private readonly headers;
|
46
|
+
order: number;
|
47
|
+
constructor(options?: BatchHandlerOptions<T>);
|
48
|
+
init(options: StandardHandlerOptions<T>): void;
|
49
|
+
}
|
50
|
+
|
51
|
+
interface CORSOptions<T extends Context> {
|
52
|
+
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
53
|
+
timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
54
|
+
allowMethods?: readonly string[];
|
55
|
+
allowHeaders?: readonly string[];
|
14
56
|
maxAge?: number;
|
15
57
|
credentials?: boolean;
|
16
|
-
exposeHeaders?: string[];
|
58
|
+
exposeHeaders?: readonly string[];
|
17
59
|
}
|
18
|
-
|
60
|
+
/**
|
61
|
+
* CORSPlugin is a plugin for oRPC that allows you to configure CORS for your API.
|
62
|
+
*
|
63
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/cors CORS Plugin Docs}
|
64
|
+
*/
|
65
|
+
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
19
66
|
private readonly options;
|
20
|
-
|
21
|
-
|
67
|
+
order: number;
|
68
|
+
constructor(options?: CORSOptions<T>);
|
69
|
+
init(options: StandardHandlerOptions<T>): void;
|
70
|
+
}
|
71
|
+
|
72
|
+
interface RequestHeadersPluginContext {
|
73
|
+
reqHeaders?: Headers;
|
74
|
+
}
|
75
|
+
/**
|
76
|
+
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
77
|
+
* allowing access to request headers in oRPC.
|
78
|
+
*
|
79
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
|
80
|
+
*/
|
81
|
+
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
82
|
+
init(options: StandardHandlerOptions<T>): void;
|
22
83
|
}
|
23
84
|
|
24
85
|
interface ResponseHeadersPluginContext {
|
25
86
|
resHeaders?: Headers;
|
26
87
|
}
|
27
|
-
|
28
|
-
|
88
|
+
/**
|
89
|
+
* The Response Headers Plugin allows you to set response headers in oRPC.
|
90
|
+
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
91
|
+
*
|
92
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
|
93
|
+
*/
|
94
|
+
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
95
|
+
init(options: StandardHandlerOptions<T>): void;
|
96
|
+
}
|
97
|
+
|
98
|
+
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
99
|
+
/**
|
100
|
+
* The name of the header to check.
|
101
|
+
*
|
102
|
+
* @default 'x-csrf-token'
|
103
|
+
*/
|
104
|
+
headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
105
|
+
/**
|
106
|
+
* The value of the header to check.
|
107
|
+
*
|
108
|
+
* @default 'orpc'
|
109
|
+
*
|
110
|
+
*/
|
111
|
+
headerValue?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
112
|
+
/**
|
113
|
+
* Exclude a procedure from the plugin.
|
114
|
+
*
|
115
|
+
* @default false
|
116
|
+
*
|
117
|
+
*/
|
118
|
+
exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
|
119
|
+
/**
|
120
|
+
* The error thrown when the CSRF token is invalid.
|
121
|
+
*
|
122
|
+
* @default new ORPCError('CSRF_TOKEN_MISMATCH', {
|
123
|
+
* status: 403,
|
124
|
+
* message: 'Invalid CSRF token',
|
125
|
+
* })
|
126
|
+
*/
|
127
|
+
error?: InstanceType<typeof ORPCError>;
|
128
|
+
}
|
129
|
+
/**
|
130
|
+
* This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
|
131
|
+
* It helps ensure that requests to your procedures originate from JavaScript code,
|
132
|
+
* not from other sources like standard HTML forms or direct browser navigation.
|
133
|
+
*
|
134
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
|
135
|
+
*/
|
136
|
+
declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
137
|
+
private readonly headerName;
|
138
|
+
private readonly headerValue;
|
139
|
+
private readonly exclude;
|
140
|
+
private readonly error;
|
141
|
+
constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
|
142
|
+
order: number;
|
143
|
+
init(options: StandardHandlerOptions<T>): void;
|
144
|
+
}
|
145
|
+
|
146
|
+
interface StrictGetMethodPluginOptions {
|
147
|
+
/**
|
148
|
+
* The error thrown when a GET request is made to a procedure that doesn't allow GET.
|
149
|
+
*
|
150
|
+
* @default new ORPCError('METHOD_NOT_SUPPORTED')
|
151
|
+
*/
|
152
|
+
error?: InstanceType<typeof ORPCError$1>;
|
153
|
+
}
|
154
|
+
/**
|
155
|
+
* This plugin enhances security by ensuring only procedures explicitly marked to accept GET requests
|
156
|
+
* can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
|
157
|
+
* Cross-Site Request Forgery (CSRF) attacks.
|
158
|
+
*
|
159
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
|
160
|
+
*/
|
161
|
+
declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
162
|
+
private readonly error;
|
163
|
+
order: number;
|
164
|
+
constructor(options?: StrictGetMethodPluginOptions);
|
165
|
+
init(options: StandardHandlerOptions<T>): void;
|
29
166
|
}
|
30
167
|
|
31
|
-
export {
|
168
|
+
export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
|
169
|
+
export type { BatchHandlerOptions, CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
|