fix(ci & formatting): Minor fixes: update CI workflow image and npmci package references, adjust package.json and readme URLs, and apply consistent code formatting.

This commit is contained in:
2025-04-06 18:18:39 +00:00
parent 4fac974fc9
commit 9426a21a2a
19 changed files with 437 additions and 354 deletions

View File

@@ -40,13 +40,13 @@ export function svDb() {
export function searchable() {
return (target: SmartDataDbDoc<unknown, unknown>, key: string) => {
console.log(`called searchable() on >${target.constructor.name}.${key}<`);
// Initialize the set for this class if it doesn't exist
const className = target.constructor.name;
if (!searchableFieldsMap.has(className)) {
searchableFieldsMap.set(className, new Set<string>());
}
// Add the property to the searchable fields set
searchableFieldsMap.get(className).add(key);
};
@@ -135,7 +135,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
// STATIC
public static createInstanceFromMongoDbNativeDoc<T>(
this: plugins.tsclass.typeFest.Class<T>,
mongoDbNativeDocArg: any
mongoDbNativeDocArg: any,
): T {
const newInstance = new this();
(newInstance as any).creationStatus = 'db';
@@ -153,7 +153,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
public static async getInstances<T>(
this: plugins.tsclass.typeFest.Class<T>,
filterArg: plugins.tsclass.typeFest.PartialDeep<T>
filterArg: plugins.tsclass.typeFest.PartialDeep<T>,
): Promise<T[]> {
const foundDocs = await (this as any).collection.findAll(convertFilterForMongoDb(filterArg));
const returnArray = [];
@@ -172,7 +172,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
public static async getInstance<T>(
this: plugins.tsclass.typeFest.Class<T>,
filterArg: plugins.tsclass.typeFest.PartialDeep<T>
filterArg: plugins.tsclass.typeFest.PartialDeep<T>,
): Promise<T> {
const foundDoc = await (this as any).collection.findOne(convertFilterForMongoDb(filterArg));
if (foundDoc) {
@@ -186,7 +186,10 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
/**
* get a unique id prefixed with the class name
*/
public static async getNewId<T = any>(this: plugins.tsclass.typeFest.Class<T>, lengthArg: number = 20) {
public static async getNewId<T = any>(
this: plugins.tsclass.typeFest.Class<T>,
lengthArg: number = 20,
) {
return `${(this as any).className}:${plugins.smartunique.shortId(lengthArg)}`;
}
@@ -196,12 +199,12 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
public static async getCursor<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 cursor: SmartdataDbCursor<T> = await collection.getCursor(
convertFilterForMongoDb(filterArg),
this as any as typeof SmartDataDbDoc
this as any as typeof SmartDataDbDoc,
);
return cursor;
}
@@ -214,12 +217,12 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
public static async watch<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 watcher: SmartdataDbWatcher<T> = await collection.watch(
convertFilterForMongoDb(filterArg),
this as any
this as any,
);
return watcher;
}
@@ -231,7 +234,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
public static async forEach<T>(
this: plugins.tsclass.typeFest.Class<T>,
filterArg: plugins.tsclass.typeFest.PartialDeep<T>,
forEachFunction: (itemArg: T) => Promise<any>
forEachFunction: (itemArg: T) => Promise<any>,
) {
const cursor: SmartdataDbCursor<T> = await (this as any).getCursor(filterArg);
await cursor.forEach(forEachFunction);
@@ -242,7 +245,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
public static async getCount<T>(
this: plugins.tsclass.typeFest.Class<T>,
filterArg: plugins.tsclass.typeFest.PartialDeep<T> = ({} as any)
filterArg: plugins.tsclass.typeFest.PartialDeep<T> = {} as any,
) {
const collection: SmartdataCollection<T> = (this as any).collection;
return await collection.getCount(filterArg);
@@ -255,15 +258,15 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
public static createSearchFilter<T>(
this: plugins.tsclass.typeFest.Class<T>,
luceneQuery: string
luceneQuery: string,
): any {
const className = (this as any).className || this.name;
const searchableFields = getSearchableFields(className);
if (searchableFields.length === 0) {
throw new Error(`No searchable fields defined for class ${className}`);
}
const adapter = new SmartdataLuceneAdapter(searchableFields);
return adapter.convert(luceneQuery);
}
@@ -275,7 +278,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
public static async search<T>(
this: plugins.tsclass.typeFest.Class<T>,
luceneQuery: string
luceneQuery: string,
): Promise<T[]> {
const filter = (this as any).createSearchFilter(luceneQuery);
return await (this as any).getInstances(filter);
@@ -288,25 +291,29 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
public static async searchWithLucene<T>(
this: plugins.tsclass.typeFest.Class<T>,
luceneQuery: string
luceneQuery: string,
): Promise<T[]> {
try {
const className = (this as any).className || this.name;
const searchableFields = getSearchableFields(className);
if (searchableFields.length === 0) {
console.warn(`No searchable fields defined for class ${className}, falling back to simple search`);
console.warn(
`No searchable fields defined for class ${className}, falling back to simple search`,
);
return (this as any).searchByTextAcrossFields(luceneQuery);
}
// Simple term search optimization
if (!luceneQuery.includes(':') &&
!luceneQuery.includes(' AND ') &&
!luceneQuery.includes(' OR ') &&
!luceneQuery.includes(' NOT ')) {
if (
!luceneQuery.includes(':') &&
!luceneQuery.includes(' AND ') &&
!luceneQuery.includes(' OR ') &&
!luceneQuery.includes(' NOT ')
) {
return (this as any).searchByTextAcrossFields(luceneQuery);
}
// Try to use the Lucene-to-MongoDB conversion
const filter = (this as any).createSearchFilter(luceneQuery);
return await (this as any).getInstances(filter);
@@ -323,21 +330,21 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
private static async searchByTextAcrossFields<T>(
this: plugins.tsclass.typeFest.Class<T>,
searchText: string
searchText: string,
): Promise<T[]> {
try {
const className = (this as any).className || this.name;
const searchableFields = getSearchableFields(className);
// Fallback to direct filter if we have searchable fields
if (searchableFields.length > 0) {
// Create a simple $or query with regex for each field
const orConditions = searchableFields.map(field => ({
[field]: { $regex: searchText, $options: 'i' }
const orConditions = searchableFields.map((field) => ({
[field]: { $regex: searchText, $options: 'i' },
}));
const filter = { $or: orConditions };
try {
// Try with MongoDB filter first
return await (this as any).getInstances(filter);
@@ -345,16 +352,15 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
console.warn('MongoDB filter failed, falling back to in-memory search');
}
}
// Last resort: get all and filter in memory
const allDocs = await (this as any).getInstances({});
const lowerSearchText = searchText.toLowerCase();
return allDocs.filter((doc: any) => {
for (const field of searchableFields) {
const value = doc[field];
if (value && typeof value === 'string' &&
value.toLowerCase().includes(lowerSearchText)) {
if (value && typeof value === 'string' && value.toLowerCase().includes(lowerSearchText)) {
return true;
}
}
@@ -377,13 +383,13 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
* updated from db in any case where doc comes from db
*/
@globalSvDb()
_createdAt: string = (new Date()).toISOString();
_createdAt: string = new Date().toISOString();
/**
* will be updated everytime the doc is saved
*/
@globalSvDb()
_updatedAt: string = (new Date()).toISOString();
_updatedAt: string = new Date().toISOString();
/**
* an array of saveable properties of ALL doc
@@ -424,7 +430,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
const self: any = this;
let dbResult: any;
this._updatedAt = (new Date()).toISOString();
this._updatedAt = new Date().toISOString();
switch (this.creationStatus) {
case 'db':
@@ -480,10 +486,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
public async createSavableObject(): Promise<TImplements> {
const saveableObject: unknown = {}; // is not exposed to outside, so any is ok here
const saveableProperties = [
...this.globalSaveableProperties,
...this.saveableProperties
]
const saveableProperties = [...this.globalSaveableProperties, ...this.saveableProperties];
for (const propertyNameString of saveableProperties) {
saveableObject[propertyNameString] = this[propertyNameString];
}
@@ -500,4 +503,4 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
}
return identifiableObject;
}
}
}