seroval 0.14.0 → 0.14.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 +147 -112
- package/dist/cjs/development/index.cjs.map +2 -2
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +147 -112
- package/dist/esm/development/index.mjs.map +2 -2
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/base-primitives.d.ts +3 -3
- package/dist/types/core/base-primitives.d.ts.map +1 -1
- package/dist/types/core/constants.d.ts +2 -3
- package/dist/types/core/constants.d.ts.map +1 -1
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/parser/stream.d.ts.map +1 -1
- package/dist/types/core/context/parser.d.ts +3 -3
- package/dist/types/core/context/parser.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts +11 -10
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/dist/types/core/cross/serializer.d.ts +1 -8
- package/dist/types/core/cross/serializer.d.ts.map +1 -1
- package/dist/types/core/keys.d.ts +0 -12
- package/dist/types/core/keys.d.ts.map +1 -1
- package/dist/types/core/special-reference.d.ts +13 -3
- package/dist/types/core/special-reference.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +33 -20
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/core/web-api.d.ts +2 -2
- package/dist/types/core/web-api.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/core/base-primitives.ts +3 -2
- package/src/core/constants.ts +1 -2
- package/src/core/context/deserializer.ts +6 -7
- package/src/core/context/parser/async.ts +2 -2
- package/src/core/context/parser/stream.ts +29 -13
- package/src/core/context/parser.ts +12 -36
- package/src/core/context/serializer.ts +105 -44
- package/src/core/cross/serializer.ts +0 -57
- package/src/core/keys.ts +0 -36
- package/src/core/special-reference.ts +23 -3
- package/src/core/types.ts +33 -24
- package/src/core/web-api.ts +2 -1
- package/src/index.ts +1 -1
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '../constants';
|
|
9
9
|
import { REFERENCES_KEY } from '../keys';
|
|
10
10
|
import type { Plugin, PluginAccessOptions, SerovalMode } from '../plugin';
|
|
11
|
+
import { SpecialReference } from '../special-reference';
|
|
11
12
|
import type {
|
|
12
13
|
SerovalArrayNode,
|
|
13
14
|
SerovalIndexedValueNode,
|
|
@@ -49,13 +50,13 @@ import type {
|
|
|
49
50
|
SerovalReadableStreamEnqueueNode,
|
|
50
51
|
SerovalReadableStreamErrorNode,
|
|
51
52
|
SerovalReadableStreamCloseNode,
|
|
52
|
-
SerovalMapSentinelNode,
|
|
53
53
|
SerovalIteratorFactoryInstanceNode,
|
|
54
54
|
SerovalIteratorFactoryNode,
|
|
55
55
|
SerovalAsyncIteratorFactoryInstanceNode,
|
|
56
56
|
SerovalAsyncIteratorFactoryNode,
|
|
57
57
|
SerovalReadableStreamNode,
|
|
58
|
-
|
|
58
|
+
SerovalSpecialReferenceNode,
|
|
59
|
+
SerovalNodeWithID,
|
|
59
60
|
} from '../types';
|
|
60
61
|
import { isValidIdentifier } from '../utils/is-valid-identifier';
|
|
61
62
|
|
|
@@ -746,7 +747,7 @@ export default abstract class BaseSerializerContext implements PluginAccessOptio
|
|
|
746
747
|
serialized += '([' + result + '])';
|
|
747
748
|
}
|
|
748
749
|
}
|
|
749
|
-
if (sentinel.t === SerovalNodeType.
|
|
750
|
+
if (sentinel.t === SerovalNodeType.SpecialReference) {
|
|
750
751
|
this.markRef(sentinel.i);
|
|
751
752
|
serialized = '(' + this.serialize(sentinel) + ',' + serialized + ')';
|
|
752
753
|
}
|
|
@@ -986,38 +987,118 @@ export default abstract class BaseSerializerContext implements PluginAccessOptio
|
|
|
986
987
|
throw new Error('Missing plugin for tag "' + node.c + '".');
|
|
987
988
|
}
|
|
988
989
|
|
|
989
|
-
|
|
990
|
+
private getConstructor(node: SerovalNodeWithID): string {
|
|
991
|
+
const constructor = this.serialize(node);
|
|
992
|
+
return (constructor === this.getRefParam(node.i)) ? constructor : ('(' + constructor + ')');
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
protected serializePromiseConstructor(
|
|
990
996
|
node: SerovalPromiseConstructorNode,
|
|
991
|
-
): string
|
|
997
|
+
): string {
|
|
998
|
+
return this.assignIndexedValue(
|
|
999
|
+
node.i,
|
|
1000
|
+
this.getConstructor(node.f) + '()',
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
992
1003
|
|
|
993
|
-
protected
|
|
1004
|
+
protected serializePromiseResolve(
|
|
994
1005
|
node: SerovalPromiseResolveNode,
|
|
995
|
-
): string
|
|
1006
|
+
): string {
|
|
1007
|
+
return this.getConstructor(node.a[0]) + '(' + this.getRefParam(node.i) + ',' + this.serialize(node.a[1]) + ')';
|
|
1008
|
+
}
|
|
996
1009
|
|
|
997
|
-
protected
|
|
1010
|
+
protected serializePromiseReject(
|
|
998
1011
|
node: SerovalPromiseRejectNode,
|
|
999
|
-
): string
|
|
1012
|
+
): string {
|
|
1013
|
+
return this.getConstructor(node.a[0]) + '(' + this.getRefParam(node.i) + ',' + this.serialize(node.a[1]) + ')';
|
|
1014
|
+
}
|
|
1000
1015
|
|
|
1001
|
-
protected
|
|
1016
|
+
protected serializeReadableStreamConstructor(
|
|
1002
1017
|
node: SerovalReadableStreamConstructorNode,
|
|
1003
|
-
): string
|
|
1018
|
+
): string {
|
|
1019
|
+
return this.assignIndexedValue(
|
|
1020
|
+
node.i,
|
|
1021
|
+
this.getConstructor(node.f) + '()',
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1004
1024
|
|
|
1005
|
-
protected
|
|
1025
|
+
protected serializeReadableStreamEnqueue(
|
|
1006
1026
|
node: SerovalReadableStreamEnqueueNode,
|
|
1007
|
-
): string
|
|
1027
|
+
): string {
|
|
1028
|
+
return this.getConstructor(node.a[0]) + '(' + this.getRefParam(node.i) + ',' + this.serialize(node.a[1]) + ')';
|
|
1029
|
+
}
|
|
1008
1030
|
|
|
1009
|
-
protected
|
|
1031
|
+
protected serializeReadableStreamError(
|
|
1010
1032
|
node: SerovalReadableStreamErrorNode,
|
|
1011
|
-
): string
|
|
1033
|
+
): string {
|
|
1034
|
+
return this.getConstructor(node.a[0]) + '(' + this.getRefParam(node.i) + ',' + this.serialize(node.a[1]) + ')';
|
|
1035
|
+
}
|
|
1012
1036
|
|
|
1013
|
-
protected
|
|
1037
|
+
protected serializeReadableStreamClose(
|
|
1014
1038
|
node: SerovalReadableStreamCloseNode,
|
|
1015
|
-
): string
|
|
1039
|
+
): string {
|
|
1040
|
+
return this.getConstructor(node.f) + '(' + this.getRefParam(node.i) + ')';
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
private serializeSpecialReferenceValue(ref: SpecialReference): string {
|
|
1044
|
+
switch (ref) {
|
|
1045
|
+
case SpecialReference.MapSentinel:
|
|
1046
|
+
return '[]';
|
|
1047
|
+
case SpecialReference.ReadableStream:
|
|
1048
|
+
return this.createFunction(
|
|
1049
|
+
['s'],
|
|
1050
|
+
'new ReadableStream({start:' + this.createFunction(
|
|
1051
|
+
['c'],
|
|
1052
|
+
'Promise.resolve().then(' + this.createEffectfulFunction(
|
|
1053
|
+
['i', 'v'],
|
|
1054
|
+
'for(i=0;i<s.d;i++)c.enqueue(s.v[i]);(s.t===-1)?c.close():c.error(s.v[i])',
|
|
1055
|
+
) + ')',
|
|
1056
|
+
) + '})',
|
|
1057
|
+
);
|
|
1058
|
+
case SpecialReference.PromiseConstructor:
|
|
1059
|
+
return this.createFunction(
|
|
1060
|
+
['s', 'f', 'p'],
|
|
1061
|
+
'((p=new Promise(' + this.createEffectfulFunction(['a', 'b'], 's=a,f=b') + ')).s=s,p.f=f,p)',
|
|
1062
|
+
);
|
|
1063
|
+
case SpecialReference.PromiseResolve:
|
|
1064
|
+
return this.createEffectfulFunction(
|
|
1065
|
+
['p', 'd'],
|
|
1066
|
+
'p.s(d),p.status="success",p.value=d;delete p.s;delete p.f',
|
|
1067
|
+
);
|
|
1068
|
+
case SpecialReference.PromiseReject:
|
|
1069
|
+
return this.createEffectfulFunction(
|
|
1070
|
+
['p', 'd'],
|
|
1071
|
+
'p.f(d),p.status="failure",p.value=d;delete p.s;delete p.f',
|
|
1072
|
+
);
|
|
1073
|
+
case SpecialReference.ReadableStreamConstructor:
|
|
1074
|
+
return this.createFunction(
|
|
1075
|
+
['s', 'c'],
|
|
1076
|
+
'((s=new ReadableStream({start:' + this.createEffectfulFunction(['x'], 'c=x') + '})).c=c,s)',
|
|
1077
|
+
);
|
|
1078
|
+
case SpecialReference.ReadableStreamEnqueue:
|
|
1079
|
+
return this.createEffectfulFunction(
|
|
1080
|
+
['s', 'd'],
|
|
1081
|
+
's.c.enqueue(d)',
|
|
1082
|
+
);
|
|
1083
|
+
case SpecialReference.ReadableStreamError:
|
|
1084
|
+
return this.createEffectfulFunction(
|
|
1085
|
+
['s', 'd'],
|
|
1086
|
+
's.c.error(d);delete s.c',
|
|
1087
|
+
);
|
|
1088
|
+
case SpecialReference.ReadableStreamClose:
|
|
1089
|
+
return this.createEffectfulFunction(
|
|
1090
|
+
['s'],
|
|
1091
|
+
's.c.close();delete s.c',
|
|
1092
|
+
);
|
|
1093
|
+
default:
|
|
1094
|
+
return '';
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1016
1097
|
|
|
1017
|
-
protected
|
|
1098
|
+
protected serializeSpecialReference(node: SerovalSpecialReferenceNode): string {
|
|
1018
1099
|
return this.assignIndexedValue(
|
|
1019
1100
|
node.i,
|
|
1020
|
-
|
|
1101
|
+
this.serializeSpecialReferenceValue(node.s),
|
|
1021
1102
|
);
|
|
1022
1103
|
}
|
|
1023
1104
|
|
|
@@ -1038,7 +1119,7 @@ export default abstract class BaseSerializerContext implements PluginAccessOptio
|
|
|
1038
1119
|
protected serializeIteratorFactoryInstance(
|
|
1039
1120
|
node: SerovalIteratorFactoryInstanceNode,
|
|
1040
1121
|
): string {
|
|
1041
|
-
return
|
|
1122
|
+
return this.getConstructor(node.a[0]) + '(' + this.serialize(node.a[1]) + ')';
|
|
1042
1123
|
}
|
|
1043
1124
|
|
|
1044
1125
|
private getStreamingAsyncIteratorFactory(node: SerovalAsyncIteratorFactoryNode): string {
|
|
@@ -1087,14 +1168,14 @@ export default abstract class BaseSerializerContext implements PluginAccessOptio
|
|
|
1087
1168
|
protected serializeAsyncIteratorFactoryInstance(
|
|
1088
1169
|
node: SerovalAsyncIteratorFactoryInstanceNode,
|
|
1089
1170
|
): string {
|
|
1090
|
-
return
|
|
1171
|
+
return this.getConstructor(node.a[0]) + '(' + this.serialize(node.a[1]) + ')';
|
|
1091
1172
|
}
|
|
1092
1173
|
|
|
1093
1174
|
protected serializeReadableStream(
|
|
1094
1175
|
node: SerovalReadableStreamNode,
|
|
1095
1176
|
): string {
|
|
1096
1177
|
this.stack.push(node.i);
|
|
1097
|
-
const result =
|
|
1178
|
+
const result = this.getConstructor(node.a[0]) + '(' + this.serialize(node.a[1]) + ')';
|
|
1098
1179
|
this.stack.pop();
|
|
1099
1180
|
return this.assignIndexedValue(
|
|
1100
1181
|
node.i,
|
|
@@ -1102,24 +1183,6 @@ export default abstract class BaseSerializerContext implements PluginAccessOptio
|
|
|
1102
1183
|
);
|
|
1103
1184
|
}
|
|
1104
1185
|
|
|
1105
|
-
protected serializeReadableStreamFactory(
|
|
1106
|
-
node: SerovalReadableStreamFactoryNode,
|
|
1107
|
-
): string {
|
|
1108
|
-
return this.assignIndexedValue(
|
|
1109
|
-
node.i,
|
|
1110
|
-
this.createFunction(
|
|
1111
|
-
['s'],
|
|
1112
|
-
'new ReadableStream({start:' + this.createFunction(
|
|
1113
|
-
['c'],
|
|
1114
|
-
'Promise.resolve().then(' + this.createEffectfulFunction(
|
|
1115
|
-
['i', 'v'],
|
|
1116
|
-
'for(i=0;i<s.d;i++)c.enqueue(s.v[i]);(s.t===-1)?c.close():c.error(s.v[i])',
|
|
1117
|
-
) + ')',
|
|
1118
|
-
) + '})',
|
|
1119
|
-
),
|
|
1120
|
-
);
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
1186
|
serialize(node: SerovalNode): string {
|
|
1124
1187
|
switch (node.t) {
|
|
1125
1188
|
case SerovalNodeType.Constant:
|
|
@@ -1203,8 +1266,8 @@ export default abstract class BaseSerializerContext implements PluginAccessOptio
|
|
|
1203
1266
|
return this.serializeDOMException(node);
|
|
1204
1267
|
case SerovalNodeType.Plugin:
|
|
1205
1268
|
return this.serializePlugin(node);
|
|
1206
|
-
case SerovalNodeType.
|
|
1207
|
-
return this.
|
|
1269
|
+
case SerovalNodeType.SpecialReference:
|
|
1270
|
+
return this.serializeSpecialReference(node);
|
|
1208
1271
|
case SerovalNodeType.IteratorFactory:
|
|
1209
1272
|
return this.serializeIteratorFactory(node);
|
|
1210
1273
|
case SerovalNodeType.IteratorFactoryInstance:
|
|
@@ -1215,8 +1278,6 @@ export default abstract class BaseSerializerContext implements PluginAccessOptio
|
|
|
1215
1278
|
return this.serializeAsyncIteratorFactoryInstance(node);
|
|
1216
1279
|
case SerovalNodeType.ReadableStream:
|
|
1217
1280
|
return this.serializeReadableStream(node);
|
|
1218
|
-
case SerovalNodeType.ReadableStreamFactory:
|
|
1219
|
-
return this.serializeReadableStreamFactory(node);
|
|
1220
1281
|
default:
|
|
1221
1282
|
throw new Error('invariant');
|
|
1222
1283
|
}
|
|
@@ -1,23 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
SerovalPromiseConstructorNode,
|
|
3
|
-
SerovalPromiseResolveNode,
|
|
4
|
-
SerovalPromiseRejectNode,
|
|
5
|
-
SerovalReadableStreamCloseNode,
|
|
6
|
-
SerovalReadableStreamEnqueueNode,
|
|
7
|
-
SerovalReadableStreamErrorNode,
|
|
8
|
-
SerovalReadableStreamConstructorNode,
|
|
9
2
|
SerovalNode,
|
|
10
3
|
} from '../types';
|
|
11
4
|
import {
|
|
12
|
-
GLOBAL_CONTEXT_PROMISE_REJECT,
|
|
13
|
-
GLOBAL_CONTEXT_PROMISE_RESOLVE,
|
|
14
|
-
GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR,
|
|
15
5
|
GLOBAL_CONTEXT_REFERENCES,
|
|
16
|
-
GLOBAL_CONTEXT_STREAM_CONSTRUCTOR,
|
|
17
|
-
GLOBAL_CONTEXT_STREAM_ENQUEUE,
|
|
18
|
-
GLOBAL_CONTEXT_STREAM_CLOSE,
|
|
19
|
-
GLOBAL_CONTEXT_STREAM_ERROR,
|
|
20
|
-
GLOBAL_CONTEXT_API,
|
|
21
6
|
} from '../keys';
|
|
22
7
|
import type { BaseSerializerContextOptions } from '../context/serializer';
|
|
23
8
|
import BaseSerializerContext from '../context/serializer';
|
|
@@ -53,48 +38,6 @@ export default class CrossSerializerContext extends BaseSerializerContext {
|
|
|
53
38
|
return this.getRefParam(index) + '=' + value;
|
|
54
39
|
}
|
|
55
40
|
|
|
56
|
-
protected serializePromiseConstructor(
|
|
57
|
-
node: SerovalPromiseConstructorNode,
|
|
58
|
-
): string {
|
|
59
|
-
return this.assignIndexedValue(node.i, GLOBAL_CONTEXT_API + '.' + GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR + '()');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
protected serializePromiseResolve(
|
|
63
|
-
node: SerovalPromiseResolveNode,
|
|
64
|
-
): string {
|
|
65
|
-
return GLOBAL_CONTEXT_API + '.' + GLOBAL_CONTEXT_PROMISE_RESOLVE + '(' + this.getRefParam(node.i) + ',' + this.serialize(node.f) + ')';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
protected serializePromiseReject(
|
|
69
|
-
node: SerovalPromiseRejectNode,
|
|
70
|
-
): string {
|
|
71
|
-
return GLOBAL_CONTEXT_API + '.' + GLOBAL_CONTEXT_PROMISE_REJECT + '(' + this.getRefParam(node.i) + ',' + this.serialize(node.f) + ')';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
protected serializeReadableStreamConstructor(
|
|
75
|
-
node: SerovalReadableStreamConstructorNode,
|
|
76
|
-
): string {
|
|
77
|
-
return this.assignIndexedValue(node.i, GLOBAL_CONTEXT_API + '.' + GLOBAL_CONTEXT_STREAM_CONSTRUCTOR + '()');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
protected serializeReadableStreamEnqueue(
|
|
81
|
-
node: SerovalReadableStreamEnqueueNode,
|
|
82
|
-
): string {
|
|
83
|
-
return GLOBAL_CONTEXT_API + '.' + GLOBAL_CONTEXT_STREAM_ENQUEUE + '(' + this.getRefParam(node.i) + ',' + this.serialize(node.f) + ')';
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
protected serializeReadableStreamError(
|
|
87
|
-
node: SerovalReadableStreamErrorNode,
|
|
88
|
-
): string {
|
|
89
|
-
return GLOBAL_CONTEXT_API + '.' + GLOBAL_CONTEXT_STREAM_ERROR + '(' + this.getRefParam(node.i) + ',' + this.serialize(node.f) + ')';
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
protected serializeReadableStreamClose(
|
|
93
|
-
node: SerovalReadableStreamCloseNode,
|
|
94
|
-
): string {
|
|
95
|
-
return GLOBAL_CONTEXT_API + '.' + GLOBAL_CONTEXT_STREAM_CLOSE + '(' + this.getRefParam(node.i) + ')';
|
|
96
|
-
}
|
|
97
|
-
|
|
98
41
|
serializeTop(tree: SerovalNode): string {
|
|
99
42
|
const result = this.serialize(tree);
|
|
100
43
|
const id = tree.i;
|
package/src/core/keys.ts
CHANGED
|
@@ -3,44 +3,8 @@ import { serializeString } from './string';
|
|
|
3
3
|
// Used for mapping isomorphic references
|
|
4
4
|
export const REFERENCES_KEY = '__SEROVAL_REFS__';
|
|
5
5
|
|
|
6
|
-
export const GLOBAL_CONTEXT_API = '_$';
|
|
7
|
-
|
|
8
6
|
export const GLOBAL_CONTEXT_REFERENCES = '$R';
|
|
9
7
|
|
|
10
|
-
export const LOCAL_CONTEXT_PROMISE_RESOLVE = 's';
|
|
11
|
-
|
|
12
|
-
export const LOCAL_CONTEXT_PROMISE_REJECT = 'f';
|
|
13
|
-
|
|
14
|
-
export const GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR = 'P';
|
|
15
|
-
|
|
16
|
-
export const GLOBAL_CONTEXT_PROMISE_RESOLVE = 'Ps';
|
|
17
|
-
|
|
18
|
-
export const GLOBAL_CONTEXT_PROMISE_REJECT = 'Pf';
|
|
19
|
-
|
|
20
|
-
export const LOCAL_CONTEXT_STREAM_CONTROLLER = 'c';
|
|
21
|
-
|
|
22
|
-
export const GLOBAL_CONTEXT_STREAM_CONSTRUCTOR = 'S';
|
|
23
|
-
|
|
24
|
-
export const GLOBAL_CONTEXT_STREAM_ENQUEUE = 'Se';
|
|
25
|
-
|
|
26
|
-
export const GLOBAL_CONTEXT_STREAM_ERROR = 'St';
|
|
27
|
-
|
|
28
|
-
export const GLOBAL_CONTEXT_STREAM_CLOSE = 'Sc';
|
|
29
|
-
|
|
30
|
-
const GLOBAL_CONTEXT_API_REF = `self.${GLOBAL_CONTEXT_API}`;
|
|
31
|
-
|
|
32
|
-
export const GLOBAL_CONTEXT_API_SCRIPT = `${GLOBAL_CONTEXT_API_REF}=${GLOBAL_CONTEXT_API_REF}||{`
|
|
33
|
-
+ `${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR}:function(s,f,p){return(p=new Promise(function(a,b){s=a,f=b})).${LOCAL_CONTEXT_PROMISE_RESOLVE}=s,p.${LOCAL_CONTEXT_PROMISE_REJECT}=f,p},`
|
|
34
|
-
+ `uP:function(p){delete p.${LOCAL_CONTEXT_PROMISE_RESOLVE};delete p.${LOCAL_CONTEXT_PROMISE_REJECT}},`
|
|
35
|
-
+ `${GLOBAL_CONTEXT_PROMISE_RESOLVE}:function(p,d){p.${LOCAL_CONTEXT_PROMISE_RESOLVE}(d),p.status="success",p.value=d,this.uP(p)},`
|
|
36
|
-
+ `${GLOBAL_CONTEXT_PROMISE_REJECT}:function(p,d){p.${LOCAL_CONTEXT_PROMISE_REJECT}(d),p.status="failure",p.value=d,this.uP(p)},`
|
|
37
|
-
+ `uS:function(s){delete s.${LOCAL_CONTEXT_STREAM_CONTROLLER}},`
|
|
38
|
-
+ `${GLOBAL_CONTEXT_STREAM_CLOSE}:function(s){s.${LOCAL_CONTEXT_STREAM_CONTROLLER}.close(),this.uS(s)},`
|
|
39
|
-
+ `${GLOBAL_CONTEXT_STREAM_ERROR}:function(s,e){s.${LOCAL_CONTEXT_STREAM_CONTROLLER}.error(e),this.uS(s)},`
|
|
40
|
-
+ `${GLOBAL_CONTEXT_STREAM_ENQUEUE}:function(s,d){s.${LOCAL_CONTEXT_STREAM_CONTROLLER}.enqueue(d)},`
|
|
41
|
-
+ `${GLOBAL_CONTEXT_STREAM_CONSTRUCTOR}:function(s,c){return(s=new ReadableStream({start:function(x){c=x}})).${LOCAL_CONTEXT_STREAM_CONTROLLER}=c,s}`
|
|
42
|
-
+ '}';
|
|
43
|
-
|
|
44
8
|
const GLOBAL_CONTEXT_R = `self.${GLOBAL_CONTEXT_REFERENCES}`;
|
|
45
9
|
|
|
46
10
|
export function getCrossReferenceHeader(id?: string): string {
|
|
@@ -1,9 +1,29 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const UNIVERSAL_SENTINEL = {};
|
|
2
2
|
|
|
3
3
|
export const ITERATOR = {};
|
|
4
4
|
|
|
5
5
|
export const ASYNC_ITERATOR = {};
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const enum SpecialReference {
|
|
8
|
+
MapSentinel = 0,
|
|
9
|
+
ReadableStream = 1,
|
|
10
|
+
PromiseConstructor = 2,
|
|
11
|
+
PromiseResolve = 3,
|
|
12
|
+
PromiseReject = 4,
|
|
13
|
+
ReadableStreamConstructor = 5,
|
|
14
|
+
ReadableStreamEnqueue = 6,
|
|
15
|
+
ReadableStreamError = 7,
|
|
16
|
+
ReadableStreamClose = 8,
|
|
17
|
+
}
|
|
8
18
|
|
|
9
|
-
export const
|
|
19
|
+
export const SPECIAL_REFS: Record<SpecialReference, unknown> = {
|
|
20
|
+
[SpecialReference.MapSentinel]: {},
|
|
21
|
+
[SpecialReference.ReadableStream]: {},
|
|
22
|
+
[SpecialReference.PromiseConstructor]: {},
|
|
23
|
+
[SpecialReference.PromiseResolve]: {},
|
|
24
|
+
[SpecialReference.PromiseReject]: {},
|
|
25
|
+
[SpecialReference.ReadableStreamConstructor]: {},
|
|
26
|
+
[SpecialReference.ReadableStreamEnqueue]: {},
|
|
27
|
+
[SpecialReference.ReadableStreamError]: {},
|
|
28
|
+
[SpecialReference.ReadableStreamClose]: {},
|
|
29
|
+
};
|
package/src/core/types.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
Symbols,
|
|
6
6
|
ErrorConstructorTag,
|
|
7
7
|
} from './constants';
|
|
8
|
+
import type { SpecialReference } from './special-reference';
|
|
8
9
|
|
|
9
10
|
export interface SerovalBaseNode {
|
|
10
11
|
// Type of the node
|
|
@@ -162,7 +163,7 @@ export interface SerovalMapNode extends SerovalBaseNode {
|
|
|
162
163
|
i: number;
|
|
163
164
|
// key/value pairs
|
|
164
165
|
e: SerovalMapRecordNode;
|
|
165
|
-
f:
|
|
166
|
+
f: SerovalNodeWithID;
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
export interface SerovalArrayNode extends SerovalBaseNode {
|
|
@@ -300,42 +301,55 @@ export interface SerovalBoxedNode extends SerovalBaseNode {
|
|
|
300
301
|
export interface SerovalPromiseConstructorNode extends SerovalBaseNode {
|
|
301
302
|
t: SerovalNodeType.PromiseConstructor;
|
|
302
303
|
i: number;
|
|
304
|
+
f: SerovalNodeWithID;
|
|
303
305
|
}
|
|
304
306
|
|
|
305
307
|
export interface SerovalPromiseResolveNode extends SerovalBaseNode {
|
|
306
308
|
t: SerovalNodeType.PromiseResolve;
|
|
307
|
-
// reference to the resolver
|
|
308
309
|
i: number;
|
|
309
|
-
|
|
310
|
+
a: [
|
|
311
|
+
resolver: SerovalNodeWithID,
|
|
312
|
+
resolved: SerovalNode,
|
|
313
|
+
];
|
|
310
314
|
}
|
|
311
315
|
|
|
312
316
|
export interface SerovalPromiseRejectNode extends SerovalBaseNode {
|
|
313
317
|
t: SerovalNodeType.PromiseReject;
|
|
314
|
-
// reference to the resolver
|
|
315
318
|
i: number;
|
|
316
|
-
|
|
319
|
+
a: [
|
|
320
|
+
resolver: SerovalNodeWithID,
|
|
321
|
+
resolved: SerovalNode,
|
|
322
|
+
];
|
|
317
323
|
}
|
|
318
324
|
|
|
319
325
|
export interface SerovalReadableStreamConstructorNode extends SerovalBaseNode {
|
|
320
326
|
t: SerovalNodeType.ReadableStreamConstructor;
|
|
321
327
|
i: number;
|
|
328
|
+
f: SerovalNodeWithID;
|
|
322
329
|
}
|
|
323
330
|
|
|
324
331
|
export interface SerovalReadableStreamEnqueueNode extends SerovalBaseNode {
|
|
325
332
|
t: SerovalNodeType.ReadableStreamEnqueue;
|
|
326
333
|
i: number;
|
|
327
|
-
|
|
334
|
+
a: [
|
|
335
|
+
resolver: SerovalNodeWithID,
|
|
336
|
+
resolved: SerovalNode,
|
|
337
|
+
];
|
|
328
338
|
}
|
|
329
339
|
|
|
330
|
-
export interface
|
|
331
|
-
t: SerovalNodeType.
|
|
340
|
+
export interface SerovalReadableStreamErrorNode extends SerovalBaseNode {
|
|
341
|
+
t: SerovalNodeType.ReadableStreamError;
|
|
332
342
|
i: number;
|
|
343
|
+
a: [
|
|
344
|
+
resolver: SerovalNodeWithID,
|
|
345
|
+
resolved: SerovalNode,
|
|
346
|
+
];
|
|
333
347
|
}
|
|
334
348
|
|
|
335
|
-
export interface
|
|
336
|
-
t: SerovalNodeType.
|
|
349
|
+
export interface SerovalReadableStreamCloseNode extends SerovalBaseNode {
|
|
350
|
+
t: SerovalNodeType.ReadableStreamClose;
|
|
337
351
|
i: number;
|
|
338
|
-
f:
|
|
352
|
+
f: SerovalNodeWithID;
|
|
339
353
|
}
|
|
340
354
|
|
|
341
355
|
export interface SerovalRequestNode extends SerovalBaseNode {
|
|
@@ -389,9 +403,10 @@ export interface SerovalPluginNode extends SerovalBaseNode {
|
|
|
389
403
|
c: string;
|
|
390
404
|
}
|
|
391
405
|
|
|
392
|
-
export interface
|
|
393
|
-
t: SerovalNodeType.
|
|
406
|
+
export interface SerovalSpecialReferenceNode extends SerovalBaseNode {
|
|
407
|
+
t: SerovalNodeType.SpecialReference;
|
|
394
408
|
i: number;
|
|
409
|
+
s: SpecialReference;
|
|
395
410
|
}
|
|
396
411
|
|
|
397
412
|
export interface SerovalIteratorFactoryNode extends SerovalBaseNode {
|
|
@@ -403,7 +418,7 @@ export interface SerovalIteratorFactoryNode extends SerovalBaseNode {
|
|
|
403
418
|
export interface SerovalIteratorFactoryInstanceNode extends SerovalBaseNode {
|
|
404
419
|
t: SerovalNodeType.IteratorFactoryInstance;
|
|
405
420
|
a: [
|
|
406
|
-
instance:
|
|
421
|
+
instance: SerovalNodeWithID,
|
|
407
422
|
sequence: SerovalNode,
|
|
408
423
|
];
|
|
409
424
|
}
|
|
@@ -418,7 +433,7 @@ export interface SerovalAsyncIteratorFactoryNode extends SerovalBaseNode {
|
|
|
418
433
|
export interface SerovalAsyncIteratorFactoryInstanceNode extends SerovalBaseNode {
|
|
419
434
|
t: SerovalNodeType.AsyncIteratorFactoryInstance;
|
|
420
435
|
a: [
|
|
421
|
-
instance:
|
|
436
|
+
instance: SerovalNodeWithID,
|
|
422
437
|
sequence: SerovalNode,
|
|
423
438
|
];
|
|
424
439
|
}
|
|
@@ -427,16 +442,11 @@ export interface SerovalReadableStreamNode extends SerovalBaseNode {
|
|
|
427
442
|
t: SerovalNodeType.ReadableStream;
|
|
428
443
|
i: number;
|
|
429
444
|
a: [
|
|
430
|
-
instance:
|
|
445
|
+
instance: SerovalNodeWithID,
|
|
431
446
|
sequence: SerovalNode,
|
|
432
447
|
];
|
|
433
448
|
}
|
|
434
449
|
|
|
435
|
-
export interface SerovalReadableStreamFactoryNode extends SerovalBaseNode {
|
|
436
|
-
t: SerovalNodeType.ReadableStreamFactory;
|
|
437
|
-
i: number;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
450
|
export type SerovalSyncNode =
|
|
441
451
|
| SerovalPrimitiveNode
|
|
442
452
|
| SerovalIndexedValueNode
|
|
@@ -464,7 +474,7 @@ export type SerovalSyncNode =
|
|
|
464
474
|
| SerovalCustomEventNode
|
|
465
475
|
| SerovalDOMExceptionNode
|
|
466
476
|
| SerovalPluginNode
|
|
467
|
-
|
|
|
477
|
+
| SerovalSpecialReferenceNode
|
|
468
478
|
| SerovalIteratorFactoryNode
|
|
469
479
|
| SerovalIteratorFactoryInstanceNode
|
|
470
480
|
| SerovalAsyncIteratorFactoryNode
|
|
@@ -483,8 +493,7 @@ export type SerovalAsyncNode =
|
|
|
483
493
|
| SerovalReadableStreamErrorNode
|
|
484
494
|
| SerovalRequestNode
|
|
485
495
|
| SerovalResponseNode
|
|
486
|
-
| SerovalReadableStreamNode
|
|
487
|
-
| SerovalReadableStreamFactoryNode;
|
|
496
|
+
| SerovalReadableStreamNode;
|
|
488
497
|
|
|
489
498
|
export type SerovalNode =
|
|
490
499
|
| SerovalSyncNode
|
package/src/core/web-api.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
SerovalDOMExceptionNode,
|
|
6
6
|
SerovalEventNode,
|
|
7
7
|
SerovalNode,
|
|
8
|
+
SerovalNodeWithID,
|
|
8
9
|
SerovalReadableStreamNode,
|
|
9
10
|
SerovalURLNode,
|
|
10
11
|
SerovalURLSearchParamsNode,
|
|
@@ -114,7 +115,7 @@ export function createCustomEventNode(
|
|
|
114
115
|
|
|
115
116
|
export function createReadableStreamNode(
|
|
116
117
|
id: number,
|
|
117
|
-
factory:
|
|
118
|
+
factory: SerovalNodeWithID,
|
|
118
119
|
items: SerovalNode,
|
|
119
120
|
): SerovalReadableStreamNode {
|
|
120
121
|
return {
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { createReference } from './core/reference';
|
|
|
14
14
|
export * from './core/tree';
|
|
15
15
|
export * from './core/cross';
|
|
16
16
|
|
|
17
|
-
export {
|
|
17
|
+
export { getCrossReferenceHeader } from './core/keys';
|
|
18
18
|
|
|
19
19
|
export { default as Serializer } from './core/Serializer';
|
|
20
20
|
export * from './core/plugin';
|