js docs cleanup (#367)
This commit is contained in:
Родитель
111fda5a30
Коммит
452b29d540
|
@ -3695,7 +3695,7 @@
|
|||
},
|
||||
"os-homedir": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "http://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
|
||||
"resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
|
||||
"integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=",
|
||||
"dev": true
|
||||
},
|
||||
|
|
20
src/auth.ts
20
src/auth.ts
|
@ -14,6 +14,15 @@ export interface RequestInfo {
|
|||
|
||||
export type TokenProvider = (requestInfo: RequestInfo) => Promise<string>;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param clientOptions
|
||||
* @param verb
|
||||
* @param path
|
||||
* @param resourceId
|
||||
* @param resourceType
|
||||
* @param headers
|
||||
*/
|
||||
export async function setAuthorizationHeader(
|
||||
clientOptions: CosmosClientOptions,
|
||||
verb: HTTPMethod,
|
||||
|
@ -48,7 +57,10 @@ export async function setAuthorizationHeader(
|
|||
}
|
||||
}
|
||||
|
||||
/** The default function for setting header token using the masterKey */
|
||||
/**
|
||||
* The default function for setting header token using the masterKey
|
||||
* @ignore
|
||||
*/
|
||||
export function setAuthorizationTokenHeaderUsingMasterKey(
|
||||
verb: HTTPMethod,
|
||||
resourceId: string,
|
||||
|
@ -63,6 +75,12 @@ export function setAuthorizationTokenHeaderUsingMasterKey(
|
|||
headers = Object.assign(headers, generateHeaders(masterKey, verb, resourceType, resourceId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param resourceTokens
|
||||
* @param path
|
||||
* @param resourceId
|
||||
*/
|
||||
// TODO: Resource tokens
|
||||
function getAuthorizationTokenUsingResourceTokens(
|
||||
resourceTokens: { [resourceId: string]: string },
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export interface PartitionKeyRange {
|
||||
id: string;
|
||||
minInclusive: string;
|
||||
|
|
|
@ -12,6 +12,10 @@ import { Item } from "./Item";
|
|||
import { ItemDefinition } from "./ItemDefinition";
|
||||
import { ItemResponse } from "./ItemResponse";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param options
|
||||
*/
|
||||
function isChangeFeedOptions(options: unknown): options is ChangeFeedOptions {
|
||||
const optionsType = typeof options;
|
||||
return options && !(optionsType === "string" || optionsType === "boolean" || optionsType === "number");
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const Constants = {
|
||||
MediaTypes: {
|
||||
Any: "*/*",
|
||||
|
@ -231,6 +234,9 @@ export const Constants = {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export enum ResourceType {
|
||||
none = "",
|
||||
database = "dbs",
|
||||
|
@ -246,6 +252,9 @@ export enum ResourceType {
|
|||
pkranges = "pkranges"
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export enum HTTPMethod {
|
||||
get = "GET",
|
||||
post = "POST",
|
||||
|
@ -253,6 +262,9 @@ export enum HTTPMethod {
|
|||
delete = "DELETE"
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export enum OperationType {
|
||||
Create = "create",
|
||||
Replace = "replace",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { CosmosClientOptions } from "../CosmosClientOptions";
|
||||
import { Constants, OperationType, ResourceType } from "./constants";
|
||||
|
||||
/** @hidden */
|
||||
/** @ignore */
|
||||
const Regexes = Constants.RegularExpressions;
|
||||
|
||||
/** @hidden */
|
||||
|
@ -13,6 +13,9 @@ export function jsonStringifyAndEscapeNonASCII(arg: any) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function parseLink(resourcePath: string) {
|
||||
if (resourcePath.length === 0) {
|
||||
/* for DatabaseAccount case, both type and objectBody will be undefined. */
|
||||
|
@ -65,10 +68,16 @@ export function parseLink(resourcePath: string) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function isReadRequest(operationType: OperationType): boolean {
|
||||
return operationType === OperationType.Read || operationType === OperationType.Query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function sleep(time: number): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
|
@ -77,6 +86,9 @@ export function sleep(time: number): Promise<void> {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function getContainerLink(link: string) {
|
||||
return link
|
||||
.split("/")
|
||||
|
@ -84,16 +96,25 @@ export function getContainerLink(link: string) {
|
|||
.join("/");
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function trimSlashes(source: string) {
|
||||
return source
|
||||
.replace(Constants.RegularExpressions.TrimLeftSlashes, "")
|
||||
.replace(Constants.RegularExpressions.TrimRightSlashes, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function getHexaDigit() {
|
||||
return Math.floor(Math.random() * 16).toString(16);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function parsePath(path: string) {
|
||||
const pathParts = [];
|
||||
let currentIndex = 0;
|
||||
|
@ -157,6 +178,10 @@ export function parsePath(path: string) {
|
|||
|
||||
return pathParts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function isResourceValid(resource: any, err: any) {
|
||||
// TODO: any TODO: code smell
|
||||
if (resource.id) {
|
||||
|
@ -197,11 +222,18 @@ export function getPathFromLink(resourceLink: string, resourceType?: string) {
|
|||
return "/" + encodeURI(resourceLink);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function isStringNullOrEmpty(inputString: string) {
|
||||
// checks whether string is null, undefined, empty or only contains space
|
||||
return !inputString || /^\s*$/.test(inputString);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function trimSlashFromLeftAndRight(inputString: string) {
|
||||
if (typeof inputString !== "string") {
|
||||
throw new Error("invalid input: input is not string");
|
||||
|
@ -210,6 +242,9 @@ export function trimSlashFromLeftAndRight(inputString: string) {
|
|||
return inputString.replace(Regexes.TrimLeftSlashes, "").replace(Regexes.TrimRightSlashes, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function validateResourceId(resourceId: string) {
|
||||
// if resourceId is not a string or is empty throw an error
|
||||
if (typeof resourceId !== "string" || isStringNullOrEmpty(resourceId)) {
|
||||
|
@ -229,6 +264,10 @@ export function validateResourceId(resourceId: string) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param resourcePath
|
||||
*/
|
||||
export function getResourceIdFromPath(resourcePath: string) {
|
||||
if (!resourcePath || typeof resourcePath !== "string") {
|
||||
return null;
|
||||
|
@ -245,11 +284,17 @@ export function getResourceIdFromPath(resourcePath: string) {
|
|||
return pathSegments[pathSegments.length - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
interface ConnectionObject {
|
||||
AccountEndpoint: string;
|
||||
AccountKey: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function parseConnectionString(connectionString: string): CosmosClientOptions {
|
||||
const keyValueStrings = connectionString.split(";");
|
||||
const { AccountEndpoint, AccountKey } = keyValueStrings.reduce(
|
||||
|
@ -269,6 +314,9 @@ export function parseConnectionString(connectionString: string): CosmosClientOpt
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
// https://github.com/iliakan/detect-node/blob/master/index.js
|
||||
export const isNode: boolean =
|
||||
Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
||||
|
|
|
@ -2,13 +2,15 @@
|
|||
import { Constants } from "./constants";
|
||||
|
||||
/** @hidden */
|
||||
|
||||
export function getPlatformDefaultHeaders(): { [key: string]: string } {
|
||||
const defaultHeaders: { [key: string]: string } = {};
|
||||
defaultHeaders[Constants.HttpHeaders.UserAgent] = getUserAgent();
|
||||
return defaultHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function getUserAgent() {
|
||||
return `${userAgent()} ${Constants.SDKName}/${Constants.SDKVersion}`;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
// tslint:disable:object-literal-key-quotes
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const StatusCodes = {
|
||||
// Success
|
||||
Ok: 200,
|
||||
|
@ -30,6 +32,9 @@ export const StatusCodes = {
|
|||
OperationCancelled: 1201
|
||||
};
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const SubStatusCodes = {
|
||||
Unknown: 0,
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Constants } from "./constants";
|
||||
import { trimSlashFromLeftAndRight, validateResourceId } from "./helper";
|
||||
|
||||
/** @hidden */
|
||||
/**
|
||||
* @ignore
|
||||
* Given a database id, this creates a database link.
|
||||
* @param {string} databaseId -The database id
|
||||
* @returns {string} -A database link in the format of dbs/{0} \
|
||||
|
@ -26,6 +26,7 @@ export function createDatabaseUri(databaseId: string) {
|
|||
* @description Would be used when updating or deleting a DocumentCollection, creating a \
|
||||
* Document, a StoredProcedure, a Trigger, a UserDefinedFunction, or when executing a query \
|
||||
* with CreateDocumentQuery in Azure Cosmos DB database service.
|
||||
* @ignore
|
||||
*/
|
||||
export function createDocumentCollectionUri(databaseId: string, collectionId: string) {
|
||||
collectionId = trimSlashFromLeftAndRight(collectionId);
|
||||
|
@ -42,6 +43,7 @@ export function createDocumentCollectionUri(databaseId: string, collectionId: st
|
|||
* with {0} being a Uri escaped version of the databaseId and {1} being userId
|
||||
* @description Would be used when creating a Permission, or when replacing or deleting \
|
||||
* a User in Azure Cosmos DB database service
|
||||
* @ignore
|
||||
*/
|
||||
export function createUserUri(databaseId: string, userId: string) {
|
||||
userId = trimSlashFromLeftAndRight(userId);
|
||||
|
@ -60,6 +62,7 @@ export function createUserUri(databaseId: string, userId: string) {
|
|||
* the databaseId, {1} being collectionId and {2} being the documentId
|
||||
* @description Would be used when creating an Attachment, or when replacing \
|
||||
* or deleting a Document in Azure Cosmos DB database service
|
||||
* @ignore
|
||||
*/
|
||||
export function createDocumentUri(databaseId: string, collectionId: string, documentId: string) {
|
||||
documentId = trimSlashFromLeftAndRight(documentId);
|
||||
|
@ -78,6 +81,7 @@ export function createDocumentUri(databaseId: string, collectionId: string, docu
|
|||
* @returns {string} A permission link in the format of dbs/{0}/users/{1}/permissions/{2} \
|
||||
* with {0} being a Uri escaped version of the databaseId, {1} being userId and {2} being permissionId
|
||||
* @description Would be used when replacing or deleting a Permission in Azure Cosmos DB database service.
|
||||
* @ignore
|
||||
*/
|
||||
export function createPermissionUri(databaseId: string, userId: string, permissionId: string) {
|
||||
permissionId = trimSlashFromLeftAndRight(permissionId);
|
||||
|
@ -96,6 +100,7 @@ export function createPermissionUri(databaseId: string, userId: string, permissi
|
|||
* {1} being collectionId and {2} being the storedProcedureId
|
||||
* @description Would be used when replacing, executing, or deleting a StoredProcedure in \
|
||||
* Azure Cosmos DB database service.
|
||||
* @ignore
|
||||
*/
|
||||
export function createStoredProcedureUri(databaseId: string, collectionId: string, storedProcedureId: string) {
|
||||
storedProcedureId = trimSlashFromLeftAndRight(storedProcedureId);
|
||||
|
@ -119,6 +124,7 @@ export function createStoredProcedureUri(databaseId: string, collectionId: strin
|
|||
* dbs/{0}/colls/{1}/triggers/{2} with {0} being a Uri escaped version of the databaseId, \
|
||||
* {1} being collectionId and {2} being the triggerId
|
||||
* @description Would be used when replacing, executing, or deleting a Trigger in Azure Cosmos DB database service
|
||||
* @ignore
|
||||
*/
|
||||
export function createTriggerUri(databaseId: string, collectionId: string, triggerId: string) {
|
||||
triggerId = trimSlashFromLeftAndRight(triggerId);
|
||||
|
@ -138,6 +144,7 @@ export function createTriggerUri(databaseId: string, collectionId: string, trigg
|
|||
* with {0} being a Uri escaped version of the databaseId, {1} being collectionId and {2} being the udfId
|
||||
* @description Would be used when replacing, executing, or deleting a UserDefinedFunction in \
|
||||
* Azure Cosmos DB database service
|
||||
* @ignore
|
||||
*/
|
||||
export function createUserDefinedFunctionUri(databaseId: string, collectionId: string, udfId: string) {
|
||||
udfId = trimSlashFromLeftAndRight(udfId);
|
||||
|
@ -160,6 +167,7 @@ export function createUserDefinedFunctionUri(databaseId: string, collectionId: s
|
|||
* @returns {string} -A conflict link in the format of dbs/{0}/colls/{1}/conflicts/{2} \
|
||||
* with {0} being a Uri escaped version of the databaseId, {1} being collectionId and {2} being the conflictId
|
||||
* @description Would be used when creating a Conflict in Azure Cosmos DB database service.
|
||||
* @ignore
|
||||
*/
|
||||
export function createConflictUri(databaseId: string, collectionId: string, conflictId: string) {
|
||||
conflictId = trimSlashFromLeftAndRight(conflictId);
|
||||
|
@ -179,6 +187,7 @@ export function createConflictUri(databaseId: string, collectionId: string, conf
|
|||
* @returns {string} -A conflict link in the format of dbs/{0}/colls/{1}/conflicts/{2} \
|
||||
* with {0} being a Uri escaped version of the databaseId, {1} being collectionId and {2} being the conflictId
|
||||
* @description Would be used when creating a Conflict in Azure Cosmos DB database service.
|
||||
* @ignore
|
||||
*/
|
||||
export function createAttachmentUri(
|
||||
databaseId: string,
|
||||
|
@ -205,6 +214,7 @@ export function createAttachmentUri(
|
|||
* @param {string} collectionId -The collection Id
|
||||
* @returns {string} -A partition key ranges link in the format of \
|
||||
* dbs/{0}/colls/{1}/pkranges with {0} being a Uri escaped version of the databaseId and {1} being collectionId
|
||||
* @ignore
|
||||
*/
|
||||
export function createPartitionKeyRangesUri(databaseId: string, collectionId: string) {
|
||||
return createDocumentCollectionUri(databaseId, collectionId) + "/" + Constants.Path.PartitionKeyRangesPathSegment;
|
||||
|
|
|
@ -26,6 +26,9 @@ export interface ConnectionPolicy {
|
|||
useMultipleWriteLocations?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const defaultConnectionPolicy = Object.freeze({
|
||||
connectionMode: ConnectionMode.Gateway,
|
||||
requestTimeout: 60000,
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import { parsePath } from "./common";
|
||||
import { PartitionKey, PartitionKeyDefinition } from "./documents";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param document
|
||||
* @param partitionKeyDefinition
|
||||
*/
|
||||
export function extractPartitionKey(document: any, partitionKeyDefinition: PartitionKeyDefinition): PartitionKey[] {
|
||||
if (partitionKeyDefinition && partitionKeyDefinition.paths && partitionKeyDefinition.paths.length > 0) {
|
||||
const partitionKey: PartitionKey[] = [];
|
||||
|
@ -22,7 +27,10 @@ export function extractPartitionKey(document: any, partitionKeyDefinition: Parti
|
|||
return partitionKey;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param partitionKeyDefinition
|
||||
*/
|
||||
export function undefinedPartitionKey(partitionKeyDefinition: PartitionKeyDefinition) {
|
||||
if (partitionKeyDefinition.systemKey === true) {
|
||||
return [];
|
||||
|
|
|
@ -3,6 +3,8 @@ import { Response } from "../request/Response";
|
|||
|
||||
/**
|
||||
* Used to specify which type of events to execute this plug in on.
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
export enum PluginOn {
|
||||
/**
|
||||
|
@ -17,6 +19,8 @@ export enum PluginOn {
|
|||
|
||||
/**
|
||||
* Specifies which event to run for the specified plugin
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
export interface PluginConfig {
|
||||
/**
|
||||
|
@ -39,18 +43,22 @@ export interface PluginConfig {
|
|||
*
|
||||
* RequestContext is an object which controls what operation is happening, against which endpoint, and more. Modifying this and passing it along via next is how
|
||||
* you modify future SDK behavior.
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
export type Plugin<T> = (context: RequestContext, next: Next<T>) => Promise<Response<T>>;
|
||||
|
||||
/**
|
||||
* Next is a function which takes in requestContext returns a promise. You must await/then that promise which will contain the response from further plugins,
|
||||
* allowing you to log those results or handle errors.
|
||||
* @ignore
|
||||
*/
|
||||
export type Next<T> = (context: RequestContext) => Promise<Response<T>>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @hidden
|
||||
* @ignore
|
||||
* @param requestContext
|
||||
* @param next
|
||||
* @param on
|
||||
|
|
|
@ -26,6 +26,9 @@ export function getRequestChargeIfAny(headers: CosmosHeaders | number): number {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export function getInitialHeader(): CosmosHeaders {
|
||||
const headers: CosmosHeaders = {};
|
||||
headers[Constants.HttpHeaders.RequestCharge] = 0;
|
||||
|
@ -33,6 +36,11 @@ export function getInitialHeader(): CosmosHeaders {
|
|||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param headers
|
||||
* @param toBeMergedHeaders
|
||||
*/
|
||||
// TODO: The name of this method isn't very accurate to what it does
|
||||
export function mergeHeaders(headers: CosmosHeaders, toBeMergedHeaders: CosmosHeaders) {
|
||||
if (headers[Constants.HttpHeaders.RequestCharge] === undefined) {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import { TimeSpan } from "./timeSpan";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param delimitedString
|
||||
*/
|
||||
export function parseDelimitedString(delimitedString: string) {
|
||||
if (delimitedString == null) {
|
||||
throw new Error("delimitedString is null or undefined");
|
||||
|
@ -24,6 +28,11 @@ export function parseDelimitedString(delimitedString: string) {
|
|||
return metrics;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param metrics
|
||||
* @param key
|
||||
*/
|
||||
export function timeSpanFromMetrics(metrics: { [key: string]: any } /* TODO: any */, key: string) {
|
||||
if (key in metrics) {
|
||||
return TimeSpan.fromMilliseconds(metrics[key]);
|
||||
|
@ -32,6 +41,10 @@ export function timeSpanFromMetrics(metrics: { [key: string]: any } /* TODO: any
|
|||
return TimeSpan.zero;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param input
|
||||
*/
|
||||
export function isNumeric(input: any) {
|
||||
return !isNaN(parseFloat(input)) && isFinite(input);
|
||||
}
|
||||
|
|
|
@ -3,15 +3,24 @@ import { CosmosHeaders } from "../index";
|
|||
interface ErrorBody {
|
||||
code: string;
|
||||
message: string;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
additionalErrorInfo?: PartitionedQueryExecutionInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export interface PartitionedQueryExecutionInfo {
|
||||
partitionedQueryExecutionInfoVersion: number;
|
||||
queryInfo: QueryInfo;
|
||||
queryRanges: QueryRange[];
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
interface QueryRange {
|
||||
min: string;
|
||||
max: string;
|
||||
|
@ -19,6 +28,9 @@ interface QueryRange {
|
|||
isMaxInclusive: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
interface QueryInfo {
|
||||
top?: any;
|
||||
orderBy?: any[];
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export class LocationRouting {
|
||||
private pIgnorePreferredLocation: boolean;
|
||||
private pLocationIndexToRoute: number;
|
||||
|
|
|
@ -9,6 +9,9 @@ import { FeedOptions } from "./FeedOptions";
|
|||
import { LocationRouting } from "./LocationRouting";
|
||||
import { RequestOptions } from "./RequestOptions";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export interface RequestContext {
|
||||
path?: string;
|
||||
operationType?: OperationType;
|
||||
|
|
|
@ -16,6 +16,10 @@ export async function executeRequest(requestContext: RequestContext) {
|
|||
return executePlugins(requestContext, httpRequest, PluginOn.request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param requestContext
|
||||
*/
|
||||
async function httpRequest(requestContext: RequestContext) {
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
|
@ -107,6 +111,10 @@ async function httpRequest(requestContext: RequestContext) {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param requestContext
|
||||
*/
|
||||
export async function request<T>(requestContext: RequestContext): Promise<CosmosResponse<T>> {
|
||||
if (requestContext.body) {
|
||||
requestContext.body = bodyFromData(requestContext.body);
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import { CosmosHeaders } from "../index";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export interface Response<T> {
|
||||
headers: CosmosHeaders;
|
||||
result?: T;
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const StatusCode = {
|
||||
// Success
|
||||
Ok: 200 as 200,
|
||||
|
@ -29,8 +32,14 @@ export const StatusCode = {
|
|||
OperationCancelled: 1201
|
||||
};
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export type StatusCode = (typeof StatusCode)[keyof typeof StatusCode];
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const SubStatusCode = {
|
||||
Unknown: 0 as 0,
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const TimeoutErrorCode = "TimeoutError";
|
||||
|
||||
export class TimeoutError extends Error {
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
import { Agent } from "http";
|
||||
import { isNode } from "../common";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export let defaultHttpAgent: Agent;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export let defaultHttpsAgent: Agent;
|
||||
|
||||
if (isNode) {
|
||||
|
|
|
@ -26,6 +26,9 @@ export function bodyFromData(data: Buffer | string | object) {
|
|||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
interface GetHeadersOptions {
|
||||
clientOptions: CosmosClientOptions;
|
||||
defaultHeaders: CosmosHeaders;
|
||||
|
@ -39,6 +42,10 @@ interface GetHeadersOptions {
|
|||
partitionKey?: PartitionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param param0
|
||||
*/
|
||||
export async function getHeaders({
|
||||
clientOptions,
|
||||
defaultHeaders,
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { ErrorResponse } from "../request";
|
||||
import { RetryContext } from "./RetryContext";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export interface RetryPolicy {
|
||||
retryAfterInMilliseconds: number;
|
||||
shouldRetry: (
|
||||
|
|
|
@ -3,26 +3,80 @@ import { ErrorResponse } from "../request";
|
|||
import { TimeoutErrorCode } from "../request/TimeoutError";
|
||||
import { RetryPolicy } from "./RetryPolicy";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
// Windows Socket Error Codes
|
||||
const WindowsInterruptedFunctionCall = 10004;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsFileHandleNotValid = 10009;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsPermissionDenied = 10013;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsBadAddress = 10014;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsInvalidArgumnet = 10022;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsResourceTemporarilyUnavailable = 10035;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsOperationNowInProgress = 10036;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsAddressAlreadyInUse = 10048;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsConnectionResetByPeer = 10054;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsCannotSendAfterSocketShutdown = 10058;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsConnectionTimedOut = 10060;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsConnectionRefused = 10061;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsNameTooLong = 10063;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsHostIsDown = 10064;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const WindowsNoRouteTohost = 10065;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
// Linux Error Codes
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const LinuxConnectionReset = "ECONNRESET";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
const CONNECTION_ERROR_CODES = [
|
||||
WindowsInterruptedFunctionCall,
|
||||
WindowsFileHandleNotValid,
|
||||
|
@ -43,6 +97,9 @@ const CONNECTION_ERROR_CODES = [
|
|||
TimeoutErrorCode
|
||||
];
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
function needsRetry(operationType: OperationType, code: number | string) {
|
||||
if (
|
||||
(operationType === OperationType.Read || operationType === OperationType.Query) &&
|
||||
|
@ -58,6 +115,7 @@ function needsRetry(operationType: OperationType, code: number | string) {
|
|||
* This class implements the default connection retry policy for requests.
|
||||
* @property {int} currentRetryAttemptCount - Current retry attempt count.
|
||||
* @hidden
|
||||
* @ignore
|
||||
*/
|
||||
export class DefaultRetryPolicy implements RetryPolicy {
|
||||
private maxRetryAttemptCount: number = 10;
|
||||
|
|
|
@ -10,6 +10,9 @@ export interface RetryOptions {
|
|||
maxWaitTimeInSeconds: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const defaultRetryOptions = Object.freeze({
|
||||
maxRetryAttemptCount: 9,
|
||||
fixedRetryIntervalInMilliseconds: 0,
|
||||
|
|
|
@ -12,12 +12,18 @@ import { RetryContext } from "./RetryContext";
|
|||
import { RetryPolicy } from "./RetryPolicy";
|
||||
import { SessionRetryPolicy } from "./sessionRetryPolicy";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
interface ExecuteArgs {
|
||||
retryContext?: RetryContext;
|
||||
retryPolicies?: RetryPolicies;
|
||||
requestContext: RequestContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
interface RetryPolicies {
|
||||
endpointDiscoveryRetryPolicy: EndpointDiscoveryRetryPolicy;
|
||||
resourceThrottleRetryPolicy: ResourceThrottleRetryPolicy;
|
||||
|
@ -25,6 +31,11 @@ interface RetryPolicies {
|
|||
defaultRetryPolicy: DefaultRetryPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param param0
|
||||
* @ignore
|
||||
*/
|
||||
export async function execute({
|
||||
retryContext = {},
|
||||
retryPolicies,
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { Constants } from "../common/constants";
|
||||
import { InMemoryCollectionRoutingMap } from "./inMemoryCollectionRoutingMap";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
function compareRanges(a: any, b: any) {
|
||||
const aVal = a[0][Constants.PartitionKeyRange.MinInclusive];
|
||||
const bVal = b[0][Constants.PartitionKeyRange.MinInclusive];
|
||||
|
@ -37,6 +40,9 @@ export function createCompleteRoutingMap(partitionKeyRangeInfoTuppleList: any[])
|
|||
return new InMemoryCollectionRoutingMap(partitionKeyOrderedRange, orderedPartitionInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
function isCompleteSetOfRange(partitionKeyOrderedRange: any) {
|
||||
// TODO: any
|
||||
let isComplete = false;
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import { OperationType, ResourceType } from "../common";
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export interface SessionContext {
|
||||
resourceId?: string;
|
||||
resourceAddress?: string;
|
||||
|
|
|
@ -140,6 +140,11 @@ export class VectorSessionToken {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @param int1
|
||||
* @param int2
|
||||
*/
|
||||
function max(int1: string, int2: string) {
|
||||
// NOTE: This only works for positive numbers
|
||||
if (int1.length === int2.length) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче