Skip to content

Commit

Permalink
refactor!: remove deprecated RestrictedKV class
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxken committed Jan 8, 2025
1 parent 53b8e35 commit a30ca49
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 997 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ $ yarn add @myunisoft/redis
- Abstraction
- [KVPeer](./docs/KVPeer.md)
- [TimedKVPeer](./docs/TimedKVPeer.md)
- [RestrictedKV](./docs/RestrictedKV.md)
- [StoreContext](./docs/StoreContext.md)
- [PubSub](./docs/pubsub/Channel.md)
- [Stream](./docs/stream/Stream.md)
Expand Down
107 changes: 0 additions & 107 deletions docs/RestrictedKV.md

This file was deleted.

10 changes: 0 additions & 10 deletions docs/adapter/memory.adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ const result = await memoryAdapter.deleteValue(key);
console.log(result); // 0 for Failure, 1 for Success
```

### clearExpired(options: { banTimeInSecond: number; }): (string | Buffer)[]

this method is used to clear expired key-value pairs in memory

```ts
const result = await memoryAdapter.clearExpired({ banTimeInSecond: 10 });

console.log(result); // []
```

### getValue(key: string): null | unknown

this method is used to get a value from memory
Expand Down
22 changes: 0 additions & 22 deletions docs/adapter/redis.adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,6 @@ const result = await redisAdapter.deleteValue(key);
console.log(result); // 0 for Failure, 1 for Success
```

### clearExpired(options: ClearExpiredOptions): (string | Buffer)[]

this method is used to clear expired key-value pairs in redis

```ts
const result = await redisAdapter.clearExpired({ banTimeInSecond: 10 });

console.log(result); // []
```

### isKeyExpired(options: RedisIsKeyExpiredOptions): boolean

this method is used to check if a key is expired in redis

```ts
const key = "foo";

const result = await redisAdapter.isKeyExpired({ key, banTimeInSecond: 10 });

console.log(result); // false
```

### deepParseInput(input: Record<string, any> | any[]): Generator<string | Record<string, any> | any[]>

this method is used to deep parse input
Expand Down
155 changes: 0 additions & 155 deletions src/class/RestrictedKV.class.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/class/adapter/memory.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,6 @@ export class MemoryAdapter implements DatabaseConnection {
return isDelete ? 1 : 0;
}

clearExpired(options: { banTimeInSecond: number; }): (string | Buffer)[] {
const { banTimeInSecond } = options;

const expired: string[] = [];

for (const [key, value] of this.#values) {
if (this.isKeyExpired({
banTimeInSecond,
value: value as Record<string, unknown>
})) {
expired.push(key);
this.#values.delete(key);
}
}

return expired;
}

// Implement the no-argument version of getValue
getValue(key: string): null | unknown {
const valueExist = this.#values.has(key);
Expand All @@ -75,12 +57,4 @@ export class MemoryAdapter implements DatabaseConnection {

return this.#values.get(key);
}

private isKeyExpired(options: InMemIsKeyExpiredOptions) {
const { banTimeInSecond, value } = options;

const lastTry = "lastTry" in value ? Number(value.lastTry) : null;

return lastTry === null ? false : (Date.now() - lastTry) / 1000 >= banTimeInSecond;
}
}
Loading

0 comments on commit a30ca49

Please sign in to comment.