ipld-schema
Advanced tools
Comparing version 2.0.2 to 3.0.0
#!/usr/bin/env node | ||
const validate = require('./validate') | ||
const toJSON = require('./to-json') | ||
const toSchema = require('./to-schema') | ||
const jsonToSchema = require('./json-to-schema') | ||
import { validate } from './validate.js' | ||
import { toJSON } from './to-json.js' | ||
import { toSchema } from './to-schema.js' | ||
import { jsonToSchema } from './json-to-schema.js' | ||
import _yargs from 'yargs' | ||
import { hideBin } from 'yargs/helpers' | ||
@@ -16,3 +18,3 @@ const toOpts = { | ||
const yargs = require('yargs') | ||
const yargs = _yargs(hideBin(process.argv)) | ||
.scriptName('ipld-schema') | ||
@@ -19,0 +21,0 @@ .usage('$0 <cmd> [args]') |
@@ -1,3 +0,3 @@ | ||
const getStdin = require('get-stdin') | ||
const fs = require('fs').promises | ||
import getStdin from 'get-stdin' | ||
import fs from 'fs' | ||
@@ -29,6 +29,6 @@ function stripMarkdown (str) { | ||
async function read (filename) { | ||
return fs.readFile(filename, 'utf8') | ||
return fs.promises.readFile(filename, 'utf8') | ||
} | ||
async function collectInput (files) { | ||
export async function collectInput (files) { | ||
let input = [] | ||
@@ -64,3 +64,1 @@ | ||
} | ||
module.exports = collectInput |
#!/usr/bin/env node | ||
const print = require('../print') | ||
const collectInput = require('./collect-input') | ||
import { print } from '../print.js' | ||
import { collectInput } from './collect-input.js' | ||
let indent = ' ' | ||
async function toSchema (files, options) { | ||
export async function jsonToSchema (files, options) { | ||
if (options.tabs) { | ||
@@ -20,3 +20,1 @@ indent = '\t' | ||
} | ||
module.exports = toSchema |
#!/usr/bin/env node | ||
const parser = require('../parser') | ||
const { transformError } = require('../util') | ||
const collectInput = require('./collect-input') | ||
import * as parser from '../parser.cjs' | ||
import { transformError } from '../util.js' | ||
import { collectInput } from './collect-input.js' | ||
let indent = ' ' | ||
async function toJSON (files, options) { | ||
export async function toJSON (files, options) { | ||
if (options.tabs) { | ||
@@ -49,3 +49,1 @@ indent = '\t' | ||
} | ||
module.exports = toJSON |
#!/usr/bin/env node | ||
const parser = require('../parser') | ||
const print = require('../print') | ||
const { transformError } = require('../util') | ||
const collectInput = require('./collect-input') | ||
import * as parser from '../parser.cjs' | ||
import { print } from '../print.js' | ||
import { transformError } from '../util.js' | ||
import { collectInput } from './collect-input.js' | ||
let indent = ' ' | ||
async function toSchema (files, options) { | ||
export async function toSchema (files, options) { | ||
if (options.tabs) { | ||
@@ -40,3 +40,1 @@ indent = '\t' | ||
} | ||
module.exports = toSchema |
@@ -1,6 +0,6 @@ | ||
const parser = require('../parser') | ||
const { transformError } = require('../util') | ||
const collectInput = require('./collect-input') | ||
import * as parser from '../parser.cjs' | ||
import { transformError } from '../util.js' | ||
import { collectInput } from './collect-input.js' | ||
async function validate (files) { | ||
export async function validate (files) { | ||
const input = await collectInput(files) | ||
@@ -18,3 +18,1 @@ | ||
} | ||
module.exports = validate |
@@ -0,1 +1,26 @@ | ||
## [3.0.0](https://github.com/rvagg/js-ipld-schema/compare/v2.0.2...v3.0.0) (2022-08-13) | ||
### ⚠ BREAKING CHANGES | ||
* convert to ESM-only | ||
* adapt to latest major upstream spec changes | ||
### Features | ||
* convert to ESM-only ([2a86b2e](https://github.com/rvagg/js-ipld-schema/commit/2a86b2e7635e27ec611aef7d933714e3865a6605)) | ||
### Bug Fixes | ||
* adapt to latest major upstream spec changes ([f3f70ca](https://github.com/rvagg/js-ipld-schema/commit/f3f70ca300ccc935b8c66ab71607f05119f0036d)), closes [#45](https://github.com/rvagg/js-ipld-schema/issues/45) | ||
### Trivial Changes | ||
* **no-release:** bump actions/setup-node from 3.1.1 to 3.2.0 ([#62](https://github.com/rvagg/js-ipld-schema/issues/62)) ([a25f92a](https://github.com/rvagg/js-ipld-schema/commit/a25f92ab32b675430baa2b7c9262ead906504224)) | ||
* **no-release:** bump actions/setup-node from 3.2.0 to 3.3.0 ([#63](https://github.com/rvagg/js-ipld-schema/issues/63)) ([358ba3f](https://github.com/rvagg/js-ipld-schema/commit/358ba3f785265f65af70d9651f2a76c4653eaa5e)) | ||
* **no-release:** bump actions/setup-node from 3.3.0 to 3.4.0 ([#64](https://github.com/rvagg/js-ipld-schema/issues/64)) ([f8b83cd](https://github.com/rvagg/js-ipld-schema/commit/f8b83cda5f9552bc2d083746b8f3875397aed523)) | ||
* **no-release:** bump actions/setup-node from 3.4.0 to 3.4.1 ([#65](https://github.com/rvagg/js-ipld-schema/issues/65)) ([216dd76](https://github.com/rvagg/js-ipld-schema/commit/216dd76b790ac906d13d27544eb81387055b13cc)) | ||
### [2.0.2](https://github.com/rvagg/js-ipld-schema/compare/v2.0.1...v2.0.2) (2022-05-02) | ||
@@ -2,0 +27,0 @@ |
@@ -1,5 +0,5 @@ | ||
const parser = require('./parser') | ||
const { transformError } = require('./util') | ||
import * as parser from './parser.cjs' | ||
import { transformError } from './util.js' | ||
function parse (text) { | ||
export function parse (text) { | ||
try { | ||
@@ -11,3 +11,1 @@ return parser.parse(text) | ||
} | ||
module.exports.parse = parse |
{ | ||
"name": "ipld-schema", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "IPLD Schema parser and CLI utilities for JavaScript", | ||
"main": "./ipld-schema.js", | ||
"type": "module", | ||
"types": "./types.d.ts", | ||
"scripts": { | ||
"peg": "npm_config_yes=true npx pegjs -o parser.js ipld-schema.pegjs", | ||
"peg": "npm_config_yes=true npx pegjs -o parser.cjs ipld-schema.pegjs", | ||
"lint": "standard *.js test/*.js bin/*.js", | ||
@@ -13,2 +14,10 @@ "test": "npm run lint && mocha test/*-test.js", | ||
}, | ||
"exports": { | ||
".": { | ||
"import": "./ipld-schema.js" | ||
}, | ||
"./print.js": { | ||
"import": "./print.js" | ||
} | ||
}, | ||
"bin": { | ||
@@ -15,0 +24,0 @@ "ipld-schema": "bin/cli.js" |
65
print.js
@@ -8,3 +8,3 @@ const noop = (s) => s | ||
operator: noop, | ||
// number: noop, | ||
number: noop, | ||
string: noop, | ||
@@ -16,3 +16,3 @@ // comment: noop, | ||
function print (schema, indent = ' ', highlighter = {}) { | ||
export function print (schema, indent = ' ', highlighter = {}) { | ||
if (!schema || typeof schema.types !== 'object') { | ||
@@ -48,6 +48,2 @@ throw new Error('Invalid schema') | ||
for (const [type, defn] of Object.entries(schema.types)) { | ||
if (typeof defn.kind !== 'string') { | ||
throw new Error(`Invalid schema ${type} doesn't have a kind`) | ||
} | ||
str += `${highlighter.keyword('type')} ${highlighter.className(type)} ${printType(defn, indent, highlighter)}\n\n` | ||
@@ -59,16 +55,29 @@ } | ||
function kindFromDefinition (defn) { | ||
const [kind, more] = Object.keys(defn) | ||
if (!kind) { | ||
throw new Error('Invalid schema, missing kind') | ||
} | ||
if (more !== undefined) { | ||
throw new Error('Invalid schema more than one kind') | ||
} | ||
return kind | ||
} | ||
function printType (defn, indent, highlighter) { | ||
if (['map', 'list', 'link', 'copy'].includes(defn.kind)) { | ||
const kind = kindFromDefinition(defn) | ||
if (['map', 'list', 'link', 'copy'].includes(kind)) { | ||
return printTypeTerm(defn, indent, highlighter) | ||
} | ||
if (['struct', 'union', 'enum'].includes(defn.kind)) { | ||
return `${highlighter.builtin(defn.kind)} ${printTypeTerm(defn, indent, highlighter)}` | ||
if (['struct', 'union', 'enum'].includes(kind)) { | ||
return `${highlighter.builtin(kind)} ${printTypeTerm(defn, indent, highlighter)}` | ||
} | ||
if (defn.kind === 'bytes' && defn.representation && typeof defn.representation.advanced === 'string') { | ||
return `bytes ${highlighter.builtin('representation')} advanced ${defn.representation.advanced}` | ||
if ((kind === 'bytes' || kind === 'string') && defn[kind].representation && typeof defn[kind].representation.advanced === 'string') { | ||
return `${kind} ${highlighter.builtin('representation')} advanced ${defn[kind].representation.advanced}` | ||
} | ||
return defn.kind | ||
return kind | ||
} | ||
@@ -81,7 +90,9 @@ | ||
if (typeof printTypeTerm[defn.kind] !== 'function') { | ||
throw new Error(`Invalid schema unsupported kind (${defn.kind})`) | ||
const kind = kindFromDefinition(defn) | ||
if (typeof printTypeTerm[kind] !== 'function') { | ||
throw new Error(`Invalid schema unsupported kind (${kind})`) | ||
} | ||
return printTypeTerm[defn.kind](defn, indent, highlighter) | ||
return printTypeTerm[kind](defn[kind], indent, highlighter) | ||
} | ||
@@ -162,3 +173,8 @@ | ||
if (hasImplicit) { | ||
fieldRepr += `${highlighter.keyword('implicit')} ${highlighter.string(`"${fr.implicit}"`)}` | ||
const impl = typeof fr.implicit === 'string' | ||
? highlighter.string(`"${fr.implicit}"`) | ||
: typeof fr.implicit === 'number' | ||
? highlighter.number(fr.implicit) | ||
: highlighter.keyword(fr.implicit) | ||
fieldRepr += `${highlighter.keyword('implicit')} ${impl}` | ||
} | ||
@@ -266,3 +282,14 @@ fieldRepr += highlighter.punctuation(')') | ||
str += `\n${highlighter.punctuation('}')} ${highlighter.builtin('representation')} kinded` | ||
} else if (repr === 'keyed' || repr === 'stringprefix' || repr === 'bytesprefix') { | ||
} else if (repr === 'stringprefix' || repr === 'bytesprefix') { | ||
if (typeof defn.representation[repr].prefixes !== 'object') { | ||
throw new Error(`Invalid schema, ${repr} unions require a representation prefixes map`) | ||
} | ||
for (const [key, type] of Object.entries(defn.representation[repr].prefixes)) { | ||
str += `\n${indent}${highlighter.punctuation('|')} ${printTypeTerm(type, indent, highlighter)} ${highlighter.string(`"${key}"`)}` | ||
} | ||
str += `\n${highlighter.punctuation('}')} ${highlighter.builtin('representation')} ${repr}` | ||
} else if (repr === 'keyed') { | ||
if (typeof defn.representation[repr] !== 'object') { | ||
throw new Error(`Invalid schema, ${repr} unions require a representation keyed map`) | ||
} | ||
for (const [key, type] of Object.entries(defn.representation[repr])) { | ||
@@ -318,3 +345,3 @@ str += `\n${indent}${highlighter.punctuation('|')} ${printTypeTerm(type, indent, highlighter)} ${highlighter.string(`"${key}"`)}` | ||
for (const ev of Object.keys(defn.members)) { | ||
for (const ev of defn.members) { | ||
str += `\n${indent}${highlighter.punctuation('|')} ${ev}` | ||
@@ -334,3 +361,1 @@ const sv = (defn.representation.string && defn.representation.string[ev]) || | ||
} | ||
module.exports = print |
@@ -12,3 +12,3 @@ # ipld-schema | ||
```js | ||
const { parse } = require('ipld-schema') | ||
import { parse } from 'ipld-schema' | ||
@@ -29,14 +29,24 @@ let schema = parse(` | ||
// SimpleStruct: { | ||
// kind: 'struct', | ||
// fields: { | ||
// foo: { type: 'Int' }, | ||
// bar: { type: 'Bool' }, | ||
// baz: { type: 'String' } | ||
// }, | ||
// representation: { map: {} } | ||
// struct: { | ||
// fields: { | ||
// foo: { type: 'Int' }, | ||
// bar: { type: 'Bool' }, | ||
// baz: { type: 'String' } | ||
// }, | ||
// representation: { map: {} } | ||
// } | ||
// }, | ||
// MyMap: { kind: 'map', keyType: 'String', valueType: 'SimpleStruct' } | ||
// MyMap: { map: { keyType: 'String', valueType: 'SimpleStruct' } } | ||
// } | ||
``` | ||
You can also convert the parsed form back to DSL form with the `print` function: | ||
```js | ||
import { print } from 'ipld-schema/print.js' | ||
console.log(print(schema)) | ||
``` | ||
## Command line | ||
@@ -85,22 +95,24 @@ | ||
"SimpleStruct": { | ||
"kind": "struct", | ||
"fields": { | ||
"foo": { | ||
"type": "Int" | ||
"struct": { | ||
"fields": { | ||
"foo": { | ||
"type": "Int" | ||
}, | ||
"bar": { | ||
"type": "Bool" | ||
}, | ||
"baz": { | ||
"type": "String" | ||
} | ||
}, | ||
"bar": { | ||
"type": "Bool" | ||
}, | ||
"baz": { | ||
"type": "String" | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"MyMap": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "SimpleStruct" | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "SimpleStruct" | ||
} | ||
} | ||
@@ -107,0 +119,0 @@ } |
// A run-once script to split up schema-schema.ipldsch into a markdown file per type | ||
// for the purpose of test fixtures | ||
const fs = require('fs').promises | ||
const path = require('path') | ||
import fs from 'fs' | ||
import { fileURLToPath } from 'url' | ||
async function run () { | ||
let schemaText = await fs.readFile(path.join(__dirname, 'fixtures/schema-schema.ipldsch'), 'utf8') | ||
let schemaText = await fs.promises.readFile(new URL('./fixtures/schema-schema.ipldsch', import.meta.url), 'utf8') | ||
schemaText = schemaText.split('\n') | ||
const outDir = path.join(__dirname, 'fixtures/schema-schema/') | ||
await fs.mkdir(outDir, { recursive: true }) | ||
const outDir = new URL('./fixtures/schema-schema/', import.meta.url) | ||
await fs.promises.mkdir(outDir, { recursive: true }) | ||
@@ -23,5 +23,5 @@ let block = [] | ||
block.push('') | ||
const file = path.join(outDir, `${inType}.md`) | ||
await fs.writeFile(file, block.join('\n'), 'utf8') | ||
console.log('Wrote', inType, 'to', file) | ||
const file = new URL(`${inType}.md`, outDir) | ||
await fs.promises.writeFile(file, block.join('\n'), 'utf8') | ||
console.log('Wrote', inType, 'to', fileURLToPath(file)) | ||
block = [] | ||
@@ -28,0 +28,0 @@ inType = null |
/* eslint-env mocha */ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const yaml = require('js-yaml') | ||
const { parse } = require('../ipld-schema') | ||
const print = require('../print') | ||
const { assert } = require('chai') | ||
import fs from 'fs' | ||
import yaml from 'js-yaml' | ||
import { parse } from '../ipld-schema.js' | ||
import { print } from '../print.js' | ||
import { assert } from 'chai' | ||
describe('fixtures/bulk', () => { | ||
fs.readdirSync(path.join(__dirname, 'fixtures/bulk')).forEach((f) => { | ||
fs.readdirSync(new URL('./fixtures/bulk/', import.meta.url)).forEach((f) => { | ||
if (!f.endsWith('.yml')) { | ||
@@ -32,3 +31,3 @@ return | ||
const expected = fixture.canonical || fixture.schema | ||
assert.deepStrictEqual(schemaCanonical, expected.replace(/\n+$/, ''), `canonicalizing ${testName}`) | ||
assert.deepStrictEqual(schemaCanonical.replace(/\n+$/gm, ''), expected.replace(/\n+$/gm, ''), `canonicalizing ${testName}`) | ||
}) | ||
@@ -40,3 +39,3 @@ }) | ||
async function loadFixture (file) { | ||
const yamlContent = await fs.promises.readFile(path.join(__dirname, 'fixtures/bulk', file), 'utf8') | ||
const yamlContent = await fs.promises.readFile(new URL(file, new URL('./fixtures/bulk/', import.meta.url)), 'utf8') | ||
const fixture = yaml.load(yamlContent) | ||
@@ -43,0 +42,0 @@ fixture.expected = JSON.parse(fixture.expected) |
/* eslint-env mocha */ | ||
const path = require('path') | ||
const fs = require('fs/promises') | ||
const { execFile } = require('child_process') | ||
const { promisify } = require('util') | ||
const { assert } = require('chai') | ||
import path from 'path' | ||
import fs from 'fs' | ||
import { execFile } from 'child_process' | ||
import { promisify } from 'util' | ||
import { fileURLToPath } from 'url' | ||
import { assert } from 'chai' | ||
const execFileP = promisify(execFile) | ||
@@ -12,5 +14,5 @@ | ||
it('examples to-json ipldsch', async () => { | ||
const inFile = path.join(__dirname, 'fixtures/examples.ipldsch') | ||
const cli = require.resolve('../bin/cli.js') | ||
const expectedSchema = require(path.join(__dirname, 'fixtures/examples.ipldsch.json')) | ||
const inFile = fileURLToPath(new URL('./fixtures/examples.ipldsch', import.meta.url)) | ||
const cli = fileURLToPath(new URL('../bin/cli.js', import.meta.url)) | ||
const expectedSchema = JSON.parse(await fs.promises.readFile(new URL('./fixtures/examples.ipldsch.json', import.meta.url))) | ||
@@ -29,5 +31,5 @@ const { stdout, stderr } = await execFileP(process.execPath, [cli, 'to-json', inFile]) | ||
it('examples-adl to-json ipldsch', async () => { | ||
const inFile = path.join(__dirname, 'fixtures/examples-adl.ipldsch') | ||
const cli = require.resolve('../bin/cli.js') | ||
const expectedSchema = require(path.join(__dirname, 'fixtures/examples-adl.ipldsch.json')) | ||
const inFile = fileURLToPath(new URL('./fixtures/examples-adl.ipldsch', import.meta.url)) | ||
const cli = fileURLToPath(new URL('../bin/cli.js', import.meta.url)) | ||
const expectedSchema = JSON.parse(await fs.promises.readFile(new URL('./fixtures/examples-adl.ipldsch.json', import.meta.url))) | ||
@@ -41,5 +43,5 @@ const { stdout, stderr } = await execFileP(process.execPath, [cli, 'to-json', inFile]) | ||
it('examples to-json md', async () => { | ||
const inFile = path.join(__dirname, 'fixtures/examples.ipldsch.md') | ||
const cli = require.resolve('../bin/cli.js') | ||
const expectedSchema = require(path.join(__dirname, 'fixtures/examples.ipldsch.json')) | ||
const inFile = fileURLToPath(new URL('./fixtures/examples.ipldsch.md', import.meta.url)) | ||
const cli = fileURLToPath(new URL('../bin/cli.js', import.meta.url)) | ||
const expectedSchema = JSON.parse(await fs.promises.readFile(new URL('./fixtures/examples.ipldsch.json', import.meta.url))) | ||
@@ -55,4 +57,4 @@ const { stdout, stderr } = await execFileP(process.execPath, [cli, 'to-json', inFile]) | ||
const filename = 'examples.ipldsch.md' | ||
const inFile = path.join(__dirname, 'fixtures', filename) | ||
const cli = require.resolve('../bin/cli.js') | ||
const inFile = fileURLToPath(new URL(filename, new URL('./fixtures/', import.meta.url))) | ||
const cli = fileURLToPath(new URL('../bin/cli.js', import.meta.url)) | ||
@@ -66,4 +68,4 @@ const { stdout, stderr } = await execFileP(process.execPath, [cli, 'validate', inFile]) | ||
const filename = 'examples.ipldsch.md' | ||
const inFile = path.join(__dirname, 'fixtures', filename) | ||
const cli = require.resolve('../bin/cli.js') | ||
const inFile = fileURLToPath(new URL(filename, new URL('./fixtures/', import.meta.url))) | ||
const cli = fileURLToPath(new URL('../bin/cli.js', import.meta.url)) | ||
@@ -76,6 +78,6 @@ const { stdout, stderr } = await execFileP(process.execPath, [cli, 'validate', inFile]) | ||
it('validate failure', async () => { | ||
const inFile = path.join(__dirname, 'bork.ipldsch') | ||
const cli = require.resolve('../bin/cli.js') | ||
const inFile = fileURLToPath(new URL('bork.ipldsch', import.meta.url)) | ||
const cli = fileURLToPath(new URL('../bin/cli.js', import.meta.url)) | ||
await fs.writeFile(inFile, 'type Nope NopeNopeNope Nopity Nope nope [&{!') | ||
await fs.promises.writeFile(inFile, 'type Nope NopeNopeNope Nopity Nope nope [&{!') | ||
let failed = false | ||
@@ -90,3 +92,3 @@ try { | ||
} finally { | ||
await fs.unlink(inFile) | ||
await fs.promises.unlink(inFile) | ||
} | ||
@@ -99,5 +101,5 @@ if (!failed) { | ||
it('schema-schema multi md validate', async () => { | ||
const inDir = path.join(__dirname, 'fixtures/schema-schema/') | ||
const files = (await fs.readdir(inDir)).map((f) => path.join(inDir, f)) | ||
const cli = require.resolve('../bin/cli.js') | ||
const inDir = fileURLToPath(new URL('./fixtures/schema-schema/', import.meta.url)) | ||
const files = (await fs.promises.readdir(inDir)).map((f) => path.join(inDir, f)) | ||
const cli = fileURLToPath(new URL('../bin/cli.js', import.meta.url)) | ||
@@ -112,6 +114,6 @@ const { stdout, stderr } = await execFileP(process.execPath, [cli, 'validate'].concat(files)) | ||
it('schema-schema multi md to-json', async () => { | ||
const inDir = path.join(__dirname, 'fixtures/schema-schema/') | ||
const files = (await fs.readdir(inDir)).map((f) => path.join(inDir, f)) | ||
const cli = require.resolve('../bin/cli.js') | ||
const expectedSchema = require(path.join(__dirname, 'fixtures/schema-schema.ipldsch.json')) | ||
const inDir = fileURLToPath(new URL('./fixtures/schema-schema/', import.meta.url)) | ||
const files = (await fs.promises.readdir(inDir)).map((f) => path.join(inDir, f)) | ||
const cli = fileURLToPath(new URL('../bin/cli.js', import.meta.url)) | ||
const expectedSchema = JSON.parse(await fs.promises.readFile(new URL('./fixtures/schema-schema.ipldsch.json', import.meta.url))) | ||
@@ -126,6 +128,6 @@ const { stdout, stderr } = await execFileP(process.execPath, [cli, 'to-json'].concat(files)) | ||
it('schema-schema multi md to-json', async () => { | ||
const inDir = path.join(__dirname, 'fixtures/schema-schema/') | ||
const files = (await fs.readdir(inDir)).map((f) => path.join(inDir, f)) | ||
const cli = require.resolve('../bin/cli.js') | ||
const expectedSchema = require(path.join(__dirname, 'fixtures/schema-schema.ipldsch.json')) | ||
const inDir = fileURLToPath(new URL('./fixtures/schema-schema/', import.meta.url)) | ||
const files = (await fs.promises.readdir(inDir)).map((f) => path.join(inDir, f)) | ||
const cli = fileURLToPath(new URL('../bin/cli.js', import.meta.url)) | ||
const expectedSchema = JSON.parse(await fs.promises.readFile(new URL('./fixtures/schema-schema.ipldsch.json', import.meta.url))) | ||
@@ -141,7 +143,7 @@ const { stdout, stderr } = await execFileP(process.execPath, [cli, 'to-json'].concat(files)) | ||
const inFiles = [ | ||
path.join(__dirname, 'fixtures/examples.ipldsch'), | ||
path.join(__dirname, 'fixtures/examples-adl.ipldsch') | ||
fileURLToPath(new URL('./fixtures/examples.ipldsch', import.meta.url)), | ||
fileURLToPath(new URL('./fixtures/examples-adl.ipldsch', import.meta.url)) | ||
] | ||
const cli = require.resolve('../bin/cli.js') | ||
const expectedSchema = require(path.join(__dirname, 'fixtures/examples-all.ipldsch.json')) | ||
const cli = fileURLToPath(new URL('../bin/cli.js', import.meta.url)) | ||
const expectedSchema = JSON.parse(await fs.promises.readFile(new URL('./fixtures/examples-all.ipldsch.json', import.meta.url))) | ||
@@ -148,0 +150,0 @@ const { stdout, stderr } = await execFileP(process.execPath, [cli, 'to-json'].concat(inFiles)) |
/* eslint-env mocha */ | ||
const fs = require('fs/promises') | ||
const path = require('path') | ||
const { parse } = require('../ipld-schema') | ||
const { assert } = require('chai') | ||
import fs from 'fs' | ||
import { parse } from '../ipld-schema.js' | ||
import { assert } from 'chai' | ||
it('examples', async () => { | ||
const schemaText = await fs.readFile(path.join(__dirname, 'fixtures/examples.ipldsch'), 'utf8') | ||
const schemaText = await fs.promises.readFile(new URL('./fixtures/examples.ipldsch', import.meta.url), 'utf8') | ||
const schema = parse(schemaText) | ||
const expectedSchema = require(path.join(__dirname, 'fixtures/examples.ipldsch.json')) | ||
const expectedSchema = JSON.parse(await fs.promises.readFile(new URL('./fixtures/examples.ipldsch.json', import.meta.url))) | ||
assert.deepStrictEqual(schema, expectedSchema) | ||
}) |
{ | ||
"advanced": { | ||
"FunkyBytes": { | ||
"kind": "advanced" | ||
"advanced": {} | ||
}, | ||
"FunkyVector": { | ||
"kind": "advanced" | ||
"advanced": {} | ||
} | ||
@@ -12,70 +12,80 @@ }, | ||
"MyFunkyBytes": { | ||
"kind": "bytes", | ||
"representation": { | ||
"advanced": "FunkyBytes" | ||
"bytes": { | ||
"representation": { | ||
"advanced": "FunkyBytes" | ||
} | ||
} | ||
}, | ||
"MyFunkyVector": { | ||
"kind": "list", | ||
"valueType": { | ||
"kind": "link", | ||
"expectedType": "MyFunkyBytes" | ||
}, | ||
"representation": { | ||
"advanced": "FunkyVector" | ||
"list": { | ||
"valueType": { | ||
"link": { | ||
"expectedType": "MyFunkyBytes" | ||
} | ||
}, | ||
"representation": { | ||
"advanced": "FunkyVector" | ||
} | ||
} | ||
}, | ||
"ADLExample": { | ||
"kind": "struct", | ||
"fields": { | ||
"fooField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "MyFunkyBytes" | ||
"struct": { | ||
"fields": { | ||
"fooField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "MyFunkyBytes" | ||
} | ||
}, | ||
"optional": true | ||
}, | ||
"optional": true | ||
}, | ||
"barField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "String" | ||
"barField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "String" | ||
} | ||
}, | ||
"nullable": true | ||
}, | ||
"nullable": true | ||
}, | ||
"bazField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "MyFunkyBytes", | ||
"valueNullable": true | ||
} | ||
}, | ||
"wozField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": { | ||
"kind": "list", | ||
"valueType": "String", | ||
"valueNullable": true | ||
"bazField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "MyFunkyBytes", | ||
"valueNullable": true | ||
} | ||
} | ||
}, | ||
"wozField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": { | ||
"list": { | ||
"valueType": "String", | ||
"valueNullable": true | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"boomField": { | ||
"type": { | ||
"link": { | ||
"expectedType": "ExampleWithNullable" | ||
} | ||
} | ||
}, | ||
"funkyField": { | ||
"type": "MyFunkyVector" | ||
} | ||
}, | ||
"boomField": { | ||
"type": { | ||
"kind": "link", | ||
"expectedType": "ExampleWithNullable" | ||
} | ||
}, | ||
"funkyField": { | ||
"type": "MyFunkyVector" | ||
} | ||
}, | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"fooField": { | ||
"rename": "foo_field" | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"fooField": { | ||
"rename": "foo_field" | ||
} | ||
} | ||
@@ -82,0 +92,0 @@ } |
{ | ||
"advanced": { | ||
"FunkyBytes": { | ||
"kind": "advanced" | ||
"advanced": {} | ||
}, | ||
"FunkyVector": { | ||
"kind": "advanced" | ||
"advanced": {} | ||
} | ||
@@ -12,70 +12,80 @@ }, | ||
"MyFunkyBytes": { | ||
"kind": "bytes", | ||
"representation": { | ||
"advanced": "FunkyBytes" | ||
"bytes": { | ||
"representation": { | ||
"advanced": "FunkyBytes" | ||
} | ||
} | ||
}, | ||
"MyFunkyVector": { | ||
"kind": "list", | ||
"valueType": { | ||
"kind": "link", | ||
"expectedType": "MyFunkyBytes" | ||
}, | ||
"representation": { | ||
"advanced": "FunkyVector" | ||
"list": { | ||
"valueType": { | ||
"link": { | ||
"expectedType": "MyFunkyBytes" | ||
} | ||
}, | ||
"representation": { | ||
"advanced": "FunkyVector" | ||
} | ||
} | ||
}, | ||
"ADLExample": { | ||
"kind": "struct", | ||
"fields": { | ||
"fooField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "MyFunkyBytes" | ||
"struct": { | ||
"fields": { | ||
"fooField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "MyFunkyBytes" | ||
} | ||
}, | ||
"optional": true | ||
}, | ||
"optional": true | ||
}, | ||
"barField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "String" | ||
"barField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "String" | ||
} | ||
}, | ||
"nullable": true | ||
}, | ||
"nullable": true | ||
}, | ||
"bazField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "MyFunkyBytes", | ||
"valueNullable": true | ||
} | ||
}, | ||
"wozField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": { | ||
"kind": "list", | ||
"valueType": "String", | ||
"valueNullable": true | ||
"bazField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "MyFunkyBytes", | ||
"valueNullable": true | ||
} | ||
} | ||
}, | ||
"wozField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": { | ||
"list": { | ||
"valueType": "String", | ||
"valueNullable": true | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"boomField": { | ||
"type": { | ||
"link": { | ||
"expectedType": "ExampleWithNullable" | ||
} | ||
} | ||
}, | ||
"funkyField": { | ||
"type": "MyFunkyVector" | ||
} | ||
}, | ||
"boomField": { | ||
"type": { | ||
"kind": "link", | ||
"expectedType": "ExampleWithNullable" | ||
} | ||
}, | ||
"funkyField": { | ||
"type": "MyFunkyVector" | ||
} | ||
}, | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"fooField": { | ||
"rename": "foo_field" | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"fooField": { | ||
"rename": "foo_field" | ||
} | ||
} | ||
@@ -87,59 +97,69 @@ } | ||
"ExampleWithNullable": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": { | ||
"kind": "link" | ||
}, | ||
"valueNullable": true | ||
"map": { | ||
"keyType": "String", | ||
"valueType": { | ||
"link": { | ||
"expectedType": "Any" | ||
} | ||
}, | ||
"valueNullable": true | ||
} | ||
}, | ||
"ExampleWithAnonDefns": { | ||
"kind": "struct", | ||
"fields": { | ||
"fooField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "String" | ||
"struct": { | ||
"fields": { | ||
"fooField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "String" | ||
} | ||
}, | ||
"optional": true | ||
}, | ||
"optional": true | ||
}, | ||
"barField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "String" | ||
"barField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "String" | ||
} | ||
}, | ||
"nullable": true | ||
}, | ||
"nullable": true | ||
}, | ||
"bazField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "String", | ||
"valueNullable": true | ||
} | ||
}, | ||
"wozField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": { | ||
"kind": "list", | ||
"valueType": "String", | ||
"valueNullable": true | ||
"bazField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "String", | ||
"valueNullable": true | ||
} | ||
} | ||
}, | ||
"wozField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": { | ||
"list": { | ||
"valueType": "String", | ||
"valueNullable": true | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"boomField": { | ||
"type": { | ||
"link": { | ||
"expectedType": "ExampleWithNullable" | ||
} | ||
} | ||
} | ||
}, | ||
"boomField": { | ||
"type": { | ||
"kind": "link", | ||
"expectedType": "ExampleWithNullable" | ||
} | ||
} | ||
}, | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"fooField": { | ||
"rename": "foo_field" | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"fooField": { | ||
"rename": "foo_field" | ||
} | ||
} | ||
@@ -146,0 +166,0 @@ } |
{ | ||
"types": { | ||
"ExampleWithNullable": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": { | ||
"kind": "link" | ||
}, | ||
"valueNullable": true | ||
"map": { | ||
"keyType": "String", | ||
"valueType": { | ||
"link": { | ||
"expectedType": "Any" | ||
} | ||
}, | ||
"valueNullable": true | ||
} | ||
}, | ||
"ExampleWithAnonDefns": { | ||
"kind": "struct", | ||
"fields": { | ||
"fooField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "String" | ||
}, | ||
"optional": true | ||
}, | ||
"barField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "String" | ||
}, | ||
"nullable": true | ||
}, | ||
"bazField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "String", | ||
"valueNullable": true | ||
} | ||
}, | ||
"wozField": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": { | ||
"kind": "list", | ||
"valueType": "String", | ||
"valueNullable": true | ||
} | ||
} | ||
}, | ||
"boomField": { | ||
"type": { | ||
"kind": "link", | ||
"expectedType": "ExampleWithNullable" | ||
} | ||
} | ||
}, | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"fooField": { | ||
"rename": "foo_field" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
"struct": { | ||
"fields": { | ||
"fooField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "String" | ||
} | ||
}, | ||
"optional": true | ||
}, | ||
"barField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "String" | ||
} | ||
}, | ||
"nullable": true | ||
}, | ||
"bazField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "String", | ||
"valueNullable": true | ||
} | ||
} | ||
}, | ||
"wozField": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": { | ||
"list": { | ||
"valueType": "String", | ||
"valueNullable": true | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"boomField": { | ||
"type": { | ||
"link": { | ||
"expectedType": "ExampleWithNullable" | ||
} | ||
} | ||
} | ||
}, | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"fooField": { | ||
"rename": "foo_field" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
{ | ||
"types": { | ||
"Schema": { | ||
"struct": { | ||
"fields": { | ||
"types": { | ||
"type": { | ||
"map": { | ||
"keyType": "TypeName", | ||
"valueType": "TypeDefn" | ||
} | ||
} | ||
}, | ||
"advanced": { | ||
"type": "AdvancedDataLayoutMap", | ||
"optional": true | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeName": { | ||
"kind": "string" | ||
"string": {} | ||
}, | ||
"SchemaMap": { | ||
"kind": "map", | ||
"keyType": "TypeName", | ||
"valueType": "Type" | ||
}, | ||
"AdvancedDataLayoutName": { | ||
"kind": "string" | ||
"string": {} | ||
}, | ||
"AdvancedDataLayoutMap": { | ||
"kind": "map", | ||
"keyType": "AdvancedDataLayoutName", | ||
"valueType": "AdvancedDataLayout" | ||
}, | ||
"Schema": { | ||
"kind": "struct", | ||
"fields": { | ||
"types": { | ||
"type": "SchemaMap" | ||
}, | ||
"advanced": { | ||
"type": "AdvancedDataLayoutMap" | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
"map": { | ||
"keyType": "AdvancedDataLayoutName", | ||
"valueType": "AdvancedDataLayout" | ||
} | ||
}, | ||
"Type": { | ||
"kind": "union", | ||
"representation": { | ||
"inline": { | ||
"discriminantKey": "kind", | ||
"discriminantTable": { | ||
"bool": "TypeBool", | ||
"string": "TypeString", | ||
"bytes": "TypeBytes", | ||
"int": "TypeInt", | ||
"float": "TypeFloat", | ||
"map": "TypeMap", | ||
"list": "TypeList", | ||
"link": "TypeLink", | ||
"union": "TypeUnion", | ||
"struct": "TypeStruct", | ||
"enum": "TypeEnum", | ||
"copy": "TypeCopy" | ||
"TypeDefn": { | ||
"union": { | ||
"members": [ | ||
"TypeDefnBool", | ||
"TypeDefnString", | ||
"TypeDefnBytes", | ||
"TypeDefnInt", | ||
"TypeDefnFloat", | ||
"TypeDefnMap", | ||
"TypeDefnList", | ||
"TypeDefnLink", | ||
"TypeDefnUnion", | ||
"TypeDefnStruct", | ||
"TypeDefnEnum", | ||
"TypeDefnUnit", | ||
"TypeDefnAny", | ||
"TypeDefnCopy" | ||
], | ||
"representation": { | ||
"keyed": { | ||
"bool": "TypeDefnBool", | ||
"string": "TypeDefnString", | ||
"bytes": "TypeDefnBytes", | ||
"int": "TypeDefnInt", | ||
"float": "TypeDefnFloat", | ||
"map": "TypeDefnMap", | ||
"list": "TypeDefnList", | ||
"link": "TypeDefnLink", | ||
"union": "TypeDefnUnion", | ||
"struct": "TypeDefnStruct", | ||
"enum": "TypeDefnEnum", | ||
"unit": "TypeDefnUnit", | ||
"any": "TypeDefnAny", | ||
"copy": "TypeDefnCopy" | ||
} | ||
@@ -56,45 +75,80 @@ } | ||
"TypeKind": { | ||
"kind": "enum", | ||
"members": { | ||
"Bool": null, | ||
"String": null, | ||
"Bytes": null, | ||
"Int": null, | ||
"Float": null, | ||
"Map": null, | ||
"List": null, | ||
"Link": null, | ||
"Union": null, | ||
"Struct": null, | ||
"Enum": null | ||
}, | ||
"representation": { | ||
"string": {} | ||
"enum": { | ||
"members": [ | ||
"Bool", | ||
"String", | ||
"Bytes", | ||
"Int", | ||
"Float", | ||
"Map", | ||
"List", | ||
"Link", | ||
"Union", | ||
"Struct", | ||
"Enum", | ||
"Unit", | ||
"Any" | ||
], | ||
"representation": { | ||
"string": { | ||
"Bool": "bool", | ||
"String": "string", | ||
"Bytes": "bytes", | ||
"Int": "int", | ||
"Float": "float", | ||
"Map": "map", | ||
"List": "list", | ||
"Link": "link", | ||
"Union": "union", | ||
"Struct": "struct", | ||
"Enum": "enum", | ||
"Unit": "unit", | ||
"Any": "any" | ||
} | ||
} | ||
} | ||
}, | ||
"RepresentationKind": { | ||
"kind": "enum", | ||
"members": { | ||
"Bool": null, | ||
"String": null, | ||
"Bytes": null, | ||
"Int": null, | ||
"Float": null, | ||
"Map": null, | ||
"List": null, | ||
"Link": null | ||
}, | ||
"representation": { | ||
"string": {} | ||
"enum": { | ||
"members": [ | ||
"Bool", | ||
"String", | ||
"Bytes", | ||
"Int", | ||
"Float", | ||
"Map", | ||
"List", | ||
"Link" | ||
], | ||
"representation": { | ||
"string": { | ||
"Bool": "bool", | ||
"String": "string", | ||
"Bytes": "bytes", | ||
"Int": "int", | ||
"Float": "float", | ||
"Map": "map", | ||
"List": "list", | ||
"Link": "link" | ||
} | ||
} | ||
} | ||
}, | ||
"AnyScalar": { | ||
"kind": "union", | ||
"representation": { | ||
"kinded": { | ||
"bool": "Bool", | ||
"string": "String", | ||
"bytes": "Bytes", | ||
"int": "Int", | ||
"float": "Float" | ||
"union": { | ||
"members": [ | ||
"Bool", | ||
"String", | ||
"Bytes", | ||
"Int", | ||
"Float" | ||
], | ||
"representation": { | ||
"kinded": { | ||
"bool": "Bool", | ||
"string": "String", | ||
"bytes": "Bytes", | ||
"int": "Int", | ||
"float": "Float" | ||
} | ||
} | ||
@@ -104,39 +158,48 @@ } | ||
"AdvancedDataLayout": { | ||
"kind": "struct", | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
"struct": { | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeBool": { | ||
"kind": "struct", | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
"TypeDefnBool": { | ||
"struct": { | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeString": { | ||
"kind": "struct", | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
"TypeDefnString": { | ||
"struct": { | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeBytes": { | ||
"kind": "struct", | ||
"fields": { | ||
"TypeDefnBytes": { | ||
"struct": { | ||
"fields": { | ||
"representation": { | ||
"type": "BytesRepresentation" | ||
} | ||
}, | ||
"representation": { | ||
"type": "BytesRepresentation" | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"BytesRepresentation": { | ||
"kind": "union", | ||
"representation": { | ||
"keyed": { | ||
"bytes": "BytesRepresentation_Bytes", | ||
"advanced": "AdvancedDataLayoutName" | ||
"union": { | ||
"members": [ | ||
"BytesRepresentation_Bytes", | ||
"AdvancedDataLayoutName" | ||
], | ||
"representation": { | ||
"keyed": { | ||
"bytes": "BytesRepresentation_Bytes", | ||
"advanced": "AdvancedDataLayoutName" | ||
} | ||
} | ||
@@ -146,43 +209,48 @@ } | ||
"BytesRepresentation_Bytes": { | ||
"kind": "struct", | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
"struct": { | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeInt": { | ||
"kind": "struct", | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
"TypeDefnInt": { | ||
"struct": { | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeFloat": { | ||
"kind": "struct", | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
"TypeDefnFloat": { | ||
"struct": { | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeMap": { | ||
"kind": "struct", | ||
"fields": { | ||
"keyType": { | ||
"type": "TypeName" | ||
"TypeDefnMap": { | ||
"struct": { | ||
"fields": { | ||
"keyType": { | ||
"type": "TypeName" | ||
}, | ||
"valueType": { | ||
"type": "TypeNameOrInlineDefn" | ||
}, | ||
"valueNullable": { | ||
"type": "Bool" | ||
}, | ||
"representation": { | ||
"type": "MapRepresentation", | ||
"optional": true | ||
} | ||
}, | ||
"valueType": { | ||
"type": "TypeTerm" | ||
}, | ||
"valueNullable": { | ||
"type": "Bool" | ||
}, | ||
"representation": { | ||
"type": "MapRepresentation" | ||
} | ||
}, | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"valueNullable": { | ||
"implicit": false | ||
"map": { | ||
"fields": { | ||
"valueNullable": { | ||
"implicit": false | ||
} | ||
} | ||
@@ -194,58 +262,60 @@ } | ||
"MapRepresentation": { | ||
"kind": "union", | ||
"representation": { | ||
"keyed": { | ||
"map": "MapRepresentation_Map", | ||
"stringpairs": "MapRepresentation_StringPairs", | ||
"listpairs": "MapRepresentation_ListPairs", | ||
"advanced": "AdvancedDataLayoutName" | ||
"union": { | ||
"members": [ | ||
"MapRepresentation_StringPairs", | ||
"MapRepresentation_ListPairs", | ||
"AdvancedDataLayoutName" | ||
], | ||
"representation": { | ||
"keyed": { | ||
"stringpairs": "MapRepresentation_StringPairs", | ||
"listpairs": "MapRepresentation_ListPairs", | ||
"advanced": "AdvancedDataLayoutName" | ||
} | ||
} | ||
} | ||
}, | ||
"MapRepresentation_Map": { | ||
"kind": "struct", | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"MapRepresentation_StringPairs": { | ||
"kind": "struct", | ||
"fields": { | ||
"innerDelim": { | ||
"type": "String" | ||
"struct": { | ||
"fields": { | ||
"innerDelim": { | ||
"type": "String" | ||
}, | ||
"entryDelim": { | ||
"type": "String" | ||
} | ||
}, | ||
"entryDelim": { | ||
"type": "String" | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"MapRepresentation_ListPairs": { | ||
"kind": "struct", | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
"struct": { | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeList": { | ||
"kind": "struct", | ||
"fields": { | ||
"valueType": { | ||
"type": "TypeTerm" | ||
"TypeDefnList": { | ||
"struct": { | ||
"fields": { | ||
"valueType": { | ||
"type": "TypeNameOrInlineDefn" | ||
}, | ||
"valueNullable": { | ||
"type": "Bool" | ||
}, | ||
"representation": { | ||
"type": "ListRepresentation", | ||
"optional": true | ||
} | ||
}, | ||
"valueNullable": { | ||
"type": "Bool" | ||
}, | ||
"representation": { | ||
"type": "ListRepresentation" | ||
} | ||
}, | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"valueNullable": { | ||
"implicit": false | ||
"map": { | ||
"fields": { | ||
"valueNullable": { | ||
"implicit": false | ||
} | ||
} | ||
@@ -257,54 +327,95 @@ } | ||
"ListRepresentation": { | ||
"kind": "union", | ||
"representation": { | ||
"keyed": { | ||
"list": "ListRepresentation_List", | ||
"advanced": "AdvancedDataLayoutName" | ||
"union": { | ||
"members": [ | ||
"AdvancedDataLayoutName" | ||
], | ||
"representation": { | ||
"keyed": { | ||
"advanced": "AdvancedDataLayoutName" | ||
} | ||
} | ||
} | ||
}, | ||
"ListRepresentation_List": { | ||
"kind": "struct", | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
"TypeDefnLink": { | ||
"struct": { | ||
"fields": { | ||
"expectedType": { | ||
"type": "TypeName" | ||
} | ||
}, | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"expectedType": { | ||
"implicit": "Any" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"TypeLink": { | ||
"kind": "struct", | ||
"fields": { | ||
"expectedType": { | ||
"type": "String" | ||
} | ||
}, | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"expectedType": { | ||
"implicit": "Any" | ||
"TypeDefnUnion": { | ||
"struct": { | ||
"fields": { | ||
"members": { | ||
"type": { | ||
"list": { | ||
"valueType": "UnionMember" | ||
} | ||
} | ||
}, | ||
"representation": { | ||
"type": "UnionRepresentation" | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeUnion": { | ||
"kind": "struct", | ||
"fields": { | ||
"UnionMember": { | ||
"union": { | ||
"members": [ | ||
"TypeName", | ||
"UnionMemberInlineDefn" | ||
], | ||
"representation": { | ||
"type": "UnionRepresentation" | ||
"kinded": { | ||
"string": "TypeName", | ||
"map": "UnionMemberInlineDefn" | ||
} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"UnionMemberInlineDefn": { | ||
"union": { | ||
"members": [ | ||
"TypeDefnLink" | ||
], | ||
"representation": { | ||
"keyed": { | ||
"link": "TypeDefnLink" | ||
} | ||
} | ||
} | ||
}, | ||
"UnionRepresentation": { | ||
"kind": "union", | ||
"representation": { | ||
"keyed": { | ||
"kinded": "UnionRepresentation_Kinded", | ||
"keyed": "UnionRepresentation_Keyed", | ||
"envelope": "UnionRepresentation_Envelope", | ||
"inline": "UnionRepresentation_Inline", | ||
"bytesprefix": "UnionRepresentation_BytesPrefix" | ||
"union": { | ||
"members": [ | ||
"UnionRepresentation_Kinded", | ||
"UnionRepresentation_Keyed", | ||
"UnionRepresentation_Envelope", | ||
"UnionRepresentation_Inline", | ||
"UnionRepresentation_StringPrefix", | ||
"UnionRepresentation_BytesPrefix" | ||
], | ||
"representation": { | ||
"keyed": { | ||
"kinded": "UnionRepresentation_Kinded", | ||
"keyed": "UnionRepresentation_Keyed", | ||
"envelope": "UnionRepresentation_Envelope", | ||
"inline": "UnionRepresentation_Inline", | ||
"stringprefix": "UnionRepresentation_StringPrefix", | ||
"bytesprefix": "UnionRepresentation_BytesPrefix" | ||
} | ||
} | ||
@@ -314,97 +425,138 @@ } | ||
"UnionRepresentation_Kinded": { | ||
"kind": "map", | ||
"keyType": "RepresentationKind", | ||
"valueType": "TypeName" | ||
"map": { | ||
"keyType": "RepresentationKind", | ||
"valueType": "UnionMember" | ||
} | ||
}, | ||
"UnionRepresentation_Keyed": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "TypeName" | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "UnionMember" | ||
} | ||
}, | ||
"UnionRepresentation_Envelope": { | ||
"kind": "struct", | ||
"fields": { | ||
"discriminantKey": { | ||
"type": "String" | ||
"struct": { | ||
"fields": { | ||
"discriminantKey": { | ||
"type": "String" | ||
}, | ||
"contentKey": { | ||
"type": "String" | ||
}, | ||
"discriminantTable": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "UnionMember" | ||
} | ||
} | ||
} | ||
}, | ||
"contentKey": { | ||
"type": "String" | ||
}, | ||
"discriminantTable": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "TypeName" | ||
} | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"UnionRepresentation_Inline": { | ||
"kind": "struct", | ||
"fields": { | ||
"discriminantKey": { | ||
"type": "String" | ||
"struct": { | ||
"fields": { | ||
"discriminantKey": { | ||
"type": "String" | ||
}, | ||
"discriminantTable": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "TypeName" | ||
} | ||
} | ||
} | ||
}, | ||
"discriminantTable": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "TypeName" | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"UnionRepresentation_StringPrefix": { | ||
"struct": { | ||
"fields": { | ||
"prefixes": { | ||
"type": { | ||
"map": { | ||
"keyType": "String", | ||
"valueType": "TypeName" | ||
} | ||
} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"UnionRepresentation_BytesPrefix": { | ||
"kind": "map", | ||
"keyType": "String", | ||
"valueType": "TypeName" | ||
"struct": { | ||
"fields": { | ||
"prefixes": { | ||
"type": { | ||
"map": { | ||
"keyType": "HexString", | ||
"valueType": "TypeName" | ||
} | ||
} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeStruct": { | ||
"kind": "struct", | ||
"fields": { | ||
"HexString": { | ||
"string": {} | ||
}, | ||
"TypeDefnStruct": { | ||
"struct": { | ||
"fields": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "FieldName", | ||
"valueType": "StructField" | ||
"fields": { | ||
"type": { | ||
"map": { | ||
"keyType": "FieldName", | ||
"valueType": "StructField" | ||
} | ||
} | ||
}, | ||
"representation": { | ||
"type": "StructRepresentation" | ||
} | ||
}, | ||
"representation": { | ||
"type": "StructRepresentation" | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"FieldName": { | ||
"kind": "string" | ||
"string": {} | ||
}, | ||
"StructField": { | ||
"kind": "struct", | ||
"fields": { | ||
"type": { | ||
"type": "TypeTerm" | ||
"struct": { | ||
"fields": { | ||
"type": { | ||
"type": "TypeNameOrInlineDefn" | ||
}, | ||
"optional": { | ||
"type": "Bool" | ||
}, | ||
"nullable": { | ||
"type": "Bool" | ||
} | ||
}, | ||
"optional": { | ||
"type": "Bool" | ||
}, | ||
"nullable": { | ||
"type": "Bool" | ||
} | ||
}, | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"optional": { | ||
"implicit": false | ||
}, | ||
"nullable": { | ||
"implicit": false | ||
"representation": { | ||
"map": { | ||
"fields": { | ||
"optional": { | ||
"implicit": false | ||
}, | ||
"nullable": { | ||
"implicit": false | ||
} | ||
} | ||
@@ -415,8 +567,13 @@ } | ||
}, | ||
"TypeTerm": { | ||
"kind": "union", | ||
"representation": { | ||
"kinded": { | ||
"string": "TypeName", | ||
"map": "InlineDefn" | ||
"TypeNameOrInlineDefn": { | ||
"union": { | ||
"members": [ | ||
"TypeName", | ||
"InlineDefn" | ||
], | ||
"representation": { | ||
"kinded": { | ||
"string": "TypeName", | ||
"map": "InlineDefn" | ||
} | ||
} | ||
@@ -426,9 +583,13 @@ } | ||
"InlineDefn": { | ||
"kind": "union", | ||
"representation": { | ||
"inline": { | ||
"discriminantKey": "kind", | ||
"discriminantTable": { | ||
"map": "TypeMap", | ||
"list": "TypeList" | ||
"union": { | ||
"members": [ | ||
"TypeDefnMap", | ||
"TypeDefnList", | ||
"TypeDefnLink" | ||
], | ||
"representation": { | ||
"keyed": { | ||
"map": "TypeDefnMap", | ||
"list": "TypeDefnList", | ||
"link": "TypeDefnLink" | ||
} | ||
@@ -439,10 +600,18 @@ } | ||
"StructRepresentation": { | ||
"kind": "union", | ||
"representation": { | ||
"keyed": { | ||
"map": "StructRepresentation_Map", | ||
"tuple": "StructRepresentation_Tuple", | ||
"stringpairs": "StructRepresentation_StringPairs", | ||
"stringjoin": "StructRepresentation_StringJoin", | ||
"listpairs": "StructRepresentation_ListPairs" | ||
"union": { | ||
"members": [ | ||
"StructRepresentation_Map", | ||
"StructRepresentation_Tuple", | ||
"StructRepresentation_StringPairs", | ||
"StructRepresentation_StringJoin", | ||
"StructRepresentation_ListPairs" | ||
], | ||
"representation": { | ||
"keyed": { | ||
"map": "StructRepresentation_Map", | ||
"tuple": "StructRepresentation_Tuple", | ||
"stringpairs": "StructRepresentation_StringPairs", | ||
"stringjoin": "StructRepresentation_StringJoin", | ||
"listpairs": "StructRepresentation_ListPairs" | ||
} | ||
} | ||
@@ -452,114 +621,129 @@ } | ||
"StructRepresentation_Map": { | ||
"kind": "struct", | ||
"fields": { | ||
"struct": { | ||
"fields": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "FieldName", | ||
"valueType": "StructRepresentation_Map_FieldDetails" | ||
}, | ||
"optional": true | ||
"fields": { | ||
"type": { | ||
"map": { | ||
"keyType": "FieldName", | ||
"valueType": "StructRepresentation_Map_FieldDetails" | ||
} | ||
}, | ||
"optional": true | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"StructRepresentation_Map_FieldDetails": { | ||
"kind": "struct", | ||
"fields": { | ||
"rename": { | ||
"type": "String", | ||
"optional": true | ||
"struct": { | ||
"fields": { | ||
"rename": { | ||
"type": "String", | ||
"optional": true | ||
}, | ||
"implicit": { | ||
"type": "AnyScalar", | ||
"optional": true | ||
} | ||
}, | ||
"implicit": { | ||
"type": "AnyScalar", | ||
"optional": true | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"StructRepresentation_Tuple": { | ||
"kind": "struct", | ||
"fields": { | ||
"fieldOrder": { | ||
"type": { | ||
"kind": "list", | ||
"valueType": "FieldName" | ||
}, | ||
"optional": true | ||
"struct": { | ||
"fields": { | ||
"fieldOrder": { | ||
"type": { | ||
"list": { | ||
"valueType": "FieldName" | ||
} | ||
}, | ||
"optional": true | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"StructRepresentation_StringPairs": { | ||
"kind": "struct", | ||
"fields": { | ||
"innerDelim": { | ||
"type": "String" | ||
"struct": { | ||
"fields": { | ||
"innerDelim": { | ||
"type": "String" | ||
}, | ||
"entryDelim": { | ||
"type": "String" | ||
} | ||
}, | ||
"entryDelim": { | ||
"type": "String" | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"StructRepresentation_StringJoin": { | ||
"kind": "struct", | ||
"fields": { | ||
"join": { | ||
"type": "String" | ||
"struct": { | ||
"fields": { | ||
"join": { | ||
"type": "String" | ||
}, | ||
"fieldOrder": { | ||
"type": { | ||
"list": { | ||
"valueType": "FieldName" | ||
} | ||
}, | ||
"optional": true | ||
} | ||
}, | ||
"fieldOrder": { | ||
"type": { | ||
"kind": "list", | ||
"valueType": "FieldName" | ||
}, | ||
"optional": true | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"StructRepresentation_ListPairs": { | ||
"kind": "struct", | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
"struct": { | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeEnum": { | ||
"kind": "struct", | ||
"fields": { | ||
"members": { | ||
"type": { | ||
"kind": "map", | ||
"keyType": "EnumValue", | ||
"valueType": "Null" | ||
"TypeDefnEnum": { | ||
"struct": { | ||
"fields": { | ||
"members": { | ||
"type": { | ||
"list": { | ||
"valueType": "EnumMember" | ||
} | ||
} | ||
}, | ||
"representation": { | ||
"type": "EnumRepresentation" | ||
} | ||
}, | ||
"representation": { | ||
"type": "EnumRepresentation" | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"EnumValue": { | ||
"kind": "string" | ||
"EnumMember": { | ||
"string": {} | ||
}, | ||
"EnumRepresentation": { | ||
"kind": "union", | ||
"representation": { | ||
"keyed": { | ||
"string": "EnumRepresentation_String", | ||
"int": "EnumRepresentation_Int" | ||
"union": { | ||
"members": [ | ||
"EnumRepresentation_String", | ||
"EnumRepresentation_Int" | ||
], | ||
"representation": { | ||
"keyed": { | ||
"string": "EnumRepresentation_String", | ||
"int": "EnumRepresentation_Int" | ||
} | ||
} | ||
@@ -569,23 +753,64 @@ } | ||
"EnumRepresentation_String": { | ||
"kind": "map", | ||
"keyType": "EnumValue", | ||
"valueType": "String" | ||
"map": { | ||
"keyType": "EnumMember", | ||
"valueType": "String" | ||
} | ||
}, | ||
"EnumRepresentation_Int": { | ||
"kind": "map", | ||
"keyType": "EnumValue", | ||
"valueType": "Int" | ||
"map": { | ||
"keyType": "EnumMember", | ||
"valueType": "Int" | ||
} | ||
}, | ||
"TypeCopy": { | ||
"kind": "struct", | ||
"fields": { | ||
"fromType": { | ||
"type": "TypeName" | ||
"TypeDefnUnit": { | ||
"struct": { | ||
"fields": { | ||
"representation": { | ||
"type": "UnitRepresentation" | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
}, | ||
"UnitRepresentation": { | ||
"enum": { | ||
"members": [ | ||
"Null", | ||
"True", | ||
"False", | ||
"Emptymap" | ||
], | ||
"representation": { | ||
"string": { | ||
"Null": "null", | ||
"True": "true", | ||
"False": "false", | ||
"Emptymap": "emptymap" | ||
} | ||
} | ||
} | ||
}, | ||
"TypeDefnAny": { | ||
"struct": { | ||
"fields": {}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
}, | ||
"TypeDefnCopy": { | ||
"struct": { | ||
"fields": { | ||
"fromType": { | ||
"type": "TypeName" | ||
} | ||
}, | ||
"representation": { | ||
"map": {} | ||
} | ||
} | ||
} | ||
} | ||
} |
# schema-schema: `BytesRepresentation_Bytes` | ||
BytesRepresentation_Bytes is the default representation for TypeBytes and | ||
BytesRepresentation_Bytes is the default representation for TypeDefnBytes and | ||
will be used implicitly if no representation is specified. | ||
@@ -5,0 +5,0 @@ |
# schema-schema: `BytesRepresentation` | ||
BytesRepresentation specifies how a TypeBytes is to be serialized. By | ||
BytesRepresentation specifies how a TypeDefnBytes is to be serialized. By | ||
default it will be stored as bytes in the data model but it may be replaced | ||
@@ -5,0 +5,0 @@ with an ADL. |
@@ -6,7 +6,7 @@ # schema-schema: `EnumRepresentation_Int` | ||
conversion from int to enum value. In the DSL, int values _must_ be provided | ||
for each EnumValue (with `Foo ("100")`, those are stored here. | ||
for each EnumMember (with `Foo ("100")`, those are stored here. | ||
```ipldsch | ||
type EnumRepresentation_Int {EnumValue:Int} | ||
type EnumRepresentation_Int {EnumMember:Int} | ||
``` |
# schema-schema: `EnumRepresentation_String` | ||
EnumRepresentation_String describes the way an enum is represented as a | ||
string in the data model. By default, the strings used as EnumValue will be | ||
string in the data model. By default, the strings used as EnumMember will be | ||
used at the serialization. A custom string may be provided (with `Foo ("x")` | ||
@@ -11,3 +11,3 @@ in the DSL) which will be stored here in the representation block. Missing | ||
```ipldsch | ||
type EnumRepresentation_String {EnumValue:String} | ||
type EnumRepresentation_String {EnumMember:String} | ||
``` |
# schema-schema: `InlineDefn` | ||
InlineDefn represents a declaration of an anonymous type of one of the simple | ||
recursive kinds (e.g. map or list) which is found "inline" in another type's | ||
definition. It's the more complex option of the TypeTerm union. | ||
recursive kinds (e.g. map or list) which is found "inline" in another type's definition. | ||
InlineDefn also allows description of anonymous but typed links for similar reasons. | ||
InlineDefn is the more complex option of the TypeNameOrInlineDefn union. | ||
Note that the representation of this union -- `representation inline "kind"` | ||
-- as well as the keywords for its members -- align exactly with those | ||
in the Type union. Technically, this isn't a necessary property (in that | ||
Note that the representation of this union -- the use of a keyed representation, | ||
as well as the keywords for its members -- align exactly with those | ||
in the TypeNameOrInlineDefn union. Technically, this isn't a necessary property (in that | ||
nothing would break if that sameness was violated) but it's awfully nice for | ||
sanity; what we're saying here is that the representation of the types in an | ||
InlineDefn should look *exactly the same* as the top-level Types... it's just | ||
that we're restricted to a subset of the members. | ||
InlineDefn should look *exactly the same* as the top-level type declarations... | ||
it's just that within an InlineDefn, we're restricted to a subset of the members. | ||
@@ -18,7 +19,6 @@ | ||
type InlineDefn union { | ||
| TypeMap "map" | ||
| TypeList "list" | ||
} representation inline { | ||
discriminantKey "kind" | ||
} | ||
| TypeDefnMap "map" | ||
| TypeDefnList "list" | ||
| TypeDefnLink "link" | ||
} representation keyed | ||
``` |
@@ -7,8 +7,10 @@ # schema-schema: `ListRepresentation` | ||
Note that the `TypeDefnList.representation` field is optional -- | ||
the default behavior is demarcated by the lack of any of these values. | ||
```ipldsch | ||
type ListRepresentation union { | ||
| ListRepresentation_List "list" | ||
| AdvancedDataLayoutName "advanced" | ||
} representation keyed | ||
``` |
# schema-schema: `MapRepresentation` | ||
MapRepresentation describes how a map type should be mapped onto | ||
its IPLD Data Model representation. By default a map is a map in the | ||
Data Model but other kinds can be configured. | ||
its IPLD Data Model representation. | ||
By default, a map type is also represented as a map in the Data Model, | ||
but other representation strategies can be configured | ||
Note that the `TypeDefnMap.representation` field is optional -- | ||
the default behavior is demarcated by the lack of any of these values. | ||
```ipldsch | ||
type MapRepresentation union { | ||
| MapRepresentation_Map "map" | ||
| MapRepresentation_StringPairs "stringpairs" | ||
@@ -12,0 +16,0 @@ | MapRepresentation_ListPairs "listpairs" |
@@ -10,7 +10,8 @@ # schema-schema: `RepresentationKind` | ||
(e.g. a "struct" TypeKind will usually be transformed to a "map" | ||
RepresentationKind; "enum" TypeKind are always "string" RepresentationKind; | ||
and so on.) | ||
RepresentationKind; "enum" TypeKind are typically a "string" RepresentationKind; | ||
and so on; exactly what RepresentationKind a type defintion will have | ||
is determined by its representation strategy). | ||
RepresentationKind strings are sometimes used to to indicate part of the | ||
definition in the details of Type; for example, they're used describing | ||
definition in the details of TypeDefn; for example, they're used describing | ||
some of the detailed behaviors of a "kinded"-style union type. | ||
@@ -20,11 +21,11 @@ | ||
type RepresentationKind enum { | ||
| Bool | ||
| String | ||
| Bytes | ||
| Int | ||
| Float | ||
| Map | ||
| List | ||
| Link | ||
| Bool ("bool") | ||
| String ("string") | ||
| Bytes ("bytes") | ||
| Int ("int") | ||
| Float ("float") | ||
| Map ("map") | ||
| List ("list") | ||
| Link ("link") | ||
} | ||
``` |
# schema-schema: `Schema` | ||
Schema is a single-member union, which can be used in serialization | ||
to make a form of "nominative type declaration". | ||
Schema is a the root element of an IPLD Schema document. | ||
@@ -10,3 +9,3 @@ A complete (if quite short) Schema might look like this: | ||
{ | ||
"schema": { | ||
"types": { | ||
"MyFooType": { | ||
@@ -19,8 +18,16 @@ "type": "string" | ||
The main bulk of a schema is the types map, | ||
which is TypeName mapped to TypeDefn. | ||
Some additional top level fields are optional, | ||
such as some maps which may store data about where ADLs | ||
should be expected to be used within the data described by the schema. | ||
However, not all schemas use these features. | ||
```ipldsch | ||
type Schema struct { | ||
types SchemaMap | ||
advanced AdvancedDataLayoutMap | ||
types {TypeName:TypeDefn} | ||
advanced optional AdvancedDataLayoutMap | ||
} | ||
``` |
# schema-schema: `StructField` | ||
StructField describes the properties of each field declared by a TypeStruct. | ||
StructField describes the properties of each field declared by a TypeDefnStruct. | ||
StructField contains properties similar to TypeMap -- namely, it describes | ||
a content type (as a TypeTerm -- it supports inline definitions) -- and | ||
StructField contains properties similar to TypeDefnMap -- namely, it describes | ||
a content type (as a TypeNameOrInlineDefn -- it supports inline definitions) -- and | ||
has a boolean property for whether or not the value is permitted to be null. | ||
@@ -34,6 +34,6 @@ | ||
type StructField struct { | ||
type TypeTerm | ||
optional Bool (implicit "false") | ||
nullable Bool (implicit "false") | ||
type TypeNameOrInlineDefn | ||
optional Bool (implicit false) | ||
nullable Bool (implicit false) | ||
} | ||
``` |
# schema-schema: `StructRepresentation` | ||
StructRepresentation describes how a struct type should be mapped onto | ||
its IPLD Data Model representation. Typically, maps are the representation | ||
kind, but other kinds and details can be configured. | ||
its IPLD Data Model representation. | ||
The default representation strategy for struct types is a map, | ||
with the struct's field names as keys. | ||
However, that can be configured. | ||
For example, the map representation can be configured with | ||
directives to use different keys in the representation form; | ||
or, configured to consider some fields as having values which should be seen as the implicit value for that field, | ||
meaning the entire field shouldn't get an entry in the representation map if that value is found in that field. | ||
Or, wholly different representation strategies can be used | ||
(such as the tuple strategy, which results in a data model list kind, | ||
or stringjoin, which results a data model string kind!). | ||
```ipldsch | ||
@@ -9,0 +19,0 @@ type StructRepresentation union { |
@@ -5,21 +5,25 @@ # schema-schema: `TypeKind` | ||
Notice this enum's members are the same as the set of strings used as | ||
discriminants in the Type union. | ||
discriminants in the TypeDefn union. | ||
(Almost! TypeDefn also contains TypeDefnCopy, which is a slight outlier. | ||
(TypeDefnCopy can be used to define a type, but isn't a typekind itself.)) | ||
TODO: not actually sure we'll need to declare this. Only usage is | ||
in the Type union representation details? | ||
This enum is not actually used elsewhere in the schema-schema, | ||
but does correspond to the discriminant values used in the TypeDefn union. | ||
```ipldsch | ||
type TypeKind enum { | ||
| Bool | ||
| String | ||
| Bytes | ||
| Int | ||
| Float | ||
| Map | ||
| List | ||
| Link | ||
| Union | ||
| Struct | ||
| Enum | ||
| Bool ("bool") | ||
| String ("string") | ||
| Bytes ("bytes") | ||
| Int ("int") | ||
| Float ("float") | ||
| Map ("map") | ||
| List ("list") | ||
| Link ("link") | ||
| Union ("union") | ||
| Struct ("struct") | ||
| Enum ("enum") | ||
| Unit ("unit") | ||
| Any ("any") | ||
} | ||
``` |
@@ -21,3 +21,5 @@ # schema-schema: `UnionRepresentation_BytesPrefix` | ||
```ipldsch | ||
type UnionRepresentation_BytesPrefix {String:TypeName} | ||
type UnionRepresentation_BytesPrefix struct { | ||
prefixes {HexString:TypeName} | ||
} | ||
``` |
@@ -14,4 +14,4 @@ # schema-schema: `UnionRepresentation_Envelope` | ||
contentKey String | ||
discriminantTable {String:TypeName} | ||
discriminantTable {String:UnionMember} | ||
} | ||
``` |
@@ -13,3 +13,3 @@ # schema-schema: `UnionRepresentation_Keyed` | ||
```ipldsch | ||
type UnionRepresentation_Keyed {String:TypeName} | ||
type UnionRepresentation_Keyed {String:UnionMember} | ||
``` |
# schema-schema: `UnionRepresentation_Kinded` | ||
"Kinded" union representations describe a bidirectional mapping between | ||
a RepresentationKind and a Type (referenced by name) which should be the | ||
a RepresentationKind and the type which should be the | ||
union member decoded when one sees this RepresentationKind. | ||
@@ -11,3 +11,3 @@ | ||
```ipldsch | ||
type UnionRepresentation_Kinded {RepresentationKind:TypeName} | ||
type UnionRepresentation_Kinded {RepresentationKind:UnionMember} | ||
``` |
# schema-schema: `UnionRepresentation` | ||
UnionRepresentation is a union of all the distinct ways a TypeUnion's values | ||
UnionRepresentation is a union of all the distinct ways a TypeDefnUnion's values | ||
can be mapped onto a serialized format for the IPLD Data Model. | ||
There are five strategies that can be used to encode a union: | ||
"keyed", "envelope", "inline", "bytesprefix", and "kinded". | ||
There are six strategies that can be used to encode a union: | ||
"keyed", "envelope", "inline", "stringprefix", "bytesprefix", and "kinded". | ||
The "keyed", "envelope", and "inline" strategies are all ways to produce | ||
representations in a map format, using map keys as type discriminators | ||
(some literature may describe this as a "tagged" style of union). | ||
The "bytesprefix" strategy, only available only for unions in which all | ||
member types themselves represent as bytes in the data model, uses another | ||
byte as the type discrimination hint (and like the map-oriented strategies, | ||
The "stringprefix" strategy, only available for unions in which all member | ||
types themselves represent as strings in the data model, uses a prefix | ||
string as the type discrimination hint (and like the map-oriented strategies, | ||
may also be seen as a form of "tagged" style unions). | ||
The "bytesprefix" strategy, only available for unions in which all member | ||
types themselves represent as bytes in the data model, similar to | ||
"stringprefix" but with bytes. | ||
The "kinded" strategy can describe a union in which member types have | ||
@@ -29,4 +32,5 @@ several different representation kinds, and uses the representation kind | ||
| UnionRepresentation_Inline "inline" | ||
| UnionRepresentation_StringPrefix "stringprefix" | ||
| UnionRepresentation_BytesPrefix "bytesprefix" | ||
} representation keyed | ||
``` |
/* eslint-env mocha */ | ||
const fs = require('fs/promises') | ||
const path = require('path') | ||
const { parse } = require('../ipld-schema') | ||
const { assert } = require('chai') | ||
import fs from 'fs' | ||
import { parse } from '../ipld-schema.js' | ||
import { assert } from 'chai' | ||
it('schema-schema', async () => { | ||
const schemaText = await fs.readFile(path.join(__dirname, 'fixtures/schema-schema.ipldsch'), 'utf8') | ||
const schemaText = await fs.promises.readFile(new URL('./fixtures/schema-schema.ipldsch', import.meta.url), 'utf8') | ||
const schema = parse(schemaText) | ||
const expectedSchema = require(path.join(__dirname, 'fixtures/schema-schema.ipldsch.json')) | ||
const expectedSchema = JSON.parse(await fs.promises.readFile(new URL('./fixtures/schema-schema.ipldsch.json', import.meta.url))) | ||
assert.deepStrictEqual(schema, expectedSchema) | ||
}) |
@@ -1,2 +0,2 @@ | ||
module.exports.transformError = function (err) { | ||
export function transformError (err) { | ||
if (err.location) { | ||
@@ -3,0 +3,0 @@ err.message = `Error parsing schema @ line:${err.location.start.line} col:${err.location.start.column}: ${err.message}` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
299896
126
5838
136
6
Yes
3