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

configuration

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configuration - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

8

dist/index.js

@@ -25,3 +25,3 @@ "use strict";

this.defaults = new memory_1.default({ scope: config_1.SCOPE_DEFAULTS });
this.defaults.writeSync(options.defaults ? path_prop_1.default.unflat(options.defaults) : {}, true);
this.defaults.writeSync(options.defaults || {}, true);
if (options.validator) {

@@ -54,3 +54,2 @@ this.validator = options.validator;

provider.validate = this.validate.bind(this);
provider.data = path_prop_1.default.unflat(provider.data);
provider.dataSchema = provider.validate(provider.data);

@@ -219,3 +218,2 @@ provider.onChange(this.refresh.bind(this));

return; //TSC
const dataUnflattened = type_1.default.isString(data) ? data : path_prop_1.default.unflat(data);
if (scope === config_1.SCOPE_ALL) { // All

@@ -225,3 +223,3 @@ for (let scope in this.scopes) {

continue;
this.scopes[scope].write(dataUnflattened);
this.scopes[scope].write(data);
}

@@ -235,3 +233,3 @@ }

throw new Error('You can\'t update unknown scopes');
provider.write(dataUnflattened);
provider.write(data);
}

@@ -238,0 +236,0 @@ }

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

const plain_object_is_equal_1 = require("plain-object-is-equal");
const path_prop_1 = require("path-prop");
const config_1 = require("../config");

@@ -17,4 +18,4 @@ const parser_1 = require("../utils/parser");

this.dataParser = (_b = options === null || options === void 0 ? void 0 : options.parser) !== null && _b !== void 0 ? _b : new parser_1.default((_c = options === null || options === void 0 ? void 0 : options.indentation) !== null && _c !== void 0 ? _c : config_1.DEFAULTS.indentation);
this.defaults = (_d = options === null || options === void 0 ? void 0 : options.defaults) !== null && _d !== void 0 ? _d : config_1.DEFAULTS.defaults;
this.defaultsRaw = (_e = options === null || options === void 0 ? void 0 : options.defaultsRaw) !== null && _e !== void 0 ? _e : config_1.DEFAULTS.defaultsRaw;
this.defaultsRaw = (_d = options === null || options === void 0 ? void 0 : options.defaultsRaw) !== null && _d !== void 0 ? _d : config_1.DEFAULTS.defaultsRaw;
this.defaults = path_prop_1.default.unflat((_e = options === null || options === void 0 ? void 0 : options.defaults) !== null && _e !== void 0 ? _e : (this.dataParser.parse(this.defaultsRaw) || config_1.DEFAULTS.defaults));
this.handlers = [];

@@ -21,0 +22,0 @@ this.init();

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

const plain_object_clone_1 = require("plain-object-clone");
const path_prop_1 = require("path-prop");
const file_1 = require("../utils/file");

@@ -15,3 +16,3 @@ const file_2 = require("./file");

try {
const dataRaw = (_a = await file_1.default.read(this.path, { encoding: 'utf8' })) !== null && _a !== void 0 ? _a : this.defaultsRaw, data = (_b = this.dataParser.parse(dataRaw)) !== null && _b !== void 0 ? _b : plain_object_clone_1.default(this.defaults);
const dataRaw = (_a = await file_1.default.read(this.path, { encoding: 'utf8' })) !== null && _a !== void 0 ? _a : this.defaultsRaw, data = path_prop_1.default.unflat((_b = this.dataParser.parse(dataRaw)) !== null && _b !== void 0 ? _b : this.defaults);
return { data, dataRaw };

@@ -31,3 +32,3 @@ }

try {
const dataRaw = (_a = file_1.default.readSync(this.path, { encoding: 'utf8' })) !== null && _a !== void 0 ? _a : this.defaultsRaw, data = (_b = this.dataParser.parse(dataRaw)) !== null && _b !== void 0 ? _b : plain_object_clone_1.default(this.defaults);
const dataRaw = (_a = file_1.default.readSync(this.path, { encoding: 'utf8' })) !== null && _a !== void 0 ? _a : this.defaultsRaw, data = path_prop_1.default.unflat((_b = this.dataParser.parse(dataRaw)) !== null && _b !== void 0 ? _b : this.defaults);
return { data, dataRaw };

@@ -34,0 +35,0 @@ }

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

const plain_object_clone_1 = require("plain-object-clone");
const path_prop_1 = require("path-prop");
const type_1 = require("../utils/type");

@@ -26,3 +27,3 @@ const abstract_1 = require("./abstract");

if (type_1.default.isString(data)) {
this.data = (_a = this.dataParser.parse(data)) !== null && _a !== void 0 ? _a : plain_object_clone_1.default(this.defaults);
this.data = path_prop_1.default.unflat((_a = this.dataParser.parse(data)) !== null && _a !== void 0 ? _a : this.defaults);
this.dataRaw = data;

@@ -32,4 +33,4 @@ this.dataSchema = this.validate(this.data);

else {
this.data = data;
this.dataRaw = (_b = this.dataParser.stringify(this.data)) !== null && _b !== void 0 ? _b : this.defaultsRaw;
this.data = path_prop_1.default.unflat(data);
this.dataRaw = (_b = this.dataParser.stringify(data)) !== null && _b !== void 0 ? _b : this.defaultsRaw;
this.dataSchema = this.validate(this.data);

@@ -36,0 +37,0 @@ }

"use strict";
/* IMPORT */
Object.defineProperty(exports, "__esModule", { value: true });
const plain_object_clone_1 = require("plain-object-clone");
const path_prop_1 = require("path-prop");
const config_1 = require("../config");

@@ -22,3 +22,3 @@ const memory_1 = require("./memory");

return super.readSync();
const dataRaw = (_a = this.storage.getItem(this.id)) !== null && _a !== void 0 ? _a : this.defaultsRaw, data = (_b = this.dataParser.parse(dataRaw)) !== null && _b !== void 0 ? _b : plain_object_clone_1.default(this.defaults);
const dataRaw = (_a = this.storage.getItem(this.id)) !== null && _a !== void 0 ? _a : this.defaultsRaw, data = path_prop_1.default.unflat((_b = this.dataParser.parse(dataRaw)) !== null && _b !== void 0 ? _b : this.defaults);
return { data, dataRaw };

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

{
"name": "configuration",
"description": "Performant and feature rich library for managing configurations/settings.",
"version": "1.3.2",
"version": "1.3.3",
"main": "dist/index.js",

@@ -6,0 +6,0 @@ "types": "dist/index.d.ts",

@@ -46,3 +46,3 @@

this.defaults = new ProviderMemory ({ scope: SCOPE_DEFAULTS });
this.defaults.writeSync ( options.defaults ? pp.unflat ( options.defaults ) : {}, true );
this.defaults.writeSync ( options.defaults || {}, true );

@@ -100,3 +100,2 @@ if ( options.validator ) {

provider.validate = this.validate.bind ( this );
provider.data = pp.unflat ( provider.data );
provider.dataSchema = provider.validate ( provider.data );

@@ -383,4 +382,2 @@ provider.onChange ( this.refresh.bind ( this ) );

const dataUnflattened = Type.isString ( data ) ? data : pp.unflat ( data );
if ( scope === SCOPE_ALL ) { // All

@@ -392,3 +389,3 @@

this.scopes[scope].write ( dataUnflattened );
this.scopes[scope].write ( data );

@@ -405,3 +402,3 @@ }

provider.write ( dataUnflattened );
provider.write ( data );

@@ -408,0 +405,0 @@ }

@@ -5,2 +5,3 @@

import isEqual from 'plain-object-is-equal';
import pp from 'path-prop';
import {Disposer, Data, DataRaw, DataUpdate, DataParser, ProviderChangeHandler, ProviderAbstractOptions} from '../types';

@@ -30,4 +31,4 @@ import {DEFAULTS, SCOPE_ALL} from '../config';

this.dataParser = options?.parser ?? new Parser ( options?.indentation ?? DEFAULTS.indentation );
this.defaults = options?.defaults ?? DEFAULTS.defaults;
this.defaultsRaw = options?.defaultsRaw ?? DEFAULTS.defaultsRaw;
this.defaults = pp.unflat ( options?.defaults ?? ( this.dataParser.parse ( this.defaultsRaw ) || DEFAULTS.defaults ) );
this.handlers = [];

@@ -34,0 +35,0 @@

@@ -5,2 +5,3 @@

import cloneDeep from 'plain-object-clone';
import pp from 'path-prop';
import {Data, DataRaw, DataUpdate, ProviderJSONOptions} from '../types';

@@ -21,3 +22,3 @@ import File from '../utils/file';

const dataRaw = await File.read ( this.path, { encoding: 'utf8' } ) ?? this.defaultsRaw,
data = this.dataParser.parse ( dataRaw ) ?? cloneDeep ( this.defaults );
data = pp.unflat ( this.dataParser.parse ( dataRaw ) ?? this.defaults );

@@ -44,3 +45,3 @@ return {data, dataRaw};

const dataRaw = File.readSync ( this.path, { encoding: 'utf8' } ) ?? this.defaultsRaw,
data = this.dataParser.parse ( dataRaw ) ?? cloneDeep ( this.defaults );
data = pp.unflat ( this.dataParser.parse ( dataRaw ) ?? this.defaults );

@@ -47,0 +48,0 @@ return {data, dataRaw};

@@ -5,2 +5,3 @@

import cloneDeep from 'plain-object-clone';
import pp from 'path-prop';
import {Data, DataRaw, DataUpdate, ProviderMemoryOptions} from '../types';

@@ -41,3 +42,3 @@ import Type from '../utils/type';

this.data = this.dataParser.parse ( data ) ?? cloneDeep ( this.defaults );
this.data = pp.unflat ( this.dataParser.parse ( data ) ?? this.defaults );
this.dataRaw = data;

@@ -48,4 +49,4 @@ this.dataSchema = this.validate ( this.data );

this.data = data;
this.dataRaw = this.dataParser.stringify ( this.data ) ?? this.defaultsRaw;
this.data = pp.unflat ( data );
this.dataRaw = this.dataParser.stringify ( data ) ?? this.defaultsRaw;
this.dataSchema = this.validate ( this.data );

@@ -52,0 +53,0 @@

/* IMPORT */
import cloneDeep from 'plain-object-clone';
import pp from 'path-prop';
import {Data, DataRaw, DataUpdate, ProviderStorageOptions} from '../types';

@@ -34,3 +34,3 @@ import {DEFAULTS} from '../config';

const dataRaw = this.storage.getItem ( this.id ) ?? this.defaultsRaw,
data = this.dataParser.parse ( dataRaw ) ?? cloneDeep ( this.defaults );
data = pp.unflat ( this.dataParser.parse ( dataRaw ) ?? this.defaults );

@@ -37,0 +37,0 @@ return {data, dataRaw};

@@ -69,2 +69,26 @@

it ( 'supports custom flattened defaults (scope)', t => {
const conf = new Configuration ({ providers: [new ProviderMemory ()], defaults: { 'core.bar': 'custom' } });
t.true ( _.isEqual ( conf.scopes.defaults.data, { core: { bar: 'custom' } } ) );
});
it ( 'supports custom flattened defaults (provider+object)', t => {
const conf = new Configuration ({ providers: [new ProviderMemory ({ defaults: { 'core.foo': 'custom' } })] });
t.true ( _.isEqual ( conf.scopes.provider.data, { core: { foo: 'custom' } } ) );
});
it ( 'supports custom flattened defaults (provider+string)', t => {
const conf = new Configuration ({ providers: [new ProviderMemory ({ defaultsRaw: `{ "core.foo": "custom" }` })] });
t.true ( _.isEqual ( conf.scopes.provider.data, { core: { foo: 'custom' } } ) );
});
it ( 'throws if no providers are passed', t => {

@@ -719,3 +743,3 @@

it ( 'supports flattened objects', t => {
it ( 'supports flattened objects (object)', t => {

@@ -735,2 +759,17 @@ const conf = new Configuration ( Fixtures.options () );

it ( 'supports flattened objects (string)', t => {
const conf = new Configuration ( Fixtures.options () );
conf.update ( 'local', `{
"core.foo": "foo",
"core.bar": "bar"
}`);
t.is ( conf.get ( 'core.foo' ), 'foo' );
t.is ( conf.get ( 'core.bar' ), 'bar' );
t.is ( conf.get ( 'core.baz' ), 'defaults' );
});
it ( 'throws when trying to change defaults', t => {

@@ -1059,4 +1098,25 @@

it ( 'supports flattened objects (string)', async t => {
const conf = new Configuration ( Fixtures.options ({ watch: true }) );
// await new Promise ( resolve => conf.scopes.local.watcher.on ( 'ready', resolve ) ); //FIXME: Not working for some reason
await delay ( 1000 );
fs.writeFileSync ( conf.scopes.local.path, `{
"core.foo": "foo",
"core.bar": "bar"
}`);
await delay ( 1500 );
t.is ( conf.get ( 'core.foo' ), 'foo' );
t.is ( conf.get ( 'core.bar' ), 'bar' );
t.is ( conf.get ( 'core.baz' ), 'defaults' );
});
});
});
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