@harperfast/harper 5.3.0-alpha.1 → 5.3.0-beta.2
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/bin/cliOperations.ts +12 -0
- package/bin/restart.ts +66 -6
- package/components/Application.ts +1134 -112
- package/components/DESIGN.md +421 -0
- package/components/OptionsWatcher.ts +368 -102
- package/components/Scope.ts +20 -1
- package/components/componentLoader.ts +43 -4
- package/components/deploymentOperations.ts +4 -1
- package/components/deploymentRecorder.ts +9 -2
- package/components/mcp/DESIGN.md +109 -0
- package/components/mcp/audit.ts +21 -17
- package/components/operations.js +284 -52
- package/components/operationsValidation.js +49 -2
- package/components/packageComponent.ts +25 -1
- package/components/requestRestart.ts +11 -0
- package/config/DESIGN.md +306 -0
- package/config/RootConfigWatcher.ts +191 -37
- package/config/configReadRetry.ts +62 -0
- package/config/configUtils.ts +78 -26
- package/config/parseConfigFile.ts +34 -0
- package/config/readConfigFileSync.ts +44 -0
- package/config/watcherArming.ts +59 -0
- package/config-root.schema.json +4 -0
- package/dataLayer/DESIGN.md +179 -0
- package/dataLayer/harperBridge/ResourceBridge.ts +28 -2
- package/dataLayer/restoreMarker.ts +92 -25
- package/dist/bin/cliOperations.js +13 -0
- package/dist/bin/cliOperations.js.map +1 -1
- package/dist/bin/restart.js +42 -6
- package/dist/bin/restart.js.map +1 -1
- package/dist/components/Application.d.ts +104 -9
- package/dist/components/Application.js +954 -102
- package/dist/components/Application.js.map +1 -1
- package/dist/components/OptionsWatcher.d.ts +4 -1
- package/dist/components/OptionsWatcher.js +378 -104
- package/dist/components/OptionsWatcher.js.map +1 -1
- package/dist/components/Scope.js +15 -1
- package/dist/components/Scope.js.map +1 -1
- package/dist/components/componentLoader.js +35 -3
- package/dist/components/componentLoader.js.map +1 -1
- package/dist/components/deploymentOperations.js +4 -1
- package/dist/components/deploymentOperations.js.map +1 -1
- package/dist/components/deploymentRecorder.d.ts +4 -2
- package/dist/components/deploymentRecorder.js +1 -0
- package/dist/components/deploymentRecorder.js.map +1 -1
- package/dist/components/mcp/audit.d.ts +2 -1
- package/dist/components/mcp/audit.js +21 -17
- package/dist/components/mcp/audit.js.map +1 -1
- package/dist/components/operations.d.ts +28 -0
- package/dist/components/operations.js +263 -54
- package/dist/components/operations.js.map +1 -1
- package/dist/components/operationsValidation.js +48 -2
- package/dist/components/operationsValidation.js.map +1 -1
- package/dist/components/packageComponent.js +24 -0
- package/dist/components/packageComponent.js.map +1 -1
- package/dist/components/requestRestart.d.ts +1 -0
- package/dist/components/requestRestart.js +7 -0
- package/dist/components/requestRestart.js.map +1 -1
- package/dist/config/RootConfigWatcher.d.ts +2 -0
- package/dist/config/RootConfigWatcher.js +189 -35
- package/dist/config/RootConfigWatcher.js.map +1 -1
- package/dist/config/configReadRetry.d.ts +8 -0
- package/dist/config/configReadRetry.js +62 -0
- package/dist/config/configReadRetry.js.map +1 -0
- package/dist/config/configUtils.d.ts +10 -9
- package/dist/config/configUtils.js +63 -27
- package/dist/config/configUtils.js.map +1 -1
- package/dist/config/parseConfigFile.d.ts +4 -0
- package/dist/config/parseConfigFile.js +35 -0
- package/dist/config/parseConfigFile.js.map +1 -0
- package/dist/config/readConfigFileSync.d.ts +1 -0
- package/dist/config/readConfigFileSync.js +47 -0
- package/dist/config/readConfigFileSync.js.map +1 -0
- package/dist/config/watcherArming.d.ts +15 -0
- package/dist/config/watcherArming.js +59 -0
- package/dist/config/watcherArming.js.map +1 -0
- package/dist/dataLayer/harperBridge/ResourceBridge.js +21 -2
- package/dist/dataLayer/harperBridge/ResourceBridge.js.map +1 -1
- package/dist/dataLayer/restoreMarker.d.ts +21 -8
- package/dist/dataLayer/restoreMarker.js +94 -27
- package/dist/dataLayer/restoreMarker.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/json/systemSchema.json +3 -0
- package/dist/resources/DatabaseTransaction.d.ts +25 -0
- package/dist/resources/DatabaseTransaction.js +224 -18
- package/dist/resources/DatabaseTransaction.js.map +1 -1
- package/dist/resources/LMDBTransaction.d.ts +2 -1
- package/dist/resources/LMDBTransaction.js +22 -3
- package/dist/resources/LMDBTransaction.js.map +1 -1
- package/dist/resources/PrimaryRocksDatabase.js +22 -6
- package/dist/resources/PrimaryRocksDatabase.js.map +1 -1
- package/dist/resources/RecordEncoder.d.ts +1 -1
- package/dist/resources/RecordEncoder.js +46 -10
- package/dist/resources/RecordEncoder.js.map +1 -1
- package/dist/resources/Resource.js +97 -13
- package/dist/resources/Resource.js.map +1 -1
- package/dist/resources/ResourceInterface.d.ts +8 -0
- package/dist/resources/RocksIndexStore.js +2 -1
- package/dist/resources/RocksIndexStore.js.map +1 -1
- package/dist/resources/RocksTransactionLogStore.d.ts +10 -0
- package/dist/resources/RocksTransactionLogStore.js +104 -33
- package/dist/resources/RocksTransactionLogStore.js.map +1 -1
- package/dist/resources/Table.d.ts +58 -7
- package/dist/resources/Table.js +1143 -348
- package/dist/resources/Table.js.map +1 -1
- package/dist/resources/analytics/write.d.ts +3 -0
- package/dist/resources/analytics/write.js +49 -16
- package/dist/resources/analytics/write.js.map +1 -1
- package/dist/resources/auditStore.d.ts +170 -0
- package/dist/resources/auditStore.js +457 -11
- package/dist/resources/auditStore.js.map +1 -1
- package/dist/resources/crdt.d.ts +10 -0
- package/dist/resources/crdt.js +22 -0
- package/dist/resources/crdt.js.map +1 -1
- package/dist/resources/dataLoader.js +3 -4
- package/dist/resources/dataLoader.js.map +1 -1
- package/dist/resources/databases.d.ts +16 -13
- package/dist/resources/databases.js +625 -177
- package/dist/resources/databases.js.map +1 -1
- package/dist/resources/derivedIndexRegistry.d.ts +5 -0
- package/dist/resources/derivedIndexRegistry.js +68 -0
- package/dist/resources/derivedIndexRegistry.js.map +1 -0
- package/dist/resources/derivedIndexRuntime.d.ts +215 -0
- package/dist/resources/derivedIndexRuntime.js +2027 -0
- package/dist/resources/derivedIndexRuntime.js.map +1 -0
- package/dist/resources/graphql.js +3 -2
- package/dist/resources/graphql.js.map +1 -1
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.d.ts +102 -9
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js +867 -39
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js.map +1 -1
- package/dist/resources/indexes/fullTextDerivedIndex.d.ts +81 -0
- package/dist/resources/indexes/fullTextDerivedIndex.js +1004 -0
- package/dist/resources/indexes/fullTextDerivedIndex.js.map +1 -0
- package/dist/resources/indexes/fullTextNativeBinding.d.ts +78 -0
- package/dist/resources/indexes/fullTextNativeBinding.js +85 -0
- package/dist/resources/indexes/fullTextNativeBinding.js.map +1 -0
- package/dist/resources/indexes/hnswDerivedIndex.d.ts +67 -0
- package/dist/resources/indexes/hnswDerivedIndex.js +464 -0
- package/dist/resources/indexes/hnswDerivedIndex.js.map +1 -0
- package/dist/resources/indexes/hnswPlaneBinding.d.ts +65 -0
- package/dist/resources/indexes/hnswPlaneBinding.js +91 -0
- package/dist/resources/indexes/hnswPlaneBinding.js.map +1 -0
- package/dist/resources/indexes/nativeFullTextDerivedIndexLifecycle.d.ts +24 -0
- package/dist/resources/indexes/nativeFullTextDerivedIndexLifecycle.js +149 -0
- package/dist/resources/indexes/nativeFullTextDerivedIndexLifecycle.js.map +1 -0
- package/dist/resources/nodeIdMapping.d.ts +5 -0
- package/dist/resources/nodeIdMapping.js +49 -0
- package/dist/resources/nodeIdMapping.js.map +1 -1
- package/dist/resources/recordLock.d.ts +47 -4
- package/dist/resources/recordLock.js +138 -7
- package/dist/resources/recordLock.js.map +1 -1
- package/dist/resources/recordLockCoordinator.d.ts +557 -0
- package/dist/resources/recordLockCoordinator.js +2597 -0
- package/dist/resources/recordLockCoordinator.js.map +1 -0
- package/dist/resources/replayLogs.js +5 -0
- package/dist/resources/replayLogs.js.map +1 -1
- package/dist/resources/replicatedApplyFailure.d.ts +16 -0
- package/dist/resources/replicatedApplyFailure.js +63 -0
- package/dist/resources/replicatedApplyFailure.js.map +1 -0
- package/dist/resources/scheduler/scheduler.js +3 -3
- package/dist/resources/scheduler/scheduler.js.map +1 -1
- package/dist/resources/search.d.ts +10 -4
- package/dist/resources/search.js +160 -40
- package/dist/resources/search.js.map +1 -1
- package/dist/resources/tracked.d.ts +5 -1
- package/dist/resources/tracked.js +74 -23
- package/dist/resources/tracked.js.map +1 -1
- package/dist/resources/transactionBroadcast.js +4 -6
- package/dist/resources/transactionBroadcast.js.map +1 -1
- package/dist/security/auth.js +59 -23
- package/dist/security/auth.js.map +1 -1
- package/dist/security/deferredAuthentication.d.ts +11 -0
- package/dist/security/deferredAuthentication.js +25 -3
- package/dist/security/deferredAuthentication.js.map +1 -1
- package/dist/security/jsLoader.js +9 -4
- package/dist/security/jsLoader.js.map +1 -1
- package/dist/server/REST.js +39 -5
- package/dist/server/REST.js.map +1 -1
- package/dist/server/http.d.ts +5 -1
- package/dist/server/http.js +34 -2
- package/dist/server/http.js.map +1 -1
- package/dist/server/mqtt.js +5 -1
- package/dist/server/mqtt.js.map +1 -1
- package/dist/server/serverHelpers/Headers.d.ts +2 -0
- package/dist/server/serverHelpers/Headers.js +6 -0
- package/dist/server/serverHelpers/Headers.js.map +1 -1
- package/dist/server/serverHelpers/NodeAdapterResponse.d.ts +48 -0
- package/dist/server/serverHelpers/NodeAdapterResponse.js +220 -0
- package/dist/server/serverHelpers/NodeAdapterResponse.js.map +1 -0
- package/dist/server/serverHelpers/Request.d.ts +5 -10
- package/dist/server/serverHelpers/Request.js +38 -136
- package/dist/server/serverHelpers/Request.js.map +1 -1
- package/dist/server/serverHelpers/contentTypes.d.ts +2 -0
- package/dist/server/serverHelpers/contentTypes.js +189 -15
- package/dist/server/serverHelpers/contentTypes.js.map +1 -1
- package/dist/server/serverHelpers/serverUtilities.d.ts +3 -3
- package/dist/server/serverHelpers/serverUtilities.js +110 -20
- package/dist/server/serverHelpers/serverUtilities.js.map +1 -1
- package/dist/server/serverHelpers/uwsServer.js +4 -1
- package/dist/server/serverHelpers/uwsServer.js.map +1 -1
- package/dist/server/serverHelpers/webSocketCloseReason.d.ts +2 -0
- package/dist/server/serverHelpers/webSocketCloseReason.js +29 -0
- package/dist/server/serverHelpers/webSocketCloseReason.js.map +1 -0
- package/dist/server/storageReclamation.js +1 -1
- package/dist/server/storageReclamation.js.map +1 -1
- package/dist/server/threads/isolatedApplications.d.ts +47 -0
- package/dist/server/threads/isolatedApplications.js +171 -0
- package/dist/server/threads/isolatedApplications.js.map +1 -0
- package/dist/server/threads/logRotationTransport.d.ts +1 -0
- package/dist/server/threads/logRotationTransport.js +33 -0
- package/dist/server/threads/logRotationTransport.js.map +1 -0
- package/dist/server/threads/manageThreads.d.ts +64 -6
- package/dist/server/threads/manageThreads.js +261 -12
- package/dist/server/threads/manageThreads.js.map +1 -1
- package/dist/server/threads/socketRouter.d.ts +1 -0
- package/dist/server/threads/socketRouter.js +196 -13
- package/dist/server/threads/socketRouter.js.map +1 -1
- package/dist/server/threads/threadServer.js +30 -7
- package/dist/server/threads/threadServer.js.map +1 -1
- package/dist/utility/errors/hdbError.d.ts +24 -0
- package/dist/utility/errors/hdbError.js +58 -1
- package/dist/utility/errors/hdbError.js.map +1 -1
- package/dist/utility/hdbTerms.d.ts +2 -0
- package/dist/utility/hdbTerms.js +2 -0
- package/dist/utility/hdbTerms.js.map +1 -1
- package/dist/utility/logging/harper_logger.js +218 -38
- package/dist/utility/logging/harper_logger.js.map +1 -1
- package/dist/utility/logging/logGenerationCoordinator.d.ts +35 -0
- package/dist/utility/logging/logGenerationCoordinator.js +184 -0
- package/dist/utility/logging/logGenerationCoordinator.js.map +1 -0
- package/dist/utility/logging/logRotation.d.ts +46 -0
- package/dist/utility/logging/logRotation.js +365 -0
- package/dist/utility/logging/logRotation.js.map +1 -0
- package/dist/utility/logging/logRotator.d.ts +1 -1
- package/dist/utility/logging/logRotator.js +172 -92
- package/dist/utility/logging/logRotator.js.map +1 -1
- package/dist/utility/npmUtilities.js +6 -4
- package/dist/utility/npmUtilities.js.map +1 -1
- package/dist/utility/watcherFallback.d.ts +0 -45
- package/dist/utility/watcherFallback.js +1 -125
- package/dist/utility/watcherFallback.js.map +1 -1
- package/dist/validation/configValidator.js +6 -3
- package/dist/validation/configValidator.js.map +1 -1
- package/index.ts +9 -0
- package/json/systemSchema.json +3 -0
- package/npm-shrinkwrap.json +177 -87
- package/package.json +13 -5
- package/resources/DESIGN.md +689 -19
- package/resources/DatabaseTransaction.ts +230 -17
- package/resources/LMDBTransaction.ts +21 -3
- package/resources/PrimaryRocksDatabase.ts +20 -7
- package/resources/RecordEncoder.ts +52 -10
- package/resources/Resource.ts +97 -13
- package/resources/ResourceInterface.ts +8 -0
- package/resources/RocksIndexStore.ts +2 -1
- package/resources/RocksTransactionLogStore.ts +111 -31
- package/resources/Table.ts +1273 -396
- package/resources/analytics/DESIGN.md +38 -0
- package/resources/analytics/write.ts +50 -17
- package/resources/auditStore.ts +460 -11
- package/resources/crdt.ts +22 -0
- package/resources/dataLoader.ts +3 -4
- package/resources/databases.ts +611 -147
- package/resources/derivedIndexRegistry.ts +56 -0
- package/resources/derivedIndexRuntime.ts +2292 -0
- package/resources/graphql.ts +3 -2
- package/resources/indexes/DESIGN.md +833 -0
- package/resources/indexes/HierarchicalNavigableSmallWorld.ts +924 -46
- package/resources/indexes/fullTextDerivedIndex.ts +1165 -0
- package/resources/indexes/fullTextNativeBinding.ts +146 -0
- package/resources/indexes/hnswDerivedIndex.ts +531 -0
- package/resources/indexes/hnswPlaneBinding.ts +174 -0
- package/resources/indexes/nativeFullTextDerivedIndexLifecycle.ts +181 -0
- package/resources/nodeIdMapping.ts +50 -0
- package/resources/record-locks.md +1407 -0
- package/resources/recordLock.ts +173 -7
- package/resources/recordLockCoordinator.ts +3082 -0
- package/resources/replayLogs.ts +5 -0
- package/resources/replicatedApplyFailure.ts +77 -0
- package/resources/scheduler/DESIGN.md +40 -0
- package/resources/scheduler/scheduler.ts +4 -4
- package/resources/search.ts +169 -49
- package/resources/tracked.ts +73 -22
- package/resources/transactionBroadcast.ts +4 -4
- package/security/DESIGN.md +175 -0
- package/security/auth.ts +53 -24
- package/security/deferredAuthentication.ts +24 -2
- package/security/jsLoader.ts +9 -4
- package/server/DESIGN.md +275 -0
- package/server/REST.ts +42 -6
- package/server/http.ts +34 -2
- package/server/mqtt.ts +6 -4
- package/server/serverHelpers/Headers.ts +5 -1
- package/server/serverHelpers/NodeAdapterResponse.ts +221 -0
- package/server/serverHelpers/Request.ts +33 -131
- package/server/serverHelpers/contentTypes.ts +188 -15
- package/server/serverHelpers/serverUtilities.ts +157 -27
- package/server/serverHelpers/uwsServer.ts +4 -1
- package/server/serverHelpers/webSocketCloseReason.ts +25 -0
- package/server/storageReclamation.ts +2 -2
- package/server/threads/isolatedApplications.ts +157 -0
- package/server/threads/logRotationTransport.ts +40 -0
- package/server/threads/manageThreads.js +254 -12
- package/server/threads/socketRouter.ts +217 -11
- package/server/threads/threadServer.js +30 -7
- package/studio/web/assets/{Chat-BnCBegQz.js → Chat-DADFFGe_.js} +1 -1
- package/studio/web/assets/{FloatingChat-CoDW1ySS.js → FloatingChat-D_mI-rZ7.js} +3 -3
- package/studio/web/assets/{apiToken-Bwk5BLXW.js → apiToken-c2NiSDHa.js} +1 -1
- package/studio/web/assets/{applications-DHxGi7JH.js → applications-DktUqh7G.js} +1 -1
- package/studio/web/assets/{cssMode-s0cWI-_M.js → cssMode-Cs_75Xhw.js} +1 -1
- package/studio/web/assets/{editor-DNcRHK54.js → editor-19b-Y1IN.js} +1 -1
- package/studio/web/assets/{html-Bdssedlg.js → html-DiYEQMpB.js} +1 -1
- package/studio/web/assets/{htmlMode-CoDlJ3fw.js → htmlMode-CmR0y7P_.js} +1 -1
- package/studio/web/assets/{index-D6sxmFLR.js → index-Dm0rfkJ7.js} +5 -5
- package/studio/web/assets/{index.lazy-tmU5BS8s.js → index.lazy-7vqt2CC3.js} +1 -1
- package/studio/web/assets/{javascript-B8meVSTH.js → javascript-BWtCFuOt.js} +1 -1
- package/studio/web/assets/{jsonMode-DpIPd35T.js → jsonMode-Buzzbv9y.js} +1 -1
- package/studio/web/assets/{languageServices-C_5FMJzQ.js → languageServices-SqsFWfTM.js} +1 -1
- package/studio/web/assets/{lspLanguageFeatures-BIzNBzPK.js → lspLanguageFeatures-EMV5cmjo.js} +1 -1
- package/studio/web/assets/{notifications-CvZivSbh.js → notifications-CAB-LZWT.js} +1 -1
- package/studio/web/assets/{notifications-CQf18QKb.js → notifications-DRzmSRxM.js} +1 -1
- package/studio/web/assets/{profile-DdOwtntb.js → profile-BNKAl79n.js} +1 -1
- package/studio/web/assets/{regions-n69fwagr.js → regions-CUow_Zw2.js} +1 -1
- package/studio/web/assets/{register-PfWTCXWB.js → register-Dkt3WUMp.js} +2 -2
- package/studio/web/assets/{setComponentFile-Bg6O7X0S.js → setComponentFile-BZRfMD0N.js} +1 -1
- package/studio/web/assets/{setup-CUx_aUDl.js → setup-D_yiEPO2.js} +2 -2
- package/studio/web/assets/{status-D7BVKqX9.js → status-DhHh1Ge-.js} +1 -1
- package/studio/web/assets/{toggleHighContrast-DBSyXzMr.js → toggleHighContrast-D7L1PDtV.js} +1 -1
- package/studio/web/assets/{tsMode-BByKCjBS.js → tsMode-CCwLk1YS.js} +1 -1
- package/studio/web/assets/{typescript-DDLnLpw9.js → typescript-BP1j1mjn.js} +1 -1
- package/studio/web/assets/{useEntityRestURL-31CHGaHk.js → useEntityRestURL-D7bnYxLw.js} +1 -1
- package/studio/web/assets/{workers-pR3jRY9D.js → workers-tOuCNT17.js} +1 -1
- package/studio/web/assets/{xml-2iRnMhQO.js → xml-BSG_3mQT.js} +1 -1
- package/studio/web/assets/{yaml-Bf92gJpd.js → yaml-DxiLprBB.js} +1 -1
- package/studio/web/index.html +1 -1
- package/utility/DESIGN.md +55 -0
- package/utility/errors/hdbError.ts +54 -0
- package/utility/hdbTerms.ts +2 -0
- package/utility/logging/harper_logger.ts +210 -30
- package/utility/logging/logGenerationCoordinator.ts +196 -0
- package/utility/logging/logRotation.ts +367 -0
- package/utility/logging/logRotator.ts +196 -91
- package/utility/npmUtilities.ts +6 -4
- package/utility/watcherFallback.ts +0 -122
- package/validation/configValidator.ts +6 -3
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.OptionsWatcher = exports.CannotSetPropertyError = exports.KeyDoesNotExistError = exports.InvalidValueTypeError = exports.InvariantUninitializedOptionsWatcherError = exports.UninitializedOptionsWatcherError = exports.OptionsWatcherConfigFileError = void 0;
|
|
7
4
|
const harper_logger_ts_1 = require("../utility/logging/harper_logger.js");
|
|
8
5
|
const events_1 = require("events");
|
|
9
|
-
const yaml_1 = __importDefault(require("yaml"));
|
|
10
6
|
const promises_1 = require("node:fs/promises");
|
|
11
|
-
const node_fs_1 = require("node:fs");
|
|
12
7
|
const util_1 = require("util");
|
|
13
8
|
const DEFAULT_CONFIG_ts_1 = require("./DEFAULT_CONFIG.js");
|
|
14
9
|
const lodash_1 = require("lodash");
|
|
15
10
|
const watcherFallback_ts_1 = require("../utility/watcherFallback.js");
|
|
16
11
|
const watchPath_ts_1 = require("../utility/watchPath.js");
|
|
17
12
|
const harperConfigEnvVars_ts_1 = require("../config/harperConfigEnvVars.js");
|
|
13
|
+
const readConfigFileSync_ts_1 = require("../config/readConfigFileSync.js");
|
|
14
|
+
const parseConfigFile_ts_1 = require("../config/parseConfigFile.js");
|
|
15
|
+
const configReadRetry_ts_1 = require("../config/configReadRetry.js");
|
|
16
|
+
const watcherArming_ts_1 = require("../config/watcherArming.js");
|
|
18
17
|
// This is uniquely for errors coming from the chokidar watcher of the config file.
|
|
19
18
|
class OptionsWatcherConfigFileError extends Error {
|
|
20
19
|
constructor(configFilePath, error) {
|
|
@@ -74,13 +73,22 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
74
73
|
#scopedConfig;
|
|
75
74
|
#rootConfig;
|
|
76
75
|
#isRootConfig;
|
|
76
|
+
#synchronousRead;
|
|
77
|
+
#readRetry = new configReadRetry_ts_1.ConfigReadRetry();
|
|
78
|
+
#armGate = new watcherArming_ts_1.ArmGate();
|
|
77
79
|
#name;
|
|
78
80
|
#logger;
|
|
79
81
|
#usingPolling;
|
|
80
82
|
#closed;
|
|
81
83
|
#openCount = 0;
|
|
84
|
+
#readCount = 0;
|
|
85
|
+
#readSequence = 0;
|
|
86
|
+
#appliedSequence = 0;
|
|
87
|
+
#scopeConfigured = false;
|
|
88
|
+
#armAbsence;
|
|
89
|
+
#readyEmitted = false;
|
|
90
|
+
#envComposeError;
|
|
82
91
|
#pendingReads = new Set();
|
|
83
|
-
#partialRead;
|
|
84
92
|
ready;
|
|
85
93
|
constructor(name, filePath, logger, isRootConfig) {
|
|
86
94
|
super();
|
|
@@ -88,11 +96,12 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
88
96
|
this.#filePath = filePath;
|
|
89
97
|
const watchTarget = (0, watchPath_ts_1.resolveWatchTarget)(filePath);
|
|
90
98
|
this.#watchPath = watchTarget.path;
|
|
91
|
-
this.#partialRead = new watcherFallback_ts_1.PartialReadRetry(filePath);
|
|
92
99
|
// Root-config watchers must see runtime env config (HARPER_SET_CONFIG et al.)
|
|
93
100
|
// even when it hasn't been flushed to disk yet — see #handleChange (#1618).
|
|
94
101
|
// Application scopes watch their own config.yaml and are never overlaid.
|
|
95
|
-
|
|
102
|
+
const rootConfigFile = (0, harperConfigEnvVars_ts_1.isRootConfigFilename)(filePath);
|
|
103
|
+
this.#isRootConfig = isRootConfig ?? rootConfigFile;
|
|
104
|
+
this.#synchronousRead = this.#isRootConfig;
|
|
96
105
|
this.#logger = logger || (0, harper_logger_ts_1.loggerWithTag)(name);
|
|
97
106
|
this.#usingPolling = watchTarget.mustPoll;
|
|
98
107
|
this.#closed = false;
|
|
@@ -100,7 +109,7 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
100
109
|
this.#openWatcher();
|
|
101
110
|
}
|
|
102
111
|
#openWatcher() {
|
|
103
|
-
this.#openCount
|
|
112
|
+
const generation = ++this.#openCount;
|
|
104
113
|
this.#watcher = (0, watcherFallback_ts_1.guardedWatch)(this.#watchPath, {
|
|
105
114
|
persistent: false,
|
|
106
115
|
...(this.#usingPolling ? watcherFallback_ts_1.POLLING_FALLBACK_OPTIONS : {}),
|
|
@@ -109,67 +118,124 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
109
118
|
.on('change', this.#handleChange.bind(this))
|
|
110
119
|
.on('error', this.#handleError.bind(this))
|
|
111
120
|
.on('unlink', this.#handleUnlink.bind(this))
|
|
112
|
-
.
|
|
121
|
+
// Generation-bound: `#armGate.reset()` runs before the failed watcher is closed, so a
|
|
122
|
+
// `ready` still queued on it would arm the gate on the replacement's behalf and the
|
|
123
|
+
// replacement's own `ready` would then be a no-op — leaving its scan window unre-read.
|
|
124
|
+
.on('ready', () => this.#handleArmed(generation));
|
|
125
|
+
}
|
|
126
|
+
// Every root-declared plugin gets its own root-config watcher and each reads synchronously, so
|
|
127
|
+
// each has the unarmed window DESIGN.md's "`ready` means the watcher is armed" describes. The
|
|
128
|
+
// write that lands in it is reported by no event, so only this re-read can deliver it.
|
|
129
|
+
#handleArmed(generation) {
|
|
130
|
+
if (this.#closed || generation !== this.#openCount)
|
|
131
|
+
return;
|
|
132
|
+
this.#armGate.arm(() => this.#read(true, true));
|
|
113
133
|
}
|
|
114
|
-
// Root config only: see the descriptor-lifetime invariant on atomicWriteFile (DESIGN.md).
|
|
115
134
|
#handleChange() {
|
|
116
|
-
|
|
117
|
-
|
|
135
|
+
this.#read(true);
|
|
136
|
+
}
|
|
137
|
+
// While `ready` is outstanding the ladder is the only thing that can settle it, so its timer has
|
|
138
|
+
// to keep the thread alive; afterwards it must not, or a config file nobody is reading would
|
|
139
|
+
// hold a worker open.
|
|
140
|
+
#schedule() {
|
|
141
|
+
return this.#readRetry.schedule(() => this.#read(false), !this.#readyEmitted);
|
|
142
|
+
}
|
|
143
|
+
#read(waitForLock, arming = false) {
|
|
144
|
+
// A queued chokidar callback can still land after close(), and by then removeAllListeners()
|
|
145
|
+
// has run — emitting into an EventEmitter with no 'error' listener would throw out of it.
|
|
146
|
+
if (this.#closed)
|
|
147
|
+
return;
|
|
148
|
+
this.#readCount++;
|
|
149
|
+
if (this.#synchronousRead) {
|
|
150
|
+
try {
|
|
151
|
+
let contents;
|
|
152
|
+
try {
|
|
153
|
+
contents = (0, readConfigFileSync_ts_1.readConfigFileSync)(this.#filePath, waitForLock);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
this.#handleReadError(error, arming);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
this.#applyContents(contents);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
// A listener of what `#applyContents` emitted may have closed the watcher, after
|
|
163
|
+
// which `emit('error')` has no listener left and would throw out of here.
|
|
164
|
+
if (!this.#closed)
|
|
165
|
+
this.#surfaceFailure(error);
|
|
166
|
+
}
|
|
118
167
|
return;
|
|
119
168
|
}
|
|
169
|
+
// The `#closed` check above cannot cover the completion: close() may land while this read is
|
|
170
|
+
// in flight, and by then its retry state is cancelled and its listeners are gone. Nothing
|
|
171
|
+
// orders these against each other either — chokidar does not await one read before starting
|
|
172
|
+
// the next — so an older one completing last would put the file's previous contents back
|
|
173
|
+
// with no event left to correct it.
|
|
174
|
+
const sequence = ++this.#readSequence;
|
|
175
|
+
// `<=`, not `<`: a deletion supersedes the reads already in flight without being a read of
|
|
176
|
+
// its own, and says so by claiming the sequence they were issued under.
|
|
177
|
+
const outranked = () => this.#closed || sequence <= this.#appliedSequence;
|
|
120
178
|
const read = (0, promises_1.readFile)(this.#filePath, 'utf-8')
|
|
121
|
-
.then((contents) =>
|
|
122
|
-
|
|
179
|
+
.then((contents) => {
|
|
180
|
+
if (outranked())
|
|
181
|
+
return;
|
|
182
|
+
this.#appliedSequence = sequence;
|
|
183
|
+
this.#applyContents(contents);
|
|
184
|
+
}, (error) => {
|
|
185
|
+
if (outranked())
|
|
186
|
+
return;
|
|
187
|
+
this.#appliedSequence = sequence;
|
|
188
|
+
this.#handleReadError(error, arming);
|
|
189
|
+
})
|
|
190
|
+
.catch((error) => {
|
|
191
|
+
if (!this.#closed)
|
|
192
|
+
this.#surfaceFailure(error);
|
|
193
|
+
})
|
|
123
194
|
.finally(() => {
|
|
124
195
|
this.#pendingReads.delete(read);
|
|
125
196
|
});
|
|
126
197
|
this.#pendingReads.add(read);
|
|
127
198
|
}
|
|
128
|
-
#
|
|
199
|
+
#applyContents(contents) {
|
|
200
|
+
// An empty read is a writer's truncate window, not an emptied config, and falling through
|
|
201
|
+
// would emit `remove` — see DESIGN.md, "An empty read is a writer mid-write, not an empty
|
|
202
|
+
// config". Both read paths can land in that window; only the synchronous one is likely to.
|
|
203
|
+
if (!contents) {
|
|
204
|
+
if (this.#schedule())
|
|
205
|
+
return;
|
|
206
|
+
// Past the ladder the file is empty rather than mid-write, and an empty file carries no
|
|
207
|
+
// scope: keep what is already applied instead of reading it as a removal, and settle the
|
|
208
|
+
// boot barrier on the defaults rather than leaving `Scope.ready` pending forever.
|
|
209
|
+
this.#logger.warn?.(`Configuration file ${this.#filePath} is empty.`);
|
|
210
|
+
this.#settleUnconfigured();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
129
213
|
let parsed;
|
|
130
214
|
try {
|
|
131
|
-
parsed =
|
|
215
|
+
parsed = (0, parseConfigFile_ts_1.parseConfigFile)(contents, this.#filePath);
|
|
132
216
|
}
|
|
133
217
|
catch (error) {
|
|
134
|
-
// A
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
this.#
|
|
138
|
-
|
|
218
|
+
// A prefix of the document is as much a mid-write read as an empty one, and the event
|
|
219
|
+
// carrying the rest is the one chokidar throttles away — same ladder, same reason. Past it
|
|
220
|
+
// the file really is malformed, which `#read` routes to `#surfaceFailure`.
|
|
221
|
+
if (!this.#closed && this.#schedule())
|
|
222
|
+
return;
|
|
223
|
+
throw error;
|
|
139
224
|
}
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
//
|
|
225
|
+
// Judged on the file's own parse, before the overlay below: a truncated document, a lone
|
|
226
|
+
// `\n` and a file of nothing but comments all parse to `null` rather than throwing, and
|
|
227
|
+
// `overlayRootEnvConfig` turns any of them into a non-null object whenever a config env var
|
|
228
|
+
// is set — the norm in containers — so overlaying first would launder a half-written file
|
|
229
|
+
// into a valid-looking env-only config and wipe the file's own options. Past the ladder it
|
|
230
|
+
// is an empty file, which `#applyContents` already keeps rather than reads as a removal.
|
|
144
231
|
if (!parsed || typeof parsed !== 'object') {
|
|
145
|
-
if (this.#
|
|
232
|
+
if (this.#schedule())
|
|
146
233
|
return;
|
|
147
|
-
this.#
|
|
148
|
-
|
|
149
|
-
else {
|
|
150
|
-
this.#partialRead.settled();
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
this.#applyParsed(this.#overlayEnvConfig(parsed));
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
// Applying is past the point where an incomplete file could explain a failure, so a
|
|
157
|
-
// listener's throw keeps the error route rather than being retried.
|
|
158
|
-
this.emit('error', error);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
#recoverOrReport(error) {
|
|
162
|
-
if (!(0, watcherFallback_ts_1.isPartialReadError)(error))
|
|
163
|
-
return this.#handleReadError(error);
|
|
164
|
-
if (this.#partialRead.schedule(() => this.#handleChange()))
|
|
234
|
+
this.#logger.warn?.(`Configuration file ${this.#filePath} is empty.`);
|
|
235
|
+
this.#settleUnconfigured();
|
|
165
236
|
return;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
// scope's own route.
|
|
169
|
-
this.#partialRead.gaveUp(error);
|
|
170
|
-
this.#handleReadError(error);
|
|
171
|
-
}
|
|
172
|
-
#overlayEnvConfig(parsed) {
|
|
237
|
+
}
|
|
238
|
+
this.#readRetry.reset();
|
|
173
239
|
// The on-disk root config is not guaranteed to include runtime env config at
|
|
174
240
|
// boot: the file flush races component loading, so a scope's boot-time reads
|
|
175
241
|
// (e.g. an `enabled` gate in handleApplication) could observe pre-env values
|
|
@@ -177,36 +243,46 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
177
243
|
// config onto EVERY root-config read so scope.options matches the resolved
|
|
178
244
|
// view (#1618). Non-root scopes and the no-env-vars case are untouched
|
|
179
245
|
// (overlayRootEnvConfig is a no-op there).
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
246
|
+
if (this.#isRootConfig) {
|
|
247
|
+
try {
|
|
248
|
+
parsed = (0, harperConfigEnvVars_ts_1.overlayRootEnvConfig)(parsed);
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
this.#envComposeError = error;
|
|
252
|
+
if (this.#readyEmitted)
|
|
253
|
+
this.#reportEnvComposeFailure();
|
|
254
|
+
else
|
|
255
|
+
this.#settleUnconfigured();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
183
259
|
this.#rootConfig = parsed && typeof parsed === 'object' ? parsed : undefined;
|
|
184
260
|
// If the extension is in the config file
|
|
185
261
|
if (this.#rootConfig && this.#name in this.#rootConfig) {
|
|
186
|
-
|
|
187
|
-
if (!this.#scopedConfig) {
|
|
188
|
-
// set it
|
|
189
|
-
this.#scopedConfig = this.#rootConfig[this.#name];
|
|
190
|
-
// and emit a ready event
|
|
191
|
-
this.emit('ready', this.#scopedConfig);
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
// Otherwise, merge the new config with the old config
|
|
195
|
-
this.#merge(this.#rootConfig[this.#name], this.#scopedConfig);
|
|
196
|
-
}
|
|
262
|
+
this.#applyScopedConfig(this.#rootConfig[this.#name]);
|
|
197
263
|
}
|
|
198
264
|
else {
|
|
199
265
|
// Otherwise, if the extension is not in the config file
|
|
200
266
|
// This means the plugin was removed from the config file
|
|
201
|
-
|
|
202
|
-
|
|
267
|
+
// Presence, not truthiness: `myPlugin:` with nothing under it is a configured scope, and
|
|
268
|
+
// deleting that block has to reach `Scope` as a removal like any other.
|
|
269
|
+
if (this.#scopeConfigured) {
|
|
270
|
+
this.#scopeConfigured = false;
|
|
203
271
|
this.#scopedConfig = undefined;
|
|
204
|
-
this
|
|
272
|
+
this.#emitRemove();
|
|
273
|
+
}
|
|
274
|
+
// The scope may be added back later, but this read is still a terminal outcome: with
|
|
275
|
+
// nothing ever applied, neither branch above emits, and `Scope.ready` would stay pending
|
|
276
|
+
// for a config that read perfectly well. The read succeeded, so only the scope falls back
|
|
277
|
+
// to its default — `#settleUnconfigured`'s full reset would discard the root config this
|
|
278
|
+
// very read produced.
|
|
279
|
+
if (!this.#readyEmitted) {
|
|
280
|
+
this.#scopedConfig = (0, lodash_1.cloneDeep)(DEFAULT_CONFIG_ts_1.DEFAULT_CONFIG[this.#name]);
|
|
281
|
+
this.#emitReady(this.#scopedConfig);
|
|
205
282
|
}
|
|
206
|
-
// Otherwise do nothing - the user may add the config back in later
|
|
207
283
|
}
|
|
208
284
|
}
|
|
209
|
-
#handleReadError(error) {
|
|
285
|
+
#handleReadError(error, arming = false) {
|
|
210
286
|
// If the config file does not exist
|
|
211
287
|
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
212
288
|
// A readFile ENOENT here is the install window (file not written yet) or a
|
|
@@ -216,23 +292,114 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
216
292
|
// through to the original ENOENT handling with #rootConfig untouched, so a
|
|
217
293
|
// first boot still emits `ready` (not `remove`, which nothing consumes at
|
|
218
294
|
// boot → `ready` would hang forever).
|
|
295
|
+
// A ladder armed by an earlier empty read is spent here, and every other terminal path
|
|
296
|
+
// clears its deadline; leaving it armed costs the next mid-write read its whole budget.
|
|
297
|
+
this.#readRetry.reset();
|
|
219
298
|
if (this.#applyEnvOnlyConfig())
|
|
220
299
|
return;
|
|
221
300
|
// And a config already exists, reset it to the default
|
|
222
301
|
if (this.#rootConfig) {
|
|
302
|
+
// The arm gate's job is the *write* that landed while the watch was unarmed, and
|
|
303
|
+
// answering its ENOENT with a removal reports the deletion ahead of the `unlink`
|
|
304
|
+
// that would confirm it — on a platform with an arming grace, ahead of chokidar
|
|
305
|
+
// having finished its own teardown, so a config recreated on the strength of that
|
|
306
|
+
// early `remove` lands where its `add` is not observed at all. It cannot simply be
|
|
307
|
+
// dropped either: the unarmed window is exactly where an `unlink` can go missing.
|
|
308
|
+
// So it goes back to the loop once, and chokidar's own `unlink` cancels it.
|
|
309
|
+
if (arming) {
|
|
310
|
+
// Every resolution of the deferral recomposes and reports the env state it finds,
|
|
311
|
+
// so a failure held across it is one that may no longer be true — and the next
|
|
312
|
+
// path to report would attach it to an unrelated event.
|
|
313
|
+
this.#envComposeError = undefined;
|
|
314
|
+
this.#deferAbsenceCheck();
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
223
317
|
this.#resetConfig();
|
|
224
|
-
this
|
|
318
|
+
this.#emitRemove();
|
|
225
319
|
}
|
|
226
320
|
else {
|
|
227
321
|
// Otherwise, if no config exists, then just set to default and emit ready
|
|
228
322
|
this.#resetConfig();
|
|
229
|
-
this
|
|
323
|
+
this.#emitReady();
|
|
230
324
|
}
|
|
325
|
+
this.#reportEnvComposeFailure();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
// A failure that outlives the read emits no new watcher event when it clears, so without
|
|
329
|
+
// this the scope would hold a stale config until the next write. Both read paths: an
|
|
330
|
+
// application config on SMB or under an editor's replacement returns a transient
|
|
331
|
+
// EBUSY/EIO just the same, and only the read for it blocks — the ladder never does.
|
|
332
|
+
if (!this.#closed && this.#schedule())
|
|
333
|
+
return;
|
|
334
|
+
this.#surfaceFailure(error);
|
|
335
|
+
}
|
|
336
|
+
// A failure before anything has been applied is the boot window, where `error` alone strands the
|
|
337
|
+
// component: `Scope` logs it and componentLoader waits on `Scope.ready` with no timeout. Fall
|
|
338
|
+
// back to the defaults exactly as the ENOENT branch above does — and emit `ready` first, since
|
|
339
|
+
// `error` settles the `once(..., 'ready')` promises both of them await.
|
|
340
|
+
#surfaceFailure(error) {
|
|
341
|
+
this.#settleUnconfigured();
|
|
342
|
+
this.#emitError(error);
|
|
343
|
+
}
|
|
344
|
+
// Settling the barrier removes the `error` listener `once(this, 'ready')` attached, and an emit
|
|
345
|
+
// with none left throws the error back at the caller — here, chokidar's dispatch or a retry
|
|
346
|
+
// timer, where nothing can absorb it. A consumer that throws is no different.
|
|
347
|
+
#emitError(error) {
|
|
348
|
+
if (this.listenerCount('error') === 0) {
|
|
349
|
+
this.#logger.error?.(`The configuration for '${this.#name}' at ${this.#filePath} could not be read`, error);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
try {
|
|
353
|
+
this.emit('error', error);
|
|
354
|
+
}
|
|
355
|
+
catch (listenerError) {
|
|
356
|
+
this.#logger.error?.('A configuration error listener failed', listenerError);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
#emitRemove() {
|
|
360
|
+
try {
|
|
361
|
+
this.emit('remove');
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
this.#logger.error?.('A configuration removal listener failed', error);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// `#readyEmitted`, not the config's truthiness: a scope absent from a config that read fine
|
|
368
|
+
// leaves `#rootConfig` set with no `ready` behind it, and a later failure would return here
|
|
369
|
+
// with `Scope.ready` still pending.
|
|
370
|
+
#settleUnconfigured() {
|
|
371
|
+
if (this.#readyEmitted)
|
|
231
372
|
return;
|
|
373
|
+
// A file the watcher cannot use does not unset env config, exactly as on the ENOENT path
|
|
374
|
+
// (#1618) — but the barrier still has to settle, including when composing that env config is
|
|
375
|
+
// itself what failed.
|
|
376
|
+
if (this.#applyEnvOnlyConfig()) {
|
|
377
|
+
if (!this.#readyEmitted)
|
|
378
|
+
this.#emitReady(this.#scopedConfig);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
this.#resetConfig();
|
|
382
|
+
this.#emitReady(this.#scopedConfig);
|
|
383
|
+
}
|
|
384
|
+
// Also on the env-only branch: the caller may be `#handleChange`'s merge-shape failure,
|
|
385
|
+
// whose error composing `undefined` never reproduces.
|
|
386
|
+
this.#reportEnvComposeFailure();
|
|
387
|
+
}
|
|
388
|
+
#emitReady(...args) {
|
|
389
|
+
this.#readyEmitted = true;
|
|
390
|
+
try {
|
|
391
|
+
this.emit('ready', ...args);
|
|
392
|
+
}
|
|
393
|
+
catch (error) {
|
|
394
|
+
// The failure paths emit `ready` from a ladder timer and from chokidar's error dispatch,
|
|
395
|
+
// where a throwing listener is an uncaught exception that takes the worker down.
|
|
396
|
+
this.#logger.error?.('A configuration listener failed', error);
|
|
232
397
|
}
|
|
233
|
-
this.emit('error', error);
|
|
234
398
|
}
|
|
235
399
|
#handleError(error) {
|
|
400
|
+
// A queued chokidar error can land after close(), which has dropped every listener.
|
|
401
|
+
if (this.#closed)
|
|
402
|
+
return;
|
|
236
403
|
// See EntryHandler.#handleWatcherError: a lost native watch handle is benign
|
|
237
404
|
// and must not be surfaced to consumers as a config-watch failure.
|
|
238
405
|
if ((0, watcherFallback_ts_1.claimLostNativeWatchError)(error))
|
|
@@ -244,6 +411,9 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
244
411
|
if (!this.#usingPolling) {
|
|
245
412
|
(0, watcherFallback_ts_1.warnWatcherFallback)(this.#filePath);
|
|
246
413
|
this.#usingPolling = true;
|
|
414
|
+
// The generation that just failed no longer speaks for the watch; the replacement arms
|
|
415
|
+
// on its own scan, and re-reads then as the first one did.
|
|
416
|
+
this.#armGate.reset();
|
|
247
417
|
// Start close() from a microtask, not directly here, so a synchronous throw
|
|
248
418
|
// can't escape this 'error' listener as an uncaught exception.
|
|
249
419
|
Promise.resolve()
|
|
@@ -257,11 +427,35 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
257
427
|
})
|
|
258
428
|
.catch((error) => this.#logger.error?.(`Could not reopen the ${this.#filePath} watch on polling:`, error));
|
|
259
429
|
}
|
|
430
|
+
else {
|
|
431
|
+
// Already polling — the replacement failed too, or the watch was polling from
|
|
432
|
+
// construction (`mustPoll`) and never had a fallback to take. Either way the branch
|
|
433
|
+
// above reopens only once, so no read will ever run: settle the barrier rather than
|
|
434
|
+
// leave `Scope.ready` pending forever.
|
|
435
|
+
this.#settleUnconfigured();
|
|
436
|
+
}
|
|
260
437
|
return;
|
|
261
438
|
}
|
|
262
|
-
this.
|
|
439
|
+
// Terminal for this scope: `componentLoader` awaits `Scope.ready` with no timeout, and an
|
|
440
|
+
// `error` emitted while it is pending rejects that barrier instead of settling it — the
|
|
441
|
+
// asymmetry with `RootConfigWatcher.handleError` the boot-barrier contract cannot afford.
|
|
442
|
+
const watcherError = new OptionsWatcherConfigFileError(this.#filePath, error);
|
|
443
|
+
this.#settleUnconfigured();
|
|
444
|
+
this.#emitError(watcherError);
|
|
263
445
|
}
|
|
264
446
|
#handleUnlink(path) {
|
|
447
|
+
// The deletion settles what a pending read was retrying, and a rung landing after this
|
|
448
|
+
// would find ENOENT and emit a second `remove` at consumers that treat it as teardown.
|
|
449
|
+
// Same for the arming re-read's deferred absence check: this is the event it was waiting on.
|
|
450
|
+
// Cancelling the ladder covers the rung not yet armed; a rung already in flight on the
|
|
451
|
+
// asynchronous path is outranked instead, or its ENOENT would report the same deletion again
|
|
452
|
+
// — after the settle below, as a `remove` that asks `Scope` to restart a scope that just
|
|
453
|
+
// booted on the defaults.
|
|
454
|
+
this.#readRetry.reset();
|
|
455
|
+
this.#appliedSequence = this.#readSequence;
|
|
456
|
+
if (this.#armAbsence)
|
|
457
|
+
clearImmediate(this.#armAbsence);
|
|
458
|
+
this.#armAbsence = undefined;
|
|
265
459
|
// A real deletion still leaves env-var config in force: an env-defined scope must
|
|
266
460
|
// survive it exactly as on the ENOENT read path — same fallback, same error routing
|
|
267
461
|
// (#1618, #1726 review).
|
|
@@ -271,16 +465,24 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
271
465
|
}
|
|
272
466
|
this.#logger.warn?.(`Configuration file ${path} was deleted. Reverting to default configuration. Recreate it to restore the options watcher.`);
|
|
273
467
|
this.#resetConfig();
|
|
274
|
-
|
|
468
|
+
// Before the first `ready` there is nothing to remove and nothing to hear it: `Scope.ready`
|
|
469
|
+
// is still pending, so a `remove` here asks for a restart of a scope that never booted while
|
|
470
|
+
// the `#readRetry.reset()` above cancelled the only thing left to settle the barrier. Same
|
|
471
|
+
// ruling as the ENOENT read path, which already boots on the defaults rather than reporting
|
|
472
|
+
// a removal `ready` would then wait behind forever.
|
|
473
|
+
if (this.#readyEmitted)
|
|
474
|
+
this.#emitRemove();
|
|
475
|
+
else
|
|
476
|
+
this.#emitReady(this.#scopedConfig);
|
|
477
|
+
this.#reportEnvComposeFailure();
|
|
275
478
|
}
|
|
276
479
|
/**
|
|
277
480
|
* Shared fallback for the ENOENT read path and `#handleUnlink`: when config env vars
|
|
278
|
-
* define this scope, apply the env-only overlay (first application → `ready`;
|
|
279
|
-
* configured → `merge`, never reset). Returns
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* their own reset semantics.
|
|
481
|
+
* define this scope, apply the env-only overlay (first source application → `ready`;
|
|
482
|
+
* already configured → `merge`, never reset). Returns false — root config untouched, so
|
|
483
|
+
* callers keep their own reset semantics — when this is not a root config, when the env
|
|
484
|
+
* config does not provide the scope, and when composing it threw, which is held for
|
|
485
|
+
* `#reportEnvComposeFailure` rather than emitted here.
|
|
284
486
|
*/
|
|
285
487
|
#applyEnvOnlyConfig() {
|
|
286
488
|
if (!this.#isRootConfig)
|
|
@@ -290,25 +492,71 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
290
492
|
composed = (0, harperConfigEnvVars_ts_1.overlayRootEnvConfig)(undefined);
|
|
291
493
|
}
|
|
292
494
|
catch (composeError) {
|
|
293
|
-
|
|
294
|
-
|
|
495
|
+
// Env config that cannot be composed is not env config: `false` puts every caller on the
|
|
496
|
+
// path it already takes when there is none, so the barrier still settles on the defaults
|
|
497
|
+
// and a deletion still emits `remove`. The failure is held for `#reportEnvComposeFailure`,
|
|
498
|
+
// which callers run *after* settling — an `error` emitted first settles
|
|
499
|
+
// `once(this, 'ready')` by rejection instead.
|
|
500
|
+
this.#envComposeError = composeError;
|
|
501
|
+
return false;
|
|
295
502
|
}
|
|
296
503
|
if (!composed || !(this.#name in composed))
|
|
297
504
|
return false;
|
|
298
505
|
this.#rootConfig = composed;
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
506
|
+
this.#applyScopedConfig(composed[this.#name]);
|
|
507
|
+
return true;
|
|
508
|
+
}
|
|
509
|
+
#reportEnvComposeFailure() {
|
|
510
|
+
if (this.#envComposeError === undefined)
|
|
511
|
+
return;
|
|
512
|
+
const error = this.#envComposeError;
|
|
513
|
+
this.#envComposeError = undefined;
|
|
514
|
+
this.#emitError(error);
|
|
515
|
+
}
|
|
516
|
+
// A scope with no source config takes `ready`, one with a prior source value takes the granular `change`
|
|
517
|
+
// events `#merge` derives. `ready` is emitted more than once: a scope can go back to having no
|
|
518
|
+
// config of its own — see `Scope.#handleOptionsWatcherReady` for what a repeat means there.
|
|
519
|
+
#applyScopedConfig(next) {
|
|
520
|
+
if (!this.#scopeConfigured) {
|
|
521
|
+
this.#scopeConfigured = true;
|
|
522
|
+
this.#scopedConfig = next;
|
|
523
|
+
this.#emitReady(this.#scopedConfig);
|
|
524
|
+
return;
|
|
302
525
|
}
|
|
303
|
-
|
|
304
|
-
this.#merge(
|
|
526
|
+
if (this.#scopedConfig) {
|
|
527
|
+
return this.#merge(next, this.#scopedConfig);
|
|
305
528
|
}
|
|
306
|
-
|
|
529
|
+
// A falsy scope value is still a configured scope — `myPlugin:` with nothing under it is
|
|
530
|
+
// the idiomatic "enable with defaults" — and `#merge` cannot diff from one, because
|
|
531
|
+
// `#setValue` needs a value to walk. Re-reading it is not a transition (every ladder rung
|
|
532
|
+
// and rename-burst re-read would otherwise look like one), but *filling it in* is a change
|
|
533
|
+
// like any other, not the unconfigured → configured `ready` that `Scope` answers with a
|
|
534
|
+
// restart.
|
|
535
|
+
if ((0, util_1.isDeepStrictEqual)(next, this.#scopedConfig))
|
|
536
|
+
return;
|
|
537
|
+
this.#scopedConfig = next;
|
|
538
|
+
this.#emitChange([], next);
|
|
307
539
|
}
|
|
540
|
+
// Cloned, never aliased: `#merge` writes into `#scopedConfig` in place, so a scope that starts
|
|
541
|
+
// on the defaults and is then configured would otherwise write the app's values into the
|
|
542
|
+
// module-level `DEFAULT_CONFIG` every later reset hands out. And not configured: the six scopes
|
|
543
|
+
// `DEFAULT_CONFIG` names would otherwise have the next read of an unchanged file look like the
|
|
544
|
+
// block being deleted.
|
|
308
545
|
#resetConfig() {
|
|
309
|
-
this.#
|
|
546
|
+
this.#scopeConfigured = false;
|
|
547
|
+
this.#rootConfig = (0, lodash_1.cloneDeep)(DEFAULT_CONFIG_ts_1.DEFAULT_CONFIG);
|
|
310
548
|
this.#scopedConfig = this.#rootConfig[this.#name];
|
|
311
549
|
}
|
|
550
|
+
#deferAbsenceCheck() {
|
|
551
|
+
if (this.#armAbsence)
|
|
552
|
+
return;
|
|
553
|
+
this.#armAbsence = setImmediate(() => {
|
|
554
|
+
this.#armAbsence = undefined;
|
|
555
|
+
if (!this.#closed)
|
|
556
|
+
this.#read(true);
|
|
557
|
+
});
|
|
558
|
+
this.#armAbsence.unref?.();
|
|
559
|
+
}
|
|
312
560
|
/**
|
|
313
561
|
* This merge algorithm is best thought off as a diff and overwrite.
|
|
314
562
|
* The new config object will completely overwrite the old config object,
|
|
@@ -390,7 +638,7 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
390
638
|
}
|
|
391
639
|
if (keys.length === 0) {
|
|
392
640
|
this.#scopedConfig = value;
|
|
393
|
-
this
|
|
641
|
+
this.#emitChange(keys, value);
|
|
394
642
|
return;
|
|
395
643
|
}
|
|
396
644
|
let obj = this.#scopedConfig;
|
|
@@ -404,14 +652,19 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
404
652
|
throw new CannotSetPropertyError(keys);
|
|
405
653
|
}
|
|
406
654
|
obj[keys[keys.length - 1]] = value;
|
|
407
|
-
this
|
|
655
|
+
this.#emitChange(keys, value);
|
|
408
656
|
}
|
|
409
|
-
//
|
|
410
|
-
//
|
|
411
|
-
//
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
657
|
+
// `#merge` runs inside chokidar's own dispatch on the unlink and env-fallback paths, where a
|
|
658
|
+
// plugin's `change` handler throwing would leave the worker with an uncaught exception on a
|
|
659
|
+
// config event the watcher had just decided to survive. It still reaches consumers as `error`
|
|
660
|
+
// — a listener fault is not a read fault, which is why it must not reach `#handleReadError`.
|
|
661
|
+
#emitChange(keys, value) {
|
|
662
|
+
try {
|
|
663
|
+
this.emit('change', keys, value, this.#scopedConfig);
|
|
664
|
+
}
|
|
665
|
+
catch (error) {
|
|
666
|
+
this.#emitError(error);
|
|
667
|
+
}
|
|
415
668
|
}
|
|
416
669
|
// Test-only: simulate the underlying chokidar watcher emitting an error.
|
|
417
670
|
// Exposed so the polling-fallback path can be exercised without triggering a
|
|
@@ -419,24 +672,45 @@ class OptionsWatcher extends events_1.EventEmitter {
|
|
|
419
672
|
_simulateWatcherErrorForTests(error) {
|
|
420
673
|
this.#handleError(error);
|
|
421
674
|
}
|
|
422
|
-
// Test-only:
|
|
675
|
+
// Test-only: a real unlink cannot be ordered against a read already in flight — see DESIGN.md,
|
|
676
|
+
// "Root config watchers must read synchronously".
|
|
677
|
+
_simulateUnlinkForTests(path) {
|
|
678
|
+
this.#handleUnlink(path);
|
|
679
|
+
}
|
|
423
680
|
get _usingPollingForTests() {
|
|
424
681
|
return this.#usingPolling;
|
|
425
682
|
}
|
|
426
|
-
//
|
|
427
|
-
// Used to assert that a close()-during-fallback race didn't install a
|
|
428
|
-
// replacement watcher.
|
|
683
|
+
// Used to assert that a close()-during-fallback race didn't install a replacement watcher.
|
|
429
684
|
get _openCountForTests() {
|
|
430
685
|
return this.#openCount;
|
|
431
686
|
}
|
|
687
|
+
// Distinguishes a ladder rung from a watcher event.
|
|
688
|
+
get _readCountForTests() {
|
|
689
|
+
return this.#readCount;
|
|
690
|
+
}
|
|
691
|
+
get _armedForTests() {
|
|
692
|
+
return this.#armGate.armed;
|
|
693
|
+
}
|
|
694
|
+
// Test-only: read now, rather than at whatever granularity a chokidar event would arrive.
|
|
695
|
+
_refreshForTests(arming = false) {
|
|
696
|
+
this.#read(true, arming);
|
|
697
|
+
return Promise.allSettled([...this.#pendingReads]);
|
|
698
|
+
}
|
|
432
699
|
/**
|
|
433
700
|
* Closes the underlying file watcher and drains any pending config-file reads.
|
|
434
701
|
* Emits `close` synchronously, removes all listeners, then returns a Promise that
|
|
435
702
|
* resolves once the chokidar watcher has fully stopped and all in-flight reads settle.
|
|
436
703
|
*/
|
|
437
704
|
close() {
|
|
705
|
+
// Terminal like every other outcome, and `Scope.ready` has no timeout. Before `#closed` and
|
|
706
|
+
// through `#emitReady`, so a listener that throws cannot skip the teardown below it.
|
|
707
|
+
this.#settleUnconfigured();
|
|
438
708
|
this.#closed = true;
|
|
439
|
-
this.#
|
|
709
|
+
this.#readRetry.cancel();
|
|
710
|
+
this.#armGate.cancel();
|
|
711
|
+
if (this.#armAbsence)
|
|
712
|
+
clearImmediate(this.#armAbsence);
|
|
713
|
+
this.#armAbsence = undefined;
|
|
440
714
|
const pendingReads = [...this.#pendingReads];
|
|
441
715
|
const watcherClose = Promise.resolve(this.#watcher.close()).catch(() => { });
|
|
442
716
|
this.emit('close');
|