@appland/scanner 1.70.5 → 1.71.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/README.md CHANGED
@@ -66,7 +66,7 @@ documentation for each rule to see it's pattern filters and other configurable p
66
66
  To enable de-duplication of findings, a hash is calculated for each finding. The hash is the
67
67
  `sha256` digest of a canonical content string for the finding. The canonical content string combines
68
68
  stable data from the finding, such as the rule id, normalized event, etc. See
69
- [appmap-js/packages/models/src/event/hash.js](https://github.com/applandinc/appmap-js/blob/959a8c93c9be37d40a8f4a0e7d44ee211730641e/packages/models/src/event/hash.js)
69
+ [appmap-js/packages/models/src/event/hash.js](https://github.com/getappmap/appmap-js/blob/959a8c93c9be37d40a8f4a0e7d44ee211730641e/packages/models/src/event/hash.js)
70
70
  for details.
71
71
 
72
72
  ## Findings output file
@@ -102,7 +102,7 @@ _Example_
102
102
  "clients": [
103
103
  {
104
104
  "name": "appmap",
105
- "url": "https://github.com/applandinc/appmap-ruby",
105
+ "url": "https://github.com/getappmap/appmap-ruby",
106
106
  "version": "0.70.2"
107
107
  }
108
108
  ],
@@ -118,12 +118,12 @@ _Example_
118
118
  ],
119
119
  "git": [
120
120
  {
121
- "repository": "git@github.com:applandinc/appmap-server.git",
121
+ "repository": "git@github.com:getappmap/appmap-server.git",
122
122
  "branch": "master",
123
123
  "commit": "3b028018ec1f84e2c351d01d1dac45aeeae887b6"
124
124
  },
125
125
  {
126
- "repository": "git@github.com:applandinc/appmap-server.git",
126
+ "repository": "git@github.com:getappmap/appmap-server.git",
127
127
  "branch": "master",
128
128
  "commit": "3b028018ec1f84e2c351d01d1dac45aeeae887b6",
129
129
  "status": [
@@ -200,11 +200,11 @@ _Example_
200
200
  "tmp/appmap/rspec/API_APIKeysController_create_a_new_api_key.appmap.json": {
201
201
  "client": {
202
202
  "name": "appmap",
203
- "url": "https://github.com/applandinc/appmap-ruby",
203
+ "url": "https://github.com/getappmap/appmap-ruby",
204
204
  "version": "0.70.1"
205
205
  },
206
206
  "git": {
207
- "repository": "git@github.com:applandinc/appmap-server.git",
207
+ "repository": "git@github.com:getappmap/appmap-server.git",
208
208
  "branch": "master",
209
209
  "commit": "3b028018ec1f84e2c351d01d1dac45aeeae887b6"
210
210
  },
@@ -9,11 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ const src_1 = require("@appland/client/dist/src");
12
13
  const fs_1 = require("fs");
13
14
  const promises_1 = require("fs/promises");
14
15
  const js_yaml_1 = require("js-yaml");
15
16
  const path_1 = require("path");
16
- const exists_1 = require("../integration/appland/app/exists");
17
17
  const errors_1 = require("../errors");
18
18
  function resolveAppId(appIdArg, appMapDir) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -44,7 +44,7 @@ function default_1(appIdArg, appMapDir) {
44
44
  const appId = yield resolveAppId(appIdArg, appMapDir);
45
45
  if (!appId)
46
46
  throw new errors_1.ValidationError('App was not provided and could not be resolved');
47
- const appExists = yield (0, exists_1.exists)(appId);
47
+ const appExists = yield new src_1.App(appId).exists();
48
48
  if (!appExists) {
49
49
  throw new errors_1.ValidationError(`App "${appId}" is not valid or does not exist.\nPlease fix the app name in the appmap.yml file, or override it with the --app option.`);
50
50
  }
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const src_1 = require("@appland/client/dist/src");
16
16
  const configurationProvider_1 = require("../../configuration/configurationProvider");
17
- const listFindingStatus_1 = __importDefault(require("../../integration/appland/app/listFindingStatus"));
18
17
  const resolveAppId_1 = __importDefault(require("../resolveAppId"));
19
18
  const scan_1 = __importDefault(require("../scan"));
20
19
  const scanResults_1 = require("../../report/scanResults");
@@ -47,7 +46,7 @@ class ServerIntegratedScanner extends ScannerBase {
47
46
  fetchFindingStatus(appIdArg, appMapDir) {
48
47
  return __awaiter(this, void 0, void 0, function* () {
49
48
  const appId = yield (0, resolveAppId_1.default)(appIdArg, appMapDir);
50
- return yield (0, listFindingStatus_1.default)(appId);
49
+ return yield new src_1.App(appId).listFindingStatus();
51
50
  });
52
51
  }
53
52
  }
@@ -40,14 +40,14 @@ const promises_1 = require("fs/promises");
40
40
  const chokidar = __importStar(require("chokidar"));
41
41
  const formatReport_1 = require("./formatReport");
42
42
  const scanner_1 = __importDefault(require("./scanner"));
43
- const fs_1 = require("fs");
44
- const util_1 = require("util");
45
43
  const configurationProvider_1 = require("../../configuration/configurationProvider");
46
44
  const assert_1 = __importDefault(require("assert"));
47
45
  const path_1 = __importDefault(require("path"));
46
+ const async_1 = require("async");
48
47
  class Watcher {
49
48
  constructor(options) {
50
49
  this.options = options;
50
+ this.queue = (0, async_1.queue)(this.scan.bind(this), 2);
51
51
  }
52
52
  watch() {
53
53
  return __awaiter(this, void 0, void 0, function* () {
@@ -71,10 +71,9 @@ class Watcher {
71
71
  interval: 1000,
72
72
  persistent: false,
73
73
  });
74
- for (const ch of [this.appmapWatcher, this.appmapPoller]) {
75
- ch.on('add', (filePath) => this.scan(filePath));
76
- ch.on('change', (filePath) => this.scan(filePath));
77
- }
74
+ const enqueue = this.enqueue.bind(this);
75
+ for (const ch of [this.appmapWatcher, this.appmapPoller])
76
+ ch.on('add', enqueue).on('change', enqueue);
78
77
  });
79
78
  }
80
79
  close() {
@@ -87,15 +86,24 @@ class Watcher {
87
86
  }));
88
87
  });
89
88
  }
90
- scan(fileName) {
89
+ enqueue(mtimePath) {
90
+ if ([...this.queue].includes(mtimePath))
91
+ return;
92
+ this.queue.push(mtimePath);
93
+ }
94
+ scan(mtimePath) {
91
95
  return __awaiter(this, void 0, void 0, function* () {
92
96
  (0, assert_1.default)(this.config, `config should always be loaded before appmapWatcher triggers a scan`);
93
- const pathTokens = fileName.split('/');
94
- const appmapDir = pathTokens.slice(0, pathTokens.length - 1).join('/');
95
- const appmapFile = [appmapDir, 'appmap.json'].join('.');
96
- const reportFile = [appmapDir, 'appmap-findings.json'].join('/');
97
- if (!(yield (0, util_1.promisify)(fs_1.exists)(appmapFile)))
97
+ (0, assert_1.default)(this.configTime);
98
+ const appmapFile = mtimePath.replace(/\/mtime$/, '.appmap.json');
99
+ const reportFile = mtimePath.replace(/mtime$/, 'appmap-findings.json');
100
+ const [appmapStats, reportStats] = yield Promise.all([appmapFile, reportFile].map((f) => (0, promises_1.stat)(f).catch(() => null)));
101
+ if (!appmapStats)
98
102
  return;
103
+ if (reportStats &&
104
+ reportStats.mtimeMs > appmapStats.mtimeMs &&
105
+ reportStats.mtimeMs > this.configTime)
106
+ return; // report is up to date
99
107
  const scanner = yield (0, scanner_1.default)(true, this.config, [appmapFile]);
100
108
  const rawScanResults = yield scanner.scan();
101
109
  // Always report the raw data
@@ -105,6 +113,7 @@ class Watcher {
105
113
  reloadConfig() {
106
114
  return __awaiter(this, void 0, void 0, function* () {
107
115
  this.config = yield (0, configurationProvider_1.parseConfigFile)(this.options.configFile);
116
+ this.configTime = (yield (0, promises_1.stat)(this.options.configFile)).mtimeMs;
108
117
  });
109
118
  }
110
119
  }
@@ -11,10 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const async_1 = require("async");
13
13
  const promises_1 = require("fs/promises");
14
+ const src_1 = require("@appland/client/dist/src");
14
15
  const util_1 = require("../rules/lib/util");
15
- const create_1 = require("../integration/appland/appMap/create");
16
- const create_2 = require("../integration/appland/mapset/create");
17
- const create_3 = require("../integration/appland/scannerJob/create");
16
+ const create_1 = require("../integration/appland/scannerJob/create");
18
17
  const vars_1 = require("../integration/vars");
19
18
  const promises_2 = require("fs/promises");
20
19
  const path_1 = require("path");
@@ -79,7 +78,7 @@ function create(scanResults, appId, appMapDir, mergeKey, mapsetOptions = {}, ret
79
78
  commitCount[commit] || (commitCount[commit] = 1);
80
79
  commitCount[commit] += 1;
81
80
  }
82
- return (0, create_1.create)(buffer, Object.assign(retryOptions, Object.assign(Object.assign({}, createAppMapOptions), { metadata })));
81
+ return src_1.AppMap.create(buffer, Object.assign(retryOptions, Object.assign(Object.assign({}, createAppMapOptions), { metadata })));
83
82
  })
84
83
  .then((appMap) => {
85
84
  if (appMap) {
@@ -104,9 +103,9 @@ function create(scanResults, appId, appMapDir, mergeKey, mapsetOptions = {}, ret
104
103
  };
105
104
  mapsetOptions.branch || (mapsetOptions.branch = (0, vars_1.branch)() || mostFrequent(branchCount));
106
105
  mapsetOptions.commit || (mapsetOptions.commit = (0, vars_1.sha)() || mostFrequent(commitCount));
107
- const mapset = yield (0, create_2.create)(appId, Object.values(appMapUUIDByFileName), mapsetOptions, retryOptions);
106
+ const mapset = yield src_1.Mapset.create(appId, Object.values(appMapUUIDByFileName), mapsetOptions, retryOptions);
108
107
  console.warn('Uploading findings');
109
- return (0, create_3.create)(scanResults, mapset.id, appMapUUIDByFileName, { mergeKey }, retryOptions);
108
+ return (0, create_1.create)(scanResults, mapset.id, appMapUUIDByFileName, { mergeKey }, retryOptions);
110
109
  });
111
110
  }
112
111
  exports.default = create;
@@ -13,7 +13,7 @@ function rule(options) {
13
13
  (0, assert_1.default)(table.variant === 'table');
14
14
  return !excludeTables.find((filter) => filter(table.name));
15
15
  }
16
- // TODO: clean up (https://github.com/applandinc/scanner/issues/43)
16
+ // TODO: clean up (https://github.com/getappmap/scanner/issues/43)
17
17
  function matcher(command, appMapIndex, eventFilter) {
18
18
  const joinCount = {};
19
19
  for (const sqlEvent of (0, database_1.sqlStrings)(command, appMapIndex, eventFilter)) {
@@ -1,6 +1,6 @@
1
1
  ## Scanner architecture
2
2
 
3
- See [@appland/models source code](https://github.com/applandinc/appmap-js/tree/main/packages/models)
3
+ See [@appland/models source code](https://github.com/getappmap/appmap-js/tree/main/packages/models)
4
4
  for the JS API to AppMap data.
5
5
 
6
6
  ## Assertions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appland/scanner",
3
- "version": "1.70.5",
3
+ "version": "1.71.1",
4
4
  "description": "",
5
5
  "bin": "built/cli.js",
6
6
  "files": [
@@ -67,11 +67,10 @@
67
67
  "async": "^3.2.3",
68
68
  "boxen": "^5.0.1",
69
69
  "chalk": "^4.1.2",
70
- "chokidar": "applandinc/chokidar#fix/new-file-new-directory-race-on-linux",
70
+ "chokidar": "^3.5.1",
71
71
  "cli-progress": "^3.11.0",
72
72
  "conf": "^10.0.2",
73
73
  "crypto-js": "^4.0.0",
74
- "form-data": "^4.0.0",
75
74
  "glob": "7.2.3",
76
75
  "inquirer": "^8.1.2",
77
76
  "js-yaml": "^4.1.0",
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.exists = void 0;
16
- const src_1 = require("@appland/client/dist/src");
17
- const util_1 = require("../../../rules/lib/util");
18
- const retry_1 = __importDefault(require("../retry"));
19
- function exists(appId, retryOptions = {}) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const commandDescription = `Checking if app ${appId} exists`;
22
- if ((0, util_1.verbose)())
23
- console.log(commandDescription);
24
- const retrier = (0, retry_1.default)(commandDescription, retryOptions, makeRequest);
25
- function makeRequest() {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const requestPath = ['api', appId].join('/');
28
- const request = yield (0, src_1.buildRequest)(requestPath);
29
- return new Promise((resolve, reject) => {
30
- const req = request.requestFunction(request.url, {
31
- method: 'HEAD',
32
- headers: request.headers,
33
- }, resolve);
34
- req.on('error', (0, src_1.retryOnError)(retrier, resolve, reject));
35
- req.end();
36
- }).then((0, src_1.retryOn503)(retrier));
37
- });
38
- }
39
- return makeRequest().then((response) => __awaiter(this, void 0, void 0, function* () {
40
- if ((0, util_1.verbose)())
41
- console.log(`${commandDescription}: statusCode=${response.statusCode}`);
42
- if (!response.statusCode) {
43
- throw new Error('No status code was provided by the server');
44
- }
45
- if (response.statusCode === 404) {
46
- return false;
47
- }
48
- else if (response.statusCode < 300) {
49
- return true;
50
- }
51
- throw new Error(`Unexpected status code: ${response.statusCode}`);
52
- }));
53
- });
54
- }
55
- exports.exists = exists;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const src_1 = require("@appland/client/dist/src");
13
- function listFindingStatus(appId) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- return yield new src_1.App(appId).listFindingStatus();
16
- });
17
- }
18
- exports.default = listFindingStatus;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.create = void 0;
16
- const src_1 = require("@appland/client/dist/src");
17
- const form_data_1 = __importDefault(require("form-data"));
18
- const retry_1 = __importDefault(require("../retry"));
19
- function create(data, options, retryOptions = {}) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const retrier = (0, retry_1.default)(`Upload AppMap`, retryOptions, makeRequest);
22
- function makeRequest() {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const form = new form_data_1.default();
25
- form.append('data', data.toString());
26
- if (options.metadata) {
27
- form.append('metadata', JSON.stringify(options.metadata));
28
- }
29
- if (options.app) {
30
- form.append('app', options.app);
31
- }
32
- const request = yield (0, src_1.buildRequest)('api/appmaps');
33
- return new Promise((resolve, reject) => {
34
- const req = request.requestFunction(request.url, {
35
- method: 'POST',
36
- headers: Object.assign(Object.assign({}, request.headers), form.getHeaders()),
37
- }, resolve);
38
- req.on('error', (0, src_1.retryOnError)(retrier, resolve, reject));
39
- form.pipe(req);
40
- }).then((0, src_1.retryOn503)(retrier));
41
- });
42
- }
43
- return makeRequest()
44
- .then(src_1.handleError)
45
- .then((response) => {
46
- return new Promise((resolve, reject) => {
47
- const responseData = [];
48
- response
49
- .on('data', (chunk) => {
50
- responseData.push(Buffer.from(chunk));
51
- })
52
- .on('end', () => {
53
- resolve(JSON.parse(Buffer.concat(responseData).toString()));
54
- })
55
- .on('error', reject);
56
- });
57
- });
58
- });
59
- }
60
- exports.create = create;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.create = void 0;
16
- const src_1 = require("@appland/client/dist/src");
17
- const util_1 = require("../../../rules/lib/util");
18
- const retry_1 = __importDefault(require("../retry"));
19
- function create(appId, appMapIds, options, retryOptions = {}) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- if ((0, util_1.verbose)())
22
- console.log(`Creating mapset in app ${appId} with ${appMapIds.length} AppMaps`);
23
- const retrier = (0, retry_1.default)(`Create Mapset`, retryOptions, makeRequest);
24
- function makeRequest() {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const payload = JSON.stringify(Object.assign({ app: appId, appmaps: appMapIds }, options));
27
- const request = yield (0, src_1.buildRequest)('api/mapsets');
28
- return new Promise((resolve, reject) => {
29
- const req = request.requestFunction(request.url, {
30
- method: 'POST',
31
- headers: Object.assign({ 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) }, request.headers),
32
- }, resolve);
33
- req.on('error', (0, src_1.retryOnError)(retrier, resolve, reject));
34
- req.write(payload);
35
- req.end();
36
- }).then((0, src_1.retryOn503)(retrier));
37
- });
38
- }
39
- return makeRequest()
40
- .then(src_1.handleError)
41
- .then((response) => {
42
- return new Promise((resolve, reject) => {
43
- const responseData = [];
44
- response
45
- .on('data', (chunk) => {
46
- responseData.push(Buffer.from(chunk));
47
- })
48
- .on('end', () => {
49
- resolve(JSON.parse(Buffer.concat(responseData).toString()));
50
- })
51
- .on('error', reject);
52
- });
53
- });
54
- });
55
- }
56
- exports.create = create;