Code Monkey home page Code Monkey logo

loopback-visible-properties-mixin's Introduction

loopback-visible-properties-mixin

npm version Build Status Coverage Status

Loopback mixin hidden all models properties and allow setup what should be visibles.

Installation

npm install loopback-visible-properties-mixin --save

Usage

Add the mixins property to your server/model-config.json:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "../node_modules/loopback-visible-properties-mixin",
      "../common/mixins"
    ]
  }
}

Add mixin params in in model definition. Example:

{
  "name": "Person",
  "properties": {
    "firstName": "string",
    "lastName": "string",
    "email": "string",
  },
  "relaions": {
    "siblings": {
      "type": "referencesMany",
      "model": "Person",
      "foreignKey": "siblingsIds"
    },
    "mother": {
      "type": "belongsTo",
      "model": "Person",
      "foreignKey": ""
    },
    "father": {
      "type": "belongsTo",
      "model": "Person",
      "foreignKey": ""
    },
    "couple": {
      "type": "belongsTo",
      "model": "Person",
      "foreignKey": ""
    },
    "children": {
      "type": "hasMany",
      "model": "Person",
      foreignKey: "motherId"
    },
  },
  "mixins": {
    "VisibleProperties": {
      "fields": {
        "firstName":   true,
        "lastName":    true,
        "email":       false,
        "mother":      true,
        "motherId":    false,
        "father":      true,
        "fatherId":    false,
        "siblings":    true,
        "siblingsIds": false,
        "children":    true
      }
    }
  }
}

You can setup this mixin with a array of visible properties too. Example:

{
  "name": "Person",
  ...
  "mixins": {
    "VisibleProperties": {
      "fields": [
        "firstName",
        "lastName",
        "mother",
        "father",
        "siblings",
        "children",
      ]
    }
  }
}

In the above definitions, the attributes id, couple and coupleId will not be visible in remote responses because they were ignored and email, motherId, fatherId and siblingsIds will not be visible because they were set false.

Troubles

If you have any kind of trouble with it, just let me now by raising an issue on the GitHub issue tracker here:

https://github.com/arondn2/loopback-visible-properties-mixin/issues

Also, you can report the orthographic errors in the READMEs files or comments. Sorry for that, I do not speak English.

Tests

npm test or npm run cover

loopback-visible-properties-mixin's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

johndpope

loopback-visible-properties-mixin's Issues

Not an issue

Do you have any suggestion for some models
Eg.
Account
When I go to api as logged in user / I want to know all fields

But say if I surface this account model

For get friends

I want to have fields hidden

Should I use a subclass or ???

Create a pseudo model
PrivateAccount

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.