balena-settings-storage
Advanced tools
Comparing version 8.0.1 to 8.1.0-build-data-directory-false-1b8f7a795219cee4a14cddd5e0167ded1e3de243-1
@@ -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() | ||
const store = (options === null || options === void 0 ? void 0 : options.dataDirectory) !== false && localStore.isSupported() | ||
? localStore.createStorage(options === null || options === void 0 ? void 0 : options.dataDirectory) | ||
: virtualStore.createStore(options === null || options === void 0 ? void 0 : options.dataDirectory); | ||
: virtualStore.createStore(); | ||
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,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-26) | ||
* 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() | ||
? localStore.createStorage(options?.dataDirectory) | ||
: virtualStore.createStore(); | ||
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); | ||
}; |
@@ -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-1b8f7a795219cee4a14cddd5e0167ded1e3de243-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-26T16:06:02.002Z" | ||
} | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
73679
1065
1