Types.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import { Codec } from '@polkadot/types/types'
  2. import { Balance, AccountId } from '@polkadot/types/interfaces'
  3. import { DeriveBalancesAll } from '@polkadot/api-derive/types'
  4. import { KeyringPair } from '@polkadot/keyring/types'
  5. import { WorkerId, OpeningType } from '@joystream/types/working-group'
  6. import { Membership } from '@joystream/types/members'
  7. import { MemberId } from '@joystream/types/common'
  8. import { Validator } from 'inquirer'
  9. import { ApiPromise } from '@polkadot/api'
  10. import { SubmittableModuleExtrinsics, QueryableModuleStorage, QueryableModuleConsts } from '@polkadot/api/types'
  11. import { ContentId, ContentParameters } from '@joystream/types/storage'
  12. import { JSONSchema7, JSONSchema7Definition } from 'json-schema'
  13. import {
  14. IChannelMetadata,
  15. IVideoMetadata,
  16. IVideoCategoryMetadata,
  17. IChannelCategoryMetadata,
  18. } from '@joystream/metadata-protobuf'
  19. // KeyringPair type extended with mandatory "meta.name"
  20. // It's used for accounts/keys management within CLI.
  21. // If not provided in the account json file, the meta.name value is set to "Unnamed Account"
  22. export type NamedKeyringPair = KeyringPair & {
  23. meta: {
  24. name: string
  25. }
  26. }
  27. // Summary of the account information fetched from the api for "account:current" purposes (currently just balances)
  28. export type AccountSummary = {
  29. balances: DeriveBalancesAll
  30. }
  31. // Object with "name" and "value" properties, used for rendering simple CLI tables like:
  32. // Total balance: 100 JOY
  33. // Free calance: 50 JOY
  34. export type NameValueObj = { name: string; value: string }
  35. // Working groups related types
  36. export enum WorkingGroups {
  37. StorageProviders = 'storageProviders',
  38. Curators = 'curators',
  39. Forum = 'forum',
  40. Membership = 'membership',
  41. Operations = 'operations',
  42. Gateway = 'gateway',
  43. }
  44. // In contrast to Pioneer, currently only StorageProviders group is available in CLI
  45. export const AvailableGroups: readonly WorkingGroups[] = [
  46. WorkingGroups.StorageProviders,
  47. WorkingGroups.Curators,
  48. WorkingGroups.Forum,
  49. WorkingGroups.Membership,
  50. WorkingGroups.Operations,
  51. WorkingGroups.Gateway,
  52. ] as const
  53. export type Reward = {
  54. totalMissed?: Balance
  55. valuePerBlock?: Balance
  56. }
  57. // Compound working group types
  58. export type GroupMember = {
  59. workerId: WorkerId
  60. memberId: MemberId
  61. roleAccount: AccountId
  62. stakingAccount: AccountId
  63. profile: MemberDetails
  64. stake: Balance
  65. reward: Reward
  66. }
  67. export type ApplicationDetails = {
  68. applicationId: number
  69. member: MemberDetails
  70. roleAccout: AccountId
  71. stakingAccount: AccountId
  72. rewardAccount: AccountId
  73. descriptionHash: string
  74. openingId: number
  75. }
  76. export type OpeningDetails = {
  77. openingId: number
  78. stake: {
  79. value: Balance
  80. unstakingPeriod: number
  81. }
  82. applications: ApplicationDetails[]
  83. type: OpeningType
  84. createdAtBlock: number
  85. rewardPerBlock?: Balance
  86. }
  87. // Extended membership information (including optional query node data)
  88. export type MemberDetails = {
  89. id: MemberId
  90. name?: string | null
  91. handle?: string
  92. membership: Membership
  93. }
  94. // Api-related
  95. // Additional options that can be passed to ApiCommandBase.promptForParam in order to override
  96. // its default behaviour, change param name, add validation etc.
  97. export type ApiParamOptions<ParamType = Codec> = {
  98. forcedName?: string
  99. value?: {
  100. default: ParamType
  101. locked?: boolean
  102. }
  103. validator?: Validator
  104. nestedOptions?: ApiParamsOptions // For more complex params, like structs
  105. }
  106. export type ApiParamsOptions = {
  107. [paramName: string]: ApiParamOptions
  108. }
  109. export type ApiMethodArg = Codec
  110. export type ApiMethodNamedArg = {
  111. name: string
  112. value: ApiMethodArg
  113. }
  114. export type ApiMethodNamedArgs = ApiMethodNamedArg[]
  115. // Api without TypeScript augmentations for "query", "tx" and "consts" (useful when more type flexibility is needed)
  116. export type UnaugmentedApiPromise = Omit<ApiPromise, 'query' | 'tx' | 'consts'> & {
  117. query: { [key: string]: QueryableModuleStorage<'promise'> }
  118. tx: { [key: string]: SubmittableModuleExtrinsics<'promise'> }
  119. consts: { [key: string]: QueryableModuleConsts }
  120. }
  121. // Content-related
  122. export enum AssetType {
  123. AnyAsset = 1,
  124. }
  125. export type InputAsset = {
  126. path: string
  127. contentId: ContentId
  128. }
  129. export type InputAssetDetails = InputAsset & {
  130. parameters: ContentParameters
  131. }
  132. export type VideoFFProbeMetadata = {
  133. width?: number
  134. height?: number
  135. codecName?: string
  136. codecFullName?: string
  137. duration?: number
  138. }
  139. export type VideoFileMetadata = VideoFFProbeMetadata & {
  140. size: number
  141. container: string
  142. mimeType: string
  143. }
  144. export type VideoInputParameters = Omit<IVideoMetadata, 'video' | 'thumbnailPhoto'> & {
  145. videoPath?: string
  146. thumbnailPhotoPath?: string
  147. }
  148. export type ChannelInputParameters = Omit<IChannelMetadata, 'coverPhoto' | 'avatarPhoto'> & {
  149. coverPhotoPath?: string
  150. avatarPhotoPath?: string
  151. rewardAccount?: string
  152. }
  153. export type ChannelCategoryInputParameters = IChannelCategoryMetadata
  154. export type VideoCategoryInputParameters = IVideoCategoryMetadata
  155. type AnyNonObject = string | number | boolean | any[] | Long
  156. // JSONSchema utility types
  157. export type JSONTypeName<T> = T extends string
  158. ? 'string' | ['string', 'null']
  159. : T extends number
  160. ? 'number' | ['number', 'null']
  161. : T extends boolean
  162. ? 'boolean' | ['boolean', 'null']
  163. : T extends any[]
  164. ? 'array' | ['array', 'null']
  165. : T extends Long
  166. ? 'number' | ['number', 'null']
  167. : 'object' | ['object', 'null']
  168. export type PropertySchema<P> = Omit<
  169. JSONSchema7Definition & {
  170. type: JSONTypeName<P>
  171. properties: P extends AnyNonObject ? never : JsonSchemaProperties<P>
  172. },
  173. P extends AnyNonObject ? 'properties' : ''
  174. >
  175. export type JsonSchemaProperties<T> = {
  176. [K in keyof Required<T>]: PropertySchema<Required<T>[K]>
  177. }
  178. export type JsonSchema<T> = JSONSchema7 & {
  179. type: 'object'
  180. properties: JsonSchemaProperties<T>
  181. }