@lad-tech/nsc-toolkit 1.28.2 → 1.28.3
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/dist/Client.js +303 -0
- package/dist/Container.js +124 -0
- package/dist/Meter.js +77 -0
- package/dist/Method.js +7 -0
- package/dist/Root.js +120 -0
- package/dist/Service.js +677 -0
- package/dist/StreamBatchMsgFetcher.js +17 -0
- package/dist/StreamManager.js +173 -0
- package/dist/StreamOptions/BufferToJsonTransform.js +34 -0
- package/dist/StreamOptions/JsonToBufferTransform.js +11 -0
- package/dist/StreamOptions/index.js +19 -0
- package/dist/StreamSingleMsgFetcher.js +28 -0
- package/dist/Union/Broker.js +95 -0
- package/dist/Union/ConsumerApi.js +28 -0
- package/dist/Union/JetStreamClient.js +40 -0
- package/dist/Union/JetStreamManager.js +26 -0
- package/dist/Union/StreamApi.js +46 -0
- package/dist/Union/Subscription.js +47 -0
- package/dist/Union/index.js +18 -0
- package/dist/index.js +24 -0
- package/dist/injector.js +65 -0
- package/dist/interfaces.js +16 -0
- package/dist/types/Client.d.ts +32 -0
- package/dist/types/Container.d.ts +54 -0
- package/dist/types/Meter.d.ts +13 -0
- package/dist/types/Method.d.ts +6 -0
- package/dist/types/Root.d.ts +29 -0
- package/dist/types/Service.d.ts +140 -0
- package/dist/types/StreamBatchMsgFetcher.d.ts +13 -0
- package/dist/types/StreamManager.d.ts +26 -0
- package/dist/types/StreamOptions/BufferToJsonTransform.d.ts +14 -0
- package/dist/types/StreamOptions/JsonToBufferTransform.d.ts +6 -0
- package/dist/types/StreamOptions/index.d.ts +2 -0
- package/dist/types/StreamSingleMsgFetcher.d.ts +16 -0
- package/dist/types/Union/Broker.d.ts +32 -0
- package/dist/types/Union/ConsumerApi.d.ts +16 -0
- package/dist/types/Union/JetStreamClient.d.ts +18 -0
- package/dist/types/Union/JetStreamManager.d.ts +12 -0
- package/dist/types/Union/StreamApi.d.ts +16 -0
- package/dist/types/Union/Subscription.d.ts +19 -0
- package/dist/types/Union/index.d.ts +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/injector.d.ts +14 -0
- package/dist/types/interfaces.d.ts +181 -0
- package/package.json +1 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { Logs } from '@lad-tech/toolbelt';
|
|
2
|
+
import type { NatsConnection } from 'nats';
|
|
3
|
+
import type { Client } from './Client';
|
|
4
|
+
export interface MethodOptions {
|
|
5
|
+
useStream?: {
|
|
6
|
+
request?: boolean;
|
|
7
|
+
response?: boolean;
|
|
8
|
+
};
|
|
9
|
+
cache?: number;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
runTimeValidation?: {
|
|
12
|
+
request?: boolean;
|
|
13
|
+
response?: boolean;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface MethodSettings {
|
|
17
|
+
action: string;
|
|
18
|
+
options?: MethodOptions;
|
|
19
|
+
request?: Record<string, unknown>;
|
|
20
|
+
response?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export interface Method {
|
|
23
|
+
settings: MethodSettings;
|
|
24
|
+
new (...args: any[]): {
|
|
25
|
+
handler: (params: any) => Promise<any>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export type ClientService<C = Client> = new (natsConnection: NatsConnection, baggage?: Baggage, cache?: CacheSettings, loggerOutputFormatter?: Logs.OutputFormatter) => C;
|
|
29
|
+
export type Baggage = {
|
|
30
|
+
traceId: string;
|
|
31
|
+
spanId: string;
|
|
32
|
+
traceFlags: number;
|
|
33
|
+
requestId?: string;
|
|
34
|
+
expired?: number;
|
|
35
|
+
};
|
|
36
|
+
export type ExternalBaggage = {
|
|
37
|
+
'nsc-expired'?: number;
|
|
38
|
+
'nsc-trace-id'?: string;
|
|
39
|
+
'nsc-span-id'?: string;
|
|
40
|
+
'nsc-trace-flags'?: number;
|
|
41
|
+
'x-request-id'?: string;
|
|
42
|
+
};
|
|
43
|
+
export interface Message<M = any> {
|
|
44
|
+
payload: M;
|
|
45
|
+
baggage?: Baggage;
|
|
46
|
+
error?: {
|
|
47
|
+
message: string;
|
|
48
|
+
code?: number;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export type Emitter = Record<string, (params: any) => void>;
|
|
52
|
+
export interface CacheSettings {
|
|
53
|
+
service: CacheService;
|
|
54
|
+
timeout: number;
|
|
55
|
+
}
|
|
56
|
+
export interface GracefulShutdownAdditionalService {
|
|
57
|
+
close: () => Promise<any>;
|
|
58
|
+
}
|
|
59
|
+
export interface ClientParam<E extends Emitter = Emitter> {
|
|
60
|
+
broker: NatsConnection;
|
|
61
|
+
serviceName: string;
|
|
62
|
+
baggage?: Baggage;
|
|
63
|
+
cache?: CacheSettings;
|
|
64
|
+
loggerOutputFormatter?: Logs.OutputFormatter;
|
|
65
|
+
events?: Events<E>;
|
|
66
|
+
Ref?: object;
|
|
67
|
+
}
|
|
68
|
+
export interface GetListenerOptions {
|
|
69
|
+
queue?: string;
|
|
70
|
+
deliver?: 'all' | 'new';
|
|
71
|
+
maxPending?: number;
|
|
72
|
+
maxAckWaiting?: number;
|
|
73
|
+
}
|
|
74
|
+
export interface GetBatchListenerOptions extends GetListenerOptions {
|
|
75
|
+
batch: true;
|
|
76
|
+
maxPullRequestBatch?: number;
|
|
77
|
+
maxPullRequestExpires?: number;
|
|
78
|
+
ackPolicy?: 'all' | 'none';
|
|
79
|
+
}
|
|
80
|
+
export interface StreamManagerParam {
|
|
81
|
+
serviceName: string;
|
|
82
|
+
options: StreamOptions;
|
|
83
|
+
broker: NatsConnection;
|
|
84
|
+
outputFormatter?: Logs.OutputFormatter;
|
|
85
|
+
}
|
|
86
|
+
export interface EmitterEvent<D extends Record<string, any>> {
|
|
87
|
+
data: D;
|
|
88
|
+
meter: EventMeter;
|
|
89
|
+
}
|
|
90
|
+
export interface EmitterStreamEvent<D extends Record<string, any>> extends EmitterEvent<D> {
|
|
91
|
+
ack: () => void;
|
|
92
|
+
nak: (millis: number) => void;
|
|
93
|
+
meter: EventMeter;
|
|
94
|
+
}
|
|
95
|
+
export interface StreamAction {
|
|
96
|
+
action: string;
|
|
97
|
+
storage?: 'file' | 'memory' | string;
|
|
98
|
+
retentionPolicy?: 'limits' | 'interest' | 'workQueue' | string;
|
|
99
|
+
discardPolicy?: 'old' | 'new' | string;
|
|
100
|
+
messageTTL?: number;
|
|
101
|
+
maxBytes?: number;
|
|
102
|
+
duplicateTrackingTime?: number;
|
|
103
|
+
replication?: number;
|
|
104
|
+
rollUps?: boolean;
|
|
105
|
+
}
|
|
106
|
+
export interface StreamOptions {
|
|
107
|
+
prefix: string;
|
|
108
|
+
actions: StreamAction[];
|
|
109
|
+
}
|
|
110
|
+
export interface Event {
|
|
111
|
+
action: string;
|
|
112
|
+
options?: {
|
|
113
|
+
stream?: boolean;
|
|
114
|
+
};
|
|
115
|
+
description: string;
|
|
116
|
+
event: Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
export interface Events<E extends Emitter> {
|
|
119
|
+
list: Record<keyof E, Event>;
|
|
120
|
+
streamOptions: StreamOptions;
|
|
121
|
+
}
|
|
122
|
+
export interface ServiceOptions<E extends Emitter> {
|
|
123
|
+
name: string;
|
|
124
|
+
brokerConnection?: NatsConnection;
|
|
125
|
+
methods: Method[];
|
|
126
|
+
events?: Events<E>;
|
|
127
|
+
cache?: CacheSettings;
|
|
128
|
+
loggerOutputFormatter?: Logs.OutputFormatter;
|
|
129
|
+
gracefulShutdown?: {
|
|
130
|
+
additional?: GracefulShutdownAdditionalService[];
|
|
131
|
+
timeout?: number;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export type EventStreamHandler<P extends Record<string, any>> = (params: EmitterStreamEvent<P>) => void;
|
|
135
|
+
export type EventHandler<P extends Record<string, any>> = (params: EmitterEvent<P>) => void;
|
|
136
|
+
export interface Listener<E extends Emitter> {
|
|
137
|
+
on<A extends keyof E>(action: A, handler: E[A]): void;
|
|
138
|
+
off<A extends keyof E>(action: A, handler: E[A]): void;
|
|
139
|
+
}
|
|
140
|
+
export interface ListenerBatch<E extends Emitter> {
|
|
141
|
+
on<A extends keyof E>(action: A, handler: (params: Array<Parameters<E[A]>[0]>, meter: EventMeter) => void): void;
|
|
142
|
+
off<A extends keyof E>(action: A, handler: (params: Array<Parameters<E[A]>[0]>, ...args: any[]) => void): void;
|
|
143
|
+
}
|
|
144
|
+
export interface HttpSettings {
|
|
145
|
+
ip?: string;
|
|
146
|
+
port?: number;
|
|
147
|
+
}
|
|
148
|
+
export interface CacheService {
|
|
149
|
+
set: (key: string, value: string, expired?: number) => Promise<void>;
|
|
150
|
+
get: (key: string) => Promise<string | undefined>;
|
|
151
|
+
delete: (key: string) => Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
export type InitializableService = GracefulShutdownAdditionalService & {
|
|
154
|
+
init: () => Promise<any>;
|
|
155
|
+
};
|
|
156
|
+
export type DependencyType = typeof DependencyType[keyof typeof DependencyType];
|
|
157
|
+
export declare const DependencyType: {
|
|
158
|
+
readonly SERVICE: "service";
|
|
159
|
+
readonly ADAPTER: "adapter";
|
|
160
|
+
readonly CONSTANT: "constant";
|
|
161
|
+
};
|
|
162
|
+
export type TagKey = typeof TagKey[keyof typeof TagKey];
|
|
163
|
+
export declare const TagKey: {
|
|
164
|
+
readonly LOCATION: "location";
|
|
165
|
+
readonly TYPE: "type";
|
|
166
|
+
readonly NAME: "name";
|
|
167
|
+
readonly TARGET: "target";
|
|
168
|
+
};
|
|
169
|
+
export type LocationTagValue = 'internal' | 'external';
|
|
170
|
+
export type TypeTagValue = 'dbms' | 'api';
|
|
171
|
+
export type Tag = {
|
|
172
|
+
[TagKey.LOCATION]: LocationTagValue;
|
|
173
|
+
[TagKey.TYPE]: TypeTagValue;
|
|
174
|
+
[TagKey.NAME]: string;
|
|
175
|
+
[TagKey.TARGET]?: string;
|
|
176
|
+
};
|
|
177
|
+
export interface EventMeter {
|
|
178
|
+
start(): void;
|
|
179
|
+
end(): void;
|
|
180
|
+
measure<T extends (...args: any[]) => any>(func: T, arg: Parameters<T>, context: any, tag?: Tag): ReturnType<T>;
|
|
181
|
+
}
|