@finos/legend-shared
Advanced tools
Comparing version
@@ -16,2 +16,3 @@ /** | ||
*/ | ||
import { type PlainObject } from '../CommonUtils.js'; | ||
export declare class PluginInfo { | ||
@@ -33,3 +34,3 @@ name: string; | ||
getInfo(): PluginInfo; | ||
configure(configData: object): AbstractPlugin; | ||
configure(configData: PlainObject): AbstractPlugin; | ||
abstract install(pluginManager: AbstractPluginManager): void; | ||
@@ -56,3 +57,3 @@ } | ||
getInfo(): PresetInfo; | ||
configure(configData: object): AbstractPreset; | ||
configure(configData: PlainObject): AbstractPreset; | ||
install(pluginManager: AbstractPluginManager): void; | ||
@@ -64,2 +65,3 @@ } | ||
}; | ||
export declare type ExtensionsConfigurationData = Record<PropertyKey, PlainObject>; | ||
export declare abstract class AbstractPluginManager { | ||
@@ -70,3 +72,3 @@ private plugins; | ||
usePresets(presets: AbstractPreset[]): AbstractPluginManager; | ||
configure(configData: Record<PropertyKey, object>): void; | ||
configure(configData: ExtensionsConfigurationData): void; | ||
install(): void; | ||
@@ -73,0 +75,0 @@ getInfo(): PluginManagerInfo; |
@@ -94,3 +94,3 @@ /** | ||
export declare const deserializeMap: <T>(val: Record<string, T extends object ? PlainObject<T> : T>, itemDeserializer: (val: T extends object ? PlainObject<T> : T) => T) => Map<string, T>; | ||
export declare const serializeMap: <T>(val: Map<string, T>, itemSerializer: (val: T) => T extends object ? PlainObject<T> : T) => Record<PropertyKey, unknown>; | ||
export declare const serializeMap: <T>(val: Map<string, T>, itemSerializer: (val: T) => T extends object ? PlainObject<T> : T) => PlainObject; | ||
export declare const usingConstantValueSchema: (value: unknown | typeof SKIP) => PropSchema; | ||
@@ -97,0 +97,0 @@ /** |
@@ -19,2 +19,17 @@ /** | ||
export { v4 as uuid } from 'uuid'; | ||
/** | ||
* This is a dummy type that acts as a signal to say the type should be plain object with shape rather than prototype object of type | ||
* NOTE: This is useful in network client interface where we enforce that the input and output for the network call must be plain object, | ||
* so as to force proper handling (i.e. deserialize/serialize) but also signal from documentation perspective about the type/shape of the plain object | ||
*/ | ||
export declare type PlainObject<T = unknown> = Record<PropertyKey, unknown>; | ||
/** | ||
* This type allows modification of `readonly` attributes for class/interface | ||
* This is useful to set properties like `owner`, `parent` where we can't do so in the constructors | ||
* | ||
* See https://stackoverflow.com/questions/46634876/how-can-i-change-a-readonly-property-in-typescript | ||
*/ | ||
export declare type Writable<T> = { | ||
-readonly [K in keyof T]: T[K]; | ||
}; | ||
export declare type Clazz<T> = { | ||
@@ -42,7 +57,7 @@ new (...args: any[]): T; | ||
*/ | ||
export declare const recursiveOmit: (obj: Record<PropertyKey, unknown>, checker: (object: Record<PropertyKey, unknown>, propKey: PropertyKey) => boolean) => Record<PropertyKey, unknown>; | ||
export declare const recursiveOmit: <T extends object>(obj: T, checker: (object: object, propKey: PropertyKey) => boolean) => T; | ||
/** | ||
* Recursively remove fields with undefined values in object | ||
*/ | ||
export declare const pruneObject: (obj: Record<PropertyKey, unknown>) => Record<PropertyKey, unknown>; | ||
export declare const pruneObject: (obj: PlainObject) => PlainObject; | ||
/** | ||
@@ -56,7 +71,7 @@ * Recursively remove fields with null values in object | ||
*/ | ||
export declare const pruneNullValues: (obj: Record<PropertyKey, unknown>) => Record<PropertyKey, unknown>; | ||
export declare const pruneNullValues: (obj: PlainObject) => PlainObject; | ||
/** | ||
* Recursively sort object keys alphabetically | ||
*/ | ||
export declare const sortObjectKeys: (value: Record<PropertyKey, unknown>) => Record<PropertyKey, unknown>; | ||
export declare const sortObjectKeys: (value: PlainObject) => PlainObject; | ||
export declare const parseNumber: (val: string) => number; | ||
@@ -74,17 +89,2 @@ /** | ||
/** | ||
* This is a dummy type that acts as a signal to say the type should be plain object with shape rather than prototype object of type | ||
* NOTE: This is useful in network client interface where we enforce that the input and output for the network call must be plain object, | ||
* so as to force proper handling (i.e. deserialize/serialize) but also signal from documentation perspective about the type/shape of the plain object | ||
*/ | ||
export declare type PlainObject<T> = Record<PropertyKey, unknown>; | ||
/** | ||
* This type allows modification of `readonly` attributes for class/interface | ||
* This is useful to set properties like `owner`, `parent` where we can't do so in the constructors | ||
* | ||
* See https://stackoverflow.com/questions/46634876/how-can-i-change-a-readonly-property-in-typescript | ||
*/ | ||
export declare type Writable<T> = { | ||
-readonly [K in keyof T]: T[K]; | ||
}; | ||
/** | ||
* NOTE: This object mutates the input object (obj1) | ||
@@ -91,0 +91,0 @@ * To disable this behavior, set `createClone=true` |
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
import { cloneDeep as deepClone, isEqual as deepEqual, findLast, isEmpty, pickBy, uniqBy, uniq, debounce, throttle, mergeWith, toNumber, } from 'lodash-es'; | ||
import { cloneDeep as deepClone, isEqual as deepEqual, findLast, isEmpty, pickBy, uniqBy, uniq, debounce, throttle, mergeWith, toNumber, isObject, } from 'lodash-es'; | ||
import { UnsupportedOperationError } from './error/ErrorUtils.js'; | ||
@@ -70,11 +70,17 @@ import { format as prettyPrintObject } from 'pretty-format'; | ||
const omit = (_obj, _checker) => { | ||
for (const propKey in _obj) { | ||
if (Object.prototype.hasOwnProperty.call(_obj, propKey)) { | ||
const value = _obj[propKey]; | ||
if (_checker(_obj, propKey)) { | ||
delete _obj[propKey]; | ||
if (Array.isArray(_obj)) { | ||
_obj.forEach((o) => omit(o, _checker)); | ||
} | ||
else { | ||
const o = _obj; | ||
for (const propKey in o) { | ||
if (Object.prototype.hasOwnProperty.call(_obj, propKey)) { | ||
const value = o[propKey]; | ||
if (_checker(_obj, propKey)) { | ||
delete o[propKey]; | ||
} | ||
else if (isObject(value)) { | ||
omit(value, _checker); | ||
} | ||
} | ||
else if (typeof value === 'object') { | ||
omit(value, _checker); | ||
} | ||
} | ||
@@ -81,0 +87,0 @@ } |
@@ -17,3 +17,3 @@ /** | ||
import { EnrichedError } from './ErrorUtils.js'; | ||
import type { GenericClazz } from '../CommonUtils.js'; | ||
import type { GenericClazz, PlainObject } from '../CommonUtils.js'; | ||
export declare class AssertionError extends EnrichedError { | ||
@@ -36,6 +36,9 @@ constructor(error: string | Error | undefined, message?: string); | ||
export declare const isObject: (val: unknown) => val is object; | ||
export declare const isPlainObject: (val: unknown) => val is PlainObject<unknown>; | ||
export declare function assertIsString(val: unknown, message?: string): asserts val is string; | ||
export declare function assertIsNumber(val: unknown, message?: string): asserts val is number; | ||
export declare function assertIsBoolean(val: unknown, message?: string): asserts val is boolean; | ||
export declare const guaranteeIsString: (val: unknown, message?: string) => string; | ||
export declare function assertIsNumber(val: unknown, message?: string): asserts val is number; | ||
export declare const guaranteeIsNumber: (val: unknown, message?: string) => number; | ||
export declare const guaranteeIsBoolean: (val: unknown, message?: string) => boolean; | ||
//# sourceMappingURL=AssertionUtils.d.ts.map |
@@ -65,3 +65,4 @@ /** | ||
export const isBoolean = (val) => typeof val === 'boolean'; | ||
export const isObject = (val) => typeof val === 'object'; | ||
export const isObject = (val) => typeof val === 'object' && val !== null; | ||
export const isPlainObject = (val) => isObject(val) && val.constructor.name === 'Object'; | ||
export function assertIsString(val, message = '') { | ||
@@ -72,6 +73,2 @@ if (!isString(val)) { | ||
} | ||
export const guaranteeIsString = (val, message = '') => { | ||
assertIsString(val, message); | ||
return val; | ||
}; | ||
export function assertIsNumber(val, message = '') { | ||
@@ -82,2 +79,11 @@ if (!isNumber(val)) { | ||
} | ||
export function assertIsBoolean(val, message = '') { | ||
if (!isBoolean(val)) { | ||
throw new AssertionError(message || `Value is expected to be a boolean`); | ||
} | ||
} | ||
export const guaranteeIsString = (val, message = '') => { | ||
assertIsString(val, message); | ||
return val; | ||
}; | ||
export const guaranteeIsNumber = (val, message = '') => { | ||
@@ -87,2 +93,6 @@ assertIsNumber(val, message); | ||
}; | ||
export const guaranteeIsBoolean = (val, message = '') => { | ||
assertIsBoolean(val, message); | ||
return val; | ||
}; | ||
//# sourceMappingURL=AssertionUtils.js.map |
@@ -16,2 +16,3 @@ /** | ||
*/ | ||
import type { PlainObject } from '../CommonUtils.js'; | ||
import { type Parameters, type RequestHeaders, type RequestProcessConfig, type ResponseProcessConfig, HttpMethod } from './NetworkUtils.js'; | ||
@@ -21,3 +22,3 @@ import type { TraceData, TracerService } from './TracerService.js'; | ||
baseUrl?: string; | ||
networkClientOptions?: Record<PropertyKey, unknown>; | ||
networkClientOptions?: PlainObject; | ||
enableCompression?: boolean; | ||
@@ -24,0 +25,0 @@ baseHeaders?: RequestHeaders | undefined; |
@@ -17,2 +17,3 @@ /** | ||
import { StatusCodes } from 'http-status-codes'; | ||
import type { PlainObject } from '../CommonUtils.js'; | ||
export declare const URL_SEPARATOR = "/"; | ||
@@ -53,3 +54,3 @@ export declare const HttpStatus: typeof StatusCodes; | ||
export declare type Parameters = Record<string, ParamterValue | ParamterValue[]>; | ||
export declare type Payload = Record<PropertyKey, unknown> | string; | ||
export declare type Payload = PlainObject | string; | ||
export declare const unauthenticated: (response: Response) => boolean; | ||
@@ -69,3 +70,3 @@ /** | ||
response: Response & { | ||
data?: Record<PropertyKey, unknown>; | ||
data?: object; | ||
}; | ||
@@ -86,3 +87,3 @@ payload?: Payload | undefined; | ||
interface NetworkClientConfig { | ||
options?: Record<PropertyKey, unknown> | undefined; | ||
options?: PlainObject | undefined; | ||
baseUrl?: string | undefined; | ||
@@ -111,3 +112,3 @@ } | ||
export declare const getQueryParameters: <T>(url: string, isFullUrl?: boolean) => T; | ||
export declare const stringifyQueryParams: (params: Record<string, unknown>) => string; | ||
export declare const stringifyQueryParams: (params: PlainObject) => string; | ||
export declare const addQueryParamsStringToUrl: (url: string, val: string | undefined) => string; | ||
@@ -114,0 +115,0 @@ export declare const buildUrl: (parts: string[]) => string; |
@@ -265,3 +265,4 @@ /** | ||
const requestUrl = makeUrl(this.baseUrl, url, parameters ?? {}); | ||
if (data !== undefined && requestProcessConfig?.enableCompression) { | ||
if ((isString(data) || isObject(data)) && | ||
requestProcessConfig?.enableCompression) { | ||
assertTrue(method !== HttpMethod.GET, ' GET request should not have any request payload'); | ||
@@ -268,0 +269,0 @@ data = compressData(data); |
@@ -17,5 +17,6 @@ /** | ||
import { AbstractPlugin, type AbstractPluginManager } from '../application/AbstractPluginManager.js'; | ||
import type { PlainObject } from '../CommonUtils.js'; | ||
export interface TraceData { | ||
name: string; | ||
tags?: Record<PropertyKey, unknown>; | ||
tags?: PlainObject; | ||
} | ||
@@ -43,3 +44,3 @@ export declare enum CORE_TRACER_TAG { | ||
abstract createClientSpan(traceData: TraceData): T; | ||
abstract createServerSpan(clientSpan: T, method: string, url: string, headers: Record<PropertyKey, unknown>): T; | ||
abstract createServerSpan(clientSpan: T, method: string, url: string, headers: PlainObject): T; | ||
abstract concludeClientSpan(clientSpan: T | undefined, error: Error | undefined): void; | ||
@@ -64,5 +65,5 @@ abstract concludeServerSpan(serverSpan: T | undefined): void; | ||
registerPlugins(plugins: TracerServicePlugin<unknown>[]): void; | ||
createTrace(traceData: TraceData | undefined, method: string, url: string, headers: Record<PropertyKey, unknown>): Trace; | ||
createTrace(traceData: TraceData | undefined, method: string, url: string, headers: PlainObject): Trace; | ||
} | ||
export {}; | ||
//# sourceMappingURL=TracerService.d.ts.map |
{ | ||
"name": "@finos/legend-shared", | ||
"version": "6.2.0", | ||
"version": "6.2.1", | ||
"description": "Legend Studio shared utilities and helpers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
{ | ||
"name": "@finos/legend-shared", | ||
"version": "6.2.0", | ||
"version": "6.2.1", | ||
"description": "Legend Studio shared utilities and helpers", | ||
@@ -63,3 +63,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@finos/legend-dev-utils": "2.0.22", | ||
"@finos/legend-dev-utils": "2.0.24", | ||
"@jest/globals": "29.2.2", | ||
@@ -66,0 +66,0 @@ "cross-env": "7.0.3", |
@@ -17,3 +17,3 @@ /** | ||
import { uuid } from '../CommonUtils.js'; | ||
import { type PlainObject, uuid } from '../CommonUtils.js'; | ||
@@ -62,3 +62,3 @@ export class PluginInfo { | ||
configure(configData: object): AbstractPlugin { | ||
configure(configData: PlainObject): AbstractPlugin { | ||
return this; | ||
@@ -122,3 +122,3 @@ } | ||
configure(configData: object): AbstractPreset { | ||
configure(configData: PlainObject): AbstractPreset { | ||
return this; | ||
@@ -137,2 +137,4 @@ } | ||
export type ExtensionsConfigurationData = Record<PropertyKey, PlainObject>; | ||
export abstract class AbstractPluginManager { | ||
@@ -152,5 +154,5 @@ private plugins: AbstractPlugin[] = []; | ||
configure(configData: Record<PropertyKey, object>): void { | ||
configure(configData: ExtensionsConfigurationData): void { | ||
Object.keys(configData).forEach((key) => { | ||
const configObj = configData[key] as object; | ||
const configObj = configData[key] as PlainObject; | ||
this.presets.forEach((preset) => { | ||
@@ -157,0 +159,0 @@ if (preset.getName() === key) { |
@@ -153,4 +153,4 @@ /** | ||
itemSerializer: (val: T) => T extends object ? PlainObject<T> : T, | ||
): Record<PropertyKey, unknown> => { | ||
const result: Record<PropertyKey, unknown> = {}; | ||
): PlainObject => { | ||
const result: PlainObject = {}; | ||
val.forEach((v, key) => { | ||
@@ -157,0 +157,0 @@ result[key] = itemSerializer(v); |
@@ -30,2 +30,3 @@ /** | ||
type DebouncedFunc, | ||
isObject, | ||
} from 'lodash-es'; | ||
@@ -54,2 +55,17 @@ import { UnsupportedOperationError } from './error/ErrorUtils.js'; | ||
/** | ||
* This is a dummy type that acts as a signal to say the type should be plain object with shape rather than prototype object of type | ||
* NOTE: This is useful in network client interface where we enforce that the input and output for the network call must be plain object, | ||
* so as to force proper handling (i.e. deserialize/serialize) but also signal from documentation perspective about the type/shape of the plain object | ||
*/ | ||
export type PlainObject<T = unknown> = Record<PropertyKey, unknown>; // eslint-disable-line @typescript-eslint/no-unused-vars | ||
/** | ||
* This type allows modification of `readonly` attributes for class/interface | ||
* This is useful to set properties like `owner`, `parent` where we can't do so in the constructors | ||
* | ||
* See https://stackoverflow.com/questions/46634876/how-can-i-change-a-readonly-property-in-typescript | ||
*/ | ||
export type Writable<T> = { -readonly [K in keyof T]: T[K] }; | ||
// Since the right side of `instanceof` is an expression evaluating to a constructor function (ie. a class), not a type, so we have to make it | ||
@@ -121,27 +137,26 @@ // as such, this is similar to type definition of Clazz in `serializer` and we take it out here because we want to refer to it in many places | ||
*/ | ||
export const recursiveOmit = ( | ||
obj: Record<PropertyKey, unknown>, | ||
export const recursiveOmit = <T extends object>( | ||
obj: T, | ||
/** | ||
* Checker function which returns `true` if the object field should be omit | ||
*/ | ||
checker: ( | ||
object: Record<PropertyKey, unknown>, | ||
propKey: PropertyKey, | ||
) => boolean, | ||
): Record<PropertyKey, unknown> => { | ||
checker: (object: object, propKey: PropertyKey) => boolean, | ||
): T => { | ||
const newObj = deepClone(obj); | ||
const omit = ( | ||
_obj: Record<PropertyKey, unknown>, | ||
_checker: ( | ||
object: Record<PropertyKey, unknown>, | ||
propKey: string, | ||
) => boolean, | ||
_obj: object, | ||
_checker: (object: object, propKey: string) => boolean, | ||
): void => { | ||
for (const propKey in _obj) { | ||
if (Object.prototype.hasOwnProperty.call(_obj, propKey)) { | ||
const value = _obj[propKey] as Record<PropertyKey, unknown>; | ||
if (_checker(_obj, propKey)) { | ||
delete _obj[propKey]; | ||
} else if (typeof value === 'object') { | ||
omit(value, _checker); | ||
if (Array.isArray(_obj)) { | ||
_obj.forEach((o) => omit(o, _checker)); | ||
} else { | ||
const o = _obj as PlainObject; | ||
for (const propKey in o) { | ||
if (Object.prototype.hasOwnProperty.call(_obj, propKey)) { | ||
const value = o[propKey]; | ||
if (_checker(_obj, propKey)) { | ||
delete o[propKey]; | ||
} else if (isObject(value)) { | ||
omit(value, _checker); | ||
} | ||
} | ||
@@ -158,9 +173,4 @@ } | ||
*/ | ||
export const pruneObject = ( | ||
obj: Record<PropertyKey, unknown>, | ||
): Record<PropertyKey, unknown> => | ||
pickBy(obj, (val: unknown): boolean => val !== undefined) as Record< | ||
PropertyKey, | ||
unknown | ||
>; | ||
export const pruneObject = (obj: PlainObject): PlainObject => | ||
pickBy(obj, (val: unknown): boolean => val !== undefined) as PlainObject; | ||
@@ -175,9 +185,4 @@ /** | ||
*/ | ||
export const pruneNullValues = ( | ||
obj: Record<PropertyKey, unknown>, | ||
): Record<PropertyKey, unknown> => | ||
pickBy(obj, (val: unknown): boolean => val !== null) as Record< | ||
PropertyKey, | ||
unknown | ||
>; | ||
export const pruneNullValues = (obj: PlainObject): PlainObject => | ||
pickBy(obj, (val: unknown): boolean => val !== null) as PlainObject; | ||
@@ -187,5 +192,3 @@ /** | ||
*/ | ||
export const sortObjectKeys = ( | ||
value: Record<PropertyKey, unknown>, | ||
): Record<PropertyKey, unknown> => { | ||
export const sortObjectKeys = (value: PlainObject): PlainObject => { | ||
const _sort = (obj: unknown): unknown => { | ||
@@ -195,4 +198,4 @@ if (Array.isArray(obj)) { | ||
} else if (typeof obj === 'object') { | ||
const oldObj = obj as Record<PropertyKey, unknown>; | ||
const newObj: Record<PropertyKey, unknown> = {}; | ||
const oldObj = obj as PlainObject; | ||
const newObj: PlainObject = {}; | ||
Object.keys(oldObj) | ||
@@ -207,3 +210,3 @@ .sort((a, b) => a.localeCompare(b)) | ||
}; | ||
return _sort(value) as Record<PropertyKey, unknown>; | ||
return _sort(value) as PlainObject; | ||
}; | ||
@@ -259,17 +262,2 @@ | ||
/** | ||
* This is a dummy type that acts as a signal to say the type should be plain object with shape rather than prototype object of type | ||
* NOTE: This is useful in network client interface where we enforce that the input and output for the network call must be plain object, | ||
* so as to force proper handling (i.e. deserialize/serialize) but also signal from documentation perspective about the type/shape of the plain object | ||
*/ | ||
export type PlainObject<T> = Record<PropertyKey, unknown>; // eslint-disable-line @typescript-eslint/no-unused-vars | ||
/** | ||
* This type allows modification of `readonly` attributes for class/interface | ||
* This is useful to set properties like `owner`, `parent` where we can't do so in the constructors | ||
* | ||
* See https://stackoverflow.com/questions/46634876/how-can-i-change-a-readonly-property-in-typescript | ||
*/ | ||
export type Writable<T> = { -readonly [K in keyof T]: T[K] }; | ||
/** | ||
* NOTE: This object mutates the input object (obj1) | ||
@@ -276,0 +264,0 @@ * To disable this behavior, set `createClone=true` |
@@ -18,3 +18,3 @@ /** | ||
import { EnrichedError } from './ErrorUtils.js'; | ||
import type { GenericClazz } from '../CommonUtils.js'; | ||
import type { GenericClazz, PlainObject } from '../CommonUtils.js'; | ||
@@ -111,3 +111,5 @@ export class AssertionError extends EnrichedError { | ||
export const isObject = (val: unknown): val is object => | ||
typeof val === 'object'; | ||
typeof val === 'object' && val !== null; | ||
export const isPlainObject = (val: unknown): val is PlainObject => | ||
isObject(val) && val.constructor.name === 'Object'; | ||
@@ -122,6 +124,2 @@ export function assertIsString( | ||
} | ||
export const guaranteeIsString = (val: unknown, message = ''): string => { | ||
assertIsString(val, message); | ||
return val; | ||
}; | ||
export function assertIsNumber( | ||
@@ -135,2 +133,14 @@ val: unknown, | ||
} | ||
export function assertIsBoolean( | ||
val: unknown, | ||
message = '', | ||
): asserts val is boolean { | ||
if (!isBoolean(val)) { | ||
throw new AssertionError(message || `Value is expected to be a boolean`); | ||
} | ||
} | ||
export const guaranteeIsString = (val: unknown, message = ''): string => { | ||
assertIsString(val, message); | ||
return val; | ||
}; | ||
export const guaranteeIsNumber = (val: unknown, message = ''): number => { | ||
@@ -140,1 +150,5 @@ assertIsNumber(val, message); | ||
}; | ||
export const guaranteeIsBoolean = (val: unknown, message = ''): boolean => { | ||
assertIsBoolean(val, message); | ||
return val; | ||
}; |
@@ -17,2 +17,3 @@ /** | ||
import type { PlainObject } from '../CommonUtils.js'; | ||
import { guaranteeNonNullable } from '../error/AssertionUtils.js'; | ||
@@ -33,3 +34,3 @@ import { | ||
baseUrl?: string; | ||
networkClientOptions?: Record<PropertyKey, unknown>; | ||
networkClientOptions?: PlainObject; | ||
enableCompression?: boolean; | ||
@@ -36,0 +37,0 @@ baseHeaders?: RequestHeaders | undefined; |
@@ -33,2 +33,3 @@ /** | ||
import { sanitizeUrl } from '@braintree/sanitize-url'; | ||
import type { PlainObject } from '../CommonUtils.js'; | ||
@@ -42,3 +43,3 @@ /** | ||
*/ | ||
const compressData = (data: Record<PropertyKey, unknown> | string): Blob => | ||
const compressData = (data: object | string): Blob => | ||
new Blob([deflate(isObject(data) ? JSON.stringify(data) : data)]); | ||
@@ -110,3 +111,3 @@ | ||
export type Parameters = Record<string, ParamterValue | ParamterValue[]>; | ||
export type Payload = Record<PropertyKey, unknown> | string; | ||
export type Payload = PlainObject | string; | ||
@@ -124,5 +125,5 @@ /** | ||
} | ||
let payloadAsObject: Record<PropertyKey, unknown> | undefined; | ||
let payloadAsObject: PlainObject | undefined; | ||
try { | ||
payloadAsObject = JSON.parse(payload) as Record<PropertyKey, unknown>; | ||
payloadAsObject = JSON.parse(payload) as PlainObject; | ||
} catch { | ||
@@ -168,3 +169,3 @@ // NOTE: ignored, above is best effort | ||
export class NetworkClientError extends Error { | ||
response: Response & { data?: Record<PropertyKey, unknown> }; | ||
response: Response & { data?: object }; | ||
payload?: Payload | undefined; | ||
@@ -323,3 +324,3 @@ | ||
interface NetworkClientConfig { | ||
options?: Record<PropertyKey, unknown> | undefined; | ||
options?: PlainObject | undefined; | ||
baseUrl?: string | undefined; | ||
@@ -439,3 +440,6 @@ } | ||
const requestUrl = makeUrl(this.baseUrl, url, parameters ?? {}); | ||
if (data !== undefined && requestProcessConfig?.enableCompression) { | ||
if ( | ||
(isString(data) || isObject(data)) && | ||
requestProcessConfig?.enableCompression | ||
) { | ||
assertTrue( | ||
@@ -445,3 +449,3 @@ method !== HttpMethod.GET, | ||
); | ||
data = compressData(data as Record<PropertyKey, unknown> | string); | ||
data = compressData(data); | ||
// NOTE: do not use Content-Type for GET to avoid unnecessary pre-flight when cross-origin | ||
@@ -545,6 +549,4 @@ headers = mergeRequestHeaders(headers, { | ||
export const stringifyQueryParams = ( | ||
params: Record<string, unknown>, | ||
): string => { | ||
const data: Record<string, string> = {}; | ||
export const stringifyQueryParams = (params: PlainObject): string => { | ||
const data: PlainObject = {}; | ||
Object.entries(params).forEach(([key, value]) => { | ||
@@ -551,0 +553,0 @@ if (!value) { |
@@ -21,6 +21,7 @@ /** | ||
} from '../application/AbstractPluginManager.js'; | ||
import type { PlainObject } from '../CommonUtils.js'; | ||
export interface TraceData { | ||
name: string; | ||
tags?: Record<PropertyKey, unknown>; | ||
tags?: PlainObject; | ||
} | ||
@@ -58,3 +59,3 @@ | ||
url: string, | ||
headers: Record<PropertyKey, unknown>, | ||
headers: PlainObject, | ||
): T; | ||
@@ -117,3 +118,3 @@ abstract concludeClientSpan( | ||
url: string, | ||
headers: Record<PropertyKey, unknown>, | ||
headers: PlainObject, | ||
): Trace { | ||
@@ -120,0 +121,0 @@ const trace = new Trace(); |
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
353320
0.53%6433
0.5%