bajo-extra 0.2.11 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -16,14 +16,24 @@ async function handler (rec, bulk) {
|
|
|
16
16
|
if (existing) {
|
|
17
17
|
if (save.mode === 'upsert') {
|
|
18
18
|
const body = save.updateConverter ? await save.updateConverter.call(this, rec, save) : rec
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
try {
|
|
20
|
+
record = await recordUpdate(save.coll, existing.id, body)
|
|
21
|
+
method = 'updated'
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.error(err)
|
|
24
|
+
method = 'error'
|
|
25
|
+
}
|
|
21
26
|
} else {
|
|
22
27
|
method = 'skipped'
|
|
23
28
|
}
|
|
24
29
|
} else {
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
try {
|
|
31
|
+
record = await recordCreate(save.coll, rec)
|
|
32
|
+
method = 'created'
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error(err)
|
|
35
|
+
method = 'error'
|
|
36
|
+
}
|
|
27
37
|
}
|
|
28
38
|
if (record && current.coll && current.query) {
|
|
29
39
|
const query = await current.query.call(this, { body: rec, record, opts: save })
|
|
@@ -42,10 +52,14 @@ async function handler (rec, bulk) {
|
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
async function fetchAndSave ({ url, bulk, save = {}, opts = {} } = {}) {
|
|
45
|
-
const { importPkg } = this.bajo.helper
|
|
55
|
+
const { importPkg, getConfig, importModule } = this.bajo.helper
|
|
46
56
|
const { fetchBulk } = this.bajoExtra.helper
|
|
47
57
|
const { merge } = await importPkg('lodash-es')
|
|
48
58
|
merge(bulk, { handler, save })
|
|
59
|
+
const cfgDb = getConfig('bajoDb', { full: true })
|
|
60
|
+
const start = await importModule(`${cfgDb.dir.pkg}/bajo/start.js`)
|
|
61
|
+
await start.call(this, 'all')
|
|
62
|
+
|
|
49
63
|
await fetchBulk(url, bulk, opts)
|
|
50
64
|
}
|
|
51
65
|
|
|
@@ -18,6 +18,7 @@ async function fetching ({ url, opts, bulk, spin }) {
|
|
|
18
18
|
let count = 0
|
|
19
19
|
const stat = { created: 0, updated: 0, skipped: 0, error: 0 }
|
|
20
20
|
bulk.dataKey = bulk.dataKey ?? 'data'
|
|
21
|
+
if (bulk.printCount === true) bulk.printCount = 100
|
|
21
22
|
const data = isFunction(bulk.dataKey) ? await bulk.dataKey.call(this, resp) : resp[bulk.dataKey]
|
|
22
23
|
if (data.length === 0) {
|
|
23
24
|
print.warn('No records to process, abort')
|
|
@@ -43,7 +44,7 @@ async function fetching ({ url, opts, bulk, spin }) {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
print.succeed('[%s] %d/%d records processed', spin.getElapsed(), count, data.length)
|
|
46
|
-
print.succeed('[%s] Created: %d, Updated: %d, Skipped: %d', spin.getElapsed(), stat.created, stat.updated, stat.skipped)
|
|
47
|
+
if (!bulk.noStat) print.succeed('[%s] Created: %d, Updated: %d, Skipped: %d', spin.getElapsed(), stat.created, stat.updated, stat.skipped)
|
|
47
48
|
return data.length
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -53,7 +54,7 @@ async function fetchBulk (url, bulk = {}, opts = {}) {
|
|
|
53
54
|
opts.params = opts.params ?? {}
|
|
54
55
|
bulk.maxStep = bulk.maxStep ?? 0
|
|
55
56
|
if (!isFunction(bulk.handler)) throw error('A function handler must be provided')
|
|
56
|
-
if (
|
|
57
|
+
if (isFunction(bulk.paramsIncFn)) {
|
|
57
58
|
print.info('Bulk fetch starting')
|
|
58
59
|
const spin = spinner({ showCounter: true }).start('Fetching starts...')
|
|
59
60
|
let step = 1
|