Commit 01ed23c5 authored by Marco Mariani's avatar Marco Mariani

docs: typos, small fixes

parent 22d6a875
......@@ -5,16 +5,17 @@
.. _list-of-available-storages:
List of Available Storages
==========================
JIO save his job queue in a workspace which is localStorage by default.
Provided storage descirption are also stored, and it can be dangerous if we
JIO saves his job queue in a workspace which is localStorage by default.
Provided storage descriptions are also stored, and it can be dangerous to
store passwords.
The best way to create a storage description is to use the (often) provided
tool given by the storage library. The returned description is secured to avoid
clear readable password. (enciphered password for instance)
clear readable password. (encrypted password for instance)
When building storage trees, there is no limit on the number of storages you
can use. The only thing you have to be aware of is compatability of simple and
......@@ -59,6 +60,8 @@ The tool dav_storage.createDescription generates a dav storage description for
All parameters are strings.
.. XXX simplify here
Only ``url`` and ``auth_type`` are required. If ``auth_type`` is equal to "none",
then ``realm``, ``username`` and ``password`` are useless. ``username`` and ``password`` become
required if ``auth_type`` is equal to "basic". And ``realm`` also becomes required if
......@@ -139,7 +142,7 @@ Revision Based Handlers
-----------------------
A revision based handler is a storage which is able to do some document
versionning using simple storages listed above.
versioning using simple storages listed above.
On JIO command parameter, ``_id`` is still used to identify a document, but
another id ``_rev`` must be defined to use a specific revision of this document.
......@@ -148,8 +151,8 @@ On command responses, you will find another field ``rev`` which will represent t
new revision produced by your action. All the document history is kept unless
you decide to delete older revisions.
Another fields ``conflicts``, ``revisions`` and ``revs_info`` can be returned if the
options **conflicts: true**, **revs: true** and **revs_info: true** are set.
Other fields ``conflicts``, ``revisions`` and ``revs_info`` can be returned if the
options **conflicts: true**, **revs: true** or **revs_info: true** are set.
Revision Storage
^^^^^^^^^^^^^^^^
......@@ -162,4 +165,3 @@ Replicate Revision Storage
Updating to v2.0
......@@ -11,7 +11,7 @@ allDocs method can use complex queries.
A query can either be a string (using a specific language useful for writing
queries), or it can be a tree of objects (useful to browse queries). To handle
complex queries, jIO uses a parsed grammar file which is complied using `JSCC <http://jscc.phorward-software.com/>`_.
complex queries, jIO uses a parsed grammar file which is compiled using `JSCC <http://jscc.phorward-software.com/>`_.
Why use Complex Queries?
------------------------
......@@ -20,7 +20,7 @@ Complex queries can be used similar to database queries. So they are useful to:
* search a specific document
* sort a list of documents in a certain order
* avoid retreiving a list of ten thousand documents
* avoid retrieving a list of ten thousand documents
* limit the list to show only xy documents by page
For some storages (like localStorage), complex queries can be a powerful tool
......@@ -74,6 +74,8 @@ Complex queries can be triggered by including the option named query in the allD
How to use Complex Queries outside jIO?
---------------------------------------
.. XXX 404 on complex_example.html
Complex Queries provides an API - which namespace is complex_queries. Please
also refer to the `Complex Queries sample page <http://git.erp5.org/gitweb/jio.git/blob/HEAD:/examples/complex_example.html?js=1>`_
on how to use these methods in- and outside jIO. The module provides:
......@@ -140,13 +142,13 @@ Complex Queries in storage connectors
The query exec method must only be used if the server is not able to pre-select
documents. As mentioned before, you could use an indexStorage to maintain
indices with key information on all documents in a storage. This index file
will then be used to run queries on if all fields, required in the query answer
will then be used to run queries, if all of the fields required in the query answer
are available in the index.
Matching properties
^^^^^^^^^^^^^^^^^^^
Complex Queries select items which exactly match with the value given in the
Complex Queries select items which exactly match the value given in the
query. You can use wildcards ('%' is the default wildcard character), and you
can change the wildcard character in the query options object. If you don't
want to use a wildcard, just set the wildcard character to an empty string.
......@@ -171,7 +173,7 @@ have their own default properties to keep their own behavior.
Convert Complex Queries into another type
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Example, convert Query object into human readable string:
Example, convert Query object into a human readable string:
.. code-block:: javascript
......@@ -220,7 +222,7 @@ Example, convert Query object into human readable string:
JSON Schemas and Grammar
------------------------
Below you can find schemas for constructing complex queries
Below you can find schemas for constructing queries.
* Complex Queries JSON Schema:
......@@ -330,4 +332,3 @@ Below you can find schemas for constructing complex queries
ignore: " "
......@@ -4,9 +4,9 @@ For developers
Quick start
-----------
To get started with jIO, clone one of the repositories link in :ref:`Download & Fork <download-fork>` tab.
To get started with jIO, clone one of the repositories linked in :ref:`Download & Fork <download-fork>`.
To build your library you have to:
To build the library you have to:
* Install `NodeJS <http://nodejs.org/>`_ (including NPM)
* Install Grunt command line with npm.
......@@ -19,9 +19,9 @@ To build your library you have to:
* Compile JS/CC parser.
``$ make`` (until we found how to compile it with grunt)
``$ make`` (until we find how to compile it with grunt)
* And run build.
* Run build.
``$ grunt``
......@@ -32,7 +32,7 @@ plus the storages and dependencies you need and you will be good to go.
Naming Conventions
------------------
All the code follows this :ref:`Javascript Naming Conventions <naming-conventions>`.
All the code follows these :ref:`JavaScript Naming Conventions <naming-conventions>`.
How to design your own jIO Storage Library
------------------------------------------
......@@ -74,7 +74,7 @@ Create 10 methods: ``post``, ``put``, ``putAttachment``, ``get``, ``getAttachmen
(To help you to design your methods, some tools are provided by jIO.util.)
(To help you design your methods, some tools are provided by jIO.util.)
The first parameter command provides some methods to act on the JIO job:
......@@ -90,14 +90,14 @@ The first parameter command provides some methods to act on the JIO job:
* ``retry``, to tell JIO that the job cannot be done now, but can be retried later. (same API than error)
* ``reject``, to tell JIO that the job cannot be done, let JIO to decide to retry or not. (same API than error)
* ``reject``, to tell JIO that the job cannot be done, let JIO to decide whether to retry or not. (same API than error)
The second parameter ``metadata`` or ``param`` is the first parameter given by the JIO user.
The second parameter ``metadata`` or ``param`` is the first parameter provided by the JIO user.
The third parameter ``option`` is the option parameter given by the JIO user.
The third parameter ``option`` is the option parameter provided by the JIO user.
Detail of what should return a method:
Methods should return the following objects:
* post --> success("created", {"id": new_generated_id})
......@@ -123,7 +123,7 @@ Detail of what should return a method:
// or
error("conflict", "corrupted", "incoherent document or storage")
repair -->
* repair -->
.. code-block:: javascript
......@@ -134,9 +134,9 @@ Detail of what should return a method:
error("conflict", "corrupted", "impossible to repair document or storage")
// DON'T DESIGN STORAGES IF THEIR IS NO WAY TO REPAIR INCOHERENT STATES
After setting up all methods, your storage must be added to jIO. This is done
using the ``jIO.addStorage()`` method, which requires two parameters: the storage
type (string) add a constructor (function). It is called like this:
After creating all methods, your storage must be added to jIO. This is done
with the ``jIO.addStorage()`` method, which requires two parameters: the storage
type (string) and a constructor (function). It is called like this:
.. code-block:: javascript
......@@ -145,18 +145,19 @@ type (string) add a constructor (function). It is called like this:
Please refer to *localstorage.js* implementation for a good example on how to
setup a storage and what methods are required. Also keep in mind, that jIO is a
job-based library, so whenever you trigger a method, a job is created, which
after being processed returns a response.
setup a storage and what methods are required.
Also keep in mind that jIO is a job-based library: whenever you trigger a method,
a job is created, which will later return a response, after being processed.
Job rules
---------
jIO job manager will follow several rules set at the creation of a new jIO
The jIO job manager follows several rules set at the creation of a new jIO
instance. When you try to call a method, jIO will create a job and will make
sure the job is really necessary and will be executed. Thanks to these job
rules, jIO knows what to do with the new job before adding it to the queue. You
can add your own rules like this:
can also add your own rules, as we're going to see now.
These are the jIO **default rules**:
......@@ -212,14 +213,14 @@ The following condition function can be used:
* ``useMetadataOnly`` - check if the commands are ``post``, ``put``, ``get``, ``remove`` or ``allDocs``.
* ``sameMethod`` - check if the commands are equal.
* ``sameDocumentId`` - check if the document ids are equal.
* ``sameParameters`` - check if the metadata or param are equal in deep.
* ``sameParameters`` - check if the metadata or param are equal (deep comparison).
* ``sameOptions`` - check if the command options are equal.
* ``haveDocumentIds`` - test if the two commands contain document ids
* ``haveDocumentIds`` - test if the two commands contain document ids.
Create Job Condition
--------------------
You can create 2 types of function: job condition, and job comparison.
You can create two types of function: job condition, and job comparison.
.. code-block:: javascript
......@@ -267,7 +268,7 @@ You just have to define job rules in the jIO options:
Clear/Replace default job rules
-------------------------------
If a job which code_name is equal to readers update, then add this rule will replace it:
If a job's ``code_name`` is equal to ``readers update``, then adding this rule will replace it:
.. code-block:: javascript
......@@ -286,7 +287,7 @@ If a job which code_name is equal to readers update, then add this rule will rep
}]
});
Or you can just clear all rules before adding other ones:
Or you can just clear all rules before adding new ones:
.. code-block:: javascript
......
......@@ -43,6 +43,8 @@ Revision based storage handlers:
Minified version
----------------
.. XXX this sounds harsh. Can we provide it or at least be more explicit?
To get the minified version of the jIO library, you have to build it yourself. See documentation.
Fork
......
......@@ -9,19 +9,19 @@ A storage to enable interoperability between all kind of storages.
A global ID (GID) is a document id which represents a unique document. This ID
will be used to find this unique document on all kind of backends.
This storage used sub storage allDocs and complex queries to find unique documents, and convert their ids to gids.
This storage uses sub storage allDocs and complex queries to find unique documents, and converts their ids to gids.
Cases where it can be used
--------------------------
Where it can be used
--------------------
When you want to duplicate/synchronize/split/edit data in different kind of storages (ERP5 + XWiki + Dav + ...).
When you want to duplicate / synchronize / split / edit data in different kind of storages (ERP5 + XWiki + Dav + ...).
Storage Description
-------------------
* ``type`` - ``"gid"``
* ``sub_storage`` - the sub storage description.
* ``constraints`` - the constraints to use to generate a gid by define metadata types for some kind of document.
* ``constraints`` - the constraints to use to generate a gid by defining metadata types for some kind of document.
Example:
......@@ -155,5 +155,3 @@ Offline Application Usage::
**CAUTION: All gid storage must have the same description!**
......@@ -17,13 +17,15 @@ retrieve documents and specific information across storage trees.
How does it work?
-----------------
.. XXX three parts?
JIO is separated into three parts - jIO core and storage library(ies). The core
is using storage libraries (connectors) to interact with the accociated remote
is using storage libraries (connectors) to interact with the associated remote
storage servers. Some queries can be used on top of the jIO allDocs method to
query documents based on defined criteria.
JIO uses a job management system, so every method called adds a job into a
queue. The queue is copied in the browsers local storage (by default), so it
queue. The queue is copied in the browser's local storage (by default), so it
can be restored in case of a browser crash. Jobs are being invoked
asynchronously with ongoing jobs not being able to re-trigger to prevent
conflicts.
......@@ -87,6 +89,8 @@ This walkthrough is designed to get you started using a basic jIO instance.
// create your jio instance
var my_jio = jIO.createJIO(storage_description);
.. XXX 6 methods or 10?
#. The jIO API provides six main methods to manage documents across the storage(s) specified in your jIO storage tree.
================== ===================================================== ========================================
......
How to manage documents?
========================
JIO is mapped after the CouchDB API and extends it to provide unified, scalable
JIO is mapped after the CouchDB API and extends them to provide unified, scalable
and high performance access via Javascript to a wide variety of different
storage backends.
If you are unfamiliar with Apache `CouchDB <http://couchdb.apache.org/>`_:
If you are unfamiliar with `Apache CouchDB <http://couchdb.apache.org/>`_:
it is a scalable, fault-tolerant, and schema-free document-oriented database.
It's used in large and small organizations for a variety of applications where
traditional SQL databases aren't the best solution for the problem at hand.
CouchDB provides a RESTful HTTP/JSON API accessible from many programming
libraries and tools (like 'curl' or 'Pouchdb') and has it's own conflict management system.
It is used in large and small organizations for a variety of applications where
traditional SQL databases are not the best solution for the problem at hand.
CouchDB provides a RESTful HTTP/JSON API accessible by many programming
libraries and tools (like `curl <http://curl.haxx.se/>`_ or `Pouchdb <http://pouchdb.com/>`_)
and has its own conflict management system.
What is a document?
-------------------
A document an association with metadata and attachment(s). The metadata are the
properties of the document and the attachments are the binaries of the content
A document is an association of metadata and attachment(s). The metadata is the
set of properties of the document and the attachments are the binaries of the content
of the document.
In jIO, metadata are just a dictionnary with keys and values (JSON object), and
In jIO, metadata is just a dictionnary with keys and values (JSON object), and
attachments are just simple strings.
.. code-block:: javascript
......@@ -60,7 +61,7 @@ Basic Methods
Below you can find sample calls of the main jIO methods. All examples are using
revisions (as in revision storage or replicate revision storage), so you can
see, how method calls should be made with either of these storages.
see how method calls should be made with either of these storages.
.. code-block:: javascript
:linenos:
......@@ -71,20 +72,20 @@ see, how method calls should be made with either of these storages.
// create and store new document
jio_instance.post({"title": "some title"}).
then(function (response) {
// console.log(response):
// console.log(response);
});
// create or update an existing document
jio_instance.put({"_id": "my_document", "title": "New Title"}).
then(function (response) {
// console.log(response):
// console.log(response);
});
// add an attachement to a document
// add an attachment to a document
jio_instance.putAttachment({"_id": "my_document", "_attachment": "its_attachment",
"_data": "abc", "_mimetype": "text/plain"}).
then(function (response) {
// console.log(response):
// console.log(response);
});
// read a document
......@@ -93,7 +94,7 @@ see, how method calls should be made with either of these storages.
// console.log(response);
});
// read an attachement
// read an attachment
jio_instance.getAttachment({"_id": "my_document", "_attachment": "its_attachment"}).
then(function (response) {
// console.log(response);
......@@ -105,7 +106,7 @@ see, how method calls should be made with either of these storages.
// console.log(response):
});
// delete an attachement
// delete an attachment
jio_instance.removeAttachment({"_id": "my_document", "_attachment": "its_attachment"}).
then(function (response) {
// console.log(response):
......@@ -120,7 +121,7 @@ see, how method calls should be made with either of these storages.
Promises
--------
Each JIO methods return a Promise object, which allows us to get responses into
Each JIO methods returns a Promise object, which allows us to get responses into
callback parameters and to chain callbacks with other returned values.
JIO uses a custom version of `RSVP.js <https://github.com/tildeio/rsvp.js>`_, adding canceler and progression features.
......@@ -132,13 +133,10 @@ You can read more about promises:
* `CommonJS Promises <http://wiki.commonjs.org/wiki/Promises>`_
Method Options and Callback Responses
-------------------------------------
To retrieve JIO responses, you have to give callbacks like this:
To retrieve JIO responses, you have to provide callbacks like this:
.. code-block:: javascript
......@@ -337,6 +335,3 @@ localStorage contents:
"jio/local/usr/app/myVideo/video": "..."
}
......@@ -60,7 +60,7 @@ List of metadata to use
Identification
^^^^^^^^^^^^^^
* **"_id"**, a specific JIO metadata which helps the storage to find a documents
* **"_id"**, a specific JIO metadata which helps the storage to find a document
(can be a real path name, a dc:identifier, a uuid, ...). **String Only**
* **"identifer"**, :js:`{"identifier": "http://domain/jio_home_page"}, {"identifier": "urn:ISBN:978-1-2345-6789-X"},
......@@ -101,7 +101,7 @@ Intellectual property
* **"creator"**, :js:`{"creator": "Tristan Cavelier"}, {"creator": ["Tristan Cavelier", "Sven Franck"]}`
an entity primarily responsible for making the content of the resource.
an entity primarily responsible for creating the content of the resource.
Examples of a Creator include a person, an organization, or a service.
Typically the name of the Creator should be used to indicate the entity.
......@@ -150,7 +150,7 @@ Content
* **"language"**, :js:`{"language": "en"}`
a language of the intellectual content of the resource. Recommended best
the language of the intellectual content of the resource. Recommended best
practice for the values of the Language element is defined by `RFC 3066 <http://www.ietf.org/rfc/rfc3066.txt>`_
which, in conjunction with `ISO 639 <http://www.oasis-open.org/cover/iso639a.html>`_, defines two- and
three-letter primary language tags with optional subtags. Examples include "en"
......@@ -193,6 +193,8 @@ Content
* **custom**, :js:`{custom1: value1, custom2: value2, ...}`
.. XXX short description here
Examples
--------
......@@ -427,8 +429,3 @@ Sources
* https://en.wikipedia.org/wiki/Internet_media_type
* https://www.iana.org/assignments/media-types
......@@ -12,16 +12,18 @@ This document defines JavaScript naming conventions, which are split into essent
Essential Conventions
---------------------
Essential conventions include generic patterns that should be adhered in order to write *readable*, *consistent* and *maintainable* code.
Essential conventions include generic patterns that should be adhered to in order to write *readable*, *consistent* and *maintainable* code.
Minimizing Globals
^^^^^^^^^^^^^^^^^^
Variable declarations should always be made using *var* to not declare them as
Variable declarations should always be done using *var* to not declare them as
global variables. This avoids conflicts from using a variable name across
different functions as well as conflicts with global variables declared by 3rd
different functions as well as conflicts with global variables declared by third
party plugins.
.. XXX always pub good+bad or bad+good examples in the same order
Good Example
.. code-block:: javascript
......@@ -52,37 +54,37 @@ writing code.
Before validating your code in JSLint, you should use a code
beautifier to fix basic syntax errors (like indentation) automatically. There
are a number of beautifiers available online. The following seem to be the best
working:
are a number of beautifiers available online. The following ones seem to work best:
* `JSbeautifier.org <http://jsbeautifier.org/>`_
* `JS-Beautify <http://alexis.m2osw.com/js-beautify/>`_
Here, javascript sources have to begin with this header: :js:`/*jslint indent: 2,
In this project, JavaScript sources have to begin with the header: :js:`/*jslint indent: 2,
maxlen: 80, nomen: true */`, which means it uses two spaces indentation, 80
maximum characters by line and allow the use of '_' as first variable name
character. Other JSLint options can be added in sub functions if necessary;
Allowed options are:
maximum characters per line and the use of '_' as first character in a variable name is allowed.
Other JSLint options can be added in sub functions if necessary.
Some allowed options are:
* ``ass: true`` if assignment should be allowed outside of statement position.
* ``bitwise: true`` if bitwise operators should be allowed.
* ``continue: true`` if the continue statement should be allowed.
* ``newcap: true`` if Initial Caps with constructor function is optional.
* ``regexp: true`` if ``.`` and ``[^...]`` should be allowed in RegExp literals. They match more material than might be expected, allowing attackers to confuse applications. These forms should not be used when validating in secure applications.
* ``unparam: true`` if warnings should not be given for unused parameters.
* ``unparam: true`` if warnings should be silenced for unused parameters.
Coding Conventions
------------------
Coding conventions include generic patterns that ensure that written code adheres to certain formatting conventions.
Coding conventions include generic patterns that ensure that written code follows certain formatting conventions.
Uses two-space indentation
^^^^^^^^^^^^^^^^^^^^^^^^^^
Tabs and 2-space indentation are being used equally. Since a lot of errors on
JSLint often result from mixed use of space and tab using 2 spaces throughout
JSLint often result from mixed use of space and tab, using 2 spaces throughout
prevents these errors up front.
......@@ -189,7 +191,7 @@ Good Example
Closing Brace Location
^^^^^^^^^^^^^^^^^^^^^^
The closing brace should be on the same indent as the original function call.
The closing brace should be on the same indent level as the original function call.
Bad Example
......@@ -249,7 +251,7 @@ Naming conventions include generic patterns for setting names and identifiers th
Constructors
^^^^^^^^^^^^
A constructor function starting with new should always start with a capital letter
Constructor functions (called with the ``new`` statement) should always start with a capital letter:
.. code-block:: javascript
......@@ -299,7 +301,7 @@ Follow the camel case convention, typing the words in lower-case, only capitaliz
Variables
^^^^^^^^^
Variables with multiple words should always use an underscore between words.
Variable names with multiple words should always use an underscore between them.
.. code-block:: javascript
......@@ -325,7 +327,9 @@ Example
var value_list = getObjectOrArray();
// value_list can be an object which can be cast into an array
To use camelCase, when sometimes it is impossible to declare a function directly, the function variable name should match some patterns which shows that it is a function.
To use camelCase, when sometimes it is not possible to declare a function
directly, the function variable name should match some pattern which shows
that it is a function.
.. code-block:: javascript
......@@ -402,7 +406,7 @@ Bad Example
No Abbreviations
^^^^^^^^^^^^^^^^
Abbreviations should not be used to avoid confusion
Abbreviations should not be used to avoid confusion.
Good Example
......@@ -422,7 +426,7 @@ Bad Example
No Plurals
^^^^^^^^^^
Plurals should not be used when assigning names
Plurals should not be used as variable names.
.. code-block:: javascript
......@@ -436,7 +440,8 @@ Plurals should not be used when assigning names
Use Comments
^^^^^^^^^^^^
Should be used with reason but include enough information so that a reader can get a first grasp of what a part of code is supposed to do.
Comments should be used within reason but include enough information so that a
reader can get a first grasp of what a part of code is supposed to do.
Good Example
......@@ -463,9 +468,9 @@ Bad Example
Documentation
^^^^^^^^^^^^^
You can use `YUIDoc <http://yuilibrary.com/projects/yuidoc>`_ and their custom comment
You can use `YUIDoc <http://yuilibrary.com/projects/yuidoc>`_ and its custom comment
tags together with Node.js to generate the documentation from the script file
itself. Comments will look something like this:
itself. Comments should look like this:
Good Example
......@@ -495,12 +500,10 @@ Bad Example
Additional Readings
-------------------
Resources, additional reading materials and links used
Resources, additional reading materials and links:
* `Javascript Patterns <http://shop.oreilly.com/product/9780596806767.do>`_, main ressource used.
* `JSLint <http://www.jslint.com/>`_, code quality.
* `YUIDoc <http://yuilibrary.com/projects/yuidoc>`_, generate documentation from code.
......@@ -124,7 +124,9 @@ update is executed.
// response.data.email -> "me_again@web.com"
});
When multiple versions of a document are available, jIO returns the lastest, left-most version on the document tree (2-375... and labels all other versions as conflicting 2-068...).
When multiple versions of a document are available, jIO returns the latest,
left-most version on the document tree (2-375... and labels all other
versions as conflicting 2-068...).
#. Retrieve conflicts by setting option
......@@ -156,6 +158,6 @@ update is executed.
When deleting the conflicting version of your namecard, jIO removes this
version from all storages and sets the document tree leaf of this version to
deleted. All storages now contain just a single version of your namecard
(2-3753...). Note, that the on the document tree, removing a revison will
(2-3753...). Note that, on the document tree, removing a revison will
create a new revision with status set to *deleted*.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment