@xyo-network/huri 2.81.7 → 2.81.9
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/Huri.d.cts +2 -2
- package/dist/browser/Huri.d.cts.map +1 -1
- package/dist/browser/Huri.d.mts +2 -2
- package/dist/browser/Huri.d.mts.map +1 -1
- package/dist/browser/Huri.d.ts +2 -2
- package/dist/browser/Huri.d.ts.map +1 -1
- package/dist/browser/index.cjs +1 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Huri.d.cts +2 -2
- package/dist/node/Huri.d.cts.map +1 -1
- package/dist/node/Huri.d.mts +2 -2
- package/dist/node/Huri.d.mts.map +1 -1
- package/dist/node/Huri.d.ts +2 -2
- package/dist/node/Huri.d.ts.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +1 -1
- package/dist/node/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/Huri.ts +4 -3
package/dist/browser/Huri.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Hash } from '@xylabs/hex';
|
|
2
2
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
3
|
export type ObjectCategory = 'block' | 'payload';
|
|
4
4
|
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
@@ -18,7 +18,7 @@ export declare class Huri<T extends Payload = Payload> {
|
|
|
18
18
|
protocol?: string;
|
|
19
19
|
token?: string;
|
|
20
20
|
private isHuri;
|
|
21
|
-
constructor(huri:
|
|
21
|
+
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
22
|
get href(): string;
|
|
23
23
|
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
24
|
static isHuri(value: unknown): Huri<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,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,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,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;IA0BjF,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;;;IAO5B,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;IAwBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/browser/Huri.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Hash } from '@xylabs/hex';
|
|
2
2
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
3
|
export type ObjectCategory = 'block' | 'payload';
|
|
4
4
|
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
@@ -18,7 +18,7 @@ export declare class Huri<T extends Payload = Payload> {
|
|
|
18
18
|
protocol?: string;
|
|
19
19
|
token?: string;
|
|
20
20
|
private isHuri;
|
|
21
|
-
constructor(huri:
|
|
21
|
+
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
22
|
get href(): string;
|
|
23
23
|
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
24
|
static isHuri(value: unknown): Huri<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,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,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,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;IA0BjF,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;;;IAO5B,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;IAwBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/browser/Huri.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Hash } from '@xylabs/hex';
|
|
2
2
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
3
|
export type ObjectCategory = 'block' | 'payload';
|
|
4
4
|
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
@@ -18,7 +18,7 @@ export declare class Huri<T extends Payload = Payload> {
|
|
|
18
18
|
protocol?: string;
|
|
19
19
|
token?: string;
|
|
20
20
|
private isHuri;
|
|
21
|
-
constructor(huri:
|
|
21
|
+
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
22
|
get href(): string;
|
|
23
23
|
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
24
|
static isHuri(value: unknown): Huri<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,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,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,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;IA0BjF,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;;;IAO5B,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;IAwBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -37,7 +37,7 @@ var Huri = class _Huri {
|
|
|
37
37
|
token;
|
|
38
38
|
isHuri = true;
|
|
39
39
|
constructor(huri, { archivistUri, token } = {}) {
|
|
40
|
-
const huriString = _Huri.isHuri(huri)?.href ?? typeof huri === "string" ? huri : new import_account.AddressValue(huri).hex;
|
|
40
|
+
const huriString = _Huri.isHuri(huri)?.href ?? typeof huri === "string" ? huri : huri instanceof ArrayBuffer ? new import_account.AddressValue(huri).hex : huri.href;
|
|
41
41
|
this.originalHref = huriString;
|
|
42
42
|
const protocol = _Huri.parseProtocol(huriString);
|
|
43
43
|
this.protocol = protocol ?? "https";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Huri.ts"],"sourcesContent":["export * from './Huri'\n","import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Huri.ts"],"sourcesContent":["export * from './Huri'\n","import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport { Hash } 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?: string\n hash: string\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 ?? typeof huri === 'string' ? (huri as string) : huri instanceof ArrayBuffer ? new AddressValue(huri).hex : 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 = this.parsePath(path, protocol !== undefined)\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 return undefined\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 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;AAEtB,qBAA6B;AA2BtB,IAAM,OAAN,MA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,WAAW,GAAG,qBAAqB;AAEtD,WAAO;AAAA,EACT;AAAA,EAEQ,gBAAgB;AAEtB,gCAAS,KAAK,WAAW,WAAW,GAAG,0BAA0B;AAGjE,gCAAS,KAAK,SAAS,WAAW,GAAG,wBAAwB;AAG7D,gCAAS,EAAE,KAAK,WAAW,CAAC,KAAK,YAAY,mDAAmD;AAAA,EAClG;AACF;","names":[]}
|
package/dist/browser/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var Huri = class _Huri {
|
|
|
11
11
|
token;
|
|
12
12
|
isHuri = true;
|
|
13
13
|
constructor(huri, { archivistUri, token } = {}) {
|
|
14
|
-
const huriString = _Huri.isHuri(huri)?.href ?? typeof huri === "string" ? huri : new AddressValue(huri).hex;
|
|
14
|
+
const huriString = _Huri.isHuri(huri)?.href ?? typeof huri === "string" ? huri : huri instanceof ArrayBuffer ? new AddressValue(huri).hex : huri.href;
|
|
15
15
|
this.originalHref = huriString;
|
|
16
16
|
const protocol = _Huri.parseProtocol(huriString);
|
|
17
17
|
this.protocol = protocol ?? "https";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Huri.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/Huri.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport { Hash } 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?: string\n hash: string\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 ?? typeof huri === 'string' ? (huri as string) : huri instanceof ArrayBuffer ? new AddressValue(huri).hex : 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 = this.parsePath(path, protocol !== undefined)\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 return undefined\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 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;AAEtB,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,aACJ,MAAK,OAAO,IAAI,GAAG,QAAQ,OAAO,SAAS,WAAY,OAAkB,gBAAgB,cAAc,IAAI,aAAa,IAAI,EAAE,MAAM,KAAK;AAC3I,SAAK,eAAe;AAEpB,UAAM,WAAW,MAAK,c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|
|
2
2
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
3
|
export type ObjectCategory = 'block' | 'payload';
|
|
4
4
|
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
@@ -18,7 +18,7 @@ export declare class Huri<T extends Payload = Payload> {
|
|
|
18
18
|
protocol?: string;
|
|
19
19
|
token?: string;
|
|
20
20
|
private isHuri;
|
|
21
|
-
constructor(huri:
|
|
21
|
+
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
22
|
get href(): string;
|
|
23
23
|
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
24
|
static isHuri(value: unknown): Huri<{
|
package/dist/node/Huri.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,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,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,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;IA0BjF,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;;;IAO5B,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;IAwBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/node/Huri.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Hash } from '@xylabs/hex';
|
|
2
2
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
3
|
export type ObjectCategory = 'block' | 'payload';
|
|
4
4
|
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
@@ -18,7 +18,7 @@ export declare class Huri<T extends Payload = Payload> {
|
|
|
18
18
|
protocol?: string;
|
|
19
19
|
token?: string;
|
|
20
20
|
private isHuri;
|
|
21
|
-
constructor(huri:
|
|
21
|
+
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
22
|
get href(): string;
|
|
23
23
|
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
24
|
static isHuri(value: unknown): Huri<{
|
package/dist/node/Huri.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,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,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,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;IA0BjF,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;;;IAO5B,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;IAwBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/node/Huri.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Hash } from '@xylabs/hex';
|
|
2
2
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
3
|
export type ObjectCategory = 'block' | 'payload';
|
|
4
4
|
export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>;
|
|
@@ -18,7 +18,7 @@ export declare class Huri<T extends Payload = Payload> {
|
|
|
18
18
|
protocol?: string;
|
|
19
19
|
token?: string;
|
|
20
20
|
private isHuri;
|
|
21
|
-
constructor(huri:
|
|
21
|
+
constructor(huri: Hash | Huri | string, { archivistUri, token }?: HuriOptions);
|
|
22
22
|
get href(): string;
|
|
23
23
|
static fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined>;
|
|
24
24
|
static isHuri(value: unknown): Huri<{
|
package/dist/node/Huri.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Huri.d.ts","sourceRoot":"","sources":["../../src/Huri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,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,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,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;IA0BjF,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;;;IAO5B,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;IAwBjB,OAAO,CAAC,aAAa;CAUtB"}
|
package/dist/node/index.js
CHANGED
|
@@ -38,7 +38,7 @@ var Huri = class _Huri {
|
|
|
38
38
|
isHuri = true;
|
|
39
39
|
constructor(huri, { archivistUri, token } = {}) {
|
|
40
40
|
var _a;
|
|
41
|
-
const huriString = ((_a = _Huri.isHuri(huri)) == null ? void 0 : _a.href) ?? typeof huri === "string" ? huri : new import_account.AddressValue(huri).hex;
|
|
41
|
+
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;
|
|
42
42
|
this.originalHref = huriString;
|
|
43
43
|
const protocol = _Huri.parseProtocol(huriString);
|
|
44
44
|
this.protocol = protocol ?? "https";
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Huri.ts"],"sourcesContent":["export * from './Huri'\n","import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Huri.ts"],"sourcesContent":["export * from './Huri'\n","import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport { Hash } 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?: string\n hash: string\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 ?? typeof huri === 'string' ? (huri as string) : huri instanceof ArrayBuffer ? new AddressValue(huri).hex : 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 = this.parsePath(path, protocol !== undefined)\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 return undefined\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 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;AAEtB,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;AAxCrF;AAyCI,UAAM,eACJ,WAAK,OAAO,IAAI,MAAhB,mBAAmB,SAAQ,OAAO,SAAS,WAAY,OAAkB,gBAAgB,cAAc,IAAI,4BAAa,IAAI,EAAE,MAAM,KAAK;AAC3I,SAAK,eAAe;AAEpB,UAAM,WAAW,MAAK,cAAc,UAAU;AAC9C,SAAK,WAAW,YAAY;AAE5B,UAAM,WAAO,wBAAS,MAAK,UAAU,UAAU,GAAG,cAAc;AAChE,SAAK,OAAO,KAAK,UAAU,MAAM,aAAa,MAAS;AAGvD,QAAI,cAAc;AAChB,YAAM,oBAAoB,aAAa,MAAM,KAAK;AAClD,WAAK,WAAW,kBAAkB,CAAC;AACnC,WAAK,YAAY,kBAAkB,CAAC;AAAA,IACtC;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M;AACzC,kCAAS,cAAc,WAAW,GAAG,4BAA4B,WAAW,GAAG;AAC/E,kCAAS,cAAc,CAAC,EAAE,WAAW,GAAG,qCAAqC,WAAW,GAAG;AAC3F,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,gCAAS,EAAE,eAAe,UAAU,CAAC,EAAE,WAAW,IAAI,4BAA4B;AAGlF,cAAU,CAAC,EAAE,WAAW,IAAI,UAAU,MAAM,IAAI;AAGhD,UAAM,WAAO,wBAAS,UAAU,IAAI,GAAG,mBAAmB;AAG1D,SAAK,YAAY,UAAU,MAAM,KAAK;AAGtC,SAAK,UAAU,UAAU,IAAI;AAG7B,gCAAS,UAAU,WAAW,GAAG,qBAAqB;AAEtD,WAAO;AAAA,EACT;AAAA,EAEQ,gBAAgB;AApJ1B;AAsJI,kCAAS,UAAK,cAAL,mBAAgB,YAAW,GAAG,0BAA0B;AAGjE,kCAAS,UAAK,YAAL,mBAAc,YAAW,GAAG,wBAAwB;AAG7D,gCAAS,EAAE,KAAK,WAAW,CAAC,KAAK,YAAY,mDAAmD;AAAA,EAClG;AACF;","names":[]}
|
package/dist/node/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ var Huri = class _Huri {
|
|
|
12
12
|
isHuri = true;
|
|
13
13
|
constructor(huri, { archivistUri, token } = {}) {
|
|
14
14
|
var _a;
|
|
15
|
-
const huriString = ((_a = _Huri.isHuri(huri)) == null ? void 0 : _a.href) ?? typeof huri === "string" ? huri : new AddressValue(huri).hex;
|
|
15
|
+
const huriString = ((_a = _Huri.isHuri(huri)) == null ? void 0 : _a.href) ?? typeof huri === "string" ? huri : huri instanceof ArrayBuffer ? new AddressValue(huri).hex : huri.href;
|
|
16
16
|
this.originalHref = huriString;
|
|
17
17
|
const protocol = _Huri.parseProtocol(huriString);
|
|
18
18
|
this.protocol = protocol ?? "https";
|
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 {
|
|
1
|
+
{"version":3,"sources":["../../src/Huri.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { axios } from '@xylabs/axios'\nimport { Hash } 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?: string\n hash: string\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 ?? typeof huri === 'string' ? (huri as string) : huri instanceof ArrayBuffer ? new AddressValue(huri).hex : 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 = this.parsePath(path, protocol !== undefined)\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 return undefined\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 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;AAEtB,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;AAxCrF;AAyCI,UAAM,eACJ,WAAK,OAAO,IAAI,MAAhB,mBAAmB,SAAQ,OAAO,SAAS,WAAY,OAAkB,gBAAgB,cAAc,IAAI,aAAa,IAAI,EAAE,MAAM,KAAK;AAC3I,SAAK,eAAe;AAEpB,UAAM,WAAW,MAAK,cAAc,UAAU;AAC9C,SAAK,WAAW,YAAY;AAE5B,UAAM,OAAO,SAAS,MAAK,UAAU,UAAU,GAAG,cAAc;AAChE,SAAK,OAAO,KAAK,UAAU,MAAM,aAAa,MAAS;AAGvD,QAAI,cAAc;AAChB,YAAM,oBAAoB,aAAa,MAAM,KAAK;AAClD,WAAK,WAAW,kBAAkB,CAAC;AACnC,WAAK,YAAY,kBAAkB,CAAC;AAAA,IACtC;AAEA,SAAK,QAAQ;AAEb,SAAK,cAAc;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,UAAM,QAAkB,CAAC;AACzB,QAAI,KAAK,UAAU;AACjB,YAAM,KAAK,GAAG,KAAK,QAAQ,IAAI;AAAA,IACjC;AACA,QAAI,KAAK,SAAS;AAChB,YAA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A,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,4BAA4B;AAGlF,cAAU,CAAC,EAAE,WAAW,IAAI,UAAU,MAAM,IAAI;AAGhD,UAAM,OAAO,SAAS,UAAU,IAAI,GAAG,mBAAmB;AAG1D,SAAK,YAAY,UAAU,MAAM,KAAK;AAGtC,SAAK,UAAU,UAAU,IAAI;AAG7B,aAAS,UAAU,WAAW,GAAG,qBAAqB;AAEtD,WAAO;AAAA,EACT;AAAA,EAEQ,gBAAgB;AApJ1B;AAsJI,eAAS,UAAK,cAAL,mBAAgB,YAAW,GAAG,0BAA0B;AAGjE,eAAS,UAAK,YAAL,mBAAc,YAAW,GAAG,wBAAwB;AAG7D,aAAS,EAAE,KAAK,WAAW,CAAC,KAAK,YAAY,mDAAmD;AAAA,EAClG;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/assert": "^2.13.
|
|
14
|
-
"@xylabs/axios": "^2.13.
|
|
15
|
-
"@
|
|
16
|
-
"@xyo-network/
|
|
17
|
-
"@xyo-network/payload-model": "~2.81.
|
|
13
|
+
"@xylabs/assert": "^2.13.17",
|
|
14
|
+
"@xylabs/axios": "^2.13.17",
|
|
15
|
+
"@xylabs/hex": "^2.13.17",
|
|
16
|
+
"@xyo-network/account": "~2.81.9",
|
|
17
|
+
"@xyo-network/payload-model": "~2.81.9"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@xylabs/delay": "^2.13.
|
|
21
|
-
"@xylabs/ts-scripts-yarn3": "^3.2.
|
|
22
|
-
"@xylabs/tsconfig": "^3.2.
|
|
20
|
+
"@xylabs/delay": "^2.13.17",
|
|
21
|
+
"@xylabs/ts-scripts-yarn3": "^3.2.10",
|
|
22
|
+
"@xylabs/tsconfig": "^3.2.10",
|
|
23
23
|
"typescript": "^5.3.2"
|
|
24
24
|
},
|
|
25
25
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
},
|
|
63
63
|
"sideEffects": false,
|
|
64
64
|
"types": "dist/node/index.d.ts",
|
|
65
|
-
"version": "2.81.
|
|
65
|
+
"version": "2.81.9"
|
|
66
66
|
}
|
package/src/Huri.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { axios } from '@xylabs/axios'
|
|
3
|
+
import { Hash } from '@xylabs/hex'
|
|
3
4
|
import { AddressValue } from '@xyo-network/account'
|
|
4
|
-
import { DataLike } from '@xyo-network/core'
|
|
5
5
|
import { Payload } from '@xyo-network/payload-model'
|
|
6
6
|
|
|
7
7
|
export type ObjectCategory = 'block' | 'payload'
|
|
@@ -38,8 +38,9 @@ export class Huri<T extends Payload = Payload> {
|
|
|
38
38
|
|
|
39
39
|
private isHuri = true
|
|
40
40
|
|
|
41
|
-
constructor(huri:
|
|
42
|
-
const huriString =
|
|
41
|
+
constructor(huri: Hash | Huri | string, { archivistUri, token }: HuriOptions = {}) {
|
|
42
|
+
const huriString =
|
|
43
|
+
Huri.isHuri(huri)?.href ?? typeof huri === 'string' ? (huri as string) : huri instanceof ArrayBuffer ? new AddressValue(huri).hex : huri.href
|
|
43
44
|
this.originalHref = huriString
|
|
44
45
|
|
|
45
46
|
const protocol = Huri.parseProtocol(huriString)
|