diff --git a/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/package.json b/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/package.json index c387b89e..1b767a71 100644 --- a/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/package.json +++ b/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/package.json @@ -36,7 +36,8 @@ "_build:dev:watch": "monorepo-script--build-typescript-package --watch --module=esm", "dev": "run-s clean _build:dev:watch", - "demo": "node ./dist/src.es2023.esm/demo/index.js" + "demo": "node ./dist/src.es2023.esm/demo/index.js", + "demoh": "node ./dist/src.es2023.esm/hateoas/index.js" }, "devDependencies": { diff --git a/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/demo/index.ts b/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/demo/index.ts index 47ca37a2..5f64a707 100644 --- a/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/demo/index.ts +++ b/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/demo/index.ts @@ -43,6 +43,7 @@ function loop() { console.log('/////////////////////////////////////////////////') // always first const $doc = State.getꓽrecap(state.u_state) // TODO clarify recap/mode + console.log(prettifyꓽjson($doc)) console.log(to_terminal($doc)) console.log('/////////////////////////////////////////////////') @@ -73,45 +74,7 @@ function loop() { } ///////////////////////////////////////////////// -/* + loop() state = State.play(state) loop() -*/ -///////////////////////////////////////////////// -// https://github.com/kevinswiber/siren - -interface Link { - rel: string // https://www.iana.org/assignments/link-relations/link-relations.xhtml TODO array? - - cta: string - href: string -} - -interface Response { - data: { - - $doc: RichText.Document - - } - - links: { - // self must be present - - - [rel: string]: Link - } -} - - -function HATEOASᐧGETꓽⳇmodeⳇ() { - -} - -function HATEOASᐧGET(link: string = '/'): Response { - - switch (link) { - default: - throw new Error(`Unknown resource "${link}"!`) - } -} diff --git a/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/hateoas/index.ts b/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/hateoas/index.ts new file mode 100644 index 00000000..d0c90d1a --- /dev/null +++ b/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/hateoas/index.ts @@ -0,0 +1,39 @@ +import { Immutable } from '@offirmo-private/state-utils' +import { type Hyperlink } from '@offirmo-private/ts-types-web' +import * as RichText from '@offirmo-private/rich-text-format' + +import to_terminal from '@offirmo-private/rich-text-format--to-terminal' + +import * as State from '@tbrpg/state' +import * as RRT from '@tbrpg/ui--rich-text' + +import { prettifyꓽjson } from '../services/misc.js' + +///////////////////////////////////////////////// + +let state = State.create() +// TODO reseed +state = State.on_start_session(state, true) +state = State.update_to_now(state) + +///////////////////////////////////////////////// + +function HATEOASᐧGET(state: Immutable, link: Hyperlink['href'] = ''): RichText.Document { + console.log(`HATEOASᐧGET("${link}")`) + +// const $doc = State.getꓽrecap(state.u_state) // TODO clarify recap/mode + + + switch (link) { + case '': + return State.getꓽrecap(state.u_state) + default: + throw new Error(`Unknown resource "${link}"!`) + } +} + +console.log('/////////////////////////////////////////////////') +let current_uri: Hyperlink['href'] = '' +const $doc = HATEOASᐧGET(state, current_uri) +console.log(prettifyꓽjson($doc)) +//console.log(to_terminal($doc)) diff --git a/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/services/misc.ts b/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/services/misc.ts index 5932ca30..54c14b6c 100644 --- a/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/services/misc.ts +++ b/stack--current/A-apps--core/the-boring-rpg/xx-sandbox/src/services/misc.ts @@ -4,5 +4,9 @@ root_logger.setLevel('silly') import chalk from 'chalk' -import { injectꓽlibꓽchalk } from '@offirmo-private/prettify-any' +import { injectꓽlibꓽchalk, prettifyꓽjson } from '@offirmo-private/prettify-any' injectꓽlibꓽchalk(chalk) + +export { + prettifyꓽjson, +}