Skip to content

Commit

Permalink
Merge pull request #78 from windingtree/develop
Browse files Browse the repository at this point in the history
Updated node-api configuration options
  • Loading branch information
kostysh authored Dec 22, 2023
2 parents 456c777 + 0580026 commit e3934f2
Show file tree
Hide file tree
Showing 7 changed files with 2,948 additions and 7,398 deletions.
6 changes: 4 additions & 2 deletions examples/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,10 @@ const main = async (): Promise<void> => {
})();

const apiServer = new NodeApiServer({
usersStorage,
dealsStorage,
storage: {
users: usersStorage,
deals: dealsStorage,
},
prefix: 'test',
port: 3456,
secret: 'secret',
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@
},
"type": "module",
"devDependencies": {
"@types/node": "^20.10.4",
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@libp2p/crypto": "^1.0.17",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@vitest/coverage-v8": "^1.0.4",
"@vitest/ui": "^1.0.4",
"eslint": "^8.55.0",
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@vitest/coverage-v8": "^1.1.0",
"@vitest/ui": "^1.1.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-prettier": "^5.1.1",
"git-cz": "^4.9.0",
"husky": "^8.0.3",
"lerna": "^7.1.4",
"lerna": "^7.4.2",
"prettier": "^3.1.1",
"tsup": "^8.0.1",
"typescript": "^5.3.3",
"uint8arrays": "^5.0.0",
"vite": "^5.0.7",
"vite": "^5.0.10",
"vite-plugin-dts": "^3.6.4",
"vite-plugin-node-polyfills": "^0.17.0",
"vitest": "^1.0.4",
"typescript": "^5.3.3"
"vitest": "^1.1.0"
},
"scripts": {
"prepare": "husky install",
Expand Down
23 changes: 11 additions & 12 deletions packages/node-api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ const logger = createLogger('NodeApiServer');
*/
export interface NodeApiServerOptions {
/**
* An instance of the storage system that the API server will use for persisting users state.
* An instances of the storage system that the API server will use.
*/
usersStorage: Storage;

/**
* An instance of the storage system that the API server will use for persisting deals state.
*/
dealsStorage?: Storage;
storage: Record<string, Storage>;

/**
* An instance of the protocol contracts manager.
Expand Down Expand Up @@ -78,6 +73,7 @@ export interface ApiContext {
user?: User;
deals?: DealsDb;
contracts?: ProtocolContracts;
storage: Record<string, Storage>;
}

/**
Expand Down Expand Up @@ -216,6 +212,8 @@ export class NodeApiServer {
deals?: DealsDb;
/** An instance of the ProtocolContracts that manages deals via the protocol smart contracts */
protocolContracts?: ProtocolContracts;
/** An instances of the storage system that the API server will use */
storage: Record<string, Storage>;
/** An Ethereum account address of the Node owner */
ownerAccount?: Address;
/** The duration (as a string or number) after which the access token will expire */
Expand All @@ -229,8 +227,7 @@ export class NodeApiServer {
*/
constructor(options: NodeApiServerOptions) {
const {
usersStorage,
dealsStorage,
storage,
protocolContracts,
prefix,
port,
Expand All @@ -241,17 +238,18 @@ export class NodeApiServer {

// TODO Validate NodeApiServerOptions

this.storage = storage;
this.port = port;
this.secret = secret;
this.ownerAccount = ownerAccount;
this.expire = expire ?? '1h';

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

if (dealsStorage) {
if (storage['deals']) {
/** Initialize the UsersDb instance with the provided options */
this.deals = new DealsDb({ storage: dealsStorage, prefix });
this.deals = new DealsDb({ storage: storage['deals'], prefix });
}

if (protocolContracts) {
Expand Down Expand Up @@ -317,6 +315,7 @@ export class NodeApiServer {
users: this.users,
deals: this.deals,
contracts: this.protocolContracts,
storage: this.storage,
};

let accessToken: string | undefined;
Expand Down
14 changes: 8 additions & 6 deletions packages/node-api/test/api.nodeApiServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,18 @@ describe('NodeApiServer', () => {
}),
});
options = {
usersStorage: await memoryStorage.createInitializer({
scope: 'users',
})(),
storage: {
users: await memoryStorage.createInitializer({
scope: 'users',
})(),
deals: await memoryStorage.createInitializer({
scope: 'deals',
})(),
},
prefix: 'test',
port: 3456,
secret: 'secret',
ownerAccount: owner.address,
dealsStorage: await memoryStorage.createInitializer({
scope: 'deals',
})(),
protocolContracts: contractsManager,
};
server = new NodeApiServer(options);
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"superjson": "^2.2.1"
},
"scripts": {
"build": "tsup",
"build": "rm -rf dist && tsc -p ./tsconfig-build.json --emitDeclarationOnly && tsup",
"lint": "eslint . --ext .ts --ignore-path ../../.lintignore",
"lint:fix": "eslint . --ext .ts --ignore-path ../../.lintignore --fix && prettier --ignore-path ../../.lintignore --write .",
"test": "vitest --run test",
Expand Down
3 changes: 1 addition & 2 deletions packages/storage/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ export default defineConfig([
},
platform: 'neutral',
treeshake: true,
dts: { resolve: true },
// dts: { resolve: true },
sourcemap: true,
splitting: false,
clean: true,
format: ['esm', 'cjs'],
external: Object.keys(dependencies),
},
Expand Down
Loading

0 comments on commit e3934f2

Please sign in to comment.