Compare commits

..

16 Commits

Author SHA1 Message Date
ef97b390d4 5.0.10 2022-11-08 10:26:21 +01:00
cd14eb8bf3 fix(core): update 2022-11-08 10:26:20 +01:00
f48443dcd3 5.0.9 2022-11-01 18:23:58 +01:00
3f28ff80cb fix(core): update 2022-11-01 18:23:57 +01:00
64005a0b32 5.0.8 2022-09-12 11:37:54 +02:00
8a77bb3281 fix(core): update 2022-09-12 11:37:53 +02:00
25f50ecf51 5.0.7 2022-06-14 22:04:35 +02:00
ad87f8147b fix(core): update 2022-06-14 22:04:34 +02:00
da0c9873eb 5.0.6 2022-06-14 22:02:57 +02:00
2fcd3f1550 fix(core): update 2022-06-14 22:02:57 +02:00
f726cf4c5b 5.0.5 2022-06-05 17:19:12 +02:00
c198969fae fix(core): update 2022-06-05 17:19:12 +02:00
be1badeb23 5.0.4 2022-06-05 17:18:13 +02:00
fe065b966f fix(core): update 2022-06-05 17:18:13 +02:00
811e2490b8 5.0.3 2022-05-19 16:15:28 +02:00
206ccd40e9 fix(watcher.changeSubject): now emits correct type into observer functions 2022-05-19 16:15:28 +02:00
17 changed files with 5452 additions and 10866 deletions

View File

@ -13,31 +13,24 @@ stages:
- metadata - metadata
before_script: before_script:
- npm install -g @shipzone/npmci - pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ==================== # ====================
# security stage # security stage
# ==================== # ====================
mirror: # ====================
stage: security # security stage
script: # ====================
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm install --production --ignore-scripts - npmci command pnpm audit --audit-level=high --prod
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- lossless
- docker - docker
allow_failure: true allow_failure: true
@ -45,11 +38,10 @@ auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev - npmci command pnpm audit --audit-level=high --dev
tags: tags:
- lossless
- docker - docker
allow_failure: true allow_failure: true
@ -60,7 +52,6 @@ auditDevDependencies:
testStable: testStable:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
@ -71,7 +62,6 @@ testStable:
testBuild: testBuild:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci command npm run build
@ -100,10 +90,9 @@ codequality:
only: only:
- tags - tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g typescript
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless - lossless
- docker - docker
@ -123,11 +112,9 @@ trigger:
pages: pages:
stage: metadata stage: metadata
script: script:
- npmci node install lts - npmci node install stable
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command npm run buildDocs
tags: tags:
- lossless - lossless
- docker - docker

View File

@ -15,7 +15,7 @@
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",
"gitrepo": "smartdata", "gitrepo": "smartdata",
"shortDescription": "do more with data", "description": "do more with data",
"npmPackagename": "@pushrocks/smartdata", "npmPackagename": "@pushrocks/smartdata",
"license": "MIT" "license": "MIT"
} }

10765
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartdata", "name": "@pushrocks/smartdata",
"version": "5.0.2", "version": "5.0.10",
"private": false, "private": false,
"description": "do more with data", "description": "do more with data",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -8,7 +8,8 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"test": "tstest test/", "test": "tstest test/",
"build": "tsbuild --web --allowimplicitany" "build": "tsbuild --web --allowimplicitany",
"buildDocs": "tsdoc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -21,26 +22,26 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartdata#README", "homepage": "https://gitlab.com/pushrocks/smartdata#README",
"dependencies": { "dependencies": {
"@pushrocks/lik": "^5.0.4", "@pushrocks/lik": "^6.0.0",
"@pushrocks/smartdelay": "^2.0.13", "@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartlog": "^2.0.44", "@pushrocks/smartlog": "^3.0.1",
"@pushrocks/smartmongo": "^2.0.1", "@pushrocks/smartmongo": "^2.0.7",
"@pushrocks/smartpromise": "^3.1.7", "@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartrx": "^2.0.25", "@pushrocks/smartrx": "^3.0.0",
"@pushrocks/smartstring": "^4.0.2", "@pushrocks/smartstring": "^4.0.2",
"@pushrocks/smartunique": "^3.0.3", "@pushrocks/smartunique": "^3.0.3",
"@tsclass/tsclass": "^4.0.2", "@tsclass/tsclass": "^4.0.19",
"@types/lodash": "^4.14.182", "@types/lodash": "^4.14.188",
"@types/mongodb": "^4.0.7",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"mongodb": "^4.6.0" "mongodb": "^4.9.1"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.61", "@gitzone/tsbuild": "^2.1.65",
"@gitzone/tstest": "^1.0.71", "@gitzone/tsrun": "^1.2.37",
"@pushrocks/qenv": "^4.0.10", "@gitzone/tstest": "^1.0.74",
"@pushrocks/tapbundle": "^5.0.3", "@pushrocks/qenv": "^5.0.2",
"@types/node": "^17.0.34", "@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.7.16",
"@types/shortid": "0.0.29" "@types/shortid": "0.0.29"
}, },
"files": [ "files": [

5350
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,8 @@ import { Qenv } from '@pushrocks/qenv';
import * as smartmongo from '@pushrocks/smartmongo'; import * as smartmongo from '@pushrocks/smartmongo';
import { smartunique } from '../ts/smartdata.plugins.js'; import { smartunique } from '../ts/smartdata.plugins.js';
import * as mongodb from 'mongodb';
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/'); const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
console.log(process.memoryUsage()); console.log(process.memoryUsage());
@ -55,6 +57,9 @@ class Car extends smartdata.SmartDataDbDoc<Car, Car> {
@smartdata.svDb() @smartdata.svDb()
public brand: string; public brand: string;
@smartdata.svDb()
public testBuffer = Buffer.from('hello');
@smartdata.svDb() @smartdata.svDb()
deepData = { deepData = {
sodeep: 'yes', sodeep: 'yes',
@ -67,7 +72,7 @@ class Car extends smartdata.SmartDataDbDoc<Car, Car> {
} }
} }
tap.test('should save the car to the db', async () => { tap.test('should save the car to the db', async (toolsArg) => {
const myCar = new Car('red', 'Volvo'); const myCar = new Car('red', 'Volvo');
await myCar.save(); await myCar.save();
@ -75,6 +80,9 @@ tap.test('should save the car to the db', async () => {
await myCar2.save(); await myCar2.save();
let counter = 0; let counter = 0;
const gottenCarInstance = await Car.getInstance({});
console.log(gottenCarInstance.testBuffer instanceof mongodb.Binary);
process.memoryUsage(); process.memoryUsage();
do { do {
const myCar3 = new Car('red', 'Renault'); const myCar3 = new Car('red', 'Renault');

View File

@ -42,14 +42,14 @@ class House extends smartdata.SmartDataDbDoc<House, House> {
@smartdata.svDb() @smartdata.svDb()
public data = { public data = {
id: smartunique.shortId(), id: smartunique.shortId(),
hello: 'hello' hello: 'hello',
} };
} }
tap.test('should watch a collection', async (toolsArg) => { tap.test('should watch a collection', async (toolsArg) => {
const done = toolsArg.defer(); const done = toolsArg.defer();
const watcher = await House.watch({}); const watcher = await House.watch({});
watcher.changeSubject.subscribe(async houseArg => { watcher.changeSubject.subscribe(async (houseArg) => {
console.log('hey there, we observed a house'); console.log('hey there, we observed a house');
await watcher.close(); await watcher.close();
done.resolve(); done.resolve();
@ -58,7 +58,7 @@ tap.test('should watch a collection', async (toolsArg) => {
await newHouse.save(); await newHouse.save();
console.log('saved a house'); console.log('saved a house');
await done.promise; await done.promise;
}) });
// ======================================= // =======================================
// close the database connection // close the database connection
@ -71,4 +71,4 @@ tap.test('close', async () => {
} }
}); });
tap.start({ throwOnError: true }); tap.start({ throwOnError: true });

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@pushrocks/smartdata', name: '@pushrocks/smartdata',
version: '5.0.2', version: '5.0.10',
description: 'do more with data' description: 'do more with data'
} }

View File

@ -4,4 +4,7 @@ export * from './smartdata.classes.doc.js';
export * from './smartdata.classes.easystore.js'; export * from './smartdata.classes.easystore.js';
export * from './smartdata.classes.cursor.js'; export * from './smartdata.classes.cursor.js';
export type { IMongoDescriptor } from './interfaces/index.js'; // to be removed with the next breaking update
import * as plugins from './smartdata.plugins.js';
type IMongoDescriptor = plugins.tsclass.database.IMongoDescriptor;
export type { IMongoDescriptor };

View File

@ -1 +0,0 @@
export * from './mongodescriptor.js';

View File

@ -1,22 +0,0 @@
export interface IMongoDescriptor {
/**
* the URL to connect to
*/
mongoDbUrl: string;
/**
* the db to use for the project
*/
mongoDbName?: string;
/**
* a username to use to connect to the database
*/
mongoDbUser?: string;
/**
* an optional password that will be replace <PASSWORD> in the connection string
*/
mongoDbPass?: string;
}

View File

@ -109,7 +109,6 @@ export function Manager<TManager extends IManager>(managerArg?: TManager | TDela
}; };
} }
// tslint:disable-next-line: max-classes-per-file
export class SmartdataCollection<T> { export class SmartdataCollection<T> {
/** /**
* the collection that is used * the collection that is used
@ -180,7 +179,10 @@ export class SmartdataCollection<T> {
return result; return result;
} }
public async getCursor(filterObjectArg: any, dbDocArg: typeof SmartDataDbDoc): Promise<SmartdataDbCursor<any>> { public async getCursor(
filterObjectArg: any,
dbDocArg: typeof SmartDataDbDoc
): Promise<SmartdataDbCursor<any>> {
await this.init(); await this.init();
const cursor = this.mongoDbCollection.find(filterObjectArg); const cursor = this.mongoDbCollection.find(filterObjectArg);
return new SmartdataDbCursor(cursor, dbDocArg); return new SmartdataDbCursor(cursor, dbDocArg);
@ -200,16 +202,22 @@ export class SmartdataCollection<T> {
/** /**
* watches the collection while applying a filter * watches the collection while applying a filter
*/ */
public async watch(filterObject: any, smartdataDbDocArg: typeof SmartDataDbDoc): Promise<SmartdataDbWatcher> { public async watch(
filterObject: any,
smartdataDbDocArg: typeof SmartDataDbDoc
): Promise<SmartdataDbWatcher> {
await this.init(); await this.init();
const changeStream = this.mongoDbCollection.watch([ const changeStream = this.mongoDbCollection.watch(
[
{
$match: filterObject,
},
],
{ {
$match: filterObject fullDocument: 'updateLookup',
} }
], { );
fullDocument: 'updateLookup' const smartdataWatcher = new SmartdataDbWatcher(changeStream, smartdataDbDocArg);
});
const smartdataWatcher = new SmartdataDbWatcher(changeStream, smartdataDbDocArg);
await smartdataWatcher.readyDeferred.promise; await smartdataWatcher.readyDeferred.promise;
return smartdataWatcher; return smartdataWatcher;
} }

View File

@ -16,20 +16,23 @@ export class SmartdataDbCursor<T = any> {
} }
public async next(closeAtEnd = true) { public async next(closeAtEnd = true) {
const result = this.smartdataDbDoc.createInstanceFromMongoDbNativeDoc(await this.mongodbCursor.next()); const result = this.smartdataDbDoc.createInstanceFromMongoDbNativeDoc(
await this.mongodbCursor.next()
);
if (!result && closeAtEnd) { if (!result && closeAtEnd) {
await this.close(); await this.close();
} }
return result; return result;
} }
public async forEach(forEachFuncArg: (itemArg: any) => Promise<any>, closeCursorAtEnd = true) { public async forEach(forEachFuncArg: (itemArg: T) => Promise<any>, closeCursorAtEnd = true) {
let nextDocument: any; let nextDocument: any;
do { do {
nextDocument = await this.mongodbCursor.next(); nextDocument = await this.mongodbCursor.next();
if (nextDocument) { if (nextDocument) {
const nextClassInstance = this.smartdataDbDoc.createInstanceFromMongoDbNativeDoc(nextDocument); const nextClassInstance =
await forEachFuncArg(nextClassInstance); this.smartdataDbDoc.createInstanceFromMongoDbNativeDoc(nextDocument);
await forEachFuncArg(nextClassInstance as any);
} }
} while (nextDocument); } while (nextDocument);
if (closeCursorAtEnd) { if (closeCursorAtEnd) {

View File

@ -5,7 +5,6 @@ import { SmartdataCollection } from './smartdata.classes.collection.js';
import { EasyStore } from './smartdata.classes.easystore.js'; import { EasyStore } from './smartdata.classes.easystore.js';
import { logger } from './smartdata.logging.js'; import { logger } from './smartdata.logging.js';
import { IMongoDescriptor } from './interfaces/index.js';
/** /**
* interface - indicates the connection status of the db * interface - indicates the connection status of the db
@ -13,13 +12,13 @@ import { IMongoDescriptor } from './interfaces/index.js';
export type TConnectionStatus = 'initial' | 'disconnected' | 'connected' | 'failed'; export type TConnectionStatus = 'initial' | 'disconnected' | 'connected' | 'failed';
export class SmartdataDb { export class SmartdataDb {
smartdataOptions: IMongoDescriptor; smartdataOptions: plugins.tsclass.database.IMongoDescriptor;
mongoDbClient: plugins.mongodb.MongoClient; mongoDbClient: plugins.mongodb.MongoClient;
mongoDb: plugins.mongodb.Db; mongoDb: plugins.mongodb.Db;
status: TConnectionStatus; status: TConnectionStatus;
smartdataCollectionMap = new ObjectMap<SmartdataCollection<any>>(); smartdataCollectionMap = new ObjectMap<SmartdataCollection<any>>();
constructor(smartdataOptions: IMongoDescriptor) { constructor(smartdataOptions: plugins.tsclass.database.IMongoDescriptor) {
this.smartdataOptions = smartdataOptions; this.smartdataOptions = smartdataOptions;
this.status = 'initial'; this.status = 'initial';
} }

View File

@ -147,18 +147,18 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
/** /**
* watch the collection * watch the collection
* @param this * @param this
* @param filterArg * @param filterArg
* @param forEachFunction * @param forEachFunction
*/ */
public static async watch<T>( public static async watch<T>(
this: plugins.tsclass.typeFest.Class<T>, this: plugins.tsclass.typeFest.Class<T>,
filterArg: plugins.tsclass.typeFest.PartialDeep<T> filterArg: plugins.tsclass.typeFest.PartialDeep<T>
) { ) {
const collection: SmartdataCollection<T> = (this as any).collection; const collection: SmartdataCollection<T> = (this as any).collection;
const watcher: SmartdataDbWatcher<T> = await collection.watch( const watcher: SmartdataDbWatcher<T> = await collection.watch(
convertFilterForMongoDb(filterArg), convertFilterForMongoDb(filterArg),
(this as any) this as any
); );
return watcher; return watcher;
} }

View File

@ -11,12 +11,17 @@ export class SmartdataDbWatcher<T = any> {
// INSTANCE // INSTANCE
private changeStream: plugins.mongodb.ChangeStream<T>; private changeStream: plugins.mongodb.ChangeStream<T>;
public changeSubject = new plugins.smartrx.rxjs.Subject<SmartDataDbDoc<T, T>>(); public changeSubject = new plugins.smartrx.rxjs.Subject<T>();
constructor(changeStreamArg: plugins.mongodb.ChangeStream<T>, smartdataDbDocArg: typeof SmartDataDbDoc) { constructor(
changeStreamArg: plugins.mongodb.ChangeStream<T>,
smartdataDbDocArg: typeof SmartDataDbDoc
) {
this.changeStream = changeStreamArg; this.changeStream = changeStreamArg;
this.changeStream.on('change', async (item: T) => { this.changeStream.on('change', async (item: T) => {
this.changeSubject.next(smartdataDbDocArg.createInstanceFromMongoDbNativeDoc(item)); this.changeSubject.next(
}) smartdataDbDocArg.createInstanceFromMongoDbNativeDoc(item) as any as T
);
});
plugins.smartdelay.delayFor(0).then(() => { plugins.smartdelay.delayFor(0).then(() => {
this.readyDeferred.resolve(); this.readyDeferred.resolve();
}); });

View File

@ -7,11 +7,21 @@ export { tsclass };
import * as smartlog from '@pushrocks/smartlog'; import * as smartlog from '@pushrocks/smartlog';
import * as lodash from 'lodash'; import * as lodash from 'lodash';
import * as mongodb from 'mongodb'; import * as mongodb from 'mongodb';
import * as smartdelay from '@pushrocks/smartdelay' import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartq from '@pushrocks/smartpromise'; import * as smartq from '@pushrocks/smartpromise';
import * as smartrx from '@pushrocks/smartrx'; import * as smartrx from '@pushrocks/smartrx';
import * as smartstring from '@pushrocks/smartstring'; import * as smartstring from '@pushrocks/smartstring';
import * as smartunique from '@pushrocks/smartunique'; import * as smartunique from '@pushrocks/smartunique';
export { smartdelay, smartpromise, smartlog, lodash, smartq, smartrx, mongodb, smartstring, smartunique }; export {
smartdelay,
smartpromise,
smartlog,
lodash,
smartq,
smartrx,
mongodb,
smartstring,
smartunique,
};