seroval 1.5.6 → 1.6.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/index.d.ts +761 -0
- package/dist/index.js +2928 -0
- package/package.json +14 -23
- package/dist/cjs/development/index.cjs +0 -4232
- package/dist/cjs/development/index.cjs.map +0 -7
- package/dist/cjs/production/index.cjs +0 -3
- package/dist/esm/development/index.mjs +0 -4209
- package/dist/esm/development/index.mjs.map +0 -7
- package/dist/esm/production/index.mjs +0 -3
- package/dist/types/core/Serializer.d.ts +0 -28
- package/dist/types/core/Serializer.d.ts.map +0 -1
- package/dist/types/core/base-primitives.d.ts +0 -28
- package/dist/types/core/base-primitives.d.ts.map +0 -1
- package/dist/types/core/compat.d.ts +0 -15
- package/dist/types/core/compat.d.ts.map +0 -1
- package/dist/types/core/constants.d.ts +0 -105
- package/dist/types/core/constants.d.ts.map +0 -1
- package/dist/types/core/constructors.d.ts +0 -50
- package/dist/types/core/constructors.d.ts.map +0 -1
- package/dist/types/core/context/async-parser.d.ts +0 -20
- package/dist/types/core/context/async-parser.d.ts.map +0 -1
- package/dist/types/core/context/deserializer.d.ts +0 -52
- package/dist/types/core/context/deserializer.d.ts.map +0 -1
- package/dist/types/core/context/parser.d.ts +0 -62
- package/dist/types/core/context/parser.d.ts.map +0 -1
- package/dist/types/core/context/serializer.d.ts +0 -103
- package/dist/types/core/context/serializer.d.ts.map +0 -1
- package/dist/types/core/context/sync-parser.d.ts +0 -61
- package/dist/types/core/context/sync-parser.d.ts.map +0 -1
- package/dist/types/core/cross/index.d.ts +0 -24
- package/dist/types/core/cross/index.d.ts.map +0 -1
- package/dist/types/core/errors.d.ts +0 -47
- package/dist/types/core/errors.d.ts.map +0 -1
- package/dist/types/core/function-string.d.ts +0 -3
- package/dist/types/core/function-string.d.ts.map +0 -1
- package/dist/types/core/keys.d.ts +0 -4
- package/dist/types/core/keys.d.ts.map +0 -1
- package/dist/types/core/literals.d.ts +0 -10
- package/dist/types/core/literals.d.ts.map +0 -1
- package/dist/types/core/node.d.ts +0 -8
- package/dist/types/core/node.d.ts.map +0 -1
- package/dist/types/core/opaque-reference.d.ts +0 -9
- package/dist/types/core/opaque-reference.d.ts.map +0 -1
- package/dist/types/core/plugin.d.ts +0 -52
- package/dist/types/core/plugin.d.ts.map +0 -1
- package/dist/types/core/reference.d.ts +0 -6
- package/dist/types/core/reference.d.ts.map +0 -1
- package/dist/types/core/sequence.d.ts +0 -11
- package/dist/types/core/sequence.d.ts.map +0 -1
- package/dist/types/core/special-reference.d.ts +0 -16
- package/dist/types/core/special-reference.d.ts.map +0 -1
- package/dist/types/core/stream.d.ts +0 -17
- package/dist/types/core/stream.d.ts.map +0 -1
- package/dist/types/core/string.d.ts +0 -4
- package/dist/types/core/string.d.ts.map +0 -1
- package/dist/types/core/symbols.d.ts +0 -14
- package/dist/types/core/symbols.d.ts.map +0 -1
- package/dist/types/core/tree/index.d.ts +0 -21
- package/dist/types/core/tree/index.d.ts.map +0 -1
- package/dist/types/core/types.d.ts +0 -233
- package/dist/types/core/types.d.ts.map +0 -1
- package/dist/types/core/utils/error.d.ts +0 -6
- package/dist/types/core/utils/error.d.ts.map +0 -1
- package/dist/types/core/utils/get-identifier.d.ts +0 -2
- package/dist/types/core/utils/get-identifier.d.ts.map +0 -1
- package/dist/types/core/utils/get-object-flag.d.ts +0 -3
- package/dist/types/core/utils/get-object-flag.d.ts.map +0 -1
- package/dist/types/core/utils/is-valid-identifier.d.ts +0 -2
- package/dist/types/core/utils/is-valid-identifier.d.ts.map +0 -1
- package/dist/types/core/utils/promise-to-result.d.ts +0 -2
- package/dist/types/core/utils/promise-to-result.d.ts.map +0 -1
- package/dist/types/core/utils/typed-array.d.ts +0 -6
- package/dist/types/core/utils/typed-array.d.ts.map +0 -1
- package/dist/types/core/utils/valid-properties.d.ts +0 -3
- package/dist/types/core/utils/valid-properties.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -18
- package/dist/types/index.d.ts.map +0 -1
- package/src/core/Serializer.ts +0 -119
- package/src/core/base-primitives.ts +0 -537
- package/src/core/compat.ts +0 -23
- package/src/core/constants.ts +0 -202
- package/src/core/constructors.ts +0 -265
- package/src/core/context/async-parser.ts +0 -666
- package/src/core/context/deserializer.ts +0 -832
- package/src/core/context/parser.ts +0 -335
- package/src/core/context/serializer.ts +0 -1524
- package/src/core/context/sync-parser.ts +0 -943
- package/src/core/cross/index.ts +0 -190
- package/src/core/errors.ts +0 -196
- package/src/core/function-string.ts +0 -31
- package/src/core/keys.ts +0 -17
- package/src/core/literals.ts +0 -43
- package/src/core/node.ts +0 -40
- package/src/core/opaque-reference.ts +0 -9
- package/src/core/plugin.ts +0 -105
- package/src/core/reference.ts +0 -66
- package/src/core/sequence.ts +0 -59
- package/src/core/special-reference.ts +0 -42
- package/src/core/stream.ts +0 -71
- package/src/core/string.ts +0 -86
- package/src/core/symbols.ts +0 -20
- package/src/core/tree/index.ts +0 -134
- package/src/core/types.ts +0 -377
- package/src/core/utils/error.ts +0 -73
- package/src/core/utils/get-identifier.ts +0 -18
- package/src/core/utils/get-object-flag.ts +0 -14
- package/src/core/utils/is-valid-identifier.ts +0 -12
- package/src/core/utils/promise-to-result.ts +0 -9
- package/src/core/utils/typed-array.ts +0 -56
- package/src/core/utils/valid-properties.ts +0 -34
- package/src/index.ts +0 -36
package/src/core/constants.ts
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SYM_ASYNC_ITERATOR,
|
|
3
|
-
SYM_HAS_INSTANCE,
|
|
4
|
-
SYM_IS_CONCAT_SPREADABLE,
|
|
5
|
-
SYM_ITERATOR,
|
|
6
|
-
SYM_MATCH,
|
|
7
|
-
SYM_MATCH_ALL,
|
|
8
|
-
SYM_REPLACE,
|
|
9
|
-
SYM_SEARCH,
|
|
10
|
-
SYM_SPECIES,
|
|
11
|
-
SYM_SPLIT,
|
|
12
|
-
SYM_TO_PRIMITIVE,
|
|
13
|
-
SYM_TO_STRING_TAG,
|
|
14
|
-
SYM_UNSCOPABLES,
|
|
15
|
-
} from './symbols';
|
|
16
|
-
|
|
17
|
-
export const enum SerovalConstant {
|
|
18
|
-
Null = 0,
|
|
19
|
-
Undefined = 1,
|
|
20
|
-
True = 2,
|
|
21
|
-
False = 3,
|
|
22
|
-
NegZero = 4,
|
|
23
|
-
Inf = 5,
|
|
24
|
-
NegInf = 6,
|
|
25
|
-
Nan = 7,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const enum SerovalNodeType {
|
|
29
|
-
Number = 0,
|
|
30
|
-
String = 1,
|
|
31
|
-
Constant = 2,
|
|
32
|
-
BigInt = 3,
|
|
33
|
-
IndexedValue = 4,
|
|
34
|
-
Date = 5,
|
|
35
|
-
RegExp = 6,
|
|
36
|
-
Set = 7,
|
|
37
|
-
Map = 8,
|
|
38
|
-
Array = 9,
|
|
39
|
-
Object = 10,
|
|
40
|
-
NullConstructor = 11,
|
|
41
|
-
Promise = 12,
|
|
42
|
-
Error = 13,
|
|
43
|
-
AggregateError = 14,
|
|
44
|
-
TypedArray = 15,
|
|
45
|
-
BigIntTypedArray = 16,
|
|
46
|
-
WKSymbol = 17,
|
|
47
|
-
Reference = 18,
|
|
48
|
-
ArrayBuffer = 19,
|
|
49
|
-
DataView = 20,
|
|
50
|
-
Boxed = 21,
|
|
51
|
-
PromiseConstructor = 22,
|
|
52
|
-
PromiseSuccess = 23,
|
|
53
|
-
PromiseFailure = 24,
|
|
54
|
-
Plugin = 25,
|
|
55
|
-
SpecialReference = 26,
|
|
56
|
-
IteratorFactory = 27,
|
|
57
|
-
IteratorFactoryInstance = 28,
|
|
58
|
-
AsyncIteratorFactory = 29,
|
|
59
|
-
AsyncIteratorFactoryInstance = 30,
|
|
60
|
-
StreamConstructor = 31,
|
|
61
|
-
StreamNext = 32,
|
|
62
|
-
StreamThrow = 33,
|
|
63
|
-
StreamReturn = 34,
|
|
64
|
-
Sequence = 35,
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export const enum SerovalObjectFlags {
|
|
68
|
-
None = 0,
|
|
69
|
-
NonExtensible = 1,
|
|
70
|
-
Sealed = 2,
|
|
71
|
-
Frozen = 3,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const enum Symbols {
|
|
75
|
-
AsyncIterator = 0,
|
|
76
|
-
HasInstance = 1,
|
|
77
|
-
IsConcatSpreadable = 2,
|
|
78
|
-
Iterator = 3,
|
|
79
|
-
Match = 4,
|
|
80
|
-
MatchAll = 5,
|
|
81
|
-
Replace = 6,
|
|
82
|
-
Search = 7,
|
|
83
|
-
Species = 8,
|
|
84
|
-
Split = 9,
|
|
85
|
-
ToPrimitive = 10,
|
|
86
|
-
ToStringTag = 11,
|
|
87
|
-
Unscopables = 12,
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export const SYMBOL_STRING: Record<Symbols, string> = {
|
|
91
|
-
[Symbols.AsyncIterator]: 'Symbol.asyncIterator',
|
|
92
|
-
[Symbols.HasInstance]: 'Symbol.hasInstance',
|
|
93
|
-
[Symbols.IsConcatSpreadable]: 'Symbol.isConcatSpreadable',
|
|
94
|
-
[Symbols.Iterator]: 'Symbol.iterator',
|
|
95
|
-
[Symbols.Match]: 'Symbol.match',
|
|
96
|
-
[Symbols.MatchAll]: 'Symbol.matchAll',
|
|
97
|
-
[Symbols.Replace]: 'Symbol.replace',
|
|
98
|
-
[Symbols.Search]: 'Symbol.search',
|
|
99
|
-
[Symbols.Species]: 'Symbol.species',
|
|
100
|
-
[Symbols.Split]: 'Symbol.split',
|
|
101
|
-
[Symbols.ToPrimitive]: 'Symbol.toPrimitive',
|
|
102
|
-
[Symbols.ToStringTag]: 'Symbol.toStringTag',
|
|
103
|
-
[Symbols.Unscopables]: 'Symbol.unscopables',
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export const INV_SYMBOL_REF = /* @__PURE__ */ {
|
|
107
|
-
[SYM_ASYNC_ITERATOR]: Symbols.AsyncIterator,
|
|
108
|
-
[SYM_HAS_INSTANCE]: Symbols.HasInstance,
|
|
109
|
-
[SYM_IS_CONCAT_SPREADABLE]: Symbols.IsConcatSpreadable,
|
|
110
|
-
[SYM_ITERATOR]: Symbols.Iterator,
|
|
111
|
-
[SYM_MATCH]: Symbols.Match,
|
|
112
|
-
[SYM_MATCH_ALL]: Symbols.MatchAll,
|
|
113
|
-
[SYM_REPLACE]: Symbols.Replace,
|
|
114
|
-
[SYM_SEARCH]: Symbols.Search,
|
|
115
|
-
[SYM_SPECIES]: Symbols.Species,
|
|
116
|
-
[SYM_SPLIT]: Symbols.Split,
|
|
117
|
-
[SYM_TO_PRIMITIVE]: Symbols.ToPrimitive,
|
|
118
|
-
[SYM_TO_STRING_TAG]: Symbols.ToStringTag,
|
|
119
|
-
[SYM_UNSCOPABLES]: Symbols.Unscopables,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export type WellKnownSymbols = keyof typeof INV_SYMBOL_REF;
|
|
123
|
-
|
|
124
|
-
export const SYMBOL_REF: Record<Symbols, WellKnownSymbols> = {
|
|
125
|
-
[Symbols.AsyncIterator]: SYM_ASYNC_ITERATOR,
|
|
126
|
-
[Symbols.HasInstance]: SYM_HAS_INSTANCE,
|
|
127
|
-
[Symbols.IsConcatSpreadable]: SYM_IS_CONCAT_SPREADABLE,
|
|
128
|
-
[Symbols.Iterator]: SYM_ITERATOR,
|
|
129
|
-
[Symbols.Match]: SYM_MATCH,
|
|
130
|
-
[Symbols.MatchAll]: SYM_MATCH_ALL,
|
|
131
|
-
[Symbols.Replace]: SYM_REPLACE,
|
|
132
|
-
[Symbols.Search]: SYM_SEARCH,
|
|
133
|
-
[Symbols.Species]: SYM_SPECIES,
|
|
134
|
-
[Symbols.Split]: SYM_SPLIT,
|
|
135
|
-
[Symbols.ToPrimitive]: SYM_TO_PRIMITIVE,
|
|
136
|
-
[Symbols.ToStringTag]: SYM_TO_STRING_TAG,
|
|
137
|
-
[Symbols.Unscopables]: SYM_UNSCOPABLES,
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
export const CONSTANT_STRING: Record<SerovalConstant, string> = {
|
|
141
|
-
[SerovalConstant.True]: '!0',
|
|
142
|
-
[SerovalConstant.False]: '!1',
|
|
143
|
-
[SerovalConstant.Undefined]: 'void 0',
|
|
144
|
-
[SerovalConstant.Null]: 'null',
|
|
145
|
-
[SerovalConstant.NegZero]: '-0',
|
|
146
|
-
[SerovalConstant.Inf]: '1/0',
|
|
147
|
-
[SerovalConstant.NegInf]: '-1/0',
|
|
148
|
-
[SerovalConstant.Nan]: '0/0',
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
export const NIL = void 0;
|
|
152
|
-
|
|
153
|
-
export const CONSTANT_VAL: Record<SerovalConstant, unknown> = {
|
|
154
|
-
[SerovalConstant.True]: true,
|
|
155
|
-
[SerovalConstant.False]: false,
|
|
156
|
-
[SerovalConstant.Undefined]: NIL,
|
|
157
|
-
[SerovalConstant.Null]: null,
|
|
158
|
-
[SerovalConstant.NegZero]: -0,
|
|
159
|
-
[SerovalConstant.Inf]: Number.POSITIVE_INFINITY,
|
|
160
|
-
[SerovalConstant.NegInf]: Number.NEGATIVE_INFINITY,
|
|
161
|
-
[SerovalConstant.Nan]: Number.NaN,
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export const enum ErrorConstructorTag {
|
|
165
|
-
Error = 0,
|
|
166
|
-
EvalError = 1,
|
|
167
|
-
RangeError = 2,
|
|
168
|
-
ReferenceError = 3,
|
|
169
|
-
SyntaxError = 4,
|
|
170
|
-
TypeError = 5,
|
|
171
|
-
URIError = 6,
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export const ERROR_CONSTRUCTOR_STRING: Record<ErrorConstructorTag, string> = {
|
|
175
|
-
[ErrorConstructorTag.Error]: 'Error',
|
|
176
|
-
[ErrorConstructorTag.EvalError]: 'EvalError',
|
|
177
|
-
[ErrorConstructorTag.RangeError]: 'RangeError',
|
|
178
|
-
[ErrorConstructorTag.ReferenceError]: 'ReferenceError',
|
|
179
|
-
[ErrorConstructorTag.SyntaxError]: 'SyntaxError',
|
|
180
|
-
[ErrorConstructorTag.TypeError]: 'TypeError',
|
|
181
|
-
[ErrorConstructorTag.URIError]: 'URIError',
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
type ErrorConstructors =
|
|
185
|
-
| ErrorConstructor
|
|
186
|
-
| EvalErrorConstructor
|
|
187
|
-
| RangeErrorConstructor
|
|
188
|
-
| ReferenceErrorConstructor
|
|
189
|
-
| SyntaxErrorConstructor
|
|
190
|
-
| TypeErrorConstructor
|
|
191
|
-
| URIErrorConstructor;
|
|
192
|
-
|
|
193
|
-
export const ERROR_CONSTRUCTOR: Record<ErrorConstructorTag, ErrorConstructors> =
|
|
194
|
-
{
|
|
195
|
-
[ErrorConstructorTag.Error]: Error,
|
|
196
|
-
[ErrorConstructorTag.EvalError]: EvalError,
|
|
197
|
-
[ErrorConstructorTag.RangeError]: RangeError,
|
|
198
|
-
[ErrorConstructorTag.ReferenceError]: ReferenceError,
|
|
199
|
-
[ErrorConstructorTag.SyntaxError]: SyntaxError,
|
|
200
|
-
[ErrorConstructorTag.TypeError]: TypeError,
|
|
201
|
-
[ErrorConstructorTag.URIError]: URIError,
|
|
202
|
-
};
|
package/src/core/constructors.ts
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import type { Sequence } from './sequence';
|
|
2
|
-
import type { Stream } from './stream';
|
|
3
|
-
|
|
4
|
-
type SpecialPromise = Promise<unknown> & { s?: 1 | 2; v?: unknown };
|
|
5
|
-
|
|
6
|
-
export interface PromiseConstructorResolver {
|
|
7
|
-
p: SpecialPromise;
|
|
8
|
-
s: (value: unknown) => void;
|
|
9
|
-
f: (value: unknown) => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const PROMISE_CONSTRUCTOR = (): PromiseConstructorResolver => {
|
|
13
|
-
const resolver = {
|
|
14
|
-
p: 0,
|
|
15
|
-
s: 0,
|
|
16
|
-
f: 0,
|
|
17
|
-
} as unknown as PromiseConstructorResolver;
|
|
18
|
-
resolver.p = new Promise((resolve, reject) => {
|
|
19
|
-
resolver.s = resolve;
|
|
20
|
-
resolver.f = reject;
|
|
21
|
-
});
|
|
22
|
-
return resolver;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const PROMISE_SUCCESS = (
|
|
26
|
-
resolver: PromiseConstructorResolver,
|
|
27
|
-
data: unknown,
|
|
28
|
-
): void => {
|
|
29
|
-
resolver.s(data);
|
|
30
|
-
resolver.p.s = 1;
|
|
31
|
-
resolver.p.v = data;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const PROMISE_FAILURE = (
|
|
35
|
-
resolver: PromiseConstructorResolver,
|
|
36
|
-
data: unknown,
|
|
37
|
-
): void => {
|
|
38
|
-
resolver.f(data);
|
|
39
|
-
resolver.p.s = 2;
|
|
40
|
-
resolver.p.v = data;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const SERIALIZED_PROMISE_CONSTRUCTOR =
|
|
44
|
-
/* @__PURE__ */ PROMISE_CONSTRUCTOR.toString();
|
|
45
|
-
export const SERIALIZED_PROMISE_SUCCESS =
|
|
46
|
-
/* @__PURE__ */ PROMISE_SUCCESS.toString();
|
|
47
|
-
export const SERIALIZED_PROMISE_FAILURE =
|
|
48
|
-
/* @__PURE__ */ PROMISE_FAILURE.toString();
|
|
49
|
-
|
|
50
|
-
interface StreamListener<T> {
|
|
51
|
-
next(value: T): void;
|
|
52
|
-
throw(value: unknown): void;
|
|
53
|
-
return(value: T): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const STREAM_CONSTRUCTOR = () => {
|
|
57
|
-
const buffer: unknown[] = [];
|
|
58
|
-
const listeners: StreamListener<unknown>[] = [];
|
|
59
|
-
let alive = true;
|
|
60
|
-
let success = false;
|
|
61
|
-
let count = 0;
|
|
62
|
-
const flush = (
|
|
63
|
-
value: unknown,
|
|
64
|
-
mode: keyof StreamListener<unknown>,
|
|
65
|
-
x?: number,
|
|
66
|
-
) => {
|
|
67
|
-
for (x = 0; x < count; x++) {
|
|
68
|
-
if (listeners[x]) {
|
|
69
|
-
listeners[x][mode](value);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const up = (
|
|
74
|
-
listener: StreamListener<unknown>,
|
|
75
|
-
x?: number,
|
|
76
|
-
z?: number,
|
|
77
|
-
current?: unknown,
|
|
78
|
-
) => {
|
|
79
|
-
for (x = 0, z = buffer.length; x < z; x++) {
|
|
80
|
-
current = buffer[x];
|
|
81
|
-
if (!alive && x === z - 1) {
|
|
82
|
-
listener[success ? 'return' : 'throw'](current);
|
|
83
|
-
} else {
|
|
84
|
-
listener.next(current);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const on = (listener: StreamListener<unknown>, temp?: number) => {
|
|
89
|
-
if (alive) {
|
|
90
|
-
temp = count++;
|
|
91
|
-
listeners[temp] = listener;
|
|
92
|
-
}
|
|
93
|
-
up(listener);
|
|
94
|
-
return () => {
|
|
95
|
-
if (alive) {
|
|
96
|
-
listeners[temp!] = listeners[count];
|
|
97
|
-
listeners[count--] = undefined as any;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
return {
|
|
102
|
-
__SEROVAL_STREAM__: true,
|
|
103
|
-
on: (listener: StreamListener<unknown>) => on(listener),
|
|
104
|
-
next: (value: unknown) => {
|
|
105
|
-
if (alive) {
|
|
106
|
-
buffer.push(value);
|
|
107
|
-
flush(value, 'next');
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
throw: (value: unknown) => {
|
|
111
|
-
if (alive) {
|
|
112
|
-
buffer.push(value);
|
|
113
|
-
flush(value, 'throw');
|
|
114
|
-
alive = false;
|
|
115
|
-
success = false;
|
|
116
|
-
listeners.length = 0;
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
return: (value: unknown) => {
|
|
120
|
-
if (alive) {
|
|
121
|
-
buffer.push(value);
|
|
122
|
-
flush(value, 'return');
|
|
123
|
-
alive = false;
|
|
124
|
-
success = true;
|
|
125
|
-
listeners.length = 0;
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export const SERIALIZED_STREAM_CONSTRUCTOR =
|
|
132
|
-
/* @__PURE__ */ STREAM_CONSTRUCTOR.toString();
|
|
133
|
-
|
|
134
|
-
export const ITERATOR_CONSTRUCTOR =
|
|
135
|
-
(symbol: symbol) => (sequence: Sequence) => () => {
|
|
136
|
-
let index = 0;
|
|
137
|
-
const instance = {
|
|
138
|
-
[symbol]: () => instance,
|
|
139
|
-
next: () => {
|
|
140
|
-
if (index > sequence.d) {
|
|
141
|
-
return {
|
|
142
|
-
done: true,
|
|
143
|
-
value: undefined,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
const currentIndex = index++;
|
|
147
|
-
const data = sequence.v[currentIndex];
|
|
148
|
-
if (currentIndex === sequence.t) {
|
|
149
|
-
throw data;
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
done: currentIndex === sequence.d,
|
|
153
|
-
value: data,
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
return instance;
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
export const SERIALIZED_ITERATOR_CONSTRUCTOR =
|
|
161
|
-
/* @__PURE__ */ ITERATOR_CONSTRUCTOR.toString();
|
|
162
|
-
|
|
163
|
-
export const ASYNC_ITERATOR_CONSTRUCTOR =
|
|
164
|
-
(symbol: symbol, createPromise: typeof PROMISE_CONSTRUCTOR) =>
|
|
165
|
-
(stream: Stream<unknown>) =>
|
|
166
|
-
() => {
|
|
167
|
-
let count = 0;
|
|
168
|
-
let doneAt = -1;
|
|
169
|
-
let isThrow = false;
|
|
170
|
-
const buffer: unknown[] = [];
|
|
171
|
-
const pending: PromiseConstructorResolver[] = [];
|
|
172
|
-
const finalize = (i = 0, len = pending.length) => {
|
|
173
|
-
for (; i < len; i++) {
|
|
174
|
-
pending[i].s({
|
|
175
|
-
done: true,
|
|
176
|
-
value: undefined,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
stream.on({
|
|
181
|
-
next: value => {
|
|
182
|
-
const temp = pending.shift();
|
|
183
|
-
if (temp) {
|
|
184
|
-
temp.s({ done: false, value });
|
|
185
|
-
}
|
|
186
|
-
buffer.push(value);
|
|
187
|
-
},
|
|
188
|
-
throw: value => {
|
|
189
|
-
const temp = pending.shift();
|
|
190
|
-
if (temp) {
|
|
191
|
-
temp.f(value);
|
|
192
|
-
}
|
|
193
|
-
finalize();
|
|
194
|
-
doneAt = buffer.length;
|
|
195
|
-
isThrow = true;
|
|
196
|
-
buffer.push(value);
|
|
197
|
-
},
|
|
198
|
-
return: value => {
|
|
199
|
-
const temp = pending.shift();
|
|
200
|
-
if (temp) {
|
|
201
|
-
temp.s({ done: true, value });
|
|
202
|
-
}
|
|
203
|
-
finalize();
|
|
204
|
-
doneAt = buffer.length;
|
|
205
|
-
buffer.push(value);
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
const instance = {
|
|
210
|
-
[symbol]: () => instance,
|
|
211
|
-
next: () => {
|
|
212
|
-
if (doneAt === -1) {
|
|
213
|
-
const index = count++;
|
|
214
|
-
if (index >= buffer.length) {
|
|
215
|
-
const temp = createPromise();
|
|
216
|
-
pending.push(temp);
|
|
217
|
-
return temp.p;
|
|
218
|
-
}
|
|
219
|
-
return {
|
|
220
|
-
done: false,
|
|
221
|
-
value: buffer[index],
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
if (count > doneAt) {
|
|
225
|
-
return {
|
|
226
|
-
done: true,
|
|
227
|
-
value: undefined,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
const index = count++;
|
|
231
|
-
const value = buffer[index];
|
|
232
|
-
if (index !== doneAt) {
|
|
233
|
-
return {
|
|
234
|
-
done: false,
|
|
235
|
-
value,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
if (isThrow) {
|
|
239
|
-
throw value;
|
|
240
|
-
}
|
|
241
|
-
return {
|
|
242
|
-
done: true,
|
|
243
|
-
value,
|
|
244
|
-
};
|
|
245
|
-
},
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
return instance;
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
export const SERIALIZED_ASYNC_ITERATOR_CONSTRUCTOR =
|
|
252
|
-
/* @__PURE__ */ ASYNC_ITERATOR_CONSTRUCTOR.toString();
|
|
253
|
-
|
|
254
|
-
export const ARRAY_BUFFER_CONSTRUCTOR = (b64: string) => {
|
|
255
|
-
const decoded = atob(b64);
|
|
256
|
-
const length = decoded.length;
|
|
257
|
-
const arr = new Uint8Array(length);
|
|
258
|
-
for (let i = 0; i < length; i++) {
|
|
259
|
-
arr[i] = decoded.charCodeAt(i);
|
|
260
|
-
}
|
|
261
|
-
return arr.buffer;
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
export const SERIALIZED_ARRAY_BUFFER_CONSTRUCTOR =
|
|
265
|
-
/* @__PURE__ */ ARRAY_BUFFER_CONSTRUCTOR.toString();
|