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.
- package/README.md +3 -3
- package/dist/cjs/development/index.cjs +1221 -1867
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +1222 -1868
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/Serializer.d.ts +2 -1
- package/dist/types/core/Serializer.d.ts.map +1 -1
- package/dist/types/core/UnsupportedTypeError.d.ts.map +1 -1
- package/dist/types/core/base-primitives.d.ts +6 -2
- package/dist/types/core/base-primitives.d.ts.map +1 -1
- package/dist/types/core/compat.d.ts +5 -13
- package/dist/types/core/compat.d.ts.map +1 -1
- package/dist/types/core/constants.d.ts +17 -29
- package/dist/types/core/constants.d.ts.map +1 -1
- package/dist/types/core/context/deserializer.d.ts +6 -16
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/parser/async.d.ts +2 -11
- package/dist/types/core/context/parser/async.d.ts.map +1 -1
- package/dist/types/core/context/parser/stream.d.ts +10 -10
- package/dist/types/core/context/parser/stream.d.ts.map +1 -1
- package/dist/types/core/context/parser/sync.d.ts +5 -7
- package/dist/types/core/context/parser/sync.d.ts.map +1 -1
- package/dist/types/core/context/parser.d.ts +19 -4
- package/dist/types/core/context/parser.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts +11 -25
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/dist/types/core/cross/async.d.ts.map +1 -1
- package/dist/types/core/cross/deserializer.d.ts.map +1 -1
- package/dist/types/core/cross/index.d.ts.map +1 -1
- package/dist/types/core/cross/parser.d.ts.map +1 -1
- package/dist/types/core/cross/serializer.d.ts +1 -1
- package/dist/types/core/cross/serializer.d.ts.map +1 -1
- package/dist/types/core/cross/stream.d.ts.map +1 -1
- package/dist/types/core/cross/sync.d.ts.map +1 -1
- package/dist/types/core/keys.d.ts.map +1 -1
- package/dist/types/core/literals.d.ts.map +1 -1
- package/dist/types/core/plugin.d.ts +21 -0
- package/dist/types/core/plugin.d.ts.map +1 -1
- package/dist/types/core/reference.d.ts.map +1 -1
- package/dist/types/core/special-reference.d.ts +4 -9
- package/dist/types/core/special-reference.d.ts.map +1 -1
- package/dist/types/core/stream.d.ts +18 -0
- package/dist/types/core/stream.d.ts.map +1 -0
- package/dist/types/core/string.d.ts.map +1 -1
- package/dist/types/core/tree/async.d.ts.map +1 -1
- package/dist/types/core/tree/deserializer.d.ts.map +1 -1
- package/dist/types/core/tree/index.d.ts +1 -1
- package/dist/types/core/tree/index.d.ts.map +1 -1
- package/dist/types/core/tree/serializer.d.ts +3 -11
- package/dist/types/core/tree/serializer.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +28 -122
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/core/utils/deferred.d.ts +0 -7
- package/dist/types/core/utils/deferred.d.ts.map +1 -1
- package/dist/types/core/utils/error.d.ts +2 -1
- package/dist/types/core/utils/error.d.ts.map +1 -1
- package/dist/types/core/utils/get-identifier.d.ts.map +1 -1
- package/dist/types/core/utils/is-valid-identifier.d.ts.map +1 -1
- package/dist/types/core/utils/iterator-to-sequence.d.ts +0 -12
- package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -1
- package/dist/types/core/utils/typed-array.d.ts +2 -0
- package/dist/types/core/utils/typed-array.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -3
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/core/Serializer.ts +44 -28
- package/src/core/UnsupportedTypeError.ts +2 -3
- package/src/core/base-primitives.ts +124 -38
- package/src/core/compat.ts +5 -14
- package/src/core/constants.ts +28 -39
- package/src/core/context/deserializer.ts +122 -308
- package/src/core/context/parser/async.ts +163 -375
- package/src/core/context/parser/stream.ts +109 -367
- package/src/core/context/parser/sync.ts +139 -266
- package/src/core/context/parser.ts +93 -68
- package/src/core/context/serializer.ts +370 -439
- package/src/core/cross/async.ts +1 -1
- package/src/core/cross/deserializer.ts +1 -4
- package/src/core/cross/index.ts +26 -20
- package/src/core/cross/parser.ts +1 -1
- package/src/core/cross/serializer.ts +30 -20
- package/src/core/cross/stream.ts +1 -1
- package/src/core/cross/sync.ts +1 -1
- package/src/core/keys.ts +3 -1
- package/src/core/literals.ts +22 -8
- package/src/core/plugin.ts +48 -10
- package/src/core/reference.ts +4 -5
- package/src/core/special-reference.ts +5 -15
- package/src/core/stream.ts +205 -0
- package/src/core/string.ts +53 -22
- package/src/core/tree/async.ts +1 -1
- package/src/core/tree/deserializer.ts +4 -9
- package/src/core/tree/index.ts +15 -10
- package/src/core/tree/serializer.ts +6 -50
- package/src/core/types.ts +39 -179
- package/src/core/utils/deferred.ts +0 -27
- package/src/core/utils/error.ts +26 -15
- package/src/core/utils/get-identifier.ts +5 -4
- package/src/core/utils/is-valid-identifier.ts +6 -5
- package/src/core/utils/iterator-to-sequence.ts +0 -174
- package/src/core/utils/typed-array.ts +35 -11
- package/src/index.ts +3 -12
- package/dist/types/core/utils/constructors.d.ts +0 -5
- package/dist/types/core/utils/constructors.d.ts.map +0 -1
- package/dist/types/core/web-api.d.ts +0 -8
- package/dist/types/core/web-api.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -21
- package/dist/types/types.d.ts.map +0 -1
- package/src/core/utils/constructors.ts +0 -49
- package/src/core/web-api.ts +0 -138
- package/src/example.ts +0 -25
- package/src/types.ts +0 -84
package/src/core/string.ts
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
export function serializeChar(str: string): string | undefined {
|
|
2
2
|
switch (str) {
|
|
3
|
-
case '"':
|
|
4
|
-
|
|
5
|
-
case '
|
|
6
|
-
|
|
7
|
-
case '\
|
|
8
|
-
|
|
9
|
-
case '\
|
|
10
|
-
|
|
11
|
-
case '\
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
case '"':
|
|
4
|
+
return '\\"';
|
|
5
|
+
case '\\':
|
|
6
|
+
return '\\\\';
|
|
7
|
+
case '\n':
|
|
8
|
+
return '\\n';
|
|
9
|
+
case '\r':
|
|
10
|
+
return '\\r';
|
|
11
|
+
case '\b':
|
|
12
|
+
return '\\b';
|
|
13
|
+
case '\t':
|
|
14
|
+
return '\\t';
|
|
15
|
+
case '\f':
|
|
16
|
+
return '\\f';
|
|
17
|
+
case '<':
|
|
18
|
+
return '\\x3C';
|
|
19
|
+
case '\u2028':
|
|
20
|
+
return '\\u2028';
|
|
21
|
+
case '\u2029':
|
|
22
|
+
return '\\u2029';
|
|
23
|
+
default:
|
|
24
|
+
return undefined;
|
|
14
25
|
}
|
|
15
26
|
}
|
|
16
27
|
|
|
@@ -38,16 +49,36 @@ export function serializeString(str: string): string {
|
|
|
38
49
|
return result;
|
|
39
50
|
}
|
|
40
51
|
|
|
52
|
+
function deserializeReplacer(str: string): string {
|
|
53
|
+
switch (str) {
|
|
54
|
+
case '\\\\':
|
|
55
|
+
return '\\';
|
|
56
|
+
case '\\"':
|
|
57
|
+
return '"';
|
|
58
|
+
case '\\n':
|
|
59
|
+
return '\n';
|
|
60
|
+
case '\\r':
|
|
61
|
+
return '\r';
|
|
62
|
+
case '\\b':
|
|
63
|
+
return '\b';
|
|
64
|
+
case '\\t':
|
|
65
|
+
return '\t';
|
|
66
|
+
case '\\f':
|
|
67
|
+
return '\f';
|
|
68
|
+
case '\\x3C':
|
|
69
|
+
return '\x3C';
|
|
70
|
+
case '\\u2028':
|
|
71
|
+
return '\u2028';
|
|
72
|
+
case '\\u2029':
|
|
73
|
+
return '\u2029';
|
|
74
|
+
default:
|
|
75
|
+
return str;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
41
79
|
export function deserializeString(str: string): string {
|
|
42
|
-
return str
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.replace(/\\r/g, '\r')
|
|
47
|
-
.replace(/\\b/g, '\b')
|
|
48
|
-
.replace(/\\t/g, '\t')
|
|
49
|
-
.replace(/\\f/g, '\f')
|
|
50
|
-
.replace(/\\x3C/g, '<')
|
|
51
|
-
.replace(/\\u2028/g, '\u2028')
|
|
52
|
-
.replace(/\\u2029/g, '\u2029');
|
|
80
|
+
return str.replace(
|
|
81
|
+
/(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g,
|
|
82
|
+
deserializeReplacer,
|
|
83
|
+
);
|
|
53
84
|
}
|
package/src/core/tree/async.ts
CHANGED
|
@@ -2,7 +2,7 @@ import BaseAsyncParserContext from '../context/parser/async';
|
|
|
2
2
|
import type { BaseParserContextOptions } from '../context/parser';
|
|
3
3
|
import type { SerovalMode } from '../plugin';
|
|
4
4
|
|
|
5
|
-
export type AsyncParserContextOptions = Omit<BaseParserContextOptions, 'refs'
|
|
5
|
+
export type AsyncParserContextOptions = Omit<BaseParserContextOptions, 'refs'>;
|
|
6
6
|
|
|
7
7
|
export default class AsyncParserContext extends BaseAsyncParserContext {
|
|
8
8
|
readonly mode: SerovalMode = 'vanilla';
|
|
@@ -2,7 +2,8 @@ import BaseDeserializerContext from '../context/deserializer';
|
|
|
2
2
|
import type { BaseDeserializerOptions } from '../context/deserializer';
|
|
3
3
|
import type { SerovalMode } from '../plugin';
|
|
4
4
|
|
|
5
|
-
export interface VanillaDeserializerContextOptions
|
|
5
|
+
export interface VanillaDeserializerContextOptions
|
|
6
|
+
extends Omit<BaseDeserializerOptions, 'refs'> {
|
|
6
7
|
markedRefs: number[] | Set<number>;
|
|
7
8
|
}
|
|
8
9
|
|
|
@@ -12,17 +13,11 @@ export default class VanillaDeserializerContext extends BaseDeserializerContext
|
|
|
12
13
|
marked: Set<number>;
|
|
13
14
|
|
|
14
15
|
constructor(options: VanillaDeserializerContextOptions) {
|
|
15
|
-
super(
|
|
16
|
-
plugins: options.plugins,
|
|
17
|
-
refs: undefined,
|
|
18
|
-
});
|
|
16
|
+
super(options);
|
|
19
17
|
this.marked = new Set(options.markedRefs);
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
assignIndexedValue<T>(
|
|
23
|
-
index: number,
|
|
24
|
-
value: T,
|
|
25
|
-
): T {
|
|
20
|
+
assignIndexedValue<T>(index: number, value: T): T {
|
|
26
21
|
if (this.marked.has(index)) {
|
|
27
22
|
this.refs.set(index, value);
|
|
28
23
|
}
|
package/src/core/tree/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { resolvePlugins, type PluginAccessOptions } from '../plugin';
|
|
2
2
|
import type { SerovalNode } from '../types';
|
|
3
3
|
import type { AsyncParserContextOptions } from './async';
|
|
4
4
|
import AsyncParserContext from './async';
|
|
@@ -11,13 +11,14 @@ export function serialize<T>(
|
|
|
11
11
|
source: T,
|
|
12
12
|
options: SyncParserContextOptions = {},
|
|
13
13
|
): string {
|
|
14
|
+
const plugins = resolvePlugins(options.plugins);
|
|
14
15
|
const ctx = new SyncParserContext({
|
|
15
|
-
plugins
|
|
16
|
+
plugins,
|
|
16
17
|
disabledFeatures: options.disabledFeatures,
|
|
17
18
|
});
|
|
18
19
|
const tree = ctx.parse(source);
|
|
19
20
|
const serial = new VanillaSerializerContext({
|
|
20
|
-
plugins
|
|
21
|
+
plugins,
|
|
21
22
|
features: ctx.features,
|
|
22
23
|
markedRefs: ctx.marked,
|
|
23
24
|
});
|
|
@@ -28,13 +29,14 @@ export async function serializeAsync<T>(
|
|
|
28
29
|
source: T,
|
|
29
30
|
options: AsyncParserContextOptions = {},
|
|
30
31
|
): Promise<string> {
|
|
32
|
+
const plugins = resolvePlugins(options.plugins);
|
|
31
33
|
const ctx = new AsyncParserContext({
|
|
32
|
-
plugins
|
|
34
|
+
plugins,
|
|
33
35
|
disabledFeatures: options.disabledFeatures,
|
|
34
36
|
});
|
|
35
37
|
const tree = await ctx.parse(source);
|
|
36
38
|
const serial = new VanillaSerializerContext({
|
|
37
|
-
plugins
|
|
39
|
+
plugins,
|
|
38
40
|
features: ctx.features,
|
|
39
41
|
markedRefs: ctx.marked,
|
|
40
42
|
});
|
|
@@ -42,7 +44,6 @@ export async function serializeAsync<T>(
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export function deserialize<T>(source: string): T {
|
|
45
|
-
// eslint-disable-next-line no-eval
|
|
46
47
|
return (0, eval)(source) as T;
|
|
47
48
|
}
|
|
48
49
|
|
|
@@ -56,8 +57,9 @@ export function toJSON<T>(
|
|
|
56
57
|
source: T,
|
|
57
58
|
options: SyncParserContextOptions = {},
|
|
58
59
|
): SerovalJSON {
|
|
60
|
+
const plugins = resolvePlugins(options.plugins);
|
|
59
61
|
const ctx = new SyncParserContext({
|
|
60
|
-
plugins
|
|
62
|
+
plugins,
|
|
61
63
|
disabledFeatures: options.disabledFeatures,
|
|
62
64
|
});
|
|
63
65
|
return {
|
|
@@ -71,8 +73,9 @@ export async function toJSONAsync<T>(
|
|
|
71
73
|
source: T,
|
|
72
74
|
options: AsyncParserContextOptions = {},
|
|
73
75
|
): Promise<SerovalJSON> {
|
|
76
|
+
const plugins = resolvePlugins(options.plugins);
|
|
74
77
|
const ctx = new AsyncParserContext({
|
|
75
|
-
plugins
|
|
78
|
+
plugins,
|
|
76
79
|
disabledFeatures: options.disabledFeatures,
|
|
77
80
|
});
|
|
78
81
|
return {
|
|
@@ -83,8 +86,9 @@ export async function toJSONAsync<T>(
|
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
export function compileJSON(source: SerovalJSON, options: PluginAccessOptions = {}): string {
|
|
89
|
+
const plugins = resolvePlugins(options.plugins);
|
|
86
90
|
const ctx = new VanillaSerializerContext({
|
|
87
|
-
plugins
|
|
91
|
+
plugins,
|
|
88
92
|
features: source.f,
|
|
89
93
|
markedRefs: source.m,
|
|
90
94
|
});
|
|
@@ -92,8 +96,9 @@ export function compileJSON(source: SerovalJSON, options: PluginAccessOptions =
|
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
export function fromJSON<T>(source: SerovalJSON, options: PluginAccessOptions = {}): T {
|
|
99
|
+
const plugins = resolvePlugins(options.plugins);
|
|
95
100
|
const ctx = new VanillaDeserializerContext({
|
|
96
|
-
plugins
|
|
101
|
+
plugins,
|
|
97
102
|
markedRefs: source.m,
|
|
98
103
|
});
|
|
99
104
|
return ctx.deserialize(source.t) as T;
|
|
@@ -3,10 +3,6 @@ import type {
|
|
|
3
3
|
SerovalPromiseConstructorNode,
|
|
4
4
|
SerovalPromiseRejectNode,
|
|
5
5
|
SerovalPromiseResolveNode,
|
|
6
|
-
SerovalReadableStreamCloseNode,
|
|
7
|
-
SerovalReadableStreamConstructorNode,
|
|
8
|
-
SerovalReadableStreamEnqueueNode,
|
|
9
|
-
SerovalReadableStreamErrorNode,
|
|
10
6
|
} from '../types';
|
|
11
7
|
import type { BaseSerializerContextOptions } from '../context/serializer';
|
|
12
8
|
import BaseSerializerContext from '../context/serializer';
|
|
@@ -14,7 +10,7 @@ import getIdentifier from '../utils/get-identifier';
|
|
|
14
10
|
import type { SerovalMode } from '../plugin';
|
|
15
11
|
import { SerovalNodeType } from '../constants';
|
|
16
12
|
|
|
17
|
-
export type VanillaSerializerContextOptions = BaseSerializerContextOptions
|
|
13
|
+
export type VanillaSerializerContextOptions = BaseSerializerContextOptions;
|
|
18
14
|
|
|
19
15
|
export default class VanillaSerializerContext extends BaseSerializerContext {
|
|
20
16
|
readonly mode: SerovalMode = 'vanilla';
|
|
@@ -23,7 +19,7 @@ export default class VanillaSerializerContext extends BaseSerializerContext {
|
|
|
23
19
|
* Map tree refs to actual refs
|
|
24
20
|
* @private
|
|
25
21
|
*/
|
|
26
|
-
valid = new Map<number
|
|
22
|
+
valid = new Map<number, number>();
|
|
27
23
|
|
|
28
24
|
/**
|
|
29
25
|
* Variables
|
|
@@ -31,20 +27,11 @@ export default class VanillaSerializerContext extends BaseSerializerContext {
|
|
|
31
27
|
*/
|
|
32
28
|
vars: string[] = [];
|
|
33
29
|
|
|
34
|
-
/**
|
|
35
|
-
* Increments the number of references the referenced value has
|
|
36
|
-
*/
|
|
37
|
-
markRef(
|
|
38
|
-
current: number,
|
|
39
|
-
): void {
|
|
40
|
-
this.marked.add(current);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
30
|
/**
|
|
44
31
|
* Creates the reference param (identifier) from the given reference ID
|
|
45
32
|
* Calling this function means the value has been referenced somewhere
|
|
46
33
|
*/
|
|
47
|
-
getRefParam(index: number
|
|
34
|
+
getRefParam(index: number): string {
|
|
48
35
|
/**
|
|
49
36
|
* Creates a new reference ID from a given reference ID
|
|
50
37
|
* This new reference ID means that the reference itself
|
|
@@ -64,10 +51,7 @@ export default class VanillaSerializerContext extends BaseSerializerContext {
|
|
|
64
51
|
return identifier;
|
|
65
52
|
}
|
|
66
53
|
|
|
67
|
-
protected assignIndexedValue(
|
|
68
|
-
index: number,
|
|
69
|
-
value: string,
|
|
70
|
-
): string {
|
|
54
|
+
protected assignIndexedValue(index: number, value: string): string {
|
|
71
55
|
if (this.isMarked(index)) {
|
|
72
56
|
return this.getRefParam(index) + '=' + value;
|
|
73
57
|
}
|
|
@@ -80,39 +64,11 @@ export default class VanillaSerializerContext extends BaseSerializerContext {
|
|
|
80
64
|
throw new Error('Unsupported node type "' + node.t + '".');
|
|
81
65
|
}
|
|
82
66
|
|
|
83
|
-
protected serializePromiseResolve(
|
|
84
|
-
node: SerovalPromiseResolveNode,
|
|
85
|
-
): string {
|
|
86
|
-
throw new Error('Unsupported node type "' + node.t + '".');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
protected serializePromiseReject(
|
|
90
|
-
node: SerovalPromiseRejectNode,
|
|
91
|
-
): string {
|
|
67
|
+
protected serializePromiseResolve(node: SerovalPromiseResolveNode): string {
|
|
92
68
|
throw new Error('Unsupported node type "' + node.t + '".');
|
|
93
69
|
}
|
|
94
70
|
|
|
95
|
-
protected
|
|
96
|
-
node: SerovalReadableStreamConstructorNode,
|
|
97
|
-
): string {
|
|
98
|
-
throw new Error('Unsupported node type "' + node.t + '".');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
protected serializeReadableStreamEnqueue(
|
|
102
|
-
node: SerovalReadableStreamEnqueueNode,
|
|
103
|
-
): string {
|
|
104
|
-
throw new Error('Unsupported node type "' + node.t + '".');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
protected serializeReadableStreamError(
|
|
108
|
-
node: SerovalReadableStreamErrorNode,
|
|
109
|
-
): string {
|
|
110
|
-
throw new Error('Unsupported node type "' + node.t + '".');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
protected serializeReadableStreamClose(
|
|
114
|
-
node: SerovalReadableStreamCloseNode,
|
|
115
|
-
): string {
|
|
71
|
+
protected serializePromiseReject(node: SerovalPromiseRejectNode): string {
|
|
116
72
|
throw new Error('Unsupported node type "' + node.t + '".');
|
|
117
73
|
}
|
|
118
74
|
|
package/src/core/types.ts
CHANGED
|
@@ -22,8 +22,8 @@ export interface SerovalBaseNode {
|
|
|
22
22
|
m: string | undefined;
|
|
23
23
|
// properties (objects)
|
|
24
24
|
p: SerovalObjectRecordNode | undefined;
|
|
25
|
-
// entries (for Map,
|
|
26
|
-
e: SerovalMapRecordNode |
|
|
25
|
+
// entries (for Map, etc.)
|
|
26
|
+
e: SerovalMapRecordNode | undefined;
|
|
27
27
|
// array of nodes
|
|
28
28
|
a: (SerovalNode | undefined)[] | undefined;
|
|
29
29
|
// fulfilled node
|
|
@@ -34,15 +34,7 @@ export interface SerovalBaseNode {
|
|
|
34
34
|
o: SerovalObjectFlags | undefined;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export type SerovalObjectRecordKey =
|
|
38
|
-
| string
|
|
39
|
-
| SerovalNode;
|
|
40
|
-
|
|
41
|
-
export interface SerovalPlainRecordNode {
|
|
42
|
-
k: string[];
|
|
43
|
-
v: SerovalNode[];
|
|
44
|
-
s: number;
|
|
45
|
-
}
|
|
37
|
+
export type SerovalObjectRecordKey = string | SerovalNode;
|
|
46
38
|
|
|
47
39
|
export interface SerovalObjectRecordNode {
|
|
48
40
|
k: SerovalObjectRecordKey[];
|
|
@@ -226,20 +218,6 @@ export interface SerovalWKSymbolNode extends SerovalBaseNode {
|
|
|
226
218
|
s: Symbols;
|
|
227
219
|
}
|
|
228
220
|
|
|
229
|
-
export interface SerovalURLNode extends SerovalBaseNode {
|
|
230
|
-
t: SerovalNodeType.URL;
|
|
231
|
-
i: number;
|
|
232
|
-
// raw URL
|
|
233
|
-
s: string;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export interface SerovalURLSearchParamsNode extends SerovalBaseNode {
|
|
237
|
-
t: SerovalNodeType.URLSearchParams;
|
|
238
|
-
i: number;
|
|
239
|
-
// raw URL search params
|
|
240
|
-
s: string;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
221
|
export interface SerovalReferenceNode extends SerovalBaseNode {
|
|
244
222
|
t: SerovalNodeType.Reference;
|
|
245
223
|
i: number;
|
|
@@ -258,40 +236,6 @@ export interface SerovalDataViewNode extends SerovalBaseNode {
|
|
|
258
236
|
b: number;
|
|
259
237
|
}
|
|
260
238
|
|
|
261
|
-
export interface SerovalBlobNode extends SerovalBaseNode {
|
|
262
|
-
t: SerovalNodeType.Blob;
|
|
263
|
-
i: number;
|
|
264
|
-
// file type
|
|
265
|
-
c: string;
|
|
266
|
-
// reference to array buffer
|
|
267
|
-
f: SerovalNode;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export interface SerovalFileNode extends SerovalBaseNode {
|
|
271
|
-
t: SerovalNodeType.File;
|
|
272
|
-
i: number;
|
|
273
|
-
// file type
|
|
274
|
-
c: string;
|
|
275
|
-
// file name
|
|
276
|
-
m: string;
|
|
277
|
-
// reference to array buffer
|
|
278
|
-
f: SerovalNode;
|
|
279
|
-
// last modified
|
|
280
|
-
b: number;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export interface SerovalHeadersNode extends SerovalBaseNode {
|
|
284
|
-
t: SerovalNodeType.Headers;
|
|
285
|
-
i: number;
|
|
286
|
-
e: SerovalPlainRecordNode;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export interface SerovalFormDataNode extends SerovalBaseNode {
|
|
290
|
-
t: SerovalNodeType.FormData;
|
|
291
|
-
i: number;
|
|
292
|
-
e: SerovalPlainRecordNode;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
239
|
export interface SerovalBoxedNode extends SerovalBaseNode {
|
|
296
240
|
t: SerovalNodeType.Boxed;
|
|
297
241
|
i: number;
|
|
@@ -307,91 +251,13 @@ export interface SerovalPromiseConstructorNode extends SerovalBaseNode {
|
|
|
307
251
|
export interface SerovalPromiseResolveNode extends SerovalBaseNode {
|
|
308
252
|
t: SerovalNodeType.PromiseResolve;
|
|
309
253
|
i: number;
|
|
310
|
-
a: [
|
|
311
|
-
resolver: SerovalNodeWithID,
|
|
312
|
-
resolved: SerovalNode,
|
|
313
|
-
];
|
|
254
|
+
a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
|
|
314
255
|
}
|
|
315
256
|
|
|
316
257
|
export interface SerovalPromiseRejectNode extends SerovalBaseNode {
|
|
317
258
|
t: SerovalNodeType.PromiseReject;
|
|
318
259
|
i: number;
|
|
319
|
-
a: [
|
|
320
|
-
resolver: SerovalNodeWithID,
|
|
321
|
-
resolved: SerovalNode,
|
|
322
|
-
];
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export interface SerovalReadableStreamConstructorNode extends SerovalBaseNode {
|
|
326
|
-
t: SerovalNodeType.ReadableStreamConstructor;
|
|
327
|
-
i: number;
|
|
328
|
-
f: SerovalNodeWithID;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
export interface SerovalReadableStreamEnqueueNode extends SerovalBaseNode {
|
|
332
|
-
t: SerovalNodeType.ReadableStreamEnqueue;
|
|
333
|
-
i: number;
|
|
334
|
-
a: [
|
|
335
|
-
resolver: SerovalNodeWithID,
|
|
336
|
-
resolved: SerovalNode,
|
|
337
|
-
];
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export interface SerovalReadableStreamErrorNode extends SerovalBaseNode {
|
|
341
|
-
t: SerovalNodeType.ReadableStreamError;
|
|
342
|
-
i: number;
|
|
343
|
-
a: [
|
|
344
|
-
resolver: SerovalNodeWithID,
|
|
345
|
-
resolved: SerovalNode,
|
|
346
|
-
];
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
export interface SerovalReadableStreamCloseNode extends SerovalBaseNode {
|
|
350
|
-
t: SerovalNodeType.ReadableStreamClose;
|
|
351
|
-
i: number;
|
|
352
|
-
f: SerovalNodeWithID;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export interface SerovalRequestNode extends SerovalBaseNode {
|
|
356
|
-
t: SerovalNodeType.Request;
|
|
357
|
-
i: number;
|
|
358
|
-
// Request URL
|
|
359
|
-
s: string;
|
|
360
|
-
// This is just a shortcut for serializing the option fields
|
|
361
|
-
f: SerovalNode;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
export interface SerovalResponseNode extends SerovalBaseNode {
|
|
365
|
-
t: SerovalNodeType.Response;
|
|
366
|
-
i: number;
|
|
367
|
-
// This is just a shortcut for serializing the option fields
|
|
368
|
-
a: [body: SerovalNode, options: SerovalNode];
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export interface SerovalEventNode extends SerovalBaseNode {
|
|
372
|
-
t: SerovalNodeType.Event;
|
|
373
|
-
i: number;
|
|
374
|
-
// Event type
|
|
375
|
-
s: string;
|
|
376
|
-
// Event options
|
|
377
|
-
f: SerovalNode;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
export interface SerovalCustomEventNode extends SerovalBaseNode {
|
|
381
|
-
t: SerovalNodeType.CustomEvent;
|
|
382
|
-
i: number;
|
|
383
|
-
// Event type
|
|
384
|
-
s: string;
|
|
385
|
-
f: SerovalNode;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
export interface SerovalDOMExceptionNode extends SerovalBaseNode {
|
|
389
|
-
t: SerovalNodeType.DOMException;
|
|
390
|
-
i: number;
|
|
391
|
-
// Message
|
|
392
|
-
s: string;
|
|
393
|
-
// name
|
|
394
|
-
c: string;
|
|
260
|
+
a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
|
|
395
261
|
}
|
|
396
262
|
|
|
397
263
|
export interface SerovalPluginNode extends SerovalBaseNode {
|
|
@@ -412,39 +278,49 @@ export interface SerovalSpecialReferenceNode extends SerovalBaseNode {
|
|
|
412
278
|
export interface SerovalIteratorFactoryNode extends SerovalBaseNode {
|
|
413
279
|
t: SerovalNodeType.IteratorFactory;
|
|
414
280
|
i: number;
|
|
415
|
-
f:
|
|
281
|
+
f: SerovalNodeWithID;
|
|
416
282
|
}
|
|
417
283
|
|
|
418
284
|
export interface SerovalIteratorFactoryInstanceNode extends SerovalBaseNode {
|
|
419
285
|
t: SerovalNodeType.IteratorFactoryInstance;
|
|
420
|
-
a: [
|
|
421
|
-
instance: SerovalNodeWithID,
|
|
422
|
-
sequence: SerovalNode,
|
|
423
|
-
];
|
|
286
|
+
a: [instance: SerovalNodeWithID, sequence: SerovalNode];
|
|
424
287
|
}
|
|
425
288
|
|
|
426
289
|
export interface SerovalAsyncIteratorFactoryNode extends SerovalBaseNode {
|
|
427
290
|
t: SerovalNodeType.AsyncIteratorFactory;
|
|
428
291
|
i: number;
|
|
429
|
-
|
|
430
|
-
f: SerovalNode;
|
|
292
|
+
a: [promise: SerovalNodeWithID, symbol: SerovalNodeWithID];
|
|
431
293
|
}
|
|
432
294
|
|
|
433
|
-
export interface SerovalAsyncIteratorFactoryInstanceNode
|
|
295
|
+
export interface SerovalAsyncIteratorFactoryInstanceNode
|
|
296
|
+
extends SerovalBaseNode {
|
|
434
297
|
t: SerovalNodeType.AsyncIteratorFactoryInstance;
|
|
435
|
-
a: [
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
298
|
+
a: [instance: SerovalNodeWithID, sequence: SerovalNode];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export interface SerovalStreamConstructorNode extends SerovalBaseNode {
|
|
302
|
+
t: SerovalNodeType.StreamConstructor;
|
|
303
|
+
i: number;
|
|
304
|
+
a: SerovalNode[];
|
|
305
|
+
f: SerovalNodeWithID;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export interface SerovalStreamNextNode extends SerovalBaseNode {
|
|
309
|
+
t: SerovalNodeType.StreamNext;
|
|
310
|
+
i: number;
|
|
311
|
+
f: SerovalNode;
|
|
439
312
|
}
|
|
440
313
|
|
|
441
|
-
export interface
|
|
442
|
-
t: SerovalNodeType.
|
|
314
|
+
export interface SerovalStreamThrowNode extends SerovalBaseNode {
|
|
315
|
+
t: SerovalNodeType.StreamThrow;
|
|
443
316
|
i: number;
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
317
|
+
f: SerovalNode;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export interface SerovalStreamReturnNode extends SerovalBaseNode {
|
|
321
|
+
t: SerovalNodeType.StreamReturn;
|
|
322
|
+
i: number;
|
|
323
|
+
f: SerovalNode;
|
|
448
324
|
}
|
|
449
325
|
|
|
450
326
|
export type SerovalSyncNode =
|
|
@@ -460,19 +336,10 @@ export type SerovalSyncNode =
|
|
|
460
336
|
| SerovalErrorNode
|
|
461
337
|
| SerovalAggregateErrorNode
|
|
462
338
|
| SerovalWKSymbolNode
|
|
463
|
-
| SerovalURLNode
|
|
464
|
-
| SerovalURLSearchParamsNode
|
|
465
339
|
| SerovalReferenceNode
|
|
466
340
|
| SerovalArrayBufferNode
|
|
467
341
|
| SerovalDataViewNode
|
|
468
|
-
| SerovalBlobNode
|
|
469
|
-
| SerovalFileNode
|
|
470
|
-
| SerovalHeadersNode
|
|
471
|
-
| SerovalFormDataNode
|
|
472
342
|
| SerovalBoxedNode
|
|
473
|
-
| SerovalEventNode
|
|
474
|
-
| SerovalCustomEventNode
|
|
475
|
-
| SerovalDOMExceptionNode
|
|
476
343
|
| SerovalPluginNode
|
|
477
344
|
| SerovalSpecialReferenceNode
|
|
478
345
|
| SerovalIteratorFactoryNode
|
|
@@ -482,21 +349,14 @@ export type SerovalSyncNode =
|
|
|
482
349
|
|
|
483
350
|
export type SerovalAsyncNode =
|
|
484
351
|
| SerovalPromiseNode
|
|
485
|
-
| SerovalBlobNode
|
|
486
|
-
| SerovalFileNode
|
|
487
352
|
| SerovalPromiseConstructorNode
|
|
488
353
|
| SerovalPromiseResolveNode
|
|
489
354
|
| SerovalPromiseRejectNode
|
|
490
|
-
|
|
|
491
|
-
|
|
|
492
|
-
|
|
|
493
|
-
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
| SerovalReadableStreamNode;
|
|
497
|
-
|
|
498
|
-
export type SerovalNode =
|
|
499
|
-
| SerovalSyncNode
|
|
500
|
-
| SerovalAsyncNode;
|
|
355
|
+
| SerovalStreamConstructorNode
|
|
356
|
+
| SerovalStreamNextNode
|
|
357
|
+
| SerovalStreamThrowNode
|
|
358
|
+
| SerovalStreamReturnNode;
|
|
359
|
+
|
|
360
|
+
export type SerovalNode = SerovalSyncNode | SerovalAsyncNode;
|
|
501
361
|
|
|
502
362
|
export type SerovalNodeWithID = Extract<SerovalNode, { i: number }>;
|
|
@@ -20,30 +20,3 @@ export function createDeferred(): Deferred {
|
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
export interface DeferredStream {
|
|
25
|
-
stream: ReadableStream;
|
|
26
|
-
close(): void;
|
|
27
|
-
enqueue(chunk?: unknown): void;
|
|
28
|
-
error(e?: any): void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function createDeferredStream(): DeferredStream {
|
|
32
|
-
let controller: ReadableStreamDefaultController;
|
|
33
|
-
return {
|
|
34
|
-
stream: new ReadableStream({
|
|
35
|
-
start(current): void {
|
|
36
|
-
controller = current;
|
|
37
|
-
},
|
|
38
|
-
}),
|
|
39
|
-
close(): void {
|
|
40
|
-
controller.close();
|
|
41
|
-
},
|
|
42
|
-
enqueue(data): void {
|
|
43
|
-
controller.enqueue(data);
|
|
44
|
-
},
|
|
45
|
-
error(e): void {
|
|
46
|
-
controller.error(e);
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
}
|