@opra/core 0.1.1 → 0.3.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/cjs/enums/http-headers.enum.js +3 -2
- package/cjs/implementation/adapter-utils/entity-resource-execute.util.js +36 -34
- package/cjs/implementation/adapter-utils/resource-prepare.util.js +1 -1
- package/cjs/implementation/adapter.js +14 -19
- package/cjs/implementation/express-adapter.js +3 -0
- package/cjs/implementation/headers-map.js +18 -0
- package/cjs/implementation/http-adapter.js +65 -79
- package/cjs/implementation/query-context.js +12 -19
- package/cjs/index.js +1 -3
- package/cjs/services/json-collection-service.js +505 -0
- package/cjs/utils/path-to-tree.js +7 -5
- package/esm/enums/http-headers.enum.d.ts +3 -2
- package/esm/enums/http-headers.enum.js +3 -2
- package/esm/implementation/adapter-utils/entity-resource-execute.util.d.ts +2 -2
- package/esm/implementation/adapter-utils/entity-resource-execute.util.js +35 -33
- package/esm/implementation/adapter-utils/resource-execute.util.d.ts +2 -2
- package/esm/implementation/adapter-utils/resource-prepare.util.d.ts +2 -2
- package/esm/implementation/adapter-utils/resource-prepare.util.js +1 -1
- package/esm/implementation/adapter.d.ts +5 -5
- package/esm/implementation/adapter.js +12 -17
- package/esm/implementation/express-adapter.d.ts +2 -2
- package/esm/implementation/express-adapter.js +2 -0
- package/esm/implementation/headers-map.d.ts +5 -0
- package/esm/implementation/headers-map.js +14 -0
- package/esm/implementation/http-adapter.d.ts +6 -6
- package/esm/implementation/http-adapter.js +61 -75
- package/esm/implementation/query-context.d.ts +10 -16
- package/esm/implementation/query-context.js +11 -17
- package/esm/index.d.ts +1 -3
- package/esm/index.js +1 -3
- package/esm/interfaces/entity-service.interface.d.ts +8 -6
- package/esm/services/json-collection-service.d.ts +85 -0
- package/esm/services/json-collection-service.js +500 -0
- package/esm/types.d.ts +0 -3
- package/esm/utils/path-to-tree.d.ts +1 -1
- package/esm/utils/path-to-tree.js +7 -5
- package/i18n/en/error.json +5 -5
- package/package.json +10 -7
- package/cjs/exception/api-exception.js +0 -68
- package/cjs/exception/http-errors/bad-request.error.js +0 -26
- package/cjs/exception/http-errors/failed-dependency.error.js +0 -25
- package/cjs/exception/http-errors/forbidden.error.js +0 -27
- package/cjs/exception/http-errors/internal-server.error.js +0 -27
- package/cjs/exception/http-errors/method-not-allowed.error.js +0 -26
- package/cjs/exception/http-errors/not-acceptable.error.js +0 -26
- package/cjs/exception/http-errors/not-found.error.js +0 -29
- package/cjs/exception/http-errors/unauthorized.error.js +0 -26
- package/cjs/exception/http-errors/unprocessable-entity.error.js +0 -25
- package/cjs/exception/index.js +0 -15
- package/cjs/exception/resource-errors/resource-conflict.error.js +0 -19
- package/cjs/exception/resource-errors/resource-not-found.error.js +0 -19
- package/cjs/exception/wrap-error.js +0 -17
- package/cjs/interfaces/query.interface.js +0 -207
- package/cjs/services/json-data-service.js +0 -252
- package/esm/exception/api-exception.d.ts +0 -40
- package/esm/exception/api-exception.js +0 -64
- package/esm/exception/http-errors/bad-request.error.d.ts +0 -10
- package/esm/exception/http-errors/bad-request.error.js +0 -22
- package/esm/exception/http-errors/failed-dependency.error.d.ts +0 -9
- package/esm/exception/http-errors/failed-dependency.error.js +0 -21
- package/esm/exception/http-errors/forbidden.error.d.ts +0 -11
- package/esm/exception/http-errors/forbidden.error.js +0 -23
- package/esm/exception/http-errors/internal-server.error.d.ts +0 -9
- package/esm/exception/http-errors/internal-server.error.js +0 -22
- package/esm/exception/http-errors/method-not-allowed.error.d.ts +0 -10
- package/esm/exception/http-errors/method-not-allowed.error.js +0 -22
- package/esm/exception/http-errors/not-acceptable.error.d.ts +0 -10
- package/esm/exception/http-errors/not-acceptable.error.js +0 -22
- package/esm/exception/http-errors/not-found.error.d.ts +0 -13
- package/esm/exception/http-errors/not-found.error.js +0 -25
- package/esm/exception/http-errors/unauthorized.error.d.ts +0 -10
- package/esm/exception/http-errors/unauthorized.error.js +0 -22
- package/esm/exception/http-errors/unprocessable-entity.error.d.ts +0 -9
- package/esm/exception/http-errors/unprocessable-entity.error.js +0 -21
- package/esm/exception/index.d.ts +0 -12
- package/esm/exception/index.js +0 -12
- package/esm/exception/resource-errors/resource-conflict.error.d.ts +0 -4
- package/esm/exception/resource-errors/resource-conflict.error.js +0 -15
- package/esm/exception/resource-errors/resource-not-found.error.d.ts +0 -4
- package/esm/exception/resource-errors/resource-not-found.error.js +0 -15
- package/esm/exception/wrap-error.d.ts +0 -2
- package/esm/exception/wrap-error.js +0 -13
- package/esm/interfaces/query.interface.d.ts +0 -115
- package/esm/interfaces/query.interface.js +0 -203
- package/esm/services/json-data-service.d.ts +0 -68
- package/esm/services/json-data-service.js +0 -247
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JsonDataService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
-
const rule_judgment_1 = tslib_1.__importDefault(require("rule-judgment"));
|
|
7
|
-
const url_1 = require("@opra/url");
|
|
8
|
-
const index_js_1 = require("../exception/index.js");
|
|
9
|
-
// Fix invalid importing (with ESM) of rule-judgment package
|
|
10
|
-
const createFilterFn = typeof rule_judgment_1.default === 'function'
|
|
11
|
-
? rule_judgment_1.default
|
|
12
|
-
: rule_judgment_1.default.default;
|
|
13
|
-
class JsonDataService {
|
|
14
|
-
resourceName;
|
|
15
|
-
data;
|
|
16
|
-
primaryKey;
|
|
17
|
-
constructor(args) {
|
|
18
|
-
this.resourceName = args.resourceName;
|
|
19
|
-
this.data = args.data;
|
|
20
|
-
this.primaryKey = args.primaryKey;
|
|
21
|
-
}
|
|
22
|
-
processRequest(ctx) {
|
|
23
|
-
const prepared = JsonDataService.prepare(ctx.query);
|
|
24
|
-
const fn = this[prepared.method];
|
|
25
|
-
if (!fn)
|
|
26
|
-
throw new TypeError(`Unimplemented method (${prepared.method})`);
|
|
27
|
-
return fn.apply(this, prepared.args);
|
|
28
|
-
}
|
|
29
|
-
get(keyValue, options) {
|
|
30
|
-
const primaryKey = this.primaryKey;
|
|
31
|
-
let v = this.data.find(x => '' + x[primaryKey] === '' + keyValue);
|
|
32
|
-
v = JsonDataService.filterFields(v, options?.pick, options?.omit, options?.include);
|
|
33
|
-
return v;
|
|
34
|
-
}
|
|
35
|
-
count(options) {
|
|
36
|
-
return this.search(options).length;
|
|
37
|
-
}
|
|
38
|
-
search(options) {
|
|
39
|
-
let out;
|
|
40
|
-
if (options?.filter) {
|
|
41
|
-
const filter = JsonDataService.convertFilter(options.filter);
|
|
42
|
-
const filterFn = createFilterFn(filter);
|
|
43
|
-
out = this.data.filter(filterFn);
|
|
44
|
-
}
|
|
45
|
-
else
|
|
46
|
-
out = this.data;
|
|
47
|
-
return out.map(v => JsonDataService.filterFields(v, options?.pick, options?.omit, options?.include));
|
|
48
|
-
}
|
|
49
|
-
create(data, options) {
|
|
50
|
-
if (this.get(data[this.primaryKey]))
|
|
51
|
-
throw new index_js_1.ResourceConflictError(this.resourceName, this.primaryKey);
|
|
52
|
-
this.data.push(data);
|
|
53
|
-
return JsonDataService.filterFields(data, options?.pick, options?.omit, options?.include);
|
|
54
|
-
}
|
|
55
|
-
update(keyValue, data, options) {
|
|
56
|
-
const primaryKey = this.primaryKey;
|
|
57
|
-
const i = this.data.findIndex(x => '' + x[primaryKey] === '' + keyValue);
|
|
58
|
-
if (i >= 0) {
|
|
59
|
-
data = Object.assign(this.data[i], data);
|
|
60
|
-
return JsonDataService.filterFields(data, options?.pick, options?.omit, options?.include);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
updateMany(data, options) {
|
|
64
|
-
const items = this.search({ filter: options?.filter });
|
|
65
|
-
for (let i = 0; i < items.length; i++) {
|
|
66
|
-
Object.assign(items[i], data);
|
|
67
|
-
}
|
|
68
|
-
return items.length;
|
|
69
|
-
}
|
|
70
|
-
delete(keyValue) {
|
|
71
|
-
const primaryKey = this.primaryKey;
|
|
72
|
-
const i = this.data.findIndex(x => '' + x[primaryKey] === '' + keyValue);
|
|
73
|
-
if (i >= 0) {
|
|
74
|
-
this.data = this.data.slice(i, 1);
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
deleteMany(options) {
|
|
80
|
-
const items = this.search({ filter: options?.filter });
|
|
81
|
-
this.data = this.data.filter(x => !items.includes(x));
|
|
82
|
-
return items.length;
|
|
83
|
-
}
|
|
84
|
-
static filterFields(obj,
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
86
|
-
pick,
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
88
|
-
omit,
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
90
|
-
include) {
|
|
91
|
-
if (!obj)
|
|
92
|
-
return;
|
|
93
|
-
return obj;
|
|
94
|
-
}
|
|
95
|
-
static prepare(query) {
|
|
96
|
-
switch (query.queryType) {
|
|
97
|
-
case 'create': {
|
|
98
|
-
const options = lodash_1.default.omitBy({
|
|
99
|
-
pick: query.pick?.length ? query.pick : undefined,
|
|
100
|
-
omit: query.omit?.length ? query.omit : undefined,
|
|
101
|
-
include: query.include?.length ? query.include : undefined,
|
|
102
|
-
}, lodash_1.default.isNil);
|
|
103
|
-
const { data } = query;
|
|
104
|
-
return {
|
|
105
|
-
method: query.queryType,
|
|
106
|
-
values: data,
|
|
107
|
-
options,
|
|
108
|
-
args: [data, options]
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
case 'get': {
|
|
112
|
-
const options = lodash_1.default.omitBy({
|
|
113
|
-
pick: query.pick?.length ? query.pick : undefined,
|
|
114
|
-
omit: query.omit?.length ? query.omit : undefined,
|
|
115
|
-
include: query.include?.length ? query.include : undefined,
|
|
116
|
-
}, lodash_1.default.isNil);
|
|
117
|
-
const keyValue = query.keyValue;
|
|
118
|
-
return {
|
|
119
|
-
method: query.queryType,
|
|
120
|
-
keyValue,
|
|
121
|
-
options,
|
|
122
|
-
args: [keyValue, options]
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
case 'search': {
|
|
126
|
-
const options = lodash_1.default.omitBy({
|
|
127
|
-
pick: query.pick?.length ? query.pick : undefined,
|
|
128
|
-
omit: query.omit?.length ? query.omit : undefined,
|
|
129
|
-
include: query.include?.length ? query.include : undefined,
|
|
130
|
-
sort: query.sort?.length ? query.sort : undefined,
|
|
131
|
-
limit: query.limit,
|
|
132
|
-
offset: query.skip,
|
|
133
|
-
distinct: query.distinct,
|
|
134
|
-
total: query.count,
|
|
135
|
-
filter: JsonDataService.convertFilter(query.filter)
|
|
136
|
-
}, lodash_1.default.isNil);
|
|
137
|
-
return {
|
|
138
|
-
method: query.queryType,
|
|
139
|
-
options,
|
|
140
|
-
args: [options]
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
case 'update': {
|
|
144
|
-
const options = lodash_1.default.omitBy({
|
|
145
|
-
pick: query.pick?.length ? query.pick : undefined,
|
|
146
|
-
omit: query.omit?.length ? query.omit : undefined,
|
|
147
|
-
include: query.include?.length ? query.include : undefined,
|
|
148
|
-
}, lodash_1.default.isNil);
|
|
149
|
-
const { data } = query;
|
|
150
|
-
const keyValue = query.keyValue;
|
|
151
|
-
return {
|
|
152
|
-
method: query.queryType,
|
|
153
|
-
keyValue: query.keyValue,
|
|
154
|
-
values: data,
|
|
155
|
-
options,
|
|
156
|
-
args: [keyValue, data, options]
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
case 'updateMany': {
|
|
160
|
-
const options = lodash_1.default.omitBy({
|
|
161
|
-
filter: JsonDataService.convertFilter(query.filter)
|
|
162
|
-
}, lodash_1.default.isNil);
|
|
163
|
-
const { data } = query;
|
|
164
|
-
return {
|
|
165
|
-
method: query.queryType,
|
|
166
|
-
options,
|
|
167
|
-
args: [data, options]
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
case 'delete': {
|
|
171
|
-
const options = {};
|
|
172
|
-
const keyValue = query.keyValue;
|
|
173
|
-
return {
|
|
174
|
-
method: query.queryType,
|
|
175
|
-
keyValue,
|
|
176
|
-
options,
|
|
177
|
-
args: [keyValue, options]
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
case 'deleteMany': {
|
|
181
|
-
const options = lodash_1.default.omitBy({
|
|
182
|
-
filter: JsonDataService.convertFilter(query.filter)
|
|
183
|
-
}, lodash_1.default.isNil);
|
|
184
|
-
return {
|
|
185
|
-
method: query.queryType,
|
|
186
|
-
options,
|
|
187
|
-
args: [options]
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
default:
|
|
191
|
-
throw new Error(`Unimplemented query type "${query.queryType}"`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
static convertFilter(str) {
|
|
195
|
-
const ast = typeof str === 'string'
|
|
196
|
-
? (0, url_1.$parse)(str)
|
|
197
|
-
: str;
|
|
198
|
-
if (!ast || !(ast instanceof url_1.Expression))
|
|
199
|
-
return ast;
|
|
200
|
-
if (ast instanceof url_1.ComparisonExpression) {
|
|
201
|
-
const left = JsonDataService.convertFilter(ast.left);
|
|
202
|
-
const right = JsonDataService.convertFilter(ast.right);
|
|
203
|
-
switch (ast.op) {
|
|
204
|
-
case '=':
|
|
205
|
-
return { $eq: { [left]: right } };
|
|
206
|
-
case '!=':
|
|
207
|
-
return { $ne: { [left]: right } };
|
|
208
|
-
case '>':
|
|
209
|
-
return { $gt: { [left]: right } };
|
|
210
|
-
case '>=':
|
|
211
|
-
return { $gte: { [left]: right } };
|
|
212
|
-
case '<':
|
|
213
|
-
return { $lt: { [left]: right } };
|
|
214
|
-
case '<=':
|
|
215
|
-
return { $lte: { [left]: right } };
|
|
216
|
-
case 'in':
|
|
217
|
-
return { $in: { [left]: right } };
|
|
218
|
-
case '!in':
|
|
219
|
-
return { $nin: { [left]: right } };
|
|
220
|
-
default:
|
|
221
|
-
throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
if (ast instanceof url_1.QualifiedIdentifier) {
|
|
225
|
-
return ast.value;
|
|
226
|
-
}
|
|
227
|
-
if (ast instanceof url_1.NumberLiteral ||
|
|
228
|
-
ast instanceof url_1.StringLiteral ||
|
|
229
|
-
ast instanceof url_1.BooleanLiteral ||
|
|
230
|
-
ast instanceof url_1.NullLiteral ||
|
|
231
|
-
ast instanceof url_1.DateLiteral ||
|
|
232
|
-
ast instanceof url_1.TimeLiteral) {
|
|
233
|
-
return ast.value;
|
|
234
|
-
}
|
|
235
|
-
if (ast instanceof url_1.ArrayExpression) {
|
|
236
|
-
return ast.items.map(JsonDataService.convertFilter);
|
|
237
|
-
}
|
|
238
|
-
if (ast instanceof url_1.LogicalExpression) {
|
|
239
|
-
if (ast.op === 'or')
|
|
240
|
-
return { $or: ast.items.map(JsonDataService.convertFilter) };
|
|
241
|
-
return { $and: ast.items.map(JsonDataService.convertFilter) };
|
|
242
|
-
}
|
|
243
|
-
if (ast instanceof url_1.ArrayExpression) {
|
|
244
|
-
return ast.items.map(JsonDataService.convertFilter);
|
|
245
|
-
}
|
|
246
|
-
if (ast instanceof url_1.ParenthesesExpression) {
|
|
247
|
-
return JsonDataService.convertFilter(ast.expression);
|
|
248
|
-
}
|
|
249
|
-
throw new Error(`${ast.type} is not implemented yet`);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
exports.JsonDataService = JsonDataService;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { HttpStatus } from '../enums/index.js';
|
|
2
|
-
export declare type IssueSeverity = 'error' | 'fatal' | 'warning' | 'info';
|
|
3
|
-
export interface ErrorResponse {
|
|
4
|
-
/**
|
|
5
|
-
* Error message
|
|
6
|
-
*/
|
|
7
|
-
message: string;
|
|
8
|
-
/**
|
|
9
|
-
* Error or warning code
|
|
10
|
-
*/
|
|
11
|
-
code?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Severity of the issue
|
|
14
|
-
*/
|
|
15
|
-
severity?: IssueSeverity;
|
|
16
|
-
/**
|
|
17
|
-
* Additional details about the error
|
|
18
|
-
*/
|
|
19
|
-
details?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Additional diagnostic information about the issue. Error stack etc.
|
|
22
|
-
*/
|
|
23
|
-
diagnostics?: string | string[];
|
|
24
|
-
[index: string]: any;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Defines the base Opra exception, which is handled by the default Exceptions Handler.
|
|
28
|
-
*/
|
|
29
|
-
export declare class ApiException extends Error {
|
|
30
|
-
static stackAsDiagnostics: boolean;
|
|
31
|
-
response: ErrorResponse;
|
|
32
|
-
status: number;
|
|
33
|
-
cause?: Error;
|
|
34
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
35
|
-
setStatus(status: number | HttpStatus): this;
|
|
36
|
-
protected _initName(): void;
|
|
37
|
-
protected _initErrorInstance(init: Error): void;
|
|
38
|
-
protected _initResponse(response?: Partial<ErrorResponse>): void;
|
|
39
|
-
static wrap(response: string | ErrorResponse | Error): ApiException;
|
|
40
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { HttpStatus } from '../enums/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Defines the base Opra exception, which is handled by the default Exceptions Handler.
|
|
4
|
-
*/
|
|
5
|
-
export class ApiException extends Error {
|
|
6
|
-
static stackAsDiagnostics = false;
|
|
7
|
-
response;
|
|
8
|
-
status;
|
|
9
|
-
cause;
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super('');
|
|
12
|
-
this._initName();
|
|
13
|
-
this.status = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
14
|
-
cause = cause || (response instanceof Error ? response : undefined);
|
|
15
|
-
if (cause)
|
|
16
|
-
Object.defineProperty(this, 'cause', { enumerable: false, configurable: true, writable: true, value: cause });
|
|
17
|
-
if (response instanceof Error)
|
|
18
|
-
this._initErrorInstance(response);
|
|
19
|
-
else if (typeof response === 'string')
|
|
20
|
-
this._initResponse({ message: response });
|
|
21
|
-
else
|
|
22
|
-
this._initResponse(response);
|
|
23
|
-
if (!this.response.severity)
|
|
24
|
-
if (this.status >= 500)
|
|
25
|
-
this.response.severity = 'fatal';
|
|
26
|
-
else
|
|
27
|
-
this.response.severity = 'error';
|
|
28
|
-
if (this.cause instanceof Error && this.cause.stack) {
|
|
29
|
-
if (ApiException.stackAsDiagnostics)
|
|
30
|
-
this.response.diagnostics = this.cause.stack.split('\n');
|
|
31
|
-
this.stack = this.cause.stack;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
setStatus(status) {
|
|
35
|
-
this.status = status;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
_initName() {
|
|
39
|
-
this.name = this.constructor.name;
|
|
40
|
-
}
|
|
41
|
-
_initErrorInstance(init) {
|
|
42
|
-
this._initResponse({
|
|
43
|
-
message: init.message
|
|
44
|
-
});
|
|
45
|
-
if (typeof init.status === 'number')
|
|
46
|
-
this.setStatus(init.status);
|
|
47
|
-
else if (typeof init.getStatus === 'function')
|
|
48
|
-
this.setStatus(init.getStatus());
|
|
49
|
-
}
|
|
50
|
-
_initResponse(response) {
|
|
51
|
-
this.response = {
|
|
52
|
-
message: 'Unknown error',
|
|
53
|
-
...response
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
static wrap(response) {
|
|
57
|
-
if (response instanceof ApiException)
|
|
58
|
-
return response;
|
|
59
|
-
const out = new this(response, response instanceof Error ? response : undefined);
|
|
60
|
-
if (response instanceof Error)
|
|
61
|
-
out.stack = response.stack;
|
|
62
|
-
return out;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 400 Bad Request
|
|
4
|
-
* The server cannot or will not process the request due to something that is perceived to be a client error
|
|
5
|
-
* (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
|
6
|
-
*/
|
|
7
|
-
export declare class BadRequestError extends ApiException {
|
|
8
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
9
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
10
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 400 Bad Request
|
|
6
|
-
* The server cannot or will not process the request due to something that is perceived to be a client error
|
|
7
|
-
* (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
|
8
|
-
*/
|
|
9
|
-
export class BadRequestError extends ApiException {
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super(response, cause);
|
|
12
|
-
this.status = HttpStatus.BAD_REQUEST;
|
|
13
|
-
}
|
|
14
|
-
_initResponse(response) {
|
|
15
|
-
super._initResponse({
|
|
16
|
-
message: translate('error:BAD_REQUEST'),
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'BAD_REQUEST',
|
|
19
|
-
...response
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 424 Failed Dependency
|
|
4
|
-
* The request failed due to failure of a previous request.
|
|
5
|
-
*/
|
|
6
|
-
export declare class FailedDependencyError extends ApiException {
|
|
7
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
8
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
9
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 424 Failed Dependency
|
|
6
|
-
* The request failed due to failure of a previous request.
|
|
7
|
-
*/
|
|
8
|
-
export class FailedDependencyError extends ApiException {
|
|
9
|
-
constructor(response, cause) {
|
|
10
|
-
super(response, cause);
|
|
11
|
-
this.status = HttpStatus.FAILED_DEPENDENCY;
|
|
12
|
-
}
|
|
13
|
-
_initResponse(response) {
|
|
14
|
-
super._initResponse({
|
|
15
|
-
message: translate('error:FAILED_DEPENDENCY'),
|
|
16
|
-
severity: 'error',
|
|
17
|
-
code: 'FAILED_DEPENDENCY',
|
|
18
|
-
...response
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 403 Forbidden
|
|
4
|
-
* The client does not have access rights to the content; that is, it is unauthorized,
|
|
5
|
-
* so the server is refusing to give the requested resource. Unlike 401 Unauthorized,
|
|
6
|
-
* the client's identity is known to the server.
|
|
7
|
-
*/
|
|
8
|
-
export declare class ForbiddenError extends ApiException {
|
|
9
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
10
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
11
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 403 Forbidden
|
|
6
|
-
* The client does not have access rights to the content; that is, it is unauthorized,
|
|
7
|
-
* so the server is refusing to give the requested resource. Unlike 401 Unauthorized,
|
|
8
|
-
* the client's identity is known to the server.
|
|
9
|
-
*/
|
|
10
|
-
export class ForbiddenError extends ApiException {
|
|
11
|
-
constructor(response, cause) {
|
|
12
|
-
super(response, cause);
|
|
13
|
-
this.status = HttpStatus.FORBIDDEN;
|
|
14
|
-
}
|
|
15
|
-
_initResponse(response) {
|
|
16
|
-
super._initResponse({
|
|
17
|
-
message: translate('error:FORBIDDEN'),
|
|
18
|
-
severity: 'error',
|
|
19
|
-
code: 'FORBIDDEN',
|
|
20
|
-
...response
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 500 Internal Server Error
|
|
4
|
-
* The server has encountered a situation it does not know how to handle.
|
|
5
|
-
*/
|
|
6
|
-
export declare class InternalServerError extends ApiException {
|
|
7
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
8
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
9
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import { translate } from '@opra/i18n';
|
|
3
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
4
|
-
import { ApiException } from '../api-exception.js';
|
|
5
|
-
/**
|
|
6
|
-
* 500 Internal Server Error
|
|
7
|
-
* The server has encountered a situation it does not know how to handle.
|
|
8
|
-
*/
|
|
9
|
-
export class InternalServerError extends ApiException {
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super(response, cause);
|
|
12
|
-
this.status = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
13
|
-
}
|
|
14
|
-
_initResponse(response) {
|
|
15
|
-
super._initResponse({
|
|
16
|
-
message: translate('error:INTERNAL_SERVER_ERROR'),
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
19
|
-
..._.omitBy(response, _.isNil)
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 405 Method Not Allowed
|
|
4
|
-
* The request method is known by the server but is not supported by the target resource.
|
|
5
|
-
* For example, an API may not allow calling DELETE to remove a resource.
|
|
6
|
-
*/
|
|
7
|
-
export declare class MethodNotAllowedError extends ApiException {
|
|
8
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
9
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
10
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 405 Method Not Allowed
|
|
6
|
-
* The request method is known by the server but is not supported by the target resource.
|
|
7
|
-
* For example, an API may not allow calling DELETE to remove a resource.
|
|
8
|
-
*/
|
|
9
|
-
export class MethodNotAllowedError extends ApiException {
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super(response, cause);
|
|
12
|
-
this.status = HttpStatus.METHOD_NOT_ALLOWED;
|
|
13
|
-
}
|
|
14
|
-
_initResponse(response) {
|
|
15
|
-
super._initResponse({
|
|
16
|
-
message: translate('error:METHOD_NOT_ALLOWED'),
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'METHOD_NOT_ALLOWED',
|
|
19
|
-
...response
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 406 Not Acceptable
|
|
4
|
-
* This response is sent when the web server, after performing server-driven content negotiation,
|
|
5
|
-
* doesn't find any content that conforms to the criteria given by the user agent.
|
|
6
|
-
*/
|
|
7
|
-
export declare class NotAcceptableError extends ApiException {
|
|
8
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
9
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
10
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 406 Not Acceptable
|
|
6
|
-
* This response is sent when the web server, after performing server-driven content negotiation,
|
|
7
|
-
* doesn't find any content that conforms to the criteria given by the user agent.
|
|
8
|
-
*/
|
|
9
|
-
export class NotAcceptableError extends ApiException {
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super(response, cause);
|
|
12
|
-
this.status = HttpStatus.NOT_ACCEPTABLE;
|
|
13
|
-
}
|
|
14
|
-
_initResponse(response) {
|
|
15
|
-
super._initResponse({
|
|
16
|
-
message: translate('error:NOT_ACCEPTABLE', 'Not Acceptable'),
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'NOT_ACCEPTABLE',
|
|
19
|
-
...response
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 404 Not Found
|
|
4
|
-
* The server can not find the requested resource. In the browser, this means the URL is not recognized.
|
|
5
|
-
* In an API, this can also mean that the endpoint is valid but the resource itself does not exist.
|
|
6
|
-
* Servers may also send this response instead of 403 Forbidden to hide the existence of a resource
|
|
7
|
-
* from an unauthorized client. This response code is probably the most well known due to its
|
|
8
|
-
* frequent occurrence on the web.
|
|
9
|
-
*/
|
|
10
|
-
export declare class NotFoundError extends ApiException {
|
|
11
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
12
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
13
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 404 Not Found
|
|
6
|
-
* The server can not find the requested resource. In the browser, this means the URL is not recognized.
|
|
7
|
-
* In an API, this can also mean that the endpoint is valid but the resource itself does not exist.
|
|
8
|
-
* Servers may also send this response instead of 403 Forbidden to hide the existence of a resource
|
|
9
|
-
* from an unauthorized client. This response code is probably the most well known due to its
|
|
10
|
-
* frequent occurrence on the web.
|
|
11
|
-
*/
|
|
12
|
-
export class NotFoundError extends ApiException {
|
|
13
|
-
constructor(response, cause) {
|
|
14
|
-
super(response, cause);
|
|
15
|
-
this.status = HttpStatus.NOT_FOUND;
|
|
16
|
-
}
|
|
17
|
-
_initResponse(response) {
|
|
18
|
-
super._initResponse({
|
|
19
|
-
message: translate('error:NOT_FOUND', 'Not found'),
|
|
20
|
-
severity: 'error',
|
|
21
|
-
code: 'NOT_FOUND',
|
|
22
|
-
...response
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 401 Unauthorized
|
|
4
|
-
* Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated".
|
|
5
|
-
* That is, the client must authenticate itself to get the requested response.
|
|
6
|
-
*/
|
|
7
|
-
export declare class UnauthorizedError extends ApiException {
|
|
8
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
9
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
10
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 401 Unauthorized
|
|
6
|
-
* Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated".
|
|
7
|
-
* That is, the client must authenticate itself to get the requested response.
|
|
8
|
-
*/
|
|
9
|
-
export class UnauthorizedError extends ApiException {
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super(response, cause);
|
|
12
|
-
this.status = HttpStatus.UNAUTHORIZED;
|
|
13
|
-
}
|
|
14
|
-
_initResponse(response) {
|
|
15
|
-
super._initResponse({
|
|
16
|
-
message: translate('error:UNAUTHORIZED', 'Unauthorized'),
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'UNAUTHORIZED',
|
|
19
|
-
...response
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 422 Unprocessable Entity
|
|
4
|
-
* The request was well-formed but was unable to be followed due to semantic errors.
|
|
5
|
-
*/
|
|
6
|
-
export declare class UnprocessableEntityError extends ApiException {
|
|
7
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
8
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
9
|
-
}
|