Update scripts

This commit is contained in:
freearhey 2025-04-29 00:18:35 +03:00
parent 37b4197fb2
commit 6244ba7adb
54 changed files with 2020 additions and 1145 deletions

View file

@ -0,0 +1,38 @@
import { DataLoaderData } from '../types/dataLoader'
import { ValidatorProps } from '../types/validator'
import { Collection } from '@freearhey/core'
import { Validator } from './validator'
import { BlocklistRecord } from '../models'
export class BlocklistRecordValidator extends Validator {
constructor(props: ValidatorProps) {
super(props)
}
validate(blocklistRecord: BlocklistRecord): Collection {
const { channelsKeyById }: DataLoaderData = this.data
let errors = new Collection()
const joiResults = blocklistRecord
.getSchema()
.validate(blocklistRecord.data(), { abortEarly: false })
if (joiResults.error) {
joiResults.error.details.forEach((detail: { message: string }) => {
errors.add({
line: blocklistRecord.getLine(),
message: `${blocklistRecord.channelId}: ${detail.message}`
})
})
}
if (!blocklistRecord.hasValidChannelId(channelsKeyById)) {
errors.add({
line: blocklistRecord.getLine(),
message: `"${blocklistRecord.channelId}" is missing from the channels.csv`
})
}
return errors
}
}

View file

@ -0,0 +1,23 @@
import { ValidatorProps } from '../types/validator'
import { Collection } from '@freearhey/core'
import { Validator } from './validator'
import { Category } from '../models'
export class CategoryValidator extends Validator {
constructor(props: ValidatorProps) {
super(props)
}
validate(category: Category): Collection {
let errors = new Collection()
const joiResults = category.getSchema().validate(category.data(), { abortEarly: false })
if (joiResults.error) {
joiResults.error.details.forEach((detail: { message: string }) => {
errors.add({ line: category.getLine(), message: `${category.id}: ${detail.message}` })
})
}
return errors
}
}

View file

@ -0,0 +1,81 @@
import { ValidatorProps } from '../types/validator'
import { DataLoaderData } from '../types/dataLoader'
import { Collection } from '@freearhey/core'
import { Validator } from './validator'
import { Channel } from '../models'
export class ChannelValidator extends Validator {
constructor(props: ValidatorProps) {
super(props)
}
validate(channel: Channel): Collection {
const {
channelsKeyById,
feedsKeyByStreamId,
countriesKeyByCode,
subdivisionsKeyByCode,
categoriesKeyById
}: DataLoaderData = this.data
let errors = new Collection()
const joiResults = channel.getSchema().validate(channel.data(), { abortEarly: false })
if (joiResults.error) {
joiResults.error.details.forEach((detail: { message: string }) => {
errors.add({ line: channel.getLine(), message: `${channel.id}: ${detail.message}` })
})
}
if (!channel.hasValidId()) {
errors.add({
line: channel.getLine(),
message: `"${channel.id}" must be derived from the channel name "${channel.name}" and the country code "${channel.countryCode}"`
})
}
if (!channel.hasMainFeed()) {
errors.add({
line: channel.getLine(),
message: `"${channel.id}" does not have a main feed`
})
}
if (channel.hasMoreThanOneMainFeed()) {
errors.add({
line: channel.getLine(),
message: `"${channel.id}" has an more than one main feed`
})
}
if (!channel.hasValidReplacedBy(channelsKeyById, feedsKeyByStreamId)) {
errors.add({
line: channel.getLine(),
message: `"${channel.id}" has an invalid replaced_by "${channel.replacedBy}"`
})
}
if (!channel.hasValidCountryCode(countriesKeyByCode)) {
errors.add({
line: channel.getLine(),
message: `"${channel.id}" has an invalid country "${channel.countryCode}"`
})
}
if (!channel.hasValidSubdivisionCode(subdivisionsKeyByCode)) {
errors.add({
line: channel.getLine(),
message: `"${channel.id}" has an invalid subdivision "${channel.subdivisionCode}"`
})
}
if (!channel.hasValidCategoryIds(categoriesKeyById)) {
errors.add({
line: channel.getLine(),
message: `"${channel.id}" has an invalid categories "${channel.getCategoryIds().join(';')}"`
})
}
return errors
}
}

View file

@ -0,0 +1,33 @@
import { ValidatorProps } from '../types/validator'
import { Collection } from '@freearhey/core'
import { Validator } from './validator'
import { Country } from '../models'
import { DataLoaderData } from '../types/dataLoader'
export class CountryValidator extends Validator {
constructor(props: ValidatorProps) {
super(props)
}
validate(country: Country): Collection {
const { languagesKeyByCode }: DataLoaderData = this.data
let errors = new Collection()
const joiResults = country.getSchema().validate(country.data(), { abortEarly: false })
if (joiResults.error) {
joiResults.error.details.forEach((detail: { message: string }) => {
errors.add({ line: country.getLine(), message: `${country.code}: ${detail.message}` })
})
}
if (!country.hasValidLanguageCodes(languagesKeyByCode)) {
errors.add({
line: country.getLine(),
message: `"${country.code}" has an invalid languages "${country.languageCodes.join(';')}"`
})
}
return errors
}
}

View file

@ -0,0 +1,66 @@
import { ValidatorProps } from '../types/validator'
import { Collection } from '@freearhey/core'
import { Validator } from './validator'
import { Feed } from '../models'
import { DataLoaderData } from '../types/dataLoader'
export class FeedValidator extends Validator {
constructor(props: ValidatorProps) {
super(props)
}
validate(feed: Feed): Collection {
const {
channelsKeyById,
countriesKeyByCode,
subdivisionsKeyByCode,
regionsKeyByCode,
timezonesKeyById
}: DataLoaderData = this.data
let errors = new Collection()
const joiResults = feed.getSchema().validate(feed.data(), { abortEarly: false })
if (joiResults.error) {
joiResults.error.details.forEach((detail: { message: string }) => {
errors.add({ line: feed.getLine(), message: `${feed.getStreamId()}: ${detail.message}` })
})
}
if (!feed.hasValidId()) {
errors.add({
line: feed.getLine(),
message: `"${feed.getStreamId()}" id "${feed.id}" must be derived from the name "${
feed.name
}"`
})
}
if (!feed.hasValidChannelId(channelsKeyById)) {
errors.add({
line: feed.getLine(),
message: `"${feed.getStreamId()}" has the wrong channel "${feed.channelId}"`
})
}
if (
!feed.hasValidBroadcastAreaCodes(countriesKeyByCode, subdivisionsKeyByCode, regionsKeyByCode)
) {
errors.add({
line: feed.getLine(),
message: `"${feed.getStreamId()}" has the wrong broadcast_area "${feed.broadcastAreaCodes.join(
';'
)}"`
})
}
if (!feed.hasValidTimezones(timezonesKeyById)) {
errors.add({
line: feed.getLine(),
message: `"${feed.getStreamId()}" has the wrong timezones "${feed.timezoneIds.join(';')}"`
})
}
return errors
}
}

View file

@ -0,0 +1,9 @@
export * from './blocklistRecordValidator'
export * from './categoryValidator'
export * from './channelValidator'
export * from './countryValidator'
export * from './feedValidator'
export * from './languageValidator'
export * from './regionValidator'
export * from './subdivisionValidator'
export * from './timezoneValidator'

View file

@ -0,0 +1,23 @@
import { ValidatorProps } from '../types/validator'
import { Collection } from '@freearhey/core'
import { Validator } from './validator'
import { Language } from '../models'
export class LanguageValidator extends Validator {
constructor(props: ValidatorProps) {
super(props)
}
validate(language: Language): Collection {
let errors = new Collection()
const joiResults = language.getSchema().validate(language.data(), { abortEarly: false })
if (joiResults.error) {
joiResults.error.details.forEach((detail: { message: string }) => {
errors.add({ line: language.getLine(), message: `${language.code}: ${detail.message}` })
})
}
return errors
}
}

View file

@ -0,0 +1,33 @@
import { DataLoaderData } from '../types/dataLoader'
import { ValidatorProps } from '../types/validator'
import { Collection } from '@freearhey/core'
import { Validator } from './validator'
import { Region } from '../models'
export class RegionValidator extends Validator {
constructor(props: ValidatorProps) {
super(props)
}
validate(region: Region): Collection {
const { countriesKeyByCode }: DataLoaderData = this.data
let errors = new Collection()
const joiResults = region.getSchema().validate(region.data(), { abortEarly: false })
if (joiResults.error) {
joiResults.error.details.forEach((detail: { message: string }) => {
errors.add({ line: region.getLine(), message: `${region.code}: ${detail.message}` })
})
}
if (!region.hasValidCountryCodes(countriesKeyByCode)) {
errors.add({
line: region.getLine(),
message: `"${region.code}" has the wrong countries "${region.countryCodes.join(';')}"`
})
}
return errors
}
}

View file

@ -0,0 +1,36 @@
import { ValidatorProps } from '../types/validator'
import { Collection } from '@freearhey/core'
import { Validator } from './validator'
import { Subdivision } from '../models'
import { DataLoaderData } from '../types/dataLoader'
export class SubdivisionValidator extends Validator {
constructor(props: ValidatorProps) {
super(props)
}
validate(subdivision: Subdivision): Collection {
const { countriesKeyByCode }: DataLoaderData = this.data
let errors = new Collection()
const joiResults = subdivision.getSchema().validate(subdivision.data(), { abortEarly: false })
if (joiResults.error) {
joiResults.error.details.forEach((detail: { message: string }) => {
errors.add({
line: subdivision.getLine(),
message: `${subdivision.code}: ${detail.message}`
})
})
}
if (!subdivision.hasValidCountryCode(countriesKeyByCode)) {
errors.add({
line: subdivision.getLine(),
message: `"${subdivision.code}" has an invalid country "${subdivision.countryCode}"`
})
}
return errors
}
}

View file

@ -0,0 +1,33 @@
import { DataLoaderData } from '../types/dataLoader'
import { ValidatorProps } from '../types/validator'
import { Collection } from '@freearhey/core'
import { Validator } from './validator'
import { Timezone } from '../models'
export class TimezoneValidator extends Validator {
constructor(props: ValidatorProps) {
super(props)
}
validate(timezone: Timezone): Collection {
const { countriesKeyByCode }: DataLoaderData = this.data
let errors = new Collection()
const joiResults = timezone.getSchema().validate(timezone.data(), { abortEarly: false })
if (joiResults.error) {
joiResults.error.details.forEach((detail: { message: string }) => {
errors.add({ line: timezone.getLine(), message: `${timezone.id}: ${detail.message}` })
})
}
if (!timezone.hasValidCountryCodes(countriesKeyByCode)) {
errors.add({
line: timezone.getLine(),
message: `"${timezone.id}" has the wrong countries "${timezone.countryCodes.join(';')}"`
})
}
return errors
}
}

View file

@ -0,0 +1,10 @@
import { ValidatorProps } from '../types/validator'
import { DataLoaderData } from '../types/dataLoader'
export class Validator {
data: DataLoaderData
constructor({ data }: ValidatorProps) {
this.data = data
}
}