@@ -38,15 +38,15 @@ const DefaultDataSource =
3838 */
3939const DsCoreExtensions = superclass =>
4040 class extends superclass {
41- constructor ( map , name , namespace , options ) {
41+ constructor ( map , name , namespace , options ) {
4242 super ( map , name , namespace , options )
4343 }
4444
45- set factory ( value ) {
45+ set factory ( value ) {
4646 this [ FACTORY ] = value
4747 }
4848
49- get factory ( ) {
49+ get factory ( ) {
5050 return this [ FACTORY ]
5151 }
5252
@@ -61,7 +61,7 @@ const DsCoreExtensions = superclass =>
6161 * @param {string } id
6262 * @param {Model } data
6363 */
64- async save ( id , data ) {
64+ async save ( id , data ) {
6565 try {
6666 this . saveSync ( id , data )
6767 await super . save ( id , JSON . parse ( JSON . stringify ( data ) ) )
@@ -78,7 +78,7 @@ const DsCoreExtensions = superclass =>
7878 * @param {string } id
7979 * @returns {Promise<Model>|undefined }
8080 */
81- async find ( id ) {
81+ async find ( id ) {
8282 try {
8383 const cached = this . findSync ( id )
8484 if ( cached ) return cached
@@ -98,33 +98,33 @@ const DsCoreExtensions = superclass =>
9898 }
9999 }
100100
101- hydrate ( ) {
101+ hydrate ( ) {
102102 const ctx = this
103103
104104 return new Transform ( {
105105 objectMode : true ,
106106
107- transform ( chunk , encoding , next ) {
107+ transform ( chunk , encoding , next ) {
108108 this . push ( ModelFactory . loadModel ( broker , ctx , chunk , ctx . name ) )
109109 next ( )
110- } ,
110+ }
111111 } )
112112 }
113113
114- serialize ( ) {
114+ serialize ( ) {
115115 let first = true
116116
117117 return new Transform ( {
118118 objectMode : true ,
119119
120120 // start of array
121- construct ( callback ) {
121+ construct ( callback ) {
122122 this . push ( '[' )
123123 callback ( )
124124 } ,
125125
126126 // each chunk is a record
127- transform ( chunk , encoding , next ) {
127+ transform ( chunk , encoding , next ) {
128128 // comma-separate
129129 if ( first ) first = false
130130 else this . push ( ',' )
@@ -135,10 +135,10 @@ const DsCoreExtensions = superclass =>
135135 } ,
136136
137137 // end of array
138- flush ( callback ) {
138+ flush ( callback ) {
139139 this . push ( ']' )
140140 callback ( )
141- } ,
141+ }
142142 } )
143143 }
144144
@@ -148,7 +148,7 @@ const DsCoreExtensions = superclass =>
148148 * @param {import('./datasource').listOptions } options
149149 * @returns {Array<Readable|Transform> }
150150 */
151- stream ( list , options ) {
151+ stream ( list , options ) {
152152 return new Promise ( ( resolve , reject ) => {
153153 options . writable . on ( 'error' , reject )
154154 options . writable . on ( 'end' , resolve )
@@ -173,14 +173,15 @@ const DsCoreExtensions = superclass =>
173173 * @override
174174 * @param {import('../../domain/datasource').listOptions } param
175175 */
176- async list ( options ) {
176+ async list ( options ) {
177177 try {
178178 if ( options ?. query ?. __count ) return this . count ( )
179179 if ( options ?. query ?. __cached ) return this . listSync ( options . query )
180180
181181 const opts = { ...options , streamRequested : options ?. writable }
182182 const list = [ await super . list ( opts ) ] . flat ( )
183183
184+ console . debug ( { list } )
184185 if ( list . length < 1 ) return [ ]
185186
186187 if ( list [ 0 ] instanceof Readable || list [ 0 ] instanceof Transform )
@@ -202,7 +203,7 @@ const DsCoreExtensions = superclass =>
202203 * @param {* } id
203204 * @returns
204205 */
205- async delete ( id ) {
206+ async delete ( id ) {
206207 try {
207208 await super . delete ( id )
208209 // only if super succeeds
@@ -238,11 +239,11 @@ const DataSourceFactory = (() => {
238239 * @param {* } name
239240 * @returns
240241 */
241- function hasDataSource ( name ) {
242+ function hasDataSource ( name ) {
242243 return dataSources . has ( name )
243244 }
244245
245- function listDataSources ( ) {
246+ function listDataSources ( ) {
246247 return [ ...dataSources . keys ( ) ]
247248 }
248249
@@ -267,7 +268,7 @@ const DataSourceFactory = (() => {
267268 * @param {dsOpts } options
268269 * @returns {typeof DataSource }
269270 */
270- function createDataSourceClass ( spec , options ) {
271+ function createDataSourceClass ( spec , options ) {
271272 const { memoryOnly, ephemeral, adapterName } = options
272273
273274 if ( memoryOnly || ephemeral ) return dsClasses [ 'DataSourceMemory' ]
@@ -295,7 +296,7 @@ const DataSourceFactory = (() => {
295296 * @param {dsOpts } options
296297 * @returns {typeof DataSource }
297298 */
298- function extendDataSourceClass ( DsClass , options = { } ) {
299+ function extendDataSourceClass ( DsClass , options = { } ) {
299300 const mixins = [ extendClass ] . concat ( options . mixins || [ ] )
300301 return compose ( ...mixins ) ( DsClass )
301302 }
@@ -306,7 +307,7 @@ const DataSourceFactory = (() => {
306307 * @param {dsOpts } [options]
307308 * @returns {DataSource }
308309 */
309- function createDataSource ( name , namespace , options ) {
310+ function createDataSource ( name , namespace , options ) {
310311 const spec = ModelFactory . getModelSpec ( name )
311312 const dsMap = options . dsMap || new Map ( )
312313
@@ -332,7 +333,7 @@ const DataSourceFactory = (() => {
332333 * @param {dsOpts } options
333334 * @returns {import('./datasource').default }
334335 */
335- function getDataSource ( name , namespace = null , options = { } ) {
336+ function getDataSource ( name , namespace = null , options = { } ) {
336337 if ( ! dataSources ) dataSources = new Map ( )
337338 if ( ! namespace ) return dataSources . get ( name )
338339 if ( dataSources . has ( name ) ) return dataSources . get ( name )
@@ -347,7 +348,7 @@ const DataSourceFactory = (() => {
347348 * @param {dsOpts } [options]
348349 * @returns
349350 */
350- function getSharedDataSource ( name , namespace = null , options = { } ) {
351+ function getSharedDataSource ( name , namespace = null , options = { } ) {
351352 if ( ! dataSources ) dataSources = new Map ( )
352353 if ( ! namespace ) return dataSources . get ( name )
353354 if ( dataSources . has ( name ) ) return dataSources . get ( name )
@@ -362,20 +363,20 @@ const DataSourceFactory = (() => {
362363 * @param {string } name
363364 * @returns {ProxyHandler<DataSource> }
364365 */
365- function getRestrictedDataSource ( name , namespace , options ) {
366+ function getRestrictedDataSource ( name , namespace , options ) {
366367 return new Proxy ( getDataSource ( name , namespace , options ) , {
367- get ( target , key ) {
368+ get ( target , key ) {
368369 if ( key === 'factory' ) {
369370 throw new Error ( 'unauthorized' )
370371 }
371372 } ,
372- ownKeys ( target ) {
373+ ownKeys ( target ) {
373374 return [ ]
374- } ,
375+ }
375376 } )
376377 }
377378
378- function close ( ) {
379+ function close ( ) {
379380 dataSources . forEach ( ds => ds . close ( ) )
380381 }
381382
@@ -390,7 +391,7 @@ const DataSourceFactory = (() => {
390391 getRestrictedDataSource,
391392 hasDataSource,
392393 listDataSources,
393- close,
394+ close
394395 } )
395396} ) ( )
396397
0 commit comments