✌️ Thanks for your contributions ✌️
Feature suggestions and bug reports are filed in https://github.com/syuilo/misskey/issues . Before creating a new issue, please search existing issues to avoid duplication. If you find the existing issue, please add your reaction or comment to the issue.
Please use Crowdin for localization.
Misskey uses vue-i18n.
- Documents for contributors are located in
/docs
. - Documents for instance admins are located in
/docs
. - Documents for end users are located in
src/docs
.
- Test codes are located in
/test
.
Misskey uses CircleCI for automated test.
Configuration files are located in /.circleci
.
Stands for ActivityPub.
Stands for Misskey Flavored Markdown.
Stands for Misskey.
Stands for ServiceWorker.
Convert な(na) to にゃ(nya)
Revert Nyaize
ASI Hazardを避けるためでもある
Bad:
if (foo)
bar;
else
baz;
Good:
if (foo) {
bar;
} else {
baz;
}
ただし**if
が一行**の時だけは省略しても良い
Good:
if (foo) bar;
インテリセンスと相性が悪かったりするため
参考:
- https://gfx.hatenablog.com/entry/2017/11/24/135343
- https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
Bad:
export default function(foo: string): string {
Good:
export function something(foo: string): string {
src ... Source code
@types ... Type definitions
prelude ... Independence utils for coding JavaScript without side effects
misc ... Independence utils for Misskey without side effects
service ... Common functions with side effects
queue ... Job queues and Jobs
server ... Web Server
client ... Client
mfm ... MFM
test ... Test code
SQLをクエリビルダで組み立てる際、使用するプレースホルダは重複してはならない 例えば
query.andWhere(new Brackets(qb => {
for (const type of ps.fileType) {
qb.orWhere(`:type = ANY(note.attachedFileTypes)`, { type: type });
}
}));
と書くと、ループ中でtype
というプレースホルダが複数回使われてしまいおかしくなる
だから次のようにする必要がある
query.andWhere(new Brackets(qb => {
for (const type of ps.fileType) {
const i = ps.fileType.indexOf(type);
qb.orWhere(`:type${i} = ANY(note.attachedFileTypes)`, { [`type${i}`]: type });
}
}));
const foo = await Foos.findOne({
bar: Not(null)
});
のようなクエリ(bar
がnull
ではない)は期待通りに動作しない。
次のようにします:
const foo = await Foos.findOne({
bar: Not(IsNull())
});
SQLを発行する際、パラメータがnull
になる可能性のある場合はSQL文を出し分けなければならない
例えば
query.where('file.folderId = :folderId', { folderId: ps.folderId });
という処理で、ps.folderId
がnull
だと結果的にfile.folderId = null
のようなクエリが発行されてしまい、これは正しいSQLではないので期待した結果が得られない
だから次のようにする必要がある
if (ps.folderId) {
query.where('file.folderId = :folderId', { folderId: ps.folderId });
} else {
query.where('file.folderId IS NULL');
}
SQLを発行する際、IN
のパラメータが[]
(空の配列)になる可能性のある場合はSQL文を出し分けなければならない
例えば
const users = await Users.find({
id: In(userIds)
});
という処理で、userIds
が[]
だと結果的にuser.id IN ()
のようなクエリが発行されてしまい、これは正しいSQLではないので期待した結果が得られない
だから次のようにする必要がある
const users = userIds.length > 0 ? await Users.find({
id: In(userIds)
}) : [];
SQLでは配列のインデックスは1始まり。
[a, b, c]
の a
にアクセスしたいなら[0]
ではなく[1]
と書く
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 undefined
が返ってくるので注意。
MongoDBはnull
で返してきてたので、その感覚でif (x === null)
とか書くとバグる。代わりにif (x == null)
と書いてください
データベースからレコードを取得するときに、プログラムの流れ的に(ほぼ)絶対undefined
にはならない場合でも、undefined
チェックしないとTypeScriptに怒られます。
でもいちいち複数行を費やして、発生するはずのないundefined
をチェックするのも面倒なので、ensure
というユーティリティ関数を用意しています。
例えば、
const user = await Users.findOne(userId);
// この時点で user の型は User | undefined
if (user == null) {
throw 'missing user';
}
// この時点で user の型は User
という処理をensure
を使うと
const user = await Users.findOne(userId).then(ensure);
// この時点で user の型は User
という風に書けます。
もちろんensure
内部でエラーを握りつぶすようなことはしておらず、万が一undefined
だった場合はPromiseがRejectされ後続の処理は実行されません。
const user = await Users.findOne(userId).then(ensure);
// 万が一 Users.findOne の結果が undefined だったら、ensure でエラーが発生するので
// この行に到達することは無い
// なので、.then(ensure) は
// if (user == null) {
// throw 'missing user';
// }
// の糖衣構文のような扱いです
コードの変更をした後、ormconfig.json
(npm run ormconfig
で生成)を用意し、
npm i -g ts-node
ts-node ./node_modules/typeorm/cli.js migration:generate -n 変更の名前
作成されたスクリプトは不必要な変更を含むため除去してください。