7
7
import type { Parsable } from "./parsable" ;
8
8
import type { ParsableFactory } from "./parsableFactory" ;
9
9
import type { ParseNode } from "./parseNode" ;
10
- import { ParseNodeFactoryRegistry } from "./parseNodeFactoryRegistry" ;
11
10
import type { ModelSerializerFunction } from "./serializationFunctionTypes" ;
12
11
import type { SerializationWriter } from "./serializationWriter" ;
13
- import { SerializationWriterFactoryRegistry } from "./serializationWriterFactoryRegistry" ;
12
+ import { SerializationWriterFactory } from "./serializationWriterFactory" ;
13
+ import { ParseNodeFactory } from "./parseNodeFactory" ;
14
14
15
15
/**
16
16
* Serializes a parsable object into a buffer
17
- * @param serializationWriterFactoryRegistry the serialization writer factory registry
17
+ * @param serializationWriterFactory the serialization writer factory for the content type
18
18
* @param contentType the content type to serialize to
19
19
* @param value the value to serialize
20
20
* @param serializationFunction the serialization function for the model type
21
21
* @returns a buffer containing the serialized value
22
22
*/
23
- export function serialize < T extends Parsable > ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , contentType : string , value : T , serializationFunction : ModelSerializerFunction < T > ) : ArrayBuffer {
24
- const writer = getSerializationWriter ( serializationWriterFactoryRegistry , contentType , value , serializationFunction ) ;
23
+ export function serialize < T extends Parsable > ( serializationWriterFactory : SerializationWriterFactory , contentType : string , value : T , serializationFunction : ModelSerializerFunction < T > ) : ArrayBuffer {
24
+ const writer = getSerializationWriter ( serializationWriterFactory , contentType , value , serializationFunction ) ;
25
25
writer . writeObjectValue ( undefined , value , serializationFunction ) ;
26
26
return writer . getSerializedContent ( ) ;
27
27
}
28
28
/**
29
29
* Serializes a parsable object into a string representation
30
- * @param serializationWriterFactoryRegistry the serialization writer factory registry
30
+ * @param serializationWriterFactory the serialization writer factory for the content type
31
31
* @param contentType the content type to serialize to
32
32
* @param value the value to serialize
33
33
* @param serializationFunction the serialization function for the model type
34
34
* @returns a string representing the serialized value
35
35
*/
36
- export function serializeToString < T extends Parsable > ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , contentType : string , value : T , serializationFunction : ModelSerializerFunction < T > ) : string {
37
- const buffer = serialize ( serializationWriterFactoryRegistry , contentType , value , serializationFunction ) ;
36
+ export function serializeToString < T extends Parsable > ( serializationWriterFactory : SerializationWriterFactory , contentType : string , value : T , serializationFunction : ModelSerializerFunction < T > ) : string {
37
+ const buffer = serialize ( serializationWriterFactory , contentType , value , serializationFunction ) ;
38
38
return getStringValueFromBuffer ( buffer ) ;
39
39
}
40
40
/**
41
41
* Serializes a collection of parsable objects into a buffer
42
- * @param serializationWriterFactoryRegistry the serialization writer factory registry
42
+ * @param serializationWriterFactory the serialization writer factory for the content type
43
43
* @param contentType the content type to serialize to
44
44
* @param values the value to serialize
45
45
* @param serializationFunction the serialization function for the model type
46
46
* @returns a string representing the serialized value
47
47
*/
48
- export function serializeCollection < T extends Parsable > ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , contentType : string , values : T [ ] , serializationFunction : ModelSerializerFunction < T > ) : ArrayBuffer {
49
- const writer = getSerializationWriter ( serializationWriterFactoryRegistry , contentType , values , serializationFunction ) ;
48
+ export function serializeCollection < T extends Parsable > ( serializationWriterFactory : SerializationWriterFactory , contentType : string , values : T [ ] , serializationFunction : ModelSerializerFunction < T > ) : ArrayBuffer {
49
+ const writer = getSerializationWriter ( serializationWriterFactory , contentType , values , serializationFunction ) ;
50
50
writer . writeCollectionOfObjectValues ( undefined , values , serializationFunction ) ;
51
51
return writer . getSerializedContent ( ) ;
52
52
}
53
53
54
54
/**
55
55
* Serializes a collection of parsable objects into a string representation
56
- * @param serializationWriterFactoryRegistry the serialization writer factory registry
56
+ * @param serializationWriterFactory the serialization writer factory for the content type
57
57
* @param contentType the content type to serialize to
58
58
* @param values the value to serialize
59
59
* @param serializationFunction the serialization function for the model type
60
60
* @returns a string representing the serialized value
61
61
*/
62
- export function serializeCollectionToString < T extends Parsable > ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , contentType : string , values : T [ ] , serializationFunction : ModelSerializerFunction < T > ) : string {
63
- const buffer = serializeCollection ( serializationWriterFactoryRegistry , contentType , values , serializationFunction ) ;
62
+ export function serializeCollectionToString < T extends Parsable > ( serializationWriterFactory : SerializationWriterFactory , contentType : string , values : T [ ] , serializationFunction : ModelSerializerFunction < T > ) : string {
63
+ const buffer = serializeCollection ( serializationWriterFactory , contentType , values , serializationFunction ) ;
64
64
return getStringValueFromBuffer ( buffer ) ;
65
65
}
66
66
67
67
/**
68
68
* Gets a serialization writer for a given content type
69
- * @param serializationWriterFactoryRegistry the serialization writer factory registry
69
+ * @param serializationWriterFactory the serialization writer factory for the content type
70
70
* @param contentType the content type to serialize to
71
71
* @param value the value to serialize
72
72
* @param serializationFunction the serialization function for the model type
73
73
* @returns the serialization writer for the given content type
74
74
*/
75
- function getSerializationWriter ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , contentType : string , value : unknown , serializationFunction : unknown ) : SerializationWriter {
75
+ function getSerializationWriter ( serializationWriterFactory : SerializationWriterFactory , contentType : string , value : unknown , serializationFunction : unknown ) : SerializationWriter {
76
76
if ( ! contentType ) {
77
77
throw new Error ( "content type cannot be undefined or empty" ) ;
78
78
}
@@ -82,7 +82,7 @@ function getSerializationWriter(serializationWriterFactoryRegistry: Serializatio
82
82
if ( ! serializationFunction ) {
83
83
throw new Error ( "serializationFunction cannot be undefined" ) ;
84
84
}
85
- return serializationWriterFactoryRegistry . getSerializationWriter ( contentType ) ;
85
+ return serializationWriterFactory . getSerializationWriter ( contentType ) ;
86
86
}
87
87
88
88
/**
@@ -97,28 +97,28 @@ function getStringValueFromBuffer(buffer: ArrayBuffer): string {
97
97
98
98
/**
99
99
* Deserializes a buffer into a parsable object
100
- * @param parseNodeFactoryRegistry the parse node factory registry
100
+ * @param parseNodeFactory the parse node factory for the content type
101
101
* @param contentType the content type to serialize to
102
102
* @param bufferOrString the value to serialize
103
103
* @param factory the factory for the model type
104
104
* @returns the deserialized parsable object
105
105
*/
106
- export function deserialize < T extends Parsable > ( parseNodeFactoryRegistry : ParseNodeFactoryRegistry , contentType : string , bufferOrString : ArrayBuffer | string , factory : ParsableFactory < T > ) : Parsable {
106
+ export function deserialize < T extends Parsable > ( parseNodeFactory : ParseNodeFactory , contentType : string , bufferOrString : ArrayBuffer | string , factory : ParsableFactory < T > ) : Parsable {
107
107
if ( typeof bufferOrString === "string" ) {
108
108
bufferOrString = getBufferFromString ( bufferOrString ) ;
109
109
}
110
- const reader = getParseNode ( parseNodeFactoryRegistry , contentType , bufferOrString , factory ) ;
110
+ const reader = getParseNode ( parseNodeFactory , contentType , bufferOrString , factory ) ;
111
111
return reader . getObjectValue ( factory ) ;
112
112
}
113
113
/**
114
114
* Deserializes a buffer into a parsable object
115
- * @param parseNodeFactoryRegistry the parse node factory registry
115
+ * @param parseNodeFactory the parse node factory for the content type
116
116
* @param contentType the content type to serialize to
117
117
* @param buffer the value to deserialize
118
118
* @param factory the factory for the model type
119
119
* @returns the deserialized parsable object
120
120
*/
121
- function getParseNode ( parseNodeFactoryRegistry : ParseNodeFactoryRegistry , contentType : string , buffer : ArrayBuffer , factory : unknown ) : ParseNode {
121
+ function getParseNode ( parseNodeFactory : ParseNodeFactory , contentType : string , buffer : ArrayBuffer , factory : unknown ) : ParseNode {
122
122
if ( ! contentType ) {
123
123
throw new Error ( "content type cannot be undefined or empty" ) ;
124
124
}
@@ -128,21 +128,21 @@ function getParseNode(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, conten
128
128
if ( ! factory ) {
129
129
throw new Error ( "factory cannot be undefined" ) ;
130
130
}
131
- return parseNodeFactoryRegistry . getRootParseNode ( contentType , buffer ) ;
131
+ return parseNodeFactory . getRootParseNode ( contentType , buffer ) ;
132
132
}
133
133
/**
134
134
* Deserializes a buffer into a collection of parsable object
135
- * @param parseNodeFactoryRegistry the parse node factory registry
135
+ * @param parseNodeFactory the parse node factory for the content type
136
136
* @param contentType the content type to serialize to
137
137
* @param bufferOrString the value to serialize
138
138
* @param factory the factory for the model type
139
139
* @returns the deserialized collection of parsable objects
140
140
*/
141
- export function deserializeCollection < T extends Parsable > ( parseNodeFactoryRegistry : ParseNodeFactoryRegistry , contentType : string , bufferOrString : ArrayBuffer | string , factory : ParsableFactory < T > ) : T [ ] | undefined {
141
+ export function deserializeCollection < T extends Parsable > ( parseNodeFactory : ParseNodeFactory , contentType : string , bufferOrString : ArrayBuffer | string , factory : ParsableFactory < T > ) : T [ ] | undefined {
142
142
if ( typeof bufferOrString === "string" ) {
143
143
bufferOrString = getBufferFromString ( bufferOrString ) ;
144
144
}
145
- const reader = getParseNode ( parseNodeFactoryRegistry , contentType , bufferOrString , factory ) ;
145
+ const reader = getParseNode ( parseNodeFactory , contentType , bufferOrString , factory ) ;
146
146
return reader . getCollectionOfObjectValues ( factory ) ;
147
147
}
148
148
0 commit comments