seroval 1.3.2 → 1.4.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.
Files changed (125) hide show
  1. package/dist/cjs/development/index.cjs +2817 -2700
  2. package/dist/cjs/development/index.cjs.map +4 -4
  3. package/dist/cjs/production/index.cjs +3 -17
  4. package/dist/esm/development/index.mjs +2817 -2700
  5. package/dist/esm/development/index.mjs.map +4 -4
  6. package/dist/esm/production/index.mjs +3 -17
  7. package/dist/types/core/base-primitives.d.ts +3 -4
  8. package/dist/types/core/base-primitives.d.ts.map +1 -1
  9. package/dist/types/core/compat.d.ts +3 -2
  10. package/dist/types/core/compat.d.ts.map +1 -1
  11. package/dist/types/core/constants.d.ts +2 -1
  12. package/dist/types/core/constants.d.ts.map +1 -1
  13. package/dist/types/core/constructors.d.ts +54 -0
  14. package/dist/types/core/constructors.d.ts.map +1 -0
  15. package/dist/types/core/context/async-parser.d.ts +20 -0
  16. package/dist/types/core/context/async-parser.d.ts.map +1 -0
  17. package/dist/types/core/context/deserializer.d.ts +40 -38
  18. package/dist/types/core/context/deserializer.d.ts.map +1 -1
  19. package/dist/types/core/context/parser.d.ts +34 -19
  20. package/dist/types/core/context/parser.d.ts.map +1 -1
  21. package/dist/types/core/context/serializer.d.ts +38 -99
  22. package/dist/types/core/context/serializer.d.ts.map +1 -1
  23. package/dist/types/core/context/sync-parser.d.ts +59 -0
  24. package/dist/types/core/context/sync-parser.d.ts.map +1 -0
  25. package/dist/types/core/cross/index.d.ts +12 -13
  26. package/dist/types/core/cross/index.d.ts.map +1 -1
  27. package/dist/types/core/errors.d.ts +9 -0
  28. package/dist/types/core/errors.d.ts.map +1 -1
  29. package/dist/types/core/function-string.d.ts +2 -2
  30. package/dist/types/core/function-string.d.ts.map +1 -1
  31. package/dist/types/core/literals.d.ts.map +1 -1
  32. package/dist/types/core/node.d.ts +1 -1
  33. package/dist/types/core/node.d.ts.map +1 -1
  34. package/dist/types/core/plugin.d.ts +13 -11
  35. package/dist/types/core/plugin.d.ts.map +1 -1
  36. package/dist/types/core/reference.d.ts.map +1 -1
  37. package/dist/types/core/special-reference.d.ts +3 -2
  38. package/dist/types/core/special-reference.d.ts.map +1 -1
  39. package/dist/types/core/stream.d.ts +1 -2
  40. package/dist/types/core/stream.d.ts.map +1 -1
  41. package/dist/types/core/string.d.ts.map +1 -1
  42. package/dist/types/core/symbols.d.ts +14 -0
  43. package/dist/types/core/symbols.d.ts.map +1 -0
  44. package/dist/types/core/tree/index.d.ts +7 -3
  45. package/dist/types/core/tree/index.d.ts.map +1 -1
  46. package/dist/types/core/types.d.ts +4 -11
  47. package/dist/types/core/types.d.ts.map +1 -1
  48. package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -1
  49. package/dist/types/index.d.ts +10 -5
  50. package/dist/types/index.d.ts.map +1 -1
  51. package/package.json +18 -21
  52. package/dist/types/core/context/parser/async.d.ts +0 -24
  53. package/dist/types/core/context/parser/async.d.ts.map +0 -1
  54. package/dist/types/core/context/parser/stream.d.ts +0 -43
  55. package/dist/types/core/context/parser/stream.d.ts.map +0 -1
  56. package/dist/types/core/context/parser/sync.d.ts +0 -30
  57. package/dist/types/core/context/parser/sync.d.ts.map +0 -1
  58. package/dist/types/core/cross/async.d.ts +0 -8
  59. package/dist/types/core/cross/async.d.ts.map +0 -1
  60. package/dist/types/core/cross/deserializer.d.ts +0 -9
  61. package/dist/types/core/cross/deserializer.d.ts.map +0 -1
  62. package/dist/types/core/cross/parser.d.ts +0 -6
  63. package/dist/types/core/cross/parser.d.ts.map +0 -1
  64. package/dist/types/core/cross/serializer.d.ts +0 -16
  65. package/dist/types/core/cross/serializer.d.ts.map +0 -1
  66. package/dist/types/core/cross/stream.d.ts +0 -8
  67. package/dist/types/core/cross/stream.d.ts.map +0 -1
  68. package/dist/types/core/cross/sync.d.ts +0 -8
  69. package/dist/types/core/cross/sync.d.ts.map +0 -1
  70. package/dist/types/core/tree/async.d.ts +0 -8
  71. package/dist/types/core/tree/async.d.ts.map +0 -1
  72. package/dist/types/core/tree/deserializer.d.ts +0 -13
  73. package/dist/types/core/tree/deserializer.d.ts.map +0 -1
  74. package/dist/types/core/tree/serializer.d.ts +0 -29
  75. package/dist/types/core/tree/serializer.d.ts.map +0 -1
  76. package/dist/types/core/tree/sync.d.ts +0 -8
  77. package/dist/types/core/tree/sync.d.ts.map +0 -1
  78. package/dist/types/core/utils/assert.d.ts +0 -2
  79. package/dist/types/core/utils/assert.d.ts.map +0 -1
  80. package/dist/types/core/utils/deferred.d.ts +0 -7
  81. package/dist/types/core/utils/deferred.d.ts.map +0 -1
  82. package/src/core/Serializer.ts +0 -119
  83. package/src/core/base-primitives.ts +0 -542
  84. package/src/core/compat.ts +0 -20
  85. package/src/core/constants.ts +0 -185
  86. package/src/core/context/deserializer.ts +0 -456
  87. package/src/core/context/parser/async.ts +0 -495
  88. package/src/core/context/parser/stream.ts +0 -323
  89. package/src/core/context/parser/sync.ts +0 -404
  90. package/src/core/context/parser.ts +0 -270
  91. package/src/core/context/serializer.ts +0 -1180
  92. package/src/core/cross/async.ts +0 -9
  93. package/src/core/cross/deserializer.ts +0 -16
  94. package/src/core/cross/index.ts +0 -170
  95. package/src/core/cross/parser.ts +0 -7
  96. package/src/core/cross/serializer.ts +0 -72
  97. package/src/core/cross/stream.ts +0 -9
  98. package/src/core/cross/sync.ts +0 -9
  99. package/src/core/errors.ts +0 -102
  100. package/src/core/function-string.ts +0 -31
  101. package/src/core/keys.ts +0 -17
  102. package/src/core/literals.ts +0 -43
  103. package/src/core/node.ts +0 -40
  104. package/src/core/opaque-reference.ts +0 -9
  105. package/src/core/plugin.ts +0 -91
  106. package/src/core/reference.ts +0 -63
  107. package/src/core/special-reference.ts +0 -114
  108. package/src/core/stream.ts +0 -205
  109. package/src/core/string.ts +0 -84
  110. package/src/core/tree/async.ts +0 -9
  111. package/src/core/tree/deserializer.ts +0 -26
  112. package/src/core/tree/index.ts +0 -111
  113. package/src/core/tree/serializer.ts +0 -98
  114. package/src/core/tree/sync.ts +0 -9
  115. package/src/core/types.ts +0 -370
  116. package/src/core/utils/assert.ts +0 -5
  117. package/src/core/utils/deferred.ts +0 -22
  118. package/src/core/utils/error.ts +0 -73
  119. package/src/core/utils/get-identifier.ts +0 -18
  120. package/src/core/utils/get-object-flag.ts +0 -14
  121. package/src/core/utils/is-valid-identifier.ts +0 -12
  122. package/src/core/utils/iterator-to-sequence.ts +0 -66
  123. package/src/core/utils/promise-to-result.ts +0 -9
  124. package/src/core/utils/typed-array.ts +0 -56
  125. package/src/index.ts +0 -18
@@ -1,270 +0,0 @@
1
- import {
2
- createIndexedValueNode,
3
- createReferenceNode,
4
- createWKSymbolNode,
5
- } from '../base-primitives';
6
- import { ALL_ENABLED } from '../compat';
7
- import type { WellKnownSymbols } from '../constants';
8
- import { INV_SYMBOL_REF, NIL, SerovalNodeType } from '../constants';
9
- import { SerovalUnsupportedTypeError } from '../errors';
10
- import { createSerovalNode } from '../node';
11
- import type { Plugin, PluginAccessOptions, SerovalMode } from '../plugin';
12
- import { hasReferenceID } from '../reference';
13
- import {
14
- ASYNC_ITERATOR,
15
- ITERATOR,
16
- SPECIAL_REFS,
17
- SpecialReference,
18
- } from '../special-reference';
19
- import type {
20
- SerovalAsyncIteratorFactoryNode,
21
- SerovalIndexedValueNode,
22
- SerovalIteratorFactoryNode,
23
- SerovalMapNode,
24
- SerovalNode,
25
- SerovalNullConstructorNode,
26
- SerovalObjectNode,
27
- SerovalObjectRecordNode,
28
- SerovalPromiseConstructorNode,
29
- SerovalReferenceNode,
30
- SerovalSpecialReferenceNode,
31
- SerovalWKSymbolNode,
32
- } from '../types';
33
- import assert from '../utils/assert';
34
- import { getObjectFlag } from '../utils/get-object-flag';
35
-
36
- export interface BaseParserContextOptions extends PluginAccessOptions {
37
- disabledFeatures?: number;
38
- refs?: Map<unknown, number>;
39
- }
40
-
41
- export const enum ParserNodeType {
42
- Fresh = 0,
43
- Indexed = 1,
44
- Referenced = 2,
45
- }
46
-
47
- export interface FreshNode {
48
- type: ParserNodeType.Fresh;
49
- value: number;
50
- }
51
-
52
- export interface IndexedNode {
53
- type: ParserNodeType.Indexed;
54
- value: SerovalIndexedValueNode;
55
- }
56
-
57
- export interface ReferencedNode {
58
- type: ParserNodeType.Referenced;
59
- value: SerovalReferenceNode;
60
- }
61
-
62
- type ObjectNode = FreshNode | IndexedNode | ReferencedNode;
63
-
64
- export abstract class BaseParserContext implements PluginAccessOptions {
65
- abstract readonly mode: SerovalMode;
66
-
67
- features: number;
68
-
69
- marked = new Set<number>();
70
-
71
- refs: Map<unknown, number>;
72
-
73
- plugins?: Plugin<any, any>[] | undefined;
74
-
75
- constructor(options: BaseParserContextOptions) {
76
- this.plugins = options.plugins;
77
- this.features = ALL_ENABLED ^ (options.disabledFeatures || 0);
78
- this.refs = options.refs || new Map<unknown, number>();
79
- }
80
-
81
- protected markRef(id: number): void {
82
- this.marked.add(id);
83
- }
84
-
85
- protected isMarked(id: number): boolean {
86
- return this.marked.has(id);
87
- }
88
-
89
- protected createIndex<T>(current: T): number {
90
- const id = this.refs.size;
91
- this.refs.set(current, id);
92
- return id;
93
- }
94
-
95
- protected getIndexedValue<T>(current: T): FreshNode | IndexedNode {
96
- const registeredId = this.refs.get(current);
97
- if (registeredId != null) {
98
- this.markRef(registeredId);
99
- return {
100
- type: ParserNodeType.Indexed,
101
- value: createIndexedValueNode(registeredId),
102
- };
103
- }
104
- return {
105
- type: ParserNodeType.Fresh,
106
- value: this.createIndex(current),
107
- };
108
- }
109
-
110
- protected getReference<T>(current: T): ObjectNode {
111
- const indexed = this.getIndexedValue(current);
112
- if (indexed.type === ParserNodeType.Indexed) {
113
- return indexed;
114
- }
115
- if (hasReferenceID(current)) {
116
- return {
117
- type: ParserNodeType.Referenced,
118
- value: createReferenceNode(indexed.value, current),
119
- };
120
- }
121
- return indexed;
122
- }
123
-
124
- protected parseWellKnownSymbol(
125
- current: symbol,
126
- ): SerovalIndexedValueNode | SerovalWKSymbolNode | SerovalReferenceNode {
127
- const ref = this.getReference(current);
128
- if (ref.type !== ParserNodeType.Fresh) {
129
- return ref.value;
130
- }
131
- assert(current in INV_SYMBOL_REF, new SerovalUnsupportedTypeError(current));
132
- return createWKSymbolNode(ref.value, current as WellKnownSymbols);
133
- }
134
-
135
- protected parseSpecialReference(
136
- ref: SpecialReference,
137
- ): SerovalIndexedValueNode | SerovalSpecialReferenceNode {
138
- const result = this.getIndexedValue(SPECIAL_REFS[ref]);
139
- if (result.type === ParserNodeType.Indexed) {
140
- return result.value;
141
- }
142
- return createSerovalNode(
143
- SerovalNodeType.SpecialReference,
144
- result.value,
145
- ref,
146
- NIL,
147
- NIL,
148
- NIL,
149
- NIL,
150
- NIL,
151
- NIL,
152
- NIL,
153
- NIL,
154
- NIL,
155
- );
156
- }
157
-
158
- protected parseIteratorFactory():
159
- | SerovalIndexedValueNode
160
- | SerovalIteratorFactoryNode {
161
- const result = this.getIndexedValue(ITERATOR);
162
- if (result.type === ParserNodeType.Indexed) {
163
- return result.value;
164
- }
165
- return createSerovalNode(
166
- SerovalNodeType.IteratorFactory,
167
- result.value,
168
- NIL,
169
- NIL,
170
- NIL,
171
- NIL,
172
- NIL,
173
- NIL,
174
- NIL,
175
- this.parseWellKnownSymbol(Symbol.iterator),
176
- NIL,
177
- NIL,
178
- );
179
- }
180
-
181
- protected parseAsyncIteratorFactory():
182
- | SerovalIndexedValueNode
183
- | SerovalAsyncIteratorFactoryNode {
184
- const result = this.getIndexedValue(ASYNC_ITERATOR);
185
- if (result.type === ParserNodeType.Indexed) {
186
- return result.value;
187
- }
188
- return createSerovalNode(
189
- SerovalNodeType.AsyncIteratorFactory,
190
- result.value,
191
- NIL,
192
- NIL,
193
- NIL,
194
- NIL,
195
- NIL,
196
- NIL,
197
- [
198
- this.parseSpecialReference(SpecialReference.PromiseConstructor),
199
- this.parseWellKnownSymbol(Symbol.asyncIterator),
200
- ],
201
- NIL,
202
- NIL,
203
- NIL,
204
- );
205
- }
206
-
207
- protected createObjectNode(
208
- id: number,
209
- current: Record<string, unknown>,
210
- empty: boolean,
211
- record: SerovalObjectRecordNode,
212
- ): SerovalObjectNode | SerovalNullConstructorNode {
213
- return createSerovalNode(
214
- empty ? SerovalNodeType.NullConstructor : SerovalNodeType.Object,
215
- id,
216
- NIL,
217
- NIL,
218
- NIL,
219
- NIL,
220
- record,
221
- NIL,
222
- NIL,
223
- NIL,
224
- NIL,
225
- getObjectFlag(current),
226
- );
227
- }
228
-
229
- protected createMapNode(
230
- id: number,
231
- k: SerovalNode[],
232
- v: SerovalNode[],
233
- s: number,
234
- ): SerovalMapNode {
235
- return createSerovalNode(
236
- SerovalNodeType.Map,
237
- id,
238
- NIL,
239
- NIL,
240
- NIL,
241
- NIL,
242
- NIL,
243
- { k, v, s },
244
- NIL,
245
- this.parseSpecialReference(SpecialReference.MapSentinel),
246
- NIL,
247
- NIL,
248
- );
249
- }
250
-
251
- protected createPromiseConstructorNode(
252
- id: number,
253
- resolver: number,
254
- ): SerovalPromiseConstructorNode {
255
- return createSerovalNode(
256
- SerovalNodeType.PromiseConstructor,
257
- id,
258
- resolver,
259
- NIL,
260
- NIL,
261
- NIL,
262
- NIL,
263
- NIL,
264
- NIL,
265
- this.parseSpecialReference(SpecialReference.PromiseConstructor),
266
- NIL,
267
- NIL,
268
- );
269
- }
270
- }