@static-suite/static-suite-data-server 0.0.22 → 0.0.24

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 (157) hide show
  1. package/.husky/pre-commit +0 -3
  2. package/README.md +49 -0
  3. package/__mocks__/clear-module.js +2 -1
  4. package/dist/bin/serve.js +0 -1
  5. package/dist/http/README.md +49 -0
  6. package/dist/http/public/assets/bulma/bulma.min.css +3 -1
  7. package/dist/http/public/assets/simple-datatables/index.js +1 -1
  8. package/dist/http/public/assets/simple-datatables/style.css +32 -7
  9. package/dist/http/routes/cache.d.ts.map +1 -1
  10. package/dist/http/routes/cache.js +1 -1
  11. package/dist/http/routes/data.d.ts.map +1 -1
  12. package/dist/http/routes/data.js +2 -2
  13. package/dist/http/routes/dependency.d.ts.map +1 -1
  14. package/dist/http/routes/docs.d.ts.map +1 -1
  15. package/dist/http/routes/dump.d.ts.map +1 -1
  16. package/dist/http/routes/home.d.ts.map +1 -1
  17. package/dist/http/routes/index.js +6 -6
  18. package/dist/http/routes/indexUUID.d.ts.map +1 -1
  19. package/dist/http/routes/indexUUID.js +3 -3
  20. package/dist/http/routes/indexUrl.d.ts.map +1 -1
  21. package/dist/http/routes/indexUrl.js +4 -1
  22. package/dist/http/routes/query.d.ts.map +1 -1
  23. package/dist/http/routes/status.d.ts.map +1 -1
  24. package/dist/http/routes/subset.d.ts.map +1 -1
  25. package/dist/http/routes/task.d.ts.map +1 -1
  26. package/dist/http/routes/task.js +1 -1
  27. package/dist/lib/config/__tests__/config.test.d.ts +2 -0
  28. package/dist/lib/config/__tests__/config.test.d.ts.map +1 -0
  29. package/dist/lib/config/__tests__/config.test.js +123 -0
  30. package/dist/lib/config/config.d.ts.map +1 -1
  31. package/dist/lib/config/config.js +1 -0
  32. package/dist/lib/dataServer.types.js +1 -1
  33. package/dist/lib/query/__tests__/queryRunner.test.d.ts +2 -0
  34. package/dist/lib/query/__tests__/queryRunner.test.d.ts.map +1 -0
  35. package/dist/lib/query/__tests__/queryRunner.test.js +59 -0
  36. package/dist/lib/query/query.types.d.ts.map +1 -1
  37. package/dist/lib/query/query.types.js +1 -1
  38. package/dist/lib/query/queryTagManager.d.ts.map +1 -1
  39. package/dist/lib/query/queryTagManager.js +0 -1
  40. package/dist/lib/store/dataDir/__tests__/dataDirManager.test.d.ts +2 -0
  41. package/dist/lib/store/dataDir/__tests__/dataDirManager.test.d.ts.map +1 -0
  42. package/dist/lib/store/dataDir/__tests__/dataDirManager.test.js +18 -0
  43. package/dist/lib/store/dependency/dependencyManager.d.ts.map +1 -1
  44. package/dist/lib/store/dependency/dependencyTagger.d.ts.map +1 -1
  45. package/dist/lib/store/dump/dumpMetadataHelper.d.ts.map +1 -1
  46. package/dist/lib/store/dump/dumpMetadataHelper.js +1 -0
  47. package/dist/lib/store/include/__tests__/includeParser.test.d.ts +2 -0
  48. package/dist/lib/store/include/__tests__/includeParser.test.d.ts.map +1 -0
  49. package/dist/lib/store/include/__tests__/includeParser.test.js +77 -0
  50. package/dist/lib/store/include/parsers/__tests__/entityIncludeParser.test.d.ts +2 -0
  51. package/dist/lib/store/include/parsers/__tests__/entityIncludeParser.test.d.ts.map +1 -0
  52. package/dist/lib/store/include/parsers/__tests__/entityIncludeParser.test.js +43 -0
  53. package/dist/lib/store/include/parsers/configIncludeParser.d.ts.map +1 -1
  54. package/dist/lib/store/include/parsers/customIncludeParser.d.ts.map +1 -1
  55. package/dist/lib/store/include/parsers/entityIncludeParser.d.ts.map +1 -1
  56. package/dist/lib/store/include/parsers/localeIncludeParser.d.ts.map +1 -1
  57. package/dist/lib/store/include/parsers/queryIncludeParser.d.ts.map +1 -1
  58. package/dist/lib/store/include/parsers/types/__tests__/aliasIncludeParser.test.d.ts +2 -0
  59. package/dist/lib/store/include/parsers/types/__tests__/aliasIncludeParser.test.d.ts.map +1 -0
  60. package/dist/lib/store/include/parsers/types/__tests__/aliasIncludeParser.test.js +37 -0
  61. package/dist/lib/store/include/parsers/types/__tests__/aliasWithoutTypeIncludeParser.test.d.ts +2 -0
  62. package/dist/lib/store/include/parsers/types/__tests__/aliasWithoutTypeIncludeParser.test.d.ts.map +1 -0
  63. package/dist/lib/store/include/parsers/types/__tests__/aliasWithoutTypeIncludeParser.test.js +37 -0
  64. package/dist/lib/store/include/parsers/types/aliasIncludeParser.d.ts.map +1 -1
  65. package/dist/lib/store/include/parsers/types/aliasWithoutTypeIncludeParser.d.ts.map +1 -1
  66. package/dist/lib/store/workDir/__tests__/workDirHelper.test.d.ts +2 -0
  67. package/dist/lib/store/workDir/__tests__/workDirHelper.test.d.ts.map +1 -0
  68. package/dist/lib/store/workDir/__tests__/workDirHelper.test.js +38 -0
  69. package/dist/lib/store/workDir/storage/__tests__/getChangedLinesBetween.test.d.ts +2 -0
  70. package/dist/lib/store/workDir/storage/__tests__/getChangedLinesBetween.test.d.ts.map +1 -0
  71. package/dist/lib/store/workDir/storage/__tests__/getChangedLinesBetween.test.js +24 -0
  72. package/dist/lib/store/workDir/storage/__tests__/getDataFromLogLine.test.d.ts +2 -0
  73. package/dist/lib/store/workDir/storage/__tests__/getDataFromLogLine.test.d.ts.map +1 -0
  74. package/dist/lib/store/workDir/storage/__tests__/getDataFromLogLine.test.js +18 -0
  75. package/dist/lib/store/workDir/storage/getChangedLinesBetween.d.ts.map +1 -1
  76. package/dist/lib/store/workDir/storage/getDataFromLogLine.d.ts.map +1 -1
  77. package/dist/lib/task/__tests__/taskRunner.test.d.ts +2 -0
  78. package/dist/lib/task/__tests__/taskRunner.test.d.ts.map +1 -0
  79. package/dist/lib/task/__tests__/taskRunner.test.js +50 -0
  80. package/dist/lib/task/task.types.d.ts.map +1 -1
  81. package/dist/lib/utils/array/__tests__/arrayUtils.test.d.ts +2 -0
  82. package/dist/lib/utils/array/__tests__/arrayUtils.test.d.ts.map +1 -0
  83. package/dist/lib/utils/array/__tests__/arrayUtils.test.js +17 -0
  84. package/dist/lib/utils/array/arrayUtils.d.ts.map +1 -1
  85. package/dist/lib/utils/array/arrayUtils.js +0 -1
  86. package/dist/lib/utils/cache/__tests__/cache.test.d.ts +2 -0
  87. package/dist/lib/utils/cache/__tests__/cache.test.d.ts.map +1 -0
  88. package/dist/lib/utils/cache/__tests__/cache.test.js +21 -0
  89. package/dist/lib/utils/fs/__tests__/fsUtils.test.d.ts +2 -0
  90. package/dist/lib/utils/fs/__tests__/fsUtils.test.d.ts.map +1 -0
  91. package/dist/lib/utils/fs/__tests__/fsUtils.test.js +84 -0
  92. package/dist/lib/utils/fs/fsUtils.d.ts.map +1 -1
  93. package/dist/lib/utils/logger/__tests__/logger.test.d.ts +2 -0
  94. package/dist/lib/utils/logger/__tests__/logger.test.d.ts.map +1 -0
  95. package/dist/lib/utils/logger/__tests__/logger.test.js +13 -0
  96. package/dist/lib/utils/logger/logger.d.ts.map +1 -1
  97. package/dist/lib/utils/logger/logger.js +1 -3
  98. package/dist/lib/utils/logger/logger.types.js +1 -1
  99. package/dist/lib/utils/module/__tests__/dirBasedModuleGroupManager.test.d.ts +2 -0
  100. package/dist/lib/utils/module/__tests__/dirBasedModuleGroupManager.test.d.ts.map +1 -0
  101. package/dist/lib/utils/module/__tests__/dirBasedModuleGroupManager.test.js +34 -0
  102. package/dist/lib/utils/module/__tests__/moduleHandler.test.d.ts +2 -0
  103. package/dist/lib/utils/module/__tests__/moduleHandler.test.d.ts.map +1 -0
  104. package/dist/lib/utils/module/__tests__/moduleHandler.test.js +82 -0
  105. package/dist/lib/utils/module/dirBasedModuleGroupManager.d.ts +1 -1
  106. package/dist/lib/utils/module/dirBasedModuleGroupManager.d.ts.map +1 -1
  107. package/dist/lib/utils/module/moduleManager.d.ts +1 -1
  108. package/dist/lib/utils/module/moduleManager.d.ts.map +1 -1
  109. package/dist/lib/utils/module/moduleManager.js +1 -2
  110. package/dist/lib/utils/object/__tests__/objectUtils.test.d.ts +2 -0
  111. package/dist/lib/utils/object/__tests__/objectUtils.test.d.ts.map +1 -0
  112. package/dist/lib/utils/object/__tests__/objectUtils.test.js +60 -0
  113. package/dist/lib/utils/object/objectUtils.d.ts.map +1 -1
  114. package/dist/lib/utils/string/__tests__/stringUtils.test.d.ts +2 -0
  115. package/dist/lib/utils/string/__tests__/stringUtils.test.d.ts.map +1 -0
  116. package/dist/lib/utils/string/__tests__/stringUtils.test.js +51 -0
  117. package/dist/lib/utils/string/stringUtils.d.ts.map +1 -1
  118. package/eslint.config.mjs +18 -0
  119. package/package.json +35 -33
  120. package/scripts/{copy-http-files-to-src.js → copy-http-files-to-src.mjs} +10 -12
  121. package/src/__tests__/fixtures/hook/main.hook.js +4 -3
  122. package/src/__tests__/fixtures/hook/taxonomy/main.hook.js +4 -3
  123. package/src/__tests__/fixtures/hook/taxonomy/taxo.hook.js +4 -3
  124. package/src/__tests__/fixtures/query/error.query.js +1 -1
  125. package/src/__tests__/fixtures/query/noHandler.query.js +1 -0
  126. package/src/__tests__/fixtures/query/query1.query.js +1 -0
  127. package/src/__tests__/fixtures/query/query2.query.js +1 -0
  128. package/src/__tests__/fixtures/query/wrongNamequery.js +1 -0
  129. package/src/__tests__/fixtures/task/error.task.js +1 -1
  130. package/src/__tests__/fixtures/task/noHandler.task.js +1 -0
  131. package/src/__tests__/fixtures/task/task1.task.js +1 -0
  132. package/src/__tests__/fixtures/task/task2.task.js +1 -0
  133. package/src/__tests__/fixtures/task/wrongNametask.js +1 -0
  134. package/src/bin/serve.ts +0 -2
  135. package/src/http/routes/cache.ts +1 -1
  136. package/src/http/routes/data.ts +2 -3
  137. package/src/http/routes/index.ts +6 -6
  138. package/src/http/routes/indexUUID.ts +3 -3
  139. package/src/http/routes/indexUrl.ts +5 -1
  140. package/src/http/routes/task.ts +1 -1
  141. package/src/lib/config/__tests__/config.test.ts +2 -2
  142. package/src/lib/config/config.ts +1 -0
  143. package/src/lib/query/__tests__/queryRunner.test.ts +1 -0
  144. package/src/lib/query/queryTagManager.ts +0 -1
  145. package/src/lib/store/dump/dumpMetadataHelper.ts +1 -0
  146. package/src/lib/task/__tests__/taskRunner.test.ts +1 -0
  147. package/src/lib/utils/array/arrayUtils.ts +0 -1
  148. package/src/lib/utils/fs/__tests__/fsUtils.test.ts +5 -1
  149. package/src/lib/utils/logger/logger.ts +0 -1
  150. package/src/lib/utils/module/__mocks__/dummyModule.query.js +1 -0
  151. package/src/lib/utils/module/__mocks__/dummyModule2.query.js +1 -0
  152. package/src/lib/utils/module/__tests__/dirBasedModuleGroupManager.test.ts +3 -1
  153. package/src/lib/utils/module/__tests__/moduleHandler.test.ts +7 -3
  154. package/src/lib/utils/module/moduleManager.ts +1 -2
  155. package/tsconfig.json +1 -2
  156. package/.eslintignore +0 -4
  157. package/.eslintrc.json +0 -46
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const logger_1 = require("../../logger");
9
+ const moduleManager_1 = require("../moduleManager");
10
+ // This works in conjunction with "__mocks__/clear-module.js"
11
+ jest.mock('clear-module');
12
+ // This test is executed from dist folder
13
+ const dummyModulePath = fs_1.default.realpathSync(path_1.default.resolve(path_1.default.join(__dirname, '../../../../../src/lib/utils/module/__mocks__/dummyModule.query.js')));
14
+ beforeEach(() => {
15
+ logger_1.logger.error = jest.fn();
16
+ });
17
+ describe('moduleHandler test', () => {
18
+ describe('get', () => {
19
+ describe('when a module exists', () => {
20
+ it('gets a module without logging any error', () => {
21
+ const { dummyObject } = moduleManager_1.moduleManager.get(dummyModulePath);
22
+ expect(dummyObject.key).toBe('dummyModuleValue');
23
+ expect(logger_1.logger.error).not.toHaveBeenCalled();
24
+ });
25
+ it('gets a module twice without reloading it', () => {
26
+ const { dummyObject: firstDummyObject } = moduleManager_1.moduleManager.get(dummyModulePath);
27
+ expect(firstDummyObject.key).toBe('dummyModuleValue');
28
+ firstDummyObject.key = 'updatedDummyModuleValue';
29
+ const { dummyObject: secondDummyObject } = moduleManager_1.moduleManager.get(dummyModulePath);
30
+ expect(secondDummyObject.key).toBe('updatedDummyModuleValue');
31
+ });
32
+ });
33
+ describe('when a module does not exist', () => {
34
+ it('throws an exception and logs an error', () => {
35
+ expect(() => moduleManager_1.moduleManager.get('invalid-path')).toThrow();
36
+ expect(logger_1.logger.error).toHaveBeenCalled();
37
+ });
38
+ });
39
+ });
40
+ describe('load', () => {
41
+ describe('when a module exists', () => {
42
+ it('loads a module without logging any error', () => {
43
+ const { dummyObject } = moduleManager_1.moduleManager.load(dummyModulePath);
44
+ expect(dummyObject.key).toBe('dummyModuleValue');
45
+ expect(logger_1.logger.error).not.toHaveBeenCalled();
46
+ });
47
+ it('loads a module twice reloading it from scratch', () => {
48
+ const { dummyObject: firstDummyObject } = moduleManager_1.moduleManager.load(dummyModulePath);
49
+ const { dummyObject: secondDummyObject } = moduleManager_1.moduleManager.load(dummyModulePath);
50
+ firstDummyObject.key = 'updatedDummyModuleValue';
51
+ expect(firstDummyObject.key).toBe('updatedDummyModuleValue');
52
+ expect(secondDummyObject.key).toBe('dummyModuleValue');
53
+ });
54
+ });
55
+ describe('when a module does not exist', () => {
56
+ it('throws an exception and logs an error', () => {
57
+ expect(() => moduleManager_1.moduleManager.get('invalid-path')).toThrow();
58
+ expect(logger_1.logger.error).toHaveBeenCalled();
59
+ });
60
+ });
61
+ });
62
+ describe('remove', () => {
63
+ it('removes a single module from Node.js cache', () => {
64
+ const { dummyObject: firstDummyObject } = moduleManager_1.moduleManager.get(dummyModulePath);
65
+ moduleManager_1.moduleManager.remove(dummyModulePath);
66
+ const { dummyObject: secondDummyObject } = moduleManager_1.moduleManager.get(dummyModulePath);
67
+ firstDummyObject.key = 'updatedDummyModuleValue';
68
+ expect(firstDummyObject.key).toBe('updatedDummyModuleValue');
69
+ expect(secondDummyObject.key).toBe('dummyModuleValue');
70
+ });
71
+ });
72
+ describe('removeAll', () => {
73
+ it('removes several modules from Node.js cache', () => {
74
+ const { dummyObject: dummyObject1 } = moduleManager_1.moduleManager.get(dummyModulePath);
75
+ dummyObject1.key = 'updatedDummyModuleValue';
76
+ moduleManager_1.moduleManager.removeAll(/dummyModule/);
77
+ const { dummyObject: dummyObject2 } = moduleManager_1.moduleManager.get(dummyModulePath);
78
+ expect(dummyObject1.key).toBe('updatedDummyModuleValue');
79
+ expect(dummyObject2.key).toBe('dummyModuleValue');
80
+ });
81
+ });
82
+ });
@@ -26,5 +26,5 @@ import { ModuleGroupManager } from './module.types';
26
26
  * @returns A module group manager with a set of common functionalities
27
27
  * for those kind of directories.
28
28
  */
29
- export declare const dirBasedModuleGroupManager: <ModuleType>(key: 'hook' | 'query' | 'task') => ModuleGroupManager<ModuleType>;
29
+ export declare const dirBasedModuleGroupManager: <ModuleType>(key: "hook" | "query" | "task") => ModuleGroupManager<ModuleType>;
30
30
  //# sourceMappingURL=dirBasedModuleGroupManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dirBasedModuleGroupManager.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/module/dirBasedModuleGroupManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAc,MAAM,gBAAgB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,0BAA0B,oBAEhC,MAAM,GAAG,OAAO,GAAG,MAAM,mCAyC/B,CAAC"}
1
+ {"version":3,"file":"dirBasedModuleGroupManager.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/module/dirBasedModuleGroupManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAc,MAAM,gBAAgB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,0BAA0B,GAAI,UAAU,EAEnD,KAAK,MAAM,GAAG,OAAO,GAAG,MAAM,KAC7B,kBAAkB,CAAC,UAAU,CAwC/B,CAAC"}
@@ -59,6 +59,6 @@ export declare const moduleManager: {
59
59
  * @throws
60
60
  * An exception if the module cannot be loaded.
61
61
  */
62
- get: <Type_1>(modulePath: string) => Type_1;
62
+ get: <Type>(modulePath: string) => Type;
63
63
  };
64
64
  //# sourceMappingURL=moduleManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"moduleManager.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/module/moduleManager.ts"],"names":[],"mappings":"AA8CA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa;IACxB;;;;;;;;;;;;;;;OAeG;6BACsB,MAAM;IAoB/B;;;;;;;;OAQG;yBACkB,MAAM;;UAAkC,IAAI;IASjE;;;;OAIG;uBACgB,MAAM,KAAG,IAAI;IAShC;;;;;;;;;;;;;OAaG;8BACqB,MAAM;CAO/B,CAAC"}
1
+ {"version":3,"file":"moduleManager.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/module/moduleManager.ts"],"names":[],"mappings":"AA6CA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa;IACxB;;;;;;;;;;;;;;;OAeG;WACI,IAAI,cAAc,MAAM,KAAG,IAAI;IAoBtC;;;;;;;;OAQG;yBACkB,MAAM;;UAAkC,IAAI;IASjE;;;;OAIG;uBACgB,MAAM,KAAG,IAAI;IAShC;;;;;;;;;;;;;OAaG;UACG,IAAI,cAAc,MAAM,KAAG,IAAI;CAOtC,CAAC"}
@@ -4,8 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.moduleManager = void 0;
7
- /* eslint-disable global-require */
8
- /* eslint-disable import/no-dynamic-require */
9
7
  const clear_module_1 = __importDefault(require("clear-module"));
10
8
  const logger_1 = require("../logger");
11
9
  const config_1 = require("../../config");
@@ -39,6 +37,7 @@ const resolve = (modulePath) => {
39
37
  if (!resolvedModulePath) {
40
38
  try {
41
39
  resolvedModulePath = require.resolve(modulePath);
40
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
41
  }
43
42
  catch (e) {
44
43
  resolvedModulePath = modulePath;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=objectUtils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectUtils.test.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/object/__tests__/objectUtils.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const __1 = require("..");
4
+ const objectUtils_1 = require("../objectUtils");
5
+ describe('Object utils test', () => {
6
+ describe('isEmptyObject', () => {
7
+ it('returns true for an empty object', () => {
8
+ expect((0, objectUtils_1.isEmptyObject)({})).toBe(true);
9
+ });
10
+ it('returns false for a non empty object', () => {
11
+ expect((0, objectUtils_1.isEmptyObject)({ x: 1 })).toBe(false);
12
+ });
13
+ });
14
+ describe('hasKey', () => {
15
+ it('returns true if an object has a given key', () => {
16
+ expect((0, objectUtils_1.hasKey)({ x: 1 }, 'x')).toBe(true);
17
+ });
18
+ it('returns false if an object does not have a given key', () => {
19
+ expect((0, objectUtils_1.hasKey)({ x: 1 }, 'y')).toBe(false);
20
+ });
21
+ });
22
+ describe('deepClone', () => {
23
+ it('returns an object equal to the given one, without references to nested objects', () => {
24
+ const anObject = { x: 1, y: {} };
25
+ const anotherObject = { z: 34 };
26
+ anObject.y = anotherObject;
27
+ const clonedObject = (0, objectUtils_1.deepClone)(anObject);
28
+ expect(clonedObject).toStrictEqual(anObject);
29
+ anotherObject.z = 22;
30
+ expect(clonedObject).not.toStrictEqual(anObject);
31
+ });
32
+ });
33
+ describe('getObjectValue', () => {
34
+ const testObject = { x: { y: { z: 'value' } } };
35
+ it('gets object value with default separator', () => {
36
+ expect((0, __1.getObjValue)(testObject, 'x.y.z')).toBe('value');
37
+ });
38
+ it('gets object value with custom separator', () => {
39
+ expect((0, __1.getObjValue)(testObject, 'x/y/z', '/')).toBe('value');
40
+ });
41
+ it('gets object value with array separator', () => {
42
+ expect((0, __1.getObjValue)(testObject, ['x', 'y', 'z'])).toBe('value');
43
+ });
44
+ it('gets undefined when path does not exist', () => {
45
+ expect((0, __1.getObjValue)(testObject, 'x.z.z')).toBeUndefined();
46
+ });
47
+ });
48
+ describe('jsonify', () => {
49
+ const testObject = {
50
+ x: new Set([1, 2]),
51
+ y: new Map([['mapKey', 'mapValue']]),
52
+ };
53
+ it('jsonify object containing Set and Map', () => {
54
+ expect((0, objectUtils_1.jsonify)(testObject)).toEqual({
55
+ x: [1, 2],
56
+ y: { mapKey: 'mapValue' },
57
+ });
58
+ });
59
+ });
60
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"objectUtils.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/object/objectUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,WAAY,UAAU,KAAG,OACjB,CAAC;AAEnC;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,qCAEZ,WAAW,mBAGjB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,WAAY,UAAU,KAAG,UACX,CAAC;AAErC;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,WACd,UAAU,QACZ,MAAM,GAAG,MAAM,EAAE,cACX,MAAM,KACjB,GAAG,GAAG,SAMR,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,oBAQnB,CAAC"}
1
+ {"version":3,"file":"objectUtils.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/object/objectUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,UAAU,KAAG,OACjB,CAAC;AAEnC;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,MAAM,EACrC,QAAQ,CAAC,EACT,KAAK,WAAW,KACf,GAAG,IAAI,MAAM,CAEf,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,UAAU,KAAG,UACX,CAAC;AAErC;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,UAAU,EAClB,MAAM,MAAM,GAAG,MAAM,EAAE,EACvB,YAAY,MAAM,KACjB,GAAG,GAAG,SAMR,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,CAQrC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=stringUtils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringUtils.test.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/string/__tests__/stringUtils.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const logger_1 = require("../../logger");
4
+ const stringUtils_1 = require("../stringUtils");
5
+ describe('String utils test', () => {
6
+ describe('parseJsonString', () => {
7
+ logger_1.logger.error = jest.fn();
8
+ it('parses a well-formed JSON string without logging any error', () => {
9
+ expect((0, stringUtils_1.parseJsonString)('{"key": "value"}')).not.toBeNull();
10
+ expect(logger_1.logger.error).not.toHaveBeenCalled();
11
+ });
12
+ it('logs an error when parsing a malformed JSON string', () => {
13
+ expect((0, stringUtils_1.parseJsonString)('malformed-json-string')).toBeNull();
14
+ expect(logger_1.logger.error).toHaveBeenCalled();
15
+ });
16
+ });
17
+ describe('parseURLSearchParams', () => {
18
+ it('parses a query string with non repeated keys and returns an object', () => {
19
+ const parsedQuery = (0, stringUtils_1.parseURLSearchParams)('arg1=a&arg2=b');
20
+ const expectedValue = { arg1: 'a', arg2: 'b' };
21
+ expect(parsedQuery).toStrictEqual(expectedValue);
22
+ });
23
+ it('parses a query string with repeated keys and returns an object', () => {
24
+ const parsedQuery = (0, stringUtils_1.parseURLSearchParams)('arg1=a&arg2=b&arg1=c');
25
+ const expectedValue = { arg1: ['a', 'c'], arg2: 'b' };
26
+ expect(parsedQuery).toEqual(expectedValue);
27
+ });
28
+ });
29
+ describe('parseUniqueId', () => {
30
+ it('parses a valid unique id and returns a date', () => {
31
+ const uniqueIdDate = (0, stringUtils_1.parseUniqueId)('2022-09-28_11-42-00.001712__7220');
32
+ // Depending on the time of year (Daylight saving time or not), parsing
33
+ // a unique id returns a different date. This test checks both possible values.
34
+ expect([1664365320001, 1664361720001]).toContain(uniqueIdDate?.getTime());
35
+ });
36
+ it('parses a non valid unique id and returns null', () => {
37
+ const uniqueIdDate = (0, stringUtils_1.parseUniqueId)('non valid unique id');
38
+ expect(uniqueIdDate).toEqual(null);
39
+ });
40
+ });
41
+ describe('isUniqueId', () => {
42
+ it('returns true for a valid unique id', () => {
43
+ const result = (0, stringUtils_1.isUniqueId)('2022-09-28_11-42-00.001712__7220');
44
+ expect(result).toEqual(true);
45
+ });
46
+ it('returns false for a non valid unique id', () => {
47
+ const result = (0, stringUtils_1.isUniqueId)('non valid unique id');
48
+ expect(result).toEqual(false);
49
+ });
50
+ });
51
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"stringUtils.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/string/stringUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,eAAgB,MAAM,KAAG,GAQpD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,gBAClB,MAAM,KAClB,qBAWF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,aAAc,MAAM,KAAG,IAAI,GAAG,IAevD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,aAAc,MAAM,KAAG,OAC+B,CAAC"}
1
+ {"version":3,"file":"stringUtils.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/string/stringUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM,KAAG,GAQpD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAC/B,aAAa,MAAM,KAClB,qBAWF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM,KAAG,IAAI,GAAG,IAevD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,KAAG,OAC+B,CAAC"}
@@ -0,0 +1,18 @@
1
+ // @ts-check
2
+
3
+ import eslint from '@eslint/js';
4
+ import { defineConfig, globalIgnores } from 'eslint/config';
5
+ import tseslint from 'typescript-eslint';
6
+
7
+ export default defineConfig(
8
+ eslint.configs.recommended,
9
+ tseslint.configs.recommended,
10
+ globalIgnores(['src/http/public']),
11
+ {
12
+ files: ['**/*.{ts,tsx}'],
13
+ rules: {
14
+ '@typescript-eslint/no-explicit-any': ['off'],
15
+ '@typescript-eslint/no-require-imports': ['off'],
16
+ },
17
+ },
18
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@static-suite/static-suite-data-server",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "A flexible, fast and developer friendly Data Server for Static Suite",
5
5
  "main": "./dist/lib/index.js",
6
6
  "typings": "./dist/lib/index.d.ts",
@@ -13,26 +13,24 @@
13
13
  "dependencies": {
14
14
  "@creativebulma/bulma-tooltip": "^1.2.0",
15
15
  "@microsoft/api-extractor": "^7.34.4",
16
- "@types/jest": "^29.4.0",
17
- "@types/tap": "^15.0.8",
18
- "bulma": "^0.9.4",
19
- "chokidar": "^3.5.3",
16
+ "bulma": "^1.0.4",
17
+ "chokidar": "^4.0.3",
20
18
  "clear-module": "^4.1.2",
21
19
  "clipboard": "^2.0.11",
22
20
  "copyfiles": "^2.4.1",
23
21
  "cors": "^2.8.5",
24
22
  "decache": "^4.6.1",
25
- "express": "^4.18.2",
23
+ "express": "^5.1.0",
26
24
  "fast-glob": "^3.2.12",
27
- "marked": "^4.2.12",
25
+ "marked": "^16.2.1",
28
26
  "microtime": "^3.1.1",
29
- "mime-types": "^2.1.35",
27
+ "mime-types": "^3.0.1",
30
28
  "pug": "^3.0.3",
31
- "simple-datatables": "^7.1.2",
32
- "tsc-watch": "^6.0.0",
33
- "typescript": "^4.9.5",
29
+ "simple-datatables": "^10.0.0",
30
+ "tsc-watch": "^7.1.1",
31
+ "typescript": "^5.9.2",
34
32
  "winston": "^3.8.2",
35
- "yargs": "^17.6.2"
33
+ "yargs": "^18.0.0"
36
34
  },
37
35
  "bin": {
38
36
  "static-suite-data-server": "./dist/bin/serve.js"
@@ -40,38 +38,41 @@
40
38
  "scripts": {
41
39
  "dev": "tsc-watch --onSuccess \"yarn lint\"",
42
40
  "build": "rm -Rf dist && yarn copy-http-files-to-src && yarn lint && tsc && yarn api-extractor run --local --verbose && yarn post-build && yarn copy-http-files-to-dist",
43
- "post-build": "yarn rimraf dist/**/*__tests__",
41
+ "post-build": "rm -Rf dist/**/*__tests__",
44
42
  "serve": "export DATASERVER_CONFIG_FILE=dataserver.test.config.json && node ./dist/bin/serve.js http",
45
- "lint": "eslint . --ext .ts",
43
+ "lint": "eslint .",
46
44
  "docs": "yarn typedoc --out docs src/lib/",
47
45
  "prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
48
46
  "test": "jest --watch",
49
- "copy-http-files-to-src": "node ./scripts/copy-http-files-to-src.js",
50
- "copy-http-files-to-dist": "cp -r ./src/http/public/ ./dist/http/ && cp -r ./src/http/views/ ./dist/http/ && cp README.md ./dist/http/",
51
- "prepare": "husky install"
47
+ "copy-http-files-to-src": "node ./scripts/copy-http-files-to-src.mjs",
48
+ "copy-http-files-to-dist": "mkdir -p ./dist/http/ && cp -r ./src/http/public/ ./dist/http/ && cp -r ./src/http/views/ ./dist/http/ && cp README.md ./dist/http/",
49
+ "prepare": "husky"
52
50
  },
53
51
  "devDependencies": {
52
+ "@eslint/js": "^9.35.0",
54
53
  "@types/cors": "^2.8.13",
55
- "@types/express": "^4.17.17",
56
- "@types/marked": "^4.0.8",
54
+ "@types/express": "^5.0.3",
55
+ "@types/jest": "^30.0.0",
56
+ "@types/marked": "^6.0.0",
57
57
  "@types/microtime": "^2.1.0",
58
- "@types/mime-types": "^2.1.1",
58
+ "@types/mime-types": "^3.0.1",
59
59
  "@types/module-alias": "^2.0.1",
60
- "@types/node": "^18.13.0",
60
+ "@types/node": "^24.3.1",
61
61
  "@types/yargs": "^17.0.22",
62
- "@typescript-eslint/eslint-plugin": "^5.52.0",
63
- "@typescript-eslint/parser": "^5.52.0",
64
- "eslint": "^8.34.0",
65
- "eslint-config-airbnb-typescript-prettier": "^5.0.0",
66
- "eslint-import-resolver-typescript": "^3.5.3",
62
+ "@typescript-eslint/eslint-plugin": "^8.43.0",
63
+ "@typescript-eslint/parser": "^8.43.0",
64
+ "eslint": "^9.35.0",
65
+ "eslint-import-resolver-typescript": "^4.4.4",
67
66
  "eslint-plugin-import": "^2.27.5",
68
- "eslint-plugin-prettier": "^4.2.1",
69
- "eslint-plugin-tsdoc": "^0.2.17",
70
- "husky": "^8.0.0",
71
- "jest": "^29.4.3",
72
- "prettier": "^2.8.4",
73
- "ts-jest": "^29.0.5",
74
- "typedoc": "^0.23.25"
67
+ "eslint-plugin-prettier": "^5.5.4",
68
+ "eslint-plugin-tsdoc": "^0.4.0",
69
+ "globals": "^16.4.0",
70
+ "husky": "^9.1.7",
71
+ "jest": "^30.1.3",
72
+ "prettier": "^3.6.2",
73
+ "ts-jest": "^29.4.1",
74
+ "typedoc": "^0.28.12",
75
+ "typescript-eslint": "^8.43.0"
75
76
  },
76
77
  "jest": {
77
78
  "preset": "ts-jest",
@@ -81,6 +82,7 @@
81
82
  "src"
82
83
  ],
83
84
  "testPathIgnorePatterns": [
85
+ ".d.ts",
84
86
  "src/__tests__/fixtures/*",
85
87
  "src/__tests__/mocks/*"
86
88
  ]
@@ -1,23 +1,21 @@
1
+ /* eslint-disable no-undef */
1
2
  /**
2
3
  * Script to run after npm install
3
4
  *
4
5
  * Copy selected files to assets directory
5
6
  */
6
7
 
7
- const fs = require('fs');
8
+ import { mkdirSync, copyFileSync } from 'fs';
8
9
 
9
10
  // Copy files from Bulma to assets directory
10
11
  const bulmaSrcDir = 'node_modules/bulma/css/';
11
12
  const bulmaTargetDir = `${process.env.INIT_CWD}/src/http/public/assets/bulma/`;
12
- fs.mkdirSync(bulmaTargetDir, { recursive: true });
13
- fs.copyFileSync(
14
- `${bulmaSrcDir}/bulma.min.css`,
15
- `${bulmaTargetDir}/bulma.min.css`,
16
- );
13
+ mkdirSync(bulmaTargetDir, { recursive: true });
14
+ copyFileSync(`${bulmaSrcDir}/bulma.min.css`, `${bulmaTargetDir}/bulma.min.css`);
17
15
 
18
16
  // Copy files from Bulma tooltip to assets directory
19
17
  const bulmaTooltipSrcDir = 'node_modules/@creativebulma/bulma-tooltip/dist/';
20
- fs.copyFileSync(
18
+ copyFileSync(
21
19
  `${bulmaTooltipSrcDir}/bulma-tooltip.min.css`,
22
20
  `${bulmaTargetDir}/bulma-tooltip.min.css`,
23
21
  );
@@ -25,8 +23,8 @@ fs.copyFileSync(
25
23
  // Copy files from Clipboard to assets directory
26
24
  const clipboardSrcDir = 'node_modules/clipboard/dist/';
27
25
  const clipboardTargetDir = `${process.env.INIT_CWD}/src/http/public/assets/clipboard/`;
28
- fs.mkdirSync(clipboardTargetDir, { recursive: true });
29
- fs.copyFileSync(
26
+ mkdirSync(clipboardTargetDir, { recursive: true });
27
+ copyFileSync(
30
28
  `${clipboardSrcDir}/clipboard.min.js`,
31
29
  `${clipboardTargetDir}/clipboard.min.js`,
32
30
  );
@@ -34,12 +32,12 @@ fs.copyFileSync(
34
32
  // Copy files from datatables to assets directory
35
33
  const dataTablesSrcDir = 'node_modules/simple-datatables/dist/';
36
34
  const dataTablesTargetDir = `${process.env.INIT_CWD}/src/http/public/assets/simple-datatables/`;
37
- fs.mkdirSync(dataTablesTargetDir, { recursive: true });
38
- fs.copyFileSync(
35
+ mkdirSync(dataTablesTargetDir, { recursive: true });
36
+ copyFileSync(
39
37
  `${dataTablesSrcDir}/umd/simple-datatables.js`,
40
38
  `${dataTablesTargetDir}/index.js`,
41
39
  );
42
- fs.copyFileSync(
40
+ copyFileSync(
43
41
  `${dataTablesSrcDir}/style.css`,
44
42
  `${dataTablesTargetDir}/style.css`,
45
43
  );
@@ -1,4 +1,5 @@
1
- exports.onProcessFile = ({ fileContent }) => {
1
+ /* eslint-disable no-undef */
2
+ module.exports.onProcessFile = ({ fileContent }) => {
2
3
  // Do something...
3
4
  return {
4
5
  raw: fileContent.raw,
@@ -6,10 +7,10 @@ exports.onProcessFile = ({ fileContent }) => {
6
7
  };
7
8
  };
8
9
 
9
- exports.onStoreAdd = (/* _dataDir, _file, _fileContent, _store */) => {
10
+ module.exports.onStoreAdd = (/* _dataDir, _file, _fileContent, _store */) => {
10
11
  // Do something...
11
12
  };
12
13
 
13
- exports.onStoreRemove = (/* _file, _store */) => {
14
+ module.exports.onStoreRemove = (/* _file, _store */) => {
14
15
  // Do something...
15
16
  };
@@ -1,4 +1,5 @@
1
- exports.onProcessFile = ({ fileContent }) => {
1
+ /* eslint-disable no-undef */
2
+ module.exports.onProcessFile = ({ fileContent }) => {
2
3
  // Do something...
3
4
  return {
4
5
  raw: fileContent.raw,
@@ -6,10 +7,10 @@ exports.onProcessFile = ({ fileContent }) => {
6
7
  };
7
8
  };
8
9
 
9
- exports.onStoreAdd = (/* _dataDir, _file, _fileContent, _store */) => {
10
+ module.exports.onStoreAdd = (/* _dataDir, _file, _fileContent, _store */) => {
10
11
  // Do something...
11
12
  };
12
13
 
13
- exports.onStoreRemove = (/* _file, _store */) => {
14
+ module.exports.onStoreRemove = (/* _file, _store */) => {
14
15
  // Do something...
15
16
  };
@@ -1,4 +1,5 @@
1
- exports.onProcessFile = ({ fileContent }) => {
1
+ /* eslint-disable no-undef */
2
+ module.exports.onProcessFile = ({ fileContent }) => {
2
3
  // Do something...
3
4
  return {
4
5
  raw: fileContent.raw,
@@ -6,10 +7,10 @@ exports.onProcessFile = ({ fileContent }) => {
6
7
  };
7
8
  };
8
9
 
9
- exports.onStoreAdd = (/* _dataDir, _file, _fileContent, _store */) => {
10
+ module.exports.onStoreAdd = (/* _dataDir, _file, _fileContent, _store */) => {
10
11
  // Do something...
11
12
  };
12
13
 
13
- exports.onStoreRemove = (/* _file, _store */) => {
14
+ module.exports.onStoreRemove = (/* _file, _store */) => {
14
15
  // Do something...
15
16
  };
@@ -1,5 +1,5 @@
1
+ /* eslint-disable no-undef */
1
2
  const error = () => {
2
- // eslint-disable-next-line no-throw-literal
3
3
  throw new Error('oops');
4
4
  };
5
5
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-undef */
1
2
  const query2 = () => {
2
3
  const result = [
3
4
  {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-undef */
1
2
  const query1 = ({ args }) => {
2
3
  const result = [
3
4
  {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-undef */
1
2
  const query2 = () => {
2
3
  const result = [
3
4
  {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-undef */
1
2
  const query1 = () => {
2
3
  const result = [
3
4
  {
@@ -1,5 +1,5 @@
1
+ /* eslint-disable no-undef */
1
2
  const error = () => {
2
- // eslint-disable-next-line no-throw-literal
3
3
  throw new Error('oops');
4
4
  };
5
5
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-undef */
1
2
  const task2 = () => {
2
3
  const result = [
3
4
  {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-undef */
1
2
  const task1 = ({ args }) => {
2
3
  const result = [
3
4
  {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-undef */
1
2
  const task2 = () => {
2
3
  const result = [
3
4
  {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-undef */
1
2
  const task1 = () => {
2
3
  const result = [
3
4
  {
package/src/bin/serve.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env node
2
- /* eslint-disable import/first */
3
-
4
2
  import fs from 'fs';
5
3
  import yargs from 'yargs/yargs';
6
4
  import { hideBin } from 'yargs/helpers';
@@ -7,7 +7,7 @@ export const cacheIndex = (req: Request, res: Response): void => {
7
7
  };
8
8
 
9
9
  export const cacheClear = (req: Request, res: Response): void => {
10
- const cacheBinId = req.params[0];
10
+ const { cacheBinId } = req.params;
11
11
  let done = false;
12
12
  if (cache.has(cacheBinId)) {
13
13
  cache.bin(cacheBinId).clear();
@@ -7,9 +7,8 @@ import { dataDirManager } from '../../lib/store/dataDir';
7
7
 
8
8
  const data = (req: Request, res: Response): void => {
9
9
  dataDirManager.update();
10
- const storeKey = req.params[0];
11
- const storeKeyParts =
12
- !storeKey || storeKey === '' ? null : storeKey.split('/');
10
+ const storeKeyParts = Array.from(req.params.storeKeyParts || []);
11
+ const storeKey = storeKeyParts.join('/');
13
12
 
14
13
  const storeFile = store.data.get(storeKey);
15
14