@into-cps-association/libms 0.3.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 (109) hide show
  1. package/.env +9 -0
  2. package/.eslintignore +6 -0
  3. package/.eslintrc +53 -0
  4. package/.madgerc +18 -0
  5. package/.prettierrc +4 -0
  6. package/API.md +211 -0
  7. package/DEVELOPER.md +60 -0
  8. package/LICENSE.md +301 -0
  9. package/README.md +119 -0
  10. package/dist/src/app.module.d.ts +2 -0
  11. package/dist/src/app.module.js +36 -0
  12. package/dist/src/app.module.js.map +1 -0
  13. package/dist/src/bootstrap.d.ts +6 -0
  14. package/dist/src/bootstrap.js +27 -0
  15. package/dist/src/bootstrap.js.map +1 -0
  16. package/dist/src/files/files.module.d.ts +2 -0
  17. package/dist/src/files/files.module.js +27 -0
  18. package/dist/src/files/files.module.js.map +1 -0
  19. package/dist/src/files/interfaces/files.service.interface.d.ts +5 -0
  20. package/dist/src/files/interfaces/files.service.interface.js +3 -0
  21. package/dist/src/files/interfaces/files.service.interface.js.map +1 -0
  22. package/dist/src/files/queries.d.ts +2 -0
  23. package/dist/src/files/queries.js +47 -0
  24. package/dist/src/files/queries.js.map +1 -0
  25. package/dist/src/files/resolvers/files.resolver.d.ts +8 -0
  26. package/dist/src/files/resolvers/files.resolver.js +49 -0
  27. package/dist/src/files/resolvers/files.resolver.js.map +1 -0
  28. package/dist/src/files/services/files-service.factory.d.ts +11 -0
  29. package/dist/src/files/services/files-service.factory.js +48 -0
  30. package/dist/src/files/services/files-service.factory.js.map +1 -0
  31. package/dist/src/files/services/gitlab-files.service.d.ts +12 -0
  32. package/dist/src/files/services/gitlab-files.service.js +65 -0
  33. package/dist/src/files/services/gitlab-files.service.js.map +1 -0
  34. package/dist/src/files/services/local-files.service.d.ts +11 -0
  35. package/dist/src/files/services/local-files.service.js +77 -0
  36. package/dist/src/files/services/local-files.service.js.map +1 -0
  37. package/dist/src/main.d.ts +2 -0
  38. package/dist/src/main.js +20 -0
  39. package/dist/src/main.js.map +1 -0
  40. package/dist/src/types.d.ts +43 -0
  41. package/dist/src/types.js +181 -0
  42. package/dist/src/types.js.map +1 -0
  43. package/dist/test/e2e/app.e2e.spec.d.ts +1 -0
  44. package/dist/test/e2e/app.e2e.spec.js +36 -0
  45. package/dist/test/e2e/app.e2e.spec.js.map +1 -0
  46. package/dist/test/integration/files.service.integration.spec.d.ts +1 -0
  47. package/dist/test/integration/files.service.integration.spec.js +53 -0
  48. package/dist/test/integration/files.service.integration.spec.js.map +1 -0
  49. package/dist/test/testUtil.d.ts +88 -0
  50. package/dist/test/testUtil.js +182 -0
  51. package/dist/test/testUtil.js.map +1 -0
  52. package/dist/test/unit/files-service.factory.unit.spec.d.ts +1 -0
  53. package/dist/test/unit/files-service.factory.unit.spec.js +40 -0
  54. package/dist/test/unit/files-service.factory.unit.spec.js.map +1 -0
  55. package/dist/test/unit/files.resolver.unit.spec.d.ts +1 -0
  56. package/dist/test/unit/files.resolver.unit.spec.js +56 -0
  57. package/dist/test/unit/files.resolver.unit.spec.js.map +1 -0
  58. package/dist/test/unit/gitlab-files.service.unit.spec.d.ts +1 -0
  59. package/dist/test/unit/gitlab-files.service.unit.spec.js +37 -0
  60. package/dist/test/unit/gitlab-files.service.unit.spec.js.map +1 -0
  61. package/dist/test/unit/local-files.service.unit.spec.d.ts +1 -0
  62. package/dist/test/unit/local-files.service.unit.spec.js +84 -0
  63. package/dist/test/unit/local-files.service.unit.spec.js.map +1 -0
  64. package/dist/tsconfig.tsbuildinfo +1 -0
  65. package/jest.config.json +30 -0
  66. package/nest-cli.json +8 -0
  67. package/package.json +71 -0
  68. package/src/app.module.ts +24 -0
  69. package/src/bootstrap.ts +29 -0
  70. package/src/files/files.module.ts +15 -0
  71. package/src/files/interfaces/files.service.interface.ts +7 -0
  72. package/src/files/queries.ts +42 -0
  73. package/src/files/resolvers/files.resolver.ts +23 -0
  74. package/src/files/services/files-service.factory.ts +27 -0
  75. package/src/files/services/gitlab-files.service.ts +65 -0
  76. package/src/files/services/local-files.service.ts +76 -0
  77. package/src/main.ts +27 -0
  78. package/src/schema.gql +58 -0
  79. package/src/types.ts +92 -0
  80. package/test/README.md +33 -0
  81. package/test/coverage/clover.xml +40 -0
  82. package/test/coverage/coverage-final.json +2 -0
  83. package/test/coverage/lcov-report/base.css +224 -0
  84. package/test/coverage/lcov-report/block-navigation.js +87 -0
  85. package/test/coverage/lcov-report/favicon.png +0 -0
  86. package/test/coverage/lcov-report/index.html +116 -0
  87. package/test/coverage/lcov-report/prettify.css +1 -0
  88. package/test/coverage/lcov-report/prettify.js +2 -0
  89. package/test/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  90. package/test/coverage/lcov-report/sorter.js +196 -0
  91. package/test/coverage/lcov-report/testUtil.ts.html +655 -0
  92. package/test/coverage/lcov.info +52 -0
  93. package/test/data/user2/data/.gitkeep +0 -0
  94. package/test/data/user2/digital_twins/.gitkeep +0 -0
  95. package/test/data/user2/functions/.gitkeep +0 -0
  96. package/test/data/user2/models/.gitkeep +0 -0
  97. package/test/data/user2/tools/.gitkeep +0 -0
  98. package/test/data/user2/tools/README.md +1 -0
  99. package/test/e2e/app.e2e.spec.ts +79 -0
  100. package/test/integration/files.service.integration.spec.ts +67 -0
  101. package/test/jest-e2e.json +9 -0
  102. package/test/starttraefik.bash +11 -0
  103. package/test/stoptraefik.bash +9 -0
  104. package/test/testUtil.ts +190 -0
  105. package/test/unit/files-service.factory.unit.spec.ts +46 -0
  106. package/test/unit/files.resolver.unit.spec.ts +70 -0
  107. package/test/unit/gitlab-files.service.unit.spec.ts +46 -0
  108. package/test/unit/local-files.service.unit.spec.ts +108 -0
  109. package/tsconfig.json +31 -0
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@into-cps-association/libms",
3
+ "version": "0.3.1",
4
+ "description": "microservices that handles request by fetching and returning the file-names and folders of given directory",
5
+ "author": "phillip.boe.jensen@gmail.com",
6
+ "contributors": [
7
+ "Prasad Talasila",
8
+ "Mads Kelberg",
9
+ "Linda Nguyen"
10
+ ],
11
+ "private": false,
12
+ "license": "SEE LICENSE IN <LICENSE.md>",
13
+ "scripts": {
14
+ "build": "npx tsc",
15
+ "clean": "npx rimraf build node_modules coverage dist src.svg test.svg",
16
+ "format": "prettier --ignore-path ../.gitignore --write \"**/*.{ts,tsx,css,scss}\"",
17
+ "graph": "npx madge --image src.svg src && npx madge --image test.svg test",
18
+ "start": "node dist/src/main.js",
19
+ "syntax": "npx eslint . --fix",
20
+ "pretest": "npx shx cp test/data/user2/tools/README.md ../../files/user2/tools/README.md",
21
+ "test:all": "jest --coverage",
22
+ "test:e2e": "npx shx cp test/data/user2/tools/README.md ../../files/user2/tools/ && npx cross-env TEST_PATH=test/data jest --config ./test/jest-e2e.json --coverage && npx rimraf ../../files/user2/tools/README.md",
23
+ "test:int": "npx shx cp test/data/user2/tools/README.md ../../files/user2/tools/ && npx cross-env TEST_PATH=test/data jest ../test/integration --coverage && npx rimraf ../../files/user2/tools/README.md",
24
+ "test:unit": "npx shx cp test/data/user2/tools/README.md ../../files/user2/tools/ && npx cross-env TEST_PATH=test/data jest ../test/unit --coverage && npx rimraf ../../files/user2/tools/README.md"
25
+ },
26
+ "bin": "./dist/src/main.js",
27
+ "dependencies": {
28
+ "@apollo/client": "^3.8.4",
29
+ "@apollo/server": "^4.9.3",
30
+ "@nestjs/apollo": "^12.0.9",
31
+ "@nestjs/common": "^10.2.6",
32
+ "@nestjs/config": "^3.1.1",
33
+ "@nestjs/core": "^10.2.6",
34
+ "@nestjs/graphql": "^12.0.9",
35
+ "@nestjs/platform-express": "^10.2.6",
36
+ "axios": "^1.5.1",
37
+ "commander": "^11.1.0",
38
+ "dotenv": "^16.3.1",
39
+ "express": "^4.18.2",
40
+ "graphql": "^16.8.1",
41
+ "mock-fs": "^5.2.0",
42
+ "reflect-metadata": "^0.1.13",
43
+ "rxjs": "^7.8.1",
44
+ "type-graphql": "^2.0.0-beta.3"
45
+ },
46
+ "devDependencies": {
47
+ "@nestjs/cli": "^10.1.18",
48
+ "@nestjs/schematics": "^10.0.2",
49
+ "@nestjs/testing": "^10.2.6",
50
+ "@types/express": "^4.17.18",
51
+ "@types/jest": "^29.5.5",
52
+ "@types/node": "20.7.2",
53
+ "@types/supertest": "^2.0.13",
54
+ "@typescript-eslint/eslint-plugin": "^6.7.3",
55
+ "@typescript-eslint/parser": "^6.7.3",
56
+ "eslint": "^8.50.0",
57
+ "eslint-config-airbnb-base": "^15.0.0",
58
+ "eslint-config-prettier": "^9.0.0",
59
+ "eslint-plugin-import": "^2.28.1",
60
+ "eslint-plugin-jest": "^27.4.0",
61
+ "eslint-plugin-prettier": "^5.0.0",
62
+ "graphql-scalars": "^1.22.2",
63
+ "jest": "29.7.0",
64
+ "prettier": "^3.0.3",
65
+ "supertest": "^6.3.3",
66
+ "ts-jest": "^29.1.1",
67
+ "ts-node": "^10.9.1",
68
+ "tsconfig-paths": "4.2.0",
69
+ "typescript": "^5.2.2"
70
+ }
71
+ }
@@ -0,0 +1,24 @@
1
+ import { ConfigModule, ConfigService } from '@nestjs/config';
2
+ import { Module } from '@nestjs/common';
3
+ import { GraphQLModule } from '@nestjs/graphql';
4
+ import { ApolloDriver } from '@nestjs/apollo';
5
+ import { join } from 'path';
6
+ import FilesModule from './files/files.module';
7
+
8
+ @Module({
9
+ imports: [
10
+ ConfigModule.forRoot({
11
+ isGlobal: true,
12
+ }),
13
+ GraphQLModule.forRootAsync({
14
+ driver: ApolloDriver,
15
+ useFactory: (configService: ConfigService) => ({
16
+ autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
17
+ path: configService.get<string>('APOLLO_PATH'),
18
+ }),
19
+ inject: [ConfigService],
20
+ }),
21
+ FilesModule,
22
+ ],
23
+ })
24
+ export default class AppModule {}
@@ -0,0 +1,29 @@
1
+ import { NestFactory } from '@nestjs/core';
2
+ import { ConfigService } from '@nestjs/config';
3
+ import * as dotenv from 'dotenv';
4
+ import AppModule from './app.module';
5
+
6
+ type BootstrapOptions = {
7
+ config?: string;
8
+ runHelp?: CallableFunction;
9
+ };
10
+
11
+ export default async function bootstrap(options?: BootstrapOptions) {
12
+ const configFile = dotenv.config({
13
+ path: options?.config ?? '.env',
14
+ override: true,
15
+ });
16
+ if (configFile.error) {
17
+ // eslint-disable-next-line no-console
18
+ console.error(configFile.error);
19
+ if (options.runHelp) {
20
+ options.runHelp();
21
+ } else {
22
+ process.exit(1);
23
+ }
24
+ }
25
+ const app = await NestFactory.create(AppModule);
26
+ const configService = app.get(ConfigService);
27
+ const port = configService.get<number>('PORT');
28
+ await app.listen(port);
29
+ }
@@ -0,0 +1,15 @@
1
+ import { Module } from '@nestjs/common';
2
+ import FilesResolver from './resolvers/files.resolver';
3
+ import GitlabFilesService from './services/gitlab-files.service';
4
+ import FilesServiceFactory from './services/files-service.factory';
5
+ import LocalFilesService from './services/local-files.service';
6
+
7
+ @Module({
8
+ providers: [
9
+ FilesResolver,
10
+ LocalFilesService,
11
+ GitlabFilesService,
12
+ FilesServiceFactory,
13
+ ],
14
+ })
15
+ export default class FilesModule {}
@@ -0,0 +1,7 @@
1
+ import { Project } from 'src/types';
2
+
3
+ // FileService interface
4
+ export interface IFilesService {
5
+ listDirectory(path: string): Promise<Project>;
6
+ readFile(path: string): Promise<Project>;
7
+ }
@@ -0,0 +1,42 @@
1
+ export const getDirectoryQuery = (domain: string, parsedPath: string) => `
2
+ query listDirectory {
3
+ project(fullPath: "${domain}") {
4
+ repository {
5
+ tree(path: "${parsedPath}", recursive: false) {
6
+ blobs {
7
+ edges {
8
+ node {
9
+ name
10
+ type
11
+ }
12
+ }
13
+ }
14
+ trees {
15
+ edges {
16
+ node {
17
+ name
18
+ type
19
+ }
20
+ }
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ `;
27
+
28
+ export const getReadFileQuery = (domain: string, parsedPath: string) => `
29
+ query readFile {
30
+ project(fullPath: "${domain}") {
31
+ repository {
32
+ blobs(paths: "${parsedPath}") {
33
+ nodes {
34
+ name
35
+ rawBlob
36
+ rawTextBlob
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+ `;
@@ -0,0 +1,23 @@
1
+ import { Resolver, Query, Args } from '@nestjs/graphql';
2
+ import { IFilesService } from '../interfaces/files.service.interface';
3
+ import FilesServiceFactory from '../services/files-service.factory';
4
+ import { Project } from '../../types';
5
+
6
+ @Resolver()
7
+ export default class FilesResolver {
8
+ private readonly filesService: IFilesService;
9
+
10
+ constructor(filesServiceFactory: FilesServiceFactory) {
11
+ this.filesService = filesServiceFactory.create();
12
+ }
13
+
14
+ @Query(() => Project)
15
+ async listDirectory(@Args('path') path: string): Promise<Project> {
16
+ return this.filesService.listDirectory(path);
17
+ }
18
+
19
+ @Query(() => Project)
20
+ async readFile(@Args('path') path: string): Promise<Project> {
21
+ return this.filesService.readFile(path);
22
+ }
23
+ }
@@ -0,0 +1,27 @@
1
+ import { Injectable, Inject } from '@nestjs/common';
2
+ import { ConfigService } from '@nestjs/config';
3
+ import { IFilesService } from '../interfaces/files.service.interface';
4
+ import GitlabFilesService from './gitlab-files.service';
5
+ import LocalFilesService from './local-files.service';
6
+
7
+ @Injectable()
8
+ export default class FilesServiceFactory {
9
+ /* eslint-disable no-useless-constructor, no-empty-function */
10
+ constructor(
11
+ private configService: ConfigService,
12
+ @Inject(GitlabFilesService) private gitlabFilesService: GitlabFilesService,
13
+ @Inject(LocalFilesService) private localFilesService: LocalFilesService,
14
+ ) {}
15
+ /* eslint-enable no-useless-constructor, no-empty-function */
16
+
17
+ create(): IFilesService {
18
+ const mode = this.configService.get<string>('MODE');
19
+ if (mode === 'local') {
20
+ return this.localFilesService;
21
+ }
22
+ if (mode === 'gitlab') {
23
+ return this.gitlabFilesService;
24
+ }
25
+ throw new Error(`Invalid MODE: ${mode}`);
26
+ }
27
+ }
@@ -0,0 +1,65 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { ConfigService } from '@nestjs/config';
3
+ import axios from 'axios';
4
+ import { Project } from 'src/types';
5
+ import { IFilesService } from '../interfaces/files.service.interface';
6
+ import { getDirectoryQuery, getReadFileQuery } from '../queries';
7
+
8
+ type QueryFunction = (domain: string, parsedPath: string) => string;
9
+
10
+ @Injectable()
11
+ export default class GitlabFilesService implements IFilesService {
12
+ // eslint-disable-next-line no-useless-constructor, no-empty-function
13
+ constructor(private configService: ConfigService) {}
14
+
15
+ async listDirectory(path: string): Promise<Project> {
16
+ return this.executeQuery(path, getDirectoryQuery);
17
+ }
18
+
19
+ async readFile(path: string): Promise<Project> {
20
+ return this.executeQuery(path, getReadFileQuery);
21
+ }
22
+
23
+ private async parseArguments(
24
+ path: string,
25
+ ): Promise<{ domain: string; parsedPath: string }> {
26
+ const gitlabGroup = this.configService.get('GITLAB_GROUP');
27
+ const pathParts: string[] = path.split('/');
28
+ const project: string = pathParts[0];
29
+
30
+ // Only prepend the gitlabGroup if it's not already part of the path
31
+ const domain: string =
32
+ project === gitlabGroup ? project : `${gitlabGroup}/${project}`;
33
+
34
+ const parsedPath = pathParts.slice(1).join('/');
35
+ return { domain, parsedPath };
36
+ }
37
+
38
+ private async sendRequest(query: string): Promise<Project> {
39
+ try {
40
+ const response = await axios({
41
+ url: 'https://gitlab.com/api/graphql',
42
+ method: 'post',
43
+ headers: {
44
+ 'Content-Type': 'application/json',
45
+ Authorization: `Bearer ${this.configService.get('GITLAB_TOKEN')}`,
46
+ },
47
+ data: {
48
+ query,
49
+ },
50
+ });
51
+ return response.data.data.project;
52
+ } catch (error) {
53
+ throw new Error('Invalid query'); // Throw error instead of returning string
54
+ }
55
+ }
56
+
57
+ private async executeQuery(
58
+ path: string,
59
+ getQuery: QueryFunction,
60
+ ): Promise<Project> {
61
+ const { domain, parsedPath } = await this.parseArguments(path);
62
+ const query = getQuery(domain, parsedPath);
63
+ return this.sendRequest(query);
64
+ }
65
+ }
@@ -0,0 +1,76 @@
1
+ import { Injectable, InternalServerErrorException } from '@nestjs/common';
2
+ import * as fs from 'fs';
3
+ import { join } from 'path';
4
+ import { ConfigService } from '@nestjs/config';
5
+ import { Project } from 'src/types';
6
+ import { IFilesService } from '../interfaces/files.service.interface';
7
+
8
+ @Injectable()
9
+ export default class LocalFilesService implements IFilesService {
10
+ // eslint-disable-next-line no-useless-constructor, no-empty-function
11
+ constructor(private configService: ConfigService) {}
12
+
13
+ async listDirectory(path: string): Promise<Project> {
14
+ const dataPath = this.configService.get('LOCAL_PATH');
15
+ const fullPath = join(dataPath, path);
16
+
17
+ const files = await fs.promises.readdir(fullPath);
18
+
19
+ const edges = await Promise.all(
20
+ files.map((file) => LocalFilesService.getFileStats(fullPath, file)),
21
+ );
22
+
23
+ const tree = {
24
+ trees: {
25
+ edges: edges.filter((edge) => edge.node.type === 'tree'),
26
+ },
27
+ blobs: {
28
+ edges: edges.filter((edge) => edge.node.type === 'blob'),
29
+ },
30
+ };
31
+
32
+ return { repository: { tree } };
33
+ }
34
+
35
+ async readFile(path: string): Promise<Project> {
36
+ const dataPath = this.configService.get('LOCAL_PATH');
37
+ const fullpath = join(dataPath, path);
38
+
39
+ try {
40
+ const content = await (
41
+ await fs.promises.readFile(fullpath, 'utf8')
42
+ ).trim();
43
+
44
+ const name = path.split('/').pop(); // extract file name from the path
45
+
46
+ return LocalFilesService.formatResponse(name, content);
47
+ } catch (error) {
48
+ throw new InternalServerErrorException('Error reading file');
49
+ }
50
+ }
51
+
52
+ private static async getFileStats(fullPath: string, file: string) {
53
+ const stats = await fs.promises.lstat(join(fullPath, file));
54
+ if (stats.isDirectory()) {
55
+ return { node: { name: file, type: 'tree' } };
56
+ }
57
+ return { node: { name: file, type: 'blob' } };
58
+ }
59
+
60
+ private static formatResponse(name: string, content: string): Project {
61
+ // Construct the response to mimic the structure from GitLab API
62
+ return {
63
+ repository: {
64
+ blobs: {
65
+ nodes: [
66
+ {
67
+ name,
68
+ rawBlob: content,
69
+ rawTextBlob: content,
70
+ },
71
+ ],
72
+ },
73
+ },
74
+ };
75
+ }
76
+ }
package/src/main.ts ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import bootstrap from './bootstrap';
4
+
5
+ type ProgramOptions = {
6
+ config?: string;
7
+ };
8
+
9
+ const program = new Command();
10
+
11
+ program
12
+ .description(
13
+ 'The lib microservice is responsible for handling and serving the contents of library assets of the DTaaS platform. It provides API endpoints for clients to query, and fetch these assets.',
14
+ )
15
+ .option('-c, --config <path>', 'set the config path (default .env)')
16
+ .helpOption('-h, --help', 'display help for libms')
17
+ .showHelpAfterError();
18
+
19
+ program.parse(process.argv);
20
+
21
+ const options: ProgramOptions = program.opts();
22
+
23
+ if (options.config) {
24
+ bootstrap({ config: options.config, runHelp: () => program.help() });
25
+ } else {
26
+ bootstrap({ runHelp: () => program.help() });
27
+ }
package/src/schema.gql ADDED
@@ -0,0 +1,58 @@
1
+ # ------------------------------------------------------
2
+ # THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
3
+ # ------------------------------------------------------
4
+
5
+ type Blob {
6
+ name: String!
7
+ type: String!
8
+ }
9
+
10
+ type BlobEdge {
11
+ node: Blob!
12
+ }
13
+
14
+ type BlobConnection {
15
+ edges: [BlobEdge!]!
16
+ }
17
+
18
+ type TreeEntry {
19
+ name: String!
20
+ type: String!
21
+ }
22
+
23
+ type TreeEdge {
24
+ node: TreeEntry!
25
+ }
26
+
27
+ type TreeConnection {
28
+ edges: [TreeEdge!]!
29
+ }
30
+
31
+ type Tree {
32
+ blobs: BlobConnection!
33
+ trees: TreeConnection!
34
+ }
35
+
36
+ type RepositoryBlob {
37
+ name: String!
38
+ rawBlob: String!
39
+ rawTextBlob: String!
40
+ }
41
+
42
+ type RepositoryBlobConnection {
43
+ nodes: [RepositoryBlob!]!
44
+ }
45
+
46
+ type Repository {
47
+ tree: Tree!
48
+ blobs: RepositoryBlobConnection!
49
+ }
50
+
51
+ type Project {
52
+ repository: Repository!
53
+ }
54
+
55
+ type Query {
56
+ listDirectory(path: String!): Project!
57
+ readFile(path: String!): Project!
58
+ }
package/src/types.ts ADDED
@@ -0,0 +1,92 @@
1
+ import { Field, ObjectType } from '@nestjs/graphql';
2
+
3
+ @ObjectType()
4
+ export class Blob {
5
+ @Field()
6
+ name: string;
7
+
8
+ @Field()
9
+ type: string;
10
+ }
11
+
12
+ @ObjectType()
13
+ export class BlobEdge {
14
+ @Field(() => Blob)
15
+ node: Blob;
16
+ }
17
+
18
+ @ObjectType()
19
+ export class BlobConnection {
20
+ @Field(() => [BlobEdge])
21
+ edges: BlobEdge[];
22
+ }
23
+
24
+ @ObjectType()
25
+ export class TreeEntry {
26
+ @Field()
27
+ name: string;
28
+
29
+ @Field()
30
+ type: string;
31
+ }
32
+
33
+ @ObjectType()
34
+ export class TreeEdge {
35
+ @Field(() => TreeEntry)
36
+ node: TreeEntry;
37
+ }
38
+
39
+ @ObjectType()
40
+ export class TreeConnection {
41
+ @Field(() => [TreeEdge])
42
+ edges: TreeEdge[];
43
+ }
44
+
45
+ @ObjectType()
46
+ export class Tree {
47
+ @Field()
48
+ blobs: BlobConnection;
49
+
50
+ @Field()
51
+ trees: TreeConnection;
52
+ }
53
+
54
+ @ObjectType()
55
+ export class RepositoryBlob {
56
+ @Field()
57
+ name: string;
58
+
59
+ @Field()
60
+ rawBlob: string;
61
+
62
+ @Field()
63
+ rawTextBlob: string;
64
+ }
65
+ @ObjectType()
66
+ export class RepositoryBlobConnection {
67
+ @Field(() => [RepositoryBlob])
68
+ nodes: RepositoryBlob[];
69
+ }
70
+
71
+ @ObjectType()
72
+ export class Repository {
73
+ @Field()
74
+ tree?: Tree;
75
+
76
+ @Field()
77
+ blobs?: RepositoryBlobConnection;
78
+ }
79
+ @ObjectType()
80
+ export class Project {
81
+ @Field(() => Repository)
82
+ repository: Repository;
83
+ }
84
+
85
+ @ObjectType()
86
+ export class Query {
87
+ @Field()
88
+ listDirectory: Project;
89
+
90
+ @Field()
91
+ readFile: Project;
92
+ }
package/test/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # File Structure
2
+
3
+ Inorder to test the lib-MS, a specific file structure must be configured.
4
+
5
+ Since the tests are tested across two different modes,
6
+ 'local' or 'gitlab', a homogenous file structure is required.
7
+
8
+ This file structure must be within 'files' aswell as within
9
+ your working gitlab repository, as depicted below...
10
+
11
+ local file system:
12
+
13
+ ```txt
14
+ files/
15
+ user2/
16
+ data/
17
+ digital twins/
18
+ functions/
19
+ models/
20
+ tools/
21
+ ```
22
+
23
+ gitlab repository:
24
+
25
+ ```txt
26
+ {Your-Gitlab-Group}/
27
+ user2/
28
+ data/
29
+ digital twins/
30
+ functions/
31
+ models/
32
+ tools/
33
+ ```
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <coverage generated="1704119534187" clover="3.2.0">
3
+ <project timestamp="1704119534187" name="All files">
4
+ <metrics statements="31" coveredstatements="18" conditionals="8" coveredconditionals="0" methods="2" coveredmethods="0" elements="41" coveredelements="18" complexity="0" loc="31" ncloc="31" packages="1" files="1" classes="1"/>
5
+ <file name="testUtil.ts" path="/home/prasad/git/prasadtalasila/DTaaS/servers/lib/test/testUtil.ts">
6
+ <metrics statements="31" coveredstatements="18" conditionals="8" coveredconditionals="0" methods="2" coveredmethods="0"/>
7
+ <line num="1" count="1" type="stmt"/>
8
+ <line num="2" count="1" type="stmt"/>
9
+ <line num="4" count="1" type="stmt"/>
10
+ <line num="7" count="1" type="stmt"/>
11
+ <line num="9" count="1" type="stmt"/>
12
+ <line num="11" count="1" type="stmt"/>
13
+ <line num="27" count="1" type="stmt"/>
14
+ <line num="28" count="1" type="stmt"/>
15
+ <line num="29" count="1" type="stmt"/>
16
+ <line num="30" count="1" type="stmt"/>
17
+ <line num="37" count="1" type="stmt"/>
18
+ <line num="51" count="1" type="stmt"/>
19
+ <line num="52" count="0" type="stmt"/>
20
+ <line num="53" count="0" type="stmt"/>
21
+ <line num="56" count="1" type="stmt"/>
22
+ <line num="59" count="0" type="cond" truecount="0" falsecount="6"/>
23
+ <line num="61" count="0" type="stmt"/>
24
+ <line num="63" count="0" type="stmt"/>
25
+ <line num="65" count="0" type="stmt"/>
26
+ <line num="67" count="0" type="stmt"/>
27
+ <line num="69" count="0" type="cond" truecount="0" falsecount="1"/>
28
+ <line num="70" count="0" type="stmt"/>
29
+ <line num="72" count="0" type="cond" truecount="0" falsecount="1"/>
30
+ <line num="73" count="0" type="stmt"/>
31
+ <line num="75" count="0" type="stmt"/>
32
+ <line num="78" count="0" type="stmt"/>
33
+ <line num="83" count="1" type="stmt"/>
34
+ <line num="102" count="1" type="stmt"/>
35
+ <line num="142" count="1" type="stmt"/>
36
+ <line num="160" count="1" type="stmt"/>
37
+ <line num="178" count="1" type="stmt"/>
38
+ </file>
39
+ </project>
40
+ </coverage>
@@ -0,0 +1,2 @@
1
+ {"/home/prasad/git/prasadtalasila/DTaaS/servers/lib/test/testUtil.ts": {"path":"/home/prasad/git/prasadtalasila/DTaaS/servers/lib/test/testUtil.ts","statementMap":{"0":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},"1":{"start":{"line":2,"column":0},"end":{"line":2,"column":45}},"2":{"start":{"line":4,"column":0},"end":{"line":4,"column":32}},"3":{"start":{"line":7,"column":13},"end":{"line":7,"column":52}},"4":{"start":{"line":9,"column":13},"end":{"line":9,"column":43}},"5":{"start":{"line":11,"column":13},"end":{"line":26,"column":2}},"6":{"start":{"line":27,"column":13},"end":{"line":27,"column":40}},"7":{"start":{"line":28,"column":13},"end":{"line":28,"column":46}},"8":{"start":{"line":29,"column":13},"end":{"line":29,"column":61}},"9":{"start":{"line":30,"column":13},"end":{"line":36,"column":2}},"10":{"start":{"line":37,"column":13},"end":{"line":49,"column":2}},"11":{"start":{"line":52,"column":16},"end":{"line":52,"column":30}},"12":{"start":{"line":53,"column":2},"end":{"line":53,"column":25}},"13":{"start":{"line":51,"column":0},"end":{"line":51,"column":16}},"14":{"start":{"line":59,"column":4},"end":{"line":79,"column":null}},"15":{"start":{"line":61,"column":8},"end":{"line":61,"column":33}},"16":{"start":{"line":63,"column":8},"end":{"line":63,"column":37}},"17":{"start":{"line":65,"column":8},"end":{"line":65,"column":38}},"18":{"start":{"line":67,"column":8},"end":{"line":67,"column":23}},"19":{"start":{"line":69,"column":8},"end":{"line":71,"column":null}},"20":{"start":{"line":70,"column":10},"end":{"line":70,"column":26}},"21":{"start":{"line":72,"column":8},"end":{"line":74,"column":null}},"22":{"start":{"line":73,"column":10},"end":{"line":73,"column":25}},"23":{"start":{"line":75,"column":8},"end":{"line":75,"column":25}},"24":{"start":{"line":78,"column":8},"end":{"line":78,"column":25}},"25":{"start":{"line":56,"column":0},"end":{"line":56,"column":13}},"26":{"start":{"line":83,"column":13},"end":{"line":100,"column":2}},"27":{"start":{"line":102,"column":13},"end":{"line":140,"column":2}},"28":{"start":{"line":142,"column":13},"end":{"line":158,"column":2}},"29":{"start":{"line":160,"column":13},"end":{"line":176,"column":3}},"30":{"start":{"line":178,"column":13},"end":{"line":190,"column":3}}},"fnMap":{"0":{"name":"sleep","decl":{"start":{"line":51,"column":16},"end":{"line":51,"column":21}},"loc":{"start":{"line":51,"column":24},"end":{"line":54,"column":1}}},"1":{"name":"(anonymous_1)","decl":{"start":{"line":58,"column":2},"end":{"line":58,"column":5}},"loc":{"start":{"line":58,"column":17},"end":{"line":80,"column":3}}}},"branchMap":{"0":{"loc":{"start":{"line":59,"column":4},"end":{"line":79,"column":null}},"type":"switch","locations":[{"start":{"line":60,"column":6},"end":{"line":61,"column":33}},{"start":{"line":62,"column":6},"end":{"line":63,"column":37}},{"start":{"line":64,"column":6},"end":{"line":65,"column":38}},{"start":{"line":66,"column":6},"end":{"line":67,"column":23}},{"start":{"line":68,"column":6},"end":{"line":75,"column":25}},{"start":{"line":77,"column":6},"end":{"line":78,"column":25}}]},"1":{"loc":{"start":{"line":69,"column":8},"end":{"line":71,"column":null}},"type":"if","locations":[{"start":{"line":69,"column":8},"end":{"line":71,"column":null}}]},"2":{"loc":{"start":{"line":72,"column":8},"end":{"line":74,"column":null}},"type":"if","locations":[{"start":{"line":72,"column":8},"end":{"line":74,"column":null}}]}},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":1,"11":0,"12":0,"13":1,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":1,"26":1,"27":1,"28":1,"29":1,"30":1},"f":{"0":0,"1":0},"b":{"0":[0,0,0,0,0,0],"1":[0],"2":[0]}}
2
+ }