@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
|
@@ -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.Bzrdopnd.js';
|
|
3
|
+
import { c as StandardHandleOptions } from './server.B9i6p26R.js';
|
|
4
4
|
|
|
5
5
|
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
6
6
|
context?: T;
|
|
@@ -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.Bzrdopnd.mjs';
|
|
3
|
+
import { c as StandardHandleOptions } from './server.C-j2WKJz.mjs';
|
|
4
4
|
|
|
5
5
|
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
6
6
|
context?: T;
|
|
@@ -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
|
-
import { c as createProcedureClient } from './server.
|
|
4
|
-
import { s as standardizeHTTPPath, S as StandardBracketNotationSerializer, a as StandardOpenAPISerializer, b as StandardOpenAPIJsonSerializer } from './server.DhdDYN-Z.mjs';
|
|
3
|
+
import { c as createProcedureClient } from './server.NLSomL7m.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);
|
|
@@ -1,39 +1,7 @@
|
|
|
1
1
|
import { validateORPCError, ValidationError } from '@temporary-name/contract';
|
|
2
2
|
import { resolveMaybeOptionalOptions, ORPCError, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
|
|
3
3
|
import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
|
|
4
|
-
import {
|
|
5
|
-
import 'zod';
|
|
6
|
-
import * as z4 from 'zod/v4/core';
|
|
7
|
-
|
|
8
|
-
const gatingContext = new AsyncLocalStorage();
|
|
9
|
-
function withoutGatedFields(data, schema, isGateEnabled) {
|
|
10
|
-
const filtered = { ...data };
|
|
11
|
-
const gatedFields = getGatedFields(schema);
|
|
12
|
-
for (const [fieldName, gate] of gatedFields) {
|
|
13
|
-
if (!isGateEnabled(gate)) {
|
|
14
|
-
delete filtered[fieldName];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return filtered;
|
|
18
|
-
}
|
|
19
|
-
function getGatedFields(schema) {
|
|
20
|
-
if (!schema || schema["~standard"].vendor !== "zod") {
|
|
21
|
-
return [];
|
|
22
|
-
}
|
|
23
|
-
const gatedFields = [];
|
|
24
|
-
const zodDef = schema._zod.def;
|
|
25
|
-
if (zodDef.type === "object") {
|
|
26
|
-
const shape = zodDef.shape;
|
|
27
|
-
for (const fieldName in shape) {
|
|
28
|
-
const fieldSchema = shape[fieldName];
|
|
29
|
-
const gate = z4.globalRegistry.get(fieldSchema)?.gate;
|
|
30
|
-
if (gate) {
|
|
31
|
-
gatedFields.push([fieldName, gate]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return gatedFields;
|
|
36
|
-
}
|
|
4
|
+
import { safeDecodeAsync, safeEncodeAsync } from '@temporary-name/zod';
|
|
37
5
|
|
|
38
6
|
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
|
|
39
7
|
function lazy(loader, meta = {}) {
|
|
@@ -147,37 +115,41 @@ async function validateInput(procedure, input) {
|
|
|
147
115
|
return input;
|
|
148
116
|
}
|
|
149
117
|
return runWithSpan({ name: "validate_input" }, async () => {
|
|
150
|
-
const result = await schema
|
|
151
|
-
if (result.
|
|
118
|
+
const result = await safeDecodeAsync(schema, input);
|
|
119
|
+
if (!result.success) {
|
|
152
120
|
throw new ORPCError("BAD_REQUEST", {
|
|
153
121
|
message: "Input validation failed",
|
|
154
122
|
data: {
|
|
155
|
-
issues: result.issues
|
|
123
|
+
issues: result.error.issues
|
|
156
124
|
},
|
|
157
125
|
cause: new ValidationError({
|
|
158
126
|
message: "Input validation failed",
|
|
159
|
-
issues: result.issues,
|
|
127
|
+
issues: result.error.issues,
|
|
160
128
|
data: input
|
|
161
129
|
})
|
|
162
130
|
});
|
|
163
131
|
}
|
|
164
|
-
return result.
|
|
132
|
+
return result.data;
|
|
165
133
|
});
|
|
166
134
|
}
|
|
167
|
-
async function validateOutput(
|
|
135
|
+
async function validateOutput(procedure, output) {
|
|
136
|
+
const schema = procedure["~orpc"].outputSchema;
|
|
137
|
+
if (!schema) {
|
|
138
|
+
return output;
|
|
139
|
+
}
|
|
168
140
|
return runWithSpan({ name: "validate_output" }, async () => {
|
|
169
|
-
const result = await schema
|
|
170
|
-
if (result.
|
|
141
|
+
const result = await safeEncodeAsync(schema, output);
|
|
142
|
+
if (!result.success) {
|
|
171
143
|
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
172
144
|
message: "Output validation failed",
|
|
173
145
|
cause: new ValidationError({
|
|
174
146
|
message: "Output validation failed",
|
|
175
|
-
issues: result.issues,
|
|
147
|
+
issues: result.error.issues,
|
|
176
148
|
data: output
|
|
177
149
|
})
|
|
178
150
|
});
|
|
179
151
|
}
|
|
180
|
-
return result.
|
|
152
|
+
return result.data;
|
|
181
153
|
});
|
|
182
154
|
}
|
|
183
155
|
async function executeProcedureInternal(procedure, options) {
|
|
@@ -220,20 +192,11 @@ async function executeProcedureInternal(procedure, options) {
|
|
|
220
192
|
() => procedure["~orpc"].handler({ ...options, context, input: currentInput })
|
|
221
193
|
);
|
|
222
194
|
if (index === outputValidationIndex) {
|
|
223
|
-
|
|
224
|
-
if (!schema) {
|
|
225
|
-
return output;
|
|
226
|
-
}
|
|
227
|
-
const validated = await validateOutput(schema, output);
|
|
228
|
-
const isGateEnabled = gatingContext.getStore();
|
|
229
|
-
if (!validated || !isGateEnabled) {
|
|
230
|
-
return validated;
|
|
231
|
-
}
|
|
232
|
-
return withoutGatedFields(validated, schema, isGateEnabled);
|
|
195
|
+
return await validateOutput(procedure, output);
|
|
233
196
|
}
|
|
234
197
|
return output;
|
|
235
198
|
};
|
|
236
199
|
return next(0, options.context, options.input);
|
|
237
200
|
}
|
|
238
201
|
|
|
239
|
-
export { LAZY_SYMBOL as L,
|
|
202
|
+
export { LAZY_SYMBOL as L, createORPCErrorConstructorMap as a, middlewareOutputFn as b, createProcedureClient as c, getLazyMeta as g, isLazy as i, lazy as l, mergeCurrentContext as m, unlazy as u };
|
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.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.stainless.com/",
|
|
7
7
|
"repository": {
|
|
@@ -71,16 +71,17 @@
|
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"cookie": "^1.0.2",
|
|
74
|
-
"@standard-schema/spec": "^1.0.0",
|
|
75
74
|
"rou3": "^0.7.7",
|
|
76
75
|
"zod": "^4.1.12",
|
|
77
|
-
"@temporary-name/
|
|
78
|
-
"@temporary-name/
|
|
79
|
-
"@temporary-name/
|
|
80
|
-
"@temporary-name/
|
|
81
|
-
"@temporary-name/standard-server
|
|
82
|
-
"@temporary-name/standard-server-
|
|
83
|
-
"@temporary-name/
|
|
76
|
+
"@temporary-name/interop": "1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b",
|
|
77
|
+
"@temporary-name/contract": "1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b",
|
|
78
|
+
"@temporary-name/json-schema": "1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b",
|
|
79
|
+
"@temporary-name/shared": "1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b",
|
|
80
|
+
"@temporary-name/standard-server": "1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b",
|
|
81
|
+
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b",
|
|
82
|
+
"@temporary-name/zod": "1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b",
|
|
83
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b",
|
|
84
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b"
|
|
84
85
|
},
|
|
85
86
|
"devDependencies": {
|
|
86
87
|
"@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 };
|