@theshelf/filestore 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.
@@ -1,9 +1,7 @@
1
- import type { ConnectionState } from './definitions/constants.js';
2
1
  import type { Driver } from './definitions/interfaces.js';
3
2
  export default class FileStore implements Driver {
4
3
  #private;
5
4
  constructor(driver: Driver);
6
- get connectionState(): ConnectionState;
7
5
  get connected(): boolean;
8
6
  connect(): Promise<void>;
9
7
  disconnect(): Promise<void>;
package/dist/FileStore.js CHANGED
@@ -1,23 +1,16 @@
1
- import { ConnectionStates } from './definitions/constants.js';
2
- import ConnectionManager from './ConnectionManager.js';
3
1
  export default class FileStore {
4
2
  #driver;
5
- #connectionManager;
6
3
  constructor(driver) {
7
4
  this.#driver = driver;
8
- this.#connectionManager = new ConnectionManager(driver);
9
- }
10
- get connectionState() {
11
- return this.#connectionManager.state;
12
5
  }
13
6
  get connected() {
14
- return this.connectionState === ConnectionStates.CONNECTED;
7
+ return this.#driver.connected;
15
8
  }
16
9
  connect() {
17
- return this.#connectionManager.connect();
10
+ return this.#driver.connect();
18
11
  }
19
12
  disconnect() {
20
- return this.#connectionManager.disconnect();
13
+ return this.#driver.disconnect();
21
14
  }
22
15
  hasFile(path) {
23
16
  return this.#driver.hasFile(path);
@@ -18,23 +18,30 @@ export default class S3 {
18
18
  this.#client = new S3Client(this.#configuration);
19
19
  const buckets = await this.#client.send(new ListBucketsCommand({}));
20
20
  const bucketExists = buckets.Buckets?.some(bucket => bucket.Name === this.#bucketName);
21
- if (bucketExists === true)
22
- return;
23
- await this.#client.send(new CreateBucketCommand({ Bucket: this.#bucketName }));
21
+ if (bucketExists !== true) {
22
+ const createBucket = new CreateBucketCommand({ Bucket: this.#bucketName });
23
+ await this.#client.send(createBucket);
24
+ }
25
+ this.#connected = true;
24
26
  }
25
27
  catch (error) {
26
28
  const message = error instanceof Error ? error.message : UNKNOWN_ERROR;
27
29
  throw new FileStoreError('File store connection failed: ' + message);
28
30
  }
29
- this.#connected = true;
30
31
  }
31
32
  async disconnect() {
32
33
  if (this.#client === undefined) {
33
34
  throw new NotConnected();
34
35
  }
35
- this.#client.destroy();
36
- this.#client = undefined;
37
- this.#connected = false;
36
+ try {
37
+ this.#client.destroy();
38
+ this.#client = undefined;
39
+ this.#connected = false;
40
+ }
41
+ catch (error) {
42
+ const message = error instanceof Error ? error.message : UNKNOWN_ERROR;
43
+ throw new FileStoreError('File store disconnection failed: ' + message);
44
+ }
38
45
  }
39
46
  async hasFile(path) {
40
47
  const client = this.#getClient();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@theshelf/filestore",
3
3
  "private": false,
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "url": "git+https://github.com/MaskingTechnology/theshelf.git"
@@ -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
- }
@@ -1,7 +0,0 @@
1
- export declare const ConnectionStates: {
2
- readonly DISCONNECTED: "DISCONNECTED";
3
- readonly DISCONNECTING: "DISCONNECTING";
4
- readonly CONNECTING: "CONNECTING";
5
- readonly CONNECTED: "CONNECTED";
6
- };
7
- export type ConnectionState = typeof ConnectionStates[keyof typeof ConnectionStates];
@@ -1,6 +0,0 @@
1
- export const ConnectionStates = {
2
- DISCONNECTED: 'DISCONNECTED',
3
- DISCONNECTING: 'DISCONNECTING',
4
- CONNECTING: 'CONNECTING',
5
- CONNECTED: 'CONNECTED'
6
- };