@nocobase/plugin-data-source-manager 2.1.0-beta.8 → 2.2.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 (96) hide show
  1. package/client-v2.d.ts +2 -0
  2. package/client-v2.js +1 -0
  3. package/dist/ai/ai-employees/orin/ignored.d.ts +10 -0
  4. package/dist/ai/ai-employees/orin/ignored.js +59 -0
  5. package/dist/ai/ai-employees/orin/skills/data-modeling/SKILLS.md +245 -0
  6. package/dist/ai/{tools → ai-employees/orin/skills/data-modeling/tools}/defineCollections.js +47 -1
  7. package/dist/ai/{tools → ai-employees/orin/skills/data-modeling/tools}/intentRouter.js +1 -1
  8. package/dist/ai/{tools/data-query → common}/common.js +63 -11
  9. package/dist/ai/{tools/data-query → common}/utils.d.ts +1 -0
  10. package/dist/ai/{tools/data-query → common}/utils.js +15 -0
  11. package/dist/ai/skills/data-metadata/SKILLS.md +108 -0
  12. package/dist/ai/{tools → skills/data-metadata/tools}/getCollectionMetadata.js +2 -2
  13. package/dist/ai/{tools → skills/data-metadata/tools}/getCollectionNames.js +2 -2
  14. package/dist/ai/{tools → skills/data-metadata/tools}/getDataSources.js +2 -2
  15. package/dist/ai/{tools → skills/data-metadata/tools}/searchFieldMetadata.js +2 -2
  16. package/dist/ai/skills/data-query/SKILLS.md +245 -0
  17. package/dist/ai/skills/data-query/tools/dataQuery.js +282 -0
  18. package/dist/ai/{tools/data-query → skills/data-query/tools}/dataSourceCounting.js +12 -4
  19. package/dist/ai/skills/data-query/tools/dataSourceQuery.d.ts +10 -0
  20. package/dist/ai/{tools/data-query → skills/data-query/tools}/dataSourceQuery.js +12 -5
  21. package/dist/client/271.1374702d84646fff.js +10 -0
  22. package/dist/client/369.342f1e0231dbe482.js +10 -0
  23. package/dist/client/397.c8c6659cf3f7ac1c.js +10 -0
  24. package/dist/client/416.197712b8b93033c5.js +10 -0
  25. package/dist/client/420.a37695bbfc3bec7a.js +10 -0
  26. package/dist/client/603.d6022bceb934f5b0.js +10 -0
  27. package/dist/client/644.b98e4b39058e9c32.js +10 -0
  28. package/dist/client/936.d5ab7aecb4eb6004.js +10 -0
  29. package/dist/client/index.js +1 -1
  30. package/dist/client-v2/167.52e683be46f9cfc7.js +10 -0
  31. package/dist/client-v2/426.53e3eaee8d9dbca0.js +10 -0
  32. package/dist/client-v2/907.a0ab273516f45ac3.js +10 -0
  33. package/dist/client-v2/components/DataSourceForm.d.ts +17 -0
  34. package/dist/client-v2/field-interfaces/index.d.ts +13 -0
  35. package/dist/client-v2/index.d.ts +12 -0
  36. package/dist/client-v2/index.js +10 -0
  37. package/dist/client-v2/locale.d.ts +12 -0
  38. package/dist/client-v2/pages/DataSourceCollectionsPage.d.ts +10 -0
  39. package/dist/client-v2/pages/DataSourcesPage.d.ts +10 -0
  40. package/dist/client-v2/pages/components/CollectionsPage.d.ts +27 -0
  41. package/dist/client-v2/pages/components/FieldForm.d.ts +19 -0
  42. package/dist/client-v2/pages/components/FieldsPage.d.ts +16 -0
  43. package/dist/client-v2/pages/components/ViewCollectionConfigure.d.ts +27 -0
  44. package/dist/client-v2/pages/components/collectionFieldApi.d.ts +11 -0
  45. package/dist/client-v2/pages/components/collectionTemplateFieldInterfaces.d.ts +18 -0
  46. package/dist/client-v2/pages/permissions/DataSourcePermissionsTab.d.ts +15 -0
  47. package/dist/client-v2/pages/permissions/PermissionEditors.d.ts +45 -0
  48. package/dist/client-v2/pages/permissions/ScopeSelect.d.ts +21 -0
  49. package/dist/client-v2/pages/permissions/permissionRequests.d.ts +33 -0
  50. package/dist/client-v2/pages/permissions/types.d.ts +55 -0
  51. package/dist/client-v2/plugin.d.ts +243 -0
  52. package/dist/client-v2/registries.d.ts +36 -0
  53. package/dist/client-v2/runtime.d.ts +12 -0
  54. package/dist/client-v2/utils/compileLegacyTemplate.d.ts +16 -0
  55. package/dist/client-v2/utils/error.d.ts +11 -0
  56. package/dist/externalVersion.js +17 -13
  57. package/dist/locale/en-US.json +275 -3
  58. package/dist/locale/zh-CN.json +275 -3
  59. package/dist/node_modules/zod/index.cjs +1 -1
  60. package/dist/node_modules/zod/package.json +1 -1
  61. package/dist/server/collections/data-sources-collections.js +1 -0
  62. package/dist/server/collections/data-sources-fields.js +1 -0
  63. package/dist/server/collections/data-sources-roles-resources-actions.js +1 -0
  64. package/dist/server/collections/data-sources-roles-resources-scopes.js +1 -0
  65. package/dist/server/collections/data-sources-roles-resources.js +1 -0
  66. package/dist/server/collections/data-sources-roles.js +1 -0
  67. package/dist/server/collections/data-sources.js +1 -0
  68. package/dist/server/mcp-post-processors.d.ts +24 -0
  69. package/dist/server/mcp-post-processors.js +158 -0
  70. package/dist/server/models/data-source.js +3 -13
  71. package/dist/server/plugin.js +7 -2
  72. package/dist/server/resourcers/data-sources-collections-fields.d.ts +1 -0
  73. package/dist/server/resourcers/data-sources-collections-fields.js +19 -0
  74. package/dist/server/services/external-field-apply.d.ts +23 -0
  75. package/dist/server/services/external-field-apply.js +208 -0
  76. package/dist/server/utils.js +11 -3
  77. package/dist/swagger/index.d.ts +326 -0
  78. package/dist/swagger/index.js +385 -0
  79. package/package.json +4 -2
  80. package/dist/client/1a8cce8035a89dd9.js +0 -10
  81. package/dist/client/276bcf3de74bebd1.js +0 -10
  82. package/dist/client/2f7a418e7935984d.js +0 -10
  83. package/dist/client/689d3bec33ad2ec3.js +0 -10
  84. package/dist/client/d33eb40009bd7ec6.js +0 -10
  85. package/dist/client/dbf5ddf434ab29c0.js +0 -10
  86. package/dist/client/f528b165e77e3608.js +0 -10
  87. package/dist/client/fdae18574fda07af.js +0 -10
  88. /package/dist/ai/{tools → ai-employees/orin/skills/data-modeling/tools}/defineCollections.d.ts +0 -0
  89. /package/dist/ai/{tools → ai-employees/orin/skills/data-modeling/tools}/intentRouter.d.ts +0 -0
  90. /package/dist/ai/{tools/data-query → common}/common.d.ts +0 -0
  91. /package/dist/ai/{tools → skills/data-metadata/tools}/getCollectionMetadata.d.ts +0 -0
  92. /package/dist/ai/{tools → skills/data-metadata/tools}/getCollectionNames.d.ts +0 -0
  93. /package/dist/ai/{tools → skills/data-metadata/tools}/getDataSources.d.ts +0 -0
  94. /package/dist/ai/{tools → skills/data-metadata/tools}/searchFieldMetadata.d.ts +0 -0
  95. /package/dist/ai/{tools/data-query/dataSourceCounting.d.ts → skills/data-query/tools/dataQuery.d.ts} +0 -0
  96. /package/dist/ai/{tools/data-query/dataSourceQuery.d.ts → skills/data-query/tools/dataSourceCounting.d.ts} +0 -0
@@ -1 +1 @@
1
- {"name":"zod","version":"4.3.5","type":"module","license":"MIT","author":"Colin McDonnell <zod@colinhacks.com>","description":"TypeScript-first schema declaration and validation library with static type inference","homepage":"https://zod.dev","llms":"https://zod.dev/llms.txt","llmsFull":"https://zod.dev/llms-full.txt","mcpServer":"https://mcp.inkeep.com/zod/mcp","funding":"https://github.com/sponsors/colinhacks","sideEffects":false,"files":["src","**/*.js","**/*.mjs","**/*.cjs","**/*.d.ts","**/*.d.mts","**/*.d.cts","**/package.json"],"keywords":["typescript","schema","validation","type","inference"],"main":"./index.cjs","types":"./index.d.cts","module":"./index.js","zshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts","./mini":"./src/mini/index.ts","./locales":"./src/locales/index.ts","./v3":"./src/v3/index.ts","./v4":"./src/v4/index.ts","./v4-mini":"./src/v4-mini/index.ts","./v4/mini":"./src/v4/mini/index.ts","./v4/core":"./src/v4/core/index.ts","./v4/locales":"./src/v4/locales/index.ts","./v4/locales/*":"./src/v4/locales/*"},"conditions":{"@zod/source":"src"}},"exports":{"./package.json":"./package.json",".":{"@zod/source":"./src/index.ts","types":"./index.d.cts","import":"./index.js","require":"./index.cjs"},"./mini":{"@zod/source":"./src/mini/index.ts","types":"./mini/index.d.cts","import":"./mini/index.js","require":"./mini/index.cjs"},"./locales":{"@zod/source":"./src/locales/index.ts","types":"./locales/index.d.cts","import":"./locales/index.js","require":"./locales/index.cjs"},"./v3":{"@zod/source":"./src/v3/index.ts","types":"./v3/index.d.cts","import":"./v3/index.js","require":"./v3/index.cjs"},"./v4":{"@zod/source":"./src/v4/index.ts","types":"./v4/index.d.cts","import":"./v4/index.js","require":"./v4/index.cjs"},"./v4-mini":{"@zod/source":"./src/v4-mini/index.ts","types":"./v4-mini/index.d.cts","import":"./v4-mini/index.js","require":"./v4-mini/index.cjs"},"./v4/mini":{"@zod/source":"./src/v4/mini/index.ts","types":"./v4/mini/index.d.cts","import":"./v4/mini/index.js","require":"./v4/mini/index.cjs"},"./v4/core":{"@zod/source":"./src/v4/core/index.ts","types":"./v4/core/index.d.cts","import":"./v4/core/index.js","require":"./v4/core/index.cjs"},"./v4/locales":{"@zod/source":"./src/v4/locales/index.ts","types":"./v4/locales/index.d.cts","import":"./v4/locales/index.js","require":"./v4/locales/index.cjs"},"./v4/locales/*":{"@zod/source":"./src/v4/locales/*","types":"./v4/locales/*","import":"./v4/locales/*","require":"./v4/locales/*"}},"repository":{"type":"git","url":"git+https://github.com/colinhacks/zod.git"},"bugs":{"url":"https://github.com/colinhacks/zod/issues"},"support":{"backing":{"npm-funding":true}},"scripts":{"clean":"git clean -xdf . -e node_modules","build":"zshy --project tsconfig.build.json","postbuild":"tsx ../../scripts/write-stub-package-jsons.ts && pnpm biome check --write .","test:watch":"pnpm vitest","test":"pnpm vitest run","prepublishOnly":"tsx ../../scripts/check-versions.ts"},"_lastModified":"2026-03-11T23:47:57.735Z"}
1
+ {"name":"zod","version":"4.3.5","type":"module","license":"MIT","author":"Colin McDonnell <zod@colinhacks.com>","description":"TypeScript-first schema declaration and validation library with static type inference","homepage":"https://zod.dev","llms":"https://zod.dev/llms.txt","llmsFull":"https://zod.dev/llms-full.txt","mcpServer":"https://mcp.inkeep.com/zod/mcp","funding":"https://github.com/sponsors/colinhacks","sideEffects":false,"files":["src","**/*.js","**/*.mjs","**/*.cjs","**/*.d.ts","**/*.d.mts","**/*.d.cts","**/package.json"],"keywords":["typescript","schema","validation","type","inference"],"main":"./index.cjs","types":"./index.d.cts","module":"./index.js","zshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts","./mini":"./src/mini/index.ts","./locales":"./src/locales/index.ts","./v3":"./src/v3/index.ts","./v4":"./src/v4/index.ts","./v4-mini":"./src/v4-mini/index.ts","./v4/mini":"./src/v4/mini/index.ts","./v4/core":"./src/v4/core/index.ts","./v4/locales":"./src/v4/locales/index.ts","./v4/locales/*":"./src/v4/locales/*"},"conditions":{"@zod/source":"src"}},"exports":{"./package.json":"./package.json",".":{"@zod/source":"./src/index.ts","types":"./index.d.cts","import":"./index.js","require":"./index.cjs"},"./mini":{"@zod/source":"./src/mini/index.ts","types":"./mini/index.d.cts","import":"./mini/index.js","require":"./mini/index.cjs"},"./locales":{"@zod/source":"./src/locales/index.ts","types":"./locales/index.d.cts","import":"./locales/index.js","require":"./locales/index.cjs"},"./v3":{"@zod/source":"./src/v3/index.ts","types":"./v3/index.d.cts","import":"./v3/index.js","require":"./v3/index.cjs"},"./v4":{"@zod/source":"./src/v4/index.ts","types":"./v4/index.d.cts","import":"./v4/index.js","require":"./v4/index.cjs"},"./v4-mini":{"@zod/source":"./src/v4-mini/index.ts","types":"./v4-mini/index.d.cts","import":"./v4-mini/index.js","require":"./v4-mini/index.cjs"},"./v4/mini":{"@zod/source":"./src/v4/mini/index.ts","types":"./v4/mini/index.d.cts","import":"./v4/mini/index.js","require":"./v4/mini/index.cjs"},"./v4/core":{"@zod/source":"./src/v4/core/index.ts","types":"./v4/core/index.d.cts","import":"./v4/core/index.js","require":"./v4/core/index.cjs"},"./v4/locales":{"@zod/source":"./src/v4/locales/index.ts","types":"./v4/locales/index.d.cts","import":"./v4/locales/index.js","require":"./v4/locales/index.cjs"},"./v4/locales/*":{"@zod/source":"./src/v4/locales/*","types":"./v4/locales/*","import":"./v4/locales/*","require":"./v4/locales/*"}},"repository":{"type":"git","url":"git+https://github.com/colinhacks/zod.git"},"bugs":{"url":"https://github.com/colinhacks/zod/issues"},"support":{"backing":{"npm-funding":true}},"scripts":{"clean":"git clean -xdf . -e node_modules","build":"zshy --project tsconfig.build.json","postbuild":"tsx ../../scripts/write-stub-package-jsons.ts && pnpm biome check --write .","test:watch":"pnpm vitest","test":"pnpm vitest run","prepublishOnly":"tsx ../../scripts/check-versions.ts"},"_lastModified":"2026-06-10T18:12:12.137Z"}
@@ -32,6 +32,7 @@ module.exports = __toCommonJS(data_sources_collections_exports);
32
32
  var import_database = require("@nocobase/database");
33
33
  var data_sources_collections_default = (0, import_database.defineCollection)({
34
34
  name: "dataSourcesCollections",
35
+ dataCategory: "system",
35
36
  model: "DataSourcesCollectionModel",
36
37
  dumpRules: "required",
37
38
  migrationRules: ["overwrite", "schema-only"],
@@ -32,6 +32,7 @@ module.exports = __toCommonJS(data_sources_fields_exports);
32
32
  var import_database = require("@nocobase/database");
33
33
  var data_sources_fields_default = (0, import_database.defineCollection)({
34
34
  name: "dataSourcesFields",
35
+ dataCategory: "system",
35
36
  model: "DataSourcesFieldModel",
36
37
  dumpRules: "required",
37
38
  migrationRules: ["overwrite", "schema-only"],
@@ -34,6 +34,7 @@ var data_sources_roles_resources_actions_default = (0, import_database.defineCol
34
34
  dumpRules: "required",
35
35
  migrationRules: ["overwrite", "schema-only"],
36
36
  name: "dataSourcesRolesResourcesActions",
37
+ dataCategory: "system",
37
38
  model: "DataSourcesRolesResourcesActionModel",
38
39
  fields: [
39
40
  {
@@ -34,6 +34,7 @@ var data_sources_roles_resources_scopes_default = (0, import_database.defineColl
34
34
  dumpRules: "required",
35
35
  migrationRules: ["overwrite", "schema-only"],
36
36
  name: "dataSourcesRolesResourcesScopes",
37
+ dataCategory: "system",
37
38
  fields: [
38
39
  {
39
40
  name: "id",
@@ -34,6 +34,7 @@ var data_sources_roles_resources_default = (0, import_database.defineCollection)
34
34
  dumpRules: "required",
35
35
  migrationRules: ["overwrite", "schema-only"],
36
36
  name: "dataSourcesRolesResources",
37
+ dataCategory: "system",
37
38
  model: "DataSourcesRolesResourcesModel",
38
39
  fields: [
39
40
  {
@@ -32,6 +32,7 @@ module.exports = __toCommonJS(data_sources_roles_exports);
32
32
  var import_database = require("@nocobase/database");
33
33
  var data_sources_roles_default = (0, import_database.defineCollection)({
34
34
  name: "dataSourcesRoles",
35
+ dataCategory: "system",
35
36
  dumpRules: "required",
36
37
  migrationRules: ["overwrite", "schema-only"],
37
38
  autoGenId: false,
@@ -32,6 +32,7 @@ module.exports = __toCommonJS(data_sources_exports);
32
32
  var import_database = require("@nocobase/database");
33
33
  var data_sources_default = (0, import_database.defineCollection)({
34
34
  name: "dataSources",
35
+ dataCategory: "system",
35
36
  model: "DataSourceModel",
36
37
  autoGenId: false,
37
38
  shared: true,
@@ -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 type { McpToolsManager } from '@nocobase/ai';
10
+ export declare function simplifyDataSourceListResult(result: any): {
11
+ data: any;
12
+ meta: any;
13
+ };
14
+ export declare function simplifyDataSourceCollectionsListResult(result: any): {
15
+ data: any;
16
+ meta: any;
17
+ };
18
+ export declare function simplifyDataSourceFieldsListResult(result: any, options?: {
19
+ args?: Record<string, any>;
20
+ }): {
21
+ data: any;
22
+ meta: any;
23
+ };
24
+ export declare function registerDataSourceManagerMcpPostProcessors(manager: McpToolsManager): void;
@@ -0,0 +1,158 @@
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 mcp_post_processors_exports = {};
28
+ __export(mcp_post_processors_exports, {
29
+ registerDataSourceManagerMcpPostProcessors: () => registerDataSourceManagerMcpPostProcessors,
30
+ simplifyDataSourceCollectionsListResult: () => simplifyDataSourceCollectionsListResult,
31
+ simplifyDataSourceFieldsListResult: () => simplifyDataSourceFieldsListResult,
32
+ simplifyDataSourceListResult: () => simplifyDataSourceListResult
33
+ });
34
+ module.exports = __toCommonJS(mcp_post_processors_exports);
35
+ function toArray(value) {
36
+ if (Array.isArray(value)) {
37
+ return value;
38
+ }
39
+ if (Array.isArray(value == null ? void 0 : value.data)) {
40
+ return value.data;
41
+ }
42
+ return [];
43
+ }
44
+ function parseAssociatedIndex(value) {
45
+ if (typeof value !== "string") {
46
+ return {};
47
+ }
48
+ const separatorIndex = value.indexOf(".");
49
+ if (separatorIndex === -1) {
50
+ return {};
51
+ }
52
+ return {
53
+ dataSourceKey: value.slice(0, separatorIndex),
54
+ collectionName: value.slice(separatorIndex + 1)
55
+ };
56
+ }
57
+ function pickDataSourceSummary(item) {
58
+ const summary = {
59
+ displayName: item == null ? void 0 : item.displayName,
60
+ key: item == null ? void 0 : item.key,
61
+ type: item == null ? void 0 : item.type,
62
+ status: item == null ? void 0 : item.status
63
+ };
64
+ if (Array.isArray(item == null ? void 0 : item.collections)) {
65
+ summary.collections = item.collections.map((collection) => {
66
+ const nextCollection = pickCollectionSummary({
67
+ ...collection,
68
+ dataSourceKey: (collection == null ? void 0 : collection.dataSourceKey) ?? (item == null ? void 0 : item.key)
69
+ });
70
+ if (Array.isArray(collection == null ? void 0 : collection.fields)) {
71
+ nextCollection.fields = collection.fields.map(
72
+ (field) => pickRemoteFieldSummary(field, {
73
+ dataSourceKey: (collection == null ? void 0 : collection.dataSourceKey) ?? (item == null ? void 0 : item.key),
74
+ collectionName: collection == null ? void 0 : collection.name
75
+ })
76
+ );
77
+ }
78
+ return nextCollection;
79
+ });
80
+ }
81
+ return summary;
82
+ }
83
+ function pickCollectionSummary(item) {
84
+ var _a, _b;
85
+ return {
86
+ name: item == null ? void 0 : item.name,
87
+ title: (item == null ? void 0 : item.title) ?? ((_a = item == null ? void 0 : item.options) == null ? void 0 : _a.title) ?? (item == null ? void 0 : item.displayName),
88
+ description: (item == null ? void 0 : item.description) ?? ((_b = item == null ? void 0 : item.options) == null ? void 0 : _b.description),
89
+ dataSourceKey: item == null ? void 0 : item.dataSourceKey
90
+ };
91
+ }
92
+ function pickFieldSummary(item) {
93
+ var _a;
94
+ return {
95
+ name: item == null ? void 0 : item.name,
96
+ type: item == null ? void 0 : item.type,
97
+ title: (_a = item == null ? void 0 : item.uiSchema) == null ? void 0 : _a.title,
98
+ description: item == null ? void 0 : item.description,
99
+ dataSourceKey: item == null ? void 0 : item.dataSourceKey,
100
+ collectionName: item == null ? void 0 : item.collectionName
101
+ };
102
+ }
103
+ function pickRemoteFieldSummary(item, defaults) {
104
+ var _a;
105
+ return {
106
+ name: item == null ? void 0 : item.name,
107
+ type: item == null ? void 0 : item.type,
108
+ title: (_a = item == null ? void 0 : item.uiSchema) == null ? void 0 : _a.title,
109
+ description: item == null ? void 0 : item.description,
110
+ dataSourceKey: item == null ? void 0 : item.dataSourceKey,
111
+ collectionName: item == null ? void 0 : item.collectionName,
112
+ ...defaults
113
+ };
114
+ }
115
+ function simplifyDataSourceListResult(result) {
116
+ const items = toArray(result);
117
+ return {
118
+ data: items.map((item) => pickDataSourceSummary(item)),
119
+ meta: result == null ? void 0 : result.meta
120
+ };
121
+ }
122
+ function simplifyDataSourceCollectionsListResult(result) {
123
+ const items = toArray(result);
124
+ return {
125
+ data: items.map((item) => pickCollectionSummary(item)),
126
+ meta: result == null ? void 0 : result.meta
127
+ };
128
+ }
129
+ function simplifyDataSourceFieldsListResult(result, options) {
130
+ var _a;
131
+ const items = toArray(result);
132
+ const defaults = parseAssociatedIndex((_a = options == null ? void 0 : options.args) == null ? void 0 : _a.associatedIndex);
133
+ return {
134
+ data: items.map(
135
+ (item) => (item == null ? void 0 : item.dataSourceKey) || (item == null ? void 0 : item.collectionName) ? pickFieldSummary(item) : pickRemoteFieldSummary(item, defaults)
136
+ ),
137
+ meta: result == null ? void 0 : result.meta
138
+ };
139
+ }
140
+ function registerDataSourceManagerMcpPostProcessors(manager) {
141
+ manager.registerToolResultPostProcessor("dataSources", "list", simplifyDataSourceListResult);
142
+ manager.registerToolResultPostProcessor("dataSources", "listEnabled", simplifyDataSourceListResult);
143
+ manager.registerToolResultPostProcessor("dataSources.collections", "list", simplifyDataSourceCollectionsListResult);
144
+ manager.registerToolResultPostProcessor(
145
+ "dataSourcesCollections.fields",
146
+ "list",
147
+ (result, context) => simplifyDataSourceFieldsListResult(result, {
148
+ args: context == null ? void 0 : context.args
149
+ })
150
+ );
151
+ }
152
+ // Annotate the CommonJS export names for ESM import in node:
153
+ 0 && (module.exports = {
154
+ registerDataSourceManagerMcpPostProcessors,
155
+ simplifyDataSourceCollectionsListResult,
156
+ simplifyDataSourceFieldsListResult,
157
+ simplifyDataSourceListResult
158
+ });
@@ -7,11 +7,9 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- var __create = Object.create;
11
10
  var __defProp = Object.defineProperty;
12
11
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
13
  var __hasOwnProp = Object.prototype.hasOwnProperty;
16
14
  var __export = (target, all) => {
17
15
  for (var name in all)
@@ -25,14 +23,6 @@ var __copyProps = (to, from, except, desc) => {
25
23
  }
26
24
  return to;
27
25
  };
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
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
27
  var data_source_exports = {};
38
28
  __export(data_source_exports, {
@@ -41,7 +31,7 @@ __export(data_source_exports, {
41
31
  module.exports = __toCommonJS(data_source_exports);
42
32
  var import_database = require("@nocobase/database");
43
33
  var import_plugin_acl = require("@nocobase/plugin-acl");
44
- var import_path = __toESM(require("path"));
34
+ var import_utils = require("@nocobase/utils");
45
35
  const availableActions = {
46
36
  create: {
47
37
  displayName: '{{t("Add new")}}',
@@ -62,7 +52,7 @@ const availableActions = {
62
52
  view: {
63
53
  displayName: '{{t("View")}}',
64
54
  type: "old-data",
65
- aliases: ["get", "list"],
55
+ aliases: ["get", "list", "query"],
66
56
  allowConfigureFields: true
67
57
  },
68
58
  update: {
@@ -117,7 +107,7 @@ class DataSourceModel extends import_database.Model {
117
107
  logger: app.logger.child({ dataSourceKey }),
118
108
  sqlLogger: app.sqlLogger.child({ dataSourceKey }),
119
109
  cache: app.cache,
120
- storagePath: import_path.default.join(process.cwd(), "storage", "cache", "apps", app.name),
110
+ storagePath: (0, import_utils.storagePathJoin)("cache", "apps", app.name),
121
111
  databaseInstance
122
112
  });
123
113
  dataSource.on("loadingProgress", (progress) => {
@@ -57,6 +57,7 @@ var import_data_source = require("./models/data-source");
57
57
  var import_data_sources_roles_model = require("./models/data-sources-roles-model");
58
58
  var import_acl = require("@nocobase/acl");
59
59
  var import_load_tables = require("./middlewares/load-tables");
60
+ var import_mcp_post_processors = require("./mcp-post-processors");
60
61
  class PluginDataSourceManagerServer extends import_server.Plugin {
61
62
  dataSourceErrors = {};
62
63
  dataSourceStatus = {};
@@ -260,15 +261,18 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
260
261
  const mapDataSourceWithCollection = (dataSourceModel, appendCollections = true) => {
261
262
  const dataSource = app.dataSourceManager.dataSources.get(dataSourceModel.get("key"));
262
263
  const dataSourceStatus = plugin.dataSourceStatus[dataSourceModel.get("key")];
264
+ const publicOptions = dataSource == null ? void 0 : dataSource.publicOptions();
265
+ const collectionManager = dataSource == null ? void 0 : dataSource.collectionManager;
266
+ const db = collectionManager == null ? void 0 : collectionManager.db;
267
+ const isDBInstance = (db == null ? void 0 : db.isDBInstance) === false ? false : !!db;
263
268
  const item = {
264
269
  key: dataSourceModel.get("key"),
265
270
  displayName: dataSourceModel.get("displayName"),
266
271
  status: dataSourceStatus,
267
272
  type: dataSourceModel.get("type"),
268
273
  // @ts-ignore
269
- isDBInstance: !!(dataSource == null ? void 0 : dataSource.collectionManager.db)
274
+ isDBInstance
270
275
  };
271
- const publicOptions = dataSource == null ? void 0 : dataSource.publicOptions();
272
276
  if (publicOptions) {
273
277
  item["options"] = publicOptions;
274
278
  }
@@ -313,6 +317,7 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
313
317
  await next();
314
318
  });
315
319
  this.app.resourceManager.use(import_load_tables.loadDataSourceTablesIntoCollections);
320
+ (0, import_mcp_post_processors.registerDataSourceManagerMcpPostProcessors)(this.ai.mcpToolsManager);
316
321
  this.app.use(async function handleAppendDataSourceCollection(ctx, next) {
317
322
  await next();
318
323
  if (!ctx.action) {
@@ -13,6 +13,7 @@ declare const _default: {
13
13
  get(ctx: any, next: any): Promise<void>;
14
14
  update(ctx: any, next: any): Promise<void>;
15
15
  create(ctx: any, next: any): Promise<void>;
16
+ apply(ctx: any, next: any): Promise<void>;
16
17
  destroy(ctx: any, next: any): Promise<void>;
17
18
  };
18
19
  };
@@ -40,6 +40,13 @@ __export(data_sources_collections_fields_exports, {
40
40
  });
41
41
  module.exports = __toCommonJS(data_sources_collections_fields_exports);
42
42
  var import_lodash = __toESM(require("lodash"));
43
+ var import_external_field_apply = require("../services/external-field-apply");
44
+ function ensureFieldConfigureEnabled(ctx, dataSourceKey) {
45
+ const dataSource = ctx.app.dataSourceManager.dataSources.get(dataSourceKey);
46
+ if (dataSource == null ? void 0 : dataSource.disableConfigureFields) {
47
+ ctx.throw(403, "Field configuration is disabled for this data source");
48
+ }
49
+ }
43
50
  var data_sources_collections_fields_default = {
44
51
  name: "dataSourcesCollections.fields",
45
52
  actions: {
@@ -67,6 +74,7 @@ var data_sources_collections_fields_default = {
67
74
  async update(ctx, next) {
68
75
  const { associatedIndex: collectionNameWithDataSourceKey, filterByTk: name, values } = ctx.action.params;
69
76
  const [dataSourceKey, collectionName] = collectionNameWithDataSourceKey.split(".");
77
+ ensureFieldConfigureEnabled(ctx, dataSourceKey);
70
78
  const mainDb = ctx.app.db;
71
79
  let fieldRecord = await mainDb.getRepository("dataSourcesFields").findOne({
72
80
  filter: {
@@ -104,6 +112,7 @@ var data_sources_collections_fields_default = {
104
112
  async create(ctx, next) {
105
113
  const { associatedIndex: collectionNameWithDataSourceKey, values } = ctx.action.params;
106
114
  const [dataSourceKey, collectionName] = collectionNameWithDataSourceKey.split(".");
115
+ ensureFieldConfigureEnabled(ctx, dataSourceKey);
107
116
  const mainDb = ctx.app.db;
108
117
  const name = values.name;
109
118
  if (await mainDb.getRepository("dataSourcesFields").findOne({
@@ -130,9 +139,19 @@ var data_sources_collections_fields_default = {
130
139
  ctx.body = fieldRecord.toJSON();
131
140
  await next();
132
141
  },
142
+ async apply(ctx, next) {
143
+ const rawValues = ctx.action.params.values || ctx.request.body || {};
144
+ const defaults = (0, import_external_field_apply.parseCollectionNameWithDataSourceKey)(ctx.action.params.associatedIndex);
145
+ ensureFieldConfigureEnabled(ctx, defaults.dataSourceKey);
146
+ ctx.body = {
147
+ data: await (0, import_external_field_apply.applyExternalFieldDefinition)(ctx, rawValues, defaults)
148
+ };
149
+ await next();
150
+ },
133
151
  async destroy(ctx, next) {
134
152
  const { associatedIndex: collectionNameWithDataSourceKey, filterByTk: name } = ctx.action.params;
135
153
  const [dataSourceKey, collectionName] = collectionNameWithDataSourceKey.split(".");
154
+ ensureFieldConfigureEnabled(ctx, dataSourceKey);
136
155
  const mainDb = ctx.app.db;
137
156
  const fieldRecord = await mainDb.getRepository("dataSourcesFields").findOne({
138
157
  filter: {
@@ -0,0 +1,23 @@
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
+ export declare function parseCollectionNameWithDataSourceKey(value?: string): {
10
+ dataSourceKey?: undefined;
11
+ collectionName?: undefined;
12
+ } | {
13
+ dataSourceKey: string;
14
+ collectionName: string;
15
+ };
16
+ export declare function normalizeExternalFieldInput(rawValues: any, defaults: {
17
+ dataSourceKey?: string;
18
+ collectionName?: string;
19
+ }): any;
20
+ export declare function applyExternalFieldDefinition(ctx: any, rawValues: any, defaults?: {
21
+ dataSourceKey?: string;
22
+ collectionName?: string;
23
+ }): Promise<any>;
@@ -0,0 +1,208 @@
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 external_field_apply_exports = {};
38
+ __export(external_field_apply_exports, {
39
+ applyExternalFieldDefinition: () => applyExternalFieldDefinition,
40
+ normalizeExternalFieldInput: () => normalizeExternalFieldInput,
41
+ parseCollectionNameWithDataSourceKey: () => parseCollectionNameWithDataSourceKey
42
+ });
43
+ module.exports = __toCommonJS(external_field_apply_exports);
44
+ var import_lodash = __toESM(require("lodash"));
45
+ var import_sequelize = require("sequelize");
46
+ const RELATION_INTERFACE_TYPE_MAP = {
47
+ m2o: "belongsTo",
48
+ obo: "belongsTo",
49
+ o2m: "hasMany",
50
+ oho: "hasOne",
51
+ m2m: "belongsToMany"
52
+ };
53
+ const RELATION_TYPES = /* @__PURE__ */ new Set(["belongsTo", "hasMany", "hasOne", "belongsToMany"]);
54
+ function parseCollectionNameWithDataSourceKey(value) {
55
+ if (!value) {
56
+ return {};
57
+ }
58
+ const separatorIndex = value.indexOf(".");
59
+ if (separatorIndex === -1) {
60
+ return {};
61
+ }
62
+ return {
63
+ dataSourceKey: value.slice(0, separatorIndex),
64
+ collectionName: value.slice(separatorIndex + 1)
65
+ };
66
+ }
67
+ function mergeSettings(input = {}) {
68
+ const { settings, ...rest } = input;
69
+ return {
70
+ ...settings || {},
71
+ ...rest
72
+ };
73
+ }
74
+ function buildRelationKeyName(name, key = "id") {
75
+ return import_sequelize.Utils.camelize([import_sequelize.Utils.singularize(name || ""), key].join("_"));
76
+ }
77
+ function buildThroughName(source, target) {
78
+ return import_sequelize.Utils.camelize(
79
+ [source, target].filter(Boolean).map((name) => String(name).toLowerCase()).sort().join("_")
80
+ );
81
+ }
82
+ function normalizeExternalFieldInput(rawValues, defaults) {
83
+ var _a;
84
+ const values = mergeSettings(rawValues);
85
+ const dataSourceKey = values.dataSourceKey || defaults.dataSourceKey;
86
+ const collectionName = values.collectionName || defaults.collectionName;
87
+ if (!dataSourceKey) {
88
+ throw new Error("dataSourcesCollections.fields:apply requires dataSourceKey");
89
+ }
90
+ if (!collectionName) {
91
+ throw new Error("dataSourcesCollections.fields:apply requires collectionName");
92
+ }
93
+ if (!values.name) {
94
+ throw new Error("dataSourcesCollections.fields:apply requires name");
95
+ }
96
+ const interfaceType = values.interface;
97
+ const type = values.type || RELATION_INTERFACE_TYPE_MAP[interfaceType];
98
+ const normalized = {
99
+ ...values,
100
+ dataSourceKey,
101
+ collectionName,
102
+ type
103
+ };
104
+ if (RELATION_TYPES.has(normalized.type)) {
105
+ if (!normalized.target) {
106
+ throw new Error(`Relation field ${normalized.name} requires target`);
107
+ }
108
+ normalized.interface = normalized.interface || {
109
+ belongsTo: "m2o",
110
+ hasMany: "o2m",
111
+ hasOne: "oho",
112
+ belongsToMany: "m2m"
113
+ }[normalized.type];
114
+ normalized.sourceKey = normalized.sourceKey || "id";
115
+ normalized.targetKey = normalized.targetKey || "id";
116
+ if (normalized.type === "belongsTo") {
117
+ normalized.foreignKey = normalized.foreignKey || buildRelationKeyName(normalized.name, normalized.targetKey);
118
+ }
119
+ if (normalized.type === "hasMany" || normalized.type === "hasOne") {
120
+ normalized.foreignKey = normalized.foreignKey || buildRelationKeyName(collectionName, normalized.sourceKey);
121
+ }
122
+ if (normalized.type === "belongsToMany") {
123
+ normalized.foreignKey = normalized.foreignKey || buildRelationKeyName(collectionName, normalized.sourceKey);
124
+ normalized.otherKey = normalized.otherKey || buildRelationKeyName(normalized.target, normalized.targetKey);
125
+ normalized.through = normalized.through || buildThroughName(collectionName, normalized.target);
126
+ }
127
+ normalized.uiSchema = import_lodash.default.merge(
128
+ {
129
+ type: normalized.type === "belongsTo" || normalized.type === "hasOne" ? "object" : "array",
130
+ title: normalized.title || ((_a = normalized.uiSchema) == null ? void 0 : _a.title) || normalized.name,
131
+ "x-component": "AssociationField",
132
+ "x-component-props": {
133
+ multiple: normalized.type === "hasMany" || normalized.type === "belongsToMany",
134
+ fieldNames: {
135
+ value: normalized.targetKey,
136
+ label: normalized.targetTitleField || normalized.titleField || normalized.targetKey
137
+ }
138
+ }
139
+ },
140
+ normalized.uiSchema || {}
141
+ );
142
+ }
143
+ delete normalized.settings;
144
+ delete normalized.title;
145
+ delete normalized.titleField;
146
+ delete normalized.targetTitleField;
147
+ return normalized;
148
+ }
149
+ function validateExternalRelationField(values) {
150
+ if (!RELATION_TYPES.has(values.type)) {
151
+ return;
152
+ }
153
+ const validatePresent = (name) => {
154
+ if (!values[name]) {
155
+ throw new Error(`"${name}" is required`);
156
+ }
157
+ };
158
+ const validatePresents = (names) => names.forEach((name) => validatePresent(name));
159
+ if (values.type === "belongsTo") {
160
+ validatePresents(["foreignKey", "targetKey", "target"]);
161
+ }
162
+ if (values.type === "hasMany" || values.type === "hasOne") {
163
+ validatePresents(["foreignKey", "sourceKey", "target"]);
164
+ }
165
+ if (values.type === "belongsToMany") {
166
+ validatePresents(["foreignKey", "otherKey", "sourceKey", "targetKey", "through", "target"]);
167
+ }
168
+ }
169
+ function getFieldOptions(ctx, values) {
170
+ var _a;
171
+ return (_a = ctx.app.dataSourceManager.dataSources.get(values.dataSourceKey).collectionManager.getCollection(values.collectionName).getField(values.name)) == null ? void 0 : _a.options;
172
+ }
173
+ async function applyExternalFieldDefinition(ctx, rawValues, defaults = {}) {
174
+ const values = normalizeExternalFieldInput(rawValues, defaults);
175
+ validateExternalRelationField(values);
176
+ const dataSource = ctx.app.dataSourceManager.dataSources.get(values.dataSourceKey);
177
+ if (!dataSource) {
178
+ throw new Error(`dataSource ${values.dataSourceKey} not found`);
179
+ }
180
+ const collection = dataSource.collectionManager.getCollection(values.collectionName);
181
+ if (!collection) {
182
+ throw new Error(`collection ${values.collectionName} not found in dataSource ${values.dataSourceKey}`);
183
+ }
184
+ const repository = ctx.app.db.getRepository("dataSourcesFields");
185
+ const filter = {
186
+ name: values.name,
187
+ collectionName: values.collectionName,
188
+ dataSourceKey: values.dataSourceKey
189
+ };
190
+ const existing = await repository.findOne({ filter });
191
+ if (existing) {
192
+ await repository.update({
193
+ filter,
194
+ values
195
+ });
196
+ } else {
197
+ await repository.create({
198
+ values
199
+ });
200
+ }
201
+ return getFieldOptions(ctx, values);
202
+ }
203
+ // Annotate the CommonJS export names for ESM import in node:
204
+ 0 && (module.exports = {
205
+ applyExternalFieldDefinition,
206
+ normalizeExternalFieldInput,
207
+ parseCollectionNameWithDataSourceKey
208
+ });