@xyo-network/diviner-temporal-indexing-memory 5.3.22 → 5.3.25

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": "5.3.22",
3
+ "version": "5.3.25",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,80 +30,76 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
35
  "!**/*.test.*",
37
36
  "README.md"
38
37
  ],
39
38
  "dependencies": {
40
- "@xyo-network/archivist-model": "~5.3.22",
41
- "@xyo-network/archivist-wrapper": "~5.3.22",
42
- "@xyo-network/boundwitness-model": "~5.3.22",
43
- "@xyo-network/boundwitness-validator": "~5.3.22",
44
- "@xyo-network/diviner-abstract": "~5.3.22",
45
- "@xyo-network/diviner-boundwitness-abstract": "~5.3.22",
46
- "@xyo-network/diviner-boundwitness-model": "~5.3.22",
47
- "@xyo-network/diviner-indexing-memory": "~5.3.22",
48
- "@xyo-network/diviner-indexing-model": "~5.3.22",
49
- "@xyo-network/diviner-jsonpath-aggregate-memory": "~5.3.22",
50
- "@xyo-network/diviner-jsonpath-model": "~5.3.22",
51
- "@xyo-network/diviner-model": "~5.3.22",
52
- "@xyo-network/diviner-payload-model": "~5.3.22",
53
- "@xyo-network/diviner-temporal-indexing-model": "~5.3.22",
54
- "@xyo-network/diviner-wrapper": "~5.3.22",
55
- "@xyo-network/module-model": "~5.3.22",
56
- "@xyo-network/payload-builder": "~5.3.22",
57
- "@xyo-network/payload-model": "~5.3.22",
58
- "@xyo-network/payload-utils": "~5.3.22",
59
- "@xyo-network/witness-timestamp": "~5.3.22"
39
+ "@xyo-network/archivist-model": "~5.3.25",
40
+ "@xyo-network/boundwitness-model": "~5.3.25",
41
+ "@xyo-network/archivist-wrapper": "~5.3.25",
42
+ "@xyo-network/diviner-boundwitness-abstract": "~5.3.25",
43
+ "@xyo-network/diviner-indexing-memory": "~5.3.25",
44
+ "@xyo-network/diviner-boundwitness-model": "~5.3.25",
45
+ "@xyo-network/diviner-abstract": "~5.3.25",
46
+ "@xyo-network/diviner-model": "~5.3.25",
47
+ "@xyo-network/diviner-indexing-model": "~5.3.25",
48
+ "@xyo-network/boundwitness-validator": "~5.3.25",
49
+ "@xyo-network/diviner-payload-model": "~5.3.25",
50
+ "@xyo-network/diviner-jsonpath-aggregate-memory": "~5.3.25",
51
+ "@xyo-network/diviner-jsonpath-model": "~5.3.25",
52
+ "@xyo-network/module-model": "~5.3.25",
53
+ "@xyo-network/diviner-temporal-indexing-model": "~5.3.25",
54
+ "@xyo-network/diviner-wrapper": "~5.3.25",
55
+ "@xyo-network/payload-builder": "~5.3.25",
56
+ "@xyo-network/payload-model": "~5.3.25",
57
+ "@xyo-network/witness-timestamp": "~5.3.25",
58
+ "@xyo-network/payload-utils": "~5.3.25"
60
59
  },
61
60
  "devDependencies": {
62
61
  "@opentelemetry/api": "^1.9.1",
63
62
  "@types/node": "^25.5.0",
64
- "@xylabs/sdk-js": "^5.0.91",
65
- "@xylabs/ts-scripts-common": "~7.6.8",
66
- "@xylabs/ts-scripts-yarn3": "~7.6.8",
67
- "@xylabs/tsconfig": "~7.6.8",
68
- "@xylabs/vitest-extended": "~5.0.91",
69
- "@xyo-network/archivist-memory": "~5.3.22",
70
- "@xyo-network/archivist-model": "~5.3.22",
71
- "@xyo-network/archivist-wrapper": "~5.3.22",
72
- "@xyo-network/boundwitness-builder": "~5.3.22",
73
- "@xyo-network/boundwitness-model": "~5.3.22",
74
- "@xyo-network/boundwitness-validator": "~5.3.22",
75
- "@xyo-network/diviner-abstract": "~5.3.22",
76
- "@xyo-network/diviner-boundwitness-abstract": "~5.3.22",
77
- "@xyo-network/diviner-boundwitness-model": "~5.3.22",
78
- "@xyo-network/diviner-indexing-memory": "~5.3.22",
79
- "@xyo-network/diviner-indexing-model": "~5.3.22",
80
- "@xyo-network/diviner-jsonpath-aggregate-memory": "~5.3.22",
81
- "@xyo-network/diviner-jsonpath-model": "~5.3.22",
82
- "@xyo-network/diviner-model": "~5.3.22",
83
- "@xyo-network/diviner-payload-model": "~5.3.22",
84
- "@xyo-network/diviner-temporal-indexing-model": "~5.3.22",
85
- "@xyo-network/diviner-wrapper": "~5.3.22",
86
- "@xyo-network/manifest": "~5.3.22",
87
- "@xyo-network/module-factory-locator": "~5.3.22",
88
- "@xyo-network/module-model": "~5.3.22",
89
- "@xyo-network/node-memory": "~5.3.22",
90
- "@xyo-network/payload-builder": "~5.3.22",
91
- "@xyo-network/payload-model": "~5.3.22",
92
- "@xyo-network/payload-utils": "~5.3.22",
93
- "@xyo-network/wallet": "~5.3.22",
94
- "@xyo-network/witness-timestamp": "~5.3.22",
63
+ "@xylabs/sdk-js": "^5.0.93",
64
+ "@xylabs/ts-scripts-common": "~7.6.16",
65
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
66
+ "@xylabs/tsconfig": "~7.6.16",
67
+ "@xylabs/vitest-extended": "~5.0.93",
95
68
  "acorn": "^8.16.0",
96
69
  "axios": "^1.14.0",
97
- "cosmiconfig": "^9.0.1",
98
- "esbuild": "^0.27.4",
99
- "eslint": "^10.1.0",
70
+ "esbuild": "^0.28.0",
100
71
  "ethers": "^6.16.0",
101
- "rollup": "^4.60.1",
102
72
  "tslib": "^2.8.1",
103
73
  "typescript": "~5.9.3",
104
74
  "vite": "^8.0.3",
105
75
  "vitest": "~4.1.2",
106
- "zod": "^4.3.6"
76
+ "zod": "^4.3.6",
77
+ "@xyo-network/archivist-memory": "~5.3.25",
78
+ "@xyo-network/archivist-model": "~5.3.25",
79
+ "@xyo-network/boundwitness-builder": "~5.3.25",
80
+ "@xyo-network/boundwitness-validator": "~5.3.25",
81
+ "@xyo-network/archivist-wrapper": "~5.3.25",
82
+ "@xyo-network/boundwitness-model": "~5.3.25",
83
+ "@xyo-network/diviner-abstract": "~5.3.25",
84
+ "@xyo-network/diviner-boundwitness-model": "~5.3.25",
85
+ "@xyo-network/diviner-jsonpath-aggregate-memory": "~5.3.25",
86
+ "@xyo-network/diviner-indexing-model": "~5.3.25",
87
+ "@xyo-network/diviner-indexing-memory": "~5.3.25",
88
+ "@xyo-network/diviner-boundwitness-abstract": "~5.3.25",
89
+ "@xyo-network/diviner-jsonpath-model": "~5.3.25",
90
+ "@xyo-network/diviner-model": "~5.3.25",
91
+ "@xyo-network/diviner-payload-model": "~5.3.25",
92
+ "@xyo-network/diviner-temporal-indexing-model": "~5.3.25",
93
+ "@xyo-network/diviner-wrapper": "~5.3.25",
94
+ "@xyo-network/module-model": "~5.3.25",
95
+ "@xyo-network/manifest": "~5.3.25",
96
+ "@xyo-network/module-factory-locator": "~5.3.25",
97
+ "@xyo-network/node-memory": "~5.3.25",
98
+ "@xyo-network/payload-utils": "~5.3.25",
99
+ "@xyo-network/payload-builder": "~5.3.25",
100
+ "@xyo-network/payload-model": "~5.3.25",
101
+ "@xyo-network/witness-timestamp": "~5.3.25",
102
+ "@xyo-network/wallet": "~5.3.25"
107
103
  },
108
104
  "peerDependencies": {
109
105
  "@xylabs/sdk-js": "^5",
@@ -114,4 +110,4 @@
114
110
  "publishConfig": {
115
111
  "access": "public"
116
112
  }
117
- }
113
+ }
package/src/Diviner.ts DELETED
@@ -1,23 +0,0 @@
1
- import { IndexingDiviner } from '@xyo-network/diviner-indexing-memory'
2
- import type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'
3
- import type { TemporalIndexingDivinerParams } from '@xyo-network/diviner-temporal-indexing-model'
4
- import { TemporalIndexingDivinerConfigSchema } from '@xyo-network/diviner-temporal-indexing-model'
5
- import type { Payload, Schema } from '@xyo-network/payload-model'
6
-
7
- export class TemporalIndexingDiviner<
8
- TParams extends TemporalIndexingDivinerParams = TemporalIndexingDivinerParams,
9
- TIn extends Payload = Payload,
10
- TOut extends Payload = Payload,
11
- TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<
12
- DivinerInstance<TParams, TIn, TOut>,
13
- TIn,
14
- TOut
15
- >,
16
- > extends IndexingDiviner<TParams, TIn, TOut, TEventData> {
17
- static override readonly configSchemas: Schema[] = [...super.configSchemas, TemporalIndexingDivinerConfigSchema]
18
- static override readonly defaultConfigSchema: Schema = TemporalIndexingDivinerConfigSchema
19
-
20
- protected override async startHandler() {
21
- await super.startHandler()
22
- }
23
- }
@@ -1,122 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import { AbstractDiviner } from '@xyo-network/diviner-abstract'
3
- import { jsonPathToTransformersDictionary, reducePayloads } from '@xyo-network/diviner-jsonpath-aggregate-memory'
4
- import type { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-model'
5
- import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
6
- import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
7
- import type { TemporalIndexingDivinerDivinerQueryToIndexQueryDivinerParams } from '@xyo-network/diviner-temporal-indexing-model'
8
- import {
9
- TemporalIndexingDivinerDivinerQueryToIndexQueryDivinerConfigSchema,
10
- TemporalIndexingDivinerResultIndexSchema,
11
- } from '@xyo-network/diviner-temporal-indexing-model'
12
- import type { Labels } from '@xyo-network/module-model'
13
- import { PayloadBuilder } from '@xyo-network/payload-builder'
14
- import type { Payload, Schema } from '@xyo-network/payload-model'
15
- import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
16
- // TODO: Inherit from JsonPathAggregateDiviner
17
- /**
18
- * A diviner that converts diviner query to index query
19
- */
20
- export class TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner<
21
- TParams extends TemporalIndexingDivinerDivinerQueryToIndexQueryDivinerParams = TemporalIndexingDivinerDivinerQueryToIndexQueryDivinerParams,
22
- > extends AbstractDiviner<TParams> {
23
- static override readonly configSchemas = [...super.configSchemas, TemporalIndexingDivinerDivinerQueryToIndexQueryDivinerConfigSchema]
24
- static override readonly defaultConfigSchema = TemporalIndexingDivinerDivinerQueryToIndexQueryDivinerConfigSchema
25
- static override readonly labels: Labels = {
26
- ...super.labels,
27
- 'network.xyo.diviner.stage': 'divinerQueryToIndexQueryDiviner',
28
- }
29
-
30
- private _indexableSchemas: Schema[] | undefined
31
- private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined
32
-
33
- /**
34
- * The schema of the diviner query payloads
35
- */
36
- protected get divinerQuerySchema(): Schema {
37
- return this.config.divinerQuerySchema ?? PayloadDivinerQuerySchema
38
- }
39
-
40
- /**
41
- * The schema of the index query payloads
42
- */
43
- protected get indexQuerySchema(): Schema {
44
- return this.config.indexQuerySchema ?? PayloadDivinerQuerySchema
45
- }
46
-
47
- /**
48
- * The schema of the index payloads
49
- */
50
- protected get indexSchema(): Schema {
51
- return this.config.indexSchema ?? TemporalIndexingDivinerResultIndexSchema
52
- }
53
-
54
- /**
55
- * List of indexable schemas for this diviner
56
- */
57
- protected get indexableSchemas(): Schema[] {
58
- if (!this._indexableSchemas) this._indexableSchemas = Object.keys(this.schemaTransforms) as Schema[]
59
- return this._indexableSchemas
60
- }
61
-
62
- /**
63
- * Dictionary of schemas to payload transformers for creating indexes
64
- * from the payloads within a Bound Witness
65
- */
66
- protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {
67
- if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)
68
- return this._payloadTransformers
69
- }
70
-
71
- /**
72
- * The dictionary of schemas to JSON Path transform expressions for creating indexes
73
- * from the payloads within a Bound Witness
74
- */
75
- protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {
76
- return (
77
- this.config?.schemaTransforms ?? {
78
- [this.divinerQuerySchema]: [
79
- {
80
- defaultValue: 1,
81
- destinationField: 'limit',
82
- sourcePathExpression: '$.limit',
83
- },
84
- {
85
- // defaultValue: 0,
86
- destinationField: 'cursor',
87
- sourcePathExpression: '$.cursor',
88
- },
89
- {
90
- defaultValue: 'desc',
91
- destinationField: 'order',
92
- sourcePathExpression: '$.order',
93
- },
94
- ],
95
- }
96
- )
97
- }
98
-
99
- protected override async divineHandler(payloads: Payload[] = []): Promise<Payload[]> {
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- const queries = payloads.filter(isPayloadOfSchemaType<PayloadDivinerQueryPayload>(this.divinerQuerySchema as any))
102
- if (queries.length > 0) {
103
- return await Promise.all(
104
- queries.map(async (query) => {
105
- const fields = await reducePayloads<PayloadDivinerQueryPayload & { $sources?: Hash[]; sources?: Hash[] }>(
106
- [query],
107
- this.payloadTransformers,
108
- this.indexQuerySchema,
109
- )
110
- // TODO: Make index schema configurable
111
- fields.schemas = [this.indexSchema]
112
- // TODO: Make sources not need to be deleted
113
- delete fields.sources
114
- delete fields?.$sources
115
- // TODO: Add support for additional filters
116
- return new PayloadBuilder<Payload>({ schema: this.indexQuerySchema }).fields(fields).build()
117
- }),
118
- )
119
- }
120
- return []
121
- }
122
- }
@@ -1 +0,0 @@
1
- export * from './Diviner.ts'
@@ -1,144 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import {
3
- assertEx, containsAll, exists,
4
- } from '@xylabs/sdk-js'
5
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
6
- import { isBoundWitness } from '@xyo-network/boundwitness-model'
7
- import { AbstractDiviner } from '@xyo-network/diviner-abstract'
8
- import { jsonPathToTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-memory'
9
- import type { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-model'
10
- import type {
11
- TemporalIndexingDivinerIndexCandidateToIndexDivinerParams,
12
- TemporalIndexingDivinerResultIndex,
13
- } from '@xyo-network/diviner-temporal-indexing-model'
14
- import {
15
- TemporalIndexingDivinerIndexCandidateToIndexDivinerConfigSchema,
16
- TemporalIndexingDivinerResultIndexSchema,
17
- } from '@xyo-network/diviner-temporal-indexing-model'
18
- import type { Labels } from '@xyo-network/module-model'
19
- import { PayloadBuilder } from '@xyo-network/payload-builder'
20
- import type { Payload, Schema } from '@xyo-network/payload-model'
21
- import { isAnyPayload } from '@xyo-network/payload-model'
22
- import { intraBoundwitnessSchemaCombinations } from '@xyo-network/payload-utils'
23
-
24
- type IndexableHashes = [Hash, ...Hash[]]
25
-
26
- const moduleName = 'TemporalIndexingDivinerIndexCandidateToIndexDiviner'
27
-
28
- /**
29
- * Diviner which transforms index candidates to indexes using JSON Path to map
30
- * source properties in the supplied payloads to destination fields in the
31
- * resultant index
32
- */
33
- export class TemporalIndexingDivinerIndexCandidateToIndexDiviner<
34
- TParams extends TemporalIndexingDivinerIndexCandidateToIndexDivinerParams = TemporalIndexingDivinerIndexCandidateToIndexDivinerParams,
35
- > extends AbstractDiviner<TParams> {
36
- static override readonly configSchemas: Schema[] = [...super.configSchemas, TemporalIndexingDivinerIndexCandidateToIndexDivinerConfigSchema]
37
- static override readonly defaultConfigSchema: Schema = TemporalIndexingDivinerIndexCandidateToIndexDivinerConfigSchema
38
- static override readonly labels: Labels = {
39
- ...super.labels,
40
- 'network.xyo.diviner.stage': 'indexCandidateToIndexDiviner',
41
- }
42
-
43
- private _indexableSchemas: Schema[] | undefined
44
- private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined
45
-
46
- /**
47
- * List of indexable schemas for this diviner
48
- */
49
- protected get indexableSchemas(): Schema[] {
50
- if (!this._indexableSchemas) this._indexableSchemas = Object.keys(this.schemaTransforms) as Schema[]
51
- return this._indexableSchemas
52
- }
53
-
54
- /**
55
- * Dictionary of schemas to payload transformers for creating indexes
56
- * from the payloads within a Bound Witness
57
- */
58
- protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {
59
- if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)
60
- return this._payloadTransformers
61
- }
62
-
63
- /**
64
- * The dictionary of schemas to JSON Path transform expressions for creating indexes
65
- * from the payloads within a Bound Witness
66
- */
67
- protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {
68
- return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)
69
- }
70
-
71
- protected override async divineHandler(payloads: Payload[] = []): Promise<Payload[]> {
72
- // If the Bound Witness does not contain all the required schemas do not index it
73
- const indexableBoundWitnesses = payloads
74
- .filter(isBoundWitness)
75
- .filter(bw => containsAll(bw.payload_schemas, this.indexableSchemas))
76
- // If the Payload is not one of the indexable schemas do not index it
77
- const indexablePayloads = payloads.filter(p => this.isIndexablePayload(p))
78
- // If there is nothing to index, return an empty array
79
- if (indexableBoundWitnesses.length === 0 || indexablePayloads.length === 0) return []
80
- // Hash all the indexable data once
81
- const [bwDictionary, payloadDictionary] = await Promise.all([
82
- PayloadBuilder.toHashMap(indexableBoundWitnesses),
83
- PayloadBuilder.toAllHashMap(indexablePayloads),
84
- ])
85
-
86
- // Initialize the array for validIndexableTuples outside of the loop
87
- const validIndexableTuples: IndexableHashes[] = []
88
-
89
- // Iterate over each entry in bwDictionary
90
- for (const [bwHash, bw] of Object.entries(bwDictionary) as [Hash, BoundWitness][]) {
91
- // Find the combinations of payloads that satisfy the required schemas
92
- const combinations = intraBoundwitnessSchemaCombinations(bw, this.indexableSchemas)
93
-
94
- // Iterate over each combination
95
- for (const combination of combinations) {
96
- const indexablePayloads = combination.map(hash => payloadDictionary[hash]).filter(exists)
97
-
98
- // If we found the right amount of indexable payloads (of the correct schema as checked
99
- // above) in this BW, then index it
100
- if (indexablePayloads.length === this.indexableSchemas.length) {
101
- validIndexableTuples.push([bwHash, ...combination])
102
- }
103
- }
104
- }
105
-
106
- // Create the indexes from the tuples
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({}, ...indexFields))
121
- .meta({ $sources })
122
- .build()
123
- })
124
- return indexes.flat()
125
- }
126
-
127
- /**
128
- * Identifies if a payload is one that is indexed by this diviner
129
- * @param x The candidate payload
130
- * @returns True if the payload is one indexed by this diviner, false otherwise
131
- */
132
- protected isIndexablePayload = (x: unknown) => {
133
- return isAnyPayload(x) && this.indexableSchemas.includes(x?.schema)
134
- }
135
-
136
- /**
137
- * Identifies if a schema is one that is indexed by this diviner
138
- * @param schema The candidate schema
139
- * @returns True if this schema is one indexed by this diviner, false otherwise
140
- */
141
- protected isIndexableSchema = (schema?: Schema | null) => {
142
- return typeof schema === 'string' ? this.indexableSchemas.includes(schema) : false
143
- }
144
- }
@@ -1 +0,0 @@
1
- export * from './Diviner.ts'
@@ -1,30 +0,0 @@
1
- import { AbstractDiviner } from '@xyo-network/diviner-abstract'
2
- import { isPayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
3
- import { TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDivinerConfigSchema } from '@xyo-network/diviner-temporal-indexing-model'
4
- import type { Labels } from '@xyo-network/module-model'
5
- import type { Payload, Schema } from '@xyo-network/payload-model'
6
-
7
- /**
8
- * Transforms an ImageThumbnailIndex response into an ImageThumbnailResponse response
9
- */
10
- export class TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner extends AbstractDiviner {
11
- static override readonly configSchemas: Schema[] = [
12
- ...super.configSchemas,
13
- TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDivinerConfigSchema,
14
- ]
15
-
16
- static override readonly defaultConfigSchema: Schema = TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDivinerConfigSchema
17
- static override readonly labels: Labels = {
18
- ...super.labels,
19
- 'network.xyo.diviner.stage': 'indexQueryResponseToDivinerQueryResponseDiviner',
20
- }
21
-
22
- protected override async divineHandler(payloads: Payload[] = []): Promise<Payload[]> {
23
- // We're not doing anything with the query payloads but some diviners
24
- // might want to use this to transform from the query to the response (for example
25
- // if we use a plaintext value in the query to generate a hash key in the index)
26
- // const queries = payloads.filter(isPayloadDivinerQueryPayload)
27
- const responses = payloads.filter(p => !isPayloadDivinerQueryPayload(p))
28
- return await Promise.resolve(responses)
29
- }
30
- }
@@ -1 +0,0 @@
1
- export * from './Diviner.ts'
@@ -1,160 +0,0 @@
1
- import { assertEx, exists } from '@xylabs/sdk-js'
2
- import type { ArchivistInstance, ArchivistNextOptions } from '@xyo-network/archivist-model'
3
- import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
4
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
5
- import { isBoundWitness } from '@xyo-network/boundwitness-model'
6
- import { payloadSchemasContainsAll } from '@xyo-network/boundwitness-validator'
7
- import { AbstractDiviner } from '@xyo-network/diviner-abstract'
8
- import type { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'
9
- import type { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'
10
- import type { IndexingDivinerState } from '@xyo-network/diviner-indexing-model'
11
- import type { TemporalIndexingDivinerStateToIndexCandidateDivinerParams } from '@xyo-network/diviner-temporal-indexing-model'
12
- import { TemporalIndexingDivinerStateToIndexCandidateDivinerConfigSchema } from '@xyo-network/diviner-temporal-indexing-model'
13
- import { DivinerWrapper } from '@xyo-network/diviner-wrapper'
14
- import type {
15
- Labels, ModuleIdentifier, ModuleState,
16
- } from '@xyo-network/module-model'
17
- import { isModuleState, ModuleStateSchema } from '@xyo-network/module-model'
18
- import type {
19
- Payload, Schema,
20
- WithStorageMeta,
21
- } from '@xyo-network/payload-model'
22
- import { SequenceConstants } from '@xyo-network/payload-model'
23
- import { intraBoundwitnessSchemaCombinations } from '@xyo-network/payload-utils'
24
- import type { TimeStamp } from '@xyo-network/witness-timestamp'
25
- import { TimestampSchema } from '@xyo-network/witness-timestamp'
26
-
27
- /**
28
- * All Payload types involved in index candidates for indexing
29
- */
30
- export type IndexCandidate = BoundWitness | Payload | TimeStamp
31
-
32
- /**
33
- * The response from the TemporalStateToIndexCandidateDiviner
34
- */
35
- export type TemporalStateToIndexCandidateDivinerResponse = [
36
- /**
37
- * The next state of the diviner
38
- */
39
- nextState: ModuleState<IndexingDivinerState>,
40
- /**
41
- * The index candidates
42
- */
43
- ...IndexCandidate[],
44
- ]
45
-
46
- /**
47
- * The default order to search Bound Witnesses to identify index candidates
48
- */
49
- const order = 'asc'
50
-
51
- /**
52
- * The name of the module (for logging purposes)
53
- */
54
- const moduleName = 'TemporalIndexingDivinerStateToIndexCandidateDiviner'
55
-
56
- /**
57
- * Transforms candidates for image thumbnail indexing into their indexed representation
58
- */
59
- export class TemporalIndexingDivinerStateToIndexCandidateDiviner<
60
- TParams extends TemporalIndexingDivinerStateToIndexCandidateDivinerParams = TemporalIndexingDivinerStateToIndexCandidateDivinerParams,
61
- > extends AbstractDiviner<TParams, Payload, ModuleState | IndexCandidate> {
62
- static override readonly configSchemas: Schema[] = [...super.configSchemas, TemporalIndexingDivinerStateToIndexCandidateDivinerConfigSchema]
63
- static override readonly defaultConfigSchema: Schema = TemporalIndexingDivinerStateToIndexCandidateDivinerConfigSchema
64
- static override readonly labels: Labels = {
65
- ...super.labels,
66
- 'network.xyo.diviner.stage': 'stateToIndexCandidateDiviner',
67
- }
68
-
69
- get payloadDivinerLimit() {
70
- return this.config.payloadDivinerLimit ?? 1000
71
- }
72
-
73
- /**
74
- * The required payload_schemas within BoundWitnesses to identify index candidates
75
- */
76
- protected get payload_schemas(): Schema[] {
77
- const schemas = this.config.filter?.payload_schemas
78
- return [TimestampSchema, ...(schemas ?? [])]
79
- }
80
-
81
- protected override async divineHandler(payloads: Payload[] = []): Promise<TemporalStateToIndexCandidateDivinerResponse> {
82
- // Retrieve the last state from what was passed in
83
- const lastState = payloads.find(isModuleState<IndexingDivinerState>)
84
- // If there is no last state, start from the beginning
85
- ?? { schema: ModuleStateSchema, state: { cursor: SequenceConstants.minLocalSequence } }
86
-
87
- // Get the last cursor
88
- const cursor = lastState?.state?.cursor
89
- // Get the archivist for the store
90
- const sourceArchivist = await this.getArchivistForStore()
91
- if (!sourceArchivist) return [lastState]
92
-
93
- // Get the next batch of results
94
- const nextOffset: ArchivistNextOptions = { limit: this.payloadDivinerLimit, order }
95
- // Only use the cursor if it's a valid offset
96
- if (cursor !== SequenceConstants.minLocalSequence) nextOffset.cursor = cursor
97
- // Get next batch of results starting from the offset
98
- const next = await sourceArchivist.next(nextOffset)
99
- if (next.length === 0) return [lastState]
100
-
101
- const batch = next.filter(x => isBoundWitness(x))
102
- .filter(exists)
103
- .filter(bw => payloadSchemasContainsAll(bw, this.payload_schemas))
104
- // Get source data
105
- const indexCandidates: IndexCandidate[] = (await Promise.all(batch.map(bw => this.getPayloadsInBoundWitness(bw, sourceArchivist))))
106
- .filter(exists)
107
- .flat()
108
- const nextCursor = assertEx(next.at(-1)?._sequence, () => `${moduleName}: Expected next to have a sequence`)
109
- const nextState: ModuleState<IndexingDivinerState> = { schema: ModuleStateSchema, state: { ...lastState.state, cursor: nextCursor } }
110
- return [nextState, ...indexCandidates]
111
- }
112
-
113
- /**
114
- * Retrieves the archivist for the payloadStore
115
- * @returns The archivist for the payloadStore or undefined if not resolvable
116
- */
117
- protected async getArchivistForStore(): Promise<ArchivistWrapper | undefined> {
118
- // It should be defined, so we'll error if it's not
119
- const name: ModuleIdentifier = assertEx(
120
- this.config?.payloadStore?.archivist,
121
- () => `${moduleName}: Config for payloadStore.archivist not specified`,
122
- )
123
- // It might not be resolvable (yet), so we'll return undefined if it's not
124
- const mod = await this.resolve(name)
125
- if (!mod) return undefined
126
- // Return the wrapped archivist
127
- return ArchivistWrapper.wrap(mod, this.account)
128
- }
129
-
130
- /**
131
- * Retrieves the BoundWitness Diviner for the payloadStore
132
- * @returns The BoundWitness Diviner for the payloadStore or undefined if not resolvable
133
- */
134
- protected async getBoundWitnessDivinerForStore() {
135
- // It should be defined, so we'll error if it's not
136
- const name: ModuleIdentifier = assertEx(
137
- this.config?.payloadStore?.boundWitnessDiviner,
138
- () => `${moduleName}: Config for payloadStore.boundWitnessDiviner not specified`,
139
- )
140
- // It might not be resolvable (yet), so we'll return undefined if it's not
141
- const mod = await this.resolve(name)
142
- if (!mod) return
143
- // Return the wrapped diviner
144
- return DivinerWrapper.wrap<
145
- DivinerWrapper<
146
- BoundWitnessDiviner<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>,
147
- BoundWitnessDivinerQueryPayload,
148
- WithStorageMeta<BoundWitness>
149
- >
150
- >(mod, this.account)
151
- }
152
-
153
- protected async getPayloadsInBoundWitness(bw: BoundWitness, archivist: ArchivistInstance): Promise<IndexCandidate[] | undefined> {
154
- const combinations = intraBoundwitnessSchemaCombinations(bw, this.payload_schemas).flat()
155
- if (combinations.length === 0) return undefined
156
- const hashes = new Set(combinations)
157
- const indexCandidates = await archivist.get([...hashes])
158
- return [bw, ...indexCandidates]
159
- }
160
- }
@@ -1 +0,0 @@
1
- export * from './Diviner.ts'
@@ -1,59 +0,0 @@
1
- {
2
- "$schema": "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/compilations/schema.json",
3
- "nodes": [
4
- {
5
- "config": {
6
- "name": "DivinerTest",
7
- "schema": "network.xyo.node.config"
8
- },
9
- "modules": {
10
- "public": [
11
- {
12
- "config": {
13
- "language": "javascript",
14
- "name": "ImageThumbnailArchivist",
15
- "schema": "network.xyo.archivist.config"
16
- }
17
- },
18
- {
19
- "config": {
20
- "archivist": "ImageThumbnailArchivist",
21
- "language": "javascript",
22
- "name": "ImageThumbnailBoundWitnessDiviner",
23
- "schema": "network.xyo.diviner.boundwitness.config"
24
- }
25
- },
26
- {
27
- "config": {
28
- "archivist": "ImageThumbnailArchivist",
29
- "language": "javascript",
30
- "name": "ImageThumbnailPayloadDiviner",
31
- "schema": "network.xyo.diviner.payload.config"
32
- }
33
- },
34
- {
35
- "config": {
36
- "filter": {
37
- "payload_schemas": [
38
- "network.xyo.image.thumbnail"
39
- ]
40
- },
41
- "labels": {
42
- "network.xyo.diviner.stage": "stateToIndexCandidateDiviner"
43
- },
44
- "language": "javascript",
45
- "name": "TemporalStateToIndexCandidateDiviner",
46
- "payloadStore": {
47
- "archivist": "ImageThumbnailArchivist",
48
- "boundWitnessDiviner": "ImageThumbnailBoundWitnessDiviner",
49
- "payloadDiviner": "ImageThumbnailPayloadDiviner"
50
- },
51
- "schema": "network.xyo.diviner.config"
52
- }
53
- }
54
- ]
55
- }
56
- }
57
- ],
58
- "schema": "network.xyo.manifest"
59
- }
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './Diviner.ts'
2
- export * from './DivinerQueryToIndexQueryDiviner/index.ts'
3
- export * from './IndexCandidateToIndexDiviner/index.ts'
4
- export * from './IndexQueryResponseToDivinerQueryResponseDiviner/index.ts'
5
- export * from './StateToIndexCandidateDiviner/index.ts'
@@ -1,206 +0,0 @@
1
- {
2
- "nodes": [
3
- {
4
- "config": {
5
- "name": "DivinerTest",
6
- "schema": "network.xyo.node.config"
7
- },
8
- "modules": {
9
- "public": [
10
- {
11
- "config": {
12
- "language": "javascript",
13
- "name": "AddressStateArchivist",
14
- "schema": "network.xyo.archivist.config",
15
- "storeQueries": false
16
- }
17
- },
18
- {
19
- "config": {
20
- "archivist": "AddressStateArchivist",
21
- "language": "javascript",
22
- "name": "AddressStateBoundWitnessDiviner",
23
- "schema": "network.xyo.diviner.boundwitness.config"
24
- }
25
- },
26
- {
27
- "config": {
28
- "archivist": "AddressStateArchivist",
29
- "language": "javascript",
30
- "name": "AddressStatePayloadDiviner",
31
- "schema": "network.xyo.diviner.payload.config"
32
- }
33
- },
34
- {
35
- "config": {
36
- "language": "javascript",
37
- "name": "ImageThumbnailArchivist",
38
- "schema": "network.xyo.archivist.config"
39
- }
40
- },
41
- {
42
- "config": {
43
- "archivist": "ImageThumbnailArchivist",
44
- "language": "javascript",
45
- "name": "ImageThumbnailBoundWitnessDiviner",
46
- "schema": "network.xyo.diviner.boundwitness.config"
47
- }
48
- },
49
- {
50
- "config": {
51
- "archivist": "ImageThumbnailArchivist",
52
- "language": "javascript",
53
- "name": "ImageThumbnailPayloadDiviner",
54
- "schema": "network.xyo.diviner.payload.config"
55
- }
56
- },
57
- {
58
- "config": {
59
- "language": "javascript",
60
- "name": "ImageThumbnailDivinerIndexArchivist",
61
- "schema": "network.xyo.archivist.config"
62
- }
63
- },
64
- {
65
- "config": {
66
- "archivist": "ImageThumbnailDivinerIndexArchivist",
67
- "language": "javascript",
68
- "name": "ImageThumbnailDivinerIndexBoundWitnessDiviner",
69
- "schema": "network.xyo.diviner.boundwitness.config"
70
- }
71
- },
72
- {
73
- "config": {
74
- "archivist": "ImageThumbnailDivinerIndexArchivist",
75
- "language": "javascript",
76
- "name": "ImageThumbnailDivinerIndexPayloadDiviner",
77
- "schema": "network.xyo.diviner.payload.config"
78
- }
79
- },
80
- {
81
- "config": {
82
- "filter": {
83
- "payload_schemas": [
84
- "network.xyo.image.thumbnail"
85
- ]
86
- },
87
- "labels": {
88
- "network.xyo.diviner.stage": "stateToIndexCandidateDiviner",
89
- "network.xyo.image.thumbnail": "diviner"
90
- },
91
- "language": "javascript",
92
- "name": "ImageThumbnailStateToIndexCandidateDiviner",
93
- "payloadStore": {
94
- "archivist": "ImageThumbnailArchivist",
95
- "boundWitnessDiviner": "ImageThumbnailBoundWitnessDiviner",
96
- "payloadDiviner": "ImageThumbnailPayloadDiviner"
97
- },
98
- "schema": "network.xyo.diviner.config"
99
- }
100
- },
101
- {
102
- "config": {
103
- "labels": {
104
- "network.xyo.diviner.stage": "indexCandidateToIndexDiviner",
105
- "network.xyo.image.thumbnail": "diviner"
106
- },
107
- "language": "javascript",
108
- "name": "ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner",
109
- "schema": "network.xyo.diviner.config",
110
- "schemaTransforms": {
111
- "network.xyo.image.thumbnail": [
112
- {
113
- "destinationField": "url",
114
- "sourcePathExpression": "$.sourceUrl"
115
- },
116
- {
117
- "destinationField": "status",
118
- "sourcePathExpression": "$.http.status"
119
- }
120
- ],
121
- "network.xyo.timestamp": [
122
- {
123
- "destinationField": "timestamp",
124
- "sourcePathExpression": "$.timestamp"
125
- }
126
- ]
127
- }
128
- }
129
- },
130
- {
131
- "config": {
132
- "divinerQuerySchema": "network.xyo.diviner.payload.query",
133
- "indexQuerySchema": "network.xyo.diviner.payload.query",
134
- "indexSchema": "network.xyo.diviner.indexing.temporal.result.index",
135
- "labels": {
136
- "network.xyo.diviner.stage": "divinerQueryToIndexQueryDiviner",
137
- "network.xyo.image.thumbnail": "diviner"
138
- },
139
- "language": "javascript",
140
- "name": "ImageThumbnailQueryToImageThumbnailIndexQueryDiviner",
141
- "schema": "network.xyo.diviner.config",
142
- "schemaTransforms": {
143
- "network.xyo.diviner.payload.query": [
144
- {
145
- "destinationField": "url",
146
- "sourcePathExpression": "$.url"
147
- },
148
- {
149
- "defaultValue": 1,
150
- "destinationField": "limit",
151
- "sourcePathExpression": "$.limit"
152
- },
153
- {
154
- "defaultValue": "desc",
155
- "destinationField": "order",
156
- "sourcePathExpression": "$.order"
157
- },
158
- {
159
- "destinationField": "status",
160
- "sourcePathExpression": "$.status"
161
- }
162
- ]
163
- }
164
- }
165
- },
166
- {
167
- "config": {
168
- "labels": {
169
- "network.xyo.diviner.stage": "indexQueryResponseToDivinerQueryResponseDiviner",
170
- "network.xyo.image.thumbnail": "diviner"
171
- },
172
- "language": "javascript",
173
- "name": "ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner",
174
- "schema": "network.xyo.diviner.config"
175
- }
176
- },
177
- {
178
- "config": {
179
- "indexStore": {
180
- "archivist": "ImageThumbnailDivinerIndexArchivist",
181
- "boundWitnessDiviner": "ImageThumbnailDivinerIndexBoundWitnessDiviner",
182
- "payloadDiviner": "ImageThumbnailDivinerIndexPayloadDiviner"
183
- },
184
- "indexingDivinerStages": {
185
- "divinerQueryToIndexQueryDiviner": "ImageThumbnailQueryToImageThumbnailIndexQueryDiviner",
186
- "indexCandidateToIndexDiviner": "ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner",
187
- "indexQueryResponseToDivinerQueryResponseDiviner": "ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner",
188
- "stateToIndexCandidateDiviner": "ImageThumbnailStateToIndexCandidateDiviner"
189
- },
190
- "language": "javascript",
191
- "name": "ImageThumbnailDiviner",
192
- "pollFrequency": 100,
193
- "schema": "network.xyo.diviner.indexing.config",
194
- "stateStore": {
195
- "archivist": "AddressStateArchivist",
196
- "boundWitnessDiviner": "AddressStateBoundWitnessDiviner",
197
- "payloadDiviner": "AddressStatePayloadDiviner"
198
- }
199
- }
200
- }
201
- ]
202
- }
203
- }
204
- ],
205
- "schema": "network.xyo.manifest"
206
- }