Shared utilities, errors, constants, and test fixtures for the Engram system.
Foundation package providing type-safe utilities, structured error handling, system-wide constants, and comprehensive test infrastructure. Eliminates code duplication across all Engram packages and applications.
envStr,envBool,envNum,envFloat,envArray- Type-safe environment variable parsing with defaultsenvRequired- Required environment variables (throws if missing)
formatBytes,formatDuration,formatRelativeTime- Human-readable formattingtruncateId,truncateText- Text truncation for display
sha256Hash,sha256Short- SHA-256 hashing for content-addressable storagehashObject- Deterministic object hashing (order-independent)
withRetry- Exponential backoff with jitter for transient failuresRetryableErrors- Built-in retryable error patterns (network, rate limit, server errors)
EngramError- Base error with error codes and cause chainingGraphOperationError,ParseError,ValidationError- Domain-specific errorsContextAssemblyError,RehydrationError,StorageError,SearchErrorErrorCodes- Centralized error code constants
- Timeouts:
GraphTimeouts,ToolTimeouts,SearchTimeouts,HttpTimeouts,CacheTimeouts - Limits:
ContentLimits,QueryLimits,SessionLimits,RateLimits,BatchLimits - Intervals:
PruneIntervals,PollIntervals,DebounceIntervals,RetentionPeriods,WebSocketIntervals - Qdrant:
QdrantCollections,MemoryVectorFields,TurnsVectorFields
- OAuth types:
TokenRequest,TokenResponse,DeviceCodeRequest,DeviceCodeResponse - Auth types:
AuthContext,OAuthTokenContext,CachedTokens - Configs:
OAuthConfig, token patterns
- Mock Factories:
createTestLogger,createTestGraphClient,createTestMessageClient,createTestRedisPublisher,createTestBlobStore,createTestProducer,createTestConsumer - Domain Fixtures:
createTestSession,createTestTurn,createTestToolCall,createTestReasoning,createTestFileTouch,createTestObservation - Utilities:
createTestId,createTestHash,createTestBitemporalProps,createDeferred,expectToReject,spyOnConsole,wait
// Environment parsing
import { envStr, envBool, envNum } from "@engram/common";
const host = envStr("REDIS_HOST", "localhost");
const debug = envBool("DEBUG", false);
const port = envNum("PORT", 3000);
// Formatting
import { formatBytes, formatDuration } from "@engram/common";
formatBytes(1048576); // "1 MB"
formatDuration(90000); // "1m 30s"
// Hashing
import { sha256Hash, hashObject } from "@engram/common";
const hash = sha256Hash("content");
const objHash = hashObject({ b: 2, a: 1 }); // Order-independent
// Retry with exponential backoff
import { withRetry, RetryableErrors } from "@engram/common";
const result = await withRetry(() => apiCall(), {
maxRetries: 5,
isRetryable: RetryableErrors.isTransientError,
});
// Structured errors
import { GraphOperationError, ValidationError } from "@engram/common";
throw new GraphOperationError("Query failed", "MATCH (n) RETURN n", error);
// Constants
import { GraphTimeouts, ContentLimits } from "@engram/common";
const timeout = GraphTimeouts.QUERY_MS; // 10,000
// Testing
import { createTestGraphClient, createTestSession } from "@engram/testing";
const graphClient = createTestGraphClient({
query: mock().mockResolvedValue([{ id: "123" }]),
});
const session = createTestSession({ user_id: "user-123" });@engram/storage- Storage interface types for test mocks@engram/graph- Domain model types for test fixtures