fix(build): update build and test tooling configuration, migrate project config to .smartconfig.json, and align TypeScript typings
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartdata',
|
||||
version: '7.1.0',
|
||||
version: '7.1.1',
|
||||
description: 'An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.'
|
||||
}
|
||||
|
||||
@@ -174,8 +174,8 @@ export class SmartdataCollection<T> {
|
||||
/**
|
||||
* the collection that is used
|
||||
*/
|
||||
public mongoDbCollection: plugins.mongodb.Collection;
|
||||
public objectValidation: IDocValidationFunc<T> = null;
|
||||
public mongoDbCollection!: plugins.mongodb.Collection;
|
||||
public objectValidation: IDocValidationFunc<T> | null = null;
|
||||
public collectionName: string;
|
||||
public smartdataDb: SmartdataDb;
|
||||
public uniqueIndexes: string[] = [];
|
||||
@@ -330,7 +330,7 @@ export class SmartdataCollection<T> {
|
||||
);
|
||||
const smartdataWatcher = new SmartdataDbWatcher(
|
||||
changeStream,
|
||||
smartdataDbDocArg,
|
||||
smartdataDbDocArg!,
|
||||
{ bufferTimeMs },
|
||||
);
|
||||
await smartdataWatcher.readyDeferred.promise;
|
||||
@@ -353,7 +353,7 @@ export class SmartdataCollection<T> {
|
||||
this.createRegularIndexes(dbDocArg.regularIndexes);
|
||||
}
|
||||
|
||||
const saveableObject = await dbDocArg.createSavableObject();
|
||||
const saveableObject = await dbDocArg.createSavableObject() as any;
|
||||
const result = await this.mongoDbCollection.insertOne(saveableObject, { session: opts?.session });
|
||||
return result;
|
||||
}
|
||||
@@ -368,7 +368,7 @@ export class SmartdataCollection<T> {
|
||||
await this.init();
|
||||
await this.checkDoc(dbDocArg);
|
||||
const identifiableObject = await dbDocArg.createIdentifiableObject();
|
||||
const saveableObject = await dbDocArg.createSavableObject();
|
||||
const saveableObject = await dbDocArg.createSavableObject() as any;
|
||||
const updateableObject: any = {};
|
||||
for (const key of Object.keys(saveableObject)) {
|
||||
if (identifiableObject[key]) {
|
||||
|
||||
@@ -12,8 +12,8 @@ export type TConnectionStatus = 'initial' | 'disconnected' | 'connected' | 'fail
|
||||
|
||||
export class SmartdataDb {
|
||||
smartdataOptions: plugins.tsclass.database.IMongoDescriptor;
|
||||
mongoDbClient: plugins.mongodb.MongoClient;
|
||||
mongoDb: plugins.mongodb.Db;
|
||||
mongoDbClient!: plugins.mongodb.MongoClient;
|
||||
mongoDb!: plugins.mongodb.Db;
|
||||
status: TConnectionStatus;
|
||||
statusConnectedDeferred = plugins.smartpromise.defer();
|
||||
smartdataCollectionMap = new plugins.lik.ObjectMap<SmartdataCollection<any>>();
|
||||
@@ -51,8 +51,8 @@ export class SmartdataDb {
|
||||
.replace('<user>', encodedUser)
|
||||
.replace('<PASSWORD>', encodedPass)
|
||||
.replace('<password>', encodedPass)
|
||||
.replace('<DBNAME>', this.smartdataOptions.mongoDbName)
|
||||
.replace('<dbname>', this.smartdataOptions.mongoDbName);
|
||||
.replace('<DBNAME>', this.smartdataOptions.mongoDbName || '')
|
||||
.replace('<dbname>', this.smartdataOptions.mongoDbName || '');
|
||||
|
||||
const clientOptions: plugins.mongodb.MongoClientOptions = {
|
||||
maxPoolSize: (this.smartdataOptions as any).maxPoolSize ?? 100,
|
||||
@@ -70,7 +70,7 @@ export class SmartdataDb {
|
||||
} catch (error) {
|
||||
this.status = 'disconnected';
|
||||
this.statusConnectedDeferred.reject(error);
|
||||
logger.log('error', `Failed to connect to database ${this.smartdataOptions.mongoDbName}: ${error.message}`);
|
||||
logger.log('error', `Failed to connect to database ${this.smartdataOptions.mongoDbName}: ${(error as Error).message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ import { logger } from './logging.js';
|
||||
export class DistributedClass extends SmartDataDbDoc<DistributedClass, DistributedClass> {
|
||||
// INSTANCE
|
||||
@unI()
|
||||
public id: string;
|
||||
public id!: string;
|
||||
|
||||
@svDb()
|
||||
public data: {
|
||||
public data!: {
|
||||
status: 'initializing' | 'bidding' | 'settled' | 'stopped';
|
||||
biddingShortcode?: string;
|
||||
biddingStartTime?: number;
|
||||
@@ -40,8 +40,8 @@ export class SmartdataDistributedCoordinator extends plugins.taskbuffer.distribu
|
||||
public readyPromise: Promise<any>;
|
||||
public db: SmartdataDb;
|
||||
private asyncExecutionStack = new plugins.lik.AsyncExecutionStack();
|
||||
public ownInstance: DistributedClass;
|
||||
public distributedWatcher: SmartdataDbWatcher<DistributedClass>;
|
||||
public ownInstance!: DistributedClass;
|
||||
public distributedWatcher!: SmartdataDbWatcher<DistributedClass>;
|
||||
|
||||
constructor(dbArg: SmartdataDb) {
|
||||
super();
|
||||
@@ -163,8 +163,8 @@ export class SmartdataDistributedCoordinator extends plugins.taskbuffer.distribu
|
||||
} else if (
|
||||
(await DistributedClass.getInstances({})).find((instanceArg) => {
|
||||
return instanceArg.data.status === 'bidding' &&
|
||||
instanceArg.data.biddingStartTime <= Date.now() - 4000 &&
|
||||
instanceArg.data.biddingStartTime >= Date.now() - 30000;
|
||||
instanceArg.data.biddingStartTime! <= Date.now() - 4000 &&
|
||||
instanceArg.data.biddingStartTime! >= Date.now() - 30000;
|
||||
})
|
||||
) {
|
||||
logger.log('info', 'too late to the bidding party... waiting for next round.');
|
||||
@@ -191,7 +191,7 @@ export class SmartdataDistributedCoordinator extends plugins.taskbuffer.distribu
|
||||
logger.log('info', `found ${biddingInstances.length} bidding instances...`);
|
||||
this.ownInstance.data.elected = true;
|
||||
for (const biddingInstance of biddingInstances) {
|
||||
if (biddingInstance.data.biddingShortcode < this.ownInstance.data.biddingShortcode) {
|
||||
if (biddingInstance.data.biddingShortcode! < this.ownInstance.data.biddingShortcode!) {
|
||||
this.ownInstance.data.elected = false;
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ export class SmartdataDistributedCoordinator extends plugins.taskbuffer.distribu
|
||||
});
|
||||
if (!result) {
|
||||
logger.log('warn', 'no result found for task request...');
|
||||
return null;
|
||||
return null as any;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
||||
convertFilterForMongoDb(filterArg),
|
||||
{ session: opts?.session },
|
||||
);
|
||||
const returnArray = [];
|
||||
const returnArray: T[] = [];
|
||||
for (const foundDoc of foundDocs) {
|
||||
const newInstance: T = (this as any).createInstanceFromMongoDbNativeDoc(foundDoc);
|
||||
returnArray.push(newInstance);
|
||||
@@ -510,7 +510,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
||||
const newInstance: T = (this as any).createInstanceFromMongoDbNativeDoc(foundDoc);
|
||||
return newInstance;
|
||||
} else {
|
||||
return null;
|
||||
return null as any;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -833,12 +833,12 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
||||
/**
|
||||
* name
|
||||
*/
|
||||
public name: string;
|
||||
public name!: string;
|
||||
|
||||
/**
|
||||
* primary id in the database
|
||||
*/
|
||||
public dbDocUniqueId: string;
|
||||
public dbDocUniqueId!: string;
|
||||
|
||||
/**
|
||||
* class constructor
|
||||
@@ -898,7 +898,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
||||
* also store any referenced objects to DB
|
||||
* better for data consistency
|
||||
*/
|
||||
public saveDeep(savedMapArg: plugins.lik.ObjectMap<SmartDataDbDoc<any, any>> = null) {
|
||||
public saveDeep(savedMapArg?: plugins.lik.ObjectMap<SmartDataDbDoc<any, any>>) {
|
||||
if (!savedMapArg) {
|
||||
savedMapArg = new plugins.lik.ObjectMap<SmartDataDbDoc<any, any>>();
|
||||
}
|
||||
|
||||
@@ -15,19 +15,19 @@ export class EasyStore<T> {
|
||||
@Collection(() => this.smartdataDbRef)
|
||||
class SmartdataEasyStore extends SmartDataDbDoc<SmartdataEasyStore, SmartdataEasyStore> {
|
||||
@unI()
|
||||
public nameId: string;
|
||||
public nameId!: string;
|
||||
|
||||
@svDb()
|
||||
public ephemeral: {
|
||||
public ephemeral!: {
|
||||
activated: boolean;
|
||||
timeout: number;
|
||||
};
|
||||
|
||||
@svDb()
|
||||
lastEdit: number;
|
||||
lastEdit!: number;
|
||||
|
||||
@svDb()
|
||||
public data: Partial<T>;
|
||||
public data!: Partial<T>;
|
||||
}
|
||||
return SmartdataEasyStore;
|
||||
})();
|
||||
@@ -37,7 +37,7 @@ export class EasyStore<T> {
|
||||
this.nameId = nameIdArg;
|
||||
}
|
||||
|
||||
private easyStorePromise: Promise<InstanceType<typeof this.easyStoreClass>>;
|
||||
private easyStorePromise!: Promise<InstanceType<typeof this.easyStoreClass>>;
|
||||
private async getEasyStore(): Promise<InstanceType<typeof this.easyStoreClass>> {
|
||||
if (this.easyStorePromise) {
|
||||
return this.easyStorePromise;
|
||||
|
||||
@@ -536,7 +536,7 @@ export class LuceneToMongoTransformer {
|
||||
const searchTerm = rightQuery.$text.$search.replace(/"/g, '');
|
||||
|
||||
// Determine the fields to apply the negation to
|
||||
const notConditions = [];
|
||||
const notConditions: any[] = [];
|
||||
|
||||
for (const field in leftQuery) {
|
||||
if (field !== '$or' && field !== '$and') {
|
||||
|
||||
@@ -13,7 +13,7 @@ export class SmartdataDbWatcher<T = any> extends EventEmitter {
|
||||
public readyDeferred = plugins.smartpromise.defer();
|
||||
|
||||
// INSTANCE
|
||||
private changeStream: plugins.mongodb.ChangeStream<T>;
|
||||
private changeStream: plugins.mongodb.ChangeStream<any>;
|
||||
private rawSubject: plugins.smartrx.rxjs.Subject<T>;
|
||||
/** Emits change documents (or arrays of documents if buffered) */
|
||||
public changeSubject: any;
|
||||
@@ -23,7 +23,7 @@ export class SmartdataDbWatcher<T = any> extends EventEmitter {
|
||||
* @param opts.bufferTimeMs optional milliseconds to buffer events via RxJS
|
||||
*/
|
||||
constructor(
|
||||
changeStreamArg: plugins.mongodb.ChangeStream<T>,
|
||||
changeStreamArg: plugins.mongodb.ChangeStream<any>,
|
||||
smartdataDbDocArg: typeof SmartDataDbDoc,
|
||||
opts?: { bufferTimeMs?: number },
|
||||
) {
|
||||
@@ -37,14 +37,14 @@ export class SmartdataDbWatcher<T = any> extends EventEmitter {
|
||||
}
|
||||
this.changeStream = changeStreamArg;
|
||||
this.changeStream.on('change', async (item: any) => {
|
||||
let docInstance: T = null;
|
||||
let docInstance: T | null = null;
|
||||
if (item.fullDocument) {
|
||||
docInstance = smartdataDbDocArg.createInstanceFromMongoDbNativeDoc(
|
||||
item.fullDocument
|
||||
) as any as T;
|
||||
}
|
||||
// Notify subscribers
|
||||
this.rawSubject.next(docInstance);
|
||||
this.rawSubject.next(docInstance as T);
|
||||
this.emit('change', docInstance);
|
||||
});
|
||||
// Signal readiness after one tick
|
||||
|
||||
Reference in New Issue
Block a user