mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-06-12 23:47:29 +01:00
add copy of cosmos node.js SDK as local dependency
This commit is contained in:
committed by
Chris Anderson
parent
ff1e733679
commit
ca396cdfbe
@@ -0,0 +1,11 @@
|
||||
import { SasTokenProperties } from "../client/SasToken/SasTokenProperties";
|
||||
/**
|
||||
* Experimental internal only
|
||||
* Generates the payload representing the permission configuration for the sas token.
|
||||
*/
|
||||
export declare function createAuthorizationSasToken(masterKey: string, sasTokenProperties: SasTokenProperties): Promise<string>;
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
export declare function utcsecondsSinceEpoch(date: Date): number;
|
||||
//# sourceMappingURL=SasToken.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"SasToken.d.ts","sourceRoot":"","sources":["../../../src/utils/SasToken.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAK3E;;;GAGG;AAEH,wBAAsB,2BAA2B,CAC/C,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,kBAAkB,GACrC,OAAO,CAAC,MAAM,CAAC,CAmIjB;AACD;;GAEG;AAEH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEvD"}
|
||||
@@ -0,0 +1,125 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { Constants, CosmosKeyType, SasTokenPermissionKind } from "../common";
|
||||
import { encodeUTF8 } from "./encode";
|
||||
import { hmac } from "./hmac";
|
||||
/**
|
||||
* Experimental internal only
|
||||
* Generates the payload representing the permission configuration for the sas token.
|
||||
*/
|
||||
export async function createAuthorizationSasToken(masterKey, sasTokenProperties) {
|
||||
let resourcePrefixPath = "";
|
||||
if (typeof sasTokenProperties.databaseName === "string" &&
|
||||
sasTokenProperties.databaseName !== "") {
|
||||
resourcePrefixPath += `/${Constants.Path.DatabasesPathSegment}/${sasTokenProperties.databaseName}`;
|
||||
}
|
||||
if (typeof sasTokenProperties.containerName === "string" &&
|
||||
sasTokenProperties.containerName !== "") {
|
||||
if (sasTokenProperties.databaseName === "") {
|
||||
throw new Error(`illegalArgumentException : ${sasTokenProperties.databaseName} \
|
||||
is an invalid database name`);
|
||||
}
|
||||
resourcePrefixPath += `/${Constants.Path.CollectionsPathSegment}/${sasTokenProperties.containerName}`;
|
||||
}
|
||||
if (typeof sasTokenProperties.resourceName === "string" &&
|
||||
sasTokenProperties.resourceName !== "") {
|
||||
if (sasTokenProperties.containerName === "") {
|
||||
throw new Error(`illegalArgumentException : ${sasTokenProperties.containerName} \
|
||||
is an invalid container name`);
|
||||
}
|
||||
switch (sasTokenProperties.resourceKind) {
|
||||
case "ITEM":
|
||||
resourcePrefixPath += `${Constants.Path.Root}${Constants.Path.DocumentsPathSegment}`;
|
||||
break;
|
||||
case "STORED_PROCEDURE":
|
||||
resourcePrefixPath += `${Constants.Path.Root}${Constants.Path.StoredProceduresPathSegment}`;
|
||||
break;
|
||||
case "USER_DEFINED_FUNCTION":
|
||||
resourcePrefixPath += `${Constants.Path.Root}${Constants.Path.UserDefinedFunctionsPathSegment}`;
|
||||
break;
|
||||
case "TRIGGER":
|
||||
resourcePrefixPath += `${Constants.Path.Root}${Constants.Path.TriggersPathSegment}`;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`illegalArgumentException : ${sasTokenProperties.resourceKind} \
|
||||
is an invalid resource kind`);
|
||||
break;
|
||||
}
|
||||
resourcePrefixPath += `${Constants.Path.Root}${sasTokenProperties.resourceName}${Constants.Path.Root}`;
|
||||
}
|
||||
sasTokenProperties.resourcePath = resourcePrefixPath.toString();
|
||||
let partitionRanges = "";
|
||||
if (sasTokenProperties.partitionKeyValueRanges !== undefined &&
|
||||
sasTokenProperties.partitionKeyValueRanges.length > 0) {
|
||||
if (typeof sasTokenProperties.resourceKind !== "string" &&
|
||||
sasTokenProperties.resourceKind !== "ITEM") {
|
||||
throw new Error(`illegalArgumentException : ${sasTokenProperties.resourceKind} \
|
||||
is an invalid partition key value range`);
|
||||
}
|
||||
sasTokenProperties.partitionKeyValueRanges.forEach((range) => {
|
||||
partitionRanges += `${encodeUTF8(range)},`;
|
||||
});
|
||||
}
|
||||
if (sasTokenProperties.controlPlaneReaderScope === 0) {
|
||||
sasTokenProperties.controlPlaneReaderScope += SasTokenPermissionKind.ContainerReadAny;
|
||||
sasTokenProperties.controlPlaneWriterScope += SasTokenPermissionKind.ContainerReadAny;
|
||||
}
|
||||
if (sasTokenProperties.dataPlaneReaderScope === 0 &&
|
||||
sasTokenProperties.dataPlaneWriterScope === 0) {
|
||||
sasTokenProperties.dataPlaneReaderScope = SasTokenPermissionKind.ContainerFullAccess;
|
||||
sasTokenProperties.dataPlaneWriterScope = SasTokenPermissionKind.ContainerFullAccess;
|
||||
}
|
||||
if (typeof sasTokenProperties.keyType !== "number" ||
|
||||
typeof sasTokenProperties.keyType === undefined) {
|
||||
switch (sasTokenProperties.keyType) {
|
||||
case CosmosKeyType.PrimaryMaster:
|
||||
sasTokenProperties.keyType = 1;
|
||||
break;
|
||||
case CosmosKeyType.SecondaryMaster:
|
||||
sasTokenProperties.keyType = 2;
|
||||
break;
|
||||
case CosmosKeyType.PrimaryReadOnly:
|
||||
sasTokenProperties.keyType = 3;
|
||||
break;
|
||||
case CosmosKeyType.SecondaryReadOnly:
|
||||
sasTokenProperties.keyType = 4;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`illegalArgumentException : ${sasTokenProperties.keyType} \
|
||||
is an invalid key type`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
const payload = sasTokenProperties.user +
|
||||
"\n" +
|
||||
sasTokenProperties.userTag +
|
||||
"\n" +
|
||||
sasTokenProperties.resourcePath +
|
||||
"\n" +
|
||||
partitionRanges +
|
||||
"\n" +
|
||||
utcsecondsSinceEpoch(sasTokenProperties.startTime).toString(16) +
|
||||
"\n" +
|
||||
utcsecondsSinceEpoch(sasTokenProperties.expiryTime).toString(16) +
|
||||
"\n" +
|
||||
sasTokenProperties.keyType +
|
||||
"\n" +
|
||||
sasTokenProperties.controlPlaneReaderScope.toString(16) +
|
||||
"\n" +
|
||||
sasTokenProperties.controlPlaneWriterScope.toString(16) +
|
||||
"\n" +
|
||||
sasTokenProperties.dataPlaneReaderScope.toString(16) +
|
||||
"\n" +
|
||||
sasTokenProperties.dataPlaneWriterScope.toString(16) +
|
||||
"\n";
|
||||
const signedPayload = await hmac(masterKey, Buffer.from(payload).toString("base64"));
|
||||
return "type=sas&ver=1.0&sig=" + signedPayload + ";" + Buffer.from(payload).toString("base64");
|
||||
}
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
// TODO: utcMilllisecondsSinceEpoch
|
||||
export function utcsecondsSinceEpoch(date) {
|
||||
return Math.round(date.getTime() / 1000);
|
||||
}
|
||||
//# sourceMappingURL=SasToken.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
declare let safeatob: any;
|
||||
export default safeatob;
|
||||
//# sourceMappingURL=atob.browser.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"atob.browser.d.ts","sourceRoot":"","sources":["../../../src/utils/atob.browser.ts"],"names":[],"mappings":"AAGA,QAAA,IAAI,QAAQ,EAAE,GAAG,CAAC;AA8ClB,eAAe,QAAQ,CAAC"}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
let safeatob;
|
||||
// base64 character set, plus padding character (=)
|
||||
const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
// Regular expression to check formal correctness of base64 encoded strings
|
||||
const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;
|
||||
if ("function" !== typeof atob) {
|
||||
// atob implementation for React Native
|
||||
safeatob = (str) => {
|
||||
// atob can work with strings with whitespaces, even inside the encoded part,
|
||||
// but only \t, \n, \f, \r and ' ', which can be stripped.
|
||||
str = String(str).replace(/[\t\n\f\r ]+/g, "");
|
||||
if (!b64re.test(str)) {
|
||||
throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
||||
}
|
||||
// Adding the padding if missing, for simplicity
|
||||
str += "==".slice(2 - (str.length & 3));
|
||||
let bitmap;
|
||||
let result = "";
|
||||
let r1;
|
||||
let r2;
|
||||
let i = 0;
|
||||
for (; i < str.length;) {
|
||||
bitmap =
|
||||
(b64.indexOf(str.charAt(i++)) << 18) |
|
||||
(b64.indexOf(str.charAt(i++)) << 12) |
|
||||
((r1 = b64.indexOf(str.charAt(i++))) << 6) |
|
||||
(r2 = b64.indexOf(str.charAt(i++)));
|
||||
result +=
|
||||
r1 === 64
|
||||
? String.fromCharCode((bitmap >> 16) & 255)
|
||||
: r2 === 64
|
||||
? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
|
||||
: String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
else {
|
||||
safeatob = atob;
|
||||
}
|
||||
export default safeatob;
|
||||
//# sourceMappingURL=atob.browser.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"atob.browser.js","sourceRoot":"","sources":["../../../src/utils/atob.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,IAAI,QAAa,CAAC;AAElB,mDAAmD;AACnD,MAAM,GAAG,GAAG,mEAAmE,CAAC;AAChF,2EAA2E;AAC3E,MAAM,KAAK,GAAG,sEAAsE,CAAC;AAErF,IAAI,UAAU,KAAK,OAAO,IAAI,EAAE;IAC9B,uCAAuC;IACvC,QAAQ,GAAG,CAAC,GAAW,EAAU,EAAE;QACjC,6EAA6E;QAC7E,0DAA0D;QAC1D,GAAG,GAAG,MAAM,CAAC,GAAG,CAA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G,CAAC;wBAChE,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,CAAC;SACtF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;CACH;KAAM;IACL,QAAQ,GAAG,IAAI,CAAC;CACjB;AAED,eAAe,QAAQ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nlet safeatob: any;\n\n// base64 character set, plus padding character (=)\nconst b64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\";\n// Regular expression to check formal correctness of base64 encoded strings\nconst b64re = /^(?:[A-Za-z\\d+/]{4})*?(?:[A-Za-z\\d+/]{2}(?:==)?|[A-Za-z\\d+/]{3}=?)?$/;\n\nif (\"function\" !== typeof atob) {\n // atob implementation for React Native\n safeatob = (str: string): string => {\n // atob can work with strings with whitespaces, even inside the encoded part,\n // but only \\t, \\n, \\f, \\r and ' ', which can be stripped.\n str = String(str).replace(/[\\t\\n\\f\\r ]+/g, \"\");\n if (!b64re.test(str)) {\n throw new TypeError(\n \"Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.\",\n );\n }\n\n // Adding the padding if missing, for simplicity\n str += \"==\".slice(2 - (str.length & 3));\n let bitmap;\n let result = \"\";\n let r1;\n let r2;\n let i = 0;\n for (; i < str.length; ) {\n bitmap =\n (b64.indexOf(str.charAt(i++)) << 18) |\n (b64.indexOf(str.charAt(i++)) << 12) |\n ((r1 = b64.indexOf(str.charAt(i++))) << 6) |\n (r2 = b64.indexOf(str.charAt(i++)));\n\n result +=\n r1 === 64\n ? String.fromCharCode((bitmap >> 16) & 255)\n : r2 === 64\n ? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)\n : String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);\n }\n return result;\n };\n} else {\n safeatob = atob;\n}\n\nexport default safeatob;\n"]}
|
||||
@@ -0,0 +1,2 @@
|
||||
export default function atob(str: string): string;
|
||||
//# sourceMappingURL=atob.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"atob.d.ts","sourceRoot":"","sources":["../../../src/utils/atob.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
export default function atob(str) {
|
||||
return Buffer.from(str, "base64").toString("binary");
|
||||
}
|
||||
//# sourceMappingURL=atob.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"atob.js","sourceRoot":"","sources":["../../../src/utils/atob.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,GAAW;IACtC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACvD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport default function atob(str: string): string {\n return Buffer.from(str, \"base64\").toString(\"binary\");\n}\n"]}
|
||||
@@ -0,0 +1,145 @@
|
||||
import { JSONObject } from "../queryExecutionContext";
|
||||
import { CosmosDiagnostics, RequestOptions } from "..";
|
||||
import { PartitionKey, PartitionKeyDefinition, PrimitivePartitionKeyValue } from "../documents";
|
||||
import { PatchRequestBody } from "./patch";
|
||||
export type Operation = CreateOperation | UpsertOperation | ReadOperation | DeleteOperation | ReplaceOperation | BulkPatchOperation;
|
||||
export interface Batch {
|
||||
min: string;
|
||||
max: string;
|
||||
rangeId: string;
|
||||
indexes: number[];
|
||||
operations: Operation[];
|
||||
}
|
||||
export type BulkOperationResponse = OperationResponse[] & {
|
||||
diagnostics: CosmosDiagnostics;
|
||||
};
|
||||
export interface OperationResponse {
|
||||
statusCode: number;
|
||||
requestCharge: number;
|
||||
eTag?: string;
|
||||
resourceBody?: JSONObject;
|
||||
}
|
||||
/**
|
||||
* Options object used to modify bulk execution.
|
||||
* continueOnError (Default value: false) - Continues bulk execution when an operation fails ** NOTE THIS WILL DEFAULT TO TRUE IN the 4.0 RELEASE
|
||||
*/
|
||||
export interface BulkOptions {
|
||||
continueOnError?: boolean;
|
||||
}
|
||||
export declare function isKeyInRange(min: string, max: string, key: string): boolean;
|
||||
export interface OperationBase {
|
||||
partitionKey?: string;
|
||||
ifMatch?: string;
|
||||
ifNoneMatch?: string;
|
||||
}
|
||||
export declare const BulkOperationType: {
|
||||
readonly Create: "Create";
|
||||
readonly Upsert: "Upsert";
|
||||
readonly Read: "Read";
|
||||
readonly Delete: "Delete";
|
||||
readonly Replace: "Replace";
|
||||
readonly Patch: "Patch";
|
||||
};
|
||||
export type OperationInput = CreateOperationInput | UpsertOperationInput | ReadOperationInput | DeleteOperationInput | ReplaceOperationInput | PatchOperationInput;
|
||||
export interface CreateOperationInput {
|
||||
partitionKey?: PartitionKey;
|
||||
ifMatch?: string;
|
||||
ifNoneMatch?: string;
|
||||
operationType: typeof BulkOperationType.Create;
|
||||
resourceBody: JSONObject;
|
||||
}
|
||||
export interface UpsertOperationInput {
|
||||
partitionKey?: PartitionKey;
|
||||
ifMatch?: string;
|
||||
ifNoneMatch?: string;
|
||||
operationType: typeof BulkOperationType.Upsert;
|
||||
resourceBody: JSONObject;
|
||||
}
|
||||
export interface ReadOperationInput {
|
||||
partitionKey?: PartitionKey;
|
||||
operationType: typeof BulkOperationType.Read;
|
||||
id: string;
|
||||
}
|
||||
export interface DeleteOperationInput {
|
||||
partitionKey?: PartitionKey;
|
||||
operationType: typeof BulkOperationType.Delete;
|
||||
id: string;
|
||||
}
|
||||
export interface ReplaceOperationInput {
|
||||
partitionKey?: PartitionKey;
|
||||
ifMatch?: string;
|
||||
ifNoneMatch?: string;
|
||||
operationType: typeof BulkOperationType.Replace;
|
||||
resourceBody: JSONObject;
|
||||
id: string;
|
||||
}
|
||||
export interface PatchOperationInput {
|
||||
partitionKey?: PartitionKey;
|
||||
ifMatch?: string;
|
||||
ifNoneMatch?: string;
|
||||
operationType: typeof BulkOperationType.Patch;
|
||||
resourceBody: PatchRequestBody;
|
||||
id: string;
|
||||
}
|
||||
export type OperationWithItem = OperationBase & {
|
||||
resourceBody: JSONObject;
|
||||
};
|
||||
export type CreateOperation = OperationWithItem & {
|
||||
operationType: typeof BulkOperationType.Create;
|
||||
};
|
||||
export type UpsertOperation = OperationWithItem & {
|
||||
operationType: typeof BulkOperationType.Upsert;
|
||||
};
|
||||
export type ReadOperation = OperationBase & {
|
||||
operationType: typeof BulkOperationType.Read;
|
||||
id: string;
|
||||
};
|
||||
export type DeleteOperation = OperationBase & {
|
||||
operationType: typeof BulkOperationType.Delete;
|
||||
id: string;
|
||||
};
|
||||
export type ReplaceOperation = OperationWithItem & {
|
||||
operationType: typeof BulkOperationType.Replace;
|
||||
id: string;
|
||||
};
|
||||
export type BulkPatchOperation = OperationBase & {
|
||||
operationType: typeof BulkOperationType.Patch;
|
||||
id: string;
|
||||
};
|
||||
export declare function hasResource(operation: Operation): operation is CreateOperation | UpsertOperation | ReplaceOperation;
|
||||
/**
|
||||
* Maps OperationInput to Operation by
|
||||
* - generating Ids if needed.
|
||||
* - choosing partitionKey which can be used to choose which batch this
|
||||
* operation should be part of. The order is -
|
||||
* 1. If the operationInput itself has partitionKey field set it is used.
|
||||
* 2. Other wise for create/replace/upsert it is extracted from resource body.
|
||||
* 3. For read/delete/patch type operations undefined partitionKey is used.
|
||||
* - Here one nuance is that, the partitionKey field inside Operation needs to
|
||||
* be serialized as a JSON string.
|
||||
* @param operationInput - OperationInput
|
||||
* @param definition - PartitionKeyDefinition
|
||||
* @param options - RequestOptions
|
||||
* @returns
|
||||
*/
|
||||
export declare function prepareOperations(operationInput: OperationInput, definition: PartitionKeyDefinition, options?: RequestOptions): {
|
||||
operation: Operation;
|
||||
partitionKey: PrimitivePartitionKeyValue[];
|
||||
};
|
||||
/**
|
||||
* Splits a batch into array of batches based on cumulative size of its operations by making sure
|
||||
* cumulative size of an individual batch is not larger than {@link Constants.DefaultMaxBulkRequestBodySizeInBytes}.
|
||||
* If a single operation itself is larger than {@link Constants.DefaultMaxBulkRequestBodySizeInBytes}, that
|
||||
* operation would be moved into a batch containing only that operation.
|
||||
* @param originalBatch - A batch of operations needed to be checked.
|
||||
* @returns
|
||||
* @hidden
|
||||
*/
|
||||
export declare function splitBatchBasedOnBodySize(originalBatch: Batch): Batch[];
|
||||
/**
|
||||
* Calculates size of an JSON object in bytes with utf-8 encoding.
|
||||
* @hidden
|
||||
*/
|
||||
export declare function calculateObjectSizeInBytes(obj: unknown): number;
|
||||
export declare function decorateBatchOperation(operation: OperationInput, options?: RequestOptions): Operation;
|
||||
//# sourceMappingURL=batch.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../../src/utils/batch.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACvD,OAAO,EAEL,YAAY,EACZ,sBAAsB,EACtB,0BAA0B,EAE3B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAO3C,MAAM,MAAM,SAAS,GACjB,eAAe,GACf,eAAe,GACf,aAAa,GACb,eAAe,GACf,gBAAgB,GAChB,kBAAkB,CAAC;AAEvB,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EA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C,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG;IAC5C,aAAa,EAAE,OAAO,iBAAiB,CAAC,MAAM,CAAC;IAC/C,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAAG;IACjD,aAAa,EAAE,OAAO,iBAAiB,CAAC,OAAO,CAAC;IAChD,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC/C,aAAa,EAAE,OAAO,iBAAiB,CAAC,KAAK,CAAC;IAC9C,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,wBAAgB,WAAW,CACzB,SAAS,EAAE,SAAS,GACnB,SAAS,IAAI,eAAe,GAAG,eAAe,GAAG,gBAAgB,CAKnE;AACD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,sBAAsB,EAClC,OAAO,GAAE,cAAmB,GAC3B;IACD,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,0BAA0B,EAAE,CAAC;CAC5C,CA8BA;AAqBD;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,aAAa,EAAE,KAAK,GAAG,KAAK,EAAE,CA4BvE;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAE/D;AAED,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,cAAc,EACzB,OAAO,GAAE,cAAmB,GAC3B,SAAS,CAaX"}
|
||||
@@ -0,0 +1,132 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { extractPartitionKeys } from "../extractPartitionKey";
|
||||
import { NonePartitionKeyLiteral, convertToInternalPartitionKey, } from "../documents";
|
||||
import { v4 } from "uuid";
|
||||
import { assertNotUndefined } from "./typeChecks";
|
||||
import { bodyFromData } from "../request/request";
|
||||
import { Constants } from "../common/constants";
|
||||
const uuid = v4;
|
||||
export function isKeyInRange(min, max, key) {
|
||||
const isAfterMinInclusive = key.localeCompare(min) >= 0;
|
||||
const isBeforeMax = key.localeCompare(max) < 0;
|
||||
return isAfterMinInclusive && isBeforeMax;
|
||||
}
|
||||
export const BulkOperationType = {
|
||||
Create: "Create",
|
||||
Upsert: "Upsert",
|
||||
Read: "Read",
|
||||
Delete: "Delete",
|
||||
Replace: "Replace",
|
||||
Patch: "Patch",
|
||||
};
|
||||
export function hasResource(operation) {
|
||||
return (operation.operationType !== "Patch" &&
|
||||
operation.resourceBody !== undefined);
|
||||
}
|
||||
/**
|
||||
* Maps OperationInput to Operation by
|
||||
* - generating Ids if needed.
|
||||
* - choosing partitionKey which can be used to choose which batch this
|
||||
* operation should be part of. The order is -
|
||||
* 1. If the operationInput itself has partitionKey field set it is used.
|
||||
* 2. Other wise for create/replace/upsert it is extracted from resource body.
|
||||
* 3. For read/delete/patch type operations undefined partitionKey is used.
|
||||
* - Here one nuance is that, the partitionKey field inside Operation needs to
|
||||
* be serialized as a JSON string.
|
||||
* @param operationInput - OperationInput
|
||||
* @param definition - PartitionKeyDefinition
|
||||
* @param options - RequestOptions
|
||||
* @returns
|
||||
*/
|
||||
export function prepareOperations(operationInput, definition, options = {}) {
|
||||
populateIdsIfNeeded(operationInput, options);
|
||||
let partitionKey;
|
||||
if (Object.prototype.hasOwnProperty.call(operationInput, "partitionKey")) {
|
||||
if (operationInput.partitionKey === undefined) {
|
||||
partitionKey = definition.paths.map(() => NonePartitionKeyLiteral);
|
||||
}
|
||||
else {
|
||||
partitionKey = convertToInternalPartitionKey(operationInput.partitionKey);
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (operationInput.operationType) {
|
||||
case BulkOperationType.Create:
|
||||
case BulkOperationType.Replace:
|
||||
case BulkOperationType.Upsert:
|
||||
partitionKey = assertNotUndefined(extractPartitionKeys(operationInput.resourceBody, definition), "Unexpected undefined Partition Key Found.");
|
||||
break;
|
||||
case BulkOperationType.Read:
|
||||
case BulkOperationType.Delete:
|
||||
case BulkOperationType.Patch:
|
||||
partitionKey = definition.paths.map(() => NonePartitionKeyLiteral);
|
||||
}
|
||||
}
|
||||
return {
|
||||
operation: Object.assign(Object.assign({}, operationInput), { partitionKey: JSON.stringify(partitionKey) }),
|
||||
partitionKey,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* For operations requiring Id genrate random uuids.
|
||||
* @param operationInput - OperationInput to be checked.
|
||||
* @param options - RequestOptions
|
||||
*/
|
||||
function populateIdsIfNeeded(operationInput, options) {
|
||||
if (operationInput.operationType === BulkOperationType.Create ||
|
||||
operationInput.operationType === BulkOperationType.Upsert) {
|
||||
if ((operationInput.resourceBody.id === undefined || operationInput.resourceBody.id === "") &&
|
||||
!options.disableAutomaticIdGeneration) {
|
||||
operationInput.resourceBody.id = uuid();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Splits a batch into array of batches based on cumulative size of its operations by making sure
|
||||
* cumulative size of an individual batch is not larger than {@link Constants.DefaultMaxBulkRequestBodySizeInBytes}.
|
||||
* If a single operation itself is larger than {@link Constants.DefaultMaxBulkRequestBodySizeInBytes}, that
|
||||
* operation would be moved into a batch containing only that operation.
|
||||
* @param originalBatch - A batch of operations needed to be checked.
|
||||
* @returns
|
||||
* @hidden
|
||||
*/
|
||||
export function splitBatchBasedOnBodySize(originalBatch) {
|
||||
if ((originalBatch === null || originalBatch === void 0 ? void 0 : originalBatch.operations) === undefined || originalBatch.operations.length < 1)
|
||||
return [];
|
||||
let currentBatchSize = calculateObjectSizeInBytes(originalBatch.operations[0]);
|
||||
let currentBatch = Object.assign(Object.assign({}, originalBatch), { operations: [originalBatch.operations[0]], indexes: [originalBatch.indexes[0]] });
|
||||
const processedBatches = [];
|
||||
processedBatches.push(currentBatch);
|
||||
for (let index = 1; index < originalBatch.operations.length; index++) {
|
||||
const operation = originalBatch.operations[index];
|
||||
const currentOpSize = calculateObjectSizeInBytes(operation);
|
||||
if (currentBatchSize + currentOpSize > Constants.DefaultMaxBulkRequestBodySizeInBytes) {
|
||||
currentBatch = Object.assign(Object.assign({}, originalBatch), { operations: [], indexes: [] });
|
||||
processedBatches.push(currentBatch);
|
||||
currentBatchSize = 0;
|
||||
}
|
||||
currentBatch.operations.push(operation);
|
||||
currentBatch.indexes.push(originalBatch.indexes[index]);
|
||||
currentBatchSize += currentOpSize;
|
||||
}
|
||||
return processedBatches;
|
||||
}
|
||||
/**
|
||||
* Calculates size of an JSON object in bytes with utf-8 encoding.
|
||||
* @hidden
|
||||
*/
|
||||
export function calculateObjectSizeInBytes(obj) {
|
||||
return new TextEncoder().encode(bodyFromData(obj)).length;
|
||||
}
|
||||
export function decorateBatchOperation(operation, options = {}) {
|
||||
if (operation.operationType === BulkOperationType.Create ||
|
||||
operation.operationType === BulkOperationType.Upsert) {
|
||||
if ((operation.resourceBody.id === undefined || operation.resourceBody.id === "") &&
|
||||
!options.disableAutomaticIdGeneration) {
|
||||
operation.resourceBody.id = uuid();
|
||||
}
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
//# sourceMappingURL=batch.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
import { HttpClient } from "@azure/core-rest-pipeline";
|
||||
export declare function getCachedDefaultHttpClient(): HttpClient;
|
||||
//# sourceMappingURL=cachedClient.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"cachedClient.d.ts","sourceRoot":"","sources":["../../../src/utils/cachedClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAA2B,MAAM,2BAA2B,CAAC;AAIhF,wBAAgB,0BAA0B,IAAI,UAAU,CAMvD"}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { createDefaultHttpClient } from "@azure/core-rest-pipeline";
|
||||
let cachedHttpClient;
|
||||
export function getCachedDefaultHttpClient() {
|
||||
if (!cachedHttpClient) {
|
||||
cachedHttpClient = createDefaultHttpClient();
|
||||
}
|
||||
return cachedHttpClient;
|
||||
}
|
||||
//# sourceMappingURL=cachedClient.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"cachedClient.js","sourceRoot":"","sources":["../../../src/utils/cachedClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAc,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEhF,IAAI,gBAAwC,CAAC;AAE7C,MAAM,UAAU,0BAA0B;IACxC,IAAI,CAAC,gBAAgB,EAAE;QACrB,gBAAgB,GAAG,uBAAuB,EAAE,CAAC;KAC9C;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { HttpClient, createDefaultHttpClient } from \"@azure/core-rest-pipeline\";\n\nlet cachedHttpClient: HttpClient | undefined;\n\nexport function getCachedDefaultHttpClient(): HttpClient {\n if (!cachedHttpClient) {\n cachedHttpClient = createDefaultHttpClient();\n }\n\n return cachedHttpClient;\n}\n"]}
|
||||
@@ -0,0 +1,3 @@
|
||||
export declare function checkURL(testString: string): URL;
|
||||
export declare function sanitizeEndpoint(url: string): string;
|
||||
//# sourceMappingURL=checkURL.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"checkURL.d.ts","sourceRoot":"","sources":["../../../src/utils/checkURL.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAEhD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
export function checkURL(testString) {
|
||||
return new URL(testString);
|
||||
}
|
||||
export function sanitizeEndpoint(url) {
|
||||
return new URL(url).href.replace(/\/$/, "");
|
||||
}
|
||||
//# sourceMappingURL=checkURL.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"checkURL.js","sourceRoot":"","sources":["../../../src/utils/checkURL.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,UAAU,QAAQ,CAAC,UAAkB;IACzC,OAAO,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport function checkURL(testString: string): URL {\n return new URL(testString);\n}\n\nexport function sanitizeEndpoint(url: string): string {\n return new URL(url).href.replace(/\\/$/, \"\");\n}\n"]}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { CosmosDiagnostics, MetadataLookUpType } from "../CosmosDiagnostics";
|
||||
import { DiagnosticDataValue, DiagnosticNodeInternal, DiagnosticNodeType } from "../diagnostics/DiagnosticNodeInternal";
|
||||
import { ClientContext } from "../ClientContext";
|
||||
/**
|
||||
* @hidden
|
||||
* Utility function to create an Empty CosmosDiagnostic object.
|
||||
*/
|
||||
export declare function getEmptyCosmosDiagnostics(): CosmosDiagnostics;
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
export type ExtractPromise<T> = T extends Promise<infer U> ? U : never;
|
||||
/**
|
||||
* A supporting utility wrapper function, to be used inside a diagnostic session started
|
||||
* by `withDiagnostics` function.
|
||||
* Created a Diagnostic node and add it as a child to existing diagnostic session.
|
||||
* @hidden
|
||||
*/
|
||||
export declare function addDignosticChild<Callback extends (node: DiagnosticNodeInternal) => Promise<any>>(callback: Callback, node: DiagnosticNodeInternal, type: DiagnosticNodeType, data?: Partial<DiagnosticDataValue>): Promise<ExtractPromise<ReturnType<Callback>>>;
|
||||
/**
|
||||
* A supporting utility wrapper function, to be used inside a diagnostic session started
|
||||
* by `withDiagnostics` function.
|
||||
* Treats requests originating in provided `callback` as metadata calls.
|
||||
* To realize this, starts a temporary diagnostic session, after execution of callback is
|
||||
* finished. Merges this temporary diagnostic session to the original diagnostic session
|
||||
* represented by the input parameter `node`.
|
||||
* @hidden
|
||||
*/
|
||||
export declare function withMetadataDiagnostics<Callback extends (node: DiagnosticNodeInternal) => Promise<any>>(callback: Callback, node: DiagnosticNodeInternal, type: MetadataLookUpType): Promise<ExtractPromise<ReturnType<Callback>>>;
|
||||
/**
|
||||
* Utility wrapper function to managed lifecycle of a Diagnostic session.
|
||||
* Meant to be used at the root of the client operation. i.e. item.read(),
|
||||
* queryIterator.fetchAll().
|
||||
*
|
||||
* This utility starts a new diagnostic session. So using it any where else
|
||||
* other than start of operation, will result is different diagnostic sessions.
|
||||
*
|
||||
* Workings :
|
||||
* 1. Takes a callback function as input.
|
||||
* 2. Creates a new instance of DiagnosticNodeInternal, which can be though as starting
|
||||
* a new diagnostic session.
|
||||
* 3. Executes the callback function.
|
||||
* 4. If execution was successful. Converts DiagnosticNodeInternal to CosmosDiagnostics
|
||||
* and injects it to the response object and returns this object.
|
||||
* 5. If execution threw an exception. Sill converts DiagnosticNodeInternal to CosmosDiagnostics
|
||||
* and injects it to the Error object, and rethrows the Error object.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
export declare function withDiagnostics<Callback extends (node: DiagnosticNodeInternal) => Promise<any>>(callback: Callback, clientContext: ClientContext, type?: DiagnosticNodeType): Promise<ExtractPromise<ReturnType<Callback>>>;
|
||||
//# sourceMappingURL=diagnostics.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../../src/utils/diagnostics.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE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|
||||
@@ -0,0 +1,120 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { CosmosDiagnostics } from "../CosmosDiagnostics";
|
||||
import { DiagnosticNodeInternal, DiagnosticNodeType, } from "../diagnostics/DiagnosticNodeInternal";
|
||||
import { getCurrentTimestampInMs } from "./time";
|
||||
import { v4 } from "uuid";
|
||||
import { CosmosDbDiagnosticLevel } from "../diagnostics/CosmosDbDiagnosticLevel";
|
||||
/**
|
||||
* @hidden
|
||||
* Utility function to create an Empty CosmosDiagnostic object.
|
||||
*/
|
||||
export function getEmptyCosmosDiagnostics() {
|
||||
return new CosmosDiagnostics({
|
||||
requestDurationInMs: 0,
|
||||
requestStartTimeUTCInMs: getCurrentTimestampInMs(),
|
||||
totalRequestPayloadLengthInBytes: 0,
|
||||
totalResponsePayloadLengthInBytes: 0,
|
||||
locationEndpointsContacted: [],
|
||||
retryDiagnostics: {
|
||||
failedAttempts: [],
|
||||
},
|
||||
metadataDiagnostics: {
|
||||
metadataLookups: [],
|
||||
},
|
||||
gatewayStatistics: [],
|
||||
}, {
|
||||
id: v4(),
|
||||
nodeType: DiagnosticNodeType.CLIENT_REQUEST_NODE,
|
||||
children: [],
|
||||
data: {},
|
||||
startTimeUTCInMs: getCurrentTimestampInMs(),
|
||||
durationInMs: 0,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* A supporting utility wrapper function, to be used inside a diagnostic session started
|
||||
* by `withDiagnostics` function.
|
||||
* Created a Diagnostic node and add it as a child to existing diagnostic session.
|
||||
* @hidden
|
||||
*/
|
||||
export async function addDignosticChild(callback, node, type, data = {}) {
|
||||
const childNode = node.initializeChildNode(type, CosmosDbDiagnosticLevel.debug, data);
|
||||
try {
|
||||
const response = await callback(childNode);
|
||||
childNode.updateTimestamp();
|
||||
return response;
|
||||
}
|
||||
catch (e) {
|
||||
childNode.addData({
|
||||
failure: true,
|
||||
});
|
||||
childNode.updateTimestamp();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A supporting utility wrapper function, to be used inside a diagnostic session started
|
||||
* by `withDiagnostics` function.
|
||||
* Treats requests originating in provided `callback` as metadata calls.
|
||||
* To realize this, starts a temporary diagnostic session, after execution of callback is
|
||||
* finished. Merges this temporary diagnostic session to the original diagnostic session
|
||||
* represented by the input parameter `node`.
|
||||
* @hidden
|
||||
*/
|
||||
export async function withMetadataDiagnostics(callback, node, type) {
|
||||
const diagnosticNodeForMetadataCall = new DiagnosticNodeInternal(node.diagnosticLevel, DiagnosticNodeType.METADATA_REQUEST_NODE, null);
|
||||
try {
|
||||
const response = await callback(diagnosticNodeForMetadataCall);
|
||||
node.addChildNode(diagnosticNodeForMetadataCall, CosmosDbDiagnosticLevel.debug, type);
|
||||
return response;
|
||||
}
|
||||
catch (e) {
|
||||
node.addChildNode(diagnosticNodeForMetadataCall, CosmosDbDiagnosticLevel.debug, type);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Utility wrapper function to managed lifecycle of a Diagnostic session.
|
||||
* Meant to be used at the root of the client operation. i.e. item.read(),
|
||||
* queryIterator.fetchAll().
|
||||
*
|
||||
* This utility starts a new diagnostic session. So using it any where else
|
||||
* other than start of operation, will result is different diagnostic sessions.
|
||||
*
|
||||
* Workings :
|
||||
* 1. Takes a callback function as input.
|
||||
* 2. Creates a new instance of DiagnosticNodeInternal, which can be though as starting
|
||||
* a new diagnostic session.
|
||||
* 3. Executes the callback function.
|
||||
* 4. If execution was successful. Converts DiagnosticNodeInternal to CosmosDiagnostics
|
||||
* and injects it to the response object and returns this object.
|
||||
* 5. If execution threw an exception. Sill converts DiagnosticNodeInternal to CosmosDiagnostics
|
||||
* and injects it to the Error object, and rethrows the Error object.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
export async function withDiagnostics(callback, clientContext, type = DiagnosticNodeType.CLIENT_REQUEST_NODE) {
|
||||
const diagnosticNode = new DiagnosticNodeInternal(clientContext.diagnosticLevel, type, null);
|
||||
try {
|
||||
const response = await callback(diagnosticNode);
|
||||
diagnosticNode.updateTimestamp();
|
||||
const diagnostics = diagnosticNode.toDiagnostic(clientContext.getClientConfig());
|
||||
if (typeof response === "object" && response !== null) {
|
||||
response.diagnostics = diagnostics;
|
||||
}
|
||||
clientContext.recordDiagnostics(diagnostics);
|
||||
return response;
|
||||
}
|
||||
catch (e) {
|
||||
diagnosticNode.updateTimestamp();
|
||||
diagnosticNode.addData({
|
||||
failure: true,
|
||||
});
|
||||
const diagnostics = diagnosticNode.toDiagnostic(clientContext.getClientConfig());
|
||||
e.diagnostics = diagnostics;
|
||||
clientContext.recordDiagnostics(diagnostics);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=diagnostics.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
|
||||
export declare function digest(str: string): Promise<string>;
|
||||
//# sourceMappingURL=digest.browser.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"digest.browser.d.ts","sourceRoot":"","sources":["../../../src/utils/digest.browser.ts"],"names":[],"mappings":"AAMA,wBAAsB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAIzD"}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { encodeUTF8 } from "./encode";
|
||||
import { globalCrypto } from "./globalCrypto";
|
||||
export async function digest(str) {
|
||||
const data = encodeUTF8(str);
|
||||
const hash = await globalCrypto.subtle.digest("SHA-256", data);
|
||||
return bufferToHex(hash);
|
||||
}
|
||||
function bufferToHex(buffer) {
|
||||
return Array.prototype.map
|
||||
.call(new Uint8Array(buffer), (item) => ("00" + item.toString(16)).slice(-2))
|
||||
.join("");
|
||||
}
|
||||
//# sourceMappingURL=digest.browser.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"digest.browser.js","sourceRoot":"","sources":["../../../src/utils/digest.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,GAAW;IACtC,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/D,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,SAAS,WAAW,CAAC,MAAmB;IACtC,OAAO,KAAK,CAAC,SAAS,CAAC,GAAG;SACvB,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SACpF,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { encodeUTF8 } from \"./encode\";\nimport { globalCrypto } from \"./globalCrypto\";\n\nexport async function digest(str: string): Promise<string> {\n const data = encodeUTF8(str);\n const hash = await globalCrypto.subtle.digest(\"SHA-256\", data);\n return bufferToHex(hash);\n}\n\nfunction bufferToHex(buffer: ArrayBuffer): string {\n return Array.prototype.map\n .call(new Uint8Array(buffer), (item: number) => (\"00\" + item.toString(16)).slice(-2))\n .join(\"\");\n}\n"]}
|
||||
@@ -0,0 +1,2 @@
|
||||
export declare function digest(str: string): Promise<string>;
|
||||
//# sourceMappingURL=digest.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../../../src/utils/digest.ts"],"names":[],"mappings":"AAKA,wBAAsB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAIzD"}
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { createHash } from "crypto";
|
||||
export async function digest(str) {
|
||||
const hash = createHash("sha256");
|
||||
hash.update(str, "utf8");
|
||||
return hash.digest("hex");
|
||||
}
|
||||
//# sourceMappingURL=digest.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"digest.js","sourceRoot":"","sources":["../../../src/utils/digest.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,GAAW;IACtC,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACzB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createHash } from \"crypto\";\n\nexport async function digest(str: string): Promise<string> {\n const hash = createHash(\"sha256\");\n hash.update(str, \"utf8\");\n return hash.digest(\"hex\");\n}\n"]}
|
||||
@@ -0,0 +1,4 @@
|
||||
/// <reference lib="dom" />
|
||||
export declare function encodeUTF8(str: string): Uint8Array;
|
||||
export declare function encodeBase64(value: ArrayBuffer): string;
|
||||
//# sourceMappingURL=encode.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../src/utils/encode.ts"],"names":[],"mappings":";AAKA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAMlD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAYvD"}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
/// <reference lib="dom"/>
|
||||
export function encodeUTF8(str) {
|
||||
const bytes = new Uint8Array(str.length);
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
bytes[i] = str.charCodeAt(i);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
export function encodeBase64(value) {
|
||||
if ("function" !== typeof btoa) {
|
||||
throw new Error("Your browser environment is missing the global `btoa` function");
|
||||
}
|
||||
let binary = "";
|
||||
const bytes = new Uint8Array(value);
|
||||
const len = bytes.byteLength;
|
||||
for (let i = 0; i < len; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return btoa(binary);
|
||||
}
|
||||
//# sourceMappingURL=encode.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../../src/utils/encode.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,0BAA0B;AAE1B,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;KAC9B;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAkB;IAC7C,IAAI,UAAU,KAAK,OAAO,IAAI,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;KACnF;IAED,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;QAC5B,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;KACzC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/// <reference lib=\"dom\"/>\n\nexport function encodeUTF8(str: string): Uint8Array {\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n}\n\nexport function encodeBase64(value: ArrayBuffer): string {\n if (\"function\" !== typeof btoa) {\n throw new Error(\"Your browser environment is missing the global `btoa` function\");\n }\n\n let binary = \"\";\n const bytes = new Uint8Array(value);\n const len = bytes.byteLength;\n for (let i = 0; i < len; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n"]}
|
||||
@@ -0,0 +1,3 @@
|
||||
declare const globalCrypto: Crypto;
|
||||
export { globalCrypto };
|
||||
//# sourceMappingURL=globalCrypto.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"globalCrypto.d.ts","sourceRoot":"","sources":["../../../src/utils/globalCrypto.ts"],"names":[],"mappings":"AAUA,QAAA,MAAM,YAAY,EAAE,MAA+C,CAAC;AAMpE,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
// eslint-disable-next-line @azure/azure-sdk/ts-no-window
|
||||
const globalRef = typeof self === "undefined" ? window : self;
|
||||
if (!globalRef) {
|
||||
throw new Error("Could not find global");
|
||||
}
|
||||
const globalCrypto = globalRef.crypto || globalRef.msCrypto;
|
||||
if (!globalCrypto || !globalCrypto.subtle) {
|
||||
throw new Error("Browser does not support cryptography functions");
|
||||
}
|
||||
export { globalCrypto };
|
||||
//# sourceMappingURL=globalCrypto.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"globalCrypto.js","sourceRoot":"","sources":["../../../src/utils/globalCrypto.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,yDAAyD;AACzD,MAAM,SAAS,GAAQ,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAEnE,IAAI,CAAC,SAAS,EAAE;IACd,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;CAC1C;AAED,MAAM,YAAY,GAAW,SAAS,CAAC,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC;AAEpE,IAAI,CAAC,YAAY,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;IACzC,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;CACpE;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n// eslint-disable-next-line @azure/azure-sdk/ts-no-window\nconst globalRef: any = typeof self === \"undefined\" ? window : self;\n\nif (!globalRef) {\n throw new Error(\"Could not find global\");\n}\n\nconst globalCrypto: Crypto = globalRef.crypto || globalRef.msCrypto;\n\nif (!globalCrypto || !globalCrypto.subtle) {\n throw new Error(\"Browser does not support cryptography functions\");\n}\n\nexport { globalCrypto };\n"]}
|
||||
@@ -0,0 +1,3 @@
|
||||
declare const globalCrypto: any;
|
||||
export { globalCrypto };
|
||||
//# sourceMappingURL=globalCrypto.native.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"globalCrypto.native.d.ts","sourceRoot":"","sources":["../../../src/utils/globalCrypto.native.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,YAAY,KAAkC,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
// isomorphic-webcrypto is not listed as a dependency in package.json because
|
||||
// doing so requires adding a bunch of react packages as peer dependencies. So,
|
||||
// it is being loaded dynamically here to not cause compiler error.
|
||||
const globalCrypto = require("isomorphic-webcrypto"); // eslint-disable-line import/no-extraneous-dependencies, @typescript-eslint/no-require-imports
|
||||
export { globalCrypto };
|
||||
//# sourceMappingURL=globalCrypto.native.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"globalCrypto.native.js","sourceRoot":"","sources":["../../../src/utils/globalCrypto.native.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,6EAA6E;AAC7E,+EAA+E;AAC/E,mEAAmE;AACnE,MAAM,YAAY,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC,+FAA+F;AACrJ,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n// isomorphic-webcrypto is not listed as a dependency in package.json because\n// doing so requires adding a bunch of react packages as peer dependencies. So,\n// it is being loaded dynamically here to not cause compiler error.\nconst globalCrypto = require(\"isomorphic-webcrypto\"); // eslint-disable-line import/no-extraneous-dependencies, @typescript-eslint/no-require-imports\nexport { globalCrypto };\n"]}
|
||||
@@ -0,0 +1,2 @@
|
||||
export declare function hashObject(object: unknown): Promise<string>;
|
||||
//# sourceMappingURL=hashObject.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"hashObject.d.ts","sourceRoot":"","sources":["../../../src/utils/hashObject.ts"],"names":[],"mappings":"AAMA,wBAAsB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAGjE"}
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { digest } from "./digest";
|
||||
import stableStringify from "fast-json-stable-stringify";
|
||||
export async function hashObject(object) {
|
||||
const stringifiedObject = stableStringify(object);
|
||||
return digest(stringifiedObject);
|
||||
}
|
||||
//# sourceMappingURL=hashObject.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"hashObject.js","sourceRoot":"","sources":["../../../src/utils/hashObject.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,eAAe,MAAM,4BAA4B,CAAC;AAEzD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAe;IAC9C,MAAM,iBAAiB,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IAClD,OAAO,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACnC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { digest } from \"./digest\";\nimport stableStringify from \"fast-json-stable-stringify\";\n\nexport async function hashObject(object: unknown): Promise<string> {\n const stringifiedObject = stableStringify(object);\n return digest(stringifiedObject);\n}\n"]}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
/// <reference types="node" />
|
||||
export declare function writeNumberForBinaryEncodingJSBI(hash: number): Buffer;
|
||||
export declare function doubleToByteArrayJSBI(double: number): Buffer;
|
||||
//# sourceMappingURL=number.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../../../src/utils/hashing/encoding/number.ts"],"names":[],"mappings":";AAMA,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAyCrE;AAYD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAY5D"}
|
||||
@@ -0,0 +1,68 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import JSBI from "jsbi";
|
||||
import { BytePrefix } from "./prefix";
|
||||
export function writeNumberForBinaryEncodingJSBI(hash) {
|
||||
let payload = encodeNumberAsUInt64JSBI(hash);
|
||||
let outputStream = Buffer.from(BytePrefix.Number, "hex");
|
||||
const firstChunk = JSBI.asUintN(64, JSBI.signedRightShift(payload, JSBI.BigInt(56)));
|
||||
outputStream = Buffer.concat([outputStream, Buffer.from(firstChunk.toString(16), "hex")]);
|
||||
payload = JSBI.asUintN(64, JSBI.leftShift(JSBI.BigInt(payload), JSBI.BigInt(0x8)));
|
||||
let byteToWrite = JSBI.BigInt(0);
|
||||
let firstIteration = false;
|
||||
let shifted;
|
||||
let padded;
|
||||
do {
|
||||
if (!firstIteration) {
|
||||
// we pad because after shifting because we will produce characters like "f" or similar,
|
||||
// which cannot be encoded as hex in a buffer because they are invalid hex
|
||||
// https://github.com/nodejs/node/issues/24491
|
||||
padded = byteToWrite.toString(16).padStart(2, "0");
|
||||
if (padded !== "00") {
|
||||
outputStream = Buffer.concat([outputStream, Buffer.from(padded, "hex")]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
firstIteration = false;
|
||||
}
|
||||
shifted = JSBI.asUintN(64, JSBI.signedRightShift(payload, JSBI.BigInt(56)));
|
||||
byteToWrite = JSBI.asUintN(64, JSBI.bitwiseOr(shifted, JSBI.BigInt(0x01)));
|
||||
payload = JSBI.asUintN(64, JSBI.leftShift(payload, JSBI.BigInt(7)));
|
||||
} while (JSBI.notEqual(payload, JSBI.BigInt(0)));
|
||||
const lastChunk = JSBI.asUintN(64, JSBI.bitwiseAnd(byteToWrite, JSBI.BigInt(0xfe)));
|
||||
// we pad because after shifting because we will produce characters like "f" or similar,
|
||||
// which cannot be encoded as hex in a buffer because they are invalid hex
|
||||
// https://github.com/nodejs/node/issues/24491
|
||||
padded = lastChunk.toString(16).padStart(2, "0");
|
||||
if (padded !== "00") {
|
||||
outputStream = Buffer.concat([outputStream, Buffer.from(padded, "hex")]);
|
||||
}
|
||||
return outputStream;
|
||||
}
|
||||
function encodeNumberAsUInt64JSBI(value) {
|
||||
const rawValueBits = getRawBitsJSBI(value);
|
||||
const mask = JSBI.BigInt(0x8000000000000000);
|
||||
const returned = rawValueBits < mask
|
||||
? JSBI.bitwiseXor(rawValueBits, mask)
|
||||
: JSBI.add(JSBI.bitwiseNot(rawValueBits), JSBI.BigInt(1));
|
||||
return returned;
|
||||
}
|
||||
export function doubleToByteArrayJSBI(double) {
|
||||
const output = Buffer.alloc(8);
|
||||
const lng = getRawBitsJSBI(double);
|
||||
for (let i = 0; i < 8; i++) {
|
||||
output[i] = JSBI.toNumber(JSBI.bitwiseAnd(JSBI.signedRightShift(lng, JSBI.multiply(JSBI.BigInt(i), JSBI.BigInt(8))), JSBI.BigInt(0xff)));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
function getRawBitsJSBI(value) {
|
||||
const view = new DataView(new ArrayBuffer(8));
|
||||
view.setFloat64(0, value);
|
||||
return JSBI.BigInt(`0x${buf2hex(view.buffer)}`);
|
||||
}
|
||||
function buf2hex(buffer) {
|
||||
return Array.prototype.map
|
||||
.call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2))
|
||||
.join("");
|
||||
}
|
||||
//# sourceMappingURL=number.js.map
|
||||
File diff suppressed because one or more lines are too long
+25
@@ -0,0 +1,25 @@
|
||||
export declare const BytePrefix: {
|
||||
Undefined: string;
|
||||
Null: string;
|
||||
False: string;
|
||||
True: string;
|
||||
MinNumber: string;
|
||||
Number: string;
|
||||
MaxNumber: string;
|
||||
MinString: string;
|
||||
String: string;
|
||||
MaxString: string;
|
||||
Int64: string;
|
||||
Int32: string;
|
||||
Int16: string;
|
||||
Int8: string;
|
||||
Uint64: string;
|
||||
Uint32: string;
|
||||
Uint16: string;
|
||||
Uint8: string;
|
||||
Binary: string;
|
||||
Guid: string;
|
||||
Float: string;
|
||||
Infinity: string;
|
||||
};
|
||||
//# sourceMappingURL=prefix.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"prefix.d.ts","sourceRoot":"","sources":["../../../../../src/utils/hashing/encoding/prefix.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;CAuBtB,CAAC"}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
export const BytePrefix = {
|
||||
Undefined: "00",
|
||||
Null: "01",
|
||||
False: "02",
|
||||
True: "03",
|
||||
MinNumber: "04",
|
||||
Number: "05",
|
||||
MaxNumber: "06",
|
||||
MinString: "07",
|
||||
String: "08",
|
||||
MaxString: "09",
|
||||
Int64: "0a",
|
||||
Int32: "0b",
|
||||
Int16: "0c",
|
||||
Int8: "0d",
|
||||
Uint64: "0e",
|
||||
Uint32: "0f",
|
||||
Uint16: "10",
|
||||
Uint8: "11",
|
||||
Binary: "12",
|
||||
Guid: "13",
|
||||
Float: "14",
|
||||
Infinity: "FF",
|
||||
};
|
||||
//# sourceMappingURL=prefix.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"prefix.js","sourceRoot":"","sources":["../../../../../src/utils/hashing/encoding/prefix.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,SAAS,EAAE,IAAI;IACf,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,IAAI;IACZ,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,IAAI;CACf,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const BytePrefix = {\n Undefined: \"00\",\n Null: \"01\",\n False: \"02\",\n True: \"03\",\n MinNumber: \"04\",\n Number: \"05\",\n MaxNumber: \"06\",\n MinString: \"07\",\n String: \"08\",\n MaxString: \"09\",\n Int64: \"0a\",\n Int32: \"0b\",\n Int16: \"0c\",\n Int8: \"0d\",\n Uint64: \"0e\",\n Uint32: \"0f\",\n Uint16: \"10\",\n Uint8: \"11\",\n Binary: \"12\",\n Guid: \"13\",\n Float: \"14\",\n Infinity: \"FF\",\n};\n"]}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
/// <reference types="node" />
|
||||
export declare function writeStringForBinaryEncoding(payload: string): Buffer;
|
||||
//# sourceMappingURL=string.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../../../src/utils/hashing/encoding/string.ts"],"names":[],"mappings":";AAKA,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAuBpE"}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { BytePrefix } from "./prefix";
|
||||
export function writeStringForBinaryEncoding(payload) {
|
||||
let outputStream = Buffer.from(BytePrefix.String, "hex");
|
||||
const MAX_STRING_BYTES_TO_APPEND = 100;
|
||||
const byteArray = [...Buffer.from(payload)];
|
||||
const isShortString = payload.length <= MAX_STRING_BYTES_TO_APPEND;
|
||||
for (let index = 0; index < (isShortString ? byteArray.length : MAX_STRING_BYTES_TO_APPEND + 1); index++) {
|
||||
let charByte = byteArray[index];
|
||||
if (charByte < 0xff) {
|
||||
charByte++;
|
||||
}
|
||||
outputStream = Buffer.concat([outputStream, Buffer.from(charByte.toString(16), "hex")]);
|
||||
}
|
||||
if (isShortString) {
|
||||
outputStream = Buffer.concat([outputStream, Buffer.from(BytePrefix.Undefined, "hex")]);
|
||||
}
|
||||
return outputStream;
|
||||
}
|
||||
//# sourceMappingURL=string.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../../../src/utils/hashing/encoding/string.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,UAAU,4BAA4B,CAAC,OAAe;IAC1D,IAAI,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACzD,MAAM,0BAA0B,GAAG,GAAG,CAAC;IACvC,MAAM,SAAS,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAE5C,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,IAAI,0BAA0B,CAAC;IAEnE,KACE,IAAI,KAAK,GAAG,CAAC,EACb,KAAK,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,0BAA0B,GAAG,CAAC,CAAC,EAC3E,KAAK,EAAE,EACP;QACA,IAAI,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,QAAQ,GAAG,IAAI,EAAE;YACnB,QAAQ,EAAE,CAAC;SACZ;QACD,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;KACzF;IAED,IAAI,aAAa,EAAE;QACjB,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;KACxF;IACD,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { BytePrefix } from \"./prefix\";\n\nexport function writeStringForBinaryEncoding(payload: string): Buffer {\n let outputStream = Buffer.from(BytePrefix.String, \"hex\");\n const MAX_STRING_BYTES_TO_APPEND = 100;\n const byteArray = [...Buffer.from(payload)];\n\n const isShortString = payload.length <= MAX_STRING_BYTES_TO_APPEND;\n\n for (\n let index = 0;\n index < (isShortString ? byteArray.length : MAX_STRING_BYTES_TO_APPEND + 1);\n index++\n ) {\n let charByte = byteArray[index];\n if (charByte < 0xff) {\n charByte++;\n }\n outputStream = Buffer.concat([outputStream, Buffer.from(charByte.toString(16), \"hex\")]);\n }\n\n if (isShortString) {\n outputStream = Buffer.concat([outputStream, Buffer.from(BytePrefix.Undefined, \"hex\")]);\n }\n return outputStream;\n}\n"]}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { PartitionKeyDefinition, PrimitivePartitionKeyValue } from "../../documents";
|
||||
/**
|
||||
* Generate hash of a PartitonKey based on it PartitionKeyDefinition.
|
||||
* @param partitionKey - to be hashed.
|
||||
* @param partitionDefinition - container's partitionKey definition
|
||||
* @returns
|
||||
*/
|
||||
export declare function hashPartitionKey(partitionKey: PrimitivePartitionKeyValue[], partitionDefinition: PartitionKeyDefinition): string;
|
||||
//# sourceMappingURL=hash.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../../src/utils/hashing/hash.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,sBAAsB,EAGtB,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AAKzB;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,0BAA0B,EAAE,EAC1C,mBAAmB,EAAE,sBAAsB,GAC1C,MAAM,CAYR"}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { PartitionKeyDefinitionVersion, PartitionKeyKind, } from "../../documents";
|
||||
import { hashMultiHashPartitionKey } from "./multiHash";
|
||||
import { hashV1PartitionKey } from "./v1";
|
||||
import { hashV2PartitionKey } from "./v2";
|
||||
/**
|
||||
* Generate hash of a PartitonKey based on it PartitionKeyDefinition.
|
||||
* @param partitionKey - to be hashed.
|
||||
* @param partitionDefinition - container's partitionKey definition
|
||||
* @returns
|
||||
*/
|
||||
export function hashPartitionKey(partitionKey, partitionDefinition) {
|
||||
const kind = (partitionDefinition === null || partitionDefinition === void 0 ? void 0 : partitionDefinition.kind) || PartitionKeyKind.Hash; // Default value.
|
||||
const isV2 = partitionDefinition &&
|
||||
partitionDefinition.version &&
|
||||
partitionDefinition.version === PartitionKeyDefinitionVersion.V2;
|
||||
switch (kind) {
|
||||
case PartitionKeyKind.Hash:
|
||||
return isV2 ? hashV2PartitionKey(partitionKey) : hashV1PartitionKey(partitionKey);
|
||||
case PartitionKeyKind.MultiHash:
|
||||
return hashMultiHashPartitionKey(partitionKey);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=hash.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../../src/utils/hashing/hash.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAEL,6BAA6B,EAC7B,gBAAgB,GAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,YAA0C,EAC1C,mBAA2C;IAE3C,MAAM,IAAI,GAAqB,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,IAAI,KAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,iBAAiB;IACpG,MAAM,IAAI,GACR,mBAAmB;QACnB,mBAAmB,CAAC,OAAO;QAC3B,mBAAmB,CAAC,OAAO,KAAK,6BAA6B,CAAC,EAAE,CAAC;IACnE,QAAQ,IAAI,EAAE;QACZ,KAAK,gBAAgB,CAAC,IAAI;YACxB,OAAO,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;QACpF,KAAK,gBAAgB,CAAC,SAAS;YAC7B,OAAO,yBAAyB,CAAC,YAAY,CAAC,CAAC;KAClD;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n PartitionKeyDefinition,\n PartitionKeyDefinitionVersion,\n PartitionKeyKind,\n PrimitivePartitionKeyValue,\n} from \"../../documents\";\nimport { hashMultiHashPartitionKey } from \"./multiHash\";\nimport { hashV1PartitionKey } from \"./v1\";\nimport { hashV2PartitionKey } from \"./v2\";\n\n/**\n * Generate hash of a PartitonKey based on it PartitionKeyDefinition.\n * @param partitionKey - to be hashed.\n * @param partitionDefinition - container's partitionKey definition\n * @returns\n */\nexport function hashPartitionKey(\n partitionKey: PrimitivePartitionKeyValue[],\n partitionDefinition: PartitionKeyDefinition,\n): string {\n const kind: PartitionKeyKind = partitionDefinition?.kind || PartitionKeyKind.Hash; // Default value.\n const isV2 =\n partitionDefinition &&\n partitionDefinition.version &&\n partitionDefinition.version === PartitionKeyDefinitionVersion.V2;\n switch (kind) {\n case PartitionKeyKind.Hash:\n return isV2 ? hashV2PartitionKey(partitionKey) : hashV1PartitionKey(partitionKey);\n case PartitionKeyKind.MultiHash:\n return hashMultiHashPartitionKey(partitionKey);\n }\n}\n"]}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { PrimitivePartitionKeyValue } from "../../documents";
|
||||
/**
|
||||
* Generate Hash for a `Multi Hash` type partition.
|
||||
* @param partitionKey - to be hashed.
|
||||
* @returns
|
||||
*/
|
||||
export declare function hashMultiHashPartitionKey(partitionKey: PrimitivePartitionKeyValue[]): string;
|
||||
//# sourceMappingURL=multiHash.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"multiHash.d.ts","sourceRoot":"","sources":["../../../../src/utils/hashing/multiHash.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAG7D;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,0BAA0B,EAAE,GAAG,MAAM,CAE5F"}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { hashV2PartitionKey } from "./v2";
|
||||
/**
|
||||
* Generate Hash for a `Multi Hash` type partition.
|
||||
* @param partitionKey - to be hashed.
|
||||
* @returns
|
||||
*/
|
||||
export function hashMultiHashPartitionKey(partitionKey) {
|
||||
return partitionKey.map((keys) => hashV2PartitionKey([keys])).join("");
|
||||
}
|
||||
//# sourceMappingURL=multiHash.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"multiHash.js","sourceRoot":"","sources":["../../../../src/utils/hashing/multiHash.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAE1C;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,YAA0C;IAClF,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { PrimitivePartitionKeyValue } from \"../../documents\";\nimport { hashV2PartitionKey } from \"./v2\";\n\n/**\n * Generate Hash for a `Multi Hash` type partition.\n * @param partitionKey - to be hashed.\n * @returns\n */\nexport function hashMultiHashPartitionKey(partitionKey: PrimitivePartitionKeyValue[]): string {\n return partitionKey.map((keys) => hashV2PartitionKey([keys])).join(\"\");\n}\n"]}
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference types="node" />
|
||||
declare function x86Hash32(bytes: Buffer, seed?: number): number;
|
||||
declare function x86Hash128(bytes: Buffer, seed?: number): string;
|
||||
declare function x64Hash128(bytes: Buffer, seed?: number): string;
|
||||
export declare function reverse(buff: Buffer): Buffer;
|
||||
declare const _default: {
|
||||
version: string;
|
||||
x86: {
|
||||
hash32: typeof x86Hash32;
|
||||
hash128: typeof x86Hash128;
|
||||
};
|
||||
x64: {
|
||||
hash128: typeof x64Hash128;
|
||||
};
|
||||
inputValidation: boolean;
|
||||
};
|
||||
export default _default;
|
||||
//# sourceMappingURL=murmurHash.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"murmurHash.d.ts","sourceRoot":"","sources":["../../../../src/utils/hashing/murmurHash.ts"],"names":[],"mappings":";AAiLA,iBAAS,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,UAoD9C;AAED,iBAAS,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,UAwK/C;AAED,iBAAS,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,UAuI/C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,UAQnC;;;;;;;;;;;;AAED,wBAUE"}
|
||||
@@ -0,0 +1,436 @@
|
||||
// +----------------------------------------------------------------------+
|
||||
// | murmurHash3js.js v3.0.1 // https://github.com/pid/murmurHash3js
|
||||
// | A javascript implementation of MurmurHash3's x86 hashing algorithms. |
|
||||
// |----------------------------------------------------------------------|
|
||||
// | Copyright (c) 2012-2015 Karan Lyons |
|
||||
// | https://github.com/karanlyons/murmurHash3.js/blob/c1778f75792abef7bdd74bc85d2d4e1a3d25cfe9/murmurHash3.js |
|
||||
// | Freely distributable under the MIT license. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// PRIVATE FUNCTIONS
|
||||
// -----------------
|
||||
function _x86Multiply(m, n) {
|
||||
//
|
||||
// Given two 32bit ints, returns the two multiplied together as a
|
||||
// 32bit int.
|
||||
//
|
||||
return (m & 0xffff) * n + ((((m >>> 16) * n) & 0xffff) << 16);
|
||||
}
|
||||
function _x86Rotl(m, n) {
|
||||
//
|
||||
// Given a 32bit int and an int representing a number of bit positions,
|
||||
// returns the 32bit int rotated left by that number of positions.
|
||||
//
|
||||
return (m << n) | (m >>> (32 - n));
|
||||
}
|
||||
function _x86Fmix(h) {
|
||||
//
|
||||
// Given a block, returns murmurHash3's final x86 mix of that block.
|
||||
//
|
||||
h ^= h >>> 16;
|
||||
h = _x86Multiply(h, 0x85ebca6b);
|
||||
h ^= h >>> 13;
|
||||
h = _x86Multiply(h, 0xc2b2ae35);
|
||||
h ^= h >>> 16;
|
||||
return h;
|
||||
}
|
||||
function _x64Add(m, n) {
|
||||
//
|
||||
// Given two 64bit ints (as an array of two 32bit ints) returns the two
|
||||
// added together as a 64bit int (as an array of two 32bit ints).
|
||||
//
|
||||
m = [m[0] >>> 16, m[0] & 0xffff, m[1] >>> 16, m[1] & 0xffff];
|
||||
n = [n[0] >>> 16, n[0] & 0xffff, n[1] >>> 16, n[1] & 0xffff];
|
||||
const o = [0, 0, 0, 0];
|
||||
o[3] += m[3] + n[3];
|
||||
o[2] += o[3] >>> 16;
|
||||
o[3] &= 0xffff;
|
||||
o[2] += m[2] + n[2];
|
||||
o[1] += o[2] >>> 16;
|
||||
o[2] &= 0xffff;
|
||||
o[1] += m[1] + n[1];
|
||||
o[0] += o[1] >>> 16;
|
||||
o[1] &= 0xffff;
|
||||
o[0] += m[0] + n[0];
|
||||
o[0] &= 0xffff;
|
||||
return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]];
|
||||
}
|
||||
function _x64Multiply(m, n) {
|
||||
//
|
||||
// Given two 64bit ints (as an array of two 32bit ints) returns the two
|
||||
// multiplied together as a 64bit int (as an array of two 32bit ints).
|
||||
//
|
||||
m = [m[0] >>> 16, m[0] & 0xffff, m[1] >>> 16, m[1] & 0xffff];
|
||||
n = [n[0] >>> 16, n[0] & 0xffff, n[1] >>> 16, n[1] & 0xffff];
|
||||
const o = [0, 0, 0, 0];
|
||||
o[3] += m[3] * n[3];
|
||||
o[2] += o[3] >>> 16;
|
||||
o[3] &= 0xffff;
|
||||
o[2] += m[2] * n[3];
|
||||
o[1] += o[2] >>> 16;
|
||||
o[2] &= 0xffff;
|
||||
o[2] += m[3] * n[2];
|
||||
o[1] += o[2] >>> 16;
|
||||
o[2] &= 0xffff;
|
||||
o[1] += m[1] * n[3];
|
||||
o[0] += o[1] >>> 16;
|
||||
o[1] &= 0xffff;
|
||||
o[1] += m[2] * n[2];
|
||||
o[0] += o[1] >>> 16;
|
||||
o[1] &= 0xffff;
|
||||
o[1] += m[3] * n[1];
|
||||
o[0] += o[1] >>> 16;
|
||||
o[1] &= 0xffff;
|
||||
o[0] += m[0] * n[3] + m[1] * n[2] + m[2] * n[1] + m[3] * n[0];
|
||||
o[0] &= 0xffff;
|
||||
return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]];
|
||||
}
|
||||
function _x64Rotl(m, n) {
|
||||
//
|
||||
// Given a 64bit int (as an array of two 32bit ints) and an int
|
||||
// representing a number of bit positions, returns the 64bit int (as an
|
||||
// array of two 32bit ints) rotated left by that number of positions.
|
||||
//
|
||||
n %= 64;
|
||||
if (n === 32) {
|
||||
return [m[1], m[0]];
|
||||
}
|
||||
else if (n < 32) {
|
||||
return [(m[0] << n) | (m[1] >>> (32 - n)), (m[1] << n) | (m[0] >>> (32 - n))];
|
||||
}
|
||||
else {
|
||||
n -= 32;
|
||||
return [(m[1] << n) | (m[0] >>> (32 - n)), (m[0] << n) | (m[1] >>> (32 - n))];
|
||||
}
|
||||
}
|
||||
function _x64LeftShift(m, n) {
|
||||
//
|
||||
// Given a 64bit int (as an array of two 32bit ints) and an int
|
||||
// representing a number of bit positions, returns the 64bit int (as an
|
||||
// array of two 32bit ints) shifted left by that number of positions.
|
||||
//
|
||||
n %= 64;
|
||||
if (n === 0) {
|
||||
return m;
|
||||
}
|
||||
else if (n < 32) {
|
||||
return [(m[0] << n) | (m[1] >>> (32 - n)), m[1] << n];
|
||||
}
|
||||
else {
|
||||
return [m[1] << (n - 32), 0];
|
||||
}
|
||||
}
|
||||
function _x64Xor(m, n) {
|
||||
//
|
||||
// Given two 64bit ints (as an array of two 32bit ints) returns the two
|
||||
// xored together as a 64bit int (as an array of two 32bit ints).
|
||||
//
|
||||
return [m[0] ^ n[0], m[1] ^ n[1]];
|
||||
}
|
||||
function _x64Fmix(h) {
|
||||
//
|
||||
// Given a block, returns murmurHash3's final x64 mix of that block.
|
||||
// (`[0, h[0] >>> 1]` is a 33 bit unsigned right shift. This is the
|
||||
// only place where we need to right shift 64bit ints.)
|
||||
//
|
||||
h = _x64Xor(h, [0, h[0] >>> 1]);
|
||||
h = _x64Multiply(h, [0xff51afd7, 0xed558ccd]);
|
||||
h = _x64Xor(h, [0, h[0] >>> 1]);
|
||||
h = _x64Multiply(h, [0xc4ceb9fe, 0x1a85ec53]);
|
||||
h = _x64Xor(h, [0, h[0] >>> 1]);
|
||||
return h;
|
||||
}
|
||||
// PUBLIC FUNCTIONS
|
||||
// ----------------
|
||||
function x86Hash32(bytes, seed) {
|
||||
//
|
||||
// Given a string and an optional seed as an int, returns a 32 bit hash
|
||||
// using the x86 flavor of MurmurHash3, as an unsigned int.
|
||||
//
|
||||
seed = seed || 0;
|
||||
const remainder = bytes.length % 4;
|
||||
const blocks = bytes.length - remainder;
|
||||
let h1 = seed;
|
||||
let k1 = 0;
|
||||
const c1 = 0xcc9e2d51;
|
||||
const c2 = 0x1b873593;
|
||||
let j = 0;
|
||||
for (let i = 0; i < blocks; i = i + 4) {
|
||||
k1 = bytes[i] | (bytes[i + 1] << 8) | (bytes[i + 2] << 16) | (bytes[i + 3] << 24);
|
||||
k1 = _x86Multiply(k1, c1);
|
||||
k1 = _x86Rotl(k1, 15);
|
||||
k1 = _x86Multiply(k1, c2);
|
||||
h1 ^= k1;
|
||||
h1 = _x86Rotl(h1, 13);
|
||||
h1 = _x86Multiply(h1, 5) + 0xe6546b64;
|
||||
j = i + 4;
|
||||
}
|
||||
k1 = 0;
|
||||
switch (remainder) {
|
||||
case 3:
|
||||
k1 ^= bytes[j + 2] << 16;
|
||||
case 2:
|
||||
k1 ^= bytes[j + 1] << 8;
|
||||
case 1:
|
||||
k1 ^= bytes[j];
|
||||
k1 = _x86Multiply(k1, c1);
|
||||
k1 = _x86Rotl(k1, 15);
|
||||
k1 = _x86Multiply(k1, c2);
|
||||
h1 ^= k1;
|
||||
}
|
||||
h1 ^= bytes.length;
|
||||
h1 = _x86Fmix(h1);
|
||||
return h1 >>> 0;
|
||||
}
|
||||
function x86Hash128(bytes, seed) {
|
||||
//
|
||||
// Given a string and an optional seed as an int, returns a 128 bit
|
||||
// hash using the x86 flavor of MurmurHash3, as an unsigned hex.
|
||||
//
|
||||
seed = seed || 0;
|
||||
const remainder = bytes.length % 16;
|
||||
const blocks = bytes.length - remainder;
|
||||
let h1 = seed;
|
||||
let h2 = seed;
|
||||
let h3 = seed;
|
||||
let h4 = seed;
|
||||
let k1 = 0;
|
||||
let k2 = 0;
|
||||
let k3 = 0;
|
||||
let k4 = 0;
|
||||
const c1 = 0x239b961b;
|
||||
const c2 = 0xab0e9789;
|
||||
const c3 = 0x38b34ae5;
|
||||
const c4 = 0xa1e38b93;
|
||||
let j = 0;
|
||||
for (let i = 0; i < blocks; i = i + 16) {
|
||||
k1 = bytes[i] | (bytes[i + 1] << 8) | (bytes[i + 2] << 16) | (bytes[i + 3] << 24);
|
||||
k2 = bytes[i + 4] | (bytes[i + 5] << 8) | (bytes[i + 6] << 16) | (bytes[i + 7] << 24);
|
||||
k3 = bytes[i + 8] | (bytes[i + 9] << 8) | (bytes[i + 10] << 16) | (bytes[i + 11] << 24);
|
||||
k4 = bytes[i + 12] | (bytes[i + 13] << 8) | (bytes[i + 14] << 16) | (bytes[i + 15] << 24);
|
||||
k1 = _x86Multiply(k1, c1);
|
||||
k1 = _x86Rotl(k1, 15);
|
||||
k1 = _x86Multiply(k1, c2);
|
||||
h1 ^= k1;
|
||||
h1 = _x86Rotl(h1, 19);
|
||||
h1 += h2;
|
||||
h1 = _x86Multiply(h1, 5) + 0x561ccd1b;
|
||||
k2 = _x86Multiply(k2, c2);
|
||||
k2 = _x86Rotl(k2, 16);
|
||||
k2 = _x86Multiply(k2, c3);
|
||||
h2 ^= k2;
|
||||
h2 = _x86Rotl(h2, 17);
|
||||
h2 += h3;
|
||||
h2 = _x86Multiply(h2, 5) + 0x0bcaa747;
|
||||
k3 = _x86Multiply(k3, c3);
|
||||
k3 = _x86Rotl(k3, 17);
|
||||
k3 = _x86Multiply(k3, c4);
|
||||
h3 ^= k3;
|
||||
h3 = _x86Rotl(h3, 15);
|
||||
h3 += h4;
|
||||
h3 = _x86Multiply(h3, 5) + 0x96cd1c35;
|
||||
k4 = _x86Multiply(k4, c4);
|
||||
k4 = _x86Rotl(k4, 18);
|
||||
k4 = _x86Multiply(k4, c1);
|
||||
h4 ^= k4;
|
||||
h4 = _x86Rotl(h4, 13);
|
||||
h4 += h1;
|
||||
h4 = _x86Multiply(h4, 5) + 0x32ac3b17;
|
||||
j = i + 16;
|
||||
}
|
||||
k1 = 0;
|
||||
k2 = 0;
|
||||
k3 = 0;
|
||||
k4 = 0;
|
||||
switch (remainder) {
|
||||
case 15:
|
||||
k4 ^= bytes[j + 14] << 16;
|
||||
case 14:
|
||||
k4 ^= bytes[j + 13] << 8;
|
||||
case 13:
|
||||
k4 ^= bytes[j + 12];
|
||||
k4 = _x86Multiply(k4, c4);
|
||||
k4 = _x86Rotl(k4, 18);
|
||||
k4 = _x86Multiply(k4, c1);
|
||||
h4 ^= k4;
|
||||
case 12:
|
||||
k3 ^= bytes[j + 11] << 24;
|
||||
case 11:
|
||||
k3 ^= bytes[j + 10] << 16;
|
||||
case 10:
|
||||
k3 ^= bytes[j + 9] << 8;
|
||||
case 9:
|
||||
k3 ^= bytes[j + 8];
|
||||
k3 = _x86Multiply(k3, c3);
|
||||
k3 = _x86Rotl(k3, 17);
|
||||
k3 = _x86Multiply(k3, c4);
|
||||
h3 ^= k3;
|
||||
case 8:
|
||||
k2 ^= bytes[j + 7] << 24;
|
||||
case 7:
|
||||
k2 ^= bytes[j + 6] << 16;
|
||||
case 6:
|
||||
k2 ^= bytes[j + 5] << 8;
|
||||
case 5:
|
||||
k2 ^= bytes[j + 4];
|
||||
k2 = _x86Multiply(k2, c2);
|
||||
k2 = _x86Rotl(k2, 16);
|
||||
k2 = _x86Multiply(k2, c3);
|
||||
h2 ^= k2;
|
||||
case 4:
|
||||
k1 ^= bytes[j + 3] << 24;
|
||||
case 3:
|
||||
k1 ^= bytes[j + 2] << 16;
|
||||
case 2:
|
||||
k1 ^= bytes[j + 1] << 8;
|
||||
case 1:
|
||||
k1 ^= bytes[j];
|
||||
k1 = _x86Multiply(k1, c1);
|
||||
k1 = _x86Rotl(k1, 15);
|
||||
k1 = _x86Multiply(k1, c2);
|
||||
h1 ^= k1;
|
||||
}
|
||||
h1 ^= bytes.length;
|
||||
h2 ^= bytes.length;
|
||||
h3 ^= bytes.length;
|
||||
h4 ^= bytes.length;
|
||||
h1 += h2;
|
||||
h1 += h3;
|
||||
h1 += h4;
|
||||
h2 += h1;
|
||||
h3 += h1;
|
||||
h4 += h1;
|
||||
h1 = _x86Fmix(h1);
|
||||
h2 = _x86Fmix(h2);
|
||||
h3 = _x86Fmix(h3);
|
||||
h4 = _x86Fmix(h4);
|
||||
h1 += h2;
|
||||
h1 += h3;
|
||||
h1 += h4;
|
||||
h2 += h1;
|
||||
h3 += h1;
|
||||
h4 += h1;
|
||||
return (("00000000" + (h1 >>> 0).toString(16)).slice(-8) +
|
||||
("00000000" + (h2 >>> 0).toString(16)).slice(-8) +
|
||||
("00000000" + (h3 >>> 0).toString(16)).slice(-8) +
|
||||
("00000000" + (h4 >>> 0).toString(16)).slice(-8));
|
||||
}
|
||||
function x64Hash128(bytes, seed) {
|
||||
//
|
||||
// Given a string and an optional seed as an int, returns a 128 bit
|
||||
// hash using the x64 flavor of MurmurHash3, as an unsigned hex.
|
||||
//
|
||||
seed = seed || 0;
|
||||
const remainder = bytes.length % 16;
|
||||
const blocks = bytes.length - remainder;
|
||||
let h1 = [0, seed];
|
||||
let h2 = [0, seed];
|
||||
let k1 = [0, 0];
|
||||
let k2 = [0, 0];
|
||||
const c1 = [0x87c37b91, 0x114253d5];
|
||||
const c2 = [0x4cf5ad43, 0x2745937f];
|
||||
let j = 0;
|
||||
for (let i = 0; i < blocks; i = i + 16) {
|
||||
k1 = [
|
||||
bytes[i + 4] | (bytes[i + 5] << 8) | (bytes[i + 6] << 16) | (bytes[i + 7] << 24),
|
||||
bytes[i] | (bytes[i + 1] << 8) | (bytes[i + 2] << 16) | (bytes[i + 3] << 24),
|
||||
];
|
||||
k2 = [
|
||||
bytes[i + 12] | (bytes[i + 13] << 8) | (bytes[i + 14] << 16) | (bytes[i + 15] << 24),
|
||||
bytes[i + 8] | (bytes[i + 9] << 8) | (bytes[i + 10] << 16) | (bytes[i + 11] << 24),
|
||||
];
|
||||
k1 = _x64Multiply(k1, c1);
|
||||
k1 = _x64Rotl(k1, 31);
|
||||
k1 = _x64Multiply(k1, c2);
|
||||
h1 = _x64Xor(h1, k1);
|
||||
h1 = _x64Rotl(h1, 27);
|
||||
h1 = _x64Add(h1, h2);
|
||||
h1 = _x64Add(_x64Multiply(h1, [0, 5]), [0, 0x52dce729]);
|
||||
k2 = _x64Multiply(k2, c2);
|
||||
k2 = _x64Rotl(k2, 33);
|
||||
k2 = _x64Multiply(k2, c1);
|
||||
h2 = _x64Xor(h2, k2);
|
||||
h2 = _x64Rotl(h2, 31);
|
||||
h2 = _x64Add(h2, h1);
|
||||
h2 = _x64Add(_x64Multiply(h2, [0, 5]), [0, 0x38495ab5]);
|
||||
j = i + 16;
|
||||
}
|
||||
k1 = [0, 0];
|
||||
k2 = [0, 0];
|
||||
switch (remainder) {
|
||||
case 15:
|
||||
k2 = _x64Xor(k2, _x64LeftShift([0, bytes[j + 14]], 48));
|
||||
case 14:
|
||||
k2 = _x64Xor(k2, _x64LeftShift([0, bytes[j + 13]], 40));
|
||||
case 13:
|
||||
k2 = _x64Xor(k2, _x64LeftShift([0, bytes[j + 12]], 32));
|
||||
case 12:
|
||||
k2 = _x64Xor(k2, _x64LeftShift([0, bytes[j + 11]], 24));
|
||||
case 11:
|
||||
k2 = _x64Xor(k2, _x64LeftShift([0, bytes[j + 10]], 16));
|
||||
case 10:
|
||||
k2 = _x64Xor(k2, _x64LeftShift([0, bytes[j + 9]], 8));
|
||||
case 9:
|
||||
k2 = _x64Xor(k2, [0, bytes[j + 8]]);
|
||||
k2 = _x64Multiply(k2, c2);
|
||||
k2 = _x64Rotl(k2, 33);
|
||||
k2 = _x64Multiply(k2, c1);
|
||||
h2 = _x64Xor(h2, k2);
|
||||
case 8:
|
||||
k1 = _x64Xor(k1, _x64LeftShift([0, bytes[j + 7]], 56));
|
||||
case 7:
|
||||
k1 = _x64Xor(k1, _x64LeftShift([0, bytes[j + 6]], 48));
|
||||
case 6:
|
||||
k1 = _x64Xor(k1, _x64LeftShift([0, bytes[j + 5]], 40));
|
||||
case 5:
|
||||
k1 = _x64Xor(k1, _x64LeftShift([0, bytes[j + 4]], 32));
|
||||
case 4:
|
||||
k1 = _x64Xor(k1, _x64LeftShift([0, bytes[j + 3]], 24));
|
||||
case 3:
|
||||
k1 = _x64Xor(k1, _x64LeftShift([0, bytes[j + 2]], 16));
|
||||
case 2:
|
||||
k1 = _x64Xor(k1, _x64LeftShift([0, bytes[j + 1]], 8));
|
||||
case 1:
|
||||
k1 = _x64Xor(k1, [0, bytes[j]]);
|
||||
k1 = _x64Multiply(k1, c1);
|
||||
k1 = _x64Rotl(k1, 31);
|
||||
k1 = _x64Multiply(k1, c2);
|
||||
h1 = _x64Xor(h1, k1);
|
||||
}
|
||||
h1 = _x64Xor(h1, [0, bytes.length]);
|
||||
h2 = _x64Xor(h2, [0, bytes.length]);
|
||||
h1 = _x64Add(h1, h2);
|
||||
h2 = _x64Add(h2, h1);
|
||||
h1 = _x64Fmix(h1);
|
||||
h2 = _x64Fmix(h2);
|
||||
h1 = _x64Add(h1, h2);
|
||||
h2 = _x64Add(h2, h1);
|
||||
// Here we reverse h1 and h2 in Cosmos
|
||||
// This is an implementation detail and not part of the public spec
|
||||
const h1Buff = Buffer.from(("00000000" + (h1[0] >>> 0).toString(16)).slice(-8) +
|
||||
("00000000" + (h1[1] >>> 0).toString(16)).slice(-8), "hex");
|
||||
const h1Reversed = reverse(h1Buff).toString("hex");
|
||||
const h2Buff = Buffer.from(("00000000" + (h2[0] >>> 0).toString(16)).slice(-8) +
|
||||
("00000000" + (h2[1] >>> 0).toString(16)).slice(-8), "hex");
|
||||
const h2Reversed = reverse(h2Buff).toString("hex");
|
||||
return h1Reversed + h2Reversed;
|
||||
}
|
||||
export function reverse(buff) {
|
||||
const buffer = Buffer.allocUnsafe(buff.length);
|
||||
for (let i = 0, j = buff.length - 1; i <= j; ++i, --j) {
|
||||
buffer[i] = buff[j];
|
||||
buffer[j] = buff[i];
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
export default {
|
||||
version: "3.0.0",
|
||||
x86: {
|
||||
hash32: x86Hash32,
|
||||
hash128: x86Hash128,
|
||||
},
|
||||
x64: {
|
||||
hash128: x64Hash128,
|
||||
},
|
||||
inputValidation: true,
|
||||
};
|
||||
//# sourceMappingURL=murmurHash.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
import { PrimitivePartitionKeyValue } from "../../documents";
|
||||
export declare function hashV1PartitionKey(partitionKey: PrimitivePartitionKeyValue[]): string;
|
||||
//# sourceMappingURL=v1.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"v1.d.ts","sourceRoot":"","sources":["../../../../src/utils/hashing/v1.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAI7D,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,0BAA0B,EAAE,GAAG,MAAM,CAQrF"}
|
||||
@@ -0,0 +1,76 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { doubleToByteArrayJSBI, writeNumberForBinaryEncodingJSBI } from "./encoding/number";
|
||||
import { writeStringForBinaryEncoding } from "./encoding/string";
|
||||
import { BytePrefix } from "./encoding/prefix";
|
||||
import MurmurHash from "./murmurHash";
|
||||
const MAX_STRING_CHARS = 100;
|
||||
export function hashV1PartitionKey(partitionKey) {
|
||||
const key = partitionKey[0];
|
||||
const toHash = prefixKeyByType(key);
|
||||
const hash = MurmurHash.x86.hash32(toHash);
|
||||
const encodedJSBI = writeNumberForBinaryEncodingJSBI(hash);
|
||||
const encodedValue = encodeByType(key);
|
||||
const finalHash = Buffer.concat([encodedJSBI, encodedValue]).toString("hex").toUpperCase();
|
||||
return finalHash;
|
||||
}
|
||||
function prefixKeyByType(key) {
|
||||
let bytes;
|
||||
switch (typeof key) {
|
||||
case "string": {
|
||||
const truncated = key.substr(0, MAX_STRING_CHARS);
|
||||
bytes = Buffer.concat([
|
||||
Buffer.from(BytePrefix.String, "hex"),
|
||||
Buffer.from(truncated),
|
||||
Buffer.from(BytePrefix.Undefined, "hex"),
|
||||
]);
|
||||
return bytes;
|
||||
}
|
||||
case "number": {
|
||||
const numberBytes = doubleToByteArrayJSBI(key);
|
||||
bytes = Buffer.concat([Buffer.from(BytePrefix.Number, "hex"), numberBytes]);
|
||||
return bytes;
|
||||
}
|
||||
case "boolean": {
|
||||
const prefix = key ? BytePrefix.True : BytePrefix.False;
|
||||
return Buffer.from(prefix, "hex");
|
||||
}
|
||||
case "object": {
|
||||
if (key === null) {
|
||||
return Buffer.from(BytePrefix.Null, "hex");
|
||||
}
|
||||
return Buffer.from(BytePrefix.Undefined, "hex");
|
||||
}
|
||||
case "undefined": {
|
||||
return Buffer.from(BytePrefix.Undefined, "hex");
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unexpected type: ${typeof key}`);
|
||||
}
|
||||
}
|
||||
function encodeByType(key) {
|
||||
switch (typeof key) {
|
||||
case "string": {
|
||||
const truncated = key.substr(0, MAX_STRING_CHARS);
|
||||
return writeStringForBinaryEncoding(truncated);
|
||||
}
|
||||
case "number": {
|
||||
const encodedJSBI = writeNumberForBinaryEncodingJSBI(key);
|
||||
return encodedJSBI;
|
||||
}
|
||||
case "boolean": {
|
||||
const prefix = key ? BytePrefix.True : BytePrefix.False;
|
||||
return Buffer.from(prefix, "hex");
|
||||
}
|
||||
case "object":
|
||||
if (key === null) {
|
||||
return Buffer.from(BytePrefix.Null, "hex");
|
||||
}
|
||||
return Buffer.from(BytePrefix.Undefined, "hex");
|
||||
case "undefined":
|
||||
return Buffer.from(BytePrefix.Undefined, "hex");
|
||||
default:
|
||||
throw new Error(`Unexpected type: ${typeof key}`);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=v1.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,5 @@
|
||||
/// <reference types="node" />
|
||||
import { PrimitivePartitionKeyValue } from "../../documents";
|
||||
export declare function hashV2PartitionKey(partitionKey: PrimitivePartitionKeyValue[]): string;
|
||||
export declare function reverse(buff: Buffer): Buffer;
|
||||
//# sourceMappingURL=v2.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"v2.d.ts","sourceRoot":"","sources":["../../../../src/utils/hashing/v2.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAK7D,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,0BAA0B,EAAE,GAAG,MAAM,CAMrF;AAoCD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ5C"}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { doubleToByteArrayJSBI } from "./encoding/number";
|
||||
import { BytePrefix } from "./encoding/prefix";
|
||||
import MurmurHash from "./murmurHash";
|
||||
export function hashV2PartitionKey(partitionKey) {
|
||||
const toHash = Buffer.concat(partitionKey.map(prefixKeyByType));
|
||||
const hash = MurmurHash.x64.hash128(toHash);
|
||||
const reverseBuff = reverse(Buffer.from(hash, "hex"));
|
||||
reverseBuff[0] &= 0x3f;
|
||||
return reverseBuff.toString("hex").toUpperCase();
|
||||
}
|
||||
function prefixKeyByType(key) {
|
||||
let bytes;
|
||||
switch (typeof key) {
|
||||
case "string": {
|
||||
bytes = Buffer.concat([
|
||||
Buffer.from(BytePrefix.String, "hex"),
|
||||
Buffer.from(key),
|
||||
Buffer.from(BytePrefix.Infinity, "hex"),
|
||||
]);
|
||||
return bytes;
|
||||
}
|
||||
case "number": {
|
||||
const numberBytes = doubleToByteArrayJSBI(key);
|
||||
bytes = Buffer.concat([Buffer.from(BytePrefix.Number, "hex"), numberBytes]);
|
||||
return bytes;
|
||||
}
|
||||
case "boolean": {
|
||||
const prefix = key ? BytePrefix.True : BytePrefix.False;
|
||||
return Buffer.from(prefix, "hex");
|
||||
}
|
||||
case "object": {
|
||||
if (key === null) {
|
||||
return Buffer.from(BytePrefix.Null, "hex");
|
||||
}
|
||||
return Buffer.from(BytePrefix.Undefined, "hex");
|
||||
}
|
||||
case "undefined": {
|
||||
return Buffer.from(BytePrefix.Undefined, "hex");
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unexpected type: ${typeof key}`);
|
||||
}
|
||||
}
|
||||
export function reverse(buff) {
|
||||
const buffer = Buffer.allocUnsafe(buff.length);
|
||||
for (let i = 0, j = buff.length - 1; i <= j; ++i, --j) {
|
||||
buffer[i] = buff[j];
|
||||
buffer[j] = buff[i];
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
//#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esContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { PrimitivePartitionKeyValue } from \"../../documents\";\nimport { doubleToByteArrayJSBI } from \"./encoding/number\";\nimport { BytePrefix } from \"./encoding/prefix\";\nimport MurmurHash from \"./murmurHash\";\n\nexport function hashV2PartitionKey(partitionKey: PrimitivePartitionKeyValue[]): string {\n const toHash: Buffer = Buffer.concat(partitionKey.map(prefixKeyByType));\n const hash = MurmurHash.x64.hash128(toHash);\n const reverseBuff: Buffer = reverse(Buffer.from(hash, \"hex\"));\n reverseBuff[0] &= 0x3f;\n return reverseBuff.toString(\"hex\").toUpperCase();\n}\n\nfunction prefixKeyByType(key: PrimitivePartitionKeyValue): Buffer {\n let bytes: Buffer;\n switch (typeof key) {\n case \"string\": {\n bytes = Buffer.concat([\n Buffer.from(BytePrefix.String, \"hex\"),\n Buffer.from(key),\n Buffer.from(BytePrefix.Infinity, \"hex\"),\n ]);\n return bytes;\n }\n case \"number\": {\n const numberBytes = doubleToByteArrayJSBI(key);\n bytes = Buffer.concat([Buffer.from(BytePrefix.Number, \"hex\"), numberBytes]);\n return bytes;\n }\n case \"boolean\": {\n const prefix = key ? BytePrefix.True : BytePrefix.False;\n return Buffer.from(prefix, \"hex\");\n }\n case \"object\": {\n if (key === null) {\n return Buffer.from(BytePrefix.Null, \"hex\");\n }\n return Buffer.from(BytePrefix.Undefined, \"hex\");\n }\n case \"undefined\": {\n return Buffer.from(BytePrefix.Undefined, \"hex\");\n }\n default:\n throw new Error(`Unexpected type: ${typeof key}`);\n }\n}\n\nexport function reverse(buff: Buffer): Buffer {\n const buffer = Buffer.allocUnsafe(buff.length);\n\n for (let i = 0, j = buff.length - 1; i <= j; ++i, --j) {\n buffer[i] = buff[j];\n buffer[j] = buff[i];\n }\n return buffer;\n}\n"]}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { HTTPMethod, ResourceType } from "../common";
|
||||
export declare function generateHeaders(masterKey: string, method: HTTPMethod, resourceType?: ResourceType, resourceId?: string, date?: Date): Promise<{
|
||||
[x: string]: string;
|
||||
}>;
|
||||
//# sourceMappingURL=headers.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../../src/utils/headers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAa,MAAM,WAAW,CAAC;AAEhE,wBAAsB,eAAe,CACnC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,UAAU,EAClB,YAAY,GAAE,YAAgC,EAC9C,UAAU,GAAE,MAAW,EACvB,IAAI,OAAa,GAChB,OAAO,CAAC;IACT,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACrB,CAAC,CAaD"}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { hmac } from "./hmac";
|
||||
import { ResourceType, Constants } from "../common";
|
||||
export async function generateHeaders(masterKey, method, resourceType = ResourceType.none, resourceId = "", date = new Date()) {
|
||||
if (masterKey.startsWith("type=sas&")) {
|
||||
return {
|
||||
[Constants.HttpHeaders.Authorization]: encodeURIComponent(masterKey),
|
||||
[Constants.HttpHeaders.XDate]: date.toUTCString(),
|
||||
};
|
||||
}
|
||||
const sig = await signature(masterKey, method, resourceType, resourceId, date);
|
||||
return {
|
||||
[Constants.HttpHeaders.Authorization]: sig,
|
||||
[Constants.HttpHeaders.XDate]: date.toUTCString(),
|
||||
};
|
||||
}
|
||||
async function signature(masterKey, method, resourceType, resourceId = "", date = new Date()) {
|
||||
const type = "master";
|
||||
const version = "1.0";
|
||||
const text = method.toLowerCase() +
|
||||
"\n" +
|
||||
resourceType.toLowerCase() +
|
||||
"\n" +
|
||||
resourceId +
|
||||
"\n" +
|
||||
date.toUTCString().toLowerCase() +
|
||||
"\n" +
|
||||
"" +
|
||||
"\n";
|
||||
const signed = await hmac(masterKey, text);
|
||||
return encodeURIComponent("type=" + type + "&ver=" + version + "&sig=" + signed);
|
||||
}
|
||||
//# sourceMappingURL=headers.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../src/utils/headers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAc,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEhE,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,SAAiB,EACjB,MAAkB,EAClB,eAA6B,YAAY,CAAC,IAAI,EAC9C,aAAqB,EAAE,EACvB,IAAI,GAAG,IAAI,IAAI,EAAE;IAIjB,IAAI,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QACrC,OAAO;YACL,CAAC,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,kBAAkB,CAAC,SAAS,CAAC;YACpE,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE;SAClD,CAAC;KACH;IACD,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IAE/E,OAAO;QACL,CAAC,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,GAAG;QAC1C,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE;KAClD,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,SAAS,CACtB,SAAiB,EACjB,MAAkB,EAClB,YAA0B,EAC1B,aAAqB,EAAE,EACvB,IAAI,GAAG,IAAI,IAAI,EAAE;IAEjB,MAAM,IAAI,GAAG,QAAQ,CAAC;IACtB,MAAM,OAAO,GAAG,KAAK,CAAC;IACtB,MAAM,IAAI,GACR,MAAM,CAAC,WAAW,EAAE;QACpB,IAAI;QACJ,YAAY,CAAC,WAAW,EAAE;QAC1B,IAAI;QACJ,UAAU;QACV,IAAI;QACJ,IAAI,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE;QAChC,IAAI;QACJ,EAAE;QACF,IAAI,CAAC;IAEP,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAE3C,OAAO,kBAAkB,CAAC,OAAO,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC,CAAC;AACnF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { hmac } from \"./hmac\";\nimport { HTTPMethod, ResourceType, Constants } from \"../common\";\n\nexport async function generateHeaders(\n masterKey: string,\n method: HTTPMethod,\n resourceType: ResourceType = ResourceType.none,\n resourceId: string = \"\",\n date = new Date(),\n): Promise<{\n [x: string]: string;\n}> {\n if (masterKey.startsWith(\"type=sas&\")) {\n return {\n [Constants.HttpHeaders.Authorization]: encodeURIComponent(masterKey),\n [Constants.HttpHeaders.XDate]: date.toUTCString(),\n };\n }\n const sig = await signature(masterKey, method, resourceType, resourceId, date);\n\n return {\n [Constants.HttpHeaders.Authorization]: sig,\n [Constants.HttpHeaders.XDate]: date.toUTCString(),\n };\n}\n\nasync function signature(\n masterKey: string,\n method: HTTPMethod,\n resourceType: ResourceType,\n resourceId: string = \"\",\n date = new Date(),\n): Promise<string> {\n const type = \"master\";\n const version = \"1.0\";\n const text =\n method.toLowerCase() +\n \"\\n\" +\n resourceType.toLowerCase() +\n \"\\n\" +\n resourceId +\n \"\\n\" +\n date.toUTCString().toLowerCase() +\n \"\\n\" +\n \"\" +\n \"\\n\";\n\n const signed = await hmac(masterKey, text);\n\n return encodeURIComponent(\"type=\" + type + \"&ver=\" + version + \"&sig=\" + signed);\n}\n"]}
|
||||
@@ -0,0 +1,2 @@
|
||||
export declare function hmac(key: string, message: string): Promise<string>;
|
||||
//# sourceMappingURL=hmac.browser.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"hmac.browser.d.ts","sourceRoot":"","sources":["../../../src/utils/hmac.browser.ts"],"names":[],"mappings":"AAOA,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAYxE"}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { encodeUTF8, encodeBase64 } from "./encode";
|
||||
import atob from "./atob";
|
||||
import { globalCrypto } from "./globalCrypto";
|
||||
export async function hmac(key, message) {
|
||||
const importParams = { name: "HMAC", hash: { name: "SHA-256" } };
|
||||
const encodedMessage = new Uint8Array([...unescape(encodeURIComponent(message))].map((c) => c.charCodeAt(0)));
|
||||
const encodedKey = encodeUTF8(atob(key));
|
||||
const cryptoKey = await globalCrypto.subtle.importKey("raw", encodedKey, importParams, false, [
|
||||
"sign",
|
||||
]);
|
||||
const signature = await globalCrypto.subtle.sign(importParams, cryptoKey, encodedMessage);
|
||||
return encodeBase64(signature);
|
||||
}
|
||||
//# sourceMappingURL=hmac.browser.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"hmac.browser.js","sourceRoot":"","sources":["../../../src/utils/hmac.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,GAAW,EAAE,OAAe;IACrD,MAAM,YAAY,GAAqB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;IACnF,MAAM,cAAc,GAAG,IAAI,UAAU,CACnC,CAAC,GAAG,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CACvE,CAAC;IACF,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,EAAE;QAC5F,MAAM;KACP,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;IAE1F,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { encodeUTF8, encodeBase64 } from \"./encode\";\nimport atob from \"./atob\";\nimport { globalCrypto } from \"./globalCrypto\";\n\nexport async function hmac(key: string, message: string): Promise<string> {\n const importParams: HmacImportParams = { name: \"HMAC\", hash: { name: \"SHA-256\" } };\n const encodedMessage = new Uint8Array(\n [...unescape(encodeURIComponent(message))].map((c) => c.charCodeAt(0)),\n );\n const encodedKey = encodeUTF8(atob(key));\n const cryptoKey = await globalCrypto.subtle.importKey(\"raw\", encodedKey, importParams, false, [\n \"sign\",\n ]);\n const signature = await globalCrypto.subtle.sign(importParams, cryptoKey, encodedMessage);\n\n return encodeBase64(signature);\n}\n"]}
|
||||
@@ -0,0 +1,2 @@
|
||||
export declare function hmac(key: string, message: string): Promise<string>;
|
||||
//# sourceMappingURL=hmac.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../../../src/utils/hmac.ts"],"names":[],"mappings":"AAKA,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAExE"}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
import { createHmac } from "crypto";
|
||||
export async function hmac(key, message) {
|
||||
return createHmac("sha256", Buffer.from(key, "base64")).update(message).digest("base64");
|
||||
}
|
||||
//# sourceMappingURL=hmac.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"hmac.js","sourceRoot":"","sources":["../../../src/utils/hmac.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,GAAW,EAAE,OAAe;IACrD,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createHmac } from \"crypto\";\n\nexport async function hmac(key: string, message: string): Promise<string> {\n return createHmac(\"sha256\", Buffer.from(key, \"base64\")).update(message).digest(\"base64\");\n}\n"]}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
export declare class NonStreamingOrderByMap<T> {
|
||||
private map;
|
||||
private compareFn;
|
||||
constructor(compareFn: (a: T, b: T) => number);
|
||||
set(key: string, value: T): void;
|
||||
get(key: string): T | undefined;
|
||||
getAllValues(): T[];
|
||||
private replaceResults;
|
||||
size(): number;
|
||||
}
|
||||
//# sourceMappingURL=nonStreamingOrderByMap.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"nonStreamingOrderByMap.d.ts","sourceRoot":"","sources":["../../../src/utils/nonStreamingOrderByMap.ts"],"names":[],"mappings":"AAGA,qBAAa,sBAAsB,CAAC,CAAC;IACnC,OAAO,CAAC,GAAG,CAAiB;IAC5B,OAAO,CAAC,SAAS,CAAyB;gBAE9B,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM;IAKtC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAWhC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAM/B,YAAY,IAAI,CAAC,EAAE;IAS1B,OAAO,CAAC,cAAc;IAOf,IAAI,IAAI,MAAM;CAGtB"}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
export class NonStreamingOrderByMap {
|
||||
constructor(compareFn) {
|
||||
this.compareFn = compareFn;
|
||||
this.map = new Map();
|
||||
}
|
||||
set(key, value) {
|
||||
if (!this.map.has(key)) {
|
||||
this.map.set(key, value);
|
||||
}
|
||||
else {
|
||||
const oldValue = this.map.get(key);
|
||||
if (this.replaceResults(oldValue, value)) {
|
||||
this.map.set(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
get(key) {
|
||||
if (!this.map.has(key))
|
||||
return undefined;
|
||||
return this.map.get(key);
|
||||
}
|
||||
getAllValues() {
|
||||
const res = [];
|
||||
for (const [key, value] of this.map) {
|
||||
res.push(value);
|
||||
this.map.delete(key);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
replaceResults(res1, res2) {
|
||||
const res = this.compareFn(res1, res2);
|
||||
if (res < 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
size() {
|
||||
return this.map.size;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=nonStreamingOrderByMap.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"nonStreamingOrderByMap.js","sourceRoot":"","sources":["../../../src/utils/nonStreamingOrderByMap.ts"],"names":[],"mappings":"AAAA,uCA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;YAAE,OAAO,IAAI,CAAC;QAEzB,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IACvB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport class NonStreamingOrderByMap<T> {\n private map: Map<string, T>;\n private compareFn: (a: T, b: T) => number;\n\n constructor(compareFn: (a: T, b: T) => number) {\n this.compareFn = compareFn;\n this.map = new Map<string, T>();\n }\n\n public set(key: string, value: T): void {\n if (!this.map.has(key)) {\n this.map.set(key, value);\n } else {\n const oldValue = this.map.get(key);\n if (this.replaceResults(oldValue, value)) {\n this.map.set(key, value);\n }\n }\n }\n\n public get(key: string): T | undefined {\n if (!this.map.has(key)) return undefined;\n\n return this.map.get(key);\n }\n\n public getAllValues(): T[] {\n const res: T[] = [];\n for (const [key, value] of this.map) {\n res.push(value);\n this.map.delete(key);\n }\n return res;\n }\n\n private replaceResults(res1: T | undefined, res2: T | undefined): boolean {\n const res = this.compareFn(res1 as T, res2 as T);\n if (res < 0) return true;\n\n return false;\n }\n\n public size(): number {\n return this.map.size;\n }\n}\n"]}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user