New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

commodo-fields-storage-crud-logs

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commodo-fields-storage-crud-logs

Appends "createdOn", "updatedOn", and "savedOn" fields to your model.

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-22.22%
Maintainers
1
Weekly downloads
 
Created
Source

commodo-fields-storage-crud-logs

Build Status Covergrowth Status code style: prettier All Contributors PRs Welcome

Appends createdOn, updatedOn, and savedOn fields to your model. The fields are automatically updated with current time before the model is about to be saved.

Install

npm install --save commodo-fields-storage-crud-logs

Or if you prefer yarn:

yarn add commodo-fields-storage-crud-logs

Quick Example:

import { compose } from "ramda";
import { withFields, string } from "@commodo/fields";
import { withCrudLogs } from "commodo-fields-storage-crud-logs";

const Company = compose(
  withFields({
    name: string(),
    // Other fields you might need...
  }),
  withCrudLogs(),
  withStorage(...), // Required.
  // Other higher order functions (HOFs) you might need...
)();

const company = new Company();
company.name = "Acme Corporation";

// All fields null as a default value.
console.log(company.createdOn); // Logs null.
console.log(company.updatedOn); // Logs null.
console.log(company.savedOn); // Logs null.

// Upon saving the model for the first time, "createdOn" and "savedOn" fields will receive a value:
await company.save();
console.log(company.createdOn); // Logs "2020-04-19T14:34:42.993Z" (same as savedOn).  
console.log(company.updatedOn); // Logs null.
console.log(company.savedOn); // Logs "2020-04-19T14:34:42.993Z" (same as createdOn).

// On every following save, only the "updatedOn" and "savedOn" fields will be updated:
await company.save();
console.log(company.createdOn); // Logs "2020-04-19T14:34:42.993Z" (no change here).
console.log(company.updatedOn); // Logs "2020-04-19T14:37:05.726Z" (same as savedOn).
console.log(company.savedOn); // Logs "2020-04-19T14:34:42.993Z" (same as updatedOn).
withCrudLogs is used with the withStorage function

In order to update the field values accordingly, the withCrudLogs internally utilizes the beforeSave, beforeCreate, and beforeUpdate hooks, which are exposed by the withStorage function.

Contributors

Thanks goes to these wonderful people (emoji key):


Adrian Smijulj

💻 📖 💡 👀 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

Keywords

FAQs

Package last updated on 21 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc