@nnode/core-data
TypeScript icon, indicating that this package has built-in type declarations

1.5.0 • Public • Published

data

Library to work with document repositories.

Usage

npm install @nnode/core-data

Usage Details

You have to create derived types for DocumentContext and Documents<T>. A DocumentContext represents the document store, which uses the meta__doctype to represent the document type.

Example

// Create interface that represent models.
export interface EnvironmentVariable {
  name: string
  value: string
}

export interface User {
  home: string
  username: string
}

// Create model documents.
export interface EnvironmentVariableDocument extends Document, EnvironmentVariable {
  timestamp: number
}

export interface UserDocument extends Document, User {
  timestamp: number
}

// Create primary document context.
export class TestContext extends DocumentContext<CouchConfig> {
  users: Users = new Users('user', this.store)
  variables: EnvironmentVariables = new EnvironmentVariables('env', this.store)

  initialize() {
    return Promise.resolve()
  }
}

// Create specific document stores.
export class EnvironmentVariables extends Documents<EnvironmentVariableDocument> {
  readonly indexes: PouchDB.Find.CreateIndexOptions[] = []

  protected get keyProperties(): string[] {
    return ['name']
  }
}

export class Users extends Documents<UserDocument> {
  readonly indexes: PouchDB.Find.CreateIndexOptions[] = []

  protected get keyProperties(): string[] {
    return ['username']
  }
}

Readme

Keywords

Package Sidebar

Install

npm i @nnode/core-data

Weekly Downloads

49

Version

1.5.0

License

MIT

Unpacked Size

56.4 kB

Total Files

44

Last publish

Collaborators

  • teegee