Browse Source

Merge branch 'giza' into distributor-node

Leszek Wiesner 3 years ago
parent
commit
b01f67aca8

+ 2 - 5
query-node/build.sh

@@ -16,11 +16,8 @@ yarn clean
 yarn codegen:noinstall
 yarn typegen # if this fails try to run this command outside of yarn workspaces
 
-# TS4 useUnknownInCatchVariables is not compatible with auto-generated code
-sed -i '/\"compilerOptions\"\:\ {/a \ \ \ \ "useUnknownInCatchVariables": false,' ./generated/graphql-server/tsconfig.json
-# Type assertions are no longer needed for createTypeUnsafe in @polkadot/api 5.9.1 (and they break the build)
-# Here we're relpacing createTypeUnsafe<Assertions>(...params) to createTypeUnsafe(...params) in all generated types:
-find ./mappings/generated -type f -print0 | xargs -0 sed -ri 's/createTypeUnsafe<[^(]+[(]/createTypeUnsafe(/g'
+# Post-codegen - fixes in autogenerated files
+yarn ts-node --project ./mappings/tsconfig.json ./mappings/scripts/postCodegen.ts
 
 # We run yarn again to ensure graphql-server dependencies are installed
 # and are inline with root workspace resolutions

+ 20 - 0
query-node/mappings/scripts/postCodegen.ts

@@ -0,0 +1,20 @@
+// A script to be executed post hydra codegen, that may include modifications to autogenerated files
+import fs from 'fs'
+import path from 'path'
+
+// TS4 useUnknownInCatchVariables is not compatible with auto-generated code inside generated/graphql-server
+const serverTsConfigPath = path.resolve(__dirname, '../../generated/graphql-server/tsconfig.json')
+const serverTsConfig = JSON.parse(fs.readFileSync(serverTsConfigPath).toString())
+serverTsConfig.compilerOptions.useUnknownInCatchVariables = false
+fs.writeFileSync(serverTsConfigPath, JSON.stringify(serverTsConfig, undefined, 2))
+
+// Type assertions are no longer needed for createTypeUnsafe in @polkadot/api 5.9.1 (and they break the build)
+// Here we're relpacing createTypeUnsafe<Assertions>(...params) to createTypeUnsafe(...params) in all generated types:
+const generatedTypesPaths = path.resolve(__dirname, '../generated/types')
+fs.readdirSync(generatedTypesPaths).map((fileName) => {
+  if (path.extname(fileName) === '.ts') {
+    const filePath = path.join(generatedTypesPaths, fileName)
+    const fileContent = fs.readFileSync(filePath).toString()
+    fs.writeFileSync(filePath, fileContent.replace(/createTypeUnsafe<[^(]+[(]/g, 'createTypeUnsafe('))
+  }
+})

+ 0 - 4
types/augment-codec/augment-api-consts.ts

@@ -217,10 +217,6 @@ declare module '@polkadot/api/types/consts' {
        * Exports const - max allowed distribution bucket number per family.
        **/
       maxDistributionBucketNumberPerFamily: u64 & AugmentedConst<ApiType>;
-      /**
-       * Exports const - max number of data objects per bag.
-       **/
-      maxNumberOfDataObjectsPerBag: u64 & AugmentedConst<ApiType>;
       /**
        * Exports const - max number of pending invitations per distribution bucket.
        **/

+ 0 - 4
types/augment-codec/augment-api-errors.ts

@@ -3039,10 +3039,6 @@ declare module '@polkadot/api/types/errors' {
        * The `data_object_ids` extrinsic parameter collection is empty.
        **/
       DataObjectIdParamsAreEmpty: AugmentedError<ApiType>;
-      /**
-       * Upload data error: data objects per bag limit exceeded.
-       **/
-      DataObjectsPerBagLimitExceeded: AugmentedError<ApiType>;
       /**
        * Invalid extrinsic call: data size fee changed.
        **/

+ 5 - 4
types/augment/all/defs.json

@@ -522,10 +522,11 @@
         "prize": "u128"
     },
     "Bag": {
-        "objects": "BTreeMap<DataObjectId,DataObject>",
-        "stored_by": "StorageBucketIdSet",
-        "distributed_by": "DistributionBucketIdSet",
-        "deletion_prize": "Option<u128>"
+        "stored_by": "BTreeSet<StorageBucketId>",
+        "distributed_by": "BTreeSet<DistributionBucketId>",
+        "deletion_prize": "Option<u128>",
+        "objects_total_size": "u64",
+        "objects_number": "u64"
     },
     "StorageBucket": {
         "operator_status": "StorageBucketOperatorStatus",

+ 4 - 3
types/augment/all/types.ts

@@ -154,10 +154,11 @@ export interface Backers extends Vec<Backer> {}
 
 /** @name Bag */
 export interface Bag extends Struct {
-  readonly objects: BTreeMap<DataObjectId, DataObject>;
-  readonly stored_by: StorageBucketIdSet;
-  readonly distributed_by: DistributionBucketIdSet;
+  readonly stored_by: BTreeSet<StorageBucketId>;
+  readonly distributed_by: BTreeSet<DistributionBucketId>;
   readonly deletion_prize: Option<u128>;
+  readonly objects_total_size: u64;
+  readonly objects_number: u64;
 }
 
 /** @name BagId */

+ 0 - 4
types/augment/augment-api-consts.ts

@@ -217,10 +217,6 @@ declare module '@polkadot/api/types/consts' {
        * Exports const - max allowed distribution bucket number per family.
        **/
       maxDistributionBucketNumberPerFamily: u64 & AugmentedConst<ApiType>;
-      /**
-       * Exports const - max number of data objects per bag.
-       **/
-      maxNumberOfDataObjectsPerBag: u64 & AugmentedConst<ApiType>;
       /**
        * Exports const - max number of pending invitations per distribution bucket.
        **/

+ 0 - 4
types/augment/augment-api-errors.ts

@@ -3039,10 +3039,6 @@ declare module '@polkadot/api/types/errors' {
        * The `data_object_ids` extrinsic parameter collection is empty.
        **/
       DataObjectIdParamsAreEmpty: AugmentedError<ApiType>;
-      /**
-       * Upload data error: data objects per bag limit exceeded.
-       **/
-      DataObjectsPerBagLimitExceeded: AugmentedError<ApiType>;
       /**
        * Invalid extrinsic call: data size fee changed.
        **/

+ 12 - 8
types/src/storage.ts

@@ -9,7 +9,9 @@ import {
   BTreeMap,
   Option,
   u32,
+  u128,
 } from '@polkadot/types'
+import { Balance } from '@polkadot/types/interfaces'
 import { RegistryTypes } from '@polkadot/types/types'
 import { JoyEnum, JoyStructDecorated, WorkingGroup, BalanceOf } from './common'
 import { MemberId } from './members'
@@ -68,18 +70,20 @@ export class DynamicBagDeletionPrize
 export class DynamicBagDeletionPrizeRecord extends DynamicBagDeletionPrize {}
 
 export type IBag = {
-  objects: BTreeMap<DataObjectId, DataObject>
-  stored_by: StorageBucketIdSet
-  distributed_by: DistributionBucketIdSet
-  deletion_prize: Option<BalanceOf>
+  stored_by: BTreeSet<StorageBucketId>
+  distributed_by: BTreeSet<DistributionBucketId>
+  deletion_prize: Option<Balance>
+  objects_total_size: u64
+  objects_number: u64
 }
 
 export class Bag
   extends JoyStructDecorated({
-    objects: BTreeMap.with(DataObjectId, DataObject),
-    stored_by: StorageBucketIdSet,
-    distributed_by: DistributionBucketIdSet,
-    deletion_prize: Option.with(BalanceOf),
+    stored_by: BTreeSet.with(StorageBucketId),
+    distributed_by: BTreeSet.with(DistributionBucketId),
+    deletion_prize: Option.with(u128),
+    objects_total_size: u64,
+    objects_number: u64,
   })
   implements IBag {}