@sprucelabs/spruce-heartwood-utils 5.13.29 → 5.13.33
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.
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { MercuryClient } from '@sprucelabs/mercury-client';
|
|
3
|
+
import { SkillTheme } from './ThemeManager';
|
|
4
|
+
declare type ConnectToApi = () => Promise<MercuryClient>;
|
|
5
|
+
interface FactoryOptions {
|
|
6
|
+
connectToApi: ConnectToApi;
|
|
7
|
+
vcFactory: ViewControllerFactory;
|
|
8
|
+
}
|
|
9
|
+
declare type Factory = Pick<ViewControllerFactory, 'hasController'>;
|
|
10
|
+
export default class RemoteViewControllerFactory implements Factory {
|
|
11
|
+
private connectToApi;
|
|
12
|
+
private vcFactory;
|
|
13
|
+
private themesByNamespace;
|
|
14
|
+
static Factory(options: FactoryOptions): RemoteViewControllerFactory;
|
|
15
|
+
private constructor();
|
|
16
|
+
hasController(name: string): boolean;
|
|
17
|
+
getTheme(namespace?: string): SkillTheme;
|
|
18
|
+
Controller(name: string, options: Record<string, any>): any;
|
|
19
|
+
private getNamespace;
|
|
20
|
+
RemoteController(name: string, options: Record<string, any>): Promise<any>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
4
|
+
const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
|
|
5
|
+
class RemoteViewControllerFactory {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.themesByNamespace = {};
|
|
8
|
+
this.connectToApi = options.connectToApi;
|
|
9
|
+
this.vcFactory = options.vcFactory;
|
|
10
|
+
}
|
|
11
|
+
static Factory(options) {
|
|
12
|
+
return new this(options);
|
|
13
|
+
}
|
|
14
|
+
hasController(name) {
|
|
15
|
+
return this.vcFactory.hasController(name);
|
|
16
|
+
}
|
|
17
|
+
getTheme(namespace) {
|
|
18
|
+
return this.themesByNamespace[namespace !== null && namespace !== void 0 ? namespace : ''];
|
|
19
|
+
}
|
|
20
|
+
Controller(name, options) {
|
|
21
|
+
return this.vcFactory.Controller(name, options);
|
|
22
|
+
}
|
|
23
|
+
getNamespace(id) {
|
|
24
|
+
return id.split('.')[0];
|
|
25
|
+
}
|
|
26
|
+
async RemoteController(name, options) {
|
|
27
|
+
const namespace = this.getNamespace(name);
|
|
28
|
+
if (!this.hasController(name) && namespace) {
|
|
29
|
+
const client = await this.connectToApi();
|
|
30
|
+
const results = await client.emit('heartwood.get-skill-views::v2021_02_11', {
|
|
31
|
+
target: {
|
|
32
|
+
namespace,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
const { source, theme } = spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(results);
|
|
36
|
+
const importer = heartwood_view_controllers_1.ViewControllerImporter.Importer();
|
|
37
|
+
const skillViews = importer.import(source);
|
|
38
|
+
skillViews.forEach((sv) => {
|
|
39
|
+
sv.id = `${namespace}.${sv.id}`;
|
|
40
|
+
});
|
|
41
|
+
this.vcFactory.importControllers(skillViews);
|
|
42
|
+
if (theme) {
|
|
43
|
+
this.themesByNamespace[namespace] = Object.assign(Object.assign({}, theme), { namespace, name: namespace });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return this.vcFactory.Controller(name, options);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = RemoteViewControllerFactory;
|
|
50
|
+
//# sourceMappingURL=RemoteViewControllerFactory.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { ViewControllerImporter, } from '@sprucelabs/heartwood-view-controllers';
|
|
11
|
+
import { eventResponseUtil } from '@sprucelabs/spruce-event-utils';
|
|
12
|
+
export default class RemoteViewControllerFactory {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.themesByNamespace = {};
|
|
15
|
+
this.connectToApi = options.connectToApi;
|
|
16
|
+
this.vcFactory = options.vcFactory;
|
|
17
|
+
}
|
|
18
|
+
static Factory(options) {
|
|
19
|
+
return new this(options);
|
|
20
|
+
}
|
|
21
|
+
hasController(name) {
|
|
22
|
+
return this.vcFactory.hasController(name);
|
|
23
|
+
}
|
|
24
|
+
getTheme(namespace) {
|
|
25
|
+
return this.themesByNamespace[namespace !== null && namespace !== void 0 ? namespace : ''];
|
|
26
|
+
}
|
|
27
|
+
Controller(name, options) {
|
|
28
|
+
return this.vcFactory.Controller(name, options);
|
|
29
|
+
}
|
|
30
|
+
getNamespace(id) {
|
|
31
|
+
return id.split('.')[0];
|
|
32
|
+
}
|
|
33
|
+
RemoteController(name, options) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const namespace = this.getNamespace(name);
|
|
36
|
+
if (!this.hasController(name) && namespace) {
|
|
37
|
+
const client = yield this.connectToApi();
|
|
38
|
+
const results = yield client.emit('heartwood.get-skill-views::v2021_02_11', {
|
|
39
|
+
target: {
|
|
40
|
+
namespace,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const { source, theme } = eventResponseUtil.getFirstResponseOrThrow(results);
|
|
44
|
+
const importer = ViewControllerImporter.Importer();
|
|
45
|
+
const skillViews = importer.import(source);
|
|
46
|
+
skillViews.forEach((sv) => {
|
|
47
|
+
sv.id = `${namespace}.${sv.id}`;
|
|
48
|
+
});
|
|
49
|
+
this.vcFactory.importControllers(skillViews);
|
|
50
|
+
if (theme) {
|
|
51
|
+
this.themesByNamespace[namespace] = Object.assign(Object.assign({}, theme), { namespace, name: namespace });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return this.vcFactory.Controller(name, options);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprucelabs/spruce-heartwood-utils",
|
|
3
3
|
"description": "Heartwood Utilities",
|
|
4
|
-
"version": "5.13.
|
|
4
|
+
"version": "5.13.33",
|
|
5
5
|
"skill": {
|
|
6
6
|
"namespace": "heartwood"
|
|
7
7
|
},
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"build/index-module.d.ts",
|
|
19
19
|
"build/esm/index-module.js",
|
|
20
20
|
"build/esm/index-module.d.ts",
|
|
21
|
-
"build/
|
|
22
|
-
"build/
|
|
23
|
-
"build/esm/
|
|
24
|
-
"build/esm/
|
|
21
|
+
"build/RemoteViewControllerFactory.js",
|
|
22
|
+
"build/RemoteViewControllerFactory.d.ts",
|
|
23
|
+
"build/esm/RemoteViewControllerFactory.js",
|
|
24
|
+
"build/esm/romoteViewContorllerFactory.d.ts",
|
|
25
25
|
"build/ThemeManager.js",
|
|
26
26
|
"build/ThemeManager.d.ts",
|
|
27
27
|
"build/esm/ThemeManager.js",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"release": "npm publish"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@sprucelabs/heartwood-view-controllers": "
|
|
36
|
-
"@sprucelabs/mercury-client": "
|
|
37
|
-
"@sprucelabs/spruce-event-utils": "
|
|
35
|
+
"@sprucelabs/heartwood-view-controllers": "@latest",
|
|
36
|
+
"@sprucelabs/mercury-client": "@latest",
|
|
37
|
+
"@sprucelabs/spruce-event-utils": "@latest"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": "16.x",
|