@carbonorm/carbonnode 1.6.5 → 1.6.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carbonorm/carbonnode",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "browser": "dist/index.umd.js",
@@ -7,7 +7,8 @@ import {
7
7
  iPostC6RestResponse,
8
8
  iDeleteC6RestResponse,
9
9
  iPutC6RestResponse,
10
- iAPI
10
+ iAPI,
11
+ removePrefixIfExists
11
12
  } from "@carbonorm/carbonnode";
12
13
  import {AxiosResponse} from "axios";
13
14
 
@@ -108,7 +109,19 @@ async function dynamicRestImport(tableName: string) : Promise<{
108
109
 
109
110
  // if tableName is not a key in the TABLES object then throw an error
110
111
  if (!TABLES[tableName]) {
111
- throw new Error('Table (' + tableName + ') does not exist in the TABLES object. Possible values include (' + Object.keys(TABLES).join(', ') + ')');
112
+
113
+ const modifiedTableName = removePrefixIfExists(tableName, RestTablePrefix);
114
+
115
+ if (!TABLES[modifiedTableName]) {
116
+
117
+ throw new Error('Table (' + tableName + ') does not exist in the TABLES object. Possible values include (' + Object.keys(TABLES).join(', ') + ')');
118
+
119
+ } else {
120
+
121
+ tableName = modifiedTableName;
122
+
123
+ }
124
+
112
125
  }
113
126
 
114
127
  const module = await import('./' + (tableName.split('_')
@@ -233,6 +233,14 @@ export function clearCache(props?: iClearCache) {
233
233
 
234
234
  }
235
235
 
236
+
237
+ export function removePrefixIfExists(tableName: string, prefix: string): string {
238
+ if (tableName.startsWith(prefix.toLowerCase())) {
239
+ return tableName.slice(prefix.length);
240
+ }
241
+ return tableName;
242
+ }
243
+
236
244
  /**
237
245
  * the first argument ....
238
246
  *
@@ -393,7 +401,7 @@ export default function restApi<
393
401
 
394
402
  const operatingTableFullName = fullTableList[0];
395
403
 
396
- const operatingTable = operatingTableFullName.replace(C6.PREFIX, '');
404
+ const operatingTable = removePrefixIfExists(operatingTableFullName,C6.PREFIX);
397
405
 
398
406
  const tables = fullTableList.join(',')
399
407