[schema] PlanetGarden: The gardener's look, from fixed lists, kept on the device
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* The gardener's fixed lists, read from gardener.schema.json itself, so the choice the player
|
||||
* sees, the shape storage checks and the contract can never disagree (planet-garden.md G6).
|
||||
*/
|
||||
import schema from '../schemas/gardener.schema.json' with { type: 'json' };
|
||||
import type { Gardener } from './generated/index.js';
|
||||
|
||||
type Options = { readonly [K in keyof Gardener]: readonly Gardener[K][] };
|
||||
|
||||
export const GARDENER_OPTIONS: Options = Object.fromEntries(
|
||||
Object.entries(schema.properties).map(([k, v]) => [k, v.enum])
|
||||
) as unknown as Options;
|
||||
|
||||
/** The order the choice asks in. */
|
||||
export const GARDENER_FIELDS = schema.required as readonly (keyof Gardener)[];
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './constants.js';
|
||||
export type * from './generated/index.js';
|
||||
export { GARDENER_FIELDS, GARDENER_OPTIONS } from './gardener.js';
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
*/
|
||||
import { Ajv, type ErrorObject, type ValidateFunction } from 'ajv';
|
||||
import careEvent from '../schemas/care-event.schema.json' with { type: 'json' };
|
||||
import gardener from '../schemas/gardener.schema.json' with { type: 'json' };
|
||||
import hopeSentence from '../schemas/hope-sentence.schema.json' with { type: 'json' };
|
||||
import sentenceOpened from '../schemas/sentence-opened.schema.json' with { type: 'json' };
|
||||
import trace from '../schemas/trace.schema.json' with { type: 'json' };
|
||||
import type { CareEvent, HopeSentence, SentenceOpened, Trace } from './generated/index.js';
|
||||
import type { CareEvent, Gardener, HopeSentence, SentenceOpened, Trace } from './generated/index.js';
|
||||
|
||||
export type SchemaResult<T> =
|
||||
| { readonly ok: true; readonly value: T }
|
||||
@@ -40,4 +41,5 @@ function describe(error: ErrorObject): string {
|
||||
export const validateHopeSentence = wrap<HopeSentence>(ajv.compile(hopeSentence));
|
||||
export const validateCareEvent = wrap<CareEvent>(ajv.compile(careEvent));
|
||||
export const validateSentenceOpened = wrap<SentenceOpened>(ajv.compile(sentenceOpened));
|
||||
export const validateGardener = wrap<Gardener>(ajv.compile(gardener));
|
||||
export const validateTrace = wrap<Trace>(ajv.compile(trace));
|
||||
|
||||
Reference in New Issue
Block a user