@carbonorm/carbonnode 3.1.3 → 3.2.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.
@@ -1,10 +1,10 @@
1
1
  import { OrmGenerics } from "../types/ormGenerics";
2
- import { apiReturn, DetermineResponseDataType, iRest, iRestReactiveLifecycle, RequestQueryBody } from "../types/ormInterfaces";
2
+ import { DetermineResponseDataType, iRest, iRestReactiveLifecycle, RequestQueryBody } from "../types/ormInterfaces";
3
3
  export declare abstract class Executor<G extends OrmGenerics> {
4
4
  protected config: iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>;
5
5
  protected request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>;
6
6
  protected useNamedParams: boolean;
7
7
  constructor(config: iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>, request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>, useNamedParams?: boolean);
8
- abstract execute(): Promise<apiReturn<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>>;
8
+ abstract execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
9
9
  runLifecycleHooks<Phase extends keyof iRestReactiveLifecycle<G>>(phase: Phase, args: Parameters<NonNullable<iRestReactiveLifecycle<G>[Phase]>[string]>[0]): Promise<void>;
10
10
  }
@@ -1,10 +1,10 @@
1
1
  import { AxiosResponse } from "axios";
2
2
  import { OrmGenerics } from "../types/ormGenerics";
3
- import { apiReturn, DetermineResponseDataType, RequestQueryBody } from "../types/ormInterfaces";
3
+ import { DetermineResponseDataType, RequestQueryBody } from "../types/ormInterfaces";
4
4
  import { Executor } from "./Executor";
5
5
  export declare class HttpExecutor<G extends OrmGenerics> extends Executor<G> {
6
6
  putState(response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>, request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>, callback: () => void): void;
7
7
  postState(response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>, request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>, callback: () => void): void;
8
8
  deleteState(_response: AxiosResponse<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>, request: RequestQueryBody<G['RequestMethod'], G['RestTableInterface'], G['CustomAndRequiredFields'], G['RequestTableOverrides']>, callback: () => void): void;
9
- execute(): Promise<apiReturn<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>>;
9
+ execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
10
10
  }
@@ -1,9 +1,9 @@
1
1
  import { OrmGenerics } from "../types/ormGenerics";
2
- import { apiReturn, DetermineResponseDataType } from "../types/ormInterfaces";
2
+ import { DetermineResponseDataType } from "../types/ormInterfaces";
3
3
  import { ResultSetHeader } from 'mysql2/promise';
4
4
  import { Executor } from "./Executor";
5
5
  export declare class SqlExecutor<G extends OrmGenerics> extends Executor<G> {
6
- execute(): Promise<apiReturn<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>>;
6
+ execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
7
7
  private withConnection;
8
8
  serialize: (row: any) => {
9
9
  [k: string]: unknown;
@@ -1,8 +1,8 @@
1
1
  import { OrmGenerics } from "../../types/ormGenerics";
2
- import { apiReturn, DetermineResponseDataType } from "../../types/ormInterfaces";
2
+ import { DetermineResponseDataType } from "../../types/ormInterfaces";
3
3
  import { AggregateBuilder } from "./AggregateBuilder";
4
4
  export declare class ConditionBuilder<G extends OrmGenerics> extends AggregateBuilder<G> {
5
- execute(): Promise<apiReturn<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>>;
5
+ execute(): Promise<DetermineResponseDataType<G['RequestMethod'], G['RestTableInterface']>>;
6
6
  private readonly OPERATORS;
7
7
  private validateOperator;
8
8
  private addParam;
@@ -1,5 +1,5 @@
1
1
  import { OrmGenerics } from "./types/ormGenerics";
2
2
  import { iRest } from "./types/ormInterfaces";
3
3
  export declare function restOrm<G extends Omit<OrmGenerics, "requestMethod">>(config: () => Omit<iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>, "requestMethod">): {
4
- [k: string]: (request: import("./types/ormInterfaces").RequestQueryBody<G["RequestMethod"], G["RestTableInterface"], G["CustomAndRequiredFields"], G["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").apiReturn<import("./types/ormInterfaces").DetermineResponseDataType<G["RequestMethod"], G["RestTableInterface"]>>>;
4
+ [k: string]: (request: import("./types/ormInterfaces").RequestQueryBody<G["RequestMethod"], G["RestTableInterface"], G["CustomAndRequiredFields"], G["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<G["RequestMethod"], G["RestTableInterface"]>>;
5
5
  };
@@ -1,6 +1,6 @@
1
1
  import { OrmGenerics } from "./types/ormGenerics";
2
- import { apiReturn, DetermineResponseDataType, iRest, RequestQueryBody } from "./types/ormInterfaces";
2
+ import { DetermineResponseDataType, iRest, RequestQueryBody } from "./types/ormInterfaces";
3
3
  /**
4
4
  * Facade: routes API calls to SQL or HTTP executors based on runtime context.
5
5
  */
6
- export default function restRequest<G extends OrmGenerics>(configX: (() => iRest<G['RestTableInterface'], G['RestShortTableName'], G['PrimaryKey']>) | iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>): (request: RequestQueryBody<G["RequestMethod"], G["RestTableInterface"], G["CustomAndRequiredFields"], G["RequestTableOverrides"]>) => Promise<apiReturn<DetermineResponseDataType<G["RequestMethod"], G["RestTableInterface"]>>>;
6
+ export default function restRequest<G extends OrmGenerics>(configX: (() => iRest<G['RestTableInterface'], G['RestShortTableName'], G['PrimaryKey']>) | iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>): (request: RequestQueryBody<G["RequestMethod"], G["RestTableInterface"], G["CustomAndRequiredFields"], G["RequestTableOverrides"]>) => Promise<DetermineResponseDataType<G["RequestMethod"], G["RestTableInterface"]>>;
@@ -71,7 +71,7 @@ export type iAPI<T extends {
71
71
  }> = T & {
72
72
  dataInsertMultipleRows?: T[];
73
73
  cacheResults?: boolean;
74
- fetchDependencies?: number | eFetchDependencies | Awaited<apiReturn<iGetC6RestResponse<any>>>[];
74
+ fetchDependencies?: number | eFetchDependencies | Awaited<iGetC6RestResponse<any>>[];
75
75
  debug?: boolean;
76
76
  success?: string | ((r: AxiosResponse) => string | void);
77
77
  error?: string | ((r: AxiosResponse) => string | void);
@@ -106,11 +106,14 @@ export interface iC6RestResponse<RestData> {
106
106
  session?: any;
107
107
  sql?: any;
108
108
  }
109
- export type iGetC6RestResponse<ResponseDataType, ResponseDataOverrides = {}> = iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]>;
110
- export type apiReturn<Response> = null | undefined | Response | (Response extends iPutC6RestResponse | iDeleteC6RestResponse | iPostC6RestResponse ? null : () => apiReturn<Response>);
109
+ export interface iGetC6RestResponse<ResponseDataType extends {
110
+ [key: string]: any;
111
+ }, ResponseDataOverrides = {}> extends iC6RestResponse<Modify<ResponseDataType, ResponseDataOverrides> | Modify<ResponseDataType, ResponseDataOverrides>[]> {
112
+ next?: () => Promise<DetermineResponseDataType<"GET", ResponseDataType, ResponseDataOverrides>>;
113
+ }
111
114
  export type DetermineResponseDataType<Method extends iRestMethods, RestTableInterface extends {
112
115
  [key: string]: any;
113
- }> = Method extends 'POST' ? iPostC6RestResponse<RestTableInterface> : Method extends 'GET' ? iGetC6RestResponse<RestTableInterface> : Method extends 'PUT' ? iPutC6RestResponse<RestTableInterface> : Method extends 'DELETE' ? iDeleteC6RestResponse<RestTableInterface> : never;
116
+ }, ResponseDataOverrides = {}> = null | undefined | (Method extends 'POST' ? iPostC6RestResponse<RestTableInterface> : Method extends 'GET' ? iGetC6RestResponse<RestTableInterface, ResponseDataOverrides> : Method extends 'PUT' ? iPutC6RestResponse<RestTableInterface> : Method extends 'DELETE' ? iDeleteC6RestResponse<RestTableInterface> : never);
114
117
  export interface iRest<RestShortTableName extends string = any, RestTableInterface extends Record<string, any> = any, PrimaryKey extends keyof RestTableInterface & string = keyof RestTableInterface & string> {
115
118
  C6: iC6Object;
116
119
  axios?: AxiosInstance;
@@ -193,10 +196,10 @@ export interface iDynamicApiImport<RestData extends {
193
196
  export interface iRestApiFunctions<RestData extends {
194
197
  [key: string]: any;
195
198
  } = any> {
196
- Delete: (request?: RequestQueryBody<'DELETE', RestData>) => apiReturn<iDeleteC6RestResponse<RestData>>;
197
- Post: (request?: RequestQueryBody<'POST', RestData>) => apiReturn<iPostC6RestResponse<RestData>>;
198
- Get: (request?: RequestQueryBody<'GET', RestData>) => apiReturn<iGetC6RestResponse<RestData>>;
199
- Put: (request?: RequestQueryBody<'PUT', RestData>) => apiReturn<iPutC6RestResponse<RestData>>;
199
+ Delete: (request?: RequestQueryBody<'DELETE', RestData>) => iDeleteC6RestResponse<RestData>;
200
+ Post: (request?: RequestQueryBody<'POST', RestData>) => iPostC6RestResponse<RestData>;
201
+ Get: (request?: RequestQueryBody<'GET', RestData>) => iGetC6RestResponse<RestData>;
202
+ Put: (request?: RequestQueryBody<'PUT', RestData>) => iPutC6RestResponse<RestData>;
200
203
  }
201
204
  export interface iC6Object<RestShortTableName extends string = any, RestTableInterface extends {
202
205
  [key: string]: any;
package/dist/index.cjs.js CHANGED
@@ -583,25 +583,14 @@ function clearCache(props) {
583
583
  exports.userCustomClearCache = exports.apiRequestCache = [];
584
584
  }
585
585
  function checkCache(cacheResult, requestMethod, tableName, request) {
586
- var _a, _b, _c;
587
- if (undefined === (cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.response)) {
588
- console.groupCollapsed('%c API: The request on (' + tableName + ') is in cache and the response is undefined. The request has not finished. Returning the request Promise!', 'color: #0c0');
589
- console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
590
- console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', request);
591
- console.groupEnd();
592
- return cacheResult.request;
586
+ if (undefined === cacheResult) {
587
+ return false;
593
588
  }
594
- if (true === (cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.final)) {
595
- if (false === isTest() || true === isVerbose()) {
596
- console.groupCollapsed('%c API: Rest api cache (' + requestMethod + ' ' + tableName + ') has reached the final result. Returning undefined!', 'color: #cc0');
597
- console.log('%c ' + requestMethod + ' ' + tableName, 'color: #cc0');
598
- console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #cc0', request);
599
- console.log('%c Response Data:', 'color: #cc0', ((_b = (_a = cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.rest) || ((_c = cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.response) === null || _c === void 0 ? void 0 : _c.data) || (cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.response));
600
- console.groupEnd();
601
- }
602
- return undefined;
603
- }
604
- return false;
589
+ console.groupCollapsed('%c API: The request on (' + tableName + ') is in cache. Returning the request Promise!', 'color: #0c0');
590
+ console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
591
+ console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', request);
592
+ console.groupEnd();
593
+ return cacheResult.request;
605
594
  }
606
595
 
607
596
  function sortAndSerializeQueryObject(tables, query) {
@@ -899,9 +888,9 @@ var HttpExecutor = /** @class */ (function (_super) {
899
888
  return [2 /*return*/, axiosActiveRequest.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
900
889
  var cacheIndex, callback, responseData_1, dependencies_1, fetchReferences_1, apiRequestPromises, _loop_1, _a, _b, _c, _i, tableToFetch;
901
890
  var _this = this;
902
- var _d, _e, _f, _g, _h, _j, _k;
903
- return tslib.__generator(this, function (_l) {
904
- switch (_l.label) {
891
+ var _d, _e, _f, _g, _h, _j;
892
+ return tslib.__generator(this, function (_k) {
893
+ switch (_k.label) {
905
894
  case 0:
906
895
  // noinspection SuspiciousTypeOfGuard
907
896
  if (typeof response.data === 'string') {
@@ -913,6 +902,7 @@ var HttpExecutor = /** @class */ (function (_super) {
913
902
  }
914
903
  if (cachingConfirmed) {
915
904
  cacheIndex = exports.apiRequestCache.findIndex(function (cache) { return cache.requestArgumentsSerialized === querySerialized; });
905
+ // TODO - currently nonthing is setting this correctly
916
906
  exports.apiRequestCache[cacheIndex].final = false === returnGetNextPageFunction;
917
907
  // only cache get method requests
918
908
  exports.apiRequestCache[cacheIndex].response = response;
@@ -938,7 +928,7 @@ var HttpExecutor = /** @class */ (function (_super) {
938
928
  if (undefined !== reactBootstrap && response) {
939
929
  switch (requestMethod) {
940
930
  case GET:
941
- reactBootstrap.updateRestfulObjectArrays({
931
+ response.data && reactBootstrap.updateRestfulObjectArrays({
942
932
  dataOrCallback: Array.isArray(response.data.rest) ? response.data.rest : [response.data.rest],
943
933
  stateKey: this.config.restModel.TABLE_NAME,
944
934
  uniqueObjectId: this.config.restModel.PRIMARY_SHORT,
@@ -968,14 +958,19 @@ var HttpExecutor = /** @class */ (function (_super) {
968
958
  console.log('%c ' + requestMethod + ' ' + tableName, 'color: #0c0');
969
959
  console.log('%c Request Data (note you may see the success and/or error prompt):', 'color: #0c0', this.request);
970
960
  console.log('%c Response Data:', 'color: #0c0', responseData_1.rest);
971
- console.log('%c Will return get next page function:' + (1 !== ((_h = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _h === void 0 ? void 0 : _h[C6.LIMIT]) ? '' : ' (Will not return with explicit limit 1 set)'), 'color: #0c0', true === returnGetNextPageFunction);
961
+ console.log('%c Will return get next page function:' + (returnGetNextPageFunction ? '' : ' (Will not return with explicit limit 1 set)'), 'color: #0c0', true === returnGetNextPageFunction);
972
962
  console.trace();
973
963
  console.groupEnd();
974
964
  }
975
- if (false === returnGetNextPageFunction
976
- && true === debug
977
- && isLocal()) {
978
- reactToastify.toast.success("DEVS: Response returned length (" + ((_j = responseData_1.rest) === null || _j === void 0 ? void 0 : _j.length) + ") less than limit (" + ((_k = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _k === void 0 ? void 0 : _k[C6.LIMIT]) + ").", toastOptionsDevs);
965
+ if (false === returnGetNextPageFunction) {
966
+ responseData_1.next = apiRequest;
967
+ }
968
+ else {
969
+ responseData_1.next = undefined;
970
+ if (true === debug
971
+ && isLocal()) {
972
+ reactToastify.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);
973
+ }
979
974
  }
980
975
  if (!(fetchDependencies
981
976
  && 'number' === typeof fetchDependencies
@@ -989,6 +984,7 @@ var HttpExecutor = /** @class */ (function (_super) {
989
984
  console.trace(); // hidden in collapsed group
990
985
  console.groupEnd();
991
986
  dependencies_1 = {};
987
+ // Remember this is a binary bitwise operation, so we can check for multiple dependencies at once
992
988
  if (fetchDependencies & exports.eFetchDependencies.C6ENTITY) {
993
989
  dependencies_1 = operatingTable.endsWith("carbon_carbons")
994
990
  ? tslib.__assign(tslib.__assign({}, fetchDependencies & exports.eFetchDependencies.CHILDREN // REFERENCED === CHILDREN
@@ -1050,9 +1046,9 @@ var HttpExecutor = /** @class */ (function (_super) {
1050
1046
  console.log('fetchReferences', fetchReferences_1);
1051
1047
  _loop_1 = function (tableToFetch) {
1052
1048
  var referencesTables, shouldContinue, fetchTable, RestApi, nextFetchDependencies;
1053
- var _m;
1054
- return tslib.__generator(this, function (_o) {
1055
- switch (_o.label) {
1049
+ var _l;
1050
+ return tslib.__generator(this, function (_m) {
1051
+ switch (_m.label) {
1056
1052
  case 0:
1057
1053
  if (fetchDependencies & exports.eFetchDependencies.C6ENTITY
1058
1054
  && 'string' === typeof tableName
@@ -1072,7 +1068,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1072
1068
  }
1073
1069
  return [4 /*yield*/, C6.IMPORT(tableToFetch)];
1074
1070
  case 1:
1075
- fetchTable = _o.sent();
1071
+ fetchTable = _m.sent();
1076
1072
  RestApi = fetchTable.default;
1077
1073
  console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
1078
1074
  nextFetchDependencies = exports.eFetchDependencies.NONE;
@@ -1095,8 +1091,8 @@ var HttpExecutor = /** @class */ (function (_super) {
1095
1091
  // it not certain that they are using carbons' entities either
1096
1092
  // this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
1097
1093
  // todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
1098
- apiRequestPromises.push(RestApi.Get((_m = {},
1099
- _m[C6.WHERE] = {
1094
+ apiRequestPromises.push(RestApi.Get((_l = {},
1095
+ _l[C6.WHERE] = {
1100
1096
  0: Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
1101
1097
  fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
1102
1098
  if (0 === fetchReferences_1[tableToFetch][column].length) {
@@ -1111,8 +1107,8 @@ var HttpExecutor = /** @class */ (function (_super) {
1111
1107
  return sum;
1112
1108
  }, {})
1113
1109
  },
1114
- _m.fetchDependencies = nextFetchDependencies,
1115
- _m)));
1110
+ _l.fetchDependencies = nextFetchDependencies,
1111
+ _l)));
1116
1112
  return [2 /*return*/];
1117
1113
  }
1118
1114
  });
@@ -1122,7 +1118,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1122
1118
  for (_c in _a)
1123
1119
  _b.push(_c);
1124
1120
  _i = 0;
1125
- _l.label = 1;
1121
+ _k.label = 1;
1126
1122
  case 1:
1127
1123
  if (!(_i < _b.length)) return [3 /*break*/, 4];
1128
1124
  _c = _b[_i];
@@ -1130,8 +1126,8 @@ var HttpExecutor = /** @class */ (function (_super) {
1130
1126
  tableToFetch = _c;
1131
1127
  return [5 /*yield**/, _loop_1(tableToFetch)];
1132
1128
  case 2:
1133
- _l.sent();
1134
- _l.label = 3;
1129
+ _k.sent();
1130
+ _k.label = 3;
1135
1131
  case 3:
1136
1132
  _i++;
1137
1133
  return [3 /*break*/, 1];
@@ -1139,7 +1135,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1139
1135
  console.groupEnd();
1140
1136
  return [4 /*yield*/, Promise.all(apiRequestPromises)];
1141
1137
  case 5:
1142
- _l.sent();
1138
+ _k.sent();
1143
1139
  apiRequestPromises.map(function (promise) { return tslib.__awaiter(_this, void 0, void 0, function () {
1144
1140
  var _a, _b;
1145
1141
  return tslib.__generator(this, function (_c) {
@@ -1157,15 +1153,16 @@ var HttpExecutor = /** @class */ (function (_super) {
1157
1153
  }
1158
1154
  });
1159
1155
  }); });
1160
- _l.label = 6;
1156
+ _k.label = 6;
1161
1157
  case 6:
1162
1158
  if (debug && isLocal()) {
1163
1159
  reactToastify.toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
1164
1160
  }
1161
+ // this is the literal axios return
1165
1162
  return [2 /*return*/, response];
1166
1163
  }
1167
1164
  });
1168
- }); }).then(function (response) { return response.data; })];
1165
+ }); }).then(function (response) { return response.data; })]; // this escapes from axios context
1169
1166
  }
1170
1167
  catch (throwableError) {
1171
1168
  if (isTest()) {