-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify models with aleph-message
#2
Comments
Hello, I agree that having a single model definition easily synchronizable between different languages will be better. Moving the TS model definitions in To get |
I was thinking about moving |
I am ok with this, do you want me to first update |
Yes please 👍 |
After tests, I ended up with this first version, Some definition differs:
Open to your feedback! File Content:/**
* Chain defines which account was used to publish a message.
* It is automatically provided when publishing messages.
*/
export enum Chain {
DOT = "DOT",
ETH = "ETH",
SOL = "SOL",
}
/**
* Supported hash functions
*/
export enum HashType {
sha256 = "sha256",
}
/**
* Message types supported by Aleph
*/
export enum MessageType {
post = "POST",
aggregate = "AGGREGATE",
store = "STORE",
}
export enum ItemType {
inline = "inline",
storage = "storage",
ipfs = "ipfs",
}
type MongoDBID = {
$oid: string;
};
/**
* Some POST messages have a 'ref' field referencing other content
*/
export type ChainRef = {
chain: string;
channel?: string;
item_content: string;
item_hash: string;
item_type: string;
sender: string;
signature: string;
time: number;
type: MessageType.post;
};
type MessageConfirmationHash = {
binary: string;
type: string;
};
/**
* Format of the result when a message has been confirmed on a blockchain
*/
type MessageConfirmation = {
chain: string;
height: number;
hash: string | MessageConfirmationHash;
};
export type BaseContent = {
address: string;
time: number;
};
export type AggregateContentKey = {
name: string;
};
export type AggregateContent<T> = BaseContent & {
key: string | AggregateContentKey;
content: T;
};
export type PostContent<T> = BaseContent & {
content?: T;
type: string;
ref?: string | ChainRef;
};
export type StoreContent = BaseContent & {
item_type: string;
item_hash?: string;
size?: number;
content_type?: string;
ref?: string;
};
export type BaseMessage = {
_id?: MongoDBID;
chain: Chain;
sender: string;
type: MessageType;
channel: string;
confirmations?: MessageConfirmation[];
confirmed: boolean;
signature: string;
size: number;
time: number;
item_type: ItemType;
item_content: string;
hash_type?: string;
item_hash: string;
content?: BaseContent;
};
export type AggregateMessage<T> = BaseMessage & {
content: AggregateContent<T>;
type: MessageType.aggregate;
};
export type PostMessage<T> = BaseMessage & {
content: PostContent<T>;
type: MessageType.post;
};
export type StoreMessage = BaseMessage & {
content: StoreContent;
type: MessageType.store;
}; |
Thanks !
I think some historical messages used other chains such as NULS2. All historical messages should either be supported by our models or be specifically listed as unsupported. This script can download many or all the messages from Aleph, and then this test can check if they all match the specification.
PROGRAM and FORGET are two new message types I created, and must be supported by all our tools.
I believe many fields were mentioned as Optional in order to support historical messages. In some cases, the model for new messages should be more strict than the model for past messages.
This model was designed quickly with |
Possible solution : aleph-im/aleph-message#13 |
Context
The repository aleph-message contains a definition of the Aleph messages defined in Python/pydantic. These definitions are very similar to those in ./src/messages/messages.ts.
Problem
Message model definitions differ between
messages.js
andaleph-message
. It would be useful for users to find the same model definitions in both languages.When a model definition is modified, it has to be modified in both repositories.
Solutions
The main approach that comes to my mind would be to move the TS model definitions in
aleph-message
and makealeph-sdk-ts
depend on it.Automated tests in
aleph-message
could then check that model definitions in all languages match each other.The text was updated successfully, but these errors were encountered: