@carbonorm/carbonnode 3.7.12 → 3.7.13
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/dist/index.cjs.js +119 -120
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +120 -121
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/sakila-db/C6.js +1 -1
- package/src/__tests__/sakila-db/C6.ts +1 -1
- package/src/api/executors/HttpExecutor.ts +2 -10
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import Qs from 'qs';
|
|
3
|
-
import { __assign, __awaiter, __generator, __spreadArray, __rest
|
|
3
|
+
import { __assign, __awaiter, __generator, __extends, __spreadArray, __rest } from 'tslib';
|
|
4
4
|
import { toast } from 'react-toastify';
|
|
5
5
|
import namedPlaceholders from 'named-placeholders';
|
|
6
6
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
@@ -590,122 +590,6 @@ function removeInvalidKeys(request, c6Tables) {
|
|
|
590
590
|
return intersection;
|
|
591
591
|
}
|
|
592
592
|
|
|
593
|
-
/**
|
|
594
|
-
* Converts a singular T-shaped request into complex ORM format for GET/PUT/DELETE
|
|
595
|
-
* Enforces that all primary keys are present for singular syntax and that the table has PKs.
|
|
596
|
-
* Optionally accepts a previously removed primary key (key/value) to reconstruct WHERE.
|
|
597
|
-
*/
|
|
598
|
-
function normalizeSingularRequest(requestMethod, request, restModel, removedPrimary) {
|
|
599
|
-
var _a, _b;
|
|
600
|
-
var _c;
|
|
601
|
-
if (request == null || typeof request !== 'object')
|
|
602
|
-
return request;
|
|
603
|
-
var specialKeys = new Set([
|
|
604
|
-
C6Constants.SELECT,
|
|
605
|
-
C6Constants.UPDATE,
|
|
606
|
-
C6Constants.DELETE,
|
|
607
|
-
C6Constants.WHERE,
|
|
608
|
-
C6Constants.JOIN,
|
|
609
|
-
C6Constants.PAGINATION,
|
|
610
|
-
]);
|
|
611
|
-
// Determine if the request is already complex (has any special key besides PAGINATION)
|
|
612
|
-
var keys = Object.keys(request);
|
|
613
|
-
var hasComplexKeys = keys.some(function (k) { return k !== C6Constants.PAGINATION && specialKeys.has(k); });
|
|
614
|
-
if (hasComplexKeys)
|
|
615
|
-
return request; // already complex
|
|
616
|
-
// We treat it as singular when it's not complex.
|
|
617
|
-
// For GET, PUT, DELETE only
|
|
618
|
-
if (!(requestMethod === C6Constants.GET || requestMethod === C6Constants.PUT || requestMethod === C6Constants.DELETE)) {
|
|
619
|
-
return request;
|
|
620
|
-
}
|
|
621
|
-
var pkShorts = Array.isArray(restModel.PRIMARY_SHORT) ? __spreadArray([], restModel.PRIMARY_SHORT, true) : [];
|
|
622
|
-
var pkFulls = Array.isArray(restModel.PRIMARY) ? __spreadArray([], restModel.PRIMARY, true) : [];
|
|
623
|
-
var resolveShortKey = function (key) {
|
|
624
|
-
var _a;
|
|
625
|
-
var cols = restModel.COLUMNS || {};
|
|
626
|
-
return (_a = cols[key]) !== null && _a !== void 0 ? _a : key;
|
|
627
|
-
};
|
|
628
|
-
if (!pkShorts.length) {
|
|
629
|
-
// For GET requests, do not enforce primary key presence; treat as a collection query.
|
|
630
|
-
if (requestMethod === C6Constants.GET)
|
|
631
|
-
return request;
|
|
632
|
-
throw new Error("Table (".concat(restModel.TABLE_NAME, ") has no primary key; singular request syntax is not allowed."));
|
|
633
|
-
}
|
|
634
|
-
// Build pk map from request + possibly removed primary key (accept short or fully-qualified keys)
|
|
635
|
-
var pkValues = {};
|
|
636
|
-
var requestObj = request;
|
|
637
|
-
var _loop_1 = function (pkShort) {
|
|
638
|
-
// 1) direct short key
|
|
639
|
-
var value = requestObj[pkShort];
|
|
640
|
-
if (value === undefined) {
|
|
641
|
-
// 2) fully-qualified key matching this short key (from PRIMARY list or by concatenation)
|
|
642
|
-
var fqCandidate_1 = "".concat(restModel.TABLE_NAME, ".").concat(pkShort);
|
|
643
|
-
var fqKey = (_c = pkFulls.find(function (fq) { return fq === fqCandidate_1 || fq.endsWith(".".concat(pkShort)); })) !== null && _c !== void 0 ? _c : fqCandidate_1;
|
|
644
|
-
value = requestObj[fqKey];
|
|
645
|
-
}
|
|
646
|
-
if (value === undefined && removedPrimary) {
|
|
647
|
-
// 3) removedPrimary may provide either short or fully-qualified key
|
|
648
|
-
var removedKeyShort = resolveShortKey(removedPrimary.key);
|
|
649
|
-
if (removedKeyShort === pkShort)
|
|
650
|
-
value = removedPrimary.value;
|
|
651
|
-
}
|
|
652
|
-
if (value !== undefined && value !== null) {
|
|
653
|
-
pkValues[pkShort] = value;
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
for (var _i = 0, pkShorts_1 = pkShorts; _i < pkShorts_1.length; _i++) {
|
|
657
|
-
var pkShort = pkShorts_1[_i];
|
|
658
|
-
_loop_1(pkShort);
|
|
659
|
-
}
|
|
660
|
-
var missing = pkShorts.filter(function (pk) { return !(pk in pkValues); });
|
|
661
|
-
if (missing.length) {
|
|
662
|
-
// For GET requests, if not all PKs are provided, treat as a collection query and leave as-is.
|
|
663
|
-
if (requestMethod === C6Constants.GET) {
|
|
664
|
-
return request;
|
|
665
|
-
}
|
|
666
|
-
throw new Error("Singular request requires all primary key(s) [".concat(pkShorts.join(', '), "] for table (").concat(restModel.TABLE_NAME, "). Missing: [").concat(missing.join(', '), "]"));
|
|
667
|
-
}
|
|
668
|
-
// Strip API metadata that should remain at root
|
|
669
|
-
var _d = request, dataInsertMultipleRows = _d.dataInsertMultipleRows, cacheResults = _d.cacheResults, fetchDependencies = _d.fetchDependencies, debug = _d.debug, success = _d.success, error = _d.error, rest = __rest(_d, ["dataInsertMultipleRows", "cacheResults", "fetchDependencies", "debug", "success", "error"]);
|
|
670
|
-
if (requestMethod === C6Constants.GET) {
|
|
671
|
-
var normalized_1 = {
|
|
672
|
-
WHERE: __assign({}, pkValues),
|
|
673
|
-
};
|
|
674
|
-
// Preserve pagination if any was added previously
|
|
675
|
-
if (request[C6Constants.PAGINATION]) {
|
|
676
|
-
normalized_1[C6Constants.PAGINATION] = request[C6Constants.PAGINATION];
|
|
677
|
-
}
|
|
678
|
-
return __assign(__assign({}, normalized_1), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
679
|
-
}
|
|
680
|
-
if (requestMethod === C6Constants.DELETE) {
|
|
681
|
-
var normalized_2 = (_a = {},
|
|
682
|
-
_a[C6Constants.DELETE] = true,
|
|
683
|
-
_a.WHERE = __assign({}, pkValues),
|
|
684
|
-
_a);
|
|
685
|
-
return __assign(__assign({}, normalized_2), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
686
|
-
}
|
|
687
|
-
// PUT
|
|
688
|
-
var updateBody = {};
|
|
689
|
-
for (var _e = 0, _f = Object.keys(rest); _e < _f.length; _e++) {
|
|
690
|
-
var k = _f[_e];
|
|
691
|
-
// Skip special request keys if any slipped through
|
|
692
|
-
if (specialKeys.has(k))
|
|
693
|
-
continue;
|
|
694
|
-
var shortKey = resolveShortKey(k);
|
|
695
|
-
if (pkShorts.includes(shortKey))
|
|
696
|
-
continue; // don't update PK columns (short or fully qualified)
|
|
697
|
-
updateBody[shortKey] = rest[k];
|
|
698
|
-
}
|
|
699
|
-
if (Object.keys(updateBody).length === 0) {
|
|
700
|
-
throw new Error("Singular PUT request for table (".concat(restModel.TABLE_NAME, ") must include at least one non-primary field to update."));
|
|
701
|
-
}
|
|
702
|
-
var normalized = (_b = {},
|
|
703
|
-
_b[C6Constants.UPDATE] = updateBody,
|
|
704
|
-
_b.WHERE = __assign({}, pkValues),
|
|
705
|
-
_b);
|
|
706
|
-
return __assign(__assign({}, normalized), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
707
|
-
}
|
|
708
|
-
|
|
709
593
|
// do not remove entries from this array. It is used to track the progress of API requests.
|
|
710
594
|
// position in array is important. Do not sort. To not add to begging.
|
|
711
595
|
var apiRequestCache = [];
|
|
@@ -843,7 +727,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
843
727
|
query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
|
|
844
728
|
}
|
|
845
729
|
apiRequest = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
846
|
-
var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, querySerialized, cacheResult, cachingConfirmed, cacheCheck, cacheCheck, addBackPK,
|
|
730
|
+
var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, querySerialized, cacheResult, cachingConfirmed, cacheCheck, cacheCheck, addBackPK, apiResponse, returnGetNextPageFunction, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKey, removedPkValue_1, axiosActiveRequest;
|
|
847
731
|
var _e;
|
|
848
732
|
var _this = this;
|
|
849
733
|
var _f, _g, _h, _j, _k, _l;
|
|
@@ -963,7 +847,6 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
963
847
|
&& primaryKey in query) {
|
|
964
848
|
restRequestUri += query[primaryKey] + '/';
|
|
965
849
|
removedPkValue_1 = query[primaryKey];
|
|
966
|
-
removedPrimaryKV = { key: primaryKey, value: removedPkValue_1 };
|
|
967
850
|
addBackPK = function () {
|
|
968
851
|
query !== null && query !== void 0 ? query : (query = {});
|
|
969
852
|
query[primaryKey] = removedPkValue_1;
|
|
@@ -992,8 +875,8 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
992
875
|
var baseConfig = {
|
|
993
876
|
withCredentials: withCredentials,
|
|
994
877
|
};
|
|
995
|
-
//
|
|
996
|
-
var normalizedQuery =
|
|
878
|
+
// Pass-through request; singular normalization occurs on the backend (SqlExecutor)
|
|
879
|
+
var normalizedQuery = query;
|
|
997
880
|
switch (requestMethod) {
|
|
998
881
|
case GET:
|
|
999
882
|
return [__assign(__assign({}, baseConfig), { params: normalizedQuery })];
|
|
@@ -1879,6 +1762,122 @@ var UpdateQueryBuilder = /** @class */ (function (_super) {
|
|
|
1879
1762
|
return UpdateQueryBuilder;
|
|
1880
1763
|
}(PaginationBuilder));
|
|
1881
1764
|
|
|
1765
|
+
/**
|
|
1766
|
+
* Converts a singular T-shaped request into complex ORM format for GET/PUT/DELETE
|
|
1767
|
+
* Enforces that all primary keys are present for singular syntax and that the table has PKs.
|
|
1768
|
+
* Optionally accepts a previously removed primary key (key/value) to reconstruct WHERE.
|
|
1769
|
+
*/
|
|
1770
|
+
function normalizeSingularRequest(requestMethod, request, restModel, removedPrimary) {
|
|
1771
|
+
var _a, _b;
|
|
1772
|
+
var _c;
|
|
1773
|
+
if (request == null || typeof request !== 'object')
|
|
1774
|
+
return request;
|
|
1775
|
+
var specialKeys = new Set([
|
|
1776
|
+
C6Constants.SELECT,
|
|
1777
|
+
C6Constants.UPDATE,
|
|
1778
|
+
C6Constants.DELETE,
|
|
1779
|
+
C6Constants.WHERE,
|
|
1780
|
+
C6Constants.JOIN,
|
|
1781
|
+
C6Constants.PAGINATION,
|
|
1782
|
+
]);
|
|
1783
|
+
// Determine if the request is already complex (has any special key besides PAGINATION)
|
|
1784
|
+
var keys = Object.keys(request);
|
|
1785
|
+
var hasComplexKeys = keys.some(function (k) { return k !== C6Constants.PAGINATION && specialKeys.has(k); });
|
|
1786
|
+
if (hasComplexKeys)
|
|
1787
|
+
return request; // already complex
|
|
1788
|
+
// We treat it as singular when it's not complex.
|
|
1789
|
+
// For GET, PUT, DELETE only
|
|
1790
|
+
if (!(requestMethod === C6Constants.GET || requestMethod === C6Constants.PUT || requestMethod === C6Constants.DELETE)) {
|
|
1791
|
+
return request;
|
|
1792
|
+
}
|
|
1793
|
+
var pkShorts = Array.isArray(restModel.PRIMARY_SHORT) ? __spreadArray([], restModel.PRIMARY_SHORT, true) : [];
|
|
1794
|
+
var pkFulls = Array.isArray(restModel.PRIMARY) ? __spreadArray([], restModel.PRIMARY, true) : [];
|
|
1795
|
+
var resolveShortKey = function (key) {
|
|
1796
|
+
var _a;
|
|
1797
|
+
var cols = restModel.COLUMNS || {};
|
|
1798
|
+
return (_a = cols[key]) !== null && _a !== void 0 ? _a : key;
|
|
1799
|
+
};
|
|
1800
|
+
if (!pkShorts.length) {
|
|
1801
|
+
// For GET requests, do not enforce primary key presence; treat as a collection query.
|
|
1802
|
+
if (requestMethod === C6Constants.GET)
|
|
1803
|
+
return request;
|
|
1804
|
+
throw new Error("Table (".concat(restModel.TABLE_NAME, ") has no primary key; singular request syntax is not allowed."));
|
|
1805
|
+
}
|
|
1806
|
+
// Build pk map from request + possibly removed primary key (accept short or fully-qualified keys)
|
|
1807
|
+
var pkValues = {};
|
|
1808
|
+
var requestObj = request;
|
|
1809
|
+
var _loop_1 = function (pkShort) {
|
|
1810
|
+
// 1) direct short key
|
|
1811
|
+
var value = requestObj[pkShort];
|
|
1812
|
+
if (value === undefined) {
|
|
1813
|
+
// 2) fully-qualified key matching this short key (from PRIMARY list or by concatenation)
|
|
1814
|
+
var fqCandidate_1 = "".concat(restModel.TABLE_NAME, ".").concat(pkShort);
|
|
1815
|
+
var fqKey = (_c = pkFulls.find(function (fq) { return fq === fqCandidate_1 || fq.endsWith(".".concat(pkShort)); })) !== null && _c !== void 0 ? _c : fqCandidate_1;
|
|
1816
|
+
value = requestObj[fqKey];
|
|
1817
|
+
}
|
|
1818
|
+
if (value === undefined && removedPrimary) {
|
|
1819
|
+
// 3) removedPrimary may provide either short or fully-qualified key
|
|
1820
|
+
var removedKeyShort = resolveShortKey(removedPrimary.key);
|
|
1821
|
+
if (removedKeyShort === pkShort)
|
|
1822
|
+
value = removedPrimary.value;
|
|
1823
|
+
}
|
|
1824
|
+
if (value !== undefined && value !== null) {
|
|
1825
|
+
pkValues[pkShort] = value;
|
|
1826
|
+
}
|
|
1827
|
+
};
|
|
1828
|
+
for (var _i = 0, pkShorts_1 = pkShorts; _i < pkShorts_1.length; _i++) {
|
|
1829
|
+
var pkShort = pkShorts_1[_i];
|
|
1830
|
+
_loop_1(pkShort);
|
|
1831
|
+
}
|
|
1832
|
+
var missing = pkShorts.filter(function (pk) { return !(pk in pkValues); });
|
|
1833
|
+
if (missing.length) {
|
|
1834
|
+
// For GET requests, if not all PKs are provided, treat as a collection query and leave as-is.
|
|
1835
|
+
if (requestMethod === C6Constants.GET) {
|
|
1836
|
+
return request;
|
|
1837
|
+
}
|
|
1838
|
+
throw new Error("Singular request requires all primary key(s) [".concat(pkShorts.join(', '), "] for table (").concat(restModel.TABLE_NAME, "). Missing: [").concat(missing.join(', '), "]"));
|
|
1839
|
+
}
|
|
1840
|
+
// Strip API metadata that should remain at root
|
|
1841
|
+
var _d = request, dataInsertMultipleRows = _d.dataInsertMultipleRows, cacheResults = _d.cacheResults, fetchDependencies = _d.fetchDependencies, debug = _d.debug, success = _d.success, error = _d.error, rest = __rest(_d, ["dataInsertMultipleRows", "cacheResults", "fetchDependencies", "debug", "success", "error"]);
|
|
1842
|
+
if (requestMethod === C6Constants.GET) {
|
|
1843
|
+
var normalized_1 = {
|
|
1844
|
+
WHERE: __assign({}, pkValues),
|
|
1845
|
+
};
|
|
1846
|
+
// Preserve pagination if any was added previously
|
|
1847
|
+
if (request[C6Constants.PAGINATION]) {
|
|
1848
|
+
normalized_1[C6Constants.PAGINATION] = request[C6Constants.PAGINATION];
|
|
1849
|
+
}
|
|
1850
|
+
return __assign(__assign({}, normalized_1), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
1851
|
+
}
|
|
1852
|
+
if (requestMethod === C6Constants.DELETE) {
|
|
1853
|
+
var normalized_2 = (_a = {},
|
|
1854
|
+
_a[C6Constants.DELETE] = true,
|
|
1855
|
+
_a.WHERE = __assign({}, pkValues),
|
|
1856
|
+
_a);
|
|
1857
|
+
return __assign(__assign({}, normalized_2), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
1858
|
+
}
|
|
1859
|
+
// PUT
|
|
1860
|
+
var updateBody = {};
|
|
1861
|
+
for (var _e = 0, _f = Object.keys(rest); _e < _f.length; _e++) {
|
|
1862
|
+
var k = _f[_e];
|
|
1863
|
+
// Skip special request keys if any slipped through
|
|
1864
|
+
if (specialKeys.has(k))
|
|
1865
|
+
continue;
|
|
1866
|
+
var shortKey = resolveShortKey(k);
|
|
1867
|
+
if (pkShorts.includes(shortKey))
|
|
1868
|
+
continue; // don't update PK columns (short or fully qualified)
|
|
1869
|
+
updateBody[shortKey] = rest[k];
|
|
1870
|
+
}
|
|
1871
|
+
if (Object.keys(updateBody).length === 0) {
|
|
1872
|
+
throw new Error("Singular PUT request for table (".concat(restModel.TABLE_NAME, ") must include at least one non-primary field to update."));
|
|
1873
|
+
}
|
|
1874
|
+
var normalized = (_b = {},
|
|
1875
|
+
_b[C6Constants.UPDATE] = updateBody,
|
|
1876
|
+
_b.WHERE = __assign({}, pkValues),
|
|
1877
|
+
_b);
|
|
1878
|
+
return __assign(__assign({}, normalized), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1882
1881
|
var SqlExecutor = /** @class */ (function (_super) {
|
|
1883
1882
|
__extends(SqlExecutor, _super);
|
|
1884
1883
|
function SqlExecutor() {
|