mirror of
https://github.com/anyproto/anytype-ts.git
synced 2025-06-11 02:13:48 +09:00
#876: change icon
This commit is contained in:
parent
a118e68320
commit
af46367433
7 changed files with 505 additions and 0 deletions
Binary file not shown.
Before Width: | Height: | Size: 290 B After Width: | Height: | Size: 233 B |
Binary file not shown.
Before Width: | Height: | Size: 255 B After Width: | Height: | Size: 240 B |
92
src/json/schema/embed/embed.go
Executable file
92
src/json/schema/embed/embed.go
Executable file
|
@ -0,0 +1,92 @@
|
|||
//+build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type schemaID struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func getSchemaIDFromReader(r io.Reader) (string, error) {
|
||||
dec := json.NewDecoder(r)
|
||||
|
||||
var schID schemaID
|
||||
err := dec.Decode(&schID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return schID.ID, nil
|
||||
}
|
||||
|
||||
// Reads all .json files in the current folder
|
||||
// and encodes them as strings literals in schemas.gen.go
|
||||
func main() {
|
||||
out, err := os.OpenFile("schemas.gen.go", os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
out.Write([]byte(`package schema
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
//go:generate go run embed/embed.go
|
||||
|
||||
|
||||
var SchemaByURL = map[string]string{
|
||||
`))
|
||||
fs, _ := ioutil.ReadDir(".")
|
||||
first := true
|
||||
for _, f := range fs {
|
||||
if strings.HasSuffix(f.Name(), ".json") {
|
||||
//out.Write([]byte("\t" + capitalize(strings.TrimSuffix(f.Name(), ".json")) + " = `"))
|
||||
f, err := os.Open(f.Name())
|
||||
if err != nil {
|
||||
log.Fatalf("failed to read %s: %s", f.Name(), err.Error())
|
||||
}
|
||||
|
||||
id, err := getSchemaIDFromReader(f)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to extract id from %s: %s", f.Name(), err.Error())
|
||||
}
|
||||
|
||||
f.Seek(0, 0)
|
||||
|
||||
if !first {
|
||||
out.Write([]byte(","))
|
||||
} else {
|
||||
first = false
|
||||
}
|
||||
|
||||
out.Write([]byte("\n"))
|
||||
|
||||
out.Write([]byte("\"" + id + "\" : `"))
|
||||
|
||||
io.Copy(out, f)
|
||||
out.Write([]byte("`"))
|
||||
}
|
||||
|
||||
}
|
||||
out.Write([]byte("}\n"))
|
||||
}
|
||||
|
||||
func capitalize(s string) string {
|
||||
if len(s) == 0 {
|
||||
return s
|
||||
}
|
||||
|
||||
if len(s) == 1 {
|
||||
return strings.ToTitle(s[0:1])
|
||||
}
|
||||
|
||||
return strings.ToTitle(s[0:1]) + s[1:]
|
||||
}
|
12
src/json/schema/person.json
Executable file
12
src/json/schema/person.json
Executable file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"id": "https://anytype.io/schemas/person",
|
||||
"title": "Anytype Page",
|
||||
"description": "This schema contains the base properties of Anytype Person",
|
||||
|
||||
"allOf": [
|
||||
{ "$ref": "https://anytype.io/schemas/page" }
|
||||
],
|
||||
|
||||
"type": "object"
|
||||
}
|
112
src/json/schema/relation.json
Executable file
112
src/json/schema/relation.json
Executable file
|
@ -0,0 +1,112 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"id": "https://anytype.io/schemas/relation",
|
||||
"title": "Anytype Page",
|
||||
"description": "This schema contains relation and all type definitions",
|
||||
"type": "object",
|
||||
"$comment": "fills relation from specific details",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"$comment": "detail's ID"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"$comment": "json schema $id for the relation type, starting from https://anytype.io/schemas/types/"
|
||||
},
|
||||
"objectType": {
|
||||
"type": "string",
|
||||
"$comment": "json schema $id of the object type for relations with the object type, e.g. https://anytype.io/schemas/page"
|
||||
},
|
||||
"isMulti": {
|
||||
"type": "boolean",
|
||||
"$comment": "multiple fields of the same type grouped in the array. allowed for: select, image, file, object"
|
||||
},
|
||||
"isHidden": {
|
||||
"type": "boolean",
|
||||
"$comment": "presented in the dataset, may be rendered with some view types but should be hided in the relations list"
|
||||
},
|
||||
"isReadonly": {
|
||||
"type": "boolean",
|
||||
"$comment": "not existing in the page's details, added afterwards"
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"title": {
|
||||
"$id": "https://anytype.io/schemas/types/title",
|
||||
"type": "string",
|
||||
"description": "Title renders name plus first emoji/image relation for the same relation"
|
||||
},
|
||||
"description": {
|
||||
"$id": "https://anytype.io/schemas/types/description",
|
||||
"type": "string"
|
||||
},
|
||||
"select": {
|
||||
"$id": "https://anytype.io/schemas/types/select",
|
||||
"type": "string"
|
||||
},
|
||||
"number": {
|
||||
"$id": "https://anytype.io/schemas/types/number",
|
||||
"type": "number"
|
||||
},
|
||||
"url": {
|
||||
"$id": "https://anytype.io/schemas/types/url",
|
||||
"type": "string",
|
||||
"description": "External URL",
|
||||
"format": "uri"
|
||||
},
|
||||
"email": {
|
||||
"$id": "https://anytype.io/schemas/types/email",
|
||||
"type": "string",
|
||||
"format": "email"
|
||||
},
|
||||
"phone": {
|
||||
"$id": "https://anytype.io/schemas/types/phone",
|
||||
"type": "string"
|
||||
},
|
||||
"date": {
|
||||
"$id": "https://anytype.io/schemas/types/date",
|
||||
"type": "string",
|
||||
"description": "UNIX timestamp as a string"
|
||||
},
|
||||
"checkbox": {
|
||||
"$id": "https://anytype.io/schemas/types/checkbox",
|
||||
"type": "boolean"
|
||||
},
|
||||
"object": {
|
||||
"$id": "https://anytype.io/schemas/types/object",
|
||||
"type": "string",
|
||||
"description": "ID of the object, e.g. page or person"
|
||||
},
|
||||
"image": {
|
||||
"$id": "https://anytype.io/schemas/types/image",
|
||||
"type": "string",
|
||||
"description": "CID of image node in the IPFS"
|
||||
},
|
||||
"file": {
|
||||
"$id": "https://anytype.io/schemas/types/file",
|
||||
"type": "string",
|
||||
"description": "CID of file node in the IPFS"
|
||||
},
|
||||
"emoji": {
|
||||
"$id": "https://anytype.io/schemas/types/emoji",
|
||||
"type": "string",
|
||||
"description": "One emoji as unicode"
|
||||
},
|
||||
"coverType": {
|
||||
"$id": "https://anytype.io/schemas/types/coverType",
|
||||
"enum": [
|
||||
0, "None",
|
||||
1, "Image",
|
||||
2, "Color",
|
||||
3, "Gradient",
|
||||
4, "Upload",
|
||||
5, "BgImage"
|
||||
],
|
||||
"description": "Page cover type"
|
||||
}
|
||||
}
|
||||
}
|
67
src/json/schema/schema.go
Executable file
67
src/json/schema/schema.go
Executable file
|
@ -0,0 +1,67 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/anytypeio/go-anytype-middleware/pkg/lib/logging"
|
||||
)
|
||||
|
||||
var log = logging.Logger("anytype-core-schema")
|
||||
|
||||
type Schema struct {
|
||||
Schema string `json:"$schema"`
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
Items struct {
|
||||
Ref string `json:"$ref"`
|
||||
} `json:"items"`
|
||||
UniqueItems bool `json:"uniqueItems"`
|
||||
Default []Relation `json:"default"`
|
||||
}
|
||||
|
||||
type Relation struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
IsHidden bool `json:"isHidden"`
|
||||
IsReadonly bool `json:"isReadonly"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
var schemaCache = map[string]*Schema{}
|
||||
var schemaCacheMutex = sync.Mutex{}
|
||||
|
||||
func Get(url string) (*Schema, error) {
|
||||
schemaCacheMutex.Lock()
|
||||
defer schemaCacheMutex.Unlock()
|
||||
if v, exist := schemaCache[url]; exist {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
if v, exists := SchemaByURL[url]; !exists {
|
||||
return nil, fmt.Errorf("schema not found")
|
||||
} else {
|
||||
var sch Schema
|
||||
err := json.NewDecoder(strings.NewReader(v)).Decode(&sch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
schemaCache[url] = &sch
|
||||
return &sch, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (sch *Schema) GetRelationById(id string) (*Relation, error) {
|
||||
for _, rel := range sch.Default {
|
||||
if rel.ID == id {
|
||||
return &rel, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("not found")
|
||||
}
|
||||
|
||||
// Todo: data validation
|
222
src/json/schema/schemas.gen.go
Executable file
222
src/json/schema/schemas.gen.go
Executable file
|
@ -0,0 +1,222 @@
|
|||
package schema
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
//go:generate go run embed/embed.go
|
||||
|
||||
|
||||
var SchemaByURL = map[string]string{
|
||||
|
||||
"https://anytype.io/schemas/page" : `{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"id": "https://anytype.io/schemas/page",
|
||||
"title": "Anytype Page",
|
||||
"description": "This schema contains the base properties of Anytype Page and should be refereed if you want to extend it",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "https://anytype.io/schemas/relation"
|
||||
},
|
||||
"uniqueItems": true,
|
||||
"default": [
|
||||
{
|
||||
"id": "id",
|
||||
"name": "ID",
|
||||
"isHidden": true,
|
||||
"isReadonly": true,
|
||||
"type": "https://anytype.io/schemas/types/page"
|
||||
},
|
||||
{
|
||||
"id": "name",
|
||||
"name": "Name",
|
||||
"type": "https://anytype.io/schemas/types/title"
|
||||
},
|
||||
{
|
||||
"id": "iconEmoji",
|
||||
"name": "Emoji",
|
||||
"isHidden": true,
|
||||
"type": "https://anytype.io/schemas/types/emoji"
|
||||
},
|
||||
{
|
||||
"id": "iconImage",
|
||||
"name": "Image",
|
||||
"isHidden": true,
|
||||
"type": "https://anytype.io/schemas/types/image"
|
||||
},
|
||||
{
|
||||
"id": "isArchived",
|
||||
"name": "Archived",
|
||||
"isHidden": true,
|
||||
"type": "https://anytype.io/schemas/types/checkbox"
|
||||
},
|
||||
{
|
||||
"id": "lastOpened",
|
||||
"name": "Last opened",
|
||||
"isHidden": false,
|
||||
"isReadonly": true,
|
||||
"type": "https://anytype.io/schemas/types/date"
|
||||
},
|
||||
{
|
||||
"id": "lastModified",
|
||||
"name": "Last modified",
|
||||
"isHidden": false,
|
||||
"isReadonly": true,
|
||||
"type": "https://anytype.io/schemas/types/date"
|
||||
},
|
||||
{
|
||||
"id": "coverType",
|
||||
"name": "Cover Type",
|
||||
"isHidden": true,
|
||||
"type": "https://anytype.io/schemas/types/coverType"
|
||||
},
|
||||
{
|
||||
"id": "coverId",
|
||||
"name": "Predefined ID or Image",
|
||||
"isHidden": true,
|
||||
"type": "https://anytype.io/schemas/types/image"
|
||||
},
|
||||
{
|
||||
"id": "coverX",
|
||||
"name": "Cover x offset",
|
||||
"isHidden": true,
|
||||
"type": "https://anytype.io/schemas/types/number"
|
||||
},
|
||||
{
|
||||
"id": "coverY",
|
||||
"name": "Cover y offset",
|
||||
"isHidden": true,
|
||||
"type": "https://anytype.io/schemas/types/number"
|
||||
},
|
||||
{
|
||||
"id": "coverScale",
|
||||
"name": "Cover scale",
|
||||
"isHidden": true,
|
||||
"type": "https://anytype.io/schemas/types/number"
|
||||
}
|
||||
]
|
||||
}
|
||||
`,
|
||||
"https://anytype.io/schemas/person" : `{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"id": "https://anytype.io/schemas/person",
|
||||
"title": "Anytype Page",
|
||||
"description": "This schema contains the base properties of Anytype Person",
|
||||
|
||||
"allOf": [
|
||||
{ "$ref": "https://anytype.io/schemas/page" }
|
||||
],
|
||||
|
||||
"type": "object"
|
||||
}
|
||||
`,
|
||||
"https://anytype.io/schemas/relation" : `{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"id": "https://anytype.io/schemas/relation",
|
||||
"title": "Anytype Page",
|
||||
"description": "This schema contains relation and all type definitions",
|
||||
"type": "object",
|
||||
"$comment": "fills relation from specific details",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"$comment": "detail's ID"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"$comment": "json schema $id for the relation type, starting from https://anytype.io/schemas/types/"
|
||||
},
|
||||
"objectType": {
|
||||
"type": "string",
|
||||
"$comment": "json schema $id of the object type for relations with the object type, e.g. https://anytype.io/schemas/page"
|
||||
},
|
||||
"isMulti": {
|
||||
"type": "boolean",
|
||||
"$comment": "multiple fields of the same type grouped in the array. allowed for: select, image, file, object"
|
||||
},
|
||||
"isHidden": {
|
||||
"type": "boolean",
|
||||
"$comment": "presented in the dataset, may be rendered with some view types but should be hided in the relations list"
|
||||
},
|
||||
"isReadonly": {
|
||||
"type": "boolean",
|
||||
"$comment": "not existing in the page's details, added afterwards"
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"title": {
|
||||
"$id": "https://anytype.io/schemas/types/title",
|
||||
"type": "string",
|
||||
"description": "Title renders name plus first emoji/image relation for the same relation"
|
||||
},
|
||||
"description": {
|
||||
"$id": "https://anytype.io/schemas/types/description",
|
||||
"type": "string"
|
||||
},
|
||||
"select": {
|
||||
"$id": "https://anytype.io/schemas/types/select",
|
||||
"type": "string"
|
||||
},
|
||||
"number": {
|
||||
"$id": "https://anytype.io/schemas/types/number",
|
||||
"type": "number"
|
||||
},
|
||||
"url": {
|
||||
"$id": "https://anytype.io/schemas/types/url",
|
||||
"type": "string",
|
||||
"description": "External URL",
|
||||
"format": "uri"
|
||||
},
|
||||
"email": {
|
||||
"$id": "https://anytype.io/schemas/types/email",
|
||||
"type": "string",
|
||||
"format": "email"
|
||||
},
|
||||
"phone": {
|
||||
"$id": "https://anytype.io/schemas/types/phone",
|
||||
"type": "string"
|
||||
},
|
||||
"date": {
|
||||
"$id": "https://anytype.io/schemas/types/date",
|
||||
"type": "string",
|
||||
"description": "UNIX timestamp as a string"
|
||||
},
|
||||
"checkbox": {
|
||||
"$id": "https://anytype.io/schemas/types/checkbox",
|
||||
"type": "boolean"
|
||||
},
|
||||
"object": {
|
||||
"$id": "https://anytype.io/schemas/types/object",
|
||||
"type": "string",
|
||||
"description": "ID of the object, e.g. page or person"
|
||||
},
|
||||
"image": {
|
||||
"$id": "https://anytype.io/schemas/types/image",
|
||||
"type": "string",
|
||||
"description": "CID of image node in the IPFS"
|
||||
},
|
||||
"file": {
|
||||
"$id": "https://anytype.io/schemas/types/file",
|
||||
"type": "string",
|
||||
"description": "CID of file node in the IPFS"
|
||||
},
|
||||
"emoji": {
|
||||
"$id": "https://anytype.io/schemas/types/emoji",
|
||||
"type": "string",
|
||||
"description": "One emoji as unicode"
|
||||
},
|
||||
"coverType": {
|
||||
"$id": "https://anytype.io/schemas/types/coverType",
|
||||
"enum": [
|
||||
0, "None",
|
||||
1, "Image",
|
||||
2, "Color",
|
||||
3, "Gradient",
|
||||
4, "Upload",
|
||||
5, "BgImage"
|
||||
],
|
||||
"description": "Page cover type"
|
||||
}
|
||||
}
|
||||
}
|
||||
`}
|
Loading…
Add table
Add a link
Reference in a new issue