Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@matildepark
Created October 16, 2020 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matildepark/268c758c079d6cf83fd1541b2430ff7f to your computer and use it in GitHub Desktop.
Save matildepark/268c758c079d6cf83fd1541b2430ff7f to your computer and use it in GitHub Desktop.
publish: graph-store migration

Following our Links migration to graph-store, our next application to migrate will be Publish. We expect it to deploy within the next week. This document is intended to help outline, for those of you making clients, how the JSON data structure is changing.

Original content

Given that:

  • we have one notebook by ~zod called "A new notebook",
  • with one post in it, titled "A note,"
  • with the content "With content in it", and
  • one comment that simply says "And a comment"...

Publish structure (old)

{
  notebooks: {
    ~zod: {
      a-new-notebook: {
        about: "",
        comments: true,
        date-created: 1602889710825,
        notes: {
          a-note: {
            author: "~zod",
            comments: [
              {
                ~2020.10.16..23.08.53..e9ba: {
                  author: "~zod",
                  content: "And a comment",
                  date-created: 1602889733913,
                  pending: false
                }
              }
            ],
            date-created: 1602889728234,
            file: ":-  :~
                [%author '~zod']
                [%last-modified '~2020.10.16..23.08.48..3bf0']
                [%title 'A note']
                [%date-created '~2020.10.16..23.08.48..3bf0']
                  ==
              ;>
              With content in it",
            next-note: null,
            note-id: "a-note",
            num-comments: 1,
            pending: false,
            prev-note: null,
            read: true,
            snippet: "With content in it",
            title: "A note"
          }
        },
        notes-by-date: [
          "a-note"
        ],
        num-notes: 2,
        num-unread: 0,
        subscribers: [],
        subscribers-group-path: "/ship/~zod/a-new-notebook",
        title: "A new notebook",
        writers: ["~zod"],
        writers-group-path: "/ship/~zod/a-new-notebook"
      }
    }
  }
}

graph-store structure (new)

{
  graphs: {
    zod/a-new-notebook: Map([
      0: {
        key: 1602887908525,
        value: {
          children: Map([
            0: {
              key: 2,
              value: {
                children: Map([
                  0: {
                    key: 1602887912438,
                    value: {
                      children: Map([]),
                      post: {
                        author: zod,
                        contents: [
                          {
                            text: "And a comment"
                          }
                        ],
                        hash: null,
                        index: "/1602887908525/2/1602887912438",
                        signatures: [],
                        time-sent: 1602887912438
                      }
                    }
                  }
                ]),
                post: {
                  author: "zod",
                  contents: [],
                  hash: null,
                  index: "/1602887908525/2",
                  signatures: [],
                  time-sent: 1602887908525
                }
              }
            },
            1: {
              key: 1,
              value: {
                children: Map([
                  0: {
                    key: 1,
                    value: {
                      children: Map([]),
                      post: {
                        author: "zod",
                        contents: [
                          {
                            text: "A note"
                          },
                          {
                            text: "With content in it"
                          }
                        ],
                        hash: null,
                        index: "/1602887908525/1/1",
                        signatures: [],
                        time-sent: 1602887908525
                      }
                    }
                  }
                ]),
                post: {
                  author: "zod",
                  contents: [],
                  hash: null,
                  index: "/1602887908525/1",
                  signatures: [],
                  time-sent: 1602887908525
                }
              }
            }
          ]),
          post: {
            author: "zod",
            contents: [],
            hash: null,
            index: "/1602887908525",
            signatures: [],
            time-sent: 1602887908525
          }
        }
      }
    ])
  }
}
@tylershuster
Copy link

If I’m reading this correctly, the title is now declared solely by convention, and there is no explicit title declaration. Is that correct?

@matildepark
Copy link
Author

Seems to be the parent node! @liam-fitzgerald

@liam-fitzgerald
Copy link

The title is the first item in the contents array. To clarify:
A publish notebook is now a graph in graph-store.
A publish note is a top-level node on this graph. This top level node has two children 1 and 2. 1 is a container for all the revisions of the note, keyed by date. 2 is a container for comments. The children of 1 are the revisions themselves, with the title as the first item in the contents array and the actual content as the second item. The children of 2 are simply comments, whose contents are a one-item array of the content of the comment. This may be easier to grok (if you can read hoon) by looking at the validator mark

/-  *post
|_  i=indexed-post
++  grow
  |%
  ++  noun  i
  --
++  grab
  |%
  :: +noun: Validate publish post
  :: 
  ++  noun
    |=  p=*
    =/  ip  ;;(indexed-post p)
    ?+    index.p.ip  !!
    ::  container for revisions
    ::
        [@ %1 ~]  
      ?>  ?=(~ contents.p.ip)
      ip
    ::  specific revision
    ::  first content is the title
    ::  revisions are numbered by the revision count
    ::  starting at one
        [@ %1 @ ~]
      ?>  ?=([* * ~] contents.p.ip)
      ?>  ?=(%text -.i.contents.p.ip)
      ?>  ?=(%text -.t.i.contents.p.ip)
      ip
    ::  container for comments
        [@ %2 ~]
      ?>  ?=(~ contents.p.ip)
      ip
    ::  comment
        [@ %2 @ ~]
      ?>  ?=([* ~] contents.p.ip)
      ?>  ?=(%text -.i.contents.p.ip)
      ip
    ::  top level post must have no content
        [@ ~]
      ?>  ?=(~ contents.p.ip)
      ip
    ==
  --
::
++  grad  %noun
--

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment