@nocobase/plugin-field-m2m-array 1.3.0-alpha.20240710155619
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/LICENSE.txt +124 -0
- package/README.md +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/ForeignKey.d.ts +10 -0
- package/dist/client/TargetKey.d.ts +10 -0
- package/dist/client/hooks.d.ts +12 -0
- package/dist/client/index.d.ts +15 -0
- package/dist/client/index.js +10 -0
- package/dist/client/locale.d.ts +9 -0
- package/dist/client/mbm.d.ts +133 -0
- package/dist/externalVersion.js +20 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +4 -0
- package/dist/locale/zh-CN.json +4 -0
- package/dist/server/belongs-to-array-field.d.ts +28 -0
- package/dist/server/belongs-to-array-field.js +137 -0
- package/dist/server/hooks/before-destroy-foreign-key.d.ts +12 -0
- package/dist/server/hooks/before-destroy-foreign-key.js +60 -0
- package/dist/server/hooks/create-foreign-key.d.ts +12 -0
- package/dist/server/hooks/create-foreign-key.js +83 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +42 -0
- package/dist/server/plugin.d.ts +19 -0
- package/dist/server/plugin.js +68 -0
- package/package.json +16 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Updated Date: June 19, 2024
|
|
2
|
+
|
|
3
|
+
NocoBase License Agreement
|
|
4
|
+
|
|
5
|
+
NocoBase Co., Ltd. ("The Company") https://www.nocobase.com/ issues this License Agreement ("Agreement") to you. You, as an individual or a company ("User"), will be deemed to voluntarily accept all terms of this Agreement by using NocoBase (including but not limited to obtaining NocoBase source code or installation package in any form, installing and using NocoBase, purchasing NocoBase commercial license and services, purchasing NocoBase commercial plugins). If the User does not agree to any term of this Agreement, or cannot accurately understand our interpretation of the relevant terms, please stop using it immediately.
|
|
6
|
+
|
|
7
|
+
This Agreement applies to any use, quotation, contract, invoice, and all software delivered by the Company. The User and the Company or NocoBase's agents can no longer sign a separate license agreement for the sale and delivery of the software.
|
|
8
|
+
|
|
9
|
+
The Company reserves the right to formulate and modify this Agreement from time to time as needed. If there are changes, the Company will announce them in the form of website announcements, without further individual notification. The changed Agreement will automatically take effect once it is announced, becoming part of this Agreement.
|
|
10
|
+
|
|
11
|
+
==============
|
|
12
|
+
1. Definitions
|
|
13
|
+
==============
|
|
14
|
+
1.1 "Software" refers to the NocoBase kernel and plugins placed in the same code repository as the kernel, including their source code, installation packages, images, and all their modifications, updates, and upgrades.
|
|
15
|
+
|
|
16
|
+
1.2 "Plugin Market" refers to the market provided by the Company for selling Software plugins and solutions.
|
|
17
|
+
|
|
18
|
+
1.3 "Commercial Plugin" refers to the paid plugins provided by the Plugin Market.
|
|
19
|
+
|
|
20
|
+
1.4 "Root Version" refers to the major version number before the first point in the version number. For example, from 1.0 to 1.x are all the same Root Version 1.
|
|
21
|
+
|
|
22
|
+
1.5 "Plugin Package" is the unit for batch licensing Commercial Plugins. P5, P10, and P20 Plugin Packages include installation packages for 5, 10, and 20 Commercial Plugins respectively. P5+, P10+, P20+ provide the source code of the Plugins in addition to the installation packages.
|
|
23
|
+
|
|
24
|
+
1.6 "Upper Layer Application" refers to a specific business use case application serving internal or external customers of the User, developed based on Software and Commercial Plugins, such as ERP/CRM.
|
|
25
|
+
|
|
26
|
+
1.7 "Third-Party Open Source Software" refers to open source software provided with Software and Commercial Plugins. They are licensed through various published open source software licenses or copyright notices accompanying such software.
|
|
27
|
+
|
|
28
|
+
===================================
|
|
29
|
+
2. Intellectual Property Protection
|
|
30
|
+
===================================
|
|
31
|
+
|
|
32
|
+
Except for Third-Party Open Source Software, the Company owns all copyrights, trademark rights, patent rights, trade secrets, and other intellectual property rights of the Software and Commercial Plugins, and has registered and protected them in relevant countries and regions according to the "Paris Convention" or "TRIPS Agreement", ensuring that the intellectual property rights of the Software and Commercial Plugins are internationally recognized and protected.
|
|
33
|
+
|
|
34
|
+
=============
|
|
35
|
+
3. Disclaimer
|
|
36
|
+
=============
|
|
37
|
+
|
|
38
|
+
3.1 Users shall not use the Software and Commercial Plugins to engage in activities that violate local laws and regulations, religious beliefs. All legal responsibilities and legal consequences arising from the use of Software and Commercial Plugins shall be borne by the User.
|
|
39
|
+
|
|
40
|
+
3.2 The Company shall not be liable for any direct, indirect, special, incidental, or consequential damages (including but not limited to loss of profits, business interruption, data loss, or business information disclosure) caused by the User's use of the Software and Commercial Plugins, even if it has been previously informed of the possibility of such damages.
|
|
41
|
+
|
|
42
|
+
===============
|
|
43
|
+
4. License Type
|
|
44
|
+
===============
|
|
45
|
+
|
|
46
|
+
4.1 The Software uses a dual license type of AGPL-3.0 Open Source License https://www.gnu.org/licenses/agpl-3..en.htm and Commercial License.
|
|
47
|
+
|
|
48
|
+
4.2 Commercial Plugins use Commercial License.
|
|
49
|
+
|
|
50
|
+
================================================
|
|
51
|
+
5. Rights and Obligations of Open Source License
|
|
52
|
+
================================================
|
|
53
|
+
|
|
54
|
+
5.1 The Software can be used for commercial purposes, such as developing applications for internal use within a company or for clients.
|
|
55
|
+
|
|
56
|
+
5.2 User can sell plugins developed for the Software in the Plugin Market.
|
|
57
|
+
|
|
58
|
+
5.3 Outside the Plugin Market, changes and plugins to the Software developed by User or third parties, and third-party software integrated with the Software must all be open sourced under the AGPL-3.0 license.
|
|
59
|
+
|
|
60
|
+
5.4 It is not allowed to remove or change the brand, name, link, version number, license, and other information about NocoBase on the Software interface, except for the main LOGO in the upper left corner of the page.
|
|
61
|
+
|
|
62
|
+
5.5 It is not allowed to remove or change all intellectual property statements about NocoBase in the code.
|
|
63
|
+
|
|
64
|
+
5.6 It is not allowed to provide any form of no-code, zero-code, low-code platform SaaS products to the public using the original or modified Software.
|
|
65
|
+
|
|
66
|
+
5.7 Comply with all requirements of the AGPL-3.0 agreement.
|
|
67
|
+
|
|
68
|
+
===============================
|
|
69
|
+
6. Rights of Commercial License
|
|
70
|
+
===============================
|
|
71
|
+
|
|
72
|
+
6.1 Obtain a permanent commercial license for a Root Version of the Software or Commercial Plugin.
|
|
73
|
+
|
|
74
|
+
6.2 Get 6 months of exclusive technical support.
|
|
75
|
+
|
|
76
|
+
6.3 Upgrade to the next Root Version at 50% of the contract price.
|
|
77
|
+
|
|
78
|
+
6.4 The licensed Software and Commercial Plugins can be used for commercial purposes, such as developing applications for internal use within a company or for clients, with no restrictions on the number of applications and users.
|
|
79
|
+
|
|
80
|
+
6.5 Changes and plugins to the Software, and applications integrated with the Software do not need to be open sourced.
|
|
81
|
+
|
|
82
|
+
6.6 Can remove or change the brand, name, link, version number, license, and other information about NocoBase on the Software interface.
|
|
83
|
+
|
|
84
|
+
6.7 Can sell plugins developed for Software in the Plugin Market.
|
|
85
|
+
|
|
86
|
+
6.8 Can sell or provide Upper Layer Applications developed based on Software in the form of SaaS to the public.
|
|
87
|
+
|
|
88
|
+
6.9 Not restricted by the AGPL-3.0 agreement.
|
|
89
|
+
|
|
90
|
+
6.10 If there are other agreements in the contract for the above rights, the contract agreement shall prevail.
|
|
91
|
+
|
|
92
|
+
====================================
|
|
93
|
+
7. Obligations of Commercial License
|
|
94
|
+
====================================
|
|
95
|
+
|
|
96
|
+
7.1 It is not allowed to remove or change all intellectual property statements about NocoBase in the code.
|
|
97
|
+
|
|
98
|
+
7.2 It is not allowed to sell, transfer, lease, share, or give away the Commercial License.
|
|
99
|
+
|
|
100
|
+
7.3 It is not allowed to sell, transfer, lease, share, or give away any form of no-code, zero-code, low-code platform, or developer tools developed based on Software.
|
|
101
|
+
|
|
102
|
+
7.4 It is not allowed to provide any form of no-code, zero-code, low-code platform SaaS products to the public using the original or modified Software.
|
|
103
|
+
|
|
104
|
+
7.5 It is not allowed to use reverse engineering, decompilation, and other means to try to discover the source code of Commercial Plugins that have not obtained source code license.
|
|
105
|
+
|
|
106
|
+
7.6 It is not allowed to disclose the source code of Commercial Plugins to any third party.
|
|
107
|
+
|
|
108
|
+
7.7 It is not allowed to publicly sell plugins developed for Software outside of the Plugin Market.
|
|
109
|
+
|
|
110
|
+
7.8 If there is a violation of the above obligations or the terms of this Agreement, the rights owned by the User will be immediately terminated, the paid fees will not be refunded, and the Company reserves the right to pursue the User's legal responsibility.
|
|
111
|
+
|
|
112
|
+
7.9 If there are other agreements in the contract for the above obligations, the contract agreement shall prevail.
|
|
113
|
+
|
|
114
|
+
=============================================================
|
|
115
|
+
8. Legal Jurisdiction, Interpretation, and Dispute Resolution
|
|
116
|
+
=============================================================
|
|
117
|
+
|
|
118
|
+
8.1 Except for Mainland China, the interpretation, application, and all matters related to this agreement are subject to the jurisdiction of Singapore law.
|
|
119
|
+
|
|
120
|
+
8.2 Any dispute related to this Agreement should first be resolved through friendly negotiation. If the negotiation fails to resolve the dispute, the dispute should be submitted to the International Chamber of Commerce (ICC) for arbitration. The arbitration venue should be Singapore, conducted in English.
|
|
121
|
+
|
|
122
|
+
8.3 All terms and conditions of this Agreement shall be deemed enforceable to the maximum extent permitted by applicable law. If any term of this Agreement is deemed invalid by any applicable law, the invalidity of that term does not affect the validity of any other term of this Agreement, and it should be deemed that the invalid term has been modified as much as possible to make it valid and enforceable, or if the term cannot be modified, it should be deemed to have been deleted from this Agreement.
|
|
123
|
+
|
|
124
|
+
8.4 The arbitration award is final, binding on both parties, and can be enforced in any court with jurisdiction.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @nocobase/plugin-field-record-set
|
package/client.d.ts
ADDED
package/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/client/index.js');
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import React from 'react';
|
|
10
|
+
export declare const ForeignKey: React.MemoExoticComponent<import("@formily/react").ReactFC<Omit<any, "ref">>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import React from 'react';
|
|
10
|
+
export declare const TargetKey: React.MemoExoticComponent<import("@formily/react").ReactFC<Omit<any, "ref">>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useMBMFields: () => {
|
|
10
|
+
targetKeys: import("@nocobase/client").CollectionFieldOptions[];
|
|
11
|
+
foreignKeys: import("@nocobase/client").CollectionFieldOptions[];
|
|
12
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin } from '@nocobase/client';
|
|
10
|
+
export declare class PluginM2MArrayClient extends Plugin {
|
|
11
|
+
afterAdd(): Promise<void>;
|
|
12
|
+
beforeLoad(): Promise<void>;
|
|
13
|
+
load(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export default PluginM2MArrayClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
(function(t,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("@nocobase/client"),require("@nocobase/utils/client"),require("react/jsx-runtime"),require("@formily/react"),require("antd"),require("react"),require("react-router-dom")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/utils/client","react/jsx-runtime","@formily/react","antd","react","react-router-dom"],n):(t=typeof globalThis!="undefined"?globalThis:t||self,n(t["@nocobase/plugin-field-m2m-array"]={},t["@nocobase/client"],t["@nocobase/utils"],t.jsxRuntime,t["@formily/react"],t.antd,t.react,t["react-router-dom"]))})(this,function(t,n,u,F,x,q,l,I){"use strict";var P=Object.defineProperty;var G=(t,n,u)=>n in t?P(t,n,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[n]=u;var m=(t,n,u)=>(G(t,typeof n!="symbol"?n+"":n,u),u);var T=(t,n,u)=>new Promise((F,x)=>{var q=p=>{try{I(u.next(p))}catch(K){x(K)}},l=p=>{try{I(u.throw(p))}catch(K){x(K)}},I=p=>p.done?F(p.value):Promise.resolve(p.value).then(q,l);I((u=u.apply(t,n)).next())});const p="field-m2m-array";function K(e){return(e==null?void 0:e.filterTargetKey)||(e==null?void 0:e.getPrimaryKey())||"id"}class j extends n.CollectionFieldInterface{constructor(){super(...arguments);m(this,"name","mbm");m(this,"type","object");m(this,"group","relation");m(this,"order",6);m(this,"title",u.tval("Many to many (array)",{ns:p}));m(this,"description",u.tval("Many to many (array) description",{ns:p}));m(this,"isAssociation",!0);m(this,"default",{type:"belongsToArray",uiSchema:{"x-component":"AssociationField","x-component-props":{multiple:!0}}});m(this,"availableTypes",["belongsToArray"]);m(this,"properties",{"uiSchema.title":{type:"string",title:'{{t("Field display name")}}',required:!0,"x-decorator":"FormItem","x-component":"Input"},name:{type:"string",title:'{{t("Field name")}}',required:!0,"x-disabled":"{{ !createOnly }}","x-decorator":"FormItem","x-component":"Input",description:"{{t('Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.')}}"},grid:{type:"void","x-component":"Grid",properties:{row1:{type:"void","x-component":"Grid.Row",properties:{col11:{type:"void","x-component":"Grid.Col",properties:{source:{type:"void",title:'{{t("Source collection")}}',"x-decorator":"FormItem","x-component":"SourceCollection"}}},col12:{type:"void","x-component":"Grid.Col",properties:{target:{type:"string",title:'{{t("Target collection")}}',required:!0,"x-reactions":['{{useAsyncDataSource(loadCollections, ["file"])}}'],"x-decorator":"FormItem","x-component":"Select","x-disabled":"{{ !createOnly }}"}}}}},row2:{type:"void","x-component":"Grid.Row",properties:{col21:{type:"void","x-component":"Grid.Col",properties:{foreignKey:{type:"string",title:'{{t("Foreign key")}}',required:!0,default:'{{ useNewId("f_") }}',description:"{{t('Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.')}}","x-decorator":"FormItem","x-component":"MBMForeignKey","x-validator":"uid","x-disabled":"{{ !createOnly }}"}}},col22:{type:"void","x-component":"Grid.Col",properties:{targetKey:{type:"string",title:'{{t("Target key")}}',"x-decorator":"FormItem","x-component":"MBMTargetKey","x-disabled":"{{ !createOnly }}",description:"{{t('Field values must be unique.')}}"}}}}}}}});m(this,"filterable",{nested:!0,children:[]})}schemaInitialize(o,{field:g,block:b,readPretty:y,targetCollection:s}){var c;o["x-component-props"]=o["x-component-props"]||{},o["x-component-props"].fieldNames=o["x-component-props"].fieldNames||{value:K(s)},o["x-component-props"].fieldNames.label=((c=o["x-component-props"].fieldNames)==null?void 0:c.label)||(s==null?void 0:s.titleField)||K(s),["Table","Kanban"].includes(b)&&(o["x-component-props"]=o["x-component-props"]||{},o["x-component-props"].ellipsis=!0,o["x-component-props"].size="small")}}const A=()=>{const{collectionName:e,name:h}=n.useRecord(),{name:o}=I.useParams(),{getCollection:g}=n.useCollectionManager_deprecated(),b=x.useForm(),{target:y}=b.values||{},s=l.useMemo(()=>{var r;return(r=g(e||h,o))==null?void 0:r.fields},[e,o]),c=l.useMemo(()=>{var r;return(r=g(y,o))==null?void 0:r.fields},[y,o]),f=l.useMemo(()=>c==null?void 0:c.filter(r=>(r.primaryKey||r.unique)&&r.interface),[c]),C=l.useMemo(()=>s==null?void 0:s.filter(r=>["set","array"].includes(r.type)&&r.interface==="json"),[s]);return{targetKeys:f,foreignKeys:C}},B=x.observer(e=>{const{disabled:h}=e,[o,g]=l.useState([]),b=n.useRecord(),y=x.useField(),{type:s,template:c}=b,f=b[y.props.name],C=n.useCompile(),[r,i]=l.useState(f||(c==="view"?null:y.initialValue)),{foreignKeys:a}=A();l.useEffect(()=>{const M=a;if(M){const v=M.map(d=>{var S;return{value:d.name,label:C(((S=d.uiSchema)==null?void 0:S.title)||d.name)}});if(g(v),f){const d=v.find(S=>S.value===f);i((d==null?void 0:d.label)||f)}}},[s]);const w=c==="view"?q.Select:q.AutoComplete;return F.jsx("div",{children:F.jsx(w,{disabled:h,value:r,options:o,showSearch:!0,onDropdownVisibleChange:M=>T(this,null,function*(){const v=a;v&&M&&g(v.map(d=>{var S;return{value:d.name,label:C(((S=d.uiSchema)==null?void 0:S.title)||d.name)}}))}),onChange:(M,v)=>{var d;(d=e==null?void 0:e.onChange)==null||d.call(e,M),i(v.label||M)}})})},{displayName:"MBMForeignKey"}),O=x.observer(e=>{const{value:h,disabled:o}=e,{targetKey:g}=n.useRecord(),[b,y]=l.useState([]),[s,c]=l.useState(h||g),f=n.useCompile(),C=x.useField();C.required=!0;const{targetKeys:r}=A();return l.useEffect(()=>{r&&y(r.map(i=>{var a;return{value:i.name,label:f(((a=i==null?void 0:i.uiSchema)==null?void 0:a.title)||i.title||i.name)}}))},[r]),F.jsx("div",{children:F.jsx(q.Select,{showSearch:!0,options:b,onDropdownVisibleChange:i=>T(this,null,function*(){r&&i&&y(r.map(a=>{var w;return{value:a.name,label:f(((w=a==null?void 0:a.uiSchema)==null?void 0:w.title)||a.title||a.name)}}))}),onChange:i=>{var a;(a=e==null?void 0:e.onChange)==null||a.call(e,i),c(i)},value:s,disabled:o})})},{displayName:"MBMTargetKey"});class N extends n.Plugin{afterAdd(){return T(this,null,function*(){})}beforeLoad(){return T(this,null,function*(){})}load(){return T(this,null,function*(){this.app.addComponents({MBMForeignKey:B,MBMTargetKey:O}),this.app.dataSourceManager.addFieldInterfaces([j])})}}t.PluginM2MArrayClient=N,t.default=N,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export declare const NAMESPACE = "field-m2m-array";
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { ISchema } from '@formily/react';
|
|
10
|
+
import { CollectionFieldInterface } from '@nocobase/client';
|
|
11
|
+
export declare class MBMFieldInterface extends CollectionFieldInterface {
|
|
12
|
+
name: string;
|
|
13
|
+
type: string;
|
|
14
|
+
group: string;
|
|
15
|
+
order: number;
|
|
16
|
+
title: any;
|
|
17
|
+
description: any;
|
|
18
|
+
isAssociation: boolean;
|
|
19
|
+
default: {
|
|
20
|
+
type: string;
|
|
21
|
+
uiSchema: {
|
|
22
|
+
'x-component': string;
|
|
23
|
+
'x-component-props': {
|
|
24
|
+
multiple: boolean;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
availableTypes: string[];
|
|
29
|
+
schemaInitialize(schema: ISchema, { field, block, readPretty, targetCollection }: {
|
|
30
|
+
field: any;
|
|
31
|
+
block: any;
|
|
32
|
+
readPretty: any;
|
|
33
|
+
targetCollection: any;
|
|
34
|
+
}): void;
|
|
35
|
+
properties: {
|
|
36
|
+
'uiSchema.title': {
|
|
37
|
+
type: string;
|
|
38
|
+
title: string;
|
|
39
|
+
required: boolean;
|
|
40
|
+
'x-decorator': string;
|
|
41
|
+
'x-component': string;
|
|
42
|
+
};
|
|
43
|
+
name: {
|
|
44
|
+
type: string;
|
|
45
|
+
title: string;
|
|
46
|
+
required: boolean;
|
|
47
|
+
'x-disabled': string;
|
|
48
|
+
'x-decorator': string;
|
|
49
|
+
'x-component': string;
|
|
50
|
+
description: string;
|
|
51
|
+
};
|
|
52
|
+
grid: {
|
|
53
|
+
type: string;
|
|
54
|
+
'x-component': string;
|
|
55
|
+
properties: {
|
|
56
|
+
row1: {
|
|
57
|
+
type: string;
|
|
58
|
+
'x-component': string;
|
|
59
|
+
properties: {
|
|
60
|
+
col11: {
|
|
61
|
+
type: string;
|
|
62
|
+
'x-component': string;
|
|
63
|
+
properties: {
|
|
64
|
+
source: {
|
|
65
|
+
type: string;
|
|
66
|
+
title: string;
|
|
67
|
+
'x-decorator': string;
|
|
68
|
+
'x-component': string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
col12: {
|
|
73
|
+
type: string;
|
|
74
|
+
'x-component': string;
|
|
75
|
+
properties: {
|
|
76
|
+
target: {
|
|
77
|
+
type: string;
|
|
78
|
+
title: string;
|
|
79
|
+
required: boolean;
|
|
80
|
+
'x-reactions': string[];
|
|
81
|
+
'x-decorator': string;
|
|
82
|
+
'x-component': string;
|
|
83
|
+
'x-disabled': string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
row2: {
|
|
90
|
+
type: string;
|
|
91
|
+
'x-component': string;
|
|
92
|
+
properties: {
|
|
93
|
+
col21: {
|
|
94
|
+
type: string;
|
|
95
|
+
'x-component': string;
|
|
96
|
+
properties: {
|
|
97
|
+
foreignKey: {
|
|
98
|
+
type: string;
|
|
99
|
+
title: string;
|
|
100
|
+
required: boolean;
|
|
101
|
+
default: string;
|
|
102
|
+
description: string;
|
|
103
|
+
'x-decorator': string;
|
|
104
|
+
'x-component': string;
|
|
105
|
+
'x-validator': string;
|
|
106
|
+
'x-disabled': string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
col22: {
|
|
111
|
+
type: string;
|
|
112
|
+
'x-component': string;
|
|
113
|
+
properties: {
|
|
114
|
+
targetKey: {
|
|
115
|
+
type: string;
|
|
116
|
+
title: string;
|
|
117
|
+
'x-decorator': string;
|
|
118
|
+
'x-component': string;
|
|
119
|
+
'x-disabled': string;
|
|
120
|
+
description: string;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
filterable: {
|
|
130
|
+
nested: boolean;
|
|
131
|
+
children: any[];
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
"@formily/react": "2.3.0",
|
|
12
|
+
"antd": "5.12.8",
|
|
13
|
+
"react": "18.2.0",
|
|
14
|
+
"@nocobase/client": "1.3.0-alpha.20240710155619",
|
|
15
|
+
"react-router-dom": "6.21.0",
|
|
16
|
+
"@nocobase/utils": "1.3.0-alpha.20240710155619",
|
|
17
|
+
"@nocobase/database": "1.3.0-alpha.20240710155619",
|
|
18
|
+
"@nocobase/server": "1.3.0-alpha.20240710155619",
|
|
19
|
+
"@nocobase/data-source-manager": "1.3.0-alpha.20240710155619"
|
|
20
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var src_exports = {};
|
|
39
|
+
__export(src_exports, {
|
|
40
|
+
default: () => import_server.default
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(src_exports);
|
|
43
|
+
__reExport(src_exports, require("./server"), module.exports);
|
|
44
|
+
var import_server = __toESM(require("./server"));
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
...require("./server")
|
|
48
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { BaseColumnFieldOptions, RelationField } from '@nocobase/database';
|
|
10
|
+
export declare const elementTypeMap: {
|
|
11
|
+
nanoid: string;
|
|
12
|
+
sequence: string;
|
|
13
|
+
};
|
|
14
|
+
export declare class BelongsToArrayField extends RelationField {
|
|
15
|
+
get dataType(): string;
|
|
16
|
+
private setForeignKeyArray;
|
|
17
|
+
init(): void;
|
|
18
|
+
checkTargetCollection(): boolean;
|
|
19
|
+
checkAssociationKeys(): void;
|
|
20
|
+
bind(): boolean;
|
|
21
|
+
unbind(): void;
|
|
22
|
+
}
|
|
23
|
+
export interface BelongsToArrayFieldOptions extends BaseColumnFieldOptions {
|
|
24
|
+
type: 'belongsToArray';
|
|
25
|
+
foreignKey: string;
|
|
26
|
+
target: string;
|
|
27
|
+
targetKey: string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var belongs_to_array_field_exports = {};
|
|
28
|
+
__export(belongs_to_array_field_exports, {
|
|
29
|
+
BelongsToArrayField: () => BelongsToArrayField,
|
|
30
|
+
elementTypeMap: () => elementTypeMap
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(belongs_to_array_field_exports);
|
|
33
|
+
var import_database = require("@nocobase/database");
|
|
34
|
+
const elementTypeMap = {
|
|
35
|
+
nanoid: "string",
|
|
36
|
+
sequence: "string"
|
|
37
|
+
};
|
|
38
|
+
class BelongsToArrayField extends import_database.RelationField {
|
|
39
|
+
get dataType() {
|
|
40
|
+
return "BelongsToArray";
|
|
41
|
+
}
|
|
42
|
+
setForeignKeyArray = async (model, { values, transaction }) => {
|
|
43
|
+
const { name, foreignKey, target, targetKey } = this.options;
|
|
44
|
+
if (!values || values[name] === void 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const value = values[name] || [];
|
|
48
|
+
const tks = [];
|
|
49
|
+
const items = [];
|
|
50
|
+
for (const item of value) {
|
|
51
|
+
if (typeof item !== "object") {
|
|
52
|
+
tks.push(item);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
items.push(item);
|
|
56
|
+
}
|
|
57
|
+
const repo = this.database.getRepository(target);
|
|
58
|
+
const itemTks = items.map((item) => item[targetKey]).filter((tk) => tk);
|
|
59
|
+
const instances = await repo.find({
|
|
60
|
+
filter: {
|
|
61
|
+
[targetKey]: itemTks
|
|
62
|
+
},
|
|
63
|
+
transaction
|
|
64
|
+
});
|
|
65
|
+
tks.push(...instances.map((instance) => instance[targetKey]));
|
|
66
|
+
const toCreate = items.filter((item) => !item[targetKey] || !tks.includes(item[targetKey]));
|
|
67
|
+
const m = this.database.getModel(target);
|
|
68
|
+
const newInstances = await m.bulkCreate(toCreate, { transaction });
|
|
69
|
+
tks.push(...newInstances.map((instance) => instance[targetKey]));
|
|
70
|
+
model.set(foreignKey, tks);
|
|
71
|
+
};
|
|
72
|
+
init() {
|
|
73
|
+
super.init();
|
|
74
|
+
const { name, ...opts } = this.options;
|
|
75
|
+
this.collection.model.associations[name] = new import_database.BelongsToArrayAssociation({
|
|
76
|
+
db: this.database,
|
|
77
|
+
source: this.collection.model,
|
|
78
|
+
as: name,
|
|
79
|
+
...opts
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
checkTargetCollection() {
|
|
83
|
+
const { target } = this.options;
|
|
84
|
+
if (!target) {
|
|
85
|
+
throw new Error("Target is required in the options of many to many (array) field.");
|
|
86
|
+
}
|
|
87
|
+
const targetCollection = this.database.getCollection(target);
|
|
88
|
+
if (!targetCollection) {
|
|
89
|
+
this.database.addPendingField(this);
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
checkAssociationKeys() {
|
|
95
|
+
const { foreignKey, target, targetKey } = this.options;
|
|
96
|
+
if (!targetKey) {
|
|
97
|
+
throw new Error("Target key is required in the options of many to many (array) field.");
|
|
98
|
+
}
|
|
99
|
+
const targetField = this.database.getModel(target).getAttributes()[targetKey];
|
|
100
|
+
const foreignField = this.collection.model.getAttributes()[foreignKey];
|
|
101
|
+
if (!foreignField || !targetField) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const foreignType = foreignField.type.constructor.toString();
|
|
105
|
+
if (!["ARRAY", "JSONTYPE", "JSON", "JSONB"].includes(foreignType)) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`The type of foreign key "${foreignKey}" in collection "${this.collection.name}" must be ARRAY, JSON or JSONB`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (this.database.sequelize.getDialect() !== "postgres") {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const targetType = targetField.type.constructor.toString();
|
|
114
|
+
const elementType = foreignField.type.type.constructor.toString();
|
|
115
|
+
if (foreignType === "ARRAY" && elementType !== targetType) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`The element type "${elementType}" of foreign key "${foreignKey}" does not match the type "${targetType}" of target key "${targetKey}" in collection "${target}"`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
bind() {
|
|
122
|
+
if (!this.checkTargetCollection()) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
this.checkAssociationKeys();
|
|
126
|
+
this.on("beforeSave", this.setForeignKeyArray);
|
|
127
|
+
}
|
|
128
|
+
unbind() {
|
|
129
|
+
delete this.collection.model.associations[this.name];
|
|
130
|
+
this.off("beforeSave", this.setForeignKeyArray);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
BelongsToArrayField,
|
|
136
|
+
elementTypeMap
|
|
137
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Database, Model } from '@nocobase/database';
|
|
10
|
+
export declare function beforeDestroyForeignKey(db: Database): (model: Model, { transaction }: {
|
|
11
|
+
transaction: any;
|
|
12
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var before_destroy_foreign_key_exports = {};
|
|
28
|
+
__export(before_destroy_foreign_key_exports, {
|
|
29
|
+
beforeDestroyForeignKey: () => beforeDestroyForeignKey
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(before_destroy_foreign_key_exports);
|
|
32
|
+
function beforeDestroyForeignKey(db) {
|
|
33
|
+
return async (model, { transaction }) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const { isForeignKey, collectionName, name: fkName, type } = model.get();
|
|
36
|
+
if (!isForeignKey || type !== "set") {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const fieldKeys = [];
|
|
40
|
+
const collection = db.getCollection(collectionName);
|
|
41
|
+
for (const [, field] of collection.fields) {
|
|
42
|
+
const fieldKey = (_a = field.options) == null ? void 0 : _a.key;
|
|
43
|
+
if (!fieldKey || field.type !== "belongsToArray" || field.foreignKey !== fkName) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
fieldKeys.push(fieldKey);
|
|
47
|
+
}
|
|
48
|
+
const r = db.getRepository("fields");
|
|
49
|
+
await r.destroy({
|
|
50
|
+
filter: {
|
|
51
|
+
"key.$in": fieldKeys
|
|
52
|
+
},
|
|
53
|
+
transaction
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
beforeDestroyForeignKey
|
|
60
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Database, Model } from '@nocobase/database';
|
|
10
|
+
export declare const createForeignKey: (db: Database) => (model: Model, { transaction }: {
|
|
11
|
+
transaction: any;
|
|
12
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var create_foreign_key_exports = {};
|
|
28
|
+
__export(create_foreign_key_exports, {
|
|
29
|
+
createForeignKey: () => createForeignKey
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(create_foreign_key_exports);
|
|
32
|
+
var import_belongs_to_array_field = require("../belongs-to-array-field");
|
|
33
|
+
const createForeignKey = (db) => {
|
|
34
|
+
return async (model, { transaction }) => {
|
|
35
|
+
const { type, collectionName, target, targetKey, foreignKey } = model.get();
|
|
36
|
+
if (type !== "belongsToArray") {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const r = db.getRepository("fields");
|
|
40
|
+
const instance = await r.findOne({
|
|
41
|
+
filter: {
|
|
42
|
+
collectionName,
|
|
43
|
+
name: foreignKey
|
|
44
|
+
},
|
|
45
|
+
transaction
|
|
46
|
+
});
|
|
47
|
+
if (!instance) {
|
|
48
|
+
const targetField = await r.findOne({
|
|
49
|
+
filter: {
|
|
50
|
+
collectionName: target,
|
|
51
|
+
name: targetKey
|
|
52
|
+
},
|
|
53
|
+
transaction
|
|
54
|
+
});
|
|
55
|
+
if (!targetField) {
|
|
56
|
+
throw new Error(`${target}.${targetKey} not found`);
|
|
57
|
+
}
|
|
58
|
+
const field = await r.create({
|
|
59
|
+
values: {
|
|
60
|
+
interface: "json",
|
|
61
|
+
collectionName,
|
|
62
|
+
name: foreignKey,
|
|
63
|
+
type: "set",
|
|
64
|
+
dataType: "array",
|
|
65
|
+
elementType: import_belongs_to_array_field.elementTypeMap[targetField.type] || targetField.type,
|
|
66
|
+
isForeignKey: true,
|
|
67
|
+
uiSchema: {
|
|
68
|
+
type: "object",
|
|
69
|
+
title: foreignKey,
|
|
70
|
+
"x-component": "Input.JSON",
|
|
71
|
+
"x-read-pretty": true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
transaction
|
|
75
|
+
});
|
|
76
|
+
await field.load({ transaction });
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
createForeignKey
|
|
83
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './plugin';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var server_exports = {};
|
|
38
|
+
__export(server_exports, {
|
|
39
|
+
default: () => import_plugin.default
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(server_exports);
|
|
42
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin } from '@nocobase/server';
|
|
10
|
+
export declare class PluginFieldM2MArrayServer extends Plugin {
|
|
11
|
+
afterAdd(): Promise<void>;
|
|
12
|
+
beforeLoad(): Promise<void>;
|
|
13
|
+
load(): Promise<void>;
|
|
14
|
+
install(): Promise<void>;
|
|
15
|
+
afterEnable(): Promise<void>;
|
|
16
|
+
afterDisable(): Promise<void>;
|
|
17
|
+
remove(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export default PluginFieldM2MArrayServer;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var plugin_exports = {};
|
|
28
|
+
__export(plugin_exports, {
|
|
29
|
+
PluginFieldM2MArrayServer: () => PluginFieldM2MArrayServer,
|
|
30
|
+
default: () => plugin_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
33
|
+
var import_server = require("@nocobase/server");
|
|
34
|
+
var import_belongs_to_array_field = require("./belongs-to-array-field");
|
|
35
|
+
var import_create_foreign_key = require("./hooks/create-foreign-key");
|
|
36
|
+
var import_before_destroy_foreign_key = require("./hooks/before-destroy-foreign-key");
|
|
37
|
+
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
38
|
+
class PluginFieldM2MArrayServer extends import_server.Plugin {
|
|
39
|
+
async afterAdd() {
|
|
40
|
+
}
|
|
41
|
+
async beforeLoad() {
|
|
42
|
+
}
|
|
43
|
+
async load() {
|
|
44
|
+
this.app.dataSourceManager.beforeAddDataSource((dataSource) => {
|
|
45
|
+
const collectionManager = dataSource.collectionManager;
|
|
46
|
+
if (collectionManager instanceof import_data_source_manager.SequelizeCollectionManager) {
|
|
47
|
+
collectionManager.registerFieldTypes({
|
|
48
|
+
belongsToArray: import_belongs_to_array_field.BelongsToArrayField
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
this.db.on("fields.afterCreate", (0, import_create_foreign_key.createForeignKey)(this.db));
|
|
53
|
+
this.db.on("fields.beforeDestroy", (0, import_before_destroy_foreign_key.beforeDestroyForeignKey)(this.db));
|
|
54
|
+
}
|
|
55
|
+
async install() {
|
|
56
|
+
}
|
|
57
|
+
async afterEnable() {
|
|
58
|
+
}
|
|
59
|
+
async afterDisable() {
|
|
60
|
+
}
|
|
61
|
+
async remove() {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
var plugin_default = PluginFieldM2MArrayServer;
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
PluginFieldM2MArrayServer
|
|
68
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-field-m2m-array",
|
|
3
|
+
"displayName": "Collection field: Many to many (array)",
|
|
4
|
+
"displayName.zh-CN": "数据表字段:多对多 (数组)",
|
|
5
|
+
"version": "1.3.0-alpha.20240710155619",
|
|
6
|
+
"main": "dist/server/index.js",
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@nocobase/client": "1.x",
|
|
9
|
+
"@nocobase/server": "1.x",
|
|
10
|
+
"@nocobase/test": "1.x"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"Collection fields"
|
|
14
|
+
],
|
|
15
|
+
"gitHead": "95de9b94409d2e98bc2b95161ddf2012499bb5ec"
|
|
16
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|