@orion-js/echoes 4.3.2 → 4.4.0
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/LICENSE +21 -0
- package/dist/config.d.ts +3 -0
- package/dist/echo/deserialize.d.ts +1 -0
- package/dist/echo/index.d.ts +9 -0
- package/dist/index.d.ts +7 -145
- package/dist/publish/index.d.ts +5 -0
- package/dist/publish/serialize.d.ts +1 -0
- package/dist/request/getPassword.d.ts +1 -0
- package/dist/request/getSignature.d.ts +1 -0
- package/dist/request/getURL.d.ts +1 -0
- package/dist/request/index.d.ts +2 -0
- package/dist/request/makeRequest.d.ts +2 -0
- package/dist/requestsHandler/checkSignature.d.ts +1 -0
- package/dist/requestsHandler/getEcho.d.ts +1 -0
- package/dist/requestsHandler/index.d.ts +3 -0
- package/dist/service/index.d.ts +10 -0
- package/dist/startService/KafkaManager.d.ts +23 -0
- package/dist/startService/index.d.ts +3 -0
- package/dist/types.d.ts +114 -0
- package/package.json +15 -16
- package/dist/index.d.cts +0 -145
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Orionjs Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (serializedJavascript: string): any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EchoType, EchoConfig, EchoRequestConfig, EchoEventConfig } from '../types';
|
|
2
|
+
import { SchemaFieldType } from '@orion-js/schema';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use createEchoRequest and createEchoEvent instead
|
|
5
|
+
*/
|
|
6
|
+
declare const echo: <TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType, TEchoType extends 'event' | 'request'>(options: EchoConfig<TParamsSchema, TReturnsSchema, TEchoType>) => EchoType<TParamsSchema, TReturnsSchema, TEchoType>;
|
|
7
|
+
export declare function createEchoRequest<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType>(options: EchoRequestConfig<TParamsSchema, TReturnsSchema>): EchoType<TParamsSchema, TReturnsSchema, 'request'>;
|
|
8
|
+
export declare function createEchoEvent<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType>(options: EchoEventConfig<TParamsSchema, TReturnsSchema>): EchoType<TParamsSchema, TReturnsSchema, 'event'>;
|
|
9
|
+
export { echo };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,145 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
resolve(params?: InferSchemaType<TParamsSchema>, context?: any): Promise<InferSchemaType<TReturnsSchema>>;
|
|
9
|
-
attemptsBeforeDeadLetter?: number;
|
|
10
|
-
}
|
|
11
|
-
interface EchoEventConfig<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType> {
|
|
12
|
-
params?: TParamsSchema;
|
|
13
|
-
returns?: TReturnsSchema;
|
|
14
|
-
resolve(params?: InferSchemaType<TParamsSchema>, context?: any): Promise<InferSchemaType<TReturnsSchema>>;
|
|
15
|
-
attemptsBeforeDeadLetter?: number;
|
|
16
|
-
}
|
|
17
|
-
type EchoConfig<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType, TEchoType extends 'event' | 'request' = 'event' | 'request'> = (TEchoType extends 'event' ? EchoEventConfig<TParamsSchema, TReturnsSchema> : EchoRequestConfig<TParamsSchema, TReturnsSchema>) & {
|
|
18
|
-
type: TEchoType;
|
|
19
|
-
};
|
|
20
|
-
type EchoType<TParamsSchema extends SchemaFieldType = any, TReturnsSchema extends SchemaFieldType = any, TEchoType extends 'event' | 'request' = 'event' | 'request'> = {
|
|
21
|
-
params?: TParamsSchema;
|
|
22
|
-
returns?: TReturnsSchema;
|
|
23
|
-
attemptsBeforeDeadLetter?: number;
|
|
24
|
-
type: TEchoType;
|
|
25
|
-
resolve(params?: InferSchemaType<TParamsSchema>, context?: any): Promise<InferSchemaType<TReturnsSchema>>;
|
|
26
|
-
onMessage(messageData: EachMessagePayload): Promise<void>;
|
|
27
|
-
onRequest(serializedParams: string): any;
|
|
28
|
-
};
|
|
29
|
-
interface PublishOptions<TParams = any> {
|
|
30
|
-
topic: string;
|
|
31
|
-
params: TParams;
|
|
32
|
-
acks?: number;
|
|
33
|
-
timeout?: number;
|
|
34
|
-
}
|
|
35
|
-
interface RequestOptions<TParams> {
|
|
36
|
-
method: string;
|
|
37
|
-
service: string;
|
|
38
|
-
params: TParams;
|
|
39
|
-
retries?: number;
|
|
40
|
-
timeout?: number;
|
|
41
|
-
}
|
|
42
|
-
interface RequestHandlerResponse {
|
|
43
|
-
result?: any;
|
|
44
|
-
error?: any;
|
|
45
|
-
isUserError?: boolean;
|
|
46
|
-
isValidationError?: boolean;
|
|
47
|
-
errorInfo?: {
|
|
48
|
-
error: string;
|
|
49
|
-
message: string;
|
|
50
|
-
extra?: any;
|
|
51
|
-
validationErrors?: any;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
interface MakeRequestParams {
|
|
55
|
-
url: string;
|
|
56
|
-
retries?: number;
|
|
57
|
-
timeout?: number;
|
|
58
|
-
data: {
|
|
59
|
-
body: object;
|
|
60
|
-
signature: string;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
interface RequestMakerResult {
|
|
64
|
-
statusCode: number;
|
|
65
|
-
data: object;
|
|
66
|
-
}
|
|
67
|
-
type RequestMaker = (options: MakeRequestParams) => Promise<RequestMakerResult>;
|
|
68
|
-
interface RequestsConfig {
|
|
69
|
-
/**
|
|
70
|
-
* The secret key used to sign all requests. Shared between all your services.
|
|
71
|
-
* You can also set the env var echoes_password or process.env.ECHOES_PASSWORD
|
|
72
|
-
*/
|
|
73
|
-
key?: string;
|
|
74
|
-
/**
|
|
75
|
-
* The path of the echoes http receiver. Defaults to /echoes-services
|
|
76
|
-
*/
|
|
77
|
-
handlerPath?: string;
|
|
78
|
-
/**
|
|
79
|
-
* Map of all the services that have echoes requests handlers
|
|
80
|
-
*/
|
|
81
|
-
services?: {
|
|
82
|
-
[key: string]: string;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* A custom function that make the requests to the services. Uses axios by default
|
|
86
|
-
*/
|
|
87
|
-
makeRequest?: RequestMaker;
|
|
88
|
-
}
|
|
89
|
-
interface EchoesMap {
|
|
90
|
-
[key: string]: EchoType<any, any>;
|
|
91
|
-
}
|
|
92
|
-
interface EchoesOptions {
|
|
93
|
-
client?: KafkaConfig;
|
|
94
|
-
producer?: ProducerConfig;
|
|
95
|
-
consumer?: ConsumerConfig;
|
|
96
|
-
requests?: RequestsConfig;
|
|
97
|
-
echoes: EchoesMap;
|
|
98
|
-
/**
|
|
99
|
-
* Defaults to true. When true, allows a reconnecting service to read missed messages.
|
|
100
|
-
*/
|
|
101
|
-
readTopicsFromBeginning?: boolean;
|
|
102
|
-
/**
|
|
103
|
-
* Defaults to 4. How many partitions to consume concurrently, adjust this with the members to partitions ratio to avoid idle consumers.
|
|
104
|
-
*/
|
|
105
|
-
partitionsConsumedConcurrently?: number;
|
|
106
|
-
/**
|
|
107
|
-
* Defaults to 1. How many members are in comparison to partitions, this is used to determine if the consumer group has room for more members. Numbers over 1 leads to idle consumers. Numbers under 1 needs partitionsConsumedConcurrently to be more than 1.
|
|
108
|
-
*/
|
|
109
|
-
membersToPartitionsRatio?: number;
|
|
110
|
-
}
|
|
111
|
-
interface EchoesConfigHandler {
|
|
112
|
-
producer?: Producer;
|
|
113
|
-
consumer?: Consumer;
|
|
114
|
-
requests?: RequestsConfig;
|
|
115
|
-
echoes?: EchoesMap;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
declare function startService(options: EchoesOptions): Promise<void>;
|
|
119
|
-
declare function stopService(): Promise<void>;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Publish
|
|
123
|
-
*/
|
|
124
|
-
declare function publish<TParams = any>(options: PublishOptions<TParams>): Promise<kafkajs.RecordMetadata[]>;
|
|
125
|
-
|
|
126
|
-
declare function request<TData = any, TParams = any>(options: RequestOptions<TParams>): Promise<TData>;
|
|
127
|
-
|
|
128
|
-
interface EchoesPropertyDescriptor extends Omit<PropertyDecorator, 'value'> {
|
|
129
|
-
value?: EchoConfig<any, any>['resolve'];
|
|
130
|
-
}
|
|
131
|
-
declare function Echoes(): (target: any, context: ClassDecoratorContext<any>) => void;
|
|
132
|
-
declare function EchoEvent(): (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => any;
|
|
133
|
-
declare function EchoEvent(options?: Omit<EchoConfig<any, any>, 'resolve' | 'type'>): (method: any, context: ClassMethodDecoratorContext) => any;
|
|
134
|
-
declare function EchoRequest(): (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => any;
|
|
135
|
-
declare function EchoRequest(options?: Omit<EchoConfig<any, any>, 'resolve' | 'type'>): (method: any, context: ClassMethodDecoratorContext) => any;
|
|
136
|
-
declare function getServiceEchoes(target: any): EchoesMap;
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* @deprecated Use createEchoRequest and createEchoEvent instead
|
|
140
|
-
*/
|
|
141
|
-
declare const echo: <TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType, TEchoType extends "event" | "request">(options: EchoConfig<TParamsSchema, TReturnsSchema, TEchoType>) => EchoType<TParamsSchema, TReturnsSchema, TEchoType>;
|
|
142
|
-
declare function createEchoRequest<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType>(options: EchoRequestConfig<TParamsSchema, TReturnsSchema>): EchoType<TParamsSchema, TReturnsSchema, 'request'>;
|
|
143
|
-
declare function createEchoEvent<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType>(options: EchoEventConfig<TParamsSchema, TReturnsSchema>): EchoType<TParamsSchema, TReturnsSchema, 'event'>;
|
|
144
|
-
|
|
145
|
-
export { type EchoConfig, EchoEvent, type EchoEventConfig, EchoRequest, type EchoRequestConfig, type EchoType, Echoes, type EchoesConfigHandler, type EchoesMap, type EchoesOptions, type EchoesPropertyDescriptor, type MakeRequestParams, type PublishOptions, type RequestHandlerResponse, type RequestMaker, type RequestMakerResult, type RequestOptions, type RequestsConfig, createEchoEvent, createEchoRequest, echo, getServiceEchoes, publish, request, startService, stopService };
|
|
1
|
+
import startService, { stopService } from './startService';
|
|
2
|
+
import publish from './publish';
|
|
3
|
+
import request from './request';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './service';
|
|
6
|
+
export * from './echo';
|
|
7
|
+
export { publish, startService, stopService, request };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (data: any): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getEchoesPassword(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (body: any): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (serviceName: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (body: any, signature: string): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (method: string): import("..").EchoType<any, any, "event" | "request">;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { EchoesOptions } from '../types';
|
|
2
|
+
export default _default;
|
|
3
|
+
declare function _default(options: EchoesOptions): import("@orion-js/http").RouteType<string, import("@orion-js/schema").Schema, import("@orion-js/schema").Schema, import("@orion-js/schema").SchemaFieldType>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EchoConfig, EchoesMap } from '../types';
|
|
2
|
+
export interface EchoesPropertyDescriptor extends Omit<PropertyDecorator, 'value'> {
|
|
3
|
+
value?: EchoConfig<any, any>['resolve'];
|
|
4
|
+
}
|
|
5
|
+
export declare function Echoes(): (target: any, context: ClassDecoratorContext<any>) => void;
|
|
6
|
+
export declare function EchoEvent(): (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => any;
|
|
7
|
+
export declare function EchoEvent(options?: Omit<EchoConfig<any, any>, 'resolve' | 'type'>): (method: any, context: ClassMethodDecoratorContext) => any;
|
|
8
|
+
export declare function EchoRequest(): (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => any;
|
|
9
|
+
export declare function EchoRequest(options?: Omit<EchoConfig<any, any>, 'resolve' | 'type'>): (method: any, context: ClassMethodDecoratorContext) => any;
|
|
10
|
+
export declare function getServiceEchoes(target: any): EchoesMap;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Kafka, EachMessagePayload, Producer, Consumer } from 'kafkajs';
|
|
2
|
+
import { EchoesOptions, EchoType } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Manages the Kafka connection and the consumers.
|
|
5
|
+
*/
|
|
6
|
+
declare class KafkaManager {
|
|
7
|
+
kafka: Kafka;
|
|
8
|
+
options: EchoesOptions;
|
|
9
|
+
producer: Producer;
|
|
10
|
+
consumer: Consumer;
|
|
11
|
+
topics: string[];
|
|
12
|
+
started: boolean;
|
|
13
|
+
interval: NodeJS.Timeout;
|
|
14
|
+
constructor(options: EchoesOptions);
|
|
15
|
+
checkJoinConsumerGroupConditions(): Promise<boolean>;
|
|
16
|
+
joinConsumerGroup(): Promise<void>;
|
|
17
|
+
conditionalStart(): Promise<boolean>;
|
|
18
|
+
start(): Promise<void>;
|
|
19
|
+
stop(): Promise<void>;
|
|
20
|
+
handleMessage(params: EachMessagePayload): Promise<void>;
|
|
21
|
+
handleRetries(echo: EchoType, params: EachMessagePayload, error: Error): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export default KafkaManager;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { InferSchemaType, SchemaFieldType } from '@orion-js/schema';
|
|
2
|
+
import { ConsumerConfig, KafkaConfig, ProducerConfig, Consumer, Producer, EachMessagePayload } from 'kafkajs';
|
|
3
|
+
export interface EchoRequestConfig<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType> {
|
|
4
|
+
params?: TParamsSchema;
|
|
5
|
+
returns?: TReturnsSchema;
|
|
6
|
+
resolve(params?: InferSchemaType<TParamsSchema>, context?: any): Promise<InferSchemaType<TReturnsSchema>>;
|
|
7
|
+
attemptsBeforeDeadLetter?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface EchoEventConfig<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType> {
|
|
10
|
+
params?: TParamsSchema;
|
|
11
|
+
returns?: TReturnsSchema;
|
|
12
|
+
resolve(params?: InferSchemaType<TParamsSchema>, context?: any): Promise<InferSchemaType<TReturnsSchema>>;
|
|
13
|
+
attemptsBeforeDeadLetter?: number;
|
|
14
|
+
}
|
|
15
|
+
export type EchoConfig<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType, TEchoType extends 'event' | 'request' = 'event' | 'request'> = (TEchoType extends 'event' ? EchoEventConfig<TParamsSchema, TReturnsSchema> : EchoRequestConfig<TParamsSchema, TReturnsSchema>) & {
|
|
16
|
+
type: TEchoType;
|
|
17
|
+
};
|
|
18
|
+
export type EchoType<TParamsSchema extends SchemaFieldType = any, TReturnsSchema extends SchemaFieldType = any, TEchoType extends 'event' | 'request' = 'event' | 'request'> = {
|
|
19
|
+
params?: TParamsSchema;
|
|
20
|
+
returns?: TReturnsSchema;
|
|
21
|
+
attemptsBeforeDeadLetter?: number;
|
|
22
|
+
type: TEchoType;
|
|
23
|
+
resolve(params?: InferSchemaType<TParamsSchema>, context?: any): Promise<InferSchemaType<TReturnsSchema>>;
|
|
24
|
+
onMessage(messageData: EachMessagePayload): Promise<void>;
|
|
25
|
+
onRequest(serializedParams: string): any;
|
|
26
|
+
};
|
|
27
|
+
export interface PublishOptions<TParams = any> {
|
|
28
|
+
topic: string;
|
|
29
|
+
params: TParams;
|
|
30
|
+
acks?: number;
|
|
31
|
+
timeout?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface RequestOptions<TParams> {
|
|
34
|
+
method: string;
|
|
35
|
+
service: string;
|
|
36
|
+
params: TParams;
|
|
37
|
+
retries?: number;
|
|
38
|
+
timeout?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface RequestHandlerResponse {
|
|
41
|
+
result?: any;
|
|
42
|
+
error?: any;
|
|
43
|
+
isUserError?: boolean;
|
|
44
|
+
isValidationError?: boolean;
|
|
45
|
+
errorInfo?: {
|
|
46
|
+
error: string;
|
|
47
|
+
message: string;
|
|
48
|
+
extra?: any;
|
|
49
|
+
validationErrors?: any;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface MakeRequestParams {
|
|
53
|
+
url: string;
|
|
54
|
+
retries?: number;
|
|
55
|
+
timeout?: number;
|
|
56
|
+
data: {
|
|
57
|
+
body: object;
|
|
58
|
+
signature: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface RequestMakerResult {
|
|
62
|
+
statusCode: number;
|
|
63
|
+
data: object;
|
|
64
|
+
}
|
|
65
|
+
export type RequestMaker = (options: MakeRequestParams) => Promise<RequestMakerResult>;
|
|
66
|
+
export interface RequestsConfig {
|
|
67
|
+
/**
|
|
68
|
+
* The secret key used to sign all requests. Shared between all your services.
|
|
69
|
+
* You can also set the env var echoes_password or process.env.ECHOES_PASSWORD
|
|
70
|
+
*/
|
|
71
|
+
key?: string;
|
|
72
|
+
/**
|
|
73
|
+
* The path of the echoes http receiver. Defaults to /echoes-services
|
|
74
|
+
*/
|
|
75
|
+
handlerPath?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Map of all the services that have echoes requests handlers
|
|
78
|
+
*/
|
|
79
|
+
services?: {
|
|
80
|
+
[key: string]: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* A custom function that make the requests to the services. Uses axios by default
|
|
84
|
+
*/
|
|
85
|
+
makeRequest?: RequestMaker;
|
|
86
|
+
}
|
|
87
|
+
export interface EchoesMap {
|
|
88
|
+
[key: string]: EchoType<any, any>;
|
|
89
|
+
}
|
|
90
|
+
export interface EchoesOptions {
|
|
91
|
+
client?: KafkaConfig;
|
|
92
|
+
producer?: ProducerConfig;
|
|
93
|
+
consumer?: ConsumerConfig;
|
|
94
|
+
requests?: RequestsConfig;
|
|
95
|
+
echoes: EchoesMap;
|
|
96
|
+
/**
|
|
97
|
+
* Defaults to true. When true, allows a reconnecting service to read missed messages.
|
|
98
|
+
*/
|
|
99
|
+
readTopicsFromBeginning?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Defaults to 4. How many partitions to consume concurrently, adjust this with the members to partitions ratio to avoid idle consumers.
|
|
102
|
+
*/
|
|
103
|
+
partitionsConsumedConcurrently?: number;
|
|
104
|
+
/**
|
|
105
|
+
* Defaults to 1. How many members are in comparison to partitions, this is used to determine if the consumer group has room for more members. Numbers over 1 leads to idle consumers. Numbers under 1 needs partitionsConsumedConcurrently to be more than 1.
|
|
106
|
+
*/
|
|
107
|
+
membersToPartitionsRatio?: number;
|
|
108
|
+
}
|
|
109
|
+
export interface EchoesConfigHandler {
|
|
110
|
+
producer?: Producer;
|
|
111
|
+
consumer?: Consumer;
|
|
112
|
+
requests?: RequestsConfig;
|
|
113
|
+
echoes?: EchoesMap;
|
|
114
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/echoes",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -8,33 +8,26 @@
|
|
|
8
8
|
],
|
|
9
9
|
"author": "nicolaslopezj",
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"test": "bun test",
|
|
13
|
-
"prepare": "bun run build",
|
|
14
|
-
"clean": "rm -rf ./dist",
|
|
15
|
-
"build": "tsup",
|
|
16
|
-
"dev": "tsup --watch"
|
|
17
|
-
},
|
|
18
11
|
"dependencies": {
|
|
19
|
-
"@orion-js/env": "4.
|
|
20
|
-
"@orion-js/helpers": "4.
|
|
21
|
-
"@orion-js/http": "4.
|
|
22
|
-
"@orion-js/schema": "4.
|
|
23
|
-
"@orion-js/services": "4.
|
|
12
|
+
"@orion-js/env": "4.4.0",
|
|
13
|
+
"@orion-js/helpers": "4.4.0",
|
|
14
|
+
"@orion-js/http": "4.4.0",
|
|
15
|
+
"@orion-js/schema": "4.4.0",
|
|
16
|
+
"@orion-js/services": "4.4.0",
|
|
24
17
|
"axios": "^0.24.0",
|
|
25
18
|
"jssha": "^3.2.0",
|
|
26
19
|
"kafkajs": "^2.2.4",
|
|
27
20
|
"serialize-javascript": "^6.0.0"
|
|
28
21
|
},
|
|
29
22
|
"peerDependencies": {
|
|
30
|
-
"@orion-js/logger": "4.
|
|
23
|
+
"@orion-js/logger": "4.4.0"
|
|
31
24
|
},
|
|
32
25
|
"devDependencies": {
|
|
33
26
|
"@types/node": "^18.0.0",
|
|
34
27
|
"@types/supertest": "2.0.11",
|
|
35
28
|
"supertest": "^6.1.6",
|
|
36
29
|
"tsup": "^8.0.1",
|
|
37
|
-
"typescript": "^
|
|
30
|
+
"typescript": "^7.0.2"
|
|
38
31
|
},
|
|
39
32
|
"publishConfig": {
|
|
40
33
|
"access": "public"
|
|
@@ -46,5 +39,11 @@
|
|
|
46
39
|
"types": "./dist/index.d.ts",
|
|
47
40
|
"import": "./dist/index.js",
|
|
48
41
|
"require": "./dist/index.cjs"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "bun test",
|
|
45
|
+
"clean": "rm -rf ./dist",
|
|
46
|
+
"build": "tsup && bun run ../../scripts/emit-declarations.ts",
|
|
47
|
+
"dev": "tsup --watch"
|
|
49
48
|
}
|
|
50
|
-
}
|
|
49
|
+
}
|
package/dist/index.d.cts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { SchemaFieldType, InferSchemaType } from '@orion-js/schema';
|
|
2
|
-
import * as kafkajs from 'kafkajs';
|
|
3
|
-
import { EachMessagePayload, Producer, Consumer, KafkaConfig, ProducerConfig, ConsumerConfig } from 'kafkajs';
|
|
4
|
-
|
|
5
|
-
interface EchoRequestConfig<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType> {
|
|
6
|
-
params?: TParamsSchema;
|
|
7
|
-
returns?: TReturnsSchema;
|
|
8
|
-
resolve(params?: InferSchemaType<TParamsSchema>, context?: any): Promise<InferSchemaType<TReturnsSchema>>;
|
|
9
|
-
attemptsBeforeDeadLetter?: number;
|
|
10
|
-
}
|
|
11
|
-
interface EchoEventConfig<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType> {
|
|
12
|
-
params?: TParamsSchema;
|
|
13
|
-
returns?: TReturnsSchema;
|
|
14
|
-
resolve(params?: InferSchemaType<TParamsSchema>, context?: any): Promise<InferSchemaType<TReturnsSchema>>;
|
|
15
|
-
attemptsBeforeDeadLetter?: number;
|
|
16
|
-
}
|
|
17
|
-
type EchoConfig<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType, TEchoType extends 'event' | 'request' = 'event' | 'request'> = (TEchoType extends 'event' ? EchoEventConfig<TParamsSchema, TReturnsSchema> : EchoRequestConfig<TParamsSchema, TReturnsSchema>) & {
|
|
18
|
-
type: TEchoType;
|
|
19
|
-
};
|
|
20
|
-
type EchoType<TParamsSchema extends SchemaFieldType = any, TReturnsSchema extends SchemaFieldType = any, TEchoType extends 'event' | 'request' = 'event' | 'request'> = {
|
|
21
|
-
params?: TParamsSchema;
|
|
22
|
-
returns?: TReturnsSchema;
|
|
23
|
-
attemptsBeforeDeadLetter?: number;
|
|
24
|
-
type: TEchoType;
|
|
25
|
-
resolve(params?: InferSchemaType<TParamsSchema>, context?: any): Promise<InferSchemaType<TReturnsSchema>>;
|
|
26
|
-
onMessage(messageData: EachMessagePayload): Promise<void>;
|
|
27
|
-
onRequest(serializedParams: string): any;
|
|
28
|
-
};
|
|
29
|
-
interface PublishOptions<TParams = any> {
|
|
30
|
-
topic: string;
|
|
31
|
-
params: TParams;
|
|
32
|
-
acks?: number;
|
|
33
|
-
timeout?: number;
|
|
34
|
-
}
|
|
35
|
-
interface RequestOptions<TParams> {
|
|
36
|
-
method: string;
|
|
37
|
-
service: string;
|
|
38
|
-
params: TParams;
|
|
39
|
-
retries?: number;
|
|
40
|
-
timeout?: number;
|
|
41
|
-
}
|
|
42
|
-
interface RequestHandlerResponse {
|
|
43
|
-
result?: any;
|
|
44
|
-
error?: any;
|
|
45
|
-
isUserError?: boolean;
|
|
46
|
-
isValidationError?: boolean;
|
|
47
|
-
errorInfo?: {
|
|
48
|
-
error: string;
|
|
49
|
-
message: string;
|
|
50
|
-
extra?: any;
|
|
51
|
-
validationErrors?: any;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
interface MakeRequestParams {
|
|
55
|
-
url: string;
|
|
56
|
-
retries?: number;
|
|
57
|
-
timeout?: number;
|
|
58
|
-
data: {
|
|
59
|
-
body: object;
|
|
60
|
-
signature: string;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
interface RequestMakerResult {
|
|
64
|
-
statusCode: number;
|
|
65
|
-
data: object;
|
|
66
|
-
}
|
|
67
|
-
type RequestMaker = (options: MakeRequestParams) => Promise<RequestMakerResult>;
|
|
68
|
-
interface RequestsConfig {
|
|
69
|
-
/**
|
|
70
|
-
* The secret key used to sign all requests. Shared between all your services.
|
|
71
|
-
* You can also set the env var echoes_password or process.env.ECHOES_PASSWORD
|
|
72
|
-
*/
|
|
73
|
-
key?: string;
|
|
74
|
-
/**
|
|
75
|
-
* The path of the echoes http receiver. Defaults to /echoes-services
|
|
76
|
-
*/
|
|
77
|
-
handlerPath?: string;
|
|
78
|
-
/**
|
|
79
|
-
* Map of all the services that have echoes requests handlers
|
|
80
|
-
*/
|
|
81
|
-
services?: {
|
|
82
|
-
[key: string]: string;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* A custom function that make the requests to the services. Uses axios by default
|
|
86
|
-
*/
|
|
87
|
-
makeRequest?: RequestMaker;
|
|
88
|
-
}
|
|
89
|
-
interface EchoesMap {
|
|
90
|
-
[key: string]: EchoType<any, any>;
|
|
91
|
-
}
|
|
92
|
-
interface EchoesOptions {
|
|
93
|
-
client?: KafkaConfig;
|
|
94
|
-
producer?: ProducerConfig;
|
|
95
|
-
consumer?: ConsumerConfig;
|
|
96
|
-
requests?: RequestsConfig;
|
|
97
|
-
echoes: EchoesMap;
|
|
98
|
-
/**
|
|
99
|
-
* Defaults to true. When true, allows a reconnecting service to read missed messages.
|
|
100
|
-
*/
|
|
101
|
-
readTopicsFromBeginning?: boolean;
|
|
102
|
-
/**
|
|
103
|
-
* Defaults to 4. How many partitions to consume concurrently, adjust this with the members to partitions ratio to avoid idle consumers.
|
|
104
|
-
*/
|
|
105
|
-
partitionsConsumedConcurrently?: number;
|
|
106
|
-
/**
|
|
107
|
-
* Defaults to 1. How many members are in comparison to partitions, this is used to determine if the consumer group has room for more members. Numbers over 1 leads to idle consumers. Numbers under 1 needs partitionsConsumedConcurrently to be more than 1.
|
|
108
|
-
*/
|
|
109
|
-
membersToPartitionsRatio?: number;
|
|
110
|
-
}
|
|
111
|
-
interface EchoesConfigHandler {
|
|
112
|
-
producer?: Producer;
|
|
113
|
-
consumer?: Consumer;
|
|
114
|
-
requests?: RequestsConfig;
|
|
115
|
-
echoes?: EchoesMap;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
declare function startService(options: EchoesOptions): Promise<void>;
|
|
119
|
-
declare function stopService(): Promise<void>;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Publish
|
|
123
|
-
*/
|
|
124
|
-
declare function publish<TParams = any>(options: PublishOptions<TParams>): Promise<kafkajs.RecordMetadata[]>;
|
|
125
|
-
|
|
126
|
-
declare function request<TData = any, TParams = any>(options: RequestOptions<TParams>): Promise<TData>;
|
|
127
|
-
|
|
128
|
-
interface EchoesPropertyDescriptor extends Omit<PropertyDecorator, 'value'> {
|
|
129
|
-
value?: EchoConfig<any, any>['resolve'];
|
|
130
|
-
}
|
|
131
|
-
declare function Echoes(): (target: any, context: ClassDecoratorContext<any>) => void;
|
|
132
|
-
declare function EchoEvent(): (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => any;
|
|
133
|
-
declare function EchoEvent(options?: Omit<EchoConfig<any, any>, 'resolve' | 'type'>): (method: any, context: ClassMethodDecoratorContext) => any;
|
|
134
|
-
declare function EchoRequest(): (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => any;
|
|
135
|
-
declare function EchoRequest(options?: Omit<EchoConfig<any, any>, 'resolve' | 'type'>): (method: any, context: ClassMethodDecoratorContext) => any;
|
|
136
|
-
declare function getServiceEchoes(target: any): EchoesMap;
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* @deprecated Use createEchoRequest and createEchoEvent instead
|
|
140
|
-
*/
|
|
141
|
-
declare const echo: <TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType, TEchoType extends "event" | "request">(options: EchoConfig<TParamsSchema, TReturnsSchema, TEchoType>) => EchoType<TParamsSchema, TReturnsSchema, TEchoType>;
|
|
142
|
-
declare function createEchoRequest<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType>(options: EchoRequestConfig<TParamsSchema, TReturnsSchema>): EchoType<TParamsSchema, TReturnsSchema, 'request'>;
|
|
143
|
-
declare function createEchoEvent<TParamsSchema extends SchemaFieldType, TReturnsSchema extends SchemaFieldType>(options: EchoEventConfig<TParamsSchema, TReturnsSchema>): EchoType<TParamsSchema, TReturnsSchema, 'event'>;
|
|
144
|
-
|
|
145
|
-
export { type EchoConfig, EchoEvent, type EchoEventConfig, EchoRequest, type EchoRequestConfig, type EchoType, Echoes, type EchoesConfigHandler, type EchoesMap, type EchoesOptions, type EchoesPropertyDescriptor, type MakeRequestParams, type PublishOptions, type RequestHandlerResponse, type RequestMaker, type RequestMakerResult, type RequestOptions, type RequestsConfig, createEchoEvent, createEchoRequest, echo, getServiceEchoes, publish, request, startService, stopService };
|