Hydrilla on-disk data format » History » Version 5
koszko, 11/12/2021 10:03 AM
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 | 1 | koszko | { |
| 41 | // Once the json schema changes, this number will change. Our software will |
||
| 42 | // be able to handle both current and older formats thanks to this |
||
| 43 | // information present in every index.json file. |
||
| 44 | "schema_version": "2021.11.11", |
||
| 45 | |||
| 46 | // Copyright of this json file. It's a list of copyright holder information |
||
| 47 | // objects. Alternatively, "auto" can be used to make Hydrilla attempt to |
||
| 48 | // extract copyright info from the comment at the beginning of the file. |
||
| 49 | "copyright": [ |
||
| 50 | // There can be multiple entries, one for each co-holder of the |
||
| 51 | // copyright. |
||
| 52 | { |
||
| 53 | // There can also be multiple years, like ["2021","2023-2024"]. |
||
| 54 | "years": ["2021"], |
||
| 55 | // Name of the copyright holder. Depending on the situation it can |
||
| 56 | 5 | koszko | // be just the first name, name+surname, a company name, a |
| 57 | 1 | koszko | // pseudonym, etc. |
| 58 | "holder": "Wojtek Kosior" |
||
| 59 | } |
||
| 60 | ], |
||
| 61 | |||
| 62 | // License of this json file. Identifier has to be known to Hydrilla. Can |
||
| 63 | // be defined either in the same or another index.json file as a "license" |
||
| 64 | // content item. It is possible to specify license combinations, like: |
||
| 65 | // [["Expat", "and", "Apache-2.0"], "or", "GPL-3.0-only"] |
||
| 66 | // Alternatively, "auto" can be used to make Hydrilla attempt to extract |
||
| 67 | // copyright info from this file's SPDX license identifier. |
||
| 68 | "licenses": "CC0-1.0", |
||
| 69 | |||
| 70 | // Where this software/work initially comes from. In some cases (i.e. when |
||
| 71 | // the developer of content is also the one who packages it for Hydrilla) |
||
| 72 | 5 | koszko | // this might be the same as "package_url". |
| 73 | 1 | koszko | "upstream_url": "https://git.koszko.org/pydrilla/tree/example_content/hello", |
| 74 | |||
| 75 | // Where sources for the packaging of this content can be found. |
||
| 76 | 5 | koszko | "package_url": "https://git.koszko.org/pydrilla/tree/example_content/hello", |
| 77 | |||
| 78 | // Additional "comment" field can be used if needed. |
||
| 79 | // "comment": "" |
||
| 80 | 1 | koszko | |
| 81 | // List of actual site resources, pattern->payload mappings and licenses. |
||
| 82 | // Each of them is represented by an object. Meta-sites and replacement site |
||
| 83 | // interfaces will also belong here once they get implemented. |
||
| 84 | "content": [ |
||
| 85 | { |
||
| 86 | // Value of "type" can currently be one of: "resource", "license" |
||
| 87 | // and "mapping". The one we have here, "resource", defines a list |
||
| 88 | // of injectable scripts that can be used as a payload or as a |
||
| 89 | // dependency of another "resource". In the future CSS style sheets |
||
| 90 | // and WASM modules will also be composite parts of a "resource" as |
||
| 91 | // scripts are now. |
||
| 92 | "type": "resource", |
||
| 93 | |||
| 94 | 3 | koszko | // Used when referring to this resource in "dependencies" list of |
| 95 | // another resource or in "payload" field of a mapping. Should |
||
| 96 | // be consize and can only use a restricted set of characters. It |
||
| 97 | // has to match: [-0-9a-zA-Z] |
||
| 98 | "identifier": "helloapple", |
||
| 99 | 1 | koszko | |
| 100 | 3 | koszko | // "long_name" should be used to specify a user-friendly alternative |
| 101 | // to an identifier. It should not collide with a long name of some |
||
| 102 | // resource with a different uuid. However, it can change in-between |
||
| 103 | // versions of the same resource and is allowed to contain arbitrary |
||
| 104 | // unicode characters (within reason!). |
||
| 105 | "long_name": "Hello Apple", |
||
| 106 | |||
| 107 | 1 | koszko | // Different versions of the same resource can be defined in |
| 108 | // separate index.json files. This makes it easy to accidently cause |
||
| 109 | 3 | koszko | // an identifier clash. To help detect it, we require that each |
| 110 | // resource has a uuid associated with it. Attempt to define |
||
| 111 | // multiple resources with the same identifier and different uuids |
||
| 112 | // will result in an error being reported. Defining multiple |
||
| 113 | // resources with different identifiers and the same uuid is |
||
| 114 | // disallowed for now (it may be later permitted if we consider it |
||
| 115 | // good for some use-case). |
||
| 116 | 1 | koszko | "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68", |
| 117 | |||
| 118 | // "old_uuids" field can be used to indicate that some specific |
||
| 119 | 3 | koszko | // resource identifier collision is allowed, for example when some |
| 120 | 1 | koszko | // resource (e.g. a javascript library) changes its versioning |
| 121 | // schema. All definitions with one of the old uuids will be treated |
||
| 122 | // as less up-to-date versions, overriding the "version" field |
||
| 123 | 3 | koszko | // values comparison result. |
| 124 | 1 | koszko | "old_uuids": ["ad38dc5e-30b7-492d-9290-6c3ca658f1f3"], |
| 125 | |||
| 126 | 3 | koszko | // A version string. Should match: |
| 127 | 4 | koszko | // [1-9][0-9]*(\.[1-9][0-9]*)*-[1-9][0-9]*? |
| 128 | 1 | koszko | // Values of this field from various definitions of a resource will |
| 129 | // be compared to decide which one provides the most current version |
||
| 130 | // (and in the future also to see which one satisfies versioned |
||
| 131 | // dependencies...). The (optional) part after '-' is the Hydrilla |
||
| 132 | // revision number. For each new resource version it starts as 1 and |
||
| 133 | // gets incremented by 1 each time a modification to the packaging |
||
| 134 | // of this version is done. |
||
| 135 | "version": "2021.11.10-1", |
||
| 136 | |||
| 137 | // A short, meaningful description of what the resource is and/or |
||
| 138 | // what it does. |
||
| 139 | "description": "greets an apple", |
||
| 140 | |||
| 141 | // If needed, a "comment" field can be added to provide some |
||
| 142 | // additional information. |
||
| 143 | // "comment": "this resource something something", |
||
| 144 | |||
| 145 | // One should specify the copyright and licensing terms of the |
||
| 146 | // entire package. The format is the same as when specifying these |
||
| 147 | // for the index.json file, except "auto" cannot be used. |
||
| 148 | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
||
| 149 | "licenses": "CC0-1.0", |
||
| 150 | |||
| 151 | // Resource's "dependencies" array shall contain names of other |
||
| 152 | // resources that (in case of scripts at least) should get evaluated |
||
| 153 | // on a page before this resource's own scripts. |
||
| 154 | "dependencies": ["hello-message"], |
||
| 155 | |||
| 156 | // Array of javascript files that belong to this resource. |
||
| 157 | "scripts": [ |
||
| 158 | { |
||
| 159 | // Script name. It should also be a valid file path. |
||
| 160 | "name": "hello.js", |
||
| 161 | // Copyright and license info of a script file can be |
||
| 162 | // specified using the same format as in the case of the |
||
| 163 | 2 | koszko | // index.json file itself. If "copyright" or "license" is |
| 164 | // not provided, Hydrilla assumes it to be the same as the |
||
| 165 | // value specified for the resource itself. |
||
| 166 | 1 | koszko | "copyright": "auto", |
| 167 | "licenses": "auto" |
||
| 168 | }, { |
||
| 169 | "name": "bye.js" |
||
| 170 | } |
||
| 171 | ] |
||
| 172 | }, { |
||
| 173 | 3 | koszko | "type": "resource", |
| 174 | "identifier": "hello-message", |
||
| 175 | "long_name": "Hello Message", |
||
| 176 | "uuid": "1ec36229-298c-4b35-8105-c4f2e1b9811e", |
||
| 177 | 2 | koszko | // If "old_uuids" is empty, it can as well be omitted. |
| 178 | // "old_uuids": [], |
||
| 179 | 3 | koszko | "version": "2021.11.10-2", |
| 180 | 2 | koszko | "description": "define messages for saying hello and bye", |
| 181 | 3 | koszko | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
| 182 | "licenses": "CC0-1.0", |
||
| 183 | 2 | koszko | // If "dependencies" is empty, it can also be omitted. |
| 184 | 1 | koszko | // "dependencies": [], |
| 185 | "scripts": [{"name": "message.js"}] |
||
| 186 | }, { |
||
| 187 | "type": "mapping", |
||
| 188 | |||
| 189 | 3 | koszko | // Has similar function to resource's identifier. Should be consize |
| 190 | // and can only use a restricted set of characters. It has to match: |
||
| 191 | // [-0-9a-zA-Z] |
||
| 192 | // It can be the same as some resource identifier (those are |
||
| 193 | // different entities and are treated separately). |
||
| 194 | "identifier": "helloapple", |
||
| 195 | 1 | koszko | |
| 196 | 4 | koszko | // "long name", "uuid" and "old_uuids" have the same meaning as in |
| 197 | // the case of resources. |
||
| 198 | 1 | koszko | "long_name": "Hello Apple", |
| 199 | "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7", |
||
| 200 | "old_uuids": ["0525824d-f6e2-4ee2-8ac6-401e9dc79cdf"], |
||
| 201 | 4 | koszko | |
| 202 | // "version" differs from its counterpart in resource in that it has |
||
| 203 | // no revision number. It must match: [1-9][0-9]*(\.[1-9][0-9]*)* |
||
| 204 | "version": "2021.11.10", |
||
| 205 | 1 | koszko | |
| 206 | // A short, meaningful description of what the mapping does. |
||
| 207 | "description": "causes apple to get greeted on Hydrillabugs issue tracker", |
||
| 208 | |||
| 209 | // A comment, if necessary. |
||
| 210 | // "comment": "blah blah because bleh" |
||
| 211 | |||
| 212 | // The "injections" array specifies, which payloads are to be |
||
| 213 | // applied to which URLs. |
||
| 214 | "injctions": [ |
||
| 215 | { |
||
| 216 | // Should be a valid Haketilo URL pattern. |
||
| 217 | "pattern": "https://hydrillabugs.koszko.org/***", |
||
| 218 | // Should be the name of an existing resource. The resource |
||
| 219 | // may, but doesn't have to, be defined in the same |
||
| 220 | // index.json file. |
||
| 221 | "payload": "helloapple" |
||
| 222 | }, |
||
| 223 | // More associations may follow. |
||
| 224 | { |
||
| 225 | "pattern": "https://hachettebugs.koszko.org/***", |
||
| 226 | "payload": "helloapple" |
||
| 227 | } |
||
| 228 | ] |
||
| 229 | }, { |
||
| 230 | "type": "license", |
||
| 231 | |||
| 232 | // Will be used to refer to this license in other places. Should |
||
| 233 | // match the SPDX identifier if possible (despite that, please use |
||
| 234 | // "Expat" instead of "MIT" where possible). Unlike other content |
||
| 235 | // item types, "license" does not allow uuids to be used to avoid |
||
| 236 | // license id clashes. Any attempt to define multiple licenses with |
||
| 237 | // the same id will result in an error being reported. |
||
| 238 | "identifier": "CC0-1.0", |
||
| 239 | |||
| 240 | // This long name must also be unique among all license definitions. |
||
| 241 | "long_name": "Creative Commons Zero v1.0 Universal", |
||
| 242 | |||
| 243 | "legal_text": [ |
||
| 244 | // Legal text can be available in multiple forms. Usually just |
||
| 245 | // plain .txt file is enough, though. |
||
| 246 | { |
||
| 247 | // "format" should match an agreed-upon MIME type if |
||
| 248 | // possible. |
||
| 249 | "format": "text/plain", |
||
| 250 | // Value of "file" should be a path relative to the |
||
| 251 | // directory of index.json file. |
||
| 252 | "file": "cc0.txt" |
||
| 253 | } |
||
| 254 | // If a markdown version of CC0 was provided, we could add this: |
||
| 255 | // { |
||
| 256 | // "format": "text/markdown", |
||
| 257 | // "file": "cc0.md" |
||
| 258 | // } |
||
| 259 | ] |
||
| 260 | |||
| 261 | // If needed, a "comment" field can be added to clarify something. |
||
| 262 | // For example, when definind "Expat" license we could add: |
||
| 263 | // |
||
| 264 | // "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." |
||
| 265 | |||
| 266 | // If applicable, a "notice" can be included. It shall then be a |
||
| 267 | // path (relative to index.json) to a plain text file with that |
||
| 268 | // notice. |
||
| 269 | // |
||
| 270 | // "notice": "license-notice.txt" |
||
| 271 | // |
||
| 272 | // This is needed for example in case of GNU licenses (both with and |
||
| 273 | // without exceptions). For example, |
||
| 274 | // "GPL-3.0-or-later-with-html-exception" could have the following |
||
| 275 | // in its notice file: |
||
| 276 | // |
||
| 277 | // This program is free software: you can redistribute it and/or |
||
| 278 | // modify it under the terms of the GNU General Public License as |
||
| 279 | // published by the Free Software Foundation, either version 3 of |
||
| 280 | // the License, or (at your option) any later version. |
||
| 281 | // |
||
| 282 | // This program is distributed in the hope that it will be useful, |
||
| 283 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 284 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 285 | // GNU General Public License for more details. |
||
| 286 | // |
||
| 287 | // As a special exception to the GPL, any HTML file which merely |
||
| 288 | // makes function calls to this code, and for that purpose |
||
| 289 | // includes it by reference shall be deemed a separate work for |
||
| 290 | // copyright law purposes. If you modify this code, you may extend |
||
| 291 | // this exception to your version of the code, but you are not |
||
| 292 | // obligated to do so. If you do not wish to do so, delete this |
||
| 293 | // exception statement from your version. |
||
| 294 | // |
||
| 295 | // You should have received a copy of the GNU General Public License |
||
| 296 | // along with this program. If not, see |
||
| 297 | // <https://www.gnu.org/licenses/>. |
||
| 298 | } |
||
| 299 | ] |
||
| 300 | } |
||
| 301 | ``` |