fix: normalize legacy space visibility values to 3-type model
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
35a5a5f29a
commit
0d8d8202a5
|
|
@ -11,7 +11,15 @@ import {
|
|||
|
||||
const STORAGE_DIR = process.env.STORAGE_DIR || "./data/communities";
|
||||
|
||||
export type SpaceVisibility = 'public' | 'public_read' | 'authenticated' | 'members_only';
|
||||
export type SpaceVisibility = 'public' | 'permissioned' | 'private';
|
||||
|
||||
/** Normalize legacy visibility values to the current 3-type model. */
|
||||
export function normalizeVisibility(v: string): SpaceVisibility {
|
||||
if (v === 'public_read' || v === 'public') return 'public';
|
||||
if (v === 'authenticated' || v === 'permissioned') return 'permissioned';
|
||||
if (v === 'members_only' || v === 'private') return 'private';
|
||||
return 'public';
|
||||
}
|
||||
|
||||
// ── Nest Permissions & Policy ──
|
||||
|
||||
|
|
@ -243,6 +251,8 @@ export async function loadCommunity(slug: string): Promise<Automerge.Doc<Communi
|
|||
let doc = Automerge.load<CommunityDoc>(bytes);
|
||||
// Runtime migration: participant → member
|
||||
doc = migrateParticipantToMember(doc, slug);
|
||||
// Runtime migration: normalize legacy visibility values
|
||||
doc = migrateVisibility(doc, slug);
|
||||
communities.set(slug, doc);
|
||||
return doc;
|
||||
} catch (e) {
|
||||
|
|
@ -261,6 +271,8 @@ export async function loadCommunity(slug: string): Promise<Automerge.Doc<Communi
|
|||
let doc = jsonToAutomerge(data);
|
||||
// Runtime migration: participant → member
|
||||
doc = migrateParticipantToMember(doc, slug);
|
||||
// Runtime migration: normalize legacy visibility values
|
||||
doc = migrateVisibility(doc, slug);
|
||||
communities.set(slug, doc);
|
||||
// Save as Automerge binary
|
||||
await saveCommunity(slug);
|
||||
|
|
@ -348,7 +360,7 @@ export async function createCommunity(
|
|||
name: string,
|
||||
slug: string,
|
||||
ownerDID: string | null = null,
|
||||
visibility: SpaceVisibility = 'public_read',
|
||||
visibility: SpaceVisibility = 'public',
|
||||
options?: {
|
||||
enabledModules?: string[];
|
||||
nestPolicy?: NestPolicy;
|
||||
|
|
|
|||
Loading…
Reference in New Issue