@carbonorm/carbonnode 1.6.6 → 1.6.8
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/api/restRequest.d.ts +6 -5
- package/dist/index.cjs.js +68 -52
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +68 -53
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/scripts/assets/handlebars/C6.ts.handlebars +9 -5
- package/src/api/axiosInstance.ts +2 -3
- package/src/api/restRequest.ts +66 -40
package/src/api/restRequest.ts
CHANGED
|
@@ -107,21 +107,24 @@ type DeepPartialAny<T> = {
|
|
|
107
107
|
|
|
108
108
|
export enum eFetchDependencies {
|
|
109
109
|
NONE = 0,
|
|
110
|
-
REFERENCED =
|
|
111
|
-
CHILDREN =
|
|
112
|
-
REFERENCES =
|
|
113
|
-
PARENTS =
|
|
114
|
-
ALL =
|
|
110
|
+
REFERENCED = 0b1,
|
|
111
|
+
CHILDREN = 0b1,
|
|
112
|
+
REFERENCES = 0b10,
|
|
113
|
+
PARENTS = 0b10,
|
|
114
|
+
ALL = 0b11,
|
|
115
|
+
C6ENTITY = 0b100,
|
|
116
|
+
RECURSIVE = 0b1000,
|
|
115
117
|
}
|
|
116
118
|
|
|
119
|
+
// todo - I don't like that these essentially become reserved words.
|
|
117
120
|
export type iAPI<RestTableInterfaces extends { [key: string]: any }> = RestTableInterfaces & {
|
|
118
121
|
dataInsertMultipleRows?: RestTableInterfaces[],
|
|
119
122
|
cacheResults?: boolean, // aka ignoreCache
|
|
120
|
-
|
|
123
|
+
// todo - this should really only be used for get requests - add this to the Get interface or throw error (im actually inclined to ts ignore the function and add to iGetC6 atm; back later)
|
|
124
|
+
fetchDependencies?: number | eFetchDependencies | Promise<apiReturn<iGetC6RestResponse<any>>>[],
|
|
121
125
|
debug?: boolean,
|
|
122
126
|
success?: string | ((r: AxiosResponse) => (string | void)),
|
|
123
127
|
error?: string | ((r: AxiosResponse) => (string | void)),
|
|
124
|
-
blocking?: boolean
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
interface iCacheAPI<ResponseDataType = any> {
|
|
@@ -401,7 +404,7 @@ export default function restApi<
|
|
|
401
404
|
|
|
402
405
|
const operatingTableFullName = fullTableList[0];
|
|
403
406
|
|
|
404
|
-
const operatingTable = removePrefixIfExists(operatingTableFullName,C6.PREFIX);
|
|
407
|
+
const operatingTable = removePrefixIfExists(operatingTableFullName, C6.PREFIX);
|
|
405
408
|
|
|
406
409
|
const tables = fullTableList.join(',')
|
|
407
410
|
|
|
@@ -852,13 +855,14 @@ export default function restApi<
|
|
|
852
855
|
|
|
853
856
|
}
|
|
854
857
|
|
|
855
|
-
if (request.fetchDependencies ??= eFetchDependencies.NONE)
|
|
858
|
+
if ((request.fetchDependencies ??= eFetchDependencies.NONE)
|
|
859
|
+
&& 'number' === typeof request.fetchDependencies) {
|
|
856
860
|
|
|
857
861
|
console.groupCollapsed('%c API: fetchDependencies segment (' + requestMethod + ' ' + tableName + ')', 'color: #0c0')
|
|
858
862
|
|
|
859
863
|
const fetchDependencies = async (fetchData: {
|
|
860
864
|
[key: string]: iConstraint[]
|
|
861
|
-
}) => Object.keys(
|
|
865
|
+
}, fetchDependencies: number) => Object.keys(
|
|
862
866
|
fetchData
|
|
863
867
|
).map((column) => {
|
|
864
868
|
|
|
@@ -876,22 +880,52 @@ export default function restApi<
|
|
|
876
880
|
|
|
877
881
|
}
|
|
878
882
|
|
|
883
|
+
|
|
879
884
|
return fetchData[column].map(async (constraint) => {
|
|
880
885
|
|
|
881
|
-
|
|
886
|
+
const constraintTableName = constraint.TABLE
|
|
887
|
+
|
|
888
|
+
if (fetchDependencies & eFetchDependencies.C6ENTITY
|
|
889
|
+
&& tableName === "carbon_carbons") {
|
|
890
|
+
|
|
891
|
+
// todo - let's assume this handles a single row for now, handle multiple rows could improve performance
|
|
892
|
+
// this more or less implies
|
|
893
|
+
// todo - rethink the table ref entity system - when tables are renamed? no hooks exist in mysql
|
|
894
|
+
const referencesTable = (responseData.rest[0]['entity_tag'] ?? '').split('/').pop()
|
|
895
|
+
|
|
896
|
+
if (!constraintTableName.endsWith(referencesTable)) {
|
|
897
|
+
|
|
898
|
+
console.log('%c C6ENTITY: The constraintTableName ('+constraintTableName+') did not end with referencesTable (' + referencesTable + ')', 'color: #c00')
|
|
899
|
+
|
|
900
|
+
return false;
|
|
901
|
+
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
console.log('%c C6ENTITY: The constraintTableName ('+constraintTableName+') ended with referencesTable (' + referencesTable + ')', 'color: #0c0')
|
|
905
|
+
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
console.log(column, constraintTableName)
|
|
882
909
|
|
|
883
910
|
const fetchTable = await C6.IMPORT(constraint.TABLE)
|
|
884
911
|
|
|
885
912
|
const RestApi = fetchTable.default
|
|
886
913
|
|
|
887
|
-
console.log(
|
|
914
|
+
console.log('Fetch Dependencies will select ('+constraintTableName+') using GET request')
|
|
888
915
|
|
|
916
|
+
// this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
|
|
889
917
|
return RestApi.Get({
|
|
890
918
|
[C6.WHERE]: {
|
|
891
|
-
// todo - using value to avoid joins.... but. maybe this should be a parameterizable option
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
919
|
+
// todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
|
|
920
|
+
// todo - handle multiple rows returned
|
|
921
|
+
[constraint.COLUMN]: responseData.rest[column] ?? responseData.rest[0][column]
|
|
922
|
+
},
|
|
923
|
+
fetchDependencies: fetchDependencies & eFetchDependencies.RECURSIVE
|
|
924
|
+
|| (fetchDependencies & eFetchDependencies.C6ENTITY
|
|
925
|
+
&& constraintTableName === "carbon_carbons")
|
|
926
|
+
? fetchDependencies
|
|
927
|
+
: eFetchDependencies.NONE
|
|
928
|
+
})
|
|
895
929
|
|
|
896
930
|
});
|
|
897
931
|
|
|
@@ -899,43 +933,35 @@ export default function restApi<
|
|
|
899
933
|
|
|
900
934
|
let dependencies: any[] = [];
|
|
901
935
|
|
|
902
|
-
// noinspection
|
|
903
|
-
|
|
904
|
-
// @ts-ignore
|
|
905
|
-
case eFetchDependencies.ALL:
|
|
906
|
-
|
|
907
|
-
console.log('Fetching all dependencies.')
|
|
908
|
-
|
|
909
|
-
case eFetchDependencies.CHILDREN: // todo - make this a binary flag with more expressive options
|
|
910
|
-
// @ts-ignore
|
|
911
|
-
case eFetchDependencies.REFERENCED:
|
|
936
|
+
// noinspection JSBitwiseOperatorUsage
|
|
937
|
+
if (request.fetchDependencies & eFetchDependencies.REFERENCED) {
|
|
912
938
|
|
|
913
|
-
|
|
939
|
+
const referencedBy = C6.TABLES[operatingTable].TABLE_REFERENCED_BY;
|
|
914
940
|
|
|
915
|
-
|
|
941
|
+
console.log('REFERENCED BY (CHILDREN)', referencedBy)
|
|
916
942
|
|
|
917
|
-
|
|
943
|
+
if (Object.keys(referencedBy).length > 0) {
|
|
918
944
|
|
|
919
|
-
|
|
945
|
+
dependencies = await fetchDependencies(referencedBy, request.fetchDependencies)
|
|
920
946
|
|
|
921
|
-
|
|
947
|
+
}
|
|
922
948
|
|
|
923
|
-
|
|
949
|
+
}
|
|
924
950
|
|
|
925
|
-
|
|
926
|
-
|
|
951
|
+
if (request.fetchDependencies & eFetchDependencies.REFERENCES) {
|
|
952
|
+
const references = C6.TABLES[operatingTable].TABLE_REFERENCES;
|
|
927
953
|
|
|
928
|
-
|
|
954
|
+
console.log('REFERENCES (PARENTS)', references)
|
|
929
955
|
|
|
930
|
-
|
|
956
|
+
if (Object.keys(references).length > 0) {
|
|
931
957
|
|
|
932
|
-
dependencies
|
|
958
|
+
dependencies.push(await fetchDependencies(references, request.fetchDependencies))
|
|
933
959
|
|
|
934
|
-
|
|
935
|
-
default:
|
|
936
|
-
throw new Error('The value of fetchDependencies (' + request.fetchDependencies?.toString() + ') was not recognized.')
|
|
960
|
+
}
|
|
937
961
|
}
|
|
938
962
|
|
|
963
|
+
dependencies = dependencies.flat(Infinity)
|
|
964
|
+
|
|
939
965
|
request.fetchDependencies = dependencies;
|
|
940
966
|
|
|
941
967
|
await Promise.all(dependencies)
|