feat: add core

This commit is contained in:
Karl-Philipp Wulfert
2018-11-29 16:22:57 +01:00
commit 2d770dde44
131 changed files with 41268 additions and 0 deletions

View File

@@ -0,0 +1,150 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ValidationError} from 'jsonschema';
/**
* A generic error that can be returned by the backend if somethings fails during the processing of a request
*/
export interface SCErrorResponse extends Error {
/**
* Additional data that describes the error
*/
additionalData?: any;
/**
* HTTP status code to return this error with
*/
statusCode: number;
}
/**
* An error that can be created by the backend during the processing of a request
*/
export abstract class SCError implements SCErrorResponse {
/**
* Call stack of the error
*/
stack?: string;
/**
* Instatiate an SCError
* @param name Name of the error
* @param message Message of the error
* @param statusCode HTTP status code to return this error with
* @param stack Set to true if a stack trace should be created
*/
constructor(public name: string, public message: string, public statusCode: number, stack?: boolean) {
// generate stacktrace if needed
if (stack) {
this.stack = (new Error()).stack;
}
}
}
/**
* An error that is returned when the validation of a request fails
*/
export class SCValidationErrorResponse extends SCError {
/**
* List of validatation errors
*/
additionalData: ValidationError[];
/**
* Create a SCValidationErrorResponse
* @param errors List of validation errors
* @param stack Set to true if a stack trace should be created
*/
constructor(errors: ValidationError[], stack?: boolean) {
super('ValidationError', 'Validation of request failed', 400, stack);
this.additionalData = errors;
}
}
/**
* An error that is returned when the content type of the request is not supported
*/
export class SCUnsupportedMediaTypeErrorResponse extends SCError {
/**
* Create a SCUnsupportedMediaTypeErrorResponse
* @param stack Set to true if a stack trace should be created
*/
constructor(stack?: boolean) {
super('UnsupportedMediaTypeError', 'Unsupported media type', 415, stack);
}
}
/**
* An error that is returned, when the used HTTP method is not allowed on the requested route
*/
export class SCMethodNotAllowedErrorResponse extends SCError {
/**
* Create a SCMethodNotAllowedErrorResponse
* @param stack Set to true if a stack trace should be created
*/
constructor(stack?: boolean) {
super('MethodNotAllowedError', 'HTTP method is not allowed on this route', 405, stack);
}
}
/**
* An error that is returned, when to many request are submitted at once
*/
export class SCTooManyRequestsErrorResponse extends SCError {
/**
* Create a SCTooManyRequestsErrorResponse
* @param stack Set to true if a stack trace should be created
*/
constructor(stack?: boolean) {
super('TooManyRequestsError', 'Too many requests. You can not submit more than 5 queries an once', 429, stack);
}
}
/**
* An error that is returned when the requested route or resource was not found
*/
export class SCNotFoundErrorResponse extends SCError {
/**
* Create a SCNotFoundErrorResponse
* @param stack Set to true if a stack trace should be created
*/
constructor(stack?: boolean) {
super('NotFoundError', 'Resource not found', 404, stack);
}
}
/**
* An error that is returned, when an internal server error occured
*/
export class SCInternalServerErrorResponse extends SCError {
/**
* Internal error that occured. If the stack is disabled this error is not set for security reasons
*/
additionalData?: Error;
/**
* Create a SCInternalServerErrorResponse
* @param err Internal server error
* @param stack Set to true if a stack trace should be created
* and the internal server error should be displayed to the client
*/
constructor(err?: Error, stack?: boolean) {
super('InternalServerError', 'Internal server error', 502, stack);
if (stack) {
this.additionalData = err;
}
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCAbstractRoute} from '../../../Route';
/**
* Index request
*/
export interface SCIndexRequest {
}
/**
* Route to request meta information about the deployment
*/
export class SCIndexRoute extends SCAbstractRoute {
constructor() {
super();
this.errorNames = [
'SCInternalServerErrorResponse',
'SCMethodNotAllowedErrorResponse',
'SCUnsupportedMediaTypeErrorResponse',
'SCValidationErrorResponse',
];
this.method = 'POST';
this.requestBodyName = 'SCIndexRequest';
this.responseBodyName = 'SCIndexResponse';
this.statusCodeSuccess = 200;
this.urlFragment = '/';
}
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCAppConfiguration} from '../../../types/config/App';
import {SCBackendConfiguration} from '../../../types/config/Backend';
/**
* A response to an index request
*/
export interface SCIndexResponse {
app: SCAppConfiguration;
backend: SCBackendConfiguration;
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCThings} from '../../../../Classes';
import {SCAbstractRoute} from '../../../../Route';
/**
* Request to update an existing thing
*/
export type SCThingUpdateRequest = SCThings;
/**
* Route for updating existing things
*/
export class SCThingUpdateRoute extends SCAbstractRoute {
constructor() {
super();
this.errorNames = [
'SCInternalServerErrorResponse',
'SCMethodNotAllowedErrorResponse',
'SCNotFoundErrorResponse',
'SCUnsupportedMediaTypeErrorResponse',
'SCValidationErrorResponse',
];
this.method = 'PUT';
this.obligatoryParameters = [
'TYPE',
'UID',
];
this.requestBodyName = 'SCThingUpdateRequest';
this.responseBodyName = 'SCThingUpdateResponse';
this.statusCodeSuccess = 200;
this.urlFragment = '/:TYPE/:UID';
}
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Response for an entity update request
*/
export interface SCThingUpdateResponse {
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCAbstractRoute} from '../../../Route';
import {SCUuid} from '../../../types/UUID';
/**
* Request to check the availability of books
*/
export type SCBookAvailabilityRequest = SCBookAvailabilityRequestByIsbn | SCBookAvailabilityRequestByUuid;
/**
* Availability request by ISBN
*/
export interface SCBookAvailabilityRequestByIsbn {
/**
* ISBN of the book to check availability for
*/
isbn: string;
}
/**
* Availability request by UUID
*/
export interface SCBookAvailabilityRequestByUuid {
/**
* UID of the book to check availability for
*/
uid: SCUuid;
}
/**
* Route for book availiability
*/
export class SCBookAvailabilityRoute extends SCAbstractRoute {
constructor() {
super();
this.errorNames = [
'SCInternalServerErrorResponse',
'SCMethodNotAllowedErrorResponse',
'SCNotFoundErrorResponse',
'SCUnsupportedMediaTypeErrorResponse',
'SCValidationErrorResponse',
];
this.method = 'POST';
this.requestBodyName = 'SCBookAvailabilityRequest';
this.responseBodyName = 'SCBookAvailabilityResponse';
this.statusCodeSuccess = 200;
this.urlFragment = '/bookAvailability';
}
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCAcademicPriceGroup, SCThingThatCanBeOfferedOffer} from '../../../base/ThingThatCanBeOffered';
/**
* List of availabilities of a book
*/
export type SCBookAvailabilityResponse = Array<SCThingThatCanBeOfferedOffer<SCAcademicPriceGroup>>;

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCAbstractRoute} from '../../../Route';
import {SCThingTypes} from '../../../Thing';
import {SCISO8601Date} from '../../../types/Time';
/**
* A bulk request
*
* Parameters to be sent to request a new bulk.
*/
export interface SCBulkRequest extends SCBulkParameters {
}
/**
* Parameters for a bulk
*/
export interface SCBulkParameters {
/**
* Expiration of bulk
*
* If the date is hit and the bulk is not done, it will be deleted and all data removed.
* Defaults to one hour.
*/
expiration?: SCISO8601Date;
/**
* Source of data for this bulk
*
* A short "description" of the source of the data to identify it inside the database.
* A second bulk with the same source overrides the data of the first bulk once it is done.
*/
source: string;
/**
* Type of things that are indexed in this bulk
*/
type: SCThingTypes;
}
/**
* Route for bulk creation
*/
export class SCBulkRoute extends SCAbstractRoute {
constructor() {
super();
this.errorNames = [
'SCInternalServerErrorResponse',
'SCMethodNotAllowedErrorResponse',
'SCUnsupportedMediaTypeErrorResponse',
'SCValidationErrorResponse',
];
this.method = 'POST';
this.requestBodyName = 'SCBulkRequest';
this.responseBodyName = 'SCBulkResponse';
this.statusCodeSuccess = 200;
this.urlFragment = '/bulk';
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCUuid} from '../../../types/UUID';
import {SCBulkParameters} from './BulkRequest';
/**
* Requested Bulk from backend
*/
export interface SCBulkResponse extends SCBulkParameters {
/**
* State of bulk
*
* The state is `in progress` while it accepts things to be added to the bulk.
* The state is `done` once it is closed.
*/
state: 'in progress' | 'done';
/**
* Universally unique identifier of the bulk
*/
uid: SCUuid;
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCThings} from '../../../../Classes';
import {SCAbstractRoute} from '../../../../Route';
/**
* Request to add a thing to a bulk
*/
export type SCBulkAddRequest = SCThings;
/**
* Route for indexing SC things in a bulk
*/
export class SCBulkAddRoute extends SCAbstractRoute {
constructor() {
super();
this.errorNames = [
'SCInternalServerErrorResponse',
'SCMethodNotAllowedErrorResponse',
'SCNotFoundErrorResponse',
'SCUnsupportedMediaTypeErrorResponse',
'SCValidationErrorResponse',
];
this.method = 'POST';
this.obligatoryParameters = ['UID'];
this.requestBodyName = 'SCBulkAddRequest';
this.responseBodyName = 'SCBulkAddResponse';
this.statusCodeSuccess = 201;
this.urlFragment = '/bulk/:UID';
}
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Response to a request to add a thing to a bulk
*/
export interface SCBulkAddResponse {
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCAbstractRoute} from '../../../../Route';
/**
* Request to change the bulk state to done (close the bulk process)
*/
export interface SCBulkDoneRequest {
}
/**
* Route for closing bulks
*/
export class SCBulkDoneRoute extends SCAbstractRoute {
constructor() {
super();
this.errorNames = [
'SCInternalServerErrorResponse',
'SCMethodNotAllowedErrorResponse',
'SCNotFoundErrorResponse',
'SCUnsupportedMediaTypeErrorResponse',
'SCValidationErrorResponse',
];
this.method = 'POST';
this.obligatoryParameters = ['UID'];
this.requestBodyName = 'SCBulkDoneRequest';
this.responseBodyName = 'SCBulkDoneResponse';
this.statusCodeSuccess = 204;
this.urlFragment = '/bulk/:UID/done';
}
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Response to a request to change the state of a bulk to done
*/
export interface SCBulkDoneResponse {
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCAbstractRoute} from '../../../Route';
import {SCMessage} from '../../../things/Message';
/**
* User feedback
*/
export interface SCFeedbackRequest extends SCMessage {
/**
* Meta data that helps to understand the feedback
*/
metaData: {
/**
* Whether or not the user enabled the debug mode
*/
debug?: boolean;
/**
* Platform identifier
*/
platform: string;
/**
* Scope/app state at feedback invocation
*/
scope: any;
/**
* Whether or not the feedback is sendable
*/
sendable?: boolean;
/**
* App state that feedback was invoked from
*/
state: any;
/**
* User agent
*/
userAgent: string;
/**
* StApps version string
*/
version: string;
};
}
/**
* Route for feedback submission
*/
export class SCFeedbackRoute extends SCAbstractRoute {
constructor() {
super();
this.errorNames = [
'SCInternalServerErrorResponse',
'SCMethodNotAllowedErrorResponse',
'SCUnsupportedMediaTypeErrorResponse',
'SCValidationErrorResponse',
];
this.method = 'POST';
this.requestBodyName = 'SCFeedbackRequest';
this.responseBodyName = 'SCFeedbackResponse';
this.statusCodeSuccess = 204;
this.urlFragment = '/feedback';
}
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* A response to a feedback request
*/
export interface SCFeedbackResponse {
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCAbstractRoute} from '../../../Route';
import {SCSearchQuery} from './SearchRequest';
/**
* A multi search request
*
* This is a map of [[SCSearchRequest]]s indexed by name.
*
* **CAUTION: This is limited to an amount of queries. Currently this limit is 5.**
*/
export interface SCMultiSearchRequest {
[k: string]: SCSearchQuery;
}
/**
* Route for submission of multiple search requests at once
*/
export class SCMultiSearchRoute extends SCAbstractRoute {
constructor() {
super();
this.errorNames = [
'SCInternalServerErrorResponse',
'SCMethodNotAllowedErrorResponse',
'SCTooManyRequestsErrorResponse',
'SCUnsupportedMediaTypeErrorResponse',
'SCValidationErrorResponse',
];
this.method = 'POST';
this.requestBodyName = 'SCMultiSearchRequest';
this.responseBodyName = 'SCMultiSearchResponse';
this.statusCodeSuccess = 200;
this.urlFragment = '/search/multi';
}
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCSearchResult} from './SearchResponse';
/**
* A multi search response
*
* This is a map of [[SCSearchResponse]]s indexed by name
*/
export interface SCMultiSearchResponse {
[k: string]: SCSearchResult;
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCAbstractRoute} from '../../../Route';
import {SCSearchFilter} from '../../../types/filters/Abstract';
import {SCSearchSort} from '../../../types/sorts/Abstract';
/**
* A search request
*/
export interface SCSearchRequest extends SCSearchQuery {
}
/**
* A search query
*/
export interface SCSearchQuery {
/**
* A filter structure that combines any number of filters with boolean methods ('AND', 'OR', 'NOT')
*/
filter?: SCSearchFilter;
/**
* Number of things to skip in result set (paging)
*/
from?: number;
/**
* A term to search for
*/
query?: string;
/**
* Number of things to have in the result set (paging)
*/
size?: number;
/**
* A list of sorting parameters to order the result set by
*/
sort?: SCSearchSort[];
}
/**
* Route for searching things
*/
export class SCSearchRoute extends SCAbstractRoute {
constructor() {
super();
this.errorNames = [
'SCInternalServerErrorResponse',
'SCMethodNotAllowedErrorResponse',
'SCUnsupportedMediaTypeErrorResponse',
'SCValidationErrorResponse',
];
this.method = 'POST';
this.requestBodyName = 'SCSearchRequest';
this.responseBodyName = 'SCSearchResponse';
this.statusCodeSuccess = 200;
this.urlFragment = '/search';
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCThings, SCThingsField} from '../../../Classes';
/**
* A search response
*/
export interface SCSearchResponse extends SCSearchResult {
}
/**
* A search response
*/
export interface SCSearchResult {
/**
* Data (any data object)
*/
data: SCThings[];
/**
* Facets (aggregations over all matching data)
*/
facets: SCFacet[];
/**
* Pagination information
*/
pagination: {
/**
* Count of given data. Same as data.length
*/
count: number;
/**
* Offset of data on all matching data. Given by [[SCSearchQuery.from]]
*/
offset: number;
/**
* Number of total matching data
*/
total: number
};
/**
* Stats of the search engine
*/
stats: {
/**
* Response time of the search engine in ms
*/
time: number;
};
}
/**
* A search facet
*/
export interface SCFacet {
/**
* Values for the aggregation
*/
buckets: Array<{
/**
* One value with its number of occurrences
*/
[key: string]: number;
}>;
/**
* Field of the aggregation
*/
field: SCThingsField;
}