Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@es-git/checkout-mixin

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@es-git/checkout-mixin - npm Package Compare versions

Comparing version 0.9.0 to 0.10.0

jest.config.js

0

es/index.d.ts

@@ -0,0 +0,0 @@ import { Constructor, IRawRepo, Hash } from '@es-git/core';

38

es/index.js

@@ -1,8 +0,1 @@

var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
import { Type, Mode, isFile, decode } from '@es-git/core';

@@ -15,3 +8,2 @@ export default function checkoutMixin(repo) {

async checkoutCommit(hash) {
var e_1, _a;
const commit = await super.loadObject(hash);

@@ -23,24 +15,14 @@ if (!commit)

const result = { files: {}, folders: {}, hash: commit.body.tree };
try {
for (var _b = __asyncValues(super.walkTree(commit.body.tree)), _c; _c = await _b.next(), !_c.done;) {
const { path, mode, hash } = await _c.value;
if (isFile(mode)) {
const file = await super.loadObject(hash);
if (!file)
throw new Error(`Cannot find object ${hash} for file ${path.join('/')}`);
if (file.type !== Type.blob)
throw new Error(`${hash} is not a blob for file ${path.join('/')}`);
recursivelyMakeFile(result, path, mode === Mode.exec, hash, file.body);
}
else {
recursivelyMakeFolder(result, path, hash);
}
for await (const { path, mode, hash } of super.walkTree(commit.body.tree)) {
if (isFile(mode)) {
const file = await super.loadObject(hash);
if (!file)
throw new Error(`Cannot find object ${hash} for file ${path.join('/')}`);
if (file.type !== Type.blob)
throw new Error(`${hash} is not a blob for file ${path.join('/')}`);
recursivelyMakeFile(result, path, mode === Mode.exec, hash, file.body);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
else {
recursivelyMakeFolder(result, path, hash);
}
finally { if (e_1) throw e_1.error; }
}

@@ -47,0 +29,0 @@ return result;

export {};
//# sourceMappingURL=index.test.d.ts.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports["default"] = checkoutMixin;
var _toArray2 = require("babel-runtime/helpers/toArray");
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
var _toArray3 = _interopRequireDefault(_toArray2);
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _regenerator = require("babel-runtime/regenerator");
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _regenerator2 = _interopRequireDefault(_regenerator);
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _newArrowCheck2 = require("babel-runtime/helpers/newArrowCheck");
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _newArrowCheck3 = _interopRequireDefault(_newArrowCheck2);
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncIterator"));
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _core = require("@es-git/core");
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
var _createClass2 = require("babel-runtime/helpers/createClass");
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
var _createClass3 = _interopRequireDefault(_createClass2);
function checkoutMixin(repo) {
return /*#__PURE__*/function (_repo) {
(0, _inherits2["default"])(CheckoutRepo, _repo);
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
var _super = _createSuper(CheckoutRepo);
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
function CheckoutRepo() {
(0, _classCallCheck2["default"])(this, CheckoutRepo);
var _get2 = require("babel-runtime/helpers/get");
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require("babel-runtime/helpers/inherits");
var _inherits3 = _interopRequireDefault(_inherits2);
var _promise = require("babel-runtime/core-js/promise");
var _promise2 = _interopRequireDefault(_promise);
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _symbol = require("babel-runtime/core-js/symbol");
var _symbol2 = _interopRequireDefault(_symbol);
exports.default = checkoutMixin;
var _core = require("@es-git/core");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var __asyncValues = undefined && undefined.__asyncValues || function (o) {
if (!_symbol2.default.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[_symbol2.default.asyncIterator],
i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : (0, _getIterator3.default)(o), i = {}, verb("next"), verb("throw"), verb("return"), i[_symbol2.default.asyncIterator] = function () {
return this;
}, i);
function verb(n) {
i[n] = o[n] && function (v) {
return new _promise2.default(function (resolve, reject) {
v = o[n](v), settle(resolve, reject, v.done, v.value);
});
};
return _super.call.apply(_super, [this].concat(args));
}
function settle(resolve, reject, d, v) {
_promise2.default.resolve(v).then(function (v) {
resolve({ value: v, done: d });
}, reject);
}
};
function checkoutMixin(repo) {
var _this2 = this;
return function (_repo) {
(0, _inherits3.default)(CheckoutRepo, _repo);
(0, _createClass2["default"])(CheckoutRepo, [{
key: "checkoutCommit",
value: function () {
var _checkoutCommit = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(hash) {
var commit, result, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, _value2, path, mode, _hash, file;
function CheckoutRepo() {
var _ref;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return (0, _get2["default"])((0, _getPrototypeOf2["default"])(CheckoutRepo.prototype), "loadObject", this).call(this, hash);
(0, _classCallCheck3.default)(this, CheckoutRepo);
case 2:
commit = _context.sent;
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (commit) {
_context.next = 5;
break;
}
return (0, _possibleConstructorReturn3.default)(this, (_ref = CheckoutRepo.__proto__ || (0, _getPrototypeOf2.default)(CheckoutRepo)).call.apply(_ref, [this].concat(args)));
}
throw new Error("Cannot find object ".concat(hash));
(0, _createClass3.default)(CheckoutRepo, [{
key: "checkoutCommit",
value: function () {
(0, _newArrowCheck3.default)(this, _this2);
case 5:
if (!(commit.type !== _core.Type.commit)) {
_context.next = 7;
break;
}
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(hash) {
var e_1, _a, commit, result, _b, _c, _ref3, path, mode, _hash, file;
throw new Error("".concat(hash, " is not a commit"));
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return (0, _get3.default)(CheckoutRepo.prototype.__proto__ || (0, _getPrototypeOf2.default)(CheckoutRepo.prototype), "loadObject", this).call(this, hash);
case 7:
result = {
files: {},
folders: {},
hash: commit.body.tree
};
_iteratorNormalCompletion = true;
_didIteratorError = false;
_context.prev = 10;
_iterator = (0, _asyncIterator2["default"])((0, _get2["default"])((0, _getPrototypeOf2["default"])(CheckoutRepo.prototype), "walkTree", this).call(this, commit.body.tree));
case 2:
commit = _context.sent;
case 12:
_context.next = 14;
return _iterator.next();
if (commit) {
_context.next = 5;
break;
}
case 14:
_step = _context.sent;
_iteratorNormalCompletion = _step.done;
_context.next = 18;
return _step.value;
throw new Error("Cannot find object " + String(hash));
case 18:
_value = _context.sent;
case 5:
if (!(commit.type !== _core.Type.commit)) {
_context.next = 7;
break;
}
if (_iteratorNormalCompletion) {
_context.next = 36;
break;
}
throw new Error(String(hash) + " is not a commit");
_value2 = _value, path = _value2.path, mode = _value2.mode, _hash = _value2.hash;
case 7:
result = { files: {}, folders: {}, hash: commit.body.tree };
_context.prev = 8;
_b = __asyncValues((0, _get3.default)(CheckoutRepo.prototype.__proto__ || (0, _getPrototypeOf2.default)(CheckoutRepo.prototype), "walkTree", this).call(this, commit.body.tree));
if (!(0, _core.isFile)(mode)) {
_context.next = 32;
break;
}
case 10:
_context.next = 12;
return _b.next();
_context.next = 24;
return (0, _get2["default"])((0, _getPrototypeOf2["default"])(CheckoutRepo.prototype), "loadObject", this).call(this, _hash);
case 12:
_c = _context.sent;
case 24:
file = _context.sent;
if (_c.done) {
_context.next = 34;
break;
}
if (file) {
_context.next = 27;
break;
}
_context.next = 16;
return _c.value;
throw new Error("Cannot find object ".concat(_hash, " for file ").concat(path.join('/')));
case 16:
_ref3 = _context.sent;
path = _ref3.path;
mode = _ref3.mode;
_hash = _ref3.hash;
case 27:
if (!(file.type !== _core.Type.blob)) {
_context.next = 29;
break;
}
if (!(0, _core.isFile)(mode)) {
_context.next = 31;
break;
}
throw new Error("".concat(_hash, " is not a blob for file ").concat(path.join('/')));
_context.next = 23;
return (0, _get3.default)(CheckoutRepo.prototype.__proto__ || (0, _getPrototypeOf2.default)(CheckoutRepo.prototype), "loadObject", this).call(this, _hash);
case 29:
recursivelyMakeFile(result, path, mode === _core.Mode.exec, _hash, file.body);
_context.next = 33;
break;
case 23:
file = _context.sent;
case 32:
recursivelyMakeFolder(result, path, _hash);
if (file) {
_context.next = 26;
break;
}
case 33:
_iteratorNormalCompletion = true;
_context.next = 12;
break;
throw new Error("Cannot find object " + String(_hash) + " for file " + String(path.join('/')));
case 36:
_context.next = 42;
break;
case 26:
if (!(file.type !== _core.Type.blob)) {
_context.next = 28;
break;
}
case 38:
_context.prev = 38;
_context.t0 = _context["catch"](10);
_didIteratorError = true;
_iteratorError = _context.t0;
throw new Error(String(_hash) + " is not a blob for file " + String(path.join('/')));
case 42:
_context.prev = 42;
_context.prev = 43;
case 28:
recursivelyMakeFile(result, path, mode === _core.Mode.exec, _hash, file.body);
_context.next = 32;
break;
if (!(!_iteratorNormalCompletion && _iterator["return"] != null)) {
_context.next = 47;
break;
}
case 31:
recursivelyMakeFolder(result, path, _hash);
_context.next = 47;
return _iterator["return"]();
case 32:
_context.next = 10;
break;
case 47:
_context.prev = 47;
case 34:
_context.next = 39;
break;
if (!_didIteratorError) {
_context.next = 50;
break;
}
case 36:
_context.prev = 36;
_context.t0 = _context["catch"](8);
e_1 = { error: _context.t0 };
throw _iteratorError;
case 39:
_context.prev = 39;
_context.prev = 40;
case 50:
return _context.finish(47);
if (!(_c && !_c.done && (_a = _b.return))) {
_context.next = 44;
break;
}
case 51:
return _context.finish(42);
_context.next = 44;
return _a.call(_b);
case 52:
return _context.abrupt("return", result);
case 44:
_context.prev = 44;
case 53:
case "end":
return _context.stop();
}
}
}, _callee, this, [[10, 38, 42, 52], [43,, 47, 51]]);
}));
if (!e_1) {
_context.next = 47;
break;
}
function checkoutCommit(_x) {
return _checkoutCommit.apply(this, arguments);
}
throw e_1.error;
return checkoutCommit;
}()
}, {
key: "checkout",
value: function () {
var _checkout = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(ref) {
var hash;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return (0, _get2["default"])((0, _getPrototypeOf2["default"])(CheckoutRepo.prototype), "getRef", this).call(this, ref);
case 47:
return _context.finish(44);
case 2:
hash = _context2.sent;
case 48:
return _context.finish(39);
if (hash) {
_context2.next = 5;
break;
}
case 49:
return _context.abrupt("return", result);
throw new Error("Unknown ref ".concat(ref));
case 50:
case "end":
return _context.stop();
}
}
}, _callee, this, [[8, 36, 39, 49], [40,, 44, 48]]);
}));
case 5:
return _context2.abrupt("return", this.checkoutCommit(hash));
function checkoutCommit(_x) {
return _ref2.apply(this, arguments);
}
case 6:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
return checkoutCommit;
}.bind(_this2)()
}, {
key: "checkout",
value: function () {
(0, _newArrowCheck3.default)(this, _this2);
function checkout(_x2) {
return _checkout.apply(this, arguments);
}
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(ref) {
var hash;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return (0, _get3.default)(CheckoutRepo.prototype.__proto__ || (0, _getPrototypeOf2.default)(CheckoutRepo.prototype), "getRef", this).call(this, ref);
return checkout;
}()
}]);
return CheckoutRepo;
}(repo);
}
case 2:
hash = _context2.sent;
function recursivelyMakeFile(parent, path, isExecutable, hash, body) {
var _path = (0, _toArray2["default"])(path),
name = _path[0],
subPath = _path.slice(1);
if (hash) {
_context2.next = 5;
break;
}
if (subPath.length === 0) {
parent.files[name] = {
hash: hash,
isExecutable: isExecutable,
body: body,
throw new Error("Unknown ref " + String(ref));
get text() {
return (0, _core.decode)(body);
}
case 5:
return _context2.abrupt("return", this.checkoutCommit(hash));
case 6:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function checkout(_x2) {
return _ref4.apply(this, arguments);
}
return checkout;
}.bind(_this2)()
}]);
return CheckoutRepo;
}(repo);
};
} else {
recursivelyMakeFile(parent.folders[name], subPath, isExecutable, hash, body);
}
}
function recursivelyMakeFile(parent, path, isExecutable, hash, body) {
var _path = (0, _toArray3.default)(path),
name = _path[0],
subPath = _path.slice(1);
if (subPath.length === 0) {
parent.files[name] = {
hash: hash,
isExecutable: isExecutable,
body: body,
get text() {
return (0, _core.decode)(body);
}
};
} else {
recursivelyMakeFile(parent.folders[name], subPath, isExecutable, hash, body);
}
}
function recursivelyMakeFolder(parent, path, hash) {
var _path2 = (0, _toArray3.default)(path),
name = _path2[0],
subPath = _path2.slice(1);
var _path2 = (0, _toArray2["default"])(path),
name = _path2[0],
subPath = _path2.slice(1);
if (subPath.length === 0) {
parent.folders[name] = {
hash: hash,
files: {},
folders: {}
};
} else {
recursivelyMakeFolder(parent.folders[name], subPath, hash);
}
if (subPath.length === 0) {
parent.folders[name] = {
hash: hash,
files: {},
folders: {}
};
} else {
recursivelyMakeFolder(parent.folders[name], subPath, hash);
}
}
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map
{
"name": "@es-git/checkout-mixin",
"version": "0.9.0",
"version": "0.10.0",
"description": "",

@@ -9,9 +9,9 @@ "main": "js/index.js",

"scripts": {
"clean": "rm -rf ./es ./js",
"tsc": "../../node_modules/.bin/tsc",
"babel": "../../node_modules/.bin/babel --source-maps -d js es",
"clean": "rimraf ./es ./js",
"tsc": "tsc",
"babel": "babel --root-mode upward --source-maps -d js es",
"compile": "npm run tsc && npm run babel",
"test": "../../node_modules/.bin/ava",
"watch+test": "../../node_modules/.bin/tsc -w & ../../node_modules/.bin/ava -w",
"watch": "../../node_modules/.bin/tsc -w & ../../node_modules/.bin/babel --source-maps -w -d js es",
"test": "jest",
"watch+test": "tsc -w & ava -w",
"watch": "tsc -w & babel --source-maps -w -d js es",
"prepublishOnly": "npm run clean && npm run compile && npm test"

@@ -25,24 +25,11 @@ },

"license": "MIT",
"ava": {
"files": [
"es/*.test.js"
],
"source": [
"es/*.js"
],
"require": [
"babel-register"
],
"babel": {
"extends": "../../.babelrc"
}
},
"peerDependencies": {
"babel-runtime": "^6.22.0"
"@babel/runtime": "^7.12.5"
},
"dependencies": {
"@es-git/core": "^0.9.0",
"@es-git/object-mixin": "^0.9.0",
"@es-git/walkers-mixin": "^0.9.0"
}
"@es-git/core": "^0.10.0",
"@es-git/object-mixin": "^0.10.0",
"@es-git/walkers-mixin": "^0.10.0"
},
"gitHead": "5939f07143e0b8aa67d7464e6ec47754bebab347"
}

@@ -0,0 +0,0 @@ import { Type, Mode, Constructor, IRawRepo, Hash, isFile, decode } from '@es-git/core';

@@ -0,0 +0,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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc