@nocobase/plugin-field-sort 1.5.0-alpha.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.
- package/LICENSE.txt +159 -0
- package/README.md +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/index.d.ts +15 -0
- package/dist/client/index.js +10 -0
- package/dist/client/locale.d.ts +10 -0
- package/dist/client/sort-interface.d.ts +131 -0
- package/dist/externalVersion.js +18 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +1 -0
- package/dist/locale/zh-CN.json +1 -0
- package/dist/node_modules/@nocobase/lock-manager/LICENSE +661 -0
- package/dist/node_modules/@nocobase/lock-manager/lib/index.d.ts +10 -0
- package/dist/node_modules/@nocobase/lock-manager/lib/index.js +1 -0
- package/dist/node_modules/@nocobase/lock-manager/lib/lock-manager.d.ts +46 -0
- package/dist/node_modules/@nocobase/lock-manager/lib/lock-manager.js +171 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/client.js +12 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/assign.d.ts +17 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/assign.js +143 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/client.d.ts +30 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/client.js +88 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/collections-graph.d.ts +24 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/collections-graph.js +107 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/common.d.ts +14 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/common.js +87 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/date.d.ts +38 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/date.js +214 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/dayjs.d.ts +10 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/dayjs.js +72 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/forEach.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/forEach.js +45 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/fs-exists.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/fs-exists.js +46 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/getValuesByPath.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/getValuesByPath.js +71 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/handlebars.d.ts +10 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/handlebars.js +73 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/i18n.d.ts +10 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/i18n.js +43 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/index.d.ts +38 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/index.js +105 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isPortalInBody.d.ts +13 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isPortalInBody.js +54 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isValidFilter.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isValidFilter.js +63 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/json-templates.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/json-templates.js +141 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/koa-multer.d.ts +15 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/koa-multer.js +92 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/log.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/log.js +39 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/measure-execution-time.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/measure-execution-time.js +44 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/merge.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/merge.js +55 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/AsyncEmitter.d.ts +11 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/AsyncEmitter.js +80 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/index.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/index.js +48 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/notification.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/notification.js +43 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/number.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/number.js +45 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-date.d.ts +15 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-date.js +262 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-filter.d.ts +67 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-filter.js +320 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parseHTML.d.ts +15 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parseHTML.js +42 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/perf-hooks.d.ts +14 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/perf-hooks.js +69 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/registry.d.ts +22 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/registry.js +69 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/requireModule.d.ts +12 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/requireModule.js +90 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/server.d.ts +19 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/server.js +50 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/toposort.d.ts +18 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/toposort.js +83 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/uid.d.ts +9 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/uid.js +44 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/url.d.ts +14 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/url.js +46 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/wrap-middleware.d.ts +1 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/wrap-middleware.js +63 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/package.json +20 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/plugin-symlink.d.ts +6 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/plugin-symlink.js +102 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/server.d.ts +2 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/server.js +12 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/.eslintrc.js +5 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/.github/workflows/ci.yml +24 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/.github/workflows/lint.yml +23 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-fields-100mb-big.js +149 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-fields-100mb-small.js +143 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-files-100mb-big.js +154 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-files-100mb-small.js +148 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-urlencoded-fields-100pairs-small.js +101 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-urlencoded-fields-900pairs-small-alt.js +84 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/index.js +57 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/types/multipart.js +653 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/types/urlencoded.js +350 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/utils.js +596 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/package.json +22 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/common.js +109 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-multipart-charsets.js +94 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-multipart-stream-pause.js +102 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-multipart.js +1053 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-urlencoded.js +488 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test.js +20 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/index.js +104 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/counter.js +28 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/file-appender.js +67 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/make-middleware.js +173 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/multer-error.js +24 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/remove-uploaded-files.js +28 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/package.json +52 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/storage/disk.js +66 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/storage/memory.js +21 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/.eslintrc.js +5 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/.github/workflows/ci.yml +24 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/.github/workflows/lint.yml +23 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/lib/sbmh.js +267 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/package.json +34 -0
- package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/test/test.js +70 -0
- package/dist/node_modules/@nocobase/lock-manager/package.json +1 -0
- package/dist/node_modules/@nocobase/lock-manager/src/__tests__/lock-manager.test.ts +169 -0
- package/dist/node_modules/@nocobase/lock-manager/src/index.ts +11 -0
- package/dist/node_modules/@nocobase/lock-manager/src/lock-manager.ts +169 -0
- package/dist/server/action.d.ts +26 -0
- package/dist/server/action.js +168 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.js +48 -0
- package/dist/server/plugin.d.ts +19 -0
- package/dist/server/plugin.js +69 -0
- package/dist/server/sort-field.d.ts +24 -0
- package/dist/server/sort-field.js +197 -0
- package/package.json +16 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var server_exports = {};
|
|
38
|
+
__export(server_exports, {
|
|
39
|
+
default: () => import_plugin.default,
|
|
40
|
+
move: () => import_action.move
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(server_exports);
|
|
43
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
44
|
+
var import_action = require("./action");
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
move
|
|
48
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin } from '@nocobase/server';
|
|
10
|
+
export declare class PluginFieldSortServer extends Plugin {
|
|
11
|
+
afterAdd(): Promise<void>;
|
|
12
|
+
beforeLoad(): Promise<void>;
|
|
13
|
+
load(): Promise<void>;
|
|
14
|
+
install(): Promise<void>;
|
|
15
|
+
afterEnable(): Promise<void>;
|
|
16
|
+
afterDisable(): Promise<void>;
|
|
17
|
+
remove(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export default PluginFieldSortServer;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var plugin_exports = {};
|
|
28
|
+
__export(plugin_exports, {
|
|
29
|
+
PluginFieldSortServer: () => PluginFieldSortServer,
|
|
30
|
+
default: () => plugin_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
33
|
+
var import_server = require("@nocobase/server");
|
|
34
|
+
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
35
|
+
var import_sort_field = require("./sort-field");
|
|
36
|
+
var import_action = require("./action");
|
|
37
|
+
class PluginFieldSortServer extends import_server.Plugin {
|
|
38
|
+
async afterAdd() {
|
|
39
|
+
}
|
|
40
|
+
async beforeLoad() {
|
|
41
|
+
const { lockManager } = this.app;
|
|
42
|
+
class SortFieldClass extends import_sort_field.SortField {
|
|
43
|
+
}
|
|
44
|
+
SortFieldClass.lockManager = lockManager;
|
|
45
|
+
this.app.db.registerFieldTypes({
|
|
46
|
+
sort: SortFieldClass
|
|
47
|
+
});
|
|
48
|
+
this.app.dataSourceManager.beforeAddDataSource((dataSource) => {
|
|
49
|
+
if (dataSource.collectionManager instanceof import_data_source_manager.SequelizeCollectionManager) {
|
|
50
|
+
dataSource.resourceManager.registerActionHandlers({ move: import_action.move });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async load() {
|
|
55
|
+
}
|
|
56
|
+
async install() {
|
|
57
|
+
}
|
|
58
|
+
async afterEnable() {
|
|
59
|
+
}
|
|
60
|
+
async afterDisable() {
|
|
61
|
+
}
|
|
62
|
+
async remove() {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
var plugin_default = PluginFieldSortServer;
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
PluginFieldSortServer
|
|
69
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { DataTypes } from 'sequelize';
|
|
10
|
+
import { BaseColumnFieldOptions, Field } from '@nocobase/database';
|
|
11
|
+
import { LockManager } from '@nocobase/lock-manager';
|
|
12
|
+
export declare class SortField extends Field {
|
|
13
|
+
static lockManager: LockManager;
|
|
14
|
+
get dataType(): DataTypes.BigIntDataTypeConstructor;
|
|
15
|
+
setSortValue: (instance: any, options: any) => Promise<void>;
|
|
16
|
+
onScopeChange: (instance: any, options: any) => Promise<void>;
|
|
17
|
+
initRecordsSortValue: (options: any) => Promise<void>;
|
|
18
|
+
bind(): void;
|
|
19
|
+
unbind(): void;
|
|
20
|
+
}
|
|
21
|
+
export interface SortFieldOptions extends BaseColumnFieldOptions {
|
|
22
|
+
type: 'sort';
|
|
23
|
+
scopeKey?: string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var sort_field_exports = {};
|
|
28
|
+
__export(sort_field_exports, {
|
|
29
|
+
SortField: () => SortField
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(sort_field_exports);
|
|
32
|
+
var import_lodash = require("lodash");
|
|
33
|
+
var import_sequelize = require("sequelize");
|
|
34
|
+
var import_database = require("@nocobase/database");
|
|
35
|
+
class SortField extends import_database.Field {
|
|
36
|
+
static lockManager;
|
|
37
|
+
get dataType() {
|
|
38
|
+
return import_sequelize.DataTypes.BIGINT;
|
|
39
|
+
}
|
|
40
|
+
setSortValue = async (instance, options) => {
|
|
41
|
+
const { name, scopeKey } = this.options;
|
|
42
|
+
const { model } = this.context.collection;
|
|
43
|
+
if ((0, import_lodash.isNumber)(instance.get(name)) && instance._previousDataValues[scopeKey] == instance[scopeKey]) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const where = {};
|
|
47
|
+
if (scopeKey) {
|
|
48
|
+
const value = instance.get(scopeKey);
|
|
49
|
+
if (value !== void 0 && value !== null) {
|
|
50
|
+
where[scopeKey] = value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
await this.constructor.lockManager.runExclusive(
|
|
54
|
+
this.context.collection.name,
|
|
55
|
+
async () => {
|
|
56
|
+
const max = await model.max(name, { ...options, where });
|
|
57
|
+
const newValue = (max || 0) + 1;
|
|
58
|
+
instance.set(name, newValue);
|
|
59
|
+
},
|
|
60
|
+
2e3
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
onScopeChange = async (instance, options) => {
|
|
64
|
+
const { scopeKey } = this.options;
|
|
65
|
+
if (scopeKey && !instance.isNewRecord && instance._previousDataValues[scopeKey] != instance[scopeKey]) {
|
|
66
|
+
await this.setSortValue(instance, options);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
initRecordsSortValue = async (options) => {
|
|
70
|
+
const { transaction } = options;
|
|
71
|
+
const orderField = (() => {
|
|
72
|
+
const model = this.collection.model;
|
|
73
|
+
if (model.primaryKeyAttribute) {
|
|
74
|
+
return model.primaryKeyAttribute;
|
|
75
|
+
}
|
|
76
|
+
if (model.rawAttributes["createdAt"]) {
|
|
77
|
+
return model.rawAttributes["createdAt"].field;
|
|
78
|
+
}
|
|
79
|
+
throw new Error(`can not find order key for collection ${this.collection.name}`);
|
|
80
|
+
})();
|
|
81
|
+
const needInit = async (scopeKey2 = null, scopeValue = null) => {
|
|
82
|
+
const filter = {};
|
|
83
|
+
if (scopeKey2 && scopeValue) {
|
|
84
|
+
filter[scopeKey2] = scopeValue;
|
|
85
|
+
}
|
|
86
|
+
const totalCount = await this.collection.repository.count({
|
|
87
|
+
filter,
|
|
88
|
+
transaction
|
|
89
|
+
});
|
|
90
|
+
const emptyCount = await this.collection.repository.count({
|
|
91
|
+
filter: {
|
|
92
|
+
[this.name]: null,
|
|
93
|
+
...filter
|
|
94
|
+
},
|
|
95
|
+
transaction
|
|
96
|
+
});
|
|
97
|
+
return emptyCount === totalCount && emptyCount > 0;
|
|
98
|
+
};
|
|
99
|
+
const doInit = async (scopeKey2 = null, scopeValue = null) => {
|
|
100
|
+
const queryInterface = this.collection.db.sequelize.getQueryInterface();
|
|
101
|
+
if (scopeKey2) {
|
|
102
|
+
const scopeAttribute = this.collection.model.rawAttributes[scopeKey2];
|
|
103
|
+
if (!scopeAttribute) {
|
|
104
|
+
throw new Error(`can not find scope field ${scopeKey2} for collection ${this.collection.name}`);
|
|
105
|
+
}
|
|
106
|
+
scopeKey2 = scopeAttribute.field;
|
|
107
|
+
}
|
|
108
|
+
const quotedOrderField = queryInterface.quoteIdentifier(orderField);
|
|
109
|
+
const sortColumnName = queryInterface.quoteIdentifier(this.collection.model.rawAttributes[this.name].field);
|
|
110
|
+
let sql;
|
|
111
|
+
const whereClause = scopeKey2 && scopeValue ? (() => {
|
|
112
|
+
const filteredScopeValue = scopeValue.filter((v) => v !== null);
|
|
113
|
+
if (filteredScopeValue.length === 0) {
|
|
114
|
+
return "";
|
|
115
|
+
}
|
|
116
|
+
const initialClause = `
|
|
117
|
+
WHERE ${queryInterface.quoteIdentifier(scopeKey2)} IN (${filteredScopeValue.map((v) => `'${v}'`).join(", ")})`;
|
|
118
|
+
const nullCheck = scopeValue.includes(null) ? ` OR ${queryInterface.quoteIdentifier(scopeKey2)} IS NULL` : "";
|
|
119
|
+
return initialClause + nullCheck;
|
|
120
|
+
})() : "";
|
|
121
|
+
if (this.collection.db.inDialect("postgres")) {
|
|
122
|
+
sql = `
|
|
123
|
+
UPDATE ${this.collection.quotedTableName()}
|
|
124
|
+
SET ${sortColumnName} = ordered_table.new_sequence_number
|
|
125
|
+
FROM (
|
|
126
|
+
SELECT *, ROW_NUMBER() OVER (${scopeKey2 ? `PARTITION BY ${queryInterface.quoteIdentifier(scopeKey2)}` : ""} ORDER BY ${quotedOrderField}) AS new_sequence_number
|
|
127
|
+
FROM ${this.collection.quotedTableName()}
|
|
128
|
+
${whereClause}
|
|
129
|
+
) AS ordered_table
|
|
130
|
+
WHERE ${this.collection.quotedTableName()}.${quotedOrderField} = ordered_table.${quotedOrderField};
|
|
131
|
+
`;
|
|
132
|
+
} else if (this.collection.db.inDialect("sqlite")) {
|
|
133
|
+
sql = `
|
|
134
|
+
UPDATE ${this.collection.quotedTableName()}
|
|
135
|
+
SET ${sortColumnName} = (
|
|
136
|
+
SELECT new_sequence_number
|
|
137
|
+
FROM (
|
|
138
|
+
SELECT *, ROW_NUMBER() OVER (${scopeKey2 ? `PARTITION BY ${queryInterface.quoteIdentifier(scopeKey2)}` : ""} ORDER BY ${quotedOrderField}) AS new_sequence_number
|
|
139
|
+
FROM ${this.collection.quotedTableName()}
|
|
140
|
+
${whereClause}
|
|
141
|
+
) AS ordered_table
|
|
142
|
+
WHERE ${this.collection.quotedTableName()}.${quotedOrderField} = ordered_table.${quotedOrderField}
|
|
143
|
+
);
|
|
144
|
+
`;
|
|
145
|
+
} else if (this.collection.db.inDialect("mysql") || this.collection.db.inDialect("mariadb")) {
|
|
146
|
+
sql = `
|
|
147
|
+
UPDATE ${this.collection.quotedTableName()}
|
|
148
|
+
JOIN (
|
|
149
|
+
SELECT *, ROW_NUMBER() OVER (${scopeKey2 ? `PARTITION BY ${queryInterface.quoteIdentifier(scopeKey2)}` : ""} ORDER BY ${quotedOrderField}) AS new_sequence_number
|
|
150
|
+
FROM ${this.collection.quotedTableName()}
|
|
151
|
+
${whereClause}
|
|
152
|
+
) AS ordered_table ON ${this.collection.quotedTableName()}.${quotedOrderField} = ordered_table.${quotedOrderField}
|
|
153
|
+
SET ${this.collection.quotedTableName()}.${sortColumnName} = ordered_table.new_sequence_number;
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
await this.collection.db.sequelize.query(sql, {
|
|
157
|
+
transaction
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
const scopeKey = this.options.scopeKey;
|
|
161
|
+
if (scopeKey) {
|
|
162
|
+
const scopeKeyColumn = this.collection.model.rawAttributes[scopeKey].field;
|
|
163
|
+
const groups = await this.collection.model.findAll({
|
|
164
|
+
attributes: [[import_sequelize.Sequelize.fn("DISTINCT", import_sequelize.Sequelize.col(scopeKeyColumn)), scopeKey]],
|
|
165
|
+
raw: true,
|
|
166
|
+
transaction
|
|
167
|
+
});
|
|
168
|
+
const needInitGroups = [];
|
|
169
|
+
for (const group of groups) {
|
|
170
|
+
if (await needInit(scopeKey, group[scopeKey])) {
|
|
171
|
+
needInitGroups.push(group[scopeKey]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (needInitGroups.length > 0) {
|
|
175
|
+
await doInit(scopeKey, needInitGroups);
|
|
176
|
+
}
|
|
177
|
+
} else if (await needInit()) {
|
|
178
|
+
await doInit();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
bind() {
|
|
182
|
+
super.bind();
|
|
183
|
+
this.on("afterSync", this.initRecordsSortValue);
|
|
184
|
+
this.on("beforeUpdate", this.onScopeChange);
|
|
185
|
+
this.on("beforeCreate", this.setSortValue);
|
|
186
|
+
}
|
|
187
|
+
unbind() {
|
|
188
|
+
super.unbind();
|
|
189
|
+
this.off("beforeUpdate", this.onScopeChange);
|
|
190
|
+
this.off("beforeCreate", this.setSortValue);
|
|
191
|
+
this.off("afterSync", this.initRecordsSortValue);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
195
|
+
0 && (module.exports = {
|
|
196
|
+
SortField
|
|
197
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-field-sort",
|
|
3
|
+
"version": "1.5.0-alpha.1",
|
|
4
|
+
"main": "dist/server/index.js",
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"@nocobase/actions": "1.x",
|
|
7
|
+
"@nocobase/client": "1.x",
|
|
8
|
+
"@nocobase/database": "1.x",
|
|
9
|
+
"@nocobase/lock-manager": "1.x",
|
|
10
|
+
"@nocobase/server": "1.x",
|
|
11
|
+
"@nocobase/test": "1.x",
|
|
12
|
+
"lodash": "4.17.21",
|
|
13
|
+
"sequelize": "^6.26.0"
|
|
14
|
+
},
|
|
15
|
+
"gitHead": "abe58fad69534a13c2502a47da86425a597c3ba3"
|
|
16
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|