@nocobase/plugin-data-source-main 2.0.0-alpha.3 → 2.0.0-alpha.30

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.
@@ -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:"integer"}}),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}()});
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}()});
@@ -8,13 +8,15 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.0.0-alpha.3",
11
+ "@nocobase/client": "2.0.0-alpha.30",
12
12
  "lodash": "4.17.21",
13
- "@nocobase/database": "2.0.0-alpha.3",
14
- "@nocobase/plugin-error-handler": "2.0.0-alpha.3",
15
- "@nocobase/server": "2.0.0-alpha.3",
16
- "@nocobase/test": "2.0.0-alpha.3",
17
- "@nocobase/utils": "2.0.0-alpha.3",
13
+ "@nocobase/database": "2.0.0-alpha.30",
14
+ "@nocobase/plugin-error-handler": "2.0.0-alpha.30",
15
+ "@nocobase/server": "2.0.0-alpha.30",
18
16
  "sequelize": "6.35.2",
17
+ "@formily/json-schema": "2.3.7",
18
+ "@nocobase/test": "2.0.0-alpha.30",
19
+ "@nocobase/utils": "2.0.0-alpha.30",
20
+ "@nocobase/actions": "2.0.0-alpha.30",
19
21
  "dayjs": "1.11.13"
20
22
  };
@@ -1,4 +1,48 @@
1
1
  {
2
2
  "field-name-exists": "Field name \"{{name}}\" already exists in collection \"{{collectionName}}\"",
3
- "field-is-depended-on-by-other": "Can not delete field \"{{fieldName}}\" in \"{{fieldCollectionName}}\", it is used by field \"{{dependedFieldName}}\" in \"{{dependedFieldCollectionName}}\" as \"{{dependedFieldAs}}\""
3
+ "field-is-depended-on-by-other": "Can not delete field \"{{fieldName}}\" in \"{{fieldCollectionName}}\", it is used by field \"{{dependedFieldName}}\" in \"{{dependedFieldCollectionName}}\" as \"{{dependedFieldAs}}\"",
4
+ "string.base": "{{label}} must be a string",
5
+ "string.empty": "{{label}} is not allowed to be empty",
6
+ "string.min": "{{label}} length must be at least {{limit}} characters long",
7
+ "string.max": "{{label}} length must be less than or equal to {{limit}} characters long",
8
+ "string.length": "{{label}} length must be {{limit}} characters long",
9
+ "string.alphanum": "{{label}} must only contain alpha-numeric characters",
10
+ "string.token": "{{label}} must only contain alpha-numeric and underscore characters",
11
+ "string.regex": "{{label}} with value {{value}} fails to match the required pattern",
12
+ "string.email": "{{label}} email address doesn’t meet the required format",
13
+ "string.uri": "{{label}} must be a valid uri",
14
+ "string.uriCustomScheme": "{{label}} must be a valid uri with a scheme matching the {{scheme}} pattern",
15
+ "string.uriRelativeOnly": "{{label}} must be a valid relative uri",
16
+ "string.isoDate": "{{label}} must be a valid ISO 8601 date",
17
+ "string.guid": "{{label}} must be a valid UUID",
18
+ "string.hex": "{{label}} must only contain hexadecimal characters",
19
+ "string.hostname": "{{label}} must be a valid hostname",
20
+ "string.lowercase": "{{label}} must only contain lowercase characters",
21
+ "string.uppercase": "{{label}} must only contain uppercase characters",
22
+ "string.trim": "{{label}} must not have leading or trailing whitespace",
23
+ "string.creditCard": "{{label}} must be a credit card",
24
+ "string.pattern.base": "{{label}} with value \"{{value}}\" fails to match the required pattern: {{regex}}",
25
+ "string.pattern.name": "{{label}} with value \"{{value}}\" fails to match the {{name}} pattern",
26
+ "string.pattern.invert.base": "{{label}} with value \"{{value}}\" matches the inverted pattern",
27
+ "string.pattern.invert.name": "{{label}} with value \"{{value}}\" matches the inverted {{name}} pattern",
28
+ "any.required": "{{label}} is required",
29
+ "number.base": "{{label}} must be a number",
30
+ "number.min": "{{label}} must be greater than or equal to {{limit}}",
31
+ "number.max": "{{label}} must be less than or equal to {{limit}}",
32
+ "number.less": "{{label}} must be less than {{limit}}",
33
+ "number.greater": "{{label}} must be greater than {{limit}}",
34
+ "number.float": "{{label}} must be a float or double",
35
+ "number.integer": "{{label}} must be an integer",
36
+ "number.negative": "{{label}} must be a negative number",
37
+ "number.positive": "{{label}} must be a positive number",
38
+ "number.precision": "{{label}} must not have more than {{limit}} decimal places",
39
+ "number.multiple": "{{label}} must be a multiple of {{multiple}}",
40
+ "number.port": "{{label}} must be a valid port",
41
+ "number.unsafe": "{{label}} must be a safe number",
42
+ "date.base": "{{label}} must be a valid date",
43
+ "date.format": "{{label}} must be in {{format}} format",
44
+ "date.greater": "{{label}} must be greater than {{limit}}",
45
+ "date.less": "{{label}} must be less than {{limit}}",
46
+ "date.max": "{{label}} must be less than or equal to {{limit}}",
47
+ "date.min": "{{label}} must be greater than or equal to {{limit}}"
4
48
  }
@@ -1,4 +1,48 @@
1
1
  {
2
2
  "field-name-exists": "字段标识 \"{{name}}\" 已存在",
3
- "field-is-depended-on-by-other": "无法删除 \"{{fieldCollectionName}}\" 中的 \"{{fieldName}}\" 字段,它被 \"{{dependedFieldCollectionName}}\" 中的 \"{{dependedFieldName}}\" 字段用作 \"{{dependedFieldAs}}\""
3
+ "field-is-depended-on-by-other": "无法删除 \"{{fieldCollectionName}}\" 中的 \"{{fieldName}}\" 字段,它被 \"{{dependedFieldCollectionName}}\" 中的 \"{{dependedFieldName}}\" 字段用作 \"{{dependedFieldAs}}\"",
4
+ "string.base": "{{label}} 必须是字符串",
5
+ "string.empty": "{{label}} 不能为空字符串",
6
+ "string.min": "{{label}} 长度不能少于 {{limit}} 个字符",
7
+ "string.max": "{{label}} 长度不能超过 {{limit}} 个字符",
8
+ "string.length": "{{label}} 长度必须为 {{limit}} 个字符",
9
+ "string.alphanum": "{{label}} 只能包含字母和数字",
10
+ "string.token": "{{label}} 只能包含字母、数字和下划线",
11
+ "string.regex": "{{label}} 值 {{value}} 格式不正确",
12
+ "string.email": "{{label}} 邮箱地址不符合要求的格式",
13
+ "string.uri": "{{label}} 必须是有效的URI",
14
+ "string.uriRelativeOnly": "{{label}} 必须是有效的相对路径",
15
+ "string.uriCustomScheme": "{{label}} 必须是符合 {{scheme}} 模式的有效URI",
16
+ "string.isoDate": "{{label}} 必须是有效的ISO日期",
17
+ "string.guid": "{{label}} 必须是有效的UUID",
18
+ "string.hex": "{{label}} 必须是有效的十六进制字符串",
19
+ "string.hostname": "{{label}} 必须是有效的主机名",
20
+ "string.lowercase": "{{label}} 必须是小写",
21
+ "string.uppercase": "{{label}} 必须是大写",
22
+ "string.trim": "{{label}} 不能包含前后空白字符",
23
+ "string.creditCard": "{{label}} 必须是有效的信用卡号",
24
+ "string.pattern.base": "{{label}} 值 \"{{value}}\" 格式不符合要求:{{regex}}",
25
+ "string.pattern.name": "{{label}} 值 \"{{value}}\" 不符合 {{name}} 格式",
26
+ "string.pattern.invert.base": "{{label}} 值 \"{{value}}\" 包含不允许的字符",
27
+ "string.pattern.invert.name": "{{label}} 值 \"{{value}}\" 不能符合 {{name}} 格式",
28
+ "any.required": "{{label}} 是必填项",
29
+ "number.base": "{{label}} 必须是数字",
30
+ "number.min": "{{label}} 必须大于或等于 {{limit}}",
31
+ "number.max": "{{label}} 必须小于或等于 {{limit}}",
32
+ "number.less": "{{label}} 必须小于 {{limit}}",
33
+ "number.greater": "{{label}} 必须大于 {{limit}}",
34
+ "number.float": "{{label}} 必须是浮点数",
35
+ "number.integer": "{{label}} 必须是整数",
36
+ "number.negative": "{{label}} 必须是负数",
37
+ "number.positive": "{{label}} 必须是正数",
38
+ "number.precision": "{{label}} 精度不能超过 {{limit}} 位小数",
39
+ "number.multiple": "{{label}} 必须是 {{multiple}} 的倍数",
40
+ "number.port": "{{label}} 必须是有效的端口号",
41
+ "number.unsafe": "{{label}} 必须是安全整数",
42
+ "date.base": "{{label}} 必须是有效日期",
43
+ "date.format": "{{label}} 必须是 {{format}} 格式",
44
+ "date.greater": "{{label}} 必须大于 {{limit}}",
45
+ "date.less": "{{label}} 必须小于 {{limit}}",
46
+ "date.max": "{{label}} 必须小于或等于 {{limit}}",
47
+ "date.min": "{{label}} 必须大于或等于 {{limit}}"
4
48
  }
@@ -6,7 +6,4 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import Database from '@nocobase/database';
10
- export declare function afterCreateForReverseField(db: Database): (model: any, { transaction }: {
11
- transaction: any;
12
- }) => Promise<void>;
9
+ export declare const PRESET_FIELDS_INTERFACES: string[];
@@ -24,23 +24,13 @@ var __copyProps = (to, from, except, desc) => {
24
24
  return to;
25
25
  };
26
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var afterCreateForReverseField_exports = {};
28
- __export(afterCreateForReverseField_exports, {
29
- afterCreateForReverseField: () => afterCreateForReverseField
27
+ var constants_exports = {};
28
+ __export(constants_exports, {
29
+ PRESET_FIELDS_INTERFACES: () => PRESET_FIELDS_INTERFACES
30
30
  });
31
- module.exports = __toCommonJS(afterCreateForReverseField_exports);
32
- function afterCreateForReverseField(db) {
33
- return async (model, { transaction }) => {
34
- const Field = db.getCollection("fields");
35
- const reverseKey = model.get("reverseKey");
36
- if (!reverseKey) {
37
- return;
38
- }
39
- const reverse = await Field.model.findByPk(reverseKey, { transaction });
40
- await reverse.update({ reverseKey: model.get("key") }, { hooks: false, transaction });
41
- };
42
- }
31
+ module.exports = __toCommonJS(constants_exports);
32
+ const PRESET_FIELDS_INTERFACES = ["id", "createdAt", "updatedAt", "createdBy", "updatedBy"];
43
33
  // Annotate the CommonJS export names for ESM import in node:
44
34
  0 && (module.exports = {
45
- afterCreateForReverseField
35
+ PRESET_FIELDS_INTERFACES
46
36
  });
@@ -7,7 +7,6 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  export * from './afterCreateForForeignKeyField';
10
- export * from './afterCreateForReverseField';
11
10
  export * from './beforeCreateForReverseField';
12
11
  export * from './beforeDestroyForeignKey';
13
12
  export * from './beforeInitOptions';
@@ -24,14 +24,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
24
24
  var hooks_exports = {};
25
25
  module.exports = __toCommonJS(hooks_exports);
26
26
  __reExport(hooks_exports, require("./afterCreateForForeignKeyField"), module.exports);
27
- __reExport(hooks_exports, require("./afterCreateForReverseField"), module.exports);
28
27
  __reExport(hooks_exports, require("./beforeCreateForReverseField"), module.exports);
29
28
  __reExport(hooks_exports, require("./beforeDestroyForeignKey"), module.exports);
30
29
  __reExport(hooks_exports, require("./beforeInitOptions"), module.exports);
31
30
  // Annotate the CommonJS export names for ESM import in node:
32
31
  0 && (module.exports = {
33
32
  ...require("./afterCreateForForeignKeyField"),
34
- ...require("./afterCreateForReverseField"),
35
33
  ...require("./beforeCreateForReverseField"),
36
34
  ...require("./beforeDestroyForeignKey"),
37
35
  ...require("./beforeInitOptions")
@@ -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
+ };
@@ -16,6 +16,7 @@ export declare class PluginDataSourceMainServer extends Plugin {
16
16
  beforeLoad(): Promise<void>;
17
17
  private db2cm;
18
18
  load(): Promise<void>;
19
+ registerErrorHandler(): void;
19
20
  install(): Promise<void>;
20
21
  }
21
22
  export default PluginDataSourceMainServer;
@@ -55,6 +55,10 @@ 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");
60
+ var import_json_schema = require("@formily/json-schema");
61
+ var import_lodash2 = __toESM(require("lodash"));
58
62
  class PluginDataSourceMainServer extends import_server.Plugin {
59
63
  loadFilter = {};
60
64
  db2cmCollections = [];
@@ -178,7 +182,24 @@ class PluginDataSourceMainServer extends import_server.Plugin {
178
182
  }
179
183
  });
180
184
  this.app.db.on("fields.beforeCreate", (0, import_beforeCreateForValidateField.beforeCreateForValidateField)(this.app.db));
181
- this.app.db.on("fields.afterCreate", (0, import_hooks.afterCreateForReverseField)(this.app.db));
185
+ this.app.db.on("fields.afterCreate", async (model, { transaction }) => {
186
+ const Field = this.app.db.getCollection("fields");
187
+ const reverseKey = model.get("reverseKey");
188
+ if (!reverseKey) {
189
+ return;
190
+ }
191
+ const reverse = await Field.model.findByPk(reverseKey, { transaction });
192
+ await reverse.update({ reverseKey: model.get("key") }, { hooks: false, transaction });
193
+ this.sendSyncMessage(
194
+ {
195
+ type: "syncCollection",
196
+ collectionName: model.get("collectionName")
197
+ },
198
+ {
199
+ transaction
200
+ }
201
+ );
202
+ });
182
203
  this.app.db.on("fields.beforeCreate", async (model, options) => {
183
204
  const { transaction } = options;
184
205
  const collectionName = model.get("collectionName");
@@ -357,7 +378,7 @@ class PluginDataSourceMainServer extends import_server.Plugin {
357
378
  this.app.acl.allow("collectionCategories", "list", "loggedIn");
358
379
  this.app.acl.registerSnippet({
359
380
  name: `pm.data-source-manager.data-source-main`,
360
- actions: ["collections:*", "collections.fields:*", "collectionCategories:*"]
381
+ actions: ["collections:*", "collections.fields:*", "collectionCategories:*", "mainDataSource:*"]
361
382
  });
362
383
  this.app.acl.registerSnippet({
363
384
  name: `pm.data-source-manager.collection-view `,
@@ -382,52 +403,7 @@ class PluginDataSourceMainServer extends import_server.Plugin {
382
403
  }
383
404
  async load() {
384
405
  this.db.getRepository("collections").setApp(this.app);
385
- const errorHandlerPlugin = this.app.getPlugin("error-handler");
386
- errorHandlerPlugin.errorHandler.register(
387
- (err) => {
388
- return err instanceof import_database.UniqueConstraintError;
389
- },
390
- (err, ctx) => {
391
- return ctx.throw(400, ctx.t(`The value of ${Object.keys(err.fields)} field duplicated`));
392
- }
393
- );
394
- errorHandlerPlugin.errorHandler.register(
395
- (err) => err instanceof import_field_is_depended_on_by_other.FieldIsDependedOnByOtherError,
396
- (err, ctx) => {
397
- ctx.status = 400;
398
- ctx.body = {
399
- errors: [
400
- {
401
- message: ctx.i18n.t("field-is-depended-on-by-other", {
402
- fieldName: err.options.fieldName,
403
- fieldCollectionName: err.options.fieldCollectionName,
404
- dependedFieldName: err.options.dependedFieldName,
405
- dependedFieldCollectionName: err.options.dependedFieldCollectionName,
406
- dependedFieldAs: err.options.dependedFieldAs,
407
- ns: "data-source-main"
408
- })
409
- }
410
- ]
411
- };
412
- }
413
- );
414
- errorHandlerPlugin.errorHandler.register(
415
- (err) => err instanceof import_field_name_exists_error.FieldNameExistsError,
416
- (err, ctx) => {
417
- ctx.status = 400;
418
- ctx.body = {
419
- errors: [
420
- {
421
- message: ctx.i18n.t("field-name-exists", {
422
- name: err.value,
423
- collectionName: err.collectionName,
424
- ns: "data-source-main"
425
- })
426
- }
427
- ]
428
- };
429
- }
430
- );
406
+ this.registerErrorHandler();
431
407
  this.app.resourceManager.use(async function mergeReverseFieldWhenSaveCollectionField(ctx, next) {
432
408
  if (ctx.action.resourceName === "collections.fields" && ["create", "update"].includes(ctx.action.actionName)) {
433
409
  ctx.action.mergeParams({
@@ -436,9 +412,10 @@ class PluginDataSourceMainServer extends import_server.Plugin {
436
412
  }
437
413
  await next();
438
414
  });
439
- this.app.resource(import_views.default);
440
- this.app.actions(import_collections.default);
441
- const handleFieldSource = (fields) => {
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) => {
442
419
  var _a;
443
420
  for (const field of import_lodash.default.castArray(fields)) {
444
421
  if (field.get("source")) {
@@ -456,6 +433,15 @@ class PluginDataSourceMainServer extends import_server.Plugin {
456
433
  });
457
434
  field.set("options", newOptions);
458
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
+ }
459
445
  }
460
446
  };
461
447
  this.app.resourceManager.use(async function handleFieldSourceMiddleware(ctx, next) {
@@ -470,7 +456,18 @@ class PluginDataSourceMainServer extends import_server.Plugin {
470
456
  }
471
457
  }
472
458
  if (ctx.action.resourceName == "collections.fields" && ctx.action.actionName == "list") {
473
- handleFieldSource(((_b = ctx.action.params) == null ? void 0 : _b.paginate) == "false" ? ctx.body : ctx.body.rows);
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);
474
471
  }
475
472
  if (ctx.action.resourceName == "collections.fields" && ctx.action.actionName == "get") {
476
473
  handleFieldSource(ctx.body);
@@ -482,6 +479,95 @@ class PluginDataSourceMainServer extends import_server.Plugin {
482
479
  origin: this.options.packageName
483
480
  });
484
481
  }
482
+ registerErrorHandler() {
483
+ const errorHandlerPlugin = this.app.pm.get("error-handler");
484
+ errorHandlerPlugin.errorHandler.register(
485
+ (err) => {
486
+ return err instanceof import_database.UniqueConstraintError;
487
+ },
488
+ (err, ctx) => {
489
+ return ctx.throw(400, ctx.t(`The value of ${Object.keys(err.fields)} field duplicated`));
490
+ }
491
+ );
492
+ errorHandlerPlugin.errorHandler.register(
493
+ (err) => err instanceof import_field_is_depended_on_by_other.FieldIsDependedOnByOtherError,
494
+ (err, ctx) => {
495
+ ctx.status = 400;
496
+ ctx.body = {
497
+ errors: [
498
+ {
499
+ message: ctx.i18n.t("field-is-depended-on-by-other", {
500
+ fieldName: err.options.fieldName,
501
+ fieldCollectionName: err.options.fieldCollectionName,
502
+ dependedFieldName: err.options.dependedFieldName,
503
+ dependedFieldCollectionName: err.options.dependedFieldCollectionName,
504
+ dependedFieldAs: err.options.dependedFieldAs,
505
+ ns: "data-source-main"
506
+ })
507
+ }
508
+ ]
509
+ };
510
+ }
511
+ );
512
+ errorHandlerPlugin.errorHandler.register(
513
+ (err) => err instanceof import_field_name_exists_error.FieldNameExistsError,
514
+ (err, ctx) => {
515
+ ctx.status = 400;
516
+ ctx.body = {
517
+ errors: [
518
+ {
519
+ message: ctx.i18n.t("field-name-exists", {
520
+ name: err.value,
521
+ collectionName: err.collectionName,
522
+ ns: "data-source-main"
523
+ })
524
+ }
525
+ ]
526
+ };
527
+ }
528
+ );
529
+ errorHandlerPlugin.errorHandler.register(
530
+ (err) => err instanceof import_database.JoiValidationError,
531
+ (err, ctx) => {
532
+ const t = ctx.i18n.t;
533
+ ctx.status = 400;
534
+ ctx.body = {
535
+ errors: err.details.map((detail) => {
536
+ const context = detail.context;
537
+ const label = context.label;
538
+ if (label) {
539
+ const [collectionName, fieldName] = label.split(".");
540
+ const collection = this.db.getCollection(collectionName);
541
+ if (collection) {
542
+ const collectionTitle = import_json_schema.Schema.compile(collection.options.title, { t });
543
+ const field = collection.getField(fieldName);
544
+ const fieldOptions = import_json_schema.Schema.compile(field == null ? void 0 : field.options, { t });
545
+ const fieldTitle = import_lodash2.default.get(fieldOptions, "uiSchema.title", fieldName);
546
+ context.label = `${t(collectionTitle, {
547
+ ns: ["lm-collections", "client"]
548
+ })}: ${t(fieldTitle, {
549
+ ns: ["lm-collections", "client"]
550
+ })}`;
551
+ }
552
+ }
553
+ if (context.regex) {
554
+ context.regex = context.regex.source;
555
+ }
556
+ let message = ctx.i18n.t(detail.type, {
557
+ ...context,
558
+ ns: "data-source-main"
559
+ });
560
+ if (message === detail.type) {
561
+ message = err.message.replace(`"${label}"`, context.label);
562
+ }
563
+ return {
564
+ message
565
+ };
566
+ })
567
+ };
568
+ }
569
+ );
570
+ }
485
571
  async install() {
486
572
  const dataSourcesCollection = this.app.db.getCollection("dataSources");
487
573
  if (dataSourcesCollection) {
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.3",
7
+ "version": "2.0.0-alpha.30",
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": "8efc23aa78058d871e98a91419f3c4a61762cc15",
25
+ "gitHead": "cdac55c9cdf0dbdbe57a21815f323b975792bfc0",
26
26
  "keywords": [
27
27
  "Data sources"
28
28
  ]