@wxn0brp/db-core 0.11.4-alpha.0 → 0.11.4-alpha.2

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,6 +1,6 @@
1
1
  import { matchObj, findObj, updateObj } from "./utils/process.js";
2
2
  export function pathRepair(path) {
3
- return path.replaceAll("//", "/");
3
+ return path.replace(/\/+/g, "/");
4
4
  }
5
5
  export class CustomFileCpu {
6
6
  _readFile;
package/dist/db/memory.js CHANGED
@@ -40,7 +40,7 @@ export class MemoryAction extends CustomActionsBase {
40
40
  }
41
41
  export class ValtheraMemory extends ValtheraClass {
42
42
  constructor(...args) {
43
- super({ dbAction: new MemoryAction() });
43
+ super({ adapter: new MemoryAction() });
44
44
  }
45
45
  }
46
46
  export function createMemoryValthera(data) {
@@ -48,7 +48,7 @@ export function createMemoryValthera(data) {
48
48
  if (!data)
49
49
  return forgeValthera(db);
50
50
  for (const collection of Object.keys(data)) {
51
- db.dbAction.memory.set(collection, data[collection]);
51
+ db.adapter.memory.set(collection, data[collection]);
52
52
  }
53
53
  return forgeValthera(db);
54
54
  }
@@ -12,7 +12,7 @@ import { ValtheraCompatible } from "../types/valthera.js";
12
12
  */
13
13
  export declare class ValtheraClass implements ValtheraCompatible {
14
14
  options: DbOpts;
15
- dbAction: ActionsBase;
15
+ adapter: ActionsBase;
16
16
  executor: ExecutorInterface;
17
17
  emitter: VEE<{
18
18
  [K in keyof ValtheraCompatible]: (query: VQuery, result: Awaited<ReturnType<ValtheraCompatible[K]>>) => void;
@@ -39,6 +39,10 @@ export declare class ValtheraClass implements ValtheraCompatible {
39
39
  "*": (name: keyof ValtheraCompatible, query: VQuery, result: any) => void;
40
40
  }>;
41
41
  version: string;
42
+ /** @deprecated use `adapter` */
43
+ get dbAction(): ActionsBase;
44
+ /** @deprecated use `adapter` */
45
+ set dbAction(action: ActionsBase);
42
46
  constructor(options: DbOpts);
43
47
  init(...args: any[]): Promise<any>;
44
48
  close(...args: any[]): Promise<any>;
@@ -8,52 +8,62 @@ import { version } from "../version.js";
8
8
  */
9
9
  export class ValtheraClass {
10
10
  options;
11
- dbAction;
11
+ adapter;
12
12
  executor;
13
13
  emitter = new VEE();
14
14
  /** @deprecated typo */
15
15
  emiter = this.emitter;
16
16
  version = version;
17
+ /** @deprecated use `adapter` */
18
+ get dbAction() {
19
+ return this.adapter;
20
+ }
21
+ /** @deprecated use `adapter` */
22
+ set dbAction(action) {
23
+ this.adapter = action;
24
+ }
17
25
  constructor(options) {
18
26
  this.options = options;
19
27
  this.executor = options.executor || new SmartExecutor(undefined, false);
20
- if (typeof options.dbAction === "function")
28
+ options.adapter ??= options.dbAction;
29
+ options.dbAction ??= options.adapter;
30
+ if (typeof options.adapter === "function")
21
31
  return;
22
32
  else
23
- this.dbAction = options.dbAction;
33
+ this.adapter = options.adapter;
24
34
  }
25
35
  async init(...args) {
26
- if (this.dbAction?._inited)
36
+ if (this.adapter?._inited)
27
37
  return;
28
38
  const self = this;
29
39
  return await this.executor.addOp(async () => {
30
- if (self.dbAction._inited)
40
+ if (self.adapter?._inited)
31
41
  return;
32
- if (typeof self.options.dbAction === "function")
33
- self.dbAction = await self.options.dbAction();
42
+ if (typeof self.options.adapter === "function")
43
+ self.adapter = await self.options.adapter();
34
44
  // if the executor is not set, and the action wants a smart executor
35
- if (!self.options.executor && self.dbAction.smartExecutor && self.executor instanceof SmartExecutor)
45
+ if (!self.options.executor && self.adapter.smartExecutor && self.executor instanceof SmartExecutor)
36
46
  self.executor.aware = true;
37
47
  if (self.options.numberId)
38
- self.dbAction.numberId = true;
39
- await self.dbAction.init(...args);
40
- self.dbAction._inited = true;
48
+ self.adapter.numberId = true;
49
+ await self.adapter.init(...args);
50
+ self.adapter._inited = true;
41
51
  });
42
52
  }
43
53
  async close(...args) {
44
- if (!this.dbAction._inited)
54
+ if (!this.adapter._inited)
45
55
  return;
46
56
  const self = this;
47
57
  return await this.executor.addOp(async () => {
48
- if (!self.dbAction._inited)
58
+ if (!self.adapter._inited)
49
59
  return;
50
- await self.dbAction.close(...args);
51
- self.dbAction._inited = false;
60
+ await self.adapter.close(...args);
61
+ self.adapter._inited = false;
52
62
  });
53
63
  }
54
64
  async execute(name, query) {
55
65
  await this.init();
56
- const result = await this.executor.addOp(this.dbAction[name].bind(this.dbAction), query, typeof query === "string" ? query : query.collection);
66
+ const result = await this.executor.addOp(this.adapter[name].bind(this.adapter), query, typeof query === "string" ? query : query.collection);
57
67
  this.emitter.emit(name, query, result);
58
68
  return result;
59
69
  }
@@ -27,9 +27,8 @@ export class Executor {
27
27
  return;
28
28
  this.isExecuting = true;
29
29
  while (this.queue.length > 0) {
30
- let q = this.queue.shift();
31
- let res = await q.func(...q.param);
32
- q.resolve(res);
30
+ const q = this.queue.shift();
31
+ await q.func(...q.param).then(q.resolve).catch(q.reject);
33
32
  }
34
33
  this.isExecuting = false;
35
34
  }
@@ -1,11 +1,20 @@
1
1
  import { ActionsBase } from "../base/actions.js";
2
2
  import { Executor } from "../helpers/executor.js";
3
3
  import { KeysMatching } from "./utils.js";
4
- export interface DbOpts {
5
- dbAction: ActionsBase | (() => Promise<ActionsBase>);
4
+ export type AdapterValue = ActionsBase | (() => Promise<ActionsBase>);
5
+ type AdapterOption = {
6
+ adapter: AdapterValue;
7
+ /** @deprecated use `adapter` */
8
+ dbAction?: AdapterValue;
9
+ } | {
10
+ adapter?: AdapterValue;
11
+ /** @deprecated use `adapter` */
12
+ dbAction: AdapterValue;
13
+ };
14
+ export type DbOpts = AdapterOption & {
6
15
  executor?: Executor;
7
16
  numberId?: boolean;
8
- }
17
+ };
9
18
  export interface DbFindOpts<T = any> {
10
19
  reverse?: boolean;
11
20
  limit?: number;
@@ -23,3 +32,4 @@ export interface FindOpts<T = any> {
23
32
  exclude?: KeysMatching<T, any>[];
24
33
  transform?: Function;
25
34
  }
35
+ export {};
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.11.4-alpha.0";
1
+ export const version = "0.11.4-alpha.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.11.4-alpha.0",
3
+ "version": "0.11.4-alpha.2",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",