Files
shields/core/base-service/deprecated-service.js
Paul Melnikow 7c226456fe Adopt static fields in [amo] and core (#5440)
Since we've upgraded production to Node 12 (#5436) we can finally adopt static fields!

This starts the process by updating core and one of the service families.
2020-08-19 14:49:29 -04:00

48 lines
1.2 KiB
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const camelcase = require('camelcase')
const BaseService = require('./base')
const { isValidCategory } = require('./categories')
const { Deprecated } = require('./errors')
const { isValidRoute } = require('./route')
const attrSchema = Joi.object({
route: isValidRoute,
name: Joi.string(),
label: Joi.string(),
category: isValidCategory,
// The content of examples is validated later, via `transformExamples()`.
examples: Joi.array().default([]),
message: Joi.string(),
dateAdded: Joi.date().required(),
}).required()
function deprecatedService(attrs) {
const { route, name, label, category, examples, message } = Joi.attempt(
attrs,
attrSchema,
`Deprecated service for ${attrs.route.base}`
)
return class DeprecatedService extends BaseService {
static name = name
? `Deprecated${name}`
: `Deprecated${camelcase(route.base.replace(/\//g, '_'), {
pascalCase: true,
})}`
static category = category
static isDeprecated = true
static route = route
static examples = examples
static defaultBadgeData = { label }
async handle() {
throw new Deprecated({ prettyMessage: message })
}
}
}
module.exports = deprecatedService