@mongosh/node-runtime-worker-thread 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 -2
- package/.eslintignore +2 -1
- package/.eslintrc.js +10 -1
- package/.prettierignore +6 -0
- package/.prettierrc.json +1 -0
- package/dist/child-process-evaluation-listener.d.ts +3 -3
- package/dist/child-process-evaluation-listener.js +4 -4
- package/dist/child-process-evaluation-listener.js.map +1 -1
- package/dist/child-process-mongosh-bus.d.ts +3 -3
- package/dist/child-process-mongosh-bus.js +1 -1
- package/dist/child-process-mongosh-bus.js.map +1 -1
- package/dist/child-process-proxy.js +1 -1
- package/dist/child-process-proxy.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lock.d.ts +1 -1
- package/dist/lock.js +1 -1
- package/dist/lock.js.map +1 -1
- package/dist/report.html +2 -2
- package/dist/rpc.d.ts +4 -4
- package/dist/rpc.js +4 -4
- package/dist/rpc.js.map +1 -1
- package/dist/serializer.d.ts +3 -3
- package/dist/serializer.js +11 -14
- package/dist/serializer.js.map +1 -1
- package/dist/spawn-child-from-source.d.ts +2 -1
- package/dist/spawn-child-from-source.js +1 -1
- package/dist/spawn-child-from-source.js.map +1 -1
- package/dist/worker-runtime.d.ts +5 -5
- package/dist/worker-runtime.js +34 -46
- package/dist/worker-runtime.js.map +1 -1
- package/package.json +26 -15
- package/src/child-process-evaluation-listener.ts +25 -10
- package/src/child-process-mongosh-bus.ts +5 -4
- package/src/child-process-proxy.spec.ts +22 -12
- package/src/child-process-proxy.ts +18 -15
- package/src/index.spec.ts +109 -68
- package/src/index.ts +25 -13
- package/src/lock.spec.ts +9 -9
- package/src/lock.ts +1 -1
- package/src/rpc.spec.ts +33 -34
- package/src/rpc.ts +17 -16
- package/src/serializer.spec.ts +85 -63
- package/src/serializer.ts +24 -17
- package/src/spawn-child-from-source.spec.ts +10 -9
- package/src/spawn-child-from-source.ts +5 -5
- package/src/worker-runtime.spec.ts +117 -98
- package/src/worker-runtime.ts +26 -21
- package/tsconfig-lint.json +5 -0
- package/tsconfig.json +5 -11
- package/tsconfig.test.json +3 -5
- package/webpack.config.js +4 -4
- package/tsconfig.lint.json +0 -8
package/src/serializer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { inspect } from 'util';
|
|
2
2
|
import { EJSON } from 'bson';
|
|
3
|
-
import { RuntimeEvaluationResult } from '@mongosh/browser-runtime-core';
|
|
3
|
+
import type { RuntimeEvaluationResult } from '@mongosh/browser-runtime-core';
|
|
4
4
|
import type { DevtoolsConnectOptions } from '@mongosh/service-provider-server';
|
|
5
5
|
|
|
6
6
|
function isPrimitive(
|
|
@@ -44,13 +44,13 @@ export function deserializeError(err: any): Error {
|
|
|
44
44
|
export enum SerializedResultTypes {
|
|
45
45
|
SerializedErrorResult = 'SerializedErrorResult',
|
|
46
46
|
InspectResult = 'InspectResult',
|
|
47
|
-
SerializedShellApiResult = 'SerializedShellApiResult'
|
|
47
|
+
SerializedShellApiResult = 'SerializedShellApiResult',
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export function serializeEvaluationResult({
|
|
51
51
|
type,
|
|
52
52
|
printable,
|
|
53
|
-
source
|
|
53
|
+
source,
|
|
54
54
|
}: RuntimeEvaluationResult): RuntimeEvaluationResult {
|
|
55
55
|
// Primitive values don't require any special treatment for serialization
|
|
56
56
|
if (isPrimitive(printable)) {
|
|
@@ -62,7 +62,7 @@ export function serializeEvaluationResult({
|
|
|
62
62
|
return {
|
|
63
63
|
type: SerializedResultTypes.SerializedErrorResult,
|
|
64
64
|
printable: serializeError(printable),
|
|
65
|
-
source
|
|
65
|
+
source,
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -76,7 +76,7 @@ export function serializeEvaluationResult({
|
|
|
76
76
|
return {
|
|
77
77
|
type: SerializedResultTypes.InspectResult,
|
|
78
78
|
printable: inspect(printable),
|
|
79
|
-
source
|
|
79
|
+
source,
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -87,15 +87,15 @@ export function serializeEvaluationResult({
|
|
|
87
87
|
type: SerializedResultTypes.SerializedShellApiResult,
|
|
88
88
|
printable: {
|
|
89
89
|
origType: type,
|
|
90
|
-
serializedValue: EJSON.serialize(printable)
|
|
91
|
-
}
|
|
90
|
+
serializedValue: EJSON.serialize(printable),
|
|
91
|
+
},
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
export function deserializeEvaluationResult({
|
|
96
96
|
type,
|
|
97
97
|
printable,
|
|
98
|
-
source
|
|
98
|
+
source,
|
|
99
99
|
}: RuntimeEvaluationResult): RuntimeEvaluationResult {
|
|
100
100
|
if (type === SerializedResultTypes.SerializedErrorResult) {
|
|
101
101
|
return { type, printable: deserializeError(printable), source };
|
|
@@ -105,38 +105,45 @@ export function deserializeEvaluationResult({
|
|
|
105
105
|
return {
|
|
106
106
|
type: printable.origType,
|
|
107
107
|
printable: EJSON.deserialize(printable.serializedValue),
|
|
108
|
-
source
|
|
108
|
+
source,
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
return { type, printable, source };
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
const autoEncryptionBSONOptions = [
|
|
116
|
-
'schemaMap',
|
|
117
|
-
'encryptedFieldsMap'
|
|
118
|
-
] as const;
|
|
115
|
+
const autoEncryptionBSONOptions = ['schemaMap', 'encryptedFieldsMap'] as const;
|
|
119
116
|
|
|
120
|
-
export function serializeConnectOptions(
|
|
117
|
+
export function serializeConnectOptions(
|
|
118
|
+
options: Readonly<DevtoolsConnectOptions>
|
|
119
|
+
): DevtoolsConnectOptions {
|
|
121
120
|
const serializedOptions = { ...options };
|
|
122
121
|
for (const autoEncryptionOption of autoEncryptionBSONOptions) {
|
|
123
122
|
if (serializedOptions.autoEncryption?.[autoEncryptionOption]) {
|
|
124
123
|
serializedOptions.autoEncryption = {
|
|
125
124
|
...serializedOptions.autoEncryption,
|
|
126
|
-
[autoEncryptionOption]: EJSON.serialize(
|
|
125
|
+
[autoEncryptionOption]: EJSON.serialize(
|
|
126
|
+
serializedOptions.autoEncryption[autoEncryptionOption],
|
|
127
|
+
{ relaxed: false }
|
|
128
|
+
),
|
|
127
129
|
};
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
return serializedOptions;
|
|
131
133
|
}
|
|
132
134
|
|
|
133
|
-
export function deserializeConnectOptions(
|
|
135
|
+
export function deserializeConnectOptions(
|
|
136
|
+
options: Readonly<DevtoolsConnectOptions>
|
|
137
|
+
): DevtoolsConnectOptions {
|
|
134
138
|
const deserializedOptions: any = { ...options };
|
|
135
139
|
for (const autoEncryptionOption of autoEncryptionBSONOptions) {
|
|
136
140
|
if (deserializedOptions.autoEncryption?.[autoEncryptionOption]) {
|
|
137
141
|
deserializedOptions.autoEncryption = {
|
|
138
142
|
...deserializedOptions.autoEncryption,
|
|
139
|
-
[autoEncryptionOption]: EJSON.deserialize(
|
|
143
|
+
[autoEncryptionOption]: EJSON.deserialize(
|
|
144
|
+
deserializedOptions.autoEncryption[autoEncryptionOption],
|
|
145
|
+
{ relaxed: false }
|
|
146
|
+
),
|
|
140
147
|
};
|
|
141
148
|
}
|
|
142
149
|
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import
|
|
2
|
+
import type { ChildProcess } from 'child_process';
|
|
3
|
+
import childProcess from 'child_process';
|
|
3
4
|
import { once } from 'events';
|
|
4
5
|
import spawnChildFromSource, { kill } from './spawn-child-from-source';
|
|
5
6
|
|
|
6
|
-
describe('spawnChildFromSource', ()
|
|
7
|
+
describe('spawnChildFromSource', function () {
|
|
7
8
|
let spawned: ChildProcess;
|
|
8
9
|
|
|
9
|
-
afterEach(async()
|
|
10
|
+
afterEach(async function () {
|
|
10
11
|
if (spawned) {
|
|
11
12
|
await kill(spawned, 'SIGKILL');
|
|
12
13
|
spawned = null;
|
|
13
14
|
}
|
|
14
15
|
});
|
|
15
16
|
|
|
16
|
-
it('should throw if stdin is missing', async()
|
|
17
|
+
it('should throw if stdin is missing', async function () {
|
|
17
18
|
let err: Error;
|
|
18
19
|
|
|
19
20
|
try {
|
|
@@ -21,7 +22,7 @@ describe('spawnChildFromSource', () => {
|
|
|
21
22
|
// Making istanbul happy by passing stuff that's not allowed
|
|
22
23
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
24
|
// @ts-expect-error
|
|
24
|
-
stdio: 'ignore'
|
|
25
|
+
stdio: 'ignore',
|
|
25
26
|
});
|
|
26
27
|
} catch (e: any) {
|
|
27
28
|
err = e;
|
|
@@ -33,12 +34,12 @@ describe('spawnChildFromSource', () => {
|
|
|
33
34
|
.match(/missing stdin/);
|
|
34
35
|
});
|
|
35
36
|
|
|
36
|
-
it('should resolve with a child process', async()
|
|
37
|
+
it('should resolve with a child process', async function () {
|
|
37
38
|
spawned = await spawnChildFromSource('');
|
|
38
39
|
expect(spawned).to.be.instanceof((childProcess as any).ChildProcess);
|
|
39
40
|
});
|
|
40
41
|
|
|
41
|
-
it('should spawn a process with an ipc channel open', async()
|
|
42
|
+
it('should spawn a process with an ipc channel open', async function () {
|
|
42
43
|
spawned = await spawnChildFromSource(
|
|
43
44
|
'process.on("message", (data) => process.send(data))'
|
|
44
45
|
);
|
|
@@ -47,7 +48,7 @@ describe('spawnChildFromSource', () => {
|
|
|
47
48
|
expect(message).to.equal('Hi!');
|
|
48
49
|
});
|
|
49
50
|
|
|
50
|
-
it('should fail if process exited before successfully starting', async()
|
|
51
|
+
it('should fail if process exited before successfully starting', async function () {
|
|
51
52
|
let err: Error;
|
|
52
53
|
|
|
53
54
|
try {
|
|
@@ -68,7 +69,7 @@ describe('spawnChildFromSource', () => {
|
|
|
68
69
|
);
|
|
69
70
|
});
|
|
70
71
|
|
|
71
|
-
it('should fail if a timeout exceeded before the process is "ready"', async()
|
|
72
|
+
it('should fail if a timeout exceeded before the process is "ready"', async function () {
|
|
72
73
|
let err: Error;
|
|
73
74
|
|
|
74
75
|
try {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
ChildProcess,
|
|
3
3
|
Serializable,
|
|
4
|
-
spawn,
|
|
5
4
|
SpawnOptions,
|
|
6
5
|
StdioNull,
|
|
7
|
-
StdioPipe
|
|
6
|
+
StdioPipe,
|
|
8
7
|
} from 'child_process';
|
|
8
|
+
import { spawn } from 'child_process';
|
|
9
9
|
import { once } from 'events';
|
|
10
10
|
|
|
11
11
|
export async function kill(
|
|
@@ -25,12 +25,12 @@ export default function spawnChildFromSource(
|
|
|
25
25
|
_stdout: StdioNull | StdioPipe = 'inherit',
|
|
26
26
|
_stderr: StdioNull | StdioPipe = 'inherit'
|
|
27
27
|
): Promise<ChildProcess> {
|
|
28
|
-
return new Promise(async(resolve, reject) => {
|
|
28
|
+
return new Promise(async (resolve, reject) => {
|
|
29
29
|
const readyToken = Date.now().toString(32);
|
|
30
30
|
|
|
31
31
|
const childProcess = spawn(process.execPath, {
|
|
32
32
|
stdio: ['pipe', _stdout, _stderr, 'ipc'],
|
|
33
|
-
...spawnOptions
|
|
33
|
+
...spawnOptions,
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
if (!childProcess.stdin) {
|