@platform/cell.schema
Version:
URI and database schemas for the `cell.os`.
37 lines (36 loc) • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var common_1 = require("../common");
var FileLinks_1 = require("./FileLinks");
var Uri_1 = require("../Uri");
var FileSchema = (function () {
function FileSchema(args) {
this.type = 'FILE';
this.fileid = args.fileid;
this.path = args.nsPath + "/" + this.type + "/" + this.fileid;
this.uri = args.uri;
}
FileSchema.uri = function (args) {
var path = (args.path || '').trim();
var parts = path.split('/');
if (parts[0] !== 'NS') {
throw new Error("The DB path does not start with 'NS/'. Given '" + path + "'.");
}
if (parts[2] !== 'FILE') {
throw new Error("The DB path does not contain '/FILE/'. Given '" + path + "'.");
}
var ns = parts[1];
var file = parts[3];
return Uri_1.Uri.create.file(ns, file);
};
FileSchema.toFileLocation = function (input) {
if (input === void 0) { input = ''; }
input = input.trim();
return common_1.isHttp(input) ? input : "file://" + input;
};
FileSchema.links = FileLinks_1.FileLinks;
FileSchema.ERROR = common_1.ERROR;
FileSchema.create = function (args) { return new FileSchema(args); };
return FileSchema;
}());
exports.FileSchema = FileSchema;