Class: CuriousClient

curious.CuriousClient(curiousUrlnon-null, request, clientDefaultArgsopt, quietopt, camelCaseopt) → {CuriousClient}

new CuriousClient(curiousUrlnon-null, request, clientDefaultArgsopt, quietopt, camelCaseopt) → {CuriousClient}

Tool for making a curious query and returning parsed objects
Parameters:
Name Type Attributes Description
curiousUrl string

The URL of the Curious server. The query is sent to curiousUrl + '/q/'.

XXX: For compatability with legacy clients, the /q/ is not added if curiousUrl has a 'q' as its last path element. However, new code should not rely on this behavior.

request function

A function that makes a POST request and returns a Promise (a thenable)--examples are jQuery.post, axios.post, and Angular's $http.post.

Any function that meets the signature, makes a POST request and returns a thenable that resolves to the parsed JSON of the curious server's response will work. Note that axios.post and $http.post wrap the response in an object, and so require wrapper functions to be used. See module:curious.CuriousClient.wrappers for the wrappers.

clientDefaultArgs Object <optional>
Default parameters to send to the serever with every query performed by this client--see module:curious.CuriousClient#performQuery for an explanation of what each parameter means.
quiet boolean <optional>
Unless true, log every query to the console.
camelCase boolean <optional>
If true, construct camel-cased versions of the JSON objects returned by the Curious server.
Source:
Returns:
A client object with a single performQuery method
Type
CuriousClient

Namespaces

wrappers

Methods

(static) performQuery(qnon-null, relationshipsnon-null, constructorsnullable, paramsopt, nullable, existingObjectsopt) → {Promise.<{objects: Array, trees: Array.<?Object>}>}

Perform a Curious query and return back parsed objects.
Parameters:
Name Type Attributes Description
q string The query string
relationships Array.<string> The names of relationships between each joined set of objects
constructors Array.<?function(Object)> <nullable>
An array of constructors for any custom classes, or null for the default
params Object <optional>
<nullable>
Query-specific parameters for the request
Properties
Name Type Attributes Description
x boolean <optional>
Whether or not to ignore excludes; defaults to false
c boolean <optional>
Whether or not to just do a check of the query syntax; defaults to false
d boolean <optional>
Whether or not return the object data, or just return ids; always forced to be true for the JavaScript client
fk boolean <optional>
Whether or not follow foreign keys: if false, foregin keys will be IDs, as expecte. If true, foreign keys will be 4-member arrays that include the ID, name, and URL of the object being pointed to. Defaults to false.
r boolean <optional>
If true, force a refresh of the data not from cache; defaults to false.
fc boolean <optional>
If true, force using the cached data; defaults to false.
app string <optional>
If provided, the name of the app, to use for cache key construction.
existingObjects Array.<Array.<Object>> <optional>
Objects that already exist to be linked into the results returned by this query
Source:
Returns:
A promise that resolves to an object containing the objects requested by the query and a tree structure that relates IDs for recursive queries
Type
Promise.<{objects: Array, trees: Array.<?Object>}>
Example
// Here's a many-to-many example
client.performQuery(
  'Document(id__in=[1,2]) ?(Document.entities)',
  ['documents', 'entities'],
).then(function (results) {

  console.log(results.objects.documents);
  // Will show an array of documents, as CuriousObject instances:
  // [
  //   CuriousObject({
  //      __model: 'Document',
  //      __url: 'http://somewhere/document/1',
  //      id: 1,
  //      entities: [
  //        // entities associated with document 1
  //      ]
  //      ... other fields of Document objects ...
  //   }),
  //  CuriousObject({
  //      __model: 'Document',
  //      __url: 'http://somewhere/document/2',
  //      id: 2,
  //      entities: [
  //        // entities associated with document 2
  //      ]
  //      ...
  //   }),
  // ]

  console.log(results.objects.entities);
  // Will show an array of entities, as CuriousObject instances:
  // [
  //   CuriousObject({
  //      __model: 'Entity',
  //      __url: 'http://somewhere/entity/1',
  //      id: 2348,
  //      documents: [
  //        // documents associated with entity 1
  //      ]
  //      ... other fields of Entity objects ...
  //   }),
  //  CuriousObject({
  //      __model: 'Entity',
  //      __url: 'http://somewhere/entity/2',
  //      id: 2725,
  //      documents: [
  //        // documents associated with entity 2
  //      ]
  //      ...
  //   }),
  // ]
});