@xyo-network/archivist 2.36.7 → 2.36.9
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/XyoArchivist.d.ts +2 -2
- package/dist/cjs/XyoArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoArchivist.js +3 -10
- package/dist/cjs/XyoArchivist.js.map +1 -1
- package/dist/cjs/XyoCookieArchivist.d.ts +3 -1
- package/dist/cjs/XyoCookieArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoCookieArchivist.js +9 -14
- package/dist/cjs/XyoCookieArchivist.js.map +1 -1
- package/dist/cjs/XyoMemoryArchivist.d.ts +3 -1
- package/dist/cjs/XyoMemoryArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoMemoryArchivist.js +9 -14
- package/dist/cjs/XyoMemoryArchivist.js.map +1 -1
- package/dist/cjs/XyoStorageArchivist.d.ts +2 -1
- package/dist/cjs/XyoStorageArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoStorageArchivist.js +9 -14
- package/dist/cjs/XyoStorageArchivist.js.map +1 -1
- package/dist/docs.json +1759 -1669
- package/dist/esm/XyoArchivist.d.ts +2 -2
- package/dist/esm/XyoArchivist.d.ts.map +1 -1
- package/dist/esm/XyoArchivist.js +3 -9
- package/dist/esm/XyoArchivist.js.map +1 -1
- package/dist/esm/XyoCookieArchivist.d.ts +3 -1
- package/dist/esm/XyoCookieArchivist.d.ts.map +1 -1
- package/dist/esm/XyoCookieArchivist.js +9 -14
- package/dist/esm/XyoCookieArchivist.js.map +1 -1
- package/dist/esm/XyoMemoryArchivist.d.ts +3 -1
- package/dist/esm/XyoMemoryArchivist.d.ts.map +1 -1
- package/dist/esm/XyoMemoryArchivist.js +9 -14
- package/dist/esm/XyoMemoryArchivist.js.map +1 -1
- package/dist/esm/XyoStorageArchivist.d.ts +2 -1
- package/dist/esm/XyoStorageArchivist.d.ts.map +1 -1
- package/dist/esm/XyoStorageArchivist.js +9 -14
- package/dist/esm/XyoStorageArchivist.js.map +1 -1
- package/package.json +6 -6
- package/src/XyoArchivist.ts +3 -10
- package/src/XyoCookieArchivist.ts +11 -15
- package/src/XyoMemoryArchivist.ts +11 -15
- package/src/XyoStorageArchivist.spec.ts +24 -0
- package/src/XyoStorageArchivist.ts +10 -15
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { XyoAccount } from '@xyo-network/account'
|
|
2
3
|
import { XyoBoundWitness } from '@xyo-network/boundwitness'
|
|
4
|
+
import { XyoModuleResolverFunc } from '@xyo-network/module'
|
|
3
5
|
import { PayloadWrapper, XyoPayload } from '@xyo-network/payload'
|
|
4
6
|
import { PromisableArray } from '@xyo-network/promise'
|
|
5
7
|
import Cookies from 'js-cookie'
|
|
@@ -30,12 +32,6 @@ export type XyoCookieArchivistConfig = XyoArchivistConfig<{
|
|
|
30
32
|
namespace?: string
|
|
31
33
|
}>
|
|
32
34
|
|
|
33
|
-
class CookieArchivistError extends Error {
|
|
34
|
-
constructor(action: string, error: Error['cause'], message?: string) {
|
|
35
|
-
super(`Cookie Archivist [${action}] failed${message ? ` (${message})` : ''}`, { cause: error })
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
35
|
export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
40
36
|
public get domain() {
|
|
41
37
|
return this.config?.domain
|
|
@@ -66,8 +62,8 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
|
66
62
|
]
|
|
67
63
|
}
|
|
68
64
|
|
|
69
|
-
constructor(config?: PartialArchivistConfig<XyoCookieArchivistConfig
|
|
70
|
-
super({ ...config, schema: XyoCookieArchivistConfigSchema })
|
|
65
|
+
constructor(config?: PartialArchivistConfig<XyoCookieArchivistConfig>, account?: XyoAccount, resolver?: XyoModuleResolverFunc) {
|
|
66
|
+
super({ ...config, schema: XyoCookieArchivistConfigSchema }, account, resolver)
|
|
71
67
|
}
|
|
72
68
|
|
|
73
69
|
private keyFromHash(hash: string) {
|
|
@@ -82,7 +78,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
|
82
78
|
})
|
|
83
79
|
} catch (ex) {
|
|
84
80
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
85
|
-
throw
|
|
81
|
+
throw ex
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
|
|
@@ -95,7 +91,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
|
95
91
|
})
|
|
96
92
|
} catch (ex) {
|
|
97
93
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
98
|
-
throw
|
|
94
|
+
throw ex
|
|
99
95
|
}
|
|
100
96
|
}
|
|
101
97
|
|
|
@@ -109,7 +105,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
|
109
105
|
)
|
|
110
106
|
} catch (ex) {
|
|
111
107
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
112
|
-
throw
|
|
108
|
+
throw ex
|
|
113
109
|
}
|
|
114
110
|
}
|
|
115
111
|
|
|
@@ -132,7 +128,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
|
132
128
|
return [result[0], ...parentBoundWitnesses]
|
|
133
129
|
} catch (ex) {
|
|
134
130
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
135
|
-
throw
|
|
131
|
+
throw ex
|
|
136
132
|
}
|
|
137
133
|
}
|
|
138
134
|
|
|
@@ -147,7 +143,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
|
147
143
|
return x
|
|
148
144
|
} catch (ex) {
|
|
149
145
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
150
|
-
throw
|
|
146
|
+
throw ex
|
|
151
147
|
}
|
|
152
148
|
}
|
|
153
149
|
|
|
@@ -158,7 +154,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
|
158
154
|
.map(([, value]) => JSON.parse(value))
|
|
159
155
|
} catch (ex) {
|
|
160
156
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
161
|
-
throw
|
|
157
|
+
throw ex
|
|
162
158
|
}
|
|
163
159
|
}
|
|
164
160
|
|
|
@@ -186,7 +182,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
|
186
182
|
)
|
|
187
183
|
} catch (ex) {
|
|
188
184
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
189
|
-
throw
|
|
185
|
+
throw ex
|
|
190
186
|
}
|
|
191
187
|
}
|
|
192
188
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { XyoAccount } from '@xyo-network/account'
|
|
2
3
|
import { XyoBoundWitness } from '@xyo-network/boundwitness'
|
|
4
|
+
import { XyoModuleResolverFunc } from '@xyo-network/module'
|
|
3
5
|
import { PayloadWrapper, XyoPayload } from '@xyo-network/payload'
|
|
4
6
|
import { PromisableArray } from '@xyo-network/promise'
|
|
5
7
|
import compact from 'lodash/compact'
|
|
@@ -27,12 +29,6 @@ export type XyoMemoryArchivistConfig = XyoArchivistConfig<{
|
|
|
27
29
|
max?: number
|
|
28
30
|
}>
|
|
29
31
|
|
|
30
|
-
class MemoryArchivistError extends Error {
|
|
31
|
-
constructor(action: string, error: Error['cause'], message?: string) {
|
|
32
|
-
super(`Memory Archivist [${action}] failed${message ? ` (${message})` : ''}`, { cause: error })
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
32
|
export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
37
33
|
static create(config?: XyoMemoryArchivistConfig) {
|
|
38
34
|
return new XyoMemoryArchivist(config)
|
|
@@ -55,8 +51,8 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
|
55
51
|
]
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
constructor(config?: PartialArchivistConfig<XyoMemoryArchivistConfig
|
|
59
|
-
super({ ...config, schema: XyoMemoryArchivistConfigSchema })
|
|
54
|
+
constructor(config?: PartialArchivistConfig<XyoMemoryArchivistConfig>, account?: XyoAccount, resolver?: XyoModuleResolverFunc) {
|
|
55
|
+
super({ ...config, schema: XyoMemoryArchivistConfigSchema }, account, resolver)
|
|
60
56
|
this.cache = new LruCache<string, XyoPayload>({ max: this.max })
|
|
61
57
|
}
|
|
62
58
|
|
|
@@ -67,7 +63,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
|
67
63
|
})
|
|
68
64
|
} catch (ex) {
|
|
69
65
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
70
|
-
throw
|
|
66
|
+
throw ex
|
|
71
67
|
}
|
|
72
68
|
}
|
|
73
69
|
|
|
@@ -76,7 +72,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
|
76
72
|
this.cache.clear()
|
|
77
73
|
} catch (ex) {
|
|
78
74
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
79
|
-
throw
|
|
75
|
+
throw ex
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
78
|
|
|
@@ -93,7 +89,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
|
93
89
|
)
|
|
94
90
|
} catch (ex) {
|
|
95
91
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
96
|
-
throw
|
|
92
|
+
throw ex
|
|
97
93
|
}
|
|
98
94
|
}
|
|
99
95
|
|
|
@@ -115,7 +111,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
|
115
111
|
return [result[0], ...parentBoundWitnesses]
|
|
116
112
|
} catch (ex) {
|
|
117
113
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
118
|
-
throw
|
|
114
|
+
throw ex
|
|
119
115
|
}
|
|
120
116
|
}
|
|
121
117
|
|
|
@@ -130,7 +126,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
|
130
126
|
return result
|
|
131
127
|
} catch (ex) {
|
|
132
128
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
133
|
-
throw
|
|
129
|
+
throw ex
|
|
134
130
|
}
|
|
135
131
|
}
|
|
136
132
|
|
|
@@ -139,7 +135,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
|
139
135
|
return this.cache.dump().map((value) => value[1].value)
|
|
140
136
|
} catch (ex) {
|
|
141
137
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
142
|
-
throw
|
|
138
|
+
throw ex
|
|
143
139
|
}
|
|
144
140
|
}
|
|
145
141
|
|
|
@@ -166,7 +162,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
|
166
162
|
)
|
|
167
163
|
} catch (ex) {
|
|
168
164
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
169
|
-
throw
|
|
165
|
+
throw ex
|
|
170
166
|
}
|
|
171
167
|
}
|
|
172
168
|
}
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { PayloadWrapper } from '@xyo-network/payload'
|
|
6
|
+
|
|
5
7
|
import { testArchivistAll, testArchivistRoundTrip } from './test.spec.test'
|
|
8
|
+
import { XyoMemoryArchivist } from './XyoMemoryArchivist'
|
|
6
9
|
import { XyoStorageArchivist } from './XyoStorageArchivist'
|
|
7
10
|
|
|
8
11
|
testArchivistRoundTrip(new XyoStorageArchivist({ namespace: 'test', type: 'local' }), 'local')
|
|
@@ -19,3 +22,24 @@ test('XyoArchivist Private Key Save', () => {
|
|
|
19
22
|
const storage2 = new XyoStorageArchivist({ namespace: 'test', persistAccount: true, type: 'local' })
|
|
20
23
|
expect(storage2.address).toBe(address)
|
|
21
24
|
})
|
|
25
|
+
|
|
26
|
+
test('XyoArchivist Parent Write Through', async () => {
|
|
27
|
+
const memory = new XyoMemoryArchivist()
|
|
28
|
+
|
|
29
|
+
const resolver = (address: string) => {
|
|
30
|
+
return address === memory.address ? memory : null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const storage = new XyoStorageArchivist(
|
|
34
|
+
{ namespace: 'test', parents: { write: [memory.address] }, persistAccount: true, type: 'local' },
|
|
35
|
+
undefined,
|
|
36
|
+
resolver,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
const wrapper = new PayloadWrapper({ schema: 'network.xyo.test' })
|
|
40
|
+
|
|
41
|
+
await storage.insert([wrapper.payload])
|
|
42
|
+
|
|
43
|
+
expect((await storage.get([wrapper.hash])).length).toBe(1)
|
|
44
|
+
expect((await memory.get([wrapper.hash])).length).toBe(1)
|
|
45
|
+
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { XyoAccount } from '@xyo-network/account'
|
|
3
3
|
import { XyoBoundWitness } from '@xyo-network/boundwitness'
|
|
4
|
+
import { XyoModuleResolverFunc } from '@xyo-network/module'
|
|
4
5
|
import { PayloadWrapper, XyoPayload } from '@xyo-network/payload'
|
|
5
6
|
import { PromisableArray } from '@xyo-network/promise'
|
|
6
7
|
import compact from 'lodash/compact'
|
|
@@ -32,12 +33,6 @@ export type XyoStorageArchivistConfig = XyoArchivistConfig<{
|
|
|
32
33
|
persistAccount?: boolean
|
|
33
34
|
}>
|
|
34
35
|
|
|
35
|
-
class StorageArchivistError extends Error {
|
|
36
|
-
constructor(action: string, error: Error['cause'], message?: string) {
|
|
37
|
-
super(`Storage Archivist [${action}] failed${message ? ` (${message})` : ''}`, { cause: error })
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
36
|
export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig> {
|
|
42
37
|
public get type() {
|
|
43
38
|
return this.config?.type ?? 'local'
|
|
@@ -84,8 +79,8 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
84
79
|
return this._privateStorage
|
|
85
80
|
}
|
|
86
81
|
|
|
87
|
-
constructor(config?: PartialArchivistConfig<XyoStorageArchivistConfig
|
|
88
|
-
super({ ...config, schema: XyoStorageArchivistConfigSchema })
|
|
82
|
+
constructor(config?: PartialArchivistConfig<XyoStorageArchivistConfig>, account?: XyoAccount, resolver?: XyoModuleResolverFunc) {
|
|
83
|
+
super({ ...config, schema: XyoStorageArchivistConfigSchema }, account, resolver)
|
|
89
84
|
this.saveAccount()
|
|
90
85
|
}
|
|
91
86
|
|
|
@@ -121,7 +116,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
121
116
|
})
|
|
122
117
|
} catch (ex) {
|
|
123
118
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
124
|
-
throw
|
|
119
|
+
throw ex
|
|
125
120
|
}
|
|
126
121
|
}
|
|
127
122
|
|
|
@@ -130,7 +125,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
130
125
|
this.storage.clear()
|
|
131
126
|
} catch (ex) {
|
|
132
127
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
133
|
-
throw
|
|
128
|
+
throw ex
|
|
134
129
|
}
|
|
135
130
|
}
|
|
136
131
|
|
|
@@ -144,7 +139,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
144
139
|
)
|
|
145
140
|
} catch (ex) {
|
|
146
141
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
147
|
-
throw
|
|
142
|
+
throw ex
|
|
148
143
|
}
|
|
149
144
|
}
|
|
150
145
|
|
|
@@ -167,7 +162,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
167
162
|
return [result[0], ...parentBoundWitnesses]
|
|
168
163
|
} catch (ex) {
|
|
169
164
|
console.error(`Error: ${ex}`)
|
|
170
|
-
throw
|
|
165
|
+
throw ex
|
|
171
166
|
}
|
|
172
167
|
}
|
|
173
168
|
|
|
@@ -182,7 +177,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
182
177
|
return x
|
|
183
178
|
} catch (ex) {
|
|
184
179
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
185
|
-
throw
|
|
180
|
+
throw ex
|
|
186
181
|
}
|
|
187
182
|
}
|
|
188
183
|
|
|
@@ -191,7 +186,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
191
186
|
return Object.entries(this.storage.getAll()).map(([, value]) => value)
|
|
192
187
|
} catch (ex) {
|
|
193
188
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
194
|
-
throw
|
|
189
|
+
throw ex
|
|
195
190
|
}
|
|
196
191
|
}
|
|
197
192
|
|
|
@@ -219,7 +214,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
219
214
|
)
|
|
220
215
|
} catch (ex) {
|
|
221
216
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
222
|
-
throw
|
|
217
|
+
throw ex
|
|
223
218
|
}
|
|
224
219
|
}
|
|
225
220
|
}
|