@temporary-name/server 1.9.3-alpha.afd18ec2afa743b08cf1b5c2eb6252ded18a1f43 → 1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b
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 +5 -7
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +5 -7
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +5 -7
- package/dist/adapters/standard/index.d.mts +5 -51
- package/dist/adapters/standard/index.d.ts +5 -51
- package/dist/adapters/standard/index.mjs +4 -6
- package/dist/index.d.mts +41 -222
- package/dist/index.d.ts +41 -222
- package/dist/index.mjs +93 -92
- package/dist/openapi/index.d.mts +0 -1
- package/dist/openapi/index.d.ts +0 -1
- package/dist/openapi/index.mjs +4 -12
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.B9i6p26R.d.ts} +1 -1
- package/dist/shared/server.BEHw7Eyx.mjs +247 -0
- package/dist/shared/{server.BKSOrA6h.d.mts → server.Bzrdopnd.d.mts} +1 -1
- package/dist/shared/{server.BKSOrA6h.d.ts → server.Bzrdopnd.d.ts} +1 -1
- package/dist/shared/{server.C1fnTLq0.d.mts → server.C-j2WKJz.d.mts} +1 -1
- package/dist/shared/{server.SLLuK6_v.d.ts → server.CYRDznXq.d.ts} +2 -2
- package/dist/shared/{server.BeuTpcmO.d.mts → server.Cp__uvkw.d.mts} +2 -2
- package/dist/shared/{server._YqJjI50.mjs → server.CvI-wPHM.mjs} +10 -14
- package/dist/shared/{server.BKh8I1Ny.mjs → server.NLSomL7m.mjs} +17 -54
- package/package.json +10 -9
- package/dist/shared/server.DhdDYN-Z.mjs +0 -261
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
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, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, ContractProcedure, 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.NLSomL7m.mjs';
|
|
7
|
+
export { L as LAZY_SYMBOL, a as createORPCErrorConstructorMap, m as mergeCurrentContext, b as middlewareOutputFn } from './shared/server.NLSomL7m.mjs';
|
|
7
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
function isStartWithMiddlewares(middlewares, compare) {
|
|
11
|
+
if (compare.length > middlewares.length) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
15
|
+
if (compare[i] === void 0) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (middlewares[i] !== compare[i]) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
function mergeMiddlewares(first, second, options) {
|
|
25
|
+
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
26
|
+
return second;
|
|
27
|
+
}
|
|
28
|
+
return [...first, ...second];
|
|
29
|
+
}
|
|
30
|
+
function addMiddleware(middlewares, addition) {
|
|
31
|
+
return [...middlewares, addition];
|
|
32
|
+
}
|
|
11
33
|
|
|
12
34
|
function decorateMiddleware(middleware) {
|
|
13
35
|
const decorated = ((...args) => middleware(...args));
|
|
@@ -45,30 +67,6 @@ function decorateMiddleware(middleware) {
|
|
|
45
67
|
return decorated;
|
|
46
68
|
}
|
|
47
69
|
|
|
48
|
-
function isStartWithMiddlewares(middlewares, compare) {
|
|
49
|
-
if (compare.length > middlewares.length) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
53
|
-
if (compare[i] === void 0) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
if (middlewares[i] !== compare[i]) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
function mergeMiddlewares(first, second, options) {
|
|
63
|
-
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
64
|
-
return second;
|
|
65
|
-
}
|
|
66
|
-
return [...first, ...second];
|
|
67
|
-
}
|
|
68
|
-
function addMiddleware(middlewares, addition) {
|
|
69
|
-
return [...middlewares, addition];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
70
|
class Procedure {
|
|
73
71
|
/**
|
|
74
72
|
* This property holds the defined options.
|
|
@@ -295,87 +293,49 @@ async function unlazyRouter(router) {
|
|
|
295
293
|
return unlazied;
|
|
296
294
|
}
|
|
297
295
|
|
|
298
|
-
class
|
|
299
|
-
|
|
300
|
-
* This property holds the defined options.
|
|
301
|
-
*/
|
|
302
|
-
"~orpc";
|
|
296
|
+
class ProcedureBuilder extends ContractProcedure {
|
|
297
|
+
z;
|
|
303
298
|
constructor(def) {
|
|
304
|
-
|
|
299
|
+
super(def);
|
|
300
|
+
this.z = new SchemaClass();
|
|
305
301
|
}
|
|
306
302
|
/**
|
|
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.
|
|
303
|
+
* Adds type-safe custom errors to the contract.
|
|
304
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
325
305
|
*
|
|
326
306
|
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
327
307
|
*/
|
|
328
308
|
errors(errors) {
|
|
329
|
-
return new
|
|
309
|
+
return new ProcedureBuilder({
|
|
330
310
|
...this["~orpc"],
|
|
331
311
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
332
312
|
});
|
|
333
313
|
}
|
|
334
314
|
/**
|
|
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.
|
|
315
|
+
* Sets or updates the metadata for the contract.
|
|
316
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
358
317
|
*
|
|
359
318
|
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
360
319
|
*/
|
|
361
320
|
meta(meta) {
|
|
362
|
-
return new
|
|
321
|
+
return new ProcedureBuilder({
|
|
363
322
|
...this["~orpc"],
|
|
364
323
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
365
324
|
});
|
|
366
325
|
}
|
|
367
326
|
/**
|
|
368
|
-
* Sets or updates the route definition.
|
|
369
|
-
* The provided route is spared-merged with any existing route.
|
|
327
|
+
* Sets or updates the route definition for the contract.
|
|
328
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
370
329
|
* This option is typically relevant when integrating with OpenAPI.
|
|
371
330
|
*
|
|
372
331
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
373
332
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
374
333
|
*/
|
|
375
334
|
route(route) {
|
|
376
|
-
|
|
335
|
+
const { prefix } = this["~orpc"];
|
|
336
|
+
return new ProcedureBuilder({
|
|
377
337
|
...this["~orpc"],
|
|
378
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
338
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
379
339
|
});
|
|
380
340
|
}
|
|
381
341
|
/**
|
|
@@ -384,7 +344,7 @@ class Builder {
|
|
|
384
344
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
385
345
|
*/
|
|
386
346
|
input(schema) {
|
|
387
|
-
return new
|
|
347
|
+
return new ProcedureBuilder({
|
|
388
348
|
...this["~orpc"],
|
|
389
349
|
inputSchema: schema,
|
|
390
350
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
@@ -396,12 +356,33 @@ class Builder {
|
|
|
396
356
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
397
357
|
*/
|
|
398
358
|
output(schema) {
|
|
399
|
-
return new
|
|
359
|
+
return new ProcedureBuilder({
|
|
400
360
|
...this["~orpc"],
|
|
401
361
|
outputSchema: schema,
|
|
402
362
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
403
363
|
});
|
|
404
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
367
|
+
*
|
|
368
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
369
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
370
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
371
|
+
*/
|
|
372
|
+
use(middleware) {
|
|
373
|
+
return new this.constructor({
|
|
374
|
+
...this["~orpc"],
|
|
375
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
useGating(gates, isGateEnabled) {
|
|
379
|
+
return this.use(({ next, context }) => {
|
|
380
|
+
return gatingContext.run(
|
|
381
|
+
(gate) => isGateEnabled(gate, context),
|
|
382
|
+
() => next({ context: { isGateEnabled } })
|
|
383
|
+
);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
405
386
|
/**
|
|
406
387
|
* Defines the handler of the procedure.
|
|
407
388
|
*
|
|
@@ -413,6 +394,8 @@ class Builder {
|
|
|
413
394
|
handler
|
|
414
395
|
});
|
|
415
396
|
}
|
|
397
|
+
}
|
|
398
|
+
class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
416
399
|
/**
|
|
417
400
|
* Prefixes all procedures in the router.
|
|
418
401
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -422,7 +405,7 @@ class Builder {
|
|
|
422
405
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
423
406
|
*/
|
|
424
407
|
prefix(prefix) {
|
|
425
|
-
return new
|
|
408
|
+
return new this.constructor({
|
|
426
409
|
...this["~orpc"],
|
|
427
410
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
428
411
|
});
|
|
@@ -434,7 +417,7 @@ class Builder {
|
|
|
434
417
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
435
418
|
*/
|
|
436
419
|
tag(...tags) {
|
|
437
|
-
return new
|
|
420
|
+
return new this.constructor({
|
|
438
421
|
...this["~orpc"],
|
|
439
422
|
tags: mergeTags(this["~orpc"].tags, tags)
|
|
440
423
|
});
|
|
@@ -457,15 +440,34 @@ class Builder {
|
|
|
457
440
|
return enhanceRouter(lazy(loader), this["~orpc"]);
|
|
458
441
|
}
|
|
459
442
|
}
|
|
443
|
+
|
|
444
|
+
class Builder extends BuilderWithMiddlewares {
|
|
445
|
+
/**
|
|
446
|
+
* Set or override the initial context.
|
|
447
|
+
*
|
|
448
|
+
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
449
|
+
*/
|
|
450
|
+
$context() {
|
|
451
|
+
return this;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Creates a middleware.
|
|
455
|
+
*
|
|
456
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
457
|
+
*/
|
|
458
|
+
middleware(middleware) {
|
|
459
|
+
return decorateMiddleware(middleware);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
460
462
|
function createApiBuilder(opts = {}) {
|
|
461
|
-
|
|
463
|
+
return new Builder({
|
|
462
464
|
route: {},
|
|
463
465
|
meta: opts.meta ?? {},
|
|
464
466
|
errorMap: {},
|
|
465
467
|
inputValidationIndex: 0,
|
|
466
468
|
outputValidationIndex: 0,
|
|
467
469
|
middlewares: [
|
|
468
|
-
onError((error,
|
|
470
|
+
onError((error, _options) => {
|
|
469
471
|
console.dir(error, { depth: null });
|
|
470
472
|
})
|
|
471
473
|
],
|
|
@@ -473,7 +475,6 @@ function createApiBuilder(opts = {}) {
|
|
|
473
475
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
474
476
|
dedupeLeadingMiddlewares: true
|
|
475
477
|
});
|
|
476
|
-
return base;
|
|
477
478
|
}
|
|
478
479
|
const os = createApiBuilder();
|
|
479
480
|
|
|
@@ -614,4 +615,4 @@ function createRouterClient(router, ...rest) {
|
|
|
614
615
|
return recursive;
|
|
615
616
|
}
|
|
616
617
|
|
|
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 };
|
|
618
|
+
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/openapi/index.d.mts
CHANGED
|
@@ -122,7 +122,6 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
|
|
|
122
122
|
*/
|
|
123
123
|
declare class OpenAPIGenerator {
|
|
124
124
|
#private;
|
|
125
|
-
private readonly serializer;
|
|
126
125
|
private readonly converter;
|
|
127
126
|
constructor(options?: OpenAPIGeneratorOptions);
|
|
128
127
|
/**
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -122,7 +122,6 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
|
|
|
122
122
|
*/
|
|
123
123
|
declare class OpenAPIGenerator {
|
|
124
124
|
#private;
|
|
125
|
-
private readonly serializer;
|
|
126
125
|
private readonly converter;
|
|
127
126
|
constructor(options?: OpenAPIGeneratorOptions);
|
|
128
127
|
/**
|
package/dist/openapi/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isProcedure, resolveContractProcedures, ORPCError, createRouterClient } from '@temporary-name/server';
|
|
2
2
|
import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@temporary-name/contract';
|
|
3
3
|
import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus, fallbackORPCErrorStatus, fallbackORPCErrorMessage, resolveMaybeOptionalOptions, createORPCErrorFromJson } from '@temporary-name/shared';
|
|
4
|
-
import {
|
|
4
|
+
import { a as standardizeHTTPPath, j as jsonSerialize, g as getDynamicParams, d as deserialize, s as serialize } from '../shared/server.BEHw7Eyx.mjs';
|
|
5
5
|
import '@temporary-name/standard-server';
|
|
6
6
|
import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
7
|
export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
@@ -380,10 +380,8 @@ class CompositeSchemaConverter {
|
|
|
380
380
|
class OpenAPIGeneratorError extends Error {
|
|
381
381
|
}
|
|
382
382
|
class OpenAPIGenerator {
|
|
383
|
-
serializer;
|
|
384
383
|
converter;
|
|
385
384
|
constructor(options = {}) {
|
|
386
|
-
this.serializer = new StandardOpenAPIJsonSerializer();
|
|
387
385
|
this.converter = new CompositeSchemaConverter(toArray(options.schemaConverters));
|
|
388
386
|
}
|
|
389
387
|
/**
|
|
@@ -464,7 +462,7 @@ ${e.message}`
|
|
|
464
462
|
${errors.join("\n\n")}`
|
|
465
463
|
);
|
|
466
464
|
}
|
|
467
|
-
return
|
|
465
|
+
return jsonSerialize(doc)[0];
|
|
468
466
|
}
|
|
469
467
|
async #resolveCommonSchemas(doc, commonSchemas) {
|
|
470
468
|
let undefinedErrorJsonSchema = {
|
|
@@ -757,19 +755,13 @@ ${errors.join("\n\n")}`
|
|
|
757
755
|
|
|
758
756
|
function createJsonifiedRouterClient(router, ...rest) {
|
|
759
757
|
const options = resolveMaybeOptionalOptions(rest);
|
|
760
|
-
const serializer = new StandardOpenAPISerializer(
|
|
761
|
-
new StandardOpenAPIJsonSerializer(),
|
|
762
|
-
new StandardBracketNotationSerializer()
|
|
763
|
-
);
|
|
764
758
|
options.interceptors ??= [];
|
|
765
759
|
options.interceptors.unshift(async (options2) => {
|
|
766
760
|
try {
|
|
767
|
-
return
|
|
761
|
+
return deserialize(serialize(await options2.next()));
|
|
768
762
|
} catch (e) {
|
|
769
763
|
if (e instanceof ORPCError) {
|
|
770
|
-
throw createORPCErrorFromJson(
|
|
771
|
-
serializer.deserialize(serializer.serialize(e.toJSON(), { outputFormat: "plain" }))
|
|
772
|
-
);
|
|
764
|
+
throw createORPCErrorFromJson(deserialize(serialize(e.toJSON(), { outputFormat: "plain" })));
|
|
773
765
|
}
|
|
774
766
|
throw e;
|
|
775
767
|
}
|
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.C-j2WKJz.mjs';
|
|
5
|
+
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.Bzrdopnd.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.B9i6p26R.js';
|
|
5
|
+
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.Bzrdopnd.js';
|
|
6
6
|
import { Meta } from '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface BatchHandlerOptions<T extends Context> {
|
|
@@ -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.Bzrdopnd.js';
|
|
5
5
|
|
|
6
6
|
interface StandardHandlerPlugin<T extends Context> {
|
|
7
7
|
order?: number;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { isObject, NullProtoObj, isAsyncIteratorObject, isORPCErrorJson, createORPCErrorFromJson, toORPCError } from '@temporary-name/shared';
|
|
2
|
+
import { mapEventIterator, ErrorEvent } from '@temporary-name/standard-server';
|
|
3
|
+
|
|
4
|
+
function bracketNotationSerialize(data, segments = [], result = []) {
|
|
5
|
+
if (Array.isArray(data)) {
|
|
6
|
+
data.forEach((item, i) => {
|
|
7
|
+
bracketNotationSerialize(item, [...segments, i], result);
|
|
8
|
+
});
|
|
9
|
+
} else if (isObject(data)) {
|
|
10
|
+
for (const key in data) {
|
|
11
|
+
bracketNotationSerialize(data[key], [...segments, key], result);
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
result.push([stringifyPath(segments), data]);
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
function bracketNotationDeserialize(serialized, { maxArrayIndex = 9999 } = {}) {
|
|
19
|
+
if (serialized.length === 0) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
const arrayPushStyles = /* @__PURE__ */ new WeakSet();
|
|
23
|
+
const ref = { value: [] };
|
|
24
|
+
for (const [path, value] of serialized) {
|
|
25
|
+
const segments = parsePath(path);
|
|
26
|
+
let currentRef = ref;
|
|
27
|
+
let nextSegment = "value";
|
|
28
|
+
segments.forEach((segment, i) => {
|
|
29
|
+
if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
|
|
30
|
+
currentRef[nextSegment] = [];
|
|
31
|
+
}
|
|
32
|
+
if (i !== segments.length - 1) {
|
|
33
|
+
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment, maxArrayIndex)) {
|
|
34
|
+
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
35
|
+
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
36
|
+
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
37
|
+
} else {
|
|
38
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
if (Array.isArray(currentRef[nextSegment])) {
|
|
43
|
+
if (segment === "") {
|
|
44
|
+
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
45
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
49
|
+
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
50
|
+
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
51
|
+
} else if (!isValidArrayIndex(segment, maxArrayIndex)) {
|
|
52
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
currentRef = currentRef[nextSegment];
|
|
58
|
+
nextSegment = segment;
|
|
59
|
+
});
|
|
60
|
+
if (Array.isArray(currentRef) && nextSegment === "") {
|
|
61
|
+
arrayPushStyles.add(currentRef);
|
|
62
|
+
currentRef.push(value);
|
|
63
|
+
} else if (nextSegment in currentRef) {
|
|
64
|
+
if (Array.isArray(currentRef[nextSegment])) {
|
|
65
|
+
currentRef[nextSegment].push(value);
|
|
66
|
+
} else {
|
|
67
|
+
currentRef[nextSegment] = [currentRef[nextSegment], value];
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
currentRef[nextSegment] = value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return ref.value;
|
|
74
|
+
}
|
|
75
|
+
function stringifyPath(segments) {
|
|
76
|
+
return segments.map((segment) => {
|
|
77
|
+
return segment.toString().replace(/[\\[\]]/g, (match) => {
|
|
78
|
+
switch (match) {
|
|
79
|
+
case "\\":
|
|
80
|
+
return "\\\\";
|
|
81
|
+
case "[":
|
|
82
|
+
return "\\[";
|
|
83
|
+
case "]":
|
|
84
|
+
return "\\]";
|
|
85
|
+
/* v8 ignore next 2 */
|
|
86
|
+
default:
|
|
87
|
+
return match;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}).reduce((result, segment, i) => {
|
|
91
|
+
if (i === 0) {
|
|
92
|
+
return segment;
|
|
93
|
+
}
|
|
94
|
+
return `${result}[${segment}]`;
|
|
95
|
+
}, "");
|
|
96
|
+
}
|
|
97
|
+
function parsePath(path) {
|
|
98
|
+
const segments = [];
|
|
99
|
+
let inBrackets = false;
|
|
100
|
+
let currentSegment = "";
|
|
101
|
+
let backslashCount = 0;
|
|
102
|
+
for (let i = 0; i < path.length; i++) {
|
|
103
|
+
const char = path[i];
|
|
104
|
+
const nextChar = path[i + 1];
|
|
105
|
+
if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
|
|
106
|
+
if (nextChar === void 0) {
|
|
107
|
+
inBrackets = false;
|
|
108
|
+
}
|
|
109
|
+
segments.push(currentSegment);
|
|
110
|
+
currentSegment = "";
|
|
111
|
+
i++;
|
|
112
|
+
} else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
|
|
113
|
+
inBrackets = true;
|
|
114
|
+
segments.push(currentSegment);
|
|
115
|
+
currentSegment = "";
|
|
116
|
+
} else if (char === "\\") {
|
|
117
|
+
backslashCount++;
|
|
118
|
+
} else {
|
|
119
|
+
currentSegment += "\\".repeat(backslashCount / 2) + char;
|
|
120
|
+
backslashCount = 0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return inBrackets || segments.length === 0 ? [path] : segments;
|
|
124
|
+
}
|
|
125
|
+
function isValidArrayIndex(value, maxIndex) {
|
|
126
|
+
return /^0$|^[1-9]\d*$/.test(value) && Number(value) <= maxIndex;
|
|
127
|
+
}
|
|
128
|
+
function arrayToObject(array) {
|
|
129
|
+
const obj = new NullProtoObj();
|
|
130
|
+
array.forEach((item, i) => {
|
|
131
|
+
obj[i] = item;
|
|
132
|
+
});
|
|
133
|
+
return obj;
|
|
134
|
+
}
|
|
135
|
+
function pushStyleArrayToObject(array) {
|
|
136
|
+
const obj = new NullProtoObj();
|
|
137
|
+
obj[""] = array.length === 1 ? array[0] : array;
|
|
138
|
+
return obj;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function jsonSerialize(data, hasBlobRef = { value: false }) {
|
|
142
|
+
if (data instanceof Blob) {
|
|
143
|
+
hasBlobRef.value = true;
|
|
144
|
+
return [data, hasBlobRef.value];
|
|
145
|
+
}
|
|
146
|
+
if (data instanceof Set) {
|
|
147
|
+
return jsonSerialize(Array.from(data), hasBlobRef);
|
|
148
|
+
}
|
|
149
|
+
if (data instanceof Map) {
|
|
150
|
+
return jsonSerialize(Array.from(data.entries()), hasBlobRef);
|
|
151
|
+
}
|
|
152
|
+
if (Array.isArray(data)) {
|
|
153
|
+
const json = data.map((v) => v === void 0 ? null : jsonSerialize(v, hasBlobRef)[0]);
|
|
154
|
+
return [json, hasBlobRef.value];
|
|
155
|
+
}
|
|
156
|
+
if (isObject(data)) {
|
|
157
|
+
const json = {};
|
|
158
|
+
for (const k in data) {
|
|
159
|
+
if (k === "toJSON" && typeof data[k] === "function") {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
json[k] = jsonSerialize(data[k], hasBlobRef)[0];
|
|
163
|
+
}
|
|
164
|
+
return [json, hasBlobRef.value];
|
|
165
|
+
}
|
|
166
|
+
if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
|
|
167
|
+
return [data.toString(), hasBlobRef.value];
|
|
168
|
+
}
|
|
169
|
+
if (data instanceof Date) {
|
|
170
|
+
return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
|
|
171
|
+
}
|
|
172
|
+
if (Number.isNaN(data)) {
|
|
173
|
+
return [null, hasBlobRef.value];
|
|
174
|
+
}
|
|
175
|
+
return [data, hasBlobRef.value];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function serialize(data, options = {}) {
|
|
179
|
+
if (isAsyncIteratorObject(data) && !options.outputFormat) {
|
|
180
|
+
return mapEventIterator(data, {
|
|
181
|
+
value: async (value) => _serialize(value, { outputFormat: "plain" }),
|
|
182
|
+
error: async (e) => {
|
|
183
|
+
return new ErrorEvent({
|
|
184
|
+
data: _serialize(toORPCError(e).toJSON(), { outputFormat: "plain" }),
|
|
185
|
+
cause: e
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return _serialize(data, options);
|
|
191
|
+
}
|
|
192
|
+
function _serialize(data, options) {
|
|
193
|
+
const [json, hasBlob] = jsonSerialize(data);
|
|
194
|
+
if (options.outputFormat === "plain") {
|
|
195
|
+
return json;
|
|
196
|
+
}
|
|
197
|
+
if (options.outputFormat === "URLSearchParams") {
|
|
198
|
+
const params = new URLSearchParams();
|
|
199
|
+
for (const [path, value] of bracketNotationSerialize(json)) {
|
|
200
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
201
|
+
params.append(path, value.toString());
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return params;
|
|
205
|
+
}
|
|
206
|
+
if (json instanceof Blob || json === void 0 || !hasBlob) {
|
|
207
|
+
return json;
|
|
208
|
+
}
|
|
209
|
+
const form = new FormData();
|
|
210
|
+
for (const [path, value] of bracketNotationSerialize(json)) {
|
|
211
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
212
|
+
form.append(path, value.toString());
|
|
213
|
+
} else if (value instanceof Blob) {
|
|
214
|
+
form.append(path, value);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return form;
|
|
218
|
+
}
|
|
219
|
+
function deserialize(data) {
|
|
220
|
+
if (data instanceof URLSearchParams || data instanceof FormData) {
|
|
221
|
+
return bracketNotationDeserialize(Array.from(data.entries()));
|
|
222
|
+
}
|
|
223
|
+
if (isAsyncIteratorObject(data)) {
|
|
224
|
+
return mapEventIterator(data, {
|
|
225
|
+
value: async (value) => value,
|
|
226
|
+
error: async (e) => {
|
|
227
|
+
if (e instanceof ErrorEvent && isORPCErrorJson(e.data)) {
|
|
228
|
+
return createORPCErrorFromJson(e.data, { cause: e });
|
|
229
|
+
}
|
|
230
|
+
return e;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return data;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function standardizeHTTPPath(path) {
|
|
238
|
+
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
239
|
+
}
|
|
240
|
+
function getDynamicParams(path) {
|
|
241
|
+
return path ? standardizeHTTPPath(path).match(/\/\{[^}]+\}/g)?.map((v) => ({
|
|
242
|
+
raw: v,
|
|
243
|
+
name: v.match(/\{\+?([^}]+)\}/)[1]
|
|
244
|
+
})) : void 0;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export { standardizeHTTPPath as a, deserialize as d, getDynamicParams as g, jsonSerialize as j, serialize as s };
|
|
@@ -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<{
|
|
@@ -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<{
|
|
@@ -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.Bzrdopnd.mjs';
|
|
5
5
|
|
|
6
6
|
interface StandardHandlerPlugin<T extends Context> {
|
|
7
7
|
order?: number;
|