@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.
Files changed (142) hide show
  1. package/LICENSE.txt +159 -0
  2. package/README.md +1 -0
  3. package/client.d.ts +2 -0
  4. package/client.js +1 -0
  5. package/dist/client/index.d.ts +15 -0
  6. package/dist/client/index.js +10 -0
  7. package/dist/client/locale.d.ts +10 -0
  8. package/dist/client/sort-interface.d.ts +131 -0
  9. package/dist/externalVersion.js +18 -0
  10. package/dist/index.d.ts +10 -0
  11. package/dist/index.js +48 -0
  12. package/dist/locale/en-US.json +1 -0
  13. package/dist/locale/zh-CN.json +1 -0
  14. package/dist/node_modules/@nocobase/lock-manager/LICENSE +661 -0
  15. package/dist/node_modules/@nocobase/lock-manager/lib/index.d.ts +10 -0
  16. package/dist/node_modules/@nocobase/lock-manager/lib/index.js +1 -0
  17. package/dist/node_modules/@nocobase/lock-manager/lib/lock-manager.d.ts +46 -0
  18. package/dist/node_modules/@nocobase/lock-manager/lib/lock-manager.js +171 -0
  19. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/client.js +12 -0
  20. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/assign.d.ts +17 -0
  21. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/assign.js +143 -0
  22. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/client.d.ts +30 -0
  23. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/client.js +88 -0
  24. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/collections-graph.d.ts +24 -0
  25. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/collections-graph.js +107 -0
  26. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/common.d.ts +14 -0
  27. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/common.js +87 -0
  28. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/date.d.ts +38 -0
  29. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/date.js +214 -0
  30. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/dayjs.d.ts +10 -0
  31. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/dayjs.js +72 -0
  32. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/forEach.d.ts +9 -0
  33. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/forEach.js +45 -0
  34. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/fs-exists.d.ts +9 -0
  35. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/fs-exists.js +46 -0
  36. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/getValuesByPath.d.ts +9 -0
  37. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/getValuesByPath.js +71 -0
  38. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/handlebars.d.ts +10 -0
  39. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/handlebars.js +73 -0
  40. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/i18n.d.ts +10 -0
  41. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/i18n.js +43 -0
  42. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/index.d.ts +38 -0
  43. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/index.js +105 -0
  44. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isPortalInBody.d.ts +13 -0
  45. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isPortalInBody.js +54 -0
  46. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isValidFilter.d.ts +9 -0
  47. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isValidFilter.js +63 -0
  48. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/json-templates.d.ts +9 -0
  49. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/json-templates.js +141 -0
  50. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/koa-multer.d.ts +15 -0
  51. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/koa-multer.js +92 -0
  52. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/log.d.ts +9 -0
  53. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/log.js +39 -0
  54. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/measure-execution-time.d.ts +9 -0
  55. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/measure-execution-time.js +44 -0
  56. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/merge.d.ts +9 -0
  57. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/merge.js +55 -0
  58. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/AsyncEmitter.d.ts +11 -0
  59. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/AsyncEmitter.js +80 -0
  60. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/index.d.ts +9 -0
  61. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/index.js +48 -0
  62. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/notification.d.ts +9 -0
  63. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/notification.js +43 -0
  64. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/number.d.ts +9 -0
  65. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/number.js +45 -0
  66. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-date.d.ts +15 -0
  67. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-date.js +262 -0
  68. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-filter.d.ts +67 -0
  69. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-filter.js +320 -0
  70. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parseHTML.d.ts +15 -0
  71. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parseHTML.js +42 -0
  72. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/perf-hooks.d.ts +14 -0
  73. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/perf-hooks.js +69 -0
  74. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/registry.d.ts +22 -0
  75. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/registry.js +69 -0
  76. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/requireModule.d.ts +12 -0
  77. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/requireModule.js +90 -0
  78. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/server.d.ts +19 -0
  79. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/server.js +50 -0
  80. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/toposort.d.ts +18 -0
  81. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/toposort.js +83 -0
  82. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/uid.d.ts +9 -0
  83. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/uid.js +44 -0
  84. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/url.d.ts +14 -0
  85. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/url.js +46 -0
  86. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/wrap-middleware.d.ts +1 -0
  87. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/wrap-middleware.js +63 -0
  88. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/package.json +20 -0
  89. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/plugin-symlink.d.ts +6 -0
  90. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/plugin-symlink.js +102 -0
  91. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/server.d.ts +2 -0
  92. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/server.js +12 -0
  93. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/.eslintrc.js +5 -0
  94. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/.github/workflows/ci.yml +24 -0
  95. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/.github/workflows/lint.yml +23 -0
  96. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-fields-100mb-big.js +149 -0
  97. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-fields-100mb-small.js +143 -0
  98. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-files-100mb-big.js +154 -0
  99. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-files-100mb-small.js +148 -0
  100. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-urlencoded-fields-100pairs-small.js +101 -0
  101. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-urlencoded-fields-900pairs-small-alt.js +84 -0
  102. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/index.js +57 -0
  103. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/types/multipart.js +653 -0
  104. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/types/urlencoded.js +350 -0
  105. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/utils.js +596 -0
  106. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/package.json +22 -0
  107. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/common.js +109 -0
  108. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-multipart-charsets.js +94 -0
  109. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-multipart-stream-pause.js +102 -0
  110. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-multipart.js +1053 -0
  111. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-urlencoded.js +488 -0
  112. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test.js +20 -0
  113. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/index.js +104 -0
  114. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/counter.js +28 -0
  115. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/file-appender.js +67 -0
  116. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/make-middleware.js +173 -0
  117. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/multer-error.js +24 -0
  118. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/remove-uploaded-files.js +28 -0
  119. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/package.json +52 -0
  120. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/storage/disk.js +66 -0
  121. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/storage/memory.js +21 -0
  122. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/.eslintrc.js +5 -0
  123. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/.github/workflows/ci.yml +24 -0
  124. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/.github/workflows/lint.yml +23 -0
  125. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/lib/sbmh.js +267 -0
  126. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/package.json +34 -0
  127. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/test/test.js +70 -0
  128. package/dist/node_modules/@nocobase/lock-manager/package.json +1 -0
  129. package/dist/node_modules/@nocobase/lock-manager/src/__tests__/lock-manager.test.ts +169 -0
  130. package/dist/node_modules/@nocobase/lock-manager/src/index.ts +11 -0
  131. package/dist/node_modules/@nocobase/lock-manager/src/lock-manager.ts +169 -0
  132. package/dist/server/action.d.ts +26 -0
  133. package/dist/server/action.js +168 -0
  134. package/dist/server/index.d.ts +10 -0
  135. package/dist/server/index.js +48 -0
  136. package/dist/server/plugin.d.ts +19 -0
  137. package/dist/server/plugin.js +69 -0
  138. package/dist/server/sort-field.d.ts +24 -0
  139. package/dist/server/sort-field.js +197 -0
  140. package/package.json +16 -0
  141. package/server.d.ts +2 -0
  142. 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
@@ -0,0 +1,2 @@
1
+ export * from './dist/server';
2
+ export { default } from './dist/server';
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/server/index.js');