New
Apps 6,419Makers 6,403This week 7
Promote your app−30%
DON screenshot 1
4views in
the last 30 days

DON

Human-readable text format for exchanging directive objects between applications

Built with Claude Code

by jondotsoy · Unclaimed · from CLChile · added Oct 29, 2026
no ratings0 comments
donly

donly is the reference implementation of DON (Directive Object Notation), a human-readable data serialization format built around directives and subdirectives. DON was designed for writing infrastructure annotations — routes, containers, security rules, reverse proxies — in a shape that's fast for both humans and AI agents to read and generate. Instead of nesting keys and indentation levels to express a declaration, a directive takes its parameters as positional arguments, so a rule that needs a method, a path, and a body reads as one line instead of a tree:

route GET /api {
  respond 200 "Ok"
}

The equivalent in a key-value format needs an extra level of nesting per parameter:

routes:
  /api:
    GET:
      respond: 200 Ok

This matters more as the number of parameters grows — a container declaration with an image, a port mapping, and env vars stays one directive with a block, not a pyramid of nested maps. Because the shape is uniform (name arg1 arg2 ... { children }), an LLM reading or writing DON doesn't have to track indentation-sensitive nesting rules to know what a declaration means — it just reads the arguments in order.

Unlike DSLs tied to a single domain (an HTTP server config, a Dockerfile, an IaC tool), DON carries no built-in schema — it only defines the grammar for directives, arguments, and blocks. Directive names and their arguments are entirely up to you, so the same format can describe routes, containers, security rules, or any other domain-specific structure your project needs. See docs/refs/vs.md for a comparison against other DSLs.

Features

  • Directive Arguments: Directives take positional arguments (route GET /api), collapsing what would otherwise be several nested keys into one line
  • Minimal Syntax: Fewer special characters, more readability
  • Sequential Processing: Directives are processed as a pipeline, allowing overwriting and incremental composition
  • Flexible Nesting: Supports hierarchies of any depth
  • Multiple Data Types: Keywords, strings, numbers, booleans, and null
  • Comments: Line (#) and block (/* ... */) comments
  • Heredoc Support: Multi-line content blocks for embedded scripts and text

Installation

npm install donly
bun add donly

Usage

Parse a DON document into a Directive:

import { DON } from "donly";

const text = `
name "my-app"
port 8080

database {
  host "localhost"
  port 5432
}
`;

const root = DON.parse(text);

const database = root.children.find((d) => d.name === "database");
const result = database?.children.map((c) => [c.name, c.args]);
// ? const result = [
//   [ "host", [ "localhost" ] ], [ "port", [ 5432 ] ]
// ]

Each Directive has:

  • name: string | symbol — the directive's identifier
  • args: (number | string | boolean)[] — the directive's arguments
  • children: Directive[] — nested subdirectives

DON.parse() always returns a single Directive:

  • No top-level directives (empty input, or only comments) → an empty root Directive (name: ROOT_DIRECTIVE_NAME, children: []).
  • Exactly one top-level directive → that Directive itself, unwrapped (e.g. DON.parse('host "localhost"') → Directive{name:"host", args:["localhost"]}).
  • Two or more top-level directives → wrapped in a synthetic root Directive (name: ROOT_DIRECTIVE_NAME) with them as children, as in the example above.

ROOT_DIRECTIVE_NAME is exported from donly — check directive.name === ROOT_DIRECTIVE_NAME to detect a synthetic root.

AST

DON.parse() compiles the source text into a lexer/syntax tree internally, then hands you back a plain tree of Directive nodes — this Directive tree is the AST that donly exposes publicly. There is no separate "AST" type to import: every directive in the document, from the root down to the deepest subdirective, is a Directive instance, and traversing children recursively walks the whole tree.

For the example in Usage:

Directive (name: ROOT_DIRECTIVE_NAME)          # synthetic root, 2+ top-level directives
├── Directive (name: "name", args: ["my-app"])
├── Directive (name: "port", args: [8080])
└── Directive (name: "database", args: [])
    ├── Directive (name: "host", args: ["localhost"])
    └── Directive (name: "port", args: [5432])

Each node carries just three fields, with no source-position data:

  • name: string | symbol — the directive's identifier (or ROOT_DIRECTIVE_NAME for a synthetic root)
  • args: (number | string | boolean | HeredocValue)[] — the directive's arguments, already decoded to JS values
  • children: Directive[] — nested subdirectives, in source order

Because the shape is uniform (every node, root or leaf, is a Directive), you can write a single recursive function to walk it:

import { DON, type Directive } from "donly";

function walk(node: Directive, depth = 0): string[] {
  const line = `${"  ".repeat(depth)}${String(node.name)} ${JSON.stringify(node.args)}`;
  return [line, ...node.children.flatMap((child) => walk(child, depth + 1))];
}

const text = `
name "my-app"
port 8080

database {
  host "localhost"
  port 5432
}
`;

const lines = walk(DON.parse(text)).join("\n");
// ? const lines = "Symbol(root) []\n  name [\"my-app\"]\n  port [8080]\n  database []\n    host [\"localhost\"]\n    port [5432]"

A Directive's own fields never include its source Tokens or span — that data is dropped while building the tree so the public shape stays plain and JSON-serializable. When a Directive comes from DON.parse(), though, its name and args Tokens are still reachable via Directive.tokensByDirective(), keyed by the Directive instance itself:

import { DON, Directive } from "donly";

const root = DON.parse('host "localhost"');
const tokens = Directive.tokensByDirective(root)?.map((token) => token.raw());
// ? const tokens = [ "host", "\"localhost\"" ]

const [token] = Directive.tokensByDirective(root) ?? [];
// ? const token = Token {
//   type: 11,
//   parts: [
//     Part {
//       type: 1,
//       buffer: [ 104, 111, 115, 116 ],
//       span: Span {
//         index: 0,
//         length: 4,
//         startLocation: {
//           line: 0,
//           column: 0,
//           paddingLine: 0,
//         },
//         endLocation: {
//           line: 0,
//           column: 4,
//           paddingLine: 0,
//         },
//       },
//       id: 0,
//       toUint8Array: [Function: toUint8Array],
//       toText: [Function: toText],
//       toJSON: [Function: toJSON],
//     }
//   ],
//   span: Span {
//     index: 0,
//     length: 4,
//     startLocation: {
//       line: 0,
//       column: 0,
//       paddingLine: 0,
//     },
//     endLocation: {
//       line: 0,
//       column: 4,
//       paddingLine: 0,
//     },
//   },
//   describeError: [Function: describeError],
//   getErrors: [Function: getErrors],
//   arrayBuffer: [Function: arrayBuffer],
//   text: [Function: text],
//   raw: [Function: raw],
//   toJS: [Function: toJS],
//   json: [Function: json],
//   toJSON: [Function: toJSON],
// }

token.type and part.type are numeric SyntaxKind values — the enum LexerParser and the syntax parser tag every scanned unit with:

import { SyntaxKind as kindsyntax } from "donly";
// ? const kindsyntax = {
//   "0": "unknown",
//   "1": "alphabet",
//   "2": "integer",
//   "3": "whitespace",
//   "4": "newline",
//   "5": "dot",
//   "6": "underscore",
//   "7": "singleQuote",
//   "8": "doubleQuote",
//   "9": "openCurlyBrace",
//   "10": "closeCurlyBrace",
//   "11": "keyword",
//   "12": "string",
//   "13": "numeric",
//   "14": "boolean",
//   "15": "null",
//   "16": "comment",
//   "17": "indent",
//   "18": "heredoc",
//   unknown: 0,
//   alphabet: 1,
//   integer: 2,
//   whitespace: 3,
//   newline: 4,
//   dot: 5,
//   underscore: 6,
//   singleQuote: 7,
//   doubleQuote: 8,
//   openCurlyBrace: 9,
//   closeCurlyBrace: 10,
//   keyword: 11,
//   string: 12,
//   numeric: 13,
//   boolean: 14,
//   null: 15,
//   comment: 16,
//   indent: 17,
//   heredoc: 18,
// }
Value Name Description
0 unknown Fallback kind for input the lexer couldn't classify into anything below.
1 alphabet A letter, while scanning a bare word (an identifier, keyword, or the true/false/null literals).
2 integer A digit, while scanning a number literal.
3 whitespace A space or tab between tokens.
4 newline A line break, which separates directives from each other.
5 dot The . character, joining the integer parts of a decimal number.
6 underscore The _ character, allowed inside identifiers.
7 singleQuote The ' character opening/closing a quoted string.
8 doubleQuote The " character opening/closing a quoted string.
9 openCurlyBrace The { character, opening a block of nested subdirectives.
10 closeCurlyBrace The } character, closing a block of nested subdirectives.
11 keyword A resolved directive name or bare-word argument token.
12 string A resolved quoted-string argument token.
13 numeric A resolved number argument token.
14 boolean A resolved true/false argument token.
15 null A resolved null argument token.
16 comment A line (#) or block (/* ... */) comment token.
17 indent Leading whitespace on a line, recognized as indentation.
18 heredoc A heredoc block token (multi-line content between << markers).

SyntaxKind is exported from donly, but its numeric values are considered internal — treat them as opaque unless you're working at the lexer/syntax-parser level.

tokensByDirective(directive) returns undefined for a Directive not produced by the parser — one you built by hand with new Directive(...), or one that came out of DirectiveJSONDecoder.

Every Directive also exposes parent, the Directive it's nested under:

import { DON } from "donly";

const root = DON.parse(`
directivename {
  subdirective
}
`);

const subdirective = root.find("/directivename/subdirective")!;
const parent = subdirective.parent;
// ? const parent = Directive {
//   name: "directivename",
//   args: [],
//   children: [
//     Directive {
//       name: "subdirective",
//       args: [],
//       children: [],
//     }
//   ],
// }

const rootParent = root.parent;
// ? const rootParent = undefined

parent is set from children by the Directive constructor itself, so it's available regardless of how the Directive was built — parsed, decoded from JSON, or constructed by hand — and it's undefined for a top-level/root Directive with no enclosing parent.

If you need lower-level access to the parse — spans, source locations, or the full token stream including directives you don't hold a reference to — SyntaxEncode (the syntax parser) and LexerParser (the lexer, documented below) are also exported from donly, but they are considered internal/advanced APIs: Directive is the supported way to consume a parsed document.

Finding Directives

Every Directive has find(path) and findAll(path) to locate descendants by an absolute, /-separated path from that directive (treated as the document root), instead of walking children by hand:

import { DON } from "donly";

const root = DON.parse(`
server {
  route /home
  route GET /api/user
  route POST /api/user
}
`);

const home = root.find("/server/route(/home)");
// ? const home = Directive {
//   name: "route",
//   args: [ "/home" ],
//   children: [],
// }

const apiRoutes = root.findAll("/server/route(* /api/user)");
// ? const apiRoutes = [
//   Directive {
//     name: "route",
//     args: [ "GET", "/api/user" ],
//     children: [],
//   }, Directive {
//     name: "route",
//     args: [ "POST", "/api/user" ],
//     children: [],
//   }
// ]

The path syntax:

  • "/" — the directive itself.
  • "/server" — top-level children named server.
  • "/server/route" — route children of a matched server.
  • "/server/route(/home)" — route children whose args are exactly ["/home"].
  • "/server/route(* /api/user)" — route children with any first argument and a second argument exactly "/api/user" (* wildcards a single argument; a directive only matches a (...) group when its args.length equals the number of space-separated patterns).
  • "/server/\/user" — a /user child, i.e. a directive whose own name is /user (DON identifiers may contain /, see the spec); \ escapes the character that follows it so it's read literally instead of as a path separator or a (/) group delimiter.
  • "/server/route{/auth(on)}" — route children of server that have some descendant matching /auth(on); the {...} group is a filter — it doesn't change what's returned, still the route, not the matched auth.
  • "/server/route{/auth}{/respond}" and "/server/route(GET)(text/*)" — stacking {...}/(...) groups on one segment is an AND: every group must match.
  • "/server/route(GET|POST)", "/server/route{/auth(on)|/auth(strict)}", "/server/route|/server/proxy" — | is an OR, between alternative values inside one token, alternative nested paths inside one {...} group, or alternative whole paths at the top level, respectively.

See Path Expressions for the full syntax reference, including how these combine (and how the lint rule schema reuses the same matcher for its own /name sub-path keys).

find returns the first match (or undefined), findAll returns every match. findDirective/findAllDirectives are also exported from donly/find for the same lookup against any Directive, not just as instance methods.

at(path) resolves the same path syntax, but a path ending in [N] returns that directive's argument at position N instead of the directive itself. Positions are 1-based — [1] is the first argument:

const respond = root.at("/server/route(GET /api)/respond");
// ? const respond = Directive { name: "respond", args: [200], children: [] }

const status = root.at("/server/route(GET /api)/respond[1]");
// ? const status = 200

atDirective is also exported from donly/find for the same lookup against any Directive. at's return type is narrowed for string-literal paths — see TypeScript.

TypeScript

donly is written in TypeScript and ships its own .d.ts files — no @types/donly needed.

Directive#at/atDirective are generic over the path you pass them, so a string-literal path narrows the return type without a manual type assertion:

import { DON, type Directive } from "donly";

const root = DON.parse(`
server {
  route GET /api { respond 200 }
}
`);

// A path with no trailing "[N]" types as Directive | undefined.
const respond = root.at("/server/route(GET /api)/respond");
respond?.args; // Directive["args"]

// A path ending in "[N]" types as the argument value, not a Directive.
const status = root.at("/server/route(GET /api)/respond[1]");
//    ^? const status: string | number | boolean | HeredocValue | undefined

// @ts-expect-error a "[N]"-suffixed path never resolves to a Directive.
const notADirective: Directive = root.at("/server/route(GET /api)/respond[1]");

This only works when path is a string literal (or a literal type, e.g. from a const binding without a wider annotation) — TypeScript needs the exact string to check whether it ends in [N]. A path built at runtime (e.g. a string variable, or a template literal with a non-literal interpolation) can't be checked at compile time, so it types as the union of both possibilities:

declare const dynamicPath: string;

const value = root.at(dynamicPath);
//    ^? const value: string | number | boolean | HeredocValue | Directive | undefined

The conditional type behind this, AtPathResult<P>, is exported from donly/find if you need to reuse it (e.g. to type a helper that wraps at).

Plugins

DON.parse(text, { plugins }) accepts a list of DonPlugins to extend parsing itself, before donly's "Sequential Processing" pipeline hands you back the Directive tree. Each plugin's onDirective(node, ctx) runs once per directive, depth-first pre-order — the document's own reading order, parents before children, earlier siblings before later ones. See Plugins for where a plugin sits in DON.parse()'s pipeline, a full description of name/initContext/onDirective/onEnterScope/onExitScope, how to read a directive's original Tokens (Directive.tokensByDirective), and step-by-step walkthroughs of variablesPlugin, createResourcesPlugin (donly/demo/plugins/resources — expands a resource sqlite <file-url> reference into synthetic size/table/columns children via PluginDirectiveNode#children), and createScopedVariablesPlugin (donly/plugins/scoped-variables — block-scoped set plus ${name} string interpolation, with an options.variables to seed the root scope).

import { DON, type DonPlugin } from "donly";

const upper: DonPlugin = {
  name: "upper",
  onDirective(node) {
    return {
      name: node.name,
      args: node.args.map((arg) =>
        typeof arg === "string" ? arg.toUpperCase() : arg,
      ),
    };
  },
};

const result = DON.parse('greet "hi"', { plugins: [upper] });
// ? const result = Directive {
//   name: "greet",
//   args: [ "HI" ],
//   children: [],
// }

node (a PluginDirectiveNode) exposes the directive's resolved name/args, readonly — onDirective never mutates it in place. To change what gets built into the Directive, return a new PluginDirectiveNode instead, as upper does above. Returning null drops that directive — and its children — from the resulting tree entirely, which is how a pragma-style directive (one that only has a side effect,

Description taken from the repository README.

Ratings

–
0 ratings
5 0
4 0
3 0
2 0
1 0

Rate this app

Sign in to rate

Comments 0

Sign in to comment

No comments yet.

Related apps

#data-format · #serialization · #parser