@tmcp/session-manager 0.1.0 → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @tmcp/session-manager
2
+
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - c0f7d7f: fix: try catch closing controller in case it's already closed
8
+
9
+ ## 0.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 957805b: fix: await session manager calls
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmcp/session-manager",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "repository": {
package/src/index.js CHANGED
@@ -8,6 +8,7 @@ export class SessionManager {
8
8
  * @abstract
9
9
  * @param {string} id
10
10
  * @param {ReadableStreamDefaultController} controller
11
+ * @returns {void | Promise<void>}
11
12
  */
12
13
  create(id, controller) {
13
14
  throw new Error('Method not implemented.');
@@ -16,6 +17,7 @@ export class SessionManager {
16
17
  /**
17
18
  * @abstract
18
19
  * @param {string} id
20
+ * @returns {void | Promise<void>}
19
21
  */
20
22
  delete(id) {
21
23
  throw new Error('Method not implemented.');
@@ -24,7 +26,7 @@ export class SessionManager {
24
26
  /**
25
27
  * @abstract
26
28
  * @param {string} id
27
- * @returns {Promise<boolean>}
29
+ * @returns {boolean | Promise<boolean>}
28
30
  */
29
31
  has(id) {
30
32
  throw new Error('Method not implemented.');
@@ -34,6 +36,7 @@ export class SessionManager {
34
36
  * @abstract
35
37
  * @param {string[] | undefined} sessions
36
38
  * @param {string} data
39
+ * @returns {void | Promise<void>}
37
40
  */
38
41
  send(sessions, data) {
39
42
  throw new Error('Method not implemented.');
@@ -61,8 +64,12 @@ export class InMemorySessionManager extends SessionManager {
61
64
  delete(id) {
62
65
  const controller = this.#sessions.get(id);
63
66
  if (controller) {
64
- controller.close();
65
67
  this.#sessions.delete(id);
68
+ try {
69
+ controller.close();
70
+ } catch {
71
+ // could error if the controller is already closed
72
+ }
66
73
  }
67
74
  }
68
75
 
@@ -6,21 +6,28 @@ declare module '@tmcp/session-manager' {
6
6
  /**
7
7
  * @abstract
8
8
  * */
9
- abstract create(id: string, controller: ReadableStreamDefaultController): void;
9
+ abstract create(id: string, controller: ReadableStreamDefaultController): void | Promise<void>;
10
10
  /**
11
11
  * @abstract
12
12
  * */
13
- abstract delete(id: string): void;
13
+ abstract delete(id: string): void | Promise<void>;
14
14
  /**
15
15
  * @abstract
16
16
  * */
17
- abstract has(id: string): Promise<boolean>;
17
+ abstract has(id: string): boolean | Promise<boolean>;
18
18
  /**
19
19
  * @abstract
20
20
  * */
21
- abstract send(sessions: string[] | undefined, data: string): void;
21
+ abstract send(sessions: string[] | undefined, data: string): void | Promise<void>;
22
22
  }
23
23
  export class InMemorySessionManager extends SessionManager {
24
+ create(id: string, controller: ReadableStreamDefaultController): void;
25
+ delete(id: string): void;
26
+ /**
27
+ * @abstract
28
+ * */
29
+ abstract has(id: string): Promise<boolean>;
30
+ send(sessions: string[] | undefined, data: string): void;
24
31
  #private;
25
32
  }
26
33
  export {};
@@ -11,6 +11,6 @@
11
11
  "sourcesContent": [
12
12
  null
13
13
  ],
14
- "mappings": ";;;;cAKaA,cAAcA;;;;;;;;;;;;;;;;;;cAqCdC,sBAAsBA",
14
+ "mappings": ";;;;cAKaA,cAAcA;;;;;;;;;;;;;;;;;;cAwCdC,sBAAsBA",
15
15
  "ignoreList": []
16
16
  }