@@ -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,12 +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
181- const opts = { ...options , streamRequested : options ?. writable }
181+ const opts = {
182+ ...options ,
183+ streamRequested : options ?. writable ? true : false
184+ }
182185 const list = [ await super . list ( opts ) ] . flat ( )
183186
184187 if ( list . length < 1 ) return [ ]
@@ -202,7 +205,7 @@ const DsCoreExtensions = superclass =>
202205 * @param {* } id
203206 * @returns
204207 */
205- async delete ( id ) {
208+ async delete ( id ) {
206209 try {
207210 await super . delete ( id )
208211 // only if super succeeds
@@ -238,11 +241,11 @@ const DataSourceFactory = (() => {
238241 * @param {* } name
239242 * @returns
240243 */
241- function hasDataSource ( name ) {
244+ function hasDataSource ( name ) {
242245 return dataSources . has ( name )
243246 }
244247
245- function listDataSources ( ) {
248+ function listDataSources ( ) {
246249 return [ ...dataSources . keys ( ) ]
247250 }
248251
@@ -267,7 +270,7 @@ const DataSourceFactory = (() => {
267270 * @param {dsOpts } options
268271 * @returns {typeof DataSource }
269272 */
270- function createDataSourceClass ( spec , options ) {
273+ function createDataSourceClass ( spec , options ) {
271274 const { memoryOnly, ephemeral, adapterName } = options
272275
273276 if ( memoryOnly || ephemeral ) return dsClasses [ 'DataSourceMemory' ]
@@ -295,7 +298,7 @@ const DataSourceFactory = (() => {
295298 * @param {dsOpts } options
296299 * @returns {typeof DataSource }
297300 */
298- function extendDataSourceClass ( DsClass , options = { } ) {
301+ function extendDataSourceClass ( DsClass , options = { } ) {
299302 const mixins = [ extendClass ] . concat ( options . mixins || [ ] )
300303 return compose ( ...mixins ) ( DsClass )
301304 }
@@ -306,7 +309,7 @@ const DataSourceFactory = (() => {
306309 * @param {dsOpts } [options]
307310 * @returns {DataSource }
308311 */
309- function createDataSource ( name , namespace , options ) {
312+ function createDataSource ( name , namespace , options ) {
310313 const spec = ModelFactory . getModelSpec ( name )
311314 const dsMap = options . dsMap || new Map ( )
312315
@@ -332,7 +335,7 @@ const DataSourceFactory = (() => {
332335 * @param {dsOpts } options
333336 * @returns {import('./datasource').default }
334337 */
335- function getDataSource ( name , namespace = null , options = { } ) {
338+ function getDataSource ( name , namespace = null , options = { } ) {
336339 if ( ! dataSources ) dataSources = new Map ( )
337340 if ( ! namespace ) return dataSources . get ( name )
338341 if ( dataSources . has ( name ) ) return dataSources . get ( name )
@@ -347,7 +350,7 @@ const DataSourceFactory = (() => {
347350 * @param {dsOpts } [options]
348351 * @returns
349352 */
350- function getSharedDataSource ( name , namespace = null , options = { } ) {
353+ function getSharedDataSource ( name , namespace = null , options = { } ) {
351354 if ( ! dataSources ) dataSources = new Map ( )
352355 if ( ! namespace ) return dataSources . get ( name )
353356 if ( dataSources . has ( name ) ) return dataSources . get ( name )
@@ -362,20 +365,20 @@ const DataSourceFactory = (() => {
362365 * @param {string } name
363366 * @returns {ProxyHandler<DataSource> }
364367 */
365- function getRestrictedDataSource ( name , namespace , options ) {
368+ function getRestrictedDataSource ( name , namespace , options ) {
366369 return new Proxy ( getDataSource ( name , namespace , options ) , {
367- get ( target , key ) {
370+ get ( target , key ) {
368371 if ( key === 'factory' ) {
369372 throw new Error ( 'unauthorized' )
370373 }
371374 } ,
372- ownKeys ( target ) {
375+ ownKeys ( target ) {
373376 return [ ]
374- } ,
377+ }
375378 } )
376379 }
377380
378- function close ( ) {
381+ function close ( ) {
379382 dataSources . forEach ( ds => ds . close ( ) )
380383 }
381384
@@ -390,7 +393,7 @@ const DataSourceFactory = (() => {
390393 getRestrictedDataSource,
391394 hasDataSource,
392395 listDataSources,
393- close,
396+ close
394397 } )
395398} ) ( )
396399
0 commit comments