@hardkas/sessions 0.7.1-alpha → 0.7.4-alpha

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.
Files changed (2) hide show
  1. package/dist/index.js +29 -20
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -23,7 +23,10 @@ function loadSessionStoreWithDiagnostics(cwd = process.cwd()) {
23
23
  try {
24
24
  raw = JSON.parse(readFileSync(path, "utf-8"));
25
25
  } catch (e) {
26
- return { store: { sessions: {} }, diagnostics: [`Malformed JSON in ${SESSION_FILE}`] };
26
+ return {
27
+ store: { sessions: {} },
28
+ diagnostics: [`Malformed JSON in ${SESSION_FILE}`]
29
+ };
27
30
  }
28
31
  const diagnostics = [];
29
32
  if (!raw || typeof raw !== "object") {
@@ -65,28 +68,34 @@ async function saveSessionStore(store, cwd = process.cwd()) {
65
68
  });
66
69
  }
67
70
  async function createSession(session, cwd = process.cwd()) {
68
- await withLock({ rootDir: cwd, name: "workspace", wait: true, timeoutMs: 5e3 }, async () => {
69
- const store = loadSessionStoreStrict(cwd);
70
- const newStore = {
71
- ...store,
72
- sessions: {
73
- ...store.sessions,
74
- [session.name]: session
75
- },
76
- activeSession: store.activeSession || session.name
77
- };
78
- await saveSessionStore(newStore, cwd);
79
- });
71
+ await withLock(
72
+ { rootDir: cwd, name: "workspace", wait: true, timeoutMs: 5e3 },
73
+ async () => {
74
+ const store = loadSessionStoreStrict(cwd);
75
+ const newStore = {
76
+ ...store,
77
+ sessions: {
78
+ ...store.sessions,
79
+ [session.name]: session
80
+ },
81
+ activeSession: store.activeSession || session.name
82
+ };
83
+ await saveSessionStore(newStore, cwd);
84
+ }
85
+ );
80
86
  }
81
87
  async function setActiveSession(name, cwd = process.cwd()) {
82
- await withLock({ rootDir: cwd, name: "workspace", wait: true, timeoutMs: 5e3 }, async () => {
83
- const store = loadSessionStoreStrict(cwd);
84
- if (!store.sessions[name]) {
85
- throw new Error(`Session "${name}" not found.`);
88
+ await withLock(
89
+ { rootDir: cwd, name: "workspace", wait: true, timeoutMs: 5e3 },
90
+ async () => {
91
+ const store = loadSessionStoreStrict(cwd);
92
+ if (!store.sessions[name]) {
93
+ throw new Error(`Session "${name}" not found.`);
94
+ }
95
+ const newStore = { ...store, activeSession: name };
96
+ await saveSessionStore(newStore, cwd);
86
97
  }
87
- const newStore = { ...store, activeSession: name };
88
- await saveSessionStore(newStore, cwd);
89
- });
98
+ );
90
99
  }
91
100
  function getActiveSession(cwd = process.cwd()) {
92
101
  const store = loadSessionStore(cwd);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardkas/sessions",
3
- "version": "0.7.1-alpha",
3
+ "version": "0.7.4-alpha",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  ".": "./dist/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@hardkas/core": "0.7.1-alpha"
11
+ "@hardkas/core": "0.7.4-alpha"
12
12
  },
13
13
  "devDependencies": {
14
14
  "tsup": "^8.3.5",