@steedos/service-package-loader 2.5.19 → 2.5.20-beta.2

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/index.js CHANGED
@@ -56,7 +56,7 @@ module.exports = {
56
56
  /**
57
57
  * Dependencies
58
58
  */
59
- dependencies: ['metadata-server', '@steedos/service-project', '@steedos/service-packages'],
59
+ dependencies: ['metadata-server', '@steedos/service-project', '@steedos/service-packages', 'objectql', '@steedos/data-import'],
60
60
 
61
61
  /**
62
62
  * Actions
@@ -76,10 +76,10 @@ module.exports = {
76
76
  },
77
77
  "space.initialized": {
78
78
  async handler(ctx) {
79
- await this.loadDataOnServiceStarted();
80
79
  const spaceDoc = ctx.params
81
80
  // 扫描main/default/data文件夹
82
- await this.importData(path.join(this.settings.packageInfo.path, 'main', 'default', 'data'), true, spaceDoc._id);
81
+ await this.importData(path.join(this.settings.packageInfo.path, 'main', 'default', 'data'), false, spaceDoc._id);
82
+ await this.loadDataOnServiceStarted();
83
83
  }
84
84
  }
85
85
  },
@@ -237,6 +237,12 @@ module.exports = {
237
237
  },
238
238
  async onStarted(){
239
239
 
240
+ // 扫描main/default/data文件夹,在加载.flow.json前执行
241
+ const primarySpaceId = await this.broker.call("objectql.getPrimarySpaceId");
242
+ if (primarySpaceId) {
243
+ await this.importData(path.join(this.settings.packageInfo.path, 'main', 'default', 'data'), true, primarySpaceId);
244
+ }
245
+
240
246
  this.checkPackageMetadataFiles(this.settings.packageInfo.path)
241
247
 
242
248
  if(this.beforeStart){
@@ -4,7 +4,6 @@ exports.handler = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const ImportJson_1 = require("../imports/ImportJson");
6
6
  const ImportCsv_1 = require("../imports/ImportCsv");
7
- const ImportFlow_1 = require("../imports/ImportFlow");
8
7
  const fs = require("fs");
9
8
  function handler(filePath, onlyInsert, spaceId) {
10
9
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -17,19 +16,16 @@ function handler(filePath, onlyInsert, spaceId) {
17
16
  const importer = {
18
17
  csv: new ImportCsv_1.default(),
19
18
  json: new ImportJson_1.default(),
20
- flow: new ImportFlow_1.default()
21
19
  };
22
20
  const csvData = yield importer.csv.readFile(filePath);
23
21
  const jsonData = yield importer.json.readFile(filePath);
24
- const flowData = yield importer.flow.readFile(filePath);
25
- yield this.broker.call("~packages-@steedos/data-import.importData", {
22
+ yield this.broker.call("@steedos/data-import.importData", {
26
23
  data: {
27
24
  "csv": csvData,
28
25
  "json": jsonData,
29
- "flow": flowData,
30
26
  },
31
27
  spaceId,
32
- onlyInsert: true,
28
+ onlyInsert,
33
29
  });
34
30
  });
35
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"importData.js","sourceRoot":"","sources":["../../src/methods/importData.ts"],"names":[],"mappings":";;;;AAQA,sDAA+C;AAC/C,oDAA4C;AAC5C,sDAA8C;AAE9C,yBAA0B;AAE1B,SAAsB,OAAO,CAAC,QAAgB,EAAE,UAAmB,EAAE,OAAe;;QAChF,IAAI,CAAC,QAAQ,EAAE;YACX,OAAM;SACT;QACD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC1B,OAAM;SACT;QAED,MAAM,QAAQ,GAAG;YACb,GAAG,EAAE,IAAI,mBAAS,EAAE;YACpB,IAAI,EAAE,IAAI,oBAAU,EAAE;YACtB,IAAI,EAAE,IAAI,oBAAU,EAAE;SACzB,CAAA;QAED,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAEtD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAExD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAExD,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2CAA2C,EAAE;YAChE,IAAI,EAAE;gBACF,KAAK,EAAE,OAAO;gBACd,MAAM,EAAE,QAAQ;gBAChB,MAAM,EAAE,QAAQ;aACnB;YACD,OAAO;YACP,UAAU,EAAE,IAAI;SACnB,CAAC,CAAA;IAEN,CAAC;CAAA;AA9BD,0BA8BC"}
1
+ {"version":3,"file":"importData.js","sourceRoot":"","sources":["../../src/methods/importData.ts"],"names":[],"mappings":";;;;AAQA,sDAA+C;AAC/C,oDAA4C;AAE5C,yBAA0B;AAE1B,SAAsB,OAAO,CAAC,QAAgB,EAAE,UAAmB,EAAE,OAAe;;QAChF,IAAI,CAAC,QAAQ,EAAE;YACX,OAAM;SACT;QACD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC1B,OAAM;SACT;QAED,MAAM,QAAQ,GAAG;YACb,GAAG,EAAE,IAAI,mBAAS,EAAE;YACpB,IAAI,EAAE,IAAI,oBAAU,EAAE;SACzB,CAAA;QAED,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAEtD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAGxD,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iCAAiC,EAAE;YACtD,IAAI,EAAE;gBACF,KAAK,EAAE,OAAO;gBACd,MAAM,EAAE,QAAQ;aACnB;YACD,OAAO;YACP,UAAU;SACb,CAAC,CAAA;IAEN,CAAC;CAAA;AA3BD,0BA2BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-package-loader",
3
- "version": "2.5.19",
3
+ "version": "2.5.20-beta.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,10 +10,10 @@
10
10
  "author": "",
11
11
  "license": "MIT",
12
12
  "dependencies": {
13
- "@steedos/metadata-core": "2.5.19",
14
- "@steedos/metadata-registrar": "2.5.19",
15
- "@steedos/router": "2.5.19",
16
- "@steedos/service-object-mixin": "2.5.19",
13
+ "@steedos/metadata-core": "2.5.20-beta.2",
14
+ "@steedos/metadata-registrar": "2.5.20-beta.2",
15
+ "@steedos/router": "2.5.20-beta.2",
16
+ "@steedos/service-object-mixin": "2.5.20-beta.2",
17
17
  "clone": "^2.1.2",
18
18
  "csvtojson": "~2.0.10",
19
19
  "moleculer": "^0.14.25",
@@ -27,5 +27,5 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "f45f110239267697485b421285e61ca020e4779b"
30
+ "gitHead": "b9fc3773ae163df5d0062113bf6b21635c898b13"
31
31
  }
@@ -1,4 +0,0 @@
1
- import { Base } from './Base';
2
- export default class ImportFlow implements Base {
3
- readFile(filePath: string): any;
4
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const metadata_core_1 = require("@steedos/metadata-core");
4
- const path = require("path");
5
- const _ = require("lodash");
6
- class ImportFlow {
7
- readFile(filePath) {
8
- const filePatten = [
9
- path.join(filePath, "**", "*.flow.data.json"),
10
- "!" + path.join(filePath, "node_modules"),
11
- ];
12
- const matchedPaths = (0, metadata_core_1.syncMatchFiles)(filePatten);
13
- let flows = {};
14
- for (let k = 0; k < matchedPaths.length; k++) {
15
- let matchedPath = matchedPaths[k];
16
- let json = (0, metadata_core_1.loadFile)(matchedPath);
17
- let formName = matchedPath.substring(matchedPath.lastIndexOf('/') + 1, matchedPath.indexOf('.flow'));
18
- let form = {};
19
- try {
20
- if (json) {
21
- let flowKeys = _.keys(json);
22
- for (let m in flowKeys) {
23
- let key = flowKeys[m];
24
- if (typeof key === 'function') {
25
- continue;
26
- }
27
- let val = json[key];
28
- if (typeof val === 'function') {
29
- json[key] = val.toString();
30
- }
31
- form[key] = json[key];
32
- }
33
- flows[formName] = json;
34
- }
35
- }
36
- catch (error) {
37
- console.error('loadFlows error', matchedPath, error);
38
- throw error;
39
- }
40
- }
41
- return flows;
42
- }
43
- }
44
- exports.default = ImportFlow;
45
- //# sourceMappingURL=ImportFlow.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ImportFlow.js","sourceRoot":"","sources":["../../src/imports/ImportFlow.ts"],"names":[],"mappings":";;AAQA,0DAAkE;AAElE,6BAA8B;AAC9B,4BAA6B;AAE7B,MAAqB,UAAU;IAE3B,QAAQ,CAAC,QAAgB;QACrB,MAAM,UAAU,GAAG;YACf,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,kBAAkB,CAAC;YAC7C,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC;SAC5C,CAAA;QACD,MAAM,YAAY,GAAa,IAAA,8BAAc,EAAC,UAAU,CAAC,CAAC;QAC1D,IAAI,KAAK,GAAG,EAAE,CAAC;QACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC1C,IAAI,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;YAClC,IAAI,IAAI,GAAG,IAAA,wBAAQ,EAAC,WAAW,CAAC,CAAC;YACjC,IAAI,QAAQ,GAAG,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;YACrG,IAAI,IAAI,GAAG,EAAE,CAAC;YACd,IAAI;gBACA,IAAI,IAAI,EAAE;oBAEN,IAAI,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC5B,KAAK,IAAI,CAAC,IAAI,QAAQ,EAAE;wBACpB,IAAI,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;wBACtB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;4BAC3B,SAAS;yBACZ;wBACD,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;wBACpB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;4BAC3B,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;yBAC9B;wBACD,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;qBACzB;oBACD,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;iBAC1B;aACJ;YAAC,OAAO,KAAK,EAAE;gBACZ,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;gBACrD,MAAM,KAAK,CAAA;aACd;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CAEJ;AAvCD,6BAuCC"}
package/src/consts.ts DELETED
@@ -1,17 +0,0 @@
1
- /*
2
- * @Author: 孙浩林 sunhaolin@steedos.com
3
- * @Date: 2023-07-10 13:54:16
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-07-10 13:59:34
6
- * @Description:
7
- */
8
-
9
- // 加载元数据文件时给的默认权限
10
- export const METADATA_SYSTEM_PERMISSION = {
11
- is_system: true,
12
- record_permissions: {
13
- allowEdit: false,
14
- allowDelete: false,
15
- allowRead: true,
16
- }
17
- }
@@ -1,36 +0,0 @@
1
- /*
2
- * @Author: 孙浩林 sunhaolin@steedos.com
3
- * @Date: 2023-07-10 13:49:21
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-07-10 14:05:05
6
- * @FilePath: /project-template/Users/sunhaolin/Documents/GitHub/steedos-platform-2.3/services/service-package-loader/src/importLoader/index.ts
7
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8
- */
9
-
10
- import { LoadImportFile } from '@steedos/metadata-core'
11
- import { registerImport } from '@steedos/metadata-registrar'
12
- import path = require('path');
13
- import _ = require('lodash');
14
- import { Import } from './types';
15
- import { METADATA_SYSTEM_PERMISSION } from '../consts';
16
-
17
- const loadImportFile = new LoadImportFile();
18
-
19
- export async function load(broker: any, packagePath: string, packageServiceName: string) {
20
- let filePath = path.join(packagePath, "**");
21
- const metadatasJSON = loadImportFile.load(filePath);
22
- if (_.isEmpty(metadatasJSON)) {
23
- return;
24
- }
25
-
26
- // 注册到元数据中心
27
- const data = [];
28
- for (const apiName in metadatasJSON) {
29
- const doc: Import = metadatasJSON[apiName];
30
- data.push(Object.assign(doc, METADATA_SYSTEM_PERMISSION));
31
- }
32
- if (data.length > 0) {
33
- await registerImport.mregister(broker, packageServiceName, data)
34
- }
35
-
36
- }
@@ -1,26 +0,0 @@
1
- /*
2
- * @Author: 孙浩林 sunhaolin@steedos.com
3
- * @Date: 2023-07-10 13:50:03
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-07-10 15:06:59
6
- * @Description:
7
- */
8
-
9
- type FieldMapping = {
10
- header: string, // 表头
11
- api_name?: string, // 导入对象的字段
12
- matched_by?: string, // 关联对象的key
13
- save_key_while_fail?: boolean // 关联失败时保存key
14
- }
15
-
16
- export type Import = {
17
- name: string, // API Name
18
- description?: string, // 导入描述
19
- object_name: string, // 导入对象
20
- encoding?: string, // 字符代码 UTF8
21
- value_separator?: string, // 值分隔符 ','
22
- operation: 'insert' | 'update' | 'upsert', // 导入操作
23
- field_mappings: [FieldMapping], // 映射关系
24
- external_id_name?: string, // 表示数据唯一性字段(重复执行导入时根据此字段更新记录)
25
- }
26
-
@@ -1 +0,0 @@
1
- export * from './import';
@@ -1,11 +0,0 @@
1
- /*
2
- * @Author: 孙浩林 sunhaolin@steedos.com
3
- * @Date: 2023-10-26 10:31:50
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-10-26 10:41:08
6
- * @FilePath: /steedos-platform-2.3/services/service-package-loader/src/imports/Base.ts
7
- * @Description:
8
- */
9
- export interface Base {
10
- readFile(filePath: string, options?: any): any
11
- }
@@ -1,30 +0,0 @@
1
- /*
2
- * @Author: 孙浩林 sunhaolin@steedos.com
3
- * @Date: 2023-10-26 10:31:50
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-10-26 10:51:00
6
- * @FilePath: /steedos-platform-2.3/services/service-package-loader/src/imports/ImportCsv.ts
7
- * @Description:
8
- */
9
- import ImportJson from './ImportJson';
10
- import csv = require('csvtojson');
11
- import path = require('path');
12
- import { syncMatchFiles } from '@steedos/metadata-core';
13
-
14
- export default class ImportCsv extends ImportJson {
15
-
16
- async readFile(filePath: string): Promise<Array<{ objectName: string, records: Array<any> }>> {
17
- let results: any = []
18
- const filePatten = [
19
- path.join(filePath, "**", "*.data.csv"),
20
- "!" + path.join(filePath, "node_modules"),
21
- ]
22
- const matchedPaths: [string] = syncMatchFiles(filePatten);
23
- for (const matchedPath of matchedPaths) {
24
- let records = await csv().fromFile(matchedPath);
25
- let objectName = path.basename(matchedPath).split('.')[0];
26
- results.push({ objectName: objectName, records: records });
27
- }
28
- return results
29
- }
30
- }
@@ -1,28 +0,0 @@
1
- /*
2
- * @Author: 孙浩林 sunhaolin@steedos.com
3
- * @Date: 2023-10-26 10:31:50
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-10-26 10:44:27
6
- * @FilePath: /steedos-platform-2.3/services/service-package-loader/src/imports/ImportExcel.ts
7
- * @Description:
8
- */
9
- import xlsx from 'node-xlsx';
10
- import { Base } from './Base';
11
-
12
- export default class ImportExcel implements Base {
13
-
14
- readFile(filePath: string, options: any = {}): { datas: Array<any>, headers: Array<string> } {
15
- const { sheetIndex = 0, headerIndex = 0 } = options;
16
- let workbook = xlsx.parse(filePath, {
17
- cellDates: true,
18
- });
19
- const data = workbook[sheetIndex].data;
20
- const headers = data[headerIndex];
21
- const datas = data.slice(1);
22
- return {
23
- headers,
24
- datas
25
- };
26
- }
27
-
28
- }
@@ -1,53 +0,0 @@
1
- /*
2
- * @Author: 孙浩林 sunhaolin@steedos.com
3
- * @Date: 2023-10-26 10:31:50
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-10-26 10:46:25
6
- * @FilePath: /steedos-platform-2.3/services/service-package-loader/src/imports/ImportFlow.ts
7
- * @Description:
8
- */
9
- import { loadFile, syncMatchFiles } from '@steedos/metadata-core';
10
- import { Base } from './Base';
11
- import path = require('path');
12
- import _ = require('lodash');
13
-
14
- export default class ImportFlow implements Base {
15
-
16
- readFile(filePath: string): any {
17
- const filePatten = [
18
- path.join(filePath, "**", "*.flow.data.json"),
19
- "!" + path.join(filePath, "node_modules"),
20
- ]
21
- const matchedPaths: [string] = syncMatchFiles(filePatten);
22
- let flows = {};
23
- for (let k = 0; k < matchedPaths.length; k++) {
24
- let matchedPath = matchedPaths[k];
25
- let json = loadFile(matchedPath);
26
- let formName = matchedPath.substring(matchedPath.lastIndexOf('/') + 1, matchedPath.indexOf('.flow'));
27
- let form = {};
28
- try {
29
- if (json) {
30
-
31
- let flowKeys = _.keys(json);
32
- for (let m in flowKeys) {
33
- let key = flowKeys[m];
34
- if (typeof key === 'function') {
35
- continue;
36
- }
37
- let val = json[key];
38
- if (typeof val === 'function') {
39
- json[key] = val.toString();
40
- }
41
- form[key] = json[key];
42
- }
43
- flows[formName] = json;
44
- }
45
- } catch (error) {
46
- console.error('loadFlows error', matchedPath, error);
47
- throw error
48
- }
49
- }
50
- return flows;
51
- }
52
-
53
- }
@@ -1,33 +0,0 @@
1
- /*
2
- * @Author: 孙浩林 sunhaolin@steedos.com
3
- * @Date: 2023-10-26 10:31:50
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-10-26 10:48:39
6
- * @FilePath: /steedos-platform-2.3/services/service-package-loader/src/imports/ImportJson.ts
7
- * @Description:
8
- */
9
- import { each } from 'lodash';
10
- import { Base } from './Base';
11
- import { syncMatchFiles } from '@steedos/metadata-core';
12
- import path = require('path');
13
- import fs = require("fs");
14
-
15
- export default class ImportJson implements Base {
16
-
17
- async readFile(filePath: string): Promise<Array<{ objectName: string, records: Array<any> }>> {
18
- let results: any = []
19
- const filePatten = [
20
- path.join(filePath, "**", "*.data.json"),
21
- "!" + path.join(filePath, "**", "*.flow.data.json"),
22
- "!" + path.join(filePath, "node_modules")];
23
-
24
- const matchedPaths: [string] = syncMatchFiles(filePatten);
25
- each(matchedPaths, (matchedPath: string) => {
26
- let records = JSON.parse(fs.readFileSync(matchedPath, 'utf8').normalize('NFC'));
27
- let objectName = path.basename(matchedPath).split('.')[0];
28
- results.push({ objectName: objectName, records: records });
29
- })
30
- return results
31
- }
32
-
33
- }
package/src/index.ts DELETED
@@ -1,12 +0,0 @@
1
- /*
2
- * @Author: sunhaolin@hotoa.com
3
- * @Date: 2022-05-14 10:16:03
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-07-10 14:02:11
6
- * @Description:
7
- */
8
- export * as triggerLoader from "./triggerLoader"
9
- export * as processLoader from "./processLoader"
10
- export * as processTriggerLoader from "./processTriggerLoader"
11
- export * as triggerYmlLoader from './loader/triggerYmlLoader';
12
- export * as importLoader from './importLoader'
@@ -1,57 +0,0 @@
1
- /*
2
- * @Author: baozhoutao@steedos.com
3
- * @Date: 2023-04-25 16:52:28
4
- * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2023-05-18 09:27:20
6
- * @Description:
7
- */
8
-
9
- import { LoadTriggerFile } from '@steedos/metadata-core'
10
- import path = require('path');
11
- import _ = require('lodash');
12
-
13
- const loadTriggerFile = new LoadTriggerFile();
14
- function isPatternTrigger(data){
15
- const {listenTo} = data;
16
- if(listenTo === '*'){
17
- return true;
18
- }else if(_.isArray(listenTo)){
19
- return true;
20
- }else if(_.isRegExp(listenTo)){
21
- return true;
22
- }else if(_.isString(listenTo) && listenTo.startsWith("/")){
23
- try {
24
- if(_.isRegExp(eval(listenTo))){
25
- return true;
26
- }
27
- } catch (error) {
28
- return false
29
- }
30
- return false;
31
- }
32
- return false;
33
- }
34
- export async function load(broker: any, packagePath: string, packageServiceName: string) {
35
- let filePath = path.join(packagePath, "**");
36
- let triggers: any = loadTriggerFile.load(filePath);
37
- if (_.isEmpty(triggers)) {
38
- return;
39
- }
40
- for (const apiName in triggers) {
41
- const trigger = triggers[apiName];
42
- if(isPatternTrigger(trigger)){
43
- trigger.isPattern = true
44
- }
45
- await broker.call(`object_triggers.add`, { apiName: `${trigger.listenTo}.${trigger.name}`, data: trigger }, {
46
- meta: {
47
- metadataServiceName: packageServiceName,
48
- caller: {
49
- nodeID: broker.nodeID,
50
- service: {
51
- name: packageServiceName,
52
- }
53
- }
54
- }});
55
- broker.broadcast('metadata.object_triggers.change', {apiName: `${trigger.listenTo}.${trigger.name}`, listenTo: trigger.listenTo})
56
- }
57
- }
@@ -1,45 +0,0 @@
1
- /*
2
- * @Author: 孙浩林 sunhaolin@steedos.com
3
- * @Date: 2023-10-26 10:22:14
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-10-27 12:12:57
6
- * @FilePath: /steedos-platform-2.3/services/service-package-loader/src/methods/importData.ts
7
- * @Description:
8
- */
9
- import ImportJson from '../imports/ImportJson';
10
- import ImportCsv from '../imports/ImportCsv'
11
- import ImportFlow from '../imports/ImportFlow'
12
-
13
- import fs = require('fs');
14
-
15
- export async function handler(filePath: string, onlyInsert: boolean, spaceId: string) {
16
- if (!filePath) {
17
- return
18
- }
19
- if (!fs.existsSync(filePath)) {
20
- return
21
- }
22
-
23
- const importer = {
24
- csv: new ImportCsv(),
25
- json: new ImportJson(),
26
- flow: new ImportFlow()
27
- }
28
-
29
- const csvData = await importer.csv.readFile(filePath);
30
-
31
- const jsonData = await importer.json.readFile(filePath);
32
-
33
- const flowData = await importer.flow.readFile(filePath);
34
-
35
- await this.broker.call("~packages-@steedos/data-import.importData", {
36
- data: {
37
- "csv": csvData,
38
- "json": jsonData,
39
- "flow": flowData,
40
- },
41
- spaceId,
42
- onlyInsert: true,
43
- })
44
-
45
- }
@@ -1,9 +0,0 @@
1
- /*
2
- * @Author: 孙浩林 sunhaolin@steedos.com
3
- * @Date: 2023-10-26 10:21:50
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-10-26 10:40:43
6
- * @FilePath: /steedos-platform-2.3/services/service-package-loader/src/methods/index.ts
7
- * @Description:
8
- */
9
- export * as importData from './importData';
@@ -1,115 +0,0 @@
1
- /*
2
- * @Author: sunhaolin@hotoa.com
3
- * @Date: 2022-03-30 11:49:53
4
- * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2023-05-30 09:33:01
6
- * @Description:
7
- */
8
- import * as _ from "underscore";
9
- import * as path from "path";
10
- import { Process } from "./types";
11
- import { LoadProcessFile } from '@steedos/metadata-core';
12
- import { registerProcess } from '@steedos/metadata-registrar';
13
- const loadProcessFile = new LoadProcessFile();
14
-
15
- function getObject(objectName: string) {
16
- try {
17
- const objectql = require('@steedos/objectql');
18
- return objectql.getObject(objectName);
19
- } catch (error) {
20
- return null
21
- }
22
- }
23
-
24
- export async function load(broker: any, packagePath: string, packageServiceName: string) {
25
- let filePath = path.join(packagePath, "**");
26
- let processes = loadProcessFile.load(filePath);
27
- if (_.isEmpty(processes)) {
28
- return;
29
- }
30
-
31
- const data = [];
32
- for (const apiName in processes) {
33
- const process: Process = processes[apiName];
34
- data.push(Object.assign(process, {
35
- is_system: true,
36
- record_permissions: {
37
- allowEdit: false,
38
- allowDelete: false,
39
- allowRead: true,
40
- }
41
- }));
42
-
43
- }
44
- if (data.length > 0) {
45
- await registerProcess.mregister(broker, packageServiceName, data)
46
- }
47
-
48
- }
49
-
50
- // 软件包中的process元数据直接加载到库中
51
- export async function sendPackageProcessToDb(packagePath: string) {
52
- let filePath = path.join(packagePath, "**");
53
- let processes = loadProcessFile.load(filePath);
54
-
55
- if (_.isEmpty(processes)) {
56
- return;
57
- }
58
-
59
- const processObj = getObject('process');
60
- const processVersionsObj = getObject('process_versions');
61
- const spaceObj = getObject('spaces');
62
- if(!processObj || !processVersionsObj || !spaceObj){
63
- return ;
64
- }
65
- const spaceDoc = (await spaceObj.find({}))[0];
66
- // 如果没有工作区信息则说明为空库,不加载
67
- if (!spaceDoc) {
68
- return;
69
- }
70
- const now = new Date();
71
- const ownerId = spaceDoc.owner;
72
- const baseInfo = {
73
- space: spaceDoc._id,
74
- owner: ownerId,
75
- created: now,
76
- modified: now,
77
- created_by: ownerId,
78
- modified_by: ownerId,
79
- }
80
- for (const apiName in processes) {
81
- const processCount = await processObj.count({ filters: [['name', '=', apiName]] });
82
- if (processCount > 0) {
83
- console.log(`process ${apiName} already exists`);
84
- continue;
85
- }
86
- const process: Process = processes[apiName];
87
- const processId = await processObj._makeNewID();
88
- let processDoc = {
89
- _id: processId,
90
- name: process.name,
91
- label: process.label,
92
- object_name: process.object_name,
93
- engine: process.engine,
94
- is_active: false,
95
- description: process.description || '',
96
- entry_criteria: process.entry_criteria || '',
97
- when: process.when || '',
98
- ext: process.ext || '',
99
- ...baseInfo
100
- };
101
- let processVersionDoc = {
102
- process: processId,
103
- is_active: false,
104
- description: process.description || '',
105
- entry_criteria: process.entry_criteria || '',
106
- when: process.when || '',
107
- schema: process.schema || '',
108
- version: 1,
109
- ...baseInfo
110
- };
111
- await processObj.directInsert(processDoc);
112
- await processVersionsObj.directInsert(processVersionDoc);
113
- }
114
-
115
- }
@@ -1 +0,0 @@
1
- export * from './process';
@@ -1,19 +0,0 @@
1
- /*
2
- * @Author: sunhaolin@hotoa.com
3
- * @Date: 2022-03-30 11:49:53
4
- * @LastEditors: sunhaolin@hotoa.com
5
- * @LastEditTime: 2022-03-30 21:24:32
6
- * @Description: Process 元数据格式
7
- */
8
- export type Process = {
9
- name: string,
10
- label: string,
11
- object_name: string,
12
- engine: string,
13
- is_active?: boolean,
14
- description?: string,
15
- entry_criteria: string,
16
- when: 'afterInsert' | 'afterUpdate',
17
- schema?: string,
18
- ext: string
19
- }
@@ -1,45 +0,0 @@
1
- /*
2
- * @Author: baozhoutao@steedos.com
3
- * @Date: 2022-05-16 11:55:06
4
- * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2023-05-30 09:47:15
6
- * @Description:
7
- */
8
- import * as _ from "underscore";
9
- import * as path from "path";
10
- import { getMD5, JSONStringify } from '@steedos/metadata-core';
11
- import { Trigger } from "./types";
12
- import { registerProcessTrigger, loadProcessTriggers } from "@steedos/metadata-registrar";
13
-
14
- const ENUM_WHEN = ['beforeDraftInsert', 'afterDraftInsert', 'beforeDraftSubmit', 'afterDraftSubmit', 'beforeStepSubmit', 'afterStepSubmit', 'cacluateNextStepUsers',
15
- 'beforeCancel', 'afterCancel', 'beforeTerminate', 'afterTerminate', 'beforeEnd', 'afterEnd'];
16
- const LISTENTO_ALL_FLOWS = 'LISTENTO_ALL_FLOWS';
17
-
18
- export async function load(broker: any, packagePath: string, packageServiceName: string) {
19
- let filePath = path.join(packagePath, "**");
20
- let wTriggers = loadProcessTriggers(filePath);
21
- if (_.isEmpty(wTriggers)) {
22
- return;
23
- }
24
- for (const wt of wTriggers) {
25
-
26
- if (_.isString(wt.listenTo)) {
27
- for (const when of ENUM_WHEN) {
28
- let handler = wt[when];
29
- if (!handler) {
30
- continue;
31
- }
32
- let name = wt.name || getMD5(JSONStringify(wt));
33
- let config: Trigger = {
34
- name: name,
35
- "listenTo": wt.listenTo == '*' ? LISTENTO_ALL_FLOWS : wt.listenTo,
36
- "when": when,
37
- "handler": handler.toString()
38
- }
39
- await registerProcessTrigger.register(broker, packageServiceName, config);
40
- }
41
-
42
- }
43
- }
44
-
45
- }
@@ -1 +0,0 @@
1
- export * from './trigger';
@@ -1,6 +0,0 @@
1
- export type Trigger = {
2
- name: string,
3
- listenTo: string,
4
- when: string | string[],
5
- handler: Function
6
- }
@@ -1,153 +0,0 @@
1
- /*
2
- * @Author: sunhaolin@hotoa.com
3
- * @Date: 2022-06-12 19:08:48
4
- * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2023-05-30 09:52:23
6
- * @Description: 加载*.trigger.js文件注册为新版action trigger
7
- */
8
- import * as _ from "underscore";
9
- import * as path from "path";
10
- import { JSONStringify, getMD5 } from "@steedos/metadata-core";
11
- import { loadObjectTriggers } from "@steedos/metadata-registrar";
12
-
13
-
14
-
15
- const TRIGGERKEYS = ['beforeFind', 'beforeInsert', 'beforeUpdate', 'beforeDelete', 'afterFind', 'afterInsert', 'afterUpdate', 'afterDelete', 'afterFindOne', 'afterCount']
16
-
17
- function getObject(objectName: string) {
18
- try {
19
- const objectql = require('@steedos/objectql');
20
- return objectql.getObject(objectName);
21
- } catch (error) {
22
- return null
23
- }
24
- }
25
-
26
- export async function load(broker: any, packagePath: string, packageServiceName: string) {
27
- let actions = {};
28
- let serviceName = `~triggers-${packageServiceName}`;
29
- let filePath = path.join(packagePath, "**");
30
- let objTriggers = loadObjectTriggers(filePath, packageServiceName);
31
- if (_.isEmpty(objTriggers)) {
32
- return;
33
- }
34
- /** objTriggers格式
35
- [
36
- {
37
- beforeInsert: [AsyncFunction: beforeInsert],
38
- beforeUpdate: [AsyncFunction: beforeUpdate],
39
- beforeDelete: [AsyncFunction: beforeDelete],
40
- afterInsert: [AsyncFunction: afterInsert],
41
- afterUpdate: [AsyncFunction: afterUpdate],
42
- afterDelete: [AsyncFunction: afterDelete],
43
- metadataServiceName: '~packages-my-steedos-package',
44
- listenTo: 'company'
45
- }
46
- ]
47
- */
48
- for (const trigger of objTriggers) {
49
- // 转换为action trigger
50
- /** action trigger 格式
51
- spaceUsersBeforeUpdate: {
52
- trigger: {
53
- listenTo: 'space_users',
54
- when: ['beforeInsert', 'beforeUpdate']
55
- },
56
- async handler(ctx) {
57
- this.broker.logger.debug('spaceUsersBeforeUpdate', ctx)
58
- }
59
- }
60
- */
61
- const actionTriggerName = getMD5(JSONStringify(trigger));
62
- actions[actionTriggerName] = generateActionTrigger(trigger)
63
-
64
- broker.emit('trigger.loaded', {
65
- objectName: trigger['listenTo']
66
- })
67
- }
68
-
69
- let serviceConfig = {
70
- name: serviceName,
71
- actions: actions
72
- };
73
- let service = broker.createService(serviceConfig);
74
- if (!broker.started) {
75
- await broker._restartService(service)
76
- }
77
-
78
- }
79
-
80
- // 生成action trigger
81
- function generateActionTrigger(trigger) {
82
- const when = [];
83
- for (const key in trigger) {
84
- if (Object.hasOwnProperty.call(trigger, key)) {
85
- if (_.contains(TRIGGERKEYS, key)) {
86
- when.push(key);
87
- }
88
- }
89
- }
90
- const actionTrigger = {
91
- trigger: {
92
- listenTo: trigger.listenTo,
93
- when: when
94
- },
95
- async handler(ctx) {
96
- // 调用trigger.js的处理函数
97
- const {
98
- isInsert, isUpdate, isDelete, isFind, isBefore, isAfter, isFindOne, isCount,
99
- id, doc, previousDoc,
100
- // size,
101
- userId, spaceId, objectName, query, data }: any = ctx.params;
102
-
103
- const context: any = {
104
- id,
105
- userId,
106
- spaceId,
107
- doc,
108
- previousDoc,
109
- query,
110
- data,
111
- objectName
112
- }
113
-
114
- let when = ''
115
- if (isBefore) {
116
- if (isFind) {
117
- when = 'beforeFind'
118
- } else if (isInsert) {
119
- when = 'beforeInsert'
120
- } else if (isUpdate) {
121
- when = 'beforeUpdate'
122
- } else if (isDelete) {
123
- when = 'beforeDelete'
124
- }
125
- }
126
- else if (isAfter) {
127
- if (isFind) {
128
- when = 'afterFind'
129
- } else if (isInsert) {
130
- when = 'afterInsert'
131
- } else if (isUpdate) {
132
- when = 'afterUpdate'
133
- } else if (isDelete) {
134
- when = 'afterDelete'
135
- } else if (isFindOne) {
136
- when = 'afterFindOne'
137
- } else if (isCount) {
138
- when = 'afterCount'
139
- }
140
- }
141
-
142
- if (when) {
143
- const object = getObject(objectName);
144
- if(!object){
145
- return ;
146
- }
147
- await object.runTriggers(when, context);
148
- return context;
149
- }
150
- }
151
- };
152
- return actionTrigger;
153
- }
package/tsconfig.json DELETED
@@ -1,34 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./lib",
4
- "target": "es6",
5
- "module": "commonjs",
6
- "moduleResolution": "node",
7
- "importHelpers": true,
8
- "emitDecoratorMetadata": true,
9
- "experimentalDecorators": true,
10
- "sourceMap": true,
11
- "noImplicitAny": false,
12
- "declaration": true,
13
- "noFallthroughCasesInSwitch": true,
14
- //"noImplicitReturns": true,
15
- "stripInternal": true,
16
- "pretty": true,
17
- "strictNullChecks": false,
18
- "noUnusedLocals": true,
19
- "downlevelIteration": true,
20
- "skipLibCheck": true,
21
- "lib": [
22
- "es5",
23
- "es6",
24
- "es2015",
25
- "es2016",
26
- "es2017",
27
- "esnext"
28
- ],
29
- "removeComments": true
30
- },
31
- "include": [
32
- "./src/**/*"
33
- ]
34
- }