Odoo GraphQL Subscription using Node, Express JS for Sample
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
15 KiB

4 months ago
{"version":3,"file":"batch.cjs","sources":["batching.js","batchLink.js"],"sourcesContent":["import { __assign } from \"tslib\";\nimport { Observable } from \"../../utilities/index.js\";\n// QueryBatcher doesn't fire requests immediately. Requests that were enqueued within\n// a certain amount of time (configurable through `batchInterval`) will be batched together\n// into one query.\nvar OperationBatcher = /** @class */ (function () {\n function OperationBatcher(_a) {\n var batchDebounce = _a.batchDebounce, batchInterval = _a.batchInterval, batchMax = _a.batchMax, batchHandler = _a.batchHandler, batchKey = _a.batchKey;\n // Queue on which the QueryBatcher will operate on a per-tick basis.\n this.batchesByKey = new Map();\n this.scheduledBatchTimerByKey = new Map();\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval;\n this.batchMax = batchMax || 0;\n this.batchHandler = batchHandler;\n this.batchKey = batchKey || (function () { return \"\"; });\n }\n OperationBatcher.prototype.enqueueRequest = function (request) {\n var _this = this;\n var requestCopy = __assign(__assign({}, request), { next: [], error: [], complete: [], subscribers: new Set() });\n var key = this.batchKey(request.operation);\n if (!requestCopy.observable) {\n requestCopy.observable = new Observable(function (observer) {\n var batch = _this.batchesByKey.get(key);\n if (!batch)\n _this.batchesByKey.set(key, (batch = new Set()));\n // These booleans seem to me (@benjamn) like they might always be the\n // same (and thus we could do with only one of them), but I'm not 100%\n // sure about that.\n var isFirstEnqueuedRequest = batch.size === 0;\n var isFirstSubscriber = requestCopy.subscribers.size === 0;\n requestCopy.subscribers.add(observer);\n if (isFirstSubscriber) {\n batch.add(requestCopy);\n }\n // called for each subscriber, so need to save all listeners (next, error, complete)\n if (observer.next) {\n requestCopy.next.push(observer.next.bind(observer));\n }\n if (observer.error) {\n requestCopy.error.push(observer.error.bind(observer));\n }\n if (observer.complete) {\n requestCopy.complete.push(observer.complete.bind(observer));\n }\n // The first enqueued request triggers the queue consumption after `batchInterval` milliseconds.\n if (isFirstEnqueuedRequest || _this.batchDebounce) {\n _this.scheduleQueueConsumption(key);\n }\n // When amount of requests reaches `batchMax`, trigger the queue consumption without waiting on the `batchInterval`.\n if (batch.size === _this.batchMax) {\n _this.consumeQueue(key);\n }\n return function () {\n var _a;\n // If this is last subscriber for this request, remove request from queue\n if (requestCopy.subscribers.delete(observer) &&\n requestCopy.subscribers.size < 1) {\n // If this is last request from queue, remove queue entirely\n if (batch.delete(requestCopy) && batch.size < 1) {\n _this.consumeQueue(key);\n // If queue was in flight, cancel it\n (_a = batch.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();\n }\n }\n };\n });\n }\n return requestCopy.observable;\n };\n // Consumes the queue.\n // Returns a list of promises (one for each query).\n OperationBatcher.prototype.consume