@mongosh/node-runtime-worker-thread 1.10.1 → 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/rpc.spec.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
|
|
4
|
+
import type { Caller, Exposed } from './rpc';
|
|
4
5
|
import {
|
|
5
6
|
createCaller,
|
|
6
7
|
exposeAll,
|
|
7
8
|
close,
|
|
8
9
|
cancel,
|
|
9
|
-
Caller,
|
|
10
|
-
Exposed,
|
|
11
10
|
serialize,
|
|
12
11
|
deserialize,
|
|
13
|
-
removeTrailingUndefined
|
|
12
|
+
removeTrailingUndefined,
|
|
14
13
|
} from './rpc';
|
|
15
14
|
|
|
16
15
|
function createMockRpcMesageBus() {
|
|
@@ -26,25 +25,25 @@ function sleep(ms: number) {
|
|
|
26
25
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
describe('rpc helpers', ()
|
|
30
|
-
describe('serialize', ()
|
|
31
|
-
it('returns base64 representation of an input', ()
|
|
28
|
+
describe('rpc helpers', function () {
|
|
29
|
+
describe('serialize', function () {
|
|
30
|
+
it('returns base64 representation of an input', function () {
|
|
32
31
|
expect(serialize('Hello')).to.equal('data:;base64,/w0iBUhlbGxv');
|
|
33
32
|
});
|
|
34
33
|
});
|
|
35
34
|
|
|
36
|
-
describe('deserialize', ()
|
|
37
|
-
it("converts base64 representation of input back to it's original form", ()
|
|
35
|
+
describe('deserialize', function () {
|
|
36
|
+
it("converts base64 representation of input back to it's original form", function () {
|
|
38
37
|
expect(deserialize(serialize('Hello'))).to.equal('Hello');
|
|
39
38
|
});
|
|
40
39
|
|
|
41
|
-
it("returns original string if it's not a base64 data uri", ()
|
|
40
|
+
it("returns original string if it's not a base64 data uri", function () {
|
|
42
41
|
expect(deserialize('Hi')).to.equal('Hi');
|
|
43
42
|
});
|
|
44
43
|
});
|
|
45
44
|
|
|
46
|
-
describe('removeTrailingUndefined', ()
|
|
47
|
-
it('removes trailing undefineds from an array', ()
|
|
45
|
+
describe('removeTrailingUndefined', function () {
|
|
46
|
+
it('removes trailing undefineds from an array', function () {
|
|
48
47
|
expect(
|
|
49
48
|
removeTrailingUndefined([1, 2, 3, undefined, undefined, undefined])
|
|
50
49
|
).to.deep.equal([1, 2, 3]);
|
|
@@ -52,7 +51,7 @@ describe('rpc helpers', () => {
|
|
|
52
51
|
});
|
|
53
52
|
});
|
|
54
53
|
|
|
55
|
-
describe('rpc', ()
|
|
54
|
+
describe('rpc', function () {
|
|
56
55
|
let messageBus: EventEmitter;
|
|
57
56
|
let caller: Caller<{
|
|
58
57
|
meow(...args: any[]): string;
|
|
@@ -64,7 +63,7 @@ describe('rpc', () => {
|
|
|
64
63
|
}>;
|
|
65
64
|
let exposed: Exposed<unknown>;
|
|
66
65
|
|
|
67
|
-
afterEach(()
|
|
66
|
+
afterEach(function () {
|
|
68
67
|
if (messageBus) {
|
|
69
68
|
messageBus.removeAllListeners();
|
|
70
69
|
messageBus = null;
|
|
@@ -81,7 +80,7 @@ describe('rpc', () => {
|
|
|
81
80
|
}
|
|
82
81
|
});
|
|
83
82
|
|
|
84
|
-
it('exposes functions and allows to call them', async()
|
|
83
|
+
it('exposes functions and allows to call them', async function () {
|
|
85
84
|
messageBus = createMockRpcMesageBus();
|
|
86
85
|
caller = createCaller(['meow'], messageBus);
|
|
87
86
|
|
|
@@ -89,7 +88,7 @@ describe('rpc', () => {
|
|
|
89
88
|
{
|
|
90
89
|
meow() {
|
|
91
90
|
return 'Meow meow meow!';
|
|
92
|
-
}
|
|
91
|
+
},
|
|
93
92
|
},
|
|
94
93
|
messageBus
|
|
95
94
|
);
|
|
@@ -97,7 +96,7 @@ describe('rpc', () => {
|
|
|
97
96
|
expect(await caller.meow()).to.equal('Meow meow meow!');
|
|
98
97
|
});
|
|
99
98
|
|
|
100
|
-
it('serializes and de-serializes errors when thrown', async()
|
|
99
|
+
it('serializes and de-serializes errors when thrown', async function () {
|
|
101
100
|
messageBus = createMockRpcMesageBus();
|
|
102
101
|
caller = createCaller(['throws'], messageBus);
|
|
103
102
|
|
|
@@ -105,7 +104,7 @@ describe('rpc', () => {
|
|
|
105
104
|
{
|
|
106
105
|
throws() {
|
|
107
106
|
throw new TypeError('Uh-oh, error!');
|
|
108
|
-
}
|
|
107
|
+
},
|
|
109
108
|
},
|
|
110
109
|
messageBus
|
|
111
110
|
);
|
|
@@ -127,7 +126,7 @@ describe('rpc', () => {
|
|
|
127
126
|
.match(/TypeError: Uh-oh, error!\r?\n\s+at throws/);
|
|
128
127
|
});
|
|
129
128
|
|
|
130
|
-
it('throws on client if arguments are not serializable', async()
|
|
129
|
+
it('throws on client if arguments are not serializable', async function () {
|
|
131
130
|
messageBus = createMockRpcMesageBus();
|
|
132
131
|
caller = createCaller(['callMe'], messageBus);
|
|
133
132
|
|
|
@@ -135,7 +134,7 @@ describe('rpc', () => {
|
|
|
135
134
|
{
|
|
136
135
|
callMe(fn: any) {
|
|
137
136
|
fn(1, 2);
|
|
138
|
-
}
|
|
137
|
+
},
|
|
139
138
|
},
|
|
140
139
|
messageBus
|
|
141
140
|
);
|
|
@@ -154,7 +153,7 @@ describe('rpc', () => {
|
|
|
154
153
|
.match(/could not be cloned/);
|
|
155
154
|
});
|
|
156
155
|
|
|
157
|
-
it('throws on client if retured value from the server is not serializable', async()
|
|
156
|
+
it('throws on client if retured value from the server is not serializable', async function () {
|
|
158
157
|
messageBus = createMockRpcMesageBus();
|
|
159
158
|
caller = createCaller(['returnsFunction'], messageBus);
|
|
160
159
|
|
|
@@ -162,7 +161,7 @@ describe('rpc', () => {
|
|
|
162
161
|
{
|
|
163
162
|
returnsFunction() {
|
|
164
163
|
return () => {};
|
|
165
|
-
}
|
|
164
|
+
},
|
|
166
165
|
},
|
|
167
166
|
messageBus
|
|
168
167
|
);
|
|
@@ -181,15 +180,15 @@ describe('rpc', () => {
|
|
|
181
180
|
.match(/could not be cloned/);
|
|
182
181
|
});
|
|
183
182
|
|
|
184
|
-
describe('createCaller', ()
|
|
185
|
-
it('creates a caller with provided method names', ()
|
|
183
|
+
describe('createCaller', function () {
|
|
184
|
+
it('creates a caller with provided method names', function () {
|
|
186
185
|
messageBus = createMockRpcMesageBus();
|
|
187
186
|
caller = createCaller(['meow', 'woof'], messageBus);
|
|
188
187
|
expect(caller).to.have.property('meow');
|
|
189
188
|
expect(caller).to.have.property('woof');
|
|
190
189
|
});
|
|
191
190
|
|
|
192
|
-
it('attaches caller listener to provided process', (done)
|
|
191
|
+
it('attaches caller listener to provided process', function (done) {
|
|
193
192
|
messageBus = createMockRpcMesageBus();
|
|
194
193
|
caller = createCaller(['meow'], messageBus);
|
|
195
194
|
|
|
@@ -203,19 +202,19 @@ describe('rpc', () => {
|
|
|
203
202
|
});
|
|
204
203
|
});
|
|
205
204
|
|
|
206
|
-
describe('cancel', ()
|
|
207
|
-
it('stops all in-flight evaluations', async()
|
|
205
|
+
describe('cancel', function () {
|
|
206
|
+
it('stops all in-flight evaluations', async function () {
|
|
208
207
|
messageBus = createMockRpcMesageBus();
|
|
209
208
|
caller = createCaller(['neverResolves'], messageBus);
|
|
210
209
|
let err: Error;
|
|
211
210
|
try {
|
|
212
211
|
await Promise.all([
|
|
213
212
|
caller.neverResolves(),
|
|
214
|
-
(async() => {
|
|
213
|
+
(async () => {
|
|
215
214
|
// smol sleep to make sure we actually issued a call
|
|
216
215
|
await sleep(100);
|
|
217
216
|
caller[cancel]();
|
|
218
|
-
})()
|
|
217
|
+
})(),
|
|
219
218
|
]);
|
|
220
219
|
} catch (e: any) {
|
|
221
220
|
err = e;
|
|
@@ -226,15 +225,15 @@ describe('rpc', () => {
|
|
|
226
225
|
});
|
|
227
226
|
});
|
|
228
227
|
|
|
229
|
-
describe('exposeAll', ()
|
|
230
|
-
it('exposes passed methods on provided process', (done)
|
|
228
|
+
describe('exposeAll', function () {
|
|
229
|
+
it('exposes passed methods on provided process', function (done) {
|
|
231
230
|
messageBus = createMockRpcMesageBus();
|
|
232
231
|
|
|
233
232
|
exposed = exposeAll(
|
|
234
233
|
{
|
|
235
234
|
meow() {
|
|
236
235
|
return 'Meow meow meow meow!';
|
|
237
|
-
}
|
|
236
|
+
},
|
|
238
237
|
},
|
|
239
238
|
messageBus
|
|
240
239
|
);
|
|
@@ -255,12 +254,12 @@ describe('rpc', () => {
|
|
|
255
254
|
messageBus.emit('message', {
|
|
256
255
|
sender: 'postmsg-rpc/client',
|
|
257
256
|
func: 'meow',
|
|
258
|
-
id: '123abc'
|
|
257
|
+
id: '123abc',
|
|
259
258
|
});
|
|
260
259
|
});
|
|
261
260
|
|
|
262
|
-
describe('close', ()
|
|
263
|
-
it('disables all exposed listeners', ()
|
|
261
|
+
describe('close', function () {
|
|
262
|
+
it('disables all exposed listeners', function () {
|
|
264
263
|
messageBus = createMockRpcMesageBus();
|
|
265
264
|
exposed = exposeAll({ doSomething() {} }, messageBus);
|
|
266
265
|
expect(messageBus.listenerCount('message')).to.equal(1);
|
package/src/rpc.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
MessageData,
|
|
6
6
|
PostmsgRpcOptions,
|
|
7
7
|
ServerMessageData,
|
|
8
|
-
ClientMessageData
|
|
8
|
+
ClientMessageData,
|
|
9
9
|
} from 'postmsg-rpc';
|
|
10
10
|
|
|
11
11
|
export function serialize(data: unknown): string {
|
|
@@ -28,7 +28,7 @@ type RPCMessageBus = { on: Function; off: Function } & (
|
|
|
28
28
|
|
|
29
29
|
enum RPCMessageTypes {
|
|
30
30
|
Message,
|
|
31
|
-
Error
|
|
31
|
+
Error,
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
type RPCMessage = {
|
|
@@ -101,7 +101,7 @@ function getRPCOptions(messageBus: RPCMessageBus): PostmsgRpcOptions {
|
|
|
101
101
|
} catch (e: any) {
|
|
102
102
|
data.res = serialize({
|
|
103
103
|
type: RPCMessageTypes.Error,
|
|
104
|
-
payload: serializeError(e)
|
|
104
|
+
payload: serializeError(e),
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -122,7 +122,7 @@ function getRPCOptions(messageBus: RPCMessageBus): PostmsgRpcOptions {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
return data;
|
|
125
|
-
}
|
|
125
|
+
},
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -135,10 +135,10 @@ export type Exposed<T> = { [k in keyof T]: T[k] & { close(): void } } & {
|
|
|
135
135
|
};
|
|
136
136
|
|
|
137
137
|
export function exposeAll<O>(obj: O, messageBus: RPCMessageBus): Exposed<O> {
|
|
138
|
-
Object.entries(obj).forEach(([key, val]) => {
|
|
138
|
+
Object.entries(obj as Record<string, any>).forEach(([key, val]) => {
|
|
139
139
|
const { close } = expose(
|
|
140
140
|
key,
|
|
141
|
-
async(...args: unknown[]) => {
|
|
141
|
+
async (...args: unknown[]) => {
|
|
142
142
|
try {
|
|
143
143
|
return { type: RPCMessageTypes.Message, payload: await val(...args) };
|
|
144
144
|
} catch (e: any) {
|
|
@@ -156,10 +156,12 @@ export function exposeAll<O>(obj: O, messageBus: RPCMessageBus): Exposed<O> {
|
|
|
156
156
|
Object.defineProperty(obj, close, {
|
|
157
157
|
enumerable: false,
|
|
158
158
|
value() {
|
|
159
|
-
Object.values(obj
|
|
160
|
-
fn
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
Object.values(obj as Record<string, { close: () => void }>).forEach(
|
|
160
|
+
(fn) => {
|
|
161
|
+
fn.close();
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
},
|
|
163
165
|
});
|
|
164
166
|
return obj as Exposed<O>;
|
|
165
167
|
}
|
|
@@ -173,14 +175,14 @@ export function createCaller<Impl extends {}>(
|
|
|
173
175
|
methodNames: Extract<keyof Impl, string>[],
|
|
174
176
|
messageBus: RPCMessageBus,
|
|
175
177
|
processors: Partial<
|
|
176
|
-
Record<typeof methodNames[number], (...input: any[]) => any[]>
|
|
178
|
+
Record<(typeof methodNames)[number], (...input: any[]) => any[]>
|
|
177
179
|
> = {}
|
|
178
|
-
): Caller<Impl, typeof methodNames[number]> {
|
|
180
|
+
): Caller<Impl, (typeof methodNames)[number]> {
|
|
179
181
|
const obj = {};
|
|
180
182
|
const inflight = new Set<CancelablePromise<unknown>>();
|
|
181
183
|
methodNames.forEach((name) => {
|
|
182
184
|
const c = caller(name as string, getRPCOptions(messageBus));
|
|
183
|
-
(obj as any)[name] = async(...args: unknown[]) => {
|
|
185
|
+
(obj as any)[name] = async (...args: unknown[]) => {
|
|
184
186
|
const processed =
|
|
185
187
|
typeof processors[name] === 'function'
|
|
186
188
|
? processors[name]?.(...args)
|
|
@@ -200,8 +202,7 @@ export function createCaller<Impl extends {}>(
|
|
|
200
202
|
cancelable.cancel();
|
|
201
203
|
inflight.delete(cancelable);
|
|
202
204
|
}
|
|
203
|
-
}
|
|
205
|
+
},
|
|
204
206
|
});
|
|
205
|
-
return obj as Caller<Impl, typeof methodNames[number]>;
|
|
207
|
+
return obj as Caller<Impl, (typeof methodNames)[number]>;
|
|
206
208
|
}
|
|
207
|
-
|
package/src/serializer.spec.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DevtoolsConnectOptions } from '@mongosh/service-provider-server/lib/cli-service-provider';
|
|
1
|
+
import type { DevtoolsConnectOptions } from '@mongosh/service-provider-server/lib/cli-service-provider';
|
|
2
2
|
import { expect } from 'chai';
|
|
3
3
|
import { UUID, Long } from 'bson';
|
|
4
4
|
import {
|
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
deserializeEvaluationResult,
|
|
9
9
|
SerializedResultTypes,
|
|
10
10
|
serializeConnectOptions,
|
|
11
|
-
deserializeConnectOptions
|
|
11
|
+
deserializeConnectOptions,
|
|
12
12
|
} from './serializer';
|
|
13
13
|
import { dummyOptions } from './index.spec';
|
|
14
14
|
|
|
15
|
-
describe('serializer', ()
|
|
16
|
-
describe('serializeError', ()
|
|
17
|
-
it('serializer Error to plain object', ()
|
|
15
|
+
describe('serializer', function () {
|
|
16
|
+
describe('serializeError', function () {
|
|
17
|
+
it('serializer Error to plain object', function () {
|
|
18
18
|
const serialized = serializeError(new TypeError('Uh-oh'));
|
|
19
19
|
|
|
20
20
|
expect(serialized).to.have.own.property('name', 'TypeError');
|
|
@@ -23,8 +23,8 @@ describe('serializer', () => {
|
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
describe('deserializeError', ()
|
|
27
|
-
it('creates an instance of an error from plain object', ()
|
|
26
|
+
describe('deserializeError', function () {
|
|
27
|
+
it('creates an instance of an error from plain object', function () {
|
|
28
28
|
const err = deserializeError({ name: 'CustomError', message: 'Error!' });
|
|
29
29
|
|
|
30
30
|
expect(err).to.be.instanceof(Error);
|
|
@@ -33,21 +33,21 @@ describe('serializer', () => {
|
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
describe('serializeEvaluationResult', ()
|
|
37
|
-
it('should return primitive values as-is', ()
|
|
36
|
+
describe('serializeEvaluationResult', function () {
|
|
37
|
+
it('should return primitive values as-is', function () {
|
|
38
38
|
const serialized = serializeEvaluationResult({
|
|
39
39
|
type: 'primitive',
|
|
40
|
-
printable: 123
|
|
40
|
+
printable: 123,
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
expect(serialized).to.have.property('type', 'primitive');
|
|
44
44
|
expect(serialized).to.have.property('printable', 123);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
it('should serialize error values', ()
|
|
47
|
+
it('should serialize error values', function () {
|
|
48
48
|
const serialized = serializeEvaluationResult({
|
|
49
49
|
type: 'error',
|
|
50
|
-
printable: new SyntaxError('Ooops!')
|
|
50
|
+
printable: new SyntaxError('Ooops!'),
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
expect(serialized).to.have.property(
|
|
@@ -62,10 +62,10 @@ describe('serializer', () => {
|
|
|
62
62
|
expect(serialized).to.have.nested.property('printable.message', 'Ooops!');
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
it('should return inspect result for non shell-api result types (type === null)', ()
|
|
65
|
+
it('should return inspect result for non shell-api result types (type === null)', function () {
|
|
66
66
|
const serialized = serializeEvaluationResult({
|
|
67
67
|
type: null,
|
|
68
|
-
printable: function abc() {}
|
|
68
|
+
printable: function abc() {},
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
expect(serialized).to.have.property(
|
|
@@ -75,10 +75,10 @@ describe('serializer', () => {
|
|
|
75
75
|
expect(serialized).to.have.property('printable', '[Function: abc]');
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
it('should serialize shell-api result type', ()
|
|
78
|
+
it('should serialize shell-api result type', function () {
|
|
79
79
|
const serialized = serializeEvaluationResult({
|
|
80
80
|
type: 'TotallyRealShellApiType',
|
|
81
|
-
printable: { foo: 'bar' }
|
|
81
|
+
printable: { foo: 'bar' },
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
expect(serialized).to.have.property(
|
|
@@ -92,16 +92,16 @@ describe('serializer', () => {
|
|
|
92
92
|
expect(serialized)
|
|
93
93
|
.to.have.nested.property('printable.serializedValue')
|
|
94
94
|
.deep.equal({
|
|
95
|
-
foo: 'bar'
|
|
95
|
+
foo: 'bar',
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
describe('deserializeEvaluationResult', ()
|
|
101
|
-
it('should deserialize SerializedErrorResult', ()
|
|
100
|
+
describe('deserializeEvaluationResult', function () {
|
|
101
|
+
it('should deserialize SerializedErrorResult', function () {
|
|
102
102
|
const deserialized = deserializeEvaluationResult({
|
|
103
103
|
type: SerializedResultTypes.SerializedErrorResult,
|
|
104
|
-
printable: { name: 'TypeError', message: 'Uh-oh' }
|
|
104
|
+
printable: { name: 'TypeError', message: 'Uh-oh' },
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
expect(deserialized).to.have.property('printable').be.instanceof(Error);
|
|
@@ -115,13 +115,13 @@ describe('serializer', () => {
|
|
|
115
115
|
);
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
it('should deserialize SerializedShellApiResult', ()
|
|
118
|
+
it('should deserialize SerializedShellApiResult', function () {
|
|
119
119
|
const deserialized = deserializeEvaluationResult({
|
|
120
120
|
type: SerializedResultTypes.SerializedShellApiResult,
|
|
121
121
|
printable: {
|
|
122
122
|
origType: 'ShellApiResult',
|
|
123
|
-
serializedValue: { foo: 'bar' }
|
|
124
|
-
}
|
|
123
|
+
serializedValue: { foo: 'bar' },
|
|
124
|
+
},
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
expect(deserialized).to.have.property('type', 'ShellApiResult');
|
|
@@ -130,19 +130,22 @@ describe('serializer', () => {
|
|
|
130
130
|
.deep.equal({ foo: 'bar' });
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
it('should return unknown types as-is', ()
|
|
133
|
+
it('should return unknown types as-is', function () {
|
|
134
134
|
const deserialized = deserializeEvaluationResult({
|
|
135
135
|
type: 'SomethingSomethingResultType',
|
|
136
|
-
printable: 'Hello'
|
|
136
|
+
printable: 'Hello',
|
|
137
137
|
});
|
|
138
138
|
|
|
139
|
-
expect(deserialized).to.have.property(
|
|
139
|
+
expect(deserialized).to.have.property(
|
|
140
|
+
'type',
|
|
141
|
+
'SomethingSomethingResultType'
|
|
142
|
+
);
|
|
140
143
|
expect(deserialized).to.have.property('printable', 'Hello');
|
|
141
144
|
});
|
|
142
145
|
});
|
|
143
146
|
|
|
144
|
-
describe('connection options', ()
|
|
145
|
-
it('should serialize and deserialize FLE1 connection options', ()
|
|
147
|
+
describe('connection options', function () {
|
|
148
|
+
it('should serialize and deserialize FLE1 connection options', function () {
|
|
146
149
|
const options: DevtoolsConnectOptions = {
|
|
147
150
|
...dummyOptions,
|
|
148
151
|
autoEncryption: {
|
|
@@ -152,15 +155,15 @@ describe('serializer', () => {
|
|
|
152
155
|
properties: {
|
|
153
156
|
taxid: {
|
|
154
157
|
encrypt: {
|
|
155
|
-
keyId: [
|
|
158
|
+
keyId: [new UUID('a21ddc6a-8806-4384-9fdf-8ba02a767b5f')],
|
|
156
159
|
bsonType: 'string',
|
|
157
|
-
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random'
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
160
|
+
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
164
167
|
};
|
|
165
168
|
|
|
166
169
|
const serialized = serializeConnectOptions(options);
|
|
@@ -174,35 +177,44 @@ describe('serializer', () => {
|
|
|
174
177
|
properties: {
|
|
175
178
|
taxid: {
|
|
176
179
|
encrypt: {
|
|
177
|
-
keyId: [
|
|
180
|
+
keyId: [
|
|
181
|
+
{
|
|
182
|
+
$binary: {
|
|
183
|
+
base64: 'oh3caogGQ4Sf34ugKnZ7Xw==',
|
|
184
|
+
subType: '04',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
178
188
|
bsonType: 'string',
|
|
179
|
-
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random'
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
189
|
+
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random',
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
186
196
|
});
|
|
187
197
|
|
|
188
198
|
expect(deserializeConnectOptions(serialized)).to.deep.equal(options);
|
|
189
199
|
});
|
|
190
200
|
|
|
191
|
-
it('should serialize and deserialize FLE2 connection options', ()
|
|
201
|
+
it('should serialize and deserialize FLE2 connection options', function () {
|
|
192
202
|
const options: DevtoolsConnectOptions = {
|
|
193
203
|
...dummyOptions,
|
|
194
204
|
autoEncryption: {
|
|
195
205
|
encryptedFieldsMap: {
|
|
196
206
|
'hr.employees': {
|
|
197
|
-
fields: [
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
207
|
+
fields: [
|
|
208
|
+
{
|
|
209
|
+
path: 'phoneNumber',
|
|
210
|
+
keyId: new UUID('fd6275d7-9260-4e6c-a86b-68ec5240814a'),
|
|
211
|
+
bsonType: 'string',
|
|
212
|
+
queries: { queryType: 'equality', contention: new Long(0) },
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
206
218
|
};
|
|
207
219
|
|
|
208
220
|
const serialized = serializeConnectOptions(options);
|
|
@@ -212,15 +224,25 @@ describe('serializer', () => {
|
|
|
212
224
|
autoEncryption: {
|
|
213
225
|
encryptedFieldsMap: {
|
|
214
226
|
'hr.employees': {
|
|
215
|
-
fields: [
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
227
|
+
fields: [
|
|
228
|
+
{
|
|
229
|
+
path: 'phoneNumber',
|
|
230
|
+
keyId: {
|
|
231
|
+
$binary: {
|
|
232
|
+
base64: '/WJ115JgTmyoa2jsUkCBSg==',
|
|
233
|
+
subType: '04',
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
bsonType: 'string',
|
|
237
|
+
queries: {
|
|
238
|
+
queryType: 'equality',
|
|
239
|
+
contention: { $numberLong: '0' },
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
},
|
|
224
246
|
});
|
|
225
247
|
|
|
226
248
|
expect(deserializeConnectOptions(serialized)).to.deep.equal(options);
|