@temporary-name/server 1.9.3-alpha.8dcf0da5d97e7b89ab5ce50c8d1733c158e629a8 → 1.9.3-alpha.907c7c78d0193d34752279de92d699e50d6bc3a1

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.
Files changed (42) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +4 -6
  2. package/dist/adapters/aws-lambda/index.d.ts +4 -6
  3. package/dist/adapters/aws-lambda/index.mjs +4 -4
  4. package/dist/adapters/fetch/index.d.mts +8 -86
  5. package/dist/adapters/fetch/index.d.ts +8 -86
  6. package/dist/adapters/fetch/index.mjs +16 -155
  7. package/dist/adapters/node/index.d.mts +8 -63
  8. package/dist/adapters/node/index.d.ts +8 -63
  9. package/dist/adapters/node/index.mjs +14 -120
  10. package/dist/adapters/standard/index.d.mts +5 -7
  11. package/dist/adapters/standard/index.d.ts +5 -7
  12. package/dist/adapters/standard/index.mjs +4 -4
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +104 -182
  15. package/dist/index.d.ts +104 -182
  16. package/dist/index.mjs +126 -104
  17. package/dist/openapi/index.d.mts +11 -27
  18. package/dist/openapi/index.d.ts +11 -27
  19. package/dist/openapi/index.mjs +8 -75
  20. package/dist/shared/server.Bj_UpI5O.d.mts +372 -0
  21. package/dist/shared/server.Bj_UpI5O.d.ts +372 -0
  22. package/dist/shared/server.C1RJffw4.mjs +30 -0
  23. package/dist/shared/server.C6VnFy4S.d.mts +41 -0
  24. package/dist/shared/server.CQIFwyhc.mjs +40 -0
  25. package/dist/shared/server.ChOv1yG3.mjs +319 -0
  26. package/dist/shared/server.CnzXkSjj.d.ts +41 -0
  27. package/dist/shared/server.DXzEGRE2.mjs +403 -0
  28. package/dist/shared/server.DgzAlPjF.mjs +160 -0
  29. package/dist/shared/server.YUvuxHty.mjs +48 -0
  30. package/package.json +10 -27
  31. package/dist/plugins/index.d.mts +0 -160
  32. package/dist/plugins/index.d.ts +0 -160
  33. package/dist/plugins/index.mjs +0 -288
  34. package/dist/shared/server.BSJugGGA.d.mts +0 -56
  35. package/dist/shared/server.Bs8EZATl.d.ts +0 -23
  36. package/dist/shared/server.CHV9AQHl.mjs +0 -412
  37. package/dist/shared/server.CWWP8ypC.d.mts +0 -239
  38. package/dist/shared/server.CWWP8ypC.d.ts +0 -239
  39. package/dist/shared/server.Cn7WsRHl.mjs +0 -254
  40. package/dist/shared/server.DrMgIiBr.d.mts +0 -23
  41. package/dist/shared/server.EKwDe0d2.d.ts +0 -56
  42. package/dist/shared/server.JtIZ8YG7.mjs +0 -237
@@ -1,237 +0,0 @@
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
- export { bracketNotationDeserialize as b, deserialize as d, jsonSerialize as j, serialize as s };