@wxn0brp/db-core 0.11.4-alpha.1 → 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.
- package/dist/customFileCpu.js +1 -1
- package/dist/db/memory.js +2 -2
- package/dist/db/valthera.d.ts +5 -1
- package/dist/db/valthera.js +26 -16
- package/dist/helpers/executor.js +2 -3
- package/dist/types/options.d.ts +13 -3
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/customFileCpu.js
CHANGED
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({
|
|
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.
|
|
51
|
+
db.adapter.memory.set(collection, data[collection]);
|
|
52
52
|
}
|
|
53
53
|
return forgeValthera(db);
|
|
54
54
|
}
|
package/dist/db/valthera.d.ts
CHANGED
|
@@ -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
|
-
|
|
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>;
|
package/dist/db/valthera.js
CHANGED
|
@@ -8,52 +8,62 @@ import { version } from "../version.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export class ValtheraClass {
|
|
10
10
|
options;
|
|
11
|
-
|
|
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
|
-
|
|
28
|
+
options.adapter ??= options.dbAction;
|
|
29
|
+
options.dbAction ??= options.adapter;
|
|
30
|
+
if (typeof options.adapter === "function")
|
|
21
31
|
return;
|
|
22
32
|
else
|
|
23
|
-
this.
|
|
33
|
+
this.adapter = options.adapter;
|
|
24
34
|
}
|
|
25
35
|
async init(...args) {
|
|
26
|
-
if (this.
|
|
36
|
+
if (this.adapter?._inited)
|
|
27
37
|
return;
|
|
28
38
|
const self = this;
|
|
29
39
|
return await this.executor.addOp(async () => {
|
|
30
|
-
if (self.
|
|
40
|
+
if (self.adapter?._inited)
|
|
31
41
|
return;
|
|
32
|
-
if (typeof self.options.
|
|
33
|
-
self.
|
|
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.
|
|
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.
|
|
39
|
-
await self.
|
|
40
|
-
self.
|
|
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.
|
|
54
|
+
if (!this.adapter._inited)
|
|
45
55
|
return;
|
|
46
56
|
const self = this;
|
|
47
57
|
return await this.executor.addOp(async () => {
|
|
48
|
-
if (!self.
|
|
58
|
+
if (!self.adapter._inited)
|
|
49
59
|
return;
|
|
50
|
-
await self.
|
|
51
|
-
self.
|
|
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.
|
|
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
|
}
|
package/dist/helpers/executor.js
CHANGED
|
@@ -27,9 +27,8 @@ export class Executor {
|
|
|
27
27
|
return;
|
|
28
28
|
this.isExecuting = true;
|
|
29
29
|
while (this.queue.length > 0) {
|
|
30
|
-
|
|
31
|
-
|
|
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
|
}
|
package/dist/types/options.d.ts
CHANGED
|
@@ -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
|
|
5
|
-
|
|
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.
|
|
1
|
+
export const version = "0.11.4-alpha.2";
|