From 908d0f358743dd531c81ae492525a420139cfd57 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Tue, 17 Dec 2024 19:50:21 -0600 Subject: [PATCH] Add as identity function --- .../temporal/packages/memory/src/spec/Diviner.spec.ts | 11 ++++++----- .../module/packages/model/src/Payload/ModuleState.ts | 3 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/modules/packages/diviner/packages/indexing/packages/temporal/packages/memory/src/spec/Diviner.spec.ts b/packages/modules/packages/diviner/packages/indexing/packages/temporal/packages/memory/src/spec/Diviner.spec.ts index 0cf6029967..9ed0280949 100644 --- a/packages/modules/packages/diviner/packages/indexing/packages/temporal/packages/memory/src/spec/Diviner.spec.ts +++ b/packages/modules/packages/diviner/packages/indexing/packages/temporal/packages/memory/src/spec/Diviner.spec.ts @@ -1,12 +1,13 @@ import '@xylabs/vitest-extended' +import { filterAs } from '@xylabs/array' import { assertEx } from '@xylabs/assert' import { delay } from '@xylabs/delay' import { HDWallet } from '@xyo-network/account' import type { MemoryArchivist } from '@xyo-network/archivist-memory' import { asArchivistInstance } from '@xyo-network/archivist-model' import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder' -import { isBoundWitness } from '@xyo-network/boundwitness-model' +import { asBoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model' import { asDivinerInstance } from '@xyo-network/diviner-model' import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model' import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model' @@ -15,7 +16,7 @@ import type { PackageManifestPayload } from '@xyo-network/manifest' import { ManifestWrapper } from '@xyo-network/manifest' import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator' import type { Labels } from '@xyo-network/module-model' -import { isModuleState } from '@xyo-network/module-model' +import { asModuleState, isModuleState } from '@xyo-network/module-model' import type { MemoryNode } from '@xyo-network/node-memory' import { PayloadBuilder } from '@xyo-network/payload-builder' import type { Payload } from '@xyo-network/payload-model' @@ -145,7 +146,7 @@ describe.skip('TemporalIndexingDiviner', () => { }) it('has expected bound witnesses', async () => { const payloads = await stateArchivist.all() - const stateBoundWitnesses = payloads.filter(isBoundWitness) + const stateBoundWitnesses = filterAs(payloads, asBoundWitness) expect(stateBoundWitnesses).toBeArrayOfSize(2) for (const stateBoundWitness of stateBoundWitnesses) { expect(stateBoundWitness).toBeObject() @@ -155,7 +156,7 @@ describe.skip('TemporalIndexingDiviner', () => { }) it('has expected state', async () => { const payloads = await stateArchivist.all() - const statePayloads = payloads.filter(isModuleState) + const statePayloads = filterAs(payloads, asModuleState) expect(statePayloads).toBeArrayOfSize(2) expect(statePayloads.at(-1)).toBeObject() const statePayload = assertEx(statePayloads.at(-1)) @@ -172,7 +173,7 @@ describe.skip('TemporalIndexingDiviner', () => { // NOTE: We're not signing indexes for performance reasons it.skip('has expected bound witnesses', async () => { const payloads = await indexArchivist.all() - const indexBoundWitnesses = payloads.filter(isBoundWitness) + const indexBoundWitnesses = filterAs(payloads, asBoundWitness) expect(indexBoundWitnesses).toBeArrayOfSize(1) const indexBoundWitness = indexBoundWitnesses[0] expect(indexBoundWitness).toBeObject() diff --git a/packages/modules/packages/module/packages/model/src/Payload/ModuleState.ts b/packages/modules/packages/module/packages/model/src/Payload/ModuleState.ts index c4ee4e8211..5f2f529ac0 100644 --- a/packages/modules/packages/module/packages/model/src/Payload/ModuleState.ts +++ b/packages/modules/packages/module/packages/model/src/Payload/ModuleState.ts @@ -1,3 +1,4 @@ +import { AsObjectFactory } from '@xylabs/object' import type { Payload, WithSources } from '@xyo-network/payload-model' import { isPayloadOfSchemaType, isPayloadOfSchemaTypeWithSources } from '@xyo-network/payload-model' @@ -20,3 +21,5 @@ export const isModuleState = (paylo export const isModuleStateWithSources = (payload?: unknown): payload is WithSources> => { return isPayloadOfSchemaTypeWithSources>(ModuleStateSchema)(payload) } + +export const asModuleState = AsObjectFactory.create>(isModuleState)