@contentstack/datasync-mongodb-sdk 1.0.9-beta.1
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/.github/workflows/codeql-analysis.yml +68 -0
- package/.github/workflows/jira.yml +33 -0
- package/.github/workflows/release.yml +77 -0
- package/.github/workflows/sast-scan.yml +11 -0
- package/.github/workflows/sca-scan.yml +15 -0
- package/.talismanrc +4 -0
- package/CODEOWNERS +1 -0
- package/LICENCE +21 -0
- package/README.md +191 -0
- package/SECURITY.md +27 -0
- package/contentstack-datasync-mongodb-sdk-1.0.9-beta.1.tgz +0 -0
- package/dist/config.js +47 -0
- package/dist/index.js +42 -0
- package/dist/stack.js +2272 -0
- package/dist/util.js +86 -0
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/global.html +7520 -0
- package/docs/global.html#Stack +1070 -0
- package/docs/index.html +291 -0
- package/docs/index.js.html +92 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/stack.js.html +2244 -0
- package/docs/styles/jsdoc-default.css +358 -0
- package/docs/styles/prettify-jsdoc.css +111 -0
- package/docs/styles/prettify-tomorrow.css +132 -0
- package/example/index.js +56 -0
- package/package.json +59 -0
- package/test/comparison-operators.ts +257 -0
- package/test/conditional-operators.ts +106 -0
- package/test/config.ts +12 -0
- package/test/core.ts +333 -0
- package/test/count.ts +98 -0
- package/test/data/assets.ts +35 -0
- package/test/data/author.ts +168 -0
- package/test/data/blog.ts +138 -0
- package/test/data/category.ts +20 -0
- package/test/data/content_types.ts +164 -0
- package/test/data/products.ts +64 -0
- package/test/expressions.ts +108 -0
- package/test/include-exclude.ts +176 -0
- package/test/logical-operators.ts +140 -0
- package/test/projections.ts +109 -0
- package/test/queries.ts +143 -0
- package/test/references.ts +162 -0
- package/test/skip-limit.ts +150 -0
- package/test/sorting.ts +177 -0
- package/tslint.json +45 -0
- package/typings/config.d.ts +42 -0
- package/typings/index.d.ts +36 -0
- package/typings/stack.d.ts +1097 -0
- package/typings/util.d.ts +28 -0
package/dist/util.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Contentstack DataSync Mongodb SDK
|
|
4
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getCollectionName = exports.validateConfig = exports.checkCyclic = exports.validateURI = void 0;
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
/**
|
|
11
|
+
* @private
|
|
12
|
+
* @method validateURI
|
|
13
|
+
* @description
|
|
14
|
+
* Validates the mongodb 'uri' passed
|
|
15
|
+
* @param {string} uri - Mongodb connection 'uri' string
|
|
16
|
+
* @returns {string} - Returns the `uri` after validating it, else throws an error
|
|
17
|
+
*/
|
|
18
|
+
const validateURI = (uri) => {
|
|
19
|
+
if (typeof uri !== 'string' || uri.length === 0) {
|
|
20
|
+
throw new Error(`Mongodb connection url: ${uri} must be of type string`);
|
|
21
|
+
}
|
|
22
|
+
return uri;
|
|
23
|
+
};
|
|
24
|
+
exports.validateURI = validateURI;
|
|
25
|
+
/**
|
|
26
|
+
* @private
|
|
27
|
+
* @method checkCyclic
|
|
28
|
+
* @summary Checks for `cyclic` references
|
|
29
|
+
* @param {string} uid Uid to check if it exists on `map`
|
|
30
|
+
* @param {object} mapping Map of the uids tracked thusfar
|
|
31
|
+
* @returns {boolean} Returns `true` if the `uid` is part of the map (i.e. cyclic)
|
|
32
|
+
*/
|
|
33
|
+
const checkCyclic = (uid, mapping) => {
|
|
34
|
+
let flag = false;
|
|
35
|
+
let list = [uid];
|
|
36
|
+
// tslint:disable-next-line: prefer-for-of
|
|
37
|
+
for (let i = 0; i < list.length; i++) {
|
|
38
|
+
const parent = getParents(list[i], mapping);
|
|
39
|
+
if (parent.indexOf(uid) !== -1) {
|
|
40
|
+
flag = true;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
list = (0, lodash_1.uniq)(list.concat(parent));
|
|
44
|
+
}
|
|
45
|
+
return flag;
|
|
46
|
+
};
|
|
47
|
+
exports.checkCyclic = checkCyclic;
|
|
48
|
+
const getParents = (child, mapping) => {
|
|
49
|
+
const parents = [];
|
|
50
|
+
for (const key in mapping) {
|
|
51
|
+
if (mapping[key].indexOf(child) !== -1) {
|
|
52
|
+
parents.push(key);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return parents;
|
|
56
|
+
};
|
|
57
|
+
const validateContentStore = (contentStore) => {
|
|
58
|
+
if (typeof contentStore.dbName !== 'string' || contentStore.dbName.length === 0) {
|
|
59
|
+
throw new Error('Contentstore dbName should be of type string and not empty!');
|
|
60
|
+
}
|
|
61
|
+
if (typeof contentStore.collectionName === 'string') {
|
|
62
|
+
contentStore.collection = {
|
|
63
|
+
asset: contentStore.collectionName,
|
|
64
|
+
entry: contentStore.collectionName,
|
|
65
|
+
schema: contentStore.collectionName,
|
|
66
|
+
};
|
|
67
|
+
delete contentStore.collectionName;
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
};
|
|
71
|
+
const validateConfig = (config) => {
|
|
72
|
+
validateContentStore(config.contentStore);
|
|
73
|
+
return;
|
|
74
|
+
};
|
|
75
|
+
exports.validateConfig = validateConfig;
|
|
76
|
+
const getCollectionName = ({ locale, content_type_uid }, collection) => {
|
|
77
|
+
switch (content_type_uid) {
|
|
78
|
+
case '_assets':
|
|
79
|
+
return `${locale}.${collection.asset}`;
|
|
80
|
+
case '_content_types':
|
|
81
|
+
return `${locale}.${collection.schema}`;
|
|
82
|
+
default:
|
|
83
|
+
return `${locale}.${collection.entry}`;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
exports.getCollectionName = getCollectionName;
|
|
Binary file
|