Skip to content

Commit 8baf6e3

Browse files
authored
fix: Removes singleton registries (#1634)
* Migrate static functions to instance methods
1 parent 765d5b7 commit 8baf6e3

29 files changed

+616
-468
lines changed

packages/abstractions/src/apiClientBuilder.ts

+8-23
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,40 @@
77
import { type ParseNodeFactory, ParseNodeFactoryRegistry, type SerializationWriterFactory, SerializationWriterFactoryRegistry } from "./serialization";
88
import { BackingStoreParseNodeFactory, BackingStoreSerializationWriterProxyFactory } from "./store";
99

10-
/**
11-
* Registers the default serializer to the registry.
12-
* @param type the class of the factory to be registered.
13-
*/
14-
export function registerDefaultSerializer(type: new () => SerializationWriterFactory): void {
15-
if (!type) throw new Error("Type is required");
16-
const serializer = new type();
17-
SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.set(serializer.getValidContentType(), serializer);
18-
}
19-
/**
20-
* Registers the default deserializer to the registry.
21-
* @param type the class of the factory to be registered.
22-
*/
23-
export function registerDefaultDeserializer(type: new () => ParseNodeFactory): void {
24-
if (!type) throw new Error("Type is required");
25-
const deserializer = new type();
26-
ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.set(deserializer.getValidContentType(), deserializer);
27-
}
2810
/**
2911
* Enables the backing store on default serialization writers and the given serialization writer.
12+
* @param serializationWriterFactoryRegistry The serialization writer factory registry to enable the backing store on.
13+
* @param parseNodeFactoryRegistry The parse node factory registry to enable the backing store on.
3014
* @param original The serialization writer to enable the backing store on.
3115
* @returns A new serialization writer with the backing store enabled.
3216
*/
33-
export function enableBackingStoreForSerializationWriterFactory(original: SerializationWriterFactory): SerializationWriterFactory {
17+
export function enableBackingStoreForSerializationWriterFactory(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, parseNodeFactoryRegistry: ParseNodeFactoryRegistry, original: SerializationWriterFactory): SerializationWriterFactory {
3418
if (!original) throw new Error("Original must be specified");
3519
let result = original;
3620
if (original instanceof SerializationWriterFactoryRegistry) {
3721
enableBackingStoreForSerializationRegistry(original);
3822
} else {
3923
result = new BackingStoreSerializationWriterProxyFactory(original);
4024
}
41-
enableBackingStoreForSerializationRegistry(SerializationWriterFactoryRegistry.defaultInstance);
42-
enableBackingStoreForParseNodeRegistry(ParseNodeFactoryRegistry.defaultInstance);
25+
enableBackingStoreForSerializationRegistry(serializationWriterFactoryRegistry);
26+
enableBackingStoreForParseNodeRegistry(parseNodeFactoryRegistry);
4327
return result;
4428
}
4529
/**
4630
* Enables the backing store on default parse node factories and the given parse node factory.
31+
* @param parseNodeFactoryRegistry The parse node factory registry to enable the backing store on.
4732
* @param original The parse node factory to enable the backing store on.
4833
* @returns A new parse node factory with the backing store enabled.
4934
*/
50-
export function enableBackingStoreForParseNodeFactory(original: ParseNodeFactory): ParseNodeFactory {
35+
export function enableBackingStoreForParseNodeFactory(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, original: ParseNodeFactory): ParseNodeFactory {
5136
if (!original) throw new Error("Original must be specified");
5237
let result = original;
5338
if (original instanceof ParseNodeFactoryRegistry) {
5439
enableBackingStoreForParseNodeRegistry(original);
5540
} else {
5641
result = new BackingStoreParseNodeFactory(original);
5742
}
58-
enableBackingStoreForParseNodeRegistry(ParseNodeFactoryRegistry.defaultInstance);
43+
enableBackingStoreForParseNodeRegistry(parseNodeFactoryRegistry);
5944
return result;
6045
}
6146
/**

packages/abstractions/src/requestAdapter.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import type { DateOnly } from "./dateOnly";
88
import type { Duration } from "./duration";
99
import { type RequestInformation } from "./requestInformation";
10-
import type { Parsable, ParsableFactory, SerializationWriterFactory } from "./serialization";
10+
import type { Parsable, ParsableFactory, ParseNodeFactory, SerializationWriterFactory } from "./serialization";
1111
import { type BackingStoreFactory } from "./store";
1212
import type { TimeOnly } from "./timeOnly";
1313

@@ -18,6 +18,16 @@ export interface RequestAdapter {
1818
* @returns the serialization writer factory currently in use for the HTTP core service.
1919
*/
2020
getSerializationWriterFactory(): SerializationWriterFactory;
21+
/**
22+
* Gets the parse node factory currently in use for the HTTP core service.
23+
* @returns the parse node factory currently in use for the HTTP core service.
24+
*/
25+
getParseNodeFactory(): ParseNodeFactory;
26+
/**
27+
* Gets the backing store factory currently in use for the HTTP core service.
28+
* @returns The backing store factory currently in use for the HTTP core service.
29+
*/
30+
getBackingStoreFactory(): BackingStoreFactory;
2131
/**
2232
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model.
2333
* @param requestInfo the request info to execute.

packages/abstractions/src/serialization/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* -------------------------------------------------------------------------------------------
66
*/
77
export * from "./additionalDataHolder";
8-
export * from "./kiotaJsonSerializer";
9-
export * from "./kiotaSerializer";
108
export * from "./parsable";
119
export * from "./parsableFactory";
1210
export * from "./parseNode";

packages/abstractions/src/serialization/kiotaJsonSerializer.ts

-71
This file was deleted.

packages/abstractions/src/serialization/kiotaSerializer.ts

-149
This file was deleted.

0 commit comments

Comments
 (0)