Media formats

Status: implemented

The repository's blob formats, and JSON itself, are schemas:

A format someone may extend says open, with the reason written beside it, so an older reader still reads a blob a newer writer extended. A format a content-addressed store holds is a value the caller must keep, which is what validate is for (parse and validate).

Examples

The demo on this page offers five schemas: a revision, a lock, a note, any JSON value, and a JSON Schema, each with a value it accepts. They are defined in sample.f.mjs, and the module page's demo lists them among all the others.

Where it is implemented

The modules linked above.

Demo

vnd.fjs.revision: one step in the history of a mutable object over a content-addressable store. open(), so an older reader still reads a revision a newer writer extended.

import { revisionSchema } from 'functionalscript/fjs/media/revision/module.f.mjs'
open [] → {}{} [parents] → array{} [archived] → or{} [lock] → oror [] → lockField orlockField or [] → lock recordlock record [] → lockValue orlockValue or [] → lock record (recursive)open{}dialectsubjectparentssnapshotgenerationarchivedlock"vnd.fjs.revision"stringarraystringnumberororarraystringoroptiontrueoroptionlockField orlockField orstringlock recordlock recordlockValue orstringlock record

TypeScript:

type lockValue = string|{readonly[k in string]?:lockValue}
{readonly"archived"?:true,readonly"dialect":"vnd.fjs.revision",readonly"generation":number,readonly"lock"?:string|{readonly[k in string]?:lockValue},readonly"parents":readonly(string)[],readonly"snapshot":string,readonly"subject":string}

JSON Schema:

{"type":"object","properties":{"archived":{"const":true},"dialect":{"const":"vnd.fjs.revision"},"generation":{"type":"number"},"lock":{"anyOf":[{"type":"string"},{"type":"object","additionalProperties":{"$ref":"#/$defs/lockValue"}}]},"parents":{"type":"array","items":{"type":"string"}},"snapshot":{"type":"string"},"subject":{"type":"string"}},"required":["dialect","generation","parents","snapshot","subject"],"$defs":{"lockValue":{"anyOf":[{"type":"string"},{"type":"object","additionalProperties":{"$ref":"#/$defs/lockValue"}}]}}}
Canonical form (toData)
export default [{"lockValue":{"string":true,"object":[{"props":{},"rest":"lockValue"}]}},{"object":[{"props":{"archived":{"unit":24},"dialect":{"string":["vnd.fjs.revision"]},"generation":{"number":true},"lock":{"unit":16,"string":true,"object":[{"props":{},"rest":"lockValue"}]},"parents":{"array":[{"prefix":[],"rest":{"string":true}}]},"snapshot":{"string":true},"subject":{"string":true}}}]}];

parse · ok

export default {"dialect":"vnd.fjs.revision","subject":"todo","parents":[],"snapshot":"c1dq3pe0t4f7a2kx","generation":0};

validate · ok

export default {"dialect":"vnd.fjs.revision","subject":"todo","parents":[],"snapshot":"c1dq3pe0t4f7a2kx","generation":0};

Emergent Testing

Idle. Press Run to start the suite.

  • ./proof.f.mjs