@tachybase/plugin-data-source-common 0.23.8 → 0.23.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/features/rest-api/form-data-source/DataSourceSettingsForm.schema.d.ts +5 -1
- package/dist/client/index.js +9 -9
- package/dist/externalVersion.js +8 -8
- package/dist/server/http/services/http-collection-manager.d.ts +4 -1
- package/dist/server/http/services/http-collection-manager.js +2 -0
- package/dist/server/http/services/http-collection.d.ts +10 -1
- package/dist/server/http/services/http-collection.js +4 -5
- package/dist/server/http/services/http-data-source.js +1 -1
- package/dist/server/plugin.js +2 -0
- package/package.json +13 -13
- package/.turbo/turbo-build.log +0 -14
|
@@ -27,7 +27,11 @@ export declare const schemaDataSourceSettingsForm: {
|
|
|
27
27
|
required: boolean;
|
|
28
28
|
'x-decorator': string;
|
|
29
29
|
'x-component': string;
|
|
30
|
-
'x-validator':
|
|
30
|
+
'x-validator': {
|
|
31
|
+
type: string;
|
|
32
|
+
pattern: RegExp;
|
|
33
|
+
message: string;
|
|
34
|
+
};
|
|
31
35
|
};
|
|
32
36
|
headers: {
|
|
33
37
|
type: string;
|
package/dist/client/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(m,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("@tachybase/client"),require("@tachybase/module-data-source/client"),require("react/jsx-runtime"),require("react"),require("@ant-design/icons"),require("antd"),require("@tachybase/components"),require("@tachybase/schema"),require("lodash"),require("@tachybase/utils/client"),require("react-router-dom")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/module-data-source/client","react/jsx-runtime","react","@ant-design/icons","antd","@tachybase/components","@tachybase/schema","lodash","@tachybase/utils/client","react-router-dom"],r):(m=typeof globalThis!="undefined"?globalThis:m||self,r(m["@tachybase/plugin-data-source-common"]={},m["@tachybase/client"],m["@tachybase/module-data-source"],m.jsxRuntime,m.react,m["@ant-design/icons"],m.antd,m["@tachybase/components"],m["@tachybase/schema"],m.lodash,m["@tachybase/utils"],m["react-router-dom"]))})(this,function(m,r,q,c,I,R,h,k,y,V,X,
|
|
1
|
+
(function(m,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("@tachybase/client"),require("@tachybase/module-data-source/client"),require("react/jsx-runtime"),require("react"),require("@ant-design/icons"),require("antd"),require("@tachybase/components"),require("@tachybase/schema"),require("lodash"),require("@tachybase/utils/client"),require("react-router-dom")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/module-data-source/client","react/jsx-runtime","react","@ant-design/icons","antd","@tachybase/components","@tachybase/schema","lodash","@tachybase/utils/client","react-router-dom"],r):(m=typeof globalThis!="undefined"?globalThis:m||self,r(m["@tachybase/plugin-data-source-common"]={},m["@tachybase/client"],m["@tachybase/module-data-source"],m.jsxRuntime,m.react,m["@ant-design/icons"],m.antd,m["@tachybase/components"],m["@tachybase/schema"],m.lodash,m["@tachybase/utils"],m["react-router-dom"]))})(this,function(m,r,q,c,I,R,h,k,y,V,X,H){"use strict";var gt=Object.defineProperty,It=Object.defineProperties;var vt=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var ce=(m,r,q)=>r in m?gt(m,r,{enumerable:!0,configurable:!0,writable:!0,value:q}):m[r]=q,f=(m,r)=>{for(var q in r||(r={}))ie.call(r,q)&&ce(m,q,r[q]);if(U)for(var q of U(r))pe.call(r,q)&&ce(m,q,r[q]);return m},A=(m,r)=>It(m,vt(r));var le=(m,r)=>{var q={};for(var c in m)ie.call(m,c)&&r.indexOf(c)<0&&(q[c]=m[c]);if(m!=null&&U)for(var c of U(m))r.indexOf(c)<0&&pe.call(m,c)&&(q[c]=m[c]);return q};var M=(m,r,q)=>new Promise((c,I)=>{var R=y=>{try{k(q.next(y))}catch(V){I(V)}},h=y=>{try{k(q.throw(y))}catch(V){I(V)}},k=y=>y.done?c(y.value):Promise.resolve(y.value).then(R,h);k((q=q.apply(m,r)).next())});const C="data-source-common",F=(e,t=!1)=>r.tval(e,{ns:t?void 0:C});function de(e,t={}){return r.i18n.t(e,A(f({},t),{ns:[C,"core"]}))}const P=(e=!1)=>{const{i18n:t}=r.useApp();return{t:(o,n={})=>t.t(o,f({ns:e?void 0:C},n))}},_=I.createContext({}),ue=_.Provider;function j(){return I.useContext(_)}const J=I.createContext({}),me=J.Provider;function O(){return I.useContext(J)}const ye=e=>{const{visible:t,setVisible:s}=e,[o,n]=I.useState(null),[a,i]=I.useState(null),[p,l]=I.useState(null);return c.jsx(r.ActionContextProvider,{visible:t,setVisible:s,children:c.jsx(me,{value:{rawResponse:o,debugResponse:a,responseValidationErrorMessage:p,setRawResponse:n,setDebugResponse:i,setResponseValidationErrorMessage:l},children:e.children})})},G={list:["page","pageSize","filter","sort","appends","fields","except"],get:["filterByTk","filter","sort","appends","fields","except"],create:["whiteList","blacklist","body"],update:["filterByTk","filter","whiteList","blacklist","body"],destroy:["filterByTk","filter"]},xe=[{name:"X-App",title:"X-App"},{name:"X-Locale",title:"X-Locale"},{name:"X-Hostname",title:"X-Hostname"},{name:"X-Timezone",title:"X-Timezone"},{name:"X-Role",title:"X-Role"},{name:"X-Authenticator",title:"X-Authenticator"}],L=e=>{var p,l;const t=r.useCompile(),{t:s}=P(),o=I.useContext(r.SchemaComponentContext),{actionKey:n}=j(),{variables:a}=((l=(p=o.dataSourceData)==null?void 0:p.data)==null?void 0:l.options)||{};return I.useMemo(()=>fe({t:s,variables:a,compile:t,actionKey:n,showResponse:e}),[n])},fe=e=>{const{t,variables:s,compile:o,actionKey:n,showResponse:a}=e,i=[];return s&&i.push({name:"dataSourceVariables",title:t("Custom variables"),children:s==null?void 0:s.map(p=>({name:o(p.name),title:p.name}))}),i.push({name:"request",title:t("TachyBase request"),children:[{name:"params",title:"params",children:(G[n]||[]).map(p=>({name:p,title:p}))},{name:"header",title:"headers",children:xe},{name:"body",title:"Body"},{name:"token",title:"Token"}]}),a&&i.push({name:"rawResponse",title:t("Third party response"),children:[{name:"body",title:"body"}]}),i},he=e=>{const{t,method:s,setFormValue:o}=e;return{name:"method",title:"HTTP method",default:s,"x-decorator":"FormItem","x-decorator-props":{validator:{required:!0,message:t("Method is required")},feedbackLayout:"popover"},required:!0,"x-component":"Select","x-component-props":{defaultValue:s,onChange:n=>{o(n,"method")},options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"PATCH",label:"PATCH"},{value:"DELETE",label:"DELETE"}]}}},be=e=>{const{t}=P(),{method:s,setFormValue:o}=e,n=he({t,method:s,setFormValue:o});return c.jsx(r.SchemaComponent,{schema:n})},ge=e=>{var a,i,p;const{t,path:s,setFormValue:o,scCtx:n}=e;return{name:"path",title:"URL",required:!0,default:s,"x-decorator":"FormItem","x-decorator-props":{feedbackLayout:"popover",addonBefore:c.jsx(r.EllipsisWithTooltip,{ellipsis:!0,children:c.jsx(r.Input.ReadPretty,{value:(p=(i=(a=n==null?void 0:n.dataSourceData)==null?void 0:a.data)==null?void 0:i.options)==null?void 0:p.baseUrl})}),validator:{required:!0,message:t("Path is required")},className:r.css`
|
|
2
2
|
.ant-formily-item-addon-before {
|
|
3
3
|
border-width: 1px;
|
|
4
4
|
border-style: solid;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
text-overflow: ellipsis;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
`,style:{width:"100%"}},"x-component":r.Variable.RawTextArea,"x-component-props":{defaultValue:s,autoSize:!0,onChange:l=>{o(l.target.value,"path")},scope
|
|
20
|
+
`,style:{width:"100%"}},"x-component":r.Variable.RawTextArea,"x-component-props":{defaultValue:s,autoSize:!0,onChange:l=>{o(l.target.value,"path")},scope:L,fieldNames:{value:"name",label:"title"},style:{borderTopLeftRadius:"0",borderBottomLeftRadius:"0"}}}},Ie=e=>{const{t}=P(),s=r.useSchemaComponentContext(),{path:o,setFormValue:n}=e,a=ge({t,path:o,setFormValue:n,scCtx:s});return c.jsx(r.SchemaComponent,{schema:a})},Y=e=>{var x;const{data:t}=r.useCollectionRecord(),{form:s,actionKey:o,requestActionForm:n}=j(),a=r.useSchemaComponentContext(),{path:i,method:p}=((x=t==null?void 0:t.actions)==null?void 0:x[o])||{},l=V.debounce((g,T)=>M(this,null,function*(){const{actions:S}=(s==null?void 0:s.values)||{};s.setValuesIn("actions",A(f({},S),{[o]:A(f({},S==null?void 0:S[o]),{[T]:g})})),n.setValuesIn(T,g)}),100),d=I.useMemo(()=>y.createForm({initialValues:n.values}),[]);return c.jsxs(r.FormProvider,{form:e!=null&&e.actionForm?d:n,children:[c.jsx(be,{method:p,setFormValue:l}),c.jsx(y.SchemaOptionsContext.Provider,{value:a,children:c.jsx(Ie,{path:i,setFormValue:l})})]})},W=X.lodash.debounce((e,t,s,o)=>{const{actions:n}=e.values||{};e.setValuesIn("actions",A(f({},n),{[t]:A(f({},n==null?void 0:n[t]),{[s]:o})}))},400),ve=({defaultValue:e,actionKey:t,parentForm:s,field:o})=>({type:"object",properties:{contentType:{type:"string","x-decorator":"FormItem","x-component":"Select",placeholder:`{{t("Content-Type",{ ns: "${C}" })}}`,default:e==null?void 0:e.contentType,"x-component-props":{onChange:n=>{W(s,t,"contentType",n)}},enum:[{value:"application/x-www-form-urlencoded",label:"application/x-www-form-urlencoded "},{value:"application/json",label:"application/json"}],"x-reactions":n=>{const a=s.values.actions[t],i=a==null?void 0:a.contentType;(n==null?void 0:n.value)!==i&&n.setValue(i!=null?i:"application/json"),n.value||W(s,t,"contentType","application/json")}},body:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",default:e.body,items:{type:"object",properties:{space:{type:"void","x-component":"Space","x-component-props":{style:{flexWrap:"nowrap",maxWidth:"100%",display:"flex"},className:r.css`
|
|
21
21
|
& > .ant-space-item:first-child,
|
|
22
22
|
& > .ant-space-item:last-child {
|
|
23
23
|
flex-shrink: 0;
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
& > .ant-space-item:nth-of-type(2) {
|
|
27
27
|
flex: 1;
|
|
28
28
|
}
|
|
29
|
-
`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},style:{minWidth:"220px"}}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove","x-component-props":{onClick:()=>{W(s,t,"body",o.form.values.body)}}}}}}},properties:{add:{type:"void",title:`{{t("Add", { ns: "${
|
|
29
|
+
`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},style:{minWidth:"220px"}}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove","x-component-props":{onClick:()=>{W(s,t,"body",o.form.values.body)}}}}}}},properties:{add:{type:"void",title:`{{t("Add", { ns: "${C}" })}}`,"x-component":"ArrayItems.Addition"}},"x-reactions":[{dependencies:[".contentType"],fulfill:{state:{visible:'{{ $deps[0]==="application/x-www-form-urlencoded"}}'}}}]},jsonBody:{type:"string","x-decorator":"FormItem","x-component":"Variable.JSON",default:e.jsonBody,"x-component-props":{scope:"{{useVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},placeholder:'{{t("Value")}}',style:{minHeight:200},onChange:n=>{const{actions:a}=s.values||{};s.setValuesIn("actions",A(f({},a),{[t]:A(f({},a==null?void 0:a[t]),{body:n})}))}},"x-reactions":[{dependencies:[".contentType"],fulfill:{state:{visible:'{{ $deps[0]==="application/json"}}'}}},n=>{var i,p,l;const a=(l=(p=(i=s==null?void 0:s.values)==null?void 0:i.actions)==null?void 0:p[t])==null?void 0:l.body;(n==null?void 0:n.value)!==a&&n.setValue(s.values.actions[t].body)}]}}}),Ce=()=>{var a,i;const e=y.useField(),{form:t,actionKey:s}=j(),o=(i=(a=t==null?void 0:t.values)==null?void 0:a.actions)==null?void 0:i[s],n=ve({parentForm:t,actionKey:s,defaultValue:{contentType:o==null?void 0:o.contentType,body:o==null?void 0:o.body,jsonBody:o==null?void 0:o.body},field:e});return c.jsx(r.SchemaComponent,{schema:n,components:{ArrayItems:k.ArrayItems,FormItem:r.FormItem,Input:h.Input,FormProvider:r.FormProvider},scope:{useVariableOptions:L}})},Fe=({title:e,defaultValue:t,field:s,parentForm:o,actionKey:n})=>{const a=p=>{var d,x,g;const l=(g=(x=(d=o==null?void 0:o.values)==null?void 0:d.actions)==null?void 0:x[n])==null?void 0:g.headers;(l==null?void 0:l.length)>0&&l!==t&&p.setValue(l)},i=()=>{W(o,n,"headers",s.form.values.headers)};return{type:"object","x-decorator":"Form",properties:{headers:{type:"array","x-component":"ArrayItems",default:t,"x-decorator":"FormItem","x-reactions":a,items:{type:"object",properties:{space:{type:"void","x-component":"Space","x-component-props":{style:{flexWrap:"nowrap",maxWidth:"100%",display:"flex"},className:r.css`
|
|
30
30
|
& > .ant-space-item:first-child,
|
|
31
31
|
& > .ant-space-item:last-child {
|
|
32
32
|
flex-shrink: 0;
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
& > .ant-space-item:nth-of-type(2) {
|
|
36
36
|
flex: 1;
|
|
37
37
|
}
|
|
38
|
-
`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},style:{minWidth:"220px"}}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove","x-component-props":{onClick:i}}}}}},properties:{add:{title:e,type:"void","x-component":"ArrayItems.Addition"}}}}}},
|
|
38
|
+
`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},style:{minWidth:"220px"}}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove","x-component-props":{onClick:i}}}}}},properties:{add:{title:e,type:"void","x-component":"ArrayItems.Addition"}}}}}},Ae=()=>{var i,p;const{t:e}=P(),t=y.useField(),{form:s,actionKey:o}=j(),n=(p=(i=s==null?void 0:s.values)==null?void 0:i.actions)==null?void 0:p[o],a=Fe({title:e("Add header"),defaultValue:(n==null?void 0:n.headers)||[],field:t,parentForm:s,actionKey:o});return c.jsx(r.SchemaComponent,{schema:a,components:{ArrayItems:k.ArrayItems,FormItem:r.FormItem,Input:h.Input},scope:{useVariableOptions:L}})},Se=({title:e,defaultValue:t,field:s,parentForm:o,actionKey:n})=>({type:"object","x-decorator":"Form",properties:{params:{type:"array","x-component":"ArrayItems",default:t,"x-decorator":"FormItem","x-reactions":a=>{var p,l,d;const i=(d=(l=(p=o.values)==null?void 0:p.actions)==null?void 0:l[n])==null?void 0:d.params;i!=null&&i.length&&i!==t&&a.setValue(i)},items:{type:"object",properties:{space:{type:"void","x-component":"Space","x-component-props":{style:{flexWrap:"nowrap",maxWidth:"100%",display:"flex"},className:r.css`
|
|
39
39
|
& > .ant-space-item:first-child,
|
|
40
40
|
& > .ant-space-item:last-child {
|
|
41
41
|
flex-shrink: 0;
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
& > .ant-space-item:nth-of-type(2) {
|
|
45
45
|
flex: 1;
|
|
46
46
|
}
|
|
47
|
-
`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}',style:{width:"100%"}}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},style:{minWidth:"230px",width:"100%"}}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove","x-component-props":{onClick:()=>{var a;W(o,n,"params",(a=s.form.values)==null?void 0:a.params)}}}}}}},properties:{add:{type:"void",title:e,"x-component":"ArrayItems.Addition"}}}}}),
|
|
47
|
+
`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}',style:{width:"100%"}}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},style:{minWidth:"230px",width:"100%"}}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove","x-component-props":{onClick:()=>{var a;W(o,n,"params",(a=s.form.values)==null?void 0:a.params)}}}}}}},properties:{add:{type:"void",title:e,"x-component":"ArrayItems.Addition"}}}}}),we=()=>{var i,p;const{t:e}=P(),t=y.useField(),{form:s,actionKey:o}=j(),n=(p=(i=s==null?void 0:s.values)==null?void 0:i.actions)==null?void 0:p[o],a=Se({title:e("Add parameter"),defaultValue:n==null?void 0:n.params,field:t,parentForm:s,actionKey:o});return c.jsx(r.SchemaComponent,{schema:a,components:{ArrayItems:k.ArrayItems,FormItem:r.FormItem,Input:h.Input},scope:{useVariableOptions:L}})},Te=e=>{const{t}=e;return[{key:"parameters",label:t("Parameters"),children:c.jsx(we,{})},{key:"body",label:t("Body"),children:c.jsx(Ce,{})},{key:"headers",label:t("Headers"),children:c.jsx(Ae,{})}]},Q=()=>{const{t:e}=P(),t=Te({t:e});return c.jsx(h.Tabs,{items:t})},qe={data:"{{rawResponse.body}}",meta:{}},Pe=(e,t,s)=>M(this,null,function*(){const{actions:o}=e.values||{};e.setValuesIn("actions",A(f({},o),{[t]:A(f({},o==null?void 0:o[t]),{responseTransformer:s})}))}),Z=()=>{var l,d,x;const{form:e,actionKey:t,responseTransformer:s,setResponseTransformer:o}=j(),n=(x=(d=(l=e==null?void 0:e.values)==null?void 0:l.actions)==null?void 0:d[t])==null?void 0:x.responseTransformer,a=s!=null?s:n,{data:i}=r.useCollectionRecord();I.useEffect(()=>{var g,T;if(!((T=(g=i==null?void 0:i.actions)==null?void 0:g[t])!=null&&T.responseTransformer)&&!n){const{actions:S}=e.values||{};e.setValuesIn("actions",A(f({},S),{[t]:A(f({},S==null?void 0:S[t]),{responseTransformer:qe})}))}},[]);const p=L(!0);return c.jsx(r.Variable.JSON,{value:a,onChange:g=>{o(g),Pe(e,t,g)},autoSize:{minRows:5},fieldNames:{value:"name",label:"title"},scope:()=>p})},ke=()=>{const{responseValidationErrorMessage:e}=O();return e?c.jsxs(c.Fragment,{children:[c.jsx(h.Alert,{type:"error",showIcon:!0,message:e}),c.jsx("br",{})]}):null},Ve=e=>({type:"object","x-decorator":"Form","x-decorator-props":{useValues(t){return r.useRequest(()=>Promise.resolve({data:{}}),t)}},properties:{[y.uid()]:{type:"string",default:e,"x-read-pretty":!0,"x-decorator":"FormItem","x-component":"Input.JSON","x-component-props":{style:{maxHeight:"350px"}}}}}),De=()=>{const{debugResponse:e}=O(),t=Ve(e);return c.jsx(r.SchemaComponent,{schema:t,components:{ArrayTable:k.ArrayTable,FormItem:r.FormItem,Input:r.Input}})},Me=e=>{const{t}=e;return[{key:"body",label:t("Body"),children:c.jsx(De,{})}]},Ne=()=>{const{t:e}=P(),{debugResponse:t}=O(),s=Me({t:e});return t?c.jsx(h.Tabs,{defaultActiveKey:"body",items:s}):null},Be=e=>{const{t}=P(),s=t("Extract field metadata from the response data");return c.jsx(h.Tooltip,{title:s,children:e.children})},je=()=>{const e=y.useForm(),t=r.useAPIClient(),{t:s}=P(),{setVisible:o}=I.useContext(r.ActionContext),{name:n}=H.useParams(),{rawResponse:a,responseValidationErrorMessage:i}=O(),{form:p,actionKey:l}=j(),{fields:d}=p.values,[x,g]=I.useState(!1),T=V.omit(e.values,"responseTab"),S=()=>M(this,null,function*(){var v,b;try{g(!0);const w=(b=(v=p==null?void 0:p.values)==null?void 0:v.actions)==null?void 0:b[l],u=t.resource("dataSources.httpCollections",n),{data:{data:D}}=yield u.runAction({values:{debug:!1,inferFields:!0,actionOptions:A(f({},w),{type:l,responseTransformer:w==null?void 0:w.responseTransformer}),debugVars:T}});o(!1),g(!1);const{transformedResponse:N,fields:E,filterTargetKey:$}=D;if($&&p.setValuesIn("filterTargetKey",$),E){const B=V.unionBy(d,E,"name");p.setValuesIn("fields",B)}if(typeof(N==null?void 0:N.data)=="object"){let B=[];l==="get"?B=[N==null?void 0:N.data]:B=N==null?void 0:N.data,p.setValuesIn("preview",B)}}catch(w){g(!1),console.log(w)}});return["list","get"].includes(l)?c.jsx(Be,{children:c.jsx(h.Button,{type:"primary",disabled:!a||i,loading:x,onClick:S,children:s("Extract field metadata")})}):null},ee=({key:e,defaultValue:t})=>({type:"object",properties:{[e]:{type:"array","x-decorator":"FormItem","x-component":"ArrayTable",default:t,"x-component-props":{scroll:{y:300}},items:{type:"object",properties:{column1:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:200,title:`{{t("Name",{ ns: "${C}" })}}`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}}}},column2:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:200,title:`{{t("Value",{ ns: "${C}" })}}`},properties:{value:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Value")}}'}}}}}}}}}),Oe=()=>{const{rawResponse:e}=O(),{request:t}=e||{},s=Object.entries((t==null?void 0:t.headers)||{}).map(([n,a])=>({name:n,value:a})),o=ee({key:"requestHeaders",defaultValue:s});return c.jsx(r.SchemaComponent,{schema:o,components:{ArrayTable:k.ArrayTable,FormItem:r.FormItem,Input:r.Input}})},Ee=e=>({type:"object","x-decorator":"Form","x-decorator-props":{useValues(t){return r.useRequest(()=>Promise.resolve({data:{}}),t)}},properties:{[y.uid()]:{type:"string",default:e,"x-read-pretty":!0,"x-decorator":"FormItem","x-component":"Input.JSON","x-component-props":{style:{maxHeight:"400px"}}}}}),$e=()=>{const{rawResponse:e}=O(),{data:t}=e||{},s=Ee(t);return c.jsx(r.SchemaComponent,{schema:s,components:{ArrayTable:k.ArrayTable,FormItem:r.FormItem,Input:r.Input}})},He=()=>{const{rawResponse:e}=O(),{headers:t}=e||{},s=Object.entries(t||{}).map(([n,a])=>({name:n,value:a})),o=ee({key:"responseHeaders",defaultValue:s});return c.jsx(r.SchemaComponent,{schema:o,components:{ArrayTable:k.ArrayTable,FormItem:r.FormItem,Input:r.Input}})},Le=e=>{const{t}=e;return[{key:"body",label:t("Body"),children:c.jsx($e,{})},{key:"responseHeaders",label:t("Response headers"),children:c.jsx(He,{})},{key:"requestHeaders",label:t("Request headers"),children:c.jsx(Oe,{})}]},We=()=>{const{t:e}=P(),{rawResponse:t}=O(),{status:s}=t||{},o=Le({t:e});if(!t)return null;const n=s.toString().startsWith("2")?"success":"error",a=c.jsx(h.Tag,{color:n,children:`HTTP Code:${s}`});return c.jsx(h.Card,{title:a,children:c.jsx(h.Tabs,{defaultActiveKey:"body",items:o})})};function ze(e,t){var p,l;const s=(l=(p=e==null?void 0:e.values)==null?void 0:p.actions)==null?void 0:l[t];let o=[];const{params:n=[],headers:a=[],body:i=[]}=s||{};return o=[...n,...a].map(d=>{var x;return(x=d==null?void 0:d.value)==null?void 0:x.replace(/{{|}}/g,"")}),typeof i=="string"?o.concat(i==null?void 0:i.replace(/{{|}}/g,"")):o.concat(i==null?void 0:i.map(d=>d==null?void 0:d.value.replace(/{{|}}/g,""))),o.filter(Boolean)}const Ke=(e,t)=>{const s=(o,n)=>{ze(e,t).find(p=>((p==null?void 0:p.split("."))||[]).pop()===o)&&(n.description=null)};return{page:{type:"number",title:"Page","x-decorator":"FormItem","x-component":"InputNumber",description:"{{t('Page variable not used. Pagination based on total current request data.')}}","x-reactions":o=>s("page",o)},pageSize:{type:"number",title:"PageSize","x-decorator":"FormItem","x-component":"InputNumber",description:"{{t('PageSize variable not used. Pagination based on total current request data.')}}","x-reactions":o=>s("pageSize",o)},filter:{type:"object",title:"Filter","x-decorator":"FormItem","x-component":"Input.JSON",description:"{{t('Filter variable not used. Filtering will apply to the current request data.')}}","x-reactions":o=>s("filter",o)},sort:{type:"string",title:"Sort","x-decorator":"FormItem","x-component":"Input",description:"{{t('Sort variable not used. Sorting will apply to the current request data.')}}","x-reactions":o=>s("sort",o)},appends:{type:"string",title:"Appends","x-decorator":"FormItem","x-component":"Input"},fields:{type:"string",title:"Fields","x-decorator":"FormItem","x-component":"Input",description:"{{t('Fields variable not used. Filtering will be based on the current request data.')}}","x-reactions":o=>s("fields",o)},except:{type:"string",title:"Except","x-decorator":"FormItem","x-component":"Input",description:"{{t('Except variable not used. Filtering will be based on the current request data.')}}","x-reactions":o=>s("except",o)},filterByTk:{type:"string",title:"FilterByTk","x-decorator":"FormItem","x-component":"Input",description:"{{t('The current parameters are not adapted')}}","x-reactions":o=>s("filterByTk",o)},whiteList:{type:"string",title:"whiteList","x-decorator":"FormItem","x-component":"Input"},blacklist:{type:"string",title:"blacklist","x-decorator":"FormItem","x-component":"Input"},body:{type:"object",title:"Body","x-decorator":"FormItem","x-component":"Input.JSON","x-component-props":{autoSize:{minRows:5,maxRows:20}}}}};function Re(e,t){const s={},o=G[e]||[],n=Ke(t,e);for(const a of o)s[a]=n[a];return s}const Ue=()=>{const{t:e}=P(),{actionKey:t,form:s,requestActionForm:o}=j(),n=Re(t,s),a=()=>{const i=l=>M(this,null,function*(){const{actions:d}=s.values||{},{path:x,value:g}=l.getState();x.includes("add")||(yield s.setValuesIn("actions",A(f({},d),{[t]:X.unflatten(A(f({},d==null?void 0:d[t]),{[x]:g}))})),["method","path"].includes(x)&&(yield o.setValuesIn([x],g)))}),p=V.debounce(i,400);y.onFieldChange("*",(l,d)=>{d.modified&&p(l)})};return{type:"object",properties:{modal:{type:"void","x-decorator":"Form","x-component":"Action.Modal","x-component-props":{className:r.cx("tb-action-popup",r.css`
|
|
48
48
|
.ant-modal-content {
|
|
49
49
|
padding: 0;
|
|
50
50
|
}
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
.ant-formily-item-feedback-layout-loose {
|
|
62
62
|
margin-bottom: 10px;
|
|
63
63
|
}
|
|
64
|
-
`},properties:{requestAction:{type:"string","x-component":Y,"x-component-props":{actionForm:!0}},requestTab:{type:"void","x-decorator":"FormItem","x-component":Q},responseTab:{type:"string","x-component"
|
|
64
|
+
`},properties:{requestAction:{type:"string","x-component":Y,"x-component-props":{actionForm:!0}},requestTab:{type:"void","x-decorator":"FormItem","x-component":Q},responseTab:{type:"string","x-component":We}}}}},nocoBaseResponse:{type:"void","x-decorator":"Col","x-decorator-props":{span:8},"x-component":"Card","x-component-props":{bordered:!1,title:e("TachyBase response"),style:{height:"80vh",overflowY:"auto",borderTopLeftRadius:0,borderBottomLeftRadius:0}},properties:{responseContainer:{type:"void","x-decorator":"Form",properties:{alertError:{type:"string","x-component":ke},responseTransformer:{type:"string","x-decorator":"FormItem","x-component":Z},debugResponse:{type:"string","x-component":Ne}}}}}}},footer:{type:"void","x-component":"Action.Modal.Footer",properties:{debug:{title:'{{t("Debug")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ useDebugAction }}"}},extractFieldMetadata:{"x-component":je}}}}}}}},Xe=()=>{const e=y.useForm(),{setVisible:t}=I.useContext(r.ActionContext),{setRawResponse:s,setDebugResponse:o}=O();return{run(){t(!1),e.reset(),e.setValuesIn("responseTab",null),s(null),o(null)}}},_e=()=>{const e=y.useField(),t=r.useAPIClient(),s=y.useForm(),{form:o,actionKey:n,requestActionForm:a}=j(),{name:i}=H.useParams(),{setRawResponse:p,setDebugResponse:l,setResponseValidationErrorMessage:d}=O();return{run(){return M(this,null,function*(){var T,S;const g=(S=(T=o==null?void 0:o.values)==null?void 0:T.actions)==null?void 0:S[n];try{e.data=(e==null?void 0:e.data)||{},e.data.loading=!0,yield a.submit();const v=t.resource("dataSources.httpCollections",i),b=V.omit(s.values,"responseTab"),{data:{data:w}}=yield v.runAction({values:{debug:!0,inferFields:!1,actionOptions:A(f({},g),{type:n,responseTransformer:g==null?void 0:g.responseTransformer}),debugVars:b}});e.data.loading=!1;const{rawResponse:u,debugBody:D,responseValidationErrorMessage:N}=w;p(u),l(D),d(N)}catch(v){e.data.loading=!1,console.log(v)}})}}},Je=()=>{const{t:e}=P(),t=Ue();return c.jsx(r.SchemaComponent,{schema:t,components:{Form:k.Form,Input:r.Input,Action:r.Action,FormItem:r.FormItem,InputNumber:r.InputNumber,Card:h.Card,Variable:r.Variable,Space:r.Space,Select:h.Select,FormLayout:k.FormLayout,Row:h.Row,Col:h.Col},scope:{t:e,useDebugAction:_e,useCancelAction:Xe,useVariableOptions:L}})},Ge=()=>{const{t:e}=P(),{requestActionForm:t}=j(),[s,o]=I.useState(!1),n=()=>M(this,null,function*(){yield t.submit(),o(!0)});return c.jsxs(c.Fragment,{children:[c.jsx(h.Button,{type:"primary",onClick:n,children:e("Try it out")}),c.jsx(ye,{visible:s,setVisible:o,children:c.jsx(Je,{})})]})},Ye=e=>{const t=y.useForm(),{actionKey:s}=e,o=I.useMemo(()=>y.createForm({}),[]),[n,a]=I.useState(null);return c.jsx(ue,{value:{form:A(f({},t),{[s]:o}),actionKey:s,requestActionForm:o,responseTransformer:n,setResponseTransformer:a},children:e.children})},z=(e,t)=>{const s=I.useRef();return{type:"void","x-decorator":Ye,"x-decorator-props":{actionKey:e},"x-component":"FormCollapse.CollapsePanel","x-component-props":{header:t,key:e},properties:{form:{"x-decorator":"Form","x-decorator-props":{className:r.css`
|
|
65
65
|
.ant-formily-item-feedback-layout-loose {
|
|
66
66
|
margin-bottom: 10px;
|
|
67
67
|
}
|
|
68
|
-
`,useValues(o){return s.current=y.useForm(),r.useRequest(()=>Promise.resolve(),o)},effects:()=>{const o=a=>{const i=s.current,{actions:p}=i.values||{},{path:l,value:d}=a.getState();l.includes("add")||i.setValuesIn("actions",w(f({},p),{[e]:X.unflatten(w(f({},p==null?void 0:p[e]),{[l]:d}))}))},n=V.debounce((a,i)=>M(this,null,function*(){i.modified&&(yield o(a))}),400);y.onFieldChange("*",(a,i)=>{i.modified&&n(a,i)})}},type:"void",properties:{[y.uid()]:{type:"void",properties:{requestAction:{type:"string","x-component":Y},requestTab:{type:"void","x-decorator":"FormItem",title:`{{t("Adapt request parameters",{ ns: "${F}" })}}`,"x-component":Q,"x-decorator-props":{tooltip:`{{t("Provide request variables from TachyBase for use by third-party APIs.",{ ns: "${F}" })}}`}},responseTransformer:{type:"string","x-decorator":"FormItem",title:`{{t("Convert third-party response results to NocoBase standard",{ ns: "${F}" })}}`,"x-component":Z,"x-decorator-props":{tooltip:`{{t("The response results from third-party APIs need to be converted to the NocoBase standard to display correctly on the frontend.",{ ns: "${F}" })}}`}},debug:{type:"void","x-component":Je}}}}}}}},Ye=e=>{const t=y.useForm(),s=r.useCompile(),{t:o}=P(),{fields:n,preview:a}=e,[i,p]=I.useState([]),[l,d]=I.useState(a),{getInterface:x}=r.useCollectionManager_deprecated(),g=T=>{const A=T.filter(b=>b.source||b.interface);return A?A.map(b=>{var D,N;const S=((D=b==null?void 0:b.uiSchema)==null?void 0:D.title)||b.name,u=(N=x(b.interface))==null?void 0:N.default.uiSchema;return{key:b.name,title:s(S),dataIndex:b.name,width:200,render:(E,H,B)=>{const z=H[b.name],ht={type:"object",properties:{[b.name]:w(f({name:`${b.name}`},u),{"x-read-pretty":!0,default:b.interface==="json"||typeof z=="object"?JSON.stringify(z):z})}};return c.jsx(r.EllipsisWithTooltip,{ellipsis:!0,children:c.jsx(y.RecursionField,{schema:ht,name:B,onlyRenderProperties:!0})})}}}):void 0};return I.useEffect(()=>{d(a)},[a,n]),I.useEffect(()=>{p([]);const T=g(n);p(T)},[t.values.fields]),c.jsx("div",{style:{marginBottom:"var(--tb-spacing)"},children:(l==null?void 0:l.length)>0&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"ant-formily-item-label",style:{marginTop:"var(--tb-spacing)",display:"flex",padding:"0 0 8px"},children:[c.jsx("div",{className:"ant-formily-item-label-content",children:c.jsx("span",{children:c.jsx("label",{children:o("Preview")})})}),c.jsx("span",{className:"ant-formily-item-colon",children:":"})]}),c.jsx(h.Table,{size:"middle",pagination:!1,bordered:!0,columns:i,dataSource:l,scroll:{x:1e3,y:300}},"preview")]})},y.uid())},Qe=(e,t)=>e.filter(o=>o.children.filter(a=>a.availableTypes&&a.availableTypes.includes(t)).length>0).map(o=>({label:o.label,key:o.key,children:o.children.filter(n=>n.availableTypes&&n.availableTypes.includes(t))})),te=e=>{const t=r.useCompile(),{getInterface:s}=r.useCollectionManager_deprecated(),{t:o}=P(),n=y.useForm(),a=y.useField(),[i,p]=I.useState(a.value),l=r.useFieldInterfaceOptions().filter(v=>!["relation","systemInfo"].includes(v.key)),{modal:d}=h.App.useApp(),x=(v,b)=>{setTimeout(()=>{i.splice(b,1,v),p(i),a.value=i.concat()},300)},g=v=>{i.splice(v,1);const b=i.concat();a.value=b,p(b)},T=()=>{d.confirm({title:o("Are you sure you want to clear fields?"),onOk:()=>{n.setValuesIn("fields",[]),n.setValuesIn("preview",[])}})},A=I.useMemo(()=>[{dataIndex:"index",width:60,key:"index",render:(v,b,S)=>S+1},{title:o("Field display name"),dataIndex:"title",key:"title",width:150,render:(v,b,S)=>{const u=i[S];return c.jsx(h.Input,{defaultValue:u.uiSchema.title,onChange:V.debounce(D=>{x(w(f({},u),{uiSchema:w(f({},V.omit(u==null?void 0:u.uiSchema,"rawTitle")),{title:D.target.value})}),S)},300)})}},{title:o("Field name"),dataIndex:"name",key:"name",width:130},{title:o("Field type"),dataIndex:"type",width:140,key:"type",render:(v,b,S)=>{const u=i[S];return u!=null&&u.source||!(u!=null&&u.possibleTypes)?c.jsxs(h.Tag,{children:[" ",v]}):c.jsx(h.Select,{defaultValue:v,popupMatchSelectWidth:!1,style:{width:"100%"},options:(u==null?void 0:u.possibleTypes.map(D=>({label:D,value:D})))||[],onChange:D=>{x(w(f({},u),{type:D}),S)}})}},{title:o("Field interface"),dataIndex:"interface",key:"interface",width:150,render:(v,b,S)=>{const u=i[S],D=(u==null?void 0:u.type)&&Qe(l,u==null?void 0:u.type),N=E=>{var B;const H=s(E);x(w(f({},u),{interface:E,uiSchema:f(f({},u.uiSchema),(B=H==null?void 0:H.default)==null?void 0:B.uiSchema)}),S)};return c.jsx(h.Select,{defaultValue:v,style:{width:"100%"},popupMatchSelectWidth:!1,onChange:N,children:D==null?void 0:D.map(E=>c.jsx(h.Select.OptGroup,{label:t(E.label),children:E.children.map(({label:H,value:B,name:z})=>c.jsx(h.Select.Option,{value:z,children:t(H)},B))},E.key))})}},{title:o("Actions"),dataIndex:"actions",fixed:"right",key:"actions",align:"center",width:100,render:(v,b,S)=>c.jsxs("a",{onClick:()=>g(S),children:[" ",o("Delete")]})}],[i]);return I.useEffect(()=>{p(a.value)},[a.value]),c.jsxs(c.Fragment,{children:[i.length?c.jsx(h.Button,{style:{position:"absolute",top:"-10px",right:"0px"},onClick:T,children:o("Clear")}):null,c.jsx(h.Table,{bordered:!0,size:"middle",columns:A,dataSource:i,scroll:{y:300},pagination:!1})]})};te.displayName="PreviewFields";function oe(e,t,s={}){const o=V.cloneDeep(s),n=f({name:`t_${y.uid()}`},o);n.reverseField&&(n.reverseField.name=`f_${y.uid()}`);const a=K("list",`{{t("List",{ ns: "${F}" })}}`),i=K("get",`{{t("Get",{ ns: "${F}" })}}`),p=K("create",`{{t("Create",{ ns: "${F}" })}}`),l=K("update",`{{t("Update",{ ns: "${F}" })}}`),d=K("destroy",`{{t("Destroy",{ ns: "${F}" })}}`);return{type:"object",properties:{[y.uid()]:{type:"void","x-component":"Action.Drawer","x-component-props":{getContainer:"{{ getContainer }}"},"x-decorator":"Form","x-decorator-props":{useValues(x){return r.useRequest(()=>Promise.resolve({data:n}),x)}},title:e,properties:{title:{type:"string",title:'{{ t("Collection display name") }}',required:!0,"x-decorator":"FormItem","x-component":"Input"},name:{type:"string",title:'{{t("Collection name")}}',required:!0,"x-disabled":"{{ !createOnly }}","x-decorator":"FormItem","x-component":"Input","x-validator":"uid",description:"{{t('Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.')}}"},description:{title:'{{t("Description")}}',type:"string",name:"description","x-decorator":"FormItem","x-component":"Input"},actions:{type:"void",title:C("Request actions"),"x-decorator":"FormItem","x-component":"FormCollapse","x-component-props":{size:"small",accordion:!0,defaultActiveKey:[]},properties:{list:a,get:i,create:p,update:l,destroy:d}},fields:{type:"array",required:!0,"x-component":te,"x-decorator":"FormItem",title:C("Fields",!0)},filterTargetKey:{title:C("Record unique key"),required:!0,type:"single",description:C("If a collection lacks a primary key, you must configure a unique record key to locate row records within a block, failure to configure this will prevent the creation of data blocks for the collection."),"x-decorator":"FormItem","x-component":"Select","x-reactions":["{{useAsyncDataSource(loadFilterTargetKeys)}}"]},preview:{type:"void","x-visible":"{{ createOnly }}","x-component":Ye,"x-reactions":{dependencies:["fields"],fulfill:{schema:{"x-component-props":"{{$form.values}}"}}}},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{action1:{title:'{{ t("Cancel") }}',"x-component":"Action","x-component-props":{useAction:"{{ useCancelAction }}"}},action2:{title:'{{ t("Submit") }}',"x-component":"Action","x-component-props":{type:"primary",useAction:t}}}}}}}}}function re(e){return Object.keys(e).filter(n=>{const a=e[n];return a.method&&a.path}).reduce((n,a)=>w(f({},n),{[a]:e[a]}),{})}function se(e){return["list","get"].filter(t=>!e.includes(t))}function Ze(){const e=y.useForm(),{refreshCM:t}=r.useCollectionManager_deprecated(),s=r.useActionContext(),{refresh:o}=r.useResourceActionContext(),n=r.useAPIClient(),{name:a}=L.useParams(),i=n.resource("dataSources.collections",a),p=y.useField(),l=r.useDataSourceManager();return P(),{run(){return M(this,null,function*(){p.data=p.data||{},p.data.loading=!0;try{yield e.submit();const x=V.cloneDeep(e.values),g=re(x==null?void 0:x.actions),T=se(Object.keys(g)),A=V.pick(x,["fields","name","title","filterTargetKey"]),v=T[0];v?(e.query(`*.actions.${v}`).take(b=>{b.setComponentProps({style:{border:"1px solid #ff4d4f"}})}),yield e[v].submit()):(yield i.create({values:w(f({logging:!0},A),{actions:g})}),s.setVisible(!1),yield e.reset(),p.data.loading=!1,o(),yield t(),l.getDataSource(a).reload())}catch(x){console.error(x),p.data.loading=!1}})}}}const et=e=>{const{scope:t,getContainer:s,item:o}=e,n=C("Create collection",!0),a=oe(n,Ze);return c.jsx(r.SchemaComponent,{schema:a,components:{ArrayTable:k.ArrayTable,TemplateSummay:r.TemplateSummary,FormCollapse:k.FormCollapse,ArrayItems:k.ArrayItems,FormLayout:k.FormLayout,FormItem:r.FormItem},scope:f({createOnly:!0,record:o,showReverseFieldConfig:!0,presetFieldsDisabled:!0,getContainer:s,useCancelAction:r.useCancelAction},t)})},tt=e=>{const{t}=P(!0),{scope:s,getContainer:o,item:n}=e,[a,i]=I.useState(!1),p=()=>i(!0);return c.jsx(r.RecordProvider,{record:n,children:c.jsxs(r.ActionContextProvider,{value:{visible:a,setVisible:i},children:[c.jsx(h.Button,{type:"primary",icon:c.jsx(R.PlusOutlined,{}),onClick:p,children:t("Create collection")}),c.jsx(et,{scope:s,getContainer:o,item:n})]})})},ot=e=>{const t=r.useRecord();return c.jsx(tt,f({item:t},e))};function rt(){const{run:e}=st(),{refreshCM:t}=r.useCollectionManager_deprecated();return{run(){return M(this,null,function*(){yield e(),yield t()})}}}function st(){const e=r.useAPIClient(),{t}=P(),s=y.useForm(),o=r.useActionContext(),{name:n}=L.useParams(),{state:a,setState:i,refresh:p}=r.useResourceActionContext();return{run(){return M(this,null,function*(){var d;if(!(a!=null&&a.selectedRowKeys)||a.selectedRowKeys.length===0)return h.message.error(t("Please select the records you want to delete"));yield e.resource("dataSources.collections",n).destroy({filterByTk:(a==null?void 0:a.selectedRowKeys)||[]}),s.reset(),(d=o==null?void 0:o.setVisible)==null||d.call(o,!1),i==null||i({selectedRowKeys:[]}),p()})}}}function nt(){const{run:e}=at(),{refreshCM:t}=r.useCollectionManager_deprecated();return{run(){return M(this,null,function*(){yield e(),yield t()})}}}function at(){const e=r.useAPIClient(),t=r.useActionContext(),{targetKey:s}=r.useResourceContext(),{[s]:o}=r.useRecord(),{name:n}=L.useParams(),{refresh:a}=r.useResourceActionContext();return{run(){return M(this,null,function*(){var p;yield e.resource("dataSources.collections",n).destroy({filterByTk:o}),(p=t==null?void 0:t.setVisible)==null||p.call(t,!1),a()})}}}const ne=e=>{const{t}=P(),{modal:s}=h.App.useApp(),v=e,{item:o,isBulk:n,children:a}=v,i=le(v,["item","isBulk","children"]),p=V.omit(i,["scope","getContainer","useAction"]),[l,d]=I.useState(!1),{run:x}=rt(),{run:g}=nt(),T=n?x:g,A=()=>{s.confirm({title:t("Delete collection"),content:t("Are you sure you want to delete it?"),onOk:T})};return c.jsx(r.RecordProvider,{record:o,children:c.jsx(r.ActionContextProvider,{value:{visible:l,setVisible:d},children:n?c.jsx(h.Button,{icon:c.jsx(R.DeleteOutlined,{}),onClick:A,children:a||t("Delete")}):c.jsx("a",w(f({onClick:A},p),{children:a||t("Delete")}))})})};ne.displayName="DeleteCollectionAction";const ct=e=>{const t=r.useRecord();return c.jsx(ne,f({item:t},e))},it=e=>{const t=r.useAPIClient(),s=r.useDataSourceManager(),{refreshCM:o}=r.useCollectionManager_deprecated(),{refresh:n}=r.useResourceActionContext(),a=y.useForm(),i=r.useActionContext(),{targetKey:p}=r.useResourceContext(),{name:l}=L.useParams(),{[p]:d}=r.useRecord(),x=t.resource("dataSources.collections",l);return{run(){return M(this,null,function*(){yield a.submit();const T=V.cloneDeep(a.values),A=re(T==null?void 0:T.actions),v=se(Object.keys(A)),b=V.pick(a.values,["fields","name","title","filterTargetKey"]),S=v[0];if(S)a.query(`*.actions.${S}`).take(u=>{u.setComponentProps({style:{border:"1px solid #ff4d4f"}})}),yield a[S].submit();else{yield x.update({filterByTk:d,values:w(f({},b),{actions:A})}),i.setVisible(!1);const u=s.getDataSource(l);u!=null&&u.reload||u.reload.call(u),yield a.reset(),n(),yield o()}})}}},pt=e=>{const{scope:t,getContainer:s,item:o}=e,n=oe('{{ t("Edit collection") }}',it,o);return c.jsx(r.SchemaComponent,{schema:n,components:{ArrayTable:k.ArrayTable,TemplateSummay:r.TemplateSummary,FormCollapse:k.FormCollapse,ArrayItems:k.ArrayItems,FormLayout:k.FormLayout,FormItem:r.FormItem},scope:f({createOnly:!0,record:o,showReverseFieldConfig:!0,presetFieldsDisabled:!0,getContainer:s,useCancelAction:r.useCancelAction},t)})},lt=e=>{const{t}=P(),{scope:s,getContainer:o,item:n}=e,[a,i]=I.useState(!1);return c.jsx(r.RecordProvider,{record:n,children:c.jsxs(r.ActionContextProvider,{value:{visible:a,setVisible:i},children:[c.jsx("a",{onClick:()=>i(!0),children:t("Edit")}),c.jsx(pt,{scope:s,item:n,getContainer:o})]})})},dt=e=>{const t=r.useRecord();return c.jsx(lt,f({item:t},e))},ut={type:"object",properties:{displayName:{type:"string",title:`{{t("Data source display name",{ ns: "${F}" })}}`,required:!0,"x-decorator":"FormItem","x-component":"Input"},key:{type:"string",title:`{{t("Data source name",{ ns: "${F}" })}}`,required:!0,"x-decorator":"FormItem","x-component":"Input","x-validator":"uid","x-disabled":"{{ createOnly }}",description:`{{t('Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.',{ ns: "${F}" })}}`},options:{type:"object",properties:{baseUrl:{type:"string",title:`{{t("BaseURL",{ ns: "${F}" })}}`,required:!0,"x-decorator":"FormItem","x-component":"Input.URL","x-validator":"url"},headers:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:`{{t("Headers", { ns: "${F}" })}}`,items:{type:"object",properties:{space:{type:"void","x-component":"Space","x-component-props":{style:{flexWrap:"nowrap",maxWidth:"100%",display:"flex"},className:r.css`
|
|
68
|
+
`,useValues(o){return s.current=y.useForm(),r.useRequest(()=>Promise.resolve(),o)},effects:()=>{const o=a=>{const i=s.current,{actions:p}=i.values||{},{path:l,value:d}=a.getState();l.includes("add")||i.setValuesIn("actions",A(f({},p),{[e]:X.unflatten(A(f({},p==null?void 0:p[e]),{[l]:d}))}))},n=V.debounce((a,i)=>M(this,null,function*(){i.modified&&(yield o(a))}),400);y.onFieldChange("*",(a,i)=>{i.modified&&n(a,i)})}},type:"void",properties:{[y.uid()]:{type:"void",properties:{requestAction:{type:"string","x-component":Y},requestTab:{type:"void","x-decorator":"FormItem",title:`{{t("Adapt request parameters",{ ns: "${C}" })}}`,"x-component":Q,"x-decorator-props":{tooltip:`{{t("Provide request variables from TachyBase for use by third-party APIs.",{ ns: "${C}" })}}`}},responseTransformer:{type:"string","x-decorator":"FormItem",title:`{{t("Convert third-party response results to NocoBase standard",{ ns: "${C}" })}}`,"x-component":Z,"x-decorator-props":{tooltip:`{{t("The response results from third-party APIs need to be converted to the NocoBase standard to display correctly on the frontend.",{ ns: "${C}" })}}`}},debug:{type:"void","x-component":Ge}}}}}}}},Qe=e=>{const t=y.useForm(),s=r.useCompile(),{t:o}=P(),{fields:n,preview:a}=e,[i,p]=I.useState([]),[l,d]=I.useState(a),{getInterface:x}=r.useCollectionManager_deprecated(),g=T=>{const S=T.filter(b=>b.source||b.interface);return S?S.map(b=>{var D,N;const w=((D=b==null?void 0:b.uiSchema)==null?void 0:D.title)||b.name,u=(N=x(b.interface))==null?void 0:N.default.uiSchema;return{key:b.name,title:s(w),dataIndex:b.name,width:200,render:(E,$,B)=>{const K=$[b.name],bt={type:"object",properties:{[b.name]:A(f({name:`${b.name}`},u),{"x-read-pretty":!0,default:b.interface==="json"||typeof K=="object"?JSON.stringify(K):K})}};return c.jsx(r.EllipsisWithTooltip,{ellipsis:!0,children:c.jsx(y.RecursionField,{schema:bt,name:B,onlyRenderProperties:!0})})}}}):void 0};return I.useEffect(()=>{d(a)},[a,n]),I.useEffect(()=>{p([]);const T=g(n);p(T)},[t.values.fields]),c.jsx("div",{style:{marginBottom:"var(--tb-spacing)"},children:(l==null?void 0:l.length)>0&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"ant-formily-item-label",style:{marginTop:"var(--tb-spacing)",display:"flex",padding:"0 0 8px"},children:[c.jsx("div",{className:"ant-formily-item-label-content",children:c.jsx("span",{children:c.jsx("label",{children:o("Preview")})})}),c.jsx("span",{className:"ant-formily-item-colon",children:":"})]}),c.jsx(h.Table,{size:"middle",pagination:!1,bordered:!0,columns:i,dataSource:l,scroll:{x:1e3,y:300}},"preview")]})},y.uid())},Ze=(e,t)=>e.filter(o=>o.children.filter(a=>a.availableTypes&&a.availableTypes.includes(t)).length>0).map(o=>({label:o.label,key:o.key,children:o.children.filter(n=>n.availableTypes&&n.availableTypes.includes(t))})),te=e=>{const t=r.useCompile(),{getInterface:s}=r.useCollectionManager_deprecated(),{t:o}=P(),n=y.useForm(),a=y.useField(),[i,p]=I.useState(a.value),l=r.useFieldInterfaceOptions().filter(v=>!["relation","systemInfo"].includes(v.key)),{modal:d}=h.App.useApp(),x=(v,b)=>{setTimeout(()=>{i.splice(b,1,v),p(i),a.value=i.concat()},300)},g=v=>{i.splice(v,1);const b=i.concat();a.value=b,p(b)},T=()=>{d.confirm({title:o("Are you sure you want to clear fields?"),onOk:()=>{n.setValuesIn("fields",[]),n.setValuesIn("preview",[])}})},S=I.useMemo(()=>[{dataIndex:"index",width:60,key:"index",render:(v,b,w)=>w+1},{title:o("Field display name"),dataIndex:"title",key:"title",width:150,render:(v,b,w)=>{const u=i[w];return c.jsx(h.Input,{defaultValue:u.uiSchema.title,onChange:V.debounce(D=>{x(A(f({},u),{uiSchema:A(f({},V.omit(u==null?void 0:u.uiSchema,"rawTitle")),{title:D.target.value})}),w)},300)})}},{title:o("Field name"),dataIndex:"name",key:"name",width:130},{title:o("Field type"),dataIndex:"type",width:140,key:"type",render:(v,b,w)=>{const u=i[w];return u!=null&&u.source||!(u!=null&&u.possibleTypes)?c.jsxs(h.Tag,{children:[" ",v]}):c.jsx(h.Select,{defaultValue:v,popupMatchSelectWidth:!1,style:{width:"100%"},options:(u==null?void 0:u.possibleTypes.map(D=>({label:D,value:D})))||[],onChange:D=>{x(A(f({},u),{type:D}),w)}})}},{title:o("Field interface"),dataIndex:"interface",key:"interface",width:150,render:(v,b,w)=>{const u=i[w],D=(u==null?void 0:u.type)&&Ze(l,u==null?void 0:u.type),N=E=>{var B;const $=s(E);x(A(f({},u),{interface:E,uiSchema:f(f({},u.uiSchema),(B=$==null?void 0:$.default)==null?void 0:B.uiSchema)}),w)};return c.jsx(h.Select,{defaultValue:v,style:{width:"100%"},popupMatchSelectWidth:!1,onChange:N,children:D==null?void 0:D.map(E=>c.jsx(h.Select.OptGroup,{label:t(E.label),children:E.children.map(({label:$,value:B,name:K})=>c.jsx(h.Select.Option,{value:K,children:t($)},B))},E.key))})}},{title:o("Actions"),dataIndex:"actions",fixed:"right",key:"actions",align:"center",width:100,render:(v,b,w)=>c.jsxs("a",{onClick:()=>g(w),children:[" ",o("Delete")]})}],[i]);return I.useEffect(()=>{p(a.value)},[a.value]),c.jsxs(c.Fragment,{children:[i.length?c.jsx(h.Button,{style:{position:"absolute",top:"-10px",right:"0px"},onClick:T,children:o("Clear")}):null,c.jsx(h.Table,{bordered:!0,size:"middle",columns:S,dataSource:i,scroll:{y:300},pagination:!1})]})};te.displayName="PreviewFields";function oe(e,t,s={}){const o=V.cloneDeep(s),n=f({name:`t_${y.uid()}`},o);n.reverseField&&(n.reverseField.name=`f_${y.uid()}`);const a=z("list",`{{t("List",{ ns: "${C}" })}}`),i=z("get",`{{t("Get",{ ns: "${C}" })}}`),p=z("create",`{{t("Create",{ ns: "${C}" })}}`),l=z("update",`{{t("Update",{ ns: "${C}" })}}`),d=z("destroy",`{{t("Destroy",{ ns: "${C}" })}}`);return{type:"object",properties:{[y.uid()]:{type:"void","x-component":"Action.Drawer","x-component-props":{getContainer:"{{ getContainer }}"},"x-decorator":"Form","x-decorator-props":{useValues(x){return r.useRequest(()=>Promise.resolve({data:n}),x)}},title:e,properties:{title:{type:"string",title:'{{ t("Collection display name") }}',required:!0,"x-decorator":"FormItem","x-component":"Input"},name:{type:"string",title:'{{t("Collection name")}}',required:!0,"x-disabled":"{{ !createOnly }}","x-decorator":"FormItem","x-component":"Input","x-validator":"uid",description:"{{t('Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.')}}"},description:{title:'{{t("Description")}}',type:"string",name:"description","x-decorator":"FormItem","x-component":"Input"},actions:{type:"void",title:F("Request actions"),"x-decorator":"FormItem","x-component":"FormCollapse","x-component-props":{size:"small",accordion:!0,defaultActiveKey:[]},properties:{list:a,get:i,create:p,update:l,destroy:d}},fields:{type:"array",required:!0,"x-component":te,"x-decorator":"FormItem",title:F("Fields",!0)},filterTargetKey:{title:F("Record unique key"),required:!0,type:"single",description:F("If a collection lacks a primary key, you must configure a unique record key to locate row records within a block, failure to configure this will prevent the creation of data blocks for the collection."),"x-decorator":"FormItem","x-component":"Select","x-reactions":["{{useAsyncDataSource(loadFilterTargetKeys)}}"]},preview:{type:"void","x-visible":"{{ createOnly }}","x-component":Qe,"x-reactions":{dependencies:["fields"],fulfill:{schema:{"x-component-props":"{{$form.values}}"}}}},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{action1:{title:'{{ t("Cancel") }}',"x-component":"Action","x-component-props":{useAction:"{{ useCancelAction }}"}},action2:{title:'{{ t("Submit") }}',"x-component":"Action","x-component-props":{type:"primary",useAction:t}}}}}}}}}function re(e){return Object.keys(e).filter(n=>{const a=e[n];return a.method&&a.path}).reduce((n,a)=>A(f({},n),{[a]:e[a]}),{})}function se(e){return["list","get"].filter(t=>!e.includes(t))}function et(){const e=y.useForm(),{refreshCM:t}=r.useCollectionManager_deprecated(),s=r.useActionContext(),{refresh:o}=r.useResourceActionContext(),n=r.useAPIClient(),{name:a}=H.useParams(),i=n.resource("dataSources.collections",a),p=y.useField(),l=r.useDataSourceManager();return P(),{run(){return M(this,null,function*(){p.data=p.data||{},p.data.loading=!0;try{yield e.submit();const x=V.cloneDeep(e.values),g=re(x==null?void 0:x.actions),T=se(Object.keys(g)),S=V.pick(x,["fields","name","title","filterTargetKey"]),v=T[0];v?(e.query(`*.actions.${v}`).take(b=>{b.setComponentProps({style:{border:"1px solid #ff4d4f"}})}),yield e[v].submit()):(yield i.create({values:A(f({logging:!0},S),{actions:g})}),s.setVisible(!1),yield e.reset(),p.data.loading=!1,o(),yield t(),l.getDataSource(a).reload())}catch(x){console.error(x),p.data.loading=!1}})}}}const tt=e=>{const{scope:t,getContainer:s,item:o}=e,n=F("Create collection",!0),a=oe(n,et);return c.jsx(r.SchemaComponent,{schema:a,components:{ArrayTable:k.ArrayTable,TemplateSummay:r.TemplateSummary,FormCollapse:k.FormCollapse,ArrayItems:k.ArrayItems,FormLayout:k.FormLayout,FormItem:r.FormItem},scope:f({createOnly:!0,record:o,showReverseFieldConfig:!0,presetFieldsDisabled:!0,getContainer:s,useCancelAction:r.useCancelAction},t)})},ot=e=>{const{t}=P(!0),{scope:s,getContainer:o,item:n}=e,[a,i]=I.useState(!1),p=()=>i(!0);return c.jsx(r.RecordProvider,{record:n,children:c.jsxs(r.ActionContextProvider,{value:{visible:a,setVisible:i},children:[c.jsx(h.Button,{type:"primary",icon:c.jsx(R.PlusOutlined,{}),onClick:p,children:t("Create collection")}),c.jsx(tt,{scope:s,getContainer:o,item:n})]})})},rt=e=>{const t=r.useRecord();return c.jsx(ot,f({item:t},e))};function st(){const{run:e}=nt(),{refreshCM:t}=r.useCollectionManager_deprecated();return{run(){return M(this,null,function*(){yield e(),yield t()})}}}function nt(){const e=r.useAPIClient(),{t}=P(),s=y.useForm(),o=r.useActionContext(),{name:n}=H.useParams(),{state:a,setState:i,refresh:p}=r.useResourceActionContext();return{run(){return M(this,null,function*(){var d;if(!(a!=null&&a.selectedRowKeys)||a.selectedRowKeys.length===0)return h.message.error(t("Please select the records you want to delete"));yield e.resource("dataSources.collections",n).destroy({filterByTk:(a==null?void 0:a.selectedRowKeys)||[]}),s.reset(),(d=o==null?void 0:o.setVisible)==null||d.call(o,!1),i==null||i({selectedRowKeys:[]}),p()})}}}function at(){const{run:e}=ct(),{refreshCM:t}=r.useCollectionManager_deprecated();return{run(){return M(this,null,function*(){yield e(),yield t()})}}}function ct(){const e=r.useAPIClient(),t=r.useActionContext(),{key:s}=r.useRecord(),{name:o}=H.useParams(),{refresh:n}=r.useResourceActionContext();return{run(){return M(this,null,function*(){var i;yield e.resource("dataSources.collections",o).destroy({filterByTk:s}),(i=t==null?void 0:t.setVisible)==null||i.call(t,!1),n()})}}}const ne=e=>{const{t}=P(),{modal:s}=h.App.useApp(),v=e,{item:o,isBulk:n,children:a}=v,i=le(v,["item","isBulk","children"]),p=V.omit(i,["scope","getContainer","useAction"]),[l,d]=I.useState(!1),{run:x}=st(),{run:g}=at(),T=n?x:g,S=()=>{s.confirm({title:t("Delete collection"),content:t("Are you sure you want to delete it?"),onOk:T})};return c.jsx(r.RecordProvider,{record:o,children:c.jsx(r.ActionContextProvider,{value:{visible:l,setVisible:d},children:n?c.jsx(h.Button,{icon:c.jsx(R.DeleteOutlined,{}),onClick:S,children:a||t("Delete")}):c.jsx("a",A(f({onClick:S},p),{children:a||t("Delete")}))})})};ne.displayName="DeleteCollectionAction";const it=e=>{const t=r.useRecord();return c.jsx(ne,f({item:t},e))},pt=e=>{const t=r.useAPIClient(),s=r.useDataSourceManager(),{refreshCM:o}=r.useCollectionManager_deprecated(),{refresh:n}=r.useResourceActionContext(),a=y.useForm(),i=r.useActionContext(),{targetKey:p}=r.useResourceContext(),{name:l}=H.useParams(),{[p]:d}=r.useRecord(),x=t.resource("dataSources.collections",l);return{run(){return M(this,null,function*(){yield a.submit();const T=V.cloneDeep(a.values),S=re(T==null?void 0:T.actions),v=se(Object.keys(S)),b=V.pick(a.values,["fields","name","title","filterTargetKey"]),w=v[0];if(w)a.query(`*.actions.${w}`).take(u=>{u.setComponentProps({style:{border:"1px solid #ff4d4f"}})}),yield a[w].submit();else{yield x.update({filterByTk:d,values:A(f({},b),{actions:S})}),i.setVisible(!1);const u=s.getDataSource(l);u!=null&&u.reload||u.reload.call(u),yield a.reset(),n(),yield o()}})}}},lt=e=>{const{scope:t,getContainer:s,item:o}=e,n=oe('{{ t("Edit collection") }}',pt,o);return c.jsx(r.SchemaComponent,{schema:n,components:{ArrayTable:k.ArrayTable,TemplateSummay:r.TemplateSummary,FormCollapse:k.FormCollapse,ArrayItems:k.ArrayItems,FormLayout:k.FormLayout,FormItem:r.FormItem},scope:f({createOnly:!0,record:o,showReverseFieldConfig:!0,presetFieldsDisabled:!0,getContainer:s,useCancelAction:r.useCancelAction},t)})},dt=e=>{P();const{scope:t,getContainer:s,item:o}=e,[n,a]=I.useState(!1);return c.jsx(r.RecordProvider,{record:o,children:c.jsxs(r.ActionContextProvider,{value:{visible:n,setVisible:a},children:[c.jsx("a",{onClick:()=>a(!0),children:de("Edit")}),c.jsx(lt,{scope:t,item:o,getContainer:s})]})})},ut=e=>{const t=r.useRecord();return c.jsx(dt,f({item:t},e))},mt={type:"object",properties:{displayName:{type:"string",title:`{{t("Data source display name",{ ns: "${C}" })}}`,required:!0,"x-decorator":"FormItem","x-component":"Input"},key:{type:"string",title:`{{t("Data source name",{ ns: "${C}" })}}`,required:!0,"x-decorator":"FormItem","x-component":"Input","x-validator":"uid","x-disabled":"{{ createOnly }}",description:`{{t('Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.',{ ns: "${C}" })}}`},options:{type:"object",properties:{baseUrl:{type:"string",title:`{{t("BaseURL",{ ns: "${C}" })}}`,required:!0,"x-decorator":"FormItem","x-component":"Input.URL","x-validator":{type:"pattern",pattern:/^(https?|ftp):\/\/((([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})|(\d{1,3}\.){3}\d{1,3}|localhost)(:(\d{1,5}))?(\/[^\s]*)?$/,message:`{{t("Invalid URL",{ ns: "${C}" })}}`}},headers:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:`{{t("Headers", { ns: "${C}" })}}`,items:{type:"object",properties:{space:{type:"void","x-component":"Space","x-component-props":{style:{flexWrap:"nowrap",maxWidth:"100%",display:"flex"},className:r.css`
|
|
69
69
|
& > .ant-space-item:first-child,
|
|
70
70
|
& > .ant-space-item:last-child {
|
|
71
71
|
flex-shrink: 0;
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
& > .ant-space-item:nth-of-type(2) {
|
|
75
75
|
flex: 1;
|
|
76
76
|
}
|
|
77
|
-
`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}},value:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:`{{t("Add request header", { ns: "${
|
|
77
|
+
`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}},value:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:`{{t("Add request header", { ns: "${C}" })}}`,"x-component":"ArrayItems.Addition"}}},variables:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:`{{t("Variables", { ns: "${C}" })}}`,items:{type:"object",properties:{space:{type:"void","x-component":"Space","x-component-props":{style:{flexWrap:"nowrap",maxWidth:"100%",display:"flex"},className:r.css`
|
|
78
78
|
& > .ant-space-item:first-child,
|
|
79
79
|
& > .ant-space-item:last-child {
|
|
80
80
|
flex-shrink: 0;
|
|
@@ -83,4 +83,4 @@
|
|
|
83
83
|
& > .ant-space-item:nth-of-type(2) {
|
|
84
84
|
flex: 1;
|
|
85
85
|
}
|
|
86
|
-
`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}},value:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:`{{t("Add variable", { ns: "${
|
|
86
|
+
`},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}},value:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:`{{t("Add variable", { ns: "${C}" })}}`,"x-component":"ArrayItems.Addition"}}},timeout:{type:"string",title:`{{t("Timeout",{ ns: "${C}" })}}`,"x-decorator":"FormItem","x-component":"InputNumber","x-component-props":{addonAfter:"ms",style:{minWidth:200}},default:5e3},responseType:{type:"string",title:`{{t("Response type",{ ns: "${C}" })}}`,"x-decorator":"FormItem","x-component":"Select",default:"json",enum:[{value:"json",label:`{{t("JSON",{ ns: "${C}" })}}`}]}}},enabled:{type:"string","x-content":`{{t("Enabled the data source",{ ns: "${C}" })}}`,"x-decorator":"FormItem","x-component":"Checkbox",default:!0}}},yt=()=>{const{t:e}=P();return c.jsx(r.SchemaComponent,{schema:mt,components:{Space:r.Space},scope:{t:e}})};class xt extends r.Plugin{load(){return M(this,null,function*(){this.app.pm.get(q).registerType("http",{label:F("REST API"),allowCollectionCreate:!0,allowCollectionDeletion:!0,disabledConfigureFields:!1,disableAddFields:!0,disableTestConnection:!0,DataSourceSettingsForm:yt,AddCollection:rt,EditCollection:ut,DeleteCollection:it})})}}const ft=()=>{const{t:e}=P();return c.jsx(r.SchemaComponent,{scope:{t:e},schema:{type:"object",properties:{key:{type:"string",title:F("Data source name"),required:!0,"x-decorator":"FormItem","x-component":"Input","x-validator":"uid","x-disabled":"{{ createOnly }}",description:F("Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.")},displayName:{type:"string",title:F("Data source display name"),required:!0,"x-decorator":"FormItem","x-component":"Input"},options:{type:"object",properties:{host:{type:"string",title:F("Host"),required:!0,"x-decorator":"FormItem","x-component":"Input",default:"localhost"},port:{type:"string",title:F("Port"),required:!0,"x-decorator":"FormItem","x-component":"Input",default:3306},database:{type:"string",title:F("Database"),required:!0,"x-decorator":"FormItem","x-component":"Input"},username:{type:"string",title:F("Username"),required:!0,"x-decorator":"FormItem","x-component":"Input"},password:{type:"string",title:F("Password"),"x-decorator":"FormItem","x-component":"Password"},tablePrefix:{type:"string",title:F("Table prefix"),"x-decorator":"FormItem","x-component":"Input"}}},enabled:{type:"string","x-content":F("Enabled the data source"),"x-decorator":"FormItem","x-component":"Checkbox",default:!0}}}})},ht=()=>{const{t:e}=P();return c.jsx(r.SchemaComponent,{scope:{t:e},components:{Space:h.Space},schema:{type:"object",properties:{key:{type:"string",title:F("Data source name"),required:!0,"x-decorator":"FormItem","x-component":"Input","x-validator":"uid","x-disabled":"{{ createOnly }}",description:F("Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.")},displayName:{type:"string",title:F("Data source display name"),required:!0,"x-decorator":"FormItem","x-component":"Input"},options:{type:"object",properties:{host:{type:"string",title:F("Host"),required:!0,"x-decorator":"FormItem","x-component":"Input",default:"localhost"},port:{type:"string",title:F("Port"),required:!0,"x-decorator":"FormItem","x-component":"Input",default:5432},database:{type:"string",title:F("Database"),required:!0,"x-decorator":"FormItem","x-component":"Input"},username:{type:"string",title:F("Username"),required:!0,"x-decorator":"FormItem","x-component":"Input"},password:{type:"string",title:F("Password"),"x-decorator":"FormItem","x-component":"Password"},tablePrefix:{type:"string",title:F("Table prefix"),"x-decorator":"FormItem","x-component":"Input"},schema:{type:"string",title:F("Schema"),"x-decorator":"FormItem","x-component":"Input"}}},enabled:{type:"string","x-content":F("Enabled the data source"),"x-decorator":"FormItem","x-component":"Checkbox",default:!0}}}})};class ae extends r.Plugin{afterAdd(){return M(this,null,function*(){this.app.pm.add(xt)})}load(){return M(this,null,function*(){this.app.pm.get(q.PluginDataSourceManagerClient).registerType("postgres",{DataSourceSettingsForm:ht,label:F("PostgreSQL")}),this.app.pm.get(q.PluginDataSourceManagerClient).registerType("mysql",{DataSourceSettingsForm:ft,label:F("MySQL")})})}}m.PluginExternalDataSourceClient=ae,m.default=ae,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/externalVersion.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
"@tachybase/client": "0.23.
|
|
3
|
-
"@tachybase/module-data-source": "0.23.
|
|
4
|
-
"@tachybase/server": "0.23.
|
|
2
|
+
"@tachybase/client": "0.23.16",
|
|
3
|
+
"@tachybase/module-data-source": "0.23.16",
|
|
4
|
+
"@tachybase/server": "0.23.16",
|
|
5
5
|
"react": "18.3.1",
|
|
6
6
|
"antd": "5.22.5",
|
|
7
7
|
"lodash": "4.17.21",
|
|
8
|
-
"@tachybase/database": "0.23.
|
|
9
|
-
"@tachybase/data-source": "0.23.
|
|
10
|
-
"@tachybase/utils": "0.23.
|
|
8
|
+
"@tachybase/database": "0.23.16",
|
|
9
|
+
"@tachybase/data-source": "0.23.16",
|
|
10
|
+
"@tachybase/utils": "0.23.16",
|
|
11
11
|
"axios": "1.7.9",
|
|
12
12
|
"@ant-design/icons": "5.5.2",
|
|
13
|
-
"@tachybase/schema": "0.23.
|
|
14
|
-
"@tachybase/components": "0.23.
|
|
13
|
+
"@tachybase/schema": "0.23.16",
|
|
14
|
+
"@tachybase/components": "0.23.16",
|
|
15
15
|
"react-router-dom": "6.28.1"
|
|
16
16
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { CollectionManager, CollectionOptions } from '@tachybase/data-source';
|
|
2
2
|
import { HttpCollection } from './http-collection';
|
|
3
3
|
export declare class HttpCollectionManager extends CollectionManager {
|
|
4
|
-
|
|
4
|
+
dataSource: any;
|
|
5
|
+
constructor(options?: {
|
|
6
|
+
dataSource?: any;
|
|
7
|
+
});
|
|
5
8
|
newCollection(options: CollectionOptions): HttpCollection;
|
|
6
9
|
}
|
|
@@ -23,8 +23,10 @@ module.exports = __toCommonJS(http_collection_manager_exports);
|
|
|
23
23
|
var import_data_source = require("@tachybase/data-source");
|
|
24
24
|
var import_http_collection = require("./http-collection");
|
|
25
25
|
class HttpCollectionManager extends import_data_source.CollectionManager {
|
|
26
|
+
dataSource;
|
|
26
27
|
constructor(options = {}) {
|
|
27
28
|
super(options);
|
|
29
|
+
this.dataSource = options.dataSource;
|
|
28
30
|
}
|
|
29
31
|
newCollection(options) {
|
|
30
32
|
return new import_http_collection.HttpCollection(options, this);
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { Collection } from '@tachybase/data-source';
|
|
2
|
+
import { HttpDataSource } from './http-data-source';
|
|
2
3
|
export declare class HttpCollection extends Collection {
|
|
3
4
|
availableActions(): string[];
|
|
4
|
-
static runAction(options:
|
|
5
|
+
static runAction(options: {
|
|
6
|
+
dataSource: HttpDataSource;
|
|
7
|
+
actionOptions: any;
|
|
8
|
+
templateContext?: any;
|
|
9
|
+
parseField?: boolean;
|
|
10
|
+
debugVars?: any;
|
|
11
|
+
runAsDebug?: boolean;
|
|
12
|
+
}): Promise<any>;
|
|
5
13
|
getActionOptions(action: any): any;
|
|
6
14
|
runAction(action: string, templateContext?: any): Promise<any>;
|
|
15
|
+
setRepository(repository: any): void;
|
|
7
16
|
}
|
|
@@ -237,11 +237,6 @@ class HttpCollection extends import_data_source.Collection {
|
|
|
237
237
|
}
|
|
238
238
|
};
|
|
239
239
|
transformResponse(baseResponse, actionOptions);
|
|
240
|
-
dataSource.logger.debug({
|
|
241
|
-
actionOptions,
|
|
242
|
-
requestConfig,
|
|
243
|
-
baseResponse
|
|
244
|
-
});
|
|
245
240
|
return handleResponse(baseResponse);
|
|
246
241
|
}
|
|
247
242
|
getActionOptions(action) {
|
|
@@ -263,6 +258,10 @@ class HttpCollection extends import_data_source.Collection {
|
|
|
263
258
|
templateContext
|
|
264
259
|
});
|
|
265
260
|
}
|
|
261
|
+
setRepository(repository) {
|
|
262
|
+
const repo = this.collectionManager.getRegisteredRepository("HttpApiRepository");
|
|
263
|
+
this.repository = new repo(this);
|
|
264
|
+
}
|
|
266
265
|
}
|
|
267
266
|
// Annotate the CommonJS export names for ESM import in node:
|
|
268
267
|
0 && (module.exports = {
|
|
@@ -47,7 +47,7 @@ class HttpDataSource extends import_data_source.DataSource {
|
|
|
47
47
|
dataSource: this
|
|
48
48
|
});
|
|
49
49
|
collectionManager.registerRepositories({
|
|
50
|
-
|
|
50
|
+
HttpApiRepository: import_http_api_repository.HttpApiRepository
|
|
51
51
|
});
|
|
52
52
|
return collectionManager;
|
|
53
53
|
}
|
package/dist/server/plugin.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(plugin_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(plugin_exports);
|
|
24
24
|
var import_server = require("@tachybase/server");
|
|
25
25
|
var import_plugin = require("./http/plugin");
|
|
26
|
+
var import_http_data_source = require("./http/services/http-data-source");
|
|
26
27
|
var import_mysql_data_source = require("./mysql/mysql-data-source");
|
|
27
28
|
var import_postgres_data_source = require("./pg/postgres-data-source");
|
|
28
29
|
class PluginExternalDataSourceServer extends import_server.Plugin {
|
|
@@ -35,6 +36,7 @@ class PluginExternalDataSourceServer extends import_server.Plugin {
|
|
|
35
36
|
async beforeLoad() {
|
|
36
37
|
this.app.dataSourceManager.factory.register("postgres", import_postgres_data_source.PostgresDataSource);
|
|
37
38
|
this.app.dataSourceManager.factory.register("mysql", import_mysql_data_source.MySQLDataSource);
|
|
39
|
+
this.app.dataSourceManager.factory.register("http", import_http_data_source.HttpDataSource);
|
|
38
40
|
}
|
|
39
41
|
async beforeEnable() {
|
|
40
42
|
const plugin = this.pm.get("data-source");
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/plugin-data-source-common",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.16",
|
|
4
4
|
"main": "dist/server/index.js",
|
|
5
|
-
"dependencies": {
|
|
5
|
+
"dependencies": {},
|
|
6
|
+
"devDependencies": {
|
|
6
7
|
"@ant-design/icons": "^5.5.2",
|
|
8
|
+
"@types/lodash": "^4.17.13",
|
|
7
9
|
"antd": "5.22.5",
|
|
8
10
|
"lodash": "^4.17.21",
|
|
9
11
|
"mysql2": "^3.11.5",
|
|
@@ -11,18 +13,16 @@
|
|
|
11
13
|
"react-i18next": "^15.2.0",
|
|
12
14
|
"react-router-dom": "6.28.1"
|
|
13
15
|
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"@types/lodash": "^4.17.13"
|
|
16
|
-
},
|
|
17
16
|
"peerDependencies": {
|
|
18
|
-
"@tachybase/client": "0.23.
|
|
19
|
-
"@tachybase/
|
|
20
|
-
"@tachybase/
|
|
21
|
-
"@tachybase/
|
|
22
|
-
"@tachybase/
|
|
23
|
-
"@tachybase/
|
|
24
|
-
"@tachybase/server": "0.23.
|
|
25
|
-
"@tachybase/
|
|
17
|
+
"@tachybase/client": "0.23.16",
|
|
18
|
+
"@tachybase/components": "0.23.16",
|
|
19
|
+
"@tachybase/data-source": "0.23.16",
|
|
20
|
+
"@tachybase/database": "0.23.16",
|
|
21
|
+
"@tachybase/module-data-source": "0.23.16",
|
|
22
|
+
"@tachybase/schema": "0.23.16",
|
|
23
|
+
"@tachybase/server": "0.23.16",
|
|
24
|
+
"@tachybase/test": "0.23.16",
|
|
25
|
+
"@tachybase/utils": "0.23.16"
|
|
26
26
|
},
|
|
27
27
|
"description.zh-CN": "支持更多的数据源",
|
|
28
28
|
"displayName.zh-CN": "外部数据源支持",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @tachybase/plugin-data-source-common@0.23.7 build /Users/seal/Documents/projects/tachybase/packages/plugin-data-source-common
|
|
4
|
-
> tachybase-build --no-dts @tachybase/plugin-data-source-common
|
|
5
|
-
|
|
6
|
-
[33m[33mThe CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.[39m[39m
|
|
7
|
-
[4m[95m@tachybase/plugin-data-source-common[39m[24m: [1mplugin-data-source-common[22m build start
|
|
8
|
-
[4m[95m@tachybase/plugin-data-source-common[39m[24m: build plugin client
|
|
9
|
-
[4m[95m@tachybase/plugin-data-source-common[39m[24m: build plugin server source
|
|
10
|
-
[4m[95m@tachybase/plugin-data-source-common[39m[24m: delete server files
|
|
11
|
-
[4m[95m@tachybase/plugin-data-source-common[39m[24m: build plugin server dependencies
|
|
12
|
-
[4m[95m@tachybase/plugin-data-source-common[39m[24m: These packages [33m@tachybase/server, lodash, @tachybase/database, @tachybase/module-data-source, @tachybase/data-source, @tachybase/utils, axios[39m will be [3mexclude[23m.
|
|
13
|
-
[4m[95m@tachybase/plugin-data-source-common[39m[24m: write external version
|
|
14
|
-
|