@into-cps-association/libms 0.4.7 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/DEVELOPER.md +18 -0
  2. package/README.md +9 -0
  3. package/config/http.json +1 -0
  4. package/dist/src/app.module.js +5 -6
  5. package/dist/src/app.module.js.map +1 -1
  6. package/dist/src/bootstrap.js +11 -18
  7. package/dist/src/bootstrap.js.map +1 -1
  8. package/dist/src/config/config.interface.d.ts +14 -0
  9. package/dist/src/config/config.interface.js +2 -0
  10. package/dist/src/config/config.interface.js.map +1 -0
  11. package/dist/src/config/config.model.d.ts +14 -0
  12. package/dist/src/config/config.model.js +2 -0
  13. package/dist/src/config/config.model.js.map +1 -0
  14. package/dist/src/config/config.module.d.ts +2 -0
  15. package/dist/src/config/config.module.js +33 -0
  16. package/dist/src/config/config.module.js.map +1 -0
  17. package/dist/src/config/config.service.d.ts +17 -0
  18. package/dist/src/config/config.service.js +61 -0
  19. package/dist/src/config/config.service.js.map +1 -0
  20. package/dist/src/config/util.d.ts +1 -0
  21. package/dist/src/config/util.js +5 -0
  22. package/dist/src/config/util.js.map +1 -0
  23. package/dist/src/files/files-service.factory.d.ts +2 -2
  24. package/dist/src/files/files-service.factory.js +4 -1
  25. package/dist/src/files/files-service.factory.js.map +1 -1
  26. package/dist/src/files/files.module.js +2 -2
  27. package/dist/src/files/files.module.js.map +1 -1
  28. package/dist/src/files/git/git-files.module.js +2 -1
  29. package/dist/src/files/git/git-files.module.js.map +1 -1
  30. package/dist/src/files/git/git-files.service.d.ts +10 -3
  31. package/dist/src/files/git/git-files.service.js +58 -9
  32. package/dist/src/files/git/git-files.service.js.map +1 -1
  33. package/dist/src/files/interfaces/files.service.interface.d.ts +1 -0
  34. package/dist/src/files/local/local-files.service.d.ts +3 -2
  35. package/dist/src/files/local/local-files.service.js +12 -4
  36. package/dist/src/files/local/local-files.service.js.map +1 -1
  37. package/dist/src/main.d.ts +4 -1
  38. package/dist/test/cloudcmd/cloudcmd.spec.js +3 -3
  39. package/dist/test/cloudcmd/cloudcmd.spec.js.map +1 -1
  40. package/dist/test/e2e/app.e2e.spec.js +18 -12
  41. package/dist/test/e2e/app.e2e.spec.js.map +1 -1
  42. package/dist/test/integration/files.service.integration.spec.js +6 -6
  43. package/dist/test/integration/files.service.integration.spec.js.map +1 -1
  44. package/dist/test/testUtil.d.ts +7 -1
  45. package/dist/test/testUtil.js +20 -14
  46. package/dist/test/testUtil.js.map +1 -1
  47. package/dist/test/unit/files-service.factory.unit.spec.js +25 -8
  48. package/dist/test/unit/files-service.factory.unit.spec.js.map +1 -1
  49. package/dist/test/unit/files.resolver.unit.spec.js +1 -0
  50. package/dist/test/unit/files.resolver.unit.spec.js.map +1 -1
  51. package/dist/test/unit/git-files.service.unit.spec.d.ts +1 -0
  52. package/dist/test/unit/git-files.service.unit.spec.js +56 -0
  53. package/dist/test/unit/git-files.service.unit.spec.js.map +1 -0
  54. package/dist/test/unit/local-files.service.unit.spec.js +36 -21
  55. package/dist/test/unit/local-files.service.unit.spec.js.map +1 -1
  56. package/dist/tsconfig.tsbuildinfo +1 -1
  57. package/eslint.config.js +5 -0
  58. package/libms.yaml.sample +12 -0
  59. package/package.json +14 -11
  60. package/src/app.module.ts +6 -7
  61. package/src/bootstrap.ts +15 -18
  62. package/src/config/config.interface.ts +14 -0
  63. package/src/config/config.model.ts +13 -0
  64. package/src/config/config.module.ts +23 -0
  65. package/src/config/config.service.ts +54 -0
  66. package/src/config/util.ts +5 -0
  67. package/src/files/files-service.factory.ts +5 -3
  68. package/src/files/files.module.ts +3 -3
  69. package/src/files/git/git-files.module.ts +2 -1
  70. package/src/files/git/git-files.service.ts +52 -7
  71. package/src/files/interfaces/files.service.interface.ts +1 -0
  72. package/src/files/local/local-files.service.ts +13 -4
  73. package/src/main.ts +1 -1
  74. package/test/cloudcmd/cloudcmd.spec.ts +4 -4
  75. package/test/data/user2/tools/large_file.md +1 -0
  76. package/test/e2e/app.e2e.spec.ts +23 -13
  77. package/test/integration/files.service.integration.spec.ts +9 -10
  78. package/test/jest-e2e.json +3 -0
  79. package/test/libms.test.yaml +6 -0
  80. package/test/testUtil.ts +23 -16
  81. package/test/unit/files-service.factory.unit.spec.ts +31 -13
  82. package/test/unit/files.resolver.unit.spec.ts +1 -0
  83. package/test/unit/git-files.service.unit.spec.ts +82 -0
  84. package/test/unit/local-files.service.unit.spec.ts +41 -25
  85. package/test/update-config.js +25 -0
package/eslint.config.js CHANGED
@@ -20,6 +20,11 @@ export default [
20
20
  files: ['src/**', 'test/**'],
21
21
  },
22
22
  prettier,
23
+ {
24
+ ignores: [
25
+ 'test/update-config.js', // Add the file you want to ignore
26
+ ],
27
+ },
23
28
  {
24
29
  languageOptions: {
25
30
  globals: {
@@ -0,0 +1,12 @@
1
+ port: '4001'
2
+ mode: 'git'
3
+ local-path: '..\..\files'
4
+ log-level: 'debug'
5
+ apollo-path: '/lib'
6
+ graphql-playground: 'true'
7
+
8
+ git-repos:
9
+ - user-1:
10
+ repo-url: 'https://github.com/isomorphic-git/lightning-fs'
11
+ - user-2:
12
+ repo-url: 'https://github.com/isomorphic-git/lightning-fs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@into-cps-association/libms",
3
- "version": "0.4.7",
3
+ "version": "0.5.1",
4
4
  "description": "microservices that handles request by fetching and returning the file-names and folders of given directory",
5
5
  "author": "phillip.boe.jensen@gmail.com",
6
6
  "contributors": [
@@ -24,14 +24,14 @@
24
24
  "syntax": "eslint . --fix",
25
25
  "pretest": "npx shx cp test/data/user2/tools/README.md ../../files/user2/tools/README.md",
26
26
  "posttest": "npx rimraf ../../files/user2/tools/README.md",
27
- "test:all": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LOCAL_PATH=test/data jest --testPathIgnorePatterns=cloudcmd --coverage",
28
- "test:e2e": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LOCAL_PATH=test/data jest --config ./test/jest-e2e.json --coverage",
27
+ "test:all": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LIBMS_CONFIG_PATH=test/libms.test.yaml jest --testPathIgnorePatterns=cloudcmd --coverage",
28
+ "test:e2e": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LIBMS_CONFIG_PATH=test/libms.test.yaml jest --config ./test/jest-e2e.json --coverage",
29
29
  "test:http": "yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage --coverageThreshold=\"{}\" && pm2 delete libms-test",
30
30
  "test:http-nocov": "yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage=false && pm2 delete libms-test",
31
31
  "test:http-github": "jest test/cloudcmd --coverage --coverageThreshold=\"{}\"",
32
- "test:int": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LOCAL_PATH=test/data jest ../test/integration --coverage",
33
- "test:nocov": "yarn test:http-nocov && npx cross-env LOCAL_PATH=test/data jest --testPathIgnorePatterns=cloudcmd --coverage=false",
34
- "test:unit": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LOCAL_PATH=test/data jest ../test/unit --coverage"
32
+ "test:int": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LIBMS_CONFIG_PATH=test/libms.test.yaml jest ../test/integration --coverage",
33
+ "test:nocov": "yarn test:http-nocov && npx cross-env LIBMS_CONFIG_PATH=test/libms.test.yaml jest --testPathIgnorePatterns=cloudcmd --coverage=false",
34
+ "test:unit": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LIBMS_CONFIG_PATH=test/libms.test.yaml jest ../test/unit --coverage"
35
35
  },
36
36
  "bin": "./dist/src/main.js",
37
37
  "dependencies": {
@@ -47,8 +47,10 @@
47
47
  "cloudcmd": "^18.1.0",
48
48
  "commander": "^12.1.0",
49
49
  "dotenv": "^16.4.5",
50
- "globals": "^15.9.0",
50
+ "globals": "^15.11.0",
51
51
  "graphql": "^16.9.0",
52
+ "isomorphic-git": "^1.27.1",
53
+ "js-yaml": "^4.1.0",
52
54
  "mock-fs": "^5.3.0",
53
55
  "reflect-metadata": "^0.2.2",
54
56
  "rxjs": "^7.8.1",
@@ -56,7 +58,7 @@
56
58
  "type-graphql": "^2.0.0-rc.2"
57
59
  },
58
60
  "devDependencies": {
59
- "@eslint/compat": "^1.1.1",
61
+ "@eslint/compat": "^1.2.2",
60
62
  "@eslint/eslintrc": "^3.1.0",
61
63
  "@nestjs/cli": "^10.4.5",
62
64
  "@nestjs/schematics": "^10.1.4",
@@ -65,8 +67,8 @@
65
67
  "@types/jest": "^29.5.13",
66
68
  "@types/node": "22.7.0",
67
69
  "@types/supertest": "^6.0.2",
68
- "@typescript-eslint/eslint-plugin": "^8.8.0",
69
- "@typescript-eslint/parser": "^8.8.0",
70
+ "@typescript-eslint/eslint-plugin": "^8.12.2",
71
+ "@typescript-eslint/parser": "^8.12.2",
70
72
  "cross-fetch": "^4.0.0",
71
73
  "eslint": "^9.11.1",
72
74
  "eslint-config-airbnb-base": "^15.0.0",
@@ -82,6 +84,7 @@
82
84
  "ts-jest": "^29.2.5",
83
85
  "ts-node": "^10.9.2",
84
86
  "tsconfig-paths": "4.2.0",
85
- "typescript": "^5.6.2"
87
+ "typescript": "^5.6.3",
88
+ "@types/js-yaml": "^4.0.9"
86
89
  }
87
90
  }
package/src/app.module.ts CHANGED
@@ -1,22 +1,21 @@
1
- import { ConfigModule, ConfigService } from '@nestjs/config';
2
1
  import { Module } from '@nestjs/common';
3
2
  import { GraphQLModule } from '@nestjs/graphql';
4
3
  import { ApolloDriver } from '@nestjs/apollo';
5
4
  import { join } from 'path';
6
5
  import FilesModule from './files/files.module.js';
6
+ import { ConfigModule } from './config/config.module.js';
7
+ import { CONFIG_SERVICE, IConfig } from './config/config.interface.js';
7
8
 
8
9
  @Module({
9
10
  imports: [
10
- ConfigModule.forRoot({
11
- isGlobal: true,
12
- }),
11
+ ConfigModule,
13
12
  GraphQLModule.forRootAsync({
14
13
  driver: ApolloDriver,
15
- useFactory: (configService: ConfigService) => ({
14
+ useFactory: (configService: IConfig) => ({
16
15
  autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
17
- path: configService.get<string>('APOLLO_PATH'),
16
+ path: configService.getApolloPath(),
18
17
  }),
19
- inject: [ConfigService],
18
+ inject: [CONFIG_SERVICE],
20
19
  }),
21
20
  FilesModule,
22
21
  ],
package/src/bootstrap.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { NestFactory } from '@nestjs/core';
2
- import { ConfigService } from '@nestjs/config';
3
- import * as dotenv from 'dotenv';
4
2
  import AppModule from './app.module.js';
5
3
  import cloudCMD from './cloudcmd/cloudcmd.js';
4
+ import { Logger } from '@nestjs/common';
5
+ import { CONFIG_SERVICE, IConfig } from './config/config.interface.js';
6
6
 
7
7
  type BootstrapOptions = {
8
8
  config?: string;
@@ -11,26 +11,23 @@ type BootstrapOptions = {
11
11
  };
12
12
 
13
13
  export default async function bootstrap(options?: BootstrapOptions) {
14
- const configFile = dotenv.config({
15
- path: options?.config ?? '.env',
16
- override: true,
17
- });
18
- if (configFile.error && process.env.LOCAL_PATH === undefined) {
19
- // eslint-disable-next-line no-console
20
- console.error(configFile.error);
21
- if (options.runHelp) {
22
- options.runHelp();
23
- } else {
24
- process.exit(1);
25
- }
26
- }
14
+ const logger = new Logger(bootstrap.name);
15
+
16
+ if (process.env.LIBMS_CONFIG_PATH == null)
17
+ process.env.LIBMS_CONFIG_PATH = options.config ?? 'libms.yaml';
27
18
 
28
19
  const app = await NestFactory.create(AppModule);
29
- const configService = app.get(ConfigService);
30
- const port = configService.get<number>('PORT');
20
+ const configService = app.get(CONFIG_SERVICE) as IConfig;
21
+ const port = configService.getPort();
22
+ const localPath = configService.getLocalPath();
23
+ const mode = configService.getMode();
24
+
25
+ logger.log(
26
+ `\x1b[32mStarting libms in \x1b[33m${mode} \x1b[32mmode, serving files from \x1b[34m${localPath} \x1b[32mon port \x1b[35m${port}\x1b[0m`,
27
+ );
31
28
 
32
29
  if (options.httpServer) {
33
- cloudCMD(app, options.httpServer, configService.get<string>('LOCAL_PATH'));
30
+ cloudCMD(app, options.httpServer, configService.getLocalPath());
34
31
  }
35
32
 
36
33
  await app.listen(port);
@@ -0,0 +1,14 @@
1
+ import { GitRepo } from './config.model';
2
+
3
+ export const CONFIG_SERVICE = 'CONFIG_SERVICE';
4
+
5
+ export interface IConfig {
6
+ loadConfig(configPath: string): Promise<void>;
7
+ getLocalPath(): string;
8
+ getApolloPath(): string;
9
+ getMode(): string;
10
+ getPort(): number;
11
+ getLogLevel(): string;
12
+ getGraphqlPlayground(): string;
13
+ getGitRepos(): { [key: string]: GitRepo }[];
14
+ }
@@ -0,0 +1,13 @@
1
+ export type ConfigValues = {
2
+ port: number;
3
+ 'local-path': string;
4
+ mode: string;
5
+ 'log-level': string;
6
+ 'apollo-path': string;
7
+ 'graphql-playground': string;
8
+ 'git-repos': { [key: string]: GitRepo }[];
9
+ };
10
+
11
+ export type GitRepo = {
12
+ 'repo-url': string;
13
+ };
@@ -0,0 +1,23 @@
1
+ import { Global, Module } from '@nestjs/common';
2
+ import * as nestConfig from '@nestjs/config';
3
+ import Config from './config.service.js';
4
+ import { CONFIG_SERVICE } from './config.interface.js';
5
+
6
+ @Global()
7
+ @Module({
8
+ imports: [nestConfig.ConfigModule.forRoot({ isGlobal: true })],
9
+ providers: [
10
+ {
11
+ provide: CONFIG_SERVICE,
12
+ useFactory: async (envConfigservice: nestConfig.ConfigService) => {
13
+ const confPath = envConfigservice.get<string>('LIBMS_CONFIG_PATH');
14
+ const config = new Config();
15
+ await config.loadConfig(confPath);
16
+ return config;
17
+ },
18
+ inject: [nestConfig.ConfigService],
19
+ },
20
+ ],
21
+ exports: [CONFIG_SERVICE],
22
+ })
23
+ export class ConfigModule {}
@@ -0,0 +1,54 @@
1
+ import { readFileSync } from 'fs';
2
+ import * as yaml from 'js-yaml';
3
+ import { Injectable, Logger } from '@nestjs/common';
4
+ import { ConfigValues, GitRepo } from './config.model.js';
5
+ import resolveFile from './util.js';
6
+ import { IConfig } from './config.interface.js';
7
+
8
+ @Injectable()
9
+ export default class Config implements IConfig {
10
+ private configValues: ConfigValues;
11
+ private logger: Logger;
12
+
13
+ constructor() {
14
+ this.logger = new Logger(Config.name);
15
+ }
16
+
17
+ async loadConfig(configPath: string): Promise<void> {
18
+ if (configPath !== undefined) {
19
+ try {
20
+ const configFile = readFileSync(resolveFile(configPath), 'utf8');
21
+ this.configValues = yaml.load(configFile) as ConfigValues;
22
+ } catch (e) {
23
+ this.logger.error('Error loading config file', e);
24
+ process.exit(1);
25
+ }
26
+ }
27
+ this.logger.log('Config loaded', this.configValues);
28
+ }
29
+
30
+ getLocalPath(): string {
31
+ return this.configValues['local-path'];
32
+ }
33
+
34
+ getApolloPath(): string {
35
+ return this.configValues['apollo-path'];
36
+ }
37
+
38
+ getMode(): string {
39
+ return this.configValues['mode'];
40
+ }
41
+
42
+ getPort(): number {
43
+ return this.configValues['port'];
44
+ }
45
+ getLogLevel(): string {
46
+ return this.configValues['log-level'];
47
+ }
48
+ getGraphqlPlayground(): string {
49
+ return this.configValues['graphql-playground'];
50
+ }
51
+ getGitRepos(): { [key: string]: GitRepo }[] {
52
+ return this.configValues['git-repos'];
53
+ }
54
+ }
@@ -0,0 +1,5 @@
1
+ import path from 'node:path';
2
+
3
+ export default function resolveFile(name: string): string {
4
+ return path.resolve(name);
5
+ }
@@ -1,18 +1,20 @@
1
1
  import { Injectable } from '@nestjs/common';
2
- import { ConfigService } from '@nestjs/config';
3
2
  import { IFilesService } from './interfaces/files.service.interface.js';
3
+ import { IConfig } from 'src/config/config.interface.js';
4
4
 
5
5
  @Injectable()
6
6
  export default class FilesServiceFactory {
7
7
  static create(
8
- configService: ConfigService,
8
+ configService: IConfig,
9
9
  fileServices: IFilesService[],
10
10
  ): IFilesService {
11
- const mode = configService.get<string>('MODE');
11
+ const mode = configService.getMode();
12
12
  const service = fileServices.find((s) => s.getMode() == mode);
13
13
 
14
14
  if (service == undefined) {
15
15
  throw new Error(`Invalid MODE: ${mode}`);
16
+ } else {
17
+ service.init();
16
18
  }
17
19
  return service;
18
20
  }
@@ -6,7 +6,7 @@ import LocalFilesService from './local/local-files.service.js';
6
6
  import GitFilesService from './git/git-files.service.js';
7
7
  import { FILE_SERVICE } from './interfaces/files.service.interface.js';
8
8
  import FilesServiceFactory from './files-service.factory.js';
9
- import { ConfigService } from '@nestjs/config';
9
+ import { CONFIG_SERVICE, IConfig } from '../config/config.interface.js';
10
10
 
11
11
  @Module({
12
12
  imports: [LocalFilesModule, GitFilesModule],
@@ -15,14 +15,14 @@ import { ConfigService } from '@nestjs/config';
15
15
  {
16
16
  provide: FILE_SERVICE,
17
17
  useFactory: (
18
- configService: ConfigService,
18
+ configService: IConfig,
19
19
  localFilesService: LocalFilesService,
20
20
  gitFilesService: GitFilesService,
21
21
  ) => {
22
22
  const fileServices = [localFilesService, gitFilesService];
23
23
  return FilesServiceFactory.create(configService, fileServices);
24
24
  },
25
- inject: [ConfigService, LocalFilesService, GitFilesService],
25
+ inject: [CONFIG_SERVICE, LocalFilesService, GitFilesService],
26
26
  },
27
27
  ],
28
28
  })
@@ -1,8 +1,9 @@
1
1
  import { Module } from '@nestjs/common';
2
2
  import GitFilesService from './git-files.service.js';
3
+ import LocalFilesService from '../local/local-files.service.js';
3
4
 
4
5
  @Module({
5
- providers: [GitFilesService],
6
+ providers: [GitFilesService, LocalFilesService],
6
7
  exports: [GitFilesService],
7
8
  })
8
9
  export class GitFilesModule {}
@@ -1,20 +1,65 @@
1
- import { Injectable } from '@nestjs/common';
1
+ import { Inject, Injectable, Logger } from '@nestjs/common';
2
2
  import { Project } from 'src/types.js';
3
3
  import { IFilesService } from '../interfaces/files.service.interface.js';
4
4
  import { CONFIG_MODE } from '../../enums/config-mode.enum.js';
5
+ import * as git from 'isomorphic-git';
6
+ import * as fs from 'fs';
7
+ import * as http from 'isomorphic-git/http/node/index.cjs';
8
+ import LocalFilesService from '../local/local-files.service.js';
9
+ import Config from '../../config/config.service.js';
10
+ import { CONFIG_SERVICE } from '../../config/config.interface.js';
11
+ import path from 'path';
5
12
 
6
13
  @Injectable()
7
14
  export default class GitFilesService implements IFilesService {
8
- // eslint-disable-next-line no-useless-constructor, no-empty-function
9
- constructor() {}
15
+ private readonly dataPath: string;
16
+ private readonly logger: Logger;
17
+ @Inject(LocalFilesService) private localFilesService: LocalFilesService;
18
+
19
+ constructor(@Inject(CONFIG_SERVICE) private configService: Config) {
20
+ this.dataPath = this.configService.getLocalPath();
21
+ this.logger = new Logger(GitFilesService.name);
22
+ }
23
+
24
+ init(): Promise<any> {
25
+ return this.cloneRepositories();
26
+ }
27
+
28
+ private cloneRepositories(): Promise<void[]> {
29
+ const userRepoConfigs = this.configService.getGitRepos();
30
+
31
+ if (!userRepoConfigs || userRepoConfigs.length === 0) {
32
+ throw new Error('No git repos found in config');
33
+ }
34
+
35
+ const clonePromises = userRepoConfigs.map((repoConf) => {
36
+ const user = Object.keys(repoConf)[0];
37
+ const repoUrl = repoConf[user]['repo-url'];
38
+
39
+ return git
40
+ .clone({
41
+ fs,
42
+ http,
43
+ dir: this.dataPath + `/${user}`,
44
+ gitdir: path.join(this.dataPath, 'gitdir', user, '.git'),
45
+ url: repoUrl.includes('.git') ? repoUrl : repoUrl + '.git',
46
+ singleBranch: true,
47
+ depth: 1,
48
+ })
49
+ .then(() => this.logger.log('done cloning ' + repoUrl));
50
+ });
51
+ return Promise.all(clonePromises);
52
+ }
53
+
10
54
  getMode(): CONFIG_MODE {
11
55
  return CONFIG_MODE.GIT;
12
56
  }
13
57
 
14
- listDirectory(): Promise<Project> {
15
- throw new Error('Method not implemented.');
58
+ listDirectory(path: string): Promise<Project> {
59
+ return this.localFilesService.listDirectory(path);
16
60
  }
17
- readFile(): Promise<Project> {
18
- throw new Error('Method not implemented.');
61
+
62
+ readFile(path: string): Promise<Project> {
63
+ return this.localFilesService.readFile(path);
19
64
  }
20
65
  }
@@ -7,4 +7,5 @@ export interface IFilesService {
7
7
  listDirectory(path: string): Promise<Project>;
8
8
  readFile(path: string): Promise<Project>;
9
9
  getMode(): CONFIG_MODE;
10
+ init(): Promise<any>;
10
11
  }
@@ -1,19 +1,28 @@
1
- import { Injectable, InternalServerErrorException } from '@nestjs/common';
1
+ import {
2
+ Inject,
3
+ Injectable,
4
+ InternalServerErrorException,
5
+ } from '@nestjs/common';
2
6
  import * as fs from 'fs';
3
7
  import { join } from 'path';
4
- import { ConfigService } from '@nestjs/config';
5
8
  import { Project } from 'src/types.js';
6
9
  import { IFilesService } from '../interfaces/files.service.interface.js';
7
10
  import { CONFIG_MODE } from '../../enums/config-mode.enum.js';
11
+ import Config from '../../config/config.service.js';
12
+ import { CONFIG_SERVICE } from '../../config/config.interface.js';
8
13
 
9
14
  @Injectable()
10
15
  export default class LocalFilesService implements IFilesService {
11
16
  private readonly dataPath: string;
12
17
 
13
- constructor(private configService: ConfigService) {
14
- this.dataPath = this.configService.get('LOCAL_PATH');
18
+ constructor(@Inject(CONFIG_SERVICE) private configService: Config) {
19
+ this.dataPath = this.configService.getLocalPath();
20
+ }
15
21
 
22
+ init(): Promise<any> {
23
+ return Promise.resolve();
16
24
  }
25
+
17
26
  getMode(): CONFIG_MODE {
18
27
  return CONFIG_MODE.LOCAL;
19
28
  }
package/src/main.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { Command } from 'commander';
3
3
  import bootstrap from './bootstrap.js';
4
4
 
5
- type ProgramOptions = {
5
+ export type ProgramOptions = {
6
6
  config?: string;
7
7
  http?: string;
8
8
  };
@@ -7,9 +7,9 @@ describe('cloudcmd test for the application', () => {
7
7
  config();
8
8
 
9
9
  await writeFile(`${process.env.LOCAL_PATH}/test.txt`, 'content12345');
10
- // eslint-disable-next-line no-promise-executor-return
11
- await new Promise((resolve) => setTimeout(resolve, 8000));
12
- }, 10000);
10
+
11
+ await new Promise((resolve) => setTimeout(resolve, 50000)); // This is problematic.
12
+ }, 55000);
13
13
 
14
14
  afterAll(async () => {
15
15
  await unlink(`${process.env.LOCAL_PATH}/test.txt`);
@@ -30,7 +30,7 @@ describe('cloudcmd test for the application', () => {
30
30
  expect(fileNames).toContain('user2');
31
31
  }, 10000);
32
32
 
33
- it('should return the content of a file that is uplaoded to cloudcmd ', async () => {
33
+ it('should return the content of a file that is uplaoded to cloudcmd', async () => {
34
34
  const response = await axios.get(
35
35
  `http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}/files/api/v1/fs/test.txt`,
36
36
  );