@xyo-network/api 2.20.42 → 2.20.45
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/Api.d.ts +2 -1
- package/dist/cjs/Archivist/Api.js +3 -2
- package/dist/cjs/Archivist/Api.js.map +1 -1
- package/dist/cjs/Archivist/Node/Api.d.ts +28 -0
- package/dist/cjs/Archivist/Node/Api.js +74 -0
- package/dist/cjs/Archivist/Node/Api.js.map +1 -0
- package/dist/cjs/Archivist/Node/index.d.ts +1 -0
- package/dist/cjs/Archivist/Node/index.js +5 -0
- package/dist/cjs/Archivist/Node/index.js.map +1 -0
- package/dist/docs.json +4130 -4134
- package/dist/esm/Archivist/Api.d.ts +2 -1
- package/dist/esm/Archivist/Api.js +4 -3
- package/dist/esm/Archivist/Api.js.map +1 -1
- package/dist/esm/Archivist/Node/Api.d.ts +28 -0
- package/dist/esm/Archivist/Node/Api.js +67 -0
- package/dist/esm/Archivist/Node/Api.js.map +1 -0
- package/dist/esm/Archivist/Node/index.d.ts +1 -0
- package/dist/esm/Archivist/Node/index.js +2 -0
- package/dist/esm/Archivist/Node/index.js.map +1 -0
- package/package.json +3 -3
- package/src/Archivist/Api.spec.ts +1 -26
- package/src/Archivist/Api.ts +4 -3
- package/src/Archivist/Node/Api.spec.ts +141 -0
- package/src/Archivist/Node/Api.ts +75 -0
- package/src/Archivist/Node/index.ts +1 -0
|
@@ -6,6 +6,7 @@ import { XyoUserApi } from '../User';
|
|
|
6
6
|
import { XyoAccountApi } from './Account';
|
|
7
7
|
import { XyoArchivistArchiveApi } from './Archive';
|
|
8
8
|
import { XyoArchivistArchivesApi } from './Archives';
|
|
9
|
+
import { XyoArchivistNodeApi } from './Node';
|
|
9
10
|
export declare class XyoArchivistApi extends XyoApiBase {
|
|
10
11
|
private _archives?;
|
|
11
12
|
get archives(): XyoArchivistArchivesApi;
|
|
@@ -23,7 +24,7 @@ export declare class XyoArchivistApi extends XyoApiBase {
|
|
|
23
24
|
* @param archive Optional, the archive to issue the requests against
|
|
24
25
|
* @returns Confirmation for the request, as a BoundWitness, from the network Node
|
|
25
26
|
*/
|
|
26
|
-
node<
|
|
27
|
+
node<TData extends XyoBoundWitness | XyoBoundWitness[] = XyoBoundWitness | XyoBoundWitness[]>(archive?: string): XyoArchivistNodeApi<TData, import("..").WithArchive<import("../models/Api/Config").XyoApiConfig>>;
|
|
27
28
|
/** @deprecated use huri(huri) instead */
|
|
28
29
|
get(huri: Huri | string): Promise<XyoApiResponseBody<XyoPayload>>;
|
|
29
30
|
/** @deprecated use huri(huri) instead */
|
|
@@ -9,6 +9,7 @@ const User_1 = require("../User");
|
|
|
9
9
|
const Account_1 = require("./Account");
|
|
10
10
|
const Archive_1 = require("./Archive");
|
|
11
11
|
const Archives_1 = require("./Archives");
|
|
12
|
+
const Node_1 = require("./Node");
|
|
12
13
|
class XyoArchivistApi extends Base_1.XyoApiBase {
|
|
13
14
|
get archives() {
|
|
14
15
|
var _a;
|
|
@@ -48,8 +49,8 @@ class XyoArchivistApi extends Base_1.XyoApiBase {
|
|
|
48
49
|
* @param archive Optional, the archive to issue the requests against
|
|
49
50
|
* @returns Confirmation for the request, as a BoundWitness, from the network Node
|
|
50
51
|
*/
|
|
51
|
-
node(archive) {
|
|
52
|
-
return new
|
|
52
|
+
node(archive = 'temp') {
|
|
53
|
+
return new Node_1.XyoArchivistNodeApi(Object.assign(Object.assign({}, this.config), { root: `${this.root}${archive}/` }));
|
|
53
54
|
}
|
|
54
55
|
/** @deprecated use huri(huri) instead */
|
|
55
56
|
get(huri, responseType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Api.js","sourceRoot":"","sources":["../../../src/Archivist/Api.ts"],"names":[],"mappings":";;;;AAAA,4CAAmG;AAEnG,kCAAoC;AAEpC,sCAAwC;AACxC,kCAAoC;AACpC,uCAAyC;AACzC,uCAAkD;AAClD,yCAAoD;
|
|
1
|
+
{"version":3,"file":"Api.js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3
|
+
import { XyoApiSimple, XyoApiSimpleQuery } from '../../Simple';
|
|
4
|
+
import { WithArchive } from '../../WithArchive';
|
|
5
|
+
export declare class XyoArchivistNodeApi<D extends XyoBoundWitness | XyoBoundWitness[] = XyoBoundWitness | XyoBoundWitness[], C extends WithArchive<XyoApiConfig> = WithArchive<XyoApiConfig>> extends XyoApiSimple<string[][], D, XyoApiSimpleQuery, C> {
|
|
6
|
+
/**
|
|
7
|
+
* Get the result of a previously issued query (if available)
|
|
8
|
+
* @param queryId Query ID from a previously issued query
|
|
9
|
+
* @returns The result of the query (if available)
|
|
10
|
+
*/
|
|
11
|
+
result<T extends XyoPayload = XyoPayload>(queryId: string): XyoApiSimple<XyoPayload>;
|
|
12
|
+
/**
|
|
13
|
+
* Issue the supplied queries and wait (non-blocking) for the results
|
|
14
|
+
* @param data The queries to issue
|
|
15
|
+
* @param timeout The max time to wait for the query results
|
|
16
|
+
* @param retryInterval The interval to poll for query results
|
|
17
|
+
* @returns The results for the issued queries
|
|
18
|
+
*/
|
|
19
|
+
performTransaction(data: D, timeout?: number, retryInterval?: number): Promise<import("../../models").XyoApiEnvelope<import("@xyo-network/core").XyoPayloadFull | undefined>[][]>;
|
|
20
|
+
/**
|
|
21
|
+
* Issue the supplied query and wait (non-blocking) for the result
|
|
22
|
+
* @param data The query to issue
|
|
23
|
+
* @param timeout The max time to wait for the query results
|
|
24
|
+
* @param retryInterval The interval to poll for query results
|
|
25
|
+
* @returns The result for the issued query
|
|
26
|
+
*/
|
|
27
|
+
perform<T>(data: T, schema: string, timeout?: number, retryInterval?: number): Promise<import("../../models").XyoApiEnvelope<import("@xyo-network/core").XyoPayloadFull | undefined>>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XyoArchivistNodeApi = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const sdk_js_1 = require("@xylabs/sdk-js");
|
|
6
|
+
const core_1 = require("@xyo-network/core");
|
|
7
|
+
const Simple_1 = require("../../Simple");
|
|
8
|
+
const getRequestStatuses = (results) => {
|
|
9
|
+
return results.flatMap((r) => r).map((r) => { var _a; return (_a = r === null || r === void 0 ? void 0 : r[2]) === null || _a === void 0 ? void 0 : _a.status; });
|
|
10
|
+
};
|
|
11
|
+
const allRequestsSucceeded = (results) => {
|
|
12
|
+
return getRequestStatuses(results).every((status) => status === 200);
|
|
13
|
+
};
|
|
14
|
+
const anyRequestsFailed = (results) => {
|
|
15
|
+
return getRequestStatuses(results).every((status) => status > 399);
|
|
16
|
+
};
|
|
17
|
+
class XyoArchivistNodeApi extends Simple_1.XyoApiSimple {
|
|
18
|
+
/**
|
|
19
|
+
* Get the result of a previously issued query (if available)
|
|
20
|
+
* @param queryId Query ID from a previously issued query
|
|
21
|
+
* @returns The result of the query (if available)
|
|
22
|
+
*/
|
|
23
|
+
result(queryId) {
|
|
24
|
+
return new Simple_1.XyoApiSimple(Object.assign(Object.assign({}, this.config), { root: `/query/${queryId}/` }));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Issue the supplied queries and wait (non-blocking) for the results
|
|
28
|
+
* @param data The queries to issue
|
|
29
|
+
* @param timeout The max time to wait for the query results
|
|
30
|
+
* @param retryInterval The interval to poll for query results
|
|
31
|
+
* @returns The results for the issued queries
|
|
32
|
+
*/
|
|
33
|
+
performTransaction(data, timeout = 5000, retryInterval = 100) {
|
|
34
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
(0, sdk_js_1.assertEx)(timeout > 0, 'timeout must be positive');
|
|
36
|
+
(0, sdk_js_1.assertEx)(retryInterval > 0, 'retryInterval must be positive');
|
|
37
|
+
(0, sdk_js_1.assertEx)(timeout > retryInterval, 'timeout must be greater than retryInterval');
|
|
38
|
+
const ids = yield this.post(data);
|
|
39
|
+
if (!(ids === null || ids === void 0 ? void 0 : ids.length))
|
|
40
|
+
return [];
|
|
41
|
+
const loops = Math.floor(timeout / retryInterval);
|
|
42
|
+
let results = [];
|
|
43
|
+
for (let i = 0; i < loops; i++) {
|
|
44
|
+
yield (0, sdk_js_1.delay)(retryInterval);
|
|
45
|
+
results = yield Promise.all(ids === null || ids === void 0 ? void 0 : ids.map((bw) => tslib_1.__awaiter(this, void 0, void 0, function* () { return yield Promise.all(bw.map((p) => this.result(p).get('tuple'))); })));
|
|
46
|
+
if (allRequestsSucceeded(results))
|
|
47
|
+
break;
|
|
48
|
+
// TODO: More nuanced error handling of partial success/failure
|
|
49
|
+
if (anyRequestsFailed(results))
|
|
50
|
+
throw new Error('Request Error');
|
|
51
|
+
}
|
|
52
|
+
// Unpack results
|
|
53
|
+
return results.map((b) => b.map((p) => p[1]));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Issue the supplied query and wait (non-blocking) for the result
|
|
58
|
+
* @param data The query to issue
|
|
59
|
+
* @param timeout The max time to wait for the query results
|
|
60
|
+
* @param retryInterval The interval to poll for query results
|
|
61
|
+
* @returns The result for the issued query
|
|
62
|
+
*/
|
|
63
|
+
perform(data, schema, timeout = 5000, retryInterval = 100) {
|
|
64
|
+
var _a;
|
|
65
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const payload = new core_1.XyoPayloadBuilder({ schema }).fields(data).build();
|
|
67
|
+
const query = new core_1.XyoBoundWitnessBuilder({ inlinePayloads: true }).payload(payload).build();
|
|
68
|
+
const result = yield this.performTransaction(query, timeout, retryInterval);
|
|
69
|
+
return (_a = result === null || result === void 0 ? void 0 : result[0]) === null || _a === void 0 ? void 0 : _a[0];
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.XyoArchivistNodeApi = XyoArchivistNodeApi;
|
|
74
|
+
//# sourceMappingURL=Api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Api.js","sourceRoot":"","s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