nGitDB

Resource Model

nGitDB uses canonical resource paths instead of exposing raw file paths to application code.

Resource Path Format

Resource paths must use:

<collection>/<id>

Examples:

companies/acme-gmbh
products/widget-1000
locations/berlin-office

Paths with more or fewer segments are rejected.

File Resolution

By default, nGitDB maps:

<collection>/<id>

to:

data/<collection>/<id>/<fileName>

For this configuration:

{
  resourceRoot: "data",
  resources: {
    companies: {
      fileName: "company.json",
    },
  },
}

this resource path:

companies/acme-gmbh

resolves to:

data/companies/acme-gmbh/company.json

JSON Documents

V1 is JSON-only. read(resourcePath) parses the resolved file and returns a JSON object.

const company = await db.read("companies/acme-gmbh");

If the file does not exist, nGitDB throws ResourceNotFoundError.

Collection Definitions

Every collection must have a resource definition.

resources: {
  companies: {
    fileName: "company.json",
  },
}

If a resource path references an unknown collection, nGitDB throws ResourceDefinitionError.