@wxn0brp/db-core 0.11.1-alpha.1 → 0.11.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.
@@ -6,6 +6,7 @@ export declare abstract class ActionsBase implements ActionsBaseInterface {
6
6
  numberId: boolean;
7
7
  smartExecutor: boolean;
8
8
  init(...args: any[]): Promise<void>;
9
+ close(...args: any[]): Promise<void>;
9
10
  abstract getCollections(): Promise<string[]>;
10
11
  abstract ensureCollection(collection: string): Promise<boolean>;
11
12
  abstract issetCollection(collection: string): Promise<boolean>;
@@ -4,6 +4,7 @@ export class ActionsBase {
4
4
  numberId = false;
5
5
  smartExecutor = false;
6
6
  async init(...args) { }
7
+ async close(...args) { }
7
8
  async updateOneOrAdd(config) {
8
9
  const res = await this.updateOne(config);
9
10
  if (res)
@@ -5,6 +5,7 @@ export declare class MultiBackend extends ActionsBase {
5
5
  primaryBackend: ActionsBase;
6
6
  constructor(backends: ActionsBase[], primaryIndex?: number);
7
7
  init(...args: any[]): Promise<void>;
8
+ close(...args: any[]): Promise<void>;
8
9
  add(config: VQueryT.Add): Promise<import("../types/data.js").DataInternal>;
9
10
  find(config: VQueryT.Find): Promise<import("../types/data.js").DataInternal[]>;
10
11
  findOne(config: VQueryT.FindOne): Promise<import("../types/data.js").DataInternal>;
@@ -10,6 +10,9 @@ export class MultiBackend extends ActionsBase {
10
10
  async init(...args) {
11
11
  await Promise.all(this.backends.map(b => b.init?.(...args)));
12
12
  }
13
+ async close(...args) {
14
+ await Promise.all(this.backends.map(b => b.close(...args)));
15
+ }
13
16
  async add(config) {
14
17
  return await this.primaryBackend.add({ ...config });
15
18
  }
@@ -13,6 +13,7 @@ export declare class RoutedStorage extends ActionsBase {
13
13
  _withAll<T>(config: VQuery | string, fn: (b: ActionsBase) => Promise<T>, gather?: boolean): Promise<T>;
14
14
  _withFirst<T>(config: VQuery | string, fn: (b: ActionsBase) => Promise<T>): Promise<T>;
15
15
  init(...args: any[]): Promise<void>;
16
+ close(...args: any[]): Promise<void>;
16
17
  add(config: VQueryT.Add): Promise<import("../types/data.js").DataInternal>;
17
18
  find(config: VQueryT.Find): Promise<import("../types/data.js").DataInternal[]>;
18
19
  findOne(config: VQueryT.FindOne): Promise<import("../types/data.js").DataInternal>;
@@ -41,6 +41,13 @@ export class RoutedStorage extends ActionsBase {
41
41
  const all = new Set(this.rules.flatMap(r => r.backends));
42
42
  await Promise.all(Array.from(all).map(b => b.init?.(...args)));
43
43
  }
44
+ async close(...args) {
45
+ const all = new Set([
46
+ ...this.rules.flatMap(r => r.backends),
47
+ ...this.defaultBackend
48
+ ]);
49
+ await Promise.all(Array.from(all).map(b => b.close(...args)));
50
+ }
44
51
  async add(config) {
45
52
  const res = await this._withFirst(config, b => b.add(config));
46
53
  await this._withAll({ ...config, data: res }, b => b.add({ ...config, data: res }));
@@ -40,6 +40,7 @@ export declare class ValtheraClass implements ValtheraCompatible {
40
40
  version: string;
41
41
  constructor(options: DbOpts);
42
42
  init(...args: any[]): Promise<any>;
43
+ close(...args: any[]): Promise<any>;
43
44
  execute<T>(name: keyof ValtheraCompatible, query: VQuery<any> | string): Promise<T>;
44
45
  /**
45
46
  * Create a new instance of a Collection class.
@@ -30,6 +30,17 @@ export class ValtheraClass {
30
30
  self.dbAction._inited = true;
31
31
  });
32
32
  }
33
+ async close(...args) {
34
+ if (!this.dbAction._inited)
35
+ return;
36
+ const self = this;
37
+ return await this.executor.addOp(async () => {
38
+ if (!self.dbAction._inited)
39
+ return;
40
+ await self.dbAction.close(...args);
41
+ self.dbAction._inited = false;
42
+ });
43
+ }
33
44
  async execute(name, query) {
34
45
  await this.init();
35
46
  const result = await this.executor.addOp(this.dbAction[name].bind(this.dbAction), query, typeof query === "string" ? query : query.collection);
@@ -4,6 +4,7 @@ export interface ActionsBaseInterface {
4
4
  _inited: boolean;
5
5
  numberId: boolean;
6
6
  init(...args: any[]): Promise<void>;
7
+ close(...args: any[]): Promise<void>;
7
8
  getCollections(): Promise<string[]>;
8
9
  ensureCollection(collection: string): Promise<boolean>;
9
10
  issetCollection(collection: string): Promise<boolean>;
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.11.1-alpha.1";
1
+ export const version = "0.11.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.11.1-alpha.1",
3
+ "version": "0.11.1",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",