Browse Source

query-node: enable hydra-typegen

metmirr 3 years ago
parent
commit
5c9f59c8f0

+ 2 - 2
query-node/build.sh

@@ -13,14 +13,14 @@ yarn clean
 
 # Build graphql-server customizing DB name
 yarn codegen
-# yarn typegen
+yarn typegen
 
 echo "Building mappings..."
 (cd mappings && yarn build)
 echo "Done."
 
 # Copy joy types
-cp ../types/augment/all/defs.json ./mappings/lib/mappings/generated-t/types/typedefs.json
+cp ./mappings/generated/types/typedefs.json ./mappings/lib/mappings/generated/types/typedefs.json
 
 # We run yarn again to ensure processor and indexer dependencies are installed
 # and are inline with root workspace resolutions

+ 3 - 3
query-node/manifest.yml

@@ -10,7 +10,7 @@ entities:
   - mappings/lib/generated/**/*.model.js
 typegen:
   metadata:
-    source: ws://localhost:9944
+    source: wss://staging-3.joystream.app/rpc
   events:
     - contentDirectory.EntityCreated
     - contentDirectory.EntityRemoved
@@ -18,7 +18,7 @@ typegen:
     - contentDirectory.EntityPropertyValuesUpdated
     - contentDirectory.TransactionCompleted
     - contentDirectory.TransactionFailed
-  outDir: ./mappings/generated-t/types
+  outDir: ./mappings/generated/types
   customTypes:
     lib: '@joystream/types/augment/all/types'
     typedefsLoc: '../types/augment/all/defs.json'
@@ -29,7 +29,7 @@ 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-t/types
+    - mappings/lib/mappings/generated/types
   eventHandlers:
     - event: contentDirectory.EntityCreated
       handler: contentDirectory_EntityCreated(DatabaseManager, SubstrateEvent)

+ 0 - 264
query-node/mappings/generated-t/types/content-directory.ts

@@ -1,264 +0,0 @@
-import { createTypeUnsafe } from "@polkadot/types/create";
-import { SubstrateEvent, SubstrateExtrinsic } from "@dzlzv/hydra-common";
-import { Codec } from "@polkadot/types/types";
-import { typeRegistry } from ".";
-
-import {
-  Actor,
-  EntityId,
-  FailedAt,
-  SchemaId,
-  SideEffects
-} from "@joystream/types/augment/all/types";
-
-export namespace ContentDirectory {
-  export class EntityCreatedEvent {
-    public readonly expectedParamTypes = ["Actor", "EntityId"];
-
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get data(): EntityCreated_Params {
-      return new EntityCreated_Params(this.ctx);
-    }
-
-    validateParams(): boolean {
-      if (this.expectedParamTypes.length !== this.ctx.params.length) {
-        return false;
-      }
-      let valid = true;
-      this.expectedParamTypes.forEach((type, i) => {
-        if (type !== this.ctx.params[i].type) {
-          valid = false;
-        }
-      });
-      return valid;
-    }
-  }
-
-  class EntityCreated_Params {
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get actor(): Actor {
-      return createTypeUnsafe<Actor & Codec>(typeRegistry, "Actor", [
-        this.ctx.params[0].value
-      ]);
-    }
-
-    get entityId(): EntityId {
-      return createTypeUnsafe<EntityId & Codec>(typeRegistry, "EntityId", [
-        this.ctx.params[1].value
-      ]);
-    }
-  }
-  export class EntityRemovedEvent {
-    public readonly expectedParamTypes = ["Actor", "EntityId"];
-
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get data(): EntityRemoved_Params {
-      return new EntityRemoved_Params(this.ctx);
-    }
-
-    validateParams(): boolean {
-      if (this.expectedParamTypes.length !== this.ctx.params.length) {
-        return false;
-      }
-      let valid = true;
-      this.expectedParamTypes.forEach((type, i) => {
-        if (type !== this.ctx.params[i].type) {
-          valid = false;
-        }
-      });
-      return valid;
-    }
-  }
-
-  class EntityRemoved_Params {
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get actor(): Actor {
-      return createTypeUnsafe<Actor & Codec>(typeRegistry, "Actor", [
-        this.ctx.params[0].value
-      ]);
-    }
-
-    get entityId(): EntityId {
-      return createTypeUnsafe<EntityId & Codec>(typeRegistry, "EntityId", [
-        this.ctx.params[1].value
-      ]);
-    }
-  }
-  export class EntitySchemaSupportAddedEvent {
-    public readonly expectedParamTypes = [
-      "Actor",
-      "EntityId",
-      "SchemaId",
-      "SideEffects"
-    ];
-
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get data(): EntitySchemaSupportAdded_Params {
-      return new EntitySchemaSupportAdded_Params(this.ctx);
-    }
-
-    validateParams(): boolean {
-      if (this.expectedParamTypes.length !== this.ctx.params.length) {
-        return false;
-      }
-      let valid = true;
-      this.expectedParamTypes.forEach((type, i) => {
-        if (type !== this.ctx.params[i].type) {
-          valid = false;
-        }
-      });
-      return valid;
-    }
-  }
-
-  class EntitySchemaSupportAdded_Params {
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get actor(): Actor {
-      return createTypeUnsafe<Actor & Codec>(typeRegistry, "Actor", [
-        this.ctx.params[0].value
-      ]);
-    }
-
-    get entityId(): EntityId {
-      return createTypeUnsafe<EntityId & Codec>(typeRegistry, "EntityId", [
-        this.ctx.params[1].value
-      ]);
-    }
-
-    get schemaId(): SchemaId {
-      return createTypeUnsafe<SchemaId & Codec>(typeRegistry, "SchemaId", [
-        this.ctx.params[2].value
-      ]);
-    }
-
-    get sideEffects(): SideEffects {
-      return createTypeUnsafe<SideEffects & Codec>(
-        typeRegistry,
-        "SideEffects",
-        [this.ctx.params[3].value]
-      );
-    }
-  }
-  export class EntityPropertyValuesUpdatedEvent {
-    public readonly expectedParamTypes = ["Actor", "EntityId", "SideEffects"];
-
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get data(): EntityPropertyValuesUpdated_Params {
-      return new EntityPropertyValuesUpdated_Params(this.ctx);
-    }
-
-    validateParams(): boolean {
-      if (this.expectedParamTypes.length !== this.ctx.params.length) {
-        return false;
-      }
-      let valid = true;
-      this.expectedParamTypes.forEach((type, i) => {
-        if (type !== this.ctx.params[i].type) {
-          valid = false;
-        }
-      });
-      return valid;
-    }
-  }
-
-  class EntityPropertyValuesUpdated_Params {
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get actor(): Actor {
-      return createTypeUnsafe<Actor & Codec>(typeRegistry, "Actor", [
-        this.ctx.params[0].value
-      ]);
-    }
-
-    get entityId(): EntityId {
-      return createTypeUnsafe<EntityId & Codec>(typeRegistry, "EntityId", [
-        this.ctx.params[1].value
-      ]);
-    }
-
-    get sideEffects(): SideEffects {
-      return createTypeUnsafe<SideEffects & Codec>(
-        typeRegistry,
-        "SideEffects",
-        [this.ctx.params[2].value]
-      );
-    }
-  }
-  export class TransactionCompletedEvent {
-    public readonly expectedParamTypes = ["Actor"];
-
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get data(): TransactionCompleted_Params {
-      return new TransactionCompleted_Params(this.ctx);
-    }
-
-    validateParams(): boolean {
-      if (this.expectedParamTypes.length !== this.ctx.params.length) {
-        return false;
-      }
-      let valid = true;
-      this.expectedParamTypes.forEach((type, i) => {
-        if (type !== this.ctx.params[i].type) {
-          valid = false;
-        }
-      });
-      return valid;
-    }
-  }
-
-  class TransactionCompleted_Params {
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get actor(): Actor {
-      return createTypeUnsafe<Actor & Codec>(typeRegistry, "Actor", [
-        this.ctx.params[0].value
-      ]);
-    }
-  }
-  export class TransactionFailedEvent {
-    public readonly expectedParamTypes = ["Actor", "FailedAt"];
-
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get data(): TransactionFailed_Params {
-      return new TransactionFailed_Params(this.ctx);
-    }
-
-    validateParams(): boolean {
-      if (this.expectedParamTypes.length !== this.ctx.params.length) {
-        return false;
-      }
-      let valid = true;
-      this.expectedParamTypes.forEach((type, i) => {
-        if (type !== this.ctx.params[i].type) {
-          valid = false;
-        }
-      });
-      return valid;
-    }
-  }
-
-  class TransactionFailed_Params {
-    constructor(public readonly ctx: SubstrateEvent) {}
-
-    get actor(): Actor {
-      return createTypeUnsafe<Actor & Codec>(typeRegistry, "Actor", [
-        this.ctx.params[0].value
-      ]);
-    }
-
-    get failedAt(): FailedAt {
-      return createTypeUnsafe<FailedAt & Codec>(typeRegistry, "FailedAt", [
-        this.ctx.params[1].value
-      ]);
-    }
-  }
-}

+ 0 - 12
query-node/mappings/generated-t/types/index.ts

@@ -1,12 +0,0 @@
-import { TypeRegistry } from "@polkadot/types";
-import path from "path";
-import fs from "fs";
-const typeRegistry = new TypeRegistry();
-
-typeRegistry.register(
-  JSON.parse(fs.readFileSync(path.join(__dirname, "typedefs.json"), "utf-8"))
-);
-
-export { typeRegistry };
-
-export * from "./content-directory";

+ 1 - 1
query-node/package.json

@@ -18,7 +18,7 @@
     "codegen": "hydra-cli codegen",
     "codegen:noinstall": "hydra-cli codegen --no-install",
     "integration-tests": "./run-tests.sh",
-    "typegen": "rm -rf ./mappings/generated-t/ && hydra-typegen typegen manifest.yml --debug",
+    "typegen": "rm -rf ./mappings/generated/ && hydra-typegen typegen manifest.yml --debug",
     "db:init": "(cd ./generated/graphql-server && TYPEORM_LOGGING=true ts-node ../../scripts/initializeDefaultSchemas.ts)"
   },
   "author": "",