-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] Why entity.association('*') is not same as entity?.association?.('*') in cds-typer? #223
Comments
@chgeo do you know why? Can it be a bug? Thanks! |
Hi Petr, thanks for filing this issue. I have transferred it to https://github.com/cap-js/cds-types as this is likely related to the types for the cds runtime, and probably has nothing to do with the generation of types for your model (cds-typer). Can you share the type definition of Best, |
@daogrady THank you for looking into the issue. Types are generated - you can see them in a published package: https://www.npmjs.com/package/hana2cds?activeTab=code Here is the source: Here is the place causing the error: |
@sjvans / @johannes-vogel o.view((v /* type: { columns: Association to many { ... } } */) => {
v('*');
v?.columns?.('*');
}); the error seems to be thrown at runtime from the db-service module (see stacktrace in original post). Could you please have a look? Thanks! |
@patricebender should be able to assist |
Hi @ThePlenkov, please provide steps to reproduce the error:
Thank you |
@patricebender Hi Patrcie, of course. Here it is:
You will see that there will be two tests, one is working ( with conditional guards ) and one is not working with optional notation. |
@ThePlenkov thanks for providing the sample, I was able to reproduce the issue. @sjvans i looks like an issue with the query builder API: const query = SELECT.from(OBJECTS, (o) => {
o.OBJECT_TYPE, o.OBJECT_OID, o.SCHEMA_NAME, o.OBJECT_NAME;
o?.view?.((t) => {
t("*");
t?.columns?.("*");
});
});
console.log(JSON.stringify(query, null, 2)); yields: {
"SELECT": {
"from": {
"ref": [
"OBJECTS"
]
},
"columns": [
{
"ref": [
"OBJECT_TYPE"
]
},
{
"ref": [
"OBJECT_OID"
]
},
{
"ref": [
"SCHEMA_NAME"
]
},
{
"ref": [
"OBJECT_NAME"
]
},
{ // from here on, the query looks very wrong 💥
"ref": [
"call"
],
"as": "undefined"
},
{
"ref": [
"raw"
]
},
{
"ref": [
"0"
]
},
{
"ref": [
null,
"next",
"done"
],
"expand": [
"*"
]
}
]
}
} → |
@patricebender may be we can label then it as a bug, not question, thanks! |
I also thought of something - why is it even optional? I mean if it's non-optional on the type level, then it's not even the error for TS. What could be the cases when some column references are undefined in the projection function? |
@patricebender can you please assign this issue to someone who is familiar with the query builder api? Thanks! |
i added it to the team backlog |
Hi, The projection function only allows specific operations:
It allows you to statically define which columns of your entity you want to select. Technically, a JavaScript Proxy is used to execute some logic once a certain field is accessed, e.g. in SELECT.from(MyEntity, e => { e.ID /* <-- field access */ }) There must not be any conditional operator and there shouldn't be a need for it. The corresponding TypeScript type should not complain that some properties might be undefined. It must be possible to follow every navigation of that entity, without checking for its existence. For example, it must be possible to write const result = await SELECT.from(OBJECTS, (o) => {
o.OBJECT_TYPE, o.OBJECT_OID, o.SCHEMA_NAME, o.OBJECT_NAME,
o.view((v) => {
v('*'),
v.columns('*');
});
}) @daogrady , do you think we can make sure that the above code works w.r.t. TypeScript? |
Hi David, thanks for weighing in on this! I guess we should be able to express that properties, in the context of projections, are not optional. I will look into it. Best, |
Question
HI! I have q very weird issue in my project.
Let's say i have a code like this:
By default it won't run because of the TS error:
So here are two possible ways how to solve it:
and it works
and this doesn't work!
Here is what I have in the console:
Do you know why? Thank you!
The text was updated successfully, but these errors were encountered: