From 4eb860a08bebf228ea72fd43fd7205a62eb3e1bc Mon Sep 17 00:00:00 2001 From: Henry Tsai Date: Tue, 18 Jun 2024 14:52:43 -0700 Subject: [PATCH] Upgraded dwn-sdk-js dependency to support Resumable Task Store (#135) --- package-lock.json | 32 ++++++++++++++++---------------- package.json | 4 ++-- src/storage.ts | 28 ++++++++++++++++++++-------- tests/test-dwn.ts | 3 +++ 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index a4c8e6e..806faca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,8 +8,8 @@ "name": "@web5/dwn-server", "version": "0.2.3", "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.3.5", - "@tbd54566975/dwn-sql-store": "0.4.5", + "@tbd54566975/dwn-sdk-js": "0.3.7", + "@tbd54566975/dwn-sql-store": "0.5.1", "better-sqlite3": "^8.5.0", "body-parser": "^1.20.2", "bytes": "3.1.2", @@ -600,9 +600,9 @@ "dev": true }, "node_modules/@tbd54566975/dwn-sdk-js": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.3.5.tgz", - "integrity": "sha512-1OZFxZSSpMpA186wqPOMbvhE7GJAZ5agVjGusC2KF2FQ4HxM26nlW6ZVigYVnfN/ddrrrey3t3hE7BiGQ9m2yg==", + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.3.7.tgz", + "integrity": "sha512-+icacanMCX1KhpS+2k4B+akzg23ayyGPGb8IbDxxUxqBKqEJGNNNY01JBHcq+PPPeDPTPg0ZZUoSpkdYTvOo4g==", "dependencies": { "@ipld/dag-cbor": "9.0.3", "@js-temporal/polyfill": "0.4.4", @@ -666,12 +666,12 @@ } }, "node_modules/@tbd54566975/dwn-sql-store": { - "version": "0.4.5", - "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sql-store/-/dwn-sql-store-0.4.5.tgz", - "integrity": "sha512-e0m6zs5JRXzz5maRqrP6XxkdWSIqCd8F4OHZZ9liWUms6fkQA04Tfb9pwVDW/CzvbV5ld91goHtNHwJc6gSRFQ==", + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sql-store/-/dwn-sql-store-0.5.1.tgz", + "integrity": "sha512-CRTyPVtgwtHdVa5osQQ/C2DmeMqM1S2YhYnqYIrnk+6uNZvQj1kG79VPP7Kmx75hRs57BLnpaFtbWU62oWi12A==", "dependencies": { - "@ipld/dag-cbor": "^9.0.5", - "@tbd54566975/dwn-sdk-js": "0.3.5", + "@ipld/dag-cbor": "9.0.5", + "@tbd54566975/dwn-sdk-js": "0.3.7", "kysely": "0.26.3", "multiformats": "12.0.1", "readable-stream": "4.4.2" @@ -681,9 +681,9 @@ } }, "node_modules/@tbd54566975/dwn-sql-store/node_modules/@ipld/dag-cbor": { - "version": "9.0.6", - "resolved": "https://registry.npmjs.org/@ipld/dag-cbor/-/dag-cbor-9.0.6.tgz", - "integrity": "sha512-3kNab5xMppgWw6DVYx2BzmFq8t7I56AGWfp5kaU1fIPkwHVpBRglJJTYsGtbVluCi/s/q97HZM3bC+aDW4sxbQ==", + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/@ipld/dag-cbor/-/dag-cbor-9.0.5.tgz", + "integrity": "sha512-TyqgtxEojc98rvxg4NGM+73JzQeM4+tK2VQes/in2mdyhO+1wbGuBijh1tvi9BErQ/dEblxs9v4vEQSX8mFCIw==", "dependencies": { "cborg": "^4.0.0", "multiformats": "^12.0.1" @@ -694,9 +694,9 @@ } }, "node_modules/@tbd54566975/dwn-sql-store/node_modules/cborg": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/cborg/-/cborg-4.0.5.tgz", - "integrity": "sha512-q8TAjprr8pn9Fp53rOIGp/UFDdFY6os2Nq62YogPSIzczJD9M6g2b6igxMkpCiZZKJ0kn/KzDLDvG+EqBIEeCg==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/cborg/-/cborg-4.2.1.tgz", + "integrity": "sha512-LSdnRagOTx1QZ3/ECLEOMc5fYHaDBjjQkBeBGtZ9KkGa78Opb5UzUxJeuxhmYTZm1DUzdBjj9JT3fcQNRL9ZBg==", "bin": { "cborg": "lib/bin.js" } diff --git a/package.json b/package.json index e2960ec..7492c48 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "url": "https://github.com/TBD54566975/dwn-server/issues" }, "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.3.5", - "@tbd54566975/dwn-sql-store": "0.4.5", + "@tbd54566975/dwn-sdk-js": "0.3.7", + "@tbd54566975/dwn-sql-store": "0.5.1", "better-sqlite3": "^8.5.0", "body-parser": "^1.20.2", "bytes": "3.1.2", diff --git a/src/storage.ts b/src/storage.ts index a4eea8c..b5dfba8 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -4,6 +4,7 @@ import { DataStoreLevel, EventLogLevel, MessageStoreLevel, + ResumableTaskStoreLevel, } from '@tbd54566975/dwn-sdk-js'; import type { DataStore, @@ -11,6 +12,7 @@ import type { EventLog, EventStream, MessageStore, + ResumableTaskStore, TenantGate, } from '@tbd54566975/dwn-sdk-js'; import type { Dialect } from '@tbd54566975/dwn-sql-store'; @@ -20,6 +22,7 @@ import { MessageStoreSql, MysqlDialect, PostgresDialect, + ResumableTaskStoreSql, SqliteDialect, } from '@tbd54566975/dwn-sql-store'; @@ -34,6 +37,7 @@ export enum EStoreType { DataStore, MessageStore, EventLog, + ResumableTaskStore, } export enum BackendTypes { @@ -43,7 +47,7 @@ export enum BackendTypes { POSTGRES = 'postgres', } -export type StoreType = DataStore | EventLog | MessageStore; +export type StoreType = DataStore | EventLog | MessageStore | ResumableTaskStore; export function getDWNConfig( config : DwnServerConfig, @@ -55,18 +59,16 @@ export function getDWNConfig( const { tenantGate, eventStream } = options; const dataStore: DataStore = getStore(config.dataStore, EStoreType.DataStore); const eventLog: EventLog = getStore(config.eventLog, EStoreType.EventLog); - const messageStore: MessageStore = getStore( - config.messageStore, - EStoreType.MessageStore, - ); + const messageStore: MessageStore = getStore(config.messageStore, EStoreType.MessageStore); + const resumableTaskStore: ResumableTaskStore = getStore(config.messageStore, EStoreType.ResumableTaskStore); - return { eventStream, eventLog, dataStore, messageStore, tenantGate }; + return { eventStream, eventLog, dataStore, messageStore, resumableTaskStore, tenantGate }; } function getLevelStore( storeURI: URL, storeType: EStoreType, -): DataStore | MessageStore | EventLog { +): DataStore | MessageStore | EventLog | ResumableTaskStore { switch (storeType) { case EStoreType.DataStore: return new DataStoreLevel({ @@ -81,6 +83,10 @@ function getLevelStore( return new EventLogLevel({ location: storeURI.host + storeURI.pathname + '/EVENTLOG', }); + case EStoreType.ResumableTaskStore: + return new ResumableTaskStoreLevel({ + location: storeURI.host + storeURI.pathname + '/RESUMABLE-TASK-STORE', + }); default: throw new Error('Unexpected level store type'); } @@ -89,7 +95,7 @@ function getLevelStore( function getDBStore( db: Dialect, storeType: EStoreType, -): DataStore | MessageStore | EventLog { +): DataStore | MessageStore | EventLog | ResumableTaskStore { switch (storeType) { case EStoreType.DataStore: return new DataStoreSql(db); @@ -97,6 +103,8 @@ function getDBStore( return new MessageStoreSql(db); case EStoreType.EventLog: return new EventLogSql(db); + case EStoreType.ResumableTaskStore: + return new ResumableTaskStoreSql(db); default: throw new Error('Unexpected db store type'); } @@ -114,6 +122,10 @@ function getStore( storeString: string, storeType: EStoreType.MessageStore, ): MessageStore; +function getStore( + storeString: string, + storeType: EStoreType.ResumableTaskStore, +): ResumableTaskStore; function getStore(storeString: string, storeType: EStoreType): StoreType { const storeURI = new URL(storeString); diff --git a/tests/test-dwn.ts b/tests/test-dwn.ts index 27d7744..005e00d 100644 --- a/tests/test-dwn.ts +++ b/tests/test-dwn.ts @@ -4,6 +4,7 @@ import { DataStoreSql, EventLogSql, MessageStoreSql, + ResumableTaskStoreSql, } from '@tbd54566975/dwn-sql-store'; import { getDialectFromURI } from '../src/storage.js'; @@ -18,6 +19,7 @@ export async function getTestDwn(options: { const dataStore = new DataStoreSql(db); const eventLog = new EventLogSql(db); const messageStore = new MessageStoreSql(db); + const resumableTaskStore = new ResumableTaskStoreSql(db); const eventStream = withEvents ? new EventEmitterStream() : undefined; // NOTE: no resolver cache used here to avoid locking LevelDB @@ -31,6 +33,7 @@ export async function getTestDwn(options: { eventLog, dataStore, messageStore, + resumableTaskStore, eventStream, tenantGate, didResolver