Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
DRON: Data Rules Object Notation
Version 0.2. DRON is a portable description of an application's data and the rules over it. This repository's Python server is the first engine that reads it; the description does not mention Python, and a second engine that reads the same files and refuses the same writes is the test of whether the description is real.
A DRON application is a handful of JSON files:
| Part | File | Says |
|---|---|---|
| Collection | packages/<id>/schemas/<collection>.json | what a table of records holds, what a valid record is, which states it may move between, what freezes it, what must be unique, how it is listed and searched |
| Package | packages/<id>/dbbasic-package.json | which collections, rule files and seed files make up one app, what it depends on, which passes run on a clock, which doors it puts in the menu, which queues wait on a person |
| Permissions | packages/<id>/permissions/rules.json | who may do what to which collection or object, for which rows and fields; which earlier rules are withdrawn |
Seed data is TSV (first row the header, must include id); it is rows, not rules, and has no schema of its own. Two kinds of seed row are declarations in effect, because they are how an app's pages exist, and DRON covers them: seed/views.tsv (a page: a route, a layout and a JSON list of blocks, described by dron/dron-view.schema.json) and seed/site_routes.tsv (a URL pattern pointing at an object). See package-authoring.md.
DRON documents for exchange between boxes ("dron_document": "0.1": a signed JSON envelope for a purchase order, invoice, remittance and the like) are described in box-to-box-exchange.md; phase 0 is built. They are data a box sends, not declarations. dron/dron-document.schema.json describes the envelope and the body of each document kind as far as object_exchange.validate_envelope checks them; the engine stays the authority, and what needs computation is the engine's alone (see "Known gaps in 0.2").
What is in it, and what is not
DRON is facts about data. Every declaration is something you could say aloud and a reviewer could check against a record: "an amount must be greater than zero", "an approved entry changes only its status and notes", "a payment cannot exceed its invoice", "only the owner moves a draft to submitted", "scans in extracted wait on a person". The engine's job is to make those true for every writer (web form, API, agent, import, the daemon), not just the one that has a form.
It has no loops, no functions and no expressions. That is deliberate: a declaration that cannot compute cannot hide a bug, can be read by a person or a small model, and can be re-implemented by an engine in any language. When a rule needs arithmetic across rows or another collection's state, the declaration names code to consult and the code lives outside DRON:
hooks.before_writeandlocked_checks[].objectname an installed object.
DRON says the object must be consulted, over which collections, under which lock, on which writes. What it decides is code.
schedulesname an object to call on a clock. DRON says when, not what
happens.
attention[].object_idnames a provider for the few queues a count of rows
cannot express; every queue that is rows of one collection in a waiting state is declared instead (collection + where).
objectsentries name source files.
The wiring (which route serves a page, which handler reacts to which event, how the daemon is run) is the engine's, not DRON's.
One exception is carried in 0.1 and is flagged here so nobody mistakes it for the pattern: a type: computed field may declare a formula, a small arithmetic and text-join expression over the record's own fields, evaluated by a fixed grammar (no functions, no conditions, never eval). Money is not derived this way, and a broken formula stores a blank rather than failing the write. Rollups (sum, count, min, max, avg over a child collection, optional equality where) are declarations, not expressions.
The row-filter language
Permission rules, transition guards and attention counts share one small language for "which rows": {field: test, ...}, all tests must hold. A test is a literal or a $-variable (equality), one {"op", "value"} condition (eq, ne, in, gte, lte, gt, lt), or a list of conditions that must all hold. The $-variables are a closed set: $user_id, $account_id, $accessible_projects, $owned_projects, $writable_projects, $shared_records, $writable_shared_records. Attention counts add one operator, older_than_days, whose threshold may be read from a named setting. Nothing else can be put in a filter.
Regular expressions
A declaration holds a regular expression in one place: a field's validation.pattern. It is written in a small dialect that Python's re and ECMAScript (the engine behind JSON Schema validators and browsers) read alike, and DRON, not the engine underneath, says what it means. The pattern keywords inside the files in dron/ are written in the same dialect.
The whole value must match. A pattern is not searched for: [a-z]+ refuses abc1. The anchors ^ and $ are therefore optional, and fine to keep for the reader. An ECMAScript engine gets the same answer from new RegExp("^(?:" + pattern + ")$", "u"); the u flag (whole characters, not UTF-16 halves) is the one JSON Schema names. A JSON Schema pattern keyword is a search, so a pattern copied into one keeps its meaning only with its anchors written.
What a pattern may hold:
| Form | Meaning |
|---|---|
| a character | itself. The characters `^ $ \ . * + ? ( ) [ ] { } \ |
. | any one character except a line end: line feed, carriage return, U+2028, U+2029 |
[abc], [a-z0-9_], [^...] | one character from the set, with ranges; ^ first means "any but these" |
\d, \D | an ASCII digit 0-9; anything else |
\w, \W | an ASCII letter, digit or _; anything else |
\s, \S | white space as ECMAScript lists it (tab, line feed, vertical tab, form feed, carriage return, space, no-break space, U+1680, U+2000 to U+200A, U+2028, U+2029, U+202F, U+205F, U+3000, U+FEFF); anything else |
\t \n \r \f \v | tab, line feed, carriage return, form feed, vertical tab |
\xHH, \uHHHH | the character with that code, two or four hexadecimal digits (not half of a surrogate pair: write a character above U+FFFF as itself) |
^, $ | the start and the end of the value, and nothing else |
(...), (?:...) | a group |
(?=...), (?!...) | a lookahead: what follows does, or does not, match |
| `a\ | b` |
*, +, ?, {n}, {n,}, {n,m} | repetition; a ? after one makes it lazy, which never changes whether a whole value matches |
Inside a class: \d \D \w \W \s and the character escapes work; a literal ], [, \ or ^ (first) is written with a backslash; a literal - is written first, last or as \-.
Everything else is refused, because the two engines read it differently or only one reads it: lookbehind ((?<=, (?<!), named groups, inline flags ((?i); write [Aa]), backreferences (\1, \k), possessive quantifiers (a++) and atomic groups, conditionals and comments, \b and \B, \A, \Z and \z (write ^ and $), Unicode properties (\p{...}), \0, control and named characters, the long form \u{...}, a count written {,m}, an unescaped {, } or ] meant literally, a backslash before a character that needs none (\- outside a class, \@), a repeated anchor or lookahead, an empty class ([], [^]) or one that starts with ], a class inside a class ([[:alpha:]]), &&, || and ~~ inside a class, a range that starts or ends with \d, \w or \s, and \S inside a class (write [^\s], or \S outside).
Four meanings are fixed here because the engines' own defaults differ:
$is the end of the value. Python's$also matches just before a
final line feed, so in Python a$\n matches an a followed by a line feed and in ECMAScript nothing matches it. The engine reads $ as the end only. The other way to close the difference, refusing every value that holds a line feed, was not taken: a textarea value has line feeds by right, and a pattern such as [^x]* is entitled to admit them.
\dand\ware ASCII. Python's default counts every Unicode digit
and letter (\d matched the Arabic-Indic digits), ECMAScript's does not.
\sis ECMAScript's list. Python's default adds U+001C to U+001F and
U+0085 and leaves out U+FEFF; Python's ASCII-only reading leaves out the no-break space and the rest. Neither is what a browser does, so the engine spells the list out.
.stops at four line ends, not only at the line feed as in Python.
A package that declares a pattern outside the dialect is refused when it is installed or upgraded, and in a dry run, with the file, the field, the pattern and what to write instead:
schemas/widgets.json: widgets: field 'code' validation: pattern '(?i)[a-z]+' is not a DRON regular expression: an inline flag ((?i at position 0) is not in the dialect; write both cases, as in [Aa]. The dialect is in docs/dron.md, "Regular expressions"
A schema already on a box (an operator's own, or one saved through the schema API) is not refused. If its pattern is in the dialect it has the meaning above; if not, it is matched with Python's re as it always was, and nothing reports it (see "Known gaps in 0.2").
tests/test_dron_regex.py holds the table of patterns with the verdict for each, and compares the engine with ECMAScript on every allowed pattern (the table's and every shipped one) against a list of values chosen for the differences above. ECMAScript's answers are recorded in tests/dron_regex_ecmascript.json, written by Node from the same cases (tests/dron_regex_reference.js); where node is installed the test runs it again and compares.
Where the definition lives
DRON is defined twice, and the two are held together by tests:
- The JSON Schema (draft 2020-12), in
dron/:
dron-collection.schema.json, dron-package.schema.json, dron-permissions.schema.json, dron-view.schema.json (the blocks of a seeded view record), dron-policy.schema.json (the deployment's own permission policy, data/permissions/policy.json), dron-document.schema.json (the signed envelope boxes send each other), and dron-common.schema.json for the shared names and the row-filter language. Every key carries a description an author or a small model can act on, and the files refuse keys the engine would silently drop. This is what an editor reads (package-authoring.md).
- The conformance replay,
tests/test_platform_differential.py(run
deliberately with pytest -m conformance): one long scripted session of requests, errors and changes to what is on disk, played against two trees and compared response for response. Today it compares this engine against an earlier commit of itself, which is how caches are proven never stale. It is also the shape a second engine would be held to: install the same packages, replay the same session, give the same answers.
tests/test_dron_schema.py is the stitching (it runs with the standard library alone: it carries its own small JSON Schema validator, so no jsonschema package is needed, and it is the way to catch a misspelt key in a package of your own: python -m pytest tests/test_dron_schema.py -k <package>). It validates every shipped schema, manifest and rules file, every seeded view's blocks and every seeded site route against the JSON Schema or the checks beside it, and for a list of declarations it checks that the loader and the schema give the same verdict. Where they differ the difference is written down in that file, with which side is right and why, so a new disagreement fails the build. The schema cannot express a few cross-field facts (a required_when that names a field the collection lacks, a duplicate nav id, bounds that leave no value, a declared count with no literal equality); the loader refuses those at load and the test lists them.
The JSON Schema says what is well formed. The replay says what the engine does with it. Neither alone is the definition. dron-write-semantics.md writes out what the engine does with one create, update or delete: the order of every check that can refuse it, which refusal wins, and what each refusal answers, every statement pinned by a test.
Versioning
This is DRON 0.2. A version is MAJOR.MINOR, and the two parts promise different things:
- A minor version only adds: a key, a choice, an operator or a
$-variable that no earlier declaration could have used. A package written for an earlier minor of the same major means the same under the new one. An engine that reads minor N installs a package written for any minor up to N of its major, and refuses one written for a later minor, which may say something it would drop or misread.
- A major version changes or removes what something already in the
language means. An engine refuses a package written for another major, older or newer: the same file could mean something else.
A package names the version it was written for in its manifest, "dron": "0.2" (dron/dron-package.schema.json; the scaffold, scripts/new_package.py, writes it). The check is made when a package is installed or upgraded, and in a dry run, before anything is written: a value that is not "MAJOR.MINOR" text, another major, or a later minor than the server reads is refused with a message naming the version the package asks for and the version the server reads. A manifest without the key was written before versions were declared and installs as it always did; every package shipped here is one today. Only a package being installed is checked: what a box already holds (installed schemas, its policy, its records) is read as it is, whatever version it was written under. The version of an exchange envelope (dron_document) is that format's own and is not this one.
0.1 was the first machine-readable form, written from what the Python loaders accept and the shipped packages use. 0.2 adds the manifest's dron key and tightens one place where the schema was looser than the engine: in a field's permissions, a list of principals is allowed only under the keys edit, read and hidden (the engine reads a list nowhere else and raised at the first request that touched the field). 0.2 has not been released, so this is part of it and the version was not raised again. Nothing in 0.1 or in a shipped package used a list under any other key. 0.2 also gives validation.pattern a dialect ("Regular expressions"): 0.1 said only "a regular expression", the engine read it as Python's re does, and a package could declare a pattern a second engine reads differently or not at all. Such a pattern is refused at install now. Every pattern in a shipped package was already in the dialect, so none was changed. For a pattern in the dialect the meaning moved in four places, all at the edge: $ no longer matches before a final line feed (seen only in a pattern that goes on past the $ or holds it in a lookahead, since the whole value must match), \d and \w are ASCII, . no longer matches a carriage return, U+2028 or U+2029, and \s is ECMAScript's list (U+001C to U+001F and U+0085 are no longer white space, U+FEFF is). Three shipped patterns use \s or \S (the link URL in app-links, the mail address in app-mail-sync, matched_to in app-banking) and none uses \d, \w or ., so those three fields now take a value holding one of the five control characters and refuse one holding U+FEFF; nothing else a shipped package accepts or refuses changed. The deployment policy and the exchange envelope have schemas (dron/dron-policy.schema.json, dron/dron-document.schema.json; description only: no engine behaviour changed). Likewise, the manifest values listed under "Known gaps in 0.2" as refused at install (a null section, an attention severity or where-operator of the wrong kind, and so on) were read as absent or as a default before; they are refused now, and no shipped manifest used one. The engine's version is object_packages.DRON_VERSION. Each schema file says "DRON 0.2" in its description; raise it there, in DRON_VERSION, in the scaffold and on this page in the same commit as any change to the files in dron/, and say here what the change means.
Known gaps in 0.2
Where the Python loaders are laxer than the schema, the schema is the intended definition and the loader is the thing to tighten.
The package loader now refuses, at install and before anything is written, what the schema refuses in these classes, naming the file, the entry or rule, the key and the DRON spelling: unknown keys (collection root, field, validation, the closed objects, manifest sections and entries, permission rules and their files); unknown actions, principals, operators and $-variables in rules and transition guards; values of the wrong type that used to be coerced (required: "no", nav_optional: "no", a text or fractional version, a boolean row-filter value, a text capability); the synonyms the engine honours but DRON does not define (regex, readonly, readOnly, a computed flag, validation.required, .not_null, .choices, .in, a {"values": [...]} enum, capitalised types, effects, schedule types, methods and nav surfaces) and unknown field types. No shipped file used a synonym. The two shipped dead keys (denominations.json's maxlength, unit_prices.json's root label) were removed, not converted: validation.max_length would have started enforcing a length.
The same install-time refusal covers the value checks that only the schema used to make, each of which was refused later (at a write, a request or a render) or silently never applied:
- validation:
min,max,exclusive_minandexclusive_maxthat are not a
number (or text the numeric-bound pattern reads, so not "1_0"); min_length and max_length that are not a whole number of at least 0; a pattern that is not text, does not compile or is outside the dialect in "Regular expressions";
- fields: a permission level that is not
edit,readorhidden; a list of
principals under any key but edit, read and hidden; a relation with no collection, or one that is not a collection name, or a display_field that is not a field name; a formula or a rollup on a field that is not type: computed, or both on one field; a rollup with no collection, fk_field or op, an op that is not sum, count, min, max or avg, an op other than count with no field, a collection, fk_field or field that is not a name, a where that is not an object of field name to one scalar; a label, help, placeholder or description that is not text; a default that is not a scalar or null; ui, layout or validation that is not an object; an enum that is empty, holds a non-scalar or repeats a value; a visible_when with no field (or equals not text, in not a list of text); a store other than extra;
- the collection:
name,collection,title,descriptionthat are not
text (a blank or null name fell back to the file's); hooks, views, search, capabilities (a list is refused), blocks, forms, ui and the other sections that are not objects ("hooks": "hook_x" declared no hook); hooks.before_write that is not an object id; views.list_mode that is not one of table, board, tree, calendar, cards or feed; search.fields, search.result_fields, views.list_fields, detail_fields, filter_fields, blocks.feed.summary_fields and a form's fields that are not lists of field names (search.fields at least one); views.board, tree, calendar and blocks.feed that are not objects, a views.related entry without a collection name and an fk_field, a blocks.feed without owner_field and time_field; a message of a unique or locked_when entry that is not text.
The manifest is held to the same rule: a null for attention, nav, objects, schemas, seed, permissions, schedules, connectors, dependencies, migrations, description or compatibility (leave the key out); a compatibility value that is not text; a schedules[].description, nav blurb or group, or attention group that is not text; a nav order that is not a whole number, or a nav surface, attention nav_id, severity or connectors[].entry that is blank, not text or not spelt as DRON spells it; an attention reads that is not a list; an attention detail that is null, blank or empty, a detail format or op that is not one of the allowed texts; and a where-operator that is missing, not text or not spelt as DRON spells it (GT for gt), in a count's where or a detail part's where. A manifest refusal stops the dry run with the same text instead of listing it in warnings (the manifest is read before any plan is made). Mutating every shipped manifest finds no value the schema refuses and the loader accepts.
The refusal names the file, the field or entry, the key and the allowed values, and the package dry run reports it in warnings with the same reason. No shipped package used any of them, so none was changed. SCHEMA_STRICTER in tests/test_dron_schema.py, the list of declarations the schema refuses and the loader accepted, is empty: a new entry is a disagreement to fix.
What is still open:
- **A stored pattern outside the regular-expression dialect is not
reported.** A package is refused for one ("Regular expressions"). A schema already on a box, or saved through the schema API, is read as before: a pattern in the dialect gets the dialect's meaning, one outside it is matched with Python's re, and no finding says which fields those are (the policy has a findings report; schemas have none yet).
- The dialect does not bound the time a pattern takes.
(a*)*bis in it,
and both engines backtrack on it. A package's patterns are its author's; nothing limits the nesting of repetition.
- A browser's
patternattribute is stricter than the dialect. It
compiles with ECMAScript's v flag, which wants ( ) { } / | escaped inside a class. The dialect is the u flag's, the one JSON Schema names; the server does not write the attribute.
- The engine's own name checks still use Python's
$. A field name,
package id or the like that ends in a line feed passes the engine's check (re.match with $) and is refused by the schema, whose patterns are read with the dialect's $. No test case holds one. Field patterns are not affected.
- The engine still honours the synonyms, and the loose values, in a schema
already stored on a box (an operator's own, or one saved through the schema API) and in the deployment's own policy file: a box must not stop reading its own data over a key. A package declaration is held to DRON, and so is a policy an operator saves (next item).
- The deployment policy document is described by
dron-policy.schema.json
(access_mode, roles, user_roles, admin_roles, rules; each rule is the rule definition of dron-permissions.schema.json, reused). The engine's reading of a stored policy (object_permissions.policy_from_dict) is laxer in ways that matter: an unknown key is ignored, so a misspelt rule key is dropped and a misspelt row_filter turns an allow into a rule covering every row, and a deny with an unknown principal, a $-variable that is not one or an expires_at that is not a date is silently never applied. The cases are listed in tests/test_dron_schema.py (POLICY_ENGINE_LAXER), with which side is right. Two moments are treated differently:
- Saving is held to DRON.
PUT /permissions/policy(and
`object_permission_store.replace_policy`, which installs the starter
policy) refuses, before anything is written, a policy with an unknown key
on the policy or on a rule (with the closest spelling), an unknown effect,
action, principal form, row-filter operator or `$`-variable, a value of the
wrong type the engine would coerce, or a `valid_from`/`expires_at` that
does not parse: `400`, naming each rule by index and package tag, and the
key. It reuses the package check (`check_rule_declaration`). Rules the
stored policy already holds, read the same way by the engine, are not
judged again, so `GET /permissions/policy` then `PUT` it back saves, on a
box carrying package rules from an older release too. The exception fails
closed: while the stored file has a serious finding, a save that would
write the affected rule back in its widened form (making a typo
"written" and erasing its report) is refused, naming the finding, until
the same save fixes or removes it. All 13 `POLICY_ENGINE_LAXER` cases are
refused at save.
- Reading is reported, not refused. A policy file written by hand or
left by an older release loads exactly as before and every decision is
the same. Each mistake is reported, with what the engine does with it
today and how to fix it: an `/admin/status` alert, `policy.findings` and
warnings in `/permissions/status`, `findings` in `/permissions/unshipped`,
a startup log line while permission checks are on, and `findings` in a
restore's policy-difference preview. The ones that make the policy allow
more than written (an ignored key that narrows an allow, a deny that can
never apply, an ignored `rules` or `admin_roles`) are marked `serious`.
A package install, which rewrites the file, writes a rule or a
misspelt top-level key (`rulez`, `admin_role`) with a serious finding
back as the file held it, so the finding is not lost and no decision
changes.
- An allow that is wider than written can be switched off. With
`DBBASIC_POLICY_FAIL_CLOSED_WIDENED_ALLOWS` on, every stored allow rule
with a serious finding (a narrowing key that is ignored or null) grants
nothing: decisions are made as if it were absent, while it stays in the
file to be fixed. The finding says "this rule is not applied"; with the
setting off it says "this rule applies more widely than written; set
DBBASIC_POLICY_FAIL_CLOSED_WIDENED_ALLOWS to stop applying it". The
setting is off by default, so an existing box decides as it did on
upgrade; the default may turn on in a later release
(docs/permissions-model.md).
- Still the owner's decision: the deny side. A stored deny that never
applies (a principal that matches nobody, an expiry that does not parse,
a filter that matches no row) also lets the policy allow more than
written, and whether it should fail closed when read is not decided. The
setting above does not touch deny rules: each is applied, or not, exactly
as before, and reported.
- The exchange envelope is described by
dron-document.schema.json: the
envelope's keys and each document kind's body (purchase order, order confirmation, invoice, credit note, remittance, receipt, and the control messages). Every refusal validate_envelope makes that a schema can express is made by the schema too, and the 219 envelopes the exchange tests build and validate were checked against it (every one the engine accepted, the schema accepts). Engine only, because they need computation: the signature and the canonical bytes (sorted keys, no floats, ASCII keys), the SHA-256 a delivery or a refusal names, the clock window, a remittance whose settled amounts add up to paid_minor, two lines with one line_id, a created_at that is not a real day, and that a float is never a number here (JSON Schema's integer includes 1850.0). Where the schema is stricter than the engine it is right (a quantity "1_0" that Python reads as 10, a unit_code that is a number, the documented optional keys charge_minor, payment_reference, quantity_rejected and refusal code with the wrong type); the cases are ENVELOPE_* in tests/test_dron_schema.py. The patterns end in $, which Python's re also lets match before a final newline (so the engine accepts an id ending in a newline); a validator that follows ECMAScript refuses it, as this test's validator now does (it reads the files' patterns in the dialect of "Regular expressions"), and that is the intended reading. The long proposal printed in section 3 of box-to-box-exchange.md is marked illustrative and is refused by both. The envelope's own version (dron_document: "0.1") is not DRON's.
- Not described yet: the shape of object source files. (Seeded view and route
records are described; the view blocks by dron-view.schema.json, the route and view columns by checks in tests/test_dron_schema.py.) The loader does not check a seeded view's blocks at install: a bad block draws a placeholder card at runtime, which is why the schema refuses what the renderer only tolerates.