@medyll/idae-db 0.81.0 → 0.83.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,23 +2,23 @@ import { type Filter } from 'mongodb';
2
2
  export type IdaeDbQueryFilter<T> = Filter<T>;
3
3
  export type AdapterConstructor<CON> = new <T extends object>(collection: string, connection: CON, _constructor: () => IdaeDbAdapterInterface<T>) => Omit<IdaeDbAdapterInterface<T>, 'connect' | 'getDb' | 'close' | 'registerEvents'>;
4
4
  export interface IdaeDbAdapterInterface<T extends object> {
5
- createIndex<F, O>(fieldOrSpec: F, options?: O): Promise<any>;
5
+ createIndex<F, O>(fieldOrSpec: F, options?: O): Promise<unknown>;
6
6
  create(data: Partial<T>): Promise<T>;
7
7
  findById(id: string): Promise<T[]>;
8
8
  find(params: IdaeDbParams<T>): Promise<T[]>;
9
9
  findOne(params: IdaeDbParams<T>): Promise<T | null>;
10
- update(id: string, updateData: Partial<T>): Promise<any>;
11
- updateWhere<OPT = any>(params: IdaeDbParams<T>, updateData: Partial<T>, options?: OPT): Promise<any>;
12
- deleteById(id: string): Promise<any>;
10
+ update(id: string, updateData: Partial<T>): Promise<unknown>;
11
+ updateWhere<OPT = never>(params: IdaeDbParams<T>, updateData: Partial<T>, options?: OPT): Promise<unknown>;
12
+ deleteById(id: string): Promise<unknown>;
13
13
  deleteWhere(params: IdaeDbParams<T>): Promise<{
14
14
  deletedCount?: number;
15
15
  }>;
16
- transaction<TResult>(callback: (session: any) => Promise<TResult>): Promise<TResult>;
16
+ transaction<TResult>(callback: (session: unknown) => Promise<TResult>): Promise<TResult>;
17
17
  }
18
18
  export interface IdaeDbAdapterStaticMethods {
19
- connect(uri: string): Promise<any>;
20
- getDb(client: any, dbName: string): any;
21
- close(client: any): Promise<void>;
19
+ connect(uri: string): Promise<unknown>;
20
+ getDb(client: unknown, dbName: string): unknown;
21
+ close(client: unknown): Promise<void>;
22
22
  }
23
23
  export interface IdaeDbParams<T extends object = Record<string, unknown>> {
24
24
  id?: string;
@@ -36,21 +36,21 @@ export declare enum DbType {
36
36
  CHROMADB = "chromaDb"
37
37
  }
38
38
  export declare abstract class AbstractIdaeDbAdapter<T extends object> implements IdaeDbAdapterInterface<T> {
39
- abstract createIndex(fieldOrSpec: any, options?: any): Promise<string>;
39
+ abstract createIndex(fieldOrSpec: unknown, options?: unknown): Promise<string>;
40
40
  abstract create(data: Partial<T>): Promise<T>;
41
41
  abstract findById(id: string): Promise<T[]>;
42
42
  abstract find(params: IdaeDbParams<T>): Promise<T[]>;
43
43
  abstract findOne(params: IdaeDbParams<T>): Promise<T | null>;
44
- abstract update(id: string, updateData: Partial<T>): Promise<any>;
45
- abstract updateWhere<OPT = any>(params: IdaeDbParams<T>, updateData: Partial<T>, options?: OPT): Promise<any>;
46
- abstract deleteById(id: string): Promise<any>;
44
+ abstract update(id: string, updateData: Partial<T>): Promise<unknown>;
45
+ abstract updateWhere<OPT = never>(params: IdaeDbParams<T>, updateData: Partial<T>, options?: OPT): Promise<unknown>;
46
+ abstract deleteById(id: string): Promise<unknown>;
47
47
  abstract deleteWhere(params: IdaeDbParams<T>): Promise<{
48
48
  deletedCount?: number;
49
49
  }>;
50
- abstract transaction<TResult>(callback: (session: any) => Promise<TResult>): Promise<TResult>;
51
- static connect(uri: string): Promise<any>;
52
- static getDb(client: any, dbName: string): any;
53
- static close(client: any): Promise<void>;
50
+ abstract transaction<TResult>(callback: (session: unknown) => Promise<TResult>): Promise<TResult>;
51
+ static connect(uri: string): Promise<unknown>;
52
+ static getDb(client: any, dbName: string): unknown;
53
+ static close(client: unknown): Promise<void>;
54
54
  }
55
55
  export interface IdaeDbApiMethods<T extends object> extends AbstractIdaeDbAdapter<T> {
56
56
  }
@@ -40,14 +40,14 @@ export declare class IdaeDbAdapter<T extends object> extends IdaeEventEmitter im
40
40
  * @param events An object containing event listeners for different operations.
41
41
  */
42
42
  registerEvents(events: EventListeners<T>): void;
43
- createIndex<F, O>(fieldOrSpec: F, options?: O): Promise<any>;
43
+ createIndex<F, O>(fieldOrSpec: F, options?: O): Promise<unknown>;
44
44
  create(data: Partial<T>): Promise<T>;
45
45
  findById(id: string): Promise<T[]>;
46
46
  find(params: IdaeDbParams<T>): Promise<T[]>;
47
47
  findOne(params: IdaeDbParams<T>): Promise<T | null>;
48
- update(id: string, updateData: Partial<T>): Promise<any>;
49
- updateWhere<OPT = any>(params: IdaeDbParams<T>, updateData: Partial<T>, options: OPT): Promise<any>;
50
- deleteById(id: string): Promise<any>;
48
+ update(id: string, updateData: Partial<T>): Promise<unknown>;
49
+ updateWhere<OPT = any>(params: IdaeDbParams<T>, updateData: Partial<T>, options: OPT): Promise<unknown>;
50
+ deleteById(id: string): Promise<unknown>;
51
51
  deleteWhere(params: IdaeDbParams<T>): Promise<{
52
52
  deletedCount?: number;
53
53
  }>;
@@ -23,7 +23,7 @@ export declare class IdaeDbConnection {
23
23
  * @returns The database instance.
24
24
  * @throws Error if the database is not connected.
25
25
  */
26
- getDb(): any;
26
+ getDb(): {};
27
27
  /**
28
28
  * Gets the model for a collection.
29
29
  * @param collectionName The name of the collection.
@@ -1,5 +1,5 @@
1
1
  // packages\idae-db\lib\IdaeDbConnection.ts
2
- import { DbType } from './@types/types.js';
2
+ import { DbType, IdaeDbAdapterStaticMethods } from './@types/types.js';
3
3
  import { IdaeDBModel } from './IdaeDBModel.js';
4
4
  import { IdaeDb } from './idaeDb.js';
5
5
  /**
@@ -15,7 +15,7 @@ export declare class MongoDBAdapter<T extends Document> implements AbstractIdaeD
15
15
  findOne(params: IdaeDbParams<T>): Promise<T | null>;
16
16
  create(data: Partial<T>): Promise<T>;
17
17
  update(id: string, updateData: Partial<T>, options?: UpdateOptions): Promise<import("mongodb").UpdateResult<T>>;
18
- updateWhere(params: IdaeDbParams<T>, updateData: Partial<T>, options?: any): Promise<import("mongodb").UpdateResult<T>>;
18
+ updateWhere(params: IdaeDbParams<T>, updateData: Partial<T>, options?: UpdateOptions): Promise<import("mongodb").UpdateResult<T>>;
19
19
  deleteById(id: string | number): Promise<import("mongodb").DeleteResult>;
20
20
  deleteWhere(params: IdaeDbParams<T>): Promise<{
21
21
  deletedCount?: number;
@@ -57,7 +57,7 @@ export class MongoDBAdapter {
57
57
  async create(data) {
58
58
  const id = await this.model.getNextIncrement();
59
59
  const result = await this.model.collection.findOneAndUpdate({ [this.fieldId]: id }, { $set: { ...data, [this.fieldId]: id } }, { upsert: true, returnDocument: 'after' });
60
- return result.value;
60
+ return result?.value;
61
61
  }
62
62
  async update(id, updateData, options) {
63
63
  return this.model.collection.updateMany({ [this.fieldId]: id }, { $set: { ...updateData } }, options);
@@ -1,7 +1,7 @@
1
1
  import { AbstractIdaeDbAdapter, type IdaeDbParams } from '../@types/types.js';
2
2
  import { IdaeDbConnection } from '../IdaeDbConnection.js';
3
3
  import mysql from 'mysql2/promise';
4
- export declare class MySQLAdapter<T extends Record<string, any>> implements AbstractIdaeDbAdapter<T> {
4
+ export declare class MySQLAdapter<T extends Record<string, unknown>> implements AbstractIdaeDbAdapter<T> {
5
5
  private model;
6
6
  private connection;
7
7
  private fieldId;
@@ -11,12 +11,13 @@ export declare class MySQLAdapter<T extends Record<string, any>> implements Abst
11
11
  find(params: IdaeDbParams<T>): Promise<T[]>;
12
12
  findOne(params: IdaeDbParams<T>): Promise<T | null>;
13
13
  create(data: Partial<T>): Promise<T>;
14
- update(id: string, updateData: Partial<T>, options?: any): Promise<any>;
15
- updateWhere(params: IdaeDbParams<T>, updateData: Partial<T>, options?: any): Promise<any>;
16
- deleteById(id: string | number): Promise<any>;
14
+ update(id: string, updateData: Partial<T>, options?: unknown): Promise<unknown>;
15
+ updateWhere(params: IdaeDbParams<T>, updateData: Partial<T>, options?: unknown): Promise<unknown>;
16
+ deleteById(id: string | number): Promise<unknown>;
17
17
  deleteWhere(params: IdaeDbParams<T>): Promise<{
18
18
  deletedCount?: number;
19
19
  }>;
20
20
  transaction<TResult>(callback: (session: mysql.Connection) => Promise<TResult>): Promise<TResult>;
21
+ createIndex(fieldOrSpec: string, options?: unknown): Promise<string>;
21
22
  private parseSortOptions;
22
23
  }
@@ -59,6 +59,7 @@ export class MySQLAdapter {
59
59
  const insertId = result.insertId;
60
60
  return { ...data, [this.fieldId]: insertId };
61
61
  }
62
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
62
63
  async update(id, updateData, options) {
63
64
  const setClause = Object.keys(updateData)
64
65
  .map((key) => `${key} = ?`)
@@ -69,7 +70,9 @@ export class MySQLAdapter {
69
70
  .execute(`UPDATE ${this.tableName} SET ${setClause} WHERE ${this.fieldId} = ?`, values);
70
71
  return result;
71
72
  }
72
- async updateWhere(params, updateData, options = {}) {
73
+ async updateWhere(params, updateData,
74
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
75
+ options = {}) {
73
76
  const { query = {} } = params;
74
77
  const setClause = Object.keys(updateData)
75
78
  .map((key) => `${key} = ?`)
@@ -113,6 +116,12 @@ export class MySQLAdapter {
113
116
  throw error;
114
117
  }
115
118
  }
119
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
120
+ async createIndex(fieldOrSpec, options) {
121
+ const sql = `CREATE INDEX idx_${fieldOrSpec} ON ${this.tableName} (${fieldOrSpec})`;
122
+ await this.connection.getClient().execute(sql);
123
+ return `idx_${fieldOrSpec}`;
124
+ }
116
125
  parseSortOptions(sortBy) {
117
126
  return sortBy
118
127
  .split(',')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medyll/idae-db",
3
- "version": "0.81.0",
3
+ "version": "0.83.0",
4
4
  "description": "@medyll/idae-db is a flexible and powerful library for interacting with various databases, with a particular focus on MongoDB support. It offers robust connection management, an intuitive API, and simplified CRUD operations.",
5
5
  "scripts": {
6
6
  "dev": "vite dev",