cap-js / cds-typer

CDS type generator for JavaScript
Apache License 2.0
26 stars 8 forks source link

[BUG] Augmented projection does not supply types #101

Closed TruLov closed 9 months ago

TruLov commented 11 months ago

Is there an existing issue for this?

Nature of Your Project

JavaScript, TypeScript

Current Behavior

Currently, when I extend an external service with a custom association, it is not included in the .d.ts files generated by cds-typer. It seems that the select on the projection is not even taken into account by cds-typer.

Expected Behavior

I expect that when I either restrict a service projection with a select or extend it with new fields/expands, it should be considered by cds-typer.

Steps To Reproduce

One can reproduce the behaviour with the ext-service-consume-ui branch in the Risk Management Sample:

  1. Clone the sample branch and add cds-typer:

    git clone --branch ext-service-consume-ui https://github.com/SAP-samples/cloud-cap-risk-management.git
    cd cloud-cap-risk-management
    cds add typer
    npm i
  2. add an association to the Suppliers entity (it is not necessary, because the select will also not be generated):

    entity Suppliers as projection on bupa.A_BusinessPartner {
    key BusinessPartner          as ID,
        BusinessPartnerFullName  as fullName,
        BusinessPartnerIsBlocked as isBlocked,
    +      to_Risks : Association to many Risks on to_Risks.supplier = $self
    }
  3. generate types

    npx @cap-js/cds-typer '*' --outputDirectory @cds-models
  4. Check the generated Types

export function _SupplierAspect<TBase extends new (...args: any[]) => object>(Base: TBase) {
  return class Supplier extends Base {
    /**
    * Key identifying a business partner in the SAP system. The key is unique within a client.
    */
        BusinessPartner?: string;
    /**
    * Gives an alphanumeric key, which clearly identifies the customer or vendor in the SAP system.
    */
        Customer?: string;
    /**
    * Specifies an alphanumeric key that uniquely identifies the supplier in the SAP system.
    */
        Supplier?: string;
    /**
    * Key for academic title.
    * 
    * You can define a key for an academic title in Customizing.
    */
        AcademicTitle?: string;
    /**
    * You can use authorization groups to stipulate which business partners a user is allowed to process.
    * 
    * Use the following authorization object:'Business partners: authorization groups' (B_BUPA_GRP).The system only checks this authorization if you made an entry in the &quot;Authorization group&quot; field for the business partner. Otherwise, any user may process the business partner.
    */
        AuthorizationGroup?: string;
    /**
    * Category under which a business partner is classified.
    * 
    * You can distinguish between the following business partner categories:OrganizationNatural personGroup of natural persons or organizationsThe processing screens for the business partner categories are set up differently.So, for example, the screen for an organization contains the field Legal form, but this is not needed in the screen for a natural person.
    */
        BusinessPartnerCategory?: string;
        BusinessPartnerFullName?: string;
    /**
    * Classification assigned when creating a business partner.
    * 
    * Assign each business partner to a grouping when you create the business partner. The grouping determines the number range. You cannot change the assignment afterwards.You can define the groupings, their descriptions, the associated number range and other attributes in Customizing.You can define standard groupings for the internal and the external number assignment.For each grouping create a number range.When you create a business partner, the entry in the grouping field determines whether and how an entry is made in the business partner number field.
    */
        BusinessPartnerGrouping?: string;
        BusinessPartnerName?: string;
        BusinessPartnerUUID?: string;
    /**
    * Correspondence language (written) for business partners in the 'Person' category. Maintain the correspondence language for business partners in the 'Organization' and 'Group' category with the address (communication).
    * 
    * When transferring data (direct input), make sure that for a'Person', the field 'LANGU_CORR' and for an'Organization' or &quot;Group&quot; the field 'LANGU'has an entry.
    */
        CorrespondenceLanguage?: string;
        CreatedByUser?: string;
        CreationDate?: string;
        CreationTime?: string;
        FirstName?: string;
    /**
    * Key for form of address text.
    * 
    * You can also define a form of address text in Customizing.The form of address text can be maintained in different languages.
    */
        FormOfAddress?: string;
    /**
    * An industry sector is the term used to classify a company according to its main business activity.
    * 
    * You can assign an industry sector to business partners in the category 'Organization'RetailBanksServicesIndustryHealth servicePublic sectorMedia
    */
        Industry?: string;
    /**
    * Here you enter the first 7 digits of the international location number.
    * 
    * The International Location Number (ILN) is assigned (in Germany by the Centrale for Coorganisation GmbH)) when a company is founded. It consists of 13 digits, the last digit being the check digit. There are two categories of location numbers:Participants who only need an ILN to cleary and unmistakably identify themselves for communication with the business partner are given a category 1 ILN. This cannot be used to identify articles by means of EAN.Participants who wish to assign the location numbers for their own enterprise areas are given a category 2 ILN. For a category 2 ILN, digits 1 to 7 are described as basis number. This is used as basis for the creation of article numbers (EAN).
    */
        InternationalLocationNumber1?: string;
    /**
    * Here, you enter digits 8-12 of the 13-digit international location number.
    * 
    * The international location number (ILN) is assigned when establishing a company (by the &quot;Zentrale für Coorganisation GmbH&quot; in Germany). It consists of 13 digits, the last of which is the check digit. There are two types of international location numbers:Subscribers who only need one ILN to identify themselves in communication with the business partner are given an ILN of type 1. These cannot be used for identifying articles by means of EAN.Subscribers who need to assign location numbers for their own company areas are given an ILN of type 2. Positions 1 through 7 of the ILN type 2 are known as the basis number. This basis number forms the basis for article numbers (EAN).
    */
        InternationalLocationNumber2?: string;
        IsFemale?: boolean;
        IsMale?: boolean;
    /**
    * Indicator through which a distinction between natural and legal persons can be made during tax reporting.
    * 
    * Is used in Italy and Mexico ,among other countries.Brasil: If the indicator is not set, 'CGC' is relevant in tax number 1. If the indicator is set, 'CPF' is relevant in tax number 2.Colombia: In the case of some natural persons, the NIT number does not have a check digit. In this case you should set this indicator and the check is deactivated.
    */
        IsNaturalPerson?: string;
        IsSexUnknown?: boolean;
        GenderCodeName?: string;
    /**
    * Language for verbal communication with a business partner.
    * 
    * This language may differ from the language(s) defined for written correspondence.
    */
        Language?: string;
        LastChangeDate?: string;
        LastChangeTime?: string;
        LastChangedByUser?: string;
        LastName?: string;
    /**
    * Denotes certain legal norms that are of significance for the organization of a company.
    * 
    * For business partners in the category &quot;Organization&quot;, you can state the legal form of the company. This is for information purposes only.Stock corporation (AG in Germany)Limited liability company (GmbH in Germany)
    */
        LegalForm?: string;
    /**
    * First name field for business partners in the Organization category.
    */
        OrganizationBPName1?: string;
    /**
    * Second name field for business partners in the Organization category.
    */
        OrganizationBPName2?: string;
    /**
    * Third name field for business partners in the Organization category.
    */
        OrganizationBPName3?: string;
    /**
    * Fourth name field for business partners in the Organization category.
    */
        OrganizationBPName4?: string;
    /**
    * Indicates the official registration of a company in the Commercial Register.
    * 
    * If a company is not officially registered in the Commercial Register, it has to use some type of text addition, such as foundation pending, when referring to the legal form.
    */
        OrganizationFoundationDate?: string;
    /**
    * Term for the end of bankruptcy proceedings.
    * 
    * This date also indicates that the company no longer exists.
    */
        OrganizationLiquidationDate?: string;
    /**
    * Denotes the term that you define for a business partner, and via which you can restrict the search for a business partner in the business partner search or in the locator.
    */
        SearchTerm1?: string;
    /**
    * Denotes the term that you define for a business partner, and via which you can restrict the search for a business partner in the business partner search or in the locator.
    */
        SearchTerm2?: string;
        AdditionalLastName?: string;
        BirthDate?: string;
    /**
    * If the Business partner's actual birthdate is unknown, a partial entry can be made or read. This field then indicates which part of the birthdate is unknown. Below are some examples (Dates are specified in format MM/DD/YYYY):
    * 
    * 01/01/0000 => 01/01/1880 Year unknown00/01/1911 => 01/01/1911 Month unknown05/00/1911 => 05/01/1911 Day unknown05/05/1911 => 05/05/1911 Fully known00/00/1911 => 05/05/1911 Day & Month unknown00/05/0000 => 05/05/1911 Month & Year unknown05/00/0000 => 05/05/1911 Day & Year unknown00/00/0000=> 05/05/1911 Fully unknown'Date of Birth: Status' field determines the unknown parts of birthdate.Enter a valid date under Birthdate. Future dates are not accepted. If any part/s of the date is/are unknown, select the nearest date.If year is unknown, select any random valid year.
    */
        BusinessPartnerBirthDateStatus?: string;
        BusinessPartnerBirthplaceName?: string;
        BusinessPartnerDeathDate?: string;
    /**
    * If the business partner is blocked centrally, certain activities cannot be executed.
    */
        BusinessPartnerIsBlocked?: boolean;
    /**
    * You can use the business partner type to group business partners according to your own criteria in Customizing (IMG).
    * 
    * In Customizing you can show or hide fields for data entry, depending on the requirements of the relevant business partner type.Select a business partner type. You can obtain help by pressing the F4 key.
    */
        BusinessPartnerType?: string;
        ETag?: string;
    /**
    * First name field for business partners in the Group category.
    */
        GroupBusinessPartnerName1?: string;
    /**
    * Second name field for business partners in the Group category.
    */
        GroupBusinessPartnerName2?: string;
    /**
    * Internal key for identifying the address for communication data that spans all addresses in Business Partner.
    * 
    * For more information on the significance and usage of the address number, see the documentation for Business Address Services (BAS).
    */
        IndependentAddressID?: string;
    /**
    * The check digit is derived from a special check digit procedure from digits of the previous international location numbers. In this way, you can check whether the ILN entered is actually valid.
    */
        InternationalLocationNumber3?: string;
        MiddleName?: string;
    /**
    * The country/region for the name format rule and the name format rule key together uniquely identify a formatting rule.
    * 
    * A country/region can have several formats which correspond to different rules. You need formatting rules to describe the composition of a person's name.
    */
        NameCountry?: string;
    /**
    * See Name format.
    */
        NameFormat?: string;
    /**
    * States the complete name of a person.
    * 
    * The complete name is generally generated and saved by the Business Address Services (BAS) according to country-specific rules from the individual name components (without the form of address).If, during the formatting of an address, you want to use an alternative name, you can manually format the alternative name here.
    */
        PersonFullName?: string;
    /**
    * Internal key for identifying a person in Business Address Services.
    * 
    * For more information about the meaning and use of the person number and Business Address Services concepts, see the function group SZA0 documentation.
    */
        PersonNumber?: string;
    /**
    * Establishes if the business partner is meant to be archived.
    * 
    * If the indicator is set, the relevant business partner can be archived from the view of the business partner administration.If the check of the data to be archived shows, for example, that there are still active business transactions the archiving of the business partner data is prevented even if the indicator is set.If the indicator is not set, the business partner will not be taken into consideration during archiving.
    */
        IsMarkedForArchiving?: boolean;
    /**
    * Business partner number from an external system or a legacy system.
    * 
    * If the current business partner is known under a different number in an external system, you can store this number here for information purposes.Direct input gives you the option of maintaining a business partner by specifying the external business partner number. If you maintain business partner data in your legacy system, you can transmit changes made to business partners to the SAP system without having to know the SAP business partner number in the legacy system.
    */
        BusinessPartnerIDByExtSystem?: string;
    /**
    * Company ID standard for the whole group.
    */
        TradingPartner?: string;
    /**
    * Please add  an ON condition
    */
        to_BuPaIdentification?: __.Association.to.many<_API_BUSINESS_PARTNER.A_BuPaIdentification_>;
    /**
    * Key identifying a business partner in the SAP system. The key is unique within a client.
    */
        to_BuPaIdentification_BusinessPartner?: string;
    /**
    * A document (such as an ID card or driver's license) or an entry in a system of records (such as a commercial register) whose key can be stored as an attribute for a business partner.
    * 
    * The identification type is for classifying identification numbers.You can define the identification types and their descriptions in Customizing.You can also specify for which business partner category an ID type should be valid.If necessary, assign the identification type to an Identification Category.You can only assign one identification type to an identification category.
    */
        to_BuPaIdentification_BPIdentificationType?: string;
    /**
    * Number that serves to identify a business partner, such as driver's license, or ID card number.
    */
        to_BuPaIdentification_BPIdentificationNumber?: string;
    /**
    * Please add  an ON condition
    */
        to_BuPaIndustry?: __.Association.to.many<_API_BUSINESS_PARTNER.A_BuPaIndustry_>;
    /**
    * Describes an industry.
    * 
    * An industry is a classification of companies according to their main business activity. For example, you can use Commerce, Banking, Services, Industry, Healthcare, Public Sector, Media, and so on, as industries.You can define industries along with their descriptions in Customizing.Assign the industry key to an industry key system.
    */
        to_BuPaIndustry_IndustrySector?: string;
    /**
    * Serves to combine and categorize several industries into a group.
    * 
    * You can create different industry systems, each with its own catalog of industries, whereby an industry can be assigned to several industry systems.You have to select one industry system as the standard industry system. This is then automatically displayed in the initial screen for the maintenance of industry data.You can define an industry system along with its description in Customizing. You can assign several industry systems to a business partner.If you choose the button All Industry Systems, you can access all the industry systems defined in the Customizing using the input help.
    */
        to_BuPaIndustry_IndustrySystemType?: string;
    /**
    * Key identifying a business partner in the SAP system. The key is unique within a client.
    */
        to_BuPaIndustry_BusinessPartner?: string;
    /**
    * Please add  an ON condition
    */
        to_BusinessPartnerAddress?: __.Association.to.many<_API_BUSINESS_PARTNER.A_BusinessPartnerAddress_>;
    /**
    * Key identifying a business partner in the SAP system. The key is unique within a client.
    */
        to_BusinessPartnerAddress_BusinessPartner?: string;
    /**
    * Internal key for identifying a Business Address Services address.
    * 
    * For more information about the meaning and use of the address number and the Business Address Services concepts, see the function group SZA0 documentation.
    */
        to_BusinessPartnerAddress_AddressID?: string;
    /**
    * Please add  an ON condition
    */
        to_BusinessPartnerBank?: __.Association.to.many<_API_BUSINESS_PARTNER.A_BusinessPartnerBank_>;
    /**
    * Key identifying a business partner in the SAP system. The key is unique within a client.
    */
        to_BusinessPartnerBank_BusinessPartner?: string;
    /**
    * Key identifying a business partner's bank details.
    * 
    * Enter a bank details ID for each separate set of bank details for a business partner.Business Partner: H. MillerBD-ID Fin.institution Acct no. 0001 Chemical Bank, NYC 56234560002 Chemical Bank, NYC 56231220003 First Bank of Pittsburgh ...Business partner: T.Wolsey and Co.BD-ID Fin.institution Acct no.GIR0 Citibank, Charleston ...GIR1 Chemical Bank, NYC ...
    */
        to_BusinessPartnerBank_BankIdentification?: string;
    /**
    * Please add  an ON condition
    */
        to_BusinessPartnerContact?: __.Association.to.many<_API_BUSINESS_PARTNER.A_BusinessPartnerContact_>;
    /**
    * The business partner relationship number is an internal number that identifies the business partner relationship set.
    */
        to_BusinessPartnerContact_RelationshipNumber?: string;
    /**
    * Key identifying a business partner in the SAP system. The key is unique within a client.
    */
        to_BusinessPartnerContact_BusinessPartnerCompany?: string;
    /**
    * Key identifying a business partner in the SAP system. The key is unique within a client.
    */
        to_BusinessPartnerContact_BusinessPartnerPerson?: string;
        to_BusinessPartnerContact_ValidityEndDate?: string;
    /**
    * Please add  an ON condition
    */
        to_BusinessPartnerRole?: __.Association.to.many<_API_BUSINESS_PARTNER.A_BusinessPartnerRole_>;
    /**
    * Key identifying a business partner in the SAP system. The key is unique within a client.
    */
        to_BusinessPartnerRole_BusinessPartner?: string;
    /**
    * Function that a business partner takes on, depending on a business transaction.
    * 
    * You can define business partner roles along with their attributes in Customizing.You can create an alphanumeric, 6-digit key for the BP role. You can also choose a title as the short form and a description as the long form for the role text.Screen control in the dialog takes place by assigning a BP view.A program can access specific business partner roles for a business partner using thebusiness partner role category . The role categories are also in the TB003 table.
    */
        to_BusinessPartnerRole_BusinessPartnerRole?: string;
    /**
    * Please add  an ON condition
    */
        to_BusinessPartnerTax?: __.Association.to.many<_API_BUSINESS_PARTNER.A_BusinessPartnerTaxNumber_>;
    /**
    * Key identifying a business partner in the SAP system. The key is unique within a client.
    */
        to_BusinessPartnerTax_BusinessPartner?: string;
    /**
    * Specifies the tax number category.
    */
        to_BusinessPartnerTax_BPTaxType?: string;
    /**
    * Please add  an ON condition
    */
        to_Customer?: __.Association.to<_API_BUSINESS_PARTNER.A_Customer>;
    /**
    * Gives an alphanumeric key, which clearly identifies the customer or vendor in the SAP system.
    */
        to_Customer_Customer?: string;
    /**
    * Please add  an ON condition
    */
        to_Supplier?: __.Association.to<_API_BUSINESS_PARTNER.A_Supplier>;
    /**
    * Specifies an alphanumeric key that uniquely identifies the supplier in the SAP system.
    */
        to_Supplier_Supplier?: string;
      static actions: {
    }
  };
}
export class Supplier extends _SupplierAspect(__.Entity) {}

Environment

- **OS**:
- **Node**: v18.18.0
- **npm**: 9.8.1
- **cds-typer**: 0.11.1
- **cds**: 6.8.4

Repository Containing a Minimal Reproducible Example

No response

Anything else?

No response

TruLov commented 11 months ago

As I'm debugging my way through the source code, maybe the problem is that cds-typer is working with the xtended falvour of CSN instead of the inferred, as stated in the visitor.js:visitDefinitions()?

Maybe I am on the wrong track here, but I wanted to add this to my request. Below you find a Screenshot with the difference between inferred and xtended CSN for the Risk Management Sample from above.

If I can support here, please let me know

BR Tom

image
naferok commented 11 months ago

Hi, i am currently trying to solve a problem similar to yours, but i have as select from with joins. image

but looking at solution with providing additional arguments on runtime image image

and propagate to compile csn image

try test, maybe its better for us to expand this part with arguments?

TruLov commented 11 months ago

Hi naferok,

I tried your suggestion and it looks good. As I suspected, I need the inferred-flavor in my current project.

Your suggestion to pass the flavor through sounds reasonable to me, but I can't evaluate whether this might cause problems elsewhere.

I will continue follow the idea of the inferred flavor.

BR Tom

TruLov commented 11 months ago

Hi naferok,

I've implemented the proposed changes in a forked repo, which is currently passing all the tests. Please feel free to have a look into it, so we can eventually open a PR for this.

BR Tom

github-actions[bot] commented 9 months ago

This issue has not been updated in a while. If it is still relevant, please comment on it to keep it open. The issue will be closed soon if it remains inactive.

github-actions[bot] commented 9 months ago

This issue has been closed automatically due to inactivity.