@hiredue-org/datastore
v1.0.0
Published
Composable persistent, transient, and secure data stores for Node.js
Readme
Data Store
This is a javascript based implementation of a data store that can be used to store and retrieve data. It is implemented as a singleton class that uses the node-persist library for the persistent store and node-cache for the transient store. The secure store is implemented using the keytar library. The data store can be configured to use external logging, and other features. It also supports TTL (time to live) for the transient store and the persistent store. The Persistent store also has a write queue feature that allows for asynchronous writes to the persistent store. The data store can be used in a variety of applications, including web applications, desktop applications, and mobile applications.
Usage
To use the data store, you can import the DataStore class and create an instance of it. You can then create a config file that would be used to initialize the data store. The config file should be a JSON that contains the following keys:
const storeConfig = {
store: {
isLoggingEnabled : true,
logger : log
},
persistent: {
dir: persistentStoreDir,
stringify: JSON.stringify,
parse: JSON.parse,
encoding: "utf8",
logging: false,
ttl: false,
expiredInterval: 2 * 60 * 1000,
forgiveParseErrors: false,
writeQueue: true,
writeQueueIntervalMs: 1000,
writeQueueWriteOnlyLast: true
},
transient: {
ttl: 1200
},
secure: {
serviceName: appName
}
};You can then initialize the data store with the config file and use it to store and retrieve data. For example:
const dataStore = new DataStore();
await dataStore.init(storeConfig);You can then use the set and get methods to store and retrieve data. For example:
await dataStore.persistent.set("key", "value");
const value = await dataStore.persistent.get("key");
console.log(value); // "value"You can also use the transient and secure stores in a similar way. For example:
await dataStore.transient.set("key", "value123");
const value = await dataStore.secure.get("cognitoKey"); License
MIT License
