@xyo-network/diviner-image-thumbnail 2.75.16 → 2.75.18
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/dist/browser/Diviner/Diviner.d.cts +3 -3
- package/dist/browser/Diviner/Diviner.d.cts.map +1 -1
- package/dist/browser/Diviner/Diviner.d.mts +3 -3
- package/dist/browser/Diviner/Diviner.d.mts.map +1 -1
- package/dist/browser/Diviner/Diviner.d.ts +3 -3
- package/dist/browser/Diviner/Diviner.d.ts.map +1 -1
- package/dist/browser/index.cjs +19 -31
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +20 -32
- package/dist/browser/index.js.map +1 -1
- package/dist/docs.json +1967 -2533
- package/dist/node/Diviner/Diviner.d.cts +3 -3
- package/dist/node/Diviner/Diviner.d.cts.map +1 -1
- package/dist/node/Diviner/Diviner.d.mts +3 -3
- package/dist/node/Diviner/Diviner.d.mts.map +1 -1
- package/dist/node/Diviner/Diviner.d.ts +3 -3
- package/dist/node/Diviner/Diviner.d.ts.map +1 -1
- package/dist/node/index.js +21 -35
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +22 -36
- package/dist/node/index.mjs.map +1 -1
- package/package.json +26 -36
- package/src/Diviner/Diviner.ts +35 -45
- package/xy.config.ts +14 -0
package/src/Diviner/Diviner.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { exists } from '@xylabs/exists'
|
|
3
3
|
import { AbstractDiviner } from '@xyo-network/abstract-diviner'
|
|
4
|
-
import { asArchivistInstance, withArchivistModule } from '@xyo-network/archivist-model'
|
|
5
4
|
import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
|
|
5
|
+
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
6
6
|
import { isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
7
7
|
import { PayloadHasher } from '@xyo-network/core'
|
|
8
8
|
import { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
|
|
9
|
-
import {
|
|
9
|
+
import { DivinerConfigSchema } from '@xyo-network/diviner-model'
|
|
10
10
|
import { PayloadDivinerQueryPayload, PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
11
11
|
import { DivinerWrapper } from '@xyo-network/diviner-wrapper'
|
|
12
12
|
import {
|
|
@@ -73,12 +73,14 @@ export class ImageThumbnailDiviner<TParams extends ImageThumbnailDivinerParams =
|
|
|
73
73
|
const { offset } = lastState
|
|
74
74
|
// Get next batch of results
|
|
75
75
|
const boundWitnessDiviner = await this.getBoundWitnessDivinerForStore('thumbnailStore')
|
|
76
|
-
const query = new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
const query = new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })
|
|
77
|
+
.fields({
|
|
78
|
+
limit: this.payloadDivinerLimit,
|
|
79
|
+
offset,
|
|
80
|
+
order: 'asc',
|
|
81
|
+
payload_schemas: [ImageThumbnailSchema, TimestampSchema],
|
|
82
|
+
})
|
|
83
|
+
.build()
|
|
82
84
|
const batch = await boundWitnessDiviner.divine([query])
|
|
83
85
|
if (batch.length === 0) return
|
|
84
86
|
// Find all the indexable hashes in this batch
|
|
@@ -142,7 +144,7 @@ export class ImageThumbnailDiviner<TParams extends ImageThumbnailDivinerParams =
|
|
|
142
144
|
const indexArchivist = await this.getArchivistForStore('indexStore')
|
|
143
145
|
await indexArchivist.insert(indexes)
|
|
144
146
|
// Update state
|
|
145
|
-
const nextOffset = offset + batch.length
|
|
147
|
+
const nextOffset = offset + batch.length
|
|
146
148
|
const currentState = { ...lastState, offset: nextOffset }
|
|
147
149
|
await this.commitState(currentState)
|
|
148
150
|
}
|
|
@@ -154,13 +156,10 @@ export class ImageThumbnailDiviner<TParams extends ImageThumbnailDivinerParams =
|
|
|
154
156
|
* external stores.
|
|
155
157
|
*/
|
|
156
158
|
protected async commitState(state: ImageThumbnailDivinerState) {
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
await
|
|
160
|
-
|
|
161
|
-
const payload = new PayloadBuilder<ModuleState<ImageThumbnailDivinerState>>({ schema: ModuleStateSchema }).fields({ state }).build()
|
|
162
|
-
await mod.insert([payload])
|
|
163
|
-
})
|
|
159
|
+
const archivist = await this.getArchivistForStore('stateStore')
|
|
160
|
+
const payload = new PayloadBuilder<ModuleState<ImageThumbnailDivinerState>>({ schema: ModuleStateSchema }).fields({ state }).build()
|
|
161
|
+
const [bw] = await new BoundWitnessBuilder().payloads([payload]).witness(this.account).build()
|
|
162
|
+
await archivist.insert([bw, payload])
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
protected override async divineHandler(payloads: Payload[] = []): Promise<ImageThumbnailResult[]> {
|
|
@@ -189,24 +188,22 @@ export class ImageThumbnailDiviner<TParams extends ImageThumbnailDivinerParams =
|
|
|
189
188
|
return results
|
|
190
189
|
}
|
|
191
190
|
|
|
192
|
-
protected async getArchivistForStore(store: ConfigStore
|
|
191
|
+
protected async getArchivistForStore(store: ConfigStore) {
|
|
193
192
|
const name = assertEx(this.config?.[store]?.archivist, () => `${moduleName}: Config for ${store}.archivist not specified`)
|
|
194
193
|
const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.archivist`)
|
|
195
|
-
return
|
|
194
|
+
return ArchivistWrapper.wrap(mod, this.account)
|
|
196
195
|
}
|
|
197
196
|
|
|
198
|
-
protected async getBoundWitnessDivinerForStore(store: ConfigStore
|
|
197
|
+
protected async getBoundWitnessDivinerForStore(store: ConfigStore) {
|
|
199
198
|
const name = assertEx(this.config?.[store]?.boundWitnessDiviner, () => `${moduleName}: Config for ${store}.boundWitnessDiviner not specified`)
|
|
200
199
|
const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.boundWitnessDiviner`)
|
|
201
|
-
return wrap
|
|
202
|
-
? DivinerWrapper.wrap(mod, this.account)
|
|
203
|
-
: asDivinerInstance(mod, () => `${moduleName}: ${store}.boundWitnessDiviner is not a Diviner`)
|
|
200
|
+
return DivinerWrapper.wrap(mod, this.account)
|
|
204
201
|
}
|
|
205
202
|
|
|
206
|
-
protected async getPayloadDivinerForStore(store: ConfigStore
|
|
203
|
+
protected async getPayloadDivinerForStore(store: ConfigStore) {
|
|
207
204
|
const name = assertEx(this.config?.[store]?.payloadDiviner, () => `${moduleName}: Config for ${store}.payloadDiviner not specified`)
|
|
208
205
|
const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.payloadDiviner`)
|
|
209
|
-
return
|
|
206
|
+
return DivinerWrapper.wrap(mod, this.account)
|
|
210
207
|
}
|
|
211
208
|
|
|
212
209
|
/**
|
|
@@ -216,13 +213,15 @@ export class ImageThumbnailDiviner<TParams extends ImageThumbnailDivinerParams =
|
|
|
216
213
|
protected async retrieveState(): Promise<ImageThumbnailDivinerState | undefined> {
|
|
217
214
|
let hash: string = ''
|
|
218
215
|
const diviner = await this.getBoundWitnessDivinerForStore('stateStore')
|
|
219
|
-
const query = new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
216
|
+
const query = new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })
|
|
217
|
+
.fields({
|
|
218
|
+
address: this.account.address,
|
|
219
|
+
limit: 1,
|
|
220
|
+
offset: 0,
|
|
221
|
+
order: 'desc',
|
|
222
|
+
payload_schemas: [ModuleStateSchema],
|
|
223
|
+
})
|
|
224
|
+
.build()
|
|
226
225
|
const boundWitnesses = await diviner.divine([query])
|
|
227
226
|
if (boundWitnesses.length > 0) {
|
|
228
227
|
const boundWitness = boundWitnesses[0]
|
|
@@ -241,20 +240,11 @@ export class ImageThumbnailDiviner<TParams extends ImageThumbnailDivinerParams =
|
|
|
241
240
|
// If we able to located the last state
|
|
242
241
|
if (hash) {
|
|
243
242
|
// Get last state
|
|
244
|
-
const
|
|
245
|
-
await
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const payloads = await archivist.get([hash])
|
|
250
|
-
if (payloads.length > 0) {
|
|
251
|
-
const payload = payloads[0]
|
|
252
|
-
if (isModuleState(payload)) {
|
|
253
|
-
return payload.state
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
|
-
)
|
|
243
|
+
const archivist = await this.getArchivistForStore('stateStore')
|
|
244
|
+
const payload = (await archivist.get([hash])).find(isModuleState)
|
|
245
|
+
if (payload) {
|
|
246
|
+
return payload.state as ImageThumbnailDivinerState
|
|
247
|
+
}
|
|
258
248
|
}
|
|
259
249
|
return undefined
|
|
260
250
|
}
|
package/xy.config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
|
|
2
|
+
const config: XyTsupConfig = {
|
|
3
|
+
compile: {
|
|
4
|
+
browser: {
|
|
5
|
+
src: true,
|
|
6
|
+
},
|
|
7
|
+
node: {
|
|
8
|
+
src: true,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line import/no-default-export
|
|
14
|
+
export default config
|