@opinio-dev/models 1.1.0 → 1.1.1-item-types.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/items/Book.d.ts +14 -0
- package/dist/types/items/Game.d.ts +15 -0
- package/dist/types/items/Genre.d.ts +6 -0
- package/dist/types/items/Item.d.ts +14 -0
- package/dist/{ItemType.d.ts → types/items/ItemType.d.ts} +6 -0
- package/dist/types/items/Movie.d.ts +15 -0
- package/dist/types/items/Series.d.ts +18 -0
- package/dist/types/ratings/LeaderboardItem.d.ts +10 -0
- package/dist/types/ratings/LeaderboardSnapshot.d.ts +8 -0
- package/dist/types/ratings/Rating.d.ts +8 -0
- package/dist/validation/BaseValidator.d.ts +31 -0
- package/dist/validation/ValidationResult.d.ts +4 -0
- package/dist/validation/Validator.d.ts +10 -0
- package/dist/validation/ValidatorRegistry.d.ts +23 -0
- package/dist/validation/items/BaseItemValidator.d.ts +23 -0
- package/dist/validation/items/BookValidator.d.ts +11 -0
- package/dist/validation/items/GameValidator.d.ts +11 -0
- package/dist/validation/items/ItemValidatorRegistry.d.ts +3 -0
- package/dist/validation/items/MovieValidator.d.ts +11 -0
- package/dist/validation/items/SeriesValidator.d.ts +11 -0
- package/dist/validation/ratings/LeaderboardItemValidator.d.ts +11 -0
- package/dist/validation/ratings/LeaderboardSnapshotValidator.d.ts +11 -0
- package/dist/validation/ratings/RatingValidator.d.ts +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BookGenre } from './Genre';
|
|
2
|
+
import { IBaseItem, Item } from './Item';
|
|
3
|
+
export interface IBook extends IBaseItem {
|
|
4
|
+
type: 'book';
|
|
5
|
+
genres: BookGenre[];
|
|
6
|
+
author: string;
|
|
7
|
+
publisher: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Determines if the given item is a book
|
|
11
|
+
* @param {Item} item The item to check
|
|
12
|
+
* @returns {boolean} True if the item is a book, false otherwise
|
|
13
|
+
*/
|
|
14
|
+
export declare function isBook(item: Item): item is IBook;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GameGenre } from './Genre';
|
|
2
|
+
import { IBaseItem, Item } from './Item';
|
|
3
|
+
export interface IGame extends IBaseItem {
|
|
4
|
+
type: 'game';
|
|
5
|
+
genres: GameGenre[];
|
|
6
|
+
platforms: string[];
|
|
7
|
+
developer: string;
|
|
8
|
+
publisher: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Determines if the given item is a game
|
|
12
|
+
* @param {Item} item The item to check
|
|
13
|
+
* @returns {boolean} True if the item is a game, false otherwise
|
|
14
|
+
*/
|
|
15
|
+
export declare function isGame(item: Item): item is IGame;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const VideoGenres: readonly ["Action", "Adventure", "Biography", "Comedy", "Drama", "Fantasy", "Horror", "Mystery", "Romance", "Science Fiction", "Thriller", "Crime", "Documentary", "Animation", "Family", "Historical", "Musical", "War", "Western"];
|
|
2
|
+
export type VideoGenre = (typeof VideoGenres)[number];
|
|
3
|
+
export declare const GameGenres: readonly ["Action", "Adventure", "Biography", "Comedy", "Drama", "Fantasy", "Horror", "Mystery", "Romance", "Science Fiction", "Thriller", "Crime", "Documentary", "Animation", "Family", "Historical", "Musical", "War", "Western", "RPG", "Shooter", "Fighting", "Platformer", "Puzzle", "Open World", "Racing", "Simulation", "Sports", "Strategy", "Survival", "Sandbox", "MOBA", "MMO", "Roguelike"];
|
|
4
|
+
export type GameGenre = (typeof GameGenres)[number];
|
|
5
|
+
export declare const BookGenres: readonly ["Fiction", "Non-Fiction", "Fantasy", "Science Fiction", "Mystery", "Thriller", "Horror", "Romance", "Historical", "Biography", "Autobiography", "Memoir", "Self-Help", "Poetry", "Drama", "Young Adult", "Children's", "Graphic Novel", "Classic", "Philosophy", "Science", "Travel", "Religion", "True Crime", "Humor"];
|
|
6
|
+
export type BookGenre = (typeof BookGenres)[number];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IBook } from './Book.js';
|
|
2
|
+
import { IGame } from './Game.js';
|
|
3
|
+
import { ItemType } from './ItemType.js';
|
|
4
|
+
import { IMovie } from './Movie.js';
|
|
5
|
+
import { ISeries } from './Series.js';
|
|
6
|
+
export type Item = IMovie | IGame | ISeries | IBook;
|
|
7
|
+
export interface IBaseItem {
|
|
8
|
+
id: string;
|
|
9
|
+
type: ItemType;
|
|
10
|
+
name: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
imageUrl?: string;
|
|
13
|
+
releaseYear: number;
|
|
14
|
+
}
|
|
@@ -6,3 +6,9 @@ export declare const ItemType: {
|
|
|
6
6
|
};
|
|
7
7
|
export type ItemType = (typeof ItemType)[keyof typeof ItemType];
|
|
8
8
|
export declare const ItemTypes: ("book" | "game" | "movie" | "series")[];
|
|
9
|
+
/**
|
|
10
|
+
* Determines if the item type is valid
|
|
11
|
+
* @param {string|ItemType} itemType The item type to check
|
|
12
|
+
* @returns {boolean} Whether the item type is valid
|
|
13
|
+
*/
|
|
14
|
+
export declare function isItemType(itemType: string | ItemType): itemType is ItemType;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { VideoGenre } from './Genre.js';
|
|
2
|
+
import { IBaseItem, Item } from './Item.js';
|
|
3
|
+
export interface IMovie extends IBaseItem {
|
|
4
|
+
type: 'movie';
|
|
5
|
+
genres: VideoGenre[];
|
|
6
|
+
duration: number;
|
|
7
|
+
director: string;
|
|
8
|
+
cast: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Determines if the given item is a movie
|
|
12
|
+
* @param {Item} item The item to check
|
|
13
|
+
* @returns {boolean} True if the item is a movie, false otherwise
|
|
14
|
+
*/
|
|
15
|
+
export declare function isMovie(item: Item): item is IMovie;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { VideoGenre } from './Genre';
|
|
2
|
+
import { IBaseItem, Item } from './Item';
|
|
3
|
+
export declare const SeriesStatuses: readonly ["ongoing", "completed", "cancelled"];
|
|
4
|
+
export type SeriesStatus = (typeof SeriesStatuses)[number];
|
|
5
|
+
export interface ISeries extends IBaseItem {
|
|
6
|
+
type: 'series';
|
|
7
|
+
genres: VideoGenre[];
|
|
8
|
+
seasons: number;
|
|
9
|
+
status: SeriesStatus;
|
|
10
|
+
creator: string;
|
|
11
|
+
cast: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Determines if the given item is a series
|
|
15
|
+
* @param {Item} item The item to check
|
|
16
|
+
* @returns {boolean} True if the item is a series, false otherwise
|
|
17
|
+
*/
|
|
18
|
+
export declare function isSeries(item: Item): item is ISeries;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IValidationResult } from './ValidationResult';
|
|
2
|
+
import { IValidator } from './Validator';
|
|
3
|
+
/**
|
|
4
|
+
* A base validator providing common validation logic.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseValidator<T> implements IValidator<T> {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritdoc
|
|
9
|
+
*/
|
|
10
|
+
validate(item: Partial<T>, ignoredFields?: Array<keyof T>): IValidationResult;
|
|
11
|
+
/**
|
|
12
|
+
* Validates fields, returning a record of any errors. Override in subclasses.
|
|
13
|
+
* @param {Partial<T>} item The item to validate.
|
|
14
|
+
* @returns {Record<string, string>} A record of validation errors
|
|
15
|
+
*/
|
|
16
|
+
protected abstract _validateFields(item: Partial<T>): Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Filters out errors for ignored fields.
|
|
19
|
+
* @template T The type of the item being validated.
|
|
20
|
+
* @param {Record<string, string>} errors The errors to filter.
|
|
21
|
+
* @param {Array<keyof T>} ignoredFields Fields to ignore during validation.
|
|
22
|
+
* @returns {Record<string, string>} The filtered errors.
|
|
23
|
+
*/
|
|
24
|
+
private __filterIgnoredFields;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a validation result from errors.
|
|
27
|
+
* @param {Record<string, string>} errors The validation errors.
|
|
28
|
+
* @returns {IValidationResult} The validation result.
|
|
29
|
+
*/
|
|
30
|
+
private __createValidationResult;
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IValidationResult } from './ValidationResult';
|
|
2
|
+
export interface IValidator<T> {
|
|
3
|
+
/**
|
|
4
|
+
* Validates a passed item against pre-defined rules.
|
|
5
|
+
* @param {Partial<T>} item The item to validate.
|
|
6
|
+
* @param {Array<keyof T>} ignoredFields Fields to ignore during validation.
|
|
7
|
+
* @returns {IValidationResult} The result of the validation.
|
|
8
|
+
*/
|
|
9
|
+
validate(item: Partial<T>, ignoredFields: Array<keyof T>): IValidationResult;
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IValidationResult } from './ValidationResult';
|
|
2
|
+
import { IValidator } from './Validator';
|
|
3
|
+
/**
|
|
4
|
+
* A registry for managing validators.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ValidatorRegistry<T> {
|
|
7
|
+
private validators;
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves a validator.
|
|
10
|
+
* @param {string} key The key of the validator to retrieve.
|
|
11
|
+
* @param {IValidator<T>} validator The validator to register.
|
|
12
|
+
* @returns {void}
|
|
13
|
+
*/
|
|
14
|
+
register(key: string, validator: IValidator<T>): void;
|
|
15
|
+
/**
|
|
16
|
+
* Validates an item using a registered validator.
|
|
17
|
+
* @param {string} key The key of the validator to use.
|
|
18
|
+
* @param {Partial<T>} item The item to validate.
|
|
19
|
+
* @param {Array<keyof T>} ignoredFields Fields to ignore during validation.
|
|
20
|
+
* @returns {IValidationResult} The result of the validation.
|
|
21
|
+
*/
|
|
22
|
+
validate(key: string, item: Partial<T>, ignoredFields: Array<keyof T>): IValidationResult;
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Item } from '../../types/items/Item';
|
|
2
|
+
import { BaseValidator } from '../BaseValidator';
|
|
3
|
+
/**
|
|
4
|
+
* A base validator for items, providing common validation logic.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseItemValidator<T extends Item> extends BaseValidator<T> {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritdoc
|
|
9
|
+
*/
|
|
10
|
+
protected _validateFields(item: Partial<T>): Record<string, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Validates common item fields that apply to all item types.
|
|
13
|
+
* @param {Partial<T>} item The item to validate.
|
|
14
|
+
* @returns {Record<string, string>} A record of validation errors.
|
|
15
|
+
*/
|
|
16
|
+
protected _validateBaseFields(item: Partial<T>): Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Validates type-specific fields. Override in subclasses.
|
|
19
|
+
* @param {Partial<T>} item The item to validate.
|
|
20
|
+
* @returns {Record<string, string>} A record of validation errors
|
|
21
|
+
*/
|
|
22
|
+
protected abstract _validateTypeSpecificFields(item: Partial<T>): Record<string, string>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IBook } from '../../types/items/Book';
|
|
2
|
+
import { BaseItemValidator } from './BaseItemValidator';
|
|
3
|
+
/**
|
|
4
|
+
* A validator for book items.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BookValidator extends BaseItemValidator<IBook> {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritdoc
|
|
9
|
+
*/
|
|
10
|
+
protected _validateTypeSpecificFields(book: Partial<IBook>): Record<string, string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IGame } from '../../types/items/Game';
|
|
2
|
+
import { BaseItemValidator } from './BaseItemValidator';
|
|
3
|
+
/**
|
|
4
|
+
* A validator for game items.
|
|
5
|
+
*/
|
|
6
|
+
export declare class GameValidator extends BaseItemValidator<IGame> {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritdoc
|
|
9
|
+
*/
|
|
10
|
+
protected _validateTypeSpecificFields(game: Partial<IGame>): Record<string, string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IMovie } from '../../types/items/Movie';
|
|
2
|
+
import { BaseItemValidator } from './BaseItemValidator';
|
|
3
|
+
/**
|
|
4
|
+
* A validator for movie items.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MovieValidator extends BaseItemValidator<IMovie> {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritdoc
|
|
9
|
+
*/
|
|
10
|
+
protected _validateTypeSpecificFields(movie: Partial<IMovie>): Record<string, string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ISeries } from '../../types/items/Series';
|
|
2
|
+
import { BaseItemValidator } from './BaseItemValidator';
|
|
3
|
+
/**
|
|
4
|
+
* A validator for series items.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SeriesValidator extends BaseItemValidator<ISeries> {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritdoc
|
|
9
|
+
*/
|
|
10
|
+
protected _validateTypeSpecificFields(series: Partial<ISeries>): Record<string, string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ILeaderboardItem } from '../../types/ratings/LeaderboardItem';
|
|
2
|
+
import { BaseValidator } from '../BaseValidator';
|
|
3
|
+
/**
|
|
4
|
+
* A validator for item leaderboardItems.
|
|
5
|
+
*/
|
|
6
|
+
export declare class LeaderboardItemValidator extends BaseValidator<ILeaderboardItem> {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritdoc
|
|
9
|
+
*/
|
|
10
|
+
protected _validateFields(leaderboardItem: Partial<ILeaderboardItem>): Record<string, string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ILeaderboardSnapshot } from '../../types/ratings/LeaderboardSnapshot';
|
|
2
|
+
import { BaseValidator } from '../BaseValidator';
|
|
3
|
+
/**
|
|
4
|
+
* A validator for item leaderboardSnapshots.
|
|
5
|
+
*/
|
|
6
|
+
export declare class LeaderboardSnapshotValidator extends BaseValidator<ILeaderboardSnapshot> {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritdoc
|
|
9
|
+
*/
|
|
10
|
+
protected _validateFields(leaderboardSnapshot: Partial<ILeaderboardSnapshot>): Record<string, string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IRating } from '../../types/ratings/Rating';
|
|
2
|
+
import { BaseValidator } from '../BaseValidator';
|
|
3
|
+
/**
|
|
4
|
+
* A validator for item ratings.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RatingValidator extends BaseValidator<IRating> {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritdoc
|
|
9
|
+
*/
|
|
10
|
+
protected _validateFields(rating: Partial<IRating>): Record<string, string>;
|
|
11
|
+
}
|