Skip to content

Commit

Permalink
finalize the streaming typings
Browse files Browse the repository at this point in the history
  • Loading branch information
fbuecklers committed Nov 8, 2016
1 parent 29846f0 commit d025775
Show file tree
Hide file tree
Showing 32 changed files with 70 additions and 57 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/dist
/doc
/spec-ts/*.js
*.d.ts
!/spec-ts/*.d.ts
/index.d.ts
.DS_Store
*.iml
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function (grunt) {
browserifyOptions: browserifyOptions,
banner: longBanner,
plugin: ['./scripts/babel-helper', 'bundle-collapser/plugin', 'browserify-derequire'],
exclude: ['rxjs'],
exclude: ['rxjs/Observable'],
transform: [
['babelify', {
"plugins": ["external-helpers"]
Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
'https://unpkg.com/@reactivex/[email protected]/dist/global/Rx.js',
'build/baqend.js',
'spec/env.js',
'spec/helper.js',
Expand Down
8 changes: 6 additions & 2 deletions lib/query/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,12 @@ class Query {
*/

/**
* The Streaming SDK is required
* @ignore
* Returns an RxJS observable that receives events for streaming query.
* @param {Object} [options] options on whether an initial result and what kind of events (w.r.t. match types and operations) are requested
* @param {boolean} [options.initial=true] whether or not you want to receive the initial result set (i.e. the entities matching the query at subscription time)
* @param {(string|Array<string>)} [options.matchTypes=['all']] the match types you are interested in; accepts the default ('all'/['all']) or any combination of 'match', 'add', 'change', 'changeIndex' and 'remove'
* @param {(string|Array<string>)} [options.operations=['any']] the operations you are interested in; accepts the default ('any'/['any']) or any combination of 'insert', 'update', 'delete' and 'none'
* @return {Observable<StreamingEvent<T>>} an RxJS observable
*/
stream(options) {}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"dist": "grunt dist && npm run typings && npm run jsdoc",
"release": "node scripts/release",
"typings": "npm run typings-generate && npm run typings-test",
"typings-generate": "jsdoc -t tpl/typings -r lib -d index.d.ts && jsdoc -t tpl/typings -r streaming -d streaming.d.ts",
"typings-generate": "jsdoc -t tpl/typings -r lib streaming -d index.d.ts",
"typings-test": "tsc --target es6 --noImplicitAny -m commonjs spec-ts/streaming.spec.ts spec-ts/streaming.spec.ts ",
"jsdoc": "jsdoc -t tpl/theme -r lib streaming -c tpl/jsdoc.conf.json --package package.json -d doc",
"baqend": "node cli/index.js"
Expand Down
3 changes: 2 additions & 1 deletion spec/acl.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/bloomfilter.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/code.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/connect.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/crud.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/emf.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/enhancer.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/file.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/geopoint.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/globalDB.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
7 changes: 5 additions & 2 deletions spec/guide.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
DB = require('../streaming');
require('rxjs/add/operator/scan');
require('rxjs/add/operator/map');
}

describe("Guide Examples", function() {
Expand Down
3 changes: 2 additions & 1 deletion spec/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/log.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/metamodel.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/pushnotification.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/query.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
6 changes: 5 additions & 1 deletion spec/stream.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../streaming');
require('rxjs/add/operator/first');
require('rxjs/add/operator/scan');
require('rxjs/add/operator/map');
}

describe("Streaming Queries", function() {
Expand Down
3 changes: 2 additions & 1 deletion spec/types.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/user.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
3 changes: 2 additions & 1 deletion spec/validate.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof DB == 'undefined') {
var DB;
if (typeof module != 'undefined') {
require('./node');
DB = require('../lib');
}
Expand Down
1 change: 1 addition & 0 deletions streaming.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./index";
2 changes: 1 addition & 1 deletion streaming/connector/WebSocketConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class WebSocketConnector {

/**
* @param {connector.Connector} connector a connector
* @return {WebSocketConnector} a websocket connection
* @return {connector.WebSocketConnector} a websocket connection
*/
static create(connector) {
if (!connector)
Expand Down
4 changes: 3 additions & 1 deletion streaming/query/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ Node.prototype._stream = function(options, target) {
}

return new Stream(this.entityManager, type.name, this._serializeQuery(), options, this._serializeSort(), this.maxResults, this.firstResult, target).observable();
};
};

module.exports = Node;
17 changes: 0 additions & 17 deletions streaming/query/Query.js

This file was deleted.

15 changes: 9 additions & 6 deletions streaming/query/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Stream {
* @param {string} sort the sort string
* @param {number} limit the count, i.e. the number of items in the result
* @param {number} offset offset, i.e. the number of items to skip
* @param {Node} target the target of the stream
* @param {query.Node<T>} target the target of the stream
*/
constructor(entityManager, bucket, query, options, sort, limit, offset, target) {
var verifiedOptions = Stream.parseOptions(options);
Expand Down Expand Up @@ -134,7 +134,10 @@ class Stream {
* @returns {Object} an object containing VALID options
*/
static parseOptions(provided) {
var verified = {};
var verified = {
matchTypes: ['all'],
operations: ['any']
};

if (provided) {
if (provided.initial !== null && provided.initial !== undefined) {
Expand All @@ -146,7 +149,7 @@ class Stream {
}

if (provided.matchTypes) {
if (Object.prototype.toString.call(provided.matchTypes) === '[object Array]') {
if (Array.isArray(provided.matchTypes)) {
verified.matchTypes = provided.matchTypes;
} else {
verified.matchTypes = [provided.matchTypes];
Expand All @@ -156,7 +159,7 @@ class Stream {
}

if (provided.operations) {
if (Object.prototype.toString.call(provided.operations) === '[object Array]') {
if (Array.isArray(provided.operations)) {
verified.operations = provided.operations;
} else {
verified.operations = [provided.operations];
Expand All @@ -165,7 +168,7 @@ class Stream {
verified.operations = Stream.normalizeOperations(verified.operations);
}

if (verified.matchTypes && !verified.matchTypes.includes('all') && verified.operations && !verified.operations.includes('any')) {
if (verified.matchTypes.indexOf('all') == -1 && verified.operations.indexOf('any') == -1) {
throw new Error('Only subscriptions for either operations or matchTypes are allowed. You cannot subscribe to a query using matchTypes and operations at the same time!');
}
}
Expand Down Expand Up @@ -214,7 +217,7 @@ class Stream {
if (item === wildcard) {
return [wildcard];
}
if (!allowedItems.includes(item)) {//raise error on invalid elements
if (allowedItems.indexOf(item) == -1) {//raise error on invalid elements
throw new Error(item + ' not allowed for ' + itemType + '! (permitted: ' + allowedItems + '.)');
}
lastItem = item;
Expand Down
5 changes: 0 additions & 5 deletions tpl/typings/streaming.d.tpl

This file was deleted.

0 comments on commit d025775

Please sign in to comment.