@polywrap/core-js
Advanced tools
Comparing version 0.10.1 to 0.11.0
@@ -13,11 +13,19 @@ import { Result } from "@polywrap/result"; | ||
* A Polywrap URI. Some examples of valid URIs are: | ||
* wrap://https/domain.com | ||
* wrap://ipfs/QmHASH | ||
* wrap://ens/sub.dimain.eth | ||
* wrap://fs/directory/file.txt | ||
* wrap://uns/domain.crypto | ||
* wrap://ens/sub.domain.eth | ||
* wrap://file/directory/file.txt | ||
* | ||
* Some example short-hand URIs (utilizing inference): | ||
* ipfs/QmHASH -> wrap://ipfs/QmHASH | ||
* https://domain.com -> wrap://https/domain.com | ||
* | ||
* URI inference is performed in the following ways: | ||
* 1. If wrap:// is missing, it will be added. | ||
* 2. If non-wrap schema exists, it becomes the authority. | ||
* | ||
* Breaking down the various parts of the URI, as it applies | ||
* to [the URI standard](https://tools.ietf.org/html/rfc3986#section-3): | ||
* **wrap://** - URI Scheme: differentiates Polywrap URIs. | ||
* **ipfs/** - URI Authority: allows the Polywrap URI resolution algorithm to determine an authoritative URI resolver. | ||
* **ens/** - URI Authority: allows the Polywrap URI resolution algorithm to determine an authoritative URI resolver. | ||
* **sub.domain.eth** - URI Path: tells the Authority where the Wrapper resides. | ||
@@ -63,3 +71,3 @@ */ | ||
*/ | ||
static parseUri(uri: string): Result<UriConfig, Error>; | ||
static parseUri(input: string): Result<UriConfig, Error>; | ||
/** | ||
@@ -66,0 +74,0 @@ * Construct a Uri instance from a Uri or a wrap URI string |
@@ -9,11 +9,19 @@ "use strict"; | ||
* A Polywrap URI. Some examples of valid URIs are: | ||
* wrap://https/domain.com | ||
* wrap://ipfs/QmHASH | ||
* wrap://ens/sub.dimain.eth | ||
* wrap://fs/directory/file.txt | ||
* wrap://uns/domain.crypto | ||
* wrap://ens/sub.domain.eth | ||
* wrap://file/directory/file.txt | ||
* | ||
* Some example short-hand URIs (utilizing inference): | ||
* ipfs/QmHASH -> wrap://ipfs/QmHASH | ||
* https://domain.com -> wrap://https/domain.com | ||
* | ||
* URI inference is performed in the following ways: | ||
* 1. If wrap:// is missing, it will be added. | ||
* 2. If non-wrap schema exists, it becomes the authority. | ||
* | ||
* Breaking down the various parts of the URI, as it applies | ||
* to [the URI standard](https://tools.ietf.org/html/rfc3986#section-3): | ||
* **wrap://** - URI Scheme: differentiates Polywrap URIs. | ||
* **ipfs/** - URI Authority: allows the Polywrap URI resolution algorithm to determine an authoritative URI resolver. | ||
* **ens/** - URI Authority: allows the Polywrap URI resolution algorithm to determine an authoritative URI resolver. | ||
* **sub.domain.eth** - URI Path: tells the Authority where the Wrapper resides. | ||
@@ -100,42 +108,60 @@ */ | ||
*/ | ||
Uri.parseUri = function (uri) { | ||
if (!uri) { | ||
return (0, result_1.ResultErr)(Error("The provided URI is empty")); | ||
Uri.parseUri = function (input) { | ||
var authorityDelimiter = "/"; | ||
var schemeDelimiter = "://"; | ||
var wrapScheme = "wrap://"; | ||
var validUriExamples = "wrap://ipfs/QmHASH\n" + | ||
"wrap://ens/domain.eth\n" + | ||
"ipfs/QmHASH\n" + | ||
"ens/domain.eth\n" + | ||
"https://domain.com/path\n\n"; | ||
if (!input) { | ||
return (0, result_1.ResultErr)(Error("The provided URI is empty, here are some examples of valid URIs:\n" + | ||
validUriExamples)); | ||
} | ||
var processed = uri; | ||
// Trim preceding '/' characters | ||
while (processed[0] === "/") { | ||
processed = processed.substring(1); | ||
var processedUri = input.trim(); | ||
// Remove leading "/" | ||
if (processedUri.startsWith(authorityDelimiter)) { | ||
processedUri = processedUri.substring(1); | ||
} | ||
// Check for the wrap:// scheme, add if it isn't there | ||
var wrapSchemeIdx = processed.indexOf("wrap://"); | ||
// If it's missing the wrap:// scheme, add it | ||
if (wrapSchemeIdx === -1) { | ||
processed = "wrap://" + processed; | ||
// Check if the string starts with a non-wrap URI scheme | ||
if (!processedUri.startsWith(wrapScheme)) { | ||
var schemeIndex = processedUri.indexOf(schemeDelimiter); | ||
var authorityIndex = processedUri.indexOf(authorityDelimiter); | ||
if (schemeIndex !== -1) { | ||
// Make sure the string before the scheme doesn't contain an authority | ||
if (!(authorityIndex !== -1 && schemeIndex > authorityIndex)) { | ||
processedUri = | ||
processedUri.substring(0, schemeIndex) + | ||
"/" + | ||
processedUri.substring(schemeIndex + schemeDelimiter.length); | ||
} | ||
} | ||
} | ||
// If the wrap:// is not in the beginning, return an error | ||
if (wrapSchemeIdx > -1 && wrapSchemeIdx !== 0) { | ||
return (0, result_1.ResultErr)(Error("The wrap:// scheme must be at the beginning of the URI string")); | ||
else { | ||
processedUri = processedUri.substring(wrapScheme.length); | ||
} | ||
// Extract the authoriy & path | ||
var result = processed.match(/wrap:\/\/([a-z][a-z0-9-_]+)\/(.*)/); | ||
var uriParts; | ||
// Remove all empty strings | ||
if (result) { | ||
uriParts = result.filter(function (str) { return !!str; }); | ||
// Split the string into parts, using "/" as a delimeter | ||
var parts = processedUri.split(authorityDelimiter); | ||
if (parts.length < 2) { | ||
return (0, result_1.ResultErr)(Error("URI authority is missing, here are some examples of valid URIs:\n" + | ||
validUriExamples + | ||
"Invalid URI Received: ".concat(input))); | ||
} | ||
else { | ||
uriParts = []; | ||
// Extract the authority and path | ||
var authority = parts[0]; | ||
var path = parts.slice(1).join("/"); | ||
if (!path) { | ||
return (0, result_1.ResultErr)(Error("URI path is missing, here are some examples of valid URIs:\n" + | ||
validUriExamples + | ||
"Invalid URI Received: ".concat(input))); | ||
} | ||
if (uriParts.length !== 3) { | ||
return (0, result_1.ResultErr)(Error("URI is malformed, here are some examples of valid URIs:\n" + | ||
"wrap://ipfs/QmHASH\n" + | ||
"wrap://ens/domain.eth\n" + | ||
"ens/domain.eth\n\n" + | ||
"Invalid URI Received: ".concat(uri))); | ||
// Add "wrap://" if not already present | ||
if (!processedUri.startsWith("wrap://")) { | ||
processedUri = "wrap://" + processedUri; | ||
} | ||
return (0, result_1.ResultOk)({ | ||
uri: processed, | ||
authority: uriParts[1], | ||
path: uriParts[2], | ||
uri: processedUri, | ||
authority: authority, | ||
path: path, | ||
}); | ||
@@ -142,0 +168,0 @@ }; |
@@ -124,3 +124,3 @@ "use strict"; | ||
var result = WrapError.re.exec(error); | ||
if (!result) { | ||
if (!result || !result.groups) { | ||
return undefined; | ||
@@ -127,0 +127,0 @@ } |
export * from "./combinePaths"; | ||
export * from "./getEnvFromUriHistory"; | ||
export * from "./getEnvFromResolutionPath"; | ||
export * from "./is-buffer"; | ||
export * from "./typesHandler"; | ||
export * from "./RegExpGroups"; |
@@ -18,5 +18,6 @@ "use strict"; | ||
__exportStar(require("./combinePaths"), exports); | ||
__exportStar(require("./getEnvFromUriHistory"), exports); | ||
__exportStar(require("./getEnvFromResolutionPath"), exports); | ||
__exportStar(require("./is-buffer"), exports); | ||
__exportStar(require("./typesHandler"), exports); | ||
__exportStar(require("./RegExpGroups"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@polywrap/core-js", | ||
"description": "Polywrap JavaScript Core", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"license": "MIT", | ||
@@ -26,5 +26,5 @@ "repository": { | ||
"dependencies": { | ||
"@polywrap/result": "0.10.1", | ||
"@polywrap/tracing-js": "0.10.1", | ||
"@polywrap/wrap-manifest-types-js": "0.10.1" | ||
"@polywrap/result": "0.11.0", | ||
"@polywrap/tracing-js": "0.11.0", | ||
"@polywrap/wrap-manifest-types-js": "0.11.0" | ||
}, | ||
@@ -43,3 +43,2 @@ "devDependencies": { | ||
}, | ||
"gitHead": "7346adaf5adb7e6bbb70d9247583e995650d390a", | ||
"publishConfig": { | ||
@@ -46,0 +45,0 @@ "access": "public" |
@@ -342,11 +342,19 @@ # @polywrap/core-js | ||
* A Polywrap URI. Some examples of valid URIs are: | ||
* wrap://https/domain.com | ||
* wrap://ipfs/QmHASH | ||
* wrap://ens/sub.dimain.eth | ||
* wrap://fs/directory/file.txt | ||
* wrap://uns/domain.crypto | ||
* wrap://ens/sub.domain.eth | ||
* wrap://file/directory/file.txt | ||
* | ||
* Some example short-hand URIs (utilizing inference): | ||
* ipfs/QmHASH -> wrap://ipfs/QmHASH | ||
* https://domain.com -> wrap://https/domain.com | ||
* | ||
* URI inference is performed in the following ways: | ||
* 1. If wrap:// is missing, it will be added. | ||
* 2. If non-wrap schema exists, it becomes the authority. | ||
* | ||
* Breaking down the various parts of the URI, as it applies | ||
* to [the URI standard](https://tools.ietf.org/html/rfc3986#section-3): | ||
* **wrap://** - URI Scheme: differentiates Polywrap URIs. | ||
* **ipfs/** - URI Authority: allows the Polywrap URI resolution algorithm to determine an authoritative URI resolver. | ||
* **ens/** - URI Authority: allows the Polywrap URI resolution algorithm to determine an authoritative URI resolver. | ||
* **sub.domain.eth** - URI Path: tells the Authority where the Wrapper resides. | ||
@@ -435,3 +443,3 @@ */ | ||
*/ | ||
public static parseUri(uri: string): Result<UriConfig, Error> | ||
public static parseUri(input: string): Result<UriConfig, Error> | ||
``` | ||
@@ -438,0 +446,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
141822
116
2209
720
+ Added@polywrap/msgpack-js@0.11.0(transitive)
+ Added@polywrap/result@0.11.0(transitive)
+ Added@polywrap/tracing-js@0.11.0(transitive)
+ Added@polywrap/wrap-manifest-types-js@0.11.0(transitive)
+ Addedajv@8.12.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addeduri-js@4.4.1(transitive)
- Removed@apidevtools/json-schema-ref-parser@9.0.9(transitive)
- Removed@jsdevtools/ono@7.1.3(transitive)
- Removed@polywrap/msgpack-js@0.10.1(transitive)
- Removed@polywrap/result@0.10.1(transitive)
- Removed@polywrap/tracing-js@0.10.1(transitive)
- Removed@polywrap/wrap-manifest-types-js@0.10.1(transitive)
- Removed@types/json-schema@7.0.15(transitive)
- Removedargparse@2.0.1(transitive)
- Removedcall-me-maybe@1.0.2(transitive)
- Removedjs-yaml@4.1.0(transitive)
- Removedjsonschema@1.4.0(transitive)
Updated@polywrap/result@0.11.0
Updated@polywrap/tracing-js@0.11.0