Skip to content

Commit fe7e4ed

Browse files
committed
Refactor TypeGuard implementation and tests; remove unused TypeGuard and update RedisGuard error handling
1 parent 7644c2f commit fe7e4ed

File tree

9 files changed

+77
-312
lines changed

9 files changed

+77
-312
lines changed

src/infra/redis/guards/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export { RedisGuard } from './redis.guard.js';
2-
export { TypeGuard } from './type.guard.js';

src/infra/redis/guards/redis.guard.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { TypeGuard } from '../../../shared/guard/type.guard.js';
12
import { XItem, XItems } from '../interfaces/index.js';
2-
import { TypeGuard } from './type.guard.js';
33

44
export class RedisGuard {
55
public static isXItem(value: unknown): value is XItem {
@@ -19,7 +19,7 @@ export class RedisGuard {
1919

2020
public static checkXItem(value: unknown): XItem {
2121
if (!this.isXItem(value)) {
22-
throw new Error('Value is not a XItem.');
22+
throw new TypeError('Value is not a XItem.');
2323
}
2424

2525
return value;
@@ -35,7 +35,7 @@ export class RedisGuard {
3535

3636
public static checkXItems(value: unknown): XItems {
3737
if (!this.isXItems(value)) {
38-
throw new Error('One of the values is not an xItem.');
38+
throw new TypeError('One of the values is not an xItem.');
3939
}
4040

4141
return value;

src/infra/redis/guards/type.guard.spec.ts

Lines changed: 0 additions & 245 deletions
This file was deleted.

src/infra/redis/guards/type.guard.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/infra/redis/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export { TypeGuard } from './guards/type.guard.js';
21
export {
32
RedisAdapter,
43
StreamMessageReply,

src/infra/redis/mapper.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { RedisGuard, TypeGuard } from './guards/index.js';
1+
import { TypeGuard } from '../../shared/guard/type.guard.js';
2+
import { RedisGuard } from './guards/index.js';
23
import {
34
Compact,
45
DocName,
@@ -17,7 +18,7 @@ export function mapToXAutoClaimResponse(value: unknown): XAutoClaimResponse {
1718
return { nextId: '', messages: null };
1819
}
1920

20-
const unknownArray = TypeGuard.checkUnknownArrayWithElements(value);
21+
const unknownArray = TypeGuard.checkArrayWithElements(value);
2122
const xItems = RedisGuard.checkXItems(unknownArray[1]);
2223
const redisKey = TypeGuard.isString(unknownArray[0])
2324
? TypeGuard.checkString(unknownArray[0])
@@ -49,10 +50,10 @@ export function mapToStreamMessagesReply(streamReply: XReadBufferReply | unknown
4950
return [];
5051
}
5152

52-
const unknownArray = TypeGuard.checkUnknownArrayWithElements(streamReply);
53+
const unknownArray = TypeGuard.checkArrayWithElements(streamReply);
5354

5455
const result = unknownArray.map((entry) => {
55-
const entryArray = TypeGuard.checkUnknownArrayWithElements(entry);
56+
const entryArray = TypeGuard.checkArrayWithElements(entry);
5657
const key = TypeGuard.checkBuffer(entryArray[0]);
5758
const messages = RedisGuard.checkXItems(entryArray[1]);
5859

src/infra/y-redis/helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { RedisKey } from 'ioredis';
22
import { array, map } from 'lib0';
3-
import { StreamMessageReply, StreamMessagesReply, TypeGuard } from '../../infra/redis/index.js';
3+
import { StreamMessageReply, StreamMessagesReply } from '../../infra/redis/index.js';
4+
import { TypeGuard } from '../../shared/guard/type.guard.js';
45
import { YRedisMessage } from './interfaces/stream-message.js';
56

67
/* This file contains the implementation of the functions,

0 commit comments

Comments
 (0)