@abtnode/models 1.16.15-beta-12f50442 → 1.16.15-beta-d649cecc

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.
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ const models_1 = require("../../models");
5
+ const models = (0, models_1.getBlockletModels)();
6
+ const up = async ({ context }) => {
7
+ await context.createTable('tags', models.Tag.GENESIS_ATTRIBUTES);
8
+ await context.createTable('tagging', models.Tagging.GENESIS_ATTRIBUTES);
9
+ await context.addIndex('tags', ['title'], { unique: true });
10
+ await context.addIndex('tagging', ['tagId', 'taggableId'], { unique: true });
11
+ };
12
+ exports.up = up;
13
+ const down = async ({ context }) => {
14
+ await context.dropTable('tags');
15
+ await context.dropTable('tagging');
16
+ };
17
+ exports.down = down;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ const models_1 = require("../../models");
5
+ const models = (0, models_1.getBlockletModels)();
6
+ const up = async ({ context }) => {
7
+ await context.createTable('tags', models.Tag.GENESIS_ATTRIBUTES);
8
+ await context.createTable('tagging', models.Tagging.GENESIS_ATTRIBUTES);
9
+ await context.addIndex('tags', ['title'], { unique: true });
10
+ await context.addIndex('tagging', ['tagId', 'taggableId'], { unique: true });
11
+ };
12
+ exports.up = up;
13
+ const down = async ({ context }) => {
14
+ await context.dropTable('tags');
15
+ await context.dropTable('tagging');
16
+ };
17
+ exports.down = down;
@@ -23,6 +23,8 @@ export * from './connection';
23
23
  export * from './backup';
24
24
  export * from './traffic-insight';
25
25
  export * from './runtime-insight';
26
+ export * from './tag';
27
+ export * from './tagging';
26
28
  export declare function createSequelize(dbPath: string, config?: Record<string, any>): any;
27
29
  export declare function destroySequelize(dbPath: string): void;
28
30
  export declare function getServiceModels(): {
@@ -40,6 +42,8 @@ export declare function getBlockletModels(): {
40
42
  ConnectedAccount: import("../types").DynamicModel<import("./connected-account").ConnectedAccountState>;
41
43
  Session: import("../types").DynamicModel<import("./session").SessionState>;
42
44
  Rbac: import("../types").DynamicModel<import("./rbac").RbacState>;
45
+ Tag: import("../types").DynamicModel<import("@abtnode/types").TTag>;
46
+ Tagging: import("../types").DynamicModel<import("./tagging").TaggingState>;
43
47
  };
44
48
  export declare function getServerModels(): {
45
49
  AccessKey: import("../types").DynamicModel<import("./access-key").AccessKeyState>;
@@ -61,6 +65,8 @@ export declare function getServerModels(): {
61
65
  Backup: import("../types").DynamicModel<import("./backup").BackupState>;
62
66
  TrafficInsight: import("../types").DynamicModel<import("./traffic-insight").TrafficInsightState>;
63
67
  RuntimeInsight: import("../types").DynamicModel<import("./runtime-insight").RuntimeInsightState>;
68
+ Tag: import("../types").DynamicModel<import("@abtnode/types").TTag>;
69
+ Tagging: import("../types").DynamicModel<import("./tagging").TaggingState>;
64
70
  };
65
71
  export declare function getConnectModels(): {
66
72
  Connection: import("../types").DynamicModel<import("./connection").ConnectionState>;
@@ -40,6 +40,8 @@ const connection_1 = require("./connection");
40
40
  const backup_1 = require("./backup");
41
41
  const traffic_insight_1 = require("./traffic-insight");
42
42
  const runtime_insight_1 = require("./runtime-insight");
43
+ const tag_1 = require("./tag");
44
+ const tagging_1 = require("./tagging");
43
45
  __exportStar(require("./message"), exports);
44
46
  __exportStar(require("./account"), exports);
45
47
  __exportStar(require("./certificate"), exports);
@@ -64,6 +66,8 @@ __exportStar(require("./connection"), exports);
64
66
  __exportStar(require("./backup"), exports);
65
67
  __exportStar(require("./traffic-insight"), exports);
66
68
  __exportStar(require("./runtime-insight"), exports);
69
+ __exportStar(require("./tag"), exports);
70
+ __exportStar(require("./tagging"), exports);
67
71
  const instances = new Map();
68
72
  function createSequelize(dbPath, config = {
69
73
  logging: !process.env.DISABLE_SQLITE_LOG &&
@@ -114,6 +118,8 @@ function getBlockletModels() {
114
118
  ConnectedAccount: (0, connected_account_1.createConnectedAccountModel)(),
115
119
  Session: (0, session_1.createSessionModel)(),
116
120
  Rbac: (0, rbac_1.createRbacModel)(),
121
+ Tag: (0, tag_1.createTagModel)(),
122
+ Tagging: (0, tagging_1.createTaggingModel)(),
117
123
  };
118
124
  return models;
119
125
  }
@@ -139,6 +145,8 @@ function getServerModels() {
139
145
  Backup: (0, backup_1.createBackupModel)(),
140
146
  TrafficInsight: (0, traffic_insight_1.createTrafficInsightModel)(),
141
147
  RuntimeInsight: (0, runtime_insight_1.createRuntimeInsightModel)(),
148
+ Tag: (0, tag_1.createTagModel)(),
149
+ Tagging: (0, tagging_1.createTaggingModel)(),
142
150
  };
143
151
  return models;
144
152
  }
@@ -0,0 +1,4 @@
1
+ import { TTag } from '@abtnode/types';
2
+ import { DynamicModel } from '../types';
3
+ export type TagState = TTag;
4
+ export declare function createTagModel(): DynamicModel<TagState>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTagModel = void 0;
4
+ const sequelize_1 = require("sequelize");
5
+ function createTagModel() {
6
+ var _a;
7
+ return _a = class Tag extends sequelize_1.Model {
8
+ static initialize(sequelize) {
9
+ this.init({
10
+ ...this.GENESIS_ATTRIBUTES,
11
+ }, {
12
+ sequelize,
13
+ modelName: 'Tag',
14
+ tableName: 'tags',
15
+ indexes: [{ fields: ['title'], unique: true }],
16
+ timestamps: true,
17
+ });
18
+ }
19
+ static associate(models) {
20
+ Tag.belongsToMany(models.User, {
21
+ through: {
22
+ model: models.Tagging,
23
+ scope: {
24
+ taggableType: 'user',
25
+ },
26
+ },
27
+ constraints: false,
28
+ foreignKey: 'tagId',
29
+ otherKey: 'taggableId',
30
+ as: 'users',
31
+ });
32
+ }
33
+ },
34
+ // CAUTION: do not edit this
35
+ _a.GENESIS_ATTRIBUTES = {
36
+ id: {
37
+ type: sequelize_1.DataTypes.INTEGER,
38
+ primaryKey: true,
39
+ autoIncrement: true,
40
+ },
41
+ title: {
42
+ type: sequelize_1.DataTypes.STRING(64),
43
+ allowNull: false,
44
+ unique: true,
45
+ },
46
+ color: {
47
+ type: sequelize_1.DataTypes.STRING(8),
48
+ allowNull: false,
49
+ },
50
+ description: {
51
+ type: sequelize_1.DataTypes.STRING(255),
52
+ allowNull: true,
53
+ },
54
+ createdAt: {
55
+ type: sequelize_1.DataTypes.DATE,
56
+ defaultValue: sequelize_1.DataTypes.NOW,
57
+ index: true,
58
+ },
59
+ updatedAt: {
60
+ type: sequelize_1.DataTypes.DATE,
61
+ defaultValue: sequelize_1.DataTypes.NOW,
62
+ index: true,
63
+ },
64
+ },
65
+ _a;
66
+ }
67
+ exports.createTagModel = createTagModel;
@@ -0,0 +1,6 @@
1
+ import { DynamicModel } from '../types';
2
+ export type TaggingState = {
3
+ tagId: number;
4
+ taggableId: string;
5
+ };
6
+ export declare function createTaggingModel(): DynamicModel<TaggingState>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTaggingModel = void 0;
4
+ const sequelize_1 = require("sequelize");
5
+ function createTaggingModel() {
6
+ var _a;
7
+ return _a = class Tagging extends sequelize_1.Model {
8
+ static initialize(sequelize) {
9
+ this.init({
10
+ ...this.GENESIS_ATTRIBUTES,
11
+ }, {
12
+ sequelize,
13
+ modelName: 'Tagging',
14
+ tableName: 'tagging',
15
+ indexes: [{ fields: ['tagId', 'taggableId'], unique: true }],
16
+ timestamps: false,
17
+ });
18
+ }
19
+ },
20
+ // CAUTION: do not edit this
21
+ _a.GENESIS_ATTRIBUTES = {
22
+ tagId: {
23
+ type: sequelize_1.DataTypes.INTEGER,
24
+ allowNull: false,
25
+ },
26
+ taggableId: {
27
+ type: sequelize_1.DataTypes.STRING(40),
28
+ allowNull: false,
29
+ },
30
+ taggableType: {
31
+ type: sequelize_1.DataTypes.STRING(16),
32
+ allowNull: false,
33
+ },
34
+ },
35
+ _a;
36
+ }
37
+ exports.createTaggingModel = createTaggingModel;
@@ -1,4 +1,4 @@
1
1
  import { TUserInfo } from '@abtnode/types';
2
2
  import { DynamicModel } from '../types';
3
- export type UserState = Omit<TUserInfo, 'passports' | 'connectedAccounts' | 'source' | 'extraConfigs'>;
3
+ export type UserState = Omit<TUserInfo, 'passports' | 'connectedAccounts' | 'source' | 'extraConfigs' | 'tags'>;
4
4
  export declare function createUserModel(): DynamicModel<UserState>;
@@ -27,6 +27,18 @@ function createUserModel() {
27
27
  onDelete: 'CASCADE',
28
28
  as: 'connectedAccounts',
29
29
  });
30
+ User.belongsToMany(models.Tag, {
31
+ through: {
32
+ model: models.Tagging,
33
+ scope: {
34
+ taggableType: 'user',
35
+ },
36
+ },
37
+ constraints: false,
38
+ foreignKey: 'taggableId',
39
+ otherKey: 'tagId',
40
+ as: 'tags',
41
+ });
30
42
  }
31
43
  },
32
44
  _a.GENESIS_ATTRIBUTES = {
@@ -1,8 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import EventEmitter from 'events';
3
3
  import { ModelDefined } from 'sequelize';
4
+ import { MakeNullishOptional } from 'sequelize/types/utils';
4
5
  import { AnyObject, SelectOptions, SortOptions, UpdateOptions, ConditionOptions, PagingOptions } from '../types';
5
- export declare class BaseState<T> extends EventEmitter {
6
+ export declare class BaseState<T extends object> extends EventEmitter {
6
7
  model: ModelDefined<T, T>;
7
8
  jsonAttributes: string[];
8
9
  config: AnyObject;
@@ -32,6 +33,7 @@ export declare class BaseState<T> extends EventEmitter {
32
33
  sum(field: keyof T, condition?: ConditionOptions<T>): Promise<number>;
33
34
  query(query: string): Promise<object[]>;
34
35
  reset(): Promise<number>;
36
+ build(row: MakeNullishOptional<T>): import("sequelize").Model<T, T>;
35
37
  loadDatabase(cb?: Function): void;
36
38
  closeDatabase(cb?: Function): void;
37
39
  compactDatafile(cb?: Function): void;
@@ -116,6 +116,9 @@ class BaseState extends events_1.default {
116
116
  reset() {
117
117
  return this.model.destroy({ truncate: true });
118
118
  }
119
+ build(row) {
120
+ return this.model.build(row);
121
+ }
119
122
  loadDatabase(cb) {
120
123
  if (typeof cb === 'function') {
121
124
  setImmediate(() => cb());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abtnode/models",
3
- "version": "1.16.15-beta-12f50442",
3
+ "version": "1.16.15-beta-d649cecc",
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,9 +32,9 @@
32
32
  "url": "https://github.com/ArcBlock/blocklet-server/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@abtnode/logger": "1.16.15-beta-12f50442",
36
- "@abtnode/types": "1.16.15-beta-12f50442",
37
- "@blocklet/constant": "1.16.15-beta-12f50442",
35
+ "@abtnode/logger": "1.16.15-beta-d649cecc",
36
+ "@abtnode/types": "1.16.15-beta-d649cecc",
37
+ "@blocklet/constant": "1.16.15-beta-d649cecc",
38
38
  "@nedb/core": "^2.1.5",
39
39
  "lodash.clonedeep": "^4.5.0",
40
40
  "lodash.get": "^4.4.2",
@@ -55,5 +55,5 @@
55
55
  "typescript": "^5.0.4"
56
56
  },
57
57
  "resolutions": {},
58
- "gitHead": "48bda4b29eb31a70e0eb9cab0bce6e544960c7fd"
58
+ "gitHead": "56941d1056a9e5f189992ace6e93971aa4226d07"
59
59
  }