mr-jdb-server v1.1.3
mr-jdb-server
/**
* Banco de dados REST JSON - jdbServer
*
* @version 2020-07-22 // atualização da Query-Object para Query-Opts e implementação da busca de texto quebrado
*/
/**
* @name jdbServer
* jdbServer é uma plataforma NodeJS de gerencimanto de dados em JSON,
* podendo ser instanciada como um servidor REST e também pode
* ser utilizada em outros servidores NodeJS para o fornecendo
* uma base de dados em JSON.
*
* @type {object}
* @sample
* import { jdbServer } from 'jdb-server'
* jdbServer.start()
*
* @method jdbServer.start
* Inicia o servidor REST jdbServer
* @syntax jdbServer.start([port, [path, [opts]]])
*
* @param port {number} porta que o servidor irá escutar. (padrão: 'db/jdbServer')
* @param path {string} caminho da base de dados JSON a partir da raiz da aplicação ou o caminho absoluto.
* @param opts {object} opções de middleware que o servidor irá configurar
* opts = {
* [noGzip]: boolean // desabilita a compressão de todas as requisições (padrão: false)
* [noCors]: boolean // desabilita o CORS para todas as requisições (padrão: false)
* [logger]: boolean // habilita o log do servidor. (padrão: true)
* [completeLogger]: boolean // habilita o log completo das requisições. Loga as propriedades da requisição. (padrão: false)
* [readOnly]: boolean // define se bloqueia as requisições de gravações de dados. Permite apenas requisições do tipo GET. (padrão: false)
* [bodyParser]: boolean // habilita o body-parser nas requisições com body (padrão: true)
* }
*
*
* @method jdbServer.config
* Configura o caminho da base de dados JSON, que por padrão é 'db/jdbServer'
* @same jdbServerConfig
* @syntax jdbServer.config([path]) //jdbServerConfig([path])
*
* @param path {string} caminho da base de dados JSON a partir da raiz da aplicação ou o caminho absoluto.
*
* @sample
* // utilizando o método pelo objeto jdbServer
* import { jdbServer } from 'jdb-server'
* jdbServer.config('db/jdbServer')
* // ou informando o caminho absoluto
* jdbServer.config('C:\\db\\jdbServer') // ou jdbServer.config('C:/db/jdbServer')
*
* // utilizando a função jdbServerConfig
* import { jdbServerConfig } from 'jdb-server'
* jdbServerConfig('db/jdbServer')
* // ou informando o caminho absoluto
* jdbServerConfig('C:\\db\\jdbServer') // ou jdbServerConfig('C:/db/jdbServer')
*
*
* @method jdbServer.create
* Retorna um servidor express
* @same jdbServerCreate
* @syntax jdbServer.create() // jdbServerCreate()
*
* @return {object} servidor express
*
* @sample
* // utilizando o método pelo objeto jdbServer
* import { jdbServer } from 'jdb-server'
* const server = jdbServer.create()
*
* // utilizando a função jdbServerCreate()
* import { jdbServerCreate } from 'jdb-server'
* const server = jdbServerCreate()
*
*
* @method jdbServer.defaults
* Configura as defaults para adicionar ao server
* @same jdbServerDefaults
* @syntax jdbServer.defaults(opts) // jdbServerDefaults(opts)
*
* @param opts {
* [noGzip]: boolean // desabilita a compressão de todas as requisições (padrão: false)
* [noCors]: boolean // desabilita o CORS para todas as requisições (padrão: false)
* [logger]: boolean // habilita o log do servidor. (padrão: true)
* [completeLogger]: boolean // habilita o log completo das requisições (padrão: false)
* [readOnly]: boolean // define se permite apenas requisições comente leitura (GET) (padrão: false)
* [bodyParser]: boolean // habilita o body-parser nas requisições com body (padrão: true)
* }
*
* @return {array} defaults configuradas para o server express
*
* @sample
* // utilizando o método pelo objeto jdbServer
* import { jdbServer } from 'jdb-server'
* const server = jdbServer.create()
* server.use(jdbServer.defaults({ logger: false }))
*
* // ou utilizando diretamente a função jdbServerDefaults()
* import { jdbServerCreate, jdbServerDefaults } from 'jdb-server'
* const server = jdbServerCreate()
* server.use(jdbServerDefaults({ logger: false }))
*
*
* @name jdbServer.restJdbRoutes
* @type {object}
* Fornece as rotas da api rest de acesso à base de dados para servidores express
*
* @jdbRoutes
* GET | http://server:port/database/Collection
* GET | http://server:port/database/Collection/id
* POST | http://server:port/database/Collection
* PUT | http://server:port/database/Collection/id
* PATCH | http://server:port/database/Collection/id
* DELETE | http://server:port/database/Collection/id
*
* @sample
* import * as express from 'express'
* import { jdbServer } from 'jdb-server'
* const server = express()
* server.use(jdbServer.restJdbRoutes)
*
* // ou utilizando diretamente o objeto jdbServerRestJdbRoutes
* import * as express from 'express'
* import { jdbServerRestJdbRoutes } from 'jdb-server'
* const server = express()
* server.use(jdbServerRestJdbRoutes)
*
* @name jdbServer.QueryManager
* @name jdbServerQueryManager
* @type {object}
* Ferramenta de manipulação das bases de dados jdbServer
* Fornece métodos de manipulação da database.
*
* @see jdbServerQueryManager documentation
*/
/**
* @name jdbServerQueryManager
* Ferramenta de manipulação das bases de dados jdbServer.
* Fornece os 5 métodos de manipulação da database index, show, store, update e delete.
* @same jdbServer.QueryManager
* @type {object}
*
* @method jdbServerQueryManager.index
* Lista os registros de um recurso
* @same jdbServer.QueryManager.index
* @syntax jdbServerQueryManager.index(database, Collection, [query])
*
* @param database {string} nome da base de dados
* @param Collection {string} nome do recurso desejado
* @param query {object} define os filtros a serem aplicados nos registros
*
* @return {array} os registros que atendem à requisição
*
*
* @method jdbServerQueryManager.show
* Retorna um registro específico de acordo com o id informado
* @same jdbServer.QueryManager.show
* @syntax jdbServerQueryManager.show(database, Collection, id, [query])
*
* @param database {string} nome da base de dados
* @param Collection {string} nome do recurso desejado
* @param id {string|number} id do registro desejado
* @param query {object} define as opções a embutir ou expandir ($embed/$expand)
*
* @return {object} o registro solicitado
*
*
* @method jdbServerQueryManager.store
* Inclui um registro em um recurso
* @same jdbServer.QueryManager.store
* @syntax jdbServerQueryManager.store(database, Collection, body)
*
* @param database {string} nome da base de dados
* @param Collection {string} nome do recurso desejado
* @param body {object} o registro que deverá ser inserido
*
* @return {object} o registro que foi inserido
*
*
* @method jdbServerQueryManager.update
* Atualiza um registro específico
* @same jdbServer.QueryManager.update
* @syntax jdbServerQueryManager.update(database, Collection, id, body, [overwrite])
*
* @param database {string} nome da base de dados
* @param Collection {string} nome do recurso desejado
* @param id {string|number} id do registro desejado
* @param body {object} o registro que deverá ser inserido
* @param overwrite {boolean} define se deve sobrescrever o registro existente. (padrão: true)
*
* @return {object} o registro atualizado
*
*
* @method jdbServerQueryManager.delete
* Remove um registro específico
* @same jdbServer.QueryManager.delete
* @syntax jdbServerQueryManager.delete(database, Collection, id)
*
* @param database {string} nome da base de dados
* @param Collection {string} nome do recurso desejado
* @param id {string|number} id do registro desejado
*
* @return {boolean} verdadeiro se conseguiu remover
*/
Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? Use the template at the bottom!
Add your files
- Create or upload files
- Add files using the command line or push an existing Git repository with the following command:
cd existing_repo
git remote add origin https://gitlab.com/mrprojetos/business/mr-modules/mr-jdb-server.git
git branch -M main
git push -uf origin main
Integrate with your tools
Collaborate with your team
- Invite team members and collaborators
- Create a new merge request
- Automatically close issues from merge requests
- Enable merge request approvals
- Set auto-merge
Test and Deploy
Use the built-in continuous integration in GitLab.
- Get started with GitLab CI/CD
- Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)
- Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy
- Use pull-based deployments for improved Kubernetes management
- Set up protected environments
Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to makeareadme.com for this template.
Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
Name
Choose a self-explaining name for your project.
Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
License
For open source projects, say how it is licensed.
Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.