@wxn0brp/db 0.5.4 → 0.5.6
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/client/database.d.ts +1 -1
- package/dist/client/database.js +21 -2
- package/dist/client/graph.d.ts +1 -1
- package/dist/client/graph.js +21 -2
- package/dist/memory.d.ts +2 -2
- package/dist/relation.d.ts +2 -2
- package/dist/relation.js +5 -2
- package/package.json +1 -1
package/dist/client/database.js
CHANGED
|
@@ -9,7 +9,25 @@ import serializeFunctions from "./function.js";
|
|
|
9
9
|
class DataBaseRemote {
|
|
10
10
|
remote;
|
|
11
11
|
constructor(remote) {
|
|
12
|
-
|
|
12
|
+
if (typeof remote === "string") {
|
|
13
|
+
const urlObj = new URL(remote);
|
|
14
|
+
const name = urlObj.username;
|
|
15
|
+
const auth = urlObj.password;
|
|
16
|
+
if (!name || !auth)
|
|
17
|
+
throw new Error("Invalid remote database");
|
|
18
|
+
urlObj.username = "";
|
|
19
|
+
urlObj.password = "";
|
|
20
|
+
const url = urlObj.toString().slice(0, -1);
|
|
21
|
+
this.remote = {
|
|
22
|
+
name,
|
|
23
|
+
url,
|
|
24
|
+
auth
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
this.remote = remote;
|
|
29
|
+
if (this.remote.url.endsWith("/"))
|
|
30
|
+
this.remote.url = this.remote.url.slice(0, -1);
|
|
13
31
|
}
|
|
14
32
|
/**
|
|
15
33
|
* Make a request to the remote database.
|
|
@@ -21,7 +39,8 @@ class DataBaseRemote {
|
|
|
21
39
|
params: processed.data,
|
|
22
40
|
keys: processed.keys
|
|
23
41
|
};
|
|
24
|
-
const
|
|
42
|
+
const url = this.remote.url + "/db/" + type;
|
|
43
|
+
const res = await ky.post(url, {
|
|
25
44
|
json: data,
|
|
26
45
|
headers: {
|
|
27
46
|
"Authorization": this.remote.auth
|
package/dist/client/graph.d.ts
CHANGED
package/dist/client/graph.js
CHANGED
|
@@ -10,7 +10,25 @@ class GraphRemote {
|
|
|
10
10
|
* Create a new database instance.
|
|
11
11
|
*/
|
|
12
12
|
constructor(remote) {
|
|
13
|
-
|
|
13
|
+
if (typeof remote === "string") {
|
|
14
|
+
const urlObj = new URL(remote);
|
|
15
|
+
const name = urlObj.username;
|
|
16
|
+
const auth = urlObj.password;
|
|
17
|
+
if (!name || !auth)
|
|
18
|
+
throw new Error("Invalid remote database");
|
|
19
|
+
urlObj.username = "";
|
|
20
|
+
urlObj.password = "";
|
|
21
|
+
const url = urlObj.toString().slice(0, -1);
|
|
22
|
+
this.remote = {
|
|
23
|
+
name,
|
|
24
|
+
url,
|
|
25
|
+
auth
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else
|
|
29
|
+
this.remote = remote;
|
|
30
|
+
if (this.remote.url.endsWith("/"))
|
|
31
|
+
this.remote.url = this.remote.url.slice(0, -1);
|
|
14
32
|
}
|
|
15
33
|
/**
|
|
16
34
|
* Make a request to the remote database.
|
|
@@ -20,7 +38,8 @@ class GraphRemote {
|
|
|
20
38
|
db: this.remote.name,
|
|
21
39
|
params
|
|
22
40
|
};
|
|
23
|
-
const
|
|
41
|
+
const url = this.remote.url + "/db/" + type;
|
|
42
|
+
const res = await ky.post(url, {
|
|
24
43
|
json: data,
|
|
25
44
|
headers: {
|
|
26
45
|
"Authorization": this.remote.auth
|
package/dist/memory.d.ts
CHANGED
|
@@ -79,6 +79,6 @@ export declare class MemoryAction implements dbActionC {
|
|
|
79
79
|
export default class ValtheraMemory extends DataBase {
|
|
80
80
|
constructor(...args: any[]);
|
|
81
81
|
}
|
|
82
|
-
export declare function createMemoryValthera
|
|
82
|
+
export declare function createMemoryValthera<T = {
|
|
83
83
|
[key: string]: Data[];
|
|
84
|
-
}): ValtheraMemory;
|
|
84
|
+
}>(data?: T): ValtheraMemory;
|
package/dist/relation.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { RelationTypes } from "./types/relation.js";
|
|
|
4
4
|
declare class Relation {
|
|
5
5
|
dbs: RelationTypes.DBS;
|
|
6
6
|
constructor(dbs: RelationTypes.DBS);
|
|
7
|
-
findOne(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select
|
|
8
|
-
find(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select
|
|
7
|
+
findOne(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select?: RelationTypes.FieldPath[]): Promise<any>;
|
|
8
|
+
find(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select?: RelationTypes.FieldPath[], findOpts?: DbFindOpts): Promise<any[]>;
|
|
9
9
|
}
|
|
10
10
|
export default Relation;
|
package/dist/relation.js
CHANGED
|
@@ -52,8 +52,10 @@ function selectDataSelf(data, select) {
|
|
|
52
52
|
return selectDataSelf(data[select[0]], select.slice(1));
|
|
53
53
|
}
|
|
54
54
|
function selectData(data, select) {
|
|
55
|
-
if (!select
|
|
55
|
+
if (!select)
|
|
56
56
|
return data;
|
|
57
|
+
if (!data && select.length === 0)
|
|
58
|
+
return null;
|
|
57
59
|
const newData = {};
|
|
58
60
|
for (const field of select) {
|
|
59
61
|
const key = field.map(f => f.replaceAll(".", "\\.")).join(".");
|
|
@@ -70,7 +72,8 @@ class Relation {
|
|
|
70
72
|
const db = this.dbs[path[0]];
|
|
71
73
|
const data = await db.findOne(path[1], search);
|
|
72
74
|
await processRelations(this.dbs, relations, data);
|
|
73
|
-
|
|
75
|
+
const result = selectData(data, select);
|
|
76
|
+
return Object.keys(result).length === 0 ? null : result;
|
|
74
77
|
}
|
|
75
78
|
async find(path, search, relations, select, findOpts = {}) {
|
|
76
79
|
const db = this.dbs[path[0]];
|
package/package.json
CHANGED