@carbonorm/carbonnode 3.6.6 → 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 +106 -102
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +106 -103
- 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
|
@@ -839,7 +839,8 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
839
839
|
// A part of me exists that wants to remove this, but it's a good feature
|
|
840
840
|
// this allows developers the ability to cache requests based on primary key
|
|
841
841
|
// for tables like `photos` this can be a huge performance boost
|
|
842
|
-
if (
|
|
842
|
+
if (POST !== requestMethod
|
|
843
|
+
&& undefined !== query
|
|
843
844
|
&& null !== query
|
|
844
845
|
&& undefined !== primaryKey
|
|
845
846
|
&& primaryKey in query) {
|
|
@@ -905,11 +906,11 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
905
906
|
// returning the promise with this then is important for tests. todo - we could make that optional.
|
|
906
907
|
// https://rapidapi.com/guides/axios-async-await
|
|
907
908
|
return [2 /*return*/, axiosActiveRequest.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
908
|
-
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;
|
|
909
910
|
var _this = this;
|
|
910
|
-
var
|
|
911
|
-
return __generator(this, function (
|
|
912
|
-
switch (
|
|
911
|
+
var _a, _b, _c, _d, _e, _f;
|
|
912
|
+
return __generator(this, function (_g) {
|
|
913
|
+
switch (_g.label) {
|
|
913
914
|
case 0:
|
|
914
915
|
// noinspection SuspiciousTypeOfGuard
|
|
915
916
|
if (typeof response.data === 'string') {
|
|
@@ -968,12 +969,12 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
968
969
|
else {
|
|
969
970
|
callback();
|
|
970
971
|
}
|
|
971
|
-
if (!(C6.GET === requestMethod)) return [3 /*break*/,
|
|
972
|
+
if (!(C6.GET === requestMethod)) return [3 /*break*/, 2];
|
|
972
973
|
responseData_1 = response.data;
|
|
973
|
-
returnGetNextPageFunction = 1 !== ((
|
|
974
|
-
((
|
|
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;
|
|
975
976
|
if (false === isTest() || this.config.verbose) {
|
|
976
|
-
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');
|
|
977
978
|
console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
|
|
978
979
|
console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', this.request);
|
|
979
980
|
console.log('%c Response Data:', 'color: #0c0', responseData_1.rest);
|
|
@@ -988,12 +989,12 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
988
989
|
responseData_1.next = undefined;
|
|
989
990
|
if (true === debug
|
|
990
991
|
&& isLocal()) {
|
|
991
|
-
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);
|
|
992
993
|
}
|
|
993
994
|
}
|
|
994
995
|
if (!(fetchDependencies
|
|
995
996
|
&& 'number' === typeof fetchDependencies
|
|
996
|
-
&& responseData_1.rest.length > 0)) return [3 /*break*/,
|
|
997
|
+
&& responseData_1.rest.length > 0)) return [3 /*break*/, 2];
|
|
997
998
|
console.groupCollapsed('%c API: Fetch Dependencies segment (' + requestMethod + ' ' + tableName + ')'
|
|
998
999
|
+ (fetchDependencies & eFetchDependencies.CHILDREN ? ' | (CHILDREN|REFERENCED) ' : '')
|
|
999
1000
|
+ (fetchDependencies & eFetchDependencies.PARENTS ? ' | (PARENTS|REFERENCED_BY)' : '')
|
|
@@ -1064,97 +1065,73 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1064
1065
|
}); });
|
|
1065
1066
|
console.log('fetchReferences', fetchReferences_1);
|
|
1066
1067
|
_loop_1 = function (tableToFetch) {
|
|
1067
|
-
var
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') did not end with any value in referencesTables', 'color: #c00', referencesTables);
|
|
1084
|
-
return [2 /*return*/, "continue"];
|
|
1085
|
-
}
|
|
1086
|
-
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') will be fetched.', 'color: #0c0');
|
|
1087
|
-
}
|
|
1088
|
-
return [4 /*yield*/, C6.IMPORT(tableToFetch)];
|
|
1089
|
-
case 1:
|
|
1090
|
-
fetchTable = _m.sent();
|
|
1091
|
-
RestApi = fetchTable.default;
|
|
1092
|
-
console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
|
|
1093
|
-
nextFetchDependencies = eFetchDependencies.NONE;
|
|
1094
|
-
if (fetchDependencies & eFetchDependencies.RECURSIVE) {
|
|
1095
|
-
if (fetchDependencies & eFetchDependencies.ALL) {
|
|
1096
|
-
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.');
|
|
1097
|
-
}
|
|
1098
|
-
nextFetchDependencies = fetchDependencies;
|
|
1099
|
-
}
|
|
1100
|
-
else if (fetchDependencies & eFetchDependencies.C6ENTITY) {
|
|
1101
|
-
if (tableToFetch === "carbon_carbons") {
|
|
1102
|
-
nextFetchDependencies = fetchDependencies;
|
|
1103
|
-
}
|
|
1104
|
-
else {
|
|
1105
|
-
nextFetchDependencies = fetchDependencies ^ eFetchDependencies.C6ENTITY;
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
console.log('fetchReferences', fetchReferences_1[tableToFetch], "Current fetchDependencies for (" + operatingTable + "):", fetchDependencies, "New fetchDependencies for (" + tableToFetch + "): ", nextFetchDependencies);
|
|
1109
|
-
// 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
|
|
1110
|
-
// it not certain that they are using carbons' entities either
|
|
1111
|
-
// this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
|
|
1112
|
-
// todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
|
|
1113
|
-
apiRequestPromises.push(RestApi.Get((_l = {},
|
|
1114
|
-
_l[C6.WHERE] = {
|
|
1115
|
-
0: Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
|
|
1116
|
-
fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
|
|
1117
|
-
if (0 === fetchReferences_1[tableToFetch][column].length) {
|
|
1118
|
-
console.warn('The column (' + column + ') was not found in the response data. We will not fetch.', responseData_1);
|
|
1119
|
-
return false;
|
|
1120
|
-
}
|
|
1121
|
-
sum[column] = fetchReferences_1[tableToFetch][column].length === 1
|
|
1122
|
-
? fetchReferences_1[tableToFetch][column][0]
|
|
1123
|
-
: [
|
|
1124
|
-
C6.IN, fetchReferences_1[tableToFetch][column]
|
|
1125
|
-
];
|
|
1126
|
-
return sum;
|
|
1127
|
-
}, {})
|
|
1128
|
-
},
|
|
1129
|
-
_l.fetchDependencies = nextFetchDependencies,
|
|
1130
|
-
_l)));
|
|
1131
|
-
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";
|
|
1132
1084
|
}
|
|
1133
|
-
|
|
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)));
|
|
1134
1127
|
};
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
_b.push(_c);
|
|
1139
|
-
_i = 0;
|
|
1140
|
-
_k.label = 1;
|
|
1141
|
-
case 1:
|
|
1142
|
-
if (!(_i < _b.length)) return [3 /*break*/, 4];
|
|
1143
|
-
_c = _b[_i];
|
|
1144
|
-
if (!(_c in _a)) return [3 /*break*/, 3];
|
|
1145
|
-
tableToFetch = _c;
|
|
1146
|
-
return [5 /*yield**/, _loop_1(tableToFetch)];
|
|
1147
|
-
case 2:
|
|
1148
|
-
_k.sent();
|
|
1149
|
-
_k.label = 3;
|
|
1150
|
-
case 3:
|
|
1151
|
-
_i++;
|
|
1152
|
-
return [3 /*break*/, 1];
|
|
1153
|
-
case 4:
|
|
1128
|
+
for (tableToFetch in fetchReferences_1) {
|
|
1129
|
+
_loop_1(tableToFetch);
|
|
1130
|
+
}
|
|
1154
1131
|
console.groupEnd();
|
|
1155
1132
|
return [4 /*yield*/, Promise.all(apiRequestPromises)];
|
|
1156
|
-
case
|
|
1157
|
-
|
|
1133
|
+
case 1:
|
|
1134
|
+
_g.sent();
|
|
1158
1135
|
apiRequestPromises.map(function (promise) { return __awaiter(_this, void 0, void 0, function () {
|
|
1159
1136
|
var _a, _b;
|
|
1160
1137
|
return __generator(this, function (_c) {
|
|
@@ -1172,8 +1149,8 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1172
1149
|
}
|
|
1173
1150
|
});
|
|
1174
1151
|
}); });
|
|
1175
|
-
|
|
1176
|
-
case
|
|
1152
|
+
_g.label = 2;
|
|
1153
|
+
case 2:
|
|
1177
1154
|
if (debug && isLocal()) {
|
|
1178
1155
|
toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
|
|
1179
1156
|
}
|
|
@@ -1275,7 +1252,16 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
1275
1252
|
C6C.IS, C6C.IS_NOT,
|
|
1276
1253
|
C6C.BETWEEN, 'NOT BETWEEN',
|
|
1277
1254
|
C6C.MATCH_AGAINST,
|
|
1278
|
-
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
|
|
1279
1265
|
]);
|
|
1280
1266
|
return _this;
|
|
1281
1267
|
}
|
|
@@ -1357,6 +1343,19 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
1357
1343
|
var threshold = Array.isArray(value) ? value[0] : value;
|
|
1358
1344
|
return "ST_Distance_Sphere(".concat(col1, ", ").concat(col2, ") < ").concat(_this.addParam(params, '', threshold));
|
|
1359
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
|
+
}
|
|
1360
1359
|
}
|
|
1361
1360
|
var leftIsCol = _this.isColumnRef(column);
|
|
1362
1361
|
var leftIsRef = _this.isTableReference(column);
|
|
@@ -1921,7 +1920,7 @@ function ExpressHandler(_a) {
|
|
|
1921
1920
|
payload[C6C.WHERE][primaryKeyName] = primary;
|
|
1922
1921
|
}
|
|
1923
1922
|
else {
|
|
1924
|
-
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, ").") });
|
|
1925
1924
|
}
|
|
1926
1925
|
break;
|
|
1927
1926
|
case 'POST':
|
|
@@ -1970,6 +1969,10 @@ var fieldEq = function (leftCol, rightCol, leftAlias, rightAlias) {
|
|
|
1970
1969
|
var distSphere = function (fromCol, toCol, fromAlias, toAlias) {
|
|
1971
1970
|
return [C6C.ST_DISTANCE_SPHERE, F(fromCol, fromAlias), F(toCol, toAlias)];
|
|
1972
1971
|
};
|
|
1972
|
+
// ST_Contains for map envelope/shape queries
|
|
1973
|
+
var stContains = function (envelope, shape) {
|
|
1974
|
+
return [C6C.ST_CONTAINS, envelope, shape];
|
|
1975
|
+
};
|
|
1973
1976
|
|
|
1974
1977
|
function determineRuntimeJsType(mysqlType) {
|
|
1975
1978
|
var base = mysqlType.toLowerCase().split('(')[0];
|
|
@@ -2070,5 +2073,5 @@ function isVerbose () {
|
|
|
2070
2073
|
return ['true', '1', 'yes', 'on'].includes(envVerbose.toLowerCase());
|
|
2071
2074
|
}
|
|
2072
2075
|
|
|
2073
|
-
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 };
|
|
2074
2077
|
//# sourceMappingURL=index.esm.js.map
|