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
100
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.0-codewithcheese-convert-to-ts-ed39cc6815c1e2b5d64c15f3ee2a3cc81adf272e to 0.7.0-codewithcheese-convert-to-ts-f218725e356f694b4fed3e3b92205eafdcd78302

4

build/blueprint.d.ts
import Contract from './contract';
import { BlueprintType } from './types/types';
import { BlueprintObject } from './types/types';
export default class Blueprint extends Contract {
constructor(layout: BlueprintType, skeleton?: any);
constructor(layout: BlueprintObject, skeleton?: any);
sequence(contract: Contract, options?: {

@@ -6,0 +6,0 @@ allowRequirements: boolean;

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

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -6,3 +6,14 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const clone_1 = __importDefault(require("lodash/clone"));
const concat_1 = __importDefault(require("lodash/concat"));
const fill_1 = __importDefault(require("lodash/fill"));
const filter_1 = __importDefault(require("lodash/filter"));
const flatMap_1 = __importDefault(require("lodash/flatMap"));
const flatten_1 = __importDefault(require("lodash/flatten"));
const forEach_1 = __importDefault(require("lodash/forEach"));
const includes_1 = __importDefault(require("lodash/includes"));
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
const isEqual_1 = __importDefault(require("lodash/isEqual"));
const reduce_1 = __importDefault(require("lodash/reduce"));
const uniqWith_1 = __importDefault(require("lodash/uniqWith"));
const semver_1 = require("semver");

@@ -20,3 +31,3 @@ const contract_1 = __importDefault(require("./contract"));

});
this.metadata.layout = lodash_1.reduce(this.raw.layout, (accumulator, value, type) => {
this.metadata.layout = reduce_1.default(this.raw.layout, (accumulator, value, type) => {
const selector = {

@@ -30,3 +41,3 @@ cardinality: cardinality_1.parse(value.cardinality || value),

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

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

const layout = this.metadata.layout;
const combinations = lodash_1.reduce(layout.finite.selectors, (accumulator, value) => {
const combinations = reduce_1.default(layout.finite.selectors, (accumulator, value) => {
let internalAccumulator = accumulator;
lodash_1.forEach(value, (option) => {
const combi = lodash_1.uniqWith(contract.getChildrenCombinations(option), (left, right) => {
return lodash_1.isEqual(left[0].raw, right[0].raw);
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);
});

@@ -62,3 +73,3 @@ internalAccumulator = internalAccumulator.concat([combi]);

}, []);
lodash_1.forEach(combinations, (dimension) => {
forEach_1.default(combinations, (dimension) => {
dimension.sort((left, right) => {

@@ -69,3 +80,3 @@ return semver_1.compare(left[0].raw.version, right[0].raw.version);

const currentPointer = new Array(combinations.length);
lodash_1.fill(currentPointer, 0);
fill_1.default(currentPointer, 0);
const bestPointer = new Array(combinations.length);

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

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

@@ -110,4 +121,4 @@ });

const requirements = context.getAllNotSatisfiedChildRequirements();
const newRequirements = lodash_1.uniqWith(lodash_1.filter(lodash_1.concat(context.raw.requires, requirements)), lodash_1.isEqual);
if (newRequirements && !lodash_1.isEmpty(newRequirements)) {
const newRequirements = uniqWith_1.default(filter_1.default(concat_1.default(context.raw.requires, requirements)), isEqual_1.default);
if (newRequirements && !isEmpty_1.default(newRequirements)) {
if (!options.allowRequirements) {

@@ -119,4 +130,4 @@ return null;

}
const childCapabilities = lodash_1.filter(lodash_1.uniqWith(lodash_1.flatMap(context.getChildren(), (v) => v.raw.capabilities), lodash_1.isEqual));
if (childCapabilities && !lodash_1.isEmpty(childCapabilities)) {
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)) {
context.raw.capabilities = childCapabilities;

@@ -136,9 +147,9 @@ context.interpolate();

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

@@ -159,8 +170,8 @@ }

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

@@ -187,3 +198,3 @@ return true;

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

@@ -204,5 +215,5 @@ if (context) {

const layout = this.metadata.layout;
const combinations = lodash_1.reduce(layout.finite.selectors, (accumulator, value) => {
const combinations = reduce_1.default(layout.finite.selectors, (accumulator, value) => {
let internalAccumulator = accumulator;
lodash_1.forEach(value, (option) => {
forEach_1.default(value, (option) => {
internalAccumulator = internalAccumulator.concat([

@@ -236,3 +247,3 @@ contract.getChildrenCombinations(option),

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

@@ -239,0 +250,0 @@ from: contract,

@@ -1,12 +0,23 @@

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = void 0;
const lodash_1 = require("lodash");
const initial_1 = __importDefault(require("lodash/initial"));
const isEqual_1 = __importDefault(require("lodash/isEqual"));
const isInteger_1 = __importDefault(require("lodash/isInteger"));
const isNumber_1 = __importDefault(require("lodash/isNumber"));
const isString_1 = __importDefault(require("lodash/isString"));
const join_1 = __importDefault(require("lodash/join"));
const size_1 = __importDefault(require("lodash/size"));
const some_1 = __importDefault(require("lodash/some"));
const trim_1 = __importDefault(require("lodash/trim"));
const ORDERED_LIST_LENGTH = 2;
exports.parse = (input) => {
if (lodash_1.isNumber(input)) {
if (isNumber_1.default(input)) {
return exports.parse([input, input]);
}
if (lodash_1.isString(input)) {
const normalizedInput = lodash_1.trim(input);
if (isString_1.default(input)) {
const normalizedInput = trim_1.default(input);
if (normalizedInput === '*') {

@@ -22,6 +33,6 @@ return exports.parse([0, Infinity]);

}
return exports.parse([parseInt(lodash_1.join(lodash_1.initial(normalizedInput), ''), 10), Infinity]);
return exports.parse([parseInt(join_1.default(initial_1.default(normalizedInput), ''), 10), Infinity]);
}
const [from, to] = input;
if (typeof to === 'string' && lodash_1.trim(to) === '*') {
if (typeof to === 'string' && trim_1.default(to) === '*') {
return exports.parse([from, Infinity]);

@@ -31,10 +42,10 @@ }

typeof to === 'string' ||
lodash_1.some([
lodash_1.isEqual(input, [0, 0]),
some_1.default([
isEqual_1.default(input, [0, 0]),
from < 0,
to < 0,
lodash_1.size(input) !== ORDERED_LIST_LENGTH,
size_1.default(input) !== ORDERED_LIST_LENGTH,
from > to,
!lodash_1.isInteger(from),
!lodash_1.isInteger(to) && to !== Infinity,
!isInteger_1.default(from),
!isInteger_1.default(to) && to !== Infinity,
])) {

@@ -41,0 +52,0 @@ throw new Error(`Invalid cardinality: ${input}`);

@@ -1,4 +0,4 @@

import { ContractType } from '.';
import { ContractObject } from '.';
import Contract from './contract';
export declare const build: (contract: Contract) => object;
export declare const getAll: (tree: any) => ContractType[];
export declare const getAll: (tree: any) => ContractObject[];

@@ -1,5 +0,9 @@

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAll = exports.build = void 0;
const lodash_1 = require("lodash");
const reduce_1 = __importDefault(require("lodash/reduce"));
const set_1 = __importDefault(require("lodash/set"));
const utils_1 = require("./utils");

@@ -15,3 +19,3 @@ exports.build = (contract) => {

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

@@ -31,3 +35,3 @@ }

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

@@ -37,3 +41,3 @@ }

};
exports.getAll = (tree) => lodash_1.reduce(tree, (accumulator, value, _) => {
exports.getAll = (tree) => reduce_1.default(tree, (accumulator, value, _) => {
if (!value.slug) {

@@ -40,0 +44,0 @@ const out = accumulator.concat(exports.getAll(value));

@@ -1,6 +0,6 @@

import { ContractType } from './types/types';
import { ContractObject } from './types/types';
export default class Contract {
metadata: any;
raw: ContractType;
constructor(object: ContractType, options?: object);
raw: ContractObject;
constructor(object: ContractObject, options?: object);
hash(): void;

@@ -56,3 +56,3 @@ rebuild(): void;

static isEqual(contract1: Contract, contract2: Contract): boolean;
static build(source: ContractType): Contract[];
static build(source: ContractObject): Contract[];
}

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

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -6,3 +6,18 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const concat_1 = __importDefault(require("lodash/concat"));
const defaults_1 = __importDefault(require("lodash/defaults"));
const filter_1 = __importDefault(require("lodash/filter"));
const first_1 = __importDefault(require("lodash/first"));
const flatMap_1 = __importDefault(require("lodash/flatMap"));
const intersectionWith_1 = __importDefault(require("lodash/intersectionWith"));
const isEqual_1 = __importDefault(require("lodash/isEqual"));
const keys_1 = __importDefault(require("lodash/keys"));
const map_1 = __importDefault(require("lodash/map"));
const matches_1 = __importDefault(require("lodash/matches"));
const omit_1 = __importDefault(require("lodash/omit"));
const partial_1 = __importDefault(require("lodash/partial"));
const range_1 = __importDefault(require("lodash/range"));
const reduce_1 = __importDefault(require("lodash/reduce"));
const some_1 = __importDefault(require("lodash/some"));
const uniqWith_1 = __importDefault(require("lodash/uniqWith"));
const skhema_1 = require("skhema");

@@ -18,4 +33,4 @@ const js_combinatorics_1 = require("js-combinatorics");

const children_tree_1 = require("./children-tree");
const children_tree_2 = require("./children-tree");
const utils_1 = require("./utils");
const children_tree_2 = require("./children-tree");
class Contract {

@@ -40,3 +55,3 @@ constructor(object, options = {}) {

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

@@ -80,3 +95,3 @@ });

}
const operand = lodash_1.first(lodash_1.keys(conjunct));
const operand = first_1.default(keys_1.default(conjunct));
if (operand) {

@@ -103,3 +118,3 @@ const matchers = new object_set_1.default();

});
lodash_1.defaults(options, {
defaults_1.default(options, {
rehash: true,

@@ -160,3 +175,3 @@ });

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

@@ -174,3 +189,3 @@ rebuild: true,

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

@@ -209,3 +224,3 @@ });

}
lodash_1.defaults(options, {
defaults_1.default(options, {
rehash: true,

@@ -238,3 +253,3 @@ });

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

@@ -261,3 +276,3 @@ options.types.has(contract.raw.type)) {

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

@@ -273,3 +288,3 @@ if (contract.raw.capabilities) {

}
else if (lodash_1.isEqual(capability.version, versionMatch)) {
else if (isEqual_1.default(capability.version, versionMatch)) {
results.push(contract);

@@ -284,3 +299,3 @@ }

}
return lodash_1.uniqWith(results, lodash_1.isEqual);
return uniqWith_1.default(results, isEqual_1.default);
}

@@ -304,3 +319,3 @@ findChildren(matcher) {

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

@@ -329,3 +344,3 @@ const hashes = slug

}
else if (lodash_1.isEqual(child.raw.version, versionMatch)) {
else if (isEqual_1.default(child.raw.version, versionMatch)) {
results.push(child);

@@ -347,4 +362,4 @@ }

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

@@ -355,3 +370,3 @@ });

if (options['version']) {
if (lodash_1.isEqual(options['version'], 'latest')) {
if (isEqual_1.default(options['version'], 'latest')) {
contracts.sort((left, right) => {

@@ -363,3 +378,3 @@ return semver_1.compare(right.raw.version, left.raw.version);

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

@@ -379,4 +394,4 @@ });

}
const rang = lodash_1.range(cardinality.from, Math.min(cardinality.to, contracts.length) + 1);
return lodash_1.flatMap(rang, (tcardinality) => {
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();

@@ -418,8 +433,8 @@ });

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

@@ -438,6 +453,6 @@ }, contract.metadata.requirements.compiled.getAll());

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

@@ -457,3 +472,3 @@ }

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

@@ -468,6 +483,6 @@ }, contract.metadata.requirements.compiled.getAll());

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

@@ -478,6 +493,6 @@ }

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

@@ -512,3 +527,3 @@ }

utils_1.areSetsDisjoint(options.types, contract.metadata.requirements.types)) {
requirements = lodash_1.concat(requirements, lodash_1.map(contract.metadata.requirements.compiled.getAll(), 'data'));
requirements = concat_1.default(requirements, map_1.default(contract.metadata.requirements.compiled.getAll(), 'data'));
continue;

@@ -519,3 +534,3 @@ }

});
requirements = lodash_1.concat(requirements, contractRequirements);
requirements = concat_1.default(requirements, contractRequirements);
}

@@ -535,11 +550,10 @@ return requirements;

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

@@ -552,4 +566,3 @@ canonicalSlug: obj['slug'],

return accumulator.concat(contracts);
}, [])
.value();
}, []);
}

@@ -556,0 +569,0 @@ }

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

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -3,0 +3,0 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

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

import { BlueprintType, ContractType } from './types/types';
import { BlueprintObject, ContractObject } from './types/types';
import Contract from './contract';

@@ -6,4 +6,4 @@ import Blueprint from './blueprint';

import { parse as parseCardinality } from './cardinality';
export { ContractType, BlueprintType, Contract, Blueprint, buildTemplate, parseCardinality, };
export { ContractObject, BlueprintObject, Contract, Blueprint, buildTemplate, parseCardinality, };
export declare const query: (universe: Contract, layout: object, skeleton: object) => Contract[];
export declare const sequence: (universe: Contract, layout: object, skeleton: object) => Contract[];

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

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -3,0 +3,0 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

@@ -1,4 +0,9 @@

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const concat_1 = __importDefault(require("lodash/concat"));
const get_1 = __importDefault(require("lodash/get"));
const set_1 = __importDefault(require("lodash/set"));
const getMatcherCachePath = (matcher) => [

@@ -14,3 +19,3 @@ matcher.raw.data.type,

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

@@ -23,3 +28,3 @@ matcher,

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

@@ -26,0 +31,0 @@ getTypes() {

@@ -1,4 +0,10 @@

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const first_1 = __importDefault(require("lodash/first"));
const isArray_1 = __importDefault(require("lodash/isArray"));
const last_1 = __importDefault(require("lodash/last"));
const values_1 = __importDefault(require("lodash/values"));
const hash_1 = require("./hash");

@@ -12,5 +18,5 @@ class ObjectSet {

for (const object of objects) {
if (lodash_1.isArray(object)) {
const firstObj = lodash_1.first(object);
const lastObj = lodash_1.last(object);
if (isArray_1.default(object)) {
const firstObj = first_1.default(object);
const lastObj = last_1.default(object);
if (firstObj && lastObj) {

@@ -43,3 +49,3 @@ this.add(firstObj, lastObj);

getAll() {
return lodash_1.values(this.data);
return values_1.default(this.data);
}

@@ -46,0 +52,0 @@ intersection(set) {

@@ -1,8 +0,8 @@

import { ContractType } from './types/types';
export declare const findPartial: (name: string, context: ContractType, options: {
import { ContractObject } from './types/types';
export declare const findPartial: (name: string, context: ContractObject, options: {
baseDirectory: string;
structure: string[];
}) => string[];
export declare const buildTemplate: (template: string, context: ContractType, options: {
export declare const buildTemplate: (template: string, context: ContractObject, options: {
directory: string;
}) => string;

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

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -8,44 +8,53 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const debug_1 = __importDefault(require("debug"));
const fs_1 = __importDefault(require("fs"));
const memfs_1 = require("memfs");
const path_1 = __importDefault(require("path"));
const handlebars_1 = __importDefault(require("handlebars"));
const lodash_1 = require("lodash");
const attempt_1 = __importDefault(require("lodash/attempt"));
const first_1 = __importDefault(require("lodash/first"));
const invokeMap_1 = __importDefault(require("lodash/invokeMap"));
const isError_1 = __importDefault(require("lodash/isError"));
const join_1 = __importDefault(require("lodash/join"));
const last_1 = __importDefault(require("lodash/last"));
const map_1 = __importDefault(require("lodash/map"));
const merge_1 = __importDefault(require("lodash/merge"));
const range_1 = __importDefault(require("lodash/range"));
const reduce_1 = __importDefault(require("lodash/reduce"));
const sortBy_1 = __importDefault(require("lodash/sortBy"));
const split_1 = __importDefault(require("lodash/split"));
const take_1 = __importDefault(require("lodash/take"));
const thru_1 = __importDefault(require("lodash/thru"));
const trim_1 = __importDefault(require("lodash/trim"));
const uniq_1 = __importDefault(require("lodash/uniq"));
const flow_1 = __importDefault(require("lodash/flow"));
const contract_1 = __importDefault(require("./contract"));
const utils_1 = require("./utils");
const contract_1 = __importDefault(require("./contract"));
const debug = debug_1.default('partials');
const REFERENCE_DELIMITER = '+';
exports.findPartial = (name, context, options) => lodash_1.chain(options.structure)
.map((type) => {
const children = context.getChildrenByType(type);
const contracts = lodash_1.chain(children)
.map((contract) => {
const rawContract = contract.toJSON();
rawContract.slug = contract.getCanonicalSlug();
return new contract_1.default(rawContract);
exports.findPartial = (name, context, options) => {
return flow_1.default((structure) => map_1.default(structure, (type) => {
const children = context.getChildrenByType(type);
const contracts = flow_1.default((childrenRaw) => 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);
return [
join_1.default(invokeMap_1.default(contracts, 'getReferenceString'), REFERENCE_DELIMITER),
join_1.default(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), []);
return products
.concat(slices)
.concat(fallbackPaths);
})
.sortBy((contract) => contract.getSlug())
.value();
return [
lodash_1.join(lodash_1.invokeMap(contracts, 'getReferenceString'), REFERENCE_DELIMITER),
lodash_1.join(lodash_1.invokeMap(contracts, 'getSlug'), REFERENCE_DELIMITER),
];
})
.thru((combinations) => {
const products = utils_1.cartesianProductWith(combinations, (accumulator, element) => accumulator.concat([element]), [[]]);
const slices = lodash_1.reduce(lodash_1.range(options.structure.length, 1, -1), (accumulator, slice) => accumulator.concat(lodash_1.invokeMap(products, 'slice', 0, slice)), []);
const fallbackPaths = lodash_1.chain(combinations)
.reduce((accumulator, _, index, collection) => lodash_1.map([lodash_1.map(collection, lodash_1.first), lodash_1.map(collection, lodash_1.last)], (list) => lodash_1.take(list, index + 1)).concat(accumulator), [])
.value();
return products
.concat(slices)
.concat(fallbackPaths);
})
.map((references) => [lodash_1.join(references, REFERENCE_DELIMITER), name])
.concat([[name]])
.map((paths) => {
const absolutePath = [options.baseDirectory].concat(paths);
return `${path_1.default.join(...absolutePath)}.tpl`;
})
.uniq()
.value();
.map((references) => [join_1.default(references, REFERENCE_DELIMITER), name])
.concat([[name]])
.map((paths) => {
const absolutePath = [options.baseDirectory].concat(paths);
return `${path_1.default.join(...absolutePath)}.tpl`;
}), uniq_1.default)(options.structure);
};
handlebars_1.default.registerHelper('import', (options) => {

@@ -55,9 +64,9 @@ const settings = options.data.root.settings;

baseDirectory: path_1.default.join(settings.directory, options.hash.combination),
structure: lodash_1.map(lodash_1.split(options.hash.combination, REFERENCE_DELIMITER), lodash_1.trim),
structure: map_1.default(split_1.default(options.hash.combination, REFERENCE_DELIMITER), trim_1.default),
});
for (const partialPath of partialPaths) {
const partialContent = lodash_1.attempt(fs_1.default.readFileSync, partialPath, {
const partialContent = attempt_1.default(memfs_1.fs.readFileSync, partialPath, {
encoding: 'utf8',
});
if (lodash_1.isError(partialContent)) {
if (isError_1.default(partialContent)) {
if (partialContent.code === 'ENOENT') {

@@ -90,3 +99,3 @@ debug(`Ignoring ${partialPath}`);

exports.buildTemplate = (template, context, options) => {
const data = lodash_1.merge({
const data = merge_1.default({
settings: {

@@ -93,0 +102,0 @@ directory: options.directory,

@@ -1,4 +0,4 @@

import { ContractType } from './types/types';
export declare const compileContract: (contract: ContractType, options?: {
import { ContractObject } from './types/types';
export declare const compileContract: (contract: ContractObject, options?: {
blacklist?: Set<string>;
}, root?: object | undefined, breadcrumb?: string[] | undefined) => ContractType;
}, root?: object | undefined, breadcrumb?: string[] | undefined) => ContractObject;

@@ -1,10 +0,19 @@

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.compileContract = void 0;
const lodash_1 = require("lodash");
const deepMapValues = (object, callback, breadcrumb = []) => !lodash_1.isPlainObject(object)
const concat_1 = __importDefault(require("lodash/concat"));
const get_1 = __importDefault(require("lodash/get"));
const isArray_1 = __importDefault(require("lodash/isArray"));
const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
const isString_1 = __importDefault(require("lodash/isString"));
const map_1 = __importDefault(require("lodash/map"));
const mapValues_1 = __importDefault(require("lodash/mapValues"));
const deepMapValues = (object, callback, breadcrumb = []) => !isPlainObject_1.default(object)
? callback(object, breadcrumb)
: lodash_1.mapValues(object, (value, key) => {
const absoluteKey = lodash_1.concat(breadcrumb, [key]);
return lodash_1.isPlainObject(value)
: mapValues_1.default(object, (value, key) => {
const absoluteKey = concat_1.default(breadcrumb, [key]);
return isPlainObject_1.default(value)
? deepMapValues(value, callback, absoluteKey)

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

exports.compileContract = (contract, options = {}, root, breadcrumb) => deepMapValues(contract, (value, key) => {
if (lodash_1.isString(value)) {
if (isString_1.default(value)) {
if (options.blacklist) {

@@ -27,6 +36,6 @@ for (const path of options.blacklist) {

};
return value.replace(TEMPLATE_REGEXP, (interpolation, path) => lodash_1.get(data, path) || interpolation);
return value.replace(TEMPLATE_REGEXP, (interpolation, path) => get_1.default(data, path) || interpolation);
}
if (lodash_1.isArray(value)) {
return lodash_1.map(value, (object, index) => exports.compileContract(object, options, contract, lodash_1.concat(key, [index.toString()])));
if (isArray_1.default(value)) {
return map_1.default(value, (object, index) => exports.compileContract(object, options, contract, concat_1.default(key, [index.toString()])));
}

@@ -33,0 +42,0 @@ return value;

import { components } from './cuetypes';
export declare type ContractType = components['schemas']['Contract'];
export declare type BlueprintType = components['schemas']['Blueprint'];
export declare type ContractObject = components['schemas']['Contract'];
export declare type BlueprintObject = components['schemas']['Blueprint'];
export declare const CONTEXT = "meta.context";

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

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

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -3,0 +3,0 @@ exports.BLUEPRINT = exports.MATCHER = exports.UNIVERSE = exports.CONTEXT = void 0;

export declare const areSetsDisjoint: <T>(set1: Set<T>, set2: Set<T>) => boolean;
export declare const setUnion: <T>(set1: Set<T>, set2: Set<T>) => Set<T>;
export declare const setFirst: <T>(set: Set<T>) => T;
export declare const setMap: <T, V>(set: Set<T>, iteratee: (arg0: T) => V) => V[];
export declare const setFirst: <T>(set1: Set<T>) => T;
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 const stripExtraBlankLines: (text: string) => string;

@@ -1,5 +0,11 @@

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stripExtraBlankLines = exports.cartesianProductWith = exports.setMap = exports.setFirst = exports.setUnion = exports.areSetsDisjoint = void 0;
const lodash_1 = require("lodash");
const flatMap_1 = __importDefault(require("lodash/flatMap"));
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) => {

@@ -20,6 +26,6 @@ for (const element of set1) {

};
exports.setFirst = (set) => set.values().next().value;
exports.setMap = (set, iteratee) => {
exports.setFirst = (set1) => set1.values().next().value;
exports.setMap = (set1, iteratee) => {
const result = [];
for (const element of set) {
for (const element of set1) {
result.push(iteratee(element));

@@ -30,5 +36,5 @@ }

exports.cartesianProductWith = (sets, iteratee, init) => {
const product = lodash_1.reduce(sets, (accumulator, set) => set.length === 0
const product = reduce_1.default(sets, (accumulator, set1) => set1.length === 0
? accumulator
: lodash_1.flatMap(accumulator, (array) => lodash_1.reduce(set, (combinations, element) => {
: flatMap_1.default(accumulator, (array) => reduce_1.default(set1, (combinations, element) => {
const combination = iteratee(array, element);

@@ -40,5 +46,5 @@ if (combination) {

}, [])), init);
return product.length === 0 || lodash_1.isEmpty(product[0]) ? [] : product;
return product.length === 0 || isEmpty_1.default(product[0]) ? [] : product;
};
exports.stripExtraBlankLines = (text) => lodash_1.trim(text.replace(/(\r?\n){3,}/g, '\n\n'));
exports.stripExtraBlankLines = (text) => trim_1.default(text.replace(/(\r?\n){3,}/g, '\n\n'));
//# sourceMappingURL=utils.js.map

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

import { ContractType } from './types/types';
export declare const build: (contract: ContractType) => ContractType[];
import { ContractObject } from './types/types';
export declare const build: (contract: ContractObject) => ContractObject[];

@@ -1,13 +0,21 @@

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.build = void 0;
const lodash_1 = require("lodash");
const concat_1 = __importDefault(require("lodash/concat"));
const isArray_1 = __importDefault(require("lodash/isArray"));
const map_1 = __importDefault(require("lodash/map"));
const mergeWith_1 = __importDefault(require("lodash/mergeWith"));
const omit_1 = __importDefault(require("lodash/omit"));
const reduce_1 = __importDefault(require("lodash/reduce"));
const VARIANTS_PROPERTY = 'variants';
exports.build = (contract) => {
const variants = contract[VARIANTS_PROPERTY] || [];
const base = lodash_1.omit(contract, [VARIANTS_PROPERTY]);
const base = omit_1.default(contract, [VARIANTS_PROPERTY]);
return variants.length === 0
? [base]
: lodash_1.reduce(variants, (accumulator, variation) => lodash_1.concat(accumulator, lodash_1.map(exports.build(variation), (template) => lodash_1.mergeWith({}, base, template, (object, source) => lodash_1.isArray(object) ? lodash_1.concat(object, source) : undefined))), []);
: 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))), []);
};
//# sourceMappingURL=variants.js.map

@@ -8,3 +8,3 @@ # Change Log

## 0.7.0 - 2021-04-30
## 0.7.0 - 2021-05-05

@@ -11,0 +11,0 @@ * align repo with official Balena typescript skeleton [Micah Halter]

{
"name": "@balena/contrato",
"version": "0.7.0-codewithcheese-convert-to-ts-ed39cc6815c1e2b5d64c15f3ee2a3cc81adf272e",
"version": "0.7.0-codewithcheese-convert-to-ts-f218725e356f694b4fed3e3b92205eafdcd78302",
"description": "The official contract implementation",

@@ -28,7 +28,7 @@ "homepage": "https://github.com/balena-io/contrato",

"buildtypes": "ts-node ./scripts/build-types.ts && balena-lint --typescript --fix lib/types",
"docs": "typedoc --options ./typedoc.json",
"lint": "balena-lint --typescript lib tests",
"lint-fix": "balena-lint --typescript --fix lib tests",
"test:node": "mocha -r ts-node/register --reporter spec tests/**/*.spec.ts",
"test:browser": "karma start",
"test": "npm run build && npm run lint && npm run test:node && npm run test:browser",
"test": "npm run build && npm run lint && npm run test:node",
"test:fast": "npm run build && npm run test:node",

@@ -48,2 +48,3 @@ "prepack": "npm run build"

"lodash": "^4.17.19",
"memfs": "^3.2.2",
"object-hash": "^1.3.1",

@@ -58,3 +59,2 @@ "semver": "^5.7.1",

"@types/mocha": "^7.0.2",
"balena-config-karma": "^2.3.1",
"chai": "^4.2.0",

@@ -64,3 +64,2 @@ "chai-as-promised": "^7.1.1",

"husky": "^4.2.5",
"karma": "^5.0.9",
"lint-staged": "^10.1.7",

@@ -71,4 +70,5 @@ "mocha": "^7.2.0",

"ts-node": "^8.10.1",
"typedoc": "^0.20.36",
"typescript": "^3.9.3"
}
}
Contrato
========
[![CircleCI](https://circleci.com/gh/resin-io/contrato/tree/master.svg?style=svg)](https://circleci.com/gh/resin-io/contrato/tree/master)
> The official contracts implementation
[**Documentation**](https://balena-io.github.io/contrato/) | [**Code Coverage**](https://balena-io.github.io/contrato/lcov-report/)
[**Documentation**](https://balena-io.github.io/contrato/)

@@ -22,4 +20,4 @@ Tests

- Issue Tracker: [github.com/resin-io/contrato/issues](https://github.com/resin-io/contrato/issues)
- Source Code: [github.com/resin-io/contrato](https://github.com/resin-io/contrato)
- Issue Tracker: [github.com/balena-io/contrato/issues](https://github.com/balena-io/contrato/issues)
- Source Code: [github.com/balena-io/contrato](https://github.com/balena-io/contrato)

@@ -37,3 +35,3 @@ Before submitting a PR, please make sure that you include tests, and that the

If you're having any problem, please [raise an
issue](https://github.com/resin-io/contrato/issues/new) on GitHub.
issue](https://github.com/balena-io/contrato/issues/new) on GitHub.

@@ -40,0 +38,0 @@ License

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

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