balena-settings-storage
Advanced tools
Comparing version 6.0.0-6-x-ac866ae8e81880b68b7902f2a467dd3783fbed35 to 6.0.0-6-x-c558eee881428b3893cffebed6e6afb011317536
@@ -18,2 +18,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createStorage = void 0; | ||
const prefixed = (key) => `balena-${key}`; | ||
@@ -99,2 +100,5 @@ const createVirtualStore = () => { | ||
exports.createStorage = createStorage = (dataDirectory) => { | ||
if (dataDirectory == null) { | ||
throw new Error('dataDirectory must be specified in nodejs'); | ||
} | ||
if (!storageCache[dataDirectory]) { | ||
@@ -101,0 +105,0 @@ storageCache[dataDirectory] = new NodeStorage(dataDirectory); |
@@ -6,3 +6,3 @@ import { StorageLike } from './local-storage'; | ||
constructor(dataDirectory: string); | ||
init(): Promise<void>; | ||
private init; | ||
private getPath; | ||
@@ -9,0 +9,0 @@ clear(): Promise<void>; |
@@ -18,2 +18,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NodeStorage = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -29,8 +30,10 @@ const fs_1 = require("fs"); | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (this.initialized) { | ||
if (this.initialized === true) { | ||
return; | ||
} | ||
this.initialized = true; | ||
if (this.initialized === false) { | ||
this.initialized = fs_1.promises.mkdir(this.dataDirectory); | ||
} | ||
try { | ||
yield fs_1.promises.mkdir(this.dataDirectory); | ||
yield this.initialized; | ||
} | ||
@@ -40,2 +43,5 @@ catch (_a) { | ||
} | ||
finally { | ||
this.initialized = true; | ||
} | ||
}); | ||
@@ -42,0 +48,0 @@ } |
@@ -52,3 +52,3 @@ "use strict"; | ||
*/ | ||
const set = (name, value) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const set = (name, value) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
if (typeof value !== 'string') { | ||
@@ -73,3 +73,3 @@ value = JSON.stringify(value); | ||
*/ | ||
const get = (name) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const get = (name) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
@@ -112,3 +112,3 @@ const result = yield localStorage.getItem(name); | ||
*/ | ||
const has = (name) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const has = (name) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const value = yield get(name); | ||
@@ -129,3 +129,3 @@ return value != null; | ||
*/ | ||
const remove = (name) => tslib_1.__awaiter(this, void 0, void 0, function* () { return localStorage.removeItem(name); }); | ||
const remove = (name) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return localStorage.removeItem(name); }); | ||
/** | ||
@@ -142,3 +142,3 @@ * @summary Remove all values | ||
*/ | ||
const clear = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return localStorage.clear(); }); | ||
const clear = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return localStorage.clear(); }); | ||
return { set, get, has, remove, clear }; | ||
@@ -145,0 +145,0 @@ }; |
@@ -8,4 +8,7 @@ # Change Log | ||
# v6.0.0 | ||
## (2020-07-01) | ||
## (2020-07-02) | ||
* Enable strict type checking [Pagan Gazzard] | ||
* Update typescript [Pagan Gazzard] | ||
* Add engines property to package.json [Pagan Gazzard] | ||
* Update to @balena/lint 5.x [Pagan Gazzard] | ||
@@ -12,0 +15,0 @@ * Drop support for nodejs < 10 [Pagan Gazzard] |
@@ -111,3 +111,6 @@ /* | ||
const storageCache = Object.create(null); | ||
createStorage = (dataDirectory: string) => { | ||
createStorage = (dataDirectory?: string) => { | ||
if (dataDirectory == null) { | ||
throw new Error('dataDirectory must be specified in nodejs'); | ||
} | ||
if (!storageCache[dataDirectory]) { | ||
@@ -114,0 +117,0 @@ storageCache[dataDirectory] = new NodeStorage(dataDirectory); |
@@ -22,14 +22,18 @@ /* | ||
export class NodeStorage implements StorageLike { | ||
private initialized = false; | ||
private initialized: boolean | Promise<void> = false; | ||
constructor(private dataDirectory: string) {} | ||
public async init() { | ||
if (this.initialized) { | ||
private async init() { | ||
if (this.initialized === true) { | ||
return; | ||
} | ||
this.initialized = true; | ||
if (this.initialized === false) { | ||
this.initialized = fs.mkdir(this.dataDirectory); | ||
} | ||
try { | ||
await fs.mkdir(this.dataDirectory); | ||
await this.initialized; | ||
} catch { | ||
// ignore if it already exists | ||
} finally { | ||
this.initialized = true; | ||
} | ||
@@ -36,0 +40,0 @@ } |
{ | ||
"name": "balena-settings-storage", | ||
"version": "6.0.0-6-x-ac866ae8e81880b68b7902f2a467dd3783fbed35", | ||
"version": "6.0.0-6-x-c558eee881428b3893cffebed6e6afb011317536", | ||
"description": "Balena settings storage utilities", | ||
@@ -47,7 +47,10 @@ "main": "build/storage.js", | ||
"ts-node": "^3.3.0", | ||
"typescript": "3.1.3" | ||
"typescript": "^3.9.6" | ||
}, | ||
"dependencies": { | ||
"@types/node": "^10.17.26" | ||
}, | ||
"engines": { | ||
"node": ">=10.17.0" | ||
} | ||
} |
@@ -13,3 +13,3 @@ { | ||
"sourceMap": true, | ||
"strictNullChecks": true, | ||
"strict": true, | ||
"typeRoots": [ | ||
@@ -16,0 +16,0 @@ "node_modules/@types", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55551
930