Hydrilla on-disk data format » History » Version 12
koszko, 11/13/2021 12:50 PM
minor corrections
| 1 | 1 | koszko | # Hydrilla on-disk data format |
|---|---|---|---|
| 2 | |||
| 3 | This page explains the upcoming format for Hydrilla site content stored in the filesystem. It refers to the upcoming Hydrilla 0.2 release. |
||
| 4 | |||
| 5 | {{toc}} |
||
| 6 | |||
| 7 | ## How Hydrilla loads content |
||
| 8 | |||
| 9 | Hydrilla expects a content directory to be specified in its configuration file (under the key "content-dir"). It then processes all its direct subdirectories. If given subdirectory contains an `index.json` file, Hydrilla loads it (smartly ignoring '//' comments in it) and collects the definitions of site resources, pattern->payload mappings and licenses in it. |
||
| 10 | |||
| 11 | ## Format of an index.json |
||
| 12 | |||
| 13 | To understand the format, look into this example file with explanatory comments in it: |
||
| 14 | |||
| 15 | ``` javascript |
||
| 16 | // SPDX-License-Identifier: CC0-1.0 |
||
| 17 | |||
| 18 | // Copyright (C) 2021 Wojtek Kosior |
||
| 19 | // Available under the terms of Creative Commons Zero v1.0 Universal. |
||
| 20 | |||
| 21 | // This is an example index.json file describing Hydrilla site content. As you |
||
| 22 | // can see, for storing site content information Hydrilla utilizes JSON with an |
||
| 23 | // additional extension in the form of '//' comments support. Hydrilla shall |
||
| 24 | // look into each direct subdirectory of the content directory passed to it |
||
| 25 | // (via a cofig file option). If such subsirectory contains an index.json file, |
||
| 26 | // Hydrilla shall process it. |
||
| 27 | |||
| 28 | // An index.json file conveys definitions of site resources, pattern->payload |
||
| 29 | // mappings and licenses thereof. The definitions may reference files under |
||
| 30 | // index.json's containing directory, using relative paths. This is how scripts, |
||
| 31 | // license texts, etc. are included. Unix paths (using '/' as separator) are |
||
| 32 | // assumed. It is not allowed for an index.json file to reference files outside |
||
| 33 | // its directory. |
||
| 34 | |||
| 35 | 5 | koszko | // Certain objects are allowed to contain a "comment" field. Although '//' |
| 36 | // comments can be used in index.json files, they will be stripped when the file |
||
| 37 | // is processed. If a comment should be included in the JSON definitions served |
||
| 38 | // by Hydrilla API, it should be put in a "comment" field of the proper object. |
||
| 39 | |||
| 40 | 7 | koszko | // Various kinds of objects contain version information. Version is always an |
| 41 | // array of integers, with major version number being the first array item. When |
||
| 42 | 9 | koszko | // applicable, a version is accompanied by a revision field which contains a |
| 43 | // positive integer. If versions specified by arrays of different length need to |
||
| 44 | // be compared, the shorter array gets padded with zeroes on the right. This |
||
| 45 | // means that for example version 1.3 could be given as both [1, 3] and |
||
| 46 | // [1, 3, 0, 0] (aka 1.3.0.0) and either would mean the same. |
||
| 47 | 7 | koszko | |
| 48 | 1 | koszko | { |
| 49 | // Once our json schema changes, this version will change. Our software will |
||
| 50 | 7 | koszko | // be able to handle both current and older formats thanks to this |
| 51 | 10 | koszko | // information present in every index.json file. Different schema versions |
| 52 | // are always incompatible (e.g. a Hydrilla instance that understands schema |
||
| 53 | // version 0.2.0.0 will not understand version 0.2.0.1). Schemas that are |
||
| 54 | // backwards-compatible will be denoted by a different revision. |
||
| 55 | // We |
||
| 56 | // will try to make schema version match the version of Hydrilla software |
||
| 57 | // that introduced it. |
||
| 58 | 7 | koszko | "schema_version": [0, 2], |
| 59 | "schema_revision": 1, |
||
| 60 | 1 | koszko | |
| 61 | // Copyright of this json file. It's a list of copyright holder information |
||
| 62 | // objects. Alternatively, "auto" can be used to make Hydrilla attempt to |
||
| 63 | // extract copyright info from the comment at the beginning of the file. |
||
| 64 | "copyright": [ |
||
| 65 | // There can be multiple entries, one for each co-holder of the |
||
| 66 | // copyright. |
||
| 67 | { |
||
| 68 | // There can also be multiple years, like ["2021","2023-2024"]. |
||
| 69 | "years": ["2021"], |
||
| 70 | 5 | koszko | // Name of the copyright holder. Depending on the situation it can |
| 71 | 1 | koszko | // be just the first name, name+surname, a company name, a |
| 72 | // pseudonym, etc. |
||
| 73 | "holder": "Wojtek Kosior" |
||
| 74 | } |
||
| 75 | ], |
||
| 76 | |||
| 77 | // License of this json file. Identifier has to be known to Hydrilla. Can |
||
| 78 | 6 | koszko | // be defined either in the same or another index.json file as a "license" |
| 79 | 1 | koszko | // item. It is possible to specify license combinations, like: |
| 80 | // [["Expat", "and", "Apache-2.0"], "or", "GPL-3.0-only"] |
||
| 81 | // Alternatively, "auto" can be used to make Hydrilla attempt to extract |
||
| 82 | // copyright info from this file's SPDX license identifier. |
||
| 83 | "licenses": "CC0-1.0", |
||
| 84 | |||
| 85 | // Where this software/work initially comes from. In some cases (i.e. when |
||
| 86 | 5 | koszko | // the developer of content is also the one who packages it for Hydrilla) |
| 87 | 1 | koszko | // this might be the same as "package_url". |
| 88 | "upstream_url": "https://git.koszko.org/pydrilla/tree/example_content/hello", |
||
| 89 | |||
| 90 | 5 | koszko | // Where sources for the packaging of this content can be found. |
| 91 | "package_url": "https://git.koszko.org/pydrilla/tree/example_content/hello", |
||
| 92 | |||
| 93 | // Additional "comment" field can be used if needed. |
||
| 94 | 1 | koszko | // "comment": "" |
| 95 | |||
| 96 | // List of actual site resources, pattern->payload mappings and licenses. |
||
| 97 | // Each of them is represented by an object. Meta-sites and replacement site |
||
| 98 | 6 | koszko | // interfaces will also belong here once they get implemented. |
| 99 | 1 | koszko | "definitions": [ |
| 100 | { |
||
| 101 | // Value of "type" can currently be one of: "resource", "license" |
||
| 102 | // and "mapping". The one we have here, "resource", defines a list |
||
| 103 | // of injectable scripts that can be used as a payload or as a |
||
| 104 | // dependency of another "resource". In the future CSS style sheets |
||
| 105 | // and WASM modules will also be composite parts of a "resource" as |
||
| 106 | // scripts are now. |
||
| 107 | "type": "resource", |
||
| 108 | 3 | koszko | |
| 109 | // Used when referring to this resource in "dependencies" list of |
||
| 110 | // another resource or in "payload" field of a mapping. Should |
||
| 111 | // be consize and can only use a restricted set of characters. It |
||
| 112 | // has to match: [-0-9a-zA-Z] |
||
| 113 | 1 | koszko | "identifier": "helloapple", |
| 114 | 3 | koszko | |
| 115 | // "long_name" should be used to specify a user-friendly alternative |
||
| 116 | 8 | koszko | // to an identifier. It should generally not collide with a long |
| 117 | // name of some resource with a different uuid and also shouldn't |
||
| 118 | // change in-between versions of the same resource, although |
||
| 119 | // exceptions to both rules might be considered. Long name is |
||
| 120 | // allowed to contain arbitrary unicode characters (within reason!). |
||
| 121 | 1 | koszko | "long_name": "Hello Apple", |
| 122 | |||
| 123 | 8 | koszko | // Different versions (e.g. 1.0 and 1.3) of the same resource can be |
| 124 | // defined in separate index.json files. This makes it easy to |
||
| 125 | // accidently cause an identifier clash. To help detect it, we |
||
| 126 | // require that each resource has a uuid associated with it. Attempt |
||
| 127 | // to define multiple resources with the same identifier and |
||
| 128 | // different uuids will result in an error being reported. Defining |
||
| 129 | // multiple resources with different identifiers and the same uuid |
||
| 130 | // is disallowed for now (it may be later permitted if we consider |
||
| 131 | // it good for some use-case). |
||
| 132 | 1 | koszko | "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68", |
| 133 | |||
| 134 | 7 | koszko | // Version should match the upstream version of the resource (e.g. a |
| 135 | // version of javascript library). Revision number starts as 1 for |
||
| 136 | // each new resource version and gets incremented by 1 each time a |
||
| 137 | 11 | koszko | // modification to the packaging of this version is done. Hydrilla |
| 138 | // will allow multiple definitions of the same resource to load, as |
||
| 139 | // long as their versions differ. If multiple definitions of the |
||
| 140 | // same version of given resource are provided, an error is |
||
| 141 | // generated (even if those definitions differ by revision number). |
||
| 142 | 7 | koszko | "version": [2021, 11, 10], |
| 143 | 9 | koszko | "revision": 1, |
| 144 | 1 | koszko | |
| 145 | // A short, meaningful description of what the resource is and/or |
||
| 146 | // what it does. |
||
| 147 | "description": "greets an apple", |
||
| 148 | |||
| 149 | // If needed, a "comment" field can be added to provide some |
||
| 150 | // additional information. |
||
| 151 | // "comment": "this resource something something", |
||
| 152 | |||
| 153 | // One should specify the copyright and licensing terms of the |
||
| 154 | // entire package. The format is the same as when specifying these |
||
| 155 | // for the index.json file, except "auto" cannot be used. |
||
| 156 | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
||
| 157 | "licenses": "CC0-1.0", |
||
| 158 | |||
| 159 | // Resource's "dependencies" array shall contain names of other |
||
| 160 | // resources that (in case of scripts at least) should get evaluated |
||
| 161 | // on a page before this resource's own scripts. |
||
| 162 | "dependencies": ["hello-message"], |
||
| 163 | |||
| 164 | // Array of javascript files that belong to this resource. |
||
| 165 | "scripts": [ |
||
| 166 | { |
||
| 167 | // Script name. It should also be a valid file path. |
||
| 168 | "name": "hello.js", |
||
| 169 | 2 | koszko | // Copyright and license info of a script file can be |
| 170 | // specified using the same format as in the case of the |
||
| 171 | 1 | koszko | // index.json file itself. If "copyright" or "license" is |
| 172 | // not provided, Hydrilla assumes it to be the same as the |
||
| 173 | // value specified for the resource itself. |
||
| 174 | "copyright": "auto", |
||
| 175 | "licenses": "auto" |
||
| 176 | }, { |
||
| 177 | "name": "bye.js" |
||
| 178 | } |
||
| 179 | 3 | koszko | ] |
| 180 | 1 | koszko | }, { |
| 181 | "type": "resource", |
||
| 182 | "identifier": "hello-message", |
||
| 183 | "long_name": "Hello Message", |
||
| 184 | 3 | koszko | "uuid": "1ec36229-298c-4b35-8105-c4f2e1b9811e", |
| 185 | "version": [2021, 11, 10], |
||
| 186 | 2 | koszko | "revision": 2, |
| 187 | "description": "define messages for saying hello and bye", |
||
| 188 | 3 | koszko | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
| 189 | 1 | koszko | "licenses": "CC0-1.0", |
| 190 | // If "dependencies" is empty, it can also be omitted. |
||
| 191 | // "dependencies": [], |
||
| 192 | "scripts": [{"name": "message.js"}] |
||
| 193 | }, { |
||
| 194 | "type": "mapping", |
||
| 195 | |||
| 196 | 3 | koszko | // Has similar function to resource's identifier. Should be consize |
| 197 | // and can only use a restricted set of characters. It has to match: |
||
| 198 | // [-0-9a-zA-Z] |
||
| 199 | // It can be the same as some resource identifier (those are |
||
| 200 | // different entities and are treated separately). |
||
| 201 | "identifier": "helloapple", |
||
| 202 | 1 | koszko | |
| 203 | 8 | koszko | // "long name" and "uuid" have the same meaning as in the case of |
| 204 | // resources. Uuids of a resource and a mapping can technically be |
||
| 205 | // the same, but it is recommended to avoid even this kind of |
||
| 206 | // repetition. |
||
| 207 | 1 | koszko | "long_name": "Hello Apple", |
| 208 | 4 | koszko | "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7", |
| 209 | |||
| 210 | // "version" differs from its counterpart in resource in that it has |
||
| 211 | 7 | koszko | // no accompanying revision number. |
| 212 | "version": [2021, 11, 10], |
||
| 213 | 1 | koszko | |
| 214 | // A short, meaningful description of what the mapping does. |
||
| 215 | "description": "causes apple to get greeted on Hydrillabugs issue tracker", |
||
| 216 | |||
| 217 | // A comment, if necessary. |
||
| 218 | // "comment": "blah blah because bleh" |
||
| 219 | |||
| 220 | 12 | koszko | // The "payloads" array specifies, which payloads are to be |
| 221 | 1 | koszko | // applied to which URLs. |
| 222 | 12 | koszko | "payloads": [ |
| 223 | 1 | koszko | { |
| 224 | // Should be a valid Haketilo URL pattern. |
||
| 225 | "pattern": "https://hydrillabugs.koszko.org/***", |
||
| 226 | // Should be the name of an existing resource. The resource |
||
| 227 | // may, but doesn't have to, be defined in the same |
||
| 228 | // index.json file. |
||
| 229 | "payload": "helloapple" |
||
| 230 | }, |
||
| 231 | // More associations may follow. |
||
| 232 | { |
||
| 233 | "pattern": "https://hachettebugs.koszko.org/***", |
||
| 234 | "payload": "helloapple" |
||
| 235 | } |
||
| 236 | ] |
||
| 237 | }, { |
||
| 238 | "type": "license", |
||
| 239 | |||
| 240 | // Will be used to refer to this license in other places. Should |
||
| 241 | 6 | koszko | // match the SPDX identifier if possible (despite that, please use |
| 242 | // "Expat" instead of "MIT" where possible). Unlike other definition |
||
| 243 | // types, "license" does not allow uuids to be used to avoid license |
||
| 244 | // id clashes. Any attempt to define multiple licenses with the same |
||
| 245 | 1 | koszko | // id will result in an error being reported. |
| 246 | "identifier": "CC0-1.0", |
||
| 247 | |||
| 248 | // This long name must also be unique among all license definitions. |
||
| 249 | "long_name": "Creative Commons Zero v1.0 Universal", |
||
| 250 | |||
| 251 | "legal_text": [ |
||
| 252 | // Legal text can be available in multiple forms. Usually just |
||
| 253 | // plain .txt file is enough, though. |
||
| 254 | { |
||
| 255 | // "format" should match an agreed-upon MIME type if |
||
| 256 | // possible. |
||
| 257 | "format": "text/plain", |
||
| 258 | // Value of "file" should be a path relative to the |
||
| 259 | // directory of index.json file. |
||
| 260 | "file": "cc0.txt" |
||
| 261 | } |
||
| 262 | // If a markdown version of CC0 was provided, we could add this: |
||
| 263 | // { |
||
| 264 | // "format": "text/markdown", |
||
| 265 | // "file": "cc0.md" |
||
| 266 | // } |
||
| 267 | ] |
||
| 268 | |||
| 269 | // If needed, a "comment" field can be added to clarify something. |
||
| 270 | // For example, when definind "Expat" license we could add: |
||
| 271 | // |
||
| 272 | // "comment": "Expat license is the most common form of the license often called \"MIT\". Many other forms of \"MIT\" license exist. Here the name \"Expat\" is used to avoid ambiguity." |
||
| 273 | |||
| 274 | // If applicable, a "notice" can be included. It shall then be a |
||
| 275 | // path (relative to index.json) to a plain text file with that |
||
| 276 | // notice. |
||
| 277 | // |
||
| 278 | // "notice": "license-notice.txt" |
||
| 279 | // |
||
| 280 | // This is needed for example in case of GNU licenses (both with and |
||
| 281 | // without exceptions). For example, |
||
| 282 | // "GPL-3.0-or-later-with-html-exception" could have the following |
||
| 283 | // in its notice file: |
||
| 284 | // |
||
| 285 | // This program is free software: you can redistribute it and/or |
||
| 286 | // modify it under the terms of the GNU General Public License as |
||
| 287 | // published by the Free Software Foundation, either version 3 of |
||
| 288 | // the License, or (at your option) any later version. |
||
| 289 | // |
||
| 290 | // This program is distributed in the hope that it will be useful, |
||
| 291 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 292 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 293 | // GNU General Public License for more details. |
||
| 294 | // |
||
| 295 | // As a special exception to the GPL, any HTML file which merely |
||
| 296 | // makes function calls to this code, and for that purpose |
||
| 297 | // includes it by reference shall be deemed a separate work for |
||
| 298 | // copyright law purposes. If you modify this code, you may extend |
||
| 299 | // this exception to your version of the code, but you are not |
||
| 300 | // obligated to do so. If you do not wish to do so, delete this |
||
| 301 | // exception statement from your version. |
||
| 302 | // |
||
| 303 | // You should have received a copy of the GNU General Public License |
||
| 304 | // along with this program. If not, see |
||
| 305 | // <https://www.gnu.org/licenses/>. |
||
| 306 | } |
||
| 307 | ] |
||
| 308 | } |
||
| 309 | ``` |