@sprucelabs/spruce-heartwood-utils 36.1.0 → 36.2.0
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/build/__tests__/support/MockRemoteViewControllerFactory.d.ts +3 -0
- package/build/__tests__/support/MockRemoteViewControllerFactory.js +7 -0
- package/build/errors/SpruceError.js +3 -0
- package/build/esm/__tests__/support/MockRemoteViewControllerFactory.d.ts +3 -0
- package/build/esm/__tests__/support/MockRemoteViewControllerFactory.js +9 -0
- package/build/esm/errors/SpruceError.js +3 -0
- package/build/esm/views/RemoteViewControllerFactory.d.ts +2 -0
- package/build/esm/views/RemoteViewControllerFactory.js +28 -23
- package/build/views/RemoteViewControllerFactory.d.ts +2 -0
- package/build/views/RemoteViewControllerFactory.js +30 -27
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
|
|
|
10
10
|
private static controllers?;
|
|
11
11
|
private static wasReset;
|
|
12
12
|
private themes;
|
|
13
|
+
private loadedNamespaces;
|
|
13
14
|
constructor(options: RemoteFactoryOptions);
|
|
14
15
|
fetchRemoteController(_name: string): Promise<(new () => ViewController<any>) & {
|
|
15
16
|
id: string;
|
|
@@ -27,5 +28,7 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
|
|
|
27
28
|
assertRemoteCardConstructorOptionsEqual(id: string, expected: Record<string, any>): void;
|
|
28
29
|
hasController(name: string): boolean;
|
|
29
30
|
RemoteController(id: string, options: Record<string, any>): Promise<any>;
|
|
31
|
+
loadViewsForNamespace(namespace: string): Promise<void>;
|
|
32
|
+
assertLoadedViewsForNamespace(namespace: string): void;
|
|
30
33
|
}
|
|
31
34
|
export type MockDroppedInControllers = Record<string, new (args: any) => ViewController<any>>;
|
|
@@ -7,6 +7,7 @@ class MockRemoteViewControllerFactory {
|
|
|
7
7
|
this.loadedControllers = {};
|
|
8
8
|
this.constructorOptionsById = {};
|
|
9
9
|
this.themes = {};
|
|
10
|
+
this.loadedNamespaces = {};
|
|
10
11
|
MockRemoteViewControllerFactory.instance = this;
|
|
11
12
|
this.views = options.vcFactory;
|
|
12
13
|
MockRemoteViewControllerFactory.dropInControllers(this);
|
|
@@ -107,6 +108,12 @@ class MockRemoteViewControllerFactory {
|
|
|
107
108
|
this.lastRemoteCostructorOptions = options;
|
|
108
109
|
return this.views.Controller(id, options);
|
|
109
110
|
}
|
|
111
|
+
async loadViewsForNamespace(namespace) {
|
|
112
|
+
this.loadedNamespaces[namespace] = true;
|
|
113
|
+
}
|
|
114
|
+
assertLoadedViewsForNamespace(namespace) {
|
|
115
|
+
test_utils_1.assert.isTrue(this.loadedNamespaces[namespace], `You did not load views for the namespace '${namespace}'. Try removeVc.loadViewsForNamespace('${namespace}').`);
|
|
116
|
+
}
|
|
110
117
|
}
|
|
111
118
|
MockRemoteViewControllerFactory.wasReset = false;
|
|
112
119
|
exports.default = MockRemoteViewControllerFactory;
|
|
@@ -40,6 +40,9 @@ class SpruceError extends error_1.default {
|
|
|
40
40
|
case 'AUDIO_ERROR':
|
|
41
41
|
message = 'A Audio error just happened!';
|
|
42
42
|
break;
|
|
43
|
+
case 'SHARED_APP_CONTROLLER_INSTANCE_NOT_SET':
|
|
44
|
+
message = `You cannot call SharedAppController.getInstance() before setting an instance.`;
|
|
45
|
+
break;
|
|
43
46
|
default:
|
|
44
47
|
message = super.friendlyMessage();
|
|
45
48
|
}
|
|
@@ -10,6 +10,7 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
|
|
|
10
10
|
private static controllers?;
|
|
11
11
|
private static wasReset;
|
|
12
12
|
private themes;
|
|
13
|
+
private loadedNamespaces;
|
|
13
14
|
constructor(options: RemoteFactoryOptions);
|
|
14
15
|
fetchRemoteController(_name: string): Promise<(new () => ViewController<any>) & {
|
|
15
16
|
id: string;
|
|
@@ -27,5 +28,7 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
|
|
|
27
28
|
assertRemoteCardConstructorOptionsEqual(id: string, expected: Record<string, any>): void;
|
|
28
29
|
hasController(name: string): boolean;
|
|
29
30
|
RemoteController(id: string, options: Record<string, any>): Promise<any>;
|
|
31
|
+
loadViewsForNamespace(namespace: string): Promise<void>;
|
|
32
|
+
assertLoadedViewsForNamespace(namespace: string): void;
|
|
30
33
|
}
|
|
31
34
|
export type MockDroppedInControllers = Record<string, new (args: any) => ViewController<any>>;
|
|
@@ -14,6 +14,7 @@ class MockRemoteViewControllerFactory {
|
|
|
14
14
|
this.loadedControllers = {};
|
|
15
15
|
this.constructorOptionsById = {};
|
|
16
16
|
this.themes = {};
|
|
17
|
+
this.loadedNamespaces = {};
|
|
17
18
|
MockRemoteViewControllerFactory.instance = this;
|
|
18
19
|
this.views = options.vcFactory;
|
|
19
20
|
MockRemoteViewControllerFactory.dropInControllers(this);
|
|
@@ -119,6 +120,14 @@ class MockRemoteViewControllerFactory {
|
|
|
119
120
|
return this.views.Controller(id, options);
|
|
120
121
|
});
|
|
121
122
|
}
|
|
123
|
+
loadViewsForNamespace(namespace) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
this.loadedNamespaces[namespace] = true;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
assertLoadedViewsForNamespace(namespace) {
|
|
129
|
+
assert.isTrue(this.loadedNamespaces[namespace], `You did not load views for the namespace '${namespace}'. Try removeVc.loadViewsForNamespace('${namespace}').`);
|
|
130
|
+
}
|
|
122
131
|
}
|
|
123
132
|
MockRemoteViewControllerFactory.wasReset = false;
|
|
124
133
|
export default MockRemoteViewControllerFactory;
|
|
@@ -35,6 +35,9 @@ export default class SpruceError extends AbstractSpruceError {
|
|
|
35
35
|
case 'AUDIO_ERROR':
|
|
36
36
|
message = 'A Audio error just happened!';
|
|
37
37
|
break;
|
|
38
|
+
case 'SHARED_APP_CONTROLLER_INSTANCE_NOT_SET':
|
|
39
|
+
message = `You cannot call SharedAppController.getInstance() before setting an instance.`;
|
|
40
|
+
break;
|
|
38
41
|
default:
|
|
39
42
|
message = super.friendlyMessage();
|
|
40
43
|
}
|
|
@@ -20,6 +20,7 @@ export default class RemoteViewControllerFactoryImpl implements RemoteViewContro
|
|
|
20
20
|
}>;
|
|
21
21
|
RemoteController(name: string, options: Record<string, any>): Promise<any>;
|
|
22
22
|
protected optionallyLoadController(name: string): Promise<void>;
|
|
23
|
+
loadViewsForNamespace(namespace: string): Promise<void>;
|
|
23
24
|
private fetchFromUrl;
|
|
24
25
|
}
|
|
25
26
|
type ConnectToApi = () => Promise<MercuryClient>;
|
|
@@ -35,5 +36,6 @@ export interface RemoteViewControllerFactory extends Factory {
|
|
|
35
36
|
fetchRemoteController: (name: string) => Promise<(new () => ViewController<any>) & {
|
|
36
37
|
id: string;
|
|
37
38
|
}>;
|
|
39
|
+
loadViewsForNamespace(namespace: string): Promise<void>;
|
|
38
40
|
}
|
|
39
41
|
export {};
|
|
@@ -53,29 +53,34 @@ class RemoteViewControllerFactoryImpl {
|
|
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
54
|
const namespace = this.getNamespace(name);
|
|
55
55
|
if (!this.hasController(name) && namespace) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
56
|
+
yield this.loadViewsForNamespace(namespace);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
loadViewsForNamespace(namespace) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const client = yield this.connectToApi();
|
|
63
|
+
let [{ source, theme, sourceUrl }] = yield client.emitAndFlattenResponses('heartwood.get-skill-views::v2021_02_11', {
|
|
64
|
+
target: {
|
|
65
|
+
namespace,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
if (!source) {
|
|
69
|
+
source = yield this.fetchFromUrl(sourceUrl);
|
|
70
|
+
}
|
|
71
|
+
const importer = ViewControllerImporter.Importer();
|
|
72
|
+
const { controllers: skillViews, plugins, App, } = importer.import(source);
|
|
73
|
+
skillViews.forEach((sv) => {
|
|
74
|
+
sv.id = `${namespace}.${sv.id}`;
|
|
75
|
+
});
|
|
76
|
+
if (App) {
|
|
77
|
+
//@ts-ignore
|
|
78
|
+
App.id = namespace;
|
|
79
|
+
this.vcFactory.setAppController(App);
|
|
80
|
+
}
|
|
81
|
+
this.vcFactory.importControllers(skillViews, plugins);
|
|
82
|
+
if (theme) {
|
|
83
|
+
this.themesByNamespace[namespace] = Object.assign(Object.assign({}, theme), { slug: namespace, name: namespace });
|
|
79
84
|
}
|
|
80
85
|
});
|
|
81
86
|
}
|
|
@@ -20,6 +20,7 @@ export default class RemoteViewControllerFactoryImpl implements RemoteViewContro
|
|
|
20
20
|
}>;
|
|
21
21
|
RemoteController(name: string, options: Record<string, any>): Promise<any>;
|
|
22
22
|
protected optionallyLoadController(name: string): Promise<void>;
|
|
23
|
+
loadViewsForNamespace(namespace: string): Promise<void>;
|
|
23
24
|
private fetchFromUrl;
|
|
24
25
|
}
|
|
25
26
|
type ConnectToApi = () => Promise<MercuryClient>;
|
|
@@ -35,5 +36,6 @@ export interface RemoteViewControllerFactory extends Factory {
|
|
|
35
36
|
fetchRemoteController: (name: string) => Promise<(new () => ViewController<any>) & {
|
|
36
37
|
id: string;
|
|
37
38
|
}>;
|
|
39
|
+
loadViewsForNamespace(namespace: string): Promise<void>;
|
|
38
40
|
}
|
|
39
41
|
export {};
|
|
@@ -43,33 +43,36 @@ class RemoteViewControllerFactoryImpl {
|
|
|
43
43
|
async optionallyLoadController(name) {
|
|
44
44
|
const namespace = this.getNamespace(name);
|
|
45
45
|
if (!this.hasController(name) && namespace) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
46
|
+
await this.loadViewsForNamespace(namespace);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async loadViewsForNamespace(namespace) {
|
|
50
|
+
const client = await this.connectToApi();
|
|
51
|
+
let [{ source, theme, sourceUrl }] = await client.emitAndFlattenResponses('heartwood.get-skill-views::v2021_02_11', {
|
|
52
|
+
target: {
|
|
53
|
+
namespace,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
if (!source) {
|
|
57
|
+
source = await this.fetchFromUrl(sourceUrl);
|
|
58
|
+
}
|
|
59
|
+
const importer = heartwood_view_controllers_1.ViewControllerImporter.Importer();
|
|
60
|
+
const { controllers: skillViews, plugins, App, } = importer.import(source);
|
|
61
|
+
skillViews.forEach((sv) => {
|
|
62
|
+
sv.id = `${namespace}.${sv.id}`;
|
|
63
|
+
});
|
|
64
|
+
if (App) {
|
|
65
|
+
//@ts-ignore
|
|
66
|
+
App.id = namespace;
|
|
67
|
+
this.vcFactory.setAppController(App);
|
|
68
|
+
}
|
|
69
|
+
this.vcFactory.importControllers(skillViews, plugins);
|
|
70
|
+
if (theme) {
|
|
71
|
+
this.themesByNamespace[namespace] = {
|
|
72
|
+
...theme,
|
|
73
|
+
slug: namespace,
|
|
74
|
+
name: namespace,
|
|
75
|
+
};
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
async fetchFromUrl(sourceUrl) {
|