@midwayjs/core 4.0.0-alpha.1 → 4.0.0-beta.10
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/README.md +1 -1
- package/dist/baseFramework.d.ts +13 -10
- package/dist/baseFramework.js +30 -15
- package/dist/common/applicationManager.js +6 -4
- package/dist/common/asyncContextManager.js +23 -0
- package/dist/common/dataListener.d.ts +5 -3
- package/dist/common/dataListener.js +11 -3
- package/dist/common/dataSourceManager.d.ts +18 -9
- package/dist/common/dataSourceManager.js +129 -77
- package/dist/common/fileDetector.js +2 -4
- package/dist/common/filterManager.js +6 -8
- package/dist/common/loggerFactory.js +1 -3
- package/dist/common/middlewareManager.js +2 -2
- package/dist/common/performanceManager.d.ts +0 -1
- package/dist/common/performanceManager.js +21 -20
- package/dist/common/priorityManager.js +2 -4
- package/dist/common/serviceDiscovery/healthCheck.d.ts +66 -0
- package/dist/common/serviceDiscovery/healthCheck.js +215 -0
- package/dist/common/serviceDiscovery/loadBalancer.d.ts +21 -0
- package/dist/common/serviceDiscovery/loadBalancer.js +49 -0
- package/dist/common/serviceDiscovery/serviceDiscovery.d.ts +59 -0
- package/dist/common/serviceDiscovery/serviceDiscovery.js +107 -0
- package/dist/common/serviceFactory.d.ts +5 -2
- package/dist/common/serviceFactory.js +47 -12
- package/dist/common/typedResourceManager.js +3 -2
- package/dist/common/webGenerator.js +2 -0
- package/dist/config/config.default.js +4 -1
- package/dist/context/componentLoader.js +3 -2
- package/dist/context/container.d.ts +4 -4
- package/dist/context/container.js +15 -10
- package/dist/context/definitionRegistry.d.ts +2 -0
- package/dist/context/definitionRegistry.js +11 -16
- package/dist/context/dynamicContainer.d.ts +17 -0
- package/dist/context/dynamicContainer.js +203 -0
- package/dist/context/managedResolverFactory.d.ts +1 -2
- package/dist/context/managedResolverFactory.js +16 -8
- package/dist/context/providerWrapper.js +1 -2
- package/dist/context/requestContainer.d.ts +1 -0
- package/dist/context/requestContainer.js +8 -2
- package/dist/decorator/common/aspect.js +1 -2
- package/dist/decorator/common/autoload.js +1 -2
- package/dist/decorator/common/configuration.js +1 -2
- package/dist/decorator/common/filter.js +2 -3
- package/dist/decorator/common/framework.js +8 -9
- package/dist/decorator/common/guard.js +2 -3
- package/dist/decorator/common/inject.js +4 -5
- package/dist/decorator/common/middleware.js +1 -2
- package/dist/decorator/common/mock.js +1 -2
- package/dist/decorator/common/objectDef.js +2 -3
- package/dist/decorator/common/pipe.js +1 -2
- package/dist/decorator/common/provide.js +1 -2
- package/dist/decorator/common/scope.js +2 -3
- package/dist/decorator/decoratorManager.js +4 -4
- package/dist/decorator/faas/serverlessTrigger.js +2 -3
- package/dist/decorator/metadataManager.d.ts +14 -6
- package/dist/decorator/metadataManager.js +49 -63
- package/dist/decorator/microservice/consumer.js +1 -2
- package/dist/decorator/microservice/kafkaListener.js +1 -2
- package/dist/decorator/microservice/provider.js +4 -4
- package/dist/decorator/microservice/rabbitmqListener.js +1 -2
- package/dist/decorator/task/queue.js +1 -2
- package/dist/decorator/task/schedule.js +1 -2
- package/dist/decorator/task/task.js +1 -2
- package/dist/decorator/task/taskLocal.js +1 -2
- package/dist/decorator/web/controller.d.ts +6 -0
- package/dist/decorator/web/controller.js +1 -2
- package/dist/decorator/web/response.js +5 -6
- package/dist/decorator/ws/webSocketController.js +1 -2
- package/dist/decorator/ws/webSocketEvent.js +6 -6
- package/dist/definitions/functionDefinition.js +21 -12
- package/dist/definitions/objectCreator.js +5 -2
- package/dist/definitions/objectDefinition.js +19 -17
- package/dist/error/base.js +5 -2
- package/dist/error/framework.d.ts +1 -1
- package/dist/error/framework.js +4 -2
- package/dist/error/http.d.ts +7 -0
- package/dist/error/http.js +11 -1
- package/dist/functional/configuration.d.ts +6 -6
- package/dist/functional/configuration.js +11 -10
- package/dist/functional/hooks.d.ts +3 -1
- package/dist/functional/hooks.js +18 -9
- package/dist/index.d.ts +5 -1
- package/dist/index.js +8 -2
- package/dist/interface.d.ts +179 -21
- package/dist/interface.js +15 -1
- package/dist/legacy/decorator.js +31 -32
- package/dist/response/base.d.ts +3 -5
- package/dist/response/base.js +22 -21
- package/dist/response/http.d.ts +4 -7
- package/dist/response/http.js +12 -12
- package/dist/response/sse.d.ts +0 -1
- package/dist/response/sse.js +4 -1
- package/dist/response/stream.d.ts +0 -1
- package/dist/response/stream.js +3 -1
- package/dist/service/aspectService.js +1 -0
- package/dist/service/configService.d.ts +1 -1
- package/dist/service/configService.js +16 -14
- package/dist/service/decoratorService.js +6 -4
- package/dist/service/environmentService.js +2 -3
- package/dist/service/frameworkService.js +9 -1
- package/dist/service/healthService.d.ts +2 -0
- package/dist/service/healthService.js +20 -8
- package/dist/service/informationService.d.ts +3 -0
- package/dist/service/informationService.js +13 -0
- package/dist/service/lifeCycleService.d.ts +13 -7
- package/dist/service/lifeCycleService.js +55 -33
- package/dist/service/loggerService.js +6 -2
- package/dist/service/middlewareService.js +1 -0
- package/dist/service/mockService.js +17 -15
- package/dist/service/slsFunctionService.js +1 -0
- package/dist/service/webRouterService.d.ts +25 -1
- package/dist/service/webRouterService.js +20 -3
- package/dist/setup.js +12 -6
- package/dist/util/camelCase.js +2 -3
- package/dist/util/contextUtil.d.ts +3 -3
- package/dist/util/extend.js +1 -2
- package/dist/util/flatted.js +2 -3
- package/dist/util/fs.js +2 -2
- package/dist/util/httpclient.d.ts +0 -4
- package/dist/util/httpclient.js +3 -2
- package/dist/util/index.d.ts +3 -18
- package/dist/util/index.js +49 -103
- package/dist/util/network.d.ts +10 -0
- package/dist/util/network.js +40 -0
- package/dist/util/pathFileUtil.d.ts +1 -2
- package/dist/util/pathFileUtil.js +7 -7
- package/dist/util/retry.js +2 -3
- package/dist/util/timeout.d.ts +56 -0
- package/dist/util/timeout.js +143 -0
- package/dist/util/types.d.ts +7 -7
- package/dist/util/types.js +17 -17
- package/dist/util/uuid.js +1 -2
- package/package.json +5 -5
package/dist/interface.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { AsyncContextManager } from './common/asyncContextManager';
|
|
3
2
|
import type { LoggerFactory } from './common/loggerFactory';
|
|
4
3
|
import type { ManagedResolverFactory } from './context/managedResolverFactory';
|
|
@@ -382,6 +381,10 @@ export interface MidwayCoreDefaultConfig {
|
|
|
382
381
|
};
|
|
383
382
|
core?: {
|
|
384
383
|
healthCheckTimeout?: number;
|
|
384
|
+
configLoadTimeout?: number;
|
|
385
|
+
readyTimeout?: number;
|
|
386
|
+
serverReadyTimeout?: number;
|
|
387
|
+
stopTimeout?: number;
|
|
385
388
|
};
|
|
386
389
|
}
|
|
387
390
|
export type ServiceFactoryConfigOption<OPTIONS> = {
|
|
@@ -397,38 +400,44 @@ export type ServiceFactoryConfigOption<OPTIONS> = {
|
|
|
397
400
|
};
|
|
398
401
|
export type CreateDataSourceInstanceOptions = {
|
|
399
402
|
/**
|
|
400
|
-
* @
|
|
403
|
+
* @deprecated
|
|
401
404
|
*/
|
|
402
405
|
validateConnection?: boolean;
|
|
403
406
|
/**
|
|
404
|
-
* @
|
|
407
|
+
* @deprecated
|
|
405
408
|
*/
|
|
406
409
|
cacheInstance?: boolean | undefined;
|
|
407
410
|
};
|
|
408
|
-
export type
|
|
409
|
-
|
|
411
|
+
export type BaseDataSourceManagerConfigOption<OPTIONS extends Record<string, any>, ENTITY_CONFIG_KEY extends string = 'entities'> = OPTIONS & {
|
|
412
|
+
validateConnection?: boolean;
|
|
413
|
+
customDataSourceClass?: any;
|
|
414
|
+
} & {
|
|
415
|
+
[key in ENTITY_CONFIG_KEY]?: any[];
|
|
416
|
+
};
|
|
417
|
+
export interface DataSourceManagerConfigOption<OPTIONS extends Record<string, any>, ENTITY_CONFIG_KEY extends string = 'entities'> extends CreateDataSourceInstanceOptions {
|
|
418
|
+
default?: BaseDataSourceManagerConfigOption<OPTIONS, ENTITY_CONFIG_KEY>;
|
|
410
419
|
defaultDataSourceName?: string;
|
|
411
|
-
dataSource?:
|
|
412
|
-
|
|
413
|
-
[keyName in ENTITY_CONFIG_KEY]: any[];
|
|
414
|
-
}> & OPTIONS;
|
|
415
|
-
};
|
|
416
|
-
} & CreateDataSourceInstanceOptions;
|
|
420
|
+
dataSource?: BaseDataSourceManagerConfigOption<OPTIONS, ENTITY_CONFIG_KEY>;
|
|
421
|
+
}
|
|
417
422
|
type ConfigType<T> = T extends (...args: any[]) => any ? Writable<PowerPartial<ReturnType<T>>> : Writable<PowerPartial<T>>;
|
|
418
423
|
/**
|
|
419
424
|
* Get definition from config
|
|
420
425
|
*/
|
|
421
426
|
export type FileConfigOption<T, K = unknown> = K extends keyof ConfigType<T> ? Pick<ConfigType<T>, K> : ConfigType<T>;
|
|
427
|
+
export interface LifeCycleInvokeOptions {
|
|
428
|
+
abortController: AbortController;
|
|
429
|
+
timeout: number;
|
|
430
|
+
}
|
|
422
431
|
/**
|
|
423
432
|
* Lifecycle Definition
|
|
424
433
|
* 生命周期定义
|
|
425
434
|
*/
|
|
426
435
|
export interface ILifeCycle extends Partial<IObjectLifeCycle> {
|
|
427
|
-
onConfigLoad?(container: IMidwayContainer, mainApp
|
|
428
|
-
onReady?(container: IMidwayContainer, mainApp
|
|
429
|
-
onServerReady?(container: IMidwayContainer, mainApp
|
|
430
|
-
onHealthCheck?(container: IMidwayContainer): Promise<HealthResult>;
|
|
431
|
-
onStop?(container: IMidwayContainer, mainApp
|
|
436
|
+
onConfigLoad?(container: IMidwayContainer, mainApp: IMidwayApplication, options: LifeCycleInvokeOptions): Promise<any>;
|
|
437
|
+
onReady?(container: IMidwayContainer, mainApp: IMidwayApplication, options: LifeCycleInvokeOptions): Promise<void>;
|
|
438
|
+
onServerReady?(container: IMidwayContainer, mainApp: IMidwayApplication, options: LifeCycleInvokeOptions): Promise<void>;
|
|
439
|
+
onHealthCheck?(container: IMidwayContainer, mainApp: IMidwayApplication, options: LifeCycleInvokeOptions): Promise<HealthResult>;
|
|
440
|
+
onStop?(container: IMidwayContainer, mainApp: IMidwayApplication, options: LifeCycleInvokeOptions): Promise<void>;
|
|
432
441
|
}
|
|
433
442
|
/**
|
|
434
443
|
* Abstract Object Factory
|
|
@@ -544,6 +553,7 @@ export interface IObjectDefinitionRegistry {
|
|
|
544
553
|
clearAll(): void;
|
|
545
554
|
hasObject(identifier: ObjectIdentifier): boolean;
|
|
546
555
|
registerObject(identifier: ObjectIdentifier, target: any): any;
|
|
556
|
+
removeObject(identifier: ObjectIdentifier): void;
|
|
547
557
|
getObject(identifier: ObjectIdentifier): any;
|
|
548
558
|
getIdentifierRelation(): IIdentifierRelationShip;
|
|
549
559
|
setIdentifierRelation(identifierRelation: IIdentifierRelationShip): any;
|
|
@@ -581,8 +591,8 @@ export interface IMidwayGlobalContainer extends IMidwayContainer, WithFn<IObject
|
|
|
581
591
|
objectCreateEventTarget: EventEmitter;
|
|
582
592
|
getNamespaceList(): string[];
|
|
583
593
|
addNamespace(namespace: string): void;
|
|
584
|
-
bind<T>(target: T, options?: Partial<IObjectDefinition>):
|
|
585
|
-
bind<T>(identifier: ObjectIdentifier, target: T, options?: Partial<IObjectDefinition>):
|
|
594
|
+
bind<T>(target: T, options?: Partial<IObjectDefinition>): IObjectDefinition | undefined;
|
|
595
|
+
bind<T>(identifier: ObjectIdentifier, target: T, options?: Partial<IObjectDefinition>): IObjectDefinition | undefined;
|
|
586
596
|
bindClass(exports: any, options?: Partial<IObjectDefinition>): void;
|
|
587
597
|
stop(): Promise<void>;
|
|
588
598
|
getManagedResolverFactory(): ManagedResolverFactory;
|
|
@@ -597,6 +607,7 @@ export interface IMidwayContainer extends IObjectFactory {
|
|
|
597
607
|
getDefinition(identifier: ObjectIdentifier): IObjectDefinition;
|
|
598
608
|
hasObject(identifier: ObjectIdentifier): boolean;
|
|
599
609
|
getObject<T>(identifier: ObjectIdentifier): T;
|
|
610
|
+
removeObject(identifier: ObjectIdentifier): void;
|
|
600
611
|
/**
|
|
601
612
|
* Set value to app attribute map
|
|
602
613
|
* @param key
|
|
@@ -759,7 +770,7 @@ export interface IMidwayBaseApplication<CTX extends IMidwayContext> {
|
|
|
759
770
|
* Get all configuration values or get the specified configuration through parameters
|
|
760
771
|
* @param key config key
|
|
761
772
|
*/
|
|
762
|
-
getConfig(key?: string):
|
|
773
|
+
getConfig<T = any>(key?: string): T;
|
|
763
774
|
/**
|
|
764
775
|
* Get default logger object or get the specified logger through parameters
|
|
765
776
|
* @param name
|
|
@@ -832,7 +843,6 @@ export interface IMidwayBaseApplication<CTX extends IMidwayContext> {
|
|
|
832
843
|
export type IMidwayApplication<T extends IMidwayContext = IMidwayContext, FrameworkApplication = unknown> = IMidwayBaseApplication<T> & FrameworkApplication;
|
|
833
844
|
export type ModuleLoadType = 'commonjs' | 'esm';
|
|
834
845
|
export interface IMidwayBootstrapOptions {
|
|
835
|
-
[customPropertyKey: string]: any;
|
|
836
846
|
baseDir?: string;
|
|
837
847
|
appDir?: string;
|
|
838
848
|
applicationContext?: IMidwayGlobalContainer;
|
|
@@ -857,7 +867,7 @@ export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX exten
|
|
|
857
867
|
configurationOptions: CONFIG;
|
|
858
868
|
configure(options?: CONFIG): CONFIG;
|
|
859
869
|
isEnable(): boolean;
|
|
860
|
-
initialize(options:
|
|
870
|
+
initialize(options: IMidwayBootstrapOptions): Promise<void>;
|
|
861
871
|
run(): Promise<void>;
|
|
862
872
|
stop(): Promise<void>;
|
|
863
873
|
getApplication(): APP;
|
|
@@ -878,6 +888,7 @@ export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX exten
|
|
|
878
888
|
useGuard(guard: CommonGuardUnion<CTX>): void;
|
|
879
889
|
runGuard(ctx: CTX, supplierClz: new (...args: any[]) => any, methodName: string): Promise<boolean>;
|
|
880
890
|
getNamespace(): string;
|
|
891
|
+
setFrameworkLoggerName(name: string): void;
|
|
881
892
|
}
|
|
882
893
|
export interface MidwayAppInfo {
|
|
883
894
|
pkg: Record<string, any>;
|
|
@@ -908,6 +919,20 @@ export interface IServiceFactory<Client> {
|
|
|
908
919
|
isMediumPriority(clientName: string): boolean;
|
|
909
920
|
isLowPriority(clientName: string): boolean;
|
|
910
921
|
}
|
|
922
|
+
export interface IDataSourceManager<DataSource, DataSourceConfig> {
|
|
923
|
+
createInstance(config: DataSourceConfig): Promise<DataSource | void>;
|
|
924
|
+
getDataSource(dataSourceName: string): DataSource;
|
|
925
|
+
getDataSourceNames(): string[];
|
|
926
|
+
getAllDataSources(): Map<string, DataSource>;
|
|
927
|
+
hasDataSource(dataSourceName: string): boolean;
|
|
928
|
+
isConnected(dataSourceName: string): Promise<boolean>;
|
|
929
|
+
getDefaultDataSourceName(): string;
|
|
930
|
+
stop(): Promise<void>;
|
|
931
|
+
getDataSourcePriority(dataSourceName: string): string;
|
|
932
|
+
isHighPriority(dataSourceName: string): boolean;
|
|
933
|
+
isMediumPriority(dataSourceName: string): boolean;
|
|
934
|
+
isLowPriority(dataSourceName: string): boolean;
|
|
935
|
+
}
|
|
911
936
|
export interface ISimulation {
|
|
912
937
|
setup?(): Promise<void>;
|
|
913
938
|
tearDown?(): Promise<void>;
|
|
@@ -978,5 +1003,138 @@ export interface InjectionConfigurationOptions {
|
|
|
978
1003
|
detector?: IFileDetector | false;
|
|
979
1004
|
}
|
|
980
1005
|
export type FunctionalConfigurationOptions = InjectionConfigurationOptions & ILifeCycle;
|
|
1006
|
+
/**
|
|
1007
|
+
* 负载均衡策略类型
|
|
1008
|
+
*/
|
|
1009
|
+
export declare const LoadBalancerType: {
|
|
1010
|
+
readonly RANDOM: "random";
|
|
1011
|
+
readonly ROUND_ROBIN: "roundRobin";
|
|
1012
|
+
};
|
|
1013
|
+
export type LoadBalancerType = typeof LoadBalancerType[keyof typeof LoadBalancerType];
|
|
1014
|
+
export declare const ServiceDiscoveryHealthCheckType: {
|
|
1015
|
+
readonly SELF: "self";
|
|
1016
|
+
readonly TTL: "ttl";
|
|
1017
|
+
readonly HTTP: "http";
|
|
1018
|
+
readonly TCP: "tcp";
|
|
1019
|
+
readonly CUSTOM: "custom";
|
|
1020
|
+
};
|
|
1021
|
+
export type ServiceDiscoveryHealthCheckType = typeof ServiceDiscoveryHealthCheckType[keyof typeof ServiceDiscoveryHealthCheckType];
|
|
1022
|
+
/**
|
|
1023
|
+
* 基础健康检查配置
|
|
1024
|
+
*/
|
|
1025
|
+
export interface BaseServiceDiscoveryHealthCheckOptions {
|
|
1026
|
+
/**
|
|
1027
|
+
* 检查间隔(毫秒)
|
|
1028
|
+
*/
|
|
1029
|
+
interval?: number;
|
|
1030
|
+
/**
|
|
1031
|
+
* 检查超时时间(毫秒)
|
|
1032
|
+
*/
|
|
1033
|
+
timeout?: number;
|
|
1034
|
+
/**
|
|
1035
|
+
* 最大重试次数
|
|
1036
|
+
*/
|
|
1037
|
+
maxRetries?: number;
|
|
1038
|
+
/**
|
|
1039
|
+
* 重试间隔(毫秒)
|
|
1040
|
+
*/
|
|
1041
|
+
retryInterval?: number;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* TTL 健康检查配置
|
|
1045
|
+
*/
|
|
1046
|
+
export interface TTLServiceDiscoveryHealthCheckOptions extends BaseServiceDiscoveryHealthCheckOptions {
|
|
1047
|
+
/**
|
|
1048
|
+
* TTL 时间(秒)
|
|
1049
|
+
*/
|
|
1050
|
+
ttl: number;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* HTTP 健康检查配置
|
|
1054
|
+
*/
|
|
1055
|
+
export interface HTTPServiceDiscoveryHealthCheckOptions extends BaseServiceDiscoveryHealthCheckOptions {
|
|
1056
|
+
/**
|
|
1057
|
+
* 健康检查 URL
|
|
1058
|
+
*/
|
|
1059
|
+
url: string;
|
|
1060
|
+
/**
|
|
1061
|
+
* HTTP 方法
|
|
1062
|
+
*/
|
|
1063
|
+
method?: string;
|
|
1064
|
+
/**
|
|
1065
|
+
* HTTP 请求头
|
|
1066
|
+
*/
|
|
1067
|
+
headers?: Record<string, string>;
|
|
1068
|
+
/**
|
|
1069
|
+
* 期望的 HTTP 状态码
|
|
1070
|
+
*/
|
|
1071
|
+
expectedStatus?: number;
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* TCP 健康检查配置
|
|
1075
|
+
*/
|
|
1076
|
+
export interface TCPServiceDiscoveryHealthCheckOptions extends BaseServiceDiscoveryHealthCheckOptions {
|
|
1077
|
+
/**
|
|
1078
|
+
* 主机地址
|
|
1079
|
+
*/
|
|
1080
|
+
host: string;
|
|
1081
|
+
/**
|
|
1082
|
+
* 端口号
|
|
1083
|
+
*/
|
|
1084
|
+
port: number;
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* 健康检查配置联合类型
|
|
1088
|
+
*/
|
|
1089
|
+
export type ServiceDiscoveryHealthCheckOptions = TTLServiceDiscoveryHealthCheckOptions | HTTPServiceDiscoveryHealthCheckOptions | TCPServiceDiscoveryHealthCheckOptions;
|
|
1090
|
+
export interface ServiceDiscoveryBaseInstance {
|
|
1091
|
+
}
|
|
1092
|
+
export interface DefaultInstanceMetadata {
|
|
1093
|
+
id: string;
|
|
1094
|
+
serviceName: string;
|
|
1095
|
+
host: string;
|
|
1096
|
+
port: number;
|
|
1097
|
+
metadata: Record<string, any>;
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* 健康检查结果
|
|
1101
|
+
*/
|
|
1102
|
+
export interface ServiceDiscoveryHealthCheckResult {
|
|
1103
|
+
status: 'passing' | 'warning' | 'critical' | 'unknown';
|
|
1104
|
+
message?: string;
|
|
1105
|
+
timestamp: number;
|
|
1106
|
+
}
|
|
1107
|
+
export interface IServiceDiscoveryHealthCheck<ServiceInstance> {
|
|
1108
|
+
check(instance: ServiceInstance): Promise<ServiceDiscoveryHealthCheckResult>;
|
|
1109
|
+
}
|
|
1110
|
+
export interface ServiceDiscoveryOptions<ServiceInstance, serviceOptions = Record<string, any>> {
|
|
1111
|
+
serviceDiscoveryClient?: string;
|
|
1112
|
+
serviceOptions?: serviceOptions;
|
|
1113
|
+
loadBalancer?: LoadBalancerType | ILoadBalancer<ServiceInstance>;
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* 负载均衡策略接口
|
|
1117
|
+
*/
|
|
1118
|
+
export interface ILoadBalancer<ServiceInstance> {
|
|
1119
|
+
/**
|
|
1120
|
+
* 从服务实例列表中选择一个实例
|
|
1121
|
+
* @param instances 服务实例列表
|
|
1122
|
+
*/
|
|
1123
|
+
select(instances: ServiceInstance[]): ServiceInstance;
|
|
1124
|
+
}
|
|
1125
|
+
export interface IServiceDiscoveryClient<ServiceInstance> {
|
|
1126
|
+
/**
|
|
1127
|
+
* 注册服务实例
|
|
1128
|
+
*/
|
|
1129
|
+
register(instance: unknown): Promise<void>;
|
|
1130
|
+
/**
|
|
1131
|
+
* 上线服务实例
|
|
1132
|
+
*/
|
|
1133
|
+
online(): Promise<void>;
|
|
1134
|
+
/**
|
|
1135
|
+
* 下线服务实例
|
|
1136
|
+
*/
|
|
1137
|
+
offline(): Promise<void>;
|
|
1138
|
+
}
|
|
981
1139
|
export {};
|
|
982
1140
|
//# sourceMappingURL=interface.d.ts.map
|
package/dist/interface.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MidwayProcessTypeEnum = exports.ObjectLifeCycleEvent = exports.ServerlessTriggerType = exports.MSListenerType = exports.MSProviderType = exports.InjectModeEnum = exports.ScopeEnum = void 0;
|
|
3
|
+
exports.ServiceDiscoveryHealthCheckType = exports.LoadBalancerType = exports.MidwayProcessTypeEnum = exports.ObjectLifeCycleEvent = exports.ServerlessTriggerType = exports.MSListenerType = exports.MSProviderType = exports.InjectModeEnum = exports.ScopeEnum = void 0;
|
|
4
4
|
var ScopeEnum;
|
|
5
5
|
(function (ScopeEnum) {
|
|
6
6
|
ScopeEnum["Singleton"] = "Singleton";
|
|
@@ -53,4 +53,18 @@ var MidwayProcessTypeEnum;
|
|
|
53
53
|
MidwayProcessTypeEnum["APPLICATION"] = "APPLICATION";
|
|
54
54
|
MidwayProcessTypeEnum["AGENT"] = "AGENT";
|
|
55
55
|
})(MidwayProcessTypeEnum || (exports.MidwayProcessTypeEnum = MidwayProcessTypeEnum = {}));
|
|
56
|
+
/**
|
|
57
|
+
* 负载均衡策略类型
|
|
58
|
+
*/
|
|
59
|
+
exports.LoadBalancerType = {
|
|
60
|
+
RANDOM: 'random',
|
|
61
|
+
ROUND_ROBIN: 'roundRobin',
|
|
62
|
+
};
|
|
63
|
+
exports.ServiceDiscoveryHealthCheckType = {
|
|
64
|
+
SELF: 'self',
|
|
65
|
+
TTL: 'ttl',
|
|
66
|
+
HTTP: 'http',
|
|
67
|
+
TCP: 'tcp',
|
|
68
|
+
CUSTOM: 'custom'
|
|
69
|
+
};
|
|
56
70
|
//# sourceMappingURL=interface.js.map
|
package/dist/legacy/decorator.js
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.saveClassMetadata = saveClassMetadata;
|
|
4
|
+
exports.attachClassMetadata = attachClassMetadata;
|
|
5
|
+
exports.getClassExtendedMetadata = getClassExtendedMetadata;
|
|
6
|
+
exports.getClassMetadata = getClassMetadata;
|
|
7
|
+
exports.savePropertyDataToClass = savePropertyDataToClass;
|
|
8
|
+
exports.attachPropertyDataToClass = attachPropertyDataToClass;
|
|
9
|
+
exports.getPropertyDataFromClass = getPropertyDataFromClass;
|
|
10
|
+
exports.listPropertyDataFromClass = listPropertyDataFromClass;
|
|
11
|
+
exports.savePropertyMetadata = savePropertyMetadata;
|
|
12
|
+
exports.attachPropertyMetadata = attachPropertyMetadata;
|
|
13
|
+
exports.getPropertyMetadata = getPropertyMetadata;
|
|
14
|
+
exports.savePreloadModule = savePreloadModule;
|
|
15
|
+
exports.listPreloadModule = listPreloadModule;
|
|
16
|
+
exports.saveModule = saveModule;
|
|
17
|
+
exports.listModule = listModule;
|
|
18
|
+
exports.resetModule = resetModule;
|
|
19
|
+
exports.clearAllModule = clearAllModule;
|
|
20
|
+
exports.saveProviderId = saveProviderId;
|
|
21
|
+
exports.getProviderId = getProviderId;
|
|
22
|
+
exports.getProviderName = getProviderName;
|
|
23
|
+
exports.getProviderUUId = getProviderUUId;
|
|
24
|
+
exports.isProvide = isProvide;
|
|
25
|
+
exports.createCustomPropertyDecorator = createCustomPropertyDecorator;
|
|
26
|
+
exports.createCustomMethodDecorator = createCustomMethodDecorator;
|
|
27
|
+
exports.createCustomParamDecorator = createCustomParamDecorator;
|
|
28
|
+
exports.getPropertyType = getPropertyType;
|
|
29
|
+
exports.getMethodParamTypes = getMethodParamTypes;
|
|
30
|
+
exports.savePropertyInject = savePropertyInject;
|
|
31
|
+
exports.getPropertyInject = getPropertyInject;
|
|
32
|
+
exports.saveObjectDefinition = saveObjectDefinition;
|
|
33
|
+
exports.getObjectDefinition = getObjectDefinition;
|
|
4
34
|
const metadataManager_1 = require("../decorator/metadataManager");
|
|
5
35
|
const decorator_1 = require("../decorator");
|
|
6
36
|
const inject_1 = require("../decorator/common/inject");
|
|
@@ -39,7 +69,6 @@ function saveClassMetadata(decoratorNameKey, data, target, mergeIfExist) {
|
|
|
39
69
|
}
|
|
40
70
|
return metadataManager_1.MetadataManager.defineMetadata(decoratorNameKey, data, target);
|
|
41
71
|
}
|
|
42
|
-
exports.saveClassMetadata = saveClassMetadata;
|
|
43
72
|
/**
|
|
44
73
|
* attach data to class
|
|
45
74
|
* @param decoratorNameKey
|
|
@@ -52,7 +81,6 @@ exports.saveClassMetadata = saveClassMetadata;
|
|
|
52
81
|
function attachClassMetadata(decoratorNameKey, data, target, groupBy) {
|
|
53
82
|
return metadataManager_1.MetadataManager.attachMetadata(decoratorNameKey, data, target, groupBy);
|
|
54
83
|
}
|
|
55
|
-
exports.attachClassMetadata = attachClassMetadata;
|
|
56
84
|
function _getClassExtendedMetadata(decoratorNameKey, target, propertyName, useCache) {
|
|
57
85
|
const ret = metadataManager_1.MetadataManager.getPropertiesWithMetadata(decoratorNameKey, target);
|
|
58
86
|
// array item to object
|
|
@@ -87,7 +115,6 @@ function getClassExtendedMetadata(decoratorNameKey, target, propertyName, useCac
|
|
|
87
115
|
}
|
|
88
116
|
return ret;
|
|
89
117
|
}
|
|
90
|
-
exports.getClassExtendedMetadata = getClassExtendedMetadata;
|
|
91
118
|
/**
|
|
92
119
|
* get data from class
|
|
93
120
|
* @param decoratorNameKey
|
|
@@ -98,7 +125,6 @@ exports.getClassExtendedMetadata = getClassExtendedMetadata;
|
|
|
98
125
|
function getClassMetadata(decoratorNameKey, target) {
|
|
99
126
|
return metadataManager_1.MetadataManager.getOwnMetadata(decoratorNameKey, target);
|
|
100
127
|
}
|
|
101
|
-
exports.getClassMetadata = getClassMetadata;
|
|
102
128
|
/**
|
|
103
129
|
* save property data to class
|
|
104
130
|
* @param decoratorNameKey
|
|
@@ -115,7 +141,6 @@ function savePropertyDataToClass(decoratorNameKey, data, target, propertyName) {
|
|
|
115
141
|
originMap.set(dataKey, data);
|
|
116
142
|
return metadataManager_1.MetadataManager.defineMetadata(legacyListPropertyDataKey, originMap, target);
|
|
117
143
|
}
|
|
118
|
-
exports.savePropertyDataToClass = savePropertyDataToClass;
|
|
119
144
|
/**
|
|
120
145
|
* attach property data to class
|
|
121
146
|
* @param decoratorNameKey
|
|
@@ -139,7 +164,6 @@ function attachPropertyDataToClass(decoratorNameKey, data, target, propertyName)
|
|
|
139
164
|
}
|
|
140
165
|
return metadataManager_1.MetadataManager.defineMetadata(legacyListPropertyDataKey, originMap, target);
|
|
141
166
|
}
|
|
142
|
-
exports.attachPropertyDataToClass = attachPropertyDataToClass;
|
|
143
167
|
/**
|
|
144
168
|
* get property data from class
|
|
145
169
|
* @param decoratorNameKey
|
|
@@ -153,7 +177,6 @@ function getPropertyDataFromClass(decoratorNameKey, target, propertyName) {
|
|
|
153
177
|
const originMap = metadataManager_1.MetadataManager.getOwnMetadata(legacyListPropertyDataKey, target);
|
|
154
178
|
return originMap && originMap.get(dataKey);
|
|
155
179
|
}
|
|
156
|
-
exports.getPropertyDataFromClass = getPropertyDataFromClass;
|
|
157
180
|
/**
|
|
158
181
|
* list property data from class
|
|
159
182
|
* @param decoratorNameKey
|
|
@@ -172,7 +195,6 @@ function listPropertyDataFromClass(decoratorNameKey, target) {
|
|
|
172
195
|
}
|
|
173
196
|
return res;
|
|
174
197
|
}
|
|
175
|
-
exports.listPropertyDataFromClass = listPropertyDataFromClass;
|
|
176
198
|
/**
|
|
177
199
|
* save property data
|
|
178
200
|
* @param decoratorNameKey
|
|
@@ -185,7 +207,6 @@ exports.listPropertyDataFromClass = listPropertyDataFromClass;
|
|
|
185
207
|
function savePropertyMetadata(decoratorNameKey, data, target, propertyName) {
|
|
186
208
|
return metadataManager_1.MetadataManager.defineMetadata(decoratorNameKey, data, target, propertyName);
|
|
187
209
|
}
|
|
188
|
-
exports.savePropertyMetadata = savePropertyMetadata;
|
|
189
210
|
/**
|
|
190
211
|
* attach property data
|
|
191
212
|
* @param decoratorNameKey
|
|
@@ -198,7 +219,6 @@ exports.savePropertyMetadata = savePropertyMetadata;
|
|
|
198
219
|
function attachPropertyMetadata(decoratorNameKey, data, target, propertyName) {
|
|
199
220
|
return metadataManager_1.MetadataManager.attachMetadata(decoratorNameKey, data, target, propertyName);
|
|
200
221
|
}
|
|
201
|
-
exports.attachPropertyMetadata = attachPropertyMetadata;
|
|
202
222
|
/**
|
|
203
223
|
* get property data
|
|
204
224
|
* @param decoratorNameKey
|
|
@@ -210,7 +230,6 @@ exports.attachPropertyMetadata = attachPropertyMetadata;
|
|
|
210
230
|
function getPropertyMetadata(decoratorNameKey, target, propertyName) {
|
|
211
231
|
return metadataManager_1.MetadataManager.getOwnMetadata(decoratorNameKey, target, propertyName);
|
|
212
232
|
}
|
|
213
|
-
exports.getPropertyMetadata = getPropertyMetadata;
|
|
214
233
|
/**
|
|
215
234
|
* save preload module by target
|
|
216
235
|
* @param target
|
|
@@ -220,7 +239,6 @@ exports.getPropertyMetadata = getPropertyMetadata;
|
|
|
220
239
|
function savePreloadModule(target) {
|
|
221
240
|
return decorator_1.DecoratorManager.savePreStartModule(target);
|
|
222
241
|
}
|
|
223
|
-
exports.savePreloadModule = savePreloadModule;
|
|
224
242
|
/**
|
|
225
243
|
* list preload module
|
|
226
244
|
* @since 2.0.0
|
|
@@ -229,7 +247,6 @@ exports.savePreloadModule = savePreloadModule;
|
|
|
229
247
|
function listPreloadModule() {
|
|
230
248
|
return decorator_1.DecoratorManager.listPreStartModule();
|
|
231
249
|
}
|
|
232
|
-
exports.listPreloadModule = listPreloadModule;
|
|
233
250
|
/**
|
|
234
251
|
* save module to inner map
|
|
235
252
|
* @param decoratorNameKey
|
|
@@ -240,7 +257,6 @@ exports.listPreloadModule = listPreloadModule;
|
|
|
240
257
|
function saveModule(decoratorNameKey, target) {
|
|
241
258
|
return decorator_1.DecoratorManager.saveModule(decoratorNameKey, target);
|
|
242
259
|
}
|
|
243
|
-
exports.saveModule = saveModule;
|
|
244
260
|
/**
|
|
245
261
|
* list module from decorator key
|
|
246
262
|
* @param decoratorNameKey
|
|
@@ -251,7 +267,6 @@ exports.saveModule = saveModule;
|
|
|
251
267
|
function listModule(decoratorNameKey, filter) {
|
|
252
268
|
return decorator_1.DecoratorManager.listModule(decoratorNameKey, filter);
|
|
253
269
|
}
|
|
254
|
-
exports.listModule = listModule;
|
|
255
270
|
/**
|
|
256
271
|
* reset module
|
|
257
272
|
* @param decoratorNameKey
|
|
@@ -261,7 +276,6 @@ exports.listModule = listModule;
|
|
|
261
276
|
function resetModule(decoratorNameKey) {
|
|
262
277
|
return decorator_1.DecoratorManager.resetModule(decoratorNameKey);
|
|
263
278
|
}
|
|
264
|
-
exports.resetModule = resetModule;
|
|
265
279
|
/**
|
|
266
280
|
* clear all module
|
|
267
281
|
* @since 3.0.0
|
|
@@ -270,7 +284,6 @@ exports.resetModule = resetModule;
|
|
|
270
284
|
function clearAllModule() {
|
|
271
285
|
return decorator_1.DecoratorManager.clearAllModule();
|
|
272
286
|
}
|
|
273
|
-
exports.clearAllModule = clearAllModule;
|
|
274
287
|
/**
|
|
275
288
|
* class provider id
|
|
276
289
|
* @since 2.3.0
|
|
@@ -279,7 +292,6 @@ exports.clearAllModule = clearAllModule;
|
|
|
279
292
|
function saveProviderId(identifier, target) {
|
|
280
293
|
return decorator_1.DecoratorManager.saveProviderId(identifier, target);
|
|
281
294
|
}
|
|
282
|
-
exports.saveProviderId = saveProviderId;
|
|
283
295
|
/**
|
|
284
296
|
* get provider id from module
|
|
285
297
|
* @since 3.0.0
|
|
@@ -288,7 +300,6 @@ exports.saveProviderId = saveProviderId;
|
|
|
288
300
|
function getProviderId(module) {
|
|
289
301
|
return decorator_1.DecoratorManager.getProviderId(module);
|
|
290
302
|
}
|
|
291
|
-
exports.getProviderId = getProviderId;
|
|
292
303
|
/**
|
|
293
304
|
* @since 3.0.0
|
|
294
305
|
* @deprecated Use DecoratorManager.getProviderName instead
|
|
@@ -296,7 +307,6 @@ exports.getProviderId = getProviderId;
|
|
|
296
307
|
function getProviderName(module) {
|
|
297
308
|
return decorator_1.DecoratorManager.getProviderName(module);
|
|
298
309
|
}
|
|
299
|
-
exports.getProviderName = getProviderName;
|
|
300
310
|
/**
|
|
301
311
|
* get provider uuid from module
|
|
302
312
|
* @since 3.0.0
|
|
@@ -305,7 +315,6 @@ exports.getProviderName = getProviderName;
|
|
|
305
315
|
function getProviderUUId(module) {
|
|
306
316
|
return decorator_1.DecoratorManager.getProviderUUId(module);
|
|
307
317
|
}
|
|
308
|
-
exports.getProviderUUId = getProviderUUId;
|
|
309
318
|
/**
|
|
310
319
|
* use @Provide decorator or not
|
|
311
320
|
* @since 3.0.0
|
|
@@ -314,7 +323,6 @@ exports.getProviderUUId = getProviderUUId;
|
|
|
314
323
|
function isProvide(target) {
|
|
315
324
|
return decorator_1.DecoratorManager.isProvide(target);
|
|
316
325
|
}
|
|
317
|
-
exports.isProvide = isProvide;
|
|
318
326
|
/**
|
|
319
327
|
* Create a custom property inject
|
|
320
328
|
* @param decoratorKey
|
|
@@ -326,7 +334,6 @@ exports.isProvide = isProvide;
|
|
|
326
334
|
function createCustomPropertyDecorator(decoratorKey, metadata, impl = true) {
|
|
327
335
|
return decorator_1.DecoratorManager.createCustomPropertyDecorator(decoratorKey, metadata, impl);
|
|
328
336
|
}
|
|
329
|
-
exports.createCustomPropertyDecorator = createCustomPropertyDecorator;
|
|
330
337
|
/**
|
|
331
338
|
* Create a custom method decorator
|
|
332
339
|
* @param decoratorKey
|
|
@@ -338,7 +345,6 @@ exports.createCustomPropertyDecorator = createCustomPropertyDecorator;
|
|
|
338
345
|
function createCustomMethodDecorator(decoratorKey, metadata, implOrOptions = { impl: true }) {
|
|
339
346
|
return decorator_1.DecoratorManager.createCustomMethodDecorator(decoratorKey, metadata, implOrOptions);
|
|
340
347
|
}
|
|
341
|
-
exports.createCustomMethodDecorator = createCustomMethodDecorator;
|
|
342
348
|
/**
|
|
343
349
|
* Create a custom param decorator
|
|
344
350
|
* @param decoratorKey
|
|
@@ -350,7 +356,6 @@ exports.createCustomMethodDecorator = createCustomMethodDecorator;
|
|
|
350
356
|
function createCustomParamDecorator(decoratorKey, metadata, implOrOptions = { impl: true }) {
|
|
351
357
|
return decorator_1.DecoratorManager.createCustomParamDecorator(decoratorKey, metadata, implOrOptions);
|
|
352
358
|
}
|
|
353
|
-
exports.createCustomParamDecorator = createCustomParamDecorator;
|
|
354
359
|
/**
|
|
355
360
|
* get property(method) type from metadata
|
|
356
361
|
* @param target
|
|
@@ -361,7 +366,6 @@ exports.createCustomParamDecorator = createCustomParamDecorator;
|
|
|
361
366
|
function getPropertyType(target, methodName) {
|
|
362
367
|
return metadataManager_1.MetadataManager.transformTypeFromTSDesign(metadataManager_1.MetadataManager.getPropertyType(target, methodName));
|
|
363
368
|
}
|
|
364
|
-
exports.getPropertyType = getPropertyType;
|
|
365
369
|
/**
|
|
366
370
|
* get parameters type by reflect-metadata
|
|
367
371
|
* @since 3.0.0
|
|
@@ -370,7 +374,6 @@ exports.getPropertyType = getPropertyType;
|
|
|
370
374
|
function getMethodParamTypes(target, methodName) {
|
|
371
375
|
return metadataManager_1.MetadataManager.getMethodParamTypes(target, methodName);
|
|
372
376
|
}
|
|
373
|
-
exports.getMethodParamTypes = getMethodParamTypes;
|
|
374
377
|
/**
|
|
375
378
|
* save property inject args
|
|
376
379
|
* @param opts 参数
|
|
@@ -380,7 +383,6 @@ exports.getMethodParamTypes = getMethodParamTypes;
|
|
|
380
383
|
function savePropertyInject(opts) {
|
|
381
384
|
(0, inject_1.saveInjectMetadata)(opts.identifier, opts.target, opts.targetKey);
|
|
382
385
|
}
|
|
383
|
-
exports.savePropertyInject = savePropertyInject;
|
|
384
386
|
/**
|
|
385
387
|
* get property inject args
|
|
386
388
|
* @param target
|
|
@@ -398,7 +400,6 @@ function getPropertyInject(target, useCache) {
|
|
|
398
400
|
}
|
|
399
401
|
return ret;
|
|
400
402
|
}
|
|
401
|
-
exports.getPropertyInject = getPropertyInject;
|
|
402
403
|
/**
|
|
403
404
|
* save class object definition
|
|
404
405
|
* @param target class
|
|
@@ -410,7 +411,6 @@ function saveObjectDefinition(target, props = {}) {
|
|
|
410
411
|
metadataManager_1.MetadataManager.attachMetadata(constants_1.OBJ_DEF_CLS, props, target, '__fake_object_def_method');
|
|
411
412
|
return target;
|
|
412
413
|
}
|
|
413
|
-
exports.saveObjectDefinition = saveObjectDefinition;
|
|
414
414
|
/**
|
|
415
415
|
* get class object definition from metadata
|
|
416
416
|
* @param target
|
|
@@ -464,5 +464,4 @@ function getObjectDefinition(target) {
|
|
|
464
464
|
return Object.assign(res, scope);
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
|
-
exports.getObjectDefinition = getObjectDefinition;
|
|
468
467
|
//# sourceMappingURL=decorator.js.map
|
package/dist/response/base.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import { IMidwayContext } from '../interface';
|
|
4
2
|
export declare class ServerResponse<CTX extends IMidwayContext = IMidwayContext> {
|
|
5
3
|
protected readonly ctx: any;
|
|
6
4
|
protected isSuccess: boolean;
|
|
7
5
|
constructor(ctx: CTX);
|
|
8
|
-
static TEXT_TPL: <CTX_1 extends
|
|
9
|
-
static JSON_TPL: <CTX_1 extends
|
|
10
|
-
static BLOB_TPL: <CTX_1 extends
|
|
6
|
+
static TEXT_TPL: <CTX_1 extends IMidwayContext>(data: string, isSuccess: boolean, ctx: CTX_1) => unknown;
|
|
7
|
+
static JSON_TPL: <CTX_1 extends IMidwayContext>(data: Record<any, any>, isSuccess: boolean, ctx: CTX_1) => unknown;
|
|
8
|
+
static BLOB_TPL: <CTX_1 extends IMidwayContext>(data: Buffer, isSuccess: boolean, ctx: CTX_1) => unknown;
|
|
11
9
|
json(data: Record<any, any>): any;
|
|
12
10
|
text(data: string): any;
|
|
13
11
|
blob(data: Buffer): any;
|
package/dist/response/base.js
CHANGED
|
@@ -2,10 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServerResponse = void 0;
|
|
4
4
|
class ServerResponse {
|
|
5
|
+
ctx;
|
|
6
|
+
isSuccess = true;
|
|
5
7
|
constructor(ctx) {
|
|
6
|
-
this.isSuccess = true;
|
|
7
8
|
this.ctx = ctx;
|
|
8
9
|
}
|
|
10
|
+
static TEXT_TPL = (data, isSuccess, ctx) => {
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
static JSON_TPL = (data, isSuccess, ctx) => {
|
|
14
|
+
if (isSuccess) {
|
|
15
|
+
return {
|
|
16
|
+
success: 'true',
|
|
17
|
+
data,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return {
|
|
22
|
+
success: 'false',
|
|
23
|
+
message: data || 'fail',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
static BLOB_TPL = (data, isSuccess, ctx) => {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
9
30
|
json(data) {
|
|
10
31
|
return Object.getPrototypeOf(this).constructor.JSON_TPL(data, this.isSuccess, this.ctx);
|
|
11
32
|
}
|
|
@@ -25,24 +46,4 @@ class ServerResponse {
|
|
|
25
46
|
}
|
|
26
47
|
}
|
|
27
48
|
exports.ServerResponse = ServerResponse;
|
|
28
|
-
ServerResponse.TEXT_TPL = (data, isSuccess, ctx) => {
|
|
29
|
-
return data;
|
|
30
|
-
};
|
|
31
|
-
ServerResponse.JSON_TPL = (data, isSuccess, ctx) => {
|
|
32
|
-
if (isSuccess) {
|
|
33
|
-
return {
|
|
34
|
-
success: 'true',
|
|
35
|
-
data,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return {
|
|
40
|
-
success: 'false',
|
|
41
|
-
message: data || 'fail',
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
ServerResponse.BLOB_TPL = (data, isSuccess, ctx) => {
|
|
46
|
-
return data;
|
|
47
|
-
};
|
|
48
49
|
//# sourceMappingURL=base.js.map
|