@cloudbase/cals 1.2.10 → 1.2.11

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.
@@ -0,0 +1,2 @@
1
+ export declare function getUsedDatasource(apps: any, options: any): Record<string, Set<string>>;
2
+ //# sourceMappingURL=getUsedDatasource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUsedDatasource.d.ts","sourceRoot":"","sources":["../../../../../src/parser/cals/utils/getUsedDatasource.ts"],"names":[],"mappings":"AAKA,wBAAgB,iBAAiB,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CA2J5E"}
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUsedDatasource = void 0;
4
+ const types_1 = require("../../../types");
5
+ const utils_1 = require("../../../utils");
6
+ const expression_1 = require("../../expression");
7
+ const common_1 = require("./common");
8
+ function getUsedDatasource(apps, options) {
9
+ const { defaultGroup = 'default', datasources = [] } = options || '';
10
+ const usedMap = {};
11
+ const HANDLER_NAME = 'cloud.callDatasource';
12
+ apps.forEach((cals) => {
13
+ const key = cals.id || cals.appId || defaultGroup;
14
+ function processCode(code = '', set) {
15
+ code
16
+ // @ts-ignore
17
+ .replace(/\bapp(?:\.cloud)?\.dataSources\.([\da-zA-Z_]+)\b/g, (_$0, $1) => {
18
+ if ($1) {
19
+ set.add($1);
20
+ }
21
+ })
22
+ // 匹配 app.dataSources['methodName'] 形式
23
+ // 及 app.cloud.dataSources['methodName'] 形式
24
+ // @ts-ignore
25
+ .replace(/\bapp(?:\.cloud)?\.dataSources\[\s*(['"])([\da-zA-Z_]+)\1\s*\]/g, (_$0, _$1, $2) => {
26
+ if ($2) {
27
+ set.push($2);
28
+ }
29
+ })
30
+ // 匹配 app.cloud.utils.wrapperDatasourceMethod({dataSourceName: 'xxx', methodName: 'xxx'}) 的调用情况
31
+ .replace(/\bapp\.cloud\.utils\.wrapperDatasourceMethod\([\s\n]*\{(?:.|\n)*?(['"]?)dataSourceName\1\s*:\s*(['"])([\da-zA-Z_]+)\2/g,
32
+ // @ts-ignore
33
+ (_$0, _$1, _$2, $3) => {
34
+ if ($3) {
35
+ set.push($3);
36
+ }
37
+ })
38
+ // 匹配 app.cloud.callDataSource({dataSourceName: 'xxx'}) 的调用情况
39
+ .replace(/\bapp\.cloud\.(?:callDataSource|callModel|callConnector)\([\s\n]*\{(?:.|\n)*?(['"]?)(?:dataSourceName|name)\1\s*:\s*(['"])([\da-zA-Z_]+)\2/g,
40
+ // @ts-ignore
41
+ (_$0, _$1, _$2, $3) => {
42
+ if ($3) {
43
+ set.push($3);
44
+ }
45
+ });
46
+ }
47
+ function processListeners(listeners = [], set) {
48
+ listeners.forEach((listener) => {
49
+ var _a, _b, _c, _d;
50
+ if (listener.type === expression_1.ActionType.GeneralFunc) {
51
+ processCode(listener.handler[':code'], set);
52
+ }
53
+ else if (((_a = listener.handler) === null || _a === void 0 ? void 0 : _a.module) === 'platform') {
54
+ switch ((_b = listener.handler) === null || _b === void 0 ? void 0 : _b.name) {
55
+ case HANDLER_NAME: {
56
+ if ((_d = (_c = listener.handler) === null || _c === void 0 ? void 0 : _c.params) === null || _d === void 0 ? void 0 : _d.dataSourceName) {
57
+ set.add(listener.handler.params.dataSourceName);
58
+ }
59
+ break;
60
+ }
61
+ }
62
+ }
63
+ });
64
+ }
65
+ try {
66
+ (0, common_1.walkThroughComponents)([cals], (component) => {
67
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
68
+ const { resources = [], listeners = [], dataset = {} } = component;
69
+ if (!usedMap[key]) {
70
+ usedMap[key] = new Set();
71
+ }
72
+ // listener eventflow
73
+ processListeners(listeners, usedMap[key]);
74
+ // resource
75
+ resources.forEach(({ code = '' }) => {
76
+ processCode(code, usedMap[key]);
77
+ });
78
+ Object.values((dataset === null || dataset === void 0 ? void 0 : dataset.state) || {}).forEach((meta) => {
79
+ if (meta.varType == 'datasource' && meta.dataSourceName) {
80
+ usedMap[key].add(meta.dataSourceName);
81
+ }
82
+ });
83
+ Object.values((dataset === null || dataset === void 0 ? void 0 : dataset.query) || {}).forEach((query) => {
84
+ var _a, _b, _c;
85
+ if ([types_1.EQueryType.Model, types_1.EQueryType.Apis].includes(query.type) &&
86
+ ((_b = (_a = query.handler) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.dataSourceName)) {
87
+ usedMap[key].add(query.handler.params.dataSourceName);
88
+ }
89
+ else if (query.type === types_1.EQueryType.GeneralFunc) {
90
+ processCode((_c = query.handler) === null || _c === void 0 ? void 0 : _c[':code'], usedMap[key]);
91
+ }
92
+ processListeners(query.listeners, usedMap[key]);
93
+ });
94
+ if (component.module === utils_1.OFFICIAL_LIB_KEY) {
95
+ const data = component.attributes;
96
+ if (component.attributes.varPath) {
97
+ let dsName = component.attributes.varPath;
98
+ if (Array.isArray(component.attributes.varPath) && component.attributes.varPath.length === 2) {
99
+ [dsName] = component.attributes.varPath;
100
+ }
101
+ if (typeof dsName === 'string' && /^[a-z\d_]+$/.test(dsName)) {
102
+ usedMap[key].add(dsName);
103
+ }
104
+ }
105
+ // 其他绑定数据源的组件, 如 地图、图表等
106
+ if ((_a = data === null || data === void 0 ? void 0 : data.dataSource) === null || _a === void 0 ? void 0 : _a.name) {
107
+ const dsName = (_b = data === null || data === void 0 ? void 0 : data.dataSource) === null || _b === void 0 ? void 0 : _b.name;
108
+ if (typeof dsName === 'string' && /^[a-z\d_]+$/.test(dsName)) {
109
+ usedMap[key].add(dsName);
110
+ }
111
+ }
112
+ // 绑定连接器选择的连接器
113
+ if ((_d = (_c = data === null || data === void 0 ? void 0 : data.bindConnectMetadata) === null || _c === void 0 ? void 0 : _c.datasource) === null || _d === void 0 ? void 0 : _d.name) {
114
+ const dsName = (_e = data === null || data === void 0 ? void 0 : data.bindConnectMetadata) === null || _e === void 0 ? void 0 : _e.datasource.name;
115
+ if (component.component !== 'ModelTable' || (data === null || data === void 0 ? void 0 : data.dataSourceType) === 'custom-connector') {
116
+ usedMap[key].add(dsName);
117
+ }
118
+ }
119
+ // 业务模型组件数据源绑定
120
+ if ((_g = (_f = data === null || data === void 0 ? void 0 : data.bindMetadata) === null || _f === void 0 ? void 0 : _f.datasource) === null || _g === void 0 ? void 0 : _g.name) {
121
+ if (component.component !== 'ModelTable' || (data === null || data === void 0 ? void 0 : data.dataSourceType) !== 'custom-connector') {
122
+ usedMap[key].add(data.bindMetadata.datasource.name);
123
+ }
124
+ }
125
+ for (const key in data) {
126
+ if (utils_1.DYNAMIC_KEY_REG.test(key)) {
127
+ const code = data[key];
128
+ processCode(code, usedMap[key]);
129
+ }
130
+ }
131
+ // 应当判断数据容器,compConfig 中包含 isDataContainer
132
+ // 此处为了方便,松散判断
133
+ if ((_h = data === null || data === void 0 ? void 0 : data.datasource) === null || _h === void 0 ? void 0 : _h.name) {
134
+ usedMap[key].add((_j = data === null || data === void 0 ? void 0 : data.datasource) === null || _j === void 0 ? void 0 : _j.name);
135
+ }
136
+ }
137
+ });
138
+ }
139
+ catch (e) {
140
+ console.error('walkRuntimeComponent error', e);
141
+ }
142
+ if (datasources === null || datasources === void 0 ? void 0 : datasources.length) {
143
+ for (const key in usedMap) {
144
+ const set = usedMap[key];
145
+ const list = Array.from(set);
146
+ usedMap[key] = new Set(list.concat(Array.from(getConnectedDataSourceNames(list, datasources))));
147
+ }
148
+ }
149
+ });
150
+ return usedMap;
151
+ }
152
+ exports.getUsedDatasource = getUsedDatasource;
153
+ /**
154
+ * 获取数据源关联的数据源名字
155
+ */
156
+ function getConnectedDataSourceNames(names, dataSources) {
157
+ const connectedDsNames = new Set();
158
+ names.forEach((name) => {
159
+ const ds = dataSources.find((ds) => ds.name === name);
160
+ if (!ds || ds.type !== 'database' || !ds.schema.properties)
161
+ return;
162
+ // @ts-ignore
163
+ if (Array.isArray(ds.childDataSourceNames)) {
164
+ // @ts-ignore
165
+ // connectedDsNames = connectedDsNames.concat(ds.childDataSourceNames);
166
+ }
167
+ const isSystem = name === 'sys_user' || name === 'sys_department';
168
+ const RELATE_FORMAT_MAP = {
169
+ 'many-one': true,
170
+ 'one-one': true,
171
+ 'one-one-r': true,
172
+ 'one-many': true,
173
+ 'many-many': true,
174
+ };
175
+ Object.keys(ds.schema.properties).forEach((key) => {
176
+ const meta = ds.schema.properties[key];
177
+ /**
178
+ * system 不处理关联关系
179
+ */
180
+ if (isSystem && RELATE_FORMAT_MAP[meta.format]) {
181
+ return;
182
+ }
183
+ if (!meta['x-parent'])
184
+ return;
185
+ connectedDsNames.add(ds.schema.properties[key]['x-parent'].parentDataSourceName);
186
+ });
187
+ });
188
+ return Array.from(connectedDsNames);
189
+ }
@@ -0,0 +1,4 @@
1
+ import { IPlatformApp } from '../../../types';
2
+ export declare function getUsedQueryPlugin(calses?: IPlatformApp[], options?: any): {};
3
+ export declare function getUsedSQLConnector(calses?: IPlatformApp[], options?: any): void;
4
+ //# sourceMappingURL=getUsedQueryPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUsedQueryPlugin.d.ts","sourceRoot":"","sources":["../../../../../src/parser/cals/utils/getUsedQueryPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,YAAY,EAAO,EAAE,OAAO,CAAC,KAAA,MAgCvE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,YAAY,EAAO,EAAE,OAAO,CAAC,KAAA,QAiCxE"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUsedSQLConnector = exports.getUsedQueryPlugin = void 0;
4
+ function getUsedQueryPlugin(calses = [], options) {
5
+ const { defaultGroup = 'default' } = options || '';
6
+ const usesMap = {};
7
+ function parseQuery(set, query = {}) {
8
+ Object.entries(query).forEach(([key, meta]) => {
9
+ var _a, _b, _c;
10
+ switch (meta.type) {
11
+ case 'model':
12
+ case 'apis': {
13
+ return;
14
+ }
15
+ default: {
16
+ const params = Array.isArray((_a = meta.handler) === null || _a === void 0 ? void 0 : _a.params) ? (_b = meta.handler) === null || _b === void 0 ? void 0 : _b.params[0] : (_c = meta.handler) === null || _c === void 0 ? void 0 : _c.params;
17
+ if (params === null || params === void 0 ? void 0 : params.sqlTemplateId) {
18
+ set.add(params === null || params === void 0 ? void 0 : params.sqlTemplateId);
19
+ }
20
+ }
21
+ }
22
+ });
23
+ }
24
+ calses.forEach((cals) => {
25
+ var _a, _b, _c;
26
+ const id = cals.id || cals.appId || defaultGroup;
27
+ if (!usesMap[id]) {
28
+ usesMap[id] = new Set([]);
29
+ }
30
+ if (!((_a = cals === null || cals === void 0 ? void 0 : cals.extra) === null || _a === void 0 ? void 0 : _a.rootPath)) {
31
+ parseQuery(usesMap[id], (_b = cals.dataset) === null || _b === void 0 ? void 0 : _b.query);
32
+ }
33
+ (_c = cals.items) === null || _c === void 0 ? void 0 : _c.forEach((page) => {
34
+ var _a;
35
+ parseQuery(usesMap[id], (_a = page.dataset) === null || _a === void 0 ? void 0 : _a.query);
36
+ });
37
+ });
38
+ return usesMap;
39
+ }
40
+ exports.getUsedQueryPlugin = getUsedQueryPlugin;
41
+ function getUsedSQLConnector(calses = [], options) {
42
+ const { defaultGroup = 'default' } = options || '';
43
+ const usesMap = {};
44
+ function parseQuery(set, query = {}) {
45
+ Object.entries(query).forEach(([key, meta]) => {
46
+ var _a, _b, _c;
47
+ switch (meta.type) {
48
+ case 'model':
49
+ case 'apis': {
50
+ return;
51
+ }
52
+ default: {
53
+ const params = Array.isArray((_a = meta.handler) === null || _a === void 0 ? void 0 : _a.params) ? (_b = meta.handler) === null || _b === void 0 ? void 0 : _b.params[0] : (_c = meta.handler) === null || _c === void 0 ? void 0 : _c.params;
54
+ if (params === null || params === void 0 ? void 0 : params.datasourceName) {
55
+ set.add(params === null || params === void 0 ? void 0 : params.datasourceName);
56
+ }
57
+ }
58
+ }
59
+ });
60
+ }
61
+ calses.forEach((cals) => {
62
+ var _a, _b, _c;
63
+ const id = cals.id || cals.appId || defaultGroup;
64
+ if (!usesMap[id]) {
65
+ usesMap[id] = new Set([]);
66
+ }
67
+ if (!((_a = cals === null || cals === void 0 ? void 0 : cals.extra) === null || _a === void 0 ? void 0 : _a.rootPath)) {
68
+ parseQuery(usesMap[id], (_b = cals.dataset) === null || _b === void 0 ? void 0 : _b.query);
69
+ }
70
+ (_c = cals.items) === null || _c === void 0 ? void 0 : _c.forEach((page) => {
71
+ var _a;
72
+ parseQuery(usesMap[id], (_a = page.dataset) === null || _a === void 0 ? void 0 : _a.query);
73
+ });
74
+ });
75
+ }
76
+ exports.getUsedSQLConnector = getUsedSQLConnector;
@@ -0,0 +1,3 @@
1
+ import { IPlatformApp } from '../../../types';
2
+ export declare function getUsedWorkflow(apps: IPlatformApp[], options?: any): Record<string, Set<string>>;
3
+ //# sourceMappingURL=getUsedWorkflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUsedWorkflow.d.ts","sourceRoot":"","sources":["../../../../../src/parser/cals/utils/getUsedWorkflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC,KAAA,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAwB3F"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUsedWorkflow = void 0;
4
+ const common_1 = require("./common");
5
+ function getUsedWorkflow(apps, options) {
6
+ const { defaultGroup = 'default' } = options || '';
7
+ const usedMap = {};
8
+ apps.forEach((app) => {
9
+ const key = app.id || app.appId || defaultGroup;
10
+ (0, common_1.walkThroughComponents)(app.items, (component) => {
11
+ const { listeners = [] } = component;
12
+ listeners.forEach((listener) => {
13
+ var _a, _b, _c, _d;
14
+ if (((_a = listener.handler) === null || _a === void 0 ? void 0 : _a.module) === 'platform' &&
15
+ ((_b = listener.handler) === null || _b === void 0 ? void 0 : _b.name) === 'callWorkflow' &&
16
+ ((_d = (_c = listener.handler) === null || _c === void 0 ? void 0 : _c.params) === null || _d === void 0 ? void 0 : _d.flowId)) {
17
+ if (!usedMap[key]) {
18
+ usedMap[key] = new Set();
19
+ }
20
+ usedMap[key].add(listener.handler.params.flowId);
21
+ }
22
+ });
23
+ });
24
+ });
25
+ return usedMap;
26
+ }
27
+ exports.getUsedWorkflow = getUsedWorkflow;
@@ -6,6 +6,9 @@ export { parseComponentCals, regenBlockTemplateCals, regenBlockTemplateComponent
6
6
  export { ActionType, type IDataBind, PropBindType } from './expression/index';
7
7
  export { processCommonStyle2CSSProperties, processCSSProperties2Rem, processCSSPropertiesUnit, } from './cals/utils/style';
8
8
  export { getUsedResources, getNavUsedStaticResource, _simpleGetUsedResourceOfComponent, } from './cals/utils/getUsedResources';
9
+ export { getUsedQueryPlugin, getUsedSQLConnector } from './cals/utils/getUsedQueryPlugin';
10
+ export { getUsedWorkflow } from './cals/utils/getUsedWorkflow';
11
+ export { getUsedDatasource } from './cals/utils/getUsedDatasource';
9
12
  export { getUsedReference } from './cals/utils/getUsedReference';
10
13
  export { default as PostcssRpx2Calc } from './plugins/postcss-rpx2clac';
11
14
  export { Dependencies } from './dependiencies';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/parser/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EACL,UAAU,EACV,UAAU,EACV,KAAK,SAAS,EACd,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,4BAA4B,EAC5B,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,GACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,KAAK,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EACL,gCAAgC,EAChC,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,iCAAiC,GAClC,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/parser/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EACL,UAAU,EACV,UAAU,EACV,KAAK,SAAS,EACd,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,4BAA4B,EAC5B,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,GACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,KAAK,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EACL,gCAAgC,EAChC,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,iCAAiC,GAClC,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.DYNAMIC_KEY_REG = exports.walkThroughComponents = exports.Dependencies = exports.PostcssRpx2Calc = exports.getUsedReference = exports._simpleGetUsedResourceOfComponent = exports.getNavUsedStaticResource = exports.getUsedResources = exports.processCSSPropertiesUnit = exports.processCSSProperties2Rem = exports.processCommonStyle2CSSProperties = exports.PropBindType = exports.ActionType = exports.mergeCals = exports.refreshComponentIds = exports.remapComponentIds = exports.VisitedMap = exports.renewIdInResource = exports.processPage2Template = exports.regenBlockTemplateComponents = exports.regenBlockTemplateCals = exports.parseComponentCals = exports.findAllConflicts = exports.autoResolveConflicts = exports.checkForConflicts = exports.codeToCals = exports.calsToCode = exports.processComponentModule = exports.upgrageToVersion2 = void 0;
20
+ exports.DYNAMIC_KEY_REG = exports.walkThroughComponents = exports.Dependencies = exports.PostcssRpx2Calc = exports.getUsedReference = exports.getUsedDatasource = exports.getUsedWorkflow = exports.getUsedSQLConnector = exports.getUsedQueryPlugin = exports._simpleGetUsedResourceOfComponent = exports.getNavUsedStaticResource = exports.getUsedResources = exports.processCSSPropertiesUnit = exports.processCSSProperties2Rem = exports.processCommonStyle2CSSProperties = exports.PropBindType = exports.ActionType = exports.mergeCals = exports.refreshComponentIds = exports.remapComponentIds = exports.VisitedMap = exports.renewIdInResource = exports.processPage2Template = exports.regenBlockTemplateComponents = exports.regenBlockTemplateCals = exports.parseComponentCals = exports.findAllConflicts = exports.autoResolveConflicts = exports.checkForConflicts = exports.codeToCals = exports.calsToCode = exports.processComponentModule = exports.upgrageToVersion2 = void 0;
21
21
  __exportStar(require("./cals/index"), exports);
22
22
  var version_1 = require("./cals/utils/version");
23
23
  Object.defineProperty(exports, "upgrageToVersion2", { enumerable: true, get: function () { return version_1.upgrageToVersion2; } });
@@ -50,6 +50,13 @@ var getUsedResources_1 = require("./cals/utils/getUsedResources");
50
50
  Object.defineProperty(exports, "getUsedResources", { enumerable: true, get: function () { return getUsedResources_1.getUsedResources; } });
51
51
  Object.defineProperty(exports, "getNavUsedStaticResource", { enumerable: true, get: function () { return getUsedResources_1.getNavUsedStaticResource; } });
52
52
  Object.defineProperty(exports, "_simpleGetUsedResourceOfComponent", { enumerable: true, get: function () { return getUsedResources_1._simpleGetUsedResourceOfComponent; } });
53
+ var getUsedQueryPlugin_1 = require("./cals/utils/getUsedQueryPlugin");
54
+ Object.defineProperty(exports, "getUsedQueryPlugin", { enumerable: true, get: function () { return getUsedQueryPlugin_1.getUsedQueryPlugin; } });
55
+ Object.defineProperty(exports, "getUsedSQLConnector", { enumerable: true, get: function () { return getUsedQueryPlugin_1.getUsedSQLConnector; } });
56
+ var getUsedWorkflow_1 = require("./cals/utils/getUsedWorkflow");
57
+ Object.defineProperty(exports, "getUsedWorkflow", { enumerable: true, get: function () { return getUsedWorkflow_1.getUsedWorkflow; } });
58
+ var getUsedDatasource_1 = require("./cals/utils/getUsedDatasource");
59
+ Object.defineProperty(exports, "getUsedDatasource", { enumerable: true, get: function () { return getUsedDatasource_1.getUsedDatasource; } });
53
60
  var getUsedReference_1 = require("./cals/utils/getUsedReference");
54
61
  Object.defineProperty(exports, "getUsedReference", { enumerable: true, get: function () { return getUsedReference_1.getUsedReference; } });
55
62
  var postcss_rpx2clac_1 = require("./plugins/postcss-rpx2clac");
@@ -0,0 +1,2 @@
1
+ export declare function getUsedDatasource(apps: any, options: any): Record<string, Set<string>>;
2
+ //# sourceMappingURL=getUsedDatasource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUsedDatasource.d.ts","sourceRoot":"","sources":["../../../../../src/parser/cals/utils/getUsedDatasource.ts"],"names":[],"mappings":"AAKA,wBAAgB,iBAAiB,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CA2J5E"}
@@ -0,0 +1,185 @@
1
+ import { EQueryType } from '../../../types';
2
+ import { DYNAMIC_KEY_REG, OFFICIAL_LIB_KEY } from '../../../utils';
3
+ import { ActionType } from '../../expression';
4
+ import { walkThroughComponents } from './common';
5
+ export function getUsedDatasource(apps, options) {
6
+ const { defaultGroup = 'default', datasources = [] } = options || '';
7
+ const usedMap = {};
8
+ const HANDLER_NAME = 'cloud.callDatasource';
9
+ apps.forEach((cals) => {
10
+ const key = cals.id || cals.appId || defaultGroup;
11
+ function processCode(code = '', set) {
12
+ code
13
+ // @ts-ignore
14
+ .replace(/\bapp(?:\.cloud)?\.dataSources\.([\da-zA-Z_]+)\b/g, (_$0, $1) => {
15
+ if ($1) {
16
+ set.add($1);
17
+ }
18
+ })
19
+ // 匹配 app.dataSources['methodName'] 形式
20
+ // 及 app.cloud.dataSources['methodName'] 形式
21
+ // @ts-ignore
22
+ .replace(/\bapp(?:\.cloud)?\.dataSources\[\s*(['"])([\da-zA-Z_]+)\1\s*\]/g, (_$0, _$1, $2) => {
23
+ if ($2) {
24
+ set.push($2);
25
+ }
26
+ })
27
+ // 匹配 app.cloud.utils.wrapperDatasourceMethod({dataSourceName: 'xxx', methodName: 'xxx'}) 的调用情况
28
+ .replace(/\bapp\.cloud\.utils\.wrapperDatasourceMethod\([\s\n]*\{(?:.|\n)*?(['"]?)dataSourceName\1\s*:\s*(['"])([\da-zA-Z_]+)\2/g,
29
+ // @ts-ignore
30
+ (_$0, _$1, _$2, $3) => {
31
+ if ($3) {
32
+ set.push($3);
33
+ }
34
+ })
35
+ // 匹配 app.cloud.callDataSource({dataSourceName: 'xxx'}) 的调用情况
36
+ .replace(/\bapp\.cloud\.(?:callDataSource|callModel|callConnector)\([\s\n]*\{(?:.|\n)*?(['"]?)(?:dataSourceName|name)\1\s*:\s*(['"])([\da-zA-Z_]+)\2/g,
37
+ // @ts-ignore
38
+ (_$0, _$1, _$2, $3) => {
39
+ if ($3) {
40
+ set.push($3);
41
+ }
42
+ });
43
+ }
44
+ function processListeners(listeners = [], set) {
45
+ listeners.forEach((listener) => {
46
+ var _a, _b, _c, _d;
47
+ if (listener.type === ActionType.GeneralFunc) {
48
+ processCode(listener.handler[':code'], set);
49
+ }
50
+ else if (((_a = listener.handler) === null || _a === void 0 ? void 0 : _a.module) === 'platform') {
51
+ switch ((_b = listener.handler) === null || _b === void 0 ? void 0 : _b.name) {
52
+ case HANDLER_NAME: {
53
+ if ((_d = (_c = listener.handler) === null || _c === void 0 ? void 0 : _c.params) === null || _d === void 0 ? void 0 : _d.dataSourceName) {
54
+ set.add(listener.handler.params.dataSourceName);
55
+ }
56
+ break;
57
+ }
58
+ }
59
+ }
60
+ });
61
+ }
62
+ try {
63
+ walkThroughComponents([cals], (component) => {
64
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
65
+ const { resources = [], listeners = [], dataset = {} } = component;
66
+ if (!usedMap[key]) {
67
+ usedMap[key] = new Set();
68
+ }
69
+ // listener eventflow
70
+ processListeners(listeners, usedMap[key]);
71
+ // resource
72
+ resources.forEach(({ code = '' }) => {
73
+ processCode(code, usedMap[key]);
74
+ });
75
+ Object.values((dataset === null || dataset === void 0 ? void 0 : dataset.state) || {}).forEach((meta) => {
76
+ if (meta.varType == 'datasource' && meta.dataSourceName) {
77
+ usedMap[key].add(meta.dataSourceName);
78
+ }
79
+ });
80
+ Object.values((dataset === null || dataset === void 0 ? void 0 : dataset.query) || {}).forEach((query) => {
81
+ var _a, _b, _c;
82
+ if ([EQueryType.Model, EQueryType.Apis].includes(query.type) &&
83
+ ((_b = (_a = query.handler) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.dataSourceName)) {
84
+ usedMap[key].add(query.handler.params.dataSourceName);
85
+ }
86
+ else if (query.type === EQueryType.GeneralFunc) {
87
+ processCode((_c = query.handler) === null || _c === void 0 ? void 0 : _c[':code'], usedMap[key]);
88
+ }
89
+ processListeners(query.listeners, usedMap[key]);
90
+ });
91
+ if (component.module === OFFICIAL_LIB_KEY) {
92
+ const data = component.attributes;
93
+ if (component.attributes.varPath) {
94
+ let dsName = component.attributes.varPath;
95
+ if (Array.isArray(component.attributes.varPath) && component.attributes.varPath.length === 2) {
96
+ [dsName] = component.attributes.varPath;
97
+ }
98
+ if (typeof dsName === 'string' && /^[a-z\d_]+$/.test(dsName)) {
99
+ usedMap[key].add(dsName);
100
+ }
101
+ }
102
+ // 其他绑定数据源的组件, 如 地图、图表等
103
+ if ((_a = data === null || data === void 0 ? void 0 : data.dataSource) === null || _a === void 0 ? void 0 : _a.name) {
104
+ const dsName = (_b = data === null || data === void 0 ? void 0 : data.dataSource) === null || _b === void 0 ? void 0 : _b.name;
105
+ if (typeof dsName === 'string' && /^[a-z\d_]+$/.test(dsName)) {
106
+ usedMap[key].add(dsName);
107
+ }
108
+ }
109
+ // 绑定连接器选择的连接器
110
+ if ((_d = (_c = data === null || data === void 0 ? void 0 : data.bindConnectMetadata) === null || _c === void 0 ? void 0 : _c.datasource) === null || _d === void 0 ? void 0 : _d.name) {
111
+ const dsName = (_e = data === null || data === void 0 ? void 0 : data.bindConnectMetadata) === null || _e === void 0 ? void 0 : _e.datasource.name;
112
+ if (component.component !== 'ModelTable' || (data === null || data === void 0 ? void 0 : data.dataSourceType) === 'custom-connector') {
113
+ usedMap[key].add(dsName);
114
+ }
115
+ }
116
+ // 业务模型组件数据源绑定
117
+ if ((_g = (_f = data === null || data === void 0 ? void 0 : data.bindMetadata) === null || _f === void 0 ? void 0 : _f.datasource) === null || _g === void 0 ? void 0 : _g.name) {
118
+ if (component.component !== 'ModelTable' || (data === null || data === void 0 ? void 0 : data.dataSourceType) !== 'custom-connector') {
119
+ usedMap[key].add(data.bindMetadata.datasource.name);
120
+ }
121
+ }
122
+ for (const key in data) {
123
+ if (DYNAMIC_KEY_REG.test(key)) {
124
+ const code = data[key];
125
+ processCode(code, usedMap[key]);
126
+ }
127
+ }
128
+ // 应当判断数据容器,compConfig 中包含 isDataContainer
129
+ // 此处为了方便,松散判断
130
+ if ((_h = data === null || data === void 0 ? void 0 : data.datasource) === null || _h === void 0 ? void 0 : _h.name) {
131
+ usedMap[key].add((_j = data === null || data === void 0 ? void 0 : data.datasource) === null || _j === void 0 ? void 0 : _j.name);
132
+ }
133
+ }
134
+ });
135
+ }
136
+ catch (e) {
137
+ console.error('walkRuntimeComponent error', e);
138
+ }
139
+ if (datasources === null || datasources === void 0 ? void 0 : datasources.length) {
140
+ for (const key in usedMap) {
141
+ const set = usedMap[key];
142
+ const list = Array.from(set);
143
+ usedMap[key] = new Set(list.concat(Array.from(getConnectedDataSourceNames(list, datasources))));
144
+ }
145
+ }
146
+ });
147
+ return usedMap;
148
+ }
149
+ /**
150
+ * 获取数据源关联的数据源名字
151
+ */
152
+ function getConnectedDataSourceNames(names, dataSources) {
153
+ const connectedDsNames = new Set();
154
+ names.forEach((name) => {
155
+ const ds = dataSources.find((ds) => ds.name === name);
156
+ if (!ds || ds.type !== 'database' || !ds.schema.properties)
157
+ return;
158
+ // @ts-ignore
159
+ if (Array.isArray(ds.childDataSourceNames)) {
160
+ // @ts-ignore
161
+ // connectedDsNames = connectedDsNames.concat(ds.childDataSourceNames);
162
+ }
163
+ const isSystem = name === 'sys_user' || name === 'sys_department';
164
+ const RELATE_FORMAT_MAP = {
165
+ 'many-one': true,
166
+ 'one-one': true,
167
+ 'one-one-r': true,
168
+ 'one-many': true,
169
+ 'many-many': true,
170
+ };
171
+ Object.keys(ds.schema.properties).forEach((key) => {
172
+ const meta = ds.schema.properties[key];
173
+ /**
174
+ * system 不处理关联关系
175
+ */
176
+ if (isSystem && RELATE_FORMAT_MAP[meta.format]) {
177
+ return;
178
+ }
179
+ if (!meta['x-parent'])
180
+ return;
181
+ connectedDsNames.add(ds.schema.properties[key]['x-parent'].parentDataSourceName);
182
+ });
183
+ });
184
+ return Array.from(connectedDsNames);
185
+ }
@@ -0,0 +1,4 @@
1
+ import { IPlatformApp } from '../../../types';
2
+ export declare function getUsedQueryPlugin(calses?: IPlatformApp[], options?: any): {};
3
+ export declare function getUsedSQLConnector(calses?: IPlatformApp[], options?: any): void;
4
+ //# sourceMappingURL=getUsedQueryPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUsedQueryPlugin.d.ts","sourceRoot":"","sources":["../../../../../src/parser/cals/utils/getUsedQueryPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,YAAY,EAAO,EAAE,OAAO,CAAC,KAAA,MAgCvE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,YAAY,EAAO,EAAE,OAAO,CAAC,KAAA,QAiCxE"}
@@ -0,0 +1,71 @@
1
+ export function getUsedQueryPlugin(calses = [], options) {
2
+ const { defaultGroup = 'default' } = options || '';
3
+ const usesMap = {};
4
+ function parseQuery(set, query = {}) {
5
+ Object.entries(query).forEach(([key, meta]) => {
6
+ var _a, _b, _c;
7
+ switch (meta.type) {
8
+ case 'model':
9
+ case 'apis': {
10
+ return;
11
+ }
12
+ default: {
13
+ const params = Array.isArray((_a = meta.handler) === null || _a === void 0 ? void 0 : _a.params) ? (_b = meta.handler) === null || _b === void 0 ? void 0 : _b.params[0] : (_c = meta.handler) === null || _c === void 0 ? void 0 : _c.params;
14
+ if (params === null || params === void 0 ? void 0 : params.sqlTemplateId) {
15
+ set.add(params === null || params === void 0 ? void 0 : params.sqlTemplateId);
16
+ }
17
+ }
18
+ }
19
+ });
20
+ }
21
+ calses.forEach((cals) => {
22
+ var _a, _b, _c;
23
+ const id = cals.id || cals.appId || defaultGroup;
24
+ if (!usesMap[id]) {
25
+ usesMap[id] = new Set([]);
26
+ }
27
+ if (!((_a = cals === null || cals === void 0 ? void 0 : cals.extra) === null || _a === void 0 ? void 0 : _a.rootPath)) {
28
+ parseQuery(usesMap[id], (_b = cals.dataset) === null || _b === void 0 ? void 0 : _b.query);
29
+ }
30
+ (_c = cals.items) === null || _c === void 0 ? void 0 : _c.forEach((page) => {
31
+ var _a;
32
+ parseQuery(usesMap[id], (_a = page.dataset) === null || _a === void 0 ? void 0 : _a.query);
33
+ });
34
+ });
35
+ return usesMap;
36
+ }
37
+ export function getUsedSQLConnector(calses = [], options) {
38
+ const { defaultGroup = 'default' } = options || '';
39
+ const usesMap = {};
40
+ function parseQuery(set, query = {}) {
41
+ Object.entries(query).forEach(([key, meta]) => {
42
+ var _a, _b, _c;
43
+ switch (meta.type) {
44
+ case 'model':
45
+ case 'apis': {
46
+ return;
47
+ }
48
+ default: {
49
+ const params = Array.isArray((_a = meta.handler) === null || _a === void 0 ? void 0 : _a.params) ? (_b = meta.handler) === null || _b === void 0 ? void 0 : _b.params[0] : (_c = meta.handler) === null || _c === void 0 ? void 0 : _c.params;
50
+ if (params === null || params === void 0 ? void 0 : params.datasourceName) {
51
+ set.add(params === null || params === void 0 ? void 0 : params.datasourceName);
52
+ }
53
+ }
54
+ }
55
+ });
56
+ }
57
+ calses.forEach((cals) => {
58
+ var _a, _b, _c;
59
+ const id = cals.id || cals.appId || defaultGroup;
60
+ if (!usesMap[id]) {
61
+ usesMap[id] = new Set([]);
62
+ }
63
+ if (!((_a = cals === null || cals === void 0 ? void 0 : cals.extra) === null || _a === void 0 ? void 0 : _a.rootPath)) {
64
+ parseQuery(usesMap[id], (_b = cals.dataset) === null || _b === void 0 ? void 0 : _b.query);
65
+ }
66
+ (_c = cals.items) === null || _c === void 0 ? void 0 : _c.forEach((page) => {
67
+ var _a;
68
+ parseQuery(usesMap[id], (_a = page.dataset) === null || _a === void 0 ? void 0 : _a.query);
69
+ });
70
+ });
71
+ }
@@ -0,0 +1,3 @@
1
+ import { IPlatformApp } from '../../../types';
2
+ export declare function getUsedWorkflow(apps: IPlatformApp[], options?: any): Record<string, Set<string>>;
3
+ //# sourceMappingURL=getUsedWorkflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUsedWorkflow.d.ts","sourceRoot":"","sources":["../../../../../src/parser/cals/utils/getUsedWorkflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC,KAAA,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAwB3F"}