Project

General

Profile

Hydrilla on-disk data format » History » Version 9

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