@xyo-network/diviner-payload-generic 5.3.20 → 5.3.24

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-payload-generic",
3
- "version": "5.3.20",
3
+ "version": "5.3.24",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,42 +30,60 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
- "!**/*.test.*"
35
+ "!**/*.test.*",
36
+ "README.md"
37
37
  ],
38
38
  "dependencies": {
39
- "@xyo-network/archivist-model": "~5.3.20",
40
- "@xyo-network/diviner-model": "~5.3.20",
41
- "@xyo-network/diviner-payload-abstract": "~5.3.20",
42
- "@xyo-network/diviner-payload-model": "~5.3.20",
43
- "@xyo-network/module-model": "~5.3.20",
44
- "@xyo-network/payload-builder": "~5.3.20",
45
- "@xyo-network/payload-model": "~5.3.20",
46
- "async-mutex": "~0.5.0"
39
+ "async-mutex": "~0.5.0",
40
+ "@xyo-network/archivist-model": "~5.3.24",
41
+ "@xyo-network/diviner-model": "~5.3.24",
42
+ "@xyo-network/diviner-payload-model": "~5.3.24",
43
+ "@xyo-network/diviner-payload-abstract": "~5.3.24",
44
+ "@xyo-network/payload-builder": "~5.3.24",
45
+ "@xyo-network/module-model": "~5.3.24",
46
+ "@xyo-network/payload-model": "~5.3.24"
47
47
  },
48
48
  "devDependencies": {
49
- "@xylabs/sdk-js": "^5.0.90",
50
- "@xylabs/ts-scripts-common": "~7.5.6",
51
- "@xylabs/ts-scripts-yarn3": "~7.5.6",
52
- "@xylabs/tsconfig": "~7.5.6",
53
- "@xylabs/vitest-extended": "~5.0.90",
54
- "@xyo-network/archivist-indexeddb": "~5.3.20",
55
- "@xyo-network/archivist-memory": "~5.3.20",
56
- "@xyo-network/node-memory": "~5.3.20",
57
- "@xyo-network/payload-builder": "~5.3.20",
49
+ "@opentelemetry/api": "^1.9.1",
50
+ "@types/node": "^25.5.0",
51
+ "@xylabs/indexed-db": "^5.0.93",
52
+ "@xylabs/sdk-js": "^5.0.93",
53
+ "@xylabs/ts-scripts-common": "~7.6.16",
54
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
55
+ "@xylabs/tsconfig": "~7.6.16",
56
+ "@xylabs/vitest-extended": "~5.0.93",
57
+ "acorn": "^8.16.0",
58
+ "async-mutex": "~0.5.0",
59
+ "axios": "^1.14.0",
60
+ "esbuild": "^0.28.0",
61
+ "ethers": "^6.16.0",
58
62
  "fake-indexeddb": "~6.2.5",
63
+ "idb": "^8.0.3",
64
+ "tslib": "^2.8.1",
59
65
  "typescript": "~5.9.3",
66
+ "vite": "^8.0.3",
60
67
  "vitest": "~4.1.2",
61
- "zod": "^4.3.6"
68
+ "zod": "^4.3.6",
69
+ "@xyo-network/archivist-indexeddb": "~5.3.24",
70
+ "@xyo-network/archivist-model": "~5.3.24",
71
+ "@xyo-network/archivist-memory": "~5.3.24",
72
+ "@xyo-network/diviner-model": "~5.3.24",
73
+ "@xyo-network/module-model": "~5.3.24",
74
+ "@xyo-network/diviner-payload-model": "~5.3.24",
75
+ "@xyo-network/diviner-payload-abstract": "~5.3.24",
76
+ "@xyo-network/node-memory": "~5.3.24",
77
+ "@xyo-network/payload-model": "~5.3.24",
78
+ "@xyo-network/payload-builder": "~5.3.24"
62
79
  },
63
80
  "peerDependencies": {
64
81
  "@xylabs/sdk-js": "^5",
82
+ "ethers": "^6",
65
83
  "tslib": "^2.8.1",
66
84
  "zod": "^4"
67
85
  },
68
86
  "publishConfig": {
69
87
  "access": "public"
70
88
  }
71
- }
89
+ }
package/src/Diviner.ts DELETED
@@ -1,193 +0,0 @@
1
- import type { EventListener, Hex } from '@xylabs/sdk-js'
2
- import {
3
- assertEx, filterAs, forget,
4
- } from '@xylabs/sdk-js'
5
- import type { ArchivistInstance, ArchivistModuleEventData } from '@xyo-network/archivist-model'
6
- import type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'
7
- import { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'
8
- import type {
9
- Order,
10
- PayloadDivinerConfig,
11
- PayloadDivinerParams,
12
- PayloadDivinerQueryPayload,
13
- } from '@xyo-network/diviner-payload-model'
14
- import { asPayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
15
- import { creatableModule } from '@xyo-network/module-model'
16
- import { PayloadBuilder } from '@xyo-network/payload-builder'
17
- import {
18
- asSchema,
19
- type Payload, type Schema,
20
- type Sequence,
21
- type WithStorageMeta,
22
- } from '@xyo-network/payload-model'
23
- import { Mutex } from 'async-mutex'
24
-
25
- const DEFAULT_INDEX_BATCH_SIZE = 100 as const
26
- const DEFAULT_MAX_INDEX_SIZE = 8000 as const
27
-
28
- export const GenericPayloadDivinerConfigSchema = asSchema('network.xyo.diviner.payload.generic.config', true)
29
- export type GenericPayloadDivinerConfigSchema = typeof GenericPayloadDivinerConfigSchema
30
-
31
- export type GenericPayloadDivinerConfig = PayloadDivinerConfig<
32
- {
33
- indexes?: string[]
34
- },
35
- GenericPayloadDivinerConfigSchema
36
- >
37
-
38
- @creatableModule()
39
- export class GenericPayloadDiviner<
40
- TParams extends PayloadDivinerParams<GenericPayloadDivinerConfig> = PayloadDivinerParams<GenericPayloadDivinerConfig>,
41
- TIn extends PayloadDivinerQueryPayload = PayloadDivinerQueryPayload,
42
- TOut extends WithStorageMeta<Payload> = WithStorageMeta<Payload>,
43
- TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<
44
- DivinerInstance<TParams, TIn, TOut>,
45
- TIn,
46
- TOut
47
- >,
48
- > extends PayloadDiviner<TParams, TIn, TOut, TEventData> {
49
- static override readonly configSchemas: Schema[] = [...super.configSchemas, GenericPayloadDivinerConfigSchema]
50
- static override readonly defaultConfigSchema: Schema = GenericPayloadDivinerConfigSchema
51
-
52
- protected indexMaps: Record<string, WithStorageMeta<TOut>[]> = {}
53
- protected payloadsWithMeta: WithStorageMeta<TOut>[] = []
54
-
55
- private _archivistInstance?: ArchivistInstance
56
- private _cursor?: Sequence
57
- private _updatePayloadPairsMutex = new Mutex()
58
-
59
- protected get indexBatchSize() {
60
- return this.config.indexBatchSize ?? DEFAULT_INDEX_BATCH_SIZE
61
- }
62
-
63
- protected get indexes(): string[] {
64
- return ['schema', ...(this.config.indexes ?? [])]
65
- }
66
-
67
- protected get maxIndexSize() {
68
- return this.config.maxIndexSize ?? DEFAULT_MAX_INDEX_SIZE
69
- }
70
-
71
- protected all(order: Order = 'desc', cursor?: Hex) {
72
- const payloads = this.payloadsWithMeta.toSorted(PayloadBuilder.compareStorageMeta)
73
- if (order === 'desc') payloads.reverse()
74
- const startIndex = (cursor ? (payloads.findIndex(payload => payload._sequence === cursor) ?? -1) : -1) + 1
75
- return payloads.slice(startIndex)
76
- }
77
-
78
- protected override async archivistInstance(): Promise<ArchivistInstance | undefined>
79
- protected override async archivistInstance(required: true): Promise<ArchivistInstance>
80
- protected override async archivistInstance(required = false): Promise<ArchivistInstance | undefined> {
81
- if (!this._archivistInstance) {
82
- const archivist = await super.archivistInstance()
83
- if (required && !archivist) {
84
- throw new Error('Failed to find archivist')
85
- }
86
- archivist?.on('inserted', this.onArchivistInserted)
87
- archivist?.on('cleared', this.onArchivistCleared)
88
- archivist?.on('deleted', this.onArchivistDeleted)
89
- this._archivistInstance = archivist
90
- }
91
- return this._archivistInstance
92
- }
93
-
94
- protected async clearIndex() {
95
- await this._updatePayloadPairsMutex.runExclusive(() => {
96
- this._cursor = undefined
97
- this.payloadsWithMeta = []
98
- this.indexMaps = {}
99
- })
100
- }
101
-
102
- protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {
103
- const filters = filterAs(payloads ?? [], asPayloadDivinerQueryPayload)
104
- assertEx(filters.length < 2, () => 'Multiple PayloadDivinerQuery payloads may not be specified')
105
- const filter = assertEx(filters.shift(), () => 'No PayloadDivinerQuery specified') as PayloadDivinerQueryPayload
106
- await this.updateIndex()
107
-
108
- const {
109
-
110
- schema, schemas, order, limit, cursor, ...props
111
- } = filter
112
- let all: TOut[] = this.all(order, cursor)
113
- if (all) {
114
- if (schemas?.length) all = all.filter(payload => schemas.includes(payload.schema))
115
- if (Object.keys(props).length > 0) {
116
- const additionalFilterCriteria = Object.entries(props)
117
- for (const [prop, filter] of additionalFilterCriteria) {
118
- const property = prop as keyof TOut
119
- all
120
- = Array.isArray(filter)
121
- ? all.filter(payload =>
122
- filter.every((value) => {
123
- const prop = payload?.[property]
124
- // TODO: This seems to be written just to check arrays, and now that $meta is there, need to check type?
125
- return Array.isArray(prop) && prop.includes?.(value)
126
- }))
127
- : all.filter(payload => payload?.[property] === filter)
128
- }
129
- }
130
- return limit ? all.slice(0, limit) : all
131
- } else {
132
- throw new Error('Archivist does not support "all"')
133
- }
134
- }
135
-
136
- protected onArchivistCleared: EventListener<ArchivistModuleEventData['cleared']> = () => {
137
- forget(
138
- (async () => {
139
- await this.clearIndex()
140
- await this.updateIndex()
141
- })(),
142
- )
143
- }
144
-
145
- // we are just rebuilding the entire index at this point on delete since large archivists do not support delete
146
- protected onArchivistDeleted: EventListener<ArchivistModuleEventData['deleted']> = () => {
147
- forget(
148
- (async () => {
149
- await this.clearIndex()
150
- await this.updateIndex()
151
- })(),
152
- )
153
- }
154
-
155
- protected onArchivistInserted: EventListener<ArchivistModuleEventData['inserted']> = () => {
156
- forget(this.updateIndex())
157
- }
158
-
159
- protected override async stopHandler(_timeout?: number | undefined) {
160
- await super.stopHandler()
161
- const archivist = await this.archivistInstance(true)
162
- archivist.off('inserted', this.onArchivistInserted)
163
- archivist.off('deleted', this.onArchivistDeleted)
164
- archivist.off('cleared', this.onArchivistCleared)
165
- }
166
-
167
- // index any new payloads
168
- protected async updateIndex() {
169
- await this._updatePayloadPairsMutex.runExclusive(async () => {
170
- const archivist = await this.archivistInstance(true)
171
- let newPayloads = await archivist.next({ limit: 100, cursor: this._cursor }) as TOut[]
172
- while (newPayloads.length > 0) {
173
- this._cursor = newPayloads.at(-1)?._sequence
174
- assertEx(this.payloadsWithMeta.length + newPayloads.length <= this.maxIndexSize, () => 'maxIndexSize exceeded')
175
- this.indexPayloads(newPayloads)
176
- newPayloads = await archivist.next({ limit: 100, cursor: this._cursor }) as TOut[]
177
- }
178
- })
179
- }
180
-
181
- private indexPayloads(payloads: WithStorageMeta<TOut>[]): Hex {
182
- this.payloadsWithMeta.push(...payloads)
183
-
184
- // update the custom indexes
185
- for (const index of this.indexes ?? []) {
186
- this.indexMaps[index] = this.indexMaps[index] ?? []
187
- for (const payload of payloads) {
188
- this.indexMaps[index].push(payload)
189
- }
190
- }
191
- return assertEx(payloads.at(-1), () => 'No payloads to index')._sequence
192
- }
193
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './Diviner.ts'