From e1b4a0438e1dc9f0453aa4470521fee1a5d1968a Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 29 May 2023 14:03:39 +0000 Subject: [PATCH] RoleCondFormulaValue: property type assertion --- packages/backend/src/core/RoleService.ts | 2 +- packages/backend/src/models/entities/Role.ts | 79 +------------------ packages/misskey-js/src/schemas/role.ts | 83 +++++++++++++++++++- pnpm-lock.yaml | 10 +-- 4 files changed, 88 insertions(+), 86 deletions(-) diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts index 7bdf1364ef..ec61653d15 100644 --- a/packages/backend/src/core/RoleService.ts +++ b/packages/backend/src/core/RoleService.ts @@ -8,7 +8,7 @@ import { DI } from '@/di-symbols.js'; import { bindThis } from '@/decorators.js'; import { MetaService } from '@/core/MetaService.js'; import { CacheService } from '@/core/CacheService.js'; -import type { RoleCondFormulaValue } from '@/models/entities/Role.js'; +import type { RoleCondFormulaValue } from 'misskey-js/built/schemas/role.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { StreamMessages } from '@/server/api/stream/types.js'; import { IdService } from '@/core/IdService.js'; diff --git a/packages/backend/src/models/entities/Role.ts b/packages/backend/src/models/entities/Role.ts index 61f40d59da..afa615c679 100644 --- a/packages/backend/src/models/entities/Role.ts +++ b/packages/backend/src/models/entities/Role.ts @@ -1,83 +1,6 @@ import { Entity, Column, PrimaryColumn } from 'typeorm'; import { id } from '../id.js'; - -type CondFormulaValueAnd = { - type: 'and'; - values: RoleCondFormulaValue[]; -}; - -type CondFormulaValueOr = { - type: 'or'; - values: RoleCondFormulaValue[]; -}; - -type CondFormulaValueNot = { - type: 'not'; - value: RoleCondFormulaValue; -}; - -type CondFormulaValueIsLocal = { - type: 'isLocal'; -}; - -type CondFormulaValueIsRemote = { - type: 'isRemote'; -}; - -type CondFormulaValueCreatedLessThan = { - type: 'createdLessThan'; - sec: number; -}; - -type CondFormulaValueCreatedMoreThan = { - type: 'createdMoreThan'; - sec: number; -}; - -type CondFormulaValueFollowersLessThanOrEq = { - type: 'followersLessThanOrEq'; - value: number; -}; - -type CondFormulaValueFollowersMoreThanOrEq = { - type: 'followersMoreThanOrEq'; - value: number; -}; - -type CondFormulaValueFollowingLessThanOrEq = { - type: 'followingLessThanOrEq'; - value: number; -}; - -type CondFormulaValueFollowingMoreThanOrEq = { - type: 'followingMoreThanOrEq'; - value: number; -}; - -type CondFormulaValueNotesLessThanOrEq = { - type: 'notesLessThanOrEq'; - value: number; -}; - -type CondFormulaValueNotesMoreThanOrEq = { - type: 'notesMoreThanOrEq'; - value: number; -}; - -export type RoleCondFormulaValue = - CondFormulaValueAnd | - CondFormulaValueOr | - CondFormulaValueNot | - CondFormulaValueIsLocal | - CondFormulaValueIsRemote | - CondFormulaValueCreatedLessThan | - CondFormulaValueCreatedMoreThan | - CondFormulaValueFollowersLessThanOrEq | - CondFormulaValueFollowersMoreThanOrEq | - CondFormulaValueFollowingLessThanOrEq | - CondFormulaValueFollowingMoreThanOrEq | - CondFormulaValueNotesLessThanOrEq | - CondFormulaValueNotesMoreThanOrEq; +import type { RoleCondFormulaValue } from 'misskey-js/built/schemas/role.js'; @Entity() export class Role { diff --git a/packages/misskey-js/src/schemas/role.ts b/packages/misskey-js/src/schemas/role.ts index 9e64cf3bfb..75531de181 100644 --- a/packages/misskey-js/src/schemas/role.ts +++ b/packages/misskey-js/src/schemas/role.ts @@ -34,9 +34,10 @@ export const packedRoleSchema = { }, condFormula: { type: 'object', - // 循環参照なので難しい //$ref: 'https://misskey-hub.net/api/schemas/RoleCondFormula', - }, + // 循環参照なので難しい + // のでschema-typeのproperty type assertionに頼る + } as unknown as RoleCondFormulaValue, isPublic: { type: 'boolean', }, @@ -281,3 +282,81 @@ export const packedRoleCondFormulaSchema = { }, } } as const satisfies JSONSchema7Definition; + +type CondFormulaValueAnd = { + type: 'and'; + values: RoleCondFormulaValue[]; +}; + +type CondFormulaValueOr = { + type: 'or'; + values: RoleCondFormulaValue[]; +}; + +type CondFormulaValueNot = { + type: 'not'; + value: RoleCondFormulaValue; +}; + +type CondFormulaValueIsLocal = { + type: 'isLocal'; +}; + +type CondFormulaValueIsRemote = { + type: 'isRemote'; +}; + +type CondFormulaValueCreatedLessThan = { + type: 'createdLessThan'; + sec: number; +}; + +type CondFormulaValueCreatedMoreThan = { + type: 'createdMoreThan'; + sec: number; +}; + +type CondFormulaValueFollowersLessThanOrEq = { + type: 'followersLessThanOrEq'; + value: number; +}; + +type CondFormulaValueFollowersMoreThanOrEq = { + type: 'followersMoreThanOrEq'; + value: number; +}; + +type CondFormulaValueFollowingLessThanOrEq = { + type: 'followingLessThanOrEq'; + value: number; +}; + +type CondFormulaValueFollowingMoreThanOrEq = { + type: 'followingMoreThanOrEq'; + value: number; +}; + +type CondFormulaValueNotesLessThanOrEq = { + type: 'notesLessThanOrEq'; + value: number; +}; + +type CondFormulaValueNotesMoreThanOrEq = { + type: 'notesMoreThanOrEq'; + value: number; +}; + +export type RoleCondFormulaValue = + CondFormulaValueAnd | + CondFormulaValueOr | + CondFormulaValueNot | + CondFormulaValueIsLocal | + CondFormulaValueIsRemote | + CondFormulaValueCreatedLessThan | + CondFormulaValueCreatedMoreThan | + CondFormulaValueFollowersLessThanOrEq | + CondFormulaValueFollowersMoreThanOrEq | + CondFormulaValueFollowingLessThanOrEq | + CondFormulaValueFollowingMoreThanOrEq | + CondFormulaValueNotesLessThanOrEq | + CondFormulaValueNotesMoreThanOrEq; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 12fe3734fa..6755c7a161 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -630,7 +630,7 @@ importers: version: 29.5.0 schema-type: specifier: github:misskey-dev/schema-type - version: github.com/misskey-dev/schema-type/04addbe29c488e9e749bb9fe09812407da132e11(typescript@5.0.4) + version: github.com/misskey-dev/schema-type/d4ff8d1c43883a0facacc9ec47ec50aa239828bc(typescript@5.0.4) packages/frontend: dependencies: @@ -1030,7 +1030,7 @@ importers: version: 4.4.0 schema-type: specifier: github:misskey-dev/schema-type - version: github.com/misskey-dev/schema-type/04addbe29c488e9e749bb9fe09812407da132e11(typescript@5.0.4) + version: github.com/misskey-dev/schema-type/d4ff8d1c43883a0facacc9ec47ec50aa239828bc(typescript@5.0.4) ts-essentials: specifier: ^9.3.2 version: 9.3.2(typescript@5.0.4) @@ -20557,9 +20557,9 @@ packages: version: 0.0.0 dev: false - github.com/misskey-dev/schema-type/04addbe29c488e9e749bb9fe09812407da132e11(typescript@5.0.4): - resolution: {tarball: https://codeload.github.com/misskey-dev/schema-type/tar.gz/04addbe29c488e9e749bb9fe09812407da132e11} - id: github.com/misskey-dev/schema-type/04addbe29c488e9e749bb9fe09812407da132e11 + github.com/misskey-dev/schema-type/d4ff8d1c43883a0facacc9ec47ec50aa239828bc(typescript@5.0.4): + resolution: {tarball: https://codeload.github.com/misskey-dev/schema-type/tar.gz/d4ff8d1c43883a0facacc9ec47ec50aa239828bc} + id: github.com/misskey-dev/schema-type/d4ff8d1c43883a0facacc9ec47ec50aa239828bc name: schema-type version: 1.0.0 dependencies: