@abtnode/models 1.16.11-beta-0ae58a71 → 1.16.11-beta-f9719c31

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.
package/lib/migrate.js CHANGED
@@ -18,6 +18,7 @@ const models_1 = require("./models");
18
18
  const util_1 = require("./util");
19
19
  const logger = (0, logger_1.default)('@abtnode/models:migration');
20
20
  const MIGRATION_SCRIPT_EXTENSION = process.env.MIGRATION_SCRIPT_EXTENSION || 'js';
21
+ // eslint-disable-next-line require-await
21
22
  async function doSchemaMigration(dbFile, group) {
22
23
  const sequelize = (0, models_1.createSequelize)(dbFile);
23
24
  if (['server', 'blocklet', 'service', 'certificate-manager', 'connect'].includes(group) === false) {
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ const up = async ({ context }) => {
5
+ await context.bulkDelete('passports', { id: null });
6
+ await context.bulkDelete('connected_accounts', { did: null });
7
+ };
8
+ exports.up = up;
9
+ const down = async () => {
10
+ // Do nothing
11
+ };
12
+ exports.down = down;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.down = exports.up = void 0;
4
4
  const sequelize_1 = require("sequelize");
5
+ // Add missing fields for servers from launcher
5
6
  const up = async ({ context }) => {
6
7
  await context.addColumn('servers', 'launcher', { type: sequelize_1.DataTypes.JSON });
7
8
  };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ const sequelize_1 = require("sequelize");
5
+ // Add missing fields for paid blocklets
6
+ const up = async ({ context }) => {
7
+ await context.addColumn('blocklets', 'tokens', { type: sequelize_1.DataTypes.JSON });
8
+ };
9
+ exports.up = up;
10
+ const down = async ({ context }) => {
11
+ await context.removeColumn('blocklets', 'tokens');
12
+ };
13
+ exports.down = down;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ const sequelize_1 = require("sequelize");
5
+ const up = async ({ context }) => {
6
+ await context.addColumn('backups', 'targetName', { type: sequelize_1.DataTypes.STRING(256), defaultValue: '' });
7
+ };
8
+ exports.up = up;
9
+ const down = async ({ context }) => {
10
+ await context.removeColumn('backups', 'targetName');
11
+ };
12
+ exports.down = down;
@@ -9,12 +9,17 @@ function createBackupModel() {
9
9
  static initialize(sequelize) {
10
10
  this.init({
11
11
  ...this.GENESIS_ATTRIBUTES,
12
+ targetName: {
13
+ type: sequelize_1.DataTypes.STRING(256),
14
+ defaultValue: '',
15
+ },
12
16
  }, {
13
17
  sequelize,
14
18
  modelName: 'Backup',
15
19
  tableName: 'backups',
16
20
  indexes: [{ fields: ['appPid'] }],
17
- timestamps: true,
21
+ // note: 备份的过程中,updatedAt 不需要填充默认值
22
+ timestamps: false,
18
23
  });
19
24
  }
20
25
  },
@@ -1,6 +1,7 @@
1
1
  import { TBlockletState } from '@abtnode/types';
2
2
  import { DynamicModel } from '../types';
3
- export type BlockletState = Omit<TBlockletState, 'port' | 'configs' | 'trustedFactories' | 'trustedPassports' | 'enablePassportIssuance' | 'dynamic' | 'mountPoint'> & {
3
+ export type BlockletState = Omit<TBlockletState, 'port' | 'configs' | 'trustedFactories' | 'trustedPassports' | 'enablePassportIssuance' | 'dynamic' | 'mountPoint' | 'controller'> & {
4
4
  updatedAt: Date;
5
+ tokens: Record<string, any>;
5
6
  };
6
7
  export declare function createBlockletModel(): DynamicModel<BlockletState>;
@@ -7,7 +7,12 @@ function createBlockletModel() {
7
7
  var _a;
8
8
  return _a = class Blocklet extends sequelize_1.Model {
9
9
  static initialize(sequelize) {
10
- this.init({ ...this.GENESIS_ATTRIBUTES }, {
10
+ this.init({
11
+ ...this.GENESIS_ATTRIBUTES,
12
+ tokens: {
13
+ type: sequelize_1.DataTypes.JSON,
14
+ },
15
+ }, {
11
16
  sequelize,
12
17
  modelName: 'Blocklet',
13
18
  tableName: 'blocklets',
@@ -38,9 +43,6 @@ function createBlockletModel() {
38
43
  meta: {
39
44
  type: sequelize_1.DataTypes.JSON,
40
45
  },
41
- controller: {
42
- type: sequelize_1.DataTypes.JSON,
43
- },
44
46
  status: {
45
47
  type: sequelize_1.DataTypes.INTEGER,
46
48
  },
@@ -27,6 +27,7 @@ function createConnectedAccountModel() {
27
27
  did: {
28
28
  type: sequelize_1.DataTypes.STRING(40),
29
29
  primaryKey: true,
30
+ allowNull: false,
30
31
  },
31
32
  pk: {
32
33
  type: sequelize_1.DataTypes.STRING(256),
@@ -41,6 +42,7 @@ function createConnectedAccountModel() {
41
42
  },
42
43
  provider: {
43
44
  type: sequelize_1.DataTypes.STRING(32),
45
+ allowNull: false,
44
46
  },
45
47
  id: {
46
48
  type: sequelize_1.DataTypes.STRING(64),
@@ -62,7 +62,8 @@ __exportStar(require("./connection"), exports);
62
62
  __exportStar(require("./backup"), exports);
63
63
  const instances = new Map();
64
64
  function createSequelize(dbPath, config = {
65
- logging: !!process.env.DEBUG || ['production', 'test'].includes(process.env.NODE_ENV) === false,
65
+ logging: !process.env.DISABLE_SQLITE_LOG &&
66
+ (!!process.env.DEBUG || ['production', 'test'].includes(process.env.NODE_ENV) === false),
66
67
  }) {
67
68
  if (instances.has(dbPath)) {
68
69
  return instances.get(dbPath);
@@ -27,6 +27,7 @@ function createPassportModel() {
27
27
  id: {
28
28
  type: sequelize_1.DataTypes.STRING(40),
29
29
  primaryKey: true,
30
+ allowNull: false,
30
31
  },
31
32
  userDid: {
32
33
  type: sequelize_1.DataTypes.STRING(40),
@@ -8,6 +8,7 @@ const events_1 = __importDefault(require("events"));
8
8
  const sequelize_1 = require("sequelize");
9
9
  const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
10
10
  const util_1 = require("../util");
11
+ // eslint-disable-next-line import/prefer-default-export
11
12
  class BaseState extends events_1.default {
12
13
  constructor(model, config = {}) {
13
14
  super();
@@ -23,7 +24,7 @@ class BaseState extends events_1.default {
23
24
  }
24
25
  });
25
26
  }
26
- async find(condition = {}, selection = {}, sort = {}) {
27
+ find(condition = {}, selection = {}, sort = {}) {
27
28
  const params = (0, util_1.formatParams)({
28
29
  attributes: (0, util_1.formatSelection)(selection),
29
30
  order: (0, util_1.formatOrder)(sort),
@@ -32,7 +33,7 @@ class BaseState extends events_1.default {
32
33
  });
33
34
  return this.model.findAll(params).then((x) => x.map((y) => y.toJSON()));
34
35
  }
35
- async findOne(condition = {}, selection = {}, sort = {}) {
36
+ findOne(condition = {}, selection = {}, sort = {}) {
36
37
  const params = (0, util_1.formatParams)({
37
38
  attributes: (0, util_1.formatSelection)(selection),
38
39
  order: (0, util_1.formatOrder)(sort),
@@ -40,7 +41,7 @@ class BaseState extends events_1.default {
40
41
  });
41
42
  return this.model.findOne(params).then((x) => x?.toJSON());
42
43
  }
43
- async count(condition = {}) {
44
+ count(condition = {}) {
44
45
  return this.model.count({ ...(0, util_1.formatConditions)(condition) });
45
46
  }
46
47
  async insert(doc) {
@@ -65,7 +66,7 @@ class BaseState extends events_1.default {
65
66
  const docs = options.returnUpdatedDocs ? await this.find(condition) : [];
66
67
  return [affectedRows, docs];
67
68
  }
68
- async updateById(id, updates, options = {}) {
69
+ updateById(id, updates, options = {}) {
69
70
  return this.update({ id }, updates, options);
70
71
  }
71
72
  async upsert(condition, updates) {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createStateFactory = void 0;
4
+ // eslint-disable-next-line import/prefer-default-export
4
5
  function createStateFactory(initializer, models) {
5
6
  const states = {};
6
7
  return new Proxy({}, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abtnode/models",
3
- "version": "1.16.11-beta-0ae58a71",
3
+ "version": "1.16.11-beta-f9719c31",
4
4
  "description": "Sequelize models for blocklet server and blocklet service",
5
5
  "homepage": "https://github.com/ArcBlock/blocklet-server#readme",
6
6
  "publishConfig": {
@@ -32,8 +32,8 @@
32
32
  "url": "https://github.com/ArcBlock/blocklet-server/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@abtnode/logger": "1.16.11-beta-0ae58a71",
36
- "@abtnode/types": "1.16.11-beta-0ae58a71",
35
+ "@abtnode/logger": "1.16.11-beta-f9719c31",
36
+ "@abtnode/types": "1.16.11-beta-f9719c31",
37
37
  "@nedb/core": "^2.1.5",
38
38
  "lodash.clonedeep": "^4.5.0",
39
39
  "lodash.get": "^4.4.2",
@@ -44,7 +44,7 @@
44
44
  "uuid": "^8.3.2"
45
45
  },
46
46
  "devDependencies": {
47
- "@arcblock/eslint-config-ts": "^0.2.3",
47
+ "@arcblock/eslint-config-ts": "^0.2.4",
48
48
  "@types/jest": "^29.2.0",
49
49
  "@types/node": "^18.11.0",
50
50
  "@typescript-eslint/eslint-plugin": "^5.40.1",
@@ -54,5 +54,5 @@
54
54
  "typescript": "^5.0.4"
55
55
  },
56
56
  "resolutions": {},
57
- "gitHead": "5d044a08b4399eb855563e670af7cbd0d3851e94"
57
+ "gitHead": "2d88c5df1a414e5b6a8d575984e1940de7573976"
58
58
  }