Commit 6465fb74 authored by Guillaume Royer's avatar Guillaume Royer

chore: create bundle for node, browsers and commonjs

parent 4855eabd
{
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"env": {
"browser": true,
"node": true
},
"extends": "eslint:recommended",
"rules": {
"no-empty": ["error", {
"allowEmptyCatch": true
}],
"max-len": ["error", 80],
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}],
"one-var": ["error", {
"var": "always",
"const": "never",
"let": "never"
}]
}
}
...@@ -6,3 +6,4 @@ ...@@ -6,3 +6,4 @@
.directory .directory
node_modules/* node_modules/*
package-lock.json
dist/jio-*.js
lib/
.eslintrc.json
.htaccess
COPYING
Gruntfile.js
Makefile
rollup.config.js
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
module.exports = function (grunt) { module.exports = function (grunt) {
"use strict"; "use strict";
...@@ -41,6 +42,7 @@ module.exports = function (grunt) { ...@@ -41,6 +42,7 @@ module.exports = function (grunt) {
]; ];
}; };
grunt.loadNpmTasks('gruntify-eslint');
grunt.loadNpmTasks('grunt-jslint'); grunt.loadNpmTasks('grunt-jslint');
grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-uglify');
...@@ -59,10 +61,7 @@ module.exports = function (grunt) { ...@@ -59,10 +61,7 @@ module.exports = function (grunt) {
directives: { directives: {
maxlen: 100, maxlen: 100,
indent: 2, indent: 2,
maxerr: 3, maxerr: 3
predef: [
'module'
]
} }
}, },
grunt: { grunt: {
...@@ -78,66 +77,18 @@ module.exports = function (grunt) { ...@@ -78,66 +77,18 @@ module.exports = function (grunt) {
] ]
} }
}, },
jio: {
src: ['src/jio.js'],
directives: {
maxlen: 80,
indent: 2,
maxerr: 3,
nomen: true
}
},
jio_storages: {
src: ['src/jio.storage/*.js'],
directives: {
maxlen: 80,
indent: 2,
maxerr: 3,
predef: [
'define',
'exports',
'require',
'window',
'jIO',
'complex_queries'
]
}
},
jiodate: {
src: ['src/jio.date/jiodate.js'],
directives: {
maxlen: 80,
indent: 2,
maxerr: 3,
predef: [
'jIO'
]
},
},
tests: { tests: {
src: ['test/**/*.js'], src: ['test/**/*.js'],
directives: {
maxlen: 80,
indent: 2,
maxerr: 3,
predef: [
'RSVP',
'QUnit',
'jIO'
]
},
},
queries: {
src: ['src/queries/*.js'],
exclude: [ exclude: [
'src/queries/parser-begin.js', 'test/node/**/*.js'
'src/queries/parser-end.js'
], ],
directives: { directives: {
maxlen: 80, maxlen: 80,
indent: 2, indent: 2,
maxerr: 3, maxerr: 3,
predef: [ predef: [
'RSVP',
'QUnit',
'jIO' 'jIO'
] ]
} }
...@@ -155,12 +106,68 @@ module.exports = function (grunt) { ...@@ -155,12 +106,68 @@ module.exports = function (grunt) {
'QUnit', 'QUnit',
'jIO' 'jIO'
] ]
}
}
},
eslint: {
options: {
maxWarnings: 3
},
jio: {
src: [
'src/jio.bundle.js',
'src/jio.js',
'src/storage.js',
'src/utils-compat.js',
'src/utils.js'
]
},
jio_storages: {
src: ['src/jio.storage/*.js']
}, },
jiodate: {
src: ['src/jio.date/jiodate.js']
},
queries: {
src: ['src/queries/query.js']
}, },
nodeTests: {
src: ['test/node/**/*.js']
}
}, },
concat: { concat: {
options: { options: {
separator: ';' separator: ';',
process: function (src, filepath) {
// skip process libs
if (
filepath.indexOf('node_modules/') === 0 ||
filepath.indexOf('lib/') === 0
) {
return src;
}
var importRegex = new RegExp(
"import" +
"(?:[\"'\\s]*([\\w*{}\\n\\r\\t, ]+)from\\s*)?" +
"[\"'\\s].*([@\\w/_-]+)[\"'\\s].*;" +
"(\\r\\n\\t|\\n|\\r\\t)?$",
'gm'
),
exportRegex = new RegExp(
"export" +
"(?:[\"'\\s]*([\\w*{}\\n\\r\\t, ]+))?" +
"[\"'\\s].*([@\\w/_-]+)[\"'\\s].*;" +
"(\\r\\n\\t|\\n|\\r\\t)?$",
'gm'
);
return src
// remove import statements
.replace(importRegex, '')
// remove export statements
.replace(exportRegex, '');
}
}, },
jio: { jio: {
// duplicate files are ignored // duplicate files are ignored
...@@ -178,7 +185,11 @@ module.exports = function (grunt) { ...@@ -178,7 +185,11 @@ module.exports = function (grunt) {
'src/jio.date/*.js', 'src/jio.date/*.js',
'src/jio-begin.js',
'src/jio.js', 'src/jio.js',
'src/storage.js',
'src/utils.js',
'src/jio-end.js',
'node_modules/rusha/rusha.js', 'node_modules/rusha/rusha.js',
...@@ -258,11 +269,11 @@ module.exports = function (grunt) { ...@@ -258,11 +269,11 @@ module.exports = function (grunt) {
files: [ files: [
'<%= jslint.npm.src %>', '<%= jslint.npm.src %>',
'<%= jslint.grunt.src %>', '<%= jslint.grunt.src %>',
'<%= jslint.jio.src %>',
'<%= jslint.jiodate.src %>',
'<%= jslint.jio_storages.src %>',
'<%= jslint.tests.src %>', '<%= jslint.tests.src %>',
'<%= jslint.queries.src %>', '<%= eslint.jio.src %>',
'<%= eslint.jiodate.src %>',
'<%= eslint.jio_storages.src %>',
'<%= eslint.queries.src %>',
'<%= concat.jio.src %>', '<%= concat.jio.src %>',
'<%= qunit.files %>', '<%= qunit.files %>',
'test/**/*.js', 'test/**/*.js',
...@@ -300,7 +311,7 @@ module.exports = function (grunt) { ...@@ -300,7 +311,7 @@ module.exports = function (grunt) {
grunt.registerTask('default', ['all']); grunt.registerTask('default', ['all']);
grunt.registerTask('all', ['lint', 'build']); grunt.registerTask('all', ['lint', 'build']);
grunt.registerTask('lint', ['jslint']); grunt.registerTask('lint', ['jslint', 'eslint']);
grunt.registerTask('test', ['qunit']); grunt.registerTask('test', ['qunit']);
grunt.registerTask('server', ['connect:client', 'watch']); grunt.registerTask('server', ['connect:client', 'watch']);
grunt.registerTask('build', ['concat', 'copy']); grunt.registerTask('build', ['concat', 'copy']);
......
...@@ -2,19 +2,40 @@ ...@@ -2,19 +2,40 @@
jIO is a promised-based JavaScript library that offers connectors to many storages (Dropbox, webdav, IndexedDB, GDrive, ...) using a single API. jIO supports offline use, replication, encryption and synchronization as well as querying of stored documents and attachments allowing to build complex client-side centric web applications. jIO is a promised-based JavaScript library that offers connectors to many storages (Dropbox, webdav, IndexedDB, GDrive, ...) using a single API. jIO supports offline use, replication, encryption and synchronization as well as querying of stored documents and attachments allowing to build complex client-side centric web applications.
### jIO Documentation ## jIO Documentation
The documentation can be found on [https://jio.nexedi.com/](https://jio.nexedi.com/) The documentation can be found on [https://jio.nexedi.com/](https://jio.nexedi.com/)
### jIO Quickstart ## jIO Quickstart
git clone https://lab.nexedi.com/nexedi/jio.git git clone https://lab.nexedi.com/nexedi/jio.git
npm install npm install
grunt server grunt server
### jIO Code ## jIO Code
RenderJS source code is hosted on Gitlab at [https://lab.nexedi.com/nexedi/jio](https://lab.nexedi.com/nexedi/jio) (Github [mirror](https://github.com/nexedi/jio/) - please use the issue tracker on Gitlab) RenderJS source code is hosted on Gitlab at [https://lab.nexedi.com/nexedi/jio](https://lab.nexedi.com/nexedi/jio) (Github [mirror](https://github.com/nexedi/jio/) - please use the issue tracker on Gitlab)
### jIO Test ## jIO Test
You can run tests after installing and building jIO by opening the */test/* folder You can run tests after installing and building jIO by opening the */test/* folder
## Build with rollup
```
$ npm install -g rollup
$ rollup -c
```
## jIO for Node.js
1. Install the package
```sh
$ npm install --save https://lab.nexedi.com/nexedi/jio.git
```
2. Import the library and create your first storage:
```javascript
const { jIO } = require('jio/dist/node/jio.js');
const jio = jIO.createJIO({
type: 'memory'
});
```
/*eslint no-console: "off"*/
const { jIO } = require('../dist/node/jio');
const tests = async () => {
try {
const memory = jIO.createJIO({
type: 'memory'
});
console.log(memory.__type === 'memory');
const id = await memory.put('1', {
foo: 'bar'
});
console.log(id === '1');
let results = await memory.allDocs();
console.log(results.data.total_rows === 1);
process.exit(0);
}
catch (err) {
console.error('error', err);
process.exit(1);
}
};
tests();
...@@ -8,12 +8,14 @@ ...@@ -8,12 +8,14 @@
"Sven Franck <sven.franck@nexedi.com>" "Sven Franck <sven.franck@nexedi.com>"
], ],
"description": "Client-side JavaScript library to manage documents across multiple storages", "description": "Client-side JavaScript library to manage documents across multiple storages",
"main": "jio.js", "main": "dist/node/jio.js",
"module": "dist/jio.module.js",
"directories": { "directories": {
"example": "examples", "example": "examples",
"test": "test" "test": "test"
}, },
"scripts": { "scripts": {
"start": "./node_modules/.bin/grunt server",
"test": "./node_modules/.bin/grunt test", "test": "./node_modules/.bin/grunt test",
"lint": "./node_modules/.bin/grunt lint", "lint": "./node_modules/.bin/grunt lint",
"prepublish": "./node_modules/.bin/grunt build" "prepublish": "./node_modules/.bin/grunt build"
...@@ -29,28 +31,39 @@ ...@@ -29,28 +31,39 @@
"cloud" "cloud"
], ],
"dependencies": { "dependencies": {
"form-data": "^2.3.2",
"jquery": "^3.3.1",
"moment": "2.21.0",
"rsvp": "git+https://lab.nexedi.com/nexedi/rsvp.js.git", "rsvp": "git+https://lab.nexedi.com/nexedi/rsvp.js.git",
"rusha": "0.8.2",
"sjcl": "^1.0.7",
"urijs": "^1.19.1",
"uritemplate": "git+https://lab.nexedi.com/nexedi/uritemplate-js.git", "uritemplate": "git+https://lab.nexedi.com/nexedi/uritemplate-js.git",
"moment": "2.21.0", "xhr2": "^0.1.4"
"rusha": "0.8.2"
}, },
"devDependencies": { "devDependencies": {
"renderjs": "git+https://lab.nexedi.com/nexedi/renderjs.git", "connect-livereload": "~0.3.0",
"grunt": "0.4.x", "grunt": "0.4.x",
"grunt-cli": "~0.1.11", "grunt-cli": "~0.1.11",
"grunt-contrib-concat": "0.3.x", "grunt-contrib-concat": "0.3.x",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-copy": "~0.4.1", "grunt-contrib-copy": "~0.4.1",
"grunt-contrib-qunit": "~0.3.0", "grunt-contrib-qunit": "~0.3.0",
"qunitjs": "~1.23.1", "grunt-contrib-uglify": "0.2.x",
"qunit-tap": "1.5.0",
"grunt-contrib-watch": "~0.5.3", "grunt-contrib-watch": "~0.5.3",
"grunt-jslint": "~1.0.0", "grunt-jslint": "~1.0.0",
"lz-string": "^1.4.4",
"sinon": "~1.7.3",
"jison": "~0.4.16",
"connect-livereload": "~0.3.0",
"grunt-open": "~0.2.2", "grunt-open": "~0.2.2",
"grunt-contrib-connect": "~0.5.0" "gruntify-eslint": "^5.0.0",
"jison": "~0.4.16",
"lz-string": "^1.4.4",
"qunit-tap": "1.5.0",
"qunitjs": "~1.23.1",
"renderjs": "git+https://lab.nexedi.com/nexedi/renderjs.git",
"rollup-plugin-commonjs": "^9.1.5",
"rollup-plugin-hypothetical": "^2.1.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-resolve": "^3.3.0",
"sinon": "~1.7.3"
}, },
"engines": { "engines": {
"npm": ">=1.3" "npm": ">=1.3"
......
import resolve from 'rollup-plugin-node-resolve';
import commonJS from 'rollup-plugin-commonjs';
import builtins from 'rollup-plugin-node-builtins';
import hypothetical from 'rollup-plugin-hypothetical';
export default [{
input: 'src/node/jio.js',
output: {
file: 'dist/node/jio.js',
format: 'cjs'
},
plugins: [
builtins()
]
}, {
external: [
'rsvp',
'xhr2',
'form-data',
'jquery',
'sjcl'
],
input: 'src/jio.bundle.js',
output: [{
file: 'dist/jio.bundle.js',
format: 'iife',
name: 'jIOBundle',
footer: `
for (var i in jIOBundle) {
if (jIOBundle.hasOwnProperty(i)) {
window[i] = jIOBundle[i];
}
}
`,
outro: `
exports.moment = moment;
exports.LZString = lzString;
`,
globals: {
rsvp: 'RSVP',
rusha: 'Rusha',
'form-data': 'FormData',
jquery: 'jQuery',
xhr2: 'XMLHttpRequest',
sjcl: 'sjcl',
http: 'http',
https: 'https',
os: 'os',
url: 'url'
}
}],
plugins: [
hypothetical({
allowFallthrough: true,
files: {
process: `
export default window;
`
}
}),
resolve(),
commonJS({
include: 'node_modules/**'
})
]
}, {
external: [
'rsvp',
'jquery',
'sjcl',
'rusha',
'lz-string',
'uritemplate',
'urijs',
'moment'
],
input: 'src/jio.bundle.js',
output: [{
file: 'dist/jio.module.js',
format: 'cjs'
}],
plugins: [
// skip require libs already included in window
// do not include them in `external: []`
hypothetical({
allowFallthrough: true,
files: {
'form-data': `
export default window.FormData;
`,
xhr2: `
export default window.XMLHttpRequest;
`,
process: `
export default window;
`
}
}),
resolve(),
commonJS({
include: 'node_modules/**'
})
]
}];
/*
* Copyright 2018, Nexedi SA
*
* This program is free software: you can Use, Study, Modify and Redistribute
* it under the terms of the GNU General Public License version 3, or (at your
* option) any later version, as published by the Free Software Foundation.
*
* You can also Link and Combine this program with other software covered by
* the terms of any of the Free Software licenses or any of the Open Source
* Initiative approved licenses and Convey the resulting work. Corresponding
* source of such a combination shall include the source code for all other
* software used.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
(function(RSVP) {
"use strict";
var jiodates = window,
queries = window;
/*
* Copyright 2018, Nexedi SA
*
* This program is free software: you can Use, Study, Modify and Redistribute
* it under the terms of the GNU General Public License version 3, or (at your
* option) any later version, as published by the Free Software Foundation.
*
* You can also Link and Combine this program with other software covered by
* the terms of any of the Free Software licenses or any of the Open Source
* Initiative approved licenses and Convey the resulting work. Corresponding
* source of such a combination shall include the source code for all other
* software used.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
window.jIO = jIO;
}(RSVP));
import { jIO, jiodate } from './jio';
import './storage';
import './jio.storage/cloudooostorage';
import './jio.storage/cryptstorage';
import './jio.storage/davstorage';
import './jio.storage/documentstorage';
import './jio.storage/drivetojiomapping';
import './jio.storage/dropboxstorage';
import './jio.storage/erp5storage';
import './jio.storage/fbstorage';
import './jio.storage/gdrivestorage';
// import './jio.storage/gidstorage';
import './jio.storage/httpstorage';
import './jio.storage/indexeddbstorage';
// import './jio.storage/indexstorage';
import './jio.storage/localstorage';
import './jio.storage/memorystorage';
// import './jio.storage/multisplitstorage';
import './jio.storage/parserstorage';
// import './jio.storage/qiniustorage';
import './jio.storage/querystorage';
// import './jio.storage/replicaterevisionstorage';
import './jio.storage/replicatestorage';
// import './jio.storage/revisionstorage';
// import './jio.storage/s3storage';
// import './jio.storage/searchableencryptionstorage';
import './jio.storage/shastorage';
// import './jio.storage/splitstorage';
import './jio.storage/unionstorage';
import './jio.storage/uuidstorage';
import './jio.storage/websqlstorage';
// import './jio.storage/xwikistorage';
import './jio.storage/zipstorage';
export {
jIO,
jiodate
};
...@@ -17,9 +17,18 @@ ...@@ -17,9 +17,18 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*global window, moment */
/*jslint nomen: true, maxlen: 200*/ /*eslint max-len: ["error", 200], no-useless-escape: "off"*/
(function (window, moment) { /*global window */
import moment from 'moment';
var moduleExports = {};
try {
moduleExports = window;
} catch (err) {}
(function (moduleExports, moment) {
"use strict"; "use strict";
// /** // /**
...@@ -183,17 +192,7 @@ ...@@ -183,17 +192,7 @@
}; };
// _export('JIODate', JIODate); moduleExports.jiodate = {
//
// _export('YEAR', YEAR);
// _export('MONTH', MONTH);
// _export('DAY', DAY);
// _export('HOUR', HOUR);
// _export('MIN', MIN);
// _export('SEC', SEC);
// _export('MSEC', MSEC);
window.jiodate = {
JIODate: JIODate, JIODate: JIODate,
YEAR: YEAR, YEAR: YEAR,
MONTH: MONTH, MONTH: MONTH,
...@@ -203,4 +202,6 @@ ...@@ -203,4 +202,6 @@
SEC: SEC, SEC: SEC,
MSEC: MSEC MSEC: MSEC
}; };
}(window, moment)); }(moduleExports, moment));
export default moduleExports;
This diff is collapsed.
...@@ -18,8 +18,11 @@ ...@@ -18,8 +18,11 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/ /*global DOMParser, XMLSerializer*/
/*global jIO, RSVP, DOMParser, XMLSerializer*/
import RSVP from 'rsvp';
import { jIO } from '../jio';
(function (jIO, RSVP, DOMParser, XMLSerializer) { (function (jIO, RSVP, DOMParser, XMLSerializer) {
"use strict"; "use strict";
......
...@@ -18,8 +18,11 @@ ...@@ -18,8 +18,11 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/ /*global DOMException, crypto, Uint8Array, ArrayBuffer*/
/*global jIO, RSVP, DOMException, Blob, crypto, Uint8Array, ArrayBuffer*/
import RSVP from 'rsvp';
import { jIO } from '../jio';
import { Blob } from '../utils-compat';
(function (jIO, RSVP, DOMException, Blob, crypto, Uint8Array, ArrayBuffer) { (function (jIO, RSVP, DOMException, Blob, crypto, Uint8Array, ArrayBuffer) {
"use strict"; "use strict";
......
...@@ -18,8 +18,11 @@ ...@@ -18,8 +18,11 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/ /*global DOMParser */
/*global jIO, RSVP, DOMParser, Blob */
import RSVP from 'rsvp';
import { jIO } from '../jio';
import { Blob } from '../utils-compat';
// JIO Dav Storage Description : // JIO Dav Storage Description :
// { // {
......
...@@ -17,9 +17,15 @@ ...@@ -17,9 +17,15 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/
/*global Blob, RSVP, unescape, escape*/ /*eslint no-unsafe-negation: "off"*/
(function (jIO, Blob, RSVP, unescape, escape) { /*global unescape, escape*/
import RSVP from 'rsvp';
import { jIO } from '../jio';
import { Blob, btoa, atob } from '../utils-compat';
(function (jIO, Blob, RSVP, unescape, escape, atob, btoa) {
"use strict"; "use strict";
/** /**
* The jIO DocumentStorage extension * The jIO DocumentStorage extension
...@@ -37,18 +43,18 @@ ...@@ -37,18 +43,18 @@
DOCUMENT_REGEXP = new RegExp("^jio_document/([\\w=]+)" + DOCUMENT_REGEXP = new RegExp("^jio_document/([\\w=]+)" +
DOCUMENT_EXTENSION + "$"), DOCUMENT_EXTENSION + "$"),
ATTACHMENT_REGEXP = new RegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$"), ATTACHMENT_REGEXP = new RegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$"),
btoa = function (str) { btoaU = function (str) {
return window.btoa(unescape(encodeURIComponent(str))); return btoa(unescape(encodeURIComponent(str)));
}, },
atob = function (str) { atobU = function (str) {
return decodeURIComponent(escape(window.atob(str))); return decodeURIComponent(escape(atob(str)));
}; };
function getSubAttachmentIdFromParam(id, name) { function getSubAttachmentIdFromParam(id, name) {
if (name === undefined) { if (name === undefined) {
return 'jio_document/' + btoa(id) + DOCUMENT_EXTENSION; return 'jio_document/' + btoaU(id) + DOCUMENT_EXTENSION;
} }
return 'jio_attachment/' + btoa(id) + "/" + btoa(name); return 'jio_attachment/' + btoaU(id) + "/" + btoaU(name);
} }
DocumentStorage.prototype.get = function (id) { DocumentStorage.prototype.get = function (id) {
...@@ -70,8 +76,8 @@ ...@@ -70,8 +76,8 @@
if (ATTACHMENT_REGEXP.test(key)) { if (ATTACHMENT_REGEXP.test(key)) {
exec = ATTACHMENT_REGEXP.exec(key); exec = ATTACHMENT_REGEXP.exec(key);
try { try {
if (atob(exec[1]) === id) { if (atobU(exec[1]) === id) {
attachments[atob(exec[2])] = {}; attachments[atobU(exec[2])] = {};
} }
} catch (error) { } catch (error) {
// Check if unable to decode base64 data // Check if unable to decode base64 data
...@@ -142,7 +148,7 @@ ...@@ -142,7 +148,7 @@
attachment = undefined; attachment = undefined;
if (DOCUMENT_REGEXP.test(key)) { if (DOCUMENT_REGEXP.test(key)) {
try { try {
id = atob(DOCUMENT_REGEXP.exec(key)[1]); id = atobU(DOCUMENT_REGEXP.exec(key)[1]);
} catch (error) { } catch (error) {
// Check if unable to decode base64 data // Check if unable to decode base64 data
if (!error instanceof ReferenceError) { if (!error instanceof ReferenceError) {
...@@ -155,8 +161,8 @@ ...@@ -155,8 +161,8 @@
} else if (ATTACHMENT_REGEXP.test(key)) { } else if (ATTACHMENT_REGEXP.test(key)) {
exec = ATTACHMENT_REGEXP.exec(key); exec = ATTACHMENT_REGEXP.exec(key);
try { try {
id = atob(exec[1]); id = atobU(exec[1]);
attachment = atob(exec[2]); attachment = atobU(exec[2]);
} catch (error) { } catch (error) {
// Check if unable to decode base64 data // Check if unable to decode base64 data
if (!error instanceof ReferenceError) { if (!error instanceof ReferenceError) {
...@@ -209,7 +215,7 @@ ...@@ -209,7 +215,7 @@
if (DOCUMENT_REGEXP.test(key)) { if (DOCUMENT_REGEXP.test(key)) {
try { try {
result.push({ result.push({
id: atob(DOCUMENT_REGEXP.exec(key)[1]), id: atobU(DOCUMENT_REGEXP.exec(key)[1]),
value: {} value: {}
}); });
} catch (error) { } catch (error) {
...@@ -249,4 +255,4 @@ ...@@ -249,4 +255,4 @@
jIO.addStorage('document', DocumentStorage); jIO.addStorage('document', DocumentStorage);
}(jIO, Blob, RSVP, unescape, escape)); }(jIO, Blob, RSVP, unescape, escape, atob, btoa));
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/
/*global RSVP, Blob*/ import RSVP from 'rsvp';
import { jIO } from '../jio';
import { Blob } from '../utils-compat';
(function (jIO, RSVP, Blob) { (function (jIO, RSVP, Blob) {
"use strict"; "use strict";
......
...@@ -17,12 +17,15 @@ ...@@ -17,12 +17,15 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
import RSVP from 'rsvp';
import { jIO } from '../jio';
import { Blob } from '../utils-compat';
/** /**
* JIO Dropbox Storage. Type = "dropbox". * JIO Dropbox Storage. Type = "dropbox".
* Dropbox "database" storage. * Dropbox "database" storage.
*/ */
/*global Blob, jIO, RSVP*/
/*jslint nomen: true*/
(function (jIO, RSVP, Blob, JSON) { (function (jIO, RSVP, Blob, JSON) {
"use strict"; "use strict";
......
...@@ -17,16 +17,20 @@ ...@@ -17,16 +17,20 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
import RSVP from 'rsvp';
import URI from 'urijs';
import UriTemplate from 'uritemplate';
import FormData from 'form-data';
import { jIO, SimpleQuery, ComplexQuery } from '../jio';
import { Blob } from '../utils-compat';
// JIO ERP5 Storage Description : // JIO ERP5 Storage Description :
// { // {
// type: "erp5" // type: "erp5"
// url: {string} // url: {string}
// } // }
/*jslint nomen: true, unparam: true */
/*global jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery*/
(function (jIO, UriTemplate, FormData, RSVP, URI, Blob, (function (jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery) { SimpleQuery, ComplexQuery) {
"use strict"; "use strict";
......
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true */
/*global RSVP, UriTemplate*/ import RSVP from 'rsvp';
import UriTemplate from 'uritemplate';
import { jIO } from '../jio';
(function (jIO, RSVP, UriTemplate) { (function (jIO, RSVP, UriTemplate) {
"use strict"; "use strict";
......
...@@ -17,12 +17,18 @@ ...@@ -17,12 +17,18 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*global JSON*/
import RSVP from 'rsvp';
import UriTemplate from 'uritemplate';
import { jIO } from '../jio';
import { Blob } from '../utils-compat';
/** /**
* JIO Google Drive Storage. Type = "gdrive". * JIO Google Drive Storage. Type = "gdrive".
* Google Drive "database" storage. * Google Drive "database" storage.
*/ */
/*global jIO, Blob, RSVP, UriTemplate, JSON*/
/*jslint nomen: true*/
(function (jIO, Blob, RSVP, UriTemplate, JSON) { (function (jIO, Blob, RSVP, UriTemplate, JSON) {
"use strict"; "use strict";
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global define, jIO */ /*global define, jIO */
/** /**
......
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*global RSVP, Blob*/
/*jslint nomen: true*/ import RSVP from 'rsvp';
import { jIO } from '../jio';
import { Blob } from '../utils-compat';
(function (jIO, RSVP, Blob) { (function (jIO, RSVP, Blob) {
"use strict"; "use strict";
......
...@@ -18,6 +18,12 @@ ...@@ -18,6 +18,12 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*global indexedDB, Math, IDBKeyRange, IDBOpenDBRequest, DOMError*/
import RSVP from 'rsvp';
import { jIO } from '../jio';
import { Blob } from '../utils-compat';
/** /**
* JIO Indexed Database Storage. * JIO Indexed Database Storage.
* *
...@@ -41,10 +47,6 @@ ...@@ -41,10 +47,6 @@
* - https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB * - https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB
*/ */
/*jslint nomen: true */
/*global indexedDB, jIO, RSVP, Blob, Math, IDBKeyRange, IDBOpenDBRequest,
DOMError, Event*/
(function (indexedDB, jIO, RSVP, Blob, Math, IDBKeyRange, IDBOpenDBRequest, (function (indexedDB, jIO, RSVP, Blob, Math, IDBKeyRange, IDBOpenDBRequest,
DOMError) { DOMError) {
"use strict"; "use strict";
...@@ -543,4 +545,7 @@ ...@@ -543,4 +545,7 @@
}; };
jIO.addStorage("indexeddb", IndexedDBStorage); jIO.addStorage("indexeddb", IndexedDBStorage);
}(indexedDB, jIO, RSVP, Blob, Math, IDBKeyRange, IDBOpenDBRequest, DOMError));
/* Safari does not define DOMError */
}(indexedDB, jIO, RSVP, Blob, Math, IDBKeyRange, IDBOpenDBRequest,
DOMError || {}));
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, regexp: true */
/*global window, exports, require, define, jIO, RSVP */ /*global window, exports, require, define, jIO, RSVP */
/** /**
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/ /*global sessionStorage, localStorage */
/*global jIO, sessionStorage, localStorage, RSVP */
import RSVP from 'rsvp';
import { jIO } from '../jio';
/** /**
* JIO Local Storage. Type = 'local'. * JIO Local Storage. Type = 'local'.
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/ import RSVP from 'rsvp';
/*global jIO, RSVP*/ import { jIO } from '../jio';
/** /**
* JIO Memory Storage. Type = 'memory'. * JIO Memory Storage. Type = 'memory'.
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, define, Blob */ /*global jIO, define, Blob */
/** /**
......
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/
/*global jIO, DOMParser, Node */ /*global DOMParser, Node */
import { jIO } from '../jio';
(function (jIO, DOMParser, Node) { (function (jIO, DOMParser, Node) {
"use strict"; "use strict";
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*global JSON, FormData, btoa, Blob, jIO, RSVP, UriTemplate, crypto,
Uint8Array, TextEncoder*/
/** /**
* JIO Qiniu Storage. Type = "qiniu". * JIO Qiniu Storage. Type = "qiniu".
* Qiniu "database" storage. * Qiniu "database" storage.
...@@ -28,9 +31,6 @@ ...@@ -28,9 +31,6 @@
* - disable getAttachment HTTP cache * - disable getAttachment HTTP cache
*/ */
/*global JSON, FormData, btoa, Blob, jIO, RSVP, UriTemplate, crypto,
Uint8Array, TextEncoder*/
/*jslint nomen: true*/
(function (JSON, FormData, btoa, Blob, jIO, RSVP, UriTemplate, Crypto, (function (JSON, FormData, btoa, Blob, jIO, RSVP, UriTemplate, Crypto,
Uint8Array, TextEncoder) { Uint8Array, TextEncoder) {
"use strict"; "use strict";
......
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/
/*global RSVP, jiodate*/ import RSVP from 'rsvp';
import { jIO, jiodate } from '../jio';
(function (jIO, RSVP, jiodate) { (function (jIO, RSVP, jiodate) {
"use strict"; "use strict";
......
...@@ -302,7 +302,7 @@ ...@@ -302,7 +302,7 @@
}; };
functions.repair_sub_storages_count = 0; functions.repair_sub_storages_count = 0;
functions.repairAllSubStoragesCallback = function (method, functions.repairAllSubStoragesCallback = function (method,
index, err, response) { index, err) {
/*jslint unparam: true */ /*jslint unparam: true */
if (err) { if (err) {
return command.error(err); return command.error(err);
...@@ -573,7 +573,7 @@ ...@@ -573,7 +573,7 @@
} }
}; };
functions.putAttachments = function (param, attachment_to_put) { functions.putAttachments = function (param, attachment_to_put) {
return function (method, index, err, response) { return function (method, index, err) {
/*jslint unparam: true */ /*jslint unparam: true */
var i, attachment; var i, attachment;
if (err) { if (err) {
...@@ -606,9 +606,9 @@ ...@@ -606,9 +606,9 @@
} }
}; };
}; };
functions.putAttachmentCallback = function (param) { functions.putAttachmentCallback = function () {
/*jslint unparam: true */ /*jslint unparam: true */
return function (method, index, err, response) { return function (method, index, err) {
if (err) { if (err) {
return callback(err, undefined); return callback(err, undefined);
} }
......
...@@ -19,8 +19,9 @@ ...@@ -19,8 +19,9 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/ import RSVP from 'rsvp';
/*global jIO, RSVP, Rusha*/ import Rusha from 'rusha';
import { jIO } from '../jio';
(function (jIO, RSVP, Rusha, stringify) { (function (jIO, RSVP, Rusha, stringify) {
"use strict"; "use strict";
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global jIO, hex_sha256, define */ /*global jIO, hex_sha256, define */
/** /**
......
/*jslint indent: 2, maxlen: 80, nomen: true */ /*global define, jIO, btoa, b64_hmac_sha1, jQuery, XMLHttpRequest,
/*global define, jIO, btoa, b64_hmac_sha1, jQuery, XMLHttpRequest, XHRwrapper,
FormData*/ FormData*/
/**
/**
* JIO S3 Storage. Type = "s3". * JIO S3 Storage. Type = "s3".
* Amazon S3 "database" storage. * Amazon S3 "database" storage.
*/ */
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
** 31/01/2014 ** ** 31/01/2014 **
***********************************************************************/ ***********************************************************************/
/*jslint indent:2,maxlen:80,nomen:true*/
/*global jIO, define, exports, require, sjcl*/ /*global jIO, define, exports, require, sjcl*/
(function (dependencies, module) { (function (dependencies, module) {
......
...@@ -18,14 +18,14 @@ ...@@ -18,14 +18,14 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/ import Rusha from 'rusha';
/*global Rusha*/ import { jIO } from '../jio';
/** /**
* JIO Sha Storage. Type = 'sha'. * JIO Sha Storage. Type = 'sha'.
*/ */
(function (Rusha) { (function (jIO, Rusha) {
"use strict"; "use strict";
var rusha = new Rusha(); var rusha = new Rusha();
...@@ -72,4 +72,4 @@ ...@@ -72,4 +72,4 @@
jIO.addStorage('sha', ShaStorage); jIO.addStorage('sha', ShaStorage);
}(Rusha)); }(jIO, Rusha));
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, define, Blob */ /*global jIO, define, Blob */
/** /**
......
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define, jIO, test_util, RSVP, test, ok, deepEqual, module, stop, /*global define, jIO, test_util, RSVP, test, ok, deepEqual, module, stop,
start, hex_sha256 */ start */
// define([module_name], [dependencies], module); // define([module_name], [dependencies], module);
(function (dependencies, module) { (function (dependencies, module) {
......
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true */
/*global RSVP*/ import RSVP from 'rsvp';
import { jIO } from '../jio';
/** /**
* JIO Union Storage. Type = 'union'. * JIO Union Storage. Type = 'union'.
......
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/
import { jIO } from '../jio';
(function (jIO) { (function (jIO) {
"use strict"; "use strict";
......
...@@ -17,17 +17,27 @@ ...@@ -17,17 +17,27 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*global openDatabase, navigator*/
import RSVP from 'rsvp';
import { jIO } from '../jio';
import { Blob } from '../utils-compat';
/** /**
* JIO Websql Storage. Type = "websql". * JIO Websql Storage. Type = "websql".
* websql "database" storage. * websql "database" storage.
*/ */
/*global Blob, jIO, RSVP, openDatabase*/
/*jslint nomen: true*/
(function (jIO, RSVP, Blob, openDatabase) { (function (jIO, RSVP, Blob, openDatabase) {
"use strict"; "use strict";
if (openDatabase === undefined) {
openDatabase = function () {
throw new Error('WebSQL is not supported by ' + navigator.userAgent);
};
}
/** /**
* The JIO Websql Storage extension * The JIO Websql Storage extension
* *
......
/*jslint /*eslint no-useless-escape: "off"*/
indent: 2,
maxlen: 80,
plusplus: true,
nomen: true,
regexp: true
*/
/*global /*global
define: true, define: true,
exports: true, exports: true,
...@@ -15,6 +9,7 @@ ...@@ -15,6 +9,7 @@
XMLHttpRequest, XMLHttpRequest,
FormData FormData
*/ */
/** /**
* JIO XWiki Storage. Type = 'xwiki'. * JIO XWiki Storage. Type = 'xwiki'.
* XWiki Document/Attachment storage. * XWiki Document/Attachment storage.
......
...@@ -17,9 +17,15 @@ ...@@ -17,9 +17,15 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint nomen: true*/
/*global RSVP, Blob, LZString, DOMException*/ /*global DOMException*/
(function (RSVP, Blob, LZString, DOMException) {
import RSVP from 'rsvp';
import LZString from 'lz-string';
import { jIO } from '../jio';
import { Blob } from '../utils-compat';
(function (jIO, RSVP, Blob, LZString, DOMException) {
"use strict"; "use strict";
/** /**
...@@ -130,4 +136,4 @@ ...@@ -130,4 +136,4 @@
}; };
jIO.addStorage('zip', ZipStorage); jIO.addStorage('zip', ZipStorage);
}(RSVP, Blob, LZString, DOMException)); }(jIO, RSVP, Blob, LZString, DOMException));
import { jIO } from '../jio';
import '../storage';
import '../jio.storage/documentstorage';
import '../jio.storage/dropboxstorage';
import '../jio.storage/erp5storage';
import '../jio.storage/memorystorage';
import '../jio.storage/querystorage';
import '../jio.storage/replicatestorage';
export {
jIO
};
This diff is collapsed.
...@@ -17,9 +17,19 @@ ...@@ -17,9 +17,19 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*global RSVP, window, parseStringToObject*/
/*jslint nomen: true, maxlen: 90*/ /*eslint max-len: ["error", 90], no-useless-escape: "off"*/
(function (RSVP, window, parseStringToObject) { /*global window*/
import RSVP from 'rsvp';
import { parseStringToObject } from './parser-final';
var moduleExports = {};
try {
moduleExports = window;
} catch (err) {}
(function (RSVP, moduleExports, parseStringToObject) {
"use strict"; "use strict";
var query_class_dict = {}, var query_class_dict = {},
...@@ -576,7 +586,6 @@ ...@@ -576,7 +586,6 @@
* #crossLink "Query/toString:method" * #crossLink "Query/toString:method"
*/ */
ComplexQuery.prototype.toString = function () { ComplexQuery.prototype.toString = function () {
/*global objectToSearchText */
return objectToSearchText(this.toJSON()); return objectToSearchText(this.toJSON());
}; };
...@@ -1079,9 +1088,11 @@ ...@@ -1079,9 +1088,11 @@
Query.parseStringToObject = parseStringToObject; Query.parseStringToObject = parseStringToObject;
Query.objectToSearchText = objectToSearchText; Query.objectToSearchText = objectToSearchText;
window.Query = Query; moduleExports.Query = Query;
window.SimpleQuery = SimpleQuery; moduleExports.SimpleQuery = SimpleQuery;
window.ComplexQuery = ComplexQuery; moduleExports.ComplexQuery = ComplexQuery;
window.QueryFactory = QueryFactory; moduleExports.QueryFactory = QueryFactory;
}(RSVP, moduleExports, parseStringToObject));
}(RSVP, window, parseStringToObject)); export default moduleExports;
/*
* Copyright 2014, Nexedi SA
*
* This program is free software: you can Use, Study, Modify and Redistribute
* it under the terms of the GNU General Public License version 3, or (at your
* option) any later version, as published by the Free Software Foundation.
*
* You can also Link and Combine this program with other software covered by
* the terms of any of the Free Software licenses or any of the Open Source
* Initiative approved licenses and Convey the resulting work. Corresponding
* source of such a combination shall include the source code for all other
* software used.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
import RSVP from 'rsvp';
import { jIO } from './jio';
import { declareMethod, ensurePushableQueue } from './utils';
import { Blob } from './utils-compat';
// tools
function checkId(argument_list, storage, method_name) {
if (typeof argument_list[0] !== 'string' || argument_list[0] === '') {
throw new jIO.util.jIOError(
"Document id must be a non empty string on '" + storage.__type +
"." + method_name + "'.",
400
);
}
}
function checkAttachmentId(argument_list, storage, method_name) {
if (typeof argument_list[1] !== 'string' || argument_list[1] === '') {
throw new jIO.util.jIOError(
"Attachment id must be a non empty string on '" + storage.__type +
"." + method_name + "'.",
400
);
}
}
function JioProxyStorage(type, storage) {
if (!(this instanceof JioProxyStorage)) {
return new JioProxyStorage();
}
this.__type = type;
this.__storage = storage;
}
declareMethod(JioProxyStorage, 'put', checkId, function (argument_list) {
return argument_list[0];
});
declareMethod(JioProxyStorage, 'get', checkId);
declareMethod(JioProxyStorage, 'bulk');
declareMethod(JioProxyStorage, 'remove', checkId, function (argument_list) {
return argument_list[0];
});
/**
* @returns RSVP.Queue
*/
JioProxyStorage.prototype.post = function () {
var context = this,
argument_list = arguments;
return ensurePushableQueue(function () {
var storage_method = context.__storage.post;
if (storage_method === undefined) {
throw new jIO.util.jIOError(
"Capacity 'post' is not implemented on '" + context.__type + "'",
501
);
}
return context.__storage.post.apply(context.__storage, argument_list);
});
};
declareMethod(JioProxyStorage, 'putAttachment', function (
argument_list, storage, method_name
) {
checkId(argument_list, storage, method_name);
checkAttachmentId(argument_list, storage, method_name);
var options = argument_list[3] || {};
if (typeof argument_list[2] === 'string') {
argument_list[2] = new Blob([argument_list[2]], {
type: options._content_type || options._mimetype ||
'text/plain;charset=utf-8'
});
} else if (!(argument_list[2] instanceof Blob)) {
throw new jIO.util.jIOError(
'Attachment content is not a blob',
400
);
}
});
declareMethod(JioProxyStorage, 'removeAttachment', function (
argument_list, storage, method_name
) {
checkId(argument_list, storage, method_name);
checkAttachmentId(argument_list, storage, method_name);
});
declareMethod(JioProxyStorage, 'getAttachment', function (
argument_list, storage, method_name
) {
var result = 'blob';
// if (param.storage_spec.type !== 'indexeddb' &&
// param.storage_spec.type !== 'dav' &&
// (param.kwargs._start !== undefined
// || param.kwargs._end !== undefined)) {
// restCommandRejecter(param, [
// 'bad_request',
// 'unsupport',
// '_start, _end not support'
// ]);
// return false;
// }
checkId(argument_list, storage, method_name);
checkAttachmentId(argument_list, storage, method_name);
// Drop optional parameters, which are only used in postfunction
if (argument_list[2] !== undefined) {
result = argument_list[2].format || result;
delete argument_list[2].format;
}
return result;
}, function (argument_list, blob, convert) {
var result;
if (!(blob instanceof Blob)) {
throw new jIO.util.jIOError(
"'getAttachment' (" + argument_list[0] + " , " +
argument_list[1] + ") on '" + this.__type +
"' does not return a Blob.",
501
);
}
if (convert === 'blob') {
result = blob;
} else if (convert === 'data_url') {
result = new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsDataURL(blob);
})
.push(function (evt) {
return evt.target.result;
});
} else if (convert === 'array_buffer') {
result = new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsArrayBuffer(blob);
})
.push(function (evt) {
return evt.target.result;
});
} else if (convert === 'text') {
result = new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsText(blob);
})
.push(function (evt) {
return evt.target.result;
});
} else if (convert === 'json') {
result = new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsText(blob);
})
.push(function (evt) {
return JSON.parse(evt.target.result);
});
} else {
throw new jIO.util.jIOError(
this.__type + ".getAttachment format: '" + convert +
"' is not supported",
400
);
}
return result;
});
JioProxyStorage.prototype.buildQuery = function () {
var storage_method = this.__storage.buildQuery,
context = this,
argument_list = arguments;
if (storage_method === undefined) {
throw new jIO.util.jIOError(
"Capacity 'buildQuery' is not implemented on '" + this.__type + "'",
501
);
}
return ensurePushableQueue(storage_method, argument_list,
context.__storage);
};
JioProxyStorage.prototype.hasCapacity = function (name) {
var storage_method = this.__storage.hasCapacity,
capacity_method = this.__storage[name];
if (capacity_method !== undefined) {
return true;
}
if ((storage_method === undefined) ||
!storage_method.apply(this.__storage, arguments)) {
throw new jIO.util.jIOError(
"Capacity '" + name + "' is not implemented on '" + this.__type + "'",
501
);
}
return true;
};
JioProxyStorage.prototype.allDocs = function (options) {
var context = this;
if (options === undefined) {
options = {};
}
return ensurePushableQueue(function () {
if (context.hasCapacity('list') &&
((options.query === undefined) || context.hasCapacity('query')) &&
((options.sort_on === undefined) || context.hasCapacity('sort')) &&
((options.select_list === undefined) ||
context.hasCapacity('select')) &&
((options.include_docs === undefined) ||
context.hasCapacity('include')) &&
((options.limit === undefined) || context.hasCapacity('limit'))) {
return context.buildQuery(options)
.push(function (result) {
return {
data: {
rows: result,
total_rows: result.length
}
};
});
}
});
};
declareMethod(JioProxyStorage, 'allAttachments', checkId);
declareMethod(JioProxyStorage, 'repair');
JioProxyStorage.prototype.repair = function () {
var context = this,
argument_list = arguments;
return ensurePushableQueue(function () {
var storage_method = context.__storage.repair;
if (storage_method !== undefined) {
return context.__storage.repair.apply(
context.__storage, argument_list
);
}
});
};
var storageTypes = {};
function createJIO(config, util) {
if (typeof config.type !== 'string') {
throw new TypeError("Invalid storage description");
}
if (!storageTypes[config.type]) {
throw new TypeError("Unknown storage '" + config.type + "'");
}
return new JioProxyStorage(
config.type,
new storageTypes[config.type](config, util)
);
}
jIO.createJIO = createJIO;
function addStorage(type, Constructor) {
if (typeof type !== 'string') {
throw new TypeError(
"jIO.addStorage(): Argument 1 is not of type 'string'"
);
}
if (typeof Constructor !== 'function') {
throw new TypeError(
"jIO.addStorage(): Argument 2 is not of type 'function'"
);
}
if (storageTypes[type] !== undefined) {
throw new TypeError(
"jIO.addStorage(): Storage type already exists"
);
}
storageTypes[type] = Constructor;
}
jIO.addStorage = addStorage;
/*
* Copyright 2014, Nexedi SA
*
* This program is free software: you can Use, Study, Modify and Redistribute
* it under the terms of the GNU General Public License version 3, or (at your
* option) any later version, as published by the Free Software Foundation.
*
* You can also Link and Combine this program with other software covered by
* the terms of any of the Free Software licenses or any of the Open Source
* Initiative approved licenses and Convey the resulting work. Corresponding
* source of such a combination shall include the source code for all other
* software used.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/* global window, WeakMap, Buffer, ArrayBuffer, Uint8Array */
/**
* Compatibility functions with node.js
*/
import process from 'process';
var EventTarget,
Blob,
FileReader,
html5weakmap;
try {
EventTarget = window.EventTarget;
Blob = window.Blob;
FileReader = window.FileReader;
} catch (error) {
html5weakmap = new WeakMap();
EventTarget = function EventTarget() {
html5weakmap.set(this, Object.create(null));
};
EventTarget.prototype.addEventListener = function (type, listener) {
if (typeof listener !== 'function') {
return;
}
var em = html5weakmap.get(this);
type = type.toString();
if (em[type]) {
em[type].push(listener);
} else {
em[type] = [listener];
}
};
EventTarget.prototype.removeEventListener = function (type, listener) {
if (typeof listener !== 'function') {
return;
}
var em = html5weakmap.get(this),
i,
listeners = em[type];
type = type.toString();
if (listeners) {
for (i = 0; i < listeners.length; ++i) {
if (listeners[i] === listener) {
if (listeners.length === 1) {
delete em[type];
return;
}
listeners.splice(i, 1);
return;
}
}
}
};
EventTarget.prototype.dispatchEvent = function (event) {
var type = event.type.toString(),
em = html5weakmap.get(this),
ontype = 'on' + type,
i,
listeners;
if (typeof this[ontype] === 'function') {
try {
this[ontype](event);
} catch (ignore) {}
}
listeners = em[type];
if (listeners) {
for (i = 0; i < listeners.length; ++i) {
try {
listeners[i](event);
} catch (ignore) {}
}
}
};
Blob = function Blob(blobParts, options) {
// https://developer.mozilla.org/en-US/docs/Web/API/Blob
var i,
priv = {},
buffers = [];
html5weakmap.set(this, priv);
for (i = 0; i < blobParts.length; ++i) {
if (Buffer.isBuffer(blobParts[i])) {
buffers.push(blobParts[i]);
} else if (blobParts[i] instanceof Blob) {
buffers.push(html5weakmap.get(blobParts[i]).data);
} else if (blobParts[i] instanceof ArrayBuffer) {
buffers.push(new Buffer(new Uint8Array(blobParts[i])));
} else {
buffers.push(new Buffer('' + blobParts[i]));
}
}
priv.data = Buffer.concat(buffers);
Object.defineProperty(this, 'size', {
enumerable: true,
value: priv.data.length
});
Object.defineProperty(this, 'type', {
enumerable: true,
value: options ? '' + (options.type || '') : ''
});
};
Blob.prototype.size = 0;
Blob.prototype.type = '';
Blob.prototype.slice = function (start, end, contentType) {
return new Blob([html5weakmap.get(this).data.slice(start, end)], {
type: contentType
});
};
FileReader = function FileReader() {
EventTarget.call(this);
};
FileReader.prototype = Object.create(EventTarget.prototype);
Object.defineProperty(FileReader, 'constructor', {
value: FileReader
});
FileReader.prototype.readAsText = function (blob) {
var target = this,
priv = html5weakmap.get(blob),
result = priv.data.toString(),
event = Object.freeze({
type: 'load',
target: target
});
process.nextTick(function () {
target.result = result;
target.dispatchEvent(event);
});
};
FileReader.prototype.readAsArrayBuffer = function (blob) {
var target = this,
priv = html5weakmap.get(blob),
result = new Uint8Array(priv.data).buffer,
event = Object.freeze({
type: 'load',
target: target
});
process.nextTick(function () {
target.result = result;
target.dispatchEvent(event);
});
};
FileReader.prototype.readAsDataURL = function (blob) {
var target = this,
priv = html5weakmap.get(blob),
result = 'data:' + blob.type + ';base64,' + priv.data.toString('base64'),
event = Object.freeze({
type: 'load',
target: target
});
process.nextTick(function () {
target.result = result;
target.dispatchEvent(event);
});
};
}
function atob(str) {
try {
return window.atob(str);
}
catch (err) {
var buffer;
if (str instanceof Buffer) {
buffer = str;
}
else {
buffer = Buffer.from(str.toString(), 'base64');
}
return buffer.toString('binary');
}
}
function btoa(str) {
try {
return window.btoa(str);
}
catch (err) {
var buffer;
if (str instanceof Buffer) {
buffer = str;
}
else {
buffer = Buffer.from(str.toString(), 'binary');
}
return buffer.toString('base64');
}
}
export {
EventTarget,
Blob,
FileReader,
atob,
btoa
};
/*
* Copyright 2014, Nexedi SA
*
* This program is free software: you can Use, Study, Modify and Redistribute
* it under the terms of the GNU General Public License version 3, or (at your
* option) any later version, as published by the Free Software Foundation.
*
* You can also Link and Combine this program with other software covered by
* the terms of any of the Free Software licenses or any of the Open Source
* Initiative approved licenses and Convey the resulting work. Corresponding
* source of such a combination shall include the source code for all other
* software used.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/* global ArrayBuffer, Uint8Array */
import RSVP from 'rsvp';
import XMLHttpRequest from 'xhr2';
import { jIO } from './jio';
import { Blob, FileReader, atob } from './utils-compat';
/**
* @returns RSVP.Queue
*/
function ensurePushableQueue(callback, argument_list, context) {
var result;
try {
result = callback.apply(context, argument_list);
} catch (e) {
return new RSVP.Queue()
.push(function returnPushableError() {
return RSVP.reject(e);
});
}
if (result instanceof RSVP.Queue) {
return result;
}
return new RSVP.Queue().push(function () {
return result;
});
}
function declareMethod(klass, name, precondition_function, post_function) {
klass.prototype[name] = function () {
var argument_list = arguments,
context = this,
precondition_result,
storage_method,
queue;
// Precondition function are not asynchronous
if (precondition_function !== undefined) {
precondition_result = precondition_function.apply(
context.__storage,
[argument_list, context, name]
);
}
storage_method = context.__storage[name];
if (storage_method === undefined) {
throw new jIO.util.jIOError(
"Capacity '" + name + "' is not implemented on '" +
context.__type + "'",
501
);
}
queue = ensurePushableQueue(
storage_method, argument_list, context.__storage
);
if (post_function !== undefined) {
queue
.push(function (result) {
return post_function.call(
context,
argument_list,
result,
precondition_result
);
});
}
return queue;
};
// Allow chain
return this;
}
function jIOError(message, status_code) {
if ((message !== undefined) && (typeof message !== 'string')) {
throw new TypeError('You must pass a string.');
}
this.message = message || 'Default Message';
this.status_code = status_code || 500;
}
jIOError.prototype = new Error();
jIOError.prototype.constructor = jIOError;
jIO.util.jIOError = jIOError;
/**
* Send request with XHR and return a promise. xhr.onload: The promise is
* resolved when the status code is lower than 400 with the xhr object as
* first parameter. xhr.onerror: reject with xhr object as first
* parameter. xhr.onprogress: notifies the xhr object.
*
* @param param The parameters
* @param {string} param.type The request method
* @param {string} param.dataType The data type to retrieve
* @param {string} param.url The url
* @param {any} param.data The data to send
* @param {any} param.headers The HTTP headers sent with the request
* @param {number} param.timeout The request timeout value
* @param {Function} param.beforeSend A function called just before the
* send request. The first parameter of this function is the XHR object.
* @return {Promise} The promise
*/
function ajax(param) {
var xhr = new XMLHttpRequest();
return new RSVP.Promise(function (resolve, reject, notify) {
var k;
xhr.open(param.type || "GET", param.url, true);
xhr.responseType = param.dataType || "";
if (typeof param.headers === 'object' && param.headers !== null) {
for (k in param.headers) {
if (param.headers.hasOwnProperty(k)) {
xhr.setRequestHeader(k, param.headers[k]);
}
}
}
xhr.addEventListener("load", function (e) {
if (e.target.status >= 400) {
return reject(e);
}
resolve(e);
});
xhr.addEventListener("error", reject);
xhr.addEventListener("progress", function (e) {
if (notify) {
notify(e);
}
});
if (typeof param.xhrFields === 'object' && param.xhrFields !== null) {
for (k in param.xhrFields) {
if (param.xhrFields.hasOwnProperty(k)) {
xhr[k] = param.xhrFields[k];
}
}
}
if (param.timeout !== undefined && param.timeout !== 0) {
xhr.timeout = param.timeout;
xhr.ontimeout = function () {
return reject(new jIO.util.jIOError("Gateway Timeout", 504));
};
}
if (typeof param.beforeSend === 'function') {
param.beforeSend(xhr);
}
xhr.send(param.data);
}, function () {
xhr.abort();
});
}
jIO.util.ajax = ajax;
function base64toBlob(b64String, mimeString) {
var byteString = atob(b64String),
// write the bytes of the string to an ArrayBuffer
arrayBuffer = new ArrayBuffer(byteString.length),
_ia = new Uint8Array(arrayBuffer),
i;
for (i = 0; i < byteString.length; i += 1) {
_ia[i] = byteString.charCodeAt(i);
}
return new Blob([arrayBuffer], {type: mimeString});
}
jIO.util.base64toBlob = base64toBlob;
// https://gist.github.com/davoclavo/4424731
function dataURItoBlob(dataURI) {
if (dataURI === 'data:') {
return new Blob();
}
// convert base64 to raw binary data held in a string
var mimeString = dataURI.split(',')[0].split(':')[1];
mimeString = mimeString.slice(0, mimeString.length - ';base64'.length);
return base64toBlob(dataURI.split(',')[1], mimeString);
}
jIO.util.dataURItoBlob = dataURItoBlob;
function readBlobAsDataURL(blob) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject, notify) {
fr.addEventListener('load', resolve);
fr.addEventListener('error', reject);
fr.addEventListener('progress', notify);
fr.readAsDataURL(blob);
}, function () {
fr.abort();
});
}
jIO.util.readBlobAsDataURL = readBlobAsDataURL;
function readBlobAsText(blob, encoding) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject, notify) {
fr.addEventListener('load', resolve);
fr.addEventListener('error', reject);
fr.addEventListener('progress', notify);
fr.readAsText(blob, encoding);
}, function () {
fr.abort();
});
}
jIO.util.readBlobAsText = readBlobAsText;
function readBlobAsArrayBuffer(blob) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject, notify) {
fr.addEventListener('load', resolve);
fr.addEventListener('error', reject);
fr.addEventListener('progress', notify);
fr.readAsArrayBuffer(blob);
}, function () {
fr.abort();
});
}
jIO.util.readBlobAsArrayBuffer = readBlobAsArrayBuffer;
function stringify(obj) {
// Implement a stable JSON.stringify
// Object's keys are alphabetically ordered
var key,
key_list,
i,
value,
result_list;
if (obj === undefined) {
return undefined;
}
if (obj === null) {
return 'null';
}
if (obj.constructor === Object) {
key_list = Object.keys(obj).sort();
result_list = [];
for (i = 0; i < key_list.length; i += 1) {
key = key_list[i];
value = stringify(obj[key]);
if (value !== undefined) {
result_list.push(stringify(key) + ':' + value);
}
}
return '{' + result_list.join(',') + '}';
}
if (obj.constructor === Array) {
result_list = [];
for (i = 0; i < obj.length; i += 1) {
result_list.push(stringify(obj[i]));
}
return '[' + result_list.join(',') + ']';
}
return JSON.stringify(obj);
}
jIO.util.stringify = stringify;
export {
declareMethod,
ensurePushableQueue,
jIOError,
ajax,
base64toBlob,
dataURItoBlob,
readBlobAsDataURL,
readBlobAsText,
readBlobAsArrayBuffer,
stringify
};
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