-
Notifications
You must be signed in to change notification settings - Fork 57
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
map fields are always initialized to {}
even when not required and not defined
#144
Comments
Two items:
|
Sure. In this project, the presence of the attribute is treated like a typical nullable variable:
Concretely, the attributes represent some semi-structured configuration to be synchronized with a loosely-coupled system.
So the presence is used to indicate whether the deployment should be active. Regarding
So in summary there is a well-defined object containing an island of arbitrary data. Let's say This seems like it should be representable in the schema:
It generates the correct type signature, with the Hopefully that's clear enough. Apologies if I'm not seeing the wood for the trees. I've done a couple of projects in straight DynamoDB so far, but there are so many gotchas (e.g. many reserved words) that only really emerge during testing, whereas your library deals with a lot of that up front. I did see your note about previous behaviour of One possible workaround for me would be something like:
But it looks like this should be the default behaviour, otherwise the generated types don't match the initial value. I can probably also get away with just making the entire |
@tywalch We ran into the same issue. Is there a reason why this issue was closed? We'd like to have a map object (with required fields in it if it is present) on our entity, but be able to omit the object. Right now, the empty object breaks the Typescript typings. |
We are having the same issue. We have a few different user types and we store them all in the same User schema. A normal user has an Address map property, but an admin does not. Now the admin ends up with an empty object in the attribute Address and we like it to be undefined. |
Thank you three for bring this up, I will have a fix in this week 👍 |
This was addressed with the following PR: #168 I'll close this issue for now, but if anything comes up feel free to reopen and I'll make it a priority to address 👍 |
Describe the bug
Given an entity like this:
and initialization code like this:
I had expected only the
tenantName
field to be initialized.However,
configuration
is initialized to an empty map:I was surprised by this behaviour, and it broke a design that assumed the presence or otherwise of this field had meaning (something I can probably work around).
ElectroDB Version
1.11.1
ElectroDB Playground Link
Playground Link
Entity/Service Definitions
See above.
Expected behavior
I expected the field (e.g.
configuration
) to be absent until it was initialized.Errors
n/a
Additional context
Speculation:
Haven't tried to seriously debug, but at first glance the
_makeSet
method for theMapAttribute
in schema.js looks suspect in the way it creates an emptydata
object which is always returned.The text was updated successfully, but these errors were encountered: