{"version":3,"sources":["jsdelivr-header.js","/npm/promises-delivery@1.1.0/dist/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OCNS,cAAe,sBAAyB,qBAC1C,MAAM,gBAAmB,GACrB,cAAc,GAAG,UAEnB,cAAe,mBACxB,MAAM,SACF,SAAW,CAAC,EACZ,QACA,WAAA,CAAY,GACJ,GAAW,EAAQ,UACnB,KAAK,QAAU,EAAQ,QAE/B,CAUA,QAAA,CAAS,EAAK,GACV,GAAI,KAAK,SAAS,GACd,MAAM,IAAI,cAAc,kBAAkB,yBAA0B,qBAAqB,2BAE7F,IAAI,EACA,EACA,EACJ,MAAM,EAAU,IAAI,SAAQ,CAAC,EAAS,KAClC,EAAiB,EACjB,EAAgB,EAChB,MAAM,EAAe,GAAS,SAAW,KAAK,QAC1C,IACA,EAAY,YAAW,KACnB,EAAO,IAAI,cAAc,kBAAkB,QAAS,qBAAqB,qBAAuB,eACzF,KAAK,SAAS,EAAI,GAC1B,GACP,IAEE,EAAQ,CACV,UACA,QAAS,EACT,OAAQ,GAIZ,OAFA,EAAQ,SAAQ,IAAM,aAAa,KACnC,KAAK,SAAS,GAAO,EACd,CACX,CASA,OAAA,CAAQ,EAAK,GACT,IAAK,KAAK,SAAS,GACf,MAAM,IAAI,cAAc,kBAAkB,gBAAiB,qBAAqB,kBAEpF,KAAK,SAAS,GAAK,QAAQ,UACpB,KAAK,SAAS,EACzB,CASA,MAAA,CAAO,EAAK,GACR,IAAK,KAAK,SAAS,GACf,MAAM,IAAI,cAAc,kBAAkB,gBAAiB,qBAAqB,kBAEpF,KAAK,SAAS,GAAK,OAAO,UACnB,KAAK,SAAS,EACzB,CAOA,UAAA,CAAW,GACP,OAAO,KAAK,SAAS,IAAM,OAC/B,iBAEW","file":"/npm/promises-delivery@1.1.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/promises-delivery@1.1.0/dist/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","import { DeliveryError, DeliveryErrorCode } from './errors.js';\nexport const isDeliveryError = (error) => {\n    return DeliveryError.is(error);\n};\nexport { DeliveryError, DeliveryErrorCode };\nclass Delivery {\n    promises = {};\n    timeout;\n    constructor(options) {\n        if (options && options.timeout) {\n            this.timeout = options.timeout;\n        }\n    }\n    /**\n     * Registers a new promise with the given key.\n     *\n     * @param key - The unique identifier for the promise to be registered.\n     * @param options - Optional configuration for this specific promise.\n     * @param options.timeout - Override default timeout for this promise.\n     * @throws Will throw an error if a promise with the given key is already registered.\n     * @returns A Promise<T> that can be used to handle the asynchronous operation.\n     */\n    register(key, options) {\n        if (this.promises[key]) {\n            throw new DeliveryError(DeliveryErrorCode.PromiseAlreadyRegistered, `Promise with Key: ${key} is already registered`);\n        }\n        let timeoutId;\n        let resolvePromise;\n        let rejectPromise;\n        const promise = new Promise((resolve, reject) => {\n            resolvePromise = resolve;\n            rejectPromise = reject;\n            const timeoutValue = options?.timeout ?? this.timeout;\n            if (timeoutValue) {\n                timeoutId = setTimeout(() => {\n                    reject(new DeliveryError(DeliveryErrorCode.Timeout, `Promise with Key: ${key} timed out after ${timeoutValue}ms`));\n                    delete this.promises[key];\n                }, timeoutValue);\n            }\n        });\n        const state = {\n            promise,\n            resolve: resolvePromise,\n            reject: rejectPromise,\n        };\n        promise.finally(() => clearTimeout(timeoutId));\n        this.promises[key] = state;\n        return promise;\n    }\n    /**\n     * Resolves the promise associated with the given key.\n     *\n     * @param key - The unique identifier for the promise to be resolved.\n     * @param value - The value to resolve the promise with.\n     * @throws Will throw an error if a promise with the given key is not found.\n     * @returns {void}\n     */\n    resolve(key, value) {\n        if (!this.promises[key]) {\n            throw new DeliveryError(DeliveryErrorCode.PromiseNotFound, `Promise with Key: ${key} is not found`);\n        }\n        this.promises[key].resolve(value);\n        delete this.promises[key];\n    }\n    /**\n     * Rejects the promise associated with the given key with the provided reason.\n     *\n     * @param key - The unique identifier for the promise to be rejected.\n     * @param reason - The reason for rejecting the promise.\n     * @throws Will throw an error if a promise with the given key is not found.\n     * @returns {void}\n     */\n    reject(key, reason) {\n        if (!this.promises[key]) {\n            throw new DeliveryError(DeliveryErrorCode.PromiseNotFound, `Promise with Key: ${key} is not found`);\n        }\n        this.promises[key].reject(reason);\n        delete this.promises[key];\n    }\n    /**\n     * Retrieves the promise associated with the given key.\n     *\n     * @param key - The unique identifier of the promise to be retrieved.\n     * @returns The promise associated with the given key if it exists, otherwise undefined.\n     */\n    getPromise(key) {\n        return this.promises[key]?.promise;\n    }\n}\nexport default Delivery;\n"]}