Project

General

Profile

Hydrilla on-disk data format » History » Version 1

koszko, 11/11/2021 04:52 PM
explain the index.json file format that will be used by Hydrilla

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