@temporary-name/server 1.9.3-alpha.37dfe6603933b8e445661fe453c4fbdb30ccb524 → 1.9.3-alpha.50b729ba628b987e14f5bd1004e5a04590fd4b4e
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/dist/adapters/aws-lambda/index.d.mts +3 -3
- package/dist/adapters/aws-lambda/index.d.ts +3 -3
- package/dist/adapters/aws-lambda/index.mjs +3 -5
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +3 -5
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +3 -5
- package/dist/adapters/standard/index.d.mts +14 -30
- package/dist/adapters/standard/index.d.ts +14 -30
- package/dist/adapters/standard/index.mjs +3 -5
- package/dist/index.d.mts +44 -266
- package/dist/index.d.ts +44 -266
- package/dist/index.mjs +108 -151
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.DLsti1Pv.mjs → server.BVxcyR6X.mjs} +76 -82
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.Bk5r0-2R.d.ts} +1 -2
- package/dist/shared/{server.BeuTpcmO.d.mts → server.Bs6ka_UE.d.mts} +2 -2
- package/dist/shared/{server.BKSOrA6h.d.mts → server.CZNLCQBm.d.mts} +2 -2
- package/dist/shared/{server.BKSOrA6h.d.ts → server.CZNLCQBm.d.ts} +2 -2
- package/dist/shared/{server.C1fnTLq0.d.mts → server.CbLTWfgn.d.mts} +1 -2
- package/dist/shared/{server.SLLuK6_v.d.ts → server.D2UFMrxf.d.ts} +2 -2
- package/dist/shared/{server.BKh8I1Ny.mjs → server.DcfsPloY.mjs} +17 -54
- package/package.json +10 -9
package/dist/index.mjs
CHANGED
|
@@ -1,49 +1,11 @@
|
|
|
1
|
-
import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, getContractRouter } from '@temporary-name/contract';
|
|
2
|
-
export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
|
|
3
1
|
import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
4
2
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
5
|
-
import {
|
|
6
|
-
export {
|
|
3
|
+
import { isContractProcedure, mergePrefix, mergeErrorMap, enhanceRoute, mergeTags, ContractProcedure, mergeMeta, mergeRoute, prefixRoute, getContractRouter } from '@temporary-name/contract';
|
|
4
|
+
export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
5
|
+
import { SchemaClass, gatingContext } from '@temporary-name/zod';
|
|
6
|
+
import { c as createProcedureClient, i as isLazy, g as getLazyMeta, l as lazy, u as unlazy } from './shared/server.DcfsPloY.mjs';
|
|
7
|
+
export { L as LAZY_SYMBOL, a as createORPCErrorConstructorMap, m as mergeCurrentContext, b as middlewareOutputFn } from './shared/server.DcfsPloY.mjs';
|
|
7
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
8
|
-
import 'node:async_hooks';
|
|
9
|
-
import 'zod';
|
|
10
|
-
import 'zod/v4/core';
|
|
11
|
-
|
|
12
|
-
function decorateMiddleware(middleware) {
|
|
13
|
-
const decorated = ((...args) => middleware(...args));
|
|
14
|
-
decorated.mapInput = (mapInput) => {
|
|
15
|
-
const mapped = decorateMiddleware(
|
|
16
|
-
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
|
17
|
-
);
|
|
18
|
-
return mapped;
|
|
19
|
-
};
|
|
20
|
-
decorated.concat = (concatMiddleware, mapInput) => {
|
|
21
|
-
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
|
22
|
-
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
|
23
|
-
const merged = middleware(
|
|
24
|
-
{
|
|
25
|
-
...options,
|
|
26
|
-
next: (...[nextOptions1]) => mapped(
|
|
27
|
-
{
|
|
28
|
-
...options,
|
|
29
|
-
context: { ...options.context, ...nextOptions1?.context },
|
|
30
|
-
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
|
31
|
-
},
|
|
32
|
-
input,
|
|
33
|
-
output,
|
|
34
|
-
...rest
|
|
35
|
-
)
|
|
36
|
-
},
|
|
37
|
-
input,
|
|
38
|
-
output,
|
|
39
|
-
...rest
|
|
40
|
-
);
|
|
41
|
-
return merged;
|
|
42
|
-
});
|
|
43
|
-
return concatted;
|
|
44
|
-
};
|
|
45
|
-
return decorated;
|
|
46
|
-
}
|
|
47
9
|
|
|
48
10
|
function isStartWithMiddlewares(middlewares, compare) {
|
|
49
11
|
if (compare.length > middlewares.length) {
|
|
@@ -82,55 +44,10 @@ function isProcedure(item) {
|
|
|
82
44
|
if (item instanceof Procedure) {
|
|
83
45
|
return true;
|
|
84
46
|
}
|
|
85
|
-
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "
|
|
47
|
+
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "handler" in item["~orpc"];
|
|
86
48
|
}
|
|
87
49
|
|
|
88
50
|
class DecoratedProcedure extends Procedure {
|
|
89
|
-
/**
|
|
90
|
-
* Adds type-safe custom errors.
|
|
91
|
-
* The provided errors are spared-merged with any existing errors.
|
|
92
|
-
*
|
|
93
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
94
|
-
*/
|
|
95
|
-
errors(errors) {
|
|
96
|
-
return new DecoratedProcedure({
|
|
97
|
-
...this["~orpc"],
|
|
98
|
-
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Sets or updates the metadata.
|
|
103
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
104
|
-
*
|
|
105
|
-
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
106
|
-
*/
|
|
107
|
-
meta(meta) {
|
|
108
|
-
return new DecoratedProcedure({
|
|
109
|
-
...this["~orpc"],
|
|
110
|
-
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Sets or updates the route definition.
|
|
115
|
-
* The provided route is spared-merged with any existing route.
|
|
116
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
117
|
-
*
|
|
118
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
119
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
120
|
-
*/
|
|
121
|
-
route(route) {
|
|
122
|
-
return new DecoratedProcedure({
|
|
123
|
-
...this["~orpc"],
|
|
124
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
use(middleware, mapInput) {
|
|
128
|
-
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
|
129
|
-
return new DecoratedProcedure({
|
|
130
|
-
...this["~orpc"],
|
|
131
|
-
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
51
|
/**
|
|
135
52
|
* Make this procedure callable (works like a function while still being a procedure).
|
|
136
53
|
*
|
|
@@ -295,87 +212,49 @@ async function unlazyRouter(router) {
|
|
|
295
212
|
return unlazied;
|
|
296
213
|
}
|
|
297
214
|
|
|
298
|
-
class
|
|
299
|
-
|
|
300
|
-
* This property holds the defined options.
|
|
301
|
-
*/
|
|
302
|
-
"~orpc";
|
|
215
|
+
class ProcedureBuilder extends ContractProcedure {
|
|
216
|
+
z;
|
|
303
217
|
constructor(def) {
|
|
304
|
-
|
|
218
|
+
super(def);
|
|
219
|
+
this.z = new SchemaClass();
|
|
305
220
|
}
|
|
306
221
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
310
|
-
*/
|
|
311
|
-
$context() {
|
|
312
|
-
return this;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Creates a middleware.
|
|
316
|
-
*
|
|
317
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
318
|
-
*/
|
|
319
|
-
middleware(middleware) {
|
|
320
|
-
return decorateMiddleware(middleware);
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Adds type-safe custom errors.
|
|
324
|
-
* The provided errors are spared-merged with any existing errors.
|
|
222
|
+
* Adds type-safe custom errors to the contract.
|
|
223
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
325
224
|
*
|
|
326
225
|
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
327
226
|
*/
|
|
328
227
|
errors(errors) {
|
|
329
|
-
return new
|
|
228
|
+
return new ProcedureBuilder({
|
|
330
229
|
...this["~orpc"],
|
|
331
230
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
332
231
|
});
|
|
333
232
|
}
|
|
334
233
|
/**
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
338
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
339
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
340
|
-
*/
|
|
341
|
-
use(middleware) {
|
|
342
|
-
return new Builder({
|
|
343
|
-
...this["~orpc"],
|
|
344
|
-
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
useGating(gates, isGateEnabled) {
|
|
348
|
-
return this.use(({ next, context }) => {
|
|
349
|
-
return gatingContext.run(
|
|
350
|
-
(gate) => isGateEnabled(gate, context),
|
|
351
|
-
() => next({ context: { isGateEnabled } })
|
|
352
|
-
);
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Sets or updates the metadata.
|
|
357
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
234
|
+
* Sets or updates the metadata for the contract.
|
|
235
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
358
236
|
*
|
|
359
237
|
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
360
238
|
*/
|
|
361
239
|
meta(meta) {
|
|
362
|
-
return new
|
|
240
|
+
return new ProcedureBuilder({
|
|
363
241
|
...this["~orpc"],
|
|
364
242
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
365
243
|
});
|
|
366
244
|
}
|
|
367
245
|
/**
|
|
368
|
-
* Sets or updates the route definition.
|
|
369
|
-
* The provided route is spared-merged with any existing route.
|
|
246
|
+
* Sets or updates the route definition for the contract.
|
|
247
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
370
248
|
* This option is typically relevant when integrating with OpenAPI.
|
|
371
249
|
*
|
|
372
250
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
373
251
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
374
252
|
*/
|
|
375
253
|
route(route) {
|
|
376
|
-
|
|
254
|
+
const { prefix } = this["~orpc"];
|
|
255
|
+
return new ProcedureBuilder({
|
|
377
256
|
...this["~orpc"],
|
|
378
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
257
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
379
258
|
});
|
|
380
259
|
}
|
|
381
260
|
/**
|
|
@@ -384,7 +263,7 @@ class Builder {
|
|
|
384
263
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
385
264
|
*/
|
|
386
265
|
input(schema) {
|
|
387
|
-
return new
|
|
266
|
+
return new ProcedureBuilder({
|
|
388
267
|
...this["~orpc"],
|
|
389
268
|
inputSchema: schema,
|
|
390
269
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
@@ -396,12 +275,33 @@ class Builder {
|
|
|
396
275
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
397
276
|
*/
|
|
398
277
|
output(schema) {
|
|
399
|
-
return new
|
|
278
|
+
return new ProcedureBuilder({
|
|
400
279
|
...this["~orpc"],
|
|
401
280
|
outputSchema: schema,
|
|
402
281
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
403
282
|
});
|
|
404
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
286
|
+
*
|
|
287
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
288
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
289
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
290
|
+
*/
|
|
291
|
+
use(middleware) {
|
|
292
|
+
return new this.constructor({
|
|
293
|
+
...this["~orpc"],
|
|
294
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
useGating(gates, isGateEnabled) {
|
|
298
|
+
return this.use(({ next, context }) => {
|
|
299
|
+
return gatingContext.run(
|
|
300
|
+
(gate) => isGateEnabled(gate, context),
|
|
301
|
+
() => next({ context: { isGateEnabled } })
|
|
302
|
+
);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
405
305
|
/**
|
|
406
306
|
* Defines the handler of the procedure.
|
|
407
307
|
*
|
|
@@ -413,6 +313,8 @@ class Builder {
|
|
|
413
313
|
handler
|
|
414
314
|
});
|
|
415
315
|
}
|
|
316
|
+
}
|
|
317
|
+
class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
416
318
|
/**
|
|
417
319
|
* Prefixes all procedures in the router.
|
|
418
320
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -422,7 +324,7 @@ class Builder {
|
|
|
422
324
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
423
325
|
*/
|
|
424
326
|
prefix(prefix) {
|
|
425
|
-
return new
|
|
327
|
+
return new this.constructor({
|
|
426
328
|
...this["~orpc"],
|
|
427
329
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
428
330
|
});
|
|
@@ -434,7 +336,7 @@ class Builder {
|
|
|
434
336
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
435
337
|
*/
|
|
436
338
|
tag(...tags) {
|
|
437
|
-
return new
|
|
339
|
+
return new this.constructor({
|
|
438
340
|
...this["~orpc"],
|
|
439
341
|
tags: mergeTags(this["~orpc"].tags, tags)
|
|
440
342
|
});
|
|
@@ -454,18 +356,74 @@ class Builder {
|
|
|
454
356
|
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
455
357
|
*/
|
|
456
358
|
lazyRoute(loader) {
|
|
457
|
-
|
|
359
|
+
const lazied = lazy(loader);
|
|
360
|
+
return enhanceRouter(lazied, this["~orpc"]);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function decorateMiddleware(middleware) {
|
|
365
|
+
const decorated = ((...args) => middleware(...args));
|
|
366
|
+
decorated.mapInput = (mapInput) => {
|
|
367
|
+
const mapped = decorateMiddleware(
|
|
368
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
|
369
|
+
);
|
|
370
|
+
return mapped;
|
|
371
|
+
};
|
|
372
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
|
373
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
|
374
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
|
375
|
+
const merged = middleware(
|
|
376
|
+
{
|
|
377
|
+
...options,
|
|
378
|
+
next: (...[nextOptions1]) => mapped(
|
|
379
|
+
{
|
|
380
|
+
...options,
|
|
381
|
+
context: { ...options.context, ...nextOptions1?.context },
|
|
382
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
|
383
|
+
},
|
|
384
|
+
input,
|
|
385
|
+
output,
|
|
386
|
+
...rest
|
|
387
|
+
)
|
|
388
|
+
},
|
|
389
|
+
input,
|
|
390
|
+
output,
|
|
391
|
+
...rest
|
|
392
|
+
);
|
|
393
|
+
return merged;
|
|
394
|
+
});
|
|
395
|
+
return concatted;
|
|
396
|
+
};
|
|
397
|
+
return decorated;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
class Builder extends BuilderWithMiddlewares {
|
|
401
|
+
/**
|
|
402
|
+
* Set or override the initial context.
|
|
403
|
+
*
|
|
404
|
+
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
405
|
+
*/
|
|
406
|
+
$context() {
|
|
407
|
+
return this;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Creates a middleware.
|
|
411
|
+
*
|
|
412
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
413
|
+
*/
|
|
414
|
+
middleware(middleware) {
|
|
415
|
+
return decorateMiddleware(middleware);
|
|
458
416
|
}
|
|
459
417
|
}
|
|
460
418
|
function createApiBuilder(opts = {}) {
|
|
461
|
-
|
|
419
|
+
return new Builder({
|
|
462
420
|
route: {},
|
|
463
421
|
meta: opts.meta ?? {},
|
|
464
422
|
errorMap: {},
|
|
465
423
|
inputValidationIndex: 0,
|
|
466
424
|
outputValidationIndex: 0,
|
|
467
425
|
middlewares: [
|
|
468
|
-
onError((error,
|
|
426
|
+
onError((error, _options) => {
|
|
469
427
|
console.dir(error, { depth: null });
|
|
470
428
|
})
|
|
471
429
|
],
|
|
@@ -473,7 +431,6 @@ function createApiBuilder(opts = {}) {
|
|
|
473
431
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
474
432
|
dedupeLeadingMiddlewares: true
|
|
475
433
|
});
|
|
476
|
-
return base;
|
|
477
434
|
}
|
|
478
435
|
const os = createApiBuilder();
|
|
479
436
|
|
|
@@ -614,4 +571,4 @@ function createRouterClient(router, ...rest) {
|
|
|
614
571
|
return recursive;
|
|
615
572
|
}
|
|
616
573
|
|
|
617
|
-
export { Builder, DecoratedProcedure, Procedure, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
|
|
574
|
+
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
2
|
import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
|
|
3
3
|
import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.
|
|
4
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CbLTWfgn.mjs';
|
|
5
|
+
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.CZNLCQBm.mjs';
|
|
6
6
|
import { Meta } from '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface BatchHandlerOptions<T extends Context> {
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
2
|
import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
|
|
3
3
|
import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.
|
|
4
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.Bk5r0-2R.js';
|
|
5
|
+
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.CZNLCQBm.js';
|
|
6
6
|
import { Meta } from '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface BatchHandlerOptions<T extends Context> {
|
|
@@ -1,67 +1,64 @@
|
|
|
1
1
|
import { isObject, stringifyJSON, isORPCErrorStatus, tryDecodeURIComponent, value, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
|
|
2
2
|
import { flattenHeader } from '@temporary-name/standard-server';
|
|
3
|
-
import { c as createProcedureClient } from './server.
|
|
3
|
+
import { c as createProcedureClient } from './server.DcfsPloY.mjs';
|
|
4
4
|
import { fallbackContractConfig } from '@temporary-name/contract';
|
|
5
5
|
import { d as deserialize, s as serialize, a as standardizeHTTPPath } from './server.BEHw7Eyx.mjs';
|
|
6
6
|
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@temporary-name/server';
|
|
7
7
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
const data = request.method === "GET" ? deserialize(request.url.searchParams) : deserialize(await request.body());
|
|
19
|
-
if (data === void 0) {
|
|
20
|
-
return params;
|
|
21
|
-
}
|
|
22
|
-
if (isObject(data)) {
|
|
23
|
-
return {
|
|
24
|
-
...params,
|
|
25
|
-
...data
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
return data;
|
|
9
|
+
async function decode(request, params, procedure) {
|
|
10
|
+
const inputStructure = fallbackContractConfig(
|
|
11
|
+
"defaultInputStructure",
|
|
12
|
+
procedure["~orpc"].route.inputStructure
|
|
13
|
+
);
|
|
14
|
+
if (inputStructure === "compact") {
|
|
15
|
+
const data = request.method === "GET" ? deserialize(request.url.searchParams) : deserialize(await request.body());
|
|
16
|
+
if (data === void 0) {
|
|
17
|
+
return params;
|
|
29
18
|
}
|
|
30
|
-
|
|
31
|
-
return deserialize(request.url.searchParams);
|
|
32
|
-
};
|
|
33
|
-
return {
|
|
34
|
-
params,
|
|
35
|
-
get query() {
|
|
36
|
-
const value = deserializeSearchParams();
|
|
37
|
-
Object.defineProperty(this, "query", { value, writable: true });
|
|
38
|
-
return value;
|
|
39
|
-
},
|
|
40
|
-
set query(value) {
|
|
41
|
-
Object.defineProperty(this, "query", { value, writable: true });
|
|
42
|
-
},
|
|
43
|
-
headers: request.headers,
|
|
44
|
-
body: deserialize(await request.body())
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
encode(output, procedure) {
|
|
48
|
-
const successStatus = fallbackContractConfig(
|
|
49
|
-
"defaultSuccessStatus",
|
|
50
|
-
procedure["~orpc"].route.successStatus
|
|
51
|
-
);
|
|
52
|
-
const outputStructure = fallbackContractConfig(
|
|
53
|
-
"defaultOutputStructure",
|
|
54
|
-
procedure["~orpc"].route.outputStructure
|
|
55
|
-
);
|
|
56
|
-
if (outputStructure === "compact") {
|
|
19
|
+
if (isObject(data)) {
|
|
57
20
|
return {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
body: serialize(output)
|
|
21
|
+
...params,
|
|
22
|
+
...data
|
|
61
23
|
};
|
|
62
24
|
}
|
|
63
|
-
|
|
64
|
-
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
const deserializeSearchParams = () => {
|
|
28
|
+
return deserialize(request.url.searchParams);
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
params,
|
|
32
|
+
get query() {
|
|
33
|
+
const value = deserializeSearchParams();
|
|
34
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
35
|
+
return value;
|
|
36
|
+
},
|
|
37
|
+
set query(value) {
|
|
38
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
39
|
+
},
|
|
40
|
+
headers: request.headers,
|
|
41
|
+
body: deserialize(await request.body())
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function encode(output, procedure) {
|
|
45
|
+
const successStatus = fallbackContractConfig(
|
|
46
|
+
"defaultSuccessStatus",
|
|
47
|
+
procedure["~orpc"].route.successStatus
|
|
48
|
+
);
|
|
49
|
+
const outputStructure = fallbackContractConfig(
|
|
50
|
+
"defaultOutputStructure",
|
|
51
|
+
procedure["~orpc"].route.outputStructure
|
|
52
|
+
);
|
|
53
|
+
if (outputStructure === "compact") {
|
|
54
|
+
return {
|
|
55
|
+
status: successStatus,
|
|
56
|
+
headers: {},
|
|
57
|
+
body: serialize(output)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (!isDetailedOutput(output)) {
|
|
61
|
+
throw new Error(`
|
|
65
62
|
Invalid "detailed" output structure:
|
|
66
63
|
\u2022 Expected an object with optional properties:
|
|
67
64
|
- status (number 200-399)
|
|
@@ -72,32 +69,31 @@ class StandardOpenAPICodec {
|
|
|
72
69
|
Actual value:
|
|
73
70
|
${stringifyJSON(output)}
|
|
74
71
|
`);
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
status: output.status ?? successStatus,
|
|
78
|
-
headers: output.headers ?? {},
|
|
79
|
-
body: serialize(output.body)
|
|
80
|
-
};
|
|
81
72
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
73
|
+
return {
|
|
74
|
+
status: output.status ?? successStatus,
|
|
75
|
+
headers: output.headers ?? {},
|
|
76
|
+
body: serialize(output.body)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function encodeError(error) {
|
|
80
|
+
return {
|
|
81
|
+
status: error.status,
|
|
82
|
+
headers: {},
|
|
83
|
+
body: serialize(error.toJSON(), { outputFormat: "plain" })
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function isDetailedOutput(output) {
|
|
87
|
+
if (!isObject(output)) {
|
|
88
|
+
return false;
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
return true;
|
|
90
|
+
if (output.headers && !isObject(output.headers)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
|
|
94
|
+
return false;
|
|
100
95
|
}
|
|
96
|
+
return true;
|
|
101
97
|
}
|
|
102
98
|
|
|
103
99
|
function resolveFriendlyStandardHandleOptions(options) {
|
|
@@ -204,10 +200,8 @@ class StandardHandler {
|
|
|
204
200
|
clientInterceptors;
|
|
205
201
|
rootInterceptors;
|
|
206
202
|
matcher;
|
|
207
|
-
codec;
|
|
208
203
|
constructor(router, options) {
|
|
209
204
|
this.matcher = new StandardOpenAPIMatcher();
|
|
210
|
-
this.codec = new StandardOpenAPICodec();
|
|
211
205
|
const plugins = new CompositeStandardHandlerPlugin(options.plugins);
|
|
212
206
|
plugins.init(options, router);
|
|
213
207
|
this.interceptors = toArray(options.interceptors);
|
|
@@ -244,7 +238,7 @@ class StandardHandler {
|
|
|
244
238
|
step = "decode_input";
|
|
245
239
|
let input = await runWithSpan(
|
|
246
240
|
{ name: "decode_input" },
|
|
247
|
-
() =>
|
|
241
|
+
() => decode(request2, match.params, match.procedure)
|
|
248
242
|
);
|
|
249
243
|
step = void 0;
|
|
250
244
|
if (isAsyncIteratorObject(input)) {
|
|
@@ -264,7 +258,7 @@ class StandardHandler {
|
|
|
264
258
|
lastEventId: flattenHeader(request2.headers["last-event-id"])
|
|
265
259
|
});
|
|
266
260
|
step = void 0;
|
|
267
|
-
const response =
|
|
261
|
+
const response = encode(output, match.procedure);
|
|
268
262
|
return {
|
|
269
263
|
matched: true,
|
|
270
264
|
response
|
|
@@ -279,7 +273,7 @@ class StandardHandler {
|
|
|
279
273
|
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
|
280
274
|
cause: e
|
|
281
275
|
}) : toORPCError(e);
|
|
282
|
-
const response =
|
|
276
|
+
const response = encodeError(error);
|
|
283
277
|
return {
|
|
284
278
|
matched: true,
|
|
285
279
|
response
|
|
@@ -290,4 +284,4 @@ class StandardHandler {
|
|
|
290
284
|
}
|
|
291
285
|
}
|
|
292
286
|
|
|
293
|
-
export { CompositeStandardHandlerPlugin as C, StandardHandler as S,
|
|
287
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as S, encodeError as a, StandardOpenAPIMatcher as b, decodeParams as c, decode as d, encode as e, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Meta } from '@temporary-name/contract';
|
|
2
2
|
import { HTTPPath, Interceptor } from '@temporary-name/shared';
|
|
3
3
|
import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
|
|
4
|
-
import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.
|
|
4
|
+
import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.CZNLCQBm.js';
|
|
5
5
|
|
|
6
6
|
interface StandardHandlerPlugin<T extends Context> {
|
|
7
7
|
order?: number;
|
|
@@ -48,7 +48,6 @@ declare class StandardHandler<T extends Context> {
|
|
|
48
48
|
private readonly clientInterceptors;
|
|
49
49
|
private readonly rootInterceptors;
|
|
50
50
|
private readonly matcher;
|
|
51
|
-
private readonly codec;
|
|
52
51
|
constructor(router: Router<any, T>, options: NoInfer<StandardHandlerOptions<T>>);
|
|
53
52
|
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
54
53
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTTPPath } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context } from './server.
|
|
3
|
-
import { c as StandardHandleOptions } from './server.
|
|
2
|
+
import { C as Context } from './server.CZNLCQBm.mjs';
|
|
3
|
+
import { c as StandardHandleOptions } from './server.CbLTWfgn.mjs';
|
|
4
4
|
|
|
5
5
|
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
6
6
|
context?: T;
|
|
@@ -71,7 +71,7 @@ declare class Procedure<TInitialContext extends Context, TCurrentContext extends
|
|
|
71
71
|
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
72
72
|
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
73
73
|
}
|
|
74
|
-
type AnyProcedure = Procedure<any, any,
|
|
74
|
+
type AnyProcedure = Procedure<any, any, AnySchema, AnySchema, any, any>;
|
|
75
75
|
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
76
76
|
|
|
77
77
|
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
@@ -189,4 +189,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
|
|
|
189
189
|
};
|
|
190
190
|
|
|
191
191
|
export { isProcedure as D, createProcedureClient as F, 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, middlewareOutputFn as y };
|
|
192
|
-
export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L,
|
|
192
|
+
export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, ORPCErrorConstructorMap as O, Router as R, CreateProcedureClientOptions as a, ProcedureClient as b, AnyRouter as c, Lazy as d, AnyProcedure as e, Middleware as f, MergedCurrentContext as g, ProcedureHandler as h, MapInputMiddleware as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as v, MiddlewareOutputFn as w, MiddlewareOptions as x, ProcedureHandlerOptions as z };
|