Skip to content

Commit 09462e0

Browse files
committed
prettier
1 parent 889fcd0 commit 09462e0

File tree

8 files changed

+249
-249
lines changed

8 files changed

+249
-249
lines changed

src/adapters/datasources/datasource-mongodb.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ const processQuery = qpm({
1414
converters: {
1515
nullstring: val => {
1616
return { $type: 10 }
17-
} // reference BSON datatypes https://www.mongodb.com/docs/manual/reference/bson-types/
18-
}
17+
}, // reference BSON datatypes https://www.mongodb.com/docs/manual/reference/bson-types/
18+
},
1919
})
2020

2121
const url = process.env.MONGODB_URL || 'mongodb://localhost:27017'
2222

2323
const dsOptions = configRoot.adapters.datasources.DataSourceMongoDb.options || {
2424
runOffline: true,
25-
numConns: 2
25+
numConns: 2,
2626
}
2727

2828
const cacheSize = configRoot.adapters.cacheSize || 3000
@@ -44,7 +44,7 @@ const mongoOpts = {
4444
* even when the database is offline.
4545
*/
4646
export class DataSourceMongoDb extends DataSource {
47-
constructor (map, name, namespace, options = {}) {
47+
constructor(map, name, namespace, options = {}) {
4848
super(map, name, namespace, options)
4949
this.cacheSize = cacheSize
5050
this.mongoOpts = mongoOpts
@@ -57,15 +57,15 @@ export class DataSourceMongoDb extends DataSource {
5757
*
5858
* @returns {Promise<import('mongodb').Db>}
5959
*/
60-
async connectionPool () {
60+
async connectionPool() {
6161
return new Promise((resolve, reject) => {
6262
if (this.db) return resolve(this.db)
6363
MongoClient.connect(
6464
this.url,
6565
{
6666
...this.mongoOpts,
6767
poolSize: dsOptions.numConns || 2,
68-
connectTimeoutMS: 500
68+
connectTimeoutMS: 500,
6969
},
7070
(err, db) => {
7171
if (err) return reject(err)
@@ -76,7 +76,7 @@ export class DataSourceMongoDb extends DataSource {
7676
})
7777
}
7878

79-
connect (client) {
79+
connect(client) {
8080
return async function () {
8181
let timeout = false
8282
const timerId = setTimeout(() => {
@@ -88,21 +88,21 @@ export class DataSourceMongoDb extends DataSource {
8888
}
8989
}
9090

91-
async connection () {
91+
async connection() {
9292
try {
9393
while (connections.length < (dsOptions.numConns || 1)) {
9494
const client = new MongoClient(this.url, {
9595
...this.mongoOpts,
96-
connectTimeoutMS: 500
96+
connectTimeoutMS: 500,
9797
})
9898
const thresholds = {
9999
default: {
100100
errorRate: 1,
101101
callVolume: 1,
102102
intervalMs: 10000,
103103
testDelay: 300000,
104-
fallbackFn: () => console.log('circuit open')
105-
}
104+
fallbackFn: () => console.log('circuit open'),
105+
},
106106
}
107107
const breaker = CircuitBreaker(
108108
'mongodb.connect',
@@ -136,16 +136,16 @@ export class DataSourceMongoDb extends DataSource {
136136
}
137137
}
138138

139-
async collection () {
139+
async collection() {
140140
return (await this.connection()).db(this.namespace).collection(this.name)
141141
}
142142

143-
async createIndexes (client) {
143+
async createIndexes(client) {
144144
const indexOperations = this.options.connOpts.indexes.map(index => {
145145
return {
146146
name: index.fields.join('_'),
147147
key: index.fields.reduce((a, v) => ({ ...a, [v]: 1 }), {}),
148-
...index.options
148+
...index.options,
149149
}
150150
})
151151

@@ -155,7 +155,7 @@ export class DataSourceMongoDb extends DataSource {
155155
.createIndexes(indexOperations)
156156
}
157157

158-
async find (id) {
158+
async find(id) {
159159
try {
160160
return (await this.collection()).findOne({ _id: id })
161161
} catch (error) {
@@ -173,7 +173,7 @@ export class DataSourceMongoDb extends DataSource {
173173
* @param {*} id
174174
* @param {*} data
175175
*/
176-
async save (id, data) {
176+
async save(id, data) {
177177
try {
178178
await (
179179
await this.collection()
@@ -196,19 +196,19 @@ export class DataSourceMongoDb extends DataSource {
196196
* @param {number} highWaterMark num of docs per batch write
197197
* @returns
198198
*/
199-
createWriteStream (filter = {}, highWaterMark = HIGHWATERMARK) {
199+
createWriteStream(filter = {}, highWaterMark = HIGHWATERMARK) {
200200
try {
201201
let objects = []
202202
const ctx = this
203203

204-
async function upsert () {
204+
async function upsert() {
205205
const operations = objects.map(obj => {
206206
return {
207207
replaceOne: {
208208
filter: { ...filter, _id: obj.id },
209209
replacement: { ...obj, _id: obj.id },
210-
upsert: true
211-
}
210+
upsert: true,
211+
},
212212
}
213213
})
214214

@@ -227,17 +227,17 @@ export class DataSourceMongoDb extends DataSource {
227227
const writable = new Writable({
228228
objectMode: true,
229229

230-
async write (chunk, _encoding, next) {
230+
async write(chunk, _encoding, next) {
231231
objects.push(chunk)
232232
// if true time to flush buffer and write to db
233233
if (objects.length >= highWaterMark) await upsert()
234234
next()
235235
},
236236

237-
end (chunk, _, done) {
237+
end(chunk, _, done) {
238238
objects.push(chunk)
239239
done()
240-
}
240+
},
241241
})
242242

243243
writable.on('finish', async () => await upsert())
@@ -257,7 +257,7 @@ export class DataSourceMongoDb extends DataSource {
257257
*
258258
* @returns {Promise<import('mongodb').AbstractCursor>}
259259
*/
260-
async mongoFind ({ filter, sort, limit, aggregate, skip } = {}) {
260+
async mongoFind({ filter, sort, limit, aggregate, skip } = {}) {
261261
console.log({ fn: this.mongoFind.name, filter })
262262
let cursor = aggregate
263263
? (await this.collection()).aggregate(aggregate)
@@ -278,7 +278,7 @@ export class DataSourceMongoDb extends DataSource {
278278
* @returns
279279
*/
280280

281-
async mongoCount ({ filter = {} } = {}) {
281+
async mongoCount({ filter = {} } = {}) {
282282
return filter == {}
283283
? await this.countDb()
284284
: (await this.collection()).count(filter)
@@ -295,20 +295,20 @@ export class DataSourceMongoDb extends DataSource {
295295
* }} param0
296296
* @returns
297297
*/
298-
streamList ({ writable, serialize, transform, options }) {
298+
streamList({ writable, serialize, transform, options }) {
299299
try {
300300
const serializer = new Transform({
301301
writableObjectMode: true,
302302

303303
// start of array
304-
construct (callback) {
304+
construct(callback) {
305305
this.first = true
306306
this.push('[')
307307
callback()
308308
},
309309

310310
// each chunk is a record
311-
transform (chunk, _encoding, next) {
311+
transform(chunk, _encoding, next) {
312312
// comma-separate
313313
if (this.first) this.first = false
314314
else this.push(',')
@@ -319,32 +319,32 @@ export class DataSourceMongoDb extends DataSource {
319319
},
320320

321321
// end of array
322-
flush (callback) {
322+
flush(callback) {
323323
this.push(']')
324324
callback()
325-
}
325+
},
326326
})
327327

328328
const paginate = new Transform({
329329
writableObjectMode: true,
330330

331331
// start of array
332-
construct (callback) {
332+
construct(callback) {
333333
this.push('{ ')
334334
callback()
335335
},
336336

337337
// first chunk is the pagination data, rest is result
338-
transform (chunk, _encoding, next) {
338+
transform(chunk, _encoding, next) {
339339
this.push(chunk)
340340
next()
341341
},
342342

343343
// end of array
344-
flush (callback) {
344+
flush(callback) {
345345
this.push('}')
346346
callback()
347-
}
347+
},
348348
})
349349

350350
return new Promise(async (resolve, reject) => {
@@ -371,12 +371,12 @@ export class DataSourceMongoDb extends DataSource {
371371
} catch (error) {
372372
console.error({
373373
fn: this.streamList.name,
374-
error
374+
error,
375375
})
376376
}
377377
}
378378

379-
processOptions ({ options = {}, query = {} }) {
379+
processOptions({ options = {}, query = {} }) {
380380
return { ...processQuery(query), ...options } // options must overwite the query not otherwise
381381
}
382382

@@ -385,7 +385,7 @@ export class DataSourceMongoDb extends DataSource {
385385
* @override
386386
* @param {import('../../domain/datasource').listOptions} param
387387
*/
388-
async list (param) {
388+
async list(param) {
389389
try {
390390
let result
391391
const options = this.processOptions(param)
@@ -414,7 +414,7 @@ export class DataSourceMongoDb extends DataSource {
414414
...options,
415415
data,
416416
count,
417-
total: Math.ceil(count / options.limit)
417+
total: Math.ceil(count / options.limit),
418418
}
419419
}
420420

@@ -428,19 +428,19 @@ export class DataSourceMongoDb extends DataSource {
428428
*
429429
* @override
430430
*/
431-
async count () {
431+
async count() {
432432
return {
433433
total: await this.countDb(),
434434
cached: this.getCacheSize(),
435-
bytes: this.getCacheSizeBytes()
435+
bytes: this.getCacheSizeBytes(),
436436
}
437437
}
438438

439439
/**
440440
* @override
441441
* @returns
442442
*/
443-
async countDb () {
443+
async countDb() {
444444
return (await this.collection()).countDocuments()
445445
}
446446

@@ -451,7 +451,7 @@ export class DataSourceMongoDb extends DataSource {
451451
* @override
452452
* @param {*} id
453453
*/
454-
async delete (id) {
454+
async delete(id) {
455455
try {
456456
await (await this.collection()).deleteOne({ _id: id })
457457
} catch (error) {

src/adapters/webassembly/repo-client.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const RepoClient = {
1313
* @param {import('../../../webpack/remote-entries-type').remoteEntry} entry
1414
* @returns {Buffer|String|Uint16Array}
1515
*/
16-
octoGet (entry) {
16+
octoGet(entry) {
1717
console.info('github url', entry.url)
1818
const owner = entry.owner
1919
const repo = entry.repo
@@ -26,7 +26,7 @@ export const RepoClient = {
2626
owner,
2727
repo,
2828
filedir,
29-
branch
29+
branch,
3030
})
3131
.then(function (rest) {
3232
const file = rest.data.find(datum => /\.wasm$/.test(datum.name))
@@ -36,7 +36,7 @@ export const RepoClient = {
3636
return octokit.request('GET /repos/{owner}/{repo}/git/blobs/{sha}', {
3737
owner,
3838
repo,
39-
sha
39+
sha,
4040
})
4141
})
4242
.then(function (rest) {
@@ -49,7 +49,7 @@ export const RepoClient = {
4949
buf.buffer,
5050
buf.byteOffset,
5151
buf.length / Uint16Array.BYTES_PER_ELEMENT
52-
)
52+
),
5353
})
5454
})
5555
.catch(err => reject(err))
@@ -61,7 +61,7 @@ export const RepoClient = {
6161
* @param {*} params
6262
* @returns
6363
*/
64-
httpGet (params) {
64+
httpGet(params) {
6565
return new Promise(function (resolve, reject) {
6666
var req = require(params.protocol.slice(
6767
0,
@@ -94,9 +94,9 @@ export const RepoClient = {
9494
* @param {import('../../../webpack/remote-entries-type').remoteEntry} entry
9595
* @returns
9696
*/
97-
async fetch (entry) {
97+
async fetch(entry) {
9898
if (/^https:\/\/api.github.com.*/i.test(entry.url))
9999
return this.octoGet(entry)
100100
return this.httpGet(new URL(entry.url))
101-
}
101+
},
102102
}

0 commit comments

Comments
 (0)