Skip to content

Commit 9c7d08f

Browse files
committed
Fix build
1 parent c7e0e5b commit 9c7d08f

File tree

7 files changed

+114
-99
lines changed

7 files changed

+114
-99
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* -------------------------------------------------------------------------------------------
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
4+
* See License in the project root for license information.
5+
* -------------------------------------------------------------------------------------------
6+
*/
7+
import { type ParseNodeFactory, ParseNodeFactoryRegistry, type SerializationWriterFactory, SerializationWriterFactoryRegistry } from "./serialization";
8+
import { BackingStoreParseNodeFactory, BackingStoreSerializationWriterProxyFactory } from "./store";
9+
10+
/**
11+
* Registers the default serializer to the registry.
12+
* @param serializationWriterFactoryRegistry The serialization writer factory registry to register the default serializer to.
13+
* @param type the class of the factory to be registered.
14+
*/
15+
export function registerDefaultSerializer(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, type: new () => SerializationWriterFactory): void {
16+
if (!type) throw new Error("Type is required");
17+
const serializer = new type();
18+
serializationWriterFactoryRegistry.contentTypeAssociatedFactories.set(serializer.getValidContentType(), serializer);
19+
}
20+
/**
21+
* Registers the default deserializer to the registry.
22+
* @param parseNodeFactoryRegistry The parse node factory registry to register the default deserializer to.
23+
* @param type the class of the factory to be registered.
24+
*/
25+
export function registerDefaultDeserializer(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, type: new () => ParseNodeFactory): void {
26+
if (!type) throw new Error("Type is required");
27+
const deserializer = new type();
28+
parseNodeFactoryRegistry.contentTypeAssociatedFactories.set(deserializer.getValidContentType(), deserializer);
29+
}
30+
/**
31+
* 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.
34+
* @param original The serialization writer to enable the backing store on.
35+
* @returns A new serialization writer with the backing store enabled.
36+
*/
37+
export function enableBackingStoreForSerializationWriterFactory(serializationWriterFactoryRegistry: SerializationWriterFactoryRegistry, parseNodeFactoryRegistry: ParseNodeFactoryRegistry, original: SerializationWriterFactory): SerializationWriterFactory {
38+
if (!original) throw new Error("Original must be specified");
39+
let result = original;
40+
if (original instanceof SerializationWriterFactoryRegistry) {
41+
enableBackingStoreForSerializationRegistry(original);
42+
} else {
43+
result = new BackingStoreSerializationWriterProxyFactory(original);
44+
}
45+
enableBackingStoreForSerializationRegistry(serializationWriterFactoryRegistry);
46+
enableBackingStoreForParseNodeRegistry(parseNodeFactoryRegistry);
47+
return result;
48+
}
49+
/**
50+
* 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.
52+
* @param original The parse node factory to enable the backing store on.
53+
* @returns A new parse node factory with the backing store enabled.
54+
*/
55+
export function enableBackingStoreForParseNodeFactory(parseNodeFactoryRegistry: ParseNodeFactoryRegistry, original: ParseNodeFactory): ParseNodeFactory {
56+
if (!original) throw new Error("Original must be specified");
57+
let result = original;
58+
if (original instanceof ParseNodeFactoryRegistry) {
59+
enableBackingStoreForParseNodeRegistry(original);
60+
} else {
61+
result = new BackingStoreParseNodeFactory(original);
62+
}
63+
enableBackingStoreForParseNodeRegistry(parseNodeFactoryRegistry);
64+
return result;
65+
}
66+
/**
67+
* Enables the backing store on the given parse node factory registry.
68+
* @param registry The parse node factory registry to enable the backing store on.
69+
*/
70+
function enableBackingStoreForParseNodeRegistry(registry: ParseNodeFactoryRegistry): void {
71+
for (const [k, v] of registry.contentTypeAssociatedFactories) {
72+
if (!(v instanceof BackingStoreParseNodeFactory || v instanceof ParseNodeFactoryRegistry)) {
73+
registry.contentTypeAssociatedFactories.set(k, new BackingStoreParseNodeFactory(v));
74+
}
75+
}
76+
}
77+
/**
78+
* Enables the backing store on the given serialization factory registry.
79+
* @param registry The serialization factory registry to enable the backing store on.
80+
*/
81+
function enableBackingStoreForSerializationRegistry(registry: SerializationWriterFactoryRegistry): void {
82+
for (const [k, v] of registry.contentTypeAssociatedFactories) {
83+
if (!(v instanceof BackingStoreSerializationWriterProxyFactory || v instanceof SerializationWriterFactoryRegistry)) {
84+
registry.contentTypeAssociatedFactories.set(k, new BackingStoreSerializationWriterProxyFactory(v));
85+
}
86+
}
87+
}

packages/abstractions/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See License in the project root for license information.
55
* -------------------------------------------------------------------------------------------
66
*/
7+
export * from "./apiClientBuilder";
78
export * from "./apiClientProxifier";
89
export * from "./apiError";
910
export * from "./authentication";

packages/abstractions/src/serialization/parseNodeFactoryRegistry.ts

+7-38
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type { ParseNode } from "./parseNode";
88
import type { ParseNodeFactory } from "./parseNodeFactory";
99
import { Parsable } from "./parsable";
1010
import type { ParsableFactory } from "./parsableFactory";
11-
import { BackingStoreParseNodeFactory } from "../store";
1211

1312
/**
1413
* This factory holds a list of all the registered factories for the various types of nodes.
@@ -24,6 +23,13 @@ export class ParseNodeFactoryRegistry implements ParseNodeFactory {
2423
}
2524
/** List of factories that are registered by content type. */
2625
public contentTypeAssociatedFactories = new Map<string, ParseNodeFactory>();
26+
27+
/**
28+
* Creates a {@link ParseNode} from the given {@link ArrayBuffer} and content type.
29+
* @param contentType the content type of the {@link ArrayBuffer}.
30+
* @param content the {@link ArrayBuffer} to read from.
31+
* @returns a {@link ParseNode} that can deserialize the given {@link ArrayBuffer}.
32+
*/
2733
public getRootParseNode(contentType: string, content: ArrayBuffer): ParseNode {
2834
if (!contentType) {
2935
throw new Error("content type cannot be undefined or empty");
@@ -44,43 +50,6 @@ export class ParseNodeFactoryRegistry implements ParseNodeFactory {
4450
throw new Error(`Content type ${cleanedContentType} does not have a factory registered to be parsed`);
4551
}
4652

47-
/**
48-
* Registers the default deserializer to the registry.
49-
* @param type the class of the factory to be registered.
50-
*/
51-
public registerDefaultDeserializer(type: new () => ParseNodeFactory): void {
52-
if (!type) throw new Error("Type is required");
53-
const deserializer = new type();
54-
this.contentTypeAssociatedFactories.set(deserializer.getValidContentType(), deserializer);
55-
}
56-
57-
/**
58-
* Enables the backing store on default parse node factories and the given parse node factory.
59-
* @param original The parse node factory to enable the backing store on.
60-
* @returns A new parse node factory with the backing store enabled.
61-
*/
62-
public enableBackingStoreForParseNodeFactory(original: ParseNodeFactory): ParseNodeFactory {
63-
if (!original) throw new Error("Original must be specified");
64-
let result = original;
65-
if (original instanceof ParseNodeFactoryRegistry) {
66-
original.enableBackingStoreForParseNodeRegistry();
67-
} else {
68-
result = new BackingStoreParseNodeFactory(original);
69-
}
70-
this.enableBackingStoreForParseNodeRegistry();
71-
return result;
72-
}
73-
/**
74-
* Enables the backing store on the given parse node factory registry.
75-
*/
76-
public enableBackingStoreForParseNodeRegistry(): void {
77-
for (const [k, v] of this.contentTypeAssociatedFactories) {
78-
if (!(v instanceof BackingStoreParseNodeFactory || v instanceof ParseNodeFactoryRegistry)) {
79-
this.contentTypeAssociatedFactories.set(k, new BackingStoreParseNodeFactory(v));
80-
}
81-
}
82-
}
83-
8453
/**
8554
* Deserializes a buffer into a parsable object
8655
* @param bufferOrString the value to serialize

packages/abstractions/src/serialization/serializationWriterFactoryRegistry.ts

-42
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import type { SerializationWriter } from "./serializationWriter";
88
import type { SerializationWriterFactory } from "./serializationWriterFactory";
99
import type { Parsable } from "./parsable";
1010
import type { ModelSerializerFunction } from "./serializationFunctionTypes";
11-
import { BackingStoreSerializationWriterProxyFactory } from "../store";
12-
import { ParseNodeFactoryRegistry } from "./parseNodeFactoryRegistry";
1311

1412
/** This factory holds a list of all the registered factories for the various types of nodes. */
1513
export class SerializationWriterFactoryRegistry implements SerializationWriterFactory {
@@ -40,27 +38,6 @@ export class SerializationWriterFactoryRegistry implements SerializationWriterFa
4038
throw new Error(`Content type ${cleanedContentType} does not have a factory registered to be serialized`);
4139
}
4240

43-
/**
44-
* Registers the default serializer to the registry.
45-
* @param type the class of the factory to be registered.
46-
*/
47-
public registerDefaultSerializer(type: new () => SerializationWriterFactory): void {
48-
if (!type) throw new Error("Type is required");
49-
const serializer = new type();
50-
this.contentTypeAssociatedFactories.set(serializer.getValidContentType(), serializer);
51-
}
52-
53-
/**
54-
* Enables the backing store on the given serialization factory registry.
55-
*/
56-
public enableBackingStoreForSerializationRegistry(): void {
57-
for (const [k, v] of this.contentTypeAssociatedFactories) {
58-
if (!(v instanceof BackingStoreSerializationWriterProxyFactory || v instanceof SerializationWriterFactoryRegistry)) {
59-
this.contentTypeAssociatedFactories.set(k, new BackingStoreSerializationWriterProxyFactory(v));
60-
}
61-
}
62-
}
63-
6441
/**
6542
* Serializes a parsable object into a buffer
6643
* @param value the value to serialize
@@ -178,23 +155,4 @@ export class SerializationWriterFactoryRegistry implements SerializationWriterFa
178155
const decoder = new TextDecoder();
179156
return decoder.decode(buffer);
180157
}
181-
182-
/**
183-
* Enables the backing store on default serialization writers and the given serialization writer.
184-
* @param parseNodeFactoryRegistry The parse node factory registry to enable the backing store on.
185-
* @param original The serialization writer to enable the backing store on.
186-
* @returns A new serialization writer with the backing store enabled.
187-
*/
188-
public enableBackingStoreForSerializationWriterFactory = (parseNodeFactoryRegistry: ParseNodeFactoryRegistry, original: SerializationWriterFactory): SerializationWriterFactory => {
189-
if (!original) throw new Error("Original must be specified");
190-
let result = original;
191-
if (original instanceof SerializationWriterFactoryRegistry) {
192-
original.enableBackingStoreForSerializationRegistry();
193-
} else {
194-
result = new BackingStoreSerializationWriterProxyFactory(original);
195-
}
196-
this.enableBackingStoreForSerializationRegistry();
197-
parseNodeFactoryRegistry.enableBackingStoreForParseNodeRegistry();
198-
return result;
199-
};
200158
}

packages/bundle/src/defaultRequestAdapter.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* -------------------------------------------------------------------------------------------
66
*/
77

8-
import { AuthenticationProvider, ParseNodeFactory, ParseNodeFactoryRegistry, SerializationWriterFactory, SerializationWriterFactoryRegistry } from "@microsoft/kiota-abstractions";
8+
import { AuthenticationProvider, ParseNodeFactory, ParseNodeFactoryRegistry, registerDefaultDeserializer, registerDefaultSerializer, SerializationWriterFactory, SerializationWriterFactoryRegistry } from "@microsoft/kiota-abstractions";
99
import { FormParseNodeFactory, FormSerializationWriterFactory } from "@microsoft/kiota-serialization-form";
1010
import { JsonParseNodeFactory, JsonSerializationWriterFactory } from "@microsoft/kiota-serialization-json";
1111
import { MultipartSerializationWriterFactory } from "@microsoft/kiota-serialization-multipart";
@@ -44,12 +44,12 @@ export class DefaultRequestAdapter extends FetchRequestAdapter {
4444
throw new Error("SerializationWriterFactory must be a SerializationWriterFactoryRegistry");
4545
}
4646

47-
serializationWriterFactoryRegistry.registerDefaultSerializer(JsonSerializationWriterFactory);
48-
serializationWriterFactoryRegistry.registerDefaultSerializer(TextSerializationWriterFactory);
49-
serializationWriterFactoryRegistry.registerDefaultSerializer(FormSerializationWriterFactory);
50-
serializationWriterFactoryRegistry.registerDefaultSerializer(MultipartSerializationWriterFactory);
51-
parseNodeFactoryRegistry.registerDefaultDeserializer(JsonParseNodeFactory);
52-
parseNodeFactoryRegistry.registerDefaultDeserializer(TextParseNodeFactory);
53-
parseNodeFactoryRegistry.registerDefaultDeserializer(FormParseNodeFactory);
47+
registerDefaultSerializer(serializationWriterFactoryRegistry, JsonSerializationWriterFactory);
48+
registerDefaultSerializer(serializationWriterFactoryRegistry, TextSerializationWriterFactory);
49+
registerDefaultSerializer(serializationWriterFactoryRegistry, FormSerializationWriterFactory);
50+
registerDefaultSerializer(serializationWriterFactoryRegistry, MultipartSerializationWriterFactory);
51+
registerDefaultDeserializer(parseNodeFactoryRegistry, JsonParseNodeFactory);
52+
registerDefaultDeserializer(parseNodeFactoryRegistry, TextParseNodeFactory);
53+
registerDefaultDeserializer(parseNodeFactoryRegistry, FormParseNodeFactory);
5454
}
5555
}

packages/http/fetch/src/fetchRequestAdapter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* -------------------------------------------------------------------------------------------
66
*/
77

8-
import { type ApiError, type AuthenticationProvider, type BackingStoreFactory, BackingStoreFactorySingleton, type DateOnly, DefaultApiError, type Duration, type ErrorMappings, type Parsable, type ParsableFactory, type ParseNode, type ParseNodeFactory, ParseNodeFactoryRegistry, type PrimitiveTypesForDeserialization, type PrimitiveTypesForDeserializationType, type RequestAdapter, type RequestInformation, type ResponseHandler, type ResponseHandlerOption, ResponseHandlerOptionKey, type SerializationWriterFactory, SerializationWriterFactoryRegistry, type TimeOnly } from "@microsoft/kiota-abstractions";
8+
import { type ApiError, type AuthenticationProvider, type BackingStoreFactory, BackingStoreFactorySingleton, type DateOnly, DefaultApiError, type Duration, enableBackingStoreForParseNodeFactory, enableBackingStoreForSerializationWriterFactory, type ErrorMappings, type Parsable, type ParsableFactory, type ParseNode, type ParseNodeFactory, ParseNodeFactoryRegistry, type PrimitiveTypesForDeserialization, type PrimitiveTypesForDeserializationType, type RequestAdapter, type RequestInformation, type ResponseHandler, type ResponseHandlerOption, ResponseHandlerOptionKey, type SerializationWriterFactory, SerializationWriterFactoryRegistry, type TimeOnly } from "@microsoft/kiota-abstractions";
99
import { type Span, SpanStatusCode, trace } from "@opentelemetry/api";
1010

1111
import { HttpClient } from "./httpClient";
@@ -360,12 +360,12 @@ export class FetchRequestAdapter implements RequestAdapter {
360360
};
361361
public enableBackingStore = (backingStoreFactory?: BackingStoreFactory): void => {
362362
if (this.parseNodeFactory instanceof ParseNodeFactoryRegistry) {
363-
this.parseNodeFactory = this.parseNodeFactory.enableBackingStoreForParseNodeFactory(this.parseNodeFactory);
363+
this.parseNodeFactory = enableBackingStoreForParseNodeFactory(this.parseNodeFactory, this.parseNodeFactory);
364364
} else {
365365
throw new Error("parseNodeFactory is not a ParseNodeFactoryRegistry");
366366
}
367367
if (this.serializationWriterFactory instanceof SerializationWriterFactoryRegistry && this.parseNodeFactory instanceof ParseNodeFactoryRegistry) {
368-
this.serializationWriterFactory = this.serializationWriterFactory.enableBackingStoreForSerializationWriterFactory(this.parseNodeFactory, this.serializationWriterFactory);
368+
this.serializationWriterFactory = enableBackingStoreForSerializationWriterFactory(this.serializationWriterFactory, this.parseNodeFactory, this.serializationWriterFactory);
369369
} else {
370370
throw new Error("serializationWriterFactory is not a SerializationWriterFactoryRegistry or parseNodeFactory is not a ParseNodeFactoryRegistry");
371371
}

packages/test/generatedCode/apiClient.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// @ts-ignore
55
import { type UsersRequestBuilder, UsersRequestBuilderNavigationMetadata } from './users/index.js';
66
// @ts-ignore
7-
import { apiClientProxifier, type BaseRequestBuilder, type KeysToExcludeForNavigationMetadata, type NavigationMetadata, type RequestAdapter, ParseNodeFactoryRegistry, SerializationWriterFactoryRegistry } from '@microsoft/kiota-abstractions';
7+
import { apiClientProxifier,registerDefaultDeserializer, registerDefaultSerializer, type BaseRequestBuilder, type KeysToExcludeForNavigationMetadata, type NavigationMetadata, type RequestAdapter, ParseNodeFactoryRegistry, SerializationWriterFactoryRegistry } from '@microsoft/kiota-abstractions';
88
// @ts-ignore
99
import { FormParseNodeFactory, FormSerializationWriterFactory } from '@microsoft/kiota-serialization-form';
1010
// @ts-ignore
@@ -46,13 +46,13 @@ export function createApiClient(requestAdapter: RequestAdapter) {
4646
throw new Error("serializationWriterFactory is not an instance of SerializationWriterFactory");
4747
}
4848

49-
serializationWriterFactory.registerDefaultSerializer(JsonSerializationWriterFactory);
50-
serializationWriterFactory.registerDefaultSerializer(TextSerializationWriterFactory);
51-
serializationWriterFactory.registerDefaultSerializer(FormSerializationWriterFactory);
52-
serializationWriterFactory.registerDefaultSerializer(MultipartSerializationWriterFactory);
53-
parseNodeFactoryRegistry.registerDefaultDeserializer(JsonParseNodeFactory);
54-
parseNodeFactoryRegistry.registerDefaultDeserializer(TextParseNodeFactory);
55-
parseNodeFactoryRegistry.registerDefaultDeserializer(FormParseNodeFactory);
49+
registerDefaultSerializer(serializationWriterFactory, JsonSerializationWriterFactory);
50+
registerDefaultSerializer(serializationWriterFactory, TextSerializationWriterFactory);
51+
registerDefaultSerializer(serializationWriterFactory, FormSerializationWriterFactory);
52+
registerDefaultSerializer(serializationWriterFactory, MultipartSerializationWriterFactory);
53+
registerDefaultDeserializer(parseNodeFactoryRegistry, JsonParseNodeFactory);
54+
registerDefaultDeserializer(parseNodeFactoryRegistry, TextParseNodeFactory);
55+
registerDefaultDeserializer(parseNodeFactoryRegistry, FormParseNodeFactory);
5656
if (requestAdapter.baseUrl === undefined || requestAdapter.baseUrl === "") {
5757
requestAdapter.baseUrl = "https://graph.microsoft.com/v1.0";
5858
}

0 commit comments

Comments
 (0)