Files
memind/health-baseline-store.mjs
T
john 2baf29b3ae feat(health): complete P0 health channel — baseline engine, page-data, MindSpace UI
Deliver encrypted health zone, observation API, baseline maturity pipeline,
page-data bindings, and H5/WeChat channel integration for health P0.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-09 18:04:57 +08:00

31 lines
1.0 KiB
JavaScript

import { baselineRowKey, serializeBaselineRow } from './health-baseline-serialize.mjs';
export function createInMemoryHealthBaselineStore() {
const rowsByUser = new Map();
let nextId = 1;
return {
async list(userId) {
return [...(rowsByUser.get(String(userId)) ?? [])];
},
async upsertMany(userId, baselines = [], { computedAt = Date.now() } = {}) {
const key = String(userId);
const existing = rowsByUser.get(key) ?? [];
const index = new Map(existing.map((row) => [baselineRowKey(row), row]));
for (const base of baselines) {
const serialized = serializeBaselineRow(base, computedAt);
const rowKey = baselineRowKey(serialized);
const prior = index.get(rowKey);
if (prior) {
index.set(rowKey, { ...prior, ...serialized });
} else {
index.set(rowKey, { id: nextId++, userId: key, ...serialized });
}
}
const merged = [...index.values()];
rowsByUser.set(key, merged);
return merged;
},
};
}