wip
This commit is contained in:
@@ -39,6 +39,10 @@ export type Channel = Packed<'Channel'>;
|
||||
export type Following = Packed<'Following'>;
|
||||
export type Blocking = Packed<'Blocking'>;
|
||||
export type Relay = Packed<'Relay'>;
|
||||
export type Role = Packed<'Role'>;
|
||||
export type RoleAssign = Packed<'RoleAssign'>;
|
||||
export type RolePolicy = Packed<'RolePolicy'>;
|
||||
export type RoleCondFormula = Packed<'RoleCondFormula'>;
|
||||
|
||||
export type LiteInstanceMetadata = {
|
||||
maintainerName: string | null;
|
||||
|
@@ -36,7 +36,12 @@ import { packedFlashSchema } from './schemas/flash.js';
|
||||
import { packedAdSchema } from './schemas/ad.js';
|
||||
import { packedAnnouncementSchema } from './schemas/announcement.js';
|
||||
import { packedRelaySchema } from './schemas/relay.js';
|
||||
import { packedRoleAssignSchema } from './schemas/role.js';
|
||||
import {
|
||||
packedRoleSchema,
|
||||
packedRoleAssignSchema,
|
||||
packedRolePolicySchema,
|
||||
packedRoleCondFormulaSchema,
|
||||
} from './schemas/role.js';
|
||||
import { Error, ApiError } from './schemas/error.js';
|
||||
import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type';
|
||||
|
||||
@@ -78,8 +83,10 @@ export const refs = {
|
||||
Ad: packedAdSchema,
|
||||
Announcement: packedAnnouncementSchema,
|
||||
Relay: packedRelaySchema,
|
||||
|
||||
Role: packedRoleSchema,
|
||||
RoleAssign: packedRoleAssignSchema,
|
||||
RolePolicy: packedRolePolicySchema,
|
||||
RoleCondFormula: packedRoleCondFormulaSchema,
|
||||
|
||||
Error: Error,
|
||||
ApiError: ApiError,
|
||||
|
@@ -14,31 +14,81 @@ export const packedRoleSchema = {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
},
|
||||
color: {
|
||||
type: ['string', 'null'],
|
||||
},
|
||||
iconUrl: {
|
||||
type: ['string', 'null'],
|
||||
},
|
||||
target: {
|
||||
enum: [
|
||||
'manual',
|
||||
'conditional',
|
||||
],
|
||||
}
|
||||
name: {
|
||||
type: 'string',
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
},
|
||||
color: {
|
||||
type: ['string', 'null'],
|
||||
},
|
||||
iconUrl: {
|
||||
type: ['string', 'null'],
|
||||
},
|
||||
target: {
|
||||
enum: [
|
||||
'manual',
|
||||
'conditional',
|
||||
],
|
||||
},
|
||||
condFormula: {
|
||||
type: 'object',
|
||||
// 循環参照なので難しい
|
||||
//$ref: 'https://misskey-hub.net/api/schemas/RoleCondFormula',
|
||||
},
|
||||
isPublic: {
|
||||
type: 'boolean',
|
||||
},
|
||||
isAdministrator: {
|
||||
type: 'boolean',
|
||||
},
|
||||
isModerator: {
|
||||
type: 'boolean',
|
||||
},
|
||||
isExplorable: {
|
||||
type: 'boolean',
|
||||
},
|
||||
asBadge: {
|
||||
type: 'boolean',
|
||||
},
|
||||
canEditMembersByModerator: {
|
||||
type: 'boolean',
|
||||
},
|
||||
displayOrder: {
|
||||
type: 'number',
|
||||
},
|
||||
policies: {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
$ref: 'https://misskey-hub.net/api/schemas/RolePolicy',
|
||||
},
|
||||
},
|
||||
usersCount: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'createdAt',
|
||||
'updatedAt',
|
||||
'updatedAt',
|
||||
'name',
|
||||
'description',
|
||||
'color',
|
||||
'iconUrl',
|
||||
'target',
|
||||
'condFormula',
|
||||
'isPublic',
|
||||
'isAdministrator',
|
||||
'isModerator',
|
||||
'isExplorable',
|
||||
'asBadge',
|
||||
'canEditMembersByModerator',
|
||||
'displayOrder',
|
||||
'policies',
|
||||
'usersCount',
|
||||
],
|
||||
}
|
||||
} as const satisfies JSONSchema7Definition;
|
||||
|
||||
export const packedRoleAssignSchema = {
|
||||
$id: 'https://misskey-hub.net/api/schemas/RoleAssign',
|
||||
@@ -50,20 +100,184 @@ export const packedRoleAssignSchema = {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
user: { $ref: 'https://misskey-hub.net/api/schemas/UserDetailed' },
|
||||
expiresAt: {
|
||||
oneOf: [{
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
}, {
|
||||
type: 'null',
|
||||
}],
|
||||
},
|
||||
user: { $ref: 'https://misskey-hub.net/api/schemas/UserDetailed' },
|
||||
expiresAt: {
|
||||
oneOf: [{
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
}, {
|
||||
type: 'null',
|
||||
}],
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'createdAt',
|
||||
'user',
|
||||
'expiresAt',
|
||||
'user',
|
||||
'expiresAt',
|
||||
],
|
||||
} as const satisfies JSONSchema7Definition;
|
||||
|
||||
export const packedRolePolicySchema = {
|
||||
$id: 'https://misskey-hub.net/api/schemas/RolePolicy',
|
||||
|
||||
type: 'object',
|
||||
properties: {
|
||||
useDefault: { type: 'boolean' },
|
||||
priority: { type: 'number' },
|
||||
value: { additionalProperties: true },
|
||||
},
|
||||
required: [
|
||||
'useDefault',
|
||||
'priority',
|
||||
'value',
|
||||
],
|
||||
} as const satisfies JSONSchema7Definition;
|
||||
|
||||
export const packedRoleCondFormulaSchema = {
|
||||
$id: 'https://misskey-hub.net/api/schemas/RoleCondFormula',
|
||||
|
||||
oneOf: [
|
||||
{ $ref: '#/$defs/and' },
|
||||
{ $ref: '#/$defs/or' },
|
||||
{ $ref: '#/$defs/not' },
|
||||
{ $ref: '#/$defs/isLocal' },
|
||||
{ $ref: '#/$defs/isRemote' },
|
||||
{ $ref: '#/$defs/createdLessThan' },
|
||||
{ $ref: '#/$defs/createdMoreThan' },
|
||||
{ $ref: '#/$defs/createdLessThanOrEq' },
|
||||
{ $ref: '#/$defs/createdMoreThanOrEq' },
|
||||
{ $ref: '#/$defs/followersLessThanOrEq' },
|
||||
{ $ref: '#/$defs/followersMoreThanOrEq' },
|
||||
{ $ref: '#/$defs/followingLessThanOrEq' },
|
||||
{ $ref: '#/$defs/followingMoreThanOrEq' },
|
||||
{ $ref: '#/$defs/notesLessThanOrEq' },
|
||||
{ $ref: '#/$defs/notesMoreThanOrEq' },
|
||||
],
|
||||
$defs: {
|
||||
and: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'and' },
|
||||
values: {
|
||||
type: 'array',
|
||||
items: { $ref: '#' },
|
||||
},
|
||||
},
|
||||
required: ['type', 'values'],
|
||||
},
|
||||
or: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'or' },
|
||||
values: {
|
||||
type: 'array',
|
||||
items: { $ref: '#' },
|
||||
},
|
||||
},
|
||||
required: ['type', 'values'],
|
||||
},
|
||||
not: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'not' },
|
||||
value: { $ref: '#' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
isLocal: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'isLocal' },
|
||||
},
|
||||
required: ['type'],
|
||||
},
|
||||
isRemote: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'isRemote' },
|
||||
},
|
||||
required: ['type'],
|
||||
},
|
||||
createdLessThan: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'createdLessThan' },
|
||||
value: { type: 'number' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
createdMoreThan: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'createdMoreThan' },
|
||||
value: { type: 'number' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
createdLessThanOrEq: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'createdLessThanOrEq' },
|
||||
value: { type: 'number' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
createdMoreThanOrEq: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'createdMoreThanOrEq' },
|
||||
value: { type: 'number' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
followersLessThanOrEq: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'followersLessThanOrEq' },
|
||||
value: { type: 'number' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
followersMoreThanOrEq: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'followersMoreThanOrEq' },
|
||||
value: { type: 'number' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
followingLessThanOrEq: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'followingLessThanOrEq' },
|
||||
value: { type: 'number' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
followingMoreThanOrEq: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'followingMoreThanOrEq' },
|
||||
value: { type: 'number' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
notesLessThanOrEq: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'notesLessThanOrEq' },
|
||||
value: { type: 'number' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
notesMoreThanOrEq: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { const: 'notesMoreThanOrEq' },
|
||||
value: { type: 'number' },
|
||||
},
|
||||
required: ['type', 'value'],
|
||||
},
|
||||
}
|
||||
} as const satisfies JSONSchema7Definition;
|
||||
|
@@ -100,9 +100,12 @@ describe('schemas', () => {
|
||||
test('relay', () => {
|
||||
type Relay = Packed<'Relay'>;
|
||||
});
|
||||
test('role': () => {
|
||||
|
||||
test('role', () => {
|
||||
type Role = Packed<'Role'>;
|
||||
type CF = Role['condFormula'];
|
||||
type RoleAssign = Packed<'RoleAssign'>;
|
||||
type RolePolicy = Packed<'RolePolicy'>;
|
||||
type RoleCondFormula = Packed<'RoleCondFormula'>;
|
||||
});
|
||||
test('error', () => {
|
||||
type Error = Packed<'Error'>;
|
||||
|
Reference in New Issue
Block a user