Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix! Removes singleton registries #1634

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
28 changes: 17 additions & 11 deletions packages/abstractions/src/apiClientBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,70 @@
* -------------------------------------------------------------------------------------------
*/
import { type ParseNodeFactory, ParseNodeFactoryRegistry, type SerializationWriterFactory, SerializationWriterFactoryRegistry } from "./serialization";
import { BackingStoreParseNodeFactory, BackingStoreSerializationWriterProxyFactory } from "./store";
import { BackingStoreFactory, BackingStoreParseNodeFactory, BackingStoreSerializationWriterProxyFactory } from "./store";

/**
* Registers the default serializer to the registry.
* @param serializationWriterFactoryRegistry The serialization writer factory registry to register the default serializer to.
* @param type the class of the factory to be registered.
*/
export function registerDefaultSerializer(type: new () => SerializationWriterFactory): void {
export function registerDefaultSerializer(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, type: new () => SerializationWriterFactory): void {

Check warning on line 15 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Use const or class constructors instead of named functions

Check warning on line 15 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Use const or class constructors instead of named functions

Check warning on line 15 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Use const or class constructors instead of named functions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those should probably be instance methods now that we require an instance to be passed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to revert to functions since they will require cyclic dependencies that are problematic

if (!type) throw new Error("Type is required");
const serializer = new type();
SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.set(serializer.getValidContentType(), serializer);
serializationWriterFactoryRegistry.contentTypeAssociatedFactories.set(serializer.getValidContentType(), serializer);
}
/**
* Registers the default deserializer to the registry.
* @param parseNodeFactoryRegistry The parse node factory registry to register the default deserializer to.
* @param type the class of the factory to be registered.
* @param backingStoreFactory The backing store factory to use.
*/
export function registerDefaultDeserializer(type: new () => ParseNodeFactory): void {
export function registerDefaultDeserializer(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, type: new (backingStoreFactory: BackingStoreFactory) => ParseNodeFactory, backingStoreFactory: BackingStoreFactory): void {

Check warning on line 26 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Use const or class constructors instead of named functions

Check warning on line 26 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Use const or class constructors instead of named functions

Check warning on line 26 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Use const or class constructors instead of named functions
if (!type) throw new Error("Type is required");
const deserializer = new type();
ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.set(deserializer.getValidContentType(), deserializer);
const deserializer = new type(backingStoreFactory);
parseNodeFactoryRegistry.contentTypeAssociatedFactories.set(deserializer.getValidContentType(), deserializer);
}
/**
* Enables the backing store on default serialization writers and the given serialization writer.
* @param serializationWriterFactoryRegistry The serialization writer factory registry to enable the backing store on.
* @param parseNodeFactoryRegistry The parse node factory registry to enable the backing store on.
* @param original The serialization writer to enable the backing store on.
* @returns A new serialization writer with the backing store enabled.
*/
export function enableBackingStoreForSerializationWriterFactory(original: SerializationWriterFactory): SerializationWriterFactory {
export function enableBackingStoreForSerializationWriterFactory(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, parseNodeFactoryRegistry: ParseNodeFactoryRegistry, original: SerializationWriterFactory): SerializationWriterFactory {

Check warning on line 38 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Use const or class constructors instead of named functions

Check warning on line 38 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Use const or class constructors instead of named functions

Check warning on line 38 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Use const or class constructors instead of named functions
if (!original) throw new Error("Original must be specified");
let result = original;
if (original instanceof SerializationWriterFactoryRegistry) {
enableBackingStoreForSerializationRegistry(original);
} else {
result = new BackingStoreSerializationWriterProxyFactory(original);
}
enableBackingStoreForSerializationRegistry(SerializationWriterFactoryRegistry.defaultInstance);
enableBackingStoreForParseNodeRegistry(ParseNodeFactoryRegistry.defaultInstance);
enableBackingStoreForSerializationRegistry(serializationWriterFactoryRegistry);
enableBackingStoreForParseNodeRegistry(parseNodeFactoryRegistry);
return result;
}
/**
* Enables the backing store on default parse node factories and the given parse node factory.
* @param parseNodeFactoryRegistry The parse node factory registry to enable the backing store on.
* @param original The parse node factory to enable the backing store on.
* @returns A new parse node factory with the backing store enabled.
*/
export function enableBackingStoreForParseNodeFactory(original: ParseNodeFactory): ParseNodeFactory {
export function enableBackingStoreForParseNodeFactory(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, original: ParseNodeFactory): ParseNodeFactory {

Check warning on line 56 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Use const or class constructors instead of named functions

Check warning on line 56 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Use const or class constructors instead of named functions

Check warning on line 56 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Use const or class constructors instead of named functions
if (!original) throw new Error("Original must be specified");
let result = original;
if (original instanceof ParseNodeFactoryRegistry) {
enableBackingStoreForParseNodeRegistry(original);
} else {
result = new BackingStoreParseNodeFactory(original);
}
enableBackingStoreForParseNodeRegistry(ParseNodeFactoryRegistry.defaultInstance);
enableBackingStoreForParseNodeRegistry(parseNodeFactoryRegistry);
return result;
}
/**
* Enables the backing store on the given parse node factory registry.
* @param registry The parse node factory registry to enable the backing store on.
*/
function enableBackingStoreForParseNodeRegistry(registry: ParseNodeFactoryRegistry): void {

Check warning on line 71 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Use const or class constructors instead of named functions

Check warning on line 71 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Use const or class constructors instead of named functions

Check warning on line 71 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Use const or class constructors instead of named functions
for (const [k, v] of registry.contentTypeAssociatedFactories) {
if (!(v instanceof BackingStoreParseNodeFactory || v instanceof ParseNodeFactoryRegistry)) {
registry.contentTypeAssociatedFactories.set(k, new BackingStoreParseNodeFactory(v));
Expand All @@ -73,7 +79,7 @@
* Enables the backing store on the given serialization factory registry.
* @param registry The serialization factory registry to enable the backing store on.
*/
function enableBackingStoreForSerializationRegistry(registry: SerializationWriterFactoryRegistry): void {

Check warning on line 82 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Use const or class constructors instead of named functions

Check warning on line 82 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Use const or class constructors instead of named functions

Check warning on line 82 in packages/abstractions/src/apiClientBuilder.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Use const or class constructors instead of named functions
for (const [k, v] of registry.contentTypeAssociatedFactories) {
if (!(v instanceof BackingStoreSerializationWriterProxyFactory || v instanceof SerializationWriterFactoryRegistry)) {
registry.contentTypeAssociatedFactories.set(k, new BackingStoreSerializationWriterProxyFactory(v));
Expand Down
12 changes: 11 additions & 1 deletion packages/abstractions/src/requestAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import type { DateOnly } from "./dateOnly";
import type { Duration } from "./duration";
import { type RequestInformation } from "./requestInformation";
import type { Parsable, ParsableFactory, SerializationWriterFactory } from "./serialization";
import type { Parsable, ParsableFactory, ParseNodeFactory, SerializationWriterFactory } from "./serialization";
import { type BackingStoreFactory } from "./store";
import type { TimeOnly } from "./timeOnly";

Expand All @@ -18,6 +18,16 @@ export interface RequestAdapter {
* @returns the serialization writer factory currently in use for the HTTP core service.
*/
getSerializationWriterFactory(): SerializationWriterFactory;
/**
* Gets the parse node factory currently in use for the HTTP core service.
* @returns the parse node factory currently in use for the HTTP core service.
*/
getParseNodeFactory(): ParseNodeFactory;
/**
* Gets the backing store factory currently in use for the HTTP core service.
* @returns The backing store factory currently in use for the HTTP core service.
*/
getBackingStoreFactory(): BackingStoreFactory;
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model.
* @param requestInfo the request info to execute.
Expand Down
2 changes: 0 additions & 2 deletions packages/abstractions/src/serialization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* -------------------------------------------------------------------------------------------
*/
export * from "./additionalDataHolder";
export * from "./kiotaJsonSerializer";
export * from "./kiotaSerializer";
export * from "./parsable";
export * from "./parsableFactory";
export * from "./parseNode";
Expand Down
71 changes: 0 additions & 71 deletions packages/abstractions/src/serialization/kiotaJsonSerializer.ts

This file was deleted.

149 changes: 0 additions & 149 deletions packages/abstractions/src/serialization/kiotaSerializer.ts

This file was deleted.

Loading
Loading