@tachybase/actions 0.23.8
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.
- package/.turbo/turbo-build.log +9 -0
- package/LICENSE +201 -0
- package/lib/actions/add.d.ts +2 -0
- package/lib/actions/add.js +40 -0
- package/lib/actions/count.d.ts +2 -0
- package/lib/actions/count.js +39 -0
- package/lib/actions/create.d.ts +2 -0
- package/lib/actions/create.js +42 -0
- package/lib/actions/destroy.d.ts +2 -0
- package/lib/actions/destroy.js +40 -0
- package/lib/actions/first-or-create.d.ts +1 -0
- package/lib/actions/first-or-create.js +28 -0
- package/lib/actions/get.d.ts +1 -0
- package/lib/actions/get.js +31 -0
- package/lib/actions/index.d.ts +13 -0
- package/lib/actions/index.js +45 -0
- package/lib/actions/list.d.ts +2 -0
- package/lib/actions/list.js +225 -0
- package/lib/actions/move.d.ts +18 -0
- package/lib/actions/move.js +168 -0
- package/lib/actions/proxy-to-repository.d.ts +2 -0
- package/lib/actions/proxy-to-repository.js +50 -0
- package/lib/actions/remove.d.ts +1 -0
- package/lib/actions/remove.js +28 -0
- package/lib/actions/set.d.ts +1 -0
- package/lib/actions/set.js +28 -0
- package/lib/actions/toggle.d.ts +2 -0
- package/lib/actions/toggle.js +39 -0
- package/lib/actions/update-or-create.d.ts +1 -0
- package/lib/actions/update-or-create.js +28 -0
- package/lib/actions/update.d.ts +1 -0
- package/lib/actions/update.js +40 -0
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +30 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +67 -0
- package/lib/utils.d.ts +8 -0
- package/lib/utils.js +60 -0
- package/package.json +24 -0
|
@@ -0,0 +1,225 @@
|
|
|
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 list_exports = {};
|
|
30
|
+
__export(list_exports, {
|
|
31
|
+
list: () => list
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(list_exports);
|
|
34
|
+
var import_querystring = __toESM(require("querystring"));
|
|
35
|
+
var import_utils = require("@tachybase/utils");
|
|
36
|
+
var import_sequelize = require("sequelize");
|
|
37
|
+
var import_constants = require("../constants");
|
|
38
|
+
var import_utils2 = require("../utils");
|
|
39
|
+
function totalPage(total, pageSize) {
|
|
40
|
+
return Math.ceil(total / pageSize);
|
|
41
|
+
}
|
|
42
|
+
__name(totalPage, "totalPage");
|
|
43
|
+
function findArgs(ctx) {
|
|
44
|
+
var _a, _b, _c;
|
|
45
|
+
const resourceName = ctx.action.resourceName;
|
|
46
|
+
const params = ctx.action.params;
|
|
47
|
+
const includeSort = ((_a = params.sort) == null ? void 0 : _a.filter((item) => item.split(".").length > 1)) ?? [];
|
|
48
|
+
const sortItems = [];
|
|
49
|
+
includeSort.forEach((sort2) => {
|
|
50
|
+
const parts = sort2[0] === "-" ? sort2.slice(1, sort2.length).split(".") : sort2.split(".");
|
|
51
|
+
const prefix = parts.slice(0, -1).join(".");
|
|
52
|
+
const sign = sort2[0] === "-" ? "-" : "";
|
|
53
|
+
const sortItem = sign + parts.slice(-1).join(".");
|
|
54
|
+
const findIndex = sortItems.findIndex((item) => item.prefix === prefix);
|
|
55
|
+
if (findIndex !== -1) {
|
|
56
|
+
sortItems[findIndex].items.push(sortItem);
|
|
57
|
+
} else {
|
|
58
|
+
sortItems.push({
|
|
59
|
+
prefix,
|
|
60
|
+
sortItems: [sortItem]
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
sortItems.forEach((item) => {
|
|
65
|
+
var _a2;
|
|
66
|
+
const i = ((_a2 = params.appends) == null ? void 0 : _a2.findIndex((append) => append === item.prefix)) ?? -1;
|
|
67
|
+
if (i !== -1) {
|
|
68
|
+
params.appends[i] = `${item.prefix}(${import_querystring.default.stringify({ sort: item.sortItems })})`;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
params.sort = ((_b = params.sort) == null ? void 0 : _b.filter((item) => item.split(".").length === 1)) ?? [];
|
|
72
|
+
if (params.tree) {
|
|
73
|
+
const [collectionName, associationName] = resourceName.split(".");
|
|
74
|
+
const collection = ctx.db.getCollection(resourceName);
|
|
75
|
+
if (collection.options.tree && !(associationName && collectionName === collection.name)) {
|
|
76
|
+
const foreignKey = ((_c = collection.treeParentField) == null ? void 0 : _c.foreignKey) || "parentId";
|
|
77
|
+
(0, import_utils.assign)(params, { filter: { [foreignKey]: null } }, { filter: "andMerge" });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const { tree, fields, filter, appends, except, sort } = params;
|
|
81
|
+
return { tree, filter, fields, appends, except, sort };
|
|
82
|
+
}
|
|
83
|
+
__name(findArgs, "findArgs");
|
|
84
|
+
async function listWithPagination(ctx) {
|
|
85
|
+
var _a;
|
|
86
|
+
const { page = import_constants.DEFAULT_PAGE, pageSize = import_constants.DEFAULT_PER_PAGE } = ctx.action.params;
|
|
87
|
+
const repository = (0, import_utils2.getRepositoryFromParams)(ctx);
|
|
88
|
+
const resourceName = ctx.action.resourceName;
|
|
89
|
+
const collection = ctx.db.getCollection(resourceName);
|
|
90
|
+
const options = {
|
|
91
|
+
context: ctx,
|
|
92
|
+
...findArgs(ctx),
|
|
93
|
+
...(0, import_utils2.pageArgsToLimitArgs)(parseInt(String(page)), parseInt(String(pageSize)))
|
|
94
|
+
};
|
|
95
|
+
Object.keys(options).forEach((key) => {
|
|
96
|
+
if (options[key] === void 0) {
|
|
97
|
+
delete options[key];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
let filterTreeData = [];
|
|
101
|
+
let filterTreeCount = 0;
|
|
102
|
+
if (ctx.action.params.tree && options.filter) {
|
|
103
|
+
const foreignKey = ((_a = collection.treeParentField) == null ? void 0 : _a.foreignKey) || "parentId";
|
|
104
|
+
const params = Object.values(options.filter).flat()[0] || {};
|
|
105
|
+
let dataIds = [];
|
|
106
|
+
if (Object.entries(params).length) {
|
|
107
|
+
const getParent = /* @__PURE__ */ __name(async (filter = {}) => {
|
|
108
|
+
const data = await repository.find({
|
|
109
|
+
filter
|
|
110
|
+
});
|
|
111
|
+
dataIds = data.map((item) => item.id);
|
|
112
|
+
}, "getParent");
|
|
113
|
+
await getParent(params);
|
|
114
|
+
const allDataIds = [];
|
|
115
|
+
for (const dataId of dataIds) {
|
|
116
|
+
const query = `
|
|
117
|
+
WITH RECURSIVE tree1 AS (
|
|
118
|
+
SELECT id, "${foreignKey}"
|
|
119
|
+
FROM ${collection.name}
|
|
120
|
+
WHERE id = :dataId
|
|
121
|
+
|
|
122
|
+
UNION ALL
|
|
123
|
+
|
|
124
|
+
SELECT p.id, p."${foreignKey}"
|
|
125
|
+
FROM tree1 up
|
|
126
|
+
JOIN ${collection.name} p ON up."${foreignKey}" = p.id
|
|
127
|
+
),
|
|
128
|
+
tree2 AS (
|
|
129
|
+
SELECT id, "${foreignKey}"
|
|
130
|
+
FROM ${collection.name}
|
|
131
|
+
WHERE id = :dataId
|
|
132
|
+
|
|
133
|
+
UNION ALL
|
|
134
|
+
|
|
135
|
+
SELECT p.id, p."${foreignKey}"
|
|
136
|
+
FROM tree2 down
|
|
137
|
+
JOIN ${collection.name} p ON down.id = p."${foreignKey}"
|
|
138
|
+
)
|
|
139
|
+
SELECT DISTINCT *
|
|
140
|
+
FROM (
|
|
141
|
+
SELECT *
|
|
142
|
+
FROM tree1
|
|
143
|
+
UNION ALL
|
|
144
|
+
SELECT *
|
|
145
|
+
FROM tree2
|
|
146
|
+
) AS formData;`;
|
|
147
|
+
const filterTreeDatas = await ctx.db.sequelize.query(query, {
|
|
148
|
+
replacements: {
|
|
149
|
+
dataId
|
|
150
|
+
},
|
|
151
|
+
type: import_sequelize.QueryTypes.SELECT
|
|
152
|
+
});
|
|
153
|
+
const newRows = filterTreeDatas;
|
|
154
|
+
const filterIds = newRows.map((item) => item.id);
|
|
155
|
+
allDataIds.push(...filterIds);
|
|
156
|
+
}
|
|
157
|
+
const ids = [...new Set(allDataIds)];
|
|
158
|
+
const where = {
|
|
159
|
+
id: {
|
|
160
|
+
[import_sequelize.Op.in]: ids
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const [rows2, count2] = await repository.findAndCount({
|
|
164
|
+
filter: where,
|
|
165
|
+
appends: options.appends || []
|
|
166
|
+
});
|
|
167
|
+
const _data = rows2.map((item) => item.dataValues);
|
|
168
|
+
const father = _data.filter((parent) => parent.parentId === null);
|
|
169
|
+
const transTreeData = /* @__PURE__ */ __name((father2, allRows) => {
|
|
170
|
+
father2.forEach((parent, index) => {
|
|
171
|
+
var _a2;
|
|
172
|
+
const children = allRows.filter((child) => child.parentId === parent.id);
|
|
173
|
+
const i = index.toString();
|
|
174
|
+
parent.__index = parent.father || parent.father === "0" ? parent.father + ".children." + i : i;
|
|
175
|
+
if (children == null ? void 0 : children.length) {
|
|
176
|
+
const transChild = children.map((child) => {
|
|
177
|
+
return {
|
|
178
|
+
...child,
|
|
179
|
+
father: parent.__index
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
parent.children = transChild;
|
|
183
|
+
}
|
|
184
|
+
if ((_a2 = parent.children) == null ? void 0 : _a2.length) {
|
|
185
|
+
transTreeData(parent.children, allRows);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}, "transTreeData");
|
|
189
|
+
transTreeData(father, _data);
|
|
190
|
+
filterTreeData = father;
|
|
191
|
+
filterTreeCount = father.length;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const [rows, count] = await repository.findAndCount(options);
|
|
195
|
+
ctx.body = {
|
|
196
|
+
count: filterTreeData.length ? filterTreeCount : count,
|
|
197
|
+
rows: filterTreeData.length ? filterTreeData : rows,
|
|
198
|
+
page: Number(page),
|
|
199
|
+
pageSize: Number(pageSize),
|
|
200
|
+
totalPage: totalPage(count, pageSize)
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
__name(listWithPagination, "listWithPagination");
|
|
204
|
+
async function listWithNonPaged(ctx) {
|
|
205
|
+
const repository = (0, import_utils2.getRepositoryFromParams)(ctx);
|
|
206
|
+
const rows = await repository.find({ context: ctx, ...findArgs(ctx) });
|
|
207
|
+
ctx.body = rows;
|
|
208
|
+
}
|
|
209
|
+
__name(listWithNonPaged, "listWithNonPaged");
|
|
210
|
+
async function list(ctx, next) {
|
|
211
|
+
const { paginate } = ctx.action.params;
|
|
212
|
+
if (paginate === false || paginate === "false") {
|
|
213
|
+
await listWithNonPaged(ctx);
|
|
214
|
+
ctx.paginate = false;
|
|
215
|
+
} else {
|
|
216
|
+
await listWithPagination(ctx);
|
|
217
|
+
ctx.paginate = true;
|
|
218
|
+
}
|
|
219
|
+
await next();
|
|
220
|
+
}
|
|
221
|
+
__name(list, "list");
|
|
222
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
223
|
+
0 && (module.exports = {
|
|
224
|
+
list
|
|
225
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Collection, SortField, TargetKey } from '@tachybase/database';
|
|
2
|
+
import { Model } from 'sequelize';
|
|
3
|
+
import { Context } from '..';
|
|
4
|
+
export declare function move(ctx: Context, next: any): Promise<void>;
|
|
5
|
+
interface MoveOptions {
|
|
6
|
+
insertAfter?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class SortAbleCollection {
|
|
9
|
+
collection: Collection;
|
|
10
|
+
field: SortField;
|
|
11
|
+
scopeKey: string;
|
|
12
|
+
constructor(collection: Collection, fieldName?: string);
|
|
13
|
+
move(sourceInstanceId: TargetKey, targetInstanceId: TargetKey, options?: MoveOptions): Promise<void>;
|
|
14
|
+
changeScope(sourceInstanceId: TargetKey, targetScope: any, method?: string): Promise<void>;
|
|
15
|
+
sticky(sourceInstanceId: TargetKey): Promise<void>;
|
|
16
|
+
sameScopeMove(sourceInstance: Model, targetInstance: Model, options: MoveOptions, sourceInstanceId: TargetKey): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var move_exports = {};
|
|
20
|
+
__export(move_exports, {
|
|
21
|
+
SortAbleCollection: () => SortAbleCollection,
|
|
22
|
+
move: () => move
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(move_exports);
|
|
25
|
+
var import_database = require("@tachybase/database");
|
|
26
|
+
var import_sequelize = require("sequelize");
|
|
27
|
+
var import_utils = require("../utils");
|
|
28
|
+
async function move(ctx, next) {
|
|
29
|
+
const repository = ctx.databaseRepository || (0, import_utils.getRepositoryFromParams)(ctx);
|
|
30
|
+
const { sourceId, targetId, sortField, targetScope, sticky, method } = ctx.action.params;
|
|
31
|
+
if (repository instanceof import_database.BelongsToManyRepository) {
|
|
32
|
+
throw new Error("Sorting association as 'belongs-to-many' type is not supported.");
|
|
33
|
+
}
|
|
34
|
+
if (repository instanceof import_database.HasManyRepository) {
|
|
35
|
+
const hasManyField = repository.sourceCollection.getField(repository.associationName);
|
|
36
|
+
if (!hasManyField.options.sortable) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`association ${hasManyField.options.name} in ${repository.sourceCollection.name} is not sortable`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const sortAbleCollection = new SortAbleCollection(
|
|
43
|
+
repository instanceof import_database.Repository ? repository.collection : repository.targetCollection,
|
|
44
|
+
repository instanceof import_database.Repository ? sortField : `${repository.association.foreignKey}Sort`
|
|
45
|
+
);
|
|
46
|
+
if (sourceId && targetId) {
|
|
47
|
+
await sortAbleCollection.move(sourceId, targetId, {
|
|
48
|
+
insertAfter: method === "insertAfter"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (sourceId && targetScope) {
|
|
52
|
+
await sortAbleCollection.changeScope(sourceId, targetScope, method);
|
|
53
|
+
}
|
|
54
|
+
if (sourceId && sticky) {
|
|
55
|
+
await sortAbleCollection.sticky(sourceId);
|
|
56
|
+
}
|
|
57
|
+
ctx.body = "ok";
|
|
58
|
+
await next();
|
|
59
|
+
}
|
|
60
|
+
__name(move, "move");
|
|
61
|
+
const _SortAbleCollection = class _SortAbleCollection {
|
|
62
|
+
collection;
|
|
63
|
+
field;
|
|
64
|
+
scopeKey;
|
|
65
|
+
constructor(collection, fieldName = "sort") {
|
|
66
|
+
this.collection = collection;
|
|
67
|
+
this.field = collection.getField(fieldName);
|
|
68
|
+
if (!(this.field instanceof import_database.SortField)) {
|
|
69
|
+
throw new Error(`${fieldName} is not a sort field`);
|
|
70
|
+
}
|
|
71
|
+
this.scopeKey = this.field.get("scopeKey");
|
|
72
|
+
}
|
|
73
|
+
// insert source position to target position
|
|
74
|
+
async move(sourceInstanceId, targetInstanceId, options = {}) {
|
|
75
|
+
const sourceInstance = await this.collection.repository.findById(sourceInstanceId);
|
|
76
|
+
const targetInstance = await this.collection.repository.findById(targetInstanceId);
|
|
77
|
+
if (this.scopeKey && sourceInstance.get(this.scopeKey) !== targetInstance.get(this.scopeKey)) {
|
|
78
|
+
await this.collection.repository.update({
|
|
79
|
+
targetCollection: this.collection.name,
|
|
80
|
+
filterByTk: sourceInstanceId,
|
|
81
|
+
values: {
|
|
82
|
+
[this.scopeKey]: targetInstance.get(this.scopeKey)
|
|
83
|
+
},
|
|
84
|
+
silent: false
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
await this.sameScopeMove(sourceInstance, targetInstance, options, sourceInstanceId);
|
|
88
|
+
}
|
|
89
|
+
async changeScope(sourceInstanceId, targetScope, method) {
|
|
90
|
+
const sourceInstance = await this.collection.repository.findById(sourceInstanceId);
|
|
91
|
+
const targetScopeValue = targetScope[this.scopeKey];
|
|
92
|
+
if (targetScopeValue && sourceInstance.get(this.scopeKey) !== targetScopeValue) {
|
|
93
|
+
await this.collection.repository.update({
|
|
94
|
+
targetCollection: this.collection.name,
|
|
95
|
+
filterByTk: sourceInstanceId,
|
|
96
|
+
values: {
|
|
97
|
+
[this.scopeKey]: targetScopeValue
|
|
98
|
+
},
|
|
99
|
+
silent: false
|
|
100
|
+
});
|
|
101
|
+
if (method === "prepend") {
|
|
102
|
+
await this.sticky(sourceInstanceId);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async sticky(sourceInstanceId) {
|
|
107
|
+
await this.collection.repository.update({
|
|
108
|
+
targetCollection: this.collection.name,
|
|
109
|
+
filterByTk: sourceInstanceId,
|
|
110
|
+
values: {
|
|
111
|
+
[this.field.get("name")]: 0
|
|
112
|
+
},
|
|
113
|
+
silent: true
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async sameScopeMove(sourceInstance, targetInstance, options, sourceInstanceId) {
|
|
117
|
+
const fieldName = this.field.get("name");
|
|
118
|
+
const sourceSort = sourceInstance.get(fieldName);
|
|
119
|
+
let targetSort = targetInstance.get(fieldName);
|
|
120
|
+
if (options.insertAfter) {
|
|
121
|
+
targetSort = targetSort + 1;
|
|
122
|
+
}
|
|
123
|
+
const scopeValue = this.scopeKey ? sourceInstance.get(this.scopeKey) : null;
|
|
124
|
+
let updateCondition;
|
|
125
|
+
let change;
|
|
126
|
+
if (targetSort > sourceSort) {
|
|
127
|
+
updateCondition = {
|
|
128
|
+
[import_sequelize.Op.gt]: sourceSort,
|
|
129
|
+
[import_sequelize.Op.lte]: targetSort
|
|
130
|
+
};
|
|
131
|
+
change = -1;
|
|
132
|
+
} else {
|
|
133
|
+
updateCondition = {
|
|
134
|
+
[import_sequelize.Op.lt]: sourceSort,
|
|
135
|
+
[import_sequelize.Op.gte]: targetSort
|
|
136
|
+
};
|
|
137
|
+
change = 1;
|
|
138
|
+
}
|
|
139
|
+
const where = {
|
|
140
|
+
[fieldName]: updateCondition
|
|
141
|
+
};
|
|
142
|
+
if (scopeValue) {
|
|
143
|
+
where[this.scopeKey] = {
|
|
144
|
+
[import_sequelize.Op.eq]: scopeValue
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
await this.collection.model.increment(fieldName, {
|
|
148
|
+
where,
|
|
149
|
+
by: change,
|
|
150
|
+
silent: true
|
|
151
|
+
});
|
|
152
|
+
await this.collection.repository.update({
|
|
153
|
+
targetCollection: this.collection.name,
|
|
154
|
+
filterByTk: sourceInstanceId,
|
|
155
|
+
values: {
|
|
156
|
+
[fieldName]: targetSort
|
|
157
|
+
},
|
|
158
|
+
silent: true
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
__name(_SortAbleCollection, "SortAbleCollection");
|
|
163
|
+
let SortAbleCollection = _SortAbleCollection;
|
|
164
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
165
|
+
0 && (module.exports = {
|
|
166
|
+
SortAbleCollection,
|
|
167
|
+
move
|
|
168
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
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 proxy_to_repository_exports = {};
|
|
30
|
+
__export(proxy_to_repository_exports, {
|
|
31
|
+
proxyToRepository: () => proxyToRepository
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(proxy_to_repository_exports);
|
|
34
|
+
var import_lodash = __toESM(require("lodash"));
|
|
35
|
+
var import_utils = require("../utils");
|
|
36
|
+
function proxyToRepository(paramKeys, repositoryMethod) {
|
|
37
|
+
return async function(ctx, next) {
|
|
38
|
+
const repository = (0, import_utils.getRepositoryFromParams)(ctx);
|
|
39
|
+
const callObj = import_lodash.default.pick(ctx.action.params, paramKeys);
|
|
40
|
+
callObj.context = ctx;
|
|
41
|
+
ctx.body = await repository[repositoryMethod](callObj);
|
|
42
|
+
ctx.status = 200;
|
|
43
|
+
await next();
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
__name(proxyToRepository, "proxyToRepository");
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
proxyToRepository
|
|
50
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const remove: (ctx: import("..").Context, next: any) => Promise<void>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var remove_exports = {};
|
|
19
|
+
__export(remove_exports, {
|
|
20
|
+
remove: () => remove
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(remove_exports);
|
|
23
|
+
var import_utils = require("../utils");
|
|
24
|
+
const remove = (0, import_utils.RelationRepositoryActionBuilder)("remove");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
remove
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const set: (ctx: import("..").Context, next: any) => Promise<void>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var set_exports = {};
|
|
19
|
+
__export(set_exports, {
|
|
20
|
+
set: () => set
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(set_exports);
|
|
23
|
+
var import_utils = require("../utils");
|
|
24
|
+
const set = (0, import_utils.RelationRepositoryActionBuilder)("set");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
set
|
|
28
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var toggle_exports = {};
|
|
20
|
+
__export(toggle_exports, {
|
|
21
|
+
toggle: () => toggle
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(toggle_exports);
|
|
24
|
+
var import_database = require("@tachybase/database");
|
|
25
|
+
var import_utils = require("../utils");
|
|
26
|
+
async function toggle(ctx, next) {
|
|
27
|
+
const repository = (0, import_utils.getRepositoryFromParams)(ctx);
|
|
28
|
+
if (!(repository instanceof import_database.BelongsToManyRepository)) {
|
|
29
|
+
return await next();
|
|
30
|
+
}
|
|
31
|
+
await repository.toggle(ctx.action.params.values);
|
|
32
|
+
ctx.body = "ok";
|
|
33
|
+
await next();
|
|
34
|
+
}
|
|
35
|
+
__name(toggle, "toggle");
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
toggle
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const updateOrCreate: (ctx: import("..").Context, next: any) => Promise<void>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var update_or_create_exports = {};
|
|
19
|
+
__export(update_or_create_exports, {
|
|
20
|
+
updateOrCreate: () => updateOrCreate
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(update_or_create_exports);
|
|
23
|
+
var import_proxy_to_repository = require("./proxy-to-repository");
|
|
24
|
+
const updateOrCreate = (0, import_proxy_to_repository.proxyToRepository)(["values", "filterKeys"], "updateOrCreate");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
updateOrCreate
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const update: (ctx: import("..").Context, next: any) => Promise<void>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var update_exports = {};
|
|
19
|
+
__export(update_exports, {
|
|
20
|
+
update: () => update
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(update_exports);
|
|
23
|
+
var import_proxy_to_repository = require("./proxy-to-repository");
|
|
24
|
+
const update = (0, import_proxy_to_repository.proxyToRepository)(
|
|
25
|
+
[
|
|
26
|
+
"filterByTk",
|
|
27
|
+
"values",
|
|
28
|
+
"whitelist",
|
|
29
|
+
"blacklist",
|
|
30
|
+
"filter",
|
|
31
|
+
"updateAssociationValues",
|
|
32
|
+
"forceUpdate",
|
|
33
|
+
"targetCollection"
|
|
34
|
+
],
|
|
35
|
+
"update"
|
|
36
|
+
);
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
update
|
|
40
|
+
});
|