@codemem/server 0.36.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +7 -34
- package/dist/index.js.map +1 -1
- package/dist/routes/memory.d.ts.map +1 -1
- package/package.json +2 -2
- package/static/app.js +1 -1
package/dist/index.js
CHANGED
|
@@ -556,37 +556,14 @@ function queryBool(value) {
|
|
|
556
556
|
}
|
|
557
557
|
//#endregion
|
|
558
558
|
//#region src/routes/memory.ts
|
|
559
|
-
function
|
|
560
|
-
if (typeof value !== "string") return null;
|
|
561
|
-
const trimmed = value.trim();
|
|
562
|
-
return trimmed ? trimmed : null;
|
|
563
|
-
}
|
|
564
|
-
function buildOwnershipContext(store) {
|
|
565
|
-
const claimedPeerIds = new Set(store.sameActorPeerIds());
|
|
566
|
-
return {
|
|
567
|
-
actorId: store.actorId,
|
|
568
|
-
claimedPeerIds,
|
|
569
|
-
deviceId: store.deviceId,
|
|
570
|
-
legacyActorIds: new Set(Array.from(claimedPeerIds, (peerId) => `legacy-sync:${peerId}`))
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
function memoryOwnedBySelf(row, ownership, metadata = fromJson(row.metadata_json ?? null)) {
|
|
574
|
-
const meta = metadata;
|
|
575
|
-
const actorId = cleanOwnershipValue(row.actor_id) ?? cleanOwnershipValue(meta.actor_id);
|
|
576
|
-
if (actorId === ownership.actorId) return true;
|
|
577
|
-
const deviceId = cleanOwnershipValue(row.origin_device_id) ?? cleanOwnershipValue(meta.origin_device_id);
|
|
578
|
-
if (deviceId === ownership.deviceId) return true;
|
|
579
|
-
if (deviceId && ownership.claimedPeerIds.has(deviceId)) return true;
|
|
580
|
-
if (actorId && ownership.legacyActorIds.has(actorId)) return true;
|
|
581
|
-
return false;
|
|
582
|
-
}
|
|
583
|
-
function serializeMemoryRow(ownership, row) {
|
|
559
|
+
function serializeMemoryRow(ownedBySelf, row) {
|
|
584
560
|
const metadata = fromJson(row.metadata_json ?? null);
|
|
561
|
+
const owned_by_self = ownedBySelf(row);
|
|
585
562
|
return {
|
|
586
563
|
...row,
|
|
587
564
|
kind: canonicalMemoryKind(row.kind ?? null, row.metadata_json),
|
|
588
565
|
metadata_json: metadata,
|
|
589
|
-
owned_by_self
|
|
566
|
+
owned_by_self
|
|
590
567
|
};
|
|
591
568
|
}
|
|
592
569
|
/**
|
|
@@ -642,11 +619,7 @@ function normalizeScope(raw) {
|
|
|
642
619
|
if (value === "mine" || value === "theirs") return value;
|
|
643
620
|
}
|
|
644
621
|
function buildViewerMemoryFilters(store, filters) {
|
|
645
|
-
return buildFilterClausesWithContext(filters,
|
|
646
|
-
actorId: store.actorId,
|
|
647
|
-
deviceId: store.deviceId,
|
|
648
|
-
enforceScopeVisibility: true
|
|
649
|
-
});
|
|
622
|
+
return buildFilterClausesWithContext(filters, store.ownershipFilterContext());
|
|
650
623
|
}
|
|
651
624
|
function countVisibleMemoryRows(store, filters) {
|
|
652
625
|
const filterResult = buildViewerMemoryFilters(store, filters);
|
|
@@ -729,8 +702,8 @@ function queryMemoryPage(store, options) {
|
|
|
729
702
|
WHERE ${where}
|
|
730
703
|
ORDER BY memory_items.created_at DESC
|
|
731
704
|
LIMIT ? OFFSET ?`).all(...filterResult.params, options.limit + 1, options.offset);
|
|
732
|
-
const
|
|
733
|
-
return rows.map((row) => serializeMemoryRow(
|
|
705
|
+
const ownedBySelf = store.buildOwnershipPredicate();
|
|
706
|
+
return rows.map((row) => serializeMemoryRow(ownedBySelf, row));
|
|
734
707
|
}
|
|
735
708
|
function isSummaryLikeMemory$1(item) {
|
|
736
709
|
return isSummaryLikeMemory({
|
|
@@ -1010,7 +983,7 @@ function memoryRoutes(getStore) {
|
|
|
1010
983
|
if (!store.get(memoryId)) return c.json({ error: "memory not found" }, 404);
|
|
1011
984
|
const row = drizzle(store.db, { schema }).select().from(schema.memoryItems).where(eq(schema.memoryItems.id, memoryId)).get();
|
|
1012
985
|
if (!row) return c.json({ error: "memory not found" }, 404);
|
|
1013
|
-
if (!memoryOwnedBySelf(row
|
|
986
|
+
if (!store.memoryOwnedBySelf(row)) return c.json({ error: "memory not owned by this device" }, 403);
|
|
1014
987
|
if (Number(row.active ?? 1) === 0 || row.deleted_at != null) return c.json({ status: "ok" });
|
|
1015
988
|
try {
|
|
1016
989
|
store.forget(memoryId);
|