@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.
Files changed (70) hide show
  1. package/.github/workflows/codeql-analysis.yml +68 -0
  2. package/.github/workflows/jira.yml +33 -0
  3. package/.github/workflows/release.yml +77 -0
  4. package/.github/workflows/sast-scan.yml +11 -0
  5. package/.github/workflows/sca-scan.yml +15 -0
  6. package/.talismanrc +4 -0
  7. package/CODEOWNERS +1 -0
  8. package/LICENCE +21 -0
  9. package/README.md +191 -0
  10. package/SECURITY.md +27 -0
  11. package/contentstack-datasync-mongodb-sdk-1.0.9-beta.1.tgz +0 -0
  12. package/dist/config.js +47 -0
  13. package/dist/index.js +42 -0
  14. package/dist/stack.js +2272 -0
  15. package/dist/util.js +86 -0
  16. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  17. package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
  18. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  19. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  20. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  21. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  22. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  23. package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
  24. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  25. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  26. package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
  27. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  28. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  29. package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  30. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  31. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  32. package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
  33. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  34. package/docs/global.html +7520 -0
  35. package/docs/global.html#Stack +1070 -0
  36. package/docs/index.html +291 -0
  37. package/docs/index.js.html +92 -0
  38. package/docs/scripts/linenumber.js +25 -0
  39. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  40. package/docs/scripts/prettify/lang-css.js +2 -0
  41. package/docs/stack.js.html +2244 -0
  42. package/docs/styles/jsdoc-default.css +358 -0
  43. package/docs/styles/prettify-jsdoc.css +111 -0
  44. package/docs/styles/prettify-tomorrow.css +132 -0
  45. package/example/index.js +56 -0
  46. package/package.json +59 -0
  47. package/test/comparison-operators.ts +257 -0
  48. package/test/conditional-operators.ts +106 -0
  49. package/test/config.ts +12 -0
  50. package/test/core.ts +333 -0
  51. package/test/count.ts +98 -0
  52. package/test/data/assets.ts +35 -0
  53. package/test/data/author.ts +168 -0
  54. package/test/data/blog.ts +138 -0
  55. package/test/data/category.ts +20 -0
  56. package/test/data/content_types.ts +164 -0
  57. package/test/data/products.ts +64 -0
  58. package/test/expressions.ts +108 -0
  59. package/test/include-exclude.ts +176 -0
  60. package/test/logical-operators.ts +140 -0
  61. package/test/projections.ts +109 -0
  62. package/test/queries.ts +143 -0
  63. package/test/references.ts +162 -0
  64. package/test/skip-limit.ts +150 -0
  65. package/test/sorting.ts +177 -0
  66. package/tslint.json +45 -0
  67. package/typings/config.d.ts +42 -0
  68. package/typings/index.d.ts +36 -0
  69. package/typings/stack.d.ts +1097 -0
  70. 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;