npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cds-change-log

v0.0.9

Published

best practice of Change Log for CAP nodejs runtime

Downloads

21

Readme

CDS Change Log

provide the ChangeLog best practice for SAP CAP nodejs runtime

node-test npm NPM node-lts

codecov Quality Gate Status Security Rating Libraries.io dependency status for latest release

Get Started

package.json

{
  "cds": {
    "plugins": {
      "cds-change-log": {
        "impl": "cds-change-log"
      }
    }
  }
}

entity.cds

  • MUST using from 'cds-change-log' statement in CDS model
  • MUST annotating @cds.changelog.enabled on elements
  • MUST annotating at the root/raw entity level, annotations on projection/view will not work
  • MUST have at least one PRIMARY KEY
using {cap.community.common} from 'cds-change-log'

entity People : cuid, managed, customManaged {
  Name       : String(255);
  Age        : Integer;
  changeLogs : Association to many common.ChangeLog
                 on  changeLogs.entityKey  = $self.ID
                 and changeLogs.entityName = 'People';
}

// mark in entity and field elements level
// annotation in another place, you can put it into entity definition directly
annotate People with {
  Age  @cds.changelog.enabled;
  Name @cds.changelog.enabled;
};

create and update objects

let response = await axios.post("/sample/Peoples", { Name: "Theo Sun 2", Age: 39 })
const { ID } = response.data
await axios.patch(`/sample/Peoples(${ID})`, { Name: "Theo Sun 9", Age: 12 })

generated change logs

[
  {
    ID: "595b3604-d7dd-434f-962c-1e70e92bd775",
    actionAt: "2022-03-17T04:20:41.402Z",
    actionBy: "anonymous",
    entityName: "People",
    entityKey: "0e926ff2-53ad-4cd9-9569-ad2147dad0bc",
    action: "Create",
    Items: [
      {
        sequence: 0,
        Parent_ID: "595b3604-d7dd-434f-962c-1e70e92bd775",
        attributeKey: "Name",
        attributeNewValue: "Theo Sun 2",
        attributeOldValue: null,
      },
      {
        sequence: 1,
        Parent_ID: "595b3604-d7dd-434f-962c-1e70e92bd775",
        attributeKey: "Age",
        attributeNewValue: "39",
        attributeOldValue: null,
      },
    ],
  },
  {
    ID: "55bca8b8-1e79-4c9b-8bc9-1a013bf3cf39",
    actionAt: "2022-03-17T04:20:41.461Z",
    actionBy: "anonymous",
    entityName: "People",
    entityKey: "0e926ff2-53ad-4cd9-9569-ad2147dad0bc",
    action: "Update",
    Items: [
      {
        sequence: 0,
        Parent_ID: "55bca8b8-1e79-4c9b-8bc9-1a013bf3cf39",
        attributeKey: "Name",
        attributeNewValue: "Theo Sun 9",
        attributeOldValue: "Theo Sun 2",
      },
      {
        sequence: 1,
        Parent_ID: "55bca8b8-1e79-4c9b-8bc9-1a013bf3cf39",
        attributeKey: "Age",
        attributeNewValue: "12",
        attributeOldValue: "39",
      },
    ],
  },
]

Custom Type Primary Key

if you want to use Integer or other cds built-in type as primary key

entity.cds

@cds.changelog.enabled
entity Order : managed { // a sample entity
  key ID     : Integer; // use Integer as key, not out-of-box UUID
      @cds.changelog.enabled
      Amount : Decimal;
};

extension.cds

// remember using this file from your project root
using {cap.community.common.ChangeLog} from 'cds-change-log';

extend ChangeLog with {

  // add a new column 'entityKeyInteger' for integer key
  @cds.changelog.extension.entityKey
  // this column will be used when entity use `Integer` as primary key
  // MUST add the `cds.` prefix for built-in types
  @cds.changelog.extension.for.type : cds.Integer 
  entityKeyInteger : Integer;
  
};

Multi Primary Keys on target entity

if you want to manually specify the data storage for entity keys

entity.cds

@cds.changelog.enabled
entity PeopleOrderForProduct {
      // store key to ChangeLog.entityKeyInteger
      @cds.changelog.extension.key.target : 'entityKeyInteger'
  key OrderID  : Integer;
      // store key to ChangeLog.entityKey
      @cds.changelog.extension.key.target : 'entityKey'
  key PeopleID : UUID;
      @cds.changelog.enabled
      Amount   : Decimal;
}

Features

  • [x] single CUD OData requests
  • [x] multi CUD CQL
  • [x] all Update/Delete CQL (without where)
  • [x] aspect support
  • [x] localization support
  • [x] custom type key (e.g. Integer) support
    • [x] metadata cache
  • [x] multi primary key support
  • [x] extension field support
  • [ ] draft mode (draftActivate)
    • [x] simple single entity
    • [ ] localization
  • [ ] key relation cache
  • [ ] built-in FE UI Annotations
  • [ ] save change logs in async mode
  • [ ] benchmark test
  • [ ] subscribe change log event
  • [ ] validation at startup
  • [ ] skip/warn log for Blob
  • [ ] secondary storage like mongo/s3
  • [ ] readable identifier support
  • [ ] association/composition support
    • [ ] annotation @cds.changelog.to
  • [ ] Samples
    • [ ] localized data sample
    • [ ] for fiori elements
    • [ ] rows to columns table records

CHANGELOG

LICENSE