Skip to content

Commit

Permalink
Added some changes to the structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jnbdz committed Oct 7, 2024
1 parent b462005 commit 11ff846
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 18 deletions.
10 changes: 6 additions & 4 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ But to glorify what!?

## History

Whilst working on the [Amadla](https://github.com/AmadlaOrg/) project I tried different ways to store, and organize
configurations and nothing was found that satisfied the requirements and the desideratum of what solutions it was
Whilst working on the [Amadla](https://github.com/AmadlaOrg/) project I tried different ways to store, and organize
configurations and nothing was found that satisfied the requirements and the desideratum of what solutions it was
supposed to provide.

So by trying out different ideas in code and on paper, HERY was born.

It was important for the [Amadla](https://github.com/AmadlaOrg/) project that the reinventing of the wheel not supervened nor should it be
adding complexity by creating too many new concepts. A maximum of technologies needed to be familiar to the users.

This is why HERY is more of an extension to YAML than a completely new
This is why HERY is more of an extension to YAML than a completely new
[Electronic Data Interchange (EDI)](https://en.wikipedia.org/wiki/Electronic_data_interchange)/storage/[markup](https://en.wikipedia.org/wiki/Markup_language) thingamajig.

But again back to the question... Glorify what!?
Expand All @@ -32,7 +32,9 @@ But again back to the question... Glorify what!?
- **Hierarchy** - Entities can have a parent entity that it can overwrite so this way an entity can be reused multiple times with default values
- **Relational content** - A property can point to one or multiple entities (in this context an entity is like a table in a RDBMS and a property is like a column)
- `_entity` - Is a URI with a version number after `@` that informs what schema the content under it must follow
- `_body` - Contains the entity properties and its values
- `_id` - Is an ID given to a property to point to another entity
- `_meta` - Is an optional property that contains an entity or entities for metadata to an entity

That's it!

Expand All @@ -44,4 +46,4 @@ That's it!
- **Validation** - the cli makes it possible to validate an entity or many entities
- **Get** - by using given entity URLs it will download the entity and its relational entities automatically
- **Compose** - combines the entities together
- And many other tools
- And many other tools
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,59 @@ Additionally, the term "hery" in British English, pronounced /ˈhɛrɪ/, is an o
This name reflects the utility's aim to elevate and celebrate structured data management.

## Install
### With Go
```bash
go install github.com/AmadlaOrg/hery
```
### Build
```bash
go build -o hery
```

## Quickstart
HERY does not require a lot of learning to get started. All you need to know is the four reserved properties, the
`.hery` file format that the reserved properties are found, that there is a SQLite caching system, a few of the
commands and understand some of the basics of the query language.

### `.hery` File Format
The `.hery` file format is the same as a `.yml`/`.yaml` file. The reason the extension is different is so that `hery`
CLI is able to find it and so that IDEs can have better support.

HERY format comes with four different reserved properties:
- `_meta` - For metadata for the relative entity
- `_entity` - Contains the entity URI with the version (is optional)
- `_body` - Contains the content of the entity
- `_id` - To be able to make reference to a specific entity content

Here is an example:
```hery
---
_meta:
_entity: github.com/AmadlaOrg/Entity@latest
_body:
name: RandomName
description: Entity Pseudo Version definitions.
category: QA
tags:
- QA
- fixture
- test
_body:
name: Random Name
```

There are different structures that are valid. For example `_meta` is an optional reserved property. And at the root of
the entity content `_entity` is not allowed since it takes the value from the repository itself.

When validation happens it takes for account the entity URI and validates what is in the `_body` whilst everything else
is ignored.

### Caching
Since the querying on YAML files would be a bit slow and resource demanding, SQLite is used to store all the entities.

Each entity has its own table and it is found: `~/.hery/collection/<collection name>/<collection name>.cache`.

### Basic Commands
To verify that it was installed properly:
```bash
hery --version
Expand Down
6 changes: 3 additions & 3 deletions entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"sync"
)

// IEntity
// IEntity used for mock
type IEntity interface {
FindEntityDir(paths storage.AbsPaths, entityVals Entity) (string, error)
CheckDuplicateEntity(entities []Entity, entityMeta Entity) error
Expand All @@ -25,15 +25,15 @@ type IEntity interface {
Read(path, collectionName string) (map[string]any, error)
}

// SEntity
// SEntity used for mock
type SEntity struct {
EntityVersion version.IVersion

// Data
Entities []Entity
}

// SetEntity
// SetEntity for appending an entity into the struct entity list
func (s *SEntity) SetEntity(entity Entity) {
s.Entities = append(s.Entities, entity)
}
Expand Down
86 changes: 86 additions & 0 deletions entity/entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,99 @@ package entity
import (
"fmt"
"github.com/AmadlaOrg/hery/storage"
"github.com/santhosh-tekuri/jsonschema/v6"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

func TestSetEntity(t *testing.T) {
entityService := NewEntityService()

tests := []struct {
name string
serviceEntities []Entity
inputEntityUri string
expectedEntity Entity
expectedErr error
hasError bool
}{
{
name: "Valid: entity",
serviceEntities: []Entity{
{
Id: "97d4b783-f448-483c-8111-380d6082ae1c",
Entity: "github.com/AmadlaOrg/Entity@v0.0.0-20240924093300-abcd1234efgh",
Name: "Entity",
RepoUrl: "https://github.com/AmadlaOrg/Entity",
Origin: "github.com/AmadlaOrg/Entity",
Version: "latest",
LatestVersion: true,
IsPseudoVersion: true,
AbsPath: "/home/user/.hery/collection/amadla/entity/github.com/AmadlaOrg/Entity@v.0.0.0-",
Have: true,
Hash: "",
Exist: true,
Schema: &jsonschema.Schema{},
Config: map[string]any{
"name": "Entity",
"description": "The meta Entity definition.",
"category": "General",
"tags": []string{
"main",
"master",
},
},
},
{
Id: "56d4b783-c448-983c-8911-400d6082ae1c",
Entity: "github.com/AmadlaOrg/Entity@v0.0.0-20240924093300-abcd1234efgh",
Name: "Entity",
RepoUrl: "https://github.com/AmadlaOrg/Entity",
Origin: "github.com/AmadlaOrg/Entity",
Version: "latest",
LatestVersion: false,
IsPseudoVersion: true,
AbsPath: "/home/user/.hery/amadla/entity/github.com/AmadlaOrg/Entity@v.0.0.0-",
Have: true,
Hash: "",
Exist: true,
Schema: &jsonschema.Schema{},
Config: map[string]any{
"name": "Entity",
"description": "The meta Entity definition.",
"category": "General",
"tags": []string{
"main",
"master",
},
},
},
},
inputEntityUri: "github.com/AmadlaOrg/Entity@latest",
expectedEntity: Entity{},
expectedErr: nil,
hasError: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
entityService.Entities = tt.serviceEntities

got, err := entityService.GetEntity(tt.inputEntityUri)
if tt.hasError {
assert.Error(t, err)
assert.ErrorIs(t, err, tt.expectedErr)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.expectedEntity, got)
})
}
}

func TestFindEntityDir(t *testing.T) {
entityService := NewEntityService()

Expand Down
26 changes: 15 additions & 11 deletions entity/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ func (s *SVersion) Latest(versions []string) (string, error) {
return versions[len(versions)-1], nil
}

// GeneratePseudo generates a pseudo version to be used when there is no other source to identify the version of the entity.
func (s *SVersion) GeneratePseudo(entityFullRepoUrl string) (string, error) {
commitHeadHash, err := s.GitRemote.CommitHeadHash(entityFullRepoUrl)
if err != nil {
return "", err
}
timestamp := time.Now().Format("20060102150405")
pseudoVersion := fmt.Sprintf("v0.0.0-%s-%s", timestamp, commitHeadHash[:12])
return pseudoVersion, nil
}

//
// Private functions
//

// versionLess compares two version strings and returns true if v1 < v2.
func (s *SVersion) versionLess(v1, v2 string) bool {
return s.compareVersions(v1, v2) < 0
Expand Down Expand Up @@ -182,14 +197,3 @@ func (s *SVersion) parseVersion(version string) ([]int, string) {

return nums, pre
}

// GeneratePseudo generates a pseudo version to be used when there is no other source to identify the version of the entity.
func (s *SVersion) GeneratePseudo(entityFullRepoUrl string) (string, error) {
commitHeadHash, err := s.GitRemote.CommitHeadHash(entityFullRepoUrl)
if err != nil {
return "", err
}
timestamp := time.Now().Format("20060102150405")
pseudoVersion := fmt.Sprintf("v0.0.0-%s-%s", timestamp, commitHeadHash[:12])
return pseudoVersion, nil
}

0 comments on commit 11ff846

Please sign in to comment.