@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
@@ -16,6 +16,7 @@ let AnyType = class AnyType {
16
16
  };
17
17
  AnyType = __decorate([
18
18
  SimpleType({
19
+ name: 'any',
19
20
  description: 'Represents any value',
20
21
  }),
21
22
  __metadata("design:paramtypes", [Object])
@@ -23,6 +23,7 @@ let BigintType = class BigintType extends NumberType {
23
23
  };
24
24
  BigintType = __decorate([
25
25
  SimpleType({
26
+ name: 'bigint',
26
27
  description: 'BigInt number',
27
28
  nameMappings: {
28
29
  js: 'bigint',
@@ -16,6 +16,7 @@ let BooleanType = class BooleanType {
16
16
  };
17
17
  BooleanType = __decorate([
18
18
  SimpleType({
19
+ name: 'boolean',
19
20
  description: 'Simple true/false value',
20
21
  nameMappings: {
21
22
  js: 'boolean',
@@ -23,6 +23,7 @@ let IntegerType = class IntegerType extends NumberType {
23
23
  };
24
24
  IntegerType = __decorate([
25
25
  SimpleType({
26
+ name: 'integer',
26
27
  description: 'An integer number',
27
28
  nameMappings: {
28
29
  js: 'number',
@@ -16,6 +16,7 @@ let NullType = class NullType {
16
16
  };
17
17
  NullType = __decorate([
18
18
  SimpleType({
19
+ name: 'null',
19
20
  description: 'A Null value',
20
21
  nameMappings: {
21
22
  js: 'null',
@@ -35,6 +35,7 @@ __decorate([
35
35
  ], NumberType.prototype, "maxValue", void 0);
36
36
  NumberType = __decorate([
37
37
  SimpleType({
38
+ name: 'number',
38
39
  description: 'Both Integer as well as Floating-Point numbers',
39
40
  nameMappings: {
40
41
  js: 'number',
@@ -55,6 +55,7 @@ __decorate([
55
55
  ], StringType.prototype, "maxLength", void 0);
56
56
  StringType = __decorate([
57
57
  SimpleType({
58
+ name: 'string',
58
59
  description: 'A sequence of characters',
59
60
  nameMappings: {
60
61
  js: 'string',
@@ -67,7 +67,7 @@ class SimpleTypeClass extends DataType {
67
67
  let t = this;
68
68
  while (t) {
69
69
  if (t._generateDecoder)
70
- return t._generateDecoder(prop, options?.documentElement || this.owner);
70
+ return t._generateDecoder(prop, options?.documentElement || this.owner, options?.scope);
71
71
  t = this.base;
72
72
  }
73
73
  return isAny;
@@ -75,28 +75,30 @@ class SimpleTypeClass extends DataType {
75
75
  let t = this;
76
76
  while (t) {
77
77
  if (t._generateEncoder)
78
- return t._generateEncoder(prop, options?.documentElement || this.owner);
78
+ return t._generateEncoder(prop, options?.documentElement || this.owner, options?.scope);
79
79
  t = this.base;
80
80
  }
81
81
  return isAny;
82
82
  }
83
- toJSON() {
83
+ toJSON(options) {
84
+ const superJson = super.toJSON(options);
85
+ const baseName = this.base
86
+ ? this.node.getDataTypeNameWithNs(this.base)
87
+ : undefined;
84
88
  const attributes = omitUndefined(this.ownAttributes);
85
89
  let properties;
86
90
  if (this.properties && typeof this.properties.toJSON === 'function') {
87
- properties = this.properties.toJSON(this.properties, this.owner);
91
+ properties = this.properties.toJSON(this.properties, this.owner, options);
88
92
  }
89
93
  else
90
94
  properties = this.properties ? cloneObject(this.properties) : {};
91
- const baseName = this.base
92
- ? this.node.getDataTypeNameWithNs(this.base)
93
- : undefined;
94
- const out = omitUndefined({
95
- ...DataType.prototype.toJSON.apply(this),
96
- base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
95
+ const out = {
96
+ ...superJson,
97
+ kind: this.kind,
98
+ base: baseName,
97
99
  attributes: attributes && Object.keys(attributes).length ? attributes : undefined,
98
100
  properties: Object.keys(properties).length ? properties : undefined,
99
- });
101
+ };
100
102
  if (Object.keys(this.ownNameMappings).length)
101
103
  out.nameMappings = { ...this.ownNameMappings };
102
104
  return omitUndefined(out, true);
@@ -1,7 +1,13 @@
1
+ // import { omitUndefined } from '@jsopen/objects';
2
+ // import { StrictOmit } from 'ts-gems';
1
3
  import { OpraSchema } from '../../schema/index.js';
2
4
  import { DATATYPE_METADATA } from '../constants.js';
3
- export function ApiFieldDecorator(options) {
4
- return function (target, propertyKey) {
5
+ export function ApiFieldDecoratorFactory(options) {
6
+ const decoratorChain = [];
7
+ /**
8
+ *
9
+ */
10
+ const decorator = function (target, propertyKey) {
5
11
  if (typeof propertyKey !== 'string')
6
12
  throw new TypeError(`Symbol properties can't be used as a field`);
7
13
  const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target.constructor) ||
@@ -11,6 +17,11 @@ export function ApiFieldDecorator(options) {
11
17
  const designType = Reflect.getMetadata('design:type', target, propertyKey);
12
18
  const elemMeta = (metadata.fields[propertyKey] = {
13
19
  ...options,
20
+ scopePattern: options?.scopePattern
21
+ ? Array.isArray(options.scopePattern)
22
+ ? options.scopePattern
23
+ : [options.scopePattern]
24
+ : undefined,
14
25
  });
15
26
  if (designType === Array) {
16
27
  elemMeta.isArray = true;
@@ -18,5 +29,28 @@ export function ApiFieldDecorator(options) {
18
29
  else
19
30
  elemMeta.type = elemMeta.type || designType;
20
31
  Reflect.defineMetadata(DATATYPE_METADATA, metadata, target.constructor);
32
+ for (const fn of decoratorChain)
33
+ fn(metadata, target);
21
34
  };
35
+ // /**
36
+ // *
37
+ // */
38
+ // decorator.Override = (
39
+ // scopes: (string | RegExp) | (string | RegExp)[],
40
+ // opts: StrictOmit<ApiField.Options, 'isArray' | 'type' | 'scopePattern'>,
41
+ // ): any => {
42
+ // decoratorChain.push((meta: ApiField.Metadata): void => {
43
+ // meta.overrides = meta.overrides || [];
44
+ // meta.overrides.push(
45
+ // omitUndefined({
46
+ // ...opts,
47
+ // scopes: Array.isArray(scopes) ? scopes : [scopes],
48
+ // type: undefined,
49
+ // isArray: undefined,
50
+ // }),
51
+ // );
52
+ // });
53
+ // return decorator;
54
+ // };
55
+ return decorator;
22
56
  }
@@ -1,6 +1,6 @@
1
1
  import { omit } from '@jsopen/objects';
2
2
  import { OpraSchema } from '../../schema/index.js';
3
- import { CLASS_NAME_PATTERN, DATATYPE_METADATA, EXTRACT_TYPENAME_PATTERN, } from '../constants.js';
3
+ import { CLASS_NAME_PATTERN, DATATYPE_METADATA } from '../constants.js';
4
4
  export function ComplexTypeDecorator(options) {
5
5
  return function (target) {
6
6
  let name;
@@ -11,7 +11,7 @@ export function ComplexTypeDecorator(options) {
11
11
  name = options.name;
12
12
  }
13
13
  else {
14
- name = target.name.match(EXTRACT_TYPENAME_PATTERN)?.[1] || target.name;
14
+ name = target.name;
15
15
  }
16
16
  }
17
17
  let metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target);
@@ -1,5 +1,5 @@
1
1
  import { OpraSchema } from '../../schema/index.js';
2
- import { CLASS_NAME_PATTERN, DATATYPE_METADATA, EXTRACT_TYPENAME_PATTERN, } from '../constants.js';
2
+ import { CLASS_NAME_PATTERN, DATATYPE_METADATA } from '../constants.js';
3
3
  export function SimpleTypeDecoratorFactory(options) {
4
4
  const decoratorChain = [];
5
5
  /**
@@ -14,7 +14,7 @@ export function SimpleTypeDecoratorFactory(options) {
14
14
  name = options.name;
15
15
  }
16
16
  else {
17
- name = target.name.match(EXTRACT_TYPENAME_PATTERN)?.[1] || target.name;
17
+ name = target.name;
18
18
  name = name.toLowerCase();
19
19
  }
20
20
  }
@@ -24,6 +24,8 @@ export function SimpleTypeDecoratorFactory(options) {
24
24
  metadata.kind = OpraSchema.SimpleType.Kind;
25
25
  metadata.name = name;
26
26
  Reflect.defineMetadata(DATATYPE_METADATA, metadata, target);
27
+ for (const fn of decoratorChain)
28
+ fn(metadata, target);
27
29
  };
28
30
  decorator.Example = (value, description) => {
29
31
  decoratorChain.push((meta) => {
@@ -20,7 +20,7 @@ export class HttpApi extends ApiBase {
20
20
  const controller = this.findController(arg0);
21
21
  return controller?.operations.get(operationName);
22
22
  }
23
- toJSON() {
23
+ toJSON(options) {
24
24
  const schema = super.toJSON();
25
25
  const out = {
26
26
  ...schema,
@@ -29,7 +29,7 @@ export class HttpApi extends ApiBase {
29
29
  controllers: {},
30
30
  };
31
31
  for (const v of this.controllers.values()) {
32
- out.controllers[v.name] = v.toJSON();
32
+ out.controllers[v.name] = v.toJSON(options);
33
33
  }
34
34
  return out;
35
35
  }
@@ -111,7 +111,7 @@ class HttpControllerClass extends DocumentElement {
111
111
  /**
112
112
  *
113
113
  */
114
- toJSON() {
114
+ toJSON(options) {
115
115
  const out = omitUndefined({
116
116
  kind: this.kind,
117
117
  description: this.description,
@@ -120,25 +120,25 @@ class HttpControllerClass extends DocumentElement {
120
120
  if (this.operations.size) {
121
121
  out.operations = {};
122
122
  for (const v of this.operations.values()) {
123
- out.operations[v.name] = v.toJSON();
123
+ out.operations[v.name] = v.toJSON(options);
124
124
  }
125
125
  }
126
126
  if (this.controllers.size) {
127
127
  out.controllers = {};
128
128
  for (const v of this.controllers.values()) {
129
- out.controllers[v.name] = v.toJSON();
129
+ out.controllers[v.name] = v.toJSON(options);
130
130
  }
131
131
  }
132
132
  if (this.types.size) {
133
133
  out.types = {};
134
134
  for (const v of this.types.values()) {
135
- out.types[v.name] = v.toJSON();
135
+ out.types[v.name] = v.toJSON(options);
136
136
  }
137
137
  }
138
138
  if (this.parameters.length) {
139
139
  out.parameters = [];
140
140
  for (const prm of this.parameters) {
141
- out.parameters.push(prm.toJSON());
141
+ out.parameters.push(prm.toJSON(options));
142
142
  }
143
143
  }
144
144
  return out;
@@ -48,7 +48,7 @@ class HttpMediaTypeClass extends DocumentElement {
48
48
  }
49
49
  }
50
50
  }
51
- toJSON() {
51
+ toJSON(options) {
52
52
  const typeName = this.type
53
53
  ? this.node.getDataTypeNameWithNs(this.type)
54
54
  : undefined;
@@ -56,7 +56,7 @@ class HttpMediaTypeClass extends DocumentElement {
56
56
  description: this.description,
57
57
  contentType: this.contentType,
58
58
  contentEncoding: this.contentEncoding,
59
- type: typeName ? typeName : this.type?.toJSON(),
59
+ type: typeName ? typeName : this.type?.toJSON(options),
60
60
  isArray: this.isArray,
61
61
  example: this.example,
62
62
  examples: this.examples,
@@ -67,7 +67,7 @@ class HttpMediaTypeClass extends DocumentElement {
67
67
  maxTotalFileSize: this.maxTotalFileSize,
68
68
  });
69
69
  if (this.multipartFields?.length) {
70
- out.multipartFields = this.multipartFields.map(x => x.toJSON());
70
+ out.multipartFields = this.multipartFields.map(x => x.toJSON(options));
71
71
  }
72
72
  return out;
73
73
  }
@@ -17,12 +17,12 @@ export class HttpMultipartField extends HttpMediaType {
17
17
  this.fieldType = initArgs.fieldType;
18
18
  this.required = initArgs.required;
19
19
  }
20
- toJSON() {
20
+ toJSON(options) {
21
21
  return omitUndefined({
22
22
  fieldName: this.fieldName,
23
23
  fieldType: this.fieldType,
24
24
  required: this.required,
25
- ...super.toJSON(),
25
+ ...super.toJSON(options),
26
26
  });
27
27
  }
28
28
  }
@@ -23,10 +23,10 @@ export class HttpOperationResponse extends HttpMediaType {
23
23
  }
24
24
  }
25
25
  }
26
- toJSON() {
26
+ toJSON(options) {
27
27
  const statusCode = this.statusCode.map(x => x.toJSON());
28
28
  const out = omitUndefined({
29
- ...super.toJSON(),
29
+ ...super.toJSON(options),
30
30
  statusCode: statusCode.length === 1 && typeof statusCode[0] === 'number'
31
31
  ? statusCode[0]
32
32
  : statusCode,
@@ -35,7 +35,7 @@ export class HttpOperationResponse extends HttpMediaType {
35
35
  if (this.parameters.length) {
36
36
  out.parameters = [];
37
37
  for (const prm of this.parameters) {
38
- out.parameters.push(prm.toJSON());
38
+ out.parameters.push(prm.toJSON(options));
39
39
  }
40
40
  }
41
41
  return out;
@@ -67,7 +67,7 @@ class HttpOperationClass extends DocumentElement {
67
67
  }
68
68
  return this.path || '/';
69
69
  }
70
- toJSON() {
70
+ toJSON(options) {
71
71
  const out = omitUndefined({
72
72
  kind: OpraSchema.HttpOperation.Kind,
73
73
  description: this.description,
@@ -75,22 +75,22 @@ class HttpOperationClass extends DocumentElement {
75
75
  path: this.path,
76
76
  mergePath: this.mergePath,
77
77
  composition: this.composition,
78
- requestBody: this.requestBody?.toJSON(),
78
+ requestBody: this.requestBody?.toJSON(options),
79
79
  });
80
80
  if (this.types.size) {
81
81
  out.types = {};
82
82
  for (const v of this.types.values()) {
83
- out.types[v.name] = v.toJSON();
83
+ out.types[v.name] = v.toJSON(options);
84
84
  }
85
85
  }
86
86
  if (this.parameters.length) {
87
87
  out.parameters = [];
88
88
  for (const prm of this.parameters) {
89
- out.parameters.push(prm.toJSON());
89
+ out.parameters.push(prm.toJSON(options));
90
90
  }
91
91
  }
92
92
  if (this.responses.length)
93
- out.responses = this.responses.map(r => r.toJSON());
93
+ out.responses = this.responses.map(r => r.toJSON(options));
94
94
  return out;
95
95
  }
96
96
  }
@@ -30,9 +30,9 @@ export const HttpParameter = function (owner, initArgs) {
30
30
  * @class HttpParameter
31
31
  */
32
32
  class HttpParameterClass extends Value {
33
- toJSON() {
33
+ toJSON(options) {
34
34
  return omitUndefined({
35
- ...super.toJSON(),
35
+ ...super.toJSON(options),
36
36
  name: this.name,
37
37
  location: this.location,
38
38
  arraySeparator: this.arraySeparator,
@@ -8,12 +8,14 @@ export class HttpRequestBody extends DocumentElement {
8
8
  super(owner);
9
9
  this.content = [];
10
10
  }
11
- toJSON() {
11
+ toJSON(options) {
12
12
  return omitUndefined({
13
13
  description: this.description,
14
14
  required: this.required,
15
15
  maxContentSize: this.maxContentSize,
16
- content: this.content.length ? this.content.map(x => x.toJSON()) : [],
16
+ content: this.content.length
17
+ ? this.content.map(x => x.toJSON(options))
18
+ : [],
17
19
  partial: this.partial,
18
20
  allowPatchOperators: this.allowPatchOperators,
19
21
  });
@@ -0,0 +1,10 @@
1
+ export function testScopeMatch(scope, pattern) {
2
+ if (!(scope && pattern))
3
+ return true;
4
+ if (Array.isArray(pattern)) {
5
+ return pattern.some(x => {
6
+ return typeof x === 'string' ? scope === x : x.test(scope);
7
+ });
8
+ }
9
+ return typeof pattern === 'string' ? scope === pattern : pattern.test(scope);
10
+ }
@@ -29,11 +29,11 @@ export class FilterRules {
29
29
  operators,
30
30
  }));
31
31
  }
32
- normalizeFilter(filter, currentType) {
32
+ normalizeFilter(filter, currentType, scope) {
33
33
  const ast = typeof filter === 'string' ? parse(filter) : filter;
34
- return this.normalizeFilterAst(ast, [], currentType);
34
+ return this.normalizeFilterAst(ast, [], currentType, scope);
35
35
  }
36
- normalizeFilterAst(ast, stack, currentType) {
36
+ normalizeFilterAst(ast, stack, currentType, scope) {
37
37
  if (ast instanceof ComparisonExpression) {
38
38
  stack.push(ast);
39
39
  this.normalizeFilterAst(ast.left, stack, currentType);
@@ -96,8 +96,8 @@ export class FilterRules {
96
96
  return ast;
97
97
  }
98
98
  if (ast instanceof QualifiedIdentifier && currentType) {
99
- ast.value = currentType.normalizeFieldPath(ast.value);
100
- ast.field = currentType.getField(ast.value);
99
+ ast.value = currentType.normalizeFieldPath(ast.value, { scope });
100
+ ast.field = currentType.getField(ast.value, scope);
101
101
  ast.dataType = ast.field.type;
102
102
  return ast;
103
103
  }
@@ -125,9 +125,9 @@ export class FilterRules {
125
125
  decoder = this._decoderCache.get(comp.left.field);
126
126
  if (!decoder) {
127
127
  decoder = comp.left.field.type.generateCodec('decode', {
128
+ scope,
128
129
  projection: '*',
129
130
  ignoreWriteonlyFields: true,
130
- ignoreHiddenFields: true,
131
131
  coerce: true,
132
132
  });
133
133
  this._decoderCache.set(comp.left.field, decoder);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "1.4.4",
3
+ "version": "1.5.1",
4
4
  "description": "Opra common package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -33,7 +33,12 @@ export declare class ApiDocument extends DocumentElement {
33
33
  /**
34
34
  * Export as Opra schema definition object
35
35
  */
36
- export(): OpraSchema.ApiDocument;
36
+ export(options?: ApiDocument.ExportOptions): OpraSchema.ApiDocument;
37
37
  invalidate(): void;
38
- protected _findDataType(nameOrCtor: string | Type | Function | EnumType.EnumArray | EnumType.EnumObject, visitedRefs?: WeakMap<ApiDocument, boolean>): DataType | undefined;
38
+ protected _findDataType(nameOrCtor: string | Type | Function | EnumType.EnumArray | EnumType.EnumObject, scope?: string, visitedRefs?: WeakMap<ApiDocument, boolean>): DataType | undefined;
39
+ }
40
+ export declare namespace ApiDocument {
41
+ interface ExportOptions {
42
+ scope?: string;
43
+ }
39
44
  }
@@ -13,6 +13,6 @@ export declare abstract class ApiBase extends DocumentElement {
13
13
  name: string;
14
14
  description?: string;
15
15
  protected constructor(init: ApiBase.InitArguments);
16
- toJSON(): OpraSchema.Api;
16
+ toJSON(options?: ApiDocument.ExportOptions): OpraSchema.Api;
17
17
  protected _initialize(init: ApiBase.InitArguments, context: DocumentInitContext): Promise<void>;
18
18
  }
@@ -2,6 +2,7 @@ import { OpraDocumentError } from './opra-document-error.js';
2
2
  export declare namespace DocumentInitContext {
3
3
  interface Options {
4
4
  maxErrors?: number;
5
+ scopes?: string | string[];
5
6
  }
6
7
  }
7
8
  export declare class DocumentInitContext {
@@ -19,47 +19,41 @@ export declare class DocumentNode {
19
19
  readonly element: DocumentElement;
20
20
  constructor(element: DocumentElement, parent?: DocumentNode);
21
21
  getDocument(): ApiDocument;
22
- hasDataType(nameOrCtor: string | Type | Function | object | any[]): boolean;
23
- findDataType(nameOrCtor: string | Type | Function | object | any[]): DataType | undefined;
22
+ hasDataType(nameOrCtor: string | Type | Function | object | any[], scope?: string): boolean;
23
+ findDataType(nameOrCtor: string | Type | Function | object | any[], scope?: string): DataType | undefined;
24
24
  /**
25
25
  * Returns DataType instance by name or Constructor. Returns undefined if not found
26
- * @param nameOrCtor
27
26
  */
28
- getDataType(nameOrCtor: string | Type | Function | object | any[]): DataType;
27
+ getDataType(nameOrCtor: string | Type | Function | object | any[], scope?: string): DataType;
29
28
  getDataTypeNameWithNs(dataType: DataType): string | undefined;
30
29
  /**
31
30
  * Returns ComplexType instance by name or Constructor.
32
31
  * Returns undefined if not found
33
32
  * Throws error if data type is not a ComplexType
34
- * @param nameOrCtor
35
33
  */
36
- getComplexType(nameOrCtor: string | Type | Function): ComplexType;
34
+ getComplexType(nameOrCtor: string | Type | Function, scope?: string): ComplexType;
37
35
  /**
38
36
  * Returns SimpleType instance by name or Constructor.
39
37
  * Returns undefined if not found
40
38
  * Throws error if data type is not a SimpleType
41
- * @param nameOrCtor
42
39
  */
43
- getSimpleType(nameOrCtor: string | Type): SimpleType;
40
+ getSimpleType(nameOrCtor: string | Type, scope?: string): SimpleType;
44
41
  /**
45
42
  * Returns EnumType instance by name or Constructor.
46
43
  * Returns undefined if not found
47
44
  * Throws error if data type is not a EnumType
48
- * @param nameOrCtor
49
45
  */
50
- getEnumType(nameOrCtor: string | object | any[]): EnumType;
46
+ getEnumType(nameOrCtor: string | object | any[], scope?: string): EnumType;
51
47
  /**
52
48
  * Returns EnumType instance by name or Constructor.
53
49
  * Returns undefined if not found
54
50
  * Throws error if data type is not a MappedType
55
- * @param nameOrCtor
56
51
  */
57
- getMappedType(nameOrCtor: string | object | any[]): MappedType;
52
+ getMappedType(nameOrCtor: string | object | any[], scope?: string): MappedType;
58
53
  /**
59
54
  * Returns EnumType instance by name or Constructor.
60
55
  * Returns undefined if not found
61
56
  * Throws error if data type is not a MixinType
62
- * @param nameOrCtor
63
57
  */
64
- getMixinType(nameOrCtor: string | object | any[]): MixinType;
58
+ getMixinType(nameOrCtor: string | object | any[], scope?: string): MixinType;
65
59
  }
@@ -1,5 +1,6 @@
1
1
  import type { Combine, StrictOmit, TypeThunkAsync } from 'ts-gems';
2
2
  import type { OpraSchema } from '../../schema/index.js';
3
+ import type { ApiDocument } from '../api-document';
3
4
  import { DataType } from '../data-type/data-type.js';
4
5
  import type { EnumType } from '../data-type/enum-type.js';
5
6
  import { DocumentElement } from './document-element.js';
@@ -43,6 +44,6 @@ declare class ValueClass extends DocumentElement {
43
44
  description?: string;
44
45
  examples?: any[] | Record<string, any>;
45
46
  isArray?: boolean;
46
- toJSON(): OpraSchema.Value;
47
+ toJSON(options?: ApiDocument.ExportOptions): OpraSchema.Value;
47
48
  }
48
49
  export {};
@@ -7,7 +7,6 @@ export declare const DECORATOR: unique symbol;
7
7
  export declare const BUILTIN: unique symbol;
8
8
  export declare const NAMESPACE_PATTERN: RegExp;
9
9
  export declare const CLASS_NAME_PATTERN: RegExp;
10
- export declare const EXTRACT_TYPENAME_PATTERN: RegExp;
11
10
  export declare const kDataTypeMap: unique symbol;
12
11
  export declare const kCtorMap: unique symbol;
13
12
  export declare const kTypeNSMap: unique symbol;