pure-orm 2.3.0 → 3.0.0
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/package.json +1 -1
- package/src/bo/base-bo.js +2 -2
- package/src/bo/base-bo.spec.js +38 -0
- package/test-utils/thirteen/bo/audience.js +18 -0
- package/test-utils/thirteen/bo/audiences.js +9 -0
- package/test-utils/thirteen/bo/base.js +5 -0
- package/test-utils/thirteen/bo/brand.js +18 -0
- package/test-utils/thirteen/bo/brands.js +9 -0
- package/test-utils/thirteen/bo/categories.js +12 -0
- package/test-utils/thirteen/bo/category.js +18 -0
- package/test-utils/thirteen/bo/member.js +18 -0
- package/test-utils/thirteen/bo/members.js +9 -0
- package/test-utils/thirteen/bo/passion.js +18 -0
- package/test-utils/thirteen/bo/passions.js +9 -0
- package/test-utils/thirteen/bo/product.js +19 -0
- package/test-utils/thirteen/bo/products.js +9 -0
- package/test-utils/thirteen/bo/recommendation-audience.js +24 -0
- package/test-utils/thirteen/bo/recommendation-audiences.js +9 -0
- package/test-utils/thirteen/bo/recommendation.js +30 -0
- package/test-utils/thirteen/bo/recommendations.js +9 -0
- package/test-utils/thirteen/business-objects.js +14 -0
- package/test-utils/thirteen/results.json +74 -0
package/package.json
CHANGED
package/src/bo/base-bo.js
CHANGED
|
@@ -185,8 +185,8 @@ module.exports = ({ getBusinessObjects }) =>
|
|
|
185
185
|
return null;
|
|
186
186
|
}, null);
|
|
187
187
|
const parentHeirarchy = [
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
root,
|
|
189
|
+
...nodes.slice(0, indexOfOldestParent + 1).reverse()
|
|
190
190
|
];
|
|
191
191
|
const nodeItPointsTo = parentHeirarchy.find(parent => {
|
|
192
192
|
const index = Object.values(bo.constructor.references).indexOf(
|
package/src/bo/base-bo.spec.js
CHANGED
|
@@ -20,6 +20,8 @@ const ten = require('../../test-utils/ten/results.json');
|
|
|
20
20
|
const eleven = require('../../test-utils/eleven/results.json');
|
|
21
21
|
const twelve = require('../../test-utils/twelve/results.json');
|
|
22
22
|
const Prompt = require('../../test-utils/twelve/bo/prompt');
|
|
23
|
+
const thirteen = require('../../test-utils/thirteen/results.json');
|
|
24
|
+
const Member = require('../../test-utils/thirteen/bo/member');
|
|
23
25
|
|
|
24
26
|
test('Bo#parseFromDatabase where multiple rows reduce to one nested object (with all one-to-one or one-to-many tables)', () => {
|
|
25
27
|
const order = Order.createOneFromDatabase(one);
|
|
@@ -545,3 +547,39 @@ test('Bo#parseFromDatabase 12', () => {
|
|
|
545
547
|
// Ideally the below should work
|
|
546
548
|
// expect(prompt.fromMember.id).toEqual(1);
|
|
547
549
|
});
|
|
550
|
+
|
|
551
|
+
// Issue occcurs in nestClump
|
|
552
|
+
// Problem when a table has records that are supposed to nest under root
|
|
553
|
+
// but nest under other stuff below it instead
|
|
554
|
+
// Member
|
|
555
|
+
// Recommendations [1]
|
|
556
|
+
// Brand
|
|
557
|
+
// Recommendations [1]
|
|
558
|
+
// Passion
|
|
559
|
+
// Recommendations [2]
|
|
560
|
+
// -- instead of correct --
|
|
561
|
+
// Member
|
|
562
|
+
// Recommendations[4]
|
|
563
|
+
// Brand
|
|
564
|
+
// Passion
|
|
565
|
+
test('Bo#parseFromDatabase 13', () => {
|
|
566
|
+
const members = Member.createFromDatabase(thirteen);
|
|
567
|
+
const member = members.models[0];
|
|
568
|
+
expect(member.recommendations.models.length).toEqual(4);
|
|
569
|
+
expect(member.recommendations.models[0].brand.id).toEqual(2);
|
|
570
|
+
expect(member.recommendations.models[0].product.id).toEqual(7);
|
|
571
|
+
expect(member.recommendations.models[0].category.id).toEqual(1);
|
|
572
|
+
expect(member.recommendations.models[0].recommendationAudiences.models[0].audience.id).toEqual(1);
|
|
573
|
+
expect(member.recommendations.models[1].brand.id).toEqual(2);
|
|
574
|
+
expect(member.recommendations.models[1].product.id).toEqual(1);
|
|
575
|
+
expect(member.recommendations.models[1].category.id).toEqual(2);
|
|
576
|
+
expect(member.recommendations.models[1].recommendationAudiences.models[0].audience.id).toEqual(1);
|
|
577
|
+
expect(member.recommendations.models[2].brand.id).toEqual(3);
|
|
578
|
+
expect(member.recommendations.models[2].product.id).toEqual(27);
|
|
579
|
+
expect(member.recommendations.models[2].category.id).toEqual(3);
|
|
580
|
+
expect(member.recommendations.models[2].recommendationAudiences.models[0].audience.id).toEqual(1);
|
|
581
|
+
expect(member.recommendations.models[3].brand.id).toEqual(6);
|
|
582
|
+
expect(member.recommendations.models[3].product.id).toEqual(75);
|
|
583
|
+
expect(member.recommendations.models[3].category.id).toEqual(4);
|
|
584
|
+
expect(member.recommendations.models[3].recommendationAudiences.models[0].audience.id).toEqual(1);
|
|
585
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const Audiences = require('./audiences');
|
|
3
|
+
|
|
4
|
+
class Audience extends Base {
|
|
5
|
+
get BoCollection() {
|
|
6
|
+
return Audiences;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get tableName() {
|
|
10
|
+
return 'audience';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get sqlColumnsData() {
|
|
14
|
+
return ['id'];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = Audience;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const Brands = require('./brands');
|
|
3
|
+
|
|
4
|
+
class Brand extends Base {
|
|
5
|
+
get BoCollection() {
|
|
6
|
+
return Brands;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get tableName() {
|
|
10
|
+
return 'brand';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get sqlColumnsData() {
|
|
14
|
+
return ['id'];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = Brand;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const { BaseBoCollection } = require('../../../src/index');
|
|
2
|
+
|
|
3
|
+
class Categories extends BaseBoCollection {
|
|
4
|
+
static get Bo() {
|
|
5
|
+
return require('./category'); // eslint-disable-line
|
|
6
|
+
}
|
|
7
|
+
static get displayName() {
|
|
8
|
+
return 'categories';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = Categories;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const Categories = require('./categories');
|
|
3
|
+
|
|
4
|
+
class Category extends Base {
|
|
5
|
+
get BoCollection() {
|
|
6
|
+
return Categories;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get tableName() {
|
|
10
|
+
return 'category';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get sqlColumnsData() {
|
|
14
|
+
return ['id'];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = Category;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const Members = require('./members');
|
|
3
|
+
|
|
4
|
+
class Member extends Base {
|
|
5
|
+
get BoCollection() {
|
|
6
|
+
return Members;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get tableName() {
|
|
10
|
+
return 'member';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get sqlColumnsData() {
|
|
14
|
+
return ['id'];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = Member;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const Passions = require('./passions');
|
|
3
|
+
|
|
4
|
+
class Passion extends Base {
|
|
5
|
+
get BoCollection() {
|
|
6
|
+
return Passions;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get tableName() {
|
|
10
|
+
return 'passion';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get sqlColumnsData() {
|
|
14
|
+
return ['id'];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = Passion;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const Brand = require('./brand');
|
|
3
|
+
const Products = require('./products');
|
|
4
|
+
|
|
5
|
+
class Product extends Base {
|
|
6
|
+
get BoCollection() {
|
|
7
|
+
return Products;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static get tableName() {
|
|
11
|
+
return 'product';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static get sqlColumnsData() {
|
|
15
|
+
return ['id', { column: 'brand_id', references: Brand }];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = Product;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const RecommendationAudiences = require('./recommendation-audiences');
|
|
3
|
+
const Recommendation = require('./recommendation');
|
|
4
|
+
const Audience = require('./audience');
|
|
5
|
+
|
|
6
|
+
class RecommendationAudience extends Base {
|
|
7
|
+
get BoCollection() {
|
|
8
|
+
return RecommendationAudiences;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static get tableName() {
|
|
12
|
+
return 'recommendation_audience';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static get sqlColumnsData() {
|
|
16
|
+
return [
|
|
17
|
+
'id',
|
|
18
|
+
{ column: 'recommendation_id', references: Recommendation },
|
|
19
|
+
{ column: 'audience_id', references: Audience }
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = RecommendationAudience;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const { BaseBoCollection } = require('../../../src/index');
|
|
2
|
+
|
|
3
|
+
class RecommendationAudiences extends BaseBoCollection {
|
|
4
|
+
static get Bo() {
|
|
5
|
+
return require('./recommendation-audience'); // eslint-disable-line
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
module.exports = RecommendationAudiences;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const Recommendations = require('./recommendations');
|
|
3
|
+
const Member = require('./member');
|
|
4
|
+
const Brand = require('./brand');
|
|
5
|
+
const Product = require('./product');
|
|
6
|
+
const Category = require('./category');
|
|
7
|
+
const Passion = require('./passion');
|
|
8
|
+
|
|
9
|
+
class Recommendation extends Base {
|
|
10
|
+
get BoCollection() {
|
|
11
|
+
return Recommendations;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static get tableName() {
|
|
15
|
+
return 'recommendation';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static get sqlColumnsData() {
|
|
19
|
+
return [
|
|
20
|
+
'id',
|
|
21
|
+
{ column: 'member_id', references: Member },
|
|
22
|
+
{ column: 'brand_id', references: Brand },
|
|
23
|
+
{ column: 'product_id', references: Product },
|
|
24
|
+
{ column: 'category_id', references: Category },
|
|
25
|
+
{ column: 'passion_id', references: Passion }
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = Recommendation;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* eslint-disable global-require */
|
|
2
|
+
const getBusinessObjects = () => [
|
|
3
|
+
// These need to be imported here to get around circular dependencies
|
|
4
|
+
require('./bo/member'),
|
|
5
|
+
require('./bo/recommendation'),
|
|
6
|
+
require('./bo/brand'),
|
|
7
|
+
require('./bo/product'),
|
|
8
|
+
require('./bo/category'),
|
|
9
|
+
require('./bo/passion'),
|
|
10
|
+
require('./bo/recommendation-audience'),
|
|
11
|
+
require('./bo/audience')
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
module.exports = getBusinessObjects;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"member#id": 1,
|
|
4
|
+
"recommendation#id": 1,
|
|
5
|
+
"recommendation#member_id": 1,
|
|
6
|
+
"recommendation#brand_id": 2,
|
|
7
|
+
"recommendation#product_id": 7,
|
|
8
|
+
"recommendation#category_id": 1,
|
|
9
|
+
"recommendation#passion_id": 2,
|
|
10
|
+
"brand#id": 2,
|
|
11
|
+
"product#id": 7,
|
|
12
|
+
"product#brand_id": 2,
|
|
13
|
+
"category#id": 1,
|
|
14
|
+
"passion#id": 2,
|
|
15
|
+
"recommendation_audience#id": 1,
|
|
16
|
+
"recommendation_audience#recommendation_id": 1,
|
|
17
|
+
"recommendation_audience#audience_id": 1,
|
|
18
|
+
"audience#id": 1
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"member#id": 1,
|
|
22
|
+
"recommendation#id": 2,
|
|
23
|
+
"recommendation#member_id": 1,
|
|
24
|
+
"recommendation#brand_id": 2,
|
|
25
|
+
"recommendation#product_id": 1,
|
|
26
|
+
"recommendation#category_id": 2,
|
|
27
|
+
"recommendation#passion_id": 2,
|
|
28
|
+
"brand#id": 2,
|
|
29
|
+
"product#id": 1,
|
|
30
|
+
"product#brand_id": 2,
|
|
31
|
+
"category#id": 2,
|
|
32
|
+
"passion#id": 2,
|
|
33
|
+
"recommendation_audience#id": 2,
|
|
34
|
+
"recommendation_audience#recommendation_id": 2,
|
|
35
|
+
"recommendation_audience#audience_id": 1,
|
|
36
|
+
"audience#id": 1
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"member#id": 1,
|
|
40
|
+
"recommendation#id": 3,
|
|
41
|
+
"recommendation#member_id": 1,
|
|
42
|
+
"recommendation#brand_id": 3,
|
|
43
|
+
"recommendation#product_id": 27,
|
|
44
|
+
"recommendation#category_id": 3,
|
|
45
|
+
"recommendation#passion_id": 2,
|
|
46
|
+
"brand#id": 3,
|
|
47
|
+
"product#id": 27,
|
|
48
|
+
"product#brand_id": 3,
|
|
49
|
+
"category#id": 3,
|
|
50
|
+
"passion#id": 2,
|
|
51
|
+
"recommendation_audience#id": 3,
|
|
52
|
+
"recommendation_audience#recommendation_id": 3,
|
|
53
|
+
"recommendation_audience#audience_id": 1,
|
|
54
|
+
"audience#id": 1
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"member#id": 1,
|
|
58
|
+
"recommendation#id": 4,
|
|
59
|
+
"recommendation#member_id": 1,
|
|
60
|
+
"recommendation#brand_id": 6,
|
|
61
|
+
"recommendation#product_id": 75,
|
|
62
|
+
"recommendation#category_id": 4,
|
|
63
|
+
"recommendation#passion_id": 2,
|
|
64
|
+
"brand#id": 6,
|
|
65
|
+
"product#id": 75,
|
|
66
|
+
"product#brand_id": 6,
|
|
67
|
+
"category#id": 4,
|
|
68
|
+
"passion#id": 2,
|
|
69
|
+
"recommendation_audience#id": 4,
|
|
70
|
+
"recommendation_audience#recommendation_id": 4,
|
|
71
|
+
"recommendation_audience#audience_id": 1,
|
|
72
|
+
"audience#id": 1
|
|
73
|
+
}
|
|
74
|
+
]
|