@opra/common 1.4.4 → 1.5.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 (124) hide show
  1. package/browser/index.cjs +5 -5
  2. package/browser/index.mjs +5 -5
  3. package/cjs/document/api-document.js +12 -8
  4. package/cjs/document/common/api-base.js +2 -1
  5. package/cjs/document/common/document-node.js +24 -29
  6. package/cjs/document/common/value.js +6 -2
  7. package/cjs/document/constants.js +1 -2
  8. package/cjs/document/data-type/api-field.js +12 -8
  9. package/cjs/document/data-type/complex-type-base.js +22 -11
  10. package/cjs/document/data-type/complex-type.js +22 -8
  11. package/cjs/document/data-type/data-type.js +14 -1
  12. package/cjs/document/data-type/enum-type.js +13 -3
  13. package/cjs/document/data-type/extended-types/base64.type.js +1 -0
  14. package/cjs/document/data-type/extended-types/date-string.type.js +1 -0
  15. package/cjs/document/data-type/extended-types/date-time-string.type.js +1 -0
  16. package/cjs/document/data-type/extended-types/date-time.type.js +1 -0
  17. package/cjs/document/data-type/extended-types/date.type.js +1 -0
  18. package/cjs/document/data-type/extended-types/email.type.js +1 -0
  19. package/cjs/document/data-type/extended-types/field-path.type.js +10 -6
  20. package/cjs/document/data-type/extended-types/filter.type.js +11 -4
  21. package/cjs/document/data-type/extended-types/object-id.type.js +1 -0
  22. package/cjs/document/data-type/extended-types/operation-result.type.js +1 -0
  23. package/cjs/document/data-type/extended-types/time.type.js +1 -0
  24. package/cjs/document/data-type/extended-types/url.type.js +1 -0
  25. package/cjs/document/data-type/extended-types/uuid.type.js +1 -0
  26. package/cjs/document/data-type/mapped-type.js +12 -3
  27. package/cjs/document/data-type/mixin-type.js +17 -5
  28. package/cjs/document/data-type/primitive-types/any.type.js +1 -0
  29. package/cjs/document/data-type/primitive-types/bigint.type.js +1 -0
  30. package/cjs/document/data-type/primitive-types/boolean.type.js +1 -0
  31. package/cjs/document/data-type/primitive-types/integer.type.js +1 -0
  32. package/cjs/document/data-type/primitive-types/null.type.js +1 -0
  33. package/cjs/document/data-type/primitive-types/number.type.js +1 -0
  34. package/cjs/document/data-type/primitive-types/string.type.js +1 -0
  35. package/cjs/document/data-type/simple-type.js +13 -11
  36. package/cjs/document/decorators/api-field-decorator.js +37 -3
  37. package/cjs/document/decorators/complex-type.decorator.js +1 -1
  38. package/cjs/document/decorators/simple-type.decorator.js +3 -1
  39. package/cjs/document/http/http-api.js +2 -2
  40. package/cjs/document/http/http-controller.js +5 -5
  41. package/cjs/document/http/http-media-type.js +3 -3
  42. package/cjs/document/http/http-multipart-field.js +2 -2
  43. package/cjs/document/http/http-operation-response.js +3 -3
  44. package/cjs/document/http/http-operation.js +5 -5
  45. package/cjs/document/http/http-parameter.js +2 -2
  46. package/cjs/document/http/http-request-body.js +4 -2
  47. package/cjs/document/utils/test-scope-match.js +13 -0
  48. package/cjs/filter/filter-rules.js +6 -6
  49. package/esm/document/api-document.js +12 -8
  50. package/esm/document/common/api-base.js +2 -1
  51. package/esm/document/common/document-node.js +24 -29
  52. package/esm/document/common/value.js +6 -2
  53. package/esm/document/constants.js +0 -1
  54. package/esm/document/data-type/api-field.js +13 -9
  55. package/esm/document/data-type/complex-type-base.js +22 -11
  56. package/esm/document/data-type/complex-type.js +22 -8
  57. package/esm/document/data-type/data-type.js +14 -1
  58. package/esm/document/data-type/enum-type.js +13 -3
  59. package/esm/document/data-type/extended-types/base64.type.js +1 -0
  60. package/esm/document/data-type/extended-types/date-string.type.js +1 -0
  61. package/esm/document/data-type/extended-types/date-time-string.type.js +1 -0
  62. package/esm/document/data-type/extended-types/date-time.type.js +1 -0
  63. package/esm/document/data-type/extended-types/date.type.js +1 -0
  64. package/esm/document/data-type/extended-types/email.type.js +1 -0
  65. package/esm/document/data-type/extended-types/field-path.type.js +10 -6
  66. package/esm/document/data-type/extended-types/filter.type.js +11 -4
  67. package/esm/document/data-type/extended-types/object-id.type.js +1 -0
  68. package/esm/document/data-type/extended-types/operation-result.type.js +1 -0
  69. package/esm/document/data-type/extended-types/time.type.js +1 -0
  70. package/esm/document/data-type/extended-types/url.type.js +1 -0
  71. package/esm/document/data-type/extended-types/uuid.type.js +1 -0
  72. package/esm/document/data-type/mapped-type.js +12 -3
  73. package/esm/document/data-type/mixin-type.js +17 -5
  74. package/esm/document/data-type/primitive-types/any.type.js +1 -0
  75. package/esm/document/data-type/primitive-types/bigint.type.js +1 -0
  76. package/esm/document/data-type/primitive-types/boolean.type.js +1 -0
  77. package/esm/document/data-type/primitive-types/integer.type.js +1 -0
  78. package/esm/document/data-type/primitive-types/null.type.js +1 -0
  79. package/esm/document/data-type/primitive-types/number.type.js +1 -0
  80. package/esm/document/data-type/primitive-types/string.type.js +1 -0
  81. package/esm/document/data-type/simple-type.js +13 -11
  82. package/esm/document/decorators/api-field-decorator.js +36 -2
  83. package/esm/document/decorators/complex-type.decorator.js +2 -2
  84. package/esm/document/decorators/simple-type.decorator.js +4 -2
  85. package/esm/document/http/http-api.js +2 -2
  86. package/esm/document/http/http-controller.js +5 -5
  87. package/esm/document/http/http-media-type.js +3 -3
  88. package/esm/document/http/http-multipart-field.js +2 -2
  89. package/esm/document/http/http-operation-response.js +3 -3
  90. package/esm/document/http/http-operation.js +5 -5
  91. package/esm/document/http/http-parameter.js +2 -2
  92. package/esm/document/http/http-request-body.js +4 -2
  93. package/esm/document/utils/test-scope-match.js +10 -0
  94. package/esm/filter/filter-rules.js +6 -6
  95. package/package.json +1 -1
  96. package/types/document/api-document.d.ts +7 -2
  97. package/types/document/common/api-base.d.ts +1 -1
  98. package/types/document/common/document-init-context.d.ts +1 -0
  99. package/types/document/common/document-node.d.ts +8 -14
  100. package/types/document/common/value.d.ts +2 -1
  101. package/types/document/constants.d.ts +0 -1
  102. package/types/document/data-type/api-field.d.ts +42 -34
  103. package/types/document/data-type/complex-type-base.d.ts +4 -2
  104. package/types/document/data-type/complex-type.d.ts +3 -1
  105. package/types/document/data-type/data-type.d.ts +8 -2
  106. package/types/document/data-type/enum-type.d.ts +3 -1
  107. package/types/document/data-type/extended-types/field-path.type.d.ts +4 -3
  108. package/types/document/data-type/extended-types/filter.type.d.ts +2 -1
  109. package/types/document/data-type/mapped-type.d.ts +3 -1
  110. package/types/document/data-type/mixin-type.d.ts +3 -1
  111. package/types/document/data-type/simple-type.d.ts +3 -2
  112. package/types/document/decorators/api-field-decorator.d.ts +5 -3
  113. package/types/document/decorators/simple-type.decorator.d.ts +34 -0
  114. package/types/document/factory/api-document.factory.d.ts +1 -0
  115. package/types/document/http/http-api.d.ts +1 -1
  116. package/types/document/http/http-controller.d.ts +2 -1
  117. package/types/document/http/http-media-type.d.ts +2 -1
  118. package/types/document/http/http-multipart-field.d.ts +2 -1
  119. package/types/document/http/http-operation-response.d.ts +2 -1
  120. package/types/document/http/http-operation.d.ts +2 -1
  121. package/types/document/http/http-parameter.d.ts +2 -1
  122. package/types/document/http/http-request-body.d.ts +2 -1
  123. package/types/document/utils/test-scope-match.d.ts +1 -0
  124. package/types/filter/filter-rules.d.ts +2 -2
@@ -20,6 +20,7 @@ let UrlType = class UrlType {
20
20
  exports.UrlType = UrlType;
21
21
  exports.UrlType = UrlType = tslib_1.__decorate([
22
22
  ((0, simple_type_js_1.SimpleType)({
23
+ name: 'url',
23
24
  description: 'A Uniform Resource Identifier Reference (RFC 3986 icon) value',
24
25
  nameMappings: {
25
26
  js: 'string',
@@ -26,6 +26,7 @@ tslib_1.__decorate([
26
26
  ], UuidType.prototype, "version", void 0);
27
27
  exports.UuidType = UuidType = tslib_1.__decorate([
28
28
  (0, simple_type_js_1.SimpleType)({
29
+ name: 'uuid',
29
30
  description: 'A Universal Unique Identifier (UUID) value',
30
31
  nameMappings: {
31
32
  js: 'string',
@@ -88,13 +88,14 @@ class MappedTypeClass extends complex_type_base_js_1.ComplexTypeBase {
88
88
  return true;
89
89
  return !!this.base?.extendsFrom(baseType);
90
90
  }
91
- toJSON() {
91
+ toJSON(options) {
92
+ const superJson = super.toJSON(options);
92
93
  const baseName = this.base
93
94
  ? this.node.getDataTypeNameWithNs(this.base)
94
95
  : undefined;
95
96
  return (0, objects_1.omitUndefined)({
96
- ...complex_type_base_js_1.ComplexTypeBase.prototype.toJSON.call(this),
97
- base: baseName ? baseName : this.base.toJSON(),
97
+ ...superJson,
98
+ base: baseName ? baseName : this.base.toJSON(options),
98
99
  kind: this.kind,
99
100
  pick: this.pick,
100
101
  omit: this.omit,
@@ -102,6 +103,14 @@ class MappedTypeClass extends complex_type_base_js_1.ComplexTypeBase {
102
103
  required: this.required,
103
104
  });
104
105
  }
106
+ _locateBase(callback) {
107
+ if (!this.base)
108
+ return;
109
+ if (callback(this.base))
110
+ return this.base;
111
+ if (this.base._locateBase)
112
+ return this.base._locateBase(callback);
113
+ }
105
114
  }
106
115
  exports.MappedType.prototype = MappedTypeClass.prototype;
107
116
  exports.MappedType._applyMixin = () => undefined;
@@ -57,16 +57,28 @@ class MixinTypeClass extends complex_type_base_js_1.ComplexTypeBase {
57
57
  }
58
58
  return false;
59
59
  }
60
- toJSON() {
60
+ toJSON(options) {
61
+ const superJson = super.toJSON(options);
61
62
  return (0, objects_1.omitUndefined)({
62
- ...complex_type_base_js_1.ComplexTypeBase.prototype.toJSON.call(this),
63
+ ...superJson,
63
64
  kind: this.kind,
64
- types: this.types.map(t => {
65
- const baseName = this.node.getDataTypeNameWithNs(t);
66
- return baseName ? baseName : t.toJSON();
65
+ types: this.types.map(base => {
66
+ const baseName = this.node.getDataTypeNameWithNs(base);
67
+ return baseName ? baseName : base.toJSON(options);
67
68
  }),
68
69
  });
69
70
  }
71
+ _locateBase(callback) {
72
+ for (const t of this.types) {
73
+ if (callback(t))
74
+ return t;
75
+ if (t._locateBase) {
76
+ const x = t._locateBase(callback);
77
+ if (x)
78
+ return x;
79
+ }
80
+ }
81
+ }
70
82
  }
71
83
  exports.MixinType.prototype = MixinTypeClass.prototype;
72
84
  exports.MixinType[constants_js_1.DECORATOR] = MixinTypeFactory;
@@ -20,6 +20,7 @@ let AnyType = class AnyType {
20
20
  exports.AnyType = AnyType;
21
21
  exports.AnyType = AnyType = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
+ name: 'any',
23
24
  description: 'Represents any value',
24
25
  }),
25
26
  tslib_1.__metadata("design:paramtypes", [Object])
@@ -27,6 +27,7 @@ let BigintType = class BigintType extends number_type_js_1.NumberType {
27
27
  exports.BigintType = BigintType;
28
28
  exports.BigintType = BigintType = tslib_1.__decorate([
29
29
  (0, simple_type_js_1.SimpleType)({
30
+ name: 'bigint',
30
31
  description: 'BigInt number',
31
32
  nameMappings: {
32
33
  js: 'bigint',
@@ -20,6 +20,7 @@ let BooleanType = class BooleanType {
20
20
  exports.BooleanType = BooleanType;
21
21
  exports.BooleanType = BooleanType = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
+ name: 'boolean',
23
24
  description: 'Simple true/false value',
24
25
  nameMappings: {
25
26
  js: 'boolean',
@@ -27,6 +27,7 @@ let IntegerType = class IntegerType extends number_type_js_1.NumberType {
27
27
  exports.IntegerType = IntegerType;
28
28
  exports.IntegerType = IntegerType = tslib_1.__decorate([
29
29
  (0, simple_type_js_1.SimpleType)({
30
+ name: 'integer',
30
31
  description: 'An integer number',
31
32
  nameMappings: {
32
33
  js: 'number',
@@ -20,6 +20,7 @@ let NullType = class NullType {
20
20
  exports.NullType = NullType;
21
21
  exports.NullType = NullType = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
+ name: 'null',
23
24
  description: 'A Null value',
24
25
  nameMappings: {
25
26
  js: 'null',
@@ -39,6 +39,7 @@ tslib_1.__decorate([
39
39
  ], NumberType.prototype, "maxValue", void 0);
40
40
  exports.NumberType = NumberType = tslib_1.__decorate([
41
41
  (0, simple_type_js_1.SimpleType)({
42
+ name: 'number',
42
43
  description: 'Both Integer as well as Floating-Point numbers',
43
44
  nameMappings: {
44
45
  js: 'number',
@@ -59,6 +59,7 @@ tslib_1.__decorate([
59
59
  ], StringType.prototype, "maxLength", void 0);
60
60
  exports.StringType = StringType = tslib_1.__decorate([
61
61
  (0, simple_type_js_1.SimpleType)({
62
+ name: 'string',
62
63
  description: 'A sequence of characters',
63
64
  nameMappings: {
64
65
  js: 'string',
@@ -70,7 +70,7 @@ class SimpleTypeClass extends data_type_js_1.DataType {
70
70
  let t = this;
71
71
  while (t) {
72
72
  if (t._generateDecoder)
73
- return t._generateDecoder(prop, options?.documentElement || this.owner);
73
+ return t._generateDecoder(prop, options?.documentElement || this.owner, options?.scope);
74
74
  t = this.base;
75
75
  }
76
76
  return valgen_1.isAny;
@@ -78,28 +78,30 @@ class SimpleTypeClass extends data_type_js_1.DataType {
78
78
  let t = this;
79
79
  while (t) {
80
80
  if (t._generateEncoder)
81
- return t._generateEncoder(prop, options?.documentElement || this.owner);
81
+ return t._generateEncoder(prop, options?.documentElement || this.owner, options?.scope);
82
82
  t = this.base;
83
83
  }
84
84
  return valgen_1.isAny;
85
85
  }
86
- toJSON() {
86
+ toJSON(options) {
87
+ const superJson = super.toJSON(options);
88
+ const baseName = this.base
89
+ ? this.node.getDataTypeNameWithNs(this.base)
90
+ : undefined;
87
91
  const attributes = (0, objects_1.omitUndefined)(this.ownAttributes);
88
92
  let properties;
89
93
  if (this.properties && typeof this.properties.toJSON === 'function') {
90
- properties = this.properties.toJSON(this.properties, this.owner);
94
+ properties = this.properties.toJSON(this.properties, this.owner, options);
91
95
  }
92
96
  else
93
97
  properties = this.properties ? (0, index_js_1.cloneObject)(this.properties) : {};
94
- const baseName = this.base
95
- ? this.node.getDataTypeNameWithNs(this.base)
96
- : undefined;
97
- const out = (0, objects_1.omitUndefined)({
98
- ...data_type_js_1.DataType.prototype.toJSON.apply(this),
99
- base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
98
+ const out = {
99
+ ...superJson,
100
+ kind: this.kind,
101
+ base: baseName,
100
102
  attributes: attributes && Object.keys(attributes).length ? attributes : undefined,
101
103
  properties: Object.keys(properties).length ? properties : undefined,
102
- });
104
+ };
103
105
  if (Object.keys(this.ownNameMappings).length)
104
106
  out.nameMappings = { ...this.ownNameMappings };
105
107
  return (0, objects_1.omitUndefined)(out, true);
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiFieldDecorator = ApiFieldDecorator;
3
+ exports.ApiFieldDecoratorFactory = ApiFieldDecoratorFactory;
4
+ // import { omitUndefined } from '@jsopen/objects';
5
+ // import { StrictOmit } from 'ts-gems';
4
6
  const index_js_1 = require("../../schema/index.js");
5
7
  const constants_js_1 = require("../constants.js");
6
- function ApiFieldDecorator(options) {
7
- return function (target, propertyKey) {
8
+ function ApiFieldDecoratorFactory(options) {
9
+ const decoratorChain = [];
10
+ /**
11
+ *
12
+ */
13
+ const decorator = function (target, propertyKey) {
8
14
  if (typeof propertyKey !== 'string')
9
15
  throw new TypeError(`Symbol properties can't be used as a field`);
10
16
  const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) ||
@@ -14,6 +20,11 @@ function ApiFieldDecorator(options) {
14
20
  const designType = Reflect.getMetadata('design:type', target, propertyKey);
15
21
  const elemMeta = (metadata.fields[propertyKey] = {
16
22
  ...options,
23
+ scopePattern: options?.scopePattern
24
+ ? Array.isArray(options.scopePattern)
25
+ ? options.scopePattern
26
+ : [options.scopePattern]
27
+ : undefined,
17
28
  });
18
29
  if (designType === Array) {
19
30
  elemMeta.isArray = true;
@@ -21,5 +32,28 @@ function ApiFieldDecorator(options) {
21
32
  else
22
33
  elemMeta.type = elemMeta.type || designType;
23
34
  Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target.constructor);
35
+ for (const fn of decoratorChain)
36
+ fn(metadata, target);
24
37
  };
38
+ // /**
39
+ // *
40
+ // */
41
+ // decorator.Override = (
42
+ // scopes: (string | RegExp) | (string | RegExp)[],
43
+ // opts: StrictOmit<ApiField.Options, 'isArray' | 'type' | 'scopePattern'>,
44
+ // ): any => {
45
+ // decoratorChain.push((meta: ApiField.Metadata): void => {
46
+ // meta.overrides = meta.overrides || [];
47
+ // meta.overrides.push(
48
+ // omitUndefined({
49
+ // ...opts,
50
+ // scopes: Array.isArray(scopes) ? scopes : [scopes],
51
+ // type: undefined,
52
+ // isArray: undefined,
53
+ // }),
54
+ // );
55
+ // });
56
+ // return decorator;
57
+ // };
58
+ return decorator;
25
59
  }
@@ -14,7 +14,7 @@ function ComplexTypeDecorator(options) {
14
14
  name = options.name;
15
15
  }
16
16
  else {
17
- name = target.name.match(constants_js_1.EXTRACT_TYPENAME_PATTERN)?.[1] || target.name;
17
+ name = target.name;
18
18
  }
19
19
  }
20
20
  let metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target);
@@ -18,7 +18,7 @@ function SimpleTypeDecoratorFactory(options) {
18
18
  name = options.name;
19
19
  }
20
20
  else {
21
- name = target.name.match(constants_js_1.EXTRACT_TYPENAME_PATTERN)?.[1] || target.name;
21
+ name = target.name;
22
22
  name = name.toLowerCase();
23
23
  }
24
24
  }
@@ -28,6 +28,8 @@ function SimpleTypeDecoratorFactory(options) {
28
28
  metadata.kind = index_js_1.OpraSchema.SimpleType.Kind;
29
29
  metadata.name = name;
30
30
  Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target);
31
+ for (const fn of decoratorChain)
32
+ fn(metadata, target);
31
33
  };
32
34
  decorator.Example = (value, description) => {
33
35
  decoratorChain.push((meta) => {
@@ -23,7 +23,7 @@ class HttpApi extends api_base_js_1.ApiBase {
23
23
  const controller = this.findController(arg0);
24
24
  return controller?.operations.get(operationName);
25
25
  }
26
- toJSON() {
26
+ toJSON(options) {
27
27
  const schema = super.toJSON();
28
28
  const out = {
29
29
  ...schema,
@@ -32,7 +32,7 @@ class HttpApi extends api_base_js_1.ApiBase {
32
32
  controllers: {},
33
33
  };
34
34
  for (const v of this.controllers.values()) {
35
- out.controllers[v.name] = v.toJSON();
35
+ out.controllers[v.name] = v.toJSON(options);
36
36
  }
37
37
  return out;
38
38
  }
@@ -115,7 +115,7 @@ class HttpControllerClass extends document_element_js_1.DocumentElement {
115
115
  /**
116
116
  *
117
117
  */
118
- toJSON() {
118
+ toJSON(options) {
119
119
  const out = (0, objects_1.omitUndefined)({
120
120
  kind: this.kind,
121
121
  description: this.description,
@@ -124,25 +124,25 @@ class HttpControllerClass extends document_element_js_1.DocumentElement {
124
124
  if (this.operations.size) {
125
125
  out.operations = {};
126
126
  for (const v of this.operations.values()) {
127
- out.operations[v.name] = v.toJSON();
127
+ out.operations[v.name] = v.toJSON(options);
128
128
  }
129
129
  }
130
130
  if (this.controllers.size) {
131
131
  out.controllers = {};
132
132
  for (const v of this.controllers.values()) {
133
- out.controllers[v.name] = v.toJSON();
133
+ out.controllers[v.name] = v.toJSON(options);
134
134
  }
135
135
  }
136
136
  if (this.types.size) {
137
137
  out.types = {};
138
138
  for (const v of this.types.values()) {
139
- out.types[v.name] = v.toJSON();
139
+ out.types[v.name] = v.toJSON(options);
140
140
  }
141
141
  }
142
142
  if (this.parameters.length) {
143
143
  out.parameters = [];
144
144
  for (const prm of this.parameters) {
145
- out.parameters.push(prm.toJSON());
145
+ out.parameters.push(prm.toJSON(options));
146
146
  }
147
147
  }
148
148
  return out;
@@ -52,7 +52,7 @@ class HttpMediaTypeClass extends document_element_js_1.DocumentElement {
52
52
  }
53
53
  }
54
54
  }
55
- toJSON() {
55
+ toJSON(options) {
56
56
  const typeName = this.type
57
57
  ? this.node.getDataTypeNameWithNs(this.type)
58
58
  : undefined;
@@ -60,7 +60,7 @@ class HttpMediaTypeClass extends document_element_js_1.DocumentElement {
60
60
  description: this.description,
61
61
  contentType: this.contentType,
62
62
  contentEncoding: this.contentEncoding,
63
- type: typeName ? typeName : this.type?.toJSON(),
63
+ type: typeName ? typeName : this.type?.toJSON(options),
64
64
  isArray: this.isArray,
65
65
  example: this.example,
66
66
  examples: this.examples,
@@ -71,7 +71,7 @@ class HttpMediaTypeClass extends document_element_js_1.DocumentElement {
71
71
  maxTotalFileSize: this.maxTotalFileSize,
72
72
  });
73
73
  if (this.multipartFields?.length) {
74
- out.multipartFields = this.multipartFields.map(x => x.toJSON());
74
+ out.multipartFields = this.multipartFields.map(x => x.toJSON(options));
75
75
  }
76
76
  return out;
77
77
  }
@@ -20,12 +20,12 @@ class HttpMultipartField extends http_media_type_js_1.HttpMediaType {
20
20
  this.fieldType = initArgs.fieldType;
21
21
  this.required = initArgs.required;
22
22
  }
23
- toJSON() {
23
+ toJSON(options) {
24
24
  return (0, objects_1.omitUndefined)({
25
25
  fieldName: this.fieldName,
26
26
  fieldType: this.fieldType,
27
27
  required: this.required,
28
- ...super.toJSON(),
28
+ ...super.toJSON(options),
29
29
  });
30
30
  }
31
31
  }
@@ -26,10 +26,10 @@ class HttpOperationResponse extends http_media_type_js_1.HttpMediaType {
26
26
  }
27
27
  }
28
28
  }
29
- toJSON() {
29
+ toJSON(options) {
30
30
  const statusCode = this.statusCode.map(x => x.toJSON());
31
31
  const out = (0, objects_1.omitUndefined)({
32
- ...super.toJSON(),
32
+ ...super.toJSON(options),
33
33
  statusCode: statusCode.length === 1 && typeof statusCode[0] === 'number'
34
34
  ? statusCode[0]
35
35
  : statusCode,
@@ -38,7 +38,7 @@ class HttpOperationResponse extends http_media_type_js_1.HttpMediaType {
38
38
  if (this.parameters.length) {
39
39
  out.parameters = [];
40
40
  for (const prm of this.parameters) {
41
- out.parameters.push(prm.toJSON());
41
+ out.parameters.push(prm.toJSON(options));
42
42
  }
43
43
  }
44
44
  return out;
@@ -71,7 +71,7 @@ class HttpOperationClass extends document_element_js_1.DocumentElement {
71
71
  }
72
72
  return this.path || '/';
73
73
  }
74
- toJSON() {
74
+ toJSON(options) {
75
75
  const out = (0, objects_1.omitUndefined)({
76
76
  kind: index_js_2.OpraSchema.HttpOperation.Kind,
77
77
  description: this.description,
@@ -79,22 +79,22 @@ class HttpOperationClass extends document_element_js_1.DocumentElement {
79
79
  path: this.path,
80
80
  mergePath: this.mergePath,
81
81
  composition: this.composition,
82
- requestBody: this.requestBody?.toJSON(),
82
+ requestBody: this.requestBody?.toJSON(options),
83
83
  });
84
84
  if (this.types.size) {
85
85
  out.types = {};
86
86
  for (const v of this.types.values()) {
87
- out.types[v.name] = v.toJSON();
87
+ out.types[v.name] = v.toJSON(options);
88
88
  }
89
89
  }
90
90
  if (this.parameters.length) {
91
91
  out.parameters = [];
92
92
  for (const prm of this.parameters) {
93
- out.parameters.push(prm.toJSON());
93
+ out.parameters.push(prm.toJSON(options));
94
94
  }
95
95
  }
96
96
  if (this.responses.length)
97
- out.responses = this.responses.map(r => r.toJSON());
97
+ out.responses = this.responses.map(r => r.toJSON(options));
98
98
  return out;
99
99
  }
100
100
  }
@@ -33,9 +33,9 @@ exports.HttpParameter = function (owner, initArgs) {
33
33
  * @class HttpParameter
34
34
  */
35
35
  class HttpParameterClass extends value_js_1.Value {
36
- toJSON() {
36
+ toJSON(options) {
37
37
  return (0, objects_1.omitUndefined)({
38
- ...super.toJSON(),
38
+ ...super.toJSON(options),
39
39
  name: this.name,
40
40
  location: this.location,
41
41
  arraySeparator: this.arraySeparator,
@@ -11,12 +11,14 @@ class HttpRequestBody extends document_element_js_1.DocumentElement {
11
11
  super(owner);
12
12
  this.content = [];
13
13
  }
14
- toJSON() {
14
+ toJSON(options) {
15
15
  return (0, objects_1.omitUndefined)({
16
16
  description: this.description,
17
17
  required: this.required,
18
18
  maxContentSize: this.maxContentSize,
19
- content: this.content.length ? this.content.map(x => x.toJSON()) : [],
19
+ content: this.content.length
20
+ ? this.content.map(x => x.toJSON(options))
21
+ : [],
20
22
  partial: this.partial,
21
23
  allowPatchOperators: this.allowPatchOperators,
22
24
  });
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testScopeMatch = testScopeMatch;
4
+ function testScopeMatch(scope, pattern) {
5
+ if (!(scope && pattern))
6
+ return true;
7
+ if (Array.isArray(pattern)) {
8
+ return pattern.some(x => {
9
+ return typeof x === 'string' ? scope === x : x.test(scope);
10
+ });
11
+ }
12
+ return typeof pattern === 'string' ? scope === pattern : pattern.test(scope);
13
+ }
@@ -32,11 +32,11 @@ class FilterRules {
32
32
  operators,
33
33
  }));
34
34
  }
35
- normalizeFilter(filter, currentType) {
35
+ normalizeFilter(filter, currentType, scope) {
36
36
  const ast = typeof filter === 'string' ? (0, parse_js_1.parse)(filter) : filter;
37
- return this.normalizeFilterAst(ast, [], currentType);
37
+ return this.normalizeFilterAst(ast, [], currentType, scope);
38
38
  }
39
- normalizeFilterAst(ast, stack, currentType) {
39
+ normalizeFilterAst(ast, stack, currentType, scope) {
40
40
  if (ast instanceof index_js_4.ComparisonExpression) {
41
41
  stack.push(ast);
42
42
  this.normalizeFilterAst(ast.left, stack, currentType);
@@ -99,8 +99,8 @@ class FilterRules {
99
99
  return ast;
100
100
  }
101
101
  if (ast instanceof index_js_4.QualifiedIdentifier && currentType) {
102
- ast.value = currentType.normalizeFieldPath(ast.value);
103
- ast.field = currentType.getField(ast.value);
102
+ ast.value = currentType.normalizeFieldPath(ast.value, { scope });
103
+ ast.field = currentType.getField(ast.value, scope);
104
104
  ast.dataType = ast.field.type;
105
105
  return ast;
106
106
  }
@@ -128,9 +128,9 @@ class FilterRules {
128
128
  decoder = this._decoderCache.get(comp.left.field);
129
129
  if (!decoder) {
130
130
  decoder = comp.left.field.type.generateCodec('decode', {
131
+ scope,
131
132
  projection: '*',
132
133
  ignoreWriteonlyFields: true,
133
- ignoreHiddenFields: true,
134
134
  coerce: true,
135
135
  });
136
136
  this._decoderCache.set(comp.left.field, decoder);
@@ -64,7 +64,7 @@ export class ApiDocument extends DocumentElement {
64
64
  /**
65
65
  * Export as Opra schema definition object
66
66
  */
67
- export() {
67
+ export(options) {
68
68
  const out = omitUndefined({
69
69
  spec: OpraSchema.SpecVersion,
70
70
  id: this.id,
@@ -90,25 +90,29 @@ export class ApiDocument extends DocumentElement {
90
90
  if (this.types.size) {
91
91
  out.types = {};
92
92
  for (const v of this.types.values()) {
93
- out.types[v.name] = v.toJSON();
93
+ if (options?.scope && !v.inScope(options?.scope))
94
+ continue;
95
+ out.types[v.name] = v.toJSON(options);
94
96
  }
95
97
  }
96
98
  if (this.api)
97
- out.api = this.api.toJSON();
99
+ out.api = this.api.toJSON(options);
98
100
  return out;
99
101
  }
100
102
  invalidate() {
101
103
  /** Generate id */
102
- const x = this.export();
104
+ const x = this.export({});
103
105
  delete x.id;
104
106
  this.id = md5(JSON.stringify(x));
105
107
  /** Clear [kTypeNSMap] */
106
108
  this[kTypeNSMap] = new WeakMap();
107
109
  }
108
- _findDataType(nameOrCtor, visitedRefs) {
110
+ _findDataType(nameOrCtor, scope, visitedRefs) {
109
111
  let result = this.types.get(nameOrCtor);
110
- if (result || !this.references.size)
112
+ if (result && (!scope || result.inScope(scope)))
111
113
  return result;
114
+ if (!this.references.size)
115
+ return;
112
116
  // Lookup for references
113
117
  if (typeof nameOrCtor === 'string') {
114
118
  // If given string has namespace pattern (ns:type_name)
@@ -122,7 +126,7 @@ export class ApiDocument extends DocumentElement {
122
126
  visitedRefs = visitedRefs || new WeakMap();
123
127
  visitedRefs.set(this, true);
124
128
  visitedRefs.set(ref, true);
125
- return ref._findDataType(m[2], visitedRefs);
129
+ return ref._findDataType(m[2], scope, visitedRefs);
126
130
  }
127
131
  nameOrCtor = m[2];
128
132
  }
@@ -144,7 +148,7 @@ export class ApiDocument extends DocumentElement {
144
148
  for (const refNs of references) {
145
149
  const ref = this.references.get(refNs);
146
150
  visitedRefs.set(ref, true);
147
- result = ref._findDataType(nameOrCtor, visitedRefs);
151
+ result = ref._findDataType(nameOrCtor, scope, visitedRefs);
148
152
  if (result) {
149
153
  this[kTypeNSMap].set(result, ref?.[BUILTIN] ? '' : refNs);
150
154
  return result;
@@ -8,7 +8,8 @@ export class ApiBase extends DocumentElement {
8
8
  this.name = init.name;
9
9
  this.description = init.description;
10
10
  }
11
- toJSON() {
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ toJSON(options) {
12
13
  return omitUndefined({
13
14
  transport: this.transport,
14
15
  name: this.name,