ts-server-lib 0.0.17
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 +1 -0
- package/README.md +8 -0
- package/db/TSMongo.d.ts +103 -0
- package/db/TSMongo.js +483 -0
- package/db/TSRQW.d.ts +271 -0
- package/db/TSRQW.js +699 -0
- package/db/TSRedis.d.ts +174 -0
- package/db/TSRedis.js +602 -0
- package/package.json +85 -0
- package/ussd/TSUssdMenu.d.ts +139 -0
- package/ussd/TSUssdMenu.js +364 -0
- package/ussd/TSUssdScreen.d.ts +58 -0
- package/ussd/TSUssdScreen.js +218 -0
- package/ussd/index.d.ts +3 -0
- package/ussd/index.js +19 -0
- package/ussd/providers/AfricasTalking.d.ts +3 -0
- package/ussd/providers/AfricasTalking.js +17 -0
- package/ussd/providers/AirtelDRC.d.ts +9 -0
- package/ussd/providers/AirtelDRC.js +31 -0
- package/ussd/providers/OrangeDRC.d.ts +5 -0
- package/ussd/providers/OrangeDRC.js +213 -0
- package/ussd/providers/VodacomDRC.d.ts +9 -0
- package/ussd/providers/VodacomDRC.js +48 -0
- package/ussd/providers/_.d.ts +55 -0
- package/ussd/providers/_.js +83 -0
- package/ussd/providers/index.d.ts +13 -0
- package/ussd/providers/index.js +56 -0
- package/utils/TSFile.d.ts +36 -0
- package/utils/TSFile.js +244 -0
- package/utils/TSHash.d.ts +20 -0
- package/utils/TSHash.js +75 -0
- package/utils/TSRequest.d.ts +39 -0
- package/utils/TSRequest.js +256 -0
- package/utils/TSStub.d.ts +159 -0
- package/utils/TSStub.js +296 -0
- package/utils/abort.d.ts +18 -0
- package/utils/abort.js +97 -0
- package/utils/mime.json +11358 -0
package/db/TSRedis.d.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TSRedis – Single file for Redis: connection (standalone/Sentinel), events (pub/sub), operations.
|
|
3
|
+
*/
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
import { type RedisClientType, type RedisClusterType, type RedisSentinelType } from 'redis';
|
|
6
|
+
export type TSRedisClient = RedisClientType | RedisClusterType | RedisSentinelType;
|
|
7
|
+
export type TSRedisPattern = {
|
|
8
|
+
match?: string;
|
|
9
|
+
text?: string;
|
|
10
|
+
} | string;
|
|
11
|
+
export type TSRedisScan = {
|
|
12
|
+
pattern?: TSRedisPattern;
|
|
13
|
+
COUNT?: number;
|
|
14
|
+
};
|
|
15
|
+
export type TSRedisCallback = (data: unknown, k?: string) => unknown;
|
|
16
|
+
export interface RedisSentinelConfig {
|
|
17
|
+
hosts: Array<{
|
|
18
|
+
host: string;
|
|
19
|
+
port: number;
|
|
20
|
+
}>;
|
|
21
|
+
name: string;
|
|
22
|
+
password?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface RedisReplicaConfig {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
urls?: string[];
|
|
27
|
+
strategy?: 'round-robin' | 'random' | 'first-available';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Redis Cluster connection config. When set on `RedisConfig`, `TSRedis.connect()` creates
|
|
31
|
+
* a `createCluster()` client instead of `createClient()` and stores it as the active client.
|
|
32
|
+
*
|
|
33
|
+
* Multi-key constraints: commands that touch >1 key (`mGet`, `mSet`, `multi().chain`, custom
|
|
34
|
+
* Lua) require all keys to hash to the same slot. Use {tag} hash tags
|
|
35
|
+
* (e.g. `wallet:{tenantId:userId}:bal`) so co-located keys land on the same node.
|
|
36
|
+
*
|
|
37
|
+
* Caveat for queue consumers: TSRQW is built for the standalone client API. In cluster
|
|
38
|
+
* deployments, pass a standalone client to TSRQW (or a dedicated connection to one node)
|
|
39
|
+
* — see TSRedis.md §"Tuning and deployment".
|
|
40
|
+
*/
|
|
41
|
+
export interface RedisClusterConfig {
|
|
42
|
+
/** Seed nodes — node-redis discovers the rest via CLUSTER SLOTS after connect. */
|
|
43
|
+
nodes: Array<{
|
|
44
|
+
host: string;
|
|
45
|
+
port: number;
|
|
46
|
+
}>;
|
|
47
|
+
/** When true, route read-only commands (GET, MGET, …) to replicas. Default false (read from masters). */
|
|
48
|
+
useReplicas?: boolean;
|
|
49
|
+
/** Cluster-wide password (most clusters share one). */
|
|
50
|
+
password?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Optional remap of cluster-announced addresses. Cluster nodes typically announce docker
|
|
53
|
+
* hostnames (e.g. `ms-redis-3`) which aren't resolvable from a host-machine validator;
|
|
54
|
+
* supply this map to rewrite each discovered address to a client-reachable one
|
|
55
|
+
* (e.g. `127.0.0.1:7003`). Form: object map keyed by `host:port`, OR a function returning
|
|
56
|
+
* `{ host, port }` per discovered address string.
|
|
57
|
+
*/
|
|
58
|
+
nodeAddressMap?: Record<string, {
|
|
59
|
+
host: string;
|
|
60
|
+
port: number;
|
|
61
|
+
}> | ((address: string) => {
|
|
62
|
+
host: string;
|
|
63
|
+
port: number;
|
|
64
|
+
} | undefined);
|
|
65
|
+
}
|
|
66
|
+
export interface RedisConfig {
|
|
67
|
+
url: string;
|
|
68
|
+
connectTimeout?: number;
|
|
69
|
+
socketTimeout?: number;
|
|
70
|
+
autoReconnect?: boolean;
|
|
71
|
+
maxReconnectRetries?: number;
|
|
72
|
+
reconnectDelay?: number;
|
|
73
|
+
clientName?: string;
|
|
74
|
+
pingInterval?: number;
|
|
75
|
+
commandsQueueMaxLength?: number;
|
|
76
|
+
disableOfflineQueue?: boolean;
|
|
77
|
+
sentinel?: RedisSentinelConfig;
|
|
78
|
+
/**
|
|
79
|
+
* Redis Cluster mode. Mutually exclusive with `sentinel` and `readReplicas` (the cluster
|
|
80
|
+
* client handles replica routing internally via `useReplicas`).
|
|
81
|
+
* When set, `TSRedis.connect()` creates a cluster client; `TSRedis.getCluster()` returns it.
|
|
82
|
+
* `TSRedis.getClient()` returns null in cluster mode (singleton client variable stays null);
|
|
83
|
+
* callers needing the cluster client should use `TSRedis.getCluster()` or `TSRedis.getActiveClient()`.
|
|
84
|
+
*/
|
|
85
|
+
cluster?: RedisClusterConfig;
|
|
86
|
+
readReplicas?: RedisReplicaConfig;
|
|
87
|
+
}
|
|
88
|
+
export interface ScanOptions {
|
|
89
|
+
pattern?: string;
|
|
90
|
+
count?: number;
|
|
91
|
+
maxKeys?: number;
|
|
92
|
+
batchSize?: number;
|
|
93
|
+
}
|
|
94
|
+
export interface RedisConnectionStats {
|
|
95
|
+
connected: boolean;
|
|
96
|
+
mode: 'standalone' | 'sentinel' | 'cluster';
|
|
97
|
+
hasReadReplica: boolean;
|
|
98
|
+
master: {
|
|
99
|
+
connected: boolean;
|
|
100
|
+
};
|
|
101
|
+
replica: {
|
|
102
|
+
connected: boolean;
|
|
103
|
+
count: number;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
declare function connectRedisImpl(urlOrConfig: string | RedisConfig): Promise<RedisClientType>;
|
|
107
|
+
declare function getRedisImpl(): RedisClientType | null;
|
|
108
|
+
/**
|
|
109
|
+
/** Returns the active cluster client when `connectRedisImpl` was called with `config.cluster`, else null. */
|
|
110
|
+
declare function getRedisClusterImpl(): RedisClusterType | null;
|
|
111
|
+
/**
|
|
112
|
+
* Returns whichever client backs the active singleton: standalone, sentinel, or cluster.
|
|
113
|
+
* Use this when the code path is topology-agnostic (e.g. health checks, GET/SET on a single key).
|
|
114
|
+
* For multi-key ops you still need to know cluster mode to enforce hash-tag co-location.
|
|
115
|
+
*/
|
|
116
|
+
declare function getActiveClientImpl(): TSRedisClient | null;
|
|
117
|
+
declare function getRedisForReadImpl(): RedisClientType | null;
|
|
118
|
+
declare function hasReadReplicaImpl(): boolean;
|
|
119
|
+
declare function checkRedisHealthImpl(): Promise<{
|
|
120
|
+
healthy: boolean;
|
|
121
|
+
latencyMs: number;
|
|
122
|
+
}>;
|
|
123
|
+
declare function publishImpl(channel: string, message: string): Promise<boolean>;
|
|
124
|
+
declare function subscribeImpl(channel: string, handler: (message: string) => void): Promise<() => Promise<void>>;
|
|
125
|
+
declare function scanKeysIteratorImpl(options?: ScanOptions): AsyncGenerator<string, void, unknown>;
|
|
126
|
+
declare function batchGetValuesImpl(keys: string[]): Promise<Record<string, string | null>>;
|
|
127
|
+
declare function closeRedisImpl(): Promise<void>;
|
|
128
|
+
declare function getRedisConnectionStatsImpl(): RedisConnectionStats;
|
|
129
|
+
export declare class TSRedis extends EventEmitter {
|
|
130
|
+
redis: TSRedisClient;
|
|
131
|
+
constructor(instance: TSRedisClient);
|
|
132
|
+
/** Connect (standalone, Sentinel, Cluster, or with read replicas). Cluster is selected
|
|
133
|
+
* when the supplied `RedisConfig.cluster` is set; otherwise sentinel / standalone per
|
|
134
|
+
* the existing precedence rules. */
|
|
135
|
+
static connect: typeof connectRedisImpl;
|
|
136
|
+
/** Standalone / sentinel client singleton. Returns null in cluster mode — use {@link getCluster}. */
|
|
137
|
+
static getClient: typeof getRedisImpl;
|
|
138
|
+
/** Active cluster client. Returns null when not in cluster mode. */
|
|
139
|
+
static getCluster: typeof getRedisClusterImpl;
|
|
140
|
+
/** Topology-agnostic accessor — returns the active client (standalone / sentinel / cluster). */
|
|
141
|
+
static getActiveClient: typeof getActiveClientImpl;
|
|
142
|
+
static getClientForRead: typeof getRedisForReadImpl;
|
|
143
|
+
static hasReadReplica: typeof hasReadReplicaImpl;
|
|
144
|
+
static close: typeof closeRedisImpl;
|
|
145
|
+
static checkHealth: typeof checkRedisHealthImpl;
|
|
146
|
+
static getConnectionStats: typeof getRedisConnectionStatsImpl;
|
|
147
|
+
static publish: typeof publishImpl;
|
|
148
|
+
static subscribe: typeof subscribeImpl;
|
|
149
|
+
static scanKeysIterator: typeof scanKeysIteratorImpl;
|
|
150
|
+
static batchGetValues: typeof batchGetValuesImpl;
|
|
151
|
+
cachedRequest(options: Record<string, unknown>, defaultValue?: unknown, debug?: unknown): Promise<any>;
|
|
152
|
+
pathToStore(keys: string[] | undefined, object: unknown): unknown;
|
|
153
|
+
cached: (path: string, options?: {
|
|
154
|
+
value?: string;
|
|
155
|
+
expire?: number;
|
|
156
|
+
}) => Promise<string | undefined>;
|
|
157
|
+
load: (entity: string) => Promise<unknown[]>;
|
|
158
|
+
get: (key: string, cb?: (r: string | null) => unknown) => Promise<unknown>;
|
|
159
|
+
set: (key: string, data: unknown) => Promise<boolean>;
|
|
160
|
+
hget: (key: string, field: string) => Promise<any>;
|
|
161
|
+
getM: (entity: string, keys: string[]) => Promise<(string | null)[]>;
|
|
162
|
+
hgetall: (key: string, cb?: (r: Record<string, string>) => unknown) => Promise<unknown>;
|
|
163
|
+
hset: (key: string, field: string, data: unknown) => Promise<boolean>;
|
|
164
|
+
hdel: (key: string, fields: string[] | string) => Promise<boolean>;
|
|
165
|
+
del: (keys: string[] | string) => Promise<boolean>;
|
|
166
|
+
readonly loadLists: (pattern?: TSRedisPattern) => Promise<Record<string, Record<string, string>>>;
|
|
167
|
+
readonly hscanr: (entity: string, { pattern, COUNT }: TSRedisScan, cb?: TSRedisCallback) => Promise<Record<string, unknown>>;
|
|
168
|
+
readonly zscanr: (entity: string, { pattern, COUNT }: TSRedisScan, cb?: TSRedisCallback) => Promise<unknown[]>;
|
|
169
|
+
readonly scanr: ({ pattern, COUNT }: TSRedisScan, cb?: TSRedisCallback) => Promise<string[]>;
|
|
170
|
+
private static readonly _regexCache;
|
|
171
|
+
private check;
|
|
172
|
+
private match;
|
|
173
|
+
}
|
|
174
|
+
export {};
|