@xyo-network/archivist 2.34.0 → 2.35.0
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 -1
- package/dist/cjs/Archivist.d.ts.map +1 -1
- package/dist/cjs/Queries/Insert.d.ts +1 -2
- package/dist/cjs/Queries/Insert.d.ts.map +1 -1
- package/dist/cjs/Queries/Insert.js.map +1 -1
- package/dist/cjs/XyoArchivist.d.ts +2 -2
- package/dist/cjs/XyoArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoArchivist.js +22 -12
- package/dist/cjs/XyoArchivist.js.map +1 -1
- package/dist/cjs/XyoArchivistWrapper.d.ts +1 -1
- package/dist/cjs/XyoArchivistWrapper.d.ts.map +1 -1
- package/dist/cjs/XyoArchivistWrapper.js +10 -4
- package/dist/cjs/XyoArchivistWrapper.js.map +1 -1
- package/dist/cjs/XyoCookieArchivist.d.ts +1 -1
- package/dist/cjs/XyoCookieArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoCookieArchivist.js +9 -4
- package/dist/cjs/XyoCookieArchivist.js.map +1 -1
- package/dist/cjs/XyoMemoryArchivist.d.ts +1 -1
- package/dist/cjs/XyoMemoryArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoMemoryArchivist.js +9 -4
- package/dist/cjs/XyoMemoryArchivist.js.map +1 -1
- package/dist/cjs/XyoStorageArchivist.d.ts +1 -1
- package/dist/cjs/XyoStorageArchivist.d.ts.map +1 -1
- package/dist/cjs/XyoStorageArchivist.js +9 -4
- package/dist/cjs/XyoStorageArchivist.js.map +1 -1
- package/dist/docs.json +2867 -2566
- package/dist/esm/Archivist.d.ts +1 -1
- package/dist/esm/Archivist.d.ts.map +1 -1
- package/dist/esm/Queries/Insert.d.ts +1 -2
- package/dist/esm/Queries/Insert.d.ts.map +1 -1
- package/dist/esm/Queries/Insert.js.map +1 -1
- package/dist/esm/XyoArchivist.d.ts +2 -2
- package/dist/esm/XyoArchivist.d.ts.map +1 -1
- package/dist/esm/XyoArchivist.js +21 -12
- package/dist/esm/XyoArchivist.js.map +1 -1
- package/dist/esm/XyoArchivistWrapper.d.ts +1 -1
- package/dist/esm/XyoArchivistWrapper.d.ts.map +1 -1
- package/dist/esm/XyoArchivistWrapper.js +10 -4
- package/dist/esm/XyoArchivistWrapper.js.map +1 -1
- package/dist/esm/XyoCookieArchivist.d.ts +1 -1
- package/dist/esm/XyoCookieArchivist.d.ts.map +1 -1
- package/dist/esm/XyoCookieArchivist.js +8 -4
- package/dist/esm/XyoCookieArchivist.js.map +1 -1
- package/dist/esm/XyoMemoryArchivist.d.ts +1 -1
- package/dist/esm/XyoMemoryArchivist.d.ts.map +1 -1
- package/dist/esm/XyoMemoryArchivist.js +8 -4
- package/dist/esm/XyoMemoryArchivist.js.map +1 -1
- package/dist/esm/XyoStorageArchivist.d.ts +1 -1
- package/dist/esm/XyoStorageArchivist.d.ts.map +1 -1
- package/dist/esm/XyoStorageArchivist.js +8 -4
- package/dist/esm/XyoStorageArchivist.js.map +1 -1
- package/package.json +6 -6
- package/src/Archivist.ts +1 -1
- package/src/Queries/Insert.ts +1 -2
- package/src/XyoArchivist.ts +28 -13
- package/src/XyoArchivistWrapper.ts +14 -6
- package/src/XyoCookieArchivist.ts +11 -5
- package/src/XyoMemoryArchivist.ts +11 -5
- package/src/XyoStorageArchivist.ts +11 -5
- package/src/test.spec.test/testArchivist.ts +6 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { XyoBoundWitness } from '@xyo-network/boundwitness'
|
|
2
2
|
import { XyoModuleWrapper } from '@xyo-network/module'
|
|
3
|
-
import { XyoPayload } from '@xyo-network/payload'
|
|
3
|
+
import { PayloadWrapper, XyoPayload } from '@xyo-network/payload'
|
|
4
4
|
|
|
5
5
|
import { PayloadArchivist } from './Archivist'
|
|
6
6
|
import {
|
|
@@ -41,9 +41,17 @@ export class XyoArchivistWrapper extends XyoModuleWrapper implements PayloadArch
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
public async insert(payloads: XyoPayload[]): Promise<XyoBoundWitness> {
|
|
44
|
-
const query: XyoArchivistInsertQuery = {
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
const query: XyoArchivistInsertQuery = {
|
|
45
|
+
payloads: payloads.map((payload) => PayloadWrapper.hash(payload)),
|
|
46
|
+
schema: XyoArchivistInsertQuerySchema,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const bw = (await this.bindPayloads([query, ...payloads]))[0]
|
|
50
|
+
const result = await this.module.query(bw, query, payloads)
|
|
51
|
+
|
|
52
|
+
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
53
|
+
|
|
54
|
+
return result[1][0] as XyoBoundWitness
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
public async find(filter?: XyoPayloadFindFilter): Promise<(XyoPayload | null)[]> {
|
|
@@ -58,9 +66,9 @@ export class XyoArchivistWrapper extends XyoModuleWrapper implements PayloadArch
|
|
|
58
66
|
return (await this.module.query(bw, query))[1]
|
|
59
67
|
}
|
|
60
68
|
|
|
61
|
-
public async commit(): Promise<XyoBoundWitness> {
|
|
69
|
+
public async commit(): Promise<XyoBoundWitness[]> {
|
|
62
70
|
const query: XyoArchivistCommitQuery = { schema: XyoArchivistCommitQuerySchema }
|
|
63
71
|
const bw = (await this.bindPayloads([query]))[0]
|
|
64
|
-
return (await this.module.query(bw, query))[
|
|
72
|
+
return (await this.module.query(bw, query))[1] as XyoBoundWitness[]
|
|
65
73
|
}
|
|
66
74
|
}
|
|
@@ -160,22 +160,28 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
public override async commit(): Promise<XyoBoundWitness> {
|
|
163
|
+
public override async commit(): Promise<XyoBoundWitness[]> {
|
|
164
164
|
try {
|
|
165
165
|
const payloads = await this.all()
|
|
166
166
|
assertEx(payloads.length > 0, 'Nothing to commit')
|
|
167
|
-
const
|
|
168
|
-
await Promise.allSettled(
|
|
167
|
+
const settled = await Promise.allSettled(
|
|
169
168
|
compact(
|
|
170
169
|
Object.values(this.parents?.commit ?? [])?.map(async (parent) => {
|
|
171
|
-
const query: XyoArchivistInsertQuery = {
|
|
170
|
+
const query: XyoArchivistInsertQuery = {
|
|
171
|
+
payloads: payloads.map((payload) => PayloadWrapper.hash(payload)),
|
|
172
|
+
schema: XyoArchivistInsertQuerySchema,
|
|
173
|
+
}
|
|
172
174
|
const bw = (await this.bindPayloads([query]))[0]
|
|
173
175
|
return await parent?.query(bw, query)
|
|
174
176
|
}),
|
|
175
177
|
),
|
|
176
178
|
)
|
|
177
179
|
await this.clear()
|
|
178
|
-
return
|
|
180
|
+
return compact(
|
|
181
|
+
settled.map((result) => {
|
|
182
|
+
return result.status === 'fulfilled' ? result.value?.[0] : null
|
|
183
|
+
}),
|
|
184
|
+
)
|
|
179
185
|
} catch (ex) {
|
|
180
186
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
181
187
|
throw new CookieArchivistError('commit', ex, 'unexpected')
|
|
@@ -140,21 +140,27 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
public override async commit(): Promise<XyoBoundWitness> {
|
|
143
|
+
public override async commit(): Promise<XyoBoundWitness[]> {
|
|
144
144
|
try {
|
|
145
145
|
const payloads = assertEx(await this.all(), 'Nothing to commit')
|
|
146
|
-
const
|
|
147
|
-
await Promise.allSettled(
|
|
146
|
+
const settled = await Promise.allSettled(
|
|
148
147
|
compact(
|
|
149
148
|
Object.values(this.parents?.commit ?? [])?.map(async (parent) => {
|
|
150
|
-
const query: XyoArchivistInsertQuery = {
|
|
149
|
+
const query: XyoArchivistInsertQuery = {
|
|
150
|
+
payloads: payloads.map((payload) => PayloadWrapper.hash(payload)),
|
|
151
|
+
schema: XyoArchivistInsertQuerySchema,
|
|
152
|
+
}
|
|
151
153
|
const bw = (await this.bindPayloads([query]))[0]
|
|
152
154
|
return await parent?.query(bw, query)
|
|
153
155
|
}),
|
|
154
156
|
),
|
|
155
157
|
)
|
|
156
158
|
await this.clear()
|
|
157
|
-
return
|
|
159
|
+
return compact(
|
|
160
|
+
settled.map((result) => {
|
|
161
|
+
return result.status === 'fulfilled' ? result.value?.[0] : null
|
|
162
|
+
}),
|
|
163
|
+
)
|
|
158
164
|
} catch (ex) {
|
|
159
165
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
160
166
|
throw new MemoryArchivistError('commit', ex, 'unexpected')
|
|
@@ -151,22 +151,28 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
public override async commit(): Promise<XyoBoundWitness> {
|
|
154
|
+
public override async commit(): Promise<XyoBoundWitness[]> {
|
|
155
155
|
try {
|
|
156
156
|
const payloads = await this.all()
|
|
157
157
|
assertEx(payloads.length > 0, 'Nothing to commit')
|
|
158
|
-
const
|
|
159
|
-
await Promise.allSettled(
|
|
158
|
+
const settled = await Promise.allSettled(
|
|
160
159
|
compact(
|
|
161
160
|
Object.values(this.parents?.commit ?? [])?.map(async (parent) => {
|
|
162
|
-
const query: XyoArchivistInsertQuery = {
|
|
161
|
+
const query: XyoArchivistInsertQuery = {
|
|
162
|
+
payloads: payloads.map((payload) => PayloadWrapper.hash(payload)),
|
|
163
|
+
schema: XyoArchivistInsertQuerySchema,
|
|
164
|
+
}
|
|
163
165
|
const bw = (await this.bindPayloads([query]))[0]
|
|
164
166
|
return await parent?.query(bw, query)
|
|
165
167
|
}),
|
|
166
168
|
),
|
|
167
169
|
)
|
|
168
170
|
await this.clear()
|
|
169
|
-
return
|
|
171
|
+
return compact(
|
|
172
|
+
settled.map((result) => {
|
|
173
|
+
return result.status === 'fulfilled' ? result.value?.[0] : null
|
|
174
|
+
}),
|
|
175
|
+
)
|
|
170
176
|
} catch (ex) {
|
|
171
177
|
console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
|
|
172
178
|
throw new StorageArchivistError('commit', ex, 'unexpected')
|
|
@@ -11,13 +11,15 @@ import { XyoArchivistWrapper } from '../XyoArchivistWrapper'
|
|
|
11
11
|
export const testArchivistRoundTrip = (archivist: XyoArchivist, name: string) => {
|
|
12
12
|
test(`XyoArchivist [${name}]`, async () => {
|
|
13
13
|
const idPayload: XyoPayload<{ salt: string }> = {
|
|
14
|
-
salt:
|
|
14
|
+
salt: Date.now().toString(),
|
|
15
15
|
schema: 'network.xyo.id',
|
|
16
16
|
}
|
|
17
17
|
const payloadWrapper = new PayloadWrapper(idPayload)
|
|
18
|
+
|
|
18
19
|
const archivistWrapper = new XyoArchivistWrapper(archivist)
|
|
19
20
|
const insertResult = await archivistWrapper.insert([idPayload])
|
|
20
21
|
expect(insertResult).toBeDefined()
|
|
22
|
+
|
|
21
23
|
expect(insertResult.payload_hashes.find((hash) => hash === payloadWrapper.hash)).toBeDefined()
|
|
22
24
|
const getResult = await archivistWrapper.get([payloadWrapper.hash])
|
|
23
25
|
expect(getResult).toBeDefined()
|
|
@@ -33,16 +35,16 @@ export const testArchivistRoundTrip = (archivist: XyoArchivist, name: string) =>
|
|
|
33
35
|
export const testArchivistAll = (archivist: XyoArchivist, name: string) => {
|
|
34
36
|
test(`XyoArchivist [${name}]`, async () => {
|
|
35
37
|
const idPayload = {
|
|
36
|
-
salt:
|
|
38
|
+
salt: Date.now().toString(),
|
|
37
39
|
schema: 'network.xyo.id',
|
|
38
40
|
}
|
|
39
41
|
const archivistWrapper = new XyoArchivistWrapper(archivist)
|
|
40
42
|
for (let x = 0; x < 10; x++) {
|
|
41
|
-
await archivistWrapper.insert([
|
|
43
|
+
await archivistWrapper.insert([idPayload])
|
|
42
44
|
await delay(10)
|
|
43
45
|
}
|
|
44
46
|
const getResult = await archivistWrapper.all()
|
|
45
47
|
expect(getResult).toBeDefined()
|
|
46
|
-
expect(getResult.length).toBe(
|
|
48
|
+
expect(getResult.length).toBe(2)
|
|
47
49
|
})
|
|
48
50
|
}
|