@tachybase/plugin-field-snapshot 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.
Files changed (41) hide show
  1. package/.turbo/turbo-build.log +14 -0
  2. package/LICENSE +201 -0
  3. package/README.md +13 -0
  4. package/README.zh-CN.md +13 -0
  5. package/client.d.ts +2 -0
  6. package/client.js +1 -0
  7. package/dist/client/SnapshotBlock/SnapshotBlockInitializers/SnapshotBlockInitializers.d.ts +2 -0
  8. package/dist/client/SnapshotBlock/SnapshotBlockInitializers/SnapshotBlockInitializersDetailItem.d.ts +59 -0
  9. package/dist/client/SnapshotBlock/SnapshotBlockProvider.d.ts +2 -0
  10. package/dist/client/SnapshotFieldProvider.d.ts +4 -0
  11. package/dist/client/SnapshotHistoryCollectionProvider.d.ts +5 -0
  12. package/dist/client/SnapshotRecordPicker.d.ts +2 -0
  13. package/dist/client/components/SnapshotOwnerCollectionFieldsSelect.d.ts +13 -0
  14. package/dist/client/index.d.ts +5 -0
  15. package/dist/client/index.js +1 -0
  16. package/dist/client/interface.d.ts +95 -0
  17. package/dist/client/locale/index.d.ts +3 -0
  18. package/dist/externalVersion.js +11 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +39 -0
  21. package/dist/locale/en-US.json +11 -0
  22. package/dist/locale/es-ES.json +11 -0
  23. package/dist/locale/fr-FR.json +11 -0
  24. package/dist/locale/ko_KR.json +13 -0
  25. package/dist/locale/pt-BR.json +11 -0
  26. package/dist/locale/zh-CN.json +13 -0
  27. package/dist/server/collections/collectionsHistory.d.ts +2 -0
  28. package/dist/server/collections/collectionsHistory.js +77 -0
  29. package/dist/server/collections/fieldsHistory.d.ts +2 -0
  30. package/dist/server/collections/fieldsHistory.js +95 -0
  31. package/dist/server/fields/field-snapshot.d.ts +13 -0
  32. package/dist/server/fields/field-snapshot.js +70 -0
  33. package/dist/server/index.d.ts +1 -0
  34. package/dist/server/index.js +33 -0
  35. package/dist/server/plugin.d.ts +13 -0
  36. package/dist/server/plugin.js +128 -0
  37. package/dist/swagger/index.d.ts +8 -0
  38. package/dist/swagger/index.js +29 -0
  39. package/package.json +32 -0
  40. package/server.d.ts +2 -0
  41. package/server.js +1 -0
@@ -0,0 +1,14 @@
1
+
2
+ 
3
+ > @tachybase/plugin-field-snapshot@0.23.2 build /Users/seal/Documents/projects/tachybase/packages/plugin-field-snapshot
4
+ > tachybase-build --no-dts @tachybase/plugin-field-snapshot
5
+
6
+ The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
7
+ @tachybase/plugin-field-snapshot: plugin-field-snapshot build start
8
+ @tachybase/plugin-field-snapshot: build plugin client
9
+ @tachybase/plugin-field-snapshot: build plugin server source
10
+ @tachybase/plugin-field-snapshot: delete server files
11
+ @tachybase/plugin-field-snapshot: build plugin server dependencies
12
+ @tachybase/plugin-field-snapshot: These packages @tachybase/database, @tachybase/server will be exclude.
13
+ @tachybase/plugin-field-snapshot: 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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # snapshot-field
2
+
3
+ English | [中文](./README.zh-CN.md)
4
+
5
+ 关系数据快照插件。
6
+
7
+ ## 安装激活
8
+
9
+ ```bash
10
+ yarn pm enable snapshot-field
11
+ ```
12
+
13
+ ## 使用方法
@@ -0,0 +1,13 @@
1
+ # snapshot-field
2
+
3
+ [English](./README.md) | 中文
4
+
5
+ 关系数据快照插件。
6
+
7
+ ## 安装激活
8
+
9
+ ```bash
10
+ yarn pm enable snapshot-field
11
+ ```
12
+
13
+ ## 使用方法
package/client.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/client';
2
+ export { default } from './dist/client';
package/client.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/client/index.js');
@@ -0,0 +1,2 @@
1
+ import { SchemaInitializer } from '@tachybase/client';
2
+ export declare const snapshotBlockInitializers: SchemaInitializer<import("antd").ButtonProps, {}>;
@@ -0,0 +1,59 @@
1
+ import React from 'react';
2
+ export declare const createSnapshotBlockSchema: (options: any) => import("@tachybase/schema").Stringify<{
3
+ [key: symbol]: any;
4
+ [key: `x-${string}`]: any;
5
+ [key: `x-${number}`]: any;
6
+ version?: string;
7
+ name?: import("@tachybase/schema").SchemaKey;
8
+ title?: any;
9
+ description?: any;
10
+ default?: any;
11
+ readOnly?: boolean;
12
+ writeOnly?: boolean;
13
+ type?: import("@tachybase/schema").SchemaTypes;
14
+ enum?: import("@tachybase/schema").SchemaEnum<any>;
15
+ const?: any;
16
+ multipleOf?: number;
17
+ maximum?: number;
18
+ exclusiveMaximum?: number;
19
+ minimum?: number;
20
+ exclusiveMinimum?: number;
21
+ maxLength?: number;
22
+ minLength?: number;
23
+ pattern?: string | RegExp;
24
+ maxItems?: number;
25
+ minItems?: number;
26
+ uniqueItems?: boolean;
27
+ maxProperties?: number;
28
+ minProperties?: number;
29
+ required?: string[] | boolean | string;
30
+ format?: string;
31
+ $ref?: string;
32
+ $namespace?: string;
33
+ definitions?: import("@tachybase/schema").SchemaProperties<any, any, any, any, any, any, any, any>;
34
+ properties?: import("@tachybase/schema").SchemaProperties<any, any, any, any, any, any, any, any>;
35
+ items?: import("@tachybase/schema").SchemaItems<any, any, any, any, any, any, any, any>;
36
+ additionalItems?: import("@tachybase/schema").Stringify</*elided*/ any>;
37
+ patternProperties?: import("@tachybase/schema").SchemaProperties<any, any, any, any, any, any, any, any>;
38
+ additionalProperties?: import("@tachybase/schema").Stringify</*elided*/ any>;
39
+ "x-value"?: any;
40
+ "x-index"?: number;
41
+ "x-pattern"?: any;
42
+ "x-display"?: any;
43
+ "x-validator"?: any;
44
+ "x-decorator"?: any;
45
+ "x-decorator-props"?: any;
46
+ "x-component"?: any;
47
+ "x-component-props"?: any;
48
+ "x-reactions"?: import("@tachybase/schema").SchemaReactions<any>;
49
+ "x-content"?: any;
50
+ "x-data"?: any;
51
+ "x-visible"?: boolean;
52
+ "x-hidden"?: boolean;
53
+ "x-disabled"?: boolean;
54
+ "x-editable"?: boolean;
55
+ "x-read-only"?: boolean;
56
+ "x-read-pretty"?: boolean;
57
+ "x-compile-omitted"?: string[];
58
+ }>;
59
+ export declare const SnapshotBlockInitializersDetailItem: () => React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const SnapshotBlockProvider: (props: any) => React.JSX.Element;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare const SnapshotFieldProvider: React.MemoExoticComponent<(props: {
3
+ children: React.ReactNode;
4
+ }) => React.JSX.Element>;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export declare const SnapshotHistoryCollectionProvider: (props: {
3
+ collectionName: string;
4
+ children: React.ReactNode;
5
+ }) => React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const SnapshotRecordPicker: (props: any) => React.JSX.Element;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { SelectProps } from 'antd';
3
+ export type SnapshotOwnerCollectionFieldsSelectProps = Omit<SelectProps, 'options'>;
4
+ export declare const useSnapshotOwnerCollectionFields: () => {
5
+ label: any;
6
+ value: any;
7
+ name?: any;
8
+ collectionName?: string;
9
+ sourceKey?: string;
10
+ uiSchema?: any;
11
+ target?: string;
12
+ }[];
13
+ export declare const SnapshotOwnerCollectionFieldsSelect: React.FC<SnapshotOwnerCollectionFieldsSelectProps>;
@@ -0,0 +1,5 @@
1
+ import { Plugin } from '@tachybase/client';
2
+ export declare class SnapshotFieldPlugin extends Plugin {
3
+ load(): Promise<void>;
4
+ }
5
+ export default SnapshotFieldPlugin;
@@ -0,0 +1 @@
1
+ (function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("@tachybase/schema"),require("lodash"),require("react-i18next"),require("react/jsx-runtime"),require("react"),require("antd"),require("@ant-design/icons")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/schema","lodash","react-i18next","react/jsx-runtime","react","antd","@ant-design/icons"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@tachybase/plugin-field-snapshot"]={},n["@tachybase/client"],n["@tachybase/schema"],n.lodash,n["react-i18next"],n.jsxRuntime,n.react,n.antd,n["@ant-design/icons"]))})(this,function(n,e,s,h,M,i,k,v,y){"use strict";var se=Object.defineProperty,ae=Object.defineProperties;var ce=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var V=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var w=(n,e,s)=>e in n?se(n,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[e]=s,g=(n,e)=>{for(var s in e||(e={}))V.call(e,s)&&w(n,s,e[s]);if(B)for(var s of B(e))H.call(e,s)&&w(n,s,e[s]);return n},x=(n,e)=>ae(n,ce(e));var _=(n,e)=>{var s={};for(var h in n)V.call(n,h)&&e.indexOf(h)<0&&(s[h]=n[h]);if(n!=null&&B)for(var h of B(n))e.indexOf(h)<0&&H.call(n,h)&&(s[h]=n[h]);return s};var S=(n,e,s)=>w(n,typeof e!="symbol"?e+"":e,s);var z=(n,e,s)=>new Promise((h,M)=>{var i=y=>{try{v(s.next(y))}catch(C){M(C)}},k=y=>{try{v(s.throw(y))}catch(C){M(C)}},v=y=>y.done?h(y.value):Promise.resolve(y.value).then(i,k);v((s=s.apply(n,e)).next())});const C="field-snapshot",{defaultProps:G}=e.interfacesProperties,$="appends",T="targetField",A=()=>{let t=e.useRecord();for(;t!=null&&t.__parent&&Object.keys(t.__parent).length>0;)t=t.__parent;return t};function W(){var r;const{getCollectionField:t}=e.useCollectionManager_deprecated(),c=A(),a=s.useForm().values;return(r=t(`${c.name}.${a.targetField}`))==null?void 0:r.target}function q(t,c=[]){const{getCollection:a}=e.useCollectionManager_deprecated(),r=[];return t.forEach(o=>{var l,d,u,m;if(["belongsTo","hasOne","hasMany","belongsToMany"].includes(o.type)){const P=c.filter(f=>`${f}.`.startsWith(`${o.name}.`));if(P.length){const f=a(o.target),F=P.filter(p=>p!==o.name).map(p=>p.replace(`${o.name}.`,"")).filter(p=>p);r.push({label:(d=(l=o.uiSchema)==null?void 0:l.title)!=null?d:o.name,value:o.name,children:q(f.fields,F)})}}else r.push({label:(m=(u=o.uiSchema)==null?void 0:u.title)!=null?m:o.name,value:o.name})}),r}const L={type:"void",title:"{{t('View record')}}","x-component":"RecordPicker.Viewer","x-component-props":{className:"tb-action-popup"},properties:{tabs:{type:"void","x-component":"Tabs","x-component-props":{},properties:{tab1:{type:"void",title:"{{t('Detail')}}","x-component":"Tabs.TabPane","x-designer":"Tabs.Designer","x-component-props":{},properties:{grid:{type:"void","x-component":"Grid","x-initializer":"popup:snapshot:addBlock",properties:{}}}}}}}};class J extends e.CollectionFieldInterface{constructor(){super(...arguments);S(this,"name","snapshot");S(this,"type","object");S(this,"group","advanced");S(this,"title",`{{t('Snapshot', {ns: '${C}'})}}`);S(this,"description",`{{t('When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.', {ns: '${C}'})}}`);S(this,"default",{type:"snapshot",uiSchema:{"x-component":"SnapshotRecordPicker","x-component-props":{multiple:!0,fieldNames:{label:"id",value:"id"}}}});S(this,"properties",x(g({},G),{[T]:{type:"string",title:`{{t('The association field to snapshot', {ns: '${C}'})}}`,required:!0,"x-decorator":"FormItem","x-component":"SnapshotOwnerCollectionFieldsSelect","x-disabled":"{{ !createOnly || isOverride }}","x-reactions":[{target:$,when:"{{$self.value != undefined}}",fulfill:{state:{visible:!0}},otherwise:{state:{visible:!1}}}]},[$]:{type:"string",title:`{{t("Snapshot the snapshot's association fields", {ns: "${C}"})}}`,"x-decorator":"FormItem","x-component":"AppendsTreeSelect","x-component-props":{multiple:!0,useCollection:W},"x-reactions":[{dependencies:[T],when:"{{$deps[0]}}",fulfill:{run:"{{$self.setValue($self.value)}}"}}]}}))}schemaInitialize(a,{field:r,readPretty:o,action:l,block:d}){a.properties={viewer:h.cloneDeep(L)}}initialize(a){}usePathOptions(a){const{appends:r=[],targetCollection:o}=a,{getCollection:l}=e.useCollectionManager_deprecated(),{fields:d}=l(o),u=q(d,r);return[{label:`{{t('Snapshot data', { ns: '${C}' })}}`,value:"data",children:u}]}}const K=new e.SchemaInitializer({name:"popup:snapshot:addBlock",wrap:e.gridRowColWrap,title:`{{t("Add block", { ns: "${C}" })}}`,icon:"PlusOutlined",items:[{type:"itemGroup",title:'{{t("Current record blocks")}}',name:"currentRecordBlocks",children:[{name:"details",title:'{{t("Details")}}',Component:"SnapshotBlockInitializersDetailItem",actionInitializers:"details:configureActions"}]},{type:"itemGroup",title:'{{t("Other blocks")}}',name:"otherBlocks",children:[{name:"markdown",title:'{{t("Demonstration text")}}',Component:"MarkdownBlockInitializer"}]}]}),Q=()=>{const t=A(),{getCollection:c}=e.useCollectionManager_deprecated(),a=c(t.name),r=e.useCompile();return a.fields.filter(o=>!!o.target&&!!o.interface).map(o=>{var l;return x(g({},o),{label:r((l=o.uiSchema)==null?void 0:l.title),value:o.name})})},U=t=>{const c=Q();return i.jsx(v.Select,g({popupMatchSelectWidth:!1,options:c},t))},O=t=>{const f=t,{formItemInitializers:c="details:configureFields",actionInitializers:a="details:configureActions",collection:r,association:o,resource:l,template:d}=f,u=_(f,["formItemInitializers","actionInitializers","collection","association","resource","template"]),m=l||o||r;return{type:"void","x-acl-action":`${m}:get`,"x-decorator":"SnapshotBlockProvider","x-decorator-props":g({resource:m,collection:r,association:o,readPretty:!0,action:"get",useParams:"{{ useParamsFromRecord }}"},u),"x-designer":"FormV2.ReadPrettyDesigner","x-component":"CardItem",properties:{[s.uid()]:{type:"void","x-component":"FormV2","x-read-pretty":!0,"x-use-component-props":"useFormBlockProps",properties:{grid:d||{type:"void","x-component":"Grid","x-initializer":c,properties:{}}}}}}},X=()=>{const t=e.useSchemaInitializerItem(),b=t,{onCreateBlockSchema:c,componentType:a,createBlockSchema:r,icon:o=!0,targetCollection:l}=b,d=_(b,["onCreateBlockSchema","componentType","createBlockSchema","icon","targetCollection"]),{insert:u}=e.useSchemaInitializer(),{getTemplateSchemaByMode:m}=e.useSchemaTemplateManager(),P=l||e.useCollection_deprecated(),f=e.useBlockAssociationContext(),{block:F}=e.useBlockRequestContext(),p=F!=="TableField"?t.actionInitializers||"details:configureActions":null;return k.createElement(e.SchemaInitializerItem,x(g({icon:o&&i.jsx(y.FormOutlined,{})},d),{key:"snapshotDetail",onClick:de=>z(this,[de],function*({item:I}){if(I.template){const j=yield m(I);if(I.template.componentName==="ReadPrettyFormItem"){const E=O({actionInitializers:p,association:f,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}",template:j});I.mode==="reference"&&(E["x-template-key"]=I.template.key),u(E)}else u(j)}else u(O({actionInitializers:p,association:f,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}"}))}),items:e.useRecordCollectionDataSourceItems("ReadPrettyFormItem")}))},Y=t=>{var m;const{action:c,readPretty:a}=t,r=s.useField(),o=k.useMemo(()=>s.createForm({readPretty:a}),[]),{resource:l,service:d}=e.useBlockRequestContext(),u=k.useRef();return d.loading?i.jsx(v.Spin,{}):i.jsx(e.FormBlockContext.Provider,{value:{action:c,form:o,field:r,service:d,resource:l,updateAssociationValues:[],formBlockRef:u},children:a?i.jsx(e.RecordProvider,{record:(m=d==null?void 0:d.data)==null?void 0:m.data,children:i.jsx("div",{ref:u,children:t.children})}):i.jsx("div",{ref:u,children:t.children})})},Z=t=>{const c=s.useField(),a=e.useBlockResource(),r={loading:!1,data:{data:e.useRecord()}},o=e.useBlockRequestContext();return i.jsx(e.BlockRequestContext_deprecated.Provider,{value:{block:t.block,props:t,field:c,service:r,resource:a,__parent:o},children:t.children})},ee=t=>{const{collection:c,association:a,dataSource:r}=t,o=e.useResource(t);return i.jsx(e.CollectionManagerProvider,{dataSource:r,children:i.jsx(e.MaybeCollectionProvider,{collection:c,children:i.jsx(e.BlockAssociationContext.Provider,{value:a,children:i.jsx(e.BlockResourceContext.Provider,{value:o,children:i.jsx(Z,x(g({},t),{children:t.children}))})})})})},te=t=>{const c=e.useRecord(),{__tableName:a}=c,{getInheritCollections:r}=e.useCollectionManager_deprecated(t.dataSource),o=r(a),{designable:l}=e.useDesignable();return!(!l&&a&&!o.includes(t.collection)&&a!==t.collection)&&i.jsx(ee,x(g({},t),{children:i.jsx(Y,g({},t))}))},oe=t=>{var P,f,F;const{collectionName:c}=t,{collections:a}=e.useCollectionManager_deprecated(),r=(P=e.useHistoryCollectionsByNames([c]))==null?void 0:P[0],o=e.useHistoryCollectionsByNames((f=r==null?void 0:r.inherits)!=null?f:[]),l=e.useHistoryCollectionsByNames((F=r==null?void 0:r.fields.filter(p=>p.interface!=="snapshot").map(p=>p.target))!=null?F:[]),d=[r,...l,...o].filter(p=>p),m=[...a.filter(p=>!d.map(b=>b.name).includes(p.name)),...d];return i.jsx(e.ExtendCollectionsProvider,{collections:m,children:i.jsx(e.CollectionManagerProvider_deprecated,{children:t.children})})},R=t=>{const c=s.useFieldSchema(),{getField:a}=e.useCollection_deprecated(),r=a(c.name);return i.jsx(oe,{collectionName:r==null?void 0:r.targetCollection,children:i.jsx(e.ReadPrettyRecordPicker,g({},t))})},ne=s.connect(R,s.mapReadPretty(R)),re=t=>{const l=t,{value:c,onChange:a}=l,r=_(l,["value","onChange"]),o=x(g({},r),{value:c==null?void 0:c.data,onChange:d=>a({data:d})});return i.jsx(ne,g({},o))},D=k.memo(t=>i.jsx(e.CollectionHistoryProvider,{children:i.jsx(e.SchemaComponentOptions,{components:{SnapshotRecordPicker:re,SnapshotBlockProvider:te,SnapshotBlockInitializersDetailItem:X,SnapshotOwnerCollectionFieldsSelect:U},children:t.children})}));D.displayName="SnapshotFieldProvider";class N extends e.Plugin{load(){return z(this,null,function*(){this.app.use(D),this.app.schemaInitializerManager.add(K),this.app.dataSourceManager.addFieldInterfaces([J])})}}n.SnapshotFieldPlugin=N,n.default=N,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,95 @@
1
+ import { CollectionFieldInterface } from '@tachybase/client';
2
+ import { ISchema } from '@tachybase/schema';
3
+ export declare const useTopRecord: () => any;
4
+ declare function useRecordCollection(): any;
5
+ export declare class SnapshotFieldInterface extends CollectionFieldInterface {
6
+ name: string;
7
+ type: string;
8
+ group: string;
9
+ title: string;
10
+ description: string;
11
+ default: {
12
+ type: string;
13
+ uiSchema: {
14
+ 'x-component': string;
15
+ 'x-component-props': {
16
+ multiple: boolean;
17
+ fieldNames: {
18
+ label: string;
19
+ value: string;
20
+ };
21
+ };
22
+ };
23
+ };
24
+ schemaInitialize(schema: ISchema, { field, readPretty, action, block }: {
25
+ field: any;
26
+ readPretty: any;
27
+ action: any;
28
+ block: any;
29
+ }): void;
30
+ initialize(values: any): void;
31
+ usePathOptions(field: any): {
32
+ label: string;
33
+ value: string;
34
+ children: any[];
35
+ }[];
36
+ properties: {
37
+ targetField: {
38
+ type: string;
39
+ title: string;
40
+ required: boolean;
41
+ 'x-decorator': string;
42
+ 'x-component': string;
43
+ 'x-disabled': string;
44
+ 'x-reactions': {
45
+ target: string;
46
+ when: string;
47
+ fulfill: {
48
+ state: {
49
+ visible: boolean;
50
+ };
51
+ };
52
+ otherwise: {
53
+ state: {
54
+ visible: boolean;
55
+ };
56
+ };
57
+ }[];
58
+ };
59
+ appends: {
60
+ type: string;
61
+ title: string;
62
+ 'x-decorator': string;
63
+ 'x-component': string;
64
+ 'x-component-props': {
65
+ multiple: boolean;
66
+ useCollection: typeof useRecordCollection;
67
+ };
68
+ 'x-reactions': {
69
+ dependencies: string[];
70
+ when: string;
71
+ fulfill: {
72
+ run: string;
73
+ };
74
+ }[];
75
+ };
76
+ 'uiSchema.title': {
77
+ type: string;
78
+ title: string;
79
+ required: boolean;
80
+ "x-decorator": string;
81
+ "x-component": string;
82
+ };
83
+ name: {
84
+ type: string;
85
+ title: string;
86
+ required: boolean;
87
+ "x-disabled": string;
88
+ "x-decorator": string;
89
+ "x-component": string;
90
+ "x-validator": string;
91
+ description: string;
92
+ };
93
+ };
94
+ }
95
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const NAMESPACE = "field-snapshot";
2
+ export declare function lang(key: string): string;
3
+ export declare function useSnapshotTranslation(): import("react-i18next").UseTranslationResponse<"field-snapshot", undefined>;
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ "react": "18.3.1",
3
+ "@tachybase/client": "0.23.8",
4
+ "@tachybase/schema": "0.23.8",
5
+ "lodash": "4.17.21",
6
+ "@tachybase/database": "0.23.8",
7
+ "@tachybase/server": "0.23.8",
8
+ "antd": "5.22.5",
9
+ "react-i18next": "15.2.0",
10
+ "@ant-design/icons": "5.3.7"
11
+ };
@@ -0,0 +1,2 @@
1
+ export * from './server';
2
+ export { default } from './server';
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,11 @@
1
+ {
2
+ "Add block": "Add block",
3
+ "Allow linking to multiple records": "Allow linking to multiple records",
4
+ "Detail": "Detail",
5
+ "Please select": "Please select",
6
+ "Snapshot": "Snapshot",
7
+ "Snapshot the snapshot's association fields": "Snapshot the snapshot's association fields",
8
+ "The association field to snapshot": "The association field to snapshot",
9
+ "View record": "View record",
10
+ "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.": "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated."
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "Add block": "Añadir bloque",
3
+ "Allow linking to multiple records": "Permitir enlace a múltiples registros",
4
+ "Detail": "Detalle",
5
+ "Please select": "Por favor, seleccione",
6
+ "Snapshot": "Snapshot",
7
+ "Snapshot the snapshot's association fields": "Snapshot los campos de asociación de la snapshot",
8
+ "The association field to snapshot": "El campo de asociación a la snapshot",
9
+ "View record": "Ver registro",
10
+ "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.": "Al añadir un nuevo registro, crear una snapshot para su registro relacional y guardar en el registro actual. La snapshot no se actualiza cuando el registro se actualiza posteriormente."
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "Add block": "Ajouter un bloc",
3
+ "Allow linking to multiple records": "Autoriser la liaison à plusieurs enregistrements",
4
+ "Detail": "Détail",
5
+ "Please select": "Veuillez sélectionner",
6
+ "Snapshot": "Snapshot",
7
+ "Snapshot the snapshot's association fields": "Snapshot des champs d'association du snapshot",
8
+ "The association field to snapshot": "Le champ d'association à un snapshot",
9
+ "View record": "Voir l'enregistrement",
10
+ "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.": "Lors de l'ajout d'un nouvel enregistrement, créez un snapshot pour son enregistrement relationnel et enregistrez-le dans l'enregistrement actuel. Le snapshot n'est pas mis à jour lorsque l'enregistrement est ultérieurement modifié."
11
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "Add block": "블록 추가",
3
+ "Allow linking to multiple records": "다중 레코드에 연결 허용",
4
+ "Detail": "상세 정보",
5
+ "Please select": "선택하세요",
6
+ "Snapshot": "스냅샷",
7
+ "Snapshot data": "스냅샷 데이터",
8
+ "Snapshot the snapshot's association fields": "스냅샷의 관련 필드를 스냅샷으로 만듭니다.",
9
+ "The association field to snapshot": "스냅샷을 찍을 관련 필드",
10
+ "View record": "레코드 보기",
11
+ "When a record is created, association data is backed up in a snapshot": "레코드가 생성되면 관련 데이터가 스냅샷에 백업됩니다.",
12
+ "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.": "새로운 레코드를 추가할 때 해당 레코드의 관련 데이터에 대한 스냅샷을 생성하고 현재 레코드에 저장합니다. 레코드가 이후에 업데이트되어도 스냅샷은 업데이트되지 않습니다."
13
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "Add block": "Adicionar bloco",
3
+ "Allow linking to multiple records": "Permitir vinculação a vários registros",
4
+ "Detail": "Detalhes",
5
+ "Please select": "Por favor, selecione",
6
+ "Snapshot": "Fotografia",
7
+ "Snapshot the snapshot's association fields": "Criar imagem instantânea para os campos de associação da imagem instantânea",
8
+ "The association field to snapshot": "O campo de associação para criar imagem instantânea",
9
+ "View record": "Visualizar registro",
10
+ "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.": "Ao adicionar um novo registro, crie uma imagem instantânea para o registro relacionado e salve no registro atual. A imagem instantânea não é atualizada quando o registro é posteriormente atualizado."
11
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "Add block": "添加卡片",
3
+ "Allow linking to multiple records": "允许关联多条记录",
4
+ "Detail": "详情",
5
+ "Please select": "请选择",
6
+ "Snapshot": "快照",
7
+ "Snapshot data": "快照数据",
8
+ "Snapshot the snapshot's association fields": "为快照的关系数据创建快照",
9
+ "The association field to snapshot": "快照目标关系字段",
10
+ "View record": "查看数据",
11
+ "When a record is created, association data is backed up in a snapshot": "创建记录时,关系数据会备份到快照里",
12
+ "When adding a new record, create a snapshot for its relational record and save in the new record. The snapshot will not be updated when the relational record is updated.": "在添加数据时,为它的关系数据创建快照,并保存在当前的数据中。关系数据更新时,快照不会更新。"
13
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@tachybase/database").CollectionOptions;
2
+ export default _default;
@@ -0,0 +1,77 @@
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 collectionsHistory_exports = {};
19
+ __export(collectionsHistory_exports, {
20
+ default: () => collectionsHistory_default
21
+ });
22
+ module.exports = __toCommonJS(collectionsHistory_exports);
23
+ var import_database = require("@tachybase/database");
24
+ var collectionsHistory_default = (0, import_database.defineCollection)({
25
+ dumpRules: "required",
26
+ name: "collectionsHistory",
27
+ sortable: "sort",
28
+ autoGenId: false,
29
+ model: "CollectionModel",
30
+ repository: "CollectionRepository",
31
+ timestamps: false,
32
+ filterTargetKey: "name",
33
+ shared: true,
34
+ fields: [
35
+ {
36
+ type: "uid",
37
+ name: "key",
38
+ primaryKey: true
39
+ },
40
+ {
41
+ type: "uid",
42
+ name: "name",
43
+ unique: true,
44
+ prefix: "t_"
45
+ },
46
+ {
47
+ type: "string",
48
+ name: "title",
49
+ required: true
50
+ },
51
+ {
52
+ type: "boolean",
53
+ name: "inherit",
54
+ defaultValue: false
55
+ },
56
+ {
57
+ type: "boolean",
58
+ name: "hidden",
59
+ defaultValue: false
60
+ },
61
+ {
62
+ type: "json",
63
+ name: "options",
64
+ defaultValue: {}
65
+ },
66
+ {
67
+ type: "hasMany",
68
+ name: "fields",
69
+ target: "fieldsHistory",
70
+ sourceKey: "name",
71
+ targetKey: "name",
72
+ foreignKey: "collectionName",
73
+ onDelete: "CASCADE",
74
+ sortBy: "sort"
75
+ }
76
+ ]
77
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@tachybase/database").CollectionOptions;
2
+ export default _default;
@@ -0,0 +1,95 @@
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 fieldsHistory_exports = {};
19
+ __export(fieldsHistory_exports, {
20
+ default: () => fieldsHistory_default
21
+ });
22
+ module.exports = __toCommonJS(fieldsHistory_exports);
23
+ var import_database = require("@tachybase/database");
24
+ var fieldsHistory_default = (0, import_database.defineCollection)({
25
+ dumpRules: "required",
26
+ name: "fieldsHistory",
27
+ autoGenId: false,
28
+ model: "FieldModel",
29
+ timestamps: false,
30
+ shared: true,
31
+ sortable: {
32
+ name: "sort",
33
+ scopeKey: "collectionName"
34
+ },
35
+ indexes: [
36
+ {
37
+ type: "UNIQUE",
38
+ fields: ["collectionName", "name"]
39
+ }
40
+ ],
41
+ fields: [
42
+ {
43
+ type: "uid",
44
+ name: "key",
45
+ primaryKey: true
46
+ },
47
+ {
48
+ type: "uid",
49
+ name: "name",
50
+ prefix: "f_"
51
+ },
52
+ {
53
+ type: "string",
54
+ name: "type"
55
+ },
56
+ {
57
+ type: "string",
58
+ name: "interface",
59
+ allowNull: true
60
+ },
61
+ {
62
+ type: "belongsTo",
63
+ name: "collection",
64
+ target: "collectionsHistory",
65
+ foreignKey: "collectionName",
66
+ targetKey: "name",
67
+ onDelete: "CASCADE"
68
+ },
69
+ {
70
+ type: "hasMany",
71
+ name: "children",
72
+ target: "fieldsHistory",
73
+ sourceKey: "key",
74
+ foreignKey: "parentKey"
75
+ },
76
+ {
77
+ type: "hasOne",
78
+ name: "reverseField",
79
+ target: "fieldsHistory",
80
+ sourceKey: "key",
81
+ foreignKey: "reverseKey"
82
+ },
83
+ // {
84
+ // type: 'belongsTo',
85
+ // name: 'uiSchema',
86
+ // target: 'uiSchemas',
87
+ // foreignKey: 'uiSchemaUid',
88
+ // },
89
+ {
90
+ type: "json",
91
+ name: "options",
92
+ defaultValue: {}
93
+ }
94
+ ]
95
+ });
@@ -0,0 +1,13 @@
1
+ import { BaseColumnFieldOptions, CreateOptions, DataTypes, Field, Model } from '@tachybase/database';
2
+ export declare class SnapshotField extends Field {
3
+ get dataType(): DataTypes.AbstractDataTypeConstructor;
4
+ createSnapshot: (model: Model, { transaction, values }: CreateOptions) => Promise<void>;
5
+ bind(): void;
6
+ unbind(): void;
7
+ }
8
+ export interface SnapshotFieldOptions extends BaseColumnFieldOptions {
9
+ type: 'snapshot';
10
+ targetField: string;
11
+ targetCollection?: string;
12
+ appends?: string[];
13
+ }
@@ -0,0 +1,70 @@
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 field_snapshot_exports = {};
19
+ __export(field_snapshot_exports, {
20
+ SnapshotField: () => SnapshotField
21
+ });
22
+ module.exports = __toCommonJS(field_snapshot_exports);
23
+ var import_database = require("@tachybase/database");
24
+ class SnapshotField extends import_database.Field {
25
+ get dataType() {
26
+ return import_database.DataTypes.JSON;
27
+ }
28
+ createSnapshot = async (model, { transaction, values }) => {
29
+ const { name, targetField } = this.options;
30
+ const collectionName = this.collection.name;
31
+ const primaryKey = this.collection.model.primaryKeyAttribute;
32
+ if (!this.collection.hasField(targetField)) {
33
+ return;
34
+ }
35
+ const repository = this.database.getRepository(`${collectionName}.${targetField}`, model.get(primaryKey));
36
+ const appends = (this.options.appends || []).filter(
37
+ (appendName) => this.database.getFieldByPath(`${repository.targetCollection.name}.${appendName}`)
38
+ );
39
+ let data = await repository.find({
40
+ transaction,
41
+ appends
42
+ });
43
+ if (Array.isArray(data)) {
44
+ data = data.map((i) => i.toJSON());
45
+ } else if (data == null ? void 0 : data.toJSON) {
46
+ data = data.toJSON();
47
+ }
48
+ await model.update(
49
+ {
50
+ [name]: {
51
+ collectionName,
52
+ data
53
+ }
54
+ },
55
+ { transaction }
56
+ );
57
+ };
58
+ bind() {
59
+ super.bind();
60
+ this.on("afterCreateWithAssociations", this.createSnapshot);
61
+ }
62
+ unbind() {
63
+ super.unbind();
64
+ this.off("afterCreateWithAssociations", this.createSnapshot);
65
+ }
66
+ }
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ SnapshotField
70
+ });
@@ -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,13 @@
1
+ import { Model } from '@tachybase/database';
2
+ import { InstallOptions, Plugin } from '@tachybase/server';
3
+ export declare class SnapshotFieldPlugin extends Plugin {
4
+ afterAdd(): void;
5
+ beforeLoad(): Promise<void>;
6
+ autoFillTargetCollection: (model: Model) => Promise<void>;
7
+ load(): Promise<void>;
8
+ install(options?: InstallOptions): Promise<void>;
9
+ afterEnable(): Promise<void>;
10
+ afterDisable(): Promise<void>;
11
+ remove(): Promise<void>;
12
+ }
13
+ export default SnapshotFieldPlugin;
@@ -0,0 +1,128 @@
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 plugin_exports = {};
19
+ __export(plugin_exports, {
20
+ SnapshotFieldPlugin: () => SnapshotFieldPlugin,
21
+ default: () => plugin_default
22
+ });
23
+ module.exports = __toCommonJS(plugin_exports);
24
+ var import_path = require("path");
25
+ var import_server = require("@tachybase/server");
26
+ var import_field_snapshot = require("./fields/field-snapshot");
27
+ class SnapshotFieldPlugin extends import_server.Plugin {
28
+ afterAdd() {
29
+ }
30
+ async beforeLoad() {
31
+ const collectionHandler = async (model, { transaction }) => {
32
+ const collectionDoc = model.toJSON();
33
+ const collectionsHistoryRepository = this.app.db.getRepository("collectionsHistory");
34
+ const fieldsHistoryRepository = this.app.db.getRepository("fieldsHistory");
35
+ const existCollection = await collectionsHistoryRepository.findOne({
36
+ filter: {
37
+ name: collectionDoc.name
38
+ },
39
+ transaction
40
+ });
41
+ if (existCollection) {
42
+ await existCollection.destroy({
43
+ transaction
44
+ });
45
+ }
46
+ await collectionsHistoryRepository.create({
47
+ values: collectionDoc,
48
+ transaction
49
+ });
50
+ };
51
+ this.app.db.on("collections.afterCreateWithAssociations", collectionHandler);
52
+ const deleteField = async (field, transaction) => {
53
+ const fieldsHistoryRepository = this.app.db.getRepository("fieldsHistory");
54
+ const { name, collectionName } = field;
55
+ await fieldsHistoryRepository.destroy({
56
+ filter: { name, collectionName },
57
+ transaction
58
+ });
59
+ };
60
+ const fieldHandler = async (model, { transaction }) => {
61
+ const fieldsHistoryRepository = this.app.db.getRepository("fieldsHistory");
62
+ const fieldDoc = model.get();
63
+ await deleteField(fieldDoc, transaction);
64
+ const reverseField = fieldDoc.reverseField;
65
+ if (reverseField) {
66
+ await deleteField(reverseField, transaction);
67
+ }
68
+ await fieldsHistoryRepository.create({
69
+ values: JSON.parse(JSON.stringify(fieldDoc)),
70
+ transaction
71
+ });
72
+ };
73
+ this.app.db.on("fields.afterCreateWithAssociations", fieldHandler);
74
+ this.app.db.on("fields.beforeCreate", this.autoFillTargetCollection);
75
+ }
76
+ autoFillTargetCollection = async (model) => {
77
+ const { collectionName, targetField } = model.get();
78
+ const collection = this.db.getCollection(collectionName);
79
+ if (!collection) {
80
+ return;
81
+ }
82
+ const field = collection.getField(targetField);
83
+ if (field == null ? void 0 : field.target) {
84
+ model.set("targetCollection", field.target);
85
+ }
86
+ };
87
+ async load() {
88
+ await this.importCollections((0, import_path.resolve)(__dirname, "collections"));
89
+ this.app.db.registerFieldTypes({
90
+ snapshot: import_field_snapshot.SnapshotField
91
+ });
92
+ this.app.acl.allow("collectionsHistory", "list", "loggedIn");
93
+ }
94
+ // 初始化安装的时候
95
+ async install(options) {
96
+ await this.app.db.sequelize.transaction(async (transaction) => {
97
+ const collectionsRepository = this.app.db.getRepository("collections");
98
+ const collectionsHistoryRepository = this.app.db.getRepository("collectionsHistory");
99
+ if ((await collectionsHistoryRepository.find()).length === 0) {
100
+ const collectionsModels = await collectionsRepository.find();
101
+ await collectionsHistoryRepository.createMany({
102
+ records: collectionsModels.map((m) => m.get()),
103
+ transaction
104
+ });
105
+ }
106
+ const fieldsRepository = this.app.db.getRepository("fields");
107
+ const fieldsHistoryRepository = this.app.db.getRepository("fieldsHistory");
108
+ if ((await fieldsHistoryRepository.find()).length === 0) {
109
+ const fieldsModels = await fieldsRepository.find();
110
+ await fieldsHistoryRepository.createMany({
111
+ records: fieldsModels.map((m) => m.get()),
112
+ transaction
113
+ });
114
+ }
115
+ });
116
+ }
117
+ async afterEnable() {
118
+ }
119
+ async afterDisable() {
120
+ }
121
+ async remove() {
122
+ }
123
+ }
124
+ var plugin_default = SnapshotFieldPlugin;
125
+ // Annotate the CommonJS export names for ESM import in node:
126
+ 0 && (module.exports = {
127
+ SnapshotFieldPlugin
128
+ });
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ info: {
3
+ title: string;
4
+ };
5
+ tags: any[];
6
+ paths: {};
7
+ };
8
+ export default _default;
@@ -0,0 +1,29 @@
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 swagger_exports = {};
19
+ __export(swagger_exports, {
20
+ default: () => swagger_default
21
+ });
22
+ module.exports = __toCommonJS(swagger_exports);
23
+ var swagger_default = {
24
+ info: {
25
+ title: "TachyBase API - Snapshot field plugin"
26
+ },
27
+ tags: [],
28
+ paths: {}
29
+ };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@tachybase/plugin-field-snapshot",
3
+ "displayName": "Collection field: Snapshot",
4
+ "version": "0.23.8",
5
+ "description": "When adding a new record, create a snapshot for its relational record and save in the new record. The snapshot will not be updated when the relational record is updated.",
6
+ "keywords": [
7
+ "Collection fields"
8
+ ],
9
+ "license": "Apache-2.0",
10
+ "main": "./dist/server/index.js",
11
+ "devDependencies": {
12
+ "@ant-design/icons": "~5.3.7",
13
+ "antd": "5.22.5",
14
+ "lodash": "4.17.21",
15
+ "rc-tree-select": "5.25.0",
16
+ "react": "~18.3.1",
17
+ "react-i18next": "^15.2.0",
18
+ "@tachybase/schema": "0.23.8"
19
+ },
20
+ "peerDependencies": {
21
+ "@tachybase/client": "0.23.8",
22
+ "@tachybase/test": "0.23.8",
23
+ "@tachybase/server": "0.23.8",
24
+ "@tachybase/database": "0.23.8",
25
+ "@tachybase/utils": "0.23.8"
26
+ },
27
+ "description.zh-CN": "在添加数据时,为它的关系数据创建快照,并保存在当前的数据中。关系数据更新时,快照不会更新。",
28
+ "displayName.zh-CN": "数据表字段:关系快照",
29
+ "scripts": {
30
+ "build": "tachybase-build --no-dts @tachybase/plugin-field-snapshot"
31
+ }
32
+ }
package/server.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/server';
2
+ export { default } from './dist/server';
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/server/index.js');