seroval 1.1.1 → 1.2.1
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/cjs/development/index.cjs +728 -523
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +7 -7
- package/dist/esm/development/index.mjs +728 -523
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +7 -7
- package/dist/types/core/abort-signal.d.ts +2 -0
- package/dist/types/core/abort-signal.d.ts.map +1 -0
- package/dist/types/core/base-primitives.d.ts +2 -1
- package/dist/types/core/base-primitives.d.ts.map +1 -1
- package/dist/types/core/compat.d.ts +3 -2
- package/dist/types/core/compat.d.ts.map +1 -1
- package/dist/types/core/constants.d.ts +5 -1
- package/dist/types/core/constants.d.ts.map +1 -1
- package/dist/types/core/context/deserializer.d.ts +3 -0
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/parser/async.d.ts +3 -0
- package/dist/types/core/context/parser/async.d.ts.map +1 -1
- package/dist/types/core/context/parser/stream.d.ts +3 -1
- package/dist/types/core/context/parser/stream.d.ts.map +1 -1
- package/dist/types/core/context/parser/sync.d.ts +4 -1
- package/dist/types/core/context/parser/sync.d.ts.map +1 -1
- package/dist/types/core/context/parser.d.ts +9 -10
- package/dist/types/core/context/parser.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts +4 -1
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/dist/types/core/cross/index.d.ts.map +1 -1
- package/dist/types/core/literals.d.ts.map +1 -1
- package/dist/types/core/node.d.ts +8 -0
- package/dist/types/core/node.d.ts.map +1 -0
- package/dist/types/core/special-reference.d.ts +6 -1
- package/dist/types/core/special-reference.d.ts.map +1 -1
- package/dist/types/core/tree/serializer.d.ts +2 -1
- package/dist/types/core/tree/serializer.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +20 -2
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/core/abort-signal.ts +19 -0
- package/src/core/base-primitives.ts +359 -337
- package/src/core/compat.ts +2 -1
- package/src/core/constants.ts +5 -0
- package/src/core/context/deserializer.ts +34 -1
- package/src/core/context/parser/async.ts +75 -22
- package/src/core/context/parser/stream.ts +91 -37
- package/src/core/context/parser/sync.ts +61 -7
- package/src/core/context/parser.ts +121 -117
- package/src/core/context/serializer.ts +55 -9
- package/src/core/cross/index.ts +2 -6
- package/src/core/literals.ts +16 -15
- package/src/core/node.ts +40 -0
- package/src/core/special-reference.ts +7 -0
- package/src/core/tree/serializer.ts +7 -0
- package/src/core/types.ts +32 -2
- package/src/core/utils/iterator-to-sequence.ts +3 -1
|
@@ -5,8 +5,9 @@ import {
|
|
|
5
5
|
} from '../base-primitives';
|
|
6
6
|
import { ALL_ENABLED } from '../compat';
|
|
7
7
|
import type { WellKnownSymbols } from '../constants';
|
|
8
|
-
import { INV_SYMBOL_REF, SerovalNodeType } from '../constants';
|
|
8
|
+
import { INV_SYMBOL_REF, NIL, SerovalNodeType } from '../constants';
|
|
9
9
|
import { SerovalUnsupportedTypeError } from '../errors';
|
|
10
|
+
import { createSerovalNode } from '../node';
|
|
10
11
|
import type { Plugin, PluginAccessOptions, SerovalMode } from '../plugin';
|
|
11
12
|
import { hasReferenceID } from '../reference';
|
|
12
13
|
import {
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
SpecialReference,
|
|
17
18
|
} from '../special-reference';
|
|
18
19
|
import type {
|
|
20
|
+
SerovalAbortSignalConstructorNode,
|
|
19
21
|
SerovalAsyncIteratorFactoryNode,
|
|
20
22
|
SerovalIndexedValueNode,
|
|
21
23
|
SerovalIteratorFactoryNode,
|
|
@@ -37,24 +39,24 @@ export interface BaseParserContextOptions extends PluginAccessOptions {
|
|
|
37
39
|
refs?: Map<unknown, number>;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
const enum
|
|
42
|
+
export const enum ParserNodeType {
|
|
41
43
|
Fresh = 0,
|
|
42
44
|
Indexed = 1,
|
|
43
45
|
Referenced = 2,
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
interface FreshNode {
|
|
47
|
-
type:
|
|
48
|
+
export interface FreshNode {
|
|
49
|
+
type: ParserNodeType.Fresh;
|
|
48
50
|
value: number;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
interface IndexedNode {
|
|
52
|
-
type:
|
|
53
|
+
export interface IndexedNode {
|
|
54
|
+
type: ParserNodeType.Indexed;
|
|
53
55
|
value: SerovalIndexedValueNode;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
interface ReferencedNode {
|
|
57
|
-
type:
|
|
58
|
+
export interface ReferencedNode {
|
|
59
|
+
type: ParserNodeType.Referenced;
|
|
58
60
|
value: SerovalReferenceNode;
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -90,54 +92,37 @@ export abstract class BaseParserContext implements PluginAccessOptions {
|
|
|
90
92
|
if (registeredId != null) {
|
|
91
93
|
this.markRef(registeredId);
|
|
92
94
|
return {
|
|
93
|
-
type:
|
|
95
|
+
type: ParserNodeType.Indexed,
|
|
94
96
|
value: createIndexedValueNode(registeredId),
|
|
95
97
|
};
|
|
96
98
|
}
|
|
97
99
|
const id = this.refs.size;
|
|
98
100
|
this.refs.set(current, id);
|
|
99
101
|
return {
|
|
100
|
-
type:
|
|
102
|
+
type: ParserNodeType.Fresh,
|
|
101
103
|
value: id,
|
|
102
104
|
};
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
protected getReference<T>(current: T): ObjectNode {
|
|
106
108
|
const indexed = this.getIndexedValue(current);
|
|
107
|
-
if (indexed.type ===
|
|
109
|
+
if (indexed.type === ParserNodeType.Indexed) {
|
|
108
110
|
return indexed;
|
|
109
111
|
}
|
|
110
112
|
if (hasReferenceID(current)) {
|
|
111
113
|
return {
|
|
112
|
-
type:
|
|
114
|
+
type: ParserNodeType.Referenced,
|
|
113
115
|
value: createReferenceNode(indexed.value, current),
|
|
114
116
|
};
|
|
115
117
|
}
|
|
116
118
|
return indexed;
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
protected getStrictReference<T>(
|
|
120
|
-
current: T,
|
|
121
|
-
): SerovalIndexedValueNode | SerovalReferenceNode {
|
|
122
|
-
assert(hasReferenceID(current), new SerovalUnsupportedTypeError(current));
|
|
123
|
-
const result = this.getIndexedValue(current);
|
|
124
|
-
if (result.type === NodeType.Indexed) {
|
|
125
|
-
return result.value;
|
|
126
|
-
}
|
|
127
|
-
return createReferenceNode(result.value, current);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
protected parseFunction(
|
|
131
|
-
current: (...args: unknown[]) => unknown,
|
|
132
|
-
): SerovalNode {
|
|
133
|
-
return this.getStrictReference(current);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
121
|
protected parseWellKnownSymbol(
|
|
137
122
|
current: symbol,
|
|
138
123
|
): SerovalIndexedValueNode | SerovalWKSymbolNode | SerovalReferenceNode {
|
|
139
124
|
const ref = this.getReference(current);
|
|
140
|
-
if (ref.type !==
|
|
125
|
+
if (ref.type !== ParserNodeType.Fresh) {
|
|
141
126
|
return ref.value;
|
|
142
127
|
}
|
|
143
128
|
assert(current in INV_SYMBOL_REF, new SerovalUnsupportedTypeError(current));
|
|
@@ -148,72 +133,72 @@ export abstract class BaseParserContext implements PluginAccessOptions {
|
|
|
148
133
|
ref: SpecialReference,
|
|
149
134
|
): SerovalIndexedValueNode | SerovalSpecialReferenceNode {
|
|
150
135
|
const result = this.getIndexedValue(SPECIAL_REFS[ref]);
|
|
151
|
-
if (result.type ===
|
|
136
|
+
if (result.type === ParserNodeType.Indexed) {
|
|
152
137
|
return result.value;
|
|
153
138
|
}
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
139
|
+
return createSerovalNode(
|
|
140
|
+
SerovalNodeType.SpecialReference,
|
|
141
|
+
result.value,
|
|
142
|
+
ref,
|
|
143
|
+
NIL,
|
|
144
|
+
NIL,
|
|
145
|
+
NIL,
|
|
146
|
+
NIL,
|
|
147
|
+
NIL,
|
|
148
|
+
NIL,
|
|
149
|
+
NIL,
|
|
150
|
+
NIL,
|
|
151
|
+
NIL,
|
|
152
|
+
);
|
|
168
153
|
}
|
|
169
154
|
|
|
170
155
|
protected parseIteratorFactory():
|
|
171
156
|
| SerovalIndexedValueNode
|
|
172
157
|
| SerovalIteratorFactoryNode {
|
|
173
158
|
const result = this.getIndexedValue(ITERATOR);
|
|
174
|
-
if (result.type ===
|
|
159
|
+
if (result.type === ParserNodeType.Indexed) {
|
|
175
160
|
return result.value;
|
|
176
161
|
}
|
|
177
|
-
return
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
162
|
+
return createSerovalNode(
|
|
163
|
+
SerovalNodeType.IteratorFactory,
|
|
164
|
+
result.value,
|
|
165
|
+
NIL,
|
|
166
|
+
NIL,
|
|
167
|
+
NIL,
|
|
168
|
+
NIL,
|
|
169
|
+
NIL,
|
|
170
|
+
NIL,
|
|
171
|
+
NIL,
|
|
172
|
+
this.parseWellKnownSymbol(Symbol.iterator),
|
|
173
|
+
NIL,
|
|
174
|
+
NIL,
|
|
175
|
+
);
|
|
191
176
|
}
|
|
192
177
|
|
|
193
178
|
protected parseAsyncIteratorFactory():
|
|
194
179
|
| SerovalIndexedValueNode
|
|
195
180
|
| SerovalAsyncIteratorFactoryNode {
|
|
196
181
|
const result = this.getIndexedValue(ASYNC_ITERATOR);
|
|
197
|
-
if (result.type ===
|
|
182
|
+
if (result.type === ParserNodeType.Indexed) {
|
|
198
183
|
return result.value;
|
|
199
184
|
}
|
|
200
|
-
return
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
185
|
+
return createSerovalNode(
|
|
186
|
+
SerovalNodeType.AsyncIteratorFactory,
|
|
187
|
+
result.value,
|
|
188
|
+
NIL,
|
|
189
|
+
NIL,
|
|
190
|
+
NIL,
|
|
191
|
+
NIL,
|
|
192
|
+
NIL,
|
|
193
|
+
NIL,
|
|
194
|
+
[
|
|
210
195
|
this.parseSpecialReference(SpecialReference.PromiseConstructor),
|
|
211
196
|
this.parseWellKnownSymbol(Symbol.asyncIterator),
|
|
212
197
|
],
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
198
|
+
NIL,
|
|
199
|
+
NIL,
|
|
200
|
+
NIL,
|
|
201
|
+
);
|
|
217
202
|
}
|
|
218
203
|
|
|
219
204
|
protected createObjectNode(
|
|
@@ -222,20 +207,20 @@ export abstract class BaseParserContext implements PluginAccessOptions {
|
|
|
222
207
|
empty: boolean,
|
|
223
208
|
record: SerovalObjectRecordNode,
|
|
224
209
|
): SerovalObjectNode | SerovalNullConstructorNode {
|
|
225
|
-
return
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
210
|
+
return createSerovalNode(
|
|
211
|
+
empty ? SerovalNodeType.NullConstructor : SerovalNodeType.Object,
|
|
212
|
+
id,
|
|
213
|
+
NIL,
|
|
214
|
+
NIL,
|
|
215
|
+
NIL,
|
|
216
|
+
NIL,
|
|
217
|
+
record,
|
|
218
|
+
NIL,
|
|
219
|
+
NIL,
|
|
220
|
+
NIL,
|
|
221
|
+
NIL,
|
|
222
|
+
getObjectFlag(current),
|
|
223
|
+
);
|
|
239
224
|
}
|
|
240
225
|
|
|
241
226
|
protected createMapNode(
|
|
@@ -244,38 +229,57 @@ export abstract class BaseParserContext implements PluginAccessOptions {
|
|
|
244
229
|
v: SerovalNode[],
|
|
245
230
|
s: number,
|
|
246
231
|
): SerovalMapNode {
|
|
247
|
-
return
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
232
|
+
return createSerovalNode(
|
|
233
|
+
SerovalNodeType.Map,
|
|
234
|
+
id,
|
|
235
|
+
NIL,
|
|
236
|
+
NIL,
|
|
237
|
+
NIL,
|
|
238
|
+
NIL,
|
|
239
|
+
NIL,
|
|
240
|
+
{ k, v, s },
|
|
241
|
+
NIL,
|
|
242
|
+
this.parseSpecialReference(SpecialReference.MapSentinel),
|
|
243
|
+
NIL,
|
|
244
|
+
NIL,
|
|
245
|
+
);
|
|
261
246
|
}
|
|
262
247
|
|
|
263
248
|
protected createPromiseConstructorNode(
|
|
264
249
|
id: number,
|
|
265
250
|
): SerovalPromiseConstructorNode {
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
251
|
+
return createSerovalNode(
|
|
252
|
+
SerovalNodeType.PromiseConstructor,
|
|
253
|
+
id,
|
|
254
|
+
NIL,
|
|
255
|
+
NIL,
|
|
256
|
+
NIL,
|
|
257
|
+
NIL,
|
|
258
|
+
NIL,
|
|
259
|
+
NIL,
|
|
260
|
+
NIL,
|
|
261
|
+
this.parseSpecialReference(SpecialReference.PromiseConstructor),
|
|
262
|
+
NIL,
|
|
263
|
+
NIL,
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
protected createAbortSignalConstructorNode(
|
|
268
|
+
id: number,
|
|
269
|
+
): SerovalAbortSignalConstructorNode {
|
|
270
|
+
return createSerovalNode(
|
|
271
|
+
SerovalNodeType.AbortSignalConstructor,
|
|
272
|
+
id,
|
|
273
|
+
NIL,
|
|
274
|
+
NIL,
|
|
275
|
+
NIL,
|
|
276
|
+
NIL,
|
|
277
|
+
NIL,
|
|
278
|
+
NIL,
|
|
279
|
+
NIL,
|
|
280
|
+
this.parseSpecialReference(SpecialReference.AbortSignalConstructor),
|
|
281
|
+
NIL,
|
|
282
|
+
NIL,
|
|
283
|
+
);
|
|
280
284
|
}
|
|
281
285
|
}
|
|
@@ -2,6 +2,7 @@ import { Feature } from '../compat';
|
|
|
2
2
|
import {
|
|
3
3
|
CONSTANT_STRING,
|
|
4
4
|
ERROR_CONSTRUCTOR_STRING,
|
|
5
|
+
NIL,
|
|
5
6
|
SYMBOL_STRING,
|
|
6
7
|
SerovalNodeType,
|
|
7
8
|
SerovalObjectFlags,
|
|
@@ -15,6 +16,9 @@ import { REFERENCES_KEY } from '../keys';
|
|
|
15
16
|
import type { Plugin, PluginAccessOptions, SerovalMode } from '../plugin';
|
|
16
17
|
import { SpecialReference } from '../special-reference';
|
|
17
18
|
import type {
|
|
19
|
+
SerovalAbortSignalAbortNode,
|
|
20
|
+
SerovalAbortSignalConstructorNode,
|
|
21
|
+
SerovalAbortSignalSyncNode,
|
|
18
22
|
SerovalAggregateErrorNode,
|
|
19
23
|
SerovalArrayBufferNode,
|
|
20
24
|
SerovalArrayNode,
|
|
@@ -128,7 +132,7 @@ function mergeAssignments(assignments: Assignment[]): Assignment[] {
|
|
|
128
132
|
current = {
|
|
129
133
|
t: AssignmentType.Index,
|
|
130
134
|
s: item.s,
|
|
131
|
-
k:
|
|
135
|
+
k: NIL,
|
|
132
136
|
v: getAssignmentExpression(current),
|
|
133
137
|
} as IndexAssignment;
|
|
134
138
|
} else if (item.t === AssignmentType.Set && item.s === prev.s) {
|
|
@@ -144,7 +148,7 @@ function mergeAssignments(assignments: Assignment[]): Assignment[] {
|
|
|
144
148
|
current = {
|
|
145
149
|
t: AssignmentType.Add,
|
|
146
150
|
s: getAssignmentExpression(current),
|
|
147
|
-
k:
|
|
151
|
+
k: NIL,
|
|
148
152
|
v: item.v,
|
|
149
153
|
} as AddAssignment;
|
|
150
154
|
} else if (item.t === AssignmentType.Delete && item.s === prev.s) {
|
|
@@ -153,7 +157,7 @@ function mergeAssignments(assignments: Assignment[]): Assignment[] {
|
|
|
153
157
|
t: AssignmentType.Delete,
|
|
154
158
|
s: getAssignmentExpression(current),
|
|
155
159
|
k: item.k,
|
|
156
|
-
v:
|
|
160
|
+
v: NIL,
|
|
157
161
|
} as DeleteAssignment;
|
|
158
162
|
} else {
|
|
159
163
|
// Different assignment, push current
|
|
@@ -177,7 +181,7 @@ function resolveAssignments(assignments: Assignment[]): string | undefined {
|
|
|
177
181
|
}
|
|
178
182
|
return result;
|
|
179
183
|
}
|
|
180
|
-
return
|
|
184
|
+
return NIL;
|
|
181
185
|
}
|
|
182
186
|
|
|
183
187
|
const NULL_CONSTRUCTOR = 'Object.create(null)';
|
|
@@ -192,7 +196,7 @@ const OBJECT_FLAG_CONSTRUCTOR: Record<SerovalObjectFlags, string | undefined> =
|
|
|
192
196
|
[SerovalObjectFlags.Frozen]: 'Object.freeze',
|
|
193
197
|
[SerovalObjectFlags.Sealed]: 'Object.seal',
|
|
194
198
|
[SerovalObjectFlags.NonExtensible]: 'Object.preventExtensions',
|
|
195
|
-
[SerovalObjectFlags.None]:
|
|
199
|
+
[SerovalObjectFlags.None]: NIL,
|
|
196
200
|
};
|
|
197
201
|
|
|
198
202
|
type SerovalNodeWithProperties =
|
|
@@ -331,7 +335,7 @@ export default abstract class BaseSerializerContext
|
|
|
331
335
|
this.assignments.push({
|
|
332
336
|
t: AssignmentType.Index,
|
|
333
337
|
s: source,
|
|
334
|
-
k:
|
|
338
|
+
k: NIL,
|
|
335
339
|
v: value,
|
|
336
340
|
});
|
|
337
341
|
}
|
|
@@ -340,7 +344,7 @@ export default abstract class BaseSerializerContext
|
|
|
340
344
|
this.assignments.push({
|
|
341
345
|
t: AssignmentType.Add,
|
|
342
346
|
s: this.getRefParam(ref),
|
|
343
|
-
k:
|
|
347
|
+
k: NIL,
|
|
344
348
|
v: value,
|
|
345
349
|
});
|
|
346
350
|
}
|
|
@@ -359,7 +363,7 @@ export default abstract class BaseSerializerContext
|
|
|
359
363
|
t: AssignmentType.Delete,
|
|
360
364
|
s: this.getRefParam(ref),
|
|
361
365
|
k: key,
|
|
362
|
-
v:
|
|
366
|
+
v: NIL,
|
|
363
367
|
});
|
|
364
368
|
}
|
|
365
369
|
|
|
@@ -610,7 +614,7 @@ export default abstract class BaseSerializerContext
|
|
|
610
614
|
this.stack.pop();
|
|
611
615
|
return resolveAssignments(mainAssignments);
|
|
612
616
|
}
|
|
613
|
-
return
|
|
617
|
+
return NIL;
|
|
614
618
|
}
|
|
615
619
|
|
|
616
620
|
protected serializeDictionary(
|
|
@@ -997,6 +1001,16 @@ export default abstract class BaseSerializerContext
|
|
|
997
1001
|
) +
|
|
998
1002
|
'})',
|
|
999
1003
|
);
|
|
1004
|
+
case SpecialReference.AbortSignalConstructor:
|
|
1005
|
+
return this.createFunction(
|
|
1006
|
+
['a', 's'],
|
|
1007
|
+
'((s=(a=new AbortController).signal).a=a,s)',
|
|
1008
|
+
);
|
|
1009
|
+
case SpecialReference.AbortSignalAbort:
|
|
1010
|
+
return this.createEffectfulFunction(
|
|
1011
|
+
['s', 'r'],
|
|
1012
|
+
's.a.abort(r);delete s.a',
|
|
1013
|
+
);
|
|
1000
1014
|
default:
|
|
1001
1015
|
return '';
|
|
1002
1016
|
}
|
|
@@ -1159,6 +1173,32 @@ export default abstract class BaseSerializerContext
|
|
|
1159
1173
|
return this.getRefParam(node.i) + '.return(' + this.serialize(node.f) + ')';
|
|
1160
1174
|
}
|
|
1161
1175
|
|
|
1176
|
+
protected serializeAbortSignalSync(node: SerovalAbortSignalSyncNode): string {
|
|
1177
|
+
return this.assignIndexedValue(
|
|
1178
|
+
node.i,
|
|
1179
|
+
'AbortSignal.abort(' + this.serialize(node.f) + ')',
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
protected serializeAbortSignalConstructor(
|
|
1184
|
+
node: SerovalAbortSignalConstructorNode,
|
|
1185
|
+
): string {
|
|
1186
|
+
return this.assignIndexedValue(node.i, this.getConstructor(node.f) + '()');
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
protected serializeAbortSignalAbort(
|
|
1190
|
+
node: SerovalAbortSignalAbortNode,
|
|
1191
|
+
): string {
|
|
1192
|
+
return (
|
|
1193
|
+
this.getConstructor(node.a[0]) +
|
|
1194
|
+
'(' +
|
|
1195
|
+
this.getRefParam(node.i) +
|
|
1196
|
+
',' +
|
|
1197
|
+
this.serialize(node.a[1]) +
|
|
1198
|
+
')'
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1162
1202
|
serialize(node: SerovalNode): string {
|
|
1163
1203
|
try {
|
|
1164
1204
|
switch (node.t) {
|
|
@@ -1231,6 +1271,12 @@ export default abstract class BaseSerializerContext
|
|
|
1231
1271
|
return this.serializeStreamThrow(node);
|
|
1232
1272
|
case SerovalNodeType.StreamReturn:
|
|
1233
1273
|
return this.serializeStreamReturn(node);
|
|
1274
|
+
case SerovalNodeType.AbortSignalAbort:
|
|
1275
|
+
return this.serializeAbortSignalAbort(node);
|
|
1276
|
+
case SerovalNodeType.AbortSignalConstructor:
|
|
1277
|
+
return this.serializeAbortSignalConstructor(node);
|
|
1278
|
+
case SerovalNodeType.AbortSignalSync:
|
|
1279
|
+
return this.serializeAbortSignalSync(node);
|
|
1234
1280
|
default:
|
|
1235
1281
|
throw new SerovalUnsupportedNodeError(node);
|
|
1236
1282
|
}
|
package/src/core/cross/index.ts
CHANGED
|
@@ -131,9 +131,7 @@ export function crossSerializeStream<T>(
|
|
|
131
131
|
|
|
132
132
|
ctx.start(source);
|
|
133
133
|
|
|
134
|
-
return ()
|
|
135
|
-
ctx.destroy();
|
|
136
|
-
};
|
|
134
|
+
return ctx.destroy.bind(ctx);
|
|
137
135
|
}
|
|
138
136
|
|
|
139
137
|
export type ToCrossJSONStreamOptions = CrossStreamParserContextOptions;
|
|
@@ -154,9 +152,7 @@ export function toCrossJSONStream<T>(
|
|
|
154
152
|
|
|
155
153
|
ctx.start(source);
|
|
156
154
|
|
|
157
|
-
return ()
|
|
158
|
-
ctx.destroy();
|
|
159
|
-
};
|
|
155
|
+
return ctx.destroy.bind(ctx);
|
|
160
156
|
}
|
|
161
157
|
|
|
162
158
|
export type FromCrossJSONOptions = CrossDeserializerContextOptions;
|
package/src/core/literals.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { SerovalConstant, SerovalNodeType } from './constants';
|
|
1
|
+
import { NIL, SerovalConstant, SerovalNodeType } from './constants';
|
|
2
|
+
import { createSerovalNode } from './node';
|
|
2
3
|
import type { SerovalConstantNode } from './types';
|
|
3
4
|
|
|
4
5
|
function createConstantNode(value: SerovalConstant): SerovalConstantNode {
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
return createSerovalNode(
|
|
7
|
+
SerovalNodeType.Constant,
|
|
8
|
+
NIL,
|
|
9
|
+
value,
|
|
10
|
+
NIL,
|
|
11
|
+
NIL,
|
|
12
|
+
NIL,
|
|
13
|
+
NIL,
|
|
14
|
+
NIL,
|
|
15
|
+
NIL,
|
|
16
|
+
NIL,
|
|
17
|
+
NIL,
|
|
18
|
+
NIL,
|
|
19
|
+
);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export const TRUE_NODE = /* @__PURE__ */ createConstantNode(
|
package/src/core/node.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SerovalNodeType } from './constants';
|
|
2
|
+
import type { SerovalNode } from './types';
|
|
3
|
+
|
|
4
|
+
type ExtractedNodeType<T extends SerovalNodeType> = Extract<
|
|
5
|
+
SerovalNode,
|
|
6
|
+
{ t: T }
|
|
7
|
+
>;
|
|
8
|
+
|
|
9
|
+
export function createSerovalNode<
|
|
10
|
+
T extends SerovalNodeType,
|
|
11
|
+
N extends ExtractedNodeType<T>,
|
|
12
|
+
>(
|
|
13
|
+
t: T,
|
|
14
|
+
i: N['i'],
|
|
15
|
+
s: N['s'],
|
|
16
|
+
l: N['l'],
|
|
17
|
+
c: N['c'],
|
|
18
|
+
m: N['m'],
|
|
19
|
+
p: N['p'],
|
|
20
|
+
e: N['e'],
|
|
21
|
+
a: N['a'],
|
|
22
|
+
f: N['f'],
|
|
23
|
+
b: N['b'],
|
|
24
|
+
o: N['o'],
|
|
25
|
+
): N {
|
|
26
|
+
return {
|
|
27
|
+
t,
|
|
28
|
+
i,
|
|
29
|
+
s,
|
|
30
|
+
l,
|
|
31
|
+
c,
|
|
32
|
+
m,
|
|
33
|
+
p,
|
|
34
|
+
e,
|
|
35
|
+
a,
|
|
36
|
+
f,
|
|
37
|
+
b,
|
|
38
|
+
o,
|
|
39
|
+
} as N;
|
|
40
|
+
}
|
|
@@ -8,12 +8,19 @@ export const enum SpecialReference {
|
|
|
8
8
|
PromiseResolve = 2,
|
|
9
9
|
PromiseReject = 3,
|
|
10
10
|
StreamConstructor = 4,
|
|
11
|
+
AbortSignalConstructor = 5,
|
|
12
|
+
AbortSignalAbort = 6,
|
|
11
13
|
}
|
|
12
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Placeholder references
|
|
17
|
+
*/
|
|
13
18
|
export const SPECIAL_REFS: Record<SpecialReference, unknown> = {
|
|
14
19
|
[SpecialReference.MapSentinel]: {},
|
|
15
20
|
[SpecialReference.PromiseConstructor]: {},
|
|
16
21
|
[SpecialReference.PromiseResolve]: {},
|
|
17
22
|
[SpecialReference.PromiseReject]: {},
|
|
18
23
|
[SpecialReference.StreamConstructor]: {},
|
|
24
|
+
[SpecialReference.AbortSignalConstructor]: {},
|
|
25
|
+
[SpecialReference.AbortSignalAbort]: {},
|
|
19
26
|
};
|
|
@@ -4,6 +4,7 @@ import BaseSerializerContext from '../context/serializer';
|
|
|
4
4
|
import { SerovalUnsupportedNodeError } from '../errors';
|
|
5
5
|
import type { SerovalMode } from '../plugin';
|
|
6
6
|
import type {
|
|
7
|
+
SerovalAbortSignalAbortNode,
|
|
7
8
|
SerovalNode,
|
|
8
9
|
SerovalPromiseConstructorNode,
|
|
9
10
|
SerovalPromiseRejectNode,
|
|
@@ -73,6 +74,12 @@ export default class VanillaSerializerContext extends BaseSerializerContext {
|
|
|
73
74
|
throw new SerovalUnsupportedNodeError(node);
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
protected serializeAbortSignalAbort(
|
|
78
|
+
node: SerovalAbortSignalAbortNode,
|
|
79
|
+
): string {
|
|
80
|
+
throw new SerovalUnsupportedNodeError(node);
|
|
81
|
+
}
|
|
82
|
+
|
|
76
83
|
serializeTop(tree: SerovalNode): string {
|
|
77
84
|
const result = this.serialize(tree);
|
|
78
85
|
// Shared references detected
|