@sprucelabs/spruce-heartwood-utils 36.0.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.
@@ -1,4 +1,5 @@
1
1
  import { ViewControllerMap, ControllerOptions, ViewController, SkillViewController } from '@sprucelabs/heartwood-view-controllers';
2
+ import { SkillTheme } from '../../types/heartwood.types';
2
3
  import { RemoteFactoryOptions, RemoteViewControllerFactory } from '../../views/RemoteViewControllerFactory';
3
4
  export default class MockRemoteViewControllerFactory implements RemoteViewControllerFactory {
4
5
  private static instance?;
@@ -8,21 +9,26 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
8
9
  private views;
9
10
  private static controllers?;
10
11
  private static wasReset;
12
+ private themes;
13
+ private loadedNamespaces;
11
14
  constructor(options: RemoteFactoryOptions);
12
15
  fetchRemoteController(_name: string): Promise<(new () => ViewController<any>) & {
13
16
  id: string;
14
17
  }>;
15
- Controller<N extends keyof ViewControllerMap, O extends ControllerOptions<N>>(_name: N, _options: O): ViewControllerMap[N];
18
+ Controller<N extends keyof ViewControllerMap, O extends ControllerOptions<N>>(name: N, options: O): ViewControllerMap[N];
16
19
  static dropInRemoteController(id: string, Class: new (args: any) => ViewController<any>): void;
17
20
  private static dropInControllers;
18
21
  assertSkillViewRendersRemoteCard(vc: SkillViewController, name: string, id?: string): void;
19
22
  static reset(): void;
20
23
  static getInstance(): MockRemoteViewControllerFactory;
21
- getTheme(_namespace?: string | undefined): undefined;
24
+ getTheme(namespace?: string | undefined): SkillTheme | undefined;
25
+ setTheme(namespace: string, theme: SkillTheme): void;
22
26
  assertDidNotFetchRemoteController(id: string): void;
23
27
  assertFetchedRemoteController(name: string, options?: Record<string, any>): void;
24
28
  assertRemoteCardConstructorOptionsEqual(id: string, expected: Record<string, any>): void;
25
29
  hasController(name: string): boolean;
26
30
  RemoteController(id: string, options: Record<string, any>): Promise<any>;
31
+ loadViewsForNamespace(namespace: string): Promise<void>;
32
+ assertLoadedViewsForNamespace(namespace: string): void;
27
33
  }
28
34
  export type MockDroppedInControllers = Record<string, new (args: any) => ViewController<any>>;
@@ -6,6 +6,8 @@ class MockRemoteViewControllerFactory {
6
6
  constructor(options) {
7
7
  this.loadedControllers = {};
8
8
  this.constructorOptionsById = {};
9
+ this.themes = {};
10
+ this.loadedNamespaces = {};
9
11
  MockRemoteViewControllerFactory.instance = this;
10
12
  this.views = options.vcFactory;
11
13
  MockRemoteViewControllerFactory.dropInControllers(this);
@@ -13,8 +15,8 @@ class MockRemoteViewControllerFactory {
13
15
  fetchRemoteController(_name) {
14
16
  throw new Error('Not implemented in mock. Maybe you meant to use this.remote.RemoteController(..)?');
15
17
  }
16
- Controller(_name, _options) {
17
- return {};
18
+ Controller(name, options) {
19
+ return this.views.Controller(name, options);
18
20
  }
19
21
  static dropInRemoteController(id, Class) {
20
22
  if (!this.controllers) {
@@ -72,8 +74,11 @@ class MockRemoteViewControllerFactory {
72
74
  }
73
75
  return this.instance;
74
76
  }
75
- getTheme(_namespace) {
76
- return undefined;
77
+ getTheme(namespace) {
78
+ return namespace ? this.themes[namespace] : undefined;
79
+ }
80
+ setTheme(namespace, theme) {
81
+ this.themes[namespace] = theme;
77
82
  }
78
83
  assertDidNotFetchRemoteController(id) {
79
84
  try {
@@ -103,6 +108,12 @@ class MockRemoteViewControllerFactory {
103
108
  this.lastRemoteCostructorOptions = options;
104
109
  return this.views.Controller(id, options);
105
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
+ }
106
117
  }
107
118
  MockRemoteViewControllerFactory.wasReset = false;
108
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
  }
@@ -1,4 +1,5 @@
1
1
  import { ViewControllerMap, ControllerOptions, ViewController, SkillViewController } from '@sprucelabs/heartwood-view-controllers';
2
+ import { SkillTheme } from '../../types/heartwood.types';
2
3
  import { RemoteFactoryOptions, RemoteViewControllerFactory } from '../../views/RemoteViewControllerFactory';
3
4
  export default class MockRemoteViewControllerFactory implements RemoteViewControllerFactory {
4
5
  private static instance?;
@@ -8,21 +9,26 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
8
9
  private views;
9
10
  private static controllers?;
10
11
  private static wasReset;
12
+ private themes;
13
+ private loadedNamespaces;
11
14
  constructor(options: RemoteFactoryOptions);
12
15
  fetchRemoteController(_name: string): Promise<(new () => ViewController<any>) & {
13
16
  id: string;
14
17
  }>;
15
- Controller<N extends keyof ViewControllerMap, O extends ControllerOptions<N>>(_name: N, _options: O): ViewControllerMap[N];
18
+ Controller<N extends keyof ViewControllerMap, O extends ControllerOptions<N>>(name: N, options: O): ViewControllerMap[N];
16
19
  static dropInRemoteController(id: string, Class: new (args: any) => ViewController<any>): void;
17
20
  private static dropInControllers;
18
21
  assertSkillViewRendersRemoteCard(vc: SkillViewController, name: string, id?: string): void;
19
22
  static reset(): void;
20
23
  static getInstance(): MockRemoteViewControllerFactory;
21
- getTheme(_namespace?: string | undefined): undefined;
24
+ getTheme(namespace?: string | undefined): SkillTheme | undefined;
25
+ setTheme(namespace: string, theme: SkillTheme): void;
22
26
  assertDidNotFetchRemoteController(id: string): void;
23
27
  assertFetchedRemoteController(name: string, options?: Record<string, any>): void;
24
28
  assertRemoteCardConstructorOptionsEqual(id: string, expected: Record<string, any>): void;
25
29
  hasController(name: string): boolean;
26
30
  RemoteController(id: string, options: Record<string, any>): Promise<any>;
31
+ loadViewsForNamespace(namespace: string): Promise<void>;
32
+ assertLoadedViewsForNamespace(namespace: string): void;
27
33
  }
28
34
  export type MockDroppedInControllers = Record<string, new (args: any) => ViewController<any>>;
@@ -13,6 +13,8 @@ class MockRemoteViewControllerFactory {
13
13
  constructor(options) {
14
14
  this.loadedControllers = {};
15
15
  this.constructorOptionsById = {};
16
+ this.themes = {};
17
+ this.loadedNamespaces = {};
16
18
  MockRemoteViewControllerFactory.instance = this;
17
19
  this.views = options.vcFactory;
18
20
  MockRemoteViewControllerFactory.dropInControllers(this);
@@ -20,8 +22,8 @@ class MockRemoteViewControllerFactory {
20
22
  fetchRemoteController(_name) {
21
23
  throw new Error('Not implemented in mock. Maybe you meant to use this.remote.RemoteController(..)?');
22
24
  }
23
- Controller(_name, _options) {
24
- return {};
25
+ Controller(name, options) {
26
+ return this.views.Controller(name, options);
25
27
  }
26
28
  static dropInRemoteController(id, Class) {
27
29
  if (!this.controllers) {
@@ -80,8 +82,11 @@ class MockRemoteViewControllerFactory {
80
82
  }
81
83
  return this.instance;
82
84
  }
83
- getTheme(_namespace) {
84
- return undefined;
85
+ getTheme(namespace) {
86
+ return namespace ? this.themes[namespace] : undefined;
87
+ }
88
+ setTheme(namespace, theme) {
89
+ this.themes[namespace] = theme;
85
90
  }
86
91
  assertDidNotFetchRemoteController(id) {
87
92
  try {
@@ -115,6 +120,14 @@ class MockRemoteViewControllerFactory {
115
120
  return this.views.Controller(id, options);
116
121
  });
117
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
+ }
118
131
  }
119
132
  MockRemoteViewControllerFactory.wasReset = false;
120
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
- const client = yield this.connectToApi();
57
- let [{ source, theme, sourceUrl }] = yield client.emitAndFlattenResponses('heartwood.get-skill-views::v2021_02_11', {
58
- target: {
59
- namespace,
60
- },
61
- });
62
- if (!source) {
63
- source = yield this.fetchFromUrl(sourceUrl);
64
- }
65
- const importer = ViewControllerImporter.Importer();
66
- const { controllers: skillViews, plugins, App, } = importer.import(source);
67
- skillViews.forEach((sv) => {
68
- sv.id = `${namespace}.${sv.id}`;
69
- });
70
- if (App) {
71
- //@ts-ignore
72
- App.id = namespace;
73
- this.vcFactory.setAppController(App);
74
- }
75
- this.vcFactory.importControllers(skillViews, plugins);
76
- if (theme) {
77
- this.themesByNamespace[namespace] = Object.assign(Object.assign({}, theme), { slug: namespace, name: namespace });
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
- const client = await this.connectToApi();
47
- let [{ source, theme, sourceUrl }] = await client.emitAndFlattenResponses('heartwood.get-skill-views::v2021_02_11', {
48
- target: {
49
- namespace,
50
- },
51
- });
52
- if (!source) {
53
- source = await this.fetchFromUrl(sourceUrl);
54
- }
55
- const importer = heartwood_view_controllers_1.ViewControllerImporter.Importer();
56
- const { controllers: skillViews, plugins, App, } = importer.import(source);
57
- skillViews.forEach((sv) => {
58
- sv.id = `${namespace}.${sv.id}`;
59
- });
60
- if (App) {
61
- //@ts-ignore
62
- App.id = namespace;
63
- this.vcFactory.setAppController(App);
64
- }
65
- this.vcFactory.importControllers(skillViews, plugins);
66
- if (theme) {
67
- this.themesByNamespace[namespace] = {
68
- ...theme,
69
- slug: namespace,
70
- name: namespace,
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) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-heartwood-utils",
3
3
  "description": "Heartwood Utilities",
4
- "version": "36.0.0",
4
+ "version": "36.2.0",
5
5
  "skill": {
6
6
  "namespace": "heartwood"
7
7
  },