-
Notifications
You must be signed in to change notification settings - Fork 8
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
Proposal to add "types" and "thing" #17
Open
elliotBraem
wants to merge
1
commit into
NearSocial:main
Choose a base branch
from
near-everything:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Thing | ||
|
||
A thing is the most basic interface for any real or digital asset. | ||
|
||
## Schema | ||
|
||
The schema is defined by its Type committed on chain. | ||
|
||
|
||
## Example | ||
|
||
A [Type](../type/Type.md) is created with properties that look like this: | ||
|
||
```json | ||
{ | ||
"properties": [ | ||
{ | ||
"name": "title", | ||
"type": "String", | ||
"required": true | ||
}, | ||
{ | ||
"name": "description", | ||
"type": "md", | ||
"required": false | ||
} | ||
] | ||
} | ||
``` | ||
|
||
We see that this Type has two properties; a title of type String and a description of type md (Markdown). | ||
|
||
When a Type is created, it also autogenerates basic Widgets for creating and displaying this data, and so our Type looks like: | ||
|
||
```json | ||
"evrything.near": { | ||
"types": { | ||
"Idea": { | ||
"properties": [ | ||
{ | ||
"name": "title", | ||
"type": "String", | ||
"required": true | ||
}, | ||
{ | ||
"name": "description", | ||
"type": "md", | ||
"required": false | ||
} | ||
], | ||
"widgets": { | ||
"summary": "Everything.Summary.Idea", | ||
"view": "Everything.View.Idea", | ||
"create": "Everything.Create.Idea" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
The autogenerated "create" widget is a basic template and form for creating data of type "evrything.near/type/Idea", which consists of a title and description (a text input and a textarea). | ||
|
||
When data is created via the Everything.Create.Idea widget, it will save to the Social contract: | ||
|
||
```json | ||
{ | ||
"thing": { | ||
"main": "[DATA]" | ||
}, | ||
"index": { | ||
"[DOMAIN]": "{ key: \"main\", \"value\": { \"type\": \"evrything.near/type/Idea\" } })", | ||
}, | ||
} | ||
``` | ||
|
||
Since the Create widget was autogenerated, we know that the DATA will be following the properties of the Type. | ||
|
||
However, we allow this to be free form because maybe the developer doesn't want the data to be permanent and forever on chain. If the developer wants the data to be stored on chain, then DATA would look like this: | ||
|
||
```json | ||
{ | ||
"title": "I have a cool idea!", | ||
"description": "With Types, we could let the user choose where the data is stored, while still keeping it predictable for developers." | ||
} | ||
``` | ||
|
||
But maybe the developer wants the data to follow the Type schema, then be POSTed to a decentralized storage service where it can have some privacy. In this case, it creates the data and saves a reference to the thingId instead: | ||
|
||
```json | ||
{ | ||
"thingId": "thing123456789" | ||
} | ||
``` | ||
|
||
It doesn't matter how or where this data is stored, because the developer can design the view and summary widget to use the thingId to fetch the offchain data. | ||
|
||
The DATA just needs to represent a thing of TYPE, no matter where it is stored. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Type | ||
|
||
Contains the properties, references to widgets necessary to display and create data of this type, and the optional metadata. | ||
|
||
## Schema | ||
|
||
| Key | Type | Description | | ||
|--------------|-----------------------------------|-------------------------------------------------| | ||
| **`""`** | String | Schema describing the properities of a thing and holding references to necessary widgets for displaying and creating data of this type. | | ||
| _`metadata`_ | [Metadata](../common/Metadata.md) | The metadata information describing the type. | | ||
|
||
## Example | ||
|
||
```json | ||
{ | ||
"": "{ \"properties\": [{\"name\": \"title\",\"type\": \"String\",\"required\": true }, {\"name\": \"description\",\"type\": \"md\",\"required\": false },], \"widgets\": {\"summary\": \"evrything.near/widget/Everything.Summary.Idea\",\"view\": \"evrything.near/widget/Everything.View.Idea\",\"create\": \"evrything.near/widget/Everything.Create.Idea\"}};", | ||
"metadata": { | ||
"name": "Idea", | ||
"description": "Idea type for proposals to the everything DAO", | ||
"tags": { | ||
"example": "", | ||
"inline": "" | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Types | ||
|
||
Types created by the account. | ||
|
||
## Schema | ||
|
||
| Key | Type | Description | | ||
|----------------------|-----------------------|--------------------------------------------------------------| | ||
| **`[type_name]`** | [Type](./Type.md) | Contains the properties, references to widgets necessary to display and create data of this type, and the optional metadata. | | ||
|
||
## Example | ||
|
||
```json | ||
{ | ||
"Idea": { | ||
"": "{ \"properties\": [{\"name\": \"title\",\"type\": \"String\",\"required\": true }, {\"name\": \"description\",\"type\": \"md\",\"required\": false },], \"widgets\": {\"summary\": \"evrything.near/widget/Everything.Summary.Idea\",\"view\": \"evrything.near/widget/Everything.View.Idea\",\"create\": \"evrything.near/widget/Everything.Create.Idea\"}};", | ||
"metadata": { | ||
"name": "Idea", | ||
"description": "Idea type for proposals to the everything DAO", | ||
"tags": { | ||
"example": "", | ||
"inline": "" | ||
} | ||
} | ||
}, | ||
"Event": { | ||
"": "{ \"properties\": [{\"name\": \"title\",\"type\": \"String\",\"required\": true }, {\"name\": \"description\",\"type\": \"md\",\"required\": false }, {\"name\": \"date\",\"type\": \"Date\",\"required\": true }], \"widgets\": {\"summary\": \"evrything.near/widget/Everything.Summary.Event\",\"view\": \"evrything.near/widget/Everything.View.Event\",\"create\": \"evrything.near/widget/Everything.Create.Event\"}};", | ||
"metadata": { | ||
"name": "Event", | ||
"description": "Event type for events approved by everything DAO", | ||
"tags": { | ||
"example": "", | ||
"inline": "" | ||
} | ||
} | ||
} | ||
} | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @elliotBraem, Do you mind to elaborate on this part
When a Type is created, it also autogenerates basic Widgets for creating and displaying this data
. What is this process of autogenerating components?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @charleslavon ; yeah so at the time of this PR, I had methods in a revised VM that would bootstrap and commit new widgets under the type creator's account. The guiding principle was that if a Type were to be defined, then we would know the props that would be passed into a View and Summary widget, and the props necessary to initialize state in a Create Widget. I can't find the exact code, but it looked something like this:
It was just simple string replaces for basic starter widgets that create, view, and summarize data of this Type.
Although soon after, I decided against needing to generate new widgets because it's a lot of code duplication and it means 3 new Widget paths to remember per Type. And so it evolved to a dynamic form generator like you see in the creator (which is being revamped, see post here ). I have a lot more I can share here if interested.
If you're interested in code generators however, then check out Teleport HQ's open source code generators which generate code from a JSON UIDL. They can be used to generate component code or entire projects in a variety of frameworks. We have a developer that is currently working on extending the generator for Social React; happening on the "teleport" branch here. If you're interested in contributing to this effort, you can follow this document to set yourself up with a bos-workspace and utilize a BOS -> Teleport dashboard for testing your conversions.