@morlay/session-rdb 0.0.15 → 0.0.16-alpha.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.
Files changed (65) hide show
  1. package/README.md +11 -13
  2. package/dist/artifact.d.mts +6 -16
  3. package/dist/artifact.mjs +3 -3
  4. package/dist/{import-DFed8DBt.mjs → import-CKrzjXVB.mjs} +73 -83
  5. package/dist/import.d.mts +2 -3
  6. package/dist/import.mjs +2 -2
  7. package/dist/index-CgGDHQSK.d.mts +225 -0
  8. package/dist/index.d.mts +3 -3
  9. package/dist/index.mjs +694 -169
  10. package/dist/log-DTJsxMud.mjs +314 -0
  11. package/dist/{schema-CFXZURX7.d.mts → schema-COK7-wRV.d.mts} +3 -15
  12. package/dist/sqlite-DCy4VTD8.mjs +698 -0
  13. package/dist/storage.d.mts +2 -7
  14. package/dist/storage.mjs +2 -3
  15. package/dist/testing.d.mts +30 -1
  16. package/dist/testing.mjs +676 -1991
  17. package/drizzle/postgres/20260908072805_v2_initial/migration.sql +58 -0
  18. package/drizzle/postgres/20260908072805_v2_initial/snapshot.json +686 -0
  19. package/drizzle/postgres/20260908072806_v3_drop_original_seq/migration.sql +1 -0
  20. package/drizzle/postgres/20260908072806_v3_drop_original_seq/snapshot.json +673 -0
  21. package/drizzle/sqlite/20260908072751_v2_initial/migration.sql +53 -0
  22. package/drizzle/sqlite/20260908072751_v2_initial/snapshot.json +492 -0
  23. package/drizzle/sqlite/20260908072752_v3_drop_original_seq/migration.sql +6 -0
  24. package/drizzle/sqlite/20260908072752_v3_drop_original_seq/snapshot.json +513 -0
  25. package/package.json +17 -12
  26. package/src/adapters/index.ts +10 -2
  27. package/src/adapters/to-postgres.ts +19 -15
  28. package/src/adapters/to-sqlite.ts +20 -14
  29. package/src/{entities → adapters}/types.ts +7 -8
  30. package/src/backend.ts +0 -7
  31. package/src/branch.ts +29 -110
  32. package/src/drizzle/postgres-v2.ts +11 -0
  33. package/src/drizzle/postgres-v3.ts +11 -0
  34. package/src/drizzle/sqlite-v2.ts +10 -0
  35. package/src/drizzle/sqlite-v3.ts +11 -0
  36. package/src/entities/index.ts +2 -30
  37. package/src/entities/v2/index.ts +20 -0
  38. package/src/entities/v2/session-events.ts +11 -0
  39. package/src/entities/v3/events.ts +27 -0
  40. package/src/entities/v3/index.ts +27 -0
  41. package/src/entities/v3/persistence-state.ts +10 -0
  42. package/src/entities/v3/schema-meta.ts +9 -0
  43. package/src/entities/v3/session-events.ts +26 -0
  44. package/src/entities/v3/sessions.ts +20 -0
  45. package/src/import.ts +65 -57
  46. package/src/index.ts +868 -223
  47. package/src/invariant.ts +0 -2
  48. package/src/legacy.ts +67 -0
  49. package/src/log.ts +41 -87
  50. package/src/postgres.ts +75 -93
  51. package/src/schema.ts +3 -14
  52. package/src/sqlite.ts +59 -46
  53. package/src/testing/contract.ts +460 -375
  54. package/src/testing/coordinator-contract.ts +108 -1374
  55. package/src/testing.ts +1 -6
  56. package/dist/index-uUvn6gYp.d.mts +0 -111
  57. package/dist/schema-vwzwEXNE.mjs +0 -878
  58. package/dist/sqlite-CG_Qcx5C.mjs +0 -356
  59. package/src/adapters/ddl.ts +0 -77
  60. package/src/entities/events.ts +0 -27
  61. package/src/entities/persistence-state.ts +0 -10
  62. package/src/entities/schema-meta.ts +0 -9
  63. package/src/entities/session-events.ts +0 -29
  64. package/src/entities/sessions.ts +0 -20
  65. package/src/migrate.ts +0 -137
@@ -1,4 +1,4 @@
1
- import { _ as WriteGuard, a as EventRole, b as EventRow, c as SESSION_PERSISTENCE_SQLITE_APPLICATION_ID, d as isEphemeralType, f as isPersistedEvent, g as tSessions, h as tSessionEvents, i as EventKind, l as eventDimensions, m as tPersistenceState, n as EPHEMERAL_EVENT_TYPES, o as JournalMode, p as tEvents, r as EVENT_ENCODING, s as SCHEMA_VERSION, t as DEFAULT_BUSY_TIMEOUT_MS, u as eventKind, v as Backend, x as SessionRow, y as BackendTx } from "./schema-CFXZURX7.mjs";
1
+ import { _ as BackendTx, a as JournalMode, c as eventDimensions, d as tPersistenceState, f as tSchemaMeta, g as Backend, h as WriteGuard, i as EventRole, l as eventKind, m as tSessions, n as EVENT_ENCODING, o as SCHEMA_VERSION, p as tSessionEvents, r as EventKind, s as SESSION_PERSISTENCE_SQLITE_APPLICATION_ID, t as DEFAULT_BUSY_TIMEOUT_MS, u as tEvents, v as EventRow, y as SessionRow } from "./schema-COK7-wRV.mjs";
2
2
  import { SessionId } from "@deepseek-ai/dsh-session";
3
3
  import { DatabaseSync } from "node:sqlite";
4
4
  //#region src/sqlite.d.ts
@@ -18,10 +18,6 @@ declare class SqliteBackend implements Backend {
18
18
  open(): Promise<void>;
19
19
  close(): Promise<void>;
20
20
  getSession(id: SessionId): Promise<SessionRow | undefined>;
21
- getSeqMapRows(id: SessionId): Promise<Array<{
22
- fSequence: number;
23
- fOriginalSeq: number;
24
- }>>;
25
21
  getEventRows(id: SessionId, fromSequence?: number): Promise<EventRow[]>;
26
22
  listSessions(): Promise<SessionRow[]>;
27
23
  transaction<T>(fn: (tx: BackendTx) => Promise<T>): Promise<T>;
@@ -37,8 +33,7 @@ declare class SqliteBackend implements Backend {
37
33
  private bumpRevision;
38
34
  private deleteBridgeTail;
39
35
  private getPrevBridge;
40
- private getLastBridge;
41
36
  private eventRows;
42
37
  }
43
38
  //#endregion
44
- export { DEFAULT_BUSY_TIMEOUT_MS, EPHEMERAL_EVENT_TYPES, EVENT_ENCODING, EventKind, EventRole, type EventRow, JournalMode, SCHEMA_VERSION, SESSION_PERSISTENCE_SQLITE_APPLICATION_ID, type SessionRow, SqliteBackend, SqliteBackendOptions, WriteGuard, eventDimensions, eventKind, isEphemeralType, isPersistedEvent, openDatabase, tEvents, tPersistenceState, tSessionEvents, tSessions };
39
+ export { DEFAULT_BUSY_TIMEOUT_MS, EVENT_ENCODING, EventKind, EventRole, type EventRow, JournalMode, SCHEMA_VERSION, SESSION_PERSISTENCE_SQLITE_APPLICATION_ID, type SessionRow, SqliteBackend, SqliteBackendOptions, WriteGuard, eventDimensions, eventKind, openDatabase, tEvents, tPersistenceState, tSchemaMeta, tSessionEvents, tSessions };
package/dist/storage.mjs CHANGED
@@ -1,3 +1,2 @@
1
- import { i as WriteGuard, n as openDatabase, t as SqliteBackend } from "./sqlite-CG_Qcx5C.mjs";
2
- import { a as SESSION_PERSISTENCE_SQLITE_APPLICATION_ID, c as isEphemeralType, d as tPersistenceState, f as tSessionEvents, i as SCHEMA_VERSION, l as isPersistedEvent, n as EPHEMERAL_EVENT_TYPES, o as eventDimensions, p as tSessions, r as EVENT_ENCODING, s as eventKind, t as DEFAULT_BUSY_TIMEOUT_MS, u as tEvents } from "./schema-vwzwEXNE.mjs";
3
- export { DEFAULT_BUSY_TIMEOUT_MS, EPHEMERAL_EVENT_TYPES, EVENT_ENCODING, SCHEMA_VERSION, SESSION_PERSISTENCE_SQLITE_APPLICATION_ID, SqliteBackend, WriteGuard, eventDimensions, eventKind, isEphemeralType, isPersistedEvent, openDatabase, tEvents, tPersistenceState, tSessionEvents, tSessions };
1
+ import { a as SCHEMA_VERSION, c as eventKind, d as tSchemaMeta, f as tSessionEvents, g as WriteGuard, i as EVENT_ENCODING, l as tEvents, n as openDatabase, o as SESSION_PERSISTENCE_SQLITE_APPLICATION_ID, p as tSessions, r as DEFAULT_BUSY_TIMEOUT_MS, s as eventDimensions, t as SqliteBackend, u as tPersistenceState } from "./sqlite-DCy4VTD8.mjs";
2
+ export { DEFAULT_BUSY_TIMEOUT_MS, EVENT_ENCODING, SCHEMA_VERSION, SESSION_PERSISTENCE_SQLITE_APPLICATION_ID, SqliteBackend, WriteGuard, eventDimensions, eventKind, openDatabase, tEvents, tPersistenceState, tSchemaMeta, tSessionEvents, tSessions };
@@ -11,13 +11,37 @@ declare class EmptySettings extends SettingsProvider {
11
11
  }
12
12
  //#endregion
13
13
  //#region src/testing/contract.d.ts
14
- interface ContractBackend {
14
+ /** One backend service instance under test plus its teardown. */
15
+ interface ContractBackendInstance {
15
16
  persistence: SessionPersistence;
16
17
  dispose: () => Promise<void>;
17
18
  }
19
+ /** A backend under test: the primary instance plus optional storage-level capabilities. */
20
+ interface ContractBackend extends ContractBackendInstance {
21
+ /**
22
+ * Open a FRESH backend instance over the SAME storage, as another process
23
+ * would after this one exits. Enables the cross-instance visibility and
24
+ * reopen-continuation tests; a backend without shared storage omits it and
25
+ * those tests self-skip.
26
+ */
27
+ reopen?: () => Promise<ContractBackendInstance>;
28
+ /**
29
+ * Inject a torn physical tail after the committed log of one stored session,
30
+ * simulating a crash mid-write. Enables the torn-tail tests.
31
+ */
32
+ corruptTail?: (id: SessionId, cwd: string | undefined) => Promise<void>;
33
+ }
34
+ /** Build a minimal {@link SessionHeader} for a session id. */
18
35
  declare function meta(id: string, cwd?: string): SessionHeader;
36
+ /** A well-formed one-turn event log (contiguous seqs from 0). */
19
37
  declare function oneTurnLog(): SessionEvent[];
20
38
  declare function appendLog(session: Session, events: readonly SessionEvent[]): void;
39
+ /**
40
+ * Run the backend-agnostic handle contract suite. `make()` MUST return a
41
+ * fresh backend over fresh, empty storage each call.
42
+ * @param name - suite label, e.g. `jsonl-none` / `sqlite`.
43
+ * @param make - factory producing one fresh {@link ContractBackend} per test.
44
+ */
21
45
  declare function runPersistenceContract(name: string, make: () => Promise<ContractBackend>): void;
22
46
  //#endregion
23
47
  //#region src/testing/coordinator-contract.d.ts
@@ -26,6 +50,11 @@ interface CoordinatorFixture {
26
50
  corruptTail?: (id: SessionId, cwd: string | undefined) => Promise<void>;
27
51
  cleanup: () => Promise<void>;
28
52
  }
53
+ /**
54
+ * RDB 特有行为契约:live 会话驱动持久化、seed 边界、fork/resume、HMR
55
+ * dispose drain、冲突拒绝、torn-tail。coordinator 内部状态(ownerless /
56
+ * per-id chain / legacy 迁移)已由新版 handle 模型承担,不再单独测试。
57
+ */
29
58
  declare function runCoordinatorContract(name: string, makeFixture: () => Promise<CoordinatorFixture>): void;
30
59
  //#endregion
31
60
  export { type ContractBackend, type CoordinatorFixture, EmptySettings, appendLog, meta, oneTurnLog, runCoordinatorContract, runPersistenceContract };