From 21317e12f41921c450e35abfb76f42ce1da28af3 Mon Sep 17 00:00:00 2001 From: Petr Plenkov Date: Mon, 11 Nov 2024 10:35:06 +0000 Subject: [PATCH] format --- packages/components/src/lib/components.ts | 8 +- .../src/lib/components/componentTypes.ts | 6 +- .../src/lib/components/doma/dataTypes.ts | 76 ++++---- .../src/lib/components/doma/domain.ts | 52 ++--- .../src/lib/components/doma/domainInput.ts | 54 +++--- .../src/lib/components/doma/outputStyle.ts | 16 +- .../src/lib/components/dtel/dataElement.ts | 181 +++++++++--------- .../lib/components/dtel/dataElementInput.ts | 61 +++--- .../src/lib/components/dtel/refKind.ts | 15 +- .../src/lib/components/dtel/refType.ts | 20 +- samples/cds/src/build.test.ts | 124 ++++++------ samples/cds/src/lib/annotations.ts | 20 +- samples/cds/src/lib/objectList.ts | 16 +- samples/cds/src/lib/objectTypes.ts | 6 +- 14 files changed, 331 insertions(+), 324 deletions(-) diff --git a/packages/components/src/lib/components.ts b/packages/components/src/lib/components.ts index 53d03d0..27c9e2d 100644 --- a/packages/components/src/lib/components.ts +++ b/packages/components/src/lib/components.ts @@ -1,4 +1,4 @@ -export * from "./components/component"; -export * from "./components/devc/package"; -export * from "./components/doma/domain"; -export * from "./components/dtel/dataElement"; \ No newline at end of file +export * from './components/component'; +export * from './components/devc/package'; +export * from './components/doma/domain'; +export * from './components/dtel/dataElement'; diff --git a/packages/components/src/lib/components/componentTypes.ts b/packages/components/src/lib/components/componentTypes.ts index 125040e..5e62784 100644 --- a/packages/components/src/lib/components/componentTypes.ts +++ b/packages/components/src/lib/components/componentTypes.ts @@ -1,4 +1,4 @@ export enum ComponentType { - dataElement = 'DTEL', - domain = 'DOMA', -} \ No newline at end of file + dataElement = 'DTEL', + domain = 'DOMA', +} diff --git a/packages/components/src/lib/components/doma/dataTypes.ts b/packages/components/src/lib/components/doma/dataTypes.ts index 3e13f59..ace3c3c 100644 --- a/packages/components/src/lib/components/doma/dataTypes.ts +++ b/packages/components/src/lib/components/doma/dataTypes.ts @@ -1,39 +1,39 @@ export enum DataTypes { - ACCP, - CHAR, - CLNT, - CUKY, - CURR, - DF16_DEC, - DECFLOAT16, - DF16_RAW, - DF16_SCL, - DF34_DEC, - DECFLOAT34, - DF34_RAW, - DF34_SCL, - DATN, - DATS, - DEC, - FLTP, - GEOM_EWKB, - INT1, - INT2, - INT4, - INT8, - LANG, - LCHR, - LRAW, - NUMC, - PREC, - QUAN, - RAW, - RAWSTRING, - SSTRING, - STRING, - TIMN, - TIMS, - UNIT, - UTCLONG, - VARC -} \ No newline at end of file + ACCP, + CHAR, + CLNT, + CUKY, + CURR, + DF16_DEC, + DECFLOAT16, + DF16_RAW, + DF16_SCL, + DF34_DEC, + DECFLOAT34, + DF34_RAW, + DF34_SCL, + DATN, + DATS, + DEC, + FLTP, + GEOM_EWKB, + INT1, + INT2, + INT4, + INT8, + LANG, + LCHR, + LRAW, + NUMC, + PREC, + QUAN, + RAW, + RAWSTRING, + SSTRING, + STRING, + TIMN, + TIMS, + UNIT, + UTCLONG, + VARC, +} diff --git a/packages/components/src/lib/components/doma/domain.ts b/packages/components/src/lib/components/doma/domain.ts index 568dc26..cdab292 100644 --- a/packages/components/src/lib/components/doma/domain.ts +++ b/packages/components/src/lib/components/doma/domain.ts @@ -1,30 +1,30 @@ -import { Component } from "../component" -import { ComponentType } from "../componentTypes"; -import { DomainInput } from "./domainInput"; +import { Component } from '../component'; +import { ComponentType } from '../componentTypes'; +import { DomainInput } from './domainInput'; export class Domain extends Component { - override get type(): ComponentType { - return ComponentType.domain; - } - override get id(): string { - return this.input.name; - } - override get abapgitSerializer(): string { - return 'LCL_OBJECT_DOMA'; - } - override toAbapgit() { - const input = this.input; - return { - DD01V: { - DOMNAME: input.name, - DDLANGUAGE: input.header?.originalLanguage, - DATATYPE: input.dataType, - LENG: input.length, - OUTPUTLEN: input.outputLength, - DDTEXT: input.header?.description, - }, - }; - } + override get type(): ComponentType { + return ComponentType.domain; + } + override get id(): string { + return this.input.name; + } + override get abapgitSerializer(): string { + return 'LCL_OBJECT_DOMA'; + } + override toAbapgit() { + const input = this.input; + return { + DD01V: { + DOMNAME: input.name, + DDLANGUAGE: input.header?.originalLanguage, + DATATYPE: input.dataType, + LENG: input.length, + OUTPUTLEN: input.outputLength, + DDTEXT: input.header?.description, + }, + }; + } } -export * from "./domainInput"; +export * from './domainInput'; diff --git a/packages/components/src/lib/components/doma/domainInput.ts b/packages/components/src/lib/components/doma/domainInput.ts index 87e2a2e..0940967 100644 --- a/packages/components/src/lib/components/doma/domainInput.ts +++ b/packages/components/src/lib/components/doma/domainInput.ts @@ -1,30 +1,30 @@ -import { DataTypes } from "./dataTypes"; -import { OutputStyle } from "./outputStyle"; +import { DataTypes } from './dataTypes'; +import { OutputStyle } from './outputStyle'; export interface DomainInput { - name: string; - formatVersion: "1"; - header?: { - description: string; - originalLanguage: string; - abapLanguageVersion?: "standard" | "keyUser" | "cloudDevelopment"; - }; - dataType: DataTypes; - length: number; - decimals?: number; - negativeValues?: boolean; - caseSensitive?: boolean; - outputLength?: number; - conversionRoutine?: string; - valueTable?: string; - fixedValues?: Array<{ - fixedValue: string; - description: string; - }>; - fixedValueIntervals?: Array<{ - lowLimit?: string; - highLimit: string; - description?: string; - }>; - outputStyle?: OutputStyle + name: string; + formatVersion: '1'; + header?: { + description: string; + originalLanguage: string; + abapLanguageVersion?: 'standard' | 'keyUser' | 'cloudDevelopment'; + }; + dataType: DataTypes; + length: number; + decimals?: number; + negativeValues?: boolean; + caseSensitive?: boolean; + outputLength?: number; + conversionRoutine?: string; + valueTable?: string; + fixedValues?: Array<{ + fixedValue: string; + description: string; + }>; + fixedValueIntervals?: Array<{ + lowLimit?: string; + highLimit: string; + description?: string; + }>; + outputStyle?: OutputStyle; } diff --git a/packages/components/src/lib/components/doma/outputStyle.ts b/packages/components/src/lib/components/doma/outputStyle.ts index 66012ad..cc93c08 100644 --- a/packages/components/src/lib/components/doma/outputStyle.ts +++ b/packages/components/src/lib/components/doma/outputStyle.ts @@ -8,11 +8,11 @@ // generate enum export enum OutputStyle { - NORMAL = '00', - SIGN_RIGHT = '01', - SCALE_PRESERVING = '02', - SCIENTIFIC = '03', - SCIENTIFIC_WITH_LEADING_ZERO = '04', - SCALE_PRESERVING_SCIENTIFIC = '05', - ENGINEERING = '06' -} \ No newline at end of file + NORMAL = '00', + SIGN_RIGHT = '01', + SCALE_PRESERVING = '02', + SCIENTIFIC = '03', + SCIENTIFIC_WITH_LEADING_ZERO = '04', + SCALE_PRESERVING_SCIENTIFIC = '05', + ENGINEERING = '06', +} diff --git a/packages/components/src/lib/components/dtel/dataElement.ts b/packages/components/src/lib/components/dtel/dataElement.ts index 8b45f2a..786e2b3 100644 --- a/packages/components/src/lib/components/dtel/dataElement.ts +++ b/packages/components/src/lib/components/dtel/dataElement.ts @@ -1,100 +1,105 @@ -import { Component } from "../component" -import { ComponentType } from "../componentTypes"; -import { DataElementInput } from "./dataElementInput"; -import { RefKind } from "./refKind"; -import { RefType } from "./refType"; - +import { Component } from '../component'; +import { ComponentType } from '../componentTypes'; +import { DataElementInput } from './dataElementInput'; +import { RefKind } from './refKind'; +import { RefType } from './refType'; export class DataElement extends Component { - override get type(): ComponentType { - return ComponentType.dataElement; - } - override get id(): string { - return this.input.name - } - override get abapgitSerializer(): string { - return 'LCL_OBJECT_DTEL'; - } - override toAbapgit() { - const input = this.input; - - const dtel = { - DD04V: { - ROLLNAME: input.name, - DDTEXT: input.description, - DDLANGUAGE: 'E', - SCRTEXT_S: input.labels?.short, - SCRTEXT_M: input.labels?.medium, - SCRTEXT_L: input.labels?.long, - REPTEXT: input.labels?.heading, - SCRLEN1: input.labels?.short?.length, - SCRLEN2: input.labels?.medium?.length, - SCRLEN3: input.labels?.long?.length, - HEADLEN: input.labels?.heading?.length, - DTELMASTER: 'E', - REFKIND: input.refKind - } - }; - - switch (input.refKind) { - - case RefKind.DOMAIN: - - { - const domain = typeof input.domain === "string" ? ({ name: input.domain }) : input.domain; - - Object.assign(dtel.DD04V, { - DOMNAME: domain?.name - }); - } - - break; - - case RefKind.REFERENCE: - - switch (input.refType) { - case RefType.BUILT_IN_DICTIONARY_TYPE: - - Object.assign(dtel.DD04V, typeof input.builtInType === "string" ? { - DOMNAME: input.builtInType - } : { - DOMNAME: input.builtInType.type, - LENG: input.builtInType.length, - OUTPUTLEN: input.builtInType.outputLength, - DECIMALS: input.builtInType.decimals - }) - - break; - - default: - - Object.assign(dtel.DD04V, { - REFTYPE: input.refKind, - DOMNAME: input.referencedType - }) - - break; - } - - break; - - case RefKind.DIRECT_TYPE_ENTRY: + override get type(): ComponentType { + return ComponentType.dataElement; + } + override get id(): string { + return this.input.name; + } + override get abapgitSerializer(): string { + return 'LCL_OBJECT_DTEL'; + } + override toAbapgit() { + const input = this.input; + + const dtel = { + DD04V: { + ROLLNAME: input.name, + DDTEXT: input.description, + DDLANGUAGE: 'E', + SCRTEXT_S: input.labels?.short, + SCRTEXT_M: input.labels?.medium, + SCRTEXT_L: input.labels?.long, + REPTEXT: input.labels?.heading, + SCRLEN1: input.labels?.short?.length, + SCRLEN2: input.labels?.medium?.length, + SCRLEN3: input.labels?.long?.length, + HEADLEN: input.labels?.heading?.length, + DTELMASTER: 'E', + REFKIND: input.refKind, + }, + }; + + switch (input.refKind) { + case RefKind.DOMAIN: + { + const domain = + typeof input.domain === 'string' + ? { name: input.domain } + : input.domain; + + Object.assign(dtel.DD04V, { + DOMNAME: domain?.name, + }); + } - Object.assign(dtel.DD04V, typeof input.builtInType === "string" ? { - DATATYPE: input.builtInType - } : { - DATATYPE: input.builtInType.type, + break; + + case RefKind.REFERENCE: + switch (input.refType) { + case RefType.BUILT_IN_DICTIONARY_TYPE: + Object.assign( + dtel.DD04V, + typeof input.builtInType === 'string' + ? { + DOMNAME: input.builtInType, + } + : { + DOMNAME: input.builtInType.type, LENG: input.builtInType.length, OUTPUTLEN: input.builtInType.outputLength, - DECIMALS: input.builtInType.decimals - }); + DECIMALS: input.builtInType.decimals, + } + ); - break; + break; + default: + Object.assign(dtel.DD04V, { + REFTYPE: input.refKind, + DOMNAME: input.referencedType, + }); + + break; } - return dtel; + break; + + case RefKind.DIRECT_TYPE_ENTRY: + Object.assign( + dtel.DD04V, + typeof input.builtInType === 'string' + ? { + DATATYPE: input.builtInType, + } + : { + DATATYPE: input.builtInType.type, + LENG: input.builtInType.length, + OUTPUTLEN: input.builtInType.outputLength, + DECIMALS: input.builtInType.decimals, + } + ); + + break; } + + return dtel; + } } -export * from "./dataElementInput"; +export * from './dataElementInput'; diff --git a/packages/components/src/lib/components/dtel/dataElementInput.ts b/packages/components/src/lib/components/dtel/dataElementInput.ts index c27703e..51bfb9c 100644 --- a/packages/components/src/lib/components/dtel/dataElementInput.ts +++ b/packages/components/src/lib/components/dtel/dataElementInput.ts @@ -1,52 +1,53 @@ -import { DataTypes } from "../doma/dataTypes" -import { RefKind } from "./refKind" -import { DomainInput } from "../doma/domainInput" -import { RefType } from "./refType" +import { DataTypes } from '../doma/dataTypes'; +import { RefKind } from './refKind'; +import { DomainInput } from '../doma/domainInput'; +import { RefType } from './refType'; interface BuiltInType { - type: DataTypes, - length?: number, - decimals?: number - outputLength?: number + type: DataTypes; + length?: number; + decimals?: number; + outputLength?: number; } interface DataElementInputBase { - name: string - description: string - labels?: { - short?: string, - medium?: string, - long?: string, - heading?: string - }, + name: string; + description: string; + labels?: { + short?: string; + medium?: string; + long?: string; + heading?: string; + }; } -export type DataElementInput = DataElementInputBase & ( +export type DataElementInput = DataElementInputBase & + ( | DataElementWithDomain | DataElementBuiltInType | DataElementReferencedType | DataElementRefToBuiltIn -) + ); interface DataElementWithDomain { - refKind: RefKind.DOMAIN, - domain: DomainInput | string + refKind: RefKind.DOMAIN; + domain: DomainInput | string; } interface DataElementBuiltInType { - refKind: RefKind.DIRECT_TYPE_ENTRY, - builtInType: BuiltInType | string + refKind: RefKind.DIRECT_TYPE_ENTRY; + builtInType: BuiltInType | string; } interface DataElementReferencedType { - refKind: RefKind.REFERENCE, - //refType exludicng builtin - refType: Exclude, - referencedType: string, + refKind: RefKind.REFERENCE; + //refType exludicng builtin + refType: Exclude; + referencedType: string; } interface DataElementRefToBuiltIn { - refKind: RefKind.REFERENCE, - refType: RefType.BUILT_IN_DICTIONARY_TYPE, - builtInType: BuiltInType | string -} \ No newline at end of file + refKind: RefKind.REFERENCE; + refType: RefType.BUILT_IN_DICTIONARY_TYPE; + builtInType: BuiltInType | string; +} diff --git a/packages/components/src/lib/components/dtel/refKind.ts b/packages/components/src/lib/components/dtel/refKind.ts index 81606f9..37e00e8 100644 --- a/packages/components/src/lib/components/dtel/refKind.ts +++ b/packages/components/src/lib/components/dtel/refKind.ts @@ -5,12 +5,11 @@ // R Reference Type // D Domain - export enum RefKind { - // ELEMENTARY = 'E', - // STRUCTURED = 'S', - // TABLE = 'L', - DIRECT_TYPE_ENTRY = '', - REFERENCE = 'R', - DOMAIN = 'D' -} \ No newline at end of file + // ELEMENTARY = 'E', + // STRUCTURED = 'S', + // TABLE = 'L', + DIRECT_TYPE_ENTRY = '', + REFERENCE = 'R', + DOMAIN = 'D', +} diff --git a/packages/components/src/lib/components/dtel/refType.ts b/packages/components/src/lib/components/dtel/refType.ts index bf83c48..01cf328 100644 --- a/packages/components/src/lib/components/dtel/refType.ts +++ b/packages/components/src/lib/components/dtel/refType.ts @@ -10,13 +10,13 @@ // I Interface export enum RefType { - ANY = 'A', - OBJECT = 'O', - DATA = 'D', - BUILT_IN_DICTIONARY_TYPE = 'B', - DATA_ELEMENT = 'E', - STRUCTURED_TYPE = 'S', - TABLE_TYPE = 'L', - CLASS = 'C', - INTERFACE = 'I' -} \ No newline at end of file + ANY = 'A', + OBJECT = 'O', + DATA = 'D', + BUILT_IN_DICTIONARY_TYPE = 'B', + DATA_ELEMENT = 'E', + STRUCTURED_TYPE = 'S', + TABLE_TYPE = 'L', + CLASS = 'C', + INTERFACE = 'I', +} diff --git a/samples/cds/src/build.test.ts b/samples/cds/src/build.test.ts index 0dd7557..3f35ab7 100644 --- a/samples/cds/src/build.test.ts +++ b/samples/cds/src/build.test.ts @@ -3,87 +3,89 @@ import * as cds from '@sap/cds'; import { dset } from 'dset'; import { AbapAnnotation } from './lib/annotations'; -import { Component, DataElement, DataElementInput, Domain, DomainInput } from '@abapify/components'; - +import { + Component, + DataElement, + DataElementInput, + Domain, + DomainInput, +} from '@abapify/components'; test('generate abapgit project from CDS model', async () => { - const model = await cds.load(__dirname + '/cds/model.cds'); - const generator = cds2abap(model); - - const abapComponents = new Map>(); + const model = await cds.load(__dirname + '/cds/model.cds'); + const generator = cds2abap(model); - function addComponent(component: Component) { + const abapComponents = new Map>(); - const componentId = `${component.type}/${component.id}`; + function addComponent(component: Component) { + const componentId = `${component.type}/${component.id}`; - if (abapComponents.has(componentId)) { - throw new Error(`Duplicate component ID: ${componentId}`); - } - abapComponents.set(componentId, component); + if (abapComponents.has(componentId)) { + throw new Error(`Duplicate component ID: ${componentId}`); } + abapComponents.set(componentId, component); + } - for (const annotation of generator) { - - const ddic = annotation['@abap']?.ddic; - - //data element - if (typeof ddic?.dataElement === 'object' && ddic.dataElement.generate) { - processDataElement(ddic.dataElement, ddic.dataElement.generate); - } - - //domain - if (typeof ddic?.domain === 'object' && ddic.domain.generate) { - processDomain(ddic.domain, ddic.domain.generate); - } + for (const annotation of generator) { + const ddic = annotation['@abap']?.ddic; + //data element + if (typeof ddic?.dataElement === 'object' && ddic.dataElement.generate) { + processDataElement(ddic.dataElement, ddic.dataElement.generate); } - for (const component of abapComponents.values()) { - console.log('\n', component.type, component.id, component.toAbapgitXML()); + //domain + if (typeof ddic?.domain === 'object' && ddic.domain.generate) { + processDomain(ddic.domain, ddic.domain.generate); } - - function processDataElement(dataElement: DataElementInput, generate?: boolean) { - - if (generate) { - const component = new DataElement(dataElement); - addComponent(component); - } - - if ('domain' in dataElement && typeof dataElement.domain === "object" && 'generate' in dataElement.domain) { - processDomain(dataElement.domain, generate); - } - + } + + for (const component of abapComponents.values()) { + console.log('\n', component.type, component.id, component.toAbapgitXML()); + } + + function processDataElement( + dataElement: DataElementInput, + generate?: boolean + ) { + if (generate) { + const component = new DataElement(dataElement); + addComponent(component); } - function processDomain(domain: DomainInput, generate?: boolean) { - if (generate) { - const component = new Domain(domain); - addComponent(component); - } + if ( + 'domain' in dataElement && + typeof dataElement.domain === 'object' && + 'generate' in dataElement.domain + ) { + processDomain(dataElement.domain, generate); } + } + function processDomain(domain: DomainInput, generate?: boolean) { + if (generate) { + const component = new Domain(domain); + addComponent(component); + } + } }); function* cds2abap(csn: cds.csn.CSN) { + for (const definition_key in csn.definitions) { + const definition = csn.definitions[definition_key]; - for (const definition_key in csn.definitions) { - const definition = csn.definitions[definition_key]; - - for (const element_key in definition.elements) { - const element = definition.elements[element_key]; + for (const element_key in definition.elements) { + const element = definition.elements[element_key]; - const properties: Record = {}; - - for (const property_key in element) { - if (Object.prototype.hasOwnProperty.call(element, property_key)) { - const property = element[property_key as keyof typeof element]; - dset(properties, property_key, property); - } - } - - yield (properties as unknown as AbapAnnotation); + const properties: Record = {}; + for (const property_key in element) { + if (Object.prototype.hasOwnProperty.call(element, property_key)) { + const property = element[property_key as keyof typeof element]; + dset(properties, property_key, property); } - } + } + yield properties as unknown as AbapAnnotation; + } + } } - diff --git a/samples/cds/src/lib/annotations.ts b/samples/cds/src/lib/annotations.ts index f26f25a..deec2ca 100644 --- a/samples/cds/src/lib/annotations.ts +++ b/samples/cds/src/lib/annotations.ts @@ -1,15 +1,15 @@ -import { DomainInput } from "@abapify/components" -import { DataElementInput } from "@abapify/components" +import { DomainInput } from '@abapify/components'; +import { DataElementInput } from '@abapify/components'; // create generic type GeneratorInput extending the given type with { generate?: true } -type GeneratorInput = T & { generate?: true } +type GeneratorInput = T & { generate?: true }; export interface AbapAnnotation { - '@abap': { - ddic?: { - dataElement?: GeneratorInput | string, - domain?: GeneratorInput | string, - } - } -} \ No newline at end of file + '@abap': { + ddic?: { + dataElement?: GeneratorInput | string; + domain?: GeneratorInput | string; + }; + }; +} diff --git a/samples/cds/src/lib/objectList.ts b/samples/cds/src/lib/objectList.ts index 72b4251..f1a64ed 100644 --- a/samples/cds/src/lib/objectList.ts +++ b/samples/cds/src/lib/objectList.ts @@ -1,14 +1,14 @@ -import { ObjectTypes } from "./objectTypes" -import { Domain, DataElement } from "@abapify/components" +import { ObjectTypes } from './objectTypes'; +import { Domain, DataElement } from '@abapify/components'; -export type ObjectList = Array +export type ObjectList = Array; interface DomainItem { - type: ObjectTypes.domain, - domain: Domain + type: ObjectTypes.domain; + domain: Domain; } interface DataElementItem { - type: ObjectTypes.dataElement, - dataElement: DataElement -} \ No newline at end of file + type: ObjectTypes.dataElement; + dataElement: DataElement; +} diff --git a/samples/cds/src/lib/objectTypes.ts b/samples/cds/src/lib/objectTypes.ts index 8f57e0a..be341a7 100644 --- a/samples/cds/src/lib/objectTypes.ts +++ b/samples/cds/src/lib/objectTypes.ts @@ -1,4 +1,4 @@ export enum ObjectTypes { - domain, - dataElement -} \ No newline at end of file + domain, + dataElement, +}