@spexcode/session-application 0.6.8
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 +17 -0
- package/dist/index.js +35 -0
- package/dist/migration.d.ts +51 -0
- package/dist/migration.js +694 -0
- package/dist/production.d.ts +109 -0
- package/dist/production.js +438 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +39 -0
- package/package.json +29 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Message, MessageInput, SessionProtocol } from '@spexcode/session-protocol';
|
|
2
|
+
import type { SessionTopology, TopologyEdge } from '@spexcode/session-topology';
|
|
3
|
+
export interface NotificationResult {
|
|
4
|
+
edge: TopologyEdge | null;
|
|
5
|
+
recipients: string[];
|
|
6
|
+
messages: Message[];
|
|
7
|
+
}
|
|
8
|
+
export interface SessionApplication {
|
|
9
|
+
notifyRecipients(subjectSessionId: string, message: MessageInput): NotificationResult;
|
|
10
|
+
attachAndNotify(fromSessionId: string, subjectSessionId: string, relationType: string, message: MessageInput): NotificationResult;
|
|
11
|
+
}
|
|
12
|
+
export declare function openSessionApplication(protocol: SessionProtocol, topology: SessionTopology): SessionApplication;
|
|
13
|
+
export { openProjectSessionApplication } from './production.js';
|
|
14
|
+
export { jsonMigrationFencePath, legacyResidueExists, migrateJsonSessionRecords, MIGRATED_MESSAGE_EVENT, MIGRATED_STATE_EVENT } from './migration.js';
|
|
15
|
+
export type { CommittedSessionChange, ConversationMessageInput, CreateSessionInput, LocalityPrecondition, NativeRuntimeIdentity, ProductionSessionApplication, ProjectSessionApplicationOptions, SessionState, SessionStateChange, TransitionSessionInput, } from './production.js';
|
|
16
|
+
export type { SessionEvent } from '@spexcode/session-events';
|
|
17
|
+
export type { JsonMigrationRecord, JsonResidueMigrationReport, JsonSessionMigrationOptions, JsonSessionMigrationReport, } from './migration.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function enqueueForRecipients(tx, topology, subjectSessionId, message) {
|
|
2
|
+
const recipients = topology.recipients(subjectSessionId, tx);
|
|
3
|
+
const messages = recipients.map(recipient => tx.enqueue(recipient, {
|
|
4
|
+
...message,
|
|
5
|
+
senderSessionId: message.senderSessionId === undefined
|
|
6
|
+
? subjectSessionId
|
|
7
|
+
: message.senderSessionId,
|
|
8
|
+
}));
|
|
9
|
+
return { edge: null, recipients, messages };
|
|
10
|
+
}
|
|
11
|
+
export function openSessionApplication(protocol, topology) {
|
|
12
|
+
if (!protocol || typeof protocol.withTransaction !== 'function') {
|
|
13
|
+
throw new TypeError('session application requires a live protocol handle');
|
|
14
|
+
}
|
|
15
|
+
if (!topology || typeof topology.recipients !== 'function' || typeof topology.attach !== 'function') {
|
|
16
|
+
throw new TypeError('session application requires a live topology handle');
|
|
17
|
+
}
|
|
18
|
+
const run = (subjectSessionId, message, edge, tx) => {
|
|
19
|
+
const result = enqueueForRecipients(tx, topology, subjectSessionId, message);
|
|
20
|
+
return { ...result, edge };
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
notifyRecipients(subjectSessionId, message) {
|
|
24
|
+
return protocol.withTransaction(tx => run(subjectSessionId, message, null, tx));
|
|
25
|
+
},
|
|
26
|
+
attachAndNotify(fromSessionId, subjectSessionId, relationType, message) {
|
|
27
|
+
return protocol.withTransaction(tx => {
|
|
28
|
+
const edge = topology.attach(tx, fromSessionId, subjectSessionId, relationType);
|
|
29
|
+
return run(subjectSessionId, message, edge, tx);
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export { openProjectSessionApplication } from './production.js';
|
|
35
|
+
export { jsonMigrationFencePath, legacyResidueExists, migrateJsonSessionRecords, MIGRATED_MESSAGE_EVENT, MIGRATED_STATE_EVENT } from './migration.js';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type LocalityPrecondition, type ProductionSessionApplication } from './production.js';
|
|
2
|
+
/** Migrated legacy history keeps the live payload shapes under its own ignorable types: a timeline projection
|
|
3
|
+
* shows it beside live events, while state replay (which knows only the live types) skips it as history. */
|
|
4
|
+
export declare const MIGRATED_STATE_EVENT = "session.state.migrated.v1";
|
|
5
|
+
export declare const MIGRATED_MESSAGE_EVENT = "session.message.migrated.v1";
|
|
6
|
+
export interface JsonMigrationRecord {
|
|
7
|
+
session_id: string;
|
|
8
|
+
status: string;
|
|
9
|
+
parent?: string | null;
|
|
10
|
+
createdAt?: number;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface JsonSessionMigrationOptions {
|
|
14
|
+
databasePath: string;
|
|
15
|
+
recordsRoot: string;
|
|
16
|
+
locality: LocalityPrecondition;
|
|
17
|
+
backupRoot?: string;
|
|
18
|
+
now?: () => number;
|
|
19
|
+
orphanParentPolicy?: 'fail' | 'tombstone';
|
|
20
|
+
/** A caller that already owns the open canonical application lends it for residue import; otherwise the
|
|
21
|
+
* importer opens and closes its own handle. */
|
|
22
|
+
application?: ProductionSessionApplication;
|
|
23
|
+
}
|
|
24
|
+
/** The durable fence shared by the one-time importer and legacy JSON writers. */
|
|
25
|
+
export declare function jsonMigrationFencePath(recordsRoot: string): string;
|
|
26
|
+
export interface JsonResidueMigrationReport {
|
|
27
|
+
sourceDigest: string;
|
|
28
|
+
records: number;
|
|
29
|
+
events: number;
|
|
30
|
+
parentEdges: number;
|
|
31
|
+
watchEdges: number;
|
|
32
|
+
pending: number;
|
|
33
|
+
unclaimed: string[];
|
|
34
|
+
backupRoot: string;
|
|
35
|
+
}
|
|
36
|
+
export interface JsonSessionMigrationReport {
|
|
37
|
+
version: number;
|
|
38
|
+
sourceDigest: string;
|
|
39
|
+
records: number;
|
|
40
|
+
parentEdges: number;
|
|
41
|
+
watchEdges: number;
|
|
42
|
+
events: number;
|
|
43
|
+
orphanParents: string[];
|
|
44
|
+
backupRoot: string;
|
|
45
|
+
markerPath: string;
|
|
46
|
+
replayed: boolean;
|
|
47
|
+
residue?: JsonResidueMigrationReport;
|
|
48
|
+
}
|
|
49
|
+
/** Whether the legacy tree still holds anything the canonical store must absorb before the tree is retired. */
|
|
50
|
+
export declare function legacyResidueExists(recordsRoot: string): boolean;
|
|
51
|
+
export declare function migrateJsonSessionRecords(options: JsonSessionMigrationOptions): JsonSessionMigrationReport;
|