@opra/common 0.32.6 → 0.33.1
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/browser.js +94 -89
- package/cjs/document/data-type/builtin/approx-date.type.js +2 -2
- package/cjs/document/data-type/builtin/approx-datetime.type.js +2 -2
- package/cjs/document/data-type/builtin/base64.type.js +2 -2
- package/cjs/document/data-type/builtin/bigint.type.js +2 -2
- package/cjs/document/data-type/builtin/boolean.type.js +2 -2
- package/cjs/document/data-type/builtin/date.type.js +2 -2
- package/cjs/document/data-type/builtin/datetime.type.js +2 -2
- package/cjs/document/data-type/builtin/email.type.js +2 -2
- package/cjs/document/data-type/builtin/integer.type.js +2 -2
- package/cjs/document/data-type/builtin/null.type.js +2 -2
- package/cjs/document/data-type/builtin/number.type.js +2 -2
- package/cjs/document/data-type/builtin/object-id.type.js +2 -2
- package/cjs/document/data-type/builtin/string.type.js +2 -2
- package/cjs/document/data-type/builtin/time.type.js +2 -2
- package/cjs/document/data-type/builtin/url.type.js +2 -2
- package/cjs/document/data-type/builtin/uuid.type.js +2 -2
- package/cjs/document/data-type/complex-type-class.js +2 -3
- package/cjs/document/data-type/enum-type-class.js +5 -5
- package/cjs/document/data-type/field-class.js +10 -8
- package/cjs/document/data-type/simple-type-class.js +3 -4
- package/cjs/document/resource/action.js +2 -3
- package/cjs/document/resource/collection-class.js +2 -3
- package/cjs/document/resource/container-class.js +1 -1
- package/cjs/document/resource/crud-operation.js +3 -4
- package/cjs/document/resource/parameter.js +3 -4
- package/cjs/exception/index.js +2 -2
- package/cjs/exception/resource-errors/permission.error.js +21 -0
- package/cjs/exception/resource-errors/resource-conflict.error.js +1 -1
- package/cjs/exception/resource-errors/resource-not-found.error.js +2 -2
- package/cjs/exception/resource-errors/resource-not.available.error.js +24 -0
- package/cjs/exception/resource-errors/resource-not.available.js +24 -0
- package/cjs/filter/ast/terms/date-literal.js +1 -1
- package/cjs/filter/ast/terms/number-literal.js +1 -1
- package/cjs/filter/ast/terms/time-literal.js +1 -1
- package/cjs/filter/errors.js +3 -3
- package/esm/document/data-type/builtin/approx-date.type.js +3 -3
- package/esm/document/data-type/builtin/approx-datetime.type.js +2 -2
- package/esm/document/data-type/builtin/base64.type.js +2 -2
- package/esm/document/data-type/builtin/bigint.type.js +3 -3
- package/esm/document/data-type/builtin/boolean.type.js +2 -2
- package/esm/document/data-type/builtin/date.type.js +3 -3
- package/esm/document/data-type/builtin/datetime.type.js +3 -3
- package/esm/document/data-type/builtin/email.type.js +3 -3
- package/esm/document/data-type/builtin/integer.type.js +2 -2
- package/esm/document/data-type/builtin/null.type.js +2 -2
- package/esm/document/data-type/builtin/number.type.js +2 -2
- package/esm/document/data-type/builtin/object-id.type.js +3 -3
- package/esm/document/data-type/builtin/string.type.js +2 -2
- package/esm/document/data-type/builtin/time.type.js +3 -3
- package/esm/document/data-type/builtin/url.type.js +2 -2
- package/esm/document/data-type/builtin/uuid.type.js +2 -2
- package/esm/document/data-type/complex-type-class.js +1 -1
- package/esm/document/data-type/enum-type-class.js +3 -2
- package/esm/document/data-type/field-class.js +8 -5
- package/esm/document/data-type/simple-type-class.js +3 -3
- package/esm/document/resource/action.js +2 -2
- package/esm/document/resource/collection-class.js +1 -1
- package/esm/document/resource/container-class.js +2 -2
- package/esm/document/resource/crud-operation.js +1 -1
- package/esm/document/resource/parameter.js +1 -1
- package/esm/exception/index.js +2 -2
- package/esm/exception/resource-errors/permission.error.js +17 -0
- package/esm/exception/resource-errors/resource-conflict.error.js +1 -1
- package/esm/exception/resource-errors/resource-not-found.error.js +2 -2
- package/esm/exception/resource-errors/resource-not.available.error.js +20 -0
- package/esm/exception/resource-errors/resource-not.available.js +20 -0
- package/esm/filter/ast/terms/date-literal.js +2 -2
- package/esm/filter/ast/terms/number-literal.js +2 -2
- package/esm/filter/ast/terms/time-literal.js +2 -2
- package/esm/filter/errors.js +1 -1
- package/package.json +3 -3
- package/types/document/data-type/complex-type-class.d.ts +4 -4
- package/types/document/data-type/data-type.d.ts +3 -3
- package/types/document/data-type/enum-type-class.d.ts +4 -4
- package/types/document/data-type/field-class.d.ts +3 -3
- package/types/document/data-type/field.d.ts +6 -3
- package/types/document/data-type/simple-type-class.d.ts +4 -4
- package/types/document/data-type/simple-type.d.ts +7 -7
- package/types/document/resource/action.d.ts +2 -2
- package/types/document/resource/crud-operation.d.ts +3 -3
- package/types/document/resource/parameter.d.ts +6 -6
- package/types/exception/index.d.ts +2 -2
- package/types/exception/resource-errors/permission.error.d.ts +11 -0
- package/types/exception/resource-errors/resource-not.available.d.ts +8 -0
- package/types/exception/resource-errors/resource-not.available.error.d.ts +8 -0
- package/types/filter/errors.d.ts +1 -1
- package/types/helpers/object-utils.d.ts +2 -2
- package/types/schema/data-type/complex-type.interface.d.ts +1 -1
- package/types/schema/data-type/field.interface.d.ts +4 -1
- package/types/schema/data-type/mapped-type.interface.d.ts +1 -1
- package/types/schema/data-type/simple-type.interface.d.ts +3 -3
- package/types/types.d.ts +5 -26
- package/cjs/exception/common-errors/validation.error.js +0 -11
- package/esm/exception/common-errors/validation.error.js +0 -7
- package/types/exception/common-errors/validation.error.d.ts +0 -4
|
@@ -6,8 +6,8 @@ let UrlType = class UrlType {
|
|
|
6
6
|
UrlType = __decorate([
|
|
7
7
|
SimpleType({
|
|
8
8
|
description: 'A Uniform Resource Identifier Reference (RFC 3986 icon) value',
|
|
9
|
-
decoder: isURL
|
|
10
|
-
encoder: isURL
|
|
9
|
+
decoder: isURL,
|
|
10
|
+
encoder: isURL
|
|
11
11
|
})
|
|
12
12
|
], UrlType);
|
|
13
13
|
export { UrlType };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { vg } from 'valgen';
|
|
2
2
|
import { omitUndefined } from '../../helpers/index.js';
|
|
3
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import { DATATYPE_METADATA } from '../constants.js';
|
|
@@ -15,7 +15,8 @@ export class EnumTypeClass extends DataType {
|
|
|
15
15
|
this.encode = vg.isEnum(Object.keys(this.values));
|
|
16
16
|
}
|
|
17
17
|
isTypeOf(t) {
|
|
18
|
-
return t[DATATYPE_METADATA]
|
|
18
|
+
return t[DATATYPE_METADATA] &&
|
|
19
|
+
t[DATATYPE_METADATA] === this.enumObject?.[DATATYPE_METADATA];
|
|
19
20
|
}
|
|
20
21
|
exportSchema() {
|
|
21
22
|
const out = super.exportSchema();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isUndefined, vg } from 'valgen';
|
|
2
2
|
import { omitUndefined } from '../../helpers/index.js';
|
|
3
3
|
export class FieldClass {
|
|
4
4
|
constructor(owner, init) {
|
|
@@ -18,7 +18,8 @@ export class FieldClass {
|
|
|
18
18
|
this.translatable = init.translatable;
|
|
19
19
|
this.deprecated = init.deprecated;
|
|
20
20
|
this.examples = init.examples;
|
|
21
|
-
this.
|
|
21
|
+
this.pattern = init.pattern ?
|
|
22
|
+
(init.pattern instanceof RegExp ? init.pattern : new RegExp(init.pattern)) : undefined;
|
|
22
23
|
this.partialUpdate = init.partialUpdate;
|
|
23
24
|
}
|
|
24
25
|
exportSchema(options) {
|
|
@@ -39,20 +40,22 @@ export class FieldClass {
|
|
|
39
40
|
translatable: this.translatable,
|
|
40
41
|
deprecated: this.deprecated,
|
|
41
42
|
examples: this.examples,
|
|
42
|
-
|
|
43
|
+
pattern: this.pattern ? String(this.pattern) : undefined,
|
|
43
44
|
partialUpdate: this.partialUpdate,
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
generateCodec(codec, options) {
|
|
47
48
|
if (options?.operation === 'read' && this.writeonly)
|
|
48
|
-
return
|
|
49
|
+
return isUndefined;
|
|
49
50
|
if (options?.operation === 'write' && this.readonly)
|
|
50
|
-
return
|
|
51
|
+
return isUndefined;
|
|
51
52
|
let fn = this.type.generateCodec(codec, {
|
|
52
53
|
...options,
|
|
53
54
|
designType: this.designType,
|
|
54
55
|
partial: options?.partial && (this.partialUpdate || !this.isArray)
|
|
55
56
|
});
|
|
57
|
+
if (this.pattern)
|
|
58
|
+
fn = vg.allOf(fn, vg.isRegExp(this.pattern));
|
|
56
59
|
if (this.isArray)
|
|
57
60
|
fn = vg.isArray(fn);
|
|
58
61
|
return !options?.partial && this.required ? vg.required(fn) : vg.optional(fn);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isAny } from 'valgen';
|
|
2
2
|
import { omitUndefined } from '../../helpers/index.js';
|
|
3
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import { DataType } from './data-type.js';
|
|
@@ -10,8 +10,8 @@ export class SimpleTypeClass extends DataType {
|
|
|
10
10
|
super(document, init);
|
|
11
11
|
this.kind = OpraSchema.SimpleType.Kind;
|
|
12
12
|
this.base = init.base;
|
|
13
|
-
this.decode = init.decoder || init.base?.decode ||
|
|
14
|
-
this.encode = init.encoder || init.base?.encode ||
|
|
13
|
+
this.decode = init.decoder || init.base?.decode || isAny;
|
|
14
|
+
this.encode = init.encoder || init.base?.encode || isAny;
|
|
15
15
|
}
|
|
16
16
|
exportSchema(options) {
|
|
17
17
|
// noinspection UnnecessaryLocalVariableJS
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isAny } from 'valgen';
|
|
2
2
|
import { DataType } from '../data-type/data-type.js';
|
|
3
3
|
import { Endpoint } from './endpoint.js';
|
|
4
4
|
/**
|
|
@@ -11,7 +11,7 @@ export class Action extends Endpoint {
|
|
|
11
11
|
this.resource = resource;
|
|
12
12
|
this.name = name;
|
|
13
13
|
this.kind = 'action';
|
|
14
|
-
this.encodeReturning =
|
|
14
|
+
this.encodeReturning = isAny;
|
|
15
15
|
if (init.returnType)
|
|
16
16
|
this.returnType = init.returnType instanceof DataType
|
|
17
17
|
? init.returnType : this.resource.document.getDataType(init.returnType);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NotAcceptableError,
|
|
1
|
+
import { NotAcceptableError, ResourceNotAvailableError } from '../../exception/index.js';
|
|
2
2
|
import { ResponsiveMap } from '../../helpers/index.js';
|
|
3
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import { Resource } from './resource.js';
|
|
@@ -41,7 +41,7 @@ export class ContainerClass extends Resource {
|
|
|
41
41
|
resource = this.resources.get(path);
|
|
42
42
|
if (resource || silent)
|
|
43
43
|
return resource;
|
|
44
|
-
throw new
|
|
44
|
+
throw new ResourceNotAvailableError(path);
|
|
45
45
|
}
|
|
46
46
|
getContainer(path, silent) {
|
|
47
47
|
const t = this.getResource(path);
|
package/esm/exception/index.js
CHANGED
|
@@ -12,6 +12,6 @@ export * from './http-errors/not-acceptable.error.js';
|
|
|
12
12
|
export * from './http-errors/not-found.error.js';
|
|
13
13
|
export * from './http-errors/unauthorized.error.js';
|
|
14
14
|
export * from './http-errors/unprocessable-entity.error.js';
|
|
15
|
+
export * from './resource-errors/permission.error.js';
|
|
15
16
|
export * from './resource-errors/resource-conflict.error.js';
|
|
16
|
-
export * from './resource-errors/resource-not
|
|
17
|
-
export * from './common-errors/validation.error.js';
|
|
17
|
+
export * from './resource-errors/resource-not.available.error.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { ForbiddenError } from '../http-errors/forbidden.error.js';
|
|
3
|
+
/**
|
|
4
|
+
* 403 Forbidden
|
|
5
|
+
* The client does not have access rights to the content; that is, it is unauthorized,
|
|
6
|
+
* so the server is refusing to give the requested resource. Unlike 401 Unauthorized,
|
|
7
|
+
* the client's identity is known to the server.
|
|
8
|
+
*/
|
|
9
|
+
export class PermissionError extends ForbiddenError {
|
|
10
|
+
init(issue) {
|
|
11
|
+
super.init({
|
|
12
|
+
message: translate('error:PERMISSION_ERROR', 'You dont have permission for this operation'),
|
|
13
|
+
code: 'PERMISSION_ERROR',
|
|
14
|
+
...issue
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -3,7 +3,7 @@ import { OpraException } from '../opra-exception.js';
|
|
|
3
3
|
export class ResourceConflictError extends OpraException {
|
|
4
4
|
constructor(resource, fields, cause) {
|
|
5
5
|
super({
|
|
6
|
-
message: translate(`error:RESOURCE_CONFLICT`, { resource, fields }, `There is already an other {{resource}} resource with same
|
|
6
|
+
message: translate(`error:RESOURCE_CONFLICT`, { resource, fields }, `There is already an other {{resource}} resource with same values ({{fields}})`),
|
|
7
7
|
severity: 'error',
|
|
8
8
|
code: 'RESOURCE_CONFLICT',
|
|
9
9
|
details: {
|
|
@@ -8,9 +8,9 @@ import { OpraException } from '../opra-exception.js';
|
|
|
8
8
|
export class ResourceNotFoundError extends OpraException {
|
|
9
9
|
constructor(resource, keyValue, cause) {
|
|
10
10
|
super({
|
|
11
|
-
message: translate(`error:
|
|
11
|
+
message: translate(`error:RESOURCE_NOT_AVAILABLE`, `Resource "${resource}${keyValue ? '/' + keyValue : ''}" is not available or you dont have access`),
|
|
12
12
|
severity: 'error',
|
|
13
|
-
code: '
|
|
13
|
+
code: 'RESOURCE_NOT_AVAILABLE',
|
|
14
14
|
details: {
|
|
15
15
|
resource,
|
|
16
16
|
key: keyValue
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HttpStatusCodes } from '../../http/index.js';
|
|
2
|
+
import { translate } from '../../i18n/index.js';
|
|
3
|
+
import { OpraException } from '../opra-exception.js';
|
|
4
|
+
/**
|
|
5
|
+
* The server cannot find the requested resource.
|
|
6
|
+
* This can also mean that the endpoint is valid but the resource itself does not exist.
|
|
7
|
+
*/
|
|
8
|
+
export class ResourceNotAvailableError extends OpraException {
|
|
9
|
+
constructor(resource, keyValue, cause) {
|
|
10
|
+
super({
|
|
11
|
+
message: translate(`error:RESOURCE_NOT_AVAILABLE`, `Resource "${resource}${keyValue ? '/' + keyValue : ''}" is not available or you dont have access`),
|
|
12
|
+
severity: 'error',
|
|
13
|
+
code: 'RESOURCE_NOT_AVAILABLE',
|
|
14
|
+
details: {
|
|
15
|
+
resource,
|
|
16
|
+
key: keyValue
|
|
17
|
+
}
|
|
18
|
+
}, cause, HttpStatusCodes.UNPROCESSABLE_ENTITY);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HttpStatusCodes } from '../../http/index.js';
|
|
2
|
+
import { translate } from '../../i18n/index.js';
|
|
3
|
+
import { OpraException } from '../opra-exception.js';
|
|
4
|
+
/**
|
|
5
|
+
* The server cannot find the requested resource.
|
|
6
|
+
* This can also mean that the endpoint is valid but the resource itself does not exist.
|
|
7
|
+
*/
|
|
8
|
+
export class ResourceNotAvailable extends OpraException {
|
|
9
|
+
constructor(resource, keyValue, cause) {
|
|
10
|
+
super({
|
|
11
|
+
message: translate(`error:RESOURCE_NOT_AVAILABLE`, `Resource "${resource}${keyValue ? '/' + keyValue : ''}" is not available or you dont have access`),
|
|
12
|
+
severity: 'error',
|
|
13
|
+
code: 'RESOURCE_NOT_AVAILABLE',
|
|
14
|
+
details: {
|
|
15
|
+
resource,
|
|
16
|
+
key: keyValue
|
|
17
|
+
}
|
|
18
|
+
}, cause, HttpStatusCodes.UNPROCESSABLE_ENTITY);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toDateDef } from 'putil-varhelpers';
|
|
2
|
-
import {
|
|
2
|
+
import { FilterValidationError } from '../../errors.js';
|
|
3
3
|
import { quoteFilterString } from '../../utils.js';
|
|
4
4
|
import { Literal } from '../abstract/literal.js';
|
|
5
5
|
// const DATE_PATTERN = /^(\d{4})-(0[1-9]|1[012])-([123]0|[012][1-9]|31)/;
|
|
@@ -16,7 +16,7 @@ export class DateLiteral extends Literal {
|
|
|
16
16
|
this.value = value;
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
throw new
|
|
19
|
+
throw new FilterValidationError(`Invalid date value "${value}"`);
|
|
20
20
|
}
|
|
21
21
|
toString() {
|
|
22
22
|
return quoteFilterString(this.value);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FilterValidationError } from '../../errors.js';
|
|
2
2
|
import { Literal } from '../abstract/literal.js';
|
|
3
3
|
export class NumberLiteral extends Literal {
|
|
4
4
|
constructor(value) {
|
|
@@ -25,7 +25,7 @@ export class NumberLiteral extends Literal {
|
|
|
25
25
|
catch {
|
|
26
26
|
//
|
|
27
27
|
}
|
|
28
|
-
throw new
|
|
28
|
+
throw new FilterValidationError(`Invalid number literal ${value}`);
|
|
29
29
|
}
|
|
30
30
|
toString() {
|
|
31
31
|
return typeof this.value === 'bigint'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FilterValidationError } from '../../errors.js';
|
|
2
2
|
import { quoteFilterString } from '../../utils.js';
|
|
3
3
|
import { Literal } from '../abstract/literal.js';
|
|
4
4
|
const TIME_PATTERN = /^([01]\d|2[0-3]):([0-5]\d)(:[0-5]\d)?(\.(\d+))?$/;
|
|
@@ -17,7 +17,7 @@ export class TimeLiteral extends Literal {
|
|
|
17
17
|
this.value = value;
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
throw new
|
|
20
|
+
throw new FilterValidationError(`Invalid time value "${value}"`);
|
|
21
21
|
}
|
|
22
22
|
toString() {
|
|
23
23
|
return quoteFilterString(this.value);
|
package/esm/filter/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export class SyntaxError extends TypeError {
|
|
2
2
|
}
|
|
3
|
-
export class
|
|
3
|
+
export class FilterValidationError extends TypeError {
|
|
4
4
|
constructor(message) {
|
|
5
5
|
super(typeof message === 'string' ? message : message?.message);
|
|
6
6
|
if (typeof message === 'object')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.1",
|
|
4
4
|
"description": "Opra common package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"putil-varhelpers": "^1.6.5",
|
|
47
47
|
"reflect-metadata": "^0.1.14",
|
|
48
48
|
"uid": "^2.0.1",
|
|
49
|
-
"valgen": "^
|
|
49
|
+
"valgen": "^5.0.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@browsery/fs": "^0.4.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@types/lodash.omit": "^4.5.9",
|
|
57
57
|
"@types/validator": "^13.11.7",
|
|
58
58
|
"path-browserify": "^1.0.1",
|
|
59
|
-
"ts-gems": "^
|
|
59
|
+
"ts-gems": "^3.1.0"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=16.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequiredSome, Type } from 'ts-gems';
|
|
2
|
-
import
|
|
2
|
+
import { IsObject } from 'valgen';
|
|
3
3
|
import { ResponsiveMap } from '../../helpers/index.js';
|
|
4
4
|
import { OpraSchema } from '../../schema/index.js';
|
|
5
5
|
import type { ApiDocument } from '../api-document.js';
|
|
@@ -29,8 +29,8 @@ export declare class ComplexTypeClass extends DataType {
|
|
|
29
29
|
}): any;
|
|
30
30
|
isTypeOf(t: Type | Function): boolean;
|
|
31
31
|
extendsFrom(t: string | Type | DataType): boolean;
|
|
32
|
-
generateCodec<T extends Object = any>(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions):
|
|
33
|
-
generateCodecSchema(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions):
|
|
34
|
-
protected _generateCodecSchema(codec: 'decode' | 'encode', options?: RequiredSome<DataType.GenerateCodecOptions, 'pick' | 'omit'>):
|
|
32
|
+
generateCodec<T extends Object = any>(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): IsObject.Validator<T>;
|
|
33
|
+
generateCodecSchema(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): IsObject.Schema;
|
|
34
|
+
protected _generateCodecSchema(codec: 'decode' | 'encode', options?: RequiredSome<DataType.GenerateCodecOptions, 'pick' | 'omit'>): IsObject.Schema;
|
|
35
35
|
protected _buildOverwriteFieldsTree(obj: Record<string, DataType.OverrideFieldsConfig>): Record<string, DataType.OverrideFieldsConfig>;
|
|
36
36
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequiredSome, StrictOmit, Type } from 'ts-gems';
|
|
2
|
-
import
|
|
2
|
+
import { OnFailFunction, Validator } from 'valgen';
|
|
3
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import type { ApiDocument } from '../api-document.js';
|
|
5
5
|
import { nodeInspectCustom } from '../utils/inspect.util.js';
|
|
@@ -17,7 +17,7 @@ export declare abstract class DataType {
|
|
|
17
17
|
description?: string;
|
|
18
18
|
isAnonymous?: boolean;
|
|
19
19
|
protected constructor(document: ApiDocument, init?: DataType.InitArguments);
|
|
20
|
-
abstract generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions):
|
|
20
|
+
abstract generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): Validator;
|
|
21
21
|
exportSchema(options?: {
|
|
22
22
|
webSafe?: boolean;
|
|
23
23
|
}): OpraSchema.DataType;
|
|
@@ -52,6 +52,6 @@ export declare namespace DataType {
|
|
|
52
52
|
operation?: 'read' | 'write';
|
|
53
53
|
overwriteFields?: Record<string, OverrideFieldsConfig>;
|
|
54
54
|
designType?: Type;
|
|
55
|
-
onFail?:
|
|
55
|
+
onFail?: OnFailFunction;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Validator } from 'valgen';
|
|
2
2
|
import { OpraSchema } from '../../schema/index.js';
|
|
3
3
|
import type { ApiDocument } from '../api-document.js';
|
|
4
4
|
import { DataType } from './data-type.js';
|
|
@@ -9,10 +9,10 @@ export declare class EnumTypeClass extends DataType {
|
|
|
9
9
|
readonly base?: EnumType;
|
|
10
10
|
readonly values: Record<OpraSchema.EnumType.Value, OpraSchema.EnumType.ValueInfo>;
|
|
11
11
|
readonly ownValues: Record<OpraSchema.EnumType.Value, OpraSchema.EnumType.ValueInfo>;
|
|
12
|
-
readonly decode:
|
|
13
|
-
readonly encode:
|
|
12
|
+
readonly decode: Validator;
|
|
13
|
+
readonly encode: Validator;
|
|
14
14
|
constructor(document: ApiDocument, init: EnumType.InitArguments);
|
|
15
15
|
isTypeOf(t: object): boolean;
|
|
16
16
|
exportSchema(): OpraSchema.EnumType;
|
|
17
|
-
generateCodec(codec: 'decode' | 'encode'):
|
|
17
|
+
generateCodec(codec: 'decode' | 'encode'): Validator;
|
|
18
18
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Type } from 'ts-gems';
|
|
2
|
-
import
|
|
2
|
+
import { Validator } from 'valgen';
|
|
3
3
|
import type { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import type { ComplexType } from './complex-type.js';
|
|
5
5
|
import type { DataType } from './data-type.js';
|
|
@@ -21,11 +21,11 @@ export declare class FieldClass {
|
|
|
21
21
|
translatable?: boolean;
|
|
22
22
|
deprecated?: boolean | string;
|
|
23
23
|
examples?: any[] | Record<string, any>;
|
|
24
|
-
|
|
24
|
+
pattern?: RegExp;
|
|
25
25
|
partialUpdate?: boolean;
|
|
26
26
|
constructor(owner: ComplexType, init: ApiField.InitArguments);
|
|
27
27
|
exportSchema(options?: {
|
|
28
28
|
webSafe?: boolean;
|
|
29
29
|
}): OpraSchema.Field;
|
|
30
|
-
generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions):
|
|
30
|
+
generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): Validator;
|
|
31
31
|
}
|
|
@@ -25,19 +25,22 @@ export declare const ApiField: FieldConstructor;
|
|
|
25
25
|
* @namespace ApiField
|
|
26
26
|
*/
|
|
27
27
|
export declare namespace ApiField {
|
|
28
|
-
interface InitArguments extends StrictOmit<OpraSchema.Field, 'type'> {
|
|
28
|
+
interface InitArguments extends StrictOmit<OpraSchema.Field, 'type' | 'pattern'> {
|
|
29
29
|
name: string;
|
|
30
30
|
type: DataType;
|
|
31
31
|
designType?: Type;
|
|
32
32
|
origin?: ComplexType;
|
|
33
|
+
pattern?: string | RegExp;
|
|
33
34
|
}
|
|
34
|
-
interface DecoratorOptions extends Partial<StrictOmit<OpraSchema.Field, 'isArray' | 'type'>> {
|
|
35
|
+
interface DecoratorOptions extends Partial<StrictOmit<OpraSchema.Field, 'isArray' | 'type' | 'pattern'>> {
|
|
35
36
|
type?: string | OpraSchema.DataType | TypeThunkAsync;
|
|
36
37
|
enum?: EnumType.EnumObject | EnumType.EnumArray;
|
|
38
|
+
pattern?: string | RegExp;
|
|
37
39
|
}
|
|
38
|
-
interface Metadata extends StrictOmit<OpraSchema.Field, 'type'> {
|
|
40
|
+
interface Metadata extends StrictOmit<OpraSchema.Field, 'type' | 'pattern'> {
|
|
39
41
|
type?: string | OpraSchema.DataType | TypeThunkAsync;
|
|
40
42
|
enum?: EnumType.EnumObject | EnumType.EnumArray;
|
|
41
43
|
designType?: Type;
|
|
44
|
+
pattern?: string | RegExp;
|
|
42
45
|
}
|
|
43
46
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Validator } from 'valgen';
|
|
2
2
|
import type { ApiDocument } from '../api-document.js';
|
|
3
3
|
import { DataType } from './data-type.js';
|
|
4
4
|
import type { SimpleType } from './simple-type.js';
|
|
@@ -9,11 +9,11 @@ export declare class SimpleTypeClass extends DataType {
|
|
|
9
9
|
readonly kind = "SimpleType";
|
|
10
10
|
readonly base?: SimpleType;
|
|
11
11
|
readonly own: SimpleType.OwnProperties;
|
|
12
|
-
readonly decode:
|
|
13
|
-
readonly encode:
|
|
12
|
+
readonly decode: Validator;
|
|
13
|
+
readonly encode: Validator;
|
|
14
14
|
constructor(document: ApiDocument, init: SimpleType.InitArguments);
|
|
15
15
|
exportSchema(options?: {
|
|
16
16
|
webSafe?: boolean;
|
|
17
17
|
}): any;
|
|
18
|
-
generateCodec(codec: 'decode' | 'encode'):
|
|
18
|
+
generateCodec(codec: 'decode' | 'encode'): Validator;
|
|
19
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import
|
|
2
|
+
import { Validator } from 'valgen';
|
|
3
3
|
import type { ApiDocument } from '../api-document.js';
|
|
4
4
|
import { DataType } from './data-type.js';
|
|
5
5
|
import { SimpleTypeClass } from './simple-type-class.js';
|
|
@@ -20,16 +20,16 @@ export declare const SimpleType: SimpleTypeConstructor;
|
|
|
20
20
|
export declare namespace SimpleType {
|
|
21
21
|
interface InitArguments extends DataType.InitArguments {
|
|
22
22
|
base?: SimpleType;
|
|
23
|
-
decoder?:
|
|
24
|
-
encoder?:
|
|
23
|
+
decoder?: Validator;
|
|
24
|
+
encoder?: Validator;
|
|
25
25
|
}
|
|
26
26
|
interface DecoratorOptions extends DataType.DecoratorOptions {
|
|
27
|
-
decoder?:
|
|
28
|
-
encoder?:
|
|
27
|
+
decoder?: Validator;
|
|
28
|
+
encoder?: Validator;
|
|
29
29
|
}
|
|
30
30
|
interface Metadata extends DataType.Metadata {
|
|
31
|
-
decoder?:
|
|
32
|
-
encoder?:
|
|
31
|
+
decoder?: Validator;
|
|
32
|
+
encoder?: Validator;
|
|
33
33
|
}
|
|
34
34
|
interface OwnProperties extends DataType.OwnProperties {
|
|
35
35
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import
|
|
2
|
+
import { Validator } from 'valgen';
|
|
3
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import { DataType } from '../data-type/data-type.js';
|
|
5
5
|
import { Endpoint } from './endpoint.js';
|
|
@@ -15,7 +15,7 @@ export declare class Action extends Endpoint {
|
|
|
15
15
|
readonly kind = "action";
|
|
16
16
|
returnType?: DataType;
|
|
17
17
|
returnMime?: string;
|
|
18
|
-
encodeReturning:
|
|
18
|
+
encodeReturning: Validator;
|
|
19
19
|
constructor(resource: Resource, name: string, init: Action.InitArguments);
|
|
20
20
|
exportSchema(options?: {
|
|
21
21
|
webSafe?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import
|
|
2
|
+
import { Validator } from 'valgen';
|
|
3
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import { DataType } from '../data-type/data-type.js';
|
|
5
5
|
import { ApiField } from '../data-type/field.js';
|
|
@@ -14,9 +14,9 @@ export declare class CrudOperation extends Endpoint {
|
|
|
14
14
|
readonly resource: Resource;
|
|
15
15
|
readonly name: string;
|
|
16
16
|
readonly kind = "operation";
|
|
17
|
-
decodeInput:
|
|
17
|
+
decodeInput: Validator;
|
|
18
18
|
returnType: DataType;
|
|
19
|
-
encodeReturning:
|
|
19
|
+
encodeReturning: Validator;
|
|
20
20
|
inputOverwriteFields?: Record<string, ApiField.InitArguments>;
|
|
21
21
|
outputOverwriteFields?: Record<string, ApiField.InitArguments>;
|
|
22
22
|
constructor(resource: Resource, name: string, init: CrudOperation.InitArguments);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import
|
|
2
|
+
import { Validator } from 'valgen';
|
|
3
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import { DataType } from '../data-type/data-type.js';
|
|
5
5
|
import type { ResourceDecorator } from './resource-decorator.js';
|
|
@@ -8,8 +8,8 @@ import type { ResourceDecorator } from './resource-decorator.js';
|
|
|
8
8
|
* @class Parameter
|
|
9
9
|
*/
|
|
10
10
|
export declare class Parameter {
|
|
11
|
-
protected _decoder:
|
|
12
|
-
protected _encoder:
|
|
11
|
+
protected _decoder: Validator;
|
|
12
|
+
protected _encoder: Validator;
|
|
13
13
|
readonly name: string;
|
|
14
14
|
readonly type: DataType;
|
|
15
15
|
description?: string;
|
|
@@ -23,9 +23,9 @@ export declare class Parameter {
|
|
|
23
23
|
exportSchema(options?: {
|
|
24
24
|
webSafe?: boolean;
|
|
25
25
|
}): OpraSchema.Endpoint.Parameter;
|
|
26
|
-
getDecoder():
|
|
27
|
-
getEncoder():
|
|
28
|
-
generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions):
|
|
26
|
+
getDecoder(): Validator;
|
|
27
|
+
getEncoder(): Validator;
|
|
28
|
+
generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): Validator;
|
|
29
29
|
}
|
|
30
30
|
export declare namespace Parameter {
|
|
31
31
|
interface InitArguments extends StrictOmit<ResourceDecorator.ParameterMetadata, 'type'> {
|
|
@@ -12,6 +12,6 @@ export * from './http-errors/not-acceptable.error.js';
|
|
|
12
12
|
export * from './http-errors/not-found.error.js';
|
|
13
13
|
export * from './http-errors/unauthorized.error.js';
|
|
14
14
|
export * from './http-errors/unprocessable-entity.error.js';
|
|
15
|
+
export * from './resource-errors/permission.error.js';
|
|
15
16
|
export * from './resource-errors/resource-conflict.error.js';
|
|
16
|
-
export * from './resource-errors/resource-not
|
|
17
|
-
export * from './common-errors/validation.error.js';
|
|
17
|
+
export * from './resource-errors/resource-not.available.error.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ErrorIssue } from '../error-issue.js';
|
|
2
|
+
import { ForbiddenError } from '../http-errors/forbidden.error.js';
|
|
3
|
+
/**
|
|
4
|
+
* 403 Forbidden
|
|
5
|
+
* The client does not have access rights to the content; that is, it is unauthorized,
|
|
6
|
+
* so the server is refusing to give the requested resource. Unlike 401 Unauthorized,
|
|
7
|
+
* the client's identity is known to the server.
|
|
8
|
+
*/
|
|
9
|
+
export declare class PermissionError extends ForbiddenError {
|
|
10
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpraException } from '../opra-exception.js';
|
|
2
|
+
/**
|
|
3
|
+
* The server cannot find the requested resource.
|
|
4
|
+
* This can also mean that the endpoint is valid but the resource itself does not exist.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ResourceNotAvailable extends OpraException {
|
|
7
|
+
constructor(resource: string, keyValue?: any, cause?: Error);
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpraException } from '../opra-exception.js';
|
|
2
|
+
/**
|
|
3
|
+
* The server cannot find the requested resource.
|
|
4
|
+
* This can also mean that the endpoint is valid but the resource itself does not exist.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ResourceNotAvailableError extends OpraException {
|
|
7
|
+
constructor(resource: string, keyValue?: any, cause?: Error);
|
|
8
|
+
}
|
package/types/filter/errors.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { RecognitionException } from '@browsery/antlr4';
|
|
|
2
2
|
import { Recognizer } from '@browsery/antlr4/typings/Recognizer';
|
|
3
3
|
export declare class SyntaxError extends TypeError {
|
|
4
4
|
}
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class FilterValidationError extends TypeError {
|
|
6
6
|
constructor(message?: string | {
|
|
7
7
|
message?: string;
|
|
8
8
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeeperOmitTypes } from 'ts-gems';
|
|
2
2
|
export declare function cloneObject<T extends {}>(obj: T, jsonOnly?: boolean): T;
|
|
3
3
|
export declare function omitUndefined<T>(obj: T, recursive?: boolean): T;
|
|
4
|
-
export declare function omitNullish<T>(obj: T, recursive?: boolean):
|
|
4
|
+
export declare function omitNullish<T>(obj: T, recursive?: boolean): DeeperOmitTypes<T, null | undefined>;
|