0.4.3 • Published 12 months ago

@krakerxyz/typed-base v0.4.3

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Installation

npm install -D typed-base

Transformer setup

The library works by what of a "transformer" plugin that runs during TSC compilation. We need to tell TSC to run the transformer by adding it to your tsconfig.json plugins array.

{
    "compilerOptions": {
        ...,
        "plugins": [
            {
                "transform": "@krakerxyz/typed-base/dist/cjs/transformer/transform",
                "collectionNamingStrategy": "kebab"
            }
        ]
    }
}

Plugin Options

collectionNamingStrategy

Controls the name the collection is given for a interface.

  • camel - BookAuthors -> bookAuthors
  • kebab - BookAuthors -> book-authors
  • snake - BookAuthors -> book_authors
  • pascal - bookAuthors -> BookAuthors

Configuring DB

When our application starts, we need to make a call to configureDb to setup the connection string and db name that all our entities will use

import { configureDb } from '@krakerxyz/typed-base';

configuredDb({
    dbName: 'my-db',
    uri: 'mongodb://[connectionString]'
})

Usage

import { TypedEntity } from '@krakerxyz/typed-base'

interface Author {
    id: string;
    name: string;
    created: number;
}

const authorEntity = new TypedEntity<Author>();

const author = await author.findOne({id: 'id-1'});
0.4.1

12 months ago

0.4.0

12 months ago

0.4.3

12 months ago

0.4.2

12 months ago

0.3.0

1 year ago

0.0.14

2 years ago

0.1.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.0.15

2 years ago

0.0.13

2 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago