@resistdesign/voltra 3.0.0-alpha.3 → 3.0.0-alpha.4
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 +75 -0
- package/SearchTypes-DjN6YQzE.d.ts +577 -0
- package/Types-C7XjUjoF.d.ts +240 -0
- package/Validation-CFP59oIP.d.ts +226 -0
- package/api/index.d.ts +6 -0
- package/api/index.js +7968 -0
- package/app/index.d.ts +5 -0
- package/app/index.js +810 -0
- package/common/Testing/CLI.js +432 -0
- package/common/index.d.ts +4 -0
- package/common/index.js +1760 -0
- package/iac/index.d.ts +2 -0
- package/iac/index.js +1661 -0
- package/iac/packs/index.d.ts +1 -0
- package/iac/packs/index.js +1620 -0
- package/index-BkFZlfit.d.ts +112 -0
- package/index-C3-iD9Mh.d.ts +690 -0
- package/index-DZ2BB4iX.d.ts +5357 -0
- package/{src/iac/types/IaCTypes.d.ts → index-DcvJOZ_c.d.ts} +1018 -23
- package/index-IokxSNxm.d.ts +745 -0
- package/index.d.ts +13 -0
- package/index.js +10973 -0
- package/package.json +40 -41
- package/src/api/DataAccessControl.d.ts +0 -85
- package/src/api/DataAccessControl.js +0 -159
- package/src/api/ORM/DACUtils.d.ts +0 -60
- package/src/api/ORM/DACUtils.js +0 -197
- package/src/api/ORM/ListItemUtils.d.ts +0 -7
- package/src/api/ORM/ListItemUtils.js +0 -22
- package/src/api/ORM/ORMRouteMap.d.ts +0 -19
- package/src/api/ORM/ORMRouteMap.js +0 -82
- package/src/api/ORM/TypeInfoORMService.d.ts +0 -103
- package/src/api/ORM/TypeInfoORMService.js +0 -581
- package/src/api/ORM/drivers/DynamoDBDataItemDBDriver/ConfigTypes.d.ts +0 -63
- package/src/api/ORM/drivers/DynamoDBDataItemDBDriver/ConfigTypes.js +0 -2
- package/src/api/ORM/drivers/DynamoDBDataItemDBDriver.d.ts +0 -36
- package/src/api/ORM/drivers/DynamoDBDataItemDBDriver.js +0 -282
- package/src/api/ORM/drivers/S3FileItemDBDriver/ConfigTypes.d.ts +0 -90
- package/src/api/ORM/drivers/S3FileItemDBDriver/ConfigTypes.js +0 -2
- package/src/api/ORM/drivers/S3FileItemDBDriver/S3FileDriver.d.ts +0 -45
- package/src/api/ORM/drivers/S3FileItemDBDriver/S3FileDriver.js +0 -127
- package/src/api/ORM/drivers/S3FileItemDBDriver.d.ts +0 -44
- package/src/api/ORM/drivers/S3FileItemDBDriver.js +0 -182
- package/src/api/ORM/drivers/common/SupportedTypeInfoORMDBDrivers.d.ts +0 -12
- package/src/api/ORM/drivers/common/SupportedTypeInfoORMDBDrivers.js +0 -20
- package/src/api/ORM/drivers/common/Types.d.ts +0 -77
- package/src/api/ORM/drivers/common/Types.js +0 -14
- package/src/api/ORM/drivers/common/index.d.ts +0 -2
- package/src/api/ORM/drivers/common/index.js +0 -18
- package/src/api/ORM/drivers/index.d.ts +0 -3
- package/src/api/ORM/drivers/index.js +0 -19
- package/src/api/ORM/index.d.ts +0 -4
- package/src/api/ORM/index.js +0 -43
- package/src/api/Router/AWS.d.ts +0 -26
- package/src/api/Router/AWS.js +0 -76
- package/src/api/Router/Auth.d.ts +0 -2
- package/src/api/Router/Auth.js +0 -9
- package/src/api/Router/CORS.d.ts +0 -6
- package/src/api/Router/CORS.js +0 -27
- package/src/api/Router/Types.d.ts +0 -71
- package/src/api/Router/Types.js +0 -2
- package/src/api/Router/index.d.ts +0 -18
- package/src/api/Router/index.js +0 -145
- package/src/api/index.d.ts +0 -3
- package/src/api/index.js +0 -39
- package/src/app/index.d.ts +0 -1
- package/src/app/index.js +0 -37
- package/src/app/utils/ApplicationState.d.ts +0 -52
- package/src/app/utils/ApplicationState.js +0 -86
- package/src/app/utils/ApplicationStateLoader.d.ts +0 -46
- package/src/app/utils/ApplicationStateLoader.js +0 -57
- package/src/app/utils/Controller.d.ts +0 -4
- package/src/app/utils/Controller.js +0 -47
- package/src/app/utils/Debug.d.ts +0 -4
- package/src/app/utils/Debug.js +0 -30
- package/src/app/utils/EasyLayout.d.ts +0 -49
- package/src/app/utils/EasyLayout.js +0 -122
- package/src/app/utils/Route.d.ts +0 -28
- package/src/app/utils/Route.js +0 -102
- package/src/app/utils/Service.d.ts +0 -12
- package/src/app/utils/Service.js +0 -34
- package/src/app/utils/TypeInfoORMAPIUtils.d.ts +0 -20
- package/src/app/utils/TypeInfoORMAPIUtils.js +0 -62
- package/src/app/utils/TypeInfoORMClient.d.ts +0 -24
- package/src/app/utils/TypeInfoORMClient.js +0 -69
- package/src/app/utils/index.d.ts +0 -8
- package/src/app/utils/index.js +0 -24
- package/src/common/CommandLine/collectRequiredEnvironmentVariables.d.ts +0 -1
- package/src/common/CommandLine/collectRequiredEnvironmentVariables.js +0 -16
- package/src/common/HelperTypes.d.ts +0 -3
- package/src/common/HelperTypes.js +0 -2
- package/src/common/IdGeneration/getSimpleId.d.ts +0 -4
- package/src/common/IdGeneration/getSimpleId.js +0 -16
- package/src/common/IdGeneration/index.d.ts +0 -1
- package/src/common/IdGeneration/index.js +0 -17
- package/src/common/ItemRelationshipInfoTypes.d.ts +0 -46
- package/src/common/ItemRelationshipInfoTypes.js +0 -20
- package/src/common/ItemRelationships/ItemRelationshipValidation.d.ts +0 -10
- package/src/common/ItemRelationships/ItemRelationshipValidation.js +0 -43
- package/src/common/ItemRelationships/index.d.ts +0 -1
- package/src/common/ItemRelationships/index.js +0 -17
- package/src/common/Logging/Utils.d.ts +0 -10
- package/src/common/Logging/Utils.js +0 -33
- package/src/common/Logging/index.d.ts +0 -1
- package/src/common/Logging/index.js +0 -17
- package/src/common/Routing.d.ts +0 -25
- package/src/common/Routing.js +0 -102
- package/src/common/SearchTypes.d.ts +0 -98
- package/src/common/SearchTypes.js +0 -39
- package/src/common/SearchUtils.d.ts +0 -22
- package/src/common/SearchUtils.js +0 -134
- package/src/common/SearchValidation.d.ts +0 -17
- package/src/common/SearchValidation.js +0 -90
- package/src/common/Storyboarding/Types.d.ts +0 -25
- package/src/common/Storyboarding/Types.js +0 -2
- package/src/common/StringTransformers.d.ts +0 -17
- package/src/common/StringTransformers.js +0 -36
- package/src/common/Testing/CLI.d.ts +0 -2
- package/src/common/Testing/CLI.js +0 -56
- package/src/common/Testing/Types.d.ts +0 -117
- package/src/common/Testing/Types.js +0 -19
- package/src/common/Testing/Utils.d.ts +0 -48
- package/src/common/Testing/Utils.js +0 -334
- package/src/common/Testing/index.d.ts +0 -2
- package/src/common/Testing/index.js +0 -18
- package/src/common/TypeInfoDataItemUtils.d.ts +0 -10
- package/src/common/TypeInfoDataItemUtils.js +0 -55
- package/src/common/TypeInfoORM/Types.d.ts +0 -76
- package/src/common/TypeInfoORM/Types.js +0 -55
- package/src/common/TypeInfoORM/index.d.ts +0 -1
- package/src/common/TypeInfoORM/index.js +0 -17
- package/src/common/TypeParsing/Constants.d.ts +0 -1
- package/src/common/TypeParsing/Constants.js +0 -4
- package/src/common/TypeParsing/ParsingUtils/Constants.d.ts +0 -5
- package/src/common/TypeParsing/ParsingUtils/Constants.js +0 -8
- package/src/common/TypeParsing/ParsingUtils/checkType.d.ts +0 -8
- package/src/common/TypeParsing/ParsingUtils/checkType.js +0 -46
- package/src/common/TypeParsing/ParsingUtils/checkUnionType.d.ts +0 -6
- package/src/common/TypeParsing/ParsingUtils/checkUnionType.js +0 -15
- package/src/common/TypeParsing/ParsingUtils/extractCommentTags.d.ts +0 -2
- package/src/common/TypeParsing/ParsingUtils/extractCommentTags.js +0 -105
- package/src/common/TypeParsing/ParsingUtils/extractLiteralValues.d.ts +0 -6
- package/src/common/TypeParsing/ParsingUtils/extractLiteralValues.js +0 -42
- package/src/common/TypeParsing/ParsingUtils/extractTypeDetails.d.ts +0 -8
- package/src/common/TypeParsing/ParsingUtils/extractTypeDetails.js +0 -14
- package/src/common/TypeParsing/ParsingUtils/getPrimaryFieldForTypeInfo.d.ts +0 -5
- package/src/common/TypeParsing/ParsingUtils/getPrimaryFieldForTypeInfo.js +0 -27
- package/src/common/TypeParsing/ParsingUtils/getTypeInfo.d.ts +0 -3
- package/src/common/TypeParsing/ParsingUtils/getTypeInfo.js +0 -27
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoField.d.ts +0 -3
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoField.js +0 -44
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromAliasType.d.ts +0 -4
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromAliasType.js +0 -28
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromFieldFilter.d.ts +0 -4
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromFieldFilter.js +0 -105
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromTypeAlias.d.ts +0 -4
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromTypeAlias.js +0 -20
- package/src/common/TypeParsing/ParsingUtils/getTypeKeyword.d.ts +0 -3
- package/src/common/TypeParsing/ParsingUtils/getTypeKeyword.js +0 -17
- package/src/common/TypeParsing/ParsingUtils/getUnionOrIntersectionTypeInfo.d.ts +0 -4
- package/src/common/TypeParsing/ParsingUtils/getUnionOrIntersectionTypeInfo.js +0 -49
- package/src/common/TypeParsing/ParsingUtils/getUnionOrLiteralStringValues.d.ts +0 -2
- package/src/common/TypeParsing/ParsingUtils/getUnionOrLiteralStringValues.js +0 -24
- package/src/common/TypeParsing/TypeInfo.d.ts +0 -142
- package/src/common/TypeParsing/TypeInfo.js +0 -13
- package/src/common/TypeParsing/TypeMapping.d.ts +0 -9
- package/src/common/TypeParsing/TypeMapping.js +0 -32
- package/src/common/TypeParsing/TypeParsing.d.ts +0 -5
- package/src/common/TypeParsing/TypeParsing.js +0 -39
- package/src/common/TypeParsing/Utils.d.ts +0 -21
- package/src/common/TypeParsing/Utils.js +0 -94
- package/src/common/TypeParsing/Validation.d.ts +0 -92
- package/src/common/TypeParsing/Validation.js +0 -340
- package/src/common/TypeParsing/index.d.ts +0 -5
- package/src/common/TypeParsing/index.js +0 -44
- package/src/common/index.d.ts +0 -11
- package/src/common/index.js +0 -47
- package/src/iac/SimpleCFT.d.ts +0 -48
- package/src/iac/SimpleCFT.js +0 -82
- package/src/iac/index.d.ts +0 -9
- package/src/iac/index.js +0 -48
- package/src/iac/packs/auth/user-management.d.ts +0 -14
- package/src/iac/packs/auth/user-management.js +0 -302
- package/src/iac/packs/auth.d.ts +0 -19
- package/src/iac/packs/auth.js +0 -47
- package/src/iac/packs/build/utils.d.ts +0 -100
- package/src/iac/packs/build/utils.js +0 -23
- package/src/iac/packs/build.d.ts +0 -29
- package/src/iac/packs/build.js +0 -217
- package/src/iac/packs/cdn.d.ts +0 -12
- package/src/iac/packs/cdn.js +0 -126
- package/src/iac/packs/cloud-function.d.ts +0 -17
- package/src/iac/packs/cloud-function.js +0 -69
- package/src/iac/packs/database.d.ts +0 -29
- package/src/iac/packs/database.js +0 -27
- package/src/iac/packs/dns.d.ts +0 -13
- package/src/iac/packs/dns.js +0 -26
- package/src/iac/packs/file-storage.d.ts +0 -14
- package/src/iac/packs/file-storage.js +0 -71
- package/src/iac/packs/gateway.d.ts +0 -27
- package/src/iac/packs/gateway.js +0 -342
- package/src/iac/packs/index.d.ts +0 -11
- package/src/iac/packs/index.js +0 -27
- package/src/iac/packs/repo.d.ts +0 -10
- package/src/iac/packs/repo.js +0 -34
- package/src/iac/packs/ssl-certificate.d.ts +0 -10
- package/src/iac/packs/ssl-certificate.js +0 -36
- package/src/iac/types/CloudFormationResourceSpecification.d.ts +0 -2
- package/src/iac/types/Constants.d.ts +0 -9
- package/src/iac/types/Constants.js +0 -20
- package/src/iac/types/IaCTypes.js +0 -14
- package/src/iac/types/Renderers.d.ts +0 -12
- package/src/iac/types/Renderers.js +0 -112
- package/src/iac/types/Types.d.ts +0 -37
- package/src/iac/types/Types.js +0 -2
- package/src/iac/types/Utils.d.ts +0 -2
- package/src/iac/types/Utils.js +0 -60
- package/src/iac/types/generate.d.ts +0 -1
- package/src/iac/types/generate.js +0 -31
- package/src/iac/utils/index.d.ts +0 -36
- package/src/iac/utils/index.js +0 -105
- package/src/iac/utils/patch-utils.d.ts +0 -15
- package/src/iac/utils/patch-utils.js +0 -62
- package/src/index.d.ts +0 -178
- package/src/index.js +0 -214
|
@@ -1,581 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypeInfoORMService = exports.getDriverMethodWithModifiedError = exports.cleanRelationshipItem = void 0;
|
|
4
|
-
const TypeInfo_1 = require("../../common/TypeParsing/TypeInfo");
|
|
5
|
-
const Validation_1 = require("../../common/TypeParsing/Validation");
|
|
6
|
-
const SearchTypes_1 = require("../../common/SearchTypes");
|
|
7
|
-
const SearchValidation_1 = require("../../common/SearchValidation");
|
|
8
|
-
const ItemRelationships_1 = require("../../common/ItemRelationships");
|
|
9
|
-
const TypeInfoORM_1 = require("../../common/TypeInfoORM");
|
|
10
|
-
const Utils_1 = require("../../common/TypeParsing/Utils");
|
|
11
|
-
const ItemRelationshipInfoTypes_1 = require("../../common/ItemRelationshipInfoTypes");
|
|
12
|
-
const DataAccessControl_1 = require("../DataAccessControl");
|
|
13
|
-
const DACUtils_1 = require("./DACUtils");
|
|
14
|
-
const ListItemUtils_1 = require("./ListItemUtils");
|
|
15
|
-
const cleanRelationshipItem = (relationshipItem) => {
|
|
16
|
-
const relItemKeys = Object.values(ItemRelationshipInfoTypes_1.ItemRelationshipInfoKeys);
|
|
17
|
-
const cleanedItem = {};
|
|
18
|
-
for (const rIK of relItemKeys) {
|
|
19
|
-
cleanedItem[rIK] = relationshipItem[rIK];
|
|
20
|
-
}
|
|
21
|
-
return cleanedItem;
|
|
22
|
-
};
|
|
23
|
-
exports.cleanRelationshipItem = cleanRelationshipItem;
|
|
24
|
-
const getDriverMethodWithModifiedError = (extendedData, driver, driverMethodName) => ((...args) => {
|
|
25
|
-
try {
|
|
26
|
-
return driver[driverMethodName](...args);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
throw {
|
|
30
|
-
...error,
|
|
31
|
-
...extendedData,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
exports.getDriverMethodWithModifiedError = getDriverMethodWithModifiedError;
|
|
36
|
-
/**
|
|
37
|
-
* A service using TypeInfo to perform ORM operations with one or many `DBServiceItemDriver` instances.
|
|
38
|
-
* */
|
|
39
|
-
class TypeInfoORMService {
|
|
40
|
-
config;
|
|
41
|
-
dacRoleCache = {};
|
|
42
|
-
constructor(config) {
|
|
43
|
-
this.config = config;
|
|
44
|
-
if (!config.getDriver) {
|
|
45
|
-
throw new Error(TypeInfoORM_1.TypeInfoORMServiceError.NO_DRIVERS_SUPPLIED);
|
|
46
|
-
}
|
|
47
|
-
if (!config.getRelationshipDriver) {
|
|
48
|
-
throw new Error(TypeInfoORM_1.TypeInfoORMServiceError.NO_RELATIONSHIP_DRIVERS_SUPPLIED);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
getItemDACValidation = (item, typeName, typeOperation) => {
|
|
52
|
-
const { useDAC } = this.config;
|
|
53
|
-
if (useDAC) {
|
|
54
|
-
const typeInfo = this.getTypeInfo(typeName);
|
|
55
|
-
const { dacConfig } = this.config;
|
|
56
|
-
const { itemResourcePathPrefix, accessingRole, getDACRoleById } = dacConfig;
|
|
57
|
-
return (0, DACUtils_1.mergeDACDataItemResourceAccessResultMaps)((0, DACUtils_1.getDACRoleHasAccessToDataItem)(itemResourcePathPrefix, typeOperation, typeName, item, typeInfo, accessingRole, getDACRoleById, this.dacRoleCache), (0, DACUtils_1.getDACRoleHasAccessToDataItem)(itemResourcePathPrefix, TypeInfoORM_1.OperationGroup.ALL_ITEM_OPERATIONS, typeName, item, typeInfo, accessingRole, getDACRoleById, this.dacRoleCache), (0, DACUtils_1.getDACRoleHasAccessToDataItem)(itemResourcePathPrefix, TypeInfoORM_1.OperationGroup.ALL_OPERATIONS, typeName, item, typeInfo, accessingRole, getDACRoleById, this.dacRoleCache));
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
return {
|
|
61
|
-
allowed: true,
|
|
62
|
-
denied: false,
|
|
63
|
-
fieldsResources: {},
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
getRelationshipDACValidation = (itemRelationship, relationshipOperation) => {
|
|
68
|
-
const { useDAC } = this.config;
|
|
69
|
-
if (useDAC) {
|
|
70
|
-
const { dacConfig } = this.config;
|
|
71
|
-
const { relationshipResourcePathPrefix, accessingRole, getDACRoleById } = dacConfig;
|
|
72
|
-
return (0, DataAccessControl_1.mergeDACAccessResults)((0, DataAccessControl_1.getResourceAccessByDACRole)((0, DACUtils_1.getItemRelationshipDACResourcePath)(relationshipResourcePathPrefix, relationshipOperation, itemRelationship), accessingRole, getDACRoleById, this.dacRoleCache), (0, DataAccessControl_1.getResourceAccessByDACRole)((0, DACUtils_1.getItemRelationshipDACResourcePath)(relationshipResourcePathPrefix, TypeInfoORM_1.OperationGroup.ALL_RELATIONSHIP_OPERATIONS, itemRelationship), accessingRole, getDACRoleById, this.dacRoleCache), (0, DataAccessControl_1.getResourceAccessByDACRole)((0, DACUtils_1.getItemRelationshipDACResourcePath)(relationshipResourcePathPrefix, TypeInfoORM_1.OperationGroup.ALL_OPERATIONS, itemRelationship), accessingRole, getDACRoleById, this.dacRoleCache));
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
return {
|
|
76
|
-
allowed: true,
|
|
77
|
-
denied: false,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
getWrappedDriverWithExtendedErrorData = (driver, extendedData) => {
|
|
82
|
-
const driverMethodList = [
|
|
83
|
-
"createItem",
|
|
84
|
-
"readItem",
|
|
85
|
-
"updateItem",
|
|
86
|
-
"deleteItem",
|
|
87
|
-
"listItems",
|
|
88
|
-
];
|
|
89
|
-
const driverWrapper = {};
|
|
90
|
-
for (const dM of driverMethodList) {
|
|
91
|
-
driverWrapper[dM] = (0, exports.getDriverMethodWithModifiedError)(extendedData, driver, dM);
|
|
92
|
-
}
|
|
93
|
-
return driverWrapper;
|
|
94
|
-
};
|
|
95
|
-
getDriverInternal = (typeName) => {
|
|
96
|
-
const driver = this.config.getDriver(typeName);
|
|
97
|
-
if (!driver) {
|
|
98
|
-
throw new Error(TypeInfoORM_1.TypeInfoORMServiceError.INVALID_DRIVER);
|
|
99
|
-
}
|
|
100
|
-
return this.getWrappedDriverWithExtendedErrorData(driver, { typeName });
|
|
101
|
-
};
|
|
102
|
-
getRelationshipDriverInternal = (typeName, fieldName) => {
|
|
103
|
-
const driver = this.config.getRelationshipDriver(typeName, fieldName);
|
|
104
|
-
if (!driver) {
|
|
105
|
-
throw new Error(TypeInfoORM_1.TypeInfoORMServiceError.INVALID_RELATIONSHIP_DRIVER);
|
|
106
|
-
}
|
|
107
|
-
return this.getWrappedDriverWithExtendedErrorData(driver, {
|
|
108
|
-
typeName,
|
|
109
|
-
fieldName,
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
getTypeInfo = (typeName) => {
|
|
113
|
-
const typeInfo = this.config.typeInfoMap[typeName];
|
|
114
|
-
if (!typeInfo) {
|
|
115
|
-
throw {
|
|
116
|
-
message: TypeInfoORM_1.TypeInfoORMServiceError.INVALID_TYPE_INFO,
|
|
117
|
-
typeName,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
const { primaryField } = typeInfo;
|
|
122
|
-
if (typeof primaryField === "undefined") {
|
|
123
|
-
throw {
|
|
124
|
-
message: TypeInfoORM_1.TypeInfoORMServiceError.TYPE_INFO_MISSING_PRIMARY_FIELD,
|
|
125
|
-
typeName,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return typeInfo;
|
|
130
|
-
};
|
|
131
|
-
validateReadOperation = (typeName, selectedFields) => {
|
|
132
|
-
const typeInfo = this.getTypeInfo(typeName);
|
|
133
|
-
const { fields = {} } = typeInfo;
|
|
134
|
-
const cleanSelectedFields = this.getCleanSelectedFields(typeName, selectedFields);
|
|
135
|
-
const results = {
|
|
136
|
-
typeName,
|
|
137
|
-
valid: !!typeInfo,
|
|
138
|
-
error: !!typeInfo ? "" : Validation_1.ERROR_MESSAGE_CONSTANTS.TYPE_DOES_NOT_EXIST,
|
|
139
|
-
errorMap: {},
|
|
140
|
-
};
|
|
141
|
-
const { valid: operationValid, error: operationError, errorMap: operationErrorMap, } = (0, Validation_1.validateTypeOperationAllowed)(typeName, cleanSelectedFields ? cleanSelectedFields : Object.keys(fields), TypeInfo_1.TypeOperation.READ, typeInfo);
|
|
142
|
-
results.valid = (0, Validation_1.getValidityValue)(results.valid, operationValid);
|
|
143
|
-
results.error = operationError;
|
|
144
|
-
for (const oE in operationErrorMap) {
|
|
145
|
-
const existingError = results.errorMap[oE] ?? [];
|
|
146
|
-
results.errorMap[oE] = existingError
|
|
147
|
-
? [...existingError, ...operationErrorMap[oE]]
|
|
148
|
-
: operationErrorMap[oE];
|
|
149
|
-
}
|
|
150
|
-
if (!operationValid && operationError) {
|
|
151
|
-
results.error = operationError;
|
|
152
|
-
}
|
|
153
|
-
if (!results.valid) {
|
|
154
|
-
throw results;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
validate = (typeName, item, typeOperation, itemIsPartial) => {
|
|
158
|
-
const validationResults = (0, Validation_1.validateTypeInfoValue)(item, typeName, this.config.typeInfoMap, true, this.config.customValidators, typeOperation, Validation_1.RelationshipValidationType.STRICT_EXCLUDE, itemIsPartial);
|
|
159
|
-
if (!validationResults.valid) {
|
|
160
|
-
throw validationResults;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
getCleanItem = (typeName, item, dacFieldResources, selectedFields) => {
|
|
164
|
-
const typeInfo = this.getTypeInfo(typeName);
|
|
165
|
-
const cleanSelectedFields = this.getCleanSelectedFields(typeName, selectedFields);
|
|
166
|
-
const itemCleanedByTypeInfo = (0, Utils_1.removeUnselectedFieldsFromDataItem)((0, Utils_1.removeTypeReferenceFieldsFromDataItem)(typeInfo, (0, Utils_1.removeNonexistentFieldsFromDataItem)(typeInfo, item)), cleanSelectedFields);
|
|
167
|
-
if (dacFieldResources) {
|
|
168
|
-
const itemCleanedByDAC = {};
|
|
169
|
-
for (const fN in itemCleanedByTypeInfo) {
|
|
170
|
-
const fR = dacFieldResources[fN];
|
|
171
|
-
if (fR) {
|
|
172
|
-
const { allowed, denied } = fR;
|
|
173
|
-
if (allowed && !denied) {
|
|
174
|
-
itemCleanedByDAC[fN] = itemCleanedByTypeInfo[fN];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
itemCleanedByDAC[fN] = itemCleanedByTypeInfo[fN];
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return itemCleanedByDAC;
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
return itemCleanedByTypeInfo;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
getCleanSelectedFields = (typeName, selectedFields) => {
|
|
188
|
-
const typeInfo = this.getTypeInfo(typeName);
|
|
189
|
-
const { primaryField } = typeInfo;
|
|
190
|
-
let cleanSelectedFields = (0, Utils_1.removeTypeReferenceFieldsFromSelectedFields)(typeInfo, (0, Utils_1.removeNonexistentFieldsFromSelectedFields)(typeInfo, selectedFields));
|
|
191
|
-
if (primaryField &&
|
|
192
|
-
Array.isArray(cleanSelectedFields) &&
|
|
193
|
-
!cleanSelectedFields.includes(primaryField)) {
|
|
194
|
-
// IMPORTANT: Ensure that the primary field is always included in the selected fields.
|
|
195
|
-
cleanSelectedFields = [...cleanSelectedFields, primaryField];
|
|
196
|
-
}
|
|
197
|
-
return cleanSelectedFields;
|
|
198
|
-
};
|
|
199
|
-
validateRelationshipItem = (relationshipItem, omitFields = []) => {
|
|
200
|
-
const validationResults = (0, ItemRelationships_1.validateRelationshipItem)(relationshipItem, omitFields);
|
|
201
|
-
if (!validationResults.valid) {
|
|
202
|
-
throw validationResults;
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
const { fromTypeName, fromTypeFieldName } = relationshipItem;
|
|
206
|
-
const { fields: { [fromTypeFieldName]: { typeReference = undefined } = {}, } = {}, } = this.getTypeInfo(fromTypeName);
|
|
207
|
-
const relatedTypeInfo = typeReference
|
|
208
|
-
? this.getTypeInfo(typeReference)
|
|
209
|
-
: undefined;
|
|
210
|
-
if (!relatedTypeInfo) {
|
|
211
|
-
const relationshipValidationResults = {
|
|
212
|
-
typeName: fromTypeName,
|
|
213
|
-
valid: false,
|
|
214
|
-
error: TypeInfoORM_1.TypeInfoORMServiceError.INVALID_RELATIONSHIP,
|
|
215
|
-
errorMap: {},
|
|
216
|
-
};
|
|
217
|
-
throw relationshipValidationResults;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
cleanupRelationships = async (relationshipOriginatingItem) => {
|
|
222
|
-
if (this.config.createRelationshipCleanupItem) {
|
|
223
|
-
await this.config.createRelationshipCleanupItem(relationshipOriginatingItem);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* Create a new relationship between two items.
|
|
228
|
-
* */
|
|
229
|
-
createRelationship = async (relationshipItem) => {
|
|
230
|
-
this.validateRelationshipItem(relationshipItem);
|
|
231
|
-
const { allowed: createAllowed, denied: createDenied } = this.getRelationshipDACValidation(relationshipItem, TypeInfoORM_1.RelationshipOperation.SET);
|
|
232
|
-
if (createDenied || !createAllowed) {
|
|
233
|
-
throw {
|
|
234
|
-
message: TypeInfoORM_1.TypeInfoORMServiceError.INVALID_OPERATION,
|
|
235
|
-
relationshipItem,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
const cleanedItem = (0, exports.cleanRelationshipItem)(relationshipItem);
|
|
240
|
-
const { fromTypeName, fromTypeFieldName } = cleanedItem;
|
|
241
|
-
const { fields: { [fromTypeFieldName]: { array: relationshipIsMultiple = false } = {}, } = {}, } = this.getTypeInfo(fromTypeName);
|
|
242
|
-
const driver = this.getRelationshipDriverInternal(fromTypeName, fromTypeFieldName);
|
|
243
|
-
if (relationshipIsMultiple) {
|
|
244
|
-
await driver.createItem(cleanedItem);
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
// VALIDATION: Need to update when the field is not an array.
|
|
248
|
-
const { items: [{ [ItemRelationshipInfoTypes_1.ItemRelationshipInfoIdentifyingKeys.id]: existingIdentifier },] = [{}], } = (await driver.listItems({
|
|
249
|
-
criteria: {
|
|
250
|
-
logicalOperator: SearchTypes_1.LogicalOperators.AND,
|
|
251
|
-
fieldCriteria: [
|
|
252
|
-
{
|
|
253
|
-
fieldName: ItemRelationshipInfoTypes_1.ItemRelationshipInfoKeys.fromTypeName,
|
|
254
|
-
operator: SearchTypes_1.ComparisonOperators.EQUALS,
|
|
255
|
-
value: fromTypeName,
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
fieldName: ItemRelationshipInfoTypes_1.ItemRelationshipInfoKeys.fromTypeFieldName,
|
|
259
|
-
operator: SearchTypes_1.ComparisonOperators.EQUALS,
|
|
260
|
-
value: fromTypeFieldName,
|
|
261
|
-
},
|
|
262
|
-
],
|
|
263
|
-
},
|
|
264
|
-
itemsPerPage: 1,
|
|
265
|
-
}, [ItemRelationshipInfoTypes_1.ItemRelationshipInfoIdentifyingKeys.id]));
|
|
266
|
-
if (existingIdentifier) {
|
|
267
|
-
await driver.updateItem(existingIdentifier, cleanedItem);
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
await driver.createItem(cleanedItem);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return true;
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
/**
|
|
277
|
-
* Delete a relationship between two items.
|
|
278
|
-
* */
|
|
279
|
-
deleteRelationship = async (relationshipItem) => {
|
|
280
|
-
this.validateRelationshipItem(relationshipItem);
|
|
281
|
-
const { allowed: deleteAllowed, denied: deleteDenied } = this.getRelationshipDACValidation(relationshipItem, TypeInfoORM_1.RelationshipOperation.UNSET);
|
|
282
|
-
if (deleteDenied || !deleteAllowed) {
|
|
283
|
-
throw {
|
|
284
|
-
message: TypeInfoORM_1.TypeInfoORMServiceError.INVALID_OPERATION,
|
|
285
|
-
relationshipItem,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
const cleanedItem = (0, exports.cleanRelationshipItem)(relationshipItem);
|
|
290
|
-
const { fromTypeName, fromTypeFieldName, fromTypePrimaryFieldValue, toTypePrimaryFieldValue, } = cleanedItem;
|
|
291
|
-
const driver = this.getRelationshipDriverInternal(fromTypeName, fromTypeFieldName);
|
|
292
|
-
const { items: itemList = [], cursor } = (await driver.listItems({
|
|
293
|
-
criteria: {
|
|
294
|
-
logicalOperator: SearchTypes_1.LogicalOperators.AND,
|
|
295
|
-
fieldCriteria: [
|
|
296
|
-
{
|
|
297
|
-
fieldName: ItemRelationshipInfoTypes_1.ItemRelationshipInfoKeys.fromTypeName,
|
|
298
|
-
operator: SearchTypes_1.ComparisonOperators.EQUALS,
|
|
299
|
-
value: fromTypeName,
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
fieldName: ItemRelationshipInfoTypes_1.ItemRelationshipInfoKeys.fromTypePrimaryFieldValue,
|
|
303
|
-
operator: SearchTypes_1.ComparisonOperators.EQUALS,
|
|
304
|
-
value: fromTypePrimaryFieldValue,
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
fieldName: ItemRelationshipInfoTypes_1.ItemRelationshipInfoKeys.fromTypeFieldName,
|
|
308
|
-
operator: SearchTypes_1.ComparisonOperators.EQUALS,
|
|
309
|
-
value: fromTypeFieldName,
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
fieldName: ItemRelationshipInfoTypes_1.ItemRelationshipInfoKeys.toTypePrimaryFieldValue,
|
|
313
|
-
operator: SearchTypes_1.ComparisonOperators.EQUALS,
|
|
314
|
-
value: toTypePrimaryFieldValue,
|
|
315
|
-
},
|
|
316
|
-
],
|
|
317
|
-
},
|
|
318
|
-
}));
|
|
319
|
-
for (const item of itemList) {
|
|
320
|
-
const { id: itemId } = item;
|
|
321
|
-
await driver.deleteItem(itemId);
|
|
322
|
-
}
|
|
323
|
-
return {
|
|
324
|
-
success: true,
|
|
325
|
-
remainingItemsExist: !!cursor,
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
/**
|
|
330
|
-
* List the relationships for a given item.
|
|
331
|
-
* */
|
|
332
|
-
listRelationships = async (config) => {
|
|
333
|
-
const { useDAC } = this.config;
|
|
334
|
-
const { relationshipItemOrigin, ...remainingConfig } = config;
|
|
335
|
-
this.validateRelationshipItem(relationshipItemOrigin);
|
|
336
|
-
const { fromTypeName, fromTypeFieldName, fromTypePrimaryFieldValue } = relationshipItemOrigin;
|
|
337
|
-
const driver = this.getRelationshipDriverInternal(fromTypeName, fromTypeFieldName);
|
|
338
|
-
const results = await driver.listItems({
|
|
339
|
-
...remainingConfig,
|
|
340
|
-
criteria: {
|
|
341
|
-
logicalOperator: SearchTypes_1.LogicalOperators.AND,
|
|
342
|
-
fieldCriteria: [
|
|
343
|
-
{
|
|
344
|
-
fieldName: ItemRelationshipInfoTypes_1.ItemRelationshipInfoKeys.fromTypeName,
|
|
345
|
-
operator: SearchTypes_1.ComparisonOperators.EQUALS,
|
|
346
|
-
value: fromTypeName,
|
|
347
|
-
},
|
|
348
|
-
{
|
|
349
|
-
fieldName: ItemRelationshipInfoTypes_1.ItemRelationshipInfoKeys.fromTypeFieldName,
|
|
350
|
-
operator: SearchTypes_1.ComparisonOperators.EQUALS,
|
|
351
|
-
value: fromTypeFieldName,
|
|
352
|
-
},
|
|
353
|
-
{
|
|
354
|
-
fieldName: ItemRelationshipInfoTypes_1.ItemRelationshipInfoKeys.fromTypePrimaryFieldValue,
|
|
355
|
-
operator: SearchTypes_1.ComparisonOperators.EQUALS,
|
|
356
|
-
value: fromTypePrimaryFieldValue,
|
|
357
|
-
},
|
|
358
|
-
],
|
|
359
|
-
},
|
|
360
|
-
});
|
|
361
|
-
if (useDAC) {
|
|
362
|
-
const { items = [], cursor: nextCursor } = results;
|
|
363
|
-
const revisedItems = [];
|
|
364
|
-
for (const rItm of items) {
|
|
365
|
-
const { allowed: readAllowed, denied: readDenied } = this.getRelationshipDACValidation(rItm, TypeInfoORM_1.RelationshipOperation.GET);
|
|
366
|
-
const listDenied = readDenied || !readAllowed;
|
|
367
|
-
if (!listDenied) {
|
|
368
|
-
revisedItems.push(rItm);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
return {
|
|
372
|
-
items: revisedItems,
|
|
373
|
-
cursor: nextCursor,
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
return results;
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
listRelatedItems = async (config, selectedFields) => {
|
|
381
|
-
const { relationshipItemOrigin: { fromTypeName, fromTypeFieldName }, } = config;
|
|
382
|
-
const { fields: { [fromTypeFieldName]: { typeReference = undefined, } = {}, } = {}, } = this.getTypeInfo(fromTypeName);
|
|
383
|
-
const targetTypeInfo = typeof typeReference === "string"
|
|
384
|
-
? this.getTypeInfo(typeReference)
|
|
385
|
-
: undefined;
|
|
386
|
-
if (typeof typeReference === "string" &&
|
|
387
|
-
typeof targetTypeInfo !== "undefined") {
|
|
388
|
-
const { cursor, items: relationshipItems = [] } = await this.listRelationships(config);
|
|
389
|
-
const items = [];
|
|
390
|
-
for (const rItm of relationshipItems) {
|
|
391
|
-
const { toTypePrimaryFieldValue } = rItm;
|
|
392
|
-
const itm = await this.read(typeReference, toTypePrimaryFieldValue, selectedFields);
|
|
393
|
-
items.push(itm);
|
|
394
|
-
}
|
|
395
|
-
return {
|
|
396
|
-
items,
|
|
397
|
-
cursor,
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
throw new Error(TypeInfoORM_1.TypeInfoORMServiceError.INVALID_RELATIONSHIP);
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
/**
|
|
405
|
-
* Create a new item of the given type.
|
|
406
|
-
* */
|
|
407
|
-
create = async (typeName, item) => {
|
|
408
|
-
this.validate(typeName, item, TypeInfo_1.TypeOperation.CREATE);
|
|
409
|
-
const { allowed: createAllowed, denied: createDenied, fieldsResources = {}, } = this.getItemDACValidation(item, typeName, TypeInfo_1.TypeOperation.CREATE);
|
|
410
|
-
if (createDenied || !createAllowed) {
|
|
411
|
-
throw {
|
|
412
|
-
message: TypeInfoORM_1.TypeInfoORMServiceError.INVALID_OPERATION,
|
|
413
|
-
typeName,
|
|
414
|
-
item,
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
const driver = this.getDriverInternal(typeName);
|
|
419
|
-
const cleanItem = this.getCleanItem(typeName, item, fieldsResources);
|
|
420
|
-
const newIdentifier = await driver.createItem(cleanItem);
|
|
421
|
-
return newIdentifier;
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
/**
|
|
425
|
-
* Read an existing item of the given type.
|
|
426
|
-
* */
|
|
427
|
-
read = async (typeName, primaryFieldValue, selectedFields) => {
|
|
428
|
-
const cleanSelectedFields = this.getCleanSelectedFields(typeName, selectedFields);
|
|
429
|
-
this.validateReadOperation(typeName, cleanSelectedFields);
|
|
430
|
-
const { useDAC } = this.config;
|
|
431
|
-
const driver = this.getDriverInternal(typeName);
|
|
432
|
-
const item = await driver.readItem(primaryFieldValue,
|
|
433
|
-
// SECURITY: Dac validation could fail when `item` is missing unselected fields.
|
|
434
|
-
// CANNOT pass selected fields to `driver` when DAC is enabled.
|
|
435
|
-
useDAC ? undefined : cleanSelectedFields);
|
|
436
|
-
const { allowed: readAllowed, denied: readDenied, fieldsResources = {}, } = this.getItemDACValidation(item, typeName, TypeInfo_1.TypeOperation.READ);
|
|
437
|
-
if (readDenied || !readAllowed) {
|
|
438
|
-
throw {
|
|
439
|
-
message: TypeInfoORM_1.TypeInfoORMServiceError.INVALID_OPERATION,
|
|
440
|
-
typeName,
|
|
441
|
-
primaryFieldValue,
|
|
442
|
-
selectedFields,
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
const cleanItem = this.getCleanItem(typeName, item, fieldsResources, cleanSelectedFields);
|
|
447
|
-
return cleanItem;
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
/**
|
|
451
|
-
* Update an existing item of the given type.
|
|
452
|
-
*
|
|
453
|
-
* This update will always act as a **patch**.
|
|
454
|
-
* Use `null` to signify the deletion of a field.
|
|
455
|
-
* Assign values to **all** fields to perform a **replacement**.
|
|
456
|
-
*
|
|
457
|
-
* The `item` **must always** contain its **primary field value**.
|
|
458
|
-
* */
|
|
459
|
-
update = async (typeName, item) => {
|
|
460
|
-
this.validate(typeName, item, TypeInfo_1.TypeOperation.UPDATE, true);
|
|
461
|
-
const { primaryField } = this.getTypeInfo(typeName);
|
|
462
|
-
const primaryFieldValue = typeof item === "object" && item !== null
|
|
463
|
-
? item[primaryField]
|
|
464
|
-
: undefined;
|
|
465
|
-
if (typeof primaryFieldValue === "undefined") {
|
|
466
|
-
const validationResults = {
|
|
467
|
-
typeName,
|
|
468
|
-
valid: false,
|
|
469
|
-
error: TypeInfoORM_1.TypeInfoORMServiceError.NO_PRIMARY_FIELD_VALUE_SUPPLIED,
|
|
470
|
-
errorMap: {},
|
|
471
|
-
};
|
|
472
|
-
throw validationResults;
|
|
473
|
-
}
|
|
474
|
-
else {
|
|
475
|
-
const driver = this.getDriverInternal(typeName);
|
|
476
|
-
const initialCleanItem = this.getCleanItem(typeName, item, {});
|
|
477
|
-
const { allowed: updateAllowed, denied: updateDenied, fieldsResources = {}, } = this.getItemDACValidation(initialCleanItem, typeName, TypeInfo_1.TypeOperation.UPDATE);
|
|
478
|
-
if (updateDenied || !updateAllowed) {
|
|
479
|
-
throw {
|
|
480
|
-
message: TypeInfoORM_1.TypeInfoORMServiceError.INVALID_OPERATION,
|
|
481
|
-
typeName,
|
|
482
|
-
item,
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
// SECURITY: Update could potentially delete fields. Use `fieldsResources` from `TypeOperation.DELETE` to prevent this issue.
|
|
487
|
-
const { fieldsResources: fieldsResourcesForDeleteOperation = {} } = this.getItemDACValidation(initialCleanItem, typeName, TypeInfo_1.TypeOperation.DELETE);
|
|
488
|
-
const fieldsResourcesForUpdateOperationForNullFields = Object.keys(initialCleanItem).reduce((acc, fN) => ({
|
|
489
|
-
...acc,
|
|
490
|
-
// TRICKY: Remove delete fields for fields not being deleted.
|
|
491
|
-
...(initialCleanItem[fN] === null
|
|
492
|
-
? {
|
|
493
|
-
[fN]: fieldsResourcesForDeleteOperation[fN],
|
|
494
|
-
}
|
|
495
|
-
: undefined),
|
|
496
|
-
}), {});
|
|
497
|
-
const { fieldsResources: mergedFieldsResources = {} } = (0, DACUtils_1.mergeDACDataItemResourceAccessResultMaps)({
|
|
498
|
-
allowed: true,
|
|
499
|
-
denied: false,
|
|
500
|
-
fieldsResources,
|
|
501
|
-
}, {
|
|
502
|
-
allowed: true,
|
|
503
|
-
denied: false,
|
|
504
|
-
fieldsResources: fieldsResourcesForUpdateOperationForNullFields,
|
|
505
|
-
});
|
|
506
|
-
const cleanItem = this.getCleanItem(typeName, item, mergedFieldsResources);
|
|
507
|
-
const result = await driver.updateItem(primaryFieldValue, cleanItem);
|
|
508
|
-
return result;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
/**
|
|
513
|
-
* Delete an existing item of the given type.
|
|
514
|
-
* */
|
|
515
|
-
delete = async (typeName, primaryFieldValue) => {
|
|
516
|
-
const { useDAC } = this.config;
|
|
517
|
-
const { primaryField } = this.getTypeInfo(typeName);
|
|
518
|
-
const itemWithPrimaryFieldOnly = {
|
|
519
|
-
[primaryField]: primaryFieldValue,
|
|
520
|
-
};
|
|
521
|
-
this.validate(typeName, itemWithPrimaryFieldOnly, TypeInfo_1.TypeOperation.DELETE);
|
|
522
|
-
const driver = this.getDriverInternal(typeName);
|
|
523
|
-
const existingItem =
|
|
524
|
-
// SECURITY: Dac validation could fail when `item` is missing unselected fields.
|
|
525
|
-
useDAC
|
|
526
|
-
? await driver.readItem(primaryFieldValue)
|
|
527
|
-
: itemWithPrimaryFieldOnly;
|
|
528
|
-
const { allowed: deleteAllowed, denied: deleteDenied } = this.getItemDACValidation(existingItem, typeName, TypeInfo_1.TypeOperation.DELETE);
|
|
529
|
-
if (deleteDenied || !deleteAllowed) {
|
|
530
|
-
throw {
|
|
531
|
-
message: TypeInfoORM_1.TypeInfoORMServiceError.INVALID_OPERATION,
|
|
532
|
-
typeName,
|
|
533
|
-
primaryFieldValue,
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
const result = await driver.deleteItem(primaryFieldValue);
|
|
538
|
-
await this.cleanupRelationships({
|
|
539
|
-
fromTypeName: typeName,
|
|
540
|
-
fromTypePrimaryFieldValue: primaryFieldValue,
|
|
541
|
-
});
|
|
542
|
-
return result;
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
/**
|
|
546
|
-
* List items of the given type, with the given criteria.
|
|
547
|
-
* */
|
|
548
|
-
list = async (typeName, config, selectedFields) => {
|
|
549
|
-
const cleanSelectedFields = this.getCleanSelectedFields(typeName, selectedFields);
|
|
550
|
-
this.validateReadOperation(typeName, cleanSelectedFields);
|
|
551
|
-
const { typeInfoMap, useDAC } = this.config;
|
|
552
|
-
const typeInfo = this.getTypeInfo(typeName);
|
|
553
|
-
const { fields: {} = {} } = typeInfo;
|
|
554
|
-
const { criteria } = config;
|
|
555
|
-
const { fieldCriteria = [] } = criteria || {};
|
|
556
|
-
const searchFieldValidationResults = (0, SearchValidation_1.validateSearchFields)(typeName, typeInfoMap, fieldCriteria, true);
|
|
557
|
-
const { valid: searchFieldsValid } = searchFieldValidationResults;
|
|
558
|
-
if (searchFieldsValid) {
|
|
559
|
-
const driver = this.getDriverInternal(typeName);
|
|
560
|
-
const fieldsResourcesCache = [];
|
|
561
|
-
const results = await (0, ListItemUtils_1.executeDriverListItems)(driver, config, useDAC
|
|
562
|
-
? (item) => {
|
|
563
|
-
const { allowed: readAllowed, denied: readDenied, fieldsResources = {}, } = this.getItemDACValidation(item, typeName, TypeInfo_1.TypeOperation.READ);
|
|
564
|
-
const listDenied = readDenied || !readAllowed;
|
|
565
|
-
if (!listDenied) {
|
|
566
|
-
fieldsResourcesCache.push(fieldsResources);
|
|
567
|
-
}
|
|
568
|
-
return !listDenied;
|
|
569
|
-
}
|
|
570
|
-
: undefined, (item) => {
|
|
571
|
-
const fieldsResources = fieldsResourcesCache[fieldsResourcesCache.length - 1];
|
|
572
|
-
return this.getCleanItem(typeName, item, fieldsResources, cleanSelectedFields);
|
|
573
|
-
}, cleanSelectedFields);
|
|
574
|
-
return results;
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
throw searchFieldValidationResults;
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
exports.TypeInfoORMService = TypeInfoORMService;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
export type Trace = (...content: any[]) => void;
|
|
2
|
-
export type Logger = {
|
|
3
|
-
trace?: string | Trace;
|
|
4
|
-
debug: Trace;
|
|
5
|
-
info: Trace;
|
|
6
|
-
warn: Trace;
|
|
7
|
-
error: Trace;
|
|
8
|
-
};
|
|
9
|
-
export type Endpoint = {
|
|
10
|
-
protocol: string;
|
|
11
|
-
hostname: string;
|
|
12
|
-
port?: string;
|
|
13
|
-
path: string;
|
|
14
|
-
query?: string;
|
|
15
|
-
};
|
|
16
|
-
export type RetryStrategy = {
|
|
17
|
-
mode?: string;
|
|
18
|
-
retry: any;
|
|
19
|
-
};
|
|
20
|
-
export type DynamoDBSpecificConfig = {
|
|
21
|
-
requestHandler?: string;
|
|
22
|
-
apiVersion?: string;
|
|
23
|
-
sha256?: string;
|
|
24
|
-
urlParser?: string;
|
|
25
|
-
bodyLengthChecker?: string;
|
|
26
|
-
streamCollector?: string;
|
|
27
|
-
base64Decoder?: string;
|
|
28
|
-
base64Encoder?: string;
|
|
29
|
-
utf8Decoder?: string;
|
|
30
|
-
utf8Encoder?: string;
|
|
31
|
-
runtime?: string;
|
|
32
|
-
disableHostPrefix?: string | false | true;
|
|
33
|
-
serviceId?: string;
|
|
34
|
-
useDualstackEndpoint?: string | false | true;
|
|
35
|
-
useFipsEndpoint?: string | false | true;
|
|
36
|
-
defaultUserAgentProvider?: string;
|
|
37
|
-
region?: string;
|
|
38
|
-
credentialDefaultProvider?: string;
|
|
39
|
-
maxAttempts?: string;
|
|
40
|
-
retryMode?: string;
|
|
41
|
-
logger?: string | Logger;
|
|
42
|
-
extensions?: string;
|
|
43
|
-
/**
|
|
44
|
-
* @allowCustomSelection
|
|
45
|
-
* */
|
|
46
|
-
defaultsMode?: "standard" | "in-region" | "cross-region" | "mobile" | "auto" | "legacy";
|
|
47
|
-
endpointDiscoveryEnabledProvider?: string;
|
|
48
|
-
endpoint?: string | Endpoint;
|
|
49
|
-
endpointProvider?: string;
|
|
50
|
-
tls?: string | false | true;
|
|
51
|
-
retryStrategy?: string | RetryStrategy;
|
|
52
|
-
customUserAgent?: string;
|
|
53
|
-
httpAuthSchemes?: string;
|
|
54
|
-
httpAuthSchemeProvider?: string;
|
|
55
|
-
credentials?: string;
|
|
56
|
-
signer?: string;
|
|
57
|
-
signingEscapePath?: string | false | true;
|
|
58
|
-
systemClockOffset?: string;
|
|
59
|
-
signingRegion?: string;
|
|
60
|
-
signerConstructor?: string;
|
|
61
|
-
endpointCacheSize?: string;
|
|
62
|
-
endpointDiscoveryEnabled?: string | false | true;
|
|
63
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { DataItemDBDriver, DataItemDBDriverConfig, SupportedDataItemDBDriverEntry } from "./common";
|
|
2
|
-
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
3
|
-
import { TypeInfoDataItem } from "../../../common/TypeParsing/TypeInfo";
|
|
4
|
-
import { ListItemsConfig, ListItemsResults } from "../../../common/SearchTypes";
|
|
5
|
-
/**
|
|
6
|
-
* A {@link DataItemDBDriver} that uses DynamoDB as its database.
|
|
7
|
-
* */
|
|
8
|
-
export declare class DynamoDBDataItemDBDriver<ItemType extends TypeInfoDataItem, UniquelyIdentifyingFieldName extends keyof ItemType> implements DataItemDBDriver<ItemType, UniquelyIdentifyingFieldName> {
|
|
9
|
-
protected config: DataItemDBDriverConfig<ItemType, UniquelyIdentifyingFieldName>;
|
|
10
|
-
protected dynamoDBClient: DynamoDBClient;
|
|
11
|
-
constructor(config: DataItemDBDriverConfig<ItemType, UniquelyIdentifyingFieldName>);
|
|
12
|
-
/**
|
|
13
|
-
* Create an item in the database.
|
|
14
|
-
*/
|
|
15
|
-
createItem: (newItem: Partial<Omit<ItemType, UniquelyIdentifyingFieldName>>) => Promise<ItemType[UniquelyIdentifyingFieldName]>;
|
|
16
|
-
/**
|
|
17
|
-
* Read an item from the database.
|
|
18
|
-
*/
|
|
19
|
-
readItem: (uniqueIdentifier: ItemType[UniquelyIdentifyingFieldName], selectedFields?: (keyof ItemType)[]) => Promise<Partial<ItemType>>;
|
|
20
|
-
/**
|
|
21
|
-
* Update an item in the database.
|
|
22
|
-
*/
|
|
23
|
-
updateItem: (uniqueIdentifier: ItemType[UniquelyIdentifyingFieldName], updatedItem: Partial<ItemType>) => Promise<boolean>;
|
|
24
|
-
/**
|
|
25
|
-
* Delete an item from the database.
|
|
26
|
-
*/
|
|
27
|
-
deleteItem: (uniqueIdentifier: ItemType[UniquelyIdentifyingFieldName]) => Promise<boolean>;
|
|
28
|
-
/**
|
|
29
|
-
* List items from the database.
|
|
30
|
-
*/
|
|
31
|
-
listItems: (config: ListItemsConfig, selectedFields?: (keyof ItemType)[]) => Promise<ListItemsResults<ItemType>>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* The supported DB driver entry for the DynamoDB {@link DataItemDBDriver}.
|
|
35
|
-
* */
|
|
36
|
-
export declare const DynamoDBSupportedDataItemDBDriverEntry: SupportedDataItemDBDriverEntry;
|