utils/node_modules/@rushstack/node-core-library/lib/LegacyAdapters.js.map
2024-02-07 01:33:07 -05:00

1 line
5.7 KiB
Plaintext

{"version":3,"file":"LegacyAdapters.js","sourceRoot":"","sources":["../src/LegacyAdapters.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAS3D;;;GAGG;AACH,MAAa,cAAc;IA6BlB,MAAM,CAAC,wBAAwB,CACpC,EAMS,EACT,IAAY,EACZ,IAAY,EACZ,IAAY,EACZ,IAAY;QAEZ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAkC,EAAE,MAA8B,EAAE,EAAE;YACxF,MAAM,EAAE,GAAoC,CAAC,KAAgC,EAAE,MAAe,EAAE,EAAE;gBAChG,IAAI,KAAK,EAAE;oBACT,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;iBAC1C;qBAAM;oBACL,OAAO,CAAC,MAAM,CAAC,CAAC;iBACjB;YACH,CAAC,CAAC;YAEF,IAAI;gBACF,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE;oBACxF,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;iBAChC;qBAAM,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE;oBACzE,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;iBAC1B;qBAAM,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE;oBACnD,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;iBACpB;qBAAM,IAAI,IAAI,KAAK,SAAS,EAAE;oBAC7B,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;iBACd;qBAAM;oBACL,EAAE,CAAC,EAAE,CAAC,CAAC;iBACR;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,CAAU,CAAC,CAAC;aACpB;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,8DAA8D;IACvD,MAAM,CAAC,UAAU,CAAC,KAA2B;QAClD,IAAI,KAAK,YAAY,KAAK,EAAE;YAC1B,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YACpC,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;SACzB;aAAM;YACL,MAAM,WAAW,GAAU,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;YAC1D,WAAmB,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC,yDAAyD;YACjG,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,UAAU,CAAI,KAAU,EAAE,OAAgC;QACtE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF;AAjGD,wCAiGC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * Callback used by {@link LegacyAdapters}.\n * @public\n */\n// eslint-disable-next-line @rushstack/no-new-null\nexport type LegacyCallback<TResult, TError> = (error: TError | null | undefined, result: TResult) => void;\n\n/**\n * Helper functions used when interacting with APIs that do not follow modern coding practices.\n * @public\n */\nexport class LegacyAdapters {\n /**\n * This function wraps a function with a callback in a promise.\n */\n public static convertCallbackToPromise<TResult, TError>(\n fn: (cb: LegacyCallback<TResult, TError>) => void\n ): Promise<TResult>;\n public static convertCallbackToPromise<TResult, TError, TArg1>(\n fn: (arg1: TArg1, cb: LegacyCallback<TResult, TError>) => void,\n arg1: TArg1\n ): Promise<TResult>;\n public static convertCallbackToPromise<TResult, TError, TArg1, TArg2>(\n fn: (arg1: TArg1, arg2: TArg2, cb: LegacyCallback<TResult, TError>) => void,\n arg1: TArg1,\n arg2: TArg2\n ): Promise<TResult>;\n public static convertCallbackToPromise<TResult, TError, TArg1, TArg2, TArg3>(\n fn: (arg1: TArg1, arg2: TArg2, arg3: TArg3, cb: LegacyCallback<TResult, TError>) => void,\n arg1: TArg1,\n arg2: TArg2,\n arg3: TArg3\n ): Promise<TResult>;\n public static convertCallbackToPromise<TResult, TError, TArg1, TArg2, TArg3, TArg4>(\n fn: (arg1: TArg1, arg2: TArg2, arg3: TArg3, arg4: TArg4, cb: LegacyCallback<TResult, TError>) => void,\n arg1: TArg1,\n arg2: TArg2,\n arg3: TArg3,\n arg4: TArg4\n ): Promise<TResult>;\n public static convertCallbackToPromise<TResult, TError, TArg1, TArg2, TArg3, TArg4>(\n fn: (\n a: TArg1 | LegacyCallback<TResult, TError>,\n b?: TArg2 | LegacyCallback<TResult, TError>,\n c?: TArg3 | LegacyCallback<TResult, TError>,\n d?: TArg4 | LegacyCallback<TResult, TError>,\n e?: TArg4 | LegacyCallback<TResult, TError>\n ) => void,\n arg1?: TArg1,\n arg2?: TArg2,\n arg3?: TArg3,\n arg4?: TArg4\n ): Promise<TResult> {\n return new Promise((resolve: (result: TResult) => void, reject: (error: Error) => void) => {\n const cb: LegacyCallback<TResult, TError> = (error: TError | null | undefined, result: TResult) => {\n if (error) {\n reject(LegacyAdapters.scrubError(error));\n } else {\n resolve(result);\n }\n };\n\n try {\n if (arg1 !== undefined && arg2 !== undefined && arg3 !== undefined && arg4 !== undefined) {\n fn(arg1, arg2, arg3, arg4, cb);\n } else if (arg1 !== undefined && arg2 !== undefined && arg3 !== undefined) {\n fn(arg1, arg2, arg3, cb);\n } else if (arg1 !== undefined && arg2 !== undefined) {\n fn(arg1, arg2, cb);\n } else if (arg1 !== undefined) {\n fn(arg1, cb);\n } else {\n fn(cb);\n }\n } catch (e) {\n reject(e as Error);\n }\n });\n }\n\n /**\n * Normalizes an object into an `Error` object.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public static scrubError(error: Error | string | any): Error {\n if (error instanceof Error) {\n return error;\n } else if (typeof error === 'string') {\n return new Error(error);\n } else {\n const errorObject: Error = new Error('An error occurred.');\n (errorObject as any).errorData = error; // eslint-disable-line @typescript-eslint/no-explicit-any\n return errorObject;\n }\n }\n\n /**\n * Prior to Node 11.x, the `Array.sort()` algorithm is not guaranteed to be stable.\n * If you need a stable sort, you can use `sortStable()` as a workaround.\n *\n * @deprecated\n * Use native Array.sort(), since Node &lt; 14 is no longer supported\n * @remarks\n * On NodeJS 11.x and later, this method simply calls the native `Array.sort()`.\n */\n public static sortStable<T>(array: T[], compare?: (a: T, b: T) => number): void {\n Array.prototype.sort.call(array, compare);\n }\n}\n"]}