seroval 0.15.1 → 1.0.0

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 (114) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/development/index.cjs +1221 -1867
  3. package/dist/cjs/development/index.cjs.map +3 -3
  4. package/dist/cjs/production/index.cjs +3 -3
  5. package/dist/esm/development/index.mjs +1222 -1868
  6. package/dist/esm/development/index.mjs.map +3 -3
  7. package/dist/esm/production/index.mjs +3 -3
  8. package/dist/types/core/Serializer.d.ts +2 -1
  9. package/dist/types/core/Serializer.d.ts.map +1 -1
  10. package/dist/types/core/UnsupportedTypeError.d.ts.map +1 -1
  11. package/dist/types/core/base-primitives.d.ts +6 -2
  12. package/dist/types/core/base-primitives.d.ts.map +1 -1
  13. package/dist/types/core/compat.d.ts +5 -13
  14. package/dist/types/core/compat.d.ts.map +1 -1
  15. package/dist/types/core/constants.d.ts +17 -29
  16. package/dist/types/core/constants.d.ts.map +1 -1
  17. package/dist/types/core/context/deserializer.d.ts +6 -16
  18. package/dist/types/core/context/deserializer.d.ts.map +1 -1
  19. package/dist/types/core/context/parser/async.d.ts +2 -11
  20. package/dist/types/core/context/parser/async.d.ts.map +1 -1
  21. package/dist/types/core/context/parser/stream.d.ts +10 -10
  22. package/dist/types/core/context/parser/stream.d.ts.map +1 -1
  23. package/dist/types/core/context/parser/sync.d.ts +5 -7
  24. package/dist/types/core/context/parser/sync.d.ts.map +1 -1
  25. package/dist/types/core/context/parser.d.ts +19 -4
  26. package/dist/types/core/context/parser.d.ts.map +1 -1
  27. package/dist/types/core/context/serializer.d.ts +11 -25
  28. package/dist/types/core/context/serializer.d.ts.map +1 -1
  29. package/dist/types/core/cross/async.d.ts.map +1 -1
  30. package/dist/types/core/cross/deserializer.d.ts.map +1 -1
  31. package/dist/types/core/cross/index.d.ts.map +1 -1
  32. package/dist/types/core/cross/parser.d.ts.map +1 -1
  33. package/dist/types/core/cross/serializer.d.ts +1 -1
  34. package/dist/types/core/cross/serializer.d.ts.map +1 -1
  35. package/dist/types/core/cross/stream.d.ts.map +1 -1
  36. package/dist/types/core/cross/sync.d.ts.map +1 -1
  37. package/dist/types/core/keys.d.ts.map +1 -1
  38. package/dist/types/core/literals.d.ts.map +1 -1
  39. package/dist/types/core/plugin.d.ts +21 -0
  40. package/dist/types/core/plugin.d.ts.map +1 -1
  41. package/dist/types/core/reference.d.ts.map +1 -1
  42. package/dist/types/core/special-reference.d.ts +4 -9
  43. package/dist/types/core/special-reference.d.ts.map +1 -1
  44. package/dist/types/core/stream.d.ts +18 -0
  45. package/dist/types/core/stream.d.ts.map +1 -0
  46. package/dist/types/core/string.d.ts.map +1 -1
  47. package/dist/types/core/tree/async.d.ts.map +1 -1
  48. package/dist/types/core/tree/deserializer.d.ts.map +1 -1
  49. package/dist/types/core/tree/index.d.ts +1 -1
  50. package/dist/types/core/tree/index.d.ts.map +1 -1
  51. package/dist/types/core/tree/serializer.d.ts +3 -11
  52. package/dist/types/core/tree/serializer.d.ts.map +1 -1
  53. package/dist/types/core/types.d.ts +28 -122
  54. package/dist/types/core/types.d.ts.map +1 -1
  55. package/dist/types/core/utils/deferred.d.ts +0 -7
  56. package/dist/types/core/utils/deferred.d.ts.map +1 -1
  57. package/dist/types/core/utils/error.d.ts +2 -1
  58. package/dist/types/core/utils/error.d.ts.map +1 -1
  59. package/dist/types/core/utils/get-identifier.d.ts.map +1 -1
  60. package/dist/types/core/utils/is-valid-identifier.d.ts.map +1 -1
  61. package/dist/types/core/utils/iterator-to-sequence.d.ts +0 -12
  62. package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -1
  63. package/dist/types/core/utils/typed-array.d.ts +2 -0
  64. package/dist/types/core/utils/typed-array.d.ts.map +1 -1
  65. package/dist/types/index.d.ts +2 -3
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/package.json +7 -7
  68. package/src/core/Serializer.ts +44 -28
  69. package/src/core/UnsupportedTypeError.ts +2 -3
  70. package/src/core/base-primitives.ts +124 -38
  71. package/src/core/compat.ts +5 -14
  72. package/src/core/constants.ts +28 -39
  73. package/src/core/context/deserializer.ts +122 -308
  74. package/src/core/context/parser/async.ts +163 -375
  75. package/src/core/context/parser/stream.ts +109 -367
  76. package/src/core/context/parser/sync.ts +139 -266
  77. package/src/core/context/parser.ts +93 -68
  78. package/src/core/context/serializer.ts +370 -439
  79. package/src/core/cross/async.ts +1 -1
  80. package/src/core/cross/deserializer.ts +1 -4
  81. package/src/core/cross/index.ts +26 -20
  82. package/src/core/cross/parser.ts +1 -1
  83. package/src/core/cross/serializer.ts +30 -20
  84. package/src/core/cross/stream.ts +1 -1
  85. package/src/core/cross/sync.ts +1 -1
  86. package/src/core/keys.ts +3 -1
  87. package/src/core/literals.ts +22 -8
  88. package/src/core/plugin.ts +48 -10
  89. package/src/core/reference.ts +4 -5
  90. package/src/core/special-reference.ts +5 -15
  91. package/src/core/stream.ts +205 -0
  92. package/src/core/string.ts +53 -22
  93. package/src/core/tree/async.ts +1 -1
  94. package/src/core/tree/deserializer.ts +4 -9
  95. package/src/core/tree/index.ts +15 -10
  96. package/src/core/tree/serializer.ts +6 -50
  97. package/src/core/types.ts +39 -179
  98. package/src/core/utils/deferred.ts +0 -27
  99. package/src/core/utils/error.ts +26 -15
  100. package/src/core/utils/get-identifier.ts +5 -4
  101. package/src/core/utils/is-valid-identifier.ts +6 -5
  102. package/src/core/utils/iterator-to-sequence.ts +0 -174
  103. package/src/core/utils/typed-array.ts +35 -11
  104. package/src/index.ts +3 -12
  105. package/dist/types/core/utils/constructors.d.ts +0 -5
  106. package/dist/types/core/utils/constructors.d.ts.map +0 -1
  107. package/dist/types/core/web-api.d.ts +0 -8
  108. package/dist/types/core/web-api.d.ts.map +0 -1
  109. package/dist/types/types.d.ts +0 -21
  110. package/dist/types/types.d.ts.map +0 -1
  111. package/src/core/utils/constructors.ts +0 -49
  112. package/src/core/web-api.ts +0 -138
  113. package/src/example.ts +0 -25
  114. package/src/types.ts +0 -84
@@ -1,11 +1,15 @@
1
- import type {
2
- ErrorValue,
3
- } from '../../types';
4
1
  import { Feature } from '../compat';
5
- import {
6
- ERROR_CONSTRUCTOR_STRING,
7
- ErrorConstructorTag,
8
- } from '../constants';
2
+ import { ERROR_CONSTRUCTOR_STRING, ErrorConstructorTag } from '../constants';
3
+
4
+ type ErrorValue =
5
+ | Error
6
+ | AggregateError
7
+ | EvalError
8
+ | RangeError
9
+ | ReferenceError
10
+ | TypeError
11
+ | SyntaxError
12
+ | URIError;
9
13
 
10
14
  export function getErrorConstructor(error: ErrorValue): ErrorConstructorTag {
11
15
  if (error instanceof EvalError) {
@@ -29,20 +33,27 @@ export function getErrorConstructor(error: ErrorValue): ErrorConstructorTag {
29
33
  return ErrorConstructorTag.Error;
30
34
  }
31
35
 
32
- export function getErrorOptions(
36
+ function getInitialErrorOptions(
33
37
  error: Error,
34
- features: number,
35
38
  ): Record<string, unknown> | undefined {
36
- let options: Record<string, unknown> | undefined;
37
- const constructor = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
39
+ const construct = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
38
40
  // Name has been modified
39
- if (error.name !== constructor) {
40
- options = { name: error.name };
41
- } else if (error.constructor.name !== constructor) {
41
+ if (error.name !== construct) {
42
+ return { name: error.name };
43
+ }
44
+ if (error.constructor.name !== construct) {
42
45
  // Otherwise, name is overriden because
43
46
  // the Error class is extended
44
- options = { name: error.constructor.name };
47
+ return { name: error.constructor.name };
45
48
  }
49
+ return {};
50
+ }
51
+
52
+ export function getErrorOptions(
53
+ error: Error,
54
+ features: number,
55
+ ): Record<string, unknown> | undefined {
56
+ let options = getInitialErrorOptions(error);
46
57
  const names = Object.getOwnPropertyNames(error);
47
58
  for (let i = 0, len = names.length, name: string; i < len; i++) {
48
59
  name = names[i];
@@ -1,8 +1,9 @@
1
1
  // Written by https://github.com/DylanPiercey and is distributed under the MIT license.
2
- const REF_START_CHARS = 'hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_'; // Avoids chars that could evaluate to a reserved word.
3
- const REF_START_CHARS_LEN = REF_START_CHARS.length;
4
- const REF_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_';
5
- const REF_CHARS_LEN = REF_CHARS.length;
2
+ const REF_START_CHARS = /* @__PURE__ */ 'hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_'; // Avoids chars that could evaluate to a reserved word.
3
+ const REF_START_CHARS_LEN = /* @__PURE__ */ REF_START_CHARS.length;
4
+ const REF_CHARS =
5
+ /* @__PURE__ */ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_';
6
+ const REF_CHARS_LEN = /* @__PURE__ */ REF_CHARS.length;
6
7
 
7
8
  export default function getIdentifier(index: number): string {
8
9
  let mod = index % REF_START_CHARS_LEN;
@@ -3,9 +3,10 @@ const IDENTIFIER_CHECK = /^[$A-Z_][0-9A-Z_$]*$/i;
3
3
  export function isValidIdentifier(name: string): boolean {
4
4
  const char = name[0];
5
5
  return (
6
- char === '$'
7
- || char === '_'
8
- || (char >= 'A' && char <= 'Z')
9
- || (char >= 'a' && char <= 'z')
10
- ) && IDENTIFIER_CHECK.test(name);
6
+ (char === '$' ||
7
+ char === '_' ||
8
+ (char >= 'A' && char <= 'Z') ||
9
+ (char >= 'a' && char <= 'z')) &&
10
+ IDENTIFIER_CHECK.test(name)
11
+ );
11
12
  }
@@ -1,6 +1,3 @@
1
- import type BaseStreamParserContext from '../context/parser/stream';
2
-
3
- /* eslint-disable no-await-in-loop */
4
1
  export interface Sequence {
5
2
  v: unknown[];
6
3
  t: number;
@@ -65,174 +62,3 @@ export function sequenceToIterator<T>(
65
62
  };
66
63
  };
67
64
  }
68
-
69
- export async function asyncIteratorToSequence<T>(source: AsyncIterable<T>): Promise<Sequence> {
70
- const values: unknown[] = [];
71
- let throwsAt = -1;
72
- let doneAt = -1;
73
-
74
- const iterator = source[Symbol.asyncIterator]();
75
-
76
- while (true) {
77
- try {
78
- const value = await iterator.next();
79
- values.push(value.value);
80
- if (value.done) {
81
- doneAt = values.length - 1;
82
- break;
83
- }
84
- } catch (error) {
85
- throwsAt = values.length;
86
- values.push(error);
87
- }
88
- }
89
-
90
- return {
91
- v: values,
92
- t: throwsAt,
93
- d: doneAt,
94
- };
95
- }
96
-
97
- export function sequenceToAsyncIterator<T>(
98
- sequence: Sequence,
99
- ): () => AsyncIterableIterator<T> {
100
- return (): AsyncIterableIterator<T> => {
101
- let index = 0;
102
- return {
103
- [Symbol.asyncIterator](): AsyncIterableIterator<T> {
104
- return this;
105
- },
106
- async next(): Promise<IteratorResult<T>> {
107
- if (index > sequence.d) {
108
- return {
109
- done: true,
110
- value: undefined,
111
- };
112
- }
113
- const currentIndex = index++;
114
- const currentItem = sequence.v[currentIndex];
115
- if (currentIndex === sequence.t) {
116
- throw currentItem;
117
- }
118
- return Promise.resolve({
119
- done: currentIndex === sequence.d,
120
- value: currentItem as T,
121
- });
122
- },
123
- };
124
- };
125
- }
126
-
127
- export function asyncIteratorToReadableStream<T>(
128
- source: AsyncIterable<T>,
129
- parser: BaseStreamParserContext,
130
- ): ReadableStream<unknown> {
131
- return new ReadableStream({
132
- async start(controller): Promise<void> {
133
- const iterator = source[Symbol.asyncIterator]();
134
- while (parser.isAlive()) {
135
- try {
136
- const result = await iterator.next();
137
- controller.enqueue([result.done ? 2 : 0, result.value]);
138
- if (result.done) {
139
- controller.close();
140
- return;
141
- }
142
- } catch (error) {
143
- controller.enqueue([1, error]);
144
- }
145
- }
146
- controller.close();
147
- },
148
- });
149
- }
150
-
151
- type RSNext<T> = [0, T];
152
- type RSThrow = [1, any];
153
- type RSReturn<T> = [2, T];
154
-
155
- export type SerializedAsyncIteratorResult<T> = RSNext<T> | RSThrow | RSReturn<T>;
156
-
157
- export function readableStreamToAsyncIterator<T>(
158
- source: ReadableStream<SerializedAsyncIteratorResult<T>>,
159
- ): () => AsyncIterableIterator<T> {
160
- let current = source;
161
- return (): AsyncIterableIterator<T> => {
162
- const [left, right] = current.tee();
163
- const clone = left;
164
- current = right;
165
- const reader = clone.getReader();
166
- return {
167
- [Symbol.asyncIterator](): AsyncIterableIterator<T> {
168
- return this;
169
- },
170
- async next(): Promise<IteratorResult<T>> {
171
- const result = await reader.read();
172
- if (result.done) {
173
- return {
174
- done: true,
175
- value: undefined,
176
- };
177
- }
178
- const [status, value] = result.value;
179
- if (status === 1) {
180
- throw value;
181
- }
182
- return {
183
- done: status === 2,
184
- value,
185
- };
186
- },
187
- };
188
- };
189
- }
190
-
191
- export async function readableStreamToSequence<T>(
192
- stream: ReadableStream<T>,
193
- ): Promise<Sequence> {
194
- const values: unknown[] = [];
195
- let throwsAt = -1;
196
- let doneAt = -1;
197
-
198
- const iterator = stream.getReader();
199
-
200
- while (true) {
201
- try {
202
- const value = await iterator.read();
203
- values.push(value.value);
204
- if (value.done) {
205
- doneAt = values.length - 1;
206
- break;
207
- }
208
- } catch (error) {
209
- throwsAt = values.length;
210
- doneAt = throwsAt;
211
- values.push(error);
212
- break;
213
- }
214
- }
215
-
216
- return {
217
- v: values,
218
- t: throwsAt,
219
- d: doneAt,
220
- };
221
- }
222
-
223
- export function sequenceToReadableStream<T>(
224
- sequence: Sequence,
225
- ): ReadableStream<T> {
226
- return new ReadableStream<T>({
227
- start(controller): void {
228
- for (let i = 0; i < sequence.d; i++) {
229
- controller.enqueue(sequence.v[i] as T);
230
- }
231
- if (sequence.t === -1) {
232
- controller.close();
233
- } else {
234
- controller.error(sequence.v[sequence.t] as T);
235
- }
236
- },
237
- });
238
- }
@@ -11,19 +11,43 @@ type TypedArrayConstructor =
11
11
  | BigInt64ArrayConstructor
12
12
  | BigUint64ArrayConstructor;
13
13
 
14
+ export type TypedArrayValue =
15
+ | Int8Array
16
+ | Int16Array
17
+ | Int32Array
18
+ | Uint8Array
19
+ | Uint16Array
20
+ | Uint32Array
21
+ | Uint8ClampedArray
22
+ | Float32Array
23
+ | Float64Array;
24
+
25
+ export type BigIntTypedArrayValue = BigInt64Array | BigUint64Array;
26
+
14
27
  export function getTypedArrayConstructor(name: string): TypedArrayConstructor {
15
28
  switch (name) {
16
- case 'Int8Array': return Int8Array;
17
- case 'Int16Array': return Int16Array;
18
- case 'Int32Array': return Int32Array;
19
- case 'Uint8Array': return Uint8Array;
20
- case 'Uint16Array': return Uint16Array;
21
- case 'Uint32Array': return Uint32Array;
22
- case 'Uint8ClampedArray': return Uint8ClampedArray;
23
- case 'Float32Array': return Float32Array;
24
- case 'Float64Array': return Float64Array;
25
- case 'BigInt64Array': return BigInt64Array;
26
- case 'BigUint64Array': return BigUint64Array;
29
+ case 'Int8Array':
30
+ return Int8Array;
31
+ case 'Int16Array':
32
+ return Int16Array;
33
+ case 'Int32Array':
34
+ return Int32Array;
35
+ case 'Uint8Array':
36
+ return Uint8Array;
37
+ case 'Uint16Array':
38
+ return Uint16Array;
39
+ case 'Uint32Array':
40
+ return Uint32Array;
41
+ case 'Uint8ClampedArray':
42
+ return Uint8ClampedArray;
43
+ case 'Float32Array':
44
+ return Float32Array;
45
+ case 'Float64Array':
46
+ return Float64Array;
47
+ case 'BigInt64Array':
48
+ return BigInt64Array;
49
+ case 'BigUint64Array':
50
+ return BigUint64Array;
27
51
  default:
28
52
  throw new Error(`Unknown TypedArray "${name}"`);
29
53
  }
package/src/index.ts CHANGED
@@ -1,13 +1,3 @@
1
- import { serialize } from './core/tree';
2
-
3
- export type {
4
- AsyncServerValue,
5
- ServerValue,
6
- PrimitiveValue,
7
- CommonServerValue,
8
- SemiPrimitiveValue,
9
- ErrorValue,
10
- } from './types';
11
1
  export { Feature } from './core/compat';
12
2
  export { createReference } from './core/reference';
13
3
 
@@ -19,6 +9,7 @@ export { getCrossReferenceHeader } from './core/keys';
19
9
  export { default as Serializer } from './core/Serializer';
20
10
  export * from './core/plugin';
21
11
 
22
- export type { SerovalNode } from './core/types';
12
+ export type { Stream } from './core/stream';
13
+ export { createStream } from './core/stream';
23
14
 
24
- export default serialize;
15
+ export type { SerovalNode } from './core/types';
@@ -1,5 +0,0 @@
1
- export declare function createRequestOptions(current: Request, body: ArrayBuffer | ReadableStream | null): RequestInit;
2
- export declare function createResponseOptions(current: Response): ResponseInit;
3
- export declare function createEventOptions(current: Event): EventInit;
4
- export declare function createCustomEventOptions(current: CustomEvent): CustomEventInit;
5
- //# sourceMappingURL=constructors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constructors.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/constructors.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,WAAW,GAAG,cAAc,GAAG,IAAI,GACxC,WAAW,CAcb;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,QAAQ,GAChB,YAAY,CAMd;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,KAAK,GACb,SAAS,CAMX;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,WAAW,GACnB,eAAe,CAOjB"}
@@ -1,8 +0,0 @@
1
- import type { SerovalCustomEventNode, SerovalDOMExceptionNode, SerovalEventNode, SerovalNode, SerovalNodeWithID, SerovalReadableStreamNode, SerovalURLNode, SerovalURLSearchParamsNode } from './types';
2
- export declare function createURLNode(id: number, current: URL): SerovalURLNode;
3
- export declare function createURLSearchParamsNode(id: number, current: URLSearchParams): SerovalURLSearchParamsNode;
4
- export declare function createDOMExceptionNode(id: number, current: DOMException): SerovalDOMExceptionNode;
5
- export declare function createEventNode(id: number, type: string, options: SerovalNode): SerovalEventNode;
6
- export declare function createCustomEventNode(id: number, type: string, options: SerovalNode): SerovalCustomEventNode;
7
- export declare function createReadableStreamNode(id: number, factory: SerovalNodeWithID, items: SerovalNode): SerovalReadableStreamNode;
8
- //# sourceMappingURL=web-api.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-api.d.ts","sourceRoot":"","sources":["../../../src/core/web-api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,yBAAyB,EACzB,cAAc,EACd,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAEjB,wBAAgB,aAAa,CAC3B,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,GAAG,GACX,cAAc,CAehB;AAED,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,eAAe,GACvB,0BAA0B,CAe5B;AAED,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,YAAY,GACpB,uBAAuB,CAezB;AAED,wBAAgB,eAAe,CAC7B,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,WAAW,GACnB,gBAAgB,CAelB;AAED,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,WAAW,GACnB,sBAAsB,CAexB;AAED,wBAAgB,wBAAwB,CACtC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,iBAAiB,EAC1B,KAAK,EAAE,WAAW,GACjB,yBAAyB,CAkB3B"}
@@ -1,21 +0,0 @@
1
- import type { WellKnownSymbols } from './core/constants';
2
- export type PrimitiveValue = boolean | string | number | undefined | null | WellKnownSymbols;
3
- export type ErrorValue = Error | AggregateError | EvalError | RangeError | ReferenceError | TypeError | SyntaxError | URIError;
4
- export type TypedArrayValue = Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array;
5
- export type BigIntTypedArrayValue = BigInt64Array | BigUint64Array;
6
- export type WebAPIValue = URL | URLSearchParams | Blob | File;
7
- export type SemiPrimitiveValue = RegExp | Date | ArrayBuffer | DataView | TypedArrayValue | BigIntTypedArrayValue | bigint | WebAPIValue;
8
- export type CommonServerValue = PrimitiveValue | SemiPrimitiveValue | ErrorValue;
9
- export type ServerValue = CommonServerValue | Array<ServerValue> | readonly ServerValue[] | Iterable<ServerValue> | {
10
- [key: string | number]: ServerValue;
11
- } | {
12
- readonly [key: string | number]: ServerValue;
13
- } | Set<ServerValue> | Map<ServerValue, ServerValue>;
14
- export type AsyncServerValue = CommonServerValue | Array<AsyncServerValue> | readonly AsyncServerValue[] | Iterable<AsyncServerValue> | {
15
- [key: string | number]: AsyncServerValue;
16
- } | {
17
- readonly [key: string | number]: AsyncServerValue;
18
- } | Set<AsyncServerValue> | Map<AsyncServerValue, AsyncServerValue> | Promise<AsyncServerValue>;
19
- export type NonPrimitiveServerValue<T> = T extends PrimitiveValue ? never : T;
20
- export type MaybePromise<T> = T | Promise<T>;
21
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,MAAM,GACN,MAAM,GACN,SAAS,GACT,IAAI,GACJ,gBAAgB,CAAC;AAErB,MAAM,MAAM,UAAU,GAClB,KAAK,GACL,cAAc,GACd,SAAS,GACT,UAAU,GACV,cAAc,GACd,SAAS,GACT,WAAW,GACX,QAAQ,CAAC;AAEb,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,UAAU,GACV,UAAU,GACV,UAAU,GACV,WAAW,GACX,WAAW,GACX,iBAAiB,GACjB,YAAY,GACZ,YAAY,CAAC;AAEjB,MAAM,MAAM,qBAAqB,GAC7B,aAAa,GACb,cAAc,CAAC;AAEnB,MAAM,MAAM,WAAW,GACnB,GAAG,GACH,eAAe,GACf,IAAI,GACJ,IAAI,CAAC;AAET,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,IAAI,GACJ,WAAW,GACX,QAAQ,GACR,eAAe,GACf,qBAAqB,GACrB,MAAM,GACN,WAAW,CAAC;AAEhB,MAAM,MAAM,iBAAiB,GACzB,cAAc,GACd,kBAAkB,GAClB,UAAU,CAAC;AAEf,MAAM,MAAM,WAAW,GACnB,iBAAiB,GACjB,KAAK,CAAC,WAAW,CAAC,GAClB,SAAS,WAAW,EAAE,GACtB,QAAQ,CAAC,WAAW,CAAC,GACrB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,WAAW,CAAA;CAAE,GACvC;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,WAAW,CAAA;CAAE,GAChD,GAAG,CAAC,WAAW,CAAC,GAChB,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAElC,MAAM,MAAM,gBAAgB,GACxB,iBAAiB,GACjB,KAAK,CAAC,gBAAgB,CAAC,GACvB,SAAS,gBAAgB,EAAE,GAC3B,QAAQ,CAAC,gBAAgB,CAAC,GAC1B;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,gBAAgB,CAAA;CAAE,GAC5C;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,gBAAgB,CAAA;CAAE,GACrD,GAAG,CAAC,gBAAgB,CAAC,GACrB,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,GACvC,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE9B,MAAM,MAAM,uBAAuB,CAAC,CAAC,IACnC,CAAC,SAAS,cAAc,GACpB,KAAK,GACL,CAAC,CAAC;AAER,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC"}
@@ -1,49 +0,0 @@
1
- export function createRequestOptions(
2
- current: Request,
3
- body: ArrayBuffer | ReadableStream | null,
4
- ): RequestInit {
5
- return {
6
- body,
7
- cache: current.cache,
8
- credentials: current.credentials,
9
- headers: current.headers,
10
- integrity: current.integrity,
11
- keepalive: current.keepalive,
12
- method: current.method,
13
- mode: current.mode,
14
- redirect: current.redirect,
15
- referrer: current.referrer,
16
- referrerPolicy: current.referrerPolicy,
17
- };
18
- }
19
-
20
- export function createResponseOptions(
21
- current: Response,
22
- ): ResponseInit {
23
- return {
24
- headers: current.headers,
25
- status: current.status,
26
- statusText: current.statusText,
27
- };
28
- }
29
-
30
- export function createEventOptions(
31
- current: Event,
32
- ): EventInit {
33
- return {
34
- bubbles: current.bubbles,
35
- cancelable: current.cancelable,
36
- composed: current.composed,
37
- };
38
- }
39
-
40
- export function createCustomEventOptions(
41
- current: CustomEvent,
42
- ): CustomEventInit {
43
- return {
44
- detail: current.detail as unknown,
45
- bubbles: current.bubbles,
46
- cancelable: current.cancelable,
47
- composed: current.composed,
48
- };
49
- }
@@ -1,138 +0,0 @@
1
- import { SerovalNodeType } from './constants';
2
- import { serializeString } from './string';
3
- import type {
4
- SerovalCustomEventNode,
5
- SerovalDOMExceptionNode,
6
- SerovalEventNode,
7
- SerovalNode,
8
- SerovalNodeWithID,
9
- SerovalReadableStreamNode,
10
- SerovalURLNode,
11
- SerovalURLSearchParamsNode,
12
- } from './types';
13
-
14
- export function createURLNode(
15
- id: number,
16
- current: URL,
17
- ): SerovalURLNode {
18
- return {
19
- t: SerovalNodeType.URL,
20
- i: id,
21
- s: serializeString(current.href),
22
- l: undefined,
23
- c: undefined,
24
- m: undefined,
25
- p: undefined,
26
- e: undefined,
27
- f: undefined,
28
- a: undefined,
29
- b: undefined,
30
- o: undefined,
31
- };
32
- }
33
-
34
- export function createURLSearchParamsNode(
35
- id: number,
36
- current: URLSearchParams,
37
- ): SerovalURLSearchParamsNode {
38
- return {
39
- t: SerovalNodeType.URLSearchParams,
40
- i: id,
41
- s: serializeString(current.toString()),
42
- l: undefined,
43
- c: undefined,
44
- m: undefined,
45
- p: undefined,
46
- e: undefined,
47
- f: undefined,
48
- a: undefined,
49
- b: undefined,
50
- o: undefined,
51
- };
52
- }
53
-
54
- export function createDOMExceptionNode(
55
- id: number,
56
- current: DOMException,
57
- ): SerovalDOMExceptionNode {
58
- return {
59
- t: SerovalNodeType.DOMException,
60
- i: id,
61
- s: serializeString(current.message),
62
- l: undefined,
63
- c: serializeString(current.name),
64
- m: undefined,
65
- p: undefined,
66
- e: undefined,
67
- a: undefined,
68
- f: undefined,
69
- b: undefined,
70
- o: undefined,
71
- };
72
- }
73
-
74
- export function createEventNode(
75
- id: number,
76
- type: string,
77
- options: SerovalNode,
78
- ): SerovalEventNode {
79
- return {
80
- t: SerovalNodeType.Event,
81
- i: id,
82
- s: serializeString(type),
83
- l: undefined,
84
- c: undefined,
85
- m: undefined,
86
- p: undefined,
87
- e: undefined,
88
- a: undefined,
89
- f: options,
90
- b: undefined,
91
- o: undefined,
92
- };
93
- }
94
-
95
- export function createCustomEventNode(
96
- id: number,
97
- type: string,
98
- options: SerovalNode,
99
- ): SerovalCustomEventNode {
100
- return {
101
- t: SerovalNodeType.CustomEvent,
102
- i: id,
103
- s: serializeString(type),
104
- l: undefined,
105
- c: undefined,
106
- m: undefined,
107
- p: undefined,
108
- e: undefined,
109
- a: undefined,
110
- f: options,
111
- b: undefined,
112
- o: undefined,
113
- };
114
- }
115
-
116
- export function createReadableStreamNode(
117
- id: number,
118
- factory: SerovalNodeWithID,
119
- items: SerovalNode,
120
- ): SerovalReadableStreamNode {
121
- return {
122
- t: SerovalNodeType.ReadableStream,
123
- i: id,
124
- s: undefined,
125
- l: undefined,
126
- c: undefined,
127
- m: undefined,
128
- p: undefined,
129
- e: undefined,
130
- a: [
131
- factory,
132
- items,
133
- ],
134
- f: undefined,
135
- b: undefined,
136
- o: undefined,
137
- };
138
- }
package/src/example.ts DELETED
@@ -1,25 +0,0 @@
1
- import { createPlugin, type SerovalNode } from '..';
2
-
3
- const BufferPlugin = createPlugin<Buffer, SerovalNode>({
4
- tag: 'Buffer',
5
- test(value) {
6
- return value instanceof Buffer;
7
- },
8
- parse: {
9
- sync(value, ctx) {
10
- return ctx.parse(value.toString('base64'));
11
- },
12
- async async(value, ctx) {
13
- return ctx.parse(value.toString('base64'));
14
- },
15
- stream(value, ctx) {
16
- return ctx.parse(value.toString('base64'));
17
- },
18
- },
19
- serialize(node, ctx) {
20
- return `Buffer.from(${ctx.serialize(node)}, "base64")`;
21
- },
22
- deserialize(node, ctx) {
23
- return Buffer.from(ctx.deserialize(node) as string, 'base64');
24
- },
25
- });