@wxn0brp/db-core 0.12.4-alpha.1 → 0.12.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/base/actions.d.ts +1 -0
- package/dist/base/actions.js +3 -0
- package/dist/db/valthera.d.ts +5 -0
- package/dist/db/valthera.js +14 -0
- package/dist/helpers/addId.js +5 -1
- package/dist/helpers/collection.d.ts +5 -0
- package/dist/helpers/collection.js +6 -0
- package/dist/types/action.d.ts +1 -0
- package/dist/types/idx.d.ts +12 -0
- package/dist/types/idx.js +1 -0
- package/dist/types/query.d.ts +5 -0
- package/dist/types/valthera.d.ts +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/base/actions.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare abstract class ActionsBase implements ActionsBaseInterface {
|
|
|
25
25
|
beginTransaction(id: Id): Promise<TransactionHandle>;
|
|
26
26
|
commitTransaction(handle: TransactionHandle): Promise<void>;
|
|
27
27
|
rollbackTransaction(handle: TransactionHandle): Promise<void>;
|
|
28
|
+
createIndex(config: VQueryT.CreateIndex): Promise<void>;
|
|
28
29
|
updateOneOrAdd(config: VQueryT.UpdateOneOrAdd): Promise<VQueryT.UpdateOneOrAddResult<DataInternal>>;
|
|
29
30
|
toggleOne(config: VQueryT.ToggleOne): Promise<VQueryT.ToggleOneResult<DataInternal>>;
|
|
30
31
|
}
|
package/dist/base/actions.js
CHANGED
|
@@ -19,6 +19,9 @@ export class ActionsBase {
|
|
|
19
19
|
async rollbackTransaction(handle) {
|
|
20
20
|
throw new Error("Transactions are not supported for ActionsBase");
|
|
21
21
|
}
|
|
22
|
+
async createIndex(config) {
|
|
23
|
+
// No-op: adapter does not use indexes internally
|
|
24
|
+
}
|
|
22
25
|
async updateOneOrAdd(config) {
|
|
23
26
|
const res = await this.updateOne(config);
|
|
24
27
|
if (res)
|
package/dist/db/valthera.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ActionsBase } from "../base/actions.js";
|
|
|
3
3
|
import { Collection } from "../helpers/collection.js";
|
|
4
4
|
import { ExecutorInterface } from "../helpers/executor.js";
|
|
5
5
|
import { Data } from "../types/data.js";
|
|
6
|
+
import { IndexOpts } from "../types/idx.js";
|
|
6
7
|
import { DbOpts } from "../types/options.js";
|
|
7
8
|
import { ValtheraPlugin } from "../types/plugin.js";
|
|
8
9
|
import { VQuery, VQueryT } from "../types/query.js";
|
|
@@ -86,6 +87,10 @@ export declare class ValtheraClass implements ValtheraCompatible {
|
|
|
86
87
|
* Removes a database collection from the database.
|
|
87
88
|
*/
|
|
88
89
|
removeCollection(collection: string): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* Create an index on a collection.
|
|
92
|
+
*/
|
|
93
|
+
createIndex(collection: string, fields: string[], opts?: IndexOpts): Promise<void>;
|
|
89
94
|
/**
|
|
90
95
|
* @experimental
|
|
91
96
|
*
|
package/dist/db/valthera.js
CHANGED
|
@@ -195,6 +195,20 @@ export class ValtheraClass {
|
|
|
195
195
|
this._collections.delete(collection);
|
|
196
196
|
return this.execute("removeCollection", collection);
|
|
197
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Create an index on a collection.
|
|
200
|
+
*/
|
|
201
|
+
async createIndex(collection, fields, opts) {
|
|
202
|
+
const index = {
|
|
203
|
+
collection,
|
|
204
|
+
fields,
|
|
205
|
+
opts,
|
|
206
|
+
};
|
|
207
|
+
await this.execute("createIndex", {
|
|
208
|
+
collection,
|
|
209
|
+
index,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
198
212
|
/**
|
|
199
213
|
* @experimental
|
|
200
214
|
*
|
package/dist/helpers/addId.js
CHANGED
|
@@ -11,7 +11,11 @@ export async function addId(query, actions, defaultGen = true) {
|
|
|
11
11
|
data[idKey] = genId();
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
const txOpts = query.transaction
|
|
14
|
+
const txOpts = query.transaction
|
|
15
|
+
? {
|
|
16
|
+
transaction: query.transaction,
|
|
17
|
+
}
|
|
18
|
+
: {};
|
|
15
19
|
const find = (await actions.findOne({
|
|
16
20
|
collection: "__vdb_id",
|
|
17
21
|
search: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Arg, Search, Updater } from "../types/arg.js";
|
|
2
2
|
import { UpdateOneOrAdd } from "../types/collection.js";
|
|
3
3
|
import { Data } from "../types/data.js";
|
|
4
|
+
import { IndexOpts } from "../types/idx.js";
|
|
4
5
|
import { DbFindOpts, FindOpts } from "../types/options.js";
|
|
5
6
|
import { VQueryT } from "../types/query.js";
|
|
6
7
|
import { VContext } from "../types/types.js";
|
|
@@ -48,4 +49,8 @@ export declare class Collection<D = Data> {
|
|
|
48
49
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
49
50
|
*/
|
|
50
51
|
toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<VQueryT.ToggleOneResult<D>>;
|
|
52
|
+
/**
|
|
53
|
+
* Create an index on this collection.
|
|
54
|
+
*/
|
|
55
|
+
createIndex(fields: string[], opts?: IndexOpts): Promise<void>;
|
|
51
56
|
}
|
package/dist/types/action.d.ts
CHANGED
|
@@ -25,4 +25,5 @@ export interface ActionsBaseInterface {
|
|
|
25
25
|
beginTransaction(id: Id): Promise<TransactionHandle>;
|
|
26
26
|
commitTransaction(handle: TransactionHandle): Promise<void>;
|
|
27
27
|
rollbackTransaction(handle: TransactionHandle): Promise<void>;
|
|
28
|
+
createIndex(config: VQueryT.CreateIndex): Promise<void>;
|
|
28
29
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/query.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Arg, Search, Updater } from "./arg.js";
|
|
2
2
|
import { Data } from "./data.js";
|
|
3
|
+
import { IndexDefinition } from "./idx.js";
|
|
3
4
|
import { DbFindOpts, FindOpts } from "./options.js";
|
|
4
5
|
import { TransactionHandle } from "./transaction.js";
|
|
5
6
|
import { VContext } from "./types.js";
|
|
@@ -27,6 +28,7 @@ export interface VQuery<T = Data, AllowFn extends boolean = true> {
|
|
|
27
28
|
updater?: Updater<T, AllowFn>;
|
|
28
29
|
control?: VQuery_Control;
|
|
29
30
|
transaction?: TransactionHandle;
|
|
31
|
+
index?: IndexDefinition;
|
|
30
32
|
}
|
|
31
33
|
export declare namespace VQueryT {
|
|
32
34
|
type QueryBase<T = Data> = {
|
|
@@ -78,4 +80,7 @@ export declare namespace VQueryT {
|
|
|
78
80
|
data: T;
|
|
79
81
|
type: "added" | "removed";
|
|
80
82
|
}
|
|
83
|
+
type CreateIndex<T = Data> = QueryBase<T> & {
|
|
84
|
+
index: IndexDefinition;
|
|
85
|
+
};
|
|
81
86
|
}
|
package/dist/types/valthera.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Collection } from "../helpers/collection.js";
|
|
2
2
|
import { Data } from "./data.js";
|
|
3
|
+
import { IndexOpts } from "./idx.js";
|
|
3
4
|
import { VQueryT } from "./query.js";
|
|
4
5
|
export interface ValtheraCompatible {
|
|
5
6
|
c<T = Data>(collection: string): Collection<T>;
|
|
@@ -16,4 +17,5 @@ export interface ValtheraCompatible {
|
|
|
16
17
|
removeCollection(collection: string): Promise<boolean>;
|
|
17
18
|
updateOneOrAdd<T = Data>(query: VQueryT.UpdateOneOrAdd<T>): Promise<VQueryT.UpdateOneOrAddResult<T>>;
|
|
18
19
|
toggleOne<T = Data>(query: VQueryT.ToggleOne<T>): Promise<VQueryT.ToggleOneResult<T>>;
|
|
20
|
+
createIndex(collection: string, fields: string[], opts?: IndexOpts): Promise<void>;
|
|
19
21
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.12.4-alpha.
|
|
1
|
+
export declare const version = "0.12.4-alpha.2";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.12.4-alpha.
|
|
1
|
+
export const version = "0.12.4-alpha.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db-core",
|
|
3
|
-
"version": "0.12.4-alpha.
|
|
3
|
+
"version": "0.12.4-alpha.2",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "wxn0brP",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/wxn0brP/ValtheraDB",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@wxn0brp/event-emitter": "0.0.
|
|
16
|
+
"@wxn0brp/event-emitter": "0.0.7"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/bun": "*",
|