deno-anki
anki-apkg-exportをDeno & TypeScriptに書き換えたもの
https://github.com/takker99/deno-anki
API reference (master branch)
機能
deck (Anki), note type (Anki), note (Anki)からapkgを生成する
fork元からの変更点
node対応を外した
TypeScriptで書き換えた
Deta Schema等の型定義
Denoに対応した
sql.jsとJSZipを外部から注入できるようにした
scrapboxから使うときは、まとめてbundleするのではなくCDN経由で注入したいため
API設計を元repoから変える
設定を予め全部JSONで決めて、一発で作らせる?
一番汎用性がありそう
immutableなAPIにする
Deta Schema等の型定義とにらめっこしつつ、必要なパラメタのみ設定できるようにする
code:ts
export const makeAnkiDB: (init: {
decks: {
/** used as deck ID */
created: number;
updated?: number;
name: string;
description?: string;
}[];
notes: {
guid: string;
/** used as note ID */
created: number;
updated?: number;
noteTypeId: string;
tags: string[];
fields: string[];
}[];
noteTypes: {
/** used as model(aka. note type) ID */
created: number;
updated?: number;
/** @default 1 */
deckId?: number;
fields: {
name: string;
rtl?: boolean;
font?: string;
fontSize?: number;
}[] | string[];
templates: {
name: string;
question: string;
answer: string;
example?: string, string;
}[];
latex?: string, string;
css?: string;
isCloze?: boolean;
}[];
}, sql: SQLDatabase) => Promise<Uint8Array>
export const makeApkg: (
ankiDB: Uint8Array,
media:
Record<string, InputFormat> | Map<string, InputFormat>,
jsZip: :JSZip,
) => Promise<Uint8Array>;
やること
✅函数名変更
makecollectionとmakepackage
✅idgenでミスってたとこ
jsdoc
後回し
testコードを綺麗にする
後回し
testケースを増やす
後回し
✅noteごとにdeckとnote typeを指定させる (deno-anki)
modはmillisecondsだった
apkgのデータ構造のwiki referenceと説明が違う!!!
wikiの説明が古かったようだ
課題
単体テストでJSZipが機能しない
JSZip.prototype.generatorAsync()で止まっていることはわかっている
JSZipのみの単体テストを試してみるか
example/server/server.tsが<C-c>で強制終了しないと終了しない現象との関連性も気になる
unresolved Promiseが居残っている?
memory leaksが原因かも
このmoduleをimportすると、deno check --remoteが通らなくなる
なんでだろtakker.icon
@types/nodeと@types/ecmascriptenまわりで型の競合が起きている
2023-02-20 17:39:13 NodeJS.ReadableStreamが悪さをしているのかも
20行目のhttps://code2svg.vercel.app/svg/L20/https://raw.githubusercontent.com/takker99/deno-anki/2a3ed108e2ec4f25b27c40a287c01be7ce05dd6e/deps.ts#.svg
https://code2svg.vercel.app/svg/L10-26/https://raw.githubusercontent.com/takker99/deno-anki/2a3ed108e2ec4f25b27c40a287c01be7ce05dd6e/deps.ts#.svg
エラーメッセージに、なぜかnpmjs.comからimportされたファイルパスが写っていた
多分この型のせいだろう
どうせNode.jsをサポートする予定はないし、InputByTypeから削ってしまうか
rustとpythonによる実装もあったみたい
https://github.com/yannickfunk/genanki-rs
https://github.com/kerrickstaley/genanki
どちらも解説がくわしい
genankiにinterfaceを統一する手もあるのか
code:mod.ts
export * from "https://raw.githubusercontent.com/takker99/deno-anki/0.0.2/mod.ts";
#2023-02-26 21:15:21
#2023-02-20 08:54:15
#2023-02-10 06:12:14
#2023-02-08 18:39:20
#2022-10-31 22:25:39