Socket
Socket
Sign inDemoInstall

@es-git/path-to-object-mixin

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@es-git/path-to-object-mixin - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

2

es/index.d.ts

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

loadObjectByPath(rootTree: Hash, path: string | string[]): Promise<TreeObject | BlobObject | undefined>;
loadBlobByPath(rootTree: Hash, path: string | string[]): Promise<Uint8Array | undefined>;
loadTextByPath(rootTree: Hash, path: string | string[]): Promise<string | undefined>;
}
export default function mixin<T extends Constructor<IObjectRepo>>(repo: T): Constructor<IPathToObjectRepo> & T;

@@ -1,2 +0,2 @@

import { Type } from '@es-git/core';
import { Type, decode } from '@es-git/core';
export default function mixin(repo) {

@@ -34,4 +34,19 @@ return class PathToObjectRepo extends repo {

}
async loadBlobByPath(rootTree, path) {
const object = await this.loadObjectByPath(rootTree, path);
if (!object)
return undefined;
if (object.type !== Type.blob) {
throw new Error(`Wrong object: ${path}. Expected tree or blob, got ${object.type}`);
}
return object.body;
}
async loadTextByPath(rootTree, path) {
const blob = await this.loadBlobByPath(rootTree, path);
if (!blob)
return undefined;
return decode(blob);
}
};
}
//# sourceMappingURL=index.js.map

@@ -213,2 +213,92 @@ "use strict";

}.bind(_this2)()
}, {
key: "loadBlobByPath",
value: function () {
(0, _newArrowCheck3.default)(this, _this2);
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(rootTree, path) {
var object;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return this.loadObjectByPath(rootTree, path);
case 2:
object = _context2.sent;
if (object) {
_context2.next = 5;
break;
}
return _context2.abrupt("return", undefined);
case 5:
if (!(object.type !== _core.Type.blob)) {
_context2.next = 7;
break;
}
throw new Error("Wrong object: " + String(path) + ". Expected tree or blob, got " + String(object.type));
case 7:
return _context2.abrupt("return", object.body);
case 8:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function loadBlobByPath(_x3, _x4) {
return _ref2.apply(this, arguments);
}
return loadBlobByPath;
}.bind(_this2)()
}, {
key: "loadTextByPath",
value: function () {
(0, _newArrowCheck3.default)(this, _this2);
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(rootTree, path) {
var blob;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return this.loadBlobByPath(rootTree, path);
case 2:
blob = _context3.sent;
if (blob) {
_context3.next = 5;
break;
}
return _context3.abrupt("return", undefined);
case 5:
return _context3.abrupt("return", (0, _core.decode)(blob));
case 6:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}));
function loadTextByPath(_x5, _x6) {
return _ref3.apply(this, arguments);
}
return loadTextByPath;
}.bind(_this2)()
}]);

@@ -215,0 +305,0 @@ return PathToObjectRepo;

6

package.json
{
"name": "@es-git/path-to-object-mixin",
"version": "0.1.2",
"version": "0.2.0",
"description": "",

@@ -42,5 +42,5 @@ "main": "js/index.js",

"dependencies": {
"@es-git/core": "^0.1.2",
"@es-git/object-mixin": "^0.1.2"
"@es-git/core": "^0.2.0",
"@es-git/object-mixin": "^0.2.0"
}
}

@@ -29,2 +29,4 @@ # path-to-object-mixin

const object = await repo.loadObjectByPath(hash, ['folder', 'directory', 'file.txt']);
const content = await repo.loadTextByPath(hash, ['folder', 'directory', 'file.txt']);
```

@@ -39,2 +41,4 @@

loadObjectByPath(rootTree : Hash, path : string | string[]) : Promise<TreeObject | BlobObject | undefined>
loadBlobByPath(rootTree : Hash, path : string | string[]) : Promise<Uint8Array | undefined>
loadTextByPath(rootTree : Hash, path : string | string[]) : Promise<string | undefined>
}

@@ -44,2 +48,3 @@ ```

### GitObject
```js

@@ -46,0 +51,0 @@ type Hash = string;

@@ -1,2 +0,2 @@

import { Type, Mode, Constructor, IRawRepo, Hash } from '@es-git/core';
import { Type, Mode, Constructor, IRawRepo, Hash, decode } from '@es-git/core';
import { IObjectRepo, TreeObject, BlobObject, ModeHash } from '@es-git/object-mixin';

@@ -6,2 +6,4 @@

loadObjectByPath(rootTree : Hash, path : string | string[]) : Promise<TreeObject | BlobObject | undefined>
loadBlobByPath(rootTree : Hash, path : string | string[]) : Promise<Uint8Array | undefined>
loadTextByPath(rootTree : Hash, path : string | string[]) : Promise<string | undefined>
}

@@ -37,3 +39,18 @@

}
async loadBlobByPath(rootTree : Hash, path : string | string[]) : Promise<Uint8Array | undefined> {
const object = await this.loadObjectByPath(rootTree, path);
if(!object) return undefined;
if(object.type !== Type.blob){
throw new Error(`Wrong object: ${path}. Expected tree or blob, got ${object.type}`);
}
return object.body;
}
async loadTextByPath(rootTree : Hash, path : string | string[]) : Promise<string | undefined> {
const blob = await this.loadBlobByPath(rootTree, path);
if(!blob) return undefined;
return decode(blob);
}
}
}

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