@tachybase/module-data-source 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.
Files changed (122) hide show
  1. package/.turbo/turbo-build.log +14 -0
  2. package/LICENSE +201 -0
  3. package/README.md +1 -0
  4. package/client.d.ts +2 -0
  5. package/client.js +1 -0
  6. package/dist/client/DatabaseConnectionProvider.d.ts +3 -0
  7. package/dist/client/ThridDataSource.d.ts +4 -0
  8. package/dist/client/component/BreadcumbTitle.d.ts +2 -0
  9. package/dist/client/component/CollectionsManager/AddFieldAction.d.ts +5 -0
  10. package/dist/client/component/CollectionsManager/CollectionFields.d.ts +8 -0
  11. package/dist/client/component/CollectionsManager/ConfigurationTable.d.ts +2 -0
  12. package/dist/client/component/CollectionsManager/ConfigurationTabs.d.ts +2 -0
  13. package/dist/client/component/CollectionsManager/EditCollectionAction.d.ts +6 -0
  14. package/dist/client/component/CollectionsManager/EditFieldAction.d.ts +2 -0
  15. package/dist/client/component/CollectionsManager/components/CollectionFieldInterfaceSelect.d.ts +2 -0
  16. package/dist/client/component/CollectionsManager/components/CollectionName.d.ts +1 -0
  17. package/dist/client/component/CollectionsManager/components/FieldTitleInput.d.ts +2 -0
  18. package/dist/client/component/CollectionsManager/components/FieldType.d.ts +2 -0
  19. package/dist/client/component/CollectionsManager/components/TitleField.d.ts +2 -0
  20. package/dist/client/component/CollectionsManager/components/UnSupportFields.d.ts +2 -0
  21. package/dist/client/component/CollectionsManager/components/index.d.ts +6 -0
  22. package/dist/client/component/CollectionsManager/hooks.d.ts +12 -0
  23. package/dist/client/component/CollectionsManager/index.d.ts +2 -0
  24. package/dist/client/component/CollectionsManager/schema/collectionFields.d.ts +4 -0
  25. package/dist/client/component/CollectionsManager/schema/collections.d.ts +8 -0
  26. package/dist/client/component/CreateDatabaseConnectAction.d.ts +2 -0
  27. package/dist/client/component/DatabaseConnectionManager.d.ts +2 -0
  28. package/dist/client/component/DatasourceLink.d.ts +2 -0
  29. package/dist/client/component/EditDatabaseConnectionAction.d.ts +2 -0
  30. package/dist/client/component/MainDataSourceManager/Configuration/AddCategoryAction.d.ts +3 -0
  31. package/dist/client/component/MainDataSourceManager/Configuration/CollectionFields.d.ts +2 -0
  32. package/dist/client/component/MainDataSourceManager/Configuration/CollectionFieldsTable.d.ts +15 -0
  33. package/dist/client/component/MainDataSourceManager/Configuration/CollectionFieldsTableArray.d.ts +8 -0
  34. package/dist/client/component/MainDataSourceManager/Configuration/ConfigurationTable.d.ts +2 -0
  35. package/dist/client/component/MainDataSourceManager/Configuration/ConfigurationTabs.d.ts +2 -0
  36. package/dist/client/component/MainDataSourceManager/Configuration/EditCategoryAction.d.ts +3 -0
  37. package/dist/client/component/MainDataSourceManager/Configuration/index.d.ts +6 -0
  38. package/dist/client/component/MainDataSourceManager/Configuration/interfaces.d.ts +16 -0
  39. package/dist/client/component/MainDataSourceManager/Configuration/schemas/collectionFields.d.ts +5 -0
  40. package/dist/client/component/MainDataSourceManager/Configuration/schemas/collections.d.ts +7 -0
  41. package/dist/client/component/MainDataSourceManager/index.d.ts +2 -0
  42. package/dist/client/component/PermissionManager/DataSourceTable.d.ts +3 -0
  43. package/dist/client/component/PermissionManager/PermisionProvider.d.ts +5 -0
  44. package/dist/client/component/PermissionManager/RoleConfigure.d.ts +2 -0
  45. package/dist/client/component/PermissionManager/RolesResourcesActions.d.ts +3 -0
  46. package/dist/client/component/PermissionManager/ScopeSelect.d.ts +3 -0
  47. package/dist/client/component/PermissionManager/StrategyActions.d.ts +2 -0
  48. package/dist/client/component/PermissionManager/index.d.ts +3 -0
  49. package/dist/client/component/PermissionManager/schemas/dataSourceTable.d.ts +2 -0
  50. package/dist/client/component/PermissionManager/schemas/roleCollections.d.ts +2 -0
  51. package/dist/client/component/PermissionManager/schemas/scopes.d.ts +11 -0
  52. package/dist/client/component/PermissionManager/schemas/useRoleResourceValues.d.ts +8 -0
  53. package/dist/client/component/PermissionManager/schemas/useSaveRoleResourceAction.d.ts +3 -0
  54. package/dist/client/component/PermissionManager/style.d.ts +1 -0
  55. package/dist/client/component/ViewDatabaseConnectionAction.d.ts +2 -0
  56. package/dist/client/constant.d.ts +4 -0
  57. package/dist/client/hooks/index.d.ts +6 -0
  58. package/dist/client/index.d.ts +9 -0
  59. package/dist/client/index.js +56 -0
  60. package/dist/client/locale/index.d.ts +3 -0
  61. package/dist/client/schema/index.d.ts +7 -0
  62. package/dist/externalVersion.js +19 -0
  63. package/dist/index.d.ts +2 -0
  64. package/dist/index.js +39 -0
  65. package/dist/locale/zh-CN.json +35 -0
  66. package/dist/server/collections/data-sources-collections.d.ts +2 -0
  67. package/dist/server/collections/data-sources-collections.js +66 -0
  68. package/dist/server/collections/data-sources-fields.d.ts +2 -0
  69. package/dist/server/collections/data-sources-fields.js +87 -0
  70. package/dist/server/collections/data-sources-roles-resources-actions.d.ts +2 -0
  71. package/dist/server/collections/data-sources-roles-resources-actions.js +52 -0
  72. package/dist/server/collections/data-sources-roles-resources-scopes.d.ts +2 -0
  73. package/dist/server/collections/data-sources-roles-resources-scopes.js +56 -0
  74. package/dist/server/collections/data-sources-roles-resources.d.ts +2 -0
  75. package/dist/server/collections/data-sources-roles-resources.js +62 -0
  76. package/dist/server/collections/data-sources-roles.d.ts +2 -0
  77. package/dist/server/collections/data-sources-roles.js +54 -0
  78. package/dist/server/collections/data-sources.d.ts +2 -0
  79. package/dist/server/collections/data-sources.js +71 -0
  80. package/dist/server/errors/type-infer-error.d.ts +2 -0
  81. package/dist/server/errors/type-infer-error.js +28 -0
  82. package/dist/server/index.d.ts +2 -0
  83. package/dist/server/index.js +39 -0
  84. package/dist/server/migrations/20240301164024-migrate-acl-resources.d.ts +7 -0
  85. package/dist/server/migrations/20240301164024-migrate-acl-resources.js +117 -0
  86. package/dist/server/models/connections-roles-resources-action.d.ts +3 -0
  87. package/dist/server/models/connections-roles-resources-action.js +29 -0
  88. package/dist/server/models/connections-roles-resources.d.ts +3 -0
  89. package/dist/server/models/connections-roles-resources.js +29 -0
  90. package/dist/server/models/data-source.d.ts +18 -0
  91. package/dist/server/models/data-source.js +170 -0
  92. package/dist/server/models/data-sources-collection-model.d.ts +7 -0
  93. package/dist/server/models/data-sources-collection-model.js +37 -0
  94. package/dist/server/models/data-sources-field-model.d.ts +10 -0
  95. package/dist/server/models/data-sources-field-model.js +54 -0
  96. package/dist/server/models/data-sources-roles-model.d.ts +13 -0
  97. package/dist/server/models/data-sources-roles-model.js +58 -0
  98. package/dist/server/plugin.d.ts +13 -0
  99. package/dist/server/plugin.js +448 -0
  100. package/dist/server/resourcers/data-sources-collections-fields.d.ts +11 -0
  101. package/dist/server/resourcers/data-sources-collections-fields.js +131 -0
  102. package/dist/server/resourcers/data-sources-collections.d.ts +8 -0
  103. package/dist/server/resourcers/data-sources-collections.js +106 -0
  104. package/dist/server/resourcers/data-sources-resources.d.ts +9 -0
  105. package/dist/server/resourcers/data-sources-resources.js +88 -0
  106. package/dist/server/resourcers/data-sources-roles.d.ts +8 -0
  107. package/dist/server/resourcers/data-sources-roles.js +89 -0
  108. package/dist/server/resourcers/roles-data-sources-collections.d.ts +7 -0
  109. package/dist/server/resourcers/roles-data-sources-collections.js +102 -0
  110. package/dist/server/services/collection-manager.d.ts +6 -0
  111. package/dist/server/services/collection-manager.js +33 -0
  112. package/dist/server/services/database-introspector.d.ts +70 -0
  113. package/dist/server/services/database-introspector.js +235 -0
  114. package/dist/server/services/full-data-repository.d.ts +8 -0
  115. package/dist/server/services/full-data-repository.js +51 -0
  116. package/dist/server/services/type-interface-map.d.ts +183 -0
  117. package/dist/server/services/type-interface-map.js +243 -0
  118. package/dist/server/utils.d.ts +1 -0
  119. package/dist/server/utils.js +38 -0
  120. package/package.json +36 -0
  121. package/server.d.ts +2 -0
  122. package/server.js +1 -0
@@ -0,0 +1,106 @@
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 __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var data_sources_collections_exports = {};
29
+ __export(data_sources_collections_exports, {
30
+ default: () => data_sources_collections_default
31
+ });
32
+ module.exports = __toCommonJS(data_sources_collections_exports);
33
+ var import_lodash = __toESM(require("lodash"));
34
+ var data_sources_collections_default = {
35
+ name: "dataSources.collections",
36
+ actions: {
37
+ async list(ctx, next) {
38
+ var _a, _b;
39
+ const params = ctx.action.params;
40
+ const { associatedIndex: dataSourceKey } = params;
41
+ const dataSource = ctx.app.dataSourceManager.dataSources.get(dataSourceKey);
42
+ if (!dataSource) {
43
+ throw new Error(`dataSource ${dataSourceKey} not found`);
44
+ }
45
+ const { paginate, filter } = ctx.action.params;
46
+ const filterTitle = (_a = import_lodash.default.get(filter, "$and.0.title.$includes")) == null ? void 0 : _a.toLowerCase();
47
+ const filterName = (_b = import_lodash.default.get(filter, "$and.0.name.$includes")) == null ? void 0 : _b.toLowerCase();
48
+ const collections = import_lodash.default.sortBy(
49
+ dataSource.collectionManager.getCollections().filter((collection) => {
50
+ var _a2;
51
+ return (!filterTitle || ((_a2 = import_lodash.default.get(collection, "options.title")) == null ? void 0 : _a2.toLowerCase().includes(filterTitle))) && (!filterName || collection.options.name.toLowerCase().includes(filterName));
52
+ }),
53
+ "name"
54
+ );
55
+ const mapCollection = (collections2) => {
56
+ return collections2.map((collection) => {
57
+ return {
58
+ ...collection.options,
59
+ fields: collection.getFields().map((field) => field.options)
60
+ };
61
+ });
62
+ };
63
+ if (paginate === false || paginate === "false") {
64
+ ctx.body = mapCollection(collections);
65
+ } else {
66
+ const { page = 1, pageSize = 20 } = ctx.action.params;
67
+ ctx.withoutDataWrapping = true;
68
+ ctx.body = {
69
+ data: mapCollection(collections.slice((page - 1) * pageSize, page * pageSize)),
70
+ meta: {
71
+ count: collections.length,
72
+ page,
73
+ pageSize,
74
+ totalPage: Math.ceil(collections.length / pageSize)
75
+ }
76
+ };
77
+ }
78
+ await next();
79
+ },
80
+ async update(ctx, next) {
81
+ const params = ctx.action.params;
82
+ const { filterByTk: collectionName, associatedIndex: dataSourceKey } = params;
83
+ let dataSourceCollectionRecord = await ctx.db.getRepository("dataSourcesCollections").findOne({
84
+ filter: {
85
+ name: collectionName,
86
+ dataSourceKey
87
+ }
88
+ });
89
+ if (!dataSourceCollectionRecord) {
90
+ dataSourceCollectionRecord = await ctx.db.getRepository("dataSourcesCollections").create({
91
+ values: {
92
+ ...params.values,
93
+ name: collectionName,
94
+ dataSourceKey
95
+ }
96
+ });
97
+ } else {
98
+ await dataSourceCollectionRecord.update({
99
+ ...params.values
100
+ });
101
+ }
102
+ ctx.body = dataSourceCollectionRecord.toJSON();
103
+ await next();
104
+ }
105
+ }
106
+ };
@@ -0,0 +1,9 @@
1
+ declare const _default: {
2
+ name: string;
3
+ actions: {
4
+ create(ctx: any, next: any): Promise<void>;
5
+ update(ctx: any, next: any): Promise<void>;
6
+ get(ctx: any, next: any): Promise<void>;
7
+ };
8
+ };
9
+ export default _default;
@@ -0,0 +1,88 @@
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 data_sources_resources_exports = {};
19
+ __export(data_sources_resources_exports, {
20
+ default: () => data_sources_resources_default
21
+ });
22
+ module.exports = __toCommonJS(data_sources_resources_exports);
23
+ var data_sources_resources_default = {
24
+ name: "roles.dataSourceResources",
25
+ actions: {
26
+ async create(ctx, next) {
27
+ const { associatedIndex: roleName } = ctx.action.params;
28
+ const db = ctx.db;
29
+ const transaction = await db.sequelize.transaction();
30
+ const dataSourceKey = ctx.action.params.values.dataSourceKey;
31
+ if (!dataSourceKey) {
32
+ throw new Error("dataSourceKey is required");
33
+ }
34
+ const connectionRole = await db.getRepository("dataSourcesRoles").findOne({
35
+ filter: {
36
+ roleName,
37
+ dataSourceKey
38
+ },
39
+ transaction
40
+ });
41
+ if (!connectionRole) {
42
+ await db.getRepository("dataSourcesRoles").create({
43
+ values: {
44
+ roleName,
45
+ dataSourceKey
46
+ },
47
+ transaction
48
+ });
49
+ }
50
+ const record = await db.getRepository("dataSourcesRolesResources").create({
51
+ values: {
52
+ roleName,
53
+ ...ctx.action.params.values
54
+ },
55
+ transaction
56
+ });
57
+ await transaction.commit();
58
+ ctx.body = record.toJSON();
59
+ await next();
60
+ },
61
+ async update(ctx, next) {
62
+ const { associatedIndex: roleName } = ctx.action.params;
63
+ ctx.body = await ctx.db.getRepository("dataSourcesRolesResources").update({
64
+ filter: {
65
+ roleName,
66
+ dataSourceKey: ctx.action.params.filter.dataSourceKey,
67
+ name: ctx.action.params.filter.name
68
+ },
69
+ values: ctx.action.params.values,
70
+ updateAssociationValues: ["actions"]
71
+ });
72
+ await next();
73
+ },
74
+ async get(ctx, next) {
75
+ const { associatedIndex: roleName } = ctx.action.params;
76
+ const record = await ctx.db.getRepository("dataSourcesRolesResources").findOne({
77
+ filter: {
78
+ roleName,
79
+ dataSourceKey: ctx.action.params.filter.dataSourceKey,
80
+ name: ctx.action.params.filter.name
81
+ },
82
+ appends: ctx.action.params.appends
83
+ });
84
+ ctx.body = record;
85
+ await next();
86
+ }
87
+ }
88
+ };
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ name: string;
3
+ actions: {
4
+ update(ctx: any, next: any): Promise<void>;
5
+ get(ctx: any, next: any): Promise<void>;
6
+ };
7
+ };
8
+ export default _default;
@@ -0,0 +1,89 @@
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 data_sources_roles_exports = {};
19
+ __export(data_sources_roles_exports, {
20
+ default: () => data_sources_roles_default
21
+ });
22
+ module.exports = __toCommonJS(data_sources_roles_exports);
23
+ var data_sources_roles_default = {
24
+ name: "dataSources.roles",
25
+ actions: {
26
+ async update(ctx, next) {
27
+ const params = ctx.action.params;
28
+ const { filterByTk: name, associatedIndex: dataSourceKey } = params;
29
+ let connectionRoleRecord = await ctx.db.getRepository("dataSourcesRoles").findOne({
30
+ filter: {
31
+ roleName: name,
32
+ dataSourceKey
33
+ }
34
+ });
35
+ if (!connectionRoleRecord) {
36
+ connectionRoleRecord = await ctx.db.getRepository("dataSourcesRoles").create({
37
+ values: {
38
+ ...params.values,
39
+ roleName: name,
40
+ dataSourceKey
41
+ }
42
+ });
43
+ } else {
44
+ await connectionRoleRecord.update({
45
+ ...params.values
46
+ });
47
+ }
48
+ if (params.values.resources) {
49
+ await ctx.db.getRepository("dataSourcesRolesResources").destroy({
50
+ filter: {
51
+ roleName: name,
52
+ dataSourceKey
53
+ }
54
+ });
55
+ for (const resource of params.values.resources) {
56
+ await ctx.db.getRepository("dataSourcesRolesResources").create({
57
+ values: {
58
+ ...resource,
59
+ roleName: name,
60
+ dataSourceKey
61
+ }
62
+ });
63
+ }
64
+ }
65
+ ctx.body = connectionRoleRecord.toJSON();
66
+ await next();
67
+ },
68
+ async get(ctx, next) {
69
+ const params = ctx.action.params;
70
+ const { filterByTk: name, associatedIndex: dataSourceKey } = params;
71
+ let connectionRoleRecord = await ctx.db.getRepository("dataSourcesRoles").findOne({
72
+ filter: {
73
+ roleName: name,
74
+ dataSourceKey
75
+ }
76
+ });
77
+ if (!connectionRoleRecord) {
78
+ connectionRoleRecord = await ctx.db.getRepository("dataSourcesRoles").create({
79
+ values: {
80
+ roleName: name,
81
+ dataSourceKey
82
+ }
83
+ });
84
+ }
85
+ ctx.body = connectionRoleRecord.toJSON();
86
+ await next();
87
+ }
88
+ }
89
+ };
@@ -0,0 +1,7 @@
1
+ declare const rolesRemoteCollectionsResourcer: {
2
+ name: string;
3
+ actions: {
4
+ list(ctx: any, next: any): Promise<void>;
5
+ };
6
+ };
7
+ export { rolesRemoteCollectionsResourcer };
@@ -0,0 +1,102 @@
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 __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var roles_data_sources_collections_exports = {};
29
+ __export(roles_data_sources_collections_exports, {
30
+ rolesRemoteCollectionsResourcer: () => rolesRemoteCollectionsResourcer
31
+ });
32
+ module.exports = __toCommonJS(roles_data_sources_collections_exports);
33
+ var import_lodash = __toESM(require("lodash"));
34
+ var import_full_data_repository = require("../services/full-data-repository");
35
+ function totalPage(total, pageSize) {
36
+ return Math.ceil(total / pageSize);
37
+ }
38
+ const rolesRemoteCollectionsResourcer = {
39
+ name: "roles.dataSourcesCollections",
40
+ actions: {
41
+ async list(ctx, next) {
42
+ var _a, _b;
43
+ const role = ctx.action.params.associatedIndex;
44
+ const { page = 1, pageSize = 20 } = ctx.action.params;
45
+ const { filter } = ctx.action.params;
46
+ const { dataSourceKey } = filter;
47
+ const dataSource = ctx.app.dataSourceManager.dataSources.get(dataSourceKey);
48
+ const collectionRepository = new import_full_data_repository.FullDataRepository(dataSource.collectionManager.getCollections());
49
+ const [collections] = await collectionRepository.findAndCount();
50
+ const filterItem = import_lodash.default.get(filter, "$and");
51
+ const filterByTitle = filterItem == null ? void 0 : filterItem.find((item) => item.title);
52
+ const filterByName = filterItem == null ? void 0 : filterItem.find((item) => item.name);
53
+ const filterTitle = (_a = import_lodash.default.get(filterByTitle, "title.$includes")) == null ? void 0 : _a.toLowerCase();
54
+ const filterName = (_b = import_lodash.default.get(filterByName, "name.$includes")) == null ? void 0 : _b.toLowerCase();
55
+ const roleResources = await ctx.app.db.getRepository("dataSourcesRolesResources").find({
56
+ filter: {
57
+ roleName: role,
58
+ dataSourceKey
59
+ }
60
+ });
61
+ const roleResourcesNames = roleResources.map((roleResource) => roleResource.get("name"));
62
+ const roleResourceActionResourceNames = roleResources.filter((roleResources2) => roleResources2.get("usingActionsConfig")).map((roleResources2) => roleResources2.get("name"));
63
+ const filtedCollections = collections.filter((collection) => {
64
+ var _a2;
65
+ return (!filterTitle || ((_a2 = import_lodash.default.get(collection, "options.title")) == null ? void 0 : _a2.toLowerCase().includes(filterTitle))) && (!filterName || collection.options.name.toLowerCase().includes(filterName));
66
+ });
67
+ const items = import_lodash.default.sortBy(
68
+ filtedCollections.map((collection, i) => {
69
+ var _a2;
70
+ const collectionName = collection.options.name;
71
+ const exists = roleResourcesNames.includes(collectionName);
72
+ const usingConfig = roleResourceActionResourceNames.includes(collectionName) ? "resourceAction" : "strategy";
73
+ return {
74
+ type: "collection",
75
+ name: collectionName,
76
+ collectionName,
77
+ title: ((_a2 = collection.options.uiSchema) == null ? void 0 : _a2.title) || collection.options.title,
78
+ roleName: role,
79
+ usingConfig,
80
+ exists,
81
+ fields: [...collection.fields.values()].map((field) => {
82
+ return field.options;
83
+ })
84
+ };
85
+ }),
86
+ "name"
87
+ );
88
+ ctx.body = {
89
+ count: filtedCollections.length,
90
+ rows: items,
91
+ page: Number(page),
92
+ pageSize: Number(pageSize),
93
+ totalPage: totalPage(filtedCollections.length, pageSize)
94
+ };
95
+ await next();
96
+ }
97
+ }
98
+ };
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ rolesRemoteCollectionsResourcer
102
+ });
@@ -0,0 +1,6 @@
1
+ import { Database } from '@tachybase/database';
2
+ export declare class CollectionManager {
3
+ private db;
4
+ constructor(db: Database);
5
+ findAndCount(): void;
6
+ }
@@ -0,0 +1,33 @@
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 collection_manager_exports = {};
19
+ __export(collection_manager_exports, {
20
+ CollectionManager: () => CollectionManager
21
+ });
22
+ module.exports = __toCommonJS(collection_manager_exports);
23
+ class CollectionManager {
24
+ constructor(db) {
25
+ this.db = db;
26
+ }
27
+ findAndCount() {
28
+ }
29
+ }
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ CollectionManager
33
+ });
@@ -0,0 +1,70 @@
1
+ import { Database } from '@tachybase/database';
2
+ type tableInfo = {
3
+ tableName: string;
4
+ schema?: string;
5
+ };
6
+ type GetCollectionOptions = {
7
+ tableInfo: tableInfo;
8
+ localOptions?: PartialCollectionOptions;
9
+ };
10
+ export type LocalData = {
11
+ [collectionName: string]: PartialCollectionOptions;
12
+ };
13
+ type GetCollectionsOptions = {
14
+ localData?: LocalData;
15
+ };
16
+ export type PartialCollectionOptions = Partial<Omit<CollectionOptions, 'fields'> & {
17
+ fields?: Partial<FieldOptions>[];
18
+ }>;
19
+ interface CollectionOptions {
20
+ name: string;
21
+ schema?: string;
22
+ tableName: string;
23
+ title?: string;
24
+ timestamps?: boolean;
25
+ filterTargetKey?: string;
26
+ fields: FieldOptions[];
27
+ unsupportedFields?: UnsupportedFieldOptions[];
28
+ }
29
+ interface UnsupportedFieldOptions {
30
+ rawType: string;
31
+ name: string;
32
+ supported: false;
33
+ }
34
+ interface FieldOptions {
35
+ name: string;
36
+ field: string;
37
+ rawType: string;
38
+ type: string;
39
+ description?: string;
40
+ interface?: string;
41
+ uiSchema?: any;
42
+ possibleTypes?: string[];
43
+ defaultValue?: any;
44
+ primaryKey: boolean;
45
+ unique: boolean;
46
+ allowNull?: boolean;
47
+ autoIncrement?: boolean;
48
+ }
49
+ export declare class DatabaseIntrospector {
50
+ private db;
51
+ constructor(db: Database);
52
+ getCollections(options?: GetCollectionsOptions): Promise<Array<CollectionOptions>>;
53
+ getCollection(options: GetCollectionOptions): Promise<CollectionOptions>;
54
+ loadCollection(options: CollectionOptions): void;
55
+ loadCollections(options: {
56
+ collections: CollectionOptions[];
57
+ }): void;
58
+ tableInfoToCollectionOptions(tableInfo: tableInfo): {
59
+ name: string;
60
+ schema?: string;
61
+ tableName: string;
62
+ title?: string;
63
+ };
64
+ private collectionOptionsByFields;
65
+ private mergeLocalDataIntoCollectionOptions;
66
+ private columnInfoToFieldOptions;
67
+ private getDefaultInterfaceByType;
68
+ private columnAttribute;
69
+ }
70
+ export {};