{"_id":"@amnet/base-model","_rev":"1-bf682502b9adaf037e76ef2bc2c5c012","name":"@amnet/base-model","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@amnet/base-model","version":"1.0.0","description":"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/).","main":"src/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":{"name":"Adam Hyde"},"license":"MIT","dependencies":{"@amnet/db-manager":"^1.5.0","@pubsweet/errors":"^2.0.51","@pubsweet/logger":"^0.2.61","knex":"^3.1.0","lodash":"^4.17.11","objection":"^2.1.6","uuid":"^7.0.3"},"peerDependencies":{"config":">=3.0.0","pubsweet-server":">=13.0.0"},"publishConfig":{"access":"public"},"gitHead":"44654719d99f1c6cf588a2f85e58f6c02cd9a9da","_id":"@amnet/base-model@1.0.0","_nodeVersion":"12.22.12","_npmVersion":"6.14.16","dist":{"integrity":"sha512-bYhIXid6YrCvP5GvKo74vPMHWquI3E/Mt22Z9SnuYpHLZZrxldAoCv3GEtMzGk4nyjhaObefYuEmiDyPIUb3IQ==","shasum":"fae05b5acb2205a6de3051ec0262e233b872e787","tarball":"https://registry.npmjs.org/@amnet/base-model/-/base-model-1.0.0.tgz","fileCount":4,"unpackedSize":29218,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHggQLk75Yt//pzCXQBVOVU2Ftr7eHEnmf3WIqUfV+87AiEA+L5K0Bzt1yUqB0ygFvDPZOD0lG3LyMb6nq2sPOOifC0="}]},"_npmUser":{"name":"amnet","email":"devaraj.b@amnet-systems.com"},"directories":{},"maintainers":[{"name":"amnet","email":"devaraj.b@amnet-systems.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/base-model_1.0.0_1704266476382_0.2700769070020326"},"_hasShrinkwrap":false},"1.1.0":{"name":"@amnet/base-model","version":"1.1.0","description":"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/).","main":"src/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":{"name":"Adam Hyde"},"license":"MIT","dependencies":{"@amnet/db-manager":"^1.6.0","@pubsweet/errors":"^2.0.51","@pubsweet/logger":"^0.2.61","knex":"^3.1.0","lodash":"^4.17.11","objection":"^2.1.6","uuid":"^7.0.3"},"peerDependencies":{"config":">=3.0.0","pubsweet-server":">=13.0.0"},"publishConfig":{"access":"public"},"gitHead":"44654719d99f1c6cf588a2f85e58f6c02cd9a9da","_id":"@amnet/base-model@1.1.0","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-Pn09JrDsLtkrjsUNrT+XL4+i4jIc6CTgBF6entk60+4lGqvy2fj6YYlZUroc/dxIUF8HbRe3gi54j3VeRgR0hA==","shasum":"ebe55d1d12483c3b1475b39ee23d65a353efa63b","tarball":"https://registry.npmjs.org/@amnet/base-model/-/base-model-1.1.0.tgz","fileCount":4,"unpackedSize":29218,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBhE7rqcBkjJFmccLc8h5Oh8G3SgazCJaOh4grfbRjDpAiEA+LJRvJFdm1BH+vKVzwq7lbUBwAR6FymrjPkaHPRW6fM="}]},"_npmUser":{"name":"amnet","email":"devaraj.b@amnet-systems.com"},"directories":{},"maintainers":[{"name":"amnet","email":"devaraj.b@amnet-systems.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/base-model_1.1.0_1704283612832_0.3917277635969003"},"_hasShrinkwrap":false}},"time":{"created":"2024-01-03T07:21:16.267Z","1.0.0":"2024-01-03T07:21:16.573Z","modified":"2024-01-03T12:06:53.187Z","1.1.0":"2024-01-03T12:06:53.018Z"},"maintainers":[{"name":"amnet","email":"devaraj.b@amnet-systems.com"}],"description":"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/).","author":{"name":"Adam Hyde"},"license":"MIT","readme":"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/).\n\nFor a data model component, its defined exports are:\n\n```js static\nmodule.exports = {\n  typeDefs: // GraphQL type definitions\n  resolvers: // GraphQL resolvers\n  modelName: 'Collection',\n  model: require('./collection'),\n}\n```\n\nMigrations (folder `./migrations`) are automatically added if they exist. For example migrations, see e.g. the [User model's migrations](https://gitlab.coko.foundation/pubsweet/pubsweet/tree/master/components/server/model-user/src/migrations).\n\nIf 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.\n\n### Using standalone data models\n\nTo use the above models, all you need to do is to add them to the `pubsweet.components` configuration, e.g.:\n\n```js static\n  pubsweet: {\n    components: ['@pubsweet/model-some-model'],\n  },\n```\n\nThe 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.\n\n### API documentation\n\nThere are a few methods in the BaseModel that add utility features.\n\n#### save() - Saving a single model\n\n```js static\nconst manuscript = await new Manuscript({ title: 'Test' }).save()\n```\n\n#### saveGraph() - Saving a graph\n\n```js static\nconst manuscript = await new Manuscript({\n  title: 'Test',\n  teams: [{ role: 'reviewer' }],\n}).saveGraph()\n```\n\n#### find() - Finding a single instance by id\n\nPasses parameters onwards to Objection's `findById` and supports its options:\n\n```js static\nconst manuscript = await Manuscript.find(\n  'b70cd527-6b96-4612-b516-38a0e5ebfa65',\n  { eager: 'teams' },\n)\n```\n\n#### findByField() - Finding instances by field value\n\nPasses parameters to Objection's `where`.\n\n```js static\nconst manuscript = await Manuscript.findByField(\n  'title',\n  'Breakthrough research',\n)\n```\n\n#### findOneByField() - Find a single instance by field value\n\nUses Objections's `where().limit(1)`.\n\n```js static\nconst manuscript = await Manuscript.findOneByField('content', 'Great success')\n```\n\n#### all() - Returns all records\n\n```js static\nconst manuscript = await Manuscript.all()\n```\n\n### Support for extended data models (models based on another model)\n\nShown 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:\n\n```js static\nmodule.exports = {\n  typeDefs:\n  resolvers:\n  modelName: 'Model',\n  model: require('./model'),\n  extending: '@pubsweet/model-some-model',\n}\n```\n\nThings 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. ∞\n\n### Examples in the wild\n\nTake a look at the [micropubs/wormbase](https://gitlab.coko.foundation/micropubs/wormbase/tree/master/server) application, for an example implementation of two models, `Manuscript` and `Review` using the `BaseModel` class, the supplied GraphQL connectors and Authsome.\n","readmeFilename":"README.md"}