@mongosh/node-runtime-worker-thread 1.10.1 → 1.10.3

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.
Files changed (54) hide show
  1. package/.depcheckrc +14 -2
  2. package/.eslintignore +2 -1
  3. package/.eslintrc.js +10 -1
  4. package/.prettierignore +6 -0
  5. package/.prettierrc.json +1 -0
  6. package/dist/child-process-evaluation-listener.d.ts +3 -3
  7. package/dist/child-process-evaluation-listener.js +4 -4
  8. package/dist/child-process-evaluation-listener.js.map +1 -1
  9. package/dist/child-process-mongosh-bus.d.ts +3 -3
  10. package/dist/child-process-mongosh-bus.js +1 -1
  11. package/dist/child-process-mongosh-bus.js.map +1 -1
  12. package/dist/child-process-proxy.js +1 -1
  13. package/dist/child-process-proxy.js.map +1 -1
  14. package/dist/index.d.ts +3 -3
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/lock.d.ts +1 -1
  18. package/dist/lock.js +1 -1
  19. package/dist/lock.js.map +1 -1
  20. package/dist/report.html +2 -2
  21. package/dist/rpc.d.ts +4 -4
  22. package/dist/rpc.js +4 -4
  23. package/dist/rpc.js.map +1 -1
  24. package/dist/serializer.d.ts +3 -3
  25. package/dist/serializer.js +11 -14
  26. package/dist/serializer.js.map +1 -1
  27. package/dist/spawn-child-from-source.d.ts +2 -1
  28. package/dist/spawn-child-from-source.js +1 -1
  29. package/dist/spawn-child-from-source.js.map +1 -1
  30. package/dist/worker-runtime.d.ts +5 -5
  31. package/dist/worker-runtime.js +34 -46
  32. package/dist/worker-runtime.js.map +1 -1
  33. package/package.json +26 -15
  34. package/src/child-process-evaluation-listener.ts +25 -10
  35. package/src/child-process-mongosh-bus.ts +5 -4
  36. package/src/child-process-proxy.spec.ts +22 -12
  37. package/src/child-process-proxy.ts +18 -15
  38. package/src/index.spec.ts +109 -68
  39. package/src/index.ts +25 -13
  40. package/src/lock.spec.ts +9 -9
  41. package/src/lock.ts +1 -1
  42. package/src/rpc.spec.ts +33 -34
  43. package/src/rpc.ts +17 -16
  44. package/src/serializer.spec.ts +85 -63
  45. package/src/serializer.ts +24 -17
  46. package/src/spawn-child-from-source.spec.ts +10 -9
  47. package/src/spawn-child-from-source.ts +5 -5
  48. package/src/worker-runtime.spec.ts +117 -98
  49. package/src/worker-runtime.ts +26 -21
  50. package/tsconfig-lint.json +5 -0
  51. package/tsconfig.json +5 -11
  52. package/tsconfig.test.json +3 -5
  53. package/webpack.config.js +4 -4
  54. package/tsconfig.lint.json +0 -8
@@ -2,23 +2,29 @@
2
2
  /* ^^^ we test the dist directly, so isntanbul can't calculate the coverage correctly */
3
3
 
4
4
  import { parentPort, isMainThread } from 'worker_threads';
5
- import {
5
+ import type {
6
+ Completion,
6
7
  Runtime,
7
8
  RuntimeEvaluationListener,
8
- RuntimeEvaluationResult
9
+ RuntimeEvaluationResult,
9
10
  } from '@mongosh/browser-runtime-core';
10
11
  import { ElectronRuntime } from '@mongosh/browser-runtime-electron';
11
12
  import type { ServiceProvider } from '@mongosh/service-provider-core';
12
- import {
13
- CompassServiceProvider
14
- } from '@mongosh/service-provider-server';
13
+ import { CompassServiceProvider } from '@mongosh/service-provider-server';
15
14
  import { exposeAll, createCaller } from './rpc';
16
- import { serializeEvaluationResult, deserializeConnectOptions } from './serializer';
15
+ import {
16
+ serializeEvaluationResult,
17
+ deserializeConnectOptions,
18
+ } from './serializer';
17
19
  import type { MongoshBus } from '@mongosh/types';
18
- import { Lock, UNLOCKED } from './lock';
19
- import { runInterruptible, InterruptHandle } from 'interruptor';
20
+ import type { UNLOCKED } from './lock';
21
+ import { Lock } from './lock';
22
+ import type { InterruptHandle } from 'interruptor';
23
+ import { runInterruptible } from 'interruptor';
20
24
 
21
- type DevtoolsConnectOptions = Parameters<(typeof CompassServiceProvider)['connect']>[1];
25
+ type DevtoolsConnectOptions = Parameters<
26
+ (typeof CompassServiceProvider)['connect']
27
+ >[1];
22
28
 
23
29
  if (!parentPort || isMainThread) {
24
30
  throw new Error('Worker runtime can be used only in a worker thread');
@@ -54,17 +60,19 @@ const evaluationListener = createCaller<WorkerRuntimeEvaluationListener>(
54
60
  'listConfigOptions',
55
61
  'onClearCommand',
56
62
  'onExit',
57
- 'onRunInterruptible'
63
+ 'onRunInterruptible',
58
64
  ],
59
65
  parentPort,
60
66
  {
61
- onPrint: function(results: RuntimeEvaluationResult[]): RuntimeEvaluationResult[][] {
67
+ onPrint: function (
68
+ results: RuntimeEvaluationResult[]
69
+ ): RuntimeEvaluationResult[][] {
62
70
  // We're transforming an args array, so we have to return an array of
63
71
  // args. onPrint only takes one arg which is an array of
64
72
  // RuntimeEvaluationResult so in this case it will just return a
65
73
  // single-element array that itself is an array.
66
74
  return [results.map(serializeEvaluationResult)];
67
- }
75
+ },
68
76
  }
69
77
  );
70
78
 
@@ -76,7 +84,7 @@ const messageBus: MongoshBus = Object.assign(
76
84
  },
77
85
  once() {
78
86
  throw new Error("Can't call `once` method on worker runtime MongoshBus");
79
- }
87
+ },
80
88
  }
81
89
  );
82
90
 
@@ -114,7 +122,7 @@ const workerRuntime: WorkerRuntime = {
114
122
  runtime.setEvaluationListener(evaluationListener);
115
123
  },
116
124
 
117
- async evaluate(code) {
125
+ async evaluate(code: string) {
118
126
  if (evaluationLock.isLocked()) {
119
127
  throw new Error(
120
128
  "Can't run another evaluation while the previous is not finished"
@@ -154,10 +162,7 @@ const workerRuntime: WorkerRuntime = {
154
162
  let result: void | RuntimeEvaluationResult | UNLOCKED;
155
163
 
156
164
  try {
157
- result = await Promise.race([
158
- evaluationPromise,
159
- evaluationLock.lock()
160
- ]);
165
+ result = await Promise.race([evaluationPromise, evaluationLock.lock()]);
161
166
  } finally {
162
167
  evaluationLock.unlock();
163
168
  }
@@ -173,11 +178,11 @@ const workerRuntime: WorkerRuntime = {
173
178
  return serializeEvaluationResult(result);
174
179
  },
175
180
 
176
- async getCompletions(code) {
181
+ getCompletions(code: string): Promise<Completion[]> {
177
182
  return ensureRuntime('getCompletions').getCompletions(code);
178
183
  },
179
184
 
180
- async getShellPrompt() {
185
+ getShellPrompt(): Promise<string> {
181
186
  return ensureRuntime('getShellPrompt').getShellPrompt();
182
187
  },
183
188
 
@@ -189,7 +194,7 @@ const workerRuntime: WorkerRuntime = {
189
194
 
190
195
  interrupt() {
191
196
  return evaluationLock.unlock();
192
- }
197
+ },
193
198
  };
194
199
 
195
200
  // We expect the amount of listeners to be more than the default value of 10 but
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["**/*"],
4
+ "exclude": ["node_modules", "dist", "lib"]
5
+ }
package/tsconfig.json CHANGED
@@ -1,16 +1,10 @@
1
1
  {
2
- "extends": "../../config/tsconfig.base.json",
2
+ "extends": "@mongodb-js/tsconfig-mongosh/tsconfig.common.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "./dist",
5
5
  "allowJs": true
6
6
  },
7
- "files": [
8
- "./src/index.d.ts"
9
- ],
10
- "include": [
11
- "./src/**/*"
12
- ],
13
- "exclude": [
14
- "./src/**/*.spec.*"
15
- ]
16
- }
7
+ "files": ["./src/index.d.ts"],
8
+ "include": ["src/**/*"],
9
+ "exclude": ["./src/**/*.spec.*"]
10
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "../../config/tsconfig.test.json",
2
+ "extends": "@mongodb-js/tsconfig-mongosh/tsconfig.test.json",
3
3
  "ts-node": {
4
4
  "files": true
5
5
  },
@@ -7,7 +7,5 @@
7
7
  "outDir": "./lib",
8
8
  "allowJs": false
9
9
  },
10
- "files": [
11
- "./src/index.d.ts"
12
- ]
13
- }
10
+ "files": ["./src/index.d.ts"]
11
+ }
package/webpack.config.js CHANGED
@@ -9,7 +9,7 @@ const config = {
9
9
  output: {
10
10
  path: path.resolve(__dirname, 'dist'),
11
11
  filename: '[name].js',
12
- libraryTarget: 'umd'
12
+ libraryTarget: 'umd',
13
13
  },
14
14
 
15
15
  externals: {
@@ -18,13 +18,13 @@ const config = {
18
18
  snappy: 'commonjs2 snappy',
19
19
  interruptor: 'commonjs2 interruptor',
20
20
  'os-dns-native': 'commonjs2 os-dns-native',
21
- 'system-ca': 'commonjs2 system-ca'
22
- }
21
+ 'system-ca': 'commonjs2 system-ca',
22
+ },
23
23
  };
24
24
 
25
25
  module.exports = ['index', 'child-process-proxy', 'worker-runtime'].map(
26
26
  (entry) => ({
27
27
  entry: { [entry]: path.resolve(__dirname, 'src', `${entry}.ts`) },
28
- ...merge(baseWebpackConfig, config)
28
+ ...merge(baseWebpackConfig, config),
29
29
  })
30
30
  );
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "include": [
4
- "./src/**/*",
5
- "./test/**/*"
6
- ],
7
- "exclude": []
8
- }