@mongodb-js/compass-utils 0.10.5 → 0.10.7
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/dist/.esm-wrapper.mjs +7 -0
- package/dist/events.d.ts +34 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +173 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/utility-process.d.ts +16 -0
- package/dist/utility-process.d.ts.map +1 -0
- package/dist/utility-process.js +28 -0
- package/package.json +7 -7
package/dist/.esm-wrapper.mjs
CHANGED
|
@@ -3,10 +3,17 @@ import mod from "./index.js";
|
|
|
3
3
|
export default mod;
|
|
4
4
|
export const cancellableWait = mod.cancellableWait;
|
|
5
5
|
export const createCancelError = mod.createCancelError;
|
|
6
|
+
export const errorFromEvent = mod.errorFromEvent;
|
|
6
7
|
export const getAppName = mod.getAppName;
|
|
7
8
|
export const getAppVersion = mod.getAppVersion;
|
|
8
9
|
export const getStoragePath = mod.getStoragePath;
|
|
9
10
|
export const isCancelError = mod.isCancelError;
|
|
11
|
+
export const isUtilityPortChannel = mod.isUtilityPortChannel;
|
|
12
|
+
export const listen = mod.listen;
|
|
13
|
+
export const once = mod.once;
|
|
14
|
+
export const openUtilityPort = mod.openUtilityPort;
|
|
10
15
|
export const promisifyAmpersandMethod = mod.promisifyAmpersandMethod;
|
|
11
16
|
export const raceWithAbort = mod.raceWithAbort;
|
|
12
17
|
export const throwIfAborted = mod.throwIfAborted;
|
|
18
|
+
export const utilityPortChannel = mod.utilityPortChannel;
|
|
19
|
+
export const waitUntil = mod.waitUntil;
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { EventEmitter } from 'node:events';
|
|
2
|
+
export type EventSource = Pick<EventTarget, 'addEventListener' | 'removeEventListener'> | Pick<EventEmitter, 'once' | 'on' | 'off'>;
|
|
3
|
+
/**
|
|
4
|
+
* Adds `listener` and returns a Disposable that removes it, so callers can use
|
|
5
|
+
* `using` or a DisposableStack instead of keeping track of the listener. Works
|
|
6
|
+
* with DOM EventTargets and Node.js-style emitters (EventEmitter, Electron's
|
|
7
|
+
* MessagePortMain and parentPort): `listener` gets the event for the former
|
|
8
|
+
* and the emitted arguments for the latter. With `once`, the listener is
|
|
9
|
+
* removed after it first runs.
|
|
10
|
+
*/
|
|
11
|
+
export declare function listen<Args extends unknown[]>(es: EventSource, event: string, listener: (...args: Args) => void, { once }?: {
|
|
12
|
+
once?: boolean;
|
|
13
|
+
}): Disposable;
|
|
14
|
+
/**
|
|
15
|
+
* Resolves with the arguments of the next `event`, like Node.js's
|
|
16
|
+
* `events.once`, for both kinds of target. Rejects if `signal` aborts.
|
|
17
|
+
*/
|
|
18
|
+
export declare function once<Args extends unknown[]>(es: EventSource, event: string, { signal }?: {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<Args>;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves with the arguments of the first `event` that `filter` accepts.
|
|
23
|
+
* `filter` may throw to reject instead, e.g. when an error message arrives.
|
|
24
|
+
*/
|
|
25
|
+
export declare function waitUntil<Args extends unknown[] = unknown[]>(es: EventSource, event: string, filter: (...args: Args) => boolean, { signal }?: {
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}): Promise<Args>;
|
|
28
|
+
/**
|
|
29
|
+
* The Error behind an `error` event. A DOM ErrorEvent carries it on `.error`;
|
|
30
|
+
* Node-style emitters and libraries like web-worker dispatch the Error itself.
|
|
31
|
+
* Falls back to an Error built from the event's message.
|
|
32
|
+
*/
|
|
33
|
+
export declare function errorFromEvent(event: unknown): Error;
|
|
34
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,WAAW,GACnB,IAAI,CAAC,WAAW,EAAE,kBAAkB,GAAG,qBAAqB,CAAC,GAC7D,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC,CAAC;AAyC9C;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,IAAI,SAAS,OAAO,EAAE,EAC3C,EAAE,EAAE,WAAW,EACf,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,IAAI,EACjC,EAAE,IAAY,EAAE,GAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAO,GACxC,UAAU,CAMZ;AASD;;;GAGG;AACH,wBAAsB,IAAI,CAAC,IAAI,SAAS,OAAO,EAAE,EAC/C,EAAE,EAAE,WAAW,EACf,KAAK,EAAE,MAAM,EACb,EAAE,MAAM,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACxC,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAAC,IAAI,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,EAChE,EAAE,EAAE,WAAW,EACf,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,EAClC,EAAE,MAAM,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACxC,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAOpD"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
3
|
+
if (value !== null && value !== void 0) {
|
|
4
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
5
|
+
var dispose, inner;
|
|
6
|
+
if (async) {
|
|
7
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
8
|
+
dispose = value[Symbol.asyncDispose];
|
|
9
|
+
}
|
|
10
|
+
if (dispose === void 0) {
|
|
11
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
12
|
+
dispose = value[Symbol.dispose];
|
|
13
|
+
if (async) inner = dispose;
|
|
14
|
+
}
|
|
15
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
16
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
17
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
18
|
+
}
|
|
19
|
+
else if (async) {
|
|
20
|
+
env.stack.push({ async: true });
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
25
|
+
return function (env) {
|
|
26
|
+
function fail(e) {
|
|
27
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
28
|
+
env.hasError = true;
|
|
29
|
+
}
|
|
30
|
+
var r, s = 0;
|
|
31
|
+
function next() {
|
|
32
|
+
while (r = env.stack.pop()) {
|
|
33
|
+
try {
|
|
34
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
35
|
+
if (r.dispose) {
|
|
36
|
+
var result = r.dispose.call(r.value);
|
|
37
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
38
|
+
}
|
|
39
|
+
else s |= 1;
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
fail(e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
46
|
+
if (env.hasError) throw env.error;
|
|
47
|
+
}
|
|
48
|
+
return next();
|
|
49
|
+
};
|
|
50
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
51
|
+
var e = new Error(message);
|
|
52
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.listen = listen;
|
|
56
|
+
exports.once = once;
|
|
57
|
+
exports.waitUntil = waitUntil;
|
|
58
|
+
exports.errorFromEvent = errorFromEvent;
|
|
59
|
+
function isEventTarget(et) {
|
|
60
|
+
return (!!et &&
|
|
61
|
+
typeof et === 'object' &&
|
|
62
|
+
'addEventListener' in et &&
|
|
63
|
+
typeof et.addEventListener === 'function');
|
|
64
|
+
}
|
|
65
|
+
function addListener(es, event, listener, { once = false } = {}) {
|
|
66
|
+
if (isEventTarget(es)) {
|
|
67
|
+
es.addEventListener(event, listener, { once });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (once) {
|
|
71
|
+
es.once(event, listener);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
es.on(event, listener);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function removeListener(es, event, listener) {
|
|
78
|
+
if (isEventTarget(es)) {
|
|
79
|
+
es.removeEventListener(event, listener);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
es.off(event, listener);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Adds `listener` and returns a Disposable that removes it, so callers can use
|
|
86
|
+
* `using` or a DisposableStack instead of keeping track of the listener. Works
|
|
87
|
+
* with DOM EventTargets and Node.js-style emitters (EventEmitter, Electron's
|
|
88
|
+
* MessagePortMain and parentPort): `listener` gets the event for the former
|
|
89
|
+
* and the emitted arguments for the latter. With `once`, the listener is
|
|
90
|
+
* removed after it first runs.
|
|
91
|
+
*/
|
|
92
|
+
function listen(es, event, listener, { once = false } = {}) {
|
|
93
|
+
addListener(es, event, listener, { once });
|
|
94
|
+
return {
|
|
95
|
+
[Symbol.dispose]: () => removeListener(es, event, listener),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function rejectOnAbort(signal, reject) {
|
|
99
|
+
return signal && listen(signal, 'abort', () => reject(signal.reason));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Resolves with the arguments of the next `event`, like Node.js's
|
|
103
|
+
* `events.once`, for both kinds of target. Rejects if `signal` aborts.
|
|
104
|
+
*/
|
|
105
|
+
async function once(es, event, { signal } = {}) {
|
|
106
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
107
|
+
try {
|
|
108
|
+
signal?.throwIfAborted();
|
|
109
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
110
|
+
const _listener = __addDisposableResource(env_1, listen(es, event, (...args) => resolve(args), {
|
|
111
|
+
once: true,
|
|
112
|
+
}), false);
|
|
113
|
+
const _abort = __addDisposableResource(env_1, rejectOnAbort(signal, reject), false);
|
|
114
|
+
return await promise;
|
|
115
|
+
}
|
|
116
|
+
catch (e_1) {
|
|
117
|
+
env_1.error = e_1;
|
|
118
|
+
env_1.hasError = true;
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
__disposeResources(env_1);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolves with the arguments of the first `event` that `filter` accepts.
|
|
126
|
+
* `filter` may throw to reject instead, e.g. when an error message arrives.
|
|
127
|
+
*/
|
|
128
|
+
async function waitUntil(es, event, filter, { signal } = {}) {
|
|
129
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
130
|
+
try {
|
|
131
|
+
signal?.throwIfAborted();
|
|
132
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
133
|
+
// Stop listening inside the listener: an emitter can emit again before any
|
|
134
|
+
// promise callback runs, and `filter` must not see those events.
|
|
135
|
+
const waiter = __addDisposableResource(env_2, listen(es, event, (...args) => {
|
|
136
|
+
try {
|
|
137
|
+
if (!filter(...args))
|
|
138
|
+
return;
|
|
139
|
+
waiter[Symbol.dispose]();
|
|
140
|
+
resolve(args);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
waiter[Symbol.dispose]();
|
|
144
|
+
reject(error);
|
|
145
|
+
}
|
|
146
|
+
}), false);
|
|
147
|
+
const _abort = __addDisposableResource(env_2, rejectOnAbort(signal, (error) => {
|
|
148
|
+
waiter[Symbol.dispose]();
|
|
149
|
+
reject(error);
|
|
150
|
+
}), false);
|
|
151
|
+
return await promise;
|
|
152
|
+
}
|
|
153
|
+
catch (e_2) {
|
|
154
|
+
env_2.error = e_2;
|
|
155
|
+
env_2.hasError = true;
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
__disposeResources(env_2);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The Error behind an `error` event. A DOM ErrorEvent carries it on `.error`;
|
|
163
|
+
* Node-style emitters and libraries like web-worker dispatch the Error itself.
|
|
164
|
+
* Falls back to an Error built from the event's message.
|
|
165
|
+
*/
|
|
166
|
+
function errorFromEvent(event) {
|
|
167
|
+
if (event instanceof Error)
|
|
168
|
+
return event;
|
|
169
|
+
const { error, message } = (event ?? {});
|
|
170
|
+
if (error instanceof Error)
|
|
171
|
+
return error;
|
|
172
|
+
return new Error(typeof message === 'string' ? message : `Unknown error: ${String(message)}`);
|
|
173
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,7 @@ export type { AmpersandMethodOptions } from './promisify-ampersand-method';
|
|
|
2
2
|
export { promisifyAmpersandMethod } from './promisify-ampersand-method';
|
|
3
3
|
export { getAppName, getStoragePath, getAppVersion } from './electron';
|
|
4
4
|
export { raceWithAbort, cancellableWait, createCancelError, isCancelError, throwIfAborted, } from './cancellable-promise';
|
|
5
|
+
export { utilityPortChannel, isUtilityPortChannel, openUtilityPort, } from './utility-process';
|
|
6
|
+
export { errorFromEvent, listen, once, waitUntil } from './events';
|
|
7
|
+
export type { EventSource } from './events';
|
|
5
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EACL,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EACL,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACnE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwIfAborted = exports.isCancelError = exports.createCancelError = exports.cancellableWait = exports.raceWithAbort = exports.getAppVersion = exports.getStoragePath = exports.getAppName = exports.promisifyAmpersandMethod = void 0;
|
|
3
|
+
exports.waitUntil = exports.once = exports.listen = exports.errorFromEvent = exports.openUtilityPort = exports.isUtilityPortChannel = exports.utilityPortChannel = exports.throwIfAborted = exports.isCancelError = exports.createCancelError = exports.cancellableWait = exports.raceWithAbort = exports.getAppVersion = exports.getStoragePath = exports.getAppName = exports.promisifyAmpersandMethod = void 0;
|
|
4
4
|
var promisify_ampersand_method_1 = require("./promisify-ampersand-method");
|
|
5
5
|
Object.defineProperty(exports, "promisifyAmpersandMethod", { enumerable: true, get: function () { return promisify_ampersand_method_1.promisifyAmpersandMethod; } });
|
|
6
6
|
var electron_1 = require("./electron");
|
|
@@ -13,3 +13,12 @@ Object.defineProperty(exports, "cancellableWait", { enumerable: true, get: funct
|
|
|
13
13
|
Object.defineProperty(exports, "createCancelError", { enumerable: true, get: function () { return cancellable_promise_1.createCancelError; } });
|
|
14
14
|
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return cancellable_promise_1.isCancelError; } });
|
|
15
15
|
Object.defineProperty(exports, "throwIfAborted", { enumerable: true, get: function () { return cancellable_promise_1.throwIfAborted; } });
|
|
16
|
+
var utility_process_1 = require("./utility-process");
|
|
17
|
+
Object.defineProperty(exports, "utilityPortChannel", { enumerable: true, get: function () { return utility_process_1.utilityPortChannel; } });
|
|
18
|
+
Object.defineProperty(exports, "isUtilityPortChannel", { enumerable: true, get: function () { return utility_process_1.isUtilityPortChannel; } });
|
|
19
|
+
Object.defineProperty(exports, "openUtilityPort", { enumerable: true, get: function () { return utility_process_1.openUtilityPort; } });
|
|
20
|
+
var events_1 = require("./events");
|
|
21
|
+
Object.defineProperty(exports, "errorFromEvent", { enumerable: true, get: function () { return events_1.errorFromEvent; } });
|
|
22
|
+
Object.defineProperty(exports, "listen", { enumerable: true, get: function () { return events_1.listen; } });
|
|
23
|
+
Object.defineProperty(exports, "once", { enumerable: true, get: function () { return events_1.once; } });
|
|
24
|
+
Object.defineProperty(exports, "waitUntil", { enumerable: true, get: function () { return events_1.waitUntil; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How renderer code reaches a utility process. Everything follows from the
|
|
3
|
+
* utility's name, which is its directory under packages/compass/src/utilities.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Channel name the renderer posts its end of a MessageChannel on for the utility to pickup.
|
|
7
|
+
*/
|
|
8
|
+
export declare function utilityPortChannel(name: string): string;
|
|
9
|
+
/** Whether `channel` is one `utilityPortChannel` produces, for any utility. */
|
|
10
|
+
export declare function isUtilityPortChannel(channel: unknown): channel is `compass:utility:${string}:port`;
|
|
11
|
+
/**
|
|
12
|
+
* Opens a channel to the named utility. The preload script forwards the other
|
|
13
|
+
* end to main, which hands it to the utility.
|
|
14
|
+
*/
|
|
15
|
+
export declare function openUtilityPort(name: string): MessagePort;
|
|
16
|
+
//# sourceMappingURL=utility-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility-process.d.ts","sourceRoot":"","sources":["../src/utility-process.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,+EAA+E;AAC/E,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,GACf,OAAO,IAAI,mBAAmB,MAAM,OAAO,CAI7C;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAIzD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* How renderer code reaches a utility process. Everything follows from the
|
|
4
|
+
* utility's name, which is its directory under packages/compass/src/utilities.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.utilityPortChannel = utilityPortChannel;
|
|
8
|
+
exports.isUtilityPortChannel = isUtilityPortChannel;
|
|
9
|
+
exports.openUtilityPort = openUtilityPort;
|
|
10
|
+
/**
|
|
11
|
+
* Channel name the renderer posts its end of a MessageChannel on for the utility to pickup.
|
|
12
|
+
*/
|
|
13
|
+
function utilityPortChannel(name) {
|
|
14
|
+
return `compass:utility:${name}:port`;
|
|
15
|
+
}
|
|
16
|
+
/** Whether `channel` is one `utilityPortChannel` produces, for any utility. */
|
|
17
|
+
function isUtilityPortChannel(channel) {
|
|
18
|
+
return (typeof channel === 'string' && /^compass:utility:[^:]+:port$/.test(channel));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Opens a channel to the named utility. The preload script forwards the other
|
|
22
|
+
* end to main, which hands it to the utility.
|
|
23
|
+
*/
|
|
24
|
+
function openUtilityPort(name) {
|
|
25
|
+
const { port1, port2 } = new MessageChannel();
|
|
26
|
+
window.postMessage({ type: utilityPortChannel(name) }, '*', [port2]);
|
|
27
|
+
return port1;
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"email": "compass@mongodb.com"
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/mongodb-js/compass",
|
|
16
|
-
"version": "0.10.
|
|
16
|
+
"version": "0.10.7",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "https://github.com/mongodb-js/compass.git"
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write ."
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@mongodb-js/eslint-config-compass": "^1.4.
|
|
54
|
-
"@mongodb-js/mocha-config-compass": "^1.8.
|
|
55
|
-
"@mongodb-js/prettier-config-compass": "^1.2.
|
|
56
|
-
"@mongodb-js/tsconfig-compass": "^1.3.
|
|
53
|
+
"@mongodb-js/eslint-config-compass": "^1.4.30",
|
|
54
|
+
"@mongodb-js/mocha-config-compass": "^1.8.2",
|
|
55
|
+
"@mongodb-js/prettier-config-compass": "^1.2.10",
|
|
56
|
+
"@mongodb-js/tsconfig-compass": "^1.3.2",
|
|
57
57
|
"@types/chai": "^4.2.21",
|
|
58
58
|
"@types/mocha": "^9.0.0",
|
|
59
59
|
"@types/sinon-chai": "^3.2.5",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@electron/remote": "^2.1.3",
|
|
70
|
-
"electron": "^
|
|
70
|
+
"electron": "^45.0.0"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "ba44a9dbfe032bf5acb4b6daac0718fbc96892c0"
|
|
73
73
|
}
|