@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.
- package/browser/index.cjs +5 -5
- package/browser/index.mjs +5 -5
- package/cjs/document/api-document.js +12 -8
- package/cjs/document/common/api-base.js +2 -1
- package/cjs/document/common/document-node.js +24 -29
- package/cjs/document/common/value.js +6 -2
- package/cjs/document/constants.js +1 -2
- package/cjs/document/data-type/api-field.js +12 -8
- package/cjs/document/data-type/complex-type-base.js +22 -11
- package/cjs/document/data-type/complex-type.js +22 -8
- package/cjs/document/data-type/data-type.js +14 -1
- package/cjs/document/data-type/enum-type.js +13 -3
- package/cjs/document/data-type/extended-types/base64.type.js +1 -0
- package/cjs/document/data-type/extended-types/date-string.type.js +1 -0
- package/cjs/document/data-type/extended-types/date-time-string.type.js +1 -0
- package/cjs/document/data-type/extended-types/date-time.type.js +1 -0
- package/cjs/document/data-type/extended-types/date.type.js +1 -0
- package/cjs/document/data-type/extended-types/email.type.js +1 -0
- package/cjs/document/data-type/extended-types/field-path.type.js +10 -6
- package/cjs/document/data-type/extended-types/filter.type.js +11 -4
- package/cjs/document/data-type/extended-types/object-id.type.js +1 -0
- package/cjs/document/data-type/extended-types/operation-result.type.js +1 -0
- package/cjs/document/data-type/extended-types/time.type.js +1 -0
- package/cjs/document/data-type/extended-types/url.type.js +1 -0
- package/cjs/document/data-type/extended-types/uuid.type.js +1 -0
- package/cjs/document/data-type/mapped-type.js +12 -3
- package/cjs/document/data-type/mixin-type.js +17 -5
- package/cjs/document/data-type/primitive-types/any.type.js +1 -0
- package/cjs/document/data-type/primitive-types/bigint.type.js +1 -0
- package/cjs/document/data-type/primitive-types/boolean.type.js +1 -0
- package/cjs/document/data-type/primitive-types/integer.type.js +1 -0
- package/cjs/document/data-type/primitive-types/null.type.js +1 -0
- package/cjs/document/data-type/primitive-types/number.type.js +1 -0
- package/cjs/document/data-type/primitive-types/string.type.js +1 -0
- package/cjs/document/data-type/simple-type.js +13 -11
- package/cjs/document/decorators/api-field-decorator.js +37 -3
- package/cjs/document/decorators/complex-type.decorator.js +1 -1
- package/cjs/document/decorators/simple-type.decorator.js +3 -1
- package/cjs/document/http/http-api.js +2 -2
- package/cjs/document/http/http-controller.js +5 -5
- package/cjs/document/http/http-media-type.js +3 -3
- package/cjs/document/http/http-multipart-field.js +2 -2
- package/cjs/document/http/http-operation-response.js +3 -3
- package/cjs/document/http/http-operation.js +5 -5
- package/cjs/document/http/http-parameter.js +2 -2
- package/cjs/document/http/http-request-body.js +4 -2
- package/cjs/document/utils/test-scope-match.js +13 -0
- package/cjs/filter/filter-rules.js +6 -6
- package/esm/document/api-document.js +12 -8
- package/esm/document/common/api-base.js +2 -1
- package/esm/document/common/document-node.js +24 -29
- package/esm/document/common/value.js +6 -2
- package/esm/document/constants.js +0 -1
- package/esm/document/data-type/api-field.js +13 -9
- package/esm/document/data-type/complex-type-base.js +22 -11
- package/esm/document/data-type/complex-type.js +22 -8
- package/esm/document/data-type/data-type.js +14 -1
- package/esm/document/data-type/enum-type.js +13 -3
- package/esm/document/data-type/extended-types/base64.type.js +1 -0
- package/esm/document/data-type/extended-types/date-string.type.js +1 -0
- package/esm/document/data-type/extended-types/date-time-string.type.js +1 -0
- package/esm/document/data-type/extended-types/date-time.type.js +1 -0
- package/esm/document/data-type/extended-types/date.type.js +1 -0
- package/esm/document/data-type/extended-types/email.type.js +1 -0
- package/esm/document/data-type/extended-types/field-path.type.js +10 -6
- package/esm/document/data-type/extended-types/filter.type.js +11 -4
- package/esm/document/data-type/extended-types/object-id.type.js +1 -0
- package/esm/document/data-type/extended-types/operation-result.type.js +1 -0
- package/esm/document/data-type/extended-types/time.type.js +1 -0
- package/esm/document/data-type/extended-types/url.type.js +1 -0
- package/esm/document/data-type/extended-types/uuid.type.js +1 -0
- package/esm/document/data-type/mapped-type.js +12 -3
- package/esm/document/data-type/mixin-type.js +17 -5
- package/esm/document/data-type/primitive-types/any.type.js +1 -0
- package/esm/document/data-type/primitive-types/bigint.type.js +1 -0
- package/esm/document/data-type/primitive-types/boolean.type.js +1 -0
- package/esm/document/data-type/primitive-types/integer.type.js +1 -0
- package/esm/document/data-type/primitive-types/null.type.js +1 -0
- package/esm/document/data-type/primitive-types/number.type.js +1 -0
- package/esm/document/data-type/primitive-types/string.type.js +1 -0
- package/esm/document/data-type/simple-type.js +13 -11
- package/esm/document/decorators/api-field-decorator.js +36 -2
- package/esm/document/decorators/complex-type.decorator.js +2 -2
- package/esm/document/decorators/simple-type.decorator.js +4 -2
- package/esm/document/http/http-api.js +2 -2
- package/esm/document/http/http-controller.js +5 -5
- package/esm/document/http/http-media-type.js +3 -3
- package/esm/document/http/http-multipart-field.js +2 -2
- package/esm/document/http/http-operation-response.js +3 -3
- package/esm/document/http/http-operation.js +5 -5
- package/esm/document/http/http-parameter.js +2 -2
- package/esm/document/http/http-request-body.js +4 -2
- package/esm/document/utils/test-scope-match.js +10 -0
- package/esm/filter/filter-rules.js +6 -6
- package/package.json +1 -1
- package/types/document/api-document.d.ts +7 -2
- package/types/document/common/api-base.d.ts +1 -1
- package/types/document/common/document-init-context.d.ts +1 -0
- package/types/document/common/document-node.d.ts +8 -14
- package/types/document/common/value.d.ts +2 -1
- package/types/document/constants.d.ts +0 -1
- package/types/document/data-type/api-field.d.ts +42 -34
- package/types/document/data-type/complex-type-base.d.ts +4 -2
- package/types/document/data-type/complex-type.d.ts +3 -1
- package/types/document/data-type/data-type.d.ts +8 -2
- package/types/document/data-type/enum-type.d.ts +3 -1
- package/types/document/data-type/extended-types/field-path.type.d.ts +4 -3
- package/types/document/data-type/extended-types/filter.type.d.ts +2 -1
- package/types/document/data-type/mapped-type.d.ts +3 -1
- package/types/document/data-type/mixin-type.d.ts +3 -1
- package/types/document/data-type/simple-type.d.ts +3 -2
- package/types/document/decorators/api-field-decorator.d.ts +5 -3
- package/types/document/decorators/simple-type.decorator.d.ts +34 -0
- package/types/document/factory/api-document.factory.d.ts +1 -0
- package/types/document/http/http-api.d.ts +1 -1
- package/types/document/http/http-controller.d.ts +2 -1
- package/types/document/http/http-media-type.d.ts +2 -1
- package/types/document/http/http-multipart-field.d.ts +2 -1
- package/types/document/http/http-operation-response.d.ts +2 -1
- package/types/document/http/http-operation.d.ts +2 -1
- package/types/document/http/http-parameter.d.ts +2 -1
- package/types/document/http/http-request-body.d.ts +2 -1
- package/types/document/utils/test-scope-match.d.ts +1 -0
- package/types/filter/filter-rules.d.ts +2 -2
|
@@ -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
|
|
92
|
-
|
|
93
|
-
:
|
|
94
|
-
|
|
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
|
|
4
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
@@ -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
|
}
|
|
@@ -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;
|