Skip to content

Commit

Permalink
Merge pull request #789 from microsoft/feature/use-import-type-for-in…
Browse files Browse the repository at this point in the history
…terfaces

Update the abstraction library code to use import type for interfaces
  • Loading branch information
koros authored Oct 12, 2023
2 parents 29baf06 + 0bc9e9b commit aba545b
Show file tree
Hide file tree
Showing 469 changed files with 4,928 additions and 4,307 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.js
*.js.map
*.d.ts

node_modules
dist
35 changes: 35 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/consistent-type-imports": "error"
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"build:sdk:cjs": "tsc -b packages/test/tsconfig.sdk.cjs.json",
"build:watch:es": "tsc -b packages/test/tsconfig.es.json -w",
"test": "lerna run test --parallel",
"tsc:version": "tsc --version"
"tsc:version": "tsc --version",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix"
}
}
1 change: 1 addition & 0 deletions packages/abstractions/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/consistent-type-imports": "error",
"prettier/prettier": [
"error",
{
Expand Down
6 changes: 3 additions & 3 deletions packages/abstractions/src/apiClientBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
ParseNodeFactory,
type ParseNodeFactory,
ParseNodeFactoryRegistry,
SerializationWriterFactory,
SerializationWriterFactoryRegistry,
type SerializationWriterFactory,
SerializationWriterFactoryRegistry
} from "./serialization";
import {
BackingStoreParseNodeFactory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AllowedHostsValidator } from "./allowedHostsValidator";
import { type AllowedHostsValidator } from "./allowedHostsValidator";

/**
* @interface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RequestInformation } from "../requestInformation";
import { AuthenticationProvider } from "./authenticationProvider";
import { type RequestInformation } from "../requestInformation";
import { type AuthenticationProvider } from "./authenticationProvider";

/** This authentication provider does not perform any authentication. */
export class AnonymousAuthenticationProvider implements AuthenticationProvider {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RequestInformation } from "../requestInformation";
import { type RequestInformation } from "../requestInformation";
import { AllowedHostsValidator } from "./allowedHostsValidator";
import { AuthenticationProvider } from "./authenticationProvider";
import type { AuthenticationProvider } from "./authenticationProvider";
import { validateProtocol } from "./validateProtocol";

/** Authenticate a request by using an API Key */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RequestInformation } from "../requestInformation";
import { type RequestInformation } from "../requestInformation";

/**
* @interface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RequestInformation } from "../requestInformation";
import { AccessTokenProvider } from "./accessTokenProvider";
import { AuthenticationProvider } from "./authenticationProvider";
import { type RequestInformation } from "../requestInformation";
import type { AccessTokenProvider } from "./accessTokenProvider";
import type { AuthenticationProvider } from "./authenticationProvider";

/** Provides a base class for implementing AuthenticationProvider for Bearer token scheme. */
export class BaseBearerTokenAuthenticationProvider
Expand Down
6 changes: 3 additions & 3 deletions packages/abstractions/src/authentication/validateProtocol.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export function validateProtocol(url: string): void {
if(!url.toLocaleLowerCase().startsWith('https://') && !windowUrlStartsWithHttps()) {
throw new Error('Authentication scheme can only be used with https requests');
if(!url.toLocaleLowerCase().startsWith("https://") && !windowUrlStartsWithHttps()) {
throw new Error("Authentication scheme can only be used with https requests");
}
}
function windowUrlStartsWithHttps(): boolean {
// @ts-ignore
return typeof window !== 'undefined' && typeof window.location !== 'undefined' && (window.location.protocol as string).toLowerCase() !== 'https:';
return typeof window !== "undefined" && typeof window.location !== "undefined" && (window.location.protocol as string).toLowerCase() !== "https:";
}
2 changes: 1 addition & 1 deletion packages/abstractions/src/baseRequestBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPathParameters } from "./getPathParameters";
import { RequestAdapter } from "./requestAdapter";
import type { RequestAdapter } from "./requestAdapter";

export abstract class BaseRequestBuilder {
/** Path parameters for the request */
Expand Down
1 change: 1 addition & 0 deletions packages/abstractions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export * from "./serialization";
export * from "./store";
export * from "./timeOnly";
export * from "./utils";
export * from "./recordWithCaseInsensitiveKeys";
export * from "./responseHandlerOptions";
7 changes: 1 addition & 6 deletions packages/abstractions/src/multipartBody.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Guid } from "guid-typescript";

import type { RequestAdapter } from "./requestAdapter";
import type {
ModelSerializerFunction,
ParseNode,
SerializationWriter,
} from "./serialization";
import type { Parsable } from "./serialization/parsable";
import type { ModelSerializerFunction, Parsable, ParseNode, SerializationWriter } from "./serialization";
/**
* Defines an interface for a multipart body for request or response.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/abstractions/src/nativeResponseHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ResponseHandler } from "./responseHandler";
import { Parsable, ParsableFactory } from "./serialization";
import type { ResponseHandler } from "./responseHandler";
import type { Parsable, ParsableFactory } from "./serialization";

/** Default response handler to access the native response object. */
export class NativeResponseHandler implements ResponseHandler {
Expand Down
4 changes: 2 additions & 2 deletions packages/abstractions/src/nativeResponseWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NativeResponseHandler } from "./nativeResponseHandler";
import { RequestOption } from "./requestOption";
import { ResponseHandler } from "./responseHandler";
import type { RequestOption } from "./requestOption";
import type { ResponseHandler } from "./responseHandler";

type originalCallType<modelType, queryParametersType, headersType> = (
q?: queryParametersType,
Expand Down
10 changes: 3 additions & 7 deletions packages/abstractions/src/requestAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { RequestInformation } from "./requestInformation";
import {
Parsable,
ParsableFactory,
SerializationWriterFactory,
} from "./serialization";
import { BackingStoreFactory } from "./store";
import { type RequestInformation } from "./requestInformation";
import type { Parsable, ParsableFactory, SerializationWriterFactory } from "./serialization";
import { type BackingStoreFactory } from "./store";

/** Service responsible for translating abstract Request Info into concrete native HTTP requests. */
export interface RequestAdapter {
Expand Down
15 changes: 6 additions & 9 deletions packages/abstractions/src/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import { StdUriTemplate } from "@std-uritemplate/std-uritemplate";

import { DateOnly } from "./dateOnly";
import { Duration } from "./duration";
import { HttpMethod } from "./httpMethod";
import { type HttpMethod } from "./httpMethod";
import { MultipartBody } from "./multipartBody";
import { createRecordWithCaseInsensitiveKeys } from "./recordWithCaseInsensitiveKeys";
import { RequestAdapter } from "./requestAdapter";
import { RequestOption } from "./requestOption";
import {
ModelSerializerFunction,
Parsable,
SerializationWriter,
} from "./serialization";
import type { RequestAdapter } from "./requestAdapter";
import type { RequestOption } from "./requestOption";
import type { ModelSerializerFunction, Parsable, SerializationWriter } from "./serialization";
import { TimeOnly } from "./timeOnly";

/** This class represents an abstract HTTP request. */
Expand Down Expand Up @@ -76,7 +72,8 @@ export class RequestInformation {
string | number | boolean | undefined
>();
/** The Request Headers. */
public headers: Record<string, string[]> = {};
public headers: Record<string, string[]> =
createRecordWithCaseInsensitiveKeys<string[]>();
private _requestOptions: Record<string, RequestOption> =
createRecordWithCaseInsensitiveKeys<RequestOption>();
/** Gets the request options for the request. */
Expand Down
2 changes: 1 addition & 1 deletion packages/abstractions/src/responseHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Parsable, ParsableFactory } from "./serialization";
import type { Parsable, ParsableFactory } from "./serialization";

/** Defines the contract for a response handler. */
export interface ResponseHandler {
Expand Down
4 changes: 2 additions & 2 deletions packages/abstractions/src/responseHandlerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* -------------------------------------------------------------------------------------------
*/

import { RequestOption } from "./requestOption";
import { ResponseHandler } from "./responseHandler";
import type { RequestOption } from "./requestOption";
import type { ResponseHandler } from "./responseHandler";

export const ResponseHandlerOptionKey = "ResponseHandlerOptionKey";

Expand Down
6 changes: 3 additions & 3 deletions packages/abstractions/src/serialization/parsableFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Parsable } from "./parsable";
import { ParseNode } from "./parseNode";
import { DeserializeIntoModelFunction } from "./serializationFunctionTypes";
import type { Parsable } from "./parsable";
import type { ParseNode } from "./parseNode";
import type { DeserializeIntoModelFunction } from "./serializationFunctionTypes";

/**
* Defines the factory to get the deserializers constructing the parsable models.
Expand Down
12 changes: 6 additions & 6 deletions packages/abstractions/src/serialization/parseNode.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Guid } from "guid-typescript";
import type { Guid } from "guid-typescript";

import { DateOnly } from "../dateOnly";
import { Duration } from "../duration";
import { TimeOnly } from "../timeOnly";
import { Parsable } from "./parsable";
import { ParsableFactory } from "./parsableFactory";
import type { DateOnly } from "../dateOnly";
import type { Duration } from "../duration";
import type { TimeOnly } from "../timeOnly";
import type { Parsable } from "./parsable";
import type { ParsableFactory } from "./parsableFactory";

/**
* Interface for a deserialization node in a parse tree. This interface provides an abstraction layer over serialization formats, libraries and implementations.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParseNode } from "./parseNode";
import type { ParseNode } from "./parseNode";

/**
* Defines the contract for a factory that is used to create {@link ParseNode}s.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ParseNode } from "./parseNode";
import { ParseNodeFactory } from "./parseNodeFactory";
import type { ParseNode } from "./parseNode";
import type { ParseNodeFactory } from "./parseNodeFactory";

/**
* This factory holds a list of all the registered factories for the various types of nodes.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Parsable } from "./parsable";
import { ParseNode } from "./parseNode";
import { ParseNodeFactory } from "./parseNodeFactory";
import type { Parsable } from "./parsable";
import type { ParseNode } from "./parseNode";
import type { ParseNodeFactory } from "./parseNodeFactory";

/** Proxy factory that allows the composition of before and after callbacks on existing factories. */
export abstract class ParseNodeProxyFactory implements ParseNodeFactory {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Parsable } from "./parsable";
import { ParseNode } from "./parseNode";
import { SerializationWriter } from "./serializationWriter";
import type { Parsable } from "./parsable";
import type { ParseNode } from "./parseNode";
import type { SerializationWriter } from "./serializationWriter";

export type ModelSerializerFunction<T extends Parsable> = (
writer: SerializationWriter,
Expand Down
12 changes: 6 additions & 6 deletions packages/abstractions/src/serialization/serializationWriter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Guid } from "guid-typescript";
import type { Guid } from "guid-typescript";

import { DateOnly } from "../dateOnly";
import { Duration } from "../duration";
import { TimeOnly } from "../timeOnly";
import { Parsable } from "./parsable";
import { ModelSerializerFunction } from "./serializationFunctionTypes";
import type { DateOnly } from "../dateOnly";
import type { Duration } from "../duration";
import type { TimeOnly } from "../timeOnly";
import type { Parsable } from "./parsable";
import type { ModelSerializerFunction } from "./serializationFunctionTypes";

/** Defines an interface for serialization of objects to a stream. */
export interface SerializationWriter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SerializationWriter } from "./serializationWriter";
import type { SerializationWriter } from "./serializationWriter";

/** Defines the contract for a factory that creates SerializationWriter instances. */
export interface SerializationWriterFactory {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SerializationWriter } from "./serializationWriter";
import { SerializationWriterFactory } from "./serializationWriterFactory";
import type { SerializationWriter } from "./serializationWriter";
import type { SerializationWriterFactory } from "./serializationWriterFactory";

/** This factory holds a list of all the registered factories for the various types of nodes. */
export class SerializationWriterFactoryRegistry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Parsable } from "./parsable";
import { SerializationWriter } from "./serializationWriter";
import { SerializationWriterFactory } from "./serializationWriterFactory";
import type { Parsable } from "./parsable";
import type { SerializationWriter } from "./serializationWriter";
import type { SerializationWriterFactory } from "./serializationWriterFactory";

/** Proxy factory that allows the composition of before and after callbacks on existing factories. */
export abstract class SerializationWriterProxyFactory
Expand Down
2 changes: 1 addition & 1 deletion packages/abstractions/src/store/backedModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BackingStore } from "./backingStore";
import type { BackingStore } from "./backingStore";

/** Defines the contracts for a model that is backed by a store. */
export interface BackedModel {
Expand Down
2 changes: 1 addition & 1 deletion packages/abstractions/src/store/backingStoreFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BackingStore } from "./backingStore";
import type { BackingStore } from "./backingStore";

/** Defines the contract for a factory that creates backing stores. */
export interface BackingStoreFactory {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BackingStoreFactory } from "./backingStoreFactory";
import type { BackingStoreFactory } from "./backingStoreFactory";
import { InMemoryBackingStoreFactory } from "./inMemoryBackingStoreFactory";

export class BackingStoreFactorySingleton {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ParseNodeFactory, ParseNodeProxyFactory } from "../serialization";
import { BackedModel } from "./backedModel";
import { type ParseNodeFactory, ParseNodeProxyFactory } from "../serialization";
import type { BackedModel } from "./backedModel";

/** Proxy implementation of ParseNodeFactory for the backing store that automatically sets the state of the backing store when deserializing. */
export class BackingStoreParseNodeFactory extends ParseNodeProxyFactory {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
SerializationWriterFactory,
SerializationWriterProxyFactory,
} from "../serialization";
import { BackedModel } from "./backedModel";
import { type SerializationWriterFactory, SerializationWriterProxyFactory } from "../serialization";
import type { BackedModel } from "./backedModel";

/**Proxy implementation of SerializationWriterFactory for the backing store that automatically sets the state of the backing store when serializing. */
export class BackingStoreSerializationWriterProxyFactory extends SerializationWriterProxyFactory {
Expand Down
2 changes: 1 addition & 1 deletion packages/abstractions/src/store/inMemoryBackingStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { v4 as uuidv4 } from "uuid";

import { BackingStore } from "./backingStore";
import type { BackingStore } from "./backingStore";

interface storeEntryWrapper {
changed: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BackingStore } from "./backingStore";
import { BackingStoreFactory } from "./backingStoreFactory";
import type { BackingStore } from "./backingStore";
import type { BackingStoreFactory } from "./backingStoreFactory";
import { InMemoryBackingStore } from "./inMemoryBackingStore";

/** This class is used to create instances of InMemoryBackingStore */
Expand Down
Loading

0 comments on commit aba545b

Please sign in to comment.