@appland/scanner 1.66.0 → 1.67.0
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/CHANGELOG.md +12 -0
- package/built/configuration/configurationProvider.js +1 -1
- package/built/database/index.js +15 -2
- package/built/rules/too-many-joins/metadata.js +10 -0
- package/built/rules/too-many-joins/options.js +12 -0
- package/built/rules/{tooManyJoins.js → too-many-joins/rule.js} +14 -24
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# [@appland/scanner-v1.67.0](https://github.com/applandinc/appmap-js/compare/@appland/scanner-v1.66.0...@appland/scanner-v1.67.0) (2022-08-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Fix Options loading from dir-based rules ([f58ce49](https://github.com/applandinc/appmap-js/commit/f58ce49f22ba4d649e8886d76373cf23d6614b37))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Ignore schema info tables in too-many-joins ([0cb387d](https://github.com/applandinc/appmap-js/commit/0cb387d74aa7e6edda5e24a88d07fa65b3900966))
|
|
12
|
+
|
|
1
13
|
# [@appland/scanner-v1.66.0](https://github.com/applandinc/appmap-js/compare/@appland/scanner-v1.65.0...@appland/scanner-v1.66.0) (2022-08-08)
|
|
2
14
|
|
|
3
15
|
|
|
@@ -83,7 +83,7 @@ function loadFromDir(ruleName) {
|
|
|
83
83
|
if ((0, util_1.verbose)())
|
|
84
84
|
console.log(`Loaded rule ${ruleName}: ${rule}`);
|
|
85
85
|
try {
|
|
86
|
-
options = yield Promise.resolve().then(() => __importStar(require(`../rules/${ruleName}/options`)));
|
|
86
|
+
options = (yield Promise.resolve().then(() => __importStar(require(`../rules/${ruleName}/options`)))).default;
|
|
87
87
|
if ((0, util_1.verbose)())
|
|
88
88
|
console.log(`Loaded rule ${ruleName} options: ${options}`);
|
|
89
89
|
}
|
package/built/database/index.js
CHANGED
|
@@ -126,14 +126,27 @@ function* sqlStrings(event, appMapIndex, filter = () => true) {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
exports.sqlStrings = sqlStrings;
|
|
129
|
-
function countJoins(ast) {
|
|
129
|
+
function countJoins(ast, filterTable) {
|
|
130
130
|
if (!ast)
|
|
131
131
|
return 0;
|
|
132
132
|
let joins = 0;
|
|
133
133
|
(0, visit_1.visit)(ast, {
|
|
134
134
|
'map.join': (node) => {
|
|
135
135
|
var _a;
|
|
136
|
-
|
|
136
|
+
const map = (_a = node.map) !== null && _a !== void 0 ? _a : [];
|
|
137
|
+
const tableCount = filterTable
|
|
138
|
+
? map.filter((entry) => {
|
|
139
|
+
const source = entry === null || entry === void 0 ? void 0 : entry.source;
|
|
140
|
+
if (!source)
|
|
141
|
+
return true;
|
|
142
|
+
if (source.type !== 'identifier')
|
|
143
|
+
return true;
|
|
144
|
+
if (source.variant !== 'table')
|
|
145
|
+
return true;
|
|
146
|
+
return filterTable(source);
|
|
147
|
+
}).length
|
|
148
|
+
: map.length;
|
|
149
|
+
joins += tableCount;
|
|
137
150
|
},
|
|
138
151
|
});
|
|
139
152
|
return joins;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
title: 'Too many joins',
|
|
5
|
+
enumerateScope: false,
|
|
6
|
+
impactDomain: 'Performance',
|
|
7
|
+
references: {
|
|
8
|
+
'CWE-1049': 'https://cwe.mitre.org/data/definitions/1049.html',
|
|
9
|
+
},
|
|
10
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Options {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.warningLimit = 5;
|
|
6
|
+
this.excludeTables = [
|
|
7
|
+
{ match: /^pg_/, ignoreCase: false },
|
|
8
|
+
{ match: /^information_schema$/, ignoreCase: true },
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.default = Options;
|
|
@@ -3,24 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const assert_1 = __importDefault(require("assert"));
|
|
7
|
+
const database_1 = require("../../database");
|
|
8
|
+
const matchPattern_1 = require("../lib/matchPattern");
|
|
9
|
+
function rule(options) {
|
|
10
|
+
const excludeTables = (0, matchPattern_1.buildFilters)(options.excludeTables);
|
|
11
|
+
function filterTable(table) {
|
|
12
|
+
(0, assert_1.default)(table.type === 'identifier');
|
|
13
|
+
(0, assert_1.default)(table.variant === 'table');
|
|
14
|
+
return !excludeTables.find((filter) => filter(table.name));
|
|
12
15
|
}
|
|
13
|
-
|
|
14
|
-
// TODO: clean up (https://github.com/applandinc/scanner/issues/43)
|
|
15
|
-
function build(options = new Options()) {
|
|
16
|
-
const joinCount = {};
|
|
16
|
+
// TODO: clean up (https://github.com/applandinc/scanner/issues/43)
|
|
17
17
|
function matcher(command, appMapIndex, eventFilter) {
|
|
18
|
+
const joinCount = {};
|
|
18
19
|
for (const sqlEvent of (0, database_1.sqlStrings)(command, appMapIndex, eventFilter)) {
|
|
19
20
|
let occurrence = joinCount[sqlEvent.sql];
|
|
20
21
|
if (!occurrence) {
|
|
22
|
+
const sqlAST = appMapIndex.sqlAST(sqlEvent.event);
|
|
21
23
|
occurrence = {
|
|
22
24
|
count: 1,
|
|
23
|
-
joins: (0, database_1.countJoins)(
|
|
25
|
+
joins: (0, database_1.countJoins)(sqlAST, filterTable),
|
|
24
26
|
events: [sqlEvent.event],
|
|
25
27
|
};
|
|
26
28
|
joinCount[sqlEvent.sql] = occurrence;
|
|
@@ -46,16 +48,4 @@ function build(options = new Options()) {
|
|
|
46
48
|
matcher,
|
|
47
49
|
};
|
|
48
50
|
}
|
|
49
|
-
exports.default =
|
|
50
|
-
id: 'too-many-joins',
|
|
51
|
-
title: 'Too many joins',
|
|
52
|
-
impactDomain: 'Performance',
|
|
53
|
-
enumerateScope: false,
|
|
54
|
-
references: {
|
|
55
|
-
'CWE-1049': new url_1.URL('https://cwe.mitre.org/data/definitions/1049.html'),
|
|
56
|
-
},
|
|
57
|
-
description: (0, parseRuleDescription_1.default)('tooManyJoins'),
|
|
58
|
-
url: 'https://appland.com/docs/analysis/rules-reference.html#too-many-joins',
|
|
59
|
-
Options,
|
|
60
|
-
build,
|
|
61
|
-
};
|
|
51
|
+
exports.default = rule;
|