-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1298 from microsoft/andrueastman/kiota-bundle
Setup bundle for TS
- Loading branch information
Showing
21 changed files
with
214 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
*.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.eslint** | ||
.prettier** | ||
*.log | ||
*.tgz | ||
**/test/**/* | ||
docs/ | ||
node_modules/ | ||
rollup.config.js | ||
src/ | ||
tsconfig.**.json | ||
vite.config.mts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[![npm version badge](https://img.shields.io/npm/v/@microsoft/kiota-bundle?color=blue)](https://www.npmjs.com/package/@microsoft/kiota-bundle) | ||
|
||
The Kiota Bundle Library provides default implementations for client setup. | ||
The package provides a request adapter implementation with defaults serialization libraries setup fo use with a generated Kiota client. | ||
|
||
Read more about Kiota [here](https://github.com/microsoft/kiota/blob/main/README.md). | ||
|
||
## Using the bundle | ||
|
||
`npm i @microsoft/kiota-bundle` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "@microsoft/kiota-bundle", | ||
"version": "1.0.0-preview.1", | ||
"description": "Kiota Bundle package providing default implementations for client setup for kiota generated libraries in TypeScript and JavaScript", | ||
"main": "dist/es/src/index.js", | ||
"module": "dist/es/src/index.js", | ||
"types": "dist/es/src/index.d.ts", | ||
"type": "module", | ||
"scripts": { | ||
"build": "npm run build:esm", | ||
"build:esm": "tsc && tsc-alias", | ||
"lint": "eslint . --ext .ts", | ||
"lint:fix": "eslint . --ext .ts --fix", | ||
"clean": "rimraf ./dist", | ||
"test:browser": "vitest run --browser.name=chrome --browser.headless --browser.provider=webdriverio", | ||
"test:node": "vitest --run", | ||
"test": "npm run test:node && npm run test:browser" | ||
}, | ||
"repository": "git://github.com/microsoft/kiota-typescript.git", | ||
"keywords": [ | ||
"kiota", | ||
"openAPI", | ||
"Microsoft", | ||
"Graph" | ||
], | ||
"author": "Microsoft", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/microsoft/kiota-typescript/issues" | ||
}, | ||
"homepage": "https://github.com/microsoft/kiota#readme", | ||
"devDependencies": { | ||
}, | ||
"dependencies": { | ||
"@microsoft/kiota-abstractions": "*", | ||
"@microsoft/kiota-http-fetchlibrary": "*", | ||
"@microsoft/kiota-serialization-form": "*", | ||
"@microsoft/kiota-serialization-json": "*", | ||
"@microsoft/kiota-serialization-text": "*", | ||
"@microsoft/kiota-serialization-multipart": "*" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* ------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. | ||
* See License in the project root for license information. | ||
* ------------------------------------------------------------------------------------------- | ||
*/ | ||
|
||
import { AuthenticationProvider, ParseNodeFactory, ParseNodeFactoryRegistry, registerDefaultDeserializer, registerDefaultSerializer, SerializationWriterFactory, SerializationWriterFactoryRegistry } from "@microsoft/kiota-abstractions"; | ||
import { FormParseNodeFactory, FormSerializationWriterFactory } from "@microsoft/kiota-serialization-form"; | ||
import { JsonParseNodeFactory, JsonSerializationWriterFactory } from "@microsoft/kiota-serialization-json"; | ||
import { MultipartSerializationWriterFactory } from "@microsoft/kiota-serialization-multipart"; | ||
import { TextParseNodeFactory, TextSerializationWriterFactory } from "@microsoft/kiota-serialization-text"; | ||
import { FetchRequestAdapter, HttpClient, type ObservabilityOptions, ObservabilityOptionsImpl } from "@microsoft/kiota-http-fetchlibrary"; | ||
|
||
/** | ||
* Default request adapter for graph clients. Bootstraps serialization and other aspects. | ||
*/ | ||
export class DefaultRequestAdapter extends FetchRequestAdapter { | ||
/** | ||
* Instantiates a new request adapter. | ||
* @param authenticationProvider the authentication provider to use. | ||
* @param parseNodeFactory the parse node factory to deserialize responses. | ||
* @param serializationWriterFactory the serialization writer factory to use to serialize request bodies. | ||
* @param httpClient the http client to use to execute requests. | ||
* @param observabilityOptions the observability options to use. | ||
*/ | ||
public constructor(authenticationProvider: AuthenticationProvider, parseNodeFactory: ParseNodeFactory = ParseNodeFactoryRegistry.defaultInstance, serializationWriterFactory: SerializationWriterFactory = SerializationWriterFactoryRegistry.defaultInstance, httpClient: HttpClient = new HttpClient(), observabilityOptions: ObservabilityOptions = new ObservabilityOptionsImpl()) { | ||
super(authenticationProvider, parseNodeFactory, serializationWriterFactory, httpClient, observabilityOptions); | ||
DefaultRequestAdapter.setupDefaults(); | ||
} | ||
|
||
private static setupDefaults() { | ||
registerDefaultSerializer(JsonSerializationWriterFactory); | ||
registerDefaultSerializer(TextSerializationWriterFactory); | ||
registerDefaultSerializer(FormSerializationWriterFactory); | ||
registerDefaultSerializer(MultipartSerializationWriterFactory); | ||
registerDefaultDeserializer(JsonParseNodeFactory); | ||
registerDefaultDeserializer(TextParseNodeFactory); | ||
registerDefaultDeserializer(FormParseNodeFactory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* ------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. | ||
* See License in the project root for license information. | ||
* ------------------------------------------------------------------------------------------- | ||
*/ | ||
|
||
/* eslint-disable @typescript-eslint/triple-slash-reference*/ | ||
|
||
export * from "./defaultRequestAdapter"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* ------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. | ||
* See License in the project root for license information. | ||
* ------------------------------------------------------------------------------------------- | ||
*/ | ||
import { AnonymousAuthenticationProvider, AuthenticationProvider, ParseNodeFactoryRegistry, SerializationWriterFactoryRegistry } from "@microsoft/kiota-abstractions"; | ||
import { assert, describe, it } from "vitest"; | ||
|
||
import { DefaultRequestAdapter } from "../src/defaultRequestAdapter"; | ||
|
||
describe("defaultRequestAdapter.ts", () => { | ||
describe("Initialization", () => { | ||
it("should throw error on null authProvider", async () => { | ||
assert.throws(() => new DefaultRequestAdapter(null as unknown as AuthenticationProvider), Error, "authentication provider cannot be null"); | ||
}); | ||
|
||
it("should setup serializers correctly", async () => { | ||
const requestAdapter = new DefaultRequestAdapter(new AnonymousAuthenticationProvider()); | ||
|
||
assert.isNotNull(requestAdapter); | ||
|
||
const serializerMap = SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories; | ||
const deserializerMap = ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories; | ||
|
||
assert.isNotNull(serializerMap); | ||
assert.isNotNull(deserializerMap); | ||
|
||
// verify that the default serializers are registered | ||
assert.equal(serializerMap.size, 4); | ||
assert.equal(deserializerMap.size, 3); | ||
|
||
// verify that the default serializers are registered by name | ||
assert.isTrue(serializerMap.has("application/json")); | ||
assert.isTrue(serializerMap.has("text/plain")); | ||
assert.isTrue(serializerMap.has("application/x-www-form-urlencoded")); | ||
assert.isTrue(serializerMap.has("multipart/form-data")); | ||
|
||
// verify that the default deserializers are registered by name | ||
assert.isTrue(deserializerMap.has("application/json")); | ||
assert.isTrue(deserializerMap.has("text/plain")); | ||
assert.isTrue(deserializerMap.has("application/x-www-form-urlencoded")); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "dist/es/" | ||
}, | ||
"include": [ | ||
"./src/**/*.ts", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineConfig, configDefaults } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
exclude: [...configDefaults.exclude, "**/test{Entity,Enum}.ts"], | ||
include: [...configDefaults.include, "test/**/*.ts"], | ||
coverage: { | ||
reporter: ["html"], | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters