@wxn0brp/db-core 0.0.7 → 0.1.1

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,8 +1,10 @@
1
1
  import Data from "../types/data.js";
2
2
  import { VQuery } from "../types/query.js";
3
- declare class dbActionBase {
3
+ declare class ActionsBase {
4
+ _inited: boolean;
5
+ init(...args: any[]): Promise<void>;
4
6
  getCollections(): Promise<string[]>;
5
- checkCollection(config: VQuery): Promise<boolean>;
7
+ ensureCollection(config: VQuery): Promise<boolean>;
6
8
  issetCollection(config: VQuery): Promise<boolean>;
7
9
  add(config: VQuery): Promise<Data>;
8
10
  find(config: VQuery): Promise<Data[]>;
@@ -14,4 +16,4 @@ declare class dbActionBase {
14
16
  removeCollection(config: VQuery): Promise<boolean>;
15
17
  updateOneOrAdd(config: VQuery): Promise<boolean>;
16
18
  }
17
- export default dbActionBase;
19
+ export default ActionsBase;
@@ -1,10 +1,12 @@
1
1
  import { setDataUsingUpdateOneOrAdd } from "../helpers/updateOneOrAdd.js";
2
- class dbActionBase {
2
+ class ActionsBase {
3
+ _inited = true;
4
+ async init(...args) { }
3
5
  async getCollections() {
4
6
  throw new Error("Not implemented");
5
7
  return [];
6
8
  }
7
- async checkCollection(config) {
9
+ async ensureCollection(config) {
8
10
  throw new Error("Not implemented");
9
11
  return false;
10
12
  }
@@ -53,4 +55,4 @@ class dbActionBase {
53
55
  return res;
54
56
  }
55
57
  }
56
- export default dbActionBase;
58
+ export default ActionsBase;
@@ -0,0 +1,36 @@
1
+ import CustomFileCpu from "../customFileCpu.js";
2
+ import Data from "../types/data.js";
3
+ import { VQuery } from "../types/query.js";
4
+ import ActionsBase from "./actions.js";
5
+ export declare class CustomActionsBase extends ActionsBase {
6
+ fileCpu: CustomFileCpu;
7
+ constructor();
8
+ /**
9
+ * Add a new entry to the specified database.
10
+ */
11
+ add({ collection, data, id_gen }: VQuery): Promise<import("../types/arg.js").Arg>;
12
+ /**
13
+ * Find entries in the specified database based on search criteria.
14
+ */
15
+ find(query: VQuery): Promise<Data[]>;
16
+ /**
17
+ * Find the first matching entry in the specified database based on search criteria.
18
+ */
19
+ findOne({ collection, search, context, findOpts }: VQuery): Promise<Data>;
20
+ /**
21
+ * Update entries in the specified database based on search criteria and an updater function or object.
22
+ */
23
+ update({ collection, search, updater, context }: VQuery): Promise<boolean>;
24
+ /**
25
+ * Update the first matching entry in the specified database based on search criteria and an updater function or object.
26
+ */
27
+ updateOne({ collection, search, updater, context }: VQuery): Promise<boolean>;
28
+ /**
29
+ * Remove entries from the specified database based on search criteria.
30
+ */
31
+ remove({ collection, search, context }: VQuery): Promise<boolean>;
32
+ /**
33
+ * Remove the first matching entry from the specified database based on search criteria.
34
+ */
35
+ removeOne({ collection, search, context }: VQuery): Promise<boolean>;
36
+ }
@@ -0,0 +1,63 @@
1
+ import genId from "../helpers/gen.js";
2
+ import { findUtil } from "../utils/action.js";
3
+ import ActionsBase from "./actions.js";
4
+ export class CustomActionsBase extends ActionsBase {
5
+ fileCpu;
6
+ constructor() {
7
+ super();
8
+ }
9
+ /**
10
+ * Add a new entry to the specified database.
11
+ */
12
+ async add({ collection, data, id_gen = true }) {
13
+ await this.ensureCollection(arguments[0]);
14
+ if (id_gen)
15
+ data._id = data._id || genId();
16
+ await this.fileCpu.add(collection, data);
17
+ return data;
18
+ }
19
+ /**
20
+ * Find entries in the specified database based on search criteria.
21
+ */
22
+ async find(query) {
23
+ await this.ensureCollection(query);
24
+ const data = await findUtil(query, this.fileCpu, [query.collection]);
25
+ return data;
26
+ }
27
+ /**
28
+ * Find the first matching entry in the specified database based on search criteria.
29
+ */
30
+ async findOne({ collection, search, context = {}, findOpts = {} }) {
31
+ await this.ensureCollection(arguments[0]);
32
+ let data = await this.fileCpu.findOne(collection, search, context, findOpts);
33
+ return data || null;
34
+ }
35
+ /**
36
+ * Update entries in the specified database based on search criteria and an updater function or object.
37
+ */
38
+ async update({ collection, search, updater, context = {} }) {
39
+ await this.ensureCollection(arguments[0]);
40
+ return await this.fileCpu.update(collection, false, search, updater, context);
41
+ }
42
+ /**
43
+ * Update the first matching entry in the specified database based on search criteria and an updater function or object.
44
+ */
45
+ async updateOne({ collection, search, updater, context = {} }) {
46
+ await this.ensureCollection(arguments[0]);
47
+ return await this.fileCpu.update(collection, true, search, updater, context);
48
+ }
49
+ /**
50
+ * Remove entries from the specified database based on search criteria.
51
+ */
52
+ async remove({ collection, search, context = {} }) {
53
+ await this.ensureCollection(arguments[0]);
54
+ return await this.fileCpu.remove(collection, false, search, context);
55
+ }
56
+ /**
57
+ * Remove the first matching entry from the specified database based on search criteria.
58
+ */
59
+ async removeOne({ collection, search, context = {} }) {
60
+ await this.ensureCollection(arguments[0]);
61
+ return await this.fileCpu.remove(collection, true, search, context);
62
+ }
63
+ }
@@ -1,70 +1,21 @@
1
- import ValtheraClass from "./valthera.js";
2
- import dbActionBase from "../base/actions.js";
1
+ import { CustomActionsBase } from "../base/custom.js";
2
+ import CollectionManager from "../helpers/CollectionManager.js";
3
3
  import Data from "../types/data.js";
4
- import FileCpu from "../types/fileCpu.js";
5
- import { DbOpts } from "../types/options.js";
6
4
  import { VQuery } from "../types/query.js";
7
- export declare class MemoryAction extends dbActionBase {
8
- folder: string;
9
- options: DbOpts;
10
- fileCpu: FileCpu;
5
+ import ValtheraClass from "./valthera.js";
6
+ export declare class MemoryAction extends CustomActionsBase {
11
7
  memory: Map<string, any[]>;
12
- /**
13
- * Creates a new instance of dbActionC.
14
- * @constructor
15
- * @param folder - The folder where database files are stored.
16
- * @param options - The options object.
17
- */
18
8
  constructor();
19
9
  _readMemory(key: string): any[];
20
10
  _writeMemory(key: string, data: any[]): void;
21
- _getCollectionPath(collection: string): string;
22
- /**
23
- * Get a list of available databases in the specified folder.
24
- */
25
11
  getCollections(): Promise<string[]>;
26
- /**
27
- * Check and create the specified collection if it doesn't exist.
28
- */
29
- checkCollection({ collection }: VQuery): Promise<boolean>;
30
- /**
31
- * Check if a collection exists.
32
- */
12
+ ensureCollection({ collection }: VQuery): Promise<boolean>;
33
13
  issetCollection({ collection }: VQuery): Promise<boolean>;
34
- /**
35
- * Add a new entry to the specified database.
36
- */
37
- add({ collection, data, id_gen }: VQuery): Promise<import("../types/arg.js").Arg>;
38
- /**
39
- * Find entries in the specified database based on search criteria.
40
- */
41
- find(query: VQuery): Promise<Data[]>;
42
- /**
43
- * Find the first matching entry in the specified database based on search criteria.
44
- */
45
- findOne({ collection, search, context, findOpts }: VQuery): Promise<Data>;
46
- /**
47
- * Update entries in the specified database based on search criteria and an updater function or object.
48
- */
49
- update({ collection, search, updater, context }: VQuery): Promise<boolean>;
50
- /**
51
- * Update the first matching entry in the specified database based on search criteria and an updater function or object.
52
- */
53
- updateOne({ collection, search, updater, context }: VQuery): Promise<boolean>;
54
- /**
55
- * Remove entries from the specified database based on search criteria.
56
- */
57
- remove({ collection, search, context }: VQuery): Promise<boolean>;
58
- /**
59
- * Remove the first matching entry from the specified database based on search criteria.
60
- */
61
- removeOne({ collection, search, context }: VQuery): Promise<boolean>;
62
- /**
63
- * Removes a database collection from the file system.
64
- */
65
14
  removeCollection({ collection }: VQuery): Promise<boolean>;
66
15
  }
67
16
  export default class ValtheraMemory extends ValtheraClass {
68
17
  constructor(...args: any[]);
69
18
  }
70
- export declare function createMemoryValthera<T extends Record<string, Data[]>>(data?: T): ValtheraMemory;
19
+ export declare function createMemoryValthera<T extends Record<string, Data[]>>(data?: T): ValtheraMemory & {
20
+ [K in keyof T]: CollectionManager<T[K][number]>;
21
+ };
package/dist/db/memory.js CHANGED
@@ -1,23 +1,13 @@
1
- import ValtheraClass from "./valthera.js";
1
+ import { CustomActionsBase } from "../base/custom.js";
2
2
  import CustomFileCpu from "../customFileCpu.js";
3
- import genId from "../helpers/gen.js";
4
- import dbActionBase from "../base/actions.js";
5
- import { findUtil } from "../utils/action.js";
6
- export class MemoryAction extends dbActionBase {
7
- folder;
8
- options;
9
- fileCpu;
3
+ import { forgeValthera } from "../utils/forge.js";
4
+ import ValtheraClass from "./valthera.js";
5
+ export class MemoryAction extends CustomActionsBase {
10
6
  memory;
11
- /**
12
- * Creates a new instance of dbActionC.
13
- * @constructor
14
- * @param folder - The folder where database files are stored.
15
- * @param options - The options object.
16
- */
17
7
  constructor() {
18
8
  super();
19
- this.memory = new Map();
20
9
  this.fileCpu = new CustomFileCpu(this._readMemory.bind(this), this._writeMemory.bind(this));
10
+ this.memory = new Map();
21
11
  }
22
12
  _readMemory(key) {
23
13
  if (!this.memory.has(key))
@@ -27,88 +17,19 @@ export class MemoryAction extends dbActionBase {
27
17
  _writeMemory(key, data) {
28
18
  this.memory.set(key, data);
29
19
  }
30
- _getCollectionPath(collection) {
31
- return this.folder + "/" + collection + "/";
32
- }
33
- /**
34
- * Get a list of available databases in the specified folder.
35
- */
36
20
  async getCollections() {
37
21
  const collections = Array.from(this.memory.keys());
38
22
  return collections;
39
23
  }
40
- /**
41
- * Check and create the specified collection if it doesn't exist.
42
- */
43
- async checkCollection({ collection }) {
24
+ async ensureCollection({ collection }) {
44
25
  if (this.issetCollection(collection))
45
26
  return;
46
27
  this.memory.set(collection, []);
47
28
  return true;
48
29
  }
49
- /**
50
- * Check if a collection exists.
51
- */
52
30
  async issetCollection({ collection }) {
53
31
  return this.memory.has(collection);
54
32
  }
55
- /**
56
- * Add a new entry to the specified database.
57
- */
58
- async add({ collection, data, id_gen = true }) {
59
- await this.checkCollection(arguments[0]);
60
- if (id_gen)
61
- data._id = data._id || genId();
62
- await this.fileCpu.add(collection, data);
63
- return data;
64
- }
65
- /**
66
- * Find entries in the specified database based on search criteria.
67
- */
68
- async find(query) {
69
- await this.checkCollection(query);
70
- const data = await findUtil(query, this.fileCpu, [query.collection]);
71
- return data;
72
- }
73
- /**
74
- * Find the first matching entry in the specified database based on search criteria.
75
- */
76
- async findOne({ collection, search, context = {}, findOpts = {} }) {
77
- await this.checkCollection(arguments[0]);
78
- let data = await this.fileCpu.findOne(collection, search, context, findOpts);
79
- return data || null;
80
- }
81
- /**
82
- * Update entries in the specified database based on search criteria and an updater function or object.
83
- */
84
- async update({ collection, search, updater, context = {} }) {
85
- await this.checkCollection(arguments[0]);
86
- return await this.fileCpu.update(collection, false, search, updater, context);
87
- }
88
- /**
89
- * Update the first matching entry in the specified database based on search criteria and an updater function or object.
90
- */
91
- async updateOne({ collection, search, updater, context = {} }) {
92
- await this.checkCollection(arguments[0]);
93
- return await this.fileCpu.update(collection, true, search, updater, context);
94
- }
95
- /**
96
- * Remove entries from the specified database based on search criteria.
97
- */
98
- async remove({ collection, search, context = {} }) {
99
- await this.checkCollection(arguments[0]);
100
- return await this.fileCpu.remove(collection, false, search, context);
101
- }
102
- /**
103
- * Remove the first matching entry from the specified database based on search criteria.
104
- */
105
- async removeOne({ collection, search, context = {} }) {
106
- await this.checkCollection(arguments[0]);
107
- return await this.fileCpu.remove(collection, true, search, context);
108
- }
109
- /**
110
- * Removes a database collection from the file system.
111
- */
112
33
  async removeCollection({ collection }) {
113
34
  this.memory.delete(collection);
114
35
  return true;
@@ -122,9 +43,9 @@ export default class ValtheraMemory extends ValtheraClass {
122
43
  export function createMemoryValthera(data) {
123
44
  const db = new ValtheraMemory();
124
45
  if (!data)
125
- return db;
46
+ return forgeValthera(db);
126
47
  for (const collection of Object.keys(data)) {
127
48
  db.dbAction.memory.set(collection, data[collection]);
128
49
  }
129
- return db;
50
+ return forgeValthera(db);
130
51
  }
@@ -1,5 +1,5 @@
1
1
  import { UniversalEventEmitter } from "../helpers/eventEmiter.js";
2
- import dbActionBase from "../base/actions.js";
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";
@@ -12,16 +12,17 @@ import { ValtheraCompatible } from "../types/valthera.js";
12
12
  * @class
13
13
  */
14
14
  declare class ValtheraClass implements ValtheraCompatible {
15
- dbAction: dbActionBase;
15
+ dbAction: ActionsBase;
16
16
  executor: executorC;
17
17
  emiter: UniversalEventEmitter;
18
18
  version: string;
19
19
  constructor(options?: DbOpts);
20
+ init(...args: any[]): Promise<unknown>;
20
21
  private execute;
21
22
  /**
22
23
  * Create a new instance of a CollectionManager class.
23
24
  */
24
- c(collection: string): CollectionManager;
25
+ c<T = Data>(collection: string): CollectionManager<T>;
25
26
  /**
26
27
  * Get the names of all available databases.
27
28
  */
@@ -29,7 +30,7 @@ declare class ValtheraClass implements ValtheraCompatible {
29
30
  /**
30
31
  * Check and create the specified collection if it doesn't exist.
31
32
  */
32
- checkCollection(collection: string): Promise<boolean>;
33
+ ensureCollection(collection: string): Promise<boolean>;
33
34
  /**
34
35
  * Check if a collection exists.
35
36
  */
@@ -1,6 +1,6 @@
1
1
  import { version } from "../version.js";
2
2
  import { UniversalEventEmitter } from "../helpers/eventEmiter.js";
3
- import dbActionBase from "../base/actions.js";
3
+ import ActionsBase from "../base/actions.js";
4
4
  import CollectionManager from "../helpers/CollectionManager.js";
5
5
  import executorC from "../helpers/executor.js";
6
6
  /**
@@ -13,16 +13,26 @@ class ValtheraClass {
13
13
  emiter;
14
14
  version = version;
15
15
  constructor(options = {}) {
16
- this.dbAction = options.dbAction || new dbActionBase();
16
+ this.dbAction = options.dbAction || new ActionsBase();
17
17
  this.executor = options.executor || new executorC();
18
18
  this.emiter = new UniversalEventEmitter();
19
19
  }
20
+ async init(...args) {
21
+ if (this.dbAction._inited)
22
+ return;
23
+ const self = this;
24
+ return await this.executor.addOp(async () => {
25
+ if (self.dbAction._inited)
26
+ return;
27
+ await self.dbAction.init(...args);
28
+ self.dbAction._inited = true;
29
+ });
30
+ }
20
31
  async execute(name, ...args) {
32
+ await this.init();
21
33
  const result = await this.executor.addOp(this.dbAction[name].bind(this.dbAction), ...args);
22
- if (this.emiter.listenerCount(name) !== 0)
23
- this.emiter.emit(name, args, result);
24
- if (this.emiter.listenerCount("*") !== 0)
25
- this.emiter.emit("*", name, args, result);
34
+ this.emiter.emit(name, args, result);
35
+ this.emiter.emit("*", name, args, result);
26
36
  return result;
27
37
  }
28
38
  /**
@@ -40,8 +50,8 @@ class ValtheraClass {
40
50
  /**
41
51
  * Check and create the specified collection if it doesn't exist.
42
52
  */
43
- async checkCollection(collection) {
44
- return await this.execute("checkCollection", { collection });
53
+ async ensureCollection(collection) {
54
+ return await this.execute("ensureCollection", { collection });
45
55
  }
46
56
  /**
47
57
  * Check if a collection exists.
@@ -3,41 +3,41 @@ import { DbFindOpts, FindOpts } from "../types/options.js";
3
3
  import { VContext } from "../types/types.js";
4
4
  import Data from "../types/data.js";
5
5
  import { ValtheraCompatible } from "../types/valthera.js";
6
- declare class CollectionManager {
6
+ declare class CollectionManager<D = Data> {
7
7
  private db;
8
8
  private collection;
9
9
  constructor(db: ValtheraCompatible, collection: string);
10
10
  /**
11
11
  * Add data to a database.
12
12
  */
13
- add<T = Data>(data: Arg, id_gen?: boolean): Promise<T>;
13
+ add<T = D>(data: Arg<T>, id_gen?: boolean): Promise<T>;
14
14
  /**
15
15
  * Find data in a database.
16
16
  */
17
- find<T = Data>(search: Search, context?: VContext, options?: DbFindOpts, findOpts?: FindOpts): Promise<T[]>;
17
+ find<T = D>(search?: Search<T>, context?: VContext, options?: DbFindOpts<T>, findOpts?: FindOpts<T>): Promise<T[]>;
18
18
  /**
19
19
  * Find one data entry in a database.
20
20
  */
21
- findOne<T = Data>(search: Search, context?: VContext, findOpts?: FindOpts): Promise<T>;
21
+ findOne<T = D>(search?: Search<T>, context?: VContext, findOpts?: FindOpts<T>): Promise<T>;
22
22
  /**
23
23
  * Update data in a database.
24
24
  */
25
- update(search: Search, updater: Updater, context?: VContext): Promise<boolean>;
25
+ update<T = D>(search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
26
26
  /**
27
27
  * Update one data entry in a database.
28
28
  */
29
- updateOne(search: Search, updater: Updater, context?: VContext): Promise<boolean>;
29
+ updateOne<T = D>(search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
30
30
  /**
31
31
  * Remove data from a database.
32
32
  */
33
- remove(search: Search, context?: VContext): Promise<boolean>;
33
+ remove<T = D>(search: Search<T>, context?: VContext): Promise<boolean>;
34
34
  /**
35
35
  * Remove one data entry from a database.
36
36
  */
37
- removeOne(search: Search, context?: VContext): Promise<boolean>;
37
+ removeOne<T = D>(search: Search<T>, context?: VContext): Promise<boolean>;
38
38
  /**
39
39
  * Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
40
40
  */
41
- updateOneOrAdd(search: Search, updater: Updater, add_arg?: Arg, context?: VContext, id_gen?: boolean): Promise<boolean>;
41
+ updateOneOrAdd<T = D>(search: Search<T>, updater: Updater<T>, add_arg?: Arg<T>, context?: VContext, id_gen?: boolean): Promise<boolean>;
42
42
  }
43
43
  export default CollectionManager;
@@ -14,13 +14,13 @@ class CollectionManager {
14
14
  /**
15
15
  * Find data in a database.
16
16
  */
17
- async find(search, context = {}, options = {}, findOpts = {}) {
17
+ async find(search = {}, context = {}, options = {}, findOpts = {}) {
18
18
  return await this.db.find(this.collection, search, context, options, findOpts);
19
19
  }
20
20
  /**
21
21
  * Find one data entry in a database.
22
22
  */
23
- async findOne(search, context = {}, findOpts = {}) {
23
+ async findOne(search = {}, context = {}, findOpts = {}) {
24
24
  return await this.db.findOne(this.collection, search, context, findOpts);
25
25
  }
26
26
  /**
package/dist/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
+ import CustomFileCpu from "./customFileCpu.js";
2
+ import ValtheraMemory, { createMemoryValthera } from "./db/memory.js";
3
+ import ValtheraClass from "./db/valthera.js";
1
4
  import genId from "./helpers/gen.js";
2
5
  import Relation from "./helpers/relation.js";
6
+ import { ValtheraTypes } from "./types/export.js";
3
7
  import { RelationTypes } from "./types/relation.js";
4
8
  import { ValtheraCompatible } from "./types/valthera.js";
5
- import { ValtheraTypes } from "./types/export.js";
6
- import CustomFileCpu from "./customFileCpu.js";
7
- import ValtheraClass from "./db/valthera.js";
8
- import ValtheraMemory, { createMemoryValthera } from "./db/memory.js";
9
- export { ValtheraClass, ValtheraMemory, createMemoryValthera, Relation, genId, CustomFileCpu, };
10
- export type { ValtheraCompatible, RelationTypes, ValtheraTypes };
9
+ import { forgeValthera } from "./utils/forge.js";
10
+ export { createMemoryValthera, CustomFileCpu, forgeValthera, genId, Relation, ValtheraClass, ValtheraMemory };
11
+ export type { RelationTypes, ValtheraCompatible, ValtheraTypes };
11
12
  export type Id = import("./types/Id.js").Id;
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
- import genId from "./helpers/gen.js";
2
- import Relation from "./helpers/relation.js";
3
1
  import CustomFileCpu from "./customFileCpu.js";
4
- import ValtheraClass from "./db/valthera.js";
5
2
  import ValtheraMemory, { createMemoryValthera } from "./db/memory.js";
6
- export { ValtheraClass, ValtheraMemory, createMemoryValthera, Relation, genId, CustomFileCpu, };
3
+ import ValtheraClass from "./db/valthera.js";
4
+ import genId from "./helpers/gen.js";
5
+ import Relation from "./helpers/relation.js";
6
+ import { forgeValthera } from "./utils/forge.js";
7
+ export { createMemoryValthera, CustomFileCpu, forgeValthera, genId, Relation, ValtheraClass, ValtheraMemory };
@@ -1,9 +1,9 @@
1
- import dbActionBase from "../base/actions.js";
1
+ import ActionsBase from "../base/actions.js";
2
2
  import executorC from "../helpers/executor.js";
3
3
  import { KeysMatching } from "./utils.js";
4
4
  export interface DbOpts {
5
5
  maxFileSize?: number;
6
- dbAction?: dbActionBase;
6
+ dbAction?: ActionsBase;
7
7
  executor?: executorC;
8
8
  }
9
9
  export interface DbFindOpts<T = any> {
@@ -7,7 +7,7 @@ import { VContext } from "./types.js";
7
7
  export interface ValtheraCompatible {
8
8
  c(collection: string): CollectionManager;
9
9
  getCollections(): Promise<string[]>;
10
- checkCollection(collection: string): Promise<boolean>;
10
+ ensureCollection(collection: string): Promise<boolean>;
11
11
  issetCollection(collection: string): Promise<boolean>;
12
12
  add<T = Data>(collection: string, data: Arg<T>, id_gen?: boolean): Promise<T>;
13
13
  find<T = Data>(collection: string, search: Search<T>, context?: VContext, options?: DbFindOpts<T>, findOpts?: FindOpts<T>): Promise<T[]>;
@@ -22,7 +22,7 @@ export interface ValtheraCompatible {
22
22
  export interface ValtheraCompatibleInternal {
23
23
  c(config: VQuery): CollectionManager;
24
24
  getCollections(): Promise<string[]>;
25
- checkCollection(config: VQuery): Promise<boolean>;
25
+ ensureCollection(config: VQuery): Promise<boolean>;
26
26
  issetCollection(config: VQuery): Promise<boolean>;
27
27
  add<T = Data>(config: VQuery): Promise<T>;
28
28
  find<T = Data>(config: VQuery): Promise<T[]>;
@@ -0,0 +1,3 @@
1
+ import CollectionManager from "../helpers/CollectionManager.js";
2
+ import { ValtheraCompatible } from "../types/valthera.js";
3
+ export declare function forgeValthera<T extends string>(target: ValtheraCompatible): ValtheraCompatible & { [K in T]: CollectionManager; };
@@ -0,0 +1,17 @@
1
+ import CollectionManager from "../helpers/CollectionManager.js";
2
+ export function forgeValthera(target) {
3
+ return new Proxy(target, {
4
+ get(target, prop, receiver) {
5
+ if (prop in target) {
6
+ return Reflect.get(target, prop, receiver);
7
+ }
8
+ const collection = new CollectionManager(target, prop);
9
+ target[prop] = collection;
10
+ return collection;
11
+ },
12
+ set(target, prop, value, receiver) {
13
+ return Reflect.set(target, prop, value, receiver);
14
+ }
15
+ });
16
+ }
17
+ ;
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.0.7";
1
+ export const version = "0.1.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.0.7",
3
+ "version": "0.1.1",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",
package/dist/base/db.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import CollectionManager from "../helpers/CollectionManager.js";
2
- import Data from "../types/data.js";
3
- import { VQuery } from "../types/query.js";
4
- import { ValtheraCompatibleInternal } from "../types/valthera.js";
5
- declare class ValtheraBase implements ValtheraCompatibleInternal {
6
- version: string;
7
- c(config: VQuery): CollectionManager;
8
- getCollections(): Promise<any[]>;
9
- checkCollection(config: VQuery): Promise<boolean>;
10
- issetCollection(config: VQuery): Promise<boolean>;
11
- add<T = Data>(config: VQuery): Promise<T>;
12
- find<T = Data>(config: VQuery): Promise<T[]>;
13
- findOne<T = Data>(config: VQuery): Promise<T>;
14
- remove(config: VQuery): Promise<boolean>;
15
- removeCollection(config: VQuery): Promise<boolean>;
16
- removeOne(config: VQuery): Promise<boolean>;
17
- update(config: VQuery): Promise<boolean>;
18
- updateOne(config: VQuery): Promise<boolean>;
19
- updateOneOrAdd(config: VQuery): Promise<boolean>;
20
- }
21
- export default ValtheraBase;
package/dist/base/db.js DELETED
@@ -1,56 +0,0 @@
1
- import { version } from "../version.js";
2
- class ValtheraBase {
3
- version = version;
4
- c(config) {
5
- throw new Error("Not implemented");
6
- }
7
- async getCollections() {
8
- throw new Error("Not implemented");
9
- return [];
10
- }
11
- async checkCollection(config) {
12
- throw new Error("Not implemented");
13
- return false;
14
- }
15
- async issetCollection(config) {
16
- throw new Error("Not implemented");
17
- return false;
18
- }
19
- async add(config) {
20
- throw new Error("Not implemented");
21
- return {};
22
- }
23
- async find(config) {
24
- throw new Error("Not implemented");
25
- return [];
26
- }
27
- async findOne(config) {
28
- throw new Error("Not implemented");
29
- return {};
30
- }
31
- async remove(config) {
32
- throw new Error("Not implemented");
33
- return false;
34
- }
35
- async removeCollection(config) {
36
- throw new Error("Not implemented");
37
- return false;
38
- }
39
- async removeOne(config) {
40
- throw new Error("Not implemented");
41
- return false;
42
- }
43
- async update(config) {
44
- throw new Error("Not implemented");
45
- return false;
46
- }
47
- async updateOne(config) {
48
- throw new Error("Not implemented");
49
- return false;
50
- }
51
- async updateOneOrAdd(config) {
52
- throw new Error("Not implemented");
53
- return false;
54
- }
55
- }
56
- export default ValtheraBase;