seroval 0.11.6 → 0.12.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 +29 -16
- package/dist/cjs/development/index.cjs +3072 -4875
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +3069 -4874
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/Serializer.d.ts +2 -0
- package/dist/types/core/Serializer.d.ts.map +1 -0
- package/dist/types/core/UnsupportedTypeError.d.ts +1 -0
- package/dist/types/core/UnsupportedTypeError.d.ts.map +1 -0
- package/dist/types/core/assert.d.ts +1 -0
- package/dist/types/core/assert.d.ts.map +1 -0
- package/dist/types/core/base/async.d.ts +30 -0
- package/dist/types/core/base/async.d.ts.map +1 -0
- package/dist/types/core/base/stream.d.ts +40 -0
- package/dist/types/core/base/stream.d.ts.map +1 -0
- package/dist/types/core/base/sync.d.ts +32 -0
- package/dist/types/core/base/sync.d.ts.map +1 -0
- package/dist/types/core/base-primitives.d.ts +3 -1
- package/dist/types/core/base-primitives.d.ts.map +1 -0
- package/dist/types/core/compat.d.ts +1 -0
- package/dist/types/core/compat.d.ts.map +1 -0
- package/dist/types/core/constants.d.ts +19 -4
- package/dist/types/core/constants.d.ts.map +1 -0
- package/dist/types/core/constructors.d.ts +1 -0
- package/dist/types/core/constructors.d.ts.map +1 -0
- package/dist/types/core/cross/async.d.ts +8 -3
- package/dist/types/core/cross/async.d.ts.map +1 -0
- package/dist/types/core/cross/cross-parser.d.ts +8 -0
- package/dist/types/core/cross/cross-parser.d.ts.map +1 -0
- package/dist/types/core/cross/index.d.ts +12 -5
- package/dist/types/core/cross/index.d.ts.map +1 -0
- package/dist/types/core/cross/serialize.d.ts +23 -5
- package/dist/types/core/cross/serialize.d.ts.map +1 -0
- package/dist/types/core/cross/stream.d.ts +8 -3
- package/dist/types/core/cross/stream.d.ts.map +1 -0
- package/dist/types/core/cross/sync.d.ts +8 -3
- package/dist/types/core/cross/sync.d.ts.map +1 -0
- package/dist/types/core/get-identifier.d.ts +1 -0
- package/dist/types/core/get-identifier.d.ts.map +1 -0
- package/dist/types/core/keys.d.ts +1 -0
- package/dist/types/core/keys.d.ts.map +1 -0
- package/dist/types/core/literals.d.ts +1 -0
- package/dist/types/core/literals.d.ts.map +1 -0
- package/dist/types/core/parser-context.d.ts +23 -0
- package/dist/types/core/parser-context.d.ts.map +1 -0
- package/dist/types/core/plugin.d.ts +26 -0
- package/dist/types/core/plugin.d.ts.map +1 -0
- package/dist/types/core/promise-to-result.d.ts +1 -0
- package/dist/types/core/promise-to-result.d.ts.map +1 -0
- package/dist/types/core/reference.d.ts +1 -0
- package/dist/types/core/reference.d.ts.map +1 -0
- package/dist/types/core/serializer-context.old.d.ts +165 -0
- package/dist/types/core/serializer-context.old.d.ts.map +1 -0
- package/dist/types/core/shared.d.ts +4 -7
- package/dist/types/core/shared.d.ts.map +1 -0
- package/dist/types/core/string.d.ts +1 -0
- package/dist/types/core/string.d.ts.map +1 -0
- package/dist/types/core/tree/async.d.ts +8 -3
- package/dist/types/core/tree/async.d.ts.map +1 -0
- package/dist/types/core/tree/deserialize.d.ts +49 -2
- package/dist/types/core/tree/deserialize.d.ts.map +1 -0
- package/dist/types/core/tree/index.d.ts +10 -7
- package/dist/types/core/tree/index.d.ts.map +1 -0
- package/dist/types/core/tree/serialize.d.ts +37 -4
- package/dist/types/core/tree/serialize.d.ts.map +1 -0
- package/dist/types/core/tree/sync.d.ts +8 -3
- package/dist/types/core/tree/sync.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +10 -3
- package/dist/types/core/types.d.ts.map +1 -0
- package/dist/types/core/web-api.d.ts +1 -0
- package/dist/types/core/web-api.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/core/Serializer.ts +2 -0
- package/src/core/base/async.ts +804 -0
- package/src/core/base/stream.ts +496 -0
- package/src/core/base/sync.ts +675 -0
- package/src/core/base-primitives.ts +22 -0
- package/src/core/constants.ts +61 -45
- package/src/core/cross/async.ts +6 -751
- package/src/core/cross/cross-parser.ts +9 -0
- package/src/core/cross/index.ts +62 -84
- package/src/core/cross/serialize.ts +71 -862
- package/src/core/cross/stream.ts +6 -873
- package/src/core/cross/sync.ts +6 -624
- package/src/core/is-serializable.new.ts +208 -0
- package/src/core/keys.ts +1 -1
- package/src/core/parser-context.ts +131 -0
- package/src/core/plugin.ts +55 -0
- package/src/core/serializer-context.new.ts +1168 -0
- package/src/core/serializer-context.old.ts +1126 -0
- package/src/core/shared.ts +46 -123
- package/src/core/tree/async.ts +6 -750
- package/src/core/tree/deserialize.ts +423 -420
- package/src/core/tree/index.ts +49 -91
- package/src/core/tree/parser.ts +45 -0
- package/src/core/tree/serialize.ts +122 -828
- package/src/core/tree/sync.ts +6 -624
- package/src/core/types.ts +13 -2
- package/src/example.ts +28 -0
- package/src/index.ts +3 -0
- package/dist/types/core/assignments.d.ts +0 -33
- package/dist/types/core/context.d.ts +0 -9
- package/dist/types/core/cross/context.d.ts +0 -37
- package/dist/types/core/cross/primitives.d.ts +0 -9
- package/dist/types/core/cross/web-api.d.ts +0 -4
- package/dist/types/core/tree/context.d.ts +0 -44
- package/dist/types/core/tree/primitives.d.ts +0 -9
- package/dist/types/core/tree/web-api.d.ts +0 -4
- package/src/core/assignments.ts +0 -159
- package/src/core/context.ts +0 -15
- package/src/core/cross/context.ts +0 -102
- package/src/core/cross/primitives.ts +0 -128
- package/src/core/cross/web-api.ts +0 -50
- package/src/core/tree/context.ts +0 -125
- package/src/core/tree/primitives.ts +0 -123
- package/src/core/tree/web-api.ts +0 -50
package/src/core/cross/index.ts
CHANGED
|
@@ -1,79 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
createCrossSerializerContext,
|
|
13
|
-
createStreamingCrossParserContext,
|
|
14
|
-
} from './context';
|
|
15
|
-
import crossSerializeTree, { getRefExpr, resolvePatches } from './serialize';
|
|
16
|
-
import crossParseStream from './stream';
|
|
17
|
-
import parseSync from './sync';
|
|
18
|
-
|
|
19
|
-
function finalize(
|
|
20
|
-
ctx: CrossSerializerContext,
|
|
21
|
-
scopeId: string | undefined,
|
|
22
|
-
id: number | undefined,
|
|
23
|
-
result: string,
|
|
24
|
-
): string {
|
|
25
|
-
if (id == null) {
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
const patches = resolvePatches(ctx);
|
|
29
|
-
const ref = getRefExpr(id);
|
|
30
|
-
const params = scopeId == null ? '' : GLOBAL_CONTEXT_REFERENCES;
|
|
31
|
-
const mainBody = patches ? result + ',' + patches : result;
|
|
32
|
-
if (params === '') {
|
|
33
|
-
return patches ? '(' + mainBody + ref + ')' : mainBody;
|
|
34
|
-
}
|
|
35
|
-
const args = scopeId == null ? '()' : '(' + GLOBAL_CONTEXT_REFERENCES + '["' + serializeString(scopeId) + '"])';
|
|
36
|
-
const body = mainBody + (patches ? ref : '');
|
|
37
|
-
if (ctx.features & Feature.ArrowFunction) {
|
|
38
|
-
return '(' + params + '=>(' + body + '))' + args;
|
|
39
|
-
}
|
|
40
|
-
return '(function(' + params + '){return ' + body + '})' + args;
|
|
1
|
+
import type { CrossAsyncParserContextOptions } from './async';
|
|
2
|
+
import AsyncCrossParserContext from './async';
|
|
3
|
+
import type { CrossContextOptions } from './cross-parser';
|
|
4
|
+
import CrossSerializerContext from './serialize';
|
|
5
|
+
import type { CrossStreamParserContextOptions } from './stream';
|
|
6
|
+
import StreamCrossParserContext from './stream';
|
|
7
|
+
import type { CrossSyncParserContextOptions } from './sync';
|
|
8
|
+
import SyncCrossParserContext from './sync';
|
|
9
|
+
|
|
10
|
+
export interface CrossSerializeOptions
|
|
11
|
+
extends CrossSyncParserContextOptions, CrossContextOptions {
|
|
41
12
|
}
|
|
42
13
|
|
|
43
14
|
export function crossSerialize<T>(
|
|
44
15
|
source: T,
|
|
45
|
-
options
|
|
16
|
+
options: CrossSerializeOptions = {},
|
|
46
17
|
): string {
|
|
47
|
-
const ctx =
|
|
48
|
-
|
|
49
|
-
|
|
18
|
+
const ctx = new SyncCrossParserContext({
|
|
19
|
+
plugins: options.plugins,
|
|
20
|
+
disabledFeatures: options.disabledFeatures,
|
|
21
|
+
refs: options.refs,
|
|
22
|
+
});
|
|
23
|
+
const tree = ctx.parse(source);
|
|
24
|
+
const serial = new CrossSerializerContext({
|
|
25
|
+
plugins: options.plugins,
|
|
50
26
|
features: ctx.features,
|
|
27
|
+
scopeId: options.scopeId,
|
|
28
|
+
markedRefs: ctx.marked,
|
|
51
29
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
result,
|
|
58
|
-
);
|
|
30
|
+
return serial.serializeTop(tree);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CrossSerializeAsyncOptions
|
|
34
|
+
extends CrossAsyncParserContextOptions, CrossContextOptions {
|
|
59
35
|
}
|
|
60
36
|
|
|
61
37
|
export async function crossSerializeAsync<T>(
|
|
62
38
|
source: T,
|
|
63
|
-
options
|
|
39
|
+
options: CrossSerializeAsyncOptions = {},
|
|
64
40
|
): Promise<string> {
|
|
65
|
-
const ctx =
|
|
66
|
-
|
|
67
|
-
|
|
41
|
+
const ctx = new AsyncCrossParserContext({
|
|
42
|
+
plugins: options.plugins,
|
|
43
|
+
disabledFeatures: options.disabledFeatures,
|
|
44
|
+
refs: options.refs,
|
|
45
|
+
});
|
|
46
|
+
const tree = await ctx.parse(source);
|
|
47
|
+
const serial = new CrossSerializerContext({
|
|
48
|
+
plugins: options.plugins,
|
|
68
49
|
features: ctx.features,
|
|
50
|
+
scopeId: options.scopeId,
|
|
51
|
+
markedRefs: ctx.marked,
|
|
69
52
|
});
|
|
70
|
-
|
|
71
|
-
return finalize(
|
|
72
|
-
serial,
|
|
73
|
-
ctx.scopeId,
|
|
74
|
-
tree.i,
|
|
75
|
-
result,
|
|
76
|
-
);
|
|
53
|
+
return serial.serializeTop(tree);
|
|
77
54
|
}
|
|
78
55
|
|
|
79
56
|
// export interface SerovalCrossJSON {
|
|
@@ -122,48 +99,49 @@ export async function crossSerializeAsync<T>(
|
|
|
122
99
|
// return deserializeTree(serial, source.t) as T;
|
|
123
100
|
// }
|
|
124
101
|
|
|
125
|
-
export interface CrossSerializeStreamOptions
|
|
102
|
+
export interface CrossSerializeStreamOptions
|
|
103
|
+
extends Omit<CrossStreamParserContextOptions, 'onParse'>, CrossContextOptions {
|
|
126
104
|
onSerialize: (data: string, initial: boolean) => void;
|
|
127
|
-
onDone?: () => void;
|
|
128
105
|
}
|
|
129
106
|
|
|
130
107
|
export function crossSerializeStream<T>(
|
|
131
108
|
source: T,
|
|
132
109
|
options: CrossSerializeStreamOptions,
|
|
133
110
|
): () => void {
|
|
134
|
-
const ctx =
|
|
135
|
-
scopeId: options.scopeId,
|
|
111
|
+
const ctx = new StreamCrossParserContext({
|
|
136
112
|
refs: options.refs,
|
|
137
113
|
disabledFeatures: options.disabledFeatures,
|
|
138
|
-
onParse(node, initial) {
|
|
139
|
-
const serial =
|
|
114
|
+
onParse(node, initial): void {
|
|
115
|
+
const serial = new CrossSerializerContext({
|
|
116
|
+
plugins: options.plugins,
|
|
140
117
|
features: ctx.features,
|
|
118
|
+
scopeId: options.scopeId,
|
|
119
|
+
markedRefs: ctx.marked,
|
|
141
120
|
});
|
|
142
121
|
|
|
122
|
+
let serialized: string;
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
serialized = serial.serializeTop(node);
|
|
126
|
+
} catch (err) {
|
|
127
|
+
if (options.onError) {
|
|
128
|
+
options.onError(err);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
143
133
|
options.onSerialize(
|
|
144
|
-
|
|
145
|
-
serial,
|
|
146
|
-
ctx.scopeId,
|
|
147
|
-
node.i,
|
|
148
|
-
crossSerializeTree(serial, node),
|
|
149
|
-
),
|
|
134
|
+
serialized,
|
|
150
135
|
initial,
|
|
151
136
|
);
|
|
152
137
|
},
|
|
138
|
+
onError: options.onError,
|
|
153
139
|
onDone: options.onDone,
|
|
154
140
|
});
|
|
155
141
|
|
|
156
|
-
ctx.
|
|
157
|
-
|
|
158
|
-
if (ctx.pending <= 0) {
|
|
159
|
-
ctx.onDone();
|
|
160
|
-
ctx.alive = false;
|
|
161
|
-
}
|
|
142
|
+
ctx.start(source);
|
|
162
143
|
|
|
163
144
|
return () => {
|
|
164
|
-
|
|
165
|
-
ctx.alive = false;
|
|
166
|
-
ctx.onDone();
|
|
167
|
-
}
|
|
145
|
+
ctx.destroy();
|
|
168
146
|
};
|
|
169
147
|
}
|