New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 8.0.1 to 8.1.0-build-data-directory-false-106b2ce73664a26a0ab3e163949b161186bcf1cc-1

8

build/index.browser.d.ts

@@ -1,5 +0,3 @@

import type { BalenaSettingsStorage } from './types';
export type { BalenaSettingsStorage } from './types';
export declare const getStorage: (options: {
dataDirectory?: string;
}) => BalenaSettingsStorage;
import type { BalenaSettingsStorageOptions, BalenaSettingsStorage } from './types';
export type { BalenaSettingsStorageOptions, BalenaSettingsStorage, } from './types';
export declare const getStorage: (options: BalenaSettingsStorageOptions) => BalenaSettingsStorage;

@@ -8,5 +8,5 @@ "use strict";

const getStorage = (options) => {
const store = localStore.isSupported()
? localStore.createStorage(options === null || options === void 0 ? void 0 : options.dataDirectory)
: virtualStore.createStore(options === null || options === void 0 ? void 0 : options.dataDirectory);
const store = (options === null || options === void 0 ? void 0 : options.dataDirectory) === false || !localStore.isSupported()
? virtualStore.createStore()
: localStore.createStorage(options === null || options === void 0 ? void 0 : options.dataDirectory);
return (0, storage_1.getStorage)(store);

@@ -13,0 +13,0 @@ };

@@ -1,5 +0,3 @@

import type { BalenaSettingsStorage } from './types';
export type { BalenaSettingsStorage } from './types';
export declare const getStorage: (options: {
dataDirectory?: string;
}) => BalenaSettingsStorage;
import type { BalenaSettingsStorage, BalenaSettingsStorageOptions } from './types';
export type { BalenaSettingsStorageOptions, BalenaSettingsStorage, } from './types';
export declare const getStorage: (options: BalenaSettingsStorageOptions) => BalenaSettingsStorage;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStorage = void 0;
const nodeStore = require("./stores/node-storage");
const storage_1 = require("./storage");
// use dynamic imports so that node apps have less files to read on startup.
const lazyImport = {
virtual: () => require('./stores/virtual-storage'),
local: () => require('./stores/local-storage'),
node: () => require('./stores/node-storage'),
};
const getStorage = (options) => {
let store;
if (typeof window !== 'undefined') {
// use dynamic imports so that node apps have less files to read on startup.
const localStore = require('./stores/local-storage');
if ((options === null || options === void 0 ? void 0 : options.dataDirectory) === false) {
store = lazyImport.virtual().createStore();
}
else if (typeof window !== 'undefined') {
// Even though we specify an alternative file for this in the package.json's `browser` field
// we still need to handle the `isBrowser` case in the default file for the case that the
// bundler doesn't support/use the `browser` field.
const localStore = lazyImport.local();
store = localStore.isSupported()
? localStore.createStorage(options === null || options === void 0 ? void 0 : options.dataDirectory)
: require('./stores/virtual-storage').createStore(options === null || options === void 0 ? void 0 : options.dataDirectory);
: lazyImport.virtual().createStore(options === null || options === void 0 ? void 0 : options.dataDirectory);
}
else {
// Fallback to filesystem based storage if not in the browser.
store = nodeStore.createStorage(options === null || options === void 0 ? void 0 : options.dataDirectory);
store = lazyImport.node().createStorage(options === null || options === void 0 ? void 0 : options.dataDirectory);
}

@@ -19,0 +29,0 @@ return (0, storage_1.getStorage)(store);

@@ -0,5 +1,5 @@

import { BalenaSettingsStorage, StorageLike } from './types';
/**
* @module storage
*/
import { BalenaSettingsStorage, StorageLike } from './types';
/**

@@ -6,0 +6,0 @@ * @summary Get an instance of storage module

@@ -22,2 +22,5 @@ "use strict";

/**
* @module storage
*/
/**
* @summary Get an instance of storage module

@@ -24,0 +27,0 @@ * @function

@@ -0,1 +1,4 @@

export interface BalenaSettingsStorageOptions {
dataDirectory?: string | false;
}
export interface BalenaSettingsStorage {

@@ -2,0 +5,0 @@ set: (name: string, value: any) => Promise<void>;

@@ -7,2 +7,7 @@ # Change Log

# v8.1.0
## (2023-07-27)
* Support using memory storage by passing dataDirectory: false [Thodoris Greasidis]
# v8.0.1

@@ -9,0 +14,0 @@ ## (2023-07-26)

import * as localStore from './stores/local-storage';
import * as virtualStore from './stores/virtual-storage';
import { getStorage as $getStorage } from './storage';
import type { BalenaSettingsStorage } from './types';
import type {
BalenaSettingsStorageOptions,
BalenaSettingsStorage,
} from './types';
export type { BalenaSettingsStorage } from './types';
export type {
BalenaSettingsStorageOptions,
BalenaSettingsStorage,
} from './types';
export const getStorage = (options: {
dataDirectory?: string;
}): BalenaSettingsStorage => {
const store = localStore.isSupported()
? localStore.createStorage(options?.dataDirectory)
: virtualStore.createStore(options?.dataDirectory);
export const getStorage = (
options: BalenaSettingsStorageOptions,
): BalenaSettingsStorage => {
const store =
options?.dataDirectory === false || !localStore.isSupported()
? virtualStore.createStore()
: localStore.createStorage(options?.dataDirectory);
return $getStorage(store);
};

@@ -1,25 +0,42 @@

import * as nodeStore from './stores/node-storage';
import { getStorage as $getStorage } from './storage';
import type { BalenaSettingsStorage, StorageLike } from './types';
import type {
BalenaSettingsStorage,
BalenaSettingsStorageOptions,
StorageLike,
} from './types';
export type { BalenaSettingsStorage } from './types';
export type {
BalenaSettingsStorageOptions,
BalenaSettingsStorage,
} from './types';
export const getStorage = (options: {
dataDirectory?: string;
}): BalenaSettingsStorage => {
// use dynamic imports so that node apps have less files to read on startup.
const lazyImport = {
virtual: () =>
require('./stores/virtual-storage') as typeof import('./stores/virtual-storage'),
local: () =>
require('./stores/local-storage') as typeof import('./stores/local-storage'),
node: () =>
require('./stores/node-storage') as typeof import('./stores/node-storage'),
};
export const getStorage = (
options: BalenaSettingsStorageOptions,
): BalenaSettingsStorage => {
let store: StorageLike;
if (typeof window !== 'undefined') {
// use dynamic imports so that node apps have less files to read on startup.
const localStore =
require('./stores/local-storage') as typeof import('./stores/local-storage');
if (options?.dataDirectory === false) {
store = lazyImport.virtual().createStore();
} else if (typeof window !== 'undefined') {
// Even though we specify an alternative file for this in the package.json's `browser` field
// we still need to handle the `isBrowser` case in the default file for the case that the
// bundler doesn't support/use the `browser` field.
const localStore = lazyImport.local();
store = localStore.isSupported()
? localStore.createStorage(options?.dataDirectory)
: (
require('./stores/virtual-storage') as typeof import('./stores/virtual-storage')
).createStore(options?.dataDirectory);
: lazyImport.virtual().createStore(options?.dataDirectory);
} else {
// Fallback to filesystem based storage if not in the browser.
store = nodeStore.createStorage(options?.dataDirectory);
store = lazyImport.node().createStorage(options?.dataDirectory);
}
return $getStorage(store);
};

@@ -17,2 +17,5 @@ /*

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

@@ -22,5 +25,2 @@ * @module storage

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

@@ -27,0 +27,0 @@ * @summary Get an instance of storage module

@@ -0,1 +1,5 @@

export interface BalenaSettingsStorageOptions {
dataDirectory?: string | false;
}
export interface BalenaSettingsStorage {

@@ -2,0 +6,0 @@ set: (name: string, value: any) => Promise<void>;

{
"name": "balena-settings-storage",
"version": "8.0.1",
"version": "8.1.0-build-data-directory-false-106b2ce73664a26a0ab3e163949b161186bcf1cc-1",
"description": "Balena settings storage utilities",

@@ -63,4 +63,4 @@ "main": "build/index.js",

"versionist": {
"publishedAt": "2023-07-26T14:05:37.485Z"
"publishedAt": "2023-07-27T08:18:06.896Z"
}
}

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

ERROR, Cannot find module.
* [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
// 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'
});
```
* [.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()
```
Support

@@ -37,0 +157,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