UNPKG

16.7 kBTypeScriptView Raw
1declare module '@accordproject/concerto-core' {
2 // Exceptions
3 interface FileLocation {
4 start: {
5 line: string;
6 column: string;
7 }
8 end: {
9 line: string;
10 column: string;
11 }
12 }
13
14 export class BaseException extends Error {
15 constructor(message: string, component?: string);
16 }
17
18 export class BaseFileException extends BaseException {
19 constructor(message: string, fileLocation?: string, fullMessage?: string, fileName?: string, component?: string);
20 getFileLocation(): string | null;
21 getShortMessage(): string;
22 getFileName(): string | null;
23 }
24
25 export class ParseException extends BaseFileException {
26 constructor(message: string, fileLocation?: string, fileName?: string, fullMessageOverride?: string, component?: string);
27 }
28
29 export class SecurityException extends BaseException {
30 constructor(message: string);
31 }
32
33 export class IllegalModelException extends BaseFileException {
34 constructor(message: string, modelFile?: ModelFile, fileLocation?: FileLocation, component?: string);
35 getModelFile(): ModelFile | null;
36 }
37
38 export class TypeNotFoundException extends BaseException {
39 constructor(typeName: string, message?: string, component?: string);
40 getTypeName(): string;
41 }
42
43 // Decorated
44 class Decorated {
45 constructor(modelFile: ModelFile, ast: string);
46 getModelFile(): ModelFile;
47 private accept(visitor: any, parameters: any): any;
48 private process(): void;
49 private validate(): void;
50 getDecorators(): Decorator[];
51 getDecorator(name: string): Decorator | null;
52 }
53
54 export class Decorator {
55 constructor(parent: ClassDeclaration | Property, ast: any);
56 private accept(visitor: any, parameters: any): any;
57 getParent(): ClassDeclaration | Property;
58 private process(): void;
59 private validate(): void;
60 getName(): string;
61 getArguments(): any[];
62 }
63
64 export abstract class DecoratorFactory {
65 abstract newDecorator(parent: ClassDeclaration | Property, ast: any): Decorator;
66 }
67
68 // ClassDeclarations
69 export abstract class ClassDeclaration extends Decorated {
70 constructor(modelFile: ModelFile, ast: any);
71 private process(): void;
72 private addTimestampField(): void;
73 private addIdentifierField(): void;
74 _resolveSuperType(): ClassDeclaration | null;
75 private validate(): void;
76 isAbstract(): boolean;
77 isEnum(): boolean;
78 isConcept(): boolean;
79 isEvent(): boolean;
80 getName(): string;
81 getNamespace(): string;
82 getFullyQualifiedName(): string;
83 isIdentified(): boolean;
84 isSystemIdentified(): boolean;
85 isExplicitlyIdentified(): boolean;
86 getIdentifierFieldName(): string | null;
87 getOwnProperty(name: string): Property | null;
88 getOwnProperties(): Property[];
89 getSuperType(): string | null;
90 getSuperTypeDeclaration(): ClassDeclaration | null;
91 getAssignableClassDeclarations(): ClassDeclaration[];
92 getAllSuperTypeDeclarations(): ClassDeclaration[];
93 getProperty(name: string): Property | null;
94 getProperties(): Property[];
95 getNestedProperty(propertyPath: string): Property;
96 toString(): string;
97 static [Symbol.hasInstance](object: any): boolean;
98 }
99
100 export class IdentifiedDeclaration extends ClassDeclaration { }
101
102 export class AssetDeclaration extends IdentifiedDeclaration { }
103
104 export class ConceptDeclaration extends ClassDeclaration { }
105
106 export class EnumDeclaration extends ClassDeclaration { }
107
108 export class EventDeclaration extends IdentifiedDeclaration { }
109
110 export class ParticipantDeclaration extends IdentifiedDeclaration { }
111
112 export class TransactionDeclaration extends IdentifiedDeclaration { }
113
114 // Properties
115 export class Property extends Decorated {
116 constructor(parent: ClassDeclaration, ast: any);
117 getParent(): ClassDeclaration;
118 private process(): void;
119 private validate(classDecl?: ClassDeclaration): void;
120 getName(): string;
121 getType(): string;
122 isOptional(): boolean;
123 getFullyQualifiedTypeName(): string;
124 getFullyQualifiedName(): string;
125 getNamespace(): string;
126 isArray(): boolean;
127 isTypeEnum(): boolean;
128 isPrimitive(): boolean;
129 static [Symbol.hasInstance](object: any): boolean;
130 }
131
132 export class Field extends Property {
133 getValidator(): string | null;
134 getDefaultValue(): string | null;
135 toString(): string;
136 }
137
138 export class EnumValueDeclaration extends Property { }
139
140 export class RelationshipDeclaration extends Property {
141 toString(): string;
142 }
143
144 // Typed
145 export abstract class Typed {
146 constructor(modelManager: ModelManager, classDeclaration: ClassDeclaration, ns: string, type: string);
147 private accept(visitor: any, parameters: any): any;
148 private getModelManager(): ModelManager;
149 getType(): string;
150 getFullyQualifiedType(): string;
151 getNamespace(): string;
152 private getClassDeclaration(): ClassDeclaration;
153 setPropertyValue(propName: string, value: string): void;
154 addArrayValue(propName: string, value: string): void;
155 private assignFieldDefaults(): void;
156 instanceOf(fqt: string): boolean;
157 private toJSON(): any;
158 [propertyName: string]: any;
159 }
160
161 // Identifiables
162 abstract class Identifiable extends Typed {
163 constructor(modelManager: ModelManager, classDeclaration: ClassDeclaration, ns: string, type: string, id: string, timestamp: string);
164 getTimestamp(): string;
165 getIdentifier(): string;
166 setIdentifier(id: string): void;
167 getFullyQualifiedIdentifier(): string;
168 toString(): string;
169 isRelationship(): boolean;
170 isResource(): boolean;
171 toURI(): string;
172 }
173
174 export class Relationship extends Identifiable {
175 static fromURI(modelManager: ModelManager, uriAsstring: string, defaultNamespace?: string, defaultType?: string): Relationship;
176 }
177
178 export class Resource extends Identifiable {
179 isConcept(): boolean;
180 isIdentifiable(): boolean;
181 }
182
183 // Writers
184 export class Writer {
185 constructor();
186 writeBeforeLine(tabs: number, text: string): void;
187 writeLine(tabs: number, text: string): void;
188 getLineCount(): number;
189 writeIndented(tabs: number, text: string): void;
190 write(msg: string): void;
191 getBuffer(): string;
192 clearBuffer(): void;
193 }
194
195 // Factory
196 interface NewResourceOptions {
197 disableValidation?: boolean;
198 generate?: string;
199 includeOptionalFields?: boolean;
200 }
201
202 interface NewConceptOptions {
203 disableValidation?: boolean;
204 generate?: string;
205 includeOptionalFields?: boolean;
206 }
207
208 interface NewTransactionOptions {
209 generate?: string;
210 includeOptionalFields?: boolean;
211 }
212
213 interface NewEventOptions {
214 generate?: string;
215 includeOptionalFields?: boolean;
216 }
217
218 export class Factory {
219 static newId(): string;
220 constructor(modelManager: ModelManager);
221 newResource(ns: string, type: string, id: string, options?: NewResourceOptions): Resource;
222 newConcept(ns: string, type: string, id: string, options?: NewConceptOptions): Resource;
223 newRelationship(ns: string, type: string, id: string): Relationship;
224 newTransaction(ns: string, type: string, id?: string, options?: NewTransactionOptions): Resource;
225 newEvent(ns: string, type: string, id?: string, options?: NewEventOptions): Resource;
226 private initializeNewObject(newObject: Typed, classDeclaration: ClassDeclaration, clientOptions: any): void;
227 private parseGenerateOptions(clientOptions: any): any;
228 static [Symbol.hasInstance](object: any): boolean;
229 }
230
231 // Globalize
232 export function Globalize(locale: string): any;
233
234 export namespace Globalize {
235 function messageFormatter(message: string): any;
236 function formatMessage(message: string): any;
237 }
238
239 // Introspector
240 export class Introspector {
241 constructor(modelManager: ModelManager);
242 private accept(visitor: any, parameters: any): any;
243 getClassDeclarations(): ClassDeclaration[];
244 getClassDeclaration(fullyQualifiedTypeName: string): ClassDeclaration;
245 private getModelManager(): ModelManager;
246 }
247
248 // ModelFile
249 export class ModelFile {
250 constructor(modelManager: ModelManager, definitions: string, fileName?: string);
251 private fromAst(ast: any): void;
252 isSystemModelFile(): boolean;
253 isExternal(): boolean;
254 private getImportURI(namespace: string): string | null;
255 private getExternalImports(): any;
256 private accept(visitor: any, parameters: any): any;
257 getModelManager(): ModelManager;
258 getImports(): string[];
259 private validate(): void;
260 private resolveType(context: string, type: string, fileLocation: FileLocation): void;
261 private isLocalType(type: string): boolean;
262 private isImportedType(type: string): boolean;
263 private resolveImport(type: string): string;
264 isDefined(type: string): boolean;
265 private getType(type: string): string | ClassDeclaration;
266 private getFullyQualifiedTypeName(type: string): string;
267 getLocalType(type: string): ClassDeclaration | null;
268 getAssetDeclaration(name: string): AssetDeclaration | null;
269 getTransactionDeclaration(name: string): TransactionDeclaration | null;
270 getEventDeclaration(name: string): EventDeclaration | null;
271 getParticipantDeclaration(name: string): ParticipantDeclaration | null;
272 getNamespace(): string;
273 getName(): string;
274 getAssetDeclarations(): AssetDeclaration[];
275 getTransactionDeclarations(): TransactionDeclaration[];
276 getEventDeclarations(): EventDeclaration[];
277 getParticipantDeclarations(): ParticipantDeclaration[];
278 getConceptDeclarations(): ConceptDeclaration[];
279 getEnumDeclarations(): EnumDeclaration[];
280 getDeclarations(type: (...params: any[]) => any): ClassDeclaration[];
281 getAllDeclarations(): ClassDeclaration[];
282 getDefinitions(): string;
283 getConcertoVersion(): string;
284 static [Symbol.hasInstance](object: any): boolean;
285 }
286
287 // ModelManager
288 interface IncludeModelsOptions {
289 includeExternalModels: boolean;
290 includeSystemModels: boolean;
291 }
292
293 export class ModelManager {
294 constructor(options?: any);
295 private addRootModel(): void;
296 accept(visitor: any, parameters: any): any;
297 validateModelFile(modelFile: string, fileName?: string): void;
298 private _throwAlreadyExists(modelFile: ModelFile): void;
299 addModelFile(modelFile: string, fileName?: string, disableValidation?: boolean): any;
300 updateModelFile(modelFile: string, fileName?: string, disableValidation?: boolean): any;
301 deleteModelFile(namespace: string): void;
302 addModelFiles(modelFiles: (string|ModelFile)[], fileNames?: string[], disableValidation?: boolean): any[];
303 validateModelFiles(): void;
304 updateExternalModels(options?: any, modelFileDownloader?: ModelFileDownloader): Promise<ModelFile[]>;
305 writeModelsToFileSystem(path: string, options?: IncludeModelsOptions): void;
306 private getModelFiles(): ModelFile[];
307 private getSystemModelFiles(): ModelFile[];
308 getModels(options?: IncludeModelsOptions): { name: string; content: string }[];
309 private resolveType(context: string, type: string): string;
310 clearModelFiles(): void;
311 getModelFile(namespace: string): ModelFile | null;
312 private getModelFileByFileName(fileName: string): ModelFile | null;
313 getNamespaces(): string[];
314 getType(qualifiedName: string): ClassDeclaration;
315 getSystemTypes(): ClassDeclaration[];
316 getAssetDeclarations(): AssetDeclaration[];
317 getTransactionDeclarations(): TransactionDeclaration[];
318 getEventDeclarations(): EventDeclaration[];
319 getParticipantDeclarations(): ParticipantDeclaration[];
320 getEnumDeclarations(): EnumDeclaration[];
321 getConceptDeclarations(): ConceptDeclaration[];
322 getFactory(): Factory;
323 getSerializer(): Serializer;
324 getDecoratorFactories(): DecoratorFactory[];
325 addDecoratorFactory(factory: DecoratorFactory): void;
326 derivesFrom(fqt1: string, fqt2: string): boolean;
327 static [Symbol.hasInstance](object: any): boolean;
328 }
329
330 // Serializer
331 interface SerializerToJSONOptions {
332 validate?: boolean;
333 convertResourcesToRelationships?: boolean;
334 permitResourcesForRelationships?: boolean;
335 deduplicateResources?: boolean;
336 convertResourcesToId?: boolean;
337 utcOffset: number;
338 }
339
340 interface SerializerFromJSONOptions {
341 acceptResourcesForRelationships: boolean;
342 validate: boolean;
343 utcOffset: number;
344 }
345
346 export class Serializer {
347 constructor(factory: Factory, modelManager: ModelManager, options?: any);
348 setDefaultOptions(newDefaultOptions: any): void;
349 toJSON(resource: Resource, options?: SerializerToJSONOptions): any;
350 fromJSON(jsonObject: any, options?: SerializerFromJSONOptions): Resource;
351 static [Symbol.hasInstance](object: any): boolean;
352 }
353
354 // ModelUtil
355 export class ModelUtil {
356 private static getShortName(fqn: string): string;
357 private static isWildcardName(fqn: string): boolean;
358 private static isRecursiveWildcardName(fqn: string): boolean;
359 private static isMatchingType(type: Typed, fqn: string): boolean;
360 private static getNamespace(fqn: string): string;
361 private static isPrimitiveType(typeName: string): boolean;
362 private static isAssignableTo(modelFile: ModelFile, typeName: string, property: Property): boolean;
363 private static capitalizeFirstLetter(string: string): string;
364 private static isEnum(field: Field): boolean;
365 static getFullyQualifiedName(namespace: string, type: string): string;
366 }
367
368 // ModelFileLoaders
369 interface ModelFileLoader {
370 accepts(url: string): boolean;
371 load(url: string, options: any): Promise<ModelFile>;
372 }
373
374 class CompositeModelFileLoader implements ModelFileLoader {
375 constructor();
376 addModelFileLoader(modelFileLoader: ModelFileLoader): void;
377 private getModelFileLoaders(): ModelFileLoader[];
378 clearModelFileLoaders(): void;
379 accepts(url: string): boolean;
380 load(url: string, options: any): Promise<ModelFile>;
381 }
382
383 export class DefaultModelFileLoader extends CompositeModelFileLoader {
384 constructor(modelManager: ModelManager);
385 }
386
387 export class ModelFileDownloader {
388 constructor(modelFileLoader: ModelFileLoader, concurrency: number);
389 downloadExternalDependencies(modelFiles: ModelFile[], options?: any): Promise<ModelFile[]>;
390 runJob(job: any, modelFileLoader: ModelFileLoader): Promise<ModelFile>;
391 }
392
393 // ModelLoader
394 export class ModelLoader {
395 private addModel(modelFileLoader: ModelFileLoader, modelManager: ModelManager, ctoFile: string): ModelManager;
396 static loadModelManager(ctoFiles: string[], options?: any): Promise<ModelManager>;
397 static loadModelManagerFromModelFiles(modelFiles: ModelFile[], fileNames?: string[], options?: any): Promise<ModelManager>;
398 }
399
400 // Logger
401 export class Logger {
402 private static dispatch(level, ...args: any[]): void;
403 private static add(transport: any): void;
404 private static error(...args: any[]): void;
405 private static info(...args: any[]): void;
406 private static log(...args: any[]): void;
407 private static http(...args: any[]): void;
408 private static verbose(...args:any[]): void;
409 private static debug(...args:any[]): void;
410 private static silly(...args:any[]): void;
411 level: string;
412 transports: any[];
413 }
414
415 // DateTimeUtil
416 interface CurrentTime {
417 currentTime: any,
418 utcOffset: number
419 }
420
421 export namespace DateTimeUtil {
422 function setCurrentTime(currentTime?: string, utcOffset?: number): CurrentTime;
423 }
424
425 // TypedStack
426 export class TypedStack {
427 constructor(resource: any);
428 push(obj: any, expectedType: any): void;
429 pop(expectedType: obj): any?;
430 peek(expectedType: obj): any?;
431 clear(): void;
432 }
433
434 // Concerto
435 class Concerto {
436 constructor(modelManager: ModelManager);
437 validate(obj: any, options?: any): void;
438 getModelManager(): ModelManager;
439 isObject(obj: any): boolean;
440 getTypeDeclaration(obj: any): ClassDeclaration;
441 getIdentifier(obj: any): string;
442 isIdentifiable(obj: any): boolean;
443 isRelationship(obj: aby): boolean;
444 setIdentifier(obj: any, id: string): any;
445 getFullyQualifiedIdentifier(obj: any): string;
446 toURI(obj: any): string;
447 fromURI(uri: string): any;
448 getType(obj: any): string;
449 getNamespace(obj: any): string;
450 }
451
452 // MetaModel
453 export namespace MetaModel {
454 const metaModelCto: string;
455 function modelFileToMetaModel(modelFile: ModelFile, validate?: boolean): any;
456 function ctoToMetaModel(model: string, validate?: boolean): any;
457 function ctoToMetaModelAndResolve(modelManager: ModelManager, model: string, validate?: boolean);
458 function ctoFromMetaModel(metaModel: any, validate?: boolean): string;
459 }
460
461 // version
462 export const version: any;
463}