diff --git a/packages/types/src/v20170710/assignments.ts b/packages/types/src/v20170710/assignments.ts index 0e48f9ba..b73a49f4 100644 --- a/packages/types/src/v20170710/assignments.ts +++ b/packages/types/src/v20170710/assignments.ts @@ -42,7 +42,7 @@ export interface Assignment extends BaseResource { started_at: DatableString | null; /** Unique identifier of the associated subject. */ - subject_id: number; + subject_id: SafeInteger; /** The type of the associated subject. */ subject_type: SubjectType; @@ -59,7 +59,7 @@ export interface Assignment extends BaseResource { }; /** A unique number identifying the assignment. */ - id: number; + id: SafeInteger; /** The kind of object returned. */ object: "assignment"; diff --git a/packages/types/src/v20170710/base.ts b/packages/types/src/v20170710/base.ts index 52b4625a..06920c70 100644 --- a/packages/types/src/v20170710/base.ts +++ b/packages/types/src/v20170710/base.ts @@ -98,7 +98,7 @@ export interface BaseCollection { next_url: string | null; /** Maximum number of items delivered per page for this collection. */ - per_page: number; + per_page: SafeInteger; /** * The URL of the previous page of results. If there are no results at all or no previous page to go to, the value @@ -108,7 +108,7 @@ export interface BaseCollection { }; /** The total number of items in the collection. */ - total_count: number; + total_count: SafeInteger; /** The URL of the request. For collections, that will contain all the filters and options you've passed to the API. */ url: string; @@ -170,7 +170,7 @@ export interface BaseReport { */ export interface ApiError { /** An HTTP status code indicating the type of error. */ - code: number; + code: SafeInteger; /** A message string that describes the error. */ error: string; diff --git a/packages/types/src/v20170710/level-progressions.ts b/packages/types/src/v20170710/level-progressions.ts index 6cb4c551..0bf0832b 100644 --- a/packages/types/src/v20170710/level-progressions.ts +++ b/packages/types/src/v20170710/level-progressions.ts @@ -1,4 +1,4 @@ -import type { BaseCollection, BaseResource, DatableString, Level } from "./base.js"; +import type { BaseCollection, BaseResource, DatableString, Level, SafeInteger } from "./base.js"; /** * Level progressions contain information about a user's progress through the WaniKani levels. @@ -43,7 +43,7 @@ export interface LevelProgression extends BaseResource { }; /** A unique number identifying the level progression. */ - id: number; + id: SafeInteger; /** The kind of object returned. */ object: "level_progression"; diff --git a/packages/types/src/v20170710/resets.ts b/packages/types/src/v20170710/resets.ts index c950fcd6..924c5a8d 100644 --- a/packages/types/src/v20170710/resets.ts +++ b/packages/types/src/v20170710/resets.ts @@ -1,4 +1,4 @@ -import type { BaseCollection, BaseResource, DatableString, Level } from "./base.js"; +import type { BaseCollection, BaseResource, DatableString, Level, SafeInteger } from "./base.js"; /** * Users can reset their progress back to any level at or below their current level. When they reset to a particular @@ -27,7 +27,7 @@ export interface Reset extends BaseResource { }; /** A unique number identifying the reset. */ - id: number; + id: SafeInteger; /** The kind of object returned. */ object: "reset"; diff --git a/packages/types/src/v20170710/review-statistics.ts b/packages/types/src/v20170710/review-statistics.ts index d3482218..37ceabc7 100644 --- a/packages/types/src/v20170710/review-statistics.ts +++ b/packages/types/src/v20170710/review-statistics.ts @@ -22,41 +22,41 @@ export interface ReviewStatistic extends BaseResource { hidden: boolean; /** Total number of correct answers submitted for the meaning of the associated subject. */ - meaning_correct: number; + meaning_correct: SafeInteger; /** The current, uninterrupted series of correct answers given for the meaning of the associated subject. */ - meaning_current_streak: number; + meaning_current_streak: SafeInteger; /** Total number of incorrect answers submitted for the meaning of the associated subject. */ - meaning_incorrect: number; + meaning_incorrect: SafeInteger; /** The longest, uninterrupted series of correct answers ever given for the meaning of the associated subject. */ - meaning_max_streak: number; + meaning_max_streak: SafeInteger; /** The overall correct answer rate by the user for the subject, including both meaning and reading. */ percentage_correct: number; /** Total number of correct answers submitted for the reading of the associated subject. */ - reading_correct: number; + reading_correct: SafeInteger; /** The current, uninterrupted series of correct answers given for the reading of the associated subject. */ - reading_current_streak: number; + reading_current_streak: SafeInteger; /** Total number of incorrect answers submitted for the reading of the associated subject. */ - reading_incorrect: number; + reading_incorrect: SafeInteger; /** The longest, uninterrupted series of correct answers ever given for the reading of the associated subject. */ - reading_max_streak: number; + reading_max_streak: SafeInteger; /** Unique identifier of the associated subject. */ - subject_id: number; + subject_id: SafeInteger; /** The type of the associated subject. */ subject_type: SubjectType; }; /** A unique number identifying the review statistic. */ - id: number; + id: SafeInteger; /** The kind of object returned. */ object: "review_statistic"; diff --git a/packages/types/src/v20170710/reviews.ts b/packages/types/src/v20170710/reviews.ts index 8693bf74..06fa536c 100644 --- a/packages/types/src/v20170710/reviews.ts +++ b/packages/types/src/v20170710/reviews.ts @@ -16,7 +16,7 @@ export interface Review extends BaseResource { /** Data for the returned review. */ data: { /** Unique identifier of the associated assignment. */ - assignment_id: number; + assignment_id: SafeInteger; /** Timestamp when the review was created. */ created_at: DatableString; @@ -28,23 +28,23 @@ export interface Review extends BaseResource { ending_srs_stage: SpacedRepetitionSystemStageNumber; /** The number of times the user has answered the meaning incorrectly. */ - incorrect_meaning_answers: number; + incorrect_meaning_answers: SafeInteger; /** The number of times the user has answered the reading incorrectly. */ - incorrect_reading_answers: number; + incorrect_reading_answers: SafeInteger; /** Unique identifier of the associated `spaced_repetition_system`. */ - spaced_repetition_system_id: number; + spaced_repetition_system_id: SafeInteger; /** The starting SRS stage interval, with valid values ranging from `1` to `8`. */ starting_srs_stage: SpacedRepetitionSystemStageNumber; /** Unique identifier of the associated subject. */ - subject_id: number; + subject_id: SafeInteger; }; /** A unique number identifying the review. */ - id: number; + id: SafeInteger; /** The kind of object returned. */ object: "review"; diff --git a/packages/types/src/v20170710/spaced-repetition-systems.ts b/packages/types/src/v20170710/spaced-repetition-systems.ts index 8bfa0da6..76f7a6e6 100644 --- a/packages/types/src/v20170710/spaced-repetition-systems.ts +++ b/packages/types/src/v20170710/spaced-repetition-systems.ts @@ -1,4 +1,4 @@ -import type { BaseCollection, BaseResource, DatableString } from "./base.js"; +import type { BaseCollection, BaseResource, DatableString, SafeInteger } from "./base.js"; /** * The minimum SRS Stage Number used in WaniKani's SRS; exported for use in lieu of a Magic Number. @@ -36,7 +36,7 @@ export type SpacedRepetitionSystemStageNumber = number & {}; */ export interface SpacedRepetitionSystemStage { /** The length of time added to the time of review registration, adjusted to the beginning of the hour. */ - interval: number | null; + interval: SafeInteger | null; /** Unit of time. Can be the following: `milliseconds`, `seconds`, `minutes`, `hours`, `days`, and `weeks`. */ interval_unit: "days" | "hours" | "milliseconds" | "minutes" | "seconds" | "weeks" | null; @@ -82,7 +82,7 @@ export interface SpacedRepetitionSystem extends BaseResource { }; /** A unique number identifying the Spaced Repetition System. */ - id: number; + id: SafeInteger; /** The kind of object returned. */ object: "spaced_repetition_system"; diff --git a/packages/types/src/v20170710/study-materials.ts b/packages/types/src/v20170710/study-materials.ts index 384ea337..3b66b3d3 100644 --- a/packages/types/src/v20170710/study-materials.ts +++ b/packages/types/src/v20170710/study-materials.ts @@ -38,14 +38,14 @@ export interface StudyMaterial extends BaseResource { hidden: boolean; /** Unique identifier of the associated subject. */ - subject_id: number; + subject_id: SafeInteger; /** The type of the associated subject. */ subject_type: SubjectType; }; /** A unique number identifying the study material. */ - id: number; + id: SafeInteger; /** The kind of object returned. */ object: "study_material"; diff --git a/packages/types/src/v20170710/subjects.ts b/packages/types/src/v20170710/subjects.ts index 83dd764c..4e1d561c 100644 --- a/packages/types/src/v20170710/subjects.ts +++ b/packages/types/src/v20170710/subjects.ts @@ -1,4 +1,4 @@ -import type { BaseCollection, BaseResource, CollectionParameters, DatableString, Level } from "./base.js"; +import type { BaseCollection, BaseResource, CollectionParameters, DatableString, Level, SafeInteger } from "./base.js"; /** * The types of subjects used on WaniKani and its API. @@ -79,7 +79,7 @@ export interface SubjectBaseData { * The position that the subject appears in lessons. Note that the value is scoped to the level of the subject, so * there are duplicate values across levels. */ - lesson_position: number; + lesson_position: SafeInteger; /** The level of the subject, from `1` to `60`. */ level: Level; @@ -97,7 +97,7 @@ export interface SubjectBaseData { slug: string; /** Unique identifier of the associated Spaced Repetition System. */ - spaced_repetition_system_id: number; + spaced_repetition_system_id: SafeInteger; } /** @@ -143,7 +143,7 @@ export type RadicalCharacterImage = { */ export interface RadicalData extends SubjectBaseData { /** An array of numeric identifiers for the kanji that have the radical as a component. */ - amalgamation_subject_ids: number[]; + amalgamation_subject_ids: SafeInteger[]; /** A collection of images of the radical. */ character_images: RadicalCharacterImage[]; @@ -183,7 +183,7 @@ export interface KanjiReading { */ export interface KanjiData extends SubjectBaseData { /** An array of numeric identifiers for the vocabulary that have the kanji as a component. */ - amalgamation_subject_ids: number[]; + amalgamation_subject_ids: SafeInteger[]; /** The UTF-8 characters for the subject, including kanji and hiragana. */ characters: string; @@ -192,7 +192,7 @@ export interface KanjiData extends SubjectBaseData { * An array of numeric identifiers for the radicals that make up this kanji. Note that these are the subjects that * must have passed assignments in order to unlock this subject's assignment. */ - component_subject_ids: number[]; + component_subject_ids: SafeInteger[]; /** Meaning hint for the kanji. */ meaning_hint: string | null; @@ -207,7 +207,7 @@ export interface KanjiData extends SubjectBaseData { readings: KanjiReading[]; /** An array of numeric identifiers for kanji which are visually similar to the kanji in question. */ - visually_similar_subject_ids: number[]; + visually_similar_subject_ids: SafeInteger[]; } /** @@ -243,10 +243,10 @@ export interface VocabularyPronunciationAudio { pronunciation: string; /** A unique ID shared between same source pronunciation audio. */ - source_id: number; + source_id: SafeInteger; /** A unique ID belonging to the voice actor. */ - voice_actor_id: number; + voice_actor_id: SafeInteger; /** Humanized name of the voice actor. */ voice_actor_name: string; @@ -290,7 +290,7 @@ export interface VocabularyData extends SubjectBaseData { * An array of numeric identifiers for the kanji that make up this vocabulary. Note that these are the subjects that * must be have passed assignments in order to unlock this subject's assignment. */ - component_subject_ids: number[]; + component_subject_ids: SafeInteger[]; /** A collection of context sentences. */ context_sentences: VocabularyContextSentence[]; @@ -341,7 +341,7 @@ export interface KanaVocabularyData extends SubjectBaseData { */ export type Subject = BaseResource & { /** A unique number identifying the subject. */ - id: number; + id: SafeInteger; } & ( | { /** Data for the returned kana-only vocabulary. */ diff --git a/packages/types/src/v20170710/summary.ts b/packages/types/src/v20170710/summary.ts index 501f85c8..a61636a4 100644 --- a/packages/types/src/v20170710/summary.ts +++ b/packages/types/src/v20170710/summary.ts @@ -1,4 +1,4 @@ -import type { BaseReport, DatableString } from "./base.js"; +import type { BaseReport, DatableString, SafeInteger } from "./base.js"; /** * Details about subjects listed as available for lessons in the Summary report. @@ -14,7 +14,7 @@ export interface SummaryInterval { available_at: DatableString; /** Collection of unique identifiers for subjects. */ - subject_ids: number[]; + subject_ids: SafeInteger[]; } /** diff --git a/packages/types/src/v20170710/user.ts b/packages/types/src/v20170710/user.ts index 5d455707..3cb3f73b 100644 --- a/packages/types/src/v20170710/user.ts +++ b/packages/types/src/v20170710/user.ts @@ -1,4 +1,4 @@ -import type { BaseResource, DatableString, Level } from "./base.js"; +import type { BaseResource, DatableString, Level, SafeInteger } from "./base.js"; /** * The minimum batch size for lessons in the WaniKani app; exported for use in lieu of a Magic Number. @@ -32,7 +32,7 @@ export interface UserPreferences { * @deprecated This is a deprecated user preference. It will always return `1` and cannot be set. It exists only to * ensure existing consumers of this API don't break. */ - default_voice_actor_id: number; + default_voice_actor_id: SafeInteger; /** Automatically play pronunciation audio for vocabulary during extra study. */ extra_study_autoplay_audio: boolean; diff --git a/packages/types/src/v20170710/voice-actors.ts b/packages/types/src/v20170710/voice-actors.ts index e757ed02..55beae12 100644 --- a/packages/types/src/v20170710/voice-actors.ts +++ b/packages/types/src/v20170710/voice-actors.ts @@ -1,4 +1,4 @@ -import type { BaseCollection, BaseResource, DatableString } from "./base.js"; +import type { BaseCollection, BaseResource, DatableString, SafeInteger } from "./base.js"; /** * Available voice actors used for vocabulary reading pronunciation audio. @@ -24,7 +24,7 @@ export interface VoiceActor extends BaseResource { }; /** A unique number identifying the voice actor. */ - id: number; + id: SafeInteger; /** The kind of object returned. */ object: "voice_actor"; diff --git a/packages/valibot/src/v20170710/assignments.ts b/packages/valibot/src/v20170710/assignments.ts index 16755b34..12fcdfe3 100644 --- a/packages/valibot/src/v20170710/assignments.ts +++ b/packages/valibot/src/v20170710/assignments.ts @@ -21,19 +21,19 @@ export const Assignment = v.object( BaseResource, v.object({ data: v.object({ - available_at: v.union([DatableString, v.null()]), - burned_at: v.union([DatableString, v.null()]), + available_at: v.nullable(DatableString), + burned_at: v.nullable(DatableString), created_at: DatableString, hidden: v.boolean(), - passed_at: v.union([DatableString, v.null()]), - resurrected_at: v.union([DatableString, v.null()]), + passed_at: v.nullable(DatableString), + resurrected_at: v.nullable(DatableString), srs_stage: SpacedRepetitionSystemStageNumber, - started_at: v.union([DatableString, v.null()]), - subject_id: v.number(), + started_at: v.nullable(DatableString), + subject_id: SafeInteger, subject_type: SubjectType, - unlocked_at: v.union([DatableString, v.null()]), + unlocked_at: v.nullable(DatableString), }), - id: v.number(), + id: SafeInteger, object: v.literal("assignment"), }), ]), diff --git a/packages/valibot/src/v20170710/base.ts b/packages/valibot/src/v20170710/base.ts index a5867e6a..23056e1b 100644 --- a/packages/valibot/src/v20170710/base.ts +++ b/packages/valibot/src/v20170710/base.ts @@ -110,14 +110,14 @@ export const BaseResource = v.object({ */ export type BaseCollection = Types.BaseCollection; export const BaseCollection = v.object({ - data_updated_at: v.union([DatableString, v.null()]), + data_updated_at: v.nullable(DatableString), object: v.literal("collection"), pages: v.object({ - next_url: v.union([v.string(), v.null()]), - per_page: v.number(), - previous_url: v.union([v.string(), v.null()]), + next_url: v.nullable(v.string()), + per_page: SafeInteger, + previous_url: v.nullable(v.string()), }), - total_count: v.number(), + total_count: SafeInteger, url: v.string(), }); @@ -159,7 +159,7 @@ export const BaseReport = v.object({ */ export type ApiError = Types.ApiError; export const ApiError = v.object({ - code: v.number(), + code: SafeInteger, error: v.string(), }); diff --git a/packages/valibot/src/v20170710/level-progressions.ts b/packages/valibot/src/v20170710/level-progressions.ts index d95cb44e..47e1925c 100644 --- a/packages/valibot/src/v20170710/level-progressions.ts +++ b/packages/valibot/src/v20170710/level-progressions.ts @@ -1,7 +1,7 @@ import type * as Types from "@bachman-dev/wanikani-api-types/v20170710"; import * as v from "valibot"; -import { BaseCollection, BaseResource, DatableString, Level } from "./base.js"; +import { BaseCollection, BaseResource, DatableString, Level, SafeInteger } from "./base.js"; /** * Level progressions contain information about a user's progress through the WaniKani levels. @@ -23,15 +23,15 @@ export const LevelProgression = v.object( BaseResource, v.object({ data: v.object({ - abandoned_at: v.union([DatableString, v.null()]), - completed_at: v.union([DatableString, v.null()]), + abandoned_at: v.nullable(DatableString), + completed_at: v.nullable(DatableString), created_at: DatableString, level: Level, - passed_at: v.union([DatableString, v.null()]), - started_at: v.union([DatableString, v.null()]), - unlocked_at: v.union([DatableString, v.null()]), + passed_at: v.nullable(DatableString), + started_at: v.nullable(DatableString), + unlocked_at: v.nullable(DatableString), }), - id: v.number(), + id: SafeInteger, object: v.literal("level_progression"), }), ]), diff --git a/packages/valibot/src/v20170710/resets.ts b/packages/valibot/src/v20170710/resets.ts index 068910c4..cf3bd99c 100644 --- a/packages/valibot/src/v20170710/resets.ts +++ b/packages/valibot/src/v20170710/resets.ts @@ -1,7 +1,7 @@ import type * as Types from "@bachman-dev/wanikani-api-types/v20170710"; import * as v from "valibot"; -import { BaseCollection, BaseResource, DatableString, Level } from "./base.js"; +import { BaseCollection, BaseResource, DatableString, Level, SafeInteger } from "./base.js"; /** * Users can reset their progress back to any level at or below their current level. When they reset to a particular @@ -19,12 +19,12 @@ export const Reset = v.object( BaseResource, v.object({ data: v.object({ - confirmed_at: v.union([DatableString, v.null()]), + confirmed_at: v.nullable(DatableString), created_at: DatableString, original_level: Level, target_level: Level, }), - id: v.number(), + id: SafeInteger, object: v.literal("reset"), }), ]), diff --git a/packages/valibot/src/v20170710/review-statistics.ts b/packages/valibot/src/v20170710/review-statistics.ts index d61174bb..dbb4f731 100644 --- a/packages/valibot/src/v20170710/review-statistics.ts +++ b/packages/valibot/src/v20170710/review-statistics.ts @@ -23,19 +23,19 @@ export const ReviewStatistic = v.object( data: v.object({ created_at: DatableString, hidden: v.boolean(), - meaning_correct: v.number(), - meaning_current_streak: v.number(), - meaning_incorrect: v.number(), - meaning_max_streak: v.number(), + meaning_correct: SafeInteger, + meaning_current_streak: SafeInteger, + meaning_incorrect: SafeInteger, + meaning_max_streak: SafeInteger, percentage_correct: v.number(), - reading_correct: v.number(), - reading_current_streak: v.number(), - reading_incorrect: v.number(), - reading_max_streak: v.number(), - subject_id: v.number(), + reading_correct: SafeInteger, + reading_current_streak: SafeInteger, + reading_incorrect: SafeInteger, + reading_max_streak: SafeInteger, + subject_id: SafeInteger, subject_type: SubjectType, }), - id: v.number(), + id: SafeInteger, object: v.literal("review_statistic"), }), ]), diff --git a/packages/valibot/src/v20170710/reviews.ts b/packages/valibot/src/v20170710/reviews.ts index de4b99a1..81e3b0b7 100644 --- a/packages/valibot/src/v20170710/reviews.ts +++ b/packages/valibot/src/v20170710/reviews.ts @@ -22,16 +22,16 @@ export const Review = v.object( BaseResource, v.object({ data: v.object({ - assignment_id: v.number(), + assignment_id: SafeInteger, created_at: DatableString, ending_srs_stage: SpacedRepetitionSystemStageNumber, - incorrect_meaning_answers: v.number(), - incorrect_reading_answers: v.number(), - spaced_repetition_system_id: v.number(), + incorrect_meaning_answers: SafeInteger, + incorrect_reading_answers: SafeInteger, + spaced_repetition_system_id: SafeInteger, starting_srs_stage: SpacedRepetitionSystemStageNumber, - subject_id: v.number(), + subject_id: SafeInteger, }), - id: v.number(), + id: SafeInteger, object: v.literal("review"), }), ]), diff --git a/packages/valibot/src/v20170710/spaced-repetition-systems.ts b/packages/valibot/src/v20170710/spaced-repetition-systems.ts index 2e291ffb..18fee86e 100644 --- a/packages/valibot/src/v20170710/spaced-repetition-systems.ts +++ b/packages/valibot/src/v20170710/spaced-repetition-systems.ts @@ -39,8 +39,8 @@ export function isSpacedRepetitionSystemStageNumber(value: unknown): value is Sp */ export type SpacedRepetitionSystemStage = Types.SpacedRepetitionSystemStage; export const SpacedRepetitionSystemStage = v.object({ - interval: v.union([v.number(), v.null()]), - interval_unit: v.union([v.picklist(["days", "hours", "milliseconds", "minutes", "seconds", "weeks"]), v.null()]), + interval: v.nullable(SafeInteger), + interval_unit: v.nullable(v.picklist(["days", "hours", "milliseconds", "minutes", "seconds", "weeks"])), position: SpacedRepetitionSystemStageNumber, }); @@ -67,7 +67,7 @@ export const SpacedRepetitionSystem = v.object( starting_stage_position: SpacedRepetitionSystemStageNumber, unlocking_stage_position: SpacedRepetitionSystemStageNumber, }), - id: v.number(), + id: SafeInteger, object: v.literal("spaced_repetition_system"), }), ]), diff --git a/packages/valibot/src/v20170710/study-materials.ts b/packages/valibot/src/v20170710/study-materials.ts index 313bb2a7..8db2e17d 100644 --- a/packages/valibot/src/v20170710/study-materials.ts +++ b/packages/valibot/src/v20170710/study-materials.ts @@ -37,11 +37,11 @@ export const StudyMaterial = v.object( v.object({ created_at: DatableString, hidden: v.boolean(), - subject_id: v.number(), + subject_id: SafeInteger, subject_type: SubjectType, }), ]), - id: v.number(), + id: SafeInteger, object: v.literal("study_material"), }), ]), diff --git a/packages/valibot/src/v20170710/subjects.ts b/packages/valibot/src/v20170710/subjects.ts index 09280c50..8a5f8b14 100644 --- a/packages/valibot/src/v20170710/subjects.ts +++ b/packages/valibot/src/v20170710/subjects.ts @@ -1,7 +1,7 @@ import type * as Types from "@bachman-dev/wanikani-api-types/v20170710"; import * as v from "valibot"; -import { BaseCollection, BaseResource, CollectionParameters, DatableString, Level } from "./base.js"; +import { BaseCollection, BaseResource, CollectionParameters, DatableString, Level, SafeInteger } from "./base.js"; /** * The types of subjects used on WaniKani and its API. @@ -93,13 +93,13 @@ export const SubjectBaseData = v.object({ auxiliary_meanings: v.array(SubjectAuxiliaryMeaning), created_at: DatableString, document_url: v.string(), - hidden_at: v.union([DatableString, v.null()]), - lesson_position: v.number(), + hidden_at: v.nullable(DatableString), + lesson_position: SafeInteger, level: Level, meaning_mnemonic: v.string(), meanings: v.array(SubjectMeaning), slug: v.string(), - spaced_repetition_system_id: v.number(), + spaced_repetition_system_id: SafeInteger, }); /** @@ -142,9 +142,9 @@ export const RadicalData = v.object( v.entriesFromObjects([ SubjectBaseData, v.object({ - amalgamation_subject_ids: v.array(v.number()), + amalgamation_subject_ids: v.array(SafeInteger), character_images: v.array(RadicalCharacterImage), - characters: v.union([v.string(), v.null()]), + characters: v.nullable(v.string()), }), ]), ); @@ -174,14 +174,14 @@ export const KanjiData = v.object( v.entriesFromObjects([ SubjectBaseData, v.object({ - amalgamation_subject_ids: v.array(v.number()), + amalgamation_subject_ids: v.array(SafeInteger), characters: v.string(), - component_subject_ids: v.array(v.number()), - meaning_hint: v.union([v.string(), v.null()]), - reading_hint: v.union([v.string(), v.null()]), + component_subject_ids: v.array(SafeInteger), + meaning_hint: v.nullable(v.string()), + reading_hint: v.nullable(v.string()), reading_mnemonic: v.string(), readings: v.array(KanjiReading), - visually_similar_subject_ids: v.array(v.number()), + visually_similar_subject_ids: v.array(SafeInteger), }), ]), ); @@ -210,8 +210,8 @@ export const VocabularyPronunciationAudio = v.object({ metadata: v.object({ gender: v.picklist(["female", "male"]), pronunciation: v.string(), - source_id: v.number(), - voice_actor_id: v.number(), + source_id: SafeInteger, + voice_actor_id: SafeInteger, voice_actor_name: v.string(), voice_description: v.string(), }), @@ -243,7 +243,7 @@ export const VocabularyData = v.object( SubjectBaseData, v.object({ characters: v.string(), - component_subject_ids: v.array(v.number()), + component_subject_ids: v.array(SafeInteger), context_sentences: v.array(VocabularyContextSentence), parts_of_speech: v.array(v.string()), pronunciation_audios: v.array(VocabularyPronunciationAudio), @@ -287,7 +287,7 @@ export type Subject = Types.Subject; export const Subject = v.intersect([ BaseResource, v.object({ - id: v.number(), + id: SafeInteger, }), v.variant("object", [ v.object({ diff --git a/packages/valibot/src/v20170710/summary.ts b/packages/valibot/src/v20170710/summary.ts index c772e50d..283640aa 100644 --- a/packages/valibot/src/v20170710/summary.ts +++ b/packages/valibot/src/v20170710/summary.ts @@ -1,7 +1,7 @@ import type * as Types from "@bachman-dev/wanikani-api-types/v20170710"; import * as v from "valibot"; -import { BaseReport, DatableString } from "./base.js"; +import { BaseReport, DatableString, SafeInteger } from "./base.js"; /** * Details about subjects listed as available for lessons in the Summary report. @@ -12,7 +12,7 @@ import { BaseReport, DatableString } from "./base.js"; export type SummaryInterval = Types.SummaryInterval; export const SummaryInterval = v.object({ available_at: DatableString, - subject_ids: v.array(v.number()), + subject_ids: v.array(SafeInteger), }); /** @@ -30,7 +30,7 @@ export const Summary = v.object( v.object({ data: v.object({ lessons: v.array(SummaryInterval), - next_reviews_at: v.union([DatableString, v.null()]), + next_reviews_at: v.nullable(DatableString), reviews: v.array(SummaryInterval), }), }), diff --git a/packages/valibot/src/v20170710/user.ts b/packages/valibot/src/v20170710/user.ts index e8ce892d..1a974380 100644 --- a/packages/valibot/src/v20170710/user.ts +++ b/packages/valibot/src/v20170710/user.ts @@ -62,7 +62,7 @@ export const User = v.object( BaseResource, v.object({ data: v.object({ - current_vacation_started_at: v.union([DatableString, v.null()]), + current_vacation_started_at: v.nullable(DatableString), id: v.string(), level: Level, preferences: UserPreferences, @@ -71,7 +71,7 @@ export const User = v.object( subscription: v.object({ active: v.boolean(), max_level_granted: Level, - period_ends_at: v.union([DatableString, v.null()]), + period_ends_at: v.nullable(DatableString), type: v.picklist(["free", "lifetime", "recurring", "unknown"]), }), username: v.string(), diff --git a/packages/valibot/src/v20170710/voice-actors.ts b/packages/valibot/src/v20170710/voice-actors.ts index 74b5962d..f402565b 100644 --- a/packages/valibot/src/v20170710/voice-actors.ts +++ b/packages/valibot/src/v20170710/voice-actors.ts @@ -1,7 +1,7 @@ import type * as Types from "@bachman-dev/wanikani-api-types/v20170710"; import * as v from "valibot"; -import { BaseCollection, BaseResource, DatableString } from "./base.js"; +import { BaseCollection, BaseResource, DatableString, SafeInteger } from "./base.js"; /** * Available voice actors used for vocabulary reading pronunciation audio. @@ -21,7 +21,7 @@ export const VoiceActor = v.object( gender: v.picklist(["female", "male"]), name: v.string(), }), - id: v.number(), + id: SafeInteger, object: v.literal("voice_actor"), }), ]), diff --git a/packages/zod/src/v20170710/assignments.ts b/packages/zod/src/v20170710/assignments.ts index a057907e..47ff0f6e 100644 --- a/packages/zod/src/v20170710/assignments.ts +++ b/packages/zod/src/v20170710/assignments.ts @@ -28,11 +28,11 @@ export const Assignment = z.toZod()( resurrected_at: z.nullable(DatableString), srs_stage: SpacedRepetitionSystemStageNumber, started_at: z.nullable(DatableString), - subject_id: z.number(), + subject_id: SafeInteger, subject_type: SubjectType, unlocked_at: z.nullable(DatableString), }), - id: z.number(), + id: SafeInteger, object: z.literal("assignment"), }), ); diff --git a/packages/zod/src/v20170710/base.ts b/packages/zod/src/v20170710/base.ts index 112bccc4..aa53e491 100644 --- a/packages/zod/src/v20170710/base.ts +++ b/packages/zod/src/v20170710/base.ts @@ -117,10 +117,10 @@ export const BaseCollection = z.toZod()( object: z.literal("collection"), pages: z.object({ next_url: z.nullable(z.string()), - per_page: z.number(), + per_page: SafeInteger, previous_url: z.nullable(z.string()), }), - total_count: z.number(), + total_count: SafeInteger, url: z.string(), }), ); @@ -168,7 +168,7 @@ export const BaseReport = z.toZod()( export type ApiError = Types.ApiError; export const ApiError = z.toZod()( z.object({ - code: z.number(), + code: SafeInteger, error: z.string(), }), ); diff --git a/packages/zod/src/v20170710/level-progressions.ts b/packages/zod/src/v20170710/level-progressions.ts index f7029212..0332878c 100644 --- a/packages/zod/src/v20170710/level-progressions.ts +++ b/packages/zod/src/v20170710/level-progressions.ts @@ -1,7 +1,7 @@ import type * as Types from "@bachman-dev/wanikani-api-types/v20170710"; import * as z from "zod/mini"; -import { BaseCollection, BaseResource, DatableString, Level } from "./base.js"; +import { BaseCollection, BaseResource, DatableString, Level, SafeInteger } from "./base.js"; /** * Level progressions contain information about a user's progress through the WaniKani levels. @@ -30,7 +30,7 @@ export const LevelProgression = z.toZod()( started_at: z.nullable(DatableString), unlocked_at: z.nullable(DatableString), }), - id: z.number(), + id: SafeInteger, object: z.literal("level_progression"), }), ); diff --git a/packages/zod/src/v20170710/resets.ts b/packages/zod/src/v20170710/resets.ts index 44d30ddd..564257c3 100644 --- a/packages/zod/src/v20170710/resets.ts +++ b/packages/zod/src/v20170710/resets.ts @@ -1,7 +1,7 @@ import type * as Types from "@bachman-dev/wanikani-api-types/v20170710"; import * as z from "zod/mini"; -import { BaseCollection, BaseResource, DatableString, Level } from "./base.js"; +import { BaseCollection, BaseResource, DatableString, Level, SafeInteger } from "./base.js"; /** * Users can reset their progress back to any level at or below their current level. When they reset to a particular @@ -23,7 +23,7 @@ export const Reset = z.toZod()( original_level: Level, target_level: Level, }), - id: z.number(), + id: SafeInteger, object: z.literal("reset"), }), ); diff --git a/packages/zod/src/v20170710/review-statistics.ts b/packages/zod/src/v20170710/review-statistics.ts index 3108fa31..363a6edc 100644 --- a/packages/zod/src/v20170710/review-statistics.ts +++ b/packages/zod/src/v20170710/review-statistics.ts @@ -22,19 +22,19 @@ export const ReviewStatistic = z.toZod()( data: z.object({ created_at: DatableString, hidden: z.boolean(), - meaning_correct: z.number(), - meaning_current_streak: z.number(), - meaning_incorrect: z.number(), - meaning_max_streak: z.number(), + meaning_correct: SafeInteger, + meaning_current_streak: SafeInteger, + meaning_incorrect: SafeInteger, + meaning_max_streak: SafeInteger, percentage_correct: z.number(), - reading_correct: z.number(), - reading_current_streak: z.number(), - reading_incorrect: z.number(), - reading_max_streak: z.number(), - subject_id: z.number(), + reading_correct: SafeInteger, + reading_current_streak: SafeInteger, + reading_incorrect: SafeInteger, + reading_max_streak: SafeInteger, + subject_id: SafeInteger, subject_type: SubjectType, }), - id: z.number(), + id: SafeInteger, object: z.literal("review_statistic"), }), ); diff --git a/packages/zod/src/v20170710/reviews.ts b/packages/zod/src/v20170710/reviews.ts index edaca903..e61aaff3 100644 --- a/packages/zod/src/v20170710/reviews.ts +++ b/packages/zod/src/v20170710/reviews.ts @@ -21,16 +21,16 @@ export const Review = z.toZod()( z.object({ ...BaseResource.shape, data: z.object({ - assignment_id: z.number(), + assignment_id: SafeInteger, created_at: DatableString, ending_srs_stage: SpacedRepetitionSystemStageNumber, - incorrect_meaning_answers: z.number(), - incorrect_reading_answers: z.number(), - spaced_repetition_system_id: z.number(), + incorrect_meaning_answers: SafeInteger, + incorrect_reading_answers: SafeInteger, + spaced_repetition_system_id: SafeInteger, starting_srs_stage: SpacedRepetitionSystemStageNumber, - subject_id: z.number(), + subject_id: SafeInteger, }), - id: z.number(), + id: SafeInteger, object: z.literal("review"), }), ); @@ -134,13 +134,15 @@ export const ReviewPayload = z.toZod()( * @see {@link https://docs.api.wanikani.com/20170710/#create-a-review} */ export type CreatedReview = Types.CreatedReview; -export const CreatedReview = z.object({ - ...Review.shape, - resources_updated: z.object({ - assignment: Assignment, - review_statistic: ReviewStatistic, +export const CreatedReview = z.toZod()( + z.object({ + ...Review.shape, + resources_updated: z.object({ + assignment: Assignment, + review_statistic: ReviewStatistic, + }), }), -}); +); /** * A type guard that checks if the given value matches the type predicate. diff --git a/packages/zod/src/v20170710/spaced-repetition-systems.ts b/packages/zod/src/v20170710/spaced-repetition-systems.ts index 8b85f256..5ef4857f 100644 --- a/packages/zod/src/v20170710/spaced-repetition-systems.ts +++ b/packages/zod/src/v20170710/spaced-repetition-systems.ts @@ -38,7 +38,7 @@ export function isSpacedRepetitionSystemStageNumber(value: unknown): value is Sp export type SpacedRepetitionSystemStage = Types.SpacedRepetitionSystemStage; export const SpacedRepetitionSystemStage = z.toZod()( z.object({ - interval: z.nullable(z.number()), + interval: z.nullable(SafeInteger), interval_unit: z.nullable(z.enum(["days", "hours", "milliseconds", "minutes", "seconds", "weeks"])), position: SpacedRepetitionSystemStageNumber, }), @@ -66,7 +66,7 @@ export const SpacedRepetitionSystem = z.toZod()( starting_stage_position: SpacedRepetitionSystemStageNumber, unlocking_stage_position: SpacedRepetitionSystemStageNumber, }), - id: z.number(), + id: SafeInteger, object: z.literal("spaced_repetition_system"), }), ); diff --git a/packages/zod/src/v20170710/study-materials.ts b/packages/zod/src/v20170710/study-materials.ts index d9f42cd1..bd553ff2 100644 --- a/packages/zod/src/v20170710/study-materials.ts +++ b/packages/zod/src/v20170710/study-materials.ts @@ -37,10 +37,10 @@ export const StudyMaterial = z.toZod()( ...StudyMaterialBaseData.shape, created_at: DatableString, hidden: z.boolean(), - subject_id: z.number(), + subject_id: SafeInteger, subject_type: SubjectType, }), - id: z.number(), + id: SafeInteger, object: z.literal("study_material"), }), ); diff --git a/packages/zod/src/v20170710/subjects.ts b/packages/zod/src/v20170710/subjects.ts index 5fecb045..ec0ec010 100644 --- a/packages/zod/src/v20170710/subjects.ts +++ b/packages/zod/src/v20170710/subjects.ts @@ -2,7 +2,7 @@ import type * as Types from "@bachman-dev/wanikani-api-types/v20170710"; import * as z from "zod/mini"; import * as m from "./lang/index.ts"; -import { BaseCollection, BaseResource, CollectionParameters, DatableString, Level } from "./base.js"; +import { BaseCollection, BaseResource, CollectionParameters, DatableString, Level, SafeInteger } from "./base.js"; /** * The types of subjects used on WaniKani and its API. @@ -98,12 +98,12 @@ export const SubjectBaseData = z.toZod()( created_at: DatableString, document_url: z.string(), hidden_at: z.nullable(DatableString), - lesson_position: z.number(), + lesson_position: SafeInteger, level: Level, meaning_mnemonic: z.string(), meanings: z.array(SubjectMeaning), slug: z.string(), - spaced_repetition_system_id: z.number(), + spaced_repetition_system_id: SafeInteger, }), ); @@ -148,7 +148,7 @@ export type RadicalData = Types.RadicalData; export const RadicalData = z.toZod()( z.object({ ...SubjectBaseData.shape, - amalgamation_subject_ids: z.array(z.number()), + amalgamation_subject_ids: z.array(SafeInteger), character_images: z.array(RadicalCharacterImage), characters: z.nullable(z.string()), }), @@ -180,14 +180,14 @@ export type KanjiData = Types.KanjiData; export const KanjiData = z.toZod()( z.object({ ...SubjectBaseData.shape, - amalgamation_subject_ids: z.array(z.number()), + amalgamation_subject_ids: z.array(SafeInteger), characters: z.string(), - component_subject_ids: z.array(z.number()), + component_subject_ids: z.array(SafeInteger), meaning_hint: z.nullable(z.string()), reading_hint: z.nullable(z.string()), reading_mnemonic: z.string(), readings: z.array(KanjiReading), - visually_similar_subject_ids: z.array(z.number()), + visually_similar_subject_ids: z.array(SafeInteger), }), ); @@ -218,8 +218,8 @@ export const VocabularyPronunciationAudio = z.toZod()( z.object({ ...SubjectBaseData.shape, characters: z.string(), - component_subject_ids: z.array(z.number()), + component_subject_ids: z.array(SafeInteger), context_sentences: z.array(VocabularyContextSentence), parts_of_speech: z.array(z.string()), pronunciation_audios: z.array(VocabularyPronunciationAudio), @@ -295,7 +295,7 @@ export const Subject = z.toZod()( z.intersection( z.object({ ...BaseResource.shape, - id: z.number(), + id: SafeInteger, }), z.discriminatedUnion("object", [ z.object({ diff --git a/packages/zod/src/v20170710/summary.ts b/packages/zod/src/v20170710/summary.ts index cc8a6095..dcedc7f7 100644 --- a/packages/zod/src/v20170710/summary.ts +++ b/packages/zod/src/v20170710/summary.ts @@ -1,7 +1,7 @@ import type * as Types from "@bachman-dev/wanikani-api-types/v20170710"; import * as z from "zod/mini"; -import { BaseReport, DatableString } from "./base.js"; +import { BaseReport, DatableString, SafeInteger } from "./base.js"; /** * Details about subjects listed as available for lessons in the Summary report. @@ -10,10 +10,12 @@ import { BaseReport, DatableString } from "./base.js"; * @see {@link https://docs.api.wanikani.com/20170710/#summary} */ export type SummaryInterval = Types.SummaryInterval; -export const SummaryInterval = z.object({ - available_at: DatableString, - subject_ids: z.array(z.number()), -}); +export const SummaryInterval = z.toZod()( + z.object({ + available_at: DatableString, + subject_ids: z.array(SafeInteger), + }), +); /** * The summary report contains currently available lessons and reviews and the reviews that will become available in the diff --git a/packages/zod/src/v20170710/user.ts b/packages/zod/src/v20170710/user.ts index 598285db..6956089a 100644 --- a/packages/zod/src/v20170710/user.ts +++ b/packages/zod/src/v20170710/user.ts @@ -12,9 +12,8 @@ export { MIN_LESSON_BATCH_SIZE, MAX_LESSON_BATCH_SIZE } from "@bachman-dev/wanik * @category User */ export type LessonBatchSizeNumber = Types.LessonBatchSizeNumber; -export const LessonBatchSizeNumber = SafeInteger.check( - z.minimum(MIN_LESSON_BATCH_SIZE), - z.maximum(MAX_LESSON_BATCH_SIZE), +export const LessonBatchSizeNumber = z.toZod()( + SafeInteger.check(z.minimum(MIN_LESSON_BATCH_SIZE), z.maximum(MAX_LESSON_BATCH_SIZE)), ); /** @@ -39,7 +38,7 @@ export function isLessonBatchSizeNumber(value: unknown): value is LessonBatchSiz export type UserPreferences = Types.UserPreferences; export const UserPreferences = z.toZod()( z.object({ - default_voice_actor_id: z.number(), + default_voice_actor_id: SafeInteger, extra_study_autoplay_audio: z.boolean(), lessons_autoplay_audio: z.boolean(), lessons_batch_size: LessonBatchSizeNumber, diff --git a/packages/zod/src/v20170710/voice-actors.ts b/packages/zod/src/v20170710/voice-actors.ts index f682bb19..dd1de4c8 100644 --- a/packages/zod/src/v20170710/voice-actors.ts +++ b/packages/zod/src/v20170710/voice-actors.ts @@ -1,7 +1,7 @@ import type * as Types from "@bachman-dev/wanikani-api-types/v20170710"; import * as z from "zod/mini"; -import { BaseCollection, BaseResource, DatableString } from "./base.js"; +import { BaseCollection, BaseResource, DatableString, SafeInteger } from "./base.js"; /** * Available voice actors used for vocabulary reading pronunciation audio. @@ -20,7 +20,7 @@ export const VoiceActor = z.toZod()( gender: z.enum(["female", "male"]), name: z.string(), }), - id: z.number(), + id: SafeInteger, object: z.literal("voice_actor"), }), );