@tachybase/database 0.23.41 → 0.23.47

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.
@@ -25,9 +25,9 @@ var import_collection = require("./collection");
25
25
  const _CollectionFactory = class _CollectionFactory {
26
26
  constructor(database) {
27
27
  this.database = database;
28
+ // Using a Map with the collection subclass as the key and options as the value
29
+ this.collectionTypes = /* @__PURE__ */ new Map();
28
30
  }
29
- // Using a Map with the collection subclass as the key and options as the value
30
- collectionTypes = /* @__PURE__ */ new Map();
31
31
  registerCollectionType(collectionClass, options) {
32
32
  this.collectionTypes.set(collectionClass, options);
33
33
  }
@@ -37,8 +37,6 @@ var import_path = __toESM(require("path"));
37
37
  var import_utils = require("@tachybase/utils");
38
38
  var import_lodash = require("lodash");
39
39
  const _ImporterReader = class _ImporterReader {
40
- directory;
41
- extensions;
42
40
  constructor(directory, extensions) {
43
41
  this.directory = directory;
44
42
  if (!extensions) {
package/lib/collection.js CHANGED
@@ -64,7 +64,6 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
64
64
  }
65
65
  return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
66
66
  };
67
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
68
67
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
69
68
  var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
70
69
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
@@ -112,12 +111,12 @@ const _Collection = class _Collection extends (_a = import_events.EventEmitter,
112
111
  constructor(options, context) {
113
112
  super();
114
113
  __runInitializers(_init, 5, this);
115
- __publicField(this, "options");
116
- __publicField(this, "context");
117
- __publicField(this, "isThrough");
118
- __publicField(this, "fields", /* @__PURE__ */ new Map());
119
- __publicField(this, "model");
120
- __publicField(this, "repository");
114
+ this.options = void 0;
115
+ this.context = void 0;
116
+ this.isThrough = void 0;
117
+ this.fields = /* @__PURE__ */ new Map();
118
+ this.model = void 0;
119
+ this.repository = void 0;
121
120
  this.context = context;
122
121
  this.options = options;
123
122
  this.checkOptions(options);
package/lib/database.js CHANGED
@@ -95,7 +95,6 @@ const DialectVersionAccessors = {
95
95
  }
96
96
  };
97
97
  const _DatabaseVersion = class _DatabaseVersion {
98
- db;
99
98
  constructor(db) {
100
99
  this.db = db;
101
100
  }
@@ -121,33 +120,25 @@ const _DatabaseVersion = class _DatabaseVersion {
121
120
  __name(_DatabaseVersion, "DatabaseVersion");
122
121
  let DatabaseVersion = _DatabaseVersion;
123
122
  const _Database = class _Database extends import_events.EventEmitter {
124
- sequelize;
125
- migrator;
126
- migrations;
127
- fieldTypes = /* @__PURE__ */ new Map();
128
- fieldValueParsers = /* @__PURE__ */ new Map();
129
- options;
130
- models = /* @__PURE__ */ new Map();
131
- repositories = /* @__PURE__ */ new Map();
132
- operators = /* @__PURE__ */ new Map();
133
- collections = /* @__PURE__ */ new Map();
134
- pendingFields = /* @__PURE__ */ new Map();
135
- modelCollection = /* @__PURE__ */ new Map();
136
- tableNameCollectionMap = /* @__PURE__ */ new Map();
137
- context = {};
138
- queryInterface;
139
- utils = new import_database_utils.default(this);
140
- referenceMap = new import_references_map.default();
141
- inheritanceMap = new import_inherited_map.default();
142
- importedFrom = /* @__PURE__ */ new Map();
143
- modelHook;
144
- version;
145
- delayCollectionExtend = /* @__PURE__ */ new Map();
146
- logger;
147
- collectionGroupManager = new import_collection_group_manager.CollectionGroupManager(this);
148
- collectionFactory = new import_collection_factory.CollectionFactory(this);
149
123
  constructor(options) {
150
124
  super();
125
+ this.fieldTypes = /* @__PURE__ */ new Map();
126
+ this.fieldValueParsers = /* @__PURE__ */ new Map();
127
+ this.models = /* @__PURE__ */ new Map();
128
+ this.repositories = /* @__PURE__ */ new Map();
129
+ this.operators = /* @__PURE__ */ new Map();
130
+ this.collections = /* @__PURE__ */ new Map();
131
+ this.pendingFields = /* @__PURE__ */ new Map();
132
+ this.modelCollection = /* @__PURE__ */ new Map();
133
+ this.tableNameCollectionMap = /* @__PURE__ */ new Map();
134
+ this.context = {};
135
+ this.utils = new import_database_utils.default(this);
136
+ this.referenceMap = new import_references_map.default();
137
+ this.inheritanceMap = new import_inherited_map.default();
138
+ this.importedFrom = /* @__PURE__ */ new Map();
139
+ this.delayCollectionExtend = /* @__PURE__ */ new Map();
140
+ this.collectionGroupManager = new import_collection_group_manager.CollectionGroupManager(this);
141
+ this.collectionFactory = new import_collection_factory.CollectionFactory(this);
151
142
  this.setMaxListeners(50);
152
143
  this.version = new DatabaseVersion(this);
153
144
  const opts = {
@@ -250,7 +241,6 @@ const _Database = class _Database extends import_events.EventEmitter {
250
241
  (0, import_utils2.patchSequelizeQueryInterface)(this);
251
242
  this.registerCollectionType();
252
243
  }
253
- _instanceId;
254
244
  get instanceId() {
255
245
  return this._instanceId;
256
246
  }
@@ -36,6 +36,37 @@ var import_sequelize = require("sequelize");
36
36
  var import_append_child_collection_name_after_repository_find = require("../listeners/append-child-collection-name-after-repository-find");
37
37
  var import_options_parser = require("../options-parser");
38
38
  var import_adjacency_list_repository = require("../repositories/tree-repository/adjacency-list-repository");
39
+ var import_sort_parser = __toESM(require("../sort-parser"));
40
+ function mergeInclude(left, right) {
41
+ const merged = [];
42
+ left.forEach((baseItem) => {
43
+ var _a;
44
+ const updateItem = right.find((updateItem2) => updateItem2.association === baseItem.association);
45
+ if (updateItem) {
46
+ const mergedInclude = ((_a = baseItem.include) == null ? void 0 : _a.map((baseInclude) => {
47
+ const updateInclude = updateItem.include ? updateItem.include.find((item) => item.association === baseInclude.association) : null;
48
+ return updateInclude ? mergeInclude([baseInclude], [updateInclude])[0] : baseInclude;
49
+ })) || [];
50
+ merged.push({
51
+ ...baseItem,
52
+ // 合并 baseItem 的其他属性
53
+ ...updateItem,
54
+ // 覆盖 baseItem 的属性
55
+ include: mergedInclude
56
+ // 合并后的 include
57
+ });
58
+ } else {
59
+ merged.push(baseItem);
60
+ }
61
+ });
62
+ right.forEach((updateItem) => {
63
+ if (!left.find((baseItem) => baseItem.association === updateItem.association)) {
64
+ merged.push(updateItem);
65
+ }
66
+ });
67
+ return merged;
68
+ }
69
+ __name(mergeInclude, "mergeInclude");
39
70
  const pushAttribute = /* @__PURE__ */ __name((node, attribute) => {
40
71
  if (import_lodash.default.isArray(node.attributes) && !node.attributes.includes(attribute)) {
41
72
  node.attributes.push(attribute);
@@ -59,10 +90,8 @@ const EagerLoadingNodeProto = {
59
90
  }
60
91
  };
61
92
  const _EagerLoadingTree = class _EagerLoadingTree {
62
- root;
63
- db;
64
- rootQueryOptions = {};
65
93
  constructor(root) {
94
+ this.rootQueryOptions = {};
66
95
  this.root = root;
67
96
  }
68
97
  static buildFromSequelizeOptions(options) {
@@ -144,7 +173,7 @@ const _EagerLoadingTree = class _EagerLoadingTree {
144
173
  return order;
145
174
  }, "orderOption");
146
175
  const loadRecursive = /* @__PURE__ */ __name(async (node, ids = []) => {
147
- var _a, _b;
176
+ var _a, _b, _c;
148
177
  let instances = [];
149
178
  if (!node.parent) {
150
179
  const rootInclude = ((_a = this.rootQueryOptions) == null ? void 0 : _a.include) || node.includeOption;
@@ -152,24 +181,13 @@ const _EagerLoadingTree = class _EagerLoadingTree {
152
181
  var _a2, _b2;
153
182
  return Object.keys(include.where || {}).length > 0 || ((_b2 = JSON.stringify((_a2 = this.rootQueryOptions) == null ? void 0 : _a2.filter)) == null ? void 0 : _b2.includes(include.association));
154
183
  });
155
- const sortModelSet = /* @__PURE__ */ new Set();
156
- if ((_b = this.rootQueryOptions) == null ? void 0 : _b.order) {
157
- for (const order of this.rootQueryOptions.order) {
158
- for (const field of order) {
159
- if (field.as) {
160
- sortModelSet.add(field.as);
161
- }
162
- }
163
- }
164
- }
165
- const inCludeForSort = [];
166
- for (const sortModel of sortModelSet) {
167
- if (includeForFilter.find((v) => v.association === sortModel)) {
168
- continue;
169
- }
170
- inCludeForSort.push({
171
- association: sortModel
172
- });
184
+ let includeForSort = [];
185
+ let groupForSort = [];
186
+ if ((_b = this.rootQueryOptions) == null ? void 0 : _b.sort) {
187
+ const sortParser = new import_sort_parser.default((_c = this.rootQueryOptions) == null ? void 0 : _c.sort, node.model);
188
+ const res = sortParser.toSequelizeParams();
189
+ includeForSort = res.include;
190
+ groupForSort = res.group;
173
191
  }
174
192
  const isBelongsToAssociationOnly = /* @__PURE__ */ __name((includes, model) => {
175
193
  for (const include of includes) {
@@ -186,13 +204,14 @@ const _EagerLoadingTree = class _EagerLoadingTree {
186
204
  }
187
205
  return true;
188
206
  }, "isBelongsToAssociationOnly");
189
- const belongsToAssociationsOnly = isBelongsToAssociationOnly(includeForFilter, node.model);
207
+ const includeForAll = mergeInclude(includeForFilter, includeForSort);
208
+ const belongsToAssociationsOnly = isBelongsToAssociationOnly(includeForAll, node.model);
190
209
  if (belongsToAssociationsOnly) {
191
210
  instances = await node.model.findAll({
192
211
  ...this.rootQueryOptions,
193
212
  attributes: node.attributes,
194
213
  distinct: true,
195
- include: includeForFilter.concat(inCludeForSort),
214
+ include: includeForAll,
196
215
  transaction
197
216
  });
198
217
  } else {
@@ -200,13 +219,14 @@ const _EagerLoadingTree = class _EagerLoadingTree {
200
219
  if (!primaryKeyField) {
201
220
  throw new Error(`Model ${node.model.name} does not have primary key`);
202
221
  }
222
+ const group = [`${node.model.name}.${primaryKeyField}`].concat(groupForSort);
203
223
  const ids2 = (await node.model.findAll({
204
224
  ...this.rootQueryOptions,
205
225
  includeIgnoreAttributes: false,
206
226
  attributes: [primaryKeyField],
207
- group: `${node.model.name}.${primaryKeyField}`,
227
+ group,
208
228
  transaction,
209
- include: includeForFilter.concat(inCludeForSort)
229
+ include: includeForAll
210
230
  })).map((row) => {
211
231
  return { row, pk: row[primaryKeyField] };
212
232
  });
@@ -219,7 +239,8 @@ const _EagerLoadingTree = class _EagerLoadingTree {
219
239
  }
220
240
  instances = await node.model.findAll({
221
241
  ...findOptions,
222
- transaction
242
+ transaction,
243
+ include: includeForSort
223
244
  });
224
245
  }
225
246
  const associations = node.model.associations;
@@ -47,7 +47,9 @@ const PRIORITY_MAP = {
47
47
  user: 2
48
48
  };
49
49
  const _ReferencesMap = class _ReferencesMap {
50
- map = /* @__PURE__ */ new Map();
50
+ constructor() {
51
+ this.map = /* @__PURE__ */ new Map();
52
+ }
51
53
  addReference(reference) {
52
54
  const existReference = this.existReference(reference);
53
55
  if (existReference && existReference.onDelete !== reference.onDelete) {
@@ -24,22 +24,25 @@ module.exports = __toCommonJS(array_field_exports);
24
24
  var import_sequelize = require("sequelize");
25
25
  var import_field = require("./field");
26
26
  const _ArrayField = class _ArrayField extends import_field.Field {
27
+ constructor() {
28
+ super(...arguments);
29
+ this.sortValue = /* @__PURE__ */ __name((model) => {
30
+ let oldValue = model.get(this.options.name);
31
+ if (oldValue) {
32
+ if (typeof oldValue === "string") {
33
+ oldValue = JSON.parse(oldValue);
34
+ }
35
+ const newValue = oldValue.sort();
36
+ model.set(this.options.name, newValue);
37
+ }
38
+ }, "sortValue");
39
+ }
27
40
  get dataType() {
28
41
  if (this.database.sequelize.getDialect() === "postgres") {
29
42
  return import_sequelize.DataTypes.JSONB;
30
43
  }
31
44
  return import_sequelize.DataTypes.JSON;
32
45
  }
33
- sortValue = /* @__PURE__ */ __name((model) => {
34
- let oldValue = model.get(this.options.name);
35
- if (oldValue) {
36
- if (typeof oldValue === "string") {
37
- oldValue = JSON.parse(oldValue);
38
- }
39
- const newValue = oldValue.sort();
40
- model.set(this.options.name, newValue);
41
- }
42
- }, "sortValue");
43
46
  bind() {
44
47
  super.bind();
45
48
  this.on("beforeSave", this.sortValue);
@@ -4,7 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
8
  var __export = (target, all) => {
10
9
  for (var name in all)
@@ -27,7 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
26
  mod
28
27
  ));
29
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
29
  var belongs_to_field_exports = {};
32
30
  __export(belongs_to_field_exports, {
33
31
  BelongsToField: () => BelongsToField
@@ -146,7 +144,7 @@ const _BelongsToField = class _BelongsToField extends import_relation_field.Rela
146
144
  }
147
145
  };
148
146
  __name(_BelongsToField, "BelongsToField");
149
- __publicField(_BelongsToField, "type", "belongsTo");
147
+ _BelongsToField.type = "belongsTo";
150
148
  let BelongsToField = _BelongsToField;
151
149
  // Annotate the CommonJS export names for ESM import in node:
152
150
  0 && (module.exports = {
@@ -35,16 +35,19 @@ var import_lodash = __toESM(require("lodash"));
35
35
  var import_sequelize = require("sequelize");
36
36
  var import_field = require("./field");
37
37
  const _ContextField = class _ContextField extends import_field.Field {
38
+ constructor() {
39
+ super(...arguments);
40
+ this.listener = /* @__PURE__ */ __name(async (model, options) => {
41
+ const { name, dataIndex } = this.options;
42
+ const { context } = options;
43
+ model.set(name, import_lodash.default.get(context, dataIndex));
44
+ model.changed(name, true);
45
+ }, "listener");
46
+ }
38
47
  get dataType() {
39
48
  const type = this.options.dataType || "string";
40
49
  return import_sequelize.DataTypes[type.toUpperCase()] || import_sequelize.DataTypes.STRING;
41
50
  }
42
- listener = /* @__PURE__ */ __name(async (model, options) => {
43
- const { name, dataIndex } = this.options;
44
- const { context } = options;
45
- model.set(name, import_lodash.default.get(context, dataIndex));
46
- model.changed(name, true);
47
- }, "listener");
48
51
  bind() {
49
52
  super.bind();
50
53
  const { createOnly } = this.options;
@@ -34,10 +34,6 @@ module.exports = __toCommonJS(field_exports);
34
34
  var import_lodash = __toESM(require("lodash"));
35
35
  var import_utils = require("../utils");
36
36
  const _Field = class _Field {
37
- options;
38
- context;
39
- database;
40
- collection;
41
37
  constructor(options, context) {
42
38
  this.context = context;
43
39
  this.database = this.context.database;
@@ -24,29 +24,32 @@ module.exports = __toCommonJS(radio_field_exports);
24
24
  var import_sequelize = require("sequelize");
25
25
  var import_field = require("./field");
26
26
  const _RadioField = class _RadioField extends import_field.Field {
27
+ constructor() {
28
+ super(...arguments);
29
+ this.listener = /* @__PURE__ */ __name(async (model, { transaction }) => {
30
+ const { name } = this.options;
31
+ if (!model.changed(name)) {
32
+ return;
33
+ }
34
+ const value = model.get(name);
35
+ if (value) {
36
+ const M = this.collection.model;
37
+ await M.update(
38
+ { [name]: false },
39
+ {
40
+ where: {
41
+ [name]: true
42
+ },
43
+ transaction,
44
+ hooks: false
45
+ }
46
+ );
47
+ }
48
+ }, "listener");
49
+ }
27
50
  get dataType() {
28
51
  return import_sequelize.DataTypes.BOOLEAN;
29
52
  }
30
- listener = /* @__PURE__ */ __name(async (model, { transaction }) => {
31
- const { name } = this.options;
32
- if (!model.changed(name)) {
33
- return;
34
- }
35
- const value = model.get(name);
36
- if (value) {
37
- const M = this.collection.model;
38
- await M.update(
39
- { [name]: false },
40
- {
41
- where: {
42
- [name]: true
43
- },
44
- transaction,
45
- hooks: false
46
- }
47
- );
48
- }
49
- }, "listener");
50
53
  bind() {
51
54
  super.bind();
52
55
  this.on("beforeCreate", this.listener);
@@ -23,12 +23,15 @@ __export(set_field_exports, {
23
23
  module.exports = __toCommonJS(set_field_exports);
24
24
  var import_array_field = require("./array-field");
25
25
  const _SetField = class _SetField extends import_array_field.ArrayField {
26
- beforeSave = /* @__PURE__ */ __name((model) => {
27
- const oldValue = model.get(this.options.name);
28
- if (oldValue) {
29
- model.set(this.options.name, [...new Set(oldValue)]);
30
- }
31
- }, "beforeSave");
26
+ constructor() {
27
+ super(...arguments);
28
+ this.beforeSave = /* @__PURE__ */ __name((model) => {
29
+ const oldValue = model.get(this.options.name);
30
+ if (oldValue) {
31
+ model.set(this.options.name, [...new Set(oldValue)]);
32
+ }
33
+ }, "beforeSave");
34
+ }
32
35
  bind() {
33
36
  super.bind();
34
37
  this.on("beforeSave", this.beforeSave);
@@ -27,87 +27,86 @@ var import_sequelize = require("sequelize");
27
27
  var import_field = require("./field");
28
28
  const sortFieldMutex = new import_async_mutex.Mutex();
29
29
  const _SortField = class _SortField extends import_field.Field {
30
- get dataType() {
31
- return import_sequelize.DataTypes.BIGINT;
32
- }
33
- setSortValue = /* @__PURE__ */ __name(async (instance, options) => {
34
- const { name, scopeKey } = this.options;
35
- const { model } = this.context.collection;
36
- if ((0, import_lodash.isNumber)(instance.get(name)) && instance._previousDataValues[scopeKey] == instance[scopeKey]) {
37
- return;
38
- }
39
- const where = {};
40
- if (scopeKey) {
41
- const value = instance.get(scopeKey);
42
- if (value !== void 0 && value !== null) {
43
- where[scopeKey] = value;
30
+ constructor() {
31
+ super(...arguments);
32
+ this.setSortValue = /* @__PURE__ */ __name(async (instance, options) => {
33
+ const { name, scopeKey } = this.options;
34
+ const { model } = this.context.collection;
35
+ if ((0, import_lodash.isNumber)(instance.get(name)) && instance._previousDataValues[scopeKey] == instance[scopeKey]) {
36
+ return;
44
37
  }
45
- }
46
- await sortFieldMutex.runExclusive(async () => {
47
- const max = await model.max(name, { ...options, where });
48
- const newValue = (max || 0) + 1;
49
- instance.set(name, newValue);
50
- });
51
- }, "setSortValue");
52
- onScopeChange = /* @__PURE__ */ __name(async (instance, options) => {
53
- const { scopeKey } = this.options;
54
- if (scopeKey && !instance.isNewRecord && instance._previousDataValues[scopeKey] != instance[scopeKey]) {
55
- await this.setSortValue(instance, options);
56
- }
57
- }, "onScopeChange");
58
- initRecordsSortValue = /* @__PURE__ */ __name(async ({ transaction }) => {
59
- const orderField = (() => {
60
- const model = this.collection.model;
61
- if (model.primaryKeyAttribute) {
62
- return model.primaryKeyAttribute;
63
- }
64
- if (model.rawAttributes["createdAt"]) {
65
- return model.rawAttributes["createdAt"].field;
66
- }
67
- throw new Error(`can not find order key for collection ${this.collection.name}`);
68
- })();
69
- const needInit = /* @__PURE__ */ __name(async (scopeKey2 = null, scopeValue = null) => {
70
- const filter = {};
71
- if (scopeKey2 && scopeValue) {
72
- filter[scopeKey2] = scopeValue;
38
+ const where = {};
39
+ if (scopeKey) {
40
+ const value = instance.get(scopeKey);
41
+ if (value !== void 0 && value !== null) {
42
+ where[scopeKey] = value;
43
+ }
73
44
  }
74
- const totalCount = await this.collection.repository.count({
75
- filter,
76
- transaction
45
+ await sortFieldMutex.runExclusive(async () => {
46
+ const max = await model.max(name, { ...options, where });
47
+ const newValue = (max || 0) + 1;
48
+ instance.set(name, newValue);
77
49
  });
78
- const emptyCount = await this.collection.repository.count({
79
- filter: {
80
- [this.name]: null,
81
- ...filter
82
- },
83
- transaction
84
- });
85
- return emptyCount === totalCount && emptyCount > 0;
86
- }, "needInit");
87
- const doInit = /* @__PURE__ */ __name(async (scopeKey2 = null, scopeValue = null) => {
88
- const queryInterface = this.collection.db.sequelize.getQueryInterface();
89
- if (scopeKey2) {
90
- const scopeAttribute = this.collection.model.rawAttributes[scopeKey2];
91
- if (!scopeAttribute) {
92
- throw new Error(`can not find scope field ${scopeKey2} for collection ${this.collection.name}`);
93
- }
94
- scopeKey2 = scopeAttribute.field;
50
+ }, "setSortValue");
51
+ this.onScopeChange = /* @__PURE__ */ __name(async (instance, options) => {
52
+ const { scopeKey } = this.options;
53
+ if (scopeKey && !instance.isNewRecord && instance._previousDataValues[scopeKey] != instance[scopeKey]) {
54
+ await this.setSortValue(instance, options);
95
55
  }
96
- const quotedOrderField = queryInterface.quoteIdentifier(orderField);
97
- const sortColumnName = queryInterface.quoteIdentifier(this.collection.model.rawAttributes[this.name].field);
98
- let sql;
99
- const whereClause = scopeKey2 && scopeValue ? (() => {
100
- const filteredScopeValue = scopeValue.filter((v) => v !== null);
101
- if (filteredScopeValue.length === 0) {
102
- return "";
56
+ }, "onScopeChange");
57
+ this.initRecordsSortValue = /* @__PURE__ */ __name(async ({ transaction }) => {
58
+ const orderField = (() => {
59
+ const model = this.collection.model;
60
+ if (model.primaryKeyAttribute) {
61
+ return model.primaryKeyAttribute;
62
+ }
63
+ if (model.rawAttributes["createdAt"]) {
64
+ return model.rawAttributes["createdAt"].field;
65
+ }
66
+ throw new Error(`can not find order key for collection ${this.collection.name}`);
67
+ })();
68
+ const needInit = /* @__PURE__ */ __name(async (scopeKey2 = null, scopeValue = null) => {
69
+ const filter = {};
70
+ if (scopeKey2 && scopeValue) {
71
+ filter[scopeKey2] = scopeValue;
72
+ }
73
+ const totalCount = await this.collection.repository.count({
74
+ filter,
75
+ transaction
76
+ });
77
+ const emptyCount = await this.collection.repository.count({
78
+ filter: {
79
+ [this.name]: null,
80
+ ...filter
81
+ },
82
+ transaction
83
+ });
84
+ return emptyCount === totalCount && emptyCount > 0;
85
+ }, "needInit");
86
+ const doInit = /* @__PURE__ */ __name(async (scopeKey2 = null, scopeValue = null) => {
87
+ const queryInterface = this.collection.db.sequelize.getQueryInterface();
88
+ if (scopeKey2) {
89
+ const scopeAttribute = this.collection.model.rawAttributes[scopeKey2];
90
+ if (!scopeAttribute) {
91
+ throw new Error(`can not find scope field ${scopeKey2} for collection ${this.collection.name}`);
92
+ }
93
+ scopeKey2 = scopeAttribute.field;
103
94
  }
104
- const initialClause = `
95
+ const quotedOrderField = queryInterface.quoteIdentifier(orderField);
96
+ const sortColumnName = queryInterface.quoteIdentifier(this.collection.model.rawAttributes[this.name].field);
97
+ let sql;
98
+ const whereClause = scopeKey2 && scopeValue ? (() => {
99
+ const filteredScopeValue = scopeValue.filter((v) => v !== null);
100
+ if (filteredScopeValue.length === 0) {
101
+ return "";
102
+ }
103
+ const initialClause = `
105
104
  WHERE ${queryInterface.quoteIdentifier(scopeKey2)} IN (${filteredScopeValue.map((v) => `'${v}'`).join(", ")})`;
106
- const nullCheck = scopeValue.includes(null) ? ` OR ${queryInterface.quoteIdentifier(scopeKey2)} IS NULL` : "";
107
- return initialClause + nullCheck;
108
- })() : "";
109
- if (this.collection.db.inDialect("postgres")) {
110
- sql = `
105
+ const nullCheck = scopeValue.includes(null) ? ` OR ${queryInterface.quoteIdentifier(scopeKey2)} IS NULL` : "";
106
+ return initialClause + nullCheck;
107
+ })() : "";
108
+ if (this.collection.db.inDialect("postgres")) {
109
+ sql = `
111
110
  UPDATE ${this.collection.quotedTableName()}
112
111
  SET ${sortColumnName} = ordered_table.new_sequence_number
113
112
  FROM (
@@ -117,8 +116,8 @@ const _SortField = class _SortField extends import_field.Field {
117
116
  ) AS ordered_table
118
117
  WHERE ${this.collection.quotedTableName()}.${quotedOrderField} = ordered_table.${quotedOrderField};
119
118
  `;
120
- } else if (this.collection.db.inDialect("sqlite")) {
121
- sql = `
119
+ } else if (this.collection.db.inDialect("sqlite")) {
120
+ sql = `
122
121
  UPDATE ${this.collection.quotedTableName()}
123
122
  SET ${sortColumnName} = (
124
123
  SELECT new_sequence_number
@@ -130,8 +129,8 @@ const _SortField = class _SortField extends import_field.Field {
130
129
  WHERE ${this.collection.quotedTableName()}.${quotedOrderField} = ordered_table.${quotedOrderField}
131
130
  );
132
131
  `;
133
- } else if (this.collection.db.inDialect("mysql") || this.collection.db.inDialect("mariadb")) {
134
- sql = `
132
+ } else if (this.collection.db.inDialect("mysql") || this.collection.db.inDialect("mariadb")) {
133
+ sql = `
135
134
  UPDATE ${this.collection.quotedTableName()}
136
135
  JOIN (
137
136
  SELECT *, ROW_NUMBER() OVER (${scopeKey2 ? `PARTITION BY ${queryInterface.quoteIdentifier(scopeKey2)}` : ""} ORDER BY ${quotedOrderField}) AS new_sequence_number
@@ -140,32 +139,36 @@ const _SortField = class _SortField extends import_field.Field {
140
139
  ) AS ordered_table ON ${this.collection.quotedTableName()}.${quotedOrderField} = ordered_table.${quotedOrderField}
141
140
  SET ${this.collection.quotedTableName()}.${sortColumnName} = ordered_table.new_sequence_number;
142
141
  `;
143
- }
144
- await this.collection.db.sequelize.query(sql, {
145
- transaction
146
- });
147
- }, "doInit");
148
- const scopeKey = this.options.scopeKey;
149
- if (scopeKey) {
150
- const groups = await this.collection.repository.find({
151
- attributes: [scopeKey],
152
- group: [scopeKey],
153
- raw: true,
154
- transaction
155
- });
156
- const needInitGroups = [];
157
- for (const group of groups) {
158
- if (await needInit(scopeKey, group[scopeKey])) {
159
- needInitGroups.push(group[scopeKey]);
160
142
  }
143
+ await this.collection.db.sequelize.query(sql, {
144
+ transaction
145
+ });
146
+ }, "doInit");
147
+ const scopeKey = this.options.scopeKey;
148
+ if (scopeKey) {
149
+ const groups = await this.collection.repository.find({
150
+ attributes: [scopeKey],
151
+ group: [scopeKey],
152
+ raw: true,
153
+ transaction
154
+ });
155
+ const needInitGroups = [];
156
+ for (const group of groups) {
157
+ if (await needInit(scopeKey, group[scopeKey])) {
158
+ needInitGroups.push(group[scopeKey]);
159
+ }
160
+ }
161
+ if (needInitGroups.length > 0) {
162
+ await doInit(scopeKey, needInitGroups);
163
+ }
164
+ } else if (await needInit()) {
165
+ await doInit();
161
166
  }
162
- if (needInitGroups.length > 0) {
163
- await doInit(scopeKey, needInitGroups);
164
- }
165
- } else if (await needInit()) {
166
- await doInit();
167
- }
168
- }, "initRecordsSortValue");
167
+ }, "initRecordsSortValue");
168
+ }
169
+ get dataType() {
170
+ return import_sequelize.DataTypes.BIGINT;
171
+ }
169
172
  bind() {
170
173
  super.bind();
171
174
  this.on("afterSync", this.initRecordsSortValue);
@@ -35,11 +35,6 @@ var import_flat = require("flat");
35
35
  var import_lodash = __toESM(require("lodash"));
36
36
  const debug = require("debug")("noco-database");
37
37
  const _FilterParser = class _FilterParser {
38
- collection;
39
- database;
40
- model;
41
- filter;
42
- context;
43
38
  constructor(filter, context) {
44
39
  const { collection } = context;
45
40
  this.collection = collection;
@@ -34,7 +34,6 @@ module.exports = __toCommonJS(inherited_collection_exports);
34
34
  var import_lodash = __toESM(require("lodash"));
35
35
  var import_collection = require("./collection");
36
36
  const _InheritedCollection = class _InheritedCollection extends import_collection.Collection {
37
- parents;
38
37
  constructor(options, context) {
39
38
  if (!options.inherits) {
40
39
  throw new Error("InheritedCollection must have inherits option");
@@ -33,9 +33,6 @@ __export(inherited_map_exports, {
33
33
  module.exports = __toCommonJS(inherited_map_exports);
34
34
  var import_lodash = __toESM(require("lodash"));
35
35
  const _TableNode = class _TableNode {
36
- name;
37
- parents;
38
- children;
39
36
  constructor(name) {
40
37
  this.name = name;
41
38
  this.parents = /* @__PURE__ */ new Set();
@@ -45,7 +42,9 @@ const _TableNode = class _TableNode {
45
42
  __name(_TableNode, "TableNode");
46
43
  let TableNode = _TableNode;
47
44
  const _InheritanceMap = class _InheritanceMap {
48
- nodes = /* @__PURE__ */ new Map();
45
+ constructor() {
46
+ this.nodes = /* @__PURE__ */ new Map();
47
+ }
49
48
  removeNode(name) {
50
49
  const node = this.nodes.get(name);
51
50
  if (!node) return;
package/lib/migration.js CHANGED
@@ -35,8 +35,6 @@ module.exports = __toCommonJS(migration_exports);
35
35
  var import_utils = require("@tachybase/utils");
36
36
  var import_lodash = __toESM(require("lodash"));
37
37
  const _Migration = class _Migration {
38
- name;
39
- context;
40
38
  constructor(context) {
41
39
  this.context = context;
42
40
  }
@@ -57,9 +55,8 @@ const _Migration = class _Migration {
57
55
  __name(_Migration, "Migration");
58
56
  let Migration = _Migration;
59
57
  const _Migrations = class _Migrations {
60
- items = [];
61
- context;
62
58
  constructor(context) {
59
+ this.items = [];
63
60
  this.context = context;
64
61
  }
65
62
  clear() {
package/lib/model-hook.js CHANGED
@@ -34,9 +34,8 @@ module.exports = __toCommonJS(model_hook_exports);
34
34
  var import_lodash = __toESM(require("lodash"));
35
35
  const { hooks } = require("sequelize/lib/hooks");
36
36
  const _ModelHook = class _ModelHook {
37
- database;
38
- boundEvents = /* @__PURE__ */ new Set();
39
37
  constructor(database) {
38
+ this.boundEvents = /* @__PURE__ */ new Set();
40
39
  this.database = database;
41
40
  }
42
41
  match(event) {
package/lib/model.js CHANGED
@@ -4,7 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
8
  var __export = (target, all) => {
10
9
  for (var name in all)
@@ -27,7 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
26
  mod
28
27
  ));
29
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
29
  var model_exports = {};
32
30
  __export(model_exports, {
33
31
  Model: () => Model
@@ -38,8 +36,11 @@ var import_sequelize = require("sequelize");
38
36
  var import_sync_runner = require("./sync-runner");
39
37
  const _ = import_lodash.default;
40
38
  const _Model = class _Model extends import_sequelize.Model {
41
- _changedWithAssociations = /* @__PURE__ */ new Set();
42
- _previousDataValuesWithAssociations = {};
39
+ constructor() {
40
+ super(...arguments);
41
+ this._changedWithAssociations = /* @__PURE__ */ new Set();
42
+ this._previousDataValuesWithAssociations = {};
43
+ }
43
44
  get db() {
44
45
  return this.constructor.database;
45
46
  }
@@ -143,8 +144,6 @@ const _Model = class _Model extends import_sequelize.Model {
143
144
  }
144
145
  };
145
146
  __name(_Model, "Model");
146
- __publicField(_Model, "database");
147
- __publicField(_Model, "collection");
148
147
  let Model = _Model;
149
148
  // Annotate the CommonJS export names for ESM import in node:
150
149
  0 && (module.exports = {
@@ -37,12 +37,6 @@ var import_sequelize = require("sequelize");
37
37
  var import_filter_parser = __toESM(require("./filter-parser"));
38
38
  const debug = require("debug")("noco-database");
39
39
  const _OptionsParser = class _OptionsParser {
40
- options;
41
- database;
42
- collection;
43
- model;
44
- filterParser;
45
- context;
46
40
  constructor(options, context) {
47
41
  const { collection } = context;
48
42
  this.collection = collection;
@@ -26,7 +26,6 @@ const _QueryInterface = class _QueryInterface {
26
26
  this.db = db;
27
27
  this.sequelizeQueryInterface = db.sequelize.getQueryInterface();
28
28
  }
29
- sequelizeQueryInterface;
30
29
  async dropAll(options) {
31
30
  if (options.drop !== true) return;
32
31
  const views = await this.listViews();
@@ -64,7 +64,6 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
64
64
  }
65
65
  return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
66
66
  };
67
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
68
67
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
69
68
  var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
70
69
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
@@ -90,15 +89,15 @@ _create_dec = [transaction()];
90
89
  const _RelationRepository = class _RelationRepository {
91
90
  constructor(sourceCollection, association, sourceKeyValue) {
92
91
  __runInitializers(_init, 5, this);
93
- __publicField(this, "sourceCollection");
94
- __publicField(this, "association");
95
- __publicField(this, "targetModel");
96
- __publicField(this, "targetCollection");
97
- __publicField(this, "associationName");
98
- __publicField(this, "associationField");
99
- __publicField(this, "sourceKeyValue");
100
- __publicField(this, "sourceInstance");
101
- __publicField(this, "db");
92
+ this.sourceCollection = void 0;
93
+ this.association = void 0;
94
+ this.targetModel = void 0;
95
+ this.targetCollection = void 0;
96
+ this.associationName = void 0;
97
+ this.associationField = void 0;
98
+ this.sourceKeyValue = void 0;
99
+ this.sourceInstance = void 0;
100
+ this.db = void 0;
102
101
  this.db = sourceCollection.context.database;
103
102
  this.sourceCollection = sourceCollection;
104
103
  this.sourceKeyValue = sourceKeyValue;
package/lib/repository.js CHANGED
@@ -64,7 +64,6 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
64
64
  }
65
65
  return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
66
66
  };
67
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
68
67
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
69
68
  var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
70
69
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
@@ -98,17 +97,14 @@ const transaction = (0, import_transaction_decorator.transactionWrapperBuilder)(
98
97
  return this.collection.model.sequelize.transaction();
99
98
  });
100
99
  const _RelationRepositoryBuilder = class _RelationRepositoryBuilder {
101
- collection;
102
- associationName;
103
- association;
104
- builderMap = {
105
- HasOne: import_hasone_repository.HasOneRepository,
106
- BelongsTo: import_belongs_to_repository.BelongsToRepository,
107
- BelongsToMany: import_belongs_to_many_repository.BelongsToManyRepository,
108
- HasMany: import_hasmany_repository.HasManyRepository,
109
- ArrayField: import_array_field_repository.ArrayFieldRepository
110
- };
111
100
  constructor(collection, associationName) {
101
+ this.builderMap = {
102
+ HasOne: import_hasone_repository.HasOneRepository,
103
+ BelongsTo: import_belongs_to_repository.BelongsToRepository,
104
+ BelongsToMany: import_belongs_to_many_repository.BelongsToManyRepository,
105
+ HasMany: import_hasmany_repository.HasManyRepository,
106
+ ArrayField: import_array_field_repository.ArrayFieldRepository
107
+ };
112
108
  this.collection = collection;
113
109
  this.associationName = associationName;
114
110
  this.association = this.collection.model.associations[this.associationName];
@@ -143,9 +139,9 @@ _create_dec = [transaction()], _createMany_dec = [transaction()], _update_dec =
143
139
  const _Repository = class _Repository {
144
140
  constructor(collection) {
145
141
  __runInitializers(_init, 5, this);
146
- __publicField(this, "database");
147
- __publicField(this, "collection");
148
- __publicField(this, "model");
142
+ this.database = void 0;
143
+ this.collection = void 0;
144
+ this.model = void 0;
149
145
  this.database = collection.context.database;
150
146
  this.collection = collection;
151
147
  this.model = collection.model;
@@ -0,0 +1,11 @@
1
+ import { ModelStatic } from 'sequelize';
2
+ import { Model } from './model';
3
+ type sortType = string[];
4
+ export default class SortParser {
5
+ model: ModelStatic<Model>;
6
+ sort: string | string[];
7
+ constructor(sort: sortType, model: ModelStatic<Model>);
8
+ toSequelizeParams(): any;
9
+ getGroup(): string[];
10
+ }
11
+ export {};
@@ -0,0 +1,135 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var sort_parser_exports = {};
30
+ __export(sort_parser_exports, {
31
+ default: () => SortParser
32
+ });
33
+ module.exports = __toCommonJS(sort_parser_exports);
34
+ var import_lodash = __toESM(require("lodash"));
35
+ const debug = require("debug")("noco-database");
36
+ const _SortParser = class _SortParser {
37
+ constructor(sort, model) {
38
+ this.model = model;
39
+ this.sort = sort;
40
+ }
41
+ toSequelizeParams() {
42
+ debug("sort %o", this.sort);
43
+ if (!this.sort) {
44
+ return {};
45
+ }
46
+ const model = this.model;
47
+ const include = {};
48
+ const associations = model.associations;
49
+ const group = this.getGroup();
50
+ debug("associations %O", associations);
51
+ for (const sort of group) {
52
+ const keys = sort.split(".");
53
+ const origins = [];
54
+ while (keys.length) {
55
+ const firstKey = keys.shift();
56
+ origins.push(firstKey);
57
+ if (!import_lodash.default.isNaN(parseInt(firstKey))) {
58
+ continue;
59
+ }
60
+ if (!associations[firstKey]) {
61
+ continue;
62
+ }
63
+ const associationKeys = [];
64
+ associationKeys.push(firstKey);
65
+ debug("associationKeys %o", associationKeys);
66
+ const existInclude = import_lodash.default.get(include, firstKey);
67
+ if (!existInclude) {
68
+ import_lodash.default.set(include, firstKey, {
69
+ association: firstKey,
70
+ attributes: []
71
+ // out put empty fields by default
72
+ });
73
+ }
74
+ let target = associations[firstKey].target;
75
+ debug("association target %o", target);
76
+ while (target) {
77
+ const attr = keys.shift();
78
+ origins.push(attr);
79
+ if (target.rawAttributes[attr]) {
80
+ associationKeys.push(target.rawAttributes[attr].field || attr);
81
+ target = null;
82
+ } else if (target.associations[attr]) {
83
+ associationKeys.push(attr);
84
+ const assoc = [];
85
+ associationKeys.forEach((associationKey, index) => {
86
+ if (index > 0) {
87
+ assoc.push("include");
88
+ }
89
+ assoc.push(associationKey);
90
+ });
91
+ const existInclude2 = import_lodash.default.get(include, assoc);
92
+ if (!existInclude2) {
93
+ import_lodash.default.set(include, assoc, {
94
+ association: attr,
95
+ attributes: []
96
+ });
97
+ }
98
+ target = target.associations[attr].target;
99
+ } else {
100
+ throw new Error(`${attr} neither ${firstKey}'s association nor ${firstKey}'s attribute`);
101
+ }
102
+ }
103
+ debug("associationKeys %o", associationKeys);
104
+ }
105
+ }
106
+ const toInclude = /* @__PURE__ */ __name((items) => {
107
+ return Object.values(items).map((item) => {
108
+ if (item.include) {
109
+ item.include = toInclude(item.include);
110
+ }
111
+ return item;
112
+ });
113
+ }, "toInclude");
114
+ debug("include %o", include);
115
+ const results = { include: toInclude(include), group };
116
+ const traverseInclude = /* @__PURE__ */ __name((include2) => {
117
+ for (const item of include2) {
118
+ if (item.include) {
119
+ traverseInclude(item.include);
120
+ }
121
+ }
122
+ }, "traverseInclude");
123
+ traverseInclude(results.include);
124
+ return results;
125
+ }
126
+ getGroup() {
127
+ if (!this.sort) {
128
+ return [];
129
+ }
130
+ let sortList = typeof this.sort === "string" ? [this.sort] : this.sort;
131
+ return sortList.filter((v) => v.includes(".")).map((v) => v.startsWith("-") ? v.substring(1) : v);
132
+ }
133
+ };
134
+ __name(_SortParser, "SortParser");
135
+ let SortParser = _SortParser;
@@ -4,7 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
8
  var __export = (target, all) => {
10
9
  for (var name in all)
@@ -27,7 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
26
  mod
28
27
  ));
29
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
29
  var sql_model_exports = {};
32
30
  __export(sql_model_exports, {
33
31
  SQLModel: () => SQLModel
@@ -160,7 +158,6 @@ const _SQLModel = class _SQLModel extends import_model.Model {
160
158
  }
161
159
  };
162
160
  __name(_SQLModel, "SQLModel");
163
- __publicField(_SQLModel, "sql");
164
161
  let SQLModel = _SQLModel;
165
162
  // Annotate the CommonJS export names for ESM import in node:
166
163
  0 && (module.exports = {
@@ -28,12 +28,10 @@ var import_inherited_sync_runner = require("./inherited-sync-runner");
28
28
  const _SyncRunner = class _SyncRunner {
29
29
  constructor(model) {
30
30
  this.model = model;
31
+ this.tableDescMap = {};
31
32
  this.collection = model.collection;
32
33
  this.database = model.database;
33
34
  }
34
- collection;
35
- database;
36
- tableDescMap = {};
37
35
  get tableName() {
38
36
  return this.model.getTableName();
39
37
  }
@@ -34,12 +34,6 @@ module.exports = __toCommonJS(update_guard_exports);
34
34
  var import_lodash = __toESM(require("lodash"));
35
35
  var import_model = require("./model");
36
36
  const _UpdateGuard = class _UpdateGuard {
37
- model;
38
- action;
39
- underscored;
40
- associationKeysToBeUpdate;
41
- blackList;
42
- whiteList;
43
37
  static fromOptions(model, options) {
44
38
  const guard = new _UpdateGuard();
45
39
  guard.setModel(model);
@@ -22,11 +22,8 @@ __export(base_value_parser_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(base_value_parser_exports);
24
24
  const _BaseValueParser = class _BaseValueParser {
25
- ctx;
26
- field;
27
- value;
28
- errors = [];
29
25
  constructor(field, ctx) {
26
+ this.errors = [];
30
27
  this.field = field;
31
28
  this.ctx = ctx;
32
29
  this.value = null;
@@ -24,10 +24,13 @@ module.exports = __toCommonJS(to_many_value_parser_exports);
24
24
  var import_path = require("path");
25
25
  var import_base_value_parser = require("./base-value-parser");
26
26
  const _ToManyValueParser = class _ToManyValueParser extends import_base_value_parser.BaseValueParser {
27
- setAccessors = {
28
- attachment: "setAttachments",
29
- chinaRegion: "setChinaRegion"
30
- };
27
+ constructor() {
28
+ super(...arguments);
29
+ this.setAccessors = {
30
+ attachment: "setAttachments",
31
+ chinaRegion: "setChinaRegion"
32
+ };
33
+ }
31
34
  async setAttachments(value) {
32
35
  this.value = this.toArr(value).map((url) => {
33
36
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/database",
3
- "version": "0.23.41",
3
+ "version": "0.23.47",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./lib/index.js",
@@ -24,8 +24,8 @@
24
24
  "semver": "^7.6.3",
25
25
  "sequelize": "^6.37.5",
26
26
  "umzug": "^3.8.2",
27
- "@tachybase/logger": "0.23.41",
28
- "@tachybase/utils": "0.23.41"
27
+ "@tachybase/logger": "0.23.47",
28
+ "@tachybase/utils": "0.23.47"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/flat": "^5.0.5",