integreat 0.7.40 → 0.7.42

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.
@@ -50,12 +50,6 @@ function filterResponseData(data, id) {
50
50
  return data.filter((data) => ids.includes(data.id))
51
51
  }
52
52
 
53
- const removeData = ({ type, payload: { data, ...payload }, meta }) => ({
54
- type,
55
- payload,
56
- meta,
57
- })
58
-
59
53
  /**
60
54
  * Get several items from a service, based on the given action object.
61
55
  * @param {Object} action - payload and ident from the action object
@@ -90,7 +84,7 @@ async function get(action, { getService } = {}) {
90
84
  debug('GET: Fetch from service %s at %s', service.id, endpointDebug)
91
85
 
92
86
  const { response } = await service.send(
93
- appendToAction(removeData(action), { id, onlyMappedValues })
87
+ appendToAction(action, { id, onlyMappedValues })
94
88
  )
95
89
 
96
90
  return filterWithId
@@ -135,10 +135,12 @@ const generateDoneParams = ({ from, type, done }) => {
135
135
  }
136
136
 
137
137
  const generateTransformParams = ({ transform }, { service, type }) => {
138
- if (transform) {
139
- return { service, type, ...transform }
138
+ if (Array.isArray(transform)) {
139
+ return transform.map((trans) => ({ service, type, ...trans }))
140
+ } else if (transform) {
141
+ return [{ service, type, ...transform }]
140
142
  }
141
- return null
143
+ return []
142
144
  }
143
145
 
144
146
  // TODO: Updated dates from the first fromParams are always used on toParams.
@@ -259,6 +261,19 @@ function getLastSyncedAt(
259
261
  }
260
262
  return undefined
261
263
  }
264
+
265
+ async function transformPipeline(data, dispatch, transformParams, meta) {
266
+ let response
267
+ for (const params of transformParams) {
268
+ const nextData = response ? response.data : data
269
+ response = await dispatch(createTransformAction(params, nextData, meta))
270
+ if (response.status !== 'ok') {
271
+ return response
272
+ }
273
+ }
274
+ return response
275
+ }
276
+
262
277
  async function transformData(
263
278
  data,
264
279
  dispatch,
@@ -269,13 +284,11 @@ async function transformData(
269
284
  if (useIndividualTransform) {
270
285
  return await Promise.all(
271
286
  data
272
- .map((item) =>
273
- dispatch(createTransformAction(transformParams, item, meta))
274
- )
287
+ .map((item) => transformPipeline(item, dispatch, transformParams, meta))
275
288
  .map((p) => pLimit(1)(() => p))
276
289
  )
277
290
  } else {
278
- return [await dispatch(createTransformAction(transformParams, data, meta))]
291
+ return [await transformPipeline(data, dispatch, transformParams, meta)]
279
292
  }
280
293
  }
281
294
 
@@ -337,7 +350,7 @@ async function sync({ payload, meta = {} }, { dispatch, getService }) {
337
350
  ) || new Date()
338
351
 
339
352
  // Dispatch transform action
340
- if (transformParams) {
353
+ if (transformParams.length > 0) {
341
354
  const transformResults = await transformData(
342
355
  data,
343
356
  dispatch,
package/lib/integreat.js CHANGED
@@ -5,7 +5,7 @@ const setupMapping = require('./mapping')
5
5
  const setupDispatch = require('./dispatch')
6
6
  const builtinActions = require('./actions')
7
7
 
8
- const version = '0.7.40'
8
+ const version = '0.7.42'
9
9
 
10
10
  /**
11
11
  * Return an Integreat instance with a dispatch method.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "integreat",
3
- "version": "0.7.40",
3
+ "version": "0.7.42",
4
4
  "description": "Node.js integration layer",
5
5
  "author": "Kjell-Morten Bratsberg Thorsen <post@kjellmorten.no> (http://kjellmorten.no/)",
6
6
  "license": "ISC",