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

@five12days/core

v1.5.2

Published

Core modules for FTD Application development framework

Downloads

9

Readme

FTD Core

Core Package to help Generate Code fot FTD Application Development framework. This will use a defined schema to generate core functionality

Features

  • Generate base code using a defined schema
  • Follows clean architecture patterns to maximize portability
  • Users will only need to maintain essential code (Business logic) in their repository as the rest will be generated by this tool

Getting Started

  • First install the dev dependancy dotenv using the following command.
        npm install -D dotenv
  • Run the following code to install and initiate the FTDCore package in your local project.
        npx @five12days/core --init
  • Or you can manually setup FTDCore by using the following steps.
    • Run
        npm install @five12days/core
  • Add the following text to the scripts in package.json.
        "ftd:init" : "frd-core -init"
        "ftd:gen" : "ftd-core -gen"
        "ftd:deploy" : "ftd-core -deploy"
  • Run
        npm run ftd:init
  • Update the .gitignore files with the following line.
    *.gen.ts
  • Define the schema files according to the definitions
  • You can generate the SQL table definitions and deploy them using the following command
        npm run ftd:deploy
  • Once the definitions are done run the following command
        npm run ftd:gen
  • To enable schema parsing in VS code add the following lines to in the json:schema section of the settings page and make sure that json schema download is enabled
      {
        "fileMatch": ["/*.ftd.json"],
        "url": "https://five12daysgeneral.s3.ap-southeast-1.amazonaws.com/ftd-core/ftdModel.schema.json"
      },
      {
        "fileMatch": ["ftd_config.json"],
      	    "url": "https://five12daysgeneral.s3.ap-southeast-1.amazonaws.com/ftd-core/ftdConfig.schema.json"
      }

Schema definition

A basic modle definitions should end with .ftd.json. You can see a sample below

  {
      "name": "CustomerOrder",
      "attributes": {
          "OrderNo": { "type": "Number", "flags": "KMI-" },
          "TotalAmount": { "type": "Decimal", "flags": "AMIU" },
          "Date": { "type": "Timestamp", "flags": "A-I-" }
      }
  }
  • Name is the name of the entity (Table)
  • Attributes contain the properties of the entity (Columns)
  • Valid attribute types are
    • Number (Int)
    • BigNumber(BigInt)
    • Decimal (Decimal(12,2))
    • Float (Float)
    • Date (Date)
    • Timestamp (Timestamp) -- Use when timezone is needed
    • String (Varchar) -- Define a max length when using
  • Attribute flags
    • K Primary attribute (Primary Key)
    • A Normal attribute
    • M Mandatory field
    • I Insetable field
    • U Updatable field
  • Attribute flag should be <Primary/Normal flag><Mandatory flag><Insertable flag><Updatable flag> i.e KMI-

Usage

  • When a schema is defined you can generate the code for it using sh npm run ftd:gen this will create three files for a schema.
    • .gen.ts (located at ./gen/) - contains the zod definition and the the createModel method
    • BaseUseCases.gen.ts (located at ./gen/) - contains the CRUD base use cases that contains the basic validations that are defined in the schema
    • UseCases.ts (located at ./useCases/) - contains the CRUD use cases that can be used to costomize crud logic as needed
  • Note that all files in the gen folder will not be required to be commited to your repo and will be generated everytime you run ftd:gen
  • To execute uses cases as transactions (To execute multiple sql transactions atomically) you have to wrap your use cases in an executeTransaction method. You can see examples of these in the generated useCases file. Please check the methods that does not end with '_' as you can see methods that ends like that contains the implementation details and the methods that do not have it adds the transaction wrapper to it.
  • Whenever you create custom usecases make sure to include 'executeQuery' parameter as a part of its parameter list you can use this to execute your sql.

Deployment

  • When you are ready to make a production build make sure to change the build script in your package.json so that it starts with ftd-core -gen && this will make sure that all files that needs to be generated are generated before doing the build. As an example, if you have simple typescript project the build script should look like the following.

    "build": "ftd-core -gen && tsc"

Limitations

  • As of now we can only use mysql databases with this solution