@es-git/load-as-mixin
TypeScript icon, indicating that this package has built-in type declarations

0.10.0 • Public • Published

load-as-mixin

This is part of the ES-Git project.

Install

npm install --save @es-git/load-as-mixin

Usage

Mix this in with an IObjectRepo.

This mixin makes it easier to load objects from the repo. Each method takes a hash and attempts to load the object with that hash. If the object does not exist or is not of the type exected, an Error is thrown.

import objectsMixin from '@es-git/objects-mixin';
import loadAsMixin from '@es-git/load-as-mixin';
import MemoryRepo from '@es-git/memory-repo';

const Repo = mix(MemoryRepo)
            .with(objectsMixin)
            .with(loadAsMixin);

const repo = new Repo();
const text = await repo.loadText(hash);
const tree = await repo.loadTree(hash);

Interfaces

ILoadAsRepo

interface ILoadAsRepo {
  loadBlob(hash : Hash) : Promise<Uint8Array>
  loadText(hash : Hash) : Promise<string>
  loadTree(hash : Hash) : Promise<TreeBody>
  loadCommit(hash : Hash) : Promise<CommitBody>
  loadTag(hash : Hash) : Promise<TagBody>
}

type Hash = string;

type TreeBody = {
  [key : string] : ModeHash
}

type ModeHash = {
  readonly mode : Mode
  readonly hash : string
}

type CommitBody = {
  readonly tree : string
  readonly parents : string[]
  readonly author : Person
  readonly committer : Person
  readonly message : string
}

type Person = {
  readonly name : string
  readonly email : string
  readonly date : Date | SecondsWithOffset
}

type SecondsWithOffset = {
  readonly seconds : number
  readonly offset : number
}

type TagBody = {
  readonly object : string
  readonly type : string
  readonly tag : string
  readonly tagger : Person
  readonly message : string
}

Readme

Keywords

none

Package Sidebar

Install

npm i @es-git/load-as-mixin

Weekly Downloads

2

Version

0.10.0

License

MIT

Unpacked Size

36.9 kB

Total Files

16

Last publish

Collaborators

  • mariusgundersen