@wxn0brp/db-core 0.1.3 → 0.1.5

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.
@@ -1,13 +1,13 @@
1
- import { UniversalEventEmitter } from "../helpers/eventEmiter.js";
1
+ import { VEE } from "@wxn0brp/event-emitter";
2
2
  import ActionsBase from "../base/actions.js";
3
3
  import CollectionManager from "../helpers/CollectionManager.js";
4
4
  import executorC from "../helpers/executor.js";
5
5
  import { Arg, Search, Updater } from "../types/arg.js";
6
6
  import Data from "../types/data.js";
7
- import { DbOpts, DbFindOpts, FindOpts } from "../types/options.js";
7
+ import { DbFindOpts, DbOpts, FindOpts } from "../types/options.js";
8
+ import { VQuery } from "../types/query.js";
8
9
  import { VContext } from "../types/types.js";
9
10
  import { ValtheraCompatible } from "../types/valthera.js";
10
- import { VQuery } from "../types/query.js";
11
11
  type DbActionsFns = keyof {
12
12
  [K in keyof ActionsBase as ActionsBase[K] extends (...args: any[]) => any ? K : never]: any;
13
13
  };
@@ -18,7 +18,7 @@ type DbActionsFns = keyof {
18
18
  declare class ValtheraClass implements ValtheraCompatible {
19
19
  dbAction: ActionsBase;
20
20
  executor: executorC;
21
- emiter: UniversalEventEmitter;
21
+ emiter: VEE;
22
22
  version: string;
23
23
  constructor(options?: DbOpts);
24
24
  init(...args: any[]): Promise<unknown>;
@@ -42,7 +42,10 @@ declare class ValtheraClass implements ValtheraCompatible {
42
42
  /**
43
43
  * Add data to a database.
44
44
  */
45
- add<T = Data>(collection: string, data: Arg<T>, id_gen?: boolean): Promise<T>;
45
+ add<T extends object>(collection: string, data: T, id_gen?: true): Promise<T & {
46
+ _id: string;
47
+ }>;
48
+ add<T extends object>(collection: string, data: T, id_gen: false): Promise<T>;
46
49
  /**
47
50
  * Find data in a database.
48
51
  */
@@ -1,8 +1,8 @@
1
- import { version } from "../version.js";
2
- import { UniversalEventEmitter } from "../helpers/eventEmiter.js";
1
+ import { VEE } from "@wxn0brp/event-emitter";
3
2
  import ActionsBase from "../base/actions.js";
4
3
  import CollectionManager from "../helpers/CollectionManager.js";
5
4
  import executorC from "../helpers/executor.js";
5
+ import { version } from "../version.js";
6
6
  /**
7
7
  * Represents a database management class for performing CRUD operations.
8
8
  * @class
@@ -15,7 +15,7 @@ class ValtheraClass {
15
15
  constructor(options = {}) {
16
16
  this.dbAction = options.dbAction || new ActionsBase();
17
17
  this.executor = options.executor || new executorC();
18
- this.emiter = new UniversalEventEmitter();
18
+ this.emiter = new VEE();
19
19
  }
20
20
  async init(...args) {
21
21
  if (this.dbAction._inited)
@@ -60,9 +60,6 @@ class ValtheraClass {
60
60
  async issetCollection(collection) {
61
61
  return await this.execute("issetCollection", { collection });
62
62
  }
63
- /**
64
- * Add data to a database.
65
- */
66
63
  async add(collection, data, id_gen = true) {
67
64
  return await this.execute("add", { collection, data, id_gen });
68
65
  }
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.1.3";
1
+ export const version = "0.1.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",
@@ -13,9 +13,9 @@
13
13
  },
14
14
  "homepage": "https://github.com/wxn0brP/ValtheraDB",
15
15
  "devDependencies": {
16
- "@types/node": "^22.12.0",
16
+ "@types/node": "^24.2.0",
17
17
  "tsc-alias": "^1.8.10",
18
- "typescript": "^5.7.3"
18
+ "typescript": "^5.9.2"
19
19
  },
20
20
  "files": [
21
21
  "dist"
@@ -31,5 +31,8 @@
31
31
  "import": "./dist/*.js",
32
32
  "default": "./dist/*.js"
33
33
  }
34
+ },
35
+ "dependencies": {
36
+ "@wxn0brp/event-emitter": "^0.0.2"
34
37
  }
35
38
  }
@@ -1,31 +0,0 @@
1
- export declare class UniversalEventEmitter {
2
- private _events;
3
- /**
4
- * Registers an event listener
5
- * @param {string} event - event name
6
- * @param {Function} listener - function to be called when event occurs
7
- */
8
- on(event: string, listener: Function): void;
9
- /**
10
- * Registers a one-time event listener
11
- * @param {string} event - event name
12
- * @param {Function} listener - function to be called once
13
- */
14
- once(event: string, listener: Function): void;
15
- /**
16
- * Removes an event listener
17
- * @param {string} event - event name
18
- * @param {Function} [listener] - optional: specific listener to remove
19
- */
20
- off(event?: string, listener?: Function): void;
21
- /**
22
- * Emits an event
23
- * @param {string} event - event name
24
- * @param {...any} args - arguments to be passed to listeners
25
- */
26
- emit(event: string, ...args: any[]): void;
27
- /**
28
- * Returns the number of listeners for the given event
29
- */
30
- listenerCount(event: string): number;
31
- }
@@ -1,65 +0,0 @@
1
- export class UniversalEventEmitter {
2
- _events = {};
3
- /**
4
- * Registers an event listener
5
- * @param {string} event - event name
6
- * @param {Function} listener - function to be called when event occurs
7
- */
8
- on(event, listener) {
9
- if (!this._events[event])
10
- this._events[event] = [];
11
- this._events[event].push(listener);
12
- }
13
- /**
14
- * Registers a one-time event listener
15
- * @param {string} event - event name
16
- * @param {Function} listener - function to be called once
17
- */
18
- once(event, listener) {
19
- const onceListener = (...args) => {
20
- this.off(event, onceListener);
21
- listener(...args);
22
- };
23
- this.on(event, onceListener);
24
- }
25
- /**
26
- * Removes an event listener
27
- * @param {string} event - event name
28
- * @param {Function} [listener] - optional: specific listener to remove
29
- */
30
- off(event, listener) {
31
- if (!event) {
32
- // Remove all events
33
- this._events = {};
34
- return;
35
- }
36
- if (!listener) {
37
- // Remove all listeners for the given event
38
- delete this._events[event];
39
- return;
40
- }
41
- // Remove specific listener
42
- if (this._events[event]) {
43
- this._events[event] = this._events[event].filter(l => l !== listener);
44
- }
45
- }
46
- /**
47
- * Emits an event
48
- * @param {string} event - event name
49
- * @param {...any} args - arguments to be passed to listeners
50
- */
51
- emit(event, ...args) {
52
- const listeners = this._events[event];
53
- if (listeners && listeners.length > 0) {
54
- listeners.forEach(listener => {
55
- listener(...args);
56
- });
57
- }
58
- }
59
- /**
60
- * Returns the number of listeners for the given event
61
- */
62
- listenerCount(event) {
63
- return this._events[event]?.length || 0;
64
- }
65
- }