npmextra/ts/npmextra.classes.keyvaluestore.ts

69 lines
1.4 KiB
TypeScript
Raw Normal View History

2016-09-16 20:28:38 +00:00
import * as plugins from './npmextra.plugins'
2016-09-24 19:49:53 +00:00
import * as paths from './npmextra.paths'
2016-08-28 12:51:04 +00:00
2016-09-24 19:49:53 +00:00
export type keyValueStoreTypes = 'path' | 'gitProject' | 'customString'
2016-08-28 12:51:04 +00:00
2016-09-24 14:44:48 +00:00
export class KeyValueStore {
2016-09-24 19:49:53 +00:00
type: string // the type of the kvStore
identity: string // the identity of the kvStore
filePath: string // the filePath of the kvStore
constructor(typeArg: keyValueStoreTypes, identityStringArg?: string) {
// set kvStoreType
this.type = typeArg
this.initIdentity(identityStringArg)
this.initFilePath()
2016-09-24 14:44:48 +00:00
}
2016-09-24 19:49:53 +00:00
2016-09-24 14:44:48 +00:00
/**
2016-09-24 19:49:53 +00:00
* reads a keyValueFile from disk
*/
read() {
2016-08-28 12:51:04 +00:00
2016-09-24 14:52:38 +00:00
}
2016-08-28 12:51:04 +00:00
2016-09-24 14:52:38 +00:00
/**
* writes a key value file to disk
*/
2016-09-24 19:49:53 +00:00
write() {
2016-08-28 12:51:04 +00:00
2016-09-24 14:52:38 +00:00
}
2016-08-28 12:51:04 +00:00
2016-09-24 14:52:38 +00:00
/**
* wipes a key value store from disk
*/
2016-09-24 19:49:53 +00:00
wipe() {
}
/**
* updates a value
*/
update() {
2016-08-28 12:51:04 +00:00
2016-09-24 14:52:38 +00:00
}
2016-09-24 19:49:53 +00:00
/**
* computes the identity
*/
2016-09-24 19:53:44 +00:00
private initIdentity(identityStringArg: string) {
2016-09-24 19:49:53 +00:00
}
2016-09-24 19:53:44 +00:00
2016-09-24 19:49:53 +00:00
/**
* computes the filePath
*/
private initFilePath() {
let baseDir: string
if (this.type === 'customString') {
baseDir = paths.kvCusomDir
} else if (this.type === 'gitProject') {
baseDir = paths.kvGitDir
} else if (this.type === 'path') {
baseDir = paths.kvPathDir
}
this.filePath = plugins.path.join(baseDir, this.identity + '.json')
2016-09-24 19:53:44 +00:00
plugins.smartfile.fs.ensureFileSync(this.filePath,'{}')
2016-09-24 19:49:53 +00:00
}
2016-09-16 20:28:38 +00:00
}