@temporary-name/server 1.9.3-alpha.afd18ec2afa743b08cf1b5c2eb6252ded18a1f43 → 1.9.3-alpha.e09726e1bf5340c7b7052eeabcb4935b3c85ce93
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.mjs +3 -3
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/node/index.mjs +3 -3
- package/dist/adapters/standard/index.d.mts +2 -48
- package/dist/adapters/standard/index.d.ts +2 -48
- package/dist/adapters/standard/index.mjs +2 -2
- 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/shared/server.BEHw7Eyx.mjs +247 -0
- package/dist/shared/{server._YqJjI50.mjs → server.DLsti1Pv.mjs} +9 -13
- package/package.json +8 -8
- package/dist/shared/server.DhdDYN-Z.mjs +0 -261
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
2
|
import { toStandardLazyRequest, sendStandardResponse } from '@temporary-name/standard-server-aws-lambda';
|
|
3
|
-
import { S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
|
3
|
+
import { S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DLsti1Pv.mjs';
|
|
4
4
|
import '@temporary-name/contract';
|
|
5
|
+
import '@temporary-name/standard-server';
|
|
5
6
|
import '@temporary-name/server';
|
|
6
7
|
import 'rou3';
|
|
7
|
-
import '@temporary-name/standard-server';
|
|
8
8
|
import '../../shared/server.BKh8I1Ny.mjs';
|
|
9
9
|
import 'node:async_hooks';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import 'zod/v4/core';
|
|
12
|
-
import '../../shared/server.
|
|
12
|
+
import '../../shared/server.BEHw7Eyx.mjs';
|
|
13
13
|
|
|
14
14
|
class AwsLambdaHandler {
|
|
15
15
|
sendStandardResponseOptions;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ORPCError, toArray, intercept, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
2
|
import { toStandardLazyRequest, toFetchResponse } from '@temporary-name/standard-server-fetch';
|
|
3
|
-
import { C as CompositeStandardHandlerPlugin, S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
|
3
|
+
import { C as CompositeStandardHandlerPlugin, S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DLsti1Pv.mjs';
|
|
4
4
|
import '@temporary-name/contract';
|
|
5
|
+
import '@temporary-name/standard-server';
|
|
5
6
|
import '@temporary-name/server';
|
|
6
7
|
import 'rou3';
|
|
7
|
-
import '@temporary-name/standard-server';
|
|
8
8
|
import '../../shared/server.BKh8I1Ny.mjs';
|
|
9
|
-
import '../../shared/server.
|
|
9
|
+
import '../../shared/server.BEHw7Eyx.mjs';
|
|
10
10
|
import 'node:async_hooks';
|
|
11
11
|
import 'zod';
|
|
12
12
|
import 'zod/v4/core';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { once, ORPCError, toArray, intercept, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
2
|
import compression from '@temporary-name/interop/compression';
|
|
3
3
|
import { toStandardLazyRequest, sendStandardResponse } from '@temporary-name/standard-server-node';
|
|
4
|
-
import { C as CompositeStandardHandlerPlugin, S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
|
4
|
+
import { C as CompositeStandardHandlerPlugin, S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DLsti1Pv.mjs';
|
|
5
5
|
import '@temporary-name/contract';
|
|
6
|
+
import '@temporary-name/standard-server';
|
|
6
7
|
import '@temporary-name/server';
|
|
7
8
|
import 'rou3';
|
|
8
|
-
import '@temporary-name/standard-server';
|
|
9
9
|
import '../../shared/server.BKh8I1Ny.mjs';
|
|
10
|
-
import '../../shared/server.
|
|
10
|
+
import '../../shared/server.BEHw7Eyx.mjs';
|
|
11
11
|
import 'node:async_hooks';
|
|
12
12
|
import 'zod';
|
|
13
13
|
import 'zod/v4/core';
|
|
@@ -1,61 +1,15 @@
|
|
|
1
1
|
export { C as CompositeStandardHandlerPlugin, c as StandardHandleOptions, d as StandardHandleResult, e as StandardHandler, S as StandardHandlerInterceptorOptions, b as StandardHandlerOptions, a as StandardHandlerPlugin } from '../../shared/server.C1fnTLq0.mjs';
|
|
2
2
|
import { AnyProcedure, AnyRouter } from '@temporary-name/server';
|
|
3
3
|
import { StandardCodec as StandardCodec$1, StandardParams as StandardParams$1, StandardMatcher as StandardMatcher$1, StandardMatchResult as StandardMatchResult$1 } from '@temporary-name/server/standard';
|
|
4
|
-
import {
|
|
4
|
+
import { ORPCError, HTTPPath } from '@temporary-name/shared';
|
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
|
|
6
6
|
import { h as AnyProcedure$1, f as AnyRouter$1 } from '../../shared/server.BKSOrA6h.mjs';
|
|
7
7
|
export { F as FriendlyStandardHandleOptions, d as decodeParams, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.BeuTpcmO.mjs';
|
|
8
8
|
import '@temporary-name/contract';
|
|
9
9
|
|
|
10
|
-
type StandardBracketNotationSerialized = [string, unknown][];
|
|
11
|
-
interface StandardBracketNotationSerializerOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Maximum allowed array index for bracket notation deserialization.
|
|
14
|
-
*
|
|
15
|
-
* This helps protect against memory exhaustion attacks where malicious input
|
|
16
|
-
* uses extremely large array indices (e.g., `?arr[4294967296]=value`).
|
|
17
|
-
*
|
|
18
|
-
* While bracket notation creates sparse arrays that handle large indices efficiently,
|
|
19
|
-
* downstream code might inadvertently convert these sparse arrays to dense arrays,
|
|
20
|
-
* potentially creating millions of undefined elements and causing memory issues.
|
|
21
|
-
*
|
|
22
|
-
* @note Only applies to deserialization.
|
|
23
|
-
* @default 9_999 (array with 10,000 elements)
|
|
24
|
-
*/
|
|
25
|
-
maxBracketNotationArrayIndex?: number;
|
|
26
|
-
}
|
|
27
|
-
declare class StandardBracketNotationSerializer {
|
|
28
|
-
private readonly maxArrayIndex;
|
|
29
|
-
constructor(options?: StandardBracketNotationSerializerOptions);
|
|
30
|
-
serialize(data: unknown, segments?: Segment[], result?: StandardBracketNotationSerialized): StandardBracketNotationSerialized;
|
|
31
|
-
deserialize(serialized: StandardBracketNotationSerialized): Record<string, unknown> | unknown[];
|
|
32
|
-
stringifyPath(segments: readonly Segment[]): string;
|
|
33
|
-
parsePath(path: string): string[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
type StandardOpenAPIJsonSerialized = [json: unknown, hasBlob: boolean];
|
|
37
|
-
declare class StandardOpenAPIJsonSerializer {
|
|
38
|
-
serialize(data: unknown, hasBlobRef?: {
|
|
39
|
-
value: boolean;
|
|
40
|
-
}): StandardOpenAPIJsonSerialized;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
interface StandardOpenAPISerializeOptions {
|
|
44
|
-
outputFormat?: 'plain' | 'URLSearchParams';
|
|
45
|
-
}
|
|
46
|
-
declare class StandardOpenAPISerializer {
|
|
47
|
-
#private;
|
|
48
|
-
private readonly jsonSerializer;
|
|
49
|
-
private readonly bracketNotation;
|
|
50
|
-
constructor(jsonSerializer: StandardOpenAPIJsonSerializer, bracketNotation: StandardBracketNotationSerializer);
|
|
51
|
-
serialize(data: unknown, options?: StandardOpenAPISerializeOptions): unknown;
|
|
52
|
-
deserialize(data: unknown): unknown;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
10
|
declare class StandardOpenAPICodec implements StandardCodec$1 {
|
|
56
11
|
#private;
|
|
57
|
-
|
|
58
|
-
constructor(serializer: StandardOpenAPISerializer);
|
|
12
|
+
constructor();
|
|
59
13
|
decode(request: StandardLazyRequest, params: StandardParams$1 | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
60
14
|
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
61
15
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
@@ -1,61 +1,15 @@
|
|
|
1
1
|
export { C as CompositeStandardHandlerPlugin, c as StandardHandleOptions, d as StandardHandleResult, e as StandardHandler, S as StandardHandlerInterceptorOptions, b as StandardHandlerOptions, a as StandardHandlerPlugin } from '../../shared/server.CQyYNJ1H.js';
|
|
2
2
|
import { AnyProcedure, AnyRouter } from '@temporary-name/server';
|
|
3
3
|
import { StandardCodec as StandardCodec$1, StandardParams as StandardParams$1, StandardMatcher as StandardMatcher$1, StandardMatchResult as StandardMatchResult$1 } from '@temporary-name/server/standard';
|
|
4
|
-
import {
|
|
4
|
+
import { ORPCError, HTTPPath } from '@temporary-name/shared';
|
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
|
|
6
6
|
import { h as AnyProcedure$1, f as AnyRouter$1 } from '../../shared/server.BKSOrA6h.js';
|
|
7
7
|
export { F as FriendlyStandardHandleOptions, d as decodeParams, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.SLLuK6_v.js';
|
|
8
8
|
import '@temporary-name/contract';
|
|
9
9
|
|
|
10
|
-
type StandardBracketNotationSerialized = [string, unknown][];
|
|
11
|
-
interface StandardBracketNotationSerializerOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Maximum allowed array index for bracket notation deserialization.
|
|
14
|
-
*
|
|
15
|
-
* This helps protect against memory exhaustion attacks where malicious input
|
|
16
|
-
* uses extremely large array indices (e.g., `?arr[4294967296]=value`).
|
|
17
|
-
*
|
|
18
|
-
* While bracket notation creates sparse arrays that handle large indices efficiently,
|
|
19
|
-
* downstream code might inadvertently convert these sparse arrays to dense arrays,
|
|
20
|
-
* potentially creating millions of undefined elements and causing memory issues.
|
|
21
|
-
*
|
|
22
|
-
* @note Only applies to deserialization.
|
|
23
|
-
* @default 9_999 (array with 10,000 elements)
|
|
24
|
-
*/
|
|
25
|
-
maxBracketNotationArrayIndex?: number;
|
|
26
|
-
}
|
|
27
|
-
declare class StandardBracketNotationSerializer {
|
|
28
|
-
private readonly maxArrayIndex;
|
|
29
|
-
constructor(options?: StandardBracketNotationSerializerOptions);
|
|
30
|
-
serialize(data: unknown, segments?: Segment[], result?: StandardBracketNotationSerialized): StandardBracketNotationSerialized;
|
|
31
|
-
deserialize(serialized: StandardBracketNotationSerialized): Record<string, unknown> | unknown[];
|
|
32
|
-
stringifyPath(segments: readonly Segment[]): string;
|
|
33
|
-
parsePath(path: string): string[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
type StandardOpenAPIJsonSerialized = [json: unknown, hasBlob: boolean];
|
|
37
|
-
declare class StandardOpenAPIJsonSerializer {
|
|
38
|
-
serialize(data: unknown, hasBlobRef?: {
|
|
39
|
-
value: boolean;
|
|
40
|
-
}): StandardOpenAPIJsonSerialized;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
interface StandardOpenAPISerializeOptions {
|
|
44
|
-
outputFormat?: 'plain' | 'URLSearchParams';
|
|
45
|
-
}
|
|
46
|
-
declare class StandardOpenAPISerializer {
|
|
47
|
-
#private;
|
|
48
|
-
private readonly jsonSerializer;
|
|
49
|
-
private readonly bracketNotation;
|
|
50
|
-
constructor(jsonSerializer: StandardOpenAPIJsonSerializer, bracketNotation: StandardBracketNotationSerializer);
|
|
51
|
-
serialize(data: unknown, options?: StandardOpenAPISerializeOptions): unknown;
|
|
52
|
-
deserialize(data: unknown): unknown;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
10
|
declare class StandardOpenAPICodec implements StandardCodec$1 {
|
|
56
11
|
#private;
|
|
57
|
-
|
|
58
|
-
constructor(serializer: StandardOpenAPISerializer);
|
|
12
|
+
constructor();
|
|
59
13
|
decode(request: StandardLazyRequest, params: StandardParams$1 | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
60
14
|
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
61
15
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardOpenAPICodec, b as StandardOpenAPIMatcher, d as decodeParams, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.
|
|
1
|
+
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardOpenAPICodec, b as StandardOpenAPIMatcher, d as decodeParams, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.DLsti1Pv.mjs';
|
|
2
2
|
import '@temporary-name/shared';
|
|
3
3
|
import '@temporary-name/standard-server';
|
|
4
4
|
import '../../shared/server.BKh8I1Ny.mjs';
|
|
@@ -6,6 +6,6 @@ import '@temporary-name/contract';
|
|
|
6
6
|
import 'node:async_hooks';
|
|
7
7
|
import 'zod';
|
|
8
8
|
import 'zod/v4/core';
|
|
9
|
-
import '../../shared/server.
|
|
9
|
+
import '../../shared/server.BEHw7Eyx.mjs';
|
|
10
10
|
import '@temporary-name/server';
|
|
11
11
|
import 'rou3';
|
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
|
}
|
|
@@ -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 };
|
|
@@ -1,14 +1,13 @@
|
|
|
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
3
|
import { c as createProcedureClient } from './server.BKh8I1Ny.mjs';
|
|
4
|
-
import { s as standardizeHTTPPath, S as StandardBracketNotationSerializer, a as StandardOpenAPISerializer, b as StandardOpenAPIJsonSerializer } from './server.DhdDYN-Z.mjs';
|
|
5
4
|
import { fallbackContractConfig } from '@temporary-name/contract';
|
|
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
9
|
class StandardOpenAPICodec {
|
|
10
|
-
constructor(
|
|
11
|
-
this.serializer = serializer;
|
|
10
|
+
constructor() {
|
|
12
11
|
}
|
|
13
12
|
async decode(request, params, procedure) {
|
|
14
13
|
const inputStructure = fallbackContractConfig(
|
|
@@ -16,7 +15,7 @@ class StandardOpenAPICodec {
|
|
|
16
15
|
procedure["~orpc"].route.inputStructure
|
|
17
16
|
);
|
|
18
17
|
if (inputStructure === "compact") {
|
|
19
|
-
const data = request.method === "GET" ?
|
|
18
|
+
const data = request.method === "GET" ? deserialize(request.url.searchParams) : deserialize(await request.body());
|
|
20
19
|
if (data === void 0) {
|
|
21
20
|
return params;
|
|
22
21
|
}
|
|
@@ -29,7 +28,7 @@ class StandardOpenAPICodec {
|
|
|
29
28
|
return data;
|
|
30
29
|
}
|
|
31
30
|
const deserializeSearchParams = () => {
|
|
32
|
-
return
|
|
31
|
+
return deserialize(request.url.searchParams);
|
|
33
32
|
};
|
|
34
33
|
return {
|
|
35
34
|
params,
|
|
@@ -42,7 +41,7 @@ class StandardOpenAPICodec {
|
|
|
42
41
|
Object.defineProperty(this, "query", { value, writable: true });
|
|
43
42
|
},
|
|
44
43
|
headers: request.headers,
|
|
45
|
-
body:
|
|
44
|
+
body: deserialize(await request.body())
|
|
46
45
|
};
|
|
47
46
|
}
|
|
48
47
|
encode(output, procedure) {
|
|
@@ -58,7 +57,7 @@ class StandardOpenAPICodec {
|
|
|
58
57
|
return {
|
|
59
58
|
status: successStatus,
|
|
60
59
|
headers: {},
|
|
61
|
-
body:
|
|
60
|
+
body: serialize(output)
|
|
62
61
|
};
|
|
63
62
|
}
|
|
64
63
|
if (!this.#isDetailedOutput(output)) {
|
|
@@ -77,14 +76,14 @@ class StandardOpenAPICodec {
|
|
|
77
76
|
return {
|
|
78
77
|
status: output.status ?? successStatus,
|
|
79
78
|
headers: output.headers ?? {},
|
|
80
|
-
body:
|
|
79
|
+
body: serialize(output.body)
|
|
81
80
|
};
|
|
82
81
|
}
|
|
83
82
|
encodeError(error) {
|
|
84
83
|
return {
|
|
85
84
|
status: error.status,
|
|
86
85
|
headers: {},
|
|
87
|
-
body:
|
|
86
|
+
body: serialize(error.toJSON(), { outputFormat: "plain" })
|
|
88
87
|
};
|
|
89
88
|
}
|
|
90
89
|
#isDetailedOutput(output) {
|
|
@@ -207,11 +206,8 @@ class StandardHandler {
|
|
|
207
206
|
matcher;
|
|
208
207
|
codec;
|
|
209
208
|
constructor(router, options) {
|
|
210
|
-
const jsonSerializer = new StandardOpenAPIJsonSerializer();
|
|
211
|
-
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
|
212
|
-
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
213
209
|
this.matcher = new StandardOpenAPIMatcher();
|
|
214
|
-
this.codec = new StandardOpenAPICodec(
|
|
210
|
+
this.codec = new StandardOpenAPICodec();
|
|
215
211
|
const plugins = new CompositeStandardHandlerPlugin(options.plugins);
|
|
216
212
|
plugins.init(options, router);
|
|
217
213
|
this.interceptors = toArray(options.interceptors);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporary-name/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.9.3-alpha.
|
|
4
|
+
"version": "1.9.3-alpha.e09726e1bf5340c7b7052eeabcb4935b3c85ce93",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.stainless.com/",
|
|
7
7
|
"repository": {
|
|
@@ -74,13 +74,13 @@
|
|
|
74
74
|
"@standard-schema/spec": "^1.0.0",
|
|
75
75
|
"rou3": "^0.7.7",
|
|
76
76
|
"zod": "^4.1.12",
|
|
77
|
-
"@temporary-name/
|
|
78
|
-
"@temporary-name/
|
|
79
|
-
"@temporary-name/standard-server": "1.9.3-alpha.
|
|
80
|
-
"@temporary-name/standard-server-
|
|
81
|
-
"@temporary-name/standard-server-
|
|
82
|
-
"@temporary-name/
|
|
83
|
-
"@temporary-name/shared": "1.9.3-alpha.
|
|
77
|
+
"@temporary-name/interop": "1.9.3-alpha.e09726e1bf5340c7b7052eeabcb4935b3c85ce93",
|
|
78
|
+
"@temporary-name/standard-server": "1.9.3-alpha.e09726e1bf5340c7b7052eeabcb4935b3c85ce93",
|
|
79
|
+
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.e09726e1bf5340c7b7052eeabcb4935b3c85ce93",
|
|
80
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.e09726e1bf5340c7b7052eeabcb4935b3c85ce93",
|
|
81
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.e09726e1bf5340c7b7052eeabcb4935b3c85ce93",
|
|
82
|
+
"@temporary-name/contract": "1.9.3-alpha.e09726e1bf5340c7b7052eeabcb4935b3c85ce93",
|
|
83
|
+
"@temporary-name/shared": "1.9.3-alpha.e09726e1bf5340c7b7052eeabcb4935b3c85ce93"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@types/supertest": "^6.0.3",
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { isObject, NullProtoObj, isAsyncIteratorObject, toORPCError, isORPCErrorJson, createORPCErrorFromJson } from '@temporary-name/shared';
|
|
2
|
-
import { mapEventIterator, ErrorEvent } from '@temporary-name/standard-server';
|
|
3
|
-
|
|
4
|
-
class StandardBracketNotationSerializer {
|
|
5
|
-
maxArrayIndex;
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
this.maxArrayIndex = options.maxBracketNotationArrayIndex ?? 9999;
|
|
8
|
-
}
|
|
9
|
-
serialize(data, segments = [], result = []) {
|
|
10
|
-
if (Array.isArray(data)) {
|
|
11
|
-
data.forEach((item, i) => {
|
|
12
|
-
this.serialize(item, [...segments, i], result);
|
|
13
|
-
});
|
|
14
|
-
} else if (isObject(data)) {
|
|
15
|
-
for (const key in data) {
|
|
16
|
-
this.serialize(data[key], [...segments, key], result);
|
|
17
|
-
}
|
|
18
|
-
} else {
|
|
19
|
-
result.push([this.stringifyPath(segments), data]);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
deserialize(serialized) {
|
|
24
|
-
if (serialized.length === 0) {
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
const arrayPushStyles = /* @__PURE__ */ new WeakSet();
|
|
28
|
-
const ref = { value: [] };
|
|
29
|
-
for (const [path, value] of serialized) {
|
|
30
|
-
const segments = this.parsePath(path);
|
|
31
|
-
let currentRef = ref;
|
|
32
|
-
let nextSegment = "value";
|
|
33
|
-
segments.forEach((segment, i) => {
|
|
34
|
-
if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
|
|
35
|
-
currentRef[nextSegment] = [];
|
|
36
|
-
}
|
|
37
|
-
if (i !== segments.length - 1) {
|
|
38
|
-
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment, this.maxArrayIndex)) {
|
|
39
|
-
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
40
|
-
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
41
|
-
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
42
|
-
} else {
|
|
43
|
-
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
} else {
|
|
47
|
-
if (Array.isArray(currentRef[nextSegment])) {
|
|
48
|
-
if (segment === "") {
|
|
49
|
-
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
50
|
-
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
54
|
-
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
55
|
-
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
56
|
-
} else if (!isValidArrayIndex(segment, this.maxArrayIndex)) {
|
|
57
|
-
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
currentRef = currentRef[nextSegment];
|
|
63
|
-
nextSegment = segment;
|
|
64
|
-
});
|
|
65
|
-
if (Array.isArray(currentRef) && nextSegment === "") {
|
|
66
|
-
arrayPushStyles.add(currentRef);
|
|
67
|
-
currentRef.push(value);
|
|
68
|
-
} else if (nextSegment in currentRef) {
|
|
69
|
-
if (Array.isArray(currentRef[nextSegment])) {
|
|
70
|
-
currentRef[nextSegment].push(value);
|
|
71
|
-
} else {
|
|
72
|
-
currentRef[nextSegment] = [currentRef[nextSegment], value];
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
currentRef[nextSegment] = value;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return ref.value;
|
|
79
|
-
}
|
|
80
|
-
stringifyPath(segments) {
|
|
81
|
-
return segments.map((segment) => {
|
|
82
|
-
return segment.toString().replace(/[\\[\]]/g, (match) => {
|
|
83
|
-
switch (match) {
|
|
84
|
-
case "\\":
|
|
85
|
-
return "\\\\";
|
|
86
|
-
case "[":
|
|
87
|
-
return "\\[";
|
|
88
|
-
case "]":
|
|
89
|
-
return "\\]";
|
|
90
|
-
/* v8 ignore next 2 */
|
|
91
|
-
default:
|
|
92
|
-
return match;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}).reduce((result, segment, i) => {
|
|
96
|
-
if (i === 0) {
|
|
97
|
-
return segment;
|
|
98
|
-
}
|
|
99
|
-
return `${result}[${segment}]`;
|
|
100
|
-
}, "");
|
|
101
|
-
}
|
|
102
|
-
parsePath(path) {
|
|
103
|
-
const segments = [];
|
|
104
|
-
let inBrackets = false;
|
|
105
|
-
let currentSegment = "";
|
|
106
|
-
let backslashCount = 0;
|
|
107
|
-
for (let i = 0; i < path.length; i++) {
|
|
108
|
-
const char = path[i];
|
|
109
|
-
const nextChar = path[i + 1];
|
|
110
|
-
if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
|
|
111
|
-
if (nextChar === void 0) {
|
|
112
|
-
inBrackets = false;
|
|
113
|
-
}
|
|
114
|
-
segments.push(currentSegment);
|
|
115
|
-
currentSegment = "";
|
|
116
|
-
i++;
|
|
117
|
-
} else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
|
|
118
|
-
inBrackets = true;
|
|
119
|
-
segments.push(currentSegment);
|
|
120
|
-
currentSegment = "";
|
|
121
|
-
} else if (char === "\\") {
|
|
122
|
-
backslashCount++;
|
|
123
|
-
} else {
|
|
124
|
-
currentSegment += "\\".repeat(backslashCount / 2) + char;
|
|
125
|
-
backslashCount = 0;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return inBrackets || segments.length === 0 ? [path] : segments;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function isValidArrayIndex(value, maxIndex) {
|
|
132
|
-
return /^0$|^[1-9]\d*$/.test(value) && Number(value) <= maxIndex;
|
|
133
|
-
}
|
|
134
|
-
function arrayToObject(array) {
|
|
135
|
-
const obj = new NullProtoObj();
|
|
136
|
-
array.forEach((item, i) => {
|
|
137
|
-
obj[i] = item;
|
|
138
|
-
});
|
|
139
|
-
return obj;
|
|
140
|
-
}
|
|
141
|
-
function pushStyleArrayToObject(array) {
|
|
142
|
-
const obj = new NullProtoObj();
|
|
143
|
-
obj[""] = array.length === 1 ? array[0] : array;
|
|
144
|
-
return obj;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
class StandardOpenAPIJsonSerializer {
|
|
148
|
-
serialize(data, hasBlobRef = { value: false }) {
|
|
149
|
-
if (data instanceof Blob) {
|
|
150
|
-
hasBlobRef.value = true;
|
|
151
|
-
return [data, hasBlobRef.value];
|
|
152
|
-
}
|
|
153
|
-
if (data instanceof Set) {
|
|
154
|
-
return this.serialize(Array.from(data), hasBlobRef);
|
|
155
|
-
}
|
|
156
|
-
if (data instanceof Map) {
|
|
157
|
-
return this.serialize(Array.from(data.entries()), hasBlobRef);
|
|
158
|
-
}
|
|
159
|
-
if (Array.isArray(data)) {
|
|
160
|
-
const json = data.map((v) => v === void 0 ? null : this.serialize(v, hasBlobRef)[0]);
|
|
161
|
-
return [json, hasBlobRef.value];
|
|
162
|
-
}
|
|
163
|
-
if (isObject(data)) {
|
|
164
|
-
const json = {};
|
|
165
|
-
for (const k in data) {
|
|
166
|
-
if (k === "toJSON" && typeof data[k] === "function") {
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
json[k] = this.serialize(data[k], hasBlobRef)[0];
|
|
170
|
-
}
|
|
171
|
-
return [json, hasBlobRef.value];
|
|
172
|
-
}
|
|
173
|
-
if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
|
|
174
|
-
return [data.toString(), hasBlobRef.value];
|
|
175
|
-
}
|
|
176
|
-
if (data instanceof Date) {
|
|
177
|
-
return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
|
|
178
|
-
}
|
|
179
|
-
if (Number.isNaN(data)) {
|
|
180
|
-
return [null, hasBlobRef.value];
|
|
181
|
-
}
|
|
182
|
-
return [data, hasBlobRef.value];
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
class StandardOpenAPISerializer {
|
|
187
|
-
constructor(jsonSerializer, bracketNotation) {
|
|
188
|
-
this.jsonSerializer = jsonSerializer;
|
|
189
|
-
this.bracketNotation = bracketNotation;
|
|
190
|
-
}
|
|
191
|
-
serialize(data, options = {}) {
|
|
192
|
-
if (isAsyncIteratorObject(data) && !options.outputFormat) {
|
|
193
|
-
return mapEventIterator(data, {
|
|
194
|
-
value: async (value) => this.#serialize(value, { outputFormat: "plain" }),
|
|
195
|
-
error: async (e) => {
|
|
196
|
-
return new ErrorEvent({
|
|
197
|
-
data: this.#serialize(toORPCError(e).toJSON(), { outputFormat: "plain" }),
|
|
198
|
-
cause: e
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
return this.#serialize(data, options);
|
|
204
|
-
}
|
|
205
|
-
#serialize(data, options) {
|
|
206
|
-
const [json, hasBlob] = this.jsonSerializer.serialize(data);
|
|
207
|
-
if (options.outputFormat === "plain") {
|
|
208
|
-
return json;
|
|
209
|
-
}
|
|
210
|
-
if (options.outputFormat === "URLSearchParams") {
|
|
211
|
-
const params = new URLSearchParams();
|
|
212
|
-
for (const [path, value] of this.bracketNotation.serialize(json)) {
|
|
213
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
214
|
-
params.append(path, value.toString());
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return params;
|
|
218
|
-
}
|
|
219
|
-
if (json instanceof Blob || json === void 0 || !hasBlob) {
|
|
220
|
-
return json;
|
|
221
|
-
}
|
|
222
|
-
const form = new FormData();
|
|
223
|
-
for (const [path, value] of this.bracketNotation.serialize(json)) {
|
|
224
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
225
|
-
form.append(path, value.toString());
|
|
226
|
-
} else if (value instanceof Blob) {
|
|
227
|
-
form.append(path, value);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return form;
|
|
231
|
-
}
|
|
232
|
-
deserialize(data) {
|
|
233
|
-
if (data instanceof URLSearchParams || data instanceof FormData) {
|
|
234
|
-
return this.bracketNotation.deserialize(Array.from(data.entries()));
|
|
235
|
-
}
|
|
236
|
-
if (isAsyncIteratorObject(data)) {
|
|
237
|
-
return mapEventIterator(data, {
|
|
238
|
-
value: async (value) => value,
|
|
239
|
-
error: async (e) => {
|
|
240
|
-
if (e instanceof ErrorEvent && isORPCErrorJson(e.data)) {
|
|
241
|
-
return createORPCErrorFromJson(e.data, { cause: e });
|
|
242
|
-
}
|
|
243
|
-
return e;
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
return data;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function standardizeHTTPPath(path) {
|
|
252
|
-
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
253
|
-
}
|
|
254
|
-
function getDynamicParams(path) {
|
|
255
|
-
return path ? standardizeHTTPPath(path).match(/\/\{[^}]+\}/g)?.map((v) => ({
|
|
256
|
-
raw: v,
|
|
257
|
-
name: v.match(/\{\+?([^}]+)\}/)[1]
|
|
258
|
-
})) : void 0;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export { StandardBracketNotationSerializer as S, StandardOpenAPISerializer as a, StandardOpenAPIJsonSerializer as b, getDynamicParams as g, standardizeHTTPPath as s };
|