1.4.6 • Published 19 days ago

@lpgroup/feathers-utils v1.4.6

Weekly downloads
89
License
MIT
Repository
gitlab
Last release
19 days ago

@lpgroup/feathers-utils

npm version Known Vulnerabilities Licence MIT tested with jest codecov

Collection of feathers-utils hooks and helper functions

Install

Installation of the npm

npm install @lpgroup/feathers-utils

Example

const auth = require("@lpgroup/feathers-utils");

How to use cache feature

If you want to cache the mongodb document (JSON) in the cache the only thing you need to do is to extend from ServiceCache instead of Service. it will use the default cache configuration. The cached item will be invalidated and removed on update, patch, removed.

max: 500 items ttl: 300000 // 5 minutes

you can override this in service options

const options = {
  id: "_id",
  paginate: app.get("paginate"),
  schema,
  cache: { max: 1000 },
};

Example using service cache

const { ServiceCache } = require("@lpgroup/feathers-utils");

export class Service1 extends ServiceCache {
  constructor(options, app) {
    super(options);
    this.app = app;

    onPluginReady("mongodb").then(({ database }) => {
      this.Model = database.collection("serivce1");
    });
  }
}

If you want to cache just part of the the mongodb document (JSON) in the cache. You can create caches on the service that you can access anywhere where you have access to the app.

You can specify a callback to set data in the cache and options:

const { CreateCache } = require("@lpgroup/feathers-utils");
import { Service } from "feathers-mongodb";

export class Service1 extends Service {
  constructor(options, app) {
    super(options);
    this.app = app;

    onPluginReady("mongodb").then(({ database }) => {
      this.Model = database.collection("serivce1");
    });

    CreateCache(
        this,
        "mapToOwner"
        (data) => {
          return { owner: data.owner };
        },
        { max: 1000 }
      );
  }
}

To use the cache you get access to the caches from the service:

// setting the owner of the message to the same as the visitor, this makes it possible for
// admin to create messages for the visitors.
const { owner } = await app
  .service("/organisations/:organisationAlias/bots/:botAlias/visitors")
  .caches.mapToOwner.get(visitorId);

data.owner = owner;

limitRequest

This is a middleware to limit the request. And will respond a status of 429.

import { limitRequest } from "@lpgroup/feathers-utils";

export default (app) => {
  app.use(limitRequest(app));
};

default.json

  "tooManyRequest": {
    "isEnabled": true,
    "buketSize": 80,
    "ttlSec": 2,
    "whiteList": ["127.0.0.2"]
  },
PropertyDefaultTypeDescription
isEnabledtruebooleanenable/disable 429
bucketSize100numbernum of request to display 429
ttlSec5 secnumberrefresh bucketSize time in sec
whiteList[]arrayexempted IPs e.g "127.0.0.1"

API

xxx

xxx(xxx)

xxx(xxx);

Contribute

See contribute

License

MIT - See licence

1.4.6

19 days ago

1.4.5

19 days ago

1.4.3

19 days ago

1.4.1

19 days ago

1.4.0

1 month ago

1.3.182

1 month ago

1.3.183

1 month ago

1.3.181

1 month ago

1.3.180

1 month ago

1.3.179

2 months ago

1.3.178

3 months ago

1.3.174

3 months ago

1.3.177

4 months ago

1.3.176

4 months ago

1.3.175

4 months ago

1.3.171

5 months ago

1.3.170

6 months ago

1.3.173

5 months ago

1.3.149

8 months ago

1.3.148

9 months ago

1.3.147

9 months ago

1.3.157

7 months ago

1.3.156

7 months ago

1.3.155

7 months ago

1.3.154

8 months ago

1.3.158

7 months ago

1.3.153

8 months ago

1.3.152

8 months ago

1.3.151

8 months ago

1.3.169

6 months ago

1.3.160

7 months ago

1.3.163

7 months ago

1.3.162

7 months ago

1.3.135

12 months ago

1.3.133

12 months ago

1.3.139

11 months ago

1.3.138

12 months ago

1.3.136

12 months ago

1.3.145

11 months ago

1.3.144

11 months ago

1.3.143

11 months ago

1.3.142

11 months ago

1.3.141

11 months ago

1.3.140

11 months ago

1.3.119

1 year ago

1.3.124

1 year ago

1.3.123

1 year ago

1.3.122

1 year ago

1.3.121

1 year ago

1.3.127

1 year ago

1.3.126

1 year ago

1.3.125

1 year ago

1.3.120

1 year ago

1.3.129

1 year ago

1.3.132

1 year ago

1.3.131

1 year ago

1.3.130

1 year ago

1.3.118

1 year ago

1.3.106

1 year ago

1.3.109

1 year ago

1.3.107

1 year ago

1.3.113

1 year ago

1.3.112

1 year ago

1.3.111

1 year ago

1.3.110

1 year ago

1.3.117

1 year ago

1.3.116

1 year ago

1.3.115

1 year ago

1.3.114

1 year ago

1.3.105

2 years ago

1.3.104

2 years ago

1.3.102

2 years ago

1.3.101

2 years ago

1.3.100

2 years ago

1.3.103

2 years ago

1.3.90

2 years ago

1.3.93

2 years ago

1.3.94

2 years ago

1.3.91

2 years ago

1.3.92

2 years ago

1.3.97

2 years ago

1.3.98

2 years ago

1.3.95

2 years ago

1.3.96

2 years ago

1.3.99

2 years ago

1.3.75

2 years ago

1.3.76

2 years ago

1.3.79

2 years ago

1.3.77

2 years ago

1.3.78

2 years ago

1.3.82

2 years ago

1.3.83

2 years ago

1.3.80

2 years ago

1.3.81

2 years ago

1.3.86

2 years ago

1.3.87

2 years ago

1.3.84

2 years ago

1.3.85

2 years ago

1.3.89

2 years ago

1.3.65

2 years ago

1.3.68

2 years ago

1.3.69

2 years ago

1.3.66

2 years ago

1.3.67

2 years ago

1.3.71

2 years ago

1.3.72

2 years ago

1.3.70

2 years ago

1.3.73

2 years ago

1.3.74

2 years ago

1.3.50

2 years ago

1.3.54

2 years ago

1.3.52

2 years ago

1.3.57

2 years ago

1.3.58

2 years ago

1.3.55

2 years ago

1.3.56

2 years ago

1.3.59

2 years ago

1.3.60

2 years ago

1.3.61

2 years ago

1.3.64

2 years ago

1.3.62

2 years ago

1.3.63

2 years ago

1.3.46

2 years ago

1.3.45

2 years ago

1.3.39

2 years ago

1.3.42

2 years ago

1.3.43

2 years ago

1.3.40

2 years ago

1.3.41

2 years ago

1.3.36

2 years ago

1.3.34

2 years ago

1.3.37

2 years ago

1.3.38

2 years ago

1.3.31

3 years ago

1.3.32

3 years ago

1.3.33

3 years ago

1.3.30

3 years ago

1.3.29

3 years ago

1.3.28

3 years ago

1.3.27

3 years ago

1.3.26

3 years ago

1.3.25

3 years ago

1.3.23

3 years ago

1.3.21

3 years ago

1.3.22

3 years ago

1.3.20

3 years ago

1.3.18

3 years ago

1.3.17

3 years ago

1.3.16

3 years ago

1.3.15

3 years ago

1.3.14

3 years ago

1.3.13

3 years ago

1.3.12

3 years ago

1.3.9

3 years ago

1.3.11

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.13

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.2

3 years ago