You were tasked with the creation of a proof of concept for myDB, a brand new javascript library which enables the creation of in-memory client-side databases. Your final delivery should consist of a basic version of the library and a demo App that uses it to display a visual representation of an in-memory database.
Expect to deal with:
- Data Normalization and Denormalization;
- Recursion;
- Reactive User Interfaces;
- Immutability.
Solution should be maintainable, extensible, production quality. We expect:
- Clean, concise code;
- Adoption of Functional Programming patterns – feel free to use libraries that facilitate functional operations;
- Semantic use of your chosen language;
- Accurate implementation of provided graphical references – feel free to use frameworks, but avoid UI component libraries such as Material UI and Bootstrap;
- Quality unit tests – for the library;
- Documentation;
- A ReadMe file containing comprehensive instructions on how to setup, run and test your code.
Both library and demo apps are meant for a web environment, they may be written in JavaScript or any programming language that compiles to JavaScript (TypeScript, ELM, ClojureScript, Reason). You're allowed to use any of the features supported by the most recent versions of Chrome and Firefox.
# Library
myDB is a library that allows client applications to create and manipulate in-memory databases.
The Library should be able to:
- Create dbs.
- Add new tables to a db.
- Add new entities to tables.
- An entity attribute can either be a Value (string, boolean or scalar) or a Reference to another attribute.
- A Reference should be described with a triplet following the format: `[ tableId entityId attributeId ]`.
- Resolve the value of a given reference.
- Generate a normalized representation of the state of a db.
- Generate a denormalized representation of the state of a db.
_The library should expose at least the following functions:_
# createDB
Creates and returns a new myDB db.
| Inputs | Outputs |
| None | database: object |
createDB(); // => new myDB database
# addTable
Given a db and a tableId, creates a new table with the specified tableId and adds it to the db. Returns the updated db.
| Inputs | Outputs |
| database: object | database: object |
| tableId: string | |
addTable(db, 't'); // => db with a table of id t
# addEntity
Given a db, tableId and entityBody, creates a new entity with the provided entityBody and adds it to the specified table of the db, under a unique entityId. Returns the modified db.
Inputs:
database: object
tableId: string
entityId: string
entityBody: {string: any}
| Inputs | Outputs |
| database: object | database: object |
| tableId: string | |
| entityId: string | |
| entityBody: object | |
addEntity(db, 't', 'i', { attrId: 'attrValue' }); // => db with new entity of id "i" and body {attrId: "attrValue"} added to table "t"
# dump
Generates a representation of the state of a given db.
| Inputs | Outputs |
| database: object | database: object |
dump(db); // => {t: {e1: {k: 'v'}, {e2: {refToK: ['t', 'e1', 'k']}}}}
# denormalize
Generates a denormalized representation of the state of a given db.
| Inputs | Outputs |
| database: object | database: object |
denormalize(db); // => {t: {e1: {k: 'v'}, {e2: {refToK: 'v'}}}}