@static-suite/static-suite-data-server 0.0.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.
- package/.eslintignore +4 -0
- package/.eslintrc.json +49 -0
- package/.nvmrc +1 -0
- package/.prettierrc +10 -0
- package/.vscode/launch.json +44 -0
- package/LICENSE.txt +339 -0
- package/README.md +300 -0
- package/__mocks__/clear-module.js +7 -0
- package/api-extractor.json +339 -0
- package/dist/bin/serve.d.ts +3 -0
- package/dist/bin/serve.d.ts.map +1 -0
- package/dist/bin/serve.js +105 -0
- package/dist/http/README.md +300 -0
- package/dist/http/httpServer.d.ts +4 -0
- package/dist/http/httpServer.d.ts.map +1 -0
- package/dist/http/httpServer.js +24 -0
- package/dist/http/public/assets/bulma/bulma-tooltip.min.css +2 -0
- package/dist/http/public/assets/bulma/bulma.min.css +1 -0
- package/dist/http/public/assets/clipboard/clipboard.min.js +7 -0
- package/dist/http/public/assets/simple-datatables/index.js +12 -0
- package/dist/http/public/assets/simple-datatables/style.css +173 -0
- package/dist/http/routes/cache.d.ts +4 -0
- package/dist/http/routes/cache.d.ts.map +1 -0
- package/dist/http/routes/cache.js +19 -0
- package/dist/http/routes/data.d.ts +4 -0
- package/dist/http/routes/data.d.ts.map +1 -0
- package/dist/http/routes/data.js +104 -0
- package/dist/http/routes/docs.d.ts +3 -0
- package/dist/http/routes/docs.d.ts.map +1 -0
- package/dist/http/routes/docs.js +14 -0
- package/dist/http/routes/dump.d.ts +8 -0
- package/dist/http/routes/dump.d.ts.map +1 -0
- package/dist/http/routes/dump.js +57 -0
- package/dist/http/routes/home.d.ts +3 -0
- package/dist/http/routes/home.d.ts.map +1 -0
- package/dist/http/routes/home.js +17 -0
- package/dist/http/routes/index.d.ts +3 -0
- package/dist/http/routes/index.d.ts.map +1 -0
- package/dist/http/routes/index.js +33 -0
- package/dist/http/routes/query.d.ts +5 -0
- package/dist/http/routes/query.d.ts.map +1 -0
- package/dist/http/routes/query.js +21 -0
- package/dist/http/routes/status.d.ts +9 -0
- package/dist/http/routes/status.d.ts.map +1 -0
- package/dist/http/routes/status.js +74 -0
- package/dist/http/routes/task.d.ts +5 -0
- package/dist/http/routes/task.d.ts.map +1 -0
- package/dist/http/routes/task.js +22 -0
- package/dist/http/views/cacheClear.pug +17 -0
- package/dist/http/views/cacheIndex.pug +19 -0
- package/dist/http/views/data.pug +68 -0
- package/dist/http/views/docs.pug +7 -0
- package/dist/http/views/dumpIndex.pug +14 -0
- package/dist/http/views/home.pug +15 -0
- package/dist/http/views/includes/layout.pug +23 -0
- package/dist/http/views/queryIndex.pug +17 -0
- package/dist/http/views/statusIndex.pug +14 -0
- package/dist/http/views/taskIndex.pug +17 -0
- package/dist/lib/config/config.d.ts +26 -0
- package/dist/lib/config/config.d.ts.map +1 -0
- package/dist/lib/config/config.js +122 -0
- package/dist/lib/config/config.types.d.ts +74 -0
- package/dist/lib/config/config.types.d.ts.map +1 -0
- package/dist/lib/config/config.types.js +2 -0
- package/dist/lib/config/error/InvalidRunMode.d.ts +15 -0
- package/dist/lib/config/error/InvalidRunMode.d.ts.map +1 -0
- package/dist/lib/config/error/InvalidRunMode.js +20 -0
- package/dist/lib/config/error/MissingDirectory.d.ts +24 -0
- package/dist/lib/config/error/MissingDirectory.d.ts.map +1 -0
- package/dist/lib/config/error/MissingDirectory.js +23 -0
- package/dist/lib/config/error/MissingRequiredOption.d.ts +19 -0
- package/dist/lib/config/error/MissingRequiredOption.d.ts.map +1 -0
- package/dist/lib/config/error/MissingRequiredOption.js +21 -0
- package/dist/lib/config/error/NonWritableDirectory.d.ts +24 -0
- package/dist/lib/config/error/NonWritableDirectory.d.ts.map +1 -0
- package/dist/lib/config/error/NonWritableDirectory.js +23 -0
- package/dist/lib/config/error/index.d.ts +5 -0
- package/dist/lib/config/error/index.d.ts.map +1 -0
- package/dist/lib/config/error/index.js +16 -0
- package/dist/lib/config/index.d.ts +2 -0
- package/dist/lib/config/index.d.ts.map +1 -0
- package/dist/lib/config/index.js +13 -0
- package/dist/lib/dataServer.d.ts +21 -0
- package/dist/lib/dataServer.d.ts.map +1 -0
- package/dist/lib/dataServer.js +56 -0
- package/dist/lib/dataServer.types.d.ts +84 -0
- package/dist/lib/dataServer.types.d.ts.map +1 -0
- package/dist/lib/dataServer.types.js +13 -0
- package/dist/lib/error/DomainError.d.ts +9 -0
- package/dist/lib/error/DomainError.d.ts.map +1 -0
- package/dist/lib/error/DomainError.js +20 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +15 -0
- package/dist/lib/query/index.d.ts +3 -0
- package/dist/lib/query/index.d.ts.map +1 -0
- package/dist/lib/query/index.js +14 -0
- package/dist/lib/query/query.types.d.ts +206 -0
- package/dist/lib/query/query.types.d.ts.map +1 -0
- package/dist/lib/query/query.types.js +21 -0
- package/dist/lib/query/queryManager.d.ts +10 -0
- package/dist/lib/query/queryManager.d.ts.map +1 -0
- package/dist/lib/query/queryManager.js +12 -0
- package/dist/lib/query/queryRunner copy.d.ts +3 -0
- package/dist/lib/query/queryRunner copy.d.ts.map +1 -0
- package/dist/lib/query/queryRunner copy.js +87 -0
- package/dist/lib/query/queryRunner.d.ts +3 -0
- package/dist/lib/query/queryRunner.d.ts.map +1 -0
- package/dist/lib/query/queryRunner.js +96 -0
- package/dist/lib/query/queryTagManager.d.ts +3 -0
- package/dist/lib/query/queryTagManager.d.ts.map +1 -0
- package/dist/lib/query/queryTagManager.js +47 -0
- package/dist/lib/store/dataDir/dataDir.types.d.ts +36 -0
- package/dist/lib/store/dataDir/dataDir.types.d.ts.map +1 -0
- package/dist/lib/store/dataDir/dataDir.types.js +2 -0
- package/dist/lib/store/dataDir/dataDirManager.d.ts +3 -0
- package/dist/lib/store/dataDir/dataDirManager.d.ts.map +1 -0
- package/dist/lib/store/dataDir/dataDirManager.js +97 -0
- package/dist/lib/store/dataDir/index.d.ts +2 -0
- package/dist/lib/store/dataDir/index.d.ts.map +1 -0
- package/dist/lib/store/dataDir/index.js +13 -0
- package/dist/lib/store/dependency/dependency.types.d.ts +70 -0
- package/dist/lib/store/dependency/dependency.types.d.ts.map +1 -0
- package/dist/lib/store/dependency/dependency.types.js +2 -0
- package/dist/lib/store/dependency/dependencyFileHelper.d.ts +6 -0
- package/dist/lib/store/dependency/dependencyFileHelper.d.ts.map +1 -0
- package/dist/lib/store/dependency/dependencyFileHelper.js +46 -0
- package/dist/lib/store/dependency/dependencyManager copy.d.ts +6 -0
- package/dist/lib/store/dependency/dependencyManager copy.d.ts.map +1 -0
- package/dist/lib/store/dependency/dependencyManager copy.js +91 -0
- package/dist/lib/store/dependency/dependencyManager.d.ts +6 -0
- package/dist/lib/store/dependency/dependencyManager.d.ts.map +1 -0
- package/dist/lib/store/dependency/dependencyManager.js +78 -0
- package/dist/lib/store/dependency/dependencyManager.types.d.ts +48 -0
- package/dist/lib/store/dependency/dependencyManager.types.d.ts.map +1 -0
- package/dist/lib/store/dependency/dependencyManager.types.js +2 -0
- package/dist/lib/store/dependency/dependencyTagManager.d.ts +6 -0
- package/dist/lib/store/dependency/dependencyTagManager.d.ts.map +1 -0
- package/dist/lib/store/dependency/dependencyTagManager.js +33 -0
- package/dist/lib/store/dependency/dependencyTagger.d.ts +11 -0
- package/dist/lib/store/dependency/dependencyTagger.d.ts.map +1 -0
- package/dist/lib/store/dependency/dependencyTagger.js +99 -0
- package/dist/lib/store/diff/diffManager.d.ts +3 -0
- package/dist/lib/store/diff/diffManager.d.ts.map +1 -0
- package/dist/lib/store/diff/diffManager.js +114 -0
- package/dist/lib/store/diff/diffManager.types.d.ts +50 -0
- package/dist/lib/store/diff/diffManager.types.d.ts.map +1 -0
- package/dist/lib/store/diff/diffManager.types.js +2 -0
- package/dist/lib/store/diff/index.d.ts +2 -0
- package/dist/lib/store/diff/index.d.ts.map +1 -0
- package/dist/lib/store/diff/index.js +13 -0
- package/dist/lib/store/diff/tracker.d.ts +3 -0
- package/dist/lib/store/diff/tracker.d.ts.map +1 -0
- package/dist/lib/store/diff/tracker.js +82 -0
- package/dist/lib/store/diff/tracker.types.d.ts +31 -0
- package/dist/lib/store/diff/tracker.types.d.ts.map +1 -0
- package/dist/lib/store/diff/tracker.types.js +2 -0
- package/dist/lib/store/dump/dumpManager.d.ts +3 -0
- package/dist/lib/store/dump/dumpManager.d.ts.map +1 -0
- package/dist/lib/store/dump/dumpManager.js +199 -0
- package/dist/lib/store/dump/dumpManager.types.d.ts +62 -0
- package/dist/lib/store/dump/dumpManager.types.d.ts.map +1 -0
- package/dist/lib/store/dump/dumpManager.types.js +2 -0
- package/dist/lib/store/dump/index.d.ts +2 -0
- package/dist/lib/store/dump/index.d.ts.map +1 -0
- package/dist/lib/store/dump/index.js +13 -0
- package/dist/lib/store/hook/hook.types.d.ts +205 -0
- package/dist/lib/store/hook/hook.types.d.ts.map +1 -0
- package/dist/lib/store/hook/hook.types.js +2 -0
- package/dist/lib/store/hook/hookManager.d.ts +6 -0
- package/dist/lib/store/hook/hookManager.d.ts.map +1 -0
- package/dist/lib/store/hook/hookManager.js +168 -0
- package/dist/lib/store/hook/index.d.ts +2 -0
- package/dist/lib/store/hook/index.d.ts.map +1 -0
- package/dist/lib/store/hook/index.js +13 -0
- package/dist/lib/store/include/includeIndex.d.ts +6 -0
- package/dist/lib/store/include/includeIndex.d.ts.map +1 -0
- package/dist/lib/store/include/includeIndex.js +65 -0
- package/dist/lib/store/include/includeIndex.types.d.ts +29 -0
- package/dist/lib/store/include/includeIndex.types.d.ts.map +1 -0
- package/dist/lib/store/include/includeIndex.types.js +2 -0
- package/dist/lib/store/include/includeParser.d.ts +3 -0
- package/dist/lib/store/include/includeParser.d.ts.map +1 -0
- package/dist/lib/store/include/includeParser.js +46 -0
- package/dist/lib/store/include/includeParser.types.d.ts +88 -0
- package/dist/lib/store/include/includeParser.types.d.ts.map +1 -0
- package/dist/lib/store/include/includeParser.types.js +2 -0
- package/dist/lib/store/include/index.d.ts +2 -0
- package/dist/lib/store/include/index.d.ts.map +1 -0
- package/dist/lib/store/include/index.js +13 -0
- package/dist/lib/store/include/parsers/configIncludeParser.d.ts +3 -0
- package/dist/lib/store/include/parsers/configIncludeParser.d.ts.map +1 -0
- package/dist/lib/store/include/parsers/configIncludeParser.js +8 -0
- package/dist/lib/store/include/parsers/customIncludeParser.d.ts +3 -0
- package/dist/lib/store/include/parsers/customIncludeParser.d.ts.map +1 -0
- package/dist/lib/store/include/parsers/customIncludeParser.js +8 -0
- package/dist/lib/store/include/parsers/entityIncludeParser.d.ts +3 -0
- package/dist/lib/store/include/parsers/entityIncludeParser.d.ts.map +1 -0
- package/dist/lib/store/include/parsers/entityIncludeParser.js +13 -0
- package/dist/lib/store/include/parsers/index.d.ts +6 -0
- package/dist/lib/store/include/parsers/index.d.ts.map +1 -0
- package/dist/lib/store/include/parsers/index.js +17 -0
- package/dist/lib/store/include/parsers/localeIncludeParser.d.ts +3 -0
- package/dist/lib/store/include/parsers/localeIncludeParser.d.ts.map +1 -0
- package/dist/lib/store/include/parsers/localeIncludeParser.js +8 -0
- package/dist/lib/store/include/parsers/queryIncludeParser.d.ts +11 -0
- package/dist/lib/store/include/parsers/queryIncludeParser.d.ts.map +1 -0
- package/dist/lib/store/include/parsers/queryIncludeParser.js +45 -0
- package/dist/lib/store/include/parsers/types/aliasIncludeParser.d.ts +3 -0
- package/dist/lib/store/include/parsers/types/aliasIncludeParser.d.ts.map +1 -0
- package/dist/lib/store/include/parsers/types/aliasIncludeParser.js +10 -0
- package/dist/lib/store/include/parsers/types/aliasWithoutTypeIncludeParser.d.ts +8 -0
- package/dist/lib/store/include/parsers/types/aliasWithoutTypeIncludeParser.d.ts.map +1 -0
- package/dist/lib/store/include/parsers/types/aliasWithoutTypeIncludeParser.js +18 -0
- package/dist/lib/store/index.d.ts +2 -0
- package/dist/lib/store/index.d.ts.map +1 -0
- package/dist/lib/store/index.js +13 -0
- package/dist/lib/store/store.d.ts +7 -0
- package/dist/lib/store/store.d.ts.map +1 -0
- package/dist/lib/store/store.js +89 -0
- package/dist/lib/store/store.types.d.ts +231 -0
- package/dist/lib/store/store.types.d.ts.map +1 -0
- package/dist/lib/store/store.types.js +2 -0
- package/dist/lib/store/storeManager.d.ts +3 -0
- package/dist/lib/store/storeManager.d.ts.map +1 -0
- package/dist/lib/store/storeManager.js +149 -0
- package/dist/lib/store/workDir/index.d.ts +2 -0
- package/dist/lib/store/workDir/index.d.ts.map +1 -0
- package/dist/lib/store/workDir/index.js +13 -0
- package/dist/lib/store/workDir/storage/getChangedLinesSince.d.ts +9 -0
- package/dist/lib/store/workDir/storage/getChangedLinesSince.d.ts.map +1 -0
- package/dist/lib/store/workDir/storage/getChangedLinesSince.js +47 -0
- package/dist/lib/store/workDir/storage/getDataFromLogLine.d.ts +10 -0
- package/dist/lib/store/workDir/storage/getDataFromLogLine.d.ts.map +1 -0
- package/dist/lib/store/workDir/storage/getDataFromLogLine.js +33 -0
- package/dist/lib/store/workDir/storage/getLogFile.d.ts +8 -0
- package/dist/lib/store/workDir/storage/getLogFile.d.ts.map +1 -0
- package/dist/lib/store/workDir/storage/getLogFile.js +11 -0
- package/dist/lib/store/workDir/storage/index.d.ts +4 -0
- package/dist/lib/store/workDir/storage/index.d.ts.map +1 -0
- package/dist/lib/store/workDir/storage/index.js +20 -0
- package/dist/lib/store/workDir/workDir.types.d.ts +44 -0
- package/dist/lib/store/workDir/workDir.types.d.ts.map +1 -0
- package/dist/lib/store/workDir/workDir.types.js +2 -0
- package/dist/lib/store/workDir/workDirHelper.d.ts +20 -0
- package/dist/lib/store/workDir/workDirHelper.d.ts.map +1 -0
- package/dist/lib/store/workDir/workDirHelper.js +52 -0
- package/dist/lib/task/index.d.ts +3 -0
- package/dist/lib/task/index.d.ts.map +1 -0
- package/dist/lib/task/index.js +14 -0
- package/dist/lib/task/task.types.d.ts +140 -0
- package/dist/lib/task/task.types.d.ts.map +1 -0
- package/dist/lib/task/task.types.js +11 -0
- package/dist/lib/task/taskManager.d.ts +10 -0
- package/dist/lib/task/taskManager.d.ts.map +1 -0
- package/dist/lib/task/taskManager.js +12 -0
- package/dist/lib/task/taskRunner.d.ts +3 -0
- package/dist/lib/task/taskRunner.d.ts.map +1 -0
- package/dist/lib/task/taskRunner.js +71 -0
- package/dist/lib/tsdoc-metadata.json +11 -0
- package/dist/lib/utils/array/arrayUtils.d.ts +2 -0
- package/dist/lib/utils/array/arrayUtils.d.ts.map +1 -0
- package/dist/lib/utils/array/arrayUtils.js +11 -0
- package/dist/lib/utils/cache/cacheBinManager.d.ts +37 -0
- package/dist/lib/utils/cache/cacheBinManager.d.ts.map +1 -0
- package/dist/lib/utils/cache/cacheBinManager.js +53 -0
- package/dist/lib/utils/cache/index.d.ts +2 -0
- package/dist/lib/utils/cache/index.d.ts.map +1 -0
- package/dist/lib/utils/cache/index.js +13 -0
- package/dist/lib/utils/fs/fs.types.d.ts +20 -0
- package/dist/lib/utils/fs/fs.types.d.ts.map +1 -0
- package/dist/lib/utils/fs/fs.types.js +2 -0
- package/dist/lib/utils/fs/fsUtils.d.ts +62 -0
- package/dist/lib/utils/fs/fsUtils.d.ts.map +1 -0
- package/dist/lib/utils/fs/fsUtils.js +137 -0
- package/dist/lib/utils/fs/index.d.ts +2 -0
- package/dist/lib/utils/fs/index.d.ts.map +1 -0
- package/dist/lib/utils/fs/index.js +13 -0
- package/dist/lib/utils/logger/index.d.ts +2 -0
- package/dist/lib/utils/logger/index.d.ts.map +1 -0
- package/dist/lib/utils/logger/index.js +13 -0
- package/dist/lib/utils/logger/logger.d.ts +32 -0
- package/dist/lib/utils/logger/logger.d.ts.map +1 -0
- package/dist/lib/utils/logger/logger.js +82 -0
- package/dist/lib/utils/logger/logger.types.d.ts +37 -0
- package/dist/lib/utils/logger/logger.types.d.ts.map +1 -0
- package/dist/lib/utils/logger/logger.types.js +15 -0
- package/dist/lib/utils/module/dirBasedModuleGroupManager.d.ts +30 -0
- package/dist/lib/utils/module/dirBasedModuleGroupManager.d.ts.map +1 -0
- package/dist/lib/utils/module/dirBasedModuleGroupManager.js +78 -0
- package/dist/lib/utils/module/index.d.ts +3 -0
- package/dist/lib/utils/module/index.d.ts.map +1 -0
- package/dist/lib/utils/module/index.js +14 -0
- package/dist/lib/utils/module/module.types.d.ts +53 -0
- package/dist/lib/utils/module/module.types.d.ts.map +1 -0
- package/dist/lib/utils/module/module.types.js +2 -0
- package/dist/lib/utils/module/moduleManager.d.ts +64 -0
- package/dist/lib/utils/module/moduleManager.d.ts.map +1 -0
- package/dist/lib/utils/module/moduleManager.js +139 -0
- package/dist/lib/utils/object/index.d.ts +2 -0
- package/dist/lib/utils/object/index.d.ts.map +1 -0
- package/dist/lib/utils/object/index.js +13 -0
- package/dist/lib/utils/object/object.types.d.ts +72 -0
- package/dist/lib/utils/object/object.types.d.ts.map +1 -0
- package/dist/lib/utils/object/object.types.js +2 -0
- package/dist/lib/utils/object/objectUtils.d.ts +45 -0
- package/dist/lib/utils/object/objectUtils.d.ts.map +1 -0
- package/dist/lib/utils/object/objectUtils.js +64 -0
- package/dist/lib/utils/string/index.d.ts +2 -0
- package/dist/lib/utils/string/index.d.ts.map +1 -0
- package/dist/lib/utils/string/index.js +13 -0
- package/dist/lib/utils/string/string.types.d.ts +2 -0
- package/dist/lib/utils/string/string.types.d.ts.map +1 -0
- package/dist/lib/utils/string/string.types.js +2 -0
- package/dist/lib/utils/string/stringUtils.d.ts +37 -0
- package/dist/lib/utils/string/stringUtils.d.ts.map +1 -0
- package/dist/lib/utils/string/stringUtils.js +62 -0
- package/dist/lib/watcher/index.d.ts +2 -0
- package/dist/lib/watcher/index.d.ts.map +1 -0
- package/dist/lib/watcher/index.js +13 -0
- package/dist/lib/watcher/watcher.d.ts +17 -0
- package/dist/lib/watcher/watcher.d.ts.map +1 -0
- package/dist/lib/watcher/watcher.js +65 -0
- package/dist/static-suite-data-server.d.ts +392 -0
- package/package.json +102 -0
- package/scripts/copy-http-files-to-src.js +45 -0
- package/src/__tests__/fixtures/data/en/en.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/entity.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/article/article1--card.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/article/article1--small.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/article/article1.json +40 -0
- package/src/__tests__/fixtures/data/en/entity/node/article/article2--card.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/article/article2--small.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/article/article2.json +40 -0
- package/src/__tests__/fixtures/data/en/entity/node/article/article3--card.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/article/article3--small.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/article/article3.json +7 -0
- package/src/__tests__/fixtures/data/en/entity/node/node.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/page/page1--card.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/page/page1--small.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/page/page1.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/page/page2--card.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/page/page2--small.json +3 -0
- package/src/__tests__/fixtures/data/en/entity/node/page/page2.json +3 -0
- package/src/__tests__/fixtures/data/global--block.json +3 -0
- package/src/__tests__/fixtures/data/global.json +3 -0
- package/src/__tests__/fixtures/hook/main.hook.js +15 -0
- package/src/__tests__/fixtures/hook/taxonomy/main.hook.js +15 -0
- package/src/__tests__/fixtures/hook/taxonomy/taxo.hook.js +15 -0
- package/src/__tests__/fixtures/query/error.query.js +6 -0
- package/src/__tests__/fixtures/query/noHandler.query.js +14 -0
- package/src/__tests__/fixtures/query/query1.query.js +15 -0
- package/src/__tests__/fixtures/query/query2.query.js +14 -0
- package/src/__tests__/fixtures/query/wrongNamequery.js +14 -0
- package/src/__tests__/fixtures/task/error.task.js +6 -0
- package/src/__tests__/fixtures/task/noHandler.task.js +13 -0
- package/src/__tests__/fixtures/task/task1.task.js +14 -0
- package/src/__tests__/fixtures/task/task2.task.js +13 -0
- package/src/__tests__/fixtures/task/wrongNametask.js +13 -0
- package/src/bin/serve.ts +107 -0
- package/src/http/httpServer.ts +21 -0
- package/src/http/routes/cache.ts +17 -0
- package/src/http/routes/data.ts +114 -0
- package/src/http/routes/docs.ts +9 -0
- package/src/http/routes/dump.ts +61 -0
- package/src/http/routes/home.ts +16 -0
- package/src/http/routes/index.ts +47 -0
- package/src/http/routes/query.ts +27 -0
- package/src/http/routes/status.ts +89 -0
- package/src/http/routes/task.ts +29 -0
- package/src/http/views/cacheClear.pug +17 -0
- package/src/http/views/cacheIndex.pug +19 -0
- package/src/http/views/data.pug +68 -0
- package/src/http/views/docs.pug +7 -0
- package/src/http/views/dumpIndex.pug +14 -0
- package/src/http/views/home.pug +15 -0
- package/src/http/views/includes/layout.pug +23 -0
- package/src/http/views/queryIndex.pug +17 -0
- package/src/http/views/statusIndex.pug +14 -0
- package/src/http/views/taskIndex.pug +17 -0
- package/src/lib/config/__tests__/config.test.ts +132 -0
- package/src/lib/config/config.ts +143 -0
- package/src/lib/config/config.types.ts +87 -0
- package/src/lib/config/error/InvalidRunMode.ts +17 -0
- package/src/lib/config/error/MissingDirectory.ts +30 -0
- package/src/lib/config/error/MissingRequiredOption.ts +23 -0
- package/src/lib/config/error/NonWritableDirectory.ts +30 -0
- package/src/lib/config/error/index.ts +4 -0
- package/src/lib/config/index.ts +1 -0
- package/src/lib/dataServer.ts +81 -0
- package/src/lib/dataServer.types.ts +98 -0
- package/src/lib/error/DomainError.ts +18 -0
- package/src/lib/index.ts +4 -0
- package/src/lib/query/__tests__/queryRunner.test.ts +61 -0
- package/src/lib/query/index.ts +2 -0
- package/src/lib/query/query.types.ts +231 -0
- package/src/lib/query/queryManager.ts +11 -0
- package/src/lib/query/queryRunner.ts +110 -0
- package/src/lib/query/queryTagManager.ts +53 -0
- package/src/lib/store/dataDir/__tests__/dataDirManager.test.ts +15 -0
- package/src/lib/store/dataDir/dataDir.types.ts +38 -0
- package/src/lib/store/dataDir/dataDirManager.ts +121 -0
- package/src/lib/store/dataDir/index.ts +1 -0
- package/src/lib/store/dependency/dependency.types.ts +78 -0
- package/src/lib/store/dependency/dependencyFileHelper.ts +50 -0
- package/src/lib/store/dependency/dependencyManager.ts +82 -0
- package/src/lib/store/dependency/dependencyTagger.ts +105 -0
- package/src/lib/store/diff/diffManager.ts +122 -0
- package/src/lib/store/diff/diffManager.types.ts +51 -0
- package/src/lib/store/diff/index.ts +1 -0
- package/src/lib/store/dump/dumpManager.ts +235 -0
- package/src/lib/store/dump/dumpManager.types.ts +61 -0
- package/src/lib/store/dump/index.ts +1 -0
- package/src/lib/store/hook/hook.types.ts +232 -0
- package/src/lib/store/hook/hookManager.ts +180 -0
- package/src/lib/store/hook/index.ts +1 -0
- package/src/lib/store/include/__tests__/includeParser.test.ts +80 -0
- package/src/lib/store/include/includeParser.ts +54 -0
- package/src/lib/store/include/includeParser.types.ts +99 -0
- package/src/lib/store/include/index.ts +1 -0
- package/src/lib/store/include/parsers/__tests__/entityIncludeParser.test.ts +43 -0
- package/src/lib/store/include/parsers/configIncludeParser.ts +8 -0
- package/src/lib/store/include/parsers/customIncludeParser.ts +8 -0
- package/src/lib/store/include/parsers/entityIncludeParser.ts +15 -0
- package/src/lib/store/include/parsers/index.ts +5 -0
- package/src/lib/store/include/parsers/localeIncludeParser.ts +8 -0
- package/src/lib/store/include/parsers/queryIncludeParser.ts +51 -0
- package/src/lib/store/include/parsers/types/__tests__/aliasIncludeParser.test.ts +37 -0
- package/src/lib/store/include/parsers/types/__tests__/aliasWithoutTypeIncludeParser.test.ts +43 -0
- package/src/lib/store/include/parsers/types/aliasIncludeParser.ts +13 -0
- package/src/lib/store/include/parsers/types/aliasWithoutTypeIncludeParser.ts +22 -0
- package/src/lib/store/index.ts +1 -0
- package/src/lib/store/store.ts +105 -0
- package/src/lib/store/store.types.ts +251 -0
- package/src/lib/store/storeManager.ts +187 -0
- package/src/lib/store/workDir/__tests__/workDirHelper.test.ts +25 -0
- package/src/lib/store/workDir/index.ts +1 -0
- package/src/lib/store/workDir/storage/__tests__/getChangedLinesSince.test.ts +23 -0
- package/src/lib/store/workDir/storage/__tests__/getDataFromLogLine.test.ts +21 -0
- package/src/lib/store/workDir/storage/getChangedLinesSince.ts +47 -0
- package/src/lib/store/workDir/storage/getDataFromLogLine.ts +31 -0
- package/src/lib/store/workDir/storage/getLogFile.ts +11 -0
- package/src/lib/store/workDir/storage/index.ts +8 -0
- package/src/lib/store/workDir/workDir.types.ts +48 -0
- package/src/lib/store/workDir/workDirHelper.ts +59 -0
- package/src/lib/task/__tests__/taskRunner.test.ts +47 -0
- package/src/lib/task/index.ts +2 -0
- package/src/lib/task/task.types.ts +151 -0
- package/src/lib/task/taskManager.ts +11 -0
- package/src/lib/task/taskRunner.ts +79 -0
- package/src/lib/utils/array/__tests__/arrayUtils.test.ts +16 -0
- package/src/lib/utils/array/arrayUtils.ts +7 -0
- package/src/lib/utils/cache/__tests__/cache.test.ts +24 -0
- package/src/lib/utils/cache/cacheBinManager.ts +88 -0
- package/src/lib/utils/cache/index.ts +1 -0
- package/src/lib/utils/fs/__tests__/fixtures/file.json +3 -0
- package/src/lib/utils/fs/__tests__/fixtures/file.txt +3 -0
- package/src/lib/utils/fs/__tests__/fsUtils.test.ts +93 -0
- package/src/lib/utils/fs/fs.types.ts +21 -0
- package/src/lib/utils/fs/fsUtils.ts +141 -0
- package/src/lib/utils/fs/index.ts +1 -0
- package/src/lib/utils/logger/__tests__/logger.test.ts +12 -0
- package/src/lib/utils/logger/index.ts +1 -0
- package/src/lib/utils/logger/logger.ts +87 -0
- package/src/lib/utils/logger/logger.types.ts +41 -0
- package/src/lib/utils/module/__mocks__/dummyModule.query.js +4 -0
- package/src/lib/utils/module/__mocks__/dummyModule2.query.js +4 -0
- package/src/lib/utils/module/__tests__/dirBasedModuleGroupManager.test.ts +34 -0
- package/src/lib/utils/module/__tests__/moduleHandler.test.ts +100 -0
- package/src/lib/utils/module/dirBasedModuleGroupManager.ts +78 -0
- package/src/lib/utils/module/index.ts +2 -0
- package/src/lib/utils/module/module.types.ts +57 -0
- package/src/lib/utils/module/moduleManager.ts +144 -0
- package/src/lib/utils/object/__tests__/objectUtils.test.ts +62 -0
- package/src/lib/utils/object/index.ts +1 -0
- package/src/lib/utils/object/object.types.ts +74 -0
- package/src/lib/utils/object/objectUtils.ts +71 -0
- package/src/lib/utils/string/__tests__/stringUtils.test.ts +30 -0
- package/src/lib/utils/string/index.ts +1 -0
- package/src/lib/utils/string/string.types.ts +1 -0
- package/src/lib/utils/string/stringUtils.ts +61 -0
- package/src/lib/watcher/index.ts +1 -0
- package/src/lib/watcher/watcher.ts +66 -0
- package/tsconfig.json +83 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getModificationDate } from '@lib/utils/fs';
|
|
2
|
+
import { logger } from '@lib/utils/logger';
|
|
3
|
+
import { ChangedFiles, LogLineData } from './workDir.types';
|
|
4
|
+
import {
|
|
5
|
+
getLogFile,
|
|
6
|
+
getChangedLinesSince,
|
|
7
|
+
getDataFromLogLine,
|
|
8
|
+
} from './storage';
|
|
9
|
+
|
|
10
|
+
export const workDirHelper = {
|
|
11
|
+
/**
|
|
12
|
+
* Gets date of last modification of work directory.
|
|
13
|
+
*
|
|
14
|
+
* @returns The date of last modification of work directory, or null if directory not found.
|
|
15
|
+
*/
|
|
16
|
+
getModificationDate: (): Date | null => {
|
|
17
|
+
const logFile = getLogFile();
|
|
18
|
+
return logFile ? getModificationDate(logFile) : null;
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get changed files since a date.
|
|
23
|
+
*
|
|
24
|
+
* @param sinceDate - Date to search
|
|
25
|
+
*
|
|
26
|
+
* @returns Object with two properties:
|
|
27
|
+
* - updated: array of changed files.
|
|
28
|
+
* - deleted: array of deleted files.
|
|
29
|
+
*/
|
|
30
|
+
getChangedFilesSince: (sinceDate: Date): ChangedFiles => {
|
|
31
|
+
const changedLines = getChangedLinesSince(sinceDate);
|
|
32
|
+
const lineData: Record<string, LogLineData> = {};
|
|
33
|
+
changedLines.forEach(line => {
|
|
34
|
+
const dataFromLogLine = getDataFromLogLine(line);
|
|
35
|
+
if (dataFromLogLine) {
|
|
36
|
+
// Save lines keyed by its relativePath so only the last
|
|
37
|
+
// operation on the same file is processed.
|
|
38
|
+
lineData[dataFromLogLine.file.relativePath] = dataFromLogLine;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const lineDataArray: LogLineData[] = Object.values(lineData);
|
|
42
|
+
|
|
43
|
+
const updated = lineDataArray
|
|
44
|
+
.filter(data => data.operation === 'write')
|
|
45
|
+
.map(data => data.file.relativePath);
|
|
46
|
+
updated.forEach(file => {
|
|
47
|
+
logger.debug(`Found updated file "${file}"`);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const deleted = lineDataArray
|
|
51
|
+
.filter(data => data.operation === 'delete')
|
|
52
|
+
.map(data => data.file.relativePath);
|
|
53
|
+
deleted.forEach(file => {
|
|
54
|
+
logger.debug(`Found deleted file "${file}"`);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return { updated, deleted };
|
|
58
|
+
},
|
|
59
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { config } from '@lib/config';
|
|
4
|
+
import { RunMode } from '@lib/dataServer.types';
|
|
5
|
+
import { logger } from '@lib/utils/logger';
|
|
6
|
+
import { isTaskErrorResponse } from '../task.types';
|
|
7
|
+
import { taskRunner } from '../taskRunner';
|
|
8
|
+
import { taskManager } from '../taskManager';
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
config.taskDir = fs.realpathSync(path.resolve('src/__tests__/fixtures/task'));
|
|
12
|
+
config.runMode = RunMode.PROD;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('TaskRunner test', () => {
|
|
16
|
+
describe('getAvailableTaskIds', () => {
|
|
17
|
+
it('Returns correct tasks ids from fixtures', () => {
|
|
18
|
+
expect(Array.from(taskManager.getModuleGroupInfo().keys())).toEqual([
|
|
19
|
+
'error',
|
|
20
|
+
'noHandler',
|
|
21
|
+
'task1',
|
|
22
|
+
'task2',
|
|
23
|
+
]);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('run', () => {
|
|
28
|
+
it('Returns task data', () => {
|
|
29
|
+
const taskResponse = taskRunner.run('task1', {
|
|
30
|
+
x: 'x',
|
|
31
|
+
y: '33',
|
|
32
|
+
});
|
|
33
|
+
const data = !isTaskErrorResponse(taskResponse) && taskResponse.data[0];
|
|
34
|
+
expect(data.id).toEqual('33');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('Logs error when task fails', () => {
|
|
38
|
+
logger.error = jest.fn();
|
|
39
|
+
try {
|
|
40
|
+
taskRunner.run('error', {});
|
|
41
|
+
} catch (e) {
|
|
42
|
+
// none
|
|
43
|
+
}
|
|
44
|
+
expect(logger.error).toHaveBeenCalled();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Store } from '@lib/store/store.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A service to handle the execution of tasks.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type TaskRunner = {
|
|
9
|
+
/**
|
|
10
|
+
* Runs a task and returns its results with metadata.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* It checks several validations before a task is run, and then task is executed.
|
|
14
|
+
*
|
|
15
|
+
* It logs an error and throws an exception if any problem occurs during the
|
|
16
|
+
* task execution.
|
|
17
|
+
*
|
|
18
|
+
* @param taskId - Task ID (filename without extension and suffix) of the task
|
|
19
|
+
* to be executed. @see {@link ModuleInfo#id | Definition of a module ID}
|
|
20
|
+
* @param args - Optional object with task arguments.
|
|
21
|
+
*
|
|
22
|
+
* @returns The result of the task as a JSON object with data and metadata keys,
|
|
23
|
+
* or an error response if some validation is not met.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* Here's a result example:
|
|
27
|
+
* ```
|
|
28
|
+
* {
|
|
29
|
+
* data: ['title 1', 'title 2'],
|
|
30
|
+
* metadata: {
|
|
31
|
+
* contentType: 'application/json',
|
|
32
|
+
* execTime: 2,
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
|
|
37
|
+
* @throws
|
|
38
|
+
* Exception thrown if any problem occurs during the task execution.
|
|
39
|
+
*/
|
|
40
|
+
run(
|
|
41
|
+
taskId: string,
|
|
42
|
+
args: TaskArgs,
|
|
43
|
+
): TaskSuccessfulResponse | TaskErrorResponse;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* An object with task arguments.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export type TaskArgs = Record<string, any>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The result that a task returns after being executed.
|
|
55
|
+
*/
|
|
56
|
+
export type TaskModuleResult = {
|
|
57
|
+
/**
|
|
58
|
+
* A result, which can be of any kind (and array, an object, a string, etc)
|
|
59
|
+
*/
|
|
60
|
+
result: any;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Optional content type for the data available in "result"
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* Data coming from the task can be anything (XML, a string, etc).
|
|
67
|
+
* This content type is added to the metadata section of the TaskResponse.
|
|
68
|
+
* @see {@link TaskSuccessfulResponse#metadata}.
|
|
69
|
+
*
|
|
70
|
+
* @defaultValue 'application/json'
|
|
71
|
+
*/
|
|
72
|
+
contentType?: string;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A successful response returned after executing a task.
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* It takes the results from a TaskModule#taskHandler, and wraps them into an
|
|
80
|
+
* structure with metadata. @see {@link TaskModule#default}
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export type TaskSuccessfulResponse = {
|
|
85
|
+
/**
|
|
86
|
+
* Data returned by the task. @see {@link TaskModule#default}
|
|
87
|
+
*/
|
|
88
|
+
data: any;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Task metadata
|
|
92
|
+
*/
|
|
93
|
+
metadata: {
|
|
94
|
+
/**
|
|
95
|
+
* Content type for the data available in "data"
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* Even thought this structure is a JSON object, data coming from the
|
|
99
|
+
* task can be anything (XML, a string, etc). It must be specified so any
|
|
100
|
+
* consumer of this data knows what is being returned.
|
|
101
|
+
*/
|
|
102
|
+
contentType: string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Execution time taken by the task, in milliseconds.
|
|
106
|
+
*/
|
|
107
|
+
execTimeMs: number;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A module that defines a task.
|
|
113
|
+
*/
|
|
114
|
+
export type TaskModule = {
|
|
115
|
+
/**
|
|
116
|
+
* The handler that executes a task.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* It receives the store data and a set of arguments, executes the task
|
|
120
|
+
* and returns its results.
|
|
121
|
+
*
|
|
122
|
+
* @param options - An object with options for the task: store and args
|
|
123
|
+
*/
|
|
124
|
+
default(options: { store: Store; args: TaskArgs }): TaskModuleResult;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* An error response returned after executing a task.
|
|
128
|
+
*
|
|
129
|
+
* @remarks
|
|
130
|
+
* It takes an string from TaskModule#taskHandler, and wraps them into an
|
|
131
|
+
* structure with metadata. @see {@link TaskModule#default}
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
export type TaskErrorResponse = {
|
|
136
|
+
/**
|
|
137
|
+
* Error message from the task, usually coming from a failed validation.
|
|
138
|
+
*/
|
|
139
|
+
error: string;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Tells whether a task response is erroneous or not.
|
|
144
|
+
*
|
|
145
|
+
* @param taskResponse - A response (successful or erroneous) from the task handler.
|
|
146
|
+
* @returns True if taskResponse is erroneous.
|
|
147
|
+
*/
|
|
148
|
+
export const isTaskErrorResponse = (
|
|
149
|
+
taskResponse: TaskSuccessfulResponse | TaskErrorResponse,
|
|
150
|
+
): taskResponse is TaskErrorResponse =>
|
|
151
|
+
(taskResponse as TaskErrorResponse).error !== undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { dirBasedModuleGroupManager } from '@lib/utils/module';
|
|
2
|
+
import { TaskModule } from './task.types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A manager for tasks stored in a user-land directory defined by configuration.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* It extends dirBasedModuleGroupManager, which manages groups of modules based
|
|
9
|
+
* on a directory: @see {@link dirBasedModuleGroupManager}
|
|
10
|
+
*/
|
|
11
|
+
export const taskManager = dirBasedModuleGroupManager<TaskModule>('task');
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import microtime from 'microtime';
|
|
2
|
+
import { config } from '@lib/config';
|
|
3
|
+
import { store } from '@lib/store';
|
|
4
|
+
import { logger } from '@lib/utils/logger';
|
|
5
|
+
import { taskManager } from './taskManager';
|
|
6
|
+
import {
|
|
7
|
+
TaskRunner,
|
|
8
|
+
TaskErrorResponse,
|
|
9
|
+
TaskSuccessfulResponse,
|
|
10
|
+
TaskModuleResult,
|
|
11
|
+
} from './task.types';
|
|
12
|
+
|
|
13
|
+
let count = 0;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a TaskErrorResponse object ready to be returned to clients.
|
|
17
|
+
*
|
|
18
|
+
* @param message - Error message
|
|
19
|
+
*
|
|
20
|
+
* @returns A JSON object with an error key
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
const createErrorResponse = (message: string): TaskErrorResponse => {
|
|
25
|
+
logger.error(message);
|
|
26
|
+
return { error: message };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const taskRunner: TaskRunner = {
|
|
30
|
+
run: (taskId, args): TaskSuccessfulResponse | TaskErrorResponse => {
|
|
31
|
+
if (!config.taskDir) {
|
|
32
|
+
return createErrorResponse('No task directory ("taskDir") configured');
|
|
33
|
+
}
|
|
34
|
+
if (!taskId) {
|
|
35
|
+
return createErrorResponse('No task ID received');
|
|
36
|
+
}
|
|
37
|
+
const taskModuleInfo = taskManager.getModuleGroupInfo().get(taskId);
|
|
38
|
+
if (!taskModuleInfo) {
|
|
39
|
+
return createErrorResponse(`Task module for ID ${taskId} not found`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
count += 1;
|
|
43
|
+
const startDate = microtime.now();
|
|
44
|
+
const argsString = JSON.stringify(args);
|
|
45
|
+
logger.debug(`#${count} Task started: "${taskId}", args "${argsString}"`);
|
|
46
|
+
const taskResult: TaskModuleResult = {
|
|
47
|
+
result: undefined,
|
|
48
|
+
contentType: undefined,
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
const taskModule = taskModuleInfo.getModule();
|
|
52
|
+
const taskResponse = taskModule.default({
|
|
53
|
+
store,
|
|
54
|
+
args,
|
|
55
|
+
});
|
|
56
|
+
taskResult.result = taskResponse?.result;
|
|
57
|
+
|
|
58
|
+
taskResult.contentType = taskResponse?.contentType || 'application/json';
|
|
59
|
+
} catch (e) {
|
|
60
|
+
// Log error and rethrow.
|
|
61
|
+
logger.error(
|
|
62
|
+
`#${count} Task error: "${taskId}", args "${argsString}": ${e}`,
|
|
63
|
+
);
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
const execTimeMs = (microtime.now() - startDate) / 1000;
|
|
67
|
+
const response: TaskSuccessfulResponse = {
|
|
68
|
+
data: taskResult.result,
|
|
69
|
+
metadata: {
|
|
70
|
+
contentType: taskResult.contentType || 'application/json',
|
|
71
|
+
execTimeMs,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
logger.debug(`#${count} Task "${taskId}" took ${execTimeMs} ms.`);
|
|
76
|
+
|
|
77
|
+
return response;
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { arrayRemoveByValue } from '../arrayUtils';
|
|
2
|
+
|
|
3
|
+
describe('Array utils test', () => {
|
|
4
|
+
describe('arrayRemoveByValue', () => {
|
|
5
|
+
it('removes an existing array item by value', () => {
|
|
6
|
+
const arr = [1, 2, 3];
|
|
7
|
+
arrayRemoveByValue(arr, 2);
|
|
8
|
+
expect(arr).toEqual([1, 3]);
|
|
9
|
+
});
|
|
10
|
+
it('leaves untouched an array when removing a non existing array item by value', () => {
|
|
11
|
+
const arr = [1, 2, 3];
|
|
12
|
+
arrayRemoveByValue(arr, 4);
|
|
13
|
+
expect(arr).toEqual([1, 2, 3]);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { cache } from '../cacheBinManager';
|
|
2
|
+
|
|
3
|
+
describe('Cache test', () => {
|
|
4
|
+
it('newly created cache bins are empty', () => {
|
|
5
|
+
expect(cache.bin('bin1').size).toBe(0);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('using several cache bins does not affect any of them', () => {
|
|
9
|
+
cache.bin('bin1').set('key1', 'value1');
|
|
10
|
+
cache.bin('bin2').set('key2', 'value2');
|
|
11
|
+
|
|
12
|
+
expect(cache.bin('bin1').get('key1')).toBe('value1');
|
|
13
|
+
expect(cache.bin('bin2').get('key2')).toBe('value2');
|
|
14
|
+
expect(cache.bin('bin1').size).toBe(1);
|
|
15
|
+
expect(cache.bin('bin2').size).toBe(1);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('gets the keys of all cache bins', () => {
|
|
19
|
+
cache.bin('bin1');
|
|
20
|
+
cache.bin('bin2');
|
|
21
|
+
|
|
22
|
+
expect(cache.keys()).toEqual(['bin1', 'bin2']);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type CacheBin<Type> = Map<string, Type>;
|
|
2
|
+
|
|
3
|
+
export type Cache = {
|
|
4
|
+
/**
|
|
5
|
+
* Gets a cache bin by its id.
|
|
6
|
+
*
|
|
7
|
+
* @param binId - The id of the bin.
|
|
8
|
+
* @returns The cache bin.
|
|
9
|
+
*/
|
|
10
|
+
bin<Type>(binId: string): CacheBin<Type>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns a boolean indicating whether a cache bin
|
|
14
|
+
* with the specified key exists or not.
|
|
15
|
+
*
|
|
16
|
+
* @param binId - The id of the bin.
|
|
17
|
+
* @returns True if the cache bin exists, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
has(binId: string): boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Gets an array of keys of all available cache bins.
|
|
23
|
+
*
|
|
24
|
+
* @returns An array of cache bin keys.
|
|
25
|
+
*/
|
|
26
|
+
keys(): string[];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Clears all available cache bins.
|
|
30
|
+
*/
|
|
31
|
+
clear(): void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const data = new Map<string, CacheBin<any>>();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Initializes a cache bin.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* If a cache bin already exists, it clears it, creating a new one.
|
|
41
|
+
* If the cache bin doesn't exist, it simply creates it.
|
|
42
|
+
*
|
|
43
|
+
* @param binId - The id of the bin.
|
|
44
|
+
* @returns The initialized cache bin.
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
const initBin = <Type>(binId: string): CacheBin<Type> => {
|
|
48
|
+
data.set(binId, new Map<string, Type>());
|
|
49
|
+
return data.get(binId) as CacheBin<Type>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Cache system based on specialized bins.
|
|
54
|
+
*
|
|
55
|
+
* All cache items belong to a specific bin ("file", "query", etc),
|
|
56
|
+
* which is a kind of "folder" or "directory" where data belonging
|
|
57
|
+
* to the same context/domain is stored altogether.
|
|
58
|
+
*/
|
|
59
|
+
export const cache: Cache = {
|
|
60
|
+
bin: <Type>(binId: string): CacheBin<Type> => {
|
|
61
|
+
return (data.get(binId) as CacheBin<Type>) || initBin<Type>(binId);
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Returns a boolean indicating whether a cache bin
|
|
66
|
+
* with the specified key exists or not.
|
|
67
|
+
*
|
|
68
|
+
* @param binId - The id of the bin.
|
|
69
|
+
* @returns True if the cache bin exists, false otherwise.
|
|
70
|
+
*/
|
|
71
|
+
has: binId => data.has(binId),
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets an array of keys of all available cache bins.
|
|
75
|
+
*
|
|
76
|
+
* @returns An array of cache bin keys.
|
|
77
|
+
*/
|
|
78
|
+
keys: () => Array.from(data.keys()),
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Gets an array of keys of all available cache bins.
|
|
82
|
+
*
|
|
83
|
+
* @returns An array of cache bin keys.
|
|
84
|
+
*/
|
|
85
|
+
clear: () => {
|
|
86
|
+
data.clear();
|
|
87
|
+
},
|
|
88
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cacheBinManager';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { logger } from '@lib/utils/logger';
|
|
4
|
+
import {
|
|
5
|
+
readFile,
|
|
6
|
+
getFileContent,
|
|
7
|
+
findFilesInDir,
|
|
8
|
+
getModificationDate,
|
|
9
|
+
isJsonFile,
|
|
10
|
+
} from '../fsUtils';
|
|
11
|
+
|
|
12
|
+
const fixturesDir = path.join(__dirname, './fixtures/');
|
|
13
|
+
const jsonFixturePath = path.join(fixturesDir, 'file.json');
|
|
14
|
+
const jsonRawValue = fs.readFileSync(jsonFixturePath, 'utf8');
|
|
15
|
+
const jsonParsedValue = JSON.parse(jsonRawValue);
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
logger.error = jest.fn();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('File System utils test', () => {
|
|
22
|
+
describe('isJsonFile', () => {
|
|
23
|
+
it('detects a valid JSON filepath', () => {
|
|
24
|
+
expect(isJsonFile('valid-file.json')).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
it('detects an invalid JSON filepath', () => {
|
|
27
|
+
expect(isJsonFile('invalid-file.txt')).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('readFile', () => {
|
|
32
|
+
it('reads an existing filepath without logging any error', () => {
|
|
33
|
+
expect(readFile(jsonFixturePath)).toBe(jsonRawValue);
|
|
34
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
it('logs an error when reading a non-existing filepath', () => {
|
|
37
|
+
expect(readFile('invalid-path')).toBeNull();
|
|
38
|
+
expect(logger.error).toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('getFileContent', () => {
|
|
43
|
+
describe('when a file exists', () => {
|
|
44
|
+
describe('if it is a JSON file', () => {
|
|
45
|
+
it('returns an object with non-null "raw" and "json" properties ', () => {
|
|
46
|
+
const fileContent = getFileContent(jsonFixturePath);
|
|
47
|
+
expect(fileContent.json).toStrictEqual(jsonParsedValue);
|
|
48
|
+
expect(fileContent.raw).toBe(jsonRawValue);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('if it is not a JSON file', () => {
|
|
52
|
+
it('returns an object with a non-null "raw" property and a null "json" property', () => {
|
|
53
|
+
const txtFixturePath = path.join(fixturesDir, 'file.txt');
|
|
54
|
+
const txtRawValue = fs.readFileSync(txtFixturePath, 'utf8');
|
|
55
|
+
|
|
56
|
+
const fileContent = getFileContent(txtFixturePath);
|
|
57
|
+
|
|
58
|
+
expect(fileContent.json).toBeNull();
|
|
59
|
+
expect(fileContent.raw).toBe(txtRawValue);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('when a file does not exist', () => {
|
|
64
|
+
it('returns an object with null "raw" and "json" properties', () => {
|
|
65
|
+
const fileContent = getFileContent('invalid-path');
|
|
66
|
+
expect(fileContent.json).toBeNull();
|
|
67
|
+
expect(fileContent.raw).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('findFilesInDir', () => {
|
|
73
|
+
it('finds a file non-recursively in a directory', () => {
|
|
74
|
+
const filesInDir = findFilesInDir(fixturesDir, '*.txt');
|
|
75
|
+
expect(filesInDir).toStrictEqual(['file.txt']);
|
|
76
|
+
});
|
|
77
|
+
it('finds several files recursively in a directory', () => {
|
|
78
|
+
const filesInDir = findFilesInDir(fixturesDir);
|
|
79
|
+
expect(filesInDir).toStrictEqual(['file.json', 'file.txt']);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('getModificationDate', () => {
|
|
84
|
+
it('returns a Date for an existing filepath without logging any error', () => {
|
|
85
|
+
expect(getModificationDate(jsonFixturePath) instanceof Date).toBe(true);
|
|
86
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
87
|
+
});
|
|
88
|
+
it('returns null and logs an error for a non-existing filepath', () => {
|
|
89
|
+
expect(getModificationDate('invalid-path')).toBeNull();
|
|
90
|
+
expect(logger.error).toHaveBeenCalled();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Json } from '@lib/utils/object/object.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An object that represents a file's contents.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Object with two properties, "raw" and "json", which contain
|
|
8
|
+
* the raw and json version of the file. If file is not a JSON, the "json"
|
|
9
|
+
* property is null. If file is not found, both properties are null.
|
|
10
|
+
*/
|
|
11
|
+
export type FileType = {
|
|
12
|
+
/**
|
|
13
|
+
* The raw contents of the file, as a string. Null if file is not found.
|
|
14
|
+
*/
|
|
15
|
+
raw: string | null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The file contents parsed as JSON, if file is a JSON file. Null if not a JSON file.
|
|
19
|
+
*/
|
|
20
|
+
json: Json | null;
|
|
21
|
+
};
|