Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
856e8e7d1f | |||
7a4d557724 | |||
7cbd0bd99b | |||
e10f6585a5 | |||
5c8dffdd9c | |||
846996eeac | |||
668df09ba0 | |||
03656f4ca0 | |||
c4c612f3a9 | |||
e357f7581c | |||
9697b1e48b | |||
aeb35705d4 | |||
236c8c6551 | |||
1f28db15e7 | |||
86d600e287 | |||
bb81530dac | |||
b9f9b36b87 | |||
df2fadfa01 | |||
8b2beb3485 | |||
144a620f43 | |||
c241247845 | |||
81e39d09e4 | |||
8e51b518b1 | |||
8308d8d03b | |||
97365ddf29 |
@ -12,6 +12,10 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- apt-get update && apt-get install -y libcurl3 libssl-dev openssl libssl1.0.0 mongodb
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@ -36,6 +40,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
26
package-lock.json
generated
26
package-lock.json
generated
@ -1,18 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdata",
|
"name": "@pushrocks/smartdata",
|
||||||
"version": "4.0.2",
|
"version": "4.0.15",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartdata",
|
"name": "@pushrocks/smartdata",
|
||||||
"version": "4.0.2",
|
"version": "4.0.15",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^4.0.20",
|
"@pushrocks/lik": "^4.0.20",
|
||||||
"@pushrocks/smartlog": "^2.0.39",
|
"@pushrocks/smartlog": "^2.0.39",
|
||||||
"@pushrocks/smartpromise": "^3.1.5",
|
"@pushrocks/smartpromise": "^3.1.5",
|
||||||
"@pushrocks/smartstring": "^3.0.24",
|
"@pushrocks/smartstring": "^3.0.24",
|
||||||
|
"@pushrocks/smartunique": "^3.0.3",
|
||||||
"@tsclass/tsclass": "^3.0.33",
|
"@tsclass/tsclass": "^3.0.33",
|
||||||
"@types/lodash": "^4.14.169",
|
"@types/lodash": "^4.14.169",
|
||||||
"@types/mongodb": "^3.6.12",
|
"@types/mongodb": "^3.6.12",
|
||||||
@ -24,7 +25,6 @@
|
|||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tstest": "^1.0.54",
|
"@gitzone/tstest": "^1.0.54",
|
||||||
"@pushrocks/qenv": "^4.0.10",
|
"@pushrocks/qenv": "^4.0.10",
|
||||||
"@pushrocks/smartunique": "^3.0.3",
|
|
||||||
"@pushrocks/tapbundle": "^3.2.14",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/mongodb-memory-server": "^2.3.0",
|
"@types/mongodb-memory-server": "^2.3.0",
|
||||||
"@types/node": "^15.3.0",
|
"@types/node": "^15.3.0",
|
||||||
@ -2622,7 +2622,6 @@
|
|||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartunique/-/smartunique-3.0.3.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartunique/-/smartunique-3.0.3.tgz",
|
||||||
"integrity": "sha512-f+c3s2WzzjASoRHyYTLU0kHDVWREg4sZVdi5L42bTA3CTUWNrcGUC62h4wP4U4BiPl3bopTr3LPhClZHJ738oA==",
|
"integrity": "sha512-f+c3s2WzzjASoRHyYTLU0kHDVWREg4sZVdi5L42bTA3CTUWNrcGUC62h4wP4U4BiPl3bopTr3LPhClZHJ738oA==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/shortid": "0.0.29",
|
"@types/shortid": "0.0.29",
|
||||||
@ -3195,7 +3194,6 @@
|
|||||||
"version": "0.0.29",
|
"version": "0.0.29",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fshortid/-/shortid-0.0.29.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fshortid/-/shortid-0.0.29.tgz",
|
||||||
"integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=",
|
"integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/through2": {
|
"node_modules/@types/through2": {
|
||||||
@ -3239,7 +3237,6 @@
|
|||||||
"version": "7.0.4",
|
"version": "7.0.4",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fuuid/-/uuid-7.0.4.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fuuid/-/uuid-7.0.4.tgz",
|
||||||
"integrity": "sha512-WGZCqBZZ0mXN2RxvLHL6/7RCu+OWs28jgQMP04LWfpyJlQUMTR6YU9CNJAKDgbw+EV/u687INXuLUc7FuML/4g==",
|
"integrity": "sha512-WGZCqBZZ0mXN2RxvLHL6/7RCu+OWs28jgQMP04LWfpyJlQUMTR6YU9CNJAKDgbw+EV/u687INXuLUc7FuML/4g==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/which": {
|
"node_modules/@types/which": {
|
||||||
@ -9442,7 +9439,6 @@
|
|||||||
"version": "2.1.11",
|
"version": "2.1.11",
|
||||||
"resolved": "https://verdaccio.lossless.one/nanoid/-/nanoid-2.1.11.tgz",
|
"resolved": "https://verdaccio.lossless.one/nanoid/-/nanoid-2.1.11.tgz",
|
||||||
"integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==",
|
"integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/nanomatch": {
|
"node_modules/nanomatch": {
|
||||||
@ -12714,7 +12710,6 @@
|
|||||||
"version": "2.2.16",
|
"version": "2.2.16",
|
||||||
"resolved": "https://verdaccio.lossless.one/shortid/-/shortid-2.2.16.tgz",
|
"resolved": "https://verdaccio.lossless.one/shortid/-/shortid-2.2.16.tgz",
|
||||||
"integrity": "sha512-Ugt+GIZqvGXCIItnsL+lvFJOiN7RYqlGy7QE41O3YC1xbNSeDGIRO7xg2JJXIAj1cAGnOeC1r7/T9pgrtQbv4g==",
|
"integrity": "sha512-Ugt+GIZqvGXCIItnsL+lvFJOiN7RYqlGy7QE41O3YC1xbNSeDGIRO7xg2JJXIAj1cAGnOeC1r7/T9pgrtQbv4g==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nanoid": "^2.1.0"
|
"nanoid": "^2.1.0"
|
||||||
@ -14621,7 +14616,6 @@
|
|||||||
"version": "7.0.3",
|
"version": "7.0.3",
|
||||||
"resolved": "https://verdaccio.lossless.one/uuid/-/uuid-7.0.3.tgz",
|
"resolved": "https://verdaccio.lossless.one/uuid/-/uuid-7.0.3.tgz",
|
||||||
"integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==",
|
"integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
"uuid": "dist/bin/uuid"
|
"uuid": "dist/bin/uuid"
|
||||||
@ -17058,7 +17052,6 @@
|
|||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartunique/-/smartunique-3.0.3.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartunique/-/smartunique-3.0.3.tgz",
|
||||||
"integrity": "sha512-f+c3s2WzzjASoRHyYTLU0kHDVWREg4sZVdi5L42bTA3CTUWNrcGUC62h4wP4U4BiPl3bopTr3LPhClZHJ738oA==",
|
"integrity": "sha512-f+c3s2WzzjASoRHyYTLU0kHDVWREg4sZVdi5L42bTA3CTUWNrcGUC62h4wP4U4BiPl3bopTr3LPhClZHJ738oA==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/shortid": "0.0.29",
|
"@types/shortid": "0.0.29",
|
||||||
"@types/uuid": "^7.0.0",
|
"@types/uuid": "^7.0.0",
|
||||||
@ -17527,8 +17520,7 @@
|
|||||||
"@types/shortid": {
|
"@types/shortid": {
|
||||||
"version": "0.0.29",
|
"version": "0.0.29",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fshortid/-/shortid-0.0.29.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fshortid/-/shortid-0.0.29.tgz",
|
||||||
"integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=",
|
"integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"@types/through2": {
|
"@types/through2": {
|
||||||
"version": "2.0.36",
|
"version": "2.0.36",
|
||||||
@ -17565,8 +17557,7 @@
|
|||||||
"@types/uuid": {
|
"@types/uuid": {
|
||||||
"version": "7.0.4",
|
"version": "7.0.4",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fuuid/-/uuid-7.0.4.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fuuid/-/uuid-7.0.4.tgz",
|
||||||
"integrity": "sha512-WGZCqBZZ0mXN2RxvLHL6/7RCu+OWs28jgQMP04LWfpyJlQUMTR6YU9CNJAKDgbw+EV/u687INXuLUc7FuML/4g==",
|
"integrity": "sha512-WGZCqBZZ0mXN2RxvLHL6/7RCu+OWs28jgQMP04LWfpyJlQUMTR6YU9CNJAKDgbw+EV/u687INXuLUc7FuML/4g=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"@types/which": {
|
"@types/which": {
|
||||||
"version": "1.3.2",
|
"version": "1.3.2",
|
||||||
@ -22144,8 +22135,7 @@
|
|||||||
"nanoid": {
|
"nanoid": {
|
||||||
"version": "2.1.11",
|
"version": "2.1.11",
|
||||||
"resolved": "https://verdaccio.lossless.one/nanoid/-/nanoid-2.1.11.tgz",
|
"resolved": "https://verdaccio.lossless.one/nanoid/-/nanoid-2.1.11.tgz",
|
||||||
"integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==",
|
"integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"nanomatch": {
|
"nanomatch": {
|
||||||
"version": "1.2.13",
|
"version": "1.2.13",
|
||||||
@ -24584,7 +24574,6 @@
|
|||||||
"version": "2.2.16",
|
"version": "2.2.16",
|
||||||
"resolved": "https://verdaccio.lossless.one/shortid/-/shortid-2.2.16.tgz",
|
"resolved": "https://verdaccio.lossless.one/shortid/-/shortid-2.2.16.tgz",
|
||||||
"integrity": "sha512-Ugt+GIZqvGXCIItnsL+lvFJOiN7RYqlGy7QE41O3YC1xbNSeDGIRO7xg2JJXIAj1cAGnOeC1r7/T9pgrtQbv4g==",
|
"integrity": "sha512-Ugt+GIZqvGXCIItnsL+lvFJOiN7RYqlGy7QE41O3YC1xbNSeDGIRO7xg2JJXIAj1cAGnOeC1r7/T9pgrtQbv4g==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"nanoid": "^2.1.0"
|
"nanoid": "^2.1.0"
|
||||||
}
|
}
|
||||||
@ -25976,8 +25965,7 @@
|
|||||||
"uuid": {
|
"uuid": {
|
||||||
"version": "7.0.3",
|
"version": "7.0.3",
|
||||||
"resolved": "https://verdaccio.lossless.one/uuid/-/uuid-7.0.3.tgz",
|
"resolved": "https://verdaccio.lossless.one/uuid/-/uuid-7.0.3.tgz",
|
||||||
"integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==",
|
"integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"v8-compile-cache": {
|
"v8-compile-cache": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdata",
|
"name": "@pushrocks/smartdata",
|
||||||
"version": "4.0.2",
|
"version": "4.0.15",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "do more with data",
|
"description": "do more with data",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -25,6 +25,7 @@
|
|||||||
"@pushrocks/smartlog": "^2.0.39",
|
"@pushrocks/smartlog": "^2.0.39",
|
||||||
"@pushrocks/smartpromise": "^3.1.5",
|
"@pushrocks/smartpromise": "^3.1.5",
|
||||||
"@pushrocks/smartstring": "^3.0.24",
|
"@pushrocks/smartstring": "^3.0.24",
|
||||||
|
"@pushrocks/smartunique": "^3.0.3",
|
||||||
"@tsclass/tsclass": "^3.0.33",
|
"@tsclass/tsclass": "^3.0.33",
|
||||||
"@types/lodash": "^4.14.169",
|
"@types/lodash": "^4.14.169",
|
||||||
"@types/mongodb": "^3.6.12",
|
"@types/mongodb": "^3.6.12",
|
||||||
@ -36,7 +37,6 @@
|
|||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tstest": "^1.0.54",
|
"@gitzone/tstest": "^1.0.54",
|
||||||
"@pushrocks/qenv": "^4.0.10",
|
"@pushrocks/qenv": "^4.0.10",
|
||||||
"@pushrocks/smartunique": "^3.0.3",
|
|
||||||
"@pushrocks/tapbundle": "^3.2.14",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/mongodb-memory-server": "^2.3.0",
|
"@types/mongodb-memory-server": "^2.3.0",
|
||||||
"@types/node": "^15.3.0",
|
"@types/node": "^15.3.0",
|
||||||
|
@ -90,7 +90,7 @@ class MyObject extends smartdata.DbDoc<MyObject /* ,[an optional interface to im
|
|||||||
const localObject = new MyObject({
|
const localObject = new MyObject({
|
||||||
property1: 'hi',
|
property1: 'hi',
|
||||||
property2: {
|
property2: {
|
||||||
deep: 3
|
deep: 3,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await localObject.save(); // saves the object to the database
|
await localObject.save(); // saves the object to the database
|
||||||
@ -102,9 +102,9 @@ const myInstance = await MyObject.getInstance({
|
|||||||
property1: 'hi',
|
property1: 'hi',
|
||||||
property2: {
|
property2: {
|
||||||
deep: {
|
deep: {
|
||||||
$gt: 2
|
$gt: 2,
|
||||||
} as any
|
} as any,
|
||||||
}
|
},
|
||||||
}); // outputs a new instance of MyObject with the values from db assigned
|
}); // outputs a new instance of MyObject with the values from db assigned
|
||||||
```
|
```
|
||||||
|
|
||||||
|
59
test/test.easystore.ts
Normal file
59
test/test.easystore.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
|
|
||||||
|
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
|
||||||
|
|
||||||
|
console.log(process.memoryUsage());
|
||||||
|
|
||||||
|
// the tested module
|
||||||
|
import * as smartdata from '../ts/index';
|
||||||
|
|
||||||
|
import * as mongoPlugin from 'mongodb-memory-server';
|
||||||
|
import { smartunique } from '../ts/smartdata.plugins';
|
||||||
|
|
||||||
|
// =======================================
|
||||||
|
// Connecting to the database server
|
||||||
|
// =======================================
|
||||||
|
|
||||||
|
let testDb: smartdata.SmartdataDb;
|
||||||
|
let smartdataOptions: smartdata.IMongoDescriptor;
|
||||||
|
let mongod: mongoPlugin.MongoMemoryServer;
|
||||||
|
|
||||||
|
tap.test('should create a testinstance as database', async () => {
|
||||||
|
mongod = new mongoPlugin.MongoMemoryServer({});
|
||||||
|
console.log('created mongod instance');
|
||||||
|
await mongod._startUpInstance().catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
console.log('mongod started');
|
||||||
|
smartdataOptions = {
|
||||||
|
mongoDbName: await mongod.getDbName(),
|
||||||
|
mongoDbPass: '',
|
||||||
|
mongoDbUrl: await mongod.getUri(),
|
||||||
|
};
|
||||||
|
console.log(smartdataOptions);
|
||||||
|
testDb = new smartdata.SmartdataDb(smartdataOptions);
|
||||||
|
await testDb.init();
|
||||||
|
});
|
||||||
|
|
||||||
|
let easyStore: smartdata.EasyStore<{
|
||||||
|
key1: string;
|
||||||
|
key2: string;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
tap.test('should create an easystore', async () => {
|
||||||
|
easyStore = await testDb.createEasyStore('hellothere');
|
||||||
|
await easyStore.writeKey('key1', 'hello');
|
||||||
|
const retrievedKey = await easyStore.readKey('key1');
|
||||||
|
expect(retrievedKey).to.equal('hello');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('close', async () => {
|
||||||
|
testDb.close();
|
||||||
|
mongod.stop();
|
||||||
|
setTimeout(() => {
|
||||||
|
process.exit(0);
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -134,7 +134,7 @@ tap.test('expect to get instance of Car with deep match', async () => {
|
|||||||
const timeStart = Date.now();
|
const timeStart = Date.now();
|
||||||
const myCars2 = await Car.getInstances({
|
const myCars2 = await Car.getInstances({
|
||||||
deepData: {
|
deepData: {
|
||||||
sodeep: 'yes'
|
sodeep: 'yes',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (counter % 10 === 0) {
|
if (counter % 10 === 0) {
|
||||||
@ -207,12 +207,13 @@ tap.test('should store a new Truck', async () => {
|
|||||||
console.log(myTruck2);
|
console.log(myTruck2);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should ', async () => {})
|
tap.test('should ', async () => {});
|
||||||
|
|
||||||
// =======================================
|
// =======================================
|
||||||
// close the database connection
|
// close the database connection
|
||||||
// =======================================
|
// =======================================
|
||||||
tap.test('should close the database connection', async (tools) => {
|
tap.test('should close the database connection', async (tools) => {
|
||||||
|
await testDb.mongoDb.dropDatabase();
|
||||||
await testDb.close();
|
await testDb.close();
|
||||||
try {
|
try {
|
||||||
await mongod.stop();
|
await mongod.stop();
|
||||||
|
110
test/test.typescript.ts
Normal file
110
test/test.typescript.ts
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
|
|
||||||
|
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
|
||||||
|
|
||||||
|
console.log(process.memoryUsage());
|
||||||
|
|
||||||
|
// the tested module
|
||||||
|
import * as smartdata from '../ts/index';
|
||||||
|
|
||||||
|
import * as mongoPlugin from 'mongodb-memory-server';
|
||||||
|
import { smartunique } from '../ts/smartdata.plugins';
|
||||||
|
|
||||||
|
// =======================================
|
||||||
|
// Connecting to the database server
|
||||||
|
// =======================================
|
||||||
|
|
||||||
|
let testDb: smartdata.SmartdataDb;
|
||||||
|
let smartdataOptions: smartdata.IMongoDescriptor;
|
||||||
|
let mongod: mongoPlugin.MongoMemoryServer;
|
||||||
|
|
||||||
|
const totalCars = 2000;
|
||||||
|
|
||||||
|
tap.skip.test('should create a testinstance as database', async () => {
|
||||||
|
mongod = new mongoPlugin.MongoMemoryServer({});
|
||||||
|
console.log('created mongod instance');
|
||||||
|
await mongod._startUpInstance().catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
console.log('mongod started');
|
||||||
|
smartdataOptions = {
|
||||||
|
mongoDbName: await mongod.getDbName(),
|
||||||
|
mongoDbPass: '',
|
||||||
|
mongoDbUrl: await mongod.getUri(),
|
||||||
|
};
|
||||||
|
console.log(smartdataOptions);
|
||||||
|
testDb = new smartdata.SmartdataDb(smartdataOptions);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should connect to atlas', async (tools) => {
|
||||||
|
const databaseName = `test-smartdata-${smartunique.shortId()}`;
|
||||||
|
testDb = new smartdata.SmartdataDb({
|
||||||
|
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGO_URL'),
|
||||||
|
mongoDbName: databaseName,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should establish a connection to mongod', async () => {
|
||||||
|
await testDb.init();
|
||||||
|
});
|
||||||
|
|
||||||
|
// =======================================
|
||||||
|
// The actual tests
|
||||||
|
// =======================================
|
||||||
|
|
||||||
|
// ------
|
||||||
|
// Collections
|
||||||
|
// ------
|
||||||
|
@smartdata.Manager()
|
||||||
|
class Car extends smartdata.SmartDataDbDoc<Car, Car> {
|
||||||
|
@smartdata.unI()
|
||||||
|
public index: string = smartunique.shortId();
|
||||||
|
|
||||||
|
@smartdata.svDb()
|
||||||
|
public color: string;
|
||||||
|
|
||||||
|
@smartdata.svDb()
|
||||||
|
public brand: string;
|
||||||
|
|
||||||
|
@smartdata.svDb()
|
||||||
|
deepData = {
|
||||||
|
sodeep: 'yes',
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(colorArg: string, brandArg: string) {
|
||||||
|
super();
|
||||||
|
this.color = colorArg;
|
||||||
|
this.brand = brandArg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const createCarClass = (dbArg: smartdata.SmartdataDb) => {
|
||||||
|
smartdata.setDefaultManagerForDoc({ db: dbArg }, Car);
|
||||||
|
return Car;
|
||||||
|
};
|
||||||
|
|
||||||
|
tap.test('should produce a car', async () => {
|
||||||
|
const CarClass = createCarClass(testDb);
|
||||||
|
const carInstance = new CarClass('red', 'Mercedes');
|
||||||
|
await carInstance.save();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should get a car', async () => {
|
||||||
|
const car = Car.getInstance({
|
||||||
|
color: 'red',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// =======================================
|
||||||
|
// close the database connection
|
||||||
|
// =======================================
|
||||||
|
tap.test('should close the database connection', async (tools) => {
|
||||||
|
await testDb.mongoDb.dropDatabase();
|
||||||
|
await testDb.close();
|
||||||
|
try {
|
||||||
|
await mongod.stop();
|
||||||
|
} catch (e) {}
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start({ throwOnError: true });
|
@ -1,5 +1,6 @@
|
|||||||
export * from './smartdata.classes.db';
|
export * from './smartdata.classes.db';
|
||||||
export * from './smartdata.classes.collection';
|
export * from './smartdata.classes.collection';
|
||||||
export * from './smartdata.classes.doc';
|
export * from './smartdata.classes.doc';
|
||||||
|
export * from './smartdata.classes.easystore';
|
||||||
|
|
||||||
export { IMongoDescriptor } from './interfaces';
|
export { IMongoDescriptor } from './interfaces';
|
||||||
|
@ -22,19 +22,82 @@ const collectionFactory = new CollectionFactory();
|
|||||||
* This is a decorator that will tell the decorated class what dbTable to use
|
* This is a decorator that will tell the decorated class what dbTable to use
|
||||||
* @param dbArg
|
* @param dbArg
|
||||||
*/
|
*/
|
||||||
export function Collection<TManager>(dbArg: SmartdataDb | TDelayed<SmartdataDb>, managerArg?: TDelayed<TManager>) {
|
export function Collection(dbArg: SmartdataDb | TDelayed<SmartdataDb>) {
|
||||||
return function classDecorator<T extends { new (...args: any[]): {} }>(constructor: T) {
|
return function classDecorator<T extends { new (...args: any[]): {} }>(constructor: T) {
|
||||||
return class extends constructor {
|
return class extends constructor {
|
||||||
public static get collection() {
|
public static get collection() {
|
||||||
|
if (!(dbArg instanceof SmartdataDb)) {
|
||||||
|
dbArg = dbArg();
|
||||||
|
}
|
||||||
return collectionFactory.getCollection(constructor.name, dbArg);
|
return collectionFactory.getCollection(constructor.name, dbArg);
|
||||||
}
|
}
|
||||||
public get collection() {
|
public get collection() {
|
||||||
|
if (!(dbArg instanceof SmartdataDb)) {
|
||||||
|
dbArg = dbArg();
|
||||||
|
}
|
||||||
return collectionFactory.getCollection(constructor.name, dbArg);
|
return collectionFactory.getCollection(constructor.name, dbArg);
|
||||||
}
|
}
|
||||||
public get manager() {
|
};
|
||||||
if (managerArg) {
|
};
|
||||||
return managerArg();
|
}
|
||||||
|
|
||||||
|
export interface IManager {
|
||||||
|
db: SmartdataDb;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setDefaultManagerForDoc = <T>(managerArg: IManager, dbDocArg: T): T => {
|
||||||
|
(dbDocArg as any).prototype.defaultManager = managerArg;
|
||||||
|
return dbDocArg;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a decorator that will tell the decorated class what dbTable to use
|
||||||
|
* @param dbArg
|
||||||
|
*/
|
||||||
|
export function Manager<TManager extends IManager>(managerArg?: TManager | TDelayed<TManager>) {
|
||||||
|
return function classDecorator<T extends { new (...args: any[]): any }>(constructor: T) {
|
||||||
|
return class extends constructor {
|
||||||
|
public static get collection() {
|
||||||
|
let dbArg: SmartdataDb;
|
||||||
|
if (!managerArg) {
|
||||||
|
dbArg = this.prototype.defaultManager.db;
|
||||||
|
} else if (managerArg['db']) {
|
||||||
|
dbArg = (managerArg as TManager).db;
|
||||||
|
} else {
|
||||||
|
dbArg = (managerArg as TDelayed<TManager>)().db;
|
||||||
}
|
}
|
||||||
|
return collectionFactory.getCollection(constructor.name, dbArg);
|
||||||
|
}
|
||||||
|
public get collection() {
|
||||||
|
let dbArg: SmartdataDb;
|
||||||
|
if (!managerArg) {
|
||||||
|
//console.log(this.defaultManager.db);
|
||||||
|
//process.exit(0)
|
||||||
|
dbArg = this.defaultManager.db;
|
||||||
|
} else if (managerArg['db']) {
|
||||||
|
dbArg = (managerArg as TManager).db;
|
||||||
|
} else {
|
||||||
|
dbArg = (managerArg as TDelayed<TManager>)().db;
|
||||||
|
}
|
||||||
|
return collectionFactory.getCollection(constructor.name, dbArg);
|
||||||
|
}
|
||||||
|
public static get manager() {
|
||||||
|
let manager: TManager;
|
||||||
|
if (managerArg['db']) {
|
||||||
|
manager = managerArg as TManager;
|
||||||
|
} else {
|
||||||
|
manager = (managerArg as TDelayed<TManager>)();
|
||||||
|
}
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
public get manager() {
|
||||||
|
let manager: TManager;
|
||||||
|
if (managerArg['db']) {
|
||||||
|
manager = managerArg as TManager;
|
||||||
|
} else {
|
||||||
|
manager = (managerArg as TDelayed<TManager>)();
|
||||||
|
}
|
||||||
|
return manager;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -5,18 +5,12 @@ import { SmartdataDb } from './smartdata.classes.db';
|
|||||||
export class CollectionFactory {
|
export class CollectionFactory {
|
||||||
public collections: { [key: string]: SmartdataCollection<any> } = {};
|
public collections: { [key: string]: SmartdataCollection<any> } = {};
|
||||||
|
|
||||||
public getCollection = (
|
public getCollection = (nameArg: string, dbArg: SmartdataDb): SmartdataCollection<any> => {
|
||||||
nameArg: string,
|
|
||||||
dbArg: SmartdataDb | (() => SmartdataDb)
|
|
||||||
): SmartdataCollection<any> => {
|
|
||||||
if (!this.collections[nameArg]) {
|
if (!this.collections[nameArg]) {
|
||||||
this.collections[nameArg] = (() => {
|
this.collections[nameArg] = (() => {
|
||||||
if (dbArg instanceof SmartdataDb) {
|
if (dbArg instanceof SmartdataDb) {
|
||||||
// tslint:disable-next-line: no-string-literal
|
// tslint:disable-next-line: no-string-literal
|
||||||
return new SmartdataCollection(nameArg, dbArg);
|
return new SmartdataCollection(nameArg, dbArg);
|
||||||
} else {
|
|
||||||
dbArg = dbArg();
|
|
||||||
return new SmartdataCollection(nameArg, dbArg);
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import * as plugins from './smartdata.plugins';
|
|||||||
import { ObjectMap } from '@pushrocks/lik';
|
import { ObjectMap } from '@pushrocks/lik';
|
||||||
|
|
||||||
import { SmartdataCollection } from './smartdata.classes.collection';
|
import { SmartdataCollection } from './smartdata.classes.collection';
|
||||||
|
import { EasyStore } from './smartdata.classes.easystore';
|
||||||
|
|
||||||
import { logger } from './smartdata.logging';
|
import { logger } from './smartdata.logging';
|
||||||
import { IMongoDescriptor } from './interfaces';
|
import { IMongoDescriptor } from './interfaces';
|
||||||
@ -23,6 +24,12 @@ export class SmartdataDb {
|
|||||||
this.status = 'initial';
|
this.status = 'initial';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// easystore
|
||||||
|
public async createEasyStore(nameIdArg: string) {
|
||||||
|
const easyStore = new EasyStore(nameIdArg, this);
|
||||||
|
return easyStore;
|
||||||
|
}
|
||||||
|
|
||||||
// basic connection stuff ----------------------------------------------
|
// basic connection stuff ----------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,7 +3,7 @@ import * as plugins from './smartdata.plugins';
|
|||||||
import { ObjectMap } from '@pushrocks/lik';
|
import { ObjectMap } from '@pushrocks/lik';
|
||||||
|
|
||||||
import { SmartdataDb } from './smartdata.classes.db';
|
import { SmartdataDb } from './smartdata.classes.db';
|
||||||
import { SmartdataCollection } from './smartdata.classes.collection';
|
import { IManager, SmartdataCollection } from './smartdata.classes.collection';
|
||||||
|
|
||||||
export type TDocCreation = 'db' | 'new' | 'mixed';
|
export type TDocCreation = 'db' | 'new' | 'mixed';
|
||||||
|
|
||||||
@ -41,12 +41,15 @@ export function unI() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SmartDataDbDoc<T extends TImplements, TImplements> {
|
export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends IManager = any> {
|
||||||
/**
|
/**
|
||||||
* the collection object an Doc belongs to
|
* the collection object an Doc belongs to
|
||||||
*/
|
*/
|
||||||
public static collection: SmartdataCollection<any>;
|
public static collection: SmartdataCollection<any>;
|
||||||
public collection: SmartdataCollection<any>;
|
public collection: SmartdataCollection<any>;
|
||||||
|
public static defaultManager;
|
||||||
|
public static manager;
|
||||||
|
public manager: TManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* how the Doc in memory was created, may prove useful later.
|
* how the Doc in memory was created, may prove useful later.
|
||||||
@ -95,11 +98,11 @@ export class SmartDataDbDoc<T extends TImplements, TImplements> {
|
|||||||
}
|
}
|
||||||
for (const key of Object.keys(filterArg2)) {
|
for (const key of Object.keys(filterArg2)) {
|
||||||
convertFilterArgument(`${keyPathArg}.${key}`, filterArg2[key]);
|
convertFilterArgument(`${keyPathArg}.${key}`, filterArg2[key]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
convertedFilter[keyPathArg] = filterArg2
|
convertedFilter[keyPathArg] = filterArg2;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
for (const key of Object.keys(filterArg)) {
|
for (const key of Object.keys(filterArg)) {
|
||||||
convertFilterArgument(key, filterArg[key]);
|
convertFilterArgument(key, filterArg[key]);
|
||||||
}
|
}
|
||||||
|
93
ts/smartdata.classes.easystore.ts
Normal file
93
ts/smartdata.classes.easystore.ts
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import * as plugins from './smartdata.plugins';
|
||||||
|
import { Collection } from './smartdata.classes.collection';
|
||||||
|
import { SmartdataDb } from './smartdata.classes.db';
|
||||||
|
import { SmartDataDbDoc, svDb, unI } from './smartdata.classes.doc';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EasyStore allows the storage of easy objects. It also allows easy sharing of the object between different instances
|
||||||
|
*/
|
||||||
|
export class EasyStore<T> {
|
||||||
|
// instance
|
||||||
|
public smartdataDbRef: SmartdataDb;
|
||||||
|
public nameId: string;
|
||||||
|
|
||||||
|
private easyStoreClass = (() => {
|
||||||
|
@Collection(() => this.smartdataDbRef)
|
||||||
|
class SmartdataEasyStore extends SmartDataDbDoc<SmartdataEasyStore, SmartdataEasyStore> {
|
||||||
|
@unI()
|
||||||
|
public nameId: string;
|
||||||
|
|
||||||
|
@svDb()
|
||||||
|
public data: Partial<T>;
|
||||||
|
}
|
||||||
|
return SmartdataEasyStore;
|
||||||
|
})();
|
||||||
|
|
||||||
|
constructor(nameIdArg: string, smnartdataDbRefArg: SmartdataDb) {
|
||||||
|
this.smartdataDbRef = smnartdataDbRefArg;
|
||||||
|
this.nameId = nameIdArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getEasyStore() {
|
||||||
|
let easyStore = await this.easyStoreClass.getInstance({
|
||||||
|
nameId: this.nameId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!easyStore) {
|
||||||
|
easyStore = new this.easyStoreClass();
|
||||||
|
easyStore.nameId = this.nameId;
|
||||||
|
easyStore.data = {};
|
||||||
|
await easyStore.save();
|
||||||
|
}
|
||||||
|
return easyStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reads all keyValue pairs at once and returns them
|
||||||
|
*/
|
||||||
|
public async readAll() {
|
||||||
|
const easyStore = await this.getEasyStore();
|
||||||
|
return easyStore.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reads a keyValueFile from disk
|
||||||
|
*/
|
||||||
|
public async readKey(keyArg: keyof T) {
|
||||||
|
const easyStore = await this.getEasyStore();
|
||||||
|
return easyStore.data[keyArg];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* writes a specific key to the keyValueStore
|
||||||
|
*/
|
||||||
|
public async writeKey(keyArg: keyof T, valueArg: any) {
|
||||||
|
const easyStore = await this.getEasyStore();
|
||||||
|
easyStore.data[keyArg] = valueArg;
|
||||||
|
await easyStore.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteKey(keyArg: keyof T) {
|
||||||
|
const easyStore = await this.getEasyStore();
|
||||||
|
delete easyStore.data[keyArg];
|
||||||
|
await easyStore.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* writes all keyValue pairs in the object argument
|
||||||
|
*/
|
||||||
|
public async writeAll(keyValueObject: Partial<T>) {
|
||||||
|
const easyStore = await this.getEasyStore();
|
||||||
|
easyStore.data = { ...easyStore.data, ...keyValueObject };
|
||||||
|
await easyStore.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wipes a key value store from disk
|
||||||
|
*/
|
||||||
|
public async wipe() {
|
||||||
|
const easyStore = await this.getEasyStore();
|
||||||
|
easyStore.data = {};
|
||||||
|
await easyStore.save();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user