the statusphere demo reworked into a vite/react app in a monorepo

Show generated code

+25 -2
+25 -2
TUTORIAL.md
··· 336 336 Let's create our schema in the `/lexicons` folder of our codebase. You can [read more about how to define schemas here](#todo). 337 337 338 338 ```json 339 - /* lexicons/status.json */ 339 + /** lexicons/status.json **/ 340 340 { 341 341 "lexicon": 1, 342 342 "id": "com.example.status", ··· 371 371 ./node_modules/.bin/lex gen-server ./src/lexicon ./lexicons/* 372 372 ``` 373 373 374 - This will produce Typescript interfaces as well as runtime validation functions that we can use in our `POST /status` route: 374 + This will produce Typescript interfaces as well as runtime validation functions that we can use in our app. Here's what that generated code looks like: 375 + 376 + ```typescript 377 + /** src/lexicon/types/com/example/status.ts **/ 378 + export interface Record { 379 + status: string 380 + createdAt: string 381 + [k: string]: unknown 382 + } 383 + 384 + export function isRecord(v: unknown): v is Record { 385 + return ( 386 + isObj(v) && 387 + hasProp(v, '$type') && 388 + (v.$type === 'com.example.status#main' || v.$type === 'com.example.status') 389 + ) 390 + } 391 + 392 + export function validateRecord(v: unknown): ValidationResult { 393 + return lexicons.validate('com.example.status#main', v) 394 + } 395 + ``` 396 + 397 + Let's use that code to improve the `POST /status` route: 375 398 376 399 ```typescript 377 400 /** src/routes.ts **/