seroval 1.2.0 → 1.2.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.
@@ -39,24 +39,24 @@ export interface BaseParserContextOptions extends PluginAccessOptions {
39
39
  refs?: Map<unknown, number>;
40
40
  }
41
41
 
42
- const enum NodeType {
42
+ export const enum ParserNodeType {
43
43
  Fresh = 0,
44
44
  Indexed = 1,
45
45
  Referenced = 2,
46
46
  }
47
47
 
48
- interface FreshNode {
49
- type: NodeType.Fresh;
48
+ export interface FreshNode {
49
+ type: ParserNodeType.Fresh;
50
50
  value: number;
51
51
  }
52
52
 
53
- interface IndexedNode {
54
- type: NodeType.Indexed;
53
+ export interface IndexedNode {
54
+ type: ParserNodeType.Indexed;
55
55
  value: SerovalIndexedValueNode;
56
56
  }
57
57
 
58
- interface ReferencedNode {
59
- type: NodeType.Referenced;
58
+ export interface ReferencedNode {
59
+ type: ParserNodeType.Referenced;
60
60
  value: SerovalReferenceNode;
61
61
  }
62
62
 
@@ -92,54 +92,37 @@ export abstract class BaseParserContext implements PluginAccessOptions {
92
92
  if (registeredId != null) {
93
93
  this.markRef(registeredId);
94
94
  return {
95
- type: NodeType.Indexed,
95
+ type: ParserNodeType.Indexed,
96
96
  value: createIndexedValueNode(registeredId),
97
97
  };
98
98
  }
99
99
  const id = this.refs.size;
100
100
  this.refs.set(current, id);
101
101
  return {
102
- type: NodeType.Fresh,
102
+ type: ParserNodeType.Fresh,
103
103
  value: id,
104
104
  };
105
105
  }
106
106
 
107
107
  protected getReference<T>(current: T): ObjectNode {
108
108
  const indexed = this.getIndexedValue(current);
109
- if (indexed.type === NodeType.Indexed) {
109
+ if (indexed.type === ParserNodeType.Indexed) {
110
110
  return indexed;
111
111
  }
112
112
  if (hasReferenceID(current)) {
113
113
  return {
114
- type: NodeType.Referenced,
114
+ type: ParserNodeType.Referenced,
115
115
  value: createReferenceNode(indexed.value, current),
116
116
  };
117
117
  }
118
118
  return indexed;
119
119
  }
120
120
 
121
- protected getStrictReference<T>(
122
- current: T,
123
- ): SerovalIndexedValueNode | SerovalReferenceNode {
124
- assert(hasReferenceID(current), new SerovalUnsupportedTypeError(current));
125
- const result = this.getIndexedValue(current);
126
- if (result.type === NodeType.Indexed) {
127
- return result.value;
128
- }
129
- return createReferenceNode(result.value, current);
130
- }
131
-
132
- protected parseFunction(
133
- current: (...args: unknown[]) => unknown,
134
- ): SerovalNode {
135
- return this.getStrictReference(current);
136
- }
137
-
138
121
  protected parseWellKnownSymbol(
139
122
  current: symbol,
140
123
  ): SerovalIndexedValueNode | SerovalWKSymbolNode | SerovalReferenceNode {
141
124
  const ref = this.getReference(current);
142
- if (ref.type !== NodeType.Fresh) {
125
+ if (ref.type !== ParserNodeType.Fresh) {
143
126
  return ref.value;
144
127
  }
145
128
  assert(current in INV_SYMBOL_REF, new SerovalUnsupportedTypeError(current));
@@ -150,7 +133,7 @@ export abstract class BaseParserContext implements PluginAccessOptions {
150
133
  ref: SpecialReference,
151
134
  ): SerovalIndexedValueNode | SerovalSpecialReferenceNode {
152
135
  const result = this.getIndexedValue(SPECIAL_REFS[ref]);
153
- if (result.type === NodeType.Indexed) {
136
+ if (result.type === ParserNodeType.Indexed) {
154
137
  return result.value;
155
138
  }
156
139
  return createSerovalNode(
@@ -173,7 +156,7 @@ export abstract class BaseParserContext implements PluginAccessOptions {
173
156
  | SerovalIndexedValueNode
174
157
  | SerovalIteratorFactoryNode {
175
158
  const result = this.getIndexedValue(ITERATOR);
176
- if (result.type === NodeType.Indexed) {
159
+ if (result.type === ParserNodeType.Indexed) {
177
160
  return result.value;
178
161
  }
179
162
  return createSerovalNode(
@@ -196,7 +179,7 @@ export abstract class BaseParserContext implements PluginAccessOptions {
196
179
  | SerovalIndexedValueNode
197
180
  | SerovalAsyncIteratorFactoryNode {
198
181
  const result = this.getIndexedValue(ASYNC_ITERATOR);
199
- if (result.type === NodeType.Indexed) {
182
+ if (result.type === ParserNodeType.Indexed) {
200
183
  return result.value;
201
184
  }
202
185
  return createSerovalNode(
@@ -131,9 +131,7 @@ export function crossSerializeStream<T>(
131
131
 
132
132
  ctx.start(source);
133
133
 
134
- return () => {
135
- ctx.destroy();
136
- };
134
+ return ctx.destroy.bind(ctx);
137
135
  }
138
136
 
139
137
  export type ToCrossJSONStreamOptions = CrossStreamParserContextOptions;
@@ -154,9 +152,7 @@ export function toCrossJSONStream<T>(
154
152
 
155
153
  ctx.start(source);
156
154
 
157
- return () => {
158
- ctx.destroy();
159
- };
155
+ return ctx.destroy.bind(ctx);
160
156
  }
161
157
 
162
158
  export type FromCrossJSONOptions = CrossDeserializerContextOptions;