@theshelf/database 0.3.0 → 0.3.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/Database.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type { ConnectionState } from './definitions/constants.js';
|
|
2
1
|
import type { Driver } from './definitions/interfaces.js';
|
|
3
2
|
import type { RecordData, RecordField, RecordId, RecordQuery, RecordSort, RecordType } from './definitions/types.js';
|
|
4
3
|
export default class Database implements Driver {
|
|
5
4
|
#private;
|
|
6
5
|
constructor(driver: Driver);
|
|
7
|
-
get connectionState(): ConnectionState;
|
|
8
6
|
get connected(): boolean;
|
|
9
7
|
connect(): Promise<void>;
|
|
10
8
|
disconnect(): Promise<void>;
|
package/dist/Database.js
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import sanitize from './utilities/sanitize.js';
|
|
2
|
-
import { ConnectionStates } from './definitions/constants.js';
|
|
3
|
-
import ConnectionManager from './ConnectionManager.js';
|
|
4
2
|
export default class Database {
|
|
5
3
|
#driver;
|
|
6
|
-
#connectionManager;
|
|
7
4
|
constructor(driver) {
|
|
8
5
|
this.#driver = driver;
|
|
9
|
-
this.#connectionManager = new ConnectionManager(driver);
|
|
10
|
-
}
|
|
11
|
-
get connectionState() {
|
|
12
|
-
return this.#connectionManager.state;
|
|
13
6
|
}
|
|
14
7
|
get connected() {
|
|
15
|
-
return this.
|
|
8
|
+
return this.#driver.connected;
|
|
16
9
|
}
|
|
17
10
|
connect() {
|
|
18
|
-
return this.#
|
|
11
|
+
return this.#driver.connect();
|
|
19
12
|
}
|
|
20
13
|
disconnect() {
|
|
21
|
-
return this.#
|
|
14
|
+
return this.#driver.disconnect();
|
|
22
15
|
}
|
|
23
16
|
createRecord(type, data) {
|
|
24
17
|
const cleanData = sanitize(data);
|
|
@@ -20,10 +20,3 @@ export declare const QueryOperators: {
|
|
|
20
20
|
readonly STARTS_WITH: "STARTS_WITH";
|
|
21
21
|
readonly ENDS_WITH: "ENDS_WITH";
|
|
22
22
|
};
|
|
23
|
-
export declare const ConnectionStates: {
|
|
24
|
-
readonly DISCONNECTED: "DISCONNECTED";
|
|
25
|
-
readonly DISCONNECTING: "DISCONNECTING";
|
|
26
|
-
readonly CONNECTING: "CONNECTING";
|
|
27
|
-
readonly CONNECTED: "CONNECTED";
|
|
28
|
-
};
|
|
29
|
-
export type ConnectionState = typeof ConnectionStates[keyof typeof ConnectionStates];
|
|
@@ -20,9 +20,3 @@ export const QueryOperators = {
|
|
|
20
20
|
STARTS_WITH: 'STARTS_WITH', // "LIKE%"
|
|
21
21
|
ENDS_WITH: 'ENDS_WITH' // "%LIKE"
|
|
22
22
|
};
|
|
23
|
-
export const ConnectionStates = {
|
|
24
|
-
DISCONNECTED: 'DISCONNECTED',
|
|
25
|
-
DISCONNECTING: 'DISCONNECTING',
|
|
26
|
-
CONNECTING: 'CONNECTING',
|
|
27
|
-
CONNECTED: 'CONNECTED'
|
|
28
|
-
};
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ConnectionState } from './definitions/constants.js';
|
|
2
|
-
import type { Driver } from './definitions/interfaces.js';
|
|
3
|
-
export default class ConnectionManager {
|
|
4
|
-
#private;
|
|
5
|
-
constructor(driver: Driver);
|
|
6
|
-
get state(): ConnectionState;
|
|
7
|
-
connect(): Promise<void>;
|
|
8
|
-
disconnect(): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ConnectionStates } from './definitions/constants.js';
|
|
2
|
-
export default class ConnectionManager {
|
|
3
|
-
#driver;
|
|
4
|
-
#state = ConnectionStates.DISCONNECTED;
|
|
5
|
-
#connectPromise;
|
|
6
|
-
#disconnectPromise;
|
|
7
|
-
constructor(driver) {
|
|
8
|
-
this.#driver = driver;
|
|
9
|
-
}
|
|
10
|
-
get state() { return this.#state; }
|
|
11
|
-
async connect() {
|
|
12
|
-
if (this.#connectPromise !== undefined) {
|
|
13
|
-
return this.#connectPromise;
|
|
14
|
-
}
|
|
15
|
-
if (this.#state !== ConnectionStates.DISCONNECTED) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
this.#state = ConnectionStates.CONNECTING;
|
|
19
|
-
try {
|
|
20
|
-
this.#connectPromise = this.#driver.connect();
|
|
21
|
-
await this.#connectPromise;
|
|
22
|
-
this.#state = ConnectionStates.CONNECTED;
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
this.#state = ConnectionStates.DISCONNECTED;
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
finally {
|
|
29
|
-
this.#connectPromise = undefined;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async disconnect() {
|
|
33
|
-
if (this.#disconnectPromise !== undefined) {
|
|
34
|
-
return this.#disconnectPromise;
|
|
35
|
-
}
|
|
36
|
-
if (this.#state !== ConnectionStates.CONNECTED) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
this.#state = ConnectionStates.DISCONNECTING;
|
|
40
|
-
try {
|
|
41
|
-
this.#disconnectPromise = this.#driver.disconnect();
|
|
42
|
-
await this.#disconnectPromise;
|
|
43
|
-
this.#state = ConnectionStates.DISCONNECTED;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
this.#state = ConnectionStates.CONNECTED;
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
finally {
|
|
50
|
-
this.#disconnectPromise = undefined;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|