@ -19,9 +19,6 @@ import {
FIELD_CREDENTIAL ,
FIELD_DATA ,
FIELD_USER ,
IDENTITY_ANONYMOUS ,
IDENTITY_IDENTIFIED ,
IDENTITY_NONE ,
REFRESH_STATUS_EXPIRED ,
REFRESH_STATUS_FAILED ,
REFRESH_STATUS_REFRESHED ,
@ -52,6 +49,7 @@ import {
hydrateSessionStorage ,
wireSessionStorageSync
} from './session-sync.ts' ;
import { computeSessionIdentity } from './session-identity.ts' ;
import { checkSessionInvariants , validateSessionCandidate } from './session-validation.ts' ;
import type {
AdoptResultField ,
@ -63,7 +61,6 @@ import type {
Session ,
SessionActor ,
SessionChange ,
SessionIdentityState ,
SessionListener
} from './types.ts' ;
@ -149,11 +146,6 @@ export function createEngineSession<TUser, TCredential = undefined, TData = unde
// ── State helpers ───────────────────────────────────────────────────────
function computeIdentity ( s : Snap | null ) : SessionIdentityState {
if ( s === null ) return IDENTITY_NONE ;
return s . user === null ? IDENTITY_ANONYMOUS : IDENTITY_IDENTIFIED ;
}
/ * *
* Apply a snapshot that came from outside this engine ( storage event ,
* BroadcastChannel ) . Dedups against the current snapshot so a storage
@ -164,10 +156,10 @@ export function createEngineSession<TUser, TCredential = undefined, TData = unde
function applyExternalChange ( next : Snap | null ) : void {
const prev = snapshot ;
if ( sameSnapshot ( prev , next ) ) return ;
const fromIdentity = compute Identity( prev ) ;
const fromIdentity = compute Session Identity( prev ) ;
generation += 1 ;
snapshot = next ;
const toIdentity = compute Identity( next ) ;
const toIdentity = compute Session Identity( next ) ;
dispatch ( {
event : EVENT_EXTERNAL_CHANGED ,
current : next ,
@ -210,11 +202,11 @@ export function createEngineSession<TUser, TCredential = undefined, TData = unde
event : typeof EVENT_ADOPTED | typeof EVENT_ADOPTED_SERVER | typeof EVENT_REFRESHED
) : void {
const prev = snapshot ;
const fromIdentity = compute Identity( prev ) ;
const fromIdentity = compute Session Identity( prev ) ;
generation += 1 ;
snapshot = next ;
persist ( next ) ;
const toIdentity = compute Identity( next ) ;
const toIdentity = compute Session Identity( next ) ;
dispatch ( {
event ,
current : next ,
@ -230,7 +222,7 @@ export function createEngineSession<TUser, TCredential = undefined, TData = unde
revoke? : RevokeResult
) : void {
const prev = snapshot ;
const fromIdentity = compute Identity( prev ) ;
const fromIdentity = compute Session Identity( prev ) ;
generation += 1 ;
snapshot = null ;
persist ( null ) ;
@ -239,7 +231,7 @@ export function createEngineSession<TUser, TCredential = undefined, TData = unde
current : null ,
previous : prev ,
generation ,
identity : { from : fromIdentity , to : IDENTITY_NONE } ,
identity : { from : fromIdentity , to : computeSessionIdentity( null ) } ,
revoke
} ) ;
broadcast ( event ) ;
@ -265,7 +257,7 @@ export function createEngineSession<TUser, TCredential = undefined, TData = unde
return generation ;
} ,
get identity() {
return compute Identity( snapshot ) ;
return compute Session Identity( snapshot ) ;
} ,
async adopt ( input ) {
@ -396,8 +388,8 @@ export function createEngineSession<TUser, TCredential = undefined, TData = unde
previous : snapshot ,
generation ,
identity : {
from : compute Identity( snapshot ) ,
to : compute Identity( snapshot )
from : compute Session Identity( snapshot ) ,
to : compute Session Identity( snapshot )
} ,
error : err
} ) ;
@ -511,7 +503,7 @@ export function createEngineSession<TUser, TCredential = undefined, TData = unde
if ( disposed ) return ( ) = > { } ;
listeners . add ( listener ) ;
try {
const identity = compute Identity( snapshot ) ;
const identity = compute Session Identity( snapshot ) ;
listener ( {
event : EVENT_INITIAL_SESSION ,
current : snapshot ,