contentful-import 9.0.21 → 9.1.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,14 +1,31 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
5
17
  });
6
- exports.default = sortEntries;
7
- var _collection = require("lodash/collection");
8
- var _o = _interopRequireWildcard(require("lodash/object"));
9
- var _array = require("lodash/array");
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const collection_1 = require("lodash/collection");
27
+ const _o = __importStar(require("lodash/object"));
28
+ const array_1 = require("lodash/array");
12
29
  /**
13
30
  * Given a list of entries, this function reorders them so that entries which
14
31
  * are linked from other entries always come first in the order. This ensures
@@ -16,49 +33,51 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
16
33
  * links to other entries which haven't been published yet.
17
34
  */
18
35
  function sortEntries(entries) {
19
- const linkedEntries = getLinkedEntries(entries);
20
- const mergedLinkedEntries = mergeSort(linkedEntries, a => {
21
- return hasLinkedIndexesInFront(a);
22
- });
23
- return (0, _collection.map)(mergedLinkedEntries, linkInfo => entries[linkInfo.index]);
24
- function hasLinkedIndexesInFront(item) {
25
- if (hasLinkedIndexes(item)) {
26
- return (0, _collection.some)(item.linkIndexes, index => index > item.index) ? 1 : -1;
36
+ const linkedEntries = getLinkedEntries(entries);
37
+ const mergedLinkedEntries = mergeSort(linkedEntries, (a) => {
38
+ return hasLinkedIndexesInFront(a);
39
+ });
40
+ return (0, collection_1.map)(mergedLinkedEntries, (linkInfo) => entries[linkInfo.index]);
41
+ function hasLinkedIndexesInFront(item) {
42
+ if (hasLinkedIndexes(item)) {
43
+ return (0, collection_1.some)(item.linkIndexes, (index) => index > item.index) ? 1 : -1;
44
+ }
45
+ return 0;
46
+ }
47
+ function hasLinkedIndexes(item) {
48
+ return item.linkIndexes.length > 0;
27
49
  }
28
- return 0;
29
- }
30
- function hasLinkedIndexes(item) {
31
- return item.linkIndexes.length > 0;
32
- }
33
50
  }
51
+ exports.default = sortEntries;
34
52
  function getLinkedEntries(entries) {
35
- return (0, _collection.map)(entries, function (entry) {
36
- const entryIndex = entries.indexOf(entry);
37
- const rawLinks = (0, _collection.map)(entry.fields, field => {
38
- field = _o.values(field)[0];
39
- if (isEntryLink(field)) {
40
- return getFieldEntriesIndex(field, entries);
41
- } else if (isEntityArray(field) && isEntryLink(field[0])) {
42
- return (0, _collection.map)(field, item => getFieldEntriesIndex(item, entries));
43
- }
53
+ return (0, collection_1.map)(entries, function (entry) {
54
+ const entryIndex = entries.indexOf(entry);
55
+ const rawLinks = (0, collection_1.map)(entry.fields, (field) => {
56
+ field = _o.values(field)[0];
57
+ if (isEntryLink(field)) {
58
+ return getFieldEntriesIndex(field, entries);
59
+ }
60
+ else if (isEntityArray(field) && isEntryLink(field[0])) {
61
+ return (0, collection_1.map)(field, (item) => getFieldEntriesIndex(item, entries));
62
+ }
63
+ });
64
+ return {
65
+ index: entryIndex,
66
+ linkIndexes: (0, collection_1.filter)((0, array_1.flatten)(rawLinks), (index) => index >= 0)
67
+ };
44
68
  });
45
- return {
46
- index: entryIndex,
47
- linkIndexes: (0, _collection.filter)((0, _array.flatten)(rawLinks), index => index >= 0)
48
- };
49
- });
50
69
  }
51
70
  function getFieldEntriesIndex(field, entries) {
52
- const id = _o.get(field, 'sys.id');
53
- return entries.findIndex(entry => entry.sys.id === id);
71
+ const id = _o.get(field, 'sys.id');
72
+ return entries.findIndex((entry) => entry.sys.id === id);
54
73
  }
55
74
  function isEntryLink(item) {
56
- return _o.get(item, 'sys.type') === 'Entry' || _o.get(item, 'sys.linkType') === 'Entry';
75
+ return _o.get(item, 'sys.type') === 'Entry' ||
76
+ _o.get(item, 'sys.linkType') === 'Entry';
57
77
  }
58
78
  function isEntityArray(item) {
59
- return Array.isArray(item) && item.length > 0 && _o.has(item[0], 'sys');
79
+ return Array.isArray(item) && item.length > 0 && _o.has(item[0], 'sys');
60
80
  }
61
-
62
81
  /**
63
82
  * From https://github.com/millermedeiros/amd-utils/blob/master/src/array/sort.js
64
83
  * MIT Licensed
@@ -66,28 +85,32 @@ function isEntityArray(item) {
66
85
  * @version 0.1.0 (2012/05/23)
67
86
  */
68
87
  function mergeSort(arr, compareFn) {
69
- if (arr.length < 2) return arr;
70
- if (compareFn == null) compareFn = defaultCompare;
71
- const mid = ~~(arr.length / 2);
72
- const left = mergeSort(arr.slice(0, mid), compareFn);
73
- const right = mergeSort(arr.slice(mid, arr.length), compareFn);
74
- return merge(left, right, compareFn);
88
+ if (arr.length < 2)
89
+ return arr;
90
+ if (compareFn == null)
91
+ compareFn = defaultCompare;
92
+ const mid = ~~(arr.length / 2);
93
+ const left = mergeSort(arr.slice(0, mid), compareFn);
94
+ const right = mergeSort(arr.slice(mid, arr.length), compareFn);
95
+ return merge(left, right, compareFn);
75
96
  }
76
97
  function defaultCompare(a, b) {
77
- return a < b ? -1 : a > b ? 1 : 0;
98
+ return a < b ? -1 : (a > b ? 1 : 0);
78
99
  }
79
100
  function merge(left, right, compareFn) {
80
- const result = [];
81
- while (left.length && right.length) {
82
- if (compareFn(left[0], right[0]) <= 0) {
83
- // if 0 it should preserve same order (stable)
84
- result.push(left.shift());
85
- } else {
86
- result.push(right.shift());
101
+ const result = [];
102
+ while (left.length && right.length) {
103
+ if (compareFn(left[0], right[0]) <= 0) {
104
+ // if 0 it should preserve same order (stable)
105
+ result.push(left.shift());
106
+ }
107
+ else {
108
+ result.push(right.shift());
109
+ }
87
110
  }
88
- }
89
- if (left.length) result.push.apply(result, left);
90
- if (right.length) result.push.apply(result, right);
91
- return result;
111
+ if (left.length)
112
+ result.push.apply(result, left);
113
+ if (right.length)
114
+ result.push.apply(result, right);
115
+ return result;
92
116
  }
93
- module.exports = exports.default;
@@ -1,42 +1,37 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = sortLocales;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
7
3
  /**
8
4
  * Given a list of locales, this utility will sort them by `fallback` order, i.e. the locales without fallbacks first,
9
5
  * then the locales having them as fallbacks, and then recursively.
10
6
  */
11
7
  function sortLocales(locales) {
12
- const localeByFallback = {};
13
- locales.forEach(locale => {
14
- if (locale.fallbackCode === null) {
15
- locale.fallbackCode = undefined;
16
- }
17
- if (!localeByFallback[locale.fallbackCode]) {
18
- localeByFallback[locale.fallbackCode] = [];
19
- }
20
- localeByFallback[locale.fallbackCode].push(locale);
21
- });
22
- return sortByFallbackKey(localeByFallback);
8
+ const localeByFallback = {};
9
+ locales.forEach(locale => {
10
+ if (locale.fallbackCode === null) {
11
+ locale.fallbackCode = undefined;
12
+ }
13
+ if (!localeByFallback[locale.fallbackCode]) {
14
+ localeByFallback[locale.fallbackCode] = [];
15
+ }
16
+ localeByFallback[locale.fallbackCode].push(locale);
17
+ });
18
+ return sortByFallbackKey(localeByFallback);
23
19
  }
20
+ exports.default = sortLocales;
24
21
  function sortByFallbackKey(localeByFallback, key) {
25
- if (!localeByFallback[key]) {
26
- return [];
27
- }
28
- const sortedLocales = localeByFallback[key];
29
- sortedLocales.forEach(locale => {
30
- sortByFallbackKey(localeByFallback, locale.code).forEach(x => sortedLocales.push(x));
31
- });
32
-
33
- // We have to reset the undefined fallback code to null so that the locales are properly created without fallback and
34
- // not the default (en-US)
35
- sortedLocales.forEach(locale => {
36
- if (!locale.fallbackCode) {
37
- locale.fallbackCode = null;
22
+ if (!localeByFallback[key]) {
23
+ return [];
38
24
  }
39
- });
40
- return sortedLocales;
25
+ const sortedLocales = localeByFallback[key];
26
+ sortedLocales.forEach((locale) => {
27
+ sortByFallbackKey(localeByFallback, locale.code).forEach((x) => sortedLocales.push(x));
28
+ });
29
+ // We have to reset the undefined fallback code to null so that the locales are properly created without fallback and
30
+ // not the default (en-US)
31
+ sortedLocales.forEach((locale) => {
32
+ if (!locale.fallbackCode) {
33
+ locale.fallbackCode = null;
34
+ }
35
+ });
36
+ return sortedLocales;
41
37
  }
42
- module.exports = exports.default;
@@ -1,57 +1,54 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.assertPayload = exports.assertDefaultLocale = void 0;
7
- var _schema = require("./schema");
8
- var _getEntityName = _interopRequireDefault(require("contentful-batch-libs/dist/get-entity-name"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.assertDefaultLocale = exports.assertPayload = void 0;
7
+ const schema_1 = require("./schema");
8
+ const get_entity_name_1 = __importDefault(require("contentful-batch-libs/dist/get-entity-name"));
10
9
  const attachEntityName = (details, payload) => {
11
- details.map(detail => {
12
- if (detail.path.length >= 2) {
13
- detail.entity = (0, _getEntityName.default)(payload[detail.path[0]][detail.path[1]]);
14
- }
15
- return detail;
16
- });
10
+ details.map((detail) => {
11
+ if (detail.path.length >= 2) {
12
+ detail.entity = (0, get_entity_name_1.default)(payload[detail.path[0]][detail.path[1]]);
13
+ }
14
+ return detail;
15
+ });
17
16
  };
18
- const countInvalidEntities = validationData => {
19
- const entityCount = validationData.reduce((entities, currentDetail) => {
20
- if (!entities[currentDetail.path[0]]) {
21
- entities[currentDetail.path[0]] = 1;
22
- } else {
23
- entities[currentDetail.path[0]]++;
24
- }
25
- return entities;
26
- }, {});
27
- return Object.keys(entityCount).map(key => `${key}:${entityCount[key]}`);
17
+ const countInvalidEntities = (validationData) => {
18
+ const entityCount = validationData.reduce((entities, currentDetail) => {
19
+ if (!entities[currentDetail.path[0]]) {
20
+ entities[currentDetail.path[0]] = 1;
21
+ }
22
+ else {
23
+ entities[currentDetail.path[0]]++;
24
+ }
25
+ return entities;
26
+ }, {});
27
+ return Object.keys(entityCount).map((key) => `${key}:${entityCount[key]}`);
28
28
  };
29
- const assertPayload = payload => {
30
- const result = _schema.payloadSchema.validate(payload, {
31
- allowUnknown: true,
32
- abortEarly: false
33
- });
34
- if (result.error) {
35
- attachEntityName(result.error.details, payload);
36
- const invalidEntityCount = countInvalidEntities(result.error.details).join(', ');
37
- result.error.message = `${invalidEntityCount} - Get further details in the error log file`;
38
- delete result.error._object;
39
- throw result.error;
40
- }
29
+ const assertPayload = (payload) => {
30
+ const result = schema_1.payloadSchema.validate(payload, { allowUnknown: true, abortEarly: false });
31
+ if (result.error) {
32
+ attachEntityName(result.error.details, payload);
33
+ const invalidEntityCount = countInvalidEntities(result.error.details).join(', ');
34
+ result.error.message = `${invalidEntityCount} - Get further details in the error log file`;
35
+ delete result.error._object;
36
+ throw result.error;
37
+ }
41
38
  };
42
39
  exports.assertPayload = assertPayload;
43
40
  const assertDefaultLocale = (source, destination) => {
44
- const sourceDefaultLocale = source.locales.find(locale => locale.default === true);
45
- const destinationDefaultLocale = destination.locales.find(locale => locale.default === true);
46
- if (!sourceDefaultLocale || !destinationDefaultLocale) {
47
- return;
48
- }
49
- if (sourceDefaultLocale.code !== destinationDefaultLocale.code) {
50
- throw new Error(`
41
+ const sourceDefaultLocale = source.locales.find((locale) => locale.default === true);
42
+ const destinationDefaultLocale = destination.locales.find((locale) => locale.default === true);
43
+ if (!sourceDefaultLocale || !destinationDefaultLocale) {
44
+ return;
45
+ }
46
+ if (sourceDefaultLocale.code !== destinationDefaultLocale.code) {
47
+ throw new Error(`
51
48
  Please make sure the destination space have the same default locale as the source\n
52
49
  Default locale for source space : ${sourceDefaultLocale.code}\n
53
50
  Default locale for destination space: ${destinationDefaultLocale.code}\n
54
51
  `);
55
- }
52
+ }
56
53
  };
57
- exports.assertDefaultLocale = assertDefaultLocale;
54
+ exports.assertDefaultLocale = assertDefaultLocale;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentful-import",
3
- "version": "9.0.21",
3
+ "version": "9.1.0",
4
4
  "description": "this tool allows you to import JSON dump exported by contentful-export",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -10,7 +10,7 @@
10
10
  "contentful-import": "./bin/contentful-import"
11
11
  },
12
12
  "scripts": {
13
- "build": "npm run clean && babel lib --out-dir dist",
13
+ "build": "npm run clean && tsc",
14
14
  "build:watch": "babel lib --out-dir dist --watch",
15
15
  "clean": "rimraf dist && rimraf coverage",
16
16
  "lint": "eslint lib bin/contentful-import test",
@@ -50,7 +50,6 @@
50
50
  "url": "https://github.com/contentful/contentful-import/issues"
51
51
  },
52
52
  "dependencies": {
53
- "@babel/eslint-parser": "^7.22.15",
54
53
  "@discoveryjs/json-ext": "^0.5.7",
55
54
  "bluebird": "^3.5.1",
56
55
  "cli-table3": "^0.6.0",
@@ -68,10 +67,14 @@
68
67
  "yargs": "^17.7.2"
69
68
  },
70
69
  "devDependencies": {
71
- "@babel/cli": "^7.22.15",
72
- "@babel/core": "^7.22.20",
70
+ "@babel/cli": "^7.23.0",
71
+ "@babel/core": "^7.23.0",
73
72
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
74
73
  "@babel/preset-env": "^7.22.20",
74
+ "@types/jest": "^29.5.5",
75
+ "@types/node": "^20.6.3",
76
+ "@typescript-eslint/eslint-plugin": "^6.7.2",
77
+ "@typescript-eslint/parser": "^6.7.2",
75
78
  "babel-jest": "^29.7.0",
76
79
  "babel-plugin-add-module-exports": "^1.0.2",
77
80
  "babel-preset-env": "^1.7.0",
@@ -80,10 +83,13 @@
80
83
  "eslint-plugin-jest": "^27.4.0",
81
84
  "eslint-plugin-node": "^11.1.0",
82
85
  "eslint-plugin-promise": "^6.1.1",
86
+ "eslint-plugin-standard": "^5.0.0",
83
87
  "husky": "^8.0.3",
84
88
  "jest": "^29.7.0",
85
89
  "rimraf": "^5.0.0",
86
- "semantic-release": "^19.0.5"
90
+ "semantic-release": "^19.0.5",
91
+ "ts-jest": "^29.1.1",
92
+ "typescript": "^5.2.2"
87
93
  },
88
94
  "files": [
89
95
  "bin",
@@ -113,17 +119,5 @@
113
119
  "@semantic-release/npm",
114
120
  "@semantic-release/github"
115
121
  ]
116
- },
117
- "jest": {
118
- "testEnvironment": "node",
119
- "collectCoverageFrom": [
120
- "lib/**/*.js"
121
- ],
122
- "coveragePathIgnorePatterns": [
123
- "usageParams.js"
124
- ],
125
- "transformIgnorePatterns": [
126
- "node_modules/(?!(contentful-batch-libs)/)"
127
- ]
128
122
  }
129
123
  }