@tachybase/plugin-multi-app-share-collection 0.23.8
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/.turbo/turbo-build.log +14 -0
- package/LICENSE +201 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/MultiAppShareCollectionProvider.d.ts +2 -0
- package/dist/client/TableTransfer.d.ts +3 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +18 -0
- package/dist/client/utils.d.ts +4 -0
- package/dist/externalVersion.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +12 -0
- package/dist/locale/es-ES.json +12 -0
- package/dist/locale/ko_KR.json +12 -0
- package/dist/locale/pt-BR.json +12 -0
- package/dist/locale/zh-CN.json +12 -0
- package/dist/server/collections/applications.d.ts +2 -0
- package/dist/server/collections/applications.js +38 -0
- package/dist/server/collections/collections.d.ts +2 -0
- package/dist/server/collections/collections.js +38 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/migrations/20230319111111-update-apps-collections.d.ts +5 -0
- package/dist/server/migrations/20230319111111-update-apps-collections.js +83 -0
- package/dist/server/plugin.d.ts +8 -0
- package/dist/server/plugin.js +262 -0
- package/package.json +33 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @tachybase/plugin-multi-app-share-collection@0.23.2 build /Users/seal/Documents/projects/tachybase/packages/plugin-multi-app-share-collection
|
|
4
|
+
> tachybase-build --no-dts @tachybase/plugin-multi-app-share-collection
|
|
5
|
+
|
|
6
|
+
[33m[33mThe CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.[39m[39m
|
|
7
|
+
[4m[95m@tachybase/plugin-multi-app-share-collection[39m[24m: [1mplugin-multi-app-share-collection[22m build start
|
|
8
|
+
[4m[95m@tachybase/plugin-multi-app-share-collection[39m[24m: build plugin client
|
|
9
|
+
[4m[95m@tachybase/plugin-multi-app-share-collection[39m[24m: build plugin server source
|
|
10
|
+
[4m[95m@tachybase/plugin-multi-app-share-collection[39m[24m: delete server files
|
|
11
|
+
[4m[95m@tachybase/plugin-multi-app-share-collection[39m[24m: build plugin server dependencies
|
|
12
|
+
[4m[95m@tachybase/plugin-multi-app-share-collection[39m[24m: These packages [33m@tachybase/database, @tachybase/module-multi-app, @tachybase/server, lodash, @tachybase/utils[39m will be [3mexclude[23m.
|
|
13
|
+
[4m[95m@tachybase/plugin-multi-app-share-collection[39m[24m: write external version
|
|
14
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2023-2024] [Tachybase team]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/client.d.ts
ADDED
package/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/client/index.js');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
(function(o,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@tachybase/client"),require("react/jsx-runtime"),require("@tachybase/module-multi-app/client"),require("@tachybase/schema"),require("antd"),require("react"),require("@tachybase/utils/client"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","react/jsx-runtime","@tachybase/module-multi-app/client","@tachybase/schema","antd","react","@tachybase/utils/client","react-i18next"],t):(o=typeof globalThis!="undefined"?globalThis:o||self,t(o["@tachybase/plugin-multi-app-share-collection"]={},o["@tachybase/client"],o.jsxRuntime,o["@tachybase/module-multi-app"],o["@tachybase/schema"],o.antd,o.react,o["@tachybase/utils"],o["react-i18next"]))})(this,function(o,t,e,S,T,c,p,g,C){"use strict";var R=Object.defineProperty,$=Object.defineProperties;var ee=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var _=(o,t,e)=>t in o?R(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,q=(o,t)=>{for(var e in t||(t={}))te.call(t,e)&&_(o,e,t[e]);if(O)for(var e of O(t))oe.call(t,e)&&_(o,e,t[e]);return o},M=(o,t)=>$(o,ee(t));var D=(o,t,e)=>new Promise((S,T)=>{var c=C=>{try{g(e.next(C))}catch(v){T(v)}},p=C=>{try{g(e.throw(C))}catch(v){T(v)}},g=C=>C.done?S(C.value):Promise.resolve(C.value).then(c,p);g((e=e.apply(o,t)).next())});const v=["users","roles","applications"],B=({removed:a=[]})=>{const{collections:l}=t.useCollectionManager_deprecated(),s=p.useCallback(m=>g.CollectionsGraph.connectedNodes({collections:l,nodes:[m],excludes:v}).filter(r=>a.includes(r)),[a]),i=p.useCallback(m=>g.CollectionsGraph.connectedNodes({collections:l,nodes:[m],excludes:v,direction:"reverse"}).filter(r=>!a.includes(r)),[a]);return{findAddable:s,findRemovable:i}},E=()=>{var n,b;const a=t.useRecord(),[l,s]=p.useState([]),i=t.useRequest({url:`applications/${a.name}/collectionBlacklist:list`,params:{paginate:!1,params:{fields:["name"]}}},{onSuccess(h){var w;s((w=h.data)==null?void 0:w.map(f=>f.name))}}),m=t.useRequest({url:"collections",params:{fields:["name","title","hidden","category.name","category.color","category.sort"],sort:"sort",paginate:!1}}),r=t.useRequest({url:"collectionCategories",params:{sort:"sort",paginate:!1}});return{loading:i.loading||m.loading||r.loading,collections:(((n=m.data)==null?void 0:n.data)||[]).filter(h=>!h.hidden&&!v.includes(h.name)),removed:l,setSelected:s,categories:(((b=r.data)==null?void 0:b.data)||[]).map(h=>({label:h.name,value:h.name}))}},F=(a,l)=>{const s=Array.isArray(l)?l:[l];for(const i of s)if(a.toLowerCase().includes(i))return!0;return!1},W=({collections:a,removed:l})=>{const[s,i]=p.useState({name:"",category:[]}),m=p.useMemo(()=>a.filter(n=>{const{name:b,title:h,category:w=[]}=n,f=[l.includes(n.name)];return s.name&&f.push(F(b,s.name)||F(h,s.name)),s.category.length>0&&f.push(w.some(k=>F(k.name,s.category))),!f.includes(!1)}),[a,l,s]),r=p.useMemo(()=>g.lodash.debounce(n=>{i(M(q({},s),{name:n}))},300),[]);return{dataSource:m,setNameFilter:r,setCategoryFilter:n=>{i(M(q({},s),{category:n}))}}},U=({collections:a,removed:l})=>{const[s,i]=p.useState({name:"",category:[]}),m=a.filter(n=>{const{name:b,title:h,category:w=[]}=n,f=[!l.includes(n.name)];return s.name&&f.push(F(b,s.name)||F(h,s.name)),s.category.length>0&&f.push(w.some(k=>F(k.name,s.category))),!f.includes(!1)}),r=p.useMemo(()=>g.lodash.debounce(n=>{i(M(q({},s),{name:n}))},300),[]);return{dataSource:m,setNameFilter:r,setCategoryFilter:n=>{i(M(q({},s),{category:n}))}}},V=T.connect(a=>{const{onChange:l}=a,{loading:s,collections:i,categories:m,removed:r,setSelected:n}=E(),[b,h]=p.useState([]),[w,f]=p.useState([]),{findAddable:k,findRemovable:Y}=B({removed:r}),j=U({collections:i,removed:r}),I=W({collections:i,removed:r}),{t:y}=C.useTranslation("multi-app-share-collection"),{modal:L}=c.App.useApp(),{token:z}=t.useToken(),N=p.useMemo(()=>[{title:y("Collection display name"),dataIndex:"title"},{title:y("Collection name"),dataIndex:"name"},{title:y("Collection category"),dataIndex:"category",render:d=>d.map(u=>e.jsx(c.Tag,{color:u.color,children:u.name},u.name))}],[]);return s?e.jsx(c.Spin,{}):e.jsx("div",{children:e.jsxs(c.Row,{gutter:24,className:t.css`
|
|
2
|
+
.ant-table-tbody > tr.ant-table-row:hover > td {
|
|
3
|
+
background: #e6f7ff;
|
|
4
|
+
cursor: pointer;
|
|
5
|
+
}
|
|
6
|
+
`,children:[e.jsxs(c.Col,{span:12,children:[e.jsxs("div",{className:t.css`
|
|
7
|
+
display: flex;
|
|
8
|
+
justify-content: space-between;
|
|
9
|
+
align-items: center;
|
|
10
|
+
width: 100%;
|
|
11
|
+
margin-bottom: 8px;
|
|
12
|
+
`,children:[e.jsx("strong",{style:{fontSize:z.fontSizeLG,color:z.colorText},children:y("Unshared collections")}),e.jsxs(c.Space.Compact,{style:{width:360},children:[e.jsx(c.Select,{popupMatchSelectWidth:!1,onChange:d=>{I.setCategoryFilter(d)},mode:"multiple",style:{width:"35%"},size:"middle",placeholder:y("All categories"),options:m,allowClear:!0}),e.jsx(c.Input,{onChange:d=>I.setNameFilter(d.target.value),style:{width:"65%"},placeholder:y("Enter name or title..."),allowClear:!0})]})]}),e.jsx(c.Table,{bordered:!0,rowKey:"name",rowSelection:{type:"checkbox",selectedRowKeys:b,onChange(d){const u=r.filter(x=>!d.includes(x));n(u),l(u),h([])}},pagination:!1,size:"small",columns:N,dataSource:I.dataSource,scroll:{y:"calc(100vh - 260px)"},onRow:({name:d,disabled:u})=>({onClick:()=>{if(u)return;const x=k(d),A=()=>{const K=r.filter(Z=>!x.includes(Z));n(K),l(K)};if(x.length===1)return A();L.confirm({title:y("Are you sure to add the following collections?"),width:"60%",content:e.jsx("div",{children:e.jsx(c.Table,{size:"small",columns:N,dataSource:i.filter(K=>x.includes(K.name)),pagination:!1,scroll:{y:"60vh"}})}),onOk(){A()}})}})})]}),e.jsxs(c.Col,{span:12,children:[e.jsxs("div",{className:t.css`
|
|
13
|
+
display: flex;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
align-items: center;
|
|
16
|
+
width: 100%;
|
|
17
|
+
margin-bottom: 8px;
|
|
18
|
+
`,children:[e.jsx("strong",{style:{fontSize:z.fontSizeLG,color:z.colorText},children:y("Shared collections")}),e.jsxs(c.Space.Compact,{style:{width:360},children:[e.jsx(c.Select,{popupMatchSelectWidth:!1,onChange:d=>{j.setCategoryFilter(d)},mode:"multiple",style:{width:"35%"},size:"middle",placeholder:y("All categories"),options:m,allowClear:!0}),e.jsx(c.Input,{onChange:d=>j.setNameFilter(d.target.value),style:{width:"65%"},placeholder:y("Enter name or title..."),allowClear:!0})]})]}),e.jsx(c.Table,{bordered:!0,rowKey:"name",rowSelection:{type:"checkbox",selectedRowKeys:w,onChange(d){const u=g.lodash.uniq(r.concat(d));n(u),l(u),f([])}},pagination:!1,size:"small",columns:N,dataSource:j.dataSource,scroll:{y:"calc(100vh - 260px)"},onRow:({name:d})=>({onClick:()=>{const u=Y(d),x=()=>{r.push(...u);const A=g.lodash.uniq([...r]);n(A),l(A)};if(u.length===1)return x();L.confirm({title:y("Are you sure to remove the following collections?"),width:"60%",content:e.jsx("div",{children:e.jsx(c.Table,{size:"small",columns:N,dataSource:i.filter(A=>u.includes(A.name)),pagination:!1,scroll:{y:"60vh"}})}),onOk(){x()}})}})})]})]})})}),P=a=>`{{t("${a}", { ns: 'multi-app-share-collection' })}}`,H=()=>{const a=T.useForm(),l=t.useActionContext(),s=t.useAPIClient(),i=t.useRecord();return{run(){return D(this,null,function*(){console.log(a.values.names),yield s.request({url:`applications/${i.name}/collectionBlacklist`,data:a.values.names,method:"post"}),l.setVisible(!1),a.reset(),c.message.success("Saved successfully")})}}},J=S.tableActionColumnSchema.properties.update,Q=S.tableActionColumnSchema.properties.delete;delete S.tableActionColumnSchema.properties.update,delete S.tableActionColumnSchema.properties.delete,S.tableActionColumnSchema.properties.collection={type:"void",title:P("Share collections"),"x-component":"Action.Link","x-component-props":{},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-component-props":{width:"95vw"},"x-decorator":"Form",title:P("Share collections"),properties:{names:{type:"array","x-component":V,"x-decorator":"FormItem"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:H}}}}}}}},S.tableActionColumnSchema.properties.update=J,S.tableActionColumnSchema.properties.delete=Q;const X=a=>e.jsx(e.Fragment,{children:a.children});class G extends t.Plugin{load(){return D(this,null,function*(){this.app.use(X)})}}o.MultiAppShareCollectionPlugin=G,o.default=G,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
"react": "18.3.1",
|
|
3
|
+
"@tachybase/client": "0.23.8",
|
|
4
|
+
"@tachybase/module-multi-app": "0.23.8",
|
|
5
|
+
"@tachybase/schema": "0.23.8",
|
|
6
|
+
"antd": "5.22.5",
|
|
7
|
+
"@tachybase/utils": "0.23.8",
|
|
8
|
+
"react-i18next": "15.2.0",
|
|
9
|
+
"@tachybase/database": "0.23.8",
|
|
10
|
+
"@tachybase/server": "0.23.8",
|
|
11
|
+
"lodash": "4.17.21"
|
|
12
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
default: () => import_server.default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(src_exports);
|
|
34
|
+
__reExport(src_exports, require("./server"), module.exports);
|
|
35
|
+
var import_server = __toESM(require("./server"));
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
...require("./server")
|
|
39
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"All categories": "All categories",
|
|
3
|
+
"Are you sure to add the following collections?": "Are you sure to add the following collections?",
|
|
4
|
+
"Are you sure to remove the following collections?": "Are you sure to remove the following collections?",
|
|
5
|
+
"Collection category": "Collection category",
|
|
6
|
+
"Collection display name": "Collection display name",
|
|
7
|
+
"Collection name": "Collection name",
|
|
8
|
+
"Enter name or title...": "Enter name or title...",
|
|
9
|
+
"Share collections": "Share collections",
|
|
10
|
+
"Shared collections": "Shared collections",
|
|
11
|
+
"Unshared collections": "Unshared collections"
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"All categories": "Todas las categorías",
|
|
3
|
+
"Are you sure to add the following collections?": "¿Está seguro de que desea añadir las siguientes tablas?",
|
|
4
|
+
"Are you sure to remove the following collections?": "¿Está seguro de que desea eliminar las siguientes tablas?",
|
|
5
|
+
"Collection category": "Categoría de tabla",
|
|
6
|
+
"Collection display name": "Mostrar nombre de la tabla",
|
|
7
|
+
"Collection name": "Nombre de la tabla",
|
|
8
|
+
"Enter name or title...": "Introducir nombre o título...",
|
|
9
|
+
"Share collections": "Tablas compartidas",
|
|
10
|
+
"Shared collections": "Tablas compartidas",
|
|
11
|
+
"Unshared collections": "Tablas no compartidas"
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"All categories": "모든 카테고리",
|
|
3
|
+
"Are you sure to add the following collections?": "다음 데이터 테이블을 추가하시겠습니까?",
|
|
4
|
+
"Are you sure to remove the following collections?": "다음 데이터 테이블을 제거하시겠습니까?",
|
|
5
|
+
"Collection category": "카테고리",
|
|
6
|
+
"Collection display name": "제목",
|
|
7
|
+
"Collection name": "식별자",
|
|
8
|
+
"Enter name or title...": "이름 또는 제목 입력...",
|
|
9
|
+
"Share collections": "데이터 테이블 공유",
|
|
10
|
+
"Shared collections": "공유된 데이터 테이블",
|
|
11
|
+
"Unshared collections": "공유되지 않은 데이터 테이블"
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"All categories": "Todas as categorias",
|
|
3
|
+
"Are you sure to add the following collections?": "Tem certeza de que deseja adicionar as seguintes tabelas?",
|
|
4
|
+
"Are you sure to remove the following collections?": "Tem certeza de que deseja remover as seguintes tabelas?",
|
|
5
|
+
"Collection category": "Categoria da tabela",
|
|
6
|
+
"Collection display name": "Nome de exibição da tabela",
|
|
7
|
+
"Collection name": "Nome da tabela",
|
|
8
|
+
"Enter name or title...": "Digite o nome ou título...",
|
|
9
|
+
"Share collections": "Compartilhar tabelas",
|
|
10
|
+
"Shared collections": "Tabelas compartilhadas",
|
|
11
|
+
"Unshared collections": "Tabelas não compartilhadas"
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"All categories": "所有分类",
|
|
3
|
+
"Are you sure to add the following collections?": "确定添加以下数据表?",
|
|
4
|
+
"Are you sure to remove the following collections?": "确定移除以下数据表?",
|
|
5
|
+
"Collection category": "分类",
|
|
6
|
+
"Collection display name": "标题",
|
|
7
|
+
"Collection name": "标识",
|
|
8
|
+
"Enter name or title...": "输入数据表标题或标识",
|
|
9
|
+
"Share collections": "共享数据表",
|
|
10
|
+
"Shared collections": "已共享的数据表",
|
|
11
|
+
"Unshared collections": "未共享的数据表"
|
|
12
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var applications_exports = {};
|
|
19
|
+
__export(applications_exports, {
|
|
20
|
+
default: () => applications_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(applications_exports);
|
|
23
|
+
var import_database = require("@tachybase/database");
|
|
24
|
+
var applications_default = (0, import_database.extendCollection)({
|
|
25
|
+
name: "applications",
|
|
26
|
+
fields: [
|
|
27
|
+
{
|
|
28
|
+
type: "belongsToMany",
|
|
29
|
+
name: "collectionBlacklist",
|
|
30
|
+
through: "appCollectionBlacklist",
|
|
31
|
+
target: "collections",
|
|
32
|
+
targetKey: "name",
|
|
33
|
+
otherKey: "collectionName",
|
|
34
|
+
sourceKey: "name",
|
|
35
|
+
foreignKey: "applicationName"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var collections_exports = {};
|
|
19
|
+
__export(collections_exports, {
|
|
20
|
+
default: () => collections_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(collections_exports);
|
|
23
|
+
var import_database = require("@tachybase/database");
|
|
24
|
+
var collections_default = (0, import_database.extendCollection)({
|
|
25
|
+
name: "collections",
|
|
26
|
+
fields: [
|
|
27
|
+
{
|
|
28
|
+
type: "belongsToMany",
|
|
29
|
+
name: "collectionBlacklist",
|
|
30
|
+
through: "appCollectionBlacklist",
|
|
31
|
+
target: "applications",
|
|
32
|
+
targetKey: "name",
|
|
33
|
+
otherKey: "applicationName",
|
|
34
|
+
sourceKey: "name",
|
|
35
|
+
foreignKey: "collectionName"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './plugin';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => import_plugin.default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var update_apps_collections_exports = {};
|
|
19
|
+
__export(update_apps_collections_exports, {
|
|
20
|
+
default: () => update_apps_collections_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(update_apps_collections_exports);
|
|
23
|
+
var import_server = require("@tachybase/server");
|
|
24
|
+
var import_utils = require("@tachybase/utils");
|
|
25
|
+
class update_apps_collections_default extends import_server.Migration {
|
|
26
|
+
appVersion = "<0.9.3-alpha.1";
|
|
27
|
+
async up() {
|
|
28
|
+
const result = await this.app.version.satisfies("<0.9.3-alpha.1");
|
|
29
|
+
if (!result) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!this.app.db.getCollection("applications")) return;
|
|
33
|
+
await this.app.db.getCollection("collections").repository.destroy({
|
|
34
|
+
where: {
|
|
35
|
+
name: "applications"
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const appSyncedCollections = /* @__PURE__ */ new Map();
|
|
39
|
+
const collections = await this.app.db.getCollection("collections").repository.find();
|
|
40
|
+
const collectionsData = collections.map((collection) => collection.toJSON());
|
|
41
|
+
for (const collection of collections) {
|
|
42
|
+
const collectionSyncToApps = collection.get("syncToApps");
|
|
43
|
+
if (collectionSyncToApps) {
|
|
44
|
+
for (const app of collectionSyncToApps) {
|
|
45
|
+
if (!appSyncedCollections.has(app)) {
|
|
46
|
+
appSyncedCollections.set(app, /* @__PURE__ */ new Set());
|
|
47
|
+
}
|
|
48
|
+
appSyncedCollections.get(app).add(collection.name);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const allCollections = collections.map((collection) => collection.name);
|
|
53
|
+
const appCollectionBlacklist = this.app.db.getCollection("appCollectionBlacklist");
|
|
54
|
+
for (const [app, syncedCollections] of appSyncedCollections) {
|
|
55
|
+
const blackListCollections = allCollections.filter(
|
|
56
|
+
(collection) => !syncedCollections.has(collection) && !["users", "roles"].includes(collection)
|
|
57
|
+
);
|
|
58
|
+
const connectedCollections = import_utils.CollectionsGraph.connectedNodes({
|
|
59
|
+
collections: collectionsData,
|
|
60
|
+
nodes: blackListCollections,
|
|
61
|
+
direction: "reverse"
|
|
62
|
+
});
|
|
63
|
+
console.log(
|
|
64
|
+
JSON.stringify(
|
|
65
|
+
{
|
|
66
|
+
app,
|
|
67
|
+
connectedCollections
|
|
68
|
+
},
|
|
69
|
+
null,
|
|
70
|
+
2
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
await appCollectionBlacklist.model.bulkCreate(
|
|
74
|
+
connectedCollections.map((collection) => {
|
|
75
|
+
return {
|
|
76
|
+
applicationName: app,
|
|
77
|
+
collectionName: collection
|
|
78
|
+
};
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Plugin } from '@tachybase/server';
|
|
2
|
+
export declare class MultiAppShareCollectionPlugin extends Plugin {
|
|
3
|
+
afterAdd(): void;
|
|
4
|
+
beforeEnable(): Promise<void>;
|
|
5
|
+
beforeLoad(): Promise<void>;
|
|
6
|
+
load(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export default MultiAppShareCollectionPlugin;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var plugin_exports = {};
|
|
29
|
+
__export(plugin_exports, {
|
|
30
|
+
MultiAppShareCollectionPlugin: () => MultiAppShareCollectionPlugin,
|
|
31
|
+
default: () => plugin_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
34
|
+
var import_module_multi_app = __toESM(require("@tachybase/module-multi-app"));
|
|
35
|
+
var import_server = require("@tachybase/server");
|
|
36
|
+
var import_lodash = __toESM(require("lodash"));
|
|
37
|
+
const subAppFilteredPlugins = ["multi-app-share-collection", "multi-app-manager"];
|
|
38
|
+
const unSyncPlugins = ["localization-management"];
|
|
39
|
+
class SubAppPlugin extends import_server.Plugin {
|
|
40
|
+
beforeLoad() {
|
|
41
|
+
const mainApp = this.options.mainApp;
|
|
42
|
+
const subApp = this.app;
|
|
43
|
+
const sharedCollections = [];
|
|
44
|
+
for (const collection of mainApp.db.collections.values()) {
|
|
45
|
+
if (collection.options.shared) {
|
|
46
|
+
sharedCollections.push(collection.name);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
subApp.on("beforeLoadPlugin", (plugin) => {
|
|
50
|
+
if (plugin.name === "collection-manager") {
|
|
51
|
+
plugin.setLoadFilter({
|
|
52
|
+
"name.$ne": "roles"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
subApp.db.on("beforeDefineCollection", (options) => {
|
|
57
|
+
const name = options.name;
|
|
58
|
+
if (sharedCollections.includes(name)) {
|
|
59
|
+
options.schema = mainApp.db.options.schema || "public";
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
this.app.resourcer.use(async (ctx, next) => {
|
|
63
|
+
const { actionName, resourceName } = ctx.action;
|
|
64
|
+
if (actionName === "list" && resourceName === "applicationPlugins") {
|
|
65
|
+
ctx.action.mergeParams({
|
|
66
|
+
filter: {
|
|
67
|
+
"name.$notIn": subAppFilteredPlugins
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (actionName === "list" && resourceName === "collections") {
|
|
72
|
+
const appCollectionBlacklistCollection = mainApp.db.getCollection("appCollectionBlacklist");
|
|
73
|
+
const blackList = await appCollectionBlacklistCollection.model.findAll({
|
|
74
|
+
where: {
|
|
75
|
+
applicationName: subApp.name
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (blackList.length > 0) {
|
|
79
|
+
ctx.action.mergeParams({
|
|
80
|
+
filter: {
|
|
81
|
+
"name.$notIn": blackList.map((item) => item.get("collectionName"))
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
await next();
|
|
87
|
+
});
|
|
88
|
+
subApp.on("beforeInstall", async () => {
|
|
89
|
+
await subApp.db.sync();
|
|
90
|
+
const subAppPluginsCollection = subApp.db.getCollection("applicationPlugins");
|
|
91
|
+
const mainAppPluginsCollection = mainApp.db.getCollection("applicationPlugins");
|
|
92
|
+
await subApp.db.sequelize.query(`TRUNCATE ${subAppPluginsCollection.quotedTableName()}`);
|
|
93
|
+
const columnsInfo = await subApp.db.sequelize.getQueryInterface().describeTable(subAppPluginsCollection.getTableNameWithSchema());
|
|
94
|
+
const columns = Object.keys(columnsInfo).sort();
|
|
95
|
+
const columnsInSql = columns.map((column) => `"${column}"`).join(", ");
|
|
96
|
+
await subApp.db.sequelize.query(`
|
|
97
|
+
INSERT INTO ${subAppPluginsCollection.quotedTableName()} (${columnsInSql})
|
|
98
|
+
SELECT ${columnsInSql}
|
|
99
|
+
FROM ${mainAppPluginsCollection.quotedTableName()}
|
|
100
|
+
WHERE "name" not in ('multi-app-manager', 'multi-app-share-collection');
|
|
101
|
+
`);
|
|
102
|
+
const sequenceNameSql = `SELECT pg_get_serial_sequence('"${subAppPluginsCollection.collectionSchema()}"."${subAppPluginsCollection.model.tableName}"', 'id')`;
|
|
103
|
+
const sequenceName = await subApp.db.sequelize.query(sequenceNameSql, { type: "SELECT" });
|
|
104
|
+
await subApp.db.sequelize.query(`
|
|
105
|
+
SELECT setval('${sequenceName[0]["pg_get_serial_sequence"]}', (SELECT max("id") FROM ${subAppPluginsCollection.quotedTableName()}));
|
|
106
|
+
`);
|
|
107
|
+
await subApp.reload();
|
|
108
|
+
console.log(`sync plugins from ${mainApp.name} app to sub app ${subApp.name}`);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
class MultiAppShareCollectionPlugin extends import_server.Plugin {
|
|
113
|
+
afterAdd() {
|
|
114
|
+
}
|
|
115
|
+
async beforeEnable() {
|
|
116
|
+
if (!this.db.inDialect("postgres")) {
|
|
117
|
+
throw new Error("multi-app-share-collection plugin only support postgres");
|
|
118
|
+
}
|
|
119
|
+
const plugin = this.pm.get("multi-app-manager");
|
|
120
|
+
if (!plugin.enabled) {
|
|
121
|
+
throw new Error(`${this.name} plugin need multi-app-manager plugin enabled`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async beforeLoad() {
|
|
125
|
+
if (!this.db.inDialect("postgres")) {
|
|
126
|
+
throw new Error("multi-app-share-collection plugin only support postgres");
|
|
127
|
+
}
|
|
128
|
+
const traverseSubApps = async (callback, options) => {
|
|
129
|
+
if (import_lodash.default.get(options, "loadFromDatabase")) {
|
|
130
|
+
for (const application of await this.app.db.getCollection("applications").repository.find()) {
|
|
131
|
+
const appName = application.get("name");
|
|
132
|
+
const subApp = await import_server.AppSupervisor.getInstance().getApp(appName);
|
|
133
|
+
await callback(subApp);
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const subApps = [...import_server.AppSupervisor.getInstance().subApps()];
|
|
138
|
+
for (const subApp of subApps) {
|
|
139
|
+
await callback(subApp);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const mainApp = this.app;
|
|
143
|
+
function addPluginToSubApp(app) {
|
|
144
|
+
if (app.name !== "main") {
|
|
145
|
+
app.plugin(SubAppPlugin, { name: "sub-app", mainApp });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (import_server.AppSupervisor.getInstance().listeners("afterAppAdded").filter((f) => f.name === addPluginToSubApp.name).length === 0) {
|
|
149
|
+
import_server.AppSupervisor.getInstance().on("afterAppAdded", addPluginToSubApp);
|
|
150
|
+
}
|
|
151
|
+
this.app.db.on("users.afterCreateWithAssociations", async (model, options) => {
|
|
152
|
+
await traverseSubApps(async (subApp) => {
|
|
153
|
+
const { transaction } = options;
|
|
154
|
+
const repository = subApp.db.getRepository("roles");
|
|
155
|
+
const subAppUserModel = await subApp.db.getCollection("users").repository.findOne({
|
|
156
|
+
filter: {
|
|
157
|
+
id: model.get("id")
|
|
158
|
+
},
|
|
159
|
+
transaction
|
|
160
|
+
});
|
|
161
|
+
const defaultRole = await repository.findOne({
|
|
162
|
+
filter: {
|
|
163
|
+
default: true
|
|
164
|
+
},
|
|
165
|
+
transaction
|
|
166
|
+
});
|
|
167
|
+
if (defaultRole && await subAppUserModel.countRoles({ transaction }) === 0) {
|
|
168
|
+
await subAppUserModel.addRoles(defaultRole, { transaction });
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
this.app.on("__restarted", () => {
|
|
173
|
+
traverseSubApps((subApp) => {
|
|
174
|
+
subApp.runCommand("restart");
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
this.app.on("afterEnablePlugin", (pluginNames) => {
|
|
178
|
+
traverseSubApps((subApp) => {
|
|
179
|
+
for (const pluginName of import_lodash.default.castArray(pluginNames)) {
|
|
180
|
+
if (subAppFilteredPlugins.includes(pluginName)) return;
|
|
181
|
+
subApp.runAsCLI(["pm", "enable", pluginName], { from: "user" });
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
this.app.on("afterDisablePlugin", (pluginNames) => {
|
|
186
|
+
traverseSubApps((subApp) => {
|
|
187
|
+
for (const pluginName of import_lodash.default.castArray(pluginNames)) {
|
|
188
|
+
if (subAppFilteredPlugins.includes(pluginName)) return;
|
|
189
|
+
subApp.runAsCLI(["pm", "disable", pluginName], { from: "user" });
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
this.app.db.on(`afterRemoveCollection`, (collection) => {
|
|
194
|
+
const subApps = [...import_server.AppSupervisor.getInstance().subApps()];
|
|
195
|
+
for (const subApp of subApps) {
|
|
196
|
+
if (subApp.db.hasCollection(collection.name)) {
|
|
197
|
+
subApp.db.removeCollection(collection.name);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
async load() {
|
|
203
|
+
const multiAppManager = this.app.getPlugin("multi-app-manager");
|
|
204
|
+
if (!multiAppManager) {
|
|
205
|
+
this.app.logger.warn("multi-app-share-collection plugin need multi-app-manager plugin enabled");
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this.app.resourcer.registerActionHandlers({
|
|
209
|
+
"applications:shareCollections": async (ctx, next) => {
|
|
210
|
+
const { filterByTk, values } = ctx.action.params;
|
|
211
|
+
ctx.body = {
|
|
212
|
+
filterByTk,
|
|
213
|
+
values
|
|
214
|
+
};
|
|
215
|
+
await next();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
multiAppManager.setAppOptionsFactory((appName, mainApp) => {
|
|
219
|
+
const mainAppDbConfig = import_module_multi_app.default.getDatabaseConfig(mainApp);
|
|
220
|
+
const databaseOptions = {
|
|
221
|
+
...mainAppDbConfig,
|
|
222
|
+
schema: appName
|
|
223
|
+
};
|
|
224
|
+
const plugins = [...mainApp.pm.getAliases()].filter(
|
|
225
|
+
(name) => name !== "multi-app-manager" && name !== "multi-app-share-collection"
|
|
226
|
+
);
|
|
227
|
+
return {
|
|
228
|
+
database: import_lodash.default.merge(databaseOptions, {
|
|
229
|
+
dialectOptions: {
|
|
230
|
+
application_name: `tachybase.${appName}`
|
|
231
|
+
}
|
|
232
|
+
}),
|
|
233
|
+
plugins: plugins.includes("tachybase") ? ["tachybase"] : plugins,
|
|
234
|
+
resourcer: {
|
|
235
|
+
prefix: process.env.API_BASE_PATH
|
|
236
|
+
},
|
|
237
|
+
logger: {
|
|
238
|
+
...mainApp.options.logger,
|
|
239
|
+
requestWhitelist: [
|
|
240
|
+
"action",
|
|
241
|
+
"header.x-role",
|
|
242
|
+
"header.x-hostname",
|
|
243
|
+
"header.x-timezone",
|
|
244
|
+
"header.x-locale",
|
|
245
|
+
"referer",
|
|
246
|
+
"header.x-app"
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
// pmSock: resolve(process.cwd(), 'storage', `${appName}.sock`),
|
|
250
|
+
};
|
|
251
|
+
});
|
|
252
|
+
multiAppManager.setAppDbCreator(async (app) => {
|
|
253
|
+
const schema = app.options.database.schema;
|
|
254
|
+
await this.app.db.sequelize.query(`CREATE SCHEMA IF NOT EXISTS ${schema}`);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
var plugin_default = MultiAppShareCollectionPlugin;
|
|
259
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
260
|
+
0 && (module.exports = {
|
|
261
|
+
MultiAppShareCollectionPlugin
|
|
262
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tachybase/plugin-multi-app-share-collection",
|
|
3
|
+
"displayName": "Multi-app share collection",
|
|
4
|
+
"version": "0.23.8",
|
|
5
|
+
"description": "",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"System management"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/server/index.js",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"antd": "5.22.5",
|
|
12
|
+
"lodash": "4.17.21",
|
|
13
|
+
"react": "~18.3.1",
|
|
14
|
+
"react-i18next": "^15.2.0",
|
|
15
|
+
"@tachybase/schema": "0.23.8"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@tachybase/client": "0.23.8",
|
|
19
|
+
"@tachybase/database": "0.23.8",
|
|
20
|
+
"@tachybase/server": "0.23.8",
|
|
21
|
+
"@tachybase/test": "0.23.8",
|
|
22
|
+
"@tachybase/module-user": "0.23.8",
|
|
23
|
+
"@tachybase/utils": "0.23.8",
|
|
24
|
+
"@tachybase/module-collection": "0.23.8",
|
|
25
|
+
"@tachybase/module-error-handler": "0.23.8",
|
|
26
|
+
"@tachybase/module-multi-app": "0.23.8"
|
|
27
|
+
},
|
|
28
|
+
"description.zh-CN": "多应用数据共享",
|
|
29
|
+
"displayName.zh-CN": "多应用数据共享",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tachybase-build --no-dts @tachybase/plugin-multi-app-share-collection"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|