@carbonorm/carbonnode 3.7.15 → 3.7.17
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 +143 -155
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +144 -156
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/httpExecutorSingular.e2e.test.ts +72 -0
- package/src/__tests__/normalizeSingularRequest.test.ts +8 -8
- package/src/__tests__/sakila-db/C6.js +1 -1
- package/src/__tests__/sakila-db/C6.ts +1 -1
- package/src/api/executors/HttpExecutor.ts +4 -35
- package/src/api/handlers/ExpressHandler.ts +10 -21
- package/src/api/utils/normalizeSingularRequest.ts +15 -4
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';
|
|
@@ -620,122 +620,6 @@ function sortAndSerializeQueryObject(tables, query) {
|
|
|
620
620
|
return tables + ' ' + JSON.stringify(orderedQuery);
|
|
621
621
|
}
|
|
622
622
|
|
|
623
|
-
/**
|
|
624
|
-
* Converts a singular T-shaped request into complex ORM format for GET/PUT/DELETE
|
|
625
|
-
* Enforces that all primary keys are present for singular syntax and that the table has PKs.
|
|
626
|
-
* Optionally accepts a previously removed primary key (key/value) to reconstruct WHERE.
|
|
627
|
-
*/
|
|
628
|
-
function normalizeSingularRequest(requestMethod, request, restModel, removedPrimary) {
|
|
629
|
-
var _a, _b;
|
|
630
|
-
var _c;
|
|
631
|
-
if (request == null || typeof request !== 'object')
|
|
632
|
-
return request;
|
|
633
|
-
var specialKeys = new Set([
|
|
634
|
-
C6Constants.SELECT,
|
|
635
|
-
C6Constants.UPDATE,
|
|
636
|
-
C6Constants.DELETE,
|
|
637
|
-
C6Constants.WHERE,
|
|
638
|
-
C6Constants.JOIN,
|
|
639
|
-
C6Constants.PAGINATION,
|
|
640
|
-
]);
|
|
641
|
-
// Determine if the request is already complex (has any special key besides PAGINATION)
|
|
642
|
-
var keys = Object.keys(request);
|
|
643
|
-
var hasComplexKeys = keys.some(function (k) { return k !== C6Constants.PAGINATION && specialKeys.has(k); });
|
|
644
|
-
if (hasComplexKeys)
|
|
645
|
-
return request; // already complex
|
|
646
|
-
// We treat it as singular when it's not complex.
|
|
647
|
-
// For GET, PUT, DELETE only
|
|
648
|
-
if (!(requestMethod === C6Constants.GET || requestMethod === C6Constants.PUT || requestMethod === C6Constants.DELETE)) {
|
|
649
|
-
return request;
|
|
650
|
-
}
|
|
651
|
-
var pkShorts = Array.isArray(restModel.PRIMARY_SHORT) ? __spreadArray([], restModel.PRIMARY_SHORT, true) : [];
|
|
652
|
-
var pkFulls = Array.isArray(restModel.PRIMARY) ? __spreadArray([], restModel.PRIMARY, true) : [];
|
|
653
|
-
var resolveShortKey = function (key) {
|
|
654
|
-
var _a;
|
|
655
|
-
var cols = restModel.COLUMNS || {};
|
|
656
|
-
return (_a = cols[key]) !== null && _a !== void 0 ? _a : key;
|
|
657
|
-
};
|
|
658
|
-
if (!pkShorts.length) {
|
|
659
|
-
// For GET requests, do not enforce primary key presence; treat as a collection query.
|
|
660
|
-
if (requestMethod === C6Constants.GET)
|
|
661
|
-
return request;
|
|
662
|
-
throw new Error("Table (".concat(restModel.TABLE_NAME, ") has no primary key; singular request syntax is not allowed."));
|
|
663
|
-
}
|
|
664
|
-
// Build pk map from request + possibly removed primary key (accept short or fully-qualified keys)
|
|
665
|
-
var pkValues = {};
|
|
666
|
-
var requestObj = request;
|
|
667
|
-
var _loop_1 = function (pkShort) {
|
|
668
|
-
// 1) direct short key
|
|
669
|
-
var value = requestObj[pkShort];
|
|
670
|
-
if (value === undefined) {
|
|
671
|
-
// 2) fully-qualified key matching this short key (from PRIMARY list or by concatenation)
|
|
672
|
-
var fqCandidate_1 = "".concat(restModel.TABLE_NAME, ".").concat(pkShort);
|
|
673
|
-
var fqKey = (_c = pkFulls.find(function (fq) { return fq === fqCandidate_1 || fq.endsWith(".".concat(pkShort)); })) !== null && _c !== void 0 ? _c : fqCandidate_1;
|
|
674
|
-
value = requestObj[fqKey];
|
|
675
|
-
}
|
|
676
|
-
if (value === undefined && removedPrimary) {
|
|
677
|
-
// 3) removedPrimary may provide either short or fully-qualified key
|
|
678
|
-
var removedKeyShort = resolveShortKey(removedPrimary.key);
|
|
679
|
-
if (removedKeyShort === pkShort)
|
|
680
|
-
value = removedPrimary.value;
|
|
681
|
-
}
|
|
682
|
-
if (value !== undefined && value !== null) {
|
|
683
|
-
pkValues[pkShort] = value;
|
|
684
|
-
}
|
|
685
|
-
};
|
|
686
|
-
for (var _i = 0, pkShorts_1 = pkShorts; _i < pkShorts_1.length; _i++) {
|
|
687
|
-
var pkShort = pkShorts_1[_i];
|
|
688
|
-
_loop_1(pkShort);
|
|
689
|
-
}
|
|
690
|
-
var missing = pkShorts.filter(function (pk) { return !(pk in pkValues); });
|
|
691
|
-
if (missing.length) {
|
|
692
|
-
// For GET requests, if not all PKs are provided, treat as a collection query and leave as-is.
|
|
693
|
-
if (requestMethod === C6Constants.GET) {
|
|
694
|
-
return request;
|
|
695
|
-
}
|
|
696
|
-
throw new Error("Singular request requires all primary key(s) [".concat(pkShorts.join(', '), "] for table (").concat(restModel.TABLE_NAME, "). Missing: [").concat(missing.join(', '), "]"));
|
|
697
|
-
}
|
|
698
|
-
// Strip API metadata that should remain at root
|
|
699
|
-
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"]);
|
|
700
|
-
if (requestMethod === C6Constants.GET) {
|
|
701
|
-
var normalized_1 = {
|
|
702
|
-
WHERE: __assign({}, pkValues),
|
|
703
|
-
};
|
|
704
|
-
// Preserve pagination if any was added previously
|
|
705
|
-
if (request[C6Constants.PAGINATION]) {
|
|
706
|
-
normalized_1[C6Constants.PAGINATION] = request[C6Constants.PAGINATION];
|
|
707
|
-
}
|
|
708
|
-
return __assign(__assign({}, normalized_1), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
709
|
-
}
|
|
710
|
-
if (requestMethod === C6Constants.DELETE) {
|
|
711
|
-
var normalized_2 = (_a = {},
|
|
712
|
-
_a[C6Constants.DELETE] = true,
|
|
713
|
-
_a.WHERE = __assign({}, pkValues),
|
|
714
|
-
_a);
|
|
715
|
-
return __assign(__assign({}, normalized_2), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
716
|
-
}
|
|
717
|
-
// PUT
|
|
718
|
-
var updateBody = {};
|
|
719
|
-
for (var _e = 0, _f = Object.keys(rest); _e < _f.length; _e++) {
|
|
720
|
-
var k = _f[_e];
|
|
721
|
-
// Skip special request keys if any slipped through
|
|
722
|
-
if (specialKeys.has(k))
|
|
723
|
-
continue;
|
|
724
|
-
var shortKey = resolveShortKey(k);
|
|
725
|
-
if (pkShorts.includes(shortKey))
|
|
726
|
-
continue; // don't update PK columns (short or fully qualified)
|
|
727
|
-
updateBody[shortKey] = rest[k];
|
|
728
|
-
}
|
|
729
|
-
if (Object.keys(updateBody).length === 0) {
|
|
730
|
-
throw new Error("Singular PUT request for table (".concat(restModel.TABLE_NAME, ") must include at least one non-primary field to update."));
|
|
731
|
-
}
|
|
732
|
-
var normalized = (_b = {},
|
|
733
|
-
_b[C6Constants.UPDATE] = updateBody,
|
|
734
|
-
_b.WHERE = __assign({}, pkValues),
|
|
735
|
-
_b);
|
|
736
|
-
return __assign(__assign({}, normalized), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
737
|
-
}
|
|
738
|
-
|
|
739
623
|
var HttpExecutor = /** @class */ (function (_super) {
|
|
740
624
|
__extends(HttpExecutor, _super);
|
|
741
625
|
function HttpExecutor() {
|
|
@@ -842,7 +726,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
842
726
|
query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
|
|
843
727
|
}
|
|
844
728
|
apiRequest = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
845
|
-
var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, querySerialized, cacheResult, cachingConfirmed, cacheCheck, cacheCheck,
|
|
729
|
+
var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, querySerialized, cacheResult, cachingConfirmed, cacheCheck, cacheCheck, apiResponse, returnGetNextPageFunction, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKey, axiosActiveRequest;
|
|
846
730
|
var _e;
|
|
847
731
|
var _this = this;
|
|
848
732
|
var _f, _g, _h, _j, _k, _l;
|
|
@@ -961,14 +845,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
961
845
|
&& undefined !== primaryKey
|
|
962
846
|
&& primaryKey in query) {
|
|
963
847
|
restRequestUri += query[primaryKey] + '/';
|
|
964
|
-
|
|
965
|
-
removedPrimaryKV = { key: primaryKey, value: removedPkValue_1 };
|
|
966
|
-
addBackPK = function () {
|
|
967
|
-
query !== null && query !== void 0 ? query : (query = {});
|
|
968
|
-
query[primaryKey] = removedPkValue_1;
|
|
969
|
-
};
|
|
970
|
-
delete query[primaryKey];
|
|
971
|
-
console.log('query', query, 'primaryKey', primaryKey, 'removedPkValue', removedPkValue_1);
|
|
848
|
+
console.log('query', query, 'primaryKey', primaryKey);
|
|
972
849
|
}
|
|
973
850
|
else {
|
|
974
851
|
console.log('query', query);
|
|
@@ -991,11 +868,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
991
868
|
var baseConfig = {
|
|
992
869
|
withCredentials: withCredentials,
|
|
993
870
|
};
|
|
994
|
-
// Normalize singular request (GET/PUT/DELETE) into complex ORM shape
|
|
995
|
-
var normalizedQuery = normalizeSingularRequest(requestMethod, query, restModel, removedPrimaryKV);
|
|
996
871
|
switch (requestMethod) {
|
|
997
872
|
case GET:
|
|
998
|
-
return [__assign(__assign({}, baseConfig), { params:
|
|
873
|
+
return [__assign(__assign({}, baseConfig), { params: query })];
|
|
999
874
|
case POST:
|
|
1000
875
|
if (dataInsertMultipleRows !== undefined) {
|
|
1001
876
|
return [
|
|
@@ -1005,9 +880,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1005
880
|
}
|
|
1006
881
|
return [convert(query), baseConfig];
|
|
1007
882
|
case PUT:
|
|
1008
|
-
return [convert(
|
|
883
|
+
return [convert(query), baseConfig];
|
|
1009
884
|
case DELETE:
|
|
1010
|
-
return [__assign(__assign({}, baseConfig), { data: convert(
|
|
885
|
+
return [__assign(__assign({}, baseConfig), { data: convert(query) })];
|
|
1011
886
|
default:
|
|
1012
887
|
throw new Error("The request method (".concat(requestMethod, ") was not recognized."));
|
|
1013
888
|
}
|
|
@@ -1019,9 +894,6 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1019
894
|
request: axiosActiveRequest
|
|
1020
895
|
});
|
|
1021
896
|
}
|
|
1022
|
-
// todo - wip verify this works
|
|
1023
|
-
// we had removed the value from the request to add to the URI.
|
|
1024
|
-
addBackPK === null || addBackPK === void 0 ? void 0 : addBackPK(); // adding back so post-processing methods work
|
|
1025
897
|
// returning the promise with this then is important for tests. todo - we could make that optional.
|
|
1026
898
|
// https://rapidapi.com/guides/axios-async-await
|
|
1027
899
|
return [2 /*return*/, axiosActiveRequest.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -1878,6 +1750,133 @@ var UpdateQueryBuilder = /** @class */ (function (_super) {
|
|
|
1878
1750
|
return UpdateQueryBuilder;
|
|
1879
1751
|
}(PaginationBuilder));
|
|
1880
1752
|
|
|
1753
|
+
/**
|
|
1754
|
+
* Converts a singular T-shaped request into complex ORM format for GET/PUT/DELETE
|
|
1755
|
+
* Enforces that all primary keys are present for singular syntax and that the table has PKs.
|
|
1756
|
+
* Optionally accepts a previously removed primary key (key/value) to reconstruct WHERE.
|
|
1757
|
+
*/
|
|
1758
|
+
function normalizeSingularRequest(requestMethod, request, restModel, removedPrimary) {
|
|
1759
|
+
var _a, _b;
|
|
1760
|
+
var _c;
|
|
1761
|
+
if (request == null || typeof request !== 'object')
|
|
1762
|
+
return request;
|
|
1763
|
+
var specialKeys = new Set([
|
|
1764
|
+
C6Constants.SELECT,
|
|
1765
|
+
C6Constants.UPDATE,
|
|
1766
|
+
C6Constants.DELETE,
|
|
1767
|
+
C6Constants.WHERE,
|
|
1768
|
+
C6Constants.JOIN,
|
|
1769
|
+
C6Constants.PAGINATION,
|
|
1770
|
+
]);
|
|
1771
|
+
// Determine if the request is already complex (has any special key besides PAGINATION)
|
|
1772
|
+
var keys = Object.keys(request);
|
|
1773
|
+
var hasComplexKeys = keys.some(function (k) { return k !== C6Constants.PAGINATION && specialKeys.has(k); });
|
|
1774
|
+
if (hasComplexKeys)
|
|
1775
|
+
return request; // already complex
|
|
1776
|
+
// We treat it as singular when it's not complex.
|
|
1777
|
+
// For GET, PUT, DELETE only
|
|
1778
|
+
if (!(requestMethod === C6Constants.GET || requestMethod === C6Constants.PUT || requestMethod === C6Constants.DELETE)) {
|
|
1779
|
+
return request;
|
|
1780
|
+
}
|
|
1781
|
+
var pkShorts = Array.isArray(restModel.PRIMARY_SHORT) ? __spreadArray([], restModel.PRIMARY_SHORT, true) : [];
|
|
1782
|
+
var pkFulls = Array.isArray(restModel.PRIMARY) ? __spreadArray([], restModel.PRIMARY, true) : [];
|
|
1783
|
+
var resolveShortKey = function (key) {
|
|
1784
|
+
var _a;
|
|
1785
|
+
var cols = restModel.COLUMNS || {};
|
|
1786
|
+
return (_a = cols[key]) !== null && _a !== void 0 ? _a : key;
|
|
1787
|
+
};
|
|
1788
|
+
if (!pkShorts.length) {
|
|
1789
|
+
// For GET requests, do not enforce primary key presence; treat as a collection query.
|
|
1790
|
+
if (requestMethod === C6Constants.GET)
|
|
1791
|
+
return request;
|
|
1792
|
+
throw new Error("Table (".concat(restModel.TABLE_NAME, ") has no primary key; singular request syntax is not allowed."));
|
|
1793
|
+
}
|
|
1794
|
+
// Build pk map from request + possibly removed primary key (accept short or fully-qualified keys)
|
|
1795
|
+
var pkValues = {};
|
|
1796
|
+
var requestObj = request;
|
|
1797
|
+
var _loop_1 = function (pkShort) {
|
|
1798
|
+
// 1) direct short key
|
|
1799
|
+
var value = requestObj[pkShort];
|
|
1800
|
+
if (value === undefined) {
|
|
1801
|
+
// 2) fully-qualified key matching this short key (from PRIMARY list or by concatenation)
|
|
1802
|
+
var fqCandidate_1 = "".concat(restModel.TABLE_NAME, ".").concat(pkShort);
|
|
1803
|
+
var fqKey = (_c = pkFulls.find(function (fq) { return fq === fqCandidate_1 || fq.endsWith(".".concat(pkShort)); })) !== null && _c !== void 0 ? _c : fqCandidate_1;
|
|
1804
|
+
value = requestObj[fqKey];
|
|
1805
|
+
}
|
|
1806
|
+
if (value === undefined && removedPrimary) {
|
|
1807
|
+
// 3) removedPrimary may provide either short or fully-qualified key
|
|
1808
|
+
var removedKeyShort = resolveShortKey(removedPrimary.key);
|
|
1809
|
+
if (removedKeyShort === pkShort)
|
|
1810
|
+
value = removedPrimary.value;
|
|
1811
|
+
}
|
|
1812
|
+
if (value !== undefined && value !== null) {
|
|
1813
|
+
pkValues[pkShort] = value;
|
|
1814
|
+
}
|
|
1815
|
+
};
|
|
1816
|
+
for (var _i = 0, pkShorts_1 = pkShorts; _i < pkShorts_1.length; _i++) {
|
|
1817
|
+
var pkShort = pkShorts_1[_i];
|
|
1818
|
+
_loop_1(pkShort);
|
|
1819
|
+
}
|
|
1820
|
+
var missing = pkShorts.filter(function (pk) { return !(pk in pkValues); });
|
|
1821
|
+
if (missing.length) {
|
|
1822
|
+
// For GET requests, if not all PKs are provided, treat as a collection query and leave as-is.
|
|
1823
|
+
if (requestMethod === C6Constants.GET) {
|
|
1824
|
+
return request;
|
|
1825
|
+
}
|
|
1826
|
+
throw new Error("Singular request requires all primary key(s) [".concat(pkShorts.join(', '), "] for table (").concat(restModel.TABLE_NAME, "). Missing: [").concat(missing.join(', '), "]"));
|
|
1827
|
+
}
|
|
1828
|
+
// Strip API metadata that should remain at root
|
|
1829
|
+
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"]);
|
|
1830
|
+
// Map short primary keys to fully-qualified column names
|
|
1831
|
+
var shortToFull = {};
|
|
1832
|
+
for (var _e = 0, _f = Object.entries(restModel.COLUMNS || {}); _e < _f.length; _e++) {
|
|
1833
|
+
var _g = _f[_e], full = _g[0], short = _g[1];
|
|
1834
|
+
shortToFull[short] = full;
|
|
1835
|
+
}
|
|
1836
|
+
var pkFullValues = Object.fromEntries(Object.entries(pkValues).map(function (_a) {
|
|
1837
|
+
var _b;
|
|
1838
|
+
var k = _a[0], v = _a[1];
|
|
1839
|
+
return [(_b = shortToFull[k]) !== null && _b !== void 0 ? _b : k, v];
|
|
1840
|
+
}));
|
|
1841
|
+
if (requestMethod === C6Constants.GET) {
|
|
1842
|
+
var normalized_1 = {
|
|
1843
|
+
WHERE: __assign({}, pkFullValues),
|
|
1844
|
+
};
|
|
1845
|
+
// Preserve pagination if any was added previously
|
|
1846
|
+
if (request[C6Constants.PAGINATION]) {
|
|
1847
|
+
normalized_1[C6Constants.PAGINATION] = request[C6Constants.PAGINATION];
|
|
1848
|
+
}
|
|
1849
|
+
return __assign(__assign({}, normalized_1), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
1850
|
+
}
|
|
1851
|
+
if (requestMethod === C6Constants.DELETE) {
|
|
1852
|
+
var normalized_2 = (_a = {},
|
|
1853
|
+
_a[C6Constants.DELETE] = true,
|
|
1854
|
+
_a.WHERE = __assign({}, pkFullValues),
|
|
1855
|
+
_a);
|
|
1856
|
+
return __assign(__assign({}, normalized_2), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
1857
|
+
}
|
|
1858
|
+
// PUT
|
|
1859
|
+
var updateBody = {};
|
|
1860
|
+
for (var _h = 0, _j = Object.keys(rest); _h < _j.length; _h++) {
|
|
1861
|
+
var k = _j[_h];
|
|
1862
|
+
// Skip special request keys if any slipped through
|
|
1863
|
+
if (specialKeys.has(k))
|
|
1864
|
+
continue;
|
|
1865
|
+
var shortKey = resolveShortKey(k);
|
|
1866
|
+
if (pkShorts.includes(shortKey))
|
|
1867
|
+
continue; // don't update PK columns (short or fully qualified)
|
|
1868
|
+
updateBody[shortKey] = rest[k];
|
|
1869
|
+
}
|
|
1870
|
+
if (Object.keys(updateBody).length === 0) {
|
|
1871
|
+
throw new Error("Singular PUT request for table (".concat(restModel.TABLE_NAME, ") must include at least one non-primary field to update."));
|
|
1872
|
+
}
|
|
1873
|
+
var normalized = (_b = {},
|
|
1874
|
+
_b[C6Constants.UPDATE] = updateBody,
|
|
1875
|
+
_b.WHERE = __assign({}, pkFullValues),
|
|
1876
|
+
_b);
|
|
1877
|
+
return __assign(__assign({}, normalized), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1881
1880
|
var SqlExecutor = /** @class */ (function (_super) {
|
|
1882
1881
|
__extends(SqlExecutor, _super);
|
|
1883
1882
|
function SqlExecutor() {
|
|
@@ -2091,28 +2090,17 @@ function ExpressHandler(_a) {
|
|
|
2091
2090
|
return [2 /*return*/];
|
|
2092
2091
|
}
|
|
2093
2092
|
primaryKeyName = primaryKeys[0];
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
payload[C6C.WHERE][primaryKeyName] = primary;
|
|
2106
|
-
}
|
|
2107
|
-
else {
|
|
2108
|
-
res.status(400).json({ error: "Invalid request: ".concat(method, " requires a primary key (").concat(primaryKeyName, ").") });
|
|
2109
|
-
}
|
|
2110
|
-
break;
|
|
2111
|
-
case 'POST':
|
|
2112
|
-
break;
|
|
2113
|
-
default:
|
|
2114
|
-
res.status(405).json({ error: "Method ".concat(method, " not allowed") });
|
|
2115
|
-
return [2 /*return*/];
|
|
2093
|
+
// If a primary key was provided in the URL, merge it into the payload.
|
|
2094
|
+
// Support both complex requests using WHERE and singular requests
|
|
2095
|
+
// where the primary key lives at the root of the payload.
|
|
2096
|
+
if (primary) {
|
|
2097
|
+
if (payload[C6C.WHERE]) {
|
|
2098
|
+
payload[C6C.WHERE][primaryKeyName] =
|
|
2099
|
+
(_a = payload[C6C.WHERE][primaryKeyName]) !== null && _a !== void 0 ? _a : primary;
|
|
2100
|
+
}
|
|
2101
|
+
else {
|
|
2102
|
+
payload[primaryKeyName] =
|
|
2103
|
+
(_b = payload[primaryKeyName]) !== null && _b !== void 0 ? _b : primary;
|
|
2116
2104
|
}
|
|
2117
2105
|
}
|
|
2118
2106
|
return [4 /*yield*/, restRequest({
|