@opra/common 1.0.0-beta.2 → 1.0.0-beta.4
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 +14 -0
- package/cjs/document/common/api-base.js +5 -3
- package/cjs/document/common/document-node.js +6 -2
- package/cjs/document/constants.js +2 -1
- package/cjs/document/decorators/http-controller.decorator.js +1 -1
- package/cjs/document/decorators/http-operation-entity.decorator.js +1 -1
- package/cjs/document/decorators/http-operation.decorator.js +5 -5
- package/cjs/document/decorators/rpc-controller.decorator.js +69 -0
- package/cjs/document/decorators/rpc-operation.decorator.js +80 -0
- package/cjs/document/factory/api-document.factory.js +9 -3
- package/cjs/document/factory/data-type.factory.js +20 -0
- package/cjs/document/factory/http-api.factory.js +50 -77
- package/cjs/document/factory/rpc-api.factory.js +202 -0
- package/cjs/document/http/http-api.js +5 -4
- package/cjs/document/http/http-controller.js +16 -0
- package/cjs/document/http/http-operation.js +6 -0
- package/cjs/document/index.js +8 -0
- package/cjs/document/rpc/rpc-api.js +54 -0
- package/cjs/document/rpc/rpc-controller.js +116 -0
- package/cjs/document/rpc/rpc-header.js +40 -0
- package/cjs/document/rpc/rpc-operation-response.js +58 -0
- package/cjs/document/rpc/rpc-operation.js +80 -0
- package/cjs/enums/index.js +7 -0
- package/cjs/exception/http-errors/forbidden.error.js +1 -1
- package/cjs/exception/http-errors/resource-not.available.error.js +1 -1
- package/cjs/index.js +1 -1
- package/cjs/schema/opra-schema.js +3 -0
- package/cjs/schema/rpc/rpc-controller.interface.js +11 -0
- package/cjs/schema/rpc/rpc-header.interface.js +2 -0
- package/cjs/schema/rpc/rpc-operation.interface.js +7 -0
- package/esm/document/api-document.js +14 -0
- package/esm/document/common/api-base.js +5 -3
- package/esm/document/common/document-node.js +6 -2
- package/esm/document/constants.js +1 -0
- package/esm/document/decorators/http-controller.decorator.js +1 -1
- package/esm/document/decorators/http-operation-entity.decorator.js +1 -1
- package/esm/document/decorators/http-operation.decorator.js +5 -5
- package/esm/document/decorators/rpc-controller.decorator.js +65 -0
- package/esm/document/decorators/rpc-operation.decorator.js +76 -0
- package/esm/document/factory/api-document.factory.js +9 -3
- package/esm/document/factory/data-type.factory.js +20 -0
- package/esm/document/factory/http-api.factory.js +50 -77
- package/esm/document/factory/rpc-api.factory.js +198 -0
- package/esm/document/http/http-api.js +5 -4
- package/esm/document/http/http-controller.js +17 -1
- package/esm/document/http/http-operation.js +6 -0
- package/esm/document/index.js +8 -0
- package/esm/document/rpc/rpc-api.js +50 -0
- package/esm/document/rpc/rpc-controller.js +113 -0
- package/esm/document/rpc/rpc-header.js +37 -0
- package/esm/document/rpc/rpc-operation-response.js +54 -0
- package/esm/document/rpc/rpc-operation.js +77 -0
- package/esm/enums/index.js +4 -0
- package/esm/exception/http-errors/forbidden.error.js +1 -1
- package/esm/exception/http-errors/resource-not.available.error.js +1 -1
- package/esm/index.js +1 -1
- package/esm/schema/opra-schema.js +3 -0
- package/esm/schema/rpc/rpc-controller.interface.js +8 -0
- package/esm/schema/rpc/rpc-header.interface.js +1 -0
- package/esm/schema/rpc/rpc-operation.interface.js +4 -0
- package/package.json +2 -2
- package/types/document/api-document.d.ts +5 -2
- package/types/document/common/api-base.d.ts +3 -2
- package/types/document/constants.d.ts +1 -0
- package/types/document/decorators/http-operation.decorator.d.ts +3 -3
- package/types/document/decorators/rpc-controller.decorator.d.ts +20 -0
- package/types/document/decorators/rpc-operation.decorator.d.ts +32 -0
- package/types/document/factory/api-document.factory.d.ts +2 -1
- package/types/document/factory/data-type.factory.d.ts +1 -0
- package/types/document/factory/http-api.factory.d.ts +10 -6
- package/types/document/factory/rpc-api.factory.d.ts +40 -0
- package/types/document/http/http-api.d.ts +8 -3
- package/types/document/http/http-controller.d.ts +8 -2
- package/types/document/index.d.ts +11 -0
- package/types/document/rpc/rpc-api.d.ts +27 -0
- package/types/document/rpc/rpc-controller.d.ts +89 -0
- package/types/document/rpc/rpc-header.d.ts +47 -0
- package/types/document/rpc/rpc-operation-response.d.ts +41 -0
- package/types/document/rpc/rpc-operation.d.ts +77 -0
- package/types/enums/index.d.ts +4 -0
- package/types/exception/http-errors/forbidden.error.d.ts +1 -1
- package/types/index.d.cts +1 -1
- package/types/index.d.ts +1 -1
- package/types/schema/api-document.interface.d.ts +25 -4
- package/types/schema/opra-schema.d.ts +3 -0
- package/types/schema/rpc/rpc-controller.interface.d.ts +22 -0
- package/types/schema/rpc/rpc-header.interface.d.ts +19 -0
- package/types/schema/rpc/rpc-operation.interface.d.ts +26 -0
- package/cjs/http/index.js +0 -7
- package/esm/http/index.js +0 -4
- package/types/http/index.d.ts +0 -4
- /package/cjs/{http/enums → enums}/http-headers-codes.enum.js +0 -0
- /package/cjs/{http/enums → enums}/http-status-codes.enum.js +0 -0
- /package/cjs/{http/enums → enums}/http-status-messages.js +0 -0
- /package/cjs/{http/enums → enums}/mime-types.enum.js +0 -0
- /package/esm/{http/enums → enums}/http-headers-codes.enum.js +0 -0
- /package/esm/{http/enums → enums}/http-status-codes.enum.js +0 -0
- /package/esm/{http/enums → enums}/http-status-messages.js +0 -0
- /package/esm/{http/enums → enums}/mime-types.enum.js +0 -0
- /package/types/{http/enums → enums}/http-headers-codes.enum.d.ts +0 -0
- /package/types/{http/enums → enums}/http-status-codes.enum.d.ts +0 -0
- /package/types/{http/enums → enums}/http-status-messages.d.ts +0 -0
- /package/types/{http/enums → enums}/mime-types.enum.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
4
4
|
"description": "Opra common package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"super-fast-md5": "^1.0.3",
|
|
21
21
|
"tslib": "^2.7.0",
|
|
22
22
|
"uid": "^2.0.1",
|
|
23
|
-
"valgen": "^5.
|
|
23
|
+
"valgen": "^5.10.0"
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
26
|
"exports": {
|
|
@@ -6,7 +6,8 @@ import { DocumentElement } from './common/document-element.js';
|
|
|
6
6
|
import { kTypeNSMap } from './constants.js';
|
|
7
7
|
import { DataType } from './data-type/data-type.js';
|
|
8
8
|
import type { EnumType } from './data-type/enum-type.js';
|
|
9
|
-
import
|
|
9
|
+
import { HttpApi } from './http/http-api.js';
|
|
10
|
+
import { RpcApi } from './rpc/rpc-api.js';
|
|
10
11
|
/**
|
|
11
12
|
*
|
|
12
13
|
* @class ApiDocument
|
|
@@ -18,7 +19,7 @@ export declare class ApiDocument extends DocumentElement {
|
|
|
18
19
|
info: OpraSchema.DocumentInfo;
|
|
19
20
|
references: ResponsiveMap<ApiDocument>;
|
|
20
21
|
types: DataTypeMap;
|
|
21
|
-
api?: HttpApi;
|
|
22
|
+
api?: HttpApi | RpcApi;
|
|
22
23
|
constructor();
|
|
23
24
|
/**
|
|
24
25
|
* Returns NS of datatype. Returns undefined if not found
|
|
@@ -26,6 +27,8 @@ export declare class ApiDocument extends DocumentElement {
|
|
|
26
27
|
*/
|
|
27
28
|
getDataTypeNs(nameOrCtor: string | Type | Function | EnumType.EnumArray | EnumType.EnumObject | DataType): string | undefined;
|
|
28
29
|
findDocument(id: string): ApiDocument | undefined;
|
|
30
|
+
get httpApi(): HttpApi;
|
|
31
|
+
get rpcApi(): RpcApi;
|
|
29
32
|
toJSON(): OpraSchema.ApiDocument;
|
|
30
33
|
/**
|
|
31
34
|
* Export as Opra schema definition object
|
|
@@ -4,14 +4,15 @@ import { DocumentElement } from './document-element.js';
|
|
|
4
4
|
import type { DocumentInitContext } from './document-init-context';
|
|
5
5
|
export declare namespace ApiBase {
|
|
6
6
|
interface InitArguments extends Pick<OpraSchema.Api, 'description' | 'name'> {
|
|
7
|
+
owner: ApiDocument | ApiBase;
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
export declare abstract class ApiBase extends DocumentElement {
|
|
10
|
-
abstract readonly
|
|
11
|
+
abstract readonly transport: OpraSchema.Transport;
|
|
11
12
|
readonly owner: ApiDocument | ApiBase;
|
|
12
13
|
name: string;
|
|
13
14
|
description?: string;
|
|
14
|
-
protected constructor(
|
|
15
|
+
protected constructor(init: ApiBase.InitArguments);
|
|
15
16
|
toJSON(): OpraSchema.Api;
|
|
16
17
|
protected _initialize(init: ApiBase.InitArguments, context: DocumentInitContext): Promise<void>;
|
|
17
18
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const DATATYPE_METADATA: unique symbol;
|
|
2
2
|
export declare const HTTP_CONTROLLER_METADATA: unique symbol;
|
|
3
|
+
export declare const RPC_CONTROLLER_METADATA: unique symbol;
|
|
3
4
|
export declare const DECODER: unique symbol;
|
|
4
5
|
export declare const ENCODER: unique symbol;
|
|
5
6
|
export declare const DECORATOR: unique symbol;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { StrictOmit, Type, TypeThunkAsync } from 'ts-gems';
|
|
2
2
|
import { HttpMediaType } from '../http/http-media-type.js';
|
|
3
3
|
import { HttpMultipartField } from '../http/http-multipart-field.js';
|
|
4
|
-
import type { HttpOperation } from '../http/http-operation';
|
|
5
|
-
import type { HttpOperationResponse } from '../http/http-operation-response';
|
|
6
|
-
import type { HttpParameter } from '../http/http-parameter';
|
|
4
|
+
import type { HttpOperation } from '../http/http-operation.js';
|
|
5
|
+
import type { HttpOperationResponse } from '../http/http-operation-response.js';
|
|
6
|
+
import type { HttpParameter } from '../http/http-parameter.js';
|
|
7
7
|
export interface HttpOperationDecorator {
|
|
8
8
|
(target: Object, propertyKey: string): void;
|
|
9
9
|
Cookie(name: string | RegExp, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | Type): this;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TypeThunkAsync } from 'ts-gems';
|
|
2
|
+
import type { RpcController } from '../rpc/rpc-controller';
|
|
3
|
+
import type { RpcHeader } from '../rpc/rpc-header';
|
|
4
|
+
export interface RpcControllerDecorator<T extends RpcControllerDecorator<any> = RpcControllerDecorator<any>> extends ClassDecorator {
|
|
5
|
+
Header(name: string | RegExp, optionsOrType?: RpcHeader.Options | string | TypeThunkAsync | false): T;
|
|
6
|
+
UseType(...type: TypeThunkAsync[]): T;
|
|
7
|
+
}
|
|
8
|
+
export interface RpcControllerDecoratorFactory {
|
|
9
|
+
<T extends RpcController.Options>(options?: T): RpcControllerDecorator;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @namespace RpcControllerDecoratorFactory
|
|
13
|
+
*/
|
|
14
|
+
export declare namespace RpcControllerDecoratorFactory {
|
|
15
|
+
type AugmentationFunction = (decorator: RpcControllerDecorator, decoratorChain: Function[], options?: RpcController.Options) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function RpcControllerDecoratorFactory<O extends RpcController.Options>(options?: O): RpcControllerDecorator;
|
|
18
|
+
export declare namespace RpcControllerDecoratorFactory {
|
|
19
|
+
var augment: (fn: RpcControllerDecoratorFactory.AugmentationFunction) => void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ThunkAsync, Type, TypeThunkAsync } from 'ts-gems';
|
|
2
|
+
import type { RpcHeader } from '../rpc/rpc-header';
|
|
3
|
+
import type { RpcOperation } from '../rpc/rpc-operation';
|
|
4
|
+
import type { RpcOperationResponse } from '../rpc/rpc-operation-response';
|
|
5
|
+
export interface RpcOperationDecorator {
|
|
6
|
+
(target: Object, propertyKey: string): void;
|
|
7
|
+
Header(name: string | RegExp, optionsOrType?: RpcHeader.Options | string | TypeThunkAsync): this;
|
|
8
|
+
Response(payloadType: TypeThunkAsync | string, options?: RpcOperationResponse.Options): RpcOperationResponseDecorator;
|
|
9
|
+
UseType(...type: Type[]): this;
|
|
10
|
+
}
|
|
11
|
+
export interface RpcOperationResponseDecorator {
|
|
12
|
+
(target: Object, propertyKey: string): void;
|
|
13
|
+
Header(name: string | RegExp, optionsOrType?: RpcHeader.Options | string | TypeThunkAsync): this;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @namespace RpcOperationDecoratorFactory
|
|
17
|
+
*/
|
|
18
|
+
export interface RpcOperationDecoratorFactory {
|
|
19
|
+
/**
|
|
20
|
+
* Property decorator
|
|
21
|
+
* @param decoratorChain
|
|
22
|
+
* @param payloadType
|
|
23
|
+
* @param options
|
|
24
|
+
*/ <T extends RpcOperation.Options>(decoratorChain: Function[], payloadType: ThunkAsync<Type> | string, options?: T): RpcOperationDecorator;
|
|
25
|
+
}
|
|
26
|
+
export declare namespace RpcOperationDecoratorFactory {
|
|
27
|
+
type AugmentationFunction = (decorator: RpcOperationDecorator, decoratorChain: Function[], payloadType: ThunkAsync<Type> | string, options?: RpcOperation.Options) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare function RpcOperationDecoratorFactory(decoratorChain: Function[], payloadType: ThunkAsync<Type> | string | TypeThunkAsync, options?: RpcOperation.Options): RpcOperationDecorator;
|
|
30
|
+
export declare namespace RpcOperationDecoratorFactory {
|
|
31
|
+
var augment: (fn: RpcOperationDecoratorFactory.AugmentationFunction) => void;
|
|
32
|
+
}
|
|
@@ -4,11 +4,12 @@ import { ApiDocument } from '../api-document.js';
|
|
|
4
4
|
import { DocumentInitContext } from '../common/document-init-context.js';
|
|
5
5
|
import { DataTypeFactory } from './data-type.factory.js';
|
|
6
6
|
import { HttpApiFactory } from './http-api.factory.js';
|
|
7
|
+
import { RpcApiFactory } from './rpc-api.factory.js';
|
|
7
8
|
export declare namespace ApiDocumentFactory {
|
|
8
9
|
interface InitArguments extends PartialSome<StrictOmit<OpraSchema.ApiDocument, 'id' | 'references' | 'types' | 'api'>, 'spec'> {
|
|
9
10
|
references?: Record<string, ReferenceThunk>;
|
|
10
11
|
types?: DataTypeInitSources;
|
|
11
|
-
api?: HttpApiFactory.InitArguments
|
|
12
|
+
api?: StrictOmit<HttpApiFactory.InitArguments, 'owner'> | StrictOmit<RpcApiFactory.InitArguments, 'owner'>;
|
|
12
13
|
}
|
|
13
14
|
type ReferenceSource = string | OpraSchema.ApiDocument | InitArguments | ApiDocument;
|
|
14
15
|
type ReferenceThunk = ThunkAsync<ReferenceSource>;
|
|
@@ -60,6 +60,7 @@ export declare namespace DataTypeFactory {
|
|
|
60
60
|
*/
|
|
61
61
|
export declare class DataTypeFactory {
|
|
62
62
|
static createDataType(context: DocumentInitContext | undefined, owner: DocumentElement, thunk: DataTypeFactory.DataTypeThunk): Promise<DataType | undefined>;
|
|
63
|
+
static resolveDataType(context: DocumentInitContext | undefined, owner: DocumentElement, v: any): Promise<DataType>;
|
|
63
64
|
/**
|
|
64
65
|
*
|
|
65
66
|
* @param context
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Type } from 'ts-gems';
|
|
2
2
|
import { OpraSchema } from '../../schema/index.js';
|
|
3
|
-
import { ApiDocument } from '../api-document.js';
|
|
4
3
|
import { DocumentInitContext } from '../common/document-init-context.js';
|
|
5
4
|
import { HttpApi } from '../http/http-api.js';
|
|
6
5
|
import { HttpController } from '../http/http-controller.js';
|
|
@@ -9,7 +8,7 @@ import { HttpOperation } from '../http/http-operation.js';
|
|
|
9
8
|
import { HttpOperationResponse } from '../http/http-operation-response.js';
|
|
10
9
|
import { HttpRequestBody } from '../http/http-request-body.js';
|
|
11
10
|
export declare namespace HttpApiFactory {
|
|
12
|
-
interface InitArguments extends
|
|
11
|
+
interface InitArguments extends HttpApi.InitArguments {
|
|
13
12
|
controllers: Type[] | any[] | ((parent: any) => any) | OpraSchema.HttpApi['controllers'];
|
|
14
13
|
}
|
|
15
14
|
}
|
|
@@ -20,11 +19,16 @@ export declare class HttpApiFactory {
|
|
|
20
19
|
/**
|
|
21
20
|
* Generates HttpApi
|
|
22
21
|
* @param context
|
|
23
|
-
* @param document
|
|
24
22
|
* @param init
|
|
25
23
|
*/
|
|
26
|
-
static createApi(context: DocumentInitContext,
|
|
27
|
-
protected static
|
|
24
|
+
static createApi(context: DocumentInitContext, init: HttpApiFactory.InitArguments): Promise<HttpApi>;
|
|
25
|
+
protected static _createControllers(context: DocumentInitContext, parent: HttpApi | HttpController, controllers: Type[] | any[] | ((parent: any) => any) | OpraSchema.HttpApi['controllers']): Promise<void>;
|
|
26
|
+
protected static _resolveControllerMetadata(context: DocumentInitContext, parent: HttpApi | HttpController, thunk: Type | object | Function | OpraSchema.HttpController): Promise<{
|
|
27
|
+
metadata: HttpController.Metadata | OpraSchema.HttpController;
|
|
28
|
+
instance: any;
|
|
29
|
+
ctor: Type;
|
|
30
|
+
} | undefined | void>;
|
|
31
|
+
protected static _createController(context: DocumentInitContext, parent: HttpApi | HttpController, metadata: HttpController.Metadata | OpraSchema.HttpController, instance: any, ctor: Type): Promise<HttpController | undefined | void>;
|
|
28
32
|
/**
|
|
29
33
|
* Initializes HttpOperation
|
|
30
34
|
* @param context
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Type } from 'ts-gems';
|
|
2
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
3
|
+
import { DocumentInitContext } from '../common/document-init-context.js';
|
|
4
|
+
import { RpcApi } from '../rpc/rpc-api.js';
|
|
5
|
+
import { RpcController } from '../rpc/rpc-controller.js';
|
|
6
|
+
import { RpcOperation } from '../rpc/rpc-operation.js';
|
|
7
|
+
import { RpcOperationResponse } from '../rpc/rpc-operation-response.js';
|
|
8
|
+
export declare namespace RpcApiFactory {
|
|
9
|
+
interface InitArguments extends RpcApi.InitArguments {
|
|
10
|
+
controllers: Type[] | any[] | ((parent: any) => any) | OpraSchema.RpcApi['controllers'];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @class RpcApiFactory
|
|
15
|
+
*/
|
|
16
|
+
export declare class RpcApiFactory {
|
|
17
|
+
/**
|
|
18
|
+
* Generates RpcApi
|
|
19
|
+
* @param context
|
|
20
|
+
* @param init
|
|
21
|
+
*/
|
|
22
|
+
static createApi(context: DocumentInitContext, init: RpcApiFactory.InitArguments): Promise<RpcApi>;
|
|
23
|
+
protected static _createController(context: DocumentInitContext, parent: RpcApi, thunk: Type | object | Function | OpraSchema.RpcController, name?: string): Promise<RpcController | undefined | void>;
|
|
24
|
+
/**
|
|
25
|
+
* Initializes RpcOperation
|
|
26
|
+
* @param context
|
|
27
|
+
* @param operation
|
|
28
|
+
* @param metadata
|
|
29
|
+
* @protected
|
|
30
|
+
*/
|
|
31
|
+
protected static _initRpcOperation(context: DocumentInitContext, operation: RpcOperation, metadata: RpcOperation.Metadata | OpraSchema.RpcOperation): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Initializes RpcOperationResponse
|
|
34
|
+
* @param context
|
|
35
|
+
* @param response
|
|
36
|
+
* @param metadata
|
|
37
|
+
* @protected
|
|
38
|
+
*/
|
|
39
|
+
protected static _initRpcOperationResponse(context: DocumentInitContext, response: RpcOperationResponse, metadata: RpcOperationResponse.Metadata | OpraSchema.RpcOperationResponse): Promise<void>;
|
|
40
|
+
}
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import type { Type } from 'ts-gems';
|
|
1
|
+
import type { StrictOmit, Type } from 'ts-gems';
|
|
2
2
|
import { ResponsiveMap } from '../../helpers/index.js';
|
|
3
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import type { ApiDocument } from '../api-document';
|
|
5
5
|
import { ApiBase } from '../common/api-base.js';
|
|
6
6
|
import { HttpController } from './http-controller.js';
|
|
7
7
|
import type { HttpOperation } from './http-operation.js';
|
|
8
|
+
export declare namespace HttpApi {
|
|
9
|
+
interface InitArguments extends ApiBase.InitArguments, StrictOmit<OpraSchema.HttpApi, 'controllers'> {
|
|
10
|
+
transport: 'http';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
8
13
|
/**
|
|
9
14
|
* @class HttpApi
|
|
10
15
|
*/
|
|
11
16
|
export declare class HttpApi extends ApiBase {
|
|
12
17
|
protected _controllerReverseMap: WeakMap<Type, HttpController | null>;
|
|
13
18
|
readonly owner: ApiDocument;
|
|
14
|
-
readonly
|
|
19
|
+
readonly transport = "http";
|
|
15
20
|
controllers: ResponsiveMap<HttpController>;
|
|
16
21
|
url?: string;
|
|
17
|
-
constructor(
|
|
22
|
+
constructor(init: HttpApi.InitArguments);
|
|
18
23
|
findController(controller: Type): HttpController | undefined;
|
|
19
24
|
findController(resourcePath: string): HttpController | undefined;
|
|
20
25
|
findOperation(controller: Type, operationName: string): HttpOperation | undefined;
|
|
@@ -19,6 +19,8 @@ export declare namespace HttpController {
|
|
|
19
19
|
types?: ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray>[];
|
|
20
20
|
operations?: Record<string, HttpOperation.Metadata>;
|
|
21
21
|
parameters?: HttpParameter.Metadata[];
|
|
22
|
+
onInit?: (resource: HttpController) => void;
|
|
23
|
+
onShutdown?: (resource: HttpController) => void | Promise<void>;
|
|
22
24
|
}
|
|
23
25
|
interface Options extends Partial<Pick<OpraSchema.HttpController, 'description' | 'path'>> {
|
|
24
26
|
name?: string;
|
|
@@ -27,11 +29,11 @@ export declare namespace HttpController {
|
|
|
27
29
|
interface InitArguments extends Combine<{
|
|
28
30
|
instance?: object;
|
|
29
31
|
ctor?: Type;
|
|
30
|
-
}, Pick<Metadata, 'name' | 'description' | 'path'>> {
|
|
32
|
+
}, Pick<Metadata, 'name' | 'description' | 'path' | 'onInit' | 'onShutdown'>> {
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
|
-
* Type definition for
|
|
36
|
+
* Type definition for HttpController
|
|
35
37
|
* @class HttpController
|
|
36
38
|
*/
|
|
37
39
|
export interface HttpControllerStatic extends HttpControllerDecoratorFactory {
|
|
@@ -42,6 +44,8 @@ export interface HttpControllerStatic extends HttpControllerDecoratorFactory {
|
|
|
42
44
|
*/
|
|
43
45
|
new (owner: HttpApi | HttpController, args: HttpController.InitArguments): HttpController;
|
|
44
46
|
prototype: HttpController;
|
|
47
|
+
OnInit(): PropertyDecorator;
|
|
48
|
+
OnShutdown(): PropertyDecorator;
|
|
45
49
|
}
|
|
46
50
|
/**
|
|
47
51
|
* Type definition of HttpController prototype
|
|
@@ -69,6 +73,8 @@ declare class HttpControllerClass extends DocumentElement {
|
|
|
69
73
|
operations: ResponsiveMap<HttpOperation>;
|
|
70
74
|
controllers: ResponsiveMap<HttpController>;
|
|
71
75
|
types: DataTypeMap;
|
|
76
|
+
onInit?: (resource: HttpController) => void;
|
|
77
|
+
onShutdown?: (resource: HttpController) => void | Promise<void>;
|
|
72
78
|
/**
|
|
73
79
|
* @property isRoot
|
|
74
80
|
*/
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
+
import * as RpcControllerDecorator_ from './decorators/rpc-controller.decorator.js';
|
|
3
|
+
import * as RpcOperationDecorator_ from './decorators/rpc-operation.decorator.js';
|
|
2
4
|
import * as DataTypeFactory_ from './factory/data-type.factory.js';
|
|
3
5
|
import * as HttpApiFactory_ from './factory/http-api.factory.js';
|
|
4
6
|
export * from './api-document.js';
|
|
@@ -23,6 +25,8 @@ export * from './data-type/primitive-types/index.js';
|
|
|
23
25
|
export * from './data-type/required-type.js';
|
|
24
26
|
export * from './data-type/simple-type.js';
|
|
25
27
|
export * from './decorators/http-operation-entity.decorator.js';
|
|
28
|
+
export type { RpcControllerDecorator } from './decorators/rpc-controller.decorator.js';
|
|
29
|
+
export type { RpcOperationDecorator } from './decorators/rpc-operation.decorator.js';
|
|
26
30
|
export * from './factory/api-document.factory.js';
|
|
27
31
|
export * from './http/http-api.js';
|
|
28
32
|
export * from './http/http-controller.js';
|
|
@@ -33,7 +37,14 @@ export * from './http/http-operation-response.js';
|
|
|
33
37
|
export * from './http/http-parameter.js';
|
|
34
38
|
export * from './http/http-request-body.js';
|
|
35
39
|
export * from './http/http-status-range.js';
|
|
40
|
+
export * from './rpc/rpc-api.js';
|
|
41
|
+
export * from './rpc/rpc-controller.js';
|
|
42
|
+
export * from './rpc/rpc-header.js';
|
|
43
|
+
export * from './rpc/rpc-operation.js';
|
|
44
|
+
export type { RpcOperationResponse } from './rpc/rpc-operation-response';
|
|
36
45
|
export declare namespace classes {
|
|
37
46
|
export import HttpApiFactory = HttpApiFactory_.HttpApiFactory;
|
|
38
47
|
export import DataTypeFactory = DataTypeFactory_.DataTypeFactory;
|
|
48
|
+
export import RpcOperationDecoratorFactory = RpcOperationDecorator_.RpcOperationDecoratorFactory;
|
|
49
|
+
export import RpcControllerDecoratorFactory = RpcControllerDecorator_.RpcControllerDecoratorFactory;
|
|
39
50
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { StrictOmit, Type } from 'ts-gems';
|
|
2
|
+
import { ResponsiveMap } from '../../helpers/index.js';
|
|
3
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
4
|
+
import type { ApiDocument } from '../api-document';
|
|
5
|
+
import { ApiBase } from '../common/api-base.js';
|
|
6
|
+
import { RpcController } from './rpc-controller.js';
|
|
7
|
+
import { RpcOperation } from './rpc-operation.js';
|
|
8
|
+
export declare namespace RpcApi {
|
|
9
|
+
interface InitArguments extends ApiBase.InitArguments, StrictOmit<OpraSchema.RpcApi, 'controllers'> {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @class RpcApi
|
|
14
|
+
*/
|
|
15
|
+
export declare class RpcApi extends ApiBase {
|
|
16
|
+
protected _controllerReverseMap: WeakMap<Type, RpcController | null>;
|
|
17
|
+
readonly owner: ApiDocument;
|
|
18
|
+
readonly transport = "rpc";
|
|
19
|
+
platform: string;
|
|
20
|
+
controllers: ResponsiveMap<RpcController>;
|
|
21
|
+
constructor(init: RpcApi.InitArguments);
|
|
22
|
+
findController(controller: Type): RpcController | undefined;
|
|
23
|
+
findController(name: string): RpcController | undefined;
|
|
24
|
+
findOperation(controller: Type, operationName: string): RpcOperation | undefined;
|
|
25
|
+
findOperation(controllerName: string, operationName: string): RpcOperation | undefined;
|
|
26
|
+
toJSON(): OpraSchema.RpcApi;
|
|
27
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Combine, ThunkAsync, Type } from 'ts-gems';
|
|
2
|
+
import { ResponsiveMap } from '../../helpers/index.js';
|
|
3
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
4
|
+
import { DataTypeMap } from '../common/data-type-map.js';
|
|
5
|
+
import { DocumentElement } from '../common/document-element.js';
|
|
6
|
+
import type { EnumType } from '../data-type/enum-type.js';
|
|
7
|
+
import { RpcControllerDecoratorFactory } from '../decorators/rpc-controller.decorator.js';
|
|
8
|
+
import { nodeInspectCustom } from '../utils/inspect.util.js';
|
|
9
|
+
import type { RpcApi } from './rpc-api';
|
|
10
|
+
import type { RpcHeader } from './rpc-header.js';
|
|
11
|
+
import type { RpcOperation } from './rpc-operation';
|
|
12
|
+
/**
|
|
13
|
+
* @namespace RpcController
|
|
14
|
+
*/
|
|
15
|
+
export declare namespace RpcController {
|
|
16
|
+
interface Metadata extends Pick<OpraSchema.RpcController, 'description'> {
|
|
17
|
+
name: string;
|
|
18
|
+
types?: ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray>[];
|
|
19
|
+
operations?: Record<string, RpcOperation.Metadata>;
|
|
20
|
+
headers?: RpcHeader.Metadata[];
|
|
21
|
+
onInit?: (resource: RpcController) => void;
|
|
22
|
+
onShutdown?: (resource: RpcController) => void | Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
interface Options extends Partial<Pick<OpraSchema.RpcController, 'description'>> {
|
|
25
|
+
name?: string;
|
|
26
|
+
}
|
|
27
|
+
interface InitArguments extends Combine<{
|
|
28
|
+
instance?: object;
|
|
29
|
+
ctor?: Type;
|
|
30
|
+
}, Pick<Metadata, 'name' | 'description' | 'onInit' | 'onShutdown'>> {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Type definition for RpcController
|
|
35
|
+
* @class RpcController
|
|
36
|
+
*/
|
|
37
|
+
export interface RpcControllerStatic extends RpcControllerDecoratorFactory {
|
|
38
|
+
/**
|
|
39
|
+
* Class constructor of RpcController
|
|
40
|
+
* @param owner
|
|
41
|
+
* @param args
|
|
42
|
+
*/
|
|
43
|
+
new (owner: RpcApi | RpcController, args: RpcController.InitArguments): RpcController;
|
|
44
|
+
prototype: RpcController;
|
|
45
|
+
OnInit(): PropertyDecorator;
|
|
46
|
+
OnShutdown(): PropertyDecorator;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Type definition of RpcController prototype
|
|
50
|
+
* @interface RpcController
|
|
51
|
+
*/
|
|
52
|
+
export interface RpcController extends RpcControllerClass {
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* RpcController
|
|
56
|
+
*/
|
|
57
|
+
export declare const RpcController: RpcControllerStatic;
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @class RpcController
|
|
61
|
+
*/
|
|
62
|
+
declare class RpcControllerClass extends DocumentElement {
|
|
63
|
+
protected _controllerReverseMap: WeakMap<Type, RpcController | null>;
|
|
64
|
+
readonly kind: OpraSchema.RpcController.Kind;
|
|
65
|
+
readonly name: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
path: string;
|
|
68
|
+
instance?: any;
|
|
69
|
+
ctor?: Type;
|
|
70
|
+
headers: RpcHeader[];
|
|
71
|
+
operations: ResponsiveMap<RpcOperation>;
|
|
72
|
+
types: DataTypeMap;
|
|
73
|
+
onInit?: (resource: RpcController) => void;
|
|
74
|
+
onShutdown?: (resource: RpcController) => void | Promise<void>;
|
|
75
|
+
findHeader(paramName: string, location?: OpraSchema.HttpParameterLocation): RpcHeader | undefined;
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
toString(): string;
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
toJSON(): OpraSchema.RpcController;
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
*/
|
|
87
|
+
protected [nodeInspectCustom](): string;
|
|
88
|
+
}
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Combine, type StrictOmit, type TypeThunkAsync } from 'ts-gems';
|
|
2
|
+
import type { OpraSchema } from '../../schema/index.js';
|
|
3
|
+
import { DocumentElement } from '../common/document-element.js';
|
|
4
|
+
import { Value } from '../common/value.js';
|
|
5
|
+
import { DataType } from '../data-type/data-type.js';
|
|
6
|
+
import type { EnumType } from '../data-type/enum-type.js';
|
|
7
|
+
/**
|
|
8
|
+
* @namespace RpcHeader
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace RpcHeader {
|
|
11
|
+
interface Metadata extends StrictOmit<OpraSchema.RpcHeader, 'type'> {
|
|
12
|
+
name: string | RegExp;
|
|
13
|
+
type?: string | TypeThunkAsync | EnumType.EnumObject | EnumType.EnumArray | object;
|
|
14
|
+
}
|
|
15
|
+
interface Options extends Partial<StrictOmit<Metadata, 'type'>> {
|
|
16
|
+
type?: string | TypeThunkAsync | object;
|
|
17
|
+
}
|
|
18
|
+
interface InitArguments extends Combine<{
|
|
19
|
+
type?: DataType;
|
|
20
|
+
}, Metadata> {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Type definition for RpcHeader
|
|
25
|
+
* @class RpcHeader
|
|
26
|
+
*/
|
|
27
|
+
interface RpcHeaderStatic {
|
|
28
|
+
new (owner: DocumentElement, args: RpcHeader.InitArguments): RpcHeader;
|
|
29
|
+
prototype: RpcHeader;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Type definition of RpcHeader prototype
|
|
33
|
+
* @interface RpcHeader
|
|
34
|
+
*/
|
|
35
|
+
export interface RpcHeader extends RpcHeaderClass {
|
|
36
|
+
}
|
|
37
|
+
export declare const RpcHeader: RpcHeaderStatic;
|
|
38
|
+
/**
|
|
39
|
+
* @class RpcHeader
|
|
40
|
+
*/
|
|
41
|
+
declare class RpcHeaderClass extends Value {
|
|
42
|
+
readonly owner: DocumentElement;
|
|
43
|
+
deprecated?: boolean | string;
|
|
44
|
+
required?: boolean;
|
|
45
|
+
toJSON(): OpraSchema.RpcHeader;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Combine, Type } from 'ts-gems';
|
|
2
|
+
import { TypeThunkAsync } from 'ts-gems/lib/types';
|
|
3
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
4
|
+
import { DocumentElement } from '../common/document-element.js';
|
|
5
|
+
import { DataType } from '../data-type/data-type.js';
|
|
6
|
+
import type { RpcHeader } from './rpc-header';
|
|
7
|
+
import type { RpcOperation } from './rpc-operation';
|
|
8
|
+
/**
|
|
9
|
+
* @namespace RpcOperationResponse
|
|
10
|
+
*/
|
|
11
|
+
export declare namespace RpcOperationResponse {
|
|
12
|
+
interface Metadata extends Combine<{
|
|
13
|
+
payloadType?: TypeThunkAsync | string;
|
|
14
|
+
keyType?: TypeThunkAsync | string;
|
|
15
|
+
headers?: RpcHeader.Metadata[];
|
|
16
|
+
}, OpraSchema.RpcOperationResponse> {
|
|
17
|
+
}
|
|
18
|
+
interface Options extends Combine<{
|
|
19
|
+
keyType?: Type | string;
|
|
20
|
+
}, Pick<Metadata, 'channel' | 'description'>> {
|
|
21
|
+
}
|
|
22
|
+
interface InitArguments extends Combine<{
|
|
23
|
+
payloadType?: DataType | string | Type;
|
|
24
|
+
keyType?: DataType | string | Type;
|
|
25
|
+
}, Pick<Metadata, 'channel' | 'description'>> {
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @class RpcOperationResponse
|
|
30
|
+
*/
|
|
31
|
+
export declare class RpcOperationResponse extends DocumentElement {
|
|
32
|
+
readonly owner: RpcOperation;
|
|
33
|
+
channel?: string | RegExp | (string | RegExp)[];
|
|
34
|
+
description?: string;
|
|
35
|
+
payloadType: DataType;
|
|
36
|
+
keyType?: DataType;
|
|
37
|
+
headers: RpcHeader[];
|
|
38
|
+
constructor(owner: RpcOperation, initArgs?: RpcOperationResponse.InitArguments);
|
|
39
|
+
findHeader(paramName: string): RpcHeader | undefined;
|
|
40
|
+
toJSON(): OpraSchema.RpcOperationResponse;
|
|
41
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Combine, ThunkAsync, Type } from 'ts-gems';
|
|
2
|
+
import { TypeThunkAsync } from 'ts-gems/lib/types';
|
|
3
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
4
|
+
import { DataTypeMap } from '../common/data-type-map.js';
|
|
5
|
+
import { DocumentElement } from '../common/document-element.js';
|
|
6
|
+
import { DataType } from '../data-type/data-type.js';
|
|
7
|
+
import type { EnumType } from '../data-type/enum-type.js';
|
|
8
|
+
import { RpcOperationDecorator } from '../decorators/rpc-operation.decorator.js';
|
|
9
|
+
import type { RpcController } from './rpc-controller';
|
|
10
|
+
import type { RpcHeader } from './rpc-header';
|
|
11
|
+
import type { RpcOperationResponse } from './rpc-operation-response';
|
|
12
|
+
/**
|
|
13
|
+
* @namespace RpcOperation
|
|
14
|
+
*/
|
|
15
|
+
export declare namespace RpcOperation {
|
|
16
|
+
interface Metadata extends Pick<OpraSchema.RpcOperation, 'description' | 'channel'> {
|
|
17
|
+
payloadType: TypeThunkAsync | string;
|
|
18
|
+
keyType?: TypeThunkAsync | string;
|
|
19
|
+
types?: ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray>[];
|
|
20
|
+
headers?: RpcHeader.Metadata[];
|
|
21
|
+
response?: RpcOperationResponse.Metadata;
|
|
22
|
+
}
|
|
23
|
+
interface Options extends Partial<Pick<Metadata, 'description' | 'keyType'>> {
|
|
24
|
+
channel?: (string | RegExp) | (string | RegExp)[];
|
|
25
|
+
}
|
|
26
|
+
interface InitArguments extends Combine<{
|
|
27
|
+
name: string;
|
|
28
|
+
types?: DataType[];
|
|
29
|
+
payloadType?: DataType | string | Type;
|
|
30
|
+
keyType?: DataType | string | Type;
|
|
31
|
+
}, Pick<Metadata, 'description' | 'channel'>> {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Type definition for RpcOperation
|
|
36
|
+
* @class RpcOperation
|
|
37
|
+
*/
|
|
38
|
+
export interface RpcOperationStatic {
|
|
39
|
+
/**
|
|
40
|
+
* Class constructor of RpcOperation
|
|
41
|
+
* @param controller
|
|
42
|
+
* @param args
|
|
43
|
+
*/
|
|
44
|
+
new (controller: RpcController, args: RpcOperation.InitArguments): RpcOperation;
|
|
45
|
+
/**
|
|
46
|
+
* Property decorator
|
|
47
|
+
* @param payloadType
|
|
48
|
+
* @param options
|
|
49
|
+
*/ <T extends RpcOperation.Options>(payloadType: ThunkAsync<Type> | string, options?: T): RpcOperationDecorator;
|
|
50
|
+
prototype: RpcOperation;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @class RpcOperation
|
|
54
|
+
*/
|
|
55
|
+
export interface RpcOperation extends RpcOperationClass {
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* RpcOperation
|
|
59
|
+
*/
|
|
60
|
+
export declare const RpcOperation: RpcOperationStatic;
|
|
61
|
+
/**
|
|
62
|
+
* @class RpcOperation
|
|
63
|
+
*/
|
|
64
|
+
declare class RpcOperationClass extends DocumentElement {
|
|
65
|
+
readonly owner: RpcController;
|
|
66
|
+
readonly name: string;
|
|
67
|
+
channel: string | RegExp | (string | RegExp)[];
|
|
68
|
+
description?: string;
|
|
69
|
+
payloadType: DataType;
|
|
70
|
+
keyType?: DataType;
|
|
71
|
+
types: DataTypeMap;
|
|
72
|
+
headers: RpcHeader[];
|
|
73
|
+
response: RpcOperationResponse;
|
|
74
|
+
findHeader(paramName: string): RpcHeader | undefined;
|
|
75
|
+
toJSON(): OpraSchema.RpcOperation;
|
|
76
|
+
}
|
|
77
|
+
export {};
|