Rename decorator cosmosMessage -> registered
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
import { Message } from "protobufjs";
|
import { Message } from "protobufjs";
|
||||||
|
|
||||||
import { cosmosField, cosmosMessage } from "./decorator";
|
import { cosmosField, registered } from "./decorator";
|
||||||
import { defaultRegistry } from "./msgs";
|
import { defaultRegistry } from "./msgs";
|
||||||
|
|
||||||
@cosmosMessage(defaultRegistry, "/cosmos.auth.BaseAccount")
|
@registered(defaultRegistry, "/cosmos.auth.BaseAccount")
|
||||||
export class BaseAccount extends Message {
|
export class BaseAccount extends Message {
|
||||||
@cosmosField.bytes(1)
|
@cosmosField.bytes(1)
|
||||||
public readonly address?: Uint8Array;
|
public readonly address?: Uint8Array;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { assert } from "@cosmjs/utils";
|
import { assert } from "@cosmjs/utils";
|
||||||
import { Message } from "protobufjs";
|
import { Message } from "protobufjs";
|
||||||
|
|
||||||
import { cosmosField, cosmosMessage } from "./decorator";
|
import { cosmosField, registered } from "./decorator";
|
||||||
import { cosmos, google } from "./generated/codecimpl";
|
import { cosmos, google } from "./generated/codecimpl";
|
||||||
import { Registry } from "./registry";
|
import { Registry } from "./registry";
|
||||||
|
|
||||||
@@ -15,13 +15,13 @@ describe("decorator demo", () => {
|
|||||||
const typeUrl = "/demo.MsgDemo";
|
const typeUrl = "/demo.MsgDemo";
|
||||||
const myRegistry = new Registry();
|
const myRegistry = new Registry();
|
||||||
|
|
||||||
@cosmosMessage(myRegistry, nestedTypeUrl)
|
@registered(myRegistry, nestedTypeUrl)
|
||||||
class MsgNestedDemo extends Message {
|
class MsgNestedDemo extends Message {
|
||||||
@cosmosField.string(1)
|
@cosmosField.string(1)
|
||||||
public readonly foo?: string;
|
public readonly foo?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@cosmosMessage(myRegistry, typeUrl)
|
@registered(myRegistry, typeUrl)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
class MsgDemo extends Message {
|
class MsgDemo extends Message {
|
||||||
@cosmosField.boolean(1)
|
@cosmosField.boolean(1)
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ function getTypeName(typeUrl: string): string {
|
|||||||
return parts[parts.length - 1];
|
return parts[parts.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function cosmosMessage(registry: Registry, typeUrl: string): TypeDecorator<any> {
|
/**
|
||||||
|
* A class decorator to register this type under the given type URL
|
||||||
|
* in the given registry.
|
||||||
|
*/
|
||||||
|
export function registered(registry: Registry, typeUrl: string): TypeDecorator<any> {
|
||||||
return (ctor: Constructor<Message<any>>) => {
|
return (ctor: Constructor<Message<any>>) => {
|
||||||
const typeName = getTypeName(typeUrl);
|
const typeName = getTypeName(typeUrl);
|
||||||
const generatedType = util.decorateType(ctor, typeName);
|
const generatedType = util.decorateType(ctor, typeName);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
import { Message } from "protobufjs";
|
import { Message } from "protobufjs";
|
||||||
|
|
||||||
import { cosmosField, cosmosMessage } from "./decorator";
|
import { cosmosField, registered } from "./decorator";
|
||||||
import { Registry } from "./registry";
|
import { Registry } from "./registry";
|
||||||
|
|
||||||
describe("registry magic demo", () => {
|
describe("registry magic demo", () => {
|
||||||
@@ -10,13 +10,13 @@ describe("registry magic demo", () => {
|
|||||||
const typeUrl = "/demo.MsgMagic";
|
const typeUrl = "/demo.MsgMagic";
|
||||||
const myRegistry = new Registry();
|
const myRegistry = new Registry();
|
||||||
|
|
||||||
@cosmosMessage(myRegistry, nestedTypeUrl)
|
@registered(myRegistry, nestedTypeUrl)
|
||||||
class MsgNestedMagic extends Message {
|
class MsgNestedMagic extends Message {
|
||||||
@cosmosField.string(1)
|
@cosmosField.string(1)
|
||||||
public readonly foo?: string;
|
public readonly foo?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@cosmosMessage(myRegistry, typeUrl)
|
@registered(myRegistry, typeUrl)
|
||||||
class MsgMagic extends Message {
|
class MsgMagic extends Message {
|
||||||
@cosmosField.boolean(1)
|
@cosmosField.boolean(1)
|
||||||
public readonly booleanDemo?: boolean;
|
public readonly booleanDemo?: boolean;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
import { Message } from "protobufjs";
|
import { Message } from "protobufjs";
|
||||||
|
|
||||||
import { cosmosField, cosmosMessage } from "./decorator";
|
import { cosmosField, registered } from "./decorator";
|
||||||
import { Registry } from "./registry";
|
import { Registry } from "./registry";
|
||||||
|
|
||||||
export const defaultRegistry = new Registry();
|
export const defaultRegistry = new Registry();
|
||||||
|
|
||||||
@cosmosMessage(defaultRegistry, "/cosmos.Coin")
|
@registered(defaultRegistry, "/cosmos.Coin")
|
||||||
export class Coin extends Message {
|
export class Coin extends Message {
|
||||||
@cosmosField.string(1)
|
@cosmosField.string(1)
|
||||||
public readonly denom?: string;
|
public readonly denom?: string;
|
||||||
@@ -15,7 +15,7 @@ export class Coin extends Message {
|
|||||||
public readonly amount?: string;
|
public readonly amount?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@cosmosMessage(defaultRegistry, "/cosmos.bank.MsgSend")
|
@registered(defaultRegistry, "/cosmos.bank.MsgSend")
|
||||||
export class MsgSend extends Message {
|
export class MsgSend extends Message {
|
||||||
@cosmosField.bytes(1)
|
@cosmosField.bytes(1)
|
||||||
public readonly from_address?: Uint8Array;
|
public readonly from_address?: Uint8Array;
|
||||||
|
|||||||
+5
-1
@@ -1,6 +1,10 @@
|
|||||||
import { Constructor, Message, TypeDecorator } from "protobufjs";
|
import { Constructor, Message, TypeDecorator } from "protobufjs";
|
||||||
import { Registry } from "./registry";
|
import { Registry } from "./registry";
|
||||||
export declare function cosmosMessage(registry: Registry, typeUrl: string): TypeDecorator<any>;
|
/**
|
||||||
|
* A class decorator to register this type under the given type URL
|
||||||
|
* in the given registry.
|
||||||
|
*/
|
||||||
|
export declare function registered(registry: Registry, typeUrl: string): TypeDecorator<any>;
|
||||||
/**
|
/**
|
||||||
* Like PropertyDecorator from lib.es5.d.ts but without symbol support in propertyKey.
|
* Like PropertyDecorator from lib.es5.d.ts but without symbol support in propertyKey.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user