@sera4/essentia 1.1.65 → 3.0.6
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 +352 -8
- package/dist/ts/cache/index.d.ts +33 -0
- package/dist/ts/cache/index.js +171 -0
- package/dist/ts/cache/index.js.map +1 -0
- package/dist/ts/configurations/server-config.d.ts +4 -0
- package/dist/ts/configurations/server-config.js +2 -0
- package/dist/ts/configurations/server-config.js.map +1 -0
- package/dist/ts/constants/index.d.ts +7 -0
- package/{constants → dist/ts/constants}/index.js +5 -6
- package/dist/ts/constants/index.js.map +1 -0
- package/dist/ts/cycle/index.d.ts +53 -0
- package/dist/ts/cycle/index.js +169 -0
- package/dist/ts/cycle/index.js.map +1 -0
- package/dist/ts/dns/DnsCache.d.ts +50 -0
- package/dist/ts/dns/DnsCache.js +137 -0
- package/dist/ts/dns/DnsCache.js.map +1 -0
- package/dist/ts/dns/index.d.ts +4 -0
- package/dist/ts/dns/index.js +4 -0
- package/dist/ts/dns/index.js.map +1 -0
- package/dist/ts/formatter/index.d.ts +44 -0
- package/dist/ts/formatter/index.js +76 -0
- package/dist/ts/formatter/index.js.map +1 -0
- package/dist/ts/hal/index.d.ts +26 -0
- package/dist/ts/hal/index.js +70 -0
- package/dist/ts/hal/index.js.map +1 -0
- package/dist/ts/health/index.d.ts +53 -0
- package/dist/ts/health/index.js +165 -0
- package/dist/ts/health/index.js.map +1 -0
- package/dist/ts/helpers/index.d.ts +1 -0
- package/dist/ts/helpers/index.js +2 -0
- package/dist/ts/helpers/index.js.map +1 -0
- package/dist/ts/helpers/test-server-wrapper.d.ts +56 -0
- package/dist/ts/helpers/test-server-wrapper.js +144 -0
- package/dist/ts/helpers/test-server-wrapper.js.map +1 -0
- package/dist/ts/index.d.ts +21 -0
- package/dist/ts/index.js +25 -0
- package/dist/ts/index.js.map +1 -0
- package/dist/ts/last-commit/index.d.ts +12 -0
- package/dist/ts/last-commit/index.js +82 -0
- package/dist/ts/last-commit/index.js.map +1 -0
- package/dist/ts/logger/index.d.ts +3 -0
- package/dist/ts/logger/index.js +4 -0
- package/dist/ts/logger/index.js.map +1 -0
- package/dist/ts/logger/s4-logger.d.ts +23 -0
- package/dist/ts/logger/s4-logger.js +103 -0
- package/dist/ts/logger/s4-logger.js.map +1 -0
- package/dist/ts/paginator/index.d.ts +2 -0
- package/dist/ts/paginator/index.js +3 -0
- package/dist/ts/paginator/index.js.map +1 -0
- package/dist/ts/paginator/s4-pagination.d.ts +26 -0
- package/dist/ts/paginator/s4-pagination.js +49 -0
- package/dist/ts/paginator/s4-pagination.js.map +1 -0
- package/dist/ts/paginator/sql-pagination.d.ts +52 -0
- package/dist/ts/paginator/sql-pagination.js +157 -0
- package/dist/ts/paginator/sql-pagination.js.map +1 -0
- package/dist/ts/paper-trail/helpers.d.ts +14 -0
- package/dist/ts/paper-trail/helpers.js +74 -0
- package/dist/ts/paper-trail/helpers.js.map +1 -0
- package/dist/ts/paper-trail/index.d.ts +54 -0
- package/dist/ts/paper-trail/index.js +236 -0
- package/dist/ts/paper-trail/index.js.map +1 -0
- package/dist/ts/prompts/index.d.ts +21 -0
- package/dist/ts/prompts/index.js +68 -0
- package/dist/ts/prompts/index.js.map +1 -0
- package/dist/ts/queue/index.d.ts +196 -0
- package/dist/ts/queue/index.js +371 -0
- package/dist/ts/queue/index.js.map +1 -0
- package/dist/ts/queue/publisher.d.ts +41 -0
- package/dist/ts/queue/publisher.js +84 -0
- package/dist/ts/queue/publisher.js.map +1 -0
- package/dist/ts/queue/queue-logger.d.ts +10 -0
- package/dist/ts/queue/queue-logger.js +35 -0
- package/dist/ts/queue/queue-logger.js.map +1 -0
- package/dist/ts/queue/subscriber.d.ts +55 -0
- package/dist/ts/queue/subscriber.js +98 -0
- package/dist/ts/queue/subscriber.js.map +1 -0
- package/dist/ts/safe-proxy/index.d.ts +35 -0
- package/dist/ts/safe-proxy/index.js +54 -0
- package/dist/ts/safe-proxy/index.js.map +1 -0
- package/dist/ts/serializer/index.d.ts +52 -0
- package/dist/ts/serializer/index.js +83 -0
- package/dist/ts/serializer/index.js.map +1 -0
- package/dist/ts/utils/index.d.ts +49 -0
- package/dist/ts/utils/index.js +157 -0
- package/dist/ts/utils/index.js.map +1 -0
- package/package.json +52 -11
- package/package.tar.gz +0 -0
- package/cache/index.js +0 -188
- package/formatter/index.js +0 -81
- package/hal/README.md +0 -54
- package/hal/index.js +0 -75
- package/health/health-logger.js +0 -40
- package/health/index.js +0 -188
- package/helpers/index.js +0 -1
- package/helpers/test-server-wrapper.js +0 -196
- package/last-commit.js +0 -12
- package/last_commit/index.js +0 -82
- package/logger/s4-logger.js +0 -128
- package/paginator/README.md +0 -183
- package/paginator/s4-pagination.js +0 -51
- package/paginator/sql-pagination.js +0 -178
- package/paper-trail/README.md +0 -68
- package/paper-trail/helpers.js +0 -99
- package/paper-trail/index.js +0 -842
- package/prompts/index.js +0 -78
- package/queue/index.js +0 -414
- package/queue/publisher.js +0 -96
- package/queue/queue-logger.js +0 -40
- package/queue/subscriber.js +0 -107
- package/safe_proxy/index.js +0 -61
- package/serializer/index.js +0 -90
- package/utils/index.js +0 -74
package/README.md
CHANGED
|
@@ -1,10 +1,354 @@
|
|
|
1
1
|
# ESSENTIA
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://hub.docker.com/)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
|
+
|
|
8
|
+
A comprehensive TypeScript library providing essential utilities for TWS services. Built with modern TypeScript practices and full type safety.
|
|
9
|
+
|
|
10
|
+
## Project Structure
|
|
11
|
+
|
|
12
|
+
All modules are written in TypeScript and located in the `/ts` directory:
|
|
13
|
+
|
|
14
|
+
- `/ts/logger` - S4Logger implementation with Winston integration
|
|
15
|
+
- `/ts/utils` - Utility functions (UUID validation, array conversion, etc.)
|
|
16
|
+
- `/ts/dns` - DNS caching functionality with configurable TTL
|
|
17
|
+
- `/ts/health` - Health check utilities for service monitoring
|
|
18
|
+
- `/ts/cycle` - Cycle deployment watcher for version tracking
|
|
19
|
+
- `/ts/constants` - Shared constants and configuration
|
|
20
|
+
- `/ts/helpers` - Helper functions and utilities
|
|
21
|
+
- `/ts/paginator` - Pagination utilities for SQL and data arrays
|
|
22
|
+
- `/ts/cache` - Redis cache helper with connection management
|
|
23
|
+
- `/ts/prompts` - CLI prompt utilities with argument parsing
|
|
24
|
+
- `/ts/safe-proxy` - Safe object property access with error handling
|
|
25
|
+
- `/ts/queue` - AMQP message queue management
|
|
26
|
+
- `/ts/last-commit` - Git commit information retrieval
|
|
27
|
+
- `/ts/hal` - HAL decorator for API responses
|
|
28
|
+
- `/ts/formatter` - Data formatting and error response utilities
|
|
29
|
+
- `/ts/serializer` - Sequelize model serialization utilities
|
|
30
|
+
- `/ts/paper-trail` - Data versioning and change tracking
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
Install the package:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @sera4/essentia
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Basic Usage
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import {
|
|
44
|
+
sqlPaginator,
|
|
45
|
+
paginator,
|
|
46
|
+
DnsCache,
|
|
47
|
+
S4Logger,
|
|
48
|
+
utils,
|
|
49
|
+
constants
|
|
50
|
+
} from '@sera4/essentia';
|
|
51
|
+
|
|
52
|
+
// Pagination
|
|
53
|
+
const result = sqlPaginator('SELECT * FROM users', { page: 1, limit: 10 });
|
|
54
|
+
const paginated = paginator(data, { page: 1, limit: 20 });
|
|
55
|
+
|
|
56
|
+
// DNS caching
|
|
57
|
+
const dnsCache = new DnsCache();
|
|
58
|
+
const ip = await dnsCache.resolveTarget('https://example.com');
|
|
59
|
+
|
|
60
|
+
// Logging
|
|
61
|
+
const logger = new S4Logger();
|
|
62
|
+
logger.configure({ level: 'debug', service: 'my-service' });
|
|
63
|
+
logger.info('Application started');
|
|
64
|
+
|
|
65
|
+
// Utilities
|
|
66
|
+
const isValidUuid = utils.isValidUuidV4('123e4567-e89b-12d3-a456-426614174000');
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Advanced Usage
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import {
|
|
73
|
+
sqlPaginator,
|
|
74
|
+
paginator,
|
|
75
|
+
DnsCache,
|
|
76
|
+
S4Logger,
|
|
77
|
+
HealthCheck,
|
|
78
|
+
CycleDeploymentWatcher,
|
|
79
|
+
halDecorator,
|
|
80
|
+
formatter,
|
|
81
|
+
queue,
|
|
82
|
+
paperTrail,
|
|
83
|
+
serializer,
|
|
84
|
+
lastCommit,
|
|
85
|
+
utils,
|
|
86
|
+
constants,
|
|
87
|
+
helpers,
|
|
88
|
+
prompts,
|
|
89
|
+
safeProxy
|
|
90
|
+
} from '@sera4/essentia';
|
|
91
|
+
|
|
92
|
+
// Pagination examples
|
|
93
|
+
const sqlResult = sqlPaginator('SELECT * FROM users WHERE active = ?', {
|
|
94
|
+
page: 1,
|
|
95
|
+
limit: 10,
|
|
96
|
+
orderBy: 'created_at',
|
|
97
|
+
orderDirection: 'DESC'
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const paginatedData = paginator(userList, {
|
|
101
|
+
page: 1,
|
|
102
|
+
limit: 20,
|
|
103
|
+
total: 100
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// DNS caching with configuration
|
|
107
|
+
const dnsCache = DnsCache.getInstance({
|
|
108
|
+
cacheTtlMs: 5000,
|
|
109
|
+
purgeIntervalMs: 120000,
|
|
110
|
+
debug: true
|
|
111
|
+
});
|
|
112
|
+
const ip = await dnsCache.resolveTarget('https://example.com');
|
|
113
|
+
|
|
114
|
+
// Logging with advanced configuration
|
|
115
|
+
const logger = new S4Logger();
|
|
116
|
+
logger.configure({
|
|
117
|
+
level: 'debug',
|
|
118
|
+
service: 'my-service',
|
|
119
|
+
format: 'json'
|
|
120
|
+
});
|
|
121
|
+
logger.info('Application started');
|
|
122
|
+
|
|
123
|
+
// Health checks
|
|
124
|
+
const healthCheck = new HealthCheck();
|
|
125
|
+
healthCheck.addCheck('database', async () => {
|
|
126
|
+
// Your database health check logic
|
|
127
|
+
return { status: 'healthy' };
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Cycle deployment monitoring
|
|
131
|
+
const watcher = CycleDeploymentWatcher.getInstance();
|
|
132
|
+
const currentVersion = watcher.getCurrentVersion('gateway');
|
|
133
|
+
|
|
134
|
+
// HAL decorator for API responses
|
|
135
|
+
const response = halDecorator(data, {
|
|
136
|
+
self: '/api/users',
|
|
137
|
+
next: '/api/users?page=2'
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Queue management
|
|
141
|
+
await queue.openConnection({
|
|
142
|
+
connectionUrl: 'amqp://localhost',
|
|
143
|
+
logEnabled: true
|
|
144
|
+
});
|
|
145
|
+
await queue.registerPublisher({
|
|
146
|
+
exchange: { name: 'my-exchange', type: 'topic' }
|
|
147
|
+
});
|
|
148
|
+
await queue.publishMessage('my-exchange', 'my-routing-key', { data: 'message' });
|
|
149
|
+
|
|
150
|
+
// Paper trail for data versioning
|
|
151
|
+
const trail = paperTrail(originalData, {
|
|
152
|
+
userId: 'user123',
|
|
153
|
+
action: 'update'
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Data serialization
|
|
157
|
+
const serialized = serializer(data, {
|
|
158
|
+
format: 'json',
|
|
159
|
+
pretty: true
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Last commit information
|
|
163
|
+
const commitInfo = await lastCommit.getLastCommit();
|
|
164
|
+
console.log(`Deployed version: ${commitInfo.hash}`);
|
|
165
|
+
|
|
166
|
+
// Utility functions
|
|
167
|
+
const safeData = safeProxy(data);
|
|
168
|
+
const helper = helpers.someHelperFunction();
|
|
169
|
+
const parser = prompts.setupCLIParser('My CLI Tool');
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Available Modules
|
|
173
|
+
|
|
174
|
+
All modules are written in TypeScript and provide full type safety:
|
|
175
|
+
|
|
176
|
+
### Core Modules
|
|
177
|
+
- **Logging**: `S4Logger` - Winston-based logging utility with multiple log levels and formatting options
|
|
178
|
+
- **DNS Cache**: `DnsCache` - Singleton class for caching DNS lookups with configurable TTL
|
|
179
|
+
- **Health Checks**: `HealthCheck` - Utilities for implementing health check endpoints
|
|
180
|
+
- **Cycle Deployment Watcher**: `CycleDeploymentWatcher` - Monitor and react to changes in Cycle deployment tags
|
|
181
|
+
- **Utils**: `utils` - General utility functions (UUID validation, array conversion, route type detection, JSONB helpers)
|
|
182
|
+
|
|
183
|
+
### Data Management
|
|
184
|
+
- **Pagination**: `sqlPaginator`, `paginator` - Utilities for handling pagination in SQL queries and data arrays
|
|
185
|
+
- **Cache**: `cache` - Redis cache helper with connection management and key generation
|
|
186
|
+
- **Serializer**: `serializer` - Sequelize model serialization utilities with custom decorators
|
|
187
|
+
- **Paper Trail**: `paperTrail` - Track changes to data models with automatic versioning and diff generation
|
|
188
|
+
|
|
189
|
+
### API & Communication
|
|
190
|
+
- **HAL Decorator**: `halDecorator` - Adds HAL (Hypertext Application Language) support to API responses
|
|
191
|
+
- **Formatter**: `formatter` - Data formatting utilities and error response formatting
|
|
192
|
+
- **Queue**: `queue` - AMQP message queue management with publishers and subscribers
|
|
193
|
+
- **Safe Proxy**: `safeProxy` - Safe object property access with error handling
|
|
194
|
+
|
|
195
|
+
### Utilities
|
|
196
|
+
- **Constants**: `constants` - Shared constants and configuration values
|
|
197
|
+
- **Helpers**: `helpers` - Helper functions and utilities
|
|
198
|
+
- **Prompts**: `prompts` - CLI prompt utilities with argument parsing
|
|
199
|
+
- **Last Commit**: `lastCommit` - Retrieve and display git commit information
|
|
200
|
+
|
|
201
|
+
### Cycle Deployment Watcher
|
|
202
|
+
|
|
203
|
+
The Cycle Deployment Watcher provides functionality to monitor and react to changes in Cycle deployment tags. It's particularly useful for tracking deployment tags in a Cycle environment.
|
|
204
|
+
|
|
205
|
+
#### Methods
|
|
206
|
+
|
|
207
|
+
- `getInstance()`: Returns the singleton instance of the watcher
|
|
208
|
+
- `getCurrentVersion(service: string)`: Returns the current version for a service
|
|
209
|
+
- `getLegacyVersion(service: string)`: Returns the legacy version for a service
|
|
210
|
+
- `getTagsForVersion(version: string)`: Returns all tags that match a specific version
|
|
211
|
+
- `addListener(listener: (tags: Record<string, string>) => void)`: Adds a listener for tag changes
|
|
212
|
+
- `destroy()`: Cleans up resources and removes all listeners
|
|
213
|
+
|
|
214
|
+
#### Environment Variables
|
|
215
|
+
|
|
216
|
+
- `CYCLE_DEPLOYMENT_VERSION`: Optional environment variable to specify the current deployment version
|
|
217
|
+
|
|
218
|
+
## TypeScript Support
|
|
219
|
+
|
|
220
|
+
This package is built entirely in TypeScript and provides:
|
|
221
|
+
|
|
222
|
+
- **Full Type Safety**: All modules include comprehensive TypeScript interfaces and type definitions
|
|
223
|
+
- **IntelliSense Support**: Complete autocomplete and IntelliSense in modern IDEs
|
|
224
|
+
- **Compile-time Error Checking**: Catch errors at compile time rather than runtime
|
|
225
|
+
- **Modern ES Modules**: Uses ES modules with proper import/export syntax
|
|
226
|
+
- **Declaration Files**: Generated `.d.ts` files for all modules
|
|
227
|
+
|
|
228
|
+
### Type Definitions
|
|
229
|
+
|
|
230
|
+
All modules export their TypeScript interfaces, allowing you to use them in your own code:
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import {
|
|
234
|
+
LoggerOptions,
|
|
235
|
+
DnsCacheConfig,
|
|
236
|
+
HealthCheckOptions,
|
|
237
|
+
PaginationOptions
|
|
238
|
+
} from '@sera4/essentia';
|
|
239
|
+
|
|
240
|
+
// Use the types in your own interfaces
|
|
241
|
+
interface MyServiceConfig {
|
|
242
|
+
logger: LoggerOptions;
|
|
243
|
+
dns: DnsCacheConfig;
|
|
244
|
+
health: HealthCheckOptions;
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Contributing
|
|
249
|
+
|
|
250
|
+
When contributing new features or fixes, please:
|
|
251
|
+
|
|
252
|
+
1. Use TypeScript for all new code
|
|
253
|
+
2. Follow the existing TypeScript patterns and conventions
|
|
254
|
+
3. Include appropriate type definitions and interfaces
|
|
255
|
+
4. Add unit tests for new functionality
|
|
256
|
+
5. Update this documentation as needed
|
|
257
|
+
6. Ensure all code passes the TypeScript compiler with strict mode enabled
|
|
258
|
+
|
|
259
|
+
## Running Tests
|
|
260
|
+
|
|
261
|
+
The project uses Mocha and Chai for testing. To run the tests:
|
|
262
|
+
|
|
263
|
+
1. Install dependencies:
|
|
264
|
+
```bash
|
|
265
|
+
npm install
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
2. Run all tests:
|
|
269
|
+
```bash
|
|
270
|
+
npm test
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
3. Run tests for a specific module:
|
|
274
|
+
```bash
|
|
275
|
+
npm test -- --grep "DnsCache"
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
4. Run tests with coverage:
|
|
279
|
+
```bash
|
|
280
|
+
npm run test:coverage
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
5. Run tests in watch mode (useful during development):
|
|
284
|
+
```bash
|
|
285
|
+
npm run test:watch
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Test Environment
|
|
289
|
+
|
|
290
|
+
The test environment is configured to:
|
|
291
|
+
- Use ES modules
|
|
292
|
+
- Support TypeScript
|
|
293
|
+
- Mock external dependencies
|
|
294
|
+
- Run tests in parallel
|
|
295
|
+
|
|
296
|
+
### Writing Tests
|
|
297
|
+
|
|
298
|
+
When writing new tests:
|
|
299
|
+
1. Place test files in the `test` directory, mirroring the source structure
|
|
300
|
+
2. Use `.test.ts` extension for TypeScript test files
|
|
301
|
+
3. Follow the existing test patterns and conventions
|
|
302
|
+
4. Use sinon for mocking and stubbing
|
|
303
|
+
5. Include both positive and negative test cases
|
|
304
|
+
6. Test edge cases and error conditions
|
|
305
|
+
|
|
306
|
+
Example test structure:
|
|
307
|
+
```typescript
|
|
308
|
+
import { expect } from 'chai';
|
|
309
|
+
import sinon from 'sinon';
|
|
310
|
+
import { MyModule } from '../../ts/my-module';
|
|
311
|
+
|
|
312
|
+
describe('MyModule', () => {
|
|
313
|
+
let myModule: MyModule;
|
|
314
|
+
let mockDependency: sinon.SinonStub;
|
|
315
|
+
|
|
316
|
+
beforeEach(() => {
|
|
317
|
+
myModule = new MyModule();
|
|
318
|
+
mockDependency = sinon.stub();
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
afterEach(() => {
|
|
322
|
+
sinon.restore();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
describe('someMethod', () => {
|
|
326
|
+
it('should do something', async () => {
|
|
327
|
+
mockDependency.resolves('expected result');
|
|
328
|
+
|
|
329
|
+
const result = await myModule.someMethod();
|
|
330
|
+
|
|
331
|
+
expect(result).to.equal('expected result');
|
|
332
|
+
expect(mockDependency.calledOnce).to.be.true;
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Building
|
|
339
|
+
|
|
340
|
+
To build the project:
|
|
341
|
+
|
|
342
|
+
```bash
|
|
343
|
+
npm run build
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
This will:
|
|
347
|
+
- Compile all TypeScript files to JavaScript
|
|
348
|
+
- Generate declaration files (`.d.ts`)
|
|
349
|
+
- Create source maps for debugging
|
|
350
|
+
- Output everything to the `dist/` directory
|
|
351
|
+
|
|
352
|
+
## License
|
|
353
|
+
|
|
354
|
+
This project is proprietary software. All rights reserved.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
interface CacheConfig {
|
|
2
|
+
password?: string;
|
|
3
|
+
database?: number;
|
|
4
|
+
host?: string;
|
|
5
|
+
port?: number;
|
|
6
|
+
fake?: boolean;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
declare class CacheConfigError extends Error {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
declare class Cache {
|
|
13
|
+
private redisClient;
|
|
14
|
+
private servicePrefix;
|
|
15
|
+
constructor(config: CacheConfig, servicePrefix: string);
|
|
16
|
+
ping(): Promise<string>;
|
|
17
|
+
properKey(key: string, path?: string): string;
|
|
18
|
+
writeHash(path: string, key: string, value: any): Promise<number>;
|
|
19
|
+
writeHashBlocking(path: string, key: string, value: any): void;
|
|
20
|
+
writeMultiHash(path: string, j: Record<string, any>): Promise<string>;
|
|
21
|
+
readHashKey(obj: string, key: string, autoConvert?: boolean): Promise<any>;
|
|
22
|
+
readHash(path: string): Promise<Record<string, any> | null>;
|
|
23
|
+
deleteHashKey(hash: string, key: string): Promise<void>;
|
|
24
|
+
get(key: string): Promise<string | null>;
|
|
25
|
+
getAsync(key: string): Promise<string | null>;
|
|
26
|
+
writeKey(key: string, value: any, expiry?: number): Promise<string>;
|
|
27
|
+
deleteKey(key: string): Promise<number>;
|
|
28
|
+
expire(path: string, expiry: number): Promise<number>;
|
|
29
|
+
exists(path: string): Promise<number>;
|
|
30
|
+
deleteAllKeys(): Promise<string>;
|
|
31
|
+
}
|
|
32
|
+
export default function (config: CacheConfig, servicePrefix: string): Cache;
|
|
33
|
+
export { Cache, CacheConfigError };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { promisify } from "util";
|
|
2
|
+
import { S4Logger } from "../logger/s4-logger.js";
|
|
3
|
+
const logger = new S4Logger();
|
|
4
|
+
const isEmpty = (obj) => {
|
|
5
|
+
return [Object, Array].includes((obj || {}).constructor) && !Object.entries((obj || {})).length;
|
|
6
|
+
};
|
|
7
|
+
class CacheConfigError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "CacheConfigError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/* Redis cache helper
|
|
14
|
+
* Example use: Place the following code in your project to setup redis use
|
|
15
|
+
*
|
|
16
|
+
* import { cache } from "@sera4/essentia";
|
|
17
|
+
* const cacheHelper = cache({ password: .., database: .., host: .., port: .. }, "service:"));
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
const convertRedisKeyValueToJson = (v) => {
|
|
21
|
+
return (v && v.length > 0 && v[0] !== null) ? JSON.parse(v) : null;
|
|
22
|
+
};
|
|
23
|
+
const convertRedisHashToJson = (v) => {
|
|
24
|
+
if (v) {
|
|
25
|
+
const result = {};
|
|
26
|
+
for (const k in v) {
|
|
27
|
+
if (v.hasOwnProperty(k)) {
|
|
28
|
+
result[k] = JSON.parse(v[k]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function convertJsonToRedisValue(j) {
|
|
38
|
+
const result = {};
|
|
39
|
+
for (const key in j) {
|
|
40
|
+
if (j.hasOwnProperty(key)) {
|
|
41
|
+
result[key] = JSON.stringify(j[key]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
class Cache {
|
|
47
|
+
constructor(config, servicePrefix) {
|
|
48
|
+
if ((config == undefined) || isEmpty(config)) {
|
|
49
|
+
throw new CacheConfigError("Invalid cache configuration");
|
|
50
|
+
}
|
|
51
|
+
if (servicePrefix == null) {
|
|
52
|
+
throw new CacheConfigError("Invalid service prefix");
|
|
53
|
+
}
|
|
54
|
+
if (config.fake) {
|
|
55
|
+
// used in testing
|
|
56
|
+
this.redisClient = require("fakeredis").createClient("fake backend");
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.redisClient = require("redis").createClient(config);
|
|
60
|
+
}
|
|
61
|
+
this.redisClient.on("error", (err) => {
|
|
62
|
+
logger.error("Cache/Redis error: ", err);
|
|
63
|
+
});
|
|
64
|
+
this.servicePrefix = servicePrefix;
|
|
65
|
+
}
|
|
66
|
+
ping() {
|
|
67
|
+
return this.redisClient.ping();
|
|
68
|
+
}
|
|
69
|
+
properKey(key, path) {
|
|
70
|
+
let p = this.servicePrefix + key;
|
|
71
|
+
if (path) {
|
|
72
|
+
p += path;
|
|
73
|
+
}
|
|
74
|
+
return p;
|
|
75
|
+
}
|
|
76
|
+
writeHash(path, key, value) {
|
|
77
|
+
return this.redisClient.hsetAsync(this.properKey(key), key, value);
|
|
78
|
+
}
|
|
79
|
+
writeHashBlocking(path, key, value) {
|
|
80
|
+
return this.redisClient.hset(this.properKey(key), key, value);
|
|
81
|
+
}
|
|
82
|
+
// write multiple hash keys and stringify every value
|
|
83
|
+
writeMultiHash(path, j) {
|
|
84
|
+
return this.redisClient.hmsetAsync(this.properKey(path), convertJsonToRedisValue(j));
|
|
85
|
+
}
|
|
86
|
+
readHashKey(obj, key, autoConvert = true) {
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
this.redisClient.hget(this.properKey(key, obj), key, (e, r) => {
|
|
89
|
+
if (e) {
|
|
90
|
+
logger.error("Redis hmget error:", e);
|
|
91
|
+
reject(e);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
resolve(autoConvert ? convertRedisKeyValueToJson(r) : r);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
readHash(path) {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
this.redisClient.hgetall(this.properKey(path), (e, r) => {
|
|
102
|
+
if (e) {
|
|
103
|
+
console.log("Redis hget error:", e);
|
|
104
|
+
reject(e);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
resolve(convertRedisHashToJson(r));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
deleteHashKey(hash, key) {
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
this.redisClient.hdel(this.properKey(key, hash), key, (err) => {
|
|
115
|
+
if (err) {
|
|
116
|
+
logger.error("Redis hdel error:", err);
|
|
117
|
+
reject(err);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
resolve();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
get(key) {
|
|
126
|
+
return this.redisClient.getAsync(this.properKey(key));
|
|
127
|
+
}
|
|
128
|
+
getAsync(key) {
|
|
129
|
+
return promisify(this.redisClient.get.bind(this.redisClient))(this.properKey(key));
|
|
130
|
+
}
|
|
131
|
+
/* a single key write with optional expiry */
|
|
132
|
+
// returns bluebird promise
|
|
133
|
+
writeKey(key, value, expiry) {
|
|
134
|
+
const fullKey = this.servicePrefix + key;
|
|
135
|
+
if (expiry) {
|
|
136
|
+
return this.redisClient.setAsync(fullKey, value, "EX", expiry);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return this.redisClient.setAsync(fullKey, value);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
deleteKey(key) {
|
|
143
|
+
return this.redisClient.delAsync(this.properKey(key));
|
|
144
|
+
}
|
|
145
|
+
expire(path, expiry) {
|
|
146
|
+
return this.redisClient.expire(path, expiry);
|
|
147
|
+
}
|
|
148
|
+
exists(path) {
|
|
149
|
+
return this.redisClient.exists(path);
|
|
150
|
+
}
|
|
151
|
+
deleteAllKeys() {
|
|
152
|
+
return new Promise((resolve, reject) => {
|
|
153
|
+
if (process.env.NODE_ENV === "production") {
|
|
154
|
+
throw new Error("Clearing system cache is not permitted in production");
|
|
155
|
+
}
|
|
156
|
+
this.redisClient.flushdb((err, res) => {
|
|
157
|
+
if (err) {
|
|
158
|
+
reject(err);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
resolve(res);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export default function (config, servicePrefix) {
|
|
168
|
+
return new Cache(config, servicePrefix);
|
|
169
|
+
}
|
|
170
|
+
export { Cache, CacheConfigError };
|
|
171
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;AAW9B,MAAM,OAAO,GAAG,CAAC,GAAQ,EAAW,EAAE;IACpC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAClG,CAAC,CAAC;AAEF,MAAM,gBAAiB,SAAQ,KAAK;IAClC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED;;;;;;GAMG;AAEH,MAAM,0BAA0B,GAAG,CAAC,CAAM,EAAO,EAAE;IACjD,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACrE,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,CAA6B,EAA8B,EAAE;IAC3F,IAAI,CAAC,EAAE,CAAC;QACN,MAAM,MA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AAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,aAAa;QACX,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;gBAC1C,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;YAC1E,CAAC;YACD,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,GAAW,EAAE,EAAE;gBACjD,IAAI,GAAG,EAAE,CAAC;oBACR,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,GAAG,CAAC,CAAC;gBACf,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,CAAC,OAAO,WAAU,MAAmB,EAAE,aAAqB;IAChE,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAC1C,CAAC;AAED,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-config.js","sourceRoot":"","sources":["../../../ts/configurations/server-config.ts"],"names":[],"mappings":""}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
1
|
// indicate what target URL was used for a request
|
|
4
2
|
export const TWS_ROUTE_TYPES = Object.freeze({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
'web': 1,
|
|
4
|
+
'mobile': 2,
|
|
5
|
+
'api': 3,
|
|
6
|
+
'other': 4
|
|
9
7
|
});
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/constants/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,KAAK,EAAE,CAAC;IACR,QAAQ,EAAE,CAAC;IACX,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare class CycleDeploymentWatcher {
|
|
2
|
+
private static instance;
|
|
3
|
+
private readonly metadataPath;
|
|
4
|
+
private watcher;
|
|
5
|
+
private currentTags;
|
|
6
|
+
private listeners;
|
|
7
|
+
private readonly deploymentVersion;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(): CycleDeploymentWatcher;
|
|
10
|
+
private initializeWatcher;
|
|
11
|
+
private readAndParseFile;
|
|
12
|
+
private notifyListeners;
|
|
13
|
+
/**
|
|
14
|
+
* Get all tags for a specific deployment version
|
|
15
|
+
* @param version - The deployment version to find tags for (e.g., 'gwy-20250505-UTC18:54:32')
|
|
16
|
+
* @returns Array of tag names that match the version
|
|
17
|
+
*/
|
|
18
|
+
getTagsForVersion(version: string): string[];
|
|
19
|
+
/**
|
|
20
|
+
* Get the current version for a specific service
|
|
21
|
+
* @param service - The service name (e.g., 'gateway', 'apm', etc.)
|
|
22
|
+
* @returns The current version or undefined if not found
|
|
23
|
+
*/
|
|
24
|
+
getCurrentVersion(service: string): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Get the legacy version for a specific service
|
|
27
|
+
* @param service - The service name (e.g., 'gateway', 'apm', etc.)
|
|
28
|
+
* @returns The legacy version or undefined if not found
|
|
29
|
+
*/
|
|
30
|
+
getLegacyVersion(service: string): string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get the current deployment version
|
|
33
|
+
* @returns The current deployment version from environment, or empty string if not available
|
|
34
|
+
*/
|
|
35
|
+
getDeploymentVersion(): string;
|
|
36
|
+
/**
|
|
37
|
+
* Get all tags for the current deployment version
|
|
38
|
+
* @returns Array of tag names that match the current deployment version
|
|
39
|
+
*/
|
|
40
|
+
getCurrentDeploymentTags(): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Add a listener for tag changes
|
|
43
|
+
* @param listener - Function to call when tags change
|
|
44
|
+
* @returns Function to remove the listener
|
|
45
|
+
*/
|
|
46
|
+
addListener(listener: (tags: Record<string, string>) => void): () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Clean up resources
|
|
49
|
+
*/
|
|
50
|
+
destroy(): void;
|
|
51
|
+
}
|
|
52
|
+
declare const _default: CycleDeploymentWatcher;
|
|
53
|
+
export default _default;
|