@qp-mongosh/types 0.0.0-dev.28 → 0.0.0-dev.29

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/lib/index.d.ts ADDED
@@ -0,0 +1,236 @@
1
+ import type { ConnectEventMap } from '@mongodb-js/devtools-connect';
2
+ export interface ApiEventArguments {
3
+ pipeline?: any[];
4
+ query?: object;
5
+ options?: object;
6
+ filter?: object;
7
+ }
8
+ export interface ApiEventWithArguments {
9
+ method: string;
10
+ class?: string;
11
+ db?: string;
12
+ coll?: string;
13
+ uri?: string;
14
+ arguments?: ApiEventArguments;
15
+ }
16
+ export interface ApiEvent {
17
+ method: string;
18
+ class: string;
19
+ deprecated: boolean;
20
+ isAsync: boolean;
21
+ callDepth: number;
22
+ }
23
+ export interface ApiWarning {
24
+ method: string;
25
+ class: string;
26
+ message: string;
27
+ }
28
+ export interface UseEvent {
29
+ db: string;
30
+ }
31
+ export interface EvaluateInputEvent {
32
+ input: string;
33
+ }
34
+ export interface ShowEvent {
35
+ method: string;
36
+ }
37
+ export interface ConnectEvent {
38
+ is_atlas: boolean;
39
+ is_localhost: boolean;
40
+ is_do: boolean;
41
+ server_version: string;
42
+ server_os?: string;
43
+ server_arch?: string;
44
+ is_enterprise: boolean;
45
+ auth_type?: string;
46
+ is_data_lake: boolean;
47
+ dl_version?: string;
48
+ is_genuine: boolean;
49
+ non_genuine_server_name: string;
50
+ api_version?: string;
51
+ api_strict?: boolean;
52
+ api_deprecation_errors?: boolean;
53
+ node_version: string;
54
+ uri: string;
55
+ }
56
+ export interface ScriptLoadFileEvent {
57
+ nested: boolean;
58
+ filename: string;
59
+ }
60
+ export interface StartLoadingCliScriptsEvent {
61
+ usesShellOption: boolean;
62
+ }
63
+ export interface GlobalConfigFileLoadEvent {
64
+ filename: string;
65
+ found: boolean;
66
+ }
67
+ export interface MongocryptdTrySpawnEvent {
68
+ spawnPath: string[];
69
+ path: string;
70
+ }
71
+ export interface MongocryptdErrorEvent {
72
+ cause: string;
73
+ error?: Error;
74
+ stderr?: string;
75
+ pid?: number;
76
+ }
77
+ export interface MongocryptdLogEvent {
78
+ pid: number;
79
+ logEntry: any;
80
+ }
81
+ export interface StartMongoshReplEvent {
82
+ version: string;
83
+ }
84
+ export interface SnippetsLoadedEvent {
85
+ installdir: string;
86
+ }
87
+ export interface SnippetsNpmLookupEvent {
88
+ existingVersion: string;
89
+ }
90
+ export interface SnippetsNpmDownloadActiveEvent {
91
+ npmMetadataURL: string;
92
+ npmTarballURL: string;
93
+ }
94
+ export interface SnippetsNpmDownloadFailedEvent {
95
+ npmMetadataURL: string;
96
+ npmTarballURL?: string;
97
+ status?: number;
98
+ }
99
+ export interface SnippetsFetchIndexEvent {
100
+ refreshMode: string;
101
+ }
102
+ export interface SnippetsFetchIndexErrorEvent {
103
+ action: string;
104
+ url?: string;
105
+ status?: number;
106
+ error?: string;
107
+ }
108
+ export interface SnippetsErrorEvent {
109
+ error: string;
110
+ }
111
+ export interface SnippetsRunNpmEvent {
112
+ args: string[];
113
+ }
114
+ export interface SnippetsLoadSnippetEvent {
115
+ source: string;
116
+ name: string;
117
+ }
118
+ export interface SnippetsCommandEvent {
119
+ args: string[];
120
+ }
121
+ export interface SnippetsTransformErrorEvent {
122
+ error: string;
123
+ addition: string;
124
+ name: string;
125
+ }
126
+ export interface EditorRunEditCommandEvent {
127
+ tmpDoc: string;
128
+ editor: string;
129
+ code: string;
130
+ }
131
+ export interface EditorReadVscodeExtensionsDoneEvent {
132
+ vscodeDir: string;
133
+ hasMongodbExtension: boolean;
134
+ }
135
+ export interface EditorReadVscodeExtensionsFailedEvent {
136
+ vscodeDir: string;
137
+ error: Error;
138
+ }
139
+ export interface MongoshBusEventsMap extends ConnectEventMap {
140
+ 'mongosh:connect': (ev: ConnectEvent) => void;
141
+ 'mongosh:new-user': (identity: {
142
+ userId: string;
143
+ anonymousId: string;
144
+ }) => void;
145
+ 'mongosh:update-user': (identity: {
146
+ userId: string;
147
+ anonymousId?: string;
148
+ }) => void;
149
+ 'mongosh:error': (error: Error, component: string) => void;
150
+ 'mongosh:evaluate-input': (ev: EvaluateInputEvent) => void;
151
+ 'mongosh:evaluate-started': () => void;
152
+ 'mongosh:evaluate-finished': () => void;
153
+ 'mongosh:use': (ev: UseEvent) => void;
154
+ 'mongosh:getDB': (ev: UseEvent) => void;
155
+ 'mongosh:show': (ev: ShowEvent) => void;
156
+ 'mongosh:setCtx': (ev: ApiEventWithArguments) => void;
157
+ 'mongosh:api-call-with-arguments': (ev: ApiEventWithArguments) => void;
158
+ 'mongosh:api-call': (ev: ApiEvent) => void;
159
+ 'mongosh:warn': (ev: ApiWarning) => void;
160
+ 'mongosh:api-load-file': (ev: ScriptLoadFileEvent) => void;
161
+ 'mongosh:start-loading-cli-scripts': (event: StartLoadingCliScriptsEvent) => void;
162
+ 'mongosh:start-mongosh-repl': (ev: StartMongoshReplEvent) => void;
163
+ 'mongosh:mongoshrc-load': () => void;
164
+ 'mongosh:globalconfig-load': (ev: GlobalConfigFileLoadEvent) => void;
165
+ 'mongosh:mongoshrc-mongorc-warn': () => void;
166
+ 'mongosh:eval-cli-script': () => void;
167
+ 'mongosh:eval-interrupted': () => void;
168
+ 'mongosh:mongocryptd-tryspawn': (ev: MongocryptdTrySpawnEvent) => void;
169
+ 'mongosh:mongocryptd-error': (ev: MongocryptdErrorEvent) => void;
170
+ 'mongosh:mongocryptd-log': (ev: MongocryptdLogEvent) => void;
171
+ 'mongosh:closed': () => void;
172
+ 'mongosh:eval-complete': () => void;
173
+ 'mongosh:autocompletion-complete': () => void;
174
+ 'mongosh:interrupt-complete': () => void;
175
+ 'mongosh-snippets:loaded': (ev: SnippetsLoadedEvent) => void;
176
+ 'mongosh-snippets:npm-lookup': (ev: SnippetsNpmLookupEvent) => void;
177
+ 'mongosh-snippets:npm-lookup-stopped': () => void;
178
+ 'mongosh-snippets:npm-download-failed': (ev: SnippetsNpmDownloadFailedEvent) => void;
179
+ 'mongosh-snippets:npm-download-active': (ev: SnippetsNpmDownloadActiveEvent) => void;
180
+ 'mongosh-snippets:fetch-index': (ev: SnippetsFetchIndexEvent) => void;
181
+ 'mongosh-snippets:fetch-cache-invalid': () => void;
182
+ 'mongosh-snippets:fetch-index-error': (ev: SnippetsFetchIndexErrorEvent) => void;
183
+ 'mongosh-snippets:fetch-index-done': () => void;
184
+ 'mongosh-snippets:package-json-edit-error': (ev: SnippetsErrorEvent) => void;
185
+ 'mongosh-snippets:spawn-child': (ev: SnippetsRunNpmEvent) => void;
186
+ 'mongosh-snippets:load-snippet': (ev: SnippetsLoadSnippetEvent) => void;
187
+ 'mongosh-snippets:snippet-command': (ev: SnippetsCommandEvent) => void;
188
+ 'mongosh-snippets:transform-error': (ev: SnippetsTransformErrorEvent) => void;
189
+ 'mongosh-sp:reset-connection-options': () => void;
190
+ 'mongosh-editor:run-edit-command': (ev: EditorRunEditCommandEvent) => void;
191
+ 'mongosh-editor:read-vscode-extensions-done': (ev: EditorReadVscodeExtensionsDoneEvent) => void;
192
+ 'mongosh-editor:read-vscode-extensions-failed': (ev: EditorReadVscodeExtensionsFailedEvent) => void;
193
+ }
194
+ export interface MongoshBus {
195
+ on<K extends keyof MongoshBusEventsMap>(event: K, listener: MongoshBusEventsMap[K]): this;
196
+ once<K extends keyof MongoshBusEventsMap>(event: K, listener: MongoshBusEventsMap[K]): this;
197
+ emit<K extends keyof MongoshBusEventsMap>(event: K, ...args: MongoshBusEventsMap[K] extends (...args: infer P) => any ? P : never): unknown;
198
+ }
199
+ export declare class ShellUserConfig {
200
+ displayBatchSize: number;
201
+ maxTimeMS: number | null;
202
+ enableTelemetry: boolean;
203
+ editor: string | null;
204
+ }
205
+ export declare class ShellUserConfigValidator {
206
+ static validate<K extends keyof ShellUserConfig>(key: K, value: ShellUserConfig[K]): Promise<string | null>;
207
+ }
208
+ export declare class SnippetShellUserConfig extends ShellUserConfig {
209
+ snippetIndexSourceURLs: string;
210
+ snippetRegistryURL: string;
211
+ snippetAutoload: boolean;
212
+ }
213
+ export declare class SnippetShellUserConfigValidator extends ShellUserConfigValidator {
214
+ static validate<K extends keyof SnippetShellUserConfig>(key: K, value: SnippetShellUserConfig[K]): Promise<string | null>;
215
+ }
216
+ export declare class CliUserConfig extends SnippetShellUserConfig {
217
+ userId: string;
218
+ telemetryAnonymousId: string;
219
+ disableGreetingMessage: boolean;
220
+ forceDisableTelemetry: boolean;
221
+ inspectCompact: number | boolean;
222
+ inspectDepth: number;
223
+ historyLength: number;
224
+ showStackTraces: boolean;
225
+ redactHistory: 'keep' | 'remove' | 'remove-redact';
226
+ }
227
+ export declare class CliUserConfigValidator extends SnippetShellUserConfigValidator {
228
+ static validate<K extends keyof CliUserConfig>(key: K, value: CliUserConfig[K]): Promise<string | null>;
229
+ }
230
+ export interface ConfigProvider<T> {
231
+ getConfig<K extends keyof T>(key: K): Promise<T[K]>;
232
+ setConfig<K extends keyof T>(key: K, value: T[K]): Promise<'success' | 'ignored'>;
233
+ resetConfig<K extends keyof T>(key: K): Promise<'success' | 'ignored'>;
234
+ validateConfig<K extends keyof T>(key: K, value: T[K]): Promise<string | null>;
235
+ listConfigOptions(): string[] | Promise<string[]>;
236
+ }
package/lib/index.js ADDED
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CliUserConfigValidator = exports.CliUserConfig = exports.SnippetShellUserConfigValidator = exports.SnippetShellUserConfig = exports.ShellUserConfigValidator = exports.ShellUserConfig = void 0;
4
+ class ShellUserConfig {
5
+ constructor() {
6
+ this.displayBatchSize = 20;
7
+ this.maxTimeMS = null;
8
+ this.enableTelemetry = false;
9
+ this.editor = null;
10
+ }
11
+ }
12
+ exports.ShellUserConfig = ShellUserConfig;
13
+ class ShellUserConfigValidator {
14
+ static async validate(key, value) {
15
+ switch (key) {
16
+ case 'displayBatchSize':
17
+ if (typeof value !== 'number' || value <= 0) {
18
+ return `${key} must be a positive integer`;
19
+ }
20
+ return null;
21
+ case 'maxTimeMS':
22
+ if (value !== null && (typeof value !== 'number' || value <= 0)) {
23
+ return `${key} must be null or a positive integer`;
24
+ }
25
+ return null;
26
+ case 'enableTelemetry':
27
+ if (typeof value !== 'boolean') {
28
+ return `${key} must be a boolean`;
29
+ }
30
+ return null;
31
+ case 'editor':
32
+ if (typeof value !== 'string' && value !== null) {
33
+ return `${key} must be a string or null`;
34
+ }
35
+ return null;
36
+ default:
37
+ return `${key} is not a known config option`;
38
+ }
39
+ }
40
+ }
41
+ exports.ShellUserConfigValidator = ShellUserConfigValidator;
42
+ class SnippetShellUserConfig extends ShellUserConfig {
43
+ constructor() {
44
+ super(...arguments);
45
+ this.snippetIndexSourceURLs = 'https://compass.mongodb.com/mongosh/snippets-index.bson.br';
46
+ this.snippetRegistryURL = 'https://registry.npmjs.org';
47
+ this.snippetAutoload = true;
48
+ }
49
+ }
50
+ exports.SnippetShellUserConfig = SnippetShellUserConfig;
51
+ class SnippetShellUserConfigValidator extends ShellUserConfigValidator {
52
+ static async validate(key, value) {
53
+ switch (key) {
54
+ case 'snippetIndexSourceURLs':
55
+ if (typeof value !== 'string' || value.split(';').some(url => url && !isValidUrl(url))) {
56
+ return `${key} must be a ;-separated list of valid URLs`;
57
+ }
58
+ return null;
59
+ case 'snippetRegistryURL':
60
+ if (typeof value !== 'string' || !isValidUrl(value)) {
61
+ return `${key} must be a valid URL`;
62
+ }
63
+ return null;
64
+ case 'snippetAutoload':
65
+ if (typeof value !== 'boolean') {
66
+ return `${key} must be a boolean`;
67
+ }
68
+ return null;
69
+ default:
70
+ return super.validate(key, value);
71
+ }
72
+ }
73
+ }
74
+ exports.SnippetShellUserConfigValidator = SnippetShellUserConfigValidator;
75
+ class CliUserConfig extends SnippetShellUserConfig {
76
+ constructor() {
77
+ super(...arguments);
78
+ this.userId = '';
79
+ this.telemetryAnonymousId = '';
80
+ this.disableGreetingMessage = false;
81
+ this.forceDisableTelemetry = false;
82
+ this.inspectCompact = 3;
83
+ this.inspectDepth = 6;
84
+ this.historyLength = 1000;
85
+ this.showStackTraces = false;
86
+ this.redactHistory = 'remove';
87
+ }
88
+ }
89
+ exports.CliUserConfig = CliUserConfig;
90
+ class CliUserConfigValidator extends SnippetShellUserConfigValidator {
91
+ static async validate(key, value) {
92
+ switch (key) {
93
+ case 'userId':
94
+ case 'telemetryAnonymousId':
95
+ case 'disableGreetingMessage':
96
+ return null;
97
+ case 'inspectCompact':
98
+ if (typeof value !== 'boolean' && (typeof value !== 'number' || value < 0)) {
99
+ return `${key} must be a boolean or a positive integer`;
100
+ }
101
+ return null;
102
+ case 'inspectDepth':
103
+ case 'historyLength':
104
+ if (typeof value !== 'number' || value < 0) {
105
+ return `${key} must be a positive integer`;
106
+ }
107
+ return null;
108
+ case 'forceDisableTelemetry':
109
+ case 'showStackTraces':
110
+ if (typeof value !== 'boolean') {
111
+ return `${key} must be a boolean`;
112
+ }
113
+ return null;
114
+ case 'redactHistory':
115
+ if (value !== 'keep' && value !== 'remove' && value !== 'remove-redact') {
116
+ return `${key} must be one of 'keep', 'remove', or 'remove-redact'`;
117
+ }
118
+ return null;
119
+ default:
120
+ return super.validate(key, value);
121
+ }
122
+ }
123
+ }
124
+ exports.CliUserConfigValidator = CliUserConfigValidator;
125
+ function isValidUrl(url) {
126
+ if (typeof URL === 'function') {
127
+ try {
128
+ new URL(url);
129
+ return true;
130
+ }
131
+ catch (_a) {
132
+ return false;
133
+ }
134
+ }
135
+ return true;
136
+ }
137
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AA0VA,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,Q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,CAAC,CAAC,EAAE;oBAC1E,OAAO,GAAG,GAAG,0CAA0C,CAAC;iBACzD;gBACD,OAAO,IAAI,CAAC;YACd,KAAK,cAAc,CAAC;YACpB,KAAK,eAAe;gBAClB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,GAAG,CAAC,EAAE;oBAC1C,OAAO,GAAG,GAAG,6BAA6B,CAAC;iBAC5C;gBACD,OAAO,IAAI,CAAC;YACd,KAAK,uBAAuB,CAAC;YAC7B,KAAK,iBAAiB;gBACpB,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;oBAC9B,OAAO,GAAG,GAAG,oBAAoB,CAAC;iBACnC;gBACD,OAAO,IAAI,CAAC;YACd,KAAK,eAAe;gBAClB,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,eAAe,EAAE;oBACvE,OAAO,GAAG,GAAG,sDAAsD,CAAC;iBACrE;gBACD,OAAO,IAAI,CAAC;YACd;gBACE,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAmC,EAAE,KAAY,CAAC,CAAC;SAC5E;IACH,CAAC;CACF;AAlCD,wDAkCC;AAUD,SAAS,UAAU,CAAC,GAAW;IAM7B,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;QAC7B,IAAI;YAEF,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YACb,OAAO,IAAI,CAAC;SACb;QAAC,WAAM;YACN,OAAO,KAAK,CAAC;SACd;KACF;IAGD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qp-mongosh/types",
3
- "version": "0.0.0-dev.28",
3
+ "version": "0.0.0-dev.29",
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",