spice-js 2.6.78 → 2.6.80
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 +43 -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,36 @@ 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 =
|
|
1428
|
+
currentPath ? `${currentPath}.${source_property}` : source_property;
|
|
1429
|
+
|
|
1430
|
+
return this[_mapping_dept_exempt].some((exemptPattern) => {
|
|
1431
|
+
// Exact match: "group" or "group.permissions"
|
|
1432
|
+
if (exemptPattern === source_property || exemptPattern === fullPath) {
|
|
1433
|
+
return true;
|
|
1434
|
+
}
|
|
1435
|
+
// Pattern starts with current full path (e.g., "group.permissions" starts with "group")
|
|
1436
|
+
if (exemptPattern.startsWith(fullPath + ".")) {
|
|
1437
|
+
return true;
|
|
1438
|
+
}
|
|
1439
|
+
// Full path starts with pattern (e.g., we're at "group.permissions" and "group" is exempt)
|
|
1440
|
+
if (fullPath.startsWith(exemptPattern + ".")) {
|
|
1441
|
+
return true;
|
|
1442
|
+
}
|
|
1443
|
+
return false;
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1421
1447
|
async mapToObject(data, Class, source_property, store_property, property) {
|
|
1422
1448
|
let original_is_array = _.isArray(data);
|
|
1423
1449
|
if (!original_is_array) {
|
|
1424
1450
|
data = Array.of(data);
|
|
1425
1451
|
}
|
|
1426
|
-
const isExempt = this
|
|
1452
|
+
const isExempt = this.isFieldExempt(source_property);
|
|
1427
1453
|
if (isExempt || this[_level] + 1 < this[_mapping_dept]) {
|
|
1428
1454
|
let classes = _.compact(_.isArray(Class) ? Class : [Class]);
|
|
1429
1455
|
|
|
@@ -1437,6 +1463,12 @@ export default class SpiceModel {
|
|
|
1437
1463
|
}
|
|
1438
1464
|
});
|
|
1439
1465
|
|
|
1466
|
+
// Build the path for child models
|
|
1467
|
+
const childPath =
|
|
1468
|
+
this[_current_path] ?
|
|
1469
|
+
`${this[_current_path]}.${source_property}`
|
|
1470
|
+
: source_property;
|
|
1471
|
+
|
|
1440
1472
|
var returned_all = await Promise.allSettled(
|
|
1441
1473
|
_.map(classes, (obj) => {
|
|
1442
1474
|
return new obj({
|
|
@@ -1445,6 +1477,7 @@ export default class SpiceModel {
|
|
|
1445
1477
|
_level: this[_level] + 1,
|
|
1446
1478
|
mapping_dept: this[_mapping_dept],
|
|
1447
1479
|
mapping_dept_exempt: this[_mapping_dept_exempt],
|
|
1480
|
+
_current_path: childPath,
|
|
1448
1481
|
}).getMulti({
|
|
1449
1482
|
skip_hooks: true,
|
|
1450
1483
|
ids: ids,
|
|
@@ -1482,7 +1515,7 @@ export default class SpiceModel {
|
|
|
1482
1515
|
if (!original_is_array) {
|
|
1483
1516
|
data = Array.of(data);
|
|
1484
1517
|
}
|
|
1485
|
-
const isExempt = this
|
|
1518
|
+
const isExempt = this.isFieldExempt(source_property);
|
|
1486
1519
|
if (isExempt || this[_level] + 1 < this[_mapping_dept]) {
|
|
1487
1520
|
let ids = [];
|
|
1488
1521
|
_.each(data, (result) => {
|
|
@@ -1500,6 +1533,12 @@ export default class SpiceModel {
|
|
|
1500
1533
|
ids = _.union(ids, items);
|
|
1501
1534
|
});
|
|
1502
1535
|
|
|
1536
|
+
// Build the path for child models
|
|
1537
|
+
const childPath =
|
|
1538
|
+
this[_current_path] ?
|
|
1539
|
+
`${this[_current_path]}.${source_property}`
|
|
1540
|
+
: source_property;
|
|
1541
|
+
|
|
1503
1542
|
let classes = _.compact(_.isArray(Class) ? Class : [Class]);
|
|
1504
1543
|
var returned_all = await Promise.allSettled(
|
|
1505
1544
|
_.map(classes, (obj) => {
|
|
@@ -1509,6 +1548,7 @@ export default class SpiceModel {
|
|
|
1509
1548
|
_level: this[_level] + 1,
|
|
1510
1549
|
mapping_dept: this[_mapping_dept],
|
|
1511
1550
|
mapping_dept_exempt: this[_mapping_dept_exempt],
|
|
1551
|
+
_current_path: childPath,
|
|
1512
1552
|
}).getMulti({
|
|
1513
1553
|
skip_hooks: true,
|
|
1514
1554
|
ids: ids,
|
|
@@ -1635,7 +1675,6 @@ export default class SpiceModel {
|
|
|
1635
1675
|
|
|
1636
1676
|
// Must be a string to parse
|
|
1637
1677
|
if (typeof columns !== "string") return null;
|
|
1638
|
-
|
|
1639
1678
|
// Extract field names from column specifications
|
|
1640
1679
|
// Handles: "field", "`field`", "table.field", "`table`.`field`", "expr AS alias"
|
|
1641
1680
|
const fields = new Set();
|