Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/state/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class StringRayStateManager implements StateManager {
frameworkLogger.log("state-manager", "get operation", "info", {
key,
hasValue: value !== undefined,
valueType: value ? (value as unknown as { constructor?: { name?: string } }).constructor?.name : undefined,
});
return value;
}
Expand Down Expand Up @@ -262,6 +263,34 @@ export class StringRayStateManager implements StateManager {
return StringRayStateManager.VERSION || "1.1.1";
}

// Check if stored value is a valid class instance (has prototype methods)
// This helps detect values that were serialized to JSON and lost their prototype chain
isValidClassInstance(
value: unknown,
methodName: string,
): boolean {
if (!value || typeof value !== "object") return false;
if (typeof (value as Record<string, unknown>)[methodName] === "function")
return true;
// Check if it's a plain object that lost its prototype
if (
(value as Record<string, unknown>).constructor?.name === "Object" ||
!(value as Record<string, unknown>).constructor
) {
frameworkLogger.log(
"state-manager",
"invalid-class-instance-detected",
"warning",
{
key: "detection",
hasMethod: methodName in (value as Record<string, unknown>),
},
);
return false;
}
return false;
}

getAuditLog(): Array<{ timestamp: Date; operation: string; key: string }> {
return []; // Simplified implementation for testing
}
Expand Down
Loading