@tachybase/module-collection 1.6.0 → 1.6.1

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.
@@ -1,10 +1,10 @@
1
1
  module.exports = {
2
- "@tachybase/client": "1.6.0",
3
- "@tachybase/module-error-handler": "1.6.0",
4
- "@tego/server": "1.3.52",
2
+ "@tachybase/client": "1.6.1",
3
+ "@tachybase/module-error-handler": "1.6.1",
4
+ "@tego/server": "1.6.0-alpha.9",
5
5
  "async-mutex": "0.5.0",
6
6
  "lodash": "4.17.21",
7
- "@tachybase/test": "1.3.52",
7
+ "@tachybase/test": "1.6.0-alpha.9",
8
8
  "sequelize": "6.37.5",
9
9
  "dayjs": "1.11.13"
10
10
  };
@@ -30,7 +30,7 @@ class set_collection_schema_default extends import_server.Migration {
30
30
  if (!this.db.inDialect("postgres")) {
31
31
  return;
32
32
  }
33
- if (this.context.app.name !== "main") {
33
+ if (this.context.tego.name !== "main") {
34
34
  return;
35
35
  }
36
36
  const userCollections = await this.db.getRepository("collections").find({
@@ -43,6 +43,6 @@ class set_collection_schema_default extends import_server.Migration {
43
43
  await collection.set("schema", process.env.COLLECTION_MANAGER_SCHEMA || this.db.options.schema || "public");
44
44
  await collection.save();
45
45
  }
46
- await this.context.app.emitAsync("loadCollections");
46
+ await this.context.tego.emitAsync("loadCollections");
47
47
  }
48
48
  }
@@ -24,13 +24,13 @@ var collections_default = {
24
24
  async ["collections:setFields"](ctx, next) {
25
25
  var _a;
26
26
  const { filterByTk, values } = ctx.action.params;
27
- const transaction = await ctx.app.db.sequelize.transaction();
27
+ const transaction = await ctx.tego.db.sequelize.transaction();
28
28
  try {
29
29
  const fields = (_a = values.fields) == null ? void 0 : _a.map((f) => {
30
30
  delete f.key;
31
31
  return f;
32
32
  });
33
- const db = ctx.app.db;
33
+ const db = ctx.tego.db;
34
34
  const collectionModel = await db.getRepository("collections").findOne({
35
35
  filter: {
36
36
  name: filterByTk
@@ -75,7 +75,7 @@ var sql_default = {
75
75
  await next();
76
76
  },
77
77
  setFields: async (ctx, next) => {
78
- const transaction = await ctx.app.db.sequelize.transaction();
78
+ const transaction = await ctx.tego.db.sequelize.transaction();
79
79
  try {
80
80
  const {
81
81
  upRes: [collection]
@@ -91,7 +91,7 @@ var sql_default = {
91
91
  await next();
92
92
  },
93
93
  update: async (ctx, next) => {
94
- const transaction = await ctx.app.db.sequelize.transaction();
94
+ const transaction = await ctx.tego.db.sequelize.transaction();
95
95
  try {
96
96
  const { upRes } = await updateCollection(ctx, transaction);
97
97
  const [collection] = upRes;
@@ -26,7 +26,7 @@ var views_default = {
26
26
  actions: {
27
27
  async get(ctx, next) {
28
28
  const { filterByTk, schema } = ctx.action.params;
29
- const db = ctx.app.db;
29
+ const db = ctx.tego.db;
30
30
  const fields = await import_server.ViewFieldInference.inferFields({
31
31
  db,
32
32
  viewName: filterByTk,
@@ -43,7 +43,7 @@ var views_default = {
43
43
  await next();
44
44
  },
45
45
  list: async function(ctx, next) {
46
- const db = ctx.app.db;
46
+ const db = ctx.tego.db;
47
47
  const dbViews = await db.queryInterface.listViews();
48
48
  const viewCollections = Array.from(db.collections.values()).filter((collection) => collection.isView());
49
49
  ctx.body = dbViews.map((dbView) => {
@@ -65,10 +65,10 @@ var views_default = {
65
65
  const offset = (page - 1) * pageSize;
66
66
  const limit = 1 * pageSize;
67
67
  const sql = `SELECT *
68
- FROM ${ctx.app.db.utils.quoteTable(
69
- ctx.app.db.utils.addSchema(filterByTk, schema)
68
+ FROM ${ctx.tego.db.utils.quoteTable(
69
+ ctx.tego.db.utils.addSchema(filterByTk, schema)
70
70
  )} LIMIT ${limit} OFFSET ${offset}`;
71
- const rawValues = await ctx.app.db.sequelize.query(sql, { type: "SELECT" });
71
+ const rawValues = await ctx.tego.db.sequelize.query(sql, { type: "SELECT" });
72
72
  if (fieldTypes) {
73
73
  for (const raw of rawValues) {
74
74
  const fakeInstance = {
@@ -77,11 +77,11 @@ var views_default = {
77
77
  };
78
78
  for (const fieldName of Object.keys(fieldTypes)) {
79
79
  const fieldType = fieldTypes[fieldName];
80
- const FieldClass = ctx.app.db.fieldTypes.get(fieldType);
80
+ const FieldClass = ctx.tego.db.fieldTypes.get(fieldType);
81
81
  const fieldOptions = new FieldClass(
82
82
  { name: fieldName },
83
83
  {
84
- db: ctx.app.db
84
+ db: ctx.tego.db
85
85
  }
86
86
  ).options;
87
87
  if (fieldOptions.get) {
@@ -211,7 +211,7 @@ class CollectionManagerPlugin extends import_server.Plugin {
211
211
  });
212
212
  });
213
213
  const loadCollections = async () => {
214
- this.log.debug("loading custom collections", { method: "loadCollections" });
214
+ this.app.logger.debug("loading custom collections", { method: "loadCollections" });
215
215
  this.app.setMaintainingMessage("loading custom collections");
216
216
  await this.app.db.getRepository("collections").load({
217
217
  filter: this.loadFilter
@@ -240,8 +240,7 @@ class CollectionManagerPlugin extends import_server.Plugin {
240
240
  this.app.resourcer.define(import_collectionImportExportMeta.collectionImportExportMeta);
241
241
  }
242
242
  async load() {
243
- await this.importCollections(import_node_path.default.resolve(__dirname, "./collections"));
244
- this.db.getRepository("collections").setApp(this.app);
243
+ this.app.db.getRepository("collections").setApp(this.app);
245
244
  const errorHandlerPlugin = this.app.getPlugin("error-handler");
246
245
  errorHandlerPlugin.errorHandler.register(
247
246
  (err) => {
@@ -262,9 +261,9 @@ class CollectionManagerPlugin extends import_server.Plugin {
262
261
  },
263
262
  { tag: "setReverseFieldOnFieldChange" }
264
263
  );
265
- this.app.resource(import_views.default);
266
- this.app.resource(import_sql.default);
267
- this.app.actions(import_collections.default);
264
+ this.app.resourcer.define(import_views.default);
265
+ this.app.resourcer.define(import_sql.default);
266
+ this.app.resourcer.registerActions(import_collections.default);
268
267
  const handleFieldSource = (fields) => {
269
268
  var _a;
270
269
  for (const field of import_lodash.default.castArray(fields)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/module-collection",
3
3
  "displayName": "Data source: Main",
4
- "version": "1.6.0",
4
+ "version": "1.6.1",
5
5
  "description": "TachyBase main database, supports relational databases such as MySQL, PostgreSQL, SQLite and so on.",
6
6
  "keywords": [
7
7
  "Data sources"
@@ -11,16 +11,16 @@
11
11
  "dependencies": {},
12
12
  "devDependencies": {
13
13
  "@hapi/topo": "^6.0.2",
14
- "@tachybase/test": "1.3.52",
15
- "@tego/client": "1.3.52",
16
- "@tego/server": "1.3.52",
14
+ "@tachybase/test": "1.6.0-alpha.9",
15
+ "@tego/client": "1.6.0-alpha.9",
16
+ "@tego/server": "1.6.0-alpha.9",
17
17
  "@types/lodash": "^4.17.20",
18
18
  "async-mutex": "^0.5.0",
19
19
  "lodash": "4.17.21",
20
20
  "sequelize": "6.37.5",
21
21
  "toposort": "^2.0.2",
22
- "@tachybase/client": "1.6.0",
23
- "@tachybase/module-error-handler": "1.6.0"
22
+ "@tachybase/client": "1.6.1",
23
+ "@tachybase/module-error-handler": "1.6.1"
24
24
  },
25
25
  "description.zh-CN": "TachyBase 主数据库,支持 MySQL、PostgreSQL、SQLite 等关系型数据库。",
26
26
  "displayName.zh-CN": "数据源:主数据库",