@corva/create-app 0.45.0-0 → 0.45.0-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.
@@ -114,17 +114,24 @@ export class Api {
114
114
  *
115
115
  * @public
116
116
  *
117
- * @param {string} status
117
+ * @param {string[]} statuses
118
+ * @param {number} companyId
118
119
  * @param {number} perPage
119
120
  *
120
121
  * @returns {Promise<object[]>}
121
122
  */
122
- async getAllAssets(status = 'active', perPage = 1000) {
123
- const { data } = await this.#api
124
- .get(`v2/assets`, {
125
- searchParams: { status, per_page: perPage },
126
- })
127
- .json();
123
+ async getAllAssets(statuses = ['active'], companyId = null, perPage = 2000) {
124
+ const searchParams = [['per_page', perPage]];
125
+
126
+ if (companyId) {
127
+ searchParams.push(['company_id', companyId]);
128
+ }
129
+
130
+ if (statuses?.length) {
131
+ searchParams.push(...statuses.map((status) => ['status[]', status]));
132
+ }
133
+
134
+ const { data } = await this.#api.get(`v2/assets`, { searchParams: new URLSearchParams(searchParams) }).json();
128
135
 
129
136
  return data;
130
137
  }
@@ -145,7 +152,7 @@ export class Api {
145
152
  })
146
153
  .json();
147
154
 
148
- if (!wells.length) {
155
+ if (!wells || !wells.length) {
149
156
  throw new Error(`Could not found wells by asset ID - ${assetId}`);
150
157
  }
151
158
 
@@ -24,6 +24,8 @@ export const CREATE_TASK_STEP = {
24
24
  logger.write(`\n\n${chalk.yellow.bold('There is no asset ID to create a new task')}`);
25
25
  }
26
26
 
27
+ let i = 1;
28
+
27
29
  for (const assetId of assets) {
28
30
  const wellId = mappedAssetsToWells.get(parseInt(assetId)).id;
29
31
  const streamId = mappedAssetsToStreams.get(parseInt(assetId)).id;
@@ -48,7 +50,7 @@ export const CREATE_TASK_STEP = {
48
50
  });
49
51
 
50
52
  logger.write(
51
- `\n Created a new task with ID ${chalk.yellow(result.id)} for asset ID - ${chalk.green(assetId)}`,
53
+ `\n ${i}. Created a new task with ID ${chalk.yellow(result.id)} for asset ID - ${chalk.green(assetId)}`,
52
54
  );
53
55
 
54
56
  logger.write(
@@ -56,6 +58,7 @@ export const CREATE_TASK_STEP = {
56
58
  CORVA_API_ENV === 'production' ? '.' : `.${CORVA_API_ENV}.`
57
59
  }corva.ai/dev-center/apps/${app.id}/runner`,
58
60
  );
61
+ i++;
59
62
  } catch (e) {
60
63
  logger.write(
61
64
  `\n\n${chalk.red.underline.bold(
@@ -45,7 +45,7 @@ const ensureAppIsInTheStream = async (assetId, stream, appId, api, manifest) =>
45
45
  return;
46
46
  }
47
47
 
48
- const newConnection = await api.connectAppToStream(appId, stream.id, manifest.settings.app);
48
+ const newConnection = await api.connectAppToStream(appId, stream.id, manifest.manifest.settings.app);
49
49
 
50
50
  logger.write(
51
51
  `\n\n${chalk.black.underline.bold(
@@ -72,9 +72,24 @@ const getAppVersion = async (appId, optionAppVersion, api) => {
72
72
 
73
73
  // if there are several versions, show versions list to user
74
74
  const choices = appPackages.map((appPackage) => {
75
+ const parts = [];
76
+ const { notes, label, version } = appPackage.attributes;
77
+
78
+ if (label) {
79
+ parts.push(label);
80
+ }
81
+
82
+ if (notes) {
83
+ parts.push(notes);
84
+ }
85
+
86
+ if (version) {
87
+ parts.push(version);
88
+ }
89
+
75
90
  return {
76
91
  value: appPackage.attributes.version,
77
- name: appPackage.attributes.version,
92
+ name: parts.join(' '),
78
93
  };
79
94
  });
80
95
 
@@ -4,13 +4,17 @@ import _ from 'lodash';
4
4
  import { logger } from '../../../helpers/logger.js';
5
5
  import { StepError } from '../../lib/step-error.js';
6
6
 
7
- const MAX_ASSET_IDS_COUNT = 10;
7
+ const MAX_ASSET_IDS_COUNT = 300;
8
8
 
9
9
  export const PREPARE_DATA_TASK_STEP = {
10
10
  message: 'Preparing and checking data...',
11
11
  fn: async (context) => {
12
12
  const { manifest, options, api } = context;
13
- let { assets, interval } = options;
13
+ let { assets, interval, companyId } = options;
14
+
15
+ if (companyId) {
16
+ assets = await getAssetsByCompanyId(companyId, api);
17
+ }
14
18
 
15
19
  assets = _.uniq(assets);
16
20
 
@@ -83,6 +87,24 @@ const promptAreYouSure = async () => {
83
87
  return answers.option;
84
88
  };
85
89
 
90
+ /**
91
+ * Get all suitable assets for rerun by company ID
92
+ *
93
+ * @param {number} comanyId
94
+ * @param {object} api
95
+ *
96
+ * @returns {number[]}
97
+ */
98
+ const getAssetsByCompanyId = async (companyId, api) => {
99
+ logger.write('\n Try to find all suitable assets by Company ID...');
100
+
101
+ const assets = await api.getAllAssets(['complete', 'idle', 'paused', 'unknown'], companyId);
102
+
103
+ logger.write(`\n\n Found ${chalk.yellow.bold(assets.length)} assets, for the company ID ${companyId}!`);
104
+
105
+ return assets.map((asset) => asset.id);
106
+ };
107
+
86
108
  /**
87
109
  * Check if current runs already exist
88
110
  *
@@ -151,7 +151,7 @@ const prepareWellAndStreamData = async (assets, api, manifest) => {
151
151
 
152
152
  const streams = await api.getStreamsByAssetIds([assetId], manifest.manifest.application.segments);
153
153
 
154
- if (!streams.length) {
154
+ if (!streams || !streams.length) {
155
155
  throw new Error(`Could not found streams for asset ID - ${assetId}`);
156
156
  }
157
157
 
package/lib/main.js CHANGED
@@ -226,7 +226,8 @@ export async function run() {
226
226
  .addOption(envOption)
227
227
  .addOption(silentOption)
228
228
  .addOption(appVersion)
229
- .addOption(new Option('--assets [assets...]', 'Assets ids list', []))
229
+ .addOption(new Option('--assets [assets...]', 'Assets IDs list', []).conflicts('companyId'))
230
+ .addOption(new Option('--company-id [number]', 'Company ID', []))
230
231
  .addOption(new Option('--interval [number]', 'Interval for scheduler apps (exp. 1200)'))
231
232
  .addOption(originalCwdOption)
232
233
  .action(async (dirName, options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corva/create-app",
3
- "version": "0.45.0-0",
3
+ "version": "0.45.0-1",
4
4
  "private": false,
5
5
  "description": "Create an app to use it in CORVA.AI",
6
6
  "keywords": [
@@ -57,6 +57,7 @@
57
57
  "terminal-link": "^3.0.0"
58
58
  },
59
59
  "devDependencies": {
60
+ "@babel/core": "^7.11.0",
60
61
  "@babel/eslint-parser": "^7.19.1",
61
62
  "@babel/plugin-syntax-import-assertions": "^7.20.0",
62
63
  "@commitlint/cli": "^17.3.0",
@@ -64,9 +65,21 @@
64
65
  "@corva/eslint-config-browser": "^0.0.4",
65
66
  "@corva/eslint-config-node": "^5.0.0",
66
67
  "@types/cross-spawn": "^6.0.2",
68
+ "@typescript-eslint/eslint-plugin": "^5.42.1",
69
+ "@typescript-eslint/parser": "^5.42.1",
67
70
  "conventional-changelog-cli": "^2.1.0",
71
+ "eslint": "^8.2.0",
72
+ "eslint-config-google": "^0.14.0",
73
+ "eslint-config-prettier": "^8.5.0",
74
+ "eslint-plugin-import": "^2.26.0",
75
+ "eslint-plugin-jest": "^27.1.5",
76
+ "eslint-plugin-prettier": "^4.2.1",
77
+ "eslint-plugin-require-sort": "^1.3.0",
68
78
  "husky": "^8.0.2",
69
- "standard-version": "^9.0.0"
79
+ "prettier": "^2.0.0",
80
+ "prettier-plugin-packagejson": "^2.3.0",
81
+ "standard-version": "^9.0.0",
82
+ "typescript": "^4.8.4"
70
83
  },
71
84
  "engines": {
72
85
  "node": ">=16"