@tachybase/plugin-data-source-common 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 (126) 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/features/rest-api/collection-add/AddCollection.d.ts +2 -0
  7. package/dist/client/features/rest-api/collection-add/AddCollectionAction.component.d.ts +2 -0
  8. package/dist/client/features/rest-api/collection-add/CreateCollection.schema.d.ts +389 -0
  9. package/dist/client/features/rest-api/collection-add/CreateCollection.view.d.ts +2 -0
  10. package/dist/client/features/rest-api/collection-add/PreviewComponent.d.ts +2 -0
  11. package/dist/client/features/rest-api/collection-add/PreviewFields.d.ts +5 -0
  12. package/dist/client/features/rest-api/collection-add/RequestActionItems.provider.d.ts +2 -0
  13. package/dist/client/features/rest-api/collection-add/getSchemaRequestAction.d.ts +57 -0
  14. package/dist/client/features/rest-api/collection-add/useActionCreateCollection.d.ts +3 -0
  15. package/dist/client/features/rest-api/collection-delete/DeleteCollection.d.ts +2 -0
  16. package/dist/client/features/rest-api/collection-delete/DeleteCollectionAction.component.d.ts +5 -0
  17. package/dist/client/features/rest-api/collection-delete/useBulkDestroyActionAndRefreshCM.d.ts +3 -0
  18. package/dist/client/features/rest-api/collection-delete/useDestroyActionAndRefreshCM.d.ts +3 -0
  19. package/dist/client/features/rest-api/collection-edit/EditCollection.d.ts +2 -0
  20. package/dist/client/features/rest-api/collection-edit/EditCollectionAction.component.d.ts +2 -0
  21. package/dist/client/features/rest-api/collection-edit/EditCollectionForm.view.d.ts +2 -0
  22. package/dist/client/features/rest-api/collection-edit/useActionEditCollection.d.ts +3 -0
  23. package/dist/client/features/rest-api/constants/mapListve.d.ts +7 -0
  24. package/dist/client/features/rest-api/constants/requestHeaderList.d.ts +4 -0
  25. package/dist/client/features/rest-api/contexts/RequestForm.context.d.ts +11 -0
  26. package/dist/client/features/rest-api/contexts/ResponseInfo.context.d.ts +12 -0
  27. package/dist/client/features/rest-api/form-data-source/DataSourceSettingsForm.d.ts +2 -0
  28. package/dist/client/features/rest-api/form-data-source/DataSourceSettingsForm.schema.d.ts +172 -0
  29. package/dist/client/features/rest-api/kit.d.ts +4 -0
  30. package/dist/client/features/rest-api/request-configs/debug-area/Debug.provider.d.ts +2 -0
  31. package/dist/client/features/rest-api/request-configs/debug-area/Debug.schema.d.ts +164 -0
  32. package/dist/client/features/rest-api/request-configs/debug-area/Debug.view.d.ts +2 -0
  33. package/dist/client/features/rest-api/request-configs/debug-area/DebugComponent.d.ts +2 -0
  34. package/dist/client/features/rest-api/request-configs/debug-area/components/AlertError.d.ts +2 -0
  35. package/dist/client/features/rest-api/request-configs/debug-area/components/DebugResponse.schema.d.ts +21 -0
  36. package/dist/client/features/rest-api/request-configs/debug-area/components/DebugResponse.view.d.ts +2 -0
  37. package/dist/client/features/rest-api/request-configs/debug-area/components/DebugResponseTabs.d.ts +2 -0
  38. package/dist/client/features/rest-api/request-configs/debug-area/components/DebugResponseTabs.items.d.ts +6 -0
  39. package/dist/client/features/rest-api/request-configs/debug-area/components/ExtractFieldMetadata.d.ts +2 -0
  40. package/dist/client/features/rest-api/request-configs/debug-area/components/Headers.schema.d.ts +60 -0
  41. package/dist/client/features/rest-api/request-configs/debug-area/components/RequestHeaders.view.d.ts +2 -0
  42. package/dist/client/features/rest-api/request-configs/debug-area/components/ResponseBody.schema.d.ts +21 -0
  43. package/dist/client/features/rest-api/request-configs/debug-area/components/ResponseBody.view.d.ts +2 -0
  44. package/dist/client/features/rest-api/request-configs/debug-area/components/ResponseHeaders.view.d.ts +2 -0
  45. package/dist/client/features/rest-api/request-configs/debug-area/components/ResponseTab.d.ts +2 -0
  46. package/dist/client/features/rest-api/request-configs/debug-area/components/ResponseTab.item.d.ts +6 -0
  47. package/dist/client/features/rest-api/request-configs/debug-area/components/TooltipContainer.d.ts +2 -0
  48. package/dist/client/features/rest-api/request-configs/debug-area/schemas/getSchemaAction.d.ts +88 -0
  49. package/dist/client/features/rest-api/request-configs/debug-area/schemas/getSchemaParam.d.ts +1 -0
  50. package/dist/client/features/rest-api/request-configs/debug-area/scopes/useCancelAction.d.ts +3 -0
  51. package/dist/client/features/rest-api/request-configs/debug-area/scopes/useDebugAction.d.ts +3 -0
  52. package/dist/client/features/rest-api/request-configs/method-path/FieldMethod.schema.d.ts +23 -0
  53. package/dist/client/features/rest-api/request-configs/method-path/FieldMethod.view.d.ts +2 -0
  54. package/dist/client/features/rest-api/request-configs/method-path/FieldPath.schema.d.ts +35 -0
  55. package/dist/client/features/rest-api/request-configs/method-path/FieldPath.view.d.ts +2 -0
  56. package/dist/client/features/rest-api/request-configs/method-path/MethodPathComponent.d.ts +2 -0
  57. package/dist/client/features/rest-api/request-configs/request-tab/RequestBody.schema.d.ts +124 -0
  58. package/dist/client/features/rest-api/request-configs/request-tab/RequestBody.view.d.ts +2 -0
  59. package/dist/client/features/rest-api/request-configs/request-tab/RequestHeaders.schema.d.ts +77 -0
  60. package/dist/client/features/rest-api/request-configs/request-tab/RequestHeaders.view.d.ts +2 -0
  61. package/dist/client/features/rest-api/request-configs/request-tab/RequestParams.schema.d.ts +81 -0
  62. package/dist/client/features/rest-api/request-configs/request-tab/RequestParams.view.d.ts +2 -0
  63. package/dist/client/features/rest-api/request-configs/request-tab/RequestTab.d.ts +2 -0
  64. package/dist/client/features/rest-api/request-configs/request-tab/RequestTab.items.d.ts +6 -0
  65. package/dist/client/features/rest-api/request-configs/request-tab/debounceClick.util.d.ts +2 -0
  66. package/dist/client/features/rest-api/request-configs/request-transformer/ResponseTransformerComponent.d.ts +2 -0
  67. package/dist/client/features/rest-api/scopes/useVariableOptions.d.ts +1 -0
  68. package/dist/client/features/rest-api/utils/filterObjectWithMethodAndPath.d.ts +1 -0
  69. package/dist/client/features/rest-api/utils/filterTree.d.ts +1 -0
  70. package/dist/client/features/rest-api/utils/getRequestActions.d.ts +1 -0
  71. package/dist/client/features/rest-api/utils/getRequestValues.d.ts +1 -0
  72. package/dist/client/features/rest-api/utils/responseTransformerAe.d.ts +4 -0
  73. package/dist/client/features/rest-api/utils/setFormValue.d.ts +1 -0
  74. package/dist/client/forms/msql.d.ts +2 -0
  75. package/dist/client/forms/pg.d.ts +2 -0
  76. package/dist/client/index.d.ts +6 -0
  77. package/dist/client/index.js +86 -0
  78. package/dist/client/locale.d.ts +4 -0
  79. package/dist/externalVersion.js +16 -0
  80. package/dist/index.d.ts +2 -0
  81. package/dist/index.js +39 -0
  82. package/dist/locale/en-US.json +32 -0
  83. package/dist/locale/zh-CN.json +32 -0
  84. package/dist/server/http/plugin.d.ts +10 -0
  85. package/dist/server/http/plugin.js +78 -0
  86. package/dist/server/http/services/http-api-repository.d.ts +18 -0
  87. package/dist/server/http/services/http-api-repository.js +125 -0
  88. package/dist/server/http/services/http-collection-manager.d.ts +6 -0
  89. package/dist/server/http/services/http-collection-manager.js +36 -0
  90. package/dist/server/http/services/http-collection.d.ts +7 -0
  91. package/dist/server/http/services/http-collection.js +270 -0
  92. package/dist/server/http/services/http-data-source.d.ts +10 -0
  93. package/dist/server/http/services/http-data-source.js +67 -0
  94. package/dist/server/http/services/http-request-builder.d.ts +3 -0
  95. package/dist/server/http/services/http-request-builder.js +30 -0
  96. package/dist/server/http/services/transform-response.d.ts +1 -0
  97. package/dist/server/http/services/transform-response.js +185 -0
  98. package/dist/server/http/services/type-interface-map.d.ts +182 -0
  99. package/dist/server/http/services/type-interface-map.js +246 -0
  100. package/dist/server/http/services/utils.d.ts +2 -0
  101. package/dist/server/http/services/utils.js +49 -0
  102. package/dist/server/index.d.ts +1 -0
  103. package/dist/server/index.js +33 -0
  104. package/dist/server/mysql/database-introspector.d.ts +27 -0
  105. package/dist/server/mysql/database-introspector.js +254 -0
  106. package/dist/server/mysql/mysql-collection-manager.d.ts +3 -0
  107. package/dist/server/mysql/mysql-collection-manager.js +29 -0
  108. package/dist/server/mysql/mysql-data-source.d.ts +7 -0
  109. package/dist/server/mysql/mysql-data-source.js +111 -0
  110. package/dist/server/mysql/type-interface-map.d.ts +193 -0
  111. package/dist/server/mysql/type-interface-map.js +257 -0
  112. package/dist/server/pg/database-introspector.d.ts +54 -0
  113. package/dist/server/pg/database-introspector.js +286 -0
  114. package/dist/server/pg/postgres-collection-manager.d.ts +3 -0
  115. package/dist/server/pg/postgres-collection-manager.js +29 -0
  116. package/dist/server/pg/postgres-data-source.d.ts +8 -0
  117. package/dist/server/pg/postgres-data-source.js +127 -0
  118. package/dist/server/pg/type-interface-map.d.ts +183 -0
  119. package/dist/server/pg/type-interface-map.js +243 -0
  120. package/dist/server/pg/utils.d.ts +1 -0
  121. package/dist/server/pg/utils.js +48 -0
  122. package/dist/server/plugin.d.ts +13 -0
  123. package/dist/server/plugin.js +60 -0
  124. package/package.json +32 -0
  125. package/server.d.ts +2 -0
  126. package/server.js +1 -0
@@ -0,0 +1,254 @@
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 database_introspector_exports = {};
29
+ __export(database_introspector_exports, {
30
+ DatabaseIntrospector: () => DatabaseIntrospector
31
+ });
32
+ module.exports = __toCommonJS(database_introspector_exports);
33
+ var import_events = require("events");
34
+ var import_database = require("@tachybase/database");
35
+ var import_module_data_source = require("@tachybase/module-data-source");
36
+ var import_lodash = __toESM(require("lodash"));
37
+ class DatabaseIntrospector extends import_events.EventEmitter {
38
+ db;
39
+ typeInterfaceMap;
40
+ constructor(options) {
41
+ super();
42
+ this.db = options.db;
43
+ this.typeInterfaceMap = options.typeInterfaceMap;
44
+ }
45
+ async getCollections(options = {}) {
46
+ let tableList = await this.db.sequelize.getQueryInterface().showAllTables();
47
+ const views = (await this.db.queryInterface.listViews()).map((view) => view.name);
48
+ tableList = tableList.concat(views);
49
+ if (this.db.options.tablePrefix) {
50
+ tableList = tableList.filter((tableName) => {
51
+ return tableName.startsWith(this.db.options.tablePrefix);
52
+ });
53
+ }
54
+ const batchSize = 5;
55
+ const results = [];
56
+ for (let i = 0; i < tableList.length; i += batchSize) {
57
+ const batch = tableList.slice(i, i + batchSize);
58
+ const batchResults = await Promise.all(
59
+ batch.map(async (tableName) => {
60
+ var _a;
61
+ const tableInfo = {
62
+ tableName
63
+ };
64
+ this.emit("loadMessage", {
65
+ message: `load table ${tableName}`
66
+ });
67
+ const collectionOptions = this.tableInfoToCollectionOptions(tableInfo);
68
+ const localOptions = (_a = options.localData) == null ? void 0 : _a[collectionOptions.name];
69
+ try {
70
+ return await this.getCollection({
71
+ tableInfo,
72
+ localOptions,
73
+ mergedOptions: views.includes(tableName) ? { view: true, template: "view" } : {}
74
+ });
75
+ } catch (e) {
76
+ if (e.message.includes("No description found for")) {
77
+ return false;
78
+ }
79
+ throw e;
80
+ }
81
+ })
82
+ );
83
+ results.push(...batchResults);
84
+ }
85
+ return results.filter(Boolean);
86
+ }
87
+ async getCollection(options) {
88
+ const { tableInfo } = options;
89
+ const columnsInfo = await this.db.sequelize.getQueryInterface().describeTable(tableInfo);
90
+ const collectionOptions = this.tableInfoToCollectionOptions(tableInfo);
91
+ const constraints = await this.db.sequelize.getQueryInterface().showIndex(this.db.inDialect("postgres") ? tableInfo : tableInfo.tableName);
92
+ try {
93
+ const fields = Object.keys(columnsInfo).map((columnName) => {
94
+ return this.columnInfoToFieldOptions(columnsInfo, columnName, constraints);
95
+ });
96
+ const unsupportedFields = fields.filter((field) => {
97
+ return field.supported === false;
98
+ });
99
+ const supportFields = fields.filter((field) => {
100
+ return field.supported !== false;
101
+ });
102
+ const remoteCollectionInfo = {
103
+ ...collectionOptions,
104
+ ...(options == null ? void 0 : options.mergedOptions) || {},
105
+ ...this.collectionOptionsByFields(supportFields),
106
+ fields: supportFields
107
+ };
108
+ if (unsupportedFields.length) {
109
+ remoteCollectionInfo.unsupportedFields = unsupportedFields;
110
+ }
111
+ const finalOptions = this.mergeLocalDataIntoCollectionOptions(remoteCollectionInfo, options.localOptions);
112
+ if (finalOptions.view && !finalOptions.filterTargetKey && supportFields.find((field) => field.name === "id")) {
113
+ finalOptions.filterTargetKey = "id";
114
+ }
115
+ return finalOptions;
116
+ } catch (e) {
117
+ throw new Error(`table ${tableInfo.tableName} introspection error: ${e.message}`);
118
+ }
119
+ }
120
+ loadCollection(options) {
121
+ this.db.collection({
122
+ ...options,
123
+ introspected: true
124
+ });
125
+ }
126
+ loadCollections(options) {
127
+ options.collections.forEach((collection) => {
128
+ this.loadCollection(collection);
129
+ });
130
+ }
131
+ tableInfoToCollectionOptions(tableInfo) {
132
+ const tableName = tableInfo.tableName;
133
+ let name = tableName;
134
+ if (this.db.options.tablePrefix) {
135
+ name = tableName.replace(this.db.options.tablePrefix, "");
136
+ }
137
+ return {
138
+ name,
139
+ title: name,
140
+ schema: tableInfo.schema,
141
+ tableName
142
+ };
143
+ }
144
+ collectionOptionsByFields(fields) {
145
+ const options = {
146
+ timestamps: false,
147
+ autoGenId: false
148
+ };
149
+ const autoIncrementField = fields.find((field) => field.autoIncrement);
150
+ if (autoIncrementField) {
151
+ options.filterTargetKey = autoIncrementField.name;
152
+ }
153
+ const primaryKeys = fields.filter((field) => field.primaryKey);
154
+ if (!options.filterTargetKey && primaryKeys.length === 1) {
155
+ options.filterTargetKey = primaryKeys[0].name;
156
+ }
157
+ const uniques = fields.filter((field) => field.unique);
158
+ if (!options.filterTargetKey && uniques.length === 1) {
159
+ options.filterTargetKey = uniques[0].name;
160
+ }
161
+ return options;
162
+ }
163
+ mergeLocalDataIntoCollectionOptions(collectionOptions, localData) {
164
+ var _a;
165
+ if (!localData) {
166
+ return collectionOptions;
167
+ }
168
+ const collectionFields = collectionOptions.fields || [];
169
+ const localFieldsAsObject = import_lodash.default.keyBy(localData.fields, "name");
170
+ const newFields = collectionFields.map((field) => {
171
+ const localField = localFieldsAsObject[field.name];
172
+ if (!localField) {
173
+ return field;
174
+ }
175
+ return (0, import_module_data_source.mergeOptions)(field, localField);
176
+ });
177
+ const localAssociationFields = (_a = localData.fields) == null ? void 0 : _a.filter((field) => {
178
+ return ["belongsTo", "belongsToMany", "hasMany", "hasOne"].includes(field.type);
179
+ });
180
+ if (localAssociationFields) {
181
+ newFields.push(...localAssociationFields);
182
+ }
183
+ return {
184
+ ...collectionOptions,
185
+ ...import_lodash.default.omit(localData, ["fields"]),
186
+ fields: newFields
187
+ };
188
+ }
189
+ columnInfoToFieldOptions(columnsInfo, columnName, indexes) {
190
+ const columnInfo = columnsInfo[columnName];
191
+ let fieldOptions = {
192
+ ...this.columnAttribute(columnsInfo, columnName, indexes),
193
+ ...import_database.ViewFieldInference.inferToFieldType({
194
+ dialect: this.db.options.dialect,
195
+ type: columnInfo.type,
196
+ name: columnName
197
+ }),
198
+ rawType: columnInfo.type,
199
+ name: columnName
200
+ };
201
+ if (!fieldOptions.type) {
202
+ return {
203
+ rawType: columnInfo.type,
204
+ name: columnName,
205
+ supported: false
206
+ };
207
+ }
208
+ const interfaceConfig = this.getDefaultInterfaceByType(columnsInfo, columnName, fieldOptions.type);
209
+ if (typeof interfaceConfig === "string") {
210
+ fieldOptions.interface = interfaceConfig;
211
+ } else {
212
+ fieldOptions = {
213
+ ...fieldOptions,
214
+ ...interfaceConfig
215
+ };
216
+ }
217
+ import_lodash.default.set(fieldOptions, "uiSchema.title", columnName);
218
+ return fieldOptions;
219
+ }
220
+ getDefaultInterfaceByType(columnsInfo, columnName, type) {
221
+ const interfaceConfig = this.typeInterfaceMap[type];
222
+ if (typeof interfaceConfig === "function") {
223
+ return interfaceConfig(columnsInfo[columnName]);
224
+ }
225
+ return interfaceConfig;
226
+ }
227
+ columnAttribute(columnsInfo, columnName, indexes) {
228
+ const columnInfo = columnsInfo[columnName];
229
+ const attr = {
230
+ type: columnInfo.type,
231
+ allowNull: columnInfo.allowNull,
232
+ primaryKey: columnInfo.primaryKey,
233
+ unique: false,
234
+ autoIncrement: columnInfo.autoIncrement
235
+ };
236
+ if (columnInfo.defaultValue && typeof columnInfo.defaultValue === "string") {
237
+ const isSerial = columnInfo.defaultValue.match(/^nextval\(/);
238
+ const isUUID = columnInfo.defaultValue.match(/^uuid_generate_v4\(/);
239
+ if (isSerial || isUUID) {
240
+ attr.autoIncrement = true;
241
+ }
242
+ }
243
+ for (const index of indexes) {
244
+ if (index.fields.length === 1 && index.fields[0].attribute === columnName && index.unique) {
245
+ attr.unique = true;
246
+ }
247
+ }
248
+ return attr;
249
+ }
250
+ }
251
+ // Annotate the CommonJS export names for ESM import in node:
252
+ 0 && (module.exports = {
253
+ DatabaseIntrospector
254
+ });
@@ -0,0 +1,3 @@
1
+ import { SequelizeCollectionManager } from '@tachybase/data-source';
2
+ export declare class MySQLCollectionManager extends SequelizeCollectionManager {
3
+ }
@@ -0,0 +1,29 @@
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 mysql_collection_manager_exports = {};
19
+ __export(mysql_collection_manager_exports, {
20
+ MySQLCollectionManager: () => MySQLCollectionManager
21
+ });
22
+ module.exports = __toCommonJS(mysql_collection_manager_exports);
23
+ var import_data_source = require("@tachybase/data-source");
24
+ class MySQLCollectionManager extends import_data_source.SequelizeCollectionManager {
25
+ }
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ MySQLCollectionManager
29
+ });
@@ -0,0 +1,7 @@
1
+ import { DataSource } from '@tachybase/data-source';
2
+ import { MySQLCollectionManager } from './mysql-collection-manager';
3
+ export declare class MySQLDataSource extends DataSource {
4
+ static testConnection(options: any): Promise<boolean>;
5
+ load(options: any): Promise<void>;
6
+ createCollectionManager(options: any): MySQLCollectionManager;
7
+ }
@@ -0,0 +1,111 @@
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 mysql_data_source_exports = {};
29
+ __export(mysql_data_source_exports, {
30
+ MySQLDataSource: () => MySQLDataSource
31
+ });
32
+ module.exports = __toCommonJS(mysql_data_source_exports);
33
+ var import_data_source = require("@tachybase/data-source");
34
+ var import_database = require("@tachybase/database");
35
+ var import_database_introspector = require("./database-introspector");
36
+ var import_mysql_collection_manager = require("./mysql-collection-manager");
37
+ var import_type_interface_map = __toESM(require("./type-interface-map"));
38
+ class MySQLDataSource extends import_data_source.DataSource {
39
+ static async testConnection(options) {
40
+ const database = new import_database.Database({
41
+ dialect: "mysql",
42
+ ...options
43
+ });
44
+ try {
45
+ await database.sequelize.authenticate();
46
+ } catch (e) {
47
+ throw e;
48
+ } finally {
49
+ await database.close();
50
+ }
51
+ return true;
52
+ }
53
+ async load(options) {
54
+ const db = this.collectionManager.db;
55
+ const introspector = new import_database_introspector.DatabaseIntrospector({
56
+ db,
57
+ typeInterfaceMap: import_type_interface_map.default
58
+ });
59
+ introspector.on("loadMessage", ({ message }) => {
60
+ this.emit("loadMessage", { message });
61
+ });
62
+ const { localData } = options;
63
+ const collections = await introspector.getCollections({
64
+ localData
65
+ });
66
+ const delayFields = /* @__PURE__ */ new Map();
67
+ for (const collection of collections) {
68
+ try {
69
+ const fields = collection.fields;
70
+ for (const field of fields) {
71
+ if (field.type === "belongsToMany") {
72
+ if (!delayFields.has(collection.name)) {
73
+ delayFields.set(collection.name, []);
74
+ }
75
+ delayFields.get(collection.name).push(field);
76
+ }
77
+ }
78
+ this.collectionManager.defineCollection({
79
+ ...collection,
80
+ fields: fields.filter((field) => field.type !== "belongsToMany"),
81
+ introspected: true
82
+ });
83
+ } catch (e) {
84
+ db.logger.error(`load collection failed, ${e}`);
85
+ delayFields.delete(collection.name);
86
+ }
87
+ }
88
+ for (const [name, fields] of delayFields.entries()) {
89
+ try {
90
+ for (const field of fields) {
91
+ this.collectionManager.getCollection(name).setField(field.name, field);
92
+ }
93
+ } catch (e) {
94
+ db.logger.error(`load belongs to many field failed, ${e}`);
95
+ }
96
+ }
97
+ }
98
+ createCollectionManager(options) {
99
+ const database = new import_database.Database({
100
+ dialect: "mysql",
101
+ ...options
102
+ });
103
+ return new import_mysql_collection_manager.MySQLCollectionManager({
104
+ database
105
+ });
106
+ }
107
+ }
108
+ // Annotate the CommonJS export names for ESM import in node:
109
+ 0 && (module.exports = {
110
+ MySQLDataSource
111
+ });
@@ -0,0 +1,193 @@
1
+ declare const typeInterfaceMap: {
2
+ array: string;
3
+ belongsTo: string;
4
+ belongsToMany: string;
5
+ boolean: () => {
6
+ interface: string;
7
+ uiSchema: {
8
+ type: string;
9
+ 'x-component': string;
10
+ };
11
+ };
12
+ context: string;
13
+ date: () => {
14
+ interface: string;
15
+ uiSchema: {
16
+ 'x-component': string;
17
+ 'x-component-props': {
18
+ dateFormat: string;
19
+ showTime: boolean;
20
+ };
21
+ };
22
+ };
23
+ hasMany: string;
24
+ hasOne: string;
25
+ json: () => {
26
+ interface: string;
27
+ uiSchema: {
28
+ 'x-component': string;
29
+ 'x-component-props': {
30
+ autoSize: {
31
+ minRows: number;
32
+ };
33
+ };
34
+ default: any;
35
+ };
36
+ };
37
+ jsonb: () => {
38
+ interface: string;
39
+ uiSchema: {
40
+ 'x-component': string;
41
+ 'x-component-props': {
42
+ autoSize: {
43
+ minRows: number;
44
+ };
45
+ };
46
+ default: any;
47
+ };
48
+ };
49
+ integer: () => {
50
+ interface: string;
51
+ uiSchema: {
52
+ type: string;
53
+ 'x-component': string;
54
+ 'x-component-props': {
55
+ stringMode: boolean;
56
+ step: string;
57
+ };
58
+ 'x-validator': string;
59
+ };
60
+ };
61
+ bigInt: (columnInfo: any) => {
62
+ interface: string;
63
+ uiSchema: {
64
+ 'x-component': string;
65
+ 'x-component-props': {
66
+ style: {
67
+ width: string;
68
+ };
69
+ };
70
+ };
71
+ };
72
+ float: () => {
73
+ interface: string;
74
+ uiSchema: {
75
+ type: string;
76
+ 'x-component': string;
77
+ 'x-component-props': {
78
+ stringMode: boolean;
79
+ step: string;
80
+ };
81
+ };
82
+ };
83
+ double: () => {
84
+ interface: string;
85
+ uiSchema: {
86
+ type: string;
87
+ 'x-component': string;
88
+ 'x-component-props': {
89
+ stringMode: boolean;
90
+ step: string;
91
+ };
92
+ };
93
+ };
94
+ real: () => {
95
+ interface: string;
96
+ uiSchema: {
97
+ type: string;
98
+ 'x-component': string;
99
+ 'x-component-props': {
100
+ stringMode: boolean;
101
+ step: string;
102
+ };
103
+ };
104
+ };
105
+ decimal: () => {
106
+ interface: string;
107
+ uiSchema: {
108
+ type: string;
109
+ 'x-component': string;
110
+ 'x-component-props': {
111
+ stringMode: boolean;
112
+ step: string;
113
+ };
114
+ };
115
+ };
116
+ password: () => {
117
+ interface: string;
118
+ hidden: boolean;
119
+ uiSchema: {
120
+ type: string;
121
+ 'x-component': string;
122
+ };
123
+ };
124
+ radio: string;
125
+ set: string;
126
+ sort: string;
127
+ string: (columnInfo: any) => {
128
+ interface: string;
129
+ uiSchema: {
130
+ type: string;
131
+ 'x-component': string;
132
+ enum: any;
133
+ 'x-component-props'?: undefined;
134
+ };
135
+ } | {
136
+ interface: string;
137
+ uiSchema: {
138
+ 'x-component': string;
139
+ 'x-component-props': {
140
+ style: {
141
+ width: string;
142
+ };
143
+ };
144
+ type?: undefined;
145
+ enum?: undefined;
146
+ };
147
+ };
148
+ text: () => {
149
+ interface: string;
150
+ uiSchema: {
151
+ type: string;
152
+ 'x-component': string;
153
+ };
154
+ };
155
+ time: () => {
156
+ interface: string;
157
+ uiSchema: {
158
+ type: string;
159
+ 'x-component': string;
160
+ 'x-component-props': {
161
+ format: string;
162
+ };
163
+ };
164
+ };
165
+ uid: () => {
166
+ interface: string;
167
+ uiSchema: {
168
+ 'x-component': string;
169
+ 'x-component-props': {
170
+ style: {
171
+ width: string;
172
+ };
173
+ };
174
+ };
175
+ };
176
+ uuid: () => {
177
+ interface: string;
178
+ uiSchema: {
179
+ 'x-component': string;
180
+ 'x-component-props': {
181
+ style: {
182
+ width: string;
183
+ };
184
+ };
185
+ };
186
+ };
187
+ virtual: string;
188
+ point: string;
189
+ polygon: string;
190
+ lineString: string;
191
+ circle: string;
192
+ };
193
+ export default typeInterfaceMap;