@xyo-network/api 2.33.0-rc.5 → 2.33.0-rc.7
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/RemoteArchivistError.d.ts +6 -0
- package/dist/cjs/Archivist/RemoteArchivistError.d.ts.map +1 -0
- package/dist/cjs/Archivist/RemoteArchivistError.js +14 -0
- package/dist/cjs/Archivist/RemoteArchivistError.js.map +1 -0
- package/dist/cjs/Archivist/XyoRemoteArchivist.d.ts.map +1 -1
- package/dist/cjs/Archivist/XyoRemoteArchivist.js +32 -24
- package/dist/cjs/Archivist/XyoRemoteArchivist.js.map +1 -1
- package/dist/docs.json +879 -879
- package/dist/esm/Archivist/RemoteArchivistError.d.ts +6 -0
- package/dist/esm/Archivist/RemoteArchivistError.d.ts.map +1 -0
- package/dist/esm/Archivist/RemoteArchivistError.js +10 -0
- package/dist/esm/Archivist/RemoteArchivistError.js.map +1 -0
- package/dist/esm/Archivist/XyoRemoteArchivist.d.ts.map +1 -1
- package/dist/esm/Archivist/XyoRemoteArchivist.js +27 -21
- package/dist/esm/Archivist/XyoRemoteArchivist.js.map +1 -1
- package/package.json +7 -7
- package/src/Archivist/RemoteArchivistError.ts +9 -0
- package/src/Archivist/XyoRemoteArchivist.spec.ts +7 -2
- package/src/Archivist/XyoRemoteArchivist.ts +28 -23
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class RemoteArchivistError extends Error {
|
|
2
|
+
constructor(action: string, error: Error['cause'], message?: string);
|
|
3
|
+
isRemoteArchivistError: boolean;
|
|
4
|
+
static isRemoteArchivistError(error: unknown): RemoteArchivistError | undefined;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=RemoteArchivistError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteArchivistError.d.ts","sourceRoot":"","sources":["../../../src/Archivist/RemoteArchivistError.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM;IAGnE,sBAAsB,UAAO;IAC7B,MAAM,CAAC,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS;CAGhF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class RemoteArchivistError extends Error {
|
|
2
|
+
constructor(action, error, message) {
|
|
3
|
+
super(`Remote Archivist [${action}] failed${message ? ` (${message})` : ''}`, { cause: error });
|
|
4
|
+
}
|
|
5
|
+
isRemoteArchivistError = true;
|
|
6
|
+
static isRemoteArchivistError(error) {
|
|
7
|
+
return error.isRemoteArchivistError ? error : undefined;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=RemoteArchivistError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteArchivistError.js","sourceRoot":"","sources":["../../../src/Archivist/RemoteArchivistError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,MAAc,EAAE,KAAqB,EAAE,OAAgB;QACjE,KAAK,CAAC,qBAAqB,MAAM,WAAW,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACjG,CAAC;IACD,sBAAsB,GAAG,IAAI,CAAA;IAC7B,MAAM,CAAC,sBAAsB,CAAC,KAAc;QAC1C,OAAQ,KAA8B,CAAC,sBAAsB,CAAC,CAAC,CAAE,KAA8B,CAAC,CAAC,CAAC,SAAS,CAAA;IAC7G,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XyoRemoteArchivist.d.ts","sourceRoot":"","sources":["../../../src/Archivist/XyoRemoteArchivist.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAA+B,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACxG,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"XyoRemoteArchivist.d.ts","sourceRoot":"","sources":["../../../src/Archivist/XyoRemoteArchivist.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAA+B,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACxG,OAAO,EAAE,eAAe,EAAkF,MAAM,2BAA2B,CAAA;AAC3I,OAAO,EAAE,UAAU,EAAqB,MAAM,sBAAsB,CAAA;AAGpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAErE,uFAAuF;AACvF,qBAAa,kBAAmB,SAAQ,YAAY,CAAC,wBAAwB,CAAC;IAC5E,IAAW,GAAG,oCAEb;IAEe,OAAO;IAIvB,IAAW,OAAO,uBAEjB;IAEY,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE;;;;;;IAoBpB,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;IA2BxD,IAAI,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;CAmBjG"}
|
|
@@ -2,11 +2,7 @@ import { assertEx } from '@xylabs/sdk-js';
|
|
|
2
2
|
import { XyoArchivist, XyoArchivistFindQuerySchema } from '@xyo-network/archivist';
|
|
3
3
|
import { XyoBoundWitnessSchema } from '@xyo-network/boundwitness';
|
|
4
4
|
import { XyoPayloadWrapper } from '@xyo-network/payload';
|
|
5
|
-
|
|
6
|
-
constructor(action, error, message) {
|
|
7
|
-
super(`Remote Archivist [${action}] failed${message ? ` (${message})` : ''}`, { cause: error });
|
|
8
|
-
}
|
|
9
|
-
}
|
|
5
|
+
import { RemoteArchivistError } from './RemoteArchivistError';
|
|
10
6
|
/** @description Archivist Context that connects to a remote archivist using the API */
|
|
11
7
|
export class XyoRemoteArchivist extends XyoArchivist {
|
|
12
8
|
get api() {
|
|
@@ -21,15 +17,18 @@ export class XyoRemoteArchivist extends XyoArchivist {
|
|
|
21
17
|
async get(hashes) {
|
|
22
18
|
return await Promise.all(hashes.map(async (hash) => {
|
|
23
19
|
try {
|
|
24
|
-
const [payloads,
|
|
25
|
-
if (error?.
|
|
26
|
-
throw new RemoteArchivistError('get', error);
|
|
20
|
+
const [payloads, response, error] = await this.api.archive(this.archive).payload.hash(hash).get('tuple');
|
|
21
|
+
if (error?.status >= 400) {
|
|
22
|
+
throw new RemoteArchivistError('get', `${error.statusText} [${error.status}]`);
|
|
23
|
+
}
|
|
24
|
+
if (response?.error?.length) {
|
|
25
|
+
throw new RemoteArchivistError('get', response?.error);
|
|
27
26
|
}
|
|
28
27
|
return payloads?.pop() ?? null;
|
|
29
28
|
}
|
|
30
29
|
catch (ex) {
|
|
31
|
-
console.
|
|
32
|
-
throw
|
|
30
|
+
console.error(ex);
|
|
31
|
+
throw ex;
|
|
33
32
|
}
|
|
34
33
|
}));
|
|
35
34
|
}
|
|
@@ -44,16 +43,20 @@ export class XyoRemoteArchivist extends XyoArchivist {
|
|
|
44
43
|
});
|
|
45
44
|
});
|
|
46
45
|
const [boundwitness] = await this.bindPayloads(payloads);
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
const bwWithMeta = { ...boundwitness, _payloads: payloads };
|
|
47
|
+
const bwResult = await this.api.archive(this.archive).block.post([bwWithMeta], 'tuple');
|
|
48
|
+
const [, response, error] = bwResult;
|
|
49
|
+
if (error?.status >= 400) {
|
|
50
|
+
throw new RemoteArchivistError('insert', `${error.statusText} [${error.status}]`);
|
|
51
|
+
}
|
|
52
|
+
if (response?.error?.length) {
|
|
53
|
+
throw new RemoteArchivistError('insert', response?.error);
|
|
51
54
|
}
|
|
52
55
|
return boundwitness;
|
|
53
56
|
}
|
|
54
57
|
catch (ex) {
|
|
55
|
-
console.
|
|
56
|
-
throw
|
|
58
|
+
console.error(ex);
|
|
59
|
+
throw ex;
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
async find(filter) {
|
|
@@ -62,15 +65,18 @@ export class XyoRemoteArchivist extends XyoArchivist {
|
|
|
62
65
|
if (payloadError?.length) {
|
|
63
66
|
throw new RemoteArchivistError('find', payloadError, 'payloads');
|
|
64
67
|
}
|
|
65
|
-
const [blocks = [],
|
|
66
|
-
if (
|
|
67
|
-
throw new RemoteArchivistError('find',
|
|
68
|
+
const [blocks = [], response, error] = await this.api.archive(this.archive).block.find(filter, 'tuple');
|
|
69
|
+
if (error?.status >= 400) {
|
|
70
|
+
throw new RemoteArchivistError('find', `${error.statusText} [${error.status}]`);
|
|
71
|
+
}
|
|
72
|
+
if (response?.error?.length) {
|
|
73
|
+
throw new RemoteArchivistError('find', response?.error);
|
|
68
74
|
}
|
|
69
75
|
return payloads.concat(blocks);
|
|
70
76
|
}
|
|
71
77
|
catch (ex) {
|
|
72
|
-
console.
|
|
73
|
-
throw
|
|
78
|
+
console.error(ex);
|
|
79
|
+
throw ex;
|
|
74
80
|
}
|
|
75
81
|
}
|
|
76
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XyoRemoteArchivist.js","sourceRoot":"","sources":["../../../src/Archivist/XyoRemoteArchivist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAwB,MAAM,wBAAwB,CAAA;AACxG,OAAO,EAAmB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"XyoRemoteArchivist.js","sourceRoot":"","sources":["../../../src/Archivist/XyoRemoteArchivist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAwB,MAAM,wBAAwB,CAAA;AACxG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CAAC,EAAE,CAAC,CAAA;YACjB,MAAM,EAAE,CAAA;SACT;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xylabs/sdk-js": "^2.6.7",
|
|
13
|
-
"@xyo-network/account": "^2.33.0-rc.
|
|
14
|
-
"@xyo-network/archivist": "^2.33.0-rc.
|
|
15
|
-
"@xyo-network/boundwitness": "^2.33.0-rc.
|
|
16
|
-
"@xyo-network/core": "^2.33.0-rc.
|
|
17
|
-
"@xyo-network/payload": "^2.33.0-rc.
|
|
18
|
-
"@xyo-network/schema-payload-plugin": "^2.33.0-rc.
|
|
13
|
+
"@xyo-network/account": "^2.33.0-rc.7",
|
|
14
|
+
"@xyo-network/archivist": "^2.33.0-rc.7",
|
|
15
|
+
"@xyo-network/boundwitness": "^2.33.0-rc.7",
|
|
16
|
+
"@xyo-network/core": "^2.33.0-rc.7",
|
|
17
|
+
"@xyo-network/payload": "^2.33.0-rc.7",
|
|
18
|
+
"@xyo-network/schema-payload-plugin": "^2.33.0-rc.7",
|
|
19
19
|
"axios": "^0.27.2",
|
|
20
20
|
"pako": "^2.0.4",
|
|
21
21
|
"tslib": "^2.4.0"
|
|
@@ -57,6 +57,6 @@
|
|
|
57
57
|
},
|
|
58
58
|
"sideEffects": false,
|
|
59
59
|
"types": "dist/esm/index.d.ts",
|
|
60
|
-
"version": "2.33.0-rc.
|
|
60
|
+
"version": "2.33.0-rc.7",
|
|
61
61
|
"stableVersion": "2.32.1"
|
|
62
62
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export class RemoteArchivistError extends Error {
|
|
2
|
+
constructor(action: string, error: Error['cause'], message?: string) {
|
|
3
|
+
super(`Remote Archivist [${action}] failed${message ? ` (${message})` : ''}`, { cause: error })
|
|
4
|
+
}
|
|
5
|
+
isRemoteArchivistError = true
|
|
6
|
+
static isRemoteArchivistError(error: unknown): RemoteArchivistError | undefined {
|
|
7
|
+
return (error as RemoteArchivistError).isRemoteArchivistError ? (error as RemoteArchivistError) : undefined
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { XyoPayloadWrapper } from '@xyo-network/payload'
|
|
2
|
+
|
|
1
3
|
import { XyoApiConfig } from '../models'
|
|
2
4
|
import { XyoArchivistApi } from './Api'
|
|
3
5
|
import { XyoRemoteArchivist } from './XyoRemoteArchivist'
|
|
@@ -14,10 +16,13 @@ test('XyoRemoteArchivist', async () => {
|
|
|
14
16
|
const api = new XyoArchivistApi(configData)
|
|
15
17
|
const archivist = new XyoRemoteArchivist({ api, schema: XyoRemoteArchivistConfigSchema })
|
|
16
18
|
const payload = {
|
|
17
|
-
salt:
|
|
19
|
+
salt: `${Math.random() * 10000}`,
|
|
18
20
|
schema: 'network.xyo.id',
|
|
19
21
|
}
|
|
20
22
|
const result = await archivist.insert([payload])
|
|
21
|
-
console.log(`Result: ${JSON.stringify(result)}`)
|
|
22
23
|
expect(result.payload_hashes.length).toBe(1)
|
|
24
|
+
const getResult = await archivist.get([new XyoPayloadWrapper(payload).hash])
|
|
25
|
+
console.log(`getResult: ${JSON.stringify(getResult)}`)
|
|
26
|
+
expect(getResult.length).toBe(1)
|
|
27
|
+
expect(getResult[0]?.schema).toBe(payload.schema)
|
|
23
28
|
})
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/sdk-js'
|
|
2
2
|
import { XyoArchivist, XyoArchivistFindQuerySchema, XyoPayloadFindFilter } from '@xyo-network/archivist'
|
|
3
|
-
import { XyoBoundWitness, XyoBoundWitnessSchema, XyoBoundWitnessWithPartialMeta } from '@xyo-network/boundwitness'
|
|
3
|
+
import { XyoBoundWitness, XyoBoundWitnessSchema, XyoBoundWitnessWithMeta, XyoBoundWitnessWithPartialMeta } from '@xyo-network/boundwitness'
|
|
4
4
|
import { XyoPayload, XyoPayloadWrapper } from '@xyo-network/payload'
|
|
5
5
|
|
|
6
|
+
import { RemoteArchivistError } from './RemoteArchivistError'
|
|
6
7
|
import { XyoRemoteArchivistConfig } from './XyoRemoteArchivistConfig'
|
|
7
8
|
|
|
8
|
-
class RemoteArchivistError extends Error {
|
|
9
|
-
constructor(action: string, error: Error['cause'], message?: string) {
|
|
10
|
-
super(`Remote Archivist [${action}] failed${message ? ` (${message})` : ''}`, { cause: error })
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
9
|
/** @description Archivist Context that connects to a remote archivist using the API */
|
|
15
10
|
export class XyoRemoteArchivist extends XyoArchivist<XyoRemoteArchivistConfig> {
|
|
16
11
|
public get api() {
|
|
@@ -29,14 +24,17 @@ export class XyoRemoteArchivist extends XyoArchivist<XyoRemoteArchivistConfig> {
|
|
|
29
24
|
return await Promise.all(
|
|
30
25
|
hashes.map(async (hash) => {
|
|
31
26
|
try {
|
|
32
|
-
const [payloads,
|
|
33
|
-
if (error?.
|
|
34
|
-
throw new RemoteArchivistError('get', error)
|
|
27
|
+
const [payloads, response, error] = await this.api.archive(this.archive).payload.hash(hash).get('tuple')
|
|
28
|
+
if (error?.status >= 400) {
|
|
29
|
+
throw new RemoteArchivistError('get', `${error.statusText} [${error.status}]`)
|
|
30
|
+
}
|
|
31
|
+
if (response?.error?.length) {
|
|
32
|
+
throw new RemoteArchivistError('get', response?.error)
|
|
35
33
|
}
|
|
36
34
|
return payloads?.pop() ?? null
|
|
37
35
|
} catch (ex) {
|
|
38
|
-
console.
|
|
39
|
-
throw
|
|
36
|
+
console.error(ex)
|
|
37
|
+
throw ex
|
|
40
38
|
}
|
|
41
39
|
}),
|
|
42
40
|
)
|
|
@@ -53,15 +51,19 @@ export class XyoRemoteArchivist extends XyoArchivist<XyoRemoteArchivistConfig> {
|
|
|
53
51
|
})
|
|
54
52
|
})
|
|
55
53
|
const [boundwitness] = await this.bindPayloads(payloads)
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
const bwWithMeta: Partial<XyoBoundWitnessWithMeta> & XyoBoundWitness = { ...boundwitness, _payloads: payloads }
|
|
55
|
+
const bwResult = await this.api.archive(this.archive).block.post([bwWithMeta], 'tuple')
|
|
56
|
+
const [, response, error] = bwResult
|
|
57
|
+
if (error?.status >= 400) {
|
|
58
|
+
throw new RemoteArchivistError('insert', `${error.statusText} [${error.status}]`)
|
|
59
|
+
}
|
|
60
|
+
if (response?.error?.length) {
|
|
61
|
+
throw new RemoteArchivistError('insert', response?.error)
|
|
60
62
|
}
|
|
61
63
|
return boundwitness
|
|
62
64
|
} catch (ex) {
|
|
63
|
-
console.
|
|
64
|
-
throw
|
|
65
|
+
console.error(ex)
|
|
66
|
+
throw ex
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -71,14 +73,17 @@ export class XyoRemoteArchivist extends XyoArchivist<XyoRemoteArchivistConfig> {
|
|
|
71
73
|
if (payloadError?.length) {
|
|
72
74
|
throw new RemoteArchivistError('find', payloadError, 'payloads')
|
|
73
75
|
}
|
|
74
|
-
const [blocks = [],
|
|
75
|
-
if (
|
|
76
|
-
throw new RemoteArchivistError('find',
|
|
76
|
+
const [blocks = [], response, error] = await this.api.archive(this.archive).block.find(filter, 'tuple')
|
|
77
|
+
if (error?.status >= 400) {
|
|
78
|
+
throw new RemoteArchivistError('find', `${error.statusText} [${error.status}]`)
|
|
79
|
+
}
|
|
80
|
+
if (response?.error?.length) {
|
|
81
|
+
throw new RemoteArchivistError('find', response?.error)
|
|
77
82
|
}
|
|
78
83
|
return payloads.concat(blocks) as R[]
|
|
79
84
|
} catch (ex) {
|
|
80
|
-
console.
|
|
81
|
-
throw
|
|
85
|
+
console.error(ex)
|
|
86
|
+
throw ex
|
|
82
87
|
}
|
|
83
88
|
}
|
|
84
89
|
}
|