@e22m4u/js-repository-mongodb-adapter 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.c8rc ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "all": true,
3
+ "include": [
4
+ "src/**/*.js"
5
+ ],
6
+ "exclude": [
7
+ "src/**/*.spec.js"
8
+ ]
9
+ }
package/.commitlintrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": [
3
+ "@commitlint/config-conventional"
4
+ ]
5
+ }
package/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ # Unix-style newlines with a newline ending every file
7
+ [*]
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ charset = utf-8
11
+ indent_style = space
12
+ indent_size = 2
13
+ max_line_length = 80
package/.eslintrc.cjs ADDED
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ env: {
3
+ es2021: true,
4
+ node: true
5
+ },
6
+ parserOptions: {
7
+ sourceType: 'module',
8
+ ecmaVersion: 13,
9
+ },
10
+ plugins: [
11
+ 'mocha',
12
+ 'chai-expect',
13
+ ],
14
+ extends: [
15
+ 'eslint:recommended',
16
+ 'prettier',
17
+ 'plugin:mocha/recommended',
18
+ 'plugin:chai-expect/recommended',
19
+ ],
20
+ }
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx --no -- commitlint --edit "${1}"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npm run lint:fix
5
+ npm run format
6
+
7
+ npm run test
8
+
9
+ git add -A
package/.mocharc.cjs ADDED
@@ -0,0 +1,7 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ extension: ['js'],
5
+ spec: 'src/**/*.spec.js',
6
+ require: [path.join(__dirname, 'mocha.setup.js')],
7
+ }
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "bracketSpacing": false,
3
+ "singleQuote": true,
4
+ "printWidth": 80,
5
+ "trailingComma": "all",
6
+ "arrowParens": "avoid"
7
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 e22m4u@gmail.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ ## @e22m4u/js-repository-mongodb-adapter
2
+
3
+ MongoDB адаптер для [@e22m4u/js-repository](https://www.npmjs.com/package/@e22m4u/js-repository)
4
+
5
+ ## Установка
6
+
7
+
8
+ ```bash
9
+ npm install @e22m4u/js-repository-mongodb-adapter
10
+ ```
11
+
12
+ *требует пакет [js-repository](https://www.npmjs.com/package/@e22m4u/js-repository)*
13
+
14
+ ## Параметры
15
+
16
+ Все указанные параметры опциональны:
17
+
18
+ | название | значение по умолчанию |
19
+ |----------|-----------------------|
20
+ | protocol | `'mongodb'` |
21
+ | host | `'127.0.0.1'` |
22
+ | port | `27017` |
23
+ | database | `'database'` |
24
+ | username | `undefined` |
25
+ | password | `undefined` |
26
+
27
+ Пример:
28
+
29
+ ```js
30
+ import {Schema} from '@e22m4u/js-repository';
31
+
32
+ const schema = new Schema();
33
+
34
+ // объявление источника
35
+ schema.defineDatasource({
36
+ name: 'myMongo', // название источника
37
+ adapter: 'mongodb', // имя адаптера
38
+ // параметры
39
+ host: '192.128.0.2',
40
+ port: 27017,
41
+ })
42
+
43
+ // объявление модели
44
+ schema.defineModel({
45
+ name: 'user', // название модели
46
+ datasource: 'myMongo', // используемый источник
47
+ properties: { // поля модели
48
+ name: 'string',
49
+ surname: 'string',
50
+ },
51
+ });
52
+
53
+ // получаем репозиторий по названию модели и создаем запись
54
+ const userRep = schema.getRepository('user');
55
+ const user = await userRep.create({name: 'John', surname: 'Doe'});
56
+
57
+ console.log(user);
58
+ // {
59
+ // id: '64f3454e5e0893c13f9bf47e',
60
+ // name: 'John',
61
+ // surname: 'Doe',
62
+ // }
63
+ ```
64
+
65
+ ## Тесты
66
+
67
+ Запуск контейнера `mongodb_c` скриптом `setup.sh`
68
+
69
+ ```bash
70
+ ./setup.sh
71
+ ```
72
+
73
+ Выполнение тестов
74
+
75
+ ```bash
76
+ npm run test
77
+ ```
78
+
79
+ ## Лицензия
80
+
81
+ MIT
package/mocha.setup.js ADDED
@@ -0,0 +1,13 @@
1
+ import url from 'url';
2
+ import chai from 'chai';
3
+ import dotenv from 'dotenv';
4
+ import chaiSpies from 'chai-spies';
5
+ import chaiAsPromised from 'chai-as-promised';
6
+
7
+ process.env['NODE_ENV'] = 'test';
8
+ const dirname = url.fileURLToPath(new URL('.', import.meta.url));
9
+ const envFile = `${dirname}/${process.env['NODE_ENV']}.env`;
10
+ dotenv.config({path: envFile});
11
+
12
+ chai.use(chaiSpies);
13
+ chai.use(chaiAsPromised);
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@e22m4u/js-repository-mongodb-adapter",
3
+ "version": "0.0.14",
4
+ "description": "MongoDB адаптер для @e22m4u/js-repository",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "engines": {
8
+ "node": ">=14"
9
+ },
10
+ "scripts": {
11
+ "lint": "eslint .",
12
+ "lint:fix": "eslint . --fix",
13
+ "format": "prettier --write \"./src/**/*.js\"",
14
+ "test": "eslint . && c8 --reporter=text-summary mocha",
15
+ "test:coverage": "eslint . && c8 --reporter=text mocha",
16
+ "prepare": "npx husky install"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/e22m4u/js-repository-mongodb-adapter.git"
21
+ },
22
+ "keywords": [
23
+ "MongoDB",
24
+ "Repository",
25
+ "ORM",
26
+ "ODM",
27
+ "Database",
28
+ "Datasource",
29
+ "Relation",
30
+ "Inclusion"
31
+ ],
32
+ "author": "e22m4u <e22m4u@gmail.com>",
33
+ "license": "MIT",
34
+ "homepage": "https://github.com/e22m4u/js-repository-mongodb-adapter",
35
+ "dependencies": {
36
+ "mongodb": "5.8.1"
37
+ },
38
+ "peerDependencies": {
39
+ "@e22m4u/js-format": "*",
40
+ "@e22m4u/js-service": "*",
41
+ "@e22m4u/js-repository": "~0.0.31"
42
+ },
43
+ "devDependencies": {
44
+ "@commitlint/cli": "^17.7.1",
45
+ "@commitlint/config-conventional": "^17.7.0",
46
+ "c8": "^8.0.1",
47
+ "chai": "^4.3.7",
48
+ "chai-as-promised": "^7.1.1",
49
+ "chai-spies": "^1.0.0",
50
+ "dotenv": "^16.3.1",
51
+ "eslint": "^8.47.0",
52
+ "eslint-config-prettier": "^9.0.0",
53
+ "eslint-plugin-chai-expect": "^3.0.0",
54
+ "eslint-plugin-mocha": "^10.1.0",
55
+ "husky": "^8.0.3",
56
+ "mocha": "^10.2.0",
57
+ "prettier": "^3.0.1"
58
+ }
59
+ }
package/setup.sh ADDED
@@ -0,0 +1,39 @@
1
+ #!/bin/bash
2
+
3
+ ENV_FILE="test.env"
4
+ SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
5
+
6
+ # Setting env variables
7
+ printf "\nSetting env variables..."
8
+ if [ ! -f .env ]
9
+ then
10
+ # shellcheck disable=SC2046
11
+ export $(xargs -a "$SCRIPT_DIR/$ENV_FILE")
12
+ fi
13
+
14
+ # Checking for docker
15
+ printf "\nChecking for docker...";
16
+ docker -v > /dev/null 2>&1
17
+ DOCKER_EXISTS=$?
18
+ if [ "$DOCKER_EXISTS" -ne 0 ]; then
19
+ printf "\nDocker not found. Terminating setup."
20
+ exit 1
21
+ fi
22
+
23
+ # Pulling latest mongodb image
24
+ printf "\nPulling latest mongodb image..."
25
+ docker pull mongo:latest > /dev/null 2>&1
26
+
27
+ # Starting the mongodb container
28
+ printf "\nStarting the mongodb container..."
29
+ CONTAINER_EXISTS=$(docker ps -a -q -f name="$MONGODB_CONTAINER")
30
+ if [ "$CONTAINER_EXISTS" ]; then
31
+ docker rm -f "$MONGODB_CONTAINER" > /dev/null
32
+ fi
33
+ docker run --name "$MONGODB_CONTAINER" -p "$MONGODB_PORT":27017 -d mongo:latest > /dev/null
34
+
35
+ # Mongodb container has started
36
+ printf "\n\nStatus: Mongodb container has started."
37
+ # shellcheck disable=SC2059
38
+ printf "\nInstance url: mongodb://$MONGODB_HOST:$MONGODB_PORT/$MONGODB_DATABASE"
39
+ printf "\nTo run the test suite: npm test\n\n"
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './mongodb-adapter.js';