@nocobase/plugin-collection-sql 2.1.0-beta.9 → 2.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client-v2.d.ts +2 -0
- package/client-v2.js +3 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/SqlCollectionConfigure.d.ts +63 -0
- package/dist/client-v2/index.d.ts +11 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/client-v2/plugin.d.ts +13 -0
- package/dist/externalVersion.js +15 -6
- package/dist/server/resources/sql.js +8 -0
- package/dist/server/utils.js +8 -1
- package/package.json +5 -2
package/client-v2.d.ts
ADDED
package/client-v2.js
ADDED
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e
|
|
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}()});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import type { CollectionTemplateConfigureItemProps, CollectionTemplateSyncFieldsProps } from '@nocobase/plugin-data-source-manager/client-v2';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
export type SqlPreviewField = {
|
|
12
|
+
collection?: string;
|
|
13
|
+
interface?: string;
|
|
14
|
+
source?: string | string[];
|
|
15
|
+
type?: string;
|
|
16
|
+
uiSchema?: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
export type SqlPreviewResult = {
|
|
19
|
+
data?: Array<Record<string, unknown>>;
|
|
20
|
+
error?: string;
|
|
21
|
+
fields?: Record<string, SqlPreviewField>;
|
|
22
|
+
sources?: string[];
|
|
23
|
+
};
|
|
24
|
+
export type SqlFieldRecord = {
|
|
25
|
+
interface?: string;
|
|
26
|
+
name: string;
|
|
27
|
+
source?: string | string[] | null;
|
|
28
|
+
type?: string;
|
|
29
|
+
uiSchema?: Record<string, unknown>;
|
|
30
|
+
};
|
|
31
|
+
type FieldInterfaceRecord = {
|
|
32
|
+
default?: {
|
|
33
|
+
type?: string;
|
|
34
|
+
uiSchema?: Record<string, unknown>;
|
|
35
|
+
};
|
|
36
|
+
name?: string;
|
|
37
|
+
title?: React.ReactNode;
|
|
38
|
+
availableTypes?: string[];
|
|
39
|
+
};
|
|
40
|
+
type FieldInterfaceManager = {
|
|
41
|
+
getFieldInterface?: (name?: string) => FieldInterfaceRecord | undefined;
|
|
42
|
+
getFieldInterfaceGroups?: () => Record<string, {
|
|
43
|
+
label?: React.ReactNode;
|
|
44
|
+
order?: number;
|
|
45
|
+
}>;
|
|
46
|
+
getFieldInterfaces?: () => Array<Record<string, unknown>>;
|
|
47
|
+
};
|
|
48
|
+
export declare function normalizeSqlPreviewResult(value: unknown): SqlPreviewResult;
|
|
49
|
+
export declare function buildSqlFieldsFromPreview(options: {
|
|
50
|
+
currentFields?: SqlFieldRecord[];
|
|
51
|
+
manager?: FieldInterfaceManager;
|
|
52
|
+
preview?: SqlPreviewResult;
|
|
53
|
+
}): SqlFieldRecord[];
|
|
54
|
+
export declare function SqlStatementConfigureItem(props: CollectionTemplateConfigureItemProps): React.JSX.Element;
|
|
55
|
+
export declare function SqlSourceCollectionsConfigureItem(props: CollectionTemplateConfigureItemProps): React.JSX.Element;
|
|
56
|
+
export declare function SqlFieldsConfigureItem(props: CollectionTemplateConfigureItemProps): React.JSX.Element;
|
|
57
|
+
export declare function SqlPreviewConfigureItem(props: CollectionTemplateConfigureItemProps): React.JSX.Element;
|
|
58
|
+
export declare function normalizeSqlCollectionSubmitValues(values: Record<string, unknown>): {
|
|
59
|
+
[x: string]: unknown;
|
|
60
|
+
};
|
|
61
|
+
export declare function getSqlPreviewInternalName(): string;
|
|
62
|
+
export declare function SqlSyncFieldsDrawer(props: CollectionTemplateSyncFieldsProps): React.JSX.Element;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export { default } from './plugin';
|
|
10
|
+
export * from './plugin';
|
|
11
|
+
export * from './SqlCollectionConfigure';
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
!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 G},default:function(){return U},SqlPreviewConfigureItem:function(){return L},SqlFieldsConfigureItem:function(){return V},SqlStatementConfigureItem:function(){return M},SqlSyncFieldsDrawer:function(){return $},buildSqlFieldsFromPreview:function(){return P},getSqlPreviewInternalName:function(){return B},normalizeSqlPreviewResult:function(){return O},SqlSourceCollectionsConfigureItem:function(){return _},normalizeSqlCollectionSubmitValues:function(){return R}});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 C(e){return!!A(e)&&(Array.isArray(e.data)||A(e.fields)||Array.isArray(e.sources)||"string"==typeof e.error)}function O(e){var t=[e,(0,i.get)(e,"data"),(0,i.get)(e,"data.data"),(0,i.get)(e,"data.data.data")].find(C);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 j(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){return"string"==typeof e?e:void 0}function P(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 T(){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 k(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,{autoSize:{minRows:5},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=I(e.form.getFieldValue("sql")),s=h((0,u.useState)(function(){return!l}),2),f=s[0],d=s[1],m=o.Form.useWatch("sql",e.form),y=t.dataSourceManager.collectionFieldInterfaceManager,v=(0,u.useRef)(!1),b=(0,u.useRef)(l),g=(0,u.useRef)(!l),w=(0,u.useCallback)(function(){g.current=!0,d(!0)},[]),q=(0,u.useCallback)(function(){b.current=void 0,g.current=!0,d(!0)},[]),A=(0,u.useCallback)(function(t){b.current=t,g.current=!1,d(!1),e.form.setFields([{name:"sql",errors:[]}])},[e.form]),C=(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,O(r.sent())]}})})()},{manual:!0}),j=(0,u.useCallback)(function(t){var r=O(t),n=e.form.getFieldValue("sources")||[],o=e.form.getFieldValue("fields")||[],a=P({currentFields:Array.isArray(o)?o:[],manager:y,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)},[y,e.form]),x=(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")}),q()},[q,e.form,a]),T=(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=I(e.form.getFieldValue("sql"))||I(m)))return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,C.runAsync(r)];case 2:return j(n.sent()),t.confirm&&A(r),[3,4];case 3:return x(n.sent()),[3,4];case 4:return[2]}})})()},[x,j,A,e.form,C,m]),M=(0,u.useCallback)(function(){return p(function(){return F(this,function(t){switch(t.label){case 0:if(!I(e.form.getFieldValue("sql"))&&!I(m))return[2];return[4,T({confirm:!0})];case 1:return t.sent(),[2]}})})()},[e.form,T,m]),_=(0,u.useCallback)(function(){return p(function(){return F(this,function(e){switch(e.label){case 0:return[4,T()];case 1:return e.sent(),[2]}})})()},[T]);return(0,u.useEffect)(function(){!v.current&&"edit"===e.mode&&(I(e.form.getFieldValue("sql"))||I(m))&&(v.current=!0,p(function(){return F(this,function(e){switch(e.label){case 0:return[4,T({confirm:!0})];case 1:return e.sent(),[2]}})})())},[e.form,e.mode,T,m]),c().createElement(o.Form.Item,{name:"sql",label:a("SQL"),rules:[{required:!0},{validator:function(){var t=I(e.form.getFieldValue("sql"))||I(m);return t&&b.current===t&&!g.current?Promise.resolve():Promise.reject(Error(a("Please confirm the SQL statement first")))}}]},c().createElement(k,{editing:f,loading:C.loading,t:a,onValueChange:q,onConfirm:M,onEdit:w,onExecute:_}))}function _(e){var t=(0,r.useFlowContext)().t,n=T(),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 V(e){var t=(0,r.useFlowContext)(),n=t.t,a=T(),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 O(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=P({currentFields:v,manager:l,preview:d});t.length&&e.form.setFieldValue("fields",t)}},[v,l,d,e.form,f]);var C=(0,u.useCallback)(function(t,r){var n=S(v);n.splice(t,1,g(b({},r),{source:j(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 I=[{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);C(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);C(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){C(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:I,dataSource:v,pagination:!1,rowKey:"name",scroll:{y:300},size:"small"}))}function L(e){var t=(0,r.useFlowContext)().t,n=o.Form.useWatch(E,{form:e.form,preserve:!0}),a=(0,u.useMemo)(function(){return O(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 R(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:j(e.source)})})),t}function B(){return E}function $(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=O(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:P({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(_,{form:i,mode:"edit",template:{title:"",name:"sql"},item:{}}),c().createElement(V,{form:i,mode:"edit",template:{title:"",name:"sql"},item:{}}),c().createElement(L,{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 D(e,t,r){return(D=N()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&Q(o,r.prototype),o}).apply(null,arguments)}function z(e){return(z=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Q(e,t){return(Q=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function K(e){var t="function"==typeof Map?new Map:void 0;return(K=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 D(e,arguments,z(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),Q(r,e)})(e)}function N(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(N=function(){return!!e})()}var G=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=z(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,N()?Reflect.construct(e,t||[],z(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&Q(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",collection:{options:{template:"sql"},fields:[]},capabilities:{recordUniqueKey:!0},configure:{items:[{name:"sql",Component:M,required:!0},{name:"sources",Component:_},{name:"fields",Component:V,required:!0},{name:"preview",Component:L}],syncFields:{visible:!0,Component:$},transformSubmitValues:R}}),[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}(K(e.Plugin)),U=G}(),v}()});
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { Application, Plugin } from '@nocobase/client-v2';
|
|
10
|
+
export declare class PluginCollectionSqlClientV2 extends Plugin<any, Application> {
|
|
11
|
+
load(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export default PluginCollectionSqlClientV2;
|
package/dist/externalVersion.js
CHANGED
|
@@ -8,11 +8,20 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "2.
|
|
12
|
-
"@
|
|
13
|
-
"@nocobase/
|
|
14
|
-
"@nocobase/
|
|
15
|
-
"@nocobase/
|
|
11
|
+
"@nocobase/client": "2.2.0-alpha.1",
|
|
12
|
+
"@ant-design/icons": "5.6.1",
|
|
13
|
+
"@nocobase/client-v2": "2.2.0-alpha.1",
|
|
14
|
+
"@nocobase/flow-engine": "2.2.0-alpha.1",
|
|
15
|
+
"@nocobase/plugin-data-source-manager": "2.2.0-alpha.1",
|
|
16
|
+
"ahooks": "3.7.8",
|
|
17
|
+
"antd": "5.24.2",
|
|
18
|
+
"dayjs": "1.11.13",
|
|
19
|
+
"lodash": "4.18.1",
|
|
20
|
+
"react": "18.2.0",
|
|
21
|
+
"@nocobase/data-source-manager": "2.2.0-alpha.1",
|
|
22
|
+
"@nocobase/database": "2.2.0-alpha.1",
|
|
23
|
+
"@nocobase/server": "2.2.0-alpha.1",
|
|
24
|
+
"@nocobase/actions": "2.2.0-alpha.1",
|
|
16
25
|
"sequelize": "6.35.2",
|
|
17
|
-
"@nocobase/utils": "2.
|
|
26
|
+
"@nocobase/utils": "2.2.0-alpha.1"
|
|
18
27
|
};
|
|
@@ -111,6 +111,14 @@ var sql_default = {
|
|
|
111
111
|
await next();
|
|
112
112
|
},
|
|
113
113
|
update: async (ctx, next) => {
|
|
114
|
+
const { sql } = ctx.action.params.values || {};
|
|
115
|
+
if (sql) {
|
|
116
|
+
try {
|
|
117
|
+
(0, import_utils.checkSQL)(sql);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
ctx.throw(400, ctx.t(e.message));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
114
122
|
const transaction = await ctx.app.db.sequelize.transaction();
|
|
115
123
|
try {
|
|
116
124
|
const { upRes } = await updateCollection(ctx, transaction);
|
package/dist/server/utils.js
CHANGED
|
@@ -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.
|
|
9
|
+
"version": "2.2.0-alpha.1",
|
|
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",
|
|
@@ -14,11 +14,14 @@
|
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"@nocobase/client": "2.x",
|
|
17
|
+
"@nocobase/client-v2": "2.x",
|
|
18
|
+
"@nocobase/flow-engine": "2.x",
|
|
19
|
+
"@nocobase/plugin-data-source-manager": "2.x",
|
|
17
20
|
"@nocobase/server": "2.x",
|
|
18
21
|
"@nocobase/test": "2.x"
|
|
19
22
|
},
|
|
20
23
|
"keywords": [
|
|
21
24
|
"Collections"
|
|
22
25
|
],
|
|
23
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "303663aba6c6eefa27e6a6435b4c0352074ec40f"
|
|
24
27
|
}
|