You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

elastictype

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elastictype

Elastictype is a easy way to model application data stored in Elasticsearch. It is inpsired by mongoose and @nestjs/mongoose and thus includes type casting, validation, query building, hooks and much more. It is written in TypeScript and thus provides typ


Version published
Maintainers
1
Created

Readme

Source

@cytex/elastictype

A Object Document Mapping (ODM) manager for Elasticsearch written in TypeScript.


Node.js CI Status GitHub issues GitHub pull requests License codecov


⚠️ This project is still in development and not ready for production use. ⚠️
Can't wait to use it? Feel free to contribute.

📝 Table of Contents

🧐 About

Elastictype is a easy way to model application data stored in Elasticsearch. It is inpsired by mongoose and @nestjs/mongoose and thus includes type casting, validation, query building, hooks and much more. It is written in TypeScript and thus provides type safety.

🏁 Features

  • Type casting
  • Validation
  • Query building
  • Hooks
  • Type safety
  • Intuitive index declaration via Decorators

🏁 Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Please make sure you have installed the following tools:

Installing

Install the package via npm:

npm install @cytex/elastictype --save

or via yarn:

yarn add @cytex/elastictype

🎈 Usage

Basic usage

import {
  BaseSchema,
  ElasticField,
  ElasticDataType,
  Index,
  Model,
} from "@cytex/elastictype";

@Index({
  name: "cats", // Name of the index
})
export class Cat extends BaseSchema<Cat> {
  @Prop(ElasticDataType.Keyword)
  public name: string;

  @ElasticField({
    // Type of the field (used for explicit mapping declaration)
    type: ElasticDataType.Integer,
  })
  public age: number;
}

// Create the index and the mapping in Elasticsearch
Cat.syncMapping();

// Create a new cat
const cat = new Cat();
cat.name = "Garfield";
cat.age = 42;

// Save the cat to Elasticsearch
await cat.save();

// Update the cat
await cat.update({ age: 43 });

// Delete the cat
await cat.delete();

// Find all cats
const cats = await Cat.find({ age: 43 });

// Find a cat by id
const cat = await Cat.findById("foo");

🔧 Running the tests

Tests are written with jest. You can run them with the following command:

npm run test

⛏️ Built Using

✍️ Authors

🎉 Acknowledgements

  • Nestjs - Node.js framework
  • mongoose - MongoDB object modeling for Node.js
  • @nestjs/mongoose - Mongoose module for Nest framework (not used in this project but inspired by it)

Keywords

FAQs

Package last updated on 27 Aug 2023

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc