@nocobase/plugin-data-source-main 2.0.0-alpha.21 → 2.0.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +8 -7
- package/dist/server/constants.d.ts +9 -0
- package/dist/server/constants.js +36 -0
- package/dist/server/models/collection.js +3 -0
- package/dist/server/resourcers/main-data-source.d.ts +17 -0
- package/dist/server/resourcers/main-data-source.js +52 -0
- package/dist/server/server.js +28 -5
- package/package.json +2 -2
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("lodash"),require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-data-source-main",["lodash","@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-data-source-main"]=t(require("lodash"),require("@nocobase/client")):e["@nocobase/plugin-data-source-main"]=t(e.lodash,e["@nocobase/client"])}(self,function(e,t){return function(){"use strict";var r={772:function(e){e.exports=t},467:function(t){t.exports=e}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return r[e](i,i.exports,o),i.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return!function(){o.r(i);var e=o(772),t=o(467);function r(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){r(e);return}c.done?t(u):Promise.resolve(u).then(n,o)}function n(e,t,r){return(n=l()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&c(o,r.prototype),o}).apply(null,arguments)}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){var t="function"==typeof Map?new Map:void 0;return(u=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return n(e,arguments,a(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,e)})(e)}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}i.default=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function o(){var e,t,r,n,i;if(!(this instanceof o))throw TypeError("Cannot call a class as a function");return t=o,r=arguments,t=a(t),e=function(e,t){var r;if(t&&("object"==((r=t)&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,l()?Reflect.construct(t,r||[],a(this).constructor):t.apply(this,r)),i=[],(n="collectionPresetFields")in e?Object.defineProperty(e,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[n]=i,e}return o.prototype=Object.create(e&&e.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),e&&c(o,e),n=[{key:"addCollectionPresetField",value:function(e){this.collectionPresetFields.push(e)}},{key:"removeCollectionPresetField",value:function(e){this.collectionPresetFields=(0,t.reject)(this.collectionPresetFields,function(t){return t.value.name===e})}},{key:"getCollectionPresetFields",value:function(){return(0,t.orderBy)(this.collectionPresetFields,["order"],["asc"])}},{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){var u=[i,c];if(r)throw TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,n=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(e){return t.addCollectionPresetField({order:100,description:'{{t("Primary key, unique identifier, self growth") }}',value:{name:"id",type:"bigInt",autoIncrement:!0,primaryKey:!0,allowNull:!1,uiSchema:{type:"number",title:'{{t("ID")}}',"x-component":"InputNumber","x-read-pretty":!0},interface:"
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("lodash"),require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-data-source-main",["lodash","@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-data-source-main"]=t(require("lodash"),require("@nocobase/client")):e["@nocobase/plugin-data-source-main"]=t(e.lodash,e["@nocobase/client"])}(self,function(e,t){return function(){"use strict";var r={772:function(e){e.exports=t},467:function(t){t.exports=e}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return r[e](i,i.exports,o),i.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return!function(){o.r(i);var e=o(772),t=o(467);function r(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){r(e);return}c.done?t(u):Promise.resolve(u).then(n,o)}function n(e,t,r){return(n=l()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&c(o,r.prototype),o}).apply(null,arguments)}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){var t="function"==typeof Map?new Map:void 0;return(u=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return n(e,arguments,a(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,e)})(e)}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}i.default=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function o(){var e,t,r,n,i;if(!(this instanceof o))throw TypeError("Cannot call a class as a function");return t=o,r=arguments,t=a(t),e=function(e,t){var r;if(t&&("object"==((r=t)&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,l()?Reflect.construct(t,r||[],a(this).constructor):t.apply(this,r)),i=[],(n="collectionPresetFields")in e?Object.defineProperty(e,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[n]=i,e}return o.prototype=Object.create(e&&e.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),e&&c(o,e),n=[{key:"addCollectionPresetField",value:function(e){this.collectionPresetFields.push(e)}},{key:"removeCollectionPresetField",value:function(e){this.collectionPresetFields=(0,t.reject)(this.collectionPresetFields,function(t){return t.value.name===e})}},{key:"getCollectionPresetFields",value:function(){return(0,t.orderBy)(this.collectionPresetFields,["order"],["asc"])}},{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){var u=[i,c];if(r)throw TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,n=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(e){return t.addCollectionPresetField({order:100,description:'{{t("Primary key, unique identifier, self growth") }}',value:{name:"id",type:"bigInt",autoIncrement:!0,primaryKey:!0,allowNull:!1,uiSchema:{type:"number",title:'{{t("ID")}}',"x-component":"InputNumber","x-read-pretty":!0},interface:"id"}}),t.addCollectionPresetField({order:200,description:'{{t("Store the creation time of each record")}}',value:{name:"createdAt",interface:"createdAt",type:"date",field:"createdAt",uiSchema:{type:"datetime",title:'{{t("Created at")}}',"x-component":"DatePicker","x-component-props":{},"x-read-pretty":!0}}}),t.addCollectionPresetField({order:300,description:'{{t("Store the creation user of each record") }}',value:{name:"createdBy",interface:"createdBy",type:"belongsTo",target:"users",foreignKey:"createdById",uiSchema:{type:"object",title:'{{t("Created by")}}',"x-component":"AssociationField","x-component-props":{fieldNames:{value:"id",label:"nickname"}},"x-read-pretty":!0}}}),t.addCollectionPresetField({order:400,description:'{{t("Store the last update time of each record")}}',value:{type:"date",field:"updatedAt",name:"updatedAt",interface:"updatedAt",uiSchema:{type:"datetime",title:'{{t("Last updated at")}}',"x-component":"DatePicker","x-component-props":{},"x-read-pretty":!0}}}),t.addCollectionPresetField({order:500,description:'{{t("Store the last update user of each record")}}',value:{type:"belongsTo",target:"users",foreignKey:"updatedById",name:"updatedBy",interface:"updatedBy",uiSchema:{type:"object",title:'{{t("Last updated by")}}',"x-component":"AssociationField","x-component-props":{fieldNames:{value:"id",label:"nickname"}},"x-read-pretty":!0}}}),[2]})},function(){var t=this,n=arguments;return new Promise(function(o,i){var a=e.apply(t,n);function c(e){r(a,o,i,c,u,"next",e)}function u(e){r(a,o,i,c,u,"throw",e)}c(void 0)})})()}}],function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(o.prototype,n),o}(u(e.Plugin))}(),i}()});
|
package/dist/externalVersion.js
CHANGED
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "2.0.0-alpha.
|
|
11
|
+
"@nocobase/client": "2.0.0-alpha.23",
|
|
12
12
|
"lodash": "4.17.21",
|
|
13
|
-
"@nocobase/database": "2.0.0-alpha.
|
|
14
|
-
"@nocobase/plugin-error-handler": "2.0.0-alpha.
|
|
15
|
-
"@nocobase/server": "2.0.0-alpha.
|
|
16
|
-
"@formily/json-schema": "2.3.7",
|
|
17
|
-
"@nocobase/test": "2.0.0-alpha.21",
|
|
18
|
-
"@nocobase/utils": "2.0.0-alpha.21",
|
|
13
|
+
"@nocobase/database": "2.0.0-alpha.23",
|
|
14
|
+
"@nocobase/plugin-error-handler": "2.0.0-alpha.23",
|
|
15
|
+
"@nocobase/server": "2.0.0-alpha.23",
|
|
19
16
|
"sequelize": "6.35.2",
|
|
17
|
+
"@formily/json-schema": "2.3.7",
|
|
18
|
+
"@nocobase/test": "2.0.0-alpha.23",
|
|
19
|
+
"@nocobase/utils": "2.0.0-alpha.23",
|
|
20
|
+
"@nocobase/actions": "2.0.0-alpha.23",
|
|
20
21
|
"dayjs": "1.11.13"
|
|
21
22
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
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 const PRESET_FIELDS_INTERFACES: string[];
|
|
@@ -0,0 +1,36 @@
|
|
|
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 constants_exports = {};
|
|
28
|
+
__export(constants_exports, {
|
|
29
|
+
PRESET_FIELDS_INTERFACES: () => PRESET_FIELDS_INTERFACES
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(constants_exports);
|
|
32
|
+
const PRESET_FIELDS_INTERFACES = ["id", "createdAt", "updatedAt", "createdBy", "updatedBy"];
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
PRESET_FIELDS_INTERFACES
|
|
36
|
+
});
|
|
@@ -134,6 +134,9 @@ class CollectionModel extends import_database.MagicAttributeModel {
|
|
|
134
134
|
return 0;
|
|
135
135
|
});
|
|
136
136
|
for (const instance of instances) {
|
|
137
|
+
if (!instance.get("collectionName")) {
|
|
138
|
+
instance.set("collectionName", this.get("name"));
|
|
139
|
+
}
|
|
137
140
|
await instance.load(options);
|
|
138
141
|
}
|
|
139
142
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { Context, Next } from '@nocobase/actions';
|
|
10
|
+
declare const _default: {
|
|
11
|
+
name: string;
|
|
12
|
+
actions: {
|
|
13
|
+
refresh(ctx: Context, next: Next): Promise<void>;
|
|
14
|
+
syncFields(ctx: Context, next: Next): Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
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 main_data_source_exports = {};
|
|
28
|
+
__export(main_data_source_exports, {
|
|
29
|
+
default: () => main_data_source_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(main_data_source_exports);
|
|
32
|
+
var main_data_source_default = {
|
|
33
|
+
name: "mainDataSource",
|
|
34
|
+
actions: {
|
|
35
|
+
async refresh(ctx, next) {
|
|
36
|
+
const plugin = ctx.app.pm.get("data-source-main");
|
|
37
|
+
const mainDataSource = ctx.app.dataSourceManager.get("main");
|
|
38
|
+
if (mainDataSource.status === "loaded") {
|
|
39
|
+
await plugin.loadCollections();
|
|
40
|
+
}
|
|
41
|
+
await next();
|
|
42
|
+
},
|
|
43
|
+
async syncFields(ctx, next) {
|
|
44
|
+
const { collections } = ctx.action.params.values || {};
|
|
45
|
+
const mainDataSource = ctx.app.dataSourceManager.get("main");
|
|
46
|
+
if (mainDataSource.status === "loaded") {
|
|
47
|
+
await mainDataSource.syncFieldsFromDatabase(ctx, collections);
|
|
48
|
+
}
|
|
49
|
+
await next();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
package/dist/server/server.js
CHANGED
|
@@ -55,6 +55,8 @@ var import_beforeDestoryField = require("./hooks/beforeDestoryField");
|
|
|
55
55
|
var import_models = require("./models");
|
|
56
56
|
var import_collections = __toESM(require("./resourcers/collections"));
|
|
57
57
|
var import_views = __toESM(require("./resourcers/views"));
|
|
58
|
+
var import_main_data_source = __toESM(require("./resourcers/main-data-source"));
|
|
59
|
+
var import_constants = require("./constants");
|
|
58
60
|
var import_json_schema = require("@formily/json-schema");
|
|
59
61
|
var import_lodash2 = __toESM(require("lodash"));
|
|
60
62
|
class PluginDataSourceMainServer extends import_server.Plugin {
|
|
@@ -376,7 +378,7 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
376
378
|
this.app.acl.allow("collectionCategories", "list", "loggedIn");
|
|
377
379
|
this.app.acl.registerSnippet({
|
|
378
380
|
name: `pm.data-source-manager.data-source-main`,
|
|
379
|
-
actions: ["collections:*", "collections.fields:*", "collectionCategories:*"]
|
|
381
|
+
actions: ["collections:*", "collections.fields:*", "collectionCategories:*", "mainDataSource:*"]
|
|
380
382
|
});
|
|
381
383
|
this.app.acl.registerSnippet({
|
|
382
384
|
name: `pm.data-source-manager.collection-view `,
|
|
@@ -410,9 +412,10 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
410
412
|
}
|
|
411
413
|
await next();
|
|
412
414
|
});
|
|
413
|
-
this.app.
|
|
414
|
-
this.app.
|
|
415
|
-
|
|
415
|
+
this.app.resourceManager.define(import_views.default);
|
|
416
|
+
this.app.resourceManager.registerActionHandlers(import_collections.default);
|
|
417
|
+
this.app.resourceManager.define(import_main_data_source.default);
|
|
418
|
+
const handleFieldSource = (fields, rawFields) => {
|
|
416
419
|
var _a;
|
|
417
420
|
for (const field of import_lodash.default.castArray(fields)) {
|
|
418
421
|
if (field.get("source")) {
|
|
@@ -430,6 +433,15 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
430
433
|
});
|
|
431
434
|
field.set("options", newOptions);
|
|
432
435
|
}
|
|
436
|
+
const fieldTypes = import_database.fieldTypeMap[this.db.options.dialect];
|
|
437
|
+
if (rawFields && fieldTypes) {
|
|
438
|
+
const rawField = rawFields[field.get("name")];
|
|
439
|
+
if (rawField && !import_constants.PRESET_FIELDS_INTERFACES.includes(field.get("interface"))) {
|
|
440
|
+
const mappedType = (0, import_database.extractTypeFromDefinition)(rawField.type);
|
|
441
|
+
const possibleTypes = fieldTypes[mappedType];
|
|
442
|
+
field.set("possibleTypes", possibleTypes);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
433
445
|
}
|
|
434
446
|
};
|
|
435
447
|
this.app.resourceManager.use(async function handleFieldSourceMiddleware(ctx, next) {
|
|
@@ -444,7 +456,18 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
444
456
|
}
|
|
445
457
|
}
|
|
446
458
|
if (ctx.action.resourceName == "collections.fields" && ctx.action.actionName == "list") {
|
|
447
|
-
|
|
459
|
+
const collectionName = ctx.action.sourceId;
|
|
460
|
+
const collection = ctx.db.getCollection(collectionName);
|
|
461
|
+
let rawFields = {};
|
|
462
|
+
if (collection) {
|
|
463
|
+
try {
|
|
464
|
+
rawFields = await ctx.app.db.queryInterface.sequelizeQueryInterface.describeTable(
|
|
465
|
+
collection.getTableNameWithSchema()
|
|
466
|
+
);
|
|
467
|
+
} catch (err) {
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
handleFieldSource(((_b = ctx.action.params) == null ? void 0 : _b.paginate) == "false" ? ctx.body : ctx.body.rows, rawFields);
|
|
448
471
|
}
|
|
449
472
|
if (ctx.action.resourceName == "collections.fields" && ctx.action.actionName == "get") {
|
|
450
473
|
handleFieldSource(ctx.body);
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "数据源:主数据库",
|
|
5
5
|
"description": "NocoBase main database, supports relational databases such as PostgreSQL, MySQL, MariaDB and so on.",
|
|
6
6
|
"description.zh-CN": "NocoBase 主数据库,支持 PostgreSQL、MySQL、MariaDB 等关系型数据库。",
|
|
7
|
-
"version": "2.0.0-alpha.
|
|
7
|
+
"version": "2.0.0-alpha.23",
|
|
8
8
|
"main": "./dist/server/index.js",
|
|
9
9
|
"homepage": "https://docs.nocobase.com/handbook/data-source-main",
|
|
10
10
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/data-source-main",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@nocobase/test": "2.x",
|
|
23
23
|
"@nocobase/utils": "2.x"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "ea67a7ad1c12fce26e0fff992f33de10901eff6a",
|
|
26
26
|
"keywords": [
|
|
27
27
|
"Data sources"
|
|
28
28
|
]
|