Immutable Store API
Store versioned explicit records and read their history. Immutable record IDs/version selectors do not grant authority. Destructive purge is a separate authorized administration operation and must account for retained references.
Usage boundary
Access the namespace on an explicitly configured root Cortex client. Host JWT and deployment-operator transports are distinct; validate current resource scope and do not infer authority from AuthContext metadata. See administrative operations.
Versioned records
store({ type, id, data, ... }) creates the record or adds a retained version for the same type/id. Supply structured data, optional owner and metadata; the return includes current version, timestamps and retained previous versions. It does not mutate the historical payload in place. get returns the latest ImmutableRecord or null. getVersion returns expanded version data or null, and getAtTimestamp accepts a millisecond timestamp or Date, returning the retained state at that time. Purged versions cannot be recovered through these calls.
list accepts type/owner/limit and returns an array of current entries. The SDK does not expose a cursor envelope for this method. search takes query/type/user/limit and returns matching entries with match information; count counts the selected records. For protected runtime scopes, these low-level IDs remain selectors and current read/write authority is required.
import type { Cortex } from '@cortexmemory/sdk';
export async function saveApprovedPolicy(cortex: Cortex) {
const first = await cortex.immutable.store({ type: 'delivery-policy', id: 'window',
data: { day: 'Tuesday' }, userId: 'user-123' });
const second = await cortex.immutable.store({ type: 'delivery-policy', id: 'window',
data: { day: 'Wednesday' }, userId: 'user-123' });
const original = await cortex.immutable.getVersion('delivery-policy', 'window', first.version);
const history = await cortex.immutable.getHistory('delivery-policy', 'window');
return { currentVersion: second.version, original, history };
}
purge removes an entry and all its retained versions, returning deleted and versionsDeleted. purgeVersions(type, id, keepLatest) removes older versions while reporting versionsPurged and versionsRemaining; validate the retention count before using it. purgeMany reports each removed type/id and total retained-version count. These destructive operations require the appropriate administrative scope and are not reversible history edits.
Parameter and result contracts
These are reference definitions for the explicit server APIs. Optional fields use ?; timestamps are milliseconds since epoch unless an operation accepts a Date. Resource identifiers and participant metadata do not grant runtime authority.
ImmutableEntry
export interface ImmutableEntry extends GraphCaptureMetadata {
type: string;
id: string;
data: Record<string, unknown>;
userId?: string;
metadata?: {
publishedBy?: string;
tags?: string[];
importance?: number;
[key: string]: unknown;
};
}
Also inherits GraphCaptureMetadata. See shared contracts.
ImmutableRecord
export interface ImmutableRecord {
_id: string;
type: string;
id: string;
data: Record<string, unknown>;
tenantId?: string;
userId?: string;
version: number;
previousVersions: ImmutableVersion[];
metadata?: {
publishedBy?: string;
tags?: string[];
importance?: number;
[key: string]: unknown;
};
createdAt: number;
updatedAt: number;
}
ImmutableVersionExpanded
export interface ImmutableVersionExpanded {
type: string;
id: string;
version: number;
data: Record<string, unknown>;
userId?: string;
metadata?: Record<string, unknown>;
timestamp: number;
createdAt: number;
}
ListImmutableFilter
export interface ListImmutableFilter {
type?: string;
userId?: string;
tenantId?: string;
limit?: number;
}
SearchImmutableInput
export interface SearchImmutableInput {
query: string;
type?: string;
userId?: string;
limit?: number;
}
ImmutableSearchResult
export interface ImmutableSearchResult {
entry: ImmutableRecord;
score: number;
highlights: string[];
}
CountImmutableFilter
export interface CountImmutableFilter {
type?: string;
userId?: string;
tenantId?: string;
}
Public methods
The following signatures describe the TypeScript namespace. Parameter and result fields are defined on this page; the installed @cortexmemory/sdk declarations also provide their compile-time types. Signatures are reference notation, not application code to execute.
store
Store immutable data (creates v1 or increments version if exists)
cortex.immutable.store(entry: ImmutableEntry, _options?: StoreImmutableOptions): Promise<ImmutableRecord>
get
Get current version of an immutable entry
cortex.immutable.get(type: string, id: string): Promise<ImmutableRecord | null>
getVersion
Get a specific version of an immutable entry
cortex.immutable.getVersion(type: string, id: string, version: number): Promise<ImmutableVersionExpanded | null>
getHistory
Get all versions of an immutable entry
cortex.immutable.getHistory(type: string, id: string): Promise<ImmutableVersionExpanded[]>
list
List immutable entries with optional filters
cortex.immutable.list(filter?: ListImmutableFilter): Promise<ImmutableRecord[]>
search
Search immutable entries by text query
cortex.immutable.search(input: SearchImmutableInput): Promise<ImmutableSearchResult[]>
count
Count immutable entries
cortex.immutable.count(filter?: CountImmutableFilter): Promise<number>
purge
Delete (purge) an immutable entry and all its versions
cortex.immutable.purge(type: string, id: string): Promise<{ deleted: boolean; type: string; id: string; versionsDeleted: number; }>
getAtTimestamp
Get version that was current at specific timestamp
cortex.immutable.getAtTimestamp(type: string, id: string, timestamp: number | Date): Promise<ImmutableVersionExpanded | null>
purgeMany
Bulk delete immutable entries matching filters
cortex.immutable.purgeMany(filter: { type?: string; userId?: string }): Promise<{ deleted: number; totalVersionsDeleted: number; entries: Array<{ type: string; id: string }>; }>
purgeVersions
Delete old versions while keeping recent ones
cortex.immutable.purgeVersions(type: string, id: string, keepLatest: number): Promise<{ versionsPurged: number; versionsRemaining: number; }>
Errors and lifecycle
Validation, missing capability, authorization, stale version and partial/unknown committed outcomes are explicit. Inspect operation/write/deletion receipts before recovery; do not repeat an external effect under a new identity after uncertainty. Close owned clients and graph resources at the end of the server workflow.
See runtime client for ordinary app execution and error handling for recovery boundaries.