RoleCondFormulaValue: property type assertion

This commit is contained in:
tamaina 2023-05-29 14:03:39 +00:00
parent 93ea327660
commit e1b4a0438e
4 changed files with 88 additions and 86 deletions

View file

@ -8,7 +8,7 @@ import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import { MetaService } from '@/core/MetaService.js'; import { MetaService } from '@/core/MetaService.js';
import { CacheService } from '@/core/CacheService.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 { UserEntityService } from '@/core/entities/UserEntityService.js';
import { StreamMessages } from '@/server/api/stream/types.js'; import { StreamMessages } from '@/server/api/stream/types.js';
import { IdService } from '@/core/IdService.js'; import { IdService } from '@/core/IdService.js';

View file

@ -1,83 +1,6 @@
import { Entity, Column, PrimaryColumn } from 'typeorm'; import { Entity, Column, PrimaryColumn } from 'typeorm';
import { id } from '../id.js'; import { id } from '../id.js';
import type { RoleCondFormulaValue } from 'misskey-js/built/schemas/role.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;
@Entity() @Entity()
export class Role { export class Role {

View file

@ -34,9 +34,10 @@ export const packedRoleSchema = {
}, },
condFormula: { condFormula: {
type: 'object', type: 'object',
// 循環参照なので難しい
//$ref: 'https://misskey-hub.net/api/schemas/RoleCondFormula', //$ref: 'https://misskey-hub.net/api/schemas/RoleCondFormula',
}, // 循環参照なので難しい
// のでschema-typeのproperty type assertionに頼る
} as unknown as RoleCondFormulaValue,
isPublic: { isPublic: {
type: 'boolean', type: 'boolean',
}, },
@ -281,3 +282,81 @@ export const packedRoleCondFormulaSchema = {
}, },
} }
} as const satisfies JSONSchema7Definition; } 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;

View file

@ -630,7 +630,7 @@ importers:
version: 29.5.0 version: 29.5.0
schema-type: schema-type:
specifier: github:misskey-dev/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: packages/frontend:
dependencies: dependencies:
@ -1030,7 +1030,7 @@ importers:
version: 4.4.0 version: 4.4.0
schema-type: schema-type:
specifier: github:misskey-dev/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: ts-essentials:
specifier: ^9.3.2 specifier: ^9.3.2
version: 9.3.2(typescript@5.0.4) version: 9.3.2(typescript@5.0.4)
@ -20557,9 +20557,9 @@ packages:
version: 0.0.0 version: 0.0.0
dev: false dev: false
github.com/misskey-dev/schema-type/04addbe29c488e9e749bb9fe09812407da132e11(typescript@5.0.4): github.com/misskey-dev/schema-type/d4ff8d1c43883a0facacc9ec47ec50aa239828bc(typescript@5.0.4):
resolution: {tarball: https://codeload.github.com/misskey-dev/schema-type/tar.gz/04addbe29c488e9e749bb9fe09812407da132e11} resolution: {tarball: https://codeload.github.com/misskey-dev/schema-type/tar.gz/d4ff8d1c43883a0facacc9ec47ec50aa239828bc}
id: github.com/misskey-dev/schema-type/04addbe29c488e9e749bb9fe09812407da132e11 id: github.com/misskey-dev/schema-type/d4ff8d1c43883a0facacc9ec47ec50aa239828bc
name: schema-type name: schema-type
version: 1.0.0 version: 1.0.0
dependencies: dependencies: