34 lines
954 B
JavaScript
Executable File
34 lines
954 B
JavaScript
Executable File
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.HttpUrl = exports.Url = void 0;
|
|
const url_1 = require("url");
|
|
const __1 = require("..");
|
|
/**
|
|
* Decodes a string into the `URL` type
|
|
*/
|
|
exports.Url = __1.extendType(__1.string, {
|
|
displayName: 'url',
|
|
description: 'A valid URL',
|
|
async from(str) {
|
|
const url = new url_1.URL(str);
|
|
if (!url.protocol || !url.host) {
|
|
throw new Error('Malformed URL');
|
|
}
|
|
if (!['http:', 'https:'].includes(url.protocol)) {
|
|
throw new Error('Only allowed http and https URLs');
|
|
}
|
|
return url;
|
|
},
|
|
});
|
|
/**
|
|
* Decodes an http/https only URL
|
|
*/
|
|
exports.HttpUrl = __1.extendType(exports.Url, {
|
|
async from(url) {
|
|
if (!['http:', 'https:'].includes(url.protocol)) {
|
|
throw new Error('Only allowed http and https URLs');
|
|
}
|
|
return url;
|
|
},
|
|
});
|
|
//# sourceMappingURL=url.js.map
|