@wxn0brp/db 0.5.5 → 0.5.7
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/autoCreate.d.ts +4 -0
- package/dist/autoCreate.js +9 -0
- 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/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import DataBaseRemote from "./client/database.js";
|
|
2
|
+
import DataBase from "./database.js";
|
|
3
|
+
export function autoCreate(cfg) {
|
|
4
|
+
if (typeof cfg === "object")
|
|
5
|
+
return new DataBaseRemote(cfg);
|
|
6
|
+
if (cfg.startsWith("http"))
|
|
7
|
+
return new DataBaseRemote(cfg);
|
|
8
|
+
return new DataBase(cfg);
|
|
9
|
+
}
|
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/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import genId from "./gen.js";
|
|
|
6
6
|
import Relation from "./relation.js";
|
|
7
7
|
import CustomFileCpu from "./file/customFileCpu.js";
|
|
8
8
|
import ValtheraMemory, { createMemoryValthera } from "./memory.js";
|
|
9
|
-
|
|
9
|
+
import { autoCreate } from "./autoCreate.js";
|
|
10
|
+
export { DataBase as Valthera, Graph, DataBaseRemote as ValtheraRemote, GraphRemote, Relation, genId, CustomFileCpu, ValtheraMemory, createMemoryValthera, autoCreate, };
|
|
10
11
|
export type Id = import("./types/Id.js").Id;
|
|
11
12
|
export declare namespace ValtheraTypes {
|
|
12
13
|
type Arg = import("./types/arg.js").Arg;
|
package/dist/index.js
CHANGED
|
@@ -6,4 +6,5 @@ import genId from "./gen.js";
|
|
|
6
6
|
import Relation from "./relation.js";
|
|
7
7
|
import CustomFileCpu from "./file/customFileCpu.js";
|
|
8
8
|
import ValtheraMemory, { createMemoryValthera } from "./memory.js";
|
|
9
|
-
|
|
9
|
+
import { autoCreate } from "./autoCreate.js";
|
|
10
|
+
export { DataBase as Valthera, Graph, DataBaseRemote as ValtheraRemote, GraphRemote, Relation, genId, CustomFileCpu, ValtheraMemory, createMemoryValthera, autoCreate, };
|
package/package.json
CHANGED