refactor: use ajv instead of cafy (#8324)

* wip

* wip

* Update abuse-user-reports.ts

* Update files.ts

* Update list-remote.ts

* Update list.ts

* Update show-users.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update update.ts

* Update search.ts

* Update reactions.ts

* Update search.ts

* wip

* wip

* wip

* wip

* Update update.ts

* Update relation.ts

* Update available.ts

* wip

* wip

* wip

* Update packages/backend/src/server/api/define.ts

Co-authored-by: Johann150 <johann.galle@protonmail.com>

* Update define.ts

* Update define.ts

* typo

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update update.ts

* wip

* Update signup.ts

* Update call.ts

* minimum for limit

* type

* remove needless annotation

* wip

* Update signup.ts

* wip

* wip

* fix

* Update create.ts

Co-authored-by: Johann150 <johann.galle@protonmail.com>
This commit is contained in:
syuilo
2022-02-19 14:05:32 +09:00
committed by GitHub
parent 59785ea04c
commit 510de87607
320 changed files with 4395 additions and 5939 deletions

View File

@ -1,4 +1,3 @@
import $ from 'cafy';
import define from '../../../define';
import { UserGroups, UserGroupJoinings } from '@/models/index';
import { genId } from '@/misc/gen-id';
@ -12,12 +11,6 @@ export const meta = {
kind: 'write:user-groups',
params: {
name: {
validator: $.str.range(1, 100),
},
},
res: {
type: 'object',
optional: false, nullable: false,
@ -25,8 +18,16 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1, maxLength: 100 },
},
required: ['name'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, user) => {
export default define(meta, paramDef, async (ps, user) => {
const userGroup = await UserGroups.insert({
id: genId(),
createdAt: new Date(),

View File

@ -1,5 +1,3 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { UserGroups } from '@/models/index';
@ -11,12 +9,6 @@ export const meta = {
kind: 'write:user-groups',
params: {
groupId: {
validator: $.type(ID),
},
},
errors: {
noSuchGroup: {
message: 'No such group.',
@ -26,8 +18,16 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {
groupId: { type: 'string', format: 'misskey:id' },
},
required: ['groupId'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, user) => {
export default define(meta, paramDef, async (ps, user) => {
const userGroup = await UserGroups.findOne({
id: ps.groupId,
userId: user.id,

View File

@ -1,5 +1,3 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../../define';
import { ApiError } from '../../../../error';
import { UserGroupJoinings, UserGroupInvitations } from '@/models/index';
@ -13,12 +11,6 @@ export const meta = {
kind: 'write:user-groups',
params: {
invitationId: {
validator: $.type(ID),
},
},
errors: {
noSuchInvitation: {
message: 'No such invitation.',
@ -28,8 +20,16 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {
invitationId: { type: 'string', format: 'misskey:id' },
},
required: ['invitationId'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, user) => {
export default define(meta, paramDef, async (ps, user) => {
// Fetch the invitation
const invitation = await UserGroupInvitations.findOne({
id: ps.invitationId,

View File

@ -1,5 +1,3 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../../define';
import { ApiError } from '../../../../error';
import { UserGroupInvitations } from '@/models/index';
@ -11,12 +9,6 @@ export const meta = {
kind: 'write:user-groups',
params: {
invitationId: {
validator: $.type(ID),
},
},
errors: {
noSuchInvitation: {
message: 'No such invitation.',
@ -26,8 +18,16 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {
invitationId: { type: 'string', format: 'misskey:id' },
},
required: ['invitationId'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, user) => {
export default define(meta, paramDef, async (ps, user) => {
// Fetch the invitation
const invitation = await UserGroupInvitations.findOne({
id: ps.invitationId,

View File

@ -1,5 +1,3 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { getUser } from '../../../common/getters';
@ -15,16 +13,6 @@ export const meta = {
kind: 'write:user-groups',
params: {
groupId: {
validator: $.type(ID),
},
userId: {
validator: $.type(ID),
},
},
errors: {
noSuchGroup: {
message: 'No such group.',
@ -52,8 +40,17 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {
groupId: { type: 'string', format: 'misskey:id' },
userId: { type: 'string', format: 'misskey:id' },
},
required: ['groupId', 'userId'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, me) => {
export default define(meta, paramDef, async (ps, me) => {
// Fetch the group
const userGroup = await UserGroups.findOne({
id: ps.groupId,

View File

@ -20,8 +20,14 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, me) => {
export default define(meta, paramDef, async (ps, me) => {
const ownedGroups = await UserGroups.find({
userId: me.id,
});

View File

@ -1,5 +1,3 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { UserGroups, UserGroupJoinings } from '@/models/index';
@ -11,12 +9,6 @@ export const meta = {
kind: 'write:user-groups',
params: {
groupId: {
validator: $.type(ID),
},
},
errors: {
noSuchGroup: {
message: 'No such group.',
@ -32,8 +24,16 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {
groupId: { type: 'string', format: 'misskey:id' },
},
required: ['groupId'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, me) => {
export default define(meta, paramDef, async (ps, me) => {
// Fetch the group
const userGroup = await UserGroups.findOne({
id: ps.groupId,

View File

@ -19,8 +19,14 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, me) => {
export default define(meta, paramDef, async (ps, me) => {
const userGroups = await UserGroups.find({
userId: me.id,
});

View File

@ -1,5 +1,3 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { getUser } from '../../../common/getters';
@ -12,16 +10,6 @@ export const meta = {
kind: 'write:user-groups',
params: {
groupId: {
validator: $.type(ID),
},
userId: {
validator: $.type(ID),
},
},
errors: {
noSuchGroup: {
message: 'No such group.',
@ -43,8 +31,17 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {
groupId: { type: 'string', format: 'misskey:id' },
userId: { type: 'string', format: 'misskey:id' },
},
required: ['groupId', 'userId'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, me) => {
export default define(meta, paramDef, async (ps, me) => {
// Fetch the group
const userGroup = await UserGroups.findOne({
id: ps.groupId,

View File

@ -1,5 +1,3 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { UserGroups, UserGroupJoinings } from '@/models/index';
@ -11,12 +9,6 @@ export const meta = {
kind: 'read:user-groups',
params: {
groupId: {
validator: $.type(ID),
},
},
res: {
type: 'object',
optional: false, nullable: false,
@ -32,8 +24,16 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {
groupId: { type: 'string', format: 'misskey:id' },
},
required: ['groupId'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, me) => {
export default define(meta, paramDef, async (ps, me) => {
// Fetch the group
const userGroup = await UserGroups.findOne({
id: ps.groupId,

View File

@ -1,5 +1,3 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { getUser } from '../../../common/getters';
@ -12,16 +10,6 @@ export const meta = {
kind: 'write:user-groups',
params: {
groupId: {
validator: $.type(ID),
},
userId: {
validator: $.type(ID),
},
},
res: {
type: 'object',
optional: false, nullable: false,
@ -49,8 +37,17 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {
groupId: { type: 'string', format: 'misskey:id' },
userId: { type: 'string', format: 'misskey:id' },
},
required: ['groupId', 'userId'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, me) => {
export default define(meta, paramDef, async (ps, me) => {
// Fetch the group
const userGroup = await UserGroups.findOne({
id: ps.groupId,

View File

@ -1,5 +1,3 @@
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { UserGroups } from '@/models/index';
@ -11,16 +9,6 @@ export const meta = {
kind: 'write:user-groups',
params: {
groupId: {
validator: $.type(ID),
},
name: {
validator: $.str.range(1, 100),
},
},
res: {
type: 'object',
optional: false, nullable: false,
@ -36,8 +24,17 @@ export const meta = {
},
} as const;
const paramDef = {
type: 'object',
properties: {
groupId: { type: 'string', format: 'misskey:id' },
name: { type: 'string', minLength: 1, maxLength: 100 },
},
required: ['groupId', 'name'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, me) => {
export default define(meta, paramDef, async (ps, me) => {
// Fetch the group
const userGroup = await UserGroups.findOne({
id: ps.groupId,