@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
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Test contentstack-mongodb-sdk basic methods
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { cloneDeep } from 'lodash'
|
|
6
|
+
import { Contentstack } from '../src'
|
|
7
|
+
import { config } from './config'
|
|
8
|
+
import { assets } from './data/assets'
|
|
9
|
+
import { entries as authors } from './data/author'
|
|
10
|
+
import { entries as blogs } from './data/blog'
|
|
11
|
+
import { entries as categories } from './data/category'
|
|
12
|
+
import { content_types } from './data/content_types'
|
|
13
|
+
|
|
14
|
+
const scriptConfig = cloneDeep(config)
|
|
15
|
+
const collNameConfig: any = scriptConfig.contentStore.collection
|
|
16
|
+
collNameConfig.asset = 'contents.references'
|
|
17
|
+
collNameConfig.entry = 'contents.references'
|
|
18
|
+
collNameConfig.schema = 'content_types.references'
|
|
19
|
+
|
|
20
|
+
const Stack = Contentstack.Stack(scriptConfig)
|
|
21
|
+
const collection = cloneDeep(collNameConfig)
|
|
22
|
+
|
|
23
|
+
collection.asset = `en-us.${collNameConfig.asset}`
|
|
24
|
+
collection.entry = `en-us.${collNameConfig.entry}`
|
|
25
|
+
collection.schema = `en-us.${collNameConfig.schema}`
|
|
26
|
+
|
|
27
|
+
let db
|
|
28
|
+
|
|
29
|
+
const checkEntries = (result: any) => {
|
|
30
|
+
expect(result).toHaveProperty('entries')
|
|
31
|
+
expect(result).toHaveProperty('locale')
|
|
32
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
33
|
+
expect(result.locale).toEqual('en-us')
|
|
34
|
+
expect(result.entries instanceof Array).toBeTruthy()
|
|
35
|
+
result.entries.forEach((item) => {
|
|
36
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('# References', () => {
|
|
41
|
+
|
|
42
|
+
beforeAll(() => {
|
|
43
|
+
return Stack.connect().then((dbInstance) => {
|
|
44
|
+
db = dbInstance
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
beforeAll(() => {
|
|
50
|
+
return Stack.connect().then((dbInstance) => {
|
|
51
|
+
db = dbInstance
|
|
52
|
+
|
|
53
|
+
return
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
beforeAll(async () => {
|
|
58
|
+
await db.collection(collection.entry).insertMany(authors)
|
|
59
|
+
await db.collection(collection.entry).insertMany(blogs)
|
|
60
|
+
await db.collection(collection.entry).insertMany(categories)
|
|
61
|
+
await db.collection(collection.asset).insertMany(assets)
|
|
62
|
+
await db.collection(collection.schema).insertMany(content_types)
|
|
63
|
+
|
|
64
|
+
return
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
afterAll(async () => {
|
|
68
|
+
await db.collection(collection.entry).drop()
|
|
69
|
+
// await db.collection(collection.asset).drop()
|
|
70
|
+
await db.collection(collection.schema).drop()
|
|
71
|
+
|
|
72
|
+
return Stack.close()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('basic', () => {
|
|
76
|
+
test('.includeReferences()', () => {
|
|
77
|
+
return Stack.contentType('blog')
|
|
78
|
+
.entries()
|
|
79
|
+
.includeReferences()
|
|
80
|
+
.find()
|
|
81
|
+
.then((result: any) => {
|
|
82
|
+
checkEntries(result)
|
|
83
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
84
|
+
expect(result.entries).toHaveLength(5)
|
|
85
|
+
result.entries.forEach((entry) => {
|
|
86
|
+
expect(entry).toHaveProperty('authors')
|
|
87
|
+
if (entry.authors instanceof Array) {
|
|
88
|
+
entry.authors.forEach((elem) => {
|
|
89
|
+
expect(elem).toHaveProperty('uid')
|
|
90
|
+
expect(elem).toHaveProperty('title')
|
|
91
|
+
expect(elem).not.toHaveProperty('_content_type_uid')
|
|
92
|
+
})
|
|
93
|
+
} else {
|
|
94
|
+
expect(entry.authors).toHaveProperty('uid')
|
|
95
|
+
expect(entry.authors).toHaveProperty('title')
|
|
96
|
+
expect(entry.authors).not.toHaveProperty('_content_type_uid')
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
}).catch((error) => {
|
|
100
|
+
expect(error).toBeNull()
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('.queryOnReferences()', () => {
|
|
105
|
+
return Stack.contentType('blog')
|
|
106
|
+
.entries()
|
|
107
|
+
.queryReferences({'authors.uid': 'a10'})
|
|
108
|
+
.find()
|
|
109
|
+
.then((result: any) => {
|
|
110
|
+
checkEntries(result)
|
|
111
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
112
|
+
expect(result.entries).toHaveLength(1)
|
|
113
|
+
result.entries.forEach((entry) => {
|
|
114
|
+
expect(entry).toHaveProperty('authors')
|
|
115
|
+
expect(entry.authors).toHaveProperty('uid')
|
|
116
|
+
expect(entry.authors.uid).toEqual('a10')
|
|
117
|
+
})
|
|
118
|
+
}).catch((error) => {
|
|
119
|
+
expect(error).toBeNull()
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('.include()', () => {
|
|
124
|
+
return Stack.contentType('blog')
|
|
125
|
+
.entries()
|
|
126
|
+
.include(['authors'])
|
|
127
|
+
.find()
|
|
128
|
+
.then((result: any) => {
|
|
129
|
+
checkEntries(result)
|
|
130
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
131
|
+
expect(result.entries).toHaveLength(5)
|
|
132
|
+
result.entries.forEach((entry) => {
|
|
133
|
+
if (entry.hasOwnProperty('self_reference')) {
|
|
134
|
+
expect(entry).toHaveProperty('self_reference')
|
|
135
|
+
expect(entry.self_reference instanceof Array).toBeTruthy()
|
|
136
|
+
entry.self_reference.forEach((ref) => {
|
|
137
|
+
expect(ref).toHaveProperty('_content_type_uid')
|
|
138
|
+
expect(ref).toHaveProperty('uid')
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (entry.hasOwnProperty('authors')) {
|
|
143
|
+
expect(entry).toHaveProperty('authors')
|
|
144
|
+
if (entry.authors instanceof Array) {
|
|
145
|
+
entry.authors.forEach((ref) => {
|
|
146
|
+
expect(ref).toHaveProperty('title')
|
|
147
|
+
expect(ref).toHaveProperty('uid')
|
|
148
|
+
expect(ref).not.toHaveProperty('_content_type_uid')
|
|
149
|
+
})
|
|
150
|
+
} else {
|
|
151
|
+
expect(entry.authors).toHaveProperty('title')
|
|
152
|
+
expect(entry.authors).toHaveProperty('uid')
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
}).catch((error) => {
|
|
157
|
+
expect(error).toBeNull()
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Test contentstack-mongodb-sdk basic methods
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { cloneDeep } from 'lodash'
|
|
6
|
+
import { Contentstack } from '../src'
|
|
7
|
+
import { config } from './config'
|
|
8
|
+
import { assets } from './data/assets'
|
|
9
|
+
import { entries as authors } from './data/author'
|
|
10
|
+
import { entries as blogs } from './data/blog'
|
|
11
|
+
import { entries as categories } from './data/category'
|
|
12
|
+
import { content_types } from './data/content_types'
|
|
13
|
+
|
|
14
|
+
const scriptConfig = cloneDeep(config)
|
|
15
|
+
const collNameConfig: any = scriptConfig.contentStore.collection
|
|
16
|
+
collNameConfig.asset = 'contents.skip_limit'
|
|
17
|
+
collNameConfig.entry = 'contents.skip_limit'
|
|
18
|
+
collNameConfig.schema = 'content_types.skip_limit'
|
|
19
|
+
|
|
20
|
+
const Stack = Contentstack.Stack(scriptConfig)
|
|
21
|
+
const collection = cloneDeep(collNameConfig)
|
|
22
|
+
|
|
23
|
+
collection.asset = `en-us.${collNameConfig.asset}`
|
|
24
|
+
collection.entry = `en-us.${collNameConfig.entry}`
|
|
25
|
+
collection.schema = `en-us.${collNameConfig.schema}`
|
|
26
|
+
|
|
27
|
+
let db
|
|
28
|
+
let tempVariable
|
|
29
|
+
|
|
30
|
+
const checkEntries = (result: any) => {
|
|
31
|
+
expect(result).toHaveProperty('entries')
|
|
32
|
+
expect(result).toHaveProperty('locale')
|
|
33
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
34
|
+
expect(result.locale).toEqual('en-us')
|
|
35
|
+
expect(result.entries instanceof Array).toBeTruthy()
|
|
36
|
+
result.entries.forEach((item) => {
|
|
37
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('# Conditional Operators', () => {
|
|
42
|
+
|
|
43
|
+
beforeAll(() => {
|
|
44
|
+
return Stack.connect().then((dbInstance) => {
|
|
45
|
+
db = dbInstance
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
beforeAll(() => {
|
|
51
|
+
return Stack.connect().then((dbInstance) => {
|
|
52
|
+
db = dbInstance
|
|
53
|
+
|
|
54
|
+
return
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
beforeAll(async () => {
|
|
59
|
+
await db.collection(collection.entry).insertMany(authors)
|
|
60
|
+
await db.collection(collection.entry).insertMany(blogs)
|
|
61
|
+
await db.collection(collection.entry).insertMany(categories)
|
|
62
|
+
await db.collection(collection.asset).insertMany(assets)
|
|
63
|
+
await db.collection(collection.schema).insertMany(content_types)
|
|
64
|
+
|
|
65
|
+
return
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
afterAll(async () => {
|
|
69
|
+
await db.collection(collection.entry).drop()
|
|
70
|
+
// await db.collection(collection.asset).drop()
|
|
71
|
+
await db.collection(collection.schema).drop()
|
|
72
|
+
|
|
73
|
+
return Stack.close()
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('basic', () => {
|
|
77
|
+
test('.limit(1)', () => {
|
|
78
|
+
const limit = 1
|
|
79
|
+
|
|
80
|
+
return Stack.contentType('blog')
|
|
81
|
+
.entries()
|
|
82
|
+
.limit(limit)
|
|
83
|
+
.find()
|
|
84
|
+
.then((result: any) => {
|
|
85
|
+
checkEntries(result)
|
|
86
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
87
|
+
expect(result.entries).toHaveLength(limit)
|
|
88
|
+
tempVariable = result.entries[0]
|
|
89
|
+
}).catch((error) => {
|
|
90
|
+
expect(error).toBeNull()
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('.skip(1)', () => {
|
|
95
|
+
const skip = 1
|
|
96
|
+
|
|
97
|
+
return Stack.contentType('blog')
|
|
98
|
+
.entries()
|
|
99
|
+
.find()
|
|
100
|
+
.then((r1) => {
|
|
101
|
+
|
|
102
|
+
return Stack.contentType('blog')
|
|
103
|
+
.entries()
|
|
104
|
+
.skip(skip)
|
|
105
|
+
.find()
|
|
106
|
+
.then((result: any) => {
|
|
107
|
+
checkEntries(result)
|
|
108
|
+
expect(result).toHaveProperty('entries')
|
|
109
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
110
|
+
expect(result.entries).toHaveLength((r1 as any).entries.length - skip)
|
|
111
|
+
result.entries.forEach((entry) => {
|
|
112
|
+
expect(entry).not.toMatchObject(tempVariable)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
.catch((error) => {
|
|
117
|
+
expect(error).toBeNull()
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
describe('skip-limit combination', () => {
|
|
123
|
+
test('.skip(1) + .limit(1)', () => {
|
|
124
|
+
const skip = 1
|
|
125
|
+
const limit = 1
|
|
126
|
+
|
|
127
|
+
return Stack.contentType('blog')
|
|
128
|
+
.entries()
|
|
129
|
+
.find()
|
|
130
|
+
.then((r1) => {
|
|
131
|
+
|
|
132
|
+
return Stack.contentType('blog')
|
|
133
|
+
.entries()
|
|
134
|
+
.skip(skip)
|
|
135
|
+
.limit(limit)
|
|
136
|
+
.find()
|
|
137
|
+
.then((result: any) => {
|
|
138
|
+
checkEntries(result)
|
|
139
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
140
|
+
expect(result.entries).toHaveLength(limit)
|
|
141
|
+
expect(result.entries[0]).not.toMatchObject((r1 as any).entries[0])
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
.catch((error) => {
|
|
145
|
+
expect(error).toBeNull()
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
|
package/test/sorting.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Test contentstack-mongodb-sdk basic methods
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { cloneDeep } from 'lodash'
|
|
6
|
+
import { Contentstack } from '../src'
|
|
7
|
+
import { config } from './config'
|
|
8
|
+
import { assets } from './data/assets'
|
|
9
|
+
import { entries as authors } from './data/author'
|
|
10
|
+
import { entries as blogs } from './data/blog'
|
|
11
|
+
import { entries as categories } from './data/category'
|
|
12
|
+
import { content_types } from './data/content_types'
|
|
13
|
+
|
|
14
|
+
const scriptConfig = cloneDeep(config)
|
|
15
|
+
const collNameConfig: any = scriptConfig.contentStore.collection
|
|
16
|
+
collNameConfig.asset = 'contents.sorting'
|
|
17
|
+
collNameConfig.entry = 'contents.sorting'
|
|
18
|
+
collNameConfig.schema = 'content_types.sorting'
|
|
19
|
+
|
|
20
|
+
const Stack = Contentstack.Stack(scriptConfig)
|
|
21
|
+
const collection = cloneDeep(collNameConfig)
|
|
22
|
+
|
|
23
|
+
collection.asset = `en-us.${collNameConfig.asset}`
|
|
24
|
+
collection.entry = `en-us.${collNameConfig.entry}`
|
|
25
|
+
collection.schema = `en-us.${collNameConfig.schema}`
|
|
26
|
+
|
|
27
|
+
let db
|
|
28
|
+
|
|
29
|
+
const checkEntries = (result: any) => {
|
|
30
|
+
expect(result).toHaveProperty('entries')
|
|
31
|
+
expect(result).toHaveProperty('locale')
|
|
32
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
33
|
+
expect(result.locale).toEqual('en-us')
|
|
34
|
+
expect(result.entries instanceof Array).toBeTruthy()
|
|
35
|
+
result.entries.forEach((item) => {
|
|
36
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('# Sorting', () => {
|
|
41
|
+
|
|
42
|
+
beforeAll(() => {
|
|
43
|
+
return Stack.connect().then((dbInstance) => {
|
|
44
|
+
db = dbInstance
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
beforeAll(() => {
|
|
50
|
+
return Stack.connect().then((dbInstance) => {
|
|
51
|
+
db = dbInstance
|
|
52
|
+
|
|
53
|
+
return
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
beforeAll(async () => {
|
|
58
|
+
await db.collection(collection.entry).insertMany(authors)
|
|
59
|
+
await db.collection(collection.entry).insertMany(blogs)
|
|
60
|
+
await db.collection(collection.entry).insertMany(categories)
|
|
61
|
+
await db.collection(collection.asset).insertMany(assets)
|
|
62
|
+
await db.collection(collection.schema).insertMany(content_types)
|
|
63
|
+
|
|
64
|
+
return
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
afterAll(async () => {
|
|
68
|
+
await db.collection(collection.entry).drop()
|
|
69
|
+
// await db.collection(collection.asset).drop()
|
|
70
|
+
await db.collection(collection.schema).drop()
|
|
71
|
+
|
|
72
|
+
return Stack.close()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
expect.extend({
|
|
76
|
+
compareValue(value, compareValue, operator, strict = false) {
|
|
77
|
+
// tslint:disable-next-line: one-variable-per-declaration
|
|
78
|
+
let pass, comparison
|
|
79
|
+
// if operator is true, value >= compareValue, else the opposite
|
|
80
|
+
if (operator) {
|
|
81
|
+
if (strict) {
|
|
82
|
+
comparison = ' > '
|
|
83
|
+
pass = value > compareValue
|
|
84
|
+
} else {
|
|
85
|
+
comparison = ' >= '
|
|
86
|
+
pass = value >= compareValue
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
if (strict) {
|
|
90
|
+
comparison = ' < '
|
|
91
|
+
pass = value < compareValue
|
|
92
|
+
} else {
|
|
93
|
+
comparison = ' <= '
|
|
94
|
+
pass = value <= compareValue
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (pass) {
|
|
99
|
+
return {
|
|
100
|
+
message: () =>
|
|
101
|
+
`expected ${value} not to be ${comparison} than ${compareValue}`,
|
|
102
|
+
pass: true,
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
return {
|
|
106
|
+
message: () =>
|
|
107
|
+
`expected ${value} to be ${comparison} than ${compareValue}`,
|
|
108
|
+
pass: false,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
describe('on field', () => {
|
|
115
|
+
test('ascending', () => {
|
|
116
|
+
return Stack.contentType('blog')
|
|
117
|
+
.entries()
|
|
118
|
+
.ascending('no')
|
|
119
|
+
.find()
|
|
120
|
+
.then((result: any) => {
|
|
121
|
+
checkEntries(result)
|
|
122
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
123
|
+
expect(result.entries).toHaveLength(5)
|
|
124
|
+
result.entries.forEach((entry, index) => {
|
|
125
|
+
if (index === (result.entries.length - 1)) {
|
|
126
|
+
index -= 1
|
|
127
|
+
}
|
|
128
|
+
(expect(entry.no) as any).compareValue(result.entries[index + 1].no, false)
|
|
129
|
+
})
|
|
130
|
+
}).catch((error) => {
|
|
131
|
+
expect(error).toBeNull()
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('descending', () => {
|
|
136
|
+
return Stack.contentType('blog')
|
|
137
|
+
.entries()
|
|
138
|
+
.descending('no')
|
|
139
|
+
.find()
|
|
140
|
+
.then((result: any) => {
|
|
141
|
+
checkEntries(result)
|
|
142
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
143
|
+
expect(result.entries).toHaveLength(5)
|
|
144
|
+
result.entries.forEach((entry, index) => {
|
|
145
|
+
if (index === (result.entries.length - 1)) {
|
|
146
|
+
index -= 1
|
|
147
|
+
}
|
|
148
|
+
(expect(entry.no) as any).compareValue(result.entries[index + 1].no, true)
|
|
149
|
+
})
|
|
150
|
+
}).catch((error) => {
|
|
151
|
+
expect(error).toBeNull()
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
describe('without fields', () => {
|
|
157
|
+
test('expect natural .descending()', () => {
|
|
158
|
+
return Stack.contentType('blog')
|
|
159
|
+
.entries()
|
|
160
|
+
.find()
|
|
161
|
+
.then((result: any) => {
|
|
162
|
+
checkEntries(result)
|
|
163
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
164
|
+
expect(result.entries).toHaveLength(5)
|
|
165
|
+
result.entries.forEach((entry, index) => {
|
|
166
|
+
if (index === (result.entries.length - 1)) {
|
|
167
|
+
index -= 1
|
|
168
|
+
}
|
|
169
|
+
(expect(entry.updated_at) as any).compareValue(result.entries[index + 1].updated_at, true)
|
|
170
|
+
})
|
|
171
|
+
}).catch((error) => {
|
|
172
|
+
expect(error).toBeNull()
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
|
package/tslint.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "tslint:recommended",
|
|
3
|
+
"rules": {
|
|
4
|
+
"max-line-length": {
|
|
5
|
+
"options": [120]
|
|
6
|
+
},
|
|
7
|
+
"new-parens": true,
|
|
8
|
+
"no-arg": true,
|
|
9
|
+
"no-conditional-assignment": true,
|
|
10
|
+
"no-consecutive-blank-lines": false,
|
|
11
|
+
"no-console": {
|
|
12
|
+
"severity": "warning",
|
|
13
|
+
"options": [
|
|
14
|
+
"debug",
|
|
15
|
+
"info",
|
|
16
|
+
"log",
|
|
17
|
+
"time",
|
|
18
|
+
"timeEnd",
|
|
19
|
+
"trace"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"no-empty-interface": true,
|
|
23
|
+
"only-arrow-functions": true,
|
|
24
|
+
"no-string-throw": true,
|
|
25
|
+
"triple-equals": true,
|
|
26
|
+
"eofline": true,
|
|
27
|
+
"indent": [true, "spaces", 2],
|
|
28
|
+
"max-file-line-count": [true, 2000],
|
|
29
|
+
"no-default-export": true,
|
|
30
|
+
"no-duplicate-imports": true,
|
|
31
|
+
"prefer-readonly": true,
|
|
32
|
+
"align": [true, "parameters", "statements"],
|
|
33
|
+
"class-name": true,
|
|
34
|
+
"import-spacing": true,
|
|
35
|
+
"interface-name": [true, "always-prefix"],
|
|
36
|
+
"newline-before-return": true,
|
|
37
|
+
"no-irregular-whitespace": true,
|
|
38
|
+
"no-trailing-whitespace": true,
|
|
39
|
+
"one-line": [true, "check-catch", "check-finally", "check-else"],
|
|
40
|
+
"one-variable-per-declaration": [true, "ignore-for-loop"],
|
|
41
|
+
"ordered-imports": true,
|
|
42
|
+
"semicolon": [true, "never"],
|
|
43
|
+
"quotemark": [true, "single", "avoid-escape", "avoid-template"]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Contentstack DataSync Mongodb SDK
|
|
3
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
|
+
export declare const config: {
|
|
7
|
+
contentStore: {
|
|
8
|
+
collection: {
|
|
9
|
+
asset: string;
|
|
10
|
+
entry: string;
|
|
11
|
+
schema: string;
|
|
12
|
+
};
|
|
13
|
+
dbName: string;
|
|
14
|
+
indexes: {
|
|
15
|
+
_content_type_uid: number;
|
|
16
|
+
locale: number;
|
|
17
|
+
uid: number;
|
|
18
|
+
updated_at: number;
|
|
19
|
+
};
|
|
20
|
+
internal: {
|
|
21
|
+
types: {
|
|
22
|
+
assets: string;
|
|
23
|
+
content_types: string;
|
|
24
|
+
references: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
limit: number;
|
|
28
|
+
locale: string;
|
|
29
|
+
options: {
|
|
30
|
+
connectTimeoutMS: number;
|
|
31
|
+
noDelay: boolean;
|
|
32
|
+
useNewUrlParser: boolean;
|
|
33
|
+
};
|
|
34
|
+
projections: {
|
|
35
|
+
_content_type_uid: number;
|
|
36
|
+
_id: number;
|
|
37
|
+
};
|
|
38
|
+
referenceDepth: number;
|
|
39
|
+
skip: number;
|
|
40
|
+
url: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Contentstack DataSync Mongodb SDK
|
|
3
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
|
+
import { Stack } from './stack';
|
|
7
|
+
/**
|
|
8
|
+
* @class Stack
|
|
9
|
+
* @description Initialize an instance of `Stack`
|
|
10
|
+
* @api public
|
|
11
|
+
* @example
|
|
12
|
+
* const Stack = Contentstack.Stack({
|
|
13
|
+
* contentStore: {
|
|
14
|
+
* baseDir: '../../dev-contents'
|
|
15
|
+
* },
|
|
16
|
+
* locales: [
|
|
17
|
+
* {
|
|
18
|
+
* code: 'en-us',
|
|
19
|
+
* relative_url_prefix: '/'
|
|
20
|
+
* }
|
|
21
|
+
* ]
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* @returns {Stack} Returns Stack method, which's used to create an instance of Stack
|
|
25
|
+
*/
|
|
26
|
+
export declare class Contentstack {
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
* @method Stack
|
|
30
|
+
* @summary Initialize Stack instance
|
|
31
|
+
* @param {object} config Stack config
|
|
32
|
+
* @param {object} db Existing db connection
|
|
33
|
+
* @returns {Stack} - Returns an instance of `Stack`
|
|
34
|
+
*/
|
|
35
|
+
static Stack(config?: any, db?: any): Stack;
|
|
36
|
+
}
|