Skip to content

Commit e3934f2

Browse files
authored
Merge pull request #78 from windingtree/develop
Updated node-api configuration options
2 parents 456c777 + 0580026 commit e3934f2

File tree

7 files changed

+2948
-7398
lines changed

7 files changed

+2948
-7398
lines changed

examples/node/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,10 @@ const main = async (): Promise<void> => {
280280
})();
281281

282282
const apiServer = new NodeApiServer({
283-
usersStorage,
284-
dealsStorage,
283+
storage: {
284+
users: usersStorage,
285+
deals: dealsStorage,
286+
},
285287
prefix: 'test',
286288
port: 3456,
287289
secret: 'secret',

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,28 @@
2929
},
3030
"type": "module",
3131
"devDependencies": {
32-
"@types/node": "^20.10.4",
3332
"@commitlint/cli": "^18.4.3",
3433
"@commitlint/config-conventional": "^18.4.3",
3534
"@libp2p/crypto": "^1.0.17",
36-
"@typescript-eslint/eslint-plugin": "^6.13.2",
37-
"@typescript-eslint/parser": "^6.13.2",
38-
"@vitest/coverage-v8": "^1.0.4",
39-
"@vitest/ui": "^1.0.4",
40-
"eslint": "^8.55.0",
35+
"@types/node": "^20.10.5",
36+
"@typescript-eslint/eslint-plugin": "^6.15.0",
37+
"@typescript-eslint/parser": "^6.15.0",
38+
"@vitest/coverage-v8": "^1.1.0",
39+
"@vitest/ui": "^1.1.0",
40+
"eslint": "^8.56.0",
4141
"eslint-config-prettier": "^9.1.0",
42-
"eslint-plugin-prettier": "^5.0.1",
42+
"eslint-plugin-prettier": "^5.1.1",
4343
"git-cz": "^4.9.0",
4444
"husky": "^8.0.3",
45-
"lerna": "^7.1.4",
45+
"lerna": "^7.4.2",
4646
"prettier": "^3.1.1",
4747
"tsup": "^8.0.1",
48+
"typescript": "^5.3.3",
4849
"uint8arrays": "^5.0.0",
49-
"vite": "^5.0.7",
50+
"vite": "^5.0.10",
5051
"vite-plugin-dts": "^3.6.4",
5152
"vite-plugin-node-polyfills": "^0.17.0",
52-
"vitest": "^1.0.4",
53-
"typescript": "^5.3.3"
53+
"vitest": "^1.1.0"
5454
},
5555
"scripts": {
5656
"prepare": "husky install",

packages/node-api/src/server.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ const logger = createLogger('NodeApiServer');
2020
*/
2121
export interface NodeApiServerOptions {
2222
/**
23-
* An instance of the storage system that the API server will use for persisting users state.
23+
* An instances of the storage system that the API server will use.
2424
*/
25-
usersStorage: Storage;
26-
27-
/**
28-
* An instance of the storage system that the API server will use for persisting deals state.
29-
*/
30-
dealsStorage?: Storage;
25+
storage: Record<string, Storage>;
3126

3227
/**
3328
* An instance of the protocol contracts manager.
@@ -78,6 +73,7 @@ export interface ApiContext {
7873
user?: User;
7974
deals?: DealsDb;
8075
contracts?: ProtocolContracts;
76+
storage: Record<string, Storage>;
8177
}
8278

8379
/**
@@ -216,6 +212,8 @@ export class NodeApiServer {
216212
deals?: DealsDb;
217213
/** An instance of the ProtocolContracts that manages deals via the protocol smart contracts */
218214
protocolContracts?: ProtocolContracts;
215+
/** An instances of the storage system that the API server will use */
216+
storage: Record<string, Storage>;
219217
/** An Ethereum account address of the Node owner */
220218
ownerAccount?: Address;
221219
/** The duration (as a string or number) after which the access token will expire */
@@ -229,8 +227,7 @@ export class NodeApiServer {
229227
*/
230228
constructor(options: NodeApiServerOptions) {
231229
const {
232-
usersStorage,
233-
dealsStorage,
230+
storage,
234231
protocolContracts,
235232
prefix,
236233
port,
@@ -241,17 +238,18 @@ export class NodeApiServer {
241238

242239
// TODO Validate NodeApiServerOptions
243240

241+
this.storage = storage;
244242
this.port = port;
245243
this.secret = secret;
246244
this.ownerAccount = ownerAccount;
247245
this.expire = expire ?? '1h';
248246

249247
/** Initialize the UsersDb instance with the provided options */
250-
this.users = new UsersDb({ storage: usersStorage, prefix });
248+
this.users = new UsersDb({ storage: storage['users'], prefix });
251249

252-
if (dealsStorage) {
250+
if (storage['deals']) {
253251
/** Initialize the UsersDb instance with the provided options */
254-
this.deals = new DealsDb({ storage: dealsStorage, prefix });
252+
this.deals = new DealsDb({ storage: storage['deals'], prefix });
255253
}
256254

257255
if (protocolContracts) {
@@ -317,6 +315,7 @@ export class NodeApiServer {
317315
users: this.users,
318316
deals: this.deals,
319317
contracts: this.protocolContracts,
318+
storage: this.storage,
320319
};
321320

322321
let accessToken: string | undefined;

packages/node-api/test/api.nodeApiServer.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,18 @@ describe('NodeApiServer', () => {
7777
}),
7878
});
7979
options = {
80-
usersStorage: await memoryStorage.createInitializer({
81-
scope: 'users',
82-
})(),
80+
storage: {
81+
users: await memoryStorage.createInitializer({
82+
scope: 'users',
83+
})(),
84+
deals: await memoryStorage.createInitializer({
85+
scope: 'deals',
86+
})(),
87+
},
8388
prefix: 'test',
8489
port: 3456,
8590
secret: 'secret',
8691
ownerAccount: owner.address,
87-
dealsStorage: await memoryStorage.createInitializer({
88-
scope: 'deals',
89-
})(),
9092
protocolContracts: contractsManager,
9193
};
9294
server = new NodeApiServer(options);

packages/storage/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"superjson": "^2.2.1"
6666
},
6767
"scripts": {
68-
"build": "tsup",
68+
"build": "rm -rf dist && tsc -p ./tsconfig-build.json --emitDeclarationOnly && tsup",
6969
"lint": "eslint . --ext .ts --ignore-path ../../.lintignore",
7070
"lint:fix": "eslint . --ext .ts --ignore-path ../../.lintignore --fix && prettier --ignore-path ../../.lintignore --write .",
7171
"test": "vitest --run test",

packages/storage/tsup.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ export default defineConfig([
1212
},
1313
platform: 'neutral',
1414
treeshake: true,
15-
dts: { resolve: true },
15+
// dts: { resolve: true },
1616
sourcemap: true,
1717
splitting: false,
18-
clean: true,
1918
format: ['esm', 'cjs'],
2019
external: Object.keys(dependencies),
2120
},

0 commit comments

Comments
 (0)