@skein-js/storage-memory 0.2.1 → 0.3.0

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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SkeinStore, AssistantRepo, ThreadRepo, RunRepo, StoreRepo, Assistant, Thread, Run, RunKwargs, Item, RunEventBus, RunFrame, RunQueue, QueuedRun, RunProcessor, RunConsumerOptions, RunConsumer } from '@skein-js/core';
1
+ import { SkeinStore, AssistantRepo, ThreadRepo, RunRepo, StoreRepo, SkeinStoreSnapshot, RunEventBus, RunFrame, RunQueue, QueuedRun, RunProcessor, RunConsumerOptions, RunConsumer } from '@skein-js/core';
2
2
 
3
3
  /** In-process SkeinStore for development and tests. */
4
4
  declare class MemorySkeinStore implements SkeinStore {
@@ -14,15 +14,21 @@ declare class MemorySkeinStore implements SkeinStore {
14
14
  snapshot(): MemoryStoreSnapshot;
15
15
  /** Replace all rows with a {@link snapshot}. Used by `skein dev` to restore persisted dev state. */
16
16
  hydrate(snapshot: MemoryStoreSnapshot): void;
17
+ /**
18
+ * Bulk-load rows from a snapshot, preserving ids + timestamps and *without* clearing what's
19
+ * already here: existing ids are left untouched (insert-if-absent). Unlike {@link hydrate} (a
20
+ * full replace for cross-restart persistence), this is the additive, lossless sink used by
21
+ * migration tooling — see `@skein-js/express`'s LangGraph importer. `loadSnapshotIntoStore`
22
+ * feature-detects this method, so the memory and Postgres drivers import identically.
23
+ */
24
+ restore(snapshot: SkeinStoreSnapshot): Promise<void>;
17
25
  }
18
- /** A JSON-serializable copy of a {@link MemorySkeinStore}'s rows. */
19
- interface MemoryStoreSnapshot {
20
- assistants: [string, Assistant][];
21
- threads: [string, Thread][];
22
- runs: [string, Run][];
23
- runKwargs: [string, RunKwargs][];
24
- items: [string, Item][];
25
- }
26
+ /**
27
+ * A JSON-serializable copy of a {@link MemorySkeinStore}'s rows. An alias of the driver-agnostic
28
+ * {@link SkeinStoreSnapshot} (identical shape); the name predates the shared type and is kept so
29
+ * the dev-persistence snapshot format reads the same.
30
+ */
31
+ type MemoryStoreSnapshot = SkeinStoreSnapshot;
26
32
 
27
33
  /**
28
34
  * In-memory FIFO of background runs, drained by a single-process consumer — all `skein dev` needs.
package/dist/index.js CHANGED
@@ -208,6 +208,23 @@ var MemorySkeinStore = class {
208
208
  fill(this.#runKwargs, snapshot.runKwargs);
209
209
  fill(this.#items, snapshot.items);
210
210
  }
211
+ /**
212
+ * Bulk-load rows from a snapshot, preserving ids + timestamps and *without* clearing what's
213
+ * already here: existing ids are left untouched (insert-if-absent). Unlike {@link hydrate} (a
214
+ * full replace for cross-restart persistence), this is the additive, lossless sink used by
215
+ * migration tooling — see `@skein-js/express`'s LangGraph importer. `loadSnapshotIntoStore`
216
+ * feature-detects this method, so the memory and Postgres drivers import identically.
217
+ */
218
+ async restore(snapshot) {
219
+ const add = (map, rows) => {
220
+ for (const [id, row] of rows) if (!map.has(id)) map.set(id, clone(row));
221
+ };
222
+ add(this.#assistants, snapshot.assistants);
223
+ add(this.#threads, snapshot.threads);
224
+ add(this.#runs, snapshot.runs);
225
+ add(this.#runKwargs, snapshot.runKwargs);
226
+ add(this.#items, snapshot.items);
227
+ }
211
228
  };
212
229
 
213
230
  // src/memory-queue.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skein-js/storage-memory",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "In-memory SkeinStore + queue driver for development and tests.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Maina Wycliffe <wmmaina7@gmail.com>",
@@ -40,10 +40,10 @@
40
40
  "node": ">=20"
41
41
  },
42
42
  "dependencies": {
43
- "@skein-js/core": "0.2.1"
43
+ "@skein-js/core": "0.3.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@skein-js/test-support": "0.2.1"
46
+ "@skein-js/test-support": "0.3.0"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"