├── modifiers.libsonnet ├── modifiers-test.jsonnet ├── README.md └── LICENSE /modifiers.libsonnet: -------------------------------------------------------------------------------- 1 | 2 | // Helpers 3 | 4 | local identity = function(x) x; 5 | 6 | local foldr1(func, arr) = 7 | local length = std.length(arr); 8 | if length == 0 then 9 | error "foldr1 requires at least one element in the array" 10 | else 11 | local foldr1H(index, acc) = 12 | if index >= 0 then 13 | local newAcc = func(arr[index], acc); 14 | foldr1H(index - 1, newAcc) 15 | else 16 | acc 17 | ; 18 | foldr1H(length - 2, arr[length - 1]) 19 | ; 20 | 21 | // Compose one argument functions. It also works for curried functions. 22 | local composeFuncs(f1, f2) = function(v) f1(f2(v)); 23 | 24 | local compose(fs) = 25 | foldr1(composeFuncs, fs) 26 | ; 27 | 28 | // Apply one argument function to a value. It also works for curried functions. 29 | local apply(f, v) = f(v); 30 | 31 | // == Selectors == 32 | // Selectors are functions which access a part of a complex value (field, ) 33 | // They are useful for modifying deep structures. 34 | 35 | local override(field) = function(modifier) function(obj) 36 | assert std.isString(field); 37 | assert std.isFunction(modifier) : "modifier is not a function: " + modifier; 38 | assert std.isObject(obj); 39 | obj + { [field]: modifier(super[field]) } 40 | ; 41 | 42 | local elem(n) = function(modifier) function(arr) 43 | local changeIfNth(index, elem) = if index == n then modifier(elem) else elem; 44 | std.mapWithIndex(changeIfNth, arr); 45 | 46 | local map = function (modifier) function(arr) 47 | std.map(modifier, arr) 48 | ; 49 | 50 | // It just composes the functions, but its name allows expressing intent more clearly 51 | local chain = compose; 52 | 53 | // == Modifiers == 54 | // Modifiers are simply functions which take one argument. 55 | 56 | // const is a modifer which always provides the same value 57 | local const(val) = function(_ignored) val; 58 | 59 | // many allows merging many modifiers into one (applying all the modifications in order they are provided) 60 | // It just composes the functions, but its name allows expressing intent more clearly 61 | local many = compose; 62 | 63 | // Convenience methods 64 | 65 | local normalize(val) = 66 | if std.isString(val) then 67 | override(val) 68 | else if std.isNumber(val) then 69 | elem(val) 70 | else if std.isFunction(val) then 71 | val 72 | else 73 | error ("Unexpected value: " + val) 74 | ; 75 | 76 | 77 | // TODO(sbarzowski) come up with better name 78 | local build(ops) = 79 | assert std.isArray(ops); 80 | local o = std.map(normalize, ops); 81 | local ops = o; 82 | 83 | foldr1(apply, ops) 84 | ; 85 | 86 | local change(ops, val) = 87 | build(ops + [const(val)]) 88 | ; 89 | 90 | local changeWith(ops, fun) = 91 | build(ops + [fun]) 92 | ; 93 | { 94 | override:: override, 95 | map:: map, 96 | elem:: elem, 97 | chain:: chain, 98 | many:: many, 99 | const:: const, 100 | build:: build, 101 | change:: change, 102 | changeWith:: changeWith 103 | } 104 | 105 | -------------------------------------------------------------------------------- /modifiers-test.jsonnet: -------------------------------------------------------------------------------- 1 | local m = import 'modifiers.libsonnet'; 2 | 3 | // Proof-of-concept functionality, something I wouldn't include in the lib, but perhaps expect the user to write 4 | 5 | // selector 6 | local reparseJson = function(modifier) function(str) 7 | std.manifestJson(modifier(std.parseJson(str))) 8 | ; 9 | 10 | local changeEvenPositions = function(modifier) function(arr) 11 | std.mapWithIndex(function(index, elem) if index % 2 == 0 then modifier(elem) else elem, arr) 12 | ; 13 | 14 | // Actual tests 15 | 16 | true 17 | 18 | && std.assertEqual( 19 | {foo: "bar"}, 20 | m.override("foo")(m.const("bar"))({foo: "baz"}) 21 | ) 22 | 23 | && std.assertEqual( 24 | {foo: {"foo2": "bar"}}, 25 | m.chain([m.override("foo"), m.override("foo2")])(m.const("bar"))({foo: {foo2: "baz"}}) 26 | ) 27 | 28 | && std.assertEqual( 29 | {foo: "{\n \"foo2\": \"bar\"\n}"}, 30 | m.chain([m.override("foo"), reparseJson, m.override("foo2")])(m.const("bar"))({foo: @'{"foo2": "baz"}'}) 31 | ) 32 | && std.assertEqual([2,2,6,4,10,6], changeEvenPositions(function(x) x * 2)([1,2,3,4,5,6])) 33 | 34 | && std.assertEqual( 35 | "aaa", 36 | m.build([m.const("aaa")])({"foo": "bar"}) 37 | ) 38 | 39 | && std.assertEqual( 40 | {"foo": "aaa"}, 41 | m.build([m.override("foo"), m.const("aaa")])({"foo": "bar"}) 42 | ) 43 | 44 | && std.assertEqual( 45 | {"foo": "aaa"}, 46 | m.build(["foo", m.const("aaa")])({"foo": "bar"}) 47 | ) 48 | 49 | && std.assertEqual( 50 | {"foo": "aaa"}, 51 | m.change(["foo"], "aaa")({"foo": "bar"}) 52 | ) 53 | 54 | 55 | && std.assertEqual( 56 | {"foo": "bar"}, 57 | local obj = {"foo": "baz"}; 58 | m.change(["foo"], "bar")(obj) 59 | ) 60 | 61 | && std.assertEqual( 62 | {foo: "{\n \"foo2\": \"bar\"\n}"}, 63 | m.change(["foo", reparseJson, "foo2"], "bar")({foo: @'{"foo2": "baz"}'}) 64 | ) 65 | 66 | && std.assertEqual( 67 | [2,4,6,8,10,12], 68 | m.changeWith([m.map], function(x) x * 2)([1,2,3,4,5,6]) 69 | ) 70 | 71 | && std.assertEqual( 72 | [2, 2, 6, 4, 10, 6], 73 | m.changeWith([changeEvenPositions], function(x) x * 2)([1,2,3,4,5,6]) 74 | ) 75 | 76 | && std.assertEqual( 77 | { 78 | a: { 79 | b: { 80 | c: [ 81 | { 82 | d: "a" 83 | }, 84 | { 85 | d: "CHANGED" 86 | } 87 | ] 88 | } 89 | } 90 | }, 91 | local obj = { 92 | a: { 93 | b: { 94 | c: [ 95 | { 96 | d: "a" 97 | }, 98 | { 99 | d: "a" 100 | } 101 | ] 102 | } 103 | } 104 | }; 105 | m.change(["a", "b", "c", 1, "d"], "CHANGED")(obj) 106 | ) 107 | 108 | 109 | && std.assertEqual( 110 | {"a": {"b": {"c": [{"d": "CHANGED"}, {"d": "yyy"}]}}, "moreThings": "bar", "something": "foo"}, 111 | local obj = { 112 | a: { 113 | b: { 114 | c: [ 115 | { 116 | d: "xxx" 117 | }, 118 | { 119 | d: "yyy" 120 | } 121 | ] 122 | } 123 | }, 124 | something: "foo", 125 | moreThings: "bar" 126 | }; 127 | obj + { a +: { b +: { c: std.mapWithIndex(function(i, e) if i == 0 then e + {d: "CHANGED"} else e, super.c)}}} 128 | ) 129 | 130 | && std.assertEqual( 131 | [ 132 | "a", 133 | "x" 134 | ], 135 | m.elem(0)(m.const("a"))(["x", "x"]) 136 | ) 137 | 138 | && std.assertEqual( 139 | [ 140 | "a", 141 | "x", 142 | "b" 143 | ], 144 | m.many([ 145 | m.change([0], "a"), 146 | m.change([2], "b") 147 | ])(["x", "x", "x"]) 148 | ) 149 | 150 | && std.assertEqual( 151 | [ 152 | {"a": "foo"}, 153 | {"a": "foo"}, 154 | {"a": "foo"} 155 | ], 156 | m.change([m.map, "a"], "foo")([ 157 | {"a": 0}, 158 | {"a": 1}, 159 | {"a": 2} 160 | ]) 161 | ) 162 | 163 | && std.assertEqual( 164 | {"arr": ["CHANGED-1", "x", {"a": "CHANGED-2"}]}, 165 | local obj = { 166 | arr: ["x", "x", {"a": "b"}] 167 | }; 168 | m.changeWith( 169 | ["arr"], m.many([ 170 | m.change([0], "CHANGED-1"), 171 | m.change([2, "a"], "CHANGED-2") 172 | ]) 173 | )(obj) 174 | ) 175 | 176 | && std.assertEqual( 177 | { 178 | "foo": "{\n \"a\": {\n \"b\": \"CHANGED\"\n }\n}" 179 | }, 180 | local obj = { 181 | "foo": '{"a": {"b": "x"}}' 182 | }; 183 | 184 | m.change(["foo", reparseJson, "a", "b"], 'CHANGED')(obj) 185 | ) 186 | 187 | && std.assertEqual( 188 | [1,2,3,"!!!",5,6], 189 | local changeEveryNthPosition(n) = function(modifier) function(arr) 190 | std.mapWithIndex(function(index, elem) if index % n == (n - 1) then modifier(elem) else elem, arr) 191 | ; 192 | m.change([changeEveryNthPosition(4)], "!!!")([1,2,3,4,5,6]) 193 | ) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jsonnet-modifiers 2 | 3 | **Project status: Proof of Concept** 4 | 5 | This is a library for changing parts of big nested structures in Jsonnet. It requires a recent version of Jsonnet (>=0.12.1 recommended). 6 | 7 | ## Use case 8 | 9 | Let's say you have a complex object like this one: 10 | ``` 11 | local obj = { 12 | a: { 13 | b: { 14 | c: [ 15 | { 16 | d: "xxx" 17 | }, 18 | { 19 | d: "yyy" 20 | } 21 | ] 22 | } 23 | }, 24 | something: "foo", 25 | moreThings: "bar" 26 | }; 27 | ``` 28 | Assume you want to change the "xxx" to something else. It's not hard, but a little painful using the standard way below: 29 | ``` 30 | obj + { a +: { b +: { c: std.mapWithIndex(function(i, e) if i == 0 then e + {d: "CHANGED"} else e, super.c)}}} 31 | ``` 32 | 33 | This library provides an API like this instead: 34 | ``` 35 | m.change(["a", "b", "c", 0, "d"], "CHANGED")(obj) 36 | ``` 37 | 38 | ## Basic usage 39 | 40 | To use the library you need to import it first: 41 | ``` 42 | local m = import 'modifiers.jsonnet' 43 | ``` 44 | This line is omitted in all of the subsequent example. You probably want to use a longer name in more complicated programs. 45 | 46 | ### Changing a field in an object 47 | ``` 48 | m.change(["a"], "after")({a: "before"}) 49 | ``` 50 | Result: 51 | ``` 52 | {"a": "after"} 53 | ``` 54 | 55 | ### Changing a field in a nested object 56 | ``` 57 | m.change(["a", "b"], "after")({a: {b: "before"}) 58 | ``` 59 | Result: 60 | ``` 61 | {"a": {"b": "after"}} 62 | ``` 63 | 64 | ### Modifying (in this example incrementing) a field 65 | ``` 66 | m.changeWith(["a"], function(x) x + 1)({"a": 0}) 67 | ``` 68 | Result: 69 | ``` 70 | {"a": 1} 71 | ``` 72 | 73 | ### Changing a field in all objects in an array 74 | ``` 75 | m.change([m.map, "a"], "foo")([ 76 | {"a": 0}, 77 | {"a": 1}, 78 | {"a": 2} 79 | ]) 80 | ``` 81 | Result: 82 | ``` 83 | [ 84 | {"a": "foo"}, 85 | {"a": "foo"}, 86 | {"a": "foo"} 87 | ] 88 | ``` 89 | 90 | 91 | 92 | There are two basic functions: 93 | 94 | ``` 95 | m.change(selector_list, value)(input) 96 | m.changeWith(selector_list, func)(input) 97 | ``` 98 | 99 | Function `m.change` simply changes every matched part of `input` to a `value`, while `m.changeWith` applies `func` to every matched part. 100 | 101 | Selectors are basically generalized indices. Simple ones like strings (for indexing objects) and numbers (for indexing arrays) are possible. In particular more than one part of the value can be matched with some selectors. 102 | 103 | Available selectors are currently included: 104 | 105 | * `m.override(str)` - for indexing objects. You can pass just the string string as a shortcut. 106 | * `m.elem(n)` - for choosing one element in an array. You can pass just the number as a shortcut. 107 | * `m.map` - indexing all values in an array at once 108 | 109 | It is also possible (and easy) to create your own custom selectors. Selectors can be combined in any sequence to support any nested structure. 110 | 111 | You may also wonder what is the deal with double parentheses, why input gets a separate pair. There is a very good reason actually, explained in the next sections. 112 | 113 | ## Advanced usage 114 | 115 | ### Multiple changes at once 116 | 117 | ``` 118 | local obj = { 119 | arr: ["x", "x", {"a": "b"}] 120 | } 121 | m.changeWith( 122 | ["arr"], m.many([ 123 | m.change([0], "CHANGED-1"), 124 | m.change([2, "a"], "CHANGED-2") 125 | ]) 126 | )(obj) 127 | ``` 128 | Results in: 129 | ``` 130 | { 131 | "arr": [ 132 | "CHANGED-1", 133 | "x", 134 | {"a": "CHANGED-2"} 135 | ] 136 | }, 137 | 138 | ``` 139 | 140 | A new function `m.many` was introduced which sequentially applies modifications. 141 | 142 | See how when using `m.change` here there's no second pair of parentheses? This is because it is not applied yet to any particular input - it receives the right part through the selector and `m.many`. 143 | 144 | ### Custom selector example - indexing even elements of an array 145 | 146 | ``` 147 | local changeEvenPositions = function(modifier) function(arr) 148 | std.mapWithIndex(function(index, elem) if index % 2 == 0 then modifier(elem) else elem, arr) 149 | ; 150 | 151 | m.changeWith([changeEvenPositions], function(x) x * 2)([1,2,3,4,5,6]) 152 | ``` 153 | Please note that changeEvenPosition is curried - separate `function(modifier) function(arr)`. It is because it will not be applied to all its arguments at once. 154 | 155 | ### Custom selector example - parametrizing - indexing every nth element of an array 156 | 157 | ``` 158 | local changeEveryNthPosition(n) = function(modifier) function(arr) 159 | std.mapWithIndex(function(index, elem) if index % n == (n - 1) then modifier(elem) else elem, arr) 160 | ; 161 | 162 | m.change([changeEveryNthPosition(4)], "!!!")([1,2,3,4,5,6]) 163 | ``` 164 | Results in: 165 | ``` 166 | [1,2,3,"!!!",5,6] 167 | ``` 168 | 169 | ### Custom selector example - transparently indexing within serialized JSON 170 | 171 | ``` 172 | local reparseJson = function(modifier) function(str) 173 | std.manifestJson(modifier(std.parseJson(str))) 174 | ; 175 | 176 | local obj = { 177 | "foo": '{"a": {"b": "x"}}' 178 | }; 179 | 180 | m.change(["foo", reparseJson, "a", "b"], 'CHANGED')(obj) 181 | ``` 182 | 183 | Results in: 184 | 185 | ``` 186 | { 187 | "foo": "{\n \"a\": {\n \"b\": \"CHANGED\"\n }\n}" 188 | } 189 | ``` 190 | 191 | 192 | ## Ideas behind it 193 | 194 | There are two basic concepts: 195 | * Selector - a function which takes a modifier and a part of the structure, extracts some parts of a complex structure (e.g. a field, an element, all elements) and applies 196 | * Modifier - a function which takes a part of and returns a new version of it. Technically it can be any one argument function. 197 | 198 | In type notation, assuming that the type for the parts of the structure that we're indexing is P (for part): 199 | ``` 200 | Modifier :: P -> P 201 | Selector :: Modifier -> Modifier = (P -> P) -> P -> P 202 | ``` 203 | (For clarity: it's just a notation, there are no types like that in Jsonnet) 204 | 205 | Now it's the time for the beautiful part: 206 | * nested indexing is just function composition of Selectors 207 | * applying multiple modifications is just function composition of Modifiers 208 | (Assuming they are curried.) 209 | 210 | I'm almost certain that what I'm doing here has a standard name and/or is considered pretty obvious in functional programming community. Please let me know if you know it (for example in the issues). 211 | 212 | It reminds me of Functors only that Selectors are various possible `fmap`s and it can be pretty useful to break Functor laws (see serialized JSON example which doesn't preserve identity). 213 | 214 | 215 | ## Technical notes 216 | 217 | There is a few things to know about using this library in its current state: 218 | * It's currently a proof of concept. This means that I'm very interested in any feedback and that the API is likely to change. 219 | * When there is an error in the code using this library, the stack traces can sometimes be really awful (there's a lot of anonymous functions flying around and being applied at various points). 220 | * Some operations which are very easy with the library are quite slow. In particular, in Jsonnet changing an array element currently requires creating a shallow copy of the whole array. Similarly, modifying nested objects adds an overlay on every object on the path. 221 | * If you can structure your program so that the objects are built correctly in one go, it's probably a better idea than this whole monkey patching we're doing here. However, sometimes you just can't avoid it and then this library can help you keep the code clean and readable. 222 | 223 | 224 | ## Running tests 225 | 226 | Simply run: 227 | ``` 228 | jsonnet modifiers-test.jsonnet 229 | ``` 230 | 231 | If it prints `true` it's fine and if it complains with an error we have a problem. 232 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------