@xyo-network/archivist 2.64.10 → 2.65.1
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/dist/cjs/ArchivingModule.js +1 -1
- package/dist/cjs/ArchivingModule.js.map +1 -1
- package/dist/cjs/CookieArchivist.js +7 -7
- package/dist/cjs/CookieArchivist.js.map +1 -1
- package/dist/cjs/StorageArchivist.js +41 -41
- package/dist/cjs/StorageArchivist.js.map +1 -1
- package/dist/docs.json +88379 -35028
- package/dist/esm/ArchivingModule.js +2 -2
- package/dist/esm/ArchivingModule.js.map +1 -1
- package/dist/esm/CookieArchivist.js +8 -8
- package/dist/esm/CookieArchivist.js.map +1 -1
- package/dist/esm/StorageArchivist.js +31 -31
- package/dist/esm/StorageArchivist.js.map +1 -1
- package/dist/types/ArchivingModule.d.ts +2 -2
- package/dist/types/ArchivingModule.d.ts.map +1 -1
- package/dist/types/CookieArchivist.d.ts +8 -8
- package/dist/types/CookieArchivist.d.ts.map +1 -1
- package/dist/types/StorageArchivist.d.ts +9 -9
- package/dist/types/StorageArchivist.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/ArchivingModule.ts +4 -4
- package/src/CookieArchivist.ts +8 -8
- package/src/StorageArchivist.ts +34 -34
- package/src/spec/testArchivist.ts +3 -3
package/src/StorageArchivist.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { fulfilled } from '@xylabs/promise'
|
|
3
|
-
import {
|
|
3
|
+
import { AbstractDirectArchivist } from '@xyo-network/abstract-archivist'
|
|
4
4
|
import { Account } from '@xyo-network/account'
|
|
5
5
|
import { AccountInstance } from '@xyo-network/account-model'
|
|
6
6
|
import {
|
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
ArchivistDeleteQuerySchema,
|
|
12
12
|
ArchivistInsertQuery,
|
|
13
13
|
ArchivistInsertQuerySchema,
|
|
14
|
-
ArchivistModule,
|
|
15
14
|
ArchivistModuleEventData,
|
|
16
15
|
ArchivistParams,
|
|
16
|
+
DirectArchivistModule,
|
|
17
17
|
} from '@xyo-network/archivist-model'
|
|
18
18
|
import { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
19
19
|
import { Logger, PayloadHasher } from '@xyo-network/core'
|
|
@@ -41,8 +41,8 @@ export class StorageArchivist<
|
|
|
41
41
|
TParams extends StorageArchivistParams = StorageArchivistParams,
|
|
42
42
|
TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,
|
|
43
43
|
>
|
|
44
|
-
extends
|
|
45
|
-
implements
|
|
44
|
+
extends AbstractDirectArchivist<TParams, TEventData>
|
|
45
|
+
implements DirectArchivistModule
|
|
46
46
|
{
|
|
47
47
|
static override configSchemas = [StorageArchivistConfigSchema]
|
|
48
48
|
|
|
@@ -92,18 +92,41 @@ export class StorageArchivist<
|
|
|
92
92
|
return this._storage
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
override
|
|
95
|
+
override async loadAccount(account?: AccountInstance, persistAccount?: boolean, privateStorage?: StoreBase, _logger?: Logger) {
|
|
96
|
+
if (!this._account) {
|
|
97
|
+
if (persistAccount) {
|
|
98
|
+
const privateKey = privateStorage?.get('privateKey')
|
|
99
|
+
if (privateKey) {
|
|
100
|
+
try {
|
|
101
|
+
this._account = await Account.create({ privateKey })
|
|
102
|
+
return this._account
|
|
103
|
+
} catch (ex) {
|
|
104
|
+
console.error(`Error reading Account from storage [${ex}] - Recreating Account`)
|
|
105
|
+
privateStorage?.remove('privateKey')
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return await super.loadAccount()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
override async start() {
|
|
114
|
+
await super.start()
|
|
115
|
+
this.saveAccount()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
protected override allHandler(): PromisableArray<Payload> {
|
|
96
119
|
this.logger?.log(`this.storage.length: ${this.storage.length}`)
|
|
97
120
|
return Object.entries(this.storage.getAll()).map(([, value]) => value)
|
|
98
121
|
}
|
|
99
122
|
|
|
100
|
-
override
|
|
123
|
+
protected override clearHandler(): void | Promise<void> {
|
|
101
124
|
this.logger?.log(`this.storage.length: ${this.storage.length}`)
|
|
102
125
|
this.storage.clear()
|
|
103
126
|
return this.emit('cleared', { module: this })
|
|
104
127
|
}
|
|
105
128
|
|
|
106
|
-
override async
|
|
129
|
+
protected override async commitHandler(): Promise<BoundWitness[]> {
|
|
107
130
|
this.logger?.log(`this.storage.length: ${this.storage.length}`)
|
|
108
131
|
const payloads = await this.all()
|
|
109
132
|
assertEx(payloads.length > 0, 'Nothing to commit')
|
|
@@ -124,7 +147,7 @@ export class StorageArchivist<
|
|
|
124
147
|
return compact(settled.filter(fulfilled).map((result) => result.value))
|
|
125
148
|
}
|
|
126
149
|
|
|
127
|
-
override async
|
|
150
|
+
protected override async deleteHandler(hashes: string[]): Promise<boolean[]> {
|
|
128
151
|
this.logger?.log(`delete: hashes.length: ${hashes.length}`)
|
|
129
152
|
const found = hashes.map((hash) => {
|
|
130
153
|
this.storage.remove(hash)
|
|
@@ -134,12 +157,12 @@ export class StorageArchivist<
|
|
|
134
157
|
return found
|
|
135
158
|
}
|
|
136
159
|
|
|
137
|
-
override async
|
|
160
|
+
protected override async getHandler(hashes: string[]): Promise<Payload[]> {
|
|
138
161
|
this.logger?.log(`get: hashes.length: ${hashes.length}`)
|
|
139
162
|
|
|
140
163
|
return await Promise.all(
|
|
141
164
|
hashes.map(async (hash) => {
|
|
142
|
-
const payload = this.storage.get(hash) ?? (await super.
|
|
165
|
+
const payload = this.storage.get(hash) ?? (await super.getHandler([hash]))[0] ?? null
|
|
143
166
|
if (this.storeParentReads) {
|
|
144
167
|
this.storage.set(hash, payload)
|
|
145
168
|
}
|
|
@@ -148,7 +171,7 @@ export class StorageArchivist<
|
|
|
148
171
|
)
|
|
149
172
|
}
|
|
150
173
|
|
|
151
|
-
async
|
|
174
|
+
protected async insertHandler(payloads: Payload[]): Promise<BoundWitness[]> {
|
|
152
175
|
const resultPayloads = await Promise.all(
|
|
153
176
|
payloads.map(async (payload) => {
|
|
154
177
|
const wrapper = PayloadWrapper.wrap(payload)
|
|
@@ -172,29 +195,6 @@ export class StorageArchivist<
|
|
|
172
195
|
return boundWitnesses
|
|
173
196
|
}
|
|
174
197
|
|
|
175
|
-
override async loadAccount(account?: AccountInstance, persistAccount?: boolean, privateStorage?: StoreBase, _logger?: Logger) {
|
|
176
|
-
if (!this._account) {
|
|
177
|
-
if (persistAccount) {
|
|
178
|
-
const privateKey = privateStorage?.get('privateKey')
|
|
179
|
-
if (privateKey) {
|
|
180
|
-
try {
|
|
181
|
-
this._account = await Account.create({ privateKey })
|
|
182
|
-
return this._account
|
|
183
|
-
} catch (ex) {
|
|
184
|
-
console.error(`Error reading Account from storage [${ex}] - Recreating Account`)
|
|
185
|
-
privateStorage?.remove('privateKey')
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return await super.loadAccount()
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
override async start() {
|
|
194
|
-
await super.start()
|
|
195
|
-
this.saveAccount()
|
|
196
|
-
}
|
|
197
|
-
|
|
198
198
|
protected saveAccount() {
|
|
199
199
|
if (this.persistAccount) {
|
|
200
200
|
const account = this.account
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { delay } from '@xylabs/delay'
|
|
6
|
-
import {
|
|
6
|
+
import { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
7
7
|
import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
|
|
8
8
|
import { PayloadHasher } from '@xyo-network/core'
|
|
9
9
|
import { Payload } from '@xyo-network/payload-model'
|
|
@@ -11,7 +11,7 @@ import { PayloadWrapper } from '@xyo-network/payload-wrapper'
|
|
|
11
11
|
import { IdSchema } from '@xyo-network/plugins'
|
|
12
12
|
import { Promisable } from '@xyo-network/promise'
|
|
13
13
|
|
|
14
|
-
export const testArchivistRoundTrip = (archivistPromise: Promisable<
|
|
14
|
+
export const testArchivistRoundTrip = (archivistPromise: Promisable<ArchivistInstance>, name: string) => {
|
|
15
15
|
test(`Archivist RoundTrip [${name}]`, async () => {
|
|
16
16
|
const idPayload: Payload<{ salt: string }> = {
|
|
17
17
|
salt: Date.now().toString(),
|
|
@@ -37,7 +37,7 @@ export const testArchivistRoundTrip = (archivistPromise: Promisable<ArchivistMod
|
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export const testArchivistAll = (archivist: Promisable<
|
|
40
|
+
export const testArchivistAll = (archivist: Promisable<ArchivistInstance>, name: string) => {
|
|
41
41
|
test(`Archivist All [${name}]`, async () => {
|
|
42
42
|
const idPayload = {
|
|
43
43
|
salt: Date.now().toString(),
|