@abtnode/connect-storage 1.16.19-beta-e6aac665 → 1.16.19-beta-7b2db880

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +17 -1
  2. package/lib/index.js +8 -11
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Connect Storage
2
2
 
3
- Simple storage implemented on `@abtnode/models`, should be used with `WalletHandler` from `@blocklet/sdk`
3
+ Simple did connect storage that can be used cross multiple processes.
4
4
 
5
5
  ## Usage
6
6
 
@@ -11,4 +11,20 @@ yarn add @abtnode/connect-storage
11
11
  Then:
12
12
 
13
13
  ```javascript
14
+ import { join } from 'path';
15
+
16
+ import AuthStorage from '@abtnode/connect-storage';
17
+ import WalletAuthenticator from '@blocklet/sdk/lib/wallet-authenticator';
18
+ import WalletHandler from '@blocklet/sdk/lib/wallet-handler';
19
+ import Config from '@blocklet/sdk/lib/config';
20
+
21
+ export const authenticator = new WalletAuthenticator();
22
+ export const handlers = new WalletHandler({
23
+ authenticator,
24
+ tokenStorage: new AuthStorage({
25
+ // FIXME: update this
26
+ dbPath: join(Config.env.dataDir, 'path/to/component.db'),
27
+ }),
28
+ });
29
+
14
30
  ```
package/lib/index.js CHANGED
@@ -8,22 +8,19 @@ class SequelizeStorage extends EventEmitter {
8
8
  if (!options.dbPath) {
9
9
  throw new Error('SequelizeStorage requires dbPath to be set');
10
10
  }
11
- if (!options.model) {
12
- throw new Error('SequelizeStorage requires model to be set');
13
- }
14
- if (!options.primaryKey) {
15
- throw new Error('SequelizeStorage requires primaryKey to be set');
16
- }
11
+
12
+ const model = options.v2 ? 'ConnectionV2' : 'Connection';
13
+ const primaryKey = options.v2 ? 'sessionId' : 'token';
17
14
 
18
15
  super(options);
19
16
 
20
- this.sequelize = createSequelize(options.dbPath);
21
- this.models = getConnectModels();
17
+ const sequelize = createSequelize(options.dbPath);
18
+ const models = getConnectModels();
22
19
 
23
- setupModels(this.models, this.sequelize);
20
+ setupModels(models, sequelize);
24
21
 
25
- this.state = new ConnectionState(this.models[options.model], options);
26
- this.primaryKey = options.primaryKey;
22
+ this.state = new ConnectionState(models[model], { ...options, primaryKey });
23
+ this.primaryKey = primaryKey;
27
24
 
28
25
  doSchemaMigration(options.dbPath, 'connect')
29
26
  .then(() => {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.19-beta-e6aac665",
6
+ "version": "1.16.19-beta-7b2db880",
7
7
  "description": "Sequelize storage for @arcblock/did-auth",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,11 +19,11 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "@abtnode/models": "1.16.19-beta-e6aac665",
22
+ "@abtnode/models": "1.16.19-beta-7b2db880",
23
23
  "lodash": "^4.17.21"
24
24
  },
25
25
  "devDependencies": {
26
26
  "jest": "^27.5.1"
27
27
  },
28
- "gitHead": "09b0172831521ef73f7879940b977c2696b5b247"
28
+ "gitHead": "598b576b97dd7accbfa1bb509b75e423ad27e5e2"
29
29
  }