aboutsummaryrefslogtreecommitdiff
path: root/core/raw/api.ts
blob: 47e9075eeae0332140c15cedfdc7eedf219012c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import Core, { CoreExport, CoreImport, CoreSearch, CoreUser } from "../api.ts";
import YomikunError from "../../util/error.ts";
import Search from "../../search/search.ts";
import DB from "../../db/db.ts";

/** @summary internal Core (DO NOT USE DIRECTLY) */
export default class RawCore implements Core {
	public ready: Promise<void>;

	private _search: Search;
	private _db: DB;

	constructor() {
		if (this.constructor === RawCore) {
			throw new YomikunError("RawCore instantiated! Use DirectCoreClient instead!");
		}

		this._db = new DB();
		this._search = new Search(this._db);

		this.ready = new Promise(async resolve => {
			await this._search.ready;
			resolve();
		})
	}

	public search: CoreSearch = {
		terms: async term => {
			return await this._search.terms(term);
		},
		sentence: async (sentence, optional?) => {
			return await this._search.sentence(sentence, optional);
		},
	};

	public user: CoreUser = {
		termPriority: async (uid, expression, reading, priority) => {
			this._db.termPriority(uid, expression, reading, priority);
		},
	};

	public import: CoreImport = {};

	public export: CoreExport = {};
};