@xyo-network/diviner-payload-indexeddb 5.1.22 → 5.1.23

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.1.22",
3
+ "version": "5.1.23",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,32 +30,35 @@
30
30
  "types": "dist/browser/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src"
33
+ "src",
34
+ "!**/*.bench.*",
35
+ "!**/*.spec.*",
36
+ "!**/*.test.*"
34
37
  ],
35
38
  "dependencies": {
36
- "@xylabs/array": "~5.0.24",
37
- "@xylabs/assert": "~5.0.24",
38
- "@xylabs/exists": "~5.0.24",
39
- "@xylabs/object": "~5.0.24",
40
- "@xyo-network/archivist-indexeddb": "~5.1.22",
41
- "@xyo-network/archivist-model": "~5.1.22",
42
- "@xyo-network/diviner-model": "~5.1.22",
43
- "@xyo-network/diviner-payload-abstract": "~5.1.22",
44
- "@xyo-network/diviner-payload-model": "~5.1.22",
45
- "@xyo-network/module-model": "~5.1.22",
46
- "@xyo-network/payload-model": "~5.1.22",
39
+ "@xylabs/array": "~5.0.33",
40
+ "@xylabs/assert": "~5.0.33",
41
+ "@xylabs/exists": "~5.0.33",
42
+ "@xylabs/object": "~5.0.33",
43
+ "@xyo-network/archivist-indexeddb": "~5.1.23",
44
+ "@xyo-network/archivist-model": "~5.1.23",
45
+ "@xyo-network/diviner-model": "~5.1.23",
46
+ "@xyo-network/diviner-payload-abstract": "~5.1.23",
47
+ "@xyo-network/diviner-payload-model": "~5.1.23",
48
+ "@xyo-network/module-model": "~5.1.23",
49
+ "@xyo-network/payload-model": "~5.1.23",
47
50
  "idb": "~8.0.3"
48
51
  },
49
52
  "devDependencies": {
50
53
  "@xylabs/ts-scripts-yarn3": "~7.2.8",
51
54
  "@xylabs/tsconfig": "~7.2.8",
52
- "@xylabs/vitest-extended": "~5.0.24",
53
- "@xyo-network/archivist-indexeddb": "~5.1.22",
54
- "@xyo-network/node-memory": "~5.1.22",
55
- "@xyo-network/payload-builder": "~5.1.22",
55
+ "@xylabs/vitest-extended": "~5.0.33",
56
+ "@xyo-network/archivist-indexeddb": "~5.1.23",
57
+ "@xyo-network/node-memory": "~5.1.23",
58
+ "@xyo-network/payload-builder": "~5.1.23",
56
59
  "fake-indexeddb": "~6.2.5",
57
60
  "typescript": "~5.9.3",
58
- "vitest": "~4.0.8"
61
+ "vitest": "~4.0.9"
59
62
  },
60
63
  "publishConfig": {
61
64
  "access": "public"
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Diviner.Error.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Diviner.Error.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/Diviner.Error.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- import '@xylabs/vitest-extended';
2
- //# sourceMappingURL=Diviner.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/Diviner.spec.ts"],"names":[],"mappings":"AAGA,OAAO,yBAAyB,CAAA"}
@@ -1,117 +0,0 @@
1
- import { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'
2
- import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
3
- import { MemoryNode } from '@xyo-network/node-memory'
4
- import { PayloadBuilder } from '@xyo-network/payload-builder'
5
- import {
6
- IDBCursor,
7
- IDBCursorWithValue,
8
- IDBDatabase,
9
- IDBFactory,
10
- IDBIndex,
11
- IDBKeyRange,
12
- IDBObjectStore,
13
- IDBOpenDBRequest,
14
- IDBRequest,
15
- IDBTransaction,
16
- IDBVersionChangeEvent,
17
- indexedDB,
18
- } from 'fake-indexeddb'
19
- import {
20
- beforeAll, describe, expect,
21
- it,
22
- } from 'vitest'
23
-
24
- import { IndexedDbPayloadDiviner } from '../Diviner.ts'
25
-
26
- // Augment window with prototypes to ensure instance of comparisons work
27
- globalThis.IDBCursor = IDBCursor
28
- globalThis.IDBCursorWithValue = IDBCursorWithValue
29
- globalThis.IDBDatabase = IDBDatabase
30
- globalThis.IDBFactory = IDBFactory
31
- globalThis.IDBIndex = IDBIndex
32
- globalThis.IDBKeyRange = IDBKeyRange
33
- globalThis.IDBObjectStore = IDBObjectStore
34
- globalThis.IDBOpenDBRequest = IDBOpenDBRequest
35
- globalThis.IDBRequest = IDBRequest
36
- globalThis.IDBTransaction = IDBTransaction
37
- globalThis.IDBVersionChangeEvent = IDBVersionChangeEvent
38
- globalThis.indexedDB = indexedDB
39
-
40
- /**
41
- * @group module
42
- * @group diviner
43
- */
44
- describe('IndexedDbPayloadDiviner.Errors', () => {
45
- const dbName = 'testDb-IndexedDbPayloadDiviner.Errors'
46
- const storeName = 'testStore-IndexedDbPayloadDiviner.Errors'
47
- let sut: IndexedDbPayloadDiviner
48
- const values = [
49
- {
50
- schema: 'network.xyo.test',
51
- url: 'https://xyo.network',
52
- },
53
- ]
54
- describe('divine', () => {
55
- const createTestNode = async (testDbName = 'INCORRECT-DB-NAME', testStoreName = 'INCORRECT-STORE-NAME') => {
56
- const archivist = await IndexedDbArchivist.create({
57
- account: 'random',
58
- config: {
59
- dbName, schema: IndexedDbArchivist.defaultConfigSchema, storeName,
60
- },
61
- })
62
- await archivist.clear?.()
63
- await archivist.insert(values)
64
- const sut = await IndexedDbPayloadDiviner.create({
65
- account: 'random',
66
- config: {
67
- archivist: archivist.address,
68
- dbName: testDbName,
69
- schema: IndexedDbPayloadDiviner.defaultConfigSchema,
70
- storeName: testStoreName,
71
- },
72
- })
73
- const node = await MemoryNode.create({
74
- account: 'random',
75
- config: { schema: MemoryNode.defaultConfigSchema },
76
- })
77
- const modules = [archivist, sut]
78
- await node.start()
79
- await Promise.all(
80
- modules.map(async (mod) => {
81
- await node.register(mod)
82
- await node.attach(mod.address, true)
83
- }),
84
- )
85
- return sut
86
- }
87
- describe('when DB and store do not exist', () => {
88
- beforeAll(async () => {
89
- sut = await createTestNode('INCORRECT-DB-NAME', 'INCORRECT-STORE-NAME')
90
- })
91
- it('returns empty array', async () => {
92
- const result = await sut.divine([{ schema: PayloadDivinerQuerySchema }])
93
- expect(result).toEqual([])
94
- })
95
- })
96
- describe('when DB exists but store does not exist', () => {
97
- beforeAll(async () => {
98
- sut = await createTestNode(dbName, 'INCORRECT-STORE-NAME')
99
- })
100
- it('returns empty array', async () => {
101
- const result = await sut.divine([{ schema: PayloadDivinerQuerySchema }])
102
- expect(result).toEqual([])
103
- })
104
- })
105
- describe('when DB and store exist', () => {
106
- beforeAll(async () => {
107
- sut = await createTestNode(dbName, storeName)
108
- })
109
- it('returns values', async () => {
110
- const result = await sut.divine([{ schema: PayloadDivinerQuerySchema }])
111
- expect(result.map(i => PayloadBuilder.omitMeta(i))).toMatchObject(
112
- values.map(i => PayloadBuilder.omitMeta(i)),
113
- )
114
- })
115
- })
116
- })
117
- })
@@ -1,181 +0,0 @@
1
- /// <reference lib="dom" />
2
- /* eslint-disable max-nested-callbacks */
3
-
4
- import '@xylabs/vitest-extended'
5
-
6
- import { IndexedDbArchivist } from '@xyo-network/archivist-indexeddb'
7
- import type { IndexDescription } from '@xyo-network/archivist-model'
8
- import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
9
- import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
10
- import { MemoryNode } from '@xyo-network/node-memory'
11
- import { PayloadBuilder } from '@xyo-network/payload-builder'
12
- import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
13
- import {
14
- IDBCursor,
15
- IDBCursorWithValue,
16
- IDBDatabase,
17
- IDBFactory,
18
- IDBIndex,
19
- IDBKeyRange,
20
- IDBObjectStore,
21
- IDBOpenDBRequest,
22
- IDBRequest,
23
- IDBTransaction,
24
- IDBVersionChangeEvent,
25
- indexedDB,
26
- } from 'fake-indexeddb'
27
- import {
28
- beforeAll, describe, expect, it,
29
- } from 'vitest'
30
-
31
- import { IndexedDbPayloadDiviner } from '../Diviner.ts'
32
-
33
- // Augment window with prototypes to ensure instance of comparisons work
34
- globalThis.IDBCursor = IDBCursor
35
- globalThis.IDBCursorWithValue = IDBCursorWithValue
36
- globalThis.IDBDatabase = IDBDatabase
37
- globalThis.IDBFactory = IDBFactory
38
- globalThis.IDBIndex = IDBIndex
39
- globalThis.IDBKeyRange = IDBKeyRange
40
- globalThis.IDBObjectStore = IDBObjectStore
41
- globalThis.IDBOpenDBRequest = IDBOpenDBRequest
42
- globalThis.IDBRequest = IDBRequest
43
- globalThis.IDBTransaction = IDBTransaction
44
- globalThis.IDBVersionChangeEvent = IDBVersionChangeEvent
45
- globalThis.indexedDB = indexedDB
46
-
47
- /**
48
- * @group module
49
- * @group diviner
50
- */
51
- describe('IndexedDbPayloadDiviner', () => {
52
- const dbName = 'testDb'
53
- const storeName = 'testStore'
54
- let archivist: IndexedDbArchivist
55
- let sut: IndexedDbPayloadDiviner
56
- let node: MemoryNode
57
- const urlIndex: IndexDescription = { key: { url: 1 }, name: 'IX_url' }
58
- let payloadA: Payload<{ url: string }> = {
59
- schema: 'network.xyo.test',
60
- url: 'https://xyo.network',
61
- }
62
- let payloadB: Payload<{ foo: string[]; other: string }> = {
63
- foo: ['bar', 'baz'],
64
- other: 'value',
65
- schema: 'network.xyo.debug',
66
- }
67
- let insertedPayloads: WithStorageMeta<Payload>[] = []
68
- beforeAll(async () => {
69
- archivist = await IndexedDbArchivist.create({
70
- account: 'random',
71
- config: {
72
- dbName, schema: IndexedDbArchivist.defaultConfigSchema, storage: { indexes: [urlIndex] }, storeName,
73
- },
74
- })
75
- insertedPayloads = await archivist.insert([payloadA, payloadB])
76
- sut = await IndexedDbPayloadDiviner.create({
77
- account: 'random',
78
- config: {
79
- archivist: archivist.address,
80
- dbName,
81
- schema: IndexedDbPayloadDiviner.defaultConfigSchema,
82
- storeName,
83
- },
84
- })
85
- node = await MemoryNode.create({
86
- account: 'random',
87
- config: { schema: MemoryNode.defaultConfigSchema },
88
- })
89
- const modules = [archivist, sut]
90
- await node.start()
91
- await Promise.all(
92
- modules.map(async (mod) => {
93
- await node.register(mod)
94
- await node.attach(mod.address, true)
95
- }),
96
- )
97
- })
98
- describe('with filter for', () => {
99
- describe('schema', () => {
100
- describe('single', () => {
101
- it.each(['network.xyo.test', 'network.xyo.debug'])('only returns payloads of that schema', async (schema) => {
102
- const schemas = [schema]
103
- const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema }).fields({ schemas }).build()
104
- const results = await sut.divine([query])
105
- expect(results.length).toBeGreaterThan(0)
106
- expect(results.every(result => result.schema === schema)).toBe(true)
107
- })
108
- })
109
- describe.skip('multiple', () => {
110
- it('only returns payloads of that schema', async () => {
111
- const schemas = ['network.xyo.test', 'network.xyo.debug']
112
- const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema }).fields({ schemas }).build()
113
- const results = await sut.divine([query])
114
- expect(results.length).toBeGreaterThan(0)
115
- expect(results.every(result => schemas.includes(result.schema))).toBe(true)
116
- })
117
- })
118
- })
119
- describe('custom field', () => {
120
- describe('property', () => {
121
- describe('with index', () => {
122
- it('only returns payloads with that property', async () => {
123
- type WithUrl = { url?: string }
124
- const url = payloadA.url
125
- const query = new PayloadBuilder<PayloadDivinerQueryPayload & WithUrl>({ schema: PayloadDivinerQuerySchema })
126
- .fields({ url })
127
- .build()
128
- const results = await sut.divine([query])
129
- expect(results.length).toBeGreaterThan(0)
130
- expect(results.every(result => (result as WithUrl)?.url === url)).toBe(true)
131
- })
132
- })
133
- describe('without index', () => {
134
- it('only returns payloads with that property', async () => {
135
- type WithOther = { other?: string }
136
- const other = payloadB.other
137
- const query = new PayloadBuilder<PayloadDivinerQueryPayload & WithOther>({ schema: PayloadDivinerQuerySchema })
138
- .fields({ other })
139
- .build()
140
- const results = await sut.divine([query])
141
- expect(results.length).toBeGreaterThan(0)
142
- expect(results.every(result => (result as WithOther)?.other === other)).toBe(true)
143
- })
144
- })
145
- })
146
- describe.skip('array', () => {
147
- const cases: string[][] = [['bar'], ['baz'], ['bar', 'baz']]
148
- it.each(cases)('only returns payloads that have an array containing all the values supplied', async (...foo) => {
149
- type WithFoo = { foo?: string[] }
150
- const query = new PayloadBuilder<PayloadDivinerQueryPayload & WithFoo>({ schema: PayloadDivinerQuerySchema }).fields({ foo }).build()
151
- const results = await sut.divine([query])
152
- expect(results.length).toBeGreaterThan(0)
153
- expect(results.every(result => foo.every(v => (result as unknown as WithFoo)?.foo?.includes(v)))).toBe(true)
154
- })
155
- })
156
- })
157
- })
158
- describe('with order', () => {
159
- describe('not set', () => {
160
- it('returns payloads in ascending order', async () => {
161
- const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema }).build()
162
- const results = await sut.divine([query])
163
- expect(results).toEqual(insertedPayloads)
164
- })
165
- })
166
- describe('asc', () => {
167
- it('returns payloads in ascending order', async () => {
168
- const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema }).fields({ order: 'asc' }).build()
169
- const results = await sut.divine([query])
170
- expect(results).toEqual(insertedPayloads)
171
- })
172
- })
173
- describe('desc', () => {
174
- it('returns payloads in descending order', async () => {
175
- const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema }).fields({ order: 'desc' }).build()
176
- const results = await sut.divine([query])
177
- expect(results).toEqual([...insertedPayloads].toReversed())
178
- })
179
- })
180
- })
181
- })