Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePlenkov committed Nov 11, 2024
1 parent 0f8571a commit 6692329
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
15 changes: 8 additions & 7 deletions samples/cds/src/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import * as cds from '@sap/cds';

import { dset } from 'dset';
import { AbapAnnotation } from './lib/annotations';
import {
Component,
} from '@abapify/components';
import { Component } from '@abapify/components';

import { DdicFactory } from './lib/factory';
type ComponentFactory = { [key: string]: (input: unknown) => Component<unknown> | Array<Component<unknown>> };
type ComponentFactory = {
[key: string]: (
input: unknown
) => Component<unknown> | Array<Component<unknown>>;
};

test('generate abapgit project from CDS model', async () => {
const model = await cds.load(__dirname + '/cds/model.cds');
Expand All @@ -28,7 +30,6 @@ test('generate abapgit project from CDS model', async () => {
for (const annotation of generator) {
const ddic = annotation['@abap']?.ddic;


//generic logic to generate components from abap annotation
if (ddic) {
for (const key in ddic) {
Expand Down Expand Up @@ -57,8 +58,8 @@ test('generate abapgit project from CDS model', async () => {
for (const component of abapComponents.values()) {
console.log('\n', component.type, component.id, component.toAbapgitXML());
}

}); function* cds2abap(csn: cds.csn.CSN) {
});
function* cds2abap(csn: cds.csn.CSN) {
for (const definition_key in csn.definitions) {
const definition = csn.definitions[definition_key];

Expand Down
2 changes: 0 additions & 2 deletions samples/cds/src/lib/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ export interface AbapAnnotation {
};
};
}


52 changes: 27 additions & 25 deletions samples/cds/src/lib/factory.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import { DataElement, DataElementInput, Domain, DomainInput } from "@abapify/components";
import { dset } from "dset";
import {
DataElement,
DataElementInput,
Domain,
DomainInput,
} from '@abapify/components';
import { dset } from 'dset';

export class DdicFactory {
static dataElement(input: DataElementInput): DataElement | Array<DataElement | Domain> {
static dataElement(
input: DataElementInput
): DataElement | Array<DataElement | Domain> {
const result: Array<DataElement | Domain> = [new DataElement(input)];

const result: Array<DataElement | Domain> = [new DataElement(input)];

if (
'domain' in input &&
typeof input.domain === 'object'
) {
// inherit name from data element if not specified
if (!input.domain.name) {
input.domain.name = input.name;
}
//inherit description from data element if not specified
if (!input.domain.header?.description) {
dset(input.domain, 'header.description', input.description);
}
result.push(DdicFactory.domain(input.domain));
}

return result;
}
static domain(input: DomainInput): Domain {
return new Domain(input);
if ('domain' in input && typeof input.domain === 'object') {
// inherit name from data element if not specified
if (!input.domain.name) {
input.domain.name = input.name;
}
//inherit description from data element if not specified
if (!input.domain.header?.description) {
dset(input.domain, 'header.description', input.description);
}
result.push(DdicFactory.domain(input.domain));
}
}

return result;
}
static domain(input: DomainInput): Domain {
return new Domain(input);
}
}

0 comments on commit 6692329

Please sign in to comment.