@balena/contrato
Advanced tools
Comparing version 0.9.1 to 0.9.2-build-optimizations-59d52335ca8d783cd7f9730df086c4d504b2d2cb-1
@@ -34,2 +34,3 @@ "use strict"; | ||
const utils_1 = require("./utils"); | ||
const lodash_1 = require("lodash"); | ||
class Contract { | ||
@@ -160,2 +161,3 @@ metadata; | ||
if (!this.metadata.children.types.has(type)) { | ||
this.metadata.children.types.add(type); | ||
this.metadata.children.byType[type] = new Set(); | ||
@@ -170,3 +172,2 @@ this.metadata.children.byTypeSlug[type] = {}; | ||
} | ||
this.metadata.children.types.add(type); | ||
this.metadata.children.map[contract.metadata.hash] = contract; | ||
@@ -250,9 +251,11 @@ this.metadata.children.byType[type].add(contract.metadata.hash); | ||
getChildren(options = {}) { | ||
return (0, reduce_1.default)(this.metadata.children.map, (accumulator, contract) => { | ||
const contracts = []; | ||
(0, lodash_1.forEach)(this.metadata.children.map, (contract) => { | ||
if (!options.types || | ||
options.types.has(contract.raw.type)) { | ||
accumulator.push(contract); | ||
contracts.push(contract); | ||
} | ||
return accumulator.concat(contract.getChildren(options)); | ||
}, []); | ||
contracts.push(...contract.getChildren(options)); | ||
}); | ||
return contracts; | ||
} | ||
@@ -259,0 +262,0 @@ getChildrenByType(type) { |
import { ContractObject } from './types/types'; | ||
export declare const compileContract: (contract: ContractObject, options?: { | ||
blacklist?: Set<string>; | ||
}, root?: ContractObject, breadcrumb?: string[]) => ContractObject; | ||
}, root?: { | ||
type: string; | ||
} & { | ||
[key: string]: any; | ||
}, breadcrumb?: string[]) => ContractObject; |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.compileContract = void 0; | ||
const concat_1 = __importDefault(require("lodash/concat")); | ||
const get_1 = __importDefault(require("lodash/get")); | ||
@@ -18,3 +17,3 @@ const isArray_1 = __importDefault(require("lodash/isArray")); | ||
: (0, mapValues_1.default)(object, (value, key) => { | ||
const absoluteKey = (0, concat_1.default)(breadcrumb, [key]); | ||
const absoluteKey = [...breadcrumb, key]; | ||
return (0, isPlainObject_1.default)(value) | ||
@@ -25,22 +24,40 @@ ? deepMapValues(value, callback, absoluteKey) | ||
const TEMPLATE_REGEXP = /\{\{(.+?)\}\}/g; | ||
const compileContract = (contract, options = {}, root, breadcrumb) => deepMapValues(contract, (value, key) => { | ||
if ((0, isString_1.default)(value)) { | ||
if (options.blacklist) { | ||
for (const path of options.blacklist) { | ||
if (key.join('.').startsWith(path)) { | ||
return value; | ||
const compileContract = (contract, options = {}, root = contract, breadcrumb) => { | ||
let isMultiLevelBlacklist = false; | ||
if (options.blacklist) { | ||
for (const path of options.blacklist) { | ||
if (path.includes('.')) { | ||
isMultiLevelBlacklist = true; | ||
break; | ||
} | ||
} | ||
} | ||
return deepMapValues(contract, (value, key) => { | ||
if ((0, isString_1.default)(value)) { | ||
if (options.blacklist) { | ||
const checkKey = isMultiLevelBlacklist ? key.join('.') : key[0]; | ||
for (const path of options.blacklist) { | ||
if (checkKey.startsWith(path)) { | ||
return value; | ||
} | ||
} | ||
} | ||
return value.replace(TEMPLATE_REGEXP, (interpolation, path) => { | ||
const pathArr = path.split('.'); | ||
if (pathArr.shift() !== 'this') { | ||
return interpolation; | ||
} | ||
return (0, get_1.default)(root, pathArr) || interpolation; | ||
}); | ||
} | ||
const data = { | ||
this: root || contract, | ||
}; | ||
return value.replace(TEMPLATE_REGEXP, (interpolation, path) => (0, get_1.default)(data, path) || interpolation); | ||
} | ||
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); | ||
if ((0, isArray_1.default)(value)) { | ||
return (0, map_1.default)(value, (object, index) => (0, exports.compileContract)(object, options, contract, [ | ||
...key, | ||
index.toString(), | ||
])); | ||
} | ||
return value; | ||
}, breadcrumb); | ||
}; | ||
exports.compileContract = compileContract; | ||
//# sourceMappingURL=template.js.map |
{ | ||
"name": "@balena/contrato", | ||
"version": "0.9.1", | ||
"version": "0.9.2-build-optimizations-59d52335ca8d783cd7f9730df086c4d504b2d2cb-1", | ||
"description": "The official contract implementation", | ||
@@ -74,4 +74,4 @@ "homepage": "https://github.com/product-os/contrato", | ||
"versionist": { | ||
"publishedAt": "2023-04-04T11:58:30.500Z" | ||
"publishedAt": "2023-04-04T17:28:51.137Z" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
125369
1546