@nocobase/plugin-workflow-aggregate 0.17.0-alpha.4
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 +661 -0
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/AggregateInstruction.d.ts +212 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +4 -0
- package/dist/externalVersion.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +12 -0
- package/dist/locale/index.d.ts +3 -0
- package/dist/locale/index.js +39 -0
- package/dist/locale/zh-CN.json +12 -0
- package/dist/server/AggregateInstruction.d.ts +7 -0
- package/dist/server/AggregateInstruction.js +54 -0
- package/dist/server/Plugin.d.ts +6 -0
- package/dist/server/Plugin.js +42 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/package.json +24 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/AggregateInstruction.tsx +399 -0
- package/src/client/index.ts +19 -0
- package/src/index.ts +2 -0
- package/src/locale/en-US.json +12 -0
- package/src/locale/index.ts +12 -0
- package/src/locale/zh-CN.json +12 -0
- package/src/server/AggregateInstruction.ts +39 -0
- package/src/server/Plugin.ts +14 -0
- package/src/server/__tests__/instruction.test.ts +298 -0
- package/src/server/index.ts +1 -0
package/client.d.ts
ADDED
package/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/client/index.js');
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SchemaInitializerItemType, useCollectionDataSource } from '@nocobase/client';
|
|
3
|
+
import { FilterDynamicComponent, Instruction } from '@nocobase/plugin-workflow/client';
|
|
4
|
+
declare function AssociatedConfig({ value, onChange, ...props }: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
value: any;
|
|
7
|
+
onChange: any;
|
|
8
|
+
}): JSX.Element;
|
|
9
|
+
export default class extends Instruction {
|
|
10
|
+
title: string;
|
|
11
|
+
type: string;
|
|
12
|
+
group: string;
|
|
13
|
+
description: string;
|
|
14
|
+
fieldset: {
|
|
15
|
+
aggregator: {
|
|
16
|
+
type: string;
|
|
17
|
+
title: string;
|
|
18
|
+
'x-decorator': string;
|
|
19
|
+
'x-component': string;
|
|
20
|
+
enum: {
|
|
21
|
+
label: string;
|
|
22
|
+
value: string;
|
|
23
|
+
}[];
|
|
24
|
+
required: boolean;
|
|
25
|
+
default: string;
|
|
26
|
+
};
|
|
27
|
+
associated: {
|
|
28
|
+
type: string;
|
|
29
|
+
title: string;
|
|
30
|
+
'x-decorator': string;
|
|
31
|
+
'x-component': string;
|
|
32
|
+
enum: {
|
|
33
|
+
label: string;
|
|
34
|
+
value: boolean;
|
|
35
|
+
}[];
|
|
36
|
+
required: boolean;
|
|
37
|
+
default: boolean;
|
|
38
|
+
'x-reactions': {
|
|
39
|
+
target: string;
|
|
40
|
+
effects: string[];
|
|
41
|
+
fulfill: {
|
|
42
|
+
state: {
|
|
43
|
+
value: any;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
collectionField: {
|
|
49
|
+
type: string;
|
|
50
|
+
'x-decorator': string;
|
|
51
|
+
'x-decorator-props': {
|
|
52
|
+
value: {
|
|
53
|
+
designable: boolean;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
'x-component': string;
|
|
57
|
+
properties: {
|
|
58
|
+
row: {
|
|
59
|
+
type: string;
|
|
60
|
+
'x-component': string;
|
|
61
|
+
properties: {
|
|
62
|
+
target: {
|
|
63
|
+
type: string;
|
|
64
|
+
'x-component': string;
|
|
65
|
+
properties: {
|
|
66
|
+
collection: {
|
|
67
|
+
type: string;
|
|
68
|
+
required: boolean;
|
|
69
|
+
'x-decorator': string;
|
|
70
|
+
'x-component': string;
|
|
71
|
+
title: string;
|
|
72
|
+
'x-reactions': ({
|
|
73
|
+
dependencies: string[];
|
|
74
|
+
fulfill: {
|
|
75
|
+
state: {
|
|
76
|
+
display: string;
|
|
77
|
+
value?: undefined;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
target?: undefined;
|
|
81
|
+
effects?: undefined;
|
|
82
|
+
} | {
|
|
83
|
+
target: string;
|
|
84
|
+
effects: string[];
|
|
85
|
+
fulfill: {
|
|
86
|
+
state: {
|
|
87
|
+
value: any;
|
|
88
|
+
display?: undefined;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
dependencies?: undefined;
|
|
92
|
+
})[];
|
|
93
|
+
};
|
|
94
|
+
association: {
|
|
95
|
+
type: string;
|
|
96
|
+
title: string;
|
|
97
|
+
'x-decorator': string;
|
|
98
|
+
'x-component': string;
|
|
99
|
+
'x-component-props': {
|
|
100
|
+
changeOnSelect: boolean;
|
|
101
|
+
};
|
|
102
|
+
'x-reactions': {
|
|
103
|
+
dependencies: string[];
|
|
104
|
+
fulfill: {
|
|
105
|
+
state: {
|
|
106
|
+
visible: string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
}[];
|
|
110
|
+
required: boolean;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
field: {
|
|
115
|
+
type: string;
|
|
116
|
+
'x-component': string;
|
|
117
|
+
properties: {
|
|
118
|
+
'params.field': {
|
|
119
|
+
type: string;
|
|
120
|
+
title: string;
|
|
121
|
+
'x-decorator': string;
|
|
122
|
+
'x-component': string;
|
|
123
|
+
'x-component-props': {
|
|
124
|
+
filter(field: any): boolean;
|
|
125
|
+
};
|
|
126
|
+
required: boolean;
|
|
127
|
+
'x-reactions': {
|
|
128
|
+
dependencies: string[];
|
|
129
|
+
fulfill: {
|
|
130
|
+
state: {
|
|
131
|
+
visible: string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
}[];
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
params: {
|
|
143
|
+
type: string;
|
|
144
|
+
properties: {
|
|
145
|
+
distinct: {
|
|
146
|
+
type: string;
|
|
147
|
+
title: string;
|
|
148
|
+
'x-decorator': string;
|
|
149
|
+
'x-component': string;
|
|
150
|
+
'x-reactions': {
|
|
151
|
+
dependencies: string[];
|
|
152
|
+
fulfill: {
|
|
153
|
+
state: {
|
|
154
|
+
visible: string;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
}[];
|
|
158
|
+
};
|
|
159
|
+
filter: {
|
|
160
|
+
type: string;
|
|
161
|
+
title: string;
|
|
162
|
+
'x-decorator': string;
|
|
163
|
+
'x-component': string;
|
|
164
|
+
'x-component-props': {
|
|
165
|
+
useProps(): {
|
|
166
|
+
options: any[];
|
|
167
|
+
className: string;
|
|
168
|
+
};
|
|
169
|
+
dynamicComponent: string;
|
|
170
|
+
};
|
|
171
|
+
'x-reactions': {
|
|
172
|
+
dependencies: string[];
|
|
173
|
+
fulfill: {
|
|
174
|
+
state: {
|
|
175
|
+
visible: string;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
}[];
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
scope: {
|
|
184
|
+
useCollectionDataSource: typeof useCollectionDataSource;
|
|
185
|
+
};
|
|
186
|
+
components: {
|
|
187
|
+
SchemaComponentContext: React.Context<import("@nocobase/client").ISchemaComponentContext>;
|
|
188
|
+
FilterDynamicComponent: typeof FilterDynamicComponent;
|
|
189
|
+
FieldsSelect: React.MemoExoticComponent<import("@formily/react").ReactFC<Omit<any, "ref">>>;
|
|
190
|
+
ValueBlock: (() => JSX.Element) & {
|
|
191
|
+
Initializer: () => JSX.Element;
|
|
192
|
+
Result: (props: any) => JSX.Element;
|
|
193
|
+
};
|
|
194
|
+
AssociatedConfig: typeof AssociatedConfig;
|
|
195
|
+
};
|
|
196
|
+
useVariables({ key, title }: {
|
|
197
|
+
key: any;
|
|
198
|
+
title: any;
|
|
199
|
+
}, { types, fieldNames }: {
|
|
200
|
+
types: any;
|
|
201
|
+
fieldNames?: {
|
|
202
|
+
readonly label: "label";
|
|
203
|
+
readonly value: "value";
|
|
204
|
+
readonly children: "children";
|
|
205
|
+
};
|
|
206
|
+
}): {
|
|
207
|
+
value: any;
|
|
208
|
+
label: any;
|
|
209
|
+
};
|
|
210
|
+
useInitializers(node: any): SchemaInitializerItemType | null;
|
|
211
|
+
}
|
|
212
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
(function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("@formily/react"),require("antd"),require("react"),require("@nocobase/plugin-workflow/client"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","@formily/react","antd","react","@nocobase/plugin-workflow/client","react-i18next"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["@nocobase/plugin-workflow-aggregate"]={},e["@nocobase/client"],e.jsxRuntime,e["@formily/react"],e.antd,e.react,e["@nocobase/plugin-workflow"],e["react-i18next"]))})(this,function(e,t,n,s,S,h,c,C){"use strict";var H=Object.defineProperty,J=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var $=(e,t,n)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,O=(e,t)=>{for(var n in t||(t={}))A.call(t,n)&&$(e,n,t[n]);if(I)for(var n of I(t))D.call(t,n)&&$(e,n,t[n]);return e},V=(e,t)=>J(e,W(t));var G=(e,t)=>{var n={};for(var s in e)A.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(e!=null&&I)for(var s of I(e))t.indexOf(s)<0&&D.call(e,s)&&(n[s]=e[s]);return n};var g=(e,t,n)=>($(e,typeof t!="symbol"?t+"":t,n),n);var x=(e,t,n)=>new Promise((s,S)=>{var h=i=>{try{C(n.next(i))}catch(b){S(b)}},c=i=>{try{C(n.throw(i))}catch(b){S(b)}},C=i=>i.done?s(i.value):Promise.resolve(i.value).then(h,c);C((n=n.apply(e,t)).next())});const i="workflow-aggregate";function b(l,r={}){const{t:o}=B(r);return o(l)}function B(l){return C.useTranslation(i,l)}function N(l){return["hasMany","belongsToMany"].includes(l.type)}function P(){const l=t.useCompile();return[c.nodesOptions,c.triggerOptions].map(r=>{var p;const o=(p=r.useOptions({types:[N],appends:null,depth:4}))==null?void 0:p.filter(Boolean);return{label:l(r.label),value:r.value,key:r.value,children:l(o),disabled:o&&!o.length}})}function K(p){var f=p,{value:l,onChange:r}=f,o=G(f,["value","onChange"]);const{setValuesIn:v}=s.useForm(),{getCollection:T}=t.useCollectionManager(),M=P(),[F,q]=h.useState(M),{associatedKey:L="",name:z}=l!=null?l:{};let w=[];const j=L.match(/^{{(.*)}}$/);j&&(w=[...j[1].trim().split(".").slice(0,-1),z]);const U=m=>x(this,null,function*(){var u;const a=m[m.length-1];!((u=a.children)!=null&&u.length)&&!a.isLeaf&&a.loadChildren&&(yield a.loadChildren(a),q(d=>[...d]))});h.useEffect(()=>{(()=>x(this,null,function*(){var u;if(!w||F.length<=1)return;let a=null;for(let d=0;d<w.length;d++){const k=w[d];try{d===0?a=F.find(y=>y.value===k):(a.loadChildren&&!((u=a.children)!=null&&u.length)&&(yield a.loadChildren(a)),a=a.children.find(y=>y.value===k))}catch(y){console.error(y)}}q([...F])}))()},[l,F.length]);const _=h.useCallback((m,a)=>{if(!(m!=null&&m.length)){v("collection",null),r({});return}const{field:u}=a.pop();if(!u||!["hasMany","belongsToMany"].includes(u.type))return;const{collectionName:d,target:k,name:y}=u,Q=T(d).fields.find(X=>X.primaryKey);v("collection",k),r({name:y,associatedKey:`{{${m.slice(0,-1).join(".")}.${Q.name}}}`,associatedCollection:d})},[r]);return n.jsx(S.Cascader,V(O({},o),{value:w,options:F,onChange:_,loadData:U}))}class R extends c.Instruction{constructor(){super(...arguments);g(this,"title",`{{t("Aggregate", { ns: "${i}" })}}`);g(this,"type","aggregate");g(this,"group","collection");g(this,"description",`{{t("Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.", { ns: "${i}" })}}`);g(this,"fieldset",{aggregator:{type:"string",title:`{{t("Aggregator function", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"Radio.Group",enum:[{label:"COUNT",value:"count"},{label:"SUM",value:"sum"},{label:"AVG",value:"avg"},{label:"MIN",value:"min"},{label:"MAX",value:"max"}],required:!0,default:"count"},associated:{type:"boolean",title:`{{t("Target type", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"Radio.Group",enum:[{label:`{{t("Data of collection", { ns: "${i}" })}}`,value:!1},{label:`{{t("Data of associated collection", { ns: "${i}" })}}`,value:!0}],required:!0,default:!1,"x-reactions":[{target:"collection",effects:["onFieldValueChange"],fulfill:{state:{value:null}}},{target:"association",effects:["onFieldValueChange"],fulfill:{state:{value:null}}}]},collectionField:{type:"void","x-decorator":"SchemaComponentContext.Provider","x-decorator-props":{value:{designable:!1}},"x-component":"Grid",properties:{row:{type:"void","x-component":"Grid.Row",properties:{target:{type:"void","x-component":"Grid.Col",properties:{collection:{type:"string",required:!0,"x-decorator":"FormItem","x-component":"CollectionSelect",title:`{{t("Data of collection", { ns: "${i}" })}}`,"x-reactions":[{dependencies:["associated"],fulfill:{state:{display:'{{$deps[0] ? "hidden" : "visible"}}'}}},{target:"params.field",effects:["onFieldValueChange"],fulfill:{state:{value:null}}},{target:"params.filter",effects:["onFieldValueChange"],fulfill:{state:{value:null}}}]},association:{type:"object",title:`{{t("Data of associated collection", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"AssociatedConfig","x-component-props":{changeOnSelect:!0},"x-reactions":[{dependencies:["associated"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}],required:!0}}},field:{type:"void","x-component":"Grid.Col",properties:{"params.field":{type:"string",title:`{{t("Field to aggregate", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"FieldsSelect","x-component-props":{filter(o){return!o.hidden&&o.interface&&!["belongsTo","hasOne","hasMany","belongsToMany"].includes(o.type)}},required:!0,"x-reactions":[{dependencies:["collection"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}]}}}}}}},params:{type:"object",properties:{distinct:{type:"boolean",title:`{{t("Distinct", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"Checkbox","x-reactions":[{dependencies:["collection","aggregator"],fulfill:{state:{visible:'{{!!$deps[0] && ["count"].includes($deps[1])}}'}}}]},filter:{type:"object",title:'{{t("Filter")}}',"x-decorator":"FormItem","x-component":"Filter","x-component-props":{useProps(){const{values:o}=s.useForm();return{options:t.useCollectionFilterOptions(o==null?void 0:o.collection),className:t.css`
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 100%;
|
|
4
|
+
`}},dynamicComponent:"FilterDynamicComponent"},"x-reactions":[{dependencies:["collection"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}]}}}});g(this,"scope",{useCollectionDataSource:t.useCollectionDataSource});g(this,"components",{SchemaComponentContext:t.SchemaComponentContext,FilterDynamicComponent:c.FilterDynamicComponent,FieldsSelect:c.FieldsSelect,ValueBlock:c.ValueBlock,AssociatedConfig:K})}useVariables({key:o,title:p},{types:f,fieldNames:v=c.defaultFieldNames}){return f&&!f.some(T=>T in c.BaseTypeSets||Object.values(c.BaseTypeSets).some(M=>M.has(T)))?null:{[v.value]:o,[v.label]:p}}useInitializers(o){var f;const p=b("Query result");return o.config.collection?{name:`#${o.id}`,type:"item",title:(f=o.title)!=null?f:`#${o.id}`,Component:c.ValueBlock.Initializer,node:o,resultTitle:p}:null}}class E extends t.Plugin{afterAdd(){return x(this,null,function*(){})}beforeLoad(){return x(this,null,function*(){})}load(){return x(this,null,function*(){const r=this.app.pm.get("workflow"),o=new R;r.instructions.register(o.type,o)})}}e.default=E,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
"@formily/react": "2.2.27",
|
|
3
|
+
"antd": "5.8.6",
|
|
4
|
+
"react": "18.2.0",
|
|
5
|
+
"@nocobase/client": "0.17.0-alpha.4",
|
|
6
|
+
"@nocobase/plugin-workflow": "0.17.0-alpha.4",
|
|
7
|
+
"react-i18next": "11.18.6",
|
|
8
|
+
"@nocobase/database": "0.17.0-alpha.4",
|
|
9
|
+
"@nocobase/server": "0.17.0-alpha.4"
|
|
10
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
default: () => import_server.default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(src_exports);
|
|
34
|
+
__reExport(src_exports, require("./server"), module.exports);
|
|
35
|
+
var import_server = __toESM(require("./server"));
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
...require("./server")
|
|
39
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Aggregate": "Aggregate",
|
|
3
|
+
"Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.":
|
|
4
|
+
"Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.",
|
|
5
|
+
"Aggregator function": "Aggregator function",
|
|
6
|
+
"Target type": "Target type",
|
|
7
|
+
"Data of collection": "Data of collection",
|
|
8
|
+
"Data of associated collection": "Data of associated collection",
|
|
9
|
+
"Field to aggregate": "Field to aggregate",
|
|
10
|
+
"Distinct": "Distinct",
|
|
11
|
+
"Query result": "Query result"
|
|
12
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 locale_exports = {};
|
|
19
|
+
__export(locale_exports, {
|
|
20
|
+
NAMESPACE: () => NAMESPACE,
|
|
21
|
+
useLang: () => useLang,
|
|
22
|
+
usePluginTranslation: () => usePluginTranslation
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(locale_exports);
|
|
25
|
+
var import_react_i18next = require("react-i18next");
|
|
26
|
+
const NAMESPACE = "workflow-aggregate";
|
|
27
|
+
function useLang(key, options = {}) {
|
|
28
|
+
const { t } = usePluginTranslation(options);
|
|
29
|
+
return t(key);
|
|
30
|
+
}
|
|
31
|
+
function usePluginTranslation(options) {
|
|
32
|
+
return (0, import_react_i18next.useTranslation)(NAMESPACE, options);
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
NAMESPACE,
|
|
37
|
+
useLang,
|
|
38
|
+
usePluginTranslation
|
|
39
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Aggregate": "聚合查询",
|
|
3
|
+
"Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.":
|
|
4
|
+
"对一个数据表里的多条数据或者一条数据里的关系数据进行统计、求和、求最大值、最小值、平均值。",
|
|
5
|
+
"Aggregator function": "聚合函数",
|
|
6
|
+
"Target type": "目标类型",
|
|
7
|
+
"Data of collection": "数据表数据",
|
|
8
|
+
"Data of associated collection": "关联数据表数据",
|
|
9
|
+
"Field to aggregate": "聚合字段",
|
|
10
|
+
"Distinct": "去重",
|
|
11
|
+
"Query result": "查询结果"
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 AggregateInstruction_exports = {};
|
|
19
|
+
__export(AggregateInstruction_exports, {
|
|
20
|
+
default: () => AggregateInstruction_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(AggregateInstruction_exports);
|
|
23
|
+
var import_database = require("@nocobase/database");
|
|
24
|
+
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
25
|
+
const aggregators = {
|
|
26
|
+
count: "count",
|
|
27
|
+
sum: "sum",
|
|
28
|
+
avg: "avg",
|
|
29
|
+
min: "min",
|
|
30
|
+
max: "max"
|
|
31
|
+
};
|
|
32
|
+
class AggregateInstruction_default extends import_plugin_workflow.Instruction {
|
|
33
|
+
async run(node, input, processor) {
|
|
34
|
+
const { aggregator, associated, collection, association = {}, params = {} } = node.config;
|
|
35
|
+
const options = processor.getParsedValue(params, node.id);
|
|
36
|
+
const { database } = node.constructor;
|
|
37
|
+
const repo = associated ? database.getRepository(
|
|
38
|
+
`${association == null ? void 0 : association.associatedCollection}.${association.name}`,
|
|
39
|
+
processor.getParsedValue(association == null ? void 0 : association.associatedKey, node.id)
|
|
40
|
+
) : database.getRepository(collection);
|
|
41
|
+
if (!options.dataType && aggregator === "avg") {
|
|
42
|
+
options.dataType = import_database.DataTypes.DOUBLE;
|
|
43
|
+
}
|
|
44
|
+
const result = await repo.aggregate({
|
|
45
|
+
...options,
|
|
46
|
+
method: aggregators[aggregator],
|
|
47
|
+
transaction: processor.transaction
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
result: options.dataType === import_database.DataTypes.DOUBLE ? Number(result) : result,
|
|
51
|
+
status: import_plugin_workflow.JOB_STATUS.RESOLVED
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var Plugin_exports = {};
|
|
29
|
+
__export(Plugin_exports, {
|
|
30
|
+
default: () => Plugin_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(Plugin_exports);
|
|
33
|
+
var import_server = require("@nocobase/server");
|
|
34
|
+
var import_AggregateInstruction = __toESM(require("./AggregateInstruction"));
|
|
35
|
+
class Plugin_default extends import_server.Plugin {
|
|
36
|
+
workflow;
|
|
37
|
+
async load() {
|
|
38
|
+
const workflowPlugin = this.app.getPlugin("workflow");
|
|
39
|
+
this.workflow = workflowPlugin;
|
|
40
|
+
workflowPlugin.instructions.register("aggregate", new import_AggregateInstruction.default(workflowPlugin));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -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"));
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-workflow-aggregate",
|
|
3
|
+
"displayName": "Workflow: Aggregate node",
|
|
4
|
+
"displayName.zh-CN": "工作流:聚合查询节点",
|
|
5
|
+
"description": "Used to aggregate data against the database in workflow, such as: statistics, sum, average, etc.",
|
|
6
|
+
"description.zh-CN": "可用于在工作流中对数据库进行聚合查询,如:统计数量、求和、平均值等。",
|
|
7
|
+
"version": "0.17.0-alpha.4",
|
|
8
|
+
"license": "AGPL-3.0",
|
|
9
|
+
"main": "./dist/server/index.js",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"antd": "5.x",
|
|
12
|
+
"react": "18.x",
|
|
13
|
+
"react-i18next": "^11.15.1"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"@nocobase/client": "0.x",
|
|
17
|
+
"@nocobase/database": "0.x",
|
|
18
|
+
"@nocobase/plugin-workflow": ">=0.17.0-alpha.3",
|
|
19
|
+
"@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3",
|
|
20
|
+
"@nocobase/server": "0.x",
|
|
21
|
+
"@nocobase/test": "0.x"
|
|
22
|
+
},
|
|
23
|
+
"gitHead": "663b03a3799a70ba1a2bc6a0d686e679331a50ad"
|
|
24
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|