@fluidframework/common-utils
Advanced tools
Comparing version 0.31.0 to 0.32.0-31185
@@ -7,14 +7,6 @@ /*! | ||
/** | ||
* Set a hashing function to be called in place of hashFile's internal | ||
* implementation when running under insecure contexts. Not needed | ||
* when running under Node. The internal algorithm should match that the | ||
* one used internally by hashFile. | ||
* @param hashFn - The function that should be used in place of hashFile | ||
*/ | ||
export declare function setInsecureContextHashFn(hashFn: (f: IsoBuffer) => Promise<string>): void; | ||
/** | ||
* Hash a file. Consistent within a session, but should not be persisted and | ||
* is not consistent with git. | ||
* If called under an insecure context for a browser, an override function | ||
* needs to be set using setInsecureContextHashFn | ||
* If called under an insecure context for a browser, this will fallback to | ||
* using the node implementation. | ||
* | ||
@@ -21,0 +13,0 @@ * @param file - The contents of the file in a buffer |
@@ -6,23 +6,29 @@ "use strict"; | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.gitHashFile = exports.hashFile = exports.setInsecureContextHashFn = void 0; | ||
const assert_1 = require("./assert"); | ||
exports.gitHashFile = exports.hashFile = void 0; | ||
const bufferBrowser_1 = require("./bufferBrowser"); | ||
let insecureContextHashFn; | ||
/** | ||
* Set a hashing function to be called in place of hashFile's internal | ||
* implementation when running under insecure contexts. Not needed | ||
* when running under Node. The internal algorithm should match that the | ||
* one used internally by hashFile. | ||
* @param hashFn - The function that should be used in place of hashFile | ||
*/ | ||
function setInsecureContextHashFn(hashFn) { | ||
insecureContextHashFn = hashFn; | ||
} | ||
exports.setInsecureContextHashFn = setInsecureContextHashFn; | ||
/** | ||
* Hash a file. Consistent within a session, but should not be persisted and | ||
* is not consistent with git. | ||
* If called under an insecure context for a browser, an override function | ||
* needs to be set using setInsecureContextHashFn | ||
* If called under an insecure context for a browser, this will fallback to | ||
* using the node implementation. | ||
* | ||
@@ -33,6 +39,6 @@ * @param file - The contents of the file in a buffer | ||
async function hashFile(file) { | ||
// Use the function override if provided | ||
if (insecureContextHashFn !== undefined) { | ||
assert_1.assert(crypto.subtle === undefined, 0x002 /* "Both crypto.subtle and insecureContextHashFn are defined!" */); | ||
return insecureContextHashFn(file); | ||
// Handle insecure contexts (e.g. running with local services) | ||
// by deferring to Node version, which uses a hash polyfill | ||
if (crypto.subtle === undefined) { | ||
return Promise.resolve().then(() => __importStar(require("./hashFileNode"))).then(async (m) => m.hashFile(file)); | ||
} | ||
@@ -39,0 +45,0 @@ const hash = await crypto.subtle.digest("SHA-1", file); |
@@ -7,14 +7,6 @@ /*! | ||
/** | ||
* Set a hashing function to be called in place of hashFile's internal | ||
* implementation when running under insecure contexts. Not needed | ||
* when running under Node. The internal algorithm should match that the | ||
* one used internally by hashFile. | ||
* @param hashFn - The function that should be used in place of hashFile | ||
*/ | ||
export declare function setInsecureContextHashFn(hashFn: (f: IsoBuffer) => Promise<string>): void; | ||
/** | ||
* Hash a file. Consistent within a session, but should not be persisted and | ||
* is not consistent with git. | ||
* If called under an insecure context for a browser, an override function | ||
* needs to be set using setInsecureContextHashFn | ||
* If called under an insecure context for a browser, this will fallback to | ||
* using the node implementation. | ||
* | ||
@@ -21,0 +13,0 @@ * @param file - The contents of the file in a buffer |
@@ -10,21 +10,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.gitHashFile = exports.hashFile = exports.setInsecureContextHashFn = void 0; | ||
exports.gitHashFile = exports.hashFile = void 0; | ||
// eslint-disable-next-line import/no-internal-modules | ||
const sha1_1 = __importDefault(require("sha.js/sha1")); | ||
/** | ||
* Set a hashing function to be called in place of hashFile's internal | ||
* implementation when running under insecure contexts. Not needed | ||
* when running under Node. The internal algorithm should match that the | ||
* one used internally by hashFile. | ||
* @param hashFn - The function that should be used in place of hashFile | ||
*/ | ||
function setInsecureContextHashFn(hashFn) { | ||
return; | ||
} | ||
exports.setInsecureContextHashFn = setInsecureContextHashFn; | ||
/** | ||
* Hash a file. Consistent within a session, but should not be persisted and | ||
* is not consistent with git. | ||
* If called under an insecure context for a browser, an override function | ||
* needs to be set using setInsecureContextHashFn | ||
* If called under an insecure context for a browser, this will fallback to | ||
* using the node implementation. | ||
* | ||
@@ -31,0 +20,0 @@ * @param file - The contents of the file in a buffer |
@@ -28,2 +28,7 @@ /*! | ||
} | ||
export declare function extractLogSafeErrorProperties(error: any): { | ||
message: string; | ||
errorType?: string | undefined; | ||
stack?: string | undefined; | ||
}; | ||
//# sourceMappingURL=logger.d.ts.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TelemetryNullLogger = exports.BaseTelemetryNullLogger = void 0; | ||
exports.extractLogSafeErrorProperties = exports.TelemetryNullLogger = exports.BaseTelemetryNullLogger = void 0; | ||
/** | ||
@@ -39,2 +39,33 @@ * Null logger | ||
exports.TelemetryNullLogger = TelemetryNullLogger; | ||
function extractLogSafeErrorProperties(error) { | ||
const isRegularObject = (value) => { | ||
return value !== null && !Array.isArray(value) && typeof value === "object"; | ||
}; | ||
const removeMessageFromStack = (stack, errorName) => { | ||
const stackFrames = stack.split("\n"); | ||
stackFrames.shift(); // Remove "[ErrorName]: [ErrorMessage]" | ||
if (errorName !== undefined) { | ||
stackFrames.unshift(errorName); // Add "[ErrorName]" | ||
} | ||
return stackFrames.join("\n"); | ||
}; | ||
const message = (typeof (error === null || error === void 0 ? void 0 : error.message) === "string") | ||
? error.message | ||
: String(error); | ||
const safeProps = { | ||
message, | ||
}; | ||
if (isRegularObject(error)) { | ||
const { errorType, stack, name } = error; | ||
if (typeof errorType === "string") { | ||
safeProps.errorType = errorType; | ||
} | ||
if (typeof stack === "string") { | ||
const errorName = (typeof name === "string") ? name : undefined; | ||
safeProps.stack = removeMessageFromStack(stack, errorName); | ||
} | ||
} | ||
return safeProps; | ||
} | ||
exports.extractLogSafeErrorProperties = extractLogSafeErrorProperties; | ||
//# sourceMappingURL=logger.js.map |
@@ -8,3 +8,3 @@ /*! | ||
export declare const pkgName = "@fluidframework/common-utils"; | ||
export declare const pkgVersion = "0.31.0"; | ||
export declare const pkgVersion = "0.32.0-31185"; | ||
//# sourceMappingURL=packageVersion.d.ts.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
exports.pkgName = "@fluidframework/common-utils"; | ||
exports.pkgVersion = "0.31.0"; | ||
exports.pkgVersion = "0.32.0-31185"; | ||
//# sourceMappingURL=packageVersion.js.map |
@@ -7,14 +7,6 @@ /*! | ||
/** | ||
* Set a hashing function to be called in place of hashFile's internal | ||
* implementation when running under insecure contexts. Not needed | ||
* when running under Node. The internal algorithm should match that the | ||
* one used internally by hashFile. | ||
* @param hashFn - The function that should be used in place of hashFile | ||
*/ | ||
export declare function setInsecureContextHashFn(hashFn: (f: IsoBuffer) => Promise<string>): void; | ||
/** | ||
* Hash a file. Consistent within a session, but should not be persisted and | ||
* is not consistent with git. | ||
* If called under an insecure context for a browser, an override function | ||
* needs to be set using setInsecureContextHashFn | ||
* If called under an insecure context for a browser, this will fallback to | ||
* using the node implementation. | ||
* | ||
@@ -21,0 +13,0 @@ * @param file - The contents of the file in a buffer |
@@ -5,20 +5,8 @@ /*! | ||
*/ | ||
import { assert } from "./assert"; | ||
import { IsoBuffer } from "./bufferBrowser"; | ||
let insecureContextHashFn; | ||
/** | ||
* Set a hashing function to be called in place of hashFile's internal | ||
* implementation when running under insecure contexts. Not needed | ||
* when running under Node. The internal algorithm should match that the | ||
* one used internally by hashFile. | ||
* @param hashFn - The function that should be used in place of hashFile | ||
*/ | ||
export function setInsecureContextHashFn(hashFn) { | ||
insecureContextHashFn = hashFn; | ||
} | ||
/** | ||
* Hash a file. Consistent within a session, but should not be persisted and | ||
* is not consistent with git. | ||
* If called under an insecure context for a browser, an override function | ||
* needs to be set using setInsecureContextHashFn | ||
* If called under an insecure context for a browser, this will fallback to | ||
* using the node implementation. | ||
* | ||
@@ -29,6 +17,6 @@ * @param file - The contents of the file in a buffer | ||
export async function hashFile(file) { | ||
// Use the function override if provided | ||
if (insecureContextHashFn !== undefined) { | ||
assert(crypto.subtle === undefined, 0x002 /* "Both crypto.subtle and insecureContextHashFn are defined!" */); | ||
return insecureContextHashFn(file); | ||
// Handle insecure contexts (e.g. running with local services) | ||
// by deferring to Node version, which uses a hash polyfill | ||
if (crypto.subtle === undefined) { | ||
return import("./hashFileNode").then(async (m) => m.hashFile(file)); | ||
} | ||
@@ -35,0 +23,0 @@ const hash = await crypto.subtle.digest("SHA-1", file); |
@@ -7,14 +7,6 @@ /*! | ||
/** | ||
* Set a hashing function to be called in place of hashFile's internal | ||
* implementation when running under insecure contexts. Not needed | ||
* when running under Node. The internal algorithm should match that the | ||
* one used internally by hashFile. | ||
* @param hashFn - The function that should be used in place of hashFile | ||
*/ | ||
export declare function setInsecureContextHashFn(hashFn: (f: IsoBuffer) => Promise<string>): void; | ||
/** | ||
* Hash a file. Consistent within a session, but should not be persisted and | ||
* is not consistent with git. | ||
* If called under an insecure context for a browser, an override function | ||
* needs to be set using setInsecureContextHashFn | ||
* If called under an insecure context for a browser, this will fallback to | ||
* using the node implementation. | ||
* | ||
@@ -21,0 +13,0 @@ * @param file - The contents of the file in a buffer |
@@ -8,16 +8,6 @@ /*! | ||
/** | ||
* Set a hashing function to be called in place of hashFile's internal | ||
* implementation when running under insecure contexts. Not needed | ||
* when running under Node. The internal algorithm should match that the | ||
* one used internally by hashFile. | ||
* @param hashFn - The function that should be used in place of hashFile | ||
*/ | ||
export function setInsecureContextHashFn(hashFn) { | ||
return; | ||
} | ||
/** | ||
* Hash a file. Consistent within a session, but should not be persisted and | ||
* is not consistent with git. | ||
* If called under an insecure context for a browser, an override function | ||
* needs to be set using setInsecureContextHashFn | ||
* If called under an insecure context for a browser, this will fallback to | ||
* using the node implementation. | ||
* | ||
@@ -24,0 +14,0 @@ * @param file - The contents of the file in a buffer |
@@ -28,2 +28,7 @@ /*! | ||
} | ||
export declare function extractLogSafeErrorProperties(error: any): { | ||
message: string; | ||
errorType?: string | undefined; | ||
stack?: string | undefined; | ||
}; | ||
//# sourceMappingURL=logger.d.ts.map |
@@ -33,2 +33,32 @@ /*! | ||
} | ||
export function extractLogSafeErrorProperties(error) { | ||
const isRegularObject = (value) => { | ||
return value !== null && !Array.isArray(value) && typeof value === "object"; | ||
}; | ||
const removeMessageFromStack = (stack, errorName) => { | ||
const stackFrames = stack.split("\n"); | ||
stackFrames.shift(); // Remove "[ErrorName]: [ErrorMessage]" | ||
if (errorName !== undefined) { | ||
stackFrames.unshift(errorName); // Add "[ErrorName]" | ||
} | ||
return stackFrames.join("\n"); | ||
}; | ||
const message = (typeof (error === null || error === void 0 ? void 0 : error.message) === "string") | ||
? error.message | ||
: String(error); | ||
const safeProps = { | ||
message, | ||
}; | ||
if (isRegularObject(error)) { | ||
const { errorType, stack, name } = error; | ||
if (typeof errorType === "string") { | ||
safeProps.errorType = errorType; | ||
} | ||
if (typeof stack === "string") { | ||
const errorName = (typeof name === "string") ? name : undefined; | ||
safeProps.stack = removeMessageFromStack(stack, errorName); | ||
} | ||
} | ||
return safeProps; | ||
} | ||
//# sourceMappingURL=logger.js.map |
@@ -8,3 +8,3 @@ /*! | ||
export declare const pkgName = "@fluidframework/common-utils"; | ||
export declare const pkgVersion = "0.31.0"; | ||
export declare const pkgVersion = "0.32.0-31185"; | ||
//# sourceMappingURL=packageVersion.d.ts.map |
@@ -8,3 +8,3 @@ /*! | ||
export const pkgName = "@fluidframework/common-utils"; | ||
export const pkgVersion = "0.31.0"; | ||
export const pkgVersion = "0.32.0-31185"; | ||
//# sourceMappingURL=packageVersion.js.map |
{ | ||
"name": "@fluidframework/common-utils", | ||
"version": "0.31.0", | ||
"version": "0.32.0-31185", | ||
"description": "Collection of utility functions for Fluid", | ||
@@ -82,4 +82,3 @@ "homepage": "https://fluidframework.com", | ||
"@fluidframework/eslint-config-fluid": "^0.23.0", | ||
"@microsoft/api-extractor": "^7.13.1", | ||
"@types/assert": "^1.5.2", | ||
"@microsoft/api-extractor": "^7.16.1", | ||
"@types/base64-js": "^1.3.0", | ||
@@ -86,0 +85,0 @@ "@types/benchmark": "^2.1.0", |
@@ -6,23 +6,9 @@ /*! | ||
import { assert } from "./assert"; | ||
import { IsoBuffer } from "./bufferBrowser"; | ||
let insecureContextHashFn: ((f: IsoBuffer) => Promise<string>) | undefined; | ||
/** | ||
* Set a hashing function to be called in place of hashFile's internal | ||
* implementation when running under insecure contexts. Not needed | ||
* when running under Node. The internal algorithm should match that the | ||
* one used internally by hashFile. | ||
* @param hashFn - The function that should be used in place of hashFile | ||
*/ | ||
export function setInsecureContextHashFn(hashFn: (f: IsoBuffer) => Promise<string>) { | ||
insecureContextHashFn = hashFn; | ||
} | ||
/** | ||
* Hash a file. Consistent within a session, but should not be persisted and | ||
* is not consistent with git. | ||
* If called under an insecure context for a browser, an override function | ||
* needs to be set using setInsecureContextHashFn | ||
* If called under an insecure context for a browser, this will fallback to | ||
* using the node implementation. | ||
* | ||
@@ -33,6 +19,6 @@ * @param file - The contents of the file in a buffer | ||
export async function hashFile(file: IsoBuffer): Promise<string> { | ||
// Use the function override if provided | ||
if (insecureContextHashFn !== undefined) { | ||
assert(crypto.subtle === undefined, 0x002 /* "Both crypto.subtle and insecureContextHashFn are defined!" */); | ||
return insecureContextHashFn(file); | ||
// Handle insecure contexts (e.g. running with local services) | ||
// by deferring to Node version, which uses a hash polyfill | ||
if (crypto.subtle === undefined) { | ||
return import("./hashFileNode").then(async (m) => m.hashFile(file)); | ||
} | ||
@@ -39,0 +25,0 @@ |
@@ -11,17 +11,6 @@ /*! | ||
/** | ||
* Set a hashing function to be called in place of hashFile's internal | ||
* implementation when running under insecure contexts. Not needed | ||
* when running under Node. The internal algorithm should match that the | ||
* one used internally by hashFile. | ||
* @param hashFn - The function that should be used in place of hashFile | ||
*/ | ||
export function setInsecureContextHashFn(hashFn: (f: IsoBuffer) => Promise<string>) { | ||
return; | ||
} | ||
/** | ||
* Hash a file. Consistent within a session, but should not be persisted and | ||
* is not consistent with git. | ||
* If called under an insecure context for a browser, an override function | ||
* needs to be set using setInsecureContextHashFn | ||
* If called under an insecure context for a browser, this will fallback to | ||
* using the node implementation. | ||
* | ||
@@ -28,0 +17,0 @@ * @param file - The contents of the file in a buffer |
@@ -44,1 +44,39 @@ /*! | ||
} | ||
export function extractLogSafeErrorProperties(error: any) { | ||
const isRegularObject = (value: any): boolean => { | ||
return value !== null && !Array.isArray(value) && typeof value === "object"; | ||
}; | ||
const removeMessageFromStack = (stack: string, errorName?: string) => { | ||
const stackFrames = stack.split("\n"); | ||
stackFrames.shift(); // Remove "[ErrorName]: [ErrorMessage]" | ||
if (errorName !== undefined) { | ||
stackFrames.unshift(errorName); // Add "[ErrorName]" | ||
} | ||
return stackFrames.join("\n"); | ||
}; | ||
const message = (typeof error?.message === "string") | ||
? error.message as string | ||
: String(error); | ||
const safeProps: { message: string; errorType?: string; stack?: string } = { | ||
message, | ||
}; | ||
if (isRegularObject(error)) { | ||
const { errorType, stack, name } = error; | ||
if (typeof errorType === "string") { | ||
safeProps.errorType = errorType; | ||
} | ||
if (typeof stack === "string") { | ||
const errorName = (typeof name === "string") ? name : undefined; | ||
safeProps.stack = removeMessageFromStack(stack, errorName); | ||
} | ||
} | ||
return safeProps; | ||
} |
@@ -9,2 +9,2 @@ /*! | ||
export const pkgName = "@fluidframework/common-utils"; | ||
export const pkgVersion = "0.31.0"; | ||
export const pkgVersion = "0.32.0-31185"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
470236
34
6424