@finos/legend-shared
Advanced tools
Comparing version 6.1.2 to 6.1.3
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
import { stringify as losslessStringify, parse as losslessParse } from 'lossless-json'; | ||
import { type JavaScriptValue, type Replacer, parse as losslessParse } from 'lossless-json'; | ||
export declare const capitalize: (value: string) => string; | ||
@@ -49,3 +49,4 @@ export declare const toSentenceCase: (value: string | undefined) => string; | ||
*/ | ||
export { losslessStringify, losslessParse }; | ||
export { losslessParse as parseLosslessJSON }; | ||
export declare const stringifyLosslessJSON: (val: JavaScriptValue, replacer?: Replacer, space?: number | string) => string; | ||
export declare const tryToFormatLosslessJSONString: (value: string, tabSize?: number) => string; | ||
@@ -52,0 +53,0 @@ export declare const tryToMinifyLosslessJSONString: (value: string) => string; |
@@ -17,2 +17,3 @@ /** | ||
import { stringify as losslessStringify, parse as losslessParse, } from 'lossless-json'; | ||
import { assertNonNullable } from '../error/AssertionUtils.js'; | ||
export const capitalize = (value) => value.length >= 1 | ||
@@ -106,6 +107,11 @@ ? `${value[0].toUpperCase()}${value.substring(1, value.length)}` | ||
*/ | ||
export { losslessStringify, losslessParse }; | ||
export { losslessParse as parseLosslessJSON }; | ||
export const stringifyLosslessJSON = (val, replacer, space) => { | ||
const result = losslessStringify(val, replacer, space); | ||
assertNonNullable(result, `Can't stringify lossless JSON value`); | ||
return result; | ||
}; | ||
export const tryToFormatLosslessJSONString = (value, tabSize = 2) => { | ||
try { | ||
return losslessStringify(losslessParse(value), undefined, tabSize); | ||
return stringifyLosslessJSON(losslessParse(value), undefined, tabSize); | ||
} | ||
@@ -118,3 +124,3 @@ catch { | ||
try { | ||
return losslessStringify(losslessParse(value)); | ||
return tryToFormatLosslessJSONString(value, 0); | ||
} | ||
@@ -121,0 +127,0 @@ catch { |
@@ -52,12 +52,20 @@ /** | ||
debug(event, ...data) { | ||
this.level > LOG_LEVEL.DEBUG ? undefined : this._debug(event, ...data); | ||
if (this.level <= LOG_LEVEL.DEBUG) { | ||
this._debug(event, ...data); | ||
} | ||
} | ||
info(event, ...data) { | ||
this.level > LOG_LEVEL.INFO ? undefined : this._info(event, ...data); | ||
if (this.level <= LOG_LEVEL.INFO) { | ||
this._info(event, ...data); | ||
} | ||
} | ||
warn(event, ...data) { | ||
this.level > LOG_LEVEL.WARN ? undefined : this._warn(event, ...data); | ||
if (this.level <= LOG_LEVEL.WARN) { | ||
this._warn(event, ...data); | ||
} | ||
} | ||
error(event, ...data) { | ||
this.level > LOG_LEVEL.ERROR ? undefined : this._error(event, ...data); | ||
if (this.level <= LOG_LEVEL.ERROR) { | ||
this._error(event, ...data); | ||
} | ||
} | ||
@@ -64,0 +72,0 @@ } |
@@ -107,3 +107,4 @@ /** | ||
export declare const getQueryParameters: <T>(url: string, isFullUrl?: boolean) => T; | ||
export declare const buildUrl: (parts: string[]) => string; | ||
export {}; | ||
//# sourceMappingURL=NetworkUtils.d.ts.map |
@@ -75,3 +75,3 @@ /** | ||
}; | ||
const MAX_ERROR_MESSAGE_LENGTH = 500; | ||
const MAX_ERROR_MESSAGE_LENGTH = 5000; | ||
/** | ||
@@ -83,6 +83,17 @@ * Custom error for service client with response details. | ||
const extractMessage = (payload) => { | ||
if (isObject(payload) && isString(payload.message)) { | ||
return payload.message; | ||
if (isObject(payload)) { | ||
return isString(payload.message) | ||
? payload.message | ||
: JSON.stringify(payload); | ||
} | ||
return isString(payload) ? payload : ''; | ||
let payloadAsObject; | ||
try { | ||
payloadAsObject = JSON.parse(payload); | ||
} | ||
catch { | ||
// NOTE: ignored, above is best effort | ||
} | ||
return payloadAsObject && isString(payloadAsObject.message) | ||
? payloadAsObject.message | ||
: payload; | ||
}; | ||
@@ -339,2 +350,5 @@ // NOTE: status 0 is either timeout or client error possibly caused by authentication | ||
}; | ||
export const buildUrl = (parts) => parts | ||
.map((part) => part.replaceAll(/^\/+/g, '').replaceAll(/\/+$/g, '')) | ||
.join(URL_SEPARATOR); | ||
//# sourceMappingURL=NetworkUtils.js.map |
{ | ||
"name": "@finos/legend-shared", | ||
"version": "6.1.2", | ||
"version": "6.1.3", | ||
"description": "Legend Studio shared utilities and helpers", | ||
@@ -51,7 +51,7 @@ "keywords": [ | ||
"lodash-es": "4.17.21", | ||
"lossless-json": "1.0.5", | ||
"lossless-json": "2.0.0", | ||
"mobx": "6.6.2", | ||
"object-hash": "3.0.0", | ||
"pako": "2.0.4", | ||
"pretty-format": "29.0.3", | ||
"pretty-format": "29.1.2", | ||
"query-string": "7.1.1", | ||
@@ -64,10 +64,10 @@ "seedrandom": "3.0.5", | ||
"@finos/legend-dev-utils": "workspace:*", | ||
"@jest/globals": "29.0.3", | ||
"@jest/globals": "29.1.2", | ||
"cross-env": "7.0.3", | ||
"eslint": "8.24.0", | ||
"jest": "29.0.3", | ||
"jest": "29.1.2", | ||
"lodash": "4.17.21", | ||
"npm-run-all": "4.1.5", | ||
"rimraf": "3.0.2", | ||
"typescript": "4.8.3" | ||
"typescript": "4.8.4" | ||
}, | ||
@@ -74,0 +74,0 @@ "publishConfig": { |
{ | ||
"name": "@finos/legend-shared", | ||
"version": "6.1.2", | ||
"version": "6.1.3", | ||
"description": "Legend Studio shared utilities and helpers", | ||
@@ -51,7 +51,7 @@ "keywords": [ | ||
"lodash-es": "4.17.21", | ||
"lossless-json": "1.0.5", | ||
"lossless-json": "2.0.0", | ||
"mobx": "6.6.2", | ||
"object-hash": "3.0.0", | ||
"pako": "2.0.4", | ||
"pretty-format": "29.0.3", | ||
"pretty-format": "29.1.2", | ||
"query-string": "7.1.1", | ||
@@ -63,11 +63,11 @@ "seedrandom": "3.0.5", | ||
"devDependencies": { | ||
"@finos/legend-dev-utils": "2.0.17", | ||
"@jest/globals": "29.0.3", | ||
"@finos/legend-dev-utils": "2.0.18", | ||
"@jest/globals": "29.1.2", | ||
"cross-env": "7.0.3", | ||
"eslint": "8.24.0", | ||
"jest": "29.0.3", | ||
"jest": "29.1.2", | ||
"lodash": "4.17.21", | ||
"npm-run-all": "4.1.5", | ||
"rimraf": "3.0.2", | ||
"typescript": "4.8.3" | ||
"typescript": "4.8.4" | ||
}, | ||
@@ -74,0 +74,0 @@ "publishConfig": { |
@@ -18,5 +18,8 @@ /** | ||
import { | ||
type JavaScriptValue, | ||
type Replacer, | ||
stringify as losslessStringify, | ||
parse as losslessParse, | ||
} from 'lossless-json'; | ||
import { assertNonNullable } from '../error/AssertionUtils.js'; | ||
@@ -128,3 +131,12 @@ export const capitalize = (value: string): string => | ||
*/ | ||
export { losslessStringify, losslessParse }; | ||
export { losslessParse as parseLosslessJSON }; | ||
export const stringifyLosslessJSON = ( | ||
val: JavaScriptValue, | ||
replacer?: Replacer, | ||
space?: number | string, | ||
): string => { | ||
const result = losslessStringify(val, replacer, space); | ||
assertNonNullable(result, `Can't stringify lossless JSON value`); | ||
return result; | ||
}; | ||
export const tryToFormatLosslessJSONString = ( | ||
@@ -135,3 +147,3 @@ value: string, | ||
try { | ||
return losslessStringify(losslessParse(value), undefined, tabSize); | ||
return stringifyLosslessJSON(losslessParse(value), undefined, tabSize); | ||
} catch { | ||
@@ -144,3 +156,3 @@ return value; | ||
try { | ||
return losslessStringify(losslessParse(value)); | ||
return tryToFormatLosslessJSONString(value, 0); | ||
} catch { | ||
@@ -147,0 +159,0 @@ return value.replace(/\n\s*/g, ''); |
@@ -72,15 +72,23 @@ /** | ||
debug(event: LogEvent, ...data: unknown[]): void { | ||
this.level > LOG_LEVEL.DEBUG ? undefined : this._debug(event, ...data); | ||
if (this.level <= LOG_LEVEL.DEBUG) { | ||
this._debug(event, ...data); | ||
} | ||
} | ||
info(event: LogEvent, ...data: unknown[]): void { | ||
this.level > LOG_LEVEL.INFO ? undefined : this._info(event, ...data); | ||
if (this.level <= LOG_LEVEL.INFO) { | ||
this._info(event, ...data); | ||
} | ||
} | ||
warn(event: LogEvent, ...data: unknown[]): void { | ||
this.level > LOG_LEVEL.WARN ? undefined : this._warn(event, ...data); | ||
if (this.level <= LOG_LEVEL.WARN) { | ||
this._warn(event, ...data); | ||
} | ||
} | ||
error(event: LogEvent, ...data: unknown[]): void { | ||
this.level > LOG_LEVEL.ERROR ? undefined : this._error(event, ...data); | ||
if (this.level <= LOG_LEVEL.ERROR) { | ||
this._error(event, ...data); | ||
} | ||
} | ||
@@ -87,0 +95,0 @@ } |
@@ -94,3 +94,3 @@ /** | ||
const MAX_ERROR_MESSAGE_LENGTH = 500; | ||
const MAX_ERROR_MESSAGE_LENGTH = 5000; | ||
@@ -115,6 +115,16 @@ type ParamterValue = string | number | boolean | undefined; | ||
const extractMessage = (payload: Payload): string => { | ||
if (isObject(payload) && isString(payload.message)) { | ||
return payload.message; | ||
if (isObject(payload)) { | ||
return isString(payload.message) | ||
? payload.message | ||
: JSON.stringify(payload); | ||
} | ||
return isString(payload) ? payload : ''; | ||
let payloadAsObject: Record<PropertyKey, unknown> | undefined; | ||
try { | ||
payloadAsObject = JSON.parse(payload) as Record<PropertyKey, unknown>; | ||
} catch { | ||
// NOTE: ignored, above is best effort | ||
} | ||
return payloadAsObject && isString(payloadAsObject.message) | ||
? payloadAsObject.message | ||
: payload; | ||
}; | ||
@@ -526,1 +536,6 @@ | ||
}; | ||
export const buildUrl = (parts: string[]): string => | ||
parts | ||
.map((part) => part.replaceAll(/^\/+/g, '').replaceAll(/\/+$/g, '')) | ||
.join(URL_SEPARATOR); |
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
343739
6271
+ Addedlossless-json@2.0.0(transitive)
+ Addedpretty-format@29.1.2(transitive)
- Removedlossless-json@1.0.5(transitive)
- Removedpretty-format@29.0.3(transitive)
Updatedlossless-json@2.0.0
Updatedpretty-format@29.1.2