Fix Story 1.3: StateStore spec compliance and minor cleanup

Critical Fix:
- StateStore now uses global Hooks.callAll directly (per spec)
- Removed hooks parameter from StateStore constructor
- Updated module.js to pass only adapter.settings
- Updated tests to stub globalThis.Hooks

Minor Cleanup:
- Fixed misleading warning in SocketHandler.registerPendingOp
- Added clarifying comment for setMatrix _revision behavior

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-05-22 11:38:45 +02:00
parent 110b295a7b
commit 5ba7717ecd
17 changed files with 2391 additions and 55 deletions
+5 -1
View File
@@ -15,6 +15,7 @@
* @typedef {Object} VisibilityMatrix
* @property {1} _version - Schema version; always 1 for v1.
* @property {Object.<string, VisibilityState>} matrix - userId → VisibilityState map.
* @property {number} [_revision] - Optional revision counter for optimistic concurrency control.
*/
export const VISIBILITY_STATES = Object.freeze([
@@ -50,7 +51,7 @@ export function isValidVisibilityMatrix(data) {
throw new TypeError("VisibilityMatrix: must be an object");
}
const obj = /** @type {Record<string, unknown>} */ (data);
const { _version, matrix, ...rest } = obj;
const { _version, matrix, _revision, ...rest } = obj;
if (Object.keys(rest).length > 0) {
throw new TypeError(`VisibilityMatrix: unknown keys: ${Object.keys(rest).join(", ")}`);
}
@@ -60,6 +61,9 @@ export function isValidVisibilityMatrix(data) {
if (matrix === null || typeof matrix !== "object" || Array.isArray(matrix)) {
throw new TypeError("VisibilityMatrix: matrix must be a plain object");
}
if (_revision !== undefined && (typeof _revision !== "number" || !Number.isFinite(_revision) || _revision < 0)) {
throw new TypeError("VisibilityMatrix: _revision must be a finite non-negative number");
}
const matrixObj = /** @type {Record<string, unknown>} */ (matrix);
for (const [userId, state] of Object.entries(matrixObj)) {
if (typeof userId !== "string" || userId.length === 0) {