Skip to content

Commit 201407b

Browse files
committed
backup
1 parent fd3c632 commit 201407b

File tree

7 files changed

+107
-96
lines changed

7 files changed

+107
-96
lines changed

dist/config.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@
66
*/
77
Object.defineProperty(exports, "__esModule", { value: true });
88
exports.config = {
9-
collectionName: 'contents',
10-
dbName: 'contentstack-persistent-db',
11-
limit: 100,
12-
locales: [],
13-
options: {
14-
autoReconnect: true,
15-
connectTimeoutMS: 15000,
16-
keepAlive: true,
17-
noDelay: true,
18-
reconnectInterval: 1000,
19-
reconnectTries: 20,
20-
useNewUrlParser: true,
21-
},
22-
projections: {
23-
_id: 0,
24-
_version: 0,
25-
content_type_uid: 0,
26-
created_at: 0,
27-
sys_keys: 0,
28-
updated_at: 0,
29-
updated_by: 0,
30-
},
31-
skip: 0,
32-
uri: 'mongodb://localhost:27017',
9+
contentStore: {
10+
collectionName: 'contents',
11+
dbName: 'contentstack-persistent-db',
12+
limit: 100,
13+
locales: [],
14+
options: {
15+
autoReconnect: true,
16+
connectTimeoutMS: 15000,
17+
keepAlive: true,
18+
noDelay: true,
19+
reconnectInterval: 1000,
20+
reconnectTries: 20,
21+
useNewUrlParser: true,
22+
},
23+
projections: {
24+
_id: 0,
25+
_version: 0,
26+
content_type_uid: 0,
27+
created_at: 0,
28+
sys_keys: 0,
29+
updated_at: 0,
30+
updated_by: 0,
31+
},
32+
skip: 0,
33+
uri: 'mongodb://localhost:27017',
34+
}
3335
};

dist/stack.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const util_1 = require("./util");
1616
class Stack {
1717
constructor(stackConfig, existingDB) {
1818
this.config = lodash_1.merge(config_1.config, stackConfig);
19+
this.contentStore = this.config.contentStore;
1920
this.q = {};
2021
this.internal = {};
2122
this.db = existingDB;
@@ -75,7 +76,7 @@ class Stack {
7576
connect(overrides = {}) {
7677
return new Promise((resolve, reject) => {
7778
try {
78-
const dbConfig = lodash_1.merge({}, this.config, overrides);
79+
const dbConfig = lodash_1.merge({}, this.config, overrides).contentStore;
7980
const uri = util_1.validateURI(dbConfig.uri || dbConfig.url);
8081
const options = dbConfig.options;
8182
const dbName = dbConfig.dbName;
@@ -293,7 +294,7 @@ class Stack {
293294
const stack = new Stack(this.config, this.db);
294295
if (uid && typeof uid === 'string') {
295296
stack.q.content_type_uid = uid;
296-
stack.collection = stack.db.collection(stack.config.collectionName);
297+
stack.collection = stack.db.collection(stack.contentStore.collectionName);
297298
return stack;
298299
}
299300
throw new Error('Kindly pass the content type\'s uid');
@@ -321,15 +322,15 @@ class Stack {
321322
stack.q.uid = uid;
322323
}
323324
stack.q.content_type_uid = '_assets';
324-
stack.collection = stack.db.collection(stack.config.collectionName);
325+
stack.collection = stack.db.collection(stack.contentStore.collectionName);
325326
stack.internal.limit = 1;
326327
stack.internal.single = true;
327328
return stack;
328329
}
329330
assets() {
330331
const stack = new Stack(this.config, this.db);
331332
stack.q.content_type_uid = '_assets';
332-
stack.collection = stack.db.collection(stack.config.collectionName);
333+
stack.collection = stack.db.collection(stack.contentStore.collectionName);
333334
return stack;
334335
}
335336
schema(uid) {
@@ -338,15 +339,15 @@ class Stack {
338339
stack.q.uid = uid;
339340
}
340341
stack.q.content_type_uid = 'contentTypes';
341-
stack.collection = stack.db.collection(stack.config.collectionName);
342+
stack.collection = stack.db.collection(stack.contentStore.collectionName);
342343
stack.internal.limit = 1;
343344
stack.internal.single = true;
344345
return stack;
345346
}
346347
schemas() {
347348
const stack = new Stack(this.config, this.db);
348349
stack.q.content_type_uid = 'contentTypes';
349-
stack.collection = stack.db.collection(stack.config.collectionName);
350+
stack.collection = stack.db.collection(stack.contentStore.collectionName);
350351
return stack;
351352
}
352353
limit(no) {
@@ -395,7 +396,7 @@ class Stack {
395396
this.internal.except[field] = 0;
396397
}
397398
});
398-
this.internal.except = lodash_1.merge(this.config.projections, this.internal.except);
399+
this.internal.except = lodash_1.merge(this.contentStore.projections, this.internal.except);
399400
return this;
400401
}
401402
regex(field, pattern, options = 'i') {
@@ -627,13 +628,13 @@ class Stack {
627628
this.internal.projections = this.internal.only;
628629
}
629630
else {
630-
this.internal.projections = lodash_1.merge(this.config.projections, this.internal.except);
631+
this.internal.projections = lodash_1.merge(this.contentStore.projections, this.internal.except);
631632
}
632633
if (!(this.internal.limit)) {
633-
this.internal.limit = this.config.limit;
634+
this.internal.limit = this.contentStore.limit;
634635
}
635636
if (!(this.internal.skip)) {
636-
this.internal.skip = this.config.skip;
637+
this.internal.skip = this.contentStore.skip;
637638
}
638639
if (!(this.q.locale)) {
639640
this.q.locale = this.config.locales[0].code;
@@ -753,7 +754,7 @@ class Stack {
753754
},
754755
};
755756
referencesFound.push(new Promise((rs, rj) => {
756-
return self.db.collection(this.config.collectionName)
757+
return self.db.collection(this.contentStore.collectionName)
757758
.find(query)
758759
.project(self.config.projections)
759760
.toArray()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "contentstack-sync-mongodb-sdk",
33
"version": "1.0.0",
44
"description": "Contentstack sync utility's Mongodb SDK",
5-
"main": "dist/contentstack.js",
5+
"main": "dist/index.js",
66
"scripts": {
77
"clean": "rimraf dist typings coverage",
88
"build-ts": "npm run clean && tsc",

src/config.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,32 @@
55
*/
66

77
export const config = {
8-
collectionName: 'contents',
9-
dbName: 'contentstack-persistent-db',
10-
limit: 100,
11-
locales: [
12-
],
13-
// http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html
14-
options: {
15-
autoReconnect: true,
16-
connectTimeoutMS: 15000,
17-
keepAlive: true,
18-
noDelay: true,
19-
reconnectInterval: 1000,
20-
reconnectTries: 20,
21-
useNewUrlParser: true,
22-
},
23-
projections: {
24-
_id: 0,
25-
_version: 0,
26-
content_type_uid: 0,
27-
created_at: 0,
28-
sys_keys: 0,
29-
updated_at: 0,
30-
updated_by: 0,
31-
},
32-
skip: 0,
33-
uri: 'mongodb://localhost:27017',
8+
contentStore: {
9+
collectionName: 'contents',
10+
dbName: 'contentstack-persistent-db',
11+
limit: 100,
12+
locales: [
13+
],
14+
// http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html
15+
options: {
16+
autoReconnect: true,
17+
connectTimeoutMS: 15000,
18+
keepAlive: true,
19+
noDelay: true,
20+
reconnectInterval: 1000,
21+
reconnectTries: 20,
22+
useNewUrlParser: true,
23+
},
24+
projections: {
25+
_id: 0,
26+
_version: 0,
27+
content_type_uid: 0,
28+
created_at: 0,
29+
sys_keys: 0,
30+
updated_at: 0,
31+
updated_by: 0,
32+
},
33+
skip: 0,
34+
uri: 'mongodb://localhost:27017',
35+
}
3436
}

src/stack.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import { checkCyclic, validateURI } from './util'
2121
export class Stack {
2222
private q: any
2323
private config: any
24+
private contentStore: any
2425
private client: any
2526
private collection: any
2627
private internal: any
2728
private db: Db
2829

2930
constructor(stackConfig, existingDB?) {
3031
this.config = merge(config, stackConfig)
32+
this.contentStore = this.config.contentStore
3133
this.q = {}
3234
this.internal = {}
3335
this.db = existingDB
@@ -114,7 +116,8 @@ export class Stack {
114116
public connect(overrides = {}) {
115117
return new Promise((resolve, reject) => {
116118
try {
117-
const dbConfig = merge({}, this.config, overrides)
119+
const dbConfig = merge({}, this.config, overrides).contentStore
120+
118121
const uri = validateURI(dbConfig.uri || dbConfig.url)
119122
const options = dbConfig.options
120123
const dbName = dbConfig.dbName
@@ -432,7 +435,7 @@ export class Stack {
432435
const stack = new Stack(this.config, this.db)
433436
if (uid && typeof uid === 'string') {
434437
stack.q.content_type_uid = uid
435-
stack.collection = stack.db.collection(stack.config.collectionName)
438+
stack.collection = stack.db.collection(stack.contentStore.collectionName)
436439

437440
return stack
438441
}
@@ -486,7 +489,7 @@ export class Stack {
486489
stack.q.uid = uid
487490
}
488491
stack.q.content_type_uid = '_assets'
489-
stack.collection = stack.db.collection(stack.config.collectionName)
492+
stack.collection = stack.db.collection(stack.contentStore.collectionName)
490493
stack.internal.limit = 1
491494
stack.internal.single = true
492495

@@ -501,7 +504,7 @@ export class Stack {
501504
public assets() {
502505
const stack = new Stack(this.config, this.db)
503506
stack.q.content_type_uid = '_assets'
504-
stack.collection = stack.db.collection(stack.config.collectionName)
507+
stack.collection = stack.db.collection(stack.contentStore.collectionName)
505508

506509
return stack
507510
}
@@ -519,7 +522,7 @@ export class Stack {
519522
stack.q.uid = uid
520523
}
521524
stack.q.content_type_uid = 'contentTypes'
522-
stack.collection = stack.db.collection(stack.config.collectionName)
525+
stack.collection = stack.db.collection(stack.contentStore.collectionName)
523526
stack.internal.limit = 1
524527
stack.internal.single = true
525528

@@ -534,7 +537,7 @@ export class Stack {
534537
public schemas() {
535538
const stack = new Stack(this.config, this.db)
536539
stack.q.content_type_uid = 'contentTypes'
537-
stack.collection = stack.db.collection(stack.config.collectionName)
540+
stack.collection = stack.db.collection(stack.contentStore.collectionName)
538541

539542
return stack
540543
}
@@ -626,7 +629,7 @@ export class Stack {
626629
}
627630
})
628631

629-
this.internal.except = merge(this.config.projections, this.internal.except)
632+
this.internal.except = merge(this.contentStore.projections, this.internal.except)
630633

631634
return this
632635
}
@@ -989,15 +992,15 @@ export class Stack {
989992
if (this.internal.only) {
990993
this.internal.projections = this.internal.only
991994
} else {
992-
this.internal.projections = merge(this.config.projections, this.internal.except)
995+
this.internal.projections = merge(this.contentStore.projections, this.internal.except)
993996
}
994997

995998
if (!(this.internal.limit)) {
996-
this.internal.limit = this.config.limit
999+
this.internal.limit = this.contentStore.limit
9971000
}
9981001

9991002
if (!(this.internal.skip)) {
1000-
this.internal.skip = this.config.skip
1003+
this.internal.skip = this.contentStore.skip
10011004
}
10021005

10031006
if (!(this.q.locale)) {
@@ -1159,7 +1162,7 @@ export class Stack {
11591162
}
11601163

11611164
referencesFound.push(new Promise((rs, rj) => {
1162-
return self.db.collection(this.config.collectionName)
1165+
return self.db.collection(this.contentStore.collectionName)
11631166
.find(query)
11641167
.project(self.config.projections)
11651168
.toArray()

typings/config.d.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,30 @@
44
* MIT Licensed
55
*/
66
export declare const config: {
7-
collectionName: string;
8-
dbName: string;
9-
limit: number;
10-
locales: any[];
11-
options: {
12-
autoReconnect: boolean;
13-
connectTimeoutMS: number;
14-
keepAlive: boolean;
15-
noDelay: boolean;
16-
reconnectInterval: number;
17-
reconnectTries: number;
18-
useNewUrlParser: boolean;
7+
contentStore: {
8+
collectionName: string;
9+
dbName: string;
10+
limit: number;
11+
locales: any[];
12+
options: {
13+
autoReconnect: boolean;
14+
connectTimeoutMS: number;
15+
keepAlive: boolean;
16+
noDelay: boolean;
17+
reconnectInterval: number;
18+
reconnectTries: number;
19+
useNewUrlParser: boolean;
20+
};
21+
projections: {
22+
_id: number;
23+
_version: number;
24+
content_type_uid: number;
25+
created_at: number;
26+
sys_keys: number;
27+
updated_at: number;
28+
updated_by: number;
29+
};
30+
skip: number;
31+
uri: string;
1932
};
20-
projections: {
21-
_id: number;
22-
_version: number;
23-
content_type_uid: number;
24-
created_at: number;
25-
sys_keys: number;
26-
updated_at: number;
27-
updated_by: number;
28-
};
29-
skip: number;
30-
uri: string;
3133
};

typings/stack.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
export declare class Stack {
77
private q;
88
private config;
9+
private contentStore;
910
private client;
1011
private collection;
1112
private internal;

0 commit comments

Comments
 (0)