refactor(schema): simplify validation and OpenAPI generation (#2709)

This commit is contained in:
Hampus authored and GitHub committed 2026-09-11 23:24:26 +02:00
1 parent 4bc5593f9f
commit de1fd95a99
510 files changed
+29494 -36131

No files matched your search

@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
export type MessageFetchCacheHit = 'jump' | 'before' | 'after';
@@ -157,7 +157,7 @@ export type MessageFetchPreflightSnapshot = SnapshotFrom<typeof messageFetchPref
export type MessageFetchExecutionSnapshot = SnapshotFrom<typeof messageFetchExecutionMachine>;
export function createMessageFetchPreflightSnapshot(input: MessageFetchPreflightInput): MessageFetchPreflightSnapshot {
return getInitialSnapshot(messageFetchPreflightMachine, input);
return initialTransition(messageFetchPreflightMachine, input)[0];
}
export function transitionMessageFetchPreflightSnapshot(
@@ -178,7 +178,7 @@ export function resolveMessageFetchPreflightDecision(input: MessageFetchPrefligh
}
export function createMessageFetchExecutionSnapshot(input: MessageFetchExecutionInput): MessageFetchExecutionSnapshot {
return getInitialSnapshot(messageFetchExecutionMachine, input);
return initialTransition(messageFetchExecutionMachine, input)[0];
}
export function transitionMessageFetchExecutionSnapshot(
@@ -5,7 +5,7 @@ import {
calculateAroundPaginationState,
} from '@app/features/messaging/utils/MessagePaginationUtils';
import {compare as compareSnowflakes} from '@fluxer/snowflake/src/SnowflakeUtils';
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
export interface MessagePageStateInput {
before: string | null;
@@ -158,7 +158,7 @@ export const messagePageStateMachine = setup({
export type MessagePageStateSnapshot = SnapshotFrom<typeof messagePageStateMachine>;
export function createMessagePageStateSnapshot(input: MessagePageStateInput): MessagePageStateSnapshot {
return getInitialSnapshot(messagePageStateMachine, input);
return initialTransition(messagePageStateMachine, input)[0];
}
export function transitionMessagePageStateSnapshot(
@@ -184,7 +184,7 @@ export const useMarkdownFormattingShortcut = ({
value: string;
setValue: React.Dispatch<React.SetStateAction<string>>;
handleTextChange: (newValue: string, oldValue: string) => void;
previousValueRef: React.MutableRefObject<string>;
previousValueRef: React.RefObject<string>;
}): ((event: KeyboardEvent<HTMLTextAreaElement>) => void) => {
return useCallback(
(event: KeyboardEvent<HTMLTextAreaElement>) => {
@@ -103,8 +103,8 @@ interface UseTextareaAutocompleteParams {
value: string;
setValue: React.Dispatch<React.SetStateAction<string>>;
textareaRef: React.RefObject<HTMLTextAreaElement | null>;
segmentManagerRef: React.MutableRefObject<TextareaSegmentManager>;
previousValueRef: React.MutableRefObject<string>;
segmentManagerRef: React.RefObject<TextareaSegmentManager>;
previousValueRef: React.RefObject<string>;
prepareTextChange: PrepareTextareaTextChange;
allowedTriggers?: Array<TriggerType>;
maxActualLength?: number;
@@ -12,8 +12,8 @@ interface UseTextareaDraftAndTypingOptions {
setValue: React.Dispatch<React.SetStateAction<string>>;
draft: string | null;
draftSegments?: ReadonlyArray<MentionSegment> | null;
previousValueRef: React.MutableRefObject<string>;
segmentManagerRef?: React.MutableRefObject<TextareaSegmentManager>;
previousValueRef: React.RefObject<string>;
segmentManagerRef?: React.RefObject<TextareaSegmentManager>;
isAutocompleteAttached: boolean;
enabled: boolean;
typingEnabled?: boolean;
@@ -13,7 +13,7 @@ interface UseTextareaEditingOptions {
value: string;
setValue: React.Dispatch<React.SetStateAction<string>>;
textareaRef: React.RefObject<HTMLTextAreaElement | null>;
previousValueRef: React.MutableRefObject<string>;
previousValueRef: React.RefObject<string>;
}
export const useTextareaEditing = ({
@@ -18,8 +18,8 @@ interface UseTextareaEmojiPickerReturn {
interface UseTextareaEmojiPickerParams {
setValue: React.Dispatch<React.SetStateAction<string>>;
textareaRef: React.RefObject<HTMLTextAreaElement | null>;
segmentManagerRef: React.MutableRefObject<TextareaSegmentManager>;
previousValueRef: React.MutableRefObject<string>;
segmentManagerRef: React.RefObject<TextareaSegmentManager>;
previousValueRef: React.RefObject<string>;
prepareTextChange: PrepareTextareaTextChange;
channelId?: string;
maxActualLength?: number;
@@ -31,9 +31,9 @@ interface UseTextareaExpressionHandlersOptions {
newText: string;
newSegments: Array<MentionSegment>;
};
previousValueRef: React.MutableRefObject<string>;
previousValueRef: React.RefObject<string>;
prepareTextChange: PrepareTextareaTextChange;
segmentManagerRef: React.MutableRefObject<TextareaSegmentManager>;
segmentManagerRef: React.RefObject<TextareaSegmentManager>;
sendOptimisticMessage: (
messageData: {
content: string;
@@ -21,7 +21,7 @@ interface UseTextareaKeyboardOptions {
value: string;
setValue: React.Dispatch<React.SetStateAction<string>>;
handleTextChange: (newValue: string, previousValue: string) => void;
previousValueRef: React.MutableRefObject<string>;
previousValueRef: React.RefObject<string>;
clearSegments: () => void;
replyingMessage: {
messageId: string;
@@ -21,9 +21,9 @@ import {useCallback, useEffect} from 'react';
interface UseTextareaPasteParams {
channel?: Channel | null;
textareaRef: React.RefObject<HTMLTextAreaElement | null>;
segmentManagerRef: React.MutableRefObject<TextareaSegmentManager>;
segmentManagerRef: React.RefObject<TextareaSegmentManager>;
setValue: React.Dispatch<React.SetStateAction<string>>;
previousValueRef: React.MutableRefObject<string>;
previousValueRef: React.RefObject<string>;
prepareTextChange: PrepareTextareaTextChange;
maxMessageLength?: number;
onPasteExceedsLimit?: (pastedText: string) => void;
@@ -5,8 +5,8 @@ import {TextareaSegmentManager} from '@app/features/messaging/utils/TextareaSegm
import {useCallback, useRef} from 'react';
interface UseTextareaSegmentsReturn {
segmentManagerRef: React.MutableRefObject<TextareaSegmentManager>;
previousValueRef: React.MutableRefObject<string>;
segmentManagerRef: React.RefObject<TextareaSegmentManager>;
previousValueRef: React.RefObject<string>;
displayToActual: (displayText: string) => string;
rememberSegmentsForValue: (value: string, segments?: ReadonlyArray<MentionSegment>) => void;
prepareTextChange: (nextValue: string, nextSegments: ReadonlyArray<MentionSegment>) => void;
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
export interface ChannelIncomingMessageInput {
hasNonceMatch: boolean;
@@ -111,7 +111,7 @@ export type ChannelIncomingMessageSnapshot = SnapshotFrom<typeof channelIncoming
export function createChannelIncomingMessageSnapshot(
input: ChannelIncomingMessageInput,
): ChannelIncomingMessageSnapshot {
return getInitialSnapshot(channelIncomingMessageMachine, input);
return initialTransition(channelIncomingMessageMachine, input)[0];
}
export function transitionChannelIncomingMessageSnapshot(
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {compare as compareSnowflakes} from '@fluxer/snowflake/src/SnowflakeUtils';
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
export interface ChannelMessagesLoadInput {
isBefore: boolean;
@@ -124,7 +124,7 @@ export const channelMessagesLoadMachine = setup({
export type ChannelMessagesLoadSnapshot = SnapshotFrom<typeof channelMessagesLoadMachine>;
export function createChannelMessagesLoadSnapshot(input: ChannelMessagesLoadInput): ChannelMessagesLoadSnapshot {
return getInitialSnapshot(channelMessagesLoadMachine, input);
return initialTransition(channelMessagesLoadMachine, input)[0];
}
export function transitionChannelMessagesLoadSnapshot(
@@ -247,7 +247,7 @@ export const channelMessagesWindowMachine = setup({
export type ChannelMessagesWindowSnapshot = SnapshotFrom<typeof channelMessagesWindowMachine>;
export function createChannelMessagesWindowSnapshot(input: ChannelMessagesWindowInput): ChannelMessagesWindowSnapshot {
return getInitialSnapshot(channelMessagesWindowMachine, input);
return initialTransition(channelMessagesWindowMachine, input)[0];
}
export function transitionChannelMessagesWindowSnapshot(
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
export type MentionType = '@everyone' | '@here' | 'role';
@@ -121,7 +121,7 @@ export const mentionConfirmationStateMachine = setup({
});
export function createMentionConfirmationSnapshot(): MentionConfirmationSnapshot {
return getInitialSnapshot(mentionConfirmationStateMachine);
return initialTransition(mentionConfirmationStateMachine)[0];
}
export function transitionMentionConfirmationSnapshot(
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
export interface MessageQueuePayloadRouteInput {
payloadType?: string;
@@ -275,7 +275,7 @@ export type MessageLocalSendRateLimitSnapshot = SnapshotFrom<typeof messageLocal
export function createMessageQueuePayloadRouteSnapshot(
input: MessageQueuePayloadRouteInput,
): MessageQueuePayloadRouteSnapshot {
return getInitialSnapshot(messageQueuePayloadRouteMachine, input);
return initialTransition(messageQueuePayloadRouteMachine, input)[0];
}
export function transitionMessageQueuePayloadRouteSnapshot(
@@ -307,7 +307,7 @@ export function resolveMessageQueuePayloadRouteDecision(
export function createMessageQueueSendExecutionSnapshot(
input: MessageQueueSendExecutionInput,
): MessageQueueSendExecutionSnapshot {
return getInitialSnapshot(messageQueueSendExecutionMachine, input);
return initialTransition(messageQueueSendExecutionMachine, input)[0];
}
export function transitionMessageQueueSendExecutionSnapshot(
@@ -337,7 +337,7 @@ export function resolveMessageQueueSendExecutionDecision(
export function createMessageQueueRequestOutcomeSnapshot(
input: MessageQueueRequestOutcomeInput,
): MessageQueueRequestOutcomeSnapshot {
return getInitialSnapshot(messageQueueRequestOutcomeMachine, input);
return initialTransition(messageQueueRequestOutcomeMachine, input)[0];
}
export function transitionMessageQueueRequestOutcomeSnapshot(
@@ -369,7 +369,7 @@ export function resolveMessageQueueRequestOutcomeDecision(
export function createMessageLocalSendRateLimitSnapshot(
input: MessageLocalSendRateLimitInput,
): MessageLocalSendRateLimitSnapshot {
return getInitialSnapshot(messageLocalSendRateLimitMachine, input);
return initialTransition(messageLocalSendRateLimitMachine, input)[0];
}
export function transitionMessageLocalSendRateLimitSnapshot(
@@ -2,7 +2,7 @@
import type {ReactionEmoji} from '@app/features/messaging/utils/ReactionUtils';
import type {MessageReaction} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
export interface ReactionRecord {
emoji: ReactionEmoji;
@@ -366,7 +366,7 @@ export function createReactionMachineSnapshot(
map: ReactionMap = emptyMap(),
currentUserId?: string | null,
): ReactionMachineSnapshot {
return getInitialSnapshot(reactionStateMachine, {map, currentUserId});
return initialTransition(reactionStateMachine, {map, currentUserId})[0];
}
export function transitionReactionSnapshot(
@@ -2,7 +2,7 @@
import {User} from '@app/features/user/models/User';
import type {UserPartial} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
import {assign, getInitialSnapshot, type SnapshotFrom, setup, transition} from 'xstate';
import {assign, initialTransition, type SnapshotFrom, setup, transition} from 'xstate';
export type FetchStatus = 'idle' | 'pending' | 'success' | 'error';
@@ -336,7 +336,7 @@ export const reactionUsersStateMachine = setup({
export type ReactionUsersMachineSnapshot = SnapshotFrom<typeof reactionUsersStateMachine>;
export function createReactionUsersSnapshot(requestSerial = 0): ReactionUsersMachineSnapshot {
return getInitialSnapshot(reactionUsersStateMachine, {requestSerial});
return initialTransition(reactionUsersStateMachine, {requestSerial})[0];
}
export function transitionReactionUsersSnapshot(
@@ -9,8 +9,8 @@ export type PrepareTextareaTextChange = (nextValue: string, nextSegments: Readon
export interface ApplyTextareaTextChangeOptions {
textareaRef: React.RefObject<HTMLTextAreaElement | null>;
setValue: React.Dispatch<React.SetStateAction<string>>;
segmentManagerRef: React.MutableRefObject<TextareaSegmentManager>;
previousValueRef: React.MutableRefObject<string>;
segmentManagerRef: React.RefObject<TextareaSegmentManager>;
previousValueRef: React.RefObject<string>;
prepareTextChange: PrepareTextareaTextChange;
nextValue: string;
nextSegments?: ReadonlyArray<MentionSegment>;