Skip to content

Commit

Permalink
Add as identity function
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Dec 18, 2024
1 parent 9de2fae commit 908d0f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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()
Expand All @@ -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))
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -20,3 +21,5 @@ export const isModuleState = <T extends StateDictionary = StateDictionary>(paylo
export const isModuleStateWithSources = <T extends StateDictionary = StateDictionary>(payload?: unknown): payload is WithSources<ModuleState<T>> => {
return isPayloadOfSchemaTypeWithSources<ModuleState<T>>(ModuleStateSchema)(payload)
}

export const asModuleState = AsObjectFactory.create<ModuleState<StateDictionary>>(isModuleState)

0 comments on commit 908d0f3

Please sign in to comment.