Hydrilla source package format » History » Version 2
koszko, 12/24/2021 02:43 PM
change mapping definition structure
| 1 | 1 | koszko | # Hydrilla source package format |
|---|---|---|---|
| 2 | |||
| 3 | This page explains the upcoming format for source packages used to build Hydrilla site content. It refers to the upcoming Hydrilla 1.0 release. |
||
| 4 | |||
| 5 | You might also want to read about the data format of [[Hydrilla on-disk data format| built Hydrilla resources]]. |
||
| 6 | |||
| 7 | ## How Hydrilla packages are built |
||
| 8 | Hydrilla package builder expects a source package directory and a destination directory to be specified on the command line. If source package directory is missing, current directory is used as default. |
||
| 9 | |||
| 10 | ## Desination directory |
||
| 11 | The destination directory can be considered the same as [[Hydrilla on-disk data format#How-Hydrilla-loads-content|Hydrilla's content directory]] - built artifacts will be written in conformance with Hydrilla data format. |
||
| 12 | |||
| 13 | ## Source package directory |
||
| 14 | Source package directory is expectes to contain an `index.json` file, Hydrilla loads it (smartly ignoring "//" comments in it) and collects the definitions of site resources and pattern->payload mappings in it. |
||
| 15 | |||
| 16 | ## Format of an index.json |
||
| 17 | To understand the format, look into this example file with explanatory comments in it: |
||
| 18 | |||
| 19 | ``` javascript |
||
| 20 | // SPDX-License-Identifier: CC0-1.0 |
||
| 21 | |||
| 22 | // Copyright (C) 2021 Wojtek Kosior |
||
| 23 | // Available under the terms of Creative Commons Zero v1.0 Universal. |
||
| 24 | |||
| 25 | // This is an example index.json file describing Hydrilla site content. As you |
||
| 26 | // can see, for storing site content information Hydrilla utilizes JSON with an |
||
| 27 | // additional extension in the form of '//' comments support. |
||
| 28 | |||
| 29 | // An index.json file conveys definitions of site resources and pattern->payload |
||
| 30 | // mappings. The definitions may reference files under index.json's containing |
||
| 31 | // directory, using relative paths. This is how scripts, license texts, etc. are |
||
| 32 | // included. |
||
| 33 | // File reference always takes the form of an object with "file" property |
||
| 34 | // specifying path to the file. In certain contexts additional properties may be |
||
| 35 | // allowed or required. Unix paths (using '/' as separator) are assumed. It is |
||
| 36 | // not allowed for an index.json file to reference files outside its directory. |
||
| 37 | |||
| 38 | // Certain objects are allowed to contain a "comment" field. Although '//' |
||
| 39 | // comments can be used in index.json files, they will not be included in |
||
| 40 | // generated JSON definitions. If a comment should be included in the |
||
| 41 | // definitions served by Hydrilla API, it should be put in a "comment" field of |
||
| 42 | // the proper object. |
||
| 43 | |||
| 44 | // Unknown object properties will be ignored. This is for compatibility with |
||
| 45 | // possible future revisions of the format. |
||
| 46 | |||
| 47 | // Various kinds of objects contain version information. Version is always an |
||
| 48 | // array of integers, with major version number being the first array item. When |
||
| 49 | // applicable, a version is accompanied by a revision field which contains a |
||
| 50 | // positive integer. If versions specified by arrays of different length need to |
||
| 51 | // be compared, the shorter array gets padded with zeroes on the right. This |
||
| 52 | // means that for example version 1.3 could be given as both [1, 3] and |
||
| 53 | // [1, 3, 0, 0] (aka 1.3.0.0) and either would mean the same. |
||
| 54 | |||
| 55 | { |
||
| 56 | // Once our index.json schema changes, this field's value will change. Our |
||
| 57 | // software will be able to handle both current and older formats thanks to |
||
| 58 | // this information present in every index.json file. Different schema |
||
| 59 | // versions are always incompatible (e.g. a Hydrilla instance that |
||
| 60 | // understands schema version 1.2.0.0 will not understand version 0.2.0.1). |
||
| 61 | // Schemas that are backwards-compatible will be denoted by a different |
||
| 62 | // revision. We will try to make schema version match the version of |
||
| 63 | // Hydrilla software that introduced it. |
||
| 64 | "source_schema_version": [1], |
||
| 65 | "source_schema_revision": 1, |
||
| 66 | |||
| 67 | // Used when referring to this source package. Should be consize, unique |
||
| 68 | // (among other source package names) and can only use a restricted set of |
||
| 69 | // characters. It has to match: [-0-9a-z.]+ |
||
| 70 | // If source name is lacking, Hydrilla package builder will use index.json's |
||
| 71 | // directory name instead, with all disallowed characters converted to |
||
| 72 | // hyphens ("-"). |
||
| 73 | "source_name": "hello", |
||
| 74 | |||
| 75 | // Copyright of this source package. Should list files that contain |
||
| 76 | // copyright information regarding this source package as well as texts of |
||
| 77 | // licenses used. Although no specific format of these files is mandated, it |
||
| 78 | // is recommended to make each source package REUSE-compliant, generate an |
||
| 79 | // spdx report for it as `report.spdx` and list this report together with |
||
| 80 | // all license files here. |
||
| 81 | "copyright": [ |
||
| 82 | {"file": "report.spdx"}, |
||
| 83 | {"file": "LICENSES/CC0-1.0.txt"} |
||
| 84 | ], |
||
| 85 | |||
| 86 | // Where this software/work initially comes from. |
||
| 87 | "upstream_url": "https://git.koszko.org/pydrilla/tree/src/test/example_content/hello", |
||
| 88 | |||
| 89 | // Additional "comment" field can be used if needed. |
||
| 90 | // "comment": "" |
||
| 91 | |||
| 92 | // List of actual site resources and pattern->payload mappings. Each of them |
||
| 93 | // is represented by an object. Meta-sites and replacement site interfaces |
||
| 94 | // will also belong here once they get implemented. |
||
| 95 | "definitions": [ |
||
| 96 | { |
||
| 97 | // Value of "type" can currently be one of: "resource" and |
||
| 98 | // "mapping". The one we have here, "resource", defines a list |
||
| 99 | // of injectable scripts that can be used as a payload or as a |
||
| 100 | // dependency of another "resource". In the future CSS style sheets |
||
| 101 | // and WASM modules will also be composite parts of a "resource" as |
||
| 102 | // scripts are now. |
||
| 103 | "type": "resource", |
||
| 104 | |||
| 105 | // Used when referring to this resource in "dependencies" list of |
||
| 106 | // another resource or in "payload" field of a mapping. Should |
||
| 107 | // be consize and can only use a restricted set of characters. It |
||
| 108 | // has to match: [-0-9a-z]+ |
||
| 109 | "identifier": "helloapple", |
||
| 110 | |||
| 111 | // "long_name" should be used to specify a user-friendly alternative |
||
| 112 | // to an identifier. It should generally not collide with a long |
||
| 113 | // name of some resource with a different uuid and also shouldn't |
||
| 114 | // change in-between versions of the same resource, although |
||
| 115 | // exceptions to both rules might be considered. Long name is |
||
| 116 | // allowed to contain arbitrary unicode characters (within reason!). |
||
| 117 | "long_name": "Hello Apple", |
||
| 118 | |||
| 119 | // Different versions (e.g. 1.0 and 1.3) of the same resource can be |
||
| 120 | // defined in separate index.json files. This makes it easy to |
||
| 121 | // accidently cause an identifier clash. To help detect it, we |
||
| 122 | // require that each resource has a uuid associated with it. Attempt |
||
| 123 | // to define multiple resources with the same identifier and |
||
| 124 | // different uuids will result in an error being reported. Defining |
||
| 125 | // multiple resources with different identifiers and the same uuid |
||
| 126 | // is disallowed for now (it may be later permitted if we consider |
||
| 127 | // it good for some use-case). |
||
| 128 | "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68", |
||
| 129 | |||
| 130 | // Version should match the upstream version of the resource (e.g. a |
||
| 131 | // version of javascript library). Revision number starts as 1 for |
||
| 132 | // each new resource version and gets incremented by 1 each time a |
||
| 133 | // modification to the packaging of this version is done. Hydrilla |
||
| 134 | // will allow multiple definitions of the same resource to load, as |
||
| 135 | // long as their versions differ. Thanks to the "version" and |
||
| 136 | // "revision" fields, clients will know they have to update certain |
||
| 137 | // resource after it has been updated. If multiple definitions of |
||
| 138 | // the same version of given resource are provided, an error is |
||
| 139 | // generated (even if those definitions differ by revision number). |
||
| 140 | "version": [2021, 11, 10], |
||
| 141 | "revision": 1, |
||
| 142 | |||
| 143 | // A short, meaningful description of what the resource is and/or |
||
| 144 | // what it does. |
||
| 145 | "description": "greets an apple", |
||
| 146 | |||
| 147 | // If needed, a "comment" field can be added to provide some |
||
| 148 | // additional information. |
||
| 149 | // "comment": "this resource something something", |
||
| 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 | {"file": "hello.js"}, |
||
| 159 | {"file": "bye.js"} |
||
| 160 | ] |
||
| 161 | }, { |
||
| 162 | "type": "resource", |
||
| 163 | "identifier": "hello-message", |
||
| 164 | "long_name": "Hello Message", |
||
| 165 | "uuid": "1ec36229-298c-4b35-8105-c4f2e1b9811e", |
||
| 166 | "version": [2021, 11, 10], |
||
| 167 | "revision": 2, |
||
| 168 | "description": "define messages for saying hello and bye", |
||
| 169 | // If "dependencies" is empty, it can also be omitted. |
||
| 170 | // "dependencies": [], |
||
| 171 | "scripts": [{"file": "message.js"}] |
||
| 172 | }, { |
||
| 173 | "type": "mapping", |
||
| 174 | |||
| 175 | // Has similar function to resource's identifier. Should be consize |
||
| 176 | // and can only use a restricted set of characters. It has to match: |
||
| 177 | // [-0-9a-z]+ |
||
| 178 | // It can be the same as some resource identifier (those are |
||
| 179 | // different entities and are treated separately). |
||
| 180 | "identifier": "helloapple", |
||
| 181 | |||
| 182 | // "long name" and "uuid" have the same meaning as in the case of |
||
| 183 | // resources. Uuids of a resource and a mapping can technically be |
||
| 184 | // the same, but it is recommended to avoid even this kind of |
||
| 185 | // repetition. |
||
| 186 | "long_name": "Hello Apple", |
||
| 187 | "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7", |
||
| 188 | |||
| 189 | // "version" differs from its counterpart in resource in that it has |
||
| 190 | // no accompanying revision number. |
||
| 191 | "version": [2021, 11, 10], |
||
| 192 | |||
| 193 | // A short, meaningful description of what the mapping does. |
||
| 194 | "description": "causes apple to get greeted on Hydrillabugs issue tracker", |
||
| 195 | |||
| 196 | // A comment, if necessary. |
||
| 197 | // "comment": "blah blah because bleh" |
||
| 198 | |||
| 199 | // The "payloads" array specifies which payloads are to be applied |
||
| 200 | // to which URLs. |
||
| 201 | 2 | koszko | "payloads": { |
| 202 | // Each key should be a valid Haketilo URL pattern. |
||
| 203 | "https://hydrillabugs.koszko.org/***": { |
||
| 204 | 1 | koszko | // Should be the name of an existing resource. The resource |
| 205 | // may, but doesn't have to, be defined in the same |
||
| 206 | // index.json file. |
||
| 207 | 2 | koszko | "identifier": "helloapple" |
| 208 | }, |
||
| 209 | 1 | koszko | // More associations may follow. |
| 210 | 2 | koszko | "https://hachettebugs.koszko.org/***": { |
| 211 | "identifier": "helloapple" |
||
| 212 | 1 | koszko | } |
| 213 | 2 | koszko | } |
| 214 | 1 | koszko | } |
| 215 | ] |
||
| 216 | } |
||
| 217 | ``` |