Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugins #865

Open
wants to merge 137 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
9f8b98d
Added package.json for plugin_router.
mlucy Aug 11, 2016
98e828a
Added index.js to plugin_router.
mlucy Aug 12, 2016
8b3bcac
Added package.json for permissions plugin.
mlucy Aug 12, 2016
e1e13c6
checkpoint
mlucy Aug 12, 2016
f123d52
checkpoint
mlucy Aug 13, 2016
8cfac85
Reworked reliable stuff.
mlucy Aug 15, 2016
1378c09
added ReliableMetadata sketch
Aug 16, 2016
bd146d1
Added reliable shit.
mlucy Aug 16, 2016
2143e8c
style fixes
mlucy Aug 16, 2016
9dc76cf
merged
mlucy Aug 16, 2016
a35437d
style fixes
mlucy Aug 16, 2016
365896f
checkpoint
mlucy Aug 16, 2016
58cc7f3
fixed syntax
Aug 16, 2016
b10f02c
working on middleware execution
Aug 16, 2016
2651ec1
it build!
mlucy Aug 17, 2016
25b91b6
checkpoint
mlucy Aug 17, 2016
c9136c7
checkpoint
mlucy Aug 17, 2016
9425197
fixing test bugs
Aug 17, 2016
7fdb2f2
fixed more test problems
Aug 17, 2016
757fc07
fixed eslint problems
Aug 17, 2016
ea26fec
wrote broken graph code
mlucy Aug 18, 2016
1432a9e
fixed eslint errors in plugin router
Aug 18, 2016
7df9136
checkpoint
Aug 18, 2016
5748188
checkpoint
Aug 19, 2016
5094ea8
checkpoint
mlucy Aug 20, 2016
e4b93bc
fixed square brackets style
mlucy Aug 23, 2016
54ba00a
checkpoint
mlucy Aug 24, 2016
359039a
theoretically working
mlucy Aug 25, 2016
13d6109
moved logic from server to permissions plugin
Aug 25, 2016
75f96a9
moving horizon.js to index.js
Aug 25, 2016
9ef28ae
checkpoint
Aug 25, 2016
4bf76e8
camelcase changes
Aug 25, 2016
0c9f57a
checkpoint
Aug 25, 2016
b8d4a08
checkpoint
Aug 25, 2016
8a50370
cleanup of obsolete code
Aug 25, 2016
b370128
fixed server
Aug 25, 2016
82d20df
Everything works
Aug 25, 2016
c62e3e0
everything works a little more
Aug 26, 2016
386a8e3
getting stuff running
Aug 30, 2016
75cc00a
plugins almost working
Aug 31, 2016
bc7bdee
checkpoint
Aug 31, 2016
128aa95
checkpoint
Aug 31, 2016
77f3db8
working on stuff
mlucy Aug 31, 2016
7f7b975
collection broken
mlucy Sep 1, 2016
c99fd73
added stuff
mlucy Sep 1, 2016
102fdc0
fixing bugs in testing
Sep 1, 2016
b281558
reworking plugin dependencies
Sep 2, 2016
06c79d0
restructuring plugins module
Sep 2, 2016
7ce2cea
more plugins module resturcturing
Sep 2, 2016
032554a
more plugin reorganization
Sep 2, 2016
027d064
fixing eslint errors in plugins
Sep 2, 2016
26613f4
working on getting the test server running again
Sep 2, 2016
f948716
fixing es6 compat
Sep 2, 2016
12846c2
broke plugins up into separate modules
Sep 2, 2016
9cb6e71
reorganizing some plugin stuff
Sep 2, 2016
9cf5acd
added module for default plugins
Sep 2, 2016
dead3b0
working on getting dev environment easy to set up
Sep 2, 2016
7eab310
fixed up setupDev.sh to provision plugins
Sep 2, 2016
a78b0db
fixing bugs
Sep 2, 2016
1615b7a
fixed incorrect error handling in collection creation
Sep 2, 2016
43c921a
about to fix namespaces
mlucy Sep 3, 2016
f5a8415
fixed namespacing
mlucy Sep 3, 2016
a1dfb87
fixing bugs
Sep 5, 2016
16575ca
about to start moving and writing tests
Sep 5, 2016
0a26b50
stuffs
mlucy Sep 5, 2016
4a33c83
Merge branch 'next' into grey_plugins
Sep 5, 2016
2da2dc1
Merge branch 'plugins' into grey_plugins
Sep 5, 2016
7845099
migrated permissions template tests
Sep 5, 2016
ec572f1
adding source-map-support devDependency to plugins
Sep 5, 2016
3f42c9d
migrating server tests to integration tests
Sep 5, 2016
d6b196a
fix a few test bugs
Sep 7, 2016
9b1e023
added 5 sec wait for metadata to sync
Sep 7, 2016
b14fa0d
got protocol tests passing
Sep 8, 2016
03673ca
fixed collections and permissions readiness
Sep 8, 2016
890070f
fixed test create_collection
Sep 8, 2016
b4f7882
fixed some tests
Sep 8, 2016
750b95e
reworking plugin-router, added stubs for differend backend implementa…
Sep 8, 2016
02cfdb9
no longer pass server to plugins, but a curated plugin context
Sep 9, 2016
6fda005
got previously working tests working again
Sep 9, 2016
8079784
fixing problems in integration tests
Sep 9, 2016
9361715
fixed cleanup, removed old console log statements
Sep 9, 2016
06d1427
fixed some tests
Sep 9, 2016
0392e90
almost have all server tests running
Sep 10, 2016
f61425c
changed how user info is passed to validators
Sep 11, 2016
bddb240
fixed all server tests
Sep 11, 2016
dc9ef13
got test server running
Sep 11, 2016
328d124
checkpoint
Sep 13, 2016
da538ed
camelCasing and fixing tests
Sep 13, 2016
203b420
checkpoint
Sep 16, 2016
492ef1f
fixing build
Tryneus Oct 2, 2016
480da06
working on client for new protocol
Tryneus Oct 2, 2016
db8143d
checkpoint
Tryneus Oct 7, 2016
127e379
(maybe) working script for symlinking across modules in this repo
Tryneus Oct 7, 2016
7864924
fixing module symlinks and deps
Tryneus Oct 7, 2016
3ecc060
tests are running
Tryneus Oct 8, 2016
dfdae9f
server tests running
Tryneus Oct 8, 2016
7f215bd
:checkpoint
Tryneus Oct 12, 2016
0de9487
checkpoint
Tryneus Oct 13, 2016
fe2c89a
checkpoint
Tryneus Oct 15, 2016
8e8b363
lots of refactoring and style fixes
Tryneus Oct 18, 2016
85e7643
tests passing again
Tryneus Oct 20, 2016
a3c6e4d
camelcasing
Tryneus Oct 20, 2016
2430c8a
fixed some problems in client tests
Tryneus Oct 23, 2016
1c2340c
working on client socket handling
Tryneus Oct 26, 2016
b565a41
checkpoint
Tryneus Oct 27, 2016
b5d4da7
checkpoint
Tryneus Oct 27, 2016
68e7a07
fixed client reconnection logic
Tryneus Oct 27, 2016
3913388
some client tests working
Tryneus Oct 27, 2016
a8b4054
fixing tests, sort of
Tryneus Oct 28, 2016
72b1839
compatibility changes and test fixes
Tryneus Oct 29, 2016
01f0a29
checkpoint
Tryneus Dec 12, 2016
8307bcb
add server auth unit tests
Tryneus Dec 18, 2016
c303677
moving client to client_connection
Tryneus Dec 19, 2016
05d1499
add tests, fix lint errors
Tryneus Dec 19, 2016
dca7a64
add response tests
Tryneus Dec 19, 2016
e995e4b
fix flipped logic in findAll
Tryneus Dec 20, 2016
63ec280
fix find query
Tryneus Dec 20, 2016
5ffde58
fix some client tests and compatibility
Tryneus Dec 21, 2016
a63596e
fixing bugs
Tryneus Dec 23, 2016
ae85fcf
fixing tests
Tryneus Dec 23, 2016
ca16d29
fixing tests and style
Tryneus Dec 24, 2016
baeac8f
fixing tests
Tryneus Dec 24, 2016
1ddd5cf
fixing tests
Tryneus Dec 24, 2016
c3a015b
fix some tests, currentUser
Tryneus Dec 25, 2016
bdc2be5
fix some tests
Tryneus Dec 25, 2016
83d6008
fix between problems
Tryneus Dec 25, 2016
a0cce9c
all client tests passing
Tryneus Dec 25, 2016
14aa2c9
removing old dependency
Tryneus Dec 26, 2016
d5e82b4
style and cleanup
Tryneus Dec 27, 2016
a8c1564
fix some problems in examples
Tryneus Dec 28, 2016
74bc243
some router fixes
Tryneus Dec 28, 2016
aa4b826
fix some problems in the framework integrations
Tryneus Dec 29, 2016
336b5ea
change versions
Tryneus Jan 28, 2017
6e3ce54
trying to fix setupDev.sh
Tryneus Jan 29, 2017
a39c252
temporarily sequester some test code
Tryneus Jan 29, 2017
4eb7ff0
trying to fix dev setup
Tryneus Jan 29, 2017
d7e8223
more missing links
Tryneus Jan 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed some problems in client tests
  • Loading branch information
Tryneus committed Oct 23, 2016
commit 2430c8a19516804a48d08d7dba0bb775903b554d
8 changes: 4 additions & 4 deletions client/src/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export class TermBase {
}
}

export function addOption(name, isTerminal) {
if (isTerminal) {
export function addOption(name, type) {
if (type === 'terminal') {
TermBase.prototype[name] = function (...args) {
const newOptions = Object.assign({[name]: args}, this[optionsSymbol])
return new TermBase(newOptions, this[sendSymbol])
return this[sendSymbol](newOptions)
}
} else {
TermBase.prototype[name] = function (...args) {
const newOptions = Object.assign({[name]: args}, this[optionsSymbol])
return this[sendSymbol](newOptions)
return new TermBase(newOptions, this[sendSymbol])
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions client/src/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class HorizonSocket extends WebSocketSubject {

this.keepalive = Observable
.timer(keepalive * 1000, keepalive * 1000)
.map(n => this.makeRequest({ type: 'keepalive' }).subscribe())
.map(n => this.makeRequest(null, 'keepalive').subscribe())
.publish()

// This is used to emit status changes that others can hook into.
Expand Down Expand Up @@ -151,7 +151,8 @@ export class HorizonSocket extends WebSocketSubject {
// * Send `end_subscription` when observable is unsubscribed
makeRequest(options, type) {
const requestId = this.requestCounter++
const req = {message: {requestId, options}, data: {}}
const req = {message: {requestId}, data: {}}
if (options) { req.message.options = options }
if (type) { req.message.type = type }

return super.multiplex(
Expand All @@ -174,9 +175,9 @@ export class HorizonSocket extends WebSocketSubject {
// * Completes when `state: complete` is received
// * Reference counts subscriptions
hzRequest(options) {
const end = AsyncSubject()
const end = new AsyncSubject()
return this.sendHandshake().ignoreElements()
.concat(this.makeRequest(rawRequest))
.concat(this.makeRequest(options))
.concatMap((response) => {
if (response.error) {
throw new Error(response.error)
Expand Down
2 changes: 1 addition & 1 deletion client/test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<link href="mocha.css" rel="stylesheet"/>
<script src="horizon.js"></script>
<script src="/horizon/horizon.js"></script>
</head>
<body>

Expand Down
20 changes: 12 additions & 8 deletions server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ const clientSourceMap = lazyLoadSource(`${clientSourcePath}.map`);
const clientSourceCore = lazyLoadSource(clientSourceCorePath);
const clientSourceCoreMap = lazyLoadSource(`${clientSourceCorePath}.map`);

function makeCapabilitiesCode(capabilities) {
return `
;{
let capabilities = ${JSON.stringify(capabilities)};
Object.keys(capabilities).forEach(function (key) {
Horizon.addOption(key, capabilities[key].type);
});
};`;
}

class Server {
constructor(httpServers, options) {
this.events = new EventEmitter();
Expand Down Expand Up @@ -263,21 +273,15 @@ class Server {
if (!this._capabilities) {
this._capabilities = {};
for (const key in this._methods) {
this._capabilities[key] = {type: this._methods[key]};
this._capabilities[key] = {type: this._methods[key].type};
}
}
return this._capabilities;
}

applyCapabilitiesCode() {
if (!this._applyCapabilitiesCode) {
this._applyCapabilitiesCode =
`;{
let capabilities = ${JSON.stringify(this.capabilities())};
Object.keys(capabilities).forEach(function (key) {
Horizon.addOption(key, capabilities[key].type);
});
};`;
this._applyCapabilitiesCode = makeCapabilitiesCode(this.capabilities());
}
return this._applyCapabilitiesCode;
}
Expand Down
89 changes: 51 additions & 38 deletions test/src/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const crypto = require('crypto');
const argparse = require('argparse');

const dataDir = path.resolve(__dirname, 'rethinkdb_data_test');
const testDistDir = path.resolve(__dirname, '../../client/dist');
const examplesDir = path.resolve(__dirname, '../../examples');
const rootDir = path.resolve(__dirname, '../..');
const clientDistDir = path.resolve(rootDir, 'client/dist');

const parser = new argparse.ArgumentParser();
parser.addArgument(['--port', '-p'],
Expand All @@ -53,37 +53,41 @@ if (options.bind.indexOf('all') !== -1) { options.bind = ['0.0.0.0']; }
process.on('SIGINT', () => process.exit(0));
process.on('SIGTERM', () => process.exit(0));

const serveFile = (filePath, res) => {
fs.access(filePath, fs.R_OK | fs.F_OK, (exists) => {
if (exists) {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.end(`File "${filePath}" not found\n`);
function readFile(filePath) {
return new Promise((resolve, reject) =>
fs.access(filePath, fs.R_OK | fs.F_OK, (exists) => {
if (exists) {
reject(new Error(`File "${filePath}" not found.`));
} else {
fs.readFile(filePath, 'binary',
(err, file) => (err ? reject(err) : resolve(file)));
}
})
);
}

function serveFile(filePath, res) {
console.log(`serving file ${filePath}`);
readFile(filePath).then((data) => {
if (filePath.endsWith('.js')) {
res.writeHead(200, {'Content-Type': 'application/javascript'});
} else if (filePath.endsWith('.html')) {
res.writeHead(200, {'Content-Type': 'text/html'});
} else {
fs.readFile(filePath, 'binary', (err, file) => {
if (err) {
res.writeHead(500, {'Content-Type': 'text/plain'});
res.end(`${err}\n`);
} else {
if (filePath.endsWith('.js')) {
res.writeHead(200, {'Content-Type': 'application/javascript'});
} else if (filePath.endsWith('.html')) {
res.writeHead(200, {'Content-Type': 'text/html'});
} else {
res.writeHead(200);
}
res.end(file, 'binary');
}
});
res.writeHead(200);
}
res.end(data, 'binary');
}).catch((err) => {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.end(`${err}\n`);
});
};

// On Windows, `npm` is actually `npm.cmd`
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';

// Run the client build
const buildProc = child_process.spawn(npmCmd, ['run', 'dev'],
{cwd: testDistDir});
const buildProc = child_process.spawn(npmCmd, ['run', 'dev'], {cwd: clientDistDir});

buildProc.on('exit', () => process.exit(1));
process.on('exit', () => buildProc.kill('SIGTERM'));
Expand Down Expand Up @@ -118,18 +122,13 @@ buildProc.stderr.on('data', (data) => {
// Launch HTTP server with horizon that will serve the test files
const httpServers = options.bind.map((host) =>
new http.Server((req, res) => {
const reqPath = url.parse(req.url).pathname;
if (reqPath.indexOf('/examples/') === 0) {
serveFile(path.resolve(examplesDir,
reqPath.replace(/^[/]examples[/]/, '')), res);
const reqPath = url.parse(req.url).pathname.replace(/^\//, '');
console.log(`request with path ${reqPath}`);
if (reqPath === 'test' || reqPath === 'test/') {
res.writeHead(302, {Location: '/client/dist/test.html'});
res.end();
} else {
if (!clientReady) {
res.writeHead(503, {'Content-Type': 'text/plain'});
res.end('Initial client build is ongoing, try again in a few seconds.');
} else {
serveFile(path.resolve(testDistDir,
reqPath.replace(/^[/]/, '')), res);
}
serveFile(path.resolve(rootDir, reqPath), res);
}
}));

Expand Down Expand Up @@ -195,9 +194,23 @@ Promise.all(
serv.removeAllListeners('request');
serv.on('request', (req, res) => {
const reqPath = url.parse(req.url).pathname;
if (reqPath === '/horizon/horizon.js' ||
reqPath === '/horizon/horizon.js.map') {
serveFile(path.resolve(testDistDir, reqPath.replace('/horizon/', '')), res);
console.log(`Serving path ${reqPath}`);
if (reqPath.match(/^\/horizon\/[^\/]+\.js$/)) {
console.log(`Serving modified code`);
if (!clientReady) {
res.writeHead(503, {'Content-Type': 'text/plain'});
res.end('Initial client build is ongoing, try again in a few seconds.\n');
} else {
readFile(path.resolve(clientDistDir, reqPath.replace('/horizon/', ''))).then((data) => {
res.writeHead(200, {'Content-Type': 'application/javascript'});
res.end(data + hzRouter.server.applyCapabilitiesCode(), 'binary');
}).catch((err) => {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.end(`${err}\n`);
});
}
} else if (reqPath.match(/^\/horizon\/[^\/]+\.js\.map$/)) {
serveFile(path.resolve(clientDistDir, reqPath.replace('/horizon/', '')), res);
} else {
extantListeners.forEach((l) => l.call(serv, req, res));
}
Expand Down