{"version":3,"file":"cancellation.mjs","sources":["../../../../src/runtime/internals/cancellation.ts"],"sourcesContent":["/**\n * A map of cancellable promise \"extensions\".\n *\n * Each entry value must either be a directly `cancel()`-able promise, or must\n * refer to another entry.\n *\n * When cancellation of a promise is requested, cancel\n * will check to see if the promise exists in the map. If it does, it pulls\n * the value and repeats the check. If not, it will perform the underlying\n * cancel operation.\n */\nconst promiseMap = new WeakMap();\nexport function extendCancellability(existingCancellablePromise, newPromiseToRegister) {\n    promiseMap.set(newPromiseToRegister, existingCancellablePromise);\n    return existingCancellablePromise.finally(() => {\n        promiseMap.delete(newPromiseToRegister);\n    });\n}\n/**\n * Wraps the existing `cancel()` method with logic to iteratively search for\n * the corresponding base level promise, if needed, that the core graphql client\n * knows how to cancel.\n *\n * @param client\n */\nexport function upgradeClientCancellation(client) {\n    const innerCancel = client.cancel.bind(client);\n    client.cancel = function (promise, message) {\n        const visited = new Set();\n        let targetPromise = promise;\n        while (targetPromise && promiseMap.has(targetPromise)) {\n            if (visited.has(targetPromise))\n                throw new Error('A cycle was detected in the modeled graphql cancellation chain. This is a bug. Please report it!');\n            visited.add(targetPromise);\n            targetPromise = promiseMap.get(targetPromise);\n        }\n        // call `innerCancel` with `targetPromise!` to defer to existing implementation\n        // on how to handle `null | undefined` or otherwise \"non-cancellable\" objects.\n        return innerCancel(targetPromise, message);\n    };\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,UAAU,GAAG,IAAI,OAAO,EAAE;AACzB,SAAS,oBAAoB,CAAC,0BAA0B,EAAE,oBAAoB,EAAE;AACvF,IAAI,UAAU,CAAC,GAAG,CAAC,oBAAoB,EAAE,0BAA0B,CAAC;AACpE,IAAI,OAAO,0BAA0B,CAAC,OAAO,CAAC,MAAM;AACpD,QAAQ,UAAU,CAAC,MAAM,CAAC,oBAAoB,CAAC;AAC/C,IAAI,CAAC,CAAC;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,yBAAyB,CAAC,MAAM,EAAE;AAClD,IAAI,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;AAClD,IAAI,MAAM,CAAC,MAAM,GAAG,UAAU,OAAO,EAAE,OAAO,EAAE;AAChD,QAAQ,MAAM,OAAO,GAAG,IAAI,GAAG,EAAE;AACjC,QAAQ,IAAI,aAAa,GAAG,OAAO;AACnC,QAAQ,OAAO,aAAa,IAAI,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;AAC/D,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAC1C,gBAAgB,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC;AACnI,YAAY,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AACtC,YAAY,aAAa,GAAG,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC;AACzD,QAAQ;AACR;AACA;AACA,QAAQ,OAAO,WAAW,CAAC,aAAa,EAAE,OAAO,CAAC;AAClD,IAAI,CAAC;AACL;;;;"}