@tachybase/actions 1.3.9 → 1.3.11

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.
Files changed (2) hide show
  1. package/lib/actions/list.js +15 -12
  2. package/package.json +5 -5
@@ -31,7 +31,7 @@ __export(list_exports, {
31
31
  list: () => list
32
32
  });
33
33
  module.exports = __toCommonJS(list_exports);
34
- var import_querystring = __toESM(require("querystring"));
34
+ var import_node_querystring = __toESM(require("node:querystring"));
35
35
  var import_utils = require("@tachybase/utils");
36
36
  var import_sequelize = require("sequelize");
37
37
  var import_constants = require("../constants");
@@ -42,7 +42,7 @@ function totalPage(total, pageSize) {
42
42
  __name(totalPage, "totalPage");
43
43
  const MAX_ASSOCIATION_SORT_DEPTH = 2;
44
44
  function findArgs(ctx) {
45
- var _a, _b, _c;
45
+ var _a, _b, _c, _d, _e;
46
46
  const resourceName = ctx.action.resourceName;
47
47
  const params = ctx.action.params;
48
48
  const includeSort = ((_a = params.sort) == null ? void 0 : _a.filter((item) => typeof item === "string" && item.split(".").length > 1)) ?? [];
@@ -67,7 +67,7 @@ function findArgs(ctx) {
67
67
  var _a2;
68
68
  const i = ((_a2 = params.appends) == null ? void 0 : _a2.findIndex((append) => append === item.prefix)) ?? -1;
69
69
  if (i !== -1) {
70
- params.appends[i] = `${item.prefix}(${import_querystring.default.stringify({ sort: item.sortItems })})`;
70
+ params.appends[i] = `${item.prefix}(${import_node_querystring.default.stringify({ sort: item.sortItems })})`;
71
71
  } else if (item.prefix) {
72
72
  associationAppend.add(item.prefix);
73
73
  }
@@ -85,7 +85,7 @@ function findArgs(ctx) {
85
85
  const [collectionName, associationName] = resourceName.split(".");
86
86
  const collection = ctx.db.getCollection(resourceName);
87
87
  if (collection.options.tree && !(associationName && collectionName === collection.name)) {
88
- const foreignKey = ((_c = collection.treeParentField) == null ? void 0 : _c.foreignKey) || "parentId";
88
+ const foreignKey = ((_e = (_d = collection.treeParentField) == null ? void 0 : _d.collection.model.rawAttributes[(_c = collection.treeParentField) == null ? void 0 : _c.foreignKey]) == null ? void 0 : _e.field) || "parentId";
89
89
  (0, import_utils.assign)(params, { filter: { [foreignKey]: null } }, { filter: "andMerge" });
90
90
  }
91
91
  }
@@ -94,7 +94,7 @@ function findArgs(ctx) {
94
94
  }
95
95
  __name(findArgs, "findArgs");
96
96
  async function listWithPagination(ctx) {
97
- var _a;
97
+ var _a, _b, _c;
98
98
  const { page = import_constants.DEFAULT_PAGE, pageSize = import_constants.DEFAULT_PER_PAGE } = ctx.action.params;
99
99
  const repository = (0, import_utils2.getRepositoryFromParams)(ctx);
100
100
  const resourceName = ctx.action.resourceName;
@@ -112,7 +112,10 @@ async function listWithPagination(ctx) {
112
112
  let filterTreeData = [];
113
113
  let filterTreeCount = 0;
114
114
  if (ctx.action.params.tree && options.filter) {
115
- const foreignKey = ((_a = collection.treeParentField) == null ? void 0 : _a.foreignKey) || "parentId";
115
+ let foreignKey = ((_c = (_b = collection.treeParentField) == null ? void 0 : _b.collection.model.rawAttributes[(_a = collection.treeParentField) == null ? void 0 : _a.foreignKey]) == null ? void 0 : _c.field) || "parentId";
116
+ if (!ctx.db.isMySQLCompatibleDialect()) {
117
+ foreignKey = `"${foreignKey}"`;
118
+ }
116
119
  const params = Object.values(options.filter).flat()[0] || {};
117
120
  let dataIds = [];
118
121
  if (Object.entries(params).length) {
@@ -127,26 +130,26 @@ async function listWithPagination(ctx) {
127
130
  for (const dataId of dataIds) {
128
131
  const query = `
129
132
  WITH RECURSIVE tree1 AS (
130
- SELECT id, "${foreignKey}"
133
+ SELECT id, ${foreignKey}
131
134
  FROM ${collection.name}
132
135
  WHERE id = :dataId
133
136
 
134
137
  UNION ALL
135
138
 
136
- SELECT p.id, p."${foreignKey}"
139
+ SELECT p.id, p.${foreignKey}
137
140
  FROM tree1 up
138
- JOIN ${collection.name} p ON up."${foreignKey}" = p.id
141
+ JOIN ${collection.name} p ON up.${foreignKey} = p.id
139
142
  ),
140
143
  tree2 AS (
141
- SELECT id, "${foreignKey}"
144
+ SELECT id, ${foreignKey}
142
145
  FROM ${collection.name}
143
146
  WHERE id = :dataId
144
147
 
145
148
  UNION ALL
146
149
 
147
- SELECT p.id, p."${foreignKey}"
150
+ SELECT p.id, p.${foreignKey}
148
151
  FROM tree2 down
149
- JOIN ${collection.name} p ON down.id = p."${foreignKey}"
152
+ JOIN ${collection.name} p ON down.id = p.${foreignKey}
150
153
  )
151
154
  SELECT DISTINCT *
152
155
  FROM (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/actions",
3
- "version": "1.3.9",
3
+ "version": "1.3.11",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./lib/index.js",
@@ -9,10 +9,10 @@
9
9
  "koa": "^2.15.3",
10
10
  "lodash": "4.17.21",
11
11
  "sequelize": "^6.37.5",
12
- "@tachybase/cache": "1.3.9",
13
- "@tachybase/database": "1.3.9",
14
- "@tachybase/resourcer": "1.3.9",
15
- "@tachybase/utils": "1.3.9"
12
+ "@tachybase/cache": "1.3.11",
13
+ "@tachybase/resourcer": "1.3.11",
14
+ "@tachybase/utils": "1.3.11",
15
+ "@tachybase/database": "1.3.11"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/koa": "^2.15.0",