@carbonorm/carbonnode 3.6.7 → 3.7.0
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/README.md +15 -0
- package/dist/api/orm/queryHelpers.d.ts +1 -0
- package/dist/api/types/ormInterfaces.d.ts +4 -1
- package/dist/index.cjs.js +104 -101
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +104 -102
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -2
- package/scripts/assets/handlebars/C6.ts.handlebars +4 -35
- package/scripts/generateRestBindings.cjs +1 -1
- package/scripts/generateRestBindings.ts +1 -1
- package/scripts/setup-git-hooks.mjs +77 -0
- package/scripts/test-hooks.sh +34 -0
- package/src/api/C6Constants.ts +1 -0
- package/src/api/executors/HttpExecutor.ts +1 -3
- package/src/api/handlers/ExpressHandler.ts +1 -1
- package/src/api/orm/builders/ConditionBuilder.ts +23 -1
- package/src/api/orm/queryHelpers.ts +16 -0
- package/src/api/types/ormInterfaces.ts +6 -2
package/dist/index.esm.js
CHANGED
|
@@ -906,11 +906,11 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
906
906
|
// returning the promise with this then is important for tests. todo - we could make that optional.
|
|
907
907
|
// https://rapidapi.com/guides/axios-async-await
|
|
908
908
|
return [2 /*return*/, axiosActiveRequest.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
909
|
-
var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1,
|
|
909
|
+
var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, tableToFetch;
|
|
910
910
|
var _this = this;
|
|
911
|
-
var
|
|
912
|
-
return __generator(this, function (
|
|
913
|
-
switch (
|
|
911
|
+
var _a, _b, _c, _d, _e, _f;
|
|
912
|
+
return __generator(this, function (_g) {
|
|
913
|
+
switch (_g.label) {
|
|
914
914
|
case 0:
|
|
915
915
|
// noinspection SuspiciousTypeOfGuard
|
|
916
916
|
if (typeof response.data === 'string') {
|
|
@@ -969,12 +969,12 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
969
969
|
else {
|
|
970
970
|
callback();
|
|
971
971
|
}
|
|
972
|
-
if (!(C6.GET === requestMethod)) return [3 /*break*/,
|
|
972
|
+
if (!(C6.GET === requestMethod)) return [3 /*break*/, 2];
|
|
973
973
|
responseData_1 = response.data;
|
|
974
|
-
returnGetNextPageFunction = 1 !== ((
|
|
975
|
-
((
|
|
974
|
+
returnGetNextPageFunction = 1 !== ((_a = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _a === void 0 ? void 0 : _a[C6.LIMIT]) &&
|
|
975
|
+
((_b = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _b === void 0 ? void 0 : _b[C6.LIMIT]) === responseData_1.rest.length;
|
|
976
976
|
if (false === isTest() || this.config.verbose) {
|
|
977
|
-
console.groupCollapsed('%c API: Response (' + requestMethod + ' ' + tableName + ') returned length (' + ((
|
|
977
|
+
console.groupCollapsed('%c API: Response (' + requestMethod + ' ' + tableName + ') returned length (' + ((_c = responseData_1.rest) === null || _c === void 0 ? void 0 : _c.length) + ') of possible (' + ((_d = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _d === void 0 ? void 0 : _d[C6.LIMIT]) + ') limit!', 'color: #0c0');
|
|
978
978
|
console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
|
|
979
979
|
console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', this.request);
|
|
980
980
|
console.log('%c Response Data:', 'color: #0c0', responseData_1.rest);
|
|
@@ -989,12 +989,12 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
989
989
|
responseData_1.next = undefined;
|
|
990
990
|
if (true === debug
|
|
991
991
|
&& isLocal()) {
|
|
992
|
-
toast.success("DEVS: Response returned length (" + ((
|
|
992
|
+
toast.success("DEVS: Response returned length (" + ((_e = responseData_1.rest) === null || _e === void 0 ? void 0 : _e.length) + ") less than limit (" + ((_f = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _f === void 0 ? void 0 : _f[C6.LIMIT]) + ").", toastOptionsDevs);
|
|
993
993
|
}
|
|
994
994
|
}
|
|
995
995
|
if (!(fetchDependencies
|
|
996
996
|
&& 'number' === typeof fetchDependencies
|
|
997
|
-
&& responseData_1.rest.length > 0)) return [3 /*break*/,
|
|
997
|
+
&& responseData_1.rest.length > 0)) return [3 /*break*/, 2];
|
|
998
998
|
console.groupCollapsed('%c API: Fetch Dependencies segment (' + requestMethod + ' ' + tableName + ')'
|
|
999
999
|
+ (fetchDependencies & eFetchDependencies.CHILDREN ? ' | (CHILDREN|REFERENCED) ' : '')
|
|
1000
1000
|
+ (fetchDependencies & eFetchDependencies.PARENTS ? ' | (PARENTS|REFERENCED_BY)' : '')
|
|
@@ -1065,97 +1065,73 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1065
1065
|
}); });
|
|
1066
1066
|
console.log('fetchReferences', fetchReferences_1);
|
|
1067
1067
|
_loop_1 = function (tableToFetch) {
|
|
1068
|
-
var
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') did not end with any value in referencesTables', 'color: #c00', referencesTables);
|
|
1085
|
-
return [2 /*return*/, "continue"];
|
|
1086
|
-
}
|
|
1087
|
-
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') will be fetched.', 'color: #0c0');
|
|
1088
|
-
}
|
|
1089
|
-
return [4 /*yield*/, C6.IMPORT(tableToFetch)];
|
|
1090
|
-
case 1:
|
|
1091
|
-
fetchTable = _m.sent();
|
|
1092
|
-
RestApi = fetchTable.default;
|
|
1093
|
-
console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
|
|
1094
|
-
nextFetchDependencies = eFetchDependencies.NONE;
|
|
1095
|
-
if (fetchDependencies & eFetchDependencies.RECURSIVE) {
|
|
1096
|
-
if (fetchDependencies & eFetchDependencies.ALL) {
|
|
1097
|
-
throw Error('Recursive fetch dependencies with both PARENT and CHILD reference will result in an infin1ite loop. As there is not real ending condition, this is not supported.');
|
|
1098
|
-
}
|
|
1099
|
-
nextFetchDependencies = fetchDependencies;
|
|
1100
|
-
}
|
|
1101
|
-
else if (fetchDependencies & eFetchDependencies.C6ENTITY) {
|
|
1102
|
-
if (tableToFetch === "carbon_carbons") {
|
|
1103
|
-
nextFetchDependencies = fetchDependencies;
|
|
1104
|
-
}
|
|
1105
|
-
else {
|
|
1106
|
-
nextFetchDependencies = fetchDependencies ^ eFetchDependencies.C6ENTITY;
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
console.log('fetchReferences', fetchReferences_1[tableToFetch], "Current fetchDependencies for (" + operatingTable + "):", fetchDependencies, "New fetchDependencies for (" + tableToFetch + "): ", nextFetchDependencies);
|
|
1110
|
-
// todo - filter out ids that exist in state?!? note - remember that this does not necessarily mean the pk, but only known is its an FK to somewhere
|
|
1111
|
-
// it not certain that they are using carbons' entities either
|
|
1112
|
-
// this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
|
|
1113
|
-
// todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
|
|
1114
|
-
apiRequestPromises.push(RestApi.Get((_l = {},
|
|
1115
|
-
_l[C6.WHERE] = {
|
|
1116
|
-
0: Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
|
|
1117
|
-
fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
|
|
1118
|
-
if (0 === fetchReferences_1[tableToFetch][column].length) {
|
|
1119
|
-
console.warn('The column (' + column + ') was not found in the response data. We will not fetch.', responseData_1);
|
|
1120
|
-
return false;
|
|
1121
|
-
}
|
|
1122
|
-
sum[column] = fetchReferences_1[tableToFetch][column].length === 1
|
|
1123
|
-
? fetchReferences_1[tableToFetch][column][0]
|
|
1124
|
-
: [
|
|
1125
|
-
C6.IN, fetchReferences_1[tableToFetch][column]
|
|
1126
|
-
];
|
|
1127
|
-
return sum;
|
|
1128
|
-
}, {})
|
|
1129
|
-
},
|
|
1130
|
-
_l.fetchDependencies = nextFetchDependencies,
|
|
1131
|
-
_l)));
|
|
1132
|
-
return [2 /*return*/];
|
|
1068
|
+
var _h;
|
|
1069
|
+
if (fetchDependencies & eFetchDependencies.C6ENTITY
|
|
1070
|
+
&& 'string' === typeof tableName
|
|
1071
|
+
&& tableName.endsWith("carbon_carbons")) {
|
|
1072
|
+
// todo - rethink the table ref entity system - when tables are renamed? no hooks exist in mysql
|
|
1073
|
+
// since were already filtering on column, we can assume the first row constraint is the same as the rest
|
|
1074
|
+
var referencesTables = responseData_1.rest.reduce(function (accumulator, row) {
|
|
1075
|
+
if ('entity_tag' in row && !accumulator.includes(row['entity_tag'])) {
|
|
1076
|
+
accumulator.push(row['entity_tag']);
|
|
1077
|
+
}
|
|
1078
|
+
return accumulator;
|
|
1079
|
+
}, []).map(function (entityTag) { return entityTag.split('\\').pop().toLowerCase(); });
|
|
1080
|
+
var shouldContinue = referencesTables.find(function (referencesTable) { return tableToFetch.endsWith(referencesTable); });
|
|
1081
|
+
if (!shouldContinue) {
|
|
1082
|
+
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') did not end with any value in referencesTables', 'color: #c00', referencesTables);
|
|
1083
|
+
return "continue";
|
|
1133
1084
|
}
|
|
1134
|
-
|
|
1085
|
+
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') will be fetched.', 'color: #0c0');
|
|
1086
|
+
}
|
|
1087
|
+
var RestApi = C6.ORM[tableToFetch];
|
|
1088
|
+
console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
|
|
1089
|
+
var nextFetchDependencies = eFetchDependencies.NONE;
|
|
1090
|
+
if (fetchDependencies & eFetchDependencies.RECURSIVE) {
|
|
1091
|
+
if (fetchDependencies & eFetchDependencies.ALL) {
|
|
1092
|
+
throw Error('Recursive fetch dependencies with both PARENT and CHILD reference will result in an infin1ite loop. As there is not real ending condition, this is not supported.');
|
|
1093
|
+
}
|
|
1094
|
+
nextFetchDependencies = fetchDependencies;
|
|
1095
|
+
}
|
|
1096
|
+
else if (fetchDependencies & eFetchDependencies.C6ENTITY) {
|
|
1097
|
+
if (tableToFetch === "carbon_carbons") {
|
|
1098
|
+
nextFetchDependencies = fetchDependencies;
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
nextFetchDependencies = fetchDependencies ^ eFetchDependencies.C6ENTITY;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
console.log('fetchReferences', fetchReferences_1[tableToFetch], "Current fetchDependencies for (" + operatingTable + "):", fetchDependencies, "New fetchDependencies for (" + tableToFetch + "): ", nextFetchDependencies);
|
|
1105
|
+
// todo - filter out ids that exist in state?!? note - remember that this does not necessarily mean the pk, but only known is its an FK to somewhere
|
|
1106
|
+
// it not certain that they are using carbons' entities either
|
|
1107
|
+
// this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
|
|
1108
|
+
// todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
|
|
1109
|
+
apiRequestPromises.push(RestApi.Get((_h = {},
|
|
1110
|
+
_h[C6.WHERE] = {
|
|
1111
|
+
0: Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
|
|
1112
|
+
fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
|
|
1113
|
+
if (0 === fetchReferences_1[tableToFetch][column].length) {
|
|
1114
|
+
console.warn('The column (' + column + ') was not found in the response data. We will not fetch.', responseData_1);
|
|
1115
|
+
return false;
|
|
1116
|
+
}
|
|
1117
|
+
sum[column] = fetchReferences_1[tableToFetch][column].length === 1
|
|
1118
|
+
? fetchReferences_1[tableToFetch][column][0]
|
|
1119
|
+
: [
|
|
1120
|
+
C6.IN, fetchReferences_1[tableToFetch][column]
|
|
1121
|
+
];
|
|
1122
|
+
return sum;
|
|
1123
|
+
}, {})
|
|
1124
|
+
},
|
|
1125
|
+
_h.fetchDependencies = nextFetchDependencies,
|
|
1126
|
+
_h)));
|
|
1135
1127
|
};
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
_b.push(_c);
|
|
1140
|
-
_i = 0;
|
|
1141
|
-
_k.label = 1;
|
|
1142
|
-
case 1:
|
|
1143
|
-
if (!(_i < _b.length)) return [3 /*break*/, 4];
|
|
1144
|
-
_c = _b[_i];
|
|
1145
|
-
if (!(_c in _a)) return [3 /*break*/, 3];
|
|
1146
|
-
tableToFetch = _c;
|
|
1147
|
-
return [5 /*yield**/, _loop_1(tableToFetch)];
|
|
1148
|
-
case 2:
|
|
1149
|
-
_k.sent();
|
|
1150
|
-
_k.label = 3;
|
|
1151
|
-
case 3:
|
|
1152
|
-
_i++;
|
|
1153
|
-
return [3 /*break*/, 1];
|
|
1154
|
-
case 4:
|
|
1128
|
+
for (tableToFetch in fetchReferences_1) {
|
|
1129
|
+
_loop_1(tableToFetch);
|
|
1130
|
+
}
|
|
1155
1131
|
console.groupEnd();
|
|
1156
1132
|
return [4 /*yield*/, Promise.all(apiRequestPromises)];
|
|
1157
|
-
case
|
|
1158
|
-
|
|
1133
|
+
case 1:
|
|
1134
|
+
_g.sent();
|
|
1159
1135
|
apiRequestPromises.map(function (promise) { return __awaiter(_this, void 0, void 0, function () {
|
|
1160
1136
|
var _a, _b;
|
|
1161
1137
|
return __generator(this, function (_c) {
|
|
@@ -1173,8 +1149,8 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1173
1149
|
}
|
|
1174
1150
|
});
|
|
1175
1151
|
}); });
|
|
1176
|
-
|
|
1177
|
-
case
|
|
1152
|
+
_g.label = 2;
|
|
1153
|
+
case 2:
|
|
1178
1154
|
if (debug && isLocal()) {
|
|
1179
1155
|
toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
|
|
1180
1156
|
}
|
|
@@ -1276,7 +1252,16 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
1276
1252
|
C6C.IS, C6C.IS_NOT,
|
|
1277
1253
|
C6C.BETWEEN, 'NOT BETWEEN',
|
|
1278
1254
|
C6C.MATCH_AGAINST,
|
|
1279
|
-
C6C.ST_DISTANCE_SPHERE
|
|
1255
|
+
C6C.ST_DISTANCE_SPHERE,
|
|
1256
|
+
// spatial predicates
|
|
1257
|
+
C6C.ST_CONTAINS,
|
|
1258
|
+
C6C.ST_INTERSECTS,
|
|
1259
|
+
C6C.ST_WITHIN,
|
|
1260
|
+
C6C.ST_CROSSES,
|
|
1261
|
+
C6C.ST_DISJOINT,
|
|
1262
|
+
C6C.ST_EQUALS,
|
|
1263
|
+
C6C.ST_OVERLAPS,
|
|
1264
|
+
C6C.ST_TOUCHES
|
|
1280
1265
|
]);
|
|
1281
1266
|
return _this;
|
|
1282
1267
|
}
|
|
@@ -1358,6 +1343,19 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
1358
1343
|
var threshold = Array.isArray(value) ? value[0] : value;
|
|
1359
1344
|
return "ST_Distance_Sphere(".concat(col1, ", ").concat(col2, ") < ").concat(_this.addParam(params, '', threshold));
|
|
1360
1345
|
}
|
|
1346
|
+
if ([
|
|
1347
|
+
C6C.ST_CONTAINS,
|
|
1348
|
+
C6C.ST_INTERSECTS,
|
|
1349
|
+
C6C.ST_WITHIN,
|
|
1350
|
+
C6C.ST_CROSSES,
|
|
1351
|
+
C6C.ST_DISJOINT,
|
|
1352
|
+
C6C.ST_EQUALS,
|
|
1353
|
+
C6C.ST_OVERLAPS,
|
|
1354
|
+
C6C.ST_TOUCHES
|
|
1355
|
+
].includes(column)) {
|
|
1356
|
+
var geom1 = op[0], geom2 = op[1];
|
|
1357
|
+
return "".concat(column, "(").concat(geom1, ", ").concat(geom2, ")");
|
|
1358
|
+
}
|
|
1361
1359
|
}
|
|
1362
1360
|
var leftIsCol = _this.isColumnRef(column);
|
|
1363
1361
|
var leftIsRef = _this.isTableReference(column);
|
|
@@ -1922,7 +1920,7 @@ function ExpressHandler(_a) {
|
|
|
1922
1920
|
payload[C6C.WHERE][primaryKeyName] = primary;
|
|
1923
1921
|
}
|
|
1924
1922
|
else {
|
|
1925
|
-
res.status(400).json({ error: "Invalid request: ".concat(method, " requires a primary key.") });
|
|
1923
|
+
res.status(400).json({ error: "Invalid request: ".concat(method, " requires a primary key (").concat(primaryKeyName, ").") });
|
|
1926
1924
|
}
|
|
1927
1925
|
break;
|
|
1928
1926
|
case 'POST':
|
|
@@ -1971,6 +1969,10 @@ var fieldEq = function (leftCol, rightCol, leftAlias, rightAlias) {
|
|
|
1971
1969
|
var distSphere = function (fromCol, toCol, fromAlias, toAlias) {
|
|
1972
1970
|
return [C6C.ST_DISTANCE_SPHERE, F(fromCol, fromAlias), F(toCol, toAlias)];
|
|
1973
1971
|
};
|
|
1972
|
+
// ST_Contains for map envelope/shape queries
|
|
1973
|
+
var stContains = function (envelope, shape) {
|
|
1974
|
+
return [C6C.ST_CONTAINS, envelope, shape];
|
|
1975
|
+
};
|
|
1974
1976
|
|
|
1975
1977
|
function determineRuntimeJsType(mysqlType) {
|
|
1976
1978
|
var base = mysqlType.toLowerCase().split('(')[0];
|
|
@@ -2071,5 +2073,5 @@ function isVerbose () {
|
|
|
2071
2073
|
return ['true', '1', 'yes', 'on'].includes(envVerbose.toLowerCase());
|
|
2072
2074
|
}
|
|
2073
2075
|
|
|
2074
|
-
export { A, AggregateBuilder, C6C, C6Constants, ConditionBuilder, DELETE, DeleteQueryBuilder, Executor, ExpressHandler, F, GET, HttpExecutor, JoinBuilder, POST, PUT, PaginationBuilder, PostQueryBuilder, SelectQueryBuilder, SqlExecutor, TestRestfulResponse, UpdateQueryBuilder, apiRequestCache, axiosInstance, checkAllRequestsComplete, checkCache, clearCache, convertForRequestBody, convertHexIfBinary, determineRuntimeJsType, distSphere, eFetchDependencies, error, fieldEq, getEnvVar, getPrimaryKeyTypes, group, info, isLocal, isNode, isTest, isVerbose, onError, onSuccess, removeInvalidKeys, removePrefixIfExists, restOrm, restRequest, sortAndSerializeQueryObject, timeout, toastOptions, toastOptionsDevs, userCustomClearCache, warn };
|
|
2076
|
+
export { A, AggregateBuilder, C6C, C6Constants, ConditionBuilder, DELETE, DeleteQueryBuilder, Executor, ExpressHandler, F, GET, HttpExecutor, JoinBuilder, POST, PUT, PaginationBuilder, PostQueryBuilder, SelectQueryBuilder, SqlExecutor, TestRestfulResponse, UpdateQueryBuilder, apiRequestCache, axiosInstance, checkAllRequestsComplete, checkCache, clearCache, convertForRequestBody, convertHexIfBinary, determineRuntimeJsType, distSphere, eFetchDependencies, error, fieldEq, getEnvVar, getPrimaryKeyTypes, group, info, isLocal, isNode, isTest, isVerbose, onError, onSuccess, removeInvalidKeys, removePrefixIfExists, restOrm, restRequest, sortAndSerializeQueryObject, stContains, timeout, toastOptions, toastOptionsDevs, userCustomClearCache, warn };
|
|
2075
2077
|
//# sourceMappingURL=index.esm.js.map
|