Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Objectionjs plugin to whitelist/blacklist model properties

NotificationsYou must be signed in to change notification settings

oscaroox/objection-visibility

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

workflow

objection-visibility

This plugin adds the ability to whitelist or blacklists model properties.

Installation

npm install objection-visibility

Usage

You can enable this plugin by either setting the static propertyhidden orvisible to your model.

It is possible to have a model which have both properties defined, note that thevisible method is called first and thehidden method second.

Blacklist properties

To enable blacklisting on your model add the static propertyhidden on your model and return an array with the fields you want to blacklist.

The listed fields are gone after being serialized to json

constModel=require('objection').ModelconstvisibilityPlugin=require('objection-visibility').default;classUserextendsvisibilityPlugin(Model){staticgethidden(){return['hashed_password'];}}

Whitelist properties

To enable whitelisting on your model add a static propertyvisible on your model and return an array with the fields you want to be whitelisted

The listed fields will be the only properties available after being serialized to json

constModel=require('objection').ModelconstvisibilityPlugin=require('objection-visibility').default;classUserextendsvisibilityPlugin(Model){staticgetvisible(){return['firstName','id']}}

Using with multiple models

Can be used on a base model and have it readily available on all your models

Models that dont have the static propertiesvisible orhidden will remain untouched.

// base.jsclassBaseModelextendsvisibilityPlugin(Model){}// post.jsclassPostextendsBaseModel{staticgetvisible(){return['description','title']}}// user.jsclassUserextendsBaseModel{staticgethidden(){return['hashedPassword']}}

About

Objectionjs plugin to whitelist/blacklist model properties

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2026 Movatter.jp