Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

balena-settings-storage

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

balena-settings-storage - npm Package Compare versions

Comparing version 7.0.3-build-flowzone-appvoyer-8971feccdd769237080f9dd69a15735c19f6a7a1-1 to 8.0.0-build-browser-6a1390414ba3b228c79c28cbc172887a76039d40-1

appveyor.yml

19

build/storage.d.ts

@@ -1,3 +0,6 @@

import { BalenaSettingsStorage } from './types';
/**
* @module storage
*/
import { BalenaSettingsStorage, StorageLike } from './types';
/**
* @summary Get an instance of storage module

@@ -13,9 +16,11 @@ * @function

* @example
* const storage = require('balena-settings-storage')({
* // with es6 imports
* import { getStorage } from 'balena-settings-storage';
* // or with node require
* const { getStorage } = require('balena-settings-storage');
*
* const storage = getStorage({
* dataDirectory: '/opt/cache/balena'
* })
* });
*/
declare const getStorage: ({ dataDirectory, }?: {
dataDirectory?: string | undefined;
}) => BalenaSettingsStorage;
export = getStorage;
export declare const getStorage: (store: StorageLike) => BalenaSettingsStorage;

@@ -17,7 +17,5 @@ "use strict";

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStorage = void 0;
const tslib_1 = require("tslib");
/**
* @module storage
*/
const local_storage_1 = require("./local-storage");
const balena_errors_1 = require("balena-errors");

@@ -35,8 +33,12 @@ /**

* @example
* const storage = require('balena-settings-storage')({
* // with es6 imports
* import { getStorage } from 'balena-settings-storage';
* // or with node require
* const { getStorage } = require('balena-settings-storage');
*
* const storage = getStorage({
* dataDirectory: '/opt/cache/balena'
* })
* });
*/
const getStorage = ({ dataDirectory, } = {}) => {
const localStorage = (0, local_storage_1.createStorage)(dataDirectory);
const getStorage = (store) => {
/**

@@ -59,3 +61,3 @@ * @summary Set a value

}
return localStorage.setItem(name, value);
return store.setItem(name, value);
});

@@ -78,3 +80,3 @@ /**

try {
const result = yield localStorage.getItem(name);
const result = yield store.getItem(name);
if (result == null) {

@@ -134,3 +136,3 @@ return undefined;

*/
const remove = (name) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return localStorage.removeItem(name); });
const remove = (name) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return store.removeItem(name); });
/**

@@ -147,6 +149,6 @@ * @summary Remove all values

*/
const clear = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return localStorage.clear(); });
const clear = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return store.clear(); });
return { set, get, has, remove, clear };
};
module.exports = getStorage;
exports.getStorage = getStorage;
//# sourceMappingURL=storage.js.map

@@ -8,1 +8,8 @@ export interface BalenaSettingsStorage {

}
export interface StorageLike {
clear(): PromiseLike<void> | void;
getItem(key: string): PromiseLike<string | null> | string | null;
setItem(key: string, data: string): PromiseLike<void> | void;
removeItem(key: string): PromiseLike<void> | void;
}
export type StorageFactory = (dataDirectory?: string) => StorageLike;
"use strict";
/* TODO:
because we're using `export =` style exports (for the sake of backward-compatibility)
the main module cannot export anything else.
For that matter we have to keep this definition in a separate module
to make it consumable by the downstream TS projects.
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

@@ -7,6 +7,9 @@ # Change Log

# v7.0.3
## (2023-01-19)
# v8.0.0
## (2023-07-24)
* Replace appveyor with flowzone [JSReds]
* Specify a browser entry point [Thodoris Greasidis]
* Use es6 exports [Thodoris Greasidis]
* Update TypeScript to 5.1.6 [Thodoris Greasidis]
* Drop support for nodejs < 14 [Thodoris Greasidis]

@@ -13,0 +16,0 @@ # v7.0.2

@@ -21,4 +21,3 @@ /*

import { createStorage } from './local-storage';
import { BalenaSettingsStorage } from './types';
import { BalenaSettingsStorage, StorageLike } from './types';
import { BalenaSettingsPermissionError } from 'balena-errors';

@@ -37,11 +36,12 @@

* @example
* const storage = require('balena-settings-storage')({
* // with es6 imports
* import { getStorage } from 'balena-settings-storage';
* // or with node require
* const { getStorage } = require('balena-settings-storage');
*
* const storage = getStorage({
* dataDirectory: '/opt/cache/balena'
* })
* });
*/
const getStorage = ({
dataDirectory,
}: { dataDirectory?: string } = {}): BalenaSettingsStorage => {
const localStorage = createStorage(dataDirectory);
export const getStorage = (store: StorageLike): BalenaSettingsStorage => {
/**

@@ -64,3 +64,3 @@ * @summary Set a value

}
return localStorage.setItem(name, value);
return store.setItem(name, value);
};

@@ -86,3 +86,3 @@

try {
const result = await localStorage.getItem(name);
const result = await store.getItem(name);

@@ -147,3 +147,3 @@ if (result == null) {

*/
const remove = async (name: string) => localStorage.removeItem(name);
const remove = async (name: string) => store.removeItem(name);

@@ -161,7 +161,5 @@ /**

*/
const clear = async () => localStorage.clear();
const clear = async () => store.clear();
return { set, get, has, remove, clear };
};
export = getStorage;

@@ -1,8 +0,1 @@

/* TODO:
because we're using `export =` style exports (for the sake of backward-compatibility)
the main module cannot export anything else.
For that matter we have to keep this definition in a separate module
to make it consumable by the downstream TS projects.
*/
export interface BalenaSettingsStorage {

@@ -15,1 +8,10 @@ set: (name: string, value: any) => Promise<void>;

}
export interface StorageLike {
clear(): PromiseLike<void> | void;
getItem(key: string): PromiseLike<string | null> | string | null;
setItem(key: string, data: string): PromiseLike<void> | void;
removeItem(key: string): PromiseLike<void> | void;
}
export type StorageFactory = (dataDirectory?: string) => StorageLike;
{
"name": "balena-settings-storage",
"version": "7.0.3-build-flowzone-appvoyer-8971feccdd769237080f9dd69a15735c19f6a7a1-1",
"version": "8.0.0-build-browser-6a1390414ba3b228c79c28cbc172887a76039d40-1",
"description": "Balena settings storage utilities",
"main": "build/storage.js",
"types": "build/storage.d.ts",
"main": "build/index.js",
"types": "build/index.d.ts",
"browser": {
"build/index.js": "./build/index.browser.js"
},
"homepage": "https://github.com/balena-io-modules/balena-settings-storage",

@@ -29,3 +32,3 @@ "repository": {

"prettify": "balena-lint --typescript --fix lib tests",
"readme": "jsdoc2md --template doc/README.hbs build/storage.js > README.md"
"readme": "jsdoc2md --template doc/README.hbs build/index.js build/storage.js > README.md"
},

@@ -50,3 +53,3 @@ "author": "Juan Cruz Viotti <juan@balena.io>",

"ts-node": "^10.9.1",
"typescript": "^4.8.4"
"typescript": "^5.1.6"
},

@@ -59,7 +62,7 @@ "dependencies": {

"engines": {
"node": ">=10.17.0"
"node": ">=14.0"
},
"versionist": {
"publishedAt": "2023-01-19T14:42:30.220Z"
"publishedAt": "2023-07-24T13:25:28.834Z"
}
}

@@ -34,118 +34,3 @@ balena-settings-storage

* [storage](#module_storage)
* [.getStorage(options)](#module_storage.getStorage) ⇒ <code>storage</code>
* [~set(name, value)](#module_storage.getStorage..set) ⇒ <code>Promise</code>
* [~get(name)](#module_storage.getStorage..get) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;\*&gt;</code>
* [~has(name)](#module_storage.getStorage..has) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code>
* [~remove(name)](#module_storage.getStorage..remove) ⇒ <code>Promise</code>
* [~clear()](#module_storage.getStorage..clear) ⇒ <code>Promise</code>
<a name="module_storage.getStorage"></a>
### storage.getStorage(options) ⇒ <code>storage</code>
**Kind**: static method of [<code>storage</code>](#module_storage)
**Summary**: Get an instance of storage module
**Access**: public
| Param | Type | Description |
| --- | --- | --- |
| options | <code>Object</code> | options |
| options.dataDirectory | <code>string</code> | the directory to use for storage in Node.js. Ignored in the browser. |
**Example**
```js
const storage = require('balena-settings-storage')({
dataDirectory: '/opt/cache/balena'
})
```
* [.getStorage(options)](#module_storage.getStorage) ⇒ <code>storage</code>
* [~set(name, value)](#module_storage.getStorage..set) ⇒ <code>Promise</code>
* [~get(name)](#module_storage.getStorage..get) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;\*&gt;</code>
* [~has(name)](#module_storage.getStorage..has) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code>
* [~remove(name)](#module_storage.getStorage..remove) ⇒ <code>Promise</code>
* [~clear()](#module_storage.getStorage..clear) ⇒ <code>Promise</code>
<a name="module_storage.getStorage..set"></a>
#### getStorage~set(name, value) ⇒ <code>Promise</code>
**Kind**: inner method of [<code>getStorage</code>](#module_storage.getStorage)
**Summary**: Set a value
**Access**: public
| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | name |
| value | <code>\*</code> | value |
**Example**
```js
storage.set('token', '1234')
```
<a name="module_storage.getStorage..get"></a>
#### getStorage~get(name) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;\*&gt;</code>
**Kind**: inner method of [<code>getStorage</code>](#module_storage.getStorage)
**Summary**: Get a value
**Returns**: <code>[ &#x27;Promise&#x27; ].&lt;\*&gt;</code> - value or undefined
**Access**: public
| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | name |
**Example**
```js
storage.get('token').then((token) => {
console.log(token)
});
```
<a name="module_storage.getStorage..has"></a>
#### getStorage~has(name) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code>
**Kind**: inner method of [<code>getStorage</code>](#module_storage.getStorage)
**Summary**: Check if the value exists
**Returns**: <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code> - has value
**Access**: public
| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | name |
**Example**
```js
storage.has('token').then((hasToken) => {
if (hasToken) {
console.log('Yes')
} else {
console.log('No')
});
```
<a name="module_storage.getStorage..remove"></a>
#### getStorage~remove(name) ⇒ <code>Promise</code>
**Kind**: inner method of [<code>getStorage</code>](#module_storage.getStorage)
**Summary**: Remove a value
**Access**: public
| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | name |
**Example**
```js
storage.remove('token')
```
<a name="module_storage.getStorage..clear"></a>
#### getStorage~clear() ⇒ <code>Promise</code>
**Kind**: inner method of [<code>getStorage</code>](#module_storage.getStorage)
**Summary**: Remove all values
**Access**: public
**Example**
```js
storage.clear()
```
ERROR, Cannot find module.
Support

@@ -152,0 +37,0 @@ -------

import { expect } from 'chai';
import * as BalenaSettingsClientModule from 'balena-settings-client';
import { createStorage } from '../lib/local-storage';
import { createStorage } from '../lib/stores/local-storage';

@@ -10,4 +9,5 @@ const IS_BROWSER = typeof window !== 'undefined';

if (!IS_BROWSER) {
// tslint:disable-next-line no-var-requires
const settings: typeof BalenaSettingsClientModule = require('balena-settings-client');
const settings =
// tslint:disable-next-line no-var-requires
require('balena-settings-client') as typeof import('balena-settings-client');
dataDirectory = settings.get<string>('dataDirectory');

@@ -14,0 +14,0 @@ }

@@ -5,10 +5,7 @@ import * as chai from 'chai';

import * as chaiAsPromised from 'chai-as-promised';
import * as BalenaSettingsClientModule from 'balena-settings-client';
import * as FsModule from 'fs';
import * as path from 'path';
import { BalenaSettingsPermissionError } from 'balena-errors';
chai.use(chaiAsPromised);
import { createStorage } from '../lib/local-storage';
import getStorage = require('../lib/storage');
import { createStorage } from '../lib/stores/local-storage';
import { getStorage } from '..';

@@ -18,7 +15,10 @@ const IS_BROWSER = typeof window !== 'undefined';

let dataDirectory: string | undefined;
let fs: typeof FsModule;
let fs: typeof import('fs');
let path: typeof import('path');
if (!IS_BROWSER) {
// tslint:disable no-var-requires
fs = require('fs');
const settings: typeof BalenaSettingsClientModule = require('balena-settings-client');
path = require('path');
const settings =
require('balena-settings-client') as typeof import('balena-settings-client');
dataDirectory = settings.get<string>('dataDirectory');

@@ -25,0 +25,0 @@ }

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc