@xyo-network/payload 2.38.9 → 2.38.10
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/Builder/Builder.d.ts +1 -1
- package/dist/cjs/Builder/Builder.d.ts.map +1 -1
- package/dist/cjs/Builder/Builder.js +6 -6
- package/dist/cjs/Builder/Builder.js.map +1 -1
- package/dist/cjs/Huri/Huri.d.ts +10 -10
- package/dist/cjs/Huri/Huri.d.ts.map +1 -1
- package/dist/cjs/Huri/Huri.js +47 -47
- package/dist/cjs/Huri/Huri.js.map +1 -1
- package/dist/cjs/Wrapper/Wrapper.d.ts +4 -4
- package/dist/cjs/Wrapper/Wrapper.d.ts.map +1 -1
- package/dist/cjs/Wrapper/Wrapper.js +12 -12
- package/dist/cjs/Wrapper/Wrapper.js.map +1 -1
- package/dist/docs.json +758 -606
- package/dist/esm/Builder/Builder.d.ts +1 -1
- package/dist/esm/Builder/Builder.d.ts.map +1 -1
- package/dist/esm/Builder/Builder.js +6 -6
- package/dist/esm/Builder/Builder.js.map +1 -1
- package/dist/esm/Huri/Huri.d.ts +10 -10
- package/dist/esm/Huri/Huri.d.ts.map +1 -1
- package/dist/esm/Huri/Huri.js +46 -46
- package/dist/esm/Huri/Huri.js.map +1 -1
- package/dist/esm/Wrapper/Wrapper.d.ts +4 -4
- package/dist/esm/Wrapper/Wrapper.d.ts.map +1 -1
- package/dist/esm/Wrapper/Wrapper.js +12 -12
- package/dist/esm/Wrapper/Wrapper.js.map +1 -1
- package/package.json +4 -4
- package/src/Builder/Builder.ts +7 -7
- package/src/Huri/Huri.ts +59 -60
- package/src/Wrapper/Wrapper.ts +16 -16
|
@@ -6,8 +6,8 @@ export declare class XyoPayloadBuilder<T extends XyoPayload = XyoPayload<Record<
|
|
|
6
6
|
private _fields;
|
|
7
7
|
private _schema;
|
|
8
8
|
constructor({ schema }: XyoPayloadBuilderOptions);
|
|
9
|
+
build(): T;
|
|
9
10
|
fields(fields?: Partial<T>): this;
|
|
10
11
|
hashableFields(): T;
|
|
11
|
-
build(): T;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=Builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Builder.d.ts","sourceRoot":"","sources":["../../../src/Builder/Builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAA;CACf;AAED,qBAAa,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvF,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,OAAO,CAAQ;gBAEX,EAAE,MAAM,EAAE,EAAE,wBAAwB;IAIzC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAO1B,cAAc;
|
|
1
|
+
{"version":3,"file":"Builder.d.ts","sourceRoot":"","sources":["../../../src/Builder/Builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAA;CACf;AAED,qBAAa,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvF,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,OAAO,CAAQ;gBAEX,EAAE,MAAM,EAAE,EAAE,wBAAwB;IAIzC,KAAK,IAAI,CAAC;IAOV,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAO1B,cAAc;CAMtB"}
|
|
@@ -5,6 +5,12 @@ export class XyoPayloadBuilder {
|
|
|
5
5
|
constructor({ schema }) {
|
|
6
6
|
this._schema = schema;
|
|
7
7
|
}
|
|
8
|
+
build() {
|
|
9
|
+
const hashableFields = this.hashableFields();
|
|
10
|
+
const _hash = new Hasher(hashableFields).hash;
|
|
11
|
+
const _timestamp = Date.now();
|
|
12
|
+
return { ...hashableFields, _client: 'js', _hash, _timestamp, schema: this._schema };
|
|
13
|
+
}
|
|
8
14
|
fields(fields) {
|
|
9
15
|
if (fields) {
|
|
10
16
|
this._fields = { ...this._fields, ...removeEmptyFields(fields) };
|
|
@@ -17,11 +23,5 @@ export class XyoPayloadBuilder {
|
|
|
17
23
|
schema: this._schema,
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
|
-
build() {
|
|
21
|
-
const hashableFields = this.hashableFields();
|
|
22
|
-
const _hash = new Hasher(hashableFields).hash;
|
|
23
|
-
const _timestamp = Date.now();
|
|
24
|
-
return { ...hashableFields, _client: 'js', _hash, _timestamp, schema: this._schema };
|
|
25
|
-
}
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=Builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Builder.js","sourceRoot":"","sources":["../../../src/Builder/Builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAQvF,MAAM,OAAO,iBAAiB;IACpB,OAAO,GAAe,EAAE,CAAA;IACxB,OAAO,CAAQ;IAEvB,YAAY,EAAE,MAAM,EAA4B;QAC9C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAEM,MAAM,
|
|
1
|
+
{"version":3,"file":"Builder.js","sourceRoot":"","sources":["../../../src/Builder/Builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAQvF,MAAM,OAAO,iBAAiB;IACpB,OAAO,GAAe,EAAE,CAAA;IACxB,OAAO,CAAQ;IAEvB,YAAY,EAAE,MAAM,EAA4B;QAC9C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAEM,KAAK;QACV,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;QAC5C,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAA;QAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAC7B,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,CAAA;IACtF,CAAC;IAEM,MAAM,CAAC,MAAmB;QAC/B,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAA;SACjE;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,cAAc;QACnB,OAAO;YACL,GAAG,iBAAiB,CAAC,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5D,MAAM,EAAE,IAAI,CAAC,OAAO;SAChB,CAAA;IACR,CAAC;CACF"}
|
package/dist/esm/Huri/Huri.d.ts
CHANGED
|
@@ -6,27 +6,27 @@ export interface HuriOptions {
|
|
|
6
6
|
archivistUri?: string;
|
|
7
7
|
}
|
|
8
8
|
export interface XyoFetchedPayload<T extends XyoPayload = XyoPayload> {
|
|
9
|
-
payload: T;
|
|
10
9
|
huri?: Huri;
|
|
10
|
+
payload: T;
|
|
11
11
|
}
|
|
12
12
|
export declare class Huri<T extends XyoPayload = XyoPayload> {
|
|
13
|
-
originalHref: string;
|
|
14
|
-
protocol?: string;
|
|
15
|
-
archivist?: string;
|
|
16
13
|
archive?: string;
|
|
14
|
+
archivist?: string;
|
|
17
15
|
hash: string;
|
|
16
|
+
originalHref: string;
|
|
17
|
+
protocol?: string;
|
|
18
18
|
private isHuri;
|
|
19
19
|
constructor(huri: XyoDataLike | Huri, { archivistUri }?: HuriOptions);
|
|
20
|
-
private parsePath;
|
|
21
|
-
private validateParse;
|
|
22
20
|
get href(): string;
|
|
23
|
-
toString(): string;
|
|
24
|
-
fetch(): Promise<T | undefined>;
|
|
25
21
|
static fetch<T extends XyoPayload = XyoPayload>(huri: Huri): Promise<T | undefined>;
|
|
26
|
-
private static parseProtocol;
|
|
27
|
-
private static parsePath;
|
|
28
22
|
static isHuri(value: unknown): Huri<import("../models").SchemaFields & import("../models").PayloadFields & {
|
|
29
23
|
schema: string;
|
|
30
24
|
}> | undefined;
|
|
25
|
+
private static parsePath;
|
|
26
|
+
private static parseProtocol;
|
|
27
|
+
fetch(): Promise<T | undefined>;
|
|
28
|
+
toString(): string;
|
|
29
|
+
private parsePath;
|
|
30
|
+
private validateParse;
|
|
31
31
|
}
|
|
32
32
|
//# sourceMappingURL=Huri.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../../src/Huri/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,oBAAY,iBAAiB,GAAG,OAAO,GAAG,SAAS,CAAA;AAEnD,oBAAY,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAA;AAY/E,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAClE,
|
|
1
|
+
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../../src/Huri/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,oBAAY,iBAAiB,GAAG,OAAO,GAAG,SAAS,CAAA;AAEnD,oBAAY,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAA;AAY/E,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAClE,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,EAAE,CAAC,CAAA;CACX;AAED,qBAAa,IAAI,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IAExB,OAAO,CAAC,MAAM,CAAO;gBAET,IAAI,EAAE,WAAW,GAAG,IAAI,EAAE,EAAE,YAAY,EAAE,GAAE,WAAgB;IAuBxE,IAAW,IAAI,WAad;WAEY,KAAK,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;WAI3E,MAAM,CAAC,KAAK,EAAE,OAAO;;;IAOnC,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,aAAa;IAYf,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrC,QAAQ;IAIf,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/esm/Huri/Huri.js
CHANGED
|
@@ -2,11 +2,11 @@ import { assertEx } from '@xylabs/assert';
|
|
|
2
2
|
import { XyoAddressValue } from '@xyo-network/account';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
export class Huri {
|
|
5
|
-
originalHref;
|
|
6
|
-
protocol;
|
|
7
|
-
archivist;
|
|
8
5
|
archive;
|
|
6
|
+
archivist;
|
|
9
7
|
hash;
|
|
8
|
+
originalHref;
|
|
9
|
+
protocol;
|
|
10
10
|
isHuri = true;
|
|
11
11
|
constructor(huri, { archivistUri } = {}) {
|
|
12
12
|
const huriString = (Huri.isHuri(huri)?.href ?? typeof huri === 'string') ? huri : new XyoAddressValue(huri).hex;
|
|
@@ -23,30 +23,6 @@ export class Huri {
|
|
|
23
23
|
}
|
|
24
24
|
this.validateParse();
|
|
25
25
|
}
|
|
26
|
-
parsePath(path, hasProtocol) {
|
|
27
|
-
const pathParts = path.split('/');
|
|
28
|
-
//if the protocol was found, then there is not allowed to be a leading /
|
|
29
|
-
assertEx(!(hasProtocol && pathParts[0].length === 0), 'Invalid protocol separator');
|
|
30
|
-
//remove leading '/' if needed
|
|
31
|
-
pathParts[0].length === 0 ? pathParts.shift() : null;
|
|
32
|
-
//hash is assumed to be the last part
|
|
33
|
-
const hash = assertEx(pathParts.pop(), 'No hash specified');
|
|
34
|
-
//archivist is assumed to be the first part
|
|
35
|
-
this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network';
|
|
36
|
-
//the archive is whatever is left
|
|
37
|
-
this.archive = pathParts.pop();
|
|
38
|
-
//after we pull off all the path parts, there should be nothing left
|
|
39
|
-
assertEx(pathParts.length === 0, 'Too many path parts');
|
|
40
|
-
return hash;
|
|
41
|
-
}
|
|
42
|
-
validateParse() {
|
|
43
|
-
//the archivist should not be zero length
|
|
44
|
-
assertEx(this.archivist?.length !== 0, 'Invalid archivist length');
|
|
45
|
-
//the archivist should not be zero length (can be undefined)
|
|
46
|
-
assertEx(this.archive?.length !== 0, 'Invalid archive length');
|
|
47
|
-
//the archive should not be set if the archivist is not set
|
|
48
|
-
assertEx(!(this.archive && !this.archivist), 'If specifying archive, archivist is also required');
|
|
49
|
-
}
|
|
50
26
|
/*
|
|
51
27
|
The full href or the hash
|
|
52
28
|
*/
|
|
@@ -64,25 +40,14 @@ export class Huri {
|
|
|
64
40
|
parts.push(this.hash);
|
|
65
41
|
return parts.join('/');
|
|
66
42
|
}
|
|
67
|
-
toString() {
|
|
68
|
-
return this.href;
|
|
69
|
-
}
|
|
70
|
-
async fetch() {
|
|
71
|
-
return await Huri.fetch(this);
|
|
72
|
-
}
|
|
73
43
|
static async fetch(huri) {
|
|
74
44
|
return (await axios.get(huri.href)).data;
|
|
75
45
|
}
|
|
76
|
-
static
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined;
|
|
80
|
-
if (rawProtocol) {
|
|
81
|
-
const protocolParts = rawProtocol?.split(':');
|
|
82
|
-
assertEx(protocolParts.length === 2, `Invalid protocol format [${rawProtocol}]`);
|
|
83
|
-
assertEx(protocolParts[1].length === 0, `Invalid protocol format (post :) [${rawProtocol}]`);
|
|
84
|
-
return protocolParts.shift();
|
|
46
|
+
static isHuri(value) {
|
|
47
|
+
if (typeof value === 'object') {
|
|
48
|
+
return value.isHuri ? value : undefined;
|
|
85
49
|
}
|
|
50
|
+
return undefined;
|
|
86
51
|
}
|
|
87
52
|
static parsePath(huri) {
|
|
88
53
|
const protocolSplit = huri.split('//');
|
|
@@ -94,11 +59,46 @@ export class Huri {
|
|
|
94
59
|
return protocolSplit[1];
|
|
95
60
|
}
|
|
96
61
|
}
|
|
97
|
-
static
|
|
98
|
-
|
|
99
|
-
|
|
62
|
+
static parseProtocol(huri) {
|
|
63
|
+
const protocolSplit = huri.split('//');
|
|
64
|
+
assertEx(protocolSplit.length <= 2, `Invalid second protocol [${protocolSplit[2]}]`);
|
|
65
|
+
const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined;
|
|
66
|
+
if (rawProtocol) {
|
|
67
|
+
const protocolParts = rawProtocol?.split(':');
|
|
68
|
+
assertEx(protocolParts.length === 2, `Invalid protocol format [${rawProtocol}]`);
|
|
69
|
+
assertEx(protocolParts[1].length === 0, `Invalid protocol format (post :) [${rawProtocol}]`);
|
|
70
|
+
return protocolParts.shift();
|
|
100
71
|
}
|
|
101
|
-
|
|
72
|
+
}
|
|
73
|
+
async fetch() {
|
|
74
|
+
return await Huri.fetch(this);
|
|
75
|
+
}
|
|
76
|
+
toString() {
|
|
77
|
+
return this.href;
|
|
78
|
+
}
|
|
79
|
+
parsePath(path, hasProtocol) {
|
|
80
|
+
const pathParts = path.split('/');
|
|
81
|
+
//if the protocol was found, then there is not allowed to be a leading /
|
|
82
|
+
assertEx(!(hasProtocol && pathParts[0].length === 0), 'Invalid protocol separator');
|
|
83
|
+
//remove leading '/' if needed
|
|
84
|
+
pathParts[0].length === 0 ? pathParts.shift() : null;
|
|
85
|
+
//hash is assumed to be the last part
|
|
86
|
+
const hash = assertEx(pathParts.pop(), 'No hash specified');
|
|
87
|
+
//archivist is assumed to be the first part
|
|
88
|
+
this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network';
|
|
89
|
+
//the archive is whatever is left
|
|
90
|
+
this.archive = pathParts.pop();
|
|
91
|
+
//after we pull off all the path parts, there should be nothing left
|
|
92
|
+
assertEx(pathParts.length === 0, 'Too many path parts');
|
|
93
|
+
return hash;
|
|
94
|
+
}
|
|
95
|
+
validateParse() {
|
|
96
|
+
//the archivist should not be zero length
|
|
97
|
+
assertEx(this.archivist?.length !== 0, 'Invalid archivist length');
|
|
98
|
+
//the archivist should not be zero length (can be undefined)
|
|
99
|
+
assertEx(this.archive?.length !== 0, 'Invalid archive length');
|
|
100
|
+
//the archive should not be set if the archivist is not set
|
|
101
|
+
assertEx(!(this.archive && !this.archivist), 'If specifying archive, archivist is also required');
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
//# sourceMappingURL=Huri.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.js","sourceRoot":"","sources":["../../../src/Huri/Huri.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,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,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,4BAA4B,CAAC,CAAA;QAEnF,8BAA8B;QAC9B,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;QAEpD,qCAAqC;QACrC,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,mBAAmB,CAAC,CAAA;QAE3D,2CAA2C;QAC3C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,2BAA2B,CAAA;QAEjE,iCAAiC;QACjC,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,GAAG,EAAE,CAAA;QAE9B,oEAAoE;QACpE,QAAQ,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,qBAAqB,CAAC,CAAA;QAEvD,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,aAAa;QACnB,yCAAyC;QACzC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,KAAK,CAAC,EAAE,0BAA0B,CAAC,CAAA;QAElE,4DAA4D;QAC5D,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,KAAK,CAAC,EAAE,wBAAwB,CAAC,CAAA;QAE9D,2DAA2D;QAC3D,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,mDAAmD,CAAC,CAAA;IACnG,CAAC;CACF"}
|
|
@@ -3,11 +3,13 @@ import { Promisable } from '@xyo-network/promise';
|
|
|
3
3
|
import { Huri } from '../Huri';
|
|
4
4
|
import { XyoPayload } from '../models';
|
|
5
5
|
export declare abstract class PayloadWrapperBase<TPayload extends XyoPayload = XyoPayload> extends Hasher<TPayload> {
|
|
6
|
+
get body(): TPayload;
|
|
7
|
+
get errors(): Error[];
|
|
6
8
|
get payload(): TPayload;
|
|
9
|
+
get previousHash(): null;
|
|
10
|
+
get schema(): string;
|
|
7
11
|
get schemaName(): string;
|
|
8
|
-
get body(): TPayload;
|
|
9
12
|
get valid(): boolean;
|
|
10
|
-
get errors(): Error[];
|
|
11
13
|
static load(_address: XyoDataLike | Huri): Promisable<PayloadWrapperBase | null>;
|
|
12
14
|
static parse(_obj: unknown): PayloadWrapperBase;
|
|
13
15
|
}
|
|
@@ -16,8 +18,6 @@ export declare class PayloadWrapper<TPayload extends XyoPayload = XyoPayload> ex
|
|
|
16
18
|
static load(address: XyoDataLike | Huri): Promise<PayloadWrapper<import("../models").SchemaFields & import("../models").PayloadFields & {
|
|
17
19
|
schema: string;
|
|
18
20
|
}> | null>;
|
|
19
|
-
get previousHash(): null;
|
|
20
|
-
get schema(): string;
|
|
21
21
|
static parse<T extends XyoPayload = XyoPayload>(obj: unknown): PayloadWrapper<T>;
|
|
22
22
|
}
|
|
23
23
|
/** @deprecated use PayloadWrapper instead */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../../src/Wrapper/Wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAGtC,8BAAsB,kBAAkB,CAAC,QAAQ,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,MAAM,CAAC,QAAQ,CAAC;IACzG,IAAW,OAAO,aAEjB;
|
|
1
|
+
{"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../../src/Wrapper/Wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAGtC,8BAAsB,kBAAkB,CAAC,QAAQ,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,MAAM,CAAC,QAAQ,CAAC;IACzG,IAAW,IAAI,aAEd;IAED,IAAI,MAAM,YAET;IAED,IAAW,OAAO,aAEjB;IAED,IAAW,YAAY,SAEtB;IAED,IAAW,MAAM,WAEhB;IAGD,IAAW,UAAU,WAEpB;IAED,IAAI,KAAK,YAER;WAEa,IAAI,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI,GAAG,UAAU,CAAC,kBAAkB,GAAG,IAAI,CAAC;WAIzE,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,kBAAkB;CAGvD;AAED,qBAAa,cAAc,CAAC,QAAQ,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,kBAAkB,CAAC,QAAQ,CAAC;IACxG,OAAO,CAAC,gBAAgB,CAAO;WAEF,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;;;WAKtC,KAAK,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,GAAG,EAAE,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC;CAajG;AAED,6CAA6C;AAC7C,qBAAa,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,kBAAkB,CAAC,CAAC,CAAC;CAAG"}
|
|
@@ -3,22 +3,28 @@ import { deepOmitUnderscoreFields, Hasher } from '@xyo-network/core';
|
|
|
3
3
|
import { Huri } from '../Huri';
|
|
4
4
|
import { PayloadValidator } from '../Validator';
|
|
5
5
|
export class PayloadWrapperBase extends Hasher {
|
|
6
|
+
get body() {
|
|
7
|
+
return deepOmitUnderscoreFields(this.obj);
|
|
8
|
+
}
|
|
9
|
+
get errors() {
|
|
10
|
+
return new PayloadValidator(this.payload).validate();
|
|
11
|
+
}
|
|
6
12
|
get payload() {
|
|
7
13
|
return assertEx(this.obj, 'Missing payload object');
|
|
8
14
|
}
|
|
15
|
+
get previousHash() {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
get schema() {
|
|
19
|
+
return this.payload.schema;
|
|
20
|
+
}
|
|
9
21
|
//intentionally not naming this 'schema' so that the wrapper is not confused for a XyoPayload
|
|
10
22
|
get schemaName() {
|
|
11
23
|
return assertEx(this.obj.schema, 'Missing payload schema');
|
|
12
24
|
}
|
|
13
|
-
get body() {
|
|
14
|
-
return deepOmitUnderscoreFields(this.obj);
|
|
15
|
-
}
|
|
16
25
|
get valid() {
|
|
17
26
|
return this.errors.length === 0;
|
|
18
27
|
}
|
|
19
|
-
get errors() {
|
|
20
|
-
return new PayloadValidator(this.payload).validate();
|
|
21
|
-
}
|
|
22
28
|
static load(_address) {
|
|
23
29
|
throw Error('Not implemented');
|
|
24
30
|
}
|
|
@@ -32,12 +38,6 @@ export class PayloadWrapper extends PayloadWrapperBase {
|
|
|
32
38
|
const payload = await new Huri(address).fetch();
|
|
33
39
|
return payload ? new PayloadWrapper(payload) : null;
|
|
34
40
|
}
|
|
35
|
-
get previousHash() {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
get schema() {
|
|
39
|
-
return this.payload.schema;
|
|
40
|
-
}
|
|
41
41
|
static parse(obj) {
|
|
42
42
|
assertEx(!Array.isArray(obj), 'Array can not be converted to PayloadWrapper');
|
|
43
43
|
switch (typeof obj) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wrapper.js","sourceRoot":"","sources":["../../../src/Wrapper/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,EAAe,MAAM,mBAAmB,CAAA;AAGjF,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CA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C/B,MAAM,KAAK,CAAC,iBAAiB,CAAC,CAAA;IAChC,CAAC;CACF;AAED,MAAM,OAAO,cAAyD,SAAQ,kBAA4B;IAChG,gBAAgB,GAAG,IAAI,CAAA;IAExB,MAAM,CAAU,KAAK,CAAC,IAAI,CAAC,OAA2B;QAC3D,MAAM,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAA;QAC/C,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACrD,CAAC;IAEM,MAAM,CAAU,KAAK,CAAoC,GAAY;QAC1E,QAAQ,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,8CAA8C,CAAC,CAAA;QAC7E,QAAQ,OAAO,GAAG,EAAE;YAClB,KAAK,QAAQ,CAAC,CAAC;gBACb,MAAM,WAAW,GAAG,GAAwB,CAAA;gBAC5C,OAAO,QAAQ,CACb,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAE,GAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,GAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAC9G,gCAAgC,CACjC,CAAA;aACF;SACF;QACD,MAAM,KAAK,CAAC,oBAAoB,OAAO,GAAG,GAAG,CAAC,CAAA;IAChD,CAAC;CACF;AAED,6CAA6C;AAC7C,MAAM,OAAO,iBAAqD,SAAQ,kBAAqB;CAAG"}
|
package/package.json
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.6.9",
|
|
14
|
-
"@xyo-network/account": "^2.38.
|
|
15
|
-
"@xyo-network/core": "^2.38.
|
|
16
|
-
"@xyo-network/promise": "^2.38.
|
|
14
|
+
"@xyo-network/account": "^2.38.10",
|
|
15
|
+
"@xyo-network/core": "^2.38.10",
|
|
16
|
+
"@xyo-network/promise": "^2.38.10",
|
|
17
17
|
"axios": "^1.1.3",
|
|
18
18
|
"tslib": "^2.4.0"
|
|
19
19
|
},
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
},
|
|
51
51
|
"sideEffects": false,
|
|
52
52
|
"types": "dist/esm/index.d.ts",
|
|
53
|
-
"version": "2.38.
|
|
53
|
+
"version": "2.38.10"
|
|
54
54
|
}
|
package/src/Builder/Builder.ts
CHANGED
|
@@ -14,6 +14,13 @@ export class XyoPayloadBuilder<T extends XyoPayload = XyoPayload<Record<string,
|
|
|
14
14
|
this._schema = schema
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
public build(): T {
|
|
18
|
+
const hashableFields = this.hashableFields()
|
|
19
|
+
const _hash = new Hasher(hashableFields).hash
|
|
20
|
+
const _timestamp = Date.now()
|
|
21
|
+
return { ...hashableFields, _client: 'js', _hash, _timestamp, schema: this._schema }
|
|
22
|
+
}
|
|
23
|
+
|
|
17
24
|
public fields(fields?: Partial<T>) {
|
|
18
25
|
if (fields) {
|
|
19
26
|
this._fields = { ...this._fields, ...removeEmptyFields(fields) }
|
|
@@ -27,11 +34,4 @@ export class XyoPayloadBuilder<T extends XyoPayload = XyoPayload<Record<string,
|
|
|
27
34
|
schema: this._schema,
|
|
28
35
|
} as T
|
|
29
36
|
}
|
|
30
|
-
|
|
31
|
-
public build(): T {
|
|
32
|
-
const hashableFields = this.hashableFields()
|
|
33
|
-
const _hash = new Hasher(hashableFields).hash
|
|
34
|
-
const _timestamp = Date.now()
|
|
35
|
-
return { ...hashableFields, _client: 'js', _hash, _timestamp, schema: this._schema }
|
|
36
|
-
}
|
|
37
37
|
}
|
package/src/Huri/Huri.ts
CHANGED
|
@@ -24,16 +24,16 @@ export interface HuriOptions {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export interface XyoFetchedPayload<T extends XyoPayload = XyoPayload> {
|
|
27
|
-
payload: T
|
|
28
27
|
huri?: Huri
|
|
28
|
+
payload: T
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export class Huri<T extends XyoPayload = XyoPayload> {
|
|
32
|
-
public originalHref: string
|
|
33
|
-
public protocol?: string
|
|
34
|
-
public archivist?: string
|
|
35
32
|
public archive?: string
|
|
33
|
+
public archivist?: string
|
|
36
34
|
public hash: string
|
|
35
|
+
public originalHref: string
|
|
36
|
+
public protocol?: string
|
|
37
37
|
|
|
38
38
|
private isHuri = true
|
|
39
39
|
|
|
@@ -57,45 +57,9 @@ export class Huri<T extends XyoPayload = XyoPayload> {
|
|
|
57
57
|
this.validateParse()
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
private parsePath(path: string, hasProtocol: boolean) {
|
|
61
|
-
const pathParts = path.split('/')
|
|
62
|
-
|
|
63
|
-
//if the protocol was found, then there is not allowed to be a leading /
|
|
64
|
-
assertEx(!(hasProtocol && pathParts[0].length === 0), 'Invalid protocol separator')
|
|
65
|
-
|
|
66
|
-
//remove leading '/' if needed
|
|
67
|
-
pathParts[0].length === 0 ? pathParts.shift() : null
|
|
68
|
-
|
|
69
|
-
//hash is assumed to be the last part
|
|
70
|
-
const hash = assertEx(pathParts.pop(), 'No hash specified')
|
|
71
|
-
|
|
72
|
-
//archivist is assumed to be the first part
|
|
73
|
-
this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'
|
|
74
|
-
|
|
75
|
-
//the archive is whatever is left
|
|
76
|
-
this.archive = pathParts.pop()
|
|
77
|
-
|
|
78
|
-
//after we pull off all the path parts, there should be nothing left
|
|
79
|
-
assertEx(pathParts.length === 0, 'Too many path parts')
|
|
80
|
-
|
|
81
|
-
return hash
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private validateParse() {
|
|
85
|
-
//the archivist should not be zero length
|
|
86
|
-
assertEx(this.archivist?.length !== 0, 'Invalid archivist length')
|
|
87
|
-
|
|
88
|
-
//the archivist should not be zero length (can be undefined)
|
|
89
|
-
assertEx(this.archive?.length !== 0, 'Invalid archive length')
|
|
90
|
-
|
|
91
|
-
//the archive should not be set if the archivist is not set
|
|
92
|
-
assertEx(!(this.archive && !this.archivist), 'If specifying archive, archivist is also required')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
60
|
/*
|
|
96
61
|
The full href or the hash
|
|
97
62
|
*/
|
|
98
|
-
|
|
99
63
|
public get href() {
|
|
100
64
|
const parts: string[] = []
|
|
101
65
|
if (this.protocol) {
|
|
@@ -111,16 +75,26 @@ export class Huri<T extends XyoPayload = XyoPayload> {
|
|
|
111
75
|
return parts.join('/')
|
|
112
76
|
}
|
|
113
77
|
|
|
114
|
-
|
|
115
|
-
return
|
|
78
|
+
static async fetch<T extends XyoPayload = XyoPayload>(huri: Huri): Promise<T | undefined> {
|
|
79
|
+
return (await axios.get<T>(huri.href)).data
|
|
116
80
|
}
|
|
117
81
|
|
|
118
|
-
public
|
|
119
|
-
|
|
82
|
+
public static isHuri(value: unknown) {
|
|
83
|
+
if (typeof value === 'object') {
|
|
84
|
+
return (value as Huri).isHuri ? (value as Huri) : undefined
|
|
85
|
+
}
|
|
86
|
+
return undefined
|
|
120
87
|
}
|
|
121
88
|
|
|
122
|
-
static
|
|
123
|
-
|
|
89
|
+
private static parsePath(huri: string) {
|
|
90
|
+
const protocolSplit = huri.split('//')
|
|
91
|
+
assertEx(protocolSplit.length <= 2, `Invalid format [${huri}]`)
|
|
92
|
+
if (protocolSplit.length === 1) {
|
|
93
|
+
return huri
|
|
94
|
+
}
|
|
95
|
+
if (protocolSplit.length === 2) {
|
|
96
|
+
return protocolSplit[1]
|
|
97
|
+
}
|
|
124
98
|
}
|
|
125
99
|
|
|
126
100
|
private static parseProtocol(huri: string) {
|
|
@@ -135,21 +109,46 @@ export class Huri<T extends XyoPayload = XyoPayload> {
|
|
|
135
109
|
}
|
|
136
110
|
}
|
|
137
111
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
assertEx(protocolSplit.length <= 2, `Invalid format [${huri}]`)
|
|
141
|
-
if (protocolSplit.length === 1) {
|
|
142
|
-
return huri
|
|
143
|
-
}
|
|
144
|
-
if (protocolSplit.length === 2) {
|
|
145
|
-
return protocolSplit[1]
|
|
146
|
-
}
|
|
112
|
+
public async fetch(): Promise<T | undefined> {
|
|
113
|
+
return await Huri.fetch<T>(this)
|
|
147
114
|
}
|
|
148
115
|
|
|
149
|
-
public
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
116
|
+
public toString() {
|
|
117
|
+
return this.href
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private parsePath(path: string, hasProtocol: boolean) {
|
|
121
|
+
const pathParts = path.split('/')
|
|
122
|
+
|
|
123
|
+
//if the protocol was found, then there is not allowed to be a leading /
|
|
124
|
+
assertEx(!(hasProtocol && pathParts[0].length === 0), 'Invalid protocol separator')
|
|
125
|
+
|
|
126
|
+
//remove leading '/' if needed
|
|
127
|
+
pathParts[0].length === 0 ? pathParts.shift() : null
|
|
128
|
+
|
|
129
|
+
//hash is assumed to be the last part
|
|
130
|
+
const hash = assertEx(pathParts.pop(), 'No hash specified')
|
|
131
|
+
|
|
132
|
+
//archivist is assumed to be the first part
|
|
133
|
+
this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'
|
|
134
|
+
|
|
135
|
+
//the archive is whatever is left
|
|
136
|
+
this.archive = pathParts.pop()
|
|
137
|
+
|
|
138
|
+
//after we pull off all the path parts, there should be nothing left
|
|
139
|
+
assertEx(pathParts.length === 0, 'Too many path parts')
|
|
140
|
+
|
|
141
|
+
return hash
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private validateParse() {
|
|
145
|
+
//the archivist should not be zero length
|
|
146
|
+
assertEx(this.archivist?.length !== 0, 'Invalid archivist length')
|
|
147
|
+
|
|
148
|
+
//the archivist should not be zero length (can be undefined)
|
|
149
|
+
assertEx(this.archive?.length !== 0, 'Invalid archive length')
|
|
150
|
+
|
|
151
|
+
//the archive should not be set if the archivist is not set
|
|
152
|
+
assertEx(!(this.archive && !this.archivist), 'If specifying archive, archivist is also required')
|
|
154
153
|
}
|
|
155
154
|
}
|
package/src/Wrapper/Wrapper.ts
CHANGED
|
@@ -7,27 +7,35 @@ import { XyoPayload } from '../models'
|
|
|
7
7
|
import { PayloadValidator } from '../Validator'
|
|
8
8
|
|
|
9
9
|
export abstract class PayloadWrapperBase<TPayload extends XyoPayload = XyoPayload> extends Hasher<TPayload> {
|
|
10
|
+
public get body() {
|
|
11
|
+
return deepOmitUnderscoreFields<TPayload>(this.obj)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get errors() {
|
|
15
|
+
return new PayloadValidator(this.payload).validate()
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
public get payload() {
|
|
11
19
|
return assertEx(this.obj, 'Missing payload object')
|
|
12
20
|
}
|
|
13
21
|
|
|
22
|
+
public get previousHash() {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public get schema() {
|
|
27
|
+
return this.payload.schema
|
|
28
|
+
}
|
|
29
|
+
|
|
14
30
|
//intentionally not naming this 'schema' so that the wrapper is not confused for a XyoPayload
|
|
15
31
|
public get schemaName() {
|
|
16
32
|
return assertEx(this.obj.schema, 'Missing payload schema')
|
|
17
33
|
}
|
|
18
34
|
|
|
19
|
-
public get body() {
|
|
20
|
-
return deepOmitUnderscoreFields<TPayload>(this.obj)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
35
|
get valid() {
|
|
24
36
|
return this.errors.length === 0
|
|
25
37
|
}
|
|
26
38
|
|
|
27
|
-
get errors() {
|
|
28
|
-
return new PayloadValidator(this.payload).validate()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
39
|
public static load(_address: XyoDataLike | Huri): Promisable<PayloadWrapperBase | null> {
|
|
32
40
|
throw Error('Not implemented')
|
|
33
41
|
}
|
|
@@ -45,14 +53,6 @@ export class PayloadWrapper<TPayload extends XyoPayload = XyoPayload> extends Pa
|
|
|
45
53
|
return payload ? new PayloadWrapper(payload) : null
|
|
46
54
|
}
|
|
47
55
|
|
|
48
|
-
public get previousHash() {
|
|
49
|
-
return null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public get schema() {
|
|
53
|
-
return this.payload.schema
|
|
54
|
-
}
|
|
55
|
-
|
|
56
56
|
public static override parse<T extends XyoPayload = XyoPayload>(obj: unknown): PayloadWrapper<T> {
|
|
57
57
|
assertEx(!Array.isArray(obj), 'Array can not be converted to PayloadWrapper')
|
|
58
58
|
switch (typeof obj) {
|