seroval 1.2.0 → 1.3.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/LICENSE +1 -1
- package/dist/cjs/development/index.cjs +283 -398
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +5 -5
- package/dist/esm/development/index.mjs +283 -398
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +5 -5
- package/dist/types/core/base-primitives.d.ts +1 -2
- package/dist/types/core/base-primitives.d.ts.map +1 -1
- package/dist/types/core/compat.d.ts +2 -3
- package/dist/types/core/compat.d.ts.map +1 -1
- package/dist/types/core/constants.d.ts +3 -6
- package/dist/types/core/constants.d.ts.map +1 -1
- package/dist/types/core/context/deserializer.d.ts +0 -3
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/parser/async.d.ts +2 -2
- package/dist/types/core/context/parser/async.d.ts.map +1 -1
- package/dist/types/core/context/parser/stream.d.ts +8 -7
- package/dist/types/core/context/parser/stream.d.ts.map +1 -1
- package/dist/types/core/context/parser/sync.d.ts +3 -3
- package/dist/types/core/context/parser/sync.d.ts.map +1 -1
- package/dist/types/core/context/parser.d.ts +10 -12
- package/dist/types/core/context/parser.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts +1 -5
- 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/function-string.d.ts +3 -0
- package/dist/types/core/function-string.d.ts.map +1 -0
- package/dist/types/core/special-reference.d.ts +4 -5
- package/dist/types/core/special-reference.d.ts.map +1 -1
- package/dist/types/core/tree/serializer.d.ts +1 -2
- package/dist/types/core/tree/serializer.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +5 -19
- package/dist/types/core/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/core/base-primitives.ts +2 -22
- package/src/core/compat.ts +6 -2
- package/src/core/constants.ts +2 -5
- package/src/core/context/deserializer.ts +2 -35
- package/src/core/context/parser/async.ts +67 -84
- package/src/core/context/parser/stream.ts +64 -109
- package/src/core/context/parser/sync.ts +66 -83
- package/src/core/context/parser.ts +24 -56
- package/src/core/context/serializer.ts +12 -128
- package/src/core/cross/index.ts +2 -6
- package/src/core/function-string.ts +31 -0
- package/src/core/special-reference.ts +96 -8
- package/src/core/tree/serializer.ts +0 -7
- package/src/core/types.ts +5 -27
- package/dist/types/core/abort-signal.d.ts +0 -2
- package/dist/types/core/abort-signal.d.ts.map +0 -1
- package/src/core/abort-signal.ts +0 -13
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createEffectfulFunction, createFunction } from './function-string';
|
|
2
|
+
|
|
1
3
|
export const ITERATOR = {};
|
|
2
4
|
|
|
3
5
|
export const ASYNC_ITERATOR = {};
|
|
@@ -5,11 +7,9 @@ export const ASYNC_ITERATOR = {};
|
|
|
5
7
|
export const enum SpecialReference {
|
|
6
8
|
MapSentinel = 0,
|
|
7
9
|
PromiseConstructor = 1,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
PromiseSuccess = 2,
|
|
11
|
+
PromiseFailure = 3,
|
|
10
12
|
StreamConstructor = 4,
|
|
11
|
-
AbortSignalConstructor = 5,
|
|
12
|
-
AbortSignalAbort = 6,
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -18,9 +18,97 @@ export const enum SpecialReference {
|
|
|
18
18
|
export const SPECIAL_REFS: Record<SpecialReference, unknown> = {
|
|
19
19
|
[SpecialReference.MapSentinel]: {},
|
|
20
20
|
[SpecialReference.PromiseConstructor]: {},
|
|
21
|
-
[SpecialReference.
|
|
22
|
-
[SpecialReference.
|
|
21
|
+
[SpecialReference.PromiseSuccess]: {},
|
|
22
|
+
[SpecialReference.PromiseFailure]: {},
|
|
23
23
|
[SpecialReference.StreamConstructor]: {},
|
|
24
|
-
[SpecialReference.AbortSignalConstructor]: {},
|
|
25
|
-
[SpecialReference.AbortSignalAbort]: {},
|
|
26
24
|
};
|
|
25
|
+
|
|
26
|
+
function serializePromiseConstructor(features: number): string {
|
|
27
|
+
return createFunction(
|
|
28
|
+
features,
|
|
29
|
+
['r'],
|
|
30
|
+
'(r.p=new Promise(' +
|
|
31
|
+
createEffectfulFunction(features, ['s', 'f'], 'r.s=s,r.f=f') +
|
|
32
|
+
'))',
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function serializePromiseSuccess(features: number): string {
|
|
37
|
+
return createEffectfulFunction(
|
|
38
|
+
features,
|
|
39
|
+
['r', 'd'],
|
|
40
|
+
'r.s(d),r.p.s=1,r.p.v=d',
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function serializePromiseFailure(features: number): string {
|
|
45
|
+
return createEffectfulFunction(
|
|
46
|
+
features,
|
|
47
|
+
['r', 'd'],
|
|
48
|
+
'r.f(d),r.p.s=2,r.p.v=d',
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function serializeStreamConstructor(features: number): string {
|
|
53
|
+
return createFunction(
|
|
54
|
+
features,
|
|
55
|
+
['b', 'a', 's', 'l', 'p', 'f', 'e', 'n'],
|
|
56
|
+
'(b=[],a=!0,s=!1,l=[],p=0,f=' +
|
|
57
|
+
createEffectfulFunction(
|
|
58
|
+
features,
|
|
59
|
+
['v', 'm', 'x'],
|
|
60
|
+
'for(x=0;x<p;x++)l[x]&&l[x][m](v)',
|
|
61
|
+
) +
|
|
62
|
+
',n=' +
|
|
63
|
+
createEffectfulFunction(
|
|
64
|
+
features,
|
|
65
|
+
['o', 'x', 'z', 'c'],
|
|
66
|
+
'for(x=0,z=b.length;x<z;x++)(c=b[x],(!a&&x===z-1)?o[s?"return":"throw"](c):o.next(c))',
|
|
67
|
+
) +
|
|
68
|
+
',e=' +
|
|
69
|
+
createFunction(
|
|
70
|
+
features,
|
|
71
|
+
['o', 't'],
|
|
72
|
+
'(a&&(l[t=p++]=o),n(o),' +
|
|
73
|
+
createEffectfulFunction(features, [], 'a&&(l[t]=void 0)') +
|
|
74
|
+
')',
|
|
75
|
+
) +
|
|
76
|
+
',{__SEROVAL_STREAM__:!0,on:' +
|
|
77
|
+
createFunction(features, ['o'], 'e(o)') +
|
|
78
|
+
',next:' +
|
|
79
|
+
createEffectfulFunction(features, ['v'], 'a&&(b.push(v),f(v,"next"))') +
|
|
80
|
+
',throw:' +
|
|
81
|
+
createEffectfulFunction(
|
|
82
|
+
features,
|
|
83
|
+
['v'],
|
|
84
|
+
'a&&(b.push(v),f(v,"throw"),a=s=!1,l.length=0)',
|
|
85
|
+
) +
|
|
86
|
+
',return:' +
|
|
87
|
+
createEffectfulFunction(
|
|
88
|
+
features,
|
|
89
|
+
['v'],
|
|
90
|
+
'a&&(b.push(v),f(v,"return"),a=!1,s=!0,l.length=0)',
|
|
91
|
+
) +
|
|
92
|
+
'})',
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function serializeSpecialReferenceValue(
|
|
97
|
+
features: number,
|
|
98
|
+
ref: SpecialReference,
|
|
99
|
+
): string {
|
|
100
|
+
switch (ref) {
|
|
101
|
+
case SpecialReference.MapSentinel:
|
|
102
|
+
return '[]';
|
|
103
|
+
case SpecialReference.PromiseConstructor:
|
|
104
|
+
return serializePromiseConstructor(features);
|
|
105
|
+
case SpecialReference.PromiseSuccess:
|
|
106
|
+
return serializePromiseSuccess(features);
|
|
107
|
+
case SpecialReference.PromiseFailure:
|
|
108
|
+
return serializePromiseFailure(features);
|
|
109
|
+
case SpecialReference.StreamConstructor:
|
|
110
|
+
return serializeStreamConstructor(features);
|
|
111
|
+
default:
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -4,7 +4,6 @@ import BaseSerializerContext from '../context/serializer';
|
|
|
4
4
|
import { SerovalUnsupportedNodeError } from '../errors';
|
|
5
5
|
import type { SerovalMode } from '../plugin';
|
|
6
6
|
import type {
|
|
7
|
-
SerovalAbortSignalAbortNode,
|
|
8
7
|
SerovalNode,
|
|
9
8
|
SerovalPromiseConstructorNode,
|
|
10
9
|
SerovalPromiseRejectNode,
|
|
@@ -74,12 +73,6 @@ export default class VanillaSerializerContext extends BaseSerializerContext {
|
|
|
74
73
|
throw new SerovalUnsupportedNodeError(node);
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
protected serializeAbortSignalAbort(
|
|
78
|
-
node: SerovalAbortSignalAbortNode,
|
|
79
|
-
): string {
|
|
80
|
-
throw new SerovalUnsupportedNodeError(node);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
76
|
serializeTop(tree: SerovalNode): string {
|
|
84
77
|
const result = this.serialize(tree);
|
|
85
78
|
// Shared references detected
|
package/src/core/types.ts
CHANGED
|
@@ -245,17 +245,18 @@ export interface SerovalBoxedNode extends SerovalBaseNode {
|
|
|
245
245
|
export interface SerovalPromiseConstructorNode extends SerovalBaseNode {
|
|
246
246
|
t: SerovalNodeType.PromiseConstructor;
|
|
247
247
|
i: number;
|
|
248
|
+
s: number;
|
|
248
249
|
f: SerovalNodeWithID;
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
export interface SerovalPromiseResolveNode extends SerovalBaseNode {
|
|
252
|
-
t: SerovalNodeType.
|
|
253
|
+
t: SerovalNodeType.PromiseSuccess;
|
|
253
254
|
i: number;
|
|
254
255
|
a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
|
|
255
256
|
}
|
|
256
257
|
|
|
257
258
|
export interface SerovalPromiseRejectNode extends SerovalBaseNode {
|
|
258
|
-
t: SerovalNodeType.
|
|
259
|
+
t: SerovalNodeType.PromiseFailure;
|
|
259
260
|
i: number;
|
|
260
261
|
a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
|
|
261
262
|
}
|
|
@@ -330,26 +331,6 @@ export interface SerovalStreamReturnNode extends SerovalBaseNode {
|
|
|
330
331
|
f: SerovalNode;
|
|
331
332
|
}
|
|
332
333
|
|
|
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
|
|
350
|
-
f: SerovalNode;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
334
|
export type SerovalSyncNode =
|
|
354
335
|
| SerovalPrimitiveNode
|
|
355
336
|
| SerovalIndexedValueNode
|
|
@@ -372,8 +353,7 @@ export type SerovalSyncNode =
|
|
|
372
353
|
| SerovalIteratorFactoryNode
|
|
373
354
|
| SerovalIteratorFactoryInstanceNode
|
|
374
355
|
| SerovalAsyncIteratorFactoryNode
|
|
375
|
-
| SerovalAsyncIteratorFactoryInstanceNode
|
|
376
|
-
| SerovalAbortSignalSyncNode;
|
|
356
|
+
| SerovalAsyncIteratorFactoryInstanceNode;
|
|
377
357
|
|
|
378
358
|
export type SerovalAsyncNode =
|
|
379
359
|
| SerovalPromiseNode
|
|
@@ -383,9 +363,7 @@ export type SerovalAsyncNode =
|
|
|
383
363
|
| SerovalStreamConstructorNode
|
|
384
364
|
| SerovalStreamNextNode
|
|
385
365
|
| SerovalStreamThrowNode
|
|
386
|
-
| SerovalStreamReturnNode
|
|
387
|
-
| SerovalAbortSignalConstructorNode
|
|
388
|
-
| SerovalAbortSignalAbortNode;
|
|
366
|
+
| SerovalStreamReturnNode;
|
|
389
367
|
|
|
390
368
|
export type SerovalNode = SerovalSyncNode | SerovalAsyncNode;
|
|
391
369
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"abort-signal.d.ts","sourceRoot":"","sources":["../../../src/core/abort-signal.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAYtE"}
|
package/src/core/abort-signal.ts
DELETED