Skip to content

Commit

Permalink
EW-539 Add new types to realize nesting
Browse files Browse the repository at this point in the history
Co-authored-by: Patrick Sachmann <[email protected]>
  • Loading branch information
SimoneRadtke-Cap and psachmann committed Nov 9, 2023
1 parent 548ec7c commit 4192540
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,46 @@ export type ICommonCartridgeOrganizationProps = {
version: string;
} & ({ children: ICommonCartridgeOrganizationProps[] } | { resources: ICommonCartridgeResourceProps[] });

type OrganizationItemCollection = {
title: string;
children: OrganizationItemCollection[] | OrganizationResourceCollection;
_tag: 'itemCollection';
};

type OrganizationResourceCollection = {
identifier: string;
title: string;
version: string;
resources: ICommonCartridgeResourceProps[];
_tag: 'resourceCollection';
};

export type CommonCartridgeOrganizationItemElementProps = OrganizationItemCollection | OrganizationResourceCollection;

function isOrganizationItemCollection(
item: CommonCartridgeOrganizationItemElementProps
): item is OrganizationItemCollection {
return item._tag === 'itemCollection';
}

function isOrganizationResourceCollection(
item: CommonCartridgeOrganizationItemElementProps
): item is OrganizationResourceCollection {
return item._tag === 'resourceCollection';
}

export class CommonCartridgeOrganizationItemElement implements ICommonCartridgeElement {
constructor(private readonly props: ICommonCartridgeOrganizationProps) {}
constructor(private readonly props: CommonCartridgeOrganizationItemElementProps) {}

transform(): Record<string, unknown> {
if (isOrganizationItemCollection(this.props)) {
return {};
}

if (isOrganizationResourceCollection(this.props)) {
return {};
}

return {
$: {
identifier: this.props.identifier,
Expand Down

0 comments on commit 4192540

Please sign in to comment.