@es-git/load-as-mixin
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,6 +0,10 @@ | ||
import { Constructor, Hash, Type } from '@es-git/core'; | ||
import { IObjectRepo, GitObject } from '@es-git/object-mixin'; | ||
import { Constructor, Hash } from '@es-git/core'; | ||
import { IObjectRepo, BlobObject, TextObject, TreeObject, CommitObject, TagObject } from '@es-git/object-mixin'; | ||
export interface ILoadAsRepo { | ||
loadAs(hash: Hash, type: Type): Promise<GitObject>; | ||
loadBlob(hash: Hash): Promise<BlobObject>; | ||
loadText(hash: Hash): Promise<TextObject>; | ||
loadTree(hash: Hash): Promise<TreeObject>; | ||
loadCommit(hash: Hash): Promise<CommitObject>; | ||
loadTag(hash: Hash): Promise<TagObject>; | ||
} | ||
export default function loadAsMixin<T extends Constructor<IObjectRepo>>(repo: T): T & Constructor<ILoadAsRepo>; |
@@ -0,13 +1,50 @@ | ||
import { Type } from '@es-git/core'; | ||
import { blobToText } from '@es-git/object-mixin'; | ||
export default function loadAsMixin(repo) { | ||
return class LoadAsRepo extends repo { | ||
async loadAs(hash, type) { | ||
async loadBlob(hash) { | ||
const object = await super.loadObject(hash); | ||
if (!object) | ||
throw new Error(`Object for hash ${hash} does not exist`); | ||
if (object.type !== type) | ||
throw new Error(`Expected object with hash ${hash} to be ${type} but it was ${object.type}`); | ||
if (object.type !== Type.blob) | ||
throw new Error(`Expected object with hash ${hash} to be blob but it was ${object.type}`); | ||
return object; | ||
} | ||
async loadText(hash) { | ||
const object = await super.loadObject(hash); | ||
if (!object) | ||
throw new Error(`Object for hash ${hash} does not exist`); | ||
if (object.type !== Type.blob) | ||
throw new Error(`Expected object with hash ${hash} to be blob but it was ${object.type}`); | ||
return { | ||
type: 'text', | ||
body: blobToText(object.body) | ||
}; | ||
} | ||
async loadTree(hash) { | ||
const object = await super.loadObject(hash); | ||
if (!object) | ||
throw new Error(`Object for hash ${hash} does not exist`); | ||
if (object.type !== Type.tree) | ||
throw new Error(`Expected object with hash ${hash} to be tree but it was ${object.type}`); | ||
return object; | ||
} | ||
async loadCommit(hash) { | ||
const object = await super.loadObject(hash); | ||
if (!object) | ||
throw new Error(`Object for hash ${hash} does not exist`); | ||
if (object.type !== Type.commit) | ||
throw new Error(`Expected object with hash ${hash} to be commit but it was ${object.type}`); | ||
return object; | ||
} | ||
async loadTag(hash) { | ||
const object = await super.loadObject(hash); | ||
if (!object) | ||
throw new Error(`Object for hash ${hash} does not exist`); | ||
if (object.type !== Type.tag) | ||
throw new Error(`Expected object with hash ${hash} to be tag but it was ${object.type}`); | ||
return object; | ||
} | ||
}; | ||
} | ||
//# sourceMappingURL=index.js.map |
243
js/index.js
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -7,35 +7,35 @@ Object.defineProperty(exports, "__esModule", { | ||
var _regenerator = require("babel-runtime/regenerator"); | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _newArrowCheck2 = require("babel-runtime/helpers/newArrowCheck"); | ||
var _newArrowCheck2 = require('babel-runtime/helpers/newArrowCheck'); | ||
var _newArrowCheck3 = _interopRequireDefault(_newArrowCheck2); | ||
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator"); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of"); | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require("babel-runtime/helpers/createClass"); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn"); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _get2 = require("babel-runtime/helpers/get"); | ||
var _get2 = require('babel-runtime/helpers/get'); | ||
var _get3 = _interopRequireDefault(_get2); | ||
var _inherits2 = require("babel-runtime/helpers/inherits"); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
@@ -46,2 +46,6 @@ var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _core = require('@es-git/core'); | ||
var _objectMixin = require('@es-git/object-mixin'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -61,7 +65,7 @@ | ||
(0, _createClass3.default)(LoadAsRepo, [{ | ||
key: "loadAs", | ||
key: 'loadBlob', | ||
value: function () { | ||
(0, _newArrowCheck3.default)(this, _this2); | ||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(hash, type) { | ||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(hash) { | ||
var object; | ||
@@ -73,3 +77,3 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
_context.next = 2; | ||
return (0, _get3.default)(LoadAsRepo.prototype.__proto__ || (0, _getPrototypeOf2.default)(LoadAsRepo.prototype), "loadObject", this).call(this, hash); | ||
return (0, _get3.default)(LoadAsRepo.prototype.__proto__ || (0, _getPrototypeOf2.default)(LoadAsRepo.prototype), 'loadObject', this).call(this, hash); | ||
@@ -84,6 +88,6 @@ case 2: | ||
throw new Error("Object for hash " + String(hash) + " does not exist"); | ||
throw new Error('Object for hash ' + String(hash) + ' does not exist'); | ||
case 5: | ||
if (!(object.type !== type)) { | ||
if (!(object.type !== _core.Type.blob)) { | ||
_context.next = 7; | ||
@@ -93,9 +97,9 @@ break; | ||
throw new Error("Expected object with hash " + String(hash) + " to be " + String(type) + " but it was " + String(object.type)); | ||
throw new Error('Expected object with hash ' + String(hash) + ' to be blob but it was ' + String(object.type)); | ||
case 7: | ||
return _context.abrupt("return", object); | ||
return _context.abrupt('return', object); | ||
case 8: | ||
case "end": | ||
case 'end': | ||
return _context.stop(); | ||
@@ -107,8 +111,207 @@ } | ||
function loadAs(_x, _x2) { | ||
function loadBlob(_x) { | ||
return _ref.apply(this, arguments); | ||
} | ||
return loadAs; | ||
return loadBlob; | ||
}.bind(_this2)() | ||
}, { | ||
key: 'loadText', | ||
value: function () { | ||
(0, _newArrowCheck3.default)(this, _this2); | ||
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(hash) { | ||
var object; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return (0, _get3.default)(LoadAsRepo.prototype.__proto__ || (0, _getPrototypeOf2.default)(LoadAsRepo.prototype), 'loadObject', this).call(this, hash); | ||
case 2: | ||
object = _context2.sent; | ||
if (object) { | ||
_context2.next = 5; | ||
break; | ||
} | ||
throw new Error('Object for hash ' + String(hash) + ' does not exist'); | ||
case 5: | ||
if (!(object.type !== _core.Type.blob)) { | ||
_context2.next = 7; | ||
break; | ||
} | ||
throw new Error('Expected object with hash ' + String(hash) + ' to be blob but it was ' + String(object.type)); | ||
case 7: | ||
return _context2.abrupt('return', { | ||
type: 'text', | ||
body: (0, _objectMixin.blobToText)(object.body) | ||
}); | ||
case 8: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
function loadText(_x2) { | ||
return _ref2.apply(this, arguments); | ||
} | ||
return loadText; | ||
}.bind(_this2)() | ||
}, { | ||
key: 'loadTree', | ||
value: function () { | ||
(0, _newArrowCheck3.default)(this, _this2); | ||
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(hash) { | ||
var object; | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return (0, _get3.default)(LoadAsRepo.prototype.__proto__ || (0, _getPrototypeOf2.default)(LoadAsRepo.prototype), 'loadObject', this).call(this, hash); | ||
case 2: | ||
object = _context3.sent; | ||
if (object) { | ||
_context3.next = 5; | ||
break; | ||
} | ||
throw new Error('Object for hash ' + String(hash) + ' does not exist'); | ||
case 5: | ||
if (!(object.type !== _core.Type.tree)) { | ||
_context3.next = 7; | ||
break; | ||
} | ||
throw new Error('Expected object with hash ' + String(hash) + ' to be tree but it was ' + String(object.type)); | ||
case 7: | ||
return _context3.abrupt('return', object); | ||
case 8: | ||
case 'end': | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, this); | ||
})); | ||
function loadTree(_x3) { | ||
return _ref3.apply(this, arguments); | ||
} | ||
return loadTree; | ||
}.bind(_this2)() | ||
}, { | ||
key: 'loadCommit', | ||
value: function () { | ||
(0, _newArrowCheck3.default)(this, _this2); | ||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(hash) { | ||
var object; | ||
return _regenerator2.default.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
_context4.next = 2; | ||
return (0, _get3.default)(LoadAsRepo.prototype.__proto__ || (0, _getPrototypeOf2.default)(LoadAsRepo.prototype), 'loadObject', this).call(this, hash); | ||
case 2: | ||
object = _context4.sent; | ||
if (object) { | ||
_context4.next = 5; | ||
break; | ||
} | ||
throw new Error('Object for hash ' + String(hash) + ' does not exist'); | ||
case 5: | ||
if (!(object.type !== _core.Type.commit)) { | ||
_context4.next = 7; | ||
break; | ||
} | ||
throw new Error('Expected object with hash ' + String(hash) + ' to be commit but it was ' + String(object.type)); | ||
case 7: | ||
return _context4.abrupt('return', object); | ||
case 8: | ||
case 'end': | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, this); | ||
})); | ||
function loadCommit(_x4) { | ||
return _ref4.apply(this, arguments); | ||
} | ||
return loadCommit; | ||
}.bind(_this2)() | ||
}, { | ||
key: 'loadTag', | ||
value: function () { | ||
(0, _newArrowCheck3.default)(this, _this2); | ||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(hash) { | ||
var object; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return (0, _get3.default)(LoadAsRepo.prototype.__proto__ || (0, _getPrototypeOf2.default)(LoadAsRepo.prototype), 'loadObject', this).call(this, hash); | ||
case 2: | ||
object = _context5.sent; | ||
if (object) { | ||
_context5.next = 5; | ||
break; | ||
} | ||
throw new Error('Object for hash ' + String(hash) + ' does not exist'); | ||
case 5: | ||
if (!(object.type !== _core.Type.tag)) { | ||
_context5.next = 7; | ||
break; | ||
} | ||
throw new Error('Expected object with hash ' + String(hash) + ' to be tag but it was ' + String(object.type)); | ||
case 7: | ||
return _context5.abrupt('return', object); | ||
case 8: | ||
case 'end': | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
})); | ||
function loadTag(_x5) { | ||
return _ref5.apply(this, arguments); | ||
} | ||
return loadTag; | ||
}.bind(_this2)() | ||
}]); | ||
@@ -115,0 +318,0 @@ return LoadAsRepo; |
{ | ||
"name": "@es-git/load-as-mixin", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
import { Constructor, Hash, Type } from '@es-git/core'; | ||
import { IObjectRepo, GitObject } from '@es-git/object-mixin'; | ||
import { IObjectRepo, GitObject, BlobObject, TextObject, TreeObject, CommitObject, TagObject, blobToText } from '@es-git/object-mixin'; | ||
export interface ILoadAsRepo { | ||
loadAs(hash : Hash, type : Type) : Promise<GitObject> | ||
loadBlob(hash : Hash) : Promise<BlobObject> | ||
loadText(hash : Hash) : Promise<TextObject> | ||
loadTree(hash : Hash) : Promise<TreeObject> | ||
loadCommit(hash : Hash) : Promise<CommitObject> | ||
loadTag(hash : Hash) : Promise<TagObject> | ||
} | ||
@@ -11,10 +15,40 @@ | ||
return class LoadAsRepo extends repo implements ILoadAsRepo { | ||
async loadBlob(hash : Hash) { | ||
const object = await super.loadObject(hash); | ||
if(!object) throw new Error(`Object for hash ${hash} does not exist`); | ||
if(object.type !== Type.blob) throw new Error(`Expected object with hash ${hash} to be blob but it was ${object.type}`); | ||
return object; | ||
} | ||
async loadAs(hash : Hash, type : Type) { | ||
async loadText(hash : Hash) { | ||
const object = await super.loadObject(hash); | ||
if(!object) throw new Error(`Object for hash ${hash} does not exist`); | ||
if(object.type !== type) throw new Error(`Expected object with hash ${hash} to be ${type} but it was ${object.type}`); | ||
return object | ||
if(object.type !== Type.blob) throw new Error(`Expected object with hash ${hash} to be blob but it was ${object.type}`); | ||
return { | ||
type: 'text' as 'text', | ||
body: blobToText(object.body) | ||
}; | ||
} | ||
async loadTree(hash : Hash) { | ||
const object = await super.loadObject(hash); | ||
if(!object) throw new Error(`Object for hash ${hash} does not exist`); | ||
if(object.type !== Type.tree) throw new Error(`Expected object with hash ${hash} to be tree but it was ${object.type}`); | ||
return object; | ||
} | ||
async loadCommit(hash : Hash) { | ||
const object = await super.loadObject(hash); | ||
if(!object) throw new Error(`Object for hash ${hash} does not exist`); | ||
if(object.type !== Type.commit) throw new Error(`Expected object with hash ${hash} to be commit but it was ${object.type}`); | ||
return object; | ||
} | ||
async loadTag(hash : Hash) { | ||
const object = await super.loadObject(hash); | ||
if(!object) throw new Error(`Object for hash ${hash} does not exist`); | ||
if(object.type !== Type.tag) throw new Error(`Expected object with hash ${hash} to be tag but it was ${object.type}`); | ||
return object; | ||
} | ||
} | ||
} |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36228
350
1