@accordproject/concerto-core 2.0.0-alpha.2 → 2.0.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.
Files changed (68) hide show
  1. package/changelog.txt +2 -1
  2. package/index.js +73 -33
  3. package/lib/basemodelmanager.js +30 -4
  4. package/lib/decoratormanager.js +118 -0
  5. package/lib/factory.js +9 -1
  6. package/lib/introspect/assetdeclaration.js +8 -0
  7. package/lib/introspect/classdeclaration.js +10 -1
  8. package/lib/introspect/conceptdeclaration.js +8 -0
  9. package/lib/introspect/decorated.js +11 -2
  10. package/lib/introspect/decorator.js +9 -0
  11. package/lib/introspect/decoratorfactory.js +10 -0
  12. package/lib/introspect/enumdeclaration.js +8 -0
  13. package/lib/introspect/enumvaluedeclaration.js +8 -0
  14. package/lib/introspect/eventdeclaration.js +8 -0
  15. package/lib/introspect/field.js +8 -0
  16. package/lib/introspect/identifieddeclaration.js +8 -0
  17. package/lib/introspect/illegalmodelexception.js +9 -1
  18. package/lib/introspect/introspector.js +9 -0
  19. package/lib/introspect/metamodel.js +1 -1
  20. package/lib/introspect/modelfile.js +9 -0
  21. package/lib/introspect/numbervalidator.js +8 -0
  22. package/lib/introspect/participantdeclaration.js +8 -0
  23. package/lib/introspect/property.js +9 -1
  24. package/lib/introspect/relationshipdeclaration.js +9 -1
  25. package/lib/introspect/stringvalidator.js +8 -0
  26. package/lib/introspect/transactiondeclaration.js +8 -0
  27. package/lib/introspect/validator.js +8 -0
  28. package/lib/model/identifiable.js +1 -1
  29. package/lib/model/relationship.js +8 -0
  30. package/lib/model/typed.js +11 -2
  31. package/lib/rootmodel.js +3 -1
  32. package/lib/securityexception.js +1 -1
  33. package/lib/serializer.js +11 -1
  34. package/lib/typenotfoundexception.js +2 -2
  35. package/messages/en.json +48 -48
  36. package/package.json +7 -5
  37. package/types/index.d.ts +39 -33
  38. package/types/lib/basemodelmanager.d.ts +295 -0
  39. package/types/lib/decoratormanager.d.ts +41 -0
  40. package/types/lib/factory.d.ts +1 -0
  41. package/types/lib/introspect/assetdeclaration.d.ts +7 -0
  42. package/types/lib/introspect/classdeclaration.d.ts +11 -0
  43. package/types/lib/introspect/conceptdeclaration.d.ts +6 -0
  44. package/types/lib/introspect/decorated.d.ts +4 -2
  45. package/types/lib/introspect/decorator.d.ts +5 -3
  46. package/types/lib/introspect/decoratorfactory.d.ts +4 -1
  47. package/types/lib/introspect/enumdeclaration.d.ts +6 -0
  48. package/types/lib/introspect/eventdeclaration.d.ts +7 -0
  49. package/types/lib/introspect/illegalmodelexception.d.ts +3 -2
  50. package/types/lib/introspect/introspector.d.ts +2 -0
  51. package/types/lib/introspect/metamodel.d.ts +16 -50
  52. package/types/lib/introspect/modelfile.d.ts +2 -0
  53. package/types/lib/introspect/participantdeclaration.d.ts +7 -0
  54. package/types/lib/introspect/property.d.ts +8 -0
  55. package/types/lib/introspect/transactiondeclaration.d.ts +7 -0
  56. package/types/lib/introspect/validator.d.ts +1 -0
  57. package/types/lib/model/identifiable.d.ts +2 -2
  58. package/types/lib/model/relationship.d.ts +17 -0
  59. package/types/lib/model/resource.d.ts +7 -0
  60. package/types/lib/model/typed.d.ts +6 -4
  61. package/types/lib/modelmanager.d.ts +8 -230
  62. package/types/lib/rootmodel.d.ts +4 -0
  63. package/types/lib/securityexception.d.ts +2 -2
  64. package/types/lib/serializer/validationexception.d.ts +3 -2
  65. package/types/lib/serializer.d.ts +3 -0
  66. package/types/lib/typenotfoundexception.d.ts +4 -4
  67. package/umd/concerto.js +1 -1
  68. package/umd/concerto.js.LICENSE.txt +1 -1
@@ -22,6 +22,23 @@ declare class Relationship extends Identifiable {
22
22
  * @return {Relationship} the relationship
23
23
  */
24
24
  static fromURI(modelManager: ModelManager, uriAsString: string, defaultNamespace?: string, defaultType?: string): Relationship;
25
+ /**
26
+ * Create an asset. Use the Factory to create instances.
27
+ * <p>
28
+ * <strong>Note: Only to be called by framework code. Applications should
29
+ * retrieve instances from {@link Factory}</strong>
30
+ * </p>
31
+ *
32
+ * @param {ModelManager} modelManager - The ModelManager for this instance
33
+ * @param {ClassDeclaration} classDeclaration - The class declaration for this instance.
34
+ * @param {string} ns - The namespace this instance.
35
+ * @param {string} type - The type this instance.
36
+ * @param {string} id - The identifier of this instance.
37
+ * @param {string} timestamp - The timestamp of this instance
38
+ * @private
39
+ */
40
+ private constructor();
25
41
  $class: string;
26
42
  }
27
43
  import Identifiable = require("./identifiable");
44
+ import ModelManager = require("../modelmanager");
@@ -31,5 +31,12 @@ declare class Resource extends Identifiable {
31
31
  * false if not.
32
32
  */
33
33
  isIdentifiable(): boolean;
34
+ /**
35
+ * Serialize this resource into a JavaScript object suitable for serialization to JSON,
36
+ * using the default options for the serializer. If you need to set additional options
37
+ * for the serializer, use the {@link Serializer#toJSON} method instead.
38
+ * @return {Object} A JavaScript object suitable for serialization to JSON.
39
+ */
40
+ toJSON(): any;
34
41
  }
35
42
  import Identifiable = require("./identifiable");
@@ -19,9 +19,9 @@ declare class Typed {
19
19
  * @param {ClassDeclaration} classDeclaration - The class declaration for this instance.
20
20
  * @param {string} ns - The namespace this instance.
21
21
  * @param {string} type - The type this instance.
22
- * @private
22
+ * @protected
23
23
  */
24
- private constructor();
24
+ protected constructor();
25
25
  $modelManager: ModelManager;
26
26
  $classDeclaration: ClassDeclaration;
27
27
  $namespace: string;
@@ -90,7 +90,9 @@ declare class Typed {
90
90
  /**
91
91
  * Overriden to prevent people accidentally converting a resource to JSON
92
92
  * without using the Serializer.
93
- * @private
93
+ * @protected
94
94
  */
95
- private toJSON;
95
+ protected toJSON(): void;
96
96
  }
97
+ import ModelManager = require("../modelmanager");
98
+ import ClassDeclaration = require("../introspect/classdeclaration");
@@ -1,6 +1,6 @@
1
1
  export = ModelManager;
2
2
  /**
3
- * Manages the Concerto model files.
3
+ * Manages the Concerto model files in CTO format.
4
4
  *
5
5
  * The structure of {@link Resource}s (Assets, Transactions, Participants) is modelled
6
6
  * in a set of Concerto files. The contents of these files are managed
@@ -10,246 +10,24 @@ export = ModelManager;
10
10
  * Concerto applications load their Concerto files and then call the {@link ModelManager#addModelFile addModelFile}
11
11
  * method to register the Concerto file(s) with the ModelManager.
12
12
  *
13
- * Use the {@link Concerto} class to validate instances.
14
- *
15
13
  * @memberof module:concerto-core
16
14
  */
17
- declare class ModelManager {
15
+ declare class ModelManager extends BaseModelManager {
18
16
  /**
19
17
  * Create the ModelManager.
20
18
  * @constructor
21
19
  * @param {object} [options] - Serializer options
22
20
  */
23
21
  constructor(options?: object);
24
- modelFiles: {};
25
- factory: Factory;
26
- serializer: Serializer;
27
- decoratorFactories: any[];
28
- /**
29
- * Returns true
30
- * @returns {boolean} true
31
- */
32
- isModelManager(): boolean;
33
- /**
34
- * Adds root types
35
- * @private
36
- */
37
- private addRootModel;
38
22
  /**
39
- * Visitor design pattern
40
- * @param {Object} visitor - the visitor
41
- * @param {Object} parameters - the parameter
42
- * @return {Object} the result of visiting or null
43
- */
44
- accept(visitor: any, parameters: any): any;
45
- /**
46
- * Validates a Concerto file (as a string) to the ModelManager.
47
- * Concerto files have a single namespace.
48
- *
49
- * Note that if there are dependencies between multiple files the files
50
- * must be added in dependency order, or the addModelFiles method can be
51
- * used to add a set of files irrespective of dependencies.
52
- * @param {string|ModelFile} modelFile - The Concerto file as a string
53
- * @param {string} [fileName] - a file name to associate with the model file
54
- * @throws {IllegalModelException}
55
- */
56
- validateModelFile(modelFile: string | ModelFile, fileName?: string): void;
57
- /**
58
- * Throws an error with details about the existing namespace.
59
- * @param {ModelFile} modelFile The model file that is trying to declare an existing namespace
60
- * @private
61
- */
62
- private _throwAlreadyExists;
63
- /**
64
- * Adds a Concerto file (as a string) to the ModelManager.
65
- * Concerto files have a single namespace. If a Concerto file with the
66
- * same namespace has already been added to the ModelManager then it
67
- * will be replaced.
68
- * Note that if there are dependencies between multiple files the files
69
- * must be added in dependency order, or the addModelFiles method can be
70
- * used to add a set of files irrespective of dependencies.
71
- * @param {string|ModelFile} modelFile - Model as a string or object
72
- * @param {string} fileName - an optional file name to associate with the model file
23
+ * Adds a model in CTO format to the ModelManager.
24
+ * This is a convenience function equivalent to `addModel` but useful since it avoids having to copy the input CTO.
25
+ * @param {string} cto - a cto string
26
+ * @param {string} [fileName] - an optional file name to associate with the model file
73
27
  * @param {boolean} [disableValidation] - If true then the model files are not validated
74
28
  * @throws {IllegalModelException}
75
29
  * @return {Object} The newly added model file (internal).
76
30
  */
77
- addModelFile(modelFile: string | ModelFile, fileName: string, disableValidation?: boolean): any;
78
- /**
79
- * Updates a Concerto file (as a string) on the ModelManager.
80
- * Concerto files have a single namespace. If a Concerto file with the
81
- * same namespace has already been added to the ModelManager then it
82
- * will be replaced.
83
- * @param {string|ModelFile} modelFile - Model as a string or object
84
- * @param {string} [fileName] - a file name to associate with the model file
85
- * @param {boolean} [disableValidation] - If true then the model files are not validated
86
- * @throws {IllegalModelException}
87
- * @returns {Object} The newly added model file (internal).
88
- */
89
- updateModelFile(modelFile: string | ModelFile, fileName?: string, disableValidation?: boolean): any;
90
- /**
91
- * Remove the Concerto file for a given namespace
92
- * @param {string} namespace - The namespace of the model file to delete.
93
- */
94
- deleteModelFile(namespace: string): void;
95
- /**
96
- * Add a set of Concerto files to the model manager.
97
- * @param {string[]|ModelFile[]} modelFiles - An array of models as strings or ModelFile objects.
98
- * @param {string[]} [fileNames] - A array of file names to associate with the model files
99
- * @param {boolean} [disableValidation] - If true then the model files are not validated
100
- * @returns {Object[]} The newly added model files (internal).
101
- */
102
- addModelFiles(modelFiles: string[] | ModelFile[], fileNames?: string[], disableValidation?: boolean): any[];
103
- /**
104
- * Validates all models files in this model manager
105
- */
106
- validateModelFiles(): void;
107
- /**
108
- * Downloads all ModelFiles that are external dependencies and adds or
109
- * updates them in this ModelManager.
110
- * @param {Object} [options] - Options object passed to ModelFileLoaders
111
- * @param {FileDownloader} [fileDownloader] - an optional FileDownloader
112
- * @throws {IllegalModelException} if the models fail validation
113
- * @return {Promise} a promise when the download and update operation is completed.
114
- */
115
- updateExternalModels(options?: any, fileDownloader?: typeof import("@accordproject/concerto-util/types/lib/filedownloader")): Promise<any>;
116
- /**
117
- * Write all models in this model manager to the specified path in the file system
118
- *
119
- * @param {string} path to a local directory
120
- * @param {Object} [options] - Options object
121
- * @param {boolean} options.includeExternalModels -
122
- * If true, external models are written to the file system. Defaults to true
123
- */
124
- writeModelsToFileSystem(path: string, options?: {
125
- includeExternalModels: boolean;
126
- }): void;
127
- /**
128
- * Get the array of model file instances
129
- * @param {Boolean} [includeConcertoNamespace] - whether to include the concerto namespace
130
- * (default to false)
131
- * @return {ModelFile[]} The ModelFiles registered
132
- * @private
133
- */
134
- private getModelFiles;
135
- /**
136
- * Gets all the Concerto models
137
- * @param {Object} [options] - Options object
138
- * @param {boolean} options.includeExternalModels -
139
- * If true, external models are written to the file system. Defaults to true
140
- * @return {Array<{name:string, content:string}>} the name and content of each CTO file
141
- */
142
- getModels(options?: {
143
- includeExternalModels: boolean;
144
- }): Array<{
145
- name: string;
146
- content: string;
147
- }>;
148
- /**
149
- * Check that the type is valid and returns the FQN of the type.
150
- * @param {string} context - error reporting context
151
- * @param {string} type - fully qualified type name
152
- * @return {string} - the resolved type name (fully qualified)
153
- * @throws {IllegalModelException} - if the type is not defined
154
- * @private
155
- */
156
- private resolveType;
157
- /**
158
- * Remove all registered Concerto files
159
- */
160
- clearModelFiles(): void;
161
- /**
162
- * Get the ModelFile associated with a namespace
163
- *
164
- * @param {string} namespace - the namespace containing the ModelFile
165
- * @return {ModelFile} registered ModelFile for the namespace or null
166
- */
167
- getModelFile(namespace: string): ModelFile;
168
- /**
169
- * Get the ModelFile associated with a file name
170
- *
171
- * @param {string} fileName - the fileName associated with the ModelFile
172
- * @return {ModelFile} registered ModelFile for the namespace or null
173
- * @private
174
- */
175
- private getModelFileByFileName;
176
- /**
177
- * Get the namespaces registered with the ModelManager.
178
- * @return {string[]} namespaces - the namespaces that have been registered.
179
- */
180
- getNamespaces(): string[];
181
- /**
182
- * Look up a type in all registered namespaces.
183
- *
184
- * @param {string} qualifiedName - fully qualified type name.
185
- * @return {ClassDeclaration} - the class declaration for the specified type.
186
- * @throws {TypeNotFoundException} - if the type cannot be found or is a primitive type.
187
- */
188
- getType(qualifiedName: string): ClassDeclaration;
189
- /**
190
- * Get the AssetDeclarations defined in this model manager
191
- * @return {AssetDeclaration[]} the AssetDeclarations defined in the model manager
192
- */
193
- getAssetDeclarations(): AssetDeclaration[];
194
- /**
195
- * Get the TransactionDeclarations defined in this model manager
196
- * @return {TransactionDeclaration[]} the TransactionDeclarations defined in the model manager
197
- */
198
- getTransactionDeclarations(): TransactionDeclaration[];
199
- /**
200
- * Get the EventDeclarations defined in this model manager
201
- * @return {EventDeclaration[]} the EventDeclaration defined in the model manager
202
- */
203
- getEventDeclarations(): EventDeclaration[];
204
- /**
205
- * Get the ParticipantDeclarations defined in this model manager
206
- * @return {ParticipantDeclaration[]} the ParticipantDeclaration defined in the model manager
207
- */
208
- getParticipantDeclarations(): ParticipantDeclaration[];
209
- /**
210
- * Get the EnumDeclarations defined in this model manager
211
- * @return {EnumDeclaration[]} the EnumDeclaration defined in the model manager
212
- */
213
- getEnumDeclarations(): EnumDeclaration[];
214
- /**
215
- * Get the Concepts defined in this model manager
216
- * @return {ConceptDeclaration[]} the ConceptDeclaration defined in the model manager
217
- */
218
- getConceptDeclarations(): ConceptDeclaration[];
219
- /**
220
- * Get a factory for creating new instances of types defined in this model manager.
221
- * @return {Factory} A factory for creating new instances of types defined in this model manager.
222
- */
223
- getFactory(): Factory;
224
- /**
225
- * Get a serializer for serializing instances of types defined in this model manager.
226
- * @return {Serializer} A serializer for serializing instances of types defined in this model manager.
227
- */
228
- getSerializer(): Serializer;
229
- /**
230
- * Get the decorator factories for this model manager.
231
- * @return {DecoratorFactory[]} The decorator factories for this model manager.
232
- */
233
- getDecoratorFactories(): DecoratorFactory[];
234
- /**
235
- * Add a decorator factory to this model manager.
236
- * @param {DecoratorFactory} factory The decorator factory to add to this model manager.
237
- */
238
- addDecoratorFactory(factory: DecoratorFactory): void;
239
- /**
240
- * Checks if this fully qualified type name is derived from another.
241
- * @param {string} fqt1 The fully qualified type name to check.
242
- * @param {string} fqt2 The fully qualified type name it is may be derived from.
243
- * @returns {boolean} True if this instance is an instance of the specified fully
244
- * qualified type name, false otherwise.
245
- */
246
- derivesFrom(fqt1: string, fqt2: string): boolean;
247
- /**
248
- * Get the full metamodel for a modelmanager
249
- * @returns {*} the metamodel
250
- */
251
- getMetaModel(): any;
31
+ addCTOModel(cto: string, fileName?: string, disableValidation?: boolean): any;
252
32
  }
253
- import Factory = require("./factory");
254
- import Serializer = require("./serializer");
255
- import ModelFile = require("./introspect/modelfile");
33
+ import BaseModelManager = require("./basemodelmanager");
@@ -0,0 +1,4 @@
1
+ export const rootModelFile: "concerto.cto";
2
+ export const rootModelCto: "namespace concerto\nabstract concept Concept {}\nabstract concept Asset identified {}\nabstract concept Participant identified {}\nabstract concept Transaction {}\nabstract concept Event {}\n";
3
+ /** @type unknown */
4
+ export const rootModelAst: unknown;
@@ -1,5 +1,4 @@
1
1
  export = SecurityException;
2
- declare const SecurityException_base: typeof import("@accordproject/concerto-cto/types/lib/baseexception");
3
2
  /**
4
3
  * Class representing a security exception
5
4
  * @extends BaseException
@@ -7,10 +6,11 @@ declare const SecurityException_base: typeof import("@accordproject/concerto-cto
7
6
  * @class
8
7
  * @memberof module:concerto-core
9
8
  */
10
- declare class SecurityException extends SecurityException_base {
9
+ declare class SecurityException extends BaseException {
11
10
  /**
12
11
  * Create the SecurityException.
13
12
  * @param {string} message - The exception message.
14
13
  */
15
14
  constructor(message: string);
16
15
  }
16
+ import { BaseException } from "@accordproject/concerto-util";
@@ -1,5 +1,4 @@
1
1
  export = ValidationException;
2
- declare const ValidationException_base: typeof import("@accordproject/concerto-cto/types/lib/baseexception");
3
2
  /**
4
3
  * Exception thrown when a resource fails to model against the model
5
4
  * @extends BaseException
@@ -8,5 +7,7 @@ declare const ValidationException_base: typeof import("@accordproject/concerto-c
8
7
  * @memberof module:concerto-core
9
8
  * @private
10
9
  */
11
- declare class ValidationException extends ValidationException_base {
10
+ declare class ValidationException extends BaseException {
12
11
  }
12
+ import BaseException_1 = require("@accordproject/concerto-util/types/lib/baseexception");
13
+ import BaseException = BaseException_1.BaseException;
@@ -75,3 +75,6 @@ declare class Serializer {
75
75
  utcOffset?: number;
76
76
  }): Resource;
77
77
  }
78
+ import Factory = require("./factory");
79
+ import ModelManager = require("./modelmanager");
80
+ import Resource = require("./model/resource");
@@ -1,5 +1,4 @@
1
1
  export = TypeNotFoundException;
2
- declare const TypeNotFoundException_base: typeof import("@accordproject/concerto-cto/types/lib/baseexception");
3
2
  /**
4
3
  * Error thrown when a Concerto type does not exist.
5
4
  * @extends BaseException
@@ -7,15 +6,15 @@ declare const TypeNotFoundException_base: typeof import("@accordproject/concerto
7
6
  * @class
8
7
  * @memberof module:concerto-core
9
8
  */
10
- declare class TypeNotFoundException extends TypeNotFoundException_base {
9
+ declare class TypeNotFoundException extends BaseException {
11
10
  /**
12
11
  * Constructor. If the optional 'message' argument is not supplied, it will be set to a default value that
13
12
  * includes the type name.
14
13
  * @param {string} typeName - fully qualified type name.
15
- * @param {string} [message] - error message.
14
+ * @param {string|undefined} message - error message.
16
15
  * @param {string} component - the optional component which throws this error
17
16
  */
18
- constructor(typeName: string, message?: string, component: string);
17
+ constructor(typeName: string, message: string | undefined, component: string);
19
18
  typeName: string;
20
19
  /**
21
20
  * Get the name of the type that was not found.
@@ -23,3 +22,4 @@ declare class TypeNotFoundException extends TypeNotFoundException_base {
23
22
  */
24
23
  getTypeName(): string;
25
24
  }
25
+ import { BaseException } from "@accordproject/concerto-util";