Skip to content

Commit e0147f1

Browse files
committed
Fix
1 parent 1976167 commit e0147f1

10 files changed

+99
-77
lines changed

packages/abstractions/src/apiClientBuilder.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,58 @@ import { BackingStoreParseNodeFactory, BackingStoreSerializationWriterProxyFacto
99

1010
/**
1111
* Registers the default serializer to the registry.
12+
* @param serializationWriterFactoryRegistry The registry to which the default serializer will be registered.
1213
* @param type the class of the factory to be registered.
1314
*/
14-
export function registerDefaultSerializer(type: new () => SerializationWriterFactory): void {
15+
export function registerDefaultSerializer(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, type: new () => SerializationWriterFactory): void {
1516
if (!type) throw new Error("Type is required");
1617
const serializer = new type();
17-
SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.set(serializer.getValidContentType(), serializer);
18+
serializationWriterFactoryRegistry.contentTypeAssociatedFactories.set(serializer.getValidContentType(), serializer);
1819
}
1920
/**
2021
* Registers the default deserializer to the registry.
22+
* @param parseNodeFactoryRegistry The registry to which the default deserializer will be registered.
2123
* @param type the class of the factory to be registered.
2224
*/
23-
export function registerDefaultDeserializer(type: new () => ParseNodeFactory): void {
25+
export function registerDefaultDeserializer(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, type: new () => ParseNodeFactory): void {
2426
if (!type) throw new Error("Type is required");
2527
const deserializer = new type();
26-
ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.set(deserializer.getValidContentType(), deserializer);
28+
parseNodeFactoryRegistry.contentTypeAssociatedFactories.set(deserializer.getValidContentType(), deserializer);
2729
}
2830
/**
2931
* Enables the backing store on default serialization writers and the given serialization writer.
32+
* @param serializationWriterFactoryRegistry The serialization writer factory registry to enable the backing store on.
33+
* @param parseNodeFactoryRegistry The parse node factory registry to enable the backing store on.
3034
* @param original The serialization writer to enable the backing store on.
3135
* @returns A new serialization writer with the backing store enabled.
3236
*/
33-
export function enableBackingStoreForSerializationWriterFactory(original: SerializationWriterFactory): SerializationWriterFactory {
37+
export function enableBackingStoreForSerializationWriterFactory(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, parseNodeFactoryRegistry: ParseNodeFactoryRegistry, original: SerializationWriterFactory): SerializationWriterFactory {
3438
if (!original) throw new Error("Original must be specified");
3539
let result = original;
3640
if (original instanceof SerializationWriterFactoryRegistry) {
3741
enableBackingStoreForSerializationRegistry(original);
3842
} else {
3943
result = new BackingStoreSerializationWriterProxyFactory(original);
4044
}
41-
enableBackingStoreForSerializationRegistry(SerializationWriterFactoryRegistry.defaultInstance);
42-
enableBackingStoreForParseNodeRegistry(ParseNodeFactoryRegistry.defaultInstance);
45+
enableBackingStoreForSerializationRegistry(serializationWriterFactoryRegistry);
46+
enableBackingStoreForParseNodeRegistry(parseNodeFactoryRegistry);
4347
return result;
4448
}
4549
/**
4650
* Enables the backing store on default parse node factories and the given parse node factory.
51+
* @param parseNodeFactoryRegistry The parse node factory registry to enable the backing store on.
4752
* @param original The parse node factory to enable the backing store on.
4853
* @returns A new parse node factory with the backing store enabled.
4954
*/
50-
export function enableBackingStoreForParseNodeFactory(original: ParseNodeFactory): ParseNodeFactory {
55+
export function enableBackingStoreForParseNodeFactory(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, original: ParseNodeFactory): ParseNodeFactory {
5156
if (!original) throw new Error("Original must be specified");
5257
let result = original;
5358
if (original instanceof ParseNodeFactoryRegistry) {
5459
enableBackingStoreForParseNodeRegistry(original);
5560
} else {
5661
result = new BackingStoreParseNodeFactory(original);
5762
}
58-
enableBackingStoreForParseNodeRegistry(ParseNodeFactoryRegistry.defaultInstance);
63+
enableBackingStoreForParseNodeRegistry(parseNodeFactoryRegistry);
5964
return result;
6065
}
6166
/**

packages/abstractions/src/requestAdapter.ts

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export interface RequestAdapter {
1818
* @returns the serialization writer factory currently in use for the HTTP core service.
1919
*/
2020
getSerializationWriterFactory(): SerializationWriterFactory;
21+
22+
/**
23+
* Gets the parse node factory currently in use for the HTTP core service.
24+
* @returns the parse node factory currently in use for the HTTP core service.
25+
*/
26+
getParseNodeFactory(): ParseNodeFactory;
2127
/**
2228
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model.
2329
* @param requestInfo the request info to execute.

packages/abstractions/src/serialization/kiotaJsonSerializer.ts

+21-13
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,72 @@ import { deserialize, deserializeCollection, serialize, serializeCollection, ser
88
import type { Parsable } from "./parsable";
99
import type { ParsableFactory } from "./parsableFactory";
1010
import type { ModelSerializerFunction } from "./serializationFunctionTypes";
11+
import { SerializationWriterFactoryRegistry } from "./serializationWriterFactoryRegistry";
12+
import { ParseNodeFactoryRegistry } from "./parseNodeFactoryRegistry";
1113

1214
const jsonContentType = "application/json";
1315
/**
1416
* Serializes a parsable object into a buffer
17+
* @param serializationWriterFactoryRegistry the serialization writer factory registry
1518
* @param value the value to serialize
1619
* @param serializationFunction the serialization function for the model type
1720
* @returns a buffer containing the serialized value
1821
*/
19-
export function serializeToJson<T extends Parsable>(value: T, serializationFunction: ModelSerializerFunction<T>): ArrayBuffer {
20-
return serialize(jsonContentType, value, serializationFunction);
22+
export function serializeToJson<T extends Parsable>(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, value: T, serializationFunction: ModelSerializerFunction<T>): ArrayBuffer {
23+
return serialize(serializationWriterFactoryRegistry, jsonContentType, value, serializationFunction);
2124
}
2225

2326
/**
2427
* Serializes a parsable object into a string representation
28+
* @param serializationWriterFactoryRegistry the serialization writer factory registry
2529
* @param value the value to serialize
2630
* @param serializationFunction the serialization function for the model type
2731
* @returns a string representing the serialized value
2832
*/
29-
export function serializeToJsonAsString<T extends Parsable>(value: T, serializationFunction: ModelSerializerFunction<T>): string {
30-
return serializeAsString(jsonContentType, value, serializationFunction);
33+
export function serializeToJsonAsString<T extends Parsable>(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, value: T, serializationFunction: ModelSerializerFunction<T>): string {
34+
return serializeAsString(serializationWriterFactoryRegistry, jsonContentType, value, serializationFunction);
3135
}
3236

3337
/**
3438
* Serializes a collection of parsable objects into a buffer
39+
* @param serializationWriterFactoryRegistry the serialization writer factory registry
3540
* @param values the value to serialize
3641
* @param serializationFunction the serialization function for the model type
3742
* @returns a string representing the serialized value
3843
*/
39-
export function serializeCollectionToJson<T extends Parsable>(values: T[], serializationFunction: ModelSerializerFunction<T>): ArrayBuffer {
40-
return serializeCollection(jsonContentType, values, serializationFunction);
44+
export function serializeCollectionToJson<T extends Parsable>(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, values: T[], serializationFunction: ModelSerializerFunction<T>): ArrayBuffer {
45+
return serializeCollection(serializationWriterFactoryRegistry, jsonContentType, values, serializationFunction);
4146
}
4247

4348
/**
4449
* Serializes a collection of parsable objects into a string representation
50+
* @param serializationWriterFactoryRegistry the serialization writer factory registry
4551
* @param values the value to serialize
4652
* @param serializationFunction the serialization function for the model type
4753
* @returns a string representing the serialized value
4854
*/
49-
export function serializeCollectionToJsonAsString<T extends Parsable>(values: T[], serializationFunction: ModelSerializerFunction<T>): string {
50-
return serializeCollectionAsString(jsonContentType, values, serializationFunction);
55+
export function serializeCollectionToJsonAsString<T extends Parsable>(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, values: T[], serializationFunction: ModelSerializerFunction<T>): string {
56+
return serializeCollectionAsString(serializationWriterFactoryRegistry, jsonContentType, values, serializationFunction);
5157
}
5258

5359
/**
5460
* Deserializes a buffer into a parsable object
61+
* @param parseNodeFactoryRegistry the parse node factory registry
5562
* @param bufferOrString the value to serialize
5663
* @param factory the factory for the model type
5764
* @returns the deserialized parsable object
5865
*/
59-
export function deserializeFromJson<T extends Parsable>(bufferOrString: ArrayBuffer | string, factory: ParsableFactory<T>): Parsable {
60-
return deserialize(jsonContentType, bufferOrString, factory);
66+
export function deserializeFromJson<T extends Parsable>(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, bufferOrString: ArrayBuffer | string, factory: ParsableFactory<T>): Parsable {
67+
return deserialize(parseNodeFactoryRegistry, jsonContentType, bufferOrString, factory);
6168
}
6269

6370
/**
64-
* Deserializes a buffer into a a collection of parsable object
71+
* Deserializes a buffer into a collection of parsable object
72+
* @param parseNodeFactoryRegistry the parse node factory registry
6573
* @param bufferOrString the value to serialize
6674
* @param factory the factory for the model type
6775
* @returns the deserialized collection of parsable objects
6876
*/
69-
export function deserializeCollectionFromJson<T extends Parsable>(bufferOrString: ArrayBuffer | string, factory: ParsableFactory<T>): T[] | undefined {
70-
return deserializeCollection(jsonContentType, bufferOrString, factory);
77+
export function deserializeCollectionFromJson<T extends Parsable>(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, bufferOrString: ArrayBuffer | string, factory: ParsableFactory<T>): T[] | undefined {
78+
return deserializeCollection(parseNodeFactoryRegistry, jsonContentType, bufferOrString, factory);
7179
}

packages/abstractions/src/serialization/kiotaSerializer.ts

+25-17
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,65 @@ import { SerializationWriterFactoryRegistry } from "./serializationWriterFactory
1414

1515
/**
1616
* Serializes a parsable object into a buffer
17+
* @param serializationWriterFactoryRegistry the serialization writer factory registry
1718
* @param contentType the content type to serialize to
1819
* @param value the value to serialize
1920
* @param serializationFunction the serialization function for the model type
2021
* @returns a buffer containing the serialized value
2122
*/
22-
export function serialize<T extends Parsable>(contentType: string, value: T, serializationFunction: ModelSerializerFunction<T>): ArrayBuffer {
23-
const writer = getSerializationWriter(contentType, value, serializationFunction);
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);
2425
writer.writeObjectValue(undefined, value, serializationFunction);
2526
return writer.getSerializedContent();
2627
}
2728
/**
2829
* Serializes a parsable object into a string representation
30+
* @param serializationWriterFactoryRegistry the serialization writer factory registry
2931
* @param contentType the content type to serialize to
3032
* @param value the value to serialize
3133
* @param serializationFunction the serialization function for the model type
3234
* @returns a string representing the serialized value
3335
*/
34-
export function serializeToString<T extends Parsable>(contentType: string, value: T, serializationFunction: ModelSerializerFunction<T>): string {
35-
const buffer = serialize(contentType, value, serializationFunction);
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);
3638
return getStringValueFromBuffer(buffer);
3739
}
3840
/**
3941
* Serializes a collection of parsable objects into a buffer
42+
* @param serializationWriterFactoryRegistry the serialization writer factory registry
4043
* @param contentType the content type to serialize to
4144
* @param values the value to serialize
4245
* @param serializationFunction the serialization function for the model type
4346
* @returns a string representing the serialized value
4447
*/
45-
export function serializeCollection<T extends Parsable>(contentType: string, values: T[], serializationFunction: ModelSerializerFunction<T>): ArrayBuffer {
46-
const writer = getSerializationWriter(contentType, values, serializationFunction);
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);
4750
writer.writeCollectionOfObjectValues(undefined, values, serializationFunction);
4851
return writer.getSerializedContent();
4952
}
5053

5154
/**
5255
* Serializes a collection of parsable objects into a string representation
56+
* @param serializationWriterFactoryRegistry the serialization writer factory registry
5357
* @param contentType the content type to serialize to
5458
* @param values the value to serialize
5559
* @param serializationFunction the serialization function for the model type
5660
* @returns a string representing the serialized value
5761
*/
58-
export function serializeCollectionToString<T extends Parsable>(contentType: string, values: T[], serializationFunction: ModelSerializerFunction<T>): string {
59-
const buffer = serializeCollection(contentType, values, serializationFunction);
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);
6064
return getStringValueFromBuffer(buffer);
6165
}
6266

6367
/**
6468
* Gets a serialization writer for a given content type
69+
* @param serializationWriterFactoryRegistry the serialization writer factory registry
6570
* @param contentType the content type to serialize to
6671
* @param value the value to serialize
6772
* @param serializationFunction the serialization function for the model type
6873
* @returns the serialization writer for the given content type
6974
*/
70-
function getSerializationWriter(contentType: string, value: unknown, serializationFunction: unknown): SerializationWriter {
75+
function getSerializationWriter(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, contentType: string, value: unknown, serializationFunction: unknown): SerializationWriter {
7176
if (!contentType) {
7277
throw new Error("content type cannot be undefined or empty");
7378
}
@@ -77,7 +82,7 @@ function getSerializationWriter(contentType: string, value: unknown, serializati
7782
if (!serializationFunction) {
7883
throw new Error("serializationFunction cannot be undefined");
7984
}
80-
return SerializationWriterFactoryRegistry.defaultInstance.getSerializationWriter(contentType);
85+
return serializationWriterFactoryRegistry.getSerializationWriter(contentType);
8186
}
8287

8388
/**
@@ -92,26 +97,28 @@ function getStringValueFromBuffer(buffer: ArrayBuffer): string {
9297

9398
/**
9499
* Deserializes a buffer into a parsable object
100+
* @param parseNodeFactoryRegistry the parse node factory registry
95101
* @param contentType the content type to serialize to
96102
* @param bufferOrString the value to serialize
97103
* @param factory the factory for the model type
98104
* @returns the deserialized parsable object
99105
*/
100-
export function deserialize<T extends Parsable>(contentType: string, bufferOrString: ArrayBuffer | string, factory: ParsableFactory<T>): Parsable {
106+
export function deserialize<T extends Parsable>(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, contentType: string, bufferOrString: ArrayBuffer | string, factory: ParsableFactory<T>): Parsable {
101107
if (typeof bufferOrString === "string") {
102108
bufferOrString = getBufferFromString(bufferOrString);
103109
}
104-
const reader = getParseNode(contentType, bufferOrString, factory);
110+
const reader = getParseNode(parseNodeFactoryRegistry, contentType, bufferOrString, factory);
105111
return reader.getObjectValue(factory);
106112
}
107113
/**
108114
* Deserializes a buffer into a parsable object
115+
* @param parseNodeFactoryRegistry the parse node factory registry
109116
* @param contentType the content type to serialize to
110117
* @param buffer the value to deserialize
111118
* @param factory the factory for the model type
112119
* @returns the deserialized parsable object
113120
*/
114-
function getParseNode(contentType: string, buffer: ArrayBuffer, factory: unknown): ParseNode {
121+
function getParseNode(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, contentType: string, buffer: ArrayBuffer, factory: unknown): ParseNode {
115122
if (!contentType) {
116123
throw new Error("content type cannot be undefined or empty");
117124
}
@@ -121,20 +128,21 @@ function getParseNode(contentType: string, buffer: ArrayBuffer, factory: unknown
121128
if (!factory) {
122129
throw new Error("factory cannot be undefined");
123130
}
124-
return ParseNodeFactoryRegistry.defaultInstance.getRootParseNode(contentType, buffer);
131+
return parseNodeFactoryRegistry.getRootParseNode(contentType, buffer);
125132
}
126133
/**
127-
* Deserializes a buffer into a a collection of parsable object
134+
* Deserializes a buffer into a collection of parsable object
135+
* @param parseNodeFactoryRegistry the parse node factory registry
128136
* @param contentType the content type to serialize to
129137
* @param bufferOrString the value to serialize
130138
* @param factory the factory for the model type
131139
* @returns the deserialized collection of parsable objects
132140
*/
133-
export function deserializeCollection<T extends Parsable>(contentType: string, bufferOrString: ArrayBuffer | string, factory: ParsableFactory<T>): T[] | undefined {
141+
export function deserializeCollection<T extends Parsable>(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, contentType: string, bufferOrString: ArrayBuffer | string, factory: ParsableFactory<T>): T[] | undefined {
134142
if (typeof bufferOrString === "string") {
135143
bufferOrString = getBufferFromString(bufferOrString);
136144
}
137-
const reader = getParseNode(contentType, bufferOrString, factory);
145+
const reader = getParseNode(parseNodeFactoryRegistry, contentType, bufferOrString, factory);
138146
return reader.getCollectionOfObjectValues(factory);
139147
}
140148

packages/abstractions/src/serialization/parseNodeFactoryRegistry.ts

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import type { ParseNodeFactory } from "./parseNodeFactory";
1111
* This factory holds a list of all the registered factories for the various types of nodes.
1212
*/
1313
export class ParseNodeFactoryRegistry implements ParseNodeFactory {
14-
/** Default singleton instance of the registry to be used when registring new factories that should be available by default. */
15-
public static readonly defaultInstance = new ParseNodeFactoryRegistry();
1614
public getValidContentType(): string {
1715
throw new Error("The registry supports multiple content types. Get the registered factory instead.");
1816
}

0 commit comments

Comments
 (0)