瀏覽代碼

Query node for storage_v2 - initial project setup

Leszek Wiesner 3 年之前
父節點
當前提交
6b41894508

+ 3 - 2
package.json

@@ -26,6 +26,7 @@
     "utils/api-scripts",
     "content-directory-schemas",
     "query-node",
+    "query-node/mappings",
     "query-node/generated/*"
   ],
   "resolutions": {
@@ -54,11 +55,11 @@
     }
   },
   "engines": {
-    "node": ">=12.18.0",
+    "node": ">=14.16.1",
     "yarn": "^1.22.0"
   },
   "volta": {
-    "node": "12.18.2",
+    "node": "14.16.1",
     "yarn": "1.22.4"
   }
 }

+ 7 - 13
query-node/build.sh

@@ -9,21 +9,15 @@ set -a
 . ../.env
 set +a
 
+# only use this when new Hydra releases and contents of `generated/` folder needs to be refreshed
 yarn clean
+yarn codegen:noinstall
+yarn typegen # if this fails try to run this command outside of yarn workspaces
 
-# Build graphql-server customizing DB name
-yarn codegen
-yarn typegen
+yarn workspace query-node codegen
+yarn workspace query-node build
+yarn workspace query-node-mappings build
 
-echo "Building mappings..."
-(cd mappings && yarn build)
-echo "Done."
-
-# Copy joy types
-cp ./mappings/generated/types/typedefs.json ./mappings/lib/mappings/generated/types/typedefs.json
-
-# We run yarn again to ensure processor and indexer dependencies are installed
+# We run yarn again to ensure graphql-server dependencies are installed
 # and are inline with root workspace resolutions
 yarn
-
-ln -s ../../../../../node_modules/typeorm/cli.js generated/graphql-server/node_modules/.bin/typeorm || :

+ 45 - 27
query-node/manifest.yml

@@ -1,45 +1,63 @@
-version: '0.1'
-description: Joystream query-node manifest file for antioch
+version: '3.0'
+description: Joystream query-node manifest file for storage v2
 repository: https://github.com/Joystream/joystream
-hydraVersion: '2'
+hydraVersion: "3"
 dataSource:
-  indexerVersion: '3.9'
   kind: substrate
   chain: joystream
 entities:
-  - mappings/lib/generated/**/*.model.js
+  - generated/graphql-server/dist/src/modules/**/*.model.js
 typegen:
   metadata:
-    source: wss://staging-3.joystream.app/rpc
+    source: ws://localhost:9944
   events:
-    - contentDirectory.EntityCreated
-    - contentDirectory.EntityRemoved
-    - contentDirectory.EntitySchemaSupportAdded
-    - contentDirectory.EntityPropertyValuesUpdated
-    - contentDirectory.TransactionCompleted
-    - contentDirectory.TransactionFailed
+    - storage.StorageBucketCreated
+    - storage.StorageBucketInvitationAccepted
+    - storage.StorageBucketsUpdatedForBag
+    - storage.DataObjectdUploaded
+    - storage.StorageOperatorMetadataSet
+    - storage.StorageBucketVoucherLimitsSet
+    - storage.PendingDataObjectsAccepted
+    - storage.StorageBucketInvitationCancelled
+    - storage.StorageBucketOperatorInvited
+    - storage.StorageBucketOperatorRemoved
+    - storage.UploadingBlockStatusUpdated
+    - storage.DataObjectPerMegabyteFeeUpdated
+    - storage.StorageBucketsPerBagLimitUpdated
+    - storage.StorageBucketsVoucherMaxLimitsUpdated
+    - storage.DataObjectsMoved
+    - storage.DataObjectsDeleted
+    - storage.StorageBucketStatusUpdated
+    - storage.UpdateBlacklist
+    - storage.DynamicBagDeleted
+    - storage.DynamicBagCreated
+    - storage.DeletionPrizeChanged
+    - storage.VoucherChanged
+    - storage.StorageBucketDeleted
+    - storage.NumberOfStorageBucketsInDynamicBagCreationPolicyUpdated
+  calls:
+    # - members.updateProfile
   outDir: ./mappings/generated/types
   customTypes:
     lib: '@joystream/types/augment/all/types'
     typedefsLoc: '../types/augment/all/defs.json'
 mappings:
-  hydraCommonVersion: '2.0.1-beta.0'
   # js module that exports the handler functions
-  mappingsModule: mappings/lib/mappings
+  mappingsModule: mappings/lib
   # additinal libraries the processor loads
   # typically it is a module with event and extrinsic types generated by hydra-typegen
   imports:
-    - mappings/lib/mappings/generated/types
+    - mappings/lib/generated/types
   eventHandlers:
-    - event: contentDirectory.EntityCreated
-      handler: contentDirectory_EntityCreated(DatabaseManager, SubstrateEvent)
-    - event: contentDirectory.EntityRemoved
-      handler: contentDirectory_EntityRemoved(DatabaseManager, SubstrateEvent)
-    - event: contentDirectory.EntitySchemaSupportAdded
-      handler: contentDirectory_EntitySchemaSupportAdded(DatabaseManager, SubstrateEvent)
-    - event: contentDirectory.EntityPropertyValuesUpdated
-      handler: contentDirectory_EntityPropertyValuesUpdated(DatabaseManager, SubstrateEvent)
-    - event: contentDirectory.TransactionCompleted
-      handler: contentDirectory_TransactionCompleted(DatabaseManager, SubstrateEvent)
-    - event: contentDirectory.TransactionFailed
-      handler: contentDirectory_TransactionFailed(DatabaseManager, SubstrateEvent)
+    # - event: storage.StorageBucketCreated
+    #   handler: storage_StorageBucketCreated
+  extrinsicHandlers:
+    # infer defaults here
+    #- extrinsic: Balances.Transfer
+    #- extrinsic: Sudo.batchCall
+    #  handler: handleSudoCall(DatabaseManager,SubstrateEvent)
+  preBlockHooks:
+    - handler: loadGenesisData
+      filter:
+        height: "[0,0]" # will be executed only at genesis
+  postBlockHooks:

+ 0 - 123
query-node/mappings/content-directory/content-dir-consts.ts

@@ -1,123 +0,0 @@
-import { IKnownClass, IPropertyWithId } from '../types'
-
-// Content directory predefined class names
-export enum ContentDirectoryKnownClasses {
-  CHANNEL = 'Channel',
-  CATEGORY = 'Category',
-  HTTPMEDIALOCATION = 'HttpMediaLocation',
-  JOYSTREAMMEDIALOCATION = 'JoystreamMediaLocation',
-  KNOWNLICENSE = 'KnownLicense',
-  LANGUAGE = 'Language',
-  LICENSE = 'License',
-  MEDIALOCATION = 'MediaLocation',
-  USERDEFINEDLICENSE = 'UserDefinedLicense',
-  VIDEO = 'Video',
-  VIDEOMEDIA = 'VideoMedia',
-  VIDEOMEDIAENCODING = 'VideoMediaEncoding',
-  FEATUREDVIDEOS = 'FeaturedVideo',
-}
-
-// Predefined content-directory classes, classId may change after the runtime seeding
-export const contentDirectoryClassNamesWithId: IKnownClass[] = [
-  { name: ContentDirectoryKnownClasses.CHANNEL, classId: 1 },
-  { name: ContentDirectoryKnownClasses.CATEGORY, classId: 2 },
-  { name: ContentDirectoryKnownClasses.HTTPMEDIALOCATION, classId: 3 },
-  { name: ContentDirectoryKnownClasses.JOYSTREAMMEDIALOCATION, classId: 4 },
-  { name: ContentDirectoryKnownClasses.KNOWNLICENSE, classId: 5 },
-  { name: ContentDirectoryKnownClasses.LANGUAGE, classId: 6 },
-  { name: ContentDirectoryKnownClasses.LICENSE, classId: 7 },
-  { name: ContentDirectoryKnownClasses.MEDIALOCATION, classId: 8 },
-  { name: ContentDirectoryKnownClasses.USERDEFINEDLICENSE, classId: 9 },
-  { name: ContentDirectoryKnownClasses.VIDEO, classId: 10 },
-  { name: ContentDirectoryKnownClasses.VIDEOMEDIA, classId: 11 },
-  { name: ContentDirectoryKnownClasses.VIDEOMEDIAENCODING, classId: 12 },
-  { name: ContentDirectoryKnownClasses.FEATUREDVIDEOS, classId: 13 },
-]
-
-export const categoryPropertyNamesWithId: IPropertyWithId = {
-  0: { name: 'name', type: 'string', required: true },
-  1: { name: 'description', type: 'string', required: false },
-}
-
-export const channelPropertyNamesWithId: IPropertyWithId = {
-  0: { name: 'handle', type: 'string', required: true },
-  1: { name: 'description', type: 'string', required: false },
-  2: { name: 'coverPhotoUrl', type: 'string', required: false },
-  3: { name: 'avatarPhotoUrl', type: 'string', required: false },
-  4: { name: 'isPublic', type: 'boolean', required: true },
-  5: { name: 'isCurated', type: 'boolean', required: false },
-  6: { name: 'language', type: 'number', required: false },
-}
-
-export const licensePropertyNamesWithId: IPropertyWithId = {
-  0: { name: 'knownLicense', type: 'number', required: false },
-  1: { name: 'userDefinedLicense', type: 'number', required: false },
-  2: { name: 'attribution', type: 'string', required: false },
-}
-
-export const knownLicensePropertyNamesWIthId: IPropertyWithId = {
-  0: { name: 'code', type: 'string', required: true },
-  1: { name: 'name', type: 'string', required: false },
-  2: { name: 'description', type: 'string', required: false },
-  3: { name: 'url', type: 'string', required: false },
-}
-
-export const languagePropertyNamesWIthId: IPropertyWithId = {
-  0: { name: 'name', type: 'string', required: true },
-  1: { name: 'code', type: 'string', required: true },
-}
-
-export const userDefinedLicensePropertyNamesWithId: IPropertyWithId = {
-  0: { name: 'content', type: 'string', required: false },
-}
-
-export const mediaLocationPropertyNamesWithId: IPropertyWithId = {
-  0: { name: 'httpMediaLocation', type: 'number', required: false },
-  1: { name: 'joystreamMediaLocation', type: 'number', required: false },
-}
-
-export const joystreamMediaLocationPropertyNamesWithId: IPropertyWithId = {
-  0: { name: 'dataObjectId', type: 'string', required: true },
-}
-
-export const httpMediaLocationPropertyNamesWithId: IPropertyWithId = {
-  0: { name: 'url', type: 'string', required: false },
-  1: { name: 'port', type: 'number', required: false },
-}
-
-export const videoMediaEncodingPropertyNamesWithId: IPropertyWithId = {
-  0: { name: 'name', type: 'string', required: true },
-}
-
-export const videoMediaPropertyNamesWithId: IPropertyWithId = {
-  0: { name: 'encoding', type: 'number', required: true },
-  1: { name: 'pixelWidth', type: 'number', required: true },
-  2: { name: 'pixelHeight', type: 'number', required: true },
-  3: { name: 'size', type: 'number', required: false },
-  4: { name: 'location', type: 'number', required: true },
-}
-
-export const videoPropertyNamesWithId: IPropertyWithId = {
-  // referenced entity's id
-  0: { name: 'channel', type: 'number', required: true },
-  // referenced entity's id
-  1: { name: 'category', type: 'number', required: true },
-  2: { name: 'title', type: 'string', required: false },
-  3: { name: 'description', type: 'string', required: false },
-  4: { name: 'duration', type: 'number', required: true },
-  5: { name: 'skippableIntroDuration', type: 'number', required: false },
-  6: { name: 'thumbnailUrl', type: 'string', required: true },
-  7: { name: 'language', type: 'number', required: false },
-  // referenced entity's id
-  8: { name: 'media', type: 'number', required: true },
-  9: { name: 'hasMarketing', type: 'boolean', required: false },
-  10: { name: 'publishedBeforeJoystream', type: 'number', required: false },
-  11: { name: 'isPublic', type: 'boolean', required: true },
-  12: { name: 'isExplicit', type: 'boolean', required: true },
-  13: { name: 'license', type: 'number', required: true },
-  14: { name: 'isCurated', type: 'boolean', required: true },
-}
-
-export const featuredVideoPropertyNamesWithId: IPropertyWithId = {
-  0: { name: 'video', type: 'number', required: true },
-}

+ 0 - 174
query-node/mappings/content-directory/decode.ts

@@ -1,174 +0,0 @@
-import { SubstrateEvent } from '@dzlzv/hydra-common'
-import {
-  IClassEntity,
-  IProperty,
-  IBatchOperation,
-  ICreateEntityOperation,
-  IEntity,
-  IReference,
-  IPropertyWithId,
-} from '../types'
-import Debug from 'debug'
-
-import {
-  OperationType,
-  ParametrizedClassPropertyValue,
-  UpdatePropertyValuesOperation,
-} from '@joystream/types/content-directory'
-import { createType } from '@joystream/types'
-import { Vec } from '@polkadot/types'
-
-const debug = Debug('mappings:cd:decode')
-
-function stringIfyEntityId(event: SubstrateEvent): string {
-  const { 1: entityId } = event.params
-  return entityId.value as string
-}
-
-function setProperties<T>({ extrinsic, blockNumber }: SubstrateEvent, propNamesWithId: IPropertyWithId): T {
-  if (extrinsic === undefined) throw Error('Undefined extrinsic')
-
-  const { 3: newPropertyValues } = extrinsic!.args
-  const properties: { [key: string]: any; reference?: IReference } = {}
-
-  for (const [k, v] of Object.entries(newPropertyValues.value)) {
-    const prop = propNamesWithId[k]
-    const singlePropVal = createType('InputPropertyValue', v as any).asType('Single')
-
-    if (singlePropVal.isOfType('Reference')) {
-      properties[prop.name] = { entityId: singlePropVal.asType('Reference').toJSON(), existing: true }
-    } else {
-      const val = singlePropVal.value.toJSON()
-      if (typeof val !== prop.type && !prop.required) properties[prop.name] = undefined
-      else properties[prop.name] = val
-    }
-  }
-  properties.version = blockNumber
-
-  debug(`Entity properties: ${JSON.stringify(properties)}`)
-  return properties as T
-}
-
-function getClassEntity(event: SubstrateEvent): IClassEntity {
-  const { 0: classId } = event.extrinsic!.args
-  const { 1: entityId } = event.params
-  return {
-    entityId: (entityId.value as unknown) as number,
-    classId: (classId.value as unknown) as number,
-  }
-}
-
-/**
- * When entity is creation through `transaction` extrinsic we use this function to parse
- * entity properties it looks quite similar to `setProperties` function
- * @param properties
- * @param propertyNamesWithId
- */
-function setEntityPropertyValues<T>(properties: IProperty[], propertyNamesWithId: IPropertyWithId): T {
-  const entityProperties: { [key: string]: any; reference?: IReference } = {}
-
-  for (const [propId, propName] of Object.entries(propertyNamesWithId)) {
-    // get the property value by id
-    const p = properties.find((p) => p.id === propId)
-    if (!p) continue
-
-    if (typeof p.value !== propName.type && !propName.required) entityProperties[propName.name] = undefined
-    else entityProperties[propName.name] = p.reference ? p.reference : p.value
-  }
-  debug(`Entity properties: ${JSON.stringify(entityProperties)}`)
-  return entityProperties as T
-}
-
-// Decode entity property values
-function getEntityProperties(propertyValues: ParametrizedClassPropertyValue[]): IProperty[] {
-  const properties: IProperty[] = []
-  const entityPropertyValues = createType('Vec<ParametrizedClassPropertyValue>', propertyValues)
-
-  entityPropertyValues.map((pv: ParametrizedClassPropertyValue) => {
-    const v = createType('ParametrizedPropertyValue', pv.value)
-    const propertyId = pv.in_class_index.toJSON()
-
-    let reference
-    let value
-    if (v.isOfType('InputPropertyValue')) {
-      const inputPropVal = v.asType('InputPropertyValue')
-      value = inputPropVal.isOfType('Single')
-        ? inputPropVal.asType('Single').value.toJSON()
-        : inputPropVal.asType('Vector').value.toJSON()
-
-      if (inputPropVal.isOfType('Single')) {
-        if (inputPropVal.asType('Single').isOfType('Reference')) {
-          reference = { entityId: value as number, existing: true }
-        }
-      }
-    } else if (v.isOfType('InternalEntityJustAdded')) {
-      value = v.asType('InternalEntityJustAdded').toJSON()
-      reference = { entityId: value as number, existing: false }
-    } else {
-      // TODO: Add support for v.asType('InternalEntityVec')
-      throw Error('InternalEntityVec property type is not supported yet!')
-    }
-    properties.push({ id: `${propertyId}`, value, reference })
-  })
-  return properties
-}
-
-function getOperations(event: SubstrateEvent): Vec<OperationType> {
-  if (!event.extrinsic) throw Error(`No extrinsic found for ${event.id}`)
-  return createType('Vec<OperationType>', (event.extrinsic.args[1].value as unknown) as Vec<OperationType>)
-}
-
-function getOperationsByTypes(operations: OperationType[]): IBatchOperation {
-  const updatePropertyValuesOperations: IEntity[] = []
-  const addSchemaSupportToEntityOperations: IEntity[] = []
-  const createEntityOperations: ICreateEntityOperation[] = []
-
-  for (const operation of operations) {
-    if (operation.isOfType('CreateEntity')) {
-      const cep = operation.asType('CreateEntity')
-      createEntityOperations.push({ classId: cep.class_id.toJSON() })
-    } else if (operation.isOfType('AddSchemaSupportToEntity')) {
-      const op = operation.asType('AddSchemaSupportToEntity')
-      const pe = createType('ParameterizedEntity', op.entity_id)
-      const entity: IEntity = {
-        properties: getEntityProperties(op.parametrized_property_values),
-      }
-      if (pe.isOfType('InternalEntityJustAdded')) {
-        entity.indexOf = pe.asType('InternalEntityJustAdded').toJSON()
-      } else {
-        entity.entityId = pe.asType('ExistingEntity').toJSON()
-      }
-      addSchemaSupportToEntityOperations.push(entity)
-    } else {
-      updatePropertyValuesOperations.push(makeEntity(operation.asType('UpdatePropertyValues')))
-    }
-  }
-  return {
-    updatePropertyValuesOperations,
-    addSchemaSupportToEntityOperations,
-    createEntityOperations,
-  }
-}
-
-function makeEntity(upv: UpdatePropertyValuesOperation): IEntity {
-  const entity: IEntity = {
-    properties: getEntityProperties(upv.new_parametrized_property_values),
-  }
-  const pe = createType('ParameterizedEntity', upv.entity_id)
-  if (pe.isOfType('InternalEntityJustAdded')) {
-    entity.indexOf = pe.asType('InternalEntityJustAdded').toJSON()
-  } else {
-    entity.entityId = pe.asType('ExistingEntity').toJSON()
-  }
-  return entity
-}
-
-export const decode = {
-  stringIfyEntityId,
-  getClassEntity,
-  setEntityPropertyValues,
-  getEntityProperties,
-  getOperationsByTypes,
-  setProperties,
-  getOperations,
-}

+ 0 - 302
query-node/mappings/content-directory/default-schemas.ts

@@ -1,302 +0,0 @@
-import Debug from 'debug'
-import { nanoid } from 'nanoid'
-
-import { DatabaseManager as DB } from '@dzlzv/hydra-db-utils'
-import { Channel } from '../../generated/graphql-server/src/modules/channel/channel.model'
-import { Language } from '../../generated/graphql-server/src/modules/language/language.model'
-import { ClassEntity } from '../../generated/graphql-server/src/modules/class-entity/class-entity.model'
-import { Video } from '../../generated/graphql-server/src/modules/video/video.model'
-import { Category } from '../../generated/graphql-server/src/modules/category/category.model'
-import { VideoMedia } from '../../generated/graphql-server/src/modules/video-media/video-media.model'
-import { LicenseEntity } from '../../generated/graphql-server/src/modules/license-entity/license-entity.model'
-import { VideoMediaEncoding } from '../../generated/graphql-server/src/modules/video-media-encoding/video-media-encoding.model'
-import { MediaLocationEntity } from '../../generated/graphql-server/src/modules/media-location-entity/media-location-entity.model'
-import { HttpMediaLocationEntity } from '../../generated/graphql-server/src/modules/http-media-location-entity/http-media-location-entity.model'
-import { JoystreamMediaLocationEntity } from '../../generated/graphql-server/src/modules/joystream-media-location-entity/joystream-media-location-entity.model'
-import { KnownLicenseEntity } from '../../generated/graphql-server/src/modules/known-license-entity/known-license-entity.model'
-import { UserDefinedLicenseEntity } from '../../generated/graphql-server/src/modules/user-defined-license-entity/user-defined-license-entity.model'
-import { FeaturedVideo } from '../../generated/graphql-server/src/modules/featured-video/featured-video.model'
-import { JoystreamMediaLocation } from '../../generated/graphql-server/src/modules/variants/variants.model'
-
-import { contentDirectoryClassNamesWithId, ContentDirectoryKnownClasses } from './content-dir-consts'
-
-const debug = Debug('mappings:default-schema')
-
-/**
- * Inserts a default schema for every newly created entity
- * @param db DB
- * @param ce ClassEntity
- */
-export async function createDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const knownClass = contentDirectoryClassNamesWithId.find((k) => k.classId === ce.classId)
-  // Its not a known class for query node so we simply return
-  if (!knownClass) {
-    debug(`Not a known class. ClassId: ${ce.classId} EntityId: ${ce.id}`)
-    return
-  }
-
-  switch (knownClass.name) {
-    case ContentDirectoryKnownClasses.CHANNEL:
-      await channelDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.CATEGORY:
-      await categoryDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.HTTPMEDIALOCATION:
-      await httpMediaLocationDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.JOYSTREAMMEDIALOCATION:
-      await joystreamMediaLocationDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.KNOWNLICENSE:
-      await knownLicenseDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.LANGUAGE:
-      await languageDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.LICENSE:
-      await licenseDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.MEDIALOCATION:
-      await mediaLocationDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.USERDEFINEDLICENSE:
-      await userDefinedLicenseDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.VIDEOMEDIAENCODING:
-      await videoMediaEncodingDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.FEATUREDVIDEOS:
-      await featuredVideoDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.VIDEO:
-      await videoDefaultSchema(db, ce)
-      break
-    case ContentDirectoryKnownClasses.VIDEOMEDIA:
-      await videoMediaDefaultSchema(db, ce)
-      break
-
-    default:
-      break
-  }
-}
-
-function commonProperties(ce: ClassEntity) {
-  return { id: ce.id, happenedIn: ce.happenedIn, version: ce.happenedIn.block }
-}
-
-export async function categoryDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  await db.save<Category>(
-    new Category({
-      ...commonProperties(ce),
-      name: ce.id,
-    })
-  )
-}
-
-export async function channelDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const defaultSchemaFromDb = await db.get(Channel, { where: { id: '0' } })
-  if (!defaultSchemaFromDb) throw Error(`Channel(0) not found`)
-
-  const c = new Channel({
-    ...commonProperties(ce),
-    handle: `${ce.id} - ${nanoid()}`,
-    description: `${ce.id}`,
-    isPublic: defaultSchemaFromDb.isPublic,
-    isCurated: defaultSchemaFromDb.isCurated,
-  })
-  await db.save<Channel>(c)
-}
-
-export async function httpMediaLocationDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const defaultSchemaFromDb = await db.get(HttpMediaLocationEntity, { where: { id: '0' } })
-  if (!defaultSchemaFromDb) throw Error(`HttpMediaLocationEntity(0) not found`)
-
-  await db.save<HttpMediaLocationEntity>(
-    new HttpMediaLocationEntity({
-      ...commonProperties(ce),
-      url: defaultSchemaFromDb.url,
-    })
-  )
-}
-
-export async function joystreamMediaLocationDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const defaultSchemaFromDb = await db.get(JoystreamMediaLocationEntity, { where: { id: '0' } })
-  if (!defaultSchemaFromDb) throw Error(`JoystreamMediaLocationEntity(0) not found`)
-
-  await db.save<JoystreamMediaLocationEntity>(
-    new JoystreamMediaLocationEntity({
-      ...commonProperties(ce),
-      dataObjectId: defaultSchemaFromDb.dataObjectId,
-    })
-  )
-}
-
-export async function knownLicenseDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const defaultSchemaFromDb = await db.get(KnownLicenseEntity, { where: { id: '0' } })
-  if (!defaultSchemaFromDb) throw Error(`KnownLicenseEntity(0) not found`)
-
-  await db.save<KnownLicenseEntity>(
-    new KnownLicenseEntity({
-      ...commonProperties(ce),
-      code: `${ce.id}-${defaultSchemaFromDb.code}`,
-      name: defaultSchemaFromDb.name,
-    })
-  )
-}
-
-export async function userDefinedLicenseDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  await db.save<UserDefinedLicenseEntity>(
-    new UserDefinedLicenseEntity({
-      ...commonProperties(ce),
-      content: `${ce.id}`,
-    })
-  )
-}
-
-export async function languageDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  await db.save<Language>(
-    new Language({
-      ...commonProperties(ce),
-      code: `${ce.id}`,
-      name: `${ce.id}`,
-    })
-  )
-}
-
-export async function licenseDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const defaultSchemaFromDb = await db.get(LicenseEntity, { where: { id: '0' } })
-  if (!defaultSchemaFromDb) throw Error(`LicenseEntity(0) not found`)
-
-  await db.save<LicenseEntity>(
-    new LicenseEntity({
-      ...commonProperties(ce),
-      type: defaultSchemaFromDb.type,
-    })
-  )
-}
-
-export async function mediaLocationDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const defaultSchemaFromDb = await db.get(MediaLocationEntity, {
-    where: { id: '0' },
-    relations: ['joystreamMediaLocation'],
-  })
-  if (!defaultSchemaFromDb) throw Error(`MediaLocationEntity(0) not found`)
-
-  const m = new MediaLocationEntity()
-  m.joystreamMediaLocation = defaultSchemaFromDb.joystreamMediaLocation
-  await db.save<MediaLocationEntity>(
-    new MediaLocationEntity({
-      ...commonProperties(ce),
-      joystreamMediaLocation: defaultSchemaFromDb.joystreamMediaLocation,
-    })
-  )
-}
-
-export async function videoMediaEncodingDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const defaultSchemaFromDb = await db.get(VideoMediaEncoding, { where: { id: '0' } })
-  if (!defaultSchemaFromDb) throw Error(`VideoMediaEncoding(0) not found`)
-
-  await db.save<VideoMediaEncoding>(
-    new VideoMediaEncoding({
-      ...commonProperties(ce),
-      name: defaultSchemaFromDb.name,
-    })
-  )
-}
-
-export async function featuredVideoDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const video = await db.get(Video, { where: { id: '0' } })
-  if (!video) throw Error(`Video(0) not found for FeaturedVideo(${ce.id}) creation`)
-
-  await db.save<FeaturedVideo>(
-    new FeaturedVideo({
-      ...commonProperties(ce),
-      video,
-    })
-  )
-}
-
-export async function videoDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const defaultSchemaFromDb = await db.get(Video, { where: { id: '0' } })
-  if (!defaultSchemaFromDb) throw Error(`Video(0) not found`)
-
-  const v = new Video({
-    ...commonProperties(ce),
-  })
-
-  // ///// default relations ///////
-  /* eslint-disable @typescript-eslint/no-non-null-assertion */
-  const filmAnimation = await db.get(Category, { where: { name: 'Film & Animation' } })
-  v.category = filmAnimation || (await db.get(Category, { where: { id: '0' } }))!
-  v.channel = (await db.get(Channel, { where: { id: '0' } }))!
-  v.license = (await db.get(LicenseEntity, { where: { id: '0' } }))!
-
-  // const media = (await db.get(VideoMedia, { where: { id: '0' } }))!
-
-  // const encoding = new VideoMediaEncoding({
-  //   name: `${Date.now()}`,
-  //   ...commonProperties(ce),
-  //   id: `${Date.now()}`,
-  // })
-  // await db.save<VideoMediaEncoding>(encoding)
-  const encoding = await db.get(VideoMediaEncoding, { where: { id: 0 } })
-
-  const mediaLoc = await db.get(MediaLocationEntity, { where: { id: '0' }, relations: ['joystreamMediaLocation'] })
-  if (!mediaLoc) throw Error(`MediaLocationEntity(0) not found while creating default schema for video`)
-  const location = new JoystreamMediaLocation()
-  location.dataObjectId = mediaLoc.joystreamMediaLocation!.dataObjectId
-
-  const media = await db.get(VideoMedia, { where: { id: '0' } })
-  if (!media) throw Error(`VideoMedia(0) not found while creating default schema for video`)
-
-  const newMedia = new VideoMedia({
-    ...commonProperties(ce),
-    location,
-    encoding,
-    id: `${Date.now()}`, // override id
-    pixelHeight: media.pixelHeight,
-    pixelWidth: media.pixelWidth,
-  })
-  await db.save<VideoMedia>(newMedia)
-
-  v.media = newMedia
-  // ///// default relations ///////
-
-  // Get default schema for video entity
-  // const defaultSchemaFromDb = (await db.get(Video, { where: { id: '0' } }))!
-  /* eslint-enable @typescript-eslint/no-non-null-assertion */
-
-  v.title = ce.id
-  v.description = ce.id
-  v.duration = defaultSchemaFromDb.duration
-  v.thumbnailUrl = defaultSchemaFromDb.thumbnailUrl
-  v.isPublic = defaultSchemaFromDb.isPublic
-  v.isCurated = defaultSchemaFromDb.isCurated
-  v.isExplicit = defaultSchemaFromDb.isExplicit
-  v.isFeatured = defaultSchemaFromDb.isFeatured
-
-  await db.save<Video>(v)
-}
-
-export async function videoMediaDefaultSchema(db: DB, ce: ClassEntity): Promise<void> {
-  const media = await db.get(VideoMedia, { where: { id: '0' } })
-  if (!media) throw Error(`VideoMedia(0) not found`)
-
-  const encoding = await db.get(VideoMediaEncoding, { where: { id: '0' } })
-
-  const mediaLoc = await db.get(MediaLocationEntity, { where: { id: '0' }, relations: ['joystreamMediaLocation'] })
-  if (!mediaLoc) throw Error(`MediaLocationEntity(0) not found while creating default schema for video`)
-  const location = new JoystreamMediaLocation()
-  location.dataObjectId = mediaLoc.joystreamMediaLocation!.dataObjectId
-
-  const vm = new VideoMedia({
-    ...commonProperties(ce),
-    pixelHeight: media.pixelHeight,
-    pixelWidth: media.pixelWidth,
-    encoding,
-    location,
-  })
-
-  await db.save<VideoMedia>(vm)
-}

+ 0 - 299
query-node/mappings/content-directory/entity/addSchema.ts

@@ -1,299 +0,0 @@
-import { DatabaseManager as DB } from '@dzlzv/hydra-db-utils'
-import { Channel } from '../../../generated/graphql-server/src/modules/channel/channel.model'
-import { Category } from '../../../generated/graphql-server/src/modules/category/category.model'
-import { KnownLicenseEntity } from '../../../generated/graphql-server/src/modules/known-license-entity/known-license-entity.model'
-import { UserDefinedLicenseEntity } from '../../../generated/graphql-server/src/modules/user-defined-license-entity/user-defined-license-entity.model'
-import { JoystreamMediaLocationEntity } from '../../../generated/graphql-server/src/modules/joystream-media-location-entity/joystream-media-location-entity.model'
-import { HttpMediaLocationEntity } from '../../../generated/graphql-server/src/modules/http-media-location-entity/http-media-location-entity.model'
-import { VideoMedia } from '../../../generated/graphql-server/src/modules/video-media/video-media.model'
-import { Video } from '../../../generated/graphql-server/src/modules/video/video.model'
-import { Language } from '../../../generated/graphql-server/src/modules/language/language.model'
-import { VideoMediaEncoding } from '../../../generated/graphql-server/src/modules/video-media-encoding/video-media-encoding.model'
-import { LicenseEntity } from '../../../generated/graphql-server/src/modules/license-entity/license-entity.model'
-import { MediaLocationEntity } from '../../../generated/graphql-server/src/modules/media-location-entity/media-location-entity.model'
-import { FeaturedVideo } from '../../../generated/graphql-server/src/modules/featured-video/featured-video.model'
-
-import {
-  ICategory,
-  IChannel,
-  IFeaturedVideo,
-  IHttpMediaLocation,
-  IJoystreamMediaLocation,
-  IKnownLicense,
-  ILanguage,
-  ILicense,
-  IMediaLocation,
-  IReference,
-  IUserDefinedLicense,
-  IVideo,
-  IVideoMedia,
-  IVideoMediaEncoding,
-} from '../../types'
-import {
-  HttpMediaLocation,
-  JoystreamMediaLocation,
-  KnownLicense,
-  UserDefinedLicense,
-} from '../../../generated/graphql-server/src/modules/variants/variants.model'
-
-type SchemaSupport<T> = { db: DB; entityId: number; props: T; nextEntityId: number }
-
-function getEntityIdFromRef(ref: IReference, nextEntityId: number) {
-  const { entityId, existing } = ref
-  return (existing ? entityId : entityId + nextEntityId).toString()
-}
-
-export async function addSchemaToChannel(param: SchemaSupport<IChannel>): Promise<void> {
-  const { entityId, nextEntityId, props, db } = param
-  const c = await db.get(Channel, { where: { id: entityId.toString() } })
-  if (!c) throw Error(`Channel(${entityId}) has never been created!`)
-
-  c.handle = props.handle || c.handle
-  c.description = props.description || c.description
-  c.isCurated = !!props.isCurated
-  c.isPublic = props.isPublic || c.isPublic
-  c.coverPhotoUrl = props.coverPhotoUrl || c.coverPhotoUrl
-  c.avatarPhotoUrl = props.avatarPhotoUrl || c.avatarPhotoUrl
-
-  const { language } = props
-  if (language) {
-    c.language = await db.get(Language, { where: { id: getEntityIdFromRef(language, nextEntityId) } })
-  }
-  await db.save<Channel>(c)
-}
-
-export async function addSchemaToCategory(param: SchemaSupport<ICategory>): Promise<void> {
-  const { entityId, props, db } = param
-  const c = await db.get(Category, { where: { id: entityId.toString() } })
-  if (!c) throw Error(`Category(${entityId}) has never been created!`)
-
-  c.name = props.name || c.name
-  c.description = props.description || c.description
-  await db.save<Category>(c)
-}
-
-export async function addSchemaToHttpMediaLocation(param: SchemaSupport<IHttpMediaLocation>): Promise<void> {
-  const { entityId, props, db } = param
-  const c = await db.get(HttpMediaLocationEntity, { where: { id: entityId.toString() } })
-  if (!c) throw Error(`HttpMediaLocationEntity(${entityId}) has never been created!`)
-
-  c.url = props.url || c.url
-  c.port = props.port || c.port
-
-  await db.save<HttpMediaLocationEntity>(c)
-}
-
-export async function addSchemaToJoystreamMediaLocation(param: SchemaSupport<IJoystreamMediaLocation>): Promise<void> {
-  const { entityId, props, db } = param
-  const j = await db.get(JoystreamMediaLocationEntity, { where: { id: entityId.toString() } })
-  if (!j) throw Error(`JoystreamMediaLocationEntity(${entityId}) has never been created!`)
-
-  j.dataObjectId = props.dataObjectId || j.dataObjectId
-  await db.save<JoystreamMediaLocationEntity>(j)
-}
-
-export async function addSchemaToKnownLicense(param: SchemaSupport<IKnownLicense>): Promise<void> {
-  const { entityId, props, db } = param
-  const k = await db.get(KnownLicenseEntity, { where: { id: entityId.toString() } })
-  if (!k) throw Error(`KnownLicenseEntity(${entityId}) has never been created!`)
-
-  k.code = props.code || k.code
-  k.description = props.description || k.description
-  k.name = props.name || k.name
-  k.url = props.url || k.url
-
-  await db.save<KnownLicenseEntity>(k)
-}
-
-export async function addSchemaToLanguage(param: SchemaSupport<ILanguage>): Promise<void> {
-  const { entityId, props, db } = param
-  const l = await db.get(Language, { where: { id: entityId.toString() } })
-  if (!l) throw Error(`Language(${entityId}) has never been created!`)
-
-  l.code = props.code || l.code
-  l.name = props.name || l.name
-
-  await db.save<Language>(l)
-}
-
-export async function addSchemaToLicense(param: SchemaSupport<ILicense>): Promise<void> {
-  const { entityId, props, db, nextEntityId } = param
-  const l = await db.get(LicenseEntity, { where: { id: entityId.toString() } })
-  if (!l) throw Error(`LicenseEntity(${entityId}) has never been created!`)
-
-  const { knownLicense, userDefinedLicense } = props
-
-  let licenseEntityId
-
-  if (knownLicense) {
-    licenseEntityId = getEntityIdFromRef(knownLicense, nextEntityId)
-    const k = await db.get(KnownLicenseEntity, { where: { id: licenseEntityId } })
-    if (!k) throw Error(`KnownLicenseEntity(${licenseEntityId}) not found`)
-
-    const licenseType = new KnownLicense()
-    licenseType.code = k.code
-    licenseType.description = k.description
-    licenseType.name = k.name
-    licenseType.url = k.url
-    l.type = licenseType
-  }
-
-  if (userDefinedLicense) {
-    licenseEntityId = getEntityIdFromRef(userDefinedLicense, nextEntityId)
-    const u = await db.get(UserDefinedLicenseEntity, {
-      where: { id: licenseEntityId },
-    })
-    if (!u) throw Error(`UserDefinedLicenseEntity(${licenseEntityId}) not found`)
-    const licenseType = new UserDefinedLicense()
-    licenseType.content = u.content
-    l.type = licenseType
-  }
-
-  l.attribution = props.attribution || l.attribution
-  await db.save<LicenseEntity>(l)
-}
-
-export async function addSchemaToMediaLocation(param: SchemaSupport<IMediaLocation>): Promise<void> {
-  const { entityId, props, db, nextEntityId } = param
-  const m = await db.get(MediaLocationEntity, { where: { id: entityId.toString() } })
-  if (!m) throw Error(`MediaLocationEntity(${entityId}) has never been created!`)
-
-  const { httpMediaLocation, joystreamMediaLocation } = props
-
-  if (httpMediaLocation) {
-    m.httpMediaLocation =
-      (await db.get(HttpMediaLocationEntity, {
-        where: { id: getEntityIdFromRef(httpMediaLocation, nextEntityId) },
-      })) || m.httpMediaLocation
-  }
-  if (joystreamMediaLocation) {
-    m.joystreamMediaLocation =
-      (await db.get(JoystreamMediaLocationEntity, {
-        where: { id: getEntityIdFromRef(joystreamMediaLocation, nextEntityId) },
-      })) || m.joystreamMediaLocation
-  }
-  await db.save<MediaLocationEntity>(m)
-}
-
-export async function addSchemaToUserDefinedLicense(param: SchemaSupport<IUserDefinedLicense>): Promise<void> {
-  const { entityId, props, db } = param
-  const u = await db.get(UserDefinedLicenseEntity, { where: { id: entityId.toString() } })
-  if (!u) throw Error(`UserDefinedLicenseEntity(${entityId}) has never been created!`)
-
-  u.content = props.content || u.content
-  await db.save<UserDefinedLicenseEntity>(u)
-}
-
-export async function addSchemaToVideoMedia(param: SchemaSupport<IVideoMedia>): Promise<void> {
-  const { entityId, props, db, nextEntityId } = param
-  const v = await db.get(VideoMedia, { where: { id: entityId.toString() } })
-  if (!v) throw Error(`VideoMedia(${entityId}) has never been created!`)
-
-  v.pixelHeight = props.pixelHeight || v.pixelHeight
-  v.pixelWidth = props.pixelWidth || v.pixelWidth
-  v.size = props.size || v.size
-
-  const { location, encoding } = props
-
-  if (encoding) {
-    const encodingId = getEntityIdFromRef(encoding, nextEntityId)
-    const encod = await db.get(VideoMediaEncoding, { where: { id: encodingId } })
-    if (!encod) throw Error(`VideoMediaEncoding(${encodingId}) has never been created!`)
-    v.encoding = encod
-  }
-
-  if (location) {
-    const mediaLocation = await db.get(MediaLocationEntity, {
-      where: { id: getEntityIdFromRef(location, nextEntityId) },
-      relations: ['httpMediaLocation', 'joystreamMediaLocation'],
-    })
-    v.locationEntity = mediaLocation
-
-    if (mediaLocation) {
-      const { httpMediaLocation, joystreamMediaLocation } = mediaLocation
-      if (httpMediaLocation) {
-        const mediaLoc = new HttpMediaLocation()
-        mediaLoc.port = httpMediaLocation.port
-        mediaLoc.url = httpMediaLocation.url
-        v.location = mediaLoc
-      }
-      if (joystreamMediaLocation) {
-        const mediaLoc = new JoystreamMediaLocation()
-        mediaLoc.dataObjectId = joystreamMediaLocation.dataObjectId
-        v.location = mediaLoc
-      }
-    }
-  }
-  await db.save<VideoMedia>(v)
-}
-
-export async function addSchemaToVideoMediaEncoding(param: SchemaSupport<IVideoMediaEncoding>): Promise<void> {
-  const { entityId, props, db } = param
-  const e = await db.get(VideoMediaEncoding, { where: { id: entityId.toString() } })
-  if (!e) throw Error(`VideoMediaEncoding(${entityId}) has never been created!`)
-
-  e.name = props.name || e.name
-  await db.save<VideoMediaEncoding>(e)
-}
-
-export async function addSchemaToFeaturedVideo(param: SchemaSupport<IFeaturedVideo>): Promise<void> {
-  const { entityId, props, db, nextEntityId } = param
-  const f = await db.get(FeaturedVideo, { where: { id: entityId.toString() } })
-  if (!f) throw Error(`FeaturedVideo(${entityId}) has never been created!`)
-
-  if (props.video) {
-    const videoId = getEntityIdFromRef(props.video, nextEntityId)
-    const v = await db.get(Video, { where: { id: videoId } })
-    if (!v) throw Error(`Video(${videoId}) has never been created!`)
-    f.video = v
-  }
-  await db.save<FeaturedVideo>(f)
-}
-
-export async function addSchemaToVideo(param: SchemaSupport<IVideo>): Promise<void> {
-  const { entityId, nextEntityId, props, db } = param
-
-  const v = await db.get(Video, { where: { id: entityId.toString() } })
-  if (!v) throw Error(`Video(${entityId}) has never been created!`)
-
-  v.title = props.title || v.title
-  v.description = props.description || v.description
-  v.duration = props.duration || v.duration
-  v.hasMarketing = props.hasMarketing || v.hasMarketing
-  v.isCurated = !!props.isCurated
-  v.isExplicit = props.isExplicit || v.isExplicit
-  v.isPublic = props.isPublic || v.isPublic
-  v.publishedBeforeJoystream = props.publishedBeforeJoystream || v.publishedBeforeJoystream
-  v.skippableIntroDuration = props.skippableIntroDuration || v.skippableIntroDuration
-  v.thumbnailUrl = props.thumbnailUrl || v.thumbnailUrl
-  v.isFeatured = !!v.isFeatured
-
-  const { language, license, category, channel, media } = props
-
-  if (language) {
-    v.language = await db.get(Language, { where: { id: getEntityIdFromRef(language, nextEntityId) } })
-  }
-  if (license) {
-    const licenseId = getEntityIdFromRef(license, nextEntityId)
-    const l = await db.get(LicenseEntity, { where: { id: licenseId } })
-    if (!l) throw Error(`LicenseEntity(${licenseId}) has never been created!`)
-    v.license = l
-  }
-  if (category) {
-    const categoryId = getEntityIdFromRef(category, nextEntityId)
-    const c = await db.get(Category, { where: { id: categoryId } })
-    if (!c) throw Error(`Category(${categoryId}) has never been created!`)
-    v.category = c
-  }
-  if (channel) {
-    const channelId = getEntityIdFromRef(channel, nextEntityId)
-    const c = await db.get(Channel, { where: { id: channelId } })
-    if (!c) throw Error(`Channel(${channelId}) has never been created!`)
-    v.channel = c
-  }
-  if (media) {
-    v.media = await db.get(VideoMedia, { where: { id: getEntityIdFromRef(media, nextEntityId) } })
-  }
-  /* eslint-enable @typescript-eslint/no-non-null-assertion */
-  await db.save<Video>(v)
-}

+ 0 - 456
query-node/mappings/content-directory/entity/create.ts

@@ -1,456 +0,0 @@
-import { DatabaseManager as DB } from '@dzlzv/hydra-db-utils'
-import { Channel } from '../../../generated/graphql-server/src/modules/channel/channel.model'
-import { Category } from '../../../generated/graphql-server/src/modules/category/category.model'
-import { KnownLicenseEntity } from '../../../generated/graphql-server/src/modules/known-license-entity/known-license-entity.model'
-import { UserDefinedLicenseEntity } from '../../../generated/graphql-server/src/modules/user-defined-license-entity/user-defined-license-entity.model'
-import { JoystreamMediaLocationEntity } from '../../../generated/graphql-server/src/modules/joystream-media-location-entity/joystream-media-location-entity.model'
-import { HttpMediaLocationEntity } from '../../../generated/graphql-server/src/modules/http-media-location-entity/http-media-location-entity.model'
-import { VideoMedia } from '../../../generated/graphql-server/src/modules/video-media/video-media.model'
-import { Video } from '../../../generated/graphql-server/src/modules/video/video.model'
-import { Block, Network } from '../../../generated/graphql-server/src/modules/block/block.model'
-import { Language } from '../../../generated/graphql-server/src/modules/language/language.model'
-import { VideoMediaEncoding } from '../../../generated/graphql-server/src/modules/video-media-encoding/video-media-encoding.model'
-import { ClassEntity } from '../../../generated/graphql-server/src/modules/class-entity/class-entity.model'
-import { LicenseEntity } from '../../../generated/graphql-server/src/modules/license-entity/license-entity.model'
-import { MediaLocationEntity } from '../../../generated/graphql-server/src/modules/media-location-entity/media-location-entity.model'
-import { FeaturedVideo } from '../../../generated/graphql-server/src/modules/featured-video/featured-video.model'
-
-import { contentDirectoryClassNamesWithId } from '../content-dir-consts'
-import {
-  ClassEntityMap,
-  ICategory,
-  IChannel,
-  ICreateEntityOperation,
-  IDBBlockId,
-  IEntity,
-  IFeaturedVideo,
-  IHttpMediaLocation,
-  IJoystreamMediaLocation,
-  IKnownLicense,
-  ILanguage,
-  ILicense,
-  IMediaLocation,
-  IUserDefinedLicense,
-  IVideo,
-  IVideoMedia,
-  IVideoMediaEncoding,
-} from '../../types'
-import { getOrCreate } from '../get-or-create'
-import BN from 'bn.js'
-import {
-  HttpMediaLocation,
-  JoystreamMediaLocation,
-  KnownLicense,
-  UserDefinedLicense,
-} from '../../../generated/graphql-server/src/modules/variants/variants.model'
-
-async function createBlockOrGetFromDatabase(db: DB, blockNumber: number): Promise<Block> {
-  let b = await db.get(Block, { where: { block: blockNumber } })
-  if (b === undefined) {
-    // TODO: get timestamp from the event or extrinsic
-    b = new Block({ block: blockNumber, network: Network.BABYLON, timestamp: new BN(Date.now()) })
-    await db.save<Block>(b)
-  }
-  return b
-}
-
-async function createChannel(
-  { db, block, id }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  p: IChannel,
-  nextEntityIdBeforeTransaction: number
-): Promise<Channel> {
-  const record = await db.get(Channel, { where: { id } })
-  if (record) return record
-
-  const channel = new Channel()
-
-  channel.version = block
-  channel.id = id
-  channel.handle = p.handle
-  channel.description = p.description
-  channel.isCurated = !!p.isCurated
-  channel.isPublic = p.isPublic
-  channel.coverPhotoUrl = p.coverPhotoUrl
-  channel.avatarPhotoUrl = p.avatarPhotoUrl
-
-  channel.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  const { language } = p
-  if (language) {
-    channel.language = await getOrCreate.language(
-      { db, block, id },
-      classEntityMap,
-      language,
-      nextEntityIdBeforeTransaction
-    )
-  }
-  await db.save(channel)
-  return channel
-}
-
-async function createCategory({ db, block, id }: IDBBlockId, p: ICategory): Promise<Category> {
-  const record = await db.get(Category, { where: { id } })
-  if (record) return record
-
-  const category = new Category()
-
-  category.id = id
-  category.name = p.name
-  category.description = p.description
-  category.version = block
-  category.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  await db.save(category)
-  return category
-}
-
-async function createKnownLicense({ db, block, id }: IDBBlockId, p: IKnownLicense): Promise<KnownLicenseEntity> {
-  const record = await db.get(KnownLicenseEntity, { where: { id } })
-  if (record) return record
-
-  const knownLicence = new KnownLicenseEntity()
-
-  knownLicence.id = id
-  knownLicence.code = p.code
-  knownLicence.name = p.name
-  knownLicence.description = p.description
-  knownLicence.url = p.url
-  knownLicence.version = block
-  knownLicence.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  await db.save(knownLicence)
-  return knownLicence
-}
-
-async function createUserDefinedLicense(
-  { db, block, id }: IDBBlockId,
-  p: IUserDefinedLicense
-): Promise<UserDefinedLicenseEntity> {
-  const record = await db.get(UserDefinedLicenseEntity, { where: { id } })
-  if (record) return record
-
-  const userDefinedLicense = new UserDefinedLicenseEntity()
-
-  userDefinedLicense.id = id
-  userDefinedLicense.content = p.content
-  userDefinedLicense.version = block
-  userDefinedLicense.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  await db.save<UserDefinedLicenseEntity>(userDefinedLicense)
-  return userDefinedLicense
-}
-
-async function createJoystreamMediaLocation(
-  { db, block, id }: IDBBlockId,
-  p: IJoystreamMediaLocation
-): Promise<JoystreamMediaLocationEntity> {
-  const record = await db.get(JoystreamMediaLocationEntity, { where: { id } })
-  if (record) return record
-
-  const joyMediaLoc = new JoystreamMediaLocationEntity()
-
-  joyMediaLoc.id = id
-  joyMediaLoc.dataObjectId = p.dataObjectId
-  joyMediaLoc.version = block
-  joyMediaLoc.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  await db.save(joyMediaLoc)
-  return joyMediaLoc
-}
-
-async function createHttpMediaLocation(
-  { db, block, id }: IDBBlockId,
-  p: IHttpMediaLocation
-): Promise<HttpMediaLocationEntity> {
-  const record = await db.get(HttpMediaLocationEntity, { where: { id } })
-  if (record) return record
-
-  const httpMediaLoc = new HttpMediaLocationEntity()
-
-  httpMediaLoc.id = id
-  httpMediaLoc.url = p.url
-  httpMediaLoc.port = p.port
-  httpMediaLoc.version = block
-  httpMediaLoc.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  await db.save(httpMediaLoc)
-  return httpMediaLoc
-}
-
-async function createVideoMedia(
-  { db, block, id }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  p: IVideoMedia,
-  nextEntityIdBeforeTransaction: number
-): Promise<VideoMedia> {
-  const videoMedia = new VideoMedia()
-
-  videoMedia.id = id
-  videoMedia.pixelHeight = p.pixelHeight
-  videoMedia.pixelWidth = p.pixelWidth
-  videoMedia.size = p.size
-  videoMedia.version = block
-  const { encoding, location } = p
-  if (encoding !== undefined) {
-    videoMedia.encoding = await getOrCreate.videoMediaEncoding(
-      { db, block, id },
-      classEntityMap,
-      encoding,
-      nextEntityIdBeforeTransaction
-    )
-  }
-  if (location !== undefined) {
-    const m = await getOrCreate.mediaLocation(
-      { db, block, id },
-      classEntityMap,
-      location,
-      nextEntityIdBeforeTransaction
-    )
-    videoMedia.locationEntity = m
-    const { httpMediaLocation, joystreamMediaLocation } = m
-    if (httpMediaLocation) {
-      const mediaLoc = new HttpMediaLocation()
-      mediaLoc.port = httpMediaLocation.port
-      mediaLoc.url = httpMediaLocation.url
-      videoMedia.location = mediaLoc
-    }
-    if (joystreamMediaLocation) {
-      const mediaLoc = new JoystreamMediaLocation()
-      mediaLoc.dataObjectId = joystreamMediaLocation.dataObjectId
-      videoMedia.location = mediaLoc
-    }
-  }
-
-  videoMedia.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  await db.save<VideoMedia>(videoMedia)
-  return videoMedia
-}
-
-async function createVideo(
-  { db, block, id }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  p: IVideo,
-  nextEntityIdBeforeTransaction: number
-): Promise<Video> {
-  const record = await db.get(Video, { where: { id } })
-  if (record) return record
-
-  const video = new Video()
-
-  video.id = id
-  video.title = p.title
-  video.description = p.description
-  video.duration = p.duration
-  video.hasMarketing = p.hasMarketing
-  video.isCurated = !!p.isCurated
-  video.isExplicit = p.isExplicit
-  video.isPublic = p.isPublic
-  video.publishedBeforeJoystream = p.publishedBeforeJoystream
-  video.skippableIntroDuration = p.skippableIntroDuration
-  video.thumbnailUrl = p.thumbnailUrl
-  video.version = block
-  video.isFeatured = false
-
-  const { language, license, category, channel, media } = p
-  if (language !== undefined) {
-    video.language = await getOrCreate.language(
-      { db, block, id },
-      classEntityMap,
-      language,
-      nextEntityIdBeforeTransaction
-    )
-  }
-  if (license) {
-    const lic = await getOrCreate.license({ db, block, id }, classEntityMap, license, nextEntityIdBeforeTransaction)
-    video.license = lic
-  }
-  if (category !== undefined) {
-    video.category = await getOrCreate.category(
-      { db, block, id },
-      classEntityMap,
-      category,
-      nextEntityIdBeforeTransaction
-    )
-  }
-  if (channel !== undefined) {
-    video.channel = await getOrCreate.channel({ db, block, id }, classEntityMap, channel, nextEntityIdBeforeTransaction)
-  }
-  if (media !== undefined) {
-    video.media = await getOrCreate.videoMedia({ db, block, id }, classEntityMap, media, nextEntityIdBeforeTransaction)
-  }
-
-  video.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  await db.save<Video>(video)
-  return video
-}
-
-async function createLanguage({ db, block, id }: IDBBlockId, p: ILanguage): Promise<Language> {
-  const record = await db.get(Language, { where: { id } })
-  if (record) return record
-
-  const language = new Language()
-  language.id = id
-  language.name = p.name
-  language.code = p.code
-  language.version = block
-  language.happenedIn = await createBlockOrGetFromDatabase(db, block)
-
-  await db.save<Language>(language)
-  return language
-}
-
-async function createVideoMediaEncoding(
-  { db, block, id }: IDBBlockId,
-  p: IVideoMediaEncoding
-): Promise<VideoMediaEncoding> {
-  const record = await db.get(VideoMediaEncoding, { where: { id } })
-  if (record) return record
-
-  const encoding = new VideoMediaEncoding()
-  encoding.id = id
-  encoding.name = p.name
-  encoding.version = block
-  encoding.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  await db.save<VideoMediaEncoding>(encoding)
-  return encoding
-}
-
-async function createLicense(
-  { db, block, id }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  p: ILicense,
-  nextEntityIdBeforeTransaction: number
-): Promise<LicenseEntity> {
-  const record = await db.get(LicenseEntity, { where: { id } })
-  if (record) return record
-
-  const license = new LicenseEntity()
-
-  if (p.knownLicense) {
-    const kLicense = await getOrCreate.knownLicense(
-      { db, block, id },
-      classEntityMap,
-      p.knownLicense,
-      nextEntityIdBeforeTransaction
-    )
-    const k = new KnownLicense()
-    k.code = kLicense.code
-    k.description = kLicense.description
-    k.name = kLicense.name
-    k.url = kLicense.url
-    // Set the license type
-    license.type = k
-  }
-  if (p.userDefinedLicense) {
-    const { content } = await getOrCreate.userDefinedLicense(
-      { db, block, id },
-      classEntityMap,
-      p.userDefinedLicense,
-      nextEntityIdBeforeTransaction
-    )
-    const u = new UserDefinedLicense()
-    u.content = content
-    // Set the license type
-    license.type = u
-  }
-
-  license.id = id
-  license.attribution = p.attribution
-  license.happenedIn = await createBlockOrGetFromDatabase(db, block)
-
-  await db.save<LicenseEntity>(license)
-  return license
-}
-
-async function createMediaLocation(
-  { db, block, id }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  p: IMediaLocation,
-  nextEntityIdBeforeTransaction: number
-): Promise<MediaLocationEntity> {
-  const { httpMediaLocation, joystreamMediaLocation } = p
-
-  const location = new MediaLocationEntity()
-  location.id = id
-  if (httpMediaLocation !== undefined) {
-    location.httpMediaLocation = await getOrCreate.httpMediaLocation(
-      { db, block, id },
-      classEntityMap,
-      httpMediaLocation,
-      nextEntityIdBeforeTransaction
-    )
-  }
-  if (joystreamMediaLocation !== undefined) {
-    location.joystreamMediaLocation = await getOrCreate.joystreamMediaLocation(
-      { db, block, id },
-      classEntityMap,
-      joystreamMediaLocation,
-      nextEntityIdBeforeTransaction
-    )
-  }
-  location.happenedIn = await createBlockOrGetFromDatabase(db, block)
-  await db.save<MediaLocationEntity>(location)
-  return location
-}
-
-async function createFeaturedVideo(
-  { db, block, id }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  p: IFeaturedVideo,
-  nextEntityIdBeforeTransaction: number
-): Promise<void> {
-  const featuredVideo = new FeaturedVideo()
-
-  featuredVideo.video = await getOrCreate.video(
-    { db, block, id },
-    classEntityMap,
-    p.video!,
-    nextEntityIdBeforeTransaction
-  )
-
-  featuredVideo.id = id
-  featuredVideo.version = block
-  featuredVideo.video.isFeatured = true
-
-  await db.save<Video>(featuredVideo.video)
-  await db.save<FeaturedVideo>(featuredVideo)
-}
-
-async function getClassName(
-  db: DB,
-  entity: IEntity,
-  createEntityOperations: ICreateEntityOperation[]
-): Promise<string | undefined> {
-  const { entityId, indexOf } = entity
-  if (entityId === undefined && indexOf === undefined) {
-    throw Error(`Can not determine class of the entity`)
-  }
-
-  let classId: number | undefined
-  // Is newly created entity in the same transaction
-  if (indexOf !== undefined) {
-    classId = createEntityOperations[indexOf].classId
-  } else {
-    const ce = await db.get(ClassEntity, { where: { id: entityId } })
-    if (ce === undefined) console.log(`Class not found for the entity: ${entityId}`)
-    classId = ce ? ce.classId : undefined
-  }
-
-  const c = contentDirectoryClassNamesWithId.find((c) => c.classId === classId)
-  // TODO: stop execution, class should be created before entity creation
-  if (c === undefined) console.log(`Not recognized class id: ${classId}`)
-  return c ? c.name : undefined
-}
-
-export {
-  createCategory,
-  createChannel,
-  createVideoMedia,
-  createVideo,
-  createUserDefinedLicense,
-  createKnownLicense,
-  createHttpMediaLocation,
-  createJoystreamMediaLocation,
-  createLanguage,
-  createVideoMediaEncoding,
-  createLicense,
-  createMediaLocation,
-  createBlockOrGetFromDatabase,
-  getClassName,
-  createFeaturedVideo,
-}

+ 0 - 339
query-node/mappings/content-directory/entity/index.ts

@@ -1,339 +0,0 @@
-import Debug from 'debug'
-import { SubstrateEvent } from '@dzlzv/hydra-common'
-import { DatabaseManager as DB } from '@dzlzv/hydra-db-utils'
-import { ClassEntity } from '../../../generated/graphql-server/src/modules/class-entity/class-entity.model'
-
-import { decode } from '../decode'
-import {
-  removeCategory,
-  removeChannel,
-  removeVideoMedia,
-  removeVideo,
-  removeUserDefinedLicense,
-  removeKnownLicense,
-  removeHttpMediaLocation,
-  removeJoystreamMediaLocation,
-  removeLanguage,
-  removeVideoMediaEncoding,
-  removeLicense,
-  removeMediaLocation,
-  removeFeaturedVideo,
-} from './remove'
-import { createBlockOrGetFromDatabase } from './create'
-import {
-  categoryPropertyNamesWithId,
-  channelPropertyNamesWithId,
-  httpMediaLocationPropertyNamesWithId,
-  joystreamMediaLocationPropertyNamesWithId,
-  knownLicensePropertyNamesWIthId,
-  languagePropertyNamesWIthId,
-  userDefinedLicensePropertyNamesWithId,
-  videoMediaEncodingPropertyNamesWithId,
-  videoPropertyNamesWithId,
-  ContentDirectoryKnownClasses,
-  featuredVideoPropertyNamesWithId,
-  licensePropertyNamesWithId,
-  mediaLocationPropertyNamesWithId,
-} from '../content-dir-consts'
-
-import {
-  IChannel,
-  ICategory,
-  IKnownLicense,
-  IUserDefinedLicense,
-  IJoystreamMediaLocation,
-  IHttpMediaLocation,
-  IVideoMedia,
-  IVideo,
-  ILanguage,
-  IVideoMediaEncoding,
-  IWhereCond,
-  ILicense,
-  IMediaLocation,
-  IFeaturedVideo,
-} from '../../types'
-import { getOrCreate, getKnownClass } from '../get-or-create'
-import { createDefaultSchema } from '../default-schemas'
-import {
-  addSchemaToCategory,
-  addSchemaToChannel,
-  addSchemaToFeaturedVideo,
-  addSchemaToHttpMediaLocation,
-  addSchemaToJoystreamMediaLocation,
-  addSchemaToKnownLicense,
-  addSchemaToLanguage,
-  addSchemaToLicense,
-  addSchemaToMediaLocation,
-  addSchemaToUserDefinedLicense,
-  addSchemaToVideo,
-  addSchemaToVideoMedia,
-  addSchemaToVideoMediaEncoding,
-} from './addSchema'
-import { NextEntityId } from '../../../generated/graphql-server/src/modules/next-entity-id/next-entity-id.model'
-
-const debug = Debug('mappings:content-directory')
-
-async function addSchemSupportToEntity(
-  event: SubstrateEvent,
-  className: string,
-  db: DB,
-  entityId: number,
-  nextEntityId = 0
-) {
-  switch (className) {
-    case ContentDirectoryKnownClasses.CHANNEL:
-      addSchemaToChannel({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<IChannel>(event, channelPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.CATEGORY:
-      await addSchemaToCategory({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<ICategory>(event, categoryPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.KNOWNLICENSE:
-      await addSchemaToKnownLicense({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<IKnownLicense>(event, knownLicensePropertyNamesWIthId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.USERDEFINEDLICENSE:
-      await addSchemaToUserDefinedLicense({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<IUserDefinedLicense>(event, userDefinedLicensePropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.JOYSTREAMMEDIALOCATION:
-      await addSchemaToJoystreamMediaLocation({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<IJoystreamMediaLocation>(event, joystreamMediaLocationPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.HTTPMEDIALOCATION:
-      await addSchemaToHttpMediaLocation({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<IHttpMediaLocation>(event, httpMediaLocationPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.VIDEOMEDIA:
-      await addSchemaToVideoMedia({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<IVideoMedia>(event, videoPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.VIDEO:
-      await addSchemaToVideo({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<IVideo>(event, videoPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.LANGUAGE:
-      await addSchemaToLanguage({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<ILanguage>(event, languagePropertyNamesWIthId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.VIDEOMEDIAENCODING:
-      await addSchemaToVideoMediaEncoding({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<IVideoMediaEncoding>(event, videoMediaEncodingPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.FEATUREDVIDEOS:
-      await addSchemaToFeaturedVideo({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<IFeaturedVideo>(event, featuredVideoPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.LICENSE:
-      await addSchemaToLicense({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<ILicense>(event, licensePropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.MEDIALOCATION:
-      await addSchemaToMediaLocation({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setProperties<IMediaLocation>(event, mediaLocationPropertyNamesWithId),
-      })
-      break
-
-    default:
-      debug(`Unknown class name: ${className}`)
-      break
-  }
-}
-
-// eslint-disable-next-line @typescript-eslint/naming-convention
-async function contentDirectory_EntitySchemaSupportAdded(db: DB, event: SubstrateEvent): Promise<void> {
-  if (event.extrinsic && event.extrinsic.method === 'transaction') return
-  debug(`EntitySchemaSupportAdded event: ${JSON.stringify(event)}`)
-
-  const { params } = event
-  const entityId = params[1].value as number
-
-  const [knownClass] = await getKnownClass(db, { where: { id: entityId.toString() } })
-  if (!knownClass) return
-
-  await addSchemSupportToEntity(event, knownClass.name, db, entityId)
-}
-
-// eslint-disable-next-line @typescript-eslint/naming-convention
-async function contentDirectory_EntityRemoved(db: DB, event: SubstrateEvent): Promise<void> {
-  debug(`EntityRemoved event: ${JSON.stringify(event)}`)
-
-  const entityId = decode.stringIfyEntityId(event)
-  const where: IWhereCond = { where: { id: entityId } }
-
-  const [knownClass, classEntity] = await getKnownClass(db, where)
-  if (!knownClass) return
-
-  switch (knownClass.name) {
-    case ContentDirectoryKnownClasses.CHANNEL:
-      await removeChannel(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.CATEGORY:
-      await removeCategory(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.KNOWNLICENSE:
-      await removeKnownLicense(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.USERDEFINEDLICENSE:
-      await removeUserDefinedLicense(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.JOYSTREAMMEDIALOCATION:
-      await removeJoystreamMediaLocation(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.HTTPMEDIALOCATION:
-      await removeHttpMediaLocation(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.VIDEOMEDIA:
-      await removeVideoMedia(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.VIDEO:
-      await removeVideo(db, where)
-      break
-    case ContentDirectoryKnownClasses.LANGUAGE:
-      await removeLanguage(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.VIDEOMEDIAENCODING:
-      await removeVideoMediaEncoding(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.LICENSE:
-      await removeLicense(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.MEDIALOCATION:
-      await removeMediaLocation(db, where)
-      break
-
-    case ContentDirectoryKnownClasses.FEATUREDVIDEOS:
-      await removeFeaturedVideo(db, where)
-      break
-
-    default:
-      throw new Error(`Unknown class name: ${knownClass.name}`)
-  }
-  await db.remove<ClassEntity>(classEntity)
-}
-
-// eslint-disable-next-line @typescript-eslint/naming-convention
-async function contentDirectory_EntityCreated(db: DB, event: SubstrateEvent): Promise<void> {
-  if (event.extrinsic && event.extrinsic.method === 'transaction') return
-  debug(`EntityCreated event: ${JSON.stringify(event)}`)
-
-  const c = decode.getClassEntity(event)
-  const classEntity = new ClassEntity()
-
-  classEntity.classId = c.classId
-  classEntity.id = c.entityId.toString()
-  classEntity.version = event.blockNumber
-  classEntity.happenedIn = await createBlockOrGetFromDatabase(db, event.blockNumber)
-  await db.save<ClassEntity>(classEntity)
-
-  const nextEntityIdFromDb = await getOrCreate.nextEntityId(db)
-  nextEntityIdFromDb.nextId = c.entityId + 1
-  await db.save<NextEntityId>(nextEntityIdFromDb)
-
-  await createDefaultSchema(db, classEntity)
-}
-
-// eslint-disable-next-line @typescript-eslint/naming-convention
-async function contentDirectory_EntityPropertyValuesUpdated(db: DB, event: SubstrateEvent): Promise<void> {
-  const { extrinsic } = event
-  if (extrinsic && extrinsic.method === 'transaction') return
-  if (extrinsic === undefined) throw Error(`Extrinsic data not found for event: ${event.id}`)
-
-  debug(`EntityPropertyValuesUpdated event: ${JSON.stringify(event)}`)
-
-  const { 2: newPropertyValues } = extrinsic.args
-  // const entityId = decode.stringIfyEntityId(event)
-  // const where: IWhereCond = { where: { id: entityId } }
-  const entityId = event.params[1].value as number
-
-  const [knownClass] = await getKnownClass(db, { where: { id: entityId.toString() } })
-  if (!knownClass) return
-
-  // TODO: change setProperties method signature to accecpt SubstrateExtrinsic, then remove the following
-  // line. The reason we push the same arg is beacuse of the setProperties method check the 3rd indices
-  // to get properties values
-  extrinsic.args.push(newPropertyValues)
-
-  await addSchemSupportToEntity(event, knownClass.name, db, entityId)
-}
-
-export {
-  contentDirectory_EntityCreated,
-  contentDirectory_EntityRemoved,
-  contentDirectory_EntitySchemaSupportAdded,
-  contentDirectory_EntityPropertyValuesUpdated,
-}

+ 0 - 140
query-node/mappings/content-directory/entity/remove.ts

@@ -1,140 +0,0 @@
-import assert from 'assert'
-import Debug from 'debug'
-
-import { DatabaseManager as DB } from '@dzlzv/hydra-db-utils'
-
-import { Channel } from '../../../generated/graphql-server/src/modules/channel/channel.model'
-import { Category } from '../../../generated/graphql-server/src/modules/category/category.model'
-import { KnownLicenseEntity } from '../../../generated/graphql-server/src/modules/known-license-entity/known-license-entity.model'
-import { UserDefinedLicenseEntity } from '../../../generated/graphql-server/src/modules/user-defined-license-entity/user-defined-license-entity.model'
-import { JoystreamMediaLocationEntity } from '../../../generated/graphql-server/src/modules/joystream-media-location-entity/joystream-media-location-entity.model'
-import { HttpMediaLocationEntity } from '../../../generated/graphql-server/src/modules/http-media-location-entity/http-media-location-entity.model'
-import { VideoMedia } from '../../../generated/graphql-server/src/modules/video-media/video-media.model'
-import { Video } from '../../../generated/graphql-server/src/modules/video/video.model'
-import { Language } from '../../../generated/graphql-server/src/modules/language/language.model'
-import { VideoMediaEncoding } from '../../../generated/graphql-server/src/modules/video-media-encoding/video-media-encoding.model'
-import { LicenseEntity } from '../../../generated/graphql-server/src/modules/license-entity/license-entity.model'
-import { MediaLocationEntity } from '../../../generated/graphql-server/src/modules/media-location-entity/media-location-entity.model'
-import { FeaturedVideo } from '../../../generated/graphql-server/src/modules/featured-video/featured-video.model'
-
-import { IWhereCond } from '../../types'
-
-const debug = Debug(`mappings:remove-entity`)
-
-function assertKeyViolation(entityName: string, entityId: string) {
-  assert(false, `Can not remove ${entityName}(${entityId})! There are references to this entity`)
-}
-
-function logEntityNotFound(className: string, where: IWhereCond) {
-  debug(`${className}(${where.where.id}) not found. This happen when schema support is not added for the entity.`)
-}
-
-async function removeChannel(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(Channel, where)
-  if (!record) return logEntityNotFound(`Channel`, where)
-  if (record.videos && record.videos.length) assertKeyViolation(`Channel`, record.id)
-  await db.remove<Channel>(record)
-}
-
-async function removeCategory(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(Category, where)
-  if (!record) return logEntityNotFound(`Category`, where)
-  if (record.videos && record.videos.length) assertKeyViolation(`Category`, record.id)
-  await db.remove<Category>(record)
-}
-async function removeVideoMedia(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(VideoMedia, where)
-  if (!record) return logEntityNotFound(`VideoMedia`, where)
-  if (record.video) assertKeyViolation(`VideoMedia`, record.id)
-  await db.remove<VideoMedia>(record)
-}
-
-async function removeVideo(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(Video, where)
-  if (!record) return logEntityNotFound(`Video`, where)
-  await db.remove<Video>(record)
-}
-
-async function removeLicense(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(LicenseEntity, where)
-  if (!record) return logEntityNotFound(`License`, where)
-  if (record.videolicense && record.videolicense.length) assertKeyViolation(`License`, record.id)
-  await db.remove<LicenseEntity>(record)
-}
-
-async function removeUserDefinedLicense(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(UserDefinedLicenseEntity, where)
-  if (!record) return logEntityNotFound(`UserDefinedLicense`, where)
-  await db.remove<UserDefinedLicenseEntity>(record)
-}
-
-async function removeKnownLicense(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(KnownLicenseEntity, where)
-  if (!record) return logEntityNotFound(`KnownLicense`, where)
-  await db.remove<KnownLicenseEntity>(record)
-}
-async function removeMediaLocation(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(MediaLocationEntity, where)
-  if (!record) return logEntityNotFound(`MediaLocation`, where)
-  if (record.videoMedia) assertKeyViolation('MediaLocation', record.id)
-  await db.remove<MediaLocationEntity>(record)
-}
-
-async function removeHttpMediaLocation(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(HttpMediaLocationEntity, where)
-  if (!record) return logEntityNotFound(`HttpMediaLocation`, where)
-  if (record.medialocationentityhttpMediaLocation && record.medialocationentityhttpMediaLocation.length) {
-    assertKeyViolation('HttpMediaLocation', record.id)
-  }
-  await db.remove<HttpMediaLocationEntity>(record)
-}
-
-async function removeJoystreamMediaLocation(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(JoystreamMediaLocationEntity, where)
-  if (!record) return logEntityNotFound(`JoystreamMediaLocation`, where)
-  if (record.medialocationentityjoystreamMediaLocation && record.medialocationentityjoystreamMediaLocation.length) {
-    assertKeyViolation('JoystreamMediaLocation', record.id)
-  }
-  await db.remove<JoystreamMediaLocationEntity>(record)
-}
-
-async function removeLanguage(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(Language, where)
-  if (!record) return logEntityNotFound(`Language`, where)
-  if (record.channellanguage && record.channellanguage.length) assertKeyViolation('Language', record.id)
-  if (record.videolanguage && record.videolanguage.length) assertKeyViolation('Language', record.id)
-  await db.remove<Language>(record)
-}
-
-async function removeVideoMediaEncoding(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(VideoMediaEncoding, where)
-  if (!record) return logEntityNotFound(`VideoMediaEncoding`, where)
-  await db.remove<VideoMediaEncoding>(record)
-}
-
-async function removeFeaturedVideo(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(FeaturedVideo, { ...where, relations: ['video'] })
-  if (!record) return logEntityNotFound(`FeaturedVideo`, where)
-
-  record.video.isFeatured = false
-  record.video.featured = undefined
-
-  await db.save<Video>(record.video)
-  await db.remove<FeaturedVideo>(record)
-}
-
-export {
-  removeCategory,
-  removeChannel,
-  removeVideoMedia,
-  removeVideo,
-  removeUserDefinedLicense,
-  removeKnownLicense,
-  removeHttpMediaLocation,
-  removeJoystreamMediaLocation,
-  removeLanguage,
-  removeVideoMediaEncoding,
-  removeMediaLocation,
-  removeLicense,
-  removeFeaturedVideo,
-}

+ 0 - 333
query-node/mappings/content-directory/entity/update.ts

@@ -1,333 +0,0 @@
-import { DatabaseManager as DB } from '@dzlzv/hydra-db-utils'
-
-import { Channel } from '../../../generated/graphql-server/src/modules/channel/channel.model'
-import { Category } from '../../../generated/graphql-server/src/modules/category/category.model'
-import { KnownLicenseEntity } from '../../../generated/graphql-server/src/modules/known-license-entity/known-license-entity.model'
-import { UserDefinedLicenseEntity } from '../../../generated/graphql-server/src/modules/user-defined-license-entity/user-defined-license-entity.model'
-import { VideoMedia } from '../../../generated/graphql-server/src/modules/video-media/video-media.model'
-import { Video } from '../../../generated/graphql-server/src/modules/video/video.model'
-import { Language } from '../../../generated/graphql-server/src/modules/language/language.model'
-import { VideoMediaEncoding } from '../../../generated/graphql-server/src/modules/video-media-encoding/video-media-encoding.model'
-import { LicenseEntity } from '../../../generated/graphql-server/src/modules/license-entity/license-entity.model'
-import { MediaLocationEntity } from '../../../generated/graphql-server/src/modules/media-location-entity/media-location-entity.model'
-import { HttpMediaLocationEntity } from '../../../generated/graphql-server/src/modules/http-media-location-entity/http-media-location-entity.model'
-import { JoystreamMediaLocationEntity } from '../../../generated/graphql-server/src/modules/joystream-media-location-entity/joystream-media-location-entity.model'
-import { FeaturedVideo } from '../../../generated/graphql-server/src/modules/featured-video/featured-video.model'
-
-import {
-  ICategory,
-  IChannel,
-  IFeaturedVideo,
-  IHttpMediaLocation,
-  IJoystreamMediaLocation,
-  IKnownLicense,
-  ILanguage,
-  ILicense,
-  IMediaLocation,
-  IReference,
-  IUserDefinedLicense,
-  IVideo,
-  IVideoMedia,
-  IVideoMediaEncoding,
-  IWhereCond,
-} from '../../types'
-import {
-  HttpMediaLocation,
-  JoystreamMediaLocation,
-  KnownLicense,
-  UserDefinedLicense,
-} from '../../../generated/graphql-server/src/modules/variants/variants.model'
-
-function getEntityIdFromReferencedField(ref: IReference, entityIdBeforeTransaction: number): string {
-  const { entityId, existing } = ref
-  const id = existing ? entityId : entityIdBeforeTransaction + entityId
-  return id.toString()
-}
-
-async function updateMediaLocationEntityPropertyValues(
-  db: DB,
-  where: IWhereCond,
-  props: IMediaLocation,
-  entityIdBeforeTransaction: number
-): Promise<void> {
-  const { httpMediaLocation, joystreamMediaLocation } = props
-  const record = await db.get(MediaLocationEntity, where)
-  if (record === undefined) throw Error(`MediaLocation entity not found: ${where.where.id}`)
-
-  if (httpMediaLocation) {
-    const id = getEntityIdFromReferencedField(httpMediaLocation, entityIdBeforeTransaction)
-    record.httpMediaLocation = await db.get(HttpMediaLocationEntity, { where: { id } })
-  }
-  if (joystreamMediaLocation) {
-    const id = getEntityIdFromReferencedField(joystreamMediaLocation, entityIdBeforeTransaction)
-    record.joystreamMediaLocation = await db.get(JoystreamMediaLocationEntity, { where: { id } })
-  }
-  await db.save<MediaLocationEntity>(record)
-}
-
-async function updateLicenseEntityPropertyValues(
-  db: DB,
-  where: IWhereCond,
-  props: ILicense,
-  entityIdBeforeTransaction: number
-): Promise<void> {
-  const record = await db.get(LicenseEntity, where)
-  if (record === undefined) throw Error(`License entity not found: ${where.where.id}`)
-
-  const { knownLicense, userDefinedLicense } = props
-  if (knownLicense) {
-    const id = getEntityIdFromReferencedField(knownLicense, entityIdBeforeTransaction)
-    const kLicense = await db.get(KnownLicenseEntity, { where: { id } })
-    if (!kLicense) throw Error(`KnownLicense not found ${id}`)
-
-    const k = new KnownLicense()
-    k.code = kLicense.code
-    k.description = kLicense.description
-    k.name = kLicense.name
-    k.url = kLicense.url
-    // Set the license type
-    record.type = k
-  }
-  if (userDefinedLicense) {
-    const id = getEntityIdFromReferencedField(userDefinedLicense, entityIdBeforeTransaction)
-    const udl = await db.get(UserDefinedLicenseEntity, { where: { id } })
-    if (!udl) throw Error(`UserDefinedLicense not found ${id}`)
-
-    const u = new UserDefinedLicense()
-    u.content = udl.content
-    // Set the license type
-    record.type = u
-  }
-
-  record.attribution = props.attribution || record.attribution
-  await db.save<LicenseEntity>(record)
-}
-
-async function updateCategoryEntityPropertyValues(db: DB, where: IWhereCond, props: ICategory): Promise<void> {
-  const record = await db.get(Category, where)
-  if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
-  Object.assign(record, props)
-  await db.save<Category>(record)
-}
-
-async function updateChannelEntityPropertyValues(
-  db: DB,
-  where: IWhereCond,
-  props: IChannel,
-  entityIdBeforeTransaction: number
-): Promise<void> {
-  const record = await db.get(Channel, where)
-  if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
-
-  let lang: Language | undefined = record.language
-  if (props.language) {
-    const id = getEntityIdFromReferencedField(props.language, entityIdBeforeTransaction)
-    lang = await db.get(Language, { where: { id } })
-    if (lang === undefined) throw Error(`Language entity not found: ${id}`)
-    props.language = undefined
-  }
-  Object.assign(record, props)
-
-  record.language = lang
-  await db.save<Channel>(record)
-}
-
-async function updateVideoMediaEntityPropertyValues(
-  db: DB,
-  where: IWhereCond,
-  props: IVideoMedia,
-  entityIdBeforeTransaction: number
-): Promise<void> {
-  const record = await db.get(VideoMedia, where)
-  if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
-
-  let enco: VideoMediaEncoding | undefined
-  let mediaLoc: HttpMediaLocation | JoystreamMediaLocation = record.location
-  const { encoding, location } = props
-  if (encoding) {
-    const id = getEntityIdFromReferencedField(encoding, entityIdBeforeTransaction)
-    enco = await db.get(VideoMediaEncoding, { where: { id } })
-    if (enco === undefined) throw Error(`VideoMediaEncoding entity not found: ${id}`)
-    props.encoding = undefined
-  }
-
-  if (location) {
-    const id = getEntityIdFromReferencedField(location, entityIdBeforeTransaction)
-    const mLoc = await db.get(MediaLocationEntity, { where: { id } })
-    if (!mLoc) throw Error(`MediaLocation entity not found: ${id}`)
-    const { httpMediaLocation, joystreamMediaLocation } = mLoc
-
-    if (httpMediaLocation) {
-      mediaLoc = new HttpMediaLocation()
-      mediaLoc.url = httpMediaLocation.url
-      mediaLoc.port = httpMediaLocation.port
-    }
-    if (joystreamMediaLocation) {
-      mediaLoc = new JoystreamMediaLocation()
-      mediaLoc.dataObjectId = joystreamMediaLocation.dataObjectId
-    }
-    props.location = undefined
-  }
-  Object.assign(record, props)
-
-  record.encoding = enco || record.encoding
-  record.location = mediaLoc
-  await db.save<VideoMedia>(record)
-}
-
-async function updateVideoEntityPropertyValues(
-  db: DB,
-  where: IWhereCond,
-  props: IVideo,
-  entityIdBeforeTransaction: number
-): Promise<void> {
-  const record = await db.get<Video>(Video, where)
-  if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
-
-  let chann: Channel | undefined
-  let cat: Category | undefined
-  let lang: Language | undefined
-  let vMedia: VideoMedia | undefined
-
-  const { channel, category, language, media, license } = props
-  if (channel) {
-    const id = getEntityIdFromReferencedField(channel, entityIdBeforeTransaction)
-    chann = await db.get(Channel, { where: { id } })
-    if (!chann) throw Error(`Channel entity not found: ${id}`)
-    props.channel = undefined
-  }
-  if (category) {
-    const id = getEntityIdFromReferencedField(category, entityIdBeforeTransaction)
-    cat = await db.get(Category, { where: { id } })
-    if (!cat) throw Error(`Category entity not found: ${id}`)
-    props.category = undefined
-  }
-  if (media) {
-    const id = getEntityIdFromReferencedField(media, entityIdBeforeTransaction)
-    vMedia = await db.get(VideoMedia, { where: { id } })
-    if (!vMedia) throw Error(`VideoMedia entity not found: ${id}`)
-    props.media = undefined
-  }
-  if (license) {
-    const id = getEntityIdFromReferencedField(license, entityIdBeforeTransaction)
-    const licenseEntity = await db.get(LicenseEntity, { where: { id } })
-    if (!licenseEntity) throw Error(`License entity not found: ${id}`)
-    record.license = licenseEntity
-    props.license = undefined
-  }
-  if (language) {
-    const id = getEntityIdFromReferencedField(language, entityIdBeforeTransaction)
-    lang = await db.get(Language, { where: { id } })
-    if (!lang) throw Error(`Language entity not found: ${id}`)
-    props.language = undefined
-  }
-
-  Object.assign(record, props)
-
-  record.channel = chann || record.channel
-  record.category = cat || record.category
-  record.media = vMedia || record.media
-  record.language = lang
-
-  await db.save<Video>(record)
-}
-
-async function updateUserDefinedLicenseEntityPropertyValues(
-  db: DB,
-  where: IWhereCond,
-  props: IUserDefinedLicense
-): Promise<void> {
-  const record = await db.get(UserDefinedLicenseEntity, where)
-  if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
-  Object.assign(record, props)
-  await db.save<UserDefinedLicenseEntity>(record)
-}
-
-async function updateKnownLicenseEntityPropertyValues(db: DB, where: IWhereCond, props: IKnownLicense): Promise<void> {
-  const record = await db.get(KnownLicenseEntity, where)
-  if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
-  Object.assign(record, props)
-  await db.save<KnownLicenseEntity>(record)
-}
-
-async function updateHttpMediaLocationEntityPropertyValues(
-  db: DB,
-  where: IWhereCond,
-  props: IHttpMediaLocation
-): Promise<void> {
-  const record = await db.get(HttpMediaLocationEntity, where)
-  if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
-  Object.assign(record, props)
-  await db.save<HttpMediaLocationEntity>(record)
-}
-
-async function updateJoystreamMediaLocationEntityPropertyValues(
-  db: DB,
-  where: IWhereCond,
-  props: IJoystreamMediaLocation
-): Promise<void> {
-  const record = await db.get(JoystreamMediaLocationEntity, where)
-  if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
-  Object.assign(record, props)
-  await db.save<JoystreamMediaLocationEntity>(record)
-}
-
-async function updateLanguageEntityPropertyValues(db: DB, where: IWhereCond, props: ILanguage): Promise<void> {
-  const record = await db.get(Language, where)
-  if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
-  Object.assign(record, props)
-  await db.save<Language>(record)
-}
-
-async function updateVideoMediaEncodingEntityPropertyValues(
-  db: DB,
-  where: IWhereCond,
-  props: IVideoMediaEncoding
-): Promise<void> {
-  const record = await db.get(VideoMediaEncoding, where)
-  if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
-  Object.assign(record, props)
-  await db.save<VideoMediaEncoding>(record)
-}
-
-async function updateFeaturedVideoEntityPropertyValues(
-  db: DB,
-  where: IWhereCond,
-  props: IFeaturedVideo,
-  entityIdBeforeTransaction: number
-): Promise<void> {
-  const record = await db.get(FeaturedVideo, { ...where, relations: ['video'] })
-  if (record === undefined) throw Error(`FeaturedVideo entity not found: ${where.where.id}`)
-
-  if (props.video) {
-    const id = getEntityIdFromReferencedField(props.video, entityIdBeforeTransaction)
-    const video = await db.get(Video, { where: { id } })
-    if (!video) throw Error(`Video entity not found: ${id}`)
-
-    // Update old video isFeatured to false
-    record.video.isFeatured = false
-    await db.save<Video>(record.video)
-
-    video.isFeatured = true
-    record.video = video
-
-    await db.save<Video>(video)
-    await db.save<FeaturedVideo>(record)
-  }
-}
-
-export {
-  updateCategoryEntityPropertyValues,
-  updateChannelEntityPropertyValues,
-  updateVideoMediaEntityPropertyValues,
-  updateVideoEntityPropertyValues,
-  updateUserDefinedLicenseEntityPropertyValues,
-  updateHttpMediaLocationEntityPropertyValues,
-  updateJoystreamMediaLocationEntityPropertyValues,
-  updateKnownLicenseEntityPropertyValues,
-  updateLanguageEntityPropertyValues,
-  updateVideoMediaEncodingEntityPropertyValues,
-  updateLicenseEntityPropertyValues,
-  updateMediaLocationEntityPropertyValues,
-  updateFeaturedVideoEntityPropertyValues,
-}

+ 0 - 452
query-node/mappings/content-directory/get-or-create.ts

@@ -1,452 +0,0 @@
-import { Channel } from '../../generated/graphql-server/src/modules/channel/channel.model'
-import { Category } from '../../generated/graphql-server/src/modules/category/category.model'
-import { KnownLicenseEntity } from '../../generated/graphql-server/src/modules/known-license-entity/known-license-entity.model'
-import { UserDefinedLicenseEntity } from '../../generated/graphql-server/src/modules/user-defined-license-entity/user-defined-license-entity.model'
-import { JoystreamMediaLocationEntity } from '../../generated/graphql-server/src/modules/joystream-media-location-entity/joystream-media-location-entity.model'
-import { HttpMediaLocationEntity } from '../../generated/graphql-server/src/modules/http-media-location-entity/http-media-location-entity.model'
-import { VideoMedia } from '../../generated/graphql-server/src/modules/video-media/video-media.model'
-import { Language } from '../../generated/graphql-server/src/modules/language/language.model'
-import { VideoMediaEncoding } from '../../generated/graphql-server/src/modules/video-media-encoding/video-media-encoding.model'
-import { LicenseEntity } from '../../generated/graphql-server/src/modules/license-entity/license-entity.model'
-import { MediaLocationEntity } from '../../generated/graphql-server/src/modules/media-location-entity/media-location-entity.model'
-import { Video } from '../../generated/graphql-server/src/modules/video/video.model'
-import { NextEntityId } from '../../generated/graphql-server/src/modules/next-entity-id/next-entity-id.model'
-import { ClassEntity } from '../../generated/graphql-server/src/modules/class-entity/class-entity.model'
-
-import { decode } from './decode'
-import {
-  categoryPropertyNamesWithId,
-  channelPropertyNamesWithId,
-  contentDirectoryClassNamesWithId,
-  httpMediaLocationPropertyNamesWithId,
-  joystreamMediaLocationPropertyNamesWithId,
-  knownLicensePropertyNamesWIthId,
-  languagePropertyNamesWIthId,
-  licensePropertyNamesWithId,
-  mediaLocationPropertyNamesWithId,
-  userDefinedLicensePropertyNamesWithId,
-  videoMediaEncodingPropertyNamesWithId,
-  videoPropertyNamesWithId,
-} from './content-dir-consts'
-import {
-  ClassEntityMap,
-  ICategory,
-  IChannel,
-  IDBBlockId,
-  IEntity,
-  IHttpMediaLocation,
-  IJoystreamMediaLocation,
-  IKnownClass,
-  IKnownLicense,
-  ILanguage,
-  ILicense,
-  IMediaLocation,
-  IReference,
-  IUserDefinedLicense,
-  IVideo,
-  IVideoMedia,
-  IVideoMediaEncoding,
-  IWhereCond,
-} from '../types'
-
-import {
-  createCategory,
-  createChannel,
-  createVideoMedia,
-  createUserDefinedLicense,
-  createKnownLicense,
-  createHttpMediaLocation,
-  createJoystreamMediaLocation,
-  createLanguage,
-  createVideoMediaEncoding,
-  createLicense,
-  createMediaLocation,
-  createVideo,
-} from './entity/create'
-
-import { DatabaseManager as DB } from '@dzlzv/hydra-db-utils'
-
-// Keep track of the next entity id
-async function nextEntityId(db: DB): Promise<NextEntityId> {
-  let e = await db.get(NextEntityId, { where: { id: '1' } })
-  if (!e) {
-    e = new NextEntityId({ id: '1', nextId: 1 })
-    await db.save<NextEntityId>(e)
-  }
-  return e
-}
-
-function generateEntityIdFromIndex(index: number): string {
-  return `${index}`
-}
-
-function findEntity(entityId: number, className: string, classEntityMap: ClassEntityMap): IEntity {
-  const newlyCreatedEntities = classEntityMap.get(className)
-  if (newlyCreatedEntities === undefined) throw Error(`Couldn't find '${className}' entities in the classEntityMap`)
-  const entity = newlyCreatedEntities.find((e) => e.indexOf === entityId)
-  if (!entity) throw Error(`Unknown ${className} entity id: ${entityId}`)
-
-  // Remove the inserted entity from the list
-  classEntityMap.set(
-    className,
-    newlyCreatedEntities.filter((e) => e.entityId !== entityId)
-  )
-  return entity
-}
-
-async function language(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  language: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<Language> {
-  let lang
-  const { entityId, existing } = language
-  if (existing) {
-    lang = await db.get(Language, { where: { id: entityId.toString() } })
-    if (!lang) throw Error(`Language entity not found`)
-    return lang
-  }
-
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-  // could be created in the transaction
-  lang = await db.get(Language, { where: { id } })
-  if (lang) return lang
-
-  // get the entity from list of newly created entities and insert into db
-  const { properties } = findEntity(entityId, 'Language', classEntityMap)
-  return await createLanguage(
-    { db, block, id },
-    decode.setEntityPropertyValues<ILanguage>(properties, languagePropertyNamesWIthId)
-  )
-}
-
-async function videoMediaEncoding(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  encoding: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<VideoMediaEncoding> {
-  let vmEncoding
-  const { entityId, existing } = encoding
-  if (existing) {
-    vmEncoding = await db.get(VideoMediaEncoding, { where: { id: entityId.toString() } })
-    if (!vmEncoding) throw Error(`VideoMediaEncoding entity not found`)
-    return vmEncoding
-  }
-
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-
-  // could be created in the transaction
-  vmEncoding = await db.get(VideoMediaEncoding, { where: { id } })
-  if (vmEncoding) return vmEncoding
-
-  const { properties } = findEntity(entityId, 'VideoMediaEncoding', classEntityMap)
-  return await createVideoMediaEncoding(
-    { db, block, id },
-    decode.setEntityPropertyValues<IVideoMediaEncoding>(properties, videoMediaEncodingPropertyNamesWithId)
-  )
-}
-
-async function videoMedia(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  media: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<VideoMedia> {
-  let videoM: VideoMedia | undefined
-  const { entityId, existing } = media
-  if (existing) {
-    videoM = await db.get(VideoMedia, { where: { id: entityId.toString() } })
-    if (!videoM) throw Error(`VideoMedia entity not found`)
-    return videoM
-  }
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-
-  // could be created in the transaction
-  videoM = await db.get(VideoMedia, { where: { id } })
-  if (videoM) return videoM
-
-  const { properties } = findEntity(entityId, 'VideoMedia', classEntityMap)
-  return await createVideoMedia(
-    { db, block, id },
-    classEntityMap,
-    decode.setEntityPropertyValues<IVideoMedia>(properties, videoPropertyNamesWithId),
-    nextEntityIdBeforeTransaction
-  )
-}
-
-async function knownLicense(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  knownLicense: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<KnownLicenseEntity> {
-  let kLicense: KnownLicenseEntity | undefined
-  const { entityId, existing } = knownLicense
-  if (existing) {
-    kLicense = await db.get(KnownLicenseEntity, { where: { id: entityId.toString() } })
-    if (!kLicense) throw Error(`KnownLicense entity not found`)
-    return kLicense
-  }
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-  // could be created in the transaction
-  kLicense = await db.get(KnownLicenseEntity, { where: { id } })
-  if (kLicense) return kLicense
-
-  const { properties } = findEntity(entityId, 'KnownLicense', classEntityMap)
-  return await createKnownLicense(
-    { db, block, id },
-    decode.setEntityPropertyValues<IKnownLicense>(properties, knownLicensePropertyNamesWIthId)
-  )
-}
-async function userDefinedLicense(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  userDefinedLicense: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<UserDefinedLicenseEntity> {
-  let udLicense: UserDefinedLicenseEntity | undefined
-  const { entityId, existing } = userDefinedLicense
-  if (existing) {
-    udLicense = await db.get(UserDefinedLicenseEntity, { where: { id: entityId.toString() } })
-    if (!udLicense) throw Error(`UserDefinedLicense entity not found`)
-    return udLicense
-  }
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-  // could be created in the transaction
-  udLicense = await db.get(UserDefinedLicenseEntity, {
-    where: { id },
-  })
-  if (udLicense) return udLicense
-
-  const { properties } = findEntity(entityId, 'UserDefinedLicense', classEntityMap)
-  return await createUserDefinedLicense(
-    { db, block, id },
-    decode.setEntityPropertyValues<IUserDefinedLicense>(properties, userDefinedLicensePropertyNamesWithId)
-  )
-}
-
-async function channel(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  channel: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<Channel> {
-  let chann: Channel | undefined
-  const { entityId, existing } = channel
-
-  if (existing) {
-    chann = await db.get(Channel, { where: { id: entityId.toString() } })
-    if (!chann) throw Error(`Channel entity not found`)
-    return chann
-  }
-
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-  // could be created in the transaction
-  chann = await db.get(Channel, { where: { id } })
-  if (chann) return chann
-
-  const { properties } = findEntity(entityId, 'Channel', classEntityMap)
-  return await createChannel(
-    { db, block, id },
-    classEntityMap,
-    decode.setEntityPropertyValues<IChannel>(properties, channelPropertyNamesWithId),
-    nextEntityIdBeforeTransaction
-  )
-}
-
-async function category(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  category: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<Category> {
-  let cat: Category | undefined
-  const { entityId, existing } = category
-
-  if (existing) {
-    cat = await db.get(Category, { where: { id: entityId.toString() } })
-    if (!cat) throw Error(`Category entity not found`)
-    return cat
-  }
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-  // could be created in the transaction
-  cat = await db.get(Category, { where: { id } })
-  if (cat) return cat
-
-  const { properties } = findEntity(entityId, 'Category', classEntityMap)
-  return await createCategory(
-    { db, block, id },
-    decode.setEntityPropertyValues<ICategory>(properties, categoryPropertyNamesWithId)
-  )
-}
-
-async function httpMediaLocation(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  httpMediaLoc: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<HttpMediaLocationEntity | undefined> {
-  let loc: HttpMediaLocationEntity | undefined
-  const { entityId, existing } = httpMediaLoc
-
-  if (existing) {
-    loc = await db.get(HttpMediaLocationEntity, { where: { id: entityId.toString() } })
-    if (!loc) throw Error(`HttpMediaLocation entity not found`)
-    return loc
-  }
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-
-  // could be created in the transaction
-  loc = await db.get(HttpMediaLocationEntity, {
-    where: { id },
-  })
-  if (loc) return loc
-
-  const { properties } = findEntity(entityId, 'HttpMediaLocation', classEntityMap)
-  return await createHttpMediaLocation(
-    { db, block, id },
-    decode.setEntityPropertyValues<IHttpMediaLocation>(properties, httpMediaLocationPropertyNamesWithId)
-  )
-}
-
-async function joystreamMediaLocation(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  joyMediaLoc: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<JoystreamMediaLocationEntity | undefined> {
-  let loc: JoystreamMediaLocationEntity | undefined
-  const { entityId, existing } = joyMediaLoc
-
-  if (existing) {
-    loc = await db.get(JoystreamMediaLocationEntity, { where: { id: entityId.toString() } })
-    if (!loc) throw Error(`JoystreamMediaLocation entity not found`)
-    return loc
-  }
-
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-
-  // could be created in the transaction
-  loc = await db.get(JoystreamMediaLocationEntity, {
-    where: { id },
-  })
-  if (loc) return loc
-
-  const { properties } = findEntity(entityId, 'JoystreamMediaLocation', classEntityMap)
-  return await createJoystreamMediaLocation(
-    { db, block, id },
-    decode.setEntityPropertyValues<IJoystreamMediaLocation>(properties, joystreamMediaLocationPropertyNamesWithId)
-  )
-}
-
-async function license(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  license: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<LicenseEntity> {
-  let lic: LicenseEntity | undefined
-  const { entityId, existing } = license
-
-  if (existing) {
-    lic = await db.get(LicenseEntity, { where: { id: entityId.toString() } })
-    if (!lic) throw Error(`License entity not found`)
-    return lic
-  }
-
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-  // could be created in the transaction
-  lic = await db.get(LicenseEntity, { where: { id } })
-  if (lic) return lic
-
-  const { properties } = findEntity(entityId, 'License', classEntityMap)
-  return await createLicense(
-    { db, block, id },
-    classEntityMap,
-    decode.setEntityPropertyValues<ILicense>(properties, licensePropertyNamesWithId),
-    nextEntityIdBeforeTransaction
-  )
-}
-
-async function mediaLocation(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  location: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<MediaLocationEntity> {
-  const { entityId, existing } = location
-  // Relationships to be loaded
-  const relations = ['httpMediaLocation', 'joystreamMediaLocation']
-  if (existing) {
-    const loc = await db.get(MediaLocationEntity, { where: { id: entityId.toString() }, relations })
-    if (!loc) throw Error(`MediaLocation entity not found`)
-    return loc
-  }
-  // Could be created in the same transaction so try to query
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-  const loc = await db.get(MediaLocationEntity, { where: { id }, relations })
-  if (loc) return loc
-  // Create entity
-  const { properties } = findEntity(entityId, 'MediaLocation', classEntityMap)
-  return await createMediaLocation(
-    { db, block, id },
-    classEntityMap,
-    decode.setEntityPropertyValues<IMediaLocation>(properties, mediaLocationPropertyNamesWithId),
-    nextEntityIdBeforeTransaction
-  )
-}
-
-async function video(
-  { db, block }: IDBBlockId,
-  classEntityMap: ClassEntityMap,
-  video: IReference,
-  nextEntityIdBeforeTransaction: number
-): Promise<Video> {
-  const { existing, entityId } = video
-  if (existing) {
-    const v = await db.get(Video, { where: { id: entityId.toString() } })
-    if (!v) throw Error(`Video not found. id ${entityId}`)
-    return v
-  }
-
-  const id = generateEntityIdFromIndex(nextEntityIdBeforeTransaction + entityId)
-  const v = await db.get(Video, { where: { id } })
-  if (v) return v
-
-  const { properties } = findEntity(entityId, 'MediaVideo', classEntityMap)
-  return await createVideo(
-    { db, block, id },
-    classEntityMap,
-    decode.setEntityPropertyValues<IVideo>(properties, videoPropertyNamesWithId),
-    nextEntityIdBeforeTransaction
-  )
-}
-
-export async function getKnownClass(db: DB, where: IWhereCond): Promise<[IKnownClass | undefined, ClassEntity]> {
-  const ce = await db.get(ClassEntity, where)
-  if (!ce) {
-    throw Error(`Class not found for the EntityId: ${where.where.id} or the entity has not been created.`)
-  }
-
-  const knownClass = contentDirectoryClassNamesWithId.find((c) => c.classId === ce.classId)
-  if (!knownClass) console.log('Unknown class')
-  return [knownClass, ce]
-}
-
-export const getOrCreate = {
-  language,
-  videoMediaEncoding,
-  videoMedia,
-  knownLicense,
-  userDefinedLicense,
-  channel,
-  category,
-  joystreamMediaLocation,
-  httpMediaLocation,
-  license,
-  mediaLocation,
-  nextEntityId,
-  video,
-}

+ 0 - 18
query-node/mappings/content-directory/mapping.ts

@@ -1,18 +0,0 @@
-import { DatabaseManager } from '@dzlzv/hydra-db-utils'
-import { SubstrateEvent } from '@dzlzv/hydra-common'
-
-export {
-  contentDirectory_EntitySchemaSupportAdded,
-  contentDirectory_EntityRemoved,
-  contentDirectory_EntityCreated,
-  contentDirectory_EntityPropertyValuesUpdated,
-} from './entity'
-export { contentDirectory_TransactionCompleted, contentDirectory_TransactionFailed } from './transaction'
-
-// Only one time to seed the database
-// export { system_ExtrinsicSuccess } from './initializeDefaultSchemas'
-
-// eslint-disable-next-line @typescript-eslint/naming-convention
-export function system_ExtrinsicSuccess(db: DatabaseManager, event: SubstrateEvent): void {
-  return
-}

+ 0 - 329
query-node/mappings/content-directory/transaction.ts

@@ -1,329 +0,0 @@
-import Debug from 'debug'
-
-import { SubstrateEvent } from '@dzlzv/hydra-common'
-import { DatabaseManager, DatabaseManager as DB } from '@dzlzv/hydra-db-utils'
-import { NextEntityId } from '../../generated/graphql-server/src/modules/next-entity-id/next-entity-id.model'
-import { ClassEntity } from '../../generated/graphql-server/src/modules/class-entity/class-entity.model'
-
-import { decode } from './decode'
-import {
-  ClassEntityMap,
-  IBatchOperation,
-  ICategory,
-  IChannel,
-  ICreateEntityOperation,
-  IDBBlockId,
-  IEntity,
-  IFeaturedVideo,
-  IHttpMediaLocation,
-  IJoystreamMediaLocation,
-  IKnownLicense,
-  ILanguage,
-  ILicense,
-  IMediaLocation,
-  IProperty,
-  IUserDefinedLicense,
-  IVideo,
-  IVideoMedia,
-  IVideoMediaEncoding,
-  IWhereCond,
-} from '../types'
-import {
-  categoryPropertyNamesWithId,
-  channelPropertyNamesWithId,
-  knownLicensePropertyNamesWIthId,
-  userDefinedLicensePropertyNamesWithId,
-  joystreamMediaLocationPropertyNamesWithId,
-  httpMediaLocationPropertyNamesWithId,
-  videoMediaPropertyNamesWithId,
-  videoMediaEncodingPropertyNamesWithId,
-  videoPropertyNamesWithId,
-  languagePropertyNamesWIthId,
-  ContentDirectoryKnownClasses,
-  licensePropertyNamesWithId,
-  mediaLocationPropertyNamesWithId,
-  featuredVideoPropertyNamesWithId,
-} from './content-dir-consts'
-
-import { getClassName, createBlockOrGetFromDatabase } from './entity/create'
-import { getOrCreate } from './get-or-create'
-import {
-  addSchemaToCategory,
-  addSchemaToChannel,
-  addSchemaToFeaturedVideo,
-  addSchemaToHttpMediaLocation,
-  addSchemaToJoystreamMediaLocation,
-  addSchemaToKnownLicense,
-  addSchemaToLanguage,
-  addSchemaToLicense,
-  addSchemaToMediaLocation,
-  addSchemaToUserDefinedLicense,
-  addSchemaToVideo,
-  addSchemaToVideoMedia,
-  addSchemaToVideoMediaEncoding,
-} from './entity/addSchema'
-import { createDefaultSchema } from './default-schemas'
-
-const debug = Debug('mappings:cd:transaction')
-
-async function getNextEntityId(db: DB): Promise<number> {
-  const e = await db.get(NextEntityId, { where: { id: '1' } })
-  // Entity creation happens before addSchemaSupport so this should never happen
-  if (!e) throw Error(`NextEntityId table doesn't have any record`)
-  return e.nextId
-}
-
-// eslint-disable-next-line @typescript-eslint/naming-convention
-export async function contentDirectory_TransactionFailed(db: DatabaseManager, event: SubstrateEvent): Promise<void> {
-  debug(`TransactionFailed event: ${JSON.stringify(event)}`)
-
-  const failedOperationIndex = event.params[1].value as number
-  const operations = decode.getOperations(event)
-
-  const successfulOperations = operations.toArray().slice(0, failedOperationIndex)
-  if (!successfulOperations.length) return // No succesfull operations
-
-  await applyOperations(decode.getOperationsByTypes(successfulOperations), db, event)
-}
-
-// eslint-disable-next-line @typescript-eslint/naming-convention
-export async function contentDirectory_TransactionCompleted(db: DB, event: SubstrateEvent): Promise<void> {
-  debug(`TransactionCompleted event: ${JSON.stringify(event)}`)
-
-  const operations = decode.getOperations(event)
-
-  await applyOperations(decode.getOperationsByTypes(operations), db, event)
-}
-
-async function applyOperations(operations: IBatchOperation, db: DB, event: SubstrateEvent) {
-  const { addSchemaSupportToEntityOperations, createEntityOperations, updatePropertyValuesOperations } = operations
-  // Create entities before adding schema support
-  // We need this to know which entity belongs to which class(we will need to know to update/create
-  // Channel, Video etc.). For example if there is a property update operation there is no class id
-  await batchCreateClassEntities(db, event.blockNumber, createEntityOperations)
-  await batchAddSchemaSupportToEntity(db, createEntityOperations, addSchemaSupportToEntityOperations, event.blockNumber)
-  await batchUpdatePropertyValue(db, createEntityOperations, updatePropertyValuesOperations)
-}
-
-async function batchCreateClassEntities(db: DB, block: number, operations: ICreateEntityOperation[]): Promise<void> {
-  const nextEntityIdFromDb = await getOrCreate.nextEntityId(db)
-
-  let entityId = nextEntityIdFromDb.nextId
-  for (const { classId } of operations) {
-    const c = new ClassEntity({
-      id: entityId.toString(),
-      classId: classId,
-      version: block,
-      happenedIn: await createBlockOrGetFromDatabase(db, block),
-    })
-    await db.save<ClassEntity>(c)
-
-    // Create default schema for the entity
-    await createDefaultSchema(db, c)
-    entityId++
-  }
-
-  // Update database for next entity id
-  nextEntityIdFromDb.nextId = entityId
-  await db.save<NextEntityId>(nextEntityIdFromDb)
-}
-
-/**
- *
- * @param db database connection
- * @param createEntityOperations: Entity creations with in the same transaction
- * @param entities List of entities that schema support is added for
- * @param block block number
- */
-async function batchAddSchemaSupportToEntity(
-  db: DB,
-  createEntityOperations: ICreateEntityOperation[],
-  entities: IEntity[],
-  block: number
-) {
-  const classEntityMap: ClassEntityMap = new Map<string, IEntity[]>()
-
-  for (const entity of entities) {
-    const className = await getClassName(db, entity, createEntityOperations)
-    if (className !== undefined) {
-      const es = classEntityMap.get(className)
-      classEntityMap.set(className, es ? [...es, entity] : [entity])
-    }
-  }
-
-  // This is a copy of classEntityMap, we will use it to keep track of items.
-  // We will remove items from this list whenever we insert them into db
-  // const doneList: ClassEntityMap = new Map(classEntityMap.entries())
-
-  const nextEntityIdBeforeTransaction = (await getNextEntityId(db)) - createEntityOperations.length
-
-  for (const [className, entities] of classEntityMap) {
-    for (const entity of entities) {
-      const { entityId, indexOf, properties } = entity
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      const id = entityId !== undefined ? entityId : indexOf! + nextEntityIdBeforeTransaction
-      // const arg: IDBBlockId = { db, block, id: id.toString() }
-
-      await addSchemaSupportToEntity(db, className, id, nextEntityIdBeforeTransaction, properties)
-    }
-  }
-}
-
-/**
- * Batch update operations for entity properties values update
- * @param db database connection
- * @param createEntityOperations Entity creations with in the same transaction
- * @param entities list of entities those properties values updated
- */
-async function batchUpdatePropertyValue(db: DB, createEntityOperations: ICreateEntityOperation[], entities: IEntity[]) {
-  const entityIdBeforeTransaction = (await getNextEntityId(db)) - createEntityOperations.length
-
-  for (const entity of entities) {
-    const { entityId, indexOf, properties } = entity
-    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    const id = entityId !== undefined ? entityId : entityIdBeforeTransaction - indexOf!
-
-    // const where: IWhereCond = { where: { id: id.toString() } }
-    const className = await getClassName(db, entity, createEntityOperations)
-    if (!className) {
-      debug(`Can not update entity properties values. Unknown class name`)
-      return
-    }
-
-    await addSchemaSupportToEntity(db, className, id, entityIdBeforeTransaction, properties)
-  }
-}
-
-async function addSchemaSupportToEntity(
-  db: DB,
-  className: string,
-  entityId: number,
-  nextEntityId: number,
-  properties: IProperty[]
-) {
-  switch (className) {
-    case ContentDirectoryKnownClasses.CATEGORY:
-      await addSchemaToCategory({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<ICategory>(properties, categoryPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.CHANNEL:
-      await addSchemaToChannel({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<IChannel>(properties, channelPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.KNOWNLICENSE:
-      await addSchemaToKnownLicense({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<IKnownLicense>(properties, knownLicensePropertyNamesWIthId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.USERDEFINEDLICENSE:
-      await addSchemaToUserDefinedLicense({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<IUserDefinedLicense>(properties, userDefinedLicensePropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.JOYSTREAMMEDIALOCATION:
-      await addSchemaToJoystreamMediaLocation({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<IJoystreamMediaLocation>(
-          properties,
-          joystreamMediaLocationPropertyNamesWithId
-        ),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.HTTPMEDIALOCATION:
-      await addSchemaToHttpMediaLocation({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<IHttpMediaLocation>(properties, httpMediaLocationPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.VIDEOMEDIA:
-      await addSchemaToVideoMedia({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<IVideoMedia>(properties, videoMediaPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.VIDEO:
-      await addSchemaToVideo({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<IVideo>(properties, videoPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.LANGUAGE:
-      await addSchemaToLanguage({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<ILanguage>(properties, languagePropertyNamesWIthId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.VIDEOMEDIAENCODING:
-      await addSchemaToVideoMediaEncoding({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<IVideoMediaEncoding>(properties, videoMediaEncodingPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.LICENSE:
-      await addSchemaToLicense({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<ILicense>(properties, licensePropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.MEDIALOCATION:
-      await addSchemaToMediaLocation({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<IMediaLocation>(properties, mediaLocationPropertyNamesWithId),
-      })
-      break
-
-    case ContentDirectoryKnownClasses.FEATUREDVIDEOS:
-      await addSchemaToFeaturedVideo({
-        db,
-        entityId,
-        nextEntityId,
-        props: decode.setEntityPropertyValues<IFeaturedVideo>(properties, featuredVideoPropertyNamesWithId),
-      })
-      break
-
-    default:
-      debug(`Unknown class name: ${className}`)
-      break
-  }
-}

+ 1 - 2
query-node/mappings/index.ts

@@ -1,2 +1 @@
-export * from './content-directory/mapping'
-// export * from "./membership/mapping"
+export * from './storage'

+ 9 - 5
query-node/mappings/package.json

@@ -1,18 +1,22 @@
 {
   "name": "query-node-mappings",
-  "version": "0.0.1",
+  "version": "0.1.0",
   "description": "Mappings for hydra-processor",
-  "main": "lib/mappings/index.js",
+  "main": "lib/mappings/src/index.js",
   "license": "MIT",
   "scripts": {
-    "build": "rm -rf lib && tsc --build tsconfig.json",
+    "build": "rm -rf lib && tsc --build tsconfig.json && yarn copy-types",
+    "copy-types": "cp ../../types/augment/all/defs.json lib/generated/types/typedefs.json",
     "lint": "echo \"Skippinng\"",
     "clean": "rm -rf lib"
   },
   "dependencies": {
-    "@dzlzv/hydra-common": "2.0.1-beta.9",
     "@polkadot/types": "4.2.1",
-    "warthog": "https://github.com/metmirr/warthog/releases/download/v2.23.0/warthog-v2.23.0.tgz"
+    "@joystream/hydra-common": "3.1.0-alpha.7",
+    "@joystream/hydra-db-utils": "3.1.0-alpha.7",
+    "@joystream/content-metadata-protobuf": "^1.1.0",
+    "@joystream/types": "^0.17.0",
+    "@joystream/warthog": "2.35.0"
   },
   "devDependencies": {
     "ts-node": "^9.0.0",

+ 140 - 0
query-node/mappings/storage.ts

@@ -0,0 +1,140 @@
+/*
+eslint-disable @typescript-eslint/naming-convention
+*/
+import { EventContext, StoreContext } from '@joystream/hydra-common'
+
+// BUCKETS
+
+export async function storage_StorageBucketCreated({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageOperatorMetadataSet({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageBucketStatusUpdated({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageBucketInvitationAccepted({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageBucketInvitationCancelled({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageBucketOperatorInvited({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageBucketOperatorRemoved({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageBucketsUpdatedForBag({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageBucketDeleted({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+// DYNAMIC BAGS
+export async function storage_DynamicBagCreated({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_DynamicBagDeleted({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+// DATA OBJECTS
+
+// Note: "Uploaded" here actually means "created" (the real upload happens later)
+export async function storage_DataObjectdUploaded({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_PendingDataObjectsAccepted({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_DataObjectsMoved({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_DataObjectsDeleted({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+// BLACKLIST
+export async function storage_UpdateBlacklist({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageBucketVoucherLimitsSet({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_UploadingBlockStatusUpdated({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_DataObjectPerMegabyteFeeUpdated({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageBucketsPerBagLimitUpdated({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_StorageBucketsVoucherMaxLimitsUpdated({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_DeletionPrizeChanged({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_VoucherChanged({ event, store }: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}
+
+export async function storage_NumberOfStorageBucketsInDynamicBagCreationPolicyUpdated({
+  event,
+  store,
+}: EventContext & StoreContext): Promise<void> {
+  // To be implemented
+}

+ 1 - 1
query-node/mappings/tsconfig.json

@@ -14,7 +14,7 @@
     "skipLibCheck": true,
     "baseUrl": ".",
     "paths": {
-      "@polkadot/types/augment": ["../../types/augment-codec/augment-types.ts"]
+      "@polkadot/types/augment": ["../../types/augment/augment-types.ts"]
     }
   },
   "include": ["./**/*"]

+ 0 - 209
query-node/mappings/types.ts

@@ -1,209 +0,0 @@
-import BN from 'bn.js'
-import { EntityId, SchemaId, ParametrizedClassPropertyValue, ClassId } from '@joystream/types/content-directory'
-import { DatabaseManager as DB } from '@dzlzv/hydra-db-utils'
-
-export interface BaseJoystreamMember {
-  memberId: BN
-}
-
-export interface JoystreamMember extends BaseJoystreamMember {
-  handle: string
-  avatarUri: string
-  about: string
-  registeredAtBlock: number
-  rootAccount: Buffer
-  controllerAccount: Buffer
-}
-
-export interface MemberAboutText extends BaseJoystreamMember {
-  about: string
-}
-
-export interface MemberAvatarURI extends BaseJoystreamMember {
-  avatarUri: string
-}
-
-export interface MemberHandle extends BaseJoystreamMember {
-  handle: string
-}
-
-export interface MemberRootAccount extends BaseJoystreamMember {
-  rootAccount: Buffer
-}
-export interface MemberControllerAccount extends BaseJoystreamMember {
-  controllerAccount: Buffer
-}
-
-export interface IReference {
-  entityId: number
-  existing: boolean
-}
-
-export interface IChannel {
-  handle: string
-  description: string
-  coverPhotoUrl: string
-  avatarPhotoUrl: string
-  isPublic: boolean
-  isCurated?: boolean
-  language?: IReference
-}
-
-export interface ICategory {
-  name: string
-  description: string
-}
-
-export interface IKnownLicense {
-  code: string
-  name?: string
-  description?: string
-  url?: string
-}
-
-export interface IUserDefinedLicense {
-  content: string
-}
-
-export interface IJoystreamMediaLocation {
-  dataObjectId: string
-}
-
-export interface IHttpMediaLocation {
-  url: string
-  port?: number
-}
-
-export interface ILanguage {
-  name: string
-  code: string
-}
-
-export interface IVideoMediaEncoding {
-  name: string
-}
-
-export interface IVideoMedia {
-  encoding?: IReference
-  pixelWidth: number
-  pixelHeight: number
-  size: number
-  location?: IReference
-}
-
-export interface IVideo {
-  // referenced entity's id
-  channel?: IReference
-  // referenced entity's id
-  category?: IReference
-  title: string
-  description: string
-  duration: number
-  skippableIntroDuration?: number
-  thumbnailUrl: string
-  language?: IReference
-  // referenced entity's id
-  media?: IReference
-  hasMarketing?: boolean
-  publishedBeforeJoystream?: number
-  isPublic: boolean
-  isCurated?: boolean
-  isExplicit: boolean
-  license?: IReference
-}
-
-export interface ILicense {
-  knownLicense?: IReference
-  userDefinedLicense?: IReference
-  attribution?: string
-}
-
-export interface IMediaLocation {
-  httpMediaLocation?: IReference
-  joystreamMediaLocation?: IReference
-}
-
-export enum OperationType {
-  CreateEntity = 'CreateEntity',
-  AddSchemaSupportToEntity = 'AddSchemaSupportToEntity',
-  UpdatePropertyValues = 'UpdatePropertyValues',
-}
-
-export interface IAddSchemaSupportToEntity {
-  entity_id: EntityId
-  schema_id: SchemaId
-  parametrized_property_values: ParametrizedClassPropertyValue[]
-}
-
-export interface ICreateEntity {
-  class_id: ClassId
-}
-
-export interface IClassEntity {
-  entityId: number
-  classId: number
-}
-
-export interface IBatchOperation {
-  createEntityOperations: ICreateEntityOperation[]
-  addSchemaSupportToEntityOperations: IEntity[]
-  updatePropertyValuesOperations: IEntity[]
-}
-
-export interface IProperty {
-  // PropertId: Value
-  // [propertyId: string]: any
-
-  id: string
-  value: any
-
-  // If reference.exising is false then reference.entityId is the index that entity is at
-  // in the transaction batch operation
-  reference?: IReference
-}
-
-export interface IEntity {
-  classId?: number
-  entityId?: number
-  // if entity is created in the same transaction, this is the entity id which is the index of the create
-  // entity operation
-  indexOf?: number
-  properties: IProperty[]
-}
-
-export interface IPropertyDef {
-  name: string
-  type: string
-  required: boolean
-}
-
-export interface IPropertyWithId {
-  [inClassIndex: string]: IPropertyDef
-}
-
-export interface IWhereCond {
-  where: { id: string }
-}
-
-export interface ICreateEntityOperation {
-  classId: number
-}
-
-// An interface to use in function signature to simplify function parameters
-export interface IDBBlockId {
-  db: DB
-  block: number
-  // Entity id
-  id: string
-}
-
-export type ClassEntityMap = Map<string, IEntity[]>
-
-export interface IFeaturedVideo {
-  video?: IReference
-}
-
-export interface IKnownClass {
-  name: string
-  classId: number
-}

+ 39 - 31
query-node/package.json

@@ -1,45 +1,53 @@
 {
   "name": "query-node-root",
-  "version": "1.0.0",
-  "description": "GraphQL server and Substrate indexer. Generated with ♥ by Hydra-CLI",
+  "version": "0.1.0",
+  "description": "GraphQL server and mappings. Generated with \u2665 by Hydra-CLI",
   "scripts": {
     "build": "./build.sh",
-    "test": "echo \"Error: no test specified\" && exit 1",
+    "rebuild": "yarn db:drop && yarn clean:query-node && yarn codegen:query-node && yarn db:prepare && yarn db:migrate",
+    "lint": "echo \"Skippinng\"",
     "clean": "rm -rf ./generated",
-    "processor:start": "./processor-start.sh",
-    "indexer:start": "(cd ./generated/indexer && yarn && DEBUG=${DEBUG} yarn start:indexer --env ../../../.env)",
-    "server:start:dev": "(cd ./generated/graphql-server && yarn start:dev)",
-    "server:start:prod": "(cd ./generated/graphql-server && yarn start:prod)",
-    "configure": "(cd ./generated/graphql-server && yarn config:dev)",
-    "db:up": "(cd ../ && docker-compose up -d db)",
-    "db:drop": "(cd ./generated/graphql-server && yarn db:drop)",
-    "db:migrate": "./db-migrate.sh",
-    "db:schema:migrate": "(cd ./generated/graphql-server && yarn db:create && yarn db:sync && yarn db:migrate)",
-    "codegen": "hydra-cli codegen",
-    "codegen:noinstall": "hydra-cli codegen --no-install",
-    "integration-tests": "./run-tests.sh",
-    "typegen": "rm -rf ./mappings/generated/ && hydra-typegen typegen manifest.yml --debug",
-    "db:init": "(cd ./generated/graphql-server && TYPEORM_LOGGING=true ts-node ../../scripts/initializeDefaultSchemas.ts)"
+    "clean:query-node": "rm -rf ./generated/graphql-server",
+    "processor:bootstrap": "./bootstrap.sh",
+    "processor:start": "DEBUG=${DEBUG} yarn processor:bootstrap && hydra-processor run -e ../.env",
+    "query-node:build": "yarn workspace query-node build",
+    "query-node:start:dev": "yarn workspace query-node start:dev",
+    "query-node:start:prod": "yarn workspace query-node start:prod",
+    "query-node:configure": "yarn workspace query-node config:dev",
+    "db:up": "yarn docker:db:up",
+    "db:create": "yarn workspace query-node db:create",
+    "db:drop": "yarn workspace query-node db:drop",
+    "db:prepare": "yarn workspace query-node db:create && yarn workspace query-node db:sync",
+    "db:schema:migrate": "yarn workspace query-node db:migrate",
+    "db:processor:migrate": "hydra-processor migrate --env ../.env",
+    "db:migrate": "yarn db:schema:migrate && yarn db:processor:migrate",
+    "db:bootstrap": "yarn db:create && yarn db:prepare && yarn db:migrate",
+    "db:reset": "yarn db:drop && yarn db:prepare && yarn db:migrate",
+    "bootstrap": "yarn codegen && yarn db:drop && yarn db:bootstrap",
+    "codegen": "hydra-cli codegen --schema ../../schemas/",
+    "codegen:noinstall": "yarn codegen --no-install",
+    "typegen:configure": "NODE_URL=${NODE_URL:-ws://localhost:9000} envsub typegen.template.yml typegen.yml",
+    "typegen": "rm -rf ./mappings/generated && hydra-typegen typegen manifest.yml --debug",
+    "mappings:build": "yarn workspace query-node-mappings build",
+    "docker:build": "docker build . -f docker/Dockerfile.hydra -t hydra-kit:latest",
+    "docker:db:up": "(cd ../ && docker-compose up -d db)",
+    "docker:db:migrate": "docker run --env-file .env --env DB_HOST=db --env TYPEORM_HOST=db --network container:${PWD##*/}_db_1 hydra-kit:latest yarn db:migrate",
+    "docker:up": "docker-compose up -d"
   },
   "author": "",
   "license": "ISC",
-  "devDependencies": {
-    "@dzlzv/hydra-cli": "0.1.8-1",
-    "@dzlzv/hydra-processor": "2.1.0-beta.4",
-    "@dzlzv/hydra-typegen": "2.1.0-beta.4"
-  },
   "dependencies": {
-    "@dzlzv/hydra-db-utils": "^2.0.1-beta.0",
-    "@joystream/types": "^0.15.0",
+    "tslib": "^2.0.0",
     "@types/bn.js": "^4.11.6",
-    "@types/debug": "^4.1.5",
     "bn.js": "^5.1.2",
-    "debug": "^4.2.0",
-    "dotenvi": "^0.9.1",
-    "nanoid": "^3.1.20",
-    "tslib": "^2.0.0"
+    "@polkadot/metadata": "^4.1.1",
+    "@joystream/hydra-cli": "3.1.0-alpha.7",
+    "@joystream/hydra-processor": "3.1.0-alpha.7"
+  },
+  "devDependencies": {
+    "@joystream/hydra-typegen": "3.1.0-alpha.7"
   },
   "volta": {
-    "extends": "../package.json"
-  }
+		"extends": "../package.json"
+	}
 }

+ 0 - 342
query-node/schema.graphql

@@ -1,342 +0,0 @@
-enum Network {
-  BABYLON
-  ALEXANDRIA
-  ROME
-}
-
-type Block @entity {
-  "Block number as a string"
-  id: ID!
-  block: Int!
-  timestamp: BigInt!
-  network: Network!
-}
-
-"Stored information about a registered user"
-type Member @entity {
-  "MemberId: runtime identifier for a user"
-  id: ID!
-
-  "The unique handle chosen by member"
-  handle: String @unique @fulltext(query: "membersByHandle")
-
-  "A Url to member's Avatar image"
-  avatarUri: String
-
-  "Short text chosen by member to share information about themselves"
-  about: String
-
-  "Blocknumber when member was registered"
-  registeredAtBlock: Int!
-
-  "Member's controller account id"
-  controllerAccount: Bytes!
-
-  "Member's root account id"
-  rootAccount: Bytes!
-
-  happenedIn: Block!
-}
-
-"""
-This type is to keep which entity belongs to which class. This type will be used
-by EntityCreated event. When a new schema support added to an Entity we will get the
-class name from this table.
-We need this because we can't create a database row (Channel, Video etc) without
-with empty fields.
-"""
-type ClassEntity @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  "The class id of this entity"
-  classId: Int!
-
-  happenedIn: Block!
-}
-
-"Keep track of the next entity id"
-type NextEntityId @entity {
-  "Constant field is set to '1'"
-  id: ID!
-
-  nextId: Int!
-}
-
-#### High Level Derivative Entities ####
-
-type Language @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  name: String!
-  code: String!
-
-  happenedIn: Block!
-}
-
-type Channel @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  # "Owner of the channel" Commenting out this field: 'owner' can be curator_group, lead
-  # or a member. We are not handling events related to curator group so we will not set this field
-  # owner: Member!
-
-  "The title of the Channel"
-  handle: String! @fulltext(query: "search")
-
-  "The description of a Channel"
-  description: String!
-
-  "Url for Channel's cover (background) photo. Recommended ratio: 16:9."
-  coverPhotoUrl: String
-
-  "Channel's avatar photo."
-  avatarPhotoUrl: String
-
-  "Flag signaling whether a channel is public."
-  isPublic: Boolean!
-
-  "Flag signaling whether a channel is curated/verified."
-  isCurated: Boolean!
-
-  "The primary langauge of the channel's content"
-  language: Language
-
-  videos: [Video!] @derivedFrom(field: "channel")
-
-  happenedIn: Block!
-}
-
-type Category @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  "The name of the category"
-  name: String! @unique @fulltext(query: "categoriesByName")
-
-  "The description of the category"
-  description: String
-
-  videos: [Video!] @derivedFrom(field: "category")
-
-  happenedIn: Block!
-}
-
-"Encoding and containers"
-type VideoMediaEncoding @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  name: String!
-
-  happenedIn: Block!
-}
-
-type KnownLicenseEntity @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  "Short, commonly recognized code of the licence (ie. CC_BY_SA)"
-  code: String! @unique
-
-  "Full, descriptive name of the license (ie. Creative Commons - Attribution-NonCommercial-NoDerivs)"
-  name: String
-
-  "Short description of the license conditions"
-  description: String
-
-  "An url pointing to full license content"
-  url: String
-
-  happenedIn: Block!
-}
-
-type UserDefinedLicenseEntity @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  "Custom license content"
-  content: String!
-
-  happenedIn: Block!
-}
-
-type MediaLocationEntity @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  # One of the following field will be non-null
-
-  "A reference to HttpMediaLocation"
-  httpMediaLocation: HttpMediaLocationEntity
-
-  "A reference to JoystreamMediaLocation"
-  joystreamMediaLocation: JoystreamMediaLocationEntity
-
-  videoMedia: VideoMedia @derivedFrom(field: "locationEntity")
-
-  happenedIn: Block!
-}
-
-type JoystreamMediaLocationEntity @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  "Id of the data object in the Joystream runtime dataDirectory module"
-  dataObjectId: String!
-
-  happenedIn: Block!
-}
-
-type HttpMediaLocationEntity @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  "The http url pointing to the media"
-  url: String!
-
-  "The port to use when connecting to the http url (defaults to 80)"
-  port: Int
-
-  happenedIn: Block!
-}
-
-type VideoMedia @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  "Encoding of the video media object"
-  encoding: VideoMediaEncoding!
-
-  "Video media width in pixels"
-  pixelWidth: Int!
-
-  "Video media height in pixels"
-  pixelHeight: Int!
-
-  "Video media size in bytes"
-  size: Int
-
-  video: Video @derivedFrom(field: "media")
-
-  "Location of the video media object"
-  location: MediaLocation!
-
-  locationEntity: MediaLocationEntity
-
-  happenedIn: Block!
-}
-
-type Video @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  "Reference to member's channel"
-  channel: Channel!
-
-  "Reference to a video category"
-  category: Category!
-
-  "The title of the video"
-  title: String! @fulltext(query: "search")
-
-  "The description of the Video"
-  description: String!
-
-  "Video duration in seconds"
-  duration: Int!
-
-  "Video's skippable intro duration in seconds"
-  skippableIntroDuration: Int
-
-  "Video thumbnail url (recommended ratio: 16:9)"
-  thumbnailUrl: String!
-
-  "Video's main langauge"
-  language: Language
-
-  "Reference to VideoMedia"
-  media: VideoMedia
-
-  "Whether or not Video contains marketing"
-  hasMarketing: Boolean
-
-  "If the Video was published on other platform before beeing published on Joystream - the original publication date"
-  publishedBeforeJoystream: Int
-
-  "Whether the Video is supposed to be publically displayed"
-  isPublic: Boolean!
-
-  "Video curation status set by the Curator"
-  isCurated: Boolean!
-
-  "Whether the Video contains explicit material."
-  isExplicit: Boolean!
-
-  license: LicenseEntity!
-
-  happenedIn: Block!
-
-  "Is video featured or not"
-  isFeatured: Boolean!
-
-  featured: FeaturedVideo @derivedFrom(field: "video")
-}
-
-type JoystreamMediaLocation @variant {
-  "Id of the data object in the Joystream runtime dataDirectory module"
-  dataObjectId: String!
-}
-
-type HttpMediaLocation @variant {
-  "The http url pointing to the media"
-  url: String!
-
-  "The port to use when connecting to the http url (defaults to 80)"
-  port: Int
-}
-
-union MediaLocation = HttpMediaLocation | JoystreamMediaLocation
-
-type KnownLicense @variant {
-  "Short, commonly recognized code of the licence (ie. CC_BY_SA)"
-  code: String!
-
-  "Full, descriptive name of the license (ie. Creative Commons - Attribution-NonCommercial-NoDerivs)"
-  name: String
-
-  "Short description of the license conditions"
-  description: String
-
-  "An url pointing to full license content"
-  url: String
-}
-
-type UserDefinedLicense @variant {
-  "Custom license content"
-  content: String!
-}
-
-union License = KnownLicense | UserDefinedLicense
-
-type LicenseEntity @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  type: License!
-
-  "Attribution (if required by the license)"
-  attribution: String
-
-  happenedIn: Block!
-}
-
-type FeaturedVideo @entity {
-  "Runtime entity identifier (EntityId)"
-  id: ID!
-
-  "Reference to a video"
-  video: Video!
-}

文件差異過大導致無法顯示
+ 337 - 334
yarn.lock


部分文件因文件數量過多而無法顯示