diff --git a/pkg/psync/package.json b/pkg/psync/package.json index 77d88e17..1292700a 100644 --- a/pkg/psync/package.json +++ b/pkg/psync/package.json @@ -38,7 +38,6 @@ "mnemonist": "^0.39.8", "murmurhash3js-revisited": "^3.0.0", "obliterator": "^2.0.4", - "p-defer": "^4.0.1", "pako": "^2.1.0", "tslib": "^2.8.1", "typescript-event-target": "^1.1.1" diff --git a/pkg/psync/src/psync/full.ts b/pkg/psync/src/psync/full.ts index 44716ebd..6e01a91b 100644 --- a/pkg/psync/src/psync/full.ts +++ b/pkg/psync/src/psync/full.ts @@ -3,7 +3,6 @@ import { GenericNumber } from "@ndn/naming-convention2"; import type { Component, Data, Interest, Name, Signer, Verifier } from "@ndn/packet"; import { type SyncNode, type SyncProtocol, SyncUpdate } from "@ndn/sync-api"; import { KeyMap, toHex, trackEventListener } from "@ndn/util"; -import pDefer, { type DeferredPromise } from "p-defer"; import { TypedEventTarget } from "typescript-event-target"; import { computeInterval, type IntervalFunc, type IntervalRange } from "../detail/interval"; @@ -17,7 +16,7 @@ interface PendingInterest { interest: Interest; recvIblt: IBLT; expire: NodeJS.Timeout | number; - defer: DeferredPromise; + defer: PromiseWithResolvers; } interface DebugEntry { @@ -175,7 +174,7 @@ export class FullSync extends TypedEventTarget implements SyncProtocol pending.defer.resolve(undefined); } }, interest.lifetime), - defer: pDefer(), + defer: Promise.withResolvers(), }; this.pPendings.set(ibltComp, pending); return pending.defer.promise; diff --git a/pkg/psync/src/psync/partial-publisher.ts b/pkg/psync/src/psync/partial-publisher.ts index f98669ad..c324e6af 100644 --- a/pkg/psync/src/psync/partial-publisher.ts +++ b/pkg/psync/src/psync/partial-publisher.ts @@ -4,7 +4,6 @@ import { Data, type Interest, type Name, NameMap, type Signer } from "@ndn/packe import type { SyncNode, SyncProtocol } from "@ndn/sync-api"; import { trackEventListener } from "@ndn/util"; import { BloomFilter } from "@yoursunny/psync-bloom"; -import pDefer, { type DeferredPromise } from "p-defer"; import { TypedEventTarget } from "typescript-event-target"; import type { IBLT } from "../iblt"; @@ -17,7 +16,7 @@ interface PendingInterest { recvIblt: IBLT; bloom: BloomFilter; expire: NodeJS.Timeout | number; - defer: DeferredPromise; + defer: PromiseWithResolvers; } interface DebugEntry { @@ -166,7 +165,7 @@ export class PartialPublisher extends TypedEventTarget implements Sync pending.defer.resolve(undefined); } }, interest.lifetime), - defer: pDefer(), + defer: Promise.withResolvers(), }; this.sPendings.set(interest.name, pending); return pending.defer.promise; diff --git a/pkg/psync/src/syncps/pubsub.ts b/pkg/psync/src/syncps/pubsub.ts index 2713fb49..8b0fce01 100644 --- a/pkg/psync/src/syncps/pubsub.ts +++ b/pkg/psync/src/syncps/pubsub.ts @@ -6,7 +6,6 @@ import { KeyMap, toHex, trackEventListener } from "@ndn/util"; import DefaultWeakMap from "mnemonist/default-weak-map.js"; import filter from "obliterator/filter.js"; import take from "obliterator/take.js"; -import pDefer, { type DeferredPromise } from "p-defer"; import { TypedEventTarget } from "typescript-event-target"; import { IBLT } from "../iblt"; @@ -30,7 +29,7 @@ interface SyncInterestInfo { interface PendingInterest extends SyncInterestInfo { expire: NodeJS.Timeout | number; - defer: DeferredPromise; + defer: PromiseWithResolvers; } interface DebugEntry { @@ -268,7 +267,7 @@ export class SyncpsPubsub extends TypedEventTarget implements Subscrib pending.defer.resolve(undefined); } }, interest.lifetime), - defer: pDefer(), + defer: Promise.withResolvers(), }; this.pPendings.set(ibltComp, pending); return pending.defer.promise; diff --git a/pkg/pyrepo/package.json b/pkg/pyrepo/package.json index b90c0f3d..2f7ec8d3 100644 --- a/pkg/pyrepo/package.json +++ b/pkg/pyrepo/package.json @@ -34,7 +34,6 @@ "@ndn/sync-api": "workspace:^", "@ndn/tlv": "workspace:*", "@ndn/util": "workspace:*", - "p-defer": "^4.0.1", "streaming-iterables": "^8.0.1", "tslib": "^2.8.1", "type-fest": "^4.30.0", diff --git a/pkg/pyrepo/src/store.ts b/pkg/pyrepo/src/store.ts index eba24a51..a7fb9692 100644 --- a/pkg/pyrepo/src/store.ts +++ b/pkg/pyrepo/src/store.ts @@ -2,7 +2,6 @@ import { produce, ProducerOptions } from "@ndn/endpoint"; import type { Name } from "@ndn/packet"; import { DataStore as S } from "@ndn/repo-api"; import { Closers, delay } from "@ndn/util"; -import pDefer from "p-defer"; import { collect } from "streaming-iterables"; import { PyRepoClient } from "./client"; @@ -67,7 +66,7 @@ export class PyRepoStore implements Disposable, S.Insert, S.Delete { const pkts = await collect(S.Insert.parseArgs<{}>(args).pkts); const retrieved = new Set(); - const answered = pDefer(); + const answered = Promise.withResolvers(); const timeout = setTimeout( () => answered.reject(new Error("no incoming Interest")), this.incomingInterestTimeout, diff --git a/pkg/repo-api/package.json b/pkg/repo-api/package.json index 40fe407e..11003f5a 100644 --- a/pkg/repo-api/package.json +++ b/pkg/repo-api/package.json @@ -34,7 +34,6 @@ "@ndn/tlv": "workspace:*", "@ndn/util": "workspace:*", "is-stream": "^4.0.1", - "p-defer": "^4.0.1", "p-event": "^6.0.1", "streaming-iterables": "^8.0.1", "tslib": "^2.8.1", diff --git a/pkg/repo-api/src/bulk-insert-initiator.ts b/pkg/repo-api/src/bulk-insert-initiator.ts index 9718f5bb..960fc587 100644 --- a/pkg/repo-api/src/bulk-insert-initiator.ts +++ b/pkg/repo-api/src/bulk-insert-initiator.ts @@ -2,7 +2,6 @@ import { Transport } from "@ndn/l3face"; import type { Data } from "@ndn/packet"; import { Encoder } from "@ndn/tlv"; import { pushable } from "@ndn/util"; -import pDefer, { type DeferredPromise } from "p-defer"; import { consume } from "streaming-iterables"; import { TypedEventTarget } from "typescript-event-target"; @@ -10,7 +9,7 @@ import * as S from "./data-store"; interface Burst { pkts: AsyncIterable; - defer: DeferredPromise; + defer: PromiseWithResolvers; } type EventMap = { @@ -69,7 +68,7 @@ export class BulkInsertInitiator extends TypedEventTarget implements S */ public async insert(...args: S.Insert.Args<{}>): Promise { const { pkts } = S.Insert.parseArgs<{}>(args); - const defer = pDefer(); + const defer = Promise.withResolvers(); this.queue.push({ pkts, defer }); return defer.promise; } diff --git a/pkg/segmented-object/package.json b/pkg/segmented-object/package.json index bfb3de3c..7f4a2fba 100644 --- a/pkg/segmented-object/package.json +++ b/pkg/segmented-object/package.json @@ -35,7 +35,6 @@ "it-keepalive": "^1.2.0", "mnemonist": "^0.39.8", "obliterator": "^2.0.4", - "p-defer": "^4.0.1", "p-lazy": "^5.0.0", "streaming-iterables": "^8.0.1", "tslib": "^2.8.1", diff --git a/pkg/segmented-object/src/serve/data-producer.ts b/pkg/segmented-object/src/serve/data-producer.ts index bb549c4a..7d5bd413 100644 --- a/pkg/segmented-object/src/serve/data-producer.ts +++ b/pkg/segmented-object/src/serve/data-producer.ts @@ -2,7 +2,6 @@ import type { ProducerHandler } from "@ndn/endpoint"; import { Data, digestSigning, type Interest, type Name, type Signer } from "@ndn/packet"; import { assert } from "@ndn/util"; import DefaultMap from "mnemonist/default-map.js"; -import pDefer, { type DeferredPromise } from "p-defer"; import { getIterator } from "streaming-iterables"; import { defaultSegmentConvention, type SegmentConvention } from "../convention"; @@ -84,9 +83,9 @@ class SequentialDataProducer extends DataProducer { private requested = -1; private final = Infinity; private readonly buffer = new Map(); - private readonly waitlist = new DefaultMap>(() => pDefer()); + private readonly waitlist = new DefaultMap>(() => Promise.withResolvers()); private readonly generator: AsyncGenerator; - private pause?: DeferredPromise; + private pause?: PromiseWithResolvers; constructor(source: ChunkSource, prefix: Name, opts: DataProducer.Options = {}) { super(source, prefix, opts); @@ -139,7 +138,7 @@ class SequentialDataProducer extends DataProducer { assert(chunk.i === i, "unexpected chunk number"); if (i > this.requested + bufferAhead) { - this.pause = pDefer(); + this.pause = Promise.withResolvers(); await this.pause.promise; this.pause = undefined; } diff --git a/pkg/svs/package.json b/pkg/svs/package.json index fc70662f..c82d33d2 100644 --- a/pkg/svs/package.json +++ b/pkg/svs/package.json @@ -44,7 +44,6 @@ "devDependencies": { "@ndn/keychain": "workspace:*", "@ndn/l3face": "workspace:*", - "mnemonist": "^0.39.8", - "p-defer": "^4.0.1" + "mnemonist": "^0.39.8" } } \ No newline at end of file diff --git a/pkg/svs/tests/svsps.t.ts b/pkg/svs/tests/svsps.t.ts index 44a3a021..0b3dcb81 100644 --- a/pkg/svs/tests/svsps.t.ts +++ b/pkg/svs/tests/svsps.t.ts @@ -5,7 +5,6 @@ import { generateSigningKey } from "@ndn/keychain"; import { Name, type NameLike } from "@ndn/packet"; import { DataArray } from "@ndn/repo-api"; import { Closers, console, crypto, delay } from "@ndn/util"; -import pDefer from "p-defer"; import { afterEach, beforeAll, expect, test, vi } from "vitest"; import { type MappingEntry, type Subscription, SvPublisher, SvSubscriber, SvSync, TimedMappingEntry } from ".."; @@ -66,7 +65,7 @@ async function publishCheck( const abort = new AbortController(); const received = Array.from({ length: expectReceive.length }); let nWaiting = expectReceive.length; - const allReceived = pDefer(); + const allReceived = Promise.withResolvers(); for (const [i, sub] of expectReceive.entries()) { sub.addEventListener("update", (update) => { // eslint-disable-line @typescript-eslint/no-loop-func expect(received[i]).toBeUndefined(); diff --git a/pkg/util/package.json b/pkg/util/package.json index 80509aba..63839f83 100644 --- a/pkg/util/package.json +++ b/pkg/util/package.json @@ -29,6 +29,7 @@ }, "dependencies": { "@shigen/polyfill-symbol-dispose": "^1.0.1", + "@ungap/with-resolvers": "^0.1.0", "event-iterator": "^2.0.0", "streaming-iterables": "^8.0.1", "tiny-invariant": "^1.3.3", diff --git a/pkg/util/src/polyfill_node.ts b/pkg/util/src/polyfill_node.ts index cb0ff5c3..8421e981 100644 --- a/pkg/util/src/polyfill_node.ts +++ b/pkg/util/src/polyfill_node.ts @@ -1 +1 @@ -export {}; +import "@ungap/with-resolvers"; // needed for Node 20.x diff --git a/xo.config.cjs b/xo.config.cjs index 75d42446..1076a832 100644 --- a/xo.config.cjs +++ b/xo.config.cjs @@ -37,7 +37,14 @@ function makePackageOverrides(config, ...pkgs) { /** @type {XoOptions} */ module.exports = { - ...js, + ...merge(js, { + rules: { + "n/no-unsupported-features/es-syntax": ["error", { + version: require("./package.json").engines.node, + ignores: ["promise-withresolvers"], + }], + }, + }), overrides: [ ...makePackageOverrides(merge(js, ts), ""), ...makePackageOverrides(merge(js, ts, web),