Skip to content

Instantly share code, notes, and snippets.

@mikeal
Created October 11, 2019 20:55
Show Gist options
  • Select an option

  • Save mikeal/864d1a01fb43e8149d23631e55464ce7 to your computer and use it in GitHub Desktop.

Select an option

Save mikeal/864d1a01fb43e8149d23631e55464ce7 to your computer and use it in GitHub Desktop.

Revisions

  1. mikeal revised this gist Oct 11, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion example.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ const schema = `
    `
    const DataLayout = {
    testMethod: node => {
    node.value // <-- this needs to be cast as a type.
    node.value // <-- this internal needs to be cast as a type.
    return node.get('name')
    }
    }
  2. mikeal created this gist Oct 11, 2019.
    18 changes: 18 additions & 0 deletions example.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    const gen = require('ipld-schema-gen')
    const parse = require('ipld-schema')

    const schema = `
    type DataLayout map
    advanced DataLayout
    type Data bytes representation advanced DataLayout
    `
    const DataLayout = {
    testMethod: node => {
    node.value // <-- this needs to be cast as a type.
    return node.get('name')
    }
    }
    const classes = gen(parse(schema), { advanced: { DataLayout } })
    const hw = { name: 'hello world', i: 1 }
    const t = classes.Data.encoder(hw)
    t.testMethod() === 'hello world'
    71 changes: 71 additions & 0 deletions unixsfsv2.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    type LargeFlatByteList struct {
    indexes List
    parts List
    }

    type ByteLinkArray struct {
    indexes List
    parts List
    }

    type BytesUnion union {
    | Bytes "bytes"
    | &Bytes "bytesLink"
    | ByteLinkArray "byteLinkArray"
    | LargeFlatByteList "lfbl"
    } representation keyed

    type DataLayout struct {
    bytes BytesUnion
    size Int
    }

    type Files union {
    | Map "map"
    | Hamt "hamt"
    } representation keyed

    type FileUnion union {
    | File "file"
    | &File "fileLink"
    } representation keyed

    type Directory struct {
    name optional String
    size optional Int
    files Files
    }

    advanced DataLayout

    type Data bytes representation advanced DataLayout

    type Permissions struct {
    uid Int
    gid Int
    posix Int # The standard 0777 bitpacking masks

    sticky Bool (implicit "false")
    setuid Bool (implicit "false")
    setgid Bool (implicit "false")
    }

    type Attributes struct {
    mtime optional Int
    atime optional Int
    ctime optional Int
    mtime64 optional Int
    atime64 optional Int
    ctime64 optional Int

    permissions optional Permissions

    devMajor optional Int
    devMinor optional Int
    }

    type File struct {
    name optional String
    data optional Data
    size optional Int
    }