@mongosh/types 1.10.0 → 1.10.2
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/.depcheckrc +14 -1
- package/.eslintrc.js +10 -1
- package/.prettierignore +6 -0
- package/.prettierrc.json +1 -0
- package/lib/index.js +14 -6
- package/lib/index.js.map +1 -1
- package/package.json +20 -10
- package/src/index.spec.ts +118 -39
- package/src/index.ts +93 -29
- package/tsconfig-lint.json +5 -0
- package/tsconfig.json +3 -7
- package/tsconfig.lint.json +0 -8
package/.depcheckrc
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
|
+
ignores:
|
|
2
|
+
- '@mongodb-js/eslint-config-mongosh'
|
|
3
|
+
- '@mongodb-js/tsconfig-mongosh'
|
|
4
|
+
- '@mongodb-js/prettier-config-devtools'
|
|
5
|
+
- '@typescript-eslint/parser'
|
|
6
|
+
- '@typescript-eslint/eslint-plugin'
|
|
7
|
+
- chai
|
|
8
|
+
- sinon-chai
|
|
9
|
+
- ts-sinon
|
|
10
|
+
- eslint-plugin-mocha
|
|
11
|
+
- eslint-config-mongodb-js
|
|
1
12
|
# needed as a peer dependency of @mongodb-js/devtools-connect
|
|
2
|
-
|
|
13
|
+
- mongodb
|
|
14
|
+
ignore-patterns:
|
|
15
|
+
- .eslintrc.js
|
package/.eslintrc.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
const { fixCygwinPath } = require('@mongodb-js/eslint-config-mongosh/utils');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
root: true,
|
|
5
|
+
extends: ['@mongodb-js/eslint-config-mongosh'],
|
|
6
|
+
parserOptions: {
|
|
7
|
+
tsconfigRootDir: fixCygwinPath(__dirname),
|
|
8
|
+
project: ['./tsconfig-lint.json'],
|
|
9
|
+
},
|
|
10
|
+
};
|
package/.prettierignore
ADDED
package/.prettierrc.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"@mongodb-js/prettier-config-devtools"
|
package/lib/index.js
CHANGED
|
@@ -52,7 +52,8 @@ class SnippetShellUserConfigValidator extends ShellUserConfigValidator {
|
|
|
52
52
|
static async validate(key, value) {
|
|
53
53
|
switch (key) {
|
|
54
54
|
case 'snippetIndexSourceURLs':
|
|
55
|
-
if (typeof value !== 'string' ||
|
|
55
|
+
if (typeof value !== 'string' ||
|
|
56
|
+
value.split(';').some((url) => url && !isValidUrl(url))) {
|
|
56
57
|
return `${key} must be a ;-separated list of valid URLs`;
|
|
57
58
|
}
|
|
58
59
|
return null;
|
|
@@ -98,7 +99,8 @@ class CliUserConfigValidator extends SnippetShellUserConfigValidator {
|
|
|
98
99
|
case 'disableGreetingMessage':
|
|
99
100
|
return null;
|
|
100
101
|
case 'inspectCompact':
|
|
101
|
-
if (typeof value !== 'boolean' &&
|
|
102
|
+
if (typeof value !== 'boolean' &&
|
|
103
|
+
(typeof value !== 'number' || value < 0)) {
|
|
102
104
|
return `${key} must be a boolean or a positive integer`;
|
|
103
105
|
}
|
|
104
106
|
return null;
|
|
@@ -115,22 +117,28 @@ class CliUserConfigValidator extends SnippetShellUserConfigValidator {
|
|
|
115
117
|
}
|
|
116
118
|
return null;
|
|
117
119
|
case 'redactHistory':
|
|
118
|
-
if (value !== 'keep' &&
|
|
120
|
+
if (value !== 'keep' &&
|
|
121
|
+
value !== 'remove' &&
|
|
122
|
+
value !== 'remove-redact') {
|
|
119
123
|
return `${key} must be one of 'keep', 'remove', or 'remove-redact'`;
|
|
120
124
|
}
|
|
121
125
|
return null;
|
|
122
126
|
case 'oidcRedirectURI':
|
|
123
|
-
if (value !== undefined &&
|
|
127
|
+
if (value !== undefined &&
|
|
128
|
+
(typeof value !== 'string' || !isValidUrl(value))) {
|
|
124
129
|
return `${key} must be undefined or a valid URL`;
|
|
125
130
|
}
|
|
126
131
|
return null;
|
|
127
132
|
case 'oidcTrustedEndpoints':
|
|
128
|
-
if (value !== undefined &&
|
|
133
|
+
if (value !== undefined &&
|
|
134
|
+
(!Array.isArray(value) || value.some((v) => typeof v !== 'string'))) {
|
|
129
135
|
return `${key} must be undefined or an array of hostnames`;
|
|
130
136
|
}
|
|
131
137
|
return null;
|
|
132
138
|
case 'browser':
|
|
133
|
-
if (value !== undefined &&
|
|
139
|
+
if (value !== undefined &&
|
|
140
|
+
value !== false &&
|
|
141
|
+
typeof value !== 'string') {
|
|
134
142
|
return `${key} must be undefined, false, or a command string`;
|
|
135
143
|
}
|
|
136
144
|
return null;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAiXA,MAAa,eAAe;IAA5B;QACE,qBAAgB,GAAG,EAAE,CAAC;QACtB,cAAS,GAAkB,IAAI,CAAC;QAChC,oBAAe,GAAG,KAAK,CAAC;QACxB,WAAM,GAAkB,IAAI,CAAC;IAC/B,CAAC;CAAA;AALD,0CAKC;AAED,MAAa,wBAAwB;IAEnC,MAAM,CAAC,KAAK,CAAC,QAAQ,CACnB,GAAM,EACN,KAAyB;QAEzB,QAAQ,GAAG,EAAE;YACX,KAAK,kBAAkB;gBACrB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,CAAC,EAAE;oBAC3C,OAAO,GAAG,GAAG,6BAA6B,CAAC;iBAC5C;gBACD,OAAO,IAAI,CAAC;YACd,KAAK,WAAW;gBACd,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,CAAC,CAAC,EAAE;oBAC/D,OAAO,GAAG,GAAG,qCAAqC,CAAC;iBACpD;gBACD,OAAO,IAAI,CAAC;YACd,KAAK,iBAAiB;gBACpB,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;oBAC9B,OAAO,GAAG,GAAG,oBAAo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
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongosh/types",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"description": "Types for mongosh internals",
|
|
5
5
|
"author": "Anna Henningsen <anna.henningsen@mongodb.com>",
|
|
6
6
|
"homepage": "https://github.com/mongodb-js/mongosh/tree/main/packages/types#readme",
|
|
@@ -18,12 +18,16 @@
|
|
|
18
18
|
"url": "git+https://github.com/mongodb-js/mongosh.git"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"check": "npm run lint",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
21
|
+
"check": "npm run lint && npm run depcheck",
|
|
22
|
+
"depcheck": "depcheck",
|
|
23
|
+
"compile": "tsc -p tsconfig.json",
|
|
24
|
+
"eslint": "eslint",
|
|
25
|
+
"lint": "npm run eslint . && npm run prettier -- --check .",
|
|
26
|
+
"prepublish": "npm run compile",
|
|
25
27
|
"test": "mocha --timeout 15000 -r ts-node/register \"./src/*.spec.ts\"",
|
|
26
|
-
"test-ci": "node ../../scripts/run-if-package-requested.js npm test"
|
|
28
|
+
"test-ci": "node ../../scripts/run-if-package-requested.js npm test",
|
|
29
|
+
"prettier": "prettier",
|
|
30
|
+
"reformat": "npm run prettier -- --write . && npm run eslint --fix"
|
|
27
31
|
},
|
|
28
32
|
"bugs": {
|
|
29
33
|
"url": "https://github.com/mongodb-js/mongosh/issues"
|
|
@@ -32,10 +36,16 @@
|
|
|
32
36
|
"unitTestsOnly": true
|
|
33
37
|
},
|
|
34
38
|
"dependencies": {
|
|
35
|
-
"@mongodb-js/devtools-connect": "^2.1
|
|
39
|
+
"@mongodb-js/devtools-connect": "^2.2.1"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
|
-
"mongodb": "
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
"@mongodb-js/eslint-config-mongosh": "1.10.2",
|
|
43
|
+
"@mongodb-js/prettier-config-devtools": "^1.0.1",
|
|
44
|
+
"@mongodb-js/tsconfig-mongosh": "1.10.2",
|
|
45
|
+
"depcheck": "^1.4.3",
|
|
46
|
+
"eslint": "^7.25.0",
|
|
47
|
+
"mongodb": "^5.7.0",
|
|
48
|
+
"prettier": "^2.8.8"
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "9351a54cc24def10a97fe7f8c7b455c02fdce62e"
|
|
41
51
|
}
|
package/src/index.spec.ts
CHANGED
|
@@ -1,81 +1,160 @@
|
|
|
1
1
|
import { CliUserConfig, CliUserConfigValidator } from './';
|
|
2
2
|
import { expect } from 'chai';
|
|
3
3
|
|
|
4
|
-
describe('config validation', ()
|
|
5
|
-
it('validates config option values', async()
|
|
4
|
+
describe('config validation', function () {
|
|
5
|
+
it('validates config option values', async function () {
|
|
6
6
|
const { validate } = CliUserConfigValidator as any;
|
|
7
7
|
expect(await validate('userId', 'foo')).to.equal(null);
|
|
8
8
|
expect(await validate('telemetryAnonymousId', 'foo')).to.equal(null);
|
|
9
9
|
expect(await validate('disableGreetingMessage', 'foo')).to.equal(null);
|
|
10
|
-
expect(await validate('inspectDepth', 'foo')).to.equal(
|
|
11
|
-
|
|
10
|
+
expect(await validate('inspectDepth', 'foo')).to.equal(
|
|
11
|
+
'inspectDepth must be a positive integer'
|
|
12
|
+
);
|
|
13
|
+
expect(await validate('inspectDepth', -1)).to.equal(
|
|
14
|
+
'inspectDepth must be a positive integer'
|
|
15
|
+
);
|
|
12
16
|
expect(await validate('inspectDepth', 0)).to.equal(null);
|
|
13
17
|
expect(await validate('inspectDepth', 1)).to.equal(null);
|
|
14
18
|
expect(await validate('inspectDepth', Infinity)).to.equal(null);
|
|
15
|
-
expect(await validate('historyLength', 'foo')).to.equal(
|
|
16
|
-
|
|
19
|
+
expect(await validate('historyLength', 'foo')).to.equal(
|
|
20
|
+
'historyLength must be a positive integer'
|
|
21
|
+
);
|
|
22
|
+
expect(await validate('historyLength', -1)).to.equal(
|
|
23
|
+
'historyLength must be a positive integer'
|
|
24
|
+
);
|
|
17
25
|
expect(await validate('historyLength', 0)).to.equal(null);
|
|
18
26
|
expect(await validate('historyLength', 1)).to.equal(null);
|
|
19
27
|
expect(await validate('historyLength', Infinity)).to.equal(null);
|
|
20
|
-
expect(await validate('showStackTraces', 'foo')).to.equal(
|
|
21
|
-
|
|
28
|
+
expect(await validate('showStackTraces', 'foo')).to.equal(
|
|
29
|
+
'showStackTraces must be a boolean'
|
|
30
|
+
);
|
|
31
|
+
expect(await validate('showStackTraces', -1)).to.equal(
|
|
32
|
+
'showStackTraces must be a boolean'
|
|
33
|
+
);
|
|
22
34
|
expect(await validate('showStackTraces', false)).to.equal(null);
|
|
23
35
|
expect(await validate('showStackTraces', true)).to.equal(null);
|
|
24
|
-
expect(await validate('redactHistory', 'foo')).to.equal(
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
expect(await validate('redactHistory', 'foo')).to.equal(
|
|
37
|
+
"redactHistory must be one of 'keep', 'remove', or 'remove-redact'"
|
|
38
|
+
);
|
|
39
|
+
expect(await validate('redactHistory', -1)).to.equal(
|
|
40
|
+
"redactHistory must be one of 'keep', 'remove', or 'remove-redact'"
|
|
41
|
+
);
|
|
42
|
+
expect(await validate('redactHistory', false)).to.equal(
|
|
43
|
+
"redactHistory must be one of 'keep', 'remove', or 'remove-redact'"
|
|
44
|
+
);
|
|
27
45
|
expect(await validate('redactHistory', 'keep')).to.equal(null);
|
|
28
46
|
expect(await validate('redactHistory', 'remove')).to.equal(null);
|
|
29
47
|
expect(await validate('redactHistory', 'remove-redact')).to.equal(null);
|
|
30
|
-
expect(await validate('displayBatchSize', 'foo')).to.equal(
|
|
31
|
-
|
|
32
|
-
|
|
48
|
+
expect(await validate('displayBatchSize', 'foo')).to.equal(
|
|
49
|
+
'displayBatchSize must be a positive integer'
|
|
50
|
+
);
|
|
51
|
+
expect(await validate('displayBatchSize', -1)).to.equal(
|
|
52
|
+
'displayBatchSize must be a positive integer'
|
|
53
|
+
);
|
|
54
|
+
expect(await validate('displayBatchSize', 0)).to.equal(
|
|
55
|
+
'displayBatchSize must be a positive integer'
|
|
56
|
+
);
|
|
33
57
|
expect(await validate('displayBatchSize', 1)).to.equal(null);
|
|
34
58
|
expect(await validate('displayBatchSize', Infinity)).to.equal(null);
|
|
35
|
-
expect(await validate('maxTimeMS', 'foo')).to.equal(
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
expect(await validate('maxTimeMS', 'foo')).to.equal(
|
|
60
|
+
'maxTimeMS must be null or a positive integer'
|
|
61
|
+
);
|
|
62
|
+
expect(await validate('maxTimeMS', -1)).to.equal(
|
|
63
|
+
'maxTimeMS must be null or a positive integer'
|
|
64
|
+
);
|
|
65
|
+
expect(await validate('maxTimeMS', 0)).to.equal(
|
|
66
|
+
'maxTimeMS must be null or a positive integer'
|
|
67
|
+
);
|
|
38
68
|
expect(await validate('maxTimeMS', 1)).to.equal(null);
|
|
39
69
|
expect(await validate('maxTimeMS', null)).to.equal(null);
|
|
40
|
-
expect(await validate('enableTelemetry', 'foo')).to.equal(
|
|
41
|
-
|
|
70
|
+
expect(await validate('enableTelemetry', 'foo')).to.equal(
|
|
71
|
+
'enableTelemetry must be a boolean'
|
|
72
|
+
);
|
|
73
|
+
expect(await validate('enableTelemetry', -1)).to.equal(
|
|
74
|
+
'enableTelemetry must be a boolean'
|
|
75
|
+
);
|
|
42
76
|
expect(await validate('enableTelemetry', false)).to.equal(null);
|
|
43
77
|
expect(await validate('enableTelemetry', true)).to.equal(null);
|
|
44
|
-
expect(await validate('inspectCompact', 'foo')).to.equal(
|
|
45
|
-
|
|
78
|
+
expect(await validate('inspectCompact', 'foo')).to.equal(
|
|
79
|
+
'inspectCompact must be a boolean or a positive integer'
|
|
80
|
+
);
|
|
81
|
+
expect(await validate('inspectCompact', -1)).to.equal(
|
|
82
|
+
'inspectCompact must be a boolean or a positive integer'
|
|
83
|
+
);
|
|
46
84
|
expect(await validate('inspectCompact', false)).to.equal(null);
|
|
47
85
|
expect(await validate('inspectCompact', true)).to.equal(null);
|
|
48
86
|
expect(await validate('inspectCompact', 32)).to.equal(null);
|
|
49
|
-
expect(
|
|
50
|
-
|
|
51
|
-
|
|
87
|
+
expect(
|
|
88
|
+
await validate('snippetIndexSourceURLs', 'https://example.com/')
|
|
89
|
+
).to.equal(null);
|
|
90
|
+
expect(await validate('snippetIndexSourceURLs', 'foo')).to.equal(
|
|
91
|
+
'snippetIndexSourceURLs must be a ;-separated list of valid URLs'
|
|
92
|
+
);
|
|
93
|
+
expect(
|
|
94
|
+
await validate('snippetIndexSourceURLs', 'https://xyz/;foo')
|
|
95
|
+
).to.equal(
|
|
96
|
+
'snippetIndexSourceURLs must be a ;-separated list of valid URLs'
|
|
97
|
+
);
|
|
52
98
|
expect(await validate('snippetIndexSourceURLs', ';')).to.equal(null);
|
|
53
|
-
expect(await validate('snippetIndexSourceURLs', 0)).to.equal(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
expect(await validate('snippetRegistryURL',
|
|
57
|
-
|
|
58
|
-
|
|
99
|
+
expect(await validate('snippetIndexSourceURLs', 0)).to.equal(
|
|
100
|
+
'snippetIndexSourceURLs must be a ;-separated list of valid URLs'
|
|
101
|
+
);
|
|
102
|
+
expect(await validate('snippetRegistryURL', ';')).to.equal(
|
|
103
|
+
'snippetRegistryURL must be a valid URL'
|
|
104
|
+
);
|
|
105
|
+
expect(
|
|
106
|
+
await validate('snippetRegistryURL', 'https://registry.npmjs.org')
|
|
107
|
+
).to.equal(null);
|
|
108
|
+
expect(await validate('snippetRegistryURL', 0)).to.equal(
|
|
109
|
+
'snippetRegistryURL must be a valid URL'
|
|
110
|
+
);
|
|
111
|
+
expect(await validate('snippetAutoload', 'foo')).to.equal(
|
|
112
|
+
'snippetAutoload must be a boolean'
|
|
113
|
+
);
|
|
114
|
+
expect(await validate('snippetAutoload', -1)).to.equal(
|
|
115
|
+
'snippetAutoload must be a boolean'
|
|
116
|
+
);
|
|
59
117
|
expect(await validate('snippetAutoload', false)).to.equal(null);
|
|
60
118
|
expect(await validate('snippetAutoload', true)).to.equal(null);
|
|
61
|
-
expect(
|
|
119
|
+
expect(
|
|
120
|
+
await validate('oidcRedirectURI', 'http://localhost:123456/foo')
|
|
121
|
+
).to.equal('oidcRedirectURI must be undefined or a valid URL');
|
|
62
122
|
expect(await validate('oidcRedirectURI', undefined)).to.equal(null);
|
|
63
|
-
expect(await validate('oidcRedirectURI', 'http://localhost:0/')).to.equal(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
expect(
|
|
67
|
-
|
|
123
|
+
expect(await validate('oidcRedirectURI', 'http://localhost:0/')).to.equal(
|
|
124
|
+
null
|
|
125
|
+
);
|
|
126
|
+
expect(
|
|
127
|
+
await validate('oidcRedirectURI', 'http://localhost:12345/foo')
|
|
128
|
+
).to.equal(null);
|
|
129
|
+
expect(await validate('oidcTrustedEndpoints', 'localhost')).to.equal(
|
|
130
|
+
'oidcTrustedEndpoints must be undefined or an array of hostnames'
|
|
131
|
+
);
|
|
132
|
+
expect(await validate('oidcTrustedEndpoints', [1, 2, 3])).to.equal(
|
|
133
|
+
'oidcTrustedEndpoints must be undefined or an array of hostnames'
|
|
134
|
+
);
|
|
135
|
+
expect(
|
|
136
|
+
await validate('oidcTrustedEndpoints', [
|
|
137
|
+
'::1',
|
|
138
|
+
'127.0.0.1',
|
|
139
|
+
'foo.bar.com',
|
|
140
|
+
'*.net',
|
|
141
|
+
])
|
|
142
|
+
).to.equal(null);
|
|
68
143
|
expect(await validate('oidcTrustedEndpoints', undefined)).to.equal(null);
|
|
69
|
-
expect(await validate('browser', 1234)).to.equal(
|
|
144
|
+
expect(await validate('browser', 1234)).to.equal(
|
|
145
|
+
'browser must be undefined, false, or a command string'
|
|
146
|
+
);
|
|
70
147
|
expect(await validate('browser', undefined)).to.equal(null);
|
|
71
148
|
expect(await validate('browser', false)).to.equal(null);
|
|
72
149
|
expect(await validate('browser', 'foo bar')).to.equal(null);
|
|
73
150
|
});
|
|
74
151
|
|
|
75
|
-
it('allows default CliUserConfig values', async()
|
|
152
|
+
it('allows default CliUserConfig values', async function () {
|
|
76
153
|
const userConfig = new CliUserConfig();
|
|
77
154
|
for (const key of Object.keys(userConfig) as (keyof CliUserConfig)[]) {
|
|
78
|
-
expect(
|
|
155
|
+
expect(
|
|
156
|
+
await CliUserConfigValidator.validate(key, userConfig[key])
|
|
157
|
+
).to.equal(null);
|
|
79
158
|
}
|
|
80
159
|
});
|
|
81
160
|
});
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint camelcase: 0 */
|
|
2
1
|
import type { ConnectEventMap } from '@mongodb-js/devtools-connect';
|
|
3
2
|
|
|
4
3
|
export interface ApiEventArguments {
|
|
@@ -175,11 +174,17 @@ export interface MongoshBusEventsMap extends ConnectEventMap {
|
|
|
175
174
|
/**
|
|
176
175
|
* Signals that the shell is started by a new user.
|
|
177
176
|
*/
|
|
178
|
-
'mongosh:new-user': (identity: {
|
|
177
|
+
'mongosh:new-user': (identity: {
|
|
178
|
+
userId: string;
|
|
179
|
+
anonymousId: string;
|
|
180
|
+
}) => void;
|
|
179
181
|
/**
|
|
180
182
|
* Signals a change of the user telemetry settings.
|
|
181
183
|
*/
|
|
182
|
-
'mongosh:update-user': (identity: {
|
|
184
|
+
'mongosh:update-user': (identity: {
|
|
185
|
+
userId: string;
|
|
186
|
+
anonymousId?: string;
|
|
187
|
+
}) => void;
|
|
183
188
|
/**
|
|
184
189
|
* Signals an error that should be logged or potentially tracked by analytics.
|
|
185
190
|
*/
|
|
@@ -232,7 +237,9 @@ export interface MongoshBusEventsMap extends ConnectEventMap {
|
|
|
232
237
|
/**
|
|
233
238
|
* Signals the start of loading external files upon startup.
|
|
234
239
|
*/
|
|
235
|
-
'mongosh:start-loading-cli-scripts': (
|
|
240
|
+
'mongosh:start-loading-cli-scripts': (
|
|
241
|
+
event: StartLoadingCliScriptsEvent
|
|
242
|
+
) => void;
|
|
236
243
|
/**
|
|
237
244
|
* Signals the successful startup of the mongosh REPL after initial files and configuration
|
|
238
245
|
* have been loaded.
|
|
@@ -299,15 +306,21 @@ export interface MongoshBusEventsMap extends ConnectEventMap {
|
|
|
299
306
|
/** Signals that attempting to download npm has been declined by the user. */
|
|
300
307
|
'mongosh-snippets:npm-lookup-stopped': () => void;
|
|
301
308
|
/** Signals that attempting to download npm has failed. */
|
|
302
|
-
'mongosh-snippets:npm-download-failed': (
|
|
309
|
+
'mongosh-snippets:npm-download-failed': (
|
|
310
|
+
ev: SnippetsNpmDownloadFailedEvent
|
|
311
|
+
) => void;
|
|
303
312
|
/** Signals that downloading the npm tarball has started. */
|
|
304
|
-
'mongosh-snippets:npm-download-active': (
|
|
313
|
+
'mongosh-snippets:npm-download-active': (
|
|
314
|
+
ev: SnippetsNpmDownloadActiveEvent
|
|
315
|
+
) => void;
|
|
305
316
|
/** Signals that fetching the index file from the network has started. */
|
|
306
317
|
'mongosh-snippets:fetch-index': (ev: SnippetsFetchIndexEvent) => void;
|
|
307
318
|
/** Signals that, when fetching the index file, it turned out that the cache is currently invalid (not outdated). */
|
|
308
319
|
'mongosh-snippets:fetch-cache-invalid': () => void;
|
|
309
320
|
/** Signals that fetching the index file from the network has failed. */
|
|
310
|
-
'mongosh-snippets:fetch-index-error': (
|
|
321
|
+
'mongosh-snippets:fetch-index-error': (
|
|
322
|
+
ev: SnippetsFetchIndexErrorEvent
|
|
323
|
+
) => void;
|
|
311
324
|
/** Signals that fetching the index file from the network has completed. */
|
|
312
325
|
'mongosh-snippets:fetch-index-done': () => void;
|
|
313
326
|
/** Signals that an action on the internal package.json file has failed. */
|
|
@@ -327,16 +340,31 @@ export interface MongoshBusEventsMap extends ConnectEventMap {
|
|
|
327
340
|
/** Signals that open external editor command was called. */
|
|
328
341
|
'mongosh-editor:run-edit-command': (ev: EditorRunEditCommandEvent) => void;
|
|
329
342
|
/** Signals that reading vscode extensions from disc succeeded. */
|
|
330
|
-
'mongosh-editor:read-vscode-extensions-done': (
|
|
343
|
+
'mongosh-editor:read-vscode-extensions-done': (
|
|
344
|
+
ev: EditorReadVscodeExtensionsDoneEvent
|
|
345
|
+
) => void;
|
|
331
346
|
/** Signals that reading vscode extensions from disc failed. */
|
|
332
|
-
'mongosh-editor:read-vscode-extensions-failed': (
|
|
347
|
+
'mongosh-editor:read-vscode-extensions-failed': (
|
|
348
|
+
ev: EditorReadVscodeExtensionsFailedEvent
|
|
349
|
+
) => void;
|
|
333
350
|
}
|
|
334
351
|
|
|
335
352
|
export interface MongoshBus {
|
|
336
353
|
// TypeScript uses something like this itself for its EventTarget definitions.
|
|
337
|
-
on<K extends keyof MongoshBusEventsMap>(
|
|
338
|
-
|
|
339
|
-
|
|
354
|
+
on<K extends keyof MongoshBusEventsMap>(
|
|
355
|
+
event: K,
|
|
356
|
+
listener: MongoshBusEventsMap[K]
|
|
357
|
+
): this;
|
|
358
|
+
once<K extends keyof MongoshBusEventsMap>(
|
|
359
|
+
event: K,
|
|
360
|
+
listener: MongoshBusEventsMap[K]
|
|
361
|
+
): this;
|
|
362
|
+
emit<K extends keyof MongoshBusEventsMap>(
|
|
363
|
+
event: K,
|
|
364
|
+
...args: MongoshBusEventsMap[K] extends (...args: infer P) => any
|
|
365
|
+
? P
|
|
366
|
+
: never
|
|
367
|
+
): unknown;
|
|
340
368
|
}
|
|
341
369
|
|
|
342
370
|
export class ShellUserConfig {
|
|
@@ -347,8 +375,11 @@ export class ShellUserConfig {
|
|
|
347
375
|
}
|
|
348
376
|
|
|
349
377
|
export class ShellUserConfigValidator {
|
|
350
|
-
// eslint-disable-next-line
|
|
351
|
-
static async validate<K extends keyof ShellUserConfig>(
|
|
378
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
379
|
+
static async validate<K extends keyof ShellUserConfig>(
|
|
380
|
+
key: K,
|
|
381
|
+
value: ShellUserConfig[K]
|
|
382
|
+
): Promise<string | null> {
|
|
352
383
|
switch (key) {
|
|
353
384
|
case 'displayBatchSize':
|
|
354
385
|
if (typeof value !== 'number' || value <= 0) {
|
|
@@ -377,16 +408,23 @@ export class ShellUserConfigValidator {
|
|
|
377
408
|
}
|
|
378
409
|
|
|
379
410
|
export class SnippetShellUserConfig extends ShellUserConfig {
|
|
380
|
-
snippetIndexSourceURLs =
|
|
411
|
+
snippetIndexSourceURLs =
|
|
412
|
+
'https://compass.mongodb.com/mongosh/snippets-index.bson.br';
|
|
381
413
|
snippetRegistryURL = 'https://registry.npmjs.org';
|
|
382
414
|
snippetAutoload = true;
|
|
383
415
|
}
|
|
384
416
|
|
|
385
417
|
export class SnippetShellUserConfigValidator extends ShellUserConfigValidator {
|
|
386
|
-
static async validate<K extends keyof SnippetShellUserConfig>(
|
|
418
|
+
static async validate<K extends keyof SnippetShellUserConfig>(
|
|
419
|
+
key: K,
|
|
420
|
+
value: SnippetShellUserConfig[K]
|
|
421
|
+
): Promise<string | null> {
|
|
387
422
|
switch (key) {
|
|
388
423
|
case 'snippetIndexSourceURLs':
|
|
389
|
-
if (
|
|
424
|
+
if (
|
|
425
|
+
typeof value !== 'string' ||
|
|
426
|
+
value.split(';').some((url) => url && !isValidUrl(url))
|
|
427
|
+
) {
|
|
390
428
|
return `${key} must be a ;-separated list of valid URLs`;
|
|
391
429
|
}
|
|
392
430
|
return null;
|
|
@@ -422,15 +460,20 @@ export class CliUserConfig extends SnippetShellUserConfig {
|
|
|
422
460
|
}
|
|
423
461
|
|
|
424
462
|
export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
|
|
425
|
-
|
|
426
|
-
|
|
463
|
+
static async validate<K extends keyof CliUserConfig>(
|
|
464
|
+
key: K,
|
|
465
|
+
value: CliUserConfig[K]
|
|
466
|
+
): Promise<string | null> {
|
|
427
467
|
switch (key) {
|
|
428
468
|
case 'userId':
|
|
429
469
|
case 'telemetryAnonymousId':
|
|
430
470
|
case 'disableGreetingMessage':
|
|
431
471
|
return null; // Not modifiable by the user anyway.
|
|
432
472
|
case 'inspectCompact':
|
|
433
|
-
if (
|
|
473
|
+
if (
|
|
474
|
+
typeof value !== 'boolean' &&
|
|
475
|
+
(typeof value !== 'number' || value < 0)
|
|
476
|
+
) {
|
|
434
477
|
return `${key} must be a boolean or a positive integer`;
|
|
435
478
|
}
|
|
436
479
|
return null;
|
|
@@ -447,41 +490,63 @@ export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
|
|
|
447
490
|
}
|
|
448
491
|
return null;
|
|
449
492
|
case 'redactHistory':
|
|
450
|
-
if (
|
|
493
|
+
if (
|
|
494
|
+
value !== 'keep' &&
|
|
495
|
+
value !== 'remove' &&
|
|
496
|
+
value !== 'remove-redact'
|
|
497
|
+
) {
|
|
451
498
|
return `${key} must be one of 'keep', 'remove', or 'remove-redact'`;
|
|
452
499
|
}
|
|
453
500
|
return null;
|
|
454
501
|
case 'oidcRedirectURI':
|
|
455
|
-
if (
|
|
502
|
+
if (
|
|
503
|
+
value !== undefined &&
|
|
504
|
+
(typeof value !== 'string' || !isValidUrl(value))
|
|
505
|
+
) {
|
|
456
506
|
return `${key} must be undefined or a valid URL`;
|
|
457
507
|
}
|
|
458
508
|
return null;
|
|
459
509
|
case 'oidcTrustedEndpoints':
|
|
460
|
-
if (
|
|
510
|
+
if (
|
|
511
|
+
value !== undefined &&
|
|
512
|
+
(!Array.isArray(value) || value.some((v) => typeof v !== 'string'))
|
|
513
|
+
) {
|
|
461
514
|
return `${key} must be undefined or an array of hostnames`;
|
|
462
515
|
}
|
|
463
516
|
return null;
|
|
464
517
|
case 'browser':
|
|
465
|
-
if (
|
|
518
|
+
if (
|
|
519
|
+
value !== undefined &&
|
|
520
|
+
value !== false &&
|
|
521
|
+
typeof value !== 'string'
|
|
522
|
+
) {
|
|
466
523
|
return `${key} must be undefined, false, or a command string`;
|
|
467
524
|
}
|
|
468
525
|
return null;
|
|
469
526
|
default:
|
|
470
|
-
return super.validate(
|
|
527
|
+
return super.validate(
|
|
528
|
+
key as keyof SnippetShellUserConfig,
|
|
529
|
+
value as any
|
|
530
|
+
);
|
|
471
531
|
}
|
|
472
532
|
}
|
|
473
533
|
}
|
|
474
534
|
|
|
475
535
|
export interface ConfigProvider<T> {
|
|
476
536
|
getConfig<K extends keyof T>(key: K): Promise<T[K]>;
|
|
477
|
-
setConfig<K extends keyof T>(
|
|
537
|
+
setConfig<K extends keyof T>(
|
|
538
|
+
key: K,
|
|
539
|
+
value: T[K]
|
|
540
|
+
): Promise<'success' | 'ignored'>;
|
|
478
541
|
resetConfig<K extends keyof T>(key: K): Promise<'success' | 'ignored'>;
|
|
479
|
-
validateConfig<K extends keyof T>(
|
|
542
|
+
validateConfig<K extends keyof T>(
|
|
543
|
+
key: K,
|
|
544
|
+
value: T[K]
|
|
545
|
+
): Promise<string | null>;
|
|
480
546
|
listConfigOptions(): string[] | Promise<string[]>;
|
|
481
547
|
}
|
|
482
548
|
|
|
483
549
|
function isValidUrl(url: string): boolean {
|
|
484
|
-
/* eslint-disable no-new */
|
|
485
550
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
486
551
|
// Need ts-ignore because we're not building this exclusively for environments
|
|
487
552
|
// in which URL is available.
|
|
@@ -495,7 +560,6 @@ function isValidUrl(url: string): boolean {
|
|
|
495
560
|
return false;
|
|
496
561
|
}
|
|
497
562
|
}
|
|
498
|
-
/* eslint-enable no-new */
|
|
499
563
|
/* eslint-enable @typescript-eslint/ban-ts-comment */
|
|
500
564
|
return true; // Currently no overlap between URL-less environments and environments with config options.
|
|
501
565
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "
|
|
2
|
+
"extends": "@mongodb-js/tsconfig-mongosh/tsconfig.common.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"outDir": "./lib",
|
|
5
5
|
"allowJs": true
|
|
6
6
|
},
|
|
7
|
-
"include": [
|
|
8
|
-
|
|
9
|
-
],
|
|
10
|
-
"exclude": [
|
|
11
|
-
"./src/**/*.spec.*"
|
|
12
|
-
]
|
|
7
|
+
"include": ["src/**/*"],
|
|
8
|
+
"exclude": ["./src/**/*.spec.*"]
|
|
13
9
|
}
|