Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

952 include configuration for git mode in libms #965

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7d9a3b2
adds git files service
nichlaes Oct 10, 2024
afa609e
adds gitFilesService to module
nichlaes Oct 10, 2024
1c240ed
fixed eslint errors
nichlaes Oct 10, 2024
10a74e0
fixed specs
nichlaes Oct 10, 2024
4092831
added modules
nichlaes Oct 14, 2024
0f86722
adds git files service
nichlaes Oct 10, 2024
749f99c
adds gitFilesService to module
nichlaes Oct 10, 2024
a903716
fixed eslint errors
nichlaes Oct 10, 2024
5c69068
fixed specs
nichlaes Oct 10, 2024
739a0b2
added modules
nichlaes Oct 14, 2024
0c90149
Merge branch '952-include-configuration-for-git-mode-in-libms' of htt…
nichlaes Oct 14, 2024
5615a2b
changed to useFactory
nichlaes Oct 22, 2024
1245177
Merge branch 'feature/distributed-demo' into 952-include-configuratio…
nichlaes Oct 22, 2024
9198cf9
removed configModule
nichlaes Oct 22, 2024
9cccbf3
changed to fileService map and made static
nichlaes Oct 23, 2024
b24b0c5
refactoring
nichlaes Oct 23, 2024
91d7f09
refactoring
nichlaes Oct 23, 2024
8dd40b4
adds enum
nichlaes Oct 23, 2024
959a376
formatting
nichlaes Oct 23, 2024
8af63ad
changed to IfilesService array
nichlaes Oct 24, 2024
7e8eb16
changed to IfilesService array
nichlaes Oct 24, 2024
50668fc
fixed errors
nichlaes Oct 27, 2024
1acb8c9
formatting
nichlaes Oct 28, 2024
d68cc69
adds formatting to step
nichlaes Oct 28, 2024
4bb185e
removes redundant yarn install
nichlaes Oct 28, 2024
1fd158e
sets dataPath in constructor
nichlaes Oct 28, 2024
74a9e1a
fixed linting problem
nichlaes Oct 28, 2024
c7109b0
fixed failling test
nichlaes Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions servers/lib/src/files/files.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { Module } from '@nestjs/common';
import FilesResolver from './resolvers/files.resolver.js';
import FilesServiceFactory from './services/files-service.factory.js';
import LocalFilesService from './services/local-files.service.js';
import { GitFilesModule } from './modules/git-files.module.js';
import { LocalFilesModule } from './modules/local-files.module.js';

@Module({
providers: [FilesResolver, LocalFilesService, FilesServiceFactory],
imports: [
LocalFilesModule,
GitFilesModule,
],
providers: [
FilesResolver,
FilesServiceFactory,
],
})
export default class FilesModule {}
8 changes: 8 additions & 0 deletions servers/lib/src/files/modules/git-files.module.ts
nichlaes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import GitFilesService from '../services/git-files.service.js';

@Module({
providers: [GitFilesService],
exports: [GitFilesService]
})
export class GitFilesModule {}
8 changes: 8 additions & 0 deletions servers/lib/src/files/modules/local-files.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import LocalFilesService from '../services/local-files.service.js';

@Module({
providers: [LocalFilesService],
exports: [LocalFilesService]
})
export class LocalFilesModule {}
12 changes: 9 additions & 3 deletions servers/lib/src/files/services/files-service.factory.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes into useFactory method inside files.module.ts

Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ import { Injectable, Inject } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { IFilesService } from '../interfaces/files.service.interface.js';
import LocalFilesService from './local-files.service.js';
import GitFilesService from './git-files.service.js';

@Injectable()
export default class FilesServiceFactory {
/* eslint-disable no-useless-constructor, no-empty-function */
constructor(
private configService: ConfigService,
@Inject(LocalFilesService) private localFilesService: LocalFilesService,
@Inject(GitFilesService) private gitFilesService: GitFilesService,
) {}
/* eslint-enable no-useless-constructor, no-empty-function */

create(): IFilesService {
nichlaes marked this conversation as resolved.
Show resolved Hide resolved
const mode = this.configService.get<string>('MODE');
if (mode === 'local') {
return this.localFilesService;
switch (mode) {
case 'local':
return this.localFilesService;
case 'git':
return this.gitFilesService;
default:
throw new Error(`Invalid MODE: ${mode}`);
}
throw new Error(`Invalid MODE: ${mode}`);
}
}
16 changes: 16 additions & 0 deletions servers/lib/src/files/services/git-files.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Injectable } from '@nestjs/common';
import { Project } from 'src/types.js';
import { IFilesService } from '../interfaces/files.service.interface.js';

@Injectable()
export default class GitFilesService implements IFilesService {
// eslint-disable-next-line no-useless-constructor, no-empty-function
constructor() {}

listDirectory(): Promise<Project> {
throw new Error('Method not implemented.');
}
readFile(): Promise<Project> {
throw new Error('Method not implemented.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
testFileContent,
MockConfigService,
} from '../testUtil';
import GitFilesService from '../../src/files/services/git-files.service';

describe('Integration tests for FilesResolver', () => {
let filesResolver: FilesResolver;
Expand All @@ -23,6 +24,7 @@ describe('Integration tests for FilesResolver', () => {
FilesResolver,
FilesServiceFactory,
LocalFilesService,
GitFilesService,
{ provide: ConfigService, useClass: MockConfigService },
],
}).compile();
Expand Down
2 changes: 2 additions & 0 deletions servers/lib/test/unit/files-service.factory.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ConfigService } from '@nestjs/config';
import FilesServiceFactory from '../../src/files/services/files-service.factory';
import LocalFilesService from '../../src/files/services/local-files.service';
import { IFilesService } from '../../src/files/interfaces/files.service.interface';
import GitFilesService from '../../src/files/services/git-files.service';

describe('FilesServiceFactory', () => {
let serviceFactory: FilesServiceFactory;
Expand All @@ -17,6 +18,7 @@ describe('FilesServiceFactory', () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
FilesServiceFactory,
GitFilesService,
{ provide: ConfigService, useValue: { get: jest.fn() } },
{ provide: LocalFilesService, useValue: localFilesService },
],
Expand Down
Loading