@xyo-network/archivist-abstract 3.9.0 → 3.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import * as _xylabs_object from '@xylabs/object';
2
2
  import { Hash } from '@xylabs/hex';
3
3
  import { PromisableArray, Promisable } from '@xylabs/promise';
4
4
  import { AccountInstance } from '@xyo-network/account-model';
5
- import { ArchivistInstance, ArchivistParams, ArchivistModuleEventData, AttachableArchivistInstance, ArchivistNextOptions } from '@xyo-network/archivist-model';
5
+ import { ArchivistParams, ArchivistModuleEventData, AttachableArchivistInstance, ArchivistNextOptions, ReadArchivist, ArchivistInstance } from '@xyo-network/archivist-model';
6
6
  import { BoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model';
7
7
  import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper';
8
8
  import { AbstractModuleInstance } from '@xyo-network/module-abstract';
@@ -15,7 +15,7 @@ interface ActionConfig {
15
15
  interface InsertConfig extends ActionConfig {
16
16
  writeToParents?: boolean;
17
17
  }
18
- interface ArchivistParentInstances {
18
+ interface ArchivistParentInstanceMap {
19
19
  commit?: Record<string, ArchivistInstance>;
20
20
  read?: Record<string, ArchivistInstance>;
21
21
  write?: Record<string, ArchivistInstance>;
@@ -49,7 +49,7 @@ declare abstract class AbstractArchivist<TParams extends ArchivistParams = Archi
49
49
  protected commitHandler(): Promisable<BoundWitness[]>;
50
50
  protected deleteHandler(_hashes: Hash[]): PromisableArray<Hash>;
51
51
  protected deleteWithConfig(hashes: Hash[], config?: ActionConfig): Promise<Hash[]>;
52
- protected getFromParent(hashes: Hash[], archivist: ArchivistInstance): Promise<[WithStorageMeta<Payload>[], Hash[]]>;
52
+ protected getFromParent(hashes: Hash[], archivist: ReadArchivist): Promise<[WithStorageMeta<Payload>[], Hash[]]>;
53
53
  protected getFromParents(hashes: Hash[]): Promise<[WithStorageMeta<Payload>[], Hash[]]>;
54
54
  protected getHandler(_hashes: Hash[]): Promisable<WithStorageMeta<Payload>[]>;
55
55
  protected getWithConfig(hashes: Hash[], _config?: InsertConfig): Promise<WithStorageMeta<Payload>[]>;
@@ -60,11 +60,11 @@ declare abstract class AbstractArchivist<TParams extends ArchivistParams = Archi
60
60
  protected insertWithConfig(payloads: Payload[], config?: InsertConfig): Promise<WithStorageMeta<Payload>[]>;
61
61
  protected nextHandler(_options?: ArchivistNextOptions): Promisable<WithStorageMeta<Payload>[]>;
62
62
  protected nextWithConfig(options?: ArchivistNextOptions, _config?: InsertConfig): Promise<WithStorageMeta<Payload>[]>;
63
- protected parentArchivists(): Promise<ArchivistParentInstances>;
63
+ protected parentArchivists(): Promise<ArchivistParentInstanceMap>;
64
64
  protected queryHandler<T extends QueryBoundWitness = QueryBoundWitness, TConfig extends ModuleConfig = ModuleConfig>(query: T, payloads: Payload[], queryConfig?: TConfig): Promise<ModuleQueryHandlerResult>;
65
65
  protected writeToParent(parent: ArchivistInstance, payloads: Payload[]): Promise<Payload[]>;
66
66
  protected writeToParents(payloads: Payload[]): Promise<Payload[]>;
67
67
  private resolveArchivists;
68
68
  }
69
69
 
70
- export { AbstractArchivist, type ActionConfig, type ArchivistParentInstances, type InsertConfig };
70
+ export { AbstractArchivist, type ActionConfig, type InsertConfig };
@@ -232,9 +232,9 @@ var AbstractArchivist = class _AbstractArchivist extends AbstractModuleInstance
232
232
  }
233
233
  async parentArchivists() {
234
234
  this._parentArchivists = this._parentArchivists ?? {
235
- commit: await this.resolveArchivists(this.config?.parents?.commit),
236
- read: await this.resolveArchivists(this.config?.parents?.read),
237
- write: await this.resolveArchivists(this.config?.parents?.write)
235
+ commit: { ...await this.resolveArchivists(this.config?.parents?.commit, this.params.parents?.commit) },
236
+ read: { ...await this.resolveArchivists(this.config?.parents?.read) },
237
+ write: { ...await this.resolveArchivists(this.config?.parents?.write) }
238
238
  };
239
239
  return assertEx(this._parentArchivists);
240
240
  }
@@ -302,19 +302,23 @@ var AbstractArchivist = class _AbstractArchivist extends AbstractModuleInstance
302
302
  })
303
303
  )).filter(exists).flat();
304
304
  }
305
- async resolveArchivists(archivists = []) {
305
+ async resolveArchivists(archivists = [], archivistInstances) {
306
306
  const archivistModules = (await Promise.all(archivists.map((archivist) => this.resolve(archivist)))).filter(exists).filter(duplicateModules);
307
307
  assertEx(
308
308
  !this.requireAllParents || archivistModules.length === archivists.length,
309
309
  () => `Failed to find some archivists (set allRequired to false if ok): [${archivists.filter((archivist) => archivistModules.map((mod) => !(mod.address === archivist || mod.modName === archivist)))}]`
310
310
  );
311
+ const archivistInstancesMap = {};
312
+ for (let archivistInstance of archivistInstances ?? []) {
313
+ archivistInstancesMap[archivistInstance.address] = archivistInstance;
314
+ }
311
315
  return archivistModules.reduce((prev, mod) => {
312
316
  prev[mod.address] = asArchivistInstance(mod, () => {
313
317
  isArchivistInstance(mod, { log: console });
314
318
  return `Unable to cast resolved module to an archivist: [${mod.address}, ${mod.modName}, ${mod.config.schema})}]`;
315
319
  });
316
320
  return prev;
317
- }, {});
321
+ }, archivistInstancesMap);
318
322
  }
319
323
  };
320
324
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/AbstractArchivist.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { type Hash } from '@xylabs/hex'\nimport { globallyUnique } from '@xylabs/object'\nimport type { Promisable, PromisableArray } from '@xylabs/promise'\nimport { difference } from '@xylabs/set'\nimport type { AccountInstance } from '@xyo-network/account-model'\nimport type {\n ArchivistAllQuery,\n ArchivistClearQuery,\n ArchivistCommitQuery,\n ArchivistDeleteQuery,\n ArchivistGetQuery,\n ArchivistInsertQuery,\n ArchivistInstance,\n ArchivistModuleEventData,\n ArchivistNextOptions,\n ArchivistNextQuery,\n ArchivistParams,\n ArchivistQueries,\n AttachableArchivistInstance,\n} from '@xyo-network/archivist-model'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistCommitQuerySchema,\n ArchivistConfigSchema,\n ArchivistDeleteQuerySchema,\n ArchivistGetQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistNextQuerySchema,\n asArchivistInstance,\n isArchivistInstance,\n} from '@xyo-network/archivist-model'\nimport type { BoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model'\nimport { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AbstractModuleInstance } from '@xyo-network/module-abstract'\nimport type {\n ModuleConfig, ModuleIdentifier, ModuleQueryHandlerResult, ModuleQueryResult,\n} from '@xyo-network/module-model'\nimport { duplicateModules } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type {\n Payload, Schema, WithStorageMeta,\n} from '@xyo-network/payload-model'\n\nconst NOT_IMPLEMENTED = 'Not implemented' as const\n\nexport interface ActionConfig {\n emitEvents?: boolean\n}\n\nexport interface InsertConfig extends ActionConfig {\n writeToParents?: boolean\n}\n\nexport interface ArchivistParentInstances {\n commit?: Record<string, ArchivistInstance>\n read?: Record<string, ArchivistInstance>\n write?: Record<string, ArchivistInstance>\n}\n\nexport abstract class AbstractArchivist<\n TParams extends ArchivistParams = ArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n>\n extends AbstractModuleInstance<TParams, TEventData>\n implements AttachableArchivistInstance<TParams, TEventData, Payload> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ArchivistConfigSchema]\n static override readonly defaultConfigSchema: Schema = ArchivistConfigSchema\n static override readonly uniqueName = globallyUnique('AbstractArchivist', AbstractArchivist, 'xyo')\n\n // override this if a specialized archivist should have a different default next limit\n protected static defaultNextLimitSetting = 100\n\n private _parentArchivists?: ArchivistParentInstances\n\n // do not override this! It is meant to get the this.defaultNextLimitSetting and work if it is overridden\n static get defaultNextLimit() {\n return this.defaultNextLimitSetting\n }\n\n override get queries(): string[] {\n return [ArchivistGetQuerySchema, ...super.queries]\n }\n\n get requireAllParents() {\n return this.config.requireAllParents ?? false\n }\n\n protected get storeParentReads() {\n return !!this.config?.storeParentReads\n }\n\n all(): PromisableArray<WithStorageMeta<Payload>> {\n this._noOverride('all')\n return this.busy(async () => {\n await this.started('throw')\n return PayloadBuilder.omitPrivateStorageMeta(await this.allHandler())\n })\n }\n\n async allQuery(account: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistAllQuery = { schema: ArchivistAllQuerySchema }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n clear(): Promisable<void> {\n this._noOverride('clear')\n return this.busy(async () => {\n await this.started('throw')\n return await this.clearHandler()\n })\n }\n\n async clearQuery(account: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistClearQuery = { schema: ArchivistClearQuerySchema }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n commit(): Promisable<BoundWitness[]> {\n this._noOverride('commit')\n return this.busy(async () => {\n await this.started('throw')\n return await this.commitHandler()\n })\n }\n\n async commitQuery(account: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistCommitQuery = { schema: ArchivistCommitQuerySchema }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n async delete(hashes: Hash[]): Promise<Hash[]> {\n this._noOverride('delete')\n return await this.busy(async () => {\n await this.started('throw')\n return await this.deleteWithConfig(hashes)\n })\n }\n\n async deleteQuery(hashes: Hash[], account?: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistDeleteQuery = { hashes, schema: ArchivistDeleteQuerySchema }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n async get(hashes: Hash[]): Promise<WithStorageMeta<Payload>[]> {\n this._noOverride('get')\n return await this.busy(async () => {\n await this.started('throw')\n return await this.getWithConfig(hashes)\n })\n }\n\n async getQuery(hashes: Hash[], account?: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistGetQuery = { hashes, schema: ArchivistGetQuerySchema }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n async insert(payloads: Payload[]): Promise<WithStorageMeta<Payload>[]> {\n this._noOverride('insert')\n return await this.busy(async () => {\n await this.started('throw')\n return await this.insertWithConfig(PayloadBuilder.omitStorageMeta(payloads))\n })\n }\n\n async insertQuery(payloads: Payload[], account?: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistInsertQuery = { schema: ArchivistInsertQuerySchema }\n return await this.sendQueryRaw(queryPayload, payloads, account)\n }\n\n async next(options?: ArchivistNextOptions): Promise<WithStorageMeta<Payload>[]> {\n this._noOverride('next')\n return await this.busy(async () => {\n await this.started('throw')\n const { limit = AbstractArchivist.defaultNextLimit, ...otherOptions } = options ?? {}\n return await this.nextWithConfig({ limit, ...otherOptions })\n })\n }\n\n async nextQuery(options?: ArchivistNextOptions, account?: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistNextQuery = { schema: ArchivistNextQuerySchema, ...options }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n protected allHandler(): PromisableArray<WithStorageMeta<Payload>> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected clearHandler(): Promisable<void> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected commitHandler(): Promisable<BoundWitness[]> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected deleteHandler(_hashes: Hash[]): PromisableArray<Hash> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected async deleteWithConfig(hashes: Hash[], config?: ActionConfig): Promise<Hash[]> {\n const emitEvents = config?.emitEvents ?? true\n\n const deletedHashes = await this.deleteHandler(hashes)\n\n if (emitEvents) {\n await this.emit('deleted', { hashes: deletedHashes, mod: this })\n }\n\n return deletedHashes\n }\n\n protected async getFromParent(hashes: Hash[], archivist: ArchivistInstance): Promise<[WithStorageMeta<Payload>[], Hash[]]> {\n const foundPairs = (await PayloadBuilder.dataHashPairs(await archivist.get(hashes))).filter(([, hash]) => {\n const askedFor = hashes.includes(hash)\n if (!askedFor) {\n console.warn(`Parent returned payload with hash not asked for: ${hash}`)\n // throw Error(`Parent returned payload with hash not asked for: ${hash}`)\n }\n return askedFor\n })\n\n const foundHashes = new Set(foundPairs.map(([, hash]) => hash))\n const foundPayloads = foundPairs.map(([payload]) => payload)\n\n const notfound = hashes.filter(hash => !foundHashes.has(hash))\n return [foundPayloads, notfound]\n }\n\n protected async getFromParents(hashes: Hash[]): Promise<[WithStorageMeta<Payload>[], Hash[]]> {\n const parents = Object.values((await this.parentArchivists())?.read ?? {})\n let remainingHashes = [...hashes]\n let parentIndex = 0\n let result: WithStorageMeta<Payload>[] = []\n\n // NOTE: intentionally doing this serially\n while (parentIndex < parents.length && remainingHashes.length > 0) {\n const [found, notfound] = await this.getFromParent(remainingHashes, parents[parentIndex])\n result = [...result, ...found]\n remainingHashes = notfound\n parentIndex++\n }\n return [result, remainingHashes]\n }\n\n protected getHandler(_hashes: Hash[]): Promisable<WithStorageMeta<Payload>[]> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected async getWithConfig(hashes: Hash[], _config?: InsertConfig): Promise<WithStorageMeta<Payload>[]> {\n // Filter out duplicates\n const requestedHashes = new Set(hashes)\n\n // Attempt to find the payloads in the store\n const gotten = await this.getHandler([...requestedHashes])\n\n // Do not just blindly return what the archivist told us but\n // ensure to only return requested payloads and keep track of\n // the ones it did not find so we can ask the parents.\n const foundPayloads: WithStorageMeta<Payload>[] = []\n const foundHashes = new Set<Hash>()\n\n // NOTE: We are iterating over the returned result from the archivist\n // (not the array of hashes passed in) to preserve the natural order of the\n // hashes as returned by the archivist as that should loosely\n // correspond to the order when iterated and the symmetry will\n // be helpful for debugging\n for (const payload of gotten) {\n // Compute the hashes for this payload\n const map = await PayloadBuilder.toAllHashMap([payload])\n for (const [key, payload] of Object.entries(map)) {\n let requestedPayloadFound = false\n const hash = key as Hash // NOTE: Required cast as Object.entries always returns string keys\n // If this hash was requested\n if (\n requestedHashes.has(hash) // Indicate that we found it (but do not insert it yet). Since\n // one payload could satisfy two requested hashes (vit its dataHash\n // & rootHash) we only want to insert that payload once but we want\n // to keep track of all the hashes it satisfies so we can ask th\n // parents for the ones we did not find\n && !foundHashes.has(hash)\n ) {\n requestedPayloadFound = true\n // Add it to the list of found hashes\n foundHashes.add(hash)\n }\n if (requestedPayloadFound) foundPayloads.push(payload)\n }\n }\n // For all the hashes we did not find, ask the parents\n const notFoundHashes = [...difference(requestedHashes, foundHashes)]\n const [parentFoundPayloads] = await this.getFromParents(notFoundHashes)\n\n if (this.storeParentReads) {\n await this.insertWithConfig(parentFoundPayloads)\n }\n return PayloadBuilder.omitPrivateStorageMeta([...foundPayloads, ...parentFoundPayloads]).sort(PayloadBuilder.compareStorageMeta)\n }\n\n protected insertHandler(_payloads: WithStorageMeta<Payload>[]): Promisable<WithStorageMeta<Payload>[]> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected async insertQueryHandler<T extends QueryBoundWitnessWrapper = QueryBoundWitnessWrapper>(query: T, payloads?: Payload[]) {\n assertEx(payloads, () => `Missing payloads: ${JSON.stringify(query.payload, null, 2)}`)\n const resolvedPayloads = await PayloadBuilder.filterIncludeByEitherHash(payloads, query.payloadHashes)\n assertEx(\n resolvedPayloads.length === query.payloadHashes.length,\n () => `Could not find some passed hashes [${resolvedPayloads.length} != ${query.payloadHashes.length}]`,\n )\n const queryPayload = await query.getQuery()\n const payloadsWithoutQuery = await PayloadBuilder.filterExclude(resolvedPayloads, await PayloadBuilder.dataHash(queryPayload))\n const result = await this.insertWithConfig(payloadsWithoutQuery)\n return result\n }\n\n protected async insertWithConfig(payloads: Payload[], config?: InsertConfig): Promise<WithStorageMeta<Payload>[]> {\n const emitEvents = config?.emitEvents ?? true\n const writeToParents = config?.writeToParents ?? true\n\n // remove the existing payloads\n const withStorageMeta = await PayloadBuilder.addStorageMeta(payloads)\n const hashes = withStorageMeta.map(p => p._hash)\n const existingPayloads = await this.getWithConfig(hashes)\n const existingHashes = new Set(existingPayloads.map(p => p._hash))\n const payloadsToInsert = withStorageMeta.filter(p => !existingHashes.has(p._hash))\n\n const insertedPayloads = await this.insertHandler(payloadsToInsert)\n\n if (writeToParents) {\n await this.writeToParents(insertedPayloads)\n }\n if (emitEvents) {\n await this.emit('inserted', { mod: this, payloads: insertedPayloads })\n }\n\n return PayloadBuilder.omitPrivateStorageMeta(insertedPayloads)\n }\n\n protected nextHandler(_options?: ArchivistNextOptions): Promisable<WithStorageMeta<Payload>[]> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected async nextWithConfig(options?: ArchivistNextOptions, _config?: InsertConfig): Promise<WithStorageMeta<Payload>[]> {\n const foundPayloads = await this.nextHandler(options)\n return PayloadBuilder.omitPrivateStorageMeta(foundPayloads)\n }\n\n protected async parentArchivists() {\n this._parentArchivists = this._parentArchivists ?? {\n commit: await this.resolveArchivists(this.config?.parents?.commit),\n read: await this.resolveArchivists(this.config?.parents?.read),\n write: await this.resolveArchivists(this.config?.parents?.write),\n }\n return assertEx(this._parentArchivists)\n }\n\n protected override async queryHandler<T extends QueryBoundWitness = QueryBoundWitness, TConfig extends ModuleConfig = ModuleConfig>(\n query: T,\n payloads: Payload[],\n queryConfig?: TConfig,\n ): Promise<ModuleQueryHandlerResult> {\n const sanitizedQuery = PayloadBuilder.omitStorageMeta(query)\n const sanitizedPayloads = PayloadBuilder.omitStorageMeta(payloads)\n const wrappedQuery = QueryBoundWitnessWrapper.parseQuery<ArchivistQueries>(sanitizedQuery, sanitizedPayloads)\n const queryPayload = await wrappedQuery.getQuery()\n assertEx(await this.queryable(sanitizedQuery, sanitizedPayloads, queryConfig))\n const resultPayloads: Payload[] = []\n\n switch (queryPayload.schema) {\n case ArchivistAllQuerySchema: {\n resultPayloads.push(...(await this.allHandler()))\n break\n }\n case ArchivistClearQuerySchema: {\n await this.clearHandler()\n break\n }\n case ArchivistCommitQuerySchema: {\n resultPayloads.push(...(await this.commitHandler()))\n break\n }\n case ArchivistDeleteQuerySchema: {\n const resultPayload: ArchivistDeleteQuery = {\n hashes: [...(await this.deleteWithConfig(queryPayload.hashes))],\n schema: ArchivistDeleteQuerySchema,\n }\n resultPayloads.push(await PayloadBuilder.addStorageMeta(resultPayload))\n break\n }\n case ArchivistGetQuerySchema: {\n resultPayloads.push(...(await this.getWithConfig(queryPayload.hashes ?? [])))\n break\n }\n case ArchivistInsertQuerySchema: {\n resultPayloads.push(...(await this.insertQueryHandler(wrappedQuery, sanitizedPayloads)))\n break\n }\n case ArchivistNextQuerySchema: {\n resultPayloads.push(...(await this.nextHandler(queryPayload)))\n break\n }\n default: {\n const result = await super.queryHandler(sanitizedQuery, sanitizedPayloads)\n if (this.config.storeQueries) {\n await this.insertWithConfig([sanitizedQuery])\n }\n return PayloadBuilder.omitPrivateStorageMeta(result)\n }\n }\n if (this.config.storeQueries) {\n await this.insertWithConfig([sanitizedQuery])\n }\n return PayloadBuilder.omitPrivateStorageMeta(resultPayloads)\n }\n\n protected async writeToParent(parent: ArchivistInstance, payloads: Payload[]): Promise<Payload[]> {\n return await parent.insert(PayloadBuilder.omitStorageMeta(payloads))\n }\n\n protected async writeToParents(payloads: Payload[]): Promise<Payload[]> {\n const parents = await this.parentArchivists()\n return (\n await Promise.all(\n Object.values(parents.write ?? {}).map(async (parent) => {\n return parent ? await this.writeToParent(parent, payloads) : undefined\n }),\n )\n ).filter(exists).flat()\n }\n\n private async resolveArchivists(archivists: ModuleIdentifier[] = []) {\n const archivistModules = (await Promise.all(archivists.map(archivist => this.resolve(archivist)))).filter(exists).filter(duplicateModules)\n\n assertEx(\n !this.requireAllParents || archivistModules.length === archivists.length,\n () =>\n `Failed to find some archivists (set allRequired to false if ok): [${archivists.filter(archivist =>\n archivistModules.map(mod => !(mod.address === archivist || mod.modName === archivist)))}]`,\n )\n\n // eslint-disable-next-line unicorn/no-array-reduce\n return archivistModules.reduce<Record<string, ArchivistInstance>>((prev, mod) => {\n prev[mod.address] = asArchivistInstance(mod, () => {\n isArchivistInstance(mod, { log: console })\n return `Unable to cast resolved module to an archivist: [${mod.address}, ${mod.modName}, ${mod.config.schema})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K,IAAI,OAAO,MAAM;AAAA,MAC9G,CAAC;AAED,aAAO;AAAA,IACT,GAAG,CAAC,CAAC;AAAA,EACP;AACF;","names":["payload"]}
1
+ {"version":3,"sources":["../../src/AbstractArchivist.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport type { Address, Hash } from '@xylabs/hex'\nimport { globallyUnique } from '@xylabs/object'\nimport type { Promisable, PromisableArray } from '@xylabs/promise'\nimport { difference } from '@xylabs/set'\nimport type { AccountInstance } from '@xyo-network/account-model'\nimport type {\n ArchivistAllQuery,\n ArchivistClearQuery,\n ArchivistCommitQuery,\n ArchivistDeleteQuery,\n ArchivistGetQuery,\n ArchivistInsertQuery,\n ArchivistInstance,\n ArchivistModuleEventData,\n ArchivistNextOptions,\n ArchivistNextQuery,\n ArchivistParams,\n ArchivistQueries,\n AttachableArchivistInstance,\n ReadArchivist,\n} from '@xyo-network/archivist-model'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistCommitQuerySchema,\n ArchivistConfigSchema,\n ArchivistDeleteQuerySchema,\n ArchivistGetQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistNextQuerySchema,\n asArchivistInstance,\n isArchivistInstance,\n} from '@xyo-network/archivist-model'\nimport type { BoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model'\nimport { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AbstractModuleInstance } from '@xyo-network/module-abstract'\nimport type {\n ModuleConfig, ModuleIdentifier, ModuleQueryHandlerResult, ModuleQueryResult,\n} from '@xyo-network/module-model'\nimport { duplicateModules } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type {\n Payload, Schema, WithStorageMeta,\n} from '@xyo-network/payload-model'\n\nconst NOT_IMPLEMENTED = 'Not implemented' as const\n\nexport interface ActionConfig {\n emitEvents?: boolean\n}\n\nexport interface InsertConfig extends ActionConfig {\n writeToParents?: boolean\n}\n\ninterface ArchivistParentInstanceMap {\n commit?: Record<string, ArchivistInstance>\n read?: Record<string, ArchivistInstance>\n write?: Record<string, ArchivistInstance>\n}\n\nexport abstract class AbstractArchivist<\n TParams extends ArchivistParams = ArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n>\n extends AbstractModuleInstance<TParams, TEventData>\n implements AttachableArchivistInstance<TParams, TEventData, Payload> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ArchivistConfigSchema]\n static override readonly defaultConfigSchema: Schema = ArchivistConfigSchema\n static override readonly uniqueName = globallyUnique('AbstractArchivist', AbstractArchivist, 'xyo')\n\n // override this if a specialized archivist should have a different default next limit\n protected static defaultNextLimitSetting = 100\n\n private _parentArchivists?: ArchivistParentInstanceMap\n\n // do not override this! It is meant to get the this.defaultNextLimitSetting and work if it is overridden\n static get defaultNextLimit() {\n return this.defaultNextLimitSetting\n }\n\n override get queries(): string[] {\n return [ArchivistGetQuerySchema, ...super.queries]\n }\n\n get requireAllParents() {\n return this.config.requireAllParents ?? false\n }\n\n protected get storeParentReads() {\n return !!this.config?.storeParentReads\n }\n\n all(): PromisableArray<WithStorageMeta<Payload>> {\n this._noOverride('all')\n return this.busy(async () => {\n await this.started('throw')\n return PayloadBuilder.omitPrivateStorageMeta(await this.allHandler())\n })\n }\n\n async allQuery(account: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistAllQuery = { schema: ArchivistAllQuerySchema }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n clear(): Promisable<void> {\n this._noOverride('clear')\n return this.busy(async () => {\n await this.started('throw')\n return await this.clearHandler()\n })\n }\n\n async clearQuery(account: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistClearQuery = { schema: ArchivistClearQuerySchema }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n commit(): Promisable<BoundWitness[]> {\n this._noOverride('commit')\n return this.busy(async () => {\n await this.started('throw')\n return await this.commitHandler()\n })\n }\n\n async commitQuery(account: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistCommitQuery = { schema: ArchivistCommitQuerySchema }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n async delete(hashes: Hash[]): Promise<Hash[]> {\n this._noOverride('delete')\n return await this.busy(async () => {\n await this.started('throw')\n return await this.deleteWithConfig(hashes)\n })\n }\n\n async deleteQuery(hashes: Hash[], account?: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistDeleteQuery = { hashes, schema: ArchivistDeleteQuerySchema }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n async get(hashes: Hash[]): Promise<WithStorageMeta<Payload>[]> {\n this._noOverride('get')\n return await this.busy(async () => {\n await this.started('throw')\n return await this.getWithConfig(hashes)\n })\n }\n\n async getQuery(hashes: Hash[], account?: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistGetQuery = { hashes, schema: ArchivistGetQuerySchema }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n async insert(payloads: Payload[]): Promise<WithStorageMeta<Payload>[]> {\n this._noOverride('insert')\n return await this.busy(async () => {\n await this.started('throw')\n return await this.insertWithConfig(PayloadBuilder.omitStorageMeta(payloads))\n })\n }\n\n async insertQuery(payloads: Payload[], account?: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistInsertQuery = { schema: ArchivistInsertQuerySchema }\n return await this.sendQueryRaw(queryPayload, payloads, account)\n }\n\n async next(options?: ArchivistNextOptions): Promise<WithStorageMeta<Payload>[]> {\n this._noOverride('next')\n return await this.busy(async () => {\n await this.started('throw')\n const { limit = AbstractArchivist.defaultNextLimit, ...otherOptions } = options ?? {}\n return await this.nextWithConfig({ limit, ...otherOptions })\n })\n }\n\n async nextQuery(options?: ArchivistNextOptions, account?: AccountInstance): Promise<ModuleQueryResult> {\n const queryPayload: ArchivistNextQuery = { schema: ArchivistNextQuerySchema, ...options }\n return await this.sendQueryRaw(queryPayload, undefined, account)\n }\n\n protected allHandler(): PromisableArray<WithStorageMeta<Payload>> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected clearHandler(): Promisable<void> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected commitHandler(): Promisable<BoundWitness[]> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected deleteHandler(_hashes: Hash[]): PromisableArray<Hash> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected async deleteWithConfig(hashes: Hash[], config?: ActionConfig): Promise<Hash[]> {\n const emitEvents = config?.emitEvents ?? true\n\n const deletedHashes = await this.deleteHandler(hashes)\n\n if (emitEvents) {\n await this.emit('deleted', { hashes: deletedHashes, mod: this })\n }\n\n return deletedHashes\n }\n\n protected async getFromParent(hashes: Hash[], archivist: ReadArchivist): Promise<[WithStorageMeta<Payload>[], Hash[]]> {\n const foundPairs = (await PayloadBuilder.dataHashPairs(await archivist.get(hashes))).filter(([, hash]) => {\n const askedFor = hashes.includes(hash)\n if (!askedFor) {\n console.warn(`Parent returned payload with hash not asked for: ${hash}`)\n // throw Error(`Parent returned payload with hash not asked for: ${hash}`)\n }\n return askedFor\n })\n\n const foundHashes = new Set(foundPairs.map(([, hash]) => hash))\n const foundPayloads = foundPairs.map(([payload]) => payload)\n\n const notfound = hashes.filter(hash => !foundHashes.has(hash))\n return [foundPayloads, notfound]\n }\n\n protected async getFromParents(hashes: Hash[]): Promise<[WithStorageMeta<Payload>[], Hash[]]> {\n const parents = Object.values((await this.parentArchivists())?.read ?? {})\n let remainingHashes = [...hashes]\n let parentIndex = 0\n let result: WithStorageMeta<Payload>[] = []\n\n // NOTE: intentionally doing this serially\n while (parentIndex < parents.length && remainingHashes.length > 0) {\n const [found, notfound] = await this.getFromParent(remainingHashes, parents[parentIndex])\n result = [...result, ...found]\n remainingHashes = notfound\n parentIndex++\n }\n return [result, remainingHashes]\n }\n\n protected getHandler(_hashes: Hash[]): Promisable<WithStorageMeta<Payload>[]> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected async getWithConfig(hashes: Hash[], _config?: InsertConfig): Promise<WithStorageMeta<Payload>[]> {\n // Filter out duplicates\n const requestedHashes = new Set(hashes)\n\n // Attempt to find the payloads in the store\n const gotten = await this.getHandler([...requestedHashes])\n\n // Do not just blindly return what the archivist told us but\n // ensure to only return requested payloads and keep track of\n // the ones it did not find so we can ask the parents.\n const foundPayloads: WithStorageMeta<Payload>[] = []\n const foundHashes = new Set<Hash>()\n\n // NOTE: We are iterating over the returned result from the archivist\n // (not the array of hashes passed in) to preserve the natural order of the\n // hashes as returned by the archivist as that should loosely\n // correspond to the order when iterated and the symmetry will\n // be helpful for debugging\n for (const payload of gotten) {\n // Compute the hashes for this payload\n const map = await PayloadBuilder.toAllHashMap([payload])\n for (const [key, payload] of Object.entries(map)) {\n let requestedPayloadFound = false\n const hash = key as Hash // NOTE: Required cast as Object.entries always returns string keys\n // If this hash was requested\n if (\n requestedHashes.has(hash) // Indicate that we found it (but do not insert it yet). Since\n // one payload could satisfy two requested hashes (vit its dataHash\n // & rootHash) we only want to insert that payload once but we want\n // to keep track of all the hashes it satisfies so we can ask th\n // parents for the ones we did not find\n && !foundHashes.has(hash)\n ) {\n requestedPayloadFound = true\n // Add it to the list of found hashes\n foundHashes.add(hash)\n }\n if (requestedPayloadFound) foundPayloads.push(payload)\n }\n }\n // For all the hashes we did not find, ask the parents\n const notFoundHashes = [...difference(requestedHashes, foundHashes)]\n const [parentFoundPayloads] = await this.getFromParents(notFoundHashes)\n\n if (this.storeParentReads) {\n await this.insertWithConfig(parentFoundPayloads)\n }\n return PayloadBuilder.omitPrivateStorageMeta([...foundPayloads, ...parentFoundPayloads]).sort(PayloadBuilder.compareStorageMeta)\n }\n\n protected insertHandler(_payloads: WithStorageMeta<Payload>[]): Promisable<WithStorageMeta<Payload>[]> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected async insertQueryHandler<T extends QueryBoundWitnessWrapper = QueryBoundWitnessWrapper>(query: T, payloads?: Payload[]) {\n assertEx(payloads, () => `Missing payloads: ${JSON.stringify(query.payload, null, 2)}`)\n const resolvedPayloads = await PayloadBuilder.filterIncludeByEitherHash(payloads, query.payloadHashes)\n assertEx(\n resolvedPayloads.length === query.payloadHashes.length,\n () => `Could not find some passed hashes [${resolvedPayloads.length} != ${query.payloadHashes.length}]`,\n )\n const queryPayload = await query.getQuery()\n const payloadsWithoutQuery = await PayloadBuilder.filterExclude(resolvedPayloads, await PayloadBuilder.dataHash(queryPayload))\n const result = await this.insertWithConfig(payloadsWithoutQuery)\n return result\n }\n\n protected async insertWithConfig(payloads: Payload[], config?: InsertConfig): Promise<WithStorageMeta<Payload>[]> {\n const emitEvents = config?.emitEvents ?? true\n const writeToParents = config?.writeToParents ?? true\n\n // remove the existing payloads\n const withStorageMeta = await PayloadBuilder.addStorageMeta(payloads)\n const hashes = withStorageMeta.map(p => p._hash)\n const existingPayloads = await this.getWithConfig(hashes)\n const existingHashes = new Set(existingPayloads.map(p => p._hash))\n const payloadsToInsert = withStorageMeta.filter(p => !existingHashes.has(p._hash))\n\n const insertedPayloads = await this.insertHandler(payloadsToInsert)\n\n if (writeToParents) {\n await this.writeToParents(insertedPayloads)\n }\n if (emitEvents) {\n await this.emit('inserted', { mod: this, payloads: insertedPayloads })\n }\n\n return PayloadBuilder.omitPrivateStorageMeta(insertedPayloads)\n }\n\n protected nextHandler(_options?: ArchivistNextOptions): Promisable<WithStorageMeta<Payload>[]> {\n throw new Error(NOT_IMPLEMENTED)\n }\n\n protected async nextWithConfig(options?: ArchivistNextOptions, _config?: InsertConfig): Promise<WithStorageMeta<Payload>[]> {\n const foundPayloads = await this.nextHandler(options)\n return PayloadBuilder.omitPrivateStorageMeta(foundPayloads)\n }\n\n protected async parentArchivists() {\n this._parentArchivists = this._parentArchivists ?? {\n commit: { ...await this.resolveArchivists(this.config?.parents?.commit, this.params.parents?.commit) },\n read: { ...await this.resolveArchivists(this.config?.parents?.read) },\n write: { ...await this.resolveArchivists(this.config?.parents?.write) },\n }\n return assertEx(this._parentArchivists)\n }\n\n protected override async queryHandler<T extends QueryBoundWitness = QueryBoundWitness, TConfig extends ModuleConfig = ModuleConfig>(\n query: T,\n payloads: Payload[],\n queryConfig?: TConfig,\n ): Promise<ModuleQueryHandlerResult> {\n const sanitizedQuery = PayloadBuilder.omitStorageMeta(query)\n const sanitizedPayloads = PayloadBuilder.omitStorageMeta(payloads)\n const wrappedQuery = QueryBoundWitnessWrapper.parseQuery<ArchivistQueries>(sanitizedQuery, sanitizedPayloads)\n const queryPayload = await wrappedQuery.getQuery()\n assertEx(await this.queryable(sanitizedQuery, sanitizedPayloads, queryConfig))\n const resultPayloads: Payload[] = []\n\n switch (queryPayload.schema) {\n case ArchivistAllQuerySchema: {\n resultPayloads.push(...(await this.allHandler()))\n break\n }\n case ArchivistClearQuerySchema: {\n await this.clearHandler()\n break\n }\n case ArchivistCommitQuerySchema: {\n resultPayloads.push(...(await this.commitHandler()))\n break\n }\n case ArchivistDeleteQuerySchema: {\n const resultPayload: ArchivistDeleteQuery = {\n hashes: [...(await this.deleteWithConfig(queryPayload.hashes))],\n schema: ArchivistDeleteQuerySchema,\n }\n resultPayloads.push(await PayloadBuilder.addStorageMeta(resultPayload))\n break\n }\n case ArchivistGetQuerySchema: {\n resultPayloads.push(...(await this.getWithConfig(queryPayload.hashes ?? [])))\n break\n }\n case ArchivistInsertQuerySchema: {\n resultPayloads.push(...(await this.insertQueryHandler(wrappedQuery, sanitizedPayloads)))\n break\n }\n case ArchivistNextQuerySchema: {\n resultPayloads.push(...(await this.nextHandler(queryPayload)))\n break\n }\n default: {\n const result = await super.queryHandler(sanitizedQuery, sanitizedPayloads)\n if (this.config.storeQueries) {\n await this.insertWithConfig([sanitizedQuery])\n }\n return PayloadBuilder.omitPrivateStorageMeta(result)\n }\n }\n if (this.config.storeQueries) {\n await this.insertWithConfig([sanitizedQuery])\n }\n return PayloadBuilder.omitPrivateStorageMeta(resultPayloads)\n }\n\n protected async writeToParent(parent: ArchivistInstance, payloads: Payload[]): Promise<Payload[]> {\n return await parent.insert(PayloadBuilder.omitStorageMeta(payloads))\n }\n\n protected async writeToParents(payloads: Payload[]): Promise<Payload[]> {\n const parents = await this.parentArchivists()\n return (\n await Promise.all(\n Object.values(parents.write ?? {}).map(async (parent) => {\n return parent ? await this.writeToParent(parent, payloads) : undefined\n }),\n )\n ).filter(exists).flat()\n }\n\n private async resolveArchivists(archivists: ModuleIdentifier[] = [], archivistInstances?: ArchivistInstance[]) {\n const archivistModules = (await Promise.all(archivists.map(archivist => this.resolve(archivist)))).filter(exists).filter(duplicateModules)\n\n assertEx(\n !this.requireAllParents || archivistModules.length === archivists.length,\n () =>\n `Failed to find some archivists (set allRequired to false if ok): [${archivists.filter(archivist =>\n archivistModules.map(mod => !(mod.address === archivist || mod.modName === archivist)))}]`,\n )\n\n const archivistInstancesMap: Record<Address, ArchivistInstance> = {}\n for (let archivistInstance of archivistInstances ?? []) {\n archivistInstancesMap[archivistInstance.address] = archivistInstance\n }\n\n // eslint-disable-next-line unicorn/no-array-reduce\n return archivistModules.reduce<Record<Address, ArchivistInstance>>((prev, mod) => {\n prev[mod.address] = asArchivistInstance(mod, () => {\n isArchivistInstance(mod, { log: console })\n return `Unable to cast resolved module to an archivist: [${mod.address}, ${mod.modName}, ${mod.config.schema})}]`\n })\n\n return prev\n }, archivistInstancesMap)\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEvB,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB;AAkB3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,gCAAgC;AACzC,SAAS,8BAA8B;AAIvC,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAK/B,IAAM,kBAAkB;AAgBjB,IAAe,oBAAf,MAAe,2BAIZ,uBAC6D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"version": "3.9.2",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -35,18 +35,18 @@
35
35
  "@xylabs/object": "^4.5.1",
36
36
  "@xylabs/promise": "^4.5.1",
37
37
  "@xylabs/set": "^4.5.1",
38
- "@xyo-network/account-model": "^3.9.0",
39
- "@xyo-network/archivist-model": "^3.9.0",
40
- "@xyo-network/boundwitness-model": "^3.9.0",
41
- "@xyo-network/boundwitness-wrapper": "^3.9.0",
42
- "@xyo-network/module-abstract": "^3.9.0",
43
- "@xyo-network/module-model": "^3.9.0",
44
- "@xyo-network/payload-builder": "^3.9.0",
45
- "@xyo-network/payload-model": "^3.9.0"
38
+ "@xyo-network/account-model": "^3.9.2",
39
+ "@xyo-network/archivist-model": "^3.9.2",
40
+ "@xyo-network/boundwitness-model": "^3.9.2",
41
+ "@xyo-network/boundwitness-wrapper": "^3.9.2",
42
+ "@xyo-network/module-abstract": "^3.9.2",
43
+ "@xyo-network/module-model": "^3.9.2",
44
+ "@xyo-network/payload-builder": "^3.9.2",
45
+ "@xyo-network/payload-model": "^3.9.2"
46
46
  },
47
47
  "devDependencies": {
48
- "@xylabs/ts-scripts-yarn3": "^5.0.23",
49
- "@xylabs/tsconfig": "^5.0.23",
48
+ "@xylabs/ts-scripts-yarn3": "^5.0.24",
49
+ "@xylabs/tsconfig": "^5.0.24",
50
50
  "typescript": "^5.7.3"
51
51
  },
52
52
  "publishConfig": {
@@ -1,6 +1,6 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
2
  import { exists } from '@xylabs/exists'
3
- import { type Hash } from '@xylabs/hex'
3
+ import type { Address, Hash } from '@xylabs/hex'
4
4
  import { globallyUnique } from '@xylabs/object'
5
5
  import type { Promisable, PromisableArray } from '@xylabs/promise'
6
6
  import { difference } from '@xylabs/set'
@@ -19,6 +19,7 @@ import type {
19
19
  ArchivistParams,
20
20
  ArchivistQueries,
21
21
  AttachableArchivistInstance,
22
+ ReadArchivist,
22
23
  } from '@xyo-network/archivist-model'
23
24
  import {
24
25
  ArchivistAllQuerySchema,
@@ -54,7 +55,7 @@ export interface InsertConfig extends ActionConfig {
54
55
  writeToParents?: boolean
55
56
  }
56
57
 
57
- export interface ArchivistParentInstances {
58
+ interface ArchivistParentInstanceMap {
58
59
  commit?: Record<string, ArchivistInstance>
59
60
  read?: Record<string, ArchivistInstance>
60
61
  write?: Record<string, ArchivistInstance>
@@ -73,7 +74,7 @@ export abstract class AbstractArchivist<
73
74
  // override this if a specialized archivist should have a different default next limit
74
75
  protected static defaultNextLimitSetting = 100
75
76
 
76
- private _parentArchivists?: ArchivistParentInstances
77
+ private _parentArchivists?: ArchivistParentInstanceMap
77
78
 
78
79
  // do not override this! It is meant to get the this.defaultNextLimitSetting and work if it is overridden
79
80
  static get defaultNextLimit() {
@@ -212,7 +213,7 @@ export abstract class AbstractArchivist<
212
213
  return deletedHashes
213
214
  }
214
215
 
215
- protected async getFromParent(hashes: Hash[], archivist: ArchivistInstance): Promise<[WithStorageMeta<Payload>[], Hash[]]> {
216
+ protected async getFromParent(hashes: Hash[], archivist: ReadArchivist): Promise<[WithStorageMeta<Payload>[], Hash[]]> {
216
217
  const foundPairs = (await PayloadBuilder.dataHashPairs(await archivist.get(hashes))).filter(([, hash]) => {
217
218
  const askedFor = hashes.includes(hash)
218
219
  if (!askedFor) {
@@ -350,9 +351,9 @@ export abstract class AbstractArchivist<
350
351
 
351
352
  protected async parentArchivists() {
352
353
  this._parentArchivists = this._parentArchivists ?? {
353
- commit: await this.resolveArchivists(this.config?.parents?.commit),
354
- read: await this.resolveArchivists(this.config?.parents?.read),
355
- write: await this.resolveArchivists(this.config?.parents?.write),
354
+ commit: { ...await this.resolveArchivists(this.config?.parents?.commit, this.params.parents?.commit) },
355
+ read: { ...await this.resolveArchivists(this.config?.parents?.read) },
356
+ write: { ...await this.resolveArchivists(this.config?.parents?.write) },
356
357
  }
357
358
  return assertEx(this._parentArchivists)
358
359
  }
@@ -431,7 +432,7 @@ export abstract class AbstractArchivist<
431
432
  ).filter(exists).flat()
432
433
  }
433
434
 
434
- private async resolveArchivists(archivists: ModuleIdentifier[] = []) {
435
+ private async resolveArchivists(archivists: ModuleIdentifier[] = [], archivistInstances?: ArchivistInstance[]) {
435
436
  const archivistModules = (await Promise.all(archivists.map(archivist => this.resolve(archivist)))).filter(exists).filter(duplicateModules)
436
437
 
437
438
  assertEx(
@@ -441,14 +442,19 @@ export abstract class AbstractArchivist<
441
442
  archivistModules.map(mod => !(mod.address === archivist || mod.modName === archivist)))}]`,
442
443
  )
443
444
 
445
+ const archivistInstancesMap: Record<Address, ArchivistInstance> = {}
446
+ for (let archivistInstance of archivistInstances ?? []) {
447
+ archivistInstancesMap[archivistInstance.address] = archivistInstance
448
+ }
449
+
444
450
  // eslint-disable-next-line unicorn/no-array-reduce
445
- return archivistModules.reduce<Record<string, ArchivistInstance>>((prev, mod) => {
451
+ return archivistModules.reduce<Record<Address, ArchivistInstance>>((prev, mod) => {
446
452
  prev[mod.address] = asArchivistInstance(mod, () => {
447
453
  isArchivistInstance(mod, { log: console })
448
454
  return `Unable to cast resolved module to an archivist: [${mod.address}, ${mod.modName}, ${mod.config.schema})}]`
449
455
  })
450
456
 
451
457
  return prev
452
- }, {})
458
+ }, archivistInstancesMap)
453
459
  }
454
460
  }