@xyo-network/huri 2.111.3 → 3.0.1
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/browser/index.d.ts +37 -2
- package/dist/neutral/index.d.ts +37 -2
- package/dist/node/index.d.ts +37 -2
- package/dist/node/index.mjs +4 -6
- package/dist/node/index.mjs.map +1 -1
- package/package.json +13 -32
- package/dist/browser/Huri.d.cts +0 -34
- package/dist/browser/Huri.d.cts.map +0 -1
- package/dist/browser/Huri.d.mts +0 -34
- package/dist/browser/Huri.d.mts.map +0 -1
- package/dist/browser/Huri.d.ts +0 -34
- package/dist/browser/Huri.d.ts.map +0 -1
- package/dist/browser/index.cjs +0 -125
- package/dist/browser/index.cjs.map +0 -1
- package/dist/browser/index.d.cts +0 -2
- package/dist/browser/index.d.cts.map +0 -1
- package/dist/browser/index.d.mts +0 -2
- package/dist/browser/index.d.mts.map +0 -1
- package/dist/browser/index.d.ts.map +0 -1
- package/dist/neutral/Huri.d.cts +0 -34
- package/dist/neutral/Huri.d.cts.map +0 -1
- package/dist/neutral/Huri.d.mts +0 -34
- package/dist/neutral/Huri.d.mts.map +0 -1
- package/dist/neutral/Huri.d.ts +0 -34
- package/dist/neutral/Huri.d.ts.map +0 -1
- package/dist/neutral/index.cjs +0 -125
- package/dist/neutral/index.cjs.map +0 -1
- package/dist/neutral/index.d.cts +0 -2
- package/dist/neutral/index.d.cts.map +0 -1
- package/dist/neutral/index.d.mts +0 -2
- package/dist/neutral/index.d.mts.map +0 -1
- package/dist/neutral/index.d.ts.map +0 -1
- package/dist/node/Huri.d.cts +0 -34
- package/dist/node/Huri.d.cts.map +0 -1
- package/dist/node/Huri.d.mts +0 -34
- package/dist/node/Huri.d.mts.map +0 -1
- package/dist/node/Huri.d.ts +0 -34
- package/dist/node/Huri.d.ts.map +0 -1
- package/dist/node/index.cjs +0 -131
- package/dist/node/index.cjs.map +0 -1
- package/dist/node/index.d.cts +0 -2
- package/dist/node/index.d.cts.map +0 -1
- package/dist/node/index.d.mts +0 -2
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.d.ts.map +0 -1
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as _xyo_network_payload_model from '@xyo-network/payload-model';
|
|
2
|
+
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
+
import { Address, Hash } from '@xylabs/hex';
|
|
4
|
+
|
|
5
|
+
type ObjectCategory = 'block' | 'payload';
|
|
6
|
+
type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
7
|
+
interface HuriOptions {
|
|
8
|
+
archivistUri?: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
}
|
|
11
|
+
interface FetchedPayload<T extends Payload = Payload> {
|
|
12
|
+
huri?: Huri;
|
|
13
|
+
payload: T;
|
|
14
|
+
}
|
|
15
|
+
declare class Huri<T extends Payload = Payload> {
|
|
16
|
+
archive?: string;
|
|
17
|
+
archivist?: Address | string;
|
|
18
|
+
hash: Hash;
|
|
19
|
+
originalHref: string;
|
|
20
|
+
protocol?: string;
|
|
21
|
+
token?: string;
|
|
22
|
+
private isHuri;
|
|
23
|
+
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
24
|
+
get href(): string;
|
|
25
|
+
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
26
|
+
static isHuri(value: unknown): Huri<{
|
|
27
|
+
schema: string;
|
|
28
|
+
} & _xyo_network_payload_model.PayloadFields> | undefined;
|
|
29
|
+
private static parsePath;
|
|
30
|
+
private static parseProtocol;
|
|
31
|
+
fetch(): Promise<T | undefined>;
|
|
32
|
+
toString(): string;
|
|
33
|
+
private parsePath;
|
|
34
|
+
private validateParse;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { type FetchedPayload, Huri, type HuriFetchFunction, type HuriOptions, type ObjectCategory };
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as _xyo_network_payload_model from '@xyo-network/payload-model';
|
|
2
|
+
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
+
import { Address, Hash } from '@xylabs/hex';
|
|
4
|
+
|
|
5
|
+
type ObjectCategory = 'block' | 'payload';
|
|
6
|
+
type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
7
|
+
interface HuriOptions {
|
|
8
|
+
archivistUri?: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
}
|
|
11
|
+
interface FetchedPayload<T extends Payload = Payload> {
|
|
12
|
+
huri?: Huri;
|
|
13
|
+
payload: T;
|
|
14
|
+
}
|
|
15
|
+
declare class Huri<T extends Payload = Payload> {
|
|
16
|
+
archive?: string;
|
|
17
|
+
archivist?: Address | string;
|
|
18
|
+
hash: Hash;
|
|
19
|
+
originalHref: string;
|
|
20
|
+
protocol?: string;
|
|
21
|
+
token?: string;
|
|
22
|
+
private isHuri;
|
|
23
|
+
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
24
|
+
get href(): string;
|
|
25
|
+
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
26
|
+
static isHuri(value: unknown): Huri<{
|
|
27
|
+
schema: string;
|
|
28
|
+
} & _xyo_network_payload_model.PayloadFields> | undefined;
|
|
29
|
+
private static parsePath;
|
|
30
|
+
private static parseProtocol;
|
|
31
|
+
fetch(): Promise<T | undefined>;
|
|
32
|
+
toString(): string;
|
|
33
|
+
private parsePath;
|
|
34
|
+
private validateParse;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { type FetchedPayload, Huri, type HuriFetchFunction, type HuriOptions, type ObjectCategory };
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as _xyo_network_payload_model from '@xyo-network/payload-model';
|
|
2
|
+
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
+
import { Address, Hash } from '@xylabs/hex';
|
|
4
|
+
|
|
5
|
+
type ObjectCategory = 'block' | 'payload';
|
|
6
|
+
type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
7
|
+
interface HuriOptions {
|
|
8
|
+
archivistUri?: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
}
|
|
11
|
+
interface FetchedPayload<T extends Payload = Payload> {
|
|
12
|
+
huri?: Huri;
|
|
13
|
+
payload: T;
|
|
14
|
+
}
|
|
15
|
+
declare class Huri<T extends Payload = Payload> {
|
|
16
|
+
archive?: string;
|
|
17
|
+
archivist?: Address | string;
|
|
18
|
+
hash: Hash;
|
|
19
|
+
originalHref: string;
|
|
20
|
+
protocol?: string;
|
|
21
|
+
token?: string;
|
|
22
|
+
private isHuri;
|
|
23
|
+
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
24
|
+
get href(): string;
|
|
25
|
+
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
26
|
+
static isHuri(value: unknown): Huri<{
|
|
27
|
+
schema: string;
|
|
28
|
+
} & _xyo_network_payload_model.PayloadFields> | undefined;
|
|
29
|
+
private static parsePath;
|
|
30
|
+
private static parseProtocol;
|
|
31
|
+
fetch(): Promise<T | undefined>;
|
|
32
|
+
toString(): string;
|
|
33
|
+
private parsePath;
|
|
34
|
+
private validateParse;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { type FetchedPayload, Huri, type HuriFetchFunction, type HuriOptions, type ObjectCategory };
|
package/dist/node/index.mjs
CHANGED
|
@@ -12,8 +12,7 @@ var Huri = class _Huri {
|
|
|
12
12
|
token;
|
|
13
13
|
isHuri = true;
|
|
14
14
|
constructor(huri, { archivistUri, token } = {}) {
|
|
15
|
-
|
|
16
|
-
const huriString = ((_a = _Huri.isHuri(huri)) == null ? void 0 : _a.href) ?? (typeof huri === "string" ? huri : huri instanceof ArrayBuffer ? new AddressValue(huri).hex : huri.href);
|
|
15
|
+
const huriString = _Huri.isHuri(huri)?.href ?? (typeof huri === "string" ? huri : huri instanceof ArrayBuffer ? new AddressValue(huri).hex : huri.href);
|
|
17
16
|
this.originalHref = huriString;
|
|
18
17
|
const protocol = _Huri.parseProtocol(huriString);
|
|
19
18
|
this.protocol = protocol ?? "https";
|
|
@@ -69,7 +68,7 @@ var Huri = class _Huri {
|
|
|
69
68
|
assertEx(protocolSplit.length <= 2, () => `Invalid second protocol [${protocolSplit[2]}]`);
|
|
70
69
|
const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : void 0;
|
|
71
70
|
if (rawProtocol) {
|
|
72
|
-
const protocolParts = rawProtocol
|
|
71
|
+
const protocolParts = rawProtocol?.split(":");
|
|
73
72
|
assertEx(protocolParts.length === 2, () => `Invalid protocol format [${rawProtocol}]`);
|
|
74
73
|
assertEx(protocolParts[1].length === 0, () => `Invalid protocol format (post :) [${rawProtocol}]`);
|
|
75
74
|
return protocolParts.shift();
|
|
@@ -92,9 +91,8 @@ var Huri = class _Huri {
|
|
|
92
91
|
return hash;
|
|
93
92
|
}
|
|
94
93
|
validateParse() {
|
|
95
|
-
|
|
96
|
-
assertEx(
|
|
97
|
-
assertEx(((_b = this.archive) == null ? void 0 : _b.length) !== 0, () => "Invalid archive length");
|
|
94
|
+
assertEx(this.archivist?.length !== 0, () => "Invalid archivist length");
|
|
95
|
+
assertEx(this.archive?.length !== 0, () => "Invalid archive length");
|
|
98
96
|
assertEx(!(this.archive && !this.archivist), () => "If specifying archive, archivist is also required");
|
|
99
97
|
}
|
|
100
98
|
};
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Huri.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport { Address, Hash, isHash } from '@xylabs/hex'\nimport { AddressValue } from '@xyo-network/account'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type ObjectCategory = 'block' | 'payload'\n\nexport type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>\n\n/*\n Valid Huri:\n\n [<protocol>://][<archivist>/[<archive>/]]<hash>\n\n defaults:\n protocol: https\n archivist: api.archivist.xyo.network\n*/\n\nexport interface HuriOptions {\n archivistUri?: string\n token?: string\n}\n\nexport interface FetchedPayload<T extends Payload = Payload> {\n huri?: Huri\n payload: T\n}\n\nexport class Huri<T extends Payload = Payload> {\n archive?: string\n archivist?: Address | string\n hash: Hash\n originalHref: string\n protocol?: string\n token?: string\n\n private isHuri = true\n\n constructor(huri: Hash | Huri | string, { archivistUri, token }: HuriOptions = {}) {\n const huriString\n = Huri.isHuri(huri)?.href\n ?? (typeof huri === 'string'\n ? (huri as string)\n : huri instanceof ArrayBuffer\n ? new AddressValue(huri).hex\n : huri.href)\n this.originalHref = huriString\n\n const protocol = Huri.parseProtocol(huriString)\n this.protocol = protocol ?? 'https'\n\n const path = assertEx(Huri.parsePath(huriString), () => 'Missing path')\n this.hash = assertEx(this.parsePath(path, protocol !== undefined), () => 'Missing hash') as Hash\n\n assertEx(isHash(this.hash), () => `Invalid hash [${this.hash}]`)\n\n // if archivistUri sent, overwrite protocol and archivist\n if (archivistUri) {\n const archivistUriParts = archivistUri.split('://')\n this.protocol = archivistUriParts[0]\n this.archivist = archivistUriParts[1]\n }\n\n this.token = token\n\n this.validateParse()\n }\n\n /*\n The full href or the hash\n */\n get href() {\n const parts: string[] = []\n if (this.protocol) {\n parts.push(`${this.protocol}:/`)\n }\n if (this.archive) {\n parts.push(`${this.archive}`)\n }\n if (this.archivist) {\n parts.push(`${this.archivist}`)\n }\n parts.push(this.hash)\n return parts.join('/')\n }\n\n static async fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined> {\n const AuthHeader = huri.token ? { Authorization: `Bearer ${huri.token}` } : undefined\n return (await axios.get<T>(huri.href, { headers: AuthHeader })).data\n }\n\n static isHuri(value: unknown) {\n if (typeof value === 'object') {\n return (value as Huri).isHuri ? (value as Huri) : undefined\n }\n }\n\n private static parsePath(huri: string) {\n const protocolSplit = huri.split('//')\n assertEx(protocolSplit.length <= 2, () => `Invalid format [${huri}]`)\n if (protocolSplit.length === 1) {\n return huri\n }\n if (protocolSplit.length === 2) {\n return protocolSplit[1]\n }\n }\n\n private static parseProtocol(huri: string) {\n const protocolSplit = huri.split('//')\n assertEx(protocolSplit.length <= 2, () => `Invalid second protocol [${protocolSplit[2]}]`)\n const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined\n if (rawProtocol) {\n const protocolParts = rawProtocol?.split(':')\n assertEx(protocolParts.length === 2, () => `Invalid protocol format [${rawProtocol}]`)\n assertEx(protocolParts[1].length === 0, () => `Invalid protocol format (post :) [${rawProtocol}]`)\n return protocolParts.shift()\n }\n }\n\n async fetch(): Promise<T | undefined> {\n return await Huri.fetch<T>(this)\n }\n\n toString() {\n return this.href\n }\n\n private parsePath(path: string, hasProtocol: boolean) {\n const pathParts = path.split('/')\n\n // if the protocol was found, then there is not allowed to be a leading /\n assertEx(!(hasProtocol && pathParts[0].length === 0), () => 'Invalid protocol separator')\n\n // remove leading '/' if needed\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n pathParts[0].length === 0 ? pathParts.shift() : null\n\n // hash is assumed to be the last part\n const hash = assertEx(pathParts.pop(), () => 'No hash specified')\n\n // archivist is assumed to be the first part\n this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'\n\n // the archive is whatever is left\n this.archive = pathParts.pop()\n\n // after we pull off all the path parts, there should be nothing left\n assertEx(pathParts.length === 0, () => 'Too many path parts')\n\n return hash\n }\n\n private validateParse() {\n // the archivist should not be zero length\n assertEx(this.archivist?.length !== 0, () => 'Invalid archivist length')\n\n // the archivist should not be zero length (can be undefined)\n assertEx(this.archive?.length !== 0, () => 'Invalid archive length')\n\n // the archive should not be set if the archivist is not set\n assertEx(!(this.archive && !this.archivist), () => 'If specifying archive, archivist is also required')\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,aAAa;AACtB,SAAwB,cAAc;AACtC,SAAS,oBAAoB;AA2BtB,IAAM,OAAN,MAAM,MAAkC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEQ,SAAS;AAAA,EAEjB,YAAY,MAA4B,EAAE,cAAc,MAAM,IAAiB,CAAC,GAAG;
|
|
1
|
+
{"version":3,"sources":["../../src/Huri.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport { Address, Hash, isHash } from '@xylabs/hex'\nimport { AddressValue } from '@xyo-network/account'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type ObjectCategory = 'block' | 'payload'\n\nexport type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>\n\n/*\n Valid Huri:\n\n [<protocol>://][<archivist>/[<archive>/]]<hash>\n\n defaults:\n protocol: https\n archivist: api.archivist.xyo.network\n*/\n\nexport interface HuriOptions {\n archivistUri?: string\n token?: string\n}\n\nexport interface FetchedPayload<T extends Payload = Payload> {\n huri?: Huri\n payload: T\n}\n\nexport class Huri<T extends Payload = Payload> {\n archive?: string\n archivist?: Address | string\n hash: Hash\n originalHref: string\n protocol?: string\n token?: string\n\n private isHuri = true\n\n constructor(huri: Hash | Huri | string, { archivistUri, token }: HuriOptions = {}) {\n const huriString\n = Huri.isHuri(huri)?.href\n ?? (typeof huri === 'string'\n ? (huri as string)\n : huri instanceof ArrayBuffer\n ? new AddressValue(huri).hex\n : huri.href)\n this.originalHref = huriString\n\n const protocol = Huri.parseProtocol(huriString)\n this.protocol = protocol ?? 'https'\n\n const path = assertEx(Huri.parsePath(huriString), () => 'Missing path')\n this.hash = assertEx(this.parsePath(path, protocol !== undefined), () => 'Missing hash') as Hash\n\n assertEx(isHash(this.hash), () => `Invalid hash [${this.hash}]`)\n\n // if archivistUri sent, overwrite protocol and archivist\n if (archivistUri) {\n const archivistUriParts = archivistUri.split('://')\n this.protocol = archivistUriParts[0]\n this.archivist = archivistUriParts[1]\n }\n\n this.token = token\n\n this.validateParse()\n }\n\n /*\n The full href or the hash\n */\n get href() {\n const parts: string[] = []\n if (this.protocol) {\n parts.push(`${this.protocol}:/`)\n }\n if (this.archive) {\n parts.push(`${this.archive}`)\n }\n if (this.archivist) {\n parts.push(`${this.archivist}`)\n }\n parts.push(this.hash)\n return parts.join('/')\n }\n\n static async fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined> {\n const AuthHeader = huri.token ? { Authorization: `Bearer ${huri.token}` } : undefined\n return (await axios.get<T>(huri.href, { headers: AuthHeader })).data\n }\n\n static isHuri(value: unknown) {\n if (typeof value === 'object') {\n return (value as Huri).isHuri ? (value as Huri) : undefined\n }\n }\n\n private static parsePath(huri: string) {\n const protocolSplit = huri.split('//')\n assertEx(protocolSplit.length <= 2, () => `Invalid format [${huri}]`)\n if (protocolSplit.length === 1) {\n return huri\n }\n if (protocolSplit.length === 2) {\n return protocolSplit[1]\n }\n }\n\n private static parseProtocol(huri: string) {\n const protocolSplit = huri.split('//')\n assertEx(protocolSplit.length <= 2, () => `Invalid second protocol [${protocolSplit[2]}]`)\n const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined\n if (rawProtocol) {\n const protocolParts = rawProtocol?.split(':')\n assertEx(protocolParts.length === 2, () => `Invalid protocol format [${rawProtocol}]`)\n assertEx(protocolParts[1].length === 0, () => `Invalid protocol format (post :) [${rawProtocol}]`)\n return protocolParts.shift()\n }\n }\n\n async fetch(): Promise<T | undefined> {\n return await Huri.fetch<T>(this)\n }\n\n toString() {\n return this.href\n }\n\n private parsePath(path: string, hasProtocol: boolean) {\n const pathParts = path.split('/')\n\n // if the protocol was found, then there is not allowed to be a leading /\n assertEx(!(hasProtocol && pathParts[0].length === 0), () => 'Invalid protocol separator')\n\n // remove leading '/' if needed\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n pathParts[0].length === 0 ? pathParts.shift() : null\n\n // hash is assumed to be the last part\n const hash = assertEx(pathParts.pop(), () => 'No hash specified')\n\n // archivist is assumed to be the first part\n this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'\n\n // the archive is whatever is left\n this.archive = pathParts.pop()\n\n // after we pull off all the path parts, there should be nothing left\n assertEx(pathParts.length === 0, () => 'Too many path parts')\n\n return hash\n }\n\n private validateParse() {\n // the archivist should not be zero length\n assertEx(this.archivist?.length !== 0, () => 'Invalid archivist length')\n\n // the archivist should not be zero length (can be undefined)\n assertEx(this.archive?.length !== 0, () => 'Invalid archive length')\n\n // the archive should not be set if the archivist is not set\n assertEx(!(this.archive && !this.archivist), () => 'If specifying archive, archivist is also required')\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,aAAa;AACtB,SAAwB,cAAc;AACtC,SAAS,oBAAoB;AA2BtB,IAAM,OAAN,MAAM,MAAkC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEQ,SAAS;AAAA,EAEjB,YAAY,MAA4B,EAAE,cAAc,MAAM,IAAiB,CAAC,GAAG;AACjF,UAAM,aACF,MAAK,OAAO,IAAI,GAAG,SACjB,OAAO,SAAS,WACf,OACD,gBAAgB,cACd,IAAI,aAAa,IAAI,EAAE,MACvB,KAAK;AACb,SAAK,eAAe;AAEpB,UAAM,WAAW,MAAK,cAAc,UAAU;AAC9C,SAAK,WAAW,YAAY;AAE5B,UAAM,OAAO,SAAS,MAAK,UAAU,UAAU,GAAG,MAAM,cAAc;AACtE,SAAK,OAAO,SAAS,KAAK,UAAU,MAAM,aAAa,MAAS,GAAG,MAAM,cAAc;AAEvF,aAAS,OAAO,KAAK,IAAI,GAAG,MAAM,iBAAiB,KAAK,IAAI,GAAG;AAG/D,QAAI,cAAc;AAChB,YAAM,oBAAoB,aAAa,MAAM,KAAK;AAClD,WAAK,WAAW,kBAAkB,CAAC;AACnC,WAA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;AACf,YAAM,gBAAgB,aAAa,MAAM,GAAG;AAC5C,eAAS,cAAc,WAAW,GAAG,MAAM,4BAA4B,WAAW,GAAG;AACrF,eAAS,cAAc,CAAC,EAAE,WAAW,GAAG,MAAM,qCAAqC,WAAW,GAAG;AACjG,aAAO,cAAc,MAAM;AAAA,IAC7B;AAAA,EACF;AAAA,EAEA,MAAM,QAAgC;AACpC,WAAO,MAAM,MAAK,MAAS,IAAI;AAAA,EACjC;AAAA,EAEA,WAAW;AACT,WAAO,KAAK;AAAA,EACd;AAAA,EAEQ,UAAU,MAAc,aAAsB;AACpD,UAAM,YAAY,KAAK,MAAM,GAAG;AAGhC,aAAS,EAAE,eAAe,UAAU,CAAC,EAAE,WAAW,IAAI,MAAM,4BAA4B;AAIxF,cAAU,CAAC,EAAE,WAAW,IAAI,UAAU,MAAM,IAAI;AAGhD,UAAM,OAAO,SAAS,UAAU,IAAI,GAAG,MAAM,mBAAmB;AAGhE,SAAK,YAAY,UAAU,MAAM,KAAK;AAGtC,SAAK,UAAU,UAAU,IAAI;AAG7B,aAAS,UAAU,WAAW,GAAG,MAAM,qBAAqB;AAE5D,WAAO;AAAA,EACT;AAAA,EAEQ,gBAAgB;AAEtB,aAAS,KAAK,WAAW,WAAW,GAAG,MAAM,0BAA0B;AAGvE,aAAS,KAAK,SAAS,WAAW,GAAG,MAAM,wBAAwB;AAGnE,aAAS,EAAE,KAAK,WAAW,CAAC,KAAK,YAAY,MAAM,mDAAmD;AAAA,EACxG;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -10,46 +10,27 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/assert": "^
|
|
14
|
-
"@xylabs/axios": "^
|
|
15
|
-
"@xylabs/hex": "^
|
|
16
|
-
"@xyo-network/account": "^
|
|
17
|
-
"@xyo-network/payload-model": "^
|
|
13
|
+
"@xylabs/assert": "^4.0.0",
|
|
14
|
+
"@xylabs/axios": "^4.0.0",
|
|
15
|
+
"@xylabs/hex": "^4.0.0",
|
|
16
|
+
"@xyo-network/account": "^3.0.1",
|
|
17
|
+
"@xyo-network/payload-model": "^3.0.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@xylabs/delay": "^
|
|
21
|
-
"@xylabs/ts-scripts-yarn3": "^
|
|
22
|
-
"@xylabs/tsconfig": "^
|
|
20
|
+
"@xylabs/delay": "^4.0.0",
|
|
21
|
+
"@xylabs/ts-scripts-yarn3": "^4.0.0-rc.15",
|
|
22
|
+
"@xylabs/tsconfig": "^4.0.0-rc.15",
|
|
23
23
|
"typescript": "^5.5.4"
|
|
24
24
|
},
|
|
25
25
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
"types": "./dist/browser/index.d.cts",
|
|
31
|
-
"default": "./dist/browser/index.cjs"
|
|
32
|
-
},
|
|
33
|
-
"import": {
|
|
34
|
-
"types": "./dist/browser/index.d.mts",
|
|
35
|
-
"default": "./dist/browser/index.mjs"
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
"node": {
|
|
39
|
-
"require": {
|
|
40
|
-
"types": "./dist/node/index.d.cts",
|
|
41
|
-
"default": "./dist/node/index.cjs"
|
|
42
|
-
},
|
|
43
|
-
"import": {
|
|
44
|
-
"types": "./dist/node/index.d.mts",
|
|
45
|
-
"default": "./dist/node/index.mjs"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
28
|
+
"types": "./dist/neutral/index.d.ts",
|
|
29
|
+
"default": "./dist/neutral/index.mjs"
|
|
48
30
|
},
|
|
49
31
|
"./package.json": "./package.json"
|
|
50
32
|
},
|
|
51
|
-
"
|
|
52
|
-
"module": "dist/node/index.mjs",
|
|
33
|
+
"module": "dist/neutral/index.mjs",
|
|
53
34
|
"homepage": "https://xyo.network",
|
|
54
35
|
"license": "LGPL-3.0-only",
|
|
55
36
|
"publishConfig": {
|
|
@@ -60,7 +41,7 @@
|
|
|
60
41
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
61
42
|
},
|
|
62
43
|
"sideEffects": false,
|
|
63
|
-
"types": "dist/
|
|
64
|
-
"version": "
|
|
44
|
+
"types": "dist/neutral/index.d.ts",
|
|
45
|
+
"version": "3.0.1",
|
|
65
46
|
"type": "module"
|
|
66
47
|
}
|
package/dist/browser/Huri.d.cts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Address, Hash } from '@xylabs/hex';
|
|
2
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
export type ObjectCategory = 'block' | 'payload';
|
|
4
|
-
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
5
|
-
export interface HuriOptions {
|
|
6
|
-
archivistUri?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface FetchedPayload<T extends Payload = Payload> {
|
|
10
|
-
huri?: Huri;
|
|
11
|
-
payload: T;
|
|
12
|
-
}
|
|
13
|
-
export declare class Huri<T extends Payload = Payload> {
|
|
14
|
-
archive?: string;
|
|
15
|
-
archivist?: Address | string;
|
|
16
|
-
hash: Hash;
|
|
17
|
-
originalHref: string;
|
|
18
|
-
protocol?: string;
|
|
19
|
-
token?: string;
|
|
20
|
-
private isHuri;
|
|
21
|
-
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
|
-
get href(): string;
|
|
23
|
-
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
|
-
static isHuri(value: unknown): Huri<{
|
|
25
|
-
schema: string;
|
|
26
|
-
} & import("@xyo-network/payload-model").PayloadFields> | undefined;
|
|
27
|
-
private static parsePath;
|
|
28
|
-
private static parseProtocol;
|
|
29
|
-
fetch(): Promise<T | undefined>;
|
|
30
|
-
toString(): string;
|
|
31
|
-
private parsePath;
|
|
32
|
-
private validateParse;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Huri.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAU,MAAM,aAAa,CAAA;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,CAAA;AAEhD,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;AAY5E,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IACzD,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,EAAE,CAAC,CAAA;CACX;AAED,qBAAa,IAAI,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,OAAO,CAAC,MAAM,CAAO;gBAET,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,GAAE,WAAgB;IAiCjF,IAAI,IAAI,WAaP;WAEY,KAAK,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKnF,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO;;;IAM5B,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,aAAa;IAYtB,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrC,QAAQ;IAIR,OAAO,CAAC,SAAS;IAyBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/browser/Huri.d.mts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Address, Hash } from '@xylabs/hex';
|
|
2
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
export type ObjectCategory = 'block' | 'payload';
|
|
4
|
-
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
5
|
-
export interface HuriOptions {
|
|
6
|
-
archivistUri?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface FetchedPayload<T extends Payload = Payload> {
|
|
10
|
-
huri?: Huri;
|
|
11
|
-
payload: T;
|
|
12
|
-
}
|
|
13
|
-
export declare class Huri<T extends Payload = Payload> {
|
|
14
|
-
archive?: string;
|
|
15
|
-
archivist?: Address | string;
|
|
16
|
-
hash: Hash;
|
|
17
|
-
originalHref: string;
|
|
18
|
-
protocol?: string;
|
|
19
|
-
token?: string;
|
|
20
|
-
private isHuri;
|
|
21
|
-
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
|
-
get href(): string;
|
|
23
|
-
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
|
-
static isHuri(value: unknown): Huri<{
|
|
25
|
-
schema: string;
|
|
26
|
-
} & import("@xyo-network/payload-model").PayloadFields> | undefined;
|
|
27
|
-
private static parsePath;
|
|
28
|
-
private static parseProtocol;
|
|
29
|
-
fetch(): Promise<T | undefined>;
|
|
30
|
-
toString(): string;
|
|
31
|
-
private parsePath;
|
|
32
|
-
private validateParse;
|
|
33
|
-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E,OAAO;;;IAM5B,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,aAAa;IAYtB,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrC,QAAQ;IAIR,OAAO,CAAC,SAAS;IAyBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/browser/Huri.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Address, Hash } from '@xylabs/hex';
|
|
2
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
export type ObjectCategory = 'block' | 'payload';
|
|
4
|
-
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
5
|
-
export interface HuriOptions {
|
|
6
|
-
archivistUri?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface FetchedPayload<T extends Payload = Payload> {
|
|
10
|
-
huri?: Huri;
|
|
11
|
-
payload: T;
|
|
12
|
-
}
|
|
13
|
-
export declare class Huri<T extends Payload = Payload> {
|
|
14
|
-
archive?: string;
|
|
15
|
-
archivist?: Address | string;
|
|
16
|
-
hash: Hash;
|
|
17
|
-
originalHref: string;
|
|
18
|
-
protocol?: string;
|
|
19
|
-
token?: string;
|
|
20
|
-
private isHuri;
|
|
21
|
-
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
|
-
get href(): string;
|
|
23
|
-
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
|
-
static isHuri(value: unknown): Huri<{
|
|
25
|
-
schema: string;
|
|
26
|
-
} & import("@xyo-network/payload-model").PayloadFields> | undefined;
|
|
27
|
-
private static parsePath;
|
|
28
|
-
private static parseProtocol;
|
|
29
|
-
fetch(): Promise<T | undefined>;
|
|
30
|
-
toString(): string;
|
|
31
|
-
private parsePath;
|
|
32
|
-
private validateParse;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Huri.d.ts.map
|
|
@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IAWxB,OAAO,CAAC,MAAM,CAAC,aAAa;IAYtB,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrC,QAAQ;IAIR,OAAO,CAAC,SAAS;IAyBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/browser/index.cjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
Huri: () => Huri
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
|
|
27
|
-
// src/Huri.ts
|
|
28
|
-
var import_assert = require("@xylabs/assert");
|
|
29
|
-
var import_axios = require("@xylabs/axios");
|
|
30
|
-
var import_hex = require("@xylabs/hex");
|
|
31
|
-
var import_account = require("@xyo-network/account");
|
|
32
|
-
var Huri = class _Huri {
|
|
33
|
-
archive;
|
|
34
|
-
archivist;
|
|
35
|
-
hash;
|
|
36
|
-
originalHref;
|
|
37
|
-
protocol;
|
|
38
|
-
token;
|
|
39
|
-
isHuri = true;
|
|
40
|
-
constructor(huri, { archivistUri, token } = {}) {
|
|
41
|
-
const huriString = _Huri.isHuri(huri)?.href ?? (typeof huri === "string" ? huri : huri instanceof ArrayBuffer ? new import_account.AddressValue(huri).hex : huri.href);
|
|
42
|
-
this.originalHref = huriString;
|
|
43
|
-
const protocol = _Huri.parseProtocol(huriString);
|
|
44
|
-
this.protocol = protocol ?? "https";
|
|
45
|
-
const path = (0, import_assert.assertEx)(_Huri.parsePath(huriString), () => "Missing path");
|
|
46
|
-
this.hash = (0, import_assert.assertEx)(this.parsePath(path, protocol !== void 0), () => "Missing hash");
|
|
47
|
-
(0, import_assert.assertEx)((0, import_hex.isHash)(this.hash), () => `Invalid hash [${this.hash}]`);
|
|
48
|
-
if (archivistUri) {
|
|
49
|
-
const archivistUriParts = archivistUri.split("://");
|
|
50
|
-
this.protocol = archivistUriParts[0];
|
|
51
|
-
this.archivist = archivistUriParts[1];
|
|
52
|
-
}
|
|
53
|
-
this.token = token;
|
|
54
|
-
this.validateParse();
|
|
55
|
-
}
|
|
56
|
-
/*
|
|
57
|
-
The full href or the hash
|
|
58
|
-
*/
|
|
59
|
-
get href() {
|
|
60
|
-
const parts = [];
|
|
61
|
-
if (this.protocol) {
|
|
62
|
-
parts.push(`${this.protocol}:/`);
|
|
63
|
-
}
|
|
64
|
-
if (this.archive) {
|
|
65
|
-
parts.push(`${this.archive}`);
|
|
66
|
-
}
|
|
67
|
-
if (this.archivist) {
|
|
68
|
-
parts.push(`${this.archivist}`);
|
|
69
|
-
}
|
|
70
|
-
parts.push(this.hash);
|
|
71
|
-
return parts.join("/");
|
|
72
|
-
}
|
|
73
|
-
static async fetch(huri) {
|
|
74
|
-
const AuthHeader = huri.token ? { Authorization: `Bearer ${huri.token}` } : void 0;
|
|
75
|
-
return (await import_axios.axios.get(huri.href, { headers: AuthHeader })).data;
|
|
76
|
-
}
|
|
77
|
-
static isHuri(value) {
|
|
78
|
-
if (typeof value === "object") {
|
|
79
|
-
return value.isHuri ? value : void 0;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
static parsePath(huri) {
|
|
83
|
-
const protocolSplit = huri.split("//");
|
|
84
|
-
(0, import_assert.assertEx)(protocolSplit.length <= 2, () => `Invalid format [${huri}]`);
|
|
85
|
-
if (protocolSplit.length === 1) {
|
|
86
|
-
return huri;
|
|
87
|
-
}
|
|
88
|
-
if (protocolSplit.length === 2) {
|
|
89
|
-
return protocolSplit[1];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
static parseProtocol(huri) {
|
|
93
|
-
const protocolSplit = huri.split("//");
|
|
94
|
-
(0, import_assert.assertEx)(protocolSplit.length <= 2, () => `Invalid second protocol [${protocolSplit[2]}]`);
|
|
95
|
-
const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : void 0;
|
|
96
|
-
if (rawProtocol) {
|
|
97
|
-
const protocolParts = rawProtocol?.split(":");
|
|
98
|
-
(0, import_assert.assertEx)(protocolParts.length === 2, () => `Invalid protocol format [${rawProtocol}]`);
|
|
99
|
-
(0, import_assert.assertEx)(protocolParts[1].length === 0, () => `Invalid protocol format (post :) [${rawProtocol}]`);
|
|
100
|
-
return protocolParts.shift();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async fetch() {
|
|
104
|
-
return await _Huri.fetch(this);
|
|
105
|
-
}
|
|
106
|
-
toString() {
|
|
107
|
-
return this.href;
|
|
108
|
-
}
|
|
109
|
-
parsePath(path, hasProtocol) {
|
|
110
|
-
const pathParts = path.split("/");
|
|
111
|
-
(0, import_assert.assertEx)(!(hasProtocol && pathParts[0].length === 0), () => "Invalid protocol separator");
|
|
112
|
-
pathParts[0].length === 0 ? pathParts.shift() : null;
|
|
113
|
-
const hash = (0, import_assert.assertEx)(pathParts.pop(), () => "No hash specified");
|
|
114
|
-
this.archivist = pathParts.shift() ?? "api.archivist.xyo.network";
|
|
115
|
-
this.archive = pathParts.pop();
|
|
116
|
-
(0, import_assert.assertEx)(pathParts.length === 0, () => "Too many path parts");
|
|
117
|
-
return hash;
|
|
118
|
-
}
|
|
119
|
-
validateParse() {
|
|
120
|
-
(0, import_assert.assertEx)(this.archivist?.length !== 0, () => "Invalid archivist length");
|
|
121
|
-
(0, import_assert.assertEx)(this.archive?.length !== 0, () => "Invalid archive length");
|
|
122
|
-
(0, import_assert.assertEx)(!(this.archive && !this.archivist), () => "If specifying archive, archivist is also required");
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Huri.ts"],"sourcesContent":["export * from './Huri.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport { Address, Hash, isHash } from '@xylabs/hex'\nimport { AddressValue } from '@xyo-network/account'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type ObjectCategory = 'block' | 'payload'\n\nexport type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>\n\n/*\n Valid Huri:\n\n [<protocol>://][<archivist>/[<archive>/]]<hash>\n\n defaults:\n protocol: https\n archivist: api.archivist.xyo.network\n*/\n\nexport interface HuriOptions {\n archivistUri?: string\n token?: string\n}\n\nexport interface FetchedPayload<T extends Payload = Payload> {\n huri?: Huri\n payload: T\n}\n\nexport class Huri<T extends Payload = Payload> {\n archive?: string\n archivist?: Address | string\n hash: Hash\n originalHref: string\n protocol?: string\n token?: string\n\n private isHuri = true\n\n constructor(huri: Hash | Huri | string, { archivistUri, token }: HuriOptions = {}) {\n const huriString\n = Huri.isHuri(huri)?.href\n ?? (typeof huri === 'string'\n ? (huri as string)\n : huri instanceof ArrayBuffer\n ? new AddressValue(huri).hex\n : huri.href)\n this.originalHref = huriString\n\n const protocol = Huri.parseProtocol(huriString)\n this.protocol = protocol ?? 'https'\n\n const path = assertEx(Huri.parsePath(huriString), () => 'Missing path')\n this.hash = assertEx(this.parsePath(path, protocol !== undefined), () => 'Missing hash') as Hash\n\n assertEx(isHash(this.hash), () => `Invalid hash [${this.hash}]`)\n\n // if archivistUri sent, overwrite protocol and archivist\n if (archivistUri) {\n const archivistUriParts = archivistUri.split('://')\n this.protocol = archivistUriParts[0]\n this.archivist = archivistUriParts[1]\n }\n\n this.token = token\n\n this.validateParse()\n }\n\n /*\n The full href or the hash\n */\n get href() {\n const parts: string[] = []\n if (this.protocol) {\n parts.push(`${this.protocol}:/`)\n }\n if (this.archive) {\n parts.push(`${this.archive}`)\n }\n if (this.archivist) {\n parts.push(`${this.archivist}`)\n }\n parts.push(this.hash)\n return parts.join('/')\n }\n\n static async fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined> {\n const AuthHeader = huri.token ? { Authorization: `Bearer ${huri.token}` } : undefined\n return (await axios.get<T>(huri.href, { headers: AuthHeader })).data\n }\n\n static isHuri(value: unknown) {\n if (typeof value === 'object') {\n return (value as Huri).isHuri ? (value as Huri) : undefined\n }\n }\n\n private static parsePath(huri: string) {\n const protocolSplit = huri.split('//')\n assertEx(protocolSplit.length <= 2, () => `Invalid format [${huri}]`)\n if (protocolSplit.length === 1) {\n return huri\n }\n if (protocolSplit.length === 2) {\n return protocolSplit[1]\n }\n }\n\n private static parseProtocol(huri: string) {\n const protocolSplit = huri.split('//')\n assertEx(protocolSplit.length <= 2, () => `Invalid second protocol [${protocolSplit[2]}]`)\n const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined\n if (rawProtocol) {\n const protocolParts = rawProtocol?.split(':')\n assertEx(protocolParts.length === 2, () => `Invalid protocol format [${rawProtocol}]`)\n assertEx(protocolParts[1].length === 0, () => `Invalid protocol format (post :) [${rawProtocol}]`)\n return protocolParts.shift()\n }\n }\n\n async fetch(): Promise<T | undefined> {\n return await Huri.fetch<T>(this)\n }\n\n toString() {\n return this.href\n }\n\n private parsePath(path: string, hasProtocol: boolean) {\n const pathParts = path.split('/')\n\n // if the protocol was found, then there is not allowed to be a leading /\n assertEx(!(hasProtocol && pathParts[0].length === 0), () => 'Invalid protocol separator')\n\n // remove leading '/' if needed\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n pathParts[0].length === 0 ? pathParts.shift() : null\n\n // hash is assumed to be the last part\n const hash = assertEx(pathParts.pop(), () => 'No hash specified')\n\n // archivist is assumed to be the first part\n this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'\n\n // the archive is whatever is left\n this.archive = pathParts.pop()\n\n // after we pull off all the path parts, there should be nothing left\n assertEx(pathParts.length === 0, () => 'Too many path parts')\n\n return hash\n }\n\n private validateParse() {\n // the archivist should not be zero length\n assertEx(this.archivist?.length !== 0, () => 'Invalid archivist length')\n\n // the archivist should not be zero length (can be undefined)\n assertEx(this.archive?.length !== 0, () => 'Invalid archive length')\n\n // the archive should not be set if the archivist is not set\n assertEx(!(this.archive && !this.archivist), () => 'If specifying archive, archivist is also required')\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,mBAAsB;AACtB,iBAAsC;AACtC,qBAA6B;AA2BtB,IAAM,OAAN,MAAM,MAAkC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEQ,SAAS;AAAA,EAEjB,YAAY,MAA4B,EAAE,cAAc,MAAM,IAAiB,CAAC,GAAG;AACjF,UAAM,aACF,MAAK,OAAO,IAAI,GAAG,SACjB,OAAO,SAAS,WACf,OACD,gBAAgB,cACd,IAAI,4BAAa,IAAI,EAAE,MACvB,KAAK;AACb,SAAK,eAAe;AAEpB,UAAM,WAAW,MAAK,cAAc,UAAU;AAC9C,SAAK,WAAW,YAAY;AAE5B,UAAM,WAAO,wBAAS,MAAK,UAAU,UAAU,GAAG,MAAM,cAAc;AACtE,SAAK,WAAO,wBAAS,KAAK,UA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"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
package/dist/browser/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
package/dist/neutral/Huri.d.cts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Address, Hash } from '@xylabs/hex';
|
|
2
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
export type ObjectCategory = 'block' | 'payload';
|
|
4
|
-
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
5
|
-
export interface HuriOptions {
|
|
6
|
-
archivistUri?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface FetchedPayload<T extends Payload = Payload> {
|
|
10
|
-
huri?: Huri;
|
|
11
|
-
payload: T;
|
|
12
|
-
}
|
|
13
|
-
export declare class Huri<T extends Payload = Payload> {
|
|
14
|
-
archive?: string;
|
|
15
|
-
archivist?: Address | string;
|
|
16
|
-
hash: Hash;
|
|
17
|
-
originalHref: string;
|
|
18
|
-
protocol?: string;
|
|
19
|
-
token?: string;
|
|
20
|
-
private isHuri;
|
|
21
|
-
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
|
-
get href(): string;
|
|
23
|
-
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
|
-
static isHuri(value: unknown): Huri<{
|
|
25
|
-
schema: string;
|
|
26
|
-
} & import("@xyo-network/payload-model").PayloadFields> | undefined;
|
|
27
|
-
private static parsePath;
|
|
28
|
-
private static parseProtocol;
|
|
29
|
-
fetch(): Promise<T | undefined>;
|
|
30
|
-
toString(): string;
|
|
31
|
-
private parsePath;
|
|
32
|
-
private validateParse;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Huri.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAU,MAAM,aAAa,CAAA;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,CAAA;AAEhD,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;AAY5E,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IACzD,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,EAAE,CAAC,CAAA;CACX;AAED,qBAAa,IAAI,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,OAAO,CAAC,MAAM,CAAO;gBAET,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,GAAE,WAAgB;IAiCjF,IAAI,IAAI,WAaP;WAEY,KAAK,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKnF,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO;;;IAM5B,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,aAAa;IAYtB,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrC,QAAQ;IAIR,OAAO,CAAC,SAAS;IAyBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/neutral/Huri.d.mts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Address, Hash } from '@xylabs/hex';
|
|
2
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
export type ObjectCategory = 'block' | 'payload';
|
|
4
|
-
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
5
|
-
export interface HuriOptions {
|
|
6
|
-
archivistUri?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface FetchedPayload<T extends Payload = Payload> {
|
|
10
|
-
huri?: Huri;
|
|
11
|
-
payload: T;
|
|
12
|
-
}
|
|
13
|
-
export declare class Huri<T extends Payload = Payload> {
|
|
14
|
-
archive?: string;
|
|
15
|
-
archivist?: Address | string;
|
|
16
|
-
hash: Hash;
|
|
17
|
-
originalHref: string;
|
|
18
|
-
protocol?: string;
|
|
19
|
-
token?: string;
|
|
20
|
-
private isHuri;
|
|
21
|
-
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
|
-
get href(): string;
|
|
23
|
-
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
|
-
static isHuri(value: unknown): Huri<{
|
|
25
|
-
schema: string;
|
|
26
|
-
} & import("@xyo-network/payload-model").PayloadFields> | undefined;
|
|
27
|
-
private static parsePath;
|
|
28
|
-
private static parseProtocol;
|
|
29
|
-
fetch(): Promise<T | undefined>;
|
|
30
|
-
toString(): string;
|
|
31
|
-
private parsePath;
|
|
32
|
-
private validateParse;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Huri.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAU,MAAM,aAAa,CAAA;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,CAAA;AAEhD,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;AAY5E,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IACzD,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,EAAE,CAAC,CAAA;CACX;AAED,qBAAa,IAAI,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,OAAO,CAAC,MAAM,CAAO;gBAET,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,GAAE,WAAgB;IAiCjF,IAAI,IAAI,WAaP;WAEY,KAAK,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKnF,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO;;;IAM5B,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,aAAa;IAYtB,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrC,QAAQ;IAIR,OAAO,CAAC,SAAS;IAyBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/neutral/Huri.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Address, Hash } from '@xylabs/hex';
|
|
2
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
export type ObjectCategory = 'block' | 'payload';
|
|
4
|
-
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
5
|
-
export interface HuriOptions {
|
|
6
|
-
archivistUri?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface FetchedPayload<T extends Payload = Payload> {
|
|
10
|
-
huri?: Huri;
|
|
11
|
-
payload: T;
|
|
12
|
-
}
|
|
13
|
-
export declare class Huri<T extends Payload = Payload> {
|
|
14
|
-
archive?: string;
|
|
15
|
-
archivist?: Address | string;
|
|
16
|
-
hash: Hash;
|
|
17
|
-
originalHref: string;
|
|
18
|
-
protocol?: string;
|
|
19
|
-
token?: string;
|
|
20
|
-
private isHuri;
|
|
21
|
-
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
|
-
get href(): string;
|
|
23
|
-
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
|
-
static isHuri(value: unknown): Huri<{
|
|
25
|
-
schema: string;
|
|
26
|
-
} & import("@xyo-network/payload-model").PayloadFields> | undefined;
|
|
27
|
-
private static parsePath;
|
|
28
|
-
private static parseProtocol;
|
|
29
|
-
fetch(): Promise<T | undefined>;
|
|
30
|
-
toString(): string;
|
|
31
|
-
private parsePath;
|
|
32
|
-
private validateParse;
|
|
33
|
-
}
|
|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;;;IAM5B,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,aAAa;IAYtB,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrC,QAAQ;IAIR,OAAO,CAAC,SAAS;IAyBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/neutral/index.cjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
Huri: () => Huri
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
|
|
27
|
-
// src/Huri.ts
|
|
28
|
-
var import_assert = require("@xylabs/assert");
|
|
29
|
-
var import_axios = require("@xylabs/axios");
|
|
30
|
-
var import_hex = require("@xylabs/hex");
|
|
31
|
-
var import_account = require("@xyo-network/account");
|
|
32
|
-
var Huri = class _Huri {
|
|
33
|
-
archive;
|
|
34
|
-
archivist;
|
|
35
|
-
hash;
|
|
36
|
-
originalHref;
|
|
37
|
-
protocol;
|
|
38
|
-
token;
|
|
39
|
-
isHuri = true;
|
|
40
|
-
constructor(huri, { archivistUri, token } = {}) {
|
|
41
|
-
const huriString = _Huri.isHuri(huri)?.href ?? (typeof huri === "string" ? huri : huri instanceof ArrayBuffer ? new import_account.AddressValue(huri).hex : huri.href);
|
|
42
|
-
this.originalHref = huriString;
|
|
43
|
-
const protocol = _Huri.parseProtocol(huriString);
|
|
44
|
-
this.protocol = protocol ?? "https";
|
|
45
|
-
const path = (0, import_assert.assertEx)(_Huri.parsePath(huriString), () => "Missing path");
|
|
46
|
-
this.hash = (0, import_assert.assertEx)(this.parsePath(path, protocol !== void 0), () => "Missing hash");
|
|
47
|
-
(0, import_assert.assertEx)((0, import_hex.isHash)(this.hash), () => `Invalid hash [${this.hash}]`);
|
|
48
|
-
if (archivistUri) {
|
|
49
|
-
const archivistUriParts = archivistUri.split("://");
|
|
50
|
-
this.protocol = archivistUriParts[0];
|
|
51
|
-
this.archivist = archivistUriParts[1];
|
|
52
|
-
}
|
|
53
|
-
this.token = token;
|
|
54
|
-
this.validateParse();
|
|
55
|
-
}
|
|
56
|
-
/*
|
|
57
|
-
The full href or the hash
|
|
58
|
-
*/
|
|
59
|
-
get href() {
|
|
60
|
-
const parts = [];
|
|
61
|
-
if (this.protocol) {
|
|
62
|
-
parts.push(`${this.protocol}:/`);
|
|
63
|
-
}
|
|
64
|
-
if (this.archive) {
|
|
65
|
-
parts.push(`${this.archive}`);
|
|
66
|
-
}
|
|
67
|
-
if (this.archivist) {
|
|
68
|
-
parts.push(`${this.archivist}`);
|
|
69
|
-
}
|
|
70
|
-
parts.push(this.hash);
|
|
71
|
-
return parts.join("/");
|
|
72
|
-
}
|
|
73
|
-
static async fetch(huri) {
|
|
74
|
-
const AuthHeader = huri.token ? { Authorization: `Bearer ${huri.token}` } : void 0;
|
|
75
|
-
return (await import_axios.axios.get(huri.href, { headers: AuthHeader })).data;
|
|
76
|
-
}
|
|
77
|
-
static isHuri(value) {
|
|
78
|
-
if (typeof value === "object") {
|
|
79
|
-
return value.isHuri ? value : void 0;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
static parsePath(huri) {
|
|
83
|
-
const protocolSplit = huri.split("//");
|
|
84
|
-
(0, import_assert.assertEx)(protocolSplit.length <= 2, () => `Invalid format [${huri}]`);
|
|
85
|
-
if (protocolSplit.length === 1) {
|
|
86
|
-
return huri;
|
|
87
|
-
}
|
|
88
|
-
if (protocolSplit.length === 2) {
|
|
89
|
-
return protocolSplit[1];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
static parseProtocol(huri) {
|
|
93
|
-
const protocolSplit = huri.split("//");
|
|
94
|
-
(0, import_assert.assertEx)(protocolSplit.length <= 2, () => `Invalid second protocol [${protocolSplit[2]}]`);
|
|
95
|
-
const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : void 0;
|
|
96
|
-
if (rawProtocol) {
|
|
97
|
-
const protocolParts = rawProtocol?.split(":");
|
|
98
|
-
(0, import_assert.assertEx)(protocolParts.length === 2, () => `Invalid protocol format [${rawProtocol}]`);
|
|
99
|
-
(0, import_assert.assertEx)(protocolParts[1].length === 0, () => `Invalid protocol format (post :) [${rawProtocol}]`);
|
|
100
|
-
return protocolParts.shift();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async fetch() {
|
|
104
|
-
return await _Huri.fetch(this);
|
|
105
|
-
}
|
|
106
|
-
toString() {
|
|
107
|
-
return this.href;
|
|
108
|
-
}
|
|
109
|
-
parsePath(path, hasProtocol) {
|
|
110
|
-
const pathParts = path.split("/");
|
|
111
|
-
(0, import_assert.assertEx)(!(hasProtocol && pathParts[0].length === 0), () => "Invalid protocol separator");
|
|
112
|
-
pathParts[0].length === 0 ? pathParts.shift() : null;
|
|
113
|
-
const hash = (0, import_assert.assertEx)(pathParts.pop(), () => "No hash specified");
|
|
114
|
-
this.archivist = pathParts.shift() ?? "api.archivist.xyo.network";
|
|
115
|
-
this.archive = pathParts.pop();
|
|
116
|
-
(0, import_assert.assertEx)(pathParts.length === 0, () => "Too many path parts");
|
|
117
|
-
return hash;
|
|
118
|
-
}
|
|
119
|
-
validateParse() {
|
|
120
|
-
(0, import_assert.assertEx)(this.archivist?.length !== 0, () => "Invalid archivist length");
|
|
121
|
-
(0, import_assert.assertEx)(this.archive?.length !== 0, () => "Invalid archive length");
|
|
122
|
-
(0, import_assert.assertEx)(!(this.archive && !this.archivist), () => "If specifying archive, archivist is also required");
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Huri.ts"],"sourcesContent":["export * from './Huri.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport { Address, Hash, isHash } from '@xylabs/hex'\nimport { AddressValue } from '@xyo-network/account'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type ObjectCategory = 'block' | 'payload'\n\nexport type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>\n\n/*\n Valid Huri:\n\n [<protocol>://][<archivist>/[<archive>/]]<hash>\n\n defaults:\n protocol: https\n archivist: api.archivist.xyo.network\n*/\n\nexport interface HuriOptions {\n archivistUri?: string\n token?: string\n}\n\nexport interface FetchedPayload<T extends Payload = Payload> {\n huri?: Huri\n payload: T\n}\n\nexport class Huri<T extends Payload = Payload> {\n archive?: string\n archivist?: Address | string\n hash: Hash\n originalHref: string\n protocol?: string\n token?: string\n\n private isHuri = true\n\n constructor(huri: Hash | Huri | string, { archivistUri, token }: HuriOptions = {}) {\n const huriString\n = Huri.isHuri(huri)?.href\n ?? (typeof huri === 'string'\n ? (huri as string)\n : huri instanceof ArrayBuffer\n ? new AddressValue(huri).hex\n : huri.href)\n this.originalHref = huriString\n\n const protocol = Huri.parseProtocol(huriString)\n this.protocol = protocol ?? 'https'\n\n const path = assertEx(Huri.parsePath(huriString), () => 'Missing path')\n this.hash = assertEx(this.parsePath(path, protocol !== undefined), () => 'Missing hash') as Hash\n\n assertEx(isHash(this.hash), () => `Invalid hash [${this.hash}]`)\n\n // if archivistUri sent, overwrite protocol and archivist\n if (archivistUri) {\n const archivistUriParts = archivistUri.split('://')\n this.protocol = archivistUriParts[0]\n this.archivist = archivistUriParts[1]\n }\n\n this.token = token\n\n this.validateParse()\n }\n\n /*\n The full href or the hash\n */\n get href() {\n const parts: string[] = []\n if (this.protocol) {\n parts.push(`${this.protocol}:/`)\n }\n if (this.archive) {\n parts.push(`${this.archive}`)\n }\n if (this.archivist) {\n parts.push(`${this.archivist}`)\n }\n parts.push(this.hash)\n return parts.join('/')\n }\n\n static async fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined> {\n const AuthHeader = huri.token ? { Authorization: `Bearer ${huri.token}` } : undefined\n return (await axios.get<T>(huri.href, { headers: AuthHeader })).data\n }\n\n static isHuri(value: unknown) {\n if (typeof value === 'object') {\n return (value as Huri).isHuri ? (value as Huri) : undefined\n }\n }\n\n private static parsePath(huri: string) {\n const protocolSplit = huri.split('//')\n assertEx(protocolSplit.length <= 2, () => `Invalid format [${huri}]`)\n if (protocolSplit.length === 1) {\n return huri\n }\n if (protocolSplit.length === 2) {\n return protocolSplit[1]\n }\n }\n\n private static parseProtocol(huri: string) {\n const protocolSplit = huri.split('//')\n assertEx(protocolSplit.length <= 2, () => `Invalid second protocol [${protocolSplit[2]}]`)\n const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined\n if (rawProtocol) {\n const protocolParts = rawProtocol?.split(':')\n assertEx(protocolParts.length === 2, () => `Invalid protocol format [${rawProtocol}]`)\n assertEx(protocolParts[1].length === 0, () => `Invalid protocol format (post :) [${rawProtocol}]`)\n return protocolParts.shift()\n }\n }\n\n async fetch(): Promise<T | undefined> {\n return await Huri.fetch<T>(this)\n }\n\n toString() {\n return this.href\n }\n\n private parsePath(path: string, hasProtocol: boolean) {\n const pathParts = path.split('/')\n\n // if the protocol was found, then there is not allowed to be a leading /\n assertEx(!(hasProtocol && pathParts[0].length === 0), () => 'Invalid protocol separator')\n\n // remove leading '/' if needed\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n pathParts[0].length === 0 ? pathParts.shift() : null\n\n // hash is assumed to be the last part\n const hash = assertEx(pathParts.pop(), () => 'No hash specified')\n\n // archivist is assumed to be the first part\n this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'\n\n // the archive is whatever is left\n this.archive = pathParts.pop()\n\n // after we pull off all the path parts, there should be nothing left\n assertEx(pathParts.length === 0, () => 'Too many path parts')\n\n return hash\n }\n\n private validateParse() {\n // the archivist should not be zero length\n assertEx(this.archivist?.length !== 0, () => 'Invalid archivist length')\n\n // the archivist should not be zero length (can be undefined)\n assertEx(this.archive?.length !== 0, () => 'Invalid archive length')\n\n // the archive should not be set if the archivist is not set\n assertEx(!(this.archive && !this.archivist), () => 'If specifying archive, archivist is also required')\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,mBAAsB;AACtB,iBAAsC;AACtC,qBAA6B;AA2BtB,IAAM,OAAN,MAAM,MAAkC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEQ,SAAS;AAAA,EAEjB,YAAY,MAA4B,EAAE,cAAc,MAAM,IAAiB,CAAC,GAAG;AACjF,UAAM,aACF,MAAK,OAAO,IAAI,GAAG,SACjB,OAAO,SAAS,WACf,OACD,gBAAgB,cACd,IAAI,4BAAa,IAAI,EAAE,MACvB,KAAK;AACb,SAAK,eAAe;AAEpB,UAAM,WAAW,MAAK,cAAc,UAAU;AAC9C,SAAK,WAAW,YAAY;AAE5B,UAAM,WAAO,wBAAS,MAAK,UAAU,UAAU,GAAG,MAA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
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
package/dist/neutral/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
package/dist/node/Huri.d.cts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Address, Hash } from '@xylabs/hex';
|
|
2
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
export type ObjectCategory = 'block' | 'payload';
|
|
4
|
-
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
5
|
-
export interface HuriOptions {
|
|
6
|
-
archivistUri?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface FetchedPayload<T extends Payload = Payload> {
|
|
10
|
-
huri?: Huri;
|
|
11
|
-
payload: T;
|
|
12
|
-
}
|
|
13
|
-
export declare class Huri<T extends Payload = Payload> {
|
|
14
|
-
archive?: string;
|
|
15
|
-
archivist?: Address | string;
|
|
16
|
-
hash: Hash;
|
|
17
|
-
originalHref: string;
|
|
18
|
-
protocol?: string;
|
|
19
|
-
token?: string;
|
|
20
|
-
private isHuri;
|
|
21
|
-
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
|
-
get href(): string;
|
|
23
|
-
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
|
-
static isHuri(value: unknown): Huri<{
|
|
25
|
-
schema: string;
|
|
26
|
-
} & import("@xyo-network/payload-model").PayloadFields> | undefined;
|
|
27
|
-
private static parsePath;
|
|
28
|
-
private static parseProtocol;
|
|
29
|
-
fetch(): Promise<T | undefined>;
|
|
30
|
-
toString(): string;
|
|
31
|
-
private parsePath;
|
|
32
|
-
private validateParse;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Huri.d.ts.map
|
package/dist/node/Huri.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAU,MAAM,aAAa,CAAA;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,CAAA;AAEhD,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;AAY5E,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IACzD,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,EAAE,CAAC,CAAA;CACX;AAED,qBAAa,IAAI,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,OAAO,CAAC,MAAM,CAAO;gBAET,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,GAAE,WAAgB;IAiCjF,IAAI,IAAI,WAaP;WAEY,KAAK,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKnF,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO;;;IAM5B,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,aAAa;IAYtB,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrC,QAAQ;IAIR,OAAO,CAAC,SAAS;IAyBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/node/Huri.d.mts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Address, Hash } from '@xylabs/hex';
|
|
2
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
export type ObjectCategory = 'block' | 'payload';
|
|
4
|
-
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
5
|
-
export interface HuriOptions {
|
|
6
|
-
archivistUri?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface FetchedPayload<T extends Payload = Payload> {
|
|
10
|
-
huri?: Huri;
|
|
11
|
-
payload: T;
|
|
12
|
-
}
|
|
13
|
-
export declare class Huri<T extends Payload = Payload> {
|
|
14
|
-
archive?: string;
|
|
15
|
-
archivist?: Address | string;
|
|
16
|
-
hash: Hash;
|
|
17
|
-
originalHref: string;
|
|
18
|
-
protocol?: string;
|
|
19
|
-
token?: string;
|
|
20
|
-
private isHuri;
|
|
21
|
-
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
|
-
get href(): string;
|
|
23
|
-
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
|
-
static isHuri(value: unknown): Huri<{
|
|
25
|
-
schema: string;
|
|
26
|
-
} & import("@xyo-network/payload-model").PayloadFields> | undefined;
|
|
27
|
-
private static parsePath;
|
|
28
|
-
private static parseProtocol;
|
|
29
|
-
fetch(): Promise<T | undefined>;
|
|
30
|
-
toString(): string;
|
|
31
|
-
private parsePath;
|
|
32
|
-
private validateParse;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Huri.d.ts.map
|
package/dist/node/Huri.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAU,MAAM,aAAa,CAAA;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,CAAA;AAEhD,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;AAY5E,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IACzD,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,EAAE,CAAC,CAAA;CACX;AAED,qBAAa,IAAI,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,OAAO,CAAC,MAAM,CAAO;gBAET,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,GAAE,WAAgB;IAiCjF,IAAI,IAAI,WAaP;WAEY,KAAK,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKnF,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO;;;IAM5B,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,aAAa;IAYtB,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrC,QAAQ;IAIR,OAAO,CAAC,SAAS;IAyBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/node/Huri.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Address, Hash } from '@xylabs/hex';
|
|
2
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
export type ObjectCategory = 'block' | 'payload';
|
|
4
|
-
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
5
|
-
export interface HuriOptions {
|
|
6
|
-
archivistUri?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface FetchedPayload<T extends Payload = Payload> {
|
|
10
|
-
huri?: Huri;
|
|
11
|
-
payload: T;
|
|
12
|
-
}
|
|
13
|
-
export declare class Huri<T extends Payload = Payload> {
|
|
14
|
-
archive?: string;
|
|
15
|
-
archivist?: Address | string;
|
|
16
|
-
hash: Hash;
|
|
17
|
-
originalHref: string;
|
|
18
|
-
protocol?: string;
|
|
19
|
-
token?: string;
|
|
20
|
-
private isHuri;
|
|
21
|
-
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
|
-
get href(): string;
|
|
23
|
-
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
|
-
static isHuri(value: unknown): Huri<{
|
|
25
|
-
schema: string;
|
|
26
|
-
} & import("@xyo-network/payload-model").PayloadFields> | undefined;
|
|
27
|
-
private static parsePath;
|
|
28
|
-
private static parseProtocol;
|
|
29
|
-
fetch(): Promise<T | undefined>;
|
|
30
|
-
toString(): string;
|
|
31
|
-
private parsePath;
|
|
32
|
-
private validateParse;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Huri.d.ts.map
|
package/dist/node/Huri.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAU,MAAM,aAAa,CAAA;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,CAAA;AAEhD,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;AAY5E,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IACzD,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,EAAE,CAAC,CAAA;CACX;AAED,qBAAa,IAAI,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,OAAO,CAAC,MAAM,CAAO;gBAET,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,GAAE,WAAgB;IAiCjF,IAAI,IAAI,WAaP;WAEY,KAAK,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKnF,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO;;;IAM5B,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,aAAa;IAYtB,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrC,QAAQ;IAIR,OAAO,CAAC,SAAS;IAyBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/node/index.cjs
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
Huri: () => Huri
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
|
|
27
|
-
// src/Huri.ts
|
|
28
|
-
var import_assert = require("@xylabs/assert");
|
|
29
|
-
var import_axios = require("@xylabs/axios");
|
|
30
|
-
var import_hex = require("@xylabs/hex");
|
|
31
|
-
var import_account = require("@xyo-network/account");
|
|
32
|
-
var Huri = class _Huri {
|
|
33
|
-
archive;
|
|
34
|
-
archivist;
|
|
35
|
-
hash;
|
|
36
|
-
originalHref;
|
|
37
|
-
protocol;
|
|
38
|
-
token;
|
|
39
|
-
isHuri = true;
|
|
40
|
-
constructor(huri, { archivistUri, token } = {}) {
|
|
41
|
-
var _a;
|
|
42
|
-
const huriString = ((_a = _Huri.isHuri(huri)) == null ? void 0 : _a.href) ?? (typeof huri === "string" ? huri : huri instanceof ArrayBuffer ? new import_account.AddressValue(huri).hex : huri.href);
|
|
43
|
-
this.originalHref = huriString;
|
|
44
|
-
const protocol = _Huri.parseProtocol(huriString);
|
|
45
|
-
this.protocol = protocol ?? "https";
|
|
46
|
-
const path = (0, import_assert.assertEx)(_Huri.parsePath(huriString), () => "Missing path");
|
|
47
|
-
this.hash = (0, import_assert.assertEx)(this.parsePath(path, protocol !== void 0), () => "Missing hash");
|
|
48
|
-
(0, import_assert.assertEx)((0, import_hex.isHash)(this.hash), () => `Invalid hash [${this.hash}]`);
|
|
49
|
-
if (archivistUri) {
|
|
50
|
-
const archivistUriParts = archivistUri.split("://");
|
|
51
|
-
this.protocol = archivistUriParts[0];
|
|
52
|
-
this.archivist = archivistUriParts[1];
|
|
53
|
-
}
|
|
54
|
-
this.token = token;
|
|
55
|
-
this.validateParse();
|
|
56
|
-
}
|
|
57
|
-
/*
|
|
58
|
-
The full href or the hash
|
|
59
|
-
*/
|
|
60
|
-
get href() {
|
|
61
|
-
const parts = [];
|
|
62
|
-
if (this.protocol) {
|
|
63
|
-
parts.push(`${this.protocol}:/`);
|
|
64
|
-
}
|
|
65
|
-
if (this.archive) {
|
|
66
|
-
parts.push(`${this.archive}`);
|
|
67
|
-
}
|
|
68
|
-
if (this.archivist) {
|
|
69
|
-
parts.push(`${this.archivist}`);
|
|
70
|
-
}
|
|
71
|
-
parts.push(this.hash);
|
|
72
|
-
return parts.join("/");
|
|
73
|
-
}
|
|
74
|
-
static async fetch(huri) {
|
|
75
|
-
const AuthHeader = huri.token ? { Authorization: `Bearer ${huri.token}` } : void 0;
|
|
76
|
-
return (await import_axios.axios.get(huri.href, { headers: AuthHeader })).data;
|
|
77
|
-
}
|
|
78
|
-
static isHuri(value) {
|
|
79
|
-
if (typeof value === "object") {
|
|
80
|
-
return value.isHuri ? value : void 0;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
static parsePath(huri) {
|
|
84
|
-
const protocolSplit = huri.split("//");
|
|
85
|
-
(0, import_assert.assertEx)(protocolSplit.length <= 2, () => `Invalid format [${huri}]`);
|
|
86
|
-
if (protocolSplit.length === 1) {
|
|
87
|
-
return huri;
|
|
88
|
-
}
|
|
89
|
-
if (protocolSplit.length === 2) {
|
|
90
|
-
return protocolSplit[1];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
static parseProtocol(huri) {
|
|
94
|
-
const protocolSplit = huri.split("//");
|
|
95
|
-
(0, import_assert.assertEx)(protocolSplit.length <= 2, () => `Invalid second protocol [${protocolSplit[2]}]`);
|
|
96
|
-
const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : void 0;
|
|
97
|
-
if (rawProtocol) {
|
|
98
|
-
const protocolParts = rawProtocol == null ? void 0 : rawProtocol.split(":");
|
|
99
|
-
(0, import_assert.assertEx)(protocolParts.length === 2, () => `Invalid protocol format [${rawProtocol}]`);
|
|
100
|
-
(0, import_assert.assertEx)(protocolParts[1].length === 0, () => `Invalid protocol format (post :) [${rawProtocol}]`);
|
|
101
|
-
return protocolParts.shift();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
async fetch() {
|
|
105
|
-
return await _Huri.fetch(this);
|
|
106
|
-
}
|
|
107
|
-
toString() {
|
|
108
|
-
return this.href;
|
|
109
|
-
}
|
|
110
|
-
parsePath(path, hasProtocol) {
|
|
111
|
-
const pathParts = path.split("/");
|
|
112
|
-
(0, import_assert.assertEx)(!(hasProtocol && pathParts[0].length === 0), () => "Invalid protocol separator");
|
|
113
|
-
pathParts[0].length === 0 ? pathParts.shift() : null;
|
|
114
|
-
const hash = (0, import_assert.assertEx)(pathParts.pop(), () => "No hash specified");
|
|
115
|
-
this.archivist = pathParts.shift() ?? "api.archivist.xyo.network";
|
|
116
|
-
this.archive = pathParts.pop();
|
|
117
|
-
(0, import_assert.assertEx)(pathParts.length === 0, () => "Too many path parts");
|
|
118
|
-
return hash;
|
|
119
|
-
}
|
|
120
|
-
validateParse() {
|
|
121
|
-
var _a, _b;
|
|
122
|
-
(0, import_assert.assertEx)(((_a = this.archivist) == null ? void 0 : _a.length) !== 0, () => "Invalid archivist length");
|
|
123
|
-
(0, import_assert.assertEx)(((_b = this.archive) == null ? void 0 : _b.length) !== 0, () => "Invalid archive length");
|
|
124
|
-
(0, import_assert.assertEx)(!(this.archive && !this.archivist), () => "If specifying archive, archivist is also required");
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
128
|
-
0 && (module.exports = {
|
|
129
|
-
Huri
|
|
130
|
-
});
|
|
131
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/node/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Huri.ts"],"sourcesContent":["export * from './Huri.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport { Address, Hash, isHash } from '@xylabs/hex'\nimport { AddressValue } from '@xyo-network/account'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type ObjectCategory = 'block' | 'payload'\n\nexport type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>\n\n/*\n Valid Huri:\n\n [<protocol>://][<archivist>/[<archive>/]]<hash>\n\n defaults:\n protocol: https\n archivist: api.archivist.xyo.network\n*/\n\nexport interface HuriOptions {\n archivistUri?: string\n token?: string\n}\n\nexport interface FetchedPayload<T extends Payload = Payload> {\n huri?: Huri\n payload: T\n}\n\nexport class Huri<T extends Payload = Payload> {\n archive?: string\n archivist?: Address | string\n hash: Hash\n originalHref: string\n protocol?: string\n token?: string\n\n private isHuri = true\n\n constructor(huri: Hash | Huri | string, { archivistUri, token }: HuriOptions = {}) {\n const huriString\n = Huri.isHuri(huri)?.href\n ?? (typeof huri === 'string'\n ? (huri as string)\n : huri instanceof ArrayBuffer\n ? new AddressValue(huri).hex\n : huri.href)\n this.originalHref = huriString\n\n const protocol = Huri.parseProtocol(huriString)\n this.protocol = protocol ?? 'https'\n\n const path = assertEx(Huri.parsePath(huriString), () => 'Missing path')\n this.hash = assertEx(this.parsePath(path, protocol !== undefined), () => 'Missing hash') as Hash\n\n assertEx(isHash(this.hash), () => `Invalid hash [${this.hash}]`)\n\n // if archivistUri sent, overwrite protocol and archivist\n if (archivistUri) {\n const archivistUriParts = archivistUri.split('://')\n this.protocol = archivistUriParts[0]\n this.archivist = archivistUriParts[1]\n }\n\n this.token = token\n\n this.validateParse()\n }\n\n /*\n The full href or the hash\n */\n get href() {\n const parts: string[] = []\n if (this.protocol) {\n parts.push(`${this.protocol}:/`)\n }\n if (this.archive) {\n parts.push(`${this.archive}`)\n }\n if (this.archivist) {\n parts.push(`${this.archivist}`)\n }\n parts.push(this.hash)\n return parts.join('/')\n }\n\n static async fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined> {\n const AuthHeader = huri.token ? { Authorization: `Bearer ${huri.token}` } : undefined\n return (await axios.get<T>(huri.href, { headers: AuthHeader })).data\n }\n\n static isHuri(value: unknown) {\n if (typeof value === 'object') {\n return (value as Huri).isHuri ? (value as Huri) : undefined\n }\n }\n\n private static parsePath(huri: string) {\n const protocolSplit = huri.split('//')\n assertEx(protocolSplit.length <= 2, () => `Invalid format [${huri}]`)\n if (protocolSplit.length === 1) {\n return huri\n }\n if (protocolSplit.length === 2) {\n return protocolSplit[1]\n }\n }\n\n private static parseProtocol(huri: string) {\n const protocolSplit = huri.split('//')\n assertEx(protocolSplit.length <= 2, () => `Invalid second protocol [${protocolSplit[2]}]`)\n const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined\n if (rawProtocol) {\n const protocolParts = rawProtocol?.split(':')\n assertEx(protocolParts.length === 2, () => `Invalid protocol format [${rawProtocol}]`)\n assertEx(protocolParts[1].length === 0, () => `Invalid protocol format (post :) [${rawProtocol}]`)\n return protocolParts.shift()\n }\n }\n\n async fetch(): Promise<T | undefined> {\n return await Huri.fetch<T>(this)\n }\n\n toString() {\n return this.href\n }\n\n private parsePath(path: string, hasProtocol: boolean) {\n const pathParts = path.split('/')\n\n // if the protocol was found, then there is not allowed to be a leading /\n assertEx(!(hasProtocol && pathParts[0].length === 0), () => 'Invalid protocol separator')\n\n // remove leading '/' if needed\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n pathParts[0].length === 0 ? pathParts.shift() : null\n\n // hash is assumed to be the last part\n const hash = assertEx(pathParts.pop(), () => 'No hash specified')\n\n // archivist is assumed to be the first part\n this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'\n\n // the archive is whatever is left\n this.archive = pathParts.pop()\n\n // after we pull off all the path parts, there should be nothing left\n assertEx(pathParts.length === 0, () => 'Too many path parts')\n\n return hash\n }\n\n private validateParse() {\n // the archivist should not be zero length\n assertEx(this.archivist?.length !== 0, () => 'Invalid archivist length')\n\n // the archivist should not be zero length (can be undefined)\n assertEx(this.archive?.length !== 0, () => 'Invalid archive length')\n\n // the archive should not be set if the archivist is not set\n assertEx(!(this.archive && !this.archivist), () => 'If specifying archive, archivist is also required')\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,mBAAsB;AACtB,iBAAsC;AACtC,qBAA6B;AA2BtB,IAAM,OAAN,MAAM,MAAkC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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AAU,MAAM,KAAK;AAGtC,SAAK,UAAU,UAAU,IAAI;AAG7B,gCAAS,UAAU,WAAW,GAAG,MAAM,qBAAqB;AAE5D,WAAO;AAAA,EACT;AAAA,EAEQ,gBAAgB;AA3J1B;AA6JI,kCAAS,UAAK,cAAL,mBAAgB,YAAW,GAAG,MAAM,0BAA0B;AAGvE,kCAAS,UAAK,YAAL,mBAAc,YAAW,GAAG,MAAM,wBAAwB;AAGnE,gCAAS,EAAE,KAAK,WAAW,CAAC,KAAK,YAAY,MAAM,mDAAmD;AAAA,EACxG;AACF;","names":[]}
|
package/dist/node/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
package/dist/node/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
package/dist/node/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|