Comments (6)
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 π
from electrodb.
@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.
from electrodb.
Thank you three for bring this up, I will have a fix in this week π
from electrodb.
Two items:
- This is value is added deliberately, could you describe your use case?
- Your example uses βanyβ attributes with a map which is currently not supported and could likely result in issues. I had thought the typing and validation did not allow this but I will also need to look into that.
from electrodb.
Sure. In this project, the presence of the attribute is treated like a typical nullable variable:
- if it's there, do the thing
- if it's not there, don't do the thing
Concretely, the attributes represent some semi-structured configuration to be synchronized with a loosely-coupled system.
configuration
- currently saved configuration, initially missingrequestedConfiguration
- desired state of the other system; null/missing = undeploy wantedactiveConfiguration
- reported state of the other system; null/missing = undeploy achieved
So the presence is used to indicate whether the deployment should be active.
I have some other examples, like an attribute that either contains a filled out report object, or no report object at all.
Regarding any
, each config map contains both some well-structured data, but also some arbitrary properties to be passed along. Kinda like this:
interface DeploymentConfiguration<P> {
authentication: DeploymentAuthentication; // strongly typed and required
systemProperties: P | undefined; // arbitrary system-specific properties
}
So in summary there is a well-defined object containing an island of arbitrary data. Let's say authentication
is required so DeploymentConfiguration
object can't be partially initialized - either the whole thing is present, or it's not.
This seems like it should be representable in the schema:
attributes: {
configuration: {
type: "map",
required: false,
properties: {
authentication: {
type: "map",
properties: authProperties,
required: true,
},
systemProperties: {
type: "any",
required: false,
},
},
},
}
It generates the correct type signature, with the configuration
attribute being defn | undefined
and the authentication
property being non-nullable, but then contradicts that type signature by initializing without authentication
defined - something that would not be accepted if I called .set(...)
with the same argument.
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 get
returning an empty object, so it's possible I've just stumbled into my first example of something you've used widely as a convention maybe prior to adding Typescript types, so maybe not changable.
One possible workaround for me would be something like:
configuration: {
type: "map",
properties: configProperties,
set: (a) => (_.isEmpty(a) ? undefined : a),
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 configuration
(and friends) attributes any
since I don't need to be able to query on the contents, but obviously that may not be the case for some use cases.
from electrodb.
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.
from electrodb.
Related Issues (20)
- Feature request: Add Conditional Indexing Based on Attribute Presence HOT 2
- Missing `add` Method in Upsert for Transactional Writes HOT 2
- Table in Section "Attribute Options" malformed HOT 1
- Numeric sort key being ignored when building query params on a query operation. HOT 1
- Feature Request: BatchWrite across entities HOT 2
- UpdateExpression created by `.patch` doesn't account for custom attribute `field` value HOT 3
- ExpressionAttributeNames/Values can include hyphens HOT 5
- Modeling single-partition data HOT 2
- ElectroDB playground: After Page Load, the caret in code-editor is not aligned with the letters sometimes
- Specifying `response: 'all_new'` on `.update()` returns `Partial<T>` instead of `T` HOT 2
- Broken link in docs (Pagination) HOT 2
- Improve schema type using const type parameters
- Removing attributes with upsert HOT 9
- Invalid params generated for patch/update where table/GSI specified with Composite Attribute Templates HOT 1
- Typescript Warning when Omitting Non Required Attributes on Create/ Put HOT 2
- How to create a map attribute with unknown keys? HOT 2
- How to get cursor for each item returned by a query? HOT 3
- How does it work with Python? HOT 2
- Filter expressions: Where In operation
- Malformed cursor causing issues with paginated queries HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electrodb.