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

Version bump, rename test script #7

Open
wants to merge 83 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
a14de0c
Version bump, rename test script
myw Jun 21, 2016
18f9e05
Merge branch 'v2' of github.com:benjiec/curious-js into curious-2.0
myw Jun 21, 2016
cc4a12c
Refactor how wrappers work
myw Jun 23, 2016
ca49042
Bump version to 2.1.0
myw Jun 23, 2016
79c650e
Add wrapper for Polymer's `iron-request` object and options
myw Jun 29, 2016
d21ad43
Bump version to 2.1.1
myw Jun 29, 2016
d5f5d8a
Add detailed README documentation
myw Jun 29, 2016
b5fd7a1
Add documentation release script
myw Jun 29, 2016
6fb341b
Fix improperly named property for ironRequest wrapper
myw Jun 30, 2016
d92bbe7
Bump version to 2.1.2
myw Jun 30, 2016
41ff953
Work around a bug with ironRequest
myw Jun 30, 2016
7aa3c44
Bump version to 2.1.3
myw Jun 30, 2016
b502494
Use automatic detection of content type from the headers
myw Jul 1, 2016
a53f761
Rewrite polymer wrapper to use `iron-ajax` instead of `iron-request`
myw Jul 1, 2016
719acd6
Parse out the response from the resolved ironRequest promise
myw Jul 1, 2016
33f2104
Bump version to 2.1.4
myw Jul 1, 2016
ccb7e70
Fix minor eslint tweaks
myw Jul 1, 2016
f216634
Add a camelCase function and tests for it
myw Jul 2, 2016
0becfb8
Fix indentation/eslint issues in tests/examples
myw Jul 2, 2016
cd4fe7b
Fix indentation/eslint issues in tests/curious_client
myw Jul 2, 2016
98bd359
Fix indentation/eslint issues in tests/curious_query
myw Jul 2, 2016
bd6b7ba
Add a camelCase option and incorporate it into object construction
myw Jul 2, 2016
cf0ec55
Bump version to 2.2.0
myw Jul 2, 2016
4f8ef42
Remove line breaks from the query string
myw Jul 2, 2016
1657c62
Add JSON serialization functionality
myw Sep 19, 2016
77c4151
Only create object data for actual Objects passed in
myw Sep 19, 2016
a16758f
Fix minor consistency issues in JSDoc
myw Sep 19, 2016
124fcef
Bump version to 2.2.1
myw Sep 19, 2016
6a5e86d
Make minor improvements to the release_doc script
myw Sep 20, 2016
37f03b9
Move scripts to scripts/ folder
myw Sep 20, 2016
17ea2ae
Ignore unnecessary files in each package
myw Sep 20, 2016
5e513a8
Add cleaning step to doc script
myw Sep 20, 2016
00020af
Clean up types and labels for documentation
myw Sep 20, 2016
317028d
Bump version to 2.2.2
myw Sep 20, 2016
ded22c7
Fix bower.json and package.json files
myw Sep 20, 2016
34448ea
Bump version to 2.2.3
myw Sep 20, 2016
a5e7f1f
Add toString method for CuriousQuery objects
myw Sep 21, 2016
6c09585
Update minor documentation improvements
myw Sep 21, 2016
7dcaf83
Add valueOf and toJSON methods to CuriousQuery
myw Sep 22, 2016
99a7da5
Provide detailed documentation on the nature of data returned by the …
myw Sep 22, 2016
ed32c51
Add .then and .catch methods to CuriousQuery objects
myw Sep 22, 2016
b3f4627
Bump version to 2.3.0
myw Sep 22, 2016
63d065b
Name anonymous functions and fix types in documentation
myw Sep 30, 2016
fc41cd1
Add Docker setup
myw Sep 30, 2016
7ca9ded
Update README
myw Sep 30, 2016
e1fe95f
Bump version to 2.3.1
myw Sep 30, 2016
2b8cb5a
Rename CURIOUS_URL to URL, since this is just an arbitrary server
myw Nov 29, 2016
b0dd6b4
Fix typo
myw Nov 29, 2016
490063c
Add eslint to tests
myw Nov 30, 2016
5bab89a
Change make_doc script to be more compatible
myw Nov 30, 2016
c6652a0
Add lint script
myw Nov 30, 2016
d98e047
Add query URL resolution function
myw Nov 30, 2016
775736a
Include .eslintrc.yaml in the Docker image
myw Nov 30, 2016
d73bc68
Update README to reflect changes
myw Nov 30, 2016
e1edef8
Add Travis CI support
myw Dec 1, 2016
cbcb0b0
Update build badge in README
myw Dec 1, 2016
8466cc2
Merge pull request #1 from ginkgobioworks/resolve-url-convention
myw Dec 1, 2016
df158ca
Bump version to 2.4.0
myw Dec 1, 2016
20c413f
Bind the post method of axios.
koreiklein Dec 8, 2016
3eae6d8
Check whether to call bind more carefully.
koreiklein Dec 8, 2016
8411de3
Merge pull request #2 from koreiklein/feature/kk/bind-axios
myw Dec 8, 2016
a14141f
Add NPM deployment to TravisCI setup
myw Dec 10, 2016
744ccf9
Remove version field from bower.json, since it is now deprecated
myw Dec 10, 2016
f59fd9c
Bump version to 2.4.1
myw Dec 10, 2016
97ab94a
Update and fix bower/npm ignore globs
myw Dec 10, 2016
1f8ff00
Bump version to 2.4.2
myw Dec 10, 2016
90d06a8
Clean up JSDoc
myw Dec 10, 2016
dacf213
Document CI setup
myw Dec 10, 2016
d800f28
Clean up scripts
myw Dec 10, 2016
c09258e
Improve README
myw Dec 10, 2016
ea81476
Add default messge for version bumps
myw Dec 10, 2016
8cc3c87
Bump version to 2.4.3
myw Dec 10, 2016
d92b7a5
Fix query cleanup
myw Feb 7, 2017
9fb9fe1
Merge pull request #5 from ginkgobioworks/bug/remove-line-breaks
myw Feb 7, 2017
c0cd8b0
Bump version to 2.4.4
myw Feb 7, 2017
90c4209
Fix query trimming
myw Feb 7, 2017
da20d22
Bump version to 2.4.5
myw Feb 7, 2017
bc5256a
Remove AMD label from 'define'
myw Apr 6, 2017
4976245
Merge pull request #6 from ginkgobioworks/fix/remove-amd-name
myw Apr 6, 2017
e8203b4
Bump version to 2.4.6
myw Apr 6, 2017
25bb27e
Remove 'method' JSDoc tags for with, catch
myw Oct 25, 2017
28da06e
Upgrade dev deps and add package-lock.json
myw Oct 25, 2017
1473116
Merge pull request #8 from ginkgobioworks/fix-doc
myw Oct 25, 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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*/.git*
**/*.zip
.tmp
doc
node_modules
bower_components
15 changes: 15 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
# vim: ft=yaml sw=2 ts=2 sts=2
extends: "eslint-config-airbnb-es5"
rules:
comma-dangle:
- "warn"
- "always-multiline"
func-names: "off"
no-spaced-func: "warn"
space-before-function-paren:
- "warn"
- anonymous: "always"
named: "never"
no-underscore-dangle: "off"
...
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.*
Dockerfile
bower.json
bower_components
docker-compose.yml
node_modules
scripts
tests
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message=Bump version to %s
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: node_js
node_js:
- node
cache:
directories:
- node_modules
deploy:
provider: npm
email: [email protected]
api_key:
secure: RaHu9nAQUkPyp6LZ2mEvD5zbdXeHIZrP20iTT4N5kl3kB8BmXQBVphJ4rkcmdRYT13JZIlXzIvqWE8QdK+PmapOIWaGJ4t5XQ0Hjrqm5iUutDzvkypKBl6R44SlhIAp4KwWbEHeDkVZnhHZFirhgJMADbROBvBxTYAORab2zMmWWP1QbtLNjZ0RA1GPfM4KA+XVQsNwKTvlVZDQN8pptVsxfLI+MpDkGiZbq2zs0m5MUzMRVit2yN+HbSKCZRNU46cVFkA0SaDKTShHbydFvFLCgIQrOei+GzLu0PQXyjFLyz+lgkEdRgEp6bjC+ZrpU3vDKMnzo0pucpa8LTfUFxua/OLV6MVBcjB6/BeifMyd9R9yDfZcxlePSwyiiwWdR79bWnQckrN+jf5RaUk03GVmn6oo2zXK8kFZKIQw9rYfBKyisN5I9apqEyOmGQU7Uk6oqcUU8rYAsSp+8FQ9pcPXd2PXj9HkjzakGPWutHlb+5EKRy2pjX/G2EuJUhVzs4f3TPuAEfNnG/mz5TaMU7T1XpaZ0NQ5yTgr0NRNt2lgLV5Zej6sqkE3evMEGwtC1GSkbWO3kaigBVDi3Ys09fOUzRBZebaO63exzwqVKA15D4gAsaNoReh9eelhOix4PYvlnb4huxgy1Jf5SuNSjHblAm8I2UoTAl4MRle940fQ=
on:
tags: true
repo: ginkgobioworks/curious-js
branch: v2
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM node:latest

MAINTAINER Misha Wolfson <[email protected]>

# Last update, to invalidate cache if needed
ENV LAST_UPDATE 2016-09-30

ENV CURIOUS_JS_DIR /usr/src/curious-js
WORKDIR $CURIOUS_JS_DIR

COPY package.json .
RUN npm install

COPY curious.js .
COPY scripts ./scripts
COPY tests ./tests

# Development files
COPY .eslintrc.yaml .

ENTRYPOINT ["npm", "run"]
CMD ["test"]
297 changes: 296 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,296 @@
Javascript consumer for Curious API outputs.
# curious-js

JavaScript consumer code for Curious APIs.

[![Build Status](https://travis-ci.org/ginkgobioworks/curious-js.svg?branch=v2)](https://travis-ci.org/ginkgobioworks/curious-js)

## Usage

### Installation

`curious-js` is available both from [bower](https://bower.io/search/?q=curious-js) and from
[npm](https://www.npmjs.com/package/curious-js).

### Importing

`curious-js` has been written using the [UMD](https://github.com/umdjs/umd) module pattern. This
pattern should be compatible with AMD/require.js, CommonJS/node.js, direct loading in the browser,
and Babel module variants. Requiring or loading the `curious.js` file will create a module (with the
default name `curious`) in whatever system you are using.

### Using

There are two main parts to using Curious from JavaScript: `CuriousClient` and `CuriousQuery`.

First, create an instance of `CuriousClient` that points to your Curious server, providing a
server URL and a request function.

_The server URL provided to the client should point to the Curious root endpoint, **not** to the
query endpoint (`/q/`) on the server_. The code will not break if you make this mistake, but the
behavior is deprecated.

You must also provide a request method. You are responsible for picking and using a request
method/transport layer that works for you. `CuriousClient` provides convenience wrappers for
common request methods, but you can make any asynchronous transport layer work by passing a custom
function as the second parameter to the client constructor. The function must take the URL as its
first parameter and an object payload as its second parameter, make a `POST` request to the curious
server, and return a Promise (or any thenable) that resolves to the JSON data returned by the
server. Note that if you're using jQuery, `jQuery.post` does not require any wrapping and can be
passed as the second parameter directly.

```javascript
// Example using Axios
var curiousClient = new curious.CuriousClient(CURIOUS_URL, curious.CuriousClient.wrappers.axios(axios), ...);

// Example using a custom request method
var curiousClient = new curious.CuriousClient(CURIOUS_URL, function (url, data) {
return new Promise(function (resolve, reject) {
var result;
var error;

// Perform some asynchronous access

if (error) {
reject(error);
} else {
resolve(result);
}
});
}, ...);
```

Then, construct a `CuriousQuery` and perform it on the server using the client. Attach any callbacks
to the Promise object returned by the `perform` method, or directly to the query object. They will
be executed in the order they were attached, before any callbacks attached later. The results of the
query will be passed to the first callback.

Here's a trivial example. The results, of course, depend on the schema on the Curious server; the
example uses a made up schema consiting of Document and Section entities in a 1:many relationship.

```javascript
// A simple node.js use case; works similarly on the front end, minus module loading

const util = require('util');
const axios = require('axios');
const curious = require('curious');

// Define a client to connect to a curious server
const client = new curious.CuriousClient(
'http://your-curious.com',
curious.CuriousClient.wrappers.axios(axios),
null, // serverArgs
true, // quiet
true // camelCase
);

// The schema here is a simple 1:many relationship

// Make a query
const q = new curious.CuriousQuery('Document(id=12345)', 'documents')
.follow('Document.section_set', 'sections');

// Perform that query with the client
q.perform(client).then((data) => {

// In the callback, examine the resulting data
try {
console.log('data:');
console.log(data);

console.log('data.objects:');
console.log(data.objects);

console.log('data.objects.documents:');
console.log(data.objects.documents);

console.log('data.objects.documents[0].sections:');
console.log(data.objects.documents[0].sections);

console.log('data.objects.documents[0].sections[0].documents[0]:');
console.log(data.objects.documents[0].sections[0].documents[0]);

console.log('data.objects.sections:');
console.log(data.objects.sections);

console.log('data.objects.sections[0].documents:');
console.log(data.objects.sections[0].documents);

console.log('data.objects.sections[0].documents[0].sections[0]:');
console.log(data.objects.sections[0].documents[0].sections[0]);
} catch (e) {
console.error(e);
}

return data;
}, console.error);
```

The output from the example code above would look something like this, depending on the data:
```javascript
data:
{ objects: { documents: [ [Object] ], sections: [ [Object], [Object] ] },
trees: [ null, null ] }

data.objects:
{ documents:
[ CuriousObject {
__url: 'http://your-curious.com/document/12345',
__model: 'Document',
id: 12345,
...
sections: [Object] } ],
sections:
[ CuriousObject {
__url: null,
__model: 'Section',
id: 12205,
documentId: 12345,
...
documents: [Object] },
CuriousObject {
__url: null,
__model: 'Section',
id: 112403,
documentId: 12345,
...
documents: [Object] } ] }

data.objects.documents:
[ CuriousObject {
__url: 'http://your-curious.com/document/12345',
__model: 'Document',
id: 12345,
...
sections: [ [Object], [Object] ] } ]

data.objects.documents[0].sections:
[ CuriousObject {
__url: null,
__model: 'Section',
id: 12205,
documentId: 12345,
...
documents: [ [Object] ] },
CuriousObject {
__url: null,
__model: 'Section',
id: 112403,
documentId: 12345,
...
documents: [ [Object] ] } ]

data.objects.documents[0].sections[0].documents[0]:
CuriousObject {
__url: 'http://your-curious.com/document/12345',
__model: 'Document',
id: 12345,
...
sections:
[ CuriousObject {
__url: null,
__model: 'Section',
id: 12205,
documentId: 12345,
...
documents: [Object] },
CuriousObject {
__url: null,
__model: 'Section',
id: 112403,
documentId: 12345,
...
documents: [Object] } ] }

data.objects.sections:
[ CuriousObject {
__url: null,
__model: 'Section',
id: 12205,
documentId: 12345,
...
documents: [ [Object] ] },
CuriousObject {
__url: null,
__model: 'Section',
id: 112403,
documentId: 12345,
...
documents: [ [Object] ] } ]

data.objects.sections[0].documents:
[ CuriousObject {
__url: 'http://your-curious.com/document/12345',
__model: 'Document',
id: 12345,
...
sections: [ [Object], [Object] ] } ]

data.objects.sections[0].documents[0].sections[0]:
CuriousObject {
__url: null,
__model: 'Section',
id: 12205,
documentId: 12345,
...
documents:
[ CuriousObject {
__url: 'http://your-curious.com/document/12345',
__model: 'Document',
id: 12345,
...
sections: [Object] } ] }
```

The API is explained in detail in the documentation.

## Development

Development is carried out through an included Docker environment and Travis CI.


### Gotchas

For historic reasons, since some repos still need to use Curious v 1.0, the `master` branch still
points there, and the current version, the _default_ branch, points to `v2`. Eventually this will be
resolved.

### CI build and deployment

Continuous integration is performed with [Travis CI](https://travis-ci.org/ginkgobioworks/curious-js).
Any tagged commits on the main branch (v2), update bower by default and are automatically deployed to
NPM through the CI `deploy` task.

To deploy the code:

1. Get on the default branch `git checkout v2` [*not master*]
2. Bump the version: `npm version [type]`
3. Push to the origin with tags: `git push && git push --tags`

### Docker

The project also provides a Dockerfile that builds a container capable of running the unit tests and
scripts. To run the tests, bring up the container with `docker-compose up`. Any of the scripts shown
to be run below from a shell with `npm run` can be executed in an instance of the container with
`docker-compose run --rm [script name]`.

### REPL

A script that opens up a node.js REPL and loads curious.js as `curious` is available via
`npm run repl`.

### Test framework

The tests are written in [mocha](https://mochajs.org/), with [chai](http://chaijs.com/) expect-style
assertions. Tests can be run with `npm test`.

Coding conventions and linting are enforced at the unit test level but can also be run independently
with `npm run lint`.

### Documentation

Any new code added to `curious.js` must be documented in a manner consistent with existing
documentation.

JSDoc documentation can be generated into the `doc/` subdirectory from the source code and README
with `npm run make_doc`. It can be updated on the project website automatically with `npm run
release_doc`.
Loading