@opra/common 0.24.2 → 0.25.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.js +368 -314
- package/cjs/document/data-type/complex-type-class.js +151 -0
- package/cjs/document/data-type/complex-type.js +13 -168
- package/cjs/document/data-type/data-type.js +4 -0
- package/cjs/document/data-type/enum-type-class.js +32 -0
- package/cjs/document/data-type/enum-type.js +24 -49
- package/cjs/document/data-type/field-class.js +34 -0
- package/cjs/document/data-type/field-decorator.js +45 -0
- package/cjs/document/data-type/field.js +25 -0
- package/cjs/document/data-type/mapped-type-class.js +48 -0
- package/cjs/document/data-type/mapped-type.js +18 -58
- package/cjs/document/data-type/simple-type-class.js +29 -0
- package/cjs/document/data-type/simple-type.js +12 -43
- package/cjs/document/data-type/union-type-class.js +36 -0
- package/cjs/document/data-type/union-type.js +3 -31
- package/cjs/document/{resource → decorators}/collection-decorator.js +2 -24
- package/cjs/document/decorators/complex-type.decorator.js +23 -0
- package/cjs/document/decorators/resource.decorator.js +38 -0
- package/cjs/document/decorators/simple-type.decorator.js +20 -0
- package/cjs/document/{resource/singleton-decorator.js → decorators/singleton.decorator.js} +2 -19
- package/cjs/document/{resource/storage-decorator.js → decorators/storage.decorator.js} +2 -18
- package/cjs/document/index.js +1 -1
- package/cjs/document/resource/collection.js +4 -3
- package/cjs/document/resource/endpoint.js +44 -0
- package/cjs/document/resource/resource.js +9 -10
- package/cjs/document/resource/singleton.js +5 -1
- package/cjs/document/resource/storage.js +5 -1
- package/cjs/schema/opra-schema.ns.js +1 -0
- package/cjs/schema/resource/endpoint.interface.js +2 -0
- package/esm/document/data-type/complex-type-class.js +147 -0
- package/esm/document/data-type/complex-type.js +13 -168
- package/esm/document/data-type/data-type.js +4 -0
- package/esm/document/data-type/enum-type-class.js +27 -0
- package/esm/document/data-type/enum-type.js +22 -47
- package/esm/document/data-type/field-class.js +30 -0
- package/esm/document/data-type/field-decorator.js +41 -0
- package/esm/document/data-type/field.js +21 -0
- package/esm/document/data-type/mapped-type-class.js +43 -0
- package/esm/document/data-type/mapped-type.js +13 -53
- package/esm/document/data-type/simple-type-class.js +24 -0
- package/esm/document/data-type/simple-type.js +12 -43
- package/esm/document/data-type/union-type-class.js +32 -0
- package/esm/document/data-type/union-type.js +2 -30
- package/esm/document/{resource → decorators}/collection-decorator.js +2 -23
- package/esm/document/decorators/complex-type.decorator.js +18 -0
- package/esm/document/decorators/resource.decorator.js +33 -0
- package/esm/document/decorators/simple-type.decorator.js +15 -0
- package/esm/document/{resource/singleton-decorator.js → decorators/singleton.decorator.js} +2 -18
- package/esm/document/{resource/storage-decorator.js → decorators/storage.decorator.js} +2 -17
- package/esm/document/index.js +1 -1
- package/esm/document/resource/collection.js +4 -3
- package/esm/document/resource/endpoint.js +40 -0
- package/esm/document/resource/resource.js +9 -10
- package/esm/document/resource/singleton.js +5 -1
- package/esm/document/resource/storage.js +5 -1
- package/esm/schema/opra-schema.ns.js +1 -0
- package/esm/schema/resource/endpoint.interface.js +1 -0
- package/package.json +3 -11
- package/types/document/data-type/complex-type-class.d.ts +33 -0
- package/types/document/data-type/complex-type.d.ts +18 -43
- package/types/document/data-type/data-type.d.ts +17 -13
- package/types/document/data-type/enum-type-class.d.ts +17 -0
- package/types/document/data-type/enum-type.d.ts +11 -24
- package/types/document/data-type/field-class.d.ts +20 -0
- package/types/document/data-type/field-decorator.d.ts +5 -0
- package/types/document/data-type/{api-field.d.ts → field.d.ts} +20 -20
- package/types/document/data-type/mapped-type-class.d.ts +21 -0
- package/types/document/data-type/mapped-type.d.ts +24 -39
- package/types/document/data-type/simple-type-class.d.ts +17 -0
- package/types/document/data-type/simple-type.d.ts +21 -31
- package/types/document/data-type/union-type-class.d.ts +18 -0
- package/types/document/data-type/union-type.d.ts +15 -27
- package/types/document/{resource → decorators}/collection-decorator.d.ts +14 -14
- package/types/document/decorators/complex-type.decorator.d.ts +2 -0
- package/types/document/decorators/resource.decorator.d.ts +9 -0
- package/types/document/decorators/simple-type.decorator.d.ts +2 -0
- package/types/document/{resource/singleton-decorator.d.ts → decorators/singleton.decorator.d.ts} +11 -11
- package/types/document/{resource/storage-decorator.d.ts → decorators/storage.decorator.d.ts} +10 -10
- package/types/document/factory/import-type-class.d.ts +1 -1
- package/types/document/index.d.ts +1 -1
- package/types/document/resource/collection.d.ts +16 -12
- package/types/document/resource/endpoint.d.ts +29 -0
- package/types/document/resource/resource.d.ts +15 -14
- package/types/document/resource/singleton.d.ts +15 -8
- package/types/document/resource/storage-class.d.ts +0 -2
- package/types/document/resource/storage.d.ts +12 -8
- package/types/filter/ast/terms/qualified-identifier.d.ts +1 -1
- package/types/schema/opra-schema.ns.d.ts +1 -0
- package/types/schema/resource/collection.interface.d.ts +2 -1
- package/types/schema/resource/endpoint.interface.d.ts +12 -0
- package/types/schema/resource/resource.interface.d.ts +3 -15
- package/types/schema/resource/storage.interface.d.ts +2 -1
- package/cjs/document/data-type/api-field.js +0 -83
- package/cjs/document/resource/action.js +0 -12
- package/cjs/document/resource/resource-decorator.js +0 -16
- package/esm/document/data-type/api-field.js +0 -80
- package/esm/document/resource/action.js +0 -8
- package/esm/document/resource/resource-decorator.js +0 -13
- package/types/document/resource/action.d.ts +0 -11
- package/types/document/resource/resource-decorator.d.ts +0 -5
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { StrictOmit, Type } from 'ts-gems';
|
|
2
|
+
import { ResponsiveMap } from '../../helpers/index.js';
|
|
2
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
3
4
|
import type { ApiDocument } from '../api-document.js';
|
|
4
5
|
import { nodeInspectCustom } from '../utils/inspect.util.js';
|
|
5
|
-
import {
|
|
6
|
+
import { Endpoint } from './endpoint.js';
|
|
7
|
+
export declare abstract class Resource {
|
|
8
|
+
readonly document: ApiDocument;
|
|
9
|
+
abstract readonly kind: OpraSchema.Resource.Kind;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
controller?: object | Type;
|
|
13
|
+
abstract operations: Record<string, any>;
|
|
14
|
+
actions: ResponsiveMap<Endpoint>;
|
|
15
|
+
protected constructor(document: ApiDocument, init: Resource.InitArguments);
|
|
16
|
+
exportSchema(): OpraSchema.ResourceBase;
|
|
17
|
+
toString(): string;
|
|
18
|
+
[nodeInspectCustom](): string;
|
|
19
|
+
}
|
|
6
20
|
export declare namespace Resource {
|
|
7
21
|
interface InitArguments extends StrictOmit<OpraSchema.ResourceBase, 'kind'> {
|
|
8
22
|
name: string;
|
|
@@ -16,16 +30,3 @@ export declare namespace Resource {
|
|
|
16
30
|
interface ActionOptions {
|
|
17
31
|
}
|
|
18
32
|
}
|
|
19
|
-
export declare abstract class Resource {
|
|
20
|
-
readonly document: ApiDocument;
|
|
21
|
-
abstract readonly kind: OpraSchema.Resource.Kind;
|
|
22
|
-
readonly name: string;
|
|
23
|
-
readonly description?: string;
|
|
24
|
-
readonly controller?: object | Type;
|
|
25
|
-
abstract readonly operations: Record<string, any>;
|
|
26
|
-
readonly actions: Record<string, Action>;
|
|
27
|
-
protected constructor(document: ApiDocument, init: Resource.InitArguments);
|
|
28
|
-
exportSchema(): OpraSchema.ResourceBase;
|
|
29
|
-
toString(): string;
|
|
30
|
-
[nodeInspectCustom](): string;
|
|
31
|
-
}
|
|
@@ -3,9 +3,23 @@ import { OpraSchema } from '../../schema/index.js';
|
|
|
3
3
|
import type { TypeThunkAsync } from '../../types.js';
|
|
4
4
|
import type { ApiDocument } from '../api-document.js';
|
|
5
5
|
import { ComplexType } from '../data-type/complex-type.js';
|
|
6
|
+
import { SingletonDecorator } from '../decorators/singleton.decorator.js';
|
|
6
7
|
import type { Resource } from './resource.js';
|
|
7
8
|
import { SingletonClass } from './singleton-class.js';
|
|
8
|
-
|
|
9
|
+
export interface SingletonConstructor extends SingletonDecorator {
|
|
10
|
+
prototype: SingletonClass;
|
|
11
|
+
new (document: ApiDocument, init: Singleton.InitArguments): SingletonClass;
|
|
12
|
+
}
|
|
13
|
+
export interface Singleton extends SingletonClass {
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @class Singleton
|
|
17
|
+
* @decorator Singleton
|
|
18
|
+
*/
|
|
19
|
+
export declare const Singleton: SingletonConstructor;
|
|
20
|
+
/**
|
|
21
|
+
* @namespace Singleton
|
|
22
|
+
*/
|
|
9
23
|
export declare namespace Singleton {
|
|
10
24
|
interface InitArguments extends Resource.InitArguments, StrictOmit<OpraSchema.Singleton, 'kind' | 'type'> {
|
|
11
25
|
type: ComplexType;
|
|
@@ -28,10 +42,3 @@ export declare namespace Singleton {
|
|
|
28
42
|
type GetEndpointOptions = OpraSchema.Singleton.GetEndpoint;
|
|
29
43
|
type UpdateEndpointOptions = OpraSchema.Singleton.UpdateEndpoint;
|
|
30
44
|
}
|
|
31
|
-
export interface SingletonConstructor extends SingletonDecorator {
|
|
32
|
-
prototype: Singleton;
|
|
33
|
-
new (document: ApiDocument, init: Singleton.InitArguments): Singleton;
|
|
34
|
-
}
|
|
35
|
-
export interface Singleton extends SingletonClass {
|
|
36
|
-
}
|
|
37
|
-
export declare const Singleton: SingletonConstructor;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Type } from 'ts-gems';
|
|
2
1
|
import { OpraSchema } from '../../schema/index.js';
|
|
3
2
|
import type { ApiDocument } from '../api-document.js';
|
|
4
3
|
import { Resource } from './resource.js';
|
|
@@ -6,7 +5,6 @@ import type { Storage } from './storage.js';
|
|
|
6
5
|
export declare class StorageClass extends Resource {
|
|
7
6
|
readonly kind = "Storage";
|
|
8
7
|
readonly operations: OpraSchema.Storage.Operations;
|
|
9
|
-
readonly controller?: object | Type;
|
|
10
8
|
constructor(document: ApiDocument, init: Storage.InitArguments);
|
|
11
9
|
exportSchema(): OpraSchema.Storage;
|
|
12
10
|
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { StrictOmit } from 'ts-gems';
|
|
2
2
|
import { OpraSchema } from '../../schema/index.js';
|
|
3
3
|
import type { ApiDocument } from '../api-document.js';
|
|
4
|
+
import { StorageDecorator } from '../decorators/storage.decorator.js';
|
|
4
5
|
import type { Resource } from './resource.js';
|
|
5
6
|
import { StorageClass } from './storage-class.js';
|
|
6
|
-
|
|
7
|
+
export interface StorageConstructor extends StorageDecorator {
|
|
8
|
+
prototype: StorageClass;
|
|
9
|
+
new (document: ApiDocument, init: Storage.InitArguments): StorageClass;
|
|
10
|
+
}
|
|
11
|
+
export interface Storage extends StorageClass {
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @class Storage
|
|
15
|
+
* @decorator Storage
|
|
16
|
+
*/
|
|
17
|
+
export declare const Storage: StorageConstructor;
|
|
7
18
|
export declare namespace Storage {
|
|
8
19
|
interface InitArguments extends Resource.InitArguments, StrictOmit<OpraSchema.Storage, 'kind'> {
|
|
9
20
|
}
|
|
@@ -21,10 +32,3 @@ export declare namespace Storage {
|
|
|
21
32
|
type GetEndpointOptions = OpraSchema.Storage.GetEndpoint;
|
|
22
33
|
type PostEndpointOptions = OpraSchema.Storage.PostEndpoint;
|
|
23
34
|
}
|
|
24
|
-
export interface StorageConstructor extends StorageDecorator {
|
|
25
|
-
prototype: Storage;
|
|
26
|
-
new (document: ApiDocument, init: Storage.InitArguments): Storage;
|
|
27
|
-
}
|
|
28
|
-
export interface Storage extends StorageClass {
|
|
29
|
-
}
|
|
30
|
-
export declare const Storage: StorageConstructor;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ApiField } from '../../../document/data-type/api-field.js';
|
|
2
1
|
import { DataType } from '../../../document/data-type/data-type.js';
|
|
2
|
+
import type { ApiField } from '../../../document/data-type/field.js';
|
|
3
3
|
import { Literal } from '../abstract/literal.js';
|
|
4
4
|
export declare class QualifiedIdentifier extends Literal {
|
|
5
5
|
dataType: DataType;
|
|
@@ -5,6 +5,7 @@ export * from './data-type/field.interface.js';
|
|
|
5
5
|
export * from './data-type/simple-type.interface.js';
|
|
6
6
|
export * from './data-type/mapped-type.interface.js';
|
|
7
7
|
export * from './data-type/union-type.interface.js';
|
|
8
|
+
export * from './resource/endpoint.interface.js';
|
|
8
9
|
export * from './resource/collection.interface.js';
|
|
9
10
|
export * from './resource/container.interface.js';
|
|
10
11
|
export * from './resource/resource.interface.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { OpraFilter } from '../../filter/index.js';
|
|
2
2
|
import type { DataType } from '../data-type/data-type.interface.js';
|
|
3
3
|
import type { Field } from '../data-type/field.interface';
|
|
4
|
-
import type { Endpoint
|
|
4
|
+
import type { Endpoint } from './endpoint.interface.js';
|
|
5
|
+
import type { ResourceBase } from './resource.interface.js';
|
|
5
6
|
export interface Collection extends ResourceBase {
|
|
6
7
|
kind: Collection.Kind;
|
|
7
8
|
type: DataType.Name;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Field } from '../data-type/field.interface.js';
|
|
2
|
+
export interface Endpoint {
|
|
3
|
+
description?: string;
|
|
4
|
+
parameters?: Record<Endpoint.Parameter.Name, Endpoint.Parameter>;
|
|
5
|
+
}
|
|
6
|
+
export declare namespace Endpoint {
|
|
7
|
+
interface Parameter extends Pick<Field, 'type' | 'description' | 'isArray' | 'default' | 'required' | 'deprecated' | 'examples'> {
|
|
8
|
+
}
|
|
9
|
+
namespace Parameter {
|
|
10
|
+
type Name = string;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Field } from '../data-type/field.interface.js';
|
|
2
1
|
import type { Collection } from './collection.interface.js';
|
|
3
2
|
import type { Container } from './container.interface.js';
|
|
3
|
+
import type { Endpoint } from './endpoint.interface.js';
|
|
4
4
|
import type { Singleton } from './singleton.interface.js';
|
|
5
|
-
import type { Storage } from './storage.interface';
|
|
5
|
+
import type { Storage } from './storage.interface.js';
|
|
6
6
|
export type Resource = Collection | Singleton | Storage | Container;
|
|
7
7
|
export declare namespace Resource {
|
|
8
8
|
type Name = string;
|
|
@@ -11,17 +11,5 @@ export declare namespace Resource {
|
|
|
11
11
|
export interface ResourceBase {
|
|
12
12
|
kind: string;
|
|
13
13
|
description?: string;
|
|
14
|
-
actions?: Record<
|
|
15
|
-
}
|
|
16
|
-
export interface Endpoint {
|
|
17
|
-
description?: string;
|
|
18
|
-
}
|
|
19
|
-
export interface Action {
|
|
20
|
-
parameters?: Record<Action.ParameterName, Action.Parameter>;
|
|
21
|
-
}
|
|
22
|
-
export declare namespace Action {
|
|
23
|
-
type Name = string;
|
|
24
|
-
type ParameterName = string;
|
|
25
|
-
interface Parameter extends Pick<Field, 'type' | 'description' | 'isArray' | 'default' | 'required' | 'deprecated' | 'examples'> {
|
|
26
|
-
}
|
|
14
|
+
actions?: Record<string, Endpoint>;
|
|
27
15
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Endpoint
|
|
1
|
+
import type { Endpoint } from './endpoint.interface.js';
|
|
2
|
+
import type { ResourceBase } from './resource.interface.js';
|
|
2
3
|
export interface Storage extends ResourceBase {
|
|
3
4
|
kind: Storage.Kind;
|
|
4
5
|
operations: Storage.Operations;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiField = void 0;
|
|
4
|
-
const index_js_1 = require("../../helpers/index.js");
|
|
5
|
-
const index_js_2 = require("../../schema/index.js");
|
|
6
|
-
const constants_js_1 = require("../constants.js");
|
|
7
|
-
const enum_type_js_1 = require("./enum-type.js");
|
|
8
|
-
/**
|
|
9
|
-
* @class ComplexType
|
|
10
|
-
*/
|
|
11
|
-
exports.ApiField = function (...args) {
|
|
12
|
-
// ClassDecorator
|
|
13
|
-
if (!this) {
|
|
14
|
-
const [options] = args;
|
|
15
|
-
return function (target, propertyKey) {
|
|
16
|
-
if (typeof propertyKey !== 'string')
|
|
17
|
-
throw new TypeError(`Symbol properties can't be used as a field`);
|
|
18
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) || {};
|
|
19
|
-
metadata.kind = index_js_2.OpraSchema.ComplexType.Kind;
|
|
20
|
-
metadata.fields = metadata.fields || {};
|
|
21
|
-
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
22
|
-
const elemMeta = metadata.fields[propertyKey] = {
|
|
23
|
-
...options,
|
|
24
|
-
enum: undefined,
|
|
25
|
-
designType
|
|
26
|
-
};
|
|
27
|
-
if (designType === Array) {
|
|
28
|
-
elemMeta.isArray = true;
|
|
29
|
-
delete elemMeta.designType;
|
|
30
|
-
}
|
|
31
|
-
if (options?.enum) {
|
|
32
|
-
elemMeta.type = undefined;
|
|
33
|
-
if (Array.isArray(options.enum)) {
|
|
34
|
-
const enumObj = options.enum.reduce((o, v) => {
|
|
35
|
-
o[v] = v;
|
|
36
|
-
return o;
|
|
37
|
-
}, {});
|
|
38
|
-
(0, enum_type_js_1.EnumType)(enumObj);
|
|
39
|
-
elemMeta.enum = enumObj;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const m = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, options?.enum);
|
|
43
|
-
if (!index_js_2.OpraSchema.isEnumType(m))
|
|
44
|
-
throw new TypeError(`Invalid "enum" value. Did you forget to set metadata using EnumType() method?`);
|
|
45
|
-
elemMeta.enum = options.enum;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, (0, index_js_1.omitUndefined)(metadata), target.constructor);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
// Constructor
|
|
52
|
-
const [owner, init] = args;
|
|
53
|
-
const _this = this;
|
|
54
|
-
_this.owner = owner;
|
|
55
|
-
_this.name = init.name;
|
|
56
|
-
_this.origin = init.origin || owner;
|
|
57
|
-
_this.type = init.type;
|
|
58
|
-
if (init?.description)
|
|
59
|
-
this.description = init?.description;
|
|
60
|
-
if (init?.isArray != null)
|
|
61
|
-
this.isArray = init?.isArray;
|
|
62
|
-
this.default = init?.default;
|
|
63
|
-
this.fixed = init?.fixed;
|
|
64
|
-
if (init?.deprecated != null)
|
|
65
|
-
this.deprecated = init?.deprecated;
|
|
66
|
-
if (init?.exclusive != null)
|
|
67
|
-
this.exclusive = init?.exclusive;
|
|
68
|
-
if (init?.required != null)
|
|
69
|
-
this.required = init?.required;
|
|
70
|
-
};
|
|
71
|
-
const proto = {
|
|
72
|
-
exportSchema() {
|
|
73
|
-
return (0, index_js_1.omitUndefined)({
|
|
74
|
-
type: this.type.name ? this.type.name : this.type.exportSchema(),
|
|
75
|
-
description: this.description,
|
|
76
|
-
isArray: this.isArray,
|
|
77
|
-
default: this.default,
|
|
78
|
-
fixed: this.fixed,
|
|
79
|
-
required: this.required
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
Object.assign(exports.ApiField.prototype, proto);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResourceDecorator = void 0;
|
|
4
|
-
const constants_js_1 = require("../constants.js");
|
|
5
|
-
exports.ResourceDecorator = {};
|
|
6
|
-
exports.ResourceDecorator.Action = function (options) {
|
|
7
|
-
return (target, propertyKey) => {
|
|
8
|
-
if (typeof propertyKey !== 'string')
|
|
9
|
-
throw new TypeError(`This decorator can't be used for Symbol keys'`);
|
|
10
|
-
const actionMeta = { ...options };
|
|
11
|
-
const resourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target.constructor) || {});
|
|
12
|
-
resourceMetadata.actions = resourceMetadata.actions || {};
|
|
13
|
-
resourceMetadata.actions[propertyKey] = actionMeta;
|
|
14
|
-
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, resourceMetadata, target.constructor);
|
|
15
|
-
};
|
|
16
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { omitUndefined } from '../../helpers/index.js';
|
|
2
|
-
import { OpraSchema } from '../../schema/index.js';
|
|
3
|
-
import { DATATYPE_METADATA } from '../constants.js';
|
|
4
|
-
import { EnumType } from './enum-type.js';
|
|
5
|
-
/**
|
|
6
|
-
* @class ComplexType
|
|
7
|
-
*/
|
|
8
|
-
export const ApiField = function (...args) {
|
|
9
|
-
// ClassDecorator
|
|
10
|
-
if (!this) {
|
|
11
|
-
const [options] = args;
|
|
12
|
-
return function (target, propertyKey) {
|
|
13
|
-
if (typeof propertyKey !== 'string')
|
|
14
|
-
throw new TypeError(`Symbol properties can't be used as a field`);
|
|
15
|
-
const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target.constructor) || {};
|
|
16
|
-
metadata.kind = OpraSchema.ComplexType.Kind;
|
|
17
|
-
metadata.fields = metadata.fields || {};
|
|
18
|
-
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
19
|
-
const elemMeta = metadata.fields[propertyKey] = {
|
|
20
|
-
...options,
|
|
21
|
-
enum: undefined,
|
|
22
|
-
designType
|
|
23
|
-
};
|
|
24
|
-
if (designType === Array) {
|
|
25
|
-
elemMeta.isArray = true;
|
|
26
|
-
delete elemMeta.designType;
|
|
27
|
-
}
|
|
28
|
-
if (options?.enum) {
|
|
29
|
-
elemMeta.type = undefined;
|
|
30
|
-
if (Array.isArray(options.enum)) {
|
|
31
|
-
const enumObj = options.enum.reduce((o, v) => {
|
|
32
|
-
o[v] = v;
|
|
33
|
-
return o;
|
|
34
|
-
}, {});
|
|
35
|
-
EnumType(enumObj);
|
|
36
|
-
elemMeta.enum = enumObj;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const m = Reflect.getOwnMetadata(DATATYPE_METADATA, options?.enum);
|
|
40
|
-
if (!OpraSchema.isEnumType(m))
|
|
41
|
-
throw new TypeError(`Invalid "enum" value. Did you forget to set metadata using EnumType() method?`);
|
|
42
|
-
elemMeta.enum = options.enum;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
Reflect.defineMetadata(DATATYPE_METADATA, omitUndefined(metadata), target.constructor);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
// Constructor
|
|
49
|
-
const [owner, init] = args;
|
|
50
|
-
const _this = this;
|
|
51
|
-
_this.owner = owner;
|
|
52
|
-
_this.name = init.name;
|
|
53
|
-
_this.origin = init.origin || owner;
|
|
54
|
-
_this.type = init.type;
|
|
55
|
-
if (init?.description)
|
|
56
|
-
this.description = init?.description;
|
|
57
|
-
if (init?.isArray != null)
|
|
58
|
-
this.isArray = init?.isArray;
|
|
59
|
-
this.default = init?.default;
|
|
60
|
-
this.fixed = init?.fixed;
|
|
61
|
-
if (init?.deprecated != null)
|
|
62
|
-
this.deprecated = init?.deprecated;
|
|
63
|
-
if (init?.exclusive != null)
|
|
64
|
-
this.exclusive = init?.exclusive;
|
|
65
|
-
if (init?.required != null)
|
|
66
|
-
this.required = init?.required;
|
|
67
|
-
};
|
|
68
|
-
const proto = {
|
|
69
|
-
exportSchema() {
|
|
70
|
-
return omitUndefined({
|
|
71
|
-
type: this.type.name ? this.type.name : this.type.exportSchema(),
|
|
72
|
-
description: this.description,
|
|
73
|
-
isArray: this.isArray,
|
|
74
|
-
default: this.default,
|
|
75
|
-
fixed: this.fixed,
|
|
76
|
-
required: this.required
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
Object.assign(ApiField.prototype, proto);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { RESOURCE_METADATA } from '../constants.js';
|
|
2
|
-
export const ResourceDecorator = {};
|
|
3
|
-
ResourceDecorator.Action = function (options) {
|
|
4
|
-
return (target, propertyKey) => {
|
|
5
|
-
if (typeof propertyKey !== 'string')
|
|
6
|
-
throw new TypeError(`This decorator can't be used for Symbol keys'`);
|
|
7
|
-
const actionMeta = { ...options };
|
|
8
|
-
const resourceMetadata = (Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {});
|
|
9
|
-
resourceMetadata.actions = resourceMetadata.actions || {};
|
|
10
|
-
resourceMetadata.actions[propertyKey] = actionMeta;
|
|
11
|
-
Reflect.defineMetadata(RESOURCE_METADATA, resourceMetadata, target.constructor);
|
|
12
|
-
};
|
|
13
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { OpraSchema } from '../../schema/index.js';
|
|
2
|
-
export declare namespace Action {
|
|
3
|
-
interface InitArguments extends OpraSchema.Action {
|
|
4
|
-
name: string;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export declare class Action {
|
|
8
|
-
readonly name: string;
|
|
9
|
-
constructor(init: Action.InitArguments);
|
|
10
|
-
exportSchema(): OpraSchema.Action;
|
|
11
|
-
}
|