@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
@@ -0,0 +1,108 @@
1
+ import { Test, TestingModule } from '@nestjs/testing';
2
+ import { ConfigService } from '@nestjs/config';
3
+ import * as fs from 'fs';
4
+ import { join } from 'path';
5
+ import LocalFilesService from '../../src/files/services/local-files.service';
6
+ import {
7
+ fstestFileContent,
8
+ pathToTestDirectory,
9
+ pathToTestFileContent,
10
+ testFileArray,
11
+ MockConfigService,
12
+ testFileName,
13
+ } from '../testUtil';
14
+
15
+ jest.mock('fs', () => ({
16
+ promises: {
17
+ readdir: jest.fn(),
18
+ lstat: jest.fn(),
19
+ readFile: jest.fn(),
20
+ },
21
+ }));
22
+
23
+ describe('LocalFilesService', () => {
24
+ let service: LocalFilesService;
25
+ const mockConfigService = new MockConfigService();
26
+
27
+ beforeEach(async () => {
28
+ const module: TestingModule = await Test.createTestingModule({
29
+ providers: [
30
+ LocalFilesService,
31
+ { provide: ConfigService, useValue: mockConfigService },
32
+ ],
33
+ }).compile();
34
+
35
+ service = module.get<LocalFilesService>(LocalFilesService);
36
+ });
37
+
38
+ afterEach(() => {
39
+ jest.resetAllMocks();
40
+ });
41
+
42
+ it('should be defined', () => {
43
+ expect(service).toBeDefined();
44
+ });
45
+
46
+ it('should list directory', async () => {
47
+ const fullPath = join(
48
+ mockConfigService.get('LOCAL_PATH'),
49
+ pathToTestDirectory,
50
+ );
51
+
52
+ // Mock Stats value for lstat
53
+ const statsMock: Partial<fs.Stats> = {
54
+ isDirectory: () => true, // change this to false when you need a file instead of a directory
55
+ };
56
+
57
+ jest
58
+ .spyOn(fs.promises, 'readdir')
59
+ .mockResolvedValue(testFileArray as unknown as Promise<[]>);
60
+
61
+ jest.spyOn(fs.promises, 'lstat').mockImplementation((pathToDirectory) => {
62
+ if (typeof pathToDirectory === 'string') {
63
+ return Promise.resolve(statsMock as fs.Stats);
64
+ }
65
+ throw new Error(`Invalid argument: ${pathToDirectory}`);
66
+ });
67
+ const result = await service.listDirectory(pathToTestDirectory);
68
+ expect(result).toEqual({
69
+ repository: {
70
+ tree: {
71
+ trees: {
72
+ edges: testFileArray.map((file) => ({
73
+ node: { name: file, type: 'tree' },
74
+ })),
75
+ },
76
+ blobs: { edges: [] },
77
+ },
78
+ },
79
+ });
80
+ expect(fs.promises.readdir).toHaveBeenCalledWith(fullPath);
81
+ expect(fs.promises.lstat).toHaveBeenCalledTimes(testFileArray.length);
82
+ });
83
+
84
+ it('should read file', async () => {
85
+ const fullPath = join(
86
+ mockConfigService.get('LOCAL_PATH'),
87
+ pathToTestFileContent,
88
+ );
89
+
90
+ jest.spyOn(fs.promises, 'readFile').mockResolvedValue(fstestFileContent);
91
+
92
+ const result = await service.readFile(pathToTestFileContent);
93
+ expect(result).toEqual({
94
+ repository: {
95
+ blobs: {
96
+ nodes: [
97
+ {
98
+ name: testFileName,
99
+ rawBlob: fstestFileContent,
100
+ rawTextBlob: fstestFileContent,
101
+ },
102
+ ],
103
+ },
104
+ },
105
+ });
106
+ expect(fs.promises.readFile).toHaveBeenCalledWith(fullPath, 'utf8');
107
+ });
108
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowSyntheticDefaultImports": true, //allow default imports from modules with no default export
4
+ "baseUrl": "./",
5
+ "declaration": true, //generate declaration '.d.ts' files
6
+ "emitDecoratorMetadata": true,
7
+ "experimentalDecorators": true, //allow experimental decorators for es7
8
+ "forceConsistentCasingInFileNames": false,
9
+ "incremental": true,
10
+ "module": "commonjs", //use node module system
11
+ "moduleResolution": "node", //use node module resolution strategy node
12
+ //"noImplicitAny": true, //raise error on any type
13
+ "noImplicitReturns": true, //raise error on implicit returns
14
+ "noUnusedLocals": true, //raise error on unused locals
15
+ "noUnusedParameters": true, //raise no error on unused parameters
16
+ "noFallthroughCasesInSwitch": false,
17
+ "outDir": "./dist",
18
+ "removeComments": true, //remove comments from build
19
+ "skipLibCheck": true,
20
+ "sourceMap": true, //generate .map files
21
+ "strictBindCallApply": false,
22
+ //"strictNullChecks": true,
23
+ //"strict": true, //enable all strict type-checking options
24
+ "target": "es2022",
25
+ "types": ["node", "jest"], //use node and jest types
26
+ "typeRoots": [
27
+ "node_modules/@types" //use node_modules/@types for type definitions
28
+ ],
29
+ },
30
+ "exclude": ["**/node_modules/*", "./dist"]
31
+ }