@petradb/client 1.0.1 → 1.2.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/README.md +14 -58
- package/main.js +79845 -0
- package/package.json +11 -15
- package/dist/index.d.ts +0 -25
- package/dist/index.js +0 -51
package/package.json
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@petradb/client",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"description": "PetraDB network client for JavaScript and TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"types": "./
|
|
9
|
-
"default": "./
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"default": "./main.js"
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
|
-
"main": "
|
|
13
|
-
"types": "
|
|
12
|
+
"main": "main.js",
|
|
13
|
+
"types": "index.d.ts",
|
|
14
14
|
"files": [
|
|
15
|
-
"
|
|
15
|
+
"main.js",
|
|
16
|
+
"index.d.ts",
|
|
16
17
|
"README.md"
|
|
17
18
|
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build": "tsc"
|
|
20
|
-
},
|
|
21
19
|
"repository": {
|
|
22
20
|
"type": "git",
|
|
23
21
|
"url": "git+https://github.com/edadma/petradb.git"
|
|
@@ -26,15 +24,13 @@
|
|
|
26
24
|
"SQL",
|
|
27
25
|
"database",
|
|
28
26
|
"client",
|
|
29
|
-
"
|
|
27
|
+
"javascript",
|
|
28
|
+
"typescript"
|
|
30
29
|
],
|
|
31
30
|
"author": "Edward A. Maxedon, Sr.",
|
|
32
31
|
"license": "ISC",
|
|
33
32
|
"bugs": {
|
|
34
33
|
"url": "https://github.com/edadma/petradb/issues"
|
|
35
34
|
},
|
|
36
|
-
"homepage": "https://
|
|
37
|
-
"devDependencies": {
|
|
38
|
-
"typescript": "^5.9.3"
|
|
39
|
-
}
|
|
35
|
+
"homepage": "https://petradb.dev"
|
|
40
36
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface SessionOptions {
|
|
2
|
-
host?: string;
|
|
3
|
-
port?: number;
|
|
4
|
-
rowMode?: "object" | "array";
|
|
5
|
-
}
|
|
6
|
-
export interface ExecuteOptions {
|
|
7
|
-
rowMode?: "object" | "array";
|
|
8
|
-
}
|
|
9
|
-
export interface FieldInfo {
|
|
10
|
-
name: string;
|
|
11
|
-
dataType: string;
|
|
12
|
-
}
|
|
13
|
-
export interface ExecuteResult {
|
|
14
|
-
command: string;
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
}
|
|
17
|
-
export declare class Session {
|
|
18
|
-
private baseUrl;
|
|
19
|
-
private defaultRowMode;
|
|
20
|
-
private sessionId;
|
|
21
|
-
constructor(options?: SessionOptions);
|
|
22
|
-
execute(sql: string, options?: ExecuteOptions): Promise<ExecuteResult[]>;
|
|
23
|
-
connect(): Promise<void>;
|
|
24
|
-
close(): Promise<void>;
|
|
25
|
-
}
|
package/dist/index.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export class Session {
|
|
2
|
-
constructor(options = {}) {
|
|
3
|
-
this.sessionId = null;
|
|
4
|
-
const host = options.host ?? "localhost";
|
|
5
|
-
const port = options.port ?? 5432;
|
|
6
|
-
this.baseUrl = `http://${host}:${port}`;
|
|
7
|
-
this.defaultRowMode = options.rowMode ?? "object";
|
|
8
|
-
}
|
|
9
|
-
async execute(sql, options) {
|
|
10
|
-
const rowMode = options?.rowMode ?? this.defaultRowMode;
|
|
11
|
-
const headers = {
|
|
12
|
-
"Content-Type": "application/json",
|
|
13
|
-
};
|
|
14
|
-
if (this.sessionId) {
|
|
15
|
-
headers["X-Session-Id"] = this.sessionId;
|
|
16
|
-
}
|
|
17
|
-
const res = await fetch(`${this.baseUrl}/sql`, {
|
|
18
|
-
method: "POST",
|
|
19
|
-
headers,
|
|
20
|
-
body: JSON.stringify({ sql, rowMode }),
|
|
21
|
-
});
|
|
22
|
-
if (!res.ok) {
|
|
23
|
-
const body = await res.text();
|
|
24
|
-
throw new Error(body || `HTTP ${res.status}`);
|
|
25
|
-
}
|
|
26
|
-
return (await res.json());
|
|
27
|
-
}
|
|
28
|
-
async connect() {
|
|
29
|
-
const res = await fetch(`${this.baseUrl}/session`, {
|
|
30
|
-
method: "POST",
|
|
31
|
-
});
|
|
32
|
-
if (!res.ok) {
|
|
33
|
-
const body = await res.text();
|
|
34
|
-
throw new Error(body || `HTTP ${res.status}`);
|
|
35
|
-
}
|
|
36
|
-
const data = (await res.json());
|
|
37
|
-
this.sessionId = data.sessionId;
|
|
38
|
-
}
|
|
39
|
-
async close() {
|
|
40
|
-
if (!this.sessionId)
|
|
41
|
-
return;
|
|
42
|
-
const res = await fetch(`${this.baseUrl}/session/${this.sessionId}`, {
|
|
43
|
-
method: "DELETE",
|
|
44
|
-
});
|
|
45
|
-
if (!res.ok) {
|
|
46
|
-
const body = await res.text();
|
|
47
|
-
throw new Error(body || `HTTP ${res.status}`);
|
|
48
|
-
}
|
|
49
|
-
this.sessionId = null;
|
|
50
|
-
}
|
|
51
|
-
}
|