[repo] Workspace: Scaffold Phase 0 with schema, engine, content, ui and the PWA shell
pnpm + turbo workspace with the commands from CLAUDE.md §3. The contracts from §6 as JSON Schemas with generated types; localDay as the one place a day is computed; the forbidden-word list shared by lint:copy and the library validator, with 13 negative fixtures; a Svelte 5 PWA shell built under /Rosea/ with a meta CSP. E2E and offline suites run against the built bundle; the offline one closes the server rather than emulating. Analysis: .agents/features/phase0-workspace.md
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* The product's name, in one of the three places it may appear in source
|
||||
* (CLAUDE.md preamble). The other two are `apps/rosea/index.html` and the web
|
||||
* manifest, which `apps/rosea/vite.config.ts` builds from these constants.
|
||||
*
|
||||
* `Rosea` is a working name. Renaming must stay a one-commit operation: change
|
||||
* these, `index.html`, the `@rosea/*` scope and nothing else.
|
||||
*/
|
||||
|
||||
/** What the player reads. *Domi* never appears alone. */
|
||||
export const PRODUCT_NAME = 'Rosea Domi';
|
||||
|
||||
/** The short form, for the home-screen label. */
|
||||
export const PRODUCT_SHORT_NAME = 'Rosea';
|
||||
|
||||
/** The IndexedDB database name (CLAUDE.md §4). Changes together with the name. */
|
||||
export const DATABASE_NAME = 'rosea';
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './constants.js';
|
||||
export type * from './generated/index.js';
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Schema validation, for Node only: scripts, tests and the library validator.
|
||||
*
|
||||
* It is a separate entry point (`@rosea/schema/validate`) on purpose. Ajv
|
||||
* compiles validators with `new Function`, which the app's CSP forbids
|
||||
* (`script-src 'self'`, no `'unsafe-eval'`). Importing it from the browser bundle
|
||||
* would fail at runtime, not at build time. When the app needs to validate, it
|
||||
* gets standalone pre-compiled validators (GAP_ANALYSIS G0.12).
|
||||
*/
|
||||
import { Ajv, type ErrorObject, type ValidateFunction } from 'ajv';
|
||||
import careEvent from '../schemas/care-event.schema.json' with { type: 'json' };
|
||||
import hopeSentence from '../schemas/hope-sentence.schema.json' with { type: 'json' };
|
||||
import trace from '../schemas/trace.schema.json' with { type: 'json' };
|
||||
import type { CareEvent, HopeSentence, Trace } from './generated/index.js';
|
||||
|
||||
export type SchemaResult<T> =
|
||||
| { readonly ok: true; readonly value: T }
|
||||
| { readonly ok: false; readonly errors: readonly string[] };
|
||||
|
||||
const ajv = new Ajv({ allErrors: true, strict: true });
|
||||
|
||||
function wrap<T>(validate: ValidateFunction): (input: unknown) => SchemaResult<T> {
|
||||
return (input) =>
|
||||
validate(input)
|
||||
? { ok: true, value: input as T }
|
||||
: { ok: false, errors: (validate.errors ?? []).map(describe) };
|
||||
}
|
||||
|
||||
function describe(error: ErrorObject): string {
|
||||
const where = error.instancePath === '' ? '(root)' : error.instancePath;
|
||||
// Ajv already names a missing property in its message; an extra one it does not.
|
||||
const extra =
|
||||
error.keyword === 'additionalProperties'
|
||||
? ` '${String((error.params as { additionalProperty?: unknown }).additionalProperty)}'`
|
||||
: '';
|
||||
return `${where} ${error.message ?? error.keyword}${extra}`;
|
||||
}
|
||||
|
||||
export const validateHopeSentence = wrap<HopeSentence>(ajv.compile(hopeSentence));
|
||||
export const validateCareEvent = wrap<CareEvent>(ajv.compile(careEvent));
|
||||
export const validateTrace = wrap<Trace>(ajv.compile(trace));
|
||||
Reference in New Issue
Block a user