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AAU,gBAAgB,KAAK,QAAS,EACtD,CACA,oBAAA,CAAqB,GACjB,GAAI,KAAK,UAAU,SAAS,OAAS,EAEjC,OAEJ,QAAQ,MAAM,kDAAmD,OAAQ,QAAQ,IAAK,KAAK,YAAY,KAAM,EAAI,KAAM,EAAI,QAAS,EAAI,OAGxI,MAAM,EAAY,GAClB,IAAK,MAAM,KAAO,EACF,SAAR,GAA0B,YAAR,GAGtB,EAAU,KAAK,YAAY,QAAQ,OAAO,WAAY,EAAK,EAAI,KAE/D,EAAU,QACV,QAAQ,MAAM,uBAAwB,EAAU,KAAK,OAEzD,QAAQ,OACZ,CACA,WAAM,GACF,GAAI,MAAK,EACL,OAEJ,MAAK,GAAU,EACf,MAAM,EAAc,QAAQ,IAAI,KAAM,UACtC,GAA2B,mBAAhB,EAGX,UACU,EAAY,MAAM,KAC5B,CACA,MAAO,GACH,KAAK,KAAK,QAAS,EACvB,CACJ,CACA,YAAI,GACA,OAAO,MAAK,CAChB,EAEJ,QAAQ,KAAO","file":"/npm/sdk-base@5.0.1/dist/commonjs/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/sdk-base@5.0.1/dist/commonjs/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Base = void 0;\nconst node_util_1 = __importDefault(require(\"node:util\"));\nconst node_assert_1 = __importDefault(require(\"node:assert\"));\nconst node_events_1 = require(\"node:events\");\nconst gals_1 = require(\"gals\");\nconst get_ready_1 = require(\"get-ready\");\nconst is_type_of_1 = require(\"is-type-of\");\nconst utility_1 = require(\"utility\");\nclass Base extends get_ready_1.ReadyEventEmitter {\n    options;\n    #closed = false;\n    #localStorage;\n    constructor(options) {\n        super();\n        if (options?.initMethod) {\n            const initMethod = Reflect.get(this, options.initMethod);\n            (0, node_assert_1.default)(typeof initMethod === 'function', `[sdk-base] this.${options.initMethod} should be a function`);\n            (0, node_assert_1.default)(!(0, is_type_of_1.isGeneratorFunction)(initMethod), `[sdk-base] this.${options.initMethod} should not be generator function`);\n            process.nextTick(() => {\n                const ret = initMethod.apply(this);\n                (0, node_assert_1.default)((0, is_type_of_1.isPromise)(ret), `[sdk-base] this.${options.initMethod} should return a promise`);\n                ret.then(() => {\n                    this.ready(true);\n                }).catch(err => {\n                    const hasReadyCallbacks = this.hasReadyCallbacks;\n                    this.ready(err);\n                    // no ready callbacks, should emit error event instead\n                    if (!hasReadyCallbacks) {\n                        this.emit('error', err);\n                    }\n                });\n            });\n        }\n        this.options = options ?? {};\n        this.#localStorage = this.options.localStorage ?? (0, gals_1.getAsyncLocalStorage)();\n        super.on('error', err => {\n            this._defaultErrorHandler(err);\n        });\n    }\n    /**\n     * support `await this.await('event')`\n     */\n    async await(event) {\n        const values = await (0, node_events_1.once)(this, event);\n        return values[0];\n    }\n    /**\n     * get AsyncLocalStorage from options\n     * @return {AsyncLocalStorage} asyncLocalStorage instance or undefined\n     */\n    get localStorage() {\n        return this.#localStorage;\n    }\n    async readyOrTimeout(milliseconds) {\n        await (0, utility_1.promiseTimeout)(this.ready(), milliseconds);\n    }\n    _defaultErrorHandler(err) {\n        if (this.listeners('error').length > 1) {\n            // ignore defaultErrorHandler\n            return;\n        }\n        console.error('\\n[%s][pid: %s][%s] %s: %s \\nError Stack:\\n  %s', Date(), process.pid, this.constructor.name, err.name, err.message, err.stack);\n        // try to show addition property on the error object\n        // e.g.: `err.data = {url: '/foo'};`\n        const additions = [];\n        for (const key in err) {\n            if (key === 'name' || key === 'message') {\n                continue;\n            }\n            additions.push(node_util_1.default.format('  %s: %j', key, err[key]));\n        }\n        if (additions.length) {\n            console.error('Error Additions:\\n%s', additions.join('\\n'));\n        }\n        console.error();\n    }\n    async close() {\n        if (this.#closed) {\n            return;\n        }\n        this.#closed = true;\n        const closeMethod = Reflect.get(this, '_close');\n        if (typeof closeMethod !== 'function') {\n            return;\n        }\n        try {\n            await closeMethod.apply(this);\n        }\n        catch (err) {\n            this.emit('error', err);\n        }\n    }\n    get isClosed() {\n        return this.#closed;\n    }\n}\nexports.Base = Base;\n"]}