0.0.9 • Published 6 years ago
@deepest-lore/fs-import v0.0.9
@deepest-lore/fs-import

Imports deepest-lore schemas and data from JSON and CSV files on disk.
Example
import fsImport from "@deepest-lore/fs-import"
async function importData() {
const imported = await fsImport(`base-path`)
console.log(imported) // { schema: ..., data: { entityTypes: ..., mappings: ... } }
}
File structure
All files are expected to be UTF-8 encoded.
{base directory}/schema.json
The schema, as defined in @deepest-lore/data-model.
{base directory}/entities/{entity type identifier}.csv
Each row defines a single entity instance while the first row defines the columns. The following patterns are supported:
Pattern | Meaning |
---|---|
$ | The column defines the entity instance's unique identifier. |
col_id | The column defines the value of unlocalized entity type column col_id . |
col_id:loc_id | The column defines the value of localized entity type column col_id for localization loc_id . |
Example
$,name__:en_gb_,name__:fr_fr_,catgry,weapon,food__,salqty,weight
grpfrt,Grapefruit,Pamplemousse,fruit_,❌,✔️,1,5
lemon_,Lemon,Citron,fruit_,TRUE,Yes,4,2
pebble,Pebble,Caillou,rock__,FALSE,No,50,1
$ | name_:en_gb | name_:fr_fr | catgry | weapon | food__ | salqty | weight |
---|---|---|---|---|---|---|---|
grpfrt | Grapefruit | Pamplemousse | fruit_ | ❌ | ✔️ | 1 | 5 |
lemon_ | Lemon | Citron | fruit_ | TRUE | Yes | 4 | 2 |
pebble | Pebble | Caillou | rock__ | FALSE | No | 50 | 1 |
{base directory}/mappings/{mapping identifier}.csv
Similarly to entity type files, each row defines a single mapping while the first row defines the columns. The following patterns are supported:
Pattern | Meaning |
---|---|
$key_id | The column defines the mapping key key_id . |
col_id | The column defines the value of unlocalized entity type column col_id . |
col_id:loc_id | The column defines the value of localized entity type column col_id for localization loc_id . |
Example
$item__,$vendor,price_
lemon_,grngcr,0.8
pebble,grngcr,0.5
grpfrt,grngcr,2.4
pebble,rocrus,0.4
$item__ | $vendor | price_ |
---|---|---|
lemon_ | grngcr | 0.8 |
pebble | grngcr | 0.5 |
grpfrt | grngcr | 2.4 |
pebble | rocrus | 0.4 |