Skip to content

Commit

Permalink
Refactor imports to use barrel files for better organization and main…
Browse files Browse the repository at this point in the history
…tainability
  • Loading branch information
SevenWaysDP committed Jan 6, 2025
1 parent 34fffc5 commit ff9e4d0
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/apps/tldraw-server.app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerDocumentOptions, SwaggerModule } from '@nestjs/swagger';
import { Logger } from '../infra/logger/index.js';
import { MetricsModule } from '../infra/metrics/metrics.module.js';
import { MetricsModule } from '../infra/metrics/index.js';
import { ServerModule } from '../modules/server/server.module.js';

async function bootstrap(): Promise<void> {
Expand Down
9 changes: 9 additions & 0 deletions src/infra/redis/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
export { TypeGuard } from './guards/type.guard.js';
export {
RedisAdapter,
StreamMessageReply,
StreamMessagesReply,
StreamNameClockPair,
Task,
XAutoClaimResponse,
} from './interfaces/index.js';
export * from './redis.factory.js';
export * from './redis.module.js';
7 changes: 7 additions & 0 deletions src/infra/redis/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './stream-message-reply.factory.js';
export * from './stream-messages-reply.factory.js';
export * from './x-auto-claim-raw-reply.factory.js';
export * from './x-auto-claim-response.factory.js';
export * from './x-item.factory.js';
export * from './x-items.factory.js';
export * from './x-read-buffer-reply.factory.js';
1 change: 1 addition & 0 deletions src/infra/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './test-api-client.js';
3 changes: 1 addition & 2 deletions src/infra/y-redis/helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { RedisKey } from 'ioredis';
import { array, map } from 'lib0';
import { TypeGuard } from '../../infra/redis/guards/type.guard.js';
import { StreamMessageReply, StreamMessagesReply } from '../../infra/redis/interfaces/index.js';
import { StreamMessageReply, StreamMessagesReply, TypeGuard } from '../../infra/redis/index.js';
import { YRedisMessage } from './interfaces/stream-message.js';

/* This file contains the implementation of the functions,
Expand Down
8 changes: 8 additions & 0 deletions src/infra/y-redis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export { computeRedisRoomStreamName, decodeRedisRoomStreamName, RoomStreamInfos } from './helper.js';
export { YRedisClientModule } from './y-redis-client.module.js';
export { YRedisDoc } from './y-redis-doc.js';
export { YRedisServiceModule } from './y-redis-service.module.js';
export { YRedisUserFactory } from './y-redis-user.factory.js';
export { YRedisUser } from './y-redis-user.js';
export { YRedisClient } from './y-redis.client.js';
export { YRedisService } from './y-redis.service.js';
4 changes: 2 additions & 2 deletions src/infra/y-redis/subscriber.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
import { Injectable, OnModuleDestroy } from '@nestjs/common';
import * as map from 'lib0/map';
import { Logger } from '../../infra/logger/logger.js';
import { StreamNameClockPair } from '../../infra/redis/interfaces/stream-name-clock-pair.js';
import { Logger } from '../../infra/logger/index.js';
import { StreamNameClockPair } from '../../infra/redis/index.js';
import { isSmallerRedisId } from './helper.js';
import { YRedisClient } from './y-redis.client.js';

Expand Down
3 changes: 3 additions & 0 deletions src/infra/y-redis/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { yRedisDocFactory } from './y-redis-doc.factory.js';
export { yRedisMessageFactory } from './y-redis-message.factory.js';
export { yRedisUserFactory } from './y-redis-user.factory.js';
2 changes: 1 addition & 1 deletion src/modules/server/api/test/tldraw-config.api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { TestApiClient } from '../../../../infra/testing/test-api-client.js';
import { TestApiClient } from '../../../../infra/testing/index.js';
import { ServerModule } from '../../server.module.js';

describe('Tldraw-Config Api Test', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/server/api/test/tldraw-document.api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { TestApiClient } from '../../../../infra/testing/test-api-client.js';
import { TestApiClient } from '../../../../infra/testing/index.js';
import { ServerModule } from '../../server.module.js';

describe('Tldraw-Document Api Test', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/server/api/test/websocket.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { WebSocket } from 'ws';
import { WebsocketProvider } from 'y-websocket';
import { Doc, encodeStateAsUpdateV2 } from 'yjs';
import { ResponsePayloadBuilder } from '../../../../infra//authorization/response.builder.js';
import { AuthorizationService } from '../../../../infra/authorization/authorization.service.js';
import { AuthorizationService } from '../../../../infra/authorization/index.js';
import { ServerModule } from '../../server.module.js';
import { TldrawServerConfig } from '../../tldraw-server.config.js';

Expand Down
12 changes: 4 additions & 8 deletions src/modules/server/api/websocket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import {
us_socket_context_t,
WebSocket,
} from 'uWebSockets.js';
import { AuthorizationService } from '../../../infra/authorization/authorization.service.js';
import { AuthorizationService } from '../../../infra/authorization/index.js';
import { Logger } from '../../../infra/logger/index.js';
import { MetricsService } from '../../../infra/metrics/metrics.service.js';
import { RedisAdapter } from '../../../infra/redis/interfaces/redis-adapter.js';
import { YRedisDoc } from '../../../infra/y-redis/y-redis-doc.js';
import { YRedisUserFactory } from '../../../infra/y-redis/y-redis-user.factory.js';
import { YRedisUser } from '../../../infra/y-redis/y-redis-user.js';
import { YRedisClient } from '../../../infra/y-redis/y-redis.client.js';
import { YRedisService } from '../../../infra/y-redis/y-redis.service.js';
import { MetricsService } from '../../../infra/metrics/index.js';
import { RedisAdapter } from '../../../infra/redis/index.js';
import { YRedisClient, YRedisDoc, YRedisService, YRedisUser, YRedisUserFactory } from '../../../infra/y-redis/index.js';
import { REDIS_FOR_SUBSCRIBE_OF_DELETION, UWS } from '../server.const.js';
import { TldrawServerConfig } from '../tldraw-server.config.js';

Expand Down
13 changes: 6 additions & 7 deletions src/modules/server/server.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Module, ValidationPipe } from '@nestjs/common';
import { APP_PIPE } from '@nestjs/core';
import { App } from 'uWebSockets.js';
import { AuthGuardModule } from '../../infra/auth-guard/auth-guard.module.js';
import { AuthorizationModule } from '../../infra/authorization/authorization.module.js';
import { ConfigurationModule } from '../../infra/configuration/configuration.module.js';
import { LoggerModule } from '../../infra/logger/logger.module.js';
import { AuthGuardModule } from '../../infra/auth-guard/index.js';
import { AuthorizationModule } from '../../infra/authorization/index.js';
import { ConfigurationModule } from '../../infra/configuration/index.js';
import { LoggerModule } from '../../infra/logger/index.js';
import { RedisModule } from '../../infra/redis/index.js';
import { StorageModule } from '../../infra/storage/storage.module.js';
import { YRedisClientModule } from '../../infra/y-redis/y-redis-client.module.js';
import { YRedisServiceModule } from '../../infra/y-redis/y-redis-service.module.js';
import { StorageModule } from '../../infra/storage/index.js';
import { YRedisClientModule, YRedisServiceModule } from '../../infra/y-redis/index.js';
import { TldrawConfigController } from './api/tldraw-confg.controller.js';
import { TldrawDocumentController } from './api/tldraw-document.controller.js';
import { WebsocketGateway } from './api/websocket.gateway.js';
Expand Down
3 changes: 1 addition & 2 deletions src/modules/server/service/tldraw-document.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { Test } from '@nestjs/testing';
import { TemplatedApp } from 'uWebSockets.js';
import { RedisFactory } from '../../../infra/redis/index.js';
import { RedisAdapter } from '../../../infra/redis/interfaces/redis-adapter.js';
import { RedisAdapter, RedisFactory } from '../../../infra/redis/index.js';
import { REDIS_FOR_DELETION, UWS } from '../server.const.js';
import { TldrawDocumentService } from './tldraw-document.service.js';

Expand Down
4 changes: 2 additions & 2 deletions src/modules/server/service/tldraw-document.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { TemplatedApp } from 'uWebSockets.js';
import { RedisAdapter } from '../../../infra/redis/interfaces/index.js';
import { computeRedisRoomStreamName } from '../../../infra/y-redis/helper.js';
import { RedisAdapter } from '../../../infra/redis/index.js';
import { computeRedisRoomStreamName } from '../../../infra/y-redis/index.js';
import { REDIS_FOR_DELETION, UWS } from '../server.const.js';

@Injectable()
Expand Down
10 changes: 5 additions & 5 deletions src/modules/worker/worker.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Module } from '@nestjs/common';
import { ConfigurationModule } from '../../infra/configuration/configuration.module.js';
import { LoggerModule } from '../../infra/logger/logger.module.js';
import { RedisModule } from '../../infra/redis/redis.module.js';
import { StorageModule } from '../../infra/storage/storage.module.js';
import { YRedisClientModule } from '../../infra/y-redis/y-redis-client.module.js';
import { ConfigurationModule } from '../../infra/configuration/index.js';
import { LoggerModule } from '../../infra/logger/index.js';
import { RedisModule } from '../../infra/redis/index.js';
import { StorageModule } from '../../infra/storage/index.js';
import { YRedisClientModule } from '../../infra/y-redis/index.js';
import { WorkerConfig } from './worker.config.js';
import { REDIS_FOR_WORKER } from './worker.const.js';
import { WorkerService } from './worker.service.js';
Expand Down
13 changes: 6 additions & 7 deletions src/modules/worker/worker.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { Awareness } from 'y-protocols/awareness';
import { Doc } from 'yjs';
import { Logger } from '../../infra/logger/logger.js';
import { RedisAdapter, StreamMessageReply, Task } from '../../infra/redis/interfaces/index.js';
import { streamMessageReplyFactory } from '../../infra/redis/testing/stream-message-reply.factory.js';
import { xAutoClaimResponseFactory } from '../../infra/redis/testing/x-auto-claim-response.factory.js';
import { StorageService } from '../../infra/storage/storage.service.js';
import { yRedisDocFactory } from '../../infra/y-redis/testing/y-redis-doc.factory.js';
import { YRedisClient } from '../../infra/y-redis/y-redis.client.js';
import { Logger } from '../../infra/logger/index.js';
import { RedisAdapter, StreamMessageReply, Task } from '../../infra/redis/index.js';
import { streamMessageReplyFactory, xAutoClaimResponseFactory } from '../../infra/redis/testing/index.js';
import { StorageService } from '../../infra/storage/index.js';
import { YRedisClient } from '../../infra/y-redis/index.js';
import { yRedisDocFactory } from '../../infra/y-redis/testing/index.js';
import { WorkerConfig } from './worker.config.js';
import { REDIS_FOR_WORKER } from './worker.const.js';
import { WorkerService } from './worker.service.js';
Expand Down
8 changes: 3 additions & 5 deletions src/modules/worker/worker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { Inject, Injectable, OnModuleDestroy } from '@nestjs/common';
import { randomUUID } from 'crypto';
import { RedisKey } from 'ioredis';
import { Logger } from '../../infra/logger/index.js';
import { RedisAdapter, StreamMessageReply, Task, XAutoClaimResponse } from '../../infra/redis/interfaces/index.js';
import { StorageService } from '../../infra/storage/storage.service.js';
import { decodeRedisRoomStreamName, RoomStreamInfos } from '../../infra/y-redis/helper.js';
import { YRedisDoc } from '../../infra/y-redis/y-redis-doc.js';
import { YRedisClient } from '../../infra/y-redis/y-redis.client.js';
import { RedisAdapter, StreamMessageReply, Task, XAutoClaimResponse } from '../../infra/redis/index.js';
import { StorageService } from '../../infra/storage/index.js';
import { decodeRedisRoomStreamName, RoomStreamInfos, YRedisClient, YRedisDoc } from '../../infra/y-redis/index.js';
import { WorkerConfig } from './worker.config.js';
import { REDIS_FOR_WORKER } from './worker.const.js';

Expand Down

0 comments on commit ff9e4d0

Please sign in to comment.