@xyo-network/archivist-memory 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 +28 -32
- package/src/Archivist.ts +0 -52
- package/src/Config.ts +0 -18
- package/src/MemoryDriver.ts +0 -143
- package/src/index.ts +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/archivist-memory",
|
|
3
|
-
"version": "5.3.
|
|
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,54 +30,50 @@
|
|
|
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
|
-
"
|
|
41
|
-
"@xyo-network/archivist-
|
|
42
|
-
"@xyo-network/
|
|
43
|
-
"@xyo-network/
|
|
44
|
-
"@xyo-network/
|
|
45
|
-
"@xyo-network/payload-model": "~5.3.
|
|
46
|
-
"
|
|
39
|
+
"lru-cache": "~11.2.7",
|
|
40
|
+
"@xyo-network/archivist-model": "~5.3.24",
|
|
41
|
+
"@xyo-network/module-model": "~5.3.24",
|
|
42
|
+
"@xyo-network/archivist-generic": "~5.3.24",
|
|
43
|
+
"@xyo-network/archivist-abstract": "~5.3.24",
|
|
44
|
+
"@xyo-network/payload-model": "~5.3.24",
|
|
45
|
+
"@xyo-network/payload-builder": "~5.3.24"
|
|
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.
|
|
52
|
-
"@xylabs/ts-scripts-common": "~7.6.
|
|
53
|
-
"@xylabs/ts-scripts-
|
|
54
|
-
"@xylabs/tsconfig": "~7.6.
|
|
55
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
56
|
-
"@xyo-network/account": "~5.3.22",
|
|
57
|
-
"@xyo-network/account-model": "~5.3.22",
|
|
58
|
-
"@xyo-network/archivist-abstract": "~5.3.22",
|
|
59
|
-
"@xyo-network/archivist-acceptance-tests": "~5.3.22",
|
|
60
|
-
"@xyo-network/archivist-generic": "~5.3.22",
|
|
61
|
-
"@xyo-network/archivist-model": "~5.3.22",
|
|
62
|
-
"@xyo-network/id-payload-plugin": "~5.3.22",
|
|
63
|
-
"@xyo-network/module-model": "~5.3.22",
|
|
64
|
-
"@xyo-network/payload-builder": "~5.3.22",
|
|
65
|
-
"@xyo-network/payload-model": "~5.3.22",
|
|
66
|
-
"@xyo-network/payload-wrapper": "~5.3.22",
|
|
67
|
-
"@xyo-network/wallet": "~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",
|
|
68
55
|
"acorn": "^8.16.0",
|
|
69
56
|
"axios": "^1.14.0",
|
|
70
|
-
"
|
|
71
|
-
"esbuild": "^0.27.4",
|
|
72
|
-
"eslint": "^10.1.0",
|
|
57
|
+
"esbuild": "^0.28.0",
|
|
73
58
|
"ethers": "^6.16.0",
|
|
74
59
|
"lru-cache": "^11.2.7",
|
|
75
|
-
"rollup": "^4.60.1",
|
|
76
60
|
"tslib": "^2.8.1",
|
|
77
61
|
"typescript": "~5.9.3",
|
|
78
62
|
"vite": "^8.0.3",
|
|
79
63
|
"vitest": "~4.1.2",
|
|
80
|
-
"zod": "^4.3.6"
|
|
64
|
+
"zod": "^4.3.6",
|
|
65
|
+
"@xyo-network/account-model": "~5.3.24",
|
|
66
|
+
"@xyo-network/archivist-abstract": "~5.3.24",
|
|
67
|
+
"@xyo-network/account": "~5.3.24",
|
|
68
|
+
"@xyo-network/archivist-model": "~5.3.24",
|
|
69
|
+
"@xyo-network/archivist-generic": "~5.3.24",
|
|
70
|
+
"@xyo-network/archivist-acceptance-tests": "~5.3.24",
|
|
71
|
+
"@xyo-network/id-payload-plugin": "~5.3.24",
|
|
72
|
+
"@xyo-network/payload-builder": "~5.3.24",
|
|
73
|
+
"@xyo-network/module-model": "~5.3.24",
|
|
74
|
+
"@xyo-network/payload-model": "~5.3.24",
|
|
75
|
+
"@xyo-network/wallet": "~5.3.24",
|
|
76
|
+
"@xyo-network/payload-wrapper": "~5.3.24"
|
|
81
77
|
},
|
|
82
78
|
"peerDependencies": {
|
|
83
79
|
"@xylabs/sdk-js": "^5",
|
|
@@ -88,4 +84,4 @@
|
|
|
88
84
|
"publishConfig": {
|
|
89
85
|
"access": "public"
|
|
90
86
|
}
|
|
91
|
-
}
|
|
87
|
+
}
|
package/src/Archivist.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { StorageClassLabel } from '@xyo-network/archivist-abstract'
|
|
2
|
-
import { GenericArchivist, GenericArchivistParams } from '@xyo-network/archivist-generic'
|
|
3
|
-
import {
|
|
4
|
-
ArchivistAllQuerySchema,
|
|
5
|
-
ArchivistClearQuerySchema,
|
|
6
|
-
ArchivistCommitQuerySchema,
|
|
7
|
-
ArchivistDeleteQuerySchema,
|
|
8
|
-
ArchivistInsertQuerySchema,
|
|
9
|
-
ArchivistModuleEventData,
|
|
10
|
-
ArchivistNextQuerySchema,
|
|
11
|
-
AttachableArchivistInstance,
|
|
12
|
-
} from '@xyo-network/archivist-model'
|
|
13
|
-
import {
|
|
14
|
-
AnyConfigSchema, AttachableModuleInstance, creatableModule, ModuleInstance,
|
|
15
|
-
} from '@xyo-network/module-model'
|
|
16
|
-
import { Schema } from '@xyo-network/payload-model'
|
|
17
|
-
|
|
18
|
-
import { MemoryArchivistConfig, MemoryArchivistConfigSchema } from './Config.ts'
|
|
19
|
-
import { MemoryDriver } from './MemoryDriver.ts'
|
|
20
|
-
|
|
21
|
-
export type MemoryArchivistParams<TConfig extends AnyConfigSchema<MemoryArchivistConfig> = AnyConfigSchema<MemoryArchivistConfig>>
|
|
22
|
-
= GenericArchivistParams<TConfig>
|
|
23
|
-
@creatableModule()
|
|
24
|
-
export class MemoryArchivist<
|
|
25
|
-
TParams extends MemoryArchivistParams<AnyConfigSchema<MemoryArchivistConfig>> = MemoryArchivistParams,
|
|
26
|
-
TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,
|
|
27
|
-
>
|
|
28
|
-
extends GenericArchivist<TParams, TEventData>
|
|
29
|
-
implements AttachableArchivistInstance, ModuleInstance {
|
|
30
|
-
static override readonly configSchemas: Schema[] = [...super.configSchemas, MemoryArchivistConfigSchema]
|
|
31
|
-
static override readonly defaultConfigSchema: Schema = MemoryArchivistConfigSchema
|
|
32
|
-
static override readonly labels = { ...super.labels, [StorageClassLabel]: 'memory' }
|
|
33
|
-
|
|
34
|
-
override get queries() {
|
|
35
|
-
return [
|
|
36
|
-
ArchivistAllQuerySchema,
|
|
37
|
-
ArchivistDeleteQuerySchema,
|
|
38
|
-
ArchivistClearQuerySchema,
|
|
39
|
-
ArchivistInsertQuerySchema,
|
|
40
|
-
ArchivistCommitQuerySchema,
|
|
41
|
-
ArchivistNextQuerySchema,
|
|
42
|
-
...super.queries,
|
|
43
|
-
]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static override async paramsHandler<T extends AttachableModuleInstance<MemoryArchivistParams, ArchivistModuleEventData>>(
|
|
47
|
-
inParams?: Partial<T['params']>,
|
|
48
|
-
): Promise<T['params']> {
|
|
49
|
-
const superParams = await super.paramsHandler(inParams)
|
|
50
|
-
return { ...superParams, driver: superParams.driver ?? await MemoryDriver.create(superParams) }
|
|
51
|
-
}
|
|
52
|
-
}
|
package/src/Config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { EmptyObject, WithAdditional } from '@xylabs/sdk-js'
|
|
2
|
-
import type { ArchivistConfig } from '@xyo-network/archivist-model'
|
|
3
|
-
import {
|
|
4
|
-
asSchema, type Payload, type Schema,
|
|
5
|
-
} from '@xyo-network/payload-model'
|
|
6
|
-
|
|
7
|
-
export const MemoryArchivistConfigSchema = asSchema('network.xyo.archivist.memory.config', true)
|
|
8
|
-
export type MemoryArchivistConfigSchema = typeof MemoryArchivistConfigSchema
|
|
9
|
-
|
|
10
|
-
export type MemoryArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchema extends Schema | void = void> = ArchivistConfig<
|
|
11
|
-
WithAdditional<
|
|
12
|
-
{
|
|
13
|
-
max?: number
|
|
14
|
-
},
|
|
15
|
-
TConfig
|
|
16
|
-
>,
|
|
17
|
-
TSchema extends Schema ? TSchema : MemoryArchivistConfigSchema | ArchivistConfig['schema']
|
|
18
|
-
>
|
package/src/MemoryDriver.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Hash, Hex, Promisable,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import {
|
|
5
|
-
AbstractCreatable, assertEx,
|
|
6
|
-
creatable, CreatableParams, exists,
|
|
7
|
-
isDefined,
|
|
8
|
-
} from '@xylabs/sdk-js'
|
|
9
|
-
import type { ArchivistDriver, ArchivistNextOptions } from '@xyo-network/archivist-model'
|
|
10
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
11
|
-
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
12
|
-
import { LRUCache } from 'lru-cache'
|
|
13
|
-
|
|
14
|
-
export interface MemoryDriverConfig {
|
|
15
|
-
max?: number
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface MemoryDriverParams extends CreatableParams {
|
|
19
|
-
config: MemoryDriverConfig
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@creatable()
|
|
23
|
-
export class MemoryDriver extends AbstractCreatable<MemoryDriverParams>
|
|
24
|
-
implements ArchivistDriver<Hash, Payload, WithStorageMeta<Payload>> {
|
|
25
|
-
private _cache?: LRUCache<Hash, WithStorageMeta<Payload>>
|
|
26
|
-
private _config?: MemoryDriverConfig
|
|
27
|
-
private _dataHashIndex?: LRUCache<Hash, Hash>
|
|
28
|
-
private _sortedValues?: WithStorageMeta<Payload>[]
|
|
29
|
-
|
|
30
|
-
protected get cache() {
|
|
31
|
-
this._cache = this._cache ?? new LRUCache<Hash, WithStorageMeta<Payload>>({
|
|
32
|
-
max: this.max,
|
|
33
|
-
dispose: () => { this._sortedValues = undefined },
|
|
34
|
-
})
|
|
35
|
-
return this._cache
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected get config() {
|
|
39
|
-
return assertEx(this._config, () => 'Driver config is not set')
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
protected get dataHashIndex() {
|
|
43
|
-
this._dataHashIndex = this._dataHashIndex ?? new LRUCache<Hash, Hash>({ max: this.max })
|
|
44
|
-
return this._dataHashIndex
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
protected get max() {
|
|
48
|
-
return this.config?.max ?? 10_000
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected get sortedValues(): WithStorageMeta<Payload>[] {
|
|
52
|
-
if (!this._sortedValues) {
|
|
53
|
-
this._sortedValues = [...this.cache.values()].filter(exists).toSorted(PayloadBuilder.compareStorageMeta)
|
|
54
|
-
}
|
|
55
|
-
return this._sortedValues
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private static findIndexFromCursor(payloads: WithStorageMeta[], cursor: Hex) {
|
|
59
|
-
const index = payloads.findIndex(({ _sequence }) => _sequence === cursor)
|
|
60
|
-
if (index === -1) {
|
|
61
|
-
return Infinity // move to the end
|
|
62
|
-
}
|
|
63
|
-
return index
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
all(): Promisable<WithStorageMeta<Payload>[]> {
|
|
67
|
-
return [...this.sortedValues]
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
clear() {
|
|
71
|
-
this.cache.clear()
|
|
72
|
-
this._dataHashIndex = new LRUCache<Hash, Hash>({ max: this.max })
|
|
73
|
-
this._sortedValues = undefined
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
count() {
|
|
77
|
-
return this.cache.size
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
override createHandler(): Promisable<void> {
|
|
81
|
-
this._config = this.params.config ?? {}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async delete(hashes: Hash[]): Promise<WithStorageMeta[]> {
|
|
85
|
-
this._sortedValues = undefined
|
|
86
|
-
const deletedPayloads: WithStorageMeta<Payload>[] = (await Promise.all(this.cache
|
|
87
|
-
.dump()
|
|
88
|
-
.map(async ([key, item]) => {
|
|
89
|
-
const itemValueDataHash = await PayloadBuilder.dataHash(item.value)
|
|
90
|
-
if (hashes.includes(key) || hashes.includes(itemValueDataHash)) {
|
|
91
|
-
this.cache.delete(key)
|
|
92
|
-
return item.value
|
|
93
|
-
}
|
|
94
|
-
})))
|
|
95
|
-
.filter(exists)
|
|
96
|
-
this.rebuildDataHashIndex()
|
|
97
|
-
return deletedPayloads
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
get(hashes: Hash[]): Promisable<WithStorageMeta<Payload>[]> {
|
|
101
|
-
return hashes.map((hash) => {
|
|
102
|
-
const resolvedHash = this.dataHashIndex.get(hash) ?? hash
|
|
103
|
-
const result = this.cache.get(resolvedHash)
|
|
104
|
-
if (resolvedHash !== hash && !result) {
|
|
105
|
-
throw new Error('Missing referenced payload')
|
|
106
|
-
}
|
|
107
|
-
return result
|
|
108
|
-
}).filter(exists)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
insert(payloads: WithStorageMeta<Payload>[]): WithStorageMeta<Payload>[] {
|
|
112
|
-
this._sortedValues = undefined
|
|
113
|
-
const payloadsWithMeta = payloads.toSorted(PayloadBuilder.compareStorageMeta)
|
|
114
|
-
return payloadsWithMeta.map((payload) => {
|
|
115
|
-
return this.insertPayloadIntoCache(payload)
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
next(options?: ArchivistNextOptions): Promisable<WithStorageMeta<Payload>[]> {
|
|
120
|
-
const {
|
|
121
|
-
limit = 100, cursor, order, open = true,
|
|
122
|
-
} = options ?? {}
|
|
123
|
-
const all = order === 'desc' ? this.sortedValues.toReversed() : this.sortedValues
|
|
124
|
-
const startIndex = isDefined(cursor)
|
|
125
|
-
? MemoryDriver.findIndexFromCursor(all, cursor) + (open ? 1 : 0)
|
|
126
|
-
: 0
|
|
127
|
-
return all.slice(startIndex, startIndex + limit)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private insertPayloadIntoCache(payload: WithStorageMeta<Payload>): WithStorageMeta<Payload> {
|
|
131
|
-
this.cache.set(payload._hash, payload)
|
|
132
|
-
this.dataHashIndex.set(payload._dataHash, payload._hash)
|
|
133
|
-
return payload
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
private rebuildDataHashIndex() {
|
|
137
|
-
this._dataHashIndex = new LRUCache<Hash, Hash>({ max: this.max })
|
|
138
|
-
const payloads = this.cache.dump().map(([, item]) => item.value)
|
|
139
|
-
for (const payload of payloads) {
|
|
140
|
-
this.dataHashIndex.set(payload._dataHash, payload._hash)
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
package/src/index.ts
DELETED