@xyo-network/archivist-lmdb 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/archivist-lmdb",
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,39 +30,54 @@
30
30
  "types": "dist/browser/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-abstract": "~5.3.20",
40
- "@xyo-network/archivist-model": "~5.3.20",
41
- "@xyo-network/boundwitness-model": "~5.3.20",
42
- "@xyo-network/module-model": "~5.3.20",
43
- "@xyo-network/payload-builder": "~5.3.20",
44
- "@xyo-network/payload-model": "~5.3.20"
39
+ "@xyo-network/archivist-model": "~5.3.24",
40
+ "@xyo-network/archivist-abstract": "~5.3.24",
41
+ "@xyo-network/boundwitness-model": "~5.3.24",
42
+ "@xyo-network/payload-builder": "~5.3.24",
43
+ "@xyo-network/payload-model": "~5.3.24",
44
+ "@xyo-network/module-model": "~5.3.24"
45
45
  },
46
46
  "devDependencies": {
47
- "@xylabs/sdk-js": "^5.0.90",
48
- "@xylabs/ts-scripts-common": "~7.5.6",
49
- "@xylabs/ts-scripts-yarn3": "~7.5.6",
50
- "@xylabs/tsconfig": "~7.5.6",
51
- "@xylabs/vitest-extended": "~5.0.90",
52
- "@xyo-network/account": "~5.3.20",
53
- "@xyo-network/account-model": "~5.3.20",
54
- "@xyo-network/archivist-acceptance-tests": "~5.3.20",
55
- "@xyo-network/id-payload-plugin": "~5.3.20",
56
- "@xyo-network/payload-wrapper": "~5.3.20",
57
- "@xyo-network/wallet": "~5.3.20",
47
+ "@opentelemetry/api": "^1.9.1",
48
+ "@types/node": "^25.5.0",
49
+ "@xylabs/sdk-js": "^5.0.93",
50
+ "@xylabs/ts-scripts-common": "~7.6.16",
51
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
52
+ "@xylabs/tsconfig": "~7.6.16",
53
+ "@xylabs/vitest-extended": "~5.0.93",
54
+ "acorn": "^8.16.0",
55
+ "axios": "^1.14.0",
56
+ "esbuild": "^0.28.0",
57
+ "ethers": "^6.16.0",
58
58
  "lmdb": "^3.5.2",
59
+ "tslib": "^2.8.1",
59
60
  "typescript": "~5.9.3",
60
61
  "uuid": "~13.0.0",
62
+ "vite": "^8.0.3",
61
63
  "vitest": "~4.1.2",
62
- "zod": "^4.3.6"
64
+ "zod": "^4.3.6",
65
+ "@xyo-network/archivist-abstract": "~5.3.24",
66
+ "@xyo-network/account": "~5.3.24",
67
+ "@xyo-network/account-model": "~5.3.24",
68
+ "@xyo-network/archivist-acceptance-tests": "~5.3.24",
69
+ "@xyo-network/archivist-model": "~5.3.24",
70
+ "@xyo-network/module-model": "~5.3.24",
71
+ "@xyo-network/boundwitness-model": "~5.3.24",
72
+ "@xyo-network/payload-builder": "~5.3.24",
73
+ "@xyo-network/id-payload-plugin": "~5.3.24",
74
+ "@xyo-network/payload-model": "~5.3.24",
75
+ "@xyo-network/payload-wrapper": "~5.3.24",
76
+ "@xyo-network/wallet": "~5.3.24"
63
77
  },
64
78
  "peerDependencies": {
65
79
  "@xylabs/sdk-js": "^5",
80
+ "ethers": "^6",
66
81
  "lmdb": "^3",
67
82
  "tslib": "^2.8.1",
68
83
  "zod": "^4"
@@ -70,4 +85,4 @@
70
85
  "publishConfig": {
71
86
  "access": "public"
72
87
  }
73
- }
88
+ }
package/src/Archivist.ts DELETED
@@ -1,183 +0,0 @@
1
- import {
2
- assertEx,
3
- exists,
4
- fulfilled, Hash, Hex,
5
- } from '@xylabs/sdk-js'
6
- import { AbstractArchivist, StorageClassLabel } from '@xyo-network/archivist-abstract'
7
- import {
8
- ArchivistAllQuerySchema,
9
- ArchivistClearQuerySchema,
10
- ArchivistCommitQuerySchema,
11
- ArchivistDeleteQuerySchema,
12
- ArchivistInsertQuery,
13
- ArchivistInsertQuerySchema,
14
- ArchivistModuleEventData,
15
- ArchivistNextOptions,
16
- ArchivistNextQuerySchema,
17
- IndexDescription,
18
- } from '@xyo-network/archivist-model'
19
- import { BoundWitness } from '@xyo-network/boundwitness-model'
20
- import { creatableModule } from '@xyo-network/module-model'
21
- import { PayloadBuilder } from '@xyo-network/payload-builder'
22
- import {
23
- Payload, Schema, SequenceConstants,
24
- WithStorageMeta,
25
- } from '@xyo-network/payload-model'
26
- import {
27
- Database, open,
28
- RangeOptions, RootDatabase,
29
- } from 'lmdb'
30
-
31
- import { LmdbArchivistConfigSchema } from './Config.ts'
32
- import { LmdbArchivistParams } from './Params.ts'
33
-
34
- @creatableModule()
35
- export class LmdbArchivist<
36
- TParams extends LmdbArchivistParams = LmdbArchivistParams,
37
- TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,
38
- > extends AbstractArchivist<TParams, TEventData> {
39
- static override readonly configSchemas: Schema[] = [...super.configSchemas, LmdbArchivistConfigSchema]
40
- static override readonly defaultConfigSchema: Schema = LmdbArchivistConfigSchema
41
- static override readonly labels = { ...super.labels, [StorageClassLabel]: 'disk' }
42
-
43
- protected static readonly dataHashIndex: IndexDescription = {
44
- key: { _dataHash: 1 }, multiEntry: false, unique: false,
45
- }
46
-
47
- protected static readonly sequenceIndex: IndexDescription = {
48
- key: { _sequence: 1 }, multiEntry: false, unique: true,
49
- }
50
-
51
- protected dataHashIndex!: Database<Hash, string>
52
- protected db!: RootDatabase
53
- protected hashIndex!: Database<WithStorageMeta<Payload>, Hash>
54
- protected sequenceIndex!: Database<Hash, Hex>
55
-
56
- get dbName() {
57
- return assertEx(this.config.dbName, () => 'No dbName specified')
58
- }
59
-
60
- get folderPath() {
61
- return `${this.location}/${this.config.dbName}/${this.storeName}`
62
- }
63
-
64
- get location() {
65
- return assertEx(this.config.location, () => 'No location specified')
66
- }
67
-
68
- override get queries() {
69
- return [
70
- ArchivistAllQuerySchema,
71
- ArchivistDeleteQuerySchema,
72
- ArchivistClearQuerySchema,
73
- ArchivistInsertQuerySchema,
74
- ArchivistCommitQuerySchema,
75
- ArchivistNextQuerySchema,
76
- ...super.queries,
77
- ]
78
- }
79
-
80
- get storeName() {
81
- return assertEx(this.config.storeName, () => 'No storeName specified')
82
- }
83
-
84
- override async startHandler() {
85
- await super.startHandler()
86
-
87
- // Open LMDB database
88
- this.db = open({
89
- path: this.folderPath,
90
- maxDbs: 3, // Payloads, dataHashIndex, sequenceIndex
91
- })
92
-
93
- // Open sub-databases
94
- this.hashIndex = this.db.openDB<WithStorageMeta<Payload>, Hash>({ name: 'payloads' })
95
- this.dataHashIndex = this.db.openDB<Hash, string>({ name: 'dataHashIndex' })
96
- this.sequenceIndex = this.db.openDB<Hash, Hex>({ name: 'sequenceIndex' })
97
-
98
- if (this.config.clearStoreOnStart) {
99
- await this.clearHandler()
100
- }
101
- }
102
-
103
- protected override allHandler(): WithStorageMeta<Payload>[] {
104
- return [...this.hashIndex.getRange({})].map(entry => entry.value).toSorted(PayloadBuilder.compareStorageMeta)
105
- }
106
-
107
- protected override async clearHandler(): Promise<void> {
108
- // Ensure all operations are synchronous within transaction
109
- await this.db.transaction(() => {
110
- this.hashIndex.clearSync()
111
- this.dataHashIndex.clearSync()
112
- this.sequenceIndex.clearSync()
113
- })
114
- return this.emit('cleared', { mod: this })
115
- }
116
-
117
- protected override async commitHandler(): Promise<BoundWitness[]> {
118
- const payloads = this.allHandler()
119
- const settled = await Promise.allSettled(
120
- Object.values((await this.parentArchivists()).commit ?? []).map(async (parent) => {
121
- const queryPayload: ArchivistInsertQuery = { schema: ArchivistInsertQuerySchema }
122
- const query = await this.bindQuery(queryPayload, payloads)
123
- return (await parent?.query(query[0], query[1]))?.[0]
124
- }).filter(exists),
125
- )
126
- await this.clearHandler()
127
- return settled.filter(fulfilled).map(result => result.value).filter(exists)
128
- }
129
-
130
- protected override async deleteHandler(hashes: Hash[]): Promise<WithStorageMeta<Payload>[]> {
131
- return (await this.db.transaction(() => {
132
- return hashes.map((hash) => {
133
- const payload = this.hashIndex.get(hash)
134
- if (payload) {
135
- this.hashIndex.removeSync(hash)
136
- this.dataHashIndex.removeSync(payload._dataHash)
137
- this.sequenceIndex.removeSync(payload._sequence)
138
- return payload
139
- }
140
- })
141
- })).filter(exists)
142
- }
143
-
144
- protected override getHandler(hashes: Hash[]): WithStorageMeta<Payload>[] {
145
- return hashes.map((hash) => {
146
- const byHash = this.hashIndex.get(hash)
147
- if (byHash) return byHash
148
- const byDataHash = this.dataHashIndex.get(hash)
149
- if (byDataHash) return this.hashIndex.get(byDataHash)
150
- }).filter(exists)
151
- }
152
-
153
- protected override async insertHandler(payloads: WithStorageMeta<Payload>[]): Promise<WithStorageMeta<Payload>[]> {
154
- await this.db.transaction(() => {
155
- for (const payload of payloads) {
156
- this.hashIndex.putSync(payload._hash, payload)
157
- this.dataHashIndex.putSync(payload._dataHash, payload._hash)
158
- this.sequenceIndex.putSync(payload._sequence, payload._hash)
159
- }
160
- })
161
- return payloads
162
- }
163
-
164
- protected override nextHandler(options?: ArchivistNextOptions): WithStorageMeta<Payload>[] {
165
- const {
166
- limit = 100, cursor, order, open = cursor ? true : false,
167
- } = options ?? {}
168
-
169
- // Determine search range based on order (ascending or descending)
170
- const rangeOptions: RangeOptions = order === 'desc'
171
- ? { start: cursor ?? SequenceConstants.maxLocalSequence, reverse: true }
172
- : { start: cursor ?? SequenceConstants.minLocalSequence }
173
-
174
- // Get range of sequence-indexed hashes
175
- const sequenceEntries = [...this.sequenceIndex.getRange(rangeOptions)]
176
- .slice(open ? 1 : 0, limit + (open ? 1 : 0)) // Apply cursor offset and limit
177
-
178
- // Fetch full payloads using hashes retrieved from sequence index
179
- return sequenceEntries
180
- .map(({ value: hash }) => this.hashIndex.get(hash))
181
- .filter(exists)
182
- }
183
- }
package/src/Config.ts DELETED
@@ -1,27 +0,0 @@
1
- import type { ArchivistConfig } from '@xyo-network/archivist-model'
2
- import { asSchema } from '@xyo-network/payload-model'
3
-
4
- import { LmdbArchivistSchema } from './Schema.ts'
5
-
6
- export const LmdbArchivistConfigSchema = asSchema(`${LmdbArchivistSchema}.config`, true)
7
- export type LmdbArchivistConfigSchema = typeof LmdbArchivistConfigSchema
8
-
9
- export type LmdbArchivistConfig<TStoreName extends string = string> = ArchivistConfig<{
10
- /**
11
- * If true, the store will be cleared on start
12
- */
13
- clearStoreOnStart?: boolean
14
- /**
15
- * The database name - also used as the filename for the db
16
- */
17
- dbName?: string
18
- /**
19
- * The location where the folder for the db will be created
20
- */
21
- location?: string
22
- schema: LmdbArchivistConfigSchema
23
- /**
24
- * The name of the object store - becomes a sub-level
25
- */
26
- storeName?: TStoreName
27
- }>
package/src/Params.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { ArchivistParams } from '@xyo-network/archivist-model'
2
- import type { AnyConfigSchema } from '@xyo-network/module-model'
3
-
4
- import type { LmdbArchivistConfig } from './Config.ts'
5
-
6
- export interface LmdbArchivistParams extends ArchivistParams<AnyConfigSchema<LmdbArchivistConfig>> {
7
-
8
- }
package/src/Schema.ts DELETED
@@ -1,4 +0,0 @@
1
- import { asSchema } from '@xyo-network/payload-model'
2
-
3
- export const LmdbArchivistSchema = asSchema('network.xyo.archivist.lmdb', true)
4
- export type LmdbArchivistSchema = typeof LmdbArchivistSchema
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './Archivist.ts'
2
- export * from './Config.ts'
3
- export * from './Params.ts'
4
- export * from './Schema.ts'