Skip to content

Commit be753e2

Browse files
committed
style: apply Prettier formatting to entire codebase
- Format all TypeScript, JavaScript, JSON, and Markdown files - Make Prettier check blocking in CI (no longer continue-on-error)
1 parent c4c941a commit be753e2

31 files changed

Lines changed: 1038 additions & 1083 deletions

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,3 @@ jobs:
6262

6363
- name: Check Prettier formatting
6464
run: npm run format
65-
continue-on-error: true # Existing code has formatting issues

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ npm install @hokify/node-ts-cache
2323
```
2424

2525
```typescript
26-
import { Cache, ExpirationStrategy, MemoryStorage } from "@hokify/node-ts-cache";
26+
import { Cache, ExpirationStrategy, MemoryStorage } from '@hokify/node-ts-cache';
2727

2828
const cacheStrategy = new ExpirationStrategy(new MemoryStorage());
2929

3030
class UserService {
31-
@Cache(cacheStrategy, { ttl: 300 })
32-
async getUser(id: string): Promise<User> {
33-
// This result will be cached for 5 minutes
34-
return await fetchUserFromDatabase(id);
35-
}
31+
@Cache(cacheStrategy, { ttl: 300 })
32+
async getUser(id: string): Promise<User> {
33+
// This result will be cached for 5 minutes
34+
return await fetchUserFromDatabase(id);
35+
}
3636
}
3737
```
3838

@@ -42,19 +42,19 @@ This is a monorepo containing the following packages:
4242

4343
### Core Package
4444

45-
| Package | Version | Description |
46-
|---------|---------|-------------|
45+
| Package | Version | Description |
46+
| ----------------------------------- | -------------------------------------------------------------- | ---------------------------------------------------------------------- |
4747
| [@hokify/node-ts-cache](./ts-cache) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache.svg) | Core caching module with decorators, strategies, and built-in storages |
4848

4949
### Storage Adapters
5050

51-
| Package | Version | Description |
52-
|---------|---------|-------------|
53-
| [@hokify/node-ts-cache-redis-storage](./storages/redis) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache-redis-storage.svg) | Redis storage using `redis` package (v3.x) |
54-
| [@hokify/node-ts-cache-redisio-storage](./storages/redisio) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache-redisio-storage.svg) | Redis storage using `ioredis` with compression support |
55-
| [@hokify/node-ts-cache-node-cache-storage](./storages/node-cache) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache-node-cache-storage.svg) | In-memory cache using `node-cache` |
56-
| [@hokify/node-ts-cache-lru-storage](./storages/lru) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache-lru-storage.svg) | LRU cache with automatic eviction |
57-
| [@hokify/node-ts-cache-lru-redis-storage](./storages/lru-redis) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache-lru-redis-storage.svg) | Two-tier caching (local LRU + remote Redis) |
51+
| Package | Version | Description |
52+
| ----------------------------------------------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------ |
53+
| [@hokify/node-ts-cache-redis-storage](./storages/redis) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache-redis-storage.svg) | Redis storage using `redis` package (v3.x) |
54+
| [@hokify/node-ts-cache-redisio-storage](./storages/redisio) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache-redisio-storage.svg) | Redis storage using `ioredis` with compression support |
55+
| [@hokify/node-ts-cache-node-cache-storage](./storages/node-cache) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache-node-cache-storage.svg) | In-memory cache using `node-cache` |
56+
| [@hokify/node-ts-cache-lru-storage](./storages/lru) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache-lru-storage.svg) | LRU cache with automatic eviction |
57+
| [@hokify/node-ts-cache-lru-redis-storage](./storages/lru-redis) | ![npm](https://img.shields.io/npm/v/@hokify/node-ts-cache-lru-redis-storage.svg) | Two-tier caching (local LRU + remote Redis) |
5858

5959
## Documentation
6060

@@ -90,15 +90,15 @@ For detailed documentation, see the [main package README](./ts-cache/README.md).
9090

9191
## Choosing a Storage
9292

93-
| Storage | Type | Use Case | Features |
94-
|---------|------|----------|----------|
95-
| **MemoryStorage** | Sync | Development, small datasets | Zero config, bundled |
96-
| **FsJsonStorage** | Async | Persistent local cache | File-based, survives restarts |
97-
| **NodeCacheStorage** | Sync | Production single-instance | TTL support, multi-ops |
98-
| **LRUStorage** | Sync | Memory-constrained apps | Auto-eviction, size limits |
99-
| **RedisStorage** | Async | Distributed systems | Shared cache, legacy redis |
100-
| **RedisIOStorage** | Async | Distributed systems | Compression, modern ioredis |
101-
| **LRUWithRedisStorage** | Async | High-performance distributed | Local + remote tiers |
93+
| Storage | Type | Use Case | Features |
94+
| ----------------------- | ----- | ---------------------------- | ----------------------------- |
95+
| **MemoryStorage** | Sync | Development, small datasets | Zero config, bundled |
96+
| **FsJsonStorage** | Async | Persistent local cache | File-based, survives restarts |
97+
| **NodeCacheStorage** | Sync | Production single-instance | TTL support, multi-ops |
98+
| **LRUStorage** | Sync | Memory-constrained apps | Auto-eviction, size limits |
99+
| **RedisStorage** | Async | Distributed systems | Shared cache, legacy redis |
100+
| **RedisIOStorage** | Async | Distributed systems | Compression, modern ioredis |
101+
| **LRUWithRedisStorage** | Async | High-performance distributed | Local + remote tiers |
102102

103103
## Requirements
104104

gulpfile.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ const del = require('del');
33
const glob = require('glob');
44
const childProcess = require('child_process');
55

6-
task('cleanModules', function() {
6+
task('cleanModules', function () {
77
return del(['./ts-cache/node_modules', './storages/*/node_modules']);
88
});
99

10-
task('cleanTmp', function() {
10+
task('cleanTmp', function () {
1111
return del(['./ts-cache/.tmp', './storages/*/.tmp']);
1212
});
1313

14-
task('cleanDist', function() {
14+
task('cleanDist', function () {
1515
return del(['./ts-cache/dist', './storages/*/dist']);
1616
});
1717

18-
task('updatePackages', function(cb) {
18+
task('updatePackages', function (cb) {
1919
const check = pkgJsonPath => {
2020
try {
2121
return childProcess.execSync(`npx ncu --packageFile ${pkgJsonPath} -u`).toString();

lerna.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
2-
"packages": [
3-
"storages/*",
4-
"ts-cache"
5-
],
2+
"packages": ["storages/*", "ts-cache"],
63
"version": "independent",
74
"command": {
85
"publish": {
@@ -13,8 +10,5 @@
1310
"forceLocal": true,
1411
"conventionalCommits": true,
1512
"reject-cycles": true,
16-
"ignoreChanges": [
17-
"**/test/**",
18-
"**/*.md"
19-
]
13+
"ignoreChanges": ["**/test/**", "**/*.md"]
2014
}

package.json

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
{
2-
"name": "root",
3-
"private": true,
4-
"scripts": {
5-
"publish": "lerna publish",
6-
"build": "lerna run build",
7-
"test": "lerna run test",
8-
"lint": "eslint --ext .ts ts-cache/src storages/*/src",
9-
"lint:fix": "eslint --ext .ts ts-cache/src storages/*/src --fix",
10-
"format": "prettier --check \"**/*.{ts,js,json,md}\" --ignore-path .gitignore",
11-
"format:fix": "prettier --write \"**/*.{ts,js,json,md}\" --ignore-path .gitignore",
12-
"release": "lerna publish",
13-
"prepublishOnly": "npm run test",
14-
"check-package-updates": "ncu -u && gulp updatePackages"
15-
},
16-
"devDependencies": {
17-
"@hokify/eslint-config": "^2.2.1",
18-
"@types/mocha": "10.0.6",
19-
"@types/node": "18.19.0",
20-
"lerna": "^8.0.0",
21-
"mocha": "10.4.0",
22-
"ts-node": "10.9.1",
23-
"typescript": "5.1.6"
24-
},
25-
"dependencies": {
26-
"del": "^6.0.0",
27-
"glob": "^7.2.0",
28-
"gulp": "^4.0.2",
29-
"prettier": "^2.4.1"
30-
},
31-
"workspaces": [
32-
"storages/*",
33-
"ts-cache"
34-
]
2+
"name": "root",
3+
"private": true,
4+
"workspaces": [
5+
"storages/*",
6+
"ts-cache"
7+
],
8+
"scripts": {
9+
"build": "lerna run build",
10+
"check-package-updates": "ncu -u && gulp updatePackages",
11+
"format": "prettier --check \"**/*.{ts,js,json,md}\" --ignore-path .gitignore",
12+
"format:fix": "prettier --write \"**/*.{ts,js,json,md}\" --ignore-path .gitignore",
13+
"lint": "eslint --ext .ts ts-cache/src storages/*/src",
14+
"lint:fix": "eslint --ext .ts ts-cache/src storages/*/src --fix",
15+
"prepublishOnly": "npm run test",
16+
"publish": "lerna publish",
17+
"release": "lerna publish",
18+
"test": "lerna run test"
19+
},
20+
"dependencies": {
21+
"del": "^6.0.0",
22+
"glob": "^7.2.0",
23+
"gulp": "^4.0.2",
24+
"prettier": "^2.4.1"
25+
},
26+
"devDependencies": {
27+
"@hokify/eslint-config": "^2.2.1",
28+
"@types/mocha": "10.0.6",
29+
"@types/node": "18.19.0",
30+
"lerna": "^8.0.0",
31+
"mocha": "10.4.0",
32+
"ts-node": "10.9.1",
33+
"typescript": "5.1.6"
34+
}
3535
}

storages/lru-redis/README.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,39 @@ npm install @hokify/node-ts-cache @hokify/node-ts-cache-lru-redis-storage ioredi
5050
### Basic Usage
5151

5252
```typescript
53-
import { Cache, ExpirationStrategy } from "@hokify/node-ts-cache";
54-
import LRUWithRedisStorage from "@hokify/node-ts-cache-lru-redis-storage";
55-
import Redis from "ioredis";
53+
import { Cache, ExpirationStrategy } from '@hokify/node-ts-cache';
54+
import LRUWithRedisStorage from '@hokify/node-ts-cache-lru-redis-storage';
55+
import Redis from 'ioredis';
5656

5757
const redisClient = new Redis({
58-
host: "localhost",
59-
port: 6379
58+
host: 'localhost',
59+
port: 6379
6060
});
6161

6262
const storage = new LRUWithRedisStorage(
63-
{ max: 1000 }, // LRU options: max 1000 items locally
64-
() => redisClient // Redis client factory
63+
{ max: 1000 }, // LRU options: max 1000 items locally
64+
() => redisClient // Redis client factory
6565
);
6666

6767
const strategy = new ExpirationStrategy(storage);
6868

6969
class UserService {
70-
@Cache(strategy, { ttl: 300 })
71-
async getUser(id: string): Promise<User> {
72-
return await db.users.findById(id);
73-
}
70+
@Cache(strategy, { ttl: 300 })
71+
async getUser(id: string): Promise<User> {
72+
return await db.users.findById(id);
73+
}
7474
}
7575
```
7676

7777
### With LRU TTL
7878

7979
```typescript
8080
const storage = new LRUWithRedisStorage(
81-
{
82-
max: 500,
83-
maxAge: 1000 * 60 // Local cache TTL: 1 minute (milliseconds)
84-
},
85-
() => redisClient
81+
{
82+
max: 500,
83+
maxAge: 1000 * 60 // Local cache TTL: 1 minute (milliseconds)
84+
},
85+
() => redisClient
8686
);
8787
```
8888

@@ -93,13 +93,13 @@ const storage = new LRUWithRedisStorage({ max: 100 }, () => redisClient);
9393
const strategy = new ExpirationStrategy(storage);
9494

9595
// Store (writes to both LRU and Redis)
96-
await strategy.setItem("user:123", { name: "John" }, { ttl: 60 });
96+
await strategy.setItem('user:123', { name: 'John' }, { ttl: 60 });
9797

9898
// First get - might hit Redis if not in LRU
99-
const user1 = await strategy.getItem<User>("user:123");
99+
const user1 = await strategy.getItem<User>('user:123');
100100

101101
// Second get - hits local LRU (fast!)
102-
const user2 = await strategy.getItem<User>("user:123");
102+
const user2 = await strategy.getItem<User>('user:123');
103103

104104
// Clear both caches
105105
await strategy.clear();
@@ -114,27 +114,27 @@ new LRUWithRedisStorage(
114114
)
115115
```
116116

117-
| Parameter | Type | Description |
118-
|-----------|------|-------------|
119-
| `lruOptions` | `LRU.Options` | Options for local LRU cache (see [lru-cache](https://www.npmjs.com/package/lru-cache#options)) |
120-
| `redis` | `() => Redis.Redis` | Factory function returning an ioredis client |
117+
| Parameter | Type | Description |
118+
| ------------ | ------------------- | ---------------------------------------------------------------------------------------------- |
119+
| `lruOptions` | `LRU.Options` | Options for local LRU cache (see [lru-cache](https://www.npmjs.com/package/lru-cache#options)) |
120+
| `redis` | `() => Redis.Redis` | Factory function returning an ioredis client |
121121

122122
### LRU Options
123123

124-
| Option | Type | Default | Description |
125-
|--------|------|---------|-------------|
126-
| `max` | `number` | Required | Maximum items in local cache |
127-
| `maxAge` | `number` | - | Local TTL in **milliseconds** |
128-
| `maxSize` | `number` | - | Maximum total size |
129-
| `sizeCalculation` | `function` | - | Size calculator function |
124+
| Option | Type | Default | Description |
125+
| ----------------- | ---------- | -------- | ----------------------------- |
126+
| `max` | `number` | Required | Maximum items in local cache |
127+
| `maxAge` | `number` | - | Local TTL in **milliseconds** |
128+
| `maxSize` | `number` | - | Maximum total size |
129+
| `sizeCalculation` | `function` | - | Size calculator function |
130130

131131
## Interface
132132

133133
```typescript
134134
interface IAsynchronousCacheType {
135-
getItem<T>(key: string): Promise<T | undefined>;
136-
setItem(key: string, content: any, options?: any): Promise<void>;
137-
clear(): Promise<void>;
135+
getItem<T>(key: string): Promise<T | undefined>;
136+
setItem(key: string, content: any, options?: any): Promise<void>;
137+
clear(): Promise<void>;
138138
}
139139
```
140140

@@ -144,13 +144,13 @@ interface IAsynchronousCacheType {
144144

145145
```typescript
146146
class ProductAPI {
147-
@Cache(strategy, { ttl: 60 })
148-
async getProduct(id: string): Promise<Product> {
149-
// Hot products served from local LRU (~0.01ms)
150-
// Cold products fetched from Redis (~1-5ms)
151-
// Very cold products hit database
152-
return await db.products.findById(id);
153-
}
147+
@Cache(strategy, { ttl: 60 })
148+
async getProduct(id: string): Promise<Product> {
149+
// Hot products served from local LRU (~0.01ms)
150+
// Cold products fetched from Redis (~1-5ms)
151+
// Very cold products hit database
152+
return await db.products.findById(id);
153+
}
154154
}
155155
```
156156

@@ -178,12 +178,12 @@ Multiple application instances share the same Redis cache while maintaining thei
178178

179179
```typescript
180180
class SessionService {
181-
@Cache(strategy, { ttl: 1800 }) // 30 minutes
182-
async getSession(token: string): Promise<Session> {
183-
// Active sessions stay in local LRU
184-
// Inactive sessions fall back to Redis
185-
return await db.sessions.findByToken(token);
186-
}
181+
@Cache(strategy, { ttl: 1800 }) // 30 minutes
182+
async getSession(token: string): Promise<Session> {
183+
// Active sessions stay in local LRU
184+
// Inactive sessions fall back to Redis
185+
return await db.sessions.findByToken(token);
186+
}
187187
}
188188
```
189189

0 commit comments

Comments
 (0)