diff --git a/src/lib/models/reflections/index.ts b/src/lib/models/reflections/index.ts index 856577dd2..3b4b2b5c9 100644 --- a/src/lib/models/reflections/index.ts +++ b/src/lib/models/reflections/index.ts @@ -1,4 +1,4 @@ -export { Reflection, ReflectionKind, ReflectionFlag, TypeParameterContainer, Decorator, TraverseProperty } from './abstract'; +export { Reflection, ReflectionKind, ReflectionFlag, TypeParameterContainer, Decorator, TraverseProperty, ReflectionFlags } from './abstract'; export { ContainerReflection } from './container'; export { DeclarationReflection, DeclarationHierarchy } from './declaration'; export { ParameterReflection } from './parameter'; diff --git a/src/lib/serialization/events.ts b/src/lib/serialization/events.ts index 13c3d9a90..804c8db9d 100644 --- a/src/lib/serialization/events.ts +++ b/src/lib/serialization/events.ts @@ -1,6 +1,6 @@ import { Event } from '../utils/events'; import { ProjectReflection } from '../models'; -import { JSONOutput } from './schema'; +import { ProjectReflection as JSONProjectReflection } from './schema'; /** * Optional data associated with the [[SerializeEvent]]. @@ -33,9 +33,9 @@ export class SerializeEvent extends Event { */ outputFile?: string; - output: Partial; + output: Partial; - constructor(name: string, project: ProjectReflection, output: Partial) { + constructor(name: string, project: ProjectReflection, output: Partial) { super(name); this.project = project; this.output = output; diff --git a/src/lib/serialization/index.ts b/src/lib/serialization/index.ts index 2cb3b8861..963e15449 100644 --- a/src/lib/serialization/index.ts +++ b/src/lib/serialization/index.ts @@ -33,4 +33,5 @@ export { export { SerializeEvent } from './events'; -export { JSONOutput } from './schema'; +import * as JSONOutput from './schema'; +export { JSONOutput }; diff --git a/src/lib/serialization/schema.ts b/src/lib/serialization/schema.ts index 3ee1e0fc2..d42562c58 100644 --- a/src/lib/serialization/schema.ts +++ b/src/lib/serialization/schema.ts @@ -1,45 +1,3 @@ -/** - * Documents the exported JSON schema. The root object is a [[JSONOutput.ProjectReflection]]. - */ - -/** */ -import * as M from '../models'; -import { SourceReferenceWrapper, DecoratorWrapper } from './serializers'; - -/** - * Describes the mapping from Model types to the corresponding JSON output type. - */ -export type ModelToObject = T extends Array ? _ModelToObject[] : _ModelToObject; - -// Order matters here. Some types are subtypes of other types. -type _ModelToObject = - // Reflections - T extends M.ReflectionGroup ? JSONOutput.ReflectionGroup : - T extends M.ReflectionCategory ? JSONOutput.ReflectionCategory : - T extends M.SignatureReflection ? JSONOutput.SignatureReflection : - T extends M.ParameterReflection ? JSONOutput.ParameterReflection : - T extends M.DeclarationReflection ? JSONOutput.DeclarationReflection | JSONOutput.ReflectionPointer : - T extends M.TypeParameterReflection ? JSONOutput.TypeParameterReflection : - T extends M.ProjectReflection ? JSONOutput.ProjectReflection : - T extends M.ContainerReflection ? JSONOutput.ContainerReflection : - T extends M.Reflection ? JSONOutput.Reflection : - // Types - T extends M.ArrayType ? JSONOutput.ArrayType : - T extends M.IntersectionType ? JSONOutput.IntersectionType : - T extends M.IntrinsicType ? JSONOutput.IntrinsicType : - T extends M.ReferenceType ? JSONOutput.ReferenceType : - T extends M.ReflectionType ? JSONOutput.ReflectionType : - T extends M.StringLiteralType ? JSONOutput.StringLiteralType : - T extends M.TupleType ? JSONOutput.TupleType : - T extends M.UnknownType ? JSONOutput.UnknownType : - T extends M.Type ? JSONOutput.SomeType : // Technically AbstractType, but the union is more useful - // Miscellaneous - T extends M.Comment ? JSONOutput.Comment : - T extends M.CommentTag ? JSONOutput.CommentTag : - T extends DecoratorWrapper ? JSONOutput.Decorator : - T extends SourceReferenceWrapper ? JSONOutput.SourceReference : - never; - /** * Contains interfaces which describe the JSON output. Each interface is related to a specific type of serializer. * @@ -49,15 +7,14 @@ type _ModelToObject = * For example, if your custom serializer adds a property to all [[Reflection]] objects: * ```ts * declare module 'typedoc/dist/lib/serialization/schema' { - * export namespace JSONOutput { - * export interface AbstractReflection { - * myCustomProp: boolean - * } + * export interface AbstractReflection { + * myCustomProp: boolean * } * } * ``` * - * If a plugin defines a new Model type, [[ModelToObject]] will not pick up the serializer type. + * If a plugin defines a new Model type, [[ModelToObject]] will not pick up the serializer type and + * the resulting type will not be included in the return type of {@link Serializer.toObject}. * To fix this, use declaration merging to augment the [[Serializer]] class. * ```ts * declare module 'typedoc/dist/lib/serialization/serializer' { @@ -69,187 +26,205 @@ type _ModelToObject = * * For documentation on the JSON output properties, view the corresponding model. */ -export namespace JSONOutput { - // Reflections +/** */ +import * as M from '../models'; +import { SourceReferenceWrapper, DecoratorWrapper } from './serializers'; - export interface ReflectionGroup { - title: M.ReflectionGroup['title']; - kind: M.ReflectionGroup['kind']; - children?: M.ReflectionGroup['children'][number]['id'][]; - categories?: ModelToObject; - } - - export interface ReflectionCategory { - title: M.ReflectionCategory['title']; - children?: M.ReflectionCategory['children'][number]['id'][]; - } - - export interface SignatureReflection extends Reflection { - type?: ModelToObject; - overwrites?: ModelToObject; - inheritedFrom?: ModelToObject; - implementationOf?: ModelToObject; - } - - export interface ParameterReflection extends Reflection { - type?: ModelToObject; - defaultValue?: M.ParameterReflection['defaultValue']; - } - - export interface DeclarationReflection extends ContainerReflection { - type?: ModelToObject; - defaultValue?: M.DeclarationReflection['defaultValue']; - overwrites?: ModelToObject; - inheritedFrom?: ModelToObject; - extendedTypes?: ModelToObject; - extendedBy?: ModelToObject; - implementedTypes?: ModelToObject; - implementedBy?: ModelToObject; - implementationOf?: ModelToObject; - } - - export interface TypeParameterReflection extends Reflection { - type?: ModelToObject; - } - - // Nothing extra yet. - export interface ProjectReflection extends ContainerReflection { } - - export interface ContainerReflection extends Reflection { - groups?: ModelToObject; - categories?: ModelToObject; - sources?: ModelToObject; - } - - /** - * If a 3rd party serializer creates a loop when serializing, a pointer will be created - * instead of re-serializing the [[DeclarationReflection]] - */ - export interface ReflectionPointer { - id: M.Reflection['id']; - } - - export interface Reflection { - id: M.Reflection['id']; - name: M.Reflection['name']; - originalName?: M.Reflection['originalName']; - kind: M.Reflection['kind']; - kindString: M.Reflection['kindString']; - flags: ReflectionFlags; - comment?: ModelToObject; - decorates?: ModelToObject; - decorators?: ModelToObject; - } +/** + * Describes the mapping from Model types to the corresponding JSON output type. + */ +export type ModelToObject = T extends Array ? _ModelToObject[] : _ModelToObject; +// Order matters here. Some types are subtypes of other types. +type _ModelToObject = + // Reflections + T extends M.ReflectionGroup ? ReflectionGroup : + T extends M.ReflectionCategory ? ReflectionCategory : + T extends M.SignatureReflection ? SignatureReflection : + T extends M.ParameterReflection ? ParameterReflection : + T extends M.DeclarationReflection ? DeclarationReflection | ReflectionPointer : + T extends M.TypeParameterReflection ? TypeParameterReflection : + T extends M.ProjectReflection ? ProjectReflection : + T extends M.ContainerReflection ? ContainerReflection : + T extends M.Reflection ? Reflection : // Types + T extends M.ArrayType ? ArrayType : + T extends M.IntersectionType ? IntersectionType : + T extends M.IntrinsicType ? IntrinsicType : + T extends M.ReferenceType ? ReferenceType : + T extends M.ReflectionType ? ReflectionType : + T extends M.StringLiteralType ? StringLiteralType : + T extends M.TupleType ? TupleType : + T extends M.UnknownType ? UnknownType : + T extends M.Type ? SomeType : // Technically AbstractType, but the union is more useful + // Miscellaneous + T extends M.Comment ? Comment : + T extends M.CommentTag ? CommentTag : + T extends DecoratorWrapper ? Decorator : + T extends SourceReferenceWrapper ? SourceReference : + never; - export type SomeType = - | ArrayType - | IntersectionType - | UnionType - | IntrinsicType - | ReferenceType - | ReflectionType - | StringLiteralType - | TupleType - | TypeOperatorType - | TypeParameterType - | UnionType - | UnknownType; - - export interface ArrayType extends Type { - elementType: ModelToObject; - } - - export interface IntersectionType extends Type { - types: ModelToObject; - } - - export interface UnionType extends Type { - types: ModelToObject; - } - - export interface IntrinsicType extends Type { - name: M.IntrinsicType['name']; - } - - export interface ReferenceType extends Type { - name: M.ReferenceType['name']; - id?: number; - typeArguments?: ModelToObject; - } - - export interface ReflectionType extends Type { - declaration?: ModelToObject; - } - - export interface StringLiteralType extends Type { - value: M.StringLiteralType['value']; - } - - export interface TupleType extends Type { - elements?: ModelToObject; - } - - export interface TypeOperatorType extends Type { - operator: M.TypeOperatorType['operator']; - target: ModelToObject; - } - - export interface TypeParameterType extends Type { - name: M.TypeParameterType['name']; - constraint?: ModelToObject; - } - - export interface UnknownType extends Type { - name: M.UnknownType['name']; - } - - export interface Type { - type: T['type']; - } +type Primitive = string | number | undefined | null | boolean; - // Miscellaneous +/** + * Helper to describe a set of serialized properties. Primitive types are returned + * directly, while other models are first passed through ModelToObject. + * This helper removes the readonly modifier from properties since the result of serialization + * is a plain object that consumers may modify as they choose, TypeDoc doesn't care. + */ +type S = { + -readonly [K2 in K]: T[K2] extends Primitive ? T[K2] : ModelToObject +}; + +// Reflections + +export interface ReflectionGroup extends S { + children?: M.ReflectionGroup['children'][number]['id'][]; +} + +export interface ReflectionCategory extends S { + children?: M.ReflectionCategory['children'][number]['id'][]; +} + +export interface SignatureReflection extends Reflection, S { +} + +export interface ParameterReflection extends Reflection, S { +} + +export interface DeclarationReflection extends ContainerReflection, S { +} + +export interface TypeParameterReflection extends Reflection, S { +} + +// Nothing extra yet. +export interface ProjectReflection extends ContainerReflection { } + +export interface ContainerReflection extends Reflection, S { + sources?: ModelToObject; +} + +/** + * If a 3rd party serializer creates a loop when serializing, a pointer will be created + * instead of re-serializing the [[DeclarationReflection]] + */ +export interface ReflectionPointer extends S { +} + +export interface Reflection extends S { + originalName?: M.Reflection['originalName']; + flags: ReflectionFlags; + decorators?: ModelToObject; +} + +// Types + +export type SomeType = + | ArrayType + | IntersectionType + | UnionType + | IntrinsicType + | ReferenceType + | ReflectionType + | StringLiteralType + | TupleType + | TypeOperatorType + | TypeParameterType + | UnionType + | UnknownType; + +export interface ArrayType extends Type, S { +} + +export interface IntersectionType extends Type, S { +} + +export interface UnionType extends Type, S { +} + +export interface IntrinsicType extends Type, S { +} + +export interface ReferenceType extends Type, S { + id?: number; +} + +export interface ReflectionType extends Type, S { + declaration?: ModelToObject; +} + +export interface StringLiteralType extends Type, S { +} + +export interface TupleType extends Type, S { + elements?: ModelToObject; +} + +export interface TypeOperatorType extends Type, S { +} + +export interface TypeParameterType extends Type, S { +} + +export interface UnknownType extends Type, S { +} + +/** + * Technically not correct, the `type` property will be set by the abstract serializer. + * But to allow tagged literals, the `type` property is instead defined by each child type. + */ +export interface Type { +} + +// Miscellaneous + +export interface ReflectionFlags extends Partial> { +} + +export interface Comment extends Partial> { +} + +export interface CommentTag extends S { + tag: M.CommentTag['tagName']; + param?: M.CommentTag['paramName']; +} + +export interface SourceReference extends S { +} - export interface ReflectionFlags { - isPrivate?: boolean; - isProtected?: boolean; - isPublic?: boolean; - isStatic?: boolean; - isExported?: boolean; - isExternal?: boolean; - isOptional?: boolean; - isRest?: boolean; - hasExportAssignment?: boolean; - isConstructorProperty?: boolean; - isAbstract?: boolean; - isConst?: boolean; - isLet?: boolean; - } - - export interface Comment { - shortText?: M.Comment['shortText']; - text?: M.Comment['text']; - returns?: M.Comment['returns']; - tags?: ModelToObject; - } - - export interface CommentTag { - tag: M.CommentTag['tagName']; - text: M.CommentTag['text']; - param?: M.CommentTag['paramName']; - } - - export interface SourceReference { - fileName: M.SourceReference['fileName']; - line: M.SourceReference['line']; - character: M.SourceReference['character']; - } - - export interface Decorator { - name: M.Decorator['name']; - type?: ModelToObject; - arguments?: M.Decorator['arguments']; - } +export interface Decorator extends S { } diff --git a/src/lib/serialization/serializers/comments/comment-tag.ts b/src/lib/serialization/serializers/comments/comment-tag.ts index 821e6ecf9..8df3f3439 100644 --- a/src/lib/serialization/serializers/comments/comment-tag.ts +++ b/src/lib/serialization/serializers/comments/comment-tag.ts @@ -1,7 +1,7 @@ import { CommentTag } from '../../../models'; import { SerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { CommentTag as JSONCommentTag } from '../../schema'; export class CommentTagSerializer extends SerializerComponent { static PRIORITY = 1000; @@ -17,8 +17,8 @@ export class CommentTagSerializer extends SerializerComponent { return true; } - toObject(tag: CommentTag, obj: Partial = {}): JSONOutput.CommentTag { - const result: JSONOutput.CommentTag = { + toObject(tag: CommentTag, obj: Partial = {}): JSONCommentTag { + const result: JSONCommentTag = { tag: tag.tagName, text: tag.text }; diff --git a/src/lib/serialization/serializers/comments/comment.ts b/src/lib/serialization/serializers/comments/comment.ts index 9bd5890e4..a64d26397 100644 --- a/src/lib/serialization/serializers/comments/comment.ts +++ b/src/lib/serialization/serializers/comments/comment.ts @@ -1,7 +1,7 @@ import { Comment } from '../../../models'; import { SerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { Comment as JSONComment } from '../../schema'; export class CommentSerializer extends SerializerComponent { static PRIORITY = 1000; @@ -17,7 +17,7 @@ export class CommentSerializer extends SerializerComponent { return true; } - toObject(comment: Comment, obj: Partial = {}): JSONOutput.Comment { + toObject(comment: Comment, obj: Partial = {}): JSONComment { if (comment.shortText) { obj.shortText = comment.shortText; } diff --git a/src/lib/serialization/serializers/decorator.ts b/src/lib/serialization/serializers/decorator.ts index 815861ecb..4a7c0d88d 100644 --- a/src/lib/serialization/serializers/decorator.ts +++ b/src/lib/serialization/serializers/decorator.ts @@ -1,6 +1,6 @@ import { SerializerComponent } from '../components'; import { DecoratorWrapper } from './models/decorator-wrapper'; -import { JSONOutput } from '../schema'; +import { Decorator } from '../schema'; export class DecoratorContainerSerializer extends SerializerComponent { static PRIORITY = 1000; @@ -16,8 +16,8 @@ export class DecoratorContainerSerializer extends SerializerComponent): JSONOutput.Decorator { - const result: JSONOutput.Decorator = { + toObject({ decorator }: DecoratorWrapper, obj?: Partial): Decorator { + const result: Decorator = { ...obj, name: decorator.name }; diff --git a/src/lib/serialization/serializers/reflection-category.ts b/src/lib/serialization/serializers/reflection-category.ts index a1b2fc45d..01fabc667 100644 --- a/src/lib/serialization/serializers/reflection-category.ts +++ b/src/lib/serialization/serializers/reflection-category.ts @@ -1,7 +1,7 @@ import { ReflectionCategory } from '../../models/ReflectionCategory'; import { SerializerComponent } from '../components'; -import { JSONOutput } from '../schema'; +import { ReflectionCategory as JSONReflectionCategory } from '../schema'; export class ReflectionCategorySerializer extends SerializerComponent { static PRIORITY = 1000; @@ -17,8 +17,8 @@ export class ReflectionCategorySerializer extends SerializerComponent): JSONOutput.ReflectionCategory { - const result: JSONOutput.ReflectionCategory = { + toObject(category: ReflectionCategory, obj?: Partial): JSONReflectionCategory { + const result: JSONReflectionCategory = { ...obj, title: category.title }; diff --git a/src/lib/serialization/serializers/reflection-group.ts b/src/lib/serialization/serializers/reflection-group.ts index 13ae33995..27dcb6265 100644 --- a/src/lib/serialization/serializers/reflection-group.ts +++ b/src/lib/serialization/serializers/reflection-group.ts @@ -1,7 +1,7 @@ import { ReflectionGroup } from '../../models/ReflectionGroup'; import { SerializerComponent } from '../components'; -import { JSONOutput } from '../schema'; +import { ReflectionGroup as JSONReflectionGroup } from '../schema'; export class ReflectionGroupSerializer extends SerializerComponent { static PRIORITY = 1000; @@ -17,8 +17,8 @@ export class ReflectionGroupSerializer extends SerializerComponent): JSONOutput.ReflectionGroup { - const result: JSONOutput.ReflectionGroup = { + toObject(group: ReflectionGroup, obj?: Partial): JSONReflectionGroup { + const result: JSONReflectionGroup = { ...obj, title: group.title, kind: group.kind diff --git a/src/lib/serialization/serializers/reflections/abstract.ts b/src/lib/serialization/serializers/reflections/abstract.ts index ffeec1a51..148b313c0 100644 --- a/src/lib/serialization/serializers/reflections/abstract.ts +++ b/src/lib/serialization/serializers/reflections/abstract.ts @@ -3,7 +3,7 @@ import { Reflection, TraverseProperty } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; import { DecoratorWrapper } from '../models'; import { ReflectionFlags } from '../../../models/reflections/abstract'; -import { JSONOutput, ModelToObject } from '../../schema'; +import { Reflection as JSONReflection } from '../../schema'; export class ReflectionSerializer extends ReflectionSerializerComponent { static PRIORITY = 1000; @@ -12,8 +12,8 @@ export class ReflectionSerializer extends ReflectionSerializerComponent>): JSONOutput.Reflection { - const result: JSONOutput.Reflection = { + toObject(reflection: Reflection, obj?: Partial): JSONReflection { + const result: JSONReflection = { ...obj, id: reflection.id, name: reflection.name, diff --git a/src/lib/serialization/serializers/reflections/container.ts b/src/lib/serialization/serializers/reflections/container.ts index 49110b91e..7290f5ccc 100644 --- a/src/lib/serialization/serializers/reflections/container.ts +++ b/src/lib/serialization/serializers/reflections/container.ts @@ -2,7 +2,7 @@ import { ContainerReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; import { SourceReferenceWrapper } from '../models'; -import { JSONOutput } from '../../schema'; +import { ContainerReflection as JSONContainerReflection, Reflection as JSONReflection } from '../../schema'; export class ContainerReflectionSerializer extends ReflectionSerializerComponent { supports(t: unknown) { @@ -14,8 +14,8 @@ export class ContainerReflectionSerializer extends ReflectionSerializerComponent * @param container * @param obj */ - toObject(container: ContainerReflection, obj: JSONOutput.Reflection): JSONOutput.ContainerReflection { - const result: JSONOutput.ContainerReflection = { + toObject(container: ContainerReflection, obj: JSONReflection): JSONContainerReflection { + const result: JSONContainerReflection = { ...obj }; diff --git a/src/lib/serialization/serializers/reflections/declaration.ts b/src/lib/serialization/serializers/reflections/declaration.ts index 199f649fa..0f88d6d77 100644 --- a/src/lib/serialization/serializers/reflections/declaration.ts +++ b/src/lib/serialization/serializers/reflections/declaration.ts @@ -2,7 +2,10 @@ import { DeclarationReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; import { ContainerReflectionSerializer } from './container'; -import { JSONOutput } from '../../schema'; +import { + DeclarationReflection as JSONDeclarationReflection, + ContainerReflection as JSONContainerReflection +} from '../../schema'; export class DeclarationReflectionSerializer extends ReflectionSerializerComponent { static PRIORITY = ContainerReflectionSerializer.PRIORITY - 1; // mimic inheritance, run after parent @@ -11,8 +14,8 @@ export class DeclarationReflectionSerializer extends ReflectionSerializerCompone return t instanceof DeclarationReflection; } - toObject(declaration: DeclarationReflection, obj: JSONOutput.ContainerReflection): JSONOutput.DeclarationReflection { - const result: JSONOutput.DeclarationReflection = { + toObject(declaration: DeclarationReflection, obj: JSONContainerReflection): JSONDeclarationReflection { + const result: JSONDeclarationReflection = { ...obj }; diff --git a/src/lib/serialization/serializers/reflections/parameter.ts b/src/lib/serialization/serializers/reflections/parameter.ts index e3fe4ee1d..2be25af1b 100644 --- a/src/lib/serialization/serializers/reflections/parameter.ts +++ b/src/lib/serialization/serializers/reflections/parameter.ts @@ -1,15 +1,15 @@ import { ParameterReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { ParameterReflection as JSONParameterReflection, Reflection as JSONReflection } from '../../schema'; export class ParameterReflectionSerializer extends ReflectionSerializerComponent { supports(t: unknown) { return t instanceof ParameterReflection; } - toObject(parameter: ParameterReflection, obj: JSONOutput.Reflection): JSONOutput.ParameterReflection { - const result: JSONOutput.ParameterReflection = { + toObject(parameter: ParameterReflection, obj: JSONReflection): JSONParameterReflection { + const result: JSONParameterReflection = { ...obj }; diff --git a/src/lib/serialization/serializers/reflections/project.ts b/src/lib/serialization/serializers/reflections/project.ts index 5452295a0..c15ca5559 100644 --- a/src/lib/serialization/serializers/reflections/project.ts +++ b/src/lib/serialization/serializers/reflections/project.ts @@ -2,7 +2,10 @@ import { ProjectReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; import { ContainerReflectionSerializer } from './container'; -import { JSONOutput } from '../../schema'; +import { + ProjectReflection as JSONProjectReflection, + ContainerReflection as JSONContainerReflection +} from '../../schema'; export class ProjectReflectionSerializer extends ReflectionSerializerComponent { static PRIORITY = ContainerReflectionSerializer.PRIORITY - 1; // mimic inheritance, run after parent @@ -11,7 +14,7 @@ export class ProjectReflectionSerializer extends ReflectionSerializerComponent

{ supports(t: unknown) { return t instanceof SignatureReflection; } - toObject(signature: SignatureReflection, obj: JSONOutput.Reflection): JSONOutput.SignatureReflection { - const result: JSONOutput.SignatureReflection = { ...obj }; + toObject(signature: SignatureReflection, obj: JSONReflection): JSONSignatureReflection { + const result: JSONSignatureReflection = { ...obj }; if (signature.type) { result.type = this.owner.toObject(signature.type); diff --git a/src/lib/serialization/serializers/reflections/type-parameter.ts b/src/lib/serialization/serializers/reflections/type-parameter.ts index 7bce9d0ad..39766ea69 100644 --- a/src/lib/serialization/serializers/reflections/type-parameter.ts +++ b/src/lib/serialization/serializers/reflections/type-parameter.ts @@ -1,17 +1,18 @@ import { TypeParameterReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { + TypeParameterReflection as JSONTypeParameterReflection, + Reflection as JSONReflection +} from '../../schema'; -export class TypeParameterReflectionSerializer extends ReflectionSerializerComponent< - TypeParameterReflection -> { +export class TypeParameterReflectionSerializer extends ReflectionSerializerComponent { supports(t: unknown) { return t instanceof TypeParameterReflection; } - toObject(typeParameter: TypeParameterReflection, obj: JSONOutput.Reflection): JSONOutput.TypeParameterReflection { - const result: JSONOutput.TypeParameterReflection = { ...obj }; + toObject(typeParameter: TypeParameterReflection, obj: JSONReflection): JSONTypeParameterReflection { + const result: JSONTypeParameterReflection = { ...obj }; if (typeParameter.type) { result.type = this.owner.toObject(typeParameter.type); diff --git a/src/lib/serialization/serializers/sources/source-reference.ts b/src/lib/serialization/serializers/sources/source-reference.ts index 7221eecad..fb22ec693 100644 --- a/src/lib/serialization/serializers/sources/source-reference.ts +++ b/src/lib/serialization/serializers/sources/source-reference.ts @@ -1,6 +1,6 @@ import { SerializerComponent } from '../../components'; import { SourceReferenceWrapper } from '../models'; -import { JSONOutput } from '../../schema'; +import { SourceReference as JSONSourceReference } from '../../schema'; export class SourceReferenceContainerSerializer extends SerializerComponent { static PRIORITY = 1000; @@ -13,7 +13,10 @@ export class SourceReferenceContainerSerializer extends SerializerComponent): JSONOutput.SourceReference { + toObject( + { sourceReference: ref }: SourceReferenceWrapper, + obj?: Partial + ): JSONSourceReference { return { ...obj, fileName: ref.fileName, diff --git a/src/lib/serialization/serializers/types/abstract.ts b/src/lib/serialization/serializers/types/abstract.ts index 6ef147451..59cb2966d 100644 --- a/src/lib/serialization/serializers/types/abstract.ts +++ b/src/lib/serialization/serializers/types/abstract.ts @@ -1,7 +1,7 @@ import { Type } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { Type as JSONType } from '../../schema'; export class TypeSerializer extends TypeSerializerComponent { static PRIORITY = 1000; @@ -10,7 +10,7 @@ export class TypeSerializer extends TypeSerializerComponent { return t instanceof Type; } - toObject(type: Type, obj?: Partial>): JSONOutput.Type { + toObject(type: Type, obj?: Partial): JSONType { return { ...obj, type: type.type diff --git a/src/lib/serialization/serializers/types/array.ts b/src/lib/serialization/serializers/types/array.ts index 4d3231cac..1f534bcf7 100644 --- a/src/lib/serialization/serializers/types/array.ts +++ b/src/lib/serialization/serializers/types/array.ts @@ -1,7 +1,7 @@ import { ArrayType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { ArrayType as JSONArrayType } from '../../schema'; export class ArrayTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { @@ -13,7 +13,7 @@ export class ArrayTypeSerializer extends TypeSerializerComponent { * @param type * @param obj */ - toObject(type: ArrayType, obj: Pick): JSONOutput.ArrayType { + toObject(type: ArrayType, obj: Pick): JSONArrayType { return { ...obj, elementType: this.owner.toObject(type.elementType) diff --git a/src/lib/serialization/serializers/types/intersection.ts b/src/lib/serialization/serializers/types/intersection.ts index a8c8781a8..40eecd572 100644 --- a/src/lib/serialization/serializers/types/intersection.ts +++ b/src/lib/serialization/serializers/types/intersection.ts @@ -1,7 +1,7 @@ import { IntersectionType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { IntersectionType as JSONIntersectionType } from '../../schema'; export class IntersectionTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { @@ -13,7 +13,7 @@ export class IntersectionTypeSerializer extends TypeSerializerComponent): JSONOutput.IntersectionType { + toObject(type: IntersectionType, obj: Pick): JSONIntersectionType { return { ...obj, types: type.types.map(t => this.owner.toObject(t)) diff --git a/src/lib/serialization/serializers/types/intrinsic.ts b/src/lib/serialization/serializers/types/intrinsic.ts index 956656b16..676ea9318 100644 --- a/src/lib/serialization/serializers/types/intrinsic.ts +++ b/src/lib/serialization/serializers/types/intrinsic.ts @@ -1,7 +1,7 @@ import { IntrinsicType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { IntrinsicType as JSONIntrinsicType } from '../../schema'; export class IntrinsicTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { @@ -13,7 +13,7 @@ export class IntrinsicTypeSerializer extends TypeSerializerComponent): JSONOutput.IntrinsicType { + toObject(type: IntrinsicType, obj: Pick): JSONIntrinsicType { return { ...obj, name: type.name diff --git a/src/lib/serialization/serializers/types/reference.ts b/src/lib/serialization/serializers/types/reference.ts index 6e304e551..34346fd1a 100644 --- a/src/lib/serialization/serializers/types/reference.ts +++ b/src/lib/serialization/serializers/types/reference.ts @@ -1,7 +1,7 @@ import { ReferenceType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { ReferenceType as JSONReferenceType } from '../../schema'; export class ReferenceTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { @@ -10,8 +10,8 @@ export class ReferenceTypeSerializer extends TypeSerializerComponent & Partial - ): JSONOutput.ReferenceType { + obj: Pick & Partial + ): JSONReferenceType { if (type.reflection) { obj.id = type.reflection.id; } diff --git a/src/lib/serialization/serializers/types/reflection.ts b/src/lib/serialization/serializers/types/reflection.ts index 3c869a6b5..a4285958c 100644 --- a/src/lib/serialization/serializers/types/reflection.ts +++ b/src/lib/serialization/serializers/types/reflection.ts @@ -1,7 +1,7 @@ import { DeclarationReflection, ReflectionType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { ReflectionType as JSONReflectionType } from '../../schema'; export class ReflectionTypeSerializer extends TypeSerializerComponent { private visited = new Set(); @@ -10,8 +10,8 @@ export class ReflectionTypeSerializer extends TypeSerializerComponent): JSONOutput.ReflectionType { - const result: JSONOutput.ReflectionType = { + toObject(reference: ReflectionType, obj: Pick): JSONReflectionType { + const result: JSONReflectionType = { ...obj }; diff --git a/src/lib/serialization/serializers/types/string-literal.ts b/src/lib/serialization/serializers/types/string-literal.ts index 0ce588340..cc15a1415 100644 --- a/src/lib/serialization/serializers/types/string-literal.ts +++ b/src/lib/serialization/serializers/types/string-literal.ts @@ -1,14 +1,14 @@ import { StringLiteralType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { StringLiteralType as JSONStringLiteralType } from '../../schema'; export class StringLiteralTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { return t instanceof StringLiteralType; } - toObject(type: StringLiteralType, obj: Pick): JSONOutput.StringLiteralType { + toObject(type: StringLiteralType, obj: Pick): JSONStringLiteralType { return { ...obj, value: type.value diff --git a/src/lib/serialization/serializers/types/tuple.ts b/src/lib/serialization/serializers/types/tuple.ts index 0e6592d69..0aebed210 100644 --- a/src/lib/serialization/serializers/types/tuple.ts +++ b/src/lib/serialization/serializers/types/tuple.ts @@ -1,15 +1,15 @@ import { TupleType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { TupleType as JSONTupleType } from '../../schema'; export class TupleTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { return t instanceof TupleType; } - toObject(tuple: TupleType, obj: Pick): JSONOutput.TupleType { - const result: JSONOutput.TupleType = { ...obj }; + toObject(tuple: TupleType, obj: Pick): JSONTupleType { + const result: JSONTupleType = { ...obj }; if (tuple.elements && tuple.elements.length > 0) { result.elements = tuple.elements.map(t => this.owner.toObject(t)); diff --git a/src/lib/serialization/serializers/types/type-operator.ts b/src/lib/serialization/serializers/types/type-operator.ts index 696772039..200c024df 100644 --- a/src/lib/serialization/serializers/types/type-operator.ts +++ b/src/lib/serialization/serializers/types/type-operator.ts @@ -1,14 +1,14 @@ import { TypeOperatorType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { TypeOperatorType as JSONTypeOperatorType } from '../../schema'; export class TypeOperatorTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { return t instanceof TypeOperatorType; } - toObject(type: TypeOperatorType, obj: Pick): JSONOutput.TypeOperatorType { + toObject(type: TypeOperatorType, obj: Pick): JSONTypeOperatorType { return { ...obj, operator: type.operator, diff --git a/src/lib/serialization/serializers/types/type-parameter.ts b/src/lib/serialization/serializers/types/type-parameter.ts index e3e99788f..ab2925700 100644 --- a/src/lib/serialization/serializers/types/type-parameter.ts +++ b/src/lib/serialization/serializers/types/type-parameter.ts @@ -1,15 +1,15 @@ import { TypeParameterType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { TypeParameterType as JSONTypeParameterType } from '../../schema'; export class TypeParameterTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { return t instanceof TypeParameterType; } - toObject(type: TypeParameterType, obj: Pick): JSONOutput.TypeParameterType { - const result: JSONOutput.TypeParameterType = { + toObject(type: TypeParameterType, obj: Pick): JSONTypeParameterType { + const result: JSONTypeParameterType = { ...obj, name: type.name }; diff --git a/src/lib/serialization/serializers/types/union.ts b/src/lib/serialization/serializers/types/union.ts index 57d8cf770..75df55e34 100644 --- a/src/lib/serialization/serializers/types/union.ts +++ b/src/lib/serialization/serializers/types/union.ts @@ -1,7 +1,7 @@ import { UnionType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { UnionType as JSONUnionType } from '../../schema'; export class UnionTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { @@ -13,7 +13,7 @@ export class UnionTypeSerializer extends TypeSerializerComponent { * @param type * @param obj */ - toObject(type: UnionType, obj: Pick): JSONOutput.UnionType { + toObject(type: UnionType, obj: Pick): JSONUnionType { return { ...obj, types: type.types.map(t => this.owner.toObject(t)) diff --git a/src/lib/serialization/serializers/types/unknown.ts b/src/lib/serialization/serializers/types/unknown.ts index cf606daea..01caa451f 100644 --- a/src/lib/serialization/serializers/types/unknown.ts +++ b/src/lib/serialization/serializers/types/unknown.ts @@ -1,7 +1,7 @@ import { UnknownType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -import { JSONOutput } from '../../schema'; +import { UnknownType as JSONUnknownType } from '../../schema'; export class UnknownTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { @@ -13,7 +13,7 @@ export class UnknownTypeSerializer extends TypeSerializerComponent * @param type * @param obj */ - toObject(type: UnknownType, obj: Pick): JSONOutput.UnknownType { + toObject(type: UnknownType, obj: Pick): JSONUnknownType { return { ...obj, name: type.name