Skip to content

Commit

Permalink
Merge pull request #51 from salomonelli/master
Browse files Browse the repository at this point in the history
FIX bug #50
  • Loading branch information
pubkey authored Feb 10, 2017
2 parents c45aa15 + a47c27e commit b92521e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/KeyCompressor.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ class KeyCompressor {

_compressObj(obj, path = '') {
const ret = {};
if (typeof obj !== 'object') return obj;
if (Array.isArray(obj)) {
return obj
.map(o => this._compressObj(o, util.trimDots(path + '.item')));
}
Object.keys(obj).forEach(key => {
const propertyObj = obj[key];
const fullPath = util.trimDots(path + '.' + key);
const replacedKey = this.table[fullPath] ? this.table[fullPath] : key;
let nextObj = propertyObj;
if (Array.isArray(nextObj)) {
nextObj = nextObj
.map(o => this._compressObj(o, fullPath + '.item'));
} else if (typeof nextObj === 'object')
nextObj = this._compressObj(propertyObj, fullPath);
nextObj = this._compressObj(propertyObj, fullPath);
ret[replacedKey] = nextObj;
});
return ret;
Expand Down
28 changes: 28 additions & 0 deletions test/node/KeyCompression.test.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,32 @@ describe('KeyCompressor.test.js', () => {

});

describe('bugs', () => {

it('BUG: #50 compress string array properly', async() => {
const mySchema = {
title: 'hero schema',
description: 'describes a simple hero',
type: 'object',
properties: {
likes: {
type: 'array',
items: {
type: 'string'
}
}
}
};

const db = await RxDatabase.create('heroesDB', 'memory');
const collection = await db.collection('mycollection', mySchema);
const docData = {
likes: ['abc', '8']
};
await collection.insert(docData);
const doc = await collection.findOne().exec();
assert.equal(doc.constructor.name, 'RxDocument');
assert.deepEqual(doc.likes, docData.likes);
});
});
});

0 comments on commit b92521e

Please sign in to comment.