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-common.schema.json · 14.7 KB · 432 lines
| 1 | { |
| 2 | "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 3 | "title": "DRON common definitions", |
| 4 | "description": "DRON (Data Rules Object Notation) is a portable, declarative description of an application's data and the rules over it: collections and their fields, validation, state machines, permissions, and the queues that need a person. These are the definitions the other DRON schemas share: names, the $-variables, and the row-filter language that permission rules, transition guards and attention counts all use. Every \"pattern\" keyword in the DRON schema files is written in the DRON regular-expression dialect (docs/dron.md, \"Regular expressions\"), which Python's re and ECMAScript read alike; a validator must read $ as the end of the text only. DRON 0.2.", |
| 5 | "$defs": { |
| 6 | "fieldName": { |
| 7 | "title": "Field name", |
| 8 | "description": "A field (column) name: a letter or underscore, then letters, digits and underscores, at most 64 characters. Example: \"owner_id\".", |
| 9 | "type": "string", |
| 10 | "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$" |
| 11 | }, |
| 12 | "collectionName": { |
| 13 | "title": "Collection or object name", |
| 14 | "description": "The name of a collection, or of an installed object: letters, digits and underscores, 1 to 64 characters. Example: \"time_logs\".", |
| 15 | "type": "string", |
| 16 | "pattern": "^[A-Za-z0-9_]{1,64}$" |
| 17 | }, |
| 18 | "packageId": { |
| 19 | "title": "Package id", |
| 20 | "description": "A package identifier: starts with a lowercase letter, then lowercase letters, digits, underscores and hyphens, at most 64 characters. Example: \"app-invoices\".", |
| 21 | "type": "string", |
| 22 | "pattern": "^[a-z][a-z0-9_-]{0,63}$" |
| 23 | }, |
| 24 | "slug": { |
| 25 | "title": "Registry id", |
| 26 | "description": "An id that becomes a record id in a registry (a schedule, a nav entry, an attention source): starts with a lowercase letter, then lowercase letters, digits and underscores. Example: \"scans_to_confirm\".", |
| 27 | "type": "string", |
| 28 | "pattern": "^[a-z][a-z0-9_]{0,63}$" |
| 29 | }, |
| 30 | "relativePath": { |
| 31 | "title": "Package-relative path", |
| 32 | "description": "A path inside the package directory. It must not be absolute and must not contain a '..' segment. Example: \"schemas/invoices.json\".", |
| 33 | "type": "string", |
| 34 | "minLength": 1, |
| 35 | "pattern": "^[^/]", |
| 36 | "not": { |
| 37 | "pattern": "(^|/)\\.\\.(/|$)" |
| 38 | } |
| 39 | }, |
| 40 | "nonBlankText": { |
| 41 | "title": "Non-blank text", |
| 42 | "description": "Text with at least one character that is not whitespace.", |
| 43 | "type": "string", |
| 44 | "pattern": "\\S" |
| 45 | }, |
| 46 | "variable": { |
| 47 | "title": "$-variable", |
| 48 | "description": "A name the engine fills in per viewer when it evaluates a rule. $user_id and $account_id are the viewer's ids; $accessible_projects, $owned_projects and $writable_projects are sets of project ids; $shared_records and $writable_shared_records are the ids of this collection's records shared with the viewer. A $-variable that resolves to nothing (an anonymous viewer has no $user_id) matches no row. Any other string starting with $ is NOT a variable: the engine reads it as a literal that never matches, which is why DRON refuses it.", |
| 49 | "enum": [ |
| 50 | "$user_id", |
| 51 | "$account_id", |
| 52 | "$accessible_projects", |
| 53 | "$owned_projects", |
| 54 | "$writable_projects", |
| 55 | "$shared_records", |
| 56 | "$writable_shared_records" |
| 57 | ] |
| 58 | }, |
| 59 | "filterString": { |
| 60 | "title": "Literal or $-variable", |
| 61 | "description": "A string compared exactly with the stored text of a field: either a literal (\"approved\", \"true\", or \"\" for blank) or one of the $-variables. A literal may not start with $. Booleans are stored as the strings \"true\" and \"false\".", |
| 62 | "anyOf": [ |
| 63 | { |
| 64 | "type": "string", |
| 65 | "pattern": "^(?!\\$)" |
| 66 | }, |
| 67 | { |
| 68 | "$ref": "#/$defs/variable" |
| 69 | } |
| 70 | ] |
| 71 | }, |
| 72 | "filterScalar": { |
| 73 | "title": "Row-filter operand", |
| 74 | "description": "What a row-filter condition compares a field against: a string literal, a $-variable, or a number (compared as its text, so 5 means \"5\"). A boolean is not an operand: write \"true\" or \"false\".", |
| 75 | "anyOf": [ |
| 76 | { |
| 77 | "$ref": "#/$defs/filterString" |
| 78 | }, |
| 79 | { |
| 80 | "type": "number" |
| 81 | } |
| 82 | ] |
| 83 | }, |
| 84 | "filterCondition": { |
| 85 | "title": "Row-filter condition", |
| 86 | "description": "One comparison on one field: {\"op\": ..., \"value\": ...}. eq: equal. ne: not equal (a missing field counts as not equal). in: the field is one of a list of values, or one of a set-valued $-variable. gte, lte, gt, lt: ordered comparison, numeric when both sides are numbers, then as ISO dates, else as text. Example: {\"op\": \"gte\", \"value\": \"2026-01-01\"}.", |
| 87 | "type": "object", |
| 88 | "required": [ |
| 89 | "op" |
| 90 | ], |
| 91 | "additionalProperties": false, |
| 92 | "properties": { |
| 93 | "op": { |
| 94 | "description": "The comparison.", |
| 95 | "enum": [ |
| 96 | "eq", |
| 97 | "ne", |
| 98 | "in", |
| 99 | "gte", |
| 100 | "lte", |
| 101 | "gt", |
| 102 | "lt" |
| 103 | ] |
| 104 | }, |
| 105 | "value": { |
| 106 | "description": "What to compare with. For in, a non-empty list of strings or numbers, or a set-valued $-variable such as \"$accessible_projects\". For the other ops, one string, number or $-variable (ne also allows null)." |
| 107 | } |
| 108 | }, |
| 109 | "allOf": [ |
| 110 | { |
| 111 | "if": { |
| 112 | "properties": { |
| 113 | "op": { |
| 114 | "const": "in" |
| 115 | } |
| 116 | } |
| 117 | }, |
| 118 | "then": { |
| 119 | "required": [ |
| 120 | "value" |
| 121 | ], |
| 122 | "properties": { |
| 123 | "value": { |
| 124 | "anyOf": [ |
| 125 | { |
| 126 | "$ref": "#/$defs/variable" |
| 127 | }, |
| 128 | { |
| 129 | "type": "array", |
| 130 | "minItems": 1, |
| 131 | "items": { |
| 132 | "$ref": "#/$defs/filterScalar" |
| 133 | } |
| 134 | } |
| 135 | ] |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | }, |
| 140 | { |
| 141 | "if": { |
| 142 | "properties": { |
| 143 | "op": { |
| 144 | "enum": [ |
| 145 | "eq", |
| 146 | "gte", |
| 147 | "lte", |
| 148 | "gt", |
| 149 | "lt" |
| 150 | ] |
| 151 | } |
| 152 | } |
| 153 | }, |
| 154 | "then": { |
| 155 | "required": [ |
| 156 | "value" |
| 157 | ], |
| 158 | "properties": { |
| 159 | "value": { |
| 160 | "$ref": "#/$defs/filterScalar" |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | }, |
| 165 | { |
| 166 | "if": { |
| 167 | "properties": { |
| 168 | "op": { |
| 169 | "const": "ne" |
| 170 | } |
| 171 | } |
| 172 | }, |
| 173 | "then": { |
| 174 | "required": [ |
| 175 | "value" |
| 176 | ], |
| 177 | "properties": { |
| 178 | "value": { |
| 179 | "anyOf": [ |
| 180 | { |
| 181 | "$ref": "#/$defs/filterScalar" |
| 182 | }, |
| 183 | { |
| 184 | "type": "null" |
| 185 | } |
| 186 | ] |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | ] |
| 192 | }, |
| 193 | "rowFilter": { |
| 194 | "title": "Row filter", |
| 195 | "description": "A condition on the rows a rule covers: {field: test, ...}. A row matches when EVERY field's test holds. A test is a literal or $-variable (equality), one {\"op\", \"value\"} condition, or a list of conditions that must all hold (a range on one field). A field the row does not have never matches an equality test. Examples: {\"owner_id\": \"$user_id\"}; {\"status\": {\"op\": \"in\", \"value\": [\"open\", \"assigned\"]}}; {\"due\": [{\"op\": \"gte\", \"value\": \"2026-01-01\"}, {\"op\": \"lt\", \"value\": \"2027-01-01\"}]}.", |
| 196 | "type": "object", |
| 197 | "propertyNames": { |
| 198 | "$ref": "#/$defs/fieldName" |
| 199 | }, |
| 200 | "additionalProperties": { |
| 201 | "anyOf": [ |
| 202 | { |
| 203 | "$ref": "#/$defs/filterScalar" |
| 204 | }, |
| 205 | { |
| 206 | "$ref": "#/$defs/filterCondition" |
| 207 | }, |
| 208 | { |
| 209 | "type": "array", |
| 210 | "minItems": 1, |
| 211 | "items": { |
| 212 | "$ref": "#/$defs/filterCondition" |
| 213 | } |
| 214 | } |
| 215 | ] |
| 216 | } |
| 217 | }, |
| 218 | "guard": { |
| 219 | "title": "Transition guard", |
| 220 | "description": "The condition on a guarded state move: {field: literal-or-$variable, ...}, every pair must match the record's stored values for the move to be allowed. Only equality; values are non-empty strings. Example: {\"owner_id\": \"$user_id\"} means only the record's owner may make this move.", |
| 221 | "type": "object", |
| 222 | "minProperties": 1, |
| 223 | "propertyNames": { |
| 224 | "type": "string", |
| 225 | "minLength": 1 |
| 226 | }, |
| 227 | "additionalProperties": { |
| 228 | "allOf": [ |
| 229 | { |
| 230 | "type": "string", |
| 231 | "minLength": 1 |
| 232 | }, |
| 233 | { |
| 234 | "$ref": "#/$defs/filterString" |
| 235 | } |
| 236 | ] |
| 237 | } |
| 238 | }, |
| 239 | "stateWhen": { |
| 240 | "title": "State condition", |
| 241 | "description": "A condition on stored field values: {field: value} or {field: [values]}. It holds when EVERY named field holds one of its listed values, compared exactly as stored. Names at least one field. Example: {\"status\": [\"approved\", \"billed\"]}.", |
| 242 | "type": "object", |
| 243 | "minProperties": 1, |
| 244 | "propertyNames": { |
| 245 | "$ref": "#/$defs/fieldName" |
| 246 | }, |
| 247 | "additionalProperties": { |
| 248 | "anyOf": [ |
| 249 | { |
| 250 | "type": "string" |
| 251 | }, |
| 252 | { |
| 253 | "type": "array", |
| 254 | "minItems": 1, |
| 255 | "items": { |
| 256 | "type": "string" |
| 257 | } |
| 258 | } |
| 259 | ] |
| 260 | } |
| 261 | }, |
| 262 | "fieldAccess": { |
| 263 | "title": "Field access level", |
| 264 | "description": "How much of a field a viewer gets: edit (see and write), read (see only), hidden (removed from reads, not writable). The engine also accepts synonyms; DRON uses these three.", |
| 265 | "enum": [ |
| 266 | "edit", |
| 267 | "read", |
| 268 | "hidden" |
| 269 | ] |
| 270 | }, |
| 271 | "attentionOperand": { |
| 272 | "title": "Attention operand", |
| 273 | "description": "A value an attention condition compares with: a string literal or $-variable, or an integer (compared as its text).", |
| 274 | "anyOf": [ |
| 275 | { |
| 276 | "$ref": "#/$defs/filterString" |
| 277 | }, |
| 278 | { |
| 279 | "type": "integer" |
| 280 | } |
| 281 | ] |
| 282 | }, |
| 283 | "attentionCondition": { |
| 284 | "title": "Attention condition", |
| 285 | "description": "One comparison in an attention count: the row-filter conditions (eq, ne, in, gte, lte, gt, lt) plus older_than_days, which holds when a date or datetime field is at least that many whole days old. in takes a non-empty list of strings. older_than_days takes a whole number of days, or {\"setting\": \"some.key\", \"default\": 10} to let the operator tune the threshold in app_settings. Example: {\"op\": \"older_than_days\", \"value\": 7}.", |
| 286 | "type": "object", |
| 287 | "required": [ |
| 288 | "op" |
| 289 | ], |
| 290 | "additionalProperties": false, |
| 291 | "properties": { |
| 292 | "op": { |
| 293 | "enum": [ |
| 294 | "eq", |
| 295 | "ne", |
| 296 | "in", |
| 297 | "gte", |
| 298 | "lte", |
| 299 | "gt", |
| 300 | "lt", |
| 301 | "older_than_days" |
| 302 | ], |
| 303 | "description": "The comparison: eq, ne, in, gte, lte, gt, lt as in a row filter, or older_than_days." |
| 304 | }, |
| 305 | "value": { |
| 306 | "description": "What to compare with. For in, a non-empty list of strings. For older_than_days, a whole number of days or {\"setting\", \"default\"}. For the others, a string, $-variable or integer." |
| 307 | } |
| 308 | }, |
| 309 | "allOf": [ |
| 310 | { |
| 311 | "if": { |
| 312 | "properties": { |
| 313 | "op": { |
| 314 | "const": "in" |
| 315 | } |
| 316 | } |
| 317 | }, |
| 318 | "then": { |
| 319 | "required": [ |
| 320 | "value" |
| 321 | ], |
| 322 | "properties": { |
| 323 | "value": { |
| 324 | "type": "array", |
| 325 | "minItems": 1, |
| 326 | "items": { |
| 327 | "$ref": "#/$defs/filterString" |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | }, |
| 333 | { |
| 334 | "if": { |
| 335 | "properties": { |
| 336 | "op": { |
| 337 | "enum": [ |
| 338 | "eq", |
| 339 | "ne", |
| 340 | "gte", |
| 341 | "lte", |
| 342 | "gt", |
| 343 | "lt" |
| 344 | ] |
| 345 | } |
| 346 | } |
| 347 | }, |
| 348 | "then": { |
| 349 | "required": [ |
| 350 | "value" |
| 351 | ], |
| 352 | "properties": { |
| 353 | "value": { |
| 354 | "$ref": "#/$defs/attentionOperand" |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | }, |
| 359 | { |
| 360 | "if": { |
| 361 | "properties": { |
| 362 | "op": { |
| 363 | "const": "older_than_days" |
| 364 | } |
| 365 | } |
| 366 | }, |
| 367 | "then": { |
| 368 | "required": [ |
| 369 | "value" |
| 370 | ], |
| 371 | "properties": { |
| 372 | "value": { |
| 373 | "anyOf": [ |
| 374 | { |
| 375 | "type": "integer", |
| 376 | "minimum": 0 |
| 377 | }, |
| 378 | { |
| 379 | "type": "object", |
| 380 | "required": [ |
| 381 | "setting", |
| 382 | "default" |
| 383 | ], |
| 384 | "additionalProperties": false, |
| 385 | "properties": { |
| 386 | "setting": { |
| 387 | "description": "The app_settings key holding the threshold, two or more lowercase dotted parts. Example: \"carrier.stuck_days\".", |
| 388 | "type": "string", |
| 389 | "pattern": "^[a-z0-9_]+(\\.[a-z0-9_]+)+$" |
| 390 | }, |
| 391 | "default": { |
| 392 | "description": "Whole days used when the setting is absent or not a whole number of days.", |
| 393 | "type": "integer", |
| 394 | "minimum": 0 |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | ] |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | ] |
| 404 | }, |
| 405 | "attentionWhere": { |
| 406 | "title": "Attention where", |
| 407 | "description": "Which rows of a collection count: the row-filter language, with one extra operator (older_than_days). {field: test, ...}, every test must hold. A test is a literal or $-variable (equality), one condition, or a list of conditions. A bare list is not membership: write {\"op\": \"in\", \"value\": [...]}. Example: {\"status\": \"submitted\", \"owner_id\": \"$user_id\"}.", |
| 408 | "type": "object", |
| 409 | "minProperties": 1, |
| 410 | "propertyNames": { |
| 411 | "$ref": "#/$defs/fieldName" |
| 412 | }, |
| 413 | "additionalProperties": { |
| 414 | "anyOf": [ |
| 415 | { |
| 416 | "$ref": "#/$defs/filterString" |
| 417 | }, |
| 418 | { |
| 419 | "$ref": "#/$defs/attentionCondition" |
| 420 | }, |
| 421 | { |
| 422 | "type": "array", |
| 423 | "minItems": 1, |
| 424 | "items": { |
| 425 | "$ref": "#/$defs/attentionCondition" |
| 426 | } |
| 427 | } |
| 428 | ] |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | } |