@opra/common 0.32.6 → 0.33.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.
Files changed (96) hide show
  1. package/browser.js +94 -89
  2. package/cjs/document/data-type/builtin/approx-date.type.js +2 -2
  3. package/cjs/document/data-type/builtin/approx-datetime.type.js +2 -2
  4. package/cjs/document/data-type/builtin/base64.type.js +2 -2
  5. package/cjs/document/data-type/builtin/bigint.type.js +2 -2
  6. package/cjs/document/data-type/builtin/boolean.type.js +2 -2
  7. package/cjs/document/data-type/builtin/date.type.js +2 -2
  8. package/cjs/document/data-type/builtin/datetime.type.js +2 -2
  9. package/cjs/document/data-type/builtin/email.type.js +2 -2
  10. package/cjs/document/data-type/builtin/integer.type.js +2 -2
  11. package/cjs/document/data-type/builtin/null.type.js +2 -2
  12. package/cjs/document/data-type/builtin/number.type.js +2 -2
  13. package/cjs/document/data-type/builtin/object-id.type.js +2 -2
  14. package/cjs/document/data-type/builtin/string.type.js +2 -2
  15. package/cjs/document/data-type/builtin/time.type.js +2 -2
  16. package/cjs/document/data-type/builtin/url.type.js +2 -2
  17. package/cjs/document/data-type/builtin/uuid.type.js +2 -2
  18. package/cjs/document/data-type/complex-type-class.js +2 -3
  19. package/cjs/document/data-type/enum-type-class.js +5 -5
  20. package/cjs/document/data-type/field-class.js +10 -8
  21. package/cjs/document/data-type/simple-type-class.js +3 -4
  22. package/cjs/document/resource/action.js +2 -3
  23. package/cjs/document/resource/collection-class.js +2 -3
  24. package/cjs/document/resource/container-class.js +1 -1
  25. package/cjs/document/resource/crud-operation.js +3 -4
  26. package/cjs/document/resource/parameter.js +3 -4
  27. package/cjs/exception/index.js +2 -2
  28. package/cjs/exception/resource-errors/permission.error.js +21 -0
  29. package/cjs/exception/resource-errors/resource-conflict.error.js +1 -1
  30. package/cjs/exception/resource-errors/resource-not-found.error.js +2 -2
  31. package/cjs/exception/resource-errors/resource-not.available.error.js +24 -0
  32. package/cjs/exception/resource-errors/resource-not.available.js +24 -0
  33. package/cjs/filter/ast/terms/date-literal.js +1 -1
  34. package/cjs/filter/ast/terms/number-literal.js +1 -1
  35. package/cjs/filter/ast/terms/time-literal.js +1 -1
  36. package/cjs/filter/errors.js +3 -3
  37. package/esm/document/data-type/builtin/approx-date.type.js +3 -3
  38. package/esm/document/data-type/builtin/approx-datetime.type.js +2 -2
  39. package/esm/document/data-type/builtin/base64.type.js +2 -2
  40. package/esm/document/data-type/builtin/bigint.type.js +3 -3
  41. package/esm/document/data-type/builtin/boolean.type.js +2 -2
  42. package/esm/document/data-type/builtin/date.type.js +3 -3
  43. package/esm/document/data-type/builtin/datetime.type.js +3 -3
  44. package/esm/document/data-type/builtin/email.type.js +3 -3
  45. package/esm/document/data-type/builtin/integer.type.js +2 -2
  46. package/esm/document/data-type/builtin/null.type.js +2 -2
  47. package/esm/document/data-type/builtin/number.type.js +2 -2
  48. package/esm/document/data-type/builtin/object-id.type.js +3 -3
  49. package/esm/document/data-type/builtin/string.type.js +2 -2
  50. package/esm/document/data-type/builtin/time.type.js +3 -3
  51. package/esm/document/data-type/builtin/url.type.js +2 -2
  52. package/esm/document/data-type/builtin/uuid.type.js +2 -2
  53. package/esm/document/data-type/complex-type-class.js +1 -1
  54. package/esm/document/data-type/enum-type-class.js +3 -2
  55. package/esm/document/data-type/field-class.js +8 -5
  56. package/esm/document/data-type/simple-type-class.js +3 -3
  57. package/esm/document/resource/action.js +2 -2
  58. package/esm/document/resource/collection-class.js +1 -1
  59. package/esm/document/resource/container-class.js +2 -2
  60. package/esm/document/resource/crud-operation.js +1 -1
  61. package/esm/document/resource/parameter.js +1 -1
  62. package/esm/exception/index.js +2 -2
  63. package/esm/exception/resource-errors/permission.error.js +17 -0
  64. package/esm/exception/resource-errors/resource-conflict.error.js +1 -1
  65. package/esm/exception/resource-errors/resource-not-found.error.js +2 -2
  66. package/esm/exception/resource-errors/resource-not.available.error.js +20 -0
  67. package/esm/exception/resource-errors/resource-not.available.js +20 -0
  68. package/esm/filter/ast/terms/date-literal.js +2 -2
  69. package/esm/filter/ast/terms/number-literal.js +2 -2
  70. package/esm/filter/ast/terms/time-literal.js +2 -2
  71. package/esm/filter/errors.js +1 -1
  72. package/package.json +3 -3
  73. package/types/document/data-type/complex-type-class.d.ts +4 -4
  74. package/types/document/data-type/data-type.d.ts +3 -3
  75. package/types/document/data-type/enum-type-class.d.ts +4 -4
  76. package/types/document/data-type/field-class.d.ts +3 -3
  77. package/types/document/data-type/field.d.ts +6 -3
  78. package/types/document/data-type/simple-type-class.d.ts +4 -4
  79. package/types/document/data-type/simple-type.d.ts +7 -7
  80. package/types/document/resource/action.d.ts +2 -2
  81. package/types/document/resource/crud-operation.d.ts +3 -3
  82. package/types/document/resource/parameter.d.ts +6 -6
  83. package/types/exception/index.d.ts +2 -2
  84. package/types/exception/resource-errors/permission.error.d.ts +11 -0
  85. package/types/exception/resource-errors/resource-not.available.d.ts +8 -0
  86. package/types/exception/resource-errors/resource-not.available.error.d.ts +8 -0
  87. package/types/filter/errors.d.ts +1 -1
  88. package/types/helpers/object-utils.d.ts +2 -2
  89. package/types/schema/data-type/complex-type.interface.d.ts +1 -1
  90. package/types/schema/data-type/field.interface.d.ts +4 -1
  91. package/types/schema/data-type/mapped-type.interface.d.ts +1 -1
  92. package/types/schema/data-type/simple-type.interface.d.ts +3 -3
  93. package/types/types.d.ts +5 -26
  94. package/cjs/exception/common-errors/validation.error.js +0 -11
  95. package/esm/exception/common-errors/validation.error.js +0 -7
  96. 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 };
@@ -6,8 +6,8 @@ let UuidType = class UuidType {
6
6
  UuidType = __decorate([
7
7
  SimpleType({
8
8
  description: 'A Universal Unique Identifier (UUID) value',
9
- decoder: isUUID(),
10
- encoder: isUUID()
9
+ decoder: isUUID,
10
+ encoder: isUUID
11
11
  })
12
12
  ], UuidType);
13
13
  export { UuidType };
@@ -1,4 +1,4 @@
1
- import * as vg from 'valgen';
1
+ import { vg } from 'valgen';
2
2
  import { omitUndefined, ResponsiveMap } from '../../helpers/index.js';
3
3
  import { translate } from '../../i18n/index.js';
4
4
  import { OpraSchema } from '../../schema/index.js';
@@ -1,4 +1,4 @@
1
- import * as vg from 'valgen';
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] === this.enumObject?.[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 * as vg from 'valgen';
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.format = init.format;
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
- format: this.format,
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 vg.isUndefined();
49
+ return isUndefined;
49
50
  if (options?.operation === 'write' && this.readonly)
50
- return vg.isUndefined();
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 * as vg from 'valgen';
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 || vg.isAny();
14
- this.encode = init.encoder || init.base?.encode || vg.isAny();
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 * as vg from 'valgen';
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 = vg.isAny();
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 * as vg from 'valgen';
1
+ import { vg } from 'valgen';
2
2
  import { BadRequestError } from '../../exception/index.js';
3
3
  import { OpraFilter } from '../../filter/index.js';
4
4
  import { translate } from '../../i18n/index.js';
@@ -1,4 +1,4 @@
1
- import { NotAcceptableError, ResourceNotFoundError } from '../../exception/index.js';
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 ResourceNotFoundError(path);
44
+ throw new ResourceNotAvailableError(path);
45
45
  }
46
46
  getContainer(path, silent) {
47
47
  const t = this.getResource(path);
@@ -1,4 +1,4 @@
1
- import * as vg from 'valgen';
1
+ import { vg } from 'valgen';
2
2
  import { DataType } from '../data-type/data-type.js';
3
3
  import { ApiField } from '../data-type/field.js';
4
4
  import { Endpoint } from './endpoint.js';
@@ -1,4 +1,4 @@
1
- import * as vg from 'valgen';
1
+ import { vg } from 'valgen';
2
2
  import { omitUndefined } from '../../helpers/index.js';
3
3
  /**
4
4
  *
@@ -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-found.error.js';
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 field values ({{fields}})`),
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:RESOURCE_NOT_FOUND`, `Resource not found`),
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: 'RESOURCE_NOT_FOUND',
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 { ValidationError } from '../../errors.js';
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 ValidationError(`Invalid date value "${value}"`);
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 { ValidationError } from '../../errors.js';
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 ValidationError(`Invalid number literal ${value}`);
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 { ValidationError } from '../../errors.js';
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 ValidationError(`Invalid time value "${value}"`);
20
+ throw new FilterValidationError(`Invalid time value "${value}"`);
21
21
  }
22
22
  toString() {
23
23
  return quoteFilterString(this.value);
@@ -1,6 +1,6 @@
1
1
  export class SyntaxError extends TypeError {
2
2
  }
3
- export class ValidationError extends TypeError {
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.32.6",
3
+ "version": "0.33.0",
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": "^4.3.2"
49
+ "valgen": "^5.0.0"
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": "^2.9.3"
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 * as vg from 'valgen';
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): vg.ObjectValidator<T>;
33
- generateCodecSchema(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): vg.ObjectSchema;
34
- protected _generateCodecSchema(codec: 'decode' | 'encode', options?: RequiredSome<DataType.GenerateCodecOptions, 'pick' | 'omit'>): vg.ObjectSchema;
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 * as vg from 'valgen';
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): vg.Validator;
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?: vg.OnFailFunction;
55
+ onFail?: OnFailFunction;
56
56
  }
57
57
  }
@@ -1,4 +1,4 @@
1
- import * as vg from 'valgen';
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: vg.Validator;
13
- readonly encode: vg.Validator;
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'): vg.Validator;
17
+ generateCodec(codec: 'decode' | 'encode'): Validator;
18
18
  }
@@ -1,5 +1,5 @@
1
1
  import { Type } from 'ts-gems';
2
- import * as vg from 'valgen';
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
- format?: string;
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): vg.Validator;
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 * as vg from 'valgen';
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: vg.Validator;
13
- readonly encode: vg.Validator;
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'): vg.Validator;
18
+ generateCodec(codec: 'decode' | 'encode'): Validator;
19
19
  }
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import * as vg from 'valgen';
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?: vg.Validator;
24
- encoder?: vg.Validator;
23
+ decoder?: Validator;
24
+ encoder?: Validator;
25
25
  }
26
26
  interface DecoratorOptions extends DataType.DecoratorOptions {
27
- decoder?: vg.Validator;
28
- encoder?: vg.Validator;
27
+ decoder?: Validator;
28
+ encoder?: Validator;
29
29
  }
30
30
  interface Metadata extends DataType.Metadata {
31
- decoder?: vg.Validator;
32
- encoder?: vg.Validator;
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 * as vg from 'valgen';
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: vg.Validator;
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 * as vg from 'valgen';
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: vg.Validator;
17
+ decodeInput: Validator;
18
18
  returnType: DataType;
19
- encodeReturning: vg.Validator;
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 * as vg from 'valgen';
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: vg.Validator;
12
- protected _encoder: vg.Validator;
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(): vg.Validator;
27
- getEncoder(): vg.Validator;
28
- generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): vg.Validator;
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-found.error.js';
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
+ }
@@ -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 ValidationError extends TypeError {
5
+ export declare class FilterValidationError extends TypeError {
6
6
  constructor(message?: string | {
7
7
  message?: string;
8
8
  });
@@ -1,4 +1,4 @@
1
- import { HighDeepRemoveNulls } from 'ts-gems';
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): HighDeepRemoveNulls<T>;
4
+ export declare function omitNullish<T>(obj: T, recursive?: boolean): DeeperOmitTypes<T, null | undefined>;