@commercetools/sync-actions 7.0.0-rc.2 → 7.0.0

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.
@@ -1,35 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- })
6
- exports.default = createMapActionGroup
7
- // Array of action groups which need to be whitelisted or blacklisted.
8
- // Example:
9
- // [
10
- // { type: 'base', group: 'black' },
11
- // { type: 'prices', group: 'white' },
12
- // { type: 'variants', group: 'black' },
13
- // ]
14
- function createMapActionGroup() {
15
- var actionGroups =
16
- arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []
17
-
18
- return function mapActionGroup(type, fn) {
19
- if (!Object.keys(actionGroups).length) return fn()
20
-
21
- var found = actionGroups.find(function(c) {
22
- return c.type === type
23
- })
24
- if (!found) return []
25
-
26
- if (found.group === 'black') return []
27
- if (found.group === 'white') return fn()
28
-
29
- throw new Error(
30
- "Action group '" +
31
- found.group +
32
- "' not supported. Please use black or white."
33
- )
34
- }
35
- }
@@ -1,93 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- })
6
-
7
- var _typeof =
8
- typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
9
- ? function(obj) {
10
- return typeof obj
11
- }
12
- : function(obj) {
13
- return obj &&
14
- typeof Symbol === 'function' &&
15
- obj.constructor === Symbol &&
16
- obj !== Symbol.prototype
17
- ? 'symbol'
18
- : typeof obj
19
- } // Requiring directily from `jsondiffpatch` entry point will cause warnings
20
- // while bundling with webpack because of dynamic requires.
21
- // To get around this issue, simply require the `Diffpatcher` directly.
22
- // https://github.com/benjamine/jsondiffpatch/issues/76#issuecomment-270207970
23
-
24
- exports.objectHash = objectHash
25
- exports.diff = diff
26
- exports.patch = patch
27
- exports.getDeltaValue = getDeltaValue
28
-
29
- var _diffpatcher = require('jsondiffpatch/src/diffpatcher')
30
-
31
- var diffpatcher = new _diffpatcher.DiffPatcher({
32
- objectHash: objectHash,
33
- arrays: {
34
- // detect items moved inside the array
35
- detectMove: true,
36
-
37
- // value of items moved is not included in deltas
38
- includeValueOnMove: false,
39
- },
40
- textDiff: {
41
- // If the value to diff has a bigger length,
42
- // a text diffing algorithm is used
43
- // See https://github.com/benjamine/jsondiffpatch/
44
- // blob/master/docs/deltas.md#text-diffs
45
- minLength: 300,
46
- },
47
- })
48
-
49
- function objectHash(obj, index) {
50
- var objIndex = '$$index:' + index
51
- return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) ===
52
- 'object' && obj !== null
53
- ? obj.id || obj.name || obj.url || objIndex
54
- : objIndex
55
- }
56
-
57
- function diff(oldObj, newObj) {
58
- return diffpatcher.diff(oldObj, newObj)
59
- }
60
-
61
- function patch(obj, delta) {
62
- return diffpatcher.patch(obj, delta)
63
- }
64
-
65
- function getDeltaValue(arr, originalObject) {
66
- if (!Array.isArray(arr))
67
- throw new Error('Expected array to extract delta value')
68
-
69
- if (arr.length === 1) return arr[0] // new
70
-
71
- if (arr.length === 2) return arr[1] // update
72
-
73
- if (arr.length === 3 && arr[2] === 0) return undefined // delete
74
-
75
- if (arr.length === 3 && arr[2] === 2) {
76
- // text diff
77
- if (!originalObject)
78
- throw new Error(
79
- 'Cannot apply patch to long text diff. Missing original object.'
80
- )
81
- // try to apply patch to given object based on delta value
82
- return patch(originalObject, arr)
83
- }
84
-
85
- if (arr.length === 3 && arr[2] === 3)
86
- // array move
87
- throw new Error(
88
- 'Detected an array move, it should not happen as ' +
89
- '`includeValueOnMove` should be set to false'
90
- )
91
-
92
- throw new Error('Got unsupported number ' + arr[2] + ' in delta value')
93
- }
@@ -1,67 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- })
6
- exports.default = findMatchingPairs
7
-
8
- var _lodash = require('lodash.foreach')
9
-
10
- var _lodash2 = _interopRequireDefault(_lodash)
11
-
12
- function _interopRequireDefault(obj) {
13
- return obj && obj.__esModule ? obj : { default: obj }
14
- }
15
-
16
- var REGEX_NUMBER = new RegExp(/^\d+$/)
17
- var REGEX_UNDERSCORE_NUMBER = new RegExp(/^_\d+$/)
18
-
19
- function preProcessCollection() {
20
- var collection =
21
- arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []
22
- var identifier =
23
- arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id'
24
-
25
- return collection.reduce(
26
- function(acc, currentValue, currentIndex) {
27
- acc.refByIndex[String(currentIndex)] = currentValue[identifier]
28
- acc.refByIdentifier[currentValue[identifier]] = String(currentIndex)
29
- return acc
30
- },
31
- {
32
- refByIndex: {},
33
- refByIdentifier: {},
34
- }
35
- )
36
- }
37
-
38
- // creates a hash of a location of an item in collection1 and collection2
39
- function findMatchingPairs(diff) {
40
- var before =
41
- arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []
42
- var now =
43
- arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []
44
- var identifier =
45
- arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'id'
46
-
47
- var result = {}
48
-
49
- var _preProcessCollection = preProcessCollection(before, identifier),
50
- beforeObjRefByIdentifier = _preProcessCollection.refByIdentifier,
51
- beforeObjRefByIndex = _preProcessCollection.refByIndex
52
-
53
- var _preProcessCollection2 = preProcessCollection(now, identifier),
54
- nowObjRefByIdentifier = _preProcessCollection2.refByIdentifier,
55
- nowObjRefByIndex = _preProcessCollection2.refByIndex
56
- ;(0, _lodash2.default)(diff, function(item, key) {
57
- if (REGEX_NUMBER.test(key)) {
58
- var matchingIdentifier = nowObjRefByIndex[key]
59
- result[key] = [beforeObjRefByIdentifier[matchingIdentifier], key]
60
- } else if (REGEX_UNDERSCORE_NUMBER.test(key)) {
61
- var index = key.substring(1)
62
- var _matchingIdentifier = beforeObjRefByIndex[index]
63
- result[key] = [index, nowObjRefByIdentifier[_matchingIdentifier]]
64
- }
65
- })
66
- return result
67
- }