Skip to content

Commit 5c2b7e8

Browse files
committed
.include() support added
1 parent 2b4730f commit 5c2b7e8

File tree

11 files changed

+1054
-620
lines changed

11 files changed

+1054
-620
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ coverage
99
example/**/*
1010
!example/index.js
1111

12-
# Random files
12+
# Random files/folders
13+
playground
1314
newQueryBuilder.ts
14-
query-builder.ts
15+
query-builder.ts

dist/config.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
Object.defineProperty(exports, "__esModule", { value: true });
88
exports.config = {
99
contentStore: {
10-
collectionName: 'contents',
11-
dbName: 'contentstack-persistent-db',
10+
collection: {
11+
entry: 'contents',
12+
asset: 'contents',
13+
schema: 'content_types',
14+
},
15+
dbName: 'contentstack-db',
1216
indexes: {
13-
published_at: -1,
14-
content_type_uid: 1,
17+
event_at: -1,
18+
_content_type_uid: 1,
1519
locale: 1,
1620
uid: 1
1721
},
@@ -20,7 +24,7 @@ exports.config = {
2024
assets: '_assets'
2125
},
2226
limit: 100,
23-
locales: [],
27+
locale: 'en-us',
2428
// http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html
2529
options: {
2630
autoReconnect: true,
@@ -34,9 +38,10 @@ exports.config = {
3438
projections: {
3539
_id: 0,
3640
_version: 0,
37-
content_type_uid: 0,
41+
_content_type_uid: 0,
42+
_synced_at: 0,
43+
app_user_object_uid: 0,
3844
created_at: 0,
39-
sys_keys: 0,
4045
updated_at: 0,
4146
updated_by: 0,
4247
},

dist/stack.js

Lines changed: 424 additions & 250 deletions
Large diffs are not rendered by default.

dist/util.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,31 @@ const getParents = (child, mapping) => {
5050
}
5151
return parents;
5252
};
53-
const validateLocales = (config) => {
54-
if (!(config.locales) || typeof config.locales !== 'object' || !(config.locales instanceof Array)) {
55-
throw new Error(`Kindly provide 'config.locales: [ { code: '' }, ...]'`);
56-
}
57-
config.locales.forEach((locale) => {
58-
if (!(locale) || typeof locale.code !== 'string' || locale.code.length === 0) {
59-
throw new Error(`Locale ${locale} is invalid!`);
60-
}
61-
});
62-
return;
63-
};
6453
const validateContentStore = (contentStore) => {
6554
if (typeof contentStore.dbName !== 'string' || contentStore.dbName.length === 0) {
6655
throw new Error(`Contentstore dbName should be of type string and not empty!`);
6756
}
68-
if (typeof contentStore.collectionName !== 'string' || contentStore.collectionName.length === 0) {
69-
throw new Error(`Contentstore collectionName should be of type string and not empty!`);
57+
if (typeof contentStore.collectionName === 'string') {
58+
contentStore.collection = {
59+
asset: contentStore.collectionName,
60+
entry: contentStore.collectionName,
61+
schema: contentStore.collectionName,
62+
};
63+
delete contentStore.collectionName;
7064
}
7165
return;
7266
};
7367
exports.validateConfig = (config) => {
74-
validateLocales(config);
7568
validateContentStore(config.contentStore);
7669
return;
7770
};
71+
exports.getCollectionName = ({ locale, content_type_uid }, collection) => {
72+
switch (content_type_uid) {
73+
case '_assets':
74+
return `${locale}.${collection.asset}`;
75+
case '_content_types':
76+
return `${locale}.${collection.schema}`;
77+
default:
78+
return `${locale}.${collection.entry}`;
79+
}
80+
};

example/index.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
const Contentstack = require('../dist').Contentstack
22

33
const Stack = Contentstack.Stack({
4-
locales: [
5-
{
6-
code: 'en-us',
7-
relative_url_prefix: '/'
8-
},
9-
{
10-
code: 'es-es',
11-
relative_url_prefix: '/es/'
12-
}
13-
],
4+
// locale: 'en-us',
145
contentStore: {
15-
dbName: 'mydb',
16-
collectionName: 'dev'
6+
dbName: 'references',
7+
collection: {
8+
entry: 'contents',
9+
asset: 'contents',
10+
schema: 'content_types'
11+
}
1712
}
1813
})
1914

@@ -29,18 +24,26 @@ function close () {
2924
return Stack.close()
3025
}
3126

32-
function find (contentType = 'authors') {
27+
function find (contentType = 'blog') {
3328
return new Promise((resolve, reject) => {
3429
Stack.contentType(contentType)
3530
.entries()
36-
.includeCount()
37-
.includeReferences()
38-
.includeSchema()
39-
.language('es-es')
40-
.notEqualTo('title', 'Kolan')
41-
.query({tags: {$in: ['one', 'two']}})
42-
.limit(10)
43-
.skip(1)
31+
// .includeCount()
32+
// .include(['reference_b'])
33+
// .include([
34+
// 'group.group.reference.reference_b.reference.reference',
35+
// ])
36+
// .include(['group.group.reference.reference_b.reference.reference', 'group.group.reference.reference_one',
37+
// 'group.group.reference.reference_two', 'group.group.reference.self_reference',
38+
// 'modular_blocks.block_one.reference', 'modular_blocks.block_two.group.reference.authors',
39+
// 'modular_blocks.block_two.group.reference.categories'
40+
// ])
41+
// .includeSchema()
42+
// .language('es-es')
43+
// .notEqualTo('title', 'Kolan')
44+
// .query({tags: {$in: ['one', 'two']}})
45+
.limit(1)
46+
// .skip(1)
4447
.find()
4548
.then(resolve)
4649
.catch(reject)
@@ -49,8 +52,10 @@ function find (contentType = 'authors') {
4952

5053
return connect()
5154
.then(() => {
55+
console.time('t')
5256
return find()
5357
.then((result) => {
58+
console.timeEnd('t')
5459
const keys = Object.keys(result)
5560
// Sample output
5661
// {

src/config.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66

77
export const config = {
88
contentStore: {
9-
collectionName: 'contents',
10-
dbName: 'contentstack-persistent-db',
9+
collection: {
10+
entry: 'contents',
11+
asset: 'contents',
12+
schema: 'content_types',
13+
},
14+
dbName: 'contentstack-db',
1115
indexes: {
12-
published_at: -1,
13-
content_type_uid: 1,
16+
event_at: -1,
17+
_content_type_uid: 1,
1418
locale: 1,
1519
uid: 1
1620
},
@@ -19,8 +23,7 @@ export const config = {
1923
assets: '_assets'
2024
},
2125
limit: 100,
22-
locales: [
23-
],
26+
locale: 'en-us',
2427
// http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html
2528
options: {
2629
autoReconnect: true,
@@ -34,9 +37,10 @@ export const config = {
3437
projections: {
3538
_id: 0,
3639
_version: 0,
37-
content_type_uid: 0,
40+
_content_type_uid: 0,
41+
_synced_at: 0,
42+
app_user_object_uid: 0,
3843
created_at: 0,
39-
sys_keys: 0,
4044
updated_at: 0,
4145
updated_by: 0,
4246
},

0 commit comments

Comments
 (0)