integreat 0.7.36 → 0.7.37
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.
- package/lib/dispatch.js +43 -19
- package/lib/integreat.js +1 -1
- package/lib/queue/enqueue.js +17 -6
- package/lib/queue/middleware.js +5 -2
- package/package.json +5 -4
package/lib/dispatch.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
const debug = require('debug')('great')
|
|
2
|
+
const PProgress = require('p-progress')
|
|
2
3
|
const setupGetService = require('./utils/getService')
|
|
3
4
|
|
|
4
|
-
const compose = (...fns) =>
|
|
5
|
+
const compose = (...fns) =>
|
|
6
|
+
fns.reduce(
|
|
7
|
+
(f, g) =>
|
|
8
|
+
(...args) =>
|
|
9
|
+
f(g(...args))
|
|
10
|
+
)
|
|
5
11
|
|
|
6
12
|
const handleAction = (action, resources, actionHandlers) => {
|
|
7
13
|
if (action) {
|
|
@@ -13,7 +19,7 @@ const handleAction = (action, resources, actionHandlers) => {
|
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
21
|
|
|
16
|
-
return { status: 'noaction' }
|
|
22
|
+
return PProgress.resolve({ status: 'noaction' })
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
/**
|
|
@@ -22,26 +28,44 @@ const handleAction = (action, resources, actionHandlers) => {
|
|
|
22
28
|
* @param {Object} resources - Object with actions, schemas, services, and middlewares
|
|
23
29
|
* @returns {function} Dispatch function, accepting an action as only argument
|
|
24
30
|
*/
|
|
25
|
-
function setupDispatch
|
|
31
|
+
function setupDispatch({
|
|
32
|
+
actions: actionHandlers = {},
|
|
33
|
+
schemas = {},
|
|
34
|
+
services = {},
|
|
35
|
+
middlewares = [],
|
|
36
|
+
identOptions = {},
|
|
37
|
+
}) {
|
|
26
38
|
const getService = setupGetService(schemas, services)
|
|
39
|
+
const middlewareFn =
|
|
40
|
+
middlewares.length > 0
|
|
41
|
+
? compose(...middlewares)
|
|
42
|
+
: (next) => async (action) => next(action)
|
|
27
43
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
action,
|
|
32
|
-
{
|
|
33
|
-
schemas,
|
|
34
|
-
services,
|
|
35
|
-
dispatch,
|
|
36
|
-
identOptions,
|
|
37
|
-
getService
|
|
38
|
-
},
|
|
39
|
-
actionHandlers
|
|
40
|
-
)
|
|
41
|
-
}
|
|
44
|
+
const dispatch = (action) => {
|
|
45
|
+
return new PProgress(async (resolve, reject, setProgress) => {
|
|
46
|
+
debug('Dispatch: %o', action)
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
try {
|
|
49
|
+
resolve(
|
|
50
|
+
middlewareFn((action) =>
|
|
51
|
+
handleAction(
|
|
52
|
+
action,
|
|
53
|
+
{
|
|
54
|
+
schemas,
|
|
55
|
+
services,
|
|
56
|
+
dispatch,
|
|
57
|
+
identOptions,
|
|
58
|
+
getService,
|
|
59
|
+
setProgress,
|
|
60
|
+
},
|
|
61
|
+
actionHandlers
|
|
62
|
+
)
|
|
63
|
+
)(action)
|
|
64
|
+
)
|
|
65
|
+
} catch (err) {
|
|
66
|
+
reject(err)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
45
69
|
}
|
|
46
70
|
|
|
47
71
|
return dispatch
|
package/lib/integreat.js
CHANGED
package/lib/queue/enqueue.js
CHANGED
|
@@ -3,30 +3,41 @@ const createError = require('../utils/createError')
|
|
|
3
3
|
|
|
4
4
|
const prepareMetaForQueue = ({ queue, ...rest }) => ({
|
|
5
5
|
...rest,
|
|
6
|
-
queuedAt: Date.now()
|
|
6
|
+
queuedAt: Date.now(),
|
|
7
7
|
})
|
|
8
8
|
|
|
9
9
|
const prepareForQueue = (action) => ({
|
|
10
10
|
...action,
|
|
11
|
-
meta: prepareMetaForQueue(action.meta)
|
|
11
|
+
meta: prepareMetaForQueue(action.meta),
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
const enqueue = async (queue, action) => {
|
|
15
15
|
const { meta } = action
|
|
16
16
|
const queuedAction = prepareForQueue(action)
|
|
17
|
-
const timestamp =
|
|
17
|
+
const timestamp = typeof meta.queue === 'boolean' ? null : meta.queue
|
|
18
18
|
const actionId = meta.id || null
|
|
19
19
|
|
|
20
20
|
let id
|
|
21
21
|
try {
|
|
22
22
|
id = await queue.push(queuedAction, timestamp, actionId)
|
|
23
23
|
} catch (error) {
|
|
24
|
-
debug(
|
|
24
|
+
debug(
|
|
25
|
+
'Error from queue when pushing %o with timestamp %s. Error: %s',
|
|
26
|
+
queuedAction,
|
|
27
|
+
timestamp,
|
|
28
|
+
error
|
|
29
|
+
)
|
|
25
30
|
return createError(`Could not push to queue. ${error}`)
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
debug(
|
|
29
|
-
|
|
33
|
+
debug(
|
|
34
|
+
"Pushed to queue with timestamp %s and id '%s': %o",
|
|
35
|
+
timestamp,
|
|
36
|
+
id,
|
|
37
|
+
queuedAction
|
|
38
|
+
)
|
|
39
|
+
const queuedStatus = action.meta.queuedStatus || 'queued'
|
|
40
|
+
return { status: queuedStatus, data: { id } }
|
|
30
41
|
}
|
|
31
42
|
|
|
32
43
|
module.exports = enqueue
|
package/lib/queue/middleware.js
CHANGED
|
@@ -17,12 +17,15 @@ const enqueueNext = (queue, action) => {
|
|
|
17
17
|
const nextTime = getNextTime(action)
|
|
18
18
|
|
|
19
19
|
if (nextTime) {
|
|
20
|
-
const nextAction = {
|
|
20
|
+
const nextAction = {
|
|
21
|
+
...action,
|
|
22
|
+
meta: { ...action.meta, queue: nextTime.getTime() },
|
|
23
|
+
}
|
|
21
24
|
return enqueue(queue, nextAction)
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
function middleware
|
|
28
|
+
function middleware(next, queue) {
|
|
26
29
|
return async (action) => {
|
|
27
30
|
if (action.meta && action.meta.queue) {
|
|
28
31
|
return enqueue(queue, action)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "integreat",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.37",
|
|
4
4
|
"description": "Node.js integration layer",
|
|
5
5
|
"author": "Kjell-Morten Bratsberg Thorsen <post@kjellmorten.no> (http://kjellmorten.no/)",
|
|
6
6
|
"license": "ISC",
|
|
@@ -46,12 +46,13 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@sindresorhus/is": "^1.2.0",
|
|
49
|
-
"debug": "^4.3.
|
|
49
|
+
"debug": "^4.3.3",
|
|
50
50
|
"got": "^9.6.0",
|
|
51
51
|
"later": "^1.2.0",
|
|
52
52
|
"map-any": "^0.2.1",
|
|
53
53
|
"map-transform": "^0.3.12",
|
|
54
54
|
"p-limit": "^2.3.0",
|
|
55
|
+
"p-progress": "^0.5.1",
|
|
55
56
|
"ramda": "^0.27.1",
|
|
56
57
|
"uuid": "^3.4.0"
|
|
57
58
|
},
|
|
@@ -61,9 +62,9 @@
|
|
|
61
62
|
"coveralls": "^3.1.1",
|
|
62
63
|
"dotenv": "^10.0.0",
|
|
63
64
|
"integreat-adapter-json": "^0.2.1",
|
|
64
|
-
"nock": "^13.1
|
|
65
|
+
"nock": "^13.2.1",
|
|
65
66
|
"nyc": "^15.1.0",
|
|
66
|
-
"prettier": "^2.
|
|
67
|
+
"prettier": "^2.5.1",
|
|
67
68
|
"sinon": "^11.1.2"
|
|
68
69
|
}
|
|
69
70
|
}
|