Your task is to implement a simple data store with JSON-like structure, e.g.:
{
foo: {
bar: {
baz: 42
},
hello: 'world'
}
}
The data store interface is specified in src/dataStore.ts and it consists of 3 asynchronous methods:
-
read(path: string)- should return aPromisewith data located atpath. Path is a concatenated list of keys separated with., for examplefoo.bar.bazreferences data located at keybazof objectbarnested in objectfoo. Duplicated.should not matter. If there's no value atpaththe method should returnPromisewithundefined. -
write(path: string, value: StoredValue)- should writevalueat givenpath. Value could be a primitive value (string,number,boolean), anobject(with primitive values or other objects) or anundefinedvalue. Ifpathdoesn't exist yet in the store it should be created. Writing at root path (empty string or.) should not be allowed. -
observe(path: string, callback: ObserverCallback)- should register a callback that will be called every time the value atpathor any sub-paths is modified. It should be also called immediately after registering with the current value. For example if observer is registered forfoo.barpath and laterfoo.bar.bazvalue is written the callback should be called.
For example, given the data structure shown above we should expect the following results:
read('foo.bar.baz') // 42read('foo.bar') // { baz: 42 }write('foo.bar', 'test'); read('foo') // { bar: 'test', hello: 'world' }
There are three classes to be implemented:
InMemoryStore- should keep the data in-memory.FileStore- should read and write the data to file.TypedStore-readshould return values with types depending on provided schema
There are ordered test files in tests/ folder, we strongly suggest that you fix them one by one:
01.read.test- testsreadmethod ofInMemoryStore02.write.test- testswritemethod ofInMemoryStore03.observe.test- testsobservemethod ofInMemoryStore04.file.test- tests reading and saving to file byFileStore05.typed.test- tests checking if types returned byTypedStoreare correct