@platform/cell.schema
Version:
URI and database schemas for the `cell.os`.
30 lines (29 loc) • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toRemoteImport = exports.toRemoteEntryUrl = void 0;
var ManifestUrl_parse_1 = require("./ManifestUrl.parse");
function toRemoteEntryUrl(url, manifest) {
var _a, _b, _c, _d;
if (!manifest)
return '';
var parts = typeof url === 'string' ? (0, ManifestUrl_parse_1.parse)(url) : url;
if (parts.error)
throw new Error("Failed to derive remote-entry URL. ".concat(parts.error));
var entry = (((_b = (_a = manifest === null || manifest === void 0 ? void 0 : manifest.module) === null || _a === void 0 ? void 0 : _a.remote) === null || _b === void 0 ? void 0 : _b.entry) || '').trim();
if (!entry)
return '';
var res = "".concat(parts.protocol, "://").concat(parts.domain);
if (parts.dir)
res = "".concat(res, "/").concat(parts.dir);
return "".concat(res, "/").concat(((_d = (_c = manifest === null || manifest === void 0 ? void 0 : manifest.module) === null || _c === void 0 ? void 0 : _c.remote) === null || _d === void 0 ? void 0 : _d.entry) || '');
}
exports.toRemoteEntryUrl = toRemoteEntryUrl;
function toRemoteImport(url, manifest, entry) {
var _a;
return {
url: toRemoteEntryUrl(url, manifest),
namespace: ((_a = manifest === null || manifest === void 0 ? void 0 : manifest.module) === null || _a === void 0 ? void 0 : _a.namespace) || '',
entry: entry,
};
}
exports.toRemoteImport = toRemoteImport;