@harperfast/harper 5.0.0-alpha.10 → 5.0.0-beta.3
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/BinObjects.js +17 -0
- package/bin/cliOperations.js +157 -0
- package/bin/copyDb.ts +280 -0
- package/bin/harper.js +156 -0
- package/bin/install.js +15 -0
- package/bin/lite.js +5 -0
- package/bin/restart.js +201 -0
- package/bin/run.js +409 -0
- package/bin/status.js +65 -0
- package/bin/stop.js +22 -0
- package/bin/upgrade.js +134 -0
- package/components/Application.ts +646 -0
- package/components/ApplicationScope.ts +49 -0
- package/components/Component.ts +53 -0
- package/components/ComponentV1.ts +342 -0
- package/components/DEFAULT_CONFIG.ts +18 -0
- package/components/EntryHandler.ts +227 -0
- package/components/Logger.ts +14 -0
- package/components/OptionsWatcher.ts +354 -0
- package/components/PluginModule.ts +6 -0
- package/components/Scope.ts +329 -0
- package/components/componentLoader.ts +529 -0
- package/components/deriveCommonPatternBase.ts +31 -0
- package/components/deriveGlobOptions.ts +44 -0
- package/components/deriveURLPath.ts +57 -0
- package/components/operations.js +658 -0
- package/components/operationsValidation.js +246 -0
- package/components/packageComponent.ts +39 -0
- package/components/requestRestart.ts +26 -0
- package/components/resolveBaseURLPath.ts +38 -0
- package/components/status/ComponentStatus.ts +110 -0
- package/components/status/ComponentStatusRegistry.ts +251 -0
- package/components/status/api.ts +153 -0
- package/components/status/crossThread.ts +405 -0
- package/components/status/errors.ts +152 -0
- package/components/status/index.ts +44 -0
- package/components/status/internal.ts +65 -0
- package/components/status/registry.ts +12 -0
- package/components/status/types.ts +96 -0
- package/config/RootConfigWatcher.ts +59 -0
- package/config/configHelpers.ts +11 -0
- package/config/configUtils.js +967 -0
- package/config/harperConfigEnvVars.ts +641 -0
- package/dataLayer/CreateAttributeObject.js +25 -0
- package/dataLayer/CreateTableObject.js +11 -0
- package/dataLayer/DataLayerObjects.js +43 -0
- package/dataLayer/DeleteBeforeObject.js +22 -0
- package/dataLayer/DeleteObject.js +25 -0
- package/dataLayer/DropAttributeObject.js +11 -0
- package/dataLayer/GetBackupObject.js +22 -0
- package/dataLayer/InsertObject.js +24 -0
- package/dataLayer/ReadAuditLogObject.js +24 -0
- package/dataLayer/SQLSearch.js +1335 -0
- package/dataLayer/SearchByConditionsObject.js +61 -0
- package/dataLayer/SearchByHashObject.js +21 -0
- package/dataLayer/SearchObject.js +45 -0
- package/dataLayer/SqlSearchObject.js +14 -0
- package/dataLayer/UpdateObject.js +23 -0
- package/dataLayer/UpsertObject.js +23 -0
- package/dataLayer/bulkLoad.js +813 -0
- package/dataLayer/dataObjects/BulkLoadObjects.js +27 -0
- package/dataLayer/dataObjects/UpsertObject.js +23 -0
- package/dataLayer/delete.js +164 -0
- package/dataLayer/export.js +381 -0
- package/dataLayer/getBackup.js +40 -0
- package/dataLayer/harperBridge/BridgeMethods.js +81 -0
- package/dataLayer/harperBridge/ResourceBridge.ts +633 -0
- package/dataLayer/harperBridge/bridgeUtility/insertUpdateReturnObj.js +28 -0
- package/dataLayer/harperBridge/bridgeUtility/insertUpdateValidate.js +88 -0
- package/dataLayer/harperBridge/harperBridge.js +21 -0
- package/dataLayer/harperBridge/lmdbBridge/LMDBBridge.js +119 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.js +19 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.js +112 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.js +67 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.js +31 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.js +94 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.js +98 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecords.js +89 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.js +109 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.js +107 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.js +137 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbFlush.js +35 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetBackup.js +111 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByHash.js +28 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.js +29 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbReadAuditLog.js +207 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.js +156 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.js +21 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.js +30 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbTransaction.js +19 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpdateRecords.js +64 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.js +70 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.js +22 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBDeleteTransactionObject.js +23 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBInsertTransactionObject.js +22 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBTransactionObject.js +23 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBUpdateTransactionObject.js +24 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBUpsertTransactionObject.js +24 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/TableSizeObject.js +25 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.js +21 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js +157 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.js +94 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.js +39 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.js +34 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.js +100 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbSearch.js +371 -0
- package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbWriteTransaction.js +109 -0
- package/dataLayer/hdbInfoController.js +254 -0
- package/dataLayer/insert.js +266 -0
- package/dataLayer/readAuditLog.js +59 -0
- package/dataLayer/schema.js +366 -0
- package/dataLayer/schemaDescribe.js +289 -0
- package/dataLayer/search.js +60 -0
- package/dataLayer/transaction.js +17 -0
- package/dataLayer/update.js +124 -0
- package/dist/components/Logger.d.ts +12 -0
- package/dist/{resources/ResourceInterfaceV2.js → components/Logger.js} +1 -1
- package/dist/components/Logger.js.map +1 -0
- package/dist/components/Scope.d.ts +14 -4
- package/dist/components/Scope.js +18 -10
- package/dist/components/Scope.js.map +1 -1
- package/dist/components/componentLoader.js +17 -10
- package/dist/components/componentLoader.js.map +1 -1
- package/dist/components/operations.js +2 -2
- package/dist/components/operations.js.map +1 -1
- package/dist/config/configUtils.d.ts +1 -1
- package/dist/config/configUtils.js +1 -1
- package/dist/config/configUtils.js.map +1 -1
- package/dist/dataLayer/CreateTableObject.d.ts +2 -2
- package/dist/dataLayer/CreateTableObject.js +2 -2
- package/dist/dataLayer/CreateTableObject.js.map +1 -1
- package/dist/dataLayer/delete.d.ts +1 -1
- package/dist/dataLayer/schema.js +6 -5
- package/dist/dataLayer/schema.js.map +1 -1
- package/dist/dataLayer/schemaDescribe.js +1 -1
- package/dist/dataLayer/schemaDescribe.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/resources/DatabaseTransaction.d.ts +1 -1
- package/dist/resources/IterableEventQueue.d.ts +1 -1
- package/dist/resources/LMDBTransaction.d.ts +5 -1
- package/dist/resources/Resource.d.ts +1 -1
- package/dist/resources/ResourceInterface.d.ts +1 -1
- package/dist/resources/RocksIndexStore.d.ts +3 -3
- package/dist/resources/RocksTransactionLogStore.d.ts +6 -3
- package/dist/resources/Table.d.ts +15 -6
- package/dist/resources/Table.js +12 -4
- package/dist/resources/Table.js.map +1 -1
- package/dist/resources/analytics/read.js +32 -22
- package/dist/resources/analytics/read.js.map +1 -1
- package/dist/resources/analytics/write.js +3 -6
- package/dist/resources/analytics/write.js.map +1 -1
- package/dist/resources/auditStore.d.ts +3 -3
- package/dist/resources/blob.d.ts +25 -2
- package/dist/resources/databases.d.ts +12 -2
- package/dist/resources/databases.js +22 -19
- package/dist/resources/databases.js.map +1 -1
- package/dist/resources/search.js +11 -5
- package/dist/resources/search.js.map +1 -1
- package/dist/resources/transaction.d.ts +2 -1
- package/dist/security/auth.js +1 -1
- package/dist/security/auth.js.map +1 -1
- package/dist/security/cryptoHash.d.ts +2 -2
- package/dist/security/jsLoader.js +265 -73
- package/dist/security/jsLoader.js.map +1 -1
- package/dist/security/keys.js +11 -12
- package/dist/security/keys.js.map +1 -1
- package/dist/security/user.js +3 -3
- package/dist/security/user.js.map +1 -1
- package/dist/server/REST.js +16 -2
- package/dist/server/REST.js.map +1 -1
- package/dist/server/Server.d.ts +2 -1
- package/dist/server/Server.js.map +1 -1
- package/dist/server/fastifyRoutes/plugins/hdbCore.d.ts +6 -1
- package/dist/server/fastifyRoutes.js +2 -0
- package/dist/server/fastifyRoutes.js.map +1 -1
- package/dist/server/http.js +12 -6
- package/dist/server/http.js.map +1 -1
- package/dist/server/jobs/JobObject.d.ts +3 -3
- package/dist/server/loadRootComponents.js +1 -0
- package/dist/server/loadRootComponents.js.map +1 -1
- package/dist/server/operationsServer.js +3 -1
- package/dist/server/operationsServer.js.map +1 -1
- package/dist/server/serverHelpers/JSONStream.d.ts +3 -3
- package/dist/server/serverHelpers/Request.d.ts +5 -5
- package/dist/server/serverHelpers/requestTimePlugin.d.ts +1 -1
- package/dist/server/threads/manageThreads.d.ts +2 -2
- package/dist/server/threads/manageThreads.js +52 -35
- package/dist/server/threads/manageThreads.js.map +1 -1
- package/dist/server/threads/socketRouter.d.ts +1 -1
- package/dist/sqlTranslator/deleteTranslator.d.ts +1 -1
- package/dist/utility/AWS/AWSConnector.d.ts +3 -2
- package/dist/utility/common_utils.d.ts +3 -3
- package/dist/utility/environment/systemInformation.d.ts +1 -0
- package/dist/utility/functions/date/dateFunctions.d.ts +11 -11
- package/dist/utility/globalSchema.d.ts +1 -1
- package/dist/utility/hdbTerms.d.ts +3 -0
- package/dist/utility/hdbTerms.js +3 -0
- package/dist/utility/hdbTerms.js.map +1 -1
- package/dist/utility/installation.d.ts +2 -4
- package/dist/utility/installation.js.map +1 -1
- package/dist/utility/lmdb/commonUtility.d.ts +2 -1
- package/dist/utility/lmdb/commonUtility.js +20 -13
- package/dist/utility/lmdb/commonUtility.js.map +1 -1
- package/dist/utility/lmdb/deleteUtility.d.ts +1 -0
- package/dist/utility/lmdb/environmentUtility.d.ts +1 -0
- package/dist/utility/lmdb/searchUtility.d.ts +2 -1
- package/dist/utility/lmdb/writeUtility.d.ts +1 -0
- package/dist/utility/logging/harper_logger.d.ts +6 -6
- package/dist/utility/processManagement/processManagement.d.ts +1 -1
- package/dist/utility/processManagement/servicesConfig.d.ts +12 -6
- package/dist/validation/common_validators.d.ts +4 -3
- package/dist/validation/configValidator.d.ts +3 -2
- package/index.d.ts +56 -0
- package/index.js +41 -0
- package/json/systemSchema.json +373 -0
- package/launchServiceScripts/launchHarperDB.js +3 -0
- package/launchServiceScripts/utility/checkNodeVersion.js +15 -0
- package/package.json +35 -16
- package/resources/DatabaseTransaction.ts +378 -0
- package/resources/ErrorResource.ts +57 -0
- package/resources/IterableEventQueue.ts +94 -0
- package/resources/LMDBTransaction.ts +349 -0
- package/resources/RecordEncoder.ts +702 -0
- package/resources/RequestTarget.ts +134 -0
- package/resources/Resource.ts +789 -0
- package/resources/ResourceInterface.ts +221 -0
- package/resources/Resources.ts +162 -0
- package/resources/RocksIndexStore.ts +70 -0
- package/resources/RocksTransactionLogStore.ts +352 -0
- package/resources/Table.ts +4531 -0
- package/resources/analytics/hostnames.ts +72 -0
- package/resources/analytics/metadata.ts +10 -0
- package/resources/analytics/read.ts +252 -0
- package/resources/analytics/write.ts +803 -0
- package/resources/auditStore.ts +556 -0
- package/resources/blob.ts +1268 -0
- package/resources/crdt.ts +125 -0
- package/resources/dataLoader.ts +527 -0
- package/resources/databases.ts +1290 -0
- package/resources/graphql.ts +221 -0
- package/resources/indexes/HierarchicalNavigableSmallWorld.ts +638 -0
- package/resources/indexes/customIndexes.ts +7 -0
- package/resources/indexes/vector.ts +38 -0
- package/resources/jsResource.ts +86 -0
- package/resources/loadEnv.ts +22 -0
- package/resources/login.ts +18 -0
- package/resources/openApi.ts +409 -0
- package/resources/registrationDeprecated.ts +8 -0
- package/resources/replayLogs.ts +136 -0
- package/resources/roles.ts +98 -0
- package/resources/search.ts +1301 -0
- package/resources/tracked.ts +584 -0
- package/resources/transaction.ts +89 -0
- package/resources/transactionBroadcast.ts +258 -0
- package/security/auth.ts +376 -0
- package/security/certificateVerification/certificateVerificationSource.ts +84 -0
- package/security/certificateVerification/configValidation.ts +107 -0
- package/security/certificateVerification/crlVerification.ts +623 -0
- package/security/certificateVerification/index.ts +121 -0
- package/security/certificateVerification/ocspVerification.ts +148 -0
- package/security/certificateVerification/pkijs-ed25519-patch.ts +188 -0
- package/security/certificateVerification/types.ts +128 -0
- package/security/certificateVerification/verificationConfig.ts +138 -0
- package/security/certificateVerification/verificationUtils.ts +447 -0
- package/security/cryptoHash.js +42 -0
- package/security/data_objects/PermissionAttributeResponseObject.js +15 -0
- package/security/data_objects/PermissionResponseObject.js +115 -0
- package/security/data_objects/PermissionTableResponseObject.js +20 -0
- package/security/fastifyAuth.js +169 -0
- package/security/impersonation.ts +160 -0
- package/security/jsLoader.ts +733 -0
- package/security/keys.js +948 -0
- package/security/permissionsTranslator.js +300 -0
- package/security/role.js +218 -0
- package/security/tokenAuthentication.ts +228 -0
- package/security/user.ts +449 -0
- package/server/DurableSubscriptionsSession.ts +503 -0
- package/server/REST.ts +407 -0
- package/server/Server.ts +89 -0
- package/server/fastifyRoutes/helpers/getCORSOptions.js +36 -0
- package/server/fastifyRoutes/helpers/getHeaderTimeoutConfig.js +15 -0
- package/server/fastifyRoutes/helpers/getServerOptions.js +33 -0
- package/server/fastifyRoutes/plugins/hdbCore.js +39 -0
- package/server/fastifyRoutes.ts +205 -0
- package/server/graphqlQuerying.ts +700 -0
- package/server/http.ts +640 -0
- package/server/itc/serverHandlers.js +161 -0
- package/server/itc/utility/ITCEventObject.js +10 -0
- package/server/jobs/JobObject.js +24 -0
- package/server/jobs/jobProcess.js +69 -0
- package/server/jobs/jobRunner.js +162 -0
- package/server/jobs/jobs.js +304 -0
- package/server/loadRootComponents.js +44 -0
- package/server/mqtt.ts +485 -0
- package/server/nodeName.ts +75 -0
- package/server/operationsServer.ts +313 -0
- package/server/serverHelpers/Headers.ts +108 -0
- package/server/serverHelpers/JSONStream.ts +269 -0
- package/server/serverHelpers/OperationFunctionObject.ts +13 -0
- package/server/serverHelpers/Request.ts +158 -0
- package/server/serverHelpers/contentTypes.ts +637 -0
- package/server/serverHelpers/requestTimePlugin.js +57 -0
- package/server/serverHelpers/serverHandlers.js +148 -0
- package/server/serverHelpers/serverUtilities.ts +473 -0
- package/server/serverRegistry.ts +8 -0
- package/server/static.ts +187 -0
- package/server/status/definitions.ts +37 -0
- package/server/status/index.ts +125 -0
- package/server/storageReclamation.ts +93 -0
- package/server/threads/itc.js +89 -0
- package/server/threads/manageThreads.js +596 -0
- package/server/threads/socketRouter.ts +360 -0
- package/server/threads/threadServer.js +279 -0
- package/server/throttle.ts +73 -0
- package/sqlTranslator/SelectValidator.js +330 -0
- package/sqlTranslator/alasqlFunctionImporter.js +62 -0
- package/sqlTranslator/deleteTranslator.js +67 -0
- package/sqlTranslator/index.js +242 -0
- package/sqlTranslator/sql_statement_bucket.js +472 -0
- package/static/defaultConfig.yaml +3 -0
- package/studio/web/HDBDogOnly.svg +78 -0
- package/studio/web/assets/PPRadioGrotesk-Bold-DDaUYG8E.woff +0 -0
- package/studio/web/assets/fa-brands-400-CEJbCg16.woff +0 -0
- package/studio/web/assets/fa-brands-400-CSYNqBb_.ttf +0 -0
- package/studio/web/assets/fa-brands-400-DnkPfk3o.eot +0 -0
- package/studio/web/assets/fa-brands-400-UxlILjvJ.woff2 +0 -0
- package/studio/web/assets/fa-brands-400-cH1MgKbP.svg +3717 -0
- package/studio/web/assets/fa-regular-400-BhTwtT8w.eot +0 -0
- package/studio/web/assets/fa-regular-400-D1vz6WBx.ttf +0 -0
- package/studio/web/assets/fa-regular-400-DFnMcJPd.woff +0 -0
- package/studio/web/assets/fa-regular-400-DGzu1beS.woff2 +0 -0
- package/studio/web/assets/fa-regular-400-gwj8Pxq-.svg +801 -0
- package/studio/web/assets/fa-solid-900-B4ZZ7kfP.svg +5034 -0
- package/studio/web/assets/fa-solid-900-B6Axprfb.eot +0 -0
- package/studio/web/assets/fa-solid-900-BUswJgRo.woff2 +0 -0
- package/studio/web/assets/fa-solid-900-DOXgCApm.woff +0 -0
- package/studio/web/assets/fa-solid-900-mxuxnBEa.ttf +0 -0
- package/studio/web/assets/index-C1G-Jo6n.js +37 -0
- package/studio/web/assets/index-C1G-Jo6n.js.map +1 -0
- package/studio/web/assets/index-D-CahN0-.js +2 -0
- package/studio/web/assets/index-D-CahN0-.js.map +1 -0
- package/studio/web/assets/index-DxlZI0PX.js +235 -0
- package/studio/web/assets/index-DxlZI0PX.js.map +1 -0
- package/studio/web/assets/index-Y2g_iFpU.css +1 -0
- package/studio/web/assets/index-jiPwkrsB.css +1 -0
- package/studio/web/assets/index.lazy-BUXDDqq9.js +266 -0
- package/studio/web/assets/index.lazy-BUXDDqq9.js.map +1 -0
- package/studio/web/assets/profiler-CU93QiSW.js +2 -0
- package/studio/web/assets/profiler-CU93QiSW.js.map +1 -0
- package/studio/web/assets/react-redux-B8k9Ep7e.js +6 -0
- package/studio/web/assets/react-redux-B8k9Ep7e.js.map +1 -0
- package/studio/web/assets/startRecording-DFeBXGk6.js +3 -0
- package/studio/web/assets/startRecording-DFeBXGk6.js.map +1 -0
- package/studio/web/fabric-signup-background.webp +0 -0
- package/studio/web/fabric-signup-text.png +0 -0
- package/studio/web/favicon_purple.png +0 -0
- package/studio/web/github-icon.svg +15 -0
- package/studio/web/harper-fabric_black.png +0 -0
- package/studio/web/harper-fabric_white.png +0 -0
- package/studio/web/harper-studio_white.png +0 -0
- package/studio/web/index.html +16 -0
- package/studio/web/running.css +148 -0
- package/studio/web/running.html +147 -0
- package/studio/web/running.js +111 -0
- package/upgrade/UpgradeObjects.js +13 -0
- package/upgrade/directives/directivesController.js +90 -0
- package/upgrade/directivesManager.js +139 -0
- package/upgrade/upgradePrompt.js +124 -0
- package/upgrade/upgradeUtilities.js +28 -0
- package/utility/AWS/AWSConnector.js +29 -0
- package/utility/OperationFunctionCaller.js +63 -0
- package/utility/assignCmdEnvVariables.js +62 -0
- package/utility/common_utils.js +867 -0
- package/utility/environment/environmentManager.js +208 -0
- package/utility/environment/systemInformation.js +355 -0
- package/utility/errors/commonErrors.js +267 -0
- package/utility/errors/hdbError.js +146 -0
- package/utility/functions/date/dateFunctions.js +65 -0
- package/utility/functions/geo.js +355 -0
- package/utility/functions/sql/alaSQLExtension.js +104 -0
- package/utility/globalSchema.js +35 -0
- package/utility/hdbTerms.ts +819 -0
- package/utility/install/checkJWTTokensExist.js +62 -0
- package/utility/install/harperdb.conf +15 -0
- package/utility/install/harperdb.service +14 -0
- package/utility/install/installer.js +635 -0
- package/utility/installation.ts +30 -0
- package/utility/lmdb/DBIDefinition.js +20 -0
- package/utility/lmdb/DeleteRecordsResponseObject.js +25 -0
- package/utility/lmdb/InsertRecordsResponseObject.js +22 -0
- package/utility/lmdb/OpenDBIObject.js +31 -0
- package/utility/lmdb/OpenEnvironmentObject.js +41 -0
- package/utility/lmdb/UpdateRecordsResponseObject.js +25 -0
- package/utility/lmdb/UpsertRecordsResponseObject.js +22 -0
- package/utility/lmdb/cleanLMDBMap.js +65 -0
- package/utility/lmdb/commonUtility.js +130 -0
- package/utility/lmdb/deleteUtility.js +128 -0
- package/utility/lmdb/environmentUtility.js +477 -0
- package/utility/lmdb/searchCursorFunctions.js +187 -0
- package/utility/lmdb/searchUtility.js +918 -0
- package/utility/lmdb/terms.js +57 -0
- package/utility/lmdb/writeUtility.js +407 -0
- package/utility/logging/harper_logger.js +876 -0
- package/utility/logging/logRotator.js +157 -0
- package/utility/logging/logger.ts +24 -0
- package/utility/logging/readLog.js +355 -0
- package/utility/logging/transactionLog.js +57 -0
- package/utility/mount_hdb.js +59 -0
- package/utility/npmUtilities.js +102 -0
- package/utility/operationPermissions.ts +112 -0
- package/utility/operation_authorization.js +836 -0
- package/utility/packageUtils.js +55 -0
- package/utility/password.ts +99 -0
- package/utility/processManagement/processManagement.js +187 -0
- package/utility/processManagement/servicesConfig.js +56 -0
- package/utility/scripts/restartHdb.js +24 -0
- package/utility/scripts/user_data.sh +13 -0
- package/utility/signalling.js +36 -0
- package/utility/terms/certificates.js +81 -0
- package/utility/when.ts +20 -0
- package/validation/bulkDeleteValidator.js +24 -0
- package/validation/check_permissions.js +19 -0
- package/validation/common_validators.js +95 -0
- package/validation/configValidator.js +331 -0
- package/validation/deleteValidator.js +15 -0
- package/validation/fileLoadValidator.js +153 -0
- package/validation/insertValidator.js +40 -0
- package/validation/installValidator.js +37 -0
- package/validation/readLogValidator.js +64 -0
- package/validation/role_validation.js +320 -0
- package/validation/schemaMetadataValidator.js +42 -0
- package/validation/searchValidator.js +166 -0
- package/validation/statusValidator.ts +66 -0
- package/validation/transactionLogValidator.js +33 -0
- package/validation/user_validation.js +55 -0
- package/validation/validationWrapper.js +105 -0
- package/dist/resources/ResourceInterfaceV2.d.ts +0 -21
- package/dist/resources/ResourceInterfaceV2.js.map +0 -1
- package/dist/resources/ResourceV2.d.ts +0 -30
- package/dist/resources/ResourceV2.js +0 -27
- package/dist/resources/ResourceV2.js.map +0 -1
- package/dist/resources/analytics/profile.d.ts +0 -2
- package/dist/resources/analytics/profile.js +0 -144
- package/dist/resources/analytics/profile.js.map +0 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { promises: fsProm, createReadStream, createWriteStream } = require('fs');
|
|
4
|
+
const { createGzip } = require('zlib');
|
|
5
|
+
const { promisify } = require('util');
|
|
6
|
+
const { pipeline } = require('stream');
|
|
7
|
+
const pipe = promisify(pipeline);
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const envMgr = require('../environment/environmentManager.js');
|
|
10
|
+
envMgr.initSync();
|
|
11
|
+
const hdbLogger = require('./harper_logger.js');
|
|
12
|
+
const { CONFIG_PARAMS } = require('../hdbTerms.ts');
|
|
13
|
+
const { convertToMS } = require('../common_utils.js');
|
|
14
|
+
const { onStorageReclamation } = require('../../server/storageReclamation.ts');
|
|
15
|
+
|
|
16
|
+
// Interval in ms to check log file and decide if it should be rotated.
|
|
17
|
+
const LOG_AUDIT_INTERVAL = 60000;
|
|
18
|
+
const INT_SIZE_UNDEFINED_MSG =
|
|
19
|
+
"'interval' and 'maxSize' are both undefined, to enable logging rotation at least one of these values must be defined in harperdb-config.yaml";
|
|
20
|
+
const PATH_UNDEFINED_MSG =
|
|
21
|
+
"'logging.rotation.path' is undefined, to enable logging rotation set this value in harperdb-config.yaml";
|
|
22
|
+
|
|
23
|
+
let lastRotationTime;
|
|
24
|
+
let setIntervalId;
|
|
25
|
+
|
|
26
|
+
module.exports = logRotator;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Rotates hdb.log using an interval and/or maxSize param to determine if log should be rotated.
|
|
30
|
+
* Uses an unref setInterval to periodically check time passed since rotation and size of log file.
|
|
31
|
+
* If log file is within the values set in config, log file will be renamed/moved and a new empty hdb.log created.
|
|
32
|
+
* @returns LogRotator
|
|
33
|
+
*/
|
|
34
|
+
function logRotator({ logger, maxSize, interval, retention, enabled, path: rotatedLogDir, auditInterval }) {
|
|
35
|
+
if (enabled === false) return;
|
|
36
|
+
let reclamationPriority = 0;
|
|
37
|
+
onStorageReclamation(
|
|
38
|
+
logger.path,
|
|
39
|
+
(priority) => {
|
|
40
|
+
reclamationPriority = priority;
|
|
41
|
+
},
|
|
42
|
+
true
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (!maxSize && !interval) {
|
|
46
|
+
throw new Error(INT_SIZE_UNDEFINED_MSG);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!rotatedLogDir) {
|
|
50
|
+
throw new Error(PATH_UNDEFINED_MSG);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Convert maxSize param to bytes.
|
|
54
|
+
let maxBytes;
|
|
55
|
+
if (maxSize) {
|
|
56
|
+
const unit = maxSize.slice(-1);
|
|
57
|
+
const size = maxSize.slice(0, -1);
|
|
58
|
+
if (unit === 'G') maxBytes = size * 1000000000;
|
|
59
|
+
else if (unit === 'M') maxBytes = size * 1000000;
|
|
60
|
+
else maxBytes = size * 1000;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Convert interval param to ms.
|
|
64
|
+
let maxInterval;
|
|
65
|
+
if (interval) {
|
|
66
|
+
maxInterval = convertToMS(interval);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let lastRotatedLogPath;
|
|
70
|
+
// convert date.now to minutes
|
|
71
|
+
lastRotationTime = Date.now();
|
|
72
|
+
hdbLogger.trace('Log rotate enabled, maxSize:', maxSize, 'interval:', interval);
|
|
73
|
+
setIntervalId = setInterval(async () => {
|
|
74
|
+
if (maxBytes) {
|
|
75
|
+
let fileStats;
|
|
76
|
+
try {
|
|
77
|
+
fileStats = await fsProm.stat(logger.path);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
// If the log file doesn't exist, skip rotation check
|
|
80
|
+
if (err.code === 'ENOENT') return;
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (fileStats.size >= maxBytes) {
|
|
85
|
+
try {
|
|
86
|
+
lastRotatedLogPath = await moveLogFile(logger.path, rotatedLogDir);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
// If the log file doesn't exist, skip rotation
|
|
89
|
+
if (err.code === 'ENOENT') return;
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (maxInterval) {
|
|
96
|
+
const minSinceLastRotate = Date.now() - lastRotationTime;
|
|
97
|
+
if (minSinceLastRotate >= maxInterval) {
|
|
98
|
+
try {
|
|
99
|
+
lastRotatedLogPath = await moveLogFile(logger.path, rotatedLogDir);
|
|
100
|
+
lastRotationTime = Date.now();
|
|
101
|
+
} catch (err) {
|
|
102
|
+
// If the log file doesn't exist, skip rotation
|
|
103
|
+
if (err.code === 'ENOENT') return;
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (retention || reclamationPriority) {
|
|
109
|
+
// remove old logs after retention time
|
|
110
|
+
// adjust retention time if there is a reclamation priority in place
|
|
111
|
+
const retentionMs = convertToMS(retention ?? '1M') / (1 + reclamationPriority);
|
|
112
|
+
reclamationPriority = 0; // reset it after use
|
|
113
|
+
const files = await fsProm.readdir(rotatedLogDir);
|
|
114
|
+
for (const file of files) {
|
|
115
|
+
try {
|
|
116
|
+
const fileStats = await fsProm.stat(path.join(rotatedLogDir, file));
|
|
117
|
+
if (Date.now() - fileStats.mtimeMs > retentionMs) {
|
|
118
|
+
await fsProm.unlink(path.join(rotatedLogDir, file));
|
|
119
|
+
}
|
|
120
|
+
} catch (err) {
|
|
121
|
+
hdbLogger.error('Error trying to remove log', file, err);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, auditInterval ?? LOG_AUDIT_INTERVAL).unref();
|
|
126
|
+
return {
|
|
127
|
+
end() {
|
|
128
|
+
clearInterval(setIntervalId);
|
|
129
|
+
},
|
|
130
|
+
getLastRotatedLogPath() {
|
|
131
|
+
return lastRotatedLogPath;
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function moveLogFile(logPath, rotatedLogPath) {
|
|
137
|
+
const compress = envMgr.get(CONFIG_PARAMS.LOGGING_ROTATION_COMPRESS);
|
|
138
|
+
let fullRotateLogPath = path.join(
|
|
139
|
+
rotatedLogPath,
|
|
140
|
+
`HDB-${new Date(Date.now()).toISOString().replaceAll(':', '-')}.log`
|
|
141
|
+
);
|
|
142
|
+
// Move log file to rotated log path first (if we crash
|
|
143
|
+
// during compression, we don't want to restart the compression with a new file)
|
|
144
|
+
await fsProm.rename(logPath, fullRotateLogPath);
|
|
145
|
+
if (compress) {
|
|
146
|
+
logPath = fullRotateLogPath;
|
|
147
|
+
fullRotateLogPath += '.gz';
|
|
148
|
+
await pipe(createReadStream(logPath), createGzip(), createWriteStream(fullRotateLogPath));
|
|
149
|
+
await fsProm.unlink(logPath);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Close old log file.
|
|
153
|
+
hdbLogger.closeLogFile();
|
|
154
|
+
// This notify log will create a new log file after the previous one has been rotated. It's important to keep this log as notify
|
|
155
|
+
hdbLogger.notify(`hdb.log rotated, old log moved to ${fullRotateLogPath}`);
|
|
156
|
+
return fullRotateLogPath;
|
|
157
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Like harperLogger, but conditionally exports functions based on the log level. */
|
|
2
|
+
import harperLogger from './harper_logger.js';
|
|
3
|
+
|
|
4
|
+
export const logger: Logger = {};
|
|
5
|
+
|
|
6
|
+
for (let level of ['trace', 'debug', 'info', 'warn', 'error', 'fatal', 'notify']) {
|
|
7
|
+
if (harperLogger.logsAtLevel(level)) {
|
|
8
|
+
logger[level] = harperLogger[level];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function loggerWithTag(tag: string): Logger {
|
|
13
|
+
return harperLogger.loggerWithTag(tag, true) as Logger;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Logger {
|
|
17
|
+
notify?: (...args: any[]) => void;
|
|
18
|
+
fatal?: (...args: any[]) => void;
|
|
19
|
+
error?: (...args: any[]) => void;
|
|
20
|
+
warn?: (...args: any[]) => void;
|
|
21
|
+
info?: (...args: any[]) => void;
|
|
22
|
+
debug?: (...args: any[]) => void;
|
|
23
|
+
trace?: (...args: any[]) => void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const hdbTerms = require('../hdbTerms.ts');
|
|
4
|
+
const hdbLogger = require('./harper_logger.js');
|
|
5
|
+
const envMangr = require('../environment/environmentManager.js');
|
|
6
|
+
const validator = require('../../validation/readLogValidator.js');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const fs = require('fs-extra');
|
|
9
|
+
const { once } = require('events');
|
|
10
|
+
const { handleHDBError, hdbErrors } = require('../errors/hdbError.js');
|
|
11
|
+
const { PACKAGE_ROOT } = require('../../utility/packageUtils.js');
|
|
12
|
+
const { server } = require('../../server/Server.ts');
|
|
13
|
+
|
|
14
|
+
// Install log is created in harperdb/logs because the hdb folder doesn't exist initially during the install process.
|
|
15
|
+
const INSTALL_LOG_LOCATION = path.join(PACKAGE_ROOT, `logs`);
|
|
16
|
+
const DEFAULT_READ_LOG_LIMIT = 1000;
|
|
17
|
+
const ESTIMATED_AVERAGE_ENTRY_SIZE = 200;
|
|
18
|
+
|
|
19
|
+
module.exports = readLog;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Reads a log via a read stream and filters lines if filter params are passed.
|
|
23
|
+
* Returns an object array where each object is a line from the log.
|
|
24
|
+
* @param request
|
|
25
|
+
* @returns {Promise<*[]>}
|
|
26
|
+
*/
|
|
27
|
+
async function readLog(request) {
|
|
28
|
+
const validation = validator(request);
|
|
29
|
+
if (validation) {
|
|
30
|
+
throw handleHDBError(
|
|
31
|
+
validation,
|
|
32
|
+
validation.message,
|
|
33
|
+
hdbErrors.HTTP_STATUS_CODES.BAD_REQUEST,
|
|
34
|
+
undefined,
|
|
35
|
+
undefined,
|
|
36
|
+
true
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
// start pulling logs from the other nodes now so it can be done in parallel
|
|
40
|
+
let whenReplicatedResponse = server.replication.replicateOperation(request);
|
|
41
|
+
|
|
42
|
+
const logPath = envMangr.get(hdbTerms.HDB_SETTINGS_NAMES.LOG_PATH_KEY);
|
|
43
|
+
const logName = request.log_name === undefined ? hdbTerms.LOG_NAMES.HDB : request.log_name;
|
|
44
|
+
const readLogPath =
|
|
45
|
+
logName === hdbTerms.LOG_NAMES.INSTALL
|
|
46
|
+
? path.join(INSTALL_LOG_LOCATION, hdbTerms.LOG_NAMES.INSTALL)
|
|
47
|
+
: path.join(logPath, logName);
|
|
48
|
+
|
|
49
|
+
// support 'until' attribute for backwards compatibility
|
|
50
|
+
if (request.to === undefined && request.until !== undefined) {
|
|
51
|
+
request.to = request.until;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const levelDefined = request.level !== undefined;
|
|
55
|
+
const level = levelDefined ? request.level : undefined;
|
|
56
|
+
const fromDefined = request.from !== undefined;
|
|
57
|
+
const from = fromDefined ? new Date(request.from) : undefined;
|
|
58
|
+
const toDefined = request.to !== undefined;
|
|
59
|
+
const to = toDefined ? new Date(request.to) : undefined;
|
|
60
|
+
const limit = request.limit === undefined ? DEFAULT_READ_LOG_LIMIT : request.limit;
|
|
61
|
+
const order = request.order === undefined ? undefined : request.order;
|
|
62
|
+
const start = request.start === undefined ? 0 : request.start;
|
|
63
|
+
const max = start + limit;
|
|
64
|
+
const filter = request.filter;
|
|
65
|
+
let fileStart = 0;
|
|
66
|
+
if (order === 'desc' && !from && !to) {
|
|
67
|
+
fileStart = Math.max(fs.statSync(readLogPath).size - (max + 5) * ESTIMATED_AVERAGE_ENTRY_SIZE, 0);
|
|
68
|
+
}
|
|
69
|
+
const readLogInputStream = fs.createReadStream(readLogPath, { start: fileStart });
|
|
70
|
+
readLogInputStream.on('error', (err) => {
|
|
71
|
+
hdbLogger.error(err);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
let count = 0;
|
|
75
|
+
let result = [];
|
|
76
|
+
let remaining = '';
|
|
77
|
+
let pendingLogEntry;
|
|
78
|
+
let processedCount = 0;
|
|
79
|
+
readLogInputStream.on('data', (logData) => {
|
|
80
|
+
let reader = /(?:^|\n)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:[\d.]+Z) \[(.+?)]: /g;
|
|
81
|
+
logData = remaining + logData;
|
|
82
|
+
let lastPosition = 0;
|
|
83
|
+
let parsed;
|
|
84
|
+
while ((parsed = reader.exec(logData))) {
|
|
85
|
+
if (readLogInputStream.destroyed) break;
|
|
86
|
+
if (pendingLogEntry) {
|
|
87
|
+
pendingLogEntry.message = logData.slice(lastPosition, parsed.index);
|
|
88
|
+
onLogMessage(pendingLogEntry);
|
|
89
|
+
}
|
|
90
|
+
let [intro, timestamp, tagsString] = parsed;
|
|
91
|
+
let tags = tagsString.split('] [');
|
|
92
|
+
let thread = tags[0];
|
|
93
|
+
let level = tags[1];
|
|
94
|
+
tags.splice(0, 2);
|
|
95
|
+
pendingLogEntry = {
|
|
96
|
+
timestamp,
|
|
97
|
+
thread,
|
|
98
|
+
level,
|
|
99
|
+
tags,
|
|
100
|
+
message: '',
|
|
101
|
+
};
|
|
102
|
+
lastPosition = parsed.index + intro.length;
|
|
103
|
+
}
|
|
104
|
+
remaining = logData.slice(lastPosition);
|
|
105
|
+
});
|
|
106
|
+
readLogInputStream.on('end', () => {
|
|
107
|
+
if (readLogInputStream.destroyed) return;
|
|
108
|
+
if (pendingLogEntry) {
|
|
109
|
+
pendingLogEntry.message = remaining.trim();
|
|
110
|
+
onLogMessage(pendingLogEntry);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
readLogInputStream.resume();
|
|
114
|
+
function onLogMessage(line) {
|
|
115
|
+
if (filter !== undefined) {
|
|
116
|
+
let found = false;
|
|
117
|
+
if (
|
|
118
|
+
['timestamp', 'thread', 'level', 'tags', 'message'].some((attr) => {
|
|
119
|
+
if (Array.isArray(line[attr])) {
|
|
120
|
+
return line[attr].some((val) => val.includes(filter));
|
|
121
|
+
}
|
|
122
|
+
return line[attr].includes(filter);
|
|
123
|
+
})
|
|
124
|
+
) {
|
|
125
|
+
found = true;
|
|
126
|
+
}
|
|
127
|
+
if (!found) return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Yield to event loop every 10 lines to heavily deprioritize this filtering relative to other operations
|
|
131
|
+
processedCount++;
|
|
132
|
+
if (processedCount % 10 === 0) {
|
|
133
|
+
readLogInputStream.pause();
|
|
134
|
+
setImmediate(() => readLogInputStream.resume());
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let logDate;
|
|
138
|
+
let fromDate;
|
|
139
|
+
let toDate;
|
|
140
|
+
switch (true) {
|
|
141
|
+
case levelDefined && fromDefined && toDefined:
|
|
142
|
+
logDate = new Date(line.timestamp);
|
|
143
|
+
fromDate = new Date(from);
|
|
144
|
+
toDate = new Date(to);
|
|
145
|
+
|
|
146
|
+
// If the line matches the log level and timestamp falls between the from & to dates but the result count is less that the start,
|
|
147
|
+
// increment count and go to next line.
|
|
148
|
+
if (line.level === level && logDate >= fromDate && logDate <= toDate && count < start) count++;
|
|
149
|
+
// Else if all the criteria match and the count is equal/above the start, push line to result array.
|
|
150
|
+
else if (line.level === level && logDate >= fromDate && logDate <= toDate) {
|
|
151
|
+
pushLineToResult(line, order, result);
|
|
152
|
+
count++;
|
|
153
|
+
// If the count of matching lines is the max number of results, end the readline.
|
|
154
|
+
if (count === max) readLogInputStream.destroy();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// If all the criteria do not match, ignore the line and go to the next.
|
|
158
|
+
break;
|
|
159
|
+
case levelDefined && fromDefined:
|
|
160
|
+
logDate = new Date(line.timestamp);
|
|
161
|
+
fromDate = new Date(from);
|
|
162
|
+
|
|
163
|
+
// If the line matches the log level and timestamp is equal/above the fromDate but the result count is less that the start,
|
|
164
|
+
// increment count and go to next line.
|
|
165
|
+
if (line.level === level && logDate >= fromDate && count < start) count++;
|
|
166
|
+
// Else if the level and from date criteria match and the count is equal/above the start, push line to result array.
|
|
167
|
+
else if (line.level === level && logDate >= fromDate) {
|
|
168
|
+
pushLineToResult(line, order, result);
|
|
169
|
+
count++;
|
|
170
|
+
// If the count of matching lines is the max number of results, end the readline.
|
|
171
|
+
if (count === max) readLogInputStream.destroy();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// If criteria do not match, ignore the line and go to the next.
|
|
175
|
+
break;
|
|
176
|
+
case levelDefined && toDefined:
|
|
177
|
+
logDate = new Date(line.timestamp);
|
|
178
|
+
toDate = new Date(to);
|
|
179
|
+
|
|
180
|
+
// If the line matches the log level and timestamp is equal/below the toDate but the result count is less that the start,
|
|
181
|
+
// increment count and go to next line.
|
|
182
|
+
if (line.level === level && logDate <= toDate && count < start) count++;
|
|
183
|
+
// Else if the level and to date criteria match and the count is equal/above the start, push line to result array.
|
|
184
|
+
else if (line.level === level && logDate <= toDate) {
|
|
185
|
+
pushLineToResult(line, order, result);
|
|
186
|
+
count++;
|
|
187
|
+
// If the count of matching lines is the max number of results, end the readline.
|
|
188
|
+
if (count === max) readLogInputStream.destroy();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// If criteria do not match, ignore the line and go to the next.
|
|
192
|
+
break;
|
|
193
|
+
case fromDefined && toDefined:
|
|
194
|
+
logDate = new Date(line.timestamp);
|
|
195
|
+
fromDate = new Date(from);
|
|
196
|
+
toDate = new Date(to);
|
|
197
|
+
|
|
198
|
+
// If timestamp falls between the from & to dates but the result count is less that the start,
|
|
199
|
+
// increment count and go to next line.
|
|
200
|
+
if (logDate >= fromDate && logDate <= toDate && count < start) count++;
|
|
201
|
+
// Else if all the criteria match and the count is equal/above the start, push line to result array.
|
|
202
|
+
else if (logDate >= fromDate && logDate <= toDate) {
|
|
203
|
+
pushLineToResult(line, order, result);
|
|
204
|
+
count++;
|
|
205
|
+
// If the count of matching lines is the max number of results, end the readline.
|
|
206
|
+
if (count === max) readLogInputStream.destroy();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// If all the criteria do not match, ignore the line and go to the next.
|
|
210
|
+
break;
|
|
211
|
+
case levelDefined:
|
|
212
|
+
// If line level matches but count is below start, just increment count
|
|
213
|
+
if (line.level === level && count < start) count++;
|
|
214
|
+
// If level matches and count is equal/above start, add line to result in increment count.
|
|
215
|
+
else if (line.level === level) {
|
|
216
|
+
pushLineToResult(line, order, result);
|
|
217
|
+
count++;
|
|
218
|
+
// If the count of matching lines is the max number of results, end the readline.
|
|
219
|
+
if (count === max) readLogInputStream.destroy();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// If level criteria do not match, ignore the line and go to the next.
|
|
223
|
+
break;
|
|
224
|
+
case fromDefined:
|
|
225
|
+
logDate = new Date(line.timestamp);
|
|
226
|
+
fromDate = new Date(from);
|
|
227
|
+
|
|
228
|
+
// If timestamp is equal/above the fromDate but the result count is less that the start,
|
|
229
|
+
// increment count and go to next line.
|
|
230
|
+
if (logDate >= fromDate && count < start) count++;
|
|
231
|
+
// Else if from date criteria match and the count is equal/above the start, push line to result array.
|
|
232
|
+
else if (logDate >= fromDate && count >= start) {
|
|
233
|
+
pushLineToResult(line, order, result);
|
|
234
|
+
count++;
|
|
235
|
+
// If the count of matching lines is the max number of results, end the readline.
|
|
236
|
+
if (count === max) readLogInputStream.destroy();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// If criteria do not match, ignore the line and go to the next.
|
|
240
|
+
break;
|
|
241
|
+
case toDefined:
|
|
242
|
+
logDate = new Date(line.timestamp);
|
|
243
|
+
toDate = new Date(to);
|
|
244
|
+
|
|
245
|
+
// If timestamp is equal/below the toDate but the result count is less that the start,
|
|
246
|
+
// increment count and go to next line.
|
|
247
|
+
if (logDate <= toDate && count < start) count++;
|
|
248
|
+
// Else if to date criteria match and the count is equal/above the start, push line to result array.
|
|
249
|
+
else if (logDate <= toDate && count >= start) {
|
|
250
|
+
pushLineToResult(line, order, result);
|
|
251
|
+
count++;
|
|
252
|
+
// If the count of matching lines is the max number of results, end the readline.
|
|
253
|
+
if (count === max) readLogInputStream.destroy();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// If criteria do not match, ignore the line and go to the next.
|
|
257
|
+
break;
|
|
258
|
+
default:
|
|
259
|
+
// If count is under the start, increment count and go to next line
|
|
260
|
+
if (count < start) count++;
|
|
261
|
+
// Else push line to result and increment count
|
|
262
|
+
else {
|
|
263
|
+
pushLineToResult(line, order, result);
|
|
264
|
+
count++;
|
|
265
|
+
// If the count of matching lines is the max number of results, end the readline.
|
|
266
|
+
if (count === max) readLogInputStream.destroy();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
await once(readLogInputStream, 'close');
|
|
272
|
+
let replicatedResponse = await whenReplicatedResponse;
|
|
273
|
+
if (replicatedResponse.replicated) {
|
|
274
|
+
// if this was a replicated request, add our node name to each of our own lines
|
|
275
|
+
for (let line of result) {
|
|
276
|
+
line.node = server.hostname;
|
|
277
|
+
}
|
|
278
|
+
// and then add the lines from the other nodes
|
|
279
|
+
for (let nodeResult of replicatedResponse.replicated) {
|
|
280
|
+
let node = nodeResult.node;
|
|
281
|
+
if (nodeResult.status === 'failed') {
|
|
282
|
+
// if the node failed to replicate, add an error line
|
|
283
|
+
pushLineToResult(
|
|
284
|
+
{
|
|
285
|
+
timestamp: new Date().toISOString(),
|
|
286
|
+
level: 'error',
|
|
287
|
+
node,
|
|
288
|
+
message: `Error retrieving logs: ${nodeResult.reason}`,
|
|
289
|
+
},
|
|
290
|
+
order,
|
|
291
|
+
result
|
|
292
|
+
);
|
|
293
|
+
} else {
|
|
294
|
+
for (let line of nodeResult.results) {
|
|
295
|
+
line.node = node;
|
|
296
|
+
pushLineToResult(line, order, result);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Pushes a line from the readline stream to the result array.
|
|
306
|
+
* If an order was passed in request, insert the line in the correct order.
|
|
307
|
+
* @param line
|
|
308
|
+
* @param order
|
|
309
|
+
* @param result
|
|
310
|
+
*/
|
|
311
|
+
function pushLineToResult(line, order, result) {
|
|
312
|
+
if (order === 'desc') {
|
|
313
|
+
insertDescending(line, result);
|
|
314
|
+
} else if (order === 'asc') {
|
|
315
|
+
insertAscending(line, result);
|
|
316
|
+
} else {
|
|
317
|
+
result.push(line);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Insert a line from log into result array in descending order by date.
|
|
323
|
+
* @param value
|
|
324
|
+
* @param result
|
|
325
|
+
*/
|
|
326
|
+
function insertDescending(value, result) {
|
|
327
|
+
const dateVal = new Date(value.timestamp);
|
|
328
|
+
let low = 0;
|
|
329
|
+
let high = result.length;
|
|
330
|
+
while (low < high) {
|
|
331
|
+
let mid = (low + high) >>> 1;
|
|
332
|
+
if (new Date(result[mid].timestamp) > dateVal) low = mid + 1;
|
|
333
|
+
else high = mid;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
result.splice(low, 0, value);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Insert a line from log into result array in descending order by date.
|
|
341
|
+
* @param value
|
|
342
|
+
* @param result
|
|
343
|
+
*/
|
|
344
|
+
function insertAscending(value, result) {
|
|
345
|
+
const dateVal = new Date(value.timestamp);
|
|
346
|
+
let low = 0;
|
|
347
|
+
let high = result.length;
|
|
348
|
+
while (low < high) {
|
|
349
|
+
let mid = (low + high) >>> 1;
|
|
350
|
+
if (new Date(result[mid].timestamp) < dateVal) low = mid + 1;
|
|
351
|
+
else high = mid;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
result.splice(low, 0, value);
|
|
355
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const hdbUtils = require('../common_utils.js');
|
|
4
|
+
const log = require('./harper_logger.js');
|
|
5
|
+
const { handleHDBError, hdbErrors } = require('../errors/hdbError.js');
|
|
6
|
+
const { HTTP_STATUS_CODES } = hdbErrors;
|
|
7
|
+
const {
|
|
8
|
+
readTransactionLogValidator,
|
|
9
|
+
deleteTransactionLogsBeforeValidator,
|
|
10
|
+
} = require('../../validation/transactionLogValidator.js');
|
|
11
|
+
const harperBridge = require('../../dataLayer/harperBridge/harperBridge.js');
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
readTransactionLog,
|
|
15
|
+
deleteTransactionLogsBefore,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
async function readTransactionLog(req) {
|
|
19
|
+
const validation = readTransactionLogValidator(req);
|
|
20
|
+
if (validation) {
|
|
21
|
+
throw handleHDBError(validation, validation.message, HTTP_STATUS_CODES.BAD_REQUEST, undefined, undefined, true);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
req.database = req.database ?? req.schema ?? 'data';
|
|
25
|
+
const invalidSchemaTableMsg = hdbUtils.checkSchemaTableExist(req.database, req.table);
|
|
26
|
+
if (invalidSchemaTableMsg) {
|
|
27
|
+
throw handleHDBError(new Error(), invalidSchemaTableMsg, HTTP_STATUS_CODES.NOT_FOUND, undefined, undefined, true);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
log.info('Reading Harper logs used by Plexus');
|
|
31
|
+
|
|
32
|
+
if (req.from || req.to) {
|
|
33
|
+
req.search_type = 'timestamp';
|
|
34
|
+
req.search_values = [req.from ?? 0];
|
|
35
|
+
if (req.to) req.search_values[1] = req.to;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return harperBridge.readAuditLog(req);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Deletes messages from a tables local stream (persistence layer),
|
|
43
|
+
* where all transactions against that table are stored.
|
|
44
|
+
* @param req - {schema, table, timestamp}
|
|
45
|
+
* @returns {Promise<string>}
|
|
46
|
+
*/
|
|
47
|
+
async function deleteTransactionLogsBefore(req) {
|
|
48
|
+
const validation = deleteTransactionLogsBeforeValidator(req);
|
|
49
|
+
if (validation) {
|
|
50
|
+
throw handleHDBError(validation, validation.message, HTTP_STATUS_CODES.BAD_REQUEST, undefined, undefined, true);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
req.database = req.database ?? req.schema ?? 'data';
|
|
54
|
+
|
|
55
|
+
log.info('Delete transaction logs called for Plexus');
|
|
56
|
+
return harperBridge.deleteAuditLogsBefore(req);
|
|
57
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { mkdirpSync, copySync } = require('fs-extra');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const terms = require('../utility/hdbTerms.ts');
|
|
6
|
+
const hdbLogger = require('../utility/logging/harper_logger.js');
|
|
7
|
+
const bridge = require('../dataLayer/harperBridge/harperBridge.js');
|
|
8
|
+
const systemSchema = require('../json/systemSchema.json');
|
|
9
|
+
const initPaths = require('../dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js');
|
|
10
|
+
const { PACKAGE_ROOT } = require('../utility/packageUtils');
|
|
11
|
+
|
|
12
|
+
module.exports = mountHdb;
|
|
13
|
+
|
|
14
|
+
async function mountHdb(hdbPath) {
|
|
15
|
+
hdbLogger.trace('Mounting Harper');
|
|
16
|
+
|
|
17
|
+
makeDirectory(hdbPath);
|
|
18
|
+
makeDirectory(path.join(hdbPath, 'backup'));
|
|
19
|
+
makeDirectory(path.join(hdbPath, 'keys'));
|
|
20
|
+
makeDirectory(path.join(hdbPath, 'log'));
|
|
21
|
+
makeDirectory(path.join(hdbPath, 'database'));
|
|
22
|
+
makeDirectory(path.join(hdbPath, 'components'));
|
|
23
|
+
copySync(path.join(PACKAGE_ROOT, 'static/README.md'), path.join(hdbPath, 'README.md'));
|
|
24
|
+
|
|
25
|
+
await createTables();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* creates the environments & dbis needed for lmdb based on the systemSchema
|
|
30
|
+
* @returns {Promise<void>}
|
|
31
|
+
*/
|
|
32
|
+
async function createTables() {
|
|
33
|
+
const CreateTableObject = require('../dataLayer/CreateTableObject.js');
|
|
34
|
+
|
|
35
|
+
let tables = Object.keys(systemSchema);
|
|
36
|
+
|
|
37
|
+
for (const tableName of tables) {
|
|
38
|
+
let hash_attribute = systemSchema[tableName].hash_attribute;
|
|
39
|
+
try {
|
|
40
|
+
initPaths.initSystemSchemaPaths(terms.SYSTEM_SCHEMA_NAME, tableName);
|
|
41
|
+
let createTable = new CreateTableObject(terms.SYSTEM_SCHEMA_NAME, tableName, hash_attribute);
|
|
42
|
+
createTable.attributes = systemSchema[tableName].attributes;
|
|
43
|
+
let primaryKeyAttribute = createTable.attributes.find(({ attribute }) => attribute === hash_attribute);
|
|
44
|
+
primaryKeyAttribute.isPrimaryKey = true;
|
|
45
|
+
|
|
46
|
+
// with RocksDB at least, we need to audit everything or there will be lost data
|
|
47
|
+
createTable.audit = true;
|
|
48
|
+
await bridge.createTable(tableName, createTable);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
hdbLogger.error(`issue creating environment for ${terms.SYSTEM_SCHEMA_NAME}.${tableName}: ${e}`);
|
|
51
|
+
throw e;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function makeDirectory(targetDir) {
|
|
57
|
+
mkdirpSync(targetDir, { mode: terms.HDB_FILE_PERMISSIONS });
|
|
58
|
+
hdbLogger.info(`Directory ${targetDir} created`);
|
|
59
|
+
}
|