@@ -31,13 +31,13 @@ export default class DocsService extends Service {
31
31
* The module of the manifest virtual module.
32
32
* This should be set to `await import('kolay/manifest:virtual')
33
33
*/
34
- manifest ?: any ;
34
+ manifest ?: Promise < any > ;
35
35
36
36
/**
37
37
* The module of the api docs virtual module.
38
38
* This should be set to `await import('kolay/api-docs:virtual')
39
39
*/
40
- apiDocs ?: any ;
40
+ apiDocs ?: Promise < any > ;
41
41
42
42
/**
43
43
* Additional invokables that you'd like to have access to
@@ -58,7 +58,7 @@ export default class DocsService extends Service {
58
58
* and allows you to have access to private libraries without
59
59
* needing to publish those libraries to NPM.
60
60
*/
61
- resolve ?: Record < string , Record < string , unknown > > ;
61
+ resolve ?: Record < string , Promise < Record < string , unknown > > > ;
62
62
63
63
/**
64
64
* Provide additional remark plugins to the default markdown compiler.
@@ -73,17 +73,23 @@ export default class DocsService extends Service {
73
73
*/
74
74
rehypePlugins ?: unknown [ ] ;
75
75
} ) => {
76
+ let [ manifest , apiDocs , resolve ] = await Promise . all ( [
77
+ options . manifest ,
78
+ options . apiDocs ,
79
+ promiseHash ( options . resolve ) ,
80
+ ] ) ;
81
+
76
82
if ( options . manifest ) {
77
- this . loadManifest = options . manifest . load ;
83
+ this . loadManifest = manifest . load ;
78
84
}
79
85
80
86
if ( options . apiDocs ) {
81
- this . apiDocs . _packages = options . apiDocs . packages ;
82
- this . apiDocs . loadApiDocs = options . apiDocs . loadApiDocs ;
87
+ this . apiDocs . _packages = apiDocs . packages ;
88
+ this . apiDocs . loadApiDocs = apiDocs . loadApiDocs ;
83
89
}
84
90
85
91
if ( options . resolve ) {
86
- this . additionalResolves = options . resolve ;
92
+ this . additionalResolves = resolve ;
87
93
}
88
94
89
95
if ( options . topLevelScope ) {
@@ -191,6 +197,49 @@ export default class DocsService extends Service {
191
197
} ;
192
198
}
193
199
200
+ /**
201
+ * RSVP.hash, but native
202
+ */
203
+ async function promiseHash < T > (
204
+ obj ?: Record < string , Promise < T > > ,
205
+ ) : Promise < Record < string , T > > {
206
+ let result : Record < string , T > = { } ;
207
+
208
+ if ( ! obj ) {
209
+ return result ;
210
+ }
211
+
212
+ let keys : string [ ] = [ ] ;
213
+ let promises = [ ] ;
214
+
215
+ for ( let [ key , promise ] of Object . entries ( obj ) ) {
216
+ keys . push ( key ) ;
217
+ promises . push ( promise ) ;
218
+ }
219
+
220
+ assert (
221
+ `Something went wrong when resolving a promise Hash` ,
222
+ keys . length === promises . length ,
223
+ ) ;
224
+
225
+ let resolved = await Promise . all ( promises ) ;
226
+
227
+ for ( let i = 0 ; i < resolved . length ; i ++ ) {
228
+ let key = keys [ i ] ;
229
+ let resolvedValue = resolved [ i ] ;
230
+
231
+ assert ( `Missing key for index ${ i } ` , key ) ;
232
+ assert (
233
+ `Resolved value for key ${ key } is not an object` ,
234
+ typeof resolvedValue === 'object' ,
235
+ ) ;
236
+
237
+ result [ key ] = resolvedValue ;
238
+ }
239
+
240
+ return result ;
241
+ }
242
+
194
243
// DO NOT DELETE: this is how TypeScript knows how to look up your services.
195
244
declare module '@ember/service' {
196
245
interface Registry {
0 commit comments