UNPKG

@avonjs/avonjs

Version:

A fluent Node.js API generator.

225 lines (224 loc) 8.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const helpers_1 = require("../helpers"); exports.default = (Parent) => { class Presentable extends Parent { /** * Callback that indicates if the attribute should be shown on the index api. */ showOnIndexCallback = (0, helpers_1.approveCallback)(); /** * Callback that indicates if the attribute should be shown on the detail api. */ showOnDetailCallback = (0, helpers_1.approveCallback)(); /** * Callback that indicates if the attribute should be shown on the review api. */ showOnReviewCallback = (0, helpers_1.approveCallback)(); /** * Callback that indicates if the attribute should be shown on the creation api. */ showOnCreationCallback = (0, helpers_1.approveCallback)(); /** * Callback that indicates if the attribute should be shown on the update api. */ showOnUpdateCallback = (0, helpers_1.approveCallback)(); /** * Callback that indicates if the attribute should be shown on the association api. */ showOnAssociationCallback = (0, helpers_1.approveCallback)(); /** * Specify that the attribute should be hidden from the index api. */ hideFromIndex(callback = true) { this.showOnIndexCallback = (0, helpers_1.reverseEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be hidden from the detail api. */ hideFromDetail(callback = true) { this.showOnDetailCallback = (0, helpers_1.reverseEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be hidden from the review api. */ hideFromReview(callback = true) { this.showOnReviewCallback = (0, helpers_1.reverseEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be hidden from the association api. */ hideFromAssociation(callback = true) { this.showOnAssociationCallback = (0, helpers_1.reverseEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be hidden from the creation api. */ hideWhenCreating(callback = true) { this.showOnCreationCallback = (0, helpers_1.reverseEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be hidden from the update api. */ hideWhenUpdating(callback = true) { this.showOnUpdateCallback = (0, helpers_1.reverseEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be visible on the index api. */ showOnIndex(callback = true) { this.showOnIndexCallback = (0, helpers_1.makeEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be hidden from the detail api. */ showOnDetail(callback = true) { this.showOnDetailCallback = (0, helpers_1.makeEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be hidden from the review api. */ showOnReview(callback = true) { this.showOnReviewCallback = (0, helpers_1.makeEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be hidden from the association api. */ showOnAssociation(callback = true) { this.showOnAssociationCallback = (0, helpers_1.makeEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be hidden from the creation api. */ showOnCreating(callback = true) { this.showOnCreationCallback = (0, helpers_1.makeEvaluatorCallback)(callback); return this; } /** * Specify that the attribute should be hidden from the update api. */ showOnUpdating(callback = true) { this.showOnUpdateCallback = (0, helpers_1.makeEvaluatorCallback)(callback); return this; } /** * Check for showing when updating. */ isShownOnUpdate(request, resource) { return this.showOnUpdateCallback(request, resource); } /** * Check showing on index. */ isShownOnIndex(request, resource) { return this.showOnIndexCallback(request, resource); } /** * Determine if the field is to be shown on the detail api. */ isShownOnDetail(request, resource) { return this.showOnDetailCallback(request, resource); } /** * Determine if the field is to be shown on the review api. */ isShownOnReview(request, resource) { return this.showOnReviewCallback(request, resource); } /** * Determine if the field is to be shown on the review api. */ isShownOnAssociation(request) { return this.showOnAssociationCallback(request); } /** * Check for showing when creating. */ isShownOnCreation(request) { return this.showOnCreationCallback(request); } /** * Specify that the attribute should only be shown on the index api. */ onlyOnIndex() { this.showOnIndex(true); this.showOnDetail(false); this.showOnReview(false); this.showOnAssociation(false); this.showOnCreating(false); this.showOnUpdating(false); return this; } /** * Specify that the attribute should only be shown on the detail api. */ onlyOnDetail() { this.showOnIndex(false); this.showOnDetail(true); this.showOnReview(false); this.showOnAssociation(false); this.showOnCreating(false); this.showOnUpdating(false); return this; } /** * Specify that the attribute should only be shown on the review api. */ onlyOnReview() { this.showOnIndex(false); this.showOnDetail(false); this.showOnReview(true); this.showOnAssociation(false); this.showOnCreating(false); this.showOnUpdating(false); return this; } /** * Specify that the attribute should only be shown on the association api. */ onlyOnAssociation() { this.showOnIndex(false); this.showOnDetail(false); this.showOnReview(false); this.showOnAssociation(true); this.showOnCreating(false); this.showOnUpdating(false); return this; } /** * Specify that the attribute should only be shown on forms. */ onlyOnForms() { this.showOnIndex(false); this.showOnDetail(false); this.showOnReview(false); this.showOnAssociation(false); this.showOnCreating(true); this.showOnUpdating(true); return this; } /** * Specify that the attribute should be hidden from forms. */ exceptOnForms() { this.showOnIndex(true); this.showOnDetail(true); this.showOnReview(true); this.showOnAssociation(true); this.showOnCreating(false); this.showOnUpdating(false); return this; } } return Presentable; };