@mongosh/node-runtime-worker-thread 1.4.1 → 1.5.1
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/AUTHORS +1 -0
- package/dist/child-process-evaluation-listener.d.ts +1 -1
- package/dist/child-process-evaluation-listener.js +2 -0
- package/dist/child-process-evaluation-listener.js.map +1 -1
- package/dist/child-process-proxy.js +1 -1
- package/dist/index.js +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +6 -2
- package/dist/rpc.js.map +1 -1
- package/dist/serializer.js +3 -3
- package/dist/serializer.js.map +1 -1
- package/dist/src/child-process-evaluation-listener.d.ts +1 -1
- package/dist/src/rpc.d.ts +1 -1
- package/dist/worker-runtime.js +7 -7
- package/dist/worker-runtime.js.map +1 -1
- package/package.json +9 -9
- package/src/child-process-evaluation-listener.ts +3 -1
- package/src/rpc.ts +9 -2
- package/src/serializer.spec.ts +38 -2
- package/src/serializer.ts +3 -5
- package/src/worker-runtime.spec.ts +15 -1
- package/src/worker-runtime.ts +10 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-runtime.js","sourceRoot":"","sources":["../src/worker-runtime.ts"],"names":[],"mappings":";;AAGA,mDAA0D;AAM1D,gFAAoE;AAEpE,8EAE0C;AAC1C,+BAAgD;AAChD,6CAAoF;AAEpF,iCAAwC;AACxC,6CAAgE;AAIhE,IAAI,CAAC,2BAAU,IAAI,6BAAY,EAAE;IAC/B,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;CACvE;AAED,IAAI,OAAO,GAAmB,IAAI,CAAC;AACnC,IAAI,QAAQ,GAA2B,IAAI,CAAC;AAE5C,MAAM,cAAc,GAAG,IAAI,WAAI,EAAE,CAAC;AAElC,SAAS,aAAa,CAAC,UAAkB;IACvC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,eAAe,UAAU,oCAAoC,CAC9D,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAMD,MAAM,kBAAkB,GAAG,IAAA,kBAAY,EACrC;IACE,SAAS;IACT,UAAU;IACV,WAAW;IACX,WAAW;IACX,aAAa;IACb,gBAAgB;IAChB,mBAAmB;IACnB,gBAAgB;IAChB,QAAQ;IACR,oBAAoB;CACrB,EACD,2BAAU,
|
|
1
|
+
{"version":3,"file":"worker-runtime.js","sourceRoot":"","sources":["../src/worker-runtime.ts"],"names":[],"mappings":";;AAGA,mDAA0D;AAM1D,gFAAoE;AAEpE,8EAE0C;AAC1C,+BAAgD;AAChD,6CAAoF;AAEpF,iCAAwC;AACxC,6CAAgE;AAIhE,IAAI,CAAC,2BAAU,IAAI,6BAAY,EAAE;IAC/B,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;CACvE;AAED,IAAI,OAAO,GAAmB,IAAI,CAAC;AACnC,IAAI,QAAQ,GAA2B,IAAI,CAAC;AAE5C,MAAM,cAAc,GAAG,IAAI,WAAI,EAAE,CAAC;AAElC,SAAS,aAAa,CAAC,UAAkB;IACvC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,eAAe,UAAU,oCAAoC,CAC9D,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAMD,MAAM,kBAAkB,GAAG,IAAA,kBAAY,EACrC;IACE,SAAS;IACT,UAAU;IACV,WAAW;IACX,WAAW;IACX,aAAa;IACb,gBAAgB;IAChB,mBAAmB;IACnB,gBAAgB;IAChB,QAAQ;IACR,oBAAoB;CACrB,EACD,2BAAU,EACV;IACE,OAAO,EAAE,UAAS,OAAkC;QAKlD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,sCAAyB,CAAC,CAAC,CAAC;IAClD,CAAC;CACF,CACF,CAAC;AAEF,MAAM,UAAU,GAAe,MAAM,CAAC,MAAM,CAC1C,IAAA,kBAAY,EAAC,CAAC,MAAM,CAAC,EAAE,2BAAU,CAAC,EAClC;IACE,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AAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;KACjC;AACH,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongosh/node-runtime-worker-thread",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "MongoDB shell runtime that lives in a worker thread",
|
|
5
5
|
"homepage": "https://github.com/mongodb-js/mongosh",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "https://github.com/mongodb-js/mongosh"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
17
|
+
"node": ">=14.15.1"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "cross-env TS_NODE_PROJECT=./tsconfig.test.json mocha -r \"../../scripts/import-expansions.js\" --timeout 15000 -r ts-node/register \"./src/**/*.spec.ts\"",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"prepublish": "npm run webpack-build"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@mongosh/browser-runtime-core": "1.
|
|
32
|
-
"@mongosh/browser-runtime-electron": "1.
|
|
33
|
-
"@mongosh/service-provider-core": "1.
|
|
34
|
-
"@mongosh/service-provider-server": "1.
|
|
35
|
-
"@mongosh/types": "1.
|
|
36
|
-
"bson": "^4.6.
|
|
31
|
+
"@mongosh/browser-runtime-core": "1.5.1",
|
|
32
|
+
"@mongosh/browser-runtime-electron": "1.5.1",
|
|
33
|
+
"@mongosh/service-provider-core": "1.5.1",
|
|
34
|
+
"@mongosh/service-provider-server": "1.5.1",
|
|
35
|
+
"@mongosh/types": "1.5.1",
|
|
36
|
+
"bson": "^4.6.5",
|
|
37
37
|
"mocha": "^7.1.2",
|
|
38
38
|
"postmsg-rpc": "^2.4.0",
|
|
39
39
|
"terser-webpack-plugin": "^4.2.3",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"interruptor": "^1.0.1",
|
|
46
46
|
"system-ca": "^1.0.2"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "0395e15ca5ffcad0aa22e337c014441e8da7909d"
|
|
49
49
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ChildProcess } from 'child_process';
|
|
2
2
|
import { exposeAll, Exposed, close } from './rpc';
|
|
3
3
|
import type { WorkerRuntime } from './index';
|
|
4
|
+
import { deserializeEvaluationResult } from './serializer';
|
|
4
5
|
import { RuntimeEvaluationListener } from '@mongosh/browser-runtime-core';
|
|
5
6
|
|
|
6
7
|
export class ChildProcessEvaluationListener {
|
|
7
|
-
exposedListener: Exposed<Required<Omit<RuntimeEvaluationListener, 'onLoad' | '
|
|
8
|
+
exposedListener: Exposed<Required<Omit<RuntimeEvaluationListener, 'onLoad' | 'getCryptLibraryOptions'>>>;
|
|
8
9
|
|
|
9
10
|
constructor(workerRuntime: WorkerRuntime, childProcess: ChildProcess) {
|
|
10
11
|
this.exposedListener = exposeAll(
|
|
@@ -15,6 +16,7 @@ export class ChildProcessEvaluationListener {
|
|
|
15
16
|
);
|
|
16
17
|
},
|
|
17
18
|
onPrint(values) {
|
|
19
|
+
values = values.map(deserializeEvaluationResult);
|
|
18
20
|
return workerRuntime.evaluationListener?.onPrint?.(values);
|
|
19
21
|
},
|
|
20
22
|
setConfig(key, value) {
|
package/src/rpc.ts
CHANGED
|
@@ -171,14 +171,21 @@ export type Caller<
|
|
|
171
171
|
|
|
172
172
|
export function createCaller<Impl extends {}>(
|
|
173
173
|
methodNames: Extract<keyof Impl, string>[],
|
|
174
|
-
messageBus: RPCMessageBus
|
|
174
|
+
messageBus: RPCMessageBus,
|
|
175
|
+
processors: Partial<
|
|
176
|
+
Record<typeof methodNames[number], (...input: any[]) => any[]>
|
|
177
|
+
> = {}
|
|
175
178
|
): Caller<Impl, typeof methodNames[number]> {
|
|
176
179
|
const obj = {};
|
|
177
180
|
const inflight = new Set<CancelablePromise<unknown>>();
|
|
178
181
|
methodNames.forEach((name) => {
|
|
179
182
|
const c = caller(name as string, getRPCOptions(messageBus));
|
|
180
183
|
(obj as any)[name] = async(...args: unknown[]) => {
|
|
181
|
-
const
|
|
184
|
+
const processed =
|
|
185
|
+
typeof processors[name] === 'function'
|
|
186
|
+
? processors[name]?.(...args)
|
|
187
|
+
: args;
|
|
188
|
+
const promise = c(...(processed as any[]));
|
|
182
189
|
inflight.add(promise);
|
|
183
190
|
const result = (await promise) as RPCError | RPCMessage;
|
|
184
191
|
inflight.delete(promise);
|
package/src/serializer.spec.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DevtoolsConnectOptions } from '@mongosh/service-provider-server/lib/cli-service-provider';
|
|
2
2
|
import { expect } from 'chai';
|
|
3
|
-
import { UUID } from 'bson';
|
|
3
|
+
import { UUID, Long } from 'bson';
|
|
4
4
|
import {
|
|
5
5
|
serializeError,
|
|
6
6
|
deserializeError,
|
|
@@ -141,7 +141,7 @@ describe('serializer', () => {
|
|
|
141
141
|
});
|
|
142
142
|
|
|
143
143
|
describe('connection options', () => {
|
|
144
|
-
it('should serialize and deserialize connection options', () => {
|
|
144
|
+
it('should serialize and deserialize FLE1 connection options', () => {
|
|
145
145
|
const options: DevtoolsConnectOptions = {
|
|
146
146
|
autoEncryption: {
|
|
147
147
|
schemaMap: {
|
|
@@ -184,5 +184,41 @@ describe('serializer', () => {
|
|
|
184
184
|
|
|
185
185
|
expect(deserializeConnectOptions(serialized)).to.deep.equal(options);
|
|
186
186
|
});
|
|
187
|
+
|
|
188
|
+
it('should serialize and deserialize FLE2 connection options', () => {
|
|
189
|
+
const options: DevtoolsConnectOptions = {
|
|
190
|
+
autoEncryption: {
|
|
191
|
+
encryptedFieldsMap: {
|
|
192
|
+
'hr.employees': {
|
|
193
|
+
fields: [{
|
|
194
|
+
path: 'phoneNumber',
|
|
195
|
+
keyId: new UUID('fd6275d7-9260-4e6c-a86b-68ec5240814a').toBinary(),
|
|
196
|
+
bsonType: 'string',
|
|
197
|
+
queries: { queryType: 'equality', contention: new Long(0) }
|
|
198
|
+
}]
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const serialized = serializeConnectOptions(options);
|
|
205
|
+
|
|
206
|
+
expect(serialized).to.deep.equal({
|
|
207
|
+
autoEncryption: {
|
|
208
|
+
encryptedFieldsMap: {
|
|
209
|
+
'hr.employees': {
|
|
210
|
+
fields: [{
|
|
211
|
+
path: 'phoneNumber',
|
|
212
|
+
keyId: { $binary: { base64: '/WJ115JgTmyoa2jsUkCBSg==', subType: '04' } },
|
|
213
|
+
bsonType: 'string',
|
|
214
|
+
queries: { queryType: 'equality', contention: { $numberLong: '0' } }
|
|
215
|
+
}]
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
expect(deserializeConnectOptions(serialized)).to.deep.equal(options);
|
|
222
|
+
});
|
|
187
223
|
});
|
|
188
224
|
});
|
package/src/serializer.ts
CHANGED
|
@@ -114,9 +114,7 @@ export function deserializeEvaluationResult({
|
|
|
114
114
|
|
|
115
115
|
const autoEncryptionBSONOptions = [
|
|
116
116
|
'schemaMap',
|
|
117
|
-
|
|
118
|
-
// This may need to be adjusted later.
|
|
119
|
-
'encryptedFieldConfigMap'
|
|
117
|
+
'encryptedFieldsMap'
|
|
120
118
|
] as const;
|
|
121
119
|
|
|
122
120
|
export function serializeConnectOptions(options: Readonly<DevtoolsConnectOptions> = {}): DevtoolsConnectOptions {
|
|
@@ -125,7 +123,7 @@ export function serializeConnectOptions(options: Readonly<DevtoolsConnectOptions
|
|
|
125
123
|
if (serializedOptions.autoEncryption?.[autoEncryptionOption]) {
|
|
126
124
|
serializedOptions.autoEncryption = {
|
|
127
125
|
...serializedOptions.autoEncryption,
|
|
128
|
-
[autoEncryptionOption]: EJSON.serialize(serializedOptions.autoEncryption[autoEncryptionOption])
|
|
126
|
+
[autoEncryptionOption]: EJSON.serialize(serializedOptions.autoEncryption[autoEncryptionOption], { relaxed: false })
|
|
129
127
|
};
|
|
130
128
|
}
|
|
131
129
|
}
|
|
@@ -138,7 +136,7 @@ export function deserializeConnectOptions(options: Readonly<DevtoolsConnectOptio
|
|
|
138
136
|
if (deserializedOptions.autoEncryption?.[autoEncryptionOption]) {
|
|
139
137
|
deserializedOptions.autoEncryption = {
|
|
140
138
|
...deserializedOptions.autoEncryption,
|
|
141
|
-
[autoEncryptionOption]: EJSON.deserialize(deserializedOptions.autoEncryption[autoEncryptionOption])
|
|
139
|
+
[autoEncryptionOption]: EJSON.deserialize(deserializedOptions.autoEncryption[autoEncryptionOption], { relaxed: false })
|
|
142
140
|
};
|
|
143
141
|
}
|
|
144
142
|
}
|
|
@@ -535,7 +535,21 @@ describe('worker', () => {
|
|
|
535
535
|
await evaluate('print("Hi!")');
|
|
536
536
|
|
|
537
537
|
expect(evalListener.onPrint).to.have.been.calledWith([
|
|
538
|
-
{ printable: 'Hi!',
|
|
538
|
+
{ printable: 'Hi!', source: undefined, type: null }
|
|
539
|
+
]);
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
it('should correctly serialize bson objects', async() => {
|
|
543
|
+
const { init, evaluate } = caller;
|
|
544
|
+
const evalListener = createSpiedEvaluationListener();
|
|
545
|
+
|
|
546
|
+
exposed = exposeAll(evalListener, worker);
|
|
547
|
+
|
|
548
|
+
await init('mongodb://nodb/', {}, { nodb: true });
|
|
549
|
+
await evaluate('print(new ObjectId("62a209b0c7dc31e23ab9da45"))');
|
|
550
|
+
|
|
551
|
+
expect(evalListener.onPrint).to.have.been.calledWith([
|
|
552
|
+
{ printable: 'ObjectId("62a209b0c7dc31e23ab9da45")', source: undefined, type: 'InspectResult' }
|
|
539
553
|
]);
|
|
540
554
|
});
|
|
541
555
|
});
|
package/src/worker-runtime.ts
CHANGED
|
@@ -56,7 +56,16 @@ const evaluationListener = createCaller<WorkerRuntimeEvaluationListener>(
|
|
|
56
56
|
'onExit',
|
|
57
57
|
'onRunInterruptible'
|
|
58
58
|
],
|
|
59
|
-
parentPort
|
|
59
|
+
parentPort,
|
|
60
|
+
{
|
|
61
|
+
onPrint: function(results: RuntimeEvaluationResult[]): RuntimeEvaluationResult[][] {
|
|
62
|
+
// We're transforming an args array, so we have to return an array of
|
|
63
|
+
// args. onPrint only takes one arg which is an array of
|
|
64
|
+
// RuntimeEvaluationResult so in this case it will just return a
|
|
65
|
+
// single-element array that itself is an array.
|
|
66
|
+
return [results.map(serializeEvaluationResult)];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
60
69
|
);
|
|
61
70
|
|
|
62
71
|
const messageBus: MongoshBus = Object.assign(
|