@opra/common 1.17.7 → 1.19.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.
Files changed (43) hide show
  1. package/browser/index.cjs +5 -5
  2. package/browser/index.mjs +5 -5
  3. package/cjs/document/data-type/api-field.js +12 -5
  4. package/cjs/document/data-type/complex-type-base.js +2 -0
  5. package/cjs/document/data-type/extended-types/base64.type.js +16 -3
  6. package/cjs/document/data-type/extended-types/date-time-tz.type.js +63 -0
  7. package/cjs/document/data-type/extended-types/date-time.type.js +24 -18
  8. package/cjs/document/data-type/extended-types/date.type.js +25 -18
  9. package/cjs/document/data-type/extended-types/index.js +2 -2
  10. package/cjs/document/data-type/extended-types/partial-date.type.js +85 -0
  11. package/cjs/document/data-type/simple-type.js +4 -0
  12. package/cjs/document/decorators/api-field-decorator.js +1 -0
  13. package/cjs/document/factory/api-document.factory.js +5 -25
  14. package/cjs/document/factory/data-type.factory.js +1 -0
  15. package/cjs/filter/filter-rules.js +1 -1
  16. package/esm/document/data-type/api-field.js +12 -5
  17. package/esm/document/data-type/complex-type-base.js +2 -0
  18. package/esm/document/data-type/extended-types/base64.type.js +17 -4
  19. package/esm/document/data-type/extended-types/date-time-tz.type.js +60 -0
  20. package/esm/document/data-type/extended-types/date-time.type.js +25 -19
  21. package/esm/document/data-type/extended-types/date.type.js +26 -19
  22. package/esm/document/data-type/extended-types/index.js +2 -2
  23. package/esm/document/data-type/extended-types/partial-date.type.js +82 -0
  24. package/esm/document/data-type/simple-type.js +4 -0
  25. package/esm/document/decorators/api-field-decorator.js +1 -0
  26. package/esm/document/factory/api-document.factory.js +4 -25
  27. package/esm/document/factory/data-type.factory.js +1 -0
  28. package/esm/filter/filter-rules.js +1 -1
  29. package/package.json +3 -3
  30. package/types/document/data-type/api-field.d.ts +8 -0
  31. package/types/document/data-type/data-type.d.ts +1 -1
  32. package/types/document/data-type/extended-types/base64.type.d.ts +2 -1
  33. package/types/document/data-type/extended-types/{date-string.type.d.ts → date-time-tz.type.d.ts} +2 -2
  34. package/types/document/data-type/extended-types/date-time.type.d.ts +1 -0
  35. package/types/document/data-type/extended-types/date.type.d.ts +1 -0
  36. package/types/document/data-type/extended-types/index.d.ts +2 -2
  37. package/types/document/data-type/extended-types/{date-time-string.type.d.ts → partial-date.type.d.ts} +2 -2
  38. package/types/document/data-type/simple-type.d.ts +3 -1
  39. package/types/document/factory/data-type.factory.d.ts +1 -0
  40. package/cjs/document/data-type/extended-types/date-string.type.js +0 -52
  41. package/cjs/document/data-type/extended-types/date-time-string.type.js +0 -55
  42. package/esm/document/data-type/extended-types/date-string.type.js +0 -49
  43. package/esm/document/data-type/extended-types/date-time-string.type.js +0 -52
@@ -28,11 +28,6 @@ exports.ApiField = function (...args) {
28
28
  throw new Error('Field origin should be one of ComplexType, MappedType or MixinType');
29
29
  }
30
30
  _this.origin = origin;
31
- _this.scopePattern = initArgs.scopePattern
32
- ? Array.isArray(initArgs.scopePattern)
33
- ? initArgs.scopePattern
34
- : [initArgs.scopePattern]
35
- : undefined;
36
31
  _this.type = initArgs.type || owner.node.getDataType('any');
37
32
  _this.description = initArgs.description;
38
33
  _this.isArray = initArgs.isArray;
@@ -48,6 +43,18 @@ exports.ApiField = function (...args) {
48
43
  _this.writeonly = initArgs.writeonly;
49
44
  _this.examples = initArgs.examples;
50
45
  _this.override = initArgs.override;
46
+ _this.scopePattern = initArgs.scopePattern
47
+ ? Array.isArray(initArgs.scopePattern)
48
+ ? initArgs.scopePattern
49
+ : [initArgs.scopePattern]
50
+ : undefined;
51
+ _this.convertToNative =
52
+ initArgs.convertToNative ??
53
+ (_this.type.kind === 'SimpleType' &&
54
+ initArgs.designType !== String &&
55
+ typeof initArgs.designType === 'function' &&
56
+ initArgs.designType !== Object);
57
+ _this.override = initArgs.override;
51
58
  };
52
59
  /**
53
60
  * The ApiFieldClass represents a descriptive metadata structure for API fields,
@@ -334,6 +334,8 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
334
334
  let fn = field.type.generateCodec(codec, {
335
335
  ...context,
336
336
  level: context.level + 1,
337
+ }, {
338
+ convertToNative: field.convertToNative,
337
339
  });
338
340
  if (field.fixed)
339
341
  fn = valgen_1.vg.isEqual(field.fixed);
@@ -10,11 +10,14 @@ let Base64Type = class Base64Type {
10
10
  if (attributes)
11
11
  Object.assign(this, attributes);
12
12
  }
13
- [constants_js_1.DECODER]() {
14
- return valgen_1.vg.isBase64({ coerce: true });
13
+ [constants_js_1.DECODER](properties) {
14
+ const fn = valgen_1.vg.isBase64({ coerce: true });
15
+ if (properties.convertToNative)
16
+ return valgen_1.vg.pipe([fn, toBuffer], { coerce: true });
17
+ return fn;
15
18
  }
16
19
  [constants_js_1.ENCODER]() {
17
- return valgen_1.vg.isBase64({ coerce: true });
20
+ return fromBuffer;
18
21
  }
19
22
  };
20
23
  exports.Base64Type = Base64Type;
@@ -29,3 +32,13 @@ exports.Base64Type = Base64Type = tslib_1.__decorate([
29
32
  }),
30
33
  tslib_1.__metadata("design:paramtypes", [Object])
31
34
  ], Base64Type);
35
+ const toBuffer = (0, valgen_1.validator)((base64String) => {
36
+ return Buffer.from(base64String, 'base64');
37
+ });
38
+ const fromBuffer = (0, valgen_1.validator)((input) => {
39
+ if (Buffer.isBuffer(input))
40
+ return input.toString('base64');
41
+ else {
42
+ return (0, valgen_1.isBase64)(input);
43
+ }
44
+ });
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DateTimeTypeTz = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const valgen_1 = require("valgen");
6
+ const constants_js_1 = require("../../constants.js");
7
+ const simple_type_js_1 = require("../simple-type.js");
8
+ const _isDateString = valgen_1.vg.isDateString({
9
+ precisionMin: 'tz',
10
+ coerce: true,
11
+ });
12
+ let DateTimeTypeTz = class DateTimeTypeTz {
13
+ constructor(attributes) {
14
+ if (attributes)
15
+ Object.assign(this, attributes);
16
+ }
17
+ [constants_js_1.DECODER](properties) {
18
+ const fn = _isDateString;
19
+ const x = [fn];
20
+ if (properties.minValue != null) {
21
+ x.push(valgen_1.vg.isGte(fn(properties.minValue)));
22
+ }
23
+ if (properties.maxValue != null) {
24
+ x.push(valgen_1.vg.isLte(fn(properties.maxValue)));
25
+ }
26
+ return x.length > 0 ? valgen_1.vg.pipe(x, { returnIndex: 0 }) : fn;
27
+ }
28
+ [constants_js_1.ENCODER](properties) {
29
+ const fn = _isDateString;
30
+ const x = [fn];
31
+ if (properties.minValue != null) {
32
+ x.push(valgen_1.vg.isGte(fn(properties.minValue)));
33
+ }
34
+ if (properties.maxValue != null) {
35
+ x.push(valgen_1.vg.isLte(fn(properties.maxValue)));
36
+ }
37
+ return x.length > 0 ? valgen_1.vg.pipe(x, { returnIndex: 0 }) : fn;
38
+ }
39
+ };
40
+ exports.DateTimeTypeTz = DateTimeTypeTz;
41
+ tslib_1.__decorate([
42
+ simple_type_js_1.SimpleType.Attribute({
43
+ description: 'Minimum value',
44
+ }),
45
+ tslib_1.__metadata("design:type", String)
46
+ ], DateTimeTypeTz.prototype, "minValue", void 0);
47
+ tslib_1.__decorate([
48
+ simple_type_js_1.SimpleType.Attribute({
49
+ description: 'Maximum value',
50
+ }),
51
+ tslib_1.__metadata("design:type", String)
52
+ ], DateTimeTypeTz.prototype, "maxValue", void 0);
53
+ exports.DateTimeTypeTz = DateTimeTypeTz = tslib_1.__decorate([
54
+ ((0, simple_type_js_1.SimpleType)({
55
+ name: 'datetimetz',
56
+ description: 'A full datetime value with time zone information',
57
+ nameMappings: {
58
+ js: 'string',
59
+ json: 'string',
60
+ },
61
+ }).Example('2021-04-18T22:30:15+03:00')),
62
+ tslib_1.__metadata("design:paramtypes", [Object])
63
+ ], DateTimeTypeTz);
@@ -5,40 +5,46 @@ const tslib_1 = require("tslib");
5
5
  const valgen_1 = require("valgen");
6
6
  const constants_js_1 = require("../../constants.js");
7
7
  const simple_type_js_1 = require("../simple-type.js");
8
+ const _isDateString = valgen_1.vg.isDateString({
9
+ precisionMin: 'day',
10
+ trim: 'tz',
11
+ coerce: true,
12
+ });
13
+ const _isDate = valgen_1.vg.isDate({
14
+ coerce: true,
15
+ });
8
16
  let DateTimeType = class DateTimeType {
9
17
  constructor(attributes) {
10
18
  if (attributes)
11
19
  Object.assign(this, attributes);
12
20
  }
13
21
  [constants_js_1.DECODER](properties) {
14
- const fn = valgen_1.vg.isDate({ precision: 'time', coerce: true });
15
- const x = [];
22
+ let fn;
23
+ if (properties.convertToNative) {
24
+ fn = _isDate;
25
+ }
26
+ else {
27
+ fn = _isDateString;
28
+ }
29
+ const x = [fn];
16
30
  if (properties.minValue != null) {
17
- (0, valgen_1.isDateString)(properties.minValue);
18
- x.push(valgen_1.toString, valgen_1.vg.isGte(properties.minValue));
31
+ x.push(valgen_1.vg.isGte(fn(properties.minValue)));
19
32
  }
20
33
  if (properties.maxValue != null) {
21
- (0, valgen_1.isDateString)(properties.maxValue);
22
- x.push(valgen_1.toString, valgen_1.vg.isLte(properties.maxValue));
34
+ x.push(valgen_1.vg.isLte(fn(properties.maxValue)));
23
35
  }
24
- return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
36
+ return x.length > 0 ? valgen_1.vg.pipe(x, { returnIndex: 0 }) : fn;
25
37
  }
26
38
  [constants_js_1.ENCODER](properties) {
27
- const fn = valgen_1.vg.isDateString({
28
- precision: 'time',
29
- trim: 'time',
30
- coerce: true,
31
- });
32
- const x = [];
39
+ const fn = _isDateString;
40
+ const x = [fn];
33
41
  if (properties.minValue != null) {
34
- (0, valgen_1.isDateString)(properties.minValue);
35
- x.push(valgen_1.vg.isGte(properties.minValue));
42
+ x.push(valgen_1.vg.isGte(fn(properties.minValue)));
36
43
  }
37
44
  if (properties.maxValue != null) {
38
- (0, valgen_1.isDateString)(properties.maxValue);
39
- x.push(valgen_1.vg.isLte(properties.maxValue));
45
+ x.push(valgen_1.vg.isLte(fn(properties.maxValue)));
40
46
  }
41
- return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
47
+ return x.length > 0 ? valgen_1.vg.pipe(x, { returnIndex: 0 }) : fn;
42
48
  }
43
49
  };
44
50
  exports.DateTimeType = DateTimeType;
@@ -5,40 +5,47 @@ const tslib_1 = require("tslib");
5
5
  const valgen_1 = require("valgen");
6
6
  const constants_js_1 = require("../../constants.js");
7
7
  const simple_type_js_1 = require("../simple-type.js");
8
+ const _isDateString = valgen_1.vg.isDateString({
9
+ precisionMin: 'day',
10
+ trim: 'day',
11
+ coerce: true,
12
+ });
13
+ const _isDate = valgen_1.vg.isDate({
14
+ trim: 'day',
15
+ coerce: true,
16
+ });
8
17
  let DateType = class DateType {
9
18
  constructor(attributes) {
10
19
  if (attributes)
11
20
  Object.assign(this, attributes);
12
21
  }
13
22
  [constants_js_1.DECODER](properties) {
14
- const fn = valgen_1.vg.isDate({ precision: 'date', coerce: true });
15
- const x = [];
23
+ let fn;
24
+ if (properties.convertToNative) {
25
+ fn = _isDate;
26
+ }
27
+ else {
28
+ fn = _isDateString;
29
+ }
30
+ const x = [fn];
16
31
  if (properties.minValue != null) {
17
- (0, valgen_1.isDateString)(properties.minValue);
18
- x.push(valgen_1.toString, valgen_1.vg.isGte(properties.minValue));
32
+ x.push(valgen_1.vg.isGte(fn(properties.minValue)));
19
33
  }
20
34
  if (properties.maxValue != null) {
21
- (0, valgen_1.isDateString)(properties.maxValue);
22
- x.push(valgen_1.toString, valgen_1.vg.isLte(properties.maxValue));
35
+ x.push(valgen_1.vg.isLte(fn(properties.maxValue)));
23
36
  }
24
- return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
37
+ return x.length > 0 ? valgen_1.vg.pipe(x, { returnIndex: 0 }) : fn;
25
38
  }
26
39
  [constants_js_1.ENCODER](properties) {
27
- const fn = valgen_1.vg.isDateString({
28
- precision: 'date',
29
- trim: 'date',
30
- coerce: true,
31
- });
32
- const x = [];
40
+ const fn = _isDateString;
41
+ const x = [fn];
33
42
  if (properties.minValue != null) {
34
- (0, valgen_1.isDateString)(properties.minValue);
35
- x.push(valgen_1.vg.isGte(properties.minValue));
43
+ x.push(valgen_1.vg.isGte(fn(properties.minValue)));
36
44
  }
37
45
  if (properties.maxValue != null) {
38
- (0, valgen_1.isDateString)(properties.maxValue);
39
- x.push(valgen_1.vg.isLte(properties.maxValue));
46
+ x.push(valgen_1.vg.isLte(fn(properties.maxValue)));
40
47
  }
41
- return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
48
+ return x.length > 0 ? valgen_1.vg.pipe(x, { returnIndex: 0 }) : fn;
42
49
  }
43
50
  };
44
51
  exports.DateType = DateType;
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./base64.type.js"), exports);
5
5
  tslib_1.__exportStar(require("./date.type.js"), exports);
6
- tslib_1.__exportStar(require("./date-string.type.js"), exports);
7
6
  tslib_1.__exportStar(require("./date-time.type.js"), exports);
8
- tslib_1.__exportStar(require("./date-time-string.type.js"), exports);
7
+ tslib_1.__exportStar(require("./date-time-tz.type.js"), exports);
9
8
  tslib_1.__exportStar(require("./email.type.js"), exports);
10
9
  tslib_1.__exportStar(require("./field-path.type.js"), exports);
11
10
  tslib_1.__exportStar(require("./filter.type.js"), exports);
12
11
  tslib_1.__exportStar(require("./object-id.type.js"), exports);
13
12
  tslib_1.__exportStar(require("./operation-result.type.js"), exports);
13
+ tslib_1.__exportStar(require("./partial-date.type.js"), exports);
14
14
  tslib_1.__exportStar(require("./time.type.js"), exports);
15
15
  tslib_1.__exportStar(require("./url.type.js"), exports);
16
16
  tslib_1.__exportStar(require("./uuid.type.js"), exports);
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PartialDateType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const valgen_1 = require("valgen");
6
+ const constants_js_1 = require("../../constants.js");
7
+ const simple_type_js_1 = require("../simple-type.js");
8
+ let PartialDateType = class PartialDateType {
9
+ constructor(attributes) {
10
+ if (attributes)
11
+ Object.assign(this, attributes);
12
+ }
13
+ [constants_js_1.DECODER](properties) {
14
+ const fn = toPartialDate;
15
+ const x = [];
16
+ if (properties.minValue != null) {
17
+ (0, valgen_1.isDateString)(properties.minValue);
18
+ x.push(valgen_1.toString, valgen_1.vg.isGte(properties.minValue));
19
+ }
20
+ if (properties.maxValue != null) {
21
+ (0, valgen_1.isDateString)(properties.maxValue);
22
+ x.push(valgen_1.toString, valgen_1.vg.isLte(properties.maxValue));
23
+ }
24
+ return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
25
+ }
26
+ [constants_js_1.ENCODER](properties) {
27
+ const fn = toPartialDate;
28
+ const x = [];
29
+ if (properties.minValue != null) {
30
+ (0, valgen_1.isDateString)(properties.minValue);
31
+ x.push(valgen_1.vg.isGte(properties.minValue));
32
+ }
33
+ if (properties.maxValue != null) {
34
+ (0, valgen_1.isDateString)(properties.maxValue);
35
+ x.push(valgen_1.vg.isLte(properties.maxValue));
36
+ }
37
+ return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
38
+ }
39
+ };
40
+ exports.PartialDateType = PartialDateType;
41
+ tslib_1.__decorate([
42
+ simple_type_js_1.SimpleType.Attribute({
43
+ description: 'Minimum value',
44
+ }),
45
+ tslib_1.__metadata("design:type", String)
46
+ ], PartialDateType.prototype, "minValue", void 0);
47
+ tslib_1.__decorate([
48
+ simple_type_js_1.SimpleType.Attribute({
49
+ description: 'Maximum value',
50
+ }),
51
+ tslib_1.__metadata("design:type", String)
52
+ ], PartialDateType.prototype, "maxValue", void 0);
53
+ exports.PartialDateType = PartialDateType = tslib_1.__decorate([
54
+ ((0, simple_type_js_1.SimpleType)({
55
+ name: 'partialdate',
56
+ description: 'Specifies a point in time using a 24-hour clock notation.\rFormat: YYYY-[MM-[DD-[T?HH:[MM:[SS[.S[S[S[S]]]]]]]]][+/-ZZ:ZZ].',
57
+ nameMappings: {
58
+ js: 'string',
59
+ json: 'string',
60
+ },
61
+ })
62
+ .Example('2021-04-18T22:30:15:22+03:00')
63
+ .Example('2021-04-18 22:30')
64
+ .Example('2021-04-18')
65
+ .Example('2021')),
66
+ tslib_1.__metadata("design:paramtypes", [Object])
67
+ ], PartialDateType);
68
+ const _isDateString = valgen_1.vg.isDateString({
69
+ precisionMin: 'year',
70
+ });
71
+ const toPartialDate = (0, valgen_1.validator)((input) => {
72
+ if (input instanceof Date) {
73
+ let s = _isDateString(input, { coerce: true });
74
+ if (s.endsWith('Z'))
75
+ s = s.substring(0, s.length - 1);
76
+ if (s.endsWith('.000'))
77
+ s = s.substring(0, s.length - 4);
78
+ if (s.endsWith(':00'))
79
+ s = s.substring(0, s.length - 3);
80
+ if (s.endsWith('00:00'))
81
+ s = s.substring(0, s.length - 6);
82
+ return s;
83
+ }
84
+ return _isDateString(input, { coerce: false });
85
+ });
@@ -52,6 +52,10 @@ exports.SimpleType = function (...args) {
52
52
  * @class SimpleType
53
53
  */
54
54
  class SimpleTypeClass extends data_type_js_1.DataType {
55
+ extend(properties) {
56
+ Object.setPrototypeOf(properties, this);
57
+ return properties;
58
+ }
55
59
  extendsFrom(baseType) {
56
60
  if (!(baseType instanceof data_type_js_1.DataType))
57
61
  baseType = this.node.getDataType(baseType);
@@ -19,6 +19,7 @@ function ApiFieldDecoratorFactory(options) {
19
19
  const designType = Reflect.getMetadata('design:type', target, propertyKey);
20
20
  const elemMeta = (metadata.fields[propertyKey] = {
21
21
  ...options,
22
+ designType,
22
23
  });
23
24
  if (designType === Array) {
24
25
  elemMeta.isArray = true;
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiDocumentFactory = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const index_js_1 = require("../../helpers/index.js");
5
6
  const index_js_2 = require("../../schema/index.js");
6
7
  const api_document_js_1 = require("../api-document.js");
7
8
  const document_init_context_js_1 = require("../common/document-init-context.js");
8
9
  const opra_document_error_js_1 = require("../common/opra-document-error.js");
9
10
  const constants_js_1 = require("../constants.js");
10
- const index_js_3 = require("../data-type/extended-types/index.js");
11
- const index_js_4 = require("../data-type/primitive-types/index.js");
11
+ const extendedTypes = tslib_1.__importStar(require("../data-type/extended-types/index.js"));
12
+ const primitiveTypes = tslib_1.__importStar(require("../data-type/primitive-types/index.js"));
12
13
  const data_type_factory_js_1 = require("./data-type.factory.js");
13
14
  const http_api_factory_js_1 = require("./http-api.factory.js");
14
15
  const rpc_api_factory_js_1 = require("./rpc-api.factory.js");
@@ -157,29 +158,8 @@ class ApiDocumentFactory {
157
158
  },
158
159
  },
159
160
  types: [
160
- // Primitive types
161
- index_js_4.AnyType,
162
- index_js_4.BigintType,
163
- index_js_4.BooleanType,
164
- index_js_4.IntegerType,
165
- index_js_4.NullType,
166
- index_js_4.NumberType,
167
- index_js_4.ObjectType,
168
- index_js_4.StringType,
169
- // Extended types
170
- index_js_3.Base64Type,
171
- index_js_3.DateType,
172
- index_js_3.DateStringType,
173
- index_js_3.DateTimeType,
174
- index_js_3.DateTimeStringType,
175
- index_js_3.EmailType,
176
- index_js_3.FieldPathType,
177
- index_js_3.FilterType,
178
- index_js_3.ObjectIdType,
179
- index_js_3.OperationResult,
180
- index_js_3.TimeType,
181
- index_js_3.UrlType,
182
- index_js_3.UuidType,
161
+ ...Object.values(primitiveTypes),
162
+ ...Object.values(extendedTypes),
183
163
  ],
184
164
  };
185
165
  const document = new api_document_js_1.ApiDocument();
@@ -150,6 +150,7 @@ class DataTypeFactory {
150
150
  * @param context
151
151
  * @param owner
152
152
  * @param thunk
153
+ * @param checkCircularDeps
153
154
  * @protected
154
155
  */
155
156
  static async _importDataTypeArgs(context, owner, thunk, checkCircularDeps) {
@@ -133,7 +133,7 @@ class FilterRules {
133
133
  });
134
134
  this._decoderCache.set(comp.left.field, decoder);
135
135
  }
136
- ast.value = decoder(ast.value);
136
+ ast.value = decoder(ast.value, { coerce: true });
137
137
  }
138
138
  }
139
139
  }
@@ -25,11 +25,6 @@ export const ApiField = function (...args) {
25
25
  throw new Error('Field origin should be one of ComplexType, MappedType or MixinType');
26
26
  }
27
27
  _this.origin = origin;
28
- _this.scopePattern = initArgs.scopePattern
29
- ? Array.isArray(initArgs.scopePattern)
30
- ? initArgs.scopePattern
31
- : [initArgs.scopePattern]
32
- : undefined;
33
28
  _this.type = initArgs.type || owner.node.getDataType('any');
34
29
  _this.description = initArgs.description;
35
30
  _this.isArray = initArgs.isArray;
@@ -45,6 +40,18 @@ export const ApiField = function (...args) {
45
40
  _this.writeonly = initArgs.writeonly;
46
41
  _this.examples = initArgs.examples;
47
42
  _this.override = initArgs.override;
43
+ _this.scopePattern = initArgs.scopePattern
44
+ ? Array.isArray(initArgs.scopePattern)
45
+ ? initArgs.scopePattern
46
+ : [initArgs.scopePattern]
47
+ : undefined;
48
+ _this.convertToNative =
49
+ initArgs.convertToNative ??
50
+ (_this.type.kind === 'SimpleType' &&
51
+ initArgs.designType !== String &&
52
+ typeof initArgs.designType === 'function' &&
53
+ initArgs.designType !== Object);
54
+ _this.override = initArgs.override;
48
55
  };
49
56
  /**
50
57
  * The ApiFieldClass represents a descriptive metadata structure for API fields,
@@ -330,6 +330,8 @@ class ComplexTypeBaseClass extends DataType {
330
330
  let fn = field.type.generateCodec(codec, {
331
331
  ...context,
332
332
  level: context.level + 1,
333
+ }, {
334
+ convertToNative: field.convertToNative,
333
335
  });
334
336
  if (field.fixed)
335
337
  fn = vg.isEqual(field.fixed);
@@ -1,5 +1,5 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import { vg } from 'valgen';
2
+ import { isBase64, validator, vg } from 'valgen';
3
3
  import { DECODER, ENCODER } from '../../constants.js';
4
4
  import { SimpleType } from '../simple-type.js';
5
5
  let Base64Type = class Base64Type {
@@ -7,11 +7,14 @@ let Base64Type = class Base64Type {
7
7
  if (attributes)
8
8
  Object.assign(this, attributes);
9
9
  }
10
- [DECODER]() {
11
- return vg.isBase64({ coerce: true });
10
+ [DECODER](properties) {
11
+ const fn = vg.isBase64({ coerce: true });
12
+ if (properties.convertToNative)
13
+ return vg.pipe([fn, toBuffer], { coerce: true });
14
+ return fn;
12
15
  }
13
16
  [ENCODER]() {
14
- return vg.isBase64({ coerce: true });
17
+ return fromBuffer;
15
18
  }
16
19
  };
17
20
  Base64Type = __decorate([
@@ -26,3 +29,13 @@ Base64Type = __decorate([
26
29
  __metadata("design:paramtypes", [Object])
27
30
  ], Base64Type);
28
31
  export { Base64Type };
32
+ const toBuffer = validator((base64String) => {
33
+ return Buffer.from(base64String, 'base64');
34
+ });
35
+ const fromBuffer = validator((input) => {
36
+ if (Buffer.isBuffer(input))
37
+ return input.toString('base64');
38
+ else {
39
+ return isBase64(input);
40
+ }
41
+ });
@@ -0,0 +1,60 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { vg } from 'valgen';
3
+ import { DECODER, ENCODER } from '../../constants.js';
4
+ import { SimpleType } from '../simple-type.js';
5
+ const _isDateString = vg.isDateString({
6
+ precisionMin: 'tz',
7
+ coerce: true,
8
+ });
9
+ let DateTimeTypeTz = class DateTimeTypeTz {
10
+ constructor(attributes) {
11
+ if (attributes)
12
+ Object.assign(this, attributes);
13
+ }
14
+ [DECODER](properties) {
15
+ const fn = _isDateString;
16
+ const x = [fn];
17
+ if (properties.minValue != null) {
18
+ x.push(vg.isGte(fn(properties.minValue)));
19
+ }
20
+ if (properties.maxValue != null) {
21
+ x.push(vg.isLte(fn(properties.maxValue)));
22
+ }
23
+ return x.length > 0 ? vg.pipe(x, { returnIndex: 0 }) : fn;
24
+ }
25
+ [ENCODER](properties) {
26
+ const fn = _isDateString;
27
+ const x = [fn];
28
+ if (properties.minValue != null) {
29
+ x.push(vg.isGte(fn(properties.minValue)));
30
+ }
31
+ if (properties.maxValue != null) {
32
+ x.push(vg.isLte(fn(properties.maxValue)));
33
+ }
34
+ return x.length > 0 ? vg.pipe(x, { returnIndex: 0 }) : fn;
35
+ }
36
+ };
37
+ __decorate([
38
+ SimpleType.Attribute({
39
+ description: 'Minimum value',
40
+ }),
41
+ __metadata("design:type", String)
42
+ ], DateTimeTypeTz.prototype, "minValue", void 0);
43
+ __decorate([
44
+ SimpleType.Attribute({
45
+ description: 'Maximum value',
46
+ }),
47
+ __metadata("design:type", String)
48
+ ], DateTimeTypeTz.prototype, "maxValue", void 0);
49
+ DateTimeTypeTz = __decorate([
50
+ (SimpleType({
51
+ name: 'datetimetz',
52
+ description: 'A full datetime value with time zone information',
53
+ nameMappings: {
54
+ js: 'string',
55
+ json: 'string',
56
+ },
57
+ }).Example('2021-04-18T22:30:15+03:00')),
58
+ __metadata("design:paramtypes", [Object])
59
+ ], DateTimeTypeTz);
60
+ export { DateTimeTypeTz };
@@ -1,41 +1,47 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import { isDateString, toString, vg } from 'valgen';
2
+ import { vg } from 'valgen';
3
3
  import { DECODER, ENCODER } from '../../constants.js';
4
4
  import { SimpleType } from '../simple-type.js';
5
+ const _isDateString = vg.isDateString({
6
+ precisionMin: 'day',
7
+ trim: 'tz',
8
+ coerce: true,
9
+ });
10
+ const _isDate = vg.isDate({
11
+ coerce: true,
12
+ });
5
13
  let DateTimeType = class DateTimeType {
6
14
  constructor(attributes) {
7
15
  if (attributes)
8
16
  Object.assign(this, attributes);
9
17
  }
10
18
  [DECODER](properties) {
11
- const fn = vg.isDate({ precision: 'time', coerce: true });
12
- const x = [];
19
+ let fn;
20
+ if (properties.convertToNative) {
21
+ fn = _isDate;
22
+ }
23
+ else {
24
+ fn = _isDateString;
25
+ }
26
+ const x = [fn];
13
27
  if (properties.minValue != null) {
14
- isDateString(properties.minValue);
15
- x.push(toString, vg.isGte(properties.minValue));
28
+ x.push(vg.isGte(fn(properties.minValue)));
16
29
  }
17
30
  if (properties.maxValue != null) {
18
- isDateString(properties.maxValue);
19
- x.push(toString, vg.isLte(properties.maxValue));
31
+ x.push(vg.isLte(fn(properties.maxValue)));
20
32
  }
21
- return x.length > 0 ? vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
33
+ return x.length > 0 ? vg.pipe(x, { returnIndex: 0 }) : fn;
22
34
  }
23
35
  [ENCODER](properties) {
24
- const fn = vg.isDateString({
25
- precision: 'time',
26
- trim: 'time',
27
- coerce: true,
28
- });
29
- const x = [];
36
+ const fn = _isDateString;
37
+ const x = [fn];
30
38
  if (properties.minValue != null) {
31
- isDateString(properties.minValue);
32
- x.push(vg.isGte(properties.minValue));
39
+ x.push(vg.isGte(fn(properties.minValue)));
33
40
  }
34
41
  if (properties.maxValue != null) {
35
- isDateString(properties.maxValue);
36
- x.push(vg.isLte(properties.maxValue));
42
+ x.push(vg.isLte(fn(properties.maxValue)));
37
43
  }
38
- return x.length > 0 ? vg.pipe([fn, ...x], { returnIndex: 0 }) : fn;
44
+ return x.length > 0 ? vg.pipe(x, { returnIndex: 0 }) : fn;
39
45
  }
40
46
  };
41
47
  __decorate([