Socket
Socket
Sign inDemoInstall

@accordproject/concerto-core

Package Overview
Dependencies
Maintainers
3
Versions
855
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@accordproject/concerto-core - npm Package Compare versions

Comparing version 3.18.1-20240724092842 to 3.18.1-20240807140156

2

dist/concerto-core.js.LICENSE.txt
/*!
* Concerto v3.18.1-20240724092842
* Concerto v3.18.1-20240807140156
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -4,0 +4,0 @@ * you may not use this file except in compliance with the License.

@@ -25,5 +25,15 @@ /*

* @memberof module:concerto-core
* @private
*/
class DecoratorExtractor {
/**
* The action to be performed to extract all, only vocab or only non-vocab decorators
*/
static Action = {
EXTRACT_ALL: 0,
EXTRACT_VOCAB: 1,
EXTRACT_NON_VOCAB: 2
};
/**
* Create the DecoratorExtractor.

@@ -35,4 +45,5 @@ * @constructor

* @param {Object} sourceModelAst - the ast of source models
* @param {int} [action=DecoratorExtractor.Action.EXTRACT_ALL] - the action to be performed
*/
constructor(removeDecoratorsFromModel, locale, dcs_version, sourceModelAst) {
constructor(removeDecoratorsFromModel, locale, dcs_version, sourceModelAst, action = DecoratorExtractor.Action.EXTRACT_ALL) {
this.extractionDictionary = {};

@@ -44,4 +55,15 @@ this.removeDecoratorsFromModel = removeDecoratorsFromModel;

this.updatedModelAst = sourceModelAst;
this.action = Object.values(DecoratorExtractor.Action).includes(action)? action : DecoratorExtractor.Action.EXTRACT_ALL;
}
/**
* Returns if the decorator is vocab or not
* @param {string} decoractorName - the name of decorator
* @returns {boolean} - returns true if the decorator is a vocabulary decorator else false
* @private
*/
isVocabDecorator(decoractorName) {
return decoractorName === 'Term' || decoractorName.startsWith('Term_');
}
/**
* Adds a key-value pair to a dictionary (object) if the key exists,

@@ -111,3 +133,9 @@ * or creates a new key with the provided value.

strVoc += ` - ${decl}: ${vocabObject[decl].term}\n`;
const otherProps = Object.keys(vocabObject[decl]).filter((str)=>str !== 'term' && str !== 'propertyVocabs');
}
const otherProps = Object.keys(vocabObject[decl]).filter((str)=>str !== 'term' && str !== 'propertyVocabs');
//If a declaration does not have any Term decorator, then add Term_ decorators to yaml
if(otherProps.length > 0){
if (!vocabObject[decl].term){
strVoc += ` - ${decl}: ${decl}\n`;
}
otherProps.forEach(key =>{

@@ -118,3 +146,3 @@ strVoc += ` ${key}: ${vocabObject[decl][key]}\n`;

if (vocabObject[decl].propertyVocabs && Object.keys(vocabObject[decl].propertyVocabs).length > 0){
if (!vocabObject[decl].term){
if (!vocabObject[decl].term && otherProps.length === 0){
strVoc += ` - ${decl}: ${decl}\n`;

@@ -124,3 +152,3 @@ }

Object.keys(vocabObject[decl].propertyVocabs).forEach(prop =>{
strVoc += ` - ${prop}: ${vocabObject[decl].propertyVocabs[prop].term}\n`;
strVoc += ` - ${prop}: ${vocabObject[decl].propertyVocabs[prop].term || ''}\n`;
const otherProps = Object.keys(vocabObject[decl].propertyVocabs[prop]).filter((str)=>str !== 'term');

@@ -214,2 +242,14 @@ otherProps.forEach(key =>{

}
else if (decl.mapElement !== ''){
if (!dictVoc[decl.declaration].propertyVocabs[decl.mapElement]){
dictVoc[decl.declaration].propertyVocabs[decl.mapElement] = {};
}
if (dcs.name === 'Term'){
dictVoc[decl.declaration].propertyVocabs[decl.mapElement].term = dcs.arguments[0].value;
}
else {
const extensionKey = dcs.name.split('Term_')[1];
dictVoc[decl.declaration].propertyVocabs[decl.mapElement][extensionKey] = dcs.arguments[0].value;
}
}
else {

@@ -237,3 +277,2 @@ if (dcs.name === 'Term'){

const jsonData = this.extractionDictionary[namespace];
const patternToDetermineVocab = /^Term_/i;
let dcsObjects = [];

@@ -245,6 +284,7 @@ let vocabObject = {};

decos.forEach(dcs =>{
if (dcs.name !== 'Term' && !patternToDetermineVocab.test(dcs.name)){
const isVocab = this.isVocabDecorator(dcs.name);
if (!isVocab && this.action !== DecoratorExtractor.Action.EXTRACT_VOCAB){
dcsObjects = this.parseNonVocabularyDecorators(dcsObjects, dcs, this.dcs_version, target);
}
else {
if (isVocab && this.action !== DecoratorExtractor.Action.EXTRACT_NON_VOCAB){
vocabObject = this.parseVocabularies(vocabObject, obj, dcs);

@@ -254,4 +294,8 @@ }

});
decoratorData = this.transformNonVocabularyDecorators(dcsObjects, namespace, decoratorData);
vocabData = this.transformVocabularyDecorators(vocabObject, namespace, vocabData);
if(this.action !== DecoratorExtractor.Action.EXTRACT_VOCAB){
decoratorData = this.transformNonVocabularyDecorators(dcsObjects, namespace, decoratorData);
}
if(this.action !== DecoratorExtractor.Action.EXTRACT_NON_VOCAB){
vocabData = this.transformVocabularyDecorators(vocabObject, namespace, vocabData);
}
});

@@ -263,3 +307,23 @@ return {

}
/**
* Filter vocab or non-vocab decorators
* @param {Object} decorators - the collection of decorators
* @returns {Object} - the collection of filtered decorators
* @private
*/
filterOutDecorators(decorators){
if(!this.removeDecoratorsFromModel){
return decorators;
}
if (this.action === DecoratorExtractor.Action.EXTRACT_ALL){
return undefined;
}
else if(this.action === DecoratorExtractor.Action.EXTRACT_VOCAB){
return decorators.filter((dcs) => !this.isVocabDecorator(dcs.name));
}
else{
return decorators.filter((dcs) => this.isVocabDecorator(dcs.name));
}
}
/**

@@ -281,5 +345,3 @@ * Process the map declarations to extract the decorators.

this.constructDCSDictionary(namespace, declaration.key.decorators, constructOptions);
if (this.removeDecoratorsFromModel){
declaration.key.decorators = undefined;
}
declaration.key.decorators = this.filterOutDecorators(declaration.key.decorators);
}

@@ -294,5 +356,3 @@ }

this.constructDCSDictionary(namespace, declaration.value.decorators, constructOptions);
if (this.removeDecoratorsFromModel){
declaration.value.decorators = undefined;
}
declaration.value.decorators = this.filterOutDecorators(declaration.value.decorators);
}

@@ -320,6 +380,4 @@ }

this.constructDCSDictionary(namespace, property.decorators, constructOptions );
property.decorators = this.filterOutDecorators(property.decorators);
}
if (this.removeDecoratorsFromModel){
property.decorators = undefined;
}
return property;

@@ -345,6 +403,4 @@ });

this.constructDCSDictionary(namespace, decl.decorators, constructOptions);
decl.decorators = this.filterOutDecorators(decl.decorators);
}
if (this.removeDecoratorsFromModel){
decl.decorators = undefined;
}
if (decl.$class === `${MetaModelNamespace}.MapDeclaration`) {

@@ -370,7 +426,5 @@ const processedMapDecl = this.processMapDeclaration(decl, namespace);

const processedModels = this.sourceModelAst.models.map(model =>{
if ((model?.decorators.length > 0)){
if ((model?.decorators?.length > 0)){
this.constructDCSDictionary(model.namespace, model.decorators, {});
if (this.removeDecoratorsFromModel){
model.decorators = undefined;
}
model.decorators = this.filterOutDecorators(model.decorators);
}

@@ -377,0 +431,0 @@ const processedDecl = this.processDeclarations(model.declarations, model.namespace);

@@ -427,11 +427,7 @@ /*

/**
* @typedef decoratorCommandSet
* @type {object}
* @typedef vocabularies
* @type {string}
* @typedef ExtractDecoratorsResult
* @type {object}
* @property {ModelManager} modelManager - A model manager containing models stripped without decorators
* @property {decoratorCommandSet} object[] - Stripped out decorators, formed into decorator command sets
* @property {vocabularies} object[] - Stripped out vocabularies, formed into vocabulary files
* @property {*} decoratorCommandSet - Stripped out decorators, formed into decorator command sets
* @property {string[]} vocabularies - Stripped out vocabularies, formed into vocabulary files
*/

@@ -453,3 +449,3 @@ /**

const sourceAst = modelManager.getAst(true);
const decoratorExtrator = new DecoratorExtractor(options.removeDecoratorsFromModel, options.locale, DCS_VERSION, sourceAst);
const decoratorExtrator = new DecoratorExtractor(options.removeDecoratorsFromModel, options.locale, DCS_VERSION, sourceAst, DecoratorExtractor.Action.EXTRACT_ALL);
const collectionResp = decoratorExtrator.extract();

@@ -462,4 +458,47 @@ return {

}
/**
* Extracts all the vocab decorator commands from all the models in modelManager
* @param {ModelManager} modelManager the input model manager
* @param {object} options - decorator models options
* @param {boolean} options.removeDecoratorsFromModel - flag to strip out vocab decorators from models
* @param {string} options.locale - locale for extracted vocabulary set
* @returns {ExtractDecoratorsResult} - a new model manager with/without the decorators and vocab yamls
*/
static extractVocabularies(modelManager,options) {
options = {
removeDecoratorsFromModel: false,
locale:'en',
...options
};
const sourceAst = modelManager.getAst(true);
const decoratorExtrator = new DecoratorExtractor(options.removeDecoratorsFromModel, options.locale, DCS_VERSION, sourceAst, DecoratorExtractor.Action.EXTRACT_VOCAB);
const collectionResp = decoratorExtrator.extract();
return {
modelManager: collectionResp.updatedModelManager,
vocabularies: collectionResp.vocabularies
};
}
/**
* Extracts all the non-vocab decorator commands from all the models in modelManager
* @param {ModelManager} modelManager the input model manager
* @param {object} options - decorator models options
* @param {boolean} options.removeDecoratorsFromModel - flag to strip out non-vocab decorators from models
* @param {string} options.locale - locale for extracted vocabulary set
* @returns {ExtractDecoratorsResult} - a new model manager with/without the decorators and a list of extracted decorator jsons
*/
static extractNonVocabDecorators(modelManager,options) {
options = {
removeDecoratorsFromModel: false,
locale:'en',
...options
};
const sourceAst = modelManager.getAst(true);
const decoratorExtrator = new DecoratorExtractor(options.removeDecoratorsFromModel, options.locale, DCS_VERSION, sourceAst, DecoratorExtractor.Action.EXTRACT_NON_VOCAB);
const collectionResp = decoratorExtrator.extract();
return {
modelManager: collectionResp.updatedModelManager,
decoratorCommandSet: collectionResp.decoratorCommandSet
};
}
/**
* Throws an error if the decoractor command is invalid

@@ -466,0 +505,0 @@ * @param {ModelManager} validationModelManager the validation model manager

{
"name": "@accordproject/concerto-core",
"version": "3.18.1-20240724092842",
"version": "3.18.1-20240807140156",
"description": "Core Implementation for the Concerto Modeling Language",

@@ -74,5 +74,5 @@ "homepage": "https://github.com/accordproject/concerto",

"dependencies": {
"@accordproject/concerto-cto": "3.18.1-20240724092842",
"@accordproject/concerto-cto": "3.18.1-20240807140156",
"@accordproject/concerto-metamodel": "3.10.0",
"@accordproject/concerto-util": "3.18.1-20240724092842",
"@accordproject/concerto-util": "3.18.1-20240807140156",
"dayjs": "1.11.10",

@@ -79,0 +79,0 @@ "debug": "4.3.4",

@@ -6,5 +6,14 @@ export = DecoratorExtractor;

* @memberof module:concerto-core
* @private
*/
declare class DecoratorExtractor {
/**
* The action to be performed to extract all, only vocab or only non-vocab decorators
*/
static Action: {
EXTRACT_ALL: number;
EXTRACT_VOCAB: number;
EXTRACT_NON_VOCAB: number;
};
/**
* Create the DecoratorExtractor.

@@ -16,4 +25,5 @@ * @constructor

* @param {Object} sourceModelAst - the ast of source models
* @param {int} [action=DecoratorExtractor.Action.EXTRACT_ALL] - the action to be performed
*/
constructor(removeDecoratorsFromModel: boolean, locale: string, dcs_version: string, sourceModelAst: any);
constructor(removeDecoratorsFromModel: boolean, locale: string, dcs_version: string, sourceModelAst: any, action?: int);
extractionDictionary: {};

@@ -25,3 +35,11 @@ removeDecoratorsFromModel: boolean;

updatedModelAst: any;
action: any;
/**
* Returns if the decorator is vocab or not
* @param {string} decoractorName - the name of decorator
* @returns {boolean} - returns true if the decorator is a vocabulary decorator else false
* @private
*/
private isVocabDecorator;
/**
* Adds a key-value pair to a dictionary (object) if the key exists,

@@ -91,2 +109,9 @@ * or creates a new key with the provided value.

/**
* Filter vocab or non-vocab decorators
* @param {Object} decorators - the collection of decorators
* @returns {Object} - the collection of filtered decorators
* @private
*/
private filterOutDecorators;
/**
* Process the map declarations to extract the decorators.

@@ -93,0 +118,0 @@ *

@@ -94,11 +94,7 @@ export = DecoratorManager;

/**
* @typedef decoratorCommandSet
* @type {object}
* @typedef vocabularies
* @type {string}
* @typedef ExtractDecoratorsResult
* @type {object}
* @property {ModelManager} modelManager - A model manager containing models stripped without decorators
* @property {decoratorCommandSet} object[] - Stripped out decorators, formed into decorator command sets
* @property {vocabularies} object[] - Stripped out vocabularies, formed into vocabulary files
* @property {*} decoratorCommandSet - Stripped out decorators, formed into decorator command sets
* @property {string[]} vocabularies - Stripped out vocabularies, formed into vocabulary files
*/

@@ -124,5 +120,59 @@ /**

*/
object: {};
decoratorCommandSet: any;
/**
* - Stripped out vocabularies, formed into vocabulary files
*/
vocabularies: string[];
};
/**
* Extracts all the vocab decorator commands from all the models in modelManager
* @param {ModelManager} modelManager the input model manager
* @param {object} options - decorator models options
* @param {boolean} options.removeDecoratorsFromModel - flag to strip out vocab decorators from models
* @param {string} options.locale - locale for extracted vocabulary set
* @returns {ExtractDecoratorsResult} - a new model manager with/without the decorators and vocab yamls
*/
static extractVocabularies(modelManager: ModelManager, options: {
removeDecoratorsFromModel: boolean;
locale: string;
}): {
/**
* - A model manager containing models stripped without decorators
*/
modelManager: ModelManager;
/**
* - Stripped out decorators, formed into decorator command sets
*/
decoratorCommandSet: any;
/**
* - Stripped out vocabularies, formed into vocabulary files
*/
vocabularies: string[];
};
/**
* Extracts all the non-vocab decorator commands from all the models in modelManager
* @param {ModelManager} modelManager the input model manager
* @param {object} options - decorator models options
* @param {boolean} options.removeDecoratorsFromModel - flag to strip out non-vocab decorators from models
* @param {string} options.locale - locale for extracted vocabulary set
* @returns {ExtractDecoratorsResult} - a new model manager with/without the decorators and a list of extracted decorator jsons
*/
static extractNonVocabDecorators(modelManager: ModelManager, options: {
removeDecoratorsFromModel: boolean;
locale: string;
}): {
/**
* - A model manager containing models stripped without decorators
*/
modelManager: ModelManager;
/**
* - Stripped out decorators, formed into decorator command sets
*/
decoratorCommandSet: any;
/**
* - Stripped out vocabularies, formed into vocabulary files
*/
vocabularies: string[];
};
/**
* Throws an error if the decoractor command is invalid

@@ -129,0 +179,0 @@ * @param {ModelManager} validationModelManager the validation model manager

Sorry, the diff of this file is too big to display

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