Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
055298172f | |||
278f3c8169 | |||
0709ba921b | |||
de1f1110b4 |
18
package-lock.json
generated
18
package-lock.json
generated
@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdata",
|
"name": "@pushrocks/smartdata",
|
||||||
"version": "5.0.0",
|
"version": "5.0.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartdata",
|
"name": "@pushrocks/smartdata",
|
||||||
"version": "5.0.0",
|
"version": "5.0.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^5.0.4",
|
"@pushrocks/lik": "^5.0.4",
|
||||||
"@pushrocks/smartdelay": "^2.0.13",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartlog": "^2.0.44",
|
"@pushrocks/smartlog": "^2.0.44",
|
||||||
"@pushrocks/smartmongo": "^2.0.0",
|
"@pushrocks/smartmongo": "^2.0.1",
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartrx": "^2.0.25",
|
"@pushrocks/smartrx": "^2.0.25",
|
||||||
"@pushrocks/smartstring": "^4.0.2",
|
"@pushrocks/smartstring": "^4.0.2",
|
||||||
@ -802,9 +802,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@pushrocks/smartmongo": {
|
"node_modules/@pushrocks/smartmongo": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.1",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmongo/-/smartmongo-2.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmongo/-/smartmongo-2.0.1.tgz",
|
||||||
"integrity": "sha512-YDUDQqU3ReLJvZi3CJXqn5LULOrhKdpShvSnYx4fLqCyBoP0sDA3SBP5L2arTmF5IlrhreWqBL5AX3Guegt5jQ==",
|
"integrity": "sha512-apKedLxGTd5HO6Ke43ZknA4aMI+3tTNBXAzyalHgxh+b/p5fx62mCbgpxpR5EOXfxpPiHk7eaDip6k06a2hw1Q==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdata": "^4.0.27",
|
"@pushrocks/smartdata": "^4.0.27",
|
||||||
@ -6941,9 +6941,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@pushrocks/smartmongo": {
|
"@pushrocks/smartmongo": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.1",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmongo/-/smartmongo-2.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmongo/-/smartmongo-2.0.1.tgz",
|
||||||
"integrity": "sha512-YDUDQqU3ReLJvZi3CJXqn5LULOrhKdpShvSnYx4fLqCyBoP0sDA3SBP5L2arTmF5IlrhreWqBL5AX3Guegt5jQ==",
|
"integrity": "sha512-apKedLxGTd5HO6Ke43ZknA4aMI+3tTNBXAzyalHgxh+b/p5fx62mCbgpxpR5EOXfxpPiHk7eaDip6k06a2hw1Q==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/smartdata": "^4.0.27",
|
"@pushrocks/smartdata": "^4.0.27",
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdata",
|
"name": "@pushrocks/smartdata",
|
||||||
"version": "5.0.0",
|
"version": "5.0.2",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "do more with data",
|
"description": "do more with data",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -24,7 +24,7 @@
|
|||||||
"@pushrocks/lik": "^5.0.4",
|
"@pushrocks/lik": "^5.0.4",
|
||||||
"@pushrocks/smartdelay": "^2.0.13",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartlog": "^2.0.44",
|
"@pushrocks/smartlog": "^2.0.44",
|
||||||
"@pushrocks/smartmongo": "^2.0.0",
|
"@pushrocks/smartmongo": "^2.0.1",
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartrx": "^2.0.25",
|
"@pushrocks/smartrx": "^2.0.25",
|
||||||
"@pushrocks/smartstring": "^4.0.2",
|
"@pushrocks/smartstring": "^4.0.2",
|
||||||
|
@ -92,7 +92,7 @@ tap.test('should save the car to the db', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('expect to get instance of Car with shallow match', async () => {
|
tap.test('expect to get instance of Car with shallow match', async () => {
|
||||||
const totalQueryCycles = totalCars / 2;
|
const totalQueryCycles = totalCars / 6;
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
do {
|
do {
|
||||||
const timeStart = Date.now();
|
const timeStart = Date.now();
|
||||||
@ -113,7 +113,7 @@ tap.test('expect to get instance of Car with shallow match', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('expect to get instance of Car with deep match', async () => {
|
tap.test('expect to get instance of Car with deep match', async () => {
|
||||||
const totalQueryCycles = totalCars / 4;
|
const totalQueryCycles = totalCars / 6;
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
do {
|
do {
|
||||||
const timeStart = Date.now();
|
const timeStart = Date.now();
|
||||||
|
@ -19,13 +19,13 @@ let testDb: smartdata.SmartdataDb;
|
|||||||
|
|
||||||
const totalCars = 2000;
|
const totalCars = 2000;
|
||||||
|
|
||||||
tap.skip.test('should create a testinstance as database', async () => {
|
tap.test('should create a testinstance as database', async () => {
|
||||||
smartmongoInstance = await smartmongo.SmartMongo.createAndStart();
|
smartmongoInstance = await smartmongo.SmartMongo.createAndStart();
|
||||||
testDb = new smartdata.SmartdataDb(await smartmongoInstance.getMongoDescriptor());
|
testDb = new smartdata.SmartdataDb(await smartmongoInstance.getMongoDescriptor());
|
||||||
await testDb.init();
|
await testDb.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should connect to atlas', async (tools) => {
|
tap.skip.test('should connect to atlas', async (tools) => {
|
||||||
const databaseName = `test-smartdata-${smartunique.shortId()}`;
|
const databaseName = `test-smartdata-${smartunique.shortId()}`;
|
||||||
testDb = new smartdata.SmartdataDb({
|
testDb = new smartdata.SmartdataDb({
|
||||||
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGO_URL'),
|
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGO_URL'),
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartdata',
|
name: '@pushrocks/smartdata',
|
||||||
version: '5.0.0',
|
version: '5.0.2',
|
||||||
description: 'do more with data'
|
description: 'do more with data'
|
||||||
}
|
}
|
||||||
|
@ -180,10 +180,10 @@ export class SmartdataCollection<T> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getCursor(filterObject: any): 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(filterObject);
|
const cursor = this.mongoDbCollection.find(filterObjectArg);
|
||||||
return new SmartdataDbCursor(cursor);
|
return new SmartdataDbCursor(cursor, dbDocArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -200,7 +200,7 @@ export class SmartdataCollection<T> {
|
|||||||
/**
|
/**
|
||||||
* watches the collection while applying a filter
|
* watches the collection while applying a filter
|
||||||
*/
|
*/
|
||||||
public async watch(filterObject: any): 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([
|
||||||
{
|
{
|
||||||
@ -209,7 +209,7 @@ export class SmartdataCollection<T> {
|
|||||||
], {
|
], {
|
||||||
fullDocument: 'updateLookup'
|
fullDocument: 'updateLookup'
|
||||||
});
|
});
|
||||||
const smartdataWatcher = new SmartdataDbWatcher(changeStream);
|
const smartdataWatcher = new SmartdataDbWatcher(changeStream, smartdataDbDocArg);
|
||||||
await smartdataWatcher.readyDeferred.promise;
|
await smartdataWatcher.readyDeferred.promise;
|
||||||
return smartdataWatcher;
|
return smartdataWatcher;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { SmartDataDbDoc } from './smartdata.classes.doc.js';
|
||||||
import * as plugins from './smartdata.plugins.js';
|
import * as plugins from './smartdata.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,26 +9,29 @@ export class SmartdataDbCursor<T = any> {
|
|||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public mongodbCursor: plugins.mongodb.FindCursor<T>;
|
public mongodbCursor: plugins.mongodb.FindCursor<T>;
|
||||||
constructor(cursorArg: plugins.mongodb.FindCursor<T>) {
|
private smartdataDbDoc: typeof SmartDataDbDoc;
|
||||||
|
constructor(cursorArg: plugins.mongodb.FindCursor<T>, dbDocArg: typeof SmartDataDbDoc) {
|
||||||
this.mongodbCursor = cursorArg;
|
this.mongodbCursor = cursorArg;
|
||||||
|
this.smartdataDbDoc = dbDocArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async next(closeAtEnd = true) {
|
public async next(closeAtEnd = true) {
|
||||||
const result = 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: T) => Promise<any>, closeCursorAtEnd = true) {
|
public async forEach(forEachFuncArg: (itemArg: any) => Promise<any>, closeCursorAtEnd = true) {
|
||||||
let currentValue: T;
|
let nextDocument: any;
|
||||||
do {
|
do {
|
||||||
currentValue = await this.mongodbCursor.next();
|
nextDocument = await this.mongodbCursor.next();
|
||||||
if (currentValue) {
|
if (nextDocument) {
|
||||||
await forEachFuncArg(currentValue);
|
const nextClassInstance = this.smartdataDbDoc.createInstanceFromMongoDbNativeDoc(nextDocument);
|
||||||
|
await forEachFuncArg(nextClassInstance);
|
||||||
}
|
}
|
||||||
} while (currentValue);
|
} while (nextDocument);
|
||||||
if (closeCursorAtEnd) {
|
if (closeCursorAtEnd) {
|
||||||
await this.close();
|
await this.close();
|
||||||
}
|
}
|
||||||
|
@ -137,8 +137,10 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
|||||||
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 cursor: SmartdataDbCursor<T> = await (this as any).collection.getCursor(
|
const collection: SmartdataCollection<T> = (this as any).collection;
|
||||||
convertFilterForMongoDb(filterArg)
|
const cursor: SmartdataDbCursor<T> = await collection.getCursor(
|
||||||
|
convertFilterForMongoDb(filterArg),
|
||||||
|
this as any as typeof SmartDataDbDoc
|
||||||
);
|
);
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
@ -155,7 +157,8 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
|||||||
) {
|
) {
|
||||||
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)
|
||||||
);
|
);
|
||||||
return watcher;
|
return watcher;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { SmartDataDbDoc } from './smartdata.classes.doc.js';
|
||||||
import * as plugins from './smartdata.plugins.js';
|
import * as plugins from './smartdata.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,12 +9,13 @@ export class SmartdataDbWatcher<T = any> {
|
|||||||
public readyDeferred = plugins.smartpromise.defer();
|
public readyDeferred = plugins.smartpromise.defer();
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public changeStream: plugins.mongodb.ChangeStream<T>;
|
private changeStream: plugins.mongodb.ChangeStream<T>;
|
||||||
public changeSubject = new plugins.smartrx.rxjs.Subject<T>();
|
|
||||||
constructor(changeStreamArg: plugins.mongodb.ChangeStream<T>) {
|
public changeSubject = new plugins.smartrx.rxjs.Subject<SmartDataDbDoc<T, T>>();
|
||||||
|
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(item);
|
this.changeSubject.next(smartdataDbDocArg.createInstanceFromMongoDbNativeDoc(item));
|
||||||
})
|
})
|
||||||
plugins.smartdelay.delayFor(0).then(() => {
|
plugins.smartdelay.delayFor(0).then(() => {
|
||||||
this.readyDeferred.resolve();
|
this.readyDeferred.resolve();
|
||||||
|
Reference in New Issue
Block a user