@abtnode/core 1.16.8-beta-186fd5aa → 1.16.8-next-d1e52353

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 (38) hide show
  1. package/lib/api/team.js +24 -64
  2. package/lib/blocklet/manager/disk.js +2 -8
  3. package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +5 -5
  4. package/lib/blocklet/storage/backup/blocklet-extras.js +2 -2
  5. package/lib/blocklet/storage/backup/blocklet.js +2 -2
  6. package/lib/index.js +14 -16
  7. package/lib/migrations/1.16.8-component-title.js +1 -1
  8. package/lib/migrations/1.6.9-update-node-info-and-certificate.js +1 -1
  9. package/lib/migrations/index.js +190 -40
  10. package/lib/monitor/node-runtime-monitor.js +2 -29
  11. package/lib/router/helper.js +6 -6
  12. package/lib/router/manager.js +35 -36
  13. package/lib/states/access-key.js +3 -20
  14. package/lib/states/audit-log.js +7 -8
  15. package/lib/states/backup.js +11 -59
  16. package/lib/states/base.js +13 -5
  17. package/lib/states/blocklet-extras.js +11 -8
  18. package/lib/states/blocklet.js +136 -225
  19. package/lib/states/cache.js +3 -21
  20. package/lib/states/connect-account.js +8 -0
  21. package/lib/states/index.js +28 -18
  22. package/lib/states/job.js +8 -0
  23. package/lib/states/migration.js +3 -4
  24. package/lib/states/node.js +104 -145
  25. package/lib/states/notification.js +18 -40
  26. package/lib/states/passport.js +8 -0
  27. package/lib/states/session.js +28 -44
  28. package/lib/states/site.js +32 -39
  29. package/lib/states/user.js +187 -374
  30. package/lib/states/webhook.js +5 -7
  31. package/lib/team/manager.js +108 -116
  32. package/lib/util/blocklet.js +0 -1
  33. package/lib/util/index.js +3 -0
  34. package/lib/util/queue.js +14 -20
  35. package/lib/util/ready.js +1 -1
  36. package/lib/webhook/index.js +6 -4
  37. package/package.json +19 -18
  38. package/lib/states/challenge.js +0 -58
@@ -40,7 +40,7 @@ const expandSite = async (siteId, info, node) => {
40
40
  }
41
41
 
42
42
  const { blocklet, site } = node.states;
43
- const doc = await site.findOne({ _id: siteId });
43
+ const doc = await site.findOne({ id: siteId });
44
44
  if (!doc) {
45
45
  return '';
46
46
  }
@@ -237,7 +237,7 @@ const getLogContent = async (action, args, context, result, info, node) => {
237
237
 
238
238
  // integrations
239
239
  case 'createWebHook':
240
- return `added integration ${result._id}: \n- type: ${args.type}\n${args.params.map(x => `- ${x.name}: ${x.value}`).join('\n')}`; // prettier-ignore
240
+ return `added integration ${result.id}: \n- type: ${args.type}\n${args.params.map(x => `- ${x.name}: ${x.value}`).join('\n')}`; // prettier-ignore
241
241
  case 'deleteWebHook':
242
242
  return `deleted integration ${args.id}`;
243
243
 
@@ -261,7 +261,7 @@ const getLogContent = async (action, args, context, result, info, node) => {
261
261
  case 'updateCertificate':
262
262
  return `updated certificate #${args.id}`;
263
263
  case 'issueLetsEncryptCert':
264
- return `tried to issue lets encrypt certificate for domain **${args.domain}**, ticket: ${result._id}`;
264
+ return `tried to issue lets encrypt certificate for domain **${args.domain}**, ticket: ${result.id}`;
265
265
 
266
266
  // router
267
267
  case 'addDomainAlias':
@@ -416,11 +416,10 @@ const fixActor = (actor) => {
416
416
  }
417
417
  };
418
418
 
419
+ /**
420
+ * @extends BaseState<import('@abtnode/models').AuditLogState>
421
+ */
419
422
  class AuditLogState extends BaseState {
420
- constructor(baseDir, config = {}) {
421
- super(baseDir, { filename: 'audit-log.db', ...config });
422
- }
423
-
424
423
  /**
425
424
  * Create new audit log
426
425
  *
@@ -442,7 +441,7 @@ class AuditLogState extends BaseState {
442
441
  locale: 'en',
443
442
  firstLoginAt: '2022-04-27T22:55:51.788Z',
444
443
  lastLoginAt: '2022-04-27T22:55:51.788Z',
445
- _id: 'dvOIJJVUJHGxnWBU',
444
+ id: 'dvOIJJVUJHGxnWBU',
446
445
  createdAt: '2022-04-27T22:55:51.789Z',
447
446
  updatedAt: '2022-04-27T22:55:51.789Z',
448
447
  role: 'owner',
@@ -1,21 +1,3 @@
1
- /**
2
- * @typedef{{
3
- appPid: string; // 此处建议使用 appPid
4
- userDid: string;
5
- strategy?: 0 | 1;
6
-
7
- sourceUrl: string;
8
-
9
- target?: "Spaces" | 'Local';
10
- targetUrl?: string;
11
-
12
- createdAt: string;
13
- updatedAt?: string;
14
- status?: 0 | 1;
15
- message?: string;
16
- * }} Backup
17
- */
18
-
19
1
  const { Joi } = require('@arcblock/validator');
20
2
  const BaseState = require('./base');
21
3
  const { validateBackupSuccess, validateBackupFail, validateBackupStart } = require('../validators/backup.js');
@@ -47,22 +29,11 @@ const validateBackup = Joi.object({
47
29
  });
48
30
 
49
31
  /**
50
- * @description
51
- * @class BackupState
32
+ * @extends BaseState<import('@abtnode/models').BackupState>
52
33
  */
53
34
  class BackupState extends BaseState {
54
- constructor(baseDir, config = {}) {
55
- super(baseDir, {
56
- filename: 'backup.db',
57
- ...config,
58
- });
59
- }
60
-
61
35
  /**
62
- * @description
63
- * @param {Pick<Backup, 'appPid' | 'userDid' | 'strategy' | 'sourceUrl' | 'target'>} backup
64
- * @return {Promise<Backup & {_id: string}>}
65
- * @memberof BackupState
36
+ * @param {Pick<import('@abtnode/models').BackupState, 'appPid' | 'userDid' | 'strategy' | 'sourceUrl' | 'target'>} backup
66
37
  */
67
38
  async start(backup) {
68
39
  const { error, value } = validateBackupStart.validate(backup, {
@@ -74,17 +45,12 @@ class BackupState extends BaseState {
74
45
  throw error;
75
46
  }
76
47
 
77
- return this.create({
78
- ...value,
79
- });
48
+ return this.insert(value);
80
49
  }
81
50
 
82
51
  /**
83
- * @description
84
52
  * @param {string} id
85
- * @param {Pick<Backup, 'targetUrl'>} successBackupInfo
86
- * @return {PromiseLike<import('@nedb/core').UpdateResult<Backup>>}
87
- * @memberof BackupState
53
+ * @param {Pick<import('@abtnode/models').BackupState, 'targetUrl'>} successBackupInfo
88
54
  */
89
55
  async success(id, successBackupInfo) {
90
56
  const { error, value } = validateBackupSuccess.validate(successBackupInfo, {
@@ -97,7 +63,7 @@ class BackupState extends BaseState {
97
63
  }
98
64
 
99
65
  return this.update(
100
- { _id: id },
66
+ { id },
101
67
  {
102
68
  $set: {
103
69
  ...value,
@@ -109,11 +75,8 @@ class BackupState extends BaseState {
109
75
  }
110
76
 
111
77
  /**
112
- * @description
113
78
  * @param {string} id
114
- * @param {Pick<Backup, 'message'>} errorBackupInfo
115
- * @return {PromiseLike<import('@nedb/core').UpdateResult<Backup>>}
116
- * @memberof BackupState
79
+ * @param {Pick<import('@abtnode/models').BackupState, 'message'>} errorBackupInfo
117
80
  */
118
81
  async fail(id, errorBackupInfo) {
119
82
  const { error, value } = validateBackupFail.validate(errorBackupInfo, {
@@ -126,7 +89,7 @@ class BackupState extends BaseState {
126
89
  }
127
90
 
128
91
  return this.update(
129
- { _id: id },
92
+ { id },
130
93
  {
131
94
  $set: {
132
95
  ...value,
@@ -138,10 +101,8 @@ class BackupState extends BaseState {
138
101
  }
139
102
 
140
103
  /**
141
- * @description
142
- * @param {Backup} backup
143
- * @return {Promise<Backup & {_id: string}>}
144
- * @memberof BackupState
104
+ * @param {import('@abtnode/models').BackupState} backup
105
+ * @return {Promise<import('@abtnode/models').BackupState>}
145
106
  */
146
107
  async create(backup) {
147
108
  const { error, value } = validateBackup.validate(backup, {
@@ -157,20 +118,11 @@ class BackupState extends BaseState {
157
118
  }
158
119
 
159
120
  /**
160
- * @description
161
121
  * @param {{ did: string }} { did }
162
- * @return {Promise<Array<import('@abtnode/client').Backup>>}
122
+ * @return {Promise<Array<import('@abtnode/models').BackupState>>}
163
123
  */
164
124
  async getBlockletBackups({ did }) {
165
- const backups = await this.cursor({
166
- appPid: did,
167
- })
168
- .sort({
169
- updatedAt: -1,
170
- })
171
- .exec();
172
-
173
- return backups ?? [];
125
+ return this.find({ appPid: did }, {}, { updatedAt: -1 });
174
126
  }
175
127
  }
176
128
 
@@ -1,17 +1,25 @@
1
- const DB = require('@abtnode/db');
1
+ const { BaseState } = require('@abtnode/models');
2
2
  const logger = require('@abtnode/logger')('@abtnode/core:states');
3
3
 
4
4
  const { isCLI } = require('../util');
5
5
 
6
- class BaseState extends DB {
7
- constructor(baseDir, config) {
8
- super(baseDir, config);
6
+ /**
7
+ * @template T
8
+ * @extends BaseState<T>
9
+ */
10
+ class ExtendedBase extends BaseState {
11
+ constructor(model, config) {
12
+ super(model, config);
9
13
 
10
14
  // HACK: do not emit any events from CLI
11
15
  if (isCLI() && process.env.NODE_ENV !== 'test') {
12
16
  this.emit = (name) => logger.debug('stopped state db event in CLI', name);
13
17
  }
14
18
  }
19
+
20
+ update(condition, updates, options) {
21
+ return super.update(condition, updates, { returnUpdatedDocs: true, ...options });
22
+ }
15
23
  }
16
24
 
17
- module.exports = BaseState;
25
+ module.exports = ExtendedBase;
@@ -59,9 +59,12 @@ const noop = (k) => (v) => v[k];
59
59
  // children: Children
60
60
  // };
61
61
 
62
+ /**
63
+ * @extends BaseState<import('@abtnode/models').BlockletExtraState>
64
+ */
62
65
  class BlockletExtrasState extends BaseState {
63
- constructor(baseDir, config = {}) {
64
- super(baseDir, { filename: 'blocklet_extras.db', ...config });
66
+ constructor(...args) {
67
+ super(...args);
65
68
 
66
69
  this.extras = [
67
70
  // environment
@@ -184,7 +187,7 @@ class BlockletExtrasState extends BaseState {
184
187
  await this.insert(item);
185
188
  logger.info('create extra success', { name, dids });
186
189
  } else {
187
- await this.update(item._id, item);
190
+ await this.updateByDid(item.did, item);
188
191
  logger.info('update extra success', { name, dids });
189
192
  }
190
193
 
@@ -219,7 +222,7 @@ class BlockletExtrasState extends BaseState {
219
222
  const updated = component[name];
220
223
  component[name] = null;
221
224
 
222
- await this.update(item._id, item);
225
+ await this.updateByDid(item.did, item);
223
226
 
224
227
  return updated;
225
228
  };
@@ -248,7 +251,7 @@ class BlockletExtrasState extends BaseState {
248
251
 
249
252
  await validateAddMeta(entity);
250
253
 
251
- return super.update({ did }, { $set: entity }, { upsert: true });
254
+ return super.upsert({ did }, { $set: entity });
252
255
  }
253
256
 
254
257
  async getMeta(did) {
@@ -259,7 +262,7 @@ class BlockletExtrasState extends BaseState {
259
262
  const entity = { did, expiredAt };
260
263
  await validateExpiredInfo(entity);
261
264
 
262
- return super.update({ did }, { $set: { expiredAt } });
265
+ return this.updateByDid(did, { expiredAt });
263
266
  }
264
267
 
265
268
  async getExpiredList() {
@@ -299,8 +302,8 @@ class BlockletExtrasState extends BaseState {
299
302
  return data;
300
303
  }
301
304
 
302
- updateByDid(did, data) {
303
- return super.update({ did }, { $set: data });
305
+ updateByDid(did, updates) {
306
+ return super.update({ did }, { $set: updates });
304
307
  }
305
308
  }
306
309