@xyo-network/huri 2.110.19 → 2.111.0

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.
@@ -1 +1 @@
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;IA+BjF,IAAI,IAAI,WAaP;WAEY,KAAK,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,S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AC1B,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"}
@@ -1 +1 @@
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' ? (huri as string)\n : huri instanceof ArrayBuffer ? 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 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;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4BAA4B;AAGxF,cAAU,CAAC,EAAE,WAAW,IAAI,UAAU,MAAM,IAAI;AAGhD,UAAM,WAAO,wBAAS,UAAU,IAAI,GAAG,MAAM,mBAAmB;AAGhE,SAAK,YAAY,UAAU,MAAM,KAAK;AAGtC,SAAK,UAAU,UAAU,IAAI;AAG7B,gCAAS,UAAU,WAAW,GAAG,MAAM,qBAAqB;AAE5D,WAAO;AAAA,EACT;AAAA,EAEQ,gBAAgB;AAEtB,gCAAS,KAAK,WAAW,WAAW,GAAG,MAAM,0BAA0B;AAGvE,gCAAS,KAAK,SAAS,WAAW,GAAG,MAAM,wBAAwB;AAGnE,gCAAS,EAAE,KAAK,WAAW,CAAC,KAAK,YAAY,MAAM,mDAAmD;AAAA,EACxG;AACF;","names":[]}
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,G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Huri = class _Huri {
99
99
  export {
100
100
  Huri
101
101
  };
102
- //# sourceMappingURL=index.js.map
102
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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;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,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;A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AK,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"}
@@ -1 +1 @@
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' ? (huri as string)\n : huri instanceof ArrayBuffer ? 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 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,aACJ,MAAK,OAAO,IAAI,GAAG,SAClB,OAAO,SAAS,WAAY,OAC3B,gBAAgB,cAAc,IAAI,4BAAa,IAAI,EAAE,MACrD,KAAK;AACT,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,UAAU,MAAM,aAAa,MAAS,GAAG,MAAM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Ac;AACzC,UAAM,gBAAgB,KAAK,MAAM,IAAI;AACrC,gCAAS,cAAc,UAAU,GAAG,MAAM,4BAA4B,cAAc,CAAC,CAAC,GAAG;AACzF,UAAM,cAAc,cAAc,WAAW,IAAI,cAAc,MAAM,IAAI;AACzE,QAAI,aAAa;AACf,YAAM,gBAAgB,aAAa,MAAM,GAAG;AAC5C,kCAAS,cAAc,WAAW,GAAG,MAAM,4BAA4B,WAAW,GAAG;AACrF,kCAAS,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,gCAAS,EAAE,eAAe,UAAU,CAAC,EAAE,WAAW,IAAI,MAAM,4BAA4B;AAGxF,cAAU,CAAC,EAAE,WAAW,IAAI,UAAU,MAAM,IAAI;AAGhD,UAAM,WAAO,wBAAS,UAAU,IAAI,GAAG,MAAM,mBAAmB;AAGhE,SAAK,YAAY,UAAU,MAAM,KAAK;AAGtC,SAAK,UAAU,UAAU,IAAI;AAG7B,gCAAS,UAAU,WAAW,GAAG,MAAM,qBAAqB;AAE5D,WAAO;AAAA,EACT;AAAA,EAEQ,gBAAgB;AAEtB,gCAAS,KAAK,WAAW,WAAW,GAAG,MAAM,0BAA0B;AAGvE,gCAAS,KAAK,SAAS,WAAW,GAAG,MAAM,wBAAwB;AAGnE,gCAAS,EAAE,KAAK,WAAW,CAAC,KAAK,YAAY,MAAM,mDAAmD;AAAA,EACxG;AACF;","names":[]}
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,UAAU,MAAM,aAAa,MAAS,GAAG,MAAM,cAAc;AAEvF,oCAAS,mBAAO,KAAK,IAAI,GAAG,MAAM,iBAAiB,KAAK,IAAI,GAAG;AAG/D,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,YAAM,KAAK,GAAG,KAAK,OAAO,EAAE;AAAA,IAC9B;AACA,QAAI,KA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KAAK;AAAA,EACd;AAAA,EAEQ,UAAU,MAAc,aAAsB;AACpD,UAAM,YAAY,KAAK,MAAM,GAAG;AAGhC,gCAAS,EAAE,eAAe,UAAU,CAAC,EAAE,WAAW,IAAI,MAAM,4BAA4B;AAIxF,cAAU,CAAC,EAAE,WAAW,IAAI,UAAU,MAAM,IAAI;AAGhD,UAAM,WAAO,wBAAS,UAAU,IAAI,GAAG,MAAM,mBAAmB;AAGhE,SAAK,YAAY,UAAU,MAAM,KAAK;AAGtC,SAAK,UAAU,UAAU,IAAI;AAG7B,gCAAS,UAAU,WAAW,GAAG,MAAM,qBAAqB;AAE5D,WAAO;AAAA,EACT;AAAA,EAEQ,gBAAgB;AAEtB,gCAAS,KAAK,WAAW,WAAW,GAAG,MAAM,0BAA0B;AAGvE,gCAAS,KAAK,SAAS,WAAW,GAAG,MAAM,wBAAwB;AAGnE,gCAAS,EAAE,KAAK,WAAW,CAAC,KAAK,YAAY,MAAM,mDAAmD;AAAA,EACxG;AACF;","names":[]}
@@ -99,4 +99,4 @@ var Huri = class _Huri {
99
99
  export {
100
100
  Huri
101
101
  };
102
- //# sourceMappingURL=index.js.map
102
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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;AACjF,UAAM,aACF,MAAK,OAAO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O,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"}
@@ -1 +1 @@
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' ? (huri as string)\n : huri instanceof ArrayBuffer ? 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 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')\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AK,MAAM,GAAG;AAGhC,gCAAS,EAAE,eAAe,UAAU,CAAC,EAAE,WAAW,IAAI,MAAM,4BAA4B;AAGxF,cAAU,CAAC,EAAE,WAAW,IAAI,UAAU,MAAM,IAAI;AAGhD,UAAM,WAAO,wBAAS,UAAU,IAAI,GAAG,MAAM,mBAAmB;AAGhE,SAAK,YAAY,UAAU,MAAM,KAAK;AAGtC,SAAK,UAAU,UAAU,IAAI;AAG7B,gCAAS,UAAU,WAAW,GAAG,MAAM,qBAAqB;AAE5D,WAAO;AAAA,EACT;AAAA,EAEQ,gBAAgB;AAxJ1B;AA0JI,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":[]}
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;AAxCrF;AAyCI,UAAM,eACF,WAAK,OAAO,IAAI,MAAhB,mBAAmB,UACjB,OAAO,SAAS,WACf,OACD,gBAAgB,cACd,IAAI,4BAAa,IAAI,EAAE,MACvB,KAAK;AAC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Ac,YAAW,GAAG,MAAM,wBAAwB;AAGnE,gCAAS,EAAE,KAAK,WAAW,CAAC,KAAK,YAAY,MAAM,mDAAmD;AAAA,EACxG;AACF;","names":[]}
@@ -101,4 +101,4 @@ var Huri = class _Huri {
101
101
  export {
102
102
  Huri
103
103
  };
104
- //# sourceMappingURL=index.js.map
104
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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;AAxCrF;AAyCI,UAAM,eACF,WAAK,OAAO,IAAI,MAAhB,mBAAmB,UACjB,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,WAAK,YAAY,kBAAkB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AgB,2CAAa,MAAM;AACzC,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;AA3J1B;AA6JI,eAAS,UAAK,cAAL,mBAAgB,YAAW,GAAG,MAAM,0BAA0B;AAGvE,eAAS,UAAK,YAAL,mBAAc,YAAW,GAAG,MAAM,wBAAwB;AAGnE,aAAS,EAAE,KAAK,WAAW,CAAC,KAAK,YAAY,MAAM,mDAAmD;AAAA,EACxG;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": "^3.6.6",
14
- "@xylabs/axios": "^3.6.6",
15
- "@xylabs/hex": "^3.6.6",
16
- "@xyo-network/account": "^2.110.19",
17
- "@xyo-network/payload-model": "^2.110.19"
13
+ "@xylabs/assert": "^3.6.8",
14
+ "@xylabs/axios": "^3.6.8",
15
+ "@xylabs/hex": "^3.6.8",
16
+ "@xyo-network/account": "^2.111.0",
17
+ "@xyo-network/payload-model": "^2.111.0"
18
18
  },
19
19
  "devDependencies": {
20
- "@xylabs/delay": "^3.6.6",
21
- "@xylabs/ts-scripts-yarn3": "^3.14.1",
22
- "@xylabs/tsconfig": "^3.14.1",
20
+ "@xylabs/delay": "^3.6.8",
21
+ "@xylabs/ts-scripts-yarn3": "^3.15.5",
22
+ "@xylabs/tsconfig": "^3.15.5",
23
23
  "typescript": "^5.5.4"
24
24
  },
25
25
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "import": {
34
34
  "types": "./dist/browser/index.d.mts",
35
- "default": "./dist/browser/index.js"
35
+ "default": "./dist/browser/index.mjs"
36
36
  }
37
37
  },
38
38
  "node": {
@@ -42,14 +42,14 @@
42
42
  },
43
43
  "import": {
44
44
  "types": "./dist/node/index.d.mts",
45
- "default": "./dist/node/index.js"
45
+ "default": "./dist/node/index.mjs"
46
46
  }
47
47
  }
48
48
  },
49
49
  "./package.json": "./package.json"
50
50
  },
51
51
  "main": "dist/node/index.cjs",
52
- "module": "dist/node/index.js",
52
+ "module": "dist/node/index.mjs",
53
53
  "homepage": "https://xyo.network",
54
54
  "license": "LGPL-3.0-only",
55
55
  "publishConfig": {
@@ -61,6 +61,6 @@
61
61
  },
62
62
  "sideEffects": false,
63
63
  "types": "dist/node/index.d.ts",
64
- "version": "2.110.19",
64
+ "version": "2.111.0",
65
65
  "type": "module"
66
66
  }
package/src/Huri.ts CHANGED
@@ -8,7 +8,7 @@ export type ObjectCategory = 'block' | 'payload'
8
8
 
9
9
  export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>
10
10
 
11
- /*
11
+ /*
12
12
  Valid Huri:
13
13
 
14
14
  [<protocol>://][<archivist>/[<archive>/]]<hash>
@@ -39,11 +39,13 @@ export class Huri<T extends Payload = Payload> {
39
39
  private isHuri = true
40
40
 
41
41
  constructor(huri: Hash | Huri | string, { archivistUri, token }: HuriOptions = {}) {
42
- const huriString =
43
- Huri.isHuri(huri)?.href ??
44
- (typeof huri === 'string' ? (huri as string)
45
- : huri instanceof ArrayBuffer ? new AddressValue(huri).hex
46
- : huri.href)
42
+ const huriString
43
+ = Huri.isHuri(huri)?.href
44
+ ?? (typeof huri === 'string'
45
+ ? (huri as string)
46
+ : huri instanceof ArrayBuffer
47
+ ? new AddressValue(huri).hex
48
+ : huri.href)
47
49
  this.originalHref = huriString
48
50
 
49
51
  const protocol = Huri.parseProtocol(huriString)
@@ -54,7 +56,7 @@ export class Huri<T extends Payload = Payload> {
54
56
 
55
57
  assertEx(isHash(this.hash), () => `Invalid hash [${this.hash}]`)
56
58
 
57
- //if archivistUri sent, overwrite protocol and archivist
59
+ // if archivistUri sent, overwrite protocol and archivist
58
60
  if (archivistUri) {
59
61
  const archivistUriParts = archivistUri.split('://')
60
62
  this.protocol = archivistUriParts[0]
@@ -129,35 +131,36 @@ export class Huri<T extends Payload = Payload> {
129
131
  private parsePath(path: string, hasProtocol: boolean) {
130
132
  const pathParts = path.split('/')
131
133
 
132
- //if the protocol was found, then there is not allowed to be a leading /
134
+ // if the protocol was found, then there is not allowed to be a leading /
133
135
  assertEx(!(hasProtocol && pathParts[0].length === 0), () => 'Invalid protocol separator')
134
136
 
135
- //remove leading '/' if needed
137
+ // remove leading '/' if needed
138
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
136
139
  pathParts[0].length === 0 ? pathParts.shift() : null
137
140
 
138
- //hash is assumed to be the last part
141
+ // hash is assumed to be the last part
139
142
  const hash = assertEx(pathParts.pop(), () => 'No hash specified')
140
143
 
141
- //archivist is assumed to be the first part
144
+ // archivist is assumed to be the first part
142
145
  this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'
143
146
 
144
- //the archive is whatever is left
147
+ // the archive is whatever is left
145
148
  this.archive = pathParts.pop()
146
149
 
147
- //after we pull off all the path parts, there should be nothing left
150
+ // after we pull off all the path parts, there should be nothing left
148
151
  assertEx(pathParts.length === 0, () => 'Too many path parts')
149
152
 
150
153
  return hash
151
154
  }
152
155
 
153
156
  private validateParse() {
154
- //the archivist should not be zero length
157
+ // the archivist should not be zero length
155
158
  assertEx(this.archivist?.length !== 0, () => 'Invalid archivist length')
156
159
 
157
- //the archivist should not be zero length (can be undefined)
160
+ // the archivist should not be zero length (can be undefined)
158
161
  assertEx(this.archive?.length !== 0, () => 'Invalid archive length')
159
162
 
160
- //the archive should not be set if the archivist is not set
163
+ // the archive should not be set if the archivist is not set
161
164
  assertEx(!(this.archive && !this.archivist), () => 'If specifying archive, archivist is also required')
162
165
  }
163
166
  }
@@ -1 +0,0 @@
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' ? (huri as string)\n : huri instanceof ArrayBuffer ? 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 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,aACJ,MAAK,OAAO,IAAI,GAAG,SAClB,OAAO,SAAS,WAAY,OAC3B,gBAAgB,cAAc,IAAI,aAAa,IAAI,EAAE,MACrD,KAAK;AACT,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,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M,4BAA4B,cAAc,CAAC,CAAC,GAAG;AACzF,UAAM,cAAc,cAAc,WAAW,IAAI,cAAc,MAAM,IAAI;AACzE,QAAI,aAAa;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;AAGxF,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":[]}
@@ -1 +0,0 @@
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' ? (huri as string)\n : huri instanceof ArrayBuffer ? 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 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,a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AAW,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":[]}
@@ -1 +0,0 @@
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' ? (huri as string)\n : huri instanceof ArrayBuffer ? 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 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;AAxCrF;AAyCI,UAAM,eACJ,WAAK,OAAO,IAAI,MAAhB,mBAAmB,UAClB,OAAO,SAAS,WAAY,OAC3B,gBAAgB,cAAc,IAAI,aAAa,IAAI,EAAE,MACrD,KAAK;AACT,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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