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

@contember/config-loader

Package Overview
Dependencies
Maintainers
5
Versions
262
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contember/config-loader - npm Package Compare versions

Comparing version 0.12.0-alpha.2 to 0.12.0-alpha.4

2

dist/src/config/adapters/YamlAdapter.js

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

parse(input) {
return yaml.safeLoad(input);
return yaml.load(input);
}

@@ -10,0 +10,0 @@ }

@@ -7,2 +7,3 @@ declare class Loader {

load(filename: string): Promise<any>;
loadString(content: string, adapter: string): Promise<any>;
private includeConfigs;

@@ -9,0 +10,0 @@ }

@@ -28,2 +28,8 @@ "use strict";

}
async loadString(content, adapter) {
if (!this.adapters[adapter]) {
throw new Loader.UnresolvedAdapterError(`Adapter for ${adapter} not found.`);
}
return this.adapters[adapter].parse(content);
}
async includeConfigs(data, baseDir) {

@@ -30,0 +36,0 @@ if (Array.isArray(data)) {

@@ -45,5 +45,14 @@ "use strict";

if (typeof data === 'string') {
const match = /^%(\?)?(\w+(?:\.\w+)*)(?:::(\w+))?%$/.exec(data);
if (match) {
const [, optional, parameter, cast] = match;
const expression = /^%([?])?([\w|:.]+)%$/.exec(data);
if (!expression) {
return data;
}
const isOptional = expression[1];
const expressions = expression[2].split(/\|\|/g);
for (const [i, expr] of expressions.entries()) {
const singleExpression = /^(\w+(?:\.\w+)*)(?:::(\w+))?$/.exec(expr);
if (!singleExpression) {
throw new Error(`Invalid config expression ${expr}`);
}
const [, parameter, cast] = singleExpression;
const parts = parameter.split('.');

@@ -67,4 +76,9 @@ try {

catch (e) {
if (optional && e instanceof UndefinedParameterError) {
return undefined;
if (e instanceof UndefinedParameterError) {
if (expressions[i + 1] !== undefined) {
continue;
}
else if (isOptional) {
return undefined;
}
}

@@ -74,5 +88,2 @@ throw e;

}
else {
return data;
}
}

@@ -79,0 +90,0 @@ if (data === null) {

{
"name": "@contember/config-loader",
"version": "0.12.0-alpha.2",
"version": "0.12.0-alpha.4",
"license": "Apache-2.0",

@@ -11,8 +11,8 @@ "main": "dist/src/index.js",

"devDependencies": {
"@types/js-yaml": "^3.12.1",
"@types/node": "^14.6.4"
"@types/js-yaml": "^4.0.1",
"@types/node": "^15.12.5"
},
"dependencies": {
"js-yaml": "^3.13.1"
"js-yaml": "^4.1.0"
}
}

@@ -6,4 +6,4 @@ import Loader from '../Loader'

parse(input: string): any {
return yaml.safeLoad(input)
return yaml.load(input)
}
}

@@ -30,2 +30,9 @@ import { dirname, extname, join } from 'path'

public async loadString(content: string, adapter: string): Promise<any> {
if (!this.adapters[adapter]) {
throw new Loader.UnresolvedAdapterError(`Adapter for ${adapter} not found.`)
}
return this.adapters[adapter].parse(content)
}
private async includeConfigs(data: any, baseDir: string): Promise<any> {

@@ -32,0 +39,0 @@ if (Array.isArray(data)) {

@@ -7,9 +7,11 @@ export type Path = (string | number)[]

export const createObjectParametersResolver = (parameters: any): ParametersResolver => parts =>
parts.reduce((current, part) => {
if (current === null || typeof current !== 'object' || typeof current[part] === 'undefined') {
throw new UndefinedParameterError(`Parameter "${parts.join('.')}" not found.`)
}
return current[part]
}, parameters)
export const createObjectParametersResolver =
(parameters: any): ParametersResolver =>
parts =>
parts.reduce((current, part) => {
if (current === null || typeof current !== 'object' || typeof current[part] === 'undefined') {
throw new UndefinedParameterError(`Parameter "${parts.join('.')}" not found.`)
}
return current[part]
}, parameters)

@@ -52,5 +54,14 @@ export const resolveParameters = (data: any, parametersResolver: ParametersResolver): any => {

if (typeof data === 'string') {
const match = /^%(\?)?(\w+(?:\.\w+)*)(?:::(\w+))?%$/.exec(data)
if (match) {
const [, optional, parameter, cast] = match
const expression = /^%([?])?([\w|:.]+)%$/.exec(data)
if (!expression) {
return data
}
const isOptional = expression[1]
const expressions: string[] = expression[2].split(/\|\|/g)
for (const [i, expr] of expressions.entries()) {
const singleExpression = /^(\w+(?:\.\w+)*)(?:::(\w+))?$/.exec(expr)
if (!singleExpression) {
throw new Error(`Invalid config expression ${expr}`)
}
const [, parameter, cast] = singleExpression
const parts = parameter.split('.')

@@ -73,9 +84,11 @@ try {

} catch (e) {
if (optional && e instanceof UndefinedParameterError) {
return undefined
if (e instanceof UndefinedParameterError) {
if (expressions[i + 1] !== undefined) {
continue
} else if (isOptional) {
return undefined
}
}
throw e
}
} else {
return data
}

@@ -82,0 +95,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

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