Skip to content

Commit a5c8ca4

Browse files
committed
fix: fixed npm audit issues and other compilation issues
1 parent b0a155a commit a5c8ca4

File tree

10 files changed

+3356
-56
lines changed

10 files changed

+3356
-56
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Module dependencies
22
node_modules
3-
package-lock.json
43

54
# Test coverages
65
coverage

.talismanrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fileignoreconfig:
2+
- filename: package-lock.json
3+
checksum: 218e63a11ff5af63d734e6facf8d71a2965870700eadf98c423ac74839036a46
4+
version: ""

dist/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* MIT Licensed
66
*/
77
Object.defineProperty(exports, "__esModule", { value: true });
8+
exports.config = void 0;
89
exports.config = {
910
contentStore: {
1011
collection: {

dist/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* MIT Licensed
66
*/
77
Object.defineProperty(exports, "__esModule", { value: true });
8+
exports.Contentstack = void 0;
89
const stack_1 = require("./stack");
910
/**
1011
* @class Stack

dist/stack.js

+41-33
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
* MIT Licensed
66
*/
77
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
89
return new (P || (P = Promise))(function (resolve, reject) {
910
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1011
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
12+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1213
step((generator = generator.apply(thisArg, _arguments || [])).next());
1314
});
1415
};
1516
var __importDefault = (this && this.__importDefault) || function (mod) {
1617
return (mod && mod.__esModule) ? mod : { "default": mod };
1718
};
1819
Object.defineProperty(exports, "__esModule", { value: true });
20+
exports.Stack = void 0;
1921
const lodash_1 = require("lodash");
2022
const mongodb_1 = require("mongodb");
2123
const sift_1 = __importDefault(require("sift"));
@@ -30,9 +32,9 @@ const util_1 = require("./util");
3032
*/
3133
class Stack {
3234
constructor(stackConfig, existingDB) {
33-
this.config = lodash_1.merge(config_1.config, stackConfig);
35+
this.config = (0, lodash_1.merge)(config_1.config, stackConfig);
3436
// validates config.locales property
35-
util_1.validateConfig(this.config);
37+
(0, util_1.validateConfig)(this.config);
3638
this.contentStore = this.config.contentStore;
3739
this.collectionNames = this.contentStore.collection;
3840
this.types = this.contentStore.internal.types;
@@ -137,8 +139,8 @@ class Stack {
137139
*/
138140
connect(overrides = {}) {
139141
return __awaiter(this, void 0, void 0, function* () {
140-
const dbConfig = lodash_1.merge({}, this.config, overrides).contentStore;
141-
const url = util_1.validateURI(dbConfig.url);
142+
const dbConfig = (0, lodash_1.merge)({}, this.config, overrides).contentStore;
143+
const url = (0, util_1.validateURI)(dbConfig.url);
142144
const options = dbConfig.options;
143145
const dbName = dbConfig.dbName;
144146
const client = new mongodb_1.MongoClient(url, options);
@@ -218,7 +220,7 @@ class Stack {
218220
throw new Error('Kindly provide valid parameters for .and()!');
219221
}
220222
else if (this.q.query && typeof this.q.query === 'object') {
221-
this.q.query = lodash_1.merge(this.q.query, {
223+
this.q.query = (0, lodash_1.merge)(this.q.query, {
222224
$and: queries,
223225
});
224226
}
@@ -262,7 +264,7 @@ class Stack {
262264
throw new Error('Kindly provide valid parameters for .or()!');
263265
}
264266
else if (this.q.query && typeof this.q.query === 'object') {
265-
this.q.query = lodash_1.merge(this.q.query, {
267+
this.q.query = (0, lodash_1.merge)(this.q.query, {
266268
$or: queries,
267269
});
268270
}
@@ -1011,7 +1013,7 @@ class Stack {
10111013
*/
10121014
query(queryObject = {}) {
10131015
if (this.q.query && typeof this.q.query === 'object') {
1014-
this.q.query = lodash_1.merge(this.q.query, queryObject);
1016+
this.q.query = (0, lodash_1.merge)(this.q.query, queryObject);
10151017
}
10161018
else {
10171019
this.q.query = queryObject;
@@ -1086,7 +1088,7 @@ class Stack {
10861088
this.internal.except[field] = 0;
10871089
}
10881090
});
1089-
this.internal.except = lodash_1.merge(this.contentStore.projections, this.internal.except);
1091+
this.internal.except = (0, lodash_1.merge)(this.contentStore.projections, this.internal.except);
10901092
return this;
10911093
}
10921094
/**
@@ -1118,7 +1120,7 @@ class Stack {
11181120
throw new Error('Kindly provide a valid field and pattern value for \'.regex()\'');
11191121
}
11201122
else if (this.q.query && typeof this.q.query === 'object') {
1121-
this.q.query = lodash_1.merge(this.q.query, {
1123+
this.q.query = (0, lodash_1.merge)(this.q.query, {
11221124
[field]: {
11231125
$options: options,
11241126
$regex: pattern,
@@ -1161,7 +1163,7 @@ class Stack {
11611163
throw new Error('Kindly provide valid \'field\' values for \'tags()\'');
11621164
}
11631165
// filter non-string keys
1164-
lodash_1.remove(values, (value) => {
1166+
(0, lodash_1.remove)(values, (value) => {
11651167
return typeof value !== 'string';
11661168
});
11671169
this.q.query = this.q.query || {};
@@ -1217,7 +1219,7 @@ class Stack {
12171219
if (typeof expr === 'function') {
12181220
expr = expr.toString();
12191221
}
1220-
this.q.query = lodash_1.merge(this.q.query, {
1222+
this.q.query = (0, lodash_1.merge)(this.q.query, {
12211223
$where: expr,
12221224
});
12231225
}
@@ -1489,7 +1491,7 @@ class Stack {
14891491
yield this.includeAssetsOnly(result, this.q.content_type_uid, this.q.locale);
14901492
}
14911493
if (this.internal.queryReferences) {
1492-
result = result.filter(sift_1.default(this.internal.queryReferences));
1494+
result = result.filter((0, sift_1.default)(this.internal.queryReferences));
14931495
if (this.internal.skip) {
14941496
result = result.splice(this.internal.skip, this.internal.limit);
14951497
}
@@ -1583,7 +1585,7 @@ class Stack {
15831585
preProcess(query) {
15841586
let queryFilters;
15851587
if (this.q.query && typeof this.q.query === 'object') {
1586-
this.q.query = lodash_1.merge(this.q.query, query);
1588+
this.q.query = (0, lodash_1.merge)(this.q.query, query);
15871589
}
15881590
else {
15891591
this.q.query = {};
@@ -1594,7 +1596,7 @@ class Stack {
15941596
this.internal.projections = this.internal.only;
15951597
}
15961598
else {
1597-
this.internal.projections = lodash_1.merge(this.contentStore.projections, this.internal.except);
1599+
this.internal.projections = (0, lodash_1.merge)(this.contentStore.projections, this.internal.except);
15981600
}
15991601
// set default limit, if .limit() hasn't been called
16001602
if (!(this.internal.limit)) {
@@ -1631,7 +1633,7 @@ class Stack {
16311633
else {
16321634
queryFilters = filters;
16331635
}
1634-
this.collection = this.db.collection(util_1.getCollectionName({
1636+
this.collection = this.db.collection((0, util_1.getCollectionName)({
16351637
content_type_uid: this.q.content_type_uid,
16361638
locale: this.q.locale,
16371639
}, this.collectionNames));
@@ -1696,7 +1698,7 @@ class Stack {
16961698
break;
16971699
}
16981700
if (this.internal.includeCount) {
1699-
output.count = yield this.db.collection(util_1.getCollectionName({
1701+
output.count = yield this.db.collection((0, util_1.getCollectionName)({
17001702
content_type_uid: this.q.content_type_uid,
17011703
locale: this.q.locale,
17021704
}, this.collectionNames))
@@ -1705,17 +1707,19 @@ class Stack {
17051707
});
17061708
}
17071709
if (this.internal.includeSchema) {
1708-
output.content_type = yield this.db.collection(util_1.getCollectionName({
1710+
output.content_type = yield this.db.collection((0, util_1.getCollectionName)({
17091711
content_type_uid: this.types.content_types,
17101712
locale: this.q.locale,
17111713
}, this.collectionNames))
17121714
.findOne({
17131715
uid: this.q.content_type_uid,
17141716
}, {
1715-
_assets: 0,
1716-
_content_type_uid: 0,
1717-
_id: 0,
1718-
_references: 0,
1717+
projection: {
1718+
_assets: 0,
1719+
_content_type_uid: 0,
1720+
_id: 0,
1721+
_references: 0,
1722+
}
17191723
});
17201724
}
17211725
this.cleanup();
@@ -1725,16 +1729,18 @@ class Stack {
17251729
includeAssetsOnly(entries, contentTypeUid, locale) {
17261730
return __awaiter(this, void 0, void 0, function* () {
17271731
const schema = yield this.db
1728-
.collection(util_1.getCollectionName({
1732+
.collection((0, util_1.getCollectionName)({
17291733
content_type_uid: this.types.content_types,
17301734
locale,
17311735
}, this.collectionNames))
17321736
.findOne({
17331737
_content_type_uid: this.types.content_types,
17341738
uid: contentTypeUid,
17351739
}, {
1736-
_assets: 1,
1737-
_id: 0,
1740+
projection: {
1741+
_assets: 1,
1742+
_id: 0,
1743+
}
17381744
});
17391745
if (schema === null || schema[this.types.assets] !== 'object') {
17401746
return;
@@ -1750,7 +1756,7 @@ class Stack {
17501756
if (shelf.length === 0) {
17511757
return;
17521758
}
1753-
const assets = yield this.db.collection(util_1.getCollectionName({
1759+
const assets = yield this.db.collection((0, util_1.getCollectionName)({
17541760
content_type_uid: this.types.assets,
17551761
locale,
17561762
}, this.collectionNames))
@@ -1788,7 +1794,8 @@ class Stack {
17881794
};
17891795
const { paths, // ref. fields in the current content types
17901796
pendingPath, // left over of *paths*
1791-
schemaList, } = yield this.getReferencePath(ctQuery, locale, include);
1797+
schemaList, // list of content type uids, the current content types refer to
1798+
} = yield this.getReferencePath(ctQuery, locale, include);
17921799
const queries = {
17931800
$or: [],
17941801
}; // reference field paths
@@ -1892,7 +1899,7 @@ class Stack {
18921899
bindLeftoverAssets(queries, locale, pointerList) {
18931900
return __awaiter(this, void 0, void 0, function* () {
18941901
// const contents = await readFile(getAssetsPath(locale) + '.json')
1895-
const filteredAssets = yield this.db.collection(util_1.getCollectionName({
1902+
const filteredAssets = yield this.db.collection((0, util_1.getCollectionName)({
18961903
content_type_uid: this.types.assets,
18971904
locale,
18981905
}, this.collectionNames))
@@ -1955,7 +1962,7 @@ class Stack {
19551962
}
19561963
getReferencePath(query, locale, currentInclude) {
19571964
return __awaiter(this, void 0, void 0, function* () {
1958-
const schemas = yield this.db.collection(util_1.getCollectionName({
1965+
const schemas = yield this.db.collection((0, util_1.getCollectionName)({
19591966
content_type_uid: this.types.content_types,
19601967
locale,
19611968
}, this.collectionNames))
@@ -1982,7 +1989,7 @@ class Stack {
19821989
let entryReferences = {};
19831990
schemas.forEach((schema) => {
19841991
// Entry references
1985-
entryReferences = lodash_1.merge(entryReferences, schema[this.types.references]);
1992+
entryReferences = (0, lodash_1.merge)(entryReferences, schema[this.types.references]);
19861993
// tslint:disable-next-line: forin
19871994
for (const path in schema[this.types.assets]) {
19881995
paths.push(path);
@@ -2035,7 +2042,7 @@ class Stack {
20352042
}
20362043
fetchEntries(query, locale, paths, include, includeAll = false) {
20372044
return __awaiter(this, void 0, void 0, function* () {
2038-
const result = yield this.db.collection(util_1.getCollectionName({
2045+
const result = yield this.db.collection((0, util_1.getCollectionName)({
20392046
content_type_uid: 'entries',
20402047
locale,
20412048
}, this.collectionNames))
@@ -2085,7 +2092,8 @@ class Stack {
20852092
}],
20862093
};
20872094
const { paths, // ref. fields in the current content types
2088-
ctQueries, } = yield this.getAllReferencePaths(ctQuery, locale);
2095+
ctQueries, // list of content type uids, the current content types refer to
2096+
} = yield this.getAllReferencePaths(ctQuery, locale);
20892097
const queries = {
20902098
$or: [],
20912099
}; // reference field paths
@@ -2151,7 +2159,7 @@ class Stack {
21512159
getAllReferencePaths(contentTypeQueries, locale) {
21522160
return __awaiter(this, void 0, void 0, function* () {
21532161
const contents = yield this.db
2154-
.collection(util_1.getCollectionName({
2162+
.collection((0, util_1.getCollectionName)({
21552163
content_type_uid: this.types.content_types,
21562164
locale,
21572165
}, this.collectionNames))

dist/util.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* MIT Licensed
66
*/
77
Object.defineProperty(exports, "__esModule", { value: true });
8+
exports.getCollectionName = exports.validateConfig = exports.checkCyclic = exports.validateURI = void 0;
89
const lodash_1 = require("lodash");
910
/**
1011
* @private
@@ -14,12 +15,13 @@ const lodash_1 = require("lodash");
1415
* @param {string} uri - Mongodb connection 'uri' string
1516
* @returns {string} - Returns the `uri` after validating it, else throws an error
1617
*/
17-
exports.validateURI = (uri) => {
18+
const validateURI = (uri) => {
1819
if (typeof uri !== 'string' || uri.length === 0) {
1920
throw new Error(`Mongodb connection url: ${uri} must be of type string`);
2021
}
2122
return uri;
2223
};
24+
exports.validateURI = validateURI;
2325
/**
2426
* @private
2527
* @method checkCyclic
@@ -28,7 +30,7 @@ exports.validateURI = (uri) => {
2830
* @param {object} mapping Map of the uids tracked thusfar
2931
* @returns {boolean} Returns `true` if the `uid` is part of the map (i.e. cyclic)
3032
*/
31-
exports.checkCyclic = (uid, mapping) => {
33+
const checkCyclic = (uid, mapping) => {
3234
let flag = false;
3335
let list = [uid];
3436
// tslint:disable-next-line: prefer-for-of
@@ -38,10 +40,11 @@ exports.checkCyclic = (uid, mapping) => {
3840
flag = true;
3941
break;
4042
}
41-
list = lodash_1.uniq(list.concat(parent));
43+
list = (0, lodash_1.uniq)(list.concat(parent));
4244
}
4345
return flag;
4446
};
47+
exports.checkCyclic = checkCyclic;
4548
const getParents = (child, mapping) => {
4649
const parents = [];
4750
for (const key in mapping) {
@@ -65,11 +68,12 @@ const validateContentStore = (contentStore) => {
6568
}
6669
return;
6770
};
68-
exports.validateConfig = (config) => {
71+
const validateConfig = (config) => {
6972
validateContentStore(config.contentStore);
7073
return;
7174
};
72-
exports.getCollectionName = ({ locale, content_type_uid }, collection) => {
75+
exports.validateConfig = validateConfig;
76+
const getCollectionName = ({ locale, content_type_uid }, collection) => {
7377
switch (content_type_uid) {
7478
case '_assets':
7579
return `${locale}.${collection.asset}`;
@@ -79,3 +83,4 @@ exports.getCollectionName = ({ locale, content_type_uid }, collection) => {
7983
return `${locale}.${collection.entry}`;
8084
}
8185
};
86+
exports.getCollectionName = getCollectionName;

0 commit comments

Comments
 (0)