fix(core): update

This commit is contained in:
Philipp Kunz 2022-11-01 18:23:57 +01:00
parent 64005a0b32
commit 3f28ff80cb
13 changed files with 5422 additions and 15248 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"
} }

15189
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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",
@ -59,4 +60,4 @@
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
] ]
} }

5348
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff

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.8', version: '5.0.9',
description: 'do more with data' description: 'do more with data'
} }

View File

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

View File

@ -179,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);
@ -199,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

@ -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

@ -12,11 +12,16 @@ export class SmartdataDbWatcher<T = any> {
private changeStream: plugins.mongodb.ChangeStream<T>; private changeStream: plugins.mongodb.ChangeStream<T>;
public changeSubject = new plugins.smartrx.rxjs.Subject<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) as any as T); 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,
};