@nocobase/plugin-collection-sql 2.1.0-beta.43 → 2.1.0-beta.45

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(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-collection-sql",["@nocobase/client"],e):"object"==typeof exports?exports["@nocobase/plugin-collection-sql"]=e(require("@nocobase/client")):t["@nocobase/plugin-collection-sql"]=e(t["@nocobase/client"])}(self,function(t){return function(){"use strict";var e={342:function(e){e.exports=t}},n={};function r(t){var o=n[t];if(void 0!==o)return o.exports;var c=n[t]={exports:{}};return e[t](c,c.exports,r),c.exports}r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,{a:e}),e},r.d=function(t,e){for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(t){if("object"==typeof window)return window}}(),r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.g.importScripts&&(o=r.g.location+"");var o,c=r.g.document;if(!o&&c&&(c.currentScript&&"SCRIPT"===c.currentScript.tagName.toUpperCase()&&(o=c.currentScript.src),!o)){var i=c.getElementsByTagName("script");if(i.length)for(var u=i.length-1;u>-1&&(!o||!/^http(s?):/.test(o));)o=i[u--].src}if(!o)throw Error("Automatic publicPath is not supported in this browser");r.p=o.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/");var l={};return!function(){var t="",e="u">typeof document?document.currentScript:null;if(e&&e.src&&(t=e.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),!t){var n=window.__webpack_public_path__||"";n&&("/"!==n.charAt(n.length-1)&&(n+="/"),t=n+"static/plugins/@nocobase/plugin-collection-sql/dist/client/")}if(!t){if(!(t=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var o=window.location.pathname||"/",c=o.indexOf("/v2/");t=c>=0?o.slice(0,c+1):"/"}t&&(t=t.replace(/\/v2\/?$/,"/")),t||(t="/"),"/"!==t.charAt(t.length-1)&&(t+="/"),t+="static/plugins/@nocobase/plugin-collection-sql/dist/client/"}r.p=t}(),!function(){r.r(l),r.d(l,{PluginCollectionSqlClient:function(){return p}});var t=r(342);function e(t,e,n,r,o,c,i){try{var u=t[c](i),l=u.value}catch(t){n(t);return}u.done?e(l):Promise.resolve(l).then(r,o)}function n(t){return function(){var n=this,r=arguments;return new Promise(function(o,c){var i=t.apply(n,r);function u(t){e(i,o,c,u,l,"next",t)}function l(t){e(i,o,c,u,l,"throw",t)}u(void 0)})}}function o(t,e,n){return(o=a()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&i(o,n.prototype),o}).apply(null,arguments)}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return o(t,arguments,c(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),i(n,t)})(t)}function a(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(a=function(){return!!t})()}function f(t,e){var n,r,o,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(i,"next",{value:l(0)}),u(i,"throw",{value:l(1)}),u(i,"return",{value:l(2)}),"function"==typeof Symbol&&u(i,Symbol.iterator,{value:function(){return this}}),i;function l(u){return function(l){var a=[u,l];if(n)throw TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return c.label++,{value:a[1],done:!1};case 5:c.label++,r=a[1],a=[0];continue;case 7:a=c.ops.pop(),c.trys.pop();continue;default:if(!(o=(o=c.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){c=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){c.label=a[1];break}if(6===a[0]&&c.label<o[1]){c.label=o[1],o=a;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(a);break}o[2]&&c.ops.pop(),c.trys.pop();continue}a=e.call(t,c)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}}var p=function(t){var e;if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");function r(){var t,e;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return t=r,e=arguments,t=c(t),function(t,e){var n;if(e&&("object"==((n=e)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof e))return e;if(void 0===t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(this,a()?Reflect.construct(t,e||[],c(this).constructor):t.apply(this,e))}return r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),t&&i(r,t),e=[{key:"afterAdd",value:function(){return n(function(){return f(this,function(t){return[2]})})()}},{key:"beforeLoad",value:function(){return n(function(){return f(this,function(t){return[2]})})()}},{key:"load",value:function(){return n(function(){return f(this,function(t){return[2]})})()}}],function(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}(r.prototype,e),r}(u(t.Plugin));l.default=p}(),l}()});
10
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-collection-sql",["@nocobase/client"],e):"object"==typeof exports?exports["@nocobase/plugin-collection-sql"]=e(require("@nocobase/client")):t["@nocobase/plugin-collection-sql"]=e(t["@nocobase/client"])}(self,function(t){return function(){"use strict";var e={342:function(e){e.exports=t}},n={};function r(t){var o=n[t];if(void 0!==o)return o.exports;var i=n[t]={exports:{}};return e[t](i,i.exports,r),i.exports}r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,{a:e}),e},r.d=function(t,e){for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(t){if("object"==typeof window)return window}}(),r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.g.importScripts&&(o=r.g.location+"");var o,i=r.g.document;if(!o&&i&&(i.currentScript&&"SCRIPT"===i.currentScript.tagName.toUpperCase()&&(o=i.currentScript.src),!o)){var c=i.getElementsByTagName("script");if(c.length)for(var u=c.length-1;u>-1&&(!o||!/^http(s?):/.test(o));)o=c[u--].src}if(!o)throw Error("Automatic publicPath is not supported in this browser");r.p=o.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/");var l={};return!function(){var t="",e="u">typeof document?document.currentScript:null;if(e&&e.src&&(t=e.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),!t){var n=window.__webpack_public_path__||"";n&&("/"!==n.charAt(n.length-1)&&(n+="/"),t=n+"static/plugins/@nocobase/plugin-collection-sql/dist/client/")}if(!t){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(t=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var c=window.location.pathname||"/",u=c.indexOf(i);t=u>=0?c.slice(0,u+1):"/"}t&&(t=t.replace(RegExp("/"+o+"/?$"),"/")),t||(t="/"),"/"!==t.charAt(t.length-1)&&(t+="/"),t+="static/plugins/@nocobase/plugin-collection-sql/dist/client/"}r.p=t}(),!function(){r.r(l),r.d(l,{PluginCollectionSqlClient:function(){return p}});var t=r(342);function e(t,e,n,r,o,i,c){try{var u=t[i](c),l=u.value}catch(t){n(t);return}u.done?e(l):Promise.resolve(l).then(r,o)}function n(t){return function(){var n=this,r=arguments;return new Promise(function(o,i){var c=t.apply(n,r);function u(t){e(c,o,i,u,l,"next",t)}function l(t){e(c,o,i,u,l,"throw",t)}u(void 0)})}}function o(t,e,n){return(o=a()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&c(o,n.prototype),o}).apply(null,arguments)}function i(t){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return o(t,arguments,i(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,t)})(t)}function a(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(a=function(){return!!t})()}function f(t,e){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},c=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(c,"next",{value:l(0)}),u(c,"throw",{value:l(1)}),u(c,"return",{value:l(2)}),"function"==typeof Symbol&&u(c,Symbol.iterator,{value:function(){return this}}),c;function l(u){return function(l){var a=[u,l];if(n)throw TypeError("Generator is already executing.");for(;c&&(c=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=e.call(t,i)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}}var p=function(t){var e;if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");function r(){var t,e;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return t=r,e=arguments,t=i(t),function(t,e){var n;if(e&&("object"==((n=e)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof e))return e;if(void 0===t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(this,a()?Reflect.construct(t,e||[],i(this).constructor):t.apply(this,e))}return r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),t&&c(r,t),e=[{key:"afterAdd",value:function(){return n(function(){return f(this,function(t){return[2]})})()}},{key:"beforeLoad",value:function(){return n(function(){return f(this,function(t){return[2]})})()}},{key:"load",value:function(){return n(function(){return f(this,function(t){return[2]})})()}}],function(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}(r.prototype,e),r}(u(t.Plugin));l.default=p}(),l}()});
@@ -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("ahooks"),require("@nocobase/plugin-data-source-manager/client-v2"),require("@nocobase/client-v2"),require("dayjs"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("lodash")):"function"==typeof define&&define.amd?define("@nocobase/plugin-collection-sql/client-v2",["ahooks","@nocobase/plugin-data-source-manager/client-v2","@nocobase/client-v2","dayjs","react","antd","@ant-design/icons","@nocobase/flow-engine","lodash"],t):"object"==typeof exports?exports["@nocobase/plugin-collection-sql/client-v2"]=t(require("ahooks"),require("@nocobase/plugin-data-source-manager/client-v2"),require("@nocobase/client-v2"),require("dayjs"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("lodash")):e["@nocobase/plugin-collection-sql/client-v2"]=t(e.ahooks,e["@nocobase/plugin-data-source-manager/client-v2"],e["@nocobase/client-v2"],e.dayjs,e.react,e.antd,e["@ant-design/icons"],e["@nocobase/flow-engine"],e.lodash)}(self,function(e,t,r,n,o,a,l,i,u){return function(){"use strict";var c={375:function(e){e.exports=l},485:function(e){e.exports=r},694:function(e){e.exports=i},894:function(e){e.exports=t},625:function(t){t.exports=e},59:function(e){e.exports=a},185:function(e){e.exports=n},773:function(e){e.exports=u},155:function(e){e.exports=o}},s={};function f(e){var t=s[e];if(void 0!==t)return t.exports;var r=s[e]={exports:{}};return c[e](r,r.exports,f),r.exports}f.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(t,{a:t}),t},f.d=function(e,t){for(var r in t)f.o(t,r)&&!f.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},f.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.g.importScripts&&(d=f.g.location+"");var d,m=f.g.document;if(!d&&m&&(m.currentScript&&"SCRIPT"===m.currentScript.tagName.toUpperCase()&&(d=m.currentScript.src),!d)){var p=m.getElementsByTagName("script");if(p.length)for(var y=p.length-1;y>-1&&(!d||!/^http(s?):/.test(d));)d=p[y--].src}if(!d)throw Error("Automatic publicPath is not supported in this browser");f.p=d.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/");var v={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src&&(e=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/@nocobase/plugin-collection-sql/dist/client-v2/")}if(!e){if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var n=window.location.pathname||"/",o=n.indexOf("/v2/");e=o>=0?n.slice(0,o+1):"/"}e&&(e=e.replace(/\/v2\/?$/,"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/@nocobase/plugin-collection-sql/dist/client-v2/"}f.p=e}(),!function(){f.r(v),f.d(v,{PluginCollectionSqlClientV2:function(){return N},default:function(){return G},SqlPreviewConfigureItem:function(){return V},SqlFieldsConfigureItem:function(){return _},SqlStatementConfigureItem:function(){return M},SqlSyncFieldsDrawer:function(){return R},buildSqlFieldsFromPreview:function(){return I},getSqlPreviewInternalName:function(){return B},normalizeSqlPreviewResult:function(){return j},SqlSourceCollectionsConfigureItem:function(){return k},normalizeSqlCollectionSubmitValues:function(){return L}});var e=f(485),t=f(375),r=f(694),n=f(625),o=f(59),a=f(185),l=f.n(a),i=f(773),u=f(155),c=f.n(u),s=f(894);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function m(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function p(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){m(a,n,o,l,i,"next",e)}function i(e){m(a,n,o,l,i,"throw",e)}l(void 0)})}}function y(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){y(e,t,r[t])})}return e}function g(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}),e}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||w(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e){return function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||w(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(e,t){if(e){if("string"==typeof e)return d(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return d(e,t)}}function F(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var q=new Set(["hasOne","hasMany","belongsToMany","belongsTo"]),E="__sqlPreview";function A(e){return!!e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"&&!Array.isArray(e)}function O(e){return!!A(e)&&(Array.isArray(e.data)||A(e.fields)||Array.isArray(e.sources)||"string"==typeof e.error)}function j(e){var t=[e,(0,i.get)(e,"data"),(0,i.get)(e,"data.data"),(0,i.get)(e,"data.data.data")].find(O);return t?{data:Array.isArray(t.data)?t.data:[],error:"string"==typeof t.error?t.error:void 0,fields:A(t.fields)?t.fields:{},sources:Array.isArray(t.sources)?t.sources.filter(Boolean):[]}:{data:[],fields:{},sources:[]}}function C(e){return Array.isArray(e)?e.filter(Boolean).join(".")||null:e||null}function x(e){return(null==e?void 0:e.options)||e||{}}function I(e){var t,r=e.currentFields,n=e.manager,o=e.preview,a=new Map,i=(null==o?void 0:o.fields)||{},u=(null==o||null==(t=o.data)?void 0:t[0])||{};return Object.keys(u).length?Object.entries(u).forEach(function(e){var t,r,o=h(e,2),u=o[0],c=o[1],s=i[u],f=(null==s?void 0:s.interface)||("id"===u.toLowerCase()?"id":"number"==typeof c?Number.isInteger(c)?"integer":"number":"boolean"==typeof c?"checkbox":"string"==typeof c&&l()(c).isValid()?"datetime":"input"),d=(null==n||null==(r=n.getFieldInterface)||null==(t=r.call(n,f))?void 0:t.default)||{},m=(null==s?void 0:s.uiSchema)||d.uiSchema||{};a.set(u,{name:u,interface:f,type:(null==s?void 0:s.type)||d.type,source:null==s?void 0:s.source,uiSchema:b({title:u},m)})}):Object.entries(i).forEach(function(e){var t=h(e,2),r=t[0],n=t[1];a.set(r,g(b({name:r,type:"string"},n),{uiSchema:b({title:r},n.uiSchema||{})}))}),(void 0===r?[]:r).forEach(function(e){(null==e?void 0:e.name)&&a.has(e.name)&&a.set(e.name,e)}),Array.from(a.values())}function P(){var e=(0,r.useFlowContext)();return(0,n.useRequest)(function(){return p(function(){return F(this,function(t){switch(t.label){case 0:return[4,e.api.request({url:"dataSources/main/collections:list",params:{paginate:!1,sort:["sort"],filter:{"hidden.$isFalsy":!0},appends:["fields"]}})];case 1:return[2,function(e){var t=(0,i.get)(e,"data.data");if(Array.isArray(t))return t;var r=(0,i.get)(t,"data");return Array.isArray(r)?r:[]}(t.sent())]}})})()})}function T(e){var r=e.editing,n=e.loading,a=e.onChange,l=e.onConfirm,i=e.onEdit,u=e.onExecute,s=e.onValueChange,f=e.t,d=e.value;return c().createElement("div",null,c().createElement(o.Input.TextArea,{disabled:!r,value:d,onChange:function(e){null==s||s(e.target.value),null==a||a(e.target.value)}}),c().createElement(o.Space,{size:8,style:{marginTop:4}},c().createElement(o.Button,{ghost:!0,icon:c().createElement(t.EditOutlined,null),loading:n&&r,size:"small",type:"primary",onClick:r?l:i},f(r?"Confirm":"Edit")),c().createElement(o.Button,{ghost:!0,icon:c().createElement(t.RightSquareOutlined,null),loading:n,size:"small",type:"primary",onClick:u},f("Execute"))))}function M(e){var t=(0,r.useFlowContext)(),a=t.t,l=h((0,u.useState)(function(){return!!e.form.getFieldValue("sql")}),2),s=l[0],f=l[1],d=h((0,u.useState)(function(){return!e.form.getFieldValue("sql")}),2),m=d[0],y=d[1],v=o.Form.useWatch("sql",e.form),b=t.dataSourceManager.collectionFieldInterfaceManager,g=(0,u.useRef)(!1),w=(0,n.useRequest)(function(e){return p(function(){return F(this,function(r){switch(r.label){case 0:return[4,t.api.resource("sqlCollection").execute({values:{sql:e}})];case 1:return[2,j(r.sent())]}})})()},{manual:!0}),q=(0,u.useCallback)(function(t){var r=j(t),n=e.form.getFieldValue("sources")||[],o=e.form.getFieldValue("fields")||[],a=I({currentFields:Array.isArray(o)?o:[],manager:b,preview:r});e.form.setFieldValue("sources",Array.from(new Set(S(Array.isArray(n)?n:[]).concat(S(r.sources||[]))))),e.form.setFieldValue(E,r),e.form.setFieldValue("fields",a)},[b,e.form]),A=(0,u.useCallback)(function(t){var r=(0,i.get)(t,"response.data.errors"),n=(null==r?void 0:r.map(function(e){return e.message}).filter(Boolean).join("\n"))||(0,i.get)(t,"message");e.form.setFieldValue(E,{error:n||a("SQL error")}),f(!1),y(!0)},[e.form,a]),O=(0,u.useCallback)(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return p(function(){var r;return F(this,function(n){switch(n.label){case 0:if(!(r=e.form.getFieldValue("sql")||v))return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,w.runAsync(r)];case 2:return q(n.sent()),t.confirm&&(f(!0),y(!1)),[3,4];case 3:return A(n.sent()),[3,4];case 4:return[2]}})})()},[A,q,e.form,w,v]),C=(0,u.useCallback)(function(){return p(function(){return F(this,function(t){switch(t.label){case 0:if(!e.form.getFieldValue("sql")&&!v)return[2];return[4,O({confirm:!0})];case 1:return t.sent(),[2]}})})()},[e.form,O,v]),x=(0,u.useCallback)(function(){return p(function(){return F(this,function(e){switch(e.label){case 0:return[4,O()];case 1:return e.sent(),[2]}})})()},[O]);return(0,u.useEffect)(function(){!g.current&&"edit"===e.mode&&(e.form.getFieldValue("sql")||v)&&(g.current=!0,p(function(){return F(this,function(e){switch(e.label){case 0:return[4,O({confirm:!0})];case 1:return e.sent(),[2]}})})())},[e.form,e.mode,O,v]),c().createElement(o.Form.Item,{name:"sql",label:a("SQL"),rules:[{required:!0},{validator:function(){return s&&!m?Promise.resolve():Promise.reject(Error(a("Please confirm the SQL statement first")))}}]},c().createElement(T,{editing:m,loading:w.loading,t:a,onValueChange:function(){f(!1),y(!0)},onConfirm:C,onEdit:function(){return y(!0)},onExecute:x}))}function k(e){var t=(0,r.useFlowContext)().t,n=P(),a=o.Form.useWatch("sources",e.form),l=(0,u.useMemo)(function(){return Array.isArray(a)?a:[]},[a]),i=(0,u.useMemo)(function(){var e,r=(e=n.data||[],e.filter(function(e){return e.name}).map(function(e){return{value:e.name,label:(0,s.compileLegacyTemplate)(e.title||e.name,t)}})),o=l.filter(function(e){return!r.some(function(t){return t.value===e})}).map(function(e){return{value:e,label:e}});return S(r).concat(S(o))},[n.data,l,t]);return c().createElement(o.Form.Item,{name:"sources",label:t("Source collections")},c().createElement(o.Select,{mode:"multiple",options:i,loading:n.loading,allowClear:!0}))}function _(e){var t=(0,r.useFlowContext)(),n=t.t,a=P(),l=t.dataSourceManager.collectionFieldInterfaceManager,i=t.dataSourceManager.getDataSource("main"),f=o.Form.useWatch(E,{form:e.form,preserve:!0}),d=(0,u.useMemo)(function(){return j(f)},[f]),m=o.Form.useWatch("sources",e.form),p=o.Form.useWatch("fields",e.form),y=(0,u.useMemo)(function(){return Array.isArray(m)?m:[]},[m]),v=(0,u.useMemo)(function(){return Array.isArray(p)?p:[]},[p]),w=(0,u.useMemo)(function(){var e,t,r,n,o;return r=(null==l||null==(e=l.getFieldInterfaceGroups)?void 0:e.call(l))||{},n=(null==l||null==(t=l.getFieldInterfaces)?void 0:t.call(l))||[],o=new Map,n.filter(function(e){return e.name&&"relation"!==e.group}).forEach(function(e){var t,r=String(e.group||"other"),n=o.get(r)||[];n.push({value:String(e.name),label:e.title||String(e.name),availableTypes:e.availableTypes,defaultType:null==(t=e.default)?void 0:t.type}),o.set(r,n)}),Array.from(o.entries()).sort(function(e,t){var n,o,a,l,i=h(e,1)[0],u=h(t,1)[0];return(null!=(n=null==(a=r[i])?void 0:a.order)?n:0)-(null!=(o=null==(l=r[u])?void 0:l.order)?o:0)}).map(function(e){var t,n=h(e,2),o=n[0],a=n[1];return{label:(null==(t=r[o])?void 0:t.label)||o,options:a}})},[l]),F=(0,u.useMemo)(function(){var e,t,r,o,l;return t=(e={collections:a.data||[],dataSource:i,sources:y,t:n}).collections,r=e.dataSource,o=e.sources,l=e.t,o.map(function(e){return t.find(function(t){return t.name===e})}).filter(Boolean).map(function(e){var t,n=e.name?null==r||null==(t=r.getCollection)?void 0:t.call(r,e.name):void 0,o="function"==typeof(null==n?void 0:n.getFields)?n.getFields():e.fields||[];return{value:e.name,label:(0,s.compileLegacyTemplate)(e.title||(null==n?void 0:n.title)||e.name,l),children:o.map(x).filter(function(e){return e.name&&!q.has(String(e.type))}).map(function(e){var t,r;return{value:e.name,label:(0,s.compileLegacyTemplate)((null==(t=(r=x(e)).uiSchema)?void 0:t.title)||r.title||r.name,l)}})}})},[a.data,i,y,n]),A=(0,u.useRef)();(0,u.useEffect)(function(){if(f&&A.current!==f){A.current=f;var t=I({currentFields:v,manager:l,preview:d});t.length&&e.form.setFieldValue("fields",t)}},[v,l,d,e.form,f]);var O=(0,u.useCallback)(function(t,r){var n=S(v);n.splice(t,1,g(b({},r),{source:C(r.source)})),e.form.setFieldValue("fields",n)},[v,e.form]);if(a.loading)return c().createElement(o.Spin,null);if(null==d?void 0:d.error)return c().createElement(c().Fragment,null,c().createElement(o.Form.Item,{name:"fields",hidden:!0,rules:[{required:!0}]},c().createElement(o.Input,null)),c().createElement(o.Form.Item,{label:n("Fields"),required:!0},c().createElement(o.Alert,{showIcon:!0,message:"".concat(n("SQL error: ")).concat(d.error),type:"error"})));if(!d&&!(null==v?void 0:v.length)||!(null==v?void 0:v.length))return c().createElement(c().Fragment,null,c().createElement(o.Form.Item,{name:"fields",hidden:!0,rules:[{required:!0}]},c().createElement(o.Input,null)),c().createElement(o.Form.Item,{label:n("Fields"),required:!0},c().createElement(o.Alert,{showIcon:!0,message:n("Please use a valid SELECT or WITH AS statement")})));var T=[{title:n("Field name"),dataIndex:"name",width:130},{title:n("Field source"),dataIndex:"source",width:220,render:function(e,t,r){return c().createElement(o.Cascader,{allowClear:!0,options:F,placeholder:n("Select field source"),value:"string"==typeof e?e.split("."):e,onChange:function(e){var n=function(e,t,r){if(null==t?void 0:t.length){var n,o,a=h(t,2),l=a[0],i=a[1],u=null==r||null==(n=r.getCollection)?void 0:n.call(r,l);return("function"==typeof(null==u?void 0:u.getFields)?u.getFields().map(x):(null==(o=e.find(function(e){return e.name===l}))?void 0:o.fields)||[]).find(function(e){return e.name===i})}}(a.data||[],e,i);O(r,g(b({},t),{source:e,interface:(null==n?void 0:n.interface)||t.interface,type:(null==n?void 0:n.type)||t.type,uiSchema:(null==n?void 0:n.uiSchema)||t.uiSchema}))}})}},{title:n("Field interface"),dataIndex:"interface",width:180,render:function(e,t,r){if(t.source){var a,i,u=null==l||null==(i=l.getFieldInterface)?void 0:i.call(l,e);return c().createElement(o.Tag,null,(0,s.compileLegacyTemplate)((null==u?void 0:u.title)||e,n))}return c().createElement(o.Select,{allowClear:!0,popupMatchSelectWidth:!1,style:{width:"100%"},options:(a=t.type,w.map(function(e){return{label:e.label,options:e.options.filter(function(e){var t;return!a||(null==(t=e.availableTypes)?void 0:t.includes(a))||e.defaultType===a})}}).filter(function(e){return e.options.length})).map(function(e){return{label:(0,s.compileLegacyTemplate)(e.label,n),options:e.options.map(function(e){return{value:e.value,label:(0,s.compileLegacyTemplate)(e.label,n)}})}}),value:e||"input",onChange:function(e){var n,o,a,i,u,c,s=null==l||null==(n=l.getFieldInterface)?void 0:n.call(l,e);O(r,g(b({},t),{interface:e||null,type:(null==s||null==(o=s.default)?void 0:o.type)||t.type,uiSchema:g(b({},(null==s||null==(a=s.default)?void 0:a.uiSchema)||{}),{title:(null==s||null==(u=s.default)||null==(i=u.uiSchema)?void 0:i.title)||(null==(c=t.uiSchema)?void 0:c.title)})}))}})}},{title:n("Field display name"),dataIndex:["uiSchema","title"],width:180,render:function(e,t,r){var n;return c().createElement(o.Input,{value:(null==(n=t.uiSchema)?void 0:n.title)||t.name,onChange:function(e){O(r,g(b({},t),{uiSchema:g(b({},t.uiSchema||{}),{title:e.target.value})}))}})}}];return c().createElement(o.Form.Item,{label:n("Fields"),required:!0},c().createElement(o.Form.Item,{name:"fields",hidden:!0,rules:[{required:!0}]},c().createElement(o.Input,null)),c().createElement(o.Table,{bordered:!0,columns:T,dataSource:v,pagination:!1,rowKey:"name",scroll:{y:300},size:"small"}))}function V(e){var t=(0,r.useFlowContext)().t,n=o.Form.useWatch(E,{form:e.form,preserve:!0}),a=(0,u.useMemo)(function(){return j(n)},[n]),l=o.Form.useWatch("fields",e.form),i=(0,u.useMemo)(function(){return Array.isArray(l)?l:[]},[l]),f=(0,u.useMemo)(function(){return i.reduce(function(e,t){if(null==t?void 0:t.name){var r;e[t.name]=(null==(r=t.uiSchema)?void 0:r.title)||t.name}return e},{})},[i]),d=(0,u.useMemo)(function(){var e,t=i.map(function(e){return null==e?void 0:e.name}).filter(function(e){return!!e});return t.length?t:Object.keys((null==a||null==(e=a.data)?void 0:e[0])||{})},[i,null==a?void 0:a.data]),m=(0,u.useMemo)(function(){return d.map(function(e){return{title:(0,s.compileLegacyTemplate)(f[e]||e,t),dataIndex:e,key:e}})},[d,t,f]),p=(0,u.useMemo)(function(){return((null==a?void 0:a.data)||[]).map(function(e,r){return g(b({},Object.entries(e).reduce(function(e,r){var n=h(r,2),o=n[0],a=n[1];return e[o]="string"==typeof a?(0,s.compileLegacyTemplate)(a,t):a,e},{})),{key:r})})},[null==a?void 0:a.data,t]);return c().createElement(o.Form.Item,{label:t("Preview")},c().createElement(o.Table,{bordered:!0,columns:m,dataSource:p,pagination:!1,rowKey:"key",scroll:{x:Math.max(150*m.length,300),y:300}}))}function L(e){var t=b({},e);return delete t[E],Array.isArray(t.fields)&&(t.fields=t.fields.map(function(e){return g(b({},e),{source:C(e.source)})})),t}function B(){return E}function R(t){var n=(0,r.useFlowContext)(),a=n.t,l=o.App.useApp().message,i=h(o.Form.useForm(),1)[0],s=h((0,u.useState)(!1),2),f=s[0],d=s[1];(0,u.useEffect)(function(){i.setFieldsValue(t.collection)},[i,t.collection]),(0,u.useEffect)(function(){var e=!1;return p(function(){var r,o,l,u,c,s;return F(this,function(f){switch(f.label){case 0:if(!(r=t.collection.sql))return[2];f.label=1;case 1:return f.trys.push([1,3,,4]),[4,n.api.resource("sqlCollection").execute({values:{sql:r}})];case 2:if(o=f.sent(),e)return[2];return l=j(o),u=t.collection.sources||[],c=t.collection.fields||[],i.setFieldsValue(y({sources:Array.from(new Set(S(Array.isArray(u)?u:[]).concat(S(Array.isArray(l.sources)?l.sources:[])))),fields:I({currentFields:Array.isArray(c)?c:[],manager:n.dataSourceManager.collectionFieldInterfaceManager,preview:l})},E,l)),[3,4];case 3:var d,m,p,v;return s=f.sent(),e||i.setFieldValue(E,{error:(d=a("SQL error"),(null==s||null==(v=s.response)||null==(p=v.data)||null==(m=p.errors)?void 0:m.map(function(e){return e.message}).filter(Boolean).join("\n"))||(null==s?void 0:s.message)||d)}),[3,4];case 4:return[2]}})})(),function(){e=!0}},[n.api,n.dataSourceManager.collectionFieldInterfaceManager,i,E,t.collection,a]);var m=(0,u.useCallback)(function(){return p(function(){var e,r;return F(this,function(o){switch(o.label){case 0:return[4,i.validateFields()];case 1:e=o.sent(),d(!0),o.label=2;case 2:return o.trys.push([2,,5,6]),[4,n.api.resource("sqlCollection").setFields({filterByTk:t.collection.name,values:{fields:e.fields,sources:e.sources}})];case 3:return o.sent(),[4,null==(r=n.dataSourceManager.getDataSource(t.dataSourceKey))?void 0:r.reload()];case 4:return o.sent(),t.onSubmitted(),l.success(a("Sync successfully")),[3,6];case 5:return d(!1),[7];case 6:return[2]}})})()},[n.api,n.dataSourceManager,i,l,t,a]);return c().createElement(e.DrawerFormLayout,{title:a("Sync from database"),submitting:f,submitText:a("Submit"),cancelText:a("Cancel"),onSubmit:m},c().createElement(o.Form,{form:i,layout:"vertical",initialValues:t.collection},c().createElement(k,{form:i,mode:"edit",template:{title:"",name:"sql"},item:{}}),c().createElement(_,{form:i,mode:"edit",template:{title:"",name:"sql"},item:{}}),c().createElement(V,{form:i,mode:"edit",template:{title:"",name:"sql"},item:{}})))}function W(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function $(e,t,r){return($=K()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&z(o,r.prototype),o}).apply(null,arguments)}function D(e){return(D=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function z(e,t){return(z=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Q(e){var t="function"==typeof Map?new Map:void 0;return(Q=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 $(e,arguments,D(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),z(r,e)})(e)}function K(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(K=function(){return!!e})()}var N=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=D(e),function(e,t){var r;if(t&&("object"==((r=t)&&"u">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,K()?Reflect.construct(e,t||[],D(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&z(r,e),t=[{key:"load",value:function(){var e;return(e=function(){var e,t;return function(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(r){return null==(t=this.app.pm.get("@nocobase/plugin-data-source-manager")||this.app.pm.get("data-source-manager"))||null==(e=t.registerCollectionTemplate)||e.call(t,{name:"sql",title:'{{t("SQL collection")}}',order:40,color:"yellow",divider:!0,collection:{options:{template:"sql"},fields:[]},capabilities:{recordUniqueKey:!0},configure:{items:[{name:"sql",Component:M,required:!0},{name:"sources",Component:k},{name:"fields",Component:_,required:!0},{name:"preview",Component:V}],syncFields:{visible:!0,Component:R},transformSubmitValues:L}}),[2]})},function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){W(a,n,o,l,i,"next",e)}function i(e){W(a,n,o,l,i,"throw",e)}l(void 0)})}).call(this)}}],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)}}(r.prototype,t),r}(Q(e.Plugin)),G=N}(),v}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ahooks"),require("@nocobase/plugin-data-source-manager/client-v2"),require("@nocobase/client-v2"),require("dayjs"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("lodash")):"function"==typeof define&&define.amd?define("@nocobase/plugin-collection-sql/client-v2",["ahooks","@nocobase/plugin-data-source-manager/client-v2","@nocobase/client-v2","dayjs","react","antd","@ant-design/icons","@nocobase/flow-engine","lodash"],t):"object"==typeof exports?exports["@nocobase/plugin-collection-sql/client-v2"]=t(require("ahooks"),require("@nocobase/plugin-data-source-manager/client-v2"),require("@nocobase/client-v2"),require("dayjs"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("lodash")):e["@nocobase/plugin-collection-sql/client-v2"]=t(e.ahooks,e["@nocobase/plugin-data-source-manager/client-v2"],e["@nocobase/client-v2"],e.dayjs,e.react,e.antd,e["@ant-design/icons"],e["@nocobase/flow-engine"],e.lodash)}(self,function(e,t,r,n,o,a,l,i,u){return function(){"use strict";var c={375:function(e){e.exports=l},485:function(e){e.exports=r},694:function(e){e.exports=i},894:function(e){e.exports=t},625:function(t){t.exports=e},59:function(e){e.exports=a},185:function(e){e.exports=n},773:function(e){e.exports=u},155:function(e){e.exports=o}},s={};function f(e){var t=s[e];if(void 0!==t)return t.exports;var r=s[e]={exports:{}};return c[e](r,r.exports,f),r.exports}f.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(t,{a:t}),t},f.d=function(e,t){for(var r in t)f.o(t,r)&&!f.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},f.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.g.importScripts&&(d=f.g.location+"");var d,m=f.g.document;if(!d&&m&&(m.currentScript&&"SCRIPT"===m.currentScript.tagName.toUpperCase()&&(d=m.currentScript.src),!d)){var p=m.getElementsByTagName("script");if(p.length)for(var y=p.length-1;y>-1&&(!d||!/^http(s?):/.test(d));)d=p[y--].src}if(!d)throw Error("Automatic publicPath is not supported in this browser");f.p=d.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/");var v={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src&&(e=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/@nocobase/plugin-collection-sql/dist/client-v2/")}if(!e){var n=window.__nocobase_modern_client_prefix__||"v",o="/"+(n=String(n).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var a=window.location.pathname||"/",l=a.indexOf(o);e=l>=0?a.slice(0,l+1):"/"}e&&(e=e.replace(RegExp("/"+n+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/@nocobase/plugin-collection-sql/dist/client-v2/"}f.p=e}(),!function(){f.r(v),f.d(v,{PluginCollectionSqlClientV2:function(){return N},default:function(){return G},SqlPreviewConfigureItem:function(){return V},SqlFieldsConfigureItem:function(){return k},SqlStatementConfigureItem:function(){return M},SqlSyncFieldsDrawer:function(){return B},buildSqlFieldsFromPreview:function(){return I},getSqlPreviewInternalName:function(){return R},normalizeSqlPreviewResult:function(){return j},SqlSourceCollectionsConfigureItem:function(){return _},normalizeSqlCollectionSubmitValues:function(){return L}});var e=f(485),t=f(375),r=f(694),n=f(625),o=f(59),a=f(185),l=f.n(a),i=f(773),u=f(155),c=f.n(u),s=f(894);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function m(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function p(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){m(a,n,o,l,i,"next",e)}function i(e){m(a,n,o,l,i,"throw",e)}l(void 0)})}}function y(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){y(e,t,r[t])})}return e}function g(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}),e}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||w(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e){return function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||w(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(e,t){if(e){if("string"==typeof e)return d(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return d(e,t)}}function F(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var E=new Set(["hasOne","hasMany","belongsToMany","belongsTo"]),q="__sqlPreview";function A(e){return!!e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"&&!Array.isArray(e)}function O(e){return!!A(e)&&(Array.isArray(e.data)||A(e.fields)||Array.isArray(e.sources)||"string"==typeof e.error)}function j(e){var t=[e,(0,i.get)(e,"data"),(0,i.get)(e,"data.data"),(0,i.get)(e,"data.data.data")].find(O);return t?{data:Array.isArray(t.data)?t.data:[],error:"string"==typeof t.error?t.error:void 0,fields:A(t.fields)?t.fields:{},sources:Array.isArray(t.sources)?t.sources.filter(Boolean):[]}:{data:[],fields:{},sources:[]}}function C(e){return Array.isArray(e)?e.filter(Boolean).join(".")||null:e||null}function x(e){return(null==e?void 0:e.options)||e||{}}function I(e){var t,r=e.currentFields,n=e.manager,o=e.preview,a=new Map,i=(null==o?void 0:o.fields)||{},u=(null==o||null==(t=o.data)?void 0:t[0])||{};return Object.keys(u).length?Object.entries(u).forEach(function(e){var t,r,o=h(e,2),u=o[0],c=o[1],s=i[u],f=(null==s?void 0:s.interface)||("id"===u.toLowerCase()?"id":"number"==typeof c?Number.isInteger(c)?"integer":"number":"boolean"==typeof c?"checkbox":"string"==typeof c&&l()(c).isValid()?"datetime":"input"),d=(null==n||null==(r=n.getFieldInterface)||null==(t=r.call(n,f))?void 0:t.default)||{},m=(null==s?void 0:s.uiSchema)||d.uiSchema||{};a.set(u,{name:u,interface:f,type:(null==s?void 0:s.type)||d.type,source:null==s?void 0:s.source,uiSchema:b({title:u},m)})}):Object.entries(i).forEach(function(e){var t=h(e,2),r=t[0],n=t[1];a.set(r,g(b({name:r,type:"string"},n),{uiSchema:b({title:r},n.uiSchema||{})}))}),(void 0===r?[]:r).forEach(function(e){(null==e?void 0:e.name)&&a.has(e.name)&&a.set(e.name,e)}),Array.from(a.values())}function P(){var e=(0,r.useFlowContext)();return(0,n.useRequest)(function(){return p(function(){return F(this,function(t){switch(t.label){case 0:return[4,e.api.request({url:"dataSources/main/collections:list",params:{paginate:!1,sort:["sort"],filter:{"hidden.$isFalsy":!0},appends:["fields"]}})];case 1:return[2,function(e){var t=(0,i.get)(e,"data.data");if(Array.isArray(t))return t;var r=(0,i.get)(t,"data");return Array.isArray(r)?r:[]}(t.sent())]}})})()})}function T(e){var r=e.editing,n=e.loading,a=e.onChange,l=e.onConfirm,i=e.onEdit,u=e.onExecute,s=e.onValueChange,f=e.t,d=e.value;return c().createElement("div",null,c().createElement(o.Input.TextArea,{disabled:!r,value:d,onChange:function(e){null==s||s(e.target.value),null==a||a(e.target.value)}}),c().createElement(o.Space,{size:8,style:{marginTop:4}},c().createElement(o.Button,{ghost:!0,icon:c().createElement(t.EditOutlined,null),loading:n&&r,size:"small",type:"primary",onClick:r?l:i},f(r?"Confirm":"Edit")),c().createElement(o.Button,{ghost:!0,icon:c().createElement(t.RightSquareOutlined,null),loading:n,size:"small",type:"primary",onClick:u},f("Execute"))))}function M(e){var t=(0,r.useFlowContext)(),a=t.t,l=h((0,u.useState)(function(){return!!e.form.getFieldValue("sql")}),2),s=l[0],f=l[1],d=h((0,u.useState)(function(){return!e.form.getFieldValue("sql")}),2),m=d[0],y=d[1],v=o.Form.useWatch("sql",e.form),b=t.dataSourceManager.collectionFieldInterfaceManager,g=(0,u.useRef)(!1),w=(0,n.useRequest)(function(e){return p(function(){return F(this,function(r){switch(r.label){case 0:return[4,t.api.resource("sqlCollection").execute({values:{sql:e}})];case 1:return[2,j(r.sent())]}})})()},{manual:!0}),E=(0,u.useCallback)(function(t){var r=j(t),n=e.form.getFieldValue("sources")||[],o=e.form.getFieldValue("fields")||[],a=I({currentFields:Array.isArray(o)?o:[],manager:b,preview:r});e.form.setFieldValue("sources",Array.from(new Set(S(Array.isArray(n)?n:[]).concat(S(r.sources||[]))))),e.form.setFieldValue(q,r),e.form.setFieldValue("fields",a)},[b,e.form]),A=(0,u.useCallback)(function(t){var r=(0,i.get)(t,"response.data.errors"),n=(null==r?void 0:r.map(function(e){return e.message}).filter(Boolean).join("\n"))||(0,i.get)(t,"message");e.form.setFieldValue(q,{error:n||a("SQL error")}),f(!1),y(!0)},[e.form,a]),O=(0,u.useCallback)(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return p(function(){var r;return F(this,function(n){switch(n.label){case 0:if(!(r=e.form.getFieldValue("sql")||v))return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,w.runAsync(r)];case 2:return E(n.sent()),t.confirm&&(f(!0),y(!1)),[3,4];case 3:return A(n.sent()),[3,4];case 4:return[2]}})})()},[A,E,e.form,w,v]),C=(0,u.useCallback)(function(){return p(function(){return F(this,function(t){switch(t.label){case 0:if(!e.form.getFieldValue("sql")&&!v)return[2];return[4,O({confirm:!0})];case 1:return t.sent(),[2]}})})()},[e.form,O,v]),x=(0,u.useCallback)(function(){return p(function(){return F(this,function(e){switch(e.label){case 0:return[4,O()];case 1:return e.sent(),[2]}})})()},[O]);return(0,u.useEffect)(function(){!g.current&&"edit"===e.mode&&(e.form.getFieldValue("sql")||v)&&(g.current=!0,p(function(){return F(this,function(e){switch(e.label){case 0:return[4,O({confirm:!0})];case 1:return e.sent(),[2]}})})())},[e.form,e.mode,O,v]),c().createElement(o.Form.Item,{name:"sql",label:a("SQL"),rules:[{required:!0},{validator:function(){return s&&!m?Promise.resolve():Promise.reject(Error(a("Please confirm the SQL statement first")))}}]},c().createElement(T,{editing:m,loading:w.loading,t:a,onValueChange:function(){f(!1),y(!0)},onConfirm:C,onEdit:function(){return y(!0)},onExecute:x}))}function _(e){var t=(0,r.useFlowContext)().t,n=P(),a=o.Form.useWatch("sources",e.form),l=(0,u.useMemo)(function(){return Array.isArray(a)?a:[]},[a]),i=(0,u.useMemo)(function(){var e,r=(e=n.data||[],e.filter(function(e){return e.name}).map(function(e){return{value:e.name,label:(0,s.compileLegacyTemplate)(e.title||e.name,t)}})),o=l.filter(function(e){return!r.some(function(t){return t.value===e})}).map(function(e){return{value:e,label:e}});return S(r).concat(S(o))},[n.data,l,t]);return c().createElement(o.Form.Item,{name:"sources",label:t("Source collections")},c().createElement(o.Select,{mode:"multiple",options:i,loading:n.loading,allowClear:!0}))}function k(e){var t=(0,r.useFlowContext)(),n=t.t,a=P(),l=t.dataSourceManager.collectionFieldInterfaceManager,i=t.dataSourceManager.getDataSource("main"),f=o.Form.useWatch(q,{form:e.form,preserve:!0}),d=(0,u.useMemo)(function(){return j(f)},[f]),m=o.Form.useWatch("sources",e.form),p=o.Form.useWatch("fields",e.form),y=(0,u.useMemo)(function(){return Array.isArray(m)?m:[]},[m]),v=(0,u.useMemo)(function(){return Array.isArray(p)?p:[]},[p]),w=(0,u.useMemo)(function(){var e,t,r,n,o;return r=(null==l||null==(e=l.getFieldInterfaceGroups)?void 0:e.call(l))||{},n=(null==l||null==(t=l.getFieldInterfaces)?void 0:t.call(l))||[],o=new Map,n.filter(function(e){return e.name&&"relation"!==e.group}).forEach(function(e){var t,r=String(e.group||"other"),n=o.get(r)||[];n.push({value:String(e.name),label:e.title||String(e.name),availableTypes:e.availableTypes,defaultType:null==(t=e.default)?void 0:t.type}),o.set(r,n)}),Array.from(o.entries()).sort(function(e,t){var n,o,a,l,i=h(e,1)[0],u=h(t,1)[0];return(null!=(n=null==(a=r[i])?void 0:a.order)?n:0)-(null!=(o=null==(l=r[u])?void 0:l.order)?o:0)}).map(function(e){var t,n=h(e,2),o=n[0],a=n[1];return{label:(null==(t=r[o])?void 0:t.label)||o,options:a}})},[l]),F=(0,u.useMemo)(function(){var e,t,r,o,l;return t=(e={collections:a.data||[],dataSource:i,sources:y,t:n}).collections,r=e.dataSource,o=e.sources,l=e.t,o.map(function(e){return t.find(function(t){return t.name===e})}).filter(Boolean).map(function(e){var t,n=e.name?null==r||null==(t=r.getCollection)?void 0:t.call(r,e.name):void 0,o="function"==typeof(null==n?void 0:n.getFields)?n.getFields():e.fields||[];return{value:e.name,label:(0,s.compileLegacyTemplate)(e.title||(null==n?void 0:n.title)||e.name,l),children:o.map(x).filter(function(e){return e.name&&!E.has(String(e.type))}).map(function(e){var t,r;return{value:e.name,label:(0,s.compileLegacyTemplate)((null==(t=(r=x(e)).uiSchema)?void 0:t.title)||r.title||r.name,l)}})}})},[a.data,i,y,n]),A=(0,u.useRef)();(0,u.useEffect)(function(){if(f&&A.current!==f){A.current=f;var t=I({currentFields:v,manager:l,preview:d});t.length&&e.form.setFieldValue("fields",t)}},[v,l,d,e.form,f]);var O=(0,u.useCallback)(function(t,r){var n=S(v);n.splice(t,1,g(b({},r),{source:C(r.source)})),e.form.setFieldValue("fields",n)},[v,e.form]);if(a.loading)return c().createElement(o.Spin,null);if(null==d?void 0:d.error)return c().createElement(c().Fragment,null,c().createElement(o.Form.Item,{name:"fields",hidden:!0,rules:[{required:!0}]},c().createElement(o.Input,null)),c().createElement(o.Form.Item,{label:n("Fields"),required:!0},c().createElement(o.Alert,{showIcon:!0,message:"".concat(n("SQL error: ")).concat(d.error),type:"error"})));if(!d&&!(null==v?void 0:v.length)||!(null==v?void 0:v.length))return c().createElement(c().Fragment,null,c().createElement(o.Form.Item,{name:"fields",hidden:!0,rules:[{required:!0}]},c().createElement(o.Input,null)),c().createElement(o.Form.Item,{label:n("Fields"),required:!0},c().createElement(o.Alert,{showIcon:!0,message:n("Please use a valid SELECT or WITH AS statement")})));var T=[{title:n("Field name"),dataIndex:"name",width:130},{title:n("Field source"),dataIndex:"source",width:220,render:function(e,t,r){return c().createElement(o.Cascader,{allowClear:!0,options:F,placeholder:n("Select field source"),value:"string"==typeof e?e.split("."):e,onChange:function(e){var n=function(e,t,r){if(null==t?void 0:t.length){var n,o,a=h(t,2),l=a[0],i=a[1],u=null==r||null==(n=r.getCollection)?void 0:n.call(r,l);return("function"==typeof(null==u?void 0:u.getFields)?u.getFields().map(x):(null==(o=e.find(function(e){return e.name===l}))?void 0:o.fields)||[]).find(function(e){return e.name===i})}}(a.data||[],e,i);O(r,g(b({},t),{source:e,interface:(null==n?void 0:n.interface)||t.interface,type:(null==n?void 0:n.type)||t.type,uiSchema:(null==n?void 0:n.uiSchema)||t.uiSchema}))}})}},{title:n("Field interface"),dataIndex:"interface",width:180,render:function(e,t,r){if(t.source){var a,i,u=null==l||null==(i=l.getFieldInterface)?void 0:i.call(l,e);return c().createElement(o.Tag,null,(0,s.compileLegacyTemplate)((null==u?void 0:u.title)||e,n))}return c().createElement(o.Select,{allowClear:!0,popupMatchSelectWidth:!1,style:{width:"100%"},options:(a=t.type,w.map(function(e){return{label:e.label,options:e.options.filter(function(e){var t;return!a||(null==(t=e.availableTypes)?void 0:t.includes(a))||e.defaultType===a})}}).filter(function(e){return e.options.length})).map(function(e){return{label:(0,s.compileLegacyTemplate)(e.label,n),options:e.options.map(function(e){return{value:e.value,label:(0,s.compileLegacyTemplate)(e.label,n)}})}}),value:e||"input",onChange:function(e){var n,o,a,i,u,c,s=null==l||null==(n=l.getFieldInterface)?void 0:n.call(l,e);O(r,g(b({},t),{interface:e||null,type:(null==s||null==(o=s.default)?void 0:o.type)||t.type,uiSchema:g(b({},(null==s||null==(a=s.default)?void 0:a.uiSchema)||{}),{title:(null==s||null==(u=s.default)||null==(i=u.uiSchema)?void 0:i.title)||(null==(c=t.uiSchema)?void 0:c.title)})}))}})}},{title:n("Field display name"),dataIndex:["uiSchema","title"],width:180,render:function(e,t,r){var n;return c().createElement(o.Input,{value:(null==(n=t.uiSchema)?void 0:n.title)||t.name,onChange:function(e){O(r,g(b({},t),{uiSchema:g(b({},t.uiSchema||{}),{title:e.target.value})}))}})}}];return c().createElement(o.Form.Item,{label:n("Fields"),required:!0},c().createElement(o.Form.Item,{name:"fields",hidden:!0,rules:[{required:!0}]},c().createElement(o.Input,null)),c().createElement(o.Table,{bordered:!0,columns:T,dataSource:v,pagination:!1,rowKey:"name",scroll:{y:300},size:"small"}))}function V(e){var t=(0,r.useFlowContext)().t,n=o.Form.useWatch(q,{form:e.form,preserve:!0}),a=(0,u.useMemo)(function(){return j(n)},[n]),l=o.Form.useWatch("fields",e.form),i=(0,u.useMemo)(function(){return Array.isArray(l)?l:[]},[l]),f=(0,u.useMemo)(function(){return i.reduce(function(e,t){if(null==t?void 0:t.name){var r;e[t.name]=(null==(r=t.uiSchema)?void 0:r.title)||t.name}return e},{})},[i]),d=(0,u.useMemo)(function(){var e,t=i.map(function(e){return null==e?void 0:e.name}).filter(function(e){return!!e});return t.length?t:Object.keys((null==a||null==(e=a.data)?void 0:e[0])||{})},[i,null==a?void 0:a.data]),m=(0,u.useMemo)(function(){return d.map(function(e){return{title:(0,s.compileLegacyTemplate)(f[e]||e,t),dataIndex:e,key:e}})},[d,t,f]),p=(0,u.useMemo)(function(){return((null==a?void 0:a.data)||[]).map(function(e,r){return g(b({},Object.entries(e).reduce(function(e,r){var n=h(r,2),o=n[0],a=n[1];return e[o]="string"==typeof a?(0,s.compileLegacyTemplate)(a,t):a,e},{})),{key:r})})},[null==a?void 0:a.data,t]);return c().createElement(o.Form.Item,{label:t("Preview")},c().createElement(o.Table,{bordered:!0,columns:m,dataSource:p,pagination:!1,rowKey:"key",scroll:{x:Math.max(150*m.length,300),y:300}}))}function L(e){var t=b({},e);return delete t[q],Array.isArray(t.fields)&&(t.fields=t.fields.map(function(e){return g(b({},e),{source:C(e.source)})})),t}function R(){return q}function B(t){var n=(0,r.useFlowContext)(),a=n.t,l=o.App.useApp().message,i=h(o.Form.useForm(),1)[0],s=h((0,u.useState)(!1),2),f=s[0],d=s[1];(0,u.useEffect)(function(){i.setFieldsValue(t.collection)},[i,t.collection]),(0,u.useEffect)(function(){var e=!1;return p(function(){var r,o,l,u,c,s;return F(this,function(f){switch(f.label){case 0:if(!(r=t.collection.sql))return[2];f.label=1;case 1:return f.trys.push([1,3,,4]),[4,n.api.resource("sqlCollection").execute({values:{sql:r}})];case 2:if(o=f.sent(),e)return[2];return l=j(o),u=t.collection.sources||[],c=t.collection.fields||[],i.setFieldsValue(y({sources:Array.from(new Set(S(Array.isArray(u)?u:[]).concat(S(Array.isArray(l.sources)?l.sources:[])))),fields:I({currentFields:Array.isArray(c)?c:[],manager:n.dataSourceManager.collectionFieldInterfaceManager,preview:l})},q,l)),[3,4];case 3:var d,m,p,v;return s=f.sent(),e||i.setFieldValue(q,{error:(d=a("SQL error"),(null==s||null==(v=s.response)||null==(p=v.data)||null==(m=p.errors)?void 0:m.map(function(e){return e.message}).filter(Boolean).join("\n"))||(null==s?void 0:s.message)||d)}),[3,4];case 4:return[2]}})})(),function(){e=!0}},[n.api,n.dataSourceManager.collectionFieldInterfaceManager,i,q,t.collection,a]);var m=(0,u.useCallback)(function(){return p(function(){var e,r;return F(this,function(o){switch(o.label){case 0:return[4,i.validateFields()];case 1:e=o.sent(),d(!0),o.label=2;case 2:return o.trys.push([2,,5,6]),[4,n.api.resource("sqlCollection").setFields({filterByTk:t.collection.name,values:{fields:e.fields,sources:e.sources}})];case 3:return o.sent(),[4,null==(r=n.dataSourceManager.getDataSource(t.dataSourceKey))?void 0:r.reload()];case 4:return o.sent(),t.onSubmitted(),l.success(a("Sync successfully")),[3,6];case 5:return d(!1),[7];case 6:return[2]}})})()},[n.api,n.dataSourceManager,i,l,t,a]);return c().createElement(e.DrawerFormLayout,{title:a("Sync from database"),submitting:f,submitText:a("Submit"),cancelText:a("Cancel"),onSubmit:m},c().createElement(o.Form,{form:i,layout:"vertical",initialValues:t.collection},c().createElement(_,{form:i,mode:"edit",template:{title:"",name:"sql"},item:{}}),c().createElement(k,{form:i,mode:"edit",template:{title:"",name:"sql"},item:{}}),c().createElement(V,{form:i,mode:"edit",template:{title:"",name:"sql"},item:{}})))}function $(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function W(e,t,r){return(W=K()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&z(o,r.prototype),o}).apply(null,arguments)}function D(e){return(D=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function z(e,t){return(z=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Q(e){var t="function"==typeof Map?new Map:void 0;return(Q=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 W(e,arguments,D(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),z(r,e)})(e)}function K(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(K=function(){return!!e})()}var N=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=D(e),function(e,t){var r;if(t&&("object"==((r=t)&&"u">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,K()?Reflect.construct(e,t||[],D(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&z(r,e),t=[{key:"load",value:function(){var e;return(e=function(){var e,t;return function(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(r){return null==(t=this.app.pm.get("@nocobase/plugin-data-source-manager")||this.app.pm.get("data-source-manager"))||null==(e=t.registerCollectionTemplate)||e.call(t,{name:"sql",title:'{{t("SQL collection")}}',order:40,color:"yellow",divider:!0,collection:{options:{template:"sql"},fields:[]},capabilities:{recordUniqueKey:!0},configure:{items:[{name:"sql",Component:M,required:!0},{name:"sources",Component:_},{name:"fields",Component:k,required:!0},{name:"preview",Component:V}],syncFields:{visible:!0,Component:B},transformSubmitValues:L}}),[2]})},function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){$(a,n,o,l,i,"next",e)}function i(e){$(a,n,o,l,i,"throw",e)}l(void 0)})}).call(this)}}],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)}}(r.prototype,t),r}(Q(e.Plugin)),G=N}(),v}()});
@@ -8,20 +8,20 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.1.0-beta.43",
11
+ "@nocobase/client": "2.1.0-beta.45",
12
12
  "@ant-design/icons": "5.6.1",
13
- "@nocobase/client-v2": "2.1.0-beta.43",
14
- "@nocobase/flow-engine": "2.1.0-beta.43",
15
- "@nocobase/plugin-data-source-manager": "2.1.0-beta.43",
13
+ "@nocobase/client-v2": "2.1.0-beta.45",
14
+ "@nocobase/flow-engine": "2.1.0-beta.45",
15
+ "@nocobase/plugin-data-source-manager": "2.1.0-beta.45",
16
16
  "ahooks": "3.7.8",
17
17
  "antd": "5.24.2",
18
18
  "dayjs": "1.11.13",
19
19
  "lodash": "4.18.1",
20
20
  "react": "18.2.0",
21
- "@nocobase/data-source-manager": "2.1.0-beta.43",
22
- "@nocobase/database": "2.1.0-beta.43",
23
- "@nocobase/server": "2.1.0-beta.43",
24
- "@nocobase/actions": "2.1.0-beta.43",
21
+ "@nocobase/data-source-manager": "2.1.0-beta.45",
22
+ "@nocobase/database": "2.1.0-beta.45",
23
+ "@nocobase/server": "2.1.0-beta.45",
24
+ "@nocobase/actions": "2.1.0-beta.45",
25
25
  "sequelize": "6.35.2",
26
- "@nocobase/utils": "2.1.0-beta.43"
26
+ "@nocobase/utils": "2.1.0-beta.45"
27
27
  };
@@ -44,6 +44,13 @@ const checkSQL = (sql) => {
44
44
  "pg_reload_conf",
45
45
  "pg_sleep",
46
46
  "generate_series",
47
+ "pg_catalog",
48
+ "pg_shadow",
49
+ "pg_authid",
50
+ "pg_auth_members",
51
+ "pg_roles",
52
+ "pg_stat_activity",
53
+ "information_schema",
47
54
  // MySQL
48
55
  "LOAD_FILE",
49
56
  "BENCHMARK",
@@ -53,7 +60,7 @@ const checkSQL = (sql) => {
53
60
  "sqlite3_load_extension",
54
61
  "load_extension"
55
62
  ];
56
- sql = sql.trim().split(";").shift();
63
+ sql = sql.trim().split(";").shift() || "";
57
64
  if (!/^select/i.test(sql) && !/^with([\s\S]+)select([\s\S]+)/i.test(sql)) {
58
65
  throw new Error("Only supports SELECT statements or WITH clauses");
59
66
  }
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "Provides SQL collection template",
7
7
  "description.ru-RU": "Предоставляет шаблон коллекции на основе SQL",
8
8
  "description.zh-CN": "提供 SQL 数据表模板",
9
- "version": "2.1.0-beta.43",
9
+ "version": "2.1.0-beta.45",
10
10
  "homepage": "https://docs-cn.nocobase.com/handbook/collection-sql",
11
11
  "homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/collection-sql",
12
12
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/collection-sql",
@@ -23,5 +23,5 @@
23
23
  "keywords": [
24
24
  "Collections"
25
25
  ],
26
- "gitHead": "6d7750e2373bf2451d246de88cc1f62491685e18"
26
+ "gitHead": "42587115fc34c3eb01ef2b2549f1c998e5708318"
27
27
  }