entity-helper.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. import { DB, SubstrateEvent } from '../../generated/indexer'
  2. import { Channel } from '../../generated/graphql-server/src/modules/channel/channel.model'
  3. import { Category } from '../../generated/graphql-server/src/modules/category/category.model'
  4. import { KnownLicense } from '../../generated/graphql-server/src/modules/known-license/known-license.model'
  5. import { UserDefinedLicense } from '../../generated/graphql-server/src/modules/user-defined-license/user-defined-license.model'
  6. import { JoystreamMediaLocation } from '../../generated/graphql-server/src/modules/joystream-media-location/joystream-media-location.model'
  7. import { HttpMediaLocation } from '../../generated/graphql-server/src/modules/http-media-location/http-media-location.model'
  8. import { VideoMedia } from '../../generated/graphql-server/src/modules/video-media/video-media.model'
  9. import { Video } from '../../generated/graphql-server/src/modules/video/video.model'
  10. import { Block, Network } from '../../generated/graphql-server/src/modules/block/block.model'
  11. import { Language } from '../../generated/graphql-server/src/modules/language/language.model'
  12. import { VideoMediaEncoding } from '../../generated/graphql-server/src/modules/video-media-encoding/video-media-encoding.model'
  13. import { ClassEntity } from '../../generated/graphql-server/src/modules/class-entity/class-entity.model'
  14. import { decode } from './decode'
  15. import {
  16. CategoryPropertyNamesWithId,
  17. channelPropertyNamesWithId,
  18. httpMediaLocationPropertyNamesWithId,
  19. joystreamMediaLocationPropertyNamesWithId,
  20. knownLicensePropertyNamesWIthId,
  21. languagePropertyNamesWIthId,
  22. userDefinedLicensePropertyNamesWithId,
  23. videoMediaEncodingPropertyNamesWithId,
  24. videoPropertyNamesWithId,
  25. contentDirectoryClassNamesWithId,
  26. ContentDirectoryKnownClasses,
  27. } from './content-dir-consts'
  28. import {
  29. ClassEntityMap,
  30. ICategory,
  31. IChannel,
  32. ICreateEntityOperation,
  33. IDBBlockId,
  34. IEntity,
  35. IHttpMediaLocation,
  36. IJoystreamMediaLocation,
  37. IKnownLicense,
  38. ILanguage,
  39. IUserDefinedLicense,
  40. IVideo,
  41. IVideoMedia,
  42. IVideoMediaEncoding,
  43. IWhereCond,
  44. } from '../types'
  45. import { getOrCreate } from './get-or-create'
  46. import * as BN from 'bn.js'
  47. async function createBlockOrGetFromDatabase(db: DB, blockNumber: number): Promise<Block> {
  48. let b = await db.get(Block, { where: { block: blockNumber } })
  49. if (b === undefined) {
  50. // TODO: get timestamp from the event or extrinsic
  51. b = new Block({ block: blockNumber, network: Network.BABYLON, timestamp: new BN(Date.now()) })
  52. await db.save<Block>(b)
  53. }
  54. return b
  55. }
  56. async function createChannel(
  57. { db, block, id }: IDBBlockId,
  58. classEntityMap: ClassEntityMap,
  59. p: IChannel
  60. ): Promise<Channel> {
  61. const record = await db.get(Channel, { where: { id } })
  62. if (record) return record
  63. const channel = new Channel()
  64. channel.version = block
  65. channel.id = id
  66. channel.title = p.title
  67. channel.description = p.description
  68. channel.isCurated = p.isCurated || false
  69. channel.isPublic = p.isPublic
  70. channel.coverPhotoUrl = p.coverPhotoURL
  71. channel.avatarPhotoUrl = p.avatarPhotoURL
  72. if (p.language) channel.language = await getOrCreate.language({ db, block, id }, classEntityMap, p.language)
  73. channel.happenedIn = await createBlockOrGetFromDatabase(db, block)
  74. await db.save(channel)
  75. return channel
  76. }
  77. async function createCategory({ db, block, id }: IDBBlockId, p: ICategory): Promise<Category> {
  78. const record = await db.get(Category, { where: { id } })
  79. if (record) return record
  80. const category = new Category()
  81. category.id = id
  82. category.name = p.name
  83. category.description = p.description
  84. category.version = block
  85. category.happenedIn = await createBlockOrGetFromDatabase(db, block)
  86. await db.save(category)
  87. return category
  88. }
  89. async function createKnownLicense({ db, block, id }: IDBBlockId, p: IKnownLicense): Promise<KnownLicense> {
  90. const record = await db.get(KnownLicense, { where: { id } })
  91. if (record) return record
  92. const knownLicence = new KnownLicense()
  93. knownLicence.id = id
  94. knownLicence.code = p.code
  95. knownLicence.name = p.name
  96. knownLicence.description = p.description
  97. knownLicence.url = p.url
  98. knownLicence.version = block
  99. knownLicence.happenedIn = await createBlockOrGetFromDatabase(db, block)
  100. await db.save(knownLicence)
  101. return knownLicence
  102. }
  103. async function createUserDefinedLicense(
  104. { db, block, id }: IDBBlockId,
  105. p: IUserDefinedLicense
  106. ): Promise<UserDefinedLicense> {
  107. const record = await db.get(UserDefinedLicense, { where: { id } })
  108. if (record) return record
  109. const userDefinedLicense = new UserDefinedLicense()
  110. userDefinedLicense.id = id
  111. userDefinedLicense.content = p.content
  112. userDefinedLicense.version = block
  113. userDefinedLicense.happenedIn = await createBlockOrGetFromDatabase(db, block)
  114. await db.save<UserDefinedLicense>(userDefinedLicense)
  115. return userDefinedLicense
  116. }
  117. async function createJoystreamMediaLocation(
  118. { db, block, id }: IDBBlockId,
  119. p: IJoystreamMediaLocation
  120. ): Promise<JoystreamMediaLocation> {
  121. const record = await db.get(JoystreamMediaLocation, { where: { id } })
  122. if (record) return record
  123. const joyMediaLoc = new JoystreamMediaLocation()
  124. joyMediaLoc.id = id
  125. joyMediaLoc.dataObjectId = p.dataObjectId
  126. joyMediaLoc.version = block
  127. joyMediaLoc.happenedIn = await createBlockOrGetFromDatabase(db, block)
  128. await db.save(joyMediaLoc)
  129. return joyMediaLoc
  130. }
  131. async function createHttpMediaLocation(
  132. { db, block, id }: IDBBlockId,
  133. p: IHttpMediaLocation
  134. ): Promise<HttpMediaLocation> {
  135. const record = await db.get(HttpMediaLocation, { where: { id } })
  136. if (record) return record
  137. const httpMediaLoc = new HttpMediaLocation()
  138. httpMediaLoc.id = id
  139. httpMediaLoc.url = p.url
  140. httpMediaLoc.port = p.port
  141. httpMediaLoc.version = block
  142. httpMediaLoc.happenedIn = await createBlockOrGetFromDatabase(db, block)
  143. await db.save(httpMediaLoc)
  144. return httpMediaLoc
  145. }
  146. async function createVideoMedia(
  147. { db, block, id }: IDBBlockId,
  148. classEntityMap: ClassEntityMap,
  149. p: IVideoMedia
  150. ): Promise<VideoMedia> {
  151. const videoMedia = new VideoMedia()
  152. videoMedia.id = id
  153. videoMedia.pixelHeight = p.pixelHeight
  154. videoMedia.pixelWidth = p.pixelWidth
  155. videoMedia.size = p.size
  156. videoMedia.version = block
  157. const { encoding, location } = p
  158. if (encoding) videoMedia.encoding = await getOrCreate.videoMediaEncoding({ db, block, id }, classEntityMap, encoding)
  159. if (location) {
  160. // TODO: We need to make sure to create only one location either http or joystream
  161. videoMedia.httpMediaLocation = await getOrCreate.httpMediaLocation({ db, block, id }, classEntityMap, location)
  162. videoMedia.joystreamMediaLocation = await getOrCreate.joystreamMediaLocation(
  163. { db, block, id },
  164. classEntityMap,
  165. location
  166. )
  167. }
  168. videoMedia.happenedIn = await createBlockOrGetFromDatabase(db, block)
  169. await db.save(videoMedia)
  170. return videoMedia
  171. }
  172. async function createVideo({ db, block, id }: IDBBlockId, classEntityMap: ClassEntityMap, p: IVideo): Promise<Video> {
  173. const record = await db.get(Video, { where: { id } })
  174. if (record) return record
  175. const video = new Video()
  176. video.id = id
  177. video.title = p.title
  178. video.description = p.description
  179. video.duration = p.duration
  180. video.hasMarketing = p.hasMarketing
  181. // TODO: needs to be handled correctly, from runtime CurationStatus is coming
  182. video.isCurated = p.isCurated || true
  183. video.isExplicit = p.isExplicit
  184. video.isPublic = p.isPublic
  185. video.publishedBeforeJoystream = p.publishedBeforeJoystream
  186. video.skippableIntroDuration = p.skippableIntroDuration
  187. video.thumbnailUrl = p.thumbnailURL
  188. video.version = block
  189. const { language, license, category, channel, media } = p
  190. if (language) video.language = await getOrCreate.language({ db, block, id }, classEntityMap, language)
  191. if (license) {
  192. video.knownLicense = await getOrCreate.knownLicense({ db, block, id }, classEntityMap, license)
  193. video.userdefinedLicense = await getOrCreate.userDefinedLicense({ db, block, id }, classEntityMap, license)
  194. }
  195. if (category) video.category = await getOrCreate.category({ db, block, id }, classEntityMap, category)
  196. if (channel) video.channel = await getOrCreate.channel({ db, block, id }, classEntityMap, channel)
  197. video.happenedIn = await createBlockOrGetFromDatabase(db, block)
  198. if (media) video.media = await getOrCreate.videoMedia({ db, block, id }, classEntityMap, media)
  199. await db.save<Video>(video)
  200. return video
  201. }
  202. async function createLanguage({ db, block, id }: IDBBlockId, p: ILanguage): Promise<Language> {
  203. const record = await db.get(Language, { where: { id } })
  204. if (record) return record
  205. const language = new Language()
  206. language.id = id
  207. language.name = p.name
  208. language.code = p.code
  209. language.version = block
  210. language.happenedIn = await createBlockOrGetFromDatabase(db, block)
  211. await db.save<Language>(language)
  212. return language
  213. }
  214. async function createVideoMediaEncoding(
  215. { db, block, id }: IDBBlockId,
  216. p: IVideoMediaEncoding
  217. ): Promise<VideoMediaEncoding> {
  218. const record = await db.get(VideoMediaEncoding, { where: { id } })
  219. if (record) return record
  220. const encoding = new VideoMediaEncoding()
  221. encoding.id = id
  222. encoding.name = p.name
  223. encoding.version = block
  224. // happenedIn is not defined in the graphql schema!
  225. encoding.happenedIn = await createBlockOrGetFromDatabase(db, block)
  226. await db.save<VideoMediaEncoding>(encoding)
  227. return encoding
  228. }
  229. async function batchCreateClassEntities(db: DB, block: number, operations: ICreateEntityOperation[]): Promise<void> {
  230. // Create entities before adding schema support
  231. operations.map(async ({ classId }, index) => {
  232. const c = new ClassEntity()
  233. c.id = index.toString()
  234. c.classId = classId
  235. c.version = block
  236. c.happenedIn = await createBlockOrGetFromDatabase(db, block)
  237. await db.save<ClassEntity>(c)
  238. })
  239. }
  240. async function getClassName(
  241. db: DB,
  242. entity: IEntity,
  243. createEntityOperations: ICreateEntityOperation[]
  244. ): Promise<string | undefined> {
  245. const { entityId, indexOf } = entity
  246. if (entityId === undefined && indexOf === undefined) {
  247. throw Error(`Can not determine class of the entity`)
  248. }
  249. let classId: number | undefined
  250. // Is newly created entity in the same transaction
  251. if (indexOf !== undefined) {
  252. classId = createEntityOperations[indexOf].classId
  253. } else {
  254. const ce = await db.get(ClassEntity, { where: { id: entityId } })
  255. if (ce === undefined) console.log(`Class not found for the entity: ${entityId}`)
  256. classId = ce ? ce.classId : undefined
  257. }
  258. const c = contentDirectoryClassNamesWithId.find((c) => c.classId === classId)
  259. // TODO: stop execution, class should be created before entity creation
  260. if (c === undefined) console.log(`Not recognized class id: ${classId}`)
  261. return c ? c.name : undefined
  262. }
  263. async function removeChannel(db: DB, where: IWhereCond): Promise<void> {
  264. const record = await db.get(Channel, where)
  265. if (record === undefined) throw Error(`Channel not found`)
  266. if (record.videos) record.videos.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
  267. await db.remove<Channel>(record)
  268. }
  269. async function removeCategory(db: DB, where: IWhereCond): Promise<void> {
  270. const record = await db.get(Category, where)
  271. if (record === undefined) throw Error(`Category not found`)
  272. if (record.videos) record.videos.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
  273. await db.remove<Category>(record)
  274. }
  275. async function removeVideoMedia(db: DB, where: IWhereCond): Promise<void> {
  276. const record = await db.get(VideoMedia, where)
  277. if (record === undefined) throw Error(`VideoMedia not found`)
  278. if (record.video) await db.remove<Video>(record.video)
  279. await db.remove<VideoMedia>(record)
  280. }
  281. async function removeVideo(db: DB, where: IWhereCond): Promise<void> {
  282. const record = await db.get(Video, where)
  283. if (record === undefined) throw Error(`Video not found`)
  284. await db.remove<Video>(record)
  285. }
  286. async function removeUserDefinedLicense(db: DB, where: IWhereCond): Promise<void> {
  287. const record = await db.get(UserDefinedLicense, where)
  288. if (record === undefined) throw Error(`UserDefinedLicense not found`)
  289. if (record.videouserdefinedLicense)
  290. record.videouserdefinedLicense.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
  291. await db.remove<UserDefinedLicense>(record)
  292. }
  293. async function removeKnownLicense(db: DB, where: IWhereCond): Promise<void> {
  294. const record = await db.get(KnownLicense, where)
  295. if (record === undefined) throw Error(`KnownLicense not found`)
  296. if (record.videoknownLicense)
  297. record.videoknownLicense.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
  298. await db.remove<KnownLicense>(record)
  299. }
  300. async function removeHttpMediaLocation(db: DB, where: IWhereCond): Promise<void> {
  301. const record = await db.get(HttpMediaLocation, where)
  302. if (record === undefined) throw Error(`HttpMediaLocation not found`)
  303. if (record.videomediahttpMediaLocation)
  304. record.videomediahttpMediaLocation.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
  305. await db.remove<HttpMediaLocation>(record)
  306. }
  307. async function removeJoystreamMediaLocation(db: DB, where: IWhereCond): Promise<void> {
  308. const record = await db.get(JoystreamMediaLocation, where)
  309. if (record === undefined) throw Error(`JoystreamMediaLocation not found`)
  310. if (record.videomediajoystreamMediaLocation)
  311. record.videomediajoystreamMediaLocation.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
  312. await db.remove<JoystreamMediaLocation>(record)
  313. }
  314. async function removeLanguage(db: DB, where: IWhereCond): Promise<void> {
  315. const record = await db.get(Language, where)
  316. if (record === undefined) throw Error(`Language not found`)
  317. if (record.channellanguage) record.channellanguage.map(async (c) => await removeChannel(db, { where: { id: c.id } }))
  318. if (record.videolanguage) record.videolanguage.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
  319. await db.remove<Language>(record)
  320. }
  321. async function removeVideoMediaEncoding(db: DB, where: IWhereCond): Promise<void> {
  322. const record = await db.get(VideoMediaEncoding, where)
  323. if (record === undefined) throw Error(`Language not found`)
  324. await db.remove<VideoMediaEncoding>(record)
  325. }
  326. // ========Entity property value updates========
  327. async function updateCategoryEntityPropertyValues(db: DB, where: IWhereCond, props: ICategory): Promise<void> {
  328. const record = await db.get(Category, where)
  329. if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
  330. Object.assign(record, props)
  331. await db.save<Category>(record)
  332. }
  333. async function updateChannelEntityPropertyValues(db: DB, where: IWhereCond, props: IChannel): Promise<void> {
  334. const record = await db.get(Channel, where)
  335. if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
  336. if (props.language) {
  337. const l = await db.get(Language, { where: { id: props.language.toString() } })
  338. if (l === undefined) throw Error(`Language entity not found: ${props.language}`)
  339. record.language = l
  340. props.language = undefined
  341. }
  342. Object.assign(record, props)
  343. await db.save<Channel>(record)
  344. }
  345. async function updateVideoMediaEntityPropertyValues(db: DB, where: IWhereCond, props: IVideoMedia): Promise<void> {
  346. const record = await db.get(VideoMedia, where)
  347. if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
  348. const { encoding, location } = props
  349. if (encoding) {
  350. const e = await db.get(VideoMediaEncoding, { where: { id: encoding.toString() } })
  351. if (e === undefined) throw Error(`VideoMediaEncoding entity not found: ${encoding}`)
  352. record.encoding = e
  353. props.encoding = undefined
  354. }
  355. if (location) {
  356. const httpLoc = await db.get(HttpMediaLocation, { where: { id: location.toString() } })
  357. const joyLoc = await db.get(JoystreamMediaLocation, { where: { id: location.toString() } })
  358. if (!httpLoc && !joyLoc) throw Error(`HttpMediaLocation/JoystreamMediaLocation entity not found: ${location}`)
  359. record.httpMediaLocation = httpLoc
  360. record.joystreamMediaLocation = joyLoc
  361. props.location = undefined
  362. }
  363. Object.assign(record, props)
  364. await db.save<VideoMedia>(record)
  365. }
  366. async function updateVideoEntityPropertyValues(db: DB, where: IWhereCond, props: IVideo): Promise<void> {
  367. const record = await db.get<Video>(Video, where)
  368. if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
  369. const { channel, category, language, media, license } = props
  370. if (channel) {
  371. const c = await db.get(Channel, { where: { id: channel.toString() } })
  372. if (c === undefined) throw Error(`Channel entity not found: ${channel}`)
  373. record.channel = c
  374. props.channel = undefined
  375. }
  376. if (category) {
  377. const c = await db.get(Category, { where: { id: category.toString() } })
  378. if (c === undefined) throw Error(`Category entity not found: ${category}`)
  379. record.category = c
  380. props.category = undefined
  381. }
  382. if (media) {
  383. const m = await db.get(VideoMedia, { where: { id: media.toString() } })
  384. if (m === undefined) throw Error(`VideoMedia entity not found: ${channel}`)
  385. record.media = m
  386. props.media = undefined
  387. }
  388. if (license) {
  389. const k = await db.get(KnownLicense, { where: { id: license.toString() } })
  390. const u = await db.get(UserDefinedLicense, { where: { id: license.toString() } })
  391. if (!k && !u) throw Error(`KnownLicense/UserDefinedLicense entity not found: ${license}`)
  392. record.knownLicense = k
  393. record.userdefinedLicense = u
  394. props.license = undefined
  395. }
  396. if (language) {
  397. const l = await db.get(Language, { where: { id: language.toString() } })
  398. if (l === undefined) throw Error(`Language entity not found: ${language}`)
  399. record.language = l
  400. props.language = undefined
  401. }
  402. Object.assign(record, props)
  403. await db.save<Video>(record)
  404. }
  405. async function updateUserDefinedLicenseEntityPropertyValues(
  406. db: DB,
  407. where: IWhereCond,
  408. props: IUserDefinedLicense
  409. ): Promise<void> {
  410. const record = await db.get(UserDefinedLicense, where)
  411. if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
  412. Object.assign(record, props)
  413. await db.save<UserDefinedLicense>(record)
  414. }
  415. async function updateKnownLicenseEntityPropertyValues(db: DB, where: IWhereCond, props: IKnownLicense): Promise<void> {
  416. const record = await db.get(KnownLicense, where)
  417. if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
  418. Object.assign(record, props)
  419. await db.save<KnownLicense>(record)
  420. }
  421. async function updateHttpMediaLocationEntityPropertyValues(
  422. db: DB,
  423. where: IWhereCond,
  424. props: IHttpMediaLocation
  425. ): Promise<void> {
  426. const record = await db.get(HttpMediaLocation, where)
  427. if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
  428. Object.assign(record, props)
  429. await db.save<HttpMediaLocation>(record)
  430. }
  431. async function updateJoystreamMediaLocationEntityPropertyValues(
  432. db: DB,
  433. where: IWhereCond,
  434. props: IJoystreamMediaLocation
  435. ): Promise<void> {
  436. const record = await db.get(JoystreamMediaLocation, where)
  437. if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
  438. Object.assign(record, props)
  439. await db.save<JoystreamMediaLocation>(record)
  440. }
  441. async function updateLanguageEntityPropertyValues(db: DB, where: IWhereCond, props: ILanguage): Promise<void> {
  442. const record = await db.get(Language, where)
  443. if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
  444. Object.assign(record, props)
  445. await db.save<Language>(record)
  446. }
  447. async function updateVideoMediaEncodingEntityPropertyValues(
  448. db: DB,
  449. where: IWhereCond,
  450. props: IVideoMediaEncoding
  451. ): Promise<void> {
  452. const record = await db.get(VideoMediaEncoding, where)
  453. if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
  454. Object.assign(record, props)
  455. await db.save<VideoMediaEncoding>(record)
  456. }
  457. async function updateEntityPropertyValues(
  458. db: DB,
  459. event: SubstrateEvent,
  460. where: IWhereCond,
  461. className: string
  462. ): Promise<void> {
  463. switch (className) {
  464. case ContentDirectoryKnownClasses.CHANNEL:
  465. await updateChannelEntityPropertyValues(
  466. db,
  467. where,
  468. decode.setProperties<IChannel>(event, channelPropertyNamesWithId)
  469. )
  470. break
  471. case ContentDirectoryKnownClasses.CATEGORY:
  472. await updateCategoryEntityPropertyValues(
  473. db,
  474. where,
  475. decode.setProperties<ICategory>(event, CategoryPropertyNamesWithId)
  476. )
  477. break
  478. case ContentDirectoryKnownClasses.KNOWNLICENSE:
  479. await updateKnownLicenseEntityPropertyValues(
  480. db,
  481. where,
  482. decode.setProperties<IKnownLicense>(event, knownLicensePropertyNamesWIthId)
  483. )
  484. break
  485. case ContentDirectoryKnownClasses.USERDEFINEDLICENSE:
  486. await updateUserDefinedLicenseEntityPropertyValues(
  487. db,
  488. where,
  489. decode.setProperties<IUserDefinedLicense>(event, userDefinedLicensePropertyNamesWithId)
  490. )
  491. break
  492. case ContentDirectoryKnownClasses.JOYSTREAMMEDIALOCATION:
  493. await updateJoystreamMediaLocationEntityPropertyValues(
  494. db,
  495. where,
  496. decode.setProperties<IJoystreamMediaLocation>(event, joystreamMediaLocationPropertyNamesWithId)
  497. )
  498. break
  499. case ContentDirectoryKnownClasses.HTTPMEDIALOCATION:
  500. await updateHttpMediaLocationEntityPropertyValues(
  501. db,
  502. where,
  503. decode.setProperties<IHttpMediaLocation>(event, httpMediaLocationPropertyNamesWithId)
  504. )
  505. break
  506. case ContentDirectoryKnownClasses.VIDEOMEDIA:
  507. await updateVideoMediaEntityPropertyValues(
  508. db,
  509. where,
  510. decode.setProperties<IVideoMedia>(event, videoPropertyNamesWithId)
  511. )
  512. break
  513. case ContentDirectoryKnownClasses.VIDEO:
  514. await updateVideoEntityPropertyValues(db, where, decode.setProperties<IVideo>(event, videoPropertyNamesWithId))
  515. break
  516. case ContentDirectoryKnownClasses.LANGUAGE:
  517. await updateLanguageEntityPropertyValues(
  518. db,
  519. where,
  520. decode.setProperties<ILanguage>(event, languagePropertyNamesWIthId)
  521. )
  522. break
  523. case ContentDirectoryKnownClasses.VIDEOMEDIAENCODING:
  524. await updateVideoMediaEncodingEntityPropertyValues(
  525. db,
  526. where,
  527. decode.setProperties<IVideoMediaEncoding>(event, videoMediaEncodingPropertyNamesWithId)
  528. )
  529. break
  530. default:
  531. throw new Error(`Unknown class name: ${className}`)
  532. }
  533. }
  534. export {
  535. createCategory,
  536. createChannel,
  537. createVideoMedia,
  538. createVideo,
  539. createUserDefinedLicense,
  540. createKnownLicense,
  541. createHttpMediaLocation,
  542. createJoystreamMediaLocation,
  543. createLanguage,
  544. createVideoMediaEncoding,
  545. removeCategory,
  546. removeChannel,
  547. removeVideoMedia,
  548. removeVideo,
  549. removeUserDefinedLicense,
  550. removeKnownLicense,
  551. removeHttpMediaLocation,
  552. removeJoystreamMediaLocation,
  553. removeLanguage,
  554. removeVideoMediaEncoding,
  555. createBlockOrGetFromDatabase,
  556. batchCreateClassEntities,
  557. getClassName,
  558. updateCategoryEntityPropertyValues,
  559. updateChannelEntityPropertyValues,
  560. updateVideoMediaEntityPropertyValues,
  561. updateVideoEntityPropertyValues,
  562. updateUserDefinedLicenseEntityPropertyValues,
  563. updateHttpMediaLocationEntityPropertyValues,
  564. updateJoystreamMediaLocationEntityPropertyValues,
  565. updateKnownLicenseEntityPropertyValues,
  566. updateLanguageEntityPropertyValues,
  567. updateVideoMediaEncodingEntityPropertyValues,
  568. updateEntityPropertyValues,
  569. }