@opra/common 0.31.1 → 0.31.4

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 (60) hide show
  1. package/browser.js +150 -108
  2. package/cjs/document/data-type/builtin/any.type.js +2 -1
  3. package/cjs/document/data-type/builtin/approx-date.type.js +21 -0
  4. package/cjs/document/data-type/builtin/approx-datetime.type.js +24 -0
  5. package/cjs/document/data-type/builtin/base64.type.js +2 -1
  6. package/cjs/document/data-type/builtin/bigint.type.js +2 -1
  7. package/cjs/document/data-type/builtin/boolean.type.js +2 -1
  8. package/cjs/document/data-type/builtin/date.type.js +6 -11
  9. package/cjs/document/data-type/builtin/datetime.type.js +21 -0
  10. package/cjs/document/data-type/builtin/index.js +3 -1
  11. package/cjs/document/data-type/builtin/integer.type.js +2 -1
  12. package/cjs/document/data-type/builtin/null.type.js +2 -1
  13. package/cjs/document/data-type/builtin/number.type.js +2 -1
  14. package/cjs/document/data-type/builtin/object-id.type.js +2 -1
  15. package/cjs/document/data-type/builtin/object.type.js +2 -1
  16. package/cjs/document/data-type/builtin/string.type.js +2 -1
  17. package/cjs/document/data-type/builtin/time.type.js +7 -4
  18. package/cjs/document/data-type/builtin/uuid.type.js +2 -1
  19. package/cjs/document/data-type/complex-type-class.js +2 -0
  20. package/cjs/document/data-type/data-type.js +2 -1
  21. package/cjs/document/data-type/field-class.js +7 -5
  22. package/cjs/document/factory/type-document-factory.js +3 -6
  23. package/cjs/document/resource/types/operation-result.type.js +2 -1
  24. package/cjs/document/type-document.js +1 -1
  25. package/esm/document/data-type/builtin/any.type.js +2 -1
  26. package/esm/document/data-type/builtin/approx-date.type.js +18 -0
  27. package/esm/document/data-type/builtin/approx-datetime.type.js +21 -0
  28. package/esm/document/data-type/builtin/base64.type.js +2 -1
  29. package/esm/document/data-type/builtin/bigint.type.js +2 -1
  30. package/esm/document/data-type/builtin/boolean.type.js +2 -1
  31. package/esm/document/data-type/builtin/date.type.js +6 -11
  32. package/esm/document/data-type/builtin/datetime.type.js +18 -0
  33. package/esm/document/data-type/builtin/index.js +3 -1
  34. package/esm/document/data-type/builtin/integer.type.js +2 -1
  35. package/esm/document/data-type/builtin/null.type.js +2 -1
  36. package/esm/document/data-type/builtin/number.type.js +2 -1
  37. package/esm/document/data-type/builtin/object-id.type.js +2 -1
  38. package/esm/document/data-type/builtin/object.type.js +2 -1
  39. package/esm/document/data-type/builtin/string.type.js +2 -1
  40. package/esm/document/data-type/builtin/time.type.js +8 -5
  41. package/esm/document/data-type/builtin/uuid.type.js +2 -1
  42. package/esm/document/data-type/complex-type-class.js +2 -0
  43. package/esm/document/data-type/data-type.js +2 -1
  44. package/esm/document/data-type/field-class.js +7 -5
  45. package/esm/document/factory/type-document-factory.js +4 -7
  46. package/esm/document/resource/types/operation-result.type.js +2 -1
  47. package/esm/document/type-document.js +1 -1
  48. package/package.json +5 -5
  49. package/types/document/data-type/builtin/approx-date.type.d.ts +2 -0
  50. package/types/document/data-type/builtin/approx-datetime.type.d.ts +2 -0
  51. package/types/document/data-type/builtin/datetime.type.d.ts +2 -0
  52. package/types/document/data-type/builtin/index.d.ts +3 -1
  53. package/types/document/data-type/complex-type.d.ts +2 -0
  54. package/types/document/data-type/data-type.d.ts +4 -2
  55. package/types/document/data-type/field-class.d.ts +2 -1
  56. package/types/document/data-type/field.d.ts +1 -0
  57. package/types/schema/data-type/field.interface.d.ts +0 -4
  58. package/cjs/document/data-type/builtin/timestamp.type.js +0 -17
  59. package/esm/document/data-type/builtin/timestamp.type.js +0 -14
  60. package/types/document/data-type/builtin/timestamp.type.d.ts +0 -2
@@ -24,12 +24,14 @@ class ComplexTypeClass extends data_type_js_1.DataType {
24
24
  own.ctor = own.ctor || init.base.ctor;
25
25
  }
26
26
  own.additionalFields = init?.additionalFields;
27
+ own.anonymous = init?.anonymous;
27
28
  own.fields = new index_js_1.ResponsiveMap();
28
29
  this.kind = index_js_3.OpraSchema.ComplexType.Kind;
29
30
  this.base = init?.base;
30
31
  this.ctor = own.ctor || Object;
31
32
  this.abstract = init.abstract;
32
33
  this.additionalFields = own.additionalFields;
34
+ this.isAnonymous = this.isAnonymous || init.anonymous;
33
35
  if (this.base?.additionalFields === true && this.additionalFields !== true)
34
36
  this.additionalFields = true;
35
37
  else if (this.base?.additionalFields === 'error' && !this.additionalFields)
@@ -13,7 +13,8 @@ class DataType {
13
13
  this.name = init?.name;
14
14
  this.own = {};
15
15
  this.description = init?.description;
16
- this.isAnonymous = !this.name;
16
+ if (!this.name)
17
+ this.isAnonymous = true;
17
18
  }
18
19
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
19
20
  exportSchema(options) {
@@ -9,13 +9,13 @@ class FieldClass {
9
9
  this.owner = owner;
10
10
  this.origin = init.origin || owner;
11
11
  this.type = init.type;
12
+ this.designType = init.designType;
12
13
  this.name = init.name;
13
14
  this.description = init.description;
14
15
  this.isArray = init.isArray;
15
16
  this.default = init.default;
16
17
  this.fixed = init.fixed;
17
18
  this.required = init.required;
18
- this.nullish = init.nullish;
19
19
  this.readonly = init.readonly;
20
20
  this.writeonly = init.writeonly;
21
21
  this.exclusive = init.exclusive;
@@ -24,15 +24,17 @@ class FieldClass {
24
24
  this.format = init.format;
25
25
  }
26
26
  exportSchema(options) {
27
+ const isAnonymous = !this.type.name ||
28
+ (this.type.kind === 'ComplexType' && this.type.isAnonymous);
27
29
  return (0, index_js_1.omitUndefined)({
28
- type: this.type ?
29
- (this.type.name ? this.type.name : this.type.exportSchema(options)) : undefined,
30
+ type: this.type
31
+ ? (isAnonymous ? this.type.exportSchema(options) : this.type.name)
32
+ : undefined,
30
33
  description: this.description,
31
34
  isArray: this.isArray,
32
35
  default: this.default,
33
36
  fixed: this.fixed,
34
37
  required: this.required,
35
- nullish: this.nullish,
36
38
  readonly: this.readonly,
37
39
  writeonly: this.writeonly,
38
40
  exclusive: this.exclusive,
@@ -46,7 +48,7 @@ class FieldClass {
46
48
  return vg.isUndefined();
47
49
  if (options?.operation === 'write' && this.readonly)
48
50
  return vg.isUndefined();
49
- let fn = this.type.generateCodec(codec, options);
51
+ let fn = this.type.generateCodec(codec, { ...options, designType: this.designType });
50
52
  if (this.isArray)
51
53
  fn = vg.isArray(fn);
52
54
  return !options?.partial && this.required ? vg.required(fn) : vg.optional(fn);
@@ -11,8 +11,6 @@ const enum_type_js_1 = require("../data-type/enum-type.js");
11
11
  const mapped_type_js_1 = require("../data-type/mapped-type.js");
12
12
  const mixin_type_js_1 = require("../data-type/mixin-type.js");
13
13
  const simple_type_js_1 = require("../data-type/simple-type.js");
14
- const metadata_mode_enum_js_1 = require("../resource/enums/metadata-mode.enum.js");
15
- const operation_result_type_js_1 = require("../resource/types/operation-result.type.js");
16
14
  const type_document_js_1 = require("../type-document.js");
17
15
  /**
18
16
  * @class TypeDocumentFactory
@@ -99,10 +97,9 @@ class TypeDocumentFactory {
99
97
  }
100
98
  },
101
99
  types: [index_js_3.AnyType, index_js_3.Base64Type, index_js_3.BigintType, index_js_3.BooleanType,
102
- index_js_3.DateType, index_js_3.UuidType, index_js_3.IntegerType, index_js_3.NullType,
103
- index_js_3.NumberType, index_js_3.ObjectType, index_js_3.ObjectIdType, index_js_3.StringType,
104
- index_js_3.TimeType, index_js_3.TimestampType,
105
- operation_result_type_js_1.OperationResult, metadata_mode_enum_js_1.MetadataMode,
100
+ index_js_3.DateType, index_js_3.IntegerType, index_js_3.NullType, index_js_3.NumberType, index_js_3.ObjectIdType,
101
+ index_js_3.ObjectType, index_js_3.ApproxDateType, index_js_3.ApproxDatetimeType,
102
+ index_js_3.StringType, index_js_3.DatetimeType, index_js_3.TimeType, index_js_3.UuidType
106
103
  ]
107
104
  };
108
105
  const factory = new TypeDocumentFactory();
@@ -4,12 +4,13 @@ exports.OperationResult = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const complex_type_js_1 = require("../../data-type/complex-type.js");
6
6
  const field_js_1 = require("../../data-type/field.js");
7
- let OperationResult = exports.OperationResult = class OperationResult {
7
+ let OperationResult = class OperationResult {
8
8
  constructor(init) {
9
9
  if (init)
10
10
  Object.assign(this, init);
11
11
  }
12
12
  };
13
+ exports.OperationResult = OperationResult;
13
14
  tslib_1.__decorate([
14
15
  (0, field_js_1.ApiField)()
15
16
  ], OperationResult.prototype, "context", void 0);
@@ -23,7 +23,7 @@ class TypeDocument extends document_base_js_1.DocumentBase {
23
23
  this._designCtorMap.set(Number, 'number');
24
24
  this._designCtorMap.set(Boolean, 'boolean');
25
25
  this._designCtorMap.set(Object, 'any');
26
- this._designCtorMap.set(Date, 'timestamp');
26
+ this._designCtorMap.set(Date, 'datetime');
27
27
  this._designCtorMap.set(BigIntConstructor, 'bigint');
28
28
  this._designCtorMap.set(ArrayBuffer, 'base64');
29
29
  this._designCtorMap.set(SharedArrayBuffer, 'base64');
@@ -1,9 +1,10 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { SimpleType } from '../simple-type.js';
3
- export let AnyType = class AnyType {
3
+ let AnyType = class AnyType {
4
4
  };
5
5
  AnyType = __decorate([
6
6
  SimpleType({
7
7
  description: 'Represents any value'
8
8
  })
9
9
  ], AnyType);
10
+ export { AnyType };
@@ -0,0 +1,18 @@
1
+ import { __decorate } from "tslib";
2
+ import { isDateString } from 'valgen';
3
+ import { SimpleType } from '../simple-type.js';
4
+ let ApproxDateType = class ApproxDateType {
5
+ };
6
+ ApproxDateType = __decorate([
7
+ SimpleType({
8
+ description: 'An approximate date value',
9
+ example: [
10
+ '2021-04-18',
11
+ '2021-04',
12
+ '2021',
13
+ ],
14
+ decoder: isDateString({ trim: 'date' }),
15
+ encoder: isDateString({ trim: 'date' })
16
+ })
17
+ ], ApproxDateType);
18
+ export { ApproxDateType };
@@ -0,0 +1,21 @@
1
+ import { __decorate } from "tslib";
2
+ import { isDateString } from 'valgen';
3
+ import { SimpleType } from '../simple-type.js';
4
+ let ApproxDatetimeType = class ApproxDatetimeType {
5
+ };
6
+ ApproxDatetimeType = __decorate([
7
+ SimpleType({
8
+ description: 'An approximate datetime value.',
9
+ example: [
10
+ '2021-04-18T22:30:15+01:00',
11
+ '2021-04-18T22:30:15',
12
+ '2021-04-18 22:30',
13
+ '2021-04-18',
14
+ '2021-04',
15
+ '2021',
16
+ ],
17
+ decoder: isDateString(),
18
+ encoder: isDateString()
19
+ })
20
+ ], ApproxDatetimeType);
21
+ export { ApproxDatetimeType };
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { isBase64 } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let Base64Type = class Base64Type {
4
+ let Base64Type = class Base64Type {
5
5
  };
6
6
  Base64Type = __decorate([
7
7
  SimpleType({
@@ -10,3 +10,4 @@ Base64Type = __decorate([
10
10
  encoder: isBase64(),
11
11
  })
12
12
  ], Base64Type);
13
+ export { Base64Type };
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { isBigint, isString, pipe } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let BigintType = class BigintType {
4
+ let BigintType = class BigintType {
5
5
  };
6
6
  BigintType = __decorate([
7
7
  SimpleType({
@@ -10,3 +10,4 @@ BigintType = __decorate([
10
10
  encoder: pipe(isBigint(), isString())
11
11
  })
12
12
  ], BigintType);
13
+ export { BigintType };
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { isBoolean } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let BooleanType = class BooleanType {
4
+ let BooleanType = class BooleanType {
5
5
  };
6
6
  BooleanType = __decorate([
7
7
  SimpleType({
@@ -10,3 +10,4 @@ BooleanType = __decorate([
10
10
  encoder: isBoolean()
11
11
  })
12
12
  ], BooleanType);
13
+ export { BooleanType };
@@ -1,19 +1,14 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { isDate, isDateString } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let DateType = class DateType {
4
+ let DateType = class DateType {
5
5
  };
6
6
  DateType = __decorate([
7
7
  SimpleType({
8
- description: 'Date only string, for example, 2021-04-18',
9
- decoder: isDate({
10
- format: ['YYYY-MM-DD', 'YYYY',
11
- 'YYYY-MM-DDTHH:mm:ss',
12
- 'YYYY-MM-DDTHH:mm',
13
- 'YYYY-MM-DD HH:mm:ss',
14
- 'YYYY-MM-DD HH:mm'
15
- ]
16
- }),
17
- encoder: isDateString({ format: 'YYYY-MM-DD' })
8
+ description: 'A date without time',
9
+ example: ['2021-04-18'],
10
+ decoder: isDate({ precision: 'date' }),
11
+ encoder: isDateString({ precision: 'date', trim: 'date' })
18
12
  })
19
13
  ], DateType);
14
+ export { DateType };
@@ -0,0 +1,18 @@
1
+ import { __decorate } from "tslib";
2
+ import { isDate, isDateString } from 'valgen';
3
+ import { SimpleType } from '../simple-type.js';
4
+ let DatetimeType = class DatetimeType {
5
+ };
6
+ DatetimeType = __decorate([
7
+ SimpleType({
8
+ description: 'A full datetime value',
9
+ example: [
10
+ '2021-04-18T22:30:15',
11
+ '2021-04-18 22:30:15',
12
+ '2021-04-18 22:30'
13
+ ],
14
+ decoder: isDate({ precision: 'time' }),
15
+ encoder: isDateString({ precision: 'time', trim: 'time' })
16
+ })
17
+ ], DatetimeType);
18
+ export { DatetimeType };
@@ -1,8 +1,11 @@
1
1
  export * from './any.type.js';
2
+ export * from './approx-date.type.js';
3
+ export * from './approx-datetime.type.js';
2
4
  export * from './base64.type.js';
3
5
  export * from './bigint.type.js';
4
6
  export * from './boolean.type.js';
5
7
  export * from './date.type.js';
8
+ export * from './datetime.type.js';
6
9
  export * from './uuid.type.js';
7
10
  export * from './integer.type.js';
8
11
  export * from './null.type.js';
@@ -11,4 +14,3 @@ export * from './object.type.js';
11
14
  export * from './object-id.type.js';
12
15
  export * from './string.type.js';
13
16
  export * from './time.type.js';
14
- export * from './timestamp.type.js';
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { isInteger } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let IntegerType = class IntegerType {
4
+ let IntegerType = class IntegerType {
5
5
  };
6
6
  IntegerType = __decorate([
7
7
  SimpleType({
@@ -10,3 +10,4 @@ IntegerType = __decorate([
10
10
  encoder: isInteger()
11
11
  })
12
12
  ], IntegerType);
13
+ export { IntegerType };
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { isNull } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let NullType = class NullType {
4
+ let NullType = class NullType {
5
5
  };
6
6
  NullType = __decorate([
7
7
  SimpleType({
@@ -10,3 +10,4 @@ NullType = __decorate([
10
10
  encoder: isNull()
11
11
  })
12
12
  ], NullType);
13
+ export { NullType };
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { isNumber } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let NumberType = class NumberType {
4
+ let NumberType = class NumberType {
5
5
  };
6
6
  NumberType = __decorate([
7
7
  SimpleType({
@@ -10,3 +10,4 @@ NumberType = __decorate([
10
10
  encoder: isNumber()
11
11
  })
12
12
  ], NumberType);
13
+ export { NumberType };
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { isObjectId, isString, pipe } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let ObjectIdType = class ObjectIdType {
4
+ let ObjectIdType = class ObjectIdType {
5
5
  };
6
6
  ObjectIdType = __decorate([
7
7
  SimpleType({
@@ -10,3 +10,4 @@ ObjectIdType = __decorate([
10
10
  encoder: pipe(isObjectId(), isString())
11
11
  })
12
12
  ], ObjectIdType);
13
+ export { ObjectIdType };
@@ -1,6 +1,6 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { ComplexType } from '../complex-type.js';
3
- export let ObjectType = class ObjectType {
3
+ let ObjectType = class ObjectType {
4
4
  };
5
5
  ObjectType = __decorate([
6
6
  ComplexType({
@@ -10,3 +10,4 @@ ObjectType = __decorate([
10
10
  ctor: Object
11
11
  })
12
12
  ], ObjectType);
13
+ export { ObjectType };
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { isString } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let StringType = class StringType {
4
+ let StringType = class StringType {
5
5
  };
6
6
  StringType = __decorate([
7
7
  SimpleType({
@@ -10,3 +10,4 @@ StringType = __decorate([
10
10
  encoder: isString(),
11
11
  })
12
12
  ], StringType);
13
+ export { StringType };
@@ -1,17 +1,20 @@
1
1
  import { __decorate } from "tslib";
2
- import { isDateString } from 'valgen';
2
+ import { isMatches } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let TimeType = class TimeType {
4
+ const TIME_PATTERN = /^([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?$/;
5
+ let TimeType = class TimeType {
5
6
  };
6
7
  TimeType = __decorate([
7
8
  SimpleType({
8
9
  description: 'Time string in 24h format, for example, 18:23:00',
9
- decoder: isDateString({
10
- format: ['HH:mm:ss', 'HH:mm'],
10
+ decoder: isMatches(TIME_PATTERN, {
11
+ formatName: 'time',
11
12
  onFail: () => '{{label}} is not a valid time'
12
13
  }),
13
- encoder: isDateString({ format: ['HH:mm:ss', 'HH:mm'],
14
+ encoder: isMatches(TIME_PATTERN, {
15
+ formatName: 'time',
14
16
  onFail: () => '{{label}} is not a valid time'
15
17
  })
16
18
  })
17
19
  ], TimeType);
20
+ export { TimeType };
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { isUUID } from 'valgen';
3
3
  import { SimpleType } from '../simple-type.js';
4
- export let UuidType = class UuidType {
4
+ let UuidType = class UuidType {
5
5
  };
6
6
  UuidType = __decorate([
7
7
  SimpleType({
@@ -10,3 +10,4 @@ UuidType = __decorate([
10
10
  encoder: isUUID()
11
11
  })
12
12
  ], UuidType);
13
+ export { UuidType };
@@ -20,12 +20,14 @@ export class ComplexTypeClass extends DataType {
20
20
  own.ctor = own.ctor || init.base.ctor;
21
21
  }
22
22
  own.additionalFields = init?.additionalFields;
23
+ own.anonymous = init?.anonymous;
23
24
  own.fields = new ResponsiveMap();
24
25
  this.kind = OpraSchema.ComplexType.Kind;
25
26
  this.base = init?.base;
26
27
  this.ctor = own.ctor || Object;
27
28
  this.abstract = init.abstract;
28
29
  this.additionalFields = own.additionalFields;
30
+ this.isAnonymous = this.isAnonymous || init.anonymous;
29
31
  if (this.base?.additionalFields === true && this.additionalFields !== true)
30
32
  this.additionalFields = true;
31
33
  else if (this.base?.additionalFields === 'error' && !this.additionalFields)
@@ -10,7 +10,8 @@ export class DataType {
10
10
  this.name = init?.name;
11
11
  this.own = {};
12
12
  this.description = init?.description;
13
- this.isAnonymous = !this.name;
13
+ if (!this.name)
14
+ this.isAnonymous = true;
14
15
  }
15
16
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
17
  exportSchema(options) {
@@ -5,13 +5,13 @@ export class FieldClass {
5
5
  this.owner = owner;
6
6
  this.origin = init.origin || owner;
7
7
  this.type = init.type;
8
+ this.designType = init.designType;
8
9
  this.name = init.name;
9
10
  this.description = init.description;
10
11
  this.isArray = init.isArray;
11
12
  this.default = init.default;
12
13
  this.fixed = init.fixed;
13
14
  this.required = init.required;
14
- this.nullish = init.nullish;
15
15
  this.readonly = init.readonly;
16
16
  this.writeonly = init.writeonly;
17
17
  this.exclusive = init.exclusive;
@@ -20,15 +20,17 @@ export class FieldClass {
20
20
  this.format = init.format;
21
21
  }
22
22
  exportSchema(options) {
23
+ const isAnonymous = !this.type.name ||
24
+ (this.type.kind === 'ComplexType' && this.type.isAnonymous);
23
25
  return omitUndefined({
24
- type: this.type ?
25
- (this.type.name ? this.type.name : this.type.exportSchema(options)) : undefined,
26
+ type: this.type
27
+ ? (isAnonymous ? this.type.exportSchema(options) : this.type.name)
28
+ : undefined,
26
29
  description: this.description,
27
30
  isArray: this.isArray,
28
31
  default: this.default,
29
32
  fixed: this.fixed,
30
33
  required: this.required,
31
- nullish: this.nullish,
32
34
  readonly: this.readonly,
33
35
  writeonly: this.writeonly,
34
36
  exclusive: this.exclusive,
@@ -42,7 +44,7 @@ export class FieldClass {
42
44
  return vg.isUndefined();
43
45
  if (options?.operation === 'write' && this.readonly)
44
46
  return vg.isUndefined();
45
- let fn = this.type.generateCodec(codec, options);
47
+ let fn = this.type.generateCodec(codec, { ...options, designType: this.designType });
46
48
  if (this.isArray)
47
49
  fn = vg.isArray(fn);
48
50
  return !options?.partial && this.required ? vg.required(fn) : vg.optional(fn);
@@ -2,14 +2,12 @@ import { validator } from 'valgen';
2
2
  import { cloneObject, isConstructor, resolveThunk, ResponsiveMap } from '../../helpers/index.js';
3
3
  import { OpraSchema } from '../../schema/index.js';
4
4
  import { DATATYPE_METADATA } from '../constants.js';
5
- import { AnyType, Base64Type, BigintType, BooleanType, DateType, IntegerType, NullType, NumberType, ObjectIdType, ObjectType, StringType, TimestampType, TimeType, UuidType } from '../data-type/builtin/index.js';
5
+ import { AnyType, ApproxDatetimeType, ApproxDateType, Base64Type, BigintType, BooleanType, DatetimeType, DateType, IntegerType, NullType, NumberType, ObjectIdType, ObjectType, StringType, TimeType, UuidType } from '../data-type/builtin/index.js';
6
6
  import { ComplexType } from '../data-type/complex-type.js';
7
7
  import { EnumType } from '../data-type/enum-type.js';
8
8
  import { MappedType } from '../data-type/mapped-type.js';
9
9
  import { MixinType } from '../data-type/mixin-type.js';
10
10
  import { SimpleType } from '../data-type/simple-type.js';
11
- import { MetadataMode } from '../resource/enums/metadata-mode.enum.js';
12
- import { OperationResult } from '../resource/types/operation-result.type.js';
13
11
  import { TypeDocument } from '../type-document.js';
14
12
  /**
15
13
  * @class TypeDocumentFactory
@@ -96,10 +94,9 @@ export class TypeDocumentFactory {
96
94
  }
97
95
  },
98
96
  types: [AnyType, Base64Type, BigintType, BooleanType,
99
- DateType, UuidType, IntegerType, NullType,
100
- NumberType, ObjectType, ObjectIdType, StringType,
101
- TimeType, TimestampType,
102
- OperationResult, MetadataMode,
97
+ DateType, IntegerType, NullType, NumberType, ObjectIdType,
98
+ ObjectType, ApproxDateType, ApproxDatetimeType,
99
+ StringType, DatetimeType, TimeType, UuidType
103
100
  ]
104
101
  };
105
102
  const factory = new TypeDocumentFactory();
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { ComplexType } from '../../data-type/complex-type.js';
3
3
  import { ApiField } from '../../data-type/field.js';
4
- export let OperationResult = class OperationResult {
4
+ let OperationResult = class OperationResult {
5
5
  constructor(init) {
6
6
  if (init)
7
7
  Object.assign(this, init);
@@ -39,3 +39,4 @@ OperationResult = __decorate([
39
39
  description: 'Operation result'
40
40
  })
41
41
  ], OperationResult);
42
+ export { OperationResult };
@@ -20,7 +20,7 @@ export class TypeDocument extends DocumentBase {
20
20
  this._designCtorMap.set(Number, 'number');
21
21
  this._designCtorMap.set(Boolean, 'boolean');
22
22
  this._designCtorMap.set(Object, 'any');
23
- this._designCtorMap.set(Date, 'timestamp');
23
+ this._designCtorMap.set(Date, 'datetime');
24
24
  this._designCtorMap.set(BigIntConstructor, 'bigint');
25
25
  this._designCtorMap.set(ArrayBuffer, 'base64');
26
26
  this._designCtorMap.set(SharedArrayBuffer, 'base64');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "0.31.1",
3
+ "version": "0.31.4",
4
4
  "description": "Opra common package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -45,15 +45,15 @@
45
45
  "putil-varhelpers": "^1.6.5",
46
46
  "reflect-metadata": "^0.1.13",
47
47
  "uid": "^2.0.1",
48
- "valgen": "^4.1.0"
48
+ "valgen": "^4.2.2"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@browsery/fs": "^0.4.0",
52
52
  "@browsery/stream": "^0.6.0",
53
53
  "@browsery/util": "^0.4.0",
54
- "@types/encodeurl": "^1.0.0",
55
- "@types/validator": "^13.11.3",
56
- "@types/lodash.omit": "^4.5.8",
54
+ "@types/encodeurl": "^1.0.2",
55
+ "@types/lodash.omit": "^4.5.9",
56
+ "@types/validator": "^13.11.6",
57
57
  "path-browserify": "^1.0.1",
58
58
  "ts-gems": "^2.5.0"
59
59
  },
@@ -0,0 +1,2 @@
1
+ export declare class ApproxDateType {
2
+ }
@@ -0,0 +1,2 @@
1
+ export declare class ApproxDatetimeType {
2
+ }
@@ -0,0 +1,2 @@
1
+ export declare class DatetimeType {
2
+ }
@@ -1,8 +1,11 @@
1
1
  export * from './any.type.js';
2
+ export * from './approx-date.type.js';
3
+ export * from './approx-datetime.type.js';
2
4
  export * from './base64.type.js';
3
5
  export * from './bigint.type.js';
4
6
  export * from './boolean.type.js';
5
7
  export * from './date.type.js';
8
+ export * from './datetime.type.js';
6
9
  export * from './uuid.type.js';
7
10
  export * from './integer.type.js';
8
11
  export * from './null.type.js';
@@ -11,4 +14,3 @@ export * from './object.type.js';
11
14
  export * from './object-id.type.js';
12
15
  export * from './string.type.js';
13
16
  export * from './time.type.js';
14
- export * from './timestamp.type.js';
@@ -32,11 +32,13 @@ export declare namespace ComplexType {
32
32
  base?: ComplexType | MappedType | MixinType;
33
33
  fields?: Record<string, ApiField.InitArguments>;
34
34
  additionalFields?: boolean | DataType | 'error';
35
+ anonymous?: boolean;
35
36
  }
36
37
  interface OwnProperties extends DataType.OwnProperties {
37
38
  ctor?: Type;
38
39
  additionalFields?: boolean | DataType | 'error';
39
40
  fields: ResponsiveMap<ApiField>;
41
+ anonymous?: boolean;
40
42
  }
41
43
  interface DecoratorOptions extends DataType.DecoratorOptions, Pick<InitArguments, 'ctor' | 'abstract'> {
42
44
  anonymous?: boolean;
@@ -15,8 +15,8 @@ export declare abstract class DataType {
15
15
  readonly name?: string;
16
16
  readonly base?: DataType;
17
17
  readonly own: DataType.OwnProperties;
18
- readonly description?: string;
19
- readonly isAnonymous: boolean;
18
+ description?: string;
19
+ isAnonymous?: boolean;
20
20
  protected constructor(document: ApiDocument, init?: DataType.InitArguments);
21
21
  abstract generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): vg.Validator;
22
22
  exportSchema(options?: {
@@ -30,6 +30,7 @@ export declare namespace DataType {
30
30
  interface InitArguments {
31
31
  name?: string;
32
32
  description?: string;
33
+ example?: string | string[];
33
34
  }
34
35
  interface DecoratorOptions extends InitArguments {
35
36
  }
@@ -45,5 +46,6 @@ export declare namespace DataType {
45
46
  partial?: boolean;
46
47
  operation?: 'read' | 'write';
47
48
  overwriteFields?: ResponsiveMap<ApiField.InitArguments>;
49
+ designType?: Type;
48
50
  }
49
51
  }