Skip to content

Commit c11b637

Browse files
feat: add new Event support for extensible params (#80)
Co-authored-by: Jeremy Rose <[email protected]>
1 parent 2a33816 commit c11b637

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/ParsedDocumentation.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ export declare type DetailedObjectType = {
1919
type: 'Object';
2020
properties: PropertyDocumentationBlock[];
2121
};
22+
export declare type DetailedEventType = {
23+
type: 'Event';
24+
eventProperties: PropertyDocumentationBlock[];
25+
};
26+
export declare type DetailedEventReferenceType = {
27+
type: 'Event';
28+
eventPropertiesReference: TypeInformation;
29+
};
2230
export declare type DetailedFunctionType = {
2331
type: 'Function';
2432
parameters: MethodParameterDocumentation[];
@@ -30,6 +38,8 @@ export declare type DetailedType = (
3038
}
3139
| DetailedFunctionType
3240
| DetailedObjectType
41+
| DetailedEventType
42+
| DetailedEventReferenceType
3343
| DetailedStringType
3444
| {
3545
type: string;

src/block-parsers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export const _headingToEventBlock = (heading: HeadingContent): EventDocumentatio
201201
name: typedKey.key,
202202
description: typedKey.description,
203203
...typedKey.type,
204+
additionalTags: typedKey.additionalTags,
204205
required: true,
205206
}));
206207
}

src/markdown-helpers.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,50 @@ export const rawTypeToTypeInformation = (
361361
return info;
362362
});
363363

364+
// Special case, when the generic type is "Event" then there should be no declared
365+
// innerTypes. Instead we extract the following list as event parameters.
366+
if (genericTypeString === 'Event') {
367+
if (innerTypes.length) {
368+
if (subTypedKeys && !subTypedKeys.consumed) {
369+
throw new Error(
370+
'Found an Event<> declaration with a type declared in the generic, Event<> should not have declared inner types AND a parameter list',
371+
);
372+
}
373+
374+
if (innerTypes.length > 1) {
375+
throw new Error(
376+
'Found an Event<> declaration with multiple types declared in the generic, Event<> should have at most one inner type',
377+
);
378+
}
379+
380+
return {
381+
collection,
382+
type: 'Event',
383+
eventPropertiesReference: innerTypes[0],
384+
};
385+
} else {
386+
if (!subTypedKeys || subTypedKeys.consumed) {
387+
throw new Error(
388+
'Found an Event<> declaration without a parameter list, either declare as "Event" or provide a parameter list below',
389+
);
390+
}
391+
392+
return {
393+
collection,
394+
type: 'Event',
395+
eventProperties: consumeTypedKeysList(subTypedKeys).map<PropertyDocumentationBlock>(
396+
typedKey => ({
397+
name: typedKey.key,
398+
description: typedKey.description,
399+
required: typedKey.required,
400+
additionalTags: typedKey.additionalTags,
401+
...typedKey.type,
402+
}),
403+
),
404+
};
405+
}
406+
}
407+
364408
// Special case, when the generic type is "Function" then the first N - 1 innerTypes are
365409
// parameter types and the Nth innerType is the return type
366410
if (genericTypeString === 'Function') {
@@ -384,6 +428,13 @@ export const rawTypeToTypeInformation = (
384428
returns: innerTypes[innerTypes.length - 1],
385429
};
386430
}
431+
432+
if (!innerTypes.length) {
433+
throw new Error(
434+
`Found a generic declaration without a type declared in the generic, T<> (${genericTypeString}<>) should have at least one inner type`,
435+
);
436+
}
437+
387438
return {
388439
collection,
389440
type: genericTypeString,

0 commit comments

Comments
 (0)