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

@balena/contrato

Package Overview
Dependencies
Maintainers
3
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@balena/contrato - npm Package Compare versions

Comparing version 0.7.2 to 0.8.0-build-blueprint-reproduce-iterable-fae0a843ad7b6ea45feaef2365b88a20617e26fe-1

2

build/blueprint.d.ts

@@ -9,2 +9,4 @@ import Contract from './contract';

reproduce(contract: Contract): Contract[];
reproduce(contract: Contract, asIterable: true): IterableIterator<Contract>;
reproduce(contract: Contract, asIterable?: boolean): Contract[] | IterableIterator<Contract>;
}

57

build/blueprint.js

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

});
this.metadata.layout = reduce_1.default(this.raw.layout, (accumulator, value, type) => {
this.metadata.layout = (0, reduce_1.default)(this.raw.layout, (accumulator, value, type) => {
const selector = {
cardinality: cardinality_1.parse(value.cardinality || value),
cardinality: (0, cardinality_1.parse)(value.cardinality || value),
filter: value.filter,

@@ -40,3 +40,3 @@ type: value.type || type,

const group = selector.cardinality.finite ? 'finite' : 'infinite';
accumulator[group].selectors[selector.type] = concat_1.default(accumulator[group].selectors[selector.type] || [], [selector]);
accumulator[group].selectors[selector.type] = (0, concat_1.default)(accumulator[group].selectors[selector.type] || [], [selector]);
accumulator[group].types.add(selector.type);

@@ -61,7 +61,7 @@ accumulator.types.add(selector.type);

const layout = this.metadata.layout;
const combinations = reduce_1.default(layout.finite.selectors, (accumulator, value) => {
const combinations = (0, reduce_1.default)(layout.finite.selectors, (accumulator, value) => {
let internalAccumulator = accumulator;
forEach_1.default(value, (option) => {
const combi = uniqWith_1.default(contract.getChildrenCombinations(option), (left, right) => {
return isEqual_1.default(left[0].raw, right[0].raw);
(0, forEach_1.default)(value, (option) => {
const combi = (0, uniqWith_1.default)(contract.getChildrenCombinations(option), (left, right) => {
return (0, isEqual_1.default)(left[0].raw, right[0].raw);
});

@@ -72,9 +72,9 @@ internalAccumulator = internalAccumulator.concat([combi]);

}, []);
forEach_1.default(combinations, (dimension) => {
(0, forEach_1.default)(combinations, (dimension) => {
dimension.sort((left, right) => {
return semver_1.compare(left[0].raw.version, right[0].raw.version);
return (0, semver_1.compare)(left[0].raw.version, right[0].raw.version);
});
});
const currentPointer = new Array(combinations.length);
fill_1.default(currentPointer, 0);
(0, fill_1.default)(currentPointer, 0);
const bestPointer = new Array(combinations.length);

@@ -92,3 +92,3 @@ for (let idx = 0; idx < combinations.length; idx++) {

}
context.addChildren(flatten_1.default(combination), {
context.addChildren((0, flatten_1.default)(combination), {
rehash: true,

@@ -119,4 +119,4 @@ });

const requirements = context.getAllNotSatisfiedChildRequirements();
const newRequirements = uniqWith_1.default(filter_1.default(concat_1.default(context.raw.requires, requirements)), isEqual_1.default);
if (newRequirements && !isEmpty_1.default(newRequirements)) {
const newRequirements = (0, uniqWith_1.default)((0, filter_1.default)((0, concat_1.default)(context.raw.requires, requirements)), isEqual_1.default);
if (newRequirements && !(0, isEmpty_1.default)(newRequirements)) {
if (!options.allowRequirements) {

@@ -128,4 +128,4 @@ return null;

}
const childCapabilities = filter_1.default(uniqWith_1.default(flatMap_1.default(context.getChildren(), (v) => v.raw.capabilities), isEqual_1.default));
if (childCapabilities && !isEmpty_1.default(childCapabilities)) {
const childCapabilities = (0, filter_1.default)((0, uniqWith_1.default)((0, flatMap_1.default)(context.getChildren(), (v) => v.raw.capabilities), isEqual_1.default));
if (childCapabilities && !(0, isEmpty_1.default)(childCapabilities)) {
context.raw.capabilities = childCapabilities;

@@ -145,9 +145,9 @@ context.interpolate();

const checked = [];
const pointerValue = (pointer) => reduce_1.default(pointer, (sum, value) => sum + value, 0);
const pointerValue = (pointer) => (0, reduce_1.default)(pointer, (sum, value) => sum + value, 0);
let currentBestPointer = new Array(combinations.length);
fill_1.default(currentBestPointer, 0);
(0, fill_1.default)(currentBestPointer, 0);
const currentBestPointerValue = pointerValue(currentBestPointer);
let currentBestPath = [];
const isValidPointer = (pointer) => {
if (includes_1.default(checked, pointer)) {
if ((0, includes_1.default)(checked, pointer)) {
return false;

@@ -168,8 +168,8 @@ }

for (let idx = 0; idx < combos.length; idx++) {
const possiblePointer = clone_1.default(pointer);
const possiblePointer = (0, clone_1.default)(pointer);
possiblePointer[idx] += 1;
if (isValidPointer(possiblePointer)) {
const currentPath = clone_1.default(path);
const currentPath = (0, clone_1.default)(path);
currentPath.push(possiblePointer);
if (isEqual_1.default(possiblePointer, bestPointer)) {
if ((0, isEqual_1.default)(possiblePointer, bestPointer)) {
currentBestPath = currentPath;

@@ -196,3 +196,3 @@ return true;

}
return reduce_1.default(currentBestPath, (seq, pointer) => {
return (0, reduce_1.default)(currentBestPath, (seq, pointer) => {
const context = buildContextFromPointer(pointer);

@@ -211,7 +211,10 @@ if (context) {

}
reproduce(contract) {
reproduce(contract, asIterable = false) {
if (!asIterable) {
return [...this.reproduce(contract, true)];
}
const layout = this.metadata.layout;
const combinations = reduce_1.default(layout.finite.selectors, (accumulator, value) => {
const combinations = (0, reduce_1.default)(layout.finite.selectors, (accumulator, value) => {
let internalAccumulator = accumulator;
forEach_1.default(value, (option) => {
(0, forEach_1.default)(value, (option) => {
internalAccumulator = internalAccumulator.concat([

@@ -223,3 +226,3 @@ contract.getChildrenCombinations(option),

}, []);
const product = utils_1.cartesianProductWith(combinations, (accumulator, element) => {
const productIterator = (0, utils_1.cartesianProductWith)(combinations, (accumulator, element) => {
if (accumulator instanceof contract_1.default) {

@@ -246,3 +249,3 @@ const prodContext = new contract_1.default(this.raw.skeleton, {

}, [[]]);
return flatten_1.default(product).filter((context) => {
return (0, utils_1.filter)((0, utils_1.flatten)(productIterator), (context) => {
const references = context.getChildrenCrossReferencedContracts({

@@ -249,0 +252,0 @@ from: contract,

@@ -17,34 +17,34 @@ "use strict";

const ORDERED_LIST_LENGTH = 2;
exports.parse = (input) => {
if (isNumber_1.default(input)) {
return exports.parse([input, input]);
const parse = (input) => {
if ((0, isNumber_1.default)(input)) {
return (0, exports.parse)([input, input]);
}
if (isString_1.default(input)) {
const normalizedInput = trim_1.default(input);
if ((0, isString_1.default)(input)) {
const normalizedInput = (0, trim_1.default)(input);
if (normalizedInput === '*') {
return exports.parse([0, Infinity]);
return (0, exports.parse)([0, Infinity]);
}
if (normalizedInput === '?' || /^1\s*\?$/.test(normalizedInput)) {
return exports.parse([0, 1]);
return (0, exports.parse)([0, 1]);
}
if (/^[0-9]+$/.test(normalizedInput)) {
const num = parseInt(normalizedInput, 10);
return exports.parse([num, num]);
return (0, exports.parse)([num, num]);
}
return exports.parse([parseInt(join_1.default(initial_1.default(normalizedInput), ''), 10), Infinity]);
return (0, exports.parse)([parseInt((0, join_1.default)((0, initial_1.default)(normalizedInput), ''), 10), Infinity]);
}
const [from, to] = input;
if (typeof to === 'string' && trim_1.default(to) === '*') {
return exports.parse([from, Infinity]);
if (typeof to === 'string' && (0, trim_1.default)(to) === '*') {
return (0, exports.parse)([from, Infinity]);
}
if (typeof from === 'string' ||
typeof to === 'string' ||
some_1.default([
isEqual_1.default(input, [0, 0]),
(0, some_1.default)([
(0, isEqual_1.default)(input, [0, 0]),
from < 0,
to < 0,
size_1.default(input) !== ORDERED_LIST_LENGTH,
(0, size_1.default)(input) !== ORDERED_LIST_LENGTH,
from > to,
!isInteger_1.default(from),
!isInteger_1.default(to) && to !== Infinity,
!(0, isInteger_1.default)(from),
!(0, isInteger_1.default)(to) && to !== Infinity,
])) {

@@ -59,2 +59,3 @@ throw new Error(`Invalid cardinality: ${input}`);

};
exports.parse = parse;
//# sourceMappingURL=cardinality.js.map

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

const utils_1 = require("./utils");
exports.build = (contract) => {
const build = (contract) => {
const tree = {};
for (const type of contract.metadata.children.types) {
if (contract.metadata.children.byType[type].size === 1) {
const hash = utils_1.setFirst(contract.metadata.children.byType[type]);
const hash = (0, utils_1.setFirst)(contract.metadata.children.byType[type]);
const child = contract.getChildByHash(hash);

@@ -20,3 +20,3 @@ if (child === undefined) {

}
set_1.default(tree, type, child.toJSON());
(0, set_1.default)(tree, type, child.toJSON());
continue;

@@ -36,3 +36,3 @@ }

}
set_1.default(tree, `${type}.${slug}`, sources.length === 1 ? sources[0] : sources);
(0, set_1.default)(tree, `${type}.${slug}`, sources.length === 1 ? sources[0] : sources);
}

@@ -42,5 +42,6 @@ }

};
exports.getAll = (tree) => reduce_1.default(tree, (accumulator, value, _) => {
exports.build = build;
const getAll = (tree) => (0, reduce_1.default)(tree, (accumulator, value, _) => {
if (!value.slug) {
const out = accumulator.concat(exports.getAll(value));
const out = accumulator.concat((0, exports.getAll)(value));
return out;

@@ -51,2 +52,3 @@ }

}, []);
exports.getAll = getAll;
//# sourceMappingURL=children-tree.js.map

@@ -35,2 +35,4 @@ "use strict";

class Contract {
metadata;
raw;
constructor(object, options = {}) {

@@ -48,3 +50,3 @@ this.raw = object;

};
for (const source of children_tree_2.getAll(this.raw.children)) {
for (const source of (0, children_tree_2.getAll)(this.raw.children)) {
this.addChild(new Contract(source));

@@ -55,3 +57,3 @@ }

});
defaults_1.default(options, {
(0, defaults_1.default)(options, {
hash: true,

@@ -64,6 +66,6 @@ });

hash() {
this.metadata.hash = hash_1.hashObject(this.raw);
this.metadata.hash = (0, hash_1.hashObject)(this.raw);
}
rebuild() {
const tree = children_tree_1.build(this);
const tree = (0, children_tree_1.build)(this);
if (Object.keys(tree).length > 0) {

@@ -96,3 +98,3 @@ this.raw.children = tree;

}
const operand = first_1.default(keys_1.default(conjunct));
const operand = (0, first_1.default)((0, keys_1.default)(conjunct));
if (operand) {

@@ -116,6 +118,6 @@ const matchers = new object_set_1.default();

interpolate(options = { rehash: Boolean }) {
this.raw = template_1.compileContract(this.raw, {
this.raw = (0, template_1.compileContract)(this.raw, {
blacklist: new Set(['children']),
});
defaults_1.default(options, {
(0, defaults_1.default)(options, {
rehash: true,

@@ -176,3 +178,3 @@ });

this.metadata.children.searchCache.resetType(type);
defaults_1.default(options, {
(0, defaults_1.default)(options, {
rehash: true,

@@ -190,3 +192,3 @@ rebuild: true,

removeChild(contract, options = {}) {
defaults_1.default(options, {
(0, defaults_1.default)(options, {
rehash: true,

@@ -225,3 +227,3 @@ });

}
defaults_1.default(options, {
(0, defaults_1.default)(options, {
rehash: true,

@@ -254,3 +256,3 @@ });

getChildren(options = {}) {
return reduce_1.default(this.metadata.children.map, (accumulator, contract) => {
return (0, reduce_1.default)(this.metadata.children.map, (accumulator, contract) => {
if (!options.types ||

@@ -277,3 +279,3 @@ options.types.has(contract.raw.type)) {

for (const contract of this.getChildren().concat([this])) {
const match = matches_1.default(omit_1.default(matcher.raw.data, ['slug', 'version']));
const match = (0, matches_1.default)((0, omit_1.default)(matcher.raw.data, ['slug', 'version']));
const versionMatch = matcher.raw.data.version;

@@ -284,8 +286,8 @@ if (contract.raw.capabilities) {

if (versionMatch) {
if (semver_1.valid(capability.version) && semver_1.validRange(versionMatch)) {
if (semver_1.satisfies(capability.version, versionMatch)) {
if ((0, semver_1.valid)(capability.version) && (0, semver_1.validRange)(versionMatch)) {
if ((0, semver_1.satisfies)(capability.version, versionMatch)) {
results.push(contract);
}
}
else if (isEqual_1.default(capability.version, versionMatch)) {
else if ((0, isEqual_1.default)(capability.version, versionMatch)) {
results.push(contract);

@@ -300,3 +302,3 @@ }

}
return uniqWith_1.default(results, isEqual_1.default);
return (0, uniqWith_1.default)(results, isEqual_1.default);
}

@@ -320,3 +322,3 @@ findChildren(matcher) {

}
const match = matches_1.default(omit_1.default(matcher.raw.data, ['slug', 'version']));
const match = (0, matches_1.default)((0, omit_1.default)(matcher.raw.data, ['slug', 'version']));
const versionMatch = matcher.raw.data.version;

@@ -340,8 +342,8 @@ const hashes = slug

if (versionMatch) {
if (semver_1.valid(child.raw.version) && semver_1.validRange(versionMatch)) {
if (semver_1.satisfies(child.raw.version, versionMatch)) {
if ((0, semver_1.valid)(child.raw.version) && (0, semver_1.validRange)(versionMatch)) {
if ((0, semver_1.satisfies)(child.raw.version, versionMatch)) {
results.push(child);
}
}
else if (isEqual_1.default(child.raw.version, versionMatch)) {
else if ((0, isEqual_1.default)(child.raw.version, versionMatch)) {
results.push(child);

@@ -363,4 +365,4 @@ }

if (options['filter']) {
const filterValidator = partial_1.default(skhema_1.isValid, options['filter']);
contracts = filter_1.default(contracts, (con) => {
const filterValidator = (0, partial_1.default)(skhema_1.isValid, options['filter']);
contracts = (0, filter_1.default)(contracts, (con) => {
return filterValidator(con.raw);

@@ -371,5 +373,5 @@ });

if (options['version']) {
if (isEqual_1.default(options['version'], 'latest')) {
if ((0, isEqual_1.default)(options['version'], 'latest')) {
contracts.sort((left, right) => {
return semver_1.compare(right.raw.version, left.raw.version);
return (0, semver_1.compare)(right.raw.version, left.raw.version);
});

@@ -379,4 +381,4 @@ contracts = contracts.slice(0, Math.min(contracts.length, cardinality.to));

else {
contracts = filter_1.default(contracts, (con) => {
return semver_1.satisfies(con.raw.version, options['version']);
contracts = (0, filter_1.default)(contracts, (con) => {
return (0, semver_1.satisfies)(con.raw.version, options['version']);
});

@@ -395,5 +397,5 @@ }

}
const rang = range_1.default(cardinality.from, Math.min(cardinality.to, contracts.length) + 1);
return flatMap_1.default(rang, (tcardinality) => {
return js_combinatorics_1.bigCombination(contracts, tcardinality).toArray();
const rang = (0, range_1.default)(cardinality.from, Math.min(cardinality.to, contracts.length) + 1);
return (0, flatMap_1.default)(rang, (tcardinality) => {
return (0, js_combinatorics_1.bigCombination)(contracts, tcardinality).toArray();
});

@@ -434,8 +436,8 @@ }

}
return reduce_1.default(result, (accumulator, value) => {
return accumulator.concat(intersectionWith_1.default(...value, Contract.isEqual));
return (0, reduce_1.default)(result, (accumulator, value) => {
return accumulator.concat((0, intersectionWith_1.default)(...value, Contract.isEqual));
}, []);
}
getNotSatisfiedChildRequirements(contract, options = { types: new Set() }) {
const conjuncts = reduce_1.default(contract.getChildren(), (accumulator, child) => {
const conjuncts = (0, reduce_1.default)(contract.getChildren(), (accumulator, child) => {
return accumulator.concat(child.metadata.requirements.compiled.getAll());

@@ -454,6 +456,6 @@ }, contract.metadata.requirements.compiled.getAll());

if (conjunct.raw.operation === 'or') {
const disjuncts = filter_1.default(conjunct.raw.data.getAll(), (disjunct) => {
const disjuncts = (0, filter_1.default)(conjunct.raw.data.getAll(), (disjunct) => {
return shouldEvaluateType(disjunct.raw.data.type);
});
if (disjuncts.length === 0 || some_1.default(map_1.default(disjuncts, hasMatch))) {
if (disjuncts.length === 0 || (0, some_1.default)((0, map_1.default)(disjuncts, hasMatch))) {
continue;

@@ -473,3 +475,3 @@ }

satisfiesChildContract(contract, options = {}) {
const conjuncts = reduce_1.default(contract.getChildren(), (accumulator, child) => {
const conjuncts = (0, reduce_1.default)(contract.getChildren(), (accumulator, child) => {
return accumulator.concat(child.metadata.requirements.compiled.getAll());

@@ -484,6 +486,6 @@ }, contract.metadata.requirements.compiled.getAll());

if (conjunct.raw.operation === 'or') {
const disjuncts = filter_1.default(conjunct.raw.data.getAll(), (disjunct) => {
const disjuncts = (0, filter_1.default)(conjunct.raw.data.getAll(), (disjunct) => {
return shouldEvaluateType(disjunct.raw.data.type);
});
if (disjuncts.length === 0 || some_1.default(map_1.default(disjuncts, hasMatch))) {
if (disjuncts.length === 0 || (0, some_1.default)((0, map_1.default)(disjuncts, hasMatch))) {
continue;

@@ -494,6 +496,6 @@ }

else if (conjunct.raw.operation === 'not') {
const disjuncts = filter_1.default(conjunct.raw.data.getAll(), (disjunct) => {
const disjuncts = (0, filter_1.default)(conjunct.raw.data.getAll(), (disjunct) => {
return shouldEvaluateType(disjunct.raw.data.type);
});
if (disjuncts.length > 0 && some_1.default(map_1.default(disjuncts, hasMatch))) {
if (disjuncts.length > 0 && (0, some_1.default)((0, map_1.default)(disjuncts, hasMatch))) {
return false;

@@ -512,3 +514,3 @@ }

if (options.types &&
utils_1.areSetsDisjoint(options.types, contract.metadata.requirements.types)) {
(0, utils_1.areSetsDisjoint)(options.types, contract.metadata.requirements.types)) {
continue;

@@ -528,4 +530,4 @@ }

if (options.types &&
utils_1.areSetsDisjoint(options.types, contract.metadata.requirements.types)) {
requirements = concat_1.default(requirements, map_1.default(contract.metadata.requirements.compiled.getAll(), 'data'));
(0, utils_1.areSetsDisjoint)(options.types, contract.metadata.requirements.types)) {
requirements = (0, concat_1.default)(requirements, (0, map_1.default)(contract.metadata.requirements.compiled.getAll(), 'data'));
continue;

@@ -536,3 +538,3 @@ }

});
requirements = concat_1.default(requirements, contractRequirements);
requirements = (0, concat_1.default)(requirements, contractRequirements);
}

@@ -552,10 +554,10 @@ return requirements;

}
return isEqual_1.default(contract1.raw, contract2.raw);
return (0, isEqual_1.default)(contract1.raw, contract2.raw);
}
static build(source) {
const rawContracts = variants_1.build(source);
return reduce_1.default(rawContracts, (accumulator, variant) => {
const rawContracts = (0, variants_1.build)(source);
return (0, reduce_1.default)(rawContracts, (accumulator, variant) => {
const aliases = variant['aliases'] || [];
const obj = omit_1.default(variant, ['aliases']);
const contracts = map_1.default(aliases, (alias) => {
const obj = (0, omit_1.default)(variant, ['aliases']);
const contracts = (0, map_1.default)(aliases, (alias) => {
return new Contract(Object.assign({}, obj, {

@@ -562,0 +564,0 @@ canonicalSlug: obj['slug'],

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

const object_hash_1 = __importDefault(require("object-hash"));
exports.hashObject = (object) => object_hash_1.default(object, {
const hashObject = (object) => (0, object_hash_1.default)(object, {
algorithm: 'sha1',

@@ -14,2 +14,3 @@ ignoreUnknown: true,

});
exports.hashObject = hashObject;
//# sourceMappingURL=hash.js.map

@@ -7,3 +7,3 @@ import { BlueprintLayout, BlueprintObject, ContractObject } from './types/types';

export { BlueprintLayout, ContractObject, BlueprintObject, Contract, Blueprint, buildTemplate, parseCardinality, };
export declare const query: (universe: Contract, layout: BlueprintLayout, skeleton: object) => Contract[];
export declare const query: (universe: Contract, layout: BlueprintLayout, skeleton: object, asIterable?: boolean) => Contract[] | IterableIterator<Contract>;
export declare const sequence: (universe: Contract, layout: BlueprintLayout, skeleton: object) => Contract[];

@@ -15,4 +15,6 @@ "use strict";

Object.defineProperty(exports, "parseCardinality", { enumerable: true, get: function () { return cardinality_1.parse; } });
exports.query = (universe, layout, skeleton) => new blueprint_1.default(layout, skeleton).reproduce(universe);
exports.sequence = (universe, layout, skeleton) => new blueprint_1.default(layout, skeleton).sequence(universe);
const query = (universe, layout, skeleton, asIterable = false) => new blueprint_1.default(layout, skeleton).reproduce(universe, asIterable);
exports.query = query;
const sequence = (universe, layout, skeleton) => new blueprint_1.default(layout, skeleton).sequence(universe);
exports.sequence = sequence;
//# sourceMappingURL=index.js.map

@@ -14,2 +14,4 @@ "use strict";

class MatcherCache {
data;
types;
constructor() {

@@ -20,3 +22,3 @@ this.data = {};

add(matcher, value) {
set_1.default(this.data, getMatcherCachePath(matcher), {
(0, set_1.default)(this.data, getMatcherCachePath(matcher), {
value,

@@ -29,3 +31,3 @@ matcher,

const path = getMatcherCachePath(matcher);
return get_1.default(this.data, concat_1.default(path, ['value']), null);
return (0, get_1.default)(this.data, (0, concat_1.default)(path, ['value']), null);
}

@@ -32,0 +34,0 @@ getTypes() {

@@ -12,2 +12,4 @@ "use strict";

class ObjectSet {
cache;
data;
constructor(objects = []) {

@@ -19,5 +21,5 @@ this.cache = {

for (const object of objects) {
if (isArray_1.default(object)) {
const firstObj = first_1.default(object);
const lastObj = last_1.default(object);
if ((0, isArray_1.default)(object)) {
const firstObj = (0, first_1.default)(object);
const lastObj = (0, last_1.default)(object);
if (firstObj && lastObj) {

@@ -33,3 +35,3 @@ this.add(firstObj, lastObj);

add(object, options = {}) {
const id = options.id || hash_1.hashObject(object);
const id = options.id || (0, hash_1.hashObject)(object);
if (this.hasId(id)) {

@@ -45,3 +47,3 @@ return;

hasObject(object) {
return Boolean(this.data[hash_1.hashObject(object)]);
return Boolean(this.data[(0, hash_1.hashObject)(object)]);
}

@@ -52,3 +54,3 @@ hasId(id) {

getAll() {
return values_1.default(this.data);
return (0, values_1.default)(this.data);
}

@@ -55,0 +57,0 @@ intersection(set) {

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -50,20 +54,22 @@ return result;

const utils_1 = require("./utils");
const debug = debug_1.default('partials');
const debug = (0, debug_1.default)('partials');
const REFERENCE_DELIMITER = '+';
exports.findPartial = (name, context, options) => {
return flow_1.default((structure) => map_1.default(structure, (type) => {
const findPartial = (name, context, options) => {
return (0, flow_1.default)((structure) => (0, map_1.default)(structure, (type) => {
const children = context.getChildrenByType(type);
const contracts = flow_1.default((childrenRaw) => map_1.default(childrenRaw, (contract) => {
const contracts = (0, flow_1.default)((childrenRaw) => (0, map_1.default)(childrenRaw, (contract) => {
const rawContract = contract.toJSON();
rawContract.slug = contract.getCanonicalSlug();
return new contract_1.default(rawContract);
}), (childrenContracts) => sortBy_1.default(childrenContracts, (contract) => contract.getSlug()))(children);
}), (childrenContracts) => (0, sortBy_1.default)(childrenContracts, (contract) => contract.getSlug()))(children);
return [
join_1.default(invokeMap_1.default(contracts, 'getReferenceString'), REFERENCE_DELIMITER),
join_1.default(invokeMap_1.default(contracts, 'getSlug'), REFERENCE_DELIMITER),
(0, join_1.default)((0, invokeMap_1.default)(contracts, 'getReferenceString'), REFERENCE_DELIMITER),
(0, join_1.default)((0, invokeMap_1.default)(contracts, 'getSlug'), REFERENCE_DELIMITER),
];
}), (structureReferences) => thru_1.default(structureReferences, (combinations) => {
const products = utils_1.cartesianProductWith(combinations, (accumulator, element) => accumulator.concat([element]), [[]]);
const slices = reduce_1.default(range_1.default(options.structure.length, 1, -1), (accumulator, slice) => accumulator.concat(invokeMap_1.default(products, 'slice', 0, slice)), []);
const fallbackPaths = combinations.reduce((accumulator, _, index, collection) => map_1.default([map_1.default(collection, first_1.default), map_1.default(collection, last_1.default)], (list) => take_1.default(list, index + 1)).concat(accumulator), []);
}), (structureReferences) => (0, thru_1.default)(structureReferences, (combinations) => {
const products = [
...(0, utils_1.cartesianProductWith)(combinations, (accumulator, element) => accumulator.concat([element]), [[]]),
];
const slices = (0, reduce_1.default)((0, range_1.default)(options.structure.length, 1, -1), (accumulator, slice) => accumulator.concat((0, invokeMap_1.default)(products, 'slice', 0, slice)), []);
const fallbackPaths = combinations.reduce((accumulator, _, index, collection) => (0, map_1.default)([(0, map_1.default)(collection, first_1.default), (0, map_1.default)(collection, last_1.default)], (list) => (0, take_1.default)(list, index + 1)).concat(accumulator), []);
return products

@@ -73,3 +79,3 @@ .concat(slices)

})
.map((references) => [join_1.default(references, REFERENCE_DELIMITER), name])
.map((references) => [(0, join_1.default)(references, REFERENCE_DELIMITER), name])
.concat([[name]])

@@ -81,13 +87,14 @@ .map((paths) => {

};
exports.findPartial = findPartial;
handlebars_1.default.registerHelper('import', (options) => {
const settings = options.data.root.settings;
const partialPaths = exports.findPartial(options.hash.partial, settings.context, {
const partialPaths = (0, exports.findPartial)(options.hash.partial, settings.context, {
baseDirectory: path_1.default.join(settings.directory, options.hash.combination),
structure: map_1.default(split_1.default(options.hash.combination, REFERENCE_DELIMITER), trim_1.default),
structure: (0, map_1.default)((0, split_1.default)(options.hash.combination, REFERENCE_DELIMITER), trim_1.default),
});
for (const partialPath of partialPaths) {
const partialContent = attempt_1.default(fs.readFileSync, partialPath, {
const partialContent = (0, attempt_1.default)(fs.readFileSync, partialPath, {
encoding: 'utf8',
});
if (isError_1.default(partialContent)) {
if ((0, isError_1.default)(partialContent)) {
if (partialContent.code === 'ENOENT') {

@@ -119,4 +126,4 @@ debug(`Ignoring ${partialPath}`);

});
exports.buildTemplate = (template, context, options) => {
const data = merge_1.default({
const buildTemplate = (template, context, options) => {
const data = (0, merge_1.default)({
settings: {

@@ -127,4 +134,5 @@ directory: options.directory,

}, context.toJSON().children);
return utils_1.stripExtraBlankLines(handlebars_1.default.compile(template)(data));
return (0, utils_1.stripExtraBlankLines)(handlebars_1.default.compile(template)(data));
};
exports.buildTemplate = buildTemplate;
//# sourceMappingURL=partials.js.map
import { ContractObject } from './types/types';
export declare const compileContract: (contract: ContractObject, options?: {
blacklist?: Set<string>;
}, root?: ({
type: string;
} & {
[key: string]: any;
}) | undefined, breadcrumb?: string[] | undefined) => ContractObject;
}, root?: ContractObject, breadcrumb?: string[]) => ContractObject;

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

const mapValues_1 = __importDefault(require("lodash/mapValues"));
const deepMapValues = (object, callback, breadcrumb = []) => !isPlainObject_1.default(object)
const deepMapValues = (object, callback, breadcrumb = []) => !(0, isPlainObject_1.default)(object)
? callback(object, breadcrumb)
: mapValues_1.default(object, (value, key) => {
const absoluteKey = concat_1.default(breadcrumb, [key]);
return isPlainObject_1.default(value)
: (0, mapValues_1.default)(object, (value, key) => {
const absoluteKey = (0, concat_1.default)(breadcrumb, [key]);
return (0, isPlainObject_1.default)(value)
? deepMapValues(value, callback, absoluteKey)

@@ -24,4 +24,4 @@ : callback(value, absoluteKey);

const TEMPLATE_REGEXP = /\{\{(.+?)\}\}/g;
exports.compileContract = (contract, options = {}, root, breadcrumb) => deepMapValues(contract, (value, key) => {
if (isString_1.default(value)) {
const compileContract = (contract, options = {}, root, breadcrumb) => deepMapValues(contract, (value, key) => {
if ((0, isString_1.default)(value)) {
if (options.blacklist) {

@@ -37,9 +37,10 @@ for (const path of options.blacklist) {

};
return value.replace(TEMPLATE_REGEXP, (interpolation, path) => get_1.default(data, path) || interpolation);
return value.replace(TEMPLATE_REGEXP, (interpolation, path) => (0, get_1.default)(data, path) || interpolation);
}
if (isArray_1.default(value)) {
return map_1.default(value, (object, index) => exports.compileContract(object, options, contract, concat_1.default(key, [index.toString()])));
if ((0, isArray_1.default)(value)) {
return (0, map_1.default)(value, (object, index) => (0, exports.compileContract)(object, options, contract, (0, concat_1.default)(key, [index.toString()])));
}
return value;
}, breadcrumb);
exports.compileContract = compileContract;
//# sourceMappingURL=template.js.map
import { components } from './cuetypes';
export declare type ContractObject = components['schemas']['Contract'];
export declare type BlueprintObject = components['schemas']['Blueprint'];
export declare type BlueprintLayout = components['schemas']['BlueprintLayout'];
export type ContractObject = components['schemas']['Contract'];
export type BlueprintObject = components['schemas']['Blueprint'];
export type BlueprintLayout = components['schemas']['BlueprintLayout'];
export declare const CONTEXT = "meta.context";

@@ -6,0 +6,0 @@ export declare const UNIVERSE = "meta.universe";

@@ -5,3 +5,5 @@ export declare const areSetsDisjoint: <T>(set1: Set<T>, set2: Set<T>) => boolean;

export declare const setMap: <T, V>(set1: Set<T>, iteratee: (arg0: T) => V) => V[];
export declare const cartesianProductWith: <T, V>(sets: T[][], iteratee: (arg0: V, arg1: T) => V | undefined, init: V[]) => V[];
export declare function flatten<T>(iterable: Iterable<T | T[]>): IterableIterator<T>;
export declare function filter<T>(iterable: Iterable<T>, predicate: (t: T) => boolean): IterableIterator<T>;
export declare function cartesianProductWith<T, V>(sets: T[][], iteratee: (arg0: V, arg1: T) => V | undefined, init: V[]): IterableIterator<V>;
export declare const stripExtraBlankLines: (text: string) => string;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.stripExtraBlankLines = exports.cartesianProductWith = exports.setMap = exports.setFirst = exports.setUnion = exports.areSetsDisjoint = void 0;
const flatMap_1 = __importDefault(require("lodash/flatMap"));
exports.stripExtraBlankLines = exports.cartesianProductWith = exports.filter = exports.flatten = exports.setMap = exports.setFirst = exports.setUnion = exports.areSetsDisjoint = void 0;
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
const reduce_1 = __importDefault(require("lodash/reduce"));
const trim_1 = __importDefault(require("lodash/trim"));
exports.areSetsDisjoint = (set1, set2) => {
const areSetsDisjoint = (set1, set2) => {
for (const element of set1) {

@@ -20,3 +18,4 @@ if (set2.has(element)) {

};
exports.setUnion = (set1, set2) => {
exports.areSetsDisjoint = areSetsDisjoint;
const setUnion = (set1, set2) => {
const union = new Set(set1);

@@ -28,4 +27,6 @@ for (const element of set2) {

};
exports.setFirst = (set1) => set1.values().next().value;
exports.setMap = (set1, iteratee) => {
exports.setUnion = setUnion;
const setFirst = (set1) => set1.values().next().value;
exports.setFirst = setFirst;
const setMap = (set1, iteratee) => {
const result = [];

@@ -37,15 +38,52 @@ for (const element of set1) {

};
exports.cartesianProductWith = (sets, iteratee, init) => {
const product = reduce_1.default(sets, (accumulator, set1) => set1.length === 0
? accumulator
: flatMap_1.default(accumulator, (array) => reduce_1.default(set1, (combinations, element) => {
const combination = iteratee(array, element);
if (combination) {
combinations.push(combination);
}
return combinations;
}, [])), init);
return product.length === 0 || isEmpty_1.default(product[0]) ? [] : product;
};
exports.stripExtraBlankLines = (text) => trim_1.default(text.replace(/(\r?\n){3,}/g, '\n\n'));
exports.setMap = setMap;
function* flatten(iterable) {
for (const it of iterable) {
if (!Array.isArray(it)) {
yield it;
continue;
}
for (const item of it) {
yield item;
}
}
}
exports.flatten = flatten;
function* filter(iterable, predicate) {
for (const it of iterable) {
if (predicate(it)) {
yield it;
}
}
}
exports.filter = filter;
function* nextCartesianProduct(sets, iteratee, combination, setRow, setCol) {
if (setRow >= sets.length) {
if (!(0, isEmpty_1.default)(combination)) {
yield combination;
}
return;
}
const set = sets[setRow];
if (set.length === 0) {
yield* nextCartesianProduct(sets, iteratee, combination, setRow + 1, 0);
return;
}
const value = set[setCol];
const newCombination = iteratee(combination, value);
if (newCombination) {
yield* nextCartesianProduct(sets, iteratee, newCombination, setRow + 1, 0);
}
if (setCol + 1 < set.length) {
yield* nextCartesianProduct(sets, iteratee, combination, setRow, setCol + 1);
}
}
function* cartesianProductWith(sets, iteratee, init) {
for (const combination of init) {
yield* nextCartesianProduct(sets, iteratee, combination, 0, 0);
}
}
exports.cartesianProductWith = cartesianProductWith;
const stripExtraBlankLines = (text) => (0, trim_1.default)(text.replace(/(\r?\n){3,}/g, '\n\n'));
exports.stripExtraBlankLines = stripExtraBlankLines;
//# sourceMappingURL=utils.js.map

@@ -14,9 +14,10 @@ "use strict";

const VARIANTS_PROPERTY = 'variants';
exports.build = (contract) => {
const build = (contract) => {
const variants = contract[VARIANTS_PROPERTY] || [];
const base = omit_1.default(contract, [VARIANTS_PROPERTY]);
const base = (0, omit_1.default)(contract, [VARIANTS_PROPERTY]);
return variants.length === 0
? [base]
: reduce_1.default(variants, (accumulator, variation) => concat_1.default(accumulator, map_1.default(exports.build(variation), (template) => mergeWith_1.default({}, base, template, (object, source) => isArray_1.default(object) ? concat_1.default(object, source) : undefined))), []);
: (0, reduce_1.default)(variants, (accumulator, variation) => (0, concat_1.default)(accumulator, (0, map_1.default)((0, exports.build)(variation), (template) => (0, mergeWith_1.default)({}, base, template, (object, source) => (0, isArray_1.default)(object) ? (0, concat_1.default)(object, source) : undefined))), []);
};
exports.build = build;
//# sourceMappingURL=variants.js.map
{
"name": "@balena/contrato",
"version": "0.7.2",
"version": "0.8.0-build-blueprint-reproduce-iterable-fae0a843ad7b6ea45feaef2365b88a20617e26fe-1",
"description": "The official contract implementation",

@@ -65,8 +65,8 @@ "homepage": "https://github.com/product-os/contrato",

"ts-node": "^8.10.1",
"typedoc": "^0.20.36",
"typescript": "^3.9.3"
"typedoc": "^0.23.28",
"typescript": "^4.9.5"
},
"versionist": {
"publishedAt": "2023-03-30T21:35:53.529Z"
"publishedAt": "2023-03-30T22:45:50.447Z"
}
}

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

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