@xyo-network/archivist-mongodb 2.74.4 → 2.74.5

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.
package/src/Archivist.ts CHANGED
@@ -1,74 +1,21 @@
1
- import { assertEx } from '@xylabs/assert'
2
1
  import { exists } from '@xylabs/exists'
3
- import { merge } from '@xylabs/lodash'
4
2
  import { fulfilledValues } from '@xylabs/promise'
5
- import { staticImplements } from '@xylabs/static-implements'
6
3
  import { AbstractArchivist } from '@xyo-network/archivist-abstract'
7
4
  import { ArchivistConfigSchema, ArchivistInsertQuerySchema } from '@xyo-network/archivist-model'
8
- import { MongoDBArchivistConfigSchema, MongoDBArchivistParams } from '@xyo-network/archivist-model-mongodb'
9
- import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'
10
- import { BoundWitness } from '@xyo-network/boundwitness-model'
11
- import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
12
- import { WithLabels } from '@xyo-network/module-model'
13
- import { MongoDBStorageClassLabels } from '@xyo-network/module-model-mongodb'
14
- import { BoundWitnessWithMeta, PayloadWithMeta, PayloadWithPartialMeta } from '@xyo-network/node-core-model'
5
+ import { MongoDBArchivistConfigSchema } from '@xyo-network/archivist-model-mongodb'
6
+ import { MongoDBModuleMixin } from '@xyo-network/module-abstract-mongodb'
7
+ import { PayloadWithPartialMeta } from '@xyo-network/node-core-model'
15
8
  import { Payload } from '@xyo-network/payload-model'
16
9
  import { PayloadWrapper } from '@xyo-network/payload-wrapper'
17
- import { BaseMongoSdk, BaseMongoSdkConfig } from '@xyo-network/sdk-xyo-mongo-js'
18
10
 
19
- import { validByType } from './lib'
11
+ import { toBoundWitnessWithMeta, toPayloadWithMeta, toReturnValue, validByType } from './lib'
20
12
 
21
- const toBoundWitnessWithMeta = async (wrapper: BoundWitnessWrapper | QueryBoundWitnessWrapper): Promise<BoundWitnessWithMeta> => {
22
- const bw = wrapper.boundwitness as BoundWitness
23
- return { ...bw, _hash: await wrapper.hashAsync(), _timestamp: Date.now() }
24
- }
25
-
26
- const toReturnValue = (value: Payload | BoundWitness): Payload => {
27
- const _signatures = (value as BoundWitness)?._signatures
28
- if (_signatures) {
29
- return { ...PayloadWrapper.wrap(value).body(), _signatures } as BoundWitness
30
- } else {
31
- return { ...PayloadWrapper.wrap(value).body() }
32
- }
33
- }
13
+ const MongoDBArchivistBase = MongoDBModuleMixin(AbstractArchivist)
34
14
 
35
- const toPayloadWithMeta = async (wrapper: PayloadWrapper): Promise<PayloadWithMeta> => {
36
- return { ...wrapper.payload(), _hash: await wrapper.hashAsync(), _timestamp: Date.now() }
37
- }
38
-
39
- @staticImplements<WithLabels<MongoDBStorageClassLabels>>()
40
- export class MongoDBArchivist<TParams extends MongoDBArchivistParams = MongoDBArchivistParams> extends AbstractArchivist<TParams> {
15
+ export class MongoDBArchivist extends MongoDBArchivistBase {
41
16
  static override configSchemas = [MongoDBArchivistConfigSchema, ArchivistConfigSchema]
42
- static labels = MongoDBStorageClassLabels
43
-
44
- private _boundWitnessSdk: BaseMongoSdk<BoundWitnessWithMeta> | undefined
45
- private _payloadSdk: BaseMongoSdk<PayloadWithMeta> | undefined
46
-
47
- get boundWitnessSdkConfig(): BaseMongoSdkConfig {
48
- return merge({}, this.params.boundWitnessSdkConfig, this.config.boundWitnessSdkConfig, {
49
- collection: this.config.boundWitnessSdkConfig?.collection ?? this.params.boundWitnessSdkConfig?.collection ?? 'bound_witnesses',
50
- })
51
- }
52
-
53
- get boundWitnesses() {
54
- this._boundWitnessSdk = this._boundWitnessSdk ?? new BaseMongoSdk<BoundWitnessWithMeta>(this.boundWitnessSdkConfig)
55
- return assertEx(this._boundWitnessSdk)
56
- }
57
-
58
- get payloadSdkConfig(): BaseMongoSdkConfig {
59
- return merge({}, this.params.payloadSdkConfig, this.config.payloadSdkConfig, {
60
- collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? 'payload',
61
- })
62
- }
63
-
64
- get payloads() {
65
- this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMeta>(this.payloadSdkConfig)
66
- return assertEx(this._payloadSdk)
67
- }
68
17
 
69
- override get queries(): string[] {
70
- return [ArchivistInsertQuerySchema, ...super.queries]
71
- }
18
+ override readonly queries: string[] = [ArchivistInsertQuerySchema, ...super.queries]
72
19
 
73
20
  override async head(): Promise<Payload | undefined> {
74
21
  const head = await (await this.payloads.find({})).sort({ _timestamp: -1 }).limit(1).toArray()
package/src/lib/index.ts CHANGED
@@ -1 +1,4 @@
1
+ export * from './toBoundWitnessWithMeta'
2
+ export * from './toPayloadWithMeta'
3
+ export * from './toReturnValue'
1
4
  export * from './validByType'
@@ -0,0 +1,8 @@
1
+ import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'
2
+ import { BoundWitness } from '@xyo-network/boundwitness-model'
3
+ import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
4
+
5
+ export const toBoundWitnessWithMeta = async (wrapper: BoundWitnessWrapper | QueryBoundWitnessWrapper): Promise<BoundWitnessWithMeta> => {
6
+ const bw = wrapper.boundwitness as BoundWitness
7
+ return { ...bw, _hash: await wrapper.hashAsync(), _timestamp: Date.now() }
8
+ }
@@ -0,0 +1,6 @@
1
+ import { PayloadWithMeta } from '@xyo-network/node-core-model'
2
+ import { PayloadWrapper } from '@xyo-network/payload-wrapper'
3
+
4
+ export const toPayloadWithMeta = async (wrapper: PayloadWrapper): Promise<PayloadWithMeta> => {
5
+ return { ...wrapper.payload(), _hash: await wrapper.hashAsync(), _timestamp: Date.now() }
6
+ }
@@ -0,0 +1,12 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model'
2
+ import { Payload } from '@xyo-network/payload-model'
3
+ import { PayloadWrapper } from '@xyo-network/payload-wrapper'
4
+
5
+ export const toReturnValue = (value: Payload | BoundWitness): Payload => {
6
+ const _signatures = (value as BoundWitness)?._signatures
7
+ if (_signatures) {
8
+ return { ...PayloadWrapper.wrap(value).body(), _signatures } as BoundWitness
9
+ } else {
10
+ return { ...PayloadWrapper.wrap(value).body() }
11
+ }
12
+ }