Skip to content

Instantly share code, notes, and snippets.

@mikeal
Created October 11, 2019 20:55
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 mikeal/864d1a01fb43e8149d23631e55464ce7 to your computer and use it in GitHub Desktop.
Save mikeal/864d1a01fb43e8149d23631e55464ce7 to your computer and use it in GitHub Desktop.
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 internal 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'
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment