@@ -9,8 +9,18 @@ class Application {
99
1010 cache ;
1111
12+ /**
13+ * Get application stream structure
14+ * Initialized at init()
15+ * Can be refreshed with loadStreamData
16+ */
17+ get streamData ( ) {
18+ if ( ! this . cache . streamData ) throw new Error ( 'Call .init() first' ) ;
19+ return this . cache . streamData ;
20+ }
21+
1222 get appSettings ( ) {
13- throw new Error ( 'appSettings must be implemneted ' ) ;
23+ throw new Error ( 'appSettings must be implemented ' ) ;
1424 // possible return values:
1525 /**
1626 * return {
@@ -69,6 +79,17 @@ class Application {
6979 async init ( ) {
7080 await createAppStreams ( this ) ;
7181 }
82+
83+ /**
84+ * Force loading of streamData
85+ */
86+ async loadStreamData ( ) {
87+ const streamData = ( await this . connection . apiOne ( 'streams.get' , { id : this . baseStreamId } , 'streams' ) ) [ 0 ] ;
88+ if ( streamData ) {
89+ this . cache . streamData = streamData ;
90+ }
91+ return streamData ;
92+ }
7293}
7394
7495module . exports = Application ;
@@ -101,11 +122,8 @@ async function createAppStreams (app) {
101122 // get streamStructure
102123 let found = false ;
103124 try {
104- const stream = ( await app . connection . apiOne ( 'streams.get' , { id : app . baseStreamId } , 'streams' ) ) [ 0 ] ;
105- if ( stream ) {
106- app . cache . streamData = stream ;
107- }
108- found = true ;
125+ const streamData = await app . loadStreamData ( ) ;
126+ if ( streamData ) found = true ;
109127 } catch ( e ) {
110128 if ( e . innerObject ?. id !== 'unknown-referenced-resource' || e . innerObject ?. data ?. id !== 'test-app-template-client' ) {
111129 throw e ;
0 commit comments