@betterthings/es-documentdeprecated

A small implementation of an Elasticsearch document base class.

Usage no npm install needed!

<script type="module">
  import betterthingsEsDocument from 'https://cdn.skypack.dev/@betterthings/es-document';
</script>

README

ESDocument

A small implementation of an Elasticsearch document base class.

API

  • static get(id: string): Promise<Document | null>

  • static mget(ids: string[]): Promise<Array<Document | null>>

  • static search(body: object): Promise<{ total: number, data: Document[] }>: works great with bodybuilder.

  • static create(): Document: creating a document. Never call the constructor directly! You can implement static afterCreate(obj: Document) instead.

The return value of these static methods are typed to be the instance type of the class the method is called on. In test.ts, the TypeScript compiler correctly infers the type to be User, so you can benefit from editor tooling in VS Code and other editors.

The instances of Document have the following base functionality:

  • isNew(): boolean

  • getDocId(): string

  • store(): Promise<void>