Jean Privat [Wed, 17 Aug 2016 15:00:34 +0000 (11:00 -0400)]
remove wrongly committed binary file `lib/core/collection/range`
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Wed, 17 Aug 2016 14:56:15 +0000 (10:56 -0400)]
jenkins: add checkbinaryfiles.sh
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 16 Aug 2016 21:37:29 +0000 (17:37 -0400)]
Merge: lib/popcorn: introduce AuthHandler to check user session
### AuthHandler allows access to session user
Inherit this handler to access to session user from your custom handler.
For example, you need a profile handler that checks if the user is logged
before returning it in json format.
~~~nit
import popcorn::pop_auth
class ProfileHandler
super AuthHandler
redef fun get(req, res) do
var user = check_session_user(req, res)
if user == null then return
res.json user.json
end
end
~~~
By using `check_session_user`, we delegate to the `AuthHandler` the responsability
to set the HTTP 403 error.
We then check is the user is not null before pursuing.
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Pull-Request: #2271
Reviewed-by: Jean Privat <jean@pryen.org>
Alexandre Terrasa [Tue, 16 Aug 2016 19:53:48 +0000 (15:53 -0400)]
lib/popcorn: introduce AuthHandler to check user session
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Tue, 16 Aug 2016 17:26:12 +0000 (13:26 -0400)]
Merge: remove wallet
Binary introduced by error in
840a7d2d6147a2a8ae219fa3e0f7b9dd3e5af4d5
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Pull-Request: #2270
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 16 Aug 2016 17:25:58 +0000 (13:25 -0400)]
Merge: Mongo: limit queries
Add some features used to paginate results:
* allow pop repos to query with a limit and skip
* makes Pipeline API cleaner with limit and skip
* allows user to count entities from a Repo
Pull-Request: #2269
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 16 Aug 2016 17:25:53 +0000 (13:25 -0400)]
Merge: lib/popcorn: add `remove_all` service to pop repos
No more to say here.
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Pull-Request: #2267
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 16 Aug 2016 17:25:49 +0000 (13:25 -0400)]
Merge: lib/popcorn: introduce RepoObject in pop_repos
### Base serializable entity that can go into a JsonRepository
Provide boiler plate implementation of all object serializable to json.
`id` is used as a primary key for `find_by_id`.
Subclassing RepoObject makes it easy to create a serializable class:
~~~nit
import popcorn::pop_repos
class Album
super RepoObject
serialize
var title: String
var price: Float
end
~~~
Do not forget the `serialize` annotation else the fields will not be serialized.
It is also possible to redefine the `id` primary key to use your own:
~~~nit
import popcorn::pop_repos
class Order
super RepoObject
serialize
redef var id = "order-{get_time}"
# ...
end
~~~
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Pull-Request: #2265
Reviewed-by: Jean Privat <jean@pryen.org>
Alexandre Terrasa [Mon, 15 Aug 2016 23:53:42 +0000 (19:53 -0400)]
remove wallet
Binary introduced by error in
840a7d2d6147a2a8ae219fa3e0f7b9dd3e5af4d5
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Mon, 15 Aug 2016 23:38:53 +0000 (19:38 -0400)]
lib/popcorn: introduce count in pop_repos
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Mon, 15 Aug 2016 23:38:42 +0000 (19:38 -0400)]
lib/popcorn: add limit and skip to pop_repos
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Mon, 15 Aug 2016 23:37:45 +0000 (19:37 -0400)]
lib/mongo: make limit and skip parameters optional so the client code is cleaner
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Mon, 15 Aug 2016 23:14:04 +0000 (19:14 -0400)]
lib/popcorn: introduce RepoObject in pop_repos
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Mon, 15 Aug 2016 19:41:45 +0000 (15:41 -0400)]
lib/popcorn: add `remove_all` service to pop repos
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Mon, 15 Aug 2016 19:19:20 +0000 (15:19 -0400)]
Merge: Native Windows bootstrap
This PR tweaks and hacks the core lib and the compiler to get a working bootstrap on Windows. After a regen of c_src, one could clone the repo and build c_src/nitc.exe using GCC on Windows with mingw or similar. There's a procedure using msys2 at <https://github.com/nitlang/nitlanguage/blob/master/pages/windows.mdwn>.
To achieve basic Windows compatibility, I applied the following algorithm:
1. For a missing C function, if there is an equivalent in `<windows.h>`, use an alternative static C implementation.
2. If it's a difference in a Nit only method, (like the path separator) add an alternative implementation selected at runtime.
3. If the difference spawns across more than one Nit method/class. Deactivate the code for Windows, replace by a no-op, and wait for a later fix hiding platform implementations behind an abstract API. Alternatively, we could use many `#ifdef` and keep the differences on the C side.
There are still a lot of issues:
* `c_src/nitc` can compile `hello_world` and `src/nitc.nit`. `hello_world` behaves as expected, but `src/nitc.nit` does not, there's some problems at parsing. (Maybe with the line endings.)
* The compiler hangs randomly. This may be related to different blocking behavior when reading files, or a local setup issue.
* I did not find a compatible GNU libregex, a solution is to use libboost regex. This could be declared in `lib/core/re.nit`, however would need to tweak some annotations and ensure that they work in nith. (`ldflags("-lmboost_regex-mt")@windows`)
* `poll` and `Process` related features must be replaced/implemented for Windows.
* There's a few warnings from the C compiler to check/silence.
Pull-Request: #2264
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Jean Privat [Mon, 15 Aug 2016 19:19:16 +0000 (15:19 -0400)]
Merge: Nitcc custom lexer
Proof of concept of how a nitcc lexer can be monkey-patched.
maybe not enough for @ppepos, but it's something.
Pull-Request: #2258
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Jean Privat [Mon, 15 Aug 2016 19:16:59 +0000 (15:16 -0400)]
Merge: json::serialization: fallback to the static type when there is no metadata or heuristics
Move and improve some operations between two of the serialization phases, placing them after `modelize_property_phase` so they have access to the static type of serializable attributes.
The static type is then used by the JSON deserializer as a fallback if there is no metadata and no heuristic to find which Nit type to deserialize. This affects both the attributes of standard serializable classes and the items of `SimpleCollection`, when using the `JsonDeserializer` only. This means the we need much less `class_name_heuristic` for reading plain JSON.
The static types of generic attributes is also used as heuristic to support deserializing the given parameterized type. So as long as the static type is not an abstract class, does not need an anchor, is not a subclass hiding the parameter E (for JSON arrays)... it should work. This is actually most of the time, so avoid abstract generic static types like `Set` or `Sequence`. This also means less `class_name_heuristic` for any JSON and binary data.
All of it makes it easier to deal with the following input `json_string` without metadata:
~~~
var plain_json = """{
"corners": [{"x": 0, "y": 0},
{"x": 3, "y": 0},
{"x": 2, "y": 2}],
"name": "the same triangle"
}"""
~~~
which can be deserialized with the following Nit code:
~~~
module my_module is serialize
class Triangle
var corners = new Array[Point] # Could as well be HashSet[Point]
redef var to_s is serialize_as("name") # The static type comes from the model
end
class Point
var x: Int
var y: Int
end
var deser_engine = new JsonDeserializer(json_string)
var obj = new Triangle.deserialize_from(deser_engine) # The root object still needs a type
assert deser_engine.errors.is_empty # If false, don't trust `obj`
print obj
print obj.other_corners
~~~
Pull-Request: #2257
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexis Laferrière [Mon, 15 Aug 2016 17:31:07 +0000 (13:31 -0400)]
tests: update nitce savs
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Mon, 15 Aug 2016 17:18:24 +0000 (13:18 -0400)]
Merge: lib/trees: introduce Trie
### A trie (or prefix tree) is a datastructure used to perform prefix searches.
The trie uses an arborescent datastructure to perform searches on a prefix.
With this version of the trie, you can link data to nodes so the trie can
be used as a kind of Map by prefix.
~~~nit
# Associate some integers to Map keys
var trie = new Trie[Int]
trie["foo"] = 1
trie["fooo"] = 2
trie["foooo"] = 3
trie["bar"] = 4
trie["baz"] = 5
# Get stored values by key
print trie.has_key("foo")
print trie["foo"] == 1
# Get stored values by prefix
assert trie.has_prefix("fo")
assert not trie.has_prefix("z")
assert trie.find_by_prefix("foo") == [1, 2, 3]
assert trie.find_by_prefix("bar") == [4]
assert trie.find_by_prefix("z").is_empty
~~~
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Pull-Request: #2261
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Jean Privat [Mon, 15 Aug 2016 17:18:22 +0000 (13:18 -0400)]
Merge: Make HttpRequest and Response serializable
This PR makes HTTP requests and responses serializable.
I had a hard time with deserialization because of the `host` attribute that is never initialized, I removed it. Let's see what is crashing.
Pull-Request: #2260
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Mon, 15 Aug 2016 17:18:02 +0000 (13:18 -0400)]
Merge: Nitweb sessions
Nitweb users can open sessions with Github Auth.
For now, instances are useless and the User profile page displays only `nothing to display yet`.
Demo is here: http://nitweb.moz-code.org/
Pull-Request: #2259
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 15 Aug 2016 17:17:59 +0000 (13:17 -0400)]
Merge: nitls: improve the man by giving better examples
Pull-Request: #2256
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Mon, 15 Aug 2016 17:17:54 +0000 (13:17 -0400)]
Merge: lib/mongo: introduce mongo queries
A small abstraction of JsonObject dedicated to repo queries.
Just because I'm fed up with writing my JsonObjects by hand...
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Pull-Request: #2251
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 15 Aug 2016 17:17:49 +0000 (13:17 -0400)]
Merge: lib/github: use serialization
Just to see what I broke...
Pull-Request: #2246
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Mon, 15 Aug 2016 15:54:33 +0000 (11:54 -0400)]
tests: update nituml tests
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexandre Terrasa [Mon, 15 Aug 2016 15:11:46 +0000 (11:11 -0400)]
lib/trees: introduce Trie
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexis Laferrière [Sun, 14 Aug 2016 14:07:38 +0000 (10:07 -0400)]
nitc: don't use /dev/null on windows
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Sun, 14 Aug 2016 04:05:51 +0000 (00:05 -0400)]
nitc: gen precompiler ifs to avoid features incompatible to windows
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Sun, 14 Aug 2016 19:05:05 +0000 (15:05 -0400)]
core::file & exec & enviro: deactivate incompatible implementations on windows
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Sun, 14 Aug 2016 05:29:00 +0000 (01:29 -0400)]
core::file: change basename implementation by OS
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Sun, 14 Aug 2016 19:06:05 +0000 (15:06 -0400)]
core: tweak misc services for windows
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexandre Terrasa [Sun, 14 Aug 2016 17:35:06 +0000 (13:35 -0400)]
nitweb: add user menu
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Tue, 2 Aug 2016 17:43:05 +0000 (13:43 -0400)]
nitweb/angular: add user controller
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Mon, 15 Aug 2016 04:25:30 +0000 (00:25 -0400)]
lib/nitcorn: remove uninitialized attribute `host`
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Mon, 15 Aug 2016 04:25:08 +0000 (00:25 -0400)]
lib/nitcorn: make HttpRequest and HttpResponse serializable
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Mon, 15 Aug 2016 04:22:58 +0000 (00:22 -0400)]
contrib/nitrpg: nitrpg use github serialization
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Sun, 14 Aug 2016 21:16:08 +0000 (17:16 -0400)]
lib/popcorn: pop_auth use github serialization
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Sun, 14 Aug 2016 21:15:48 +0000 (17:15 -0400)]
lib/github: use serialization
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexis Laferrière [Sun, 14 Aug 2016 04:06:34 +0000 (00:06 -0400)]
core::file: alternative C implementations for windows
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Sun, 14 Aug 2016 14:10:56 +0000 (10:10 -0400)]
core: intro `is_windows`
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexandre Terrasa [Sun, 14 Aug 2016 18:39:24 +0000 (14:39 -0400)]
nitweb: add API user login/logout end points
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Tue, 2 Aug 2016 03:26:45 +0000 (23:26 -0400)]
nitweb: init session
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Sun, 14 Aug 2016 17:10:55 +0000 (13:10 -0400)]
lib/mongo: introduce mongo queries
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Fri, 12 Aug 2016 21:53:43 +0000 (17:53 -0400)]
nitcc: add an example of a monkey-patching of a Lexer to add behavior.
Signed-off-by: Jean Privat <jean@pryen.org>
Alexis Laferrière [Fri, 12 Aug 2016 13:07:29 +0000 (09:07 -0400)]
benitlux: drop a few explicity deserialization support for generics
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Fri, 12 Aug 2016 12:40:18 +0000 (08:40 -0400)]
frontend/serialization: a bit more details to the doc
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Thu, 11 Aug 2016 18:06:05 +0000 (14:06 -0400)]
serialization: update README limitations section
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Thu, 11 Aug 2016 18:06:31 +0000 (14:06 -0400)]
json::serialization: update "Read JSON" section
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Fri, 12 Aug 2016 03:35:04 +0000 (23:35 -0400)]
json::serialization: infer the static type of the items of an array
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Fri, 12 Aug 2016 03:34:16 +0000 (23:34 -0400)]
frontent/serialization: use static types to deserialize parameterized attributes
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Thu, 11 Aug 2016 19:51:44 +0000 (15:51 -0400)]
json::serialization: use static type to deserialize arrays without metadata
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Thu, 11 Aug 2016 15:53:04 +0000 (11:53 -0400)]
frontend/serialization: pass the static type to the deserialization engine
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Thu, 11 Aug 2016 15:52:02 +0000 (11:52 -0400)]
json::serialization: fallback to the static type at deserialization
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Thu, 11 Aug 2016 15:48:49 +0000 (11:48 -0400)]
serialization: `deserialize_attribute` takes an optional static type name
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Thu, 11 Aug 2016 15:40:56 +0000 (11:40 -0400)]
frontend/serialization: use types from model at deserialization
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Thu, 11 Aug 2016 15:40:28 +0000 (11:40 -0400)]
frontent/serialization: fix warnings
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Fri, 12 Aug 2016 00:40:52 +0000 (20:40 -0400)]
nitls: improve the man by giving better examples
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Thu, 11 Aug 2016 22:18:24 +0000 (18:18 -0400)]
Merge: calculator: nicer Android adaptation with API 21 + variant
Improve the look of the Android variant for the calculator using style resources from the AOSP calculator. Also intro another variant for Android API 21+ which changes the font and deactivates the virtual keyboard.
This should also fix the calculator missing from our f-droid repository. However, I don't know yet how f-droid handles more than one APK per package...
For an idea of the result, you can take a look at the 6 different resulting calculators alongside the latest AOSP calculator: http://xymus.net/pub/calcs.pdf
Pull-Request: #2255
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Ait younes Mehdi Adel <overpex@gmail.com>
Jean Privat [Thu, 11 Aug 2016 19:43:26 +0000 (15:43 -0400)]
Merge: contrib: add shibuqam to extract information from a shibboleth authentication
Pull-Request: #2254
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Jean Privat [Thu, 11 Aug 2016 19:43:22 +0000 (15:43 -0400)]
Merge: lib/core: add `Path::/`
Pull-Request: #2253
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Jean Privat [Thu, 11 Aug 2016 19:43:20 +0000 (15:43 -0400)]
Merge: json::serialization: intro `attributes_path` as support to `class_name_heuristic`
Intro a list of the attribute names to the currently deserialized object which can be used to infer the Nit type of a JSON object to deserialize. It is not the most reliable information, some objects won't have an associated attribute like the root deserialized object and collection items.
Should help for #2246.
As a bonus, this PR improves the doc to `Deserializer` mainly to mention `errors` from `deserialize`.
Pull-Request: #2252
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Thu, 11 Aug 2016 19:42:04 +0000 (15:42 -0400)]
contrib: add shibuqam to extract information from a shibboleth authentication
Signed-off-by: Jean Privat <jean@pryen.org>
Alexis Laferrière [Wed, 10 Aug 2016 13:19:06 +0000 (09:19 -0400)]
calculator: rename android_calculator to android14
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Tue, 9 Aug 2016 14:22:33 +0000 (10:22 -0400)]
calculator: add variant for Android 21 +
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Thu, 21 Jul 2016 21:44:14 +0000 (17:44 -0400)]
calculator: prettier Android variant
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Tue, 9 Aug 2016 14:18:33 +0000 (10:18 -0400)]
calculator: add scientific variant fdroid metadata
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Thu, 11 Aug 2016 17:42:56 +0000 (13:42 -0400)]
lib/core: add `Path::/`
Signed-off-by: Jean Privat <jean@pryen.org>
Alexis Laferrière [Thu, 11 Aug 2016 12:45:20 +0000 (08:45 -0400)]
serialization: better doc for `Deserializer`
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Thu, 11 Aug 2016 11:38:16 +0000 (07:38 -0400)]
json::serialization: intro `attributes_path` as support to `class_name_heuristic`
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Thu, 11 Aug 2016 01:53:50 +0000 (21:53 -0400)]
Merge: nitweb: use pop_config
Nitweb use popconfig
No changes on the output.
Pull-Request: #2247
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Thu, 11 Aug 2016 01:53:18 +0000 (21:53 -0400)]
Merge: nitcorn: support the special address 0.0.0.0
This PR automates assigning virtual hosts on `0.0.0.0` as the `default_virtual_host`, a fallback for all request not intercepted by other virtual hosts.
It is an imperfect temporary solution as the virtual host on 0.0.0.0:80 may receive requests from other ports, and there can be only one functional virtual host on all interfaces. A better solution would involve rewriting `ConnectionListener::bind_to` and splitting it up in many services to keep the address and socket associated to a virtual host.
Pull-Request: #2250
Reviewed-by: Jean-Philippe Caissy <jpcaissy@piji.ca>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Thu, 11 Aug 2016 00:52:56 +0000 (20:52 -0400)]
nitcc: lexer can produce a single token with `next_token`
Signed-off-by: Jean Privat <jean@pryen.org>
Alexandre Terrasa [Wed, 10 Aug 2016 19:42:21 +0000 (15:42 -0400)]
nitweb: update tests
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Tue, 9 Aug 2016 01:49:55 +0000 (21:49 -0400)]
nitweb: use config file
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Tue, 2 Aug 2016 18:08:33 +0000 (14:08 -0400)]
nitweb: factorize catalog building
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Wed, 20 Jul 2016 19:41:17 +0000 (15:41 -0400)]
nitweb: factorize APIRouter
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Tue, 2 Aug 2016 03:25:38 +0000 (23:25 -0400)]
nitweb: fix typo in help message
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexis Laferrière [Sun, 19 Jun 2016 13:08:31 +0000 (09:08 -0400)]
nitcorn: update address used and style of main doc example
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Sun, 19 Jun 2016 13:04:05 +0000 (09:04 -0400)]
nitcorn: register 0.0.0.0 addresses as default_virtual_host
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Sun, 19 Jun 2016 12:58:18 +0000 (08:58 -0400)]
nitcorn: default_virtual_host should be writable
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Wed, 10 Aug 2016 13:44:15 +0000 (09:44 -0400)]
docker: hotfix image name
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Aug 2016 23:46:26 +0000 (19:46 -0400)]
Merge: new class MErrorType to handle buggy types
This is a small cleanup of some part of the code of the model.
The main improvement is the addition of a `MErrorType` class and two somewhat related services `MType::is_ok` and `MType::is_legal_in`.
Beside a better model and better services, this changeset clean the quickfix introduced in RTA (see #2245 )
There should be no change in the overall performance.
Pull-Request: #2248
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Jean Privat [Tue, 9 Aug 2016 23:46:24 +0000 (19:46 -0400)]
Merge: docker: move the test part in another Dockerfile
We have a lot of timeout with a big Dockerfile
Pull-Request: #2249
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Tue, 9 Aug 2016 18:20:17 +0000 (14:20 -0400)]
docker: move the test part in another Dockerfile
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Aug 2016 16:43:06 +0000 (12:43 -0400)]
Merge: Text API
This PR aims to make the `Text` superclass more usable.
Some methods that were only present in `String` have been moved to `Text`, where they keep their copy semantics.
This allows any client to concatenate or multiply any `Text` object.
Also, some convenience methods have been added to `Buffer`, like `insert_at` or `remove_at`.
Note that these methods ~~can~~ **will** be slow since they modify everything in-place and cause shifting the contents of a `Buffer`.
Also, the `RopeBuffer` experimental class was removed from lib since it is not faster than a regular `FlatBuffer` and added extra burden when making changes to the `Text` block.
Pull-Request: #2223
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Aug 2016 15:19:21 +0000 (11:19 -0400)]
rta: drop local `is_valid_type` and use `is_legal_in` from `model`
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Aug 2016 15:17:53 +0000 (11:17 -0400)]
model: add `MType::is_legal_in` to check the legality of a given complex type
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Aug 2016 15:16:08 +0000 (11:16 -0400)]
model: returns more MErrorType instead of aborting
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Aug 2016 15:15:21 +0000 (11:15 -0400)]
model: add MType::is_ok to check MErrorType in depth
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Aug 2016 15:13:28 +0000 (11:13 -0400)]
model: new class MErrorType as using MBottomType was abuse
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Aug 2016 01:18:27 +0000 (21:18 -0400)]
Merge: Faster lookup
This series improves the lookup strategies:
* special fast track for the virtual type SELF
* choose to iterate on the mclassdefs instead of the mpropdefs if they are less numerous.
This mainly limit the degenerative cases that where discovered while investigating the slowdown of #2223
with nitc/nitc/nitc:
before: 0m7.168s
after: 0m6.232s
with nitpick ../contrib:
before: 0m20.928s
after: 0m19.432s
Pull-Request: #2245
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Jean Privat [Tue, 9 Aug 2016 01:17:58 +0000 (21:17 -0400)]
Merge: popcorn: enhance ConsoleLog
Add some logger capabilities to ConsoleLog so it can be shared with the rest of the popcorn app as a classic logger.
Pull-Request: #2244
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Aug 2016 01:17:55 +0000 (21:17 -0400)]
Merge: Popcorn auth
## Authentification handlers.
For now, only Github OAuth is provided.
### Github
See https://developer.github.com/v3/oauth/.
This module provide 4 base classes that can be used to implement a Github
OAuth handshake.
~~~nit
import popcorn
import popcorn::pop_auth
var client_id = "github client id"
var client_secret = "github client secret"
var app = new App
app.use("/login", new GithubLogin(client_id))
app.use("/oauth", new GithubOAuthCallBack(client_id, client_secret))
app.use("/logout", new GithubLogout)
app.listen("localhost", 3000)
~~~
Optionaly, you can use the `GithubUser` handler to provide access to the
Github user stored in session:
~~~nit
app.use("/api/user", new GithubUser)
~~~
Pull-Request: #2238
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Aug 2016 00:44:00 +0000 (20:44 -0400)]
rta: fast fix to avoid resolving illegal types.
This requires a more in-depth work to improve the model.
Another improvement can also to teach RTA the context of object mechanism
so that only legal receivers are attempted.
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 8 Aug 2016 22:24:05 +0000 (18:24 -0400)]
Merge: lib/github: introduce GithubWallet
## Github OAuth tokens management
When using batch mode with the `github` API, we can rapidly reach the rate
limit allowed by Github.
One solution consists in using a wallet of tokens so we can rely on more than
one token and switch them when one become exhausted.
### Using the Github wallet to check tokens
One functionality of the wallet is to check the validity of a token against
the API. `check_token` will return false if a token is invalid or exhausted.
~~~nit
var wallet = new GithubWallet
assert not wallet.check_token("this is a bad token")
~~~
### Storing tokens
The wallet can also be used to store tokens and check all of them.
~~~nit
wallet = new GithubWallet
wallet.add "some token"
wallet.add "some other token"
~~~
or
~~~nit
wallet = new GithubWallet.from_tokens(["token 1", "token 2"])
~~~
The `show_status` method can be used to display a summary of the validity of
each token in the wallet.
~~~nit
wallet.show_status
~~~
Will display something like this:
~~~raw
Wallet (2 tokens):
* [OK] token 1
* [KO] token 2
~~~
### Using the wallet to obtain a Github API client
Using the wallet you can cycle through tokens and obtain a new Github API client
instance with a fresh rate limit.
~~~nit
wallet = new GithubWallet.from_tokens(["token 1", "token 2"])
var api = wallet.api
~~~
The wallet will automatically cycle through the registered tokens to find one
that works.
To avoid infinite loop, if not valid token is found after all of them was tried,
the wallet returns an client based on the last tried token.
Pull-Request: #2243
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 8 Aug 2016 22:24:03 +0000 (18:24 -0400)]
Merge: gamnit: intro pinch to zoom gesture for Android
Intro a service to manipulate the perspective cameras with two fingers gestures: move the camera and the classic pinch to zoom.
This feature mainly targets the `flat` API. It should also somewhat work with `depth`, even when the camera looks around, but the fingers won't fit precisely with a world object/layer.
Pull-Request: #2242
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 8 Aug 2016 22:23:52 +0000 (18:23 -0400)]
Merge: Popcorn repos
## Repositories for data management.
Repositories are used to apply persistence on instances (or **documents**).
Using repositories one can store and retrieve instance in a clean and maintenable
way.
This module provides the base interface `Repository` that defines the persistence
services available in all kind of repos.
`JsonRepository` factorizes all repositories dedicated to Json data or objects
serializable to Json.
`MongoRepository` is provided as a concrete example of repository.
It implements all the services from `Repository` using a Mongo database as backend.
Repositories can be used in Popcorn app to manage your data persistence.
Here an example with a book management app:
~~~nit
# First we declare the `Book` class. It has to be serializable so it can be used
# within a `Repository`.
import popcorn
import popcorn::pop_repos
# Serializable book representation.
class Book
serialize
super Jsonable
# Book uniq ID
var id: String = (new MongoObjectId).id is serialize_as "_id"
# Book title
var title: String
# ... Other fields
redef fun to_s do return title
redef fun ==(o) do return o isa SELF and id == o.id
redef fun hash do return id.hash
redef fun to_json do return serialize_to_json
end
# We then need to subclass the `MongoRepository` to provide Book specific services.
# Book repository for Mongo
class BookRepo
super MongoRepository[Book]
# Find books by title
fun find_by_title(title: String): Array[Book] do
var q = new JsonObject
q["title"] = title
return find_all(q)
end
end
# The repository can be used in a Handler to manage book in a REST API.
class BookHandler
super Handler
var repo: BookRepo
# Return a json array of all books
#
# If the get parameters `title` is provided, returns a json array of books
# matching the `title`.
redef fun get(req, res) do
var title = req.string_arg("title")
if title == null then
res.json new JsonArray.from(repo.find_all)
else
res.json new JsonArray.from(repo.find_by_title(title))
end
end
# Insert a new Book
redef fun post(req, res) do
var title = req.string_arg("title")
if title == null then
res.error 400
return
end
var book = new Book(title)
repo.save book
res.json book
end
end
# Let's wrap it all together in a Popcorn app:
# Init database
var mongo = new MongoClient("mongodb://localhost:27017/")
var db = mongo.database("tests_app_{100000.rand}")
var coll = db.collection("books")
# Init app
var app = new App
var repo = new BookRepo(coll)
app.use("/books", new BookHandler(repo))
app.listen("localhost", 3000)
~~~
Pull-Request: #2241
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 8 Aug 2016 22:23:50 +0000 (18:23 -0400)]
Merge: Popcorn valid
## Quick and easy validation framework for Json inputs
Validators can be used in Popcorn apps to valid your json inputs before
data processing and persistence.
Here an example with a Book management app. We use an ObjectValidator to validate
the books passed to the API in the `POST /books` handler.
~~~nit
import popcorn
import serialization
# Serializable book representation.
class Book
super Jsonable
# Book ISBN
var isbn: String
# Book title
var title: String
# Book image (optional)
var img: nullable String
# Book price
var price: Float
end
class BookValidator
super ObjectValidator
redef init do
add new ISBNField("isbn")
add new StringField("title", min_size=1, max_size=255)
add new StringField("img", required=false)
add new FloatField("price", min=0.0, max=999.0)
end
end
class BookHandler
super Handler
# Insert a new Book
redef fun post(req, res) do
var validator = new BookValidator
if not validator.validate(req.body) then
res.json_error(validator.validation, 400)
return
end
# TODO data persistence
end
end
~~~
Pull-Request: #2240
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 8 Aug 2016 22:23:47 +0000 (18:23 -0400)]
Merge: lib/popcorn: introduce `pop_config` module
## Configuration file and options for Popcorn apps
`pop_config` provide a configuration framework for Popcorn apps based on ini
files.
By default `AppConfig` provides `app.host` and `app.port` keys, it's all we
need to start an app:
~~~nit
import popcorn
import popcorn::pop_config
# Parse app options
var opts = new AppOptions.from_args(args)
# Build config from options
var config = new AppConfig.from_options(opts)
# Use options
var app = new App
app.listen(config.app_host, config.app_port)
~~~
For more advanced uses, `AppConfig` and `AppOptions` can be specialized to
offer additional config options:
~~~nit
import popcorn
import popcorn::pop_config
class MyConfig
super AppConfig
# My secret code I don't want to share in my source repository
var secret: String = value_or_default("secret", "my-secret")
redef init from_options(options) do
super
if options isa MyOptions then
var secret = options.opt_secret.value
if secret != null then self["secret"] = secret
end
end
end
class MyOptions
super AppOptions
var opt_secret = new OptionString("My secret string", "--secret")
redef init do
super
add_option opt_secret
end
end
class SecretHandler
super Handler
# Config to use to access `secret`
var config: MyConfig
redef fun get(req, res) do
res.send config.secret
end
end
var opts = new MyOptions.from_args(args)
var config = new MyConfig.from_options(opts)
var app = new App
app.use("/secret", new SecretHandler(config))
app.listen(config.app_host, config.app_port)
~~~
Pull-Request: #2239
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 8 Aug 2016 22:23:42 +0000 (18:23 -0400)]
Merge: Serialization fixes and hardening
Improve the serialization services on multiple points:
* Fix JSON serialization of `DefaultMap` by writing its attributes. (Not only the "special" length, keys and values)
* Remove type casts and the like that would crash the program on invalid format of collections and maps, raise errors instead and return an empty instance.
* Improve (from horrible to bad) the type name used in deserialization errors when the type of an attribute is not in the AST. (This is pretty much the best we can do without moving the serialization phase after the model has been built.)
* Fix a test which failed on silent errors, and print errors so it doesn't happen again. Note that the errors with nitce are expected as it doesn't have the same `class_name` than the other engines.
* Update nitserial to silence `property-conflict` warnings in the generated module. This effectively hides the conflicts between the JSON and binary serialization because all conflicts are on generic types.
Pull-Request: #2234
Reviewed-by: Jean Privat <jean@pryen.org>