0.5.40 • Published 11 months ago

@treenity/entity v0.5.40

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

@treenity/entity

About

This is client-server entity library made as simple as possible. It uses mobx under the hood for reactive updates and JSON Patch for sending changes to entities.

Features

  • Entity class with reactive properties
  • Automatic entity creation from JSON
  • Remote entity methods
  • Subscriptions and server updates to remote entities
  • TypeObjects for entity static and runtime resolving
  • Automatic schema generation for runtime type checking
  • Transport-independent API (add your connectors)
  • Weak-LRU entities caching, and automatic unsubscription on no links
  • FeathersJS hook to translate every method result to entity

Examples

1. Simplest entity

const SimpleType = metaType<SimpleEntity>('simple');

@entity(SimpleType)
class SimpleEntity {
  name!: string;
  age?: number;
}

2. Add write methods (actions in mobx)

// this will lead to age change and reactive observers to rerun
class X {
  @write
  changeAge(age: number) {
    this.age = age;
  }
}

3. Add write methods (actions in mobx)

// this will lead to real entity update and calling on patch api on the server
const SimpleType = metaType<SimpleEntity>('simple');

@entity(SimpleType)
class SimpleEntity {
  name!: string;
  age?: number;

  // optimistic method, will be called on the client
  @writeMethod
  changeName(newName: string) {
    this.name = name;
  }
}

// on the server
@entity(SimpleType.server)
class SimpleEntityServer extends SimpleEntity {
  // will be called on the server, and change underlaying entity
  @writeMethod
  changeName(newName: string) {
    this.name = name;
  }
}

Installation

Create token with "api" scope here. Add private registry info to .npmrc file in root of project

@treenity:registry=https://gitlab.com/api/v4/projects/35830151/packages/npm/
//gitlab.com/api/v4/projects/35830151/packages/npm/:_authToken=${TOKEN}

Install: TOKEN=<access_token> npm i @treenity/entity Publish: TOKEN=<access_token> npm publish

0.5.40

11 months ago

0.5.38

12 months ago

0.5.39

12 months ago

0.5.33

1 year ago

0.5.36

12 months ago

0.5.37

12 months ago

0.5.34

1 year ago

0.5.35

1 year ago

0.5.32

1 year ago

0.5.30

1 year ago

0.5.31

1 year ago

0.5.29

1 year ago

0.5.27

1 year ago

0.5.28

1 year ago

0.5.26

1 year ago

0.5.21

1 year ago

0.5.22

1 year ago

0.5.25

1 year ago

0.5.23

1 year ago

0.5.24

1 year ago

0.5.20

1 year ago

0.5.19

1 year ago

0.5.18

1 year ago

0.5.17

1 year ago

0.5.16

1 year ago

0.5.15

1 year ago

0.5.14

1 year ago

0.5.13

1 year ago

0.5.12

1 year ago

0.5.10

1 year ago

0.5.11

1 year ago

0.5.9

1 year ago

0.5.8

1 year ago

0.5.7

1 year ago

0.5.6

1 year ago

0.5.5

2 years ago

0.5.4

2 years ago

0.5.1

2 years ago