diff --git a/package.json b/package.json index 6b81392..c8ac649 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ibm-generative-ai/node-sdk", - "version": "2.0.3", + "version": "2.0.4", "description": "IBM Generative AI Node.js SDK (Tech Preview)", "keywords": [ "ai", @@ -88,7 +88,7 @@ "prettier": "^3.0.3", "ts-node": "^10.9.1", "tsup": "^8.0.2", - "typescript": "^5.3.3", + "typescript": "^5.4.3", "vitest": "^0.34.6" }, "dependencies": { @@ -96,7 +96,7 @@ "fetch-retry": "^5.0.6", "http-status-codes": "^2.3.0", "openapi-fetch": "^0.8.2", - "p-queue": "^8.0.1", + "p-queue-compat": "^1.0.225", "yaml": "^2.3.3" }, "lint-staged": { diff --git a/src/errors.ts b/src/errors.ts index bf47890..5aa3706 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,3 +1,5 @@ +import { AbortError } from 'p-queue-compat'; + import { ApiError } from './api/client.js'; export class BaseError extends Error {} diff --git a/src/utils/concurrency.ts b/src/utils/concurrency.ts index 8ecb52f..c6772a3 100644 --- a/src/utils/concurrency.ts +++ b/src/utils/concurrency.ts @@ -1,4 +1,4 @@ -import type { default as PQueueType, QueueAddOptions } from 'p-queue'; +import PQueue, { QueueAddOptions } from 'p-queue-compat'; import { HttpError } from '../errors.js'; @@ -11,13 +11,8 @@ function isConcurrencyLimitError(err: unknown): err is HttpError { ); } -const PQueue = (async () => { - const lib = await import('p-queue'); - return lib.default; -})(); - export class ConcurrencyLimiter { - private _queue?: PQueueType; + private _queue?: PQueue; private _limiterPromise?: ReturnType; constructor(private readonly limiter: Limiter) {} @@ -47,6 +42,6 @@ export class ConcurrencyLimiter { this._limiterPromise = this.limiter(); const { limit } = await this._limiterPromise; - this._queue = new (await PQueue)({ concurrency: limit }); + this._queue = new PQueue({ concurrency: limit }); } } diff --git a/src/utils/errors.ts b/src/utils/errors.ts index 43a7291..043435e 100644 --- a/src/utils/errors.ts +++ b/src/utils/errors.ts @@ -1,4 +1,6 @@ import { FetchResponse } from 'openapi-fetch'; +import { AbortError } from 'p-queue-compat'; +AbortError.prototype.name = 'AbortError'; import { HttpError, InternalError, NetworkError } from '../errors.js'; diff --git a/yarn.lock b/yarn.lock index 1ad538f..916f058 100644 --- a/yarn.lock +++ b/yarn.lock @@ -695,12 +695,12 @@ __metadata: msw: ^1.3.2 openapi-fetch: ^0.8.2 openapi-typescript: ^6.7.4 - p-queue: ^8.0.1 + p-queue-compat: ^1.0.225 pinst: ^3.0.0 prettier: ^3.0.3 ts-node: ^10.9.1 tsup: ^8.0.2 - typescript: ^5.3.3 + typescript: ^5.4.3 vitest: ^0.34.6 yaml: ^2.3.3 peerDependencies: @@ -3046,6 +3046,13 @@ __metadata: languageName: node linkType: hard +"eventemitter3@npm:5.x, eventemitter3@npm:^5.0.1": + version: 5.0.1 + resolution: "eventemitter3@npm:5.0.1" + checksum: 543d6c858ab699303c3c32e0f0f47fc64d360bf73c3daf0ac0b5079710e340d6fe9f15487f94e66c629f5f82cd1a8678d692f3dbb6f6fcd1190e1b97fcad36f8 + languageName: node + linkType: hard + "eventemitter3@npm:^4.0.4": version: 4.0.7 resolution: "eventemitter3@npm:4.0.7" @@ -3053,13 +3060,6 @@ __metadata: languageName: node linkType: hard -"eventemitter3@npm:^5.0.1": - version: 5.0.1 - resolution: "eventemitter3@npm:5.0.1" - checksum: 543d6c858ab699303c3c32e0f0f47fc64d360bf73c3daf0ac0b5079710e340d6fe9f15487f94e66c629f5f82cd1a8678d692f3dbb6f6fcd1190e1b97fcad36f8 - languageName: node - linkType: hard - "events@npm:^3.3.0": version: 3.3.0 resolution: "events@npm:3.3.0" @@ -5424,6 +5424,16 @@ __metadata: languageName: node linkType: hard +"p-queue-compat@npm:^1.0.225": + version: 1.0.225 + resolution: "p-queue-compat@npm:1.0.225" + dependencies: + eventemitter3: 5.x + p-timeout-compat: ^1.0.3 + checksum: dc35ea412ff7ba8a7ecd2057d8fd94d5efe0e75769bbc18894614b42c23cdc65d2a1e6bb92476a695b3acdaaf47dc8b7c97587cc55326a1fd06622fc11235c5e + languageName: node + linkType: hard + "p-queue@npm:^6.6.2": version: 6.6.2 resolution: "p-queue@npm:6.6.2" @@ -5434,16 +5444,6 @@ __metadata: languageName: node linkType: hard -"p-queue@npm:^8.0.1": - version: 8.0.1 - resolution: "p-queue@npm:8.0.1" - dependencies: - eventemitter3: ^5.0.1 - p-timeout: ^6.1.2 - checksum: 84a27a5b1faf2dcc96b8c0e423c34b5984b241acc07353d3cc6d8d3d1dadefb250b4ec84ce278cb1c946466999c6bf2a36ff718a75810bad8e11c7ca47ce80f5 - languageName: node - linkType: hard - "p-retry@npm:4": version: 4.6.2 resolution: "p-retry@npm:4.6.2" @@ -5454,6 +5454,13 @@ __metadata: languageName: node linkType: hard +"p-timeout-compat@npm:^1.0.3": + version: 1.0.4 + resolution: "p-timeout-compat@npm:1.0.4" + checksum: c55421977a2b73a7419ebb437dc16690bbf0eb99ce688d7f23749093c0c5b4ce08a5236b3d83483dacce594fb98c111d36bc3916e2463ef78e7a339bf0e95d5a + languageName: node + linkType: hard + "p-timeout@npm:^3.2.0": version: 3.2.0 resolution: "p-timeout@npm:3.2.0" @@ -5463,13 +5470,6 @@ __metadata: languageName: node linkType: hard -"p-timeout@npm:^6.1.2": - version: 6.1.2 - resolution: "p-timeout@npm:6.1.2" - checksum: 887b805eb72c217dbc3c55a60a7f3b89a46cab14f04af62224f253ec84716cbd0880758be13b35444a4fa12d64d37d4c8a300f0b12a57c004d289f0a574cfe91 - languageName: node - linkType: hard - "p-try@npm:^2.0.0": version: 2.2.0 resolution: "p-try@npm:2.2.0" @@ -6964,13 +6964,13 @@ __metadata: languageName: node linkType: hard -"typescript@npm:^5.3.3": - version: 5.3.3 - resolution: "typescript@npm:5.3.3" +"typescript@npm:^5.4.3": + version: 5.4.3 + resolution: "typescript@npm:5.4.3" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 2007ccb6e51bbbf6fde0a78099efe04dc1c3dfbdff04ca3b6a8bc717991862b39fd6126c0c3ebf2d2d98ac5e960bcaa873826bb2bb241f14277034148f41f6a2 + checksum: d74d731527e35e64d8d2dcf2f897cf8cfbc3428be0ad7c48434218ba4ae41239f53be7c90714089db1068c05cae22436af2ecba71fd36ecc5e7a9118af060198 languageName: node linkType: hard @@ -6984,13 +6984,13 @@ __metadata: languageName: node linkType: hard -"typescript@patch:typescript@^5.3.3#~builtin": - version: 5.3.3 - resolution: "typescript@patch:typescript@npm%3A5.3.3#~builtin::version=5.3.3&hash=85af82" +"typescript@patch:typescript@^5.4.3#~builtin": + version: 5.4.3 + resolution: "typescript@patch:typescript@npm%3A5.4.3#~builtin::version=5.4.3&hash=85af82" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: f61375590b3162599f0f0d5b8737877ac0a7bc52761dbb585d67e7b8753a3a4c42d9a554c4cc929f591ffcf3a2b0602f65ae3ce74714fd5652623a816862b610 + checksum: 3a62fe90aa79d68c9ce38ea5edb2957e62801c733b99f0e5a2b8b50922761f68f7d9a40d28c544b449866e81185cddb93cba2496d0ff3fa52ef5b1f8bcace38c languageName: node linkType: hard