askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
dron-collection.schema.json · 43.4 KB · 997 lines
| 1 | { |
| 2 | "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 3 | "title": "DRON collection", |
| 4 | "description": "DRON (Data Rules Object Notation) is a portable, declarative description of an application's data and the rules over it. A DRON collection is one table of records: its fields and types, what a valid record looks like, which states a record may move between, what freezes it, what must be unique, and how it is listed, searched and shown. It states facts about data; it has no loops, functions or wiring. This file validates one packages/<id>/schemas/<collection>.json. DRON 0.2.", |
| 5 | "type": "object", |
| 6 | "additionalProperties": false, |
| 7 | "properties": { |
| 8 | "$schema": { |
| 9 | "description": "Optional pointer to this file so an editor can offer completion and flag mistakes. The engine ignores it.", |
| 10 | "type": "string" |
| 11 | }, |
| 12 | "name": { |
| 13 | "description": "The collection's name. It must equal the file name without .json (schemas/time_logs.json declares \"time_logs\"). Letters, digits and underscores, 1 to 64 characters. If both name and collection are absent the file name is used.", |
| 14 | "$ref": "dron-common.schema.json#/$defs/collectionName" |
| 15 | }, |
| 16 | "collection": { |
| 17 | "description": "Alternative spelling of name, read only when name is absent. Prefer name.", |
| 18 | "$ref": "dron-common.schema.json#/$defs/collectionName" |
| 19 | }, |
| 20 | "title": { |
| 21 | "description": "Human title shown in lists and menus. Default: the name with underscores as spaces, title-cased. Example: \"Time Logs\".", |
| 22 | "type": "string" |
| 23 | }, |
| 24 | "version": { |
| 25 | "description": "Integer, at least 1, that you raise each time the schema changes meaning. Default 1. The engine keeps every version so a change can be rolled back.", |
| 26 | "type": "integer", |
| 27 | "minimum": 1 |
| 28 | }, |
| 29 | "description": { |
| 30 | "description": "What this collection is for and why its rules are what they are. Prose for people and agents; not interpreted. Record here the reasoning behind a gate, not a restatement of it.", |
| 31 | "type": "string" |
| 32 | }, |
| 33 | "storage": { |
| 34 | "description": "How the engine writes records to disk. \"classic\" (default) rewrites the collection file on each write. \"append\" only ever adds rows and reads the last row per id, which suits ledgers and logs that must never be rewritten.", |
| 35 | "enum": [ |
| 36 | "classic", |
| 37 | "append" |
| 38 | ] |
| 39 | }, |
| 40 | "fields": { |
| 41 | "description": "The collection's fields, in display order. Every record has an id; declare {\"name\": \"id\"} first by convention. A field not declared here can still be stored but is unchecked.", |
| 42 | "type": "array", |
| 43 | "items": { |
| 44 | "$ref": "#/$defs/field" |
| 45 | } |
| 46 | }, |
| 47 | "unique": { |
| 48 | "description": "Uniqueness constraints, enforced inside the write lock for every writer. Each entry says no two records may hold the same values for its fields (within the same scope values, if a scope is given). Blank key values are exempt. Example: [{\"fields\": [\"code\"], \"ignore_case\": true}].", |
| 49 | "type": "array", |
| 50 | "items": { |
| 51 | "$ref": "#/$defs/uniqueConstraint" |
| 52 | } |
| 53 | }, |
| 54 | "locked_when": { |
| 55 | "description": "Freeze rules, enforced inside the write lock for every writer, admins included. While the STORED record matches an entry's when, an update may change only the fields in except (or, with fields instead, anything but the fields listed), and the record cannot be deleted (unless allow_delete). Example: freeze a posted journal.", |
| 56 | "type": "array", |
| 57 | "items": { |
| 58 | "$ref": "#/$defs/lockedWhen" |
| 59 | } |
| 60 | }, |
| 61 | "locked_checks": { |
| 62 | "description": "Decisions that need other collections (a payment may not exceed its invoice), made by a read-only function of an installed object, called inside the write lock. The function is code; this entry only declares that it must be consulted, over which collections, and on which writes.", |
| 63 | "type": "array", |
| 64 | "items": { |
| 65 | "$ref": "#/$defs/lockedCheck" |
| 66 | } |
| 67 | }, |
| 68 | "subject_exempt": { |
| 69 | "description": "A sentence saying why this collection cannot be searched for a person in a subject access request (rows keyed by an anonymous token, or the operator's own mailboxes and their secrets). The privacy export returns the sentence under not_searchable instead of leaving the collection out in silence. Use it instead of a field-level subject when no field identifies a data subject. Example: \"Traffic rows are keyed by network address and an anonymous visitor token, never joined to an account.\"", |
| 70 | "type": "string", |
| 71 | "minLength": 1 |
| 72 | }, |
| 73 | "hooks": { |
| 74 | "description": "Wires code into the write path. DRON records that a hook exists; what it does is not part of DRON.", |
| 75 | "type": "object", |
| 76 | "additionalProperties": false, |
| 77 | "properties": { |
| 78 | "before_write": { |
| 79 | "description": "Name of an installed object whose BEFORE_WRITE function runs, after permission checks and before the write, on every public create, update and delete. It may reject or transform the record. Advisory only: it runs before the write lock, so it cannot close a race (use unique, locked_when or locked_checks for that).", |
| 80 | "$ref": "dron-common.schema.json#/$defs/collectionName" |
| 81 | } |
| 82 | } |
| 83 | }, |
| 84 | "forms": { |
| 85 | "description": "Layouts of the generated record form, by name. \"default\" is the one the standard form uses. Fields left out of a form are not offered (but are still validated if sent).", |
| 86 | "type": "object", |
| 87 | "additionalProperties": { |
| 88 | "$ref": "#/$defs/form" |
| 89 | } |
| 90 | }, |
| 91 | "views": { |
| 92 | "description": "How the generated list, detail and filter bar present this collection.", |
| 93 | "$ref": "#/$defs/views" |
| 94 | }, |
| 95 | "search": { |
| 96 | "description": "Opts the collection into global search. Collections without it never appear in search results. Search runs inside the permission engine.", |
| 97 | "type": "object", |
| 98 | "additionalProperties": false, |
| 99 | "properties": { |
| 100 | "fields": { |
| 101 | "description": "The fields searched. Example: [\"title\", \"content\"].", |
| 102 | "type": "array", |
| 103 | "minItems": 1, |
| 104 | "items": { |
| 105 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 106 | } |
| 107 | }, |
| 108 | "result_fields": { |
| 109 | "description": "The fields each hit returns. Default: id plus views.list_fields.", |
| 110 | "type": "array", |
| 111 | "items": { |
| 112 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | }, |
| 117 | "capabilities": { |
| 118 | "description": "Generic behaviours the platform grows on this collection's detail page from one flag each.", |
| 119 | "type": "object", |
| 120 | "additionalProperties": false, |
| 121 | "properties": { |
| 122 | "comments": { |
| 123 | "description": "true adds a comment thread to each record.", |
| 124 | "type": "boolean" |
| 125 | }, |
| 126 | "attachments": { |
| 127 | "description": "true adds an attachments list to each record.", |
| 128 | "type": "boolean" |
| 129 | }, |
| 130 | "shareable": { |
| 131 | "description": "true lets a record's owner share it with other users.", |
| 132 | "type": "boolean" |
| 133 | } |
| 134 | } |
| 135 | }, |
| 136 | "blocks": { |
| 137 | "description": "Opts the collection into a platform block.", |
| 138 | "type": "object", |
| 139 | "additionalProperties": false, |
| 140 | "properties": { |
| 141 | "feed": { |
| 142 | "description": "Makes the collection a source of the activity feed.", |
| 143 | "type": "object", |
| 144 | "additionalProperties": false, |
| 145 | "required": [ |
| 146 | "owner_field", |
| 147 | "time_field" |
| 148 | ], |
| 149 | "properties": { |
| 150 | "owner_field": { |
| 151 | "description": "Field naming the author. A viewer's feed holds records whose author they follow.", |
| 152 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 153 | }, |
| 154 | "time_field": { |
| 155 | "description": "Field holding when the item happened; the feed sorts on it.", |
| 156 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 157 | }, |
| 158 | "visibility_field": { |
| 159 | "description": "Optional field that must hold visibility_true_value for a record to appear.", |
| 160 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 161 | }, |
| 162 | "visibility_true_value": { |
| 163 | "description": "The stored text of visibility_field that means visible. Booleans are stored as \"true\". Example: \"true\".", |
| 164 | "type": "string" |
| 165 | }, |
| 166 | "summary_fields": { |
| 167 | "description": "Fields joined into the feed line. Default: views.list_fields.", |
| 168 | "type": "array", |
| 169 | "items": { |
| 170 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 171 | } |
| 172 | }, |
| 173 | "link_field": { |
| 174 | "description": "Field holding the id the feed item links to. Default \"id\".", |
| 175 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | }, |
| 181 | "flow": { |
| 182 | "description": "Names which field owns the transitions map, with who/what annotations on top of it. Passed through to the flow page and the board; the engine's own state checks read the field-level transitions.", |
| 183 | "type": "object" |
| 184 | }, |
| 185 | "ui": { |
| 186 | "description": "Free presentation hints for a front end. Not interpreted by the engine.", |
| 187 | "type": "object" |
| 188 | }, |
| 189 | "layout": { |
| 190 | "description": "Saved form layout written by a visual editor. Not interpreted by the engine.", |
| 191 | "type": "object" |
| 192 | }, |
| 193 | "table": { |
| 194 | "description": "Saved table layout written by a visual editor. Not interpreted by the engine.", |
| 195 | "type": "object" |
| 196 | }, |
| 197 | "diagram": { |
| 198 | "description": "Saved diagram placement written by a visual editor. Not interpreted by the engine.", |
| 199 | "type": "object" |
| 200 | }, |
| 201 | "validation": { |
| 202 | "description": "Reserved for collection-level validation declarations. Kept and passed through, not interpreted by DRON 0.2.", |
| 203 | "type": "object" |
| 204 | }, |
| 205 | "permissions": { |
| 206 | "description": "Reserved collection-level permission metadata, kept and passed through. Who may do what is declared in permissions/rules.json (see dron-permissions.schema.json), not here.", |
| 207 | "type": "object" |
| 208 | } |
| 209 | }, |
| 210 | "$defs": { |
| 211 | "field": { |
| 212 | "title": "DRON field", |
| 213 | "description": "One column of the collection: what it is called, what type it holds, and the rules a value must meet.", |
| 214 | "type": "object", |
| 215 | "required": [ |
| 216 | "name" |
| 217 | ], |
| 218 | "additionalProperties": false, |
| 219 | "properties": { |
| 220 | "name": { |
| 221 | "description": "The field's name: a letter or underscore, then letters, digits and underscores, at most 64 characters. \"_op\" is reserved by the engine. Example: \"amount_cents\".", |
| 222 | "$ref": "dron-common.schema.json#/$defs/fieldName", |
| 223 | "not": { |
| 224 | "const": "_op" |
| 225 | } |
| 226 | }, |
| 227 | "type": { |
| 228 | "description": "What the field holds; values are stored as text and checked against the type on every write. text (default), textarea (multi-line text), integer (alias int), number (decimals; aliases float, currency), boolean (alias bool; stored as \"true\" or \"false\"), date (YYYY-MM-DD), datetime (ISO-8601; alias timestamp), enum (one of the listed values), computed (the server fills it from a formula or rollup; a client may not write it), relation (a pointer, with the relation key). Money is an integer in the smallest unit (cents), never a decimal.", |
| 229 | "enum": [ |
| 230 | "text", |
| 231 | "textarea", |
| 232 | "integer", |
| 233 | "int", |
| 234 | "number", |
| 235 | "float", |
| 236 | "currency", |
| 237 | "boolean", |
| 238 | "bool", |
| 239 | "date", |
| 240 | "datetime", |
| 241 | "timestamp", |
| 242 | "enum", |
| 243 | "computed", |
| 244 | "relation" |
| 245 | ] |
| 246 | }, |
| 247 | "required": { |
| 248 | "description": "true makes a blank value invalid on create and update. Not applied to computed or read-only fields. Default false.", |
| 249 | "type": "boolean" |
| 250 | }, |
| 251 | "label": { |
| 252 | "description": "Name shown to people in forms, tables and filters. Example: \"Due date\".", |
| 253 | "type": "string" |
| 254 | }, |
| 255 | "help": { |
| 256 | "description": "One or two sentences shown beside the field saying what to enter and why it matters.", |
| 257 | "type": "string" |
| 258 | }, |
| 259 | "placeholder": { |
| 260 | "description": "Greyed hint shown in an empty form input.", |
| 261 | "type": "string" |
| 262 | }, |
| 263 | "description": { |
| 264 | "description": "Longer prose about the field for people and agents; not interpreted.", |
| 265 | "type": "string" |
| 266 | }, |
| 267 | "default": { |
| 268 | "description": "The value used when a create does not submit the field. Stored as text, so write \"false\" for a boolean and \"0\" for a number (a bare JSON number or boolean is accepted and stored as its text).", |
| 269 | "type": [ |
| 270 | "string", |
| 271 | "number", |
| 272 | "boolean", |
| 273 | "null" |
| 274 | ] |
| 275 | }, |
| 276 | "enum": { |
| 277 | "description": "For type enum: the allowed values. A write of any other value is refused. Example: [\"draft\", \"submitted\", \"approved\"].", |
| 278 | "type": "array", |
| 279 | "minItems": 1, |
| 280 | "uniqueItems": true, |
| 281 | "items": { |
| 282 | "type": [ |
| 283 | "string", |
| 284 | "number", |
| 285 | "boolean" |
| 286 | ] |
| 287 | } |
| 288 | }, |
| 289 | "read_only": { |
| 290 | "description": "true means a client may not write the field; the server or a trusted writer stamps it. Use for timestamps and values a person must not edit. Computed fields are read-only already.", |
| 291 | "type": "boolean" |
| 292 | }, |
| 293 | "relation": { |
| 294 | "description": "Makes the field a validated pointer to a record of another collection: a write must name an id that exists there. No joins, no cascades. A bare string is shorthand for {\"collection\": ...}.", |
| 295 | "oneOf": [ |
| 296 | { |
| 297 | "$ref": "dron-common.schema.json#/$defs/collectionName" |
| 298 | }, |
| 299 | { |
| 300 | "type": "object", |
| 301 | "required": [ |
| 302 | "collection" |
| 303 | ], |
| 304 | "additionalProperties": false, |
| 305 | "properties": { |
| 306 | "collection": { |
| 307 | "description": "The collection the id must exist in. Example: \"projects\".", |
| 308 | "$ref": "dron-common.schema.json#/$defs/collectionName" |
| 309 | }, |
| 310 | "display_field": { |
| 311 | "description": "Which field of the target record pickers and lists show instead of the raw id. Example: \"name\".", |
| 312 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 313 | }, |
| 314 | "requires": { |
| 315 | "description": "What a person writing this field over the API must be allowed to do to the record it points at: read (see it) or update (act on it). Checked on create, and on update when the pointer changes; a target the writer may not read is answered like a missing one. Use update when the row moves money, stock or state of its target (a refund on a payment, a line on an order). Absent means only that the id exists.", |
| 316 | "enum": [ |
| 317 | "read", |
| 318 | "update" |
| 319 | ] |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | ] |
| 324 | }, |
| 325 | "subject": { |
| 326 | "description": "What this field says about the person a subject access request is for (the admin-only privacy export, action_export_subject_data). email: the field holds the person's email address, so a row holding theirs is theirs. relation: the field is a relation to a record already proven to be theirs, so the row is theirs too (followed to any depth: treatment notes -> appointments -> patients). Only declared relations are followed, and only from the person's own rows, never toward a shared record. Every field whose name contains email (or is to / sent_to) needs this, or the collection needs subject_exempt; otherwise the export names the collection as undeclared and does not search it. Says what is personal; says nothing about erasure or retention. Example: \"email\".", |
| 327 | "enum": [ |
| 328 | "email", |
| 329 | "relation" |
| 330 | ] |
| 331 | }, |
| 332 | "validation": { |
| 333 | "description": "Declared limits on a value, enforced on every write by every writer.", |
| 334 | "$ref": "#/$defs/validation" |
| 335 | }, |
| 336 | "transitions": { |
| 337 | "description": "Makes the field a state machine. Maps each current value to the values it may move to; a value not listed as a key is terminal. An entry is a plain string (anyone who may update the record) or {\"to\", \"when\"} (only when every when pair matches the stored record for the viewer). Example: {\"draft\": [\"submitted\"], \"submitted\": [{\"to\": \"approved\", \"when\": {\"owner_id\": \"$user_id\"}}], \"approved\": []}.", |
| 338 | "type": "object", |
| 339 | "additionalProperties": { |
| 340 | "type": "array", |
| 341 | "items": { |
| 342 | "oneOf": [ |
| 343 | { |
| 344 | "description": "A move any updater may make.", |
| 345 | "type": "string" |
| 346 | }, |
| 347 | { |
| 348 | "description": "A guarded move.", |
| 349 | "type": "object", |
| 350 | "required": [ |
| 351 | "to" |
| 352 | ], |
| 353 | "additionalProperties": false, |
| 354 | "properties": { |
| 355 | "to": { |
| 356 | "description": "The value this move sets. Non-empty.", |
| 357 | "type": "string", |
| 358 | "minLength": 1 |
| 359 | }, |
| 360 | "when": { |
| 361 | "description": "Conditions on the stored record that must all hold for the move. Equality only. Example: {\"assigned_to\": \"$user_id\"}.", |
| 362 | "$ref": "dron-common.schema.json#/$defs/guard" |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | ] |
| 367 | } |
| 368 | } |
| 369 | }, |
| 370 | "visible_when": { |
| 371 | "description": "Show this field in forms only while another field holds a given value. Display only: it does not validate. Example: {\"field\": \"product_type\", \"equals\": \"asset\"}.", |
| 372 | "type": "object", |
| 373 | "required": [ |
| 374 | "field" |
| 375 | ], |
| 376 | "additionalProperties": false, |
| 377 | "properties": { |
| 378 | "field": { |
| 379 | "description": "The field to look at.", |
| 380 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 381 | }, |
| 382 | "equals": { |
| 383 | "description": "The stored text that makes this field visible.", |
| 384 | "type": "string" |
| 385 | }, |
| 386 | "in": { |
| 387 | "description": "A list of stored values, any of which makes this field visible.", |
| 388 | "type": "array", |
| 389 | "items": { |
| 390 | "type": "string" |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | }, |
| 395 | "permissions": { |
| 396 | "description": "Per-field access levels that refine, never widen, what the collection's permission rules already allow. Keys are principals (\"owner\", \"role:moderator\", \"public\", \"registered\", \"user:42\") or a bare role name, mapped to edit, read or hidden; \"default\" applies when none match. When several match, the most restrictive wins. A bare access string applies to everyone. Example: {\"owner\": \"read\", \"role:moderator\": \"edit\", \"default\": \"hidden\"}.", |
| 397 | "oneOf": [ |
| 398 | { |
| 399 | "$ref": "dron-common.schema.json#/$defs/fieldAccess" |
| 400 | }, |
| 401 | { |
| 402 | "type": "object", |
| 403 | "properties": { |
| 404 | "default": { |
| 405 | "description": "Access for a viewer matched by no other key.", |
| 406 | "$ref": "dron-common.schema.json#/$defs/fieldAccess" |
| 407 | }, |
| 408 | "edit": { |
| 409 | "description": "The principals this level applies to, a list such as [\"role:admin\"]. (A single level written here as text makes edit a principal's name, not a level.)", |
| 410 | "anyOf": [ |
| 411 | { |
| 412 | "$ref": "dron-common.schema.json#/$defs/fieldAccess" |
| 413 | }, |
| 414 | { |
| 415 | "type": "array", |
| 416 | "items": { |
| 417 | "type": "string", |
| 418 | "minLength": 1 |
| 419 | } |
| 420 | } |
| 421 | ] |
| 422 | }, |
| 423 | "read": { |
| 424 | "description": "The principals this level applies to, a list such as [\"registered\"]. (A single level written here as text makes read a principal's name, not a level.)", |
| 425 | "anyOf": [ |
| 426 | { |
| 427 | "$ref": "dron-common.schema.json#/$defs/fieldAccess" |
| 428 | }, |
| 429 | { |
| 430 | "type": "array", |
| 431 | "items": { |
| 432 | "type": "string", |
| 433 | "minLength": 1 |
| 434 | } |
| 435 | } |
| 436 | ] |
| 437 | }, |
| 438 | "hidden": { |
| 439 | "description": "The principals this level applies to, a list such as [\"public\"]. (A single level written here as text makes hidden a principal's name, not a level.)", |
| 440 | "anyOf": [ |
| 441 | { |
| 442 | "$ref": "dron-common.schema.json#/$defs/fieldAccess" |
| 443 | }, |
| 444 | { |
| 445 | "type": "array", |
| 446 | "items": { |
| 447 | "type": "string", |
| 448 | "minLength": 1 |
| 449 | } |
| 450 | } |
| 451 | ] |
| 452 | }, |
| 453 | "roles": { |
| 454 | "description": "Role name to access. Example: {\"sales\": \"hidden\"}.", |
| 455 | "type": "object", |
| 456 | "additionalProperties": { |
| 457 | "$ref": "dron-common.schema.json#/$defs/fieldAccess" |
| 458 | } |
| 459 | } |
| 460 | }, |
| 461 | "additionalProperties": { |
| 462 | "description": "A principal mapped to an access level (edit, read or hidden). A list of principals is not allowed under a principal: it is allowed only under the keys edit, read and hidden.", |
| 463 | "$ref": "dron-common.schema.json#/$defs/fieldAccess" |
| 464 | } |
| 465 | } |
| 466 | ] |
| 467 | }, |
| 468 | "store": { |
| 469 | "description": "\"extra\" keeps the value inside the record's JSON extra column instead of its own column. Such a field cannot appear in unique.", |
| 470 | "const": "extra" |
| 471 | }, |
| 472 | "ui": { |
| 473 | "description": "Free presentation hints for a front end. Not interpreted by the engine.", |
| 474 | "type": "object" |
| 475 | }, |
| 476 | "layout": { |
| 477 | "description": "Saved form placement written by a visual editor. Not interpreted by the engine.", |
| 478 | "type": "object" |
| 479 | }, |
| 480 | "formula": { |
| 481 | "description": "For type computed: a small arithmetic expression over this record's other fields, stored on every write of the record. Grammar: numbers, \"strings\", field names, + - * / and parentheses; + adds two numbers or joins text. A broken formula stores blank and never fails the write. This is DRON 0.2's single expression form; money must not be derived by formula (a fold must not replace a value it cannot reproduce). Example: \"first_name + \\\" \\\" + last_name\".", |
| 482 | "type": "string", |
| 483 | "pattern": "\\S" |
| 484 | }, |
| 485 | "rollup": { |
| 486 | "description": "For type computed: a number summarising child records, stored on the parent and refreshed whenever a child is created, changed or deleted. Example: {\"collection\": \"fin_journal_lines\", \"fk_field\": \"journal_id\", \"op\": \"sum\", \"field\": \"debit_cents\"}.", |
| 487 | "type": "object", |
| 488 | "required": [ |
| 489 | "collection", |
| 490 | "fk_field", |
| 491 | "op" |
| 492 | ], |
| 493 | "additionalProperties": false, |
| 494 | "properties": { |
| 495 | "collection": { |
| 496 | "description": "The child collection to aggregate.", |
| 497 | "$ref": "dron-common.schema.json#/$defs/collectionName" |
| 498 | }, |
| 499 | "fk_field": { |
| 500 | "description": "The child field holding this record's id.", |
| 501 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 502 | }, |
| 503 | "op": { |
| 504 | "description": "sum, min, max or avg of the child field; count of the children. An empty sum is \"0\"; an empty min, max or avg is blank.", |
| 505 | "enum": [ |
| 506 | "sum", |
| 507 | "count", |
| 508 | "min", |
| 509 | "max", |
| 510 | "avg" |
| 511 | ] |
| 512 | }, |
| 513 | "field": { |
| 514 | "description": "The child field aggregated. Required for every op except count; a sum without it silently reads 0.", |
| 515 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 516 | }, |
| 517 | "where": { |
| 518 | "description": "Only children whose fields equal these stored texts are counted. Equality only. Example: {\"status\": \"received\"}.", |
| 519 | "type": "object", |
| 520 | "propertyNames": { |
| 521 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 522 | }, |
| 523 | "additionalProperties": { |
| 524 | "type": [ |
| 525 | "string", |
| 526 | "number", |
| 527 | "boolean" |
| 528 | ] |
| 529 | } |
| 530 | } |
| 531 | }, |
| 532 | "if": { |
| 533 | "properties": { |
| 534 | "op": { |
| 535 | "not": { |
| 536 | "const": "count" |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | }, |
| 541 | "then": { |
| 542 | "required": [ |
| 543 | "field" |
| 544 | ] |
| 545 | } |
| 546 | } |
| 547 | }, |
| 548 | "allOf": [ |
| 549 | { |
| 550 | "description": "formula and rollup only act on a computed field; on any other type they are silently ignored.", |
| 551 | "if": { |
| 552 | "anyOf": [ |
| 553 | { |
| 554 | "required": [ |
| 555 | "formula" |
| 556 | ] |
| 557 | }, |
| 558 | { |
| 559 | "required": [ |
| 560 | "rollup" |
| 561 | ] |
| 562 | } |
| 563 | ] |
| 564 | }, |
| 565 | "then": { |
| 566 | "required": [ |
| 567 | "type" |
| 568 | ], |
| 569 | "properties": { |
| 570 | "type": { |
| 571 | "const": "computed" |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | }, |
| 576 | { |
| 577 | "description": "A field cannot be both a formula and a rollup.", |
| 578 | "not": { |
| 579 | "required": [ |
| 580 | "formula", |
| 581 | "rollup" |
| 582 | ] |
| 583 | } |
| 584 | }, |
| 585 | { |
| 586 | "description": "exclusive_min and exclusive_max need a numeric field; on a text field every write would be refused.", |
| 587 | "if": { |
| 588 | "required": [ |
| 589 | "validation" |
| 590 | ], |
| 591 | "properties": { |
| 592 | "validation": { |
| 593 | "anyOf": [ |
| 594 | { |
| 595 | "required": [ |
| 596 | "exclusive_min" |
| 597 | ] |
| 598 | }, |
| 599 | { |
| 600 | "required": [ |
| 601 | "exclusive_max" |
| 602 | ] |
| 603 | } |
| 604 | ] |
| 605 | } |
| 606 | } |
| 607 | }, |
| 608 | "then": { |
| 609 | "required": [ |
| 610 | "type" |
| 611 | ], |
| 612 | "properties": { |
| 613 | "type": { |
| 614 | "enum": [ |
| 615 | "integer", |
| 616 | "int", |
| 617 | "number", |
| 618 | "float", |
| 619 | "currency" |
| 620 | ] |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | }, |
| 625 | { |
| 626 | "description": "required_when on a computed or read-only field can never be satisfied, since nobody can supply the value.", |
| 627 | "if": { |
| 628 | "required": [ |
| 629 | "validation" |
| 630 | ], |
| 631 | "properties": { |
| 632 | "validation": { |
| 633 | "required": [ |
| 634 | "required_when" |
| 635 | ] |
| 636 | } |
| 637 | } |
| 638 | }, |
| 639 | "then": { |
| 640 | "properties": { |
| 641 | "type": { |
| 642 | "not": { |
| 643 | "const": "computed" |
| 644 | } |
| 645 | }, |
| 646 | "read_only": { |
| 647 | "not": { |
| 648 | "const": true |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | ] |
| 655 | }, |
| 656 | "validation": { |
| 657 | "title": "DRON field validation", |
| 658 | "description": "Limits a stored value must meet. Checked on every write (web form, API, agent, import, daemon); the form's own checks are only a convenience. A blank value skips every limit except required and required_when. Limits that need other fields to exist (required_when naming a real field, bounds that leave no value) are checked when the schema loads.", |
| 659 | "type": "object", |
| 660 | "additionalProperties": false, |
| 661 | "properties": { |
| 662 | "min_length": { |
| 663 | "description": "Fewest characters. Example: 3.", |
| 664 | "type": "integer", |
| 665 | "minimum": 0 |
| 666 | }, |
| 667 | "max_length": { |
| 668 | "description": "Most characters. Example: 200.", |
| 669 | "type": "integer", |
| 670 | "minimum": 0 |
| 671 | }, |
| 672 | "pattern": { |
| 673 | "description": "A regular expression the WHOLE value must match (not a search, so the anchors ^ and $ are optional; an ECMAScript engine wraps it as ^(?:pattern)$ with the u flag). It is written in the DRON dialect, which Python's re and ECMAScript read alike: literal characters, . (not a line end), classes with ranges like [a-z0-9_] and [^/], \\d and \\w (ASCII), \\s (ECMAScript's white space), \\t \\n \\r \\xHH, ^ and $ (the start and end of the value; $ never matches before a final newline), groups ( ) and (?: ), lookahead (?= ) and (?! ), | for either, and the quantifiers * + ? {n} {n,} {n,m}. Refused at install: lookbehind, named groups, inline flags such as (?i) (write [Aa]), backreferences, possessive quantifiers, atomic groups, \\b, \\A, \\Z, \\p{...}, and a literal { } or ] without a backslash. \"format\": \"regex\" here means this dialect; the full list is in docs/dron.md, \"Regular expressions\". Example for a URL, as it is written in the JSON file (a backslash is doubled there): \"^https?://\\\\S+$\". Example for a three-letter code: \"[A-Z]{3}\".", |
| 674 | "type": "string", |
| 675 | "format": "regex" |
| 676 | }, |
| 677 | "min": { |
| 678 | "description": "Inclusive lower bound, numeric fields. min: 1 admits 1 and refuses 0. For whole-number counts. Example: 1.", |
| 679 | "$ref": "#/$defs/numericBound" |
| 680 | }, |
| 681 | "max": { |
| 682 | "description": "Inclusive upper bound, numeric fields.", |
| 683 | "$ref": "#/$defs/numericBound" |
| 684 | }, |
| 685 | "exclusive_min": { |
| 686 | "description": "Strict lower bound: the value must be greater than this, compared exactly (decimal, not float). exclusive_min: 0 says \"greater than zero\" and admits 0.0000001. Numeric fields only. Example: 0.", |
| 687 | "$ref": "#/$defs/numericBound" |
| 688 | }, |
| 689 | "exclusive_max": { |
| 690 | "description": "Strict upper bound: the value must be less than this. Numeric fields only.", |
| 691 | "$ref": "#/$defs/numericBound" |
| 692 | }, |
| 693 | "required_when": { |
| 694 | "description": "The field must be non-blank while the record matches EVERY condition: {field: value} or {field: [values]}. Judged on the record as it will be stored, so the write that sets the condition must also set this field. Cannot name this field, an undeclared field, or sit on a computed or read-only field. Example: {\"match_status\": [\"matched\"]} on matched_to.", |
| 695 | "$ref": "dron-common.schema.json#/$defs/stateWhen" |
| 696 | } |
| 697 | } |
| 698 | }, |
| 699 | "uniqueConstraint": { |
| 700 | "title": "DRON unique constraint", |
| 701 | "description": "No two records may hold the same values for fields, within the same values for scope. Values are compared trimmed; a blank key means the record has no key and is exempt. A field may appear only once across fields and scope; id, computed fields and store=extra fields are refused.", |
| 702 | "type": "object", |
| 703 | "required": [ |
| 704 | "fields" |
| 705 | ], |
| 706 | "additionalProperties": false, |
| 707 | "properties": { |
| 708 | "fields": { |
| 709 | "description": "The key: one or more field names that together must be unique. Example: [\"event_id\"].", |
| 710 | "type": "array", |
| 711 | "minItems": 1, |
| 712 | "uniqueItems": true, |
| 713 | "items": { |
| 714 | "$ref": "dron-common.schema.json#/$defs/fieldName", |
| 715 | "not": { |
| 716 | "const": "id" |
| 717 | } |
| 718 | } |
| 719 | }, |
| 720 | "scope": { |
| 721 | "description": "Fields the key is unique within (\"per owner\", \"per bank account\"). Default none: unique across the whole collection. Example: [\"owner_id\"].", |
| 722 | "type": "array", |
| 723 | "uniqueItems": true, |
| 724 | "items": { |
| 725 | "$ref": "dron-common.schema.json#/$defs/fieldName", |
| 726 | "not": { |
| 727 | "const": "id" |
| 728 | } |
| 729 | } |
| 730 | }, |
| 731 | "ignore_case": { |
| 732 | "description": "true compares the fields without regard to letter case. Default false.", |
| 733 | "type": "boolean" |
| 734 | }, |
| 735 | "message": { |
| 736 | "description": "What the person refused reads, instead of the generated sentence. Write it for them, not for a developer. Example: \"That code is already in use.\"", |
| 737 | "$ref": "dron-common.schema.json#/$defs/nonBlankText" |
| 738 | } |
| 739 | } |
| 740 | }, |
| 741 | "lockedWhen": { |
| 742 | "title": "DRON locked_when rule", |
| 743 | "description": "While the stored record matches when, an update may change only the except fields (or, written with fields instead, may change anything but the fields listed) and the record cannot be deleted unless allow_delete. Judged by the stored record, not by what the write would produce. Creates are never blocked. Every matching rule applies, and each only restricts. Name except or fields, never both.", |
| 744 | "type": "object", |
| 745 | "required": [ |
| 746 | "when" |
| 747 | ], |
| 748 | "not": { |
| 749 | "required": [ |
| 750 | "except", |
| 751 | "fields" |
| 752 | ] |
| 753 | }, |
| 754 | "additionalProperties": false, |
| 755 | "properties": { |
| 756 | "when": { |
| 757 | "description": "The state that freezes the record: {field: value} or {field: [values]}, every named field holding one of its values. Names at least one field. Example: {\"status\": [\"approved\", \"billed\"]}.", |
| 758 | "$ref": "dron-common.schema.json#/$defs/stateWhen" |
| 759 | }, |
| 760 | "except": { |
| 761 | "description": "Fields an update may still change while frozen. Everything else, including fields added later, is frozen. Put the state field here so its transitions can move the record out of the state; leave it out and the state is terminal. Example: [\"status\", \"invoice_id\", \"notes\"].", |
| 762 | "type": "array", |
| 763 | "items": { |
| 764 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 765 | } |
| 766 | }, |
| 767 | "fields": { |
| 768 | "description": "The opposite of except: freeze ONLY these fields while the rule applies; every other field, including ones added later, stays editable. Non-empty, declared fields of this collection, not id. Cannot be combined with except. Example: [\"title\", \"description\"].", |
| 769 | "type": "array", |
| 770 | "minItems": 1, |
| 771 | "items": { |
| 772 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 773 | } |
| 774 | }, |
| 775 | "allow_delete": { |
| 776 | "description": "true freezes the fields but still lets the record be deleted. Default false.", |
| 777 | "type": "boolean" |
| 778 | }, |
| 779 | "message": { |
| 780 | "description": "What the person refused reads. Say what is settled and what to do instead. Example: \"Approved time is settled. Correct it with a new entry.\"", |
| 781 | "$ref": "dron-common.schema.json#/$defs/nonBlankText" |
| 782 | } |
| 783 | } |
| 784 | }, |
| 785 | "lockedCheck": { |
| 786 | "title": "DRON locked check", |
| 787 | "description": "Before any write that on selects, call a read-only function of an installed object while holding lock, with every collection in reads held still. Refuse the write unless it allows.", |
| 788 | "type": "object", |
| 789 | "required": [ |
| 790 | "object" |
| 791 | ], |
| 792 | "additionalProperties": false, |
| 793 | "properties": { |
| 794 | "object": { |
| 795 | "description": "Id of the installed object that ships the check function. Example: \"hook_payments\".", |
| 796 | "$ref": "dron-common.schema.json#/$defs/collectionName" |
| 797 | }, |
| 798 | "name": { |
| 799 | "description": "A name for this check, unique within the collection. Letters, digits and underscores. Default: the object id.", |
| 800 | "type": "string", |
| 801 | "pattern": "^[A-Za-z0-9_]{1,64}$" |
| 802 | }, |
| 803 | "function": { |
| 804 | "description": "The function to call. Default \"LOCKED_CHECK\". It may not be a request verb or the hook (GET, POST, PUT, PATCH, DELETE, COUNT, BEFORE_WRITE): a check is its own read-only function.", |
| 805 | "type": "string", |
| 806 | "pattern": "^[A-Za-z][A-Za-z0-9_]{0,63}$", |
| 807 | "not": { |
| 808 | "pattern": "^([gG][eE][tT]|[pP][oO][sS][tT]|[pP][uU][tT]|[pP][aA][tT][cC][hH]|[dD][eE][lL][eE][tT][eE]|[cC][oO][uU][nN][tT]|[bB][eE][fF][oO][rR][eE]_[wW][rR][iI][tT][eE])$" |
| 809 | } |
| 810 | }, |
| 811 | "reads": { |
| 812 | "description": "Every collection the function reads. This decides which other writers must take the same lock, so a missing collection leaves an input unlocked; a misspelling is an error. Example: [\"invoices\", \"refunds\"].", |
| 813 | "type": "array", |
| 814 | "items": { |
| 815 | "$ref": "dron-common.schema.json#/$defs/collectionName" |
| 816 | } |
| 817 | }, |
| 818 | "lock": { |
| 819 | "description": "Name of the lock to hold; writers of different collections sharing a lock exclude each other. Lowercase letters, digits and underscores. Default: this collection's name.", |
| 820 | "type": "string", |
| 821 | "pattern": "^[a-z0-9_]{1,64}$" |
| 822 | }, |
| 823 | "on": { |
| 824 | "description": "Which writes consult the check. Each key defaults to true. update may be true (any change), false, or a non-empty list of the fields whose change triggers the check. Selecting no write at all is refused. Example: {\"create\": true, \"update\": [\"amount_cents\"], \"delete\": true}.", |
| 825 | "type": "object", |
| 826 | "additionalProperties": false, |
| 827 | "properties": { |
| 828 | "create": { |
| 829 | "type": "boolean", |
| 830 | "description": "true (default) consults the check before every create." |
| 831 | }, |
| 832 | "delete": { |
| 833 | "type": "boolean", |
| 834 | "description": "true (default) consults the check before every delete." |
| 835 | }, |
| 836 | "update": { |
| 837 | "anyOf": [ |
| 838 | { |
| 839 | "type": "boolean" |
| 840 | }, |
| 841 | { |
| 842 | "type": "array", |
| 843 | "minItems": 1, |
| 844 | "items": { |
| 845 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 846 | } |
| 847 | } |
| 848 | ], |
| 849 | "description": "true (default): before every update. A list of field names: only before an update that changes one of them. false: never." |
| 850 | } |
| 851 | }, |
| 852 | "not": { |
| 853 | "required": [ |
| 854 | "create", |
| 855 | "update", |
| 856 | "delete" |
| 857 | ], |
| 858 | "properties": { |
| 859 | "create": { |
| 860 | "const": false |
| 861 | }, |
| 862 | "update": { |
| 863 | "const": false |
| 864 | }, |
| 865 | "delete": { |
| 866 | "const": false |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | } |
| 872 | }, |
| 873 | "form": { |
| 874 | "title": "DRON form layout", |
| 875 | "description": "One named layout of the generated record form.", |
| 876 | "type": "object", |
| 877 | "additionalProperties": true, |
| 878 | "properties": { |
| 879 | "fields": { |
| 880 | "description": "Field names in the order the form shows them. Leave out server-stamped fields. Example: [\"title\", \"due_date\"].", |
| 881 | "type": "array", |
| 882 | "items": { |
| 883 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | }, |
| 888 | "views": { |
| 889 | "title": "DRON views", |
| 890 | "description": "Presentation of lists and detail pages, derived from the schema so no page code is needed.", |
| 891 | "type": "object", |
| 892 | "additionalProperties": false, |
| 893 | "properties": { |
| 894 | "list_mode": { |
| 895 | "description": "How the generated list renders. table: sortable columns over list_fields. board: kanban grouped by an enum field, drag to transition (transitions still gate it). tree: nests a self-relation. calendar: buckets by a date field. cards or feed: the plain rich-row list. Absent means cards.", |
| 896 | "enum": [ |
| 897 | "table", |
| 898 | "board", |
| 899 | "tree", |
| 900 | "calendar", |
| 901 | "cards", |
| 902 | "feed" |
| 903 | ] |
| 904 | }, |
| 905 | "list_fields": { |
| 906 | "description": "Columns of a table, card fields of a board, or summary fields of a row list. Relation fields show the target's display_field.", |
| 907 | "type": "array", |
| 908 | "items": { |
| 909 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 910 | } |
| 911 | }, |
| 912 | "detail_fields": { |
| 913 | "description": "Fields shown on the record's detail page, in order. Default: all fields.", |
| 914 | "type": "array", |
| 915 | "items": { |
| 916 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 917 | } |
| 918 | }, |
| 919 | "filter_fields": { |
| 920 | "description": "Fields offered as a filter bar above the list (enum as a select, boolean as Yes/No). A pick narrows the fetch on the server, after permissions. Example: [\"status\"].", |
| 921 | "type": "array", |
| 922 | "items": { |
| 923 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 924 | } |
| 925 | }, |
| 926 | "board": { |
| 927 | "description": "Board settings.", |
| 928 | "type": "object", |
| 929 | "additionalProperties": false, |
| 930 | "properties": { |
| 931 | "group_field": { |
| 932 | "description": "The enum field whose values become the columns. Default: the first enum field with transitions.", |
| 933 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 934 | } |
| 935 | } |
| 936 | }, |
| 937 | "tree": { |
| 938 | "description": "Tree settings.", |
| 939 | "type": "object", |
| 940 | "additionalProperties": false, |
| 941 | "properties": { |
| 942 | "parent_field": { |
| 943 | "description": "The self-relation naming each record's parent. Default \"parent_id\".", |
| 944 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 945 | } |
| 946 | } |
| 947 | }, |
| 948 | "calendar": { |
| 949 | "description": "Calendar settings.", |
| 950 | "type": "object", |
| 951 | "additionalProperties": false, |
| 952 | "properties": { |
| 953 | "date_field": { |
| 954 | "description": "The date or datetime field a record is placed by. Records without one appear under Undated.", |
| 955 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 956 | } |
| 957 | } |
| 958 | }, |
| 959 | "related": { |
| 960 | "description": "Child collections listed on a record's detail page. Example: [{\"collection\": \"interactions\", \"fk_field\": \"contact_id\"}].", |
| 961 | "type": "array", |
| 962 | "items": { |
| 963 | "type": "object", |
| 964 | "required": [ |
| 965 | "collection", |
| 966 | "fk_field" |
| 967 | ], |
| 968 | "additionalProperties": false, |
| 969 | "properties": { |
| 970 | "collection": { |
| 971 | "description": "The child collection.", |
| 972 | "$ref": "dron-common.schema.json#/$defs/collectionName" |
| 973 | }, |
| 974 | "fk_field": { |
| 975 | "description": "The child field that holds this record's id.", |
| 976 | "$ref": "dron-common.schema.json#/$defs/fieldName" |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | }, |
| 983 | "numericBound": { |
| 984 | "title": "Numeric bound", |
| 985 | "description": "A finite number, or text that reads as one (\"0\", \"2.5\", \"1e3\"). The comparison is exact (decimal), not float.", |
| 986 | "anyOf": [ |
| 987 | { |
| 988 | "type": "number" |
| 989 | }, |
| 990 | { |
| 991 | "type": "string", |
| 992 | "pattern": "^\\s*[+-]?([0-9]+\\.?[0-9]*|\\.[0-9]+)([eE][+-]?[0-9]+)?\\s*$" |
| 993 | } |
| 994 | ] |
| 995 | } |
| 996 | } |
| 997 | } |