spice-js 2.6.78 → 2.6.79
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/build/models/SpiceModel.js +58 -16
- package/package.json +1 -1
- package/src/models/SpiceModel.js +41 -4
|
@@ -37,7 +37,8 @@ var SDate = require("sonover-date"),
|
|
|
37
37
|
_serializers = Symbol(),
|
|
38
38
|
_level = Symbol(),
|
|
39
39
|
_mapping_dept = Symbol(),
|
|
40
|
-
_mapping_dept_exempt = Symbol()
|
|
40
|
+
_mapping_dept_exempt = Symbol(),
|
|
41
|
+
_current_path = Symbol(); //const _type = Symbol("type");
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
var that;
|
|
@@ -60,7 +61,7 @@ class SpiceModel {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
try {
|
|
63
|
-
var _args2, _args2$args, _args3, _args3$args, _args$args, _args4, _args4$args, _args5, _args5$args, _args6, _args6$args;
|
|
64
|
+
var _args2, _args2$args, _args3, _args3$args, _args$args, _args4, _args4$args, _args5, _args5$args, _args6, _args6$args, _args7, _args7$args;
|
|
64
65
|
|
|
65
66
|
var dbtype = spice.config.database.connections[args.connection].type || "couchbase";
|
|
66
67
|
|
|
@@ -76,6 +77,7 @@ class SpiceModel {
|
|
|
76
77
|
this[_ctx] = (_args4 = args) == null ? void 0 : (_args4$args = _args4.args) == null ? void 0 : _args4$args.ctx;
|
|
77
78
|
this[_skip_cache] = ((_args5 = args) == null ? void 0 : (_args5$args = _args5.args) == null ? void 0 : _args5$args.skip_cache) || false;
|
|
78
79
|
this[_level] = ((_args6 = args) == null ? void 0 : (_args6$args = _args6.args) == null ? void 0 : _args6$args._level) || 0;
|
|
80
|
+
this[_current_path] = ((_args7 = args) == null ? void 0 : (_args7$args = _args7.args) == null ? void 0 : _args7$args._current_path) || "";
|
|
79
81
|
this[_hooks] = {
|
|
80
82
|
create: {
|
|
81
83
|
before: [],
|
|
@@ -671,10 +673,10 @@ class SpiceModel {
|
|
|
671
673
|
|
|
672
674
|
try {
|
|
673
675
|
if (p) {
|
|
674
|
-
var
|
|
676
|
+
var _args8;
|
|
675
677
|
|
|
676
678
|
return yield p.track(_this4.type + ".get", doGet, {
|
|
677
|
-
id: (
|
|
679
|
+
id: (_args8 = args) == null ? void 0 : _args8.id
|
|
678
680
|
});
|
|
679
681
|
}
|
|
680
682
|
|
|
@@ -1319,12 +1321,12 @@ class SpiceModel {
|
|
|
1319
1321
|
/*#__PURE__*/
|
|
1320
1322
|
function () {
|
|
1321
1323
|
var _ref12 = _asyncToGenerator(function* () {
|
|
1322
|
-
var
|
|
1324
|
+
var _args9, _args10, _args11;
|
|
1323
1325
|
|
|
1324
1326
|
if (args.mapping_dept) _this12[_mapping_dept] = args.mapping_dept;
|
|
1325
1327
|
if (args.mapping_dept_exempt) _this12[_mapping_dept_exempt] = args.mapping_dept_exempt; // Find alias tokens from query/columns/sort
|
|
1326
1328
|
|
|
1327
|
-
var nestings = [..._this12.extractNestings(((
|
|
1329
|
+
var nestings = [..._this12.extractNestings(((_args9 = args) == null ? void 0 : _args9.query) || "", _this12.type), ..._this12.extractNestings(((_args10 = args) == null ? void 0 : _args10.columns) || "", _this12.type), ..._this12.extractNestings(((_args11 = args) == null ? void 0 : _args11.sort) || "", _this12.type)]; // Decide which aliases we can join: only when map.type===MODEL AND reference is a STRING keyspace.
|
|
1328
1330
|
|
|
1329
1331
|
var mappedNestings = _.compact(_.uniq(nestings).map(alias => {
|
|
1330
1332
|
var prop = _this12.props[alias];
|
|
@@ -1421,11 +1423,11 @@ class SpiceModel {
|
|
|
1421
1423
|
|
|
1422
1424
|
try {
|
|
1423
1425
|
if (p) {
|
|
1424
|
-
var
|
|
1426
|
+
var _args12, _args13;
|
|
1425
1427
|
|
|
1426
1428
|
return yield p.track(_this12.type + ".list", doList, {
|
|
1427
|
-
limit: (
|
|
1428
|
-
offset: (
|
|
1429
|
+
limit: (_args12 = args) == null ? void 0 : _args12.limit,
|
|
1430
|
+
offset: (_args13 = args) == null ? void 0 : _args13.offset
|
|
1429
1431
|
});
|
|
1430
1432
|
}
|
|
1431
1433
|
|
|
@@ -1581,6 +1583,31 @@ class SpiceModel {
|
|
|
1581
1583
|
}
|
|
1582
1584
|
|
|
1583
1585
|
return SpiceModel._hiddenPropsCache[this.type];
|
|
1586
|
+
} // Check if a field is exempt from mapping depth limits
|
|
1587
|
+
// Supports deep references like "group.permissions"
|
|
1588
|
+
|
|
1589
|
+
|
|
1590
|
+
isFieldExempt(source_property) {
|
|
1591
|
+
var currentPath = this[_current_path];
|
|
1592
|
+
var fullPath = currentPath ? currentPath + "." + source_property : source_property;
|
|
1593
|
+
return this[_mapping_dept_exempt].some(exemptPattern => {
|
|
1594
|
+
// Exact match: "group" or "group.permissions"
|
|
1595
|
+
if (exemptPattern === source_property || exemptPattern === fullPath) {
|
|
1596
|
+
return true;
|
|
1597
|
+
} // Pattern starts with current full path (e.g., "group.permissions" starts with "group")
|
|
1598
|
+
|
|
1599
|
+
|
|
1600
|
+
if (exemptPattern.startsWith(fullPath + ".")) {
|
|
1601
|
+
return true;
|
|
1602
|
+
} // Full path starts with pattern (e.g., we're at "group.permissions" and "group" is exempt)
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
if (fullPath.startsWith(exemptPattern + ".")) {
|
|
1606
|
+
return true;
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
return false;
|
|
1610
|
+
});
|
|
1584
1611
|
}
|
|
1585
1612
|
|
|
1586
1613
|
mapToObject(data, Class, source_property, store_property, property) {
|
|
@@ -1593,7 +1620,7 @@ class SpiceModel {
|
|
|
1593
1620
|
data = Array.of(data);
|
|
1594
1621
|
}
|
|
1595
1622
|
|
|
1596
|
-
var isExempt = _this15
|
|
1623
|
+
var isExempt = _this15.isFieldExempt(source_property);
|
|
1597
1624
|
|
|
1598
1625
|
if (isExempt || _this15[_level] + 1 < _this15[_mapping_dept]) {
|
|
1599
1626
|
var classes = _.compact(_.isArray(Class) ? Class : [Class]);
|
|
@@ -1604,14 +1631,17 @@ class SpiceModel {
|
|
|
1604
1631
|
if (_.isString(result[source_property]) && result[source_property] != "") {
|
|
1605
1632
|
ids = _.union(ids, [result[source_property]]);
|
|
1606
1633
|
}
|
|
1607
|
-
});
|
|
1634
|
+
}); // Build the path for child models
|
|
1608
1635
|
|
|
1636
|
+
|
|
1637
|
+
var childPath = _this15[_current_path] ? _this15[_current_path] + "." + source_property : source_property;
|
|
1609
1638
|
var returned_all = yield Promise.allSettled(_.map(classes, obj => {
|
|
1610
1639
|
return new obj(_extends({}, _this15[_args], {
|
|
1611
1640
|
skip_cache: _this15[_skip_cache],
|
|
1612
1641
|
_level: _this15[_level] + 1,
|
|
1613
1642
|
mapping_dept: _this15[_mapping_dept],
|
|
1614
|
-
mapping_dept_exempt: _this15[_mapping_dept_exempt]
|
|
1643
|
+
mapping_dept_exempt: _this15[_mapping_dept_exempt],
|
|
1644
|
+
_current_path: childPath
|
|
1615
1645
|
})).getMulti({
|
|
1616
1646
|
skip_hooks: true,
|
|
1617
1647
|
ids: ids
|
|
@@ -1645,7 +1675,7 @@ class SpiceModel {
|
|
|
1645
1675
|
data = Array.of(data);
|
|
1646
1676
|
}
|
|
1647
1677
|
|
|
1648
|
-
var isExempt = _this16
|
|
1678
|
+
var isExempt = _this16.isFieldExempt(source_property);
|
|
1649
1679
|
|
|
1650
1680
|
if (isExempt || _this16[_level] + 1 < _this16[_mapping_dept]) {
|
|
1651
1681
|
var ids = [];
|
|
@@ -1664,7 +1694,10 @@ class SpiceModel {
|
|
|
1664
1694
|
var items = _.filter(value, obj => _.isString(obj) && obj != "");
|
|
1665
1695
|
|
|
1666
1696
|
ids = _.union(ids, items);
|
|
1667
|
-
});
|
|
1697
|
+
}); // Build the path for child models
|
|
1698
|
+
|
|
1699
|
+
|
|
1700
|
+
var childPath = _this16[_current_path] ? _this16[_current_path] + "." + source_property : source_property;
|
|
1668
1701
|
|
|
1669
1702
|
var classes = _.compact(_.isArray(Class) ? Class : [Class]);
|
|
1670
1703
|
|
|
@@ -1673,7 +1706,8 @@ class SpiceModel {
|
|
|
1673
1706
|
skip_cache: _this16[_skip_cache],
|
|
1674
1707
|
_level: _this16[_level] + 1,
|
|
1675
1708
|
mapping_dept: _this16[_mapping_dept],
|
|
1676
|
-
mapping_dept_exempt: _this16[_mapping_dept_exempt]
|
|
1709
|
+
mapping_dept_exempt: _this16[_mapping_dept_exempt],
|
|
1710
|
+
_current_path: childPath
|
|
1677
1711
|
})).getMulti({
|
|
1678
1712
|
skip_hooks: true,
|
|
1679
1713
|
ids: ids
|
|
@@ -1816,7 +1850,15 @@ class SpiceModel {
|
|
|
1816
1850
|
|
|
1817
1851
|
|
|
1818
1852
|
parseRequestedColumns(columns) {
|
|
1819
|
-
if (!columns || columns === "") return null; //
|
|
1853
|
+
if (!columns || columns === "") return null; // Handle array of columns (convert to string)
|
|
1854
|
+
|
|
1855
|
+
if (Array.isArray(columns)) {
|
|
1856
|
+
columns = columns.join(",");
|
|
1857
|
+
} // Must be a string to parse
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
if (typeof columns !== "string") return null;
|
|
1861
|
+
console.log("columns", columns); // Extract field names from column specifications
|
|
1820
1862
|
// Handles: "field", "`field`", "table.field", "`table`.`field`", "expr AS alias"
|
|
1821
1863
|
|
|
1822
1864
|
var fields = new Set();
|
package/package.json
CHANGED
package/src/models/SpiceModel.js
CHANGED
|
@@ -21,7 +21,8 @@ var SDate = require("sonover-date"),
|
|
|
21
21
|
_serializers = Symbol(),
|
|
22
22
|
_level = Symbol(),
|
|
23
23
|
_mapping_dept = Symbol(),
|
|
24
|
-
_mapping_dept_exempt = Symbol()
|
|
24
|
+
_mapping_dept_exempt = Symbol(),
|
|
25
|
+
_current_path = Symbol();
|
|
25
26
|
|
|
26
27
|
//const _type = Symbol("type");
|
|
27
28
|
|
|
@@ -63,6 +64,7 @@ export default class SpiceModel {
|
|
|
63
64
|
this[_ctx] = args?.args?.ctx;
|
|
64
65
|
this[_skip_cache] = args?.args?.skip_cache || false;
|
|
65
66
|
this[_level] = args?.args?._level || 0;
|
|
67
|
+
this[_current_path] = args?.args?._current_path || "";
|
|
66
68
|
this[_hooks] = {
|
|
67
69
|
create: {
|
|
68
70
|
before: [],
|
|
@@ -1418,12 +1420,35 @@ export default class SpiceModel {
|
|
|
1418
1420
|
return SpiceModel._hiddenPropsCache[this.type];
|
|
1419
1421
|
}
|
|
1420
1422
|
|
|
1423
|
+
// Check if a field is exempt from mapping depth limits
|
|
1424
|
+
// Supports deep references like "group.permissions"
|
|
1425
|
+
isFieldExempt(source_property) {
|
|
1426
|
+
const currentPath = this[_current_path];
|
|
1427
|
+
const fullPath = currentPath ? `${currentPath}.${source_property}` : source_property;
|
|
1428
|
+
|
|
1429
|
+
return this[_mapping_dept_exempt].some((exemptPattern) => {
|
|
1430
|
+
// Exact match: "group" or "group.permissions"
|
|
1431
|
+
if (exemptPattern === source_property || exemptPattern === fullPath) {
|
|
1432
|
+
return true;
|
|
1433
|
+
}
|
|
1434
|
+
// Pattern starts with current full path (e.g., "group.permissions" starts with "group")
|
|
1435
|
+
if (exemptPattern.startsWith(fullPath + ".")) {
|
|
1436
|
+
return true;
|
|
1437
|
+
}
|
|
1438
|
+
// Full path starts with pattern (e.g., we're at "group.permissions" and "group" is exempt)
|
|
1439
|
+
if (fullPath.startsWith(exemptPattern + ".")) {
|
|
1440
|
+
return true;
|
|
1441
|
+
}
|
|
1442
|
+
return false;
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1421
1446
|
async mapToObject(data, Class, source_property, store_property, property) {
|
|
1422
1447
|
let original_is_array = _.isArray(data);
|
|
1423
1448
|
if (!original_is_array) {
|
|
1424
1449
|
data = Array.of(data);
|
|
1425
1450
|
}
|
|
1426
|
-
const isExempt = this
|
|
1451
|
+
const isExempt = this.isFieldExempt(source_property);
|
|
1427
1452
|
if (isExempt || this[_level] + 1 < this[_mapping_dept]) {
|
|
1428
1453
|
let classes = _.compact(_.isArray(Class) ? Class : [Class]);
|
|
1429
1454
|
|
|
@@ -1437,6 +1462,11 @@ export default class SpiceModel {
|
|
|
1437
1462
|
}
|
|
1438
1463
|
});
|
|
1439
1464
|
|
|
1465
|
+
// Build the path for child models
|
|
1466
|
+
const childPath = this[_current_path]
|
|
1467
|
+
? `${this[_current_path]}.${source_property}`
|
|
1468
|
+
: source_property;
|
|
1469
|
+
|
|
1440
1470
|
var returned_all = await Promise.allSettled(
|
|
1441
1471
|
_.map(classes, (obj) => {
|
|
1442
1472
|
return new obj({
|
|
@@ -1445,6 +1475,7 @@ export default class SpiceModel {
|
|
|
1445
1475
|
_level: this[_level] + 1,
|
|
1446
1476
|
mapping_dept: this[_mapping_dept],
|
|
1447
1477
|
mapping_dept_exempt: this[_mapping_dept_exempt],
|
|
1478
|
+
_current_path: childPath,
|
|
1448
1479
|
}).getMulti({
|
|
1449
1480
|
skip_hooks: true,
|
|
1450
1481
|
ids: ids,
|
|
@@ -1482,7 +1513,7 @@ export default class SpiceModel {
|
|
|
1482
1513
|
if (!original_is_array) {
|
|
1483
1514
|
data = Array.of(data);
|
|
1484
1515
|
}
|
|
1485
|
-
const isExempt = this
|
|
1516
|
+
const isExempt = this.isFieldExempt(source_property);
|
|
1486
1517
|
if (isExempt || this[_level] + 1 < this[_mapping_dept]) {
|
|
1487
1518
|
let ids = [];
|
|
1488
1519
|
_.each(data, (result) => {
|
|
@@ -1500,6 +1531,11 @@ export default class SpiceModel {
|
|
|
1500
1531
|
ids = _.union(ids, items);
|
|
1501
1532
|
});
|
|
1502
1533
|
|
|
1534
|
+
// Build the path for child models
|
|
1535
|
+
const childPath = this[_current_path]
|
|
1536
|
+
? `${this[_current_path]}.${source_property}`
|
|
1537
|
+
: source_property;
|
|
1538
|
+
|
|
1503
1539
|
let classes = _.compact(_.isArray(Class) ? Class : [Class]);
|
|
1504
1540
|
var returned_all = await Promise.allSettled(
|
|
1505
1541
|
_.map(classes, (obj) => {
|
|
@@ -1509,6 +1545,7 @@ export default class SpiceModel {
|
|
|
1509
1545
|
_level: this[_level] + 1,
|
|
1510
1546
|
mapping_dept: this[_mapping_dept],
|
|
1511
1547
|
mapping_dept_exempt: this[_mapping_dept_exempt],
|
|
1548
|
+
_current_path: childPath,
|
|
1512
1549
|
}).getMulti({
|
|
1513
1550
|
skip_hooks: true,
|
|
1514
1551
|
ids: ids,
|
|
@@ -1635,7 +1672,7 @@ export default class SpiceModel {
|
|
|
1635
1672
|
|
|
1636
1673
|
// Must be a string to parse
|
|
1637
1674
|
if (typeof columns !== "string") return null;
|
|
1638
|
-
|
|
1675
|
+
console.log("columns", columns);
|
|
1639
1676
|
// Extract field names from column specifications
|
|
1640
1677
|
// Handles: "field", "`field`", "table.field", "`table`.`field`", "expr AS alias"
|
|
1641
1678
|
const fields = new Set();
|