pure-orm 1.3.1 → 2.2.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/.travis.yml +0 -6
- package/README.md +456 -185
- package/examples/order-more/bo/customer.js +18 -0
- package/examples/order-more/bo/customers.js +9 -0
- package/examples/order-more/bo/line-item.js +33 -0
- package/examples/order-more/bo/line-items.js +9 -0
- package/examples/order-more/bo/order.js +49 -0
- package/examples/order-more/bo/orders.js +9 -0
- package/examples/order-more/bo/parcel-event.js +19 -0
- package/examples/order-more/bo/parcel-events.js +9 -0
- package/examples/order-more/bo/parcel-line-item.js +24 -0
- package/examples/order-more/bo/parcel-line-items.js +9 -0
- package/examples/order-more/bo/parcel.js +18 -0
- package/examples/order-more/bo/parcels.js +9 -0
- package/examples/order-more/bo/physical-address.js +30 -0
- package/examples/order-more/bo/physical-addresses.js +12 -0
- package/examples/order-more/bo/refund.js +28 -0
- package/examples/order-more/bo/refunds.js +9 -0
- package/examples/order-more/bo/shipment-actual-product-variant.js +26 -0
- package/examples/order-more/bo/shipment-actual-product-variants.js +9 -0
- package/examples/order-more/bo/utm-medium.js +13 -0
- package/examples/order-more/bo/utm-source.js +13 -0
- package/examples/order-more/business-objects.js +12 -1
- package/package.json +1 -1
- package/src/bo/base-bo.js +51 -27
- package/src/bo/base-bo.spec.js +259 -0
- package/test-utils/eight/results.json +128 -0
- package/test-utils/eleven/results.json +818 -0
- package/test-utils/nine/bo/base.js +5 -0
- package/test-utils/nine/bo/feature-switch.js +18 -0
- package/test-utils/nine/bo/feature-switches.js +12 -0
- package/test-utils/nine/business-objects.js +7 -0
- package/test-utils/nine/results.json +12 -0
- package/test-utils/ten/results.json +899 -0
- package/test-utils/twelve/bo/base.js +5 -0
- package/test-utils/twelve/bo/member.js +16 -0
- package/test-utils/twelve/bo/members.js +9 -0
- package/test-utils/twelve/bo/prompt.js +20 -0
- package/test-utils/twelve/bo/prompts.js +9 -0
- package/test-utils/twelve/business-objects.js +8 -0
- package/test-utils/twelve/results.json +8 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const Customers = require('./customers');
|
|
3
|
+
|
|
4
|
+
class Customer extends Base {
|
|
5
|
+
get BoCollection() {
|
|
6
|
+
return Customers;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get tableName() {
|
|
10
|
+
return 'customer';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get sqlColumnsData() {
|
|
14
|
+
return ['id', 'email'];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = Customer;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const LineItems = require('./line-items');
|
|
3
|
+
const ProductVariant = require('./product-variant');
|
|
4
|
+
const Order = require('./order');
|
|
5
|
+
|
|
6
|
+
class LineItem extends Base {
|
|
7
|
+
get BoCollection() {
|
|
8
|
+
return LineItems;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static get tableName() {
|
|
12
|
+
return 'line_item';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static get sqlColumnsData() {
|
|
16
|
+
return [
|
|
17
|
+
'id',
|
|
18
|
+
{ column: 'product_variant_id', references: ProductVariant },
|
|
19
|
+
{ column: 'order_id', references: Order },
|
|
20
|
+
'fulfillment_status_id',
|
|
21
|
+
'fulfillable_quantity',
|
|
22
|
+
'fulfillment_service',
|
|
23
|
+
'grams',
|
|
24
|
+
'price',
|
|
25
|
+
'quantity',
|
|
26
|
+
'requires_shipping',
|
|
27
|
+
'taxable',
|
|
28
|
+
'total_discount'
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = LineItem;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const BaseBo = require('./base');
|
|
2
|
+
const Orders = require('./orders');
|
|
3
|
+
const UtmSource = require('./utm-source');
|
|
4
|
+
const Customer = require('./customer');
|
|
5
|
+
const PhysicalAddress = require('./physical-address');
|
|
6
|
+
|
|
7
|
+
class Order extends BaseBo {
|
|
8
|
+
get BoCollection() {
|
|
9
|
+
return Orders;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static get tableName() {
|
|
13
|
+
return 'order';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static get sqlColumnsData() {
|
|
17
|
+
return [
|
|
18
|
+
'id',
|
|
19
|
+
'email',
|
|
20
|
+
{ column: 'customer_id', references: Customer },
|
|
21
|
+
{ column: 'shipping_address_id', references: PhysicalAddress },
|
|
22
|
+
{ column: 'billing_address_id', references: PhysicalAddress },
|
|
23
|
+
'browser_ip',
|
|
24
|
+
'browser_user_agent',
|
|
25
|
+
'kujo_imported_date',
|
|
26
|
+
'created_date',
|
|
27
|
+
'cancel_reason',
|
|
28
|
+
'cancelled_date',
|
|
29
|
+
'closed_date',
|
|
30
|
+
'processed_date',
|
|
31
|
+
'updated_date',
|
|
32
|
+
'note',
|
|
33
|
+
'subtotal_price',
|
|
34
|
+
'taxes_included',
|
|
35
|
+
'total_discounts',
|
|
36
|
+
'total_price',
|
|
37
|
+
'total_tax',
|
|
38
|
+
'total_weight',
|
|
39
|
+
'order_status_url',
|
|
40
|
+
{ column: 'utm_source_id', references: UtmSource },
|
|
41
|
+
'utm_medium_id',
|
|
42
|
+
'utm_campaign',
|
|
43
|
+
'utm_content',
|
|
44
|
+
'utm_term'
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = Order;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const ParcelEvents = require('./parcel-events');
|
|
3
|
+
const Parcel = require('./parcel');
|
|
4
|
+
|
|
5
|
+
class ParcelEvent extends Base {
|
|
6
|
+
get BoCollection() {
|
|
7
|
+
return ParcelEvents;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static get tableName() {
|
|
11
|
+
return 'parcel_event';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static get sqlColumnsData() {
|
|
15
|
+
return ['id', { column: 'parcel_id', references: Parcel }, 'eta', 'status'];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = ParcelEvent;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const ParcelLineItems = require('./parcel-line-items');
|
|
3
|
+
const LineItem = require('./line-item');
|
|
4
|
+
const Parcel = require('./parcel');
|
|
5
|
+
|
|
6
|
+
class ParcelLineItem extends Base {
|
|
7
|
+
get BoCollection() {
|
|
8
|
+
return ParcelLineItems;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static get tableName() {
|
|
12
|
+
return 'parcel_line_item';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static get sqlColumnsData() {
|
|
16
|
+
return [
|
|
17
|
+
'id',
|
|
18
|
+
{ column: 'line_item_id', references: LineItem },
|
|
19
|
+
{ column: 'parcel_id', references: Parcel }
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = ParcelLineItem;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const BaseBo = require('./base');
|
|
2
|
+
const Parcels = require('./parcels');
|
|
3
|
+
|
|
4
|
+
class Parcel extends BaseBo {
|
|
5
|
+
get BoCollection() {
|
|
6
|
+
return Parcels;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get tableName() {
|
|
10
|
+
return 'parcel';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get sqlColumnsData() {
|
|
14
|
+
return ['id'];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = Parcel;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const PhysicalAddresses = require('./physical-addresses');
|
|
3
|
+
|
|
4
|
+
class PhysicalAddress extends Base {
|
|
5
|
+
get BoCollection() {
|
|
6
|
+
return PhysicalAddresses;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get tableName() {
|
|
10
|
+
return 'physical_address';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get sqlColumnsData() {
|
|
14
|
+
return [
|
|
15
|
+
'id',
|
|
16
|
+
'address1',
|
|
17
|
+
'address2',
|
|
18
|
+
'city',
|
|
19
|
+
'province',
|
|
20
|
+
'zip',
|
|
21
|
+
'country',
|
|
22
|
+
'province_code',
|
|
23
|
+
'country_code',
|
|
24
|
+
'latitude',
|
|
25
|
+
'longitude'
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = PhysicalAddress;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const { BaseBoCollection } = require('../../../src/index');
|
|
2
|
+
|
|
3
|
+
class PhysicalAddresses extends BaseBoCollection {
|
|
4
|
+
static get displayName() {
|
|
5
|
+
return 'physicalAddresses';
|
|
6
|
+
}
|
|
7
|
+
static get Bo() {
|
|
8
|
+
return require('./physical-address'); // eslint-disable-line
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = PhysicalAddresses;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const Order = require('./order');
|
|
3
|
+
const Refunds = require('./refunds');
|
|
4
|
+
|
|
5
|
+
class Refund extends Base {
|
|
6
|
+
get BoCollection() {
|
|
7
|
+
return Refunds;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static get tableName() {
|
|
11
|
+
return 'refund';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static get sqlColumnsData() {
|
|
15
|
+
return [
|
|
16
|
+
'id',
|
|
17
|
+
{ column: 'order_id', references: Order },
|
|
18
|
+
'shopify_id',
|
|
19
|
+
'created_date',
|
|
20
|
+
'processed_date',
|
|
21
|
+
'kujo_imported_date',
|
|
22
|
+
'amount',
|
|
23
|
+
'note',
|
|
24
|
+
'restock'
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
module.exports = Refund;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const Base = require('./base');
|
|
2
|
+
const ShipmentActualProductVariants = require('./shipment-actual-product-variants');
|
|
3
|
+
const ActualProductVariant = require('./actual-product-variant');
|
|
4
|
+
const Shipment = require('./shipment');
|
|
5
|
+
|
|
6
|
+
class ShipmentActualProductVariant extends Base {
|
|
7
|
+
get BoCollection() {
|
|
8
|
+
return ShipmentActualProductVariants;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static get tableName() {
|
|
12
|
+
return 'shipment_actual_product_variant';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static get sqlColumnsData() {
|
|
16
|
+
return [
|
|
17
|
+
'id',
|
|
18
|
+
{ column: 'shipment_id', references: Shipment },
|
|
19
|
+
{ column: 'actual_product_variant_id', references: ActualProductVariant },
|
|
20
|
+
'quantity',
|
|
21
|
+
'updated_date'
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = ShipmentActualProductVariant;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const { BaseBoCollection } = require('../../../src/index');
|
|
2
|
+
|
|
3
|
+
class ShipmentActualProductVariants extends BaseBoCollection {
|
|
4
|
+
static get Bo() {
|
|
5
|
+
return require('./shipment-actual-product-variant'); // eslint-disable-line
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
module.exports = ShipmentActualProductVariants;
|
|
@@ -9,7 +9,18 @@ const getBusinessObjects = () => [
|
|
|
9
9
|
require('./bo/size'),
|
|
10
10
|
require('./bo/color'),
|
|
11
11
|
require('./bo/gender'),
|
|
12
|
-
require('./bo/shipment')
|
|
12
|
+
require('./bo/shipment'),
|
|
13
|
+
require('./bo/shipment-actual-product-variant'),
|
|
14
|
+
require('./bo/refund'),
|
|
15
|
+
require('./bo/order'),
|
|
16
|
+
require('./bo/line-item'),
|
|
17
|
+
require('./bo/customer'),
|
|
18
|
+
require('./bo/physical-address'),
|
|
19
|
+
require('./bo/utm-source'),
|
|
20
|
+
require('./bo/utm-medium'),
|
|
21
|
+
require('./bo/parcel-line-item'),
|
|
22
|
+
require('./bo/parcel'),
|
|
23
|
+
require('./bo/parcel-event')
|
|
13
24
|
];
|
|
14
25
|
|
|
15
26
|
module.exports = getBusinessObjects;
|
package/package.json
CHANGED
package/src/bo/base-bo.js
CHANGED
|
@@ -147,35 +147,60 @@ module.exports = ({ getBusinessObjects }) =>
|
|
|
147
147
|
|
|
148
148
|
// Wowzer is this both CPU and Memory inefficient
|
|
149
149
|
clump.forEach(array => {
|
|
150
|
-
array.forEach(
|
|
150
|
+
array.forEach(_bo => {
|
|
151
151
|
const nodeAlreadySeen = nodes.find(
|
|
152
152
|
x =>
|
|
153
|
-
x.constructor.name ===
|
|
154
|
-
x.getId() ===
|
|
153
|
+
x.constructor.name === _bo.constructor.name &&
|
|
154
|
+
x.getId() === _bo.getId()
|
|
155
155
|
);
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
)
|
|
160
|
-
|
|
156
|
+
const bo = nodeAlreadySeen || _bo;
|
|
157
|
+
const isNodeAlreadySeen = !!nodeAlreadySeen;
|
|
158
|
+
const nodePointingToIt = nodes.find(node => {
|
|
159
|
+
const indexes = Object.values(node.constructor.references)
|
|
160
|
+
.map((x, i) => (x === bo.constructor ? i : null))
|
|
161
|
+
.filter(x => x != null);
|
|
162
|
+
if (!indexes.length) {
|
|
161
163
|
return false;
|
|
162
164
|
}
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
+
for (const index of indexes) {
|
|
166
|
+
const property = Object.keys(node.constructor.references)[index];
|
|
167
|
+
if (node[property] === bo.id) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
165
172
|
});
|
|
166
|
-
|
|
167
|
-
|
|
173
|
+
// For first obj type which is has an instance in nodes array,
|
|
174
|
+
// get its index in nodes array
|
|
175
|
+
const indexOfOldestParent = array.reduce((answer, obj) => {
|
|
176
|
+
if (answer != null) {
|
|
177
|
+
return answer;
|
|
178
|
+
}
|
|
179
|
+
const index = nodes.findIndex(
|
|
180
|
+
n => n.constructor === obj.constructor
|
|
181
|
+
);
|
|
182
|
+
if (index !== -1) {
|
|
183
|
+
return index;
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}, null);
|
|
187
|
+
const parentHeirarchy = [
|
|
188
|
+
...nodes.slice(0, indexOfOldestParent + 1).reverse(),
|
|
189
|
+
root
|
|
190
|
+
];
|
|
191
|
+
const nodeItPointsTo = parentHeirarchy.find(parent => {
|
|
168
192
|
const index = Object.values(bo.constructor.references).indexOf(
|
|
169
|
-
|
|
193
|
+
parent.constructor
|
|
170
194
|
);
|
|
171
195
|
if (index === -1) {
|
|
172
196
|
return false;
|
|
173
197
|
}
|
|
174
198
|
const property = Object.keys(bo.constructor.references)[index];
|
|
175
|
-
return bo[property] ===
|
|
199
|
+
return bo[property] === parent.id;
|
|
176
200
|
});
|
|
177
|
-
if (
|
|
201
|
+
if (isNodeAlreadySeen) {
|
|
178
202
|
if (nodeItPointsTo && !nodePointingToIt) {
|
|
203
|
+
nodes = [bo, ...nodes];
|
|
179
204
|
return;
|
|
180
205
|
}
|
|
181
206
|
// If the nodePointingToIt (eg, parcel_event) is part of an
|
|
@@ -183,24 +208,15 @@ module.exports = ({ getBusinessObjects }) =>
|
|
|
183
208
|
// nodeAlreadySeen, early return so we don't create it (parcel) on
|
|
184
209
|
// the nodePointingToIt (parcel_event), since it (parcel) has been
|
|
185
210
|
// shown to be the parent (of parcel_events).
|
|
186
|
-
const ec =
|
|
187
|
-
nodeAlreadySeen[nodePointingToIt.BoCollection.displayName];
|
|
211
|
+
const ec = bo[nodePointingToIt.BoCollection.displayName];
|
|
188
212
|
if (ec && ec.models.find(m => m === nodePointingToIt)) {
|
|
213
|
+
nodes = [bo, ...nodes];
|
|
189
214
|
return;
|
|
190
215
|
}
|
|
191
216
|
}
|
|
192
|
-
if (!(nodePointingToIt || nodeItPointsTo)) {
|
|
193
|
-
if (!bo.getId()) {
|
|
194
|
-
// If the join is fruitless; todo: add a test for this path
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
throw Error(
|
|
198
|
-
`Could not find how this BO fits: ${JSON.stringify(bo)}`
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
217
|
if (nodePointingToIt) {
|
|
202
218
|
nodePointingToIt[bo.constructor.displayName] = bo;
|
|
203
|
-
} else {
|
|
219
|
+
} else if (nodeItPointsTo) {
|
|
204
220
|
let collection = nodeItPointsTo[bo.BoCollection.displayName];
|
|
205
221
|
if (collection) {
|
|
206
222
|
collection.models.push(bo);
|
|
@@ -209,6 +225,14 @@ module.exports = ({ getBusinessObjects }) =>
|
|
|
209
225
|
{ models: [bo] }
|
|
210
226
|
);
|
|
211
227
|
}
|
|
228
|
+
} else {
|
|
229
|
+
if (!bo.getId()) {
|
|
230
|
+
// If the join is fruitless; todo: add a test for this path
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
throw Error(
|
|
234
|
+
`Could not find how this BO fits: ${JSON.stringify(bo)}`
|
|
235
|
+
);
|
|
212
236
|
}
|
|
213
237
|
nodes = [bo, ...nodes];
|
|
214
238
|
});
|