seroval 1.1.1 → 1.2.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.
- package/dist/cjs/development/index.cjs +702 -504
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +7 -7
- package/dist/esm/development/index.mjs +702 -504
- 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 +2 -0
- package/dist/types/core/context/parser/async.d.ts.map +1 -1
- package/dist/types/core/context/parser/stream.d.ts +2 -1
- package/dist/types/core/context/parser/stream.d.ts.map +1 -1
- package/dist/types/core/context/parser/sync.d.ts +3 -1
- package/dist/types/core/context/parser/sync.d.ts.map +1 -1
- package/dist/types/core/context/parser.d.ts +2 -1
- 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/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 +13 -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 +61 -20
- package/src/core/context/parser/stream.ts +89 -37
- package/src/core/context/parser/sync.ts +44 -3
- package/src/core/context/parser.ts +106 -85
- package/src/core/context/serializer.ts +55 -9
- 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,
|
|
@@ -151,20 +153,20 @@ export abstract class BaseParserContext implements PluginAccessOptions {
|
|
|
151
153
|
if (result.type === NodeType.Indexed) {
|
|
152
154
|
return result.value;
|
|
153
155
|
}
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
156
|
+
return createSerovalNode(
|
|
157
|
+
SerovalNodeType.SpecialReference,
|
|
158
|
+
result.value,
|
|
159
|
+
ref,
|
|
160
|
+
NIL,
|
|
161
|
+
NIL,
|
|
162
|
+
NIL,
|
|
163
|
+
NIL,
|
|
164
|
+
NIL,
|
|
165
|
+
NIL,
|
|
166
|
+
NIL,
|
|
167
|
+
NIL,
|
|
168
|
+
NIL,
|
|
169
|
+
);
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
protected parseIteratorFactory():
|
|
@@ -174,20 +176,20 @@ export abstract class BaseParserContext implements PluginAccessOptions {
|
|
|
174
176
|
if (result.type === NodeType.Indexed) {
|
|
175
177
|
return result.value;
|
|
176
178
|
}
|
|
177
|
-
return
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
179
|
+
return createSerovalNode(
|
|
180
|
+
SerovalNodeType.IteratorFactory,
|
|
181
|
+
result.value,
|
|
182
|
+
NIL,
|
|
183
|
+
NIL,
|
|
184
|
+
NIL,
|
|
185
|
+
NIL,
|
|
186
|
+
NIL,
|
|
187
|
+
NIL,
|
|
188
|
+
NIL,
|
|
189
|
+
this.parseWellKnownSymbol(Symbol.iterator),
|
|
190
|
+
NIL,
|
|
191
|
+
NIL,
|
|
192
|
+
);
|
|
191
193
|
}
|
|
192
194
|
|
|
193
195
|
protected parseAsyncIteratorFactory():
|
|
@@ -197,23 +199,23 @@ export abstract class BaseParserContext implements PluginAccessOptions {
|
|
|
197
199
|
if (result.type === NodeType.Indexed) {
|
|
198
200
|
return result.value;
|
|
199
201
|
}
|
|
200
|
-
return
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
202
|
+
return createSerovalNode(
|
|
203
|
+
SerovalNodeType.AsyncIteratorFactory,
|
|
204
|
+
result.value,
|
|
205
|
+
NIL,
|
|
206
|
+
NIL,
|
|
207
|
+
NIL,
|
|
208
|
+
NIL,
|
|
209
|
+
NIL,
|
|
210
|
+
NIL,
|
|
211
|
+
[
|
|
210
212
|
this.parseSpecialReference(SpecialReference.PromiseConstructor),
|
|
211
213
|
this.parseWellKnownSymbol(Symbol.asyncIterator),
|
|
212
214
|
],
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
NIL,
|
|
216
|
+
NIL,
|
|
217
|
+
NIL,
|
|
218
|
+
);
|
|
217
219
|
}
|
|
218
220
|
|
|
219
221
|
protected createObjectNode(
|
|
@@ -222,20 +224,20 @@ export abstract class BaseParserContext implements PluginAccessOptions {
|
|
|
222
224
|
empty: boolean,
|
|
223
225
|
record: SerovalObjectRecordNode,
|
|
224
226
|
): SerovalObjectNode | SerovalNullConstructorNode {
|
|
225
|
-
return
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
227
|
+
return createSerovalNode(
|
|
228
|
+
empty ? SerovalNodeType.NullConstructor : SerovalNodeType.Object,
|
|
229
|
+
id,
|
|
230
|
+
NIL,
|
|
231
|
+
NIL,
|
|
232
|
+
NIL,
|
|
233
|
+
NIL,
|
|
234
|
+
record,
|
|
235
|
+
NIL,
|
|
236
|
+
NIL,
|
|
237
|
+
NIL,
|
|
238
|
+
NIL,
|
|
239
|
+
getObjectFlag(current),
|
|
240
|
+
);
|
|
239
241
|
}
|
|
240
242
|
|
|
241
243
|
protected createMapNode(
|
|
@@ -244,38 +246,57 @@ export abstract class BaseParserContext implements PluginAccessOptions {
|
|
|
244
246
|
v: SerovalNode[],
|
|
245
247
|
s: number,
|
|
246
248
|
): SerovalMapNode {
|
|
247
|
-
return
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
249
|
+
return createSerovalNode(
|
|
250
|
+
SerovalNodeType.Map,
|
|
251
|
+
id,
|
|
252
|
+
NIL,
|
|
253
|
+
NIL,
|
|
254
|
+
NIL,
|
|
255
|
+
NIL,
|
|
256
|
+
NIL,
|
|
257
|
+
{ k, v, s },
|
|
258
|
+
NIL,
|
|
259
|
+
this.parseSpecialReference(SpecialReference.MapSentinel),
|
|
260
|
+
NIL,
|
|
261
|
+
NIL,
|
|
262
|
+
);
|
|
261
263
|
}
|
|
262
264
|
|
|
263
265
|
protected createPromiseConstructorNode(
|
|
264
266
|
id: number,
|
|
265
267
|
): SerovalPromiseConstructorNode {
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
268
|
+
return createSerovalNode(
|
|
269
|
+
SerovalNodeType.PromiseConstructor,
|
|
270
|
+
id,
|
|
271
|
+
NIL,
|
|
272
|
+
NIL,
|
|
273
|
+
NIL,
|
|
274
|
+
NIL,
|
|
275
|
+
NIL,
|
|
276
|
+
NIL,
|
|
277
|
+
NIL,
|
|
278
|
+
this.parseSpecialReference(SpecialReference.PromiseConstructor),
|
|
279
|
+
NIL,
|
|
280
|
+
NIL,
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
protected createAbortSignalConstructorNode(
|
|
285
|
+
id: number,
|
|
286
|
+
): SerovalAbortSignalConstructorNode {
|
|
287
|
+
return createSerovalNode(
|
|
288
|
+
SerovalNodeType.AbortSignalConstructor,
|
|
289
|
+
id,
|
|
290
|
+
NIL,
|
|
291
|
+
NIL,
|
|
292
|
+
NIL,
|
|
293
|
+
NIL,
|
|
294
|
+
NIL,
|
|
295
|
+
NIL,
|
|
296
|
+
NIL,
|
|
297
|
+
this.parseSpecialReference(SpecialReference.AbortSignalConstructor),
|
|
298
|
+
NIL,
|
|
299
|
+
NIL,
|
|
300
|
+
);
|
|
280
301
|
}
|
|
281
302
|
}
|
|
@@ -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/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
|
package/src/core/types.ts
CHANGED
|
@@ -269,6 +269,9 @@ export interface SerovalPluginNode extends SerovalBaseNode {
|
|
|
269
269
|
c: string;
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Represents special values as placeholders
|
|
274
|
+
*/
|
|
272
275
|
export interface SerovalSpecialReferenceNode extends SerovalBaseNode {
|
|
273
276
|
t: SerovalNodeType.SpecialReference;
|
|
274
277
|
i: number;
|
|
@@ -302,24 +305,48 @@ export interface SerovalStreamConstructorNode extends SerovalBaseNode {
|
|
|
302
305
|
t: SerovalNodeType.StreamConstructor;
|
|
303
306
|
i: number;
|
|
304
307
|
a: SerovalNode[];
|
|
308
|
+
// special reference to the constructor
|
|
305
309
|
f: SerovalNodeWithID;
|
|
306
310
|
}
|
|
307
311
|
|
|
308
312
|
export interface SerovalStreamNextNode extends SerovalBaseNode {
|
|
309
313
|
t: SerovalNodeType.StreamNext;
|
|
310
314
|
i: number;
|
|
315
|
+
// Next value
|
|
311
316
|
f: SerovalNode;
|
|
312
317
|
}
|
|
313
318
|
|
|
314
319
|
export interface SerovalStreamThrowNode extends SerovalBaseNode {
|
|
315
320
|
t: SerovalNodeType.StreamThrow;
|
|
316
321
|
i: number;
|
|
322
|
+
// Throw value
|
|
317
323
|
f: SerovalNode;
|
|
318
324
|
}
|
|
319
325
|
|
|
320
326
|
export interface SerovalStreamReturnNode extends SerovalBaseNode {
|
|
321
327
|
t: SerovalNodeType.StreamReturn;
|
|
322
328
|
i: number;
|
|
329
|
+
// Return value
|
|
330
|
+
f: SerovalNode;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface SerovalAbortSignalConstructorNode extends SerovalBaseNode {
|
|
334
|
+
t: SerovalNodeType.AbortSignalConstructor;
|
|
335
|
+
i: number;
|
|
336
|
+
// special reference to the constructor
|
|
337
|
+
f: SerovalNodeWithID;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface SerovalAbortSignalAbortNode extends SerovalBaseNode {
|
|
341
|
+
t: SerovalNodeType.AbortSignalAbort;
|
|
342
|
+
i: number;
|
|
343
|
+
a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export interface SerovalAbortSignalSyncNode extends SerovalBaseNode {
|
|
347
|
+
t: SerovalNodeType.AbortSignalSync;
|
|
348
|
+
i: number;
|
|
349
|
+
// Abort reason
|
|
323
350
|
f: SerovalNode;
|
|
324
351
|
}
|
|
325
352
|
|
|
@@ -345,7 +372,8 @@ export type SerovalSyncNode =
|
|
|
345
372
|
| SerovalIteratorFactoryNode
|
|
346
373
|
| SerovalIteratorFactoryInstanceNode
|
|
347
374
|
| SerovalAsyncIteratorFactoryNode
|
|
348
|
-
| SerovalAsyncIteratorFactoryInstanceNode
|
|
375
|
+
| SerovalAsyncIteratorFactoryInstanceNode
|
|
376
|
+
| SerovalAbortSignalSyncNode;
|
|
349
377
|
|
|
350
378
|
export type SerovalAsyncNode =
|
|
351
379
|
| SerovalPromiseNode
|
|
@@ -355,7 +383,9 @@ export type SerovalAsyncNode =
|
|
|
355
383
|
| SerovalStreamConstructorNode
|
|
356
384
|
| SerovalStreamNextNode
|
|
357
385
|
| SerovalStreamThrowNode
|
|
358
|
-
| SerovalStreamReturnNode
|
|
386
|
+
| SerovalStreamReturnNode
|
|
387
|
+
| SerovalAbortSignalConstructorNode
|
|
388
|
+
| SerovalAbortSignalAbortNode;
|
|
359
389
|
|
|
360
390
|
export type SerovalNode = SerovalSyncNode | SerovalAsyncNode;
|
|
361
391
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { NIL } from "../constants";
|
|
2
|
+
|
|
1
3
|
export interface Sequence {
|
|
2
4
|
v: unknown[];
|
|
3
5
|
t: number;
|
|
@@ -46,7 +48,7 @@ export function sequenceToIterator<T>(
|
|
|
46
48
|
if (index > sequence.d) {
|
|
47
49
|
return {
|
|
48
50
|
done: true,
|
|
49
|
-
value:
|
|
51
|
+
value: NIL,
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
const currentIndex = index++;
|