@kravc/dos 2.0.0-alpha.1 → 2.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Document/Document.d.ts +18 -5
- package/dist/Document/Document.d.ts.map +1 -1
- package/dist/Document/Document.js +27 -10
- package/dist/Document/Document.js.map +1 -1
- package/dist/Document/MemoryDocument.d.ts +5 -4
- package/dist/Document/MemoryDocument.d.ts.map +1 -1
- package/dist/Document/MemoryDocument.js +13 -7
- package/dist/Document/MemoryDocument.js.map +1 -1
- package/dist/Operation/Operation.js +2 -2
- package/dist/Operation/errors/{UnprocessibleConditionError.d.ts → UnprocessableConditionError.d.ts} +6 -6
- package/dist/Operation/errors/{UnprocessibleConditionError.d.ts.map → UnprocessableConditionError.d.ts.map} +1 -1
- package/dist/Operation/errors/{UnprocessibleConditionError.js → UnprocessableConditionError.js} +8 -8
- package/dist/Operation/errors/{UnprocessibleConditionError.js.map → UnprocessableConditionError.js.map} +1 -1
- package/dist/Operation/errors/index.d.ts +2 -2
- package/dist/Operation/errors/index.js +3 -3
- package/dist/Operation/operations/Index.js +7 -7
- package/dist/Operation/operations/Index.js.map +1 -1
- package/dist/Operation/operations/List.js +2 -2
- package/dist/Operation/operations/List.js.map +1 -1
- package/dist/Service/errors/OperationError.d.ts +2 -2
- package/dist/Service/errors/OperationError.d.ts.map +1 -1
- package/dist/Service/errors/OperationError.js.map +1 -1
- package/package.json +5 -5
- package/src/Document/Document.ts +50 -15
- package/src/Document/MemoryDocument.ts +16 -8
- package/src/Document/__tests__/MemoryDocument.test.ts +16 -0
- package/src/Operation/Operation.ts +2 -2
- package/src/Operation/errors/{UnprocessibleConditionError.ts → UnprocessableConditionError.ts} +7 -7
- package/src/Operation/errors/__tests__/UnprocessableConditionError.test.ts +20 -0
- package/src/Operation/errors/index.ts +2 -2
- package/src/Operation/operations/Index.ts +8 -8
- package/src/Operation/operations/List.ts +2 -2
- package/src/Operation/operations/__tests__/Create.test.ts +1 -1
- package/src/Operation/operations/__tests__/Delete.test.ts +1 -1
- package/src/Operation/operations/__tests__/Index.test.ts +4 -4
- package/src/Operation/operations/__tests__/List.test.ts +1 -1
- package/src/Operation/operations/__tests__/Read.test.ts +1 -1
- package/src/Operation/operations/__tests__/Update.test.ts +1 -1
- package/src/Service/__tests__/Service.test.ts +1 -6
- package/src/Service/errors/OperationError.ts +2 -2
- package/src/Service/errors/OperationErrorAttributes.d.ts +1 -1
- package/src/Operation/errors/__tests__/UnprocessibleConditionError.test.ts +0 -20
|
@@ -4,15 +4,16 @@ import Context, { type QueryMap, type MutationMap } from '../Context';
|
|
|
4
4
|
export type IndexOptions = {
|
|
5
5
|
sort?: 'asc' | 'desc';
|
|
6
6
|
limit?: number;
|
|
7
|
-
|
|
7
|
+
indexName?: string;
|
|
8
8
|
exclusiveStartKey?: string;
|
|
9
9
|
};
|
|
10
10
|
export type IndexAllOptions = {
|
|
11
11
|
sort?: 'asc' | 'desc';
|
|
12
|
-
|
|
12
|
+
indexName?: string;
|
|
13
13
|
};
|
|
14
14
|
export type DefaultAttributes = {
|
|
15
15
|
id: string;
|
|
16
|
+
partition: string;
|
|
16
17
|
createdAt: string;
|
|
17
18
|
createdBy: string;
|
|
18
19
|
createdByUserName?: string;
|
|
@@ -22,7 +23,14 @@ export type DefaultAttributes = {
|
|
|
22
23
|
};
|
|
23
24
|
type Constructor<T, D extends Document<T> = Document<T>> = {
|
|
24
25
|
new (context: Context, attributes: T): D;
|
|
26
|
+
index<T, D extends Document<T> = Document<T>>(context: Context, query?: QueryMap, options?: IndexOptions): Promise<{
|
|
27
|
+
limit: number;
|
|
28
|
+
count: number;
|
|
29
|
+
objects: D[];
|
|
30
|
+
lastEvaluatedKey?: string;
|
|
31
|
+
}>;
|
|
25
32
|
_index(query: QueryMap, options: IndexOptions): Promise<{
|
|
33
|
+
limit: number;
|
|
26
34
|
count: number;
|
|
27
35
|
items: T[];
|
|
28
36
|
lastEvaluatedKey?: string;
|
|
@@ -32,9 +40,9 @@ type Constructor<T, D extends Document<T> = Document<T>> = {
|
|
|
32
40
|
items: T[];
|
|
33
41
|
}>;
|
|
34
42
|
_read(query: QueryMap, options: unknown): Promise<T>;
|
|
35
|
-
_create(attributes: T): Promise<void>;
|
|
36
|
-
_update<T>(query: QueryMap, mutation: MutationMap): Promise<T>;
|
|
37
|
-
_delete(query: QueryMap): Promise<void>;
|
|
43
|
+
_create(attributes: T, context: Context): Promise<void>;
|
|
44
|
+
_update<T>(query: QueryMap, mutation: MutationMap, context: Context, previousAttributes: T): Promise<T>;
|
|
45
|
+
_delete(query: QueryMap, context: Context, previousAttributes: T): Promise<void>;
|
|
38
46
|
};
|
|
39
47
|
/** Abstract document class. */
|
|
40
48
|
declare class Document<Attributes> extends Component<Attributes> {
|
|
@@ -50,6 +58,8 @@ declare class Document<Attributes> extends Component<Attributes> {
|
|
|
50
58
|
static get indexDefaultSort(): 'asc' | 'desc';
|
|
51
59
|
/** Defines default limit for index action. */
|
|
52
60
|
static get indexDefaultLimit(): number;
|
|
61
|
+
/** Defines limit maximum value for index action. */
|
|
62
|
+
static get indexLimitMax(): number;
|
|
53
63
|
/** Generates ID for new document unless it's defined in parameters. */
|
|
54
64
|
static createId(attributes: Record<string, unknown>): string;
|
|
55
65
|
/** Returns default attributes schema source. */
|
|
@@ -70,8 +80,11 @@ declare class Document<Attributes> extends Component<Attributes> {
|
|
|
70
80
|
static _extendWithCreatedStamps(context: Context, mutation: MutationMap): void;
|
|
71
81
|
/** Extends mutation with updated stamps. */
|
|
72
82
|
static _extendWithUpdatedStamps(context: Context, mutation: MutationMap): void;
|
|
83
|
+
/** Extends mutation with deleted stamps. */
|
|
84
|
+
static _extendWithDeletedStamps(context: Context, mutation: MutationMap): void;
|
|
73
85
|
/** Returns documents in batches. */
|
|
74
86
|
static index<T, D extends Document<T> = Document<T>>(this: Constructor<T, D>, context: Context, query?: QueryMap, options?: IndexOptions): Promise<{
|
|
87
|
+
limit: number;
|
|
75
88
|
count: number;
|
|
76
89
|
objects: D[];
|
|
77
90
|
lastEvaluatedKey?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.d.ts","sourceRoot":"","sources":["../../src/Document/Document.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,KAAK,sBAAsB,EAAO,MAAM,eAAe,CAAC;AACzE,OAAO,OAAO,EAAE,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"Document.d.ts","sourceRoot":"","sources":["../../src/Document/Document.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,KAAK,sBAAsB,EAAO,MAAM,eAAe,CAAC;AACzE,OAAO,OAAO,EAAE,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAStE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EA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IrG,yBAAyB;WAEZ,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/H,0BAA0B;WACb,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACxD,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,QAAQ,GACd,OAAO,CAAC,CAAC,CAAC;IAiBb,0BAA0B;WAEb,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7E,yBAAyB;WAEZ,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvG,2BAA2B;IAC3B,IAAI,EAAE,IAAI,MAAM,CAGf;IAED,uDAAuD;IACvD,IAAI,kBAAkB,mCAErB;IAED,sEAAsE;IACtE,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAa1C,mCAAmC;IAC7B,MAAM,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAYnD;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -8,7 +8,8 @@ const Component_1 = __importDefault(require("../Component"));
|
|
|
8
8
|
const schema_1 = require("@kravc/schema");
|
|
9
9
|
const lodash_1 = require("lodash");
|
|
10
10
|
const DEFAULT_INDEX_SORT = 'desc';
|
|
11
|
-
const DEFAULT_INDEX_LIMIT =
|
|
11
|
+
const DEFAULT_INDEX_LIMIT = 20;
|
|
12
|
+
const DEFAULT_INDEX_LIMIT_MAX = 100;
|
|
12
13
|
const DEFAULT_PARTITION_KEY = 'partition';
|
|
13
14
|
/** Abstract document class. */
|
|
14
15
|
class Document extends Component_1.default {
|
|
@@ -34,6 +35,10 @@ class Document extends Component_1.default {
|
|
|
34
35
|
static get indexDefaultLimit() {
|
|
35
36
|
return DEFAULT_INDEX_LIMIT;
|
|
36
37
|
}
|
|
38
|
+
/** Defines limit maximum value for index action. */
|
|
39
|
+
static get indexLimitMax() {
|
|
40
|
+
return DEFAULT_INDEX_LIMIT_MAX;
|
|
41
|
+
}
|
|
37
42
|
/** Generates ID for new document unless it's defined in parameters. */
|
|
38
43
|
static createId(attributes) {
|
|
39
44
|
const id = (0, lodash_1.get)(attributes, this.idKey);
|
|
@@ -126,6 +131,13 @@ class Document extends Component_1.default {
|
|
|
126
131
|
mutation.updatedBy = context.identityId;
|
|
127
132
|
mutation.updatedByUserName = context.identityName;
|
|
128
133
|
}
|
|
134
|
+
/** Extends mutation with deleted stamps. */
|
|
135
|
+
static _extendWithDeletedStamps(context, mutation) {
|
|
136
|
+
const timestamp = new Date().toJSON();
|
|
137
|
+
mutation.deletedAt = timestamp;
|
|
138
|
+
mutation.deletedBy = context.identityId;
|
|
139
|
+
mutation.deletedByUserName = context.identityName;
|
|
140
|
+
}
|
|
129
141
|
/** Returns documents in batches. */
|
|
130
142
|
static async index(context, query = {}, options = {}) {
|
|
131
143
|
const _this = this;
|
|
@@ -136,9 +148,14 @@ class Document extends Component_1.default {
|
|
|
136
148
|
if (!options.sort) {
|
|
137
149
|
options.sort = _this.indexDefaultSort;
|
|
138
150
|
}
|
|
139
|
-
const {
|
|
151
|
+
const { count, limit, items, lastEvaluatedKey } = await this._index(query, options);
|
|
140
152
|
const objects = items.map(attributes => new this(context, attributes));
|
|
141
|
-
return {
|
|
153
|
+
return {
|
|
154
|
+
limit,
|
|
155
|
+
count,
|
|
156
|
+
objects,
|
|
157
|
+
lastEvaluatedKey,
|
|
158
|
+
};
|
|
142
159
|
}
|
|
143
160
|
/** Returns all documents. */
|
|
144
161
|
static async indexAll(context, query = {}, options = {}) {
|
|
@@ -182,7 +199,7 @@ class Document extends Component_1.default {
|
|
|
182
199
|
_this._extendWithCreatedStamps(context, attributes);
|
|
183
200
|
_this._extendWithPartition(context, attributes);
|
|
184
201
|
await _this.beforeCreate(context, query, attributes);
|
|
185
|
-
await this._create(attributes);
|
|
202
|
+
await this._create(attributes, context);
|
|
186
203
|
const object = new this(context, attributes);
|
|
187
204
|
await _this.afterCreate(context, query, mutation, object);
|
|
188
205
|
return object;
|
|
@@ -215,7 +232,7 @@ class Document extends Component_1.default {
|
|
|
215
232
|
if (!previousAttributes) {
|
|
216
233
|
previousAttributes = await this._read(query, {});
|
|
217
234
|
}
|
|
218
|
-
const updatedAttributes = await this._update(query, mutation);
|
|
235
|
+
const updatedAttributes = await this._update(query, mutation, context, previousAttributes);
|
|
219
236
|
const object = new this(context, updatedAttributes);
|
|
220
237
|
object._previousAttributes = previousAttributes;
|
|
221
238
|
await _this.afterUpdate(context, query, mutation, object);
|
|
@@ -236,11 +253,11 @@ class Document extends Component_1.default {
|
|
|
236
253
|
const _this = this;
|
|
237
254
|
_this._extendWithPartition(context, query);
|
|
238
255
|
await _this.beforeDelete(context, query);
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
await _this.afterDelete(context, query,
|
|
243
|
-
return
|
|
256
|
+
const previousAttributes = await this._read(query, {});
|
|
257
|
+
await this._delete(query, context, previousAttributes);
|
|
258
|
+
const deletedObject = new this(context, previousAttributes);
|
|
259
|
+
await _this.afterDelete(context, query, deletedObject);
|
|
260
|
+
return deletedObject;
|
|
244
261
|
}
|
|
245
262
|
/** Before delete hook. */
|
|
246
263
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.js","sourceRoot":"","sources":["../../src/Document/Document.ts"],"names":[],"mappings":";;;;;AAAA,+BAA4B;AAC5B,6DAAqC;AACrC,0CAAyE;AAEzE,mCAAqE;AAErE,MAAM,kBAA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EAAE,aAAa,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;CACF;AAED,kBAAe,QAAQ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Context, { type QueryMap, type MutationMap } from '../Context';
|
|
2
2
|
import Document, { type IndexOptions, type IndexAllOptions } from './Document';
|
|
3
3
|
type Item = {
|
|
4
4
|
id: string;
|
|
@@ -12,6 +12,7 @@ declare class MemoryDocument<T> extends Document<T> {
|
|
|
12
12
|
static reset(): Promise<void>;
|
|
13
13
|
/** Implements interface to get documents in batches. */
|
|
14
14
|
static _index<T>(query: QueryMap, options: IndexOptions): Promise<{
|
|
15
|
+
limit: number;
|
|
15
16
|
count: number;
|
|
16
17
|
items: T[];
|
|
17
18
|
lastEvaluatedKey?: string;
|
|
@@ -24,11 +25,11 @@ declare class MemoryDocument<T> extends Document<T> {
|
|
|
24
25
|
/** Implements interface to get a document. */
|
|
25
26
|
static _read<T>(query: QueryMap): Promise<T>;
|
|
26
27
|
/** Implements interface to save a document. */
|
|
27
|
-
static _create<T>(attributes: T): Promise<void>;
|
|
28
|
+
static _create<T>(attributes: T, _context: Context): Promise<void>;
|
|
28
29
|
/** Implements interface to update a document. */
|
|
29
|
-
static _update<T>(query: QueryMap, mutation: MutationMap): Promise<T>;
|
|
30
|
+
static _update<T>(query: QueryMap, mutation: MutationMap, _context: Context, _previousAttributes: T): Promise<T>;
|
|
30
31
|
/** Implements interface to delete a document. */
|
|
31
|
-
static _delete<T>(query: QueryMap): Promise<void>;
|
|
32
|
+
static _delete<T>(query: QueryMap, _context: Context, _previousAttributes: T): Promise<void>;
|
|
32
33
|
}
|
|
33
34
|
export default MemoryDocument;
|
|
34
35
|
//# sourceMappingURL=MemoryDocument.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryDocument.d.ts","sourceRoot":"","sources":["../../src/Document/MemoryDocument.ts"],"names":[],"mappings":"AACA,OAAO,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AK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAWtH,iDAAiD;WAEpC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAQnG;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -8,6 +8,8 @@ const lodash_1 = require("lodash");
|
|
|
8
8
|
const Operation_1 = require("../Operation");
|
|
9
9
|
const Document_1 = __importDefault(require("./Document"));
|
|
10
10
|
const _MEMORY_STORE = {};
|
|
11
|
+
const QUERY_ERROR_TEMPLATE = 'Query parameter "$PATH" is required';
|
|
12
|
+
const ATTRIBUTE_ERROR_TEMPLATE = 'Attribute "$PATH" is required';
|
|
11
13
|
/** Example implementation of a document class stored in memory. */
|
|
12
14
|
class MemoryDocument extends Document_1.default {
|
|
13
15
|
/** Returns collection where documents are stored. */
|
|
@@ -52,6 +54,7 @@ class MemoryDocument extends Document_1.default {
|
|
|
52
54
|
lastEvaluatedKey = undefined;
|
|
53
55
|
}
|
|
54
56
|
return {
|
|
57
|
+
limit: limit || count,
|
|
55
58
|
items,
|
|
56
59
|
count,
|
|
57
60
|
lastEvaluatedKey,
|
|
@@ -67,7 +70,7 @@ class MemoryDocument extends Document_1.default {
|
|
|
67
70
|
}
|
|
68
71
|
/** Implements interface to get a document. */
|
|
69
72
|
static async _read(query) {
|
|
70
|
-
const idValue = (0, schema_1.got)(query, this.idKey,
|
|
73
|
+
const idValue = (0, schema_1.got)(query, this.idKey, QUERY_ERROR_TEMPLATE);
|
|
71
74
|
const item = (0, lodash_1.get)(this.collection, idValue);
|
|
72
75
|
if (!item) {
|
|
73
76
|
throw new Operation_1.DocumentNotFoundError(this, query);
|
|
@@ -75,8 +78,9 @@ class MemoryDocument extends Document_1.default {
|
|
|
75
78
|
return (0, lodash_1.cloneDeep)(item);
|
|
76
79
|
}
|
|
77
80
|
/** Implements interface to save a document. */
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
82
|
+
static async _create(attributes, _context) {
|
|
83
|
+
const idValue = (0, schema_1.got)(attributes, this.idKey, ATTRIBUTE_ERROR_TEMPLATE);
|
|
80
84
|
const item = (0, lodash_1.get)(this.collection, idValue);
|
|
81
85
|
if (item) {
|
|
82
86
|
throw new Operation_1.DocumentExistsError(this, attributes);
|
|
@@ -84,16 +88,18 @@ class MemoryDocument extends Document_1.default {
|
|
|
84
88
|
(0, lodash_1.set)(this.collection, idValue, attributes);
|
|
85
89
|
}
|
|
86
90
|
/** Implements interface to update a document. */
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
92
|
+
static async _update(query, mutation, _context, _previousAttributes) {
|
|
93
|
+
const idValue = (0, schema_1.got)(query, this.idKey, QUERY_ERROR_TEMPLATE);
|
|
89
94
|
const componentTitle = this.getTitle();
|
|
90
95
|
const item = (0, schema_1.got)(this.collection, idValue, `${componentTitle} with ID "$PATH" is not found`);
|
|
91
96
|
(0, lodash_1.set)(this.collection, idValue, { ...item, ...mutation });
|
|
92
97
|
return (0, lodash_1.cloneDeep)({ ...item, ...mutation });
|
|
93
98
|
}
|
|
94
99
|
/** Implements interface to delete a document. */
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
101
|
+
static async _delete(query, _context, _previousAttributes) {
|
|
102
|
+
const idValue = (0, schema_1.got)(query, this.idKey, QUERY_ERROR_TEMPLATE);
|
|
97
103
|
const componentTitle = this.getTitle();
|
|
98
104
|
(0, schema_1.got)(this.collection, idValue, `${componentTitle} with ID "$PATH" is not found`);
|
|
99
105
|
(0, lodash_1.unset)(this.collection, idValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryDocument.js","sourceRoot":"","sources":["../../src/Document/MemoryDocument.ts"],"names":[],"mappings":";;;;;AAAA,0CAAoC;AAEpC,mCAAmE;AACnE,4CAA0E;AAC1E,0DAA+E;AAO/E,MAAM,aAAa,GAAG,EAA0C,CAAC;AAEjE,mEAAmE;AACnE,MAAM,cAAkB,SAAQ,kBAAW;IACzC,qDAAqD;IACrD,MAAM,KAAK,UAAU;QACnB,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC;QAEjC,MAAM,aAAa,GAAG,CAAC,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;QAEtD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,aAAa,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;QACrC,CAAC;QAED,OAAO,aAAa,CAAC,cAAc,CAAC,CAAC;IACvC,CAAC;IAED,yBAAyB;IACzB,MAAM,CAAC,KAAK,CAAC,KAAK;QAChB,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC;QAEjC,OAAO,aAAa,CAAC,cAAc,CAAC,CAAC;IACvC,CAAC;IAED,wDAAwD;IACxD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAI,KAAe,EAAE,OAAqB;
|
|
1
|
+
{"version":3,"file":"MemoryDocument.js","sourceRoot":"","sources":["../../src/Document/MemoryDocument.ts"],"names":[],"mappings":";;;;;AAAA,0CAAoC;AAEpC,mCAAmE;AACnE,4CAA0E;AAC1E,0DAA+E;AAO/E,MAAM,aAAa,GAAG,EAA0C,CAAC;AAEjE,MAAM,oBAAoB,GAAG,qCAAqC,CAAC;AACnE,MAAM,wBAAwB,GAAG,+BAA+B,CAAC;AAEjE,mEAAmE;AACnE,MAAM,cAAkB,SAAQ,kBAAW;IACzC,qDAAqD;IACrD,MAAM,KAAK,UAAU;QACnB,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC;QAEjC,MAAM,aAAa,GAAG,CAAC,CAAC,aAAa,CAAC,cAAc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AAG,IAAI,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,iDAAiD;IACjD,6DAA6D;IAC7D,MAAM,CAAC,KAAK,CAAC,OAAO,CAAI,KAAe,EAAE,QAAiB,EAAE,mBAAsB;QAChF,MAAM,OAAO,GAAG,IAAA,YAAG,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,oBAAoB,CAAW,CAAC;QAEvE,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvC,IAAA,YAAG,EAAC,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,cAAc,+BAA+B,CAAM,CAAC;QAErF,IAAA,cAAK,EAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAClC,CAAC;CACF;AAED,kBAAe,cAAc,CAAC"}
|
|
@@ -136,10 +136,10 @@ class Operation {
|
|
|
136
136
|
errors.InvalidParametersError = {
|
|
137
137
|
statusCode: 400,
|
|
138
138
|
description: 'Invalid operation parameters, input syntax is correct,' +
|
|
139
|
-
' but input values are not
|
|
139
|
+
' but input values are not processable'
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
|
-
errors.
|
|
142
|
+
errors.UnprocessableConditionError = {
|
|
143
143
|
statusCode: 422,
|
|
144
144
|
description: 'Operation failed to process the request cause of expected' +
|
|
145
145
|
' exit condition'
|
package/dist/Operation/errors/{UnprocessibleConditionError.d.ts → UnprocessableConditionError.d.ts}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import CommonError from './CommonError';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Unprocessable Condition Error
|
|
4
4
|
*
|
|
5
|
-
* `
|
|
5
|
+
* `UnprocessableConditionError` represents a **422 Unprocessable Entity** error that occurs
|
|
6
6
|
* when an operation encounters an expected exit condition that prevents it from processing
|
|
7
7
|
* the request. This error indicates that the request is well-formed and valid, but the
|
|
8
8
|
* operation cannot proceed due to business logic constraints or state conditions.
|
|
@@ -21,9 +21,9 @@ import CommonError from './CommonError';
|
|
|
21
21
|
* The 422 status code indicates that the server understands the request but cannot process
|
|
22
22
|
* it due to semantic errors or business logic constraints.
|
|
23
23
|
*/
|
|
24
|
-
declare class
|
|
25
|
-
/** Creates an instance of
|
|
24
|
+
declare class UnprocessableConditionError extends CommonError {
|
|
25
|
+
/** Creates an instance of unprocessable condition error. */
|
|
26
26
|
constructor(message?: string);
|
|
27
27
|
}
|
|
28
|
-
export default
|
|
29
|
-
//# sourceMappingURL=
|
|
28
|
+
export default UnprocessableConditionError;
|
|
29
|
+
//# sourceMappingURL=UnprocessableConditionError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"UnprocessableConditionError.d.ts","sourceRoot":"","sources":["../../../src/Operation/errors/UnprocessableConditionError.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,cAAM,2BAA4B,SAAQ,WAAW;IACnD,4DAA4D;gBAChD,OAAO,GAAE,MAAkC;CAGxD;AAED,eAAe,2BAA2B,CAAC"}
|
package/dist/Operation/errors/{UnprocessibleConditionError.js → UnprocessableConditionError.js}
RENAMED
|
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const CommonError_1 = __importDefault(require("./CommonError"));
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Unprocessable Condition Error
|
|
9
9
|
*
|
|
10
|
-
* `
|
|
10
|
+
* `UnprocessableConditionError` represents a **422 Unprocessable Entity** error that occurs
|
|
11
11
|
* when an operation encounters an expected exit condition that prevents it from processing
|
|
12
12
|
* the request. This error indicates that the request is well-formed and valid, but the
|
|
13
13
|
* operation cannot proceed due to business logic constraints or state conditions.
|
|
@@ -26,11 +26,11 @@ const CommonError_1 = __importDefault(require("./CommonError"));
|
|
|
26
26
|
* The 422 status code indicates that the server understands the request but cannot process
|
|
27
27
|
* it due to semantic errors or business logic constraints.
|
|
28
28
|
*/
|
|
29
|
-
class
|
|
30
|
-
/** Creates an instance of
|
|
31
|
-
constructor(message = '
|
|
32
|
-
super('
|
|
29
|
+
class UnprocessableConditionError extends CommonError_1.default {
|
|
30
|
+
/** Creates an instance of unprocessable condition error. */
|
|
31
|
+
constructor(message = 'Unprocessable condition') {
|
|
32
|
+
super('UnprocessableConditionError', message);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
exports.default =
|
|
36
|
-
//# sourceMappingURL=
|
|
35
|
+
exports.default = UnprocessableConditionError;
|
|
36
|
+
//# sourceMappingURL=UnprocessableConditionError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"UnprocessableConditionError.js","sourceRoot":"","sources":["../../../src/Operation/errors/UnprocessableConditionError.ts"],"names":[],"mappings":";;;;;AAAA,gEAAwC;AAExC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,2BAA4B,SAAQ,qBAAW;IACnD,4DAA4D;IAC5D,YAAY,UAAkB,yBAAyB;QACrD,KAAK,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;CACF;AAED,kBAAe,2BAA2B,CAAC"}
|
|
@@ -4,6 +4,6 @@ import AccessDeniedError from './AccessDeniedError';
|
|
|
4
4
|
import DocumentExistsError from './DocumentExistsError';
|
|
5
5
|
import DocumentNotFoundError from './DocumentNotFoundError';
|
|
6
6
|
import InvalidParametersError from './InvalidParametersError';
|
|
7
|
-
import
|
|
8
|
-
export { CommonError, UnauthorizedError, AccessDeniedError, DocumentExistsError, DocumentNotFoundError, InvalidParametersError,
|
|
7
|
+
import UnprocessableConditionError from './UnprocessableConditionError';
|
|
8
|
+
export { CommonError, UnauthorizedError, AccessDeniedError, DocumentExistsError, DocumentNotFoundError, InvalidParametersError, UnprocessableConditionError, };
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.UnprocessableConditionError = exports.InvalidParametersError = exports.DocumentNotFoundError = exports.DocumentExistsError = exports.AccessDeniedError = exports.UnauthorizedError = exports.CommonError = void 0;
|
|
7
7
|
const CommonError_1 = __importDefault(require("./CommonError"));
|
|
8
8
|
exports.CommonError = CommonError_1.default;
|
|
9
9
|
const UnauthorizedError_1 = __importDefault(require("./UnauthorizedError"));
|
|
@@ -16,6 +16,6 @@ const DocumentNotFoundError_1 = __importDefault(require("./DocumentNotFoundError
|
|
|
16
16
|
exports.DocumentNotFoundError = DocumentNotFoundError_1.default;
|
|
17
17
|
const InvalidParametersError_1 = __importDefault(require("./InvalidParametersError"));
|
|
18
18
|
exports.InvalidParametersError = InvalidParametersError_1.default;
|
|
19
|
-
const
|
|
20
|
-
exports.
|
|
19
|
+
const UnprocessableConditionError_1 = __importDefault(require("./UnprocessableConditionError"));
|
|
20
|
+
exports.UnprocessableConditionError = UnprocessableConditionError_1.default;
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -10,7 +10,7 @@ const SORT_ORDER = {
|
|
|
10
10
|
DESC: 'desc',
|
|
11
11
|
};
|
|
12
12
|
const DEFAULT_LIMIT = 20;
|
|
13
|
-
const DEFAULT_LIMIT_MAX =
|
|
13
|
+
const DEFAULT_LIMIT_MAX = 100;
|
|
14
14
|
const DEFAULT_SORT_ORDER = SORT_ORDER.DESC;
|
|
15
15
|
/** Returns class for an index operation. */
|
|
16
16
|
const Index = (
|
|
@@ -38,11 +38,11 @@ ComponentClass, componentAction = 'index') => {
|
|
|
38
38
|
}
|
|
39
39
|
/** Returns default value for a limit parameter. */
|
|
40
40
|
static get defaultLimit() {
|
|
41
|
-
return DEFAULT_LIMIT;
|
|
41
|
+
return (0, lodash_1.get)(ComponentClass, 'indexDefaultLimit', DEFAULT_LIMIT);
|
|
42
42
|
}
|
|
43
43
|
/** Returns maximum number for a limit parameter. */
|
|
44
44
|
static get limitMax() {
|
|
45
|
-
return DEFAULT_LIMIT_MAX;
|
|
45
|
+
return (0, lodash_1.get)(ComponentClass, 'indexLimitMax', DEFAULT_LIMIT_MAX);
|
|
46
46
|
}
|
|
47
47
|
/** Returns default value for a sort parameter. */
|
|
48
48
|
static get defaultSort() {
|
|
@@ -87,12 +87,12 @@ ComponentClass, componentAction = 'index') => {
|
|
|
87
87
|
},
|
|
88
88
|
count: {
|
|
89
89
|
type: 'integer',
|
|
90
|
-
example:
|
|
90
|
+
example: 5,
|
|
91
91
|
description: `Number of ${documentTitle}`,
|
|
92
92
|
},
|
|
93
93
|
limit: {
|
|
94
94
|
type: 'integer',
|
|
95
|
-
example:
|
|
95
|
+
example: (0, lodash_1.get)(ComponentClass, 'indexDefaultLimit', DEFAULT_LIMIT),
|
|
96
96
|
description: `Limit number of ${documentTitle} to be returned`,
|
|
97
97
|
},
|
|
98
98
|
lastEvaluatedKey: {
|
|
@@ -104,11 +104,11 @@ ComponentClass, componentAction = 'index') => {
|
|
|
104
104
|
}
|
|
105
105
|
/** Executes components index action. */
|
|
106
106
|
async action(parameters) {
|
|
107
|
-
const { sort, limit,
|
|
107
|
+
const { sort, limit, indexName, exclusiveStartKey, ...query } = parameters;
|
|
108
108
|
const options = {
|
|
109
109
|
sort,
|
|
110
110
|
limit,
|
|
111
|
-
|
|
111
|
+
indexName,
|
|
112
112
|
exclusiveStartKey,
|
|
113
113
|
};
|
|
114
114
|
const { componentActionMethod } = this.constructor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Index.js","sourceRoot":"","sources":["../../../src/Operation/operations/Index.ts"],"names":[],"mappings":";;;;;AACA,
|
|
1
|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AAE;4BAChB,WAAW,EAAE,2CAA2C,aAAa,EAAE;yBACxE;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;QAED,wCAAwC;QACxC,KAAK,CAAC,MAAM,CAAC,UAAmC;YAC9C,MAAM,EACJ,IAAI,EACJ,KAAK,EACL,SAAS,EACT,iBAAiB,EACjB,GAAG,KAAK,EACT,GAAG,UAAU,CAAC;YAEf,MAAM,OAAO,GAAG;gBACd,IAAI;gBACJ,KAAK;gBACL,SAAS;gBACT,iBAAiB;aAClB,CAAC;YAEF,MAAM,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAC,WAA+B,CAAC;YAEvE,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAEzE,MAAM,EACJ,OAAO,EAAE,IAAI,EACb,KAAK,EACL,gBAAgB,GACjB,GAAG,MAAM,CAAC;YAEX,MAAM,QAAQ,GAAG;gBACf,IAAI;gBACJ,KAAK;gBACL,KAAK;gBACL,gBAAgB;aACL,CAAC;YAEd,OAAO,EAAE,IAAI,EAAE,QAAQ,EAA0C,CAAC;QACpE,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,KAAK,CAAC"}
|
|
@@ -32,10 +32,10 @@ ComponentClass, componentAction = 'indexAll') => {
|
|
|
32
32
|
}
|
|
33
33
|
/** Executes components list action. */
|
|
34
34
|
async action(parameters) {
|
|
35
|
-
const { sort,
|
|
35
|
+
const { sort, indexName, ...query } = parameters;
|
|
36
36
|
const options = {
|
|
37
37
|
sort,
|
|
38
|
-
|
|
38
|
+
indexName,
|
|
39
39
|
};
|
|
40
40
|
const { componentActionMethod } = this.constructor;
|
|
41
41
|
const result = await componentActionMethod(this.context, query, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.js","sourceRoot":"","sources":["../../../src/Operation/operations/List.ts"],"names":[],"mappings":";;;;;AACA,mCAAoC;AACpC,6DA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AC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAE3D,2BAA2B;IAC3B,OAAO,KAAM,SAAQ,mBAAS;QAC5B,8CAA8C;QAC9C,MAAM,KAAK,OAAO;YAChB,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAC3D,OAAO,IAAA,mBAAU,EAAC,GAAG,MAAM,IAAI,aAAa,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,sDAAsD;QACtD,MAAM,KAAK,SAAS;YAClB,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,4DAA4D;QAC5D,MAAM,KAAK,eAAe;YACxB,OAAO,eAAe,CAAC;QACzB,CAAC;QAED,uCAAuC;QACvC,KAAK,CAAC,MAAM,CAAC,UAAmC;YAC9C,MAAM,EACJ,IAAI,EACJ,SAAS,EACT,GAAG,KAAK,EACT,GAAG,UAAU,CAAC;YAEf,MAAM,OAAO,GAAG;gBACd,IAAI;gBACJ,SAAS;aACV,CAAC;YAEF,MAAM,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAC,WAA+B,CAAC;YAEvE,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAEzE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;YAE3B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAsB,CAAC;QAC/C,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,IAAI,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Component from '../../Component';
|
|
2
2
|
import { Context } from '../../Context';
|
|
3
|
-
import {
|
|
3
|
+
import { OperationErrorAttributes } from './OperationErrorAttributes';
|
|
4
4
|
import { type OriginalError } from './logOperationError';
|
|
5
5
|
/**
|
|
6
6
|
* Operation Error
|
|
@@ -20,7 +20,7 @@ import { type OriginalError } from './logOperationError';
|
|
|
20
20
|
* This class acts as the final error handler in the operation processing pipeline,
|
|
21
21
|
* transforming any thrown error into a standardized, schema-validated response format.
|
|
22
22
|
*/
|
|
23
|
-
declare class OperationError extends Component<
|
|
23
|
+
declare class OperationError extends Component<OperationErrorAttributes> {
|
|
24
24
|
/** Returns schema of the operation error. */
|
|
25
25
|
static get schema(): import("@kravc/schema").Schema;
|
|
26
26
|
/** Creates instance of an operation error. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationError.d.ts","sourceRoot":"","sources":["../../../src/Service/errors/OperationError.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"OperationError.d.ts","sourceRoot":"","sources":["../../../src/Service/errors/OperationError.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAA0B,EAAE,KAAK,aAAa,EAAwB,MAAM,qBAAqB,CAAC;AAOlG;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAM,cAAe,SAAQ,SAAS,CAAC,wBAAwB,CAAC;IAC9D,6CAA6C;IAC7C,MAAM,KAAK,MAAM,mCAEhB;IAED,8CAA8C;gBAClC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa;CAkC/E;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationError.js","sourceRoot":"","sources":["../../../src/Service/errors/OperationError.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,gEAAwC;AAExC,0CAAyC;AAEzC,4EAAkG;AAElG,MAAM,WAAW,GAAG,cAAI,CAAC,OAAO,CAA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C,OAAO,EAAE,UAAU,CAAC,CAAC;QAE3B,MAAM,cAAc,GAAG,UAAU,KAAK,mBAAmB,CAAC;QAE1D,IAAI,cAAc,EAAE,CAAC;YACnB,IAAA,2BAAiB,EAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;CACF;AAED,kBAAe,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kravc/dos",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.11",
|
|
4
4
|
"description": "Convention-based, easy-to-use library for building API-driven serverless services.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Service",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"author": "Alexander Kravets <a@kra.vc>",
|
|
33
33
|
"license": "ISC",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@kravc/schema": "^2.8.0-alpha.
|
|
35
|
+
"@kravc/schema": "^2.8.0-alpha.8",
|
|
36
36
|
"@types/jsonwebtoken": "^9.0.10",
|
|
37
37
|
"cookie": "^1.1.1",
|
|
38
38
|
"jsonwebtoken": "^9.0.3",
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
"@types/lodash": "^4.17.23",
|
|
51
51
|
"@types/pluralize": "^0.0.33",
|
|
52
52
|
"eslint": "^9.39.2",
|
|
53
|
-
"eslint-plugin-jsdoc": "^62.
|
|
53
|
+
"eslint-plugin-jsdoc": "^62.6.0",
|
|
54
54
|
"globals": "^17.1.0",
|
|
55
55
|
"jest": "^30.2.0",
|
|
56
56
|
"openapi-types": "^12.1.3",
|
|
57
|
-
"rimraf": "^6.1.
|
|
57
|
+
"rimraf": "^6.1.3",
|
|
58
58
|
"ts-jest": "^29.4.6",
|
|
59
59
|
"ts-node": "^10.9.2",
|
|
60
60
|
"typescript": "^5.9.3",
|
|
61
|
-
"typescript-eslint": "^8.
|
|
61
|
+
"typescript-eslint": "^8.56.0"
|
|
62
62
|
}
|
|
63
63
|
}
|
package/src/Document/Document.ts
CHANGED
|
@@ -5,23 +5,26 @@ import Context, { type QueryMap, type MutationMap } from '../Context';
|
|
|
5
5
|
import { get, set, omit, pick, cloneDeep, capitalize } from 'lodash';
|
|
6
6
|
|
|
7
7
|
const DEFAULT_INDEX_SORT = 'desc';
|
|
8
|
-
const DEFAULT_INDEX_LIMIT =
|
|
8
|
+
const DEFAULT_INDEX_LIMIT = 20;
|
|
9
|
+
const DEFAULT_INDEX_LIMIT_MAX = 100;
|
|
10
|
+
|
|
9
11
|
const DEFAULT_PARTITION_KEY = 'partition';
|
|
10
12
|
|
|
11
13
|
export type IndexOptions = {
|
|
12
14
|
sort?: 'asc' | 'desc';
|
|
13
15
|
limit?: number;
|
|
14
|
-
|
|
16
|
+
indexName?: string;
|
|
15
17
|
exclusiveStartKey?: string;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export type IndexAllOptions = {
|
|
19
21
|
sort?: 'asc' | 'desc';
|
|
20
|
-
|
|
22
|
+
indexName?: string;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export type DefaultAttributes = {
|
|
24
26
|
id: string;
|
|
27
|
+
partition: string;
|
|
25
28
|
createdAt: string;
|
|
26
29
|
createdBy: string;
|
|
27
30
|
createdByUserName?: string;
|
|
@@ -33,7 +36,19 @@ export type DefaultAttributes = {
|
|
|
33
36
|
type Constructor<T, D extends Document<T> = Document<T>> = {
|
|
34
37
|
new(context: Context, attributes: T): D;
|
|
35
38
|
|
|
39
|
+
index<T, D extends Document<T> = Document<T>>(
|
|
40
|
+
context: Context,
|
|
41
|
+
query?: QueryMap,
|
|
42
|
+
options?: IndexOptions,
|
|
43
|
+
): Promise<{
|
|
44
|
+
limit: number;
|
|
45
|
+
count: number;
|
|
46
|
+
objects: D[];
|
|
47
|
+
lastEvaluatedKey?: string;
|
|
48
|
+
}>;
|
|
49
|
+
|
|
36
50
|
_index(query: QueryMap, options: IndexOptions): Promise<{
|
|
51
|
+
limit: number;
|
|
37
52
|
count: number;
|
|
38
53
|
items: T[];
|
|
39
54
|
lastEvaluatedKey?: string;
|
|
@@ -46,11 +61,11 @@ type Constructor<T, D extends Document<T> = Document<T>> = {
|
|
|
46
61
|
|
|
47
62
|
_read(query: QueryMap, options: unknown): Promise<T>;
|
|
48
63
|
|
|
49
|
-
_create(attributes: T): Promise<void>;
|
|
64
|
+
_create(attributes: T, context: Context): Promise<void>;
|
|
50
65
|
|
|
51
|
-
_update<T>(query: QueryMap, mutation: MutationMap): Promise<T>;
|
|
66
|
+
_update<T>(query: QueryMap, mutation: MutationMap, context: Context, previousAttributes: T): Promise<T>;
|
|
52
67
|
|
|
53
|
-
_delete(query: QueryMap): Promise<void>;
|
|
68
|
+
_delete(query: QueryMap, context: Context, previousAttributes: T): Promise<void>;
|
|
54
69
|
};
|
|
55
70
|
|
|
56
71
|
/** Abstract document class. */
|
|
@@ -84,6 +99,11 @@ class Document<Attributes> extends Component<Attributes> {
|
|
|
84
99
|
return DEFAULT_INDEX_LIMIT;
|
|
85
100
|
}
|
|
86
101
|
|
|
102
|
+
/** Defines limit maximum value for index action. */
|
|
103
|
+
static get indexLimitMax(): number {
|
|
104
|
+
return DEFAULT_INDEX_LIMIT_MAX;
|
|
105
|
+
}
|
|
106
|
+
|
|
87
107
|
/** Generates ID for new document unless it's defined in parameters. */
|
|
88
108
|
static createId(attributes: Record<string, unknown>): string {
|
|
89
109
|
const id = get(attributes, this.idKey) as string;
|
|
@@ -196,6 +216,15 @@ class Document<Attributes> extends Component<Attributes> {
|
|
|
196
216
|
mutation.updatedByUserName = context.identityName;
|
|
197
217
|
}
|
|
198
218
|
|
|
219
|
+
/** Extends mutation with deleted stamps. */
|
|
220
|
+
static _extendWithDeletedStamps(context: Context, mutation: MutationMap) {
|
|
221
|
+
const timestamp = new Date().toJSON();
|
|
222
|
+
|
|
223
|
+
mutation.deletedAt = timestamp;
|
|
224
|
+
mutation.deletedBy = context.identityId;
|
|
225
|
+
mutation.deletedByUserName = context.identityName;
|
|
226
|
+
}
|
|
227
|
+
|
|
199
228
|
/** Returns documents in batches. */
|
|
200
229
|
static async index<T, D extends Document<T> = Document<T>>(
|
|
201
230
|
this: Constructor<T, D>,
|
|
@@ -203,6 +232,7 @@ class Document<Attributes> extends Component<Attributes> {
|
|
|
203
232
|
query: QueryMap = {},
|
|
204
233
|
options: IndexOptions = {}
|
|
205
234
|
): Promise<{
|
|
235
|
+
limit: number;
|
|
206
236
|
count: number;
|
|
207
237
|
objects: D[];
|
|
208
238
|
lastEvaluatedKey?: string;
|
|
@@ -218,10 +248,15 @@ class Document<Attributes> extends Component<Attributes> {
|
|
|
218
248
|
options.sort = _this.indexDefaultSort;
|
|
219
249
|
}
|
|
220
250
|
|
|
221
|
-
const {
|
|
251
|
+
const { count, limit, items, lastEvaluatedKey } = await this._index(query, options);
|
|
222
252
|
const objects = items.map(attributes => new this(context, attributes));
|
|
223
253
|
|
|
224
|
-
return {
|
|
254
|
+
return {
|
|
255
|
+
limit,
|
|
256
|
+
count,
|
|
257
|
+
objects,
|
|
258
|
+
lastEvaluatedKey,
|
|
259
|
+
};
|
|
225
260
|
}
|
|
226
261
|
|
|
227
262
|
/** Returns all documents. */
|
|
@@ -299,7 +334,7 @@ class Document<Attributes> extends Component<Attributes> {
|
|
|
299
334
|
|
|
300
335
|
await _this.beforeCreate(context, query, attributes);
|
|
301
336
|
|
|
302
|
-
await this._create(attributes as T);
|
|
337
|
+
await this._create(attributes as T, context);
|
|
303
338
|
const object = new this(context, attributes as T);
|
|
304
339
|
|
|
305
340
|
await _this.afterCreate(context, query, mutation, object);
|
|
@@ -349,7 +384,7 @@ class Document<Attributes> extends Component<Attributes> {
|
|
|
349
384
|
previousAttributes = await this._read(query, {});
|
|
350
385
|
}
|
|
351
386
|
|
|
352
|
-
const updatedAttributes = await this._update(query, mutation) as T;
|
|
387
|
+
const updatedAttributes = await this._update(query, mutation, context, previousAttributes) as T;
|
|
353
388
|
const object = new this(context, updatedAttributes);
|
|
354
389
|
|
|
355
390
|
object._previousAttributes = previousAttributes;
|
|
@@ -383,14 +418,14 @@ class Document<Attributes> extends Component<Attributes> {
|
|
|
383
418
|
|
|
384
419
|
await _this.beforeDelete(context, query);
|
|
385
420
|
|
|
386
|
-
const
|
|
387
|
-
const object = new this(context, attributes);
|
|
421
|
+
const previousAttributes = await this._read(query, {});
|
|
388
422
|
|
|
389
|
-
await this._delete(query);
|
|
423
|
+
await this._delete(query, context, previousAttributes);
|
|
390
424
|
|
|
391
|
-
|
|
425
|
+
const deletedObject = new this(context, previousAttributes);
|
|
426
|
+
await _this.afterDelete(context, query, deletedObject);
|
|
392
427
|
|
|
393
|
-
return
|
|
428
|
+
return deletedObject;
|
|
394
429
|
}
|
|
395
430
|
|
|
396
431
|
/** Before delete hook. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { got } from '@kravc/schema';
|
|
2
|
-
import
|
|
2
|
+
import Context, { type QueryMap, type MutationMap } from '../Context';
|
|
3
3
|
import { get, set, last, unset, cloneDeep, sortBy } from 'lodash';
|
|
4
4
|
import { DocumentExistsError, DocumentNotFoundError } from '../Operation';
|
|
5
5
|
import Document, { type IndexOptions, type IndexAllOptions } from './Document';
|
|
@@ -11,6 +11,9 @@ type Item = {
|
|
|
11
11
|
|
|
12
12
|
const _MEMORY_STORE = {} as Record<string, Record<string, Item>>;
|
|
13
13
|
|
|
14
|
+
const QUERY_ERROR_TEMPLATE = 'Query parameter "$PATH" is required';
|
|
15
|
+
const ATTRIBUTE_ERROR_TEMPLATE = 'Attribute "$PATH" is required';
|
|
16
|
+
|
|
14
17
|
/** Example implementation of a document class stored in memory. */
|
|
15
18
|
class MemoryDocument<T> extends Document<T> {
|
|
16
19
|
/** Returns collection where documents are stored. */
|
|
@@ -35,6 +38,7 @@ class MemoryDocument<T> extends Document<T> {
|
|
|
35
38
|
|
|
36
39
|
/** Implements interface to get documents in batches. */
|
|
37
40
|
static async _index<T>(query: QueryMap, options: IndexOptions): Promise<{
|
|
41
|
+
limit: number;
|
|
38
42
|
count: number;
|
|
39
43
|
items: T[];
|
|
40
44
|
lastEvaluatedKey?: string;
|
|
@@ -81,6 +85,7 @@ class MemoryDocument<T> extends Document<T> {
|
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
return {
|
|
88
|
+
limit: limit || count,
|
|
84
89
|
items,
|
|
85
90
|
count,
|
|
86
91
|
lastEvaluatedKey,
|
|
@@ -102,7 +107,7 @@ class MemoryDocument<T> extends Document<T> {
|
|
|
102
107
|
|
|
103
108
|
/** Implements interface to get a document. */
|
|
104
109
|
static async _read<T>(query: QueryMap): Promise<T> {
|
|
105
|
-
const idValue = got(query, this.idKey,
|
|
110
|
+
const idValue = got(query, this.idKey, QUERY_ERROR_TEMPLATE) as string;
|
|
106
111
|
|
|
107
112
|
const item = get(this.collection, idValue) as T;
|
|
108
113
|
|
|
@@ -114,8 +119,9 @@ class MemoryDocument<T> extends Document<T> {
|
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
/** Implements interface to save a document. */
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
123
|
+
static async _create<T>(attributes: T, _context: Context): Promise<void> {
|
|
124
|
+
const idValue = got(attributes, this.idKey, ATTRIBUTE_ERROR_TEMPLATE) as string;
|
|
119
125
|
|
|
120
126
|
const item = get(this.collection, idValue) as T;
|
|
121
127
|
|
|
@@ -127,8 +133,9 @@ class MemoryDocument<T> extends Document<T> {
|
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
/** Implements interface to update a document. */
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
137
|
+
static async _update<T>(query: QueryMap, mutation: MutationMap, _context: Context, _previousAttributes: T): Promise<T> {
|
|
138
|
+
const idValue = got(query, this.idKey, QUERY_ERROR_TEMPLATE) as string;
|
|
132
139
|
|
|
133
140
|
const componentTitle = this.getTitle();
|
|
134
141
|
const item = got(this.collection, idValue, `${componentTitle} with ID "$PATH" is not found`) as T;
|
|
@@ -139,8 +146,9 @@ class MemoryDocument<T> extends Document<T> {
|
|
|
139
146
|
}
|
|
140
147
|
|
|
141
148
|
/** Implements interface to delete a document. */
|
|
142
|
-
|
|
143
|
-
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
150
|
+
static async _delete<T>(query: QueryMap, _context: Context, _previousAttributes: T): Promise<void> {
|
|
151
|
+
const idValue = got(query, this.idKey, QUERY_ERROR_TEMPLATE) as string;
|
|
144
152
|
|
|
145
153
|
const componentTitle = this.getTitle();
|
|
146
154
|
got(this.collection, idValue, `${componentTitle} with ID "$PATH" is not found`) as T;
|
|
@@ -53,6 +53,22 @@ describe('MemoryDocument', () => {
|
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
+
describe('MemoryDocument._extendWithDeletedStamps', () => {
|
|
57
|
+
it('returns document body schema', () => {
|
|
58
|
+
const mutation = {
|
|
59
|
+
deletedAt: undefined,
|
|
60
|
+
deletedBy: undefined,
|
|
61
|
+
deletedByUserName: undefined,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
Profile._extendWithDeletedStamps(context, mutation);
|
|
65
|
+
|
|
66
|
+
expect(mutation.deletedAt).toBeDefined();
|
|
67
|
+
expect(mutation.deletedBy).toEqual('SYSTEM');
|
|
68
|
+
expect(mutation.deletedByUserName).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
56
72
|
describe('MemoryDocument.create(context, query, mutation)', () => {
|
|
57
73
|
it('creates a document from mutation', async () => {
|
|
58
74
|
const profile = await Profile.create(context, {}, attributes);
|
|
@@ -184,11 +184,11 @@ class Operation {
|
|
|
184
184
|
errors.InvalidParametersError = {
|
|
185
185
|
statusCode: 400,
|
|
186
186
|
description: 'Invalid operation parameters, input syntax is correct,' +
|
|
187
|
-
' but input values are not
|
|
187
|
+
' but input values are not processable'
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
errors.
|
|
191
|
+
errors.UnprocessableConditionError = {
|
|
192
192
|
statusCode: 422,
|
|
193
193
|
description: 'Operation failed to process the request cause of expected' +
|
|
194
194
|
' exit condition'
|
package/src/Operation/errors/{UnprocessibleConditionError.ts → UnprocessableConditionError.ts}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import CommonError from './CommonError';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Unprocessable Condition Error
|
|
5
5
|
*
|
|
6
|
-
* `
|
|
6
|
+
* `UnprocessableConditionError` represents a **422 Unprocessable Entity** error that occurs
|
|
7
7
|
* when an operation encounters an expected exit condition that prevents it from processing
|
|
8
8
|
* the request. This error indicates that the request is well-formed and valid, but the
|
|
9
9
|
* operation cannot proceed due to business logic constraints or state conditions.
|
|
@@ -22,11 +22,11 @@ import CommonError from './CommonError';
|
|
|
22
22
|
* The 422 status code indicates that the server understands the request but cannot process
|
|
23
23
|
* it due to semantic errors or business logic constraints.
|
|
24
24
|
*/
|
|
25
|
-
class
|
|
26
|
-
/** Creates an instance of
|
|
27
|
-
constructor(message: string = '
|
|
28
|
-
super('
|
|
25
|
+
class UnprocessableConditionError extends CommonError {
|
|
26
|
+
/** Creates an instance of unprocessable condition error. */
|
|
27
|
+
constructor(message: string = 'Unprocessable condition') {
|
|
28
|
+
super('UnprocessableConditionError', message);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export default
|
|
32
|
+
export default UnprocessableConditionError;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import UnprocessableConditionError from '../UnprocessableConditionError';
|
|
2
|
+
|
|
3
|
+
describe('UnprocessableConditionError', () => {
|
|
4
|
+
describe('UnprocessableConditionError.constructor(message)', () => {
|
|
5
|
+
it('creates an instance with default message when no message is provided', () => {
|
|
6
|
+
const err = new UnprocessableConditionError();
|
|
7
|
+
|
|
8
|
+
expect(err.code).toBe('UnprocessableConditionError');
|
|
9
|
+
expect(err.message).toBe('Unprocessable condition');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('creates an instance with custom message when provided', () => {
|
|
13
|
+
const customMessage = 'Order is already canceled';
|
|
14
|
+
const err = new UnprocessableConditionError(customMessage);
|
|
15
|
+
|
|
16
|
+
expect(err.code).toBe('UnprocessableConditionError');
|
|
17
|
+
expect(err.message).toBe(customMessage);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -4,7 +4,7 @@ import AccessDeniedError from './AccessDeniedError';
|
|
|
4
4
|
import DocumentExistsError from './DocumentExistsError';
|
|
5
5
|
import DocumentNotFoundError from './DocumentNotFoundError';
|
|
6
6
|
import InvalidParametersError from './InvalidParametersError';
|
|
7
|
-
import
|
|
7
|
+
import UnprocessableConditionError from './UnprocessableConditionError';
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
10
|
CommonError,
|
|
@@ -13,5 +13,5 @@ export {
|
|
|
13
13
|
DocumentExistsError,
|
|
14
14
|
DocumentNotFoundError,
|
|
15
15
|
InvalidParametersError,
|
|
16
|
-
|
|
16
|
+
UnprocessableConditionError,
|
|
17
17
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Component from '../../Component';
|
|
2
|
-
import { capitalize } from 'lodash';
|
|
2
|
+
import { get, capitalize } from 'lodash';
|
|
3
3
|
import Operation, { type Result } from '../Operation';
|
|
4
4
|
import { type PropertiesSchemaSource } from '@kravc/schema';
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ const SORT_ORDER = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const DEFAULT_LIMIT = 20;
|
|
12
|
-
const DEFAULT_LIMIT_MAX =
|
|
12
|
+
const DEFAULT_LIMIT_MAX = 100;
|
|
13
13
|
const DEFAULT_SORT_ORDER = SORT_ORDER.DESC;
|
|
14
14
|
|
|
15
15
|
export type PageInfo = {
|
|
@@ -53,12 +53,12 @@ const Index = (
|
|
|
53
53
|
|
|
54
54
|
/** Returns default value for a limit parameter. */
|
|
55
55
|
static get defaultLimit() {
|
|
56
|
-
return DEFAULT_LIMIT;
|
|
56
|
+
return get(ComponentClass, 'indexDefaultLimit', DEFAULT_LIMIT);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/** Returns maximum number for a limit parameter. */
|
|
60
60
|
static get limitMax() {
|
|
61
|
-
return DEFAULT_LIMIT_MAX;
|
|
61
|
+
return get(ComponentClass, 'indexLimitMax', DEFAULT_LIMIT_MAX);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/** Returns default value for a sort parameter. */
|
|
@@ -106,12 +106,12 @@ const Index = (
|
|
|
106
106
|
},
|
|
107
107
|
count: {
|
|
108
108
|
type: 'integer',
|
|
109
|
-
example:
|
|
109
|
+
example: 5,
|
|
110
110
|
description: `Number of ${documentTitle}`,
|
|
111
111
|
},
|
|
112
112
|
limit: {
|
|
113
113
|
type: 'integer',
|
|
114
|
-
example:
|
|
114
|
+
example: get(ComponentClass, 'indexDefaultLimit', DEFAULT_LIMIT),
|
|
115
115
|
description: `Limit number of ${documentTitle} to be returned`,
|
|
116
116
|
},
|
|
117
117
|
lastEvaluatedKey: {
|
|
@@ -127,7 +127,7 @@ const Index = (
|
|
|
127
127
|
const {
|
|
128
128
|
sort,
|
|
129
129
|
limit,
|
|
130
|
-
|
|
130
|
+
indexName,
|
|
131
131
|
exclusiveStartKey,
|
|
132
132
|
...query
|
|
133
133
|
} = parameters;
|
|
@@ -135,7 +135,7 @@ const Index = (
|
|
|
135
135
|
const options = {
|
|
136
136
|
sort,
|
|
137
137
|
limit,
|
|
138
|
-
|
|
138
|
+
indexName,
|
|
139
139
|
exclusiveStartKey,
|
|
140
140
|
};
|
|
141
141
|
|
|
@@ -39,13 +39,13 @@ const List = (
|
|
|
39
39
|
async action(parameters: Record<string, unknown>) {
|
|
40
40
|
const {
|
|
41
41
|
sort,
|
|
42
|
-
|
|
42
|
+
indexName,
|
|
43
43
|
...query
|
|
44
44
|
} = parameters;
|
|
45
45
|
|
|
46
46
|
const options = {
|
|
47
47
|
sort,
|
|
48
|
-
|
|
48
|
+
indexName,
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
const { componentActionMethod } = this.constructor as typeof Operation;
|
|
@@ -100,7 +100,7 @@ describe('Create(Document, actionMethod)', () => {
|
|
|
100
100
|
const errorCodes = Object.keys(CreateProfile.errors);
|
|
101
101
|
expect(errorCodes).toContain('InvalidInputError');
|
|
102
102
|
expect(errorCodes).toContain('InvalidOutputError');
|
|
103
|
-
expect(errorCodes).toContain('
|
|
103
|
+
expect(errorCodes).toContain('UnprocessableConditionError');
|
|
104
104
|
expect(errorCodes).toContain('DocumentExistsError');
|
|
105
105
|
});
|
|
106
106
|
});
|
|
@@ -99,7 +99,7 @@ describe('Delete(Document, actionMethod)', () => {
|
|
|
99
99
|
it('includes related errors', () => {
|
|
100
100
|
const errorCodes = Object.keys(DeleteProfile.errors);
|
|
101
101
|
expect(errorCodes).toContain('InvalidInputError');
|
|
102
|
-
expect(errorCodes).toContain('
|
|
102
|
+
expect(errorCodes).toContain('UnprocessableConditionError');
|
|
103
103
|
expect(errorCodes).toContain('DocumentNotFoundError');
|
|
104
104
|
});
|
|
105
105
|
});
|
|
@@ -95,7 +95,7 @@ describe('Index(Document, actionMethod)', () => {
|
|
|
95
95
|
const errorCodes = Object.keys(IndexProfiles.errors);
|
|
96
96
|
expect(errorCodes).toContain('InvalidInputError');
|
|
97
97
|
expect(errorCodes).toContain('InvalidOutputError');
|
|
98
|
-
expect(errorCodes).toContain('
|
|
98
|
+
expect(errorCodes).toContain('UnprocessableConditionError');
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
|
|
@@ -107,7 +107,7 @@ describe('Index(Document, actionMethod)', () => {
|
|
|
107
107
|
example: 20,
|
|
108
108
|
default: 20,
|
|
109
109
|
minimum: 1,
|
|
110
|
-
maximum:
|
|
110
|
+
maximum: 100,
|
|
111
111
|
description: 'Limit number of profiles to be returned',
|
|
112
112
|
},
|
|
113
113
|
sort: {
|
|
@@ -146,12 +146,12 @@ describe('Index(Document, actionMethod)', () => {
|
|
|
146
146
|
},
|
|
147
147
|
count: {
|
|
148
148
|
type: 'integer',
|
|
149
|
-
example:
|
|
149
|
+
example: 5,
|
|
150
150
|
description: 'Number of profiles',
|
|
151
151
|
},
|
|
152
152
|
limit: {
|
|
153
153
|
type: 'integer',
|
|
154
|
-
example:
|
|
154
|
+
example: 20,
|
|
155
155
|
description: 'Limit number of profiles to be returned',
|
|
156
156
|
},
|
|
157
157
|
lastEvaluatedKey: {
|
|
@@ -93,7 +93,7 @@ describe('List(Document, actionMethod)', () => {
|
|
|
93
93
|
it('includes related errors', () => {
|
|
94
94
|
const errorCodes = Object.keys(ListProfiles.errors);
|
|
95
95
|
expect(errorCodes).toContain('InvalidOutputError');
|
|
96
|
-
expect(errorCodes).toContain('
|
|
96
|
+
expect(errorCodes).toContain('UnprocessableConditionError');
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
99
|
|
|
@@ -94,7 +94,7 @@ describe('Read(Document, actionMethod)', () => {
|
|
|
94
94
|
const errorCodes = Object.keys(ReadProfile.errors);
|
|
95
95
|
expect(errorCodes).toContain('InvalidInputError');
|
|
96
96
|
expect(errorCodes).toContain('InvalidOutputError');
|
|
97
|
-
expect(errorCodes).toContain('
|
|
97
|
+
expect(errorCodes).toContain('UnprocessableConditionError');
|
|
98
98
|
expect(errorCodes).toContain('DocumentNotFoundError');
|
|
99
99
|
});
|
|
100
100
|
});
|
|
@@ -100,7 +100,7 @@ describe('Update(Document, actionMethod)', () => {
|
|
|
100
100
|
const errorCodes = Object.keys(UpdateProfile.errors);
|
|
101
101
|
expect(errorCodes).toContain('InvalidInputError');
|
|
102
102
|
expect(errorCodes).toContain('InvalidOutputError');
|
|
103
|
-
expect(errorCodes).toContain('
|
|
103
|
+
expect(errorCodes).toContain('UnprocessableConditionError');
|
|
104
104
|
expect(errorCodes).toContain('DocumentNotFoundError');
|
|
105
105
|
});
|
|
106
106
|
});
|
|
@@ -178,12 +178,7 @@ describe('Service', () => {
|
|
|
178
178
|
|
|
179
179
|
const body = JSON.parse(json!);
|
|
180
180
|
|
|
181
|
-
expect(body).toEqual(
|
|
182
|
-
info: {
|
|
183
|
-
title: '@kravc/dos',
|
|
184
|
-
version: '2.0.0-alpha.1',
|
|
185
|
-
},
|
|
186
|
-
});
|
|
181
|
+
expect(body.info.title).toEqual('@kravc/dos');
|
|
187
182
|
});
|
|
188
183
|
|
|
189
184
|
it('returns composer file for /Enums.yaml path', async () => {
|
|
@@ -2,7 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import Component from '../../Component';
|
|
3
3
|
import { Context } from '../../Context';
|
|
4
4
|
import { loadSync } from '@kravc/schema';
|
|
5
|
-
import {
|
|
5
|
+
import { OperationErrorAttributes } from './OperationErrorAttributes';
|
|
6
6
|
import logOperationError, { type OriginalError, type ErrorAttributes } from './logOperationError';
|
|
7
7
|
|
|
8
8
|
const SCHEMA_PATH = path.resolve(__dirname) + '/OperationError.yaml';
|
|
@@ -28,7 +28,7 @@ const INTERNAL_ERROR_CODE = 500;
|
|
|
28
28
|
* This class acts as the final error handler in the operation processing pipeline,
|
|
29
29
|
* transforming any thrown error into a standardized, schema-validated response format.
|
|
30
30
|
*/
|
|
31
|
-
class OperationError extends Component<
|
|
31
|
+
class OperationError extends Component<OperationErrorAttributes> {
|
|
32
32
|
/** Returns schema of the operation error. */
|
|
33
33
|
static get schema() {
|
|
34
34
|
return operationErrorSchema;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import UnprocessibleConditionError from '../UnprocessibleConditionError';
|
|
2
|
-
|
|
3
|
-
describe('UnprocessibleConditionError', () => {
|
|
4
|
-
describe('UnprocessibleConditionError.constructor(message)', () => {
|
|
5
|
-
it('creates an instance with default message when no message is provided', () => {
|
|
6
|
-
const err = new UnprocessibleConditionError();
|
|
7
|
-
|
|
8
|
-
expect(err.code).toBe('UnprocessibleConditionError');
|
|
9
|
-
expect(err.message).toBe('Unprocessible condition');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('creates an instance with custom message when provided', () => {
|
|
13
|
-
const customMessage = 'Order is already cancelled';
|
|
14
|
-
const err = new UnprocessibleConditionError(customMessage);
|
|
15
|
-
|
|
16
|
-
expect(err.code).toBe('UnprocessibleConditionError');
|
|
17
|
-
expect(err.message).toBe(customMessage);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
});
|