Coder Social home page Coder Social logo

Comments (4)

copleykj avatar copleykj commented on July 18, 2024 1

It seems to me that this could be easily solved by just having two top level fields, updatedAt and updatedBy. Keeping anything else from modifying the field is as simple as calling unset if the operation isn't an update or upsert.

new SimpleSchema({
  updatedAt: {
    type: Date,
    autoValue() {
      if (this.isUpdate || this.isUpsert) {
        return new Date();
      }
      this.unset();
    },
    optional: true,
  },
  updatedBy: {
    type: SimpleSchema.RegEx.Id,
    autoValue() {
      if (this.isUpdate || this.isUpsert) {
        return this.userId;
      }
      this.unset();
    },
    optional: true,
  },
});

from meteor-collection2.

harryadel avatar harryadel commented on July 18, 2024

Indeed, it feels quite verbose versus a much intuitive schema you provided. I'd happily accept a PR that updates the docs.

We could definitely provide certain helpers like https://github.com/aldeed/meteor-schema-deny denyInsert and denyUpdate that'd help with your use case. But I'm unsure whether we should add those changes to collection2 or have them in a separate package like meteor-schema-deny and aldeed/meteor-schema-index. 🤔

@StorytellerCZ @coagmano Your input is greatly appreciated guys.

from meteor-collection2.

StorytellerCZ avatar StorytellerCZ commented on July 18, 2024

I'm fine with adding additional directives like denyInsert, but that would have to go into aldeed:schema-deny which already has denyUpdate.

I like the thinking behind updatedBy, though personally I would make it more of an audit. An array that would add a new unalterable entry every time the object gets updated, though depending on the application that might be better to have with more data in a separate collection, but I'm getting off-topic.

We either should bring schema-deny under community maintenance as well or if my memory serves me right there was a talk about re-integrating it and schema-index back into this package.

from meteor-collection2.

Floriferous avatar Floriferous commented on July 18, 2024

Yeah, nested objects always add a lot of extra headaches with simple schema, even though the compartmentalisation helps avoid clutter when looking through objects.

Anyways, I think @copleykj is fairly straightforward.

from meteor-collection2.

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.