@carbonorm/carbonnode 3.6.7 → 3.7.1

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.esm.js CHANGED
@@ -109,6 +109,7 @@ var C6Constants = {
109
109
  ST_GEOMFROMWKB: 'ST_GeomFromWKB',
110
110
  ST_INTERSECTS: 'ST_Intersects',
111
111
  ST_LENGTH: 'ST_Length',
112
+ ST_MAKEENVELOPE: 'ST_MakeEnvelope',
112
113
  ST_OVERLAPS: 'ST_Overlaps',
113
114
  ST_POINT: 'ST_Point',
114
115
  ST_SETSRID: 'ST_SetSRID',
@@ -906,11 +907,11 @@ var HttpExecutor = /** @class */ (function (_super) {
906
907
  // returning the promise with this then is important for tests. todo - we could make that optional.
907
908
  // https://rapidapi.com/guides/axios-async-await
908
909
  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, _a, _b, _c, _i, tableToFetch;
910
+ var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, tableToFetch;
910
911
  var _this = this;
911
- var _d, _e, _f, _g, _h, _j;
912
- return __generator(this, function (_k) {
913
- switch (_k.label) {
912
+ var _a, _b, _c, _d, _e, _f, _g;
913
+ return __generator(this, function (_h) {
914
+ switch (_h.label) {
914
915
  case 0:
915
916
  // noinspection SuspiciousTypeOfGuard
916
917
  if (typeof response.data === 'string') {
@@ -969,12 +970,12 @@ var HttpExecutor = /** @class */ (function (_super) {
969
970
  else {
970
971
  callback();
971
972
  }
972
- if (!(C6.GET === requestMethod)) return [3 /*break*/, 6];
973
+ if (!(C6.GET === requestMethod)) return [3 /*break*/, 2];
973
974
  responseData_1 = response.data;
974
- returnGetNextPageFunction = 1 !== ((_d = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _d === void 0 ? void 0 : _d[C6.LIMIT]) &&
975
- ((_e = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _e === void 0 ? void 0 : _e[C6.LIMIT]) === responseData_1.rest.length;
975
+ returnGetNextPageFunction = 1 !== ((_a = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _a === void 0 ? void 0 : _a[C6.LIMIT]) &&
976
+ ((_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
977
  if (false === isTest() || this.config.verbose) {
977
- console.groupCollapsed('%c API: Response (' + requestMethod + ' ' + tableName + ') returned length (' + ((_f = responseData_1.rest) === null || _f === void 0 ? void 0 : _f.length) + ') of possible (' + ((_g = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _g === void 0 ? void 0 : _g[C6.LIMIT]) + ') limit!', 'color: #0c0');
978
+ 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
979
  console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
979
980
  console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', this.request);
980
981
  console.log('%c Response Data:', 'color: #0c0', responseData_1.rest);
@@ -989,12 +990,12 @@ var HttpExecutor = /** @class */ (function (_super) {
989
990
  responseData_1.next = undefined;
990
991
  if (true === debug
991
992
  && isLocal()) {
992
- toast.success("DEVS: Response returned length (" + ((_h = responseData_1.rest) === null || _h === void 0 ? void 0 : _h.length) + ") less than limit (" + ((_j = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _j === void 0 ? void 0 : _j[C6.LIMIT]) + ").", toastOptionsDevs);
993
+ 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
994
  }
994
995
  }
995
996
  if (!(fetchDependencies
996
997
  && 'number' === typeof fetchDependencies
997
- && responseData_1.rest.length > 0)) return [3 /*break*/, 6];
998
+ && responseData_1.rest.length > 0)) return [3 /*break*/, 2];
998
999
  console.groupCollapsed('%c API: Fetch Dependencies segment (' + requestMethod + ' ' + tableName + ')'
999
1000
  + (fetchDependencies & eFetchDependencies.CHILDREN ? ' | (CHILDREN|REFERENCED) ' : '')
1000
1001
  + (fetchDependencies & eFetchDependencies.PARENTS ? ' | (PARENTS|REFERENCED_BY)' : '')
@@ -1065,97 +1066,77 @@ var HttpExecutor = /** @class */ (function (_super) {
1065
1066
  }); });
1066
1067
  console.log('fetchReferences', fetchReferences_1);
1067
1068
  _loop_1 = function (tableToFetch) {
1068
- var referencesTables, shouldContinue, fetchTable, RestApi, nextFetchDependencies;
1069
- var _l;
1070
- return __generator(this, function (_m) {
1071
- switch (_m.label) {
1072
- case 0:
1073
- if (fetchDependencies & eFetchDependencies.C6ENTITY
1074
- && 'string' === typeof tableName
1075
- && tableName.endsWith("carbon_carbons")) {
1076
- referencesTables = responseData_1.rest.reduce(function (accumulator, row) {
1077
- if ('entity_tag' in row && !accumulator.includes(row['entity_tag'])) {
1078
- accumulator.push(row['entity_tag']);
1079
- }
1080
- return accumulator;
1081
- }, []).map(function (entityTag) { return entityTag.split('\\').pop().toLowerCase(); });
1082
- shouldContinue = referencesTables.find(function (referencesTable) { return tableToFetch.endsWith(referencesTable); });
1083
- if (!shouldContinue) {
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*/];
1069
+ var _j;
1070
+ if (fetchDependencies & eFetchDependencies.C6ENTITY
1071
+ && 'string' === typeof tableName
1072
+ && tableName.endsWith("carbon_carbons")) {
1073
+ // todo - rethink the table ref entity system - when tables are renamed? no hooks exist in mysql
1074
+ // since were already filtering on column, we can assume the first row constraint is the same as the rest
1075
+ var referencesTables = responseData_1.rest.reduce(function (accumulator, row) {
1076
+ if ('entity_tag' in row && !accumulator.includes(row['entity_tag'])) {
1077
+ accumulator.push(row['entity_tag']);
1078
+ }
1079
+ return accumulator;
1080
+ }, []).map(function (entityTag) { return entityTag.split('\\').pop().toLowerCase(); });
1081
+ var shouldContinue = referencesTables.find(function (referencesTable) { return tableToFetch.endsWith(referencesTable); });
1082
+ if (!shouldContinue) {
1083
+ console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') did not end with any value in referencesTables', 'color: #c00', referencesTables);
1084
+ return "continue";
1133
1085
  }
1134
- });
1086
+ console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') will be fetched.', 'color: #0c0');
1087
+ }
1088
+ var ormKey = tableToFetch
1089
+ .split('_')
1090
+ .map(function (part) { return part.charAt(0).toUpperCase() + part.slice(1); })
1091
+ .join('_');
1092
+ var RestApi = (_g = C6.ORM[ormKey]) !== null && _g !== void 0 ? _g : new Error("Fetch Dependencies could not fund table (".concat(ormKey, ") in the set \u2209 [ ").concat(Object.keys(C6.ORM).join(', '), " ]"));
1093
+ console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
1094
+ var 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((_j = {},
1115
+ _j[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
+ _j.fetchDependencies = nextFetchDependencies,
1131
+ _j)));
1135
1132
  };
1136
- _a = fetchReferences_1;
1137
- _b = [];
1138
- for (_c in _a)
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:
1133
+ for (tableToFetch in fetchReferences_1) {
1134
+ _loop_1(tableToFetch);
1135
+ }
1155
1136
  console.groupEnd();
1156
1137
  return [4 /*yield*/, Promise.all(apiRequestPromises)];
1157
- case 5:
1158
- _k.sent();
1138
+ case 1:
1139
+ _h.sent();
1159
1140
  apiRequestPromises.map(function (promise) { return __awaiter(_this, void 0, void 0, function () {
1160
1141
  var _a, _b;
1161
1142
  return __generator(this, function (_c) {
@@ -1173,8 +1154,8 @@ var HttpExecutor = /** @class */ (function (_super) {
1173
1154
  }
1174
1155
  });
1175
1156
  }); });
1176
- _k.label = 6;
1177
- case 6:
1157
+ _h.label = 2;
1158
+ case 2:
1178
1159
  if (debug && isLocal()) {
1179
1160
  toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
1180
1161
  }
@@ -1276,7 +1257,16 @@ var ConditionBuilder = /** @class */ (function (_super) {
1276
1257
  C6C.IS, C6C.IS_NOT,
1277
1258
  C6C.BETWEEN, 'NOT BETWEEN',
1278
1259
  C6C.MATCH_AGAINST,
1279
- C6C.ST_DISTANCE_SPHERE
1260
+ C6C.ST_DISTANCE_SPHERE,
1261
+ // spatial predicates
1262
+ C6C.ST_CONTAINS,
1263
+ C6C.ST_INTERSECTS,
1264
+ C6C.ST_WITHIN,
1265
+ C6C.ST_CROSSES,
1266
+ C6C.ST_DISJOINT,
1267
+ C6C.ST_EQUALS,
1268
+ C6C.ST_OVERLAPS,
1269
+ C6C.ST_TOUCHES
1280
1270
  ]);
1281
1271
  return _this;
1282
1272
  }
@@ -1358,6 +1348,19 @@ var ConditionBuilder = /** @class */ (function (_super) {
1358
1348
  var threshold = Array.isArray(value) ? value[0] : value;
1359
1349
  return "ST_Distance_Sphere(".concat(col1, ", ").concat(col2, ") < ").concat(_this.addParam(params, '', threshold));
1360
1350
  }
1351
+ if ([
1352
+ C6C.ST_CONTAINS,
1353
+ C6C.ST_INTERSECTS,
1354
+ C6C.ST_WITHIN,
1355
+ C6C.ST_CROSSES,
1356
+ C6C.ST_DISJOINT,
1357
+ C6C.ST_EQUALS,
1358
+ C6C.ST_OVERLAPS,
1359
+ C6C.ST_TOUCHES
1360
+ ].includes(column)) {
1361
+ var geom1 = op[0], geom2 = op[1];
1362
+ return "".concat(column, "(").concat(geom1, ", ").concat(geom2, ")");
1363
+ }
1361
1364
  }
1362
1365
  var leftIsCol = _this.isColumnRef(column);
1363
1366
  var leftIsRef = _this.isTableReference(column);
@@ -1922,7 +1925,7 @@ function ExpressHandler(_a) {
1922
1925
  payload[C6C.WHERE][primaryKeyName] = primary;
1923
1926
  }
1924
1927
  else {
1925
- res.status(400).json({ error: "Invalid request: ".concat(method, " requires a primary key.") });
1928
+ res.status(400).json({ error: "Invalid request: ".concat(method, " requires a primary key (").concat(primaryKeyName, ").") });
1926
1929
  }
1927
1930
  break;
1928
1931
  case 'POST':
@@ -1971,6 +1974,21 @@ var fieldEq = function (leftCol, rightCol, leftAlias, rightAlias) {
1971
1974
  var distSphere = function (fromCol, toCol, fromAlias, toAlias) {
1972
1975
  return [C6C.ST_DISTANCE_SPHERE, F(fromCol, fromAlias), F(toCol, toAlias)];
1973
1976
  };
1977
+ // Build a bounding-box expression.
1978
+ //
1979
+ // Arguments must be provided in `(minLng, minLat, maxLng, maxLat)` order. The
1980
+ // helper does not attempt to swap or validate coordinates; if a minimum value
1981
+ // is greater than its corresponding maximum value, MySQL's `ST_MakeEnvelope`
1982
+ // returns `NULL`.
1983
+ var bbox = function (minLng, minLat, maxLng, maxLat) {
1984
+ return [C6C.ST_SRID, [C6C.ST_MAKEENVELOPE,
1985
+ [C6C.ST_POINT, minLng, minLat],
1986
+ [C6C.ST_POINT, maxLng, maxLat]], 4326];
1987
+ };
1988
+ // ST_Contains for map envelope/shape queries
1989
+ var stContains = function (envelope, shape) {
1990
+ return [C6C.ST_CONTAINS, envelope, shape];
1991
+ };
1974
1992
 
1975
1993
  function determineRuntimeJsType(mysqlType) {
1976
1994
  var base = mysqlType.toLowerCase().split('(')[0];
@@ -2071,5 +2089,5 @@ function isVerbose () {
2071
2089
  return ['true', '1', 'yes', 'on'].includes(envVerbose.toLowerCase());
2072
2090
  }
2073
2091
 
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 };
2092
+ export { A, AggregateBuilder, C6C, C6Constants, ConditionBuilder, DELETE, DeleteQueryBuilder, Executor, ExpressHandler, F, GET, HttpExecutor, JoinBuilder, POST, PUT, PaginationBuilder, PostQueryBuilder, SelectQueryBuilder, SqlExecutor, TestRestfulResponse, UpdateQueryBuilder, apiRequestCache, axiosInstance, bbox, 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
2093
  //# sourceMappingURL=index.esm.js.map