瀏覽代碼

query node - NFT mappings lint fixes

ondratra 3 年之前
父節點
當前提交
3a5b96db48

+ 1 - 2
query-node/codegen/package.json

@@ -4,8 +4,7 @@
   "description": "Hydra codegen tools for Joystream Query Node",
   "author": "",
   "license": "ISC",
-  "scripts": {
-  },
+  "scripts": {},
   "dependencies": {
     "@joystream/hydra-cli": "3.1.0-alpha.16",
     "@joystream/hydra-typegen": "3.1.0-alpha.16"

+ 7 - 6
query-node/mappings/.eslintrc.js

@@ -8,15 +8,16 @@ module.exports = {
     // TODO: Remove all the rules below, they seem quite useful
     '@typescript-eslint/no-explicit-any': 'off',
     '@typescript-eslint/no-non-null-assertion': 'off',
-    '@typescript-eslint/ban-types': ["error",
+    '@typescript-eslint/ban-types': [
+      'error',
       {
-        "types": {
+        'types': {
           // enable usage of `Object` data type in TS; it has it's meaning(!) and it's disabled
           // by default only beacuse people tend to misuse it
-          "Object": false,
+          'Object': false,
         },
-        "extendDefaults": true
-      }
-    ]
+        'extendDefaults': true,
+      },
+    ],
   },
 }

+ 68 - 30
query-node/mappings/src/content/nft.ts

@@ -136,7 +136,7 @@ async function resetNftTransactionalStatusFromVideo(
   videoId: string,
   errorMessage: string,
   blockNumber: number,
-  newOwner?: Membership,
+  newOwner?: Membership
 ) {
   // load NFT
   const nft = await store.get(OwnedNft, { where: { id: videoId.toString() } as FindConditions<OwnedNft> })
@@ -224,7 +224,12 @@ async function convertContentActor(
   throw new Error('Not-implemented ContentActor type used')
 }
 
-async function setNewNftTransactionalStatus(store: DatabaseManager, nft: OwnedNft, transactionalStatus: typeof TransactionalStatus, blockNumber: number) {
+async function setNewNftTransactionalStatus(
+  store: DatabaseManager,
+  nft: OwnedNft,
+  transactionalStatus: typeof TransactionalStatus,
+  blockNumber: number
+) {
   // update transactionalStatus
   nft.transactionalStatus = transactionalStatus
 
@@ -262,7 +267,13 @@ async function finishAuction(store: DatabaseManager, videoId: number, blockNumbe
   )
 
   // update NFT's transactional status
-  await resetNftTransactionalStatusFromVideo(store, videoId.toString(), `Non-existing NFT's auction completed`, blockNumber, winner)
+  await resetNftTransactionalStatusFromVideo(
+    store,
+    videoId.toString(),
+    `Non-existing NFT's auction completed`,
+    blockNumber,
+    winner
+  )
 
   // update auction
   auction.isCompleted = true
@@ -325,7 +336,7 @@ export async function createNft(
   store: DatabaseManager,
   video: Video,
   nftIssuanceParameters: joystreamTypes.NftIssuanceParameters,
-  blockNumber: number,
+  blockNumber: number
 ): Promise<OwnedNft> {
   // load owner
   const ownerMember = nftIssuanceParameters.non_channel_owner.isSome
@@ -333,7 +344,9 @@ export async function createNft(
     : undefined
 
   // calculate some values
-  const creatorRoyalty = nftIssuanceParameters.royalty.isSome ? nftIssuanceParameters.royalty.unwrap().toNumber() : undefined
+  const creatorRoyalty = nftIssuanceParameters.royalty.isSome
+    ? nftIssuanceParameters.royalty.unwrap().toNumber()
+    : undefined
   const decodedMetadata = nftIssuanceParameters.nft_metadata.toString()
 
   // prepare nft record
@@ -351,7 +364,12 @@ export async function createNft(
   await store.save<OwnedNft>(nft)
 
   // update NFT transactional status
-  const transactionalStatus = await convertTransactionalStatus(nftIssuanceParameters.init_transactional_status, store, nft, blockNumber)
+  const transactionalStatus = await convertTransactionalStatus(
+    nftIssuanceParameters.init_transactional_status,
+    store,
+    nft,
+    blockNumber
+  )
   await setNewNftTransactionalStatus(store, nft, transactionalStatus, blockNumber)
 
   return nft
@@ -397,7 +415,7 @@ export async function convertTransactionalStatus(
   transactionalStatus: joystreamTypes.InitTransactionalStatus,
   store: DatabaseManager,
   nft: OwnedNft,
-  blockNumber: number,
+  blockNumber: number
 ): Promise<typeof TransactionalStatus> {
   if (transactionalStatus.isIdle) {
     return new TransactionalStatusIdle()
@@ -493,9 +511,7 @@ function createAuctionType(rawAuctionType: joystreamTypes.AuctionType): typeof A
 export async function contentNft_NftIssued({ event, store }: EventContext & StoreContext): Promise<void> {
   // common event processing
 
-  const [actor, videoId, nftIssuanceParameters] = new Content.NftIssuedEvent(
-    event
-  ).params
+  const [actor, videoId, nftIssuanceParameters] = new Content.NftIssuedEvent(event).params
 
   // specific event processing
 
@@ -604,7 +620,12 @@ export async function contentNft_AuctionCanceled({ event, store }: EventContext
   )
 
   // update NFT's transactional status
-  await resetNftTransactionalStatusFromVideo(store, videoId.toString(), `Non-existing NFT's auction canceled`, event.blockNumber)
+  await resetNftTransactionalStatusFromVideo(
+    store,
+    videoId.toString(),
+    `Non-existing NFT's auction canceled`,
+    event.blockNumber
+  )
 
   // mark auction as canceled
   auction.isCanceled = true
@@ -751,7 +772,13 @@ export async function contentNft_OfferAccepted({ event, store }: EventContext &
   const member = new Membership({ id: memberId.toString() })
 
   // update NFT's transactional status
-  await resetNftTransactionalStatusFromVideo(store, videoId.toString(), `Non-existing NFT's offer accepted`, event.blockNumber, member)
+  await resetNftTransactionalStatusFromVideo(
+    store,
+    videoId.toString(),
+    `Non-existing NFT's offer accepted`,
+    event.blockNumber,
+    member
+  )
 
   // common event processing - second
 
@@ -771,16 +798,21 @@ export async function contentNft_OfferCanceled({ event, store }: EventContext &
 
   // specific event processing
 
-  // load NFT
-  const { video, nft } = await getNftFromVideo(
+  // load video
+  const video = await getRequiredExistingEntity(
     store,
+    Video,
     videoId.toString(),
-    'Non-existing video sell offer was canceled',
-    'Non-existing nft sell offer was canceled'
+    'Non-existing video sell offer was canceled'
   )
 
   // update NFT's transactional status
-  await resetNftTransactionalStatusFromVideo(store, videoId.toString(), `Non-existing NFT's offer canceled`, event.blockNumber)
+  await resetNftTransactionalStatusFromVideo(
+    store,
+    videoId.toString(),
+    `Non-existing NFT's offer canceled`,
+    event.blockNumber
+  )
 
   // common event processing - second
 
@@ -834,19 +866,20 @@ export async function contentNft_NftBought({ event, store }: EventContext & Stor
 
   // specific event processing
 
-  // load NFT
-  const { video } = await getNftFromVideo(
-    store,
-    videoId.toString(),
-    'Non-existing video was bought',
-    'Non-existing nft was bought'
-  )
+  // load video
+  const video = await getRequiredExistingEntity(store, Video, videoId.toString(), 'Non-existing video was bought')
 
   // read member
   const winner = new Membership({ id: memberId.toString() })
 
   // update NFT's transactional status
-  await resetNftTransactionalStatusFromVideo(store, videoId.toString(), `Non-existing NFT's auction completed`, event.blockNumber, winner)
+  await resetNftTransactionalStatusFromVideo(
+    store,
+    videoId.toString(),
+    `Non-existing NFT's auction completed`,
+    event.blockNumber,
+    winner
+  )
 
   // common event processing - second
 
@@ -867,15 +900,20 @@ export async function contentNft_BuyNowCanceled({ event, store }: EventContext &
 
   // specific event processing
 
-  // load NFT
-  const { video, nft } = await getNftFromVideo(
+  // load video
+  const video = await getRequiredExistingEntity(
     store,
+    Video,
     videoId.toString(),
-    'Non-existing video was bought',
-    'Non-existing nft was bought'
+    'Non-existing video buy-now was canceled'
   )
 
-  await resetNftTransactionalStatusFromVideo(store, videoId.toString(), `Non-existing NFT's buy-now canceled`, event.blockNumber)
+  await resetNftTransactionalStatusFromVideo(
+    store,
+    videoId.toString(),
+    `Non-existing NFT's buy-now canceled`,
+    event.blockNumber
+  )
 
   // common event processing - second
 

+ 2 - 2
query-node/mappings/src/content/video.ts

@@ -12,11 +12,11 @@ import {
   videoRelationsForCountersBare,
   videoRelationsForCounters,
 } from './utils'
-import { Channel, OwnedNft, Video, VideoCategory } from 'query-node/dist/model'
+import { Channel, Video, VideoCategory } from 'query-node/dist/model'
 import { VideoMetadata, VideoCategoryMetadata } from '@joystream/metadata-protobuf'
 import { integrateMeta } from '@joystream/metadata-protobuf/utils'
 import _ from 'lodash'
-import { createNft, convertTransactionalStatus } from './nft'
+import { createNft } from './nft'
 
 export async function content_VideoCategoryCreated({ store, event }: EventContext & StoreContext): Promise<void> {
   // read event data

+ 4 - 2
query-node/schemas/contentNft.graphql

@@ -55,7 +55,8 @@ type Curator @entity {
 }
 
 "Represents NFT details"
-type OwnedNft @entity { # NFT in name can't be UPPERCASE because it causes codegen errors
+type OwnedNft
+  @entity { # NFT in name can't be UPPERCASE because it causes codegen errors
   "NFT's video"
   video: Video! @derivedFrom(field: "nft")
 
@@ -90,7 +91,8 @@ type TransactionalStatusUpdate @entity {
 }
 
 "NFT transactional state"
-union TransactionalStatus = TransactionalStatusIdle
+union TransactionalStatus =
+    TransactionalStatusIdle
   | TransactionalStatusInitiatedOfferToMember
   | TransactionalStatusAuction
   | TransactionalStatusBuyNow

+ 1 - 1
query-node/schemas/contentNftEvents.graphql

@@ -317,7 +317,7 @@ type OfferCanceledEvent implements Event @entity {
   contentActor: ContentActor!
 }
 
-type NftSellOrderMadeEvent @entity { # NFT in name can't be UPPERCASE because it causes codegenimplements Event  errors
+type NftSellOrderMadeEvent @entity {
   ### GENERIC DATA ###
 
   "(network}-{blockNumber}-{indexInBlock}."

+ 17 - 4
query-node/schemas/storage.graphql

@@ -38,7 +38,10 @@ type StorageBucketOperatorStatusActive @variant {
   transactorAccountId: String!
 }
 
-union StorageBucketOperatorStatus = StorageBucketOperatorStatusMissing | StorageBucketOperatorStatusInvited | StorageBucketOperatorStatusActive
+union StorageBucketOperatorStatus =
+    StorageBucketOperatorStatusMissing
+  | StorageBucketOperatorStatusInvited
+  | StorageBucketOperatorStatusActive
 
 type GeoCoordinates @entity {
   latitude: Float!
@@ -143,7 +146,12 @@ type StorageBagOwnerDAO @variant {
   daoId: Int
 }
 
-union StorageBagOwner = StorageBagOwnerCouncil | StorageBagOwnerWorkingGroup | StorageBagOwnerMember | StorageBagOwnerChannel | StorageBagOwnerDAO
+union StorageBagOwner =
+    StorageBagOwnerCouncil
+  | StorageBagOwnerWorkingGroup
+  | StorageBagOwnerMember
+  | StorageBagOwnerChannel
+  | StorageBagOwnerDAO
 
 type StorageBag @entity {
   "Storage bag id"
@@ -186,7 +194,12 @@ type DataObjectTypeUnknown @variant {
   _phantom: Int
 }
 
-union DataObjectType = DataObjectTypeChannelAvatar | DataObjectTypeChannelCoverPhoto | DataObjectTypeVideoMedia | DataObjectTypeVideoThumbnail | DataObjectTypeUnknown
+union DataObjectType =
+    DataObjectTypeChannelAvatar
+  | DataObjectTypeChannelCoverPhoto
+  | DataObjectTypeVideoMedia
+  | DataObjectTypeVideoThumbnail
+  | DataObjectTypeUnknown
 
 type StorageDataObject @entity {
   "Data object runtime id"
@@ -258,7 +271,7 @@ type DistributionBucketOperatorMetadata @entity {
 }
 
 enum DistributionBucketOperatorStatus {
-  INVITED,
+  INVITED
   ACTIVE
 }