@xyo-network/archivist 2.37.6 → 2.38.0-rc.2
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 +1 -2
- package/dist/cjs/Archivist.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/Find.js.map +1 -1
- package/dist/cjs/XyoArchivist.d.ts +5 -5
- package/dist/cjs/XyoArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoArchivist.js +5 -11
- package/dist/cjs/XyoArchivist.js.map +1 -1
- package/dist/cjs/XyoArchivistWrapper.d.ts +1 -2
- package/dist/cjs/XyoArchivistWrapper.d.ts.map +1 -1
- package/dist/cjs/XyoArchivistWrapper.js.map +1 -1
- package/dist/cjs/XyoCookieArchivist.d.ts +0 -4
- package/dist/cjs/XyoCookieArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoCookieArchivist.js +0 -3
- package/dist/cjs/XyoCookieArchivist.js.map +1 -1
- package/dist/cjs/XyoMemoryArchivist.d.ts +6 -7
- package/dist/cjs/XyoMemoryArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoMemoryArchivist.js +9 -5
- package/dist/cjs/XyoMemoryArchivist.js.map +1 -1
- package/dist/cjs/XyoStorageArchivist.d.ts +3 -4
- package/dist/cjs/XyoStorageArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoStorageArchivist.js +16 -6
- package/dist/cjs/XyoStorageArchivist.js.map +1 -1
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/docs.json +11520 -9358
- package/dist/esm/Archivist.d.ts +1 -2
- package/dist/esm/Archivist.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/Find.js.map +1 -1
- package/dist/esm/XyoArchivist.d.ts +5 -5
- package/dist/esm/XyoArchivist.d.ts.map +1 -1
- package/dist/esm/XyoArchivist.js +6 -12
- package/dist/esm/XyoArchivist.js.map +1 -1
- package/dist/esm/XyoArchivistWrapper.d.ts +1 -2
- package/dist/esm/XyoArchivistWrapper.d.ts.map +1 -1
- package/dist/esm/XyoArchivistWrapper.js.map +1 -1
- package/dist/esm/XyoCookieArchivist.d.ts +0 -4
- package/dist/esm/XyoCookieArchivist.d.ts.map +1 -1
- package/dist/esm/XyoCookieArchivist.js +0 -3
- package/dist/esm/XyoCookieArchivist.js.map +1 -1
- package/dist/esm/XyoMemoryArchivist.d.ts +6 -7
- package/dist/esm/XyoMemoryArchivist.d.ts.map +1 -1
- package/dist/esm/XyoMemoryArchivist.js +7 -5
- package/dist/esm/XyoMemoryArchivist.js.map +1 -1
- package/dist/esm/XyoStorageArchivist.d.ts +3 -4
- package/dist/esm/XyoStorageArchivist.d.ts.map +1 -1
- package/dist/esm/XyoStorageArchivist.js +10 -5
- package/dist/esm/XyoStorageArchivist.js.map +1 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +7 -6
- package/src/Archivist.ts +1 -3
- package/src/Queries/Find.ts +1 -2
- package/src/XyoArchivist.ts +10 -25
- package/src/XyoArchivistWrapper.ts +1 -2
- package/src/XyoCookieArchivist.spec.ts +3 -3
- package/src/XyoCookieArchivist.ts +0 -7
- package/src/XyoMemoryArchivist.ts +12 -10
- package/src/XyoStorageArchivist.spec.ts +40 -22
- package/src/XyoStorageArchivist.ts +12 -8
- package/src/index.ts +0 -1
- package/src/test.spec.test/testArchivist.ts +5 -4
- package/dist/cjs/XyoPayloadFindFilter.d.ts +0 -16
- package/dist/cjs/XyoPayloadFindFilter.d.ts.map +0 -1
- package/dist/cjs/XyoPayloadFindFilter.js +0 -3
- package/dist/cjs/XyoPayloadFindFilter.js.map +0 -1
- package/dist/esm/XyoPayloadFindFilter.d.ts +0 -16
- package/dist/esm/XyoPayloadFindFilter.d.ts.map +0 -1
- package/dist/esm/XyoPayloadFindFilter.js +0 -2
- package/dist/esm/XyoPayloadFindFilter.js.map +0 -1
- package/src/XyoPayloadFindFilter.ts +0 -19
package/src/XyoArchivist.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
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 {
|
|
5
|
-
|
|
6
|
-
QueryBoundWitnessWrapper,
|
|
7
|
-
XyoModule,
|
|
8
|
-
XyoModuleInitializeQuerySchema,
|
|
9
|
-
XyoModuleShutdownQuerySchema,
|
|
10
|
-
XyoQueryBoundWitness,
|
|
11
|
-
} from '@xyo-network/module'
|
|
12
|
-
import { PayloadWrapper, XyoPayload } from '@xyo-network/payload'
|
|
4
|
+
import { ModuleQueryResult, QueryBoundWitnessWrapper, XyoModule, XyoModuleParams, XyoQueryBoundWitness } from '@xyo-network/module'
|
|
5
|
+
import { PayloadWrapper, XyoPayload, XyoPayloadFindFilter } from '@xyo-network/payload'
|
|
13
6
|
import { NullablePromisableArray, Promisable, PromisableArray } from '@xyo-network/promise'
|
|
14
7
|
import compact from 'lodash/compact'
|
|
15
8
|
|
|
@@ -27,7 +20,6 @@ import {
|
|
|
27
20
|
XyoArchivistQuery,
|
|
28
21
|
} from './Queries'
|
|
29
22
|
import { XyoArchivistWrapper } from './XyoArchivistWrapper'
|
|
30
|
-
import { XyoPayloadFindFilter } from './XyoPayloadFindFilter'
|
|
31
23
|
|
|
32
24
|
export interface XyoArchivistParentWrappers {
|
|
33
25
|
read?: Record<string, XyoArchivistWrapper>
|
|
@@ -35,18 +27,11 @@ export interface XyoArchivistParentWrappers {
|
|
|
35
27
|
commit?: Record<string, XyoArchivistWrapper>
|
|
36
28
|
}
|
|
37
29
|
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
{
|
|
30
|
+
export type XyoArchivistParams<TConfig extends XyoArchivistConfig = XyoArchivistConfig> = XyoModuleParams<TConfig>
|
|
31
|
+
|
|
32
|
+
export abstract class XyoArchivist<TConfig extends XyoArchivistConfig = XyoArchivistConfig> extends XyoModule<TConfig> implements PayloadArchivist {
|
|
42
33
|
public override queries() {
|
|
43
|
-
return [
|
|
44
|
-
XyoModuleInitializeQuerySchema,
|
|
45
|
-
XyoModuleShutdownQuerySchema,
|
|
46
|
-
XyoArchivistGetQuerySchema,
|
|
47
|
-
XyoArchivistInsertQuerySchema,
|
|
48
|
-
...super.queries(),
|
|
49
|
-
]
|
|
34
|
+
return [XyoArchivistGetQuerySchema, XyoArchivistInsertQuerySchema, ...super.queries()]
|
|
50
35
|
}
|
|
51
36
|
|
|
52
37
|
public get cacheParentReads() {
|
|
@@ -127,7 +112,7 @@ export abstract class XyoArchivist<TConfig extends XyoPayload = XyoPayload>
|
|
|
127
112
|
default:
|
|
128
113
|
return super.query(query, payloads)
|
|
129
114
|
}
|
|
130
|
-
this.log?.('
|
|
115
|
+
this.log?.('query', wrapper.schemaName)
|
|
131
116
|
return this.bindResult(resultPayloads, queryAccount)
|
|
132
117
|
}
|
|
133
118
|
|
|
@@ -136,9 +121,9 @@ export abstract class XyoArchivist<TConfig extends XyoPayload = XyoPayload>
|
|
|
136
121
|
if (archivists) {
|
|
137
122
|
archivists.map((archivist) => {
|
|
138
123
|
if (resolvedWrappers[archivist] === undefined) {
|
|
139
|
-
const module = this.resolver?.(archivist)
|
|
124
|
+
const module = this.resolver?.fromAddress([archivist]).shift()
|
|
140
125
|
if (module) {
|
|
141
|
-
resolvedWrappers[archivist] = new XyoArchivistWrapper(module)
|
|
126
|
+
resolvedWrappers[archivist] = new XyoArchivistWrapper({ module })
|
|
142
127
|
}
|
|
143
128
|
}
|
|
144
129
|
})
|
|
@@ -165,7 +150,7 @@ export abstract class XyoArchivist<TConfig extends XyoPayload = XyoPayload>
|
|
|
165
150
|
}
|
|
166
151
|
|
|
167
152
|
protected async writeToParent(parent: PayloadArchivist, payloads: XyoPayload[]) {
|
|
168
|
-
const wrapper = new XyoArchivistWrapper(parent)
|
|
153
|
+
const wrapper = new XyoArchivistWrapper({ module: parent })
|
|
169
154
|
return await wrapper.insert(payloads)
|
|
170
155
|
}
|
|
171
156
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { XyoBoundWitness, XyoBoundWitnessSchema } from '@xyo-network/boundwitness'
|
|
2
2
|
import { XyoModuleWrapper } from '@xyo-network/module'
|
|
3
|
-
import { PayloadWrapper, XyoPayload } from '@xyo-network/payload'
|
|
3
|
+
import { PayloadWrapper, XyoPayload, XyoPayloadFindFilter } from '@xyo-network/payload'
|
|
4
4
|
|
|
5
5
|
import { PayloadArchivist } from './Archivist'
|
|
6
6
|
import {
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
XyoArchivistInsertQuery,
|
|
20
20
|
XyoArchivistInsertQuerySchema,
|
|
21
21
|
} from './Queries'
|
|
22
|
-
import { XyoPayloadFindFilter } from './XyoPayloadFindFilter'
|
|
23
22
|
|
|
24
23
|
export class XyoArchivistWrapper extends XyoModuleWrapper implements PayloadArchivist {
|
|
25
24
|
public async delete(hashes: string[]) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { testArchivistAll, testArchivistRoundTrip } from './test.spec.test'
|
|
6
|
-
import { XyoCookieArchivist } from './XyoCookieArchivist'
|
|
6
|
+
import { XyoCookieArchivist, XyoCookieArchivistConfigSchema } from './XyoCookieArchivist'
|
|
7
7
|
|
|
8
|
-
testArchivistRoundTrip(new XyoCookieArchivist({ namespace: 'test' }), 'cookie')
|
|
9
|
-
testArchivistAll(new XyoCookieArchivist({ namespace: 'test' }), 'cookie')
|
|
8
|
+
testArchivistRoundTrip(new XyoCookieArchivist({ config: { namespace: 'test', schema: XyoCookieArchivistConfigSchema } }).start(), 'cookie')
|
|
9
|
+
testArchivistAll(new XyoCookieArchivist({ config: { namespace: 'test', schema: XyoCookieArchivistConfigSchema } }).start(), 'cookie')
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { XyoAccount } from '@xyo-network/account'
|
|
3
2
|
import { XyoBoundWitness } from '@xyo-network/boundwitness'
|
|
4
|
-
import { XyoModuleResolverFunc } from '@xyo-network/module'
|
|
5
3
|
import { PayloadWrapper, XyoPayload } from '@xyo-network/payload'
|
|
6
4
|
import { PromisableArray } from '@xyo-network/promise'
|
|
7
5
|
import Cookies from 'js-cookie'
|
|
8
6
|
import compact from 'lodash/compact'
|
|
9
7
|
|
|
10
8
|
import { XyoArchivistConfig } from './Config'
|
|
11
|
-
import { PartialArchivistConfig } from './PartialConfig'
|
|
12
9
|
import {
|
|
13
10
|
XyoArchivistAllQuerySchema,
|
|
14
11
|
XyoArchivistClearQuerySchema,
|
|
@@ -61,10 +58,6 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
|
61
58
|
]
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
constructor(config?: PartialArchivistConfig<XyoCookieArchivistConfig>, account?: XyoAccount, resolver?: XyoModuleResolverFunc) {
|
|
65
|
-
super({ ...config, schema: XyoCookieArchivistConfigSchema }, account, resolver)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
61
|
private keyFromHash(hash: string) {
|
|
69
62
|
return `${this.namespace}-${hash}`
|
|
70
63
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { XyoAccount } from '@xyo-network/account'
|
|
3
2
|
import { XyoBoundWitness } from '@xyo-network/boundwitness'
|
|
4
|
-
import {
|
|
3
|
+
import { XyoModuleConfig, XyoModuleParams } from '@xyo-network/module'
|
|
5
4
|
import { PayloadWrapper, XyoPayload } from '@xyo-network/payload'
|
|
6
5
|
import { PromisableArray } from '@xyo-network/promise'
|
|
7
6
|
import compact from 'lodash/compact'
|
|
8
7
|
import LruCache from 'lru-cache'
|
|
9
8
|
|
|
10
9
|
import { XyoArchivistConfig } from './Config'
|
|
11
|
-
import { PartialArchivistConfig } from './PartialConfig'
|
|
12
10
|
import {
|
|
13
11
|
XyoArchivistAllQuerySchema,
|
|
14
12
|
XyoArchivistClearQuerySchema,
|
|
@@ -18,7 +16,7 @@ import {
|
|
|
18
16
|
XyoArchivistInsertQuery,
|
|
19
17
|
XyoArchivistInsertQuerySchema,
|
|
20
18
|
} from './Queries'
|
|
21
|
-
import { XyoArchivist } from './XyoArchivist'
|
|
19
|
+
import { XyoArchivist, XyoArchivistParams } from './XyoArchivist'
|
|
22
20
|
|
|
23
21
|
export type XyoMemoryArchivistConfigSchema = 'network.xyo.module.config.archivist.memory'
|
|
24
22
|
export const XyoMemoryArchivistConfigSchema: XyoMemoryArchivistConfigSchema = 'network.xyo.module.config.archivist.memory'
|
|
@@ -28,15 +26,19 @@ export type XyoMemoryArchivistConfig = XyoArchivistConfig<{
|
|
|
28
26
|
max?: number
|
|
29
27
|
}>
|
|
30
28
|
|
|
31
|
-
export
|
|
32
|
-
static create(config?: XyoMemoryArchivistConfig) {
|
|
33
|
-
return new XyoMemoryArchivist(config)
|
|
34
|
-
}
|
|
29
|
+
export type XyoMemoryArchivistParams<TConfig extends XyoMemoryArchivistConfig = XyoMemoryArchivistConfig> = XyoArchivistParams<TConfig>
|
|
35
30
|
|
|
31
|
+
export class XyoMemoryArchivist<TConfig extends XyoMemoryArchivistConfig = XyoMemoryArchivistConfig> extends XyoArchivist<TConfig> {
|
|
36
32
|
public get max() {
|
|
37
33
|
return this.config?.max ?? 10000
|
|
38
34
|
}
|
|
39
35
|
|
|
36
|
+
static override async create<TParams extends XyoModuleParams<XyoModuleConfig>>(params?: TParams): Promise<XyoMemoryArchivist | null> {
|
|
37
|
+
const archivist: XyoMemoryArchivist = new XyoMemoryArchivist(params as XyoMemoryArchivistParams)
|
|
38
|
+
await archivist.start()
|
|
39
|
+
return archivist
|
|
40
|
+
}
|
|
41
|
+
|
|
40
42
|
private cache: LruCache<string, XyoPayload>
|
|
41
43
|
|
|
42
44
|
public override queries() {
|
|
@@ -50,8 +52,8 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
|
50
52
|
]
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
constructor(
|
|
54
|
-
super(
|
|
55
|
+
constructor(params?: XyoMemoryArchivistParams<TConfig>) {
|
|
56
|
+
super(params)
|
|
55
57
|
this.cache = new LruCache<string, XyoPayload>({ max: this.max })
|
|
56
58
|
}
|
|
57
59
|
|
|
@@ -2,39 +2,57 @@
|
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { XyoModuleResolver } from '@xyo-network/module'
|
|
5
6
|
import { PayloadWrapper } from '@xyo-network/payload'
|
|
6
7
|
|
|
7
8
|
import { testArchivistAll, testArchivistRoundTrip } from './test.spec.test'
|
|
8
9
|
import { XyoMemoryArchivist } from './XyoMemoryArchivist'
|
|
9
|
-
import { XyoStorageArchivist } from './XyoStorageArchivist'
|
|
10
|
-
|
|
11
|
-
testArchivistRoundTrip(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
import { XyoStorageArchivist, XyoStorageArchivistConfigSchema } from './XyoStorageArchivist'
|
|
11
|
+
|
|
12
|
+
testArchivistRoundTrip(
|
|
13
|
+
new XyoStorageArchivist({ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'local' } }).start(),
|
|
14
|
+
'local',
|
|
15
|
+
)
|
|
16
|
+
testArchivistRoundTrip(
|
|
17
|
+
new XyoStorageArchivist({ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'session' } }).start(),
|
|
18
|
+
'session',
|
|
19
|
+
)
|
|
20
|
+
testArchivistRoundTrip(
|
|
21
|
+
new XyoStorageArchivist({ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'page' } }).start(),
|
|
22
|
+
'page',
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
testArchivistAll(new XyoStorageArchivist({ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'local' } }).start(), 'local')
|
|
26
|
+
testArchivistAll(
|
|
27
|
+
new XyoStorageArchivist({ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'session' } }).start(),
|
|
28
|
+
'session',
|
|
29
|
+
)
|
|
30
|
+
testArchivistAll(new XyoStorageArchivist({ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'page' } }).start(), 'page')
|
|
31
|
+
|
|
32
|
+
test('XyoArchivist Private Key Save', async () => {
|
|
33
|
+
const storage = new XyoStorageArchivist({
|
|
34
|
+
config: { namespace: 'test', persistAccount: true, schema: XyoStorageArchivistConfigSchema, type: 'local' },
|
|
35
|
+
logger: console,
|
|
36
|
+
})
|
|
37
|
+
await storage.start()
|
|
21
38
|
const address = storage.address
|
|
22
|
-
const storage2 = new XyoStorageArchivist({
|
|
39
|
+
const storage2 = new XyoStorageArchivist({
|
|
40
|
+
config: { namespace: 'test', persistAccount: true, schema: XyoStorageArchivistConfigSchema, type: 'local' },
|
|
41
|
+
logger: console,
|
|
42
|
+
})
|
|
43
|
+
await storage2.start()
|
|
23
44
|
expect(storage2.address).toBe(address)
|
|
24
45
|
})
|
|
25
46
|
|
|
26
47
|
test('XyoArchivist Parent Write Through', async () => {
|
|
27
48
|
const memory = new XyoMemoryArchivist()
|
|
28
49
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
undefined,
|
|
36
|
-
resolver,
|
|
37
|
-
)
|
|
50
|
+
const storage = new XyoStorageArchivist({
|
|
51
|
+
config: { namespace: 'test', parents: { write: [memory.address] }, persistAccount: true, schema: XyoStorageArchivistConfigSchema, type: 'local' },
|
|
52
|
+
logger: console,
|
|
53
|
+
resolver: new XyoModuleResolver().add(memory),
|
|
54
|
+
})
|
|
55
|
+
await storage.start()
|
|
38
56
|
|
|
39
57
|
const wrapper = new PayloadWrapper({ schema: 'network.xyo.test' })
|
|
40
58
|
|
|
@@ -1,14 +1,12 @@
|
|
|
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'
|
|
5
4
|
import { PayloadWrapper, XyoPayload } from '@xyo-network/payload'
|
|
6
5
|
import { PromisableArray } from '@xyo-network/promise'
|
|
7
6
|
import compact from 'lodash/compact'
|
|
8
7
|
import store, { StoreBase } from 'store2'
|
|
9
8
|
|
|
10
9
|
import { XyoArchivistConfig } from './Config'
|
|
11
|
-
import { PartialArchivistConfig } from './PartialConfig'
|
|
12
10
|
import {
|
|
13
11
|
XyoArchivistAllQuerySchema,
|
|
14
12
|
XyoArchivistClearQuerySchema,
|
|
@@ -18,7 +16,7 @@ import {
|
|
|
18
16
|
XyoArchivistInsertQuery,
|
|
19
17
|
XyoArchivistInsertQuerySchema,
|
|
20
18
|
} from './Queries'
|
|
21
|
-
import { XyoArchivist } from './XyoArchivist'
|
|
19
|
+
import { XyoArchivist, XyoArchivistParams } from './XyoArchivist'
|
|
22
20
|
|
|
23
21
|
export type XyoStorageArchivistConfigSchema = 'network.xyo.module.config.archivist.storage'
|
|
24
22
|
export const XyoStorageArchivistConfigSchema: XyoStorageArchivistConfigSchema = 'network.xyo.module.config.archivist.storage'
|
|
@@ -78,9 +76,15 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
78
76
|
return this._privateStorage
|
|
79
77
|
}
|
|
80
78
|
|
|
81
|
-
constructor(
|
|
82
|
-
super(
|
|
79
|
+
constructor(params?: XyoArchivistParams<XyoStorageArchivistConfig>) {
|
|
80
|
+
super(params)
|
|
81
|
+
this.loadAccount()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
override async start() {
|
|
85
|
+
await super.start()
|
|
83
86
|
this.saveAccount()
|
|
87
|
+
return this
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
protected override loadAccount() {
|
|
@@ -91,8 +95,8 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
91
95
|
const account = new XyoAccount({ privateKey })
|
|
92
96
|
this.log?.('Load Account', account.addressValue.hex)
|
|
93
97
|
return account
|
|
94
|
-
} catch {
|
|
95
|
-
console.error(`Error reading Account from storage [${this.type}] - Recreating Account`)
|
|
98
|
+
} catch (ex) {
|
|
99
|
+
console.error(`Error reading Account from storage [${this.type}, ${ex}] - Recreating Account`)
|
|
96
100
|
this.privateStorage.remove('privateKey')
|
|
97
101
|
}
|
|
98
102
|
}
|
|
@@ -102,7 +106,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
102
106
|
|
|
103
107
|
protected saveAccount() {
|
|
104
108
|
if (this.persistAccount) {
|
|
105
|
-
this.log?.('
|
|
109
|
+
this.log?.('Save Account', this.account.addressValue.hex)
|
|
106
110
|
this.privateStorage.set('privateKey', this.account.private.hex)
|
|
107
111
|
}
|
|
108
112
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
import { delay } from '@xylabs/delay'
|
|
6
6
|
import { BoundWitnessWrapper } from '@xyo-network/boundwitness'
|
|
7
7
|
import { PayloadWrapper, XyoPayload } from '@xyo-network/payload'
|
|
8
|
+
import { Promisable } from '@xyo-network/promise'
|
|
8
9
|
|
|
9
10
|
import { XyoArchivist } from '../XyoArchivist'
|
|
10
11
|
import { XyoArchivistWrapper } from '../XyoArchivistWrapper'
|
|
11
12
|
|
|
12
|
-
export const testArchivistRoundTrip = (archivist: XyoArchivist
|
|
13
|
+
export const testArchivistRoundTrip = (archivist: Promisable<XyoArchivist>, name: string) => {
|
|
13
14
|
test(`XyoArchivist RoundTrip [${name}]`, async () => {
|
|
14
15
|
const idPayload: XyoPayload<{ salt: string }> = {
|
|
15
16
|
salt: Date.now().toString(),
|
|
@@ -17,7 +18,7 @@ export const testArchivistRoundTrip = (archivist: XyoArchivist, name: string) =>
|
|
|
17
18
|
}
|
|
18
19
|
const payloadWrapper = new PayloadWrapper(idPayload)
|
|
19
20
|
|
|
20
|
-
const archivistWrapper = new XyoArchivistWrapper(archivist)
|
|
21
|
+
const archivistWrapper = new XyoArchivistWrapper({ module: await archivist })
|
|
21
22
|
const insertResult = await archivistWrapper.insert([idPayload])
|
|
22
23
|
const insertResultWrappers = insertResult.map((bw) => new BoundWitnessWrapper(bw))
|
|
23
24
|
const insertResultPayload = insertResultWrappers.pop() as BoundWitnessWrapper
|
|
@@ -35,13 +36,13 @@ export const testArchivistRoundTrip = (archivist: XyoArchivist, name: string) =>
|
|
|
35
36
|
})
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export const testArchivistAll = (archivist: XyoArchivist
|
|
39
|
+
export const testArchivistAll = (archivist: Promisable<XyoArchivist>, name: string) => {
|
|
39
40
|
test(`XyoArchivist All [${name}]`, async () => {
|
|
40
41
|
const idPayload = {
|
|
41
42
|
salt: Date.now().toString(),
|
|
42
43
|
schema: 'network.xyo.id',
|
|
43
44
|
}
|
|
44
|
-
const archivistWrapper = new XyoArchivistWrapper(archivist)
|
|
45
|
+
const archivistWrapper = new XyoArchivistWrapper({ module: await archivist })
|
|
45
46
|
for (let x = 0; x < 10; x++) {
|
|
46
47
|
await archivistWrapper.insert([idPayload])
|
|
47
48
|
await delay(10)
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** @deprecated use offset as a string (hash) instead */
|
|
2
|
-
export interface XyoPayloadFindFilterTimeOffset {
|
|
3
|
-
offset?: number;
|
|
4
|
-
}
|
|
5
|
-
export interface XyoPayloadFindFilterHashOffset {
|
|
6
|
-
offset?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare type XyoPayloadFindFilterOffset = XyoPayloadFindFilterTimeOffset | XyoPayloadFindFilterHashOffset;
|
|
9
|
-
export declare type XyoPayloadFindFilter = {
|
|
10
|
-
order?: 'desc' | 'asc';
|
|
11
|
-
/** @deprecated use offset instead */
|
|
12
|
-
timestamp?: number;
|
|
13
|
-
limit?: number;
|
|
14
|
-
schema?: string | string[];
|
|
15
|
-
} & XyoPayloadFindFilterOffset;
|
|
16
|
-
//# sourceMappingURL=XyoPayloadFindFilter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"XyoPayloadFindFilter.d.ts","sourceRoot":"","sources":["../../src/XyoPayloadFindFilter.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,WAAW,8BAA8B;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,8BAA8B;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAGD,oBAAY,0BAA0B,GAAG,8BAA8B,GAAG,8BAA8B,CAAA;AAExG,oBAAY,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACtB,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC3B,GAAG,0BAA0B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"XyoPayloadFindFilter.js","sourceRoot":"","sources":["../../src/XyoPayloadFindFilter.ts"],"names":[],"mappings":""}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** @deprecated use offset as a string (hash) instead */
|
|
2
|
-
export interface XyoPayloadFindFilterTimeOffset {
|
|
3
|
-
offset?: number;
|
|
4
|
-
}
|
|
5
|
-
export interface XyoPayloadFindFilterHashOffset {
|
|
6
|
-
offset?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare type XyoPayloadFindFilterOffset = XyoPayloadFindFilterTimeOffset | XyoPayloadFindFilterHashOffset;
|
|
9
|
-
export declare type XyoPayloadFindFilter = {
|
|
10
|
-
order?: 'desc' | 'asc';
|
|
11
|
-
/** @deprecated use offset instead */
|
|
12
|
-
timestamp?: number;
|
|
13
|
-
limit?: number;
|
|
14
|
-
schema?: string | string[];
|
|
15
|
-
} & XyoPayloadFindFilterOffset;
|
|
16
|
-
//# sourceMappingURL=XyoPayloadFindFilter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"XyoPayloadFindFilter.d.ts","sourceRoot":"","sources":["../../src/XyoPayloadFindFilter.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,WAAW,8BAA8B;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,8BAA8B;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAGD,oBAAY,0BAA0B,GAAG,8BAA8B,GAAG,8BAA8B,CAAA;AAExG,oBAAY,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACtB,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC3B,GAAG,0BAA0B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"XyoPayloadFindFilter.js","sourceRoot":"","sources":["../../src/XyoPayloadFindFilter.ts"],"names":[],"mappings":""}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/** @deprecated use offset as a string (hash) instead */
|
|
2
|
-
export interface XyoPayloadFindFilterTimeOffset {
|
|
3
|
-
offset?: number
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface XyoPayloadFindFilterHashOffset {
|
|
7
|
-
offset?: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
11
|
-
export type XyoPayloadFindFilterOffset = XyoPayloadFindFilterTimeOffset | XyoPayloadFindFilterHashOffset
|
|
12
|
-
|
|
13
|
-
export type XyoPayloadFindFilter = {
|
|
14
|
-
order?: 'desc' | 'asc'
|
|
15
|
-
/** @deprecated use offset instead */
|
|
16
|
-
timestamp?: number
|
|
17
|
-
limit?: number
|
|
18
|
-
schema?: string | string[]
|
|
19
|
-
} & XyoPayloadFindFilterOffset
|