@nocobase/database 2.1.0-beta.46 → 2.1.0-beta.48

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.
@@ -30,10 +30,23 @@ export type DumpRules = BuiltInGroup | ({
30
30
  group: BuiltInGroup | string;
31
31
  } & BaseDumpRules);
32
32
  export type MigrationRule = 'overwrite' | 'skip' | 'upsert' | 'schema-only' | 'insert-ignore' | (string & {}) | null;
33
+ /**
34
+ * `dataCategory = system` marks data that is foundational to system operation and should be treated as core runtime data.
35
+ * `dataCategory = business` marks data owned by plugin features and used as part of the plugin's business domain.
36
+ * `dataCategory = runtime` excludes the collection's data from backup snapshots.
37
+ */
38
+ export type DataCategory = 'system' | 'business' | 'runtime';
39
+ export type DataCategories = DataCategory | DataCategory[];
40
+ export declare const TAG: {
41
+ basic: string;
42
+ business: string;
43
+ ignoredBackup: string;
44
+ };
33
45
  export interface CollectionOptions extends Omit<ModelOptions, 'name' | 'hooks'> {
34
46
  name: string;
35
47
  title?: string;
36
48
  namespace?: string;
49
+ dataCategory?: DataCategories;
37
50
  migrationRules?: MigrationRule[];
38
51
  dumpRules?: DumpRules;
39
52
  tableName?: string;
@@ -81,6 +94,7 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
81
94
  model: ModelStatic<Model>;
82
95
  repository: Repository<TModelAttributes, TCreationAttributes>;
83
96
  constructor(options: CollectionOptions, context: CollectionContext);
97
+ get dataCategory(): DataCategories;
84
98
  get underscored(): boolean;
85
99
  get filterTargetKey(): string | string[];
86
100
  get name(): string;
package/lib/collection.js CHANGED
@@ -45,7 +45,8 @@ var __decorateClass = (decorators, target, key, kind) => {
45
45
  };
46
46
  var collection_exports = {};
47
47
  __export(collection_exports, {
48
- Collection: () => Collection
48
+ Collection: () => Collection,
49
+ TAG: () => TAG
49
50
  });
50
51
  module.exports = __toCommonJS(collection_exports);
51
52
  var import_deepmerge = __toESM(require("deepmerge"));
@@ -89,6 +90,11 @@ function EnsureAtomicity(target, propertyKey, descriptor) {
89
90
  return descriptor;
90
91
  }
91
92
  __name(EnsureAtomicity, "EnsureAtomicity");
93
+ const TAG = {
94
+ basic: "basic",
95
+ business: "business",
96
+ ignoredBackup: "ignored:backup"
97
+ };
92
98
  const _Collection = class _Collection extends import_events.EventEmitter {
93
99
  options;
94
100
  context;
@@ -112,6 +118,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
112
118
  this.setRepository(options.repository);
113
119
  this.setSortable(options.sortable);
114
120
  }
121
+ get dataCategory() {
122
+ return this.options.dataCategory;
123
+ }
115
124
  get underscored() {
116
125
  return this.options.underscored;
117
126
  }
@@ -817,5 +826,6 @@ __decorateClass([
817
826
  let Collection = _Collection;
818
827
  // Annotate the CommonJS export names for ESM import in node:
819
828
  0 && (module.exports = {
820
- Collection
829
+ Collection,
830
+ TAG
821
831
  });
package/lib/database.js CHANGED
@@ -224,6 +224,7 @@ const _Database = class _Database extends import_events.EventEmitter {
224
224
  });
225
225
  this.collection({
226
226
  name: "migrations",
227
+ dataCategory: "system",
227
228
  autoGenId: false,
228
229
  timestamps: false,
229
230
  dumpRules: "required",
@@ -7,6 +7,8 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import { DataTypes } from 'sequelize';
10
+ import type { UpdateOptions } from 'sequelize';
11
+ import { Model } from '../model';
10
12
  import { BaseColumnFieldOptions, Field } from './field';
11
13
  export interface PasswordFieldOptions extends BaseColumnFieldOptions {
12
14
  type: 'password';
@@ -20,11 +22,15 @@ export interface PasswordFieldOptions extends BaseColumnFieldOptions {
20
22
  randomBytesSize?: number;
21
23
  }
22
24
  type PasswordValue = string | number;
25
+ type BulkUpdateOptions = UpdateOptions<Record<string, unknown>> & {
26
+ attributes?: Record<string, unknown>;
27
+ };
23
28
  export declare class PasswordField extends Field {
24
29
  get dataType(): DataTypes.StringDataTypeConstructor;
25
- verify(password: PasswordValue, hash: string): Promise<unknown>;
26
- hash(password: PasswordValue): Promise<unknown>;
27
- init(): void;
30
+ listener: (instances: Model | Model[]) => Promise<void>;
31
+ bulkUpdateListener: (options: BulkUpdateOptions) => Promise<void>;
32
+ verify(password: PasswordValue, hash: string): Promise<boolean>;
33
+ hash(password: PasswordValue): Promise<string>;
28
34
  bind(): void;
29
35
  unbind(): void;
30
36
  }
@@ -47,6 +47,41 @@ const _PasswordField = class _PasswordField extends import_field.Field {
47
47
  get dataType() {
48
48
  return import_sequelize.DataTypes.STRING;
49
49
  }
50
+ listener = /* @__PURE__ */ __name(async (instances) => {
51
+ const { name } = this.options;
52
+ const fieldName = name;
53
+ instances = Array.isArray(instances) ? instances : [instances];
54
+ for (const instance of instances) {
55
+ if (!instance.changed(fieldName)) {
56
+ continue;
57
+ }
58
+ const value = instance.get(fieldName);
59
+ if (value !== null && value !== void 0 && value !== "") {
60
+ const password = typeof value === "number" ? value : String(value);
61
+ const hash = await this.hash(password);
62
+ instance.set(fieldName, hash);
63
+ } else {
64
+ instance.set(fieldName, instance.previous(fieldName));
65
+ }
66
+ }
67
+ }, "listener");
68
+ bulkUpdateListener = /* @__PURE__ */ __name(async (options) => {
69
+ var _a;
70
+ const { name } = this.options;
71
+ const fieldName = name;
72
+ const { attributes } = options;
73
+ if (!attributes || !Object.prototype.hasOwnProperty.call(attributes, fieldName)) {
74
+ return;
75
+ }
76
+ const value = attributes[fieldName];
77
+ if (value !== null && value !== void 0 && value !== "") {
78
+ const password = typeof value === "number" ? value : String(value);
79
+ attributes[fieldName] = await this.hash(password);
80
+ } else {
81
+ delete attributes[fieldName];
82
+ options.fields = (_a = options.fields) == null ? void 0 : _a.filter((field) => field !== fieldName);
83
+ }
84
+ }, "bulkUpdateListener");
50
85
  async verify(password, hash) {
51
86
  const passwordString = password === null || password === void 0 ? "" : String(password);
52
87
  hash = hash || "";
@@ -71,37 +106,19 @@ const _PasswordField = class _PasswordField extends import_field.Field {
71
106
  });
72
107
  });
73
108
  }
74
- init() {
75
- const { name } = this.options;
76
- const fieldName = name;
77
- this.listener = async (instances) => {
78
- instances = Array.isArray(instances) ? instances : [instances];
79
- for (const instance of instances) {
80
- if (!instance.changed(fieldName)) {
81
- continue;
82
- }
83
- const value = instance.get(fieldName);
84
- if (value !== null && value !== void 0 && value !== "") {
85
- const password = typeof value === "number" ? value : String(value);
86
- const hash = await this.hash(password);
87
- instance.set(fieldName, hash);
88
- } else {
89
- instance.set(fieldName, instance.previous(fieldName));
90
- }
91
- }
92
- };
93
- }
94
109
  bind() {
95
110
  super.bind();
96
111
  this.on("beforeCreate", this.listener);
97
112
  this.on("beforeBulkCreate", this.listener);
98
113
  this.on("beforeUpdate", this.listener);
114
+ this.on("beforeBulkUpdate", this.bulkUpdateListener);
99
115
  }
100
116
  unbind() {
101
117
  super.unbind();
102
118
  this.off("beforeCreate", this.listener);
103
119
  this.off("beforeBulkCreate", this.listener);
104
120
  this.off("beforeUpdate", this.listener);
121
+ this.off("beforeBulkUpdate", this.bulkUpdateListener);
105
122
  }
106
123
  };
107
124
  __name(_PasswordField, "PasswordField");
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "2.1.0-beta.46",
3
+ "version": "2.1.0-beta.48",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "Apache-2.0",
8
8
  "dependencies": {
9
- "@nocobase/logger": "2.1.0-beta.46",
10
- "@nocobase/utils": "2.1.0-beta.46",
9
+ "@nocobase/logger": "2.1.0-beta.48",
10
+ "@nocobase/utils": "2.1.0-beta.48",
11
11
  "async-mutex": "^0.3.2",
12
12
  "chalk": "^4.1.1",
13
13
  "cron-parser": "4.4.0",
@@ -38,5 +38,5 @@
38
38
  "url": "git+https://github.com/nocobase/nocobase.git",
39
39
  "directory": "packages/database"
40
40
  },
41
- "gitHead": "91fd3ab238a5ff58735bbfca04a8cb05d233b0af"
41
+ "gitHead": "f8c27a286db015c5e433b48241f14c0412e50530"
42
42
  }