@xyo-network/diviner-image-thumbnail 2.78.5 → 2.79.0
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 +4 -44
- package/dist/browser/Diviner/Diviner.d.cts.map +1 -1
- package/dist/browser/Diviner/Diviner.d.mts +4 -44
- package/dist/browser/Diviner/Diviner.d.mts.map +1 -1
- package/dist/browser/Diviner/Diviner.d.ts +4 -44
- package/dist/browser/Diviner/Diviner.d.ts.map +1 -1
- package/dist/browser/Diviner/ImageThumbnailDivinerLabels.d.cts +19 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerLabels.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerLabels.d.mts +19 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerLabels.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerLabels.d.ts +19 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerLabels.d.ts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerState.d.cts +5 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerState.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerState.d.mts +5 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerState.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerState.d.ts +5 -0
- package/dist/browser/Diviner/ImageThumbnailDivinerState.d.ts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.cts +13 -0
- package/dist/browser/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.mts +13 -0
- package/dist/browser/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.ts +13 -0
- package/dist/browser/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.ts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.cts +13 -0
- package/dist/browser/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.mts +13 -0
- package/dist/browser/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.ts +13 -0
- package/dist/browser/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.ts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.cts +13 -0
- package/dist/browser/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.mts +13 -0
- package/dist/browser/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.ts +13 -0
- package/dist/browser/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.ts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailResultQuery.d.cts +17 -0
- package/dist/browser/Diviner/ImageThumbnailResultQuery.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailResultQuery.d.mts +17 -0
- package/dist/browser/Diviner/ImageThumbnailResultQuery.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailResultQuery.d.ts +17 -0
- package/dist/browser/Diviner/ImageThumbnailResultQuery.d.ts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.cts +14 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.mts +14 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.ts +14 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.ts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.cts +50 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.mts +50 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.ts +50 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.ts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.cts +5 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.mts +5 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.ts +5 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.ts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.cts +4 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.mts +4 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.ts +4 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.ts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.cts +5 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.cts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.mts +5 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.mts.map +1 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.ts +5 -0
- package/dist/browser/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.ts.map +1 -0
- package/dist/browser/Diviner/index.d.cts +7 -0
- package/dist/browser/Diviner/index.d.cts.map +1 -1
- package/dist/browser/Diviner/index.d.mts +7 -0
- package/dist/browser/Diviner/index.d.mts.map +1 -1
- package/dist/browser/Diviner/index.d.ts +7 -0
- package/dist/browser/Diviner/index.d.ts.map +1 -1
- package/dist/browser/index.cjs +224 -196
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +229 -200
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Diviner/Diviner.d.cts +4 -44
- package/dist/node/Diviner/Diviner.d.cts.map +1 -1
- package/dist/node/Diviner/Diviner.d.mts +4 -44
- package/dist/node/Diviner/Diviner.d.mts.map +1 -1
- package/dist/node/Diviner/Diviner.d.ts +4 -44
- package/dist/node/Diviner/Diviner.d.ts.map +1 -1
- package/dist/node/Diviner/ImageThumbnailDivinerLabels.d.cts +19 -0
- package/dist/node/Diviner/ImageThumbnailDivinerLabels.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailDivinerLabels.d.mts +19 -0
- package/dist/node/Diviner/ImageThumbnailDivinerLabels.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailDivinerLabels.d.ts +19 -0
- package/dist/node/Diviner/ImageThumbnailDivinerLabels.d.ts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailDivinerState.d.cts +5 -0
- package/dist/node/Diviner/ImageThumbnailDivinerState.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailDivinerState.d.mts +5 -0
- package/dist/node/Diviner/ImageThumbnailDivinerState.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailDivinerState.d.ts +5 -0
- package/dist/node/Diviner/ImageThumbnailDivinerState.d.ts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.cts +13 -0
- package/dist/node/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.mts +13 -0
- package/dist/node/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.ts +13 -0
- package/dist/node/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.d.ts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.cts +13 -0
- package/dist/node/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.mts +13 -0
- package/dist/node/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.ts +13 -0
- package/dist/node/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.d.ts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.cts +13 -0
- package/dist/node/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.mts +13 -0
- package/dist/node/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.ts +13 -0
- package/dist/node/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.d.ts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailResultQuery.d.cts +17 -0
- package/dist/node/Diviner/ImageThumbnailResultQuery.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailResultQuery.d.mts +17 -0
- package/dist/node/Diviner/ImageThumbnailResultQuery.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailResultQuery.d.ts +17 -0
- package/dist/node/Diviner/ImageThumbnailResultQuery.d.ts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.cts +14 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.mts +14 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.ts +14 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.d.ts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.cts +50 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.mts +50 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.ts +50 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.d.ts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.cts +5 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.mts +5 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.ts +5 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.d.ts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.cts +4 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.mts +4 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.ts +4 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.d.ts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.cts +5 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.cts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.mts +5 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.mts.map +1 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.ts +5 -0
- package/dist/node/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.d.ts.map +1 -0
- package/dist/node/Diviner/index.d.cts +7 -0
- package/dist/node/Diviner/index.d.cts.map +1 -1
- package/dist/node/Diviner/index.d.mts +7 -0
- package/dist/node/Diviner/index.d.mts.map +1 -1
- package/dist/node/Diviner/index.d.ts +7 -0
- package/dist/node/Diviner/index.d.ts.map +1 -1
- package/dist/node/index.js +242 -204
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +238 -207
- package/dist/node/index.mjs.map +1 -1
- package/package.json +24 -21
- package/src/Diviner/Diviner.ts +4 -300
- package/src/Diviner/ImageThumbnailDivinerLabels.ts +26 -0
- package/src/Diviner/ImageThumbnailDivinerState.ts +5 -0
- package/src/Diviner/ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner.ts +70 -0
- package/src/Diviner/ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner.ts +61 -0
- package/src/Diviner/ImageThumbnailQueryToImageThumbnailIndexQueryDiviner.ts +43 -0
- package/src/Diviner/ImageThumbnailResultQuery.ts +19 -0
- package/src/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Config.ts +16 -0
- package/src/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Diviner.ts +134 -0
- package/src/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Params.ts +6 -0
- package/src/Diviner/ImageThumbnailStateToIndexCandidateDiviner/Schema.ts +4 -0
- package/src/Diviner/ImageThumbnailStateToIndexCandidateDiviner/index.ts +4 -0
- package/src/Diviner/ImageThumbnailStateToIndexCandidateDiviner/spec/ImageThumbnailStateToIndexCandidateDiviner.json +56 -0
- package/src/Diviner/index.ts +7 -0
- package/src/Diviner/spec/ImageThumbnailDivinerManifest.json +159 -0
package/package.json
CHANGED
|
@@ -12,31 +12,34 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.13.3",
|
|
14
14
|
"@xylabs/exists": "^2.13.3",
|
|
15
|
-
"@xyo-network/abstract-diviner": "~2.
|
|
16
|
-
"@xyo-network/archivist-model": "~2.
|
|
17
|
-
"@xyo-network/archivist-wrapper": "~2.
|
|
18
|
-
"@xyo-network/boundwitness-model": "~2.
|
|
19
|
-
"@xyo-network/core": "~2.
|
|
20
|
-
"@xyo-network/diviner-boundwitness-model": "~2.
|
|
21
|
-
"@xyo-network/diviner-
|
|
22
|
-
"@xyo-network/diviner-
|
|
23
|
-
"@xyo-network/diviner-
|
|
24
|
-
"@xyo-network/
|
|
25
|
-
"@xyo-network/
|
|
26
|
-
"@xyo-network/
|
|
27
|
-
"@xyo-network/payload-
|
|
28
|
-
"@xyo-network/
|
|
15
|
+
"@xyo-network/abstract-diviner": "~2.79.0",
|
|
16
|
+
"@xyo-network/archivist-model": "~2.79.0",
|
|
17
|
+
"@xyo-network/archivist-wrapper": "~2.79.0",
|
|
18
|
+
"@xyo-network/boundwitness-model": "~2.79.0",
|
|
19
|
+
"@xyo-network/core": "~2.79.0",
|
|
20
|
+
"@xyo-network/diviner-boundwitness-model": "~2.79.0",
|
|
21
|
+
"@xyo-network/diviner-indexing": "~2.79.0",
|
|
22
|
+
"@xyo-network/diviner-model": "~2.79.0",
|
|
23
|
+
"@xyo-network/diviner-payload-model": "~2.79.0",
|
|
24
|
+
"@xyo-network/diviner-wrapper": "~2.79.0",
|
|
25
|
+
"@xyo-network/image-thumbnail-payload-plugin": "~2.79.0",
|
|
26
|
+
"@xyo-network/module-model": "~2.79.0",
|
|
27
|
+
"@xyo-network/payload-builder": "~2.79.0",
|
|
28
|
+
"@xyo-network/payload-model": "~2.79.0",
|
|
29
|
+
"@xyo-network/url-payload-plugin": "~2.79.0",
|
|
30
|
+
"@xyo-network/witness-timestamp": "~2.79.0"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
33
|
"@xylabs/delay": "^2.13.3",
|
|
32
34
|
"@xylabs/ts-scripts-yarn3": "^3.1.21",
|
|
33
35
|
"@xylabs/tsconfig": "^3.1.21",
|
|
34
|
-
"@xyo-network/account": "~2.
|
|
35
|
-
"@xyo-network/boundwitness-builder": "~2.
|
|
36
|
-
"@xyo-network/diviner-boundwitness-memory": "~2.
|
|
37
|
-
"@xyo-network/diviner-payload-memory": "~2.
|
|
38
|
-
"@xyo-network/
|
|
39
|
-
"@xyo-network/
|
|
36
|
+
"@xyo-network/account": "~2.79.0",
|
|
37
|
+
"@xyo-network/boundwitness-builder": "~2.79.0",
|
|
38
|
+
"@xyo-network/diviner-boundwitness-memory": "~2.79.0",
|
|
39
|
+
"@xyo-network/diviner-payload-memory": "~2.79.0",
|
|
40
|
+
"@xyo-network/manifest": "~2.79.0",
|
|
41
|
+
"@xyo-network/memory-archivist": "~2.79.0",
|
|
42
|
+
"@xyo-network/node-memory": "~2.79.0",
|
|
40
43
|
"typescript": "^5.2.2"
|
|
41
44
|
},
|
|
42
45
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
@@ -79,5 +82,5 @@
|
|
|
79
82
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
80
83
|
},
|
|
81
84
|
"sideEffects": false,
|
|
82
|
-
"version": "2.
|
|
85
|
+
"version": "2.79.0"
|
|
83
86
|
}
|
package/src/Diviner/Diviner.ts
CHANGED
|
@@ -1,303 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { exists } from '@xylabs/exists'
|
|
3
|
-
import { AbstractDiviner } from '@xyo-network/abstract-diviner'
|
|
4
|
-
import { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
5
|
-
import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
|
|
6
|
-
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
7
|
-
import { isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
8
|
-
import { PayloadHasher } from '@xyo-network/core'
|
|
9
|
-
import { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
|
|
10
|
-
import { DivinerConfigSchema } from '@xyo-network/diviner-model'
|
|
11
|
-
import { PayloadDivinerQueryPayload, PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
12
|
-
import { DivinerWrapper } from '@xyo-network/diviner-wrapper'
|
|
13
|
-
import {
|
|
14
|
-
ImageThumbnail,
|
|
15
|
-
ImageThumbnailDivinerConfig,
|
|
16
|
-
ImageThumbnailDivinerConfigSchema,
|
|
17
|
-
ImageThumbnailDivinerParams,
|
|
18
|
-
ImageThumbnailResult,
|
|
19
|
-
ImageThumbnailResultIndexSchema,
|
|
20
|
-
ImageThumbnailResultInfo,
|
|
21
|
-
ImageThumbnailSchema,
|
|
22
|
-
isImageThumbnail,
|
|
23
|
-
isImageThumbnailDivinerQuery,
|
|
24
|
-
isImageThumbnailResult,
|
|
25
|
-
} from '@xyo-network/image-thumbnail-payload-plugin'
|
|
26
|
-
import { isModuleState, ModuleState, ModuleStateSchema, StateDictionary } from '@xyo-network/module-model'
|
|
27
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
28
|
-
import { Payload } from '@xyo-network/payload-model'
|
|
29
|
-
import { isTimestamp, TimeStamp, TimestampSchema } from '@xyo-network/witness-timestamp'
|
|
1
|
+
import { IndexingDiviner } from '@xyo-network/diviner-indexing'
|
|
30
2
|
|
|
31
|
-
|
|
32
|
-
offset: number
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type ConfigStoreKey = 'indexStore' | 'stateStore' | 'thumbnailStore'
|
|
36
|
-
|
|
37
|
-
type ConfigStore = Extract<keyof ImageThumbnailDivinerConfig, ConfigStoreKey>
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* The fields that will need to be indexed on in the underlying store
|
|
41
|
-
*/
|
|
42
|
-
type QueryableImageThumbnailResultProperties = Extract<keyof ImageThumbnailResultInfo, 'status' | 'success' | 'timestamp' | 'url'>
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The query that will be used to retrieve the results from the underlying store
|
|
46
|
-
*/
|
|
47
|
-
type ImageThumbnailResultQuery = PayloadDivinerQueryPayload & { schemas: [ImageThumbnailSchema] } & Pick<
|
|
48
|
-
ImageThumbnailResult,
|
|
49
|
-
QueryableImageThumbnailResultProperties
|
|
50
|
-
>
|
|
51
|
-
|
|
52
|
-
type IndexableHashes = Readonly<[boundWitnessHash: string, imageThumbnailHash: string, timestampHash: string]>
|
|
53
|
-
|
|
54
|
-
const moduleName = 'ImageThumbnailDiviner'
|
|
55
|
-
|
|
56
|
-
export class ImageThumbnailDiviner<TParams extends ImageThumbnailDivinerParams = ImageThumbnailDivinerParams> extends AbstractDiviner<TParams> {
|
|
57
|
-
static override configSchemas = [ImageThumbnailDivinerConfigSchema, DivinerConfigSchema]
|
|
58
|
-
|
|
59
|
-
private _lastState?: ImageThumbnailDivinerState
|
|
60
|
-
private _pollId?: string | number | NodeJS.Timeout
|
|
61
|
-
|
|
62
|
-
get payloadDivinerLimit() {
|
|
63
|
-
return this.config.payloadDivinerLimit ?? 1_0000
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
get pollFrequency() {
|
|
67
|
-
return this.config.pollFrequency ?? 10_000
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
private static async indexableData(indexableHashes: IndexableHashes[], archivist: ArchivistInstance) {
|
|
71
|
-
// Find all the indexable data associated with the indexable hashes
|
|
72
|
-
type IndexableData = Readonly<
|
|
73
|
-
[
|
|
74
|
-
boundWitnessHash: string,
|
|
75
|
-
imageThumbnailHash: string,
|
|
76
|
-
imageThumbnailPayload: ImageThumbnail,
|
|
77
|
-
timestampHash: string,
|
|
78
|
-
timestampPayload: TimeStamp,
|
|
79
|
-
]
|
|
80
|
-
>
|
|
81
|
-
const indexableData: IndexableData[] = (
|
|
82
|
-
await Promise.all(
|
|
83
|
-
indexableHashes.map(async ([boundWitnessHash, imageThumbnailHash, timestampHash]) => {
|
|
84
|
-
const results = await archivist.get([imageThumbnailHash, timestampHash])
|
|
85
|
-
const imageThumbnailPayload = results.find(isImageThumbnail)
|
|
86
|
-
if (!imageThumbnailPayload) {
|
|
87
|
-
console.log(
|
|
88
|
-
`${moduleName}: Could not find ${ImageThumbnailSchema} Payload (${imageThumbnailHash}) from BoundWitness (${boundWitnessHash})`,
|
|
89
|
-
)
|
|
90
|
-
return undefined
|
|
91
|
-
}
|
|
92
|
-
const timestampPayload = results.find(isTimestamp)
|
|
93
|
-
if (!timestampPayload) {
|
|
94
|
-
console.log(`${moduleName}: Could not find ${TimestampSchema} Payload (${timestampHash}) from BoundWitness (${boundWitnessHash})`)
|
|
95
|
-
return undefined
|
|
96
|
-
}
|
|
97
|
-
const calculatedImageThumbnailHash = await PayloadHasher.hashAsync(imageThumbnailPayload)
|
|
98
|
-
const calculatedTimestampHash = await PayloadHasher.hashAsync(timestampPayload)
|
|
99
|
-
if (imageThumbnailHash !== calculatedImageThumbnailHash || timestampHash !== calculatedTimestampHash) return undefined
|
|
100
|
-
return [boundWitnessHash, imageThumbnailHash, imageThumbnailPayload, timestampHash, timestampPayload] as const
|
|
101
|
-
}),
|
|
102
|
-
)
|
|
103
|
-
).filter(exists)
|
|
104
|
-
return indexableData
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
private static async indexableHashes(batch: Payload[]) {
|
|
108
|
-
// Find all the indexable hashes in this batch
|
|
109
|
-
const indexableHashes: IndexableHashes[] = (
|
|
110
|
-
await Promise.all(
|
|
111
|
-
batch.filter(isBoundWitness).map(async (bw) => {
|
|
112
|
-
const imageThumbnailIndexes = bw.payload_schemas
|
|
113
|
-
?.map((schema, index) => (schema === ImageThumbnailSchema ? index : undefined))
|
|
114
|
-
.filter(exists)
|
|
115
|
-
const timestampIndex = bw.payload_schemas?.findIndex((schema) => schema === TimestampSchema)
|
|
116
|
-
if (!imageThumbnailIndexes.length || timestampIndex === -1) return undefined
|
|
117
|
-
const imageThumbnails = bw.payload_hashes.map((hash, index) => (imageThumbnailIndexes.includes(index) ? hash : undefined)).filter(exists)
|
|
118
|
-
const timestampHash = bw.payload_hashes?.[timestampIndex]
|
|
119
|
-
const boundWitnessHash = await PayloadHasher.hashAsync(bw)
|
|
120
|
-
return imageThumbnails.map((imageThumbnailHash) => [boundWitnessHash, imageThumbnailHash, timestampHash] as const)
|
|
121
|
-
}),
|
|
122
|
-
)
|
|
123
|
-
)
|
|
124
|
-
.flat()
|
|
125
|
-
.filter(exists)
|
|
126
|
-
return indexableHashes
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Works in the background to populate index for the Diviner
|
|
131
|
-
* @returns
|
|
132
|
-
*/
|
|
133
|
-
protected backgroundDivine = async (): Promise<void> => {
|
|
134
|
-
// Load last state
|
|
135
|
-
const lastState = (await this.retrieveState()) ?? { offset: 0 }
|
|
136
|
-
const { offset } = lastState
|
|
137
|
-
// Get next batch of results
|
|
138
|
-
const boundWitnessDiviner = await this.getBoundWitnessDivinerForStore('thumbnailStore')
|
|
139
|
-
const query = new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })
|
|
140
|
-
.fields({
|
|
141
|
-
limit: this.payloadDivinerLimit,
|
|
142
|
-
offset,
|
|
143
|
-
order: 'asc',
|
|
144
|
-
payload_schemas: [ImageThumbnailSchema, TimestampSchema],
|
|
145
|
-
})
|
|
146
|
-
.build()
|
|
147
|
-
const batch = await boundWitnessDiviner.divine([query])
|
|
148
|
-
if (batch.length === 0) return
|
|
149
|
-
const indexableHashes = await ImageThumbnailDiviner.indexableHashes(batch)
|
|
150
|
-
const archivist = await this.getArchivistForStore('thumbnailStore')
|
|
151
|
-
const indexableData = await ImageThumbnailDiviner.indexableData(indexableHashes, archivist)
|
|
152
|
-
// Build index results from the indexable data
|
|
153
|
-
const indexes: ImageThumbnailResult[] = indexableData.map(
|
|
154
|
-
([boundWitnessHash, thumbnailHash, thumbnailPayload, timestampHash, timestampPayload]) => {
|
|
155
|
-
const { sourceUrl: url } = thumbnailPayload
|
|
156
|
-
const { timestamp } = timestampPayload
|
|
157
|
-
const status = thumbnailPayload.http?.status
|
|
158
|
-
//call anything with a thumbnail url a success
|
|
159
|
-
const success = !!thumbnailPayload.url
|
|
160
|
-
const sources = [boundWitnessHash, thumbnailHash, timestampHash]
|
|
161
|
-
const fields = { sources, status, success, timestamp, url }
|
|
162
|
-
const result = new PayloadBuilder<ImageThumbnailResult>({ schema: ImageThumbnailResultIndexSchema }).fields(fields).build()
|
|
163
|
-
return result
|
|
164
|
-
},
|
|
165
|
-
)
|
|
166
|
-
// Insert index results
|
|
167
|
-
const indexArchivist = await this.getArchivistForStore('indexStore')
|
|
168
|
-
await indexArchivist.insert(indexes)
|
|
169
|
-
// Update state
|
|
170
|
-
const nextOffset = offset + batch.length
|
|
171
|
-
const currentState = { ...lastState, offset: nextOffset }
|
|
172
|
-
await this.commitState(currentState)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Commit the internal state of the Diviner process. This is similar
|
|
177
|
-
* to a transaction completion in a database and should only be called
|
|
178
|
-
* when results have been successfully persisted to the appropriate
|
|
179
|
-
* external stores.
|
|
180
|
-
*/
|
|
181
|
-
protected async commitState(state: ImageThumbnailDivinerState) {
|
|
182
|
-
this._lastState = state
|
|
183
|
-
const archivist = await this.getArchivistForStore('stateStore')
|
|
184
|
-
const payload = new PayloadBuilder<ModuleState<ImageThumbnailDivinerState>>({ schema: ModuleStateSchema }).fields({ state }).build()
|
|
185
|
-
const [bw] = await new BoundWitnessBuilder().payloads([payload]).witness(this.account).build()
|
|
186
|
-
await archivist.insert([bw, payload])
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
protected override async divineHandler(payloads: Payload[] = []): Promise<ImageThumbnailResult[]> {
|
|
190
|
-
const urls = payloads.filter(isImageThumbnailDivinerQuery)
|
|
191
|
-
const diviner = await this.getPayloadDivinerForStore('indexStore')
|
|
192
|
-
const results = (
|
|
193
|
-
await Promise.all(
|
|
194
|
-
urls.map(async (payload) => {
|
|
195
|
-
const { limit: payloadLimit, offset: payloadOffset, order: payloadOrder, status: payloadStatus, success: payloadSuccess, url } = payload
|
|
196
|
-
const limit = payloadLimit ?? 1
|
|
197
|
-
const order = payloadOrder ?? 'desc'
|
|
198
|
-
const offset = payloadOffset ?? 0
|
|
199
|
-
const fields: Partial<ImageThumbnailResultQuery> = { limit, offset, order, url }
|
|
200
|
-
if (payloadSuccess !== undefined) fields.success = payloadSuccess
|
|
201
|
-
if (payloadStatus !== undefined) fields.status = payloadStatus
|
|
202
|
-
const query = new PayloadBuilder<ImageThumbnailResultQuery>({ schema: PayloadDivinerQuerySchema }).fields(fields).build()
|
|
203
|
-
return await diviner.divine([query])
|
|
204
|
-
}),
|
|
205
|
-
)
|
|
206
|
-
)
|
|
207
|
-
.flat()
|
|
208
|
-
.filter(isImageThumbnailResult)
|
|
209
|
-
return results
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
protected async getArchivistForStore(store: ConfigStore) {
|
|
213
|
-
const name = assertEx(this.config?.[store]?.archivist, () => `${moduleName}: Config for ${store}.archivist not specified`)
|
|
214
|
-
const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.archivist`)
|
|
215
|
-
return ArchivistWrapper.wrap(mod, this.account)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
protected async getBoundWitnessDivinerForStore(store: ConfigStore) {
|
|
219
|
-
const name = assertEx(this.config?.[store]?.boundWitnessDiviner, () => `${moduleName}: Config for ${store}.boundWitnessDiviner not specified`)
|
|
220
|
-
const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.boundWitnessDiviner`)
|
|
221
|
-
return DivinerWrapper.wrap(mod, this.account)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
protected async getPayloadDivinerForStore(store: ConfigStore) {
|
|
225
|
-
const name = assertEx(this.config?.[store]?.payloadDiviner, () => `${moduleName}: Config for ${store}.payloadDiviner not specified`)
|
|
226
|
-
const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.payloadDiviner`)
|
|
227
|
-
return DivinerWrapper.wrap(mod, this.account)
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Retrieves the last state of the Diviner process. Used to recover state after
|
|
232
|
-
* preemptions, reboots, etc.
|
|
233
|
-
*/
|
|
234
|
-
protected async retrieveState(): Promise<ImageThumbnailDivinerState | undefined> {
|
|
235
|
-
if (this._lastState) return this._lastState
|
|
236
|
-
let hash: string = ''
|
|
237
|
-
const diviner = await this.getBoundWitnessDivinerForStore('stateStore')
|
|
238
|
-
const query = new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })
|
|
239
|
-
.fields({
|
|
240
|
-
address: this.account.address,
|
|
241
|
-
limit: 1,
|
|
242
|
-
offset: 0,
|
|
243
|
-
order: 'desc',
|
|
244
|
-
payload_schemas: [ModuleStateSchema],
|
|
245
|
-
})
|
|
246
|
-
.build()
|
|
247
|
-
const boundWitnesses = await diviner.divine([query])
|
|
248
|
-
if (boundWitnesses.length > 0) {
|
|
249
|
-
const boundWitness = boundWitnesses[0]
|
|
250
|
-
if (isBoundWitness(boundWitness)) {
|
|
251
|
-
// Find the index for this address in the BoundWitness that is a ModuleState
|
|
252
|
-
hash = boundWitness.addresses
|
|
253
|
-
.map((address, index) => ({ address, index }))
|
|
254
|
-
.filter(({ address }) => address === this.account.address)
|
|
255
|
-
.reduce(
|
|
256
|
-
(prev, curr) => (boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev),
|
|
257
|
-
'',
|
|
258
|
-
)
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// If we able to located the last state
|
|
263
|
-
if (hash) {
|
|
264
|
-
// Get last state
|
|
265
|
-
const archivist = await this.getArchivistForStore('stateStore')
|
|
266
|
-
const payload = (await archivist.get([hash])).find(isModuleState)
|
|
267
|
-
if (payload) {
|
|
268
|
-
return payload.state as ImageThumbnailDivinerState
|
|
269
|
-
}
|
|
270
|
-
} else {
|
|
271
|
-
console.log('Failed to locate last state')
|
|
272
|
-
}
|
|
273
|
-
return undefined
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
protected override async startHandler(): Promise<boolean> {
|
|
277
|
-
await super.startHandler()
|
|
278
|
-
this.poll()
|
|
279
|
-
return true
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
protected override async stopHandler(_timeout?: number | undefined): Promise<boolean> {
|
|
283
|
-
if (this._pollId) {
|
|
284
|
-
clearTimeout(this._pollId)
|
|
285
|
-
this._pollId = undefined
|
|
286
|
-
}
|
|
287
|
-
return await super.stopHandler()
|
|
288
|
-
}
|
|
3
|
+
import { ImageThumbnailDivinerLabels } from './ImageThumbnailDivinerLabels'
|
|
289
4
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
try {
|
|
293
|
-
await this.backgroundDivine()
|
|
294
|
-
} catch (e) {
|
|
295
|
-
console.log(e)
|
|
296
|
-
} finally {
|
|
297
|
-
if (this._pollId) clearTimeout(this._pollId)
|
|
298
|
-
this._pollId = undefined
|
|
299
|
-
this.poll()
|
|
300
|
-
}
|
|
301
|
-
}, this.pollFrequency)
|
|
302
|
-
}
|
|
5
|
+
export class ImageThumbnailDiviner extends IndexingDiviner {
|
|
6
|
+
static labels: ImageThumbnailDivinerLabels = ImageThumbnailDivinerLabels
|
|
303
7
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DivinerStageSchema, IndexingDivinerStage } from '@xyo-network/diviner-indexing'
|
|
2
|
+
import { Labels } from '@xyo-network/module-model'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Labels for Image Thumbnail Diviner components
|
|
6
|
+
*/
|
|
7
|
+
export interface ImageThumbnailDivinerLabels extends Labels {
|
|
8
|
+
'network.xyo.image.thumbnail': 'diviner'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Labels for Image Thumbnail Diviner components
|
|
13
|
+
*/
|
|
14
|
+
export const ImageThumbnailDivinerLabels: ImageThumbnailDivinerLabels = {
|
|
15
|
+
'network.xyo.image.thumbnail': 'diviner',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Labels for Image Thumbnail Diviner Stage Diviners
|
|
20
|
+
*/
|
|
21
|
+
export type ImageThumbnailDivinerStageLabels = ImageThumbnailDivinerLabels & {
|
|
22
|
+
/**
|
|
23
|
+
* Labels for the stage of the Image Thumbnail Diviner Stage Diviner
|
|
24
|
+
*/
|
|
25
|
+
[key in DivinerStageSchema]: IndexingDivinerStage
|
|
26
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AbstractDiviner } from '@xyo-network/abstract-diviner'
|
|
2
|
+
import { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
3
|
+
import { PayloadHasher } from '@xyo-network/core'
|
|
4
|
+
import { DivinerConfigSchema } from '@xyo-network/diviner-model'
|
|
5
|
+
import {
|
|
6
|
+
ImageThumbnail,
|
|
7
|
+
ImageThumbnailResultIndex,
|
|
8
|
+
ImageThumbnailResultIndexFields,
|
|
9
|
+
ImageThumbnailResultIndexSchema,
|
|
10
|
+
ImageThumbnailSchema,
|
|
11
|
+
isImageThumbnail,
|
|
12
|
+
} from '@xyo-network/image-thumbnail-payload-plugin'
|
|
13
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
14
|
+
import { Payload } from '@xyo-network/payload-model'
|
|
15
|
+
import { UrlSchema } from '@xyo-network/url-payload-plugin'
|
|
16
|
+
import { isTimestamp, TimeStamp, TimestampSchema } from '@xyo-network/witness-timestamp'
|
|
17
|
+
|
|
18
|
+
import { ImageThumbnailDivinerLabels, ImageThumbnailDivinerStageLabels } from './ImageThumbnailDivinerLabels'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Transforms candidates for image thumbnail indexing into their indexed representation
|
|
22
|
+
*/
|
|
23
|
+
export class ImageThumbnailIndexCandidateToImageThumbnailIndexDiviner extends AbstractDiviner {
|
|
24
|
+
static override configSchemas = [DivinerConfigSchema]
|
|
25
|
+
static labels: ImageThumbnailDivinerStageLabels = {
|
|
26
|
+
...ImageThumbnailDivinerLabels,
|
|
27
|
+
'network.xyo.diviner.stage': 'indexCandidateToIndexDiviner',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected override async divineHandler(payloads: Payload[] = []): Promise<ImageThumbnailResultIndex[]> {
|
|
31
|
+
const bws: BoundWitness[] = payloads.filter(isBoundWitness)
|
|
32
|
+
const imageThumbnailPayloads: ImageThumbnail[] = payloads.filter(isImageThumbnail)
|
|
33
|
+
const timestampPayloads: TimeStamp[] = payloads.filter(isTimestamp)
|
|
34
|
+
if (bws.length && imageThumbnailPayloads.length && timestampPayloads.length) {
|
|
35
|
+
const payloadDictionary = await PayloadHasher.toMap(payloads)
|
|
36
|
+
const tuples: [BoundWitness, ImageThumbnail, TimeStamp][] = bws.reduce<[BoundWitness, ImageThumbnail, TimeStamp][]>(
|
|
37
|
+
(acc, curr) => {
|
|
38
|
+
const imageThumbnailIndex = curr.payload_schemas?.findIndex((schema) => schema === ImageThumbnailSchema)
|
|
39
|
+
const timestampIndex = curr.payload_schemas?.findIndex((schema) => schema === TimestampSchema)
|
|
40
|
+
const imageThumbnailHash = curr.payload_hashes?.[imageThumbnailIndex]
|
|
41
|
+
const timestampHash = curr.payload_hashes?.[timestampIndex]
|
|
42
|
+
const imageThumbnailPayload = [payloadDictionary[imageThumbnailHash]].find(isImageThumbnail)
|
|
43
|
+
const timestampPayload = [payloadDictionary[timestampHash]].find(isTimestamp)
|
|
44
|
+
if (imageThumbnailPayload && timestampPayload) acc.push([curr, imageThumbnailPayload, timestampPayload])
|
|
45
|
+
return acc
|
|
46
|
+
},
|
|
47
|
+
[] as [BoundWitness, ImageThumbnail, TimeStamp][],
|
|
48
|
+
)
|
|
49
|
+
const indexes = await Promise.all(
|
|
50
|
+
tuples.map(async ([bw, imageThumbnailPayload, timestampPayload]) => {
|
|
51
|
+
const { sourceUrl: url } = imageThumbnailPayload
|
|
52
|
+
const { timestamp } = timestampPayload
|
|
53
|
+
const status = imageThumbnailPayload.http?.status
|
|
54
|
+
const success = !!imageThumbnailPayload.url // Call anything with a thumbnail url a success
|
|
55
|
+
const sources = (await PayloadHasher.hashPairs([bw, imageThumbnailPayload, timestampPayload])).map(([, hash]) => hash)
|
|
56
|
+
const urlPayload = { schema: UrlSchema, url }
|
|
57
|
+
const key = await PayloadHasher.hashAsync(urlPayload)
|
|
58
|
+
const fields: ImageThumbnailResultIndexFields = { key, sources, success, timestamp }
|
|
59
|
+
if (status) fields.status = status
|
|
60
|
+
const result: ImageThumbnailResultIndex = new PayloadBuilder<ImageThumbnailResultIndex>({ schema: ImageThumbnailResultIndexSchema })
|
|
61
|
+
.fields(fields)
|
|
62
|
+
.build()
|
|
63
|
+
return [result]
|
|
64
|
+
}),
|
|
65
|
+
)
|
|
66
|
+
return indexes.flat()
|
|
67
|
+
}
|
|
68
|
+
return Promise.resolve([])
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { exists } from '@xylabs/exists'
|
|
2
|
+
import { AbstractDiviner } from '@xyo-network/abstract-diviner'
|
|
3
|
+
import { PayloadHasher } from '@xyo-network/core'
|
|
4
|
+
import { DivinerConfigSchema } from '@xyo-network/diviner-model'
|
|
5
|
+
import {
|
|
6
|
+
ImageThumbnailResult,
|
|
7
|
+
ImageThumbnailResultFields,
|
|
8
|
+
ImageThumbnailResultSchema,
|
|
9
|
+
isImageThumbnailDivinerQuery,
|
|
10
|
+
isImageThumbnailResultIndex,
|
|
11
|
+
} from '@xyo-network/image-thumbnail-payload-plugin'
|
|
12
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
13
|
+
import { Payload } from '@xyo-network/payload-model'
|
|
14
|
+
import { UrlSchema } from '@xyo-network/url-payload-plugin'
|
|
15
|
+
|
|
16
|
+
import { ImageThumbnailDivinerLabels, ImageThumbnailDivinerStageLabels } from './ImageThumbnailDivinerLabels'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Transforms an ImageThumbnailIndex response into an ImageThumbnailResponse response
|
|
20
|
+
*/
|
|
21
|
+
export class ImageThumbnailIndexQueryResponseToImageThumbnailQueryResponseDiviner extends AbstractDiviner {
|
|
22
|
+
static override configSchemas = [DivinerConfigSchema]
|
|
23
|
+
static labels: ImageThumbnailDivinerStageLabels = {
|
|
24
|
+
...ImageThumbnailDivinerLabels,
|
|
25
|
+
'network.xyo.diviner.stage': 'indexQueryResponseToDivinerQueryResponseDiviner',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected override async divineHandler(payloads: Payload[] = []): Promise<ImageThumbnailResult[]> {
|
|
29
|
+
// Filter out the two operands
|
|
30
|
+
const imageThumbnailDivinerQueries = payloads.filter(isImageThumbnailDivinerQuery)
|
|
31
|
+
const imageThumbnailResultIndexes = payloads.filter(isImageThumbnailResultIndex)
|
|
32
|
+
|
|
33
|
+
// If we have operands
|
|
34
|
+
if (imageThumbnailDivinerQueries.length && imageThumbnailResultIndexes.length) {
|
|
35
|
+
// Create a dictionary to translate index keys to the urls that represent them
|
|
36
|
+
const keyToUrlDictionary = Object.fromEntries(
|
|
37
|
+
await Promise.all(
|
|
38
|
+
imageThumbnailDivinerQueries.map(async (imageThumbnailDivinerQuery) => {
|
|
39
|
+
const { url } = imageThumbnailDivinerQuery
|
|
40
|
+
const urlPayload = new PayloadBuilder<ImageThumbnailResult>({ schema: UrlSchema }).fields({ url }).build()
|
|
41
|
+
const key = await PayloadHasher.hashAsync(urlPayload)
|
|
42
|
+
return [key, url] as const
|
|
43
|
+
}),
|
|
44
|
+
),
|
|
45
|
+
)
|
|
46
|
+
// Map the indexes to responses using the dictionary
|
|
47
|
+
return imageThumbnailResultIndexes
|
|
48
|
+
.map((imageThumbnailResultIndex) => {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
50
|
+
const { key, schema, ...commonFields } = imageThumbnailResultIndex
|
|
51
|
+
const url = keyToUrlDictionary?.[key]
|
|
52
|
+
if (url) {
|
|
53
|
+
const fields: ImageThumbnailResultFields = { ...commonFields, url }
|
|
54
|
+
return new PayloadBuilder<ImageThumbnailResult>({ schema: ImageThumbnailResultSchema }).fields(fields).build()
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
.filter(exists)
|
|
58
|
+
}
|
|
59
|
+
return []
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AbstractDiviner } from '@xyo-network/abstract-diviner'
|
|
2
|
+
import { PayloadHasher } from '@xyo-network/core'
|
|
3
|
+
import { DivinerConfigSchema } from '@xyo-network/diviner-model'
|
|
4
|
+
import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
5
|
+
import { isImageThumbnailDivinerQuery } from '@xyo-network/image-thumbnail-payload-plugin'
|
|
6
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
7
|
+
import { Payload } from '@xyo-network/payload-model'
|
|
8
|
+
import { UrlSchema } from '@xyo-network/url-payload-plugin'
|
|
9
|
+
|
|
10
|
+
import { ImageThumbnailDivinerLabels, ImageThumbnailDivinerStageLabels } from './ImageThumbnailDivinerLabels'
|
|
11
|
+
import { ImageThumbnailResultQuery } from './ImageThumbnailResultQuery'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A diviner that converts ImageThumbnailDivinerQuery to ImageThumbnailResultQuery
|
|
15
|
+
*/
|
|
16
|
+
export class ImageThumbnailQueryToImageThumbnailIndexQueryDiviner extends AbstractDiviner {
|
|
17
|
+
static override configSchemas = [DivinerConfigSchema]
|
|
18
|
+
static labels: ImageThumbnailDivinerStageLabels = {
|
|
19
|
+
...ImageThumbnailDivinerLabels,
|
|
20
|
+
'network.xyo.diviner.stage': 'divinerQueryToIndexQueryDiviner',
|
|
21
|
+
}
|
|
22
|
+
protected override async divineHandler(payloads: Payload[] = []): Promise<ImageThumbnailResultQuery[]> {
|
|
23
|
+
const queries = payloads.filter(isImageThumbnailDivinerQuery)
|
|
24
|
+
if (queries.length) {
|
|
25
|
+
const results = await Promise.all(
|
|
26
|
+
queries.map(async (query) => {
|
|
27
|
+
const { limit: payloadLimit, offset: payloadOffset, order: payloadOrder, status: payloadStatus, success: payloadSuccess, url } = query
|
|
28
|
+
const limit = payloadLimit ?? 1
|
|
29
|
+
const order = payloadOrder ?? 'desc'
|
|
30
|
+
const offset = payloadOffset ?? 0
|
|
31
|
+
const urlPayload = { schema: UrlSchema, url }
|
|
32
|
+
const key = await PayloadHasher.hashAsync(urlPayload)
|
|
33
|
+
const fields: Partial<ImageThumbnailResultQuery> = { key, limit, offset, order }
|
|
34
|
+
if (payloadSuccess !== undefined) fields.success = payloadSuccess
|
|
35
|
+
if (payloadStatus !== undefined) fields.status = payloadStatus
|
|
36
|
+
return new PayloadBuilder<ImageThumbnailResultQuery>({ schema: PayloadDivinerQuerySchema }).fields(fields).build()
|
|
37
|
+
}),
|
|
38
|
+
)
|
|
39
|
+
return results
|
|
40
|
+
}
|
|
41
|
+
return Promise.resolve([])
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PayloadDivinerQueryPayload, PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
2
|
+
import { ImageThumbnailResultIndex } from '@xyo-network/image-thumbnail-payload-plugin'
|
|
3
|
+
import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The fields that will need to be indexed on in the underlying store
|
|
7
|
+
*/
|
|
8
|
+
export type QueryableImageThumbnailResultProperties = Extract<keyof ImageThumbnailResultIndex, 'status' | 'success' | 'timestamp' | 'key'>
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The query that will be used to retrieve the results from the underlying store
|
|
12
|
+
*/
|
|
13
|
+
export type ImageThumbnailResultQuery = PayloadDivinerQueryPayload & Pick<ImageThumbnailResultIndex, QueryableImageThumbnailResultProperties>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A type guard for ImageThumbnailResultQuery
|
|
17
|
+
*/
|
|
18
|
+
// TODO: Use a more derived schema than PayloadDivinerQuerySchema
|
|
19
|
+
export const isImageThumbnailResultQuery = isPayloadOfSchemaType<ImageThumbnailResultQuery>(PayloadDivinerQuerySchema)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DivinerConfig } from '@xyo-network/diviner-model'
|
|
2
|
+
import { SearchableStorage } from '@xyo-network/image-thumbnail-payload-plugin'
|
|
3
|
+
|
|
4
|
+
import { ImageThumbnailStateToIndexCandidateDivinerSchema } from './Schema'
|
|
5
|
+
|
|
6
|
+
export type ImageThumbnailStateToIndexCandidateDivinerConfigSchema = `${ImageThumbnailStateToIndexCandidateDivinerSchema}.config`
|
|
7
|
+
export const ImageThumbnailStateToIndexCandidateDivinerConfigSchema: ImageThumbnailStateToIndexCandidateDivinerConfigSchema = `${ImageThumbnailStateToIndexCandidateDivinerSchema}.config`
|
|
8
|
+
|
|
9
|
+
export type ImageThumbnailStateToIndexCandidateDivinerConfig = DivinerConfig<{
|
|
10
|
+
payloadDivinerLimit?: number
|
|
11
|
+
/**
|
|
12
|
+
* Where the diviner should look for stored thumbnails
|
|
13
|
+
*/
|
|
14
|
+
payloadStore?: SearchableStorage
|
|
15
|
+
schema: ImageThumbnailStateToIndexCandidateDivinerConfigSchema
|
|
16
|
+
}>
|