Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cmbf-hapi-restmodel

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmbf-hapi-restmodel - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

2

package.json
{
"name": "cmbf-hapi-restmodel",
"version": "0.4.0",
"version": "0.4.1",
"dependencies": {

@@ -5,0 +5,0 @@ "bluebird": "^3.0.6",

@@ -12,3 +12,3 @@ # CMBF REST Model

```npm install cmbf-restmod --save```
```npm install cmbf-hapi-restmodel --save```

@@ -61,1 +61,77 @@ With the CMBF launcher, you just add a server hook to load additional plugins like this :

## Model
Ideally, you define your model using the new ES6 class concept:
```
var Joi = require('joi');
module.exports = function(server, config, log) {
"use strict";
var BaseModel = server.plugins['cmbf-hapi-restmodel'].BaseModel;
var clock = server.plugins['covistra-system'].clock;
class Document extends BaseModel {
static get endpoint() {
return "documents";
}
static get auth() {
return "token";
}
static get name() {
return "document";
}
static get collection() {
return 'documents';
}
static get Schema() {
return Joi.object().keys({
key: Joi.string().required(),
name: Joi.string().required(),
ownerId: Joi.string(),
customerId: Joi.string(),
type: Joi.string(),
tags: Joi.array().items(Joi.string()),
content: Joi.any(),
created_at: Joi.date().default(clock.nowTs, "Default to current time")
});
}
}
return Document;
};
```
You then register this model descriptor:
```
var Document = require('./models/document')(server, config, log);
modelManager.registerModel('document', Document`);
```
This model will get automatically exposed when the server stats with all standard routes
generated for you.
### Overriding ID field
Sometimes you need to override the field through which you model is referenced. By default,
we use a ```id``` field, but you just have to override the idField property in your
derived model:
```
class MyModel extends BaseModel {
static get idField() {
return 'key';
}
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc