@xyo-network/diviner-payload-indexeddb 5.3.22 → 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-indexeddb",
3
- "version": "5.3.22",
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,53 +30,49 @@
30
30
  "types": "dist/browser/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-indexeddb": "~5.3.22",
41
- "@xyo-network/archivist-model": "~5.3.22",
42
- "@xyo-network/diviner-model": "~5.3.22",
43
- "@xyo-network/diviner-payload-abstract": "~5.3.22",
44
- "@xyo-network/diviner-payload-model": "~5.3.22",
45
- "@xyo-network/module-model": "~5.3.22",
46
- "@xyo-network/payload-model": "~5.3.22"
39
+ "@xyo-network/archivist-model": "~5.3.24",
40
+ "@xyo-network/archivist-indexeddb": "~5.3.24",
41
+ "@xyo-network/diviner-model": "~5.3.24",
42
+ "@xyo-network/diviner-payload-abstract": "~5.3.24",
43
+ "@xyo-network/diviner-payload-model": "~5.3.24",
44
+ "@xyo-network/module-model": "~5.3.24",
45
+ "@xyo-network/payload-model": "~5.3.24"
47
46
  },
48
47
  "devDependencies": {
49
48
  "@opentelemetry/api": "^1.9.1",
50
49
  "@types/node": "^25.5.0",
51
- "@xylabs/indexed-db": "^5.0.91",
52
- "@xylabs/sdk-js": "^5.0.91",
53
- "@xylabs/ts-scripts-common": "~7.6.8",
54
- "@xylabs/ts-scripts-yarn3": "~7.6.8",
55
- "@xylabs/tsconfig": "~7.6.8",
56
- "@xylabs/vitest-extended": "~5.0.91",
57
- "@xyo-network/archivist-indexeddb": "~5.3.22",
58
- "@xyo-network/archivist-model": "~5.3.22",
59
- "@xyo-network/diviner-model": "~5.3.22",
60
- "@xyo-network/diviner-payload-abstract": "~5.3.22",
61
- "@xyo-network/diviner-payload-model": "~5.3.22",
62
- "@xyo-network/module-model": "~5.3.22",
63
- "@xyo-network/node-memory": "~5.3.22",
64
- "@xyo-network/payload-builder": "~5.3.22",
65
- "@xyo-network/payload-model": "~5.3.22",
50
+ "@xylabs/indexed-db": "^5.0.93",
51
+ "@xylabs/sdk-js": "^5.0.93",
52
+ "@xylabs/ts-scripts-common": "~7.6.16",
53
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
54
+ "@xylabs/tsconfig": "~7.6.16",
55
+ "@xylabs/vitest-extended": "~5.0.93",
66
56
  "acorn": "^8.16.0",
67
57
  "axios": "^1.14.0",
68
- "cosmiconfig": "^9.0.1",
69
- "esbuild": "^0.27.4",
70
- "eslint": "^10.1.0",
58
+ "esbuild": "^0.28.0",
71
59
  "ethers": "^6.16.0",
72
60
  "fake-indexeddb": "~6.2.5",
73
61
  "idb": "^8.0.3",
74
- "rollup": "^4.60.1",
75
62
  "tslib": "^2.8.1",
76
63
  "typescript": "~5.9.3",
77
64
  "vite": "^8.0.3",
78
65
  "vitest": "~4.1.2",
79
- "zod": "^4.3.6"
66
+ "zod": "^4.3.6",
67
+ "@xyo-network/archivist-indexeddb": "~5.3.24",
68
+ "@xyo-network/archivist-model": "~5.3.24",
69
+ "@xyo-network/diviner-model": "~5.3.24",
70
+ "@xyo-network/diviner-payload-abstract": "~5.3.24",
71
+ "@xyo-network/module-model": "~5.3.24",
72
+ "@xyo-network/diviner-payload-model": "~5.3.24",
73
+ "@xyo-network/node-memory": "~5.3.24",
74
+ "@xyo-network/payload-builder": "~5.3.24",
75
+ "@xyo-network/payload-model": "~5.3.24"
80
76
  },
81
77
  "peerDependencies": {
82
78
  "@xylabs/indexed-db": "^5",
@@ -89,4 +85,4 @@
89
85
  "publishConfig": {
90
86
  "access": "public"
91
87
  }
92
- }
88
+ }
package/src/Config.ts DELETED
@@ -1,34 +0,0 @@
1
- import type { IndexDescription } from '@xyo-network/archivist-model'
2
- import type { DivinerConfig } from '@xyo-network/diviner-model'
3
- import { asSchema } from '@xyo-network/payload-model'
4
-
5
- import { IndexedDbPayloadDivinerSchema } from './Schema.ts'
6
-
7
- export const IndexedDbPayloadDivinerConfigSchema = asSchema(`${IndexedDbPayloadDivinerSchema}.config`, true)
8
- export type IndexedDbPayloadDivinerConfigSchema = typeof IndexedDbPayloadDivinerConfigSchema
9
-
10
- export type IndexedDbPayloadDivinerConfig = DivinerConfig<{
11
- /**
12
- * The database name
13
- */
14
- dbName?: string
15
- /**
16
- * The version of the DB, defaults to 1
17
- */
18
- dbVersion?: number
19
- schema: IndexedDbPayloadDivinerConfigSchema
20
- /**
21
- * The storage configuration
22
- * // TODO: Hoist to main diviner config
23
- */
24
- storage?: {
25
- /**
26
- * The indexes to create on the object store
27
- */
28
- indexes?: IndexDescription[]
29
- }
30
- /**
31
- * The name of the object store
32
- */
33
- storeName?: string
34
- }>
package/src/Diviner.ts DELETED
@@ -1,190 +0,0 @@
1
- /// <reference lib="dom" />
2
-
3
- import {
4
- assertEx, containsAll,
5
- exists, removeFields,
6
- } from '@xylabs/sdk-js'
7
- import { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'
8
- import type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'
9
- import { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'
10
- import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
11
- import { isPayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
12
- import type {
13
- AnyPayload,
14
- Payload, Schema, Sequence,
15
- } from '@xyo-network/payload-model'
16
- import type { IDBPCursorWithValue, IDBPDatabase } from 'idb'
17
- import { openDB } from 'idb'
18
-
19
- import { IndexedDbPayloadDivinerConfigSchema } from './Config.ts'
20
- import type { IndexedDbPayloadDivinerParams } from './Params.ts'
21
-
22
- interface PayloadStore {
23
- [s: string]: Payload
24
- }
25
-
26
- type ValueFilter = (payload?: AnyPayload | null) => boolean
27
-
28
- const payloadValueFilter = (key: keyof AnyPayload, value?: unknown | unknown[]): ValueFilter | undefined => {
29
- if (!value) return undefined
30
- return (payload) => {
31
- if (!payload) return false
32
- const sourceValue = payload?.[key]
33
- if (sourceValue === undefined) return false
34
- return Array.isArray(sourceValue) && Array.isArray(value) ? containsAll(sourceValue, value) : sourceValue == value
35
- }
36
- }
37
-
38
- export class IndexedDbPayloadDiviner<
39
- TParams extends IndexedDbPayloadDivinerParams = IndexedDbPayloadDivinerParams,
40
- TIn extends PayloadDivinerQueryPayload = PayloadDivinerQueryPayload,
41
- TOut extends Payload = Payload,
42
- TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<
43
- DivinerInstance<TParams, TIn, TOut>,
44
- TIn,
45
- TOut
46
- >,
47
- > extends PayloadDiviner<TParams, TIn, TOut, TEventData> {
48
- static override readonly configSchemas: Schema[] = [...super.configSchemas, IndexedDbPayloadDivinerConfigSchema]
49
- static override readonly defaultConfigSchema: Schema = IndexedDbPayloadDivinerConfigSchema
50
-
51
- /**
52
- * The database name. If not supplied via config, it defaults
53
- * to the archivist's name and if archivist's name is not supplied,
54
- * it defaults to `archivist`. This behavior
55
- * biases towards a single, isolated DB per archivist which seems to
56
- * make the most sense for 99% of use cases.
57
- */
58
- get dbName() {
59
- return this.config?.dbName ?? this.config?.archivist ?? IndexedDbArchivist.defaultDbName
60
- }
61
-
62
- /**
63
- * The database version. If not supplied via config, it defaults to the archivist default version.
64
- */
65
- get dbVersion() {
66
- return this.config?.dbVersion ?? IndexedDbArchivist.defaultDbVersion
67
- }
68
-
69
- /**
70
- * The name of the object store. If not supplied via config, it defaults
71
- * to `payloads`.
72
- */
73
- get storeName() {
74
- return this.config?.storeName ?? IndexedDbArchivist.defaultStoreName
75
- }
76
-
77
- protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {
78
- const query = payloads?.find(isPayloadDivinerQueryPayload)
79
- if (!query) return []
80
- const result = await this.tryUseDb(async (db) => {
81
- const {
82
- schemas, limit, cursor, order, ...props
83
- } = removeFields(query, ['schema'])
84
- const tx = db.transaction(this.storeName, 'readonly')
85
- const store = tx.objectStore(this.storeName)
86
- const results: TOut[] = []
87
- let parsedCursor = cursor
88
- const parsedLimit = limit ?? 10
89
- assertEx((schemas?.length ?? 1) === 1, () => 'IndexedDbPayloadDiviner: Only one filter schema supported')
90
- const filterSchema = schemas?.[0]
91
- const filter = filterSchema ? { schema: filterSchema, ...props } : { ...props }
92
- const valueFilters: ValueFilter[] = Object.entries(filter)
93
- .map(([key, value]) => payloadValueFilter(key, value))
94
- .filter(exists)
95
- const direction: IDBCursorDirection = order === 'desc' ? 'prev' : 'next'
96
-
97
- // Iterate all records using the sequence index
98
- const sequenceIndex = assertEx(store.index(IndexedDbArchivist.sequenceIndexName), () => 'Failed to get sequence index')
99
- let dbCursor: IDBPCursorWithValue<PayloadStore, [string], string, string, 'readonly'> | null
100
- = await sequenceIndex.openCursor(null, direction)
101
-
102
- // If a cursor was supplied
103
- if (parsedCursor !== undefined) {
104
- let currentSequence: Sequence | undefined
105
- // Skip records until the supplied cursor offset is reached
106
- while (dbCursor && currentSequence !== parsedCursor) {
107
- // Find the sequence of the current record
108
- currentSequence = await dbCursor.value?.sequence
109
- // Advance one record beyond the cursor
110
- dbCursor = await dbCursor.advance(1)
111
- }
112
- }
113
-
114
- // Collect results up to the limit
115
- while (dbCursor && results.length < parsedLimit) {
116
- const value = dbCursor.value
117
- if (value) {
118
- // If we're filtering on more than just the schema
119
- if (valueFilters.length > 0) {
120
- // Ensure all filters pass
121
- if (valueFilters.every(filter => filter(value))) {
122
- // Then save the value
123
- results.push(value)
124
- }
125
- } else {
126
- // Otherwise just save the value
127
- results.push(value)
128
- }
129
- }
130
- try {
131
- dbCursor = await dbCursor.continue()
132
- } catch {
133
- break
134
- }
135
- }
136
- await tx.done
137
- // Remove any metadata before returning to the client
138
- return results
139
- })
140
- return result ?? []
141
- }
142
-
143
- /**
144
- * Checks that the desired DB/objectStore exists and is initialized to the correct version
145
- * @returns The initialized DB or undefined if it does not exist in the desired state
146
- */
147
- private async tryGetInitializedDb(): Promise<IDBPDatabase<PayloadStore> | undefined> {
148
- // Enumerate the DBs
149
- const dbs = await indexedDB.databases()
150
- // Check that the DB exists
151
- const dbExists = dbs.some((db) => {
152
- return db.name === this.dbName
153
- })
154
- // If the DB exists
155
- if (dbExists) {
156
- // If the db does exist, open it
157
- const db = await openDB<PayloadStore>(this.dbName)
158
- // Check that the desired objectStore exists
159
- const storeExists = db.objectStoreNames.contains(this.storeName)
160
- // If the correct db/version/objectStore exists
161
- if (storeExists) {
162
- return db
163
- } else {
164
- // Otherwise close the db so the process that is going to update the
165
- // db can open it
166
- db.close()
167
- }
168
- }
169
- }
170
-
171
- /**
172
- * Executes a callback with the initialized DB and then closes the db
173
- * @param callback The method to execute with the initialized DB
174
- * @returns
175
- */
176
- private async tryUseDb<T>(callback: (db: IDBPDatabase<PayloadStore>) => Promise<T> | T): Promise<T | undefined> {
177
- // Get the initialized DB
178
- const db = await this.tryGetInitializedDb()
179
- if (db) {
180
- try {
181
- // Perform the callback
182
- return await callback(db)
183
- } finally {
184
- // Close the DB
185
- db.close()
186
- }
187
- }
188
- return undefined
189
- }
190
- }
package/src/Params.ts DELETED
@@ -1,6 +0,0 @@
1
- import type { DivinerParams } from '@xyo-network/diviner-model'
2
- import type { AnyConfigSchema } from '@xyo-network/module-model'
3
-
4
- import type { IndexedDbPayloadDivinerConfig } from './Config.ts'
5
-
6
- export type IndexedDbPayloadDivinerParams = DivinerParams<AnyConfigSchema<IndexedDbPayloadDivinerConfig>>
package/src/Schema.ts DELETED
@@ -1,5 +0,0 @@
1
- import { PayloadDivinerSchema } from '@xyo-network/diviner-payload-model'
2
- import { asSchema } from '@xyo-network/payload-model'
3
-
4
- export const IndexedDbPayloadDivinerSchema = asSchema(`${PayloadDivinerSchema}.indexeddb`, true)
5
- export type IndexedDbPayloadDivinerSchema = typeof IndexedDbPayloadDivinerSchema
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './Config.ts'
2
- export * from './Diviner.ts'
3
- export * from './Params.ts'
4
- export * from './Schema.ts'