docs: tsx,script,permissions (4 files)

This commit is contained in:
2025-12-26 01:19:40 +00:00
parent cc3b62717e
commit ce903c1ea9
4 changed files with 58 additions and 10 deletions

View File

@@ -2,21 +2,26 @@
* @file get-lua-script.ts
* @description Get Lua script operation
*/
import type { LuaScript, Result } from '../types';
import type { InMemoryStore } from '../store/in-memory-store';
import type { DBALAdapter } from '../../../adapters/adapter'
import type { LuaScript } from '../../types'
import { DBALError } from '../../errors'
import { validateId } from '../../validation'
/**
* Get a Lua script by ID
*/
export async function getLuaScript(store: InMemoryStore, id: string): Promise<Result<LuaScript>> {
if (!id) {
return { success: false, error: { code: 'VALIDATION_ERROR', message: 'ID required' } };
export async function getLuaScript(adapter: DBALAdapter, id: string): Promise<LuaScript> {
const validationErrors = validateId(id)
if (validationErrors.length > 0) {
throw DBALError.validationError(
'Invalid Lua script ID',
validationErrors.map(error => ({ field: 'id', error }))
)
}
const script = store.luaScripts.get(id);
if (!script) {
return { success: false, error: { code: 'NOT_FOUND', message: `Lua script not found: ${id}` } };
const result = await adapter.read('LuaScript', id) as LuaScript | null
if (!result) {
throw DBALError.notFound(`Lua script not found: ${id}`)
}
return { success: true, data: script };
return result
}

View File

@@ -48,6 +48,7 @@ Detailed implementation documentation:
- **[Prisma Implementation](./implementation/PRISMA_IMPLEMENTATION_COMPLETE.md)** - ORM setup
- **[TypeScript Enhancements](./implementation/TYPESCRIPT_DBAL_ENHANCEMENTS.md)** - Type system improvements
- **[Nerd Mode IDE](./implementation/NERD_MODE_IDE.md)** - Package templates and zip exports
- **[Permission Levels](./permissions-levels.md)** - Five-tier security and UI guide
- **[Codegen Studio Export](./codegen-studio.md)** - Zip generation service for package starters
### 🔄 [Refactoring](./refactoring/)

View File

@@ -0,0 +1,28 @@
# Permission Levels Reference
MetaBuilder runs on a five-tier permission stack that spans the public surface, authenticated experiences, moderation, system design, and governance.
## Tier breakdown
| Level | Name | Responsibilities |
|-------|------|------------------|
| 1 | Guest | Browse marketing content, view stories, consume public dashboards without any write access.
| 2 | Regular User | Maintain a profile, tune personal settings, launch saved dashboards, and participate in public workflows.
| 3 | Moderator | Keep the community healthy by resolving flags, reviewing reports, and adjusting shared spaces.
| 4 | God | Author blueprints, edit the front page, seed packages, and design workflows for the multiverse.
| 5 | Super God | Transfer front page ownership, promote gods, run audits, and override safety nets when necessary.
## Interactive view
Visit `/levels` to step through each tier. The page renders a grid of cards, highlights the selected level, and previews the bundle of privileges that accompany it. A promotion button demonstrates the jump to the next level while providing contextual messaging.
## Tooling
- Run `tsx tools/list-permissions.ts` to dump the level definitions and capabilities into the console. This script ensures workflows or automation agents always align with the same data that powers the UI.
- The CLI at `packages/codegen_studio/static_content/cli/main.cpp --levels` also prints this list so legacy tooling and C++ guardians share the same glossary.
## Testing
- `frontends/nextjs/src/app/levels/LevelsClient.test.tsx` asserts the UI renders each tier and that promotions update the alert banner.
Keeping these references synchronized prevents drift between documentation, UI, tooling, and C++ listeners.

View File

@@ -0,0 +1,14 @@
import { fireEvent, render, screen } from '@testing-library/react'
import LevelsClient from './LevelsClient'
describe('LevelsClient', () => {
it('renders permission levels and promotes to the next tier', () => {
render(<LevelsClient />)
expect(screen.getByText(/Level 1 · Guest/)).toBeInTheDocument()
const promoteButton = screen.getByRole('button', { name: /Promote to/ })
fireEvent.click(promoteButton)
expect(screen.getByText(/Upgraded to Regular User/)).toBeInTheDocument()
})
})