@accordproject/concerto-core 3.25.7 → 3.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Concerto v3.25.7
2
+ * Concerto v3.26.0
3
3
  * Licensed under the Apache License, Version 2.0 (the "License");
4
4
  * you may not use this file except in compliance with the License.
5
5
  * You may obtain a copy of the License at
@@ -307,7 +307,7 @@ class DecoratorManager {
307
307
  /**
308
308
  * Migrate or validate the DecoratorCommandSet object if the options are set as true
309
309
  * @param {ModelManager} modelManager the input model manager
310
- * @param {*} decoratorCommandSet the DecoratorCommandSet object
310
+ * @param {*} decoratorCommandSet a DecoratorCommandSet object, or an array of DecoratorCommandSet objects
311
311
  * @param {boolean} shouldMigrate migrate the decoratorCommandSet $class to match the dcs model version
312
312
  * @param {boolean} shouldValidate validate that decorator command set is valid
313
313
  * with respect to to decorator command set model
@@ -316,8 +316,13 @@ class DecoratorManager {
316
316
  * @private
317
317
  */
318
318
  static migrateAndValidate(modelManager, decoratorCommandSet, shouldMigrate, shouldValidate, shouldValidateCommands) {
319
- if (shouldMigrate && this.canMigrate(decoratorCommandSet, DCS_VERSION)) {
320
- decoratorCommandSet = this.migrateTo(decoratorCommandSet, DCS_VERSION);
319
+ const decoratorCommandSets = Array.isArray(decoratorCommandSet) ? decoratorCommandSet : [decoratorCommandSet];
320
+ if (shouldMigrate) {
321
+ decoratorCommandSets.forEach((commandSet, index) => {
322
+ if (this.canMigrate(commandSet, DCS_VERSION)) {
323
+ decoratorCommandSets[index] = this.migrateTo(commandSet, DCS_VERSION);
324
+ }
325
+ });
321
326
  }
322
327
 
323
328
  if (shouldValidate) {
@@ -336,15 +341,17 @@ class DecoratorManager {
336
341
  );
337
342
  const factory = new Factory(validationModelManager);
338
343
  const serializer = new Serializer(factory, validationModelManager);
339
- serializer.fromJSON(decoratorCommandSet);
340
- if (shouldValidateCommands) {
341
- decoratorCommandSet.commands.forEach((command) => {
342
- DecoratorManager.validateCommand(
343
- validationModelManager,
344
- command
345
- );
346
- });
347
- }
344
+ decoratorCommandSets.forEach((commandSet) => {
345
+ serializer.fromJSON(commandSet);
346
+ if (shouldValidateCommands) {
347
+ commandSet.commands.forEach((command) => {
348
+ DecoratorManager.validateCommand(
349
+ validationModelManager,
350
+ command
351
+ );
352
+ });
353
+ }
354
+ });
348
355
  }
349
356
  }
350
357
 
@@ -364,7 +371,7 @@ class DecoratorManager {
364
371
  /**
365
372
  * Applies all the decorator commands from the DecoratorCommandSet to the ModelManager
366
373
  * @param {ModelManager} modelManager the input model manager
367
- * @param {*} decoratorCommandSet the DecoratorCommandSet object
374
+ * @param {*} decoratorCommandSet the DecoratorCommandSet object, or an array of DecoratorCommandSet objects
368
375
  * @param {object} [options] - decorator models options
369
376
  * @param {boolean} [options.validate] - validate that decorator command set is valid
370
377
  * with respect to to decorator command set model
@@ -379,20 +386,31 @@ class DecoratorManager {
379
386
  * @returns {ModelManager} a new model manager with the decorations applied
380
387
  */
381
388
  static decorateModels(modelManager, decoratorCommandSet, options) {
389
+ if (!decoratorCommandSet || decoratorCommandSet?.length === 0) {
390
+ return modelManager;
391
+ }
392
+ const decoratorCommandSets = Array.isArray(decoratorCommandSet)
393
+ ? decoratorCommandSet
394
+ : [decoratorCommandSet];
382
395
 
383
396
  if (options?.skipValidationAndResolution) {
384
- if (options?.disableMetamodelResolution === false || !options?.disableMetamodelValidation === false) {
397
+ if (options?.disableMetamodelResolution === false || options?.disableMetamodelValidation === false) {
385
398
  throw new Error('skipValidationAndResolution cannot be used with disableMetamodelResolution or disableMetamodelValidation options as false');
386
399
  }
387
400
  options.disableMetamodelResolution = true;
388
401
  options.disableMetamodelValidation = true;
389
402
  }
390
403
 
391
- this.migrateAndValidate(modelManager, decoratorCommandSet, options?.migrate, options?.validate, options?.validateCommands);
404
+ this.migrateAndValidate(modelManager, decoratorCommandSets, options?.migrate, options?.validate, options?.validateCommands);
405
+
406
+ // Flatten commands across all command sets so decorators can be applied in a single AST scan.
407
+ const combinedDecoratorCommandSet = {
408
+ commands: decoratorCommandSets.flatMap(commandSet => commandSet.commands)
409
+ };
392
410
 
393
411
  // we create synthetic imports for all decorator declarations
394
412
  // along with any of their type reference arguments
395
- const decoratorImports = decoratorCommandSet.commands.flatMap(command => {
413
+ const decoratorImports = combinedDecoratorCommandSet.commands.flatMap(command => {
396
414
  return [{
397
415
  $class: `${MetaModelNamespace}.ImportType`,
398
416
  name: command.decorator.name,
@@ -407,7 +425,7 @@ class DecoratorManager {
407
425
  })
408
426
  : []);
409
427
  }).filter(i => i.namespace);
410
- const { namespaceCommandsMap, declarationCommandsMap, propertyCommandsMap, mapElementCommandsMap, typeCommandsMap } = this.getDecoratorMaps(decoratorCommandSet);
428
+ const { namespaceCommandsMap, declarationCommandsMap, propertyCommandsMap, mapElementCommandsMap, typeCommandsMap } = this.getDecoratorMaps(combinedDecoratorCommandSet);
411
429
  const ast = options?.disableMetamodelResolution ? modelManager.getAst(false, true) : modelManager.getAst(true, true);
412
430
  const decoratedAst = rfdc(ast);
413
431
  decoratedAst.models.forEach((model) => {
@@ -244,7 +244,7 @@ class ModelFile extends Decorated {
244
244
  const unseenNamespace = existingNamespaceVersion === undefined;
245
245
 
246
246
  // This check is needed because we automatically add both versioned and unversioned versions of
247
- // the root namespace for backwards compatibillity unless we're running in strict mode
247
+ // the root namespace for backwards compatibility unless we're running in strict mode
248
248
  const isGlobalModel = name === 'concerto';
249
249
 
250
250
  const differentVersionsOfSameNamespace = !unseenNamespace && existingNamespaceVersion !== importVersion;
@@ -754,10 +754,10 @@ class ModelFile extends Decorated {
754
754
  switch(imp.$class) {
755
755
  case `${MetaModelNamespace}.ImportAll`:
756
756
  if (this.getModelManager().isStrict()){
757
- throw new Error('Wilcard Imports are not permitted in strict mode.');
757
+ throw new Error('Wildcard Imports are not permitted in strict mode.');
758
758
  }
759
759
  Warning.printDeprecationWarning(
760
- 'Wilcard Imports are deprecated in this version of Concerto and will be removed in a future version.',
760
+ 'Wildcard Imports are deprecated in this version of Concerto and will be removed in a future version.',
761
761
  ErrorCodes.DEPRECATION_WARNING,
762
762
  ErrorCodes.CONCERTO_DEPRECATION_002,
763
763
  'Please refer to https://concerto.accordproject.org/deprecation/002'
@@ -79,11 +79,11 @@ class Relationship extends Identifiable {
79
79
  }
80
80
 
81
81
  /**
82
- * Contructs a Relationship instance from a URI representation (created using toURI).
82
+ * Constructs a Relationship instance from a URI representation (created using toURI).
83
83
  * @param {ModelManager} modelManager - the model manager to bind the relationship to
84
84
  * @param {String} uriAsString - the URI as a string, generated using Identifiable.toURI()
85
- * @param {String} [defaultNamespace] - default namespace to use for backwards compatability
86
- * @param {String} [defaultType] - default type to use for backwards compatability
85
+ * @param {String} [defaultNamespace] - default namespace to use for backwards compatibility
86
+ * @param {String} [defaultType] - default type to use for backwards compatibility
87
87
  * @return {Relationship} the relationship
88
88
  */
89
89
  static fromURI(modelManager, uriAsString, defaultNamespace, defaultType) {
@@ -189,7 +189,7 @@ class Typed {
189
189
  if (classDeclaration.getFullyQualifiedName() === fqt) {
190
190
  return true;
191
191
  }
192
- // Now walk the class hierachy looking to see if it's an instance of the specified type.
192
+ // Now walk the class hierarchy looking to see if it's an instance of the specified type.
193
193
  let superTypeDeclaration = classDeclaration.getSuperTypeDeclaration();
194
194
  while (superTypeDeclaration) {
195
195
  if (superTypeDeclaration.getFullyQualifiedName() === fqt) {
@@ -201,7 +201,7 @@ class Typed {
201
201
  }
202
202
 
203
203
  /**
204
- * Overriden to prevent people accidentally converting a resource to JSON
204
+ * Overridden to prevent people accidentally converting a resource to JSON
205
205
  * without using the Serializer.
206
206
  * @protected
207
207
  */
@@ -96,7 +96,7 @@ class InstanceGenerator {
96
96
  throw new Error('Model is recursive.');
97
97
  }
98
98
  parameters.seen.push(fqn);
99
- } else { parameters.seen.push('Primitve');
99
+ } else { parameters.seen.push('Primitive');
100
100
  }
101
101
  let result;
102
102
  if (field.isArray()) {
@@ -233,7 +233,7 @@ class JSONPopulator {
233
233
  parameters.resourceStack.push(subResource);
234
234
  return decl.accept(this, parameters);
235
235
  }
236
- // otherwise its a scalar value, we only need to return the primitve value of the scalar.
236
+ // otherwise its a scalar value, we only need to return the primitive value of the scalar.
237
237
  return value;
238
238
  }
239
239
 
@@ -510,7 +510,7 @@ class ObjectValidator {
510
510
 
511
511
  /**
512
512
  * Throw a validation exception for an abstract class
513
- * @param {string} resourceId - the id of the resouce being validated
513
+ * @param {string} resourceId - the id of the resource being validated
514
514
  * @param {string} propertyName - the name of the property that is not declared
515
515
  * @param {string} fullyQualifiedTypeName - the fully qualified type being validated
516
516
  * @throws {ValidationException} the validation exception
@@ -527,7 +527,7 @@ class ObjectValidator {
527
527
 
528
528
  /**
529
529
  * Throw a validation exception for an invalid field assignment
530
- * @param {string} resourceId - the id of the resouce being validated
530
+ * @param {string} resourceId - the id of the resource being validated
531
531
  * @param {string} propName - the name of the property that is being assigned
532
532
  * @param {*} obj - the Field
533
533
  * @param {Field} field - the Field
@@ -205,7 +205,7 @@ class ResourceValidator {
205
205
 
206
206
  const obj = parameters.stack.pop();
207
207
 
208
- // are we dealing with a Resouce?
208
+ // are we dealing with a Resource?
209
209
  if(!((obj instanceof Resource))) {
210
210
  ResourceValidator.reportNotResouceViolation(parameters.rootResourceIdentifier, classDeclaration, obj );
211
211
  }
@@ -233,7 +233,7 @@ class ResourceValidator {
233
233
  const field = toBeAssignedClassDeclaration.getProperty(propName);
234
234
  if (!field) {
235
235
  if(classDeclaration.isIdentified() &&
236
- // Allow shadowing of the $identifer field to normalize lookup of the identifying field.
236
+ // Allow shadowing of the $identifier field to normalize lookup of the identifying field.
237
237
  propName !== '$identifier'
238
238
  ){
239
239
  ResourceValidator.reportUndeclaredField(obj.getIdentifier(), propName, toBeAssignedClassDecName);
@@ -273,7 +273,7 @@ class ResourceValidator {
273
273
  }
274
274
  else {
275
275
  if(!property.isOptional()) {
276
- // Allow shadowing of the $identifer field to normalize lookup of the identifying field.
276
+ // Allow shadowing of the $identifier field to normalize lookup of the identifying field.
277
277
  if (property.getName() === '$identifier' && identifierFieldName !== '$identifier'
278
278
  ) {
279
279
  continue;
@@ -631,7 +631,7 @@ class ResourceValidator {
631
631
 
632
632
  /**
633
633
  * Throw a validation exception for an abstract class
634
- * @param {string} resourceId - the id of the resouce being validated
634
+ * @param {string} resourceId - the id of the resource being validated
635
635
  * @param {string} propertyName - the name of the property that is not declared
636
636
  * @param {string} fullyQualifiedTypeName - the fully qualified type being validated
637
637
  * @throws {ValidationException} the validation exception
@@ -648,7 +648,7 @@ class ResourceValidator {
648
648
 
649
649
  /**
650
650
  * Throw a validation exception for an invalid field assignment
651
- * @param {string} resourceId - the id of the resouce being validated
651
+ * @param {string} resourceId - the id of the resource being validated
652
652
  * @param {string} propName - the name of the property that is being assigned
653
653
  * @param {*} obj - the Field
654
654
  * @param {Field} field - the Field
package/lib/serializer.js CHANGED
@@ -128,7 +128,7 @@ class Serializer {
128
128
  parameters.stack.clear();
129
129
  parameters.stack.push(resource);
130
130
 
131
- // this performs the conversion of the resouce into a standard JSON object
131
+ // this performs the conversion of the resource into a standard JSON object
132
132
  let result = classDeclaration.accept(generator, parameters);
133
133
  return result;
134
134
  }
package/package.json CHANGED
@@ -1,42 +1,24 @@
1
1
  {
2
2
  "name": "@accordproject/concerto-core",
3
- "version": "3.25.7",
4
3
  "description": "Core Implementation for the Concerto Modeling Language",
5
- "homepage": "https://github.com/accordproject/concerto",
6
- "engines": {
7
- "node": ">=18",
8
- "npm": ">=10"
9
- },
10
- "main": "index.js",
4
+ "version": "3.26.0",
5
+ "author": "accordproject.org",
11
6
  "browser": "dist/concerto-core.js",
12
- "typings": "types/index.d.ts",
13
- "scripts": {
14
- "prepublishOnly": "npm run webpack",
15
- "pretest": "npm run lint",
16
- "lint": "eslint .",
17
- "postlicchk": "npm run doc",
18
- "doc": "jsdoc --pedantic --recurse -c jsdoc.json",
19
- "test": "node ./scripts/api-changelog.js && cross-env TZ=UTC nyc mocha --recursive -t 10000",
20
- "test:watch": "cross-env TZ=UTC nyc mocha --watch --recursive -t 10000",
21
- "mocha": "mocha --recursive -t 10000",
22
- "nyc": "nyc mocha --recursive -t 10000",
23
- "build": "npm run build:types",
24
- "postbuild": "npm run webpack",
25
- "webpack": "webpack --config webpack.config.js --mode production",
26
- "build:types": "tsc index.js --declaration --allowJs --emitDeclarationOnly --outDir types"
27
- },
28
- "repository": {
29
- "type": "git",
30
- "url": "https://github.com/accordproject/concerto.git",
31
- "directory": "packages/concerto-cto"
7
+ "browserslist": "> 0.25%, not dead",
8
+ "dependencies": {
9
+ "@accordproject/concerto-cto": "3.26.0",
10
+ "@accordproject/concerto-metamodel": "3.12.6",
11
+ "@accordproject/concerto-util": "3.26.0",
12
+ "dayjs": "1.11.13",
13
+ "debug": "4.3.7",
14
+ "lorem-ipsum": "2.0.8",
15
+ "randexp": "0.5.3",
16
+ "rfdc": "1.4.1",
17
+ "semver": "7.6.3",
18
+ "urijs": "1.19.11",
19
+ "uuid": "11.0.3",
20
+ "yaml": "2.8.0"
32
21
  },
33
- "keywords": [
34
- "schema",
35
- "data model",
36
- "verification"
37
- ],
38
- "author": "accordproject.org",
39
- "license": "Apache-2.0",
40
22
  "devDependencies": {
41
23
  "@babel/preset-env": "7.26.0",
42
24
  "acorn": "8.14.0",
@@ -63,21 +45,18 @@
63
45
  "xregexp": "5.1.1",
64
46
  "yargs": "17.7.2"
65
47
  },
66
- "dependencies": {
67
- "@accordproject/concerto-cto": "3.25.7",
68
- "@accordproject/concerto-metamodel": "3.12.6",
69
- "@accordproject/concerto-util": "3.25.7",
70
- "dayjs": "1.11.13",
71
- "debug": "4.3.7",
72
- "lorem-ipsum": "2.0.8",
73
- "randexp": "0.5.3",
74
- "rfdc": "1.4.1",
75
- "semver": "7.6.3",
76
- "urijs": "1.19.11",
77
- "uuid": "11.0.3",
78
- "yaml": "2.8.0"
48
+ "engines": {
49
+ "node": ">=18",
50
+ "npm": ">=10"
79
51
  },
80
- "browserslist": "> 0.25%, not dead",
52
+ "homepage": "https://github.com/accordproject/concerto",
53
+ "keywords": [
54
+ "data model",
55
+ "schema",
56
+ "verification"
57
+ ],
58
+ "license": "Apache-2.0",
59
+ "main": "index.js",
81
60
  "nyc": {
82
61
  "produce-source-map": "true",
83
62
  "sourceMap": "inline",
@@ -97,5 +76,26 @@
97
76
  "branches": 97,
98
77
  "functions": 98,
99
78
  "lines": 99
100
- }
79
+ },
80
+ "repository": {
81
+ "type": "git",
82
+ "url": "https://github.com/accordproject/concerto.git",
83
+ "directory": "packages/concerto-cto"
84
+ },
85
+ "scripts": {
86
+ "build": "npm run build:types",
87
+ "build:types": "tsc index.js --declaration --allowJs --emitDeclarationOnly --outDir types",
88
+ "doc": "jsdoc --pedantic --recurse -c jsdoc.json",
89
+ "lint": "eslint .",
90
+ "mocha": "mocha --recursive -t 10000",
91
+ "nyc": "nyc mocha --recursive -t 10000",
92
+ "postbuild": "npm run webpack",
93
+ "postlicchk": "npm run doc",
94
+ "prepublishOnly": "npm run webpack",
95
+ "pretest": "npm run lint",
96
+ "test": "node ./scripts/api-changelog.js && cross-env TZ=UTC nyc mocha --recursive -t 10000",
97
+ "test:watch": "cross-env TZ=UTC nyc mocha --watch --recursive -t 10000",
98
+ "webpack": "webpack --config webpack.config.js --mode production"
99
+ },
100
+ "typings": "types/index.d.ts"
101
101
  }
@@ -52,7 +52,7 @@ declare class DecoratorManager {
52
52
  /**
53
53
  * Migrate or validate the DecoratorCommandSet object if the options are set as true
54
54
  * @param {ModelManager} modelManager the input model manager
55
- * @param {*} decoratorCommandSet the DecoratorCommandSet object
55
+ * @param {*} decoratorCommandSet a DecoratorCommandSet object, or an array of DecoratorCommandSet objects
56
56
  * @param {boolean} shouldMigrate migrate the decoratorCommandSet $class to match the dcs model version
57
57
  * @param {boolean} shouldValidate validate that decorator command set is valid
58
58
  * with respect to to decorator command set model
@@ -72,7 +72,7 @@ declare class DecoratorManager {
72
72
  /**
73
73
  * Applies all the decorator commands from the DecoratorCommandSet to the ModelManager
74
74
  * @param {ModelManager} modelManager the input model manager
75
- * @param {*} decoratorCommandSet the DecoratorCommandSet object
75
+ * @param {*} decoratorCommandSet the DecoratorCommandSet object, or an array of DecoratorCommandSet objects
76
76
  * @param {object} [options] - decorator models options
77
77
  * @param {boolean} [options.validate] - validate that decorator command set is valid
78
78
  * with respect to to decorator command set model
@@ -14,11 +14,11 @@ export = Relationship;
14
14
  */
15
15
  declare class Relationship extends Identifiable {
16
16
  /**
17
- * Contructs a Relationship instance from a URI representation (created using toURI).
17
+ * Constructs a Relationship instance from a URI representation (created using toURI).
18
18
  * @param {ModelManager} modelManager - the model manager to bind the relationship to
19
19
  * @param {String} uriAsString - the URI as a string, generated using Identifiable.toURI()
20
- * @param {String} [defaultNamespace] - default namespace to use for backwards compatability
21
- * @param {String} [defaultType] - default type to use for backwards compatability
20
+ * @param {String} [defaultNamespace] - default namespace to use for backwards compatibility
21
+ * @param {String} [defaultType] - default type to use for backwards compatibility
22
22
  * @return {Relationship} the relationship
23
23
  */
24
24
  static fromURI(modelManager: ModelManager, uriAsString: string, defaultNamespace?: string, defaultType?: string): Relationship;
@@ -88,7 +88,7 @@ declare class Typed {
88
88
  */
89
89
  instanceOf(fqt: string): boolean;
90
90
  /**
91
- * Overriden to prevent people accidentally converting a resource to JSON
91
+ * Overridden to prevent people accidentally converting a resource to JSON
92
92
  * without using the Serializer.
93
93
  * @protected
94
94
  */
@@ -68,7 +68,7 @@ declare class ObjectValidator {
68
68
  private static reportAbstractClass;
69
69
  /**
70
70
  * Throw a validation exception for an abstract class
71
- * @param {string} resourceId - the id of the resouce being validated
71
+ * @param {string} resourceId - the id of the resource being validated
72
72
  * @param {string} propertyName - the name of the property that is not declared
73
73
  * @param {string} fullyQualifiedTypeName - the fully qualified type being validated
74
74
  * @throws {ValidationException} the validation exception
@@ -77,7 +77,7 @@ declare class ObjectValidator {
77
77
  private static reportUndeclaredField;
78
78
  /**
79
79
  * Throw a validation exception for an invalid field assignment
80
- * @param {string} resourceId - the id of the resouce being validated
80
+ * @param {string} resourceId - the id of the resource being validated
81
81
  * @param {string} propName - the name of the property that is being assigned
82
82
  * @param {*} obj - the Field
83
83
  * @param {Field} field - the Field
@@ -75,7 +75,7 @@ declare class ResourceValidator {
75
75
  private static reportAbstractClass;
76
76
  /**
77
77
  * Throw a validation exception for an abstract class
78
- * @param {string} resourceId - the id of the resouce being validated
78
+ * @param {string} resourceId - the id of the resource being validated
79
79
  * @param {string} propertyName - the name of the property that is not declared
80
80
  * @param {string} fullyQualifiedTypeName - the fully qualified type being validated
81
81
  * @throws {ValidationException} the validation exception
@@ -84,7 +84,7 @@ declare class ResourceValidator {
84
84
  private static reportUndeclaredField;
85
85
  /**
86
86
  * Throw a validation exception for an invalid field assignment
87
- * @param {string} resourceId - the id of the resouce being validated
87
+ * @param {string} resourceId - the id of the resource being validated
88
88
  * @param {string} propName - the name of the property that is being assigned
89
89
  * @param {*} obj - the Field
90
90
  * @param {Field} field - the Field