cap-js / cds-typer

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

[BUG] cds.entities not a function #335

Open GoldSucc opened 2 hours ago

GoldSucc commented 2 hours ago

Is there an existing issue for this?

Nature of Your Project

TypeScript

Current Behavior

const csn = cds.entities('EquipmentService') this is a part of generated file (js). in cds source I see that entities is actually object export class entity extends struct<'entity'> in runtime error happens when interaction with service happens:

    const equipmentService = await connect.to(EquipmentService);
    const query = SELECT.one.from(Equipment, "10000002");
    const equipment = (await equipmentService.run(query)) as Equipment;

because js file is used

Expected Behavior

proper generation of js counterpart

Steps To Reproduce

  1. Define service cds with entity
  2. Generate types
  3. Build (tsc)
  4. Query service in typed fashion as I shown in previous sections

Environment

- **OS**: MacOS 14
- **Node**: 22.8
- **npm**: 10.8
- **cds-typer**: 0.26
- **cds**: 8.2.2

Repository Containing a Minimal Reproducible Example

No response

Anything else?

No response

GoldSucc commented 2 hours ago

Note: replacing types with string:

    const equipmentService = await connect.to("EquipmentService");
    const query = SELECT.one.from("Equipment", "10000002");
    const equipment = (await equipmentService.run(query)) as Equipment;

fixes error. so it is definitely generated file error const csn = cds.entities('EquipmentService')