@xyo-network/sdk-js 3.12.3 → 3.12.5
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/README.md +8 -4
- package/eslint.config.mjs +1 -1
- package/knip.config.ts +29 -8
- package/package.json +17 -14
- package/packages/modules-mongo/dist/browser/index.mjs +195 -0
- package/packages/modules-mongo/dist/browser/index.mjs.map +1 -0
- package/packages/modules-mongo/dist/neutral/index.mjs +195 -0
- package/packages/modules-mongo/dist/neutral/index.mjs.map +1 -0
- package/packages/modules-mongo/dist/node/index.mjs +195 -0
- package/packages/modules-mongo/dist/node/index.mjs.map +1 -0
- package/packages/modules-mongo/dist/types/Archivist/addArchivistModuleFactories.d.ts +3 -0
- package/packages/modules-mongo/dist/types/Archivist/addArchivistModuleFactories.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Archivist/index.d.ts +2 -0
- package/packages/modules-mongo/dist/types/Archivist/index.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Diviner/addDivinerModuleFactories.d.ts +3 -0
- package/packages/modules-mongo/dist/types/Diviner/addDivinerModuleFactories.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Diviner/index.d.ts +2 -0
- package/packages/modules-mongo/dist/types/Diviner/index.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Job/getJobs.d.ts +4 -0
- package/packages/modules-mongo/dist/types/Job/getJobs.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Job/index.d.ts +2 -0
- package/packages/modules-mongo/dist/types/Job/index.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/JobQueue/JobQueueContainerModule.d.ts +3 -0
- package/packages/modules-mongo/dist/types/JobQueue/JobQueueContainerModule.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/JobQueue/getJobQueue.d.ts +3 -0
- package/packages/modules-mongo/dist/types/JobQueue/getJobQueue.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/JobQueue/getName.d.ts +2 -0
- package/packages/modules-mongo/dist/types/JobQueue/getName.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/JobQueue/index.d.ts +2 -0
- package/packages/modules-mongo/dist/types/JobQueue/index.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Mongo/AddressInfo.d.ts +6 -0
- package/packages/modules-mongo/dist/types/Mongo/AddressInfo.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/IndexCreationInfo.d.ts +3 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/IndexCreationInfo.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/Specifications/AddressInfo/UX_address.d.ts +3 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/Specifications/AddressInfo/UX_address.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/Specifications/AddressInfo/index.d.ts +3 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/Specifications/AddressInfo/index.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/Specifications/index.d.ts +2 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/Specifications/index.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/addIndexes.d.ts +2 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/addIndexes.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/index.d.ts +2 -0
- package/packages/modules-mongo/dist/types/Mongo/Indexes/index.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Mongo/index.d.ts +3 -0
- package/packages/modules-mongo/dist/types/Mongo/index.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/Mongo/initializeDatabase.d.ts +2 -0
- package/packages/modules-mongo/dist/types/Mongo/initializeDatabase.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/PreviousHashStore/MongoDBPreviousHashStore.d.ts +12 -0
- package/packages/modules-mongo/dist/types/PreviousHashStore/MongoDBPreviousHashStore.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/PreviousHashStore/addPreviousHashStore.d.ts +2 -0
- package/packages/modules-mongo/dist/types/PreviousHashStore/addPreviousHashStore.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/PreviousHashStore/index.d.ts +2 -0
- package/packages/modules-mongo/dist/types/PreviousHashStore/index.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/addMongoModules.d.ts +3 -0
- package/packages/modules-mongo/dist/types/addMongoModules.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/canAddMongoModules.d.ts +2 -0
- package/packages/modules-mongo/dist/types/canAddMongoModules.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/index.d.ts +4 -0
- package/packages/modules-mongo/dist/types/index.d.ts.map +1 -0
- package/packages/modules-mongo/dist/types/mongoTypes.d.ts +5 -0
- package/packages/modules-mongo/dist/types/mongoTypes.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/dist/browser/index.mjs +274 -0
- package/packages/modules-mongo/packages/archivist/dist/browser/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/archivist/dist/neutral/index.mjs +274 -0
- package/packages/modules-mongo/packages/archivist/dist/neutral/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/archivist/dist/node/index.mjs +274 -0
- package/packages/modules-mongo/packages/archivist/dist/node/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/archivist/dist/types/Archivist.d.ts +69 -0
- package/packages/modules-mongo/packages/archivist/dist/types/Archivist.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/dist/types/ArchivistV2.d.ts +65 -0
- package/packages/modules-mongo/packages/archivist/dist/types/ArchivistV2.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/dist/types/index.d.ts +4 -0
- package/packages/modules-mongo/packages/archivist/dist/types/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/dist/types/lib/index.d.ts +2 -0
- package/packages/modules-mongo/packages/archivist/dist/types/lib/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/dist/types/lib/validByType.d.ts +4 -0
- package/packages/modules-mongo/packages/archivist/dist/types/lib/validByType.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/browser/index.mjs +6 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/browser/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/neutral/index.mjs +6 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/neutral/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/node/index.mjs +6 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/node/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/Config.d.ts +9 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/Config.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/ConfigV2.d.ts +8 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/ConfigV2.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/Labels.d.ts +5 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/Labels.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/Params.d.ts +9 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/Params.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/Schema.d.ts +3 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/Schema.d.ts.map +1 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/index.d.ts +5 -0
- package/packages/modules-mongo/packages/archivist/packages/model/dist/types/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/browser/index.mjs +1100 -0
- package/packages/modules-mongo/packages/diviner/dist/browser/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/neutral/index.mjs +1100 -0
- package/packages/modules-mongo/packages/diviner/dist/neutral/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/node/index.mjs +1100 -0
- package/packages/modules-mongo/packages/diviner/dist/node/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/JobQueue/defineJobs.d.ts +3 -0
- package/packages/modules-mongo/packages/diviner/dist/types/JobQueue/defineJobs.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/JobQueue/getName.d.ts +2 -0
- package/packages/modules-mongo/packages/diviner/dist/types/JobQueue/getName.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/JobQueue/index.d.ts +3 -0
- package/packages/modules-mongo/packages/diviner/dist/types/JobQueue/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/JobQueue/scheduleJobs.d.ts +3 -0
- package/packages/modules-mongo/packages/diviner/dist/types/JobQueue/scheduleJobs.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBAddressHistoryDiviner.d.ts +61 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBAddressHistoryDiviner.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBAddressSpaceBatchDiviner.d.ts +67 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBAddressSpaceBatchDiviner.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBAddressSpaceDiviner.d.ts +57 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBAddressSpaceDiviner.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBBoundWitnessDiviner.d.ts +59 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBBoundWitnessDiviner.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBBoundWitnessStatsDiviner.d.ts +91 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBBoundWitnessStatsDiviner.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBPayloadDiviner.d.ts +57 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBPayloadDiviner.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBPayloadStatsDiviner.d.ts +104 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBPayloadStatsDiviner.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBSchemaListDiviner.d.ts +61 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBSchemaListDiviner.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBSchemaStatsDiviner.d.ts +113 -0
- package/packages/modules-mongo/packages/diviner/dist/types/MongoDBSchemaStatsDiviner.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/SetIterator/BatchSetIterator.d.ts +10 -0
- package/packages/modules-mongo/packages/diviner/dist/types/SetIterator/BatchSetIterator.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/SetIterator/SetIterator.d.ts +9 -0
- package/packages/modules-mongo/packages/diviner/dist/types/SetIterator/SetIterator.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/SetIterator/index.d.ts +3 -0
- package/packages/modules-mongo/packages/diviner/dist/types/SetIterator/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/UserLocationsDiviner.d.ts +41 -0
- package/packages/modules-mongo/packages/diviner/dist/types/UserLocationsDiviner.d.ts.map +1 -0
- package/packages/modules-mongo/packages/diviner/dist/types/index.d.ts +12 -0
- package/packages/modules-mongo/packages/diviner/dist/types/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/dist/browser/index.mjs +4 -0
- package/packages/modules-mongo/packages/module/dist/browser/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/module/dist/neutral/index.mjs +4 -0
- package/packages/modules-mongo/packages/module/dist/neutral/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/module/dist/node/index.mjs +4 -0
- package/packages/modules-mongo/packages/module/dist/node/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/module/dist/types/index.d.ts +3 -0
- package/packages/modules-mongo/packages/module/dist/types/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/browser/index.mjs +277 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/browser/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/neutral/index.mjs +277 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/neutral/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/node/index.mjs +277 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/node/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/AnyAbstractModule.d.ts +4 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/AnyAbstractModule.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Collections.d.ts +9 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Collections.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Databases.d.ts +4 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Databases.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Defaults.d.ts +5 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Defaults.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/IndexDescription.d.ts +24 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/IndexDescription.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Indexes/CollectionIndexFunction.d.ts +3 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Indexes/CollectionIndexFunction.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Indexes/index.d.ts +2 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Indexes/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Module.d.ts +42 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/Module.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/ModuleV2.d.ts +39 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/ModuleV2.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/config/getBaseMongoSdk.d.ts +6 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/config/getBaseMongoSdk.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/config/getMongoDBConfig.d.ts +5 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/config/getMongoDBConfig.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/config/hasMongoDBConfig.d.ts +2 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/config/hasMongoDBConfig.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/config/index.d.ts +4 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/config/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/index.d.ts +10 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/util/dbProperty.d.ts +4 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/util/dbProperty.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/util/index.d.ts +2 -0
- package/packages/modules-mongo/packages/module/packages/abstract/dist/types/util/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/browser/index.mjs +10 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/browser/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/neutral/index.mjs +10 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/neutral/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/node/index.mjs +10 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/node/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/Config.d.ts +9 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/Config.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/ConfigV2.d.ts +8 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/ConfigV2.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/Labels.d.ts +6 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/Labels.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/Module.d.ts +9 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/Module.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/ModuleV2.d.ts +7 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/ModuleV2.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/MongoDBModuleStatic.d.ts +5 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/MongoDBModuleStatic.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/Params.d.ts +10 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/Params.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/ParamsV2.d.ts +9 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/ParamsV2.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/Schema.d.ts +3 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/Schema.d.ts.map +1 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/index.d.ts +10 -0
- package/packages/modules-mongo/packages/module/packages/model/dist/types/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/browser/index.mjs +51 -0
- package/packages/modules-mongo/packages/payload/dist/browser/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/neutral/index.mjs +51 -0
- package/packages/modules-mongo/packages/payload/dist/neutral/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/node/index.mjs +51 -0
- package/packages/modules-mongo/packages/payload/dist/node/index.mjs.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/types/BoundWitness/BoundWitnessMongoMeta.d.ts +7 -0
- package/packages/modules-mongo/packages/payload/dist/types/BoundWitness/BoundWitnessMongoMeta.d.ts.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/types/BoundWitness/BoundWitnessWithMongoMeta.d.ts +6 -0
- package/packages/modules-mongo/packages/payload/dist/types/BoundWitness/BoundWitnessWithMongoMeta.d.ts.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/types/BoundWitness/index.d.ts +3 -0
- package/packages/modules-mongo/packages/payload/dist/types/BoundWitness/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/types/Mappings/fromDbRepresentation.d.ts +8 -0
- package/packages/modules-mongo/packages/payload/dist/types/Mappings/fromDbRepresentation.d.ts.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/types/Mappings/index.d.ts +3 -0
- package/packages/modules-mongo/packages/payload/dist/types/Mappings/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/types/Mappings/toDbRepresentation.d.ts +8 -0
- package/packages/modules-mongo/packages/payload/dist/types/Mappings/toDbRepresentation.d.ts.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/types/Payload/PayloadMongoMeta.d.ts +11 -0
- package/packages/modules-mongo/packages/payload/dist/types/Payload/PayloadMongoMeta.d.ts.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/types/Payload/PayloadWithMongoMeta.d.ts +5 -0
- package/packages/modules-mongo/packages/payload/dist/types/Payload/PayloadWithMongoMeta.d.ts.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/types/Payload/index.d.ts +3 -0
- package/packages/modules-mongo/packages/payload/dist/types/Payload/index.d.ts.map +1 -0
- package/packages/modules-mongo/packages/payload/dist/types/index.d.ts +4 -0
- package/packages/modules-mongo/packages/payload/dist/types/index.d.ts.map +1 -0
- package/typedoc.json +0 -14
|
@@ -0,0 +1,1100 @@
|
|
|
1
|
+
// src/MongoDBAddressHistoryDiviner.ts
|
|
2
|
+
import { assertEx } from "@xylabs/assert";
|
|
3
|
+
import { exists } from "@xylabs/exists";
|
|
4
|
+
import { hexFromHexString } from "@xylabs/hex";
|
|
5
|
+
import {
|
|
6
|
+
AddressHistoryDiviner,
|
|
7
|
+
AddressHistoryDivinerConfigSchema,
|
|
8
|
+
isAddressHistoryQueryPayload
|
|
9
|
+
} from "@xyo-network/diviner-address-history";
|
|
10
|
+
import {
|
|
11
|
+
DefaultLimit,
|
|
12
|
+
DefaultMaxTimeMS,
|
|
13
|
+
MongoDBModuleMixin
|
|
14
|
+
} from "@xyo-network/module-abstract-mongodb";
|
|
15
|
+
import { fromDbRepresentation } from "@xyo-network/payload-mongodb";
|
|
16
|
+
var MongoDBDivinerBase = MongoDBModuleMixin(AddressHistoryDiviner);
|
|
17
|
+
var MongoDBAddressHistoryDiviner = class extends MongoDBDivinerBase {
|
|
18
|
+
static configSchemas = [...super.configSchemas, AddressHistoryDivinerConfigSchema];
|
|
19
|
+
static defaultConfigSchema = AddressHistoryDivinerConfigSchema;
|
|
20
|
+
async divineHandler(payloads) {
|
|
21
|
+
const query = payloads?.find(isAddressHistoryQueryPayload);
|
|
22
|
+
if (!query) return [];
|
|
23
|
+
const { address, limit } = query;
|
|
24
|
+
const addresses = sanitizeAddress(address);
|
|
25
|
+
assertEx(addresses, () => "MongoDBAddressHistoryDiviner: Missing address for query");
|
|
26
|
+
const blocks = await this.getBlocks(addresses, limit || DefaultLimit);
|
|
27
|
+
return blocks.map(fromDbRepresentation);
|
|
28
|
+
}
|
|
29
|
+
async startHandler() {
|
|
30
|
+
await super.startHandler();
|
|
31
|
+
await this.ensureIndexes();
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
getBlocks = async (address, limit) => {
|
|
35
|
+
let nextHash = void 0;
|
|
36
|
+
const blocks = [];
|
|
37
|
+
const defaultFilter = { addresses: address };
|
|
38
|
+
const sort = { _sequence: -1 };
|
|
39
|
+
for (let i = 0; i < limit; i++) {
|
|
40
|
+
let block = void 0;
|
|
41
|
+
const byDataHash = { ...defaultFilter };
|
|
42
|
+
if (nextHash) byDataHash._hash = nextHash;
|
|
43
|
+
const foundByDataHash = (await (await this.boundWitnesses.find(byDataHash)).sort(sort).limit(1).maxTimeMS(DefaultMaxTimeMS).toArray()).pop();
|
|
44
|
+
if (foundByDataHash) {
|
|
45
|
+
block = foundByDataHash;
|
|
46
|
+
} else {
|
|
47
|
+
const byRootHash = { ...defaultFilter };
|
|
48
|
+
if (nextHash) byRootHash._dataHash = nextHash;
|
|
49
|
+
const foundByRootHash = (await (await this.boundWitnesses.find(byRootHash)).sort(sort).limit(1).maxTimeMS(DefaultMaxTimeMS).toArray()).pop();
|
|
50
|
+
if (foundByRootHash) {
|
|
51
|
+
block = foundByRootHash;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!block) break;
|
|
55
|
+
blocks.push(block);
|
|
56
|
+
const addressIndex = block.addresses.indexOf(address);
|
|
57
|
+
const previousHash = block.previous_hashes[addressIndex];
|
|
58
|
+
if (!previousHash) break;
|
|
59
|
+
nextHash = previousHash;
|
|
60
|
+
}
|
|
61
|
+
return blocks;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
var sanitizeAddress = (a) => {
|
|
65
|
+
return assertEx(
|
|
66
|
+
[].concat(a).filter(exists).map((x) => x.toLowerCase()).map((z) => hexFromHexString(z, { prefix: false })).findLast(exists),
|
|
67
|
+
() => "MongoDBAddressHistoryDiviner: Invalid address"
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/MongoDBAddressSpaceBatchDiviner.ts
|
|
72
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
73
|
+
import { exists as exists2 } from "@xylabs/exists";
|
|
74
|
+
import { difference, union } from "@xylabs/set";
|
|
75
|
+
import { Account } from "@xyo-network/account";
|
|
76
|
+
import { ArchivistWrapper } from "@xyo-network/archivist-wrapper";
|
|
77
|
+
import { BoundWitnessPointerSchema } from "@xyo-network/boundwitness-model";
|
|
78
|
+
import { AddressSpaceDiviner } from "@xyo-network/diviner-address-space-abstract";
|
|
79
|
+
import { AddressSpaceBatchDivinerConfigSchema } from "@xyo-network/diviner-models";
|
|
80
|
+
import {
|
|
81
|
+
COLLECTIONS,
|
|
82
|
+
DATABASES,
|
|
83
|
+
DefaultMaxTimeMS as DefaultMaxTimeMS2,
|
|
84
|
+
MongoDBModuleMixin as MongoDBModuleMixin2
|
|
85
|
+
} from "@xyo-network/module-abstract-mongodb";
|
|
86
|
+
import { AddressSchema } from "@xyo-network/module-model";
|
|
87
|
+
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
88
|
+
var moduleName = "MongoDBAddressSpaceBatchDiviner";
|
|
89
|
+
var MongoDBDivinerBase2 = MongoDBModuleMixin2(AddressSpaceDiviner);
|
|
90
|
+
var MongoDBAddressSpaceBatchDiviner = class extends MongoDBDivinerBase2 {
|
|
91
|
+
static configSchemas = [...super.configSchemas, AddressSpaceBatchDivinerConfigSchema];
|
|
92
|
+
static defaultConfigSchema = AddressSpaceBatchDivinerConfigSchema;
|
|
93
|
+
// TODO: Get via config or default
|
|
94
|
+
batchSize = 50;
|
|
95
|
+
currentlyRunning = false;
|
|
96
|
+
response;
|
|
97
|
+
witnessedAddresses = /* @__PURE__ */ new Set();
|
|
98
|
+
_paginationAccount;
|
|
99
|
+
async backgroundDivine() {
|
|
100
|
+
if (this.currentlyRunning) return;
|
|
101
|
+
try {
|
|
102
|
+
this.currentlyRunning = true;
|
|
103
|
+
if (await this.initializeArchivist()) {
|
|
104
|
+
const result = await this.boundWitnesses.useMongo((db) => {
|
|
105
|
+
return db.db(DATABASES.Archivist).command(
|
|
106
|
+
{
|
|
107
|
+
distinct: COLLECTIONS.BoundWitnesses,
|
|
108
|
+
key: "addresses"
|
|
109
|
+
},
|
|
110
|
+
{ maxTimeMS: DefaultMaxTimeMS2 }
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
const addresses = new Set(result?.values?.map((address) => address?.toLowerCase()).filter(exists2));
|
|
114
|
+
const newAddresses = difference(addresses, this.witnessedAddresses);
|
|
115
|
+
if (newAddresses.size === 0) return;
|
|
116
|
+
const toStore = [...newAddresses].map((address) => {
|
|
117
|
+
return { address, schema: AddressSchema };
|
|
118
|
+
});
|
|
119
|
+
const archivistMod = await this.archivistInstance();
|
|
120
|
+
const archivist = ArchivistWrapper.wrap(archivistMod, await this.getPaginationAccount());
|
|
121
|
+
for (let j = 0; j < toStore.length; j += this.batchSize) {
|
|
122
|
+
const batch = toStore.slice(j, j + this.batchSize);
|
|
123
|
+
await archivist.insert(batch);
|
|
124
|
+
}
|
|
125
|
+
this.witnessedAddresses = union(this.witnessedAddresses, newAddresses);
|
|
126
|
+
}
|
|
127
|
+
} catch (error) {
|
|
128
|
+
this.logger?.error(`${moduleName}.BackgroundDivine: ${error}`);
|
|
129
|
+
} finally {
|
|
130
|
+
this.currentlyRunning = false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
divineHandler(_payloads) {
|
|
134
|
+
void this.backgroundDivine();
|
|
135
|
+
return this.response ? Promise.resolve([this.response]) : Promise.resolve([]);
|
|
136
|
+
}
|
|
137
|
+
async getPaginationAccount() {
|
|
138
|
+
this._paginationAccount = this._paginationAccount ?? await Account.random();
|
|
139
|
+
return this._paginationAccount;
|
|
140
|
+
}
|
|
141
|
+
async initializeArchivist() {
|
|
142
|
+
try {
|
|
143
|
+
const archivistMod = await this.archivistInstance();
|
|
144
|
+
assertEx2(archivistMod, () => `${moduleName}.Start: No archivists found`);
|
|
145
|
+
const archivist = ArchivistWrapper.wrap(archivistMod, this.account);
|
|
146
|
+
const divinedAnswerPointer = new PayloadBuilder({ schema: BoundWitnessPointerSchema }).fields({ reference: [[{ address: (await this.getPaginationAccount()).address }], [{ schema: AddressSchema }]] }).build();
|
|
147
|
+
const divinedAnswerPointerExists = (await archivist.get([await PayloadBuilder.dataHash(divinedAnswerPointer)]))?.length > 0;
|
|
148
|
+
if (!divinedAnswerPointerExists) await archivist.insert([divinedAnswerPointer]);
|
|
149
|
+
this.response = divinedAnswerPointer;
|
|
150
|
+
return true;
|
|
151
|
+
} catch {
|
|
152
|
+
this.response = void 0;
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
async startHandler() {
|
|
157
|
+
await super.startHandler();
|
|
158
|
+
await this.ensureIndexes();
|
|
159
|
+
void this.backgroundDivine();
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/MongoDBAddressSpaceDiviner.ts
|
|
165
|
+
import { exists as exists3 } from "@xylabs/exists";
|
|
166
|
+
import { AddressSpaceDiviner as AddressSpaceDiviner2 } from "@xyo-network/diviner-address-space-abstract";
|
|
167
|
+
import { AddressSpaceDivinerConfigSchema } from "@xyo-network/diviner-models";
|
|
168
|
+
import { DefaultMaxTimeMS as DefaultMaxTimeMS3, MongoDBModuleMixin as MongoDBModuleMixin3 } from "@xyo-network/module-abstract-mongodb";
|
|
169
|
+
import { AddressSchema as AddressSchema2 } from "@xyo-network/module-model";
|
|
170
|
+
var MongoDBDivinerBase3 = MongoDBModuleMixin3(AddressSpaceDiviner2);
|
|
171
|
+
var MongoDBAddressSpaceDiviner = class extends MongoDBDivinerBase3 {
|
|
172
|
+
static configSchemas = [...super.configSchemas, AddressSpaceDivinerConfigSchema];
|
|
173
|
+
static defaultConfigSchema = AddressSpaceDivinerConfigSchema;
|
|
174
|
+
async divineHandler(_payloads) {
|
|
175
|
+
const result = await this.boundWitnesses.useCollection(async (collection) => {
|
|
176
|
+
return await collection.distinct("addresses", {}, { maxTimeMS: DefaultMaxTimeMS3 });
|
|
177
|
+
});
|
|
178
|
+
const addresses = new Set(result?.map((address) => address?.toLowerCase()).filter(exists3));
|
|
179
|
+
return [...addresses].map((address) => {
|
|
180
|
+
return { address, schema: AddressSchema2 };
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
async startHandler() {
|
|
184
|
+
await super.startHandler();
|
|
185
|
+
await this.ensureIndexes();
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/MongoDBBoundWitnessDiviner.ts
|
|
191
|
+
import { flatten } from "@xylabs/array";
|
|
192
|
+
import { exists as exists4 } from "@xylabs/exists";
|
|
193
|
+
import { hexFromHexString as hexFromHexString2 } from "@xylabs/hex";
|
|
194
|
+
import { BoundWitnessDiviner } from "@xyo-network/diviner-boundwitness-abstract";
|
|
195
|
+
import {
|
|
196
|
+
BoundWitnessDivinerConfigSchema,
|
|
197
|
+
isBoundWitnessDivinerQueryPayload
|
|
198
|
+
} from "@xyo-network/diviner-boundwitness-model";
|
|
199
|
+
import {
|
|
200
|
+
DefaultLimit as DefaultLimit2,
|
|
201
|
+
DefaultMaxTimeMS as DefaultMaxTimeMS4,
|
|
202
|
+
DefaultOrder,
|
|
203
|
+
MongoDBModuleMixin as MongoDBModuleMixin4
|
|
204
|
+
} from "@xyo-network/module-abstract-mongodb";
|
|
205
|
+
import {
|
|
206
|
+
SequenceConstants
|
|
207
|
+
} from "@xyo-network/payload-model";
|
|
208
|
+
import { fromDbRepresentation as fromDbRepresentation2 } from "@xyo-network/payload-mongodb";
|
|
209
|
+
var MongoDBDivinerBase4 = MongoDBModuleMixin4(BoundWitnessDiviner);
|
|
210
|
+
var MongoDBBoundWitnessDiviner = class extends MongoDBDivinerBase4 {
|
|
211
|
+
static configSchemas = [...super.configSchemas, BoundWitnessDivinerConfigSchema];
|
|
212
|
+
static defaultConfigSchema = BoundWitnessDivinerConfigSchema;
|
|
213
|
+
// eslint-disable-next-line complexity
|
|
214
|
+
async divineHandler(payloads) {
|
|
215
|
+
const query = payloads?.find(isBoundWitnessDivinerQueryPayload);
|
|
216
|
+
if (!query) return [];
|
|
217
|
+
const {
|
|
218
|
+
address,
|
|
219
|
+
addresses,
|
|
220
|
+
destination,
|
|
221
|
+
limit = DefaultLimit2,
|
|
222
|
+
cursor = (query.order ?? DefaultOrder) === "asc" ? SequenceConstants.minLocalSequence : SequenceConstants.maxLocalSequence,
|
|
223
|
+
order = DefaultOrder,
|
|
224
|
+
payload_hashes,
|
|
225
|
+
payload_schemas,
|
|
226
|
+
sourceQuery
|
|
227
|
+
} = query;
|
|
228
|
+
const direction = order === "asc" ? 1 : -1;
|
|
229
|
+
const sort = { _sequence: direction };
|
|
230
|
+
const filter = {};
|
|
231
|
+
if (cursor) {
|
|
232
|
+
filter._sequence = order === "desc" ? { $exists: true, $lt: cursor } : { $exists: true, $gt: cursor };
|
|
233
|
+
}
|
|
234
|
+
const allAddresses = flatten(address, addresses).map((x) => hexFromHexString2(x, { prefix: false })).filter(exists4);
|
|
235
|
+
if (allAddresses.length > 0) filter.addresses = allAddresses.length === 1 ? allAddresses[0] : { $all: allAddresses };
|
|
236
|
+
if (payload_hashes?.length) filter.payload_hashes = { $in: payload_hashes };
|
|
237
|
+
if (payload_schemas?.length) filter.payload_schemas = { $all: payload_schemas };
|
|
238
|
+
if (sourceQuery) filter["_$sourceQuery"] = sourceQuery;
|
|
239
|
+
if (destination?.length) filter["_$destination"] = { $in: destination };
|
|
240
|
+
const result = (await (await this.boundWitnesses.find(filter)).sort(sort).limit(limit).maxTimeMS(DefaultMaxTimeMS4).toArray()).map(
|
|
241
|
+
fromDbRepresentation2
|
|
242
|
+
);
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
async startHandler() {
|
|
246
|
+
await super.startHandler();
|
|
247
|
+
await this.ensureIndexes();
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// src/MongoDBBoundWitnessStatsDiviner.ts
|
|
253
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
254
|
+
import { delay } from "@xylabs/delay";
|
|
255
|
+
import { MongoClientWrapper } from "@xylabs/mongo";
|
|
256
|
+
import { fulfilled, rejected } from "@xylabs/promise";
|
|
257
|
+
import { BoundWitnessStatsDiviner } from "@xyo-network/diviner-boundwitness-stats-abstract";
|
|
258
|
+
import {
|
|
259
|
+
asDivinerInstance,
|
|
260
|
+
BoundWitnessStatsDivinerConfigSchema,
|
|
261
|
+
BoundWitnessStatsDivinerSchema,
|
|
262
|
+
isBoundWitnessStatsQueryPayload
|
|
263
|
+
} from "@xyo-network/diviner-models";
|
|
264
|
+
import {
|
|
265
|
+
COLLECTIONS as COLLECTIONS2,
|
|
266
|
+
DATABASES as DATABASES2,
|
|
267
|
+
MongoDBModuleMixin as MongoDBModuleMixin5
|
|
268
|
+
} from "@xyo-network/module-abstract-mongodb";
|
|
269
|
+
import { AddressSchema as AddressSchema3 } from "@xyo-network/module-model";
|
|
270
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
271
|
+
|
|
272
|
+
// src/JobQueue/defineJobs.ts
|
|
273
|
+
var options = { lockLifetime: 1e4 };
|
|
274
|
+
var defineJobs = (jobQueue, jobs) => {
|
|
275
|
+
for (const job of jobs) {
|
|
276
|
+
const { name, task } = job;
|
|
277
|
+
jobQueue.define(name, options, task);
|
|
278
|
+
if (job.onComplete) jobQueue.on(`complete:${name}`, job.onComplete);
|
|
279
|
+
if (job.onFail) jobQueue.on(`fail:${name}`, job.onFail);
|
|
280
|
+
if (job.onStart) jobQueue.on(`start:${name}`, job.onStart);
|
|
281
|
+
if (job.onSuccess) jobQueue.on(`success:${name}`, job.onSuccess);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// src/JobQueue/scheduleJobs.ts
|
|
286
|
+
var scheduleJobs = async (jobQueue, jobs) => {
|
|
287
|
+
await Promise.all(jobs.map(async (job) => await jobQueue.every(job.schedule, job.name)));
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// src/SetIterator/BatchSetIterator.ts
|
|
291
|
+
import {
|
|
292
|
+
difference as difference2,
|
|
293
|
+
intersection,
|
|
294
|
+
union as union2
|
|
295
|
+
} from "@xylabs/set";
|
|
296
|
+
var BatchSetIterator = class {
|
|
297
|
+
batchSize;
|
|
298
|
+
done;
|
|
299
|
+
todo;
|
|
300
|
+
constructor(values, batchSize) {
|
|
301
|
+
this.todo = new Set(values);
|
|
302
|
+
this.done = /* @__PURE__ */ new Set();
|
|
303
|
+
this.batchSize = batchSize;
|
|
304
|
+
}
|
|
305
|
+
[Symbol.iterator]() {
|
|
306
|
+
return this;
|
|
307
|
+
}
|
|
308
|
+
addValues(values) {
|
|
309
|
+
const incoming = new Set(values);
|
|
310
|
+
const knownTodo = intersection(this.todo, incoming);
|
|
311
|
+
const knownDone = intersection(this.done, incoming);
|
|
312
|
+
const known = union2(knownTodo, knownDone);
|
|
313
|
+
const unknown = difference2(incoming, known);
|
|
314
|
+
this.todo = union2(this.todo, unknown);
|
|
315
|
+
return unknown.size;
|
|
316
|
+
}
|
|
317
|
+
next() {
|
|
318
|
+
if (this.todo.size === 0) {
|
|
319
|
+
if (this.done.size === 0) {
|
|
320
|
+
return {
|
|
321
|
+
done: true,
|
|
322
|
+
value: []
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
this.todo = new Set(this.done);
|
|
326
|
+
this.done = /* @__PURE__ */ new Set();
|
|
327
|
+
}
|
|
328
|
+
const todo = [...this.todo];
|
|
329
|
+
const batch = todo.slice(0, this.batchSize);
|
|
330
|
+
const remaining = todo.slice(this.batchSize);
|
|
331
|
+
this.todo = new Set(remaining);
|
|
332
|
+
this.done = union2(this.done, new Set(batch));
|
|
333
|
+
return {
|
|
334
|
+
done: false,
|
|
335
|
+
value: batch
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// src/SetIterator/SetIterator.ts
|
|
341
|
+
import {
|
|
342
|
+
difference as difference3,
|
|
343
|
+
intersection as intersection2,
|
|
344
|
+
union as union3
|
|
345
|
+
} from "@xylabs/set";
|
|
346
|
+
var SetIterator = class {
|
|
347
|
+
done;
|
|
348
|
+
todo;
|
|
349
|
+
constructor(values) {
|
|
350
|
+
this.todo = new Set(values);
|
|
351
|
+
this.done = /* @__PURE__ */ new Set();
|
|
352
|
+
}
|
|
353
|
+
[Symbol.iterator]() {
|
|
354
|
+
return this;
|
|
355
|
+
}
|
|
356
|
+
addValues(values) {
|
|
357
|
+
const incoming = new Set(values);
|
|
358
|
+
const knownTodo = intersection2(this.todo, incoming);
|
|
359
|
+
const knownDone = intersection2(this.done, incoming);
|
|
360
|
+
const known = union3(knownTodo, knownDone);
|
|
361
|
+
const unknown = difference3(incoming, known);
|
|
362
|
+
this.todo = union3(this.todo, unknown);
|
|
363
|
+
return unknown.size;
|
|
364
|
+
}
|
|
365
|
+
next() {
|
|
366
|
+
if (this.todo.size === 0) {
|
|
367
|
+
if (this.done.size === 0) {
|
|
368
|
+
return {
|
|
369
|
+
done: true,
|
|
370
|
+
value: void 0
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
this.todo = new Set(this.done);
|
|
374
|
+
this.done = /* @__PURE__ */ new Set();
|
|
375
|
+
}
|
|
376
|
+
const value = this.todo.values().next().value;
|
|
377
|
+
if (value !== void 0) {
|
|
378
|
+
this.todo.delete(value);
|
|
379
|
+
this.done.add(value);
|
|
380
|
+
return {
|
|
381
|
+
done: false,
|
|
382
|
+
value
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
done: true,
|
|
387
|
+
value
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// src/MongoDBBoundWitnessStatsDiviner.ts
|
|
393
|
+
var updateOptions = { upsert: true };
|
|
394
|
+
var MongoDBDivinerBase5 = MongoDBModuleMixin5(BoundWitnessStatsDiviner);
|
|
395
|
+
var moduleName2 = "MongoDBBoundWitnessStatsDiviner";
|
|
396
|
+
var MongoDBBoundWitnessStatsDiviner = class extends MongoDBDivinerBase5 {
|
|
397
|
+
static configSchemas = [...super.configSchemas, BoundWitnessStatsDivinerConfigSchema];
|
|
398
|
+
static defaultConfigSchema = BoundWitnessStatsDivinerConfigSchema;
|
|
399
|
+
/**
|
|
400
|
+
* Iterates over know addresses obtained from AddressDiviner
|
|
401
|
+
*/
|
|
402
|
+
addressIterator = new SetIterator([]);
|
|
403
|
+
/**
|
|
404
|
+
* The interval at which the background divine task will run. Prevents
|
|
405
|
+
* continuously iterating over DB and exhausting DB resources
|
|
406
|
+
*/
|
|
407
|
+
backgroundDivineIntervalMs = 250;
|
|
408
|
+
/**
|
|
409
|
+
* A reference to the background task to ensure that the
|
|
410
|
+
* continuous background divine stays running
|
|
411
|
+
*/
|
|
412
|
+
backgroundDivineTask;
|
|
413
|
+
changeStream = void 0;
|
|
414
|
+
pendingCounts = {};
|
|
415
|
+
resumeAfter = void 0;
|
|
416
|
+
get jobs() {
|
|
417
|
+
return [
|
|
418
|
+
{
|
|
419
|
+
name: `${moduleName2}.UpdateChanges`,
|
|
420
|
+
onSuccess: () => {
|
|
421
|
+
this.pendingCounts = {};
|
|
422
|
+
},
|
|
423
|
+
schedule: "1 minute",
|
|
424
|
+
task: async () => await this.updateChanges()
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
name: `${moduleName2}.DivineAddressesBatch`,
|
|
428
|
+
schedule: "5 minute",
|
|
429
|
+
task: async () => await this.divineAddressesBatch()
|
|
430
|
+
}
|
|
431
|
+
];
|
|
432
|
+
}
|
|
433
|
+
async divineHandler(payloads) {
|
|
434
|
+
const query = payloads?.find(isBoundWitnessStatsQueryPayload);
|
|
435
|
+
const addresses = query?.address ? Array.isArray(query?.address) ? query.address : [query.address] : void 0;
|
|
436
|
+
const counts = addresses ? await Promise.all(addresses.map((address) => this.divineAddress(address))) : [await this.divineAllAddresses()];
|
|
437
|
+
return counts.map(
|
|
438
|
+
(count) => new PayloadBuilder2({ schema: BoundWitnessStatsDivinerSchema }).fields({ count }).build()
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
async startHandler() {
|
|
442
|
+
await super.startHandler();
|
|
443
|
+
await this.ensureIndexes();
|
|
444
|
+
await this.registerWithChangeStream();
|
|
445
|
+
defineJobs(this.jobQueue, this.jobs);
|
|
446
|
+
this.jobQueue.once("ready", async () => await scheduleJobs(this.jobQueue, this.jobs));
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
async stopHandler() {
|
|
450
|
+
await this.changeStream?.close();
|
|
451
|
+
return await super.stopHandler();
|
|
452
|
+
}
|
|
453
|
+
backgroundDivine = async () => {
|
|
454
|
+
for (const address of this.addressIterator) {
|
|
455
|
+
try {
|
|
456
|
+
await this.divineAddressFull(address);
|
|
457
|
+
} catch (error) {
|
|
458
|
+
this.logger?.error(`${moduleName2}.BackgroundDivine: ${error}`);
|
|
459
|
+
}
|
|
460
|
+
await delay(this.backgroundDivineIntervalMs);
|
|
461
|
+
}
|
|
462
|
+
this.backgroundDivineTask = void 0;
|
|
463
|
+
};
|
|
464
|
+
divineAddress = async (address) => {
|
|
465
|
+
const stats = await this.boundWitnesses.useMongo(async (mongo) => {
|
|
466
|
+
return await mongo.db(DATABASES2.Archivist).collection(COLLECTIONS2.ArchivistStats).findOne({ address });
|
|
467
|
+
});
|
|
468
|
+
const remote = stats?.bound_witnesses?.count || 0;
|
|
469
|
+
const local = this.pendingCounts[address] || 0;
|
|
470
|
+
return remote + local;
|
|
471
|
+
};
|
|
472
|
+
divineAddressFull = async (address) => {
|
|
473
|
+
const count = await this.boundWitnesses.useCollection((collection) => collection.countDocuments({ addresses: { $in: [address] } }));
|
|
474
|
+
await this.storeDivinedResult(address, count);
|
|
475
|
+
return count;
|
|
476
|
+
};
|
|
477
|
+
divineAddressesBatch = async () => {
|
|
478
|
+
this.logger?.log(`${moduleName2}.DivineAddressesBatch: Updating Addresses`);
|
|
479
|
+
const addressSpaceDiviners = await this.upResolver.resolve(assertEx3("AddressSpaceDiviner"));
|
|
480
|
+
const addressSpaceDiviner = asDivinerInstance(addressSpaceDiviners, `${moduleName2}.DivineAddressesBatch: Missing AddressSpaceDiviner`);
|
|
481
|
+
const result = await addressSpaceDiviner.divine([]) || [];
|
|
482
|
+
const addresses = result.filter((x) => x.schema === AddressSchema3).map((x) => x.address);
|
|
483
|
+
const additions = this.addressIterator.addValues(addresses);
|
|
484
|
+
this.logger?.log(`${moduleName2}.DivineAddressesBatch: Incoming Addresses Total: ${addresses.length} New: ${additions}`);
|
|
485
|
+
if (addresses.length > 0 && !this.backgroundDivineTask) this.backgroundDivineTask = this.backgroundDivine();
|
|
486
|
+
this.logger?.log(`${moduleName2}.DivineAddressesBatch: Updated Addresses`);
|
|
487
|
+
};
|
|
488
|
+
divineAllAddresses = () => this.boundWitnesses.useCollection((collection) => collection.estimatedDocumentCount());
|
|
489
|
+
processChange = (change) => {
|
|
490
|
+
this.resumeAfter = change._id;
|
|
491
|
+
const addresses = change?.fullDocument?.addresses;
|
|
492
|
+
for (const address of addresses) {
|
|
493
|
+
if (address) this.pendingCounts[address] = (this.pendingCounts[address] || 0) + 1;
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
registerWithChangeStream = async () => {
|
|
497
|
+
this.logger?.log(`${moduleName2}.RegisterWithChangeStream: Registering`);
|
|
498
|
+
const wrapper = MongoClientWrapper.get(this.boundWitnesses.uri, this.boundWitnesses.config.maxPoolSize);
|
|
499
|
+
const connection = await wrapper.connect();
|
|
500
|
+
assertEx3(connection, () => `${moduleName2}.RegisterWithChangeStream: Connection failed`);
|
|
501
|
+
const collection = connection.db(DATABASES2.Archivist).collection(COLLECTIONS2.BoundWitnesses);
|
|
502
|
+
const opts = this.resumeAfter ? { resumeAfter: this.resumeAfter } : {};
|
|
503
|
+
this.changeStream = collection.watch([], opts);
|
|
504
|
+
this.changeStream.on("change", this.processChange);
|
|
505
|
+
this.changeStream.on("error", this.registerWithChangeStream);
|
|
506
|
+
this.logger?.log(`${moduleName2}.RegisterWithChangeStream: Registered`);
|
|
507
|
+
};
|
|
508
|
+
storeDivinedResult = async (address, count) => {
|
|
509
|
+
await this.boundWitnesses.useMongo(async (mongo) => {
|
|
510
|
+
await mongo.db(DATABASES2.Archivist).collection(COLLECTIONS2.ArchivistStats).updateOne({ address }, { $set: { [`${COLLECTIONS2.BoundWitnesses}.count`]: count } }, updateOptions);
|
|
511
|
+
});
|
|
512
|
+
this.pendingCounts[address] = 0;
|
|
513
|
+
};
|
|
514
|
+
updateChanges = async () => {
|
|
515
|
+
this.logger?.log(`${moduleName2}.UpdateChanges: Updating`);
|
|
516
|
+
const updates = Object.keys(this.pendingCounts).map((address) => {
|
|
517
|
+
const count = this.pendingCounts[address];
|
|
518
|
+
this.pendingCounts[address] = 0;
|
|
519
|
+
const $inc = { [`${COLLECTIONS2.BoundWitnesses}.count`]: count };
|
|
520
|
+
return this.boundWitnesses.useMongo(async (mongo) => {
|
|
521
|
+
await mongo.db(DATABASES2.Archivist).collection(COLLECTIONS2.ArchivistStats).updateOne({ address }, { $inc }, updateOptions);
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
const results = await Promise.allSettled(updates);
|
|
525
|
+
const succeeded = results.filter(fulfilled).length;
|
|
526
|
+
const failed = results.filter(rejected).length;
|
|
527
|
+
this.logger?.log(`${moduleName2}.UpdateChanges: Updated - Succeeded: ${succeeded} Failed: ${failed}`);
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
// src/MongoDBPayloadDiviner.ts
|
|
532
|
+
import { PayloadDiviner } from "@xyo-network/diviner-payload-abstract";
|
|
533
|
+
import { isPayloadDivinerQueryPayload, PayloadDivinerConfigSchema } from "@xyo-network/diviner-payload-model";
|
|
534
|
+
import {
|
|
535
|
+
DefaultLimit as DefaultLimit3,
|
|
536
|
+
DefaultMaxTimeMS as DefaultMaxTimeMS5,
|
|
537
|
+
DefaultOrder as DefaultOrder2,
|
|
538
|
+
MongoDBModuleMixin as MongoDBModuleMixin6
|
|
539
|
+
} from "@xyo-network/module-abstract-mongodb";
|
|
540
|
+
import {
|
|
541
|
+
SequenceConstants as SequenceConstants2
|
|
542
|
+
} from "@xyo-network/payload-model";
|
|
543
|
+
import { fromDbRepresentation as fromDbRepresentation3 } from "@xyo-network/payload-mongodb";
|
|
544
|
+
var MongoDBDivinerBase6 = MongoDBModuleMixin6(PayloadDiviner);
|
|
545
|
+
var MongoDBPayloadDiviner = class extends MongoDBDivinerBase6 {
|
|
546
|
+
static configSchemas = [...super.configSchemas, PayloadDivinerConfigSchema];
|
|
547
|
+
static defaultConfigSchema = PayloadDivinerConfigSchema;
|
|
548
|
+
async divineHandler(payloads) {
|
|
549
|
+
const query = payloads?.find(isPayloadDivinerQueryPayload);
|
|
550
|
+
if (!query) throw new Error("Received payload is not a Query");
|
|
551
|
+
const {
|
|
552
|
+
limit = DefaultLimit3,
|
|
553
|
+
cursor = (query.order ?? DefaultOrder2) === "asc" ? SequenceConstants2.minLocalSequence : SequenceConstants2.maxLocalSequence,
|
|
554
|
+
order = DefaultOrder2,
|
|
555
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
556
|
+
schema,
|
|
557
|
+
schemas,
|
|
558
|
+
...props
|
|
559
|
+
} = query;
|
|
560
|
+
const direction = order === "asc" ? 1 : -1;
|
|
561
|
+
const sort = { _sequence: direction };
|
|
562
|
+
const filter = {};
|
|
563
|
+
if (cursor) {
|
|
564
|
+
filter._sequence = order === "desc" ? { $lt: cursor } : { $gt: cursor };
|
|
565
|
+
}
|
|
566
|
+
if (schemas?.length) filter.schema = { $in: schemas };
|
|
567
|
+
if (Object.keys(props).length > 0) {
|
|
568
|
+
const additionalFilterCriteria = Object.entries(props);
|
|
569
|
+
for (const [prop, propFilter] of additionalFilterCriteria) {
|
|
570
|
+
if (`${prop}`?.startsWith("$")) continue;
|
|
571
|
+
filter[prop] = Array.isArray(propFilter) ? { $in: propFilter } : propFilter;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
let result;
|
|
575
|
+
const filtered = await this.payloads.find(filter);
|
|
576
|
+
result = (await filtered.sort(sort).limit(limit).maxTimeMS(DefaultMaxTimeMS5).toArray()).map(fromDbRepresentation3);
|
|
577
|
+
return result.map(fromDbRepresentation3);
|
|
578
|
+
}
|
|
579
|
+
async startHandler() {
|
|
580
|
+
await super.startHandler();
|
|
581
|
+
await this.ensureIndexes();
|
|
582
|
+
return true;
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// src/MongoDBPayloadStatsDiviner.ts
|
|
587
|
+
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
588
|
+
import { delay as delay2 } from "@xylabs/delay";
|
|
589
|
+
import { MongoClientWrapper as MongoClientWrapper2 } from "@xylabs/mongo";
|
|
590
|
+
import { fulfilled as fulfilled2, rejected as rejected2 } from "@xylabs/promise";
|
|
591
|
+
import { asDivinerInstance as asDivinerInstance2 } from "@xyo-network/diviner-model";
|
|
592
|
+
import { PayloadStatsDiviner } from "@xyo-network/diviner-payload-stats-abstract";
|
|
593
|
+
import {
|
|
594
|
+
isPayloadStatsQueryPayload,
|
|
595
|
+
PayloadStatsDivinerConfigSchema,
|
|
596
|
+
PayloadStatsDivinerSchema
|
|
597
|
+
} from "@xyo-network/diviner-payload-stats-model";
|
|
598
|
+
import {
|
|
599
|
+
COLLECTIONS as COLLECTIONS3,
|
|
600
|
+
DATABASES as DATABASES3,
|
|
601
|
+
MongoDBModuleMixin as MongoDBModuleMixin7
|
|
602
|
+
} from "@xyo-network/module-abstract-mongodb";
|
|
603
|
+
import { AddressSchema as AddressSchema4 } from "@xyo-network/module-model";
|
|
604
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
605
|
+
var updateOptions2 = { upsert: true };
|
|
606
|
+
var MongoDBDivinerBase7 = MongoDBModuleMixin7(PayloadStatsDiviner);
|
|
607
|
+
var moduleName3 = "MongoDBPayloadStatsDiviner";
|
|
608
|
+
var MongoDBPayloadStatsDiviner = class extends MongoDBDivinerBase7 {
|
|
609
|
+
static configSchemas = [...super.configSchemas, PayloadStatsDivinerConfigSchema];
|
|
610
|
+
static defaultConfigSchema = PayloadStatsDivinerConfigSchema;
|
|
611
|
+
/**
|
|
612
|
+
* Iterates over know addresses obtained from AddressDiviner
|
|
613
|
+
*/
|
|
614
|
+
addressIterator = new SetIterator([]);
|
|
615
|
+
/**
|
|
616
|
+
* The max number of records to search during the aggregate query
|
|
617
|
+
*/
|
|
618
|
+
aggregateLimit = 1e3;
|
|
619
|
+
/**
|
|
620
|
+
* The max number of iterations of aggregate queries to allow when
|
|
621
|
+
* divining the schema stats for a single address
|
|
622
|
+
*/
|
|
623
|
+
aggregateMaxIterations = 1e6;
|
|
624
|
+
/**
|
|
625
|
+
* The amount of time to allow the aggregate query to execute
|
|
626
|
+
*/
|
|
627
|
+
aggregateTimeoutMs = 1e4;
|
|
628
|
+
/**
|
|
629
|
+
* The interval at which the background divine task will run. Prevents
|
|
630
|
+
* continuously iterating over DB and exhausting DB resources
|
|
631
|
+
*/
|
|
632
|
+
backgroundDivineIntervalMs = 250;
|
|
633
|
+
/**
|
|
634
|
+
* A reference to the background task to ensure that the
|
|
635
|
+
* continuous background divine stays running
|
|
636
|
+
*/
|
|
637
|
+
backgroundDivineTask;
|
|
638
|
+
changeStream = void 0;
|
|
639
|
+
pendingCounts = {};
|
|
640
|
+
resumeAfter = void 0;
|
|
641
|
+
get jobs() {
|
|
642
|
+
return [
|
|
643
|
+
{
|
|
644
|
+
name: `${moduleName3}.UpdateChanges`,
|
|
645
|
+
onSuccess: () => {
|
|
646
|
+
this.pendingCounts = {};
|
|
647
|
+
},
|
|
648
|
+
schedule: "1 minute",
|
|
649
|
+
task: async () => await this.updateChanges()
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
name: `${moduleName3}.DivineAddressesBatch`,
|
|
653
|
+
schedule: "5 minute",
|
|
654
|
+
task: async () => await this.divineAddressesBatch()
|
|
655
|
+
}
|
|
656
|
+
];
|
|
657
|
+
}
|
|
658
|
+
async divineHandler(payloads) {
|
|
659
|
+
const query = payloads?.find(isPayloadStatsQueryPayload);
|
|
660
|
+
const addresses = query?.address ? Array.isArray(query?.address) ? query.address : [query.address] : void 0;
|
|
661
|
+
const counts = addresses ? await Promise.all(addresses.map((address) => this.divineAddress(address))) : [await this.divineAllAddresses()];
|
|
662
|
+
return await Promise.all(
|
|
663
|
+
counts.map((count) => new PayloadBuilder3({ schema: PayloadStatsDivinerSchema }).fields({ count }).build())
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
async startHandler() {
|
|
667
|
+
await super.startHandler();
|
|
668
|
+
await this.ensureIndexes();
|
|
669
|
+
await this.registerWithChangeStream();
|
|
670
|
+
defineJobs(this.jobQueue, this.jobs);
|
|
671
|
+
this.jobQueue.once("ready", async () => await scheduleJobs(this.jobQueue, this.jobs));
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
async stopHandler() {
|
|
675
|
+
await this.changeStream?.close();
|
|
676
|
+
return await super.stopHandler();
|
|
677
|
+
}
|
|
678
|
+
backgroundDivine = async () => {
|
|
679
|
+
for (const address of this.addressIterator) {
|
|
680
|
+
try {
|
|
681
|
+
await this.divineAddressFull(address);
|
|
682
|
+
} catch (error) {
|
|
683
|
+
this.logger?.error(`${moduleName3}.BackgroundDivine: ${error}`);
|
|
684
|
+
}
|
|
685
|
+
await delay2(this.backgroundDivineIntervalMs);
|
|
686
|
+
}
|
|
687
|
+
this.backgroundDivineTask = void 0;
|
|
688
|
+
};
|
|
689
|
+
divineAddress = async (address) => {
|
|
690
|
+
const stats = await this.payloads.useMongo(async (mongo) => {
|
|
691
|
+
return await mongo.db(DATABASES3.Archivist).collection(COLLECTIONS3.ArchivistStats).findOne({ address });
|
|
692
|
+
});
|
|
693
|
+
const remote = stats?.payloads?.count || 0;
|
|
694
|
+
const local = this.pendingCounts[address] || 0;
|
|
695
|
+
return remote + local;
|
|
696
|
+
};
|
|
697
|
+
divineAddressFull = async (address) => {
|
|
698
|
+
let total = 0;
|
|
699
|
+
for (let iteration = 0; iteration < this.aggregateMaxIterations; iteration++) {
|
|
700
|
+
const count = await this.boundWitnesses.useCollection((collection) => {
|
|
701
|
+
return collection.aggregate([
|
|
702
|
+
{ $sort: { _timestamp: -1, addresses: 1 } },
|
|
703
|
+
// Find all BoundWitnesses containing this address
|
|
704
|
+
{ $match: { addresses: { $in: [address] } } },
|
|
705
|
+
// In batches
|
|
706
|
+
{ $skip: iteration * this.aggregateLimit },
|
|
707
|
+
{ $limit: this.aggregateLimit },
|
|
708
|
+
// Flatten the payload_hashes to individual documents
|
|
709
|
+
{ $unwind: { path: "$payload_hashes" } },
|
|
710
|
+
// Count all the payload hashes witnessed for this address
|
|
711
|
+
{ $count: "payload_hashes" }
|
|
712
|
+
]).maxTimeMS(this.aggregateTimeoutMs).next();
|
|
713
|
+
});
|
|
714
|
+
if (count != null) {
|
|
715
|
+
total += count.payload_hashes;
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
break;
|
|
719
|
+
}
|
|
720
|
+
await this.storeDivinedResult(address, total);
|
|
721
|
+
return total;
|
|
722
|
+
};
|
|
723
|
+
divineAddressesBatch = async () => {
|
|
724
|
+
this.logger?.log(`${moduleName3}.DivineAddressesBatch: Updating Addresses`);
|
|
725
|
+
const addressSpaceDiviners = await this.upResolver.resolve("AddressSpaceDiviner");
|
|
726
|
+
const addressSpaceDiviner = asDivinerInstance2(addressSpaceDiviners, `${moduleName3}.DivineAddressesBatch: Missing AddressSpaceDiviner`);
|
|
727
|
+
const result = await addressSpaceDiviner.divine() ?? [];
|
|
728
|
+
const addresses = result.filter((x) => x.schema === AddressSchema4).map((x) => x.address);
|
|
729
|
+
const additions = this.addressIterator.addValues(addresses);
|
|
730
|
+
this.logger?.log(`${moduleName3}.DivineAddressesBatch: Incoming Addresses Total: ${addresses.length} New: ${additions}`);
|
|
731
|
+
if (addresses.length > 0 && !this.backgroundDivineTask) this.backgroundDivineTask = this.backgroundDivine();
|
|
732
|
+
this.logger?.log(`${moduleName3}.DivineAddressesBatch: Updated Addresses`);
|
|
733
|
+
};
|
|
734
|
+
divineAllAddresses = () => this.payloads.useCollection((collection) => collection.estimatedDocumentCount());
|
|
735
|
+
processChange = (change) => {
|
|
736
|
+
this.resumeAfter = change._id;
|
|
737
|
+
const addresses = change.fullDocument.addresses;
|
|
738
|
+
const count = change.fullDocument?.payload_hashes?.length || 0;
|
|
739
|
+
if (addresses?.length && count) {
|
|
740
|
+
for (const address of addresses) {
|
|
741
|
+
if (address) this.pendingCounts[address] = (this.pendingCounts[address] || 0) + count;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
registerWithChangeStream = async () => {
|
|
746
|
+
this.logger?.log(`${moduleName3}.RegisterWithChangeStream: Registering`);
|
|
747
|
+
const wrapper = MongoClientWrapper2.get(this.boundWitnesses.uri, this.boundWitnesses.config.maxPoolSize);
|
|
748
|
+
const connection = await wrapper.connect();
|
|
749
|
+
assertEx4(connection, () => `${moduleName3}.RegisterWithChangeStream: Connection failed`);
|
|
750
|
+
const collection = connection.db(DATABASES3.Archivist).collection(COLLECTIONS3.BoundWitnesses);
|
|
751
|
+
const opts = this.resumeAfter ? { resumeAfter: this.resumeAfter } : {};
|
|
752
|
+
this.changeStream = collection.watch([], opts);
|
|
753
|
+
this.changeStream.on("change", this.processChange);
|
|
754
|
+
this.changeStream.on("error", this.registerWithChangeStream);
|
|
755
|
+
this.logger?.log(`${moduleName3}.RegisterWithChangeStream: Registered`);
|
|
756
|
+
};
|
|
757
|
+
storeDivinedResult = async (address, count) => {
|
|
758
|
+
await this.payloads.useMongo(async (mongo) => {
|
|
759
|
+
await mongo.db(DATABASES3.Archivist).collection(COLLECTIONS3.ArchivistStats).updateOne({ address }, { $set: { [`${COLLECTIONS3.Payloads}.count`]: count } }, updateOptions2);
|
|
760
|
+
});
|
|
761
|
+
this.pendingCounts[address] = 0;
|
|
762
|
+
};
|
|
763
|
+
updateChanges = async () => {
|
|
764
|
+
this.logger?.log(`${moduleName3}.UpdateChanges: Updating`);
|
|
765
|
+
const updates = Object.keys(this.pendingCounts).map((address) => {
|
|
766
|
+
const count = this.pendingCounts[address];
|
|
767
|
+
this.pendingCounts[address] = 0;
|
|
768
|
+
const $inc = { [`${COLLECTIONS3.Payloads}.count`]: count };
|
|
769
|
+
return this.payloads.useMongo(async (mongo) => {
|
|
770
|
+
await mongo.db(DATABASES3.Archivist).collection(COLLECTIONS3.ArchivistStats).updateOne({ address }, { $inc }, updateOptions2);
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
const results = await Promise.allSettled(updates);
|
|
774
|
+
const succeeded = results.filter(fulfilled2).length;
|
|
775
|
+
const failed = results.filter(rejected2).length;
|
|
776
|
+
this.logger?.log(`${moduleName3}.UpdateChanges: Updated - Succeeded: ${succeeded} Failed: ${failed}`);
|
|
777
|
+
};
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
// src/MongoDBSchemaListDiviner.ts
|
|
781
|
+
import { SchemaListDiviner } from "@xyo-network/diviner-schema-list-abstract";
|
|
782
|
+
import {
|
|
783
|
+
isSchemaListQueryPayload,
|
|
784
|
+
SchemaListDivinerConfigSchema,
|
|
785
|
+
SchemaListDivinerSchema
|
|
786
|
+
} from "@xyo-network/diviner-schema-list-model";
|
|
787
|
+
import { MongoDBModuleMixin as MongoDBModuleMixin8 } from "@xyo-network/module-abstract-mongodb";
|
|
788
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
789
|
+
import {
|
|
790
|
+
isSchema
|
|
791
|
+
} from "@xyo-network/payload-model";
|
|
792
|
+
var MongoDBDivinerBase8 = MongoDBModuleMixin8(SchemaListDiviner);
|
|
793
|
+
var MongoDBSchemaListDiviner = class extends MongoDBDivinerBase8 {
|
|
794
|
+
static configSchemas = [...super.configSchemas, SchemaListDivinerConfigSchema];
|
|
795
|
+
static defaultConfigSchema = SchemaListDivinerConfigSchema;
|
|
796
|
+
async divineHandler(payloads) {
|
|
797
|
+
const query = payloads?.find(isSchemaListQueryPayload);
|
|
798
|
+
const addresses = query?.address ? Array.isArray(query?.address) ? query.address : [query.address] : void 0;
|
|
799
|
+
const counts = addresses ? await Promise.all(addresses.map((address) => this.divineAddress(address))) : [await this.divineAllAddresses()];
|
|
800
|
+
return await Promise.all(
|
|
801
|
+
counts.map((schemas) => new PayloadBuilder4({ schema: SchemaListDivinerSchema }).fields({ schemas }).build())
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
async startHandler() {
|
|
805
|
+
await super.startHandler();
|
|
806
|
+
await this.ensureIndexes();
|
|
807
|
+
return true;
|
|
808
|
+
}
|
|
809
|
+
divineAddress = async (archive) => {
|
|
810
|
+
const result = await this.boundWitnesses.useCollection((collection) => {
|
|
811
|
+
return collection.distinct("payload_schemas", { addresses: { $in: [archive] } });
|
|
812
|
+
});
|
|
813
|
+
return result.filter(isSchema);
|
|
814
|
+
};
|
|
815
|
+
divineAllAddresses = async () => {
|
|
816
|
+
const result = await this.boundWitnesses.useCollection((collection) => {
|
|
817
|
+
return collection.distinct("payload_schemas");
|
|
818
|
+
});
|
|
819
|
+
return result.filter(isSchema);
|
|
820
|
+
};
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
// src/MongoDBSchemaStatsDiviner.ts
|
|
824
|
+
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
825
|
+
import { delay as delay3 } from "@xylabs/delay";
|
|
826
|
+
import { MongoClientWrapper as MongoClientWrapper3 } from "@xylabs/mongo";
|
|
827
|
+
import { fulfilled as fulfilled3, rejected as rejected3 } from "@xylabs/promise";
|
|
828
|
+
import { asDivinerInstance as asDivinerInstance3 } from "@xyo-network/diviner-model";
|
|
829
|
+
import { SchemaStatsDiviner } from "@xyo-network/diviner-schema-stats-abstract";
|
|
830
|
+
import {
|
|
831
|
+
isSchemaStatsQueryPayload,
|
|
832
|
+
SchemaStatsDivinerConfigSchema,
|
|
833
|
+
SchemaStatsDivinerSchema
|
|
834
|
+
} from "@xyo-network/diviner-schema-stats-model";
|
|
835
|
+
import {
|
|
836
|
+
COLLECTIONS as COLLECTIONS4,
|
|
837
|
+
DATABASES as DATABASES4,
|
|
838
|
+
fromDbProperty,
|
|
839
|
+
MongoDBModuleMixin as MongoDBModuleMixin9,
|
|
840
|
+
toDbProperty
|
|
841
|
+
} from "@xyo-network/module-abstract-mongodb";
|
|
842
|
+
import { AddressSchema as AddressSchema5 } from "@xyo-network/module-model";
|
|
843
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
844
|
+
var updateOptions3 = { upsert: true };
|
|
845
|
+
var MongoDBDivinerBase9 = MongoDBModuleMixin9(SchemaStatsDiviner);
|
|
846
|
+
var moduleName4 = "MongoDBSchemaStatsDiviner";
|
|
847
|
+
var MongoDBSchemaStatsDiviner = class extends MongoDBDivinerBase9 {
|
|
848
|
+
static configSchemas = [...super.configSchemas, SchemaStatsDivinerConfigSchema];
|
|
849
|
+
static defaultConfigSchema = SchemaStatsDivinerConfigSchema;
|
|
850
|
+
/**
|
|
851
|
+
* Iterates over know addresses obtained from AddressDiviner
|
|
852
|
+
*/
|
|
853
|
+
addressIterator = new SetIterator([]);
|
|
854
|
+
/**
|
|
855
|
+
* The max number of records to search during the aggregate query
|
|
856
|
+
*/
|
|
857
|
+
aggregateLimit = 1e3;
|
|
858
|
+
/**
|
|
859
|
+
* The max number of iterations of aggregate queries to allow when
|
|
860
|
+
* divining the schema stats for a single address
|
|
861
|
+
*/
|
|
862
|
+
aggregateMaxIterations = 1e6;
|
|
863
|
+
/**
|
|
864
|
+
* The amount of time to allow the aggregate query to execute
|
|
865
|
+
*/
|
|
866
|
+
aggregateTimeoutMs = 1e4;
|
|
867
|
+
/**
|
|
868
|
+
* The interval at which the background divine task will run. Prevents
|
|
869
|
+
* continuously iterating over DB and exhausting DB resources
|
|
870
|
+
*/
|
|
871
|
+
backgroundDivineIntervalMs = 250;
|
|
872
|
+
/**
|
|
873
|
+
* A reference to the background task to ensure that the
|
|
874
|
+
* continuous background divine stays running
|
|
875
|
+
*/
|
|
876
|
+
backgroundDivineTask;
|
|
877
|
+
/**
|
|
878
|
+
* The stream with which the diviner is notified of insertions
|
|
879
|
+
* to the payloads collection
|
|
880
|
+
*/
|
|
881
|
+
changeStream = void 0;
|
|
882
|
+
/**
|
|
883
|
+
* The counts per schema to update on the next update interval
|
|
884
|
+
*/
|
|
885
|
+
pendingCounts = {};
|
|
886
|
+
/**
|
|
887
|
+
* The resume token for listening to insertions into the payload collection
|
|
888
|
+
*/
|
|
889
|
+
resumeAfter = void 0;
|
|
890
|
+
get jobs() {
|
|
891
|
+
return [
|
|
892
|
+
{
|
|
893
|
+
name: `${moduleName4}.UpdateChanges`,
|
|
894
|
+
onSuccess: () => {
|
|
895
|
+
this.pendingCounts = {};
|
|
896
|
+
},
|
|
897
|
+
schedule: "1 minute",
|
|
898
|
+
task: async () => await this.updateChanges()
|
|
899
|
+
},
|
|
900
|
+
{
|
|
901
|
+
name: `${moduleName4}.DivineAddressesBatch`,
|
|
902
|
+
schedule: "5 minute",
|
|
903
|
+
task: async () => await this.divineAddressesBatch()
|
|
904
|
+
}
|
|
905
|
+
];
|
|
906
|
+
}
|
|
907
|
+
async divineHandler(payloads) {
|
|
908
|
+
const query = payloads?.find(isSchemaStatsQueryPayload);
|
|
909
|
+
const addresses = query?.address ? Array.isArray(query?.address) ? query.address : [query.address] : void 0;
|
|
910
|
+
const counts = addresses ? await Promise.all(addresses.map((address) => this.divineAddress(address))) : [this.divineAllAddresses()];
|
|
911
|
+
return await Promise.all(
|
|
912
|
+
counts.map((count) => new PayloadBuilder5({ schema: SchemaStatsDivinerSchema }).fields({ count }).build())
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
async startHandler() {
|
|
916
|
+
await super.startHandler();
|
|
917
|
+
await this.ensureIndexes();
|
|
918
|
+
await this.registerWithChangeStream();
|
|
919
|
+
defineJobs(this.jobQueue, this.jobs);
|
|
920
|
+
this.jobQueue.once("ready", async () => await scheduleJobs(this.jobQueue, this.jobs));
|
|
921
|
+
return true;
|
|
922
|
+
}
|
|
923
|
+
async stopHandler() {
|
|
924
|
+
await this.changeStream?.close();
|
|
925
|
+
return await super.stopHandler();
|
|
926
|
+
}
|
|
927
|
+
backgroundDivine = async () => {
|
|
928
|
+
for (const address of this.addressIterator) {
|
|
929
|
+
try {
|
|
930
|
+
await this.divineAddressFull(address);
|
|
931
|
+
} catch (error) {
|
|
932
|
+
this.logger?.error(`${moduleName4}.BackgroundDivine: ${error}`);
|
|
933
|
+
}
|
|
934
|
+
await delay3(this.backgroundDivineIntervalMs);
|
|
935
|
+
}
|
|
936
|
+
this.backgroundDivineTask = void 0;
|
|
937
|
+
};
|
|
938
|
+
divineAddress = async (address) => {
|
|
939
|
+
const stats = await this.boundWitnesses.useMongo(async (mongo) => {
|
|
940
|
+
return await mongo.db(DATABASES4.Archivist).collection(COLLECTIONS4.ArchivistStats).findOne({ address });
|
|
941
|
+
});
|
|
942
|
+
const remote = Object.fromEntries(
|
|
943
|
+
Object.entries(stats?.schema?.count || {}).map(([schema, count]) => {
|
|
944
|
+
return [fromDbProperty(schema), count];
|
|
945
|
+
})
|
|
946
|
+
);
|
|
947
|
+
const local = this.pendingCounts[address] || {};
|
|
948
|
+
const keys = [...Object.keys(local), ...Object.keys(remote).map(fromDbProperty)];
|
|
949
|
+
const ret = Object.fromEntries(
|
|
950
|
+
keys.map((key) => {
|
|
951
|
+
const localSchemaCount = local[key] || 0;
|
|
952
|
+
const remoteSchemaCount = remote[key] || 0;
|
|
953
|
+
const value = localSchemaCount + remoteSchemaCount;
|
|
954
|
+
return [key, value];
|
|
955
|
+
})
|
|
956
|
+
);
|
|
957
|
+
return ret;
|
|
958
|
+
};
|
|
959
|
+
divineAddressFull = async (address) => {
|
|
960
|
+
const sortStartTime = Date.now();
|
|
961
|
+
const totals = {};
|
|
962
|
+
for (let iteration = 0; iteration < this.aggregateMaxIterations; iteration++) {
|
|
963
|
+
const result = await this.boundWitnesses.useCollection((collection) => {
|
|
964
|
+
return collection.aggregate().sort({ _timestamp: 1 }).match({ _timestamp: { $lt: sortStartTime }, addresses: { $in: [address] } }).skip(iteration * this.aggregateLimit).limit(this.aggregateLimit).unwind({ path: "$payload_schemas" }).group({ _id: "$payload_schemas", count: { $sum: 1 } }).maxTimeMS(this.aggregateTimeoutMs).toArray();
|
|
965
|
+
});
|
|
966
|
+
if (result.length === 0) break;
|
|
967
|
+
for (const schema of result) {
|
|
968
|
+
totals[schema._id] = totals[schema._id] || 0 + schema.count;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
await this.storeDivinedResult(address, totals);
|
|
972
|
+
return totals;
|
|
973
|
+
};
|
|
974
|
+
divineAddressesBatch = async () => {
|
|
975
|
+
this.logger?.log(`${moduleName4}.DivineAddressesBatch: Updating Addresses`);
|
|
976
|
+
const addressSpaceDiviners = await this.upResolver.resolve("AddressSpaceDiviner");
|
|
977
|
+
const addressSpaceDiviner = asDivinerInstance3(addressSpaceDiviners, `${moduleName4}.DivineAddressesBatch: Missing AddressSpaceDiviner`);
|
|
978
|
+
const result = await addressSpaceDiviner.divine() ?? [];
|
|
979
|
+
const addresses = result.filter((x) => x.schema === AddressSchema5).map((x) => x.address);
|
|
980
|
+
const additions = this.addressIterator.addValues(addresses);
|
|
981
|
+
this.logger?.log(`${moduleName4}.DivineAddressesBatch: Incoming Addresses Total: ${addresses.length} New: ${additions}`);
|
|
982
|
+
if (addresses.length > 0 && !this.backgroundDivineTask) this.backgroundDivineTask = this.backgroundDivine();
|
|
983
|
+
this.logger?.log(`${moduleName4}.DivineAddressesBatch: Updated Addresses`);
|
|
984
|
+
};
|
|
985
|
+
divineAllAddresses = () => {
|
|
986
|
+
throw new Error("Not Implemented");
|
|
987
|
+
};
|
|
988
|
+
processChange = (change) => {
|
|
989
|
+
this.resumeAfter = change._id;
|
|
990
|
+
const addresses = change.fullDocument.addresses;
|
|
991
|
+
const schemas = change.fullDocument.payload_schemas;
|
|
992
|
+
if (addresses?.length) {
|
|
993
|
+
for (const address of addresses) {
|
|
994
|
+
for (const schema of schemas) {
|
|
995
|
+
if (!this.pendingCounts[address]) this.pendingCounts[address] = {};
|
|
996
|
+
this.pendingCounts[address][schema] = (this.pendingCounts[address][schema] || 0) + 1;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
registerWithChangeStream = async () => {
|
|
1002
|
+
this.logger?.log(`${moduleName4}.RegisterWithChangeStream: Registering`);
|
|
1003
|
+
const wrapper = MongoClientWrapper3.get(this.boundWitnesses.uri, this.boundWitnesses.config.maxPoolSize);
|
|
1004
|
+
const connection = await wrapper.connect();
|
|
1005
|
+
assertEx5(connection, () => `${moduleName4}.RegisterWithChangeStream: Connection failed`);
|
|
1006
|
+
const collection = connection.db(DATABASES4.Archivist).collection(COLLECTIONS4.BoundWitnesses);
|
|
1007
|
+
const opts = this.resumeAfter ? { resumeAfter: this.resumeAfter } : {};
|
|
1008
|
+
this.changeStream = collection.watch([], opts);
|
|
1009
|
+
this.changeStream.on("change", this.processChange);
|
|
1010
|
+
this.changeStream.on("error", this.registerWithChangeStream);
|
|
1011
|
+
this.logger?.log(`${moduleName4}.RegisterWithChangeStream: Registered`);
|
|
1012
|
+
};
|
|
1013
|
+
storeDivinedResult = async (address, counts) => {
|
|
1014
|
+
const sanitizedCounts = Object.fromEntries(
|
|
1015
|
+
Object.entries(counts).map(([schema, count]) => {
|
|
1016
|
+
return [toDbProperty(schema), count];
|
|
1017
|
+
})
|
|
1018
|
+
);
|
|
1019
|
+
await this.boundWitnesses.useMongo(async (mongo) => {
|
|
1020
|
+
await mongo.db(DATABASES4.Archivist).collection(COLLECTIONS4.ArchivistStats).updateOne({ address }, { $set: { ["schema.count"]: sanitizedCounts } }, updateOptions3);
|
|
1021
|
+
});
|
|
1022
|
+
this.pendingCounts[address] = {};
|
|
1023
|
+
};
|
|
1024
|
+
updateChanges = async () => {
|
|
1025
|
+
this.logger?.log(`${moduleName4}.UpdateChanges: Updating`);
|
|
1026
|
+
const updates = Object.keys(this.pendingCounts).map((address) => {
|
|
1027
|
+
const $inc = Object.keys(this.pendingCounts[address]).map((schema) => {
|
|
1028
|
+
return { [`schema.count.${toDbProperty(schema)}`]: this.pendingCounts[address][schema] };
|
|
1029
|
+
}).reduce((prev, curr) => Object.assign(prev, curr), {});
|
|
1030
|
+
this.pendingCounts[address] = {};
|
|
1031
|
+
return this.boundWitnesses.useMongo(async (mongo) => {
|
|
1032
|
+
await mongo.db(DATABASES4.Archivist).collection(COLLECTIONS4.ArchivistStats).updateOne({ address }, { $inc }, updateOptions3);
|
|
1033
|
+
});
|
|
1034
|
+
});
|
|
1035
|
+
const results = await Promise.allSettled(updates);
|
|
1036
|
+
const succeeded = results.filter(fulfilled3).length;
|
|
1037
|
+
const failed = results.filter(rejected3).length;
|
|
1038
|
+
this.logger?.log(`${moduleName4}.UpdateChanges: Updated - Succeeded: ${succeeded} Failed: ${failed}`);
|
|
1039
|
+
};
|
|
1040
|
+
};
|
|
1041
|
+
|
|
1042
|
+
// src/UserLocationsDiviner.ts
|
|
1043
|
+
import "reflect-metadata";
|
|
1044
|
+
import { assertEx as assertEx6 } from "@xylabs/assert";
|
|
1045
|
+
import { compact } from "@xylabs/lodash";
|
|
1046
|
+
import { ArchivistPayloadDivinerConfigSchema } from "@xyo-network/diviner-archivist";
|
|
1047
|
+
import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
|
|
1048
|
+
import { CoinUserLocationsDiviner } from "@xyo-network/diviner-coin-user-locations-abstract";
|
|
1049
|
+
import { LocationSchema } from "@xyo-network/location-payload-plugin";
|
|
1050
|
+
import { PayloadWrapper } from "@xyo-network/payload-wrapper";
|
|
1051
|
+
var CoinCurrentUserWitnessSchema = "co.coinapp.current.user.witness";
|
|
1052
|
+
var CoinCurrentLocationWitnessSchema = "co.coinapp.current.location.witness";
|
|
1053
|
+
var isLocationPayload = (x) => x?.schema === LocationSchema;
|
|
1054
|
+
var MemoryCoinUserLocationsDiviner = class extends CoinUserLocationsDiviner {
|
|
1055
|
+
static configSchemas = [...super.configSchemas, ArchivistPayloadDivinerConfigSchema];
|
|
1056
|
+
static defaultConfigSchema = ArchivistPayloadDivinerConfigSchema;
|
|
1057
|
+
async divineHandler(payloads) {
|
|
1058
|
+
const user = payloads?.find(
|
|
1059
|
+
(payload) => payload?.schema === CoinCurrentUserWitnessSchema
|
|
1060
|
+
);
|
|
1061
|
+
if (user) {
|
|
1062
|
+
const wrapper = PayloadWrapper.wrap(user);
|
|
1063
|
+
this.logger?.log("CoinUserLocationsDiviner.Divine: Processing query");
|
|
1064
|
+
const diviner = this.params.bws;
|
|
1065
|
+
const filter = { payload_hashes: [await wrapper.dataHash()], schema: BoundWitnessDivinerQuerySchema };
|
|
1066
|
+
const bwList = await diviner.divine([filter]) || [];
|
|
1067
|
+
const locationHashes = bwList.flatMap((bw) => {
|
|
1068
|
+
const locations2 = [];
|
|
1069
|
+
for (let i = 0; i < bwList.length; i++) {
|
|
1070
|
+
if (bw?.payload_schemas[i] === CoinCurrentLocationWitnessSchema) {
|
|
1071
|
+
locations2.push(assertEx6(bw?.payload_hashes[i], () => "Missing hash"));
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
return locations2;
|
|
1075
|
+
});
|
|
1076
|
+
const locations = compact(await this.params.archivist.get(locationHashes));
|
|
1077
|
+
this.logger?.log("CoinUserLocationsDiviner.Divine: Processed query");
|
|
1078
|
+
return locations;
|
|
1079
|
+
}
|
|
1080
|
+
return [];
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
export {
|
|
1084
|
+
BatchSetIterator,
|
|
1085
|
+
CoinCurrentLocationWitnessSchema,
|
|
1086
|
+
CoinCurrentUserWitnessSchema,
|
|
1087
|
+
MemoryCoinUserLocationsDiviner,
|
|
1088
|
+
MongoDBAddressHistoryDiviner,
|
|
1089
|
+
MongoDBAddressSpaceBatchDiviner,
|
|
1090
|
+
MongoDBAddressSpaceDiviner,
|
|
1091
|
+
MongoDBBoundWitnessDiviner,
|
|
1092
|
+
MongoDBBoundWitnessStatsDiviner,
|
|
1093
|
+
MongoDBPayloadDiviner,
|
|
1094
|
+
MongoDBPayloadStatsDiviner,
|
|
1095
|
+
MongoDBSchemaListDiviner,
|
|
1096
|
+
MongoDBSchemaStatsDiviner,
|
|
1097
|
+
SetIterator,
|
|
1098
|
+
isLocationPayload
|
|
1099
|
+
};
|
|
1100
|
+
//# sourceMappingURL=index.mjs.map
|