diff --git a/lib/components/inline.js b/lib/components/inline.js index d220c07e..b478592e 100644 --- a/lib/components/inline.js +++ b/lib/components/inline.js @@ -1,4 +1,6 @@ const { SourceFile, Buffer } = require('../file') +const { CSN, TypeResolveInfo } = require('./resolver') +const { Visitor } = require('../visitor') const { docify } = require('./wrappers') /** @@ -11,8 +13,8 @@ class InlineDeclarationResolver { /** * @param {string} name - * @param {import('./resolver').TypeResolveInfo} type - * @param {import('../file').Buffer} buffer + * @param {TypeResolveInfo} type + * @param {Buffer} buffer * @param {string} statementEnd * @protected * @abstract @@ -22,7 +24,7 @@ class InlineDeclarationResolver { /** * Attempts to resolve a type that could reference another type. * @param {any} items - * @param {import('./resolver').TypeResolveInfo} into @see Visitor.resolveType + * @param {TypeResolveInfo} into @see Visitor.resolveType * @param {SourceFile} file temporary file to resolve dummy types into. * @public */ @@ -56,7 +58,7 @@ class InlineDeclarationResolver { /** * Visits a single element in an entity. * @param {string} name name of the element - * @param {import('./resolver').CSN} element CSN data belonging to the the element. + * @param {CSN} element CSN data belonging to the the element. * @param {SourceFile} file the namespace file the surrounding entity is being printed into. * @param {Buffer} [buffer] buffer to add the definition to. If no buffer is passed, the passed file's class buffer is used instead. * @public @@ -84,7 +86,7 @@ class InlineDeclarationResolver { return this.visitor.options.propertiesOptional ? '?:' : ':' } - /** @param {import('../visitor').Visitor} visitor */ + /** @param {Visitor} visitor */ constructor(visitor) { this.visitor = visitor // type resolution might recurse. This indicator is used to determine diff --git a/lib/components/resolver.js b/lib/components/resolver.js index b9290065..c47df5f3 100644 --- a/lib/components/resolver.js +++ b/lib/components/resolver.js @@ -5,9 +5,18 @@ const { Buffer, SourceFile, Path, Library, baseDefinitions } = require("../file" const { deepRequire, createToManyAssociation, createToOneAssociation, createArrayOf, createCompositionOfMany, createCompositionOfOne } = require('./wrappers') const { Visitor } = require("../visitor") const { StructuredInlineDeclarationResolver } = require("./inline") +const { TypeResolveInfo } = require("./resolver") -/** @typedef {{ cardinality?: { max?: '*' | number } }} EntityCSN */ -/** @typedef {{ definitions?: Object }} CSN */ +/** + * @typedef {Object} EntityCSN + * @property {Object} [cardinality] {{ cardinality?: { max?: '*' | number } }} EntityCSN + * @property {'*' | number} [cardinality.max] + */ + +/** + * @typedef {Object} CSN + * @property {Object} definitions + */ /** * When nested inline types require additional imports. E.g.: @@ -19,17 +28,16 @@ const { StructuredInlineDeclarationResolver } = require("./inline") * } * } * ``` - * @typedef {{ - * isBuiltin: boolean, - * isInlineDeclaration: boolean, - * isForeignKeyReference: boolean, - * isArray: boolean, - * type: string, - * path?: Path, - * csn?: CSN, - * imports: Path[] - * inner: TypeResolveInfo - * }} TypeResolveInfo + * @typedef {Object} TypeResolveInfo + * @property {boolean} isBuiltin + * @property {boolean} isInlineDeclaration + * @property {boolean} isForeignKeyReference + * @property {boolean} isArray + * @property {string} type + * @property {Path} [path] + * @property {CSN} [csn] + * @property {Array} [imports] + * @property {TypeResolveInfo} inner */ /** @@ -86,7 +94,7 @@ class Resolver { * to end up with both the resolved Path of the namespace, * and the clean name of the class. * @param {string} fq the fully qualified name of an entity. - * @returns {[Path, string]} a tuple, [0] holding the path to the namespace, [1] holding the clean name of the entity. + * @returns {Array} a tuple, [0] holding the path (Path) to the namespace, [1] holding the clean name of the entity (string). */ untangle(fq) { const ns = this.resolveNamespace(fq.split('.')) @@ -132,7 +140,7 @@ class Resolver { * - collisions between singular and plural name (resolved by appending a '_' suffix) * - inline type definitions, which don't really have a linguistic plural, * but need to expressed as array type to be consumable by the likes of Composition.of.many - * @param {import('./resolver').TypeResolveInfo} typeInfo information about the type gathered so far. + * @param {TypeResolveInfo} typeInfo information about the type gathered so far. * @param {string} [namespace] namespace the type occurs in. If passed, will be shaved off from the name * @returns {Inflection} */ @@ -181,6 +189,12 @@ class Resolver { return { typeName, singular, plural } } + /** + * @typedef {Object} InflectedTypeResolveInfo + * @extends TypeResolveInfo + * @property {Inflection} inflection + */ + /** * Convenient API to consume resolveType. * Internally calls resolveType, determines how it has to be imported, @@ -198,7 +212,7 @@ class Resolver { * * @param {CSN} element the CSN element to resolve the type for. * @param {SourceFile} file source file for context. - * @returns {{typeName: string, typeInfo: TypeResolveInfo & { inflection: Inflection } }} info about the resolved type + * @returns {{typeName: Foo, typeInfo: InflectedTypeResolveInfo }} info about the resolved type */ resolveAndRequire(element, file) { const typeInfo = this.resolveType(element, file)