New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@balena/contrato

Package Overview
Dependencies
Maintainers
0
Versions
150
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.11.0 to 0.12.0-build-cleanup-interfaces-239c9a30cbea0ac679897976413ea4829cd5def6-1

build/types.d.ts

9

build/blueprint.d.ts
import Contract from './contract';
import type { BlueprintLayout } from './types/types';
import type { BlueprintLayout } from './types';
export default class Blueprint extends Contract {
constructor(layout: BlueprintLayout, skeleton?: any);
sequence(contract: Contract, options?: {
allowRequirements: boolean;
}): Contract[];
reproduce(contract: Contract, asIterable?: false): Contract[];
reproduce(contract: Contract, asIterable: true): IterableIterator<Contract>;
reproduce(contract: Contract, asIterable?: boolean): IterableIterator<Contract> | Contract[];
reproduce(contract: Contract): IterableIterator<Contract>;
}

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

Object.defineProperty(exports, "__esModule", { value: true });
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");
const contract_1 = __importDefault(require("./contract"));
const cardinality_1 = require("./cardinality");
const types_1 = require("./types/types");
const types_1 = require("./types");
const utils_1 = require("./utils");

@@ -56,5 +46,3 @@ class Blueprint extends contract_1.default {

}
sequence(contract, options = {
allowRequirements: true,
}) {
reproduce(contract) {
const layout = this.metadata.layout;

@@ -64,149 +52,2 @@ const combinations = (0, reduce_1.default)(layout.finite.selectors, (accumulator, value) => {

(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);
});
internalAccumulator = internalAccumulator.concat([combi]);
});
return internalAccumulator;
}, []);
(0, forEach_1.default)(combinations, (dimension) => {
dimension.sort((left, right) => {
return (0, semver_1.compare)(left[0].raw.version, right[0].raw.version);
});
});
const currentPointer = new Array(combinations.length);
(0, fill_1.default)(currentPointer, 0);
const bestPointer = new Array(combinations.length);
for (let idx = 0; idx < combinations.length; idx++) {
bestPointer[idx] = combinations[idx].length - 1;
}
const buildContextFromPointer = (pointer) => {
const context = new contract_1.default(this.raw.skeleton, {
hash: false,
});
const combination = [];
for (let idx = 0; idx < combinations.length; idx++) {
combination.push(combinations[idx][pointer[idx]]);
}
context.addChildren((0, flatten_1.default)(combination), {
rehash: true,
});
const references = context.getChildrenCrossReferencedContracts({
from: contract,
types: layout.infinite.types,
});
const contracts = references.length === 0
? contract.getChildren({
types: layout.infinite.types,
})
: references;
context.addChildren(contracts, {
rehash: false,
});
for (const reference of contracts) {
if (!context.satisfiesChildContract(reference, {
types: layout.types,
})) {
context.removeChild(reference, {
rehash: false,
});
}
}
context.interpolate();
const requirements = context.getAllNotSatisfiedChildRequirements();
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) {
return null;
}
context.raw.requires = newRequirements;
context.interpolate();
}
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;
context.interpolate();
}
return context;
};
const checkSolutions = (pointer) => {
const context = buildContextFromPointer(pointer);
return !context
? false
: context.areChildrenSatisfied({
types: layout.types,
});
};
const checked = [];
const pointerValue = (pointer) => (0, reduce_1.default)(pointer, (sum, value) => sum + value, 0);
let currentBestPointer = new Array(combinations.length);
(0, fill_1.default)(currentBestPointer, 0);
const currentBestPointerValue = pointerValue(currentBestPointer);
let currentBestPath = [];
const isValidPointer = (pointer) => {
if ((0, includes_1.default)(checked, pointer)) {
return false;
}
for (let idx = 0; idx < combinations.length; idx++) {
if (pointer[idx] > bestPointer[idx]) {
return false;
}
}
if (!checkSolutions(pointer)) {
return false;
}
return true;
};
const search = (combos, pointer, path) => {
checked.push(pointer);
for (let idx = 0; idx < combos.length; idx++) {
const possiblePointer = (0, clone_1.default)(pointer);
possiblePointer[idx] += 1;
if (isValidPointer(possiblePointer)) {
const currentPath = (0, clone_1.default)(path);
currentPath.push(possiblePointer);
if ((0, isEqual_1.default)(possiblePointer, bestPointer)) {
currentBestPath = currentPath;
return true;
}
const solutionValue = pointerValue(possiblePointer);
if (solutionValue > currentBestPointerValue) {
currentBestPointer = possiblePointer;
currentBestPath = currentPath;
}
if (search(combos, possiblePointer, currentPath)) {
return true;
}
return false;
}
}
return false;
};
if (isValidPointer(currentPointer)) {
currentBestPointer = currentPointer;
currentBestPath = [currentPointer];
search(combinations, currentPointer, [currentPointer]);
}
return (0, reduce_1.default)(currentBestPath, (seq, pointer) => {
const context = buildContextFromPointer(pointer);
if (context) {
if (!context.areChildrenSatisfied({
types: layout.infinite.types,
})) {
return seq;
}
context.interpolate();
seq.push(context);
}
return seq;
}, []);
}
reproduce(contract, asIterable = false) {
if (!asIterable) {
return [...this.reproduce(contract, true)];
}
const layout = this.metadata.layout;
const combinations = (0, reduce_1.default)(layout.finite.selectors, (accumulator, value) => {
let internalAccumulator = accumulator;
(0, forEach_1.default)(value, (option) => {
internalAccumulator = internalAccumulator.concat([

@@ -213,0 +54,0 @@ contract.getChildrenCombinations(option),

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

import type { ContractObject } from './types/types';
import type { ContractObject } from './types';
export default class Contract {

@@ -3,0 +3,0 @@ metadata: any;

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

const hash_1 = require("./hash");
const types_1 = require("./types/types");
const types_1 = require("./types");
const template_1 = require("./template");

@@ -385,3 +385,3 @@ const variants_1 = require("./variants");

return (0, flatMap_1.default)(rang, (tcardinality) => {
return (0, js_combinatorics_1.bigCombination)(contracts, tcardinality).toArray();
return new js_combinatorics_1.Combination(contracts, tcardinality).toArray();
});

@@ -388,0 +388,0 @@ }

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

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

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

import { buildTemplate } from './partials';
import { parse as parseCardinality } from './cardinality';
export { BlueprintLayout, ContractObject, BlueprintObject, Contract, Blueprint, Universe, buildTemplate, parseCardinality, };
export declare function query(universe: Contract, layout: BlueprintLayout, skeleton: object, asIterable: true): IterableIterator<Contract>;
export declare function query(universe: Contract, layout: BlueprintLayout, skeleton: object, asIterable?: false): Contract[];
export declare const sequence: (universe: Contract, layout: BlueprintLayout, skeleton: object) => Contract[];
export { BlueprintLayout, ContractObject, BlueprintObject, Contract, Blueprint, Universe, buildTemplate, };
export declare function query(universe: Contract, layout: BlueprintLayout, skeleton: object): IterableIterator<Contract>;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.sequence = exports.parseCardinality = exports.buildTemplate = exports.Universe = exports.Blueprint = exports.Contract = void 0;
exports.buildTemplate = exports.Universe = exports.Blueprint = exports.Contract = void 0;
exports.query = query;

@@ -17,9 +17,5 @@ const contract_1 = __importDefault(require("./contract"));

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

@@ -10,3 +10,3 @@ import type Contract from './contract';

resetType(type: string): void;
merge(cache: MatcherCache): MatcherCache;
merge(cache: MatcherCache): this;
}
import Contract from './contract';
import type { ContractObject } from './types/types';
import type { ContractObject } from './types';
export declare const findPartial: (name: string, context: Contract, options: {

@@ -4,0 +4,0 @@ baseDirectory: string;

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

import type { ContractObject } from './types/types';
import type { ContractObject } from './types';
export declare const compileContract: (contract: ContractObject, options?: {

@@ -3,0 +3,0 @@ blacklist?: Set<string>;

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

const contract_1 = __importDefault(require("./contract"));
const types_1 = require("./types/types");
const types_1 = require("./types");
async function findFiles(dir, filter = () => true) {

@@ -13,0 +13,0 @@ const allFiles = await fs_1.promises.readdir(dir, { recursive: true });

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

import type { ContractObject } from './types/types';
import type { ContractObject } from './types';
export declare const build: (contract: ContractObject) => ContractObject[];
{
"name": "@balena/contrato",
"version": "0.11.0",
"version": "0.12.0-build-cleanup-interfaces-239c9a30cbea0ac679897976413ea4829cd5def6-1",
"description": "The official contract implementation",

@@ -26,7 +26,6 @@ "homepage": "https://github.com/product-os/contrato",

"clean": "rimraf build",
"build": "npm run clean && npm run buildtypes && tsc",
"buildtypes": "ts-node --transpile-only ./scripts/build-types.ts && balena-lint --typescript --fix lib/types",
"build": "npm run clean && tsc",
"doc": "typedoc --options ./typedoc.json",
"lint": "balena-lint -t tsconfig.dev.json --typescript lib tests scripts",
"lint-fix": "balena-lint -t tsconfig.dev.json --typescript --fix lib tests scripts",
"lint": "balena-lint -t tsconfig.dev.json --typescript lib tests",
"lint-fix": "balena-lint -t tsconfig.dev.json --typescript --fix lib tests",
"test:node": "mocha -r ts-node/register/transpile-only --reporter spec \"tests/**/*.spec.ts\"",

@@ -42,16 +41,15 @@ "test": "npm run build && npm run lint && npm run test:node",

"handlebars": "^4.7.8",
"js-combinatorics": "^0.5.5",
"js-combinatorics": "^2.1.2",
"json-schema": "^0.4.0",
"lodash": "^4.17.19",
"object-hash": "^1.3.1",
"object-hash": "^3.0.0",
"p-map": "^7.0.3",
"promised-handlebars": "^2.0.1",
"semver": "^5.7.1"
"semver": "^7.6.3"
},
"devDependencies": {
"@balena/lint": "^8.2.8",
"@balena/lint": "^9.1.3",
"@types/chai": "^4.2.11",
"@types/chai-as-promised": "^7.1.2",
"@types/debug": "^4.1.5",
"@types/js-combinatorics": "^0.5.32",
"@types/json-schema": "^7.0.15",

@@ -65,7 +63,5 @@ "@types/lodash": "^4.14.168",

"chai-as-promised": "^7.1.1",
"cuelang-js": "^1.1.1",
"husky": "^4.2.5",
"lint-staged": "^10.1.7",
"mocha": "^10.4.0",
"openapi-typescript": "^3.2.4",
"rimraf": "^3.0.2",

@@ -81,4 +77,4 @@ "ts-node": "^8.10.1",

"versionist": {
"publishedAt": "2025-01-10T16:21:07.516Z"
"publishedAt": "2025-01-10T20:44:56.632Z"
}
}

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

Contrato
========
# Contrato
> The official contracts implementation
[![Documentation](https://github.com/product-os/contrato/actions/workflows/docs.yml/badge.svg)](https://product-os.github.io/contrato/modules/contrato.html)
[![Documentation](https://github.com/product-os/contrato/actions/workflows/docs.yml/badge.svg)](https://balena-io.github.io/contrato/modules/contrato.html)
Tests
-----
## Tests

@@ -17,7 +15,6 @@ Run the `test` npm script:

Contribute
----------
## Contribute
- Issue Tracker: [github.com/product-os/contrato/issues](https://github.com/product-os/contrato/issues)
- Source Code: [github.com/product-os/contrato](https://github.com/product-os/contrato)
- Issue Tracker: [github.com/product-os/contrato/issues](https://github.com/balena-io/contrato/issues)
- Source Code: [github.com/product-os/contrato](https://github.com/balena-io/contrato)

@@ -31,11 +28,9 @@ Before submitting a PR, please make sure that you include tests, and that the

Support
-------
## Support
If you're having any problem, please [raise an
issue](https://github.com/product-os/contrato/issues/new) on GitHub.
issue](https://github.com/balena-io/contrato/issues/new) on GitHub.
License
-------
## License
The project is licensed under the Apache 2.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

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