Skip to content
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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions types/thing/Thing.md
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:

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?

Copy link
Author

@elliotBraem elliotBraem Aug 31, 2023

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:

Social.set({
      widget: {
        [`${state.typeName}.Create`]: {
          "": `State.init([INIT_STATE]);\n return (<div>[INIT_FORM]</div>);`.replace(INIT_STATE, typeToEmptyData).replace(INIT_FORM, typeToForm),
        },
  });

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.


```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.
26 changes: 26 additions & 0 deletions types/type/Type.md
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": ""
}
}
}
```
38 changes: 38 additions & 0 deletions types/type/Types.md
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": ""
}
}
}
}
```