@xyo-network/archivist 2.38.15 → 2.38.17
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/Archivist.d.ts +3 -3
- package/dist/cjs/Archivist.d.ts.map +1 -1
- package/dist/cjs/Config.d.ts +2 -2
- package/dist/cjs/Config.d.ts.map +1 -1
- package/dist/cjs/Queries/Delete.d.ts +1 -1
- package/dist/cjs/Queries/Delete.d.ts.map +1 -1
- package/dist/cjs/Queries/Find.d.ts +1 -1
- package/dist/cjs/Queries/Find.d.ts.map +1 -1
- package/dist/cjs/Queries/Get.d.ts +1 -1
- package/dist/cjs/Queries/Get.d.ts.map +1 -1
- package/dist/cjs/Queries/Insert.d.ts +1 -1
- package/dist/cjs/Queries/Insert.d.ts.map +1 -1
- package/dist/cjs/XyoArchivist.d.ts +7 -7
- package/dist/cjs/XyoArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoArchivist.js +26 -26
- package/dist/cjs/XyoArchivist.js.map +1 -1
- package/dist/cjs/XyoArchivistWrapper.d.ts +4 -4
- package/dist/cjs/XyoArchivistWrapper.d.ts.map +1 -1
- package/dist/cjs/XyoArchivistWrapper.js +24 -24
- package/dist/cjs/XyoArchivistWrapper.js.map +1 -1
- package/dist/cjs/XyoCookieArchivist.d.ts +9 -9
- package/dist/cjs/XyoCookieArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoCookieArchivist.js +63 -63
- package/dist/cjs/XyoCookieArchivist.js.map +1 -1
- package/dist/cjs/XyoMemoryArchivist.d.ts +8 -8
- package/dist/cjs/XyoMemoryArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoMemoryArchivist.js +51 -51
- package/dist/cjs/XyoMemoryArchivist.js.map +1 -1
- package/dist/cjs/XyoStorageArchivist.d.ts +18 -18
- package/dist/cjs/XyoStorageArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoStorageArchivist.js +101 -99
- package/dist/cjs/XyoStorageArchivist.js.map +1 -1
- package/dist/docs.json +2388 -2388
- package/dist/esm/Archivist.d.ts +3 -3
- package/dist/esm/Archivist.d.ts.map +1 -1
- package/dist/esm/Config.d.ts +2 -2
- package/dist/esm/Config.d.ts.map +1 -1
- package/dist/esm/Queries/Delete.d.ts +1 -1
- package/dist/esm/Queries/Delete.d.ts.map +1 -1
- package/dist/esm/Queries/Find.d.ts +1 -1
- package/dist/esm/Queries/Find.d.ts.map +1 -1
- package/dist/esm/Queries/Get.d.ts +1 -1
- package/dist/esm/Queries/Get.d.ts.map +1 -1
- package/dist/esm/Queries/Insert.d.ts +1 -1
- package/dist/esm/Queries/Insert.d.ts.map +1 -1
- package/dist/esm/XyoArchivist.d.ts +7 -7
- package/dist/esm/XyoArchivist.d.ts.map +1 -1
- package/dist/esm/XyoArchivist.js +25 -25
- package/dist/esm/XyoArchivist.js.map +1 -1
- package/dist/esm/XyoArchivistWrapper.d.ts +4 -4
- package/dist/esm/XyoArchivistWrapper.d.ts.map +1 -1
- package/dist/esm/XyoArchivistWrapper.js +23 -23
- package/dist/esm/XyoArchivistWrapper.js.map +1 -1
- package/dist/esm/XyoCookieArchivist.d.ts +9 -9
- package/dist/esm/XyoCookieArchivist.d.ts.map +1 -1
- package/dist/esm/XyoCookieArchivist.js +54 -54
- package/dist/esm/XyoCookieArchivist.js.map +1 -1
- package/dist/esm/XyoMemoryArchivist.d.ts +8 -8
- package/dist/esm/XyoMemoryArchivist.d.ts.map +1 -1
- package/dist/esm/XyoMemoryArchivist.js +50 -50
- package/dist/esm/XyoMemoryArchivist.js.map +1 -1
- package/dist/esm/XyoStorageArchivist.d.ts +18 -18
- package/dist/esm/XyoStorageArchivist.d.ts.map +1 -1
- package/dist/esm/XyoStorageArchivist.js +89 -89
- package/dist/esm/XyoStorageArchivist.js.map +1 -1
- package/package.json +6 -6
- package/src/Archivist.ts +3 -3
- package/src/Config.ts +3 -2
- package/src/Queries/Delete.ts +1 -1
- package/src/Queries/Find.ts +1 -1
- package/src/Queries/Get.ts +1 -1
- package/src/Queries/Insert.ts +1 -1
- package/src/XyoArchivist.ts +30 -29
- package/src/XyoArchivistWrapper.ts +24 -24
- package/src/XyoCookieArchivist.ts +61 -61
- package/src/XyoMemoryArchivist.ts +58 -57
- package/src/XyoStorageArchivist.ts +98 -96
|
@@ -23,25 +23,23 @@ export type XyoStorageArchivistConfigSchema = 'network.xyo.module.config.archivi
|
|
|
23
23
|
export const XyoStorageArchivistConfigSchema: XyoStorageArchivistConfigSchema = 'network.xyo.module.config.archivist.storage'
|
|
24
24
|
|
|
25
25
|
export type XyoStorageArchivistConfig = XyoArchivistConfig<{
|
|
26
|
-
schema: XyoStorageArchivistConfigSchema
|
|
27
|
-
type?: 'local' | 'session' | 'page'
|
|
28
|
-
namespace?: string
|
|
29
26
|
maxEntries?: number
|
|
30
27
|
maxEntrySize?: number
|
|
28
|
+
namespace?: string
|
|
31
29
|
persistAccount?: boolean
|
|
30
|
+
schema: XyoStorageArchivistConfigSchema
|
|
31
|
+
type?: 'local' | 'session' | 'page'
|
|
32
32
|
}>
|
|
33
33
|
|
|
34
34
|
export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig> {
|
|
35
|
-
static override
|
|
36
|
-
return (await super.create(params)) as XyoStorageArchivist
|
|
37
|
-
}
|
|
35
|
+
static override configSchema = XyoStorageArchivistConfigSchema
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
37
|
+
private _privateStorage: StoreBase | undefined
|
|
38
|
+
private _storage: StoreBase | undefined
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
constructor(params?: XyoModuleParams<XyoStorageArchivistConfig>) {
|
|
41
|
+
super(params)
|
|
42
|
+
this.loadAccount()
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
public get maxEntries() {
|
|
@@ -52,87 +50,90 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
52
50
|
return this.config?.maxEntries ?? 16000
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
public get
|
|
56
|
-
return this.config?.
|
|
53
|
+
public get namespace() {
|
|
54
|
+
return this.config?.namespace ?? 'xyo-archivist'
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
public
|
|
60
|
-
return
|
|
61
|
-
XyoArchivistAllQuerySchema,
|
|
62
|
-
XyoArchivistDeleteQuerySchema,
|
|
63
|
-
XyoArchivistClearQuerySchema,
|
|
64
|
-
XyoArchivistFindQuerySchema,
|
|
65
|
-
XyoArchivistCommitQuerySchema,
|
|
66
|
-
...super.queries(),
|
|
67
|
-
]
|
|
57
|
+
public get persistAccount() {
|
|
58
|
+
return this.config?.persistAccount ?? false
|
|
68
59
|
}
|
|
69
60
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
private get storage(): StoreBase {
|
|
73
|
-
this._storage = this._storage ?? store[this.type].namespace(this.namespace)
|
|
74
|
-
return this._storage
|
|
61
|
+
public get type() {
|
|
62
|
+
return this.config?.type ?? 'local'
|
|
75
63
|
}
|
|
76
64
|
|
|
77
65
|
/* This has to be a getter so that it can access it during construction */
|
|
78
|
-
private _privateStorage: StoreBase | undefined
|
|
79
66
|
private get privateStorage(): StoreBase {
|
|
80
67
|
this._privateStorage = this._storage ?? store[this.type].namespace(`${this.namespace}|private`)
|
|
81
68
|
return this._privateStorage
|
|
82
69
|
}
|
|
83
70
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.
|
|
71
|
+
/* This has to be a getter so that it can access it during construction */
|
|
72
|
+
private get storage(): StoreBase {
|
|
73
|
+
this._storage = this._storage ?? store[this.type].namespace(this.namespace)
|
|
74
|
+
return this._storage
|
|
87
75
|
}
|
|
88
76
|
|
|
89
|
-
override async
|
|
90
|
-
await super.
|
|
91
|
-
this.saveAccount()
|
|
92
|
-
return this
|
|
77
|
+
static override async create(params?: XyoModuleParams<XyoStorageArchivistConfig>): Promise<XyoStorageArchivist> {
|
|
78
|
+
return (await super.create(params)) as XyoStorageArchivist
|
|
93
79
|
}
|
|
94
80
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return account
|
|
103
|
-
} catch (ex) {
|
|
104
|
-
console.error(`Error reading Account from storage [${this.type}, ${ex}] - Recreating Account`)
|
|
105
|
-
this.privateStorage.remove('privateKey')
|
|
106
|
-
}
|
|
107
|
-
}
|
|
81
|
+
public override all(): PromisableArray<XyoPayload> {
|
|
82
|
+
this.logger?.log(`this.storage.length: ${this.storage.length}`)
|
|
83
|
+
try {
|
|
84
|
+
return Object.entries(this.storage.getAll()).map(([, value]) => value)
|
|
85
|
+
} catch (ex) {
|
|
86
|
+
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
87
|
+
throw ex
|
|
108
88
|
}
|
|
109
|
-
return super.loadAccount()
|
|
110
89
|
}
|
|
111
90
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.
|
|
91
|
+
public override clear(): void | Promise<void> {
|
|
92
|
+
this.logger?.log(`this.storage.length: ${this.storage.length}`)
|
|
93
|
+
try {
|
|
94
|
+
this.storage.clear()
|
|
95
|
+
} catch (ex) {
|
|
96
|
+
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
97
|
+
throw ex
|
|
116
98
|
}
|
|
117
99
|
}
|
|
118
100
|
|
|
119
|
-
public override
|
|
120
|
-
this.logger?.log(`
|
|
101
|
+
public override async commit(): Promise<XyoBoundWitness[]> {
|
|
102
|
+
this.logger?.log(`this.storage.length: ${this.storage.length}`)
|
|
121
103
|
try {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
104
|
+
const payloads = await this.all()
|
|
105
|
+
assertEx(payloads.length > 0, 'Nothing to commit')
|
|
106
|
+
const settled = await Promise.allSettled(
|
|
107
|
+
compact(
|
|
108
|
+
Object.values(this.parents?.commit ?? [])?.map(async (parent) => {
|
|
109
|
+
const queryPayload = PayloadWrapper.parse<XyoArchivistInsertQuery>({
|
|
110
|
+
payloads: payloads.map((payload) => PayloadWrapper.hash(payload)),
|
|
111
|
+
schema: XyoArchivistInsertQuerySchema,
|
|
112
|
+
})
|
|
113
|
+
const query = await this.bindQuery(queryPayload)
|
|
114
|
+
return (await parent?.query(query[0], query[1]))?.[0]
|
|
115
|
+
}),
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
await this.clear()
|
|
119
|
+
return compact(
|
|
120
|
+
settled.map((result) => {
|
|
121
|
+
return result.status === 'fulfilled' ? result.value : null
|
|
122
|
+
}),
|
|
123
|
+
)
|
|
126
124
|
} catch (ex) {
|
|
127
125
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
128
126
|
throw ex
|
|
129
127
|
}
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
public override
|
|
133
|
-
this.logger?.log(`
|
|
130
|
+
public override delete(hashes: string[]): PromisableArray<boolean> {
|
|
131
|
+
this.logger?.log(`hashes.length: ${hashes.length}`)
|
|
134
132
|
try {
|
|
135
|
-
|
|
133
|
+
return hashes.map((hash) => {
|
|
134
|
+
this.storage.remove(hash)
|
|
135
|
+
return true
|
|
136
|
+
})
|
|
136
137
|
} catch (ex) {
|
|
137
138
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
138
139
|
throw ex
|
|
@@ -178,43 +179,44 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
public override
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
182
|
+
public override queries() {
|
|
183
|
+
return [
|
|
184
|
+
XyoArchivistAllQuerySchema,
|
|
185
|
+
XyoArchivistDeleteQuerySchema,
|
|
186
|
+
XyoArchivistClearQuerySchema,
|
|
187
|
+
XyoArchivistFindQuerySchema,
|
|
188
|
+
XyoArchivistCommitQuerySchema,
|
|
189
|
+
...super.queries(),
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
override async start() {
|
|
194
|
+
await super.start()
|
|
195
|
+
this.saveAccount()
|
|
196
|
+
return this
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
protected override loadAccount() {
|
|
200
|
+
if (this.persistAccount) {
|
|
201
|
+
const privateKey = this.privateStorage.get('privateKey')
|
|
202
|
+
if (privateKey) {
|
|
203
|
+
try {
|
|
204
|
+
const account = new XyoAccount({ privateKey })
|
|
205
|
+
this.logger?.log(account.addressValue.hex)
|
|
206
|
+
return account
|
|
207
|
+
} catch (ex) {
|
|
208
|
+
console.error(`Error reading Account from storage [${this.type}, ${ex}] - Recreating Account`)
|
|
209
|
+
this.privateStorage.remove('privateKey')
|
|
210
|
+
}
|
|
211
|
+
}
|
|
188
212
|
}
|
|
213
|
+
return super.loadAccount()
|
|
189
214
|
}
|
|
190
215
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
assertEx(payloads.length > 0, 'Nothing to commit')
|
|
196
|
-
const settled = await Promise.allSettled(
|
|
197
|
-
compact(
|
|
198
|
-
Object.values(this.parents?.commit ?? [])?.map(async (parent) => {
|
|
199
|
-
const queryPayload = PayloadWrapper.parse<XyoArchivistInsertQuery>({
|
|
200
|
-
payloads: payloads.map((payload) => PayloadWrapper.hash(payload)),
|
|
201
|
-
schema: XyoArchivistInsertQuerySchema,
|
|
202
|
-
})
|
|
203
|
-
const query = await this.bindQuery(queryPayload)
|
|
204
|
-
return (await parent?.query(query[0], query[1]))?.[0]
|
|
205
|
-
}),
|
|
206
|
-
),
|
|
207
|
-
)
|
|
208
|
-
await this.clear()
|
|
209
|
-
return compact(
|
|
210
|
-
settled.map((result) => {
|
|
211
|
-
return result.status === 'fulfilled' ? result.value : null
|
|
212
|
-
}),
|
|
213
|
-
)
|
|
214
|
-
} catch (ex) {
|
|
215
|
-
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
216
|
-
throw ex
|
|
216
|
+
protected saveAccount() {
|
|
217
|
+
if (this.persistAccount) {
|
|
218
|
+
this.logger?.log(this.account.addressValue.hex)
|
|
219
|
+
this.privateStorage.set('privateKey', this.account.private.hex)
|
|
217
220
|
}
|
|
218
221
|
}
|
|
219
|
-
static override configSchema = XyoStorageArchivistConfigSchema
|
|
220
222
|
}
|