Pārlūkot izejas kodu

Merge pull request #2167 from metmirr/qnode-indexer-processor

Query node: indexer, processor workflow update
Mokhtar Naamani 4 gadi atpakaļ
vecāks
revīzija
7023448bc0

+ 8 - 3
.env

@@ -2,12 +2,17 @@ COMPOSE_PROJECT_NAME=joystream
 PROJECT_NAME=query_node
 
 # We will use a single postgres service with multiple databases
+# The env variables below are by default used by all services and should be 
+# overriden in local env files
+# DB config
 INDEXER_DB_NAME=query_node_indexer
-PROCESSOR_DB_NAME=query_node_processor
+DB_NAME=query_node_processor
 DB_USER=postgres
 DB_PASS=postgres
 DB_HOST=localhost
 DB_PORT=5432
+DEBUG=index-builder:*
+TYPEORM_LOGGING=error
 
 DEBUG=index-builder:*
 TYPEORM_LOGGING=error
@@ -30,8 +35,8 @@ REDIS_URI=redis://localhost:6379/0
 #    Processor options    #
 ###########################
 
-# Where the mapping scripts are located, relative to ./generated/indexer
-TYPES_JSON=../../../types/augment/all/defs.json
+# Where the mapping scripts are located
+TYPES_JSON=./types/augment/all/defs.json
 
 # Indexer GraphQL API endpoint to fetch indexed events
 INDEXER_ENDPOINT_URL=http://localhost:4000/graphql

+ 15 - 13
docker-compose.yml

@@ -74,7 +74,7 @@ services:
       - .env
     environment:
       - DB_HOST=db
-      - DB_NAME=${PROCESSOR_DB_NAME}
+      - DB_NAME=${DB_NAME}
     ports:
       - "127.0.0.1:8081:${GRAPHQL_SERVER_PORT}"
     depends_on: 
@@ -93,35 +93,37 @@ services:
     environment:
       - INDEXER_ENDPOINT_URL=http://indexer-api-gateway:${WARTHOG_APP_PORT}/graphql
       - TYPEORM_HOST=db
-      - TYPEORM_DATABASE=${PROCESSOR_DB_NAME}
+      - TYPEORM_DATABASE=${DB_NAME}
       - DEBUG=index-builder:*
       - WS_PROVIDER_ENDPOINT_URI=ws://joystream-node:9944
     depends_on:
-      - indexer-api-gateway
+      - hydra-indexer-gateway
     command: ["workspace", "query-node-root", "processor:start"]
 
   indexer:
-    image: joystream/apps
+    image: joystream/hydra-indexer:latest
     restart: unless-stopped
-    build: 
-      context: .
-      dockerfile: apps.Dockerfile
     env_file:
       # relative to working directory where docker-compose was run from
       - .env
     environment:
-      - TYPEORM_HOST=db
-      - TYPEORM_DATABASE=${INDEXER_DB_NAME}
+      - DB_HOST=db
+      - DB_NAME=${INDEXER_DB_NAME}
       - INDEXER_WORKERS=5
       - PROCESSOR_POLL_INTERVAL=1000 # refresh every second 
       - REDIS_URI=redis://redis:6379/0
       - DEBUG=index-builder:*
-      - WS_PROVIDER_ENDPOINT_URI=ws://joystream-node:9944
-    depends_on: 
+      - WS_PROVIDER_ENDPOINT_URI=${WS_PROVIDER_ENDPOINT_URI}
+      - TYPES_JSON=${TYPES_JSON}
+    depends_on:
       - db
-    command: ["workspace", "query-node-root", "indexer:start"] 
+      - redis
+    volumes:
+      - ${TYPES_JSON}:/home/hydra/packages/hydra-indexer/types/augment/all/defs.json
+    command: >
+      sh -c "yarn db:bootstrap && yarn start:prod"
 
-  indexer-api-gateway:
+  hydra-indexer-gateway:
     image: joystream/hydra-indexer-gateway:latest
     restart: unless-stopped
     env_file:

+ 2 - 2
package.json

@@ -22,6 +22,7 @@
     "pioneer/packages/*",
     "utils/api-scripts",
     "query-node",
+    "query-node/mappings",
     "query-node/generated/*",
     "content-metadata-protobuf"
   ],
@@ -35,8 +36,7 @@
     "@polkadot/wasm-crypto": "^1.2.1",
     "babel-core": "^7.0.0-bridge.0",
     "typescript": "^3.9.7",
-    "bn.js": "^5.1.2",
-    "@dzlzv/hydra-indexer-lib": "0.0.22-legacy.1.26.1"
+    "bn.js": "^5.1.2"
   },
   "devDependencies": {
     "eslint": "^7.6.0",

+ 44 - 19
query-node/README.md

@@ -1,36 +1,61 @@
-# query-node
+# Query node
 
-The query-node project contains an input schema (schema.graphql) and mappings for the Joystream `content-directory` runtime module.
+This is a query-node project generated by `hydra-cli`. Experiment by modifying `schema.graphql` and the mappings in the `mappings` folder, defined in `manifest.yml`.
 
-## Code generation
+## 1. Bootstrap
 
-We use Hydra-cli to generate a graphql server and a block indexer for joystream chain:
+Run
 
 ```bash
-$ cd query-node
-$ yarn build
+yarn && yarn bootstrap
 ```
 
-## Starting services
+and generate the model files as defined in `schema.graphql`, create the database and run all the necessary migrations in one shot.
 
-To start services defined in the project docker-compose.yml, you should run docker-compose from the project root folder to use the correct .env file
+NB! Don't use in production, as it will delete all the existing records.
 
-## Run mapping processor
 
-Before running mappings make sure indexer(`yarn indexer:start`) and indexer-api-server (mappings get the chain data from this graphql server) are both running:
+## 2. Generate Types for events and extrinsics
+
+A separate tool Hydra Typegen can be used for generating Typescript classes for the event handlers (the _mappings_).  
+Run
 
 ```bash
-yarn processor:start
+yarn typegen
+```
+to run the [typegen](https://github.com/Joystream/hydra/tree/master/packages/hydra-typegen/README.md) for events and extrinsics defined in `manifest.yml` (it fetches the metadata from an RPC endpoint and blockhash defined there). 
+
+
+## 3. Build Mappings
+
+Mappings is a separated TypeScript module created in the mappings folder. The handlers exported by the module should match the ones defined in `manifest.yml` in the mappings section. Once the necessary files are generated, build it with
+
+```bash
+yarn mappings:build
 ```
 
-## Query data
+## 4. Run the processor and the GraphQL server
 
-Once processor start to store event data you will be able to query this data from `http://localhost:4002/graphql`.
+Then run the processor:
 
-```graphql
-query {
-  channels {
-    handle
-  }
-}
+```bash
+yarn processor:start
 ```
+
+Afterwards start the GraphQL server in a separate terminal (opens a GraphQL playground at localhost by default):
+
+```bash
+yarn query-node:start:dev
+```
+
+## 5. Locally hosted indexer
+
+The Hydra Indexer endpoint used by Hydra processor is defined as environment variable `INDEXER_ENDPOINT_URL` sourced from `.env`. There are publicly available Hydra indexers for Polkadot and Subsocial. For other chains, a self-hosted indexer should be used.
+
+The simplest way to run an indexer locally is to run `docker-compose-indexer.yml` with `docker-compose`. The following environment variables must be provided:
+
+- Database connection settings: DB_NAME, DB_HOST, DB_PORT, DB_USER, DB_PASS
+- Chain RPC endpoint: WS_PROVIDER_ENDPOINT_URI
+- If non-standard types are being used by the Substrate runtime, map type definitions in the json format as an external volume
+
+Follow the links for more information about the [indexer](https://github.com/Joystream/hydra/tree/master/packages/hydra-indexer/README.md) service and [indexer-api-gateway](https://github.com/Joystream/hydra/tree/master/packages/hydra-indexer-gateway/README.md).

+ 2 - 11
query-node/build.sh

@@ -11,19 +11,10 @@ set +a
 
 yarn clean
 
-# We generate the code for each service separately to be able to specify
-# separate database names.
+yarn codegen:noinstall
 
-# Build indexer customizing DB name
-DB_NAME=${INDEXER_DB_NAME} yarn codegen:indexer
-
-# Build graphql-server customizing DB name
-DB_NAME=${PROCESSOR_DB_NAME} yarn codegen:server
-
-# 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 || :
-
-yarn tsc --build tsconfig.json

+ 0 - 13
query-node/db-migrate.sh

@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-set -e
-
-SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
-cd $SCRIPT_PATH
-
-set -a
-. ../.env
-set +a
-
-yarn workspace query-node-root db:indexer:migrate
-yarn workspace query-node-root db:schema:migrate
-TYPEORM_DATABASE=${PROCESSOR_DB_NAME} yarn workspace query-node-root db:indexer:migrate

+ 0 - 21
query-node/indexer-tsconfig.json

@@ -1,21 +0,0 @@
-{
-  "compilerOptions": {
-    "declaration": true,
-    "importHelpers": true,
-    "module": "commonjs",
-    "strict": true,
-    "target": "es2017",
-    "experimentalDecorators": true,
-    "emitDecoratorMetadata": true,
-    "skipLibCheck": true,
-    "sourceMap": true,
-    "inlineSources": false,
-    "strictPropertyInitialization": false,
-    "baseUrl": ".",
-    "paths": {
-      "@polkadot/types/augment": ["../../../types/augment-codec/augment-types.ts"]
-    },
-    "esModuleInterop": true
-  },
-  "exclude": ["node_modules"]
-}

+ 57 - 0
query-node/manifest.yml

@@ -0,0 +1,57 @@
+version: '0.1'
+description: Joystream query-node manifest file for sumer
+repository: https://github.com/Joystream/joystream
+dataSource:
+  kind: substrate 
+  chain: joystream
+  indexerVersion: '0.1.6'
+entities:
+  - mappings/lib/generated/**/*.model.js
+metadata:
+  # TODO: update source and blockHash for sumer release
+  source: wss://babylon-sub-1.joystream.app/staging/rpc
+  blockHash: '0x206a6cca31333cb19ee120cde7455e13eea368ec3f6176d0cd48698228410489'
+events:
+  - members.MemberRegistered
+  - members.MemberUpdatedAboutText
+  - members.MemberUpdatedAvatar
+  - members.MemberUpdatedHandle
+  - members.MemberSetRootAccount
+  - members.MemberSetControllerAccount
+calls:
+  - members.buyMembership
+  - members.addScreenedMember
+outDir: ./mappings/generated/types
+customTypes:
+  lib: '@joystream/types/augment/all/types'
+  typedefsLoc: '../types/augment/all/defs.json'
+mappings:
+  hydraCommonVersion: '0.0.3'
+    # process only blocks with height >= 1M 
+  blockInterval: '[1000000,]'
+  # js module that exports the handler functions 
+  mappingsModule: mappings/lib/mappings
+  # 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
+  eventHandlers:
+    - event: members.MemberRegistered
+      handler: members_MemberRegistered(DatabaseManager, SubstrateEvent)
+    - event: members.MemberUpdatedAboutText
+      handler: members_MemberUpdatedAboutText(DatabaseManager, SubstrateEvent)
+    - event: members.MemberUpdatedAvatar
+      handler: members_MemberUpdatedAvatar(DatabaseManager, SubstrateEvent)
+    - event: members.MemberUpdatedHandle
+      handler: members_MemberUpdatedHandle(DatabaseManager, SubstrateEvent)
+    - event: members.MemberSetRootAccount
+      handler: members_MemberSetRootAccount(DatabaseManager, SubstrateEvent)
+    - event: members.MemberSetControllerAccount
+      handler: members_MemberSetControllerAccount(DatabaseManager, SubstrateEvent)
+  extrinsicHandlers:
+    # infer defaults here
+    #- extrinsic: Balances.Transfer 
+    #- extrinsic: Sudo.batchCall 
+    #  handler: handleSudoCall(DatabaseManager,SubstrateEvent)
+  preBlockHooks:
+  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 '../../generated/indexer'
-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 - 456
query-node/mappings/content-directory/entity/create.ts

@@ -1,456 +0,0 @@
-import { DB } from '../../../generated/indexer'
-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 - 396
query-node/mappings/content-directory/entity/index.ts

@@ -1,396 +0,0 @@
-import Debug from 'debug'
-import { DB, SubstrateEvent } from '../../../generated/indexer'
-import { ClassEntity } from '../../../generated/graphql-server/src/modules/class-entity/class-entity.model'
-
-import { decode } from '../decode'
-import {
-  updateCategoryEntityPropertyValues,
-  updateChannelEntityPropertyValues,
-  updateVideoMediaEntityPropertyValues,
-  updateVideoEntityPropertyValues,
-  updateUserDefinedLicenseEntityPropertyValues,
-  updateHttpMediaLocationEntityPropertyValues,
-  updateJoystreamMediaLocationEntityPropertyValues,
-  updateKnownLicenseEntityPropertyValues,
-  updateLanguageEntityPropertyValues,
-  updateVideoMediaEncodingEntityPropertyValues,
-  updateLicenseEntityPropertyValues,
-  updateMediaLocationEntityPropertyValues,
-  updateFeaturedVideoEntityPropertyValues,
-} from './update'
-import {
-  removeCategory,
-  removeChannel,
-  removeVideoMedia,
-  removeVideo,
-  removeUserDefinedLicense,
-  removeKnownLicense,
-  removeHttpMediaLocation,
-  removeJoystreamMediaLocation,
-  removeLanguage,
-  removeVideoMediaEncoding,
-  removeLicense,
-  removeMediaLocation,
-  removeFeaturedVideo,
-} from './remove'
-import {
-  createCategory,
-  createChannel,
-  createVideoMedia,
-  createVideo,
-  createUserDefinedLicense,
-  createKnownLicense,
-  createHttpMediaLocation,
-  createJoystreamMediaLocation,
-  createLanguage,
-  createVideoMediaEncoding,
-  createBlockOrGetFromDatabase,
-  createFeaturedVideo,
-} from './create'
-import {
-  categoryPropertyNamesWithId,
-  channelPropertyNamesWithId,
-  httpMediaLocationPropertyNamesWithId,
-  joystreamMediaLocationPropertyNamesWithId,
-  knownLicensePropertyNamesWIthId,
-  languagePropertyNamesWIthId,
-  userDefinedLicensePropertyNamesWithId,
-  videoMediaEncodingPropertyNamesWithId,
-  videoPropertyNamesWithId,
-  ContentDirectoryKnownClasses,
-  featuredVideoPropertyNamesWithId,
-} from '../content-dir-consts'
-
-import {
-  IChannel,
-  ICategory,
-  IKnownLicense,
-  IUserDefinedLicense,
-  IJoystreamMediaLocation,
-  IHttpMediaLocation,
-  IVideoMedia,
-  IVideo,
-  ILanguage,
-  IVideoMediaEncoding,
-  IDBBlockId,
-  IWhereCond,
-  IEntity,
-  ILicense,
-  IMediaLocation,
-  IFeaturedVideo,
-} from '../../types'
-import { getOrCreate, getKnownClass } from '../get-or-create'
-
-const debug = Debug('mappings:content-directory')
-
-// 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 { blockNumber: block } = event
-  const entityId = decode.stringIfyEntityId(event)
-
-  const [knownClass] = await getKnownClass(db, { where: { id: entityId } })
-  if (!knownClass) return
-
-  const arg: IDBBlockId = { db, block, id: entityId }
-
-  switch (knownClass.name) {
-    case ContentDirectoryKnownClasses.CHANNEL:
-      await createChannel(
-        arg,
-        new Map<string, IEntity[]>(),
-        decode.setProperties<IChannel>(event, channelPropertyNamesWithId),
-        0 // ignored
-      )
-      break
-
-    case ContentDirectoryKnownClasses.CATEGORY:
-      await createCategory(arg, decode.setProperties<ICategory>(event, categoryPropertyNamesWithId))
-      break
-
-    case ContentDirectoryKnownClasses.KNOWNLICENSE:
-      await createKnownLicense(arg, decode.setProperties<IKnownLicense>(event, knownLicensePropertyNamesWIthId))
-      break
-
-    case ContentDirectoryKnownClasses.USERDEFINEDLICENSE:
-      await createUserDefinedLicense(
-        arg,
-        decode.setProperties<IUserDefinedLicense>(event, userDefinedLicensePropertyNamesWithId)
-      )
-      break
-
-    case ContentDirectoryKnownClasses.JOYSTREAMMEDIALOCATION:
-      await createJoystreamMediaLocation(
-        arg,
-        decode.setProperties<IJoystreamMediaLocation>(event, joystreamMediaLocationPropertyNamesWithId)
-      )
-      break
-
-    case ContentDirectoryKnownClasses.HTTPMEDIALOCATION:
-      await createHttpMediaLocation(
-        arg,
-        decode.setProperties<IHttpMediaLocation>(event, httpMediaLocationPropertyNamesWithId)
-      )
-      break
-
-    case ContentDirectoryKnownClasses.VIDEOMEDIA:
-      await createVideoMedia(
-        arg,
-        new Map<string, IEntity[]>(),
-        decode.setProperties<IVideoMedia>(event, videoPropertyNamesWithId),
-        0 // ignored
-      )
-      break
-
-    case ContentDirectoryKnownClasses.VIDEO:
-      await createVideo(
-        arg,
-        new Map<string, IEntity[]>(),
-        decode.setProperties<IVideo>(event, videoPropertyNamesWithId),
-        0 // ignored
-      )
-      break
-
-    case ContentDirectoryKnownClasses.LANGUAGE:
-      await createLanguage(arg, decode.setProperties<ILanguage>(event, languagePropertyNamesWIthId))
-      break
-
-    case ContentDirectoryKnownClasses.VIDEOMEDIAENCODING:
-      await createVideoMediaEncoding(
-        arg,
-        decode.setProperties<IVideoMediaEncoding>(event, videoMediaEncodingPropertyNamesWithId)
-      )
-      break
-    case ContentDirectoryKnownClasses.FEATUREDVIDEOS:
-      await createFeaturedVideo(
-        arg,
-        new Map<string, IEntity[]>(),
-        decode.setProperties<IFeaturedVideo>(event, featuredVideoPropertyNamesWithId),
-        0
-      )
-      break
-
-    default:
-      throw new Error(`Unknown class name: ${knownClass.name}`)
-  }
-}
-
-// 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)
-
-  await getOrCreate.nextEntityId(db, c.entityId + 1)
-}
-
-// 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 [knownClass] = await getKnownClass(db, where)
-  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)
-
-  switch (knownClass.name) {
-    case ContentDirectoryKnownClasses.CHANNEL:
-      updateChannelEntityPropertyValues(db, where, decode.setProperties<IChannel>(event, channelPropertyNamesWithId), 0)
-      break
-
-    case ContentDirectoryKnownClasses.CATEGORY:
-      await updateCategoryEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<ICategory>(event, categoryPropertyNamesWithId)
-      )
-      break
-
-    case ContentDirectoryKnownClasses.KNOWNLICENSE:
-      await updateKnownLicenseEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<IKnownLicense>(event, knownLicensePropertyNamesWIthId)
-      )
-      break
-
-    case ContentDirectoryKnownClasses.USERDEFINEDLICENSE:
-      await updateUserDefinedLicenseEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<IUserDefinedLicense>(event, userDefinedLicensePropertyNamesWithId)
-      )
-      break
-
-    case ContentDirectoryKnownClasses.JOYSTREAMMEDIALOCATION:
-      await updateJoystreamMediaLocationEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<IJoystreamMediaLocation>(event, joystreamMediaLocationPropertyNamesWithId)
-      )
-      break
-
-    case ContentDirectoryKnownClasses.HTTPMEDIALOCATION:
-      await updateHttpMediaLocationEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<IHttpMediaLocation>(event, httpMediaLocationPropertyNamesWithId)
-      )
-      break
-
-    case ContentDirectoryKnownClasses.VIDEOMEDIA:
-      await updateVideoMediaEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<IVideoMedia>(event, videoPropertyNamesWithId),
-        0
-      )
-      break
-
-    case ContentDirectoryKnownClasses.VIDEO:
-      await updateVideoEntityPropertyValues(db, where, decode.setProperties<IVideo>(event, videoPropertyNamesWithId), 0)
-      break
-
-    case ContentDirectoryKnownClasses.LANGUAGE:
-      await updateLanguageEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<ILanguage>(event, languagePropertyNamesWIthId)
-      )
-      break
-
-    case ContentDirectoryKnownClasses.VIDEOMEDIAENCODING:
-      await updateVideoMediaEncodingEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<IVideoMediaEncoding>(event, videoMediaEncodingPropertyNamesWithId)
-      )
-      break
-
-    case ContentDirectoryKnownClasses.LICENSE:
-      await updateLicenseEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<ILicense>(event, videoMediaEncodingPropertyNamesWithId),
-        0
-      )
-      break
-
-    case ContentDirectoryKnownClasses.MEDIALOCATION:
-      await updateMediaLocationEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<IMediaLocation>(event, videoMediaEncodingPropertyNamesWithId),
-        0
-      )
-      break
-
-    case ContentDirectoryKnownClasses.FEATUREDVIDEOS:
-      await updateFeaturedVideoEntityPropertyValues(
-        db,
-        where,
-        decode.setProperties<IFeaturedVideo>(event, featuredVideoPropertyNamesWithId),
-        0
-      )
-      break
-
-    default:
-      throw new Error(`Unknown class name: ${knownClass.name}`)
-  }
-}
-
-export {
-  contentDirectory_EntityCreated,
-  contentDirectory_EntityRemoved,
-  contentDirectory_EntitySchemaSupportAdded,
-  contentDirectory_EntityPropertyValuesUpdated,
-}

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

@@ -1,139 +0,0 @@
-import assert from 'assert'
-import Debug from 'debug'
-
-import { DB } from '../../../generated/indexer'
-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 - 332
query-node/mappings/content-directory/entity/update.ts

@@ -1,332 +0,0 @@
-import { DB } from '../../../generated/indexer'
-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 - 450
query-node/mappings/content-directory/get-or-create.ts

@@ -1,450 +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 { DB } from '../../generated/indexer'
-
-// Keep track of the next entity id
-async function nextEntityId(db: DB, nextEntityId: number): Promise<void> {
-  let e = await db.get(NextEntityId, { where: { id: '1' } })
-  if (!e) e = new NextEntityId({ id: '1' })
-  e.nextId = nextEntityId
-  await db.save<NextEntityId>(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 - 7
query-node/mappings/content-directory/mapping.ts

@@ -1,7 +0,0 @@
-export {
-  contentDirectory_EntitySchemaSupportAdded,
-  contentDirectory_EntityRemoved,
-  contentDirectory_EntityCreated,
-  contentDirectory_EntityPropertyValuesUpdated,
-} from './entity'
-export { contentDirectory_TransactionCompleted, contentDirectory_TransactionFailed } from './transaction'

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

@@ -1,417 +0,0 @@
-import Debug from 'debug'
-
-import { DB, SubstrateEvent } from '../../generated/indexer'
-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,
-  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 {
-  updateCategoryEntityPropertyValues,
-  updateChannelEntityPropertyValues,
-  updateVideoMediaEntityPropertyValues,
-  updateVideoEntityPropertyValues,
-  updateUserDefinedLicenseEntityPropertyValues,
-  updateHttpMediaLocationEntityPropertyValues,
-  updateJoystreamMediaLocationEntityPropertyValues,
-  updateKnownLicenseEntityPropertyValues,
-  updateLanguageEntityPropertyValues,
-  updateVideoMediaEncodingEntityPropertyValues,
-  updateLicenseEntityPropertyValues,
-  updateMediaLocationEntityPropertyValues,
-  updateFeaturedVideoEntityPropertyValues,
-} from './entity/update'
-
-import {
-  createCategory,
-  createChannel,
-  createVideoMedia,
-  createVideo,
-  createUserDefinedLicense,
-  createKnownLicense,
-  createHttpMediaLocation,
-  createJoystreamMediaLocation,
-  createLanguage,
-  createVideoMediaEncoding,
-  getClassName,
-  createLicense,
-  createMediaLocation,
-  createBlockOrGetFromDatabase,
-  createFeaturedVideo,
-} from './entity/create'
-import { getOrCreate } from './get-or-create'
-
-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: DB, 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 nId = await db.get(NextEntityId, { where: { id: '1' } })
-  let nextId = nId ? nId.nextId : 1 // start entity id from 1
-
-  for (const { classId } of operations) {
-    const c = new ClassEntity({
-      id: nextId.toString(), // entity id
-      classId: classId,
-      version: block,
-      happenedIn: await createBlockOrGetFromDatabase(db, block),
-    })
-    await db.save<ClassEntity>(c)
-    nextId++
-  }
-
-  await getOrCreate.nextEntityId(db, nextId)
-}
-
-/**
- *
- * @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() }
-
-      switch (className) {
-        case ContentDirectoryKnownClasses.CATEGORY:
-          await createCategory(arg, decode.setEntityPropertyValues<ICategory>(properties, categoryPropertyNamesWithId))
-          break
-
-        case ContentDirectoryKnownClasses.CHANNEL:
-          await createChannel(
-            arg,
-            doneList,
-            decode.setEntityPropertyValues<IChannel>(properties, channelPropertyNamesWithId),
-            nextEntityIdBeforeTransaction
-          )
-          break
-
-        case ContentDirectoryKnownClasses.KNOWNLICENSE:
-          await createKnownLicense(
-            arg,
-            decode.setEntityPropertyValues<IKnownLicense>(properties, knownLicensePropertyNamesWIthId)
-          )
-          break
-
-        case ContentDirectoryKnownClasses.USERDEFINEDLICENSE:
-          await createUserDefinedLicense(
-            arg,
-            decode.setEntityPropertyValues<IUserDefinedLicense>(properties, userDefinedLicensePropertyNamesWithId)
-          )
-          break
-
-        case ContentDirectoryKnownClasses.JOYSTREAMMEDIALOCATION:
-          await createJoystreamMediaLocation(
-            arg,
-            decode.setEntityPropertyValues<IJoystreamMediaLocation>(
-              properties,
-              joystreamMediaLocationPropertyNamesWithId
-            )
-          )
-          break
-
-        case ContentDirectoryKnownClasses.HTTPMEDIALOCATION:
-          await createHttpMediaLocation(
-            arg,
-            decode.setEntityPropertyValues<IHttpMediaLocation>(properties, httpMediaLocationPropertyNamesWithId)
-          )
-          break
-
-        case ContentDirectoryKnownClasses.VIDEOMEDIA:
-          await createVideoMedia(
-            arg,
-            doneList,
-            decode.setEntityPropertyValues<IVideoMedia>(properties, videoMediaPropertyNamesWithId),
-            nextEntityIdBeforeTransaction
-          )
-          break
-
-        case ContentDirectoryKnownClasses.VIDEO:
-          await createVideo(
-            arg,
-            doneList,
-            decode.setEntityPropertyValues<IVideo>(properties, videoPropertyNamesWithId),
-            nextEntityIdBeforeTransaction
-          )
-          break
-
-        case ContentDirectoryKnownClasses.LANGUAGE:
-          await createLanguage(arg, decode.setEntityPropertyValues<ILanguage>(properties, languagePropertyNamesWIthId))
-          break
-
-        case ContentDirectoryKnownClasses.VIDEOMEDIAENCODING:
-          await createVideoMediaEncoding(
-            arg,
-            decode.setEntityPropertyValues<IVideoMediaEncoding>(properties, videoMediaEncodingPropertyNamesWithId)
-          )
-          break
-
-        case ContentDirectoryKnownClasses.LICENSE:
-          await createLicense(
-            arg,
-            classEntityMap,
-            decode.setEntityPropertyValues<ILicense>(properties, licensePropertyNamesWithId),
-            nextEntityIdBeforeTransaction
-          )
-          break
-        case ContentDirectoryKnownClasses.MEDIALOCATION:
-          await createMediaLocation(
-            arg,
-            classEntityMap,
-            decode.setEntityPropertyValues<IMediaLocation>(properties, mediaLocationPropertyNamesWithId),
-            nextEntityIdBeforeTransaction
-          )
-          break
-
-        case ContentDirectoryKnownClasses.FEATUREDVIDEOS:
-          await createFeaturedVideo(
-            arg,
-            classEntityMap,
-            decode.setEntityPropertyValues<IFeaturedVideo>(properties, featuredVideoPropertyNamesWithId),
-            nextEntityIdBeforeTransaction
-          )
-          break
-
-        default:
-          console.log(`Unknown class name: ${className}`)
-          break
-      }
-    }
-  }
-}
-
-/**
- * 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 ? entityId.toString() : entityIdBeforeTransaction - indexOf!
-
-    const where: IWhereCond = { where: { id: id.toString() } }
-    const className = await getClassName(db, entity, createEntityOperations)
-    if (className === undefined) {
-      console.log(`Can not update entity properties values. Unknown class name`)
-      return
-    }
-
-    switch (className) {
-      case ContentDirectoryKnownClasses.CHANNEL:
-        await updateChannelEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<IChannel>(properties, channelPropertyNamesWithId),
-          entityIdBeforeTransaction
-        )
-        break
-
-      case ContentDirectoryKnownClasses.CATEGORY:
-        await updateCategoryEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<ICategory>(properties, categoryPropertyNamesWithId)
-        )
-        break
-
-      case ContentDirectoryKnownClasses.KNOWNLICENSE:
-        await updateKnownLicenseEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<IKnownLicense>(properties, knownLicensePropertyNamesWIthId)
-        )
-        break
-
-      case ContentDirectoryKnownClasses.USERDEFINEDLICENSE:
-        await updateUserDefinedLicenseEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<IUserDefinedLicense>(properties, userDefinedLicensePropertyNamesWithId)
-        )
-        break
-
-      case ContentDirectoryKnownClasses.JOYSTREAMMEDIALOCATION:
-        await updateJoystreamMediaLocationEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<IJoystreamMediaLocation>(properties, joystreamMediaLocationPropertyNamesWithId)
-        )
-        break
-
-      case ContentDirectoryKnownClasses.HTTPMEDIALOCATION:
-        await updateHttpMediaLocationEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<IHttpMediaLocation>(properties, httpMediaLocationPropertyNamesWithId)
-        )
-        break
-
-      case ContentDirectoryKnownClasses.VIDEOMEDIA:
-        await updateVideoMediaEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<IVideoMedia>(properties, videoPropertyNamesWithId),
-          entityIdBeforeTransaction
-        )
-        break
-
-      case ContentDirectoryKnownClasses.VIDEO:
-        await updateVideoEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<IVideo>(properties, videoPropertyNamesWithId),
-          entityIdBeforeTransaction
-        )
-        break
-
-      case ContentDirectoryKnownClasses.LANGUAGE:
-        await updateLanguageEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<ILanguage>(properties, languagePropertyNamesWIthId)
-        )
-        break
-
-      case ContentDirectoryKnownClasses.VIDEOMEDIAENCODING:
-        await updateVideoMediaEncodingEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<IVideoMediaEncoding>(properties, videoMediaEncodingPropertyNamesWithId)
-        )
-        break
-      case ContentDirectoryKnownClasses.LICENSE:
-        await updateLicenseEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<ILicense>(properties, licensePropertyNamesWithId),
-          entityIdBeforeTransaction
-        )
-        break
-      case ContentDirectoryKnownClasses.MEDIALOCATION:
-        await updateMediaLocationEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<IMediaLocation>(properties, mediaLocationPropertyNamesWithId),
-          entityIdBeforeTransaction
-        )
-        break
-      case ContentDirectoryKnownClasses.FEATUREDVIDEOS:
-        await updateFeaturedVideoEntityPropertyValues(
-          db,
-          where,
-          decode.setEntityPropertyValues<IFeaturedVideo>(properties, featuredVideoPropertyNamesWithId),
-          entityIdBeforeTransaction
-        )
-        break
-
-      default:
-        console.log(`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 './mappings'

+ 26 - 0
query-node/mappings/mappings.ts

@@ -0,0 +1,26 @@
+import { SubstrateEvent } from '@dzlzv/hydra-common'
+import { DatabaseManager } from '@dzlzv/hydra-db-utils'
+
+// eslint-disable-next-line @typescript-eslint/naming-convention
+export async function members_MemberRegistered(db: DatabaseManager, event_: SubstrateEvent): Promise<void> {
+}
+
+// eslint-disable-next-line @typescript-eslint/naming-convention
+export async function members_MemberUpdatedAboutText(db: DatabaseManager, event_: SubstrateEvent): Promise<void> {
+}
+
+// eslint-disable-next-line @typescript-eslint/naming-convention
+export async function members_MemberUpdatedAvatar(db: DatabaseManager, event_: SubstrateEvent): Promise<void> {
+}
+
+// eslint-disable-next-line @typescript-eslint/naming-convention
+export async function members_MemberUpdatedHandle(db: DatabaseManager, event_: SubstrateEvent): Promise<void> {
+}
+
+// eslint-disable-next-line @typescript-eslint/naming-convention
+export async function members_MemberSetRootAccount(db: DatabaseManager, event_: SubstrateEvent): Promise<void> {
+}
+
+// eslint-disable-next-line @typescript-eslint/naming-convention
+export async function members_MemberSetControllerAccount(db: DatabaseManager, event_: SubstrateEvent): Promise<void> {
+}

+ 21 - 0
query-node/mappings/package.json

@@ -0,0 +1,21 @@
+{
+  "name": "query-node-mappings",
+  "version": "0.0.1",
+  "description": "Mappings for hydra-processor",
+  "main": "lib/mappings/index.js",
+  "license": "MIT",
+  "scripts": {
+    "build": "rm -rf lib && tsc --build tsconfig.json",
+    "lint": "echo \"Skippinng\"",
+    "clean": "rm -rf lib"
+  },
+  "dependencies": {
+    "@dzlzv/hydra-common": "0.0.3",
+    "@polkadot/types": "~2.10.2-7",
+    "warthog": "https://github.com/metmirr/warthog/releases/download/v2.23.0/warthog-v2.23.0.tgz"
+  },
+  "devDependencies": {
+    "ts-node": "^9.0.0",
+    "typescript": "^3.8"
+  }
+}

+ 19 - 0
query-node/mappings/tsconfig.json

@@ -0,0 +1,19 @@
+{
+  "compilerOptions": {
+    "declaration": true,
+    "importHelpers": true,
+    "module": "commonjs",
+    "outDir": "lib",
+    "rootDirs": [
+      "./"
+    ],
+    "strict": true,
+    "target": "es2017",
+    "noImplicitAny": false,
+    "esModuleInterop": true,
+    "experimentalDecorators": true,
+    "emitDecoratorMetadata": true,
+    "skipLibCheck": true,    
+  },
+  "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 { DB } from '../generated/indexer'
-
-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
-}

+ 45 - 38
query-node/package.json

@@ -1,42 +1,49 @@
 {
-	"name": "query-node-root",
-	"version": "1.0.0",
-	"description": "GraphQL server and Substrate indexer. Generated with ♥ by Hydra-CLI",
-	"scripts": {
-		"build": "./build.sh",
-		"test": "echo \"Error: no test specified\" && exit 1",
-		"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)",
-		"db:indexer:migrate": "(cd ./generated/indexer && yarn db:migrate)",
-		"codegen:indexer": "yarn hydra-cli codegen --no-install --no-graphql && cp indexer-tsconfig.json generated/indexer/tsconfig.json",
-		"codegen:server": "yarn hydra-cli codegen --no-install --no-indexer",
-		"cd-classes": "ts-node scripts/get-class-id-and-name.ts",
-		"integration-tests": "./run-tests.sh"
-	},
-	"author": "",
-	"license": "ISC",
-	"devDependencies": {
-		"@dzlzv/hydra-cli": "^0.0.24"
-	},
-	"dependencies": {
-		"@dzlzv/hydra-indexer-lib": "^0.0.22-legacy.1.26.1",
-		"@joystream/types": "^0.16.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",
-		"tslib": "^2.0.0"
-	},
-	"volta": {
+  "name": "query-node-root",
+  "version": "0.0.0",
+  "description": "GraphQL server and mappings. Generated with \u2665 by Hydra-CLI",
+  "scripts": {
+    "build": "./build.sh",
+    "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",
+    "clean:query-node": "rm -rf ./generated/graphql-server",
+    "processor:start": "DEBUG=${DEBUG} hydra-processor run -e ../.env",
+    "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",
+    "bootstrap": "yarn codegen && yarn db:drop && yarn db:bootstrap",
+    "codegen": "hydra-cli codegen",
+    "codegen:noinstall": "hydra-cli 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",
+  "dependencies": {
+    "tslib": "^2.0.0",
+    "@types/bn.js": "^4.11.6",
+    "bn.js": "^5.1.2"
+  },
+  "devDependencies": {
+    "@dzlzv/hydra-cli": "2.0.0-beta",
+    "@dzlzv/hydra-processor": "0.1.1",
+    "@dzlzv/hydra-typegen": "0.0.3-1"
+  },
+  "volta": {
 		"extends": "../package.json"
 	}
 }

+ 0 - 15
query-node/processor-start.sh

@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-set -e
-
-SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
-cd $SCRIPT_PATH
-
-# set +a
-# . ../.env
-# export TYPEORM_DATABASE=${PROCESSOR_DB_NAME}
-
-export TYPEORM_DATABASE=${PROCESSOR_DB_NAME:=query_node_processor}
-
-cd ./generated/indexer
-yarn
-DEBUG=${DEBUG} yarn start:processor --env ../../../.env

+ 1 - 1
query-node/run-tests.sh

@@ -23,7 +23,7 @@ function cleanup() {
     # see any possible errors
     (echo "## Processor Logs ##" && docker logs joystream_processor_1 --tail 50) || :
     (echo "## Indexer Logs ##" && docker logs joystream_indexer_1 --tail 50) || :
-    (echo "## Indexer API Gateway Logs ##" && docker logs joystream_indexer-api-gateway_1 --tail 50) || :
+    (echo "## Indexer API Gateway Logs ##" && docker logs joystream_hydra-indexer-gateway_1 --tail 50) || :
     docker-compose down -v
 }
 

+ 0 - 21
query-node/scripts/get-class-id-and-name.ts

@@ -1,21 +0,0 @@
-import { ApiPromise, WsProvider } from '@polkadot/api'
-import { types as joyTypes } from '@joystream/types'
-import * as BN from 'bn.js'
-
-async function main() {
-  // Initialize the api
-  const provider = new WsProvider('ws://127.0.0.1:9944')
-  const api = await ApiPromise.create({ provider, types: joyTypes })
-
-  const n = await api.query.contentDirectory.nextClassId()
-  const nextClassId = new BN(n.toJSON() as string).toNumber()
-  for (let id = 0; id < nextClassId; id++) {
-    const cls = await api.query.contentDirectory.classById(new BN(id))
-    const { name } = cls.toJSON() as never
-    console.log(id, name)
-  }
-}
-
-main()
-  .then(() => process.exit())
-  .catch(console.error)

+ 0 - 23
query-node/tsconfig.json

@@ -1,23 +0,0 @@
-{
-  "compilerOptions": {
-    "declaration": true,
-    "importHelpers": true,
-    "module": "commonjs",
-    "outDir": "lib",
-    "rootDir": "./",
-    "strict": true,
-    "target": "es2017",
-    "experimentalDecorators": true,
-    "emitDecoratorMetadata": true,
-    "skipLibCheck": true,
-    "sourceMap": true,
-    "inlineSources": false,
-    "baseUrl": ".",
-    "paths": {
-      "@polkadot/types/augment": ["../types/augment-codec/augment-types.ts"]
-    },
-    "esModuleInterop": true
-  },
-  "include": ["mappings/**/*"],
-  "exclude": ["node_modules"]
-}

+ 22 - 0
query-node/typegen.yml

@@ -0,0 +1,22 @@
+metadata:
+  source: wss://babylon-sub-1.joystream.app/staging/rpc
+  blockHash: '0x206a6cca31333cb19ee120cde7455e13eea368ec3f6176d0cd48698228410489'
+events:
+  - members.MemberRegistered
+  - members.MemberUpdatedAboutText
+  - members.MemberUpdatedAvatar
+  - members.MemberUpdatedHandle
+  - members.MemberSetRootAccount
+  - members.MemberSetControllerAccount
+calls:
+  - members.buyMembership
+  - members.addScreenedMember
+  - members.changeMemberAboutText
+  - members.changeMemberAvatar
+  - members.changeMemberHandle
+  - members.setRootAccount
+  - members.setControllerAccount
+outDir: ./generated/types
+customTypes:
+  lib: '@joystream/types/augment/all/types'
+  typedefsLoc: '../types/augment/all/defs.json'

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 194 - 352
yarn.lock


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels