@openfin/core 31.74.1 → 31.74.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 (120) hide show
  1. package/package.json +1 -1
  2. package/src/OpenFin.d.ts +284 -253
  3. package/src/OpenFin.js +0 -2
  4. package/src/api/api-exposer/api-consumer.d.ts +28 -0
  5. package/src/api/api-exposer/api-consumer.js +28 -0
  6. package/src/api/api-exposer/api-exposer.d.ts +35 -0
  7. package/src/api/api-exposer/api-exposer.js +38 -0
  8. package/src/api/api-exposer/decorators.d.ts +10 -0
  9. package/src/api/api-exposer/decorators.js +18 -0
  10. package/src/api/api-exposer/index.d.ts +4 -0
  11. package/src/api/api-exposer/index.js +20 -0
  12. package/src/api/api-exposer/strategies/index.d.ts +1 -0
  13. package/src/api/api-exposer/strategies/index.js +17 -0
  14. package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.d.ts +14 -0
  15. package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.js +20 -0
  16. package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.d.ts +20 -0
  17. package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.js +23 -0
  18. package/src/api/api-exposer/strategies/openfin-channels/index.d.ts +2 -0
  19. package/src/api/api-exposer/strategies/openfin-channels/index.js +18 -0
  20. package/src/api/application/Factory.js +1 -2
  21. package/src/api/application/Instance.js +23 -5
  22. package/src/api/base.d.ts +5 -2
  23. package/src/api/base.js +7 -0
  24. package/src/api/events/application.d.ts +22 -22
  25. package/src/api/events/base.d.ts +6 -9
  26. package/src/api/events/channel.d.ts +5 -5
  27. package/src/api/events/emitterMap.d.ts +1 -1
  28. package/src/api/events/externalApplication.d.ts +3 -3
  29. package/src/api/events/frame.d.ts +5 -5
  30. package/src/api/events/globalHotkey.d.ts +3 -3
  31. package/src/api/events/platform.d.ts +3 -3
  32. package/src/api/events/system.d.ts +18 -18
  33. package/src/api/events/typedEventEmitter.d.ts +1 -1
  34. package/src/api/events/view.d.ts +17 -14
  35. package/src/api/events/webcontents.d.ts +24 -22
  36. package/src/api/events/window.d.ts +65 -57
  37. package/src/api/fin.d.ts +1 -1
  38. package/src/api/frame/Instance.d.ts +1 -1
  39. package/src/api/interappbus/channel/channel.d.ts +4 -4
  40. package/src/api/interappbus/channel/channel.js +3 -3
  41. package/src/api/interappbus/channel/client.d.ts +2 -2
  42. package/src/api/interappbus/channel/client.js +20 -20
  43. package/src/api/interappbus/channel/connection-manager.d.ts +1 -1
  44. package/src/api/interappbus/channel/connection-manager.js +12 -12
  45. package/src/api/interappbus/channel/index.d.ts +2 -2
  46. package/src/api/interappbus/channel/index.js +1 -1
  47. package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +1 -1
  48. package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +2 -2
  49. package/src/api/interappbus/channel/protocols/combined/strategy.js +5 -5
  50. package/src/api/interappbus/channel/protocols/index.d.ts +4 -4
  51. package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +1 -1
  52. package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +1 -1
  53. package/src/api/interappbus/channel/protocols/strategy-types.d.ts +4 -4
  54. package/src/api/interappbus/channel/protocols/strategy.d.ts +3 -3
  55. package/src/api/interappbus/channel/provider.d.ts +5 -5
  56. package/src/api/interappbus/channel/provider.js +24 -24
  57. package/src/api/interop/InteropBroker.d.ts +1 -1
  58. package/src/api/interop/InteropBroker.js +6 -2
  59. package/src/api/interop/fdc3/PrivateChannelClient.d.ts +2 -1
  60. package/src/api/interop/fdc3/PrivateChannelClient.js +15 -7
  61. package/src/api/interop/fdc3/PrivateChannelProvider.d.ts +16 -2
  62. package/src/api/interop/fdc3/PrivateChannelProvider.js +80 -28
  63. package/src/api/interop/fdc3/fdc3-1.2.js +53 -5
  64. package/src/api/interop/fdc3/fdc3-2.0.d.ts +11 -10
  65. package/src/api/interop/fdc3/fdc3-2.0.js +18 -19
  66. package/src/api/interop/fdc3/shapes/fdc3v1.d.ts +3 -3
  67. package/src/api/interop/fdc3/shapes/fdc3v2.d.ts +5 -5
  68. package/src/api/interop/fdc3/utils.d.ts +17 -0
  69. package/src/api/interop/fdc3/utils.js +75 -21
  70. package/src/api/interop/fdc3/versions.d.ts +1 -1
  71. package/src/api/interop/utils.d.ts +0 -1
  72. package/src/api/interop/utils.js +1 -9
  73. package/src/api/me.d.ts +3 -3
  74. package/src/api/platform/Factory.js +5 -9
  75. package/src/api/platform/Instance.d.ts +1 -1
  76. package/src/api/platform/Instance.js +1 -1
  77. package/src/api/platform/common-utils.d.ts +1 -1
  78. package/src/api/platform/layout/Factory.d.ts +1 -1
  79. package/src/api/platform/layout/Factory.js +11 -3
  80. package/src/api/platform/layout/Instance.d.ts +9 -3
  81. package/src/api/platform/layout/Instance.js +26 -1
  82. package/src/api/platform/layout/controllers/layout-content-cache.d.ts +9 -0
  83. package/src/api/platform/layout/controllers/layout-content-cache.js +54 -0
  84. package/src/api/platform/layout/controllers/layout-entities-controller.d.ts +117 -0
  85. package/src/api/platform/layout/controllers/layout-entities-controller.js +270 -0
  86. package/src/api/platform/layout/controllers/splitter-controller.d.ts +1 -1
  87. package/src/api/platform/layout/entities/layout-entities.d.ts +144 -0
  88. package/src/api/platform/layout/entities/layout-entities.js +216 -0
  89. package/src/api/platform/layout/entities/shapes.d.ts +6 -0
  90. package/src/api/platform/layout/entities/shapes.js +2 -0
  91. package/src/api/platform/layout/layout.constants.d.ts +1 -0
  92. package/src/api/platform/layout/layout.constants.js +4 -0
  93. package/src/api/platform/layout/shapes.d.ts +4 -1
  94. package/src/api/platform/layout/utils/layout-traversal.d.ts +4 -0
  95. package/src/api/platform/layout/utils/layout-traversal.js +65 -0
  96. package/src/api/system/index.d.ts +13 -13
  97. package/src/api/view/Instance.d.ts +13 -3
  98. package/src/api/view/Instance.js +41 -4
  99. package/src/environment/browser.d.ts +1 -1
  100. package/src/environment/environment.d.ts +1 -1
  101. package/src/environment/node-env.d.ts +1 -1
  102. package/src/environment/openfin-env.d.ts +1 -1
  103. package/src/mock.d.ts +1 -1
  104. package/src/mock.js +5 -2
  105. package/src/shapes/ERROR_BOX_TYPES.d.ts +1 -1
  106. package/src/shapes/protocol.d.ts +3 -3
  107. package/src/transport/transport-errors.d.ts +2 -2
  108. package/src/transport/transport.d.ts +3 -3
  109. package/src/transport/transport.js +1 -4
  110. package/src/transport/wire.d.ts +14 -13
  111. package/src/util/channel-api-relay.d.ts +13 -0
  112. package/src/util/channel-api-relay.js +37 -0
  113. package/src/util/errors.d.ts +2 -2
  114. package/src/util/http.js +4 -2
  115. package/src/util/lazy.d.ts +16 -0
  116. package/src/util/lazy.js +26 -0
  117. package/src/util/promises.d.ts +1 -1
  118. package/src/util/reversible-map.d.ts +11 -0
  119. package/src/util/reversible-map.js +49 -0
  120. package/src/util/utilTypes.d.ts +1 -1
@@ -2,7 +2,7 @@ import type * as OpenFin from '../OpenFin';
2
2
  import { ChildContentOptions, Environment } from './environment';
3
3
  import { NewConnectConfig } from '../transport/wire';
4
4
  import { BrowserEnvironment } from './browser';
5
- declare type EntityType = OpenFin.EntityType;
5
+ type EntityType = OpenFin.EntityType;
6
6
  export default class OpenFinEnvironment extends BrowserEnvironment implements Environment {
7
7
  #private;
8
8
  private raiseEventAsync;
package/src/mock.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type * as OpenFin from './OpenFin';
1
+ import * as OpenFin from './OpenFin';
2
2
  export declare const fin: OpenFin.Fin<"window" | "view">;
3
3
  export default OpenFin;
package/src/mock.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fin = void 0;
4
- const events_1 = require("events");
5
4
  /* eslint-disable import/prefer-default-export */
6
5
  /* eslint-disable spaced-comment */
7
6
  /* eslint-disable @typescript-eslint/triple-slash-reference */
8
7
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
9
8
  /* eslint-disable class-methods-use-this */
10
- /// <reference path="../OpenFin.d.ts"/>
9
+ const events_1 = require("events");
10
+ const OpenFin = require("./OpenFin");
11
11
  const fin_1 = require("./api/fin");
12
12
  const transport_1 = require("./transport/transport");
13
13
  const me_1 = require("./api/me");
@@ -24,6 +24,9 @@ class MockWire extends events_1.EventEmitter {
24
24
  shutdown() {
25
25
  throw new Error('You are not running in OpenFin.');
26
26
  }
27
+ getPort() {
28
+ throw new Error('This transport has no port');
29
+ }
27
30
  // eslint-disable-next-line no-useless-constructor
28
31
  constructor() {
29
32
  super();
@@ -1 +1 @@
1
- export declare type ERROR_BOX_TYPES = 'OF_error_box:app_initialization' | 'OF_error_box:main_process' | 'OF_error_box:renderer_crash';
1
+ export type ERROR_BOX_TYPES = 'OF_error_box:app_initialization' | 'OF_error_box:main_process' | 'OF_error_box:renderer_crash';
@@ -149,12 +149,12 @@ export interface ProtocolMap extends ProtocolMapBase {
149
149
  response: OpenFin.PrinterInfo[];
150
150
  };
151
151
  }
152
- declare type ApiCall<Request, Response> = {
152
+ type ApiCall<Request, Response> = {
153
153
  request: Request;
154
154
  response: Response;
155
155
  };
156
- declare type VoidCall = ApiCall<void, void>;
157
- declare type IdentityCall<AdditionalPayload = {}, Response = void> = ApiCall<AdditionalPayload & OpenFin.Identity, Response>;
156
+ type VoidCall = ApiCall<void, void>;
157
+ type IdentityCall<AdditionalPayload = {}, Response = void> = ApiCall<AdditionalPayload & OpenFin.Identity, Response>;
158
158
  interface ProtocolMapBase {
159
159
  [action: string]: {
160
160
  request: any;
@@ -1,5 +1,5 @@
1
1
  import { ErrorPlainObject } from '../util/errors';
2
- export declare type ReadyState = 'CONNECTING' | 'OPEN' | 'CLOSING' | 'CLOSED';
2
+ export type ReadyState = 'CONNECTING' | 'OPEN' | 'CLOSING' | 'CLOSED';
3
3
  export declare class DisconnectedError extends Error {
4
4
  constructor(readyState: ReadyState);
5
5
  readyState: ReadyState;
@@ -14,7 +14,7 @@ export declare class NotImplementedError extends Error {
14
14
  }
15
15
  export declare class NotSupportedError extends Error {
16
16
  }
17
- export declare type RuntimeErrorPayload = {
17
+ export type RuntimeErrorPayload = {
18
18
  reason: string;
19
19
  error?: ErrorPlainObject;
20
20
  };
@@ -8,8 +8,8 @@ import { EntityTypeHelpers } from '../api/me';
8
8
  import { ProtocolMap } from '../shapes/protocol';
9
9
  import { NamedEvent } from '../api/events/base';
10
10
  import { ErrorPlainObject } from '../util/errors';
11
- declare type EntityType = OpenFin.EntityType;
12
- export declare type MessageHandler = (data: any) => boolean;
11
+ type EntityType = OpenFin.EntityType;
12
+ export type MessageHandler = (data: any) => boolean;
13
13
  export declare class Transport<MeType extends EntityType = EntityType> extends EventEmitter {
14
14
  #private;
15
15
  protected wireListeners: Map<number, {
@@ -49,7 +49,7 @@ export interface EventMessage extends Message<NamedEvent> {
49
49
  action: 'process-desktop-event';
50
50
  payload: NamedEvent;
51
51
  }
52
- export declare type Payload<Success extends boolean = boolean, Data = any> = {
52
+ export type Payload<Success extends boolean = boolean, Data = any> = {
53
53
  success: Success;
54
54
  data: Success extends true ? Data : never;
55
55
  reason: Success extends false ? string : never;
@@ -32,11 +32,8 @@ class Transport extends events_1.EventEmitter {
32
32
  };
33
33
  // This function is only used in our tests.
34
34
  this.getPort = () => {
35
- if (this.environment.constructor.name !== 'NodeEnvironment') {
36
- throw new transport_errors_1.NotImplementedError('Not Implemented');
37
- }
38
35
  const wire = __classPrivateFieldGet(this, _Transport_wire, "f");
39
- return wire.wire.url.split(':').slice(-1)[0];
36
+ return wire.getPort();
40
37
  };
41
38
  __classPrivateFieldSet(this, _Transport_wire, new WireType(this.onmessage.bind(this)), "f");
42
39
  this.environment = environment;
@@ -1,16 +1,17 @@
1
1
  /// <reference types="mocha" />
2
2
  /// <reference types="node" />
3
3
  import EventEmitter = NodeJS.EventEmitter;
4
- export declare type Wire = EventEmitter & {
4
+ export type Wire = EventEmitter & {
5
5
  connect(address: string, WsConstructor: typeof WebSocket): Promise<any>;
6
6
  connectSync(): any;
7
7
  send(data: any): Promise<any>;
8
8
  shutdown(): Promise<void>;
9
+ getPort(): string;
9
10
  };
10
- export declare type WireConstructor = {
11
+ export type WireConstructor = {
11
12
  new (onmessage: (data: any) => void): Wire;
12
13
  };
13
- export declare type RuntimeConfig = {
14
+ export type RuntimeConfig = {
14
15
  version: string;
15
16
  fallbackVersion?: string;
16
17
  securityRealm?: string;
@@ -18,11 +19,11 @@ export declare type RuntimeConfig = {
18
19
  arguments?: string;
19
20
  rvmDir?: string;
20
21
  };
21
- export declare type ServiceConfig = {
22
+ export type ServiceConfig = {
22
23
  name: string;
23
24
  manifestUrl: string;
24
25
  };
25
- export declare type BaseConfig = {
26
+ export type BaseConfig = {
26
27
  uuid?: string;
27
28
  address?: string;
28
29
  name?: string;
@@ -50,22 +51,22 @@ export declare type BaseConfig = {
50
51
  customItems?: [any];
51
52
  timeout?: number;
52
53
  };
53
- export declare type ConfigWithUuid = BaseConfig & {
54
+ export type ConfigWithUuid = BaseConfig & {
54
55
  uuid: string;
55
56
  };
56
- export declare type ExistingConnectConfig = ConfigWithUuid & {
57
+ export type ExistingConnectConfig = ConfigWithUuid & {
57
58
  address: string;
58
59
  };
59
- export declare type ConfigWithRuntime = BaseConfig & {
60
+ export type ConfigWithRuntime = BaseConfig & {
60
61
  runtime: RuntimeConfig;
61
62
  };
62
- export declare type ExternalConfig = BaseConfig & {
63
+ export type ExternalConfig = BaseConfig & {
63
64
  manifestUrl: string;
64
65
  };
65
- export declare type NewConnectConfig = ConfigWithUuid & ConfigWithRuntime;
66
- export declare type PortDiscoveryConfig = (ExternalConfig & ConfigWithRuntime) | NewConnectConfig;
67
- export declare type ConnectConfig = ExistingConnectConfig | NewConnectConfig | ExternalConfig;
68
- export declare type InternalConnectConfig = ExistingConnectConfig | NewConnectConfig;
66
+ export type NewConnectConfig = ConfigWithUuid & ConfigWithRuntime;
67
+ export type PortDiscoveryConfig = (ExternalConfig & ConfigWithRuntime) | NewConnectConfig;
68
+ export type ConnectConfig = ExistingConnectConfig | NewConnectConfig | ExternalConfig;
69
+ export type InternalConnectConfig = ExistingConnectConfig | NewConnectConfig;
69
70
  export interface RemoteConfig extends ExistingConnectConfig {
70
71
  token: string;
71
72
  }
@@ -0,0 +1,13 @@
1
+ import type * as OpenFin from '../OpenFin';
2
+ /**
3
+ * @internal
4
+ * Create a channel relay for a given channel exposition, allowing a single provider to route
5
+ * actions to the designated clients.
6
+ *
7
+ * Designed to be used in conjunction with @expose
8
+ *
9
+ * @param channelProvider The channel provider to relay the actions on.
10
+ * @param config Determines which actions to relay. Please ensure action prefix matches the exposed api.
11
+ */
12
+ export declare const relayChannelClientApi: (channelProvider: OpenFin.ChannelProvider, relayId: string) => Promise<void>;
13
+ export declare const createRelayedDispatch: (client: OpenFin.ChannelClient, target: OpenFin.Identity, relayId: string, relayErrorMsg?: string) => OpenFin.ChannelClient['dispatch'];
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRelayedDispatch = exports.relayChannelClientApi = void 0;
4
+ /**
5
+ * @internal
6
+ * Create a channel relay for a given channel exposition, allowing a single provider to route
7
+ * actions to the designated clients.
8
+ *
9
+ * Designed to be used in conjunction with @expose
10
+ *
11
+ * @param channelProvider The channel provider to relay the actions on.
12
+ * @param config Determines which actions to relay. Please ensure action prefix matches the exposed api.
13
+ */
14
+ const relayChannelClientApi = async (channelProvider, relayId) => {
15
+ channelProvider.register(`relay:${relayId}`, ({ action, target, payload }) => {
16
+ return channelProvider.dispatch(target, action, payload);
17
+ });
18
+ await Promise.resolve();
19
+ };
20
+ exports.relayChannelClientApi = relayChannelClientApi;
21
+ const createRelayedDispatch = (client, target, relayId, relayErrorMsg) => async (action, payload) => {
22
+ try {
23
+ return await client.dispatch(`relay:${relayId}`, {
24
+ action,
25
+ payload,
26
+ target
27
+ });
28
+ }
29
+ catch (e) {
30
+ if (e.message.includes('no longer connected') && relayErrorMsg) {
31
+ throw new Error(relayErrorMsg);
32
+ }
33
+ ;
34
+ throw e;
35
+ }
36
+ };
37
+ exports.createRelayedDispatch = createRelayedDispatch;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * This function converts JS errors into plain objects
3
3
  */
4
- export declare type ErrorPlainObject = {
5
- stack: string;
4
+ export type ErrorPlainObject = {
5
+ stack?: string;
6
6
  message: string;
7
7
  toString(): string;
8
8
  };
package/src/util/http.js CHANGED
@@ -38,9 +38,10 @@ const getRequestOptions = (url) => {
38
38
  };
39
39
  exports.getRequestOptions = getRequestOptions;
40
40
  const fetch = async (url) => {
41
+ var _a;
41
42
  const requestUrl = getProxyVar() ? getProxyVar() : url;
42
43
  const proto = (0, url_1.parse)(requestUrl).protocol.slice(0, -1) === 'http' ? 'http' : 'https';
43
- const fetcher = await Promise.resolve().then(() => require(proto));
44
+ const fetcher = await (_a = proto, Promise.resolve().then(() => require(_a)));
44
45
  return new Promise((resolve, reject) => {
45
46
  const options = (0, exports.getRequestOptions)(url);
46
47
  const request = fetcher.get(options, (response) => {
@@ -60,9 +61,10 @@ const fetch = async (url) => {
60
61
  };
61
62
  exports.fetch = fetch;
62
63
  const downloadFile = async (url, writeLocation) => {
64
+ var _a;
63
65
  const requestUrl = getProxyVar() ? getProxyVar() : url;
64
66
  const proto = (0, url_1.parse)(requestUrl).protocol.slice(0, -1) === 'http' ? 'http' : 'https';
65
- const fetcher = await Promise.resolve().then(() => require(proto));
67
+ const fetcher = await (_a = proto, Promise.resolve().then(() => require(_a)));
66
68
  return new Promise((resolve, reject) => {
67
69
  try {
68
70
  const options = (0, exports.getRequestOptions)(url);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Handy class for managing asynchronous dependencies of classes.
3
+ *
4
+ * Will call the producer function once and only once when getValue is called,
5
+ * returning the resultant value for every subsequent call.
6
+ */
7
+ export declare class Lazy<T> {
8
+ private producerFn;
9
+ constructor(producerFn: () => T);
10
+ private value;
11
+ /**
12
+ * Lazily get the value returned by the producer.
13
+ * @returns The value returned from the producer function
14
+ */
15
+ getValue(): T;
16
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Lazy = void 0;
4
+ /**
5
+ * Handy class for managing asynchronous dependencies of classes.
6
+ *
7
+ * Will call the producer function once and only once when getValue is called,
8
+ * returning the resultant value for every subsequent call.
9
+ */
10
+ class Lazy {
11
+ // eslint-disable-next-line
12
+ constructor(producerFn) {
13
+ this.producerFn = producerFn;
14
+ }
15
+ /**
16
+ * Lazily get the value returned by the producer.
17
+ * @returns The value returned from the producer function
18
+ */
19
+ getValue() {
20
+ if (!this.value) {
21
+ this.value = this.producerFn();
22
+ }
23
+ return this.value;
24
+ }
25
+ }
26
+ exports.Lazy = Lazy;
@@ -1,5 +1,5 @@
1
1
  export declare function promisify(func: Function): (...args: any[]) => Promise<any>;
2
2
  export declare function promiseMap<T, S>(arr: T[], asyncF: (x: T, i: number, r: T[]) => Promise<S>): Promise<S[]>;
3
- export declare type asyncF<T> = (...args: any[]) => Promise<T>;
3
+ export type asyncF<T> = (...args: any[]) => Promise<T>;
4
4
  export declare function serial<T>(arr: asyncF<T>[]): Promise<T[]>;
5
5
  export declare function promiseMapSerial<T>(arr: any[], func: asyncF<T>): Promise<T[]>;
@@ -0,0 +1,11 @@
1
+ export declare class ReversibleMap<TKey extends string | number | symbol, TValue extends Object | string | number> {
2
+ private readonly valueToKey;
3
+ private readonly keyToValue;
4
+ setUnique: (key: TKey, value: TValue) => void;
5
+ getKey: (value: TValue) => TKey;
6
+ getValue(key: TKey): TValue;
7
+ deleteKey: (key: TKey) => TValue | undefined;
8
+ deleteValue: (value: TValue) => TKey | undefined;
9
+ hasKey: (key: TKey) => boolean;
10
+ hasValue: (value: TValue) => boolean;
11
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReversibleMap = void 0;
4
+ class ReversibleMap {
5
+ constructor() {
6
+ this.valueToKey = new Map();
7
+ this.keyToValue = new Map();
8
+ this.setUnique = (key, value) => {
9
+ if (this.hasKey(key) || this.hasValue(value)) {
10
+ throw new Error('Key or value already in the map.');
11
+ }
12
+ this.keyToValue.set(key, value);
13
+ this.valueToKey.set(value, key);
14
+ };
15
+ this.getKey = (value) => {
16
+ const existingKey = this.valueToKey.get(value);
17
+ if (!existingKey) {
18
+ throw new Error('Value not found in the map.');
19
+ }
20
+ return existingKey;
21
+ };
22
+ this.deleteKey = (key) => {
23
+ const value = this.getValue(key);
24
+ this.keyToValue.delete(key);
25
+ this.valueToKey.delete(value);
26
+ return value;
27
+ };
28
+ this.deleteValue = (value) => {
29
+ const key = this.getKey(value);
30
+ this.keyToValue.delete(key);
31
+ this.valueToKey.delete(value);
32
+ return key;
33
+ };
34
+ this.hasKey = (key) => {
35
+ return this.keyToValue.has(key);
36
+ };
37
+ this.hasValue = (value) => {
38
+ return this.valueToKey.has(value);
39
+ };
40
+ }
41
+ getValue(key) {
42
+ const item = this.keyToValue.get(key);
43
+ if (!item) {
44
+ throw new Error('Key not found in the map.');
45
+ }
46
+ return item;
47
+ }
48
+ }
49
+ exports.ReversibleMap = ReversibleMap;
@@ -3,6 +3,6 @@
3
3
  * which are always populated in certain contexts. A `DeepPick` type would be even better,
4
4
  * but no reliable implementation of one appears to exist yet.
5
5
  */
6
- export declare type Complete<T extends {}> = T & {
6
+ export type Complete<T extends {}> = T & {
7
7
  [MK in keyof T]-?: Complete<NonNullable<T[MK]>>;
8
8
  };