@xyo-network/payload 2.35.0 → 2.36.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/Huri/Huri.js +12 -12
- package/dist/cjs/Wrapper/Wrapper.d.ts +3 -2
- package/dist/cjs/Wrapper/Wrapper.d.ts.map +1 -1
- package/dist/cjs/Wrapper/Wrapper.js +19 -4
- package/dist/cjs/Wrapper/Wrapper.js.map +1 -1
- package/dist/docs.json +800 -425
- package/dist/esm/Huri/Huri.js +1 -1
- package/dist/esm/Wrapper/Wrapper.d.ts +3 -2
- package/dist/esm/Wrapper/Wrapper.d.ts.map +1 -1
- package/dist/esm/Wrapper/Wrapper.js +17 -5
- package/dist/esm/Wrapper/Wrapper.js.map +1 -1
- package/package.json +5 -4
- package/src/Huri/Huri.spec.ts +1 -1
- package/src/Huri/Huri.ts +1 -1
- package/src/Wrapper/Wrapper.ts +20 -6
package/dist/cjs/Huri/Huri.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Huri = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const assert_1 = require("@xylabs/assert");
|
|
6
6
|
const account_1 = require("@xyo-network/account");
|
|
7
7
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
8
8
|
class Huri {
|
|
@@ -13,7 +13,7 @@ class Huri {
|
|
|
13
13
|
this.originalHref = huriString;
|
|
14
14
|
const protocol = Huri.parseProtocol(huriString);
|
|
15
15
|
this.protocol = protocol !== null && protocol !== void 0 ? protocol : 'https';
|
|
16
|
-
const path = (0,
|
|
16
|
+
const path = (0, assert_1.assertEx)(Huri.parsePath(huriString), 'Missing path');
|
|
17
17
|
this.hash = this.parsePath(path, protocol !== undefined);
|
|
18
18
|
//if archivistUri sent, overwrite protocol and archivist
|
|
19
19
|
if (archivistUri) {
|
|
@@ -27,27 +27,27 @@ class Huri {
|
|
|
27
27
|
var _a;
|
|
28
28
|
const pathParts = path.split('/');
|
|
29
29
|
//if the protocol was found, then there is not allowed to be a leading /
|
|
30
|
-
(0,
|
|
30
|
+
(0, assert_1.assertEx)(!(hasProtocol && pathParts[0].length === 0), 'Invalid protocol separator');
|
|
31
31
|
//remove leading '/' if needed
|
|
32
32
|
pathParts[0].length === 0 ? pathParts.shift() : null;
|
|
33
33
|
//hash is assumed to be the last part
|
|
34
|
-
const hash = (0,
|
|
34
|
+
const hash = (0, assert_1.assertEx)(pathParts.pop(), 'No hash specified');
|
|
35
35
|
//archivist is assumed to be the first part
|
|
36
36
|
this.archivist = (_a = pathParts.shift()) !== null && _a !== void 0 ? _a : 'api.archivist.xyo.network';
|
|
37
37
|
//the archive is whatever is left
|
|
38
38
|
this.archive = pathParts.pop();
|
|
39
39
|
//after we pull off all the path parts, there should be nothing left
|
|
40
|
-
(0,
|
|
40
|
+
(0, assert_1.assertEx)(pathParts.length === 0, 'Too many path parts');
|
|
41
41
|
return hash;
|
|
42
42
|
}
|
|
43
43
|
validateParse() {
|
|
44
44
|
var _a, _b;
|
|
45
45
|
//the archivist should not be zero length
|
|
46
|
-
(0,
|
|
46
|
+
(0, assert_1.assertEx)(((_a = this.archivist) === null || _a === void 0 ? void 0 : _a.length) !== 0, 'Invalid archivist length');
|
|
47
47
|
//the archivist should not be zero length (can be undefined)
|
|
48
|
-
(0,
|
|
48
|
+
(0, assert_1.assertEx)(((_b = this.archive) === null || _b === void 0 ? void 0 : _b.length) !== 0, 'Invalid archive length');
|
|
49
49
|
//the archive should not be set if the archivist is not set
|
|
50
|
-
(0,
|
|
50
|
+
(0, assert_1.assertEx)(!(this.archive && !this.archivist), 'If specifying archive, archivist is also required');
|
|
51
51
|
}
|
|
52
52
|
/*
|
|
53
53
|
The full href or the hash
|
|
@@ -81,18 +81,18 @@ class Huri {
|
|
|
81
81
|
}
|
|
82
82
|
static parseProtocol(huri) {
|
|
83
83
|
const protocolSplit = huri.split('//');
|
|
84
|
-
(0,
|
|
84
|
+
(0, assert_1.assertEx)(protocolSplit.length <= 2, `Invalid second protocol [${protocolSplit[2]}]`);
|
|
85
85
|
const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined;
|
|
86
86
|
if (rawProtocol) {
|
|
87
87
|
const protocolParts = rawProtocol === null || rawProtocol === void 0 ? void 0 : rawProtocol.split(':');
|
|
88
|
-
(0,
|
|
89
|
-
(0,
|
|
88
|
+
(0, assert_1.assertEx)(protocolParts.length === 2, `Invalid protocol format [${rawProtocol}]`);
|
|
89
|
+
(0, assert_1.assertEx)(protocolParts[1].length === 0, `Invalid protocol format (post :) [${rawProtocol}]`);
|
|
90
90
|
return protocolParts.shift();
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
static parsePath(huri) {
|
|
94
94
|
const protocolSplit = huri.split('//');
|
|
95
|
-
(0,
|
|
95
|
+
(0, assert_1.assertEx)(protocolSplit.length <= 2, `Invalid format [${huri}]`);
|
|
96
96
|
if (protocolSplit.length === 1) {
|
|
97
97
|
return huri;
|
|
98
98
|
}
|
|
@@ -2,15 +2,16 @@ import { Hasher, XyoDataLike } from '@xyo-network/core';
|
|
|
2
2
|
import { Huri } from '../Huri';
|
|
3
3
|
import { XyoPayload } from '../models';
|
|
4
4
|
export declare class PayloadWrapper<T extends XyoPayload = XyoPayload> extends Hasher<T> {
|
|
5
|
+
private isPayloadWrapper;
|
|
5
6
|
get payload(): T;
|
|
7
|
+
get schemaName(): string;
|
|
6
8
|
get body(): T;
|
|
7
9
|
get valid(): boolean;
|
|
8
10
|
get errors(): Error[];
|
|
9
|
-
/** @deprecated - meta fields not supported by client anymore */
|
|
10
|
-
get meta(): T;
|
|
11
11
|
static load(address: XyoDataLike | Huri): Promise<PayloadWrapper<import("../models").SchemaFields & import("../models").PayloadFields & {
|
|
12
12
|
schema: string;
|
|
13
13
|
}> | undefined>;
|
|
14
|
+
static parse<T extends XyoPayload = XyoPayload>(obj: unknown): PayloadWrapper<T>;
|
|
14
15
|
}
|
|
15
16
|
/** @deprecated use PayloadWrapper instead */
|
|
16
17
|
export declare class XyoPayloadWrapper<T extends XyoPayload = XyoPayload> extends PayloadWrapper<T> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../../src/Wrapper/Wrapper.ts"],"names":[],"mappings":"
|
|
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;AAEjF,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAGtC,qBAAa,cAAc,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;IAC9E,OAAO,CAAC,gBAAgB,CAAO;IAE/B,IAAW,OAAO,MAEjB;IAGD,IAAW,UAAU,WAEpB;IAED,IAAW,IAAI,MAEd;IAED,IAAI,KAAK,YAER;IAED,IAAI,MAAM,YAET;WAEmB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;;;WAOtC,KAAK,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,GAAG,EAAE,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC;CAUxF;AAED,6CAA6C;AAC7C,qBAAa,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;CAAG"}
|
|
@@ -2,13 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.XyoPayloadWrapper = exports.PayloadWrapper = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const assert_1 = require("@xylabs/assert");
|
|
5
6
|
const core_1 = require("@xyo-network/core");
|
|
6
7
|
const Huri_1 = require("../Huri");
|
|
7
8
|
const Validator_1 = require("../Validator");
|
|
8
9
|
class PayloadWrapper extends core_1.Hasher {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.isPayloadWrapper = true;
|
|
13
|
+
}
|
|
9
14
|
get payload() {
|
|
10
15
|
return this.obj;
|
|
11
16
|
}
|
|
17
|
+
//intentionally not naming this 'schema' so that the wrapper is not confused for a XyoPayload
|
|
18
|
+
get schemaName() {
|
|
19
|
+
return this.obj.schema;
|
|
20
|
+
}
|
|
12
21
|
get body() {
|
|
13
22
|
return (0, core_1.deepOmitUnderscoreFields)(this.obj);
|
|
14
23
|
}
|
|
@@ -18,10 +27,6 @@ class PayloadWrapper extends core_1.Hasher {
|
|
|
18
27
|
get errors() {
|
|
19
28
|
return new Validator_1.PayloadValidator(this.payload).validate();
|
|
20
29
|
}
|
|
21
|
-
/** @deprecated - meta fields not supported by client anymore */
|
|
22
|
-
get meta() {
|
|
23
|
-
return (0, core_1.deepPickUnderscoreFields)(this.obj);
|
|
24
|
-
}
|
|
25
30
|
static load(address) {
|
|
26
31
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
27
32
|
const payload = yield new Huri_1.Huri(address).fetch();
|
|
@@ -30,6 +35,16 @@ class PayloadWrapper extends core_1.Hasher {
|
|
|
30
35
|
}
|
|
31
36
|
});
|
|
32
37
|
}
|
|
38
|
+
static parse(obj) {
|
|
39
|
+
(0, assert_1.assertEx)(!Array.isArray(obj), 'Array can not be converted to PayloadWrapper');
|
|
40
|
+
switch (typeof obj) {
|
|
41
|
+
case 'object': {
|
|
42
|
+
const castWrapper = obj;
|
|
43
|
+
return (castWrapper === null || castWrapper === void 0 ? void 0 : castWrapper.isPayloadWrapper) ? castWrapper : new PayloadWrapper(obj);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw Error(`Unable to parse [${typeof obj}]`);
|
|
47
|
+
}
|
|
33
48
|
}
|
|
34
49
|
exports.PayloadWrapper = PayloadWrapper;
|
|
35
50
|
/** @deprecated use PayloadWrapper instead */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wrapper.js","sourceRoot":"","sources":["../../../src/Wrapper/Wrapper.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"Wrapper.js","sourceRoot":"","sources":["../../../src/Wrapper/Wrapper.ts"],"names":[],"mappings":";;;;AAAA,2CAAyC;AACzC,4CAAiF;AAEjF,kCAA8B;AAE9B,4CAA+C;AAE/C,MAAa,cAAkD,SAAQ,aAAS;IAAhF;;QACU,qBAAgB,GAAG,IAAI,CAAA;IAwCjC,CAAC;IAtCC,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,GAAG,CAAA;IACjB,CAAC;IAED,6FAA6F;IAC7F,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAA;IACxB,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAA,+BAAwB,EAAI,IAAI,CAAC,GAAG,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAA;IACjC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,4BAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAA;IACtD,CAAC;IAEM,MAAM,CAAO,IAAI,CAAC,OAA2B;;YAClD,MAAM,OAAO,GAAG,MAAM,IAAI,WAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAA;YAC/C,IAAI,OAAO,EAAE;gBACX,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAA;aACnC;QACH,CAAC;KAAA;IAEM,MAAM,CAAC,KAAK,CAAoC,GAAY;QACjE,IAAA,iBAAQ,EAAC,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,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,gBAAgB,EAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,GAAQ,CAAC,CAAA;aAClF;SACF;QACD,MAAM,KAAK,CAAC,oBAAoB,OAAO,GAAG,GAAG,CAAC,CAAA;IAChD,CAAC;CACF;AAzCD,wCAyCC;AAED,6CAA6C;AAC7C,MAAa,iBAAqD,SAAQ,cAAiB;CAAG;AAA9F,8CAA8F"}
|