Skip to content

Commit e24488e

Browse files
committed
REFACTOR: prettier formatting
1 parent db014b1 commit e24488e

14 files changed

Lines changed: 56 additions & 56 deletions

File tree

lib/cache/interfaces/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ModuleMetadata, Type } from '@nestjs/common';
22

33
export interface RedisDriverOption {
4-
driver?: "redis";
4+
driver?: 'redis';
55
host?: string;
66
port?: number;
77
url?: string;

lib/explorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class IntentExplorer {
104104

105105
lookupLimittedMethods(
106106
instance: Record<string, GenericFunction>,
107-
key: string
107+
key: string,
108108
) {
109109
let methodRef = instance[key];
110110
const hasCommandMeta = Reflect.hasMetadata(TOKEN_COUNT, instance, key);

lib/limiter/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const TOKEN_COUNT = "__TOKEN_COUNT__";
2-
export const REFILL_INTERVAL = "__REFILL_INTERVAL__";
1+
export const TOKEN_COUNT = '__TOKEN_COUNT__';
2+
export const REFILL_INTERVAL = '__REFILL_INTERVAL__';

lib/limiter/decorator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { REFILL_INTERVAL, TOKEN_COUNT } from "./constants";
1+
import { REFILL_INTERVAL, TOKEN_COUNT } from './constants';
22

33
export const Limit = (tokens: number, seconds: number) => {
4-
console.log("first(): factory evaluated");
4+
console.log('first(): factory evaluated');
55
return function (
66
target: any,
77
propertyKey: string,
8-
descriptor: PropertyDescriptor
8+
descriptor: PropertyDescriptor,
99
) {
1010
Reflect.defineMetadata(TOKEN_COUNT, tokens, target, propertyKey);
1111
Reflect.defineMetadata(REFILL_INTERVAL, seconds, target, propertyKey);

lib/limiter/drivers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from "./memory";
2-
export * from "./redis";
1+
export * from './memory';
2+
export * from './redis';

lib/limiter/drivers/redis.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { RedisDriverOption } from "../../cache";
2-
import { Package } from "../../utils";
3-
import { LimiterDriver } from "../interfaces/limiterDriver";
1+
import { RedisDriverOption } from '../../cache';
2+
import { Package } from '../../utils';
3+
import { LimiterDriver } from '../interfaces/limiterDriver';
44

55
export class RedisDriver implements LimiterDriver {
66
private client: any;
77

88
constructor(private options: RedisDriverOption) {
9-
const IORedis = Package.load("ioredis");
9+
const IORedis = Package.load('ioredis');
1010
if (options.url) {
1111
this.client = new IORedis(options.url, { db: options.database || 0 });
1212
} else {
@@ -23,7 +23,7 @@ export class RedisDriver implements LimiterDriver {
2323
async setCounter(
2424
key: string,
2525
value: number,
26-
ttlInSec?: number
26+
ttlInSec?: number,
2727
): Promise<void> {
2828
await this.set(key, value, ttlInSec);
2929
}
@@ -74,12 +74,12 @@ export class RedisDriver implements LimiterDriver {
7474
private async set(
7575
key: string,
7676
value: string | number | Record<string, any>,
77-
ttlInSec?: number
77+
ttlInSec?: number,
7878
): Promise<boolean> {
7979
try {
8080
const redisKey = this.storeKey(key);
8181
ttlInSec
82-
? await this.client.set(redisKey, JSON.stringify(value), "EX", ttlInSec)
82+
? await this.client.set(redisKey, JSON.stringify(value), 'EX', ttlInSec)
8383
: await this.client.set(redisKey, JSON.stringify(value));
8484
return true;
8585
} catch {

lib/limiter/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * from "./rateLimiter";
2-
export * from "./strategies";
3-
export * from "./drivers";
4-
export * from "./rateLimiter";
5-
export * from "./decorator";
1+
export * from './rateLimiter';
2+
export * from './strategies';
3+
export * from './drivers';
4+
export * from './rateLimiter';
5+
export * from './decorator';

lib/limiter/interfaces/options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MemoryDriver, RedisDriver } from "../drivers";
1+
import { MemoryDriver, RedisDriver } from '../drivers';
22

33
export interface LimiterOptions {
44
isGlobal?: boolean;
@@ -16,8 +16,8 @@ export interface RedisConnection {
1616
}
1717

1818
export enum LimiterDriverType {
19-
REDIS = "redis",
20-
IN_MEMORY = "in-memory",
19+
REDIS = 'redis',
20+
IN_MEMORY = 'in-memory',
2121
}
2222

2323
export const defaultOptions = {

lib/limiter/rateLimiter.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { LimiterDriver } from "./interfaces/limiterDriver";
2-
import { BaseStrategy } from "./strategies/baseStrategy";
3-
import { Injectable } from "@nestjs/common";
4-
import { RedisDriver } from "./drivers/redis";
5-
import { IntentConfig } from "../config/service";
1+
import { LimiterDriver } from './interfaces/limiterDriver';
2+
import { BaseStrategy } from './strategies/baseStrategy';
3+
import { Injectable } from '@nestjs/common';
4+
import { RedisDriver } from './drivers/redis';
5+
import { IntentConfig } from '../config/service';
66
import {
77
DriversMap,
88
LimiterDriverType,
99
LimiterOptions,
10-
} from "./interfaces/options";
10+
} from './interfaces/options';
1111

1212
@Injectable()
1313
export class Limiter {
1414
private static driver: LimiterDriver;
1515
private static strategy: BaseStrategy;
1616
constructor(private config: IntentConfig) {
17-
const options = this.config.get<LimiterOptions>("queue");
17+
const options = this.config.get<LimiterOptions>('queue');
1818
switch (options.driver) {
1919
case LimiterDriverType.REDIS: {
2020
Limiter.driver = new DriversMap[LimiterDriverType.REDIS](
21-
options.connection
21+
options.connection,
2222
);
2323
}
2424
default: {
@@ -31,7 +31,7 @@ export class Limiter {
3131
static initializeToken = (
3232
key: string,
3333
tokensCount: number,
34-
intervalInSeconds: number
34+
intervalInSeconds: number,
3535
) => {
3636
Limiter.strategy.initializeToken(key, tokensCount, intervalInSeconds);
3737
};

lib/limiter/strategies/baseStrategy.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { GenericException } from "../../exceptions";
2-
import { LimiterDriver } from "../interfaces/limiterDriver";
1+
import { GenericException } from '../../exceptions';
2+
import { LimiterDriver } from '../interfaces/limiterDriver';
33

44
export class BaseStrategy {
55
protected static tokensQuota = {};
@@ -12,7 +12,7 @@ export class BaseStrategy {
1212
initializeToken = async (
1313
key: string,
1414
tokensCount: number,
15-
intervalInSeconds: number
15+
intervalInSeconds: number,
1616
) => {
1717
BaseStrategy.tokensQuota[key] = tokensCount;
1818
BaseStrategy.tokensIntervals[key] = intervalInSeconds;
@@ -24,14 +24,14 @@ export class BaseStrategy {
2424
await this.initializeToken(
2525
key,
2626
BaseStrategy.tokensQuota[key] - 1,
27-
BaseStrategy.tokensIntervals[key]
27+
BaseStrategy.tokensIntervals[key],
2828
);
2929
return;
3030
}
3131
const cut = await this.driver.decrementCounter(key);
32-
console.log("current Count", await this.driver.getCount(key), cut);
32+
console.log('current Count', await this.driver.getCount(key), cut);
3333
if (!cut) {
34-
throw new GenericException("Cannot be called.");
34+
throw new GenericException('Cannot be called.');
3535
}
3636
};
3737
}

0 commit comments

Comments
 (0)