Client has only been tested with Node v14.15.1 and Typescript 3.9.7
npm install @quantleaf/query-sdk-node
In your tsconfig.json file put following properties
...
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
...
This library uses decorators to provide information about fields, hence these settings are necessary.
Obtain an API key at the account page (free if you create an account).
import {ClassInfo, FieldInfo, translate, config} from '@quantleaf/query-sdk-node';
import {StandardDomain} from '@quantleaf/query-schema';
There are two decorators you have to use to describe the database schema, ClassInfo and FieldInfo
Key from class name, one description in 'ANY' language
@ClassInfo('My class')
class MyClass
{
...
Describing the class with ClassInfo
Key from class name, multiple descriptions in 'ANY' language
@ClassInfo(['My class','Min klass'])
class MyClass
{
...
Describing the class with ClassInfo When describing fields we have to provide at most 3 things.
key, can be assumed from the class name.
description, the description of the class.
Key from class name, multiple descriptions in multiple languages
@ClassInfo(
{
SV: ['Min klass']
EN: ['My class']
}
)
class MyClass
{
...
Custom key and and multiple descriptions in multiple languages
@ClassInfo(
{
key: 'Custom key',
description: {
SV: ['Min klass']
EN: ['Min klass']
}
}
)
class MyClass
{
...
When describing fields we have to provide at most 3 things.
key, can be assumed from the field name.
domain, can be assumed from the field type. If you want to use an EnumDomain, you have to provide this. More information about the domains are found in the API documentation.
description, the description of the field. Follows the same format as for the description from ClassInfo decorator.
Key from field name, type from field value type, single description in 'ANY' language
@FieldInfo('price')
price: number;
Key from field name, type from field value type, multiple descriptions in 'ANY' language
@FieldInfo(['price','pris'])
price: number;
Key from field name, type from field value type, multiple descriptions in multiple languages.
@FieldInfo({
SV: 'pris',
EN: ['price','cost']
})
price: number;
Custom key and custom EnumDomain type with multiple descriptions in multiple languages.
@FieldInfo({
key: 'from_city',
description: {
SV: 'från',
EN: ['from','departure location']
},
domain: {
LONDON: 'London',
COPENHAGEN : {
SV: 'Köpenhamn',
EN: 'Copenhagen'
}
}
})
fromCity: string
Authorize yourself with the config function (once).
config(API_KEY);
Assume that we have decorated a class named Ticket
const response = translate(
'Some query',
[new Ticket()],
{
query: {},
suggest: {}
});
response will be a promise. The response is explained in detail in the end of the API documentation.
The request above will both request a translated query and suggestions.
Create an issue!