From 722127ef4059020876f708b1d5406c04fd07b0da Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 30 Jun 2023 17:31:46 +0200 Subject: WIP user api --- api/base.ts | 20 ++++++++++++++++++++ api/glossary.ts | 15 +++++++++++++++ api/readme.md | 6 ++++++ api/sentence.ts | 15 +++++++++++++++ api/word.ts | 15 +++++++++++++++ api/yomikun.ts | 16 ++++++++++++++++ 6 files changed, 87 insertions(+) create mode 100644 api/base.ts create mode 100644 api/glossary.ts create mode 100644 api/readme.md create mode 100644 api/sentence.ts create mode 100644 api/word.ts create mode 100644 api/yomikun.ts (limited to 'api') diff --git a/api/base.ts b/api/base.ts new file mode 100644 index 0000000..e89e76b --- /dev/null +++ b/api/base.ts @@ -0,0 +1,20 @@ +import Core from "../core/api.ts"; +import Yomikun from "./yomikun.ts"; + +/** @summary generic class that keeps a reference to parent API reference */ +export default abstract class APIBase { + private _resolveAPI: (api: Yomikun) => void = _ => {}; + + protected api: Promise; + + constructor() { + this.api = new Promise(res => this._resolveAPI = res); + } + + /** @summary set API reference and return self (for use directly after constructor) */ + withParent(api: Yomikun) { + this._resolveAPI(api); + return this; + } +} + diff --git a/api/glossary.ts b/api/glossary.ts new file mode 100644 index 0000000..0b16e48 --- /dev/null +++ b/api/glossary.ts @@ -0,0 +1,15 @@ +import APIBase from "./base.ts"; + +export default class Glossary extends APIBase { + constructor() { + super(); + } + + dict(name: string): Array { + return this.all(); + } + + all(): Array { + return []; + } +} diff --git a/api/readme.md b/api/readme.md new file mode 100644 index 0000000..58ebbcb --- /dev/null +++ b/api/readme.md @@ -0,0 +1,6 @@ +# Yomikun API + +This folder contains an abstracted version of the [Core +API](../core/readme.md), which is recommended for general use. Please see [the +API examples](../examples/readme.md). + diff --git a/api/sentence.ts b/api/sentence.ts new file mode 100644 index 0000000..dc14cb2 --- /dev/null +++ b/api/sentence.ts @@ -0,0 +1,15 @@ +import APIBase from "./base.ts"; +import Word from "./word.ts"; +import Yomikun from "./yomikun.ts"; + +export default class Sentence extends APIBase { + public words: Array = []; + + constructor() { + super(); + } + + first(searchValue: RegExp | string): Word | undefined { + return this.words[0]; + } +} diff --git a/api/word.ts b/api/word.ts new file mode 100644 index 0000000..d2df69e --- /dev/null +++ b/api/word.ts @@ -0,0 +1,15 @@ +import Glossary from "./glossary.ts"; +import APIBase from "./base.ts"; + +export default class Word extends APIBase { + public writing: string = "TODO"; + public reading: string = "TODO"; + + constructor() { + super(); + } + + async glossary() { + return new Glossary().withParent(await this.api); + } +} diff --git a/api/yomikun.ts b/api/yomikun.ts new file mode 100644 index 0000000..4971567 --- /dev/null +++ b/api/yomikun.ts @@ -0,0 +1,16 @@ +import Core from "../core/api.ts"; +import RemoteCoreClient from "../core/http/client.ts"; +import Sentence from "./sentence.ts"; + +export default class Yomikun { + protected core: Core; + + constructor(core?: Core) { + this.core = core ?? new RemoteCoreClient(); + } + + async sentence(input: string): Promise { + return new Sentence().withParent(this); + } +} + -- cgit v1.2.3