Skip to content

src/list-worlds.ts

17 lines · 688 B · TypeScript
Raw
/**
 * List the main world plus rooms you created, with block counts and active players.
 * Rooms other people share with you are opened by their link, not listed.
 *
 * @returns `{ worlds: [{ id, room, name, blockCount, activePlayers }] }`
 * @example
 * import listWorlds from 'kody:@kentcdodds/world-builder/list-worlds'
 * const { worlds } = await listWorlds()
 */
import { getCaller } from './lib/identity.ts'
import { WorldError, listWorlds as list } from './lib/world-ops.ts'

export default async function listWorlds() {
	const caller = await getCaller()
	if (!caller) throw new WorldError('Sign in to Kody to list worlds.', 401)
	return { worlds: await list(caller.username) }
}