@carbonorm/carbonnode 3.7.13 → 3.7.15
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/api/types/ormInterfaces.d.ts +1 -1
- package/dist/index.cjs.js +121 -121
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +122 -122
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/expressServer.e2e.test.ts +95 -0
- package/src/__tests__/fixtures/createTestServer.ts +15 -0
- package/src/__tests__/sakila-db/C6.js +1 -1
- package/src/__tests__/sakila-db/C6.ts +1 -1
- package/src/api/executors/HttpExecutor.ts +11 -5
- package/src/api/types/ormInterfaces.ts +2 -1
|
@@ -109,7 +109,7 @@ export interface iC6RestResponse<RestData> {
|
|
|
109
109
|
}
|
|
110
110
|
export interface iGetC6RestResponse<ResponseDataType extends {
|
|
111
111
|
[key: string]: any;
|
|
112
|
-
}, ResponseDataOverrides = {}> extends iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides>
|
|
112
|
+
}, ResponseDataOverrides = {}> extends iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides>[]> {
|
|
113
113
|
next?: () => Promise<DetermineResponseDataType<"GET", ResponseDataType, ResponseDataOverrides>>;
|
|
114
114
|
}
|
|
115
115
|
export type DetermineResponseDataType<Method extends iRestMethods, RestTableInterface extends {
|
package/dist/index.cjs.js
CHANGED
|
@@ -623,6 +623,122 @@ function sortAndSerializeQueryObject(tables, query) {
|
|
|
623
623
|
return tables + ' ' + JSON.stringify(orderedQuery);
|
|
624
624
|
}
|
|
625
625
|
|
|
626
|
+
/**
|
|
627
|
+
* Converts a singular T-shaped request into complex ORM format for GET/PUT/DELETE
|
|
628
|
+
* Enforces that all primary keys are present for singular syntax and that the table has PKs.
|
|
629
|
+
* Optionally accepts a previously removed primary key (key/value) to reconstruct WHERE.
|
|
630
|
+
*/
|
|
631
|
+
function normalizeSingularRequest(requestMethod, request, restModel, removedPrimary) {
|
|
632
|
+
var _a, _b;
|
|
633
|
+
var _c;
|
|
634
|
+
if (request == null || typeof request !== 'object')
|
|
635
|
+
return request;
|
|
636
|
+
var specialKeys = new Set([
|
|
637
|
+
C6Constants.SELECT,
|
|
638
|
+
C6Constants.UPDATE,
|
|
639
|
+
C6Constants.DELETE,
|
|
640
|
+
C6Constants.WHERE,
|
|
641
|
+
C6Constants.JOIN,
|
|
642
|
+
C6Constants.PAGINATION,
|
|
643
|
+
]);
|
|
644
|
+
// Determine if the request is already complex (has any special key besides PAGINATION)
|
|
645
|
+
var keys = Object.keys(request);
|
|
646
|
+
var hasComplexKeys = keys.some(function (k) { return k !== C6Constants.PAGINATION && specialKeys.has(k); });
|
|
647
|
+
if (hasComplexKeys)
|
|
648
|
+
return request; // already complex
|
|
649
|
+
// We treat it as singular when it's not complex.
|
|
650
|
+
// For GET, PUT, DELETE only
|
|
651
|
+
if (!(requestMethod === C6Constants.GET || requestMethod === C6Constants.PUT || requestMethod === C6Constants.DELETE)) {
|
|
652
|
+
return request;
|
|
653
|
+
}
|
|
654
|
+
var pkShorts = Array.isArray(restModel.PRIMARY_SHORT) ? tslib.__spreadArray([], restModel.PRIMARY_SHORT, true) : [];
|
|
655
|
+
var pkFulls = Array.isArray(restModel.PRIMARY) ? tslib.__spreadArray([], restModel.PRIMARY, true) : [];
|
|
656
|
+
var resolveShortKey = function (key) {
|
|
657
|
+
var _a;
|
|
658
|
+
var cols = restModel.COLUMNS || {};
|
|
659
|
+
return (_a = cols[key]) !== null && _a !== void 0 ? _a : key;
|
|
660
|
+
};
|
|
661
|
+
if (!pkShorts.length) {
|
|
662
|
+
// For GET requests, do not enforce primary key presence; treat as a collection query.
|
|
663
|
+
if (requestMethod === C6Constants.GET)
|
|
664
|
+
return request;
|
|
665
|
+
throw new Error("Table (".concat(restModel.TABLE_NAME, ") has no primary key; singular request syntax is not allowed."));
|
|
666
|
+
}
|
|
667
|
+
// Build pk map from request + possibly removed primary key (accept short or fully-qualified keys)
|
|
668
|
+
var pkValues = {};
|
|
669
|
+
var requestObj = request;
|
|
670
|
+
var _loop_1 = function (pkShort) {
|
|
671
|
+
// 1) direct short key
|
|
672
|
+
var value = requestObj[pkShort];
|
|
673
|
+
if (value === undefined) {
|
|
674
|
+
// 2) fully-qualified key matching this short key (from PRIMARY list or by concatenation)
|
|
675
|
+
var fqCandidate_1 = "".concat(restModel.TABLE_NAME, ".").concat(pkShort);
|
|
676
|
+
var fqKey = (_c = pkFulls.find(function (fq) { return fq === fqCandidate_1 || fq.endsWith(".".concat(pkShort)); })) !== null && _c !== void 0 ? _c : fqCandidate_1;
|
|
677
|
+
value = requestObj[fqKey];
|
|
678
|
+
}
|
|
679
|
+
if (value === undefined && removedPrimary) {
|
|
680
|
+
// 3) removedPrimary may provide either short or fully-qualified key
|
|
681
|
+
var removedKeyShort = resolveShortKey(removedPrimary.key);
|
|
682
|
+
if (removedKeyShort === pkShort)
|
|
683
|
+
value = removedPrimary.value;
|
|
684
|
+
}
|
|
685
|
+
if (value !== undefined && value !== null) {
|
|
686
|
+
pkValues[pkShort] = value;
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
for (var _i = 0, pkShorts_1 = pkShorts; _i < pkShorts_1.length; _i++) {
|
|
690
|
+
var pkShort = pkShorts_1[_i];
|
|
691
|
+
_loop_1(pkShort);
|
|
692
|
+
}
|
|
693
|
+
var missing = pkShorts.filter(function (pk) { return !(pk in pkValues); });
|
|
694
|
+
if (missing.length) {
|
|
695
|
+
// For GET requests, if not all PKs are provided, treat as a collection query and leave as-is.
|
|
696
|
+
if (requestMethod === C6Constants.GET) {
|
|
697
|
+
return request;
|
|
698
|
+
}
|
|
699
|
+
throw new Error("Singular request requires all primary key(s) [".concat(pkShorts.join(', '), "] for table (").concat(restModel.TABLE_NAME, "). Missing: [").concat(missing.join(', '), "]"));
|
|
700
|
+
}
|
|
701
|
+
// Strip API metadata that should remain at root
|
|
702
|
+
var _d = request, dataInsertMultipleRows = _d.dataInsertMultipleRows, cacheResults = _d.cacheResults, fetchDependencies = _d.fetchDependencies, debug = _d.debug, success = _d.success, error = _d.error, rest = tslib.__rest(_d, ["dataInsertMultipleRows", "cacheResults", "fetchDependencies", "debug", "success", "error"]);
|
|
703
|
+
if (requestMethod === C6Constants.GET) {
|
|
704
|
+
var normalized_1 = {
|
|
705
|
+
WHERE: tslib.__assign({}, pkValues),
|
|
706
|
+
};
|
|
707
|
+
// Preserve pagination if any was added previously
|
|
708
|
+
if (request[C6Constants.PAGINATION]) {
|
|
709
|
+
normalized_1[C6Constants.PAGINATION] = request[C6Constants.PAGINATION];
|
|
710
|
+
}
|
|
711
|
+
return tslib.__assign(tslib.__assign({}, normalized_1), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
712
|
+
}
|
|
713
|
+
if (requestMethod === C6Constants.DELETE) {
|
|
714
|
+
var normalized_2 = (_a = {},
|
|
715
|
+
_a[C6Constants.DELETE] = true,
|
|
716
|
+
_a.WHERE = tslib.__assign({}, pkValues),
|
|
717
|
+
_a);
|
|
718
|
+
return tslib.__assign(tslib.__assign({}, normalized_2), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
719
|
+
}
|
|
720
|
+
// PUT
|
|
721
|
+
var updateBody = {};
|
|
722
|
+
for (var _e = 0, _f = Object.keys(rest); _e < _f.length; _e++) {
|
|
723
|
+
var k = _f[_e];
|
|
724
|
+
// Skip special request keys if any slipped through
|
|
725
|
+
if (specialKeys.has(k))
|
|
726
|
+
continue;
|
|
727
|
+
var shortKey = resolveShortKey(k);
|
|
728
|
+
if (pkShorts.includes(shortKey))
|
|
729
|
+
continue; // don't update PK columns (short or fully qualified)
|
|
730
|
+
updateBody[shortKey] = rest[k];
|
|
731
|
+
}
|
|
732
|
+
if (Object.keys(updateBody).length === 0) {
|
|
733
|
+
throw new Error("Singular PUT request for table (".concat(restModel.TABLE_NAME, ") must include at least one non-primary field to update."));
|
|
734
|
+
}
|
|
735
|
+
var normalized = (_b = {},
|
|
736
|
+
_b[C6Constants.UPDATE] = updateBody,
|
|
737
|
+
_b.WHERE = tslib.__assign({}, pkValues),
|
|
738
|
+
_b);
|
|
739
|
+
return tslib.__assign(tslib.__assign({}, normalized), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
740
|
+
}
|
|
741
|
+
|
|
626
742
|
var HttpExecutor = /** @class */ (function (_super) {
|
|
627
743
|
tslib.__extends(HttpExecutor, _super);
|
|
628
744
|
function HttpExecutor() {
|
|
@@ -684,7 +800,6 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
684
800
|
switch (_b.label) {
|
|
685
801
|
case 0:
|
|
686
802
|
_a = this.config, C6 = _a.C6, axios = _a.axios, restURL = _a.restURL, withCredentials = _a.withCredentials, restModel = _a.restModel, reactBootstrap = _a.reactBootstrap, requestMethod = _a.requestMethod, skipPrimaryCheck = _a.skipPrimaryCheck, clearCache = _a.clearCache;
|
|
687
|
-
console.log('this.config', this.config);
|
|
688
803
|
return [4 /*yield*/, this.runLifecycleHooks("beforeProcessing", {
|
|
689
804
|
config: this.config,
|
|
690
805
|
request: this.request,
|
|
@@ -730,7 +845,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
730
845
|
query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
|
|
731
846
|
}
|
|
732
847
|
apiRequest = function () { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
733
|
-
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;
|
|
848
|
+
var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, querySerialized, cacheResult, cachingConfirmed, cacheCheck, cacheCheck, addBackPK, removedPrimaryKV, apiResponse, returnGetNextPageFunction, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKey, removedPkValue_1, axiosActiveRequest;
|
|
734
849
|
var _e;
|
|
735
850
|
var _this = this;
|
|
736
851
|
var _f, _g, _h, _j, _k, _l;
|
|
@@ -850,6 +965,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
850
965
|
&& primaryKey in query) {
|
|
851
966
|
restRequestUri += query[primaryKey] + '/';
|
|
852
967
|
removedPkValue_1 = query[primaryKey];
|
|
968
|
+
removedPrimaryKV = { key: primaryKey, value: removedPkValue_1 };
|
|
853
969
|
addBackPK = function () {
|
|
854
970
|
query !== null && query !== void 0 ? query : (query = {});
|
|
855
971
|
query[primaryKey] = removedPkValue_1;
|
|
@@ -878,8 +994,8 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
878
994
|
var baseConfig = {
|
|
879
995
|
withCredentials: withCredentials,
|
|
880
996
|
};
|
|
881
|
-
//
|
|
882
|
-
var normalizedQuery = query;
|
|
997
|
+
// Normalize singular request (GET/PUT/DELETE) into complex ORM shape
|
|
998
|
+
var normalizedQuery = normalizeSingularRequest(requestMethod, query, restModel, removedPrimaryKV);
|
|
883
999
|
switch (requestMethod) {
|
|
884
1000
|
case GET:
|
|
885
1001
|
return [tslib.__assign(tslib.__assign({}, baseConfig), { params: normalizedQuery })];
|
|
@@ -1082,7 +1198,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1082
1198
|
accumulator.push(row['entity_tag']);
|
|
1083
1199
|
}
|
|
1084
1200
|
return accumulator;
|
|
1085
|
-
}, []).map(function (entityTag) { return entityTag.split('\\').pop().toLowerCase(); });
|
|
1201
|
+
}, []).map(function (entityTag) { var _a, _b; return (_b = (_a = entityTag.split('\\')) === null || _a === void 0 ? void 0 : _a.pop()) === null || _b === void 0 ? void 0 : _b.toLowerCase(); });
|
|
1086
1202
|
var shouldContinue = referencesTables.find(function (referencesTable) { return tableToFetch.endsWith(referencesTable); });
|
|
1087
1203
|
if (!shouldContinue) {
|
|
1088
1204
|
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') did not end with any value in referencesTables', 'color: #c00', referencesTables);
|
|
@@ -1765,122 +1881,6 @@ var UpdateQueryBuilder = /** @class */ (function (_super) {
|
|
|
1765
1881
|
return UpdateQueryBuilder;
|
|
1766
1882
|
}(PaginationBuilder));
|
|
1767
1883
|
|
|
1768
|
-
/**
|
|
1769
|
-
* Converts a singular T-shaped request into complex ORM format for GET/PUT/DELETE
|
|
1770
|
-
* Enforces that all primary keys are present for singular syntax and that the table has PKs.
|
|
1771
|
-
* Optionally accepts a previously removed primary key (key/value) to reconstruct WHERE.
|
|
1772
|
-
*/
|
|
1773
|
-
function normalizeSingularRequest(requestMethod, request, restModel, removedPrimary) {
|
|
1774
|
-
var _a, _b;
|
|
1775
|
-
var _c;
|
|
1776
|
-
if (request == null || typeof request !== 'object')
|
|
1777
|
-
return request;
|
|
1778
|
-
var specialKeys = new Set([
|
|
1779
|
-
C6Constants.SELECT,
|
|
1780
|
-
C6Constants.UPDATE,
|
|
1781
|
-
C6Constants.DELETE,
|
|
1782
|
-
C6Constants.WHERE,
|
|
1783
|
-
C6Constants.JOIN,
|
|
1784
|
-
C6Constants.PAGINATION,
|
|
1785
|
-
]);
|
|
1786
|
-
// Determine if the request is already complex (has any special key besides PAGINATION)
|
|
1787
|
-
var keys = Object.keys(request);
|
|
1788
|
-
var hasComplexKeys = keys.some(function (k) { return k !== C6Constants.PAGINATION && specialKeys.has(k); });
|
|
1789
|
-
if (hasComplexKeys)
|
|
1790
|
-
return request; // already complex
|
|
1791
|
-
// We treat it as singular when it's not complex.
|
|
1792
|
-
// For GET, PUT, DELETE only
|
|
1793
|
-
if (!(requestMethod === C6Constants.GET || requestMethod === C6Constants.PUT || requestMethod === C6Constants.DELETE)) {
|
|
1794
|
-
return request;
|
|
1795
|
-
}
|
|
1796
|
-
var pkShorts = Array.isArray(restModel.PRIMARY_SHORT) ? tslib.__spreadArray([], restModel.PRIMARY_SHORT, true) : [];
|
|
1797
|
-
var pkFulls = Array.isArray(restModel.PRIMARY) ? tslib.__spreadArray([], restModel.PRIMARY, true) : [];
|
|
1798
|
-
var resolveShortKey = function (key) {
|
|
1799
|
-
var _a;
|
|
1800
|
-
var cols = restModel.COLUMNS || {};
|
|
1801
|
-
return (_a = cols[key]) !== null && _a !== void 0 ? _a : key;
|
|
1802
|
-
};
|
|
1803
|
-
if (!pkShorts.length) {
|
|
1804
|
-
// For GET requests, do not enforce primary key presence; treat as a collection query.
|
|
1805
|
-
if (requestMethod === C6Constants.GET)
|
|
1806
|
-
return request;
|
|
1807
|
-
throw new Error("Table (".concat(restModel.TABLE_NAME, ") has no primary key; singular request syntax is not allowed."));
|
|
1808
|
-
}
|
|
1809
|
-
// Build pk map from request + possibly removed primary key (accept short or fully-qualified keys)
|
|
1810
|
-
var pkValues = {};
|
|
1811
|
-
var requestObj = request;
|
|
1812
|
-
var _loop_1 = function (pkShort) {
|
|
1813
|
-
// 1) direct short key
|
|
1814
|
-
var value = requestObj[pkShort];
|
|
1815
|
-
if (value === undefined) {
|
|
1816
|
-
// 2) fully-qualified key matching this short key (from PRIMARY list or by concatenation)
|
|
1817
|
-
var fqCandidate_1 = "".concat(restModel.TABLE_NAME, ".").concat(pkShort);
|
|
1818
|
-
var fqKey = (_c = pkFulls.find(function (fq) { return fq === fqCandidate_1 || fq.endsWith(".".concat(pkShort)); })) !== null && _c !== void 0 ? _c : fqCandidate_1;
|
|
1819
|
-
value = requestObj[fqKey];
|
|
1820
|
-
}
|
|
1821
|
-
if (value === undefined && removedPrimary) {
|
|
1822
|
-
// 3) removedPrimary may provide either short or fully-qualified key
|
|
1823
|
-
var removedKeyShort = resolveShortKey(removedPrimary.key);
|
|
1824
|
-
if (removedKeyShort === pkShort)
|
|
1825
|
-
value = removedPrimary.value;
|
|
1826
|
-
}
|
|
1827
|
-
if (value !== undefined && value !== null) {
|
|
1828
|
-
pkValues[pkShort] = value;
|
|
1829
|
-
}
|
|
1830
|
-
};
|
|
1831
|
-
for (var _i = 0, pkShorts_1 = pkShorts; _i < pkShorts_1.length; _i++) {
|
|
1832
|
-
var pkShort = pkShorts_1[_i];
|
|
1833
|
-
_loop_1(pkShort);
|
|
1834
|
-
}
|
|
1835
|
-
var missing = pkShorts.filter(function (pk) { return !(pk in pkValues); });
|
|
1836
|
-
if (missing.length) {
|
|
1837
|
-
// For GET requests, if not all PKs are provided, treat as a collection query and leave as-is.
|
|
1838
|
-
if (requestMethod === C6Constants.GET) {
|
|
1839
|
-
return request;
|
|
1840
|
-
}
|
|
1841
|
-
throw new Error("Singular request requires all primary key(s) [".concat(pkShorts.join(', '), "] for table (").concat(restModel.TABLE_NAME, "). Missing: [").concat(missing.join(', '), "]"));
|
|
1842
|
-
}
|
|
1843
|
-
// Strip API metadata that should remain at root
|
|
1844
|
-
var _d = request, dataInsertMultipleRows = _d.dataInsertMultipleRows, cacheResults = _d.cacheResults, fetchDependencies = _d.fetchDependencies, debug = _d.debug, success = _d.success, error = _d.error, rest = tslib.__rest(_d, ["dataInsertMultipleRows", "cacheResults", "fetchDependencies", "debug", "success", "error"]);
|
|
1845
|
-
if (requestMethod === C6Constants.GET) {
|
|
1846
|
-
var normalized_1 = {
|
|
1847
|
-
WHERE: tslib.__assign({}, pkValues),
|
|
1848
|
-
};
|
|
1849
|
-
// Preserve pagination if any was added previously
|
|
1850
|
-
if (request[C6Constants.PAGINATION]) {
|
|
1851
|
-
normalized_1[C6Constants.PAGINATION] = request[C6Constants.PAGINATION];
|
|
1852
|
-
}
|
|
1853
|
-
return tslib.__assign(tslib.__assign({}, normalized_1), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
1854
|
-
}
|
|
1855
|
-
if (requestMethod === C6Constants.DELETE) {
|
|
1856
|
-
var normalized_2 = (_a = {},
|
|
1857
|
-
_a[C6Constants.DELETE] = true,
|
|
1858
|
-
_a.WHERE = tslib.__assign({}, pkValues),
|
|
1859
|
-
_a);
|
|
1860
|
-
return tslib.__assign(tslib.__assign({}, normalized_2), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
1861
|
-
}
|
|
1862
|
-
// PUT
|
|
1863
|
-
var updateBody = {};
|
|
1864
|
-
for (var _e = 0, _f = Object.keys(rest); _e < _f.length; _e++) {
|
|
1865
|
-
var k = _f[_e];
|
|
1866
|
-
// Skip special request keys if any slipped through
|
|
1867
|
-
if (specialKeys.has(k))
|
|
1868
|
-
continue;
|
|
1869
|
-
var shortKey = resolveShortKey(k);
|
|
1870
|
-
if (pkShorts.includes(shortKey))
|
|
1871
|
-
continue; // don't update PK columns (short or fully qualified)
|
|
1872
|
-
updateBody[shortKey] = rest[k];
|
|
1873
|
-
}
|
|
1874
|
-
if (Object.keys(updateBody).length === 0) {
|
|
1875
|
-
throw new Error("Singular PUT request for table (".concat(restModel.TABLE_NAME, ") must include at least one non-primary field to update."));
|
|
1876
|
-
}
|
|
1877
|
-
var normalized = (_b = {},
|
|
1878
|
-
_b[C6Constants.UPDATE] = updateBody,
|
|
1879
|
-
_b.WHERE = tslib.__assign({}, pkValues),
|
|
1880
|
-
_b);
|
|
1881
|
-
return tslib.__assign(tslib.__assign({}, normalized), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
1882
|
-
}
|
|
1883
|
-
|
|
1884
1884
|
var SqlExecutor = /** @class */ (function (_super) {
|
|
1885
1885
|
tslib.__extends(SqlExecutor, _super);
|
|
1886
1886
|
function SqlExecutor() {
|