@openfin/core 31.74.21 → 31.74.22
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/package.json +1 -1
- package/src/api/api-exposer/api-consumer.d.ts +28 -0
- package/src/api/api-exposer/api-consumer.js +28 -0
- package/src/api/api-exposer/api-exposer.d.ts +35 -0
- package/src/api/api-exposer/api-exposer.js +38 -0
- package/src/api/api-exposer/decorators.d.ts +10 -0
- package/src/api/api-exposer/decorators.js +18 -0
- package/src/api/api-exposer/index.d.ts +4 -0
- package/src/api/api-exposer/index.js +20 -0
- package/src/api/api-exposer/strategies/index.d.ts +1 -0
- package/src/api/api-exposer/strategies/index.js +17 -0
- package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.d.ts +14 -0
- package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.js +20 -0
- package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.d.ts +20 -0
- package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.js +23 -0
- package/src/api/api-exposer/strategies/openfin-channels/index.d.ts +2 -0
- package/src/api/api-exposer/strategies/openfin-channels/index.js +18 -0
package/package.json
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ExposedProp } from "./decorators";
|
|
2
|
+
export type ConsumeStrategy<TMetaConsumeOptions, TPropConsumeDefinition> = {
|
|
3
|
+
getExposedFunctions: (options: TMetaConsumeOptions) => Promise<ExposedProp<TPropConsumeDefinition>[]>;
|
|
4
|
+
createFunction: (options: ExposedProp<TPropConsumeDefinition>, meta: TMetaConsumeOptions) => Function;
|
|
5
|
+
};
|
|
6
|
+
type PickOfType<T extends Record<any, any>, TTarget> = {
|
|
7
|
+
[key in keyof T as T[key] extends TTarget | undefined ? key : never]: T[key];
|
|
8
|
+
};
|
|
9
|
+
export type ApiClient<T extends Record<any, any>> = {
|
|
10
|
+
[key in keyof PickOfType<T, Function>]: (...args: Parameters<T[key]>) => ReturnType<T[key]> extends Promise<any> ? ReturnType<T[key]> : Promise<ReturnType<T[key]>>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Consumer for apis exposed with {@see ApiExposer}.
|
|
14
|
+
*
|
|
15
|
+
* A strategy that matches the strategy used to expose a target API must be provided.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ApiConsumer<TMetaConsumeOptions = any, TPropConsumptionOptions = any> {
|
|
18
|
+
private strategy;
|
|
19
|
+
constructor(strategy: ConsumeStrategy<TMetaConsumeOptions, TPropConsumptionOptions>);
|
|
20
|
+
/**
|
|
21
|
+
* Consumes an api exposed using a given transport strategy, and generates a client
|
|
22
|
+
* for easy, type safe consumption of that client.
|
|
23
|
+
* @param options Strategy specific consumption options.
|
|
24
|
+
* @returns An api client matching the given type.
|
|
25
|
+
*/
|
|
26
|
+
consume: <T extends Record<any, any>>(options: TMetaConsumeOptions) => Promise<ApiClient<T>>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiConsumer = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Consumer for apis exposed with {@see ApiExposer}.
|
|
6
|
+
*
|
|
7
|
+
* A strategy that matches the strategy used to expose a target API must be provided.
|
|
8
|
+
*/
|
|
9
|
+
class ApiConsumer {
|
|
10
|
+
// eslint-disable-next-line
|
|
11
|
+
constructor(strategy) {
|
|
12
|
+
this.strategy = strategy;
|
|
13
|
+
/**
|
|
14
|
+
* Consumes an api exposed using a given transport strategy, and generates a client
|
|
15
|
+
* for easy, type safe consumption of that client.
|
|
16
|
+
* @param options Strategy specific consumption options.
|
|
17
|
+
* @returns An api client matching the given type.
|
|
18
|
+
*/
|
|
19
|
+
this.consume = async (options) => {
|
|
20
|
+
const exposedProperties = await this.strategy.getExposedFunctions(options);
|
|
21
|
+
return exposedProperties.reduce((client, prop) => ({
|
|
22
|
+
...client,
|
|
23
|
+
[prop.key]: this.strategy.createFunction(prop, options)
|
|
24
|
+
}), {});
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ApiConsumer = ApiConsumer;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ExposedProp } from './decorators';
|
|
2
|
+
export type ConsumptionConfig<T> = {
|
|
3
|
+
key: string;
|
|
4
|
+
options: T;
|
|
5
|
+
};
|
|
6
|
+
export type ExposeStrategy<TInstanceExposeOptions, TPropExposeOptions, TPropConsumeOptions> = {
|
|
7
|
+
/**
|
|
8
|
+
* Exposes the given function on the strategy.
|
|
9
|
+
*/
|
|
10
|
+
exposeFunction: (target: Function, config: {
|
|
11
|
+
key: string;
|
|
12
|
+
options: TPropExposeOptions;
|
|
13
|
+
meta: TInstanceExposeOptions;
|
|
14
|
+
}) => Promise<TPropConsumeOptions>;
|
|
15
|
+
/**
|
|
16
|
+
* Exposes metadata to enable creation of client objects.
|
|
17
|
+
*/
|
|
18
|
+
exposeMeta: (instanceOptions: TInstanceExposeOptions, props: ExposedProp<TPropConsumeOptions>[]) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Exposes api services on the transport of choice.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ApiExposer<TInstanceExposeOptions = any, TPropExposeOptions = any, TPropConsumptionOptions = any> {
|
|
24
|
+
private strategy;
|
|
25
|
+
/**
|
|
26
|
+
* @param strategy The expose strategy to use to expose instances.
|
|
27
|
+
*/
|
|
28
|
+
constructor(strategy: ExposeStrategy<TInstanceExposeOptions, TPropExposeOptions, TPropConsumptionOptions>);
|
|
29
|
+
/**
|
|
30
|
+
* Exposes an instance of a given api on
|
|
31
|
+
* @param instance Instance of a class which has been decorated to indicate which functions can be exposed.
|
|
32
|
+
* @param instanceOptions Transport strategy specific options to use when exposing.
|
|
33
|
+
*/
|
|
34
|
+
exposeInstance: (instance: Record<any, any>, instanceOptions: TInstanceExposeOptions) => Promise<void>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiExposer = void 0;
|
|
4
|
+
const decorators_1 = require("./decorators");
|
|
5
|
+
/**
|
|
6
|
+
* Exposes api services on the transport of choice.
|
|
7
|
+
*/
|
|
8
|
+
class ApiExposer {
|
|
9
|
+
/**
|
|
10
|
+
* @param strategy The expose strategy to use to expose instances.
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line
|
|
13
|
+
constructor(strategy) {
|
|
14
|
+
this.strategy = strategy;
|
|
15
|
+
/**
|
|
16
|
+
* Exposes an instance of a given api on
|
|
17
|
+
* @param instance Instance of a class which has been decorated to indicate which functions can be exposed.
|
|
18
|
+
* @param instanceOptions Transport strategy specific options to use when exposing.
|
|
19
|
+
*/
|
|
20
|
+
this.exposeInstance = async (instance, instanceOptions) => {
|
|
21
|
+
const exposableProps = (0, decorators_1.getExposedProperties)(instance);
|
|
22
|
+
const exposedProps = await Promise.all(exposableProps.map(async ({ key, options }) => {
|
|
23
|
+
const customConsumptionOptions = await this.strategy.exposeFunction(instance[key].bind(instance), {
|
|
24
|
+
key,
|
|
25
|
+
options,
|
|
26
|
+
meta: instanceOptions
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
key,
|
|
30
|
+
options: customConsumptionOptions
|
|
31
|
+
};
|
|
32
|
+
}));
|
|
33
|
+
await this.strategy.exposeMeta(instanceOptions, exposedProps);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
;
|
|
37
|
+
}
|
|
38
|
+
exports.ApiExposer = ApiExposer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ExposedProp<T> = {
|
|
2
|
+
key: string;
|
|
3
|
+
options: T;
|
|
4
|
+
};
|
|
5
|
+
export declare const getExposedProperties: <T>(target: Record<any, any>) => ExposedProp<T>[];
|
|
6
|
+
/**
|
|
7
|
+
* Indicates that a class member function can be exposed using {@link ApiExposer}.
|
|
8
|
+
* @param options Options specific to the strategy used in {@link ApiExposer}
|
|
9
|
+
*/
|
|
10
|
+
export declare const expose: <T = undefined>(options?: T) => any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expose = exports.getExposedProperties = void 0;
|
|
4
|
+
const exposedProperties = Symbol('exposedProperties');
|
|
5
|
+
const getExposedProperties = (target) => {
|
|
6
|
+
return target[exposedProperties] || target.prototype[exposedProperties] || [];
|
|
7
|
+
};
|
|
8
|
+
exports.getExposedProperties = getExposedProperties;
|
|
9
|
+
/**
|
|
10
|
+
* Indicates that a class member function can be exposed using {@link ApiExposer}.
|
|
11
|
+
* @param options Options specific to the strategy used in {@link ApiExposer}
|
|
12
|
+
*/
|
|
13
|
+
// Returns any as decorator typing is weird.
|
|
14
|
+
const expose = (options) => (target, key, descriptor) => {
|
|
15
|
+
target[exposedProperties] = target[exposedProperties] || [];
|
|
16
|
+
target[exposedProperties].push({ key, descriptor, options });
|
|
17
|
+
};
|
|
18
|
+
exports.expose = expose;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api-consumer"), exports);
|
|
18
|
+
__exportStar(require("./api-exposer"), exports);
|
|
19
|
+
__exportStar(require("./strategies"), exports);
|
|
20
|
+
__exportStar(require("./decorators"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './openfin-channels';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./openfin-channels"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConsumeStrategy } from "../../api-consumer";
|
|
2
|
+
import { ExposedProp } from "../../decorators";
|
|
3
|
+
export type ChannelConsumeOptions = {
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
export type ChannelsPropConfig = {
|
|
7
|
+
action: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class ChannelsConsumer implements ConsumeStrategy<ChannelConsumeOptions, ChannelsPropConfig> {
|
|
10
|
+
private channel;
|
|
11
|
+
constructor(channel: any);
|
|
12
|
+
getExposedFunctions: (options: ChannelConsumeOptions) => Promise<ExposedProp<ChannelsPropConfig>[]>;
|
|
13
|
+
createFunction: (prop: ExposedProp<ChannelsPropConfig>) => Function;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelsConsumer = void 0;
|
|
4
|
+
class ChannelsConsumer {
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
constructor(channel) {
|
|
7
|
+
this.channel = channel;
|
|
8
|
+
this.getExposedFunctions = async (options) => {
|
|
9
|
+
const { id } = options;
|
|
10
|
+
const { props } = await this.channel.dispatch(`api-meta:${id}`);
|
|
11
|
+
return props;
|
|
12
|
+
};
|
|
13
|
+
this.createFunction = (prop) => (...args) => {
|
|
14
|
+
const { action } = prop.options;
|
|
15
|
+
return this.channel.dispatch(action, { args });
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
}
|
|
20
|
+
exports.ChannelsConsumer = ChannelsConsumer;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ExposeStrategy } from '../../api-exposer';
|
|
2
|
+
import { ExposedProp } from '../../decorators';
|
|
3
|
+
import { ChannelsPropConfig } from './channels-consumer';
|
|
4
|
+
type ChannelInstanceExposeOptions = {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
export type ChannelsPropOptions = {
|
|
8
|
+
action?: string;
|
|
9
|
+
} | undefined;
|
|
10
|
+
export declare class ChannelsExposer implements ExposeStrategy<ChannelInstanceExposeOptions, ChannelsPropOptions, ChannelsPropConfig> {
|
|
11
|
+
private channelProviderOrClient;
|
|
12
|
+
constructor(channelProviderOrClient: any);
|
|
13
|
+
exposeFunction: (target: Function, config: {
|
|
14
|
+
key: string;
|
|
15
|
+
options: ChannelsPropOptions;
|
|
16
|
+
meta: ChannelInstanceExposeOptions;
|
|
17
|
+
}) => Promise<ChannelsPropConfig>;
|
|
18
|
+
exposeMeta: ({ id }: ChannelInstanceExposeOptions, props: ExposedProp<ChannelsPropOptions>[]) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelsExposer = void 0;
|
|
4
|
+
class ChannelsExposer {
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
constructor(channelProviderOrClient) {
|
|
7
|
+
this.channelProviderOrClient = channelProviderOrClient;
|
|
8
|
+
this.exposeFunction = async (target, config) => {
|
|
9
|
+
const { key, options, meta } = config;
|
|
10
|
+
const { id } = meta;
|
|
11
|
+
const action = `${id}.${(options === null || options === void 0 ? void 0 : options.action) || key}`;
|
|
12
|
+
await this.channelProviderOrClient.register(action, async ({ args }) => {
|
|
13
|
+
return target(...args);
|
|
14
|
+
});
|
|
15
|
+
return { action };
|
|
16
|
+
};
|
|
17
|
+
this.exposeMeta = async ({ id }, props) => {
|
|
18
|
+
const action = `api-meta:${id}`;
|
|
19
|
+
await this.channelProviderOrClient.register(action, () => ({ props }));
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.ChannelsExposer = ChannelsExposer;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./channels-consumer"), exports);
|
|
18
|
+
__exportStar(require("./channels-exposer"), exports);
|