@xyo-network/sentinel 2.66.9 → 2.67.0-rc.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.
@@ -1,12 +1,11 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
- import { fulfilled } from '@xylabs/promise'
2
+ import { fulfilled, rejected } from '@xylabs/promise'
3
3
  import { Account } from '@xyo-network/account'
4
4
  import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'
5
5
  import { handleError, handleErrorAsync } from '@xyo-network/error'
6
6
  import { AnyConfigSchema, ModuleConfig, ModuleErrorBuilder, ModuleQueryResult } from '@xyo-network/module'
7
7
  import { ModuleError, Payload } from '@xyo-network/payload-model'
8
- import { WitnessWrapper } from '@xyo-network/witness'
9
- import compact from 'lodash/compact'
8
+ import { WitnessInstance } from '@xyo-network/witness'
10
9
 
11
10
  import { AbstractSentinel } from './AbstractSentinel'
12
11
  import { SentinelConfig, SentinelConfigSchema } from './Config'
@@ -34,9 +33,10 @@ export class MemorySentinel<
34
33
  const resultPayloads: Payload[] = []
35
34
 
36
35
  try {
37
- const generatedPayloads = compact(await this.generatePayloads(allWitnesses))
36
+ const [generatedPayloads, generatedErrors] = await this.generateResults(allWitnesses)
38
37
  const combinedPayloads = [...generatedPayloads, ...payloads]
39
38
  resultPayloads.push(...combinedPayloads)
39
+ errors.push(...generatedErrors)
40
40
  } catch (ex) {
41
41
  handleError(ex, (error) => {
42
42
  errors.push(error)
@@ -84,10 +84,16 @@ export class MemorySentinel<
84
84
  return (await this.bindQueryResult(queryPayload, resultPayloads, [queryAccount], errorPayloads))[0]
85
85
  }
86
86
 
87
- private async generatePayloads(witnesses: WitnessWrapper[]): Promise<Payload[]> {
88
- return (await Promise.allSettled(witnesses?.map((witness) => witness.observe())))
87
+ private async generateResults(witnesses: WitnessInstance[]): Promise<[Payload[], Error[]]> {
88
+ const results = await Promise.allSettled(witnesses?.map((witness) => witness.observe()))
89
+ const payloads = results
89
90
  .filter(fulfilled)
90
91
  .map((result) => result.value)
91
92
  .flat()
93
+ const errors = results
94
+ .filter(rejected)
95
+ .map((result) => result.reason)
96
+ .flat()
97
+ return [payloads, errors]
92
98
  }
93
99
  }
@@ -1,6 +1,6 @@
1
1
  import { BoundWitness } from '@xyo-network/boundwitness-model'
2
2
  import { AnyObject } from '@xyo-network/core'
3
- import { AnyConfigSchema, EventData, Module, ModuleEventArgs, ModuleEventData, ModuleParams } from '@xyo-network/module'
3
+ import { AnyConfigSchema, EventData, Module, ModuleEventArgs, ModuleEventData, ModuleInstance, ModuleParams } from '@xyo-network/module'
4
4
  import { Payload } from '@xyo-network/payload-model'
5
5
  import { Promisable } from '@xyo-network/promise'
6
6
 
@@ -50,4 +50,4 @@ export type SentinelModule<
50
50
  export type SentinelInstance<
51
51
  TParams extends SentinelParams = SentinelParams,
52
52
  TEventData extends SentinelModuleEventData = SentinelModuleEventData,
53
- > = SentinelModule<TParams, TEventData> & Sentinel
53
+ > = SentinelModule<TParams, TEventData> & ModuleInstance & Sentinel
package/src/Wrapper.ts CHANGED
@@ -1,19 +1,21 @@
1
1
  import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module'
2
2
  import { Payload } from '@xyo-network/payload-model'
3
- import { PayloadWrapper } from '@xyo-network/payload-wrapper'
4
3
 
5
4
  import { SentinelReportQuery, SentinelReportQuerySchema } from './Queries'
6
- import { SentinelModule } from './SentinelModel'
5
+ import { SentinelInstance, SentinelModule } from './SentinelModel'
7
6
  import { isSentinelInstance, isSentinelModule } from './typeChecks'
8
7
 
9
8
  constructableModuleWrapper()
10
- export class SentinelWrapper<TModule extends SentinelModule = SentinelModule> extends ModuleWrapper<TModule> implements SentinelModule {
9
+ export class SentinelWrapper<TModule extends SentinelModule = SentinelModule>
10
+ extends ModuleWrapper<TModule>
11
+ implements SentinelInstance<TModule['params']>
12
+ {
11
13
  static override instanceIdentityCheck = isSentinelInstance
12
14
  static override moduleIdentityCheck = isSentinelModule
13
15
  static override requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries]
14
16
 
15
17
  async report(payloads?: Payload[]): Promise<Payload[]> {
16
- const queryPayload = PayloadWrapper.wrap<SentinelReportQuery>({ schema: SentinelReportQuerySchema })
18
+ const queryPayload: SentinelReportQuery = { schema: SentinelReportQuerySchema }
17
19
  const result = await this.sendQuery(queryPayload, payloads)
18
20
  return result
19
21
  }
package/src/typeChecks.ts CHANGED
@@ -1,12 +1,13 @@
1
- import { AsFactory, IsInstanceFactory, IsModuleFactory, isModuleInstance, WithFactory } from '@xyo-network/module-model'
1
+ import { IsInstanceFactory, IsModuleFactory, isModuleInstance, WithFactory } from '@xyo-network/module-model'
2
+ import { AsObjectFactory } from '@xyo-network/object-identity'
2
3
 
3
4
  import { SentinelReportQuerySchema } from './Queries'
4
5
  import { SentinelInstance, SentinelModule } from './SentinelModel'
5
6
 
6
- export const isSentinelInstance = IsInstanceFactory.create<SentinelInstance>({ report: 'function' }, isModuleInstance)
7
- export const isSentinelModule = IsModuleFactory.create<SentinelModule>([SentinelReportQuerySchema])
7
+ export const isSentinelInstance = new IsInstanceFactory<SentinelInstance>().create({ report: 'function' }, [isModuleInstance])
8
+ export const isSentinelModule = new IsModuleFactory<SentinelModule>().create([SentinelReportQuerySchema])
8
9
 
9
- export const asSentinelModule = AsFactory.create(isSentinelModule)
10
- export const asSentinelInstance = AsFactory.create(isSentinelInstance)
10
+ export const asSentinelModule = AsObjectFactory.create(isSentinelModule)
11
+ export const asSentinelInstance = AsObjectFactory.create(isSentinelInstance)
11
12
  export const withSentinelModule = WithFactory.create(isSentinelModule)
12
13
  export const withSentinelInstance = WithFactory.create(isSentinelInstance)