
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
@pubsweet/base-model
Advanced tools
For persistence of data, PubSweet uses `@pubsweet/base-model` and its BaseModel class, which is a basic model based on [Objection.js](https://vincit.github.io/objection.js/).
For persistence of data, PubSweet uses @pubsweet/base-model
and its BaseModel class, which is a basic model based on Objection.js.
For a data model component, its defined exports are:
module.exports = {
typeDefs: // GraphQL type definitions
resolvers: // GraphQL resolvers
modelName: 'Collection',
model: require('./collection'),
}
Migrations (folder ./migrations
) are automatically added if they exist. For example migrations, see e.g. the User model's migrations.
If you use @pubsweet/model-some-model
in your app (by specifying it as a component in the configuration), typeDefs
and resolvers
are gathered in server's schema.js
to compose the app's entire GraphQL schema from three parts: 1. pubsweet-server
, 2. app's components and 3. app's config.
To use the above models, all you need to do is to add them to the pubsweet.components
configuration, e.g.:
pubsweet: {
components: ['@pubsweet/model-some-model'],
},
The data model's migrations will be added to the list of your app's migrations, and GraphQL queries and mutations will automatically be added to your API.
There are a few methods in the BaseModel that add utility features.
const manuscript = await new Manuscript({ title: 'Test' }).save()
const manuscript = await new Manuscript({
title: 'Test',
teams: [{ role: 'reviewer' }],
}).saveGraph()
Passes parameters onwards to Objection's findById
and supports its options:
const manuscript = await Manuscript.find(
'b70cd527-6b96-4612-b516-38a0e5ebfa65',
{ eager: 'teams' },
)
Passes parameters to Objection's where
.
const manuscript = await Manuscript.findByField(
'title',
'Breakthrough research',
)
Uses Objections's where().limit(1)
.
const manuscript = await Manuscript.findOneByField('content', 'Great success')
const manuscript = await Manuscript.all()
Shown in (https://gitlab.coko.foundation/pubsweet/pubsweet/blob/master/packages/base-model/test/extended-data-model-component/src/index.js) is an extended data model (extended-data-model-component
) for testing purposes. It exports the following things:
module.exports = {
typeDefs:
resolvers:
modelName: 'Model',
model: require('./model'),
extending: '@pubsweet/model-some-model',
}
Things are exactly the same as in the non-extended data model, but there is one big difference, the extending
property. This is a string, the name of the model that this extended data model extends. In this case @pubsweet/model-extended-some-model
extends @pubsweet/model-some-model
and what this means, in practice, is that @pubsweet/model-some-model
's GraphQL schema, resolvers and migration paths will be added to @pubsweet/model-extended-some-model
's. This happens recursively, so for example if you had a @pubsweet/model-super-extended-some-model
that extended @pubsweet/model-extended-some-model
, it would also include @pubsweet/model-some-models
's GraphQL schema, resolvers and migration paths. ∞
Take a look at the micropubs/wormbase application, for an example implementation of two models, Manuscript
and Review
using the BaseModel
class, the supplied GraphQL connectors and Authsome.
FAQs
For persistence of data, PubSweet uses `@pubsweet/base-model` and its BaseModel class, which is a basic model based on [Objection.js](https://vincit.github.io/objection.js/).
The npm package @pubsweet/base-model receives a total of 19 weekly downloads. As such, @pubsweet/base-model popularity was classified as not popular.
We found that @pubsweet/base-model demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.