@expo/entity 0.47.0 → 0.49.0
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/LICENSE +21 -0
- package/build/src/EntityDatabaseAdapter.js +12 -5
- package/build/src/EntityDatabaseAdapter.js.map +1 -1
- package/build/src/EntityFields.d.ts +3 -1
- package/build/src/EntityFields.js +4 -2
- package/build/src/EntityFields.js.map +1 -1
- package/build/src/entityUtils.d.ts +2 -2
- package/build/src/entityUtils.js.map +1 -1
- package/build/src/errors/EntityCacheAdapterError.d.ts +7 -0
- package/build/src/errors/EntityCacheAdapterError.js +7 -0
- package/build/src/errors/EntityCacheAdapterError.js.map +1 -1
- package/build/src/errors/EntityDatabaseAdapterError.d.ts +78 -0
- package/build/src/errors/EntityDatabaseAdapterError.js +84 -1
- package/build/src/errors/EntityDatabaseAdapterError.js.map +1 -1
- package/build/src/errors/EntityError.d.ts +14 -0
- package/build/src/errors/EntityError.js +14 -0
- package/build/src/errors/EntityError.js.map +1 -1
- package/build/src/errors/EntityInvalidFieldValueError.d.ts +3 -0
- package/build/src/errors/EntityInvalidFieldValueError.js +3 -0
- package/build/src/errors/EntityInvalidFieldValueError.js.map +1 -1
- package/build/src/errors/EntityNotAuthorizedError.d.ts +3 -0
- package/build/src/errors/EntityNotAuthorizedError.js +3 -0
- package/build/src/errors/EntityNotAuthorizedError.js.map +1 -1
- package/build/src/errors/EntityNotFoundError.d.ts +3 -0
- package/build/src/errors/EntityNotFoundError.js +3 -0
- package/build/src/errors/EntityNotFoundError.js.map +1 -1
- package/package.json +3 -2
- package/src/EntityDatabaseAdapter.ts +18 -5
- package/src/EntityFields.ts +4 -2
- package/src/__tests__/EntityDatabaseAdapter-test.ts +12 -5
- package/src/__tests__/EntityFields-test.ts +1 -1
- package/src/entityUtils.ts +5 -3
- package/src/errors/EntityCacheAdapterError.ts +7 -0
- package/src/errors/EntityDatabaseAdapterError.ts +83 -0
- package/src/errors/EntityError.ts +14 -0
- package/src/errors/EntityInvalidFieldValueError.ts +3 -0
- package/src/errors/EntityNotAuthorizedError.ts +3 -0
- package/src/errors/EntityNotFoundError.ts +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-present 650 Industries, Inc. (aka Expo)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.EntityDatabaseAdapter = exports.OrderByOrdering = void 0;
|
|
7
7
|
exports.isSingleValueFieldEqualityCondition = isSingleValueFieldEqualityCondition;
|
|
8
8
|
const invariant_1 = __importDefault(require("invariant"));
|
|
9
|
+
const EntityDatabaseAdapterError_1 = require("./errors/EntityDatabaseAdapterError");
|
|
9
10
|
const EntityFieldTransformationUtils_1 = require("./internal/EntityFieldTransformationUtils");
|
|
10
11
|
function isSingleValueFieldEqualityCondition(condition) {
|
|
11
12
|
return condition.fieldValue !== undefined;
|
|
@@ -106,11 +107,14 @@ class EntityDatabaseAdapter {
|
|
|
106
107
|
async insertAsync(queryContext, object) {
|
|
107
108
|
const dbObject = (0, EntityFieldTransformationUtils_1.transformFieldsToDatabaseObject)(this.entityConfiguration, this.fieldTransformerMap, object);
|
|
108
109
|
const results = await this.insertInternalAsync(queryContext.getQueryInterface(), this.entityConfiguration.tableName, dbObject);
|
|
110
|
+
// These should never happen with a properly implemented database adapter unless the underlying database has weird triggers
|
|
111
|
+
// or something.
|
|
112
|
+
// These errors are exposed to help application developers detect and diagnose such issues.
|
|
109
113
|
if (results.length > 1) {
|
|
110
|
-
throw new
|
|
114
|
+
throw new EntityDatabaseAdapterError_1.EntityDatabaseAdapterExcessiveInsertResultError(`Excessive results from database adapter insert: ${this.entityConfiguration.tableName}`);
|
|
111
115
|
}
|
|
112
116
|
else if (results.length === 0) {
|
|
113
|
-
throw new
|
|
117
|
+
throw new EntityDatabaseAdapterError_1.EntityDatabaseAdapterEmptyInsertResultError(`Empty results from database adapter insert: ${this.entityConfiguration.tableName}`);
|
|
114
118
|
}
|
|
115
119
|
return (0, EntityFieldTransformationUtils_1.transformDatabaseObjectToFields)(this.entityConfiguration, this.fieldTransformerMap, results[0]);
|
|
116
120
|
}
|
|
@@ -128,10 +132,13 @@ class EntityDatabaseAdapter {
|
|
|
128
132
|
const dbObject = (0, EntityFieldTransformationUtils_1.transformFieldsToDatabaseObject)(this.entityConfiguration, this.fieldTransformerMap, object);
|
|
129
133
|
const results = await this.updateInternalAsync(queryContext.getQueryInterface(), this.entityConfiguration.tableName, idColumn, id, dbObject);
|
|
130
134
|
if (results.length > 1) {
|
|
131
|
-
|
|
135
|
+
// This should never happen with a properly implemented database adapter unless the underlying table has a non-unique
|
|
136
|
+
// primary key column.
|
|
137
|
+
throw new EntityDatabaseAdapterError_1.EntityDatabaseAdapterExcessiveUpdateResultError(`Excessive results from database adapter update: ${this.entityConfiguration.tableName}(id = ${id})`);
|
|
132
138
|
}
|
|
133
139
|
else if (results.length === 0) {
|
|
134
|
-
|
|
140
|
+
// This happens when the object to update does not exist. It may have been deleted by another process.
|
|
141
|
+
throw new EntityDatabaseAdapterError_1.EntityDatabaseAdapterEmptyUpdateResultError(`Empty results from database adapter update: ${this.entityConfiguration.tableName}(id = ${id})`);
|
|
135
142
|
}
|
|
136
143
|
return (0, EntityFieldTransformationUtils_1.transformDatabaseObjectToFields)(this.entityConfiguration, this.fieldTransformerMap, results[0]);
|
|
137
144
|
}
|
|
@@ -146,7 +153,7 @@ class EntityDatabaseAdapter {
|
|
|
146
153
|
const idColumn = (0, EntityFieldTransformationUtils_1.getDatabaseFieldForEntityField)(this.entityConfiguration, idField);
|
|
147
154
|
const numDeleted = await this.deleteInternalAsync(queryContext.getQueryInterface(), this.entityConfiguration.tableName, idColumn, id);
|
|
148
155
|
if (numDeleted > 1) {
|
|
149
|
-
throw new
|
|
156
|
+
throw new EntityDatabaseAdapterError_1.EntityDatabaseAdapterExcessiveDeleteResultError(`Excessive deletions from database adapter delete: ${this.entityConfiguration.tableName}(id = ${id})`);
|
|
150
157
|
}
|
|
151
158
|
}
|
|
152
159
|
convertToTableQueryModifiersWithOrderByRaw(querySelectionModifiers) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityDatabaseAdapter.js","sourceRoot":"","sources":["../../src/EntityDatabaseAdapter.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"EntityDatabaseAdapter.js","sourceRoot":"","sources":["../../src/EntityDatabaseAdapter.ts"],"names":[],"mappings":";;;;;;AAkDA,kFAOC;AAzDD,0DAAkC;AAIlC,oFAM6C;AAC7C,8FAKmD;AAkCnD,SAAgB,mC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AAuB,CAAC,MAAM;YACtC,KAAK,EAAE,uBAAuB,CAAC,KAAK;SACrC,CAAC;IACJ,CAAC;CACF;AA3UD,sDA2UC"}
|
|
@@ -7,7 +7,9 @@ export declare class StringField<TRequireExplicitCache extends boolean> extends
|
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* EntityFieldDefinition for a column with a JS string type.
|
|
10
|
-
* Enforces that the string is a valid UUID.
|
|
10
|
+
* Enforces that the string is a valid UUID and that it is lowercase. Entity requires UUIDs to be lowercase since most
|
|
11
|
+
* databases (e.g. Postgres) treat UUIDs as case-insensitive, which can lead to unexpected entity load results if mixed-case
|
|
12
|
+
* UUIDs are used.
|
|
11
13
|
*/
|
|
12
14
|
export declare class UUIDField<TRequireExplicitCache extends boolean> extends StringField<TRequireExplicitCache> {
|
|
13
15
|
protected validateInputValueInternal(value: string): boolean;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BufferField = exports.StrictEnumField = exports.EnumField = exports.JSONObjectField = exports.StringArrayField = exports.FloatField = exports.IntField = exports.BooleanField = exports.DateField = exports.UUIDField = exports.StringField = void 0;
|
|
4
4
|
const EntityFieldDefinition_1 = require("./EntityFieldDefinition");
|
|
5
5
|
// Use our own regex since the `uuid` package doesn't support validating UUIDv6/7/8 yet
|
|
6
|
-
const UUID_REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)
|
|
6
|
+
const UUID_REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
7
7
|
/**
|
|
8
8
|
* EntityFieldDefinition for a column with a JS string type.
|
|
9
9
|
*/
|
|
@@ -15,7 +15,9 @@ class StringField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
|
15
15
|
exports.StringField = StringField;
|
|
16
16
|
/**
|
|
17
17
|
* EntityFieldDefinition for a column with a JS string type.
|
|
18
|
-
* Enforces that the string is a valid UUID.
|
|
18
|
+
* Enforces that the string is a valid UUID and that it is lowercase. Entity requires UUIDs to be lowercase since most
|
|
19
|
+
* databases (e.g. Postgres) treat UUIDs as case-insensitive, which can lead to unexpected entity load results if mixed-case
|
|
20
|
+
* UUIDs are used.
|
|
19
21
|
*/
|
|
20
22
|
class UUIDField extends StringField {
|
|
21
23
|
validateInputValueInternal(value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityFields.js","sourceRoot":"","sources":["../../src/EntityFields.ts"],"names":[],"mappings":";;;AAAA,mEAIiC;AAEjC,uFAAuF;AACvF,MAAM,UAAU,GACd,
|
|
1
|
+
{"version":3,"file":"EntityFields.js","sourceRoot":"","sources":["../../src/EntityFields.ts"],"names":[],"mappings":";;;AAAA,mEAIiC;AAEjC,uFAAuF;AACvF,MAAM,UAAU,GACd,yJAAyJ,CAAC;AAE5J;;GAEG;AACH,MAAa,WAAmD,SAAQ,6CAGvE;IACW,0BAA0B,CAAC,KAAa;QAChD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;IACnC,CAAC;CACF;AAPD,kCAOC;AAED;;;;;GAKG;AACH,MAAa,SAEX,SAAQ,WAAkC;IACvB,0BAA0B,CAAC,KAAa;QACzD,OAAO,KAAK,CAAC,0BAA0B,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3E,CAAC;CACF;AAND,8BAMC;AAED;;GAEG;AACH,MAAa,SAAiD,SAAQ,6CAGrE;IACW,0BAA0B,CAAC,KAAW;QAC9C,OAAO,KAAK,YAAY,IAAI,CAAC;IAC/B,CAAC;CACF;AAPD,8BAOC;AAED;;GAEG;AACH,MAAa,Y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C,IAAI,CAAC;IAC3B,CAAC;IAEkB,0BAA0B,CAAC,KAAsB;QAClE,OAAO,KAAK,CAAC,0BAA0B,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7F,CAAC;CACF;AAjBD,0CAiBC;AAED;;GAEG;AACH,MAAa,WAAmD,SAAQ,6CAGvE;IACW,0BAA0B,CAAC,KAAa;QAChD,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AAPD,kCAOC"}
|
|
@@ -30,10 +30,10 @@ export type PartitionArrayPredicate<T, U> = (val: T | U) => val is T;
|
|
|
30
30
|
* @param values - array of values to partition
|
|
31
31
|
* @param predicate - binary predicate to evaluate partition group of each value
|
|
32
32
|
*/
|
|
33
|
-
export declare const partitionArray: <T, U>(values: (T | U)[], predicate: PartitionArrayPredicate<T, U>) => [T[], U[]];
|
|
33
|
+
export declare const partitionArray: <T, U>(values: readonly (T | U)[], predicate: PartitionArrayPredicate<T, U>) => readonly [readonly T[], readonly U[]];
|
|
34
34
|
/**
|
|
35
35
|
* Partition array of values and errors into an array of values and an array of errors.
|
|
36
36
|
* @param valuesAndErrors - array of values and errors
|
|
37
37
|
*/
|
|
38
|
-
export declare const partitionErrors: <T>(valuesAndErrors: (T | Error)[]) => [T[], Error[]];
|
|
38
|
+
export declare const partitionErrors: <T>(valuesAndErrors: readonly (T | Error)[]) => readonly [readonly T[], readonly Error[]];
|
|
39
39
|
export declare const pick: <T extends object, U extends keyof T>(object: T, props: readonly U[]) => Pick<T, U>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityUtils.js","sourceRoot":"","sources":["../../src/entityUtils.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,mBAAmB,GAAG,KAAK,EACtC,cAA6C,EACtB,EAAE;IACzB,MAAM,OAAO,GAAG,MAA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AAI,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IAED,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC,CAAC;AAhBW,QAAA,cAAc,kBAgBzB;AAEF;;;GAGG;AACI,MAAM,eAAe,GAAG,CAC7B,eAAuC,EACI,EAAE;IAC7C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAA,sBAAc,EAAW,eAAe,EAAE,OAAO,CAAC,CAAC;IAC5E,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1B,CAAC,CAAC;AALW,QAAA,eAAe,mBAK1B;AAEF,MAAM,OAAO,GAAG,CAAI,KAAgB,EAAkB,EAAE;IACtD,OAAO,KAAK,YAAY,KAAK,CAAC;AAChC,CAAC,CAAC;AAEK,MAAM,IAAI,GAAG,CAClB,MAAS,EACT,KAAmB,EACP,EAAE;IACd,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAQ,CAAC,CAAC,CACjE,CAAC;AACX,CAAC,CAAC;AARW,QAAA,IAAI,QAQf"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { EntityError, EntityErrorCode, EntityErrorState } from './EntityError';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for errors thrown by the entity cache adapter.
|
|
4
|
+
*/
|
|
2
5
|
export declare abstract class EntityCacheAdapterError extends EntityError {
|
|
3
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when a transient error occurs in the entity cache adapter.
|
|
9
|
+
* Transient errors may succeed if retried.
|
|
10
|
+
*/
|
|
4
11
|
export declare class EntityCacheAdapterTransientError extends EntityCacheAdapterError {
|
|
5
12
|
readonly state = EntityErrorState.TRANSIENT;
|
|
6
13
|
readonly code = EntityErrorCode.ERR_ENTITY_CACHE_ADAPTER_TRANSIENT;
|
|
@@ -2,9 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EntityCacheAdapterTransientError = exports.EntityCacheAdapterError = void 0;
|
|
4
4
|
const EntityError_1 = require("./EntityError");
|
|
5
|
+
/**
|
|
6
|
+
* Base class for errors thrown by the entity cache adapter.
|
|
7
|
+
*/
|
|
5
8
|
class EntityCacheAdapterError extends EntityError_1.EntityError {
|
|
6
9
|
}
|
|
7
10
|
exports.EntityCacheAdapterError = EntityCacheAdapterError;
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when a transient error occurs in the entity cache adapter.
|
|
13
|
+
* Transient errors may succeed if retried.
|
|
14
|
+
*/
|
|
8
15
|
class EntityCacheAdapterTransientError extends EntityCacheAdapterError {
|
|
9
16
|
state = EntityError_1.EntityErrorState.TRANSIENT;
|
|
10
17
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_CACHE_ADAPTER_TRANSIENT;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityCacheAdapterError.js","sourceRoot":"","sources":["../../../src/errors/EntityCacheAdapterError.ts"],"names":[],"mappings":";;;AAAA,+CAA+E;AAE/E,MAAsB,uBAAwB,SAAQ,yBAAW;CAAG;AAApE,0DAAoE;AAEpE,MAAa,gCAAiC,SAAQ,uBAAuB;IAC3D,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,kCAAkC,CAAC;CAC3E;AAHD,4EAGC"}
|
|
1
|
+
{"version":3,"file":"EntityCacheAdapterError.js","sourceRoot":"","sources":["../../../src/errors/EntityCacheAdapterError.ts"],"names":[],"mappings":";;;AAAA,+CAA+E;AAE/E;;GAEG;AACH,MAAsB,uBAAwB,SAAQ,yBAAW;CAAG;AAApE,0DAAoE;AAEpE;;;GAGG;AACH,MAAa,gCAAiC,SAAQ,uBAAuB;IAC3D,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,kCAAkC,CAAC;CAC3E;AAHD,4EAGC"}
|
|
@@ -1,31 +1,109 @@
|
|
|
1
1
|
import { EntityError, EntityErrorCode, EntityErrorState } from './EntityError';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all errors related to the database adapter.
|
|
4
|
+
*/
|
|
2
5
|
export declare abstract class EntityDatabaseAdapterError extends EntityError {
|
|
3
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Thrown when a transient error occurrs within the database adapter.
|
|
9
|
+
* Transient errors may succeed if retried.
|
|
10
|
+
*/
|
|
4
11
|
export declare class EntityDatabaseAdapterTransientError extends EntityDatabaseAdapterError {
|
|
5
12
|
readonly state = EntityErrorState.TRANSIENT;
|
|
6
13
|
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_TRANSIENT;
|
|
7
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Thrown when an unknown error occurrs within the database adapter.
|
|
17
|
+
* This is a catch-all error class for DBMS-specific errors that do not fit into other categories.
|
|
18
|
+
*/
|
|
8
19
|
export declare class EntityDatabaseAdapterUnknownError extends EntityDatabaseAdapterError {
|
|
9
20
|
readonly state = EntityErrorState.UNKNOWN;
|
|
10
21
|
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_UNKNOWN;
|
|
11
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Thrown when a check constraint is violated within the database adapter.
|
|
25
|
+
* This indicates that a value being inserted or updated does not satisfy a defined data integrity constraint.
|
|
26
|
+
*/
|
|
12
27
|
export declare class EntityDatabaseAdapterCheckConstraintError extends EntityDatabaseAdapterError {
|
|
13
28
|
readonly state = EntityErrorState.PERMANENT;
|
|
14
29
|
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_CHECK_CONSTRAINT;
|
|
15
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Thrown when an exclusion constraint is violated within the database adapter.
|
|
33
|
+
* This indicates that a value being inserted or updated conflicts with an existing value based on a defined exclusion constraint.
|
|
34
|
+
*/
|
|
16
35
|
export declare class EntityDatabaseAdapterExclusionConstraintError extends EntityDatabaseAdapterError {
|
|
17
36
|
readonly state = EntityErrorState.PERMANENT;
|
|
18
37
|
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCLUSION_CONSTRAINT;
|
|
19
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Thrown when a foreign key constraint is violated within the database adapter.
|
|
41
|
+
* This indicates that a value being inserted, updated, or deleted references a non-existent value in a related table
|
|
42
|
+
* or is referenced in a related table.
|
|
43
|
+
*/
|
|
20
44
|
export declare class EntityDatabaseAdapterForeignKeyConstraintError extends EntityDatabaseAdapterError {
|
|
21
45
|
readonly state = EntityErrorState.PERMANENT;
|
|
22
46
|
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_FOREIGN_KEY_CONSTRAINT;
|
|
23
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Thrown when a not-null constraint is violated within the database adapter.
|
|
50
|
+
* This indicates that a null value is being inserted or updated into a column that does not allow null values.
|
|
51
|
+
*/
|
|
24
52
|
export declare class EntityDatabaseAdapterNotNullConstraintError extends EntityDatabaseAdapterError {
|
|
25
53
|
readonly state = EntityErrorState.PERMANENT;
|
|
26
54
|
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_NOT_NULL_CONSTRAINT;
|
|
27
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Thrown when a unique constraint is violated within the database adapter.
|
|
58
|
+
* This indicates that a value being inserted or updated duplicates an existing value in a column or set of columns
|
|
59
|
+
* that require unique values.
|
|
60
|
+
*/
|
|
28
61
|
export declare class EntityDatabaseAdapterUniqueConstraintError extends EntityDatabaseAdapterError {
|
|
29
62
|
readonly state = EntityErrorState.PERMANENT;
|
|
30
63
|
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_UNIQUE_CONSTRAINT;
|
|
31
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Thrown when an insert operation returns more results than expected. Only one row is expected.
|
|
67
|
+
* These should never happen with a properly implemented database adapter unless the underlying database has nonstandard
|
|
68
|
+
* triggers or something similar.
|
|
69
|
+
*/
|
|
70
|
+
export declare class EntityDatabaseAdapterExcessiveInsertResultError extends EntityDatabaseAdapterError {
|
|
71
|
+
readonly state = EntityErrorState.PERMANENT;
|
|
72
|
+
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_INSERT_RESULT;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Thrown when an insert operation returns no results. One row is expected.
|
|
76
|
+
* These should never happen with a properly implemented database adapter unless the underlying database has nonstandard
|
|
77
|
+
* triggers or something similar.
|
|
78
|
+
*/
|
|
79
|
+
export declare class EntityDatabaseAdapterEmptyInsertResultError extends EntityDatabaseAdapterError {
|
|
80
|
+
readonly state = EntityErrorState.PERMANENT;
|
|
81
|
+
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EMPTY_INSERT_RESULT;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Thrown when an update operation returns more results than expected. Only one row is expected.
|
|
85
|
+
* These should never happen with a properly implemented database adapter unless the underlying table has a non-unique
|
|
86
|
+
* primary key column.
|
|
87
|
+
*/
|
|
88
|
+
export declare class EntityDatabaseAdapterExcessiveUpdateResultError extends EntityDatabaseAdapterError {
|
|
89
|
+
readonly state = EntityErrorState.PERMANENT;
|
|
90
|
+
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_UPDATE_RESULT;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Thrown when an update operation returns no results. One row is expected.
|
|
94
|
+
* This most often happens when attempting to update a non-existent row, often indicating that the row
|
|
95
|
+
* was deleted by a different process between fetching and updating it in this process.
|
|
96
|
+
*/
|
|
97
|
+
export declare class EntityDatabaseAdapterEmptyUpdateResultError extends EntityDatabaseAdapterError {
|
|
98
|
+
readonly state = EntityErrorState.PERMANENT;
|
|
99
|
+
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EMPTY_UPDATE_RESULT;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Thrown when a delete operation returns more results than expected. Only one row is expected.
|
|
103
|
+
* These should never happen with a properly implemented database adapter unless the underlying table has a non-unique
|
|
104
|
+
* primary key column.
|
|
105
|
+
*/
|
|
106
|
+
export declare class EntityDatabaseAdapterExcessiveDeleteResultError extends EntityDatabaseAdapterError {
|
|
107
|
+
readonly state = EntityErrorState.PERMANENT;
|
|
108
|
+
readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_DELETE_RESULT;
|
|
109
|
+
}
|
|
@@ -1,43 +1,126 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntityDatabaseAdapterUniqueConstraintError = exports.EntityDatabaseAdapterNotNullConstraintError = exports.EntityDatabaseAdapterForeignKeyConstraintError = exports.EntityDatabaseAdapterExclusionConstraintError = exports.EntityDatabaseAdapterCheckConstraintError = exports.EntityDatabaseAdapterUnknownError = exports.EntityDatabaseAdapterTransientError = exports.EntityDatabaseAdapterError = void 0;
|
|
3
|
+
exports.EntityDatabaseAdapterExcessiveDeleteResultError = exports.EntityDatabaseAdapterEmptyUpdateResultError = exports.EntityDatabaseAdapterExcessiveUpdateResultError = exports.EntityDatabaseAdapterEmptyInsertResultError = exports.EntityDatabaseAdapterExcessiveInsertResultError = exports.EntityDatabaseAdapterUniqueConstraintError = exports.EntityDatabaseAdapterNotNullConstraintError = exports.EntityDatabaseAdapterForeignKeyConstraintError = exports.EntityDatabaseAdapterExclusionConstraintError = exports.EntityDatabaseAdapterCheckConstraintError = exports.EntityDatabaseAdapterUnknownError = exports.EntityDatabaseAdapterTransientError = exports.EntityDatabaseAdapterError = void 0;
|
|
4
4
|
const EntityError_1 = require("./EntityError");
|
|
5
|
+
/**
|
|
6
|
+
* Base class for all errors related to the database adapter.
|
|
7
|
+
*/
|
|
5
8
|
class EntityDatabaseAdapterError extends EntityError_1.EntityError {
|
|
6
9
|
}
|
|
7
10
|
exports.EntityDatabaseAdapterError = EntityDatabaseAdapterError;
|
|
11
|
+
/**
|
|
12
|
+
* Thrown when a transient error occurrs within the database adapter.
|
|
13
|
+
* Transient errors may succeed if retried.
|
|
14
|
+
*/
|
|
8
15
|
class EntityDatabaseAdapterTransientError extends EntityDatabaseAdapterError {
|
|
9
16
|
state = EntityError_1.EntityErrorState.TRANSIENT;
|
|
10
17
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_TRANSIENT;
|
|
11
18
|
}
|
|
12
19
|
exports.EntityDatabaseAdapterTransientError = EntityDatabaseAdapterTransientError;
|
|
20
|
+
/**
|
|
21
|
+
* Thrown when an unknown error occurrs within the database adapter.
|
|
22
|
+
* This is a catch-all error class for DBMS-specific errors that do not fit into other categories.
|
|
23
|
+
*/
|
|
13
24
|
class EntityDatabaseAdapterUnknownError extends EntityDatabaseAdapterError {
|
|
14
25
|
state = EntityError_1.EntityErrorState.UNKNOWN;
|
|
15
26
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_UNKNOWN;
|
|
16
27
|
}
|
|
17
28
|
exports.EntityDatabaseAdapterUnknownError = EntityDatabaseAdapterUnknownError;
|
|
29
|
+
/**
|
|
30
|
+
* Thrown when a check constraint is violated within the database adapter.
|
|
31
|
+
* This indicates that a value being inserted or updated does not satisfy a defined data integrity constraint.
|
|
32
|
+
*/
|
|
18
33
|
class EntityDatabaseAdapterCheckConstraintError extends EntityDatabaseAdapterError {
|
|
19
34
|
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
20
35
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_CHECK_CONSTRAINT;
|
|
21
36
|
}
|
|
22
37
|
exports.EntityDatabaseAdapterCheckConstraintError = EntityDatabaseAdapterCheckConstraintError;
|
|
38
|
+
/**
|
|
39
|
+
* Thrown when an exclusion constraint is violated within the database adapter.
|
|
40
|
+
* This indicates that a value being inserted or updated conflicts with an existing value based on a defined exclusion constraint.
|
|
41
|
+
*/
|
|
23
42
|
class EntityDatabaseAdapterExclusionConstraintError extends EntityDatabaseAdapterError {
|
|
24
43
|
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
25
44
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCLUSION_CONSTRAINT;
|
|
26
45
|
}
|
|
27
46
|
exports.EntityDatabaseAdapterExclusionConstraintError = EntityDatabaseAdapterExclusionConstraintError;
|
|
47
|
+
/**
|
|
48
|
+
* Thrown when a foreign key constraint is violated within the database adapter.
|
|
49
|
+
* This indicates that a value being inserted, updated, or deleted references a non-existent value in a related table
|
|
50
|
+
* or is referenced in a related table.
|
|
51
|
+
*/
|
|
28
52
|
class EntityDatabaseAdapterForeignKeyConstraintError extends EntityDatabaseAdapterError {
|
|
29
53
|
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
30
54
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_FOREIGN_KEY_CONSTRAINT;
|
|
31
55
|
}
|
|
32
56
|
exports.EntityDatabaseAdapterForeignKeyConstraintError = EntityDatabaseAdapterForeignKeyConstraintError;
|
|
57
|
+
/**
|
|
58
|
+
* Thrown when a not-null constraint is violated within the database adapter.
|
|
59
|
+
* This indicates that a null value is being inserted or updated into a column that does not allow null values.
|
|
60
|
+
*/
|
|
33
61
|
class EntityDatabaseAdapterNotNullConstraintError extends EntityDatabaseAdapterError {
|
|
34
62
|
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
35
63
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_NOT_NULL_CONSTRAINT;
|
|
36
64
|
}
|
|
37
65
|
exports.EntityDatabaseAdapterNotNullConstraintError = EntityDatabaseAdapterNotNullConstraintError;
|
|
66
|
+
/**
|
|
67
|
+
* Thrown when a unique constraint is violated within the database adapter.
|
|
68
|
+
* This indicates that a value being inserted or updated duplicates an existing value in a column or set of columns
|
|
69
|
+
* that require unique values.
|
|
70
|
+
*/
|
|
38
71
|
class EntityDatabaseAdapterUniqueConstraintError extends EntityDatabaseAdapterError {
|
|
39
72
|
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
40
73
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_UNIQUE_CONSTRAINT;
|
|
41
74
|
}
|
|
42
75
|
exports.EntityDatabaseAdapterUniqueConstraintError = EntityDatabaseAdapterUniqueConstraintError;
|
|
76
|
+
/**
|
|
77
|
+
* Thrown when an insert operation returns more results than expected. Only one row is expected.
|
|
78
|
+
* These should never happen with a properly implemented database adapter unless the underlying database has nonstandard
|
|
79
|
+
* triggers or something similar.
|
|
80
|
+
*/
|
|
81
|
+
class EntityDatabaseAdapterExcessiveInsertResultError extends EntityDatabaseAdapterError {
|
|
82
|
+
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
83
|
+
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_INSERT_RESULT;
|
|
84
|
+
}
|
|
85
|
+
exports.EntityDatabaseAdapterExcessiveInsertResultError = EntityDatabaseAdapterExcessiveInsertResultError;
|
|
86
|
+
/**
|
|
87
|
+
* Thrown when an insert operation returns no results. One row is expected.
|
|
88
|
+
* These should never happen with a properly implemented database adapter unless the underlying database has nonstandard
|
|
89
|
+
* triggers or something similar.
|
|
90
|
+
*/
|
|
91
|
+
class EntityDatabaseAdapterEmptyInsertResultError extends EntityDatabaseAdapterError {
|
|
92
|
+
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
93
|
+
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EMPTY_INSERT_RESULT;
|
|
94
|
+
}
|
|
95
|
+
exports.EntityDatabaseAdapterEmptyInsertResultError = EntityDatabaseAdapterEmptyInsertResultError;
|
|
96
|
+
/**
|
|
97
|
+
* Thrown when an update operation returns more results than expected. Only one row is expected.
|
|
98
|
+
* These should never happen with a properly implemented database adapter unless the underlying table has a non-unique
|
|
99
|
+
* primary key column.
|
|
100
|
+
*/
|
|
101
|
+
class EntityDatabaseAdapterExcessiveUpdateResultError extends EntityDatabaseAdapterError {
|
|
102
|
+
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
103
|
+
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_UPDATE_RESULT;
|
|
104
|
+
}
|
|
105
|
+
exports.EntityDatabaseAdapterExcessiveUpdateResultError = EntityDatabaseAdapterExcessiveUpdateResultError;
|
|
106
|
+
/**
|
|
107
|
+
* Thrown when an update operation returns no results. One row is expected.
|
|
108
|
+
* This most often happens when attempting to update a non-existent row, often indicating that the row
|
|
109
|
+
* was deleted by a different process between fetching and updating it in this process.
|
|
110
|
+
*/
|
|
111
|
+
class EntityDatabaseAdapterEmptyUpdateResultError extends EntityDatabaseAdapterError {
|
|
112
|
+
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
113
|
+
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EMPTY_UPDATE_RESULT;
|
|
114
|
+
}
|
|
115
|
+
exports.EntityDatabaseAdapterEmptyUpdateResultError = EntityDatabaseAdapterEmptyUpdateResultError;
|
|
116
|
+
/**
|
|
117
|
+
* Thrown when a delete operation returns more results than expected. Only one row is expected.
|
|
118
|
+
* These should never happen with a properly implemented database adapter unless the underlying table has a non-unique
|
|
119
|
+
* primary key column.
|
|
120
|
+
*/
|
|
121
|
+
class EntityDatabaseAdapterExcessiveDeleteResultError extends EntityDatabaseAdapterError {
|
|
122
|
+
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
123
|
+
code = EntityError_1.EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_DELETE_RESULT;
|
|
124
|
+
}
|
|
125
|
+
exports.EntityDatabaseAdapterExcessiveDeleteResultError = EntityDatabaseAdapterExcessiveDeleteResultError;
|
|
43
126
|
//# sourceMappingURL=EntityDatabaseAdapterError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityDatabaseAdapterError.js","sourceRoot":"","sources":["../../../src/errors/EntityDatabaseAdapterError.ts"],"names":[],"mappings":";;;AAAA,+CAA+E;AAE/E,MAAsB,0BAA2B,SAAQ,yBAAW;CAAG;AAAvE,gEAAuE;AAEvE,MAAa,mCAAoC,SAAQ,0BAA0B;IACjE,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,qCAAqC,CAAC;CAC9E;AAHD,kFAGC;AAED,MAAa,iCAAkC,SAAQ,0BAA0B;IAC/D,KAAK,GAAG,8BAAgB,CAAC,OAAO,CAAC;IACjC,IAAI,GAAG,6BAAe,CAAC,mCAAmC,CAAC;CAC5E;AAHD,8EAGC;AAED,MAAa,yCAA0C,SAAQ,0BAA0B;IACvE,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,4CAA4C,CAAC;CACrF;AAHD,8FAGC;AAED,MAAa,6CAA8C,SAAQ,0BAA0B;IAC3E,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,gDAAgD,CAAC;CACzF;AAHD,sGAGC;AAED,MAAa,8CAA+C,SAAQ,0BAA0B;IAC5E,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,kDAAkD,C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
import ES6Error from 'es6-error';
|
|
2
|
+
/**
|
|
3
|
+
* The state of an entity error, indicating whether it may be transient/retryable.
|
|
4
|
+
*/
|
|
2
5
|
export declare enum EntityErrorState {
|
|
3
6
|
UNKNOWN = 0,
|
|
4
7
|
TRANSIENT = 1,
|
|
5
8
|
PERMANENT = 2
|
|
6
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Error code for an entity error. Each error code should map to a specific class of Entity error.
|
|
12
|
+
*/
|
|
7
13
|
export declare enum EntityErrorCode {
|
|
8
14
|
ERR_ENTITY_NOT_AUTHORIZED = "ERR_ENTITY_NOT_AUTHORIZED",
|
|
9
15
|
ERR_ENTITY_NOT_FOUND = "ERR_ENTITY_NOT_FOUND",
|
|
@@ -15,8 +21,16 @@ export declare enum EntityErrorCode {
|
|
|
15
21
|
ERR_ENTITY_DATABASE_ADAPTER_FOREIGN_KEY_CONSTRAINT = "ERR_ENTITY_DATABASE_ADAPTER_FOREIGN_KEY_CONSTRAINT",
|
|
16
22
|
ERR_ENTITY_DATABASE_ADAPTER_NOT_NULL_CONSTRAINT = "ERR_ENTITY_DATABASE_ADAPTER_NOT_NULL_CONSTRAINT",
|
|
17
23
|
ERR_ENTITY_DATABASE_ADAPTER_UNIQUE_CONSTRAINT = "ERR_ENTITY_DATABASE_ADAPTER_UNIQUE_CONSTRAINT",
|
|
24
|
+
ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_INSERT_RESULT = "ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_INSERT_RESULT",
|
|
25
|
+
ERR_ENTITY_DATABASE_ADAPTER_EMPTY_INSERT_RESULT = "ERR_ENTITY_DATABASE_ADAPTER_EMPTY_INSERT_RESULT",
|
|
26
|
+
ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_UPDATE_RESULT = "ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_UPDATE_RESULT",
|
|
27
|
+
ERR_ENTITY_DATABASE_ADAPTER_EMPTY_UPDATE_RESULT = "ERR_ENTITY_DATABASE_ADAPTER_EMPTY_UPDATE_RESULT",
|
|
28
|
+
ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_DELETE_RESULT = "ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_DELETE_RESULT",
|
|
18
29
|
ERR_ENTITY_CACHE_ADAPTER_TRANSIENT = "ERR_ENTITY_CACHE_ADAPTER_TRANSIENT"
|
|
19
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Base class for all known errors thrown by the entity system.
|
|
33
|
+
*/
|
|
20
34
|
export declare abstract class EntityError extends ES6Error {
|
|
21
35
|
readonly cause?: Error | undefined;
|
|
22
36
|
abstract readonly state: EntityErrorState;
|
|
@@ -5,12 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.EntityError = exports.EntityErrorCode = exports.EntityErrorState = void 0;
|
|
7
7
|
const es6_error_1 = __importDefault(require("es6-error"));
|
|
8
|
+
/**
|
|
9
|
+
* The state of an entity error, indicating whether it may be transient/retryable.
|
|
10
|
+
*/
|
|
8
11
|
var EntityErrorState;
|
|
9
12
|
(function (EntityErrorState) {
|
|
10
13
|
EntityErrorState[EntityErrorState["UNKNOWN"] = 0] = "UNKNOWN";
|
|
11
14
|
EntityErrorState[EntityErrorState["TRANSIENT"] = 1] = "TRANSIENT";
|
|
12
15
|
EntityErrorState[EntityErrorState["PERMANENT"] = 2] = "PERMANENT";
|
|
13
16
|
})(EntityErrorState || (exports.EntityErrorState = EntityErrorState = {}));
|
|
17
|
+
/**
|
|
18
|
+
* Error code for an entity error. Each error code should map to a specific class of Entity error.
|
|
19
|
+
*/
|
|
14
20
|
var EntityErrorCode;
|
|
15
21
|
(function (EntityErrorCode) {
|
|
16
22
|
EntityErrorCode["ERR_ENTITY_NOT_AUTHORIZED"] = "ERR_ENTITY_NOT_AUTHORIZED";
|
|
@@ -23,8 +29,16 @@ var EntityErrorCode;
|
|
|
23
29
|
EntityErrorCode["ERR_ENTITY_DATABASE_ADAPTER_FOREIGN_KEY_CONSTRAINT"] = "ERR_ENTITY_DATABASE_ADAPTER_FOREIGN_KEY_CONSTRAINT";
|
|
24
30
|
EntityErrorCode["ERR_ENTITY_DATABASE_ADAPTER_NOT_NULL_CONSTRAINT"] = "ERR_ENTITY_DATABASE_ADAPTER_NOT_NULL_CONSTRAINT";
|
|
25
31
|
EntityErrorCode["ERR_ENTITY_DATABASE_ADAPTER_UNIQUE_CONSTRAINT"] = "ERR_ENTITY_DATABASE_ADAPTER_UNIQUE_CONSTRAINT";
|
|
32
|
+
EntityErrorCode["ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_INSERT_RESULT"] = "ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_INSERT_RESULT";
|
|
33
|
+
EntityErrorCode["ERR_ENTITY_DATABASE_ADAPTER_EMPTY_INSERT_RESULT"] = "ERR_ENTITY_DATABASE_ADAPTER_EMPTY_INSERT_RESULT";
|
|
34
|
+
EntityErrorCode["ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_UPDATE_RESULT"] = "ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_UPDATE_RESULT";
|
|
35
|
+
EntityErrorCode["ERR_ENTITY_DATABASE_ADAPTER_EMPTY_UPDATE_RESULT"] = "ERR_ENTITY_DATABASE_ADAPTER_EMPTY_UPDATE_RESULT";
|
|
36
|
+
EntityErrorCode["ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_DELETE_RESULT"] = "ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_DELETE_RESULT";
|
|
26
37
|
EntityErrorCode["ERR_ENTITY_CACHE_ADAPTER_TRANSIENT"] = "ERR_ENTITY_CACHE_ADAPTER_TRANSIENT";
|
|
27
38
|
})(EntityErrorCode || (exports.EntityErrorCode = EntityErrorCode = {}));
|
|
39
|
+
/**
|
|
40
|
+
* Base class for all known errors thrown by the entity system.
|
|
41
|
+
*/
|
|
28
42
|
class EntityError extends es6_error_1.default {
|
|
29
43
|
cause;
|
|
30
44
|
constructor(message, cause) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityError.js","sourceRoot":"","sources":["../../../src/errors/EntityError.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAiC;AAEjC,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,6DAAO,CAAA;IACP,iEAAS,CAAA;IACT,iEAAS,CAAA;AACX,CAAC,EAJW,gBAAgB,gCAAhB,gBAAgB,QAI3B;AAED,IAAY,
|
|
1
|
+
{"version":3,"file":"EntityError.js","sourceRoot":"","sources":["../../../src/errors/EntityError.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAiC;AAEjC;;GAEG;AACH,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,6DAAO,CAAA;IACP,iEAAS,CAAA;IACT,iEAAS,CAAA;AACX,CAAC,EAJW,gBAAgB,gCAAhB,gBAAgB,QAI3B;AAED;;GAEG;AACH,IAAY,eAiBX;AAjBD,WAAY,eAAe;IACzB,0EAAuD,CAAA;IACvD,gEAA6C,CAAA;IAC7C,oFAAiE,CAAA;IACjE,kGAA+E,CAAA;IAC/E,8FAA2E,CAAA;IAC3E,gHAA6F,CAAA;IAC7F,wHAAqG,CAAA;IACrG,4HAAyG,CAAA;IACzG,sHAAmG,CAAA;IACnG,kHAA+F,CAAA;IAC/F,8HAA2G,CAAA;IAC3G,sHAAmG,CAAA;IACnG,8HAA2G,CAAA;IAC3G,sHAAmG,CAAA;IACnG,8HAA2G,CAAA;IAC3G,4FAAyE,CAAA;AAC3E,CAAC,EAjBW,eAAe,+BAAf,eAAe,QAiB1B;AAED;;GAEG;AACH,MAAsB,WAAY,SAAQ,mBAAQ;IAMrB;IAF3B,YACE,OAAe,EACU,KAAa;QAEtC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFU,UAAK,GAAL,KAAK,CAAQ;IAGxC,CAAC;CACF;AAVD,kCAUC"}
|
|
@@ -3,6 +3,9 @@ import { EntityPrivacyPolicy } from '../EntityPrivacyPolicy';
|
|
|
3
3
|
import { ReadonlyEntity } from '../ReadonlyEntity';
|
|
4
4
|
import { ViewerContext } from '../ViewerContext';
|
|
5
5
|
import { EntityError, EntityErrorCode, EntityErrorState } from './EntityError';
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when an entity field has an invalid value, either during load or mutation.
|
|
8
|
+
*/
|
|
6
9
|
export declare class EntityInvalidFieldValueError<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>, N extends keyof TFields, TSelectedFields extends keyof TFields = keyof TFields> extends EntityError {
|
|
7
10
|
readonly state = EntityErrorState.PERMANENT;
|
|
8
11
|
readonly code = EntityErrorCode.ERR_ENTITY_INVALID_FIELD_VALUE;
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EntityInvalidFieldValueError = void 0;
|
|
4
4
|
const EntityError_1 = require("./EntityError");
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown when an entity field has an invalid value, either during load or mutation.
|
|
7
|
+
*/
|
|
5
8
|
class EntityInvalidFieldValueError extends EntityError_1.EntityError {
|
|
6
9
|
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
7
10
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_INVALID_FIELD_VALUE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityInvalidFieldValueError.js","sourceRoot":"","sources":["../../../src/errors/EntityInvalidFieldValueError.ts"],"names":[],"mappings":";;;AAIA,+CAA+E;AAE/E,MAAa,4BAcX,SAAQ,yBAAW;IACH,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,8BAA8B,CAAC;IAEtE,YACE,WAOC,EACD,SAAY,EACZ,UAAuB;QAEvB,KAAK,CAAC,2BAA2B,WAAW,CAAC,IAAI,KAAK,MAAM,CAAC,SAAS,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;IAC9F,CAAC;CACF;AAhCD,oEAgCC"}
|
|
1
|
+
{"version":3,"file":"EntityInvalidFieldValueError.js","sourceRoot":"","sources":["../../../src/errors/EntityInvalidFieldValueError.ts"],"names":[],"mappings":";;;AAIA,+CAA+E;AAE/E;;GAEG;AACH,MAAa,4BAcX,SAAQ,yBAAW;IACH,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,8BAA8B,CAAC;IAEtE,YACE,WAOC,EACD,SAAY,EACZ,UAAuB;QAEvB,KAAK,CAAC,2BAA2B,WAAW,CAAC,IAAI,KAAK,MAAM,CAAC,SAAS,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;IAC9F,CAAC;CACF;AAhCD,oEAgCC"}
|
|
@@ -2,6 +2,9 @@ import { EntityAuthorizationAction } from '../EntityPrivacyPolicy';
|
|
|
2
2
|
import { ReadonlyEntity } from '../ReadonlyEntity';
|
|
3
3
|
import { ViewerContext } from '../ViewerContext';
|
|
4
4
|
import { EntityError, EntityErrorCode, EntityErrorState } from './EntityError';
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown when viewer context is not authorized to perform an action on an entity.
|
|
7
|
+
*/
|
|
5
8
|
export declare class EntityNotAuthorizedError<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> extends EntityError {
|
|
6
9
|
readonly state = EntityErrorState.PERMANENT;
|
|
7
10
|
readonly code = EntityErrorCode.ERR_ENTITY_NOT_AUTHORIZED;
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EntityNotAuthorizedError = void 0;
|
|
4
4
|
const EntityPrivacyPolicy_1 = require("../EntityPrivacyPolicy");
|
|
5
5
|
const EntityError_1 = require("./EntityError");
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when viewer context is not authorized to perform an action on an entity.
|
|
8
|
+
*/
|
|
6
9
|
class EntityNotAuthorizedError extends EntityError_1.EntityError {
|
|
7
10
|
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
8
11
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_NOT_AUTHORIZED;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityNotAuthorizedError.js","sourceRoot":"","sources":["../../../src/errors/EntityNotAuthorizedError.ts"],"names":[],"mappings":";;;AAAA,gEAAmE;AAGnE,+CAA+E;AAE/E,MAAa,wBAMX,SAAQ,yBAAW;IACH,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,yBAAyB,CAAC;IAEjD,eAAe,CAAS;IAExC,YACE,MAAe,EACf,aAA6B,EAC7B,MAAiC,EACjC,SAAiB;QAEjB,KAAK,CACH,0BAA0B,MAAM,cAAc,aAAa,cAAc,+CAAyB,CAAC,MAAM,CAAC,iBAAiB,SAAS,GAAG,CACxI,CAAC;QACF,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;IACjD,CAAC;CACF;AAvBD,4DAuBC"}
|
|
1
|
+
{"version":3,"file":"EntityNotAuthorizedError.js","sourceRoot":"","sources":["../../../src/errors/EntityNotAuthorizedError.ts"],"names":[],"mappings":";;;AAAA,gEAAmE;AAGnE,+CAA+E;AAE/E;;GAEG;AACH,MAAa,wBAMX,SAAQ,yBAAW;IACH,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,yBAAyB,CAAC;IAEjD,eAAe,CAAS;IAExC,YACE,MAAe,EACf,aAA6B,EAC7B,MAAiC,EACjC,SAAiB;QAEjB,KAAK,CACH,0BAA0B,MAAM,cAAc,aAAa,cAAc,+CAAyB,CAAC,MAAM,CAAC,iBAAiB,SAAS,GAAG,CACxI,CAAC;QACF,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;IACjD,CAAC;CACF;AAvBD,4DAuBC"}
|
|
@@ -8,6 +8,9 @@ type EntityNotFoundOptions<TFields extends Record<string, any>, TIDField extends
|
|
|
8
8
|
fieldName: N;
|
|
9
9
|
fieldValue: TFields[N];
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when an entity is not found during certain load methods.
|
|
13
|
+
*/
|
|
11
14
|
export declare class EntityNotFoundError<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>, N extends keyof TFields, TSelectedFields extends keyof TFields = keyof TFields> extends EntityError {
|
|
12
15
|
readonly state = EntityErrorState.PERMANENT;
|
|
13
16
|
readonly code = EntityErrorCode.ERR_ENTITY_NOT_FOUND;
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EntityNotFoundError = void 0;
|
|
4
4
|
const EntityError_1 = require("./EntityError");
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown when an entity is not found during certain load methods.
|
|
7
|
+
*/
|
|
5
8
|
class EntityNotFoundError extends EntityError_1.EntityError {
|
|
6
9
|
state = EntityError_1.EntityErrorState.PERMANENT;
|
|
7
10
|
code = EntityError_1.EntityErrorCode.ERR_ENTITY_NOT_FOUND;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityNotFoundError.js","sourceRoot":"","sources":["../../../src/errors/EntityNotFoundError.ts"],"names":[],"mappings":";;;AAIA,+CAA+E;AA6B/E,MAAa,mBAcX,SAAQ,yBAAW;IACH,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,oBAAoB,CAAC;IAe5D,YACE,gBAUK;QAEL,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;YACzC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,KAAK,CACH,qBAAqB,gBAAgB,CAAC,WAAW,CAAC,IAAI,KAAK,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,MAAM,gBAAgB,CAAC,UAAU,GAAG,CAClI,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AApDD,kDAoDC"}
|
|
1
|
+
{"version":3,"file":"EntityNotFoundError.js","sourceRoot":"","sources":["../../../src/errors/EntityNotFoundError.ts"],"names":[],"mappings":";;;AAIA,+CAA+E;AA6B/E;;GAEG;AACH,MAAa,mBAcX,SAAQ,yBAAW;IACH,KAAK,GAAG,8BAAgB,CAAC,SAAS,CAAC;IACnC,IAAI,GAAG,6BAAe,CAAC,oBAAoB,CAAC;IAe5D,YACE,gBAUK;QAEL,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;YACzC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,KAAK,CACH,qBAAqB,gBAAgB,CAAC,WAAW,CAAC,IAAI,KAAK,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,MAAM,gBAAgB,CAAC,UAAU,GAAG,CAClI,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AApDD,kDAoDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/entity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"description": "A privacy-first data model",
|
|
5
5
|
"files": [
|
|
6
6
|
"build",
|
|
@@ -43,5 +43,6 @@
|
|
|
43
43
|
"typescript": "^5.8.3",
|
|
44
44
|
"uuid": "^8.3.0",
|
|
45
45
|
"uuidv7": "^1.0.0"
|
|
46
|
-
}
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "4ab2cf1cc498f0e06bdb0f792a08aca3f49d27fc"
|
|
47
48
|
}
|
|
@@ -2,6 +2,13 @@ import invariant from 'invariant';
|
|
|
2
2
|
|
|
3
3
|
import { EntityConfiguration } from './EntityConfiguration';
|
|
4
4
|
import { EntityQueryContext } from './EntityQueryContext';
|
|
5
|
+
import {
|
|
6
|
+
EntityDatabaseAdapterEmptyInsertResultError,
|
|
7
|
+
EntityDatabaseAdapterEmptyUpdateResultError,
|
|
8
|
+
EntityDatabaseAdapterExcessiveDeleteResultError,
|
|
9
|
+
EntityDatabaseAdapterExcessiveInsertResultError,
|
|
10
|
+
EntityDatabaseAdapterExcessiveUpdateResultError,
|
|
11
|
+
} from './errors/EntityDatabaseAdapterError';
|
|
5
12
|
import {
|
|
6
13
|
FieldTransformerMap,
|
|
7
14
|
getDatabaseFieldForEntityField,
|
|
@@ -303,12 +310,15 @@ export abstract class EntityDatabaseAdapter<
|
|
|
303
310
|
dbObject,
|
|
304
311
|
);
|
|
305
312
|
|
|
313
|
+
// These should never happen with a properly implemented database adapter unless the underlying database has weird triggers
|
|
314
|
+
// or something.
|
|
315
|
+
// These errors are exposed to help application developers detect and diagnose such issues.
|
|
306
316
|
if (results.length > 1) {
|
|
307
|
-
throw new
|
|
317
|
+
throw new EntityDatabaseAdapterExcessiveInsertResultError(
|
|
308
318
|
`Excessive results from database adapter insert: ${this.entityConfiguration.tableName}`,
|
|
309
319
|
);
|
|
310
320
|
} else if (results.length === 0) {
|
|
311
|
-
throw new
|
|
321
|
+
throw new EntityDatabaseAdapterEmptyInsertResultError(
|
|
312
322
|
`Empty results from database adapter insert: ${this.entityConfiguration.tableName}`,
|
|
313
323
|
);
|
|
314
324
|
}
|
|
@@ -356,11 +366,14 @@ export abstract class EntityDatabaseAdapter<
|
|
|
356
366
|
);
|
|
357
367
|
|
|
358
368
|
if (results.length > 1) {
|
|
359
|
-
|
|
369
|
+
// This should never happen with a properly implemented database adapter unless the underlying table has a non-unique
|
|
370
|
+
// primary key column.
|
|
371
|
+
throw new EntityDatabaseAdapterExcessiveUpdateResultError(
|
|
360
372
|
`Excessive results from database adapter update: ${this.entityConfiguration.tableName}(id = ${id})`,
|
|
361
373
|
);
|
|
362
374
|
} else if (results.length === 0) {
|
|
363
|
-
|
|
375
|
+
// This happens when the object to update does not exist. It may have been deleted by another process.
|
|
376
|
+
throw new EntityDatabaseAdapterEmptyUpdateResultError(
|
|
364
377
|
`Empty results from database adapter update: ${this.entityConfiguration.tableName}(id = ${id})`,
|
|
365
378
|
);
|
|
366
379
|
}
|
|
@@ -401,7 +414,7 @@ export abstract class EntityDatabaseAdapter<
|
|
|
401
414
|
);
|
|
402
415
|
|
|
403
416
|
if (numDeleted > 1) {
|
|
404
|
-
throw new
|
|
417
|
+
throw new EntityDatabaseAdapterExcessiveDeleteResultError(
|
|
405
418
|
`Excessive deletions from database adapter delete: ${this.entityConfiguration.tableName}(id = ${id})`,
|
|
406
419
|
);
|
|
407
420
|
}
|
package/src/EntityFields.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
// Use our own regex since the `uuid` package doesn't support validating UUIDv6/7/8 yet
|
|
8
8
|
const UUID_REGEX =
|
|
9
|
-
/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)
|
|
9
|
+
/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* EntityFieldDefinition for a column with a JS string type.
|
|
@@ -22,7 +22,9 @@ export class StringField<TRequireExplicitCache extends boolean> extends EntityFi
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* EntityFieldDefinition for a column with a JS string type.
|
|
25
|
-
* Enforces that the string is a valid UUID.
|
|
25
|
+
* Enforces that the string is a valid UUID and that it is lowercase. Entity requires UUIDs to be lowercase since most
|
|
26
|
+
* databases (e.g. Postgres) treat UUIDs as case-insensitive, which can lead to unexpected entity load results if mixed-case
|
|
27
|
+
* UUIDs are used.
|
|
26
28
|
*/
|
|
27
29
|
export class UUIDField<
|
|
28
30
|
TRequireExplicitCache extends boolean,
|
|
@@ -7,6 +7,13 @@ import {
|
|
|
7
7
|
TableFieldSingleValueEqualityCondition,
|
|
8
8
|
} from '../EntityDatabaseAdapter';
|
|
9
9
|
import { EntityQueryContext } from '../EntityQueryContext';
|
|
10
|
+
import {
|
|
11
|
+
EntityDatabaseAdapterEmptyInsertResultError,
|
|
12
|
+
EntityDatabaseAdapterEmptyUpdateResultError,
|
|
13
|
+
EntityDatabaseAdapterExcessiveDeleteResultError,
|
|
14
|
+
EntityDatabaseAdapterExcessiveInsertResultError,
|
|
15
|
+
EntityDatabaseAdapterExcessiveUpdateResultError,
|
|
16
|
+
} from '../errors/EntityDatabaseAdapterError';
|
|
10
17
|
import { CompositeFieldHolder, CompositeFieldValueHolder } from '../internal/CompositeFieldHolder';
|
|
11
18
|
import { FieldTransformerMap } from '../internal/EntityFieldTransformationUtils';
|
|
12
19
|
import { SingleFieldHolder, SingleFieldValueHolder } from '../internal/SingleFieldHolder';
|
|
@@ -264,7 +271,7 @@ describe(EntityDatabaseAdapter, () => {
|
|
|
264
271
|
const queryContext = instance(mock(EntityQueryContext));
|
|
265
272
|
const adapter = new TestEntityDatabaseAdapter({ insertResults: [] });
|
|
266
273
|
await expect(adapter.insertAsync(queryContext, {} as any)).rejects.toThrow(
|
|
267
|
-
|
|
274
|
+
EntityDatabaseAdapterEmptyInsertResultError,
|
|
268
275
|
);
|
|
269
276
|
});
|
|
270
277
|
|
|
@@ -274,7 +281,7 @@ describe(EntityDatabaseAdapter, () => {
|
|
|
274
281
|
insertResults: [{ string_field: 'hello' }, { string_field: 'hello2' }],
|
|
275
282
|
});
|
|
276
283
|
await expect(adapter.insertAsync(queryContext, {} as any)).rejects.toThrow(
|
|
277
|
-
|
|
284
|
+
EntityDatabaseAdapterExcessiveInsertResultError,
|
|
278
285
|
);
|
|
279
286
|
});
|
|
280
287
|
});
|
|
@@ -292,7 +299,7 @@ describe(EntityDatabaseAdapter, () => {
|
|
|
292
299
|
const adapter = new TestEntityDatabaseAdapter({ updateResults: [] });
|
|
293
300
|
await expect(
|
|
294
301
|
adapter.updateAsync(queryContext, 'customIdField', 'wat', {} as any),
|
|
295
|
-
).rejects.toThrow(
|
|
302
|
+
).rejects.toThrow(EntityDatabaseAdapterEmptyUpdateResultError);
|
|
296
303
|
});
|
|
297
304
|
|
|
298
305
|
it('throws when update result count greater than 1', async () => {
|
|
@@ -302,7 +309,7 @@ describe(EntityDatabaseAdapter, () => {
|
|
|
302
309
|
});
|
|
303
310
|
await expect(
|
|
304
311
|
adapter.updateAsync(queryContext, 'customIdField', 'wat', {} as any),
|
|
305
|
-
).rejects.toThrow(
|
|
312
|
+
).rejects.toThrow(EntityDatabaseAdapterExcessiveUpdateResultError);
|
|
306
313
|
});
|
|
307
314
|
});
|
|
308
315
|
|
|
@@ -311,7 +318,7 @@ describe(EntityDatabaseAdapter, () => {
|
|
|
311
318
|
const queryContext = instance(mock(EntityQueryContext));
|
|
312
319
|
const adapter = new TestEntityDatabaseAdapter({ deleteCount: 2 });
|
|
313
320
|
await expect(adapter.deleteAsync(queryContext, 'customIdField', 'wat')).rejects.toThrow(
|
|
314
|
-
|
|
321
|
+
EntityDatabaseAdapterExcessiveDeleteResultError,
|
|
315
322
|
);
|
|
316
323
|
});
|
|
317
324
|
});
|
|
@@ -65,7 +65,7 @@ describeFieldTestCase(
|
|
|
65
65
|
uuidv5('wat', uuidv5.DNS),
|
|
66
66
|
/* UUIDv7 */ '018ebfda-dc80-782d-a891-22a0aa057d52',
|
|
67
67
|
],
|
|
68
|
-
[uuidv4().replace('-', ''), '', 'hello'],
|
|
68
|
+
[uuidv4().replace('-', ''), '', 'hello', uuidv4().toUpperCase()],
|
|
69
69
|
);
|
|
70
70
|
describeFieldTestCase(new DateField({ columnName: 'wat' }), [new Date()], [Date.now()]);
|
|
71
71
|
describeFieldTestCase(new BooleanField({ columnName: 'wat' }), [true, false], [0, 1, '']);
|
package/src/entityUtils.ts
CHANGED
|
@@ -79,9 +79,9 @@ export type PartitionArrayPredicate<T, U> = (val: T | U) => val is T;
|
|
|
79
79
|
* @param predicate - binary predicate to evaluate partition group of each value
|
|
80
80
|
*/
|
|
81
81
|
export const partitionArray = <T, U>(
|
|
82
|
-
values: (T | U)[],
|
|
82
|
+
values: readonly (T | U)[],
|
|
83
83
|
predicate: PartitionArrayPredicate<T, U>,
|
|
84
|
-
): [T[], U[]] => {
|
|
84
|
+
): readonly [readonly T[], readonly U[]] => {
|
|
85
85
|
const ts: T[] = [];
|
|
86
86
|
const us: U[] = [];
|
|
87
87
|
|
|
@@ -100,7 +100,9 @@ export const partitionArray = <T, U>(
|
|
|
100
100
|
* Partition array of values and errors into an array of values and an array of errors.
|
|
101
101
|
* @param valuesAndErrors - array of values and errors
|
|
102
102
|
*/
|
|
103
|
-
export const partitionErrors = <T>(
|
|
103
|
+
export const partitionErrors = <T>(
|
|
104
|
+
valuesAndErrors: readonly (T | Error)[],
|
|
105
|
+
): readonly [readonly T[], readonly Error[]] => {
|
|
104
106
|
const [errors, values] = partitionArray<Error, T>(valuesAndErrors, isError);
|
|
105
107
|
return [values, errors];
|
|
106
108
|
};
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { EntityError, EntityErrorCode, EntityErrorState } from './EntityError';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Base class for errors thrown by the entity cache adapter.
|
|
5
|
+
*/
|
|
3
6
|
export abstract class EntityCacheAdapterError extends EntityError {}
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when a transient error occurs in the entity cache adapter.
|
|
10
|
+
* Transient errors may succeed if retried.
|
|
11
|
+
*/
|
|
5
12
|
export class EntityCacheAdapterTransientError extends EntityCacheAdapterError {
|
|
6
13
|
public readonly state = EntityErrorState.TRANSIENT;
|
|
7
14
|
public readonly code = EntityErrorCode.ERR_ENTITY_CACHE_ADAPTER_TRANSIENT;
|
|
@@ -1,38 +1,121 @@
|
|
|
1
1
|
import { EntityError, EntityErrorCode, EntityErrorState } from './EntityError';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Base class for all errors related to the database adapter.
|
|
5
|
+
*/
|
|
3
6
|
export abstract class EntityDatabaseAdapterError extends EntityError {}
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Thrown when a transient error occurrs within the database adapter.
|
|
10
|
+
* Transient errors may succeed if retried.
|
|
11
|
+
*/
|
|
5
12
|
export class EntityDatabaseAdapterTransientError extends EntityDatabaseAdapterError {
|
|
6
13
|
public readonly state = EntityErrorState.TRANSIENT;
|
|
7
14
|
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_TRANSIENT;
|
|
8
15
|
}
|
|
9
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Thrown when an unknown error occurrs within the database adapter.
|
|
19
|
+
* This is a catch-all error class for DBMS-specific errors that do not fit into other categories.
|
|
20
|
+
*/
|
|
10
21
|
export class EntityDatabaseAdapterUnknownError extends EntityDatabaseAdapterError {
|
|
11
22
|
public readonly state = EntityErrorState.UNKNOWN;
|
|
12
23
|
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_UNKNOWN;
|
|
13
24
|
}
|
|
14
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Thrown when a check constraint is violated within the database adapter.
|
|
28
|
+
* This indicates that a value being inserted or updated does not satisfy a defined data integrity constraint.
|
|
29
|
+
*/
|
|
15
30
|
export class EntityDatabaseAdapterCheckConstraintError extends EntityDatabaseAdapterError {
|
|
16
31
|
public readonly state = EntityErrorState.PERMANENT;
|
|
17
32
|
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_CHECK_CONSTRAINT;
|
|
18
33
|
}
|
|
19
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Thrown when an exclusion constraint is violated within the database adapter.
|
|
37
|
+
* This indicates that a value being inserted or updated conflicts with an existing value based on a defined exclusion constraint.
|
|
38
|
+
*/
|
|
20
39
|
export class EntityDatabaseAdapterExclusionConstraintError extends EntityDatabaseAdapterError {
|
|
21
40
|
public readonly state = EntityErrorState.PERMANENT;
|
|
22
41
|
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCLUSION_CONSTRAINT;
|
|
23
42
|
}
|
|
24
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Thrown when a foreign key constraint is violated within the database adapter.
|
|
46
|
+
* This indicates that a value being inserted, updated, or deleted references a non-existent value in a related table
|
|
47
|
+
* or is referenced in a related table.
|
|
48
|
+
*/
|
|
25
49
|
export class EntityDatabaseAdapterForeignKeyConstraintError extends EntityDatabaseAdapterError {
|
|
26
50
|
public readonly state = EntityErrorState.PERMANENT;
|
|
27
51
|
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_FOREIGN_KEY_CONSTRAINT;
|
|
28
52
|
}
|
|
29
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Thrown when a not-null constraint is violated within the database adapter.
|
|
56
|
+
* This indicates that a null value is being inserted or updated into a column that does not allow null values.
|
|
57
|
+
*/
|
|
30
58
|
export class EntityDatabaseAdapterNotNullConstraintError extends EntityDatabaseAdapterError {
|
|
31
59
|
public readonly state = EntityErrorState.PERMANENT;
|
|
32
60
|
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_NOT_NULL_CONSTRAINT;
|
|
33
61
|
}
|
|
34
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Thrown when a unique constraint is violated within the database adapter.
|
|
65
|
+
* This indicates that a value being inserted or updated duplicates an existing value in a column or set of columns
|
|
66
|
+
* that require unique values.
|
|
67
|
+
*/
|
|
35
68
|
export class EntityDatabaseAdapterUniqueConstraintError extends EntityDatabaseAdapterError {
|
|
36
69
|
public readonly state = EntityErrorState.PERMANENT;
|
|
37
70
|
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_UNIQUE_CONSTRAINT;
|
|
38
71
|
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Thrown when an insert operation returns more results than expected. Only one row is expected.
|
|
75
|
+
* These should never happen with a properly implemented database adapter unless the underlying database has nonstandard
|
|
76
|
+
* triggers or something similar.
|
|
77
|
+
*/
|
|
78
|
+
export class EntityDatabaseAdapterExcessiveInsertResultError extends EntityDatabaseAdapterError {
|
|
79
|
+
public readonly state = EntityErrorState.PERMANENT;
|
|
80
|
+
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_INSERT_RESULT;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Thrown when an insert operation returns no results. One row is expected.
|
|
85
|
+
* These should never happen with a properly implemented database adapter unless the underlying database has nonstandard
|
|
86
|
+
* triggers or something similar.
|
|
87
|
+
*/
|
|
88
|
+
export class EntityDatabaseAdapterEmptyInsertResultError extends EntityDatabaseAdapterError {
|
|
89
|
+
public readonly state = EntityErrorState.PERMANENT;
|
|
90
|
+
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EMPTY_INSERT_RESULT;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Thrown when an update operation returns more results than expected. Only one row is expected.
|
|
95
|
+
* These should never happen with a properly implemented database adapter unless the underlying table has a non-unique
|
|
96
|
+
* primary key column.
|
|
97
|
+
*/
|
|
98
|
+
export class EntityDatabaseAdapterExcessiveUpdateResultError extends EntityDatabaseAdapterError {
|
|
99
|
+
public readonly state = EntityErrorState.PERMANENT;
|
|
100
|
+
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_UPDATE_RESULT;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Thrown when an update operation returns no results. One row is expected.
|
|
105
|
+
* This most often happens when attempting to update a non-existent row, often indicating that the row
|
|
106
|
+
* was deleted by a different process between fetching and updating it in this process.
|
|
107
|
+
*/
|
|
108
|
+
export class EntityDatabaseAdapterEmptyUpdateResultError extends EntityDatabaseAdapterError {
|
|
109
|
+
public readonly state = EntityErrorState.PERMANENT;
|
|
110
|
+
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EMPTY_UPDATE_RESULT;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Thrown when a delete operation returns more results than expected. Only one row is expected.
|
|
115
|
+
* These should never happen with a properly implemented database adapter unless the underlying table has a non-unique
|
|
116
|
+
* primary key column.
|
|
117
|
+
*/
|
|
118
|
+
export class EntityDatabaseAdapterExcessiveDeleteResultError extends EntityDatabaseAdapterError {
|
|
119
|
+
public readonly state = EntityErrorState.PERMANENT;
|
|
120
|
+
public readonly code = EntityErrorCode.ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_DELETE_RESULT;
|
|
121
|
+
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import ES6Error from 'es6-error';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* The state of an entity error, indicating whether it may be transient/retryable.
|
|
5
|
+
*/
|
|
3
6
|
export enum EntityErrorState {
|
|
4
7
|
UNKNOWN,
|
|
5
8
|
TRANSIENT,
|
|
6
9
|
PERMANENT,
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Error code for an entity error. Each error code should map to a specific class of Entity error.
|
|
14
|
+
*/
|
|
9
15
|
export enum EntityErrorCode {
|
|
10
16
|
ERR_ENTITY_NOT_AUTHORIZED = 'ERR_ENTITY_NOT_AUTHORIZED',
|
|
11
17
|
ERR_ENTITY_NOT_FOUND = 'ERR_ENTITY_NOT_FOUND',
|
|
@@ -17,9 +23,17 @@ export enum EntityErrorCode {
|
|
|
17
23
|
ERR_ENTITY_DATABASE_ADAPTER_FOREIGN_KEY_CONSTRAINT = 'ERR_ENTITY_DATABASE_ADAPTER_FOREIGN_KEY_CONSTRAINT',
|
|
18
24
|
ERR_ENTITY_DATABASE_ADAPTER_NOT_NULL_CONSTRAINT = 'ERR_ENTITY_DATABASE_ADAPTER_NOT_NULL_CONSTRAINT',
|
|
19
25
|
ERR_ENTITY_DATABASE_ADAPTER_UNIQUE_CONSTRAINT = 'ERR_ENTITY_DATABASE_ADAPTER_UNIQUE_CONSTRAINT',
|
|
26
|
+
ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_INSERT_RESULT = 'ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_INSERT_RESULT',
|
|
27
|
+
ERR_ENTITY_DATABASE_ADAPTER_EMPTY_INSERT_RESULT = 'ERR_ENTITY_DATABASE_ADAPTER_EMPTY_INSERT_RESULT',
|
|
28
|
+
ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_UPDATE_RESULT = 'ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_UPDATE_RESULT',
|
|
29
|
+
ERR_ENTITY_DATABASE_ADAPTER_EMPTY_UPDATE_RESULT = 'ERR_ENTITY_DATABASE_ADAPTER_EMPTY_UPDATE_RESULT',
|
|
30
|
+
ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_DELETE_RESULT = 'ERR_ENTITY_DATABASE_ADAPTER_EXCESSIVE_DELETE_RESULT',
|
|
20
31
|
ERR_ENTITY_CACHE_ADAPTER_TRANSIENT = 'ERR_ENTITY_CACHE_ADAPTER_TRANSIENT',
|
|
21
32
|
}
|
|
22
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Base class for all known errors thrown by the entity system.
|
|
36
|
+
*/
|
|
23
37
|
export abstract class EntityError extends ES6Error {
|
|
24
38
|
public abstract readonly state: EntityErrorState;
|
|
25
39
|
public abstract readonly code: EntityErrorCode;
|
|
@@ -4,6 +4,9 @@ import { ReadonlyEntity } from '../ReadonlyEntity';
|
|
|
4
4
|
import { ViewerContext } from '../ViewerContext';
|
|
5
5
|
import { EntityError, EntityErrorCode, EntityErrorState } from './EntityError';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when an entity field has an invalid value, either during load or mutation.
|
|
9
|
+
*/
|
|
7
10
|
export class EntityInvalidFieldValueError<
|
|
8
11
|
TFields extends Record<string, any>,
|
|
9
12
|
TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>,
|
|
@@ -3,6 +3,9 @@ import { ReadonlyEntity } from '../ReadonlyEntity';
|
|
|
3
3
|
import { ViewerContext } from '../ViewerContext';
|
|
4
4
|
import { EntityError, EntityErrorCode, EntityErrorState } from './EntityError';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when viewer context is not authorized to perform an action on an entity.
|
|
8
|
+
*/
|
|
6
9
|
export class EntityNotAuthorizedError<
|
|
7
10
|
TFields extends Record<string, any>,
|
|
8
11
|
TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>,
|
|
@@ -31,6 +31,9 @@ type EntityNotFoundOptions<
|
|
|
31
31
|
fieldValue: TFields[N];
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Error thrown when an entity is not found during certain load methods.
|
|
36
|
+
*/
|
|
34
37
|
export class EntityNotFoundError<
|
|
35
38
|
TFields extends Record<string, any>,
|
|
36
39
|
TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>,
|