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

@devsnicket/eunice-dependency-and-structure

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@devsnicket/eunice-dependency-and-structure - npm Package Compare versions

Comparing version 2.7.0 to 2.8.0

18

dist/findItemInStackWithIdentifierHierarchy/formatAncestorIdentifiersOfStackForError.js

@@ -1,3 +0,18 @@

module.exports = stack => ofItemWhenHasValue(stack.parent) || "";
/**
* @typedef Stack
* @property {Item} [parent]
*
* @typedef Item
* @property {String} [id]
* @property {Level} level
*
* @typedef Level
* @property {Stack} stack
*/
module.exports =
/** @param {Stack} stack */
stack => ofItemWhenHasValue(stack.parent) || "";
/** @param {Item} item */
function ofItemWhenHasValue(item) {

@@ -11,2 +26,3 @@ return item && ` in hierarchy ${formatHierarchy()}`;

/** @param {Item} item */
function* getIdentifiersOfItemAndAncestors(item) {

@@ -13,0 +29,0 @@ yield `"${item.id}"`;

@@ -0,1 +1,24 @@

/**
* @typedef Stack
* @property {Item} [parent]
* @property {function(StackReduceSelector,Item):Item} reduce
*
* @callback StackReduceSelector
* @param {Item} item
* @param {Level} level
* @returns {Item}
*
* @typedef Item
* @property {String} [id]
* @property {Stack} [items]
* @property {Level} level
*
* @typedef Level
* @property {function(LevelFindPredicate):Item} find
* @property {Stack} stack
*
* @callback LevelFindPredicate
* @param {Item} item
* @returns {Boolean}
*/
const formatAncestorIdentifiersOfStackForError = require("./formatAncestorIdentifiersOfStackForError");

@@ -7,4 +30,3 @@

* @param {String[]} parameter.identifierHierarchy
* @param {import("../index").Stack} parameter.stack
* @returns {import("../index").Item}
* @param {Stack} parameter.stack
*/

@@ -14,3 +36,5 @@ ({

stack
}) => identifierHierarchy.reduce((item, identifier) => findItemWithIdentifierOrThrowError({
}) => identifierHierarchy.reduce(
/** @param {Item} item */
(item, identifier) => findItemWithIdentifierOrThrowError({
identifier,

@@ -20,2 +44,3 @@ stack: item ? getItemsOfOrThrowError(item) : stack

/** @param {Item} item */
function getItemsOfOrThrowError(item) {

@@ -25,2 +50,7 @@ if (item.items) return item.items;else throw new Error(`Item with identifier "${item.id}" found${formatAncestorIdentifiersOfStackForError(item.level.stack)} has no child items.`);

/**
* @param {Object} parameter
* @param {String} parameter.identifier
* @param {Stack} parameter.stack
*/
function findItemWithIdentifierOrThrowError({

@@ -27,0 +57,0 @@ identifier,

8

dist/index.js

@@ -16,5 +16,7 @@ const createStackFromYaml = require("./createStackFromYaml"),

/**
* @typedef {Level[]} Stack
* @typedef HasOptionalParentItem
* @property {Item} [parent]
*
* @typedef {Level[] & HasOptionalParentItem} Stack
*
* @typedef Item

@@ -27,5 +29,7 @@ * @property {(DependUpon|DependUponMissingItem|DependUponMissingParent)[]} [dependsUpon]

*
* @typedef {Item[]} Level
* @typedef HasStack
* @property {Stack} stack
*
* @typedef {Item[] & HasStack} Level
*
* @typedef DependUpon

@@ -32,0 +36,0 @@ * @property {Item} item

@@ -0,2 +1,15 @@

/**
* @typedef Stack
* @property {Item} [parent]
*
* @typedef Item
* @property {String} [id]
* @property {Level} level
*
* @typedef Level
* @property {Stack} stack
*/
module.exports =
/** @param {Stack} stack */
stack =>

@@ -7,2 +20,3 @@ ofItemWhenHasValue(stack.parent)

/** @param {Item} item */
function ofItemWhenHasValue(

@@ -28,2 +42,3 @@ item,

/** @param {Item} item */
function * getIdentifiersOfItemAndAncestors(

@@ -30,0 +45,0 @@ item,

@@ -0,1 +1,24 @@

/**
* @typedef Stack
* @property {Item} [parent]
* @property {function(StackReduceSelector,Item):Item} reduce
*
* @callback StackReduceSelector
* @param {Item} item
* @param {Level} level
* @returns {Item}
*
* @typedef Item
* @property {String} [id]
* @property {Stack} [items]
* @property {Level} level
*
* @typedef Level
* @property {function(LevelFindPredicate):Item} find
* @property {Stack} stack
*
* @callback LevelFindPredicate
* @param {Item} item
* @returns {Boolean}
*/
const formatAncestorIdentifiersOfStackForError = require("./formatAncestorIdentifiersOfStackForError");

@@ -7,4 +30,3 @@

* @param {String[]} parameter.identifierHierarchy
* @param {import("../index").Stack} parameter.stack
* @returns {import("../index").Item}
* @param {Stack} parameter.stack
*/

@@ -16,2 +38,3 @@ ({

identifierHierarchy.reduce(
/** @param {Item} item */
(

@@ -33,2 +56,3 @@ item,

/** @param {Item} item */
function getItemsOfOrThrowError(

@@ -43,2 +67,7 @@ item,

/**
* @param {Object} parameter
* @param {String} parameter.identifier
* @param {Stack} parameter.stack
*/
function findItemWithIdentifierOrThrowError({

@@ -45,0 +74,0 @@ identifier,

@@ -1,15 +0,38 @@

const
createStackFromYaml = require("../createStackFromYaml"),
findItemWithIdentifierHierarchy = require(".");
const findItemWithIdentifierHierarchy = require(".");
test(
"missing item throws error",
"empty identifier hierarchy returns null",
() =>
expect(
findItemWithIdentifierHierarchy({
identifierHierarchy: [],
stack: null,
}),
)
.toBeNull(),
);
test(
"item missing from empty stack throws error",
() =>
expect(
() =>
findItemWithIdentifierHierarchy({
identifierHierarchy: [ "missing" ],
stack: [],
}),
)
.toThrowError("Identifier of \"missing\" not found."),
);
test(
"item missing from empty level throws error",
() =>
expect(
() =>
findItemWithIdentifierHierarchy({
identifierHierarchy:
[ "missing" ],
stack:
createStackFromYaml("not missing"),
createStackWithLevel([]),
}),

@@ -21,3 +44,3 @@ )

test(
"missing child item throws error",
"missing child item throws error with parent identifer",
() =>

@@ -30,9 +53,10 @@ expect(

stack:
createStackFromYaml(
[ [
{
createStackWithLevel(
[
createParent({
id: "parent",
items: "not missing",
},
] ],
items: [],
stack: {},
}),
],
),

@@ -45,3 +69,3 @@ }),

test(
"missing grand child item throws error",
"missing grandchild item throws error with grandparent and parent identifers",
() =>

@@ -52,24 +76,69 @@ expect(

identifierHierarchy:
[ "grandchild", "parent", "missing" ],
[ "grandparent", "parent", "missing" ],
stack:
createStackFromYaml(
[ [
{
createStackWithLevel(
[
createParent({
id:
"grandchild",
"grandparent",
items:
[ [
{
id: "parent",
items: "not missing",
},
createParent({
id:
"parent",
items:
[],
stack:
createStackParentProperty({
id: "grandparent",
stack: {},
}),
}),
] ],
},
] ],
stack:
{},
}),
],
),
}),
)
.toThrowError("Identifier of \"missing\" not found in hierarchy \"grandchild\"->\"parent\"."),
.toThrowError("Identifier of \"missing\" not found in hierarchy \"grandparent\"->\"parent\"."),
);
function createParent({
id,
items,
stack,
}) {
return (
{
id,
items:
{
...createStackParentProperty({
id,
stack,
}),
reduce:
items.reduce.bind(items),
},
}
);
}
function createStackParentProperty({
id,
stack,
}) {
return (
{
parent:
{
id,
level: { stack },
},
}
);
}
test(

@@ -84,4 +153,9 @@ "no child items throws error",

stack:
createStackFromYaml(
[ [ { id: "parent" } ] ],
createStackWithLevel(
[
{
id: "parent",
level: { stack: {} },
},
],
),

@@ -91,2 +165,15 @@ }),

.toThrowError("Item with identifier \"parent\" found has no child items."),
);
);
function createStackWithLevel(
level,
) {
return (
[
{
find: level.find.bind(level),
stack: null,
},
]
);
}

@@ -18,5 +18,7 @@ const

/**
* @typedef {Level[]} Stack
* @typedef HasOptionalParentItem
* @property {Item} [parent]
*
* @typedef {Level[] & HasOptionalParentItem} Stack
*
* @typedef Item

@@ -29,5 +31,7 @@ * @property {(DependUpon|DependUponMissingItem|DependUponMissingParent)[]} [dependsUpon]

*
* @typedef {Item[]} Level
* @typedef HasStack
* @property {Stack} stack
*
* @typedef {Item[] & HasStack} Level
*
* @typedef DependUpon

@@ -34,0 +38,0 @@ * @property {Item} item

@@ -69,3 +69,3 @@ {

},
"version": "2.7.0"
"version": "2.8.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

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