@mongodb-js/explain-plan-helper 0.8.0 → 0.11.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/dist/get-execution-stats.d.ts +13 -0
- package/dist/get-execution-stats.d.ts.map +1 -0
- package/dist/get-execution-stats.js +83 -0
- package/dist/get-execution-stats.js.map +1 -0
- package/dist/get-planner-info.d.ts +8 -0
- package/dist/get-planner-info.d.ts.map +1 -0
- package/dist/get-planner-info.js +47 -0
- package/dist/get-planner-info.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -17
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Stage, IndexInformation } from './index';
|
|
2
|
+
export declare type ExecutionStats = {
|
|
3
|
+
executionSuccess: boolean;
|
|
4
|
+
nReturned: number;
|
|
5
|
+
executionTimeMillis: number;
|
|
6
|
+
totalKeysExamined: number;
|
|
7
|
+
totalDocsExamined: number;
|
|
8
|
+
executionStages: Stage;
|
|
9
|
+
allPlansExecution: unknown[];
|
|
10
|
+
stageIndexes?: IndexInformation[];
|
|
11
|
+
};
|
|
12
|
+
export declare const getExecutionStats: (explain: Stage) => ExecutionStats;
|
|
13
|
+
//# sourceMappingURL=get-execution-stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-execution-stats.d.ts","sourceRoot":"","sources":["../src/get-execution-stats.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEvD,oBAAY,cAAc,GAAG;IAC3B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,KAAK,CAAC;IACvB,iBAAiB,EAAE,OAAO,EAAE,CAAC;IAC7B,YAAY,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,iBAAiB,YAAa,KAAK,KAAG,cAKlD,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getExecutionStats = void 0;
|
|
4
|
+
const mongodb_explain_compat_1 = require("mongodb-explain-compat");
|
|
5
|
+
const getExecutionStats = (explain) => {
|
|
6
|
+
const executionStats = (0, mongodb_explain_compat_1.isAggregationExplain)(explain)
|
|
7
|
+
? _getAggregationStats(explain)
|
|
8
|
+
: _getFindStats(explain);
|
|
9
|
+
return executionStats;
|
|
10
|
+
};
|
|
11
|
+
exports.getExecutionStats = getExecutionStats;
|
|
12
|
+
const _getAggregationStats = (explain) => {
|
|
13
|
+
return (0, mongodb_explain_compat_1.isShardedAggregationExplain)(explain)
|
|
14
|
+
? _getShardedAggregationStats(explain)
|
|
15
|
+
: _getUnshardedAggregationStats(explain);
|
|
16
|
+
};
|
|
17
|
+
const _getUnshardedAggregationStats = (explain) => {
|
|
18
|
+
const firstStage = explain.stages[0];
|
|
19
|
+
const cursorKey = (0, mongodb_explain_compat_1.getStageCursorKey)(firstStage);
|
|
20
|
+
if (!cursorKey) {
|
|
21
|
+
throw new Error('Can not find a cursor stage.');
|
|
22
|
+
}
|
|
23
|
+
const lastStage = explain.stages[explain.stages.length - 1];
|
|
24
|
+
const stats = _getFindStats(firstStage[cursorKey]);
|
|
25
|
+
stats.nReturned = lastStage.nReturned;
|
|
26
|
+
stats.stageIndexes = getIndexesFromStages(explain.stages);
|
|
27
|
+
stats.executionTimeMillis = getExecutionTime(stats, explain.stages);
|
|
28
|
+
return stats;
|
|
29
|
+
};
|
|
30
|
+
const _getShardedAggregationStats = (explain) => {
|
|
31
|
+
var _a;
|
|
32
|
+
const shardStats = [];
|
|
33
|
+
let stageIndexes = [];
|
|
34
|
+
for (const shardName in explain.shards) {
|
|
35
|
+
const stats = explain.shards[shardName].stages
|
|
36
|
+
? _getUnshardedAggregationStats(explain.shards[shardName])
|
|
37
|
+
: _getFindStats(explain.shards[shardName]);
|
|
38
|
+
shardStats.push({
|
|
39
|
+
shardName,
|
|
40
|
+
...stats,
|
|
41
|
+
});
|
|
42
|
+
stageIndexes = stageIndexes.concat(getIndexesFromStages((_a = explain.shards[shardName].stages) !== null && _a !== void 0 ? _a : [], shardName));
|
|
43
|
+
}
|
|
44
|
+
const nReturned = sumArrayProp(shardStats, 'nReturned');
|
|
45
|
+
const executionTimeMillis = sumArrayProp(shardStats, 'executionTimeMillis');
|
|
46
|
+
const totalKeysExamined = sumArrayProp(shardStats, 'totalKeysExamined');
|
|
47
|
+
const totalDocsExamined = sumArrayProp(shardStats, 'totalDocsExamined');
|
|
48
|
+
const response = {
|
|
49
|
+
nReturned,
|
|
50
|
+
executionTimeMillis,
|
|
51
|
+
totalKeysExamined,
|
|
52
|
+
totalDocsExamined,
|
|
53
|
+
allPlansExecution: [],
|
|
54
|
+
executionSuccess: true,
|
|
55
|
+
stageIndexes,
|
|
56
|
+
executionStages: {
|
|
57
|
+
stage: shardStats.length === 1 ? 'SINGLE_SHARD' : 'SHARD_MERGE',
|
|
58
|
+
nReturned,
|
|
59
|
+
executionTimeMillis,
|
|
60
|
+
totalKeysExamined,
|
|
61
|
+
totalDocsExamined,
|
|
62
|
+
shards: shardStats,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
return response;
|
|
66
|
+
};
|
|
67
|
+
const _getFindStats = (explain) => {
|
|
68
|
+
return explain.executionStats;
|
|
69
|
+
};
|
|
70
|
+
function sumArrayProp(arr, prop) {
|
|
71
|
+
return arr.reduce((acc, x) => { var _a; return acc + Number((_a = x[prop]) !== null && _a !== void 0 ? _a : 0); }, 0);
|
|
72
|
+
}
|
|
73
|
+
function getIndexesFromStages(stages, shard) {
|
|
74
|
+
return stages
|
|
75
|
+
.reduce((acc, x) => { var _a; return acc.concat((_a = x === null || x === void 0 ? void 0 : x.indexesUsed) !== null && _a !== void 0 ? _a : []); }, [])
|
|
76
|
+
.map((index) => ({ index, shard: shard !== null && shard !== void 0 ? shard : null }));
|
|
77
|
+
}
|
|
78
|
+
function getExecutionTime(stats, stages) {
|
|
79
|
+
const [, ...allStages] = stages;
|
|
80
|
+
return (stats.executionTimeMillis +
|
|
81
|
+
sumArrayProp(allStages, 'executionTimeMillisEstimate'));
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=get-execution-stats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-execution-stats.js","sourceRoot":"","sources":["../src/get-execution-stats.ts"],"names":[],"mappings":";;;AAAA,mEAIgC;AAezB,MAAM,iBAAiB,GAAG,CAAC,OAAc,EAAkB,EAAE;IAClE,MAAM,cAAc,GAAG,IAAA,6CAAoB,EAAC,OAAO,CAAC;QAClD,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC;QAC/B,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC3B,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AALW,QAAA,iBAAiB,qBAK5B;AACF,MAAM,oBAAoB,GAAG,CAAC,OAAc,EAAkB,EAAE;IAC9D,OAAO,IAAA,oDAA2B,EAAC,OAAO,CAAC;QACzC,CAAC,CAAC,2BAA2B,CAAC,OAAO,CAAC;QACtC,CAAC,CAAC,6BAA6B,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC,CAAC;AACF,MAAM,6BAA6B,GAAG,CAAC,OAAc,EAAkB,EAAE;IACvE,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,IAAA,0CAAiB,EAAC,UAAU,CAAC,CAAC;IAChD,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,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EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,EAAE,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAqB,EAAE,MAAe;IAG9D,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC,GAAG,MAAM,CAAC;IAChC,OAAO,CACL,KAAK,CAAC,mBAAmB;QACzB,YAAY,CAAC,SAAS,EAAE,6BAA6B,CAAC,CACvD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-planner-info.d.ts","sourceRoot":"","sources":["../src/get-planner-info.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,aAAK,WAAW,GAAG;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,KAAK,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,KAAK,KAAG,WAQ/C,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPlannerInfo = void 0;
|
|
4
|
+
const mongodb_explain_compat_1 = require("mongodb-explain-compat");
|
|
5
|
+
const getPlannerInfo = (explain) => {
|
|
6
|
+
const queryPlanner = (0, mongodb_explain_compat_1.isAggregationExplain)(explain)
|
|
7
|
+
? _getAggregationPlanner(explain)
|
|
8
|
+
: _getFindPlanner(explain);
|
|
9
|
+
return {
|
|
10
|
+
namespace: queryPlanner.namespace,
|
|
11
|
+
parsedQuery: queryPlanner.parsedQuery,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
exports.getPlannerInfo = getPlannerInfo;
|
|
15
|
+
const _getAggregationPlanner = (explain) => {
|
|
16
|
+
return (0, mongodb_explain_compat_1.isShardedAggregationExplain)(explain)
|
|
17
|
+
? _getShardedAggregationPlanner(explain)
|
|
18
|
+
: _getUnshardedAggregationPlanner(explain);
|
|
19
|
+
};
|
|
20
|
+
const _getUnshardedAggregationPlanner = (explain) => {
|
|
21
|
+
const firstStage = explain.stages[0];
|
|
22
|
+
const cursorKey = (0, mongodb_explain_compat_1.getStageCursorKey)(firstStage);
|
|
23
|
+
if (!cursorKey) {
|
|
24
|
+
throw new Error('Can not find a cursor stage.');
|
|
25
|
+
}
|
|
26
|
+
return _getUnshardedFindPlanner(firstStage[cursorKey]);
|
|
27
|
+
};
|
|
28
|
+
const _getShardedAggregationPlanner = (explain) => {
|
|
29
|
+
const firstShardName = Object.keys(explain.shards)[0];
|
|
30
|
+
const firstShard = explain.shards[firstShardName];
|
|
31
|
+
if (firstShard.stages) {
|
|
32
|
+
return _getUnshardedAggregationPlanner(firstShard);
|
|
33
|
+
}
|
|
34
|
+
return _getUnshardedFindPlanner(firstShard);
|
|
35
|
+
};
|
|
36
|
+
const _getFindPlanner = (explain) => {
|
|
37
|
+
return (0, mongodb_explain_compat_1.isShardedFindExplain)(explain)
|
|
38
|
+
? _getShardedFindPlanner(explain)
|
|
39
|
+
: _getUnshardedFindPlanner(explain);
|
|
40
|
+
};
|
|
41
|
+
const _getUnshardedFindPlanner = (explain) => {
|
|
42
|
+
return explain.queryPlanner;
|
|
43
|
+
};
|
|
44
|
+
const _getShardedFindPlanner = (explain) => {
|
|
45
|
+
return explain.queryPlanner.winningPlan.shards[0];
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=get-planner-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-planner-info.js","sourceRoot":"","sources":["../src/get-planner-info.ts"],"names":[],"mappings":";;;AAAA,mEAKgC;AASzB,MAAM,cAAc,GAAG,CAAC,OAAc,EAAe,EAAE;IAC5D,MAAM,YAAY,GAAG,IAAA,6CAAoB,EAAC,OAAO,CAAC;QAChD,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC;QACjC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;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,CAAC;AACxC,CAAC,CAAC;AACF,MAAM,wBAAwB,GAAG,CAAC,OAAc,EAAS,EAAE;IACzD,OAAO,OAAO,CAAC,YAAY,CAAC;AAC9B,CAAC,CAAC;AACF,MAAM,sBAAsB,GAAG,CAAC,OAAc,EAAS,EAAE;IACvD,OAAO,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { ExecutionStats } from './get-execution-stats';
|
|
1
2
|
declare const kParent: unique symbol;
|
|
2
|
-
declare type Stage = Record<string, any> & {
|
|
3
|
+
export declare type Stage = Record<string, any> & {
|
|
3
4
|
stage: string;
|
|
4
5
|
[kParent]: Stage | null;
|
|
5
6
|
};
|
|
6
|
-
declare type IndexInformation = {
|
|
7
|
+
export declare type IndexInformation = {
|
|
7
8
|
shard: string;
|
|
8
9
|
index: string;
|
|
9
10
|
} | {
|
|
@@ -21,8 +22,8 @@ export declare class ExplainPlan {
|
|
|
21
22
|
executionTimeMillis: number;
|
|
22
23
|
totalKeysExamined: number;
|
|
23
24
|
totalDocsExamined: number;
|
|
24
|
-
rawExplainObject: Stage;
|
|
25
25
|
originalExplainData: Stage;
|
|
26
|
+
executionStats: ExecutionStats;
|
|
26
27
|
constructor(originalExplainData: Stage);
|
|
27
28
|
get usedIndexes(): IndexInformation[];
|
|
28
29
|
get isCovered(): boolean;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,QAAA,MAAM,OAAO,eAAgC,CAAC;AAE9C,oBAAY,KAAK,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AC,KAAK,CAAC;IAiBjD,MAAM,CAAE,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAgCrD,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAa1C,MAAM,CAAE,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;CAMvD"}
|
package/dist/index.js
CHANGED
|
@@ -5,29 +5,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ExplainPlan = void 0;
|
|
7
7
|
const mongodb_explain_compat_1 = __importDefault(require("mongodb-explain-compat"));
|
|
8
|
+
const get_planner_info_1 = require("./get-planner-info");
|
|
9
|
+
const get_execution_stats_1 = require("./get-execution-stats");
|
|
8
10
|
const kParent = Symbol('ExplainPlan.kParent');
|
|
9
11
|
class ExplainPlan {
|
|
10
12
|
constructor(originalExplainData) {
|
|
11
|
-
var _a, _b, _c
|
|
13
|
+
var _a, _b, _c;
|
|
12
14
|
const rawExplainObject = (0, mongodb_explain_compat_1.default)(originalExplainData);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
15
|
+
const executionStats = (0, get_execution_stats_1.getExecutionStats)(rawExplainObject);
|
|
16
|
+
ExplainPlan.addParentStages(executionStats.executionStages);
|
|
17
|
+
const qpInfo = (0, get_planner_info_1.getPlannerInfo)(rawExplainObject);
|
|
18
|
+
const esInfo = (_c = (_b = (_a = executionStats === null || executionStats === void 0 ? void 0 : executionStats.executionStages) === null || _a === void 0 ? void 0 : _a.shards) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : executionStats;
|
|
19
|
+
this.executionStats = executionStats;
|
|
16
20
|
this.namespace = qpInfo.namespace;
|
|
17
21
|
this.parsedQuery = qpInfo.parsedQuery;
|
|
18
22
|
this.executionSuccess = esInfo.executionSuccess;
|
|
19
|
-
this.nReturned =
|
|
20
|
-
this.executionTimeMillis =
|
|
21
|
-
|
|
22
|
-
this.
|
|
23
|
-
this.totalDocsExamined = rawExplainObject.executionStats.totalDocsExamined;
|
|
24
|
-
this.rawExplainObject = rawExplainObject;
|
|
23
|
+
this.nReturned = executionStats.nReturned;
|
|
24
|
+
this.executionTimeMillis = executionStats.executionTimeMillis;
|
|
25
|
+
this.totalKeysExamined = executionStats.totalKeysExamined;
|
|
26
|
+
this.totalDocsExamined = executionStats.totalDocsExamined;
|
|
25
27
|
this.originalExplainData = originalExplainData;
|
|
26
28
|
}
|
|
27
29
|
get usedIndexes() {
|
|
30
|
+
var _a;
|
|
28
31
|
const ixscan = this.findAllStagesByName('IXSCAN');
|
|
29
32
|
const idhack = this.findStageByName('IDHACK');
|
|
30
|
-
const ret = [];
|
|
33
|
+
const ret = (_a = this.executionStats.stageIndexes) !== null && _a !== void 0 ? _a : [];
|
|
31
34
|
for (const stage of [...ixscan, idhack]) {
|
|
32
35
|
if (!stage)
|
|
33
36
|
continue;
|
|
@@ -44,14 +47,13 @@ class ExplainPlan {
|
|
|
44
47
|
ret.push({ index, shard });
|
|
45
48
|
}
|
|
46
49
|
if (this.isSharded) {
|
|
47
|
-
for (const shard of this.
|
|
48
|
-
.shards) {
|
|
50
|
+
for (const shard of this.executionStats.executionStages.shards) {
|
|
49
51
|
if (!ret.some((indexInfo) => indexInfo.shard === shard.shardName)) {
|
|
50
52
|
ret.push({ index: null, shard: shard.shardName });
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
|
-
return ret;
|
|
56
|
+
return ret.filter((indexInfo, index, arr) => arr.findIndex((i) => i.index === indexInfo.index && i.shard === indexInfo.shard) === index);
|
|
55
57
|
}
|
|
56
58
|
get isCovered() {
|
|
57
59
|
if (this.totalDocsExamined > 0) {
|
|
@@ -70,11 +72,11 @@ class ExplainPlan {
|
|
|
70
72
|
return this.findStageByName('COLLSCAN') !== null;
|
|
71
73
|
}
|
|
72
74
|
get isSharded() {
|
|
73
|
-
return !!this.
|
|
75
|
+
return !!this.executionStats.executionStages.shards;
|
|
74
76
|
}
|
|
75
77
|
get numShards() {
|
|
76
78
|
return this.isSharded
|
|
77
|
-
? this.
|
|
79
|
+
? this.executionStats.executionStages.shards.length
|
|
78
80
|
: 0;
|
|
79
81
|
}
|
|
80
82
|
findStageByName(name, root) {
|
|
@@ -89,7 +91,7 @@ class ExplainPlan {
|
|
|
89
91
|
return [...this._getStageIterator(root)].filter((stage) => stage.stage === name);
|
|
90
92
|
}
|
|
91
93
|
*_getStageIterator(root) {
|
|
92
|
-
const stage = root !== null && root !== void 0 ? root : this.
|
|
94
|
+
const stage = root !== null && root !== void 0 ? root : this.executionStats.executionStages;
|
|
93
95
|
yield stage;
|
|
94
96
|
for (const child of ExplainPlan.getChildStages(stage)) {
|
|
95
97
|
yield* this._getStageIterator(child);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,oFAA0D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,oFAA0D;AAC1D,yDAAoD;AACpD,+DAA0D;AAG1D,MAAM,OAAO,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAW9C,MAAa,WAAW;IAWtB,YAAY,mBAA0B;;QACpC,MAAM,gBAAgB,GAAG,IAAA,gCAAoB,EAAC,mBAAmB,CAAC,CAAC;QACnE,MAAM,cAAc,GAAG,IAAA,uCAAiB,EAAC,gBAAgB,CAAC,CAAC;QAC3D,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;QAC5D,MAAM,MAAM,GAAG,IAAA,iCAAc,EAAC,gBAAgB,CAAC,CAAC;QAChD,MAAM,MAAM,GACV,MAAA,MAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,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},
|
|
15
15
|
"homepage": "https://github.com/mongodb-js/compass",
|
|
16
|
-
"version": "0.
|
|
16
|
+
"version": "0.11.0",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "https://github.com/mongodb-js/compass.git"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"types": "./dist/index.d.ts",
|
|
35
35
|
"scripts": {
|
|
36
36
|
"bootstrap": "npm run compile",
|
|
37
|
-
"prepublishOnly": "npm run compile",
|
|
37
|
+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
|
|
38
38
|
"compile": "tsc -p tsconfig.json && gen-esm-wrapper . ./dist/.esm-wrapper.mjs",
|
|
39
39
|
"eslint": "eslint",
|
|
40
40
|
"prettier": "prettier",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"reformat": "npm run prettier -- --write ."
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"mongodb-explain-compat": "^2.
|
|
52
|
+
"mongodb-explain-compat": "^2.10.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@mongodb-js/eslint-config-compass": "^0.
|
|
56
|
-
"@mongodb-js/mocha-config-compass": "^0.
|
|
57
|
-
"@mongodb-js/prettier-config-compass": "^0.
|
|
58
|
-
"@mongodb-js/tsconfig-compass": "^0.
|
|
55
|
+
"@mongodb-js/eslint-config-compass": "^0.11.0",
|
|
56
|
+
"@mongodb-js/mocha-config-compass": "^0.12.0",
|
|
57
|
+
"@mongodb-js/prettier-config-compass": "^0.6.0",
|
|
58
|
+
"@mongodb-js/tsconfig-compass": "^0.7.0",
|
|
59
59
|
"@types/chai": "^4.2.21",
|
|
60
60
|
"@types/mocha": "^9.0.0",
|
|
61
61
|
"@types/sinon-chai": "^3.2.5",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"eslint": "^7.25.0",
|
|
65
65
|
"mocha": "^8.4.0",
|
|
66
66
|
"nyc": "^15.1.0",
|
|
67
|
-
"prettier": "2.
|
|
67
|
+
"prettier": "^2.7.1",
|
|
68
68
|
"sinon": "^9.2.3",
|
|
69
|
-
"typescript": "^4.
|
|
69
|
+
"typescript": "^4.7.4"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "9f5498524c3e50d351f6f36fb015ff14163a39cf"
|
|
72
72
|
}
|