@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,141 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import fg, { Options as fastGlobOptions } from 'fast-glob';
|
|
3
|
+
import chokidar from 'chokidar';
|
|
4
|
+
import { logger } from '@lib/utils/logger';
|
|
5
|
+
import { parseJsonString } from '@lib/utils/string';
|
|
6
|
+
import { FileType } from './fs.types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Tells whether a path is JSON or not.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* A fast checker that avoids reading the contents of a file, or doing
|
|
13
|
+
* some other complex operation to determine if a file contains JSON data.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export const isJsonFile = (filepath: string): boolean =>
|
|
18
|
+
filepath.slice(-5) === '.json';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Reads a file and logs an error on failure.
|
|
22
|
+
*
|
|
23
|
+
* @param filePath - A path to a file.
|
|
24
|
+
*
|
|
25
|
+
* @returns The file contents as a string if file is found, or null otherwise.
|
|
26
|
+
*/
|
|
27
|
+
export const readFile = (filePath: string): string | null => {
|
|
28
|
+
let content = null;
|
|
29
|
+
try {
|
|
30
|
+
content = fs.readFileSync(filePath, { encoding: 'utf8', flag: 'r' });
|
|
31
|
+
} catch (error) {
|
|
32
|
+
// When an error is thrown, content is undefined, so ensure
|
|
33
|
+
// it is converted to null.
|
|
34
|
+
content = null;
|
|
35
|
+
logger.error(`Error reading file "${filePath}": ${error}`);
|
|
36
|
+
}
|
|
37
|
+
return content;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gets raw and JSON parsed content from a file.
|
|
42
|
+
*
|
|
43
|
+
* @param filepath - A path to a file.
|
|
44
|
+
*
|
|
45
|
+
* @returns Object with two properties, "raw" and "json", which contain
|
|
46
|
+
* the raw and json version of the file. If file is not a JSON, the "json"
|
|
47
|
+
* property is null. If file is not found, both properties are null.
|
|
48
|
+
*/
|
|
49
|
+
export const getFileContent = (filepath: string): FileType => {
|
|
50
|
+
const raw = readFile(filepath);
|
|
51
|
+
let json = null;
|
|
52
|
+
if (raw && isJsonFile(filepath)) {
|
|
53
|
+
json = parseJsonString(raw);
|
|
54
|
+
if (!json) {
|
|
55
|
+
logger.error(`Error getting JSON from file "${filepath}"`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { raw, json };
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Finds all files inside a directory
|
|
63
|
+
*
|
|
64
|
+
* @param dir - Absolute path to the directory to be scanned
|
|
65
|
+
* @param glob - Optional glob to filter results (default all files recursive '**\/*')
|
|
66
|
+
* @param options - Options for the fast-glob package.
|
|
67
|
+
* See https://www.npmjs.com/package/fast-glob for reference .
|
|
68
|
+
*
|
|
69
|
+
* @returns Array of file paths found inside directory
|
|
70
|
+
*/
|
|
71
|
+
export const findFilesInDir = (
|
|
72
|
+
dir: string,
|
|
73
|
+
glob = '**/*',
|
|
74
|
+
options: fastGlobOptions = { absolute: false },
|
|
75
|
+
): string[] => {
|
|
76
|
+
const startDate = Date.now();
|
|
77
|
+
const files = fg.sync([glob], { cwd: dir, ...options });
|
|
78
|
+
const endDate = Date.now();
|
|
79
|
+
logger.debug(
|
|
80
|
+
`${files.length} files found inside ${dir} in ${endDate - startDate}ms.`,
|
|
81
|
+
);
|
|
82
|
+
return files;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Gets a file's modification date and logs an error on failure.
|
|
87
|
+
*
|
|
88
|
+
* @param filePath - Path to the file
|
|
89
|
+
*
|
|
90
|
+
* @returns The file's modification date as a Date object, or null on error
|
|
91
|
+
*/
|
|
92
|
+
export const getModificationDate = (filePath: string): Date | null => {
|
|
93
|
+
let modificationDate = null;
|
|
94
|
+
try {
|
|
95
|
+
modificationDate = new Date(fs.statSync(filePath).mtime);
|
|
96
|
+
} catch (e) {
|
|
97
|
+
logger.error(`Error getting modification date for ${`path`}: ${e}`);
|
|
98
|
+
}
|
|
99
|
+
return modificationDate;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Watches for changes on a set of paths and attach listener to them
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* It handles three different events: add, change and unlink
|
|
107
|
+
*
|
|
108
|
+
* @param paths - An array of paths to be watched
|
|
109
|
+
* @param listeners - An object with three optional event keys (add, change and unlink)
|
|
110
|
+
* and a listener function as value. That function will be executed once any of
|
|
111
|
+
* the event keys is dispatched.
|
|
112
|
+
*/
|
|
113
|
+
export const watch = (
|
|
114
|
+
paths: string[],
|
|
115
|
+
listeners: Record<'add' | 'change' | 'unlink', (filePath: string) => void>,
|
|
116
|
+
): void => {
|
|
117
|
+
if (paths.length > 0) {
|
|
118
|
+
const watcher = chokidar.watch(paths, {
|
|
119
|
+
ignored: /(^|[/\\])\../,
|
|
120
|
+
persistent: true,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Add event listeners.
|
|
124
|
+
watcher.on('ready', () => {
|
|
125
|
+
logger.debug(`Watcher listening for changes on ${paths.join(',')}`);
|
|
126
|
+
watcher
|
|
127
|
+
.on('add', filePath => {
|
|
128
|
+
logger.debug(`File ${filePath} added`);
|
|
129
|
+
listeners.add(filePath);
|
|
130
|
+
})
|
|
131
|
+
.on('change', filePath => {
|
|
132
|
+
logger.debug(`File ${filePath} changed`);
|
|
133
|
+
listeners.change(filePath);
|
|
134
|
+
})
|
|
135
|
+
.on('unlink', filePath => {
|
|
136
|
+
logger.debug(`File ${filePath} removed`);
|
|
137
|
+
listeners.unlink(filePath);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fsUtils';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { logger } from '@lib/utils/logger';
|
|
2
|
+
|
|
3
|
+
describe('Logger utils test', () => {
|
|
4
|
+
describe('logger', () => {
|
|
5
|
+
it('is an object with at least four functions: error, warn, info and debug', () => {
|
|
6
|
+
expect(typeof logger.error).toBe('function');
|
|
7
|
+
expect(typeof logger.warn).toBe('function');
|
|
8
|
+
expect(typeof logger.info).toBe('function');
|
|
9
|
+
expect(typeof logger.debug).toBe('function');
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './logger';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import winston from 'winston';
|
|
4
|
+
import { LogLevel, LogFile } from './logger.types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Defines a custom log format that prints a timestamp, a level and a message
|
|
8
|
+
*/
|
|
9
|
+
const customFormat = winston.format.printf(
|
|
10
|
+
({ level, message, timestamp }) => `${timestamp} [${level}]: ${message}`,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The combined log format, that makes use of the custom log format
|
|
15
|
+
*/
|
|
16
|
+
const combinedFormat = winston.format.combine(
|
|
17
|
+
winston.format.timestamp(),
|
|
18
|
+
customFormat,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The winston logger
|
|
23
|
+
*/
|
|
24
|
+
export const logger: winston.Logger = winston.createLogger({
|
|
25
|
+
levels: winston.config.npm.levels,
|
|
26
|
+
level: 'info',
|
|
27
|
+
format: winston.format.json(),
|
|
28
|
+
transports: [
|
|
29
|
+
// Write all logs with level `info` and below to console
|
|
30
|
+
new winston.transports.Console({
|
|
31
|
+
format: combinedFormat,
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Configures a logger instance
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* The logger can log its messages to two different transports:
|
|
41
|
+
*
|
|
42
|
+
* 1) The stdout (from the terminal/console which started this process)
|
|
43
|
+
* 2) A log file located on the filesystem
|
|
44
|
+
*
|
|
45
|
+
* Since stdout is a volatile transport that cannot be reviewed at a
|
|
46
|
+
* later point in time, it is recommended to use the log file when
|
|
47
|
+
* running the Data Server on production environments.
|
|
48
|
+
*
|
|
49
|
+
* If a log file is defined, but its path is no writable, it should:
|
|
50
|
+
* 1) Log an error (which would be logged to the stdout)
|
|
51
|
+
* 2) Throw an error
|
|
52
|
+
*
|
|
53
|
+
* @param level - Log level, defaults to "warn"
|
|
54
|
+
* @param logFile - Configuration data for the log file. An object
|
|
55
|
+
* containing two properties: path and level
|
|
56
|
+
*
|
|
57
|
+
* @throws
|
|
58
|
+
* An exception if a log file is defined, but its path is no writable
|
|
59
|
+
*/
|
|
60
|
+
export const configureLogger = (
|
|
61
|
+
level: LogLevel = LogLevel.WARN,
|
|
62
|
+
logFile?: LogFile,
|
|
63
|
+
): void => {
|
|
64
|
+
if (level) {
|
|
65
|
+
logger.level = level;
|
|
66
|
+
}
|
|
67
|
+
if (logFile && logFile.path) {
|
|
68
|
+
const logFileAbsolute = fs.realpathSync(path.resolve(logFile.path));
|
|
69
|
+
// Check if file dirname is writable.
|
|
70
|
+
try {
|
|
71
|
+
fs.accessSync(path.dirname(logFileAbsolute), fs.constants.W_OK);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
// Log error and rethrow.
|
|
74
|
+
logger.error(`Log file "${logFileAbsolute}" is not writable: ${e}`);
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Create and add the file transport to the logger
|
|
79
|
+
const fileTransport = new winston.transports.File({
|
|
80
|
+
filename: path.basename(logFileAbsolute),
|
|
81
|
+
dirname: path.dirname(logFileAbsolute),
|
|
82
|
+
format: combinedFormat,
|
|
83
|
+
level: logFile.level,
|
|
84
|
+
});
|
|
85
|
+
logger.add(fileTransport);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The logger service.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A logger currently based on the "winston" package.
|
|
8
|
+
*/
|
|
9
|
+
export type Logger = winston.Logger;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Log levels: error, warn, info and debug.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export enum LogLevel {
|
|
17
|
+
ERROR = 'error',
|
|
18
|
+
WARN = 'warn',
|
|
19
|
+
INFO = 'info',
|
|
20
|
+
DEBUG = 'debug',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A helper to get LogLevel type as strings. @see {@link LogLevel}.
|
|
25
|
+
*/
|
|
26
|
+
export type LogLevelStrings = keyof typeof LogLevel;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A log file definition.
|
|
30
|
+
*/
|
|
31
|
+
export type LogFile = {
|
|
32
|
+
/**
|
|
33
|
+
* Path to the log file.
|
|
34
|
+
*/
|
|
35
|
+
path: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Log level for the log file.
|
|
39
|
+
*/
|
|
40
|
+
level: LogLevel;
|
|
41
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { config } from '@lib/config';
|
|
4
|
+
import { dirBasedModuleGroupManager } from '@lib/utils/module';
|
|
5
|
+
|
|
6
|
+
config.queryDir = fs.realpathSync(
|
|
7
|
+
path.resolve(path.join(__dirname, '../__mocks__')),
|
|
8
|
+
);
|
|
9
|
+
export const exampleQueryManager = dirBasedModuleGroupManager('query');
|
|
10
|
+
|
|
11
|
+
describe('dirBasedModuleGroupManager test', () => {
|
|
12
|
+
describe('getModuleGroupInfo', () => {
|
|
13
|
+
it('loads a directory of modules', () => {
|
|
14
|
+
const moduleGroupInfo = exampleQueryManager.getModuleGroupInfo();
|
|
15
|
+
expect(moduleGroupInfo.size).toBe(2);
|
|
16
|
+
expect(Array.from(moduleGroupInfo.keys())).toStrictEqual([
|
|
17
|
+
'dummyModule',
|
|
18
|
+
'dummyModule2',
|
|
19
|
+
]);
|
|
20
|
+
expect(moduleGroupInfo.get('dummyModule')).not.toBe(null);
|
|
21
|
+
expect(moduleGroupInfo.get('dummyModule2')).not.toBe(null);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('reset', () => {
|
|
26
|
+
it('resets a directory of modules', () => {
|
|
27
|
+
const moduleGroupInfo = exampleQueryManager.getModuleGroupInfo();
|
|
28
|
+
expect(moduleGroupInfo.size).toBe(2);
|
|
29
|
+
|
|
30
|
+
exampleQueryManager.reset();
|
|
31
|
+
expect(moduleGroupInfo.size).toBe(0);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
/* eslint-disable global-require */
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { logger } from '@lib/utils/logger';
|
|
6
|
+
import { moduleManager } from '../moduleManager';
|
|
7
|
+
|
|
8
|
+
// This works in conjunction with "__mocks__/clear-module.js"
|
|
9
|
+
jest.mock('clear-module');
|
|
10
|
+
|
|
11
|
+
const dummyModulePath = fs.realpathSync(
|
|
12
|
+
path.resolve(path.join(__dirname, '../__mocks__/dummyModule.query.js')),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
logger.error = jest.fn();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('moduleHandler test', () => {
|
|
20
|
+
describe('get', () => {
|
|
21
|
+
describe('when a module exists', () => {
|
|
22
|
+
it('gets a module without logging any error', () => {
|
|
23
|
+
const { dummyObject } = moduleManager.get(dummyModulePath);
|
|
24
|
+
|
|
25
|
+
expect(dummyObject.key).toBe('dummyModuleValue');
|
|
26
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('gets a module twice without reloading it', () => {
|
|
30
|
+
const { dummyObject: firstDummyObject } =
|
|
31
|
+
moduleManager.get(dummyModulePath);
|
|
32
|
+
expect(firstDummyObject.key).toBe('dummyModuleValue');
|
|
33
|
+
firstDummyObject.key = 'updatedDummyModuleValue';
|
|
34
|
+
const { dummyObject: secondDummyObject } =
|
|
35
|
+
moduleManager.get(dummyModulePath);
|
|
36
|
+
expect(secondDummyObject.key).toBe('updatedDummyModuleValue');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('when a module does not exist', () => {
|
|
41
|
+
it('throws an exception and logs an error', () => {
|
|
42
|
+
expect(() => moduleManager.get('invalid-path')).toThrow();
|
|
43
|
+
expect(logger.error).toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('load', () => {
|
|
49
|
+
describe('when a module exists', () => {
|
|
50
|
+
it('loads a module without logging any error', () => {
|
|
51
|
+
const { dummyObject } = moduleManager.load(dummyModulePath);
|
|
52
|
+
expect(dummyObject.key).toBe('dummyModuleValue');
|
|
53
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('loads a module twice reloading it from scratch', () => {
|
|
57
|
+
const { dummyObject: firstDummyObject } =
|
|
58
|
+
moduleManager.load(dummyModulePath);
|
|
59
|
+
const { dummyObject: secondDummyObject } =
|
|
60
|
+
moduleManager.load(dummyModulePath);
|
|
61
|
+
|
|
62
|
+
firstDummyObject.key = 'updatedDummyModuleValue';
|
|
63
|
+
|
|
64
|
+
expect(firstDummyObject.key).toBe('updatedDummyModuleValue');
|
|
65
|
+
expect(secondDummyObject.key).toBe('dummyModuleValue');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('when a module does not exist', () => {
|
|
69
|
+
it('throws an exception and logs an error', () => {
|
|
70
|
+
expect(() => moduleManager.get('invalid-path')).toThrow();
|
|
71
|
+
expect(logger.error).toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('remove', () => {
|
|
77
|
+
it('removes a single module from Node.js cache', () => {
|
|
78
|
+
const { dummyObject: firstDummyObject } =
|
|
79
|
+
moduleManager.get(dummyModulePath);
|
|
80
|
+
moduleManager.remove(dummyModulePath);
|
|
81
|
+
const { dummyObject: secondDummyObject } =
|
|
82
|
+
moduleManager.get(dummyModulePath);
|
|
83
|
+
firstDummyObject.key = 'updatedDummyModuleValue';
|
|
84
|
+
expect(firstDummyObject.key).toBe('updatedDummyModuleValue');
|
|
85
|
+
expect(secondDummyObject.key).toBe('dummyModuleValue');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('removeAll', () => {
|
|
90
|
+
it('removes several modules from Node.js cache', () => {
|
|
91
|
+
const { dummyObject: dummyObject1 } = moduleManager.get(dummyModulePath);
|
|
92
|
+
dummyObject1.key = 'updatedDummyModuleValue';
|
|
93
|
+
moduleManager.removeAll(/dummyModule/);
|
|
94
|
+
const { dummyObject: dummyObject2 } = moduleManager.get(dummyModulePath);
|
|
95
|
+
|
|
96
|
+
expect(dummyObject1.key).toBe('updatedDummyModuleValue');
|
|
97
|
+
expect(dummyObject2.key).toBe('dummyModuleValue');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { config } from '@lib/config';
|
|
3
|
+
import { findFilesInDir } from '@lib/utils/fs';
|
|
4
|
+
import { cache } from '@lib/utils/cache';
|
|
5
|
+
import { moduleManager } from './moduleManager';
|
|
6
|
+
import { ModuleGroupManager, ModuleInfo } from './module.types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A manager of module groups based on a directory.
|
|
10
|
+
*
|
|
11
|
+
* A module group is a set of user-land modules that are stored inside
|
|
12
|
+
* a directory. The contents of that directory are unknown, and it can contain
|
|
13
|
+
* modules and other non-module files required by those modules.
|
|
14
|
+
*
|
|
15
|
+
* Modules are distinguished from other files because they contain a key as a suffix,
|
|
16
|
+
* at the end of their name, following this pattern: [MODULE_ID].[KEY].js
|
|
17
|
+
*
|
|
18
|
+
* For example:
|
|
19
|
+
*
|
|
20
|
+
* - lastContents.query.js
|
|
21
|
+
* - listByTermId.query.js
|
|
22
|
+
* - taxonomy.hook.js
|
|
23
|
+
* - media.hook.js
|
|
24
|
+
*
|
|
25
|
+
* This manager provided a set of common functionalities for those kind of
|
|
26
|
+
* directories.
|
|
27
|
+
*
|
|
28
|
+
* @param key - Key to distinguish modules from other files. This key is
|
|
29
|
+
* also used to derive the name of the configuration option that defines
|
|
30
|
+
* the path to the directory where the module group is stored, following this
|
|
31
|
+
* pattern: `${key}Dir`
|
|
32
|
+
* @returns A module group manager with a set of common functionalities
|
|
33
|
+
* for those kind of directories.
|
|
34
|
+
*/
|
|
35
|
+
export const dirBasedModuleGroupManager = <ModuleType>(
|
|
36
|
+
// Key needs to be explicitly defined to make TypeScript happy.
|
|
37
|
+
key: 'hook' | 'query' | 'task',
|
|
38
|
+
): ModuleGroupManager<ModuleType> => {
|
|
39
|
+
/**
|
|
40
|
+
* Cache bin used by this module group
|
|
41
|
+
*/
|
|
42
|
+
const moduleGroupInfo = cache.bin<ModuleInfo<ModuleType>>(`${key}-modules`);
|
|
43
|
+
|
|
44
|
+
const moduleGroupManager = {
|
|
45
|
+
getModuleGroupInfo: (): Map<string, ModuleInfo<ModuleType>> => {
|
|
46
|
+
// Use config here, because outside this function, the config object is not
|
|
47
|
+
// already defined.
|
|
48
|
+
const dir = config[`${key}Dir`];
|
|
49
|
+
// Scan directory only if moduleGroupInfo is empty.
|
|
50
|
+
if (dir && moduleGroupInfo.size === 0) {
|
|
51
|
+
// For each detected module, get all its information.
|
|
52
|
+
findFilesInDir(dir, `**/*.${key}.js`).forEach(filepath => {
|
|
53
|
+
const replace = `.${key}.js$`;
|
|
54
|
+
const moduleId = filepath.replace(new RegExp(replace), '');
|
|
55
|
+
const absolutePath = path.join(dir, filepath);
|
|
56
|
+
moduleGroupInfo.set(moduleId, {
|
|
57
|
+
id: moduleId,
|
|
58
|
+
absolutePath,
|
|
59
|
+
relativePath: filepath,
|
|
60
|
+
getModule: () => moduleManager.get<ModuleType>(absolutePath),
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return moduleGroupInfo;
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
reset: () => {
|
|
69
|
+
// Use config here, because outside this function, the config object is not
|
|
70
|
+
// already defined.
|
|
71
|
+
const dir = config[`${key}Dir`];
|
|
72
|
+
moduleManager.removeAll(new RegExp(`^${dir}`));
|
|
73
|
+
moduleGroupInfo.clear();
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return moduleGroupManager;
|
|
78
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A manager for a group of user-land modules.
|
|
3
|
+
*
|
|
4
|
+
* @typeParam ModuleType - The type of module being managed.
|
|
5
|
+
*/
|
|
6
|
+
export type ModuleGroupManager<ModuleType> = {
|
|
7
|
+
/**
|
|
8
|
+
* Gets an array with information of each module inside a module group.
|
|
9
|
+
*
|
|
10
|
+
* @returns An array with information of each detected module, containing:
|
|
11
|
+
* - module ID
|
|
12
|
+
* - module's absolute path
|
|
13
|
+
* - module's relative path
|
|
14
|
+
* - a function to load the module on demand
|
|
15
|
+
*/
|
|
16
|
+
getModuleGroupInfo(): Map<string, ModuleInfo<ModuleType>>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Resets the cache of found modules inside a module group.
|
|
20
|
+
*/
|
|
21
|
+
reset(): void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Information about a user-land module.
|
|
26
|
+
*
|
|
27
|
+
* @typeParam ModuleType - The type of the module.
|
|
28
|
+
*/
|
|
29
|
+
export type ModuleInfo<ModuleType> = {
|
|
30
|
+
/**
|
|
31
|
+
* Module ID.
|
|
32
|
+
*
|
|
33
|
+
* Given the following modules, their IDs are:
|
|
34
|
+
* - main.hook.js: main
|
|
35
|
+
* - dir/main.hook.js: dir/main
|
|
36
|
+
* - dir/taxonomy.hook.js: dir/taxonomy
|
|
37
|
+
* - latestContents.query.js: latestContents
|
|
38
|
+
* - dir/latestContents.query.js: dir/latestContents
|
|
39
|
+
* - dir/searchByTitle.query.js: dir/searchByTitle
|
|
40
|
+
*/
|
|
41
|
+
id: string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Module's absolute path.
|
|
45
|
+
*/
|
|
46
|
+
absolutePath: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Module's relative path inside module group directory.
|
|
50
|
+
*/
|
|
51
|
+
relativePath: string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Gets a module, loading it if not already loaded.
|
|
55
|
+
*/
|
|
56
|
+
getModule(): ModuleType;
|
|
57
|
+
};
|