marcidb-client 0.0.1 → 0.0.3
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/README.md +2 -2
- package/bin/marci-generate-linux-x64 +0 -0
- package/bin/marci-generate-win32-x64.exe +0 -0
- package/package.json +1 -1
- package/runtime/index.d.ts +3 -3
- package/runtime/index.js +13 -37
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ marci generate schema.marci node_modules/.marci/client
|
|
|
37
37
|
3. Start your MarciDB server and connect:
|
|
38
38
|
|
|
39
39
|
```typescript
|
|
40
|
-
import { marci } from "
|
|
40
|
+
import { marci } from "marcidb-client";
|
|
41
41
|
|
|
42
42
|
const db = marci("http://localhost:3000");
|
|
43
43
|
```
|
|
@@ -45,7 +45,7 @@ const db = marci("http://localhost:3000");
|
|
|
45
45
|
## Usage
|
|
46
46
|
|
|
47
47
|
```typescript
|
|
48
|
-
import { marci } from "
|
|
48
|
+
import { marci } from "marcidb-client";
|
|
49
49
|
|
|
50
50
|
const db = marci("http://localhost:3000");
|
|
51
51
|
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/runtime/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
3
|
-
export {
|
|
1
|
+
declare function request(method: string, url: string, body?: any);
|
|
2
|
+
declare function encodeId(id: any);
|
|
3
|
+
export { request, encodeId };
|
package/runtime/index.js
CHANGED
|
@@ -1,33 +1,15 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
body: body !== undefined ? JSON.stringify(body) : undefined
|
|
12
|
-
});
|
|
13
|
-
if (!res.ok) {
|
|
14
|
-
const text = await res.text();
|
|
15
|
-
throw new Error(`MarciDB [${res.status}]: ${text}`);
|
|
16
|
-
}
|
|
17
|
-
return res.json();
|
|
18
|
-
}
|
|
19
|
-
findMany(model, select) {
|
|
20
|
-
return this.#request("POST", `/${model}/findMany`, select);
|
|
21
|
-
}
|
|
22
|
-
insert(model, data) {
|
|
23
|
-
return this.#request("POST", `/${model}/insert`, data);
|
|
24
|
-
}
|
|
25
|
-
update(model, id, data) {
|
|
26
|
-
return this.#request("POST", `/${model}/update/${encodeId(id)}`, data);
|
|
27
|
-
}
|
|
28
|
-
delete(model, id) {
|
|
29
|
-
return this.#request("POST", `/${model}/delete/${encodeId(id)}`);
|
|
1
|
+
// src/index.ts
|
|
2
|
+
async function request(method, url, body) {
|
|
3
|
+
const res = await fetch(url, {
|
|
4
|
+
method,
|
|
5
|
+
headers: { "Content-Type": "application/json" },
|
|
6
|
+
body: body !== undefined ? JSON.stringify(body) : undefined
|
|
7
|
+
});
|
|
8
|
+
if (!res.ok) {
|
|
9
|
+
const text = await res.text();
|
|
10
|
+
throw new Error(`MarciDB [${res.status}]: ${text}`);
|
|
30
11
|
}
|
|
12
|
+
return res.json();
|
|
31
13
|
}
|
|
32
14
|
function encodeId(id) {
|
|
33
15
|
if (typeof id === "object" && id !== null) {
|
|
@@ -35,13 +17,7 @@ function encodeId(id) {
|
|
|
35
17
|
}
|
|
36
18
|
return String(id);
|
|
37
19
|
}
|
|
38
|
-
|
|
39
|
-
// src/index.ts
|
|
40
|
-
import { connect } from ".marci/client";
|
|
41
|
-
var marci = (url) => {
|
|
42
|
-
const client = new MarciClient(url);
|
|
43
|
-
return connect(client);
|
|
44
|
-
};
|
|
45
20
|
export {
|
|
46
|
-
|
|
21
|
+
request,
|
|
22
|
+
encodeId
|
|
47
23
|
};
|