@xyo-network/archivist-storage 5.3.22 → 5.3.25

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-storage",
3
- "version": "5.3.22",
3
+ "version": "5.3.25",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,56 +30,52 @@
30
30
  "types": "dist/neutral/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-abstract": "~5.3.22",
41
- "@xyo-network/archivist-model": "~5.3.22",
42
- "@xyo-network/boundwitness-model": "~5.3.22",
43
- "@xyo-network/module-model": "~5.3.22",
44
- "@xyo-network/payload-builder": "~5.3.22",
45
- "@xyo-network/payload-model": "~5.3.22",
46
- "store2": "~2.14.4"
39
+ "store2": "~2.14.4",
40
+ "@xyo-network/archivist-abstract": "~5.3.25",
41
+ "@xyo-network/payload-builder": "~5.3.25",
42
+ "@xyo-network/boundwitness-model": "~5.3.25",
43
+ "@xyo-network/module-model": "~5.3.25",
44
+ "@xyo-network/payload-model": "~5.3.25",
45
+ "@xyo-network/archivist-model": "~5.3.25"
47
46
  },
48
47
  "devDependencies": {
49
48
  "@opentelemetry/api": "^1.9.1",
50
49
  "@types/node": "^25.5.0",
51
- "@xylabs/sdk-js": "^5.0.91",
52
- "@xylabs/ts-scripts-common": "~7.6.8",
53
- "@xylabs/ts-scripts-yarn3": "~7.6.8",
54
- "@xylabs/tsconfig": "~7.6.8",
55
- "@xylabs/vitest-extended": "~5.0.91",
56
- "@xyo-network/account": "~5.3.22",
57
- "@xyo-network/archivist-abstract": "~5.3.22",
58
- "@xyo-network/archivist-acceptance-tests": "~5.3.22",
59
- "@xyo-network/archivist-memory": "~5.3.22",
60
- "@xyo-network/archivist-model": "~5.3.22",
61
- "@xyo-network/boundwitness-model": "~5.3.22",
62
- "@xyo-network/boundwitness-wrapper": "~5.3.22",
63
- "@xyo-network/id-payload-plugin": "~5.3.22",
64
- "@xyo-network/module-model": "~5.3.22",
65
- "@xyo-network/node-memory": "~5.3.22",
66
- "@xyo-network/payload-builder": "~5.3.22",
67
- "@xyo-network/payload-model": "~5.3.22",
68
- "@xyo-network/payload-wrapper": "~5.3.22",
50
+ "@xylabs/sdk-js": "^5.0.93",
51
+ "@xylabs/ts-scripts-common": "~7.6.16",
52
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
53
+ "@xylabs/tsconfig": "~7.6.16",
54
+ "@xylabs/vitest-extended": "~5.0.93",
69
55
  "acorn": "^8.16.0",
70
56
  "axios": "^1.14.0",
71
- "cosmiconfig": "^9.0.1",
72
- "esbuild": "^0.27.4",
73
- "eslint": "^10.1.0",
57
+ "esbuild": "^0.28.0",
74
58
  "ethers": "^6.16.0",
75
- "rollup": "^4.60.1",
76
59
  "store2": "~2.14.4",
77
60
  "tslib": "^2.8.1",
78
61
  "typescript": "~5.9.3",
79
62
  "uuid": "~13.0.0",
80
63
  "vite": "^8.0.3",
81
64
  "vitest": "~4.1.2",
82
- "zod": "^4.3.6"
65
+ "zod": "^4.3.6",
66
+ "@xyo-network/account": "~5.3.25",
67
+ "@xyo-network/archivist-abstract": "~5.3.25",
68
+ "@xyo-network/archivist-model": "~5.3.25",
69
+ "@xyo-network/boundwitness-model": "~5.3.25",
70
+ "@xyo-network/archivist-memory": "~5.3.25",
71
+ "@xyo-network/boundwitness-wrapper": "~5.3.25",
72
+ "@xyo-network/payload-builder": "~5.3.25",
73
+ "@xyo-network/module-model": "~5.3.25",
74
+ "@xyo-network/id-payload-plugin": "~5.3.25",
75
+ "@xyo-network/archivist-acceptance-tests": "~5.3.25",
76
+ "@xyo-network/node-memory": "~5.3.25",
77
+ "@xyo-network/payload-model": "~5.3.25",
78
+ "@xyo-network/payload-wrapper": "~5.3.25"
83
79
  },
84
80
  "peerDependencies": {
85
81
  "@xylabs/sdk-js": "^5",
@@ -90,4 +86,4 @@
90
86
  "publishConfig": {
91
87
  "access": "public"
92
88
  }
93
- }
89
+ }
@@ -1,200 +0,0 @@
1
- import type {
2
- Hash, Hex, Promisable, PromisableArray,
3
- } from '@xylabs/sdk-js'
4
- import {
5
- assertEx, exists, fulfilled,
6
- } from '@xylabs/sdk-js'
7
- import { AbstractArchivist, StorageClassLabel } from '@xyo-network/archivist-abstract'
8
- import type {
9
- ArchivistConfig,
10
- ArchivistInsertQuery,
11
- ArchivistInstance,
12
- ArchivistModuleEventData,
13
- ArchivistNextOptions,
14
- ArchivistParams,
15
- } from '@xyo-network/archivist-model'
16
- import {
17
- ArchivistAllQuerySchema,
18
- ArchivistClearQuerySchema,
19
- ArchivistCommitQuerySchema,
20
- ArchivistDeleteQuerySchema,
21
- ArchivistInsertQuerySchema,
22
- ArchivistNextQuerySchema,
23
- } from '@xyo-network/archivist-model'
24
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
25
- import type { AnyConfigSchema } from '@xyo-network/module-model'
26
- import { PayloadBuilder } from '@xyo-network/payload-builder'
27
- import {
28
- asSchema,
29
- type Payload, type Schema, type WithStorageMeta,
30
- } from '@xyo-network/payload-model'
31
- import type { StoreBase, StoreType } from 'store2'
32
- import store from 'store2'
33
-
34
- const storeTypes = store as unknown as StoreType
35
-
36
- export const StorageArchivistConfigSchema = asSchema('network.xyo.archivist.storage.config', true)
37
- export type StorageArchivistConfigSchema = typeof StorageArchivistConfigSchema
38
-
39
- export type StorageArchivistConfig = ArchivistConfig<{
40
- maxEntries?: number
41
- maxEntrySize?: number
42
- namespace?: string
43
- type?: 'local' | 'session' | 'page'
44
- }, StorageArchivistConfigSchema>
45
-
46
- export type StorageArchivistParams = ArchivistParams<AnyConfigSchema<StorageArchivistConfig>>
47
- export class StorageArchivist<
48
- TParams extends StorageArchivistParams = StorageArchivistParams,
49
- TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,
50
- >
51
- extends AbstractArchivist<TParams, TEventData>
52
- implements ArchivistInstance {
53
- static override readonly configSchemas: Schema[] = [...super.configSchemas, StorageArchivistConfigSchema]
54
- static override readonly defaultConfigSchema: Schema = StorageArchivistConfigSchema
55
- static override readonly labels = { ...super.labels, [StorageClassLabel]: 'disk' }
56
-
57
- private _privateStorage: StoreBase | undefined
58
- private _storage: StoreBase | undefined
59
-
60
- get maxEntries() {
61
- return this.config?.maxEntries ?? 1000
62
- }
63
-
64
- get maxEntrySize() {
65
- return this.config?.maxEntrySize ?? 16_000
66
- }
67
-
68
- get namespace() {
69
- return this.config?.namespace ?? 'xyo-archivist'
70
- }
71
-
72
- override get queries(): Schema[] {
73
- return [
74
- ArchivistAllQuerySchema,
75
- ArchivistDeleteQuerySchema,
76
- ArchivistClearQuerySchema,
77
- ArchivistInsertQuerySchema,
78
- ArchivistCommitQuerySchema,
79
- ArchivistNextQuerySchema,
80
- ...super.queries,
81
- ]
82
- }
83
-
84
- get type() {
85
- return this.config?.type ?? 'local'
86
- }
87
-
88
- /* This has to be a getter so that it can access it during construction */
89
- private get privateStorage(): StoreBase {
90
- this._privateStorage = this._storage ?? storeTypes[this.type].namespace(`${this.namespace}|private`)
91
- return this._privateStorage
92
- }
93
-
94
- /* This has to be a getter so that it can access it during construction */
95
- private get storage(): StoreBase {
96
- this._storage = this._storage ?? storeTypes[this.type].namespace(this.namespace)
97
- return this._storage
98
- }
99
-
100
- protected override allHandler(): PromisableArray<WithStorageMeta<Payload>> {
101
- const found = new Set<string>()
102
- this.logger?.log(`this.storage.length: ${this.storage.length}`)
103
- return Object.entries(this.storage.getAll())
104
- .map(([, value]) => value)
105
- .filter((payload) => {
106
- if (found.has(payload._dataHash)) {
107
- return false
108
- } else {
109
- found.add(payload._dataHash)
110
- return true
111
- }
112
- })
113
- .toSorted(PayloadBuilder.compareStorageMeta)
114
- }
115
-
116
- protected override clearHandler(): void | Promise<void> {
117
- this.logger?.log(`this.storage.length: ${this.storage.length}`)
118
- this.storage.clear()
119
- return this.emit('cleared', { mod: this })
120
- }
121
-
122
- protected override async commitHandler(): Promise<BoundWitness[]> {
123
- this.logger?.log(`this.storage.length: ${this.storage.length}`)
124
- const payloads = await this.next({ limit: Number.MAX_SAFE_INTEGER })
125
- assertEx(payloads.length > 0, () => 'Nothing to commit')
126
- const settled = (await Promise.allSettled(
127
- Object.values((await this.parentArchivists()).commit ?? [])?.map(async (parent) => {
128
- const queryPayload: ArchivistInsertQuery = { schema: ArchivistInsertQuerySchema }
129
- const query = await this.bindQuery(queryPayload, payloads)
130
- return (await parent?.query(query[0], query[1]))?.[0]
131
- }),
132
- )).filter(exists)
133
- // TODO - rather than clear, delete the payloads that come back as successfully inserted
134
- await this.clear()
135
- return (settled.filter(fulfilled).map(result => result.value)).filter(exists)
136
- }
137
-
138
- protected override async deleteHandler(hashes: Hash[]): Promise<WithStorageMeta<Payload>[]> {
139
- return (
140
- await Promise.all(
141
- hashes.map((hash) => {
142
- const payload = this.storage.get(hash)
143
- if (payload) {
144
- this.storage.remove(hash)
145
- }
146
- return payload
147
- }),
148
- )
149
- ).filter(exists)
150
- }
151
-
152
- protected getFromCursor(
153
- order: 'asc' | 'desc' = 'asc',
154
- limit: number = 10,
155
- cursor?: Hex,
156
- open?: boolean,
157
- ): WithStorageMeta[] {
158
- const all = Object.values(this.storage.getAll()) as WithStorageMeta[]
159
- const payloads: WithStorageMeta[] = all
160
- .map(value => value)
161
- .toSorted((item1, item2) => {
162
- return order === 'asc' ? PayloadBuilder.compareStorageMeta(item1, item2) : PayloadBuilder.compareStorageMeta(item2, item1)
163
- })
164
- const index = payloads.findIndex(payload => payload._sequence === cursor)
165
- if (index !== -1) {
166
- return payloads.slice(index + (open ? 1 : 0), index + (open ? 1 : 0) + limit)
167
- }
168
- return payloads.slice(0, limit)
169
- }
170
-
171
- protected override getHandler(hashes: string[]): Promisable<WithStorageMeta<Payload>[]> {
172
- return (
173
- hashes.map((hash) => {
174
- return this.storage.get(hash)
175
- })
176
- ).filter(exists)
177
- }
178
-
179
- protected override async insertHandler(payloads: WithStorageMeta<Payload>[]): Promise<WithStorageMeta<Payload>[]> {
180
- return await Promise.all(payloads.map((payload) => {
181
- const value = JSON.stringify(payload)
182
- // console.log('insert.storagePayloads:', storagePayload)
183
- assertEx(value.length < this.maxEntrySize, () => `Payload too large [${payload._hash}, ${value.length}]`)
184
- this.storage.set(payload._hash, payload)
185
- this.storage.set(payload._dataHash, payload)
186
- return payload
187
- }))
188
- }
189
-
190
- protected override nextHandler(options?: ArchivistNextOptions): Promisable<WithStorageMeta<Payload>[]> {
191
- const {
192
- limit, cursor, order, open = true,
193
- } = options ?? {}
194
- return this.getFromCursor(order, limit ?? 10, cursor, open)
195
- }
196
-
197
- protected override async startHandler() {
198
- await super.startHandler()
199
- }
200
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './StorageArchivist.ts'