Giter VIP home page Giter VIP logo

Comments (6)

tywalch avatar tywalch commented on May 23, 2024 2

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.

DASPRiD avatar DASPRiD commented on May 23, 2024 1

@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.

tywalch avatar tywalch commented on May 23, 2024 1

Thank you three for bring this up, I will have a fix in this week πŸ‘

from electrodb.

tywalch avatar tywalch commented on May 23, 2024

Two items:

  1. This is value is added deliberately, could you describe your use case?
  2. 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.

asquithea avatar asquithea commented on May 23, 2024

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 missing
  • requestedConfiguration - desired state of the other system; null/missing = undeploy wanted
  • activeConfiguration - 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.

RobbeCl avatar RobbeCl commented on May 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.