@steedos/service-package-loader 2.4.0-beta.8 → 2.4.1

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
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  const objectql = require('@steedos/objectql');
4
+ const Future = require('fibers/future');
4
5
  const core = require('@steedos/core');
5
6
  const triggerLoader = require('./lib').triggerLoader;
6
7
  const processLoader = require('./lib').processLoader;
7
8
  const processTriggerLoader = require('./lib').processTriggerLoader;
8
- const sendPackageFlowToDb = require('./lib/loadPackageFlow').sendPackageFlowToDb;
9
9
  const path = require('path');
10
10
  const _ = require('lodash');
11
11
  const express = require('express');
12
12
  const fs = require("fs");
13
13
  const metaDataCore = require('@steedos/metadata-core');
14
+ const loadFlowFile = new metaDataCore.LoadFlowFile();
15
+
14
16
  /**
15
17
  * @typedef {import('moleculer').Context} Context Moleculer's Context
16
18
  */
@@ -62,6 +64,80 @@ module.exports = {
62
64
  * Methods
63
65
  */
64
66
  methods: {
67
+
68
+ sendPackageFlowToDb: async function(packagePath, name) {
69
+ const flows = loadFlowFile.load(path.join(packagePath, '**'));
70
+ for (const apiName in flows) {
71
+ const flow = flows[apiName];
72
+ const flowFilePath = flow.__filename;
73
+ delete flow.__filename;
74
+ try {
75
+ await this.importFlow(flow, name);
76
+ } catch (error) {
77
+ console.error(`importFlow error`, flowFilePath, error)
78
+ }
79
+ }
80
+ },
81
+
82
+ importFlow: async function(flow, name) {
83
+ await Future.task(() => {
84
+ try {
85
+ try {
86
+ if(!db){
87
+ return
88
+ }
89
+ if(!steedosImport){
90
+ return
91
+ }
92
+ } catch (error) {
93
+ return ;
94
+ }
95
+
96
+ if(db && db.flows && steedosImport){
97
+ const steedosConfig = objectql.getSteedosConfig();
98
+ let space;
99
+ if(steedosConfig && steedosConfig.tenant && steedosConfig.tenant._id){
100
+ space = db.spaces.findOne(steedosConfig.tenant._id)
101
+ }
102
+ if(!space){
103
+ space = db.spaces.findOne()
104
+ }
105
+ if(!space){
106
+ this.logger.debug(`import flow ${flow.name} fail. not find space in db`);
107
+ return ;
108
+ }
109
+ if(!flow.api_name){
110
+ this.logger.warn(`not find api_name in file`);
111
+ return ;
112
+ }
113
+ const dbFlow = db.flows.findOne({api_name: flow.api_name});
114
+ if(!dbFlow){
115
+ if(flow && flow.current){
116
+ if(!_.has(flow.current,'fields')){
117
+ flow.current.fields = [];
118
+ }
119
+ }
120
+ this.logger.info(`insert flow ${flow.api_name} from ${name}`);
121
+
122
+ let company_id = null;
123
+ if(flow.company_id){
124
+ let count = Creator.getCollection("company").find({ _id: flow.company_id, space: space._id }).count();
125
+ if(count > 0){
126
+ company_id = flow.company_id
127
+ }
128
+ }
129
+
130
+ return steedosImport.workflow(space.owner, space._id, flow, flow.state == 'enabled' ? true : false, company_id);
131
+ }
132
+ this.logger.debug(`not import flow. find flow `, dbFlow._id)
133
+ }
134
+
135
+ } catch (error) {
136
+ this.logger.error(error)
137
+ }
138
+ }).promise();
139
+
140
+ },
65
141
  loadDataOnServiceStarted: async function(){
66
142
  let packageInfo = this.settings.packageInfo;
67
143
  if (!packageInfo) {
@@ -71,7 +147,7 @@ module.exports = {
71
147
 
72
148
  this.loadPackagePublicFiles(_path);
73
149
  if(_path){
74
- sendPackageFlowToDb(this.broker, _path)
150
+ this.sendPackageFlowToDb(_path)
75
151
  processLoader.sendPackageProcessToDb(_path);
76
152
  }
77
153
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-package-loader",
3
- "version": "2.4.0-beta.8",
3
+ "version": "2.4.1",
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/core": "2.4.0-beta.8",
14
- "@steedos/metadata-core": "2.4.0-beta.8",
15
- "@steedos/objectql": "2.4.0-beta.8",
16
- "@steedos/router": "2.4.0-beta.8",
13
+ "@steedos/core": "2.4.1",
14
+ "@steedos/metadata-core": "2.4.1",
15
+ "@steedos/objectql": "2.4.1",
16
+ "@steedos/router": "2.4.1",
17
17
  "clone": "^2.1.2",
18
18
  "moleculer": "^0.14.25",
19
19
  "underscore": "^1.12.0"
@@ -25,5 +25,5 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "gitHead": "61fe4ff720d68127dadcd728b9bc465b62c38855"
28
+ "gitHead": "ae77c1ed63399245141bf7237cd3966bfc4dc6b1"
29
29
  }
@@ -1 +0,0 @@
1
- export declare const sendPackageFlowToDb: (broker: any, packagePath: string, name: string) => Promise<void>;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendPackageFlowToDb = void 0;
4
- const tslib_1 = require("tslib");
5
- const metadata_core_1 = require("@steedos/metadata-core");
6
- const loadFlowFile = new metadata_core_1.LoadFlowFile();
7
- const path = require('path');
8
- const sendPackageFlowToDb = (broker, packagePath, name) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
9
- const flows = loadFlowFile.load(path.join(packagePath, '**'));
10
- for (const apiName in flows) {
11
- const flow = flows[apiName];
12
- const flowFilePath = flow.__filename;
13
- delete flow.__filename;
14
- try {
15
- yield broker.call('steedos-server.importFlow', { flow: flow }, { meta: { name: name } });
16
- }
17
- catch (error) {
18
- console.error(`importFlow error`, flowFilePath, error);
19
- }
20
- }
21
- });
22
- exports.sendPackageFlowToDb = sendPackageFlowToDb;
23
- //# sourceMappingURL=loadPackageFlow.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loadPackageFlow.js","sourceRoot":"","sources":["../src/loadPackageFlow.ts"],"names":[],"mappings":";;;;AAAA,0DAAsD;AACtD,MAAM,YAAY,GAAG,IAAI,4BAAY,EAAE,CAAC;AACxC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAEtB,MAAM,mBAAmB,GAAG,CAAO,MAAM,EAAE,WAAmB,EAAE,IAAY,EAAC,EAAE;IAClF,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;IAC9D,KAAK,MAAM,OAAO,IAAI,KAAK,EAAE;QACzB,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5B,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC;QACrC,OAAO,IAAI,CAAC,UAAU,CAAC;QACvB,IAAI;YACA,MAAM,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE,EAAC,IAAI,EAAE,IAAI,EAAC,EAAE,EAAC,IAAI,EAAE,EAAC,IAAI,EAAE,IAAI,EAAC,EAAC,CAAC,CAAA;SACrF;QAAC,OAAO,KAAK,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,YAAY,EAAE,KAAK,CAAC,CAAA;SACzD;KACJ;AACL,CAAC,CAAA,CAAA;AAZY,QAAA,mBAAmB,uBAY/B"}
@@ -1,17 +0,0 @@
1
- import { LoadFlowFile } from '@steedos/metadata-core';
2
- const loadFlowFile = new LoadFlowFile();
3
- const path = require('path');
4
-
5
- export const sendPackageFlowToDb = async (broker, packagePath: string, name: string)=>{
6
- const flows = loadFlowFile.load(path.join(packagePath, '**'));
7
- for (const apiName in flows) {
8
- const flow = flows[apiName];
9
- const flowFilePath = flow.__filename;
10
- delete flow.__filename;
11
- try {
12
- await broker.call('steedos-server.importFlow', {flow: flow}, {meta: {name: name}})
13
- } catch (error) {
14
- console.error(`importFlow error`, flowFilePath, error)
15
- }
16
- }
17
- }