@spinque/query-api
Advanced tools
Comparing version 0.10.1 to 0.10.2
{ | ||
"name": "@spinque/query-api", | ||
"version": "0.10.1", | ||
"version": "0.10.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -24,3 +24,3 @@ # @spinque/query-api | ||
This documents the code exported by this library. For documentation on the Spinque Query API itself, please see [this](https://docs.spinque.com/3.0/using-apis/basic.html). | ||
For documentation on the Spinque Query API itself, please see [this](https://docs.spinque.com/3.0/using-apis/basic.html). | ||
@@ -44,3 +44,3 @@ ## Usage | ||
Fetching results for a single query using an instance of the Api class: | ||
Fetching results for a single query using an instance of the Api class and its `fetch` method: | ||
@@ -50,2 +50,3 @@ ```typescript | ||
// Configure the API with workspace, configuration and API name | ||
const api = new Api({ | ||
@@ -57,2 +58,3 @@ workspace: 'my-workspace', | ||
// Construct the query to fetch results for | ||
const query: Query = { | ||
@@ -64,2 +66,3 @@ endpoint: 'movie_search', | ||
try { | ||
// Fetch the 10 first results of the query | ||
const response = await api.fetch(query, { count: 10 }); | ||
@@ -90,2 +93,4 @@ } catch (error: any) { | ||
const url = urlFromQueries(apiConfig, query, { count: 10, offset: 0 }); | ||
// Make the request here using `url` | ||
``` | ||
@@ -150,2 +155,18 @@ | ||
### Utility functions | ||
Many utility functions are available for import under `@spinque/query-api/utils`. | ||
* `urlFromQueries`, takes an ApiConfig object and an array of Query objects and returns a Spinque Query API request URL. | ||
* `pathFromQuery`, takes a single Query and returns the path of its Spinque Query API URL. | ||
* `pathFromQueries`, takes an array of Query objects and returns the path of their Spinque Query API URL. | ||
* `join`, joints together URL parts into a valid URL. | ||
* `stringifyQueries`, takes an array of Query objects and returns a string representation that can be used to e.g. store in the address baer. | ||
* `parseQueries`, takes a string from `stringifyQueries` and tries to parse it into an array of Query objects. | ||
* `stringToTupleList`, given a string, try to parse it as a tuple list (array of arrays of numbers or strings, and array of scores). | ||
* `tupleListToString`, given a tuple list, return a string representation. | ||
* `ensureTupleList`, takes a value (string, number, array of strings or numbers, or array of arrays of strings or numbers) and normalizes it into a tuple list. | ||
See the [documentation](https://spinque.github.io/query-api-ts/) for a complete list. | ||
### Faceted search | ||
@@ -156,3 +177,3 @@ | ||
The following example shows how a search endpoint 'movie_search' can be used in combination with a facet endpoint 'genre'. | ||
The following example shows how a search endpoint 'movie_search' can be used in combination with facet endpoints 'genre' and 'director'. | ||
@@ -185,7 +206,7 @@ ```typescript | ||
// Select a facet option | ||
// Select some facet options | ||
fs.setFacetSelection('genre', ['https://imdb.com/data/Drama', 'https://imdb.com/data/Biography']); | ||
fs.setFacetSelection('director', 'https://imdb.com/data/PabloLarrain'); | ||
// Get results again | ||
// Get results again, now with facets applied | ||
results = await api.fetch(fs.getResultsQuery()); | ||
@@ -192,0 +213,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98744
327