-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
archiving module functionality moved into abstract module
- Loading branch information
Showing
16 changed files
with
87 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
packages/modules/packages/archivist/packages/model/src/Config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 7 additions & 39 deletions
46
packages/modules/packages/archivist/src/AbstractArchivingModule.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,17 @@ | ||
import { compact } from '@xylabs/lodash' | ||
import { AccountInstance } from '@xyo-network/account-model' | ||
import { ArchivistInstance, asArchivistInstance } from '@xyo-network/archivist-model' | ||
import { AbstractModuleInstance, AnyConfigSchema, Module, ModuleConfig, ModuleEventData, ModuleParams, ModuleQueryResult } from '@xyo-network/module' | ||
import { ModuleError, Payload, Query } from '@xyo-network/payload-model' | ||
import { AbstractModuleInstance, AnyConfigSchema, Module, ModuleConfig, ModuleEventData, ModuleParams } from '@xyo-network/module' | ||
|
||
export type ArchivingModuleConfig<T extends ModuleConfig = ModuleConfig> = ModuleConfig< | ||
/** @deprecated use AbstractModule which now has this functionality included */ | ||
export type ArchivingModuleBaseConfig<T extends ModuleConfig = ModuleConfig> = ModuleConfig< | ||
{ | ||
archivists?: string[] | ||
schema: string | ||
} & T | ||
> | ||
// @creatableModule() | ||
|
||
/** @deprecated use AbstractModule which now has this functionality included */ | ||
export abstract class AbstractArchivingModule< | ||
TParams extends ModuleParams<AnyConfigSchema<ArchivingModuleConfig>> = ModuleParams<AnyConfigSchema<ArchivingModuleConfig>>, | ||
TParams extends ModuleParams<AnyConfigSchema<ArchivingModuleBaseConfig>> = ModuleParams<AnyConfigSchema<ArchivingModuleBaseConfig>>, | ||
TEventData extends ModuleEventData = ModuleEventData, | ||
> | ||
extends AbstractModuleInstance<TParams, TEventData> | ||
implements Module<TParams, TEventData> | ||
{ | ||
protected override async bindQueryResult<T extends Query>( | ||
query: T, | ||
payloads: Payload[], | ||
additionalWitnesses: AccountInstance[] = [], | ||
errorPayloads: ModuleError[] = [], | ||
): Promise<ModuleQueryResult> { | ||
const result = await super.bindQueryResult(query, payloads, additionalWitnesses, errorPayloads) | ||
await this.storeToArchivists(result.flat()) | ||
return result | ||
} | ||
|
||
protected async resolveArchivists(): Promise<ArchivistInstance[]> { | ||
const archivists = this.config.archivists | ||
if (!archivists) return [] | ||
const resolved = await Promise.all(archivists.map((archivist) => this.resolve(archivist))) | ||
return compact(resolved.map((mod) => asArchivistInstance(mod))) | ||
} | ||
|
||
protected async storeToArchivists(payloads: Payload[]): Promise<Payload[]> { | ||
const archivists = await this.resolveArchivists() | ||
return ( | ||
await Promise.all( | ||
archivists.map((archivist) => { | ||
return archivist.insert?.(payloads) | ||
}), | ||
) | ||
).map(([bw]) => bw) | ||
} | ||
} | ||
implements Module<TParams, TEventData> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.