{"id":13837080,"url":"https://github.com/selectel/jane","last_synced_at":"2025-04-30T16:17:24.663Z","repository":{"id":136165037,"uuid":"2032880","full_name":"selectel/jane","owner":"selectel","description":"JS's Acknowledgement of Native Erlang types  ","archived":false,"fork":false,"pushed_at":"2011-07-20T15:26:05.000Z","size":99,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-30T16:17:02.419Z","etag":null,"topics":["community","erlang"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/selectel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-07-11T21:52:35.000Z","updated_at":"2024-07-03T15:40:32.000Z","dependencies_parsed_at":"2023-03-13T02:32:58.530Z","dependency_job_id":null,"html_url":"https://github.com/selectel/jane","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selectel%2Fjane","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selectel%2Fjane/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selectel%2Fjane/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selectel%2Fjane/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/selectel","download_url":"https://codeload.github.com/selectel/jane/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251739677,"owners_count":21635893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["community","erlang"],"created_at":"2024-08-04T15:01:00.650Z","updated_at":"2025-04-30T16:17:24.622Z","avatar_url":"https://github.com/selectel.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"JANE\n====\nJS's Acknowledgement of Native Erlang types\n-------------------------------------------\n\nRationale\n---------\nNowadays, Erlang is getting a huge attention. This attention reveals a growing need for an interaction with JavaScript and other languages. Despite of Erlang's concise syntax and neat type annotations (which are used by every conscious Erlang programmer), JavaScript is the only language for the Web (for now, at least). This document represents an attempt to change the way how JS and Erlang interact by specifying how Erlang's type annotated records can be represented using JSON. The translated type information can be used to draw edit forms, check types of ingoing and outgoing messages and control the way how data is represented.\n\nFormat\n------\nThe reference implementation takes a .hrl file containing typed record definitions and translates it into a .json file containing JSON-encoded record definitions. Each record is encoded as an entry in a first-level dictionary. Then all fields are specified - again as a dictionary where key is a field name and value is a field specification.\n\nRecord field specification consists of \"type\" field and optional \"default\" field. \"default\" field contains a default value (obviously) and \"type\" field is encoded as follows:\n\n*type name is set as a key, arguments list is set as a value;\n*each type argument can be a value or a dictionary that contains type as a key and their arguments list as a value;\n*these list+dictionary constructs can go deeper.\n\nBy default all record fields contain a union of their actual type and atom \"undefined\". The reference implementation ignores these unions if flag \"ignore_undefined\" is set.\n\nImplementation\n--------------\nCurrent implementation of JANE is an escript file that can be used inside of rebar post-hook:\n\n```erlang\n{post_hooks, [{'compile', './priv/recordparser ignore_undefined include/test.hrl'}]}.\n```\n\nBy default, all resulting .json files will be located in priv/records/test.json, where test is a name of .hrl file.\n\nExample\n-------\nHere is an example .hrl file with typed records:\n\n```erlang\n-record(params_ping, {host :: nonempty_string()}).\n-record(params_tcp, {host :: list(atom()),\n                     port = 80 :: pos_integer(),\n                     timeout :: pos_integer()}).\n```\n\nHere is how it is translated to JSON with ignore_undefined:\n\n```javascript\n{\n    \"params_ping\": {\n        \"host\": {\n            \"type\": {\n                \"nonempty_string\": []\n            }\n        }\n    },\n    \"params_tcp\": {\n        \"host\": {\n            \"type\": {\n                \"list\": [\n                    {\n                        \"atom\": []\n                    }\n                ]\n            }\n        },\n        \"port\": {\n            \"type\": {\n                \"pos_integer\": []\n            },\n            \"default\": 80\n        },\n        \"timeout\": {\n            \"type\": {\n                \"pos_integer\": []\n            }\n        }\n    }\n}\n```\n\nAnd here is without ignore_undefined:\n\n```javascript\n{\n    \"params_ping\": {\n        \"host\": {\n            \"type\": {\n                \"union\": [\n                    {\n                        \"atom\": [\n                            \"undefined\"\n                        ]\n                    },\n                    {\n                        \"nonempty_string\": []\n                    }\n                ]\n            }\n        }\n    },\n    \"params_tcp\": {\n        \"host\": {\n            \"type\": {\n                \"union\": [\n                    {\n                        \"atom\": [\n                            \"undefined\"\n                        ]\n                    },\n                    {\n                        \"nonempty_string\": []\n                    }\n                ]\n            }\n        },\n        \"port\": {\n            \"type\": {\n                \"pos_integer\": []\n            },\n            \"default\": 80\n        },\n        \"timeout\": {\n            \"type\": {\n                \"union\": [\n                    {\n                        \"atom\": [\n                            \"undefined\"\n                        ]\n                    },\n                    {\n                        \"pos_integer\": []\n                    }\n                ]\n            }\n        }\n    }\n}\n```\n\nLicense\n-------\nCopyright 2011 Selectel. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are\npermitted provided that the following conditions are met:\n\n   1. Redistributions of source code must retain the above copyright notice, this list of\n      conditions and the following disclaimer.\n\n   2. Redistributions in binary form must reproduce the above copyright notice, this list\n      of conditions and the following disclaimer in the documentation and/or other materials\n      provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY SELECTEL ``AS IS'' AND ANY EXPRESS OR IMPLIED\nWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\nFITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL \u003cCOPYRIGHT HOLDER\u003e OR\nCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\nCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\nNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\nThe views and conclusions contained in the software and documentation are those of the\nauthors and should not be interpreted as representing official policies, either expressed\nor implied, of Selectel.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselectel%2Fjane","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fselectel%2Fjane","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselectel%2Fjane/lists"}