Skip to content

Commit c2e2046

Browse files
committed
backup
1 parent e6092d8 commit c2e2046

File tree

7 files changed

+64
-40
lines changed

7 files changed

+64
-40
lines changed

dist/stack.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -705,16 +705,21 @@ class Stack {
705705
references[parentUid] = references[parentUid] || [];
706706
references[parentUid] = lodash_1.uniq(references[parentUid].concat(lodash_1.map(result, 'uid')));
707707
}
708-
const referenceBucket = [];
709-
query.uid.$in.forEach((entityUid) => {
710-
const elem = lodash_1.find(result, (entity) => {
711-
return entity.uid === entityUid;
708+
if (typeof entry[prop].values === 'string') {
709+
entry[prop] = ((result === null) || result.length === 0) ? null : result[0];
710+
}
711+
else {
712+
const referenceBucket = [];
713+
query.uid.$in.forEach((entityUid) => {
714+
const elem = lodash_1.find(result, (entity) => {
715+
return entity.uid === entityUid;
716+
});
717+
if (elem) {
718+
referenceBucket.push(elem);
719+
}
712720
});
713-
if (elem) {
714-
referenceBucket.push(elem);
715-
}
716-
});
717-
entry[prop] = referenceBucket;
721+
entry[prop] = referenceBucket;
722+
}
718723
return self.includeReferencesI(entry[prop], locale, references, parentUid)
719724
.then(rs)
720725
.catch(rj);

example/index.js

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

33
const Stack = Contentstack.Stack({
44
api_key: '',
@@ -12,7 +12,7 @@ const Stack = Contentstack.Stack({
1212
code: 'es-es',
1313
relative_url_prefix: '/es/'
1414
}
15-
]
15+
],
1616
})
1717

1818
function connect () {
@@ -31,16 +31,20 @@ function find (contentType = 'blog') {
3131
return new Promise((resolve, reject) => {
3232
Stack.contentType(contentType)
3333
.entries()
34-
.includeCount()
34+
// .includeCount()
3535
.includeReferences()
36+
.queryReferences({'authors.category': {}})
3637
// .includeSchema()
37-
.language('es-es')
38+
// .language('es-es')
3839
// .notEqualTo('title', 'Blog One')
39-
// .query({"title": "Blog Two"})
40-
.limit(1)
40+
// .query({tags: {$in: ['one', 'two']}})
41+
.queryReferences({'authors.category.uid': 'c2'})
42+
// .excludeReferences()
43+
// .excludeAssets()
44+
// .limit(1)
4145
// .skip(1)
4246
// .query({
43-
// "data.uid": 'blt17559b99fee73d6f'
47+
// uid: 'blt17559b99fee73d6f'
4448
// })
4549
.find()
4650
.then(resolve)

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ module.exports = {
9999
// testEnvironmentOptions: {},
100100
testPathIgnorePatterns: [
101101
'/test/data/*',
102+
'/test/.*config.ts'
102103
],
103104
// The glob patterns Jest uses to detect test files
104105
testMatch: [

src/stack.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,17 +1101,22 @@ export class Stack {
11011101
references[parentUid] = references[parentUid] || []
11021102
references[parentUid] = uniq(references[parentUid].concat(map(result, 'uid')))
11031103
}
1104-
// format the references in order
1105-
const referenceBucket = []
1106-
query.uid.$in.forEach((entityUid) => {
1107-
const elem = find(result, (entity) => {
1108-
return entity.uid === entityUid
1104+
1105+
if (typeof entry[prop].values === 'string') {
1106+
entry[prop] = ((result === null) || result.length === 0) ? null : result[0]
1107+
} else {
1108+
// format the references in order
1109+
const referenceBucket = []
1110+
query.uid.$in.forEach((entityUid) => {
1111+
const elem = find(result, (entity) => {
1112+
return entity.uid === entityUid
1113+
})
1114+
if (elem) {
1115+
referenceBucket.push(elem)
1116+
}
11091117
})
1110-
if (elem) {
1111-
referenceBucket.push(elem)
1112-
}
1113-
})
1114-
entry[prop] = referenceBucket
1118+
entry[prop] = referenceBucket
1119+
}
11151120

11161121
return self.includeReferencesI(entry[prop], locale, references, parentUid)
11171122
.then(rs)

test/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const config = {
2+
dbName: 'sync-test',
3+
}

test/data/author.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const entries = [
7070
tags: ['8'],
7171
category: {
7272
reference_to: 'category',
73-
values: ['c1']
73+
values: 'c1'
7474
}
7575
},
7676
{
@@ -82,7 +82,7 @@ export const entries = [
8282
tags: ['10'],
8383
category: {
8484
reference_to: 'category',
85-
values: ['c2']
85+
values: 'c2'
8686
}
8787
}
8888
]

test/index.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
*/
44

55
import { Contentstack } from '../src/contentstack'
6+
import { config } from './config'
67
import { entries as authors } from './data/author'
78
import { entries as blogs } from './data/blog'
89
import { entries as categories } from './data/category'
910

10-
const Stack = Contentstack.Stack()
11+
const Stack = Contentstack.Stack(config)
1112
let db
1213

1314
describe('core', () => {
15+
beforeAll(() => {
16+
return Stack.connect({dbName: 'sync-test'}).then((dbInstance) => {
17+
db = dbInstance
18+
})
19+
})
1420
afterAll(() => {
1521
return Stack.close()
1622
})
@@ -19,17 +25,17 @@ describe('core', () => {
1925
expect(Contentstack.Stack()).toHaveProperty('connect')
2026
})
2127

22-
test('connect', () => {
23-
Stack.connect().then((dbInstance) => {
24-
db = dbInstance
25-
// const keys = ['insertMany', 'insertOne', 'updateOne', 'updateMany', 'deleteOne', 'deleteMany']
26-
// keys.forEach((key) => {
27-
// expect(dbInstance).toHaveProperty(key)
28-
// })
29-
}).catch((error) => {
30-
expect(error).toBeNull()
31-
})
32-
})
28+
// test('connect', () => {
29+
// Stack.connect().then((dbInstance) => {
30+
// // db = dbInstance
31+
// // const keys = ['insertMany', 'insertOne', 'updateOne', 'updateMany', 'deleteOne', 'deleteMany']
32+
// // keys.forEach((key) => {
33+
// // expect(dbInstance).toHaveProperty(key)
34+
// // })
35+
// }).catch((error) => {
36+
// expect(error).toBeNull()
37+
// })
38+
// })
3339

3440
test('db inserts', () => {
3541
return db.collection('contents').insertMany(authors)

0 commit comments

Comments
 (0)