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.
Files changed (111) hide show
  1. package/dist/index.d.ts +761 -0
  2. package/dist/index.js +2928 -0
  3. package/package.json +14 -23
  4. package/dist/cjs/development/index.cjs +0 -4232
  5. package/dist/cjs/development/index.cjs.map +0 -7
  6. package/dist/cjs/production/index.cjs +0 -3
  7. package/dist/esm/development/index.mjs +0 -4209
  8. package/dist/esm/development/index.mjs.map +0 -7
  9. package/dist/esm/production/index.mjs +0 -3
  10. package/dist/types/core/Serializer.d.ts +0 -28
  11. package/dist/types/core/Serializer.d.ts.map +0 -1
  12. package/dist/types/core/base-primitives.d.ts +0 -28
  13. package/dist/types/core/base-primitives.d.ts.map +0 -1
  14. package/dist/types/core/compat.d.ts +0 -15
  15. package/dist/types/core/compat.d.ts.map +0 -1
  16. package/dist/types/core/constants.d.ts +0 -105
  17. package/dist/types/core/constants.d.ts.map +0 -1
  18. package/dist/types/core/constructors.d.ts +0 -50
  19. package/dist/types/core/constructors.d.ts.map +0 -1
  20. package/dist/types/core/context/async-parser.d.ts +0 -20
  21. package/dist/types/core/context/async-parser.d.ts.map +0 -1
  22. package/dist/types/core/context/deserializer.d.ts +0 -52
  23. package/dist/types/core/context/deserializer.d.ts.map +0 -1
  24. package/dist/types/core/context/parser.d.ts +0 -62
  25. package/dist/types/core/context/parser.d.ts.map +0 -1
  26. package/dist/types/core/context/serializer.d.ts +0 -103
  27. package/dist/types/core/context/serializer.d.ts.map +0 -1
  28. package/dist/types/core/context/sync-parser.d.ts +0 -61
  29. package/dist/types/core/context/sync-parser.d.ts.map +0 -1
  30. package/dist/types/core/cross/index.d.ts +0 -24
  31. package/dist/types/core/cross/index.d.ts.map +0 -1
  32. package/dist/types/core/errors.d.ts +0 -47
  33. package/dist/types/core/errors.d.ts.map +0 -1
  34. package/dist/types/core/function-string.d.ts +0 -3
  35. package/dist/types/core/function-string.d.ts.map +0 -1
  36. package/dist/types/core/keys.d.ts +0 -4
  37. package/dist/types/core/keys.d.ts.map +0 -1
  38. package/dist/types/core/literals.d.ts +0 -10
  39. package/dist/types/core/literals.d.ts.map +0 -1
  40. package/dist/types/core/node.d.ts +0 -8
  41. package/dist/types/core/node.d.ts.map +0 -1
  42. package/dist/types/core/opaque-reference.d.ts +0 -9
  43. package/dist/types/core/opaque-reference.d.ts.map +0 -1
  44. package/dist/types/core/plugin.d.ts +0 -52
  45. package/dist/types/core/plugin.d.ts.map +0 -1
  46. package/dist/types/core/reference.d.ts +0 -6
  47. package/dist/types/core/reference.d.ts.map +0 -1
  48. package/dist/types/core/sequence.d.ts +0 -11
  49. package/dist/types/core/sequence.d.ts.map +0 -1
  50. package/dist/types/core/special-reference.d.ts +0 -16
  51. package/dist/types/core/special-reference.d.ts.map +0 -1
  52. package/dist/types/core/stream.d.ts +0 -17
  53. package/dist/types/core/stream.d.ts.map +0 -1
  54. package/dist/types/core/string.d.ts +0 -4
  55. package/dist/types/core/string.d.ts.map +0 -1
  56. package/dist/types/core/symbols.d.ts +0 -14
  57. package/dist/types/core/symbols.d.ts.map +0 -1
  58. package/dist/types/core/tree/index.d.ts +0 -21
  59. package/dist/types/core/tree/index.d.ts.map +0 -1
  60. package/dist/types/core/types.d.ts +0 -233
  61. package/dist/types/core/types.d.ts.map +0 -1
  62. package/dist/types/core/utils/error.d.ts +0 -6
  63. package/dist/types/core/utils/error.d.ts.map +0 -1
  64. package/dist/types/core/utils/get-identifier.d.ts +0 -2
  65. package/dist/types/core/utils/get-identifier.d.ts.map +0 -1
  66. package/dist/types/core/utils/get-object-flag.d.ts +0 -3
  67. package/dist/types/core/utils/get-object-flag.d.ts.map +0 -1
  68. package/dist/types/core/utils/is-valid-identifier.d.ts +0 -2
  69. package/dist/types/core/utils/is-valid-identifier.d.ts.map +0 -1
  70. package/dist/types/core/utils/promise-to-result.d.ts +0 -2
  71. package/dist/types/core/utils/promise-to-result.d.ts.map +0 -1
  72. package/dist/types/core/utils/typed-array.d.ts +0 -6
  73. package/dist/types/core/utils/typed-array.d.ts.map +0 -1
  74. package/dist/types/core/utils/valid-properties.d.ts +0 -3
  75. package/dist/types/core/utils/valid-properties.d.ts.map +0 -1
  76. package/dist/types/index.d.ts +0 -18
  77. package/dist/types/index.d.ts.map +0 -1
  78. package/src/core/Serializer.ts +0 -119
  79. package/src/core/base-primitives.ts +0 -537
  80. package/src/core/compat.ts +0 -23
  81. package/src/core/constants.ts +0 -202
  82. package/src/core/constructors.ts +0 -265
  83. package/src/core/context/async-parser.ts +0 -666
  84. package/src/core/context/deserializer.ts +0 -832
  85. package/src/core/context/parser.ts +0 -335
  86. package/src/core/context/serializer.ts +0 -1524
  87. package/src/core/context/sync-parser.ts +0 -943
  88. package/src/core/cross/index.ts +0 -190
  89. package/src/core/errors.ts +0 -196
  90. package/src/core/function-string.ts +0 -31
  91. package/src/core/keys.ts +0 -17
  92. package/src/core/literals.ts +0 -43
  93. package/src/core/node.ts +0 -40
  94. package/src/core/opaque-reference.ts +0 -9
  95. package/src/core/plugin.ts +0 -105
  96. package/src/core/reference.ts +0 -66
  97. package/src/core/sequence.ts +0 -59
  98. package/src/core/special-reference.ts +0 -42
  99. package/src/core/stream.ts +0 -71
  100. package/src/core/string.ts +0 -86
  101. package/src/core/symbols.ts +0 -20
  102. package/src/core/tree/index.ts +0 -134
  103. package/src/core/types.ts +0 -377
  104. package/src/core/utils/error.ts +0 -73
  105. package/src/core/utils/get-identifier.ts +0 -18
  106. package/src/core/utils/get-object-flag.ts +0 -14
  107. package/src/core/utils/is-valid-identifier.ts +0 -12
  108. package/src/core/utils/promise-to-result.ts +0 -9
  109. package/src/core/utils/typed-array.ts +0 -56
  110. package/src/core/utils/valid-properties.ts +0 -34
  111. package/src/index.ts +0 -36
@@ -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
- };
@@ -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();