From a75923984616f8f70fe68acc4bceca0d649deb23 Mon Sep 17 00:00:00 2001 From: Henry Tsai Date: Fri, 5 Jul 2024 17:23:47 -0700 Subject: [PATCH] Used Poller from dwn-sdk-js --- package-lock.json | 8 ++--- package.json | 2 +- tests/poller.ts | 46 ---------------------------- tests/process-handler.spec.ts | 8 ++--- tests/scenarios/web5-connect.spec.ts | 2 +- 5 files changed, 10 insertions(+), 56 deletions(-) delete mode 100644 tests/poller.ts diff --git a/package-lock.json b/package-lock.json index 15aaffc..1c2e835 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "@web5/dwn-server", "version": "0.4.1", "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.4.0", + "@tbd54566975/dwn-sdk-js": "0.4.2", "@tbd54566975/dwn-sql-store": "0.6.1", "better-sqlite3": "^8.5.0", "body-parser": "^1.20.2", @@ -605,9 +605,9 @@ "dev": true }, "node_modules/@tbd54566975/dwn-sdk-js": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.4.0.tgz", - "integrity": "sha512-eBDjIZQEsxAagKwDbHKzML00/jXlnRN9FLnV9Qx/4UkxZdKRM7IXghFnTRE7aYkwQS8nveAVcijBw46ARSPKcw==", + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.4.2.tgz", + "integrity": "sha512-ABwu6RMHDtTcRbI+b9AyqC3l7Hf50TJhbBaCMax9o/IV7KtM0RyMMBka5M7eGzQyHgWISykdUGW59yhe7/Z5Ig==", "dependencies": { "@ipld/dag-cbor": "9.0.3", "@js-temporal/polyfill": "0.4.4", diff --git a/package.json b/package.json index 853469d..d6990b2 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "url": "https://github.com/TBD54566975/dwn-server/issues" }, "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.4.0", + "@tbd54566975/dwn-sdk-js": "0.4.2", "@tbd54566975/dwn-sql-store": "0.6.1", "better-sqlite3": "^8.5.0", "body-parser": "^1.20.2", diff --git a/tests/poller.ts b/tests/poller.ts deleted file mode 100644 index cddee74..0000000 --- a/tests/poller.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Time } from '@tbd54566975/dwn-sdk-js'; - -export class Poller { - - /** - * The interval in milliseconds to wait before retrying the delegate function. - */ - static pollRetrySleep: number = 20; - - /** - * The maximum time in milliseconds to wait before timing out the delegate function. - */ - static pollTimeout: number = 2000; - - /** - * Polls the delegate function until it succeeds or the timeout is exceeded. - * - * @param delegate a function that returns a promise and may throw. - * @param retrySleep the interval in milliseconds to wait before retrying the delegate function. - * @param timeout the maximum time in milliseconds to wait before timing out the delegate function. - * - * @throws {Error} `Operation timed out` if the timeout is exceeded. - */ - static async pollUntilSuccessOrTimeout( - delegate: () => Promise, - retrySleep: number = Poller.pollRetrySleep, - timeout: number = Poller.pollTimeout, - ): Promise { - const startTime = Date.now(); - - while (true) { - try { - // Attempt to execute the delegate function - return await delegate(); - } catch (error) { - // Check if the timeout has been exceeded - if (Date.now() - startTime >= timeout) { - throw new Error('Operation timed out'); - } - - // Sleep for the retry interval before attempting again - await Time.sleep(retrySleep); - } - } - } -} \ No newline at end of file diff --git a/tests/process-handler.spec.ts b/tests/process-handler.spec.ts index 708c8fb..082c87c 100644 --- a/tests/process-handler.spec.ts +++ b/tests/process-handler.spec.ts @@ -1,11 +1,11 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; +import type { Dwn } from '@tbd54566975/dwn-sdk-js'; +import sinon from 'sinon'; import { config } from '../src/config.js'; -import type { Dwn } from '@tbd54566975/dwn-sdk-js'; import { DwnServer } from '../src/dwn-server.js'; +import { expect } from 'chai'; import { getTestDwn } from './test-dwn.js'; -import { Poller } from './poller.js'; +import { Poller } from '@tbd54566975/dwn-sdk-js'; describe('Process Handlers', function () { let dwn: Dwn; diff --git a/tests/scenarios/web5-connect.spec.ts b/tests/scenarios/web5-connect.spec.ts index f3243c6..6199048 100644 --- a/tests/scenarios/web5-connect.spec.ts +++ b/tests/scenarios/web5-connect.spec.ts @@ -3,10 +3,10 @@ import sinon from 'sinon'; import { config } from '../../src/config.js'; import { DwnServer } from '../../src/dwn-server.js'; import { expect } from 'chai'; +import { Poller } from '@tbd54566975/dwn-sdk-js'; import { useFakeTimers } from 'sinon'; import { Web5ConnectServer } from '../../src/web5-connect/web5-connect-server.js'; import { randomUUID, webcrypto } from 'node:crypto'; -import { Poller } from '../poller.js'; // node.js 18 and earlier needs globalThis.crypto polyfill if (!globalThis.crypto) {