SessionId
SessionId: (
value?) =>SessionId
Defined in: packages/protocol/src/lib/session.ts:10
Creates or brands a SessionId. Smart constructor — the identifier
SessionId refers to both the type (for type annotations) and the factory
(for runtime creation), exploiting TypeScript’s separate type/value namespaces.
- Called with no arguments: generates a new unique session ID with a
session-prefix for easy log grepping. - Called with an existing string: brands it as a SessionId without changing its value. Use this when the developer brings their own ID (DB row ID, user ID, persisted localStorage value, etc.) or when rehydrating from serialized data.
Parameters
Section titled “Parameters”value?
Section titled “value?”string
Returns
Section titled “Returns”Example
Section titled “Example”const fresh = SessionId(); // 'session-<nanoid>'const fromDb = SessionId(row.sessionId); // brands an existing id