diff --git a/package-lock.json b/package-lock.json index 596c3cb..9c3215b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -888,9 +888,9 @@ } }, "node_modules/@microsoft/kiota-abstractions": { - "version": "1.0.0-preview.91", - "resolved": "https://registry.npmjs.org/@microsoft/kiota-abstractions/-/kiota-abstractions-1.0.0-preview.91.tgz", - "integrity": "sha512-JjID/f3bv2vKM5Ahf/fwBVcnwt1AezZjiinzoIibVx2Ki4CQwyaEf5PSSxrOazhRR9UWbdv4h8kc355zxsxxZg==", + "version": "1.0.0-preview.92", + "resolved": "https://registry.npmjs.org/@microsoft/kiota-abstractions/-/kiota-abstractions-1.0.0-preview.92.tgz", + "integrity": "sha512-B0w9MJBaK/enLeXQR479YNx6uHs1I6Gfu3OszmI2JbRCfS6ON1oyAB6cWTK2cB1sUD8C3vHR3TgtQfZG2pC5Og==", "license": "MIT", "dependencies": { "@opentelemetry/api": "^1.7.0", @@ -900,79 +900,79 @@ } }, "node_modules/@microsoft/kiota-authentication-azure": { - "version": "1.0.0-preview.91", - "resolved": "https://registry.npmjs.org/@microsoft/kiota-authentication-azure/-/kiota-authentication-azure-1.0.0-preview.91.tgz", - "integrity": "sha512-YGYgona65dOCs15yfcH0xgGiKOCSQyNIPxZG9dNc6b1T7gpz5CU+U1I+2CzpwDHCBgbcqZSWwmN3fblDuvkXEg==", + "version": "1.0.0-preview.92", + "resolved": "https://registry.npmjs.org/@microsoft/kiota-authentication-azure/-/kiota-authentication-azure-1.0.0-preview.92.tgz", + "integrity": "sha512-Hif7sfkdVE+gMpvAVeG5fCRUcNp6n+XYWIxu18ewzV1UMn9qygpIFVepcVnG7lAdetBvtddlGiAnwTFSqdSJdQ==", "license": "MIT", "dependencies": { "@azure/core-auth": "^1.5.0", - "@microsoft/kiota-abstractions": "^1.0.0-preview.91", + "@microsoft/kiota-abstractions": "^1.0.0-preview.92", "@opentelemetry/api": "^1.7.0", "tslib": "^2.6.2" } }, "node_modules/@microsoft/kiota-bundle": { - "version": "1.0.0-preview.91", - "resolved": "https://registry.npmjs.org/@microsoft/kiota-bundle/-/kiota-bundle-1.0.0-preview.91.tgz", - "integrity": "sha512-gc0UnL+fkyp4oNtqLXCjM0QYngwFMIeA5r/VY7RQ1B2o02T7CheoP/C9KQnv50FYJPibMauSaWKCNgbV1vxWLA==", + "version": "1.0.0-preview.92", + "resolved": "https://registry.npmjs.org/@microsoft/kiota-bundle/-/kiota-bundle-1.0.0-preview.92.tgz", + "integrity": "sha512-BZI+gF05xMmY32oTLBbBO8vM7Zy/26dSaAqPnoxEJQombjB2LmxS/fnEhc84pHoeOsMKTFOTr9DpOzRJglhNsQ==", "license": "MIT", "dependencies": { - "@microsoft/kiota-abstractions": "^1.0.0-preview.91", - "@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.91", - "@microsoft/kiota-serialization-form": "^1.0.0-preview.91", - "@microsoft/kiota-serialization-json": "^1.0.0-preview.91", - "@microsoft/kiota-serialization-multipart": "^1.0.0-preview.91", - "@microsoft/kiota-serialization-text": "^1.0.0-preview.91" + "@microsoft/kiota-abstractions": "^1.0.0-preview.92", + "@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.92", + "@microsoft/kiota-serialization-form": "^1.0.0-preview.92", + "@microsoft/kiota-serialization-json": "^1.0.0-preview.92", + "@microsoft/kiota-serialization-multipart": "^1.0.0-preview.92", + "@microsoft/kiota-serialization-text": "^1.0.0-preview.92" } }, "node_modules/@microsoft/kiota-http-fetchlibrary": { - "version": "1.0.0-preview.91", - "resolved": "https://registry.npmjs.org/@microsoft/kiota-http-fetchlibrary/-/kiota-http-fetchlibrary-1.0.0-preview.91.tgz", - "integrity": "sha512-BNOfth/u9FSjxl/deF5Sq3oNEbApzwUZUHv9Ub1heiVh8mYeJ+IsFAz+zChv5WO9BjUz7XbalGfK/J0o2pCTRg==", + "version": "1.0.0-preview.92", + "resolved": "https://registry.npmjs.org/@microsoft/kiota-http-fetchlibrary/-/kiota-http-fetchlibrary-1.0.0-preview.92.tgz", + "integrity": "sha512-EyU7hUOuDGyCrNeJ9qR9GkE7iEq54RkQ1vdbXxbOZdPogjQcNbZm6Pb5/yDiPwwMIuS3LXvVVVY3jJQwfXQtOA==", "license": "MIT", "dependencies": { - "@microsoft/kiota-abstractions": "^1.0.0-preview.91", + "@microsoft/kiota-abstractions": "^1.0.0-preview.92", "@opentelemetry/api": "^1.7.0", "tslib": "^2.6.2" } }, "node_modules/@microsoft/kiota-serialization-form": { - "version": "1.0.0-preview.91", - "resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-form/-/kiota-serialization-form-1.0.0-preview.91.tgz", - "integrity": "sha512-oUKtwa2QhrrV+KE+tWJ5luJzPY2j5Mbnxiiu7hYXfIgPXm0vHiSwL1GUWQOMjvI/Q6ikivRxCKLhRDJAB+wWdw==", + "version": "1.0.0-preview.92", + "resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-form/-/kiota-serialization-form-1.0.0-preview.92.tgz", + "integrity": "sha512-fW7gZOnld8a+nz6mJhWbCSC96XiTxD4nGnHYi1SmvK1uK2n74taCZ6g957Fitj+60nVQAFNJmHtvqd633y4XXg==", "license": "MIT", "dependencies": { - "@microsoft/kiota-abstractions": "^1.0.0-preview.91", + "@microsoft/kiota-abstractions": "^1.0.0-preview.92", "tslib": "^2.6.2" } }, "node_modules/@microsoft/kiota-serialization-json": { - "version": "1.0.0-preview.91", - "resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-json/-/kiota-serialization-json-1.0.0-preview.91.tgz", - "integrity": "sha512-wzQb32GF0poPMwpK2ksh2PZM2GJp9S9sEcxv9+ZdkVhiDoDX5W9z2ZAgDSxMgRM/xrOG4dNEJnECeUFWxfpdZA==", + "version": "1.0.0-preview.92", + "resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-json/-/kiota-serialization-json-1.0.0-preview.92.tgz", + "integrity": "sha512-3wb08c2hnBQRmxJ6RFtiGbYEk1spWyzqKenXM1Agtg3XM3MSnpxwxXWfHFvmBGKG2TTxGWaOCCsQsiJmHiI4vA==", "license": "MIT", "dependencies": { - "@microsoft/kiota-abstractions": "^1.0.0-preview.91", + "@microsoft/kiota-abstractions": "^1.0.0-preview.92", "tslib": "^2.6.2" } }, "node_modules/@microsoft/kiota-serialization-multipart": { - "version": "1.0.0-preview.91", - "resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-multipart/-/kiota-serialization-multipart-1.0.0-preview.91.tgz", - "integrity": "sha512-PwOSYwAyPrvEQtWGwXKECVDQQLWfPEWWuSE8ekfKj9HRhCyekyZ8mboyuBIjsPsdZ/4jVQz057CKARor5tmMtQ==", + "version": "1.0.0-preview.92", + "resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-multipart/-/kiota-serialization-multipart-1.0.0-preview.92.tgz", + "integrity": "sha512-koIIAOX6gOP3vHA8s4HSq1T8CW8H5DM8+zgImI7887EDSUqo0rSFSWCVsIyQaQSgaFosxhYrdRkBrJGG2cndDw==", "license": "MIT", "dependencies": { - "@microsoft/kiota-abstractions": "^1.0.0-preview.91", + "@microsoft/kiota-abstractions": "^1.0.0-preview.92", "tslib": "^2.6.2" } }, "node_modules/@microsoft/kiota-serialization-text": { - "version": "1.0.0-preview.91", - "resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-text/-/kiota-serialization-text-1.0.0-preview.91.tgz", - "integrity": "sha512-sb0c+DYrtP+qgSJwLcIJHvOB/HEu1NBZmld4MbgmeVhtnrGnNVRF/BfQqiGtUPWsEwkRI0gLRzX3hj4CDz3+PQ==", + "version": "1.0.0-preview.92", + "resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-text/-/kiota-serialization-text-1.0.0-preview.92.tgz", + "integrity": "sha512-1FHYgw0ZyQX6Tv0Y5JmES1j+D8Tlk5r01xtq37zoAr7RcfEzoWzV9fvYhCXbleKbofE+ozJ70tp0667UdLkAKQ==", "license": "MIT", "dependencies": { - "@microsoft/kiota-abstractions": "^1.0.0-preview.91", + "@microsoft/kiota-abstractions": "^1.0.0-preview.92", "tslib": "^2.6.2" } }, diff --git a/src/adapter/BaseGraphRequestAdapter.ts b/src/adapter/BaseGraphRequestAdapter.ts index 0abb496..fb4fdec 100644 --- a/src/adapter/BaseGraphRequestAdapter.ts +++ b/src/adapter/BaseGraphRequestAdapter.ts @@ -27,8 +27,8 @@ export class BaseGraphRequestAdapter extends DefaultRequestAdapter { graphServiceTargetVersion: string, graphServiceLibraryClientVersion: string, authenticationProvider: AuthenticationProvider, - parseNodeFactory: ParseNodeFactory = ParseNodeFactoryRegistry.defaultInstance, - serializationWriterFactory: SerializationWriterFactory = SerializationWriterFactoryRegistry.defaultInstance, + parseNodeFactory: ParseNodeFactory = new ParseNodeFactoryRegistry(), + serializationWriterFactory: SerializationWriterFactory = new SerializationWriterFactoryRegistry(), httpClient: HttpClient = createGraphClientFactory({ graphServiceTargetVersion, graphServiceLibraryClientVersion, diff --git a/src/content/BatchResponseContent.ts b/src/content/BatchResponseContent.ts index fa4c1d7..cda615f 100644 --- a/src/content/BatchResponseContent.ts +++ b/src/content/BatchResponseContent.ts @@ -10,7 +10,7 @@ */ import { BatchResponseBody, BatchResponse } from "./BatchRequestStep.js"; -import { Parsable, deserializeFromJson, ParsableFactory } from "@microsoft/kiota-abstractions"; +import { Parsable, ParsableFactory, ParseNodeFactoryRegistry } from "@microsoft/kiota-abstractions"; /** * @class @@ -61,13 +61,18 @@ export class BatchResponseContent { * Retrieves a parsable response by request ID. * @template T - The type of the parsable response. * @param {string} requestId - The request ID value. + * @param parseNodeFactoryRegistry - The registry to create parse nodes. * @param {ParsableFactory} factory - The factory to create the parsable response. * @returns {T | undefined} The parsable response object instance for the particular request, or undefined if not found. */ - public getParsableResponseById(requestId: string, factory: ParsableFactory): T | undefined { + public getParsableResponseById( + requestId: string, + parseNodeFactoryRegistry: ParseNodeFactoryRegistry, + factory: ParsableFactory, + ): T | undefined { const res = this.responses.get(requestId); if (res?.body) { - const result = deserializeFromJson(res.body, factory); + const result = parseNodeFactoryRegistry.deserializeFromJson(res.body, factory); return result as T; } return undefined; diff --git a/src/content/BatchResponseContentCollection.ts b/src/content/BatchResponseContentCollection.ts index 0c976ff..79cfe96 100644 --- a/src/content/BatchResponseContentCollection.ts +++ b/src/content/BatchResponseContentCollection.ts @@ -11,12 +11,15 @@ import { BatchResponseContent } from "./BatchResponseContent.js"; import { BatchResponse } from "./BatchRequestStep.js"; -import { deserializeFromJson, Parsable, ParsableFactory } from "@microsoft/kiota-abstractions"; +import { Parsable, ParsableFactory, ParseNodeFactoryRegistry } from "@microsoft/kiota-abstractions"; /** * Represents a collection of BatchResponseContent. */ export class BatchResponseContentCollection { + /** + * An array of BatchResponseContent. + */ public readonly batchResponseContent: BatchResponseContent[] = []; /** @@ -54,13 +57,18 @@ export class BatchResponseContentCollection { /** * Gets the parsable response by the specified request ID. * @param requestId - The ID of the request. + * @param parseNodeFactoryRegistry - The registry to create parse nodes. * @param factory - The factory to create the Parsable instance. * @returns The parsable response, or undefined if not found. */ - public getParsableResponseById(requestId: string, factory: ParsableFactory): T | undefined { + public getParsableResponseById( + requestId: string, + parseNodeFactoryRegistry: ParseNodeFactoryRegistry, + factory: ParsableFactory, + ): T | undefined { const res = this.getResponseById(requestId); if (res?.body) { - const result = deserializeFromJson(res.body, factory); + const result = parseNodeFactoryRegistry.deserializeFromJson(res.body, factory); return result as T; } return undefined; diff --git a/test/content/BatchRequestContent.ts b/test/content/BatchRequestContent.ts index 71e5616..dab6c15 100644 --- a/test/content/BatchRequestContent.ts +++ b/test/content/BatchRequestContent.ts @@ -9,9 +9,9 @@ import { ParseNode, Parsable, Headers, - registerDefaultDeserializer, + ParseNodeFactoryRegistry, } from "@microsoft/kiota-abstractions"; -import { JsonParseNodeFactory, JsonSerializationWriterFactory } from "@microsoft/kiota-serialization-json"; +import { JsonParseNodeFactory } from "@microsoft/kiota-serialization-json"; // @ts-ignore import { createGraphErrorFromDiscriminatorValue } from "../tasks/PageIterator"; import { createCipheriv } from "node:crypto"; @@ -154,14 +154,22 @@ describe("BatchRequestContent tests", () => { assert.equal(response?.status, 200); }); it("Can parse a response a response by Id", () => { - registerDefaultDeserializer(JsonParseNodeFactory); + if (!(adapter.getParseNodeFactory() instanceof ParseNodeFactoryRegistry)) { + throw new Error("Invalid parse node factory"); + } + const parseNodeFactoryRegistry = adapter.getParseNodeFactory() as ParseNodeFactoryRegistry; + parseNodeFactoryRegistry.registerDefaultDeserializer(JsonParseNodeFactory, adapter.getBackingStoreFactory()); const sampleArrayBuffer = new TextEncoder().encode(JSON.stringify({ value: [1, 2, 3], id: "1", name: "test" })); const requestContent = new BatchResponseContent({ responses: [{ id: "1", status: 200, headers: {}, body: sampleArrayBuffer }], }); - const response = requestContent.getParsableResponseById("1", createSampleFromDiscriminatorValue); + const response = requestContent.getParsableResponseById( + "1", + parseNodeFactoryRegistry as ParseNodeFactoryRegistry, + createSampleFromDiscriminatorValue, + ); assert.isNotNull(response); assert.equal(response?.value.length, 3); assert.equal(response?.id, "1"); diff --git a/test/utils/DummyRequestAdapter.ts b/test/utils/DummyRequestAdapter.ts index f1e1e25..2f010b0 100644 --- a/test/utils/DummyRequestAdapter.ts +++ b/test/utils/DummyRequestAdapter.ts @@ -14,12 +14,15 @@ import { type ErrorMappings, Parsable, type ParsableFactory, + ParseNodeFactory, type PrimitiveTypesForDeserialization, type PrimitiveTypesForDeserializationType, RequestAdapter, type RequestInformation, SerializationWriterFactory, SerializationWriterFactoryRegistry, + InMemoryBackingStoreFactory, + ParseNodeFactoryRegistry, } from "@microsoft/kiota-abstractions"; import { JsonSerializationWriterFactory } from "@microsoft/kiota-serialization-json"; @@ -35,7 +38,10 @@ export class DummyRequestAdapter implements RequestAdapter { requests: RequestInformation[] = []; serializationWriterFactory = new SerializationWriterFactoryRegistry(); - constructor() { + constructor( + private parseNodeFactory: ParseNodeFactory = new ParseNodeFactoryRegistry(), + private backingStoreFactory = new InMemoryBackingStoreFactory(), + ) { const serializer = new JsonSerializationWriterFactory(); this.serializationWriterFactory.contentTypeAssociatedFactories.set(serializer.getValidContentType(), serializer); } @@ -128,4 +134,12 @@ export class DummyRequestAdapter implements RequestAdapter { this.requests.push(requestInfo); return Promise.resolve(this.response.shift()); } + + getBackingStoreFactory(): BackingStoreFactory { + return this.backingStoreFactory; + } + + getParseNodeFactory(): ParseNodeFactory { + return this.parseNodeFactory; + } }