@travetto/model 5.0.10 → 5.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model",
3
- "version": "5.0.10",
3
+ "version": "5.0.12",
4
4
  "description": "Datastore abstraction for core operations.",
5
5
  "keywords": [
6
6
  "datastore",
@@ -26,14 +26,14 @@
26
26
  "directory": "module/model"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/config": "^5.0.9",
30
- "@travetto/di": "^5.0.9",
31
- "@travetto/registry": "^5.0.9",
32
- "@travetto/schema": "^5.0.9"
29
+ "@travetto/config": "^5.0.11",
30
+ "@travetto/di": "^5.0.11",
31
+ "@travetto/registry": "^5.0.11",
32
+ "@travetto/schema": "^5.0.11"
33
33
  },
34
34
  "peerDependencies": {
35
- "@travetto/cli": "^5.0.9",
36
- "@travetto/test": "^5.0.9"
35
+ "@travetto/cli": "^5.0.11",
36
+ "@travetto/test": "^5.0.11"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@travetto/cli": {
@@ -5,6 +5,6 @@ import { Class, AppError } from '@travetto/runtime';
5
5
  */
6
6
  export class ExistsError extends AppError {
7
7
  constructor(cls: Class | string, id: string) {
8
- super(`${typeof cls === 'string' ? cls : cls.name} with id ${id} already exists`, 'data');
8
+ super(`${typeof cls === 'string' ? cls : cls.name} with id ${id} already exists`, { category: 'data' });
9
9
  }
10
10
  }
@@ -8,6 +8,6 @@ import { ModelType } from '../types/model';
8
8
  */
9
9
  export class IndexNotSupported<T extends ModelType> extends AppError {
10
10
  constructor(cls: Class<T>, idx: IndexConfig<T>, message: string = '') {
11
- super(`${typeof cls === 'string' ? cls : cls.name} and index ${idx.name} of type ${idx.type} is not supported. ${message}`.trim(), 'data');
11
+ super(`${typeof cls === 'string' ? cls : cls.name} and index ${idx.name} of type ${idx.type} is not supported. ${message}`.trim(), { category: 'data' });
12
12
  }
13
13
  }
@@ -5,6 +5,6 @@ import { Class, AppError } from '@travetto/runtime';
5
5
  */
6
6
  export class SubTypeNotSupportedError extends AppError {
7
7
  constructor(cls: Class | string) {
8
- super(`${typeof cls === 'string' ? cls : cls.name} cannot be used for this operation`, 'data');
8
+ super(`${typeof cls === 'string' ? cls : cls.name} cannot be used for this operation`, { category: 'data' });
9
9
  }
10
10
  }
@@ -4,7 +4,7 @@ import { Class, AppError } from '@travetto/runtime';
4
4
  * Represents when a model of cls and id cannot be found
5
5
  */
6
6
  export class NotFoundError extends AppError {
7
- constructor(cls: Class | string, id: string, details?: unknown) {
8
- super(`${typeof cls === 'string' ? cls : cls.name} with id ${id} not found`, 'notfound', details);
7
+ constructor(cls: Class | string, id: string, details?: Record<string, unknown>) {
8
+ super(`${typeof cls === 'string' ? cls : cls.name} with id ${id} not found`, { category: 'notfound', details });
9
9
  }
10
10
  }
@@ -39,7 +39,7 @@ export class ModelBlobUtil {
39
39
  end = Math.min(end ?? (size - 1), size - 1);
40
40
 
41
41
  if (Number.isNaN(start) || Number.isNaN(end) || !Number.isFinite(start) || start >= size || start < 0 || start > end) {
42
- throw new AppError('Invalid position, out of range', 'data');
42
+ throw new AppError('Invalid position, out of range', { category: 'data' });
43
43
  }
44
44
 
45
45
  return { start, end };
@@ -140,7 +140,7 @@ export class ModelCrudUtil {
140
140
  */
141
141
  static async prePartialUpdate<T extends ModelType>(cls: Class<T>, item: Partial<T>, view?: string): Promise<Partial<T>> {
142
142
  if (!DataUtil.isPlainObject(item)) {
143
- throw new AppError(`A partial update requires a plain object, not an instance of ${castTo<Function>(item).constructor.name}`, 'data');
143
+ throw new AppError(`A partial update requires a plain object, not an instance of ${castTo<Function>(item).constructor.name}`, { category: 'data' });
144
144
  }
145
145
  const res = await this.prePersist(cls, castTo(item), 'partial');
146
146
  await SchemaValidator.validatePartial(cls, item, view);
@@ -167,12 +167,12 @@ class $ModelRegistry extends MetadataRegistry<ModelOptions<ModelType>> {
167
167
  // Don't allow two models with same class name, or same store name
168
168
  if (candidates.length > 1) {
169
169
  if (config.store) {
170
- throw new AppError('Duplicate models with same store name', 'general', {
171
- classes: candidates.map(x => x.Ⲑid)
170
+ throw new AppError('Duplicate models with same store name', {
171
+ details: { classes: candidates.map(x => x.Ⲑid) }
172
172
  });
173
173
  } else {
174
- throw new AppError('Duplicate models with same class name, but no store name provided', 'general', {
175
- classes: candidates.map(x => x.Ⲑid)
174
+ throw new AppError('Duplicate models with same class name, but no store name provided', {
175
+ details: { classes: candidates.map(x => x.Ⲑid) }
176
176
  });
177
177
  }
178
178
  }
@@ -210,7 +210,7 @@ class $ModelRegistry extends MetadataRegistry<ModelOptions<ModelType>> {
210
210
  getExpiry<T extends ModelType>(cls: Class<T>): keyof T {
211
211
  const expiry = this.get(cls).expiresAt;
212
212
  if (!expiry) {
213
- throw new AppError(`${cls.name} is not configured with expiry support, please use @ExpiresAt to declare expiration behavior`, 'general');
213
+ throw new AppError(`${cls.name} is not configured with expiry support, please use @ExpiresAt to declare expiration behavior`);
214
214
  }
215
215
  return castTo(expiry);
216
216
  }
@@ -1,5 +1,5 @@
1
1
  import { Class, AppError } from '@travetto/runtime';
2
- import { ValidationResultError } from '@travetto/schema';
2
+ import { ValidationError, ValidationResultError } from '@travetto/schema';
3
3
 
4
4
  import { ModelCrudSupport } from './crud';
5
5
  import { ModelType, OptionalId } from '../types/model';
@@ -37,16 +37,21 @@ export interface BulkResponse<E = unknown> {
37
37
  };
38
38
  }
39
39
 
40
+ type BulkErrorItem = { message: string, type: string, errors?: ValidationError[], idx: number };
41
+
40
42
  /**
41
43
  * Bulk processing error
42
44
  */
43
- export class BulkProcessError extends AppError {
45
+ export class BulkProcessError extends AppError<{ errors: BulkErrorItem[] }> {
44
46
  constructor(public errors: { idx: number, error: ValidationResultError }[]) {
45
- super('Bulk processing errors have occurred', 'data', {
46
- errors: errors.map(x => {
47
- const { message, type, details: { errors: subErrors } = {}, details } = x.error;
48
- return { message, type, errors: subErrors ?? details, idx: x.idx };
49
- })
47
+ super('Bulk processing errors have occurred', {
48
+ category: 'data',
49
+ details: {
50
+ errors: errors.map(x => {
51
+ const { message, type, details: { errors: subErrors } = {} } = x.error;
52
+ return { message, type, errors: subErrors, idx: x.idx };
53
+ })
54
+ }
50
55
  });
51
56
  }
52
57
  }