Git Product home page Git Product logo

Comments (9)

thesayyn avatar thesayyn commented on May 24, 2024 1

We decided to add a new method that accepts json data and creates the messages recursively. I didn’t realize that this was on the spec as well. going to work on this soon.

from protoc-gen-ts.

thesayyn avatar thesayyn commented on May 24, 2024

Hey @hardikkat24

Could you please send your .proto file here?

Normally there is an easy way to do it if the field names in your json properties match the proto fields.
Just pass the parsed json object to the constructor and it will pick up the properties automatically.
Keep in mind that you have to manually create non-scalar values yourself.

Given the proto

message Product {
  string name = 1;
  string description = 2;
}

you should be able to parse the json and pass it to the constructor, like so

const json = JSON.parse('{ "name": "something something",  "description": "something something"}');
const product = new Product(json);

from protoc-gen-ts.

hardikkat24 avatar hardikkat24 commented on May 24, 2024

Thanks but this doesn't work for my proto file.
@thesayyn

syntax = "proto3";

import "google/protobuf/any.proto";


message constants {
    bool CAN_SEND_ANALYTICS_EVENTS = 1;

    string CLASSROOM_URL_FRAGMENT_FOR_UNATTACHED_TOPICS = 2;

    string DEFAULT_CLASSROOM_URL_FRAGMENT = 3;

    repeated string ALL_CATEGORIES = 4;

    string ACTIVITY_TYPE_EXPLORATION = 5;
    string ACTIVITY_TYPE_COLLECTION = 6;
    repeated string DISABLED_EXPLORATION_IDS = 7;

    string TESTING_CONSTANT = 8;

    int32 LIBRARY_TILE_WIDTH_PX = 9;

    string DASHBOARD_TYPE_CREATOR = 10;
    string DASHBOARD_TYPE_LEARNER = 11;

    string DEFAULT_COLOR = 12;
    string DEFAULT_THUMBNAIL_ICON = 13;
    string DEFAULT_CATEGORY_ICON = 14;

    string ACTION_ACCEPT_SUGGESTION = 15;
    string ACTION_REJECT_SUGGESTION = 16;

    map<string, string> SKILL_STATUS_OPTIONS = 17;

    map<string, string> TOPIC_SKILL_DASHBOARD_SORT_OPTIONS = 18;

    repeated string SEARCH_DROPDOWN_CATEGORIES = 19;

    string DEFAULT_LANGUAGE_CODE = 20;

    // Message not a map because a list for each key.
    message allowed_thumbnail_bg_colors {
        repeated string chapter = 1;
        repeated string topic = 2;
        repeated string subtopic = 3;
        repeated string story = 4;
    }
    allowed_thumbnail_bg_colors ALLOWED_THUMBNAIL_BG_COLORS = 21;

    repeated string ALLOWED_IMAGE_FORMATS = 22;

    string TASK_TYPE_HIGH_BOUNCE_RATE = 23;
    string TASK_TYPE_INEFFECTIVE_FEEDBACK_LOOP = 24;
    string TASK_TYPE_SUCCESSIVE_INCORRECT_ANSWERS = 25;
    string TASK_TYPE_NEEDS_GUIDING_RESPONSES = 26;

    string TASK_STATUS_OPEN = 27;
    string TASK_STATUS_OBSOLETE = 28;
    string TASK_STATUS_RESOLVED = 29;

    string TASK_ENTITY_TYPE_EXPLORATION = 30;

    string TASK_TARGET_TYPE_STATE = 31;

    string ROLE_OWNER = 32;
    string ROLE_EDITOR = 33;
    string ROLE_VOICE_ARTIST = 34;
    string ROLE_VIEWER = 35;

    string MATH_SVG_FILENAME_REGEX = 36;

    message svg_attrs_whitelist {
        repeated string a = 1;
        repeated string altglyph = 2;
        repeated string altglyphdef = 3;
        repeated string altglyphitem = 4;
        repeated string animatecolor = 5;
        repeated string animatemotion = 6;
        repeated string animatetransform = 7;
        repeated string audio = 8;
        repeated string canvas = 9;
        repeated string circle = 10;
        repeated string clippath = 11;
        repeated string defs = 12;
        repeated string desc = 13;
        repeated string ellipse = 14;
        repeated string feblend = 15;
        repeated string fecolormatrix = 16;
        repeated string fecomponenttransfer = 17;
        repeated string fecomposite = 18;
        repeated string feconvolvematrix = 19;
        repeated string fediffuselighting = 20;
        repeated string fedisplacementmap = 21;
        repeated string fedistantlight = 22;
        repeated string feflood = 23;
        repeated string fefunca = 24;
        repeated string fefuncb = 25;
        repeated string fefuncg = 26;
        repeated string fefuncr = 27;
        repeated string fegaussianblur = 28;
        repeated string femerge = 29;
        repeated string femergenode = 30;
        repeated string femorphology = 31;
        repeated string feoffset = 32;
        repeated string fepointlight = 33;
        repeated string fespecularlighting = 34;
        repeated string fespotlight = 35;
        repeated string fetile = 36;
        repeated string feturbulence = 37;
        repeated string filter = 38;
        repeated string font = 39;
        repeated string g = 40;
        repeated string glyph = 41;
        repeated string glyphref = 42;
        repeated string hkern = 43;
        repeated string image = 44;
        repeated string line = 45;
        repeated string lineargradient = 46;
        repeated string marker = 47;
        repeated string mask = 48;
        repeated string metadata = 49;
        repeated string mpath = 50;
        repeated string path = 51;
        repeated string pattern = 52;
        repeated string polygon = 53;
        repeated string polyline = 54;
        repeated string radialgradient = 55;
        repeated string rect = 56;
        repeated string stop = 57;
        repeated string style = 58;
        repeated string svg = 59;
        repeated string switch = 60;
        repeated string symbol = 61;
        repeated string text = 62;
        repeated string textpath = 63;
        repeated string title = 64;
        repeated string tref = 65;
        repeated string tspan = 66;
        repeated string video = 67;
        repeated string view = 68;
        repeated string vkern = 69;
    }
    svg_attrs_whitelist SVG_ATTRS_WHITELIST = 37;

    // message categories_to_colors {
    //     string Mathematics = 1;
    //     string Algebra = 2;
    //     string Arithmetic = 3;
    //     string Calculus = 4;
    //     string Logic = 5;
    //     string Combinatorics = 6;
    //     string Graph_Theory = 7;
    //     string Probability = 8;
    //     string Statistics = 9;
    //     string Geometry = 10;
    //     string Trigonometry = 11;

    //     string Algorithms = 12;
    //     string Computing = 13;
    //     string Programming = 14;

    //     string Astronomy = 15;
    //     string Biology = 16;
    //     string Chemistry = 17;
    //     string Engineering = 18;
    //     string Environment = 19;
    //     string Medicine = 20;
    //     string Physics = 21;

    //     string Architecture = 22;
    //     string Art = 23;
    //     string Music = 24;
    //     string Philosophy = 25;
    //     string Poetry = 26;

    //     string English = 27;
    //     string Languages = 28;
    //     string Latin = 29;
    //     string Reading = 30;
    //     string Spanish = 31;
    //     string Gaulish = 32;

    //     string Business = 33;
    //     string Economics = 34;
    //     string Geography = 35;
    //     string Government = 36;
    //     string History = 37;
    //     string Law = 38;

    //     string Education = 39;
    //     string Puzzles = 40;
    //     string Sport = 41;
    //     string Welcome = 42;
    // }
    // categories_to_colors CATEGORIES_TO_COLORS = 38;
    map<string, string> CATEGORIES_TO_COLORS = 38;

    repeated string VALID_RTE_COMPONENTS_FOR_ANDROID = 39;

    message supported_content_languages_for_android {
        string code = 1;
        string description = 2;
        string direction = 3;
    }
    repeated supported_content_languages_for_android SUPPORTED_CONTENT_LANGUAGES_FOR_ANDROID = 40;

    message supported_content_languages {
        string code = 1;
        string description = 2;
        string direction = 3;
    }
    repeated supported_content_languages SUPPORTED_CONTENT_LANGUAGES = 41;

    message supported_site_languages {
        string id = 1;
        string text = 2;
        string direction = 3;
    }
    repeated supported_site_languages SUPPORTED_SITE_LANGUAGES = 42;

    message supported_audio_languages {
        string id = 1;
        string description = 2;
        repeated string relatedLanguages = 3;
        string direction = 4;
    }
    repeated supported_audio_languages SUPPORTED_AUDIO_LANGUAGES = 43;

    message autogenerated_audio_languages {
        string id = 1;
        string description = 2;
        string explorationLanguage = 3;
        string speechSynthesisCode = 4;
        string speechSynthesisCodeMobile = 5;
    }
    repeated autogenerated_audio_languages AUTOGENERATED_AUDIO_LANGUAGES = 44;

    message translation_tips {
        repeated string zh = 1;
        repeated string hi = 2;
        repeated string bn = 3;
        repeated string ar = 4;
    }
    translation_tips TRANSLATION_TIPS = 45;

    message interactions {
        string name = 1;
        repeated string interaction_ids = 2;
    }
    repeated interactions ALLOWED_QUESTION_INTERACTION_CATEGORIES = 46;

    repeated interactions ALLOWED_EXPLORATION_IN_STORY_INTERACTION_CATEGORIES = 47;

    repeated interactions ALLOWED_INTERACTION_CATEGORIES = 48;

    string CONTRIBUTION_RIGHT_CATEGORY_REVIEW_TRANSLATION = 49;
    string CONTRIBUTION_RIGHT_CATEGORY_REVIEW_VOICEOVER = 50;
    string CONTRIBUTION_RIGHT_CATEGORY_REVIEW_QUESTION = 51;
    string CONTRIBUTION_RIGHT_CATEGORY_SUBMIT_QUESTION = 52;

    string ACTION_REMOVE_ALL_REVIEW_RIGHTS = 53;
    string ACTION_REMOVE_SPECIFIC_CONTRIBUTION_RIGHTS = 54;
    string USER_FILTER_CRITERION_USERNAME = 55;
    string USER_FILTER_CRITERION_ROLE = 56;

    repeated string INTERACTION_IDS_WITHOUT_ANSWER_DETAILS = 57;

    repeated string WHITELISTED_COLLECTION_IDS_FOR_SAVING_GUEST_PROGRESS = 58;

    int32 FEEDBACK_SUBJECT_MAX_CHAR_LIMIT = 59;

    string ACTIVITY_STATUS_PRIVATE = 60;
    string ACTIVITY_STATUS_PUBLIC = 61;

    string SITE_FEEDBACK_FORM_URL = 62;

    repeated string SYSTEM_USER_IDS = 63;

    repeated string INVALID_NAME_CHARS = 64;

    float DEFAULT_SKILL_DIFFICULTY = 65;

    repeated string INLINE_RTE_COMPONENTS = 66;

    string SKILL_DIFFICULTY_EASY = 67;
    string SKILL_DIFFICULTY_MEDIUM = 68;
    string SKILL_DIFFICULTY_HARD = 69;

    repeated string SKILL_DIFFICULTIES = 70;

    map<string, float> SKILL_DIFFICULTY_LABEL_TO_FLOAT = 71;

    bool ENABLE_PREREQUISITE_SKILLS = 72;

    bool ENABLE_NEW_STRUCTURE_VIEWER_UPDATES = 73;

    bool ENABLE_SOLICIT_ANSWER_DETAILS_FEATURE = 74;

    int32 MAX_SKILLS_PER_QUESTION = 75;

    int32 MAX_QUESTIONS_PER_SKILL = 76;

    int32 NUM_EXPLORATIONS_PER_REVIEW_TEST = 77;

    int32 NUM_QUESTIONS_PER_PAGE = 78;

    int32 OPPORTUNITIES_PAGE_SIZE = 79;

    int32 MAX_CHARS_IN_CLASSROOM_URL_FRAGMENT = 80;
    int32 MAX_CHARS_IN_TOPIC_NAME = 81;
    int32 MAX_CHARS_IN_ABBREV_TOPIC_NAME = 82;

    int32 MAX_CHARS_IN_TOPIC_URL_FRAGMENT = 83;
    int32 MAX_CHARS_IN_TOPIC_DESCRIPTION = 84;
    int32 MAX_CHARS_IN_SUBTOPIC_TITLE = 85;
    int32 MAX_CHARS_IN_SKILL_DESCRIPTION = 86;
    int32 MAX_CHARS_IN_STORY_TITLE = 87;
    int32 MAX_CHARS_IN_STORY_DESCRIPTION = 88;
    int32 MAX_CHARS_IN_CHAPTER_TITLE = 89;
    int32 MAX_CHARS_IN_CHAPTER_DESCRIPTION = 90;
    int32 MAX_CHARS_IN_MISCONCEPTION_NAME = 91;

    int32 MAX_CHARS_IN_STORY_URL_FRAGMENT = 92;

    int32 MAX_CHARS_IN_SUBTOPIC_URL_FRAGMENT = 93;

    int32 MAX_CHARS_IN_META_TAG_CONTENT = 94;

    int32 MAX_CHARS_IN_PAGE_TITLE_FRAGMENT_FOR_WEB = 95;


    // NEW_STATE_TEMPLATE DEFINITION BEGINS
    message content_and_feedback {
        string html = 1;
        string content_id = 2;
    }

    message empty {}

    message Default_outcome {
        string dest = 1;
        content_and_feedback feedback = 2;
        bool labelled_as_correct = 3;
        repeated google.protobuf.Any param_changes = 4;
        google.protobuf.Any refresher_exploration_id = 5;
        google.protobuf.Any missing_prerequisite_skill_id = 6;
    }

    message Interaction {
        google.protobuf.Any id = 1;
        empty customization_args = 2;
        repeated google.protobuf.Any answer_groups = 3;
        Default_outcome default_outcome = 4;
        repeated google.protobuf.Any confirmed_unclassified_answers = 5;
        repeated google.protobuf.Any hints = 6;
        google.protobuf.Any solution = 7;
    }

    message mapping {
        empty content = 1;
        empty default_outcome = 2;
    }

    message Recorded_voiceovers {
        mapping voiceovers_mapping = 1;
    }

    message Written_translations {
        mapping translations_mapping = 1;
    }

    message new_state_template {
        google.protobuf.Any classifier_model_id = 1;
        google.protobuf.Any linked_skill_id = 2;
        content_and_feedback content = 3;
        Interaction interaction = 4;
        int32 next_content_id_index = 5;
        repeated google.protobuf.Any param_changes = 6;
        Recorded_voiceovers recorded_voiceovers = 7;
        bool solicit_answer_details = 8;
        bool card_is_checkpoint = 9;
        Written_translations written_translations = 10;
    }

    new_state_template NEW_STATE_TEMPLATE = 96;
    // NEW_STATE_TEMPLATE DEFINITION ENDS

    string ANALYTICS_ID = 97;
    string SITE_NAME_FOR_ANALYTICS = 98;

    string FIREBASE_CONFIG_API_KEY = 99;
    string FIREBASE_CONFIG_AUTH_DOMAIN = 100;
    string FIREBASE_CONFIG_PROJECT_ID = 101;
    string FIREBASE_CONFIG_STORAGE_BUCKET = 102;
    string FIREBASE_CONFIG_MESSAGING_SENDER_ID = 103;
    string FIREBASE_CONFIG_APP_ID = 104;
    string FIREBASE_CONFIG_GOOGLE_CLIENT_ID = 105;

    bool ALLOW_YAML_FILE_UPLOAD = 106;

    string TAG_REGEX = 107;

    string VALID_URL_FRAGMENT_REGEX = 108;

    string VALID_SKILL_MISCONCEPTION_ID_REGEX = 109;

    repeated string INVALID_PARAMETER_NAMES = 110;

    map<string, string> GREEK_LETTER_NAMES_TO_SYMBOLS = 111;

    repeated string VALID_ALGEBRAIC_IDENTIFIERS = 112;

    repeated string VALID_CUSTOM_OSK_LETTERS = 113;

    int32 MAX_CUSTOM_LETTERS_FOR_OSK = 114;

    repeated string MATH_FUNCTION_NAMES = 115;

    string OSK_MAIN_TAB = 116;
    string OSK_FUNCTIONS_TAB = 117;
    string OSK_LETTERS_TAB = 118;

    string CUSTOM_LETTERS_LATIN_TAB = 119;
    string CUSTOM_LETTERS_GREEK_TAB = 120;

    message position_of_terms_mapping {
        string name = 1;
        string humanReadableName = 2;
    }
    repeated position_of_terms_mapping POSITION_OF_TERMS_MAPPING = 121;

    message math_interaction_placeholders {
        string AlgebraicExpressionInput = 1;
        string NumericExpressionInput = 2;
        string MathEquationInput = 3;
    }
    math_interaction_placeholders MATH_INTERACTION_PLACEHOLDERS = 122;

    bool SHOW_TRAINABLE_UNRESOLVED_ANSWERS = 123;

    string DEFAULT_TWITTER_SHARE_MESSAGE_EDITOR = 124;

    string OPPORTUNITY_TYPE_SKILL = 125;
    string OPPORTUNITY_TYPE_TRANSLATION = 126;
    string OPPORTUNITY_TYPE_VOICEOVER = 127;

    string GCS_RESOURCE_BUCKET_NAME = 128;

    bool ENABLE_EXP_FEEDBACK_FOR_LOGGED_OUT_USERS = 129;

    bool ENABLE_ACCOUNT_DELETION = 130;

    bool ENABLE_ACCOUNT_EXPORT = 131;

    google.protobuf.Any OPPIA_AVATAR_LINK_URL = 132;

    int32 MAX_USERNAME_LENGTH = 133;

    int32 MAX_STATE_NAME_LENGTH = 134;

    repeated string PLATFORM_PARAMETER_ALLOWED_BROWSER_TYPES = 135;

    repeated string PLATFORM_PARAMETER_ALLOWED_PLATFORM_TYPES = 136;

    repeated string PLATFORM_PARAMETER_ALLOWED_APP_VERSION_FLAVORS = 137;

    string PLATFORM_PARAMETER_APP_VERSION_WITHOUT_HASH_REGEXP = 138;

    string PLATFORM_PARAMETER_APP_VERSION_WITH_HASH_REGEXP = 139;

    int32 MAX_COMMIT_MESSAGE_LENGTH = 140;
    int32 MAX_REVIEW_MESSAGE_LENGTH = 141;

    // EMAIL_DASHBOARD_PREDICATE_DEFINITION START
    message Validators {
        string id = 1;
        int32 min_value = 2;
    }

    message Schema {
        string type = 1;
        repeated Validators validators = 2;
    }

    message email_dashboard_predicate_definition {
        string backend_id = 1;
        string backend_attr = 2;
        string description = 3;
        Schema schema = 4;
        bool default_value = 5;
    }
    repeated email_dashboard_predicate_definition EMAIL_DASHBOARD_PREDICATE_DEFINITION = 142;
    // EMAIL_DASHBOARD_PREDICATE_DEFINITION END

    bool DEV_MODE = 143;
    bool EMULATOR_MODE = 144;

    message allowed_creator_dashboard_display_prefs {
        string CARD = 1;
        string LIST = 2;
    }
    allowed_creator_dashboard_display_prefs ALLOWED_CREATOR_DASHBOARD_DISPLAY_PREFS = 145;

}


from protoc-gen-ts.

thesayyn avatar thesayyn commented on May 24, 2024

This proto has too many non scalar fields which you have to handle yourself.

Some fields will work but others will prevent them from working because you have to explicitly pass the submessages to their constructor.

from protoc-gen-ts.

hardikkat24 avatar hardikkat24 commented on May 24, 2024

@thesayyn Thanks a lot! Have you solved an issue like this ? I was trying to do the same but was unable to do so.

from protoc-gen-ts.

thesayyn avatar thesayyn commented on May 24, 2024

Actually, it is not an issue. You only need to pass the sub-messages into their constructors. it might be a lot of work but that is how google-protobuf works.

from protoc-gen-ts.

hardikkat24 avatar hardikkat24 commented on May 24, 2024

@thesayyn Is it possible to parse text format instead of json easily?

from protoc-gen-ts.

thesayyn avatar thesayyn commented on May 24, 2024

I think so. If you could convert it to binary format first then you could easily pass it to deserialize function. it will create everything recursively from the binary data.

i will try to add an example for this if could find a way to do this.

from protoc-gen-ts.

thesayyn avatar thesayyn commented on May 24, 2024

This has been released via 0.5.0.

from protoc-gen-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.