@xyo-network/diviner-temporal-indexing-memory 3.5.2 → 3.6.0-rc.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-temporal-indexing-memory",
3
- "version": "3.5.2",
3
+ "version": "3.6.0-rc.10",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -29,45 +29,47 @@
29
29
  "module": "dist/neutral/index.mjs",
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "dependencies": {
32
- "@xylabs/array": "^4.4.9",
33
- "@xylabs/assert": "^4.4.9",
34
- "@xylabs/exists": "^4.4.9",
35
- "@xylabs/hex": "^4.4.9",
36
- "@xyo-network/archivist-model": "^3.5.2",
37
- "@xyo-network/archivist-wrapper": "^3.5.2",
38
- "@xyo-network/boundwitness-model": "^3.5.2",
39
- "@xyo-network/diviner-abstract": "^3.5.2",
40
- "@xyo-network/diviner-boundwitness-abstract": "^3.5.2",
41
- "@xyo-network/diviner-boundwitness-model": "^3.5.2",
42
- "@xyo-network/diviner-indexing-memory": "^3.5.2",
43
- "@xyo-network/diviner-indexing-model": "^3.5.2",
44
- "@xyo-network/diviner-jsonpath-aggregate-memory": "^3.5.2",
45
- "@xyo-network/diviner-jsonpath-model": "^3.5.2",
46
- "@xyo-network/diviner-model": "^3.5.2",
47
- "@xyo-network/diviner-payload-model": "^3.5.2",
48
- "@xyo-network/diviner-temporal-indexing-model": "^3.5.2",
49
- "@xyo-network/diviner-wrapper": "^3.5.2",
50
- "@xyo-network/module-model": "^3.5.2",
51
- "@xyo-network/payload-builder": "^3.5.2",
52
- "@xyo-network/payload-model": "^3.5.2",
53
- "@xyo-network/payload-utils": "^3.5.2",
54
- "@xyo-network/witness-timestamp": "^3.5.2"
32
+ "@xylabs/array": "^4.4.21",
33
+ "@xylabs/assert": "^4.4.21",
34
+ "@xylabs/exists": "^4.4.21",
35
+ "@xylabs/hex": "^4.4.21",
36
+ "@xyo-network/archivist-model": "^3.6.0-rc.10",
37
+ "@xyo-network/archivist-wrapper": "^3.6.0-rc.10",
38
+ "@xyo-network/boundwitness-model": "^3.6.0-rc.10",
39
+ "@xyo-network/boundwitness-validator": "^3.6.0-rc.10",
40
+ "@xyo-network/diviner-abstract": "^3.6.0-rc.10",
41
+ "@xyo-network/diviner-boundwitness-abstract": "^3.6.0-rc.10",
42
+ "@xyo-network/diviner-boundwitness-model": "^3.6.0-rc.10",
43
+ "@xyo-network/diviner-indexing-memory": "^3.6.0-rc.10",
44
+ "@xyo-network/diviner-indexing-model": "^3.6.0-rc.10",
45
+ "@xyo-network/diviner-jsonpath-aggregate-memory": "^3.6.0-rc.10",
46
+ "@xyo-network/diviner-jsonpath-model": "^3.6.0-rc.10",
47
+ "@xyo-network/diviner-model": "^3.6.0-rc.10",
48
+ "@xyo-network/diviner-payload-model": "^3.6.0-rc.10",
49
+ "@xyo-network/diviner-temporal-indexing-model": "^3.6.0-rc.10",
50
+ "@xyo-network/diviner-wrapper": "^3.6.0-rc.10",
51
+ "@xyo-network/module-model": "^3.6.0-rc.10",
52
+ "@xyo-network/payload-builder": "^3.6.0-rc.10",
53
+ "@xyo-network/payload-model": "^3.6.0-rc.10",
54
+ "@xyo-network/payload-utils": "^3.6.0-rc.10",
55
+ "@xyo-network/witness-timestamp": "^3.6.0-rc.10"
55
56
  },
56
57
  "devDependencies": {
57
- "@xylabs/delay": "^4.4.9",
58
- "@xylabs/ts-scripts-yarn3": "^4.2.4",
59
- "@xylabs/tsconfig": "^4.2.4",
60
- "@xylabs/vitest-extended": "^4.4.9",
61
- "@xyo-network/account": "^3.5.2",
62
- "@xyo-network/archivist-memory": "^3.5.2",
63
- "@xyo-network/boundwitness-builder": "^3.5.2",
64
- "@xyo-network/manifest": "^3.5.2",
65
- "@xyo-network/module-factory-locator": "^3.5.2",
66
- "@xyo-network/node-memory": "^3.5.2",
58
+ "@xylabs/delay": "^4.4.21",
59
+ "@xylabs/ts-scripts-yarn3": "^4.2.6",
60
+ "@xylabs/tsconfig": "^4.2.6",
61
+ "@xylabs/vitest-extended": "^4.4.21",
62
+ "@xyo-network/account": "^3.6.0-rc.10",
63
+ "@xyo-network/archivist-memory": "^3.6.0-rc.10",
64
+ "@xyo-network/boundwitness-builder": "^3.6.0-rc.10",
65
+ "@xyo-network/manifest": "^3.6.0-rc.10",
66
+ "@xyo-network/module-factory-locator": "^3.6.0-rc.10",
67
+ "@xyo-network/node-memory": "^3.6.0-rc.10",
67
68
  "typescript": "^5.7.2",
68
- "vitest": "^2.1.5"
69
+ "vitest": "^2.1.8"
69
70
  },
70
71
  "publishConfig": {
71
72
  "access": "public"
72
- }
73
+ },
74
+ "stableVersion": "3.5.2"
73
75
  }
@@ -82,9 +82,9 @@ export class TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner<
82
82
  sourcePathExpression: '$.limit',
83
83
  },
84
84
  {
85
- defaultValue: 0,
86
- destinationField: 'offset',
87
- sourcePathExpression: '$.offset',
85
+ // defaultValue: 0,
86
+ destinationField: 'cursor',
87
+ sourcePathExpression: '$.cursor',
88
88
  },
89
89
  {
90
90
  defaultValue: 'desc',
@@ -111,7 +111,7 @@ export class TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner<
111
111
  // TODO: Make sources not need to be deleted
112
112
  delete fields.sources
113
113
  // TODO: Add support for additional filters
114
- return await new PayloadBuilder<Payload>({ schema: this.indexQuerySchema }).fields(fields).build()
114
+ return new PayloadBuilder<Payload>({ schema: this.indexQuerySchema }).fields(fields).build()
115
115
  }),
116
116
  )
117
117
  }
@@ -3,7 +3,7 @@ import { assertEx } from '@xylabs/assert'
3
3
  import { exists } from '@xylabs/exists'
4
4
  import type { Hash } from '@xylabs/hex'
5
5
  import type { BoundWitness } from '@xyo-network/boundwitness-model'
6
- import { isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'
6
+ import { isBoundWitness } from '@xyo-network/boundwitness-model'
7
7
  import { AbstractDiviner } from '@xyo-network/diviner-abstract'
8
8
  import { jsonPathToTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-memory'
9
9
  import type { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-model'
@@ -69,13 +69,12 @@ export class TemporalIndexingDivinerIndexCandidateToIndexDiviner<
69
69
  }
70
70
 
71
71
  protected override async divineHandler(payloads: Payload[] = []): Promise<Payload[]> {
72
- const builtPayloads = await Promise.all(payloads.map(payload => PayloadBuilder.build(payload)))
73
72
  // If the Bound Witness does not contain all the required schemas do not index it
74
- const indexableBoundWitnesses = builtPayloads
75
- .filter(isBoundWitnessWithMeta)
73
+ const indexableBoundWitnesses = payloads
74
+ .filter(isBoundWitness)
76
75
  .filter(bw => containsAll(bw.payload_schemas, this.indexableSchemas))
77
76
  // If the Payload is not one of the indexable schemas do not index it
78
- const indexablePayloads = builtPayloads.filter(p => this.isIndexablePayload(p))
77
+ const indexablePayloads = payloads.filter(p => this.isIndexablePayload(p))
79
78
  // If there is nothing to index, return an empty array
80
79
  if (indexableBoundWitnesses.length === 0 || indexablePayloads.length === 0) return []
81
80
  // Hash all the indexable data once
@@ -105,24 +104,22 @@ export class TemporalIndexingDivinerIndexCandidateToIndexDiviner<
105
104
  }
106
105
 
107
106
  // Create the indexes from the tuples
108
- const indexes = await Promise.all(
109
- validIndexableTuples.map<Promise<TemporalIndexingDivinerResultIndex>>(async ([bwHash, ...sourcePayloadHashes]) => {
110
- const sourcePayloads = sourcePayloadHashes.map(hash => payloadDictionary[hash])
111
- // Use the payload transformers to convert the fields from the source payloads to the destination fields
112
- const indexFields = sourcePayloads.flatMap((payload) => {
113
- // Find the transformers for this payload
114
- const transformers = this.payloadTransformers[payload.schema]
115
- // If transformers exist, apply them to the payload otherwise return an empty array
116
- return transformers ? transformers.map(transform => transform(payload)) : []
117
- })
118
- // Include all the sources for reference
119
- const sources: string[] = [bwHash, ...sourcePayloadHashes]
120
- // Build and return the index
121
- return await new PayloadBuilder<TemporalIndexingDivinerResultIndex>({ schema: TemporalIndexingDivinerResultIndexSchema })
122
- .fields(Object.assign({ sources }, ...indexFields))
123
- .build()
124
- }),
125
- )
107
+ const indexes = validIndexableTuples.map<TemporalIndexingDivinerResultIndex>(([bwHash, ...sourcePayloadHashes]) => {
108
+ const sourcePayloads = sourcePayloadHashes.map(hash => payloadDictionary[hash])
109
+ // Use the payload transformers to convert the fields from the source payloads to the destination fields
110
+ const indexFields = sourcePayloads.flatMap((payload) => {
111
+ // Find the transformers for this payload
112
+ const transformers = this.payloadTransformers[payload.schema]
113
+ // If transformers exist, apply them to the payload otherwise return an empty array
114
+ return transformers ? transformers.map(transform => transform(payload)) : []
115
+ })
116
+ // Include all the sources for reference
117
+ const sources: Hash[] = [bwHash, ...sourcePayloadHashes]
118
+ // Build and return the index
119
+ return new PayloadBuilder<TemporalIndexingDivinerResultIndex>({ schema: TemporalIndexingDivinerResultIndexSchema })
120
+ .fields(Object.assign({ sources }, ...indexFields))
121
+ .build()
122
+ })
126
123
  return indexes.flat()
127
124
  }
128
125
 
@@ -1,13 +1,14 @@
1
+ import { filterAs } from '@xylabs/array'
1
2
  import { assertEx } from '@xylabs/assert'
2
3
  import { exists } from '@xylabs/exists'
3
- import type { ArchivistInstance } from '@xyo-network/archivist-model'
4
+ import type { ArchivistInstance, ArchivistNextOptions } from '@xyo-network/archivist-model'
4
5
  import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
5
6
  import type { BoundWitness } from '@xyo-network/boundwitness-model'
6
- import { isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'
7
+ import { asBoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'
8
+ import { payloadSchemasContainsAll } from '@xyo-network/boundwitness-validator'
7
9
  import { AbstractDiviner } from '@xyo-network/diviner-abstract'
8
10
  import type { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'
9
11
  import type { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'
10
- import { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
11
12
  import type { IndexingDivinerState } from '@xyo-network/diviner-indexing-model'
12
13
  import type { TemporalIndexingDivinerStateToIndexCandidateDivinerParams } from '@xyo-network/diviner-temporal-indexing-model'
13
14
  import { TemporalIndexingDivinerStateToIndexCandidateDivinerConfigSchema } from '@xyo-network/diviner-temporal-indexing-model'
@@ -16,8 +17,11 @@ import type {
16
17
  Labels, ModuleIdentifier, ModuleState,
17
18
  } from '@xyo-network/module-model'
18
19
  import { isModuleState, ModuleStateSchema } from '@xyo-network/module-model'
19
- import { PayloadBuilder } from '@xyo-network/payload-builder'
20
- import type { Payload, Schema } from '@xyo-network/payload-model'
20
+ import type {
21
+ Payload, Schema,
22
+ WithStorageMeta,
23
+ } from '@xyo-network/payload-model'
24
+ import { SequenceConstants } from '@xyo-network/payload-model'
21
25
  import { intraBoundwitnessSchemaCombinations } from '@xyo-network/payload-utils'
22
26
  import type { TimeStamp } from '@xyo-network/witness-timestamp'
23
27
  import { TimestampSchema } from '@xyo-network/witness-timestamp'
@@ -76,31 +80,35 @@ export class TemporalIndexingDivinerStateToIndexCandidateDiviner<
76
80
  return [TimestampSchema, ...(schemas ?? [])]
77
81
  }
78
82
 
79
- protected override async divineHandler(payloads: Payload[] = []): Promise<[ModuleState, ...IndexCandidate[]]> {
83
+ protected override async divineHandler(payloads: Payload[] = []): Promise<TemporalStateToIndexCandidateDivinerResponse> {
80
84
  // Retrieve the last state from what was passed in
81
85
  const lastState = payloads.find(isModuleState<IndexingDivinerState>)
82
86
  // If there is no last state, start from the beginning
83
- if (!lastState) return [{ schema: ModuleStateSchema, state: { offset: 0 } }]
84
- // Otherwise, get the last offset
85
- const { offset } = lastState.state
86
- // Get next batch of results starting from the offset
87
- const boundWitnessDiviner = await this.getBoundWitnessDivinerForStore()
88
- if (!boundWitnessDiviner) return [lastState]
89
- const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })
90
- .fields({
91
- limit: this.payloadDivinerLimit, offset, order, payload_schemas: this.payload_schemas,
92
- })
93
- .build()
94
- const batch = await boundWitnessDiviner.divine([query])
95
- if (batch.length === 0) return [lastState]
96
- // Get source data
87
+ ?? { schema: ModuleStateSchema, state: { cursor: SequenceConstants.minLocalSequence } }
88
+
89
+ // Get the last cursor
90
+ const cursor = lastState?.state?.cursor
91
+ // Get the archivist for the store
97
92
  const sourceArchivist = await this.getArchivistForStore()
98
93
  if (!sourceArchivist) return [lastState]
99
- const bws = batch.filter(isBoundWitnessWithMeta)
94
+
95
+ // Get the next batch of results
96
+ const nextOffset: ArchivistNextOptions = { limit: this.payloadDivinerLimit, order }
97
+ // Only use the cursor if it's a valid offset
98
+ if (cursor !== SequenceConstants.minLocalSequence) nextOffset.cursor = cursor
99
+ // Get next batch of results starting from the offset
100
+ const next = await sourceArchivist.next(nextOffset)
101
+ if (next.length === 0) return [lastState]
102
+ const batch = filterAs(next, asBoundWitness)
103
+ .filter(exists)
104
+ .filter(bw => payloadSchemasContainsAll(bw, this.payload_schemas))
105
+ // Get source data
106
+ const bws = batch.filter(isBoundWitness)
100
107
  const indexCandidates: IndexCandidate[] = (await Promise.all(bws.map(bw => this.getPayloadsInBoundWitness(bw, sourceArchivist))))
101
108
  .filter(exists)
102
109
  .flat()
103
- const nextState = { schema: ModuleStateSchema, state: { ...lastState.state, offset: offset + batch.length } }
110
+ const nextCursor = assertEx(next.at(-1)?._sequence, () => `${moduleName}: Expected next to have a sequence`)
111
+ const nextState: ModuleState<IndexingDivinerState> = { schema: ModuleStateSchema, state: { ...lastState.state, cursor: nextCursor } }
104
112
  return [nextState, ...indexCandidates]
105
113
  }
106
114
 
@@ -139,7 +147,7 @@ export class TemporalIndexingDivinerStateToIndexCandidateDiviner<
139
147
  DivinerWrapper<
140
148
  BoundWitnessDiviner<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>,
141
149
  BoundWitnessDivinerQueryPayload,
142
- BoundWitness
150
+ WithStorageMeta<BoundWitness>
143
151
  >
144
152
  >(mod, this.account)
145
153
  }