0.5.40 • Published 3 months ago

@treenity/entity v0.5.40

Weekly downloads
-
License
ISC
Repository
-
Last release
3 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

3 months ago

0.5.38

4 months ago

0.5.39

4 months ago

0.5.33

5 months ago

0.5.36

4 months ago

0.5.37

4 months ago

0.5.34

5 months ago

0.5.35

5 months ago

0.5.32

5 months ago

0.5.30

6 months ago

0.5.31

6 months ago

0.5.29

7 months ago

0.5.27

7 months ago

0.5.28

7 months ago

0.5.26

7 months ago

0.5.21

7 months ago

0.5.22

7 months ago

0.5.25

7 months ago

0.5.23

7 months ago

0.5.24

7 months ago

0.5.20

7 months ago

0.5.19

7 months ago

0.5.18

8 months ago

0.5.17

8 months ago

0.5.16

8 months ago

0.5.15

8 months ago

0.5.14

8 months ago

0.5.13

9 months ago

0.5.12

9 months ago

0.5.10

10 months ago

0.5.11

10 months ago

0.5.9

10 months ago

0.5.8

11 months ago

0.5.7

11 months ago

0.5.6

11 months ago

0.5.5

11 months ago

0.5.4

11 months ago

0.5.1

11 months ago