refactor: tidy structure of source files

Fixes #79
This commit is contained in:
Karl-Philipp Wulfert
2019-06-19 15:04:59 +02:00
parent 5de9bf3794
commit ceab7cc7ef
99 changed files with 1395 additions and 1511 deletions

175
src/config/app.ts Normal file
View File

@@ -0,0 +1,175 @@
/*
* Copyright (C) 2019 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/>.
*/
// tslint:disable-next-line:no-implicit-dependencies
import {Polygon} from 'geojson';
import {SCTranslations} from '../general/i18n';
import {SCSetting} from '../things/setting';
/**
* An app configuration menu item
*/
export interface SCAppConfigurationMenuItem {
/**
* Icon for the menu item
*/
icon: string;
/**
* Route inside the app
*/
route: string;
/**
* Title of the route
*/
title: string;
/**
* Translations for the menu item
*/
translations: SCTranslations<SCAppConfigurationMenuItemTranslationTitle>;
}
/**
* An app configuration menu category
*/
export interface SCAppConfigurationMenuCategory {
/**
* Icon for the menu category
*/
icon: string;
/**
* ID of the menu category
*/
id:
'main'
| 'meta'
| 'personal'
| 'external';
/**
* A list of items that belong to the category
*/
items: SCAppConfigurationMenuItem[];
/**
* Name of the category
*/
name: string;
/**
* Translations for the menu category
*/
translations: SCTranslations<SCAppConfigurationMenuCategoryTranslationName>;
}
/**
* An app configuration
*/
export interface SCAppConfiguration {
/**
* Polygon that encapsulates the main campus
*/
campusPolygon: Polygon;
/**
* A list of features to en- or disable
*/
features: SCAppConfigurationFeature;
/**
* A URL where images are available
*/
imageUrl?: string;
/**
* A list of available menu categories in the app
*/
menus: SCAppConfigurationMenuCategory[];
/**
* Name for the app
*/
name: string;
/**
* URL to a file containing the privacy policy
*/
privacyPolicyUrl: string;
/**
* A list of available settings in the app
*/
settings: SCSetting[];
/**
* Map of store URLs
*/
storeUrl?: SCAppConfigurationStoreUrl;
/**
* URL where a web instance of the app is available
*/
url?: string;
}
/**
* Map of features
*/
export interface SCAppConfigurationFeature {
/**
* Whether or not widgets are enabled
*/
widgets: boolean;
}
/**
* URLs of published apps
*/
export interface SCAppConfigurationStoreUrl {
/**
* Google Play Store URL
*/
android?: string;
/**
* Apple App Store URL
*/
ios?: string;
/**
* Microsoft Store URL
*/
uwp?: string;
}
/**
* Translatable property of a menu item
*/
export interface SCAppConfigurationMenuItemTranslationTitle {
/**
* Translation of the title of a menu item
*/
title: string;
}
/**
* Translatable property of a menu category
*/
export interface SCAppConfigurationMenuCategoryTranslationName {
/**
* Translation of the name of a menu category
*/
name: string;
}

182
src/config/backend.ts Normal file
View File

@@ -0,0 +1,182 @@
/*
* Copyright (C) 2019 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 {SCMap, SCRestrictedMap} from '../general/map';
import {SCUuid} from '../general/uuid';
import {SCSearchSortType} from '../protocol/search/sort';
import {SCThingType} from '../things/abstract/thing';
import {SCMonitoringConfiguration} from './monitoring';
/**
* A backend configuration
*/
export interface SCBackendConfiguration {
/**
* A list of hidden SC types
*
* If a type is hidden it won't show in any result unless the type is filtered for
*
*/
hiddenTypes: SCThingType[];
/**
* Maximum number of queries, that can be used in MultiSearchRoute
*/
maxMultiSearchRouteQueries: number;
/**
* Maximum body size for requests
*/
maxRequestBodySize: number;
/**
* Name of university
*/
name: string;
/**
* Namespace of the university for UID generation
*/
namespace: SCUuid;
/**
* Version string of the installed StAppsCore
*/
SCVersion: string;
/**
* A list of sortable fields of each type
*/
sortableFields: SCBackendConfigurationSortableField[];
}
/**
* Description which sort types are supported on which fields of which types
*/
export interface SCBackendConfigurationSortableField {
/**
* Field name which the sorts should be available on
*/
fieldName: string;
/**
* A list of SC types on which this field exists
*
* If no type is given it is assumed it exists on every type
*/
onlyOnTypes?: SCThingType[];
/**
* A list of supported sorts on this field
*/
sortTypes: SCSearchSortType[];
}
/**
* Possible context names to be used by the search request
*/
export type SCSearchContext =
| 'default'
| 'dining'
| 'place';
/**
* A boosting configuration for one context
*/
export type SCBackendConfigurationSearchBoostingContext =
SCRestrictedMap<SCSearchContext,
SCBackendConfigurationSearchBoostingType[]>;
/**
* A boosting configuration for one SCType
*/
export interface SCBackendConfigurationSearchBoostingType {
/**
* The factor of which the scores matching this type should be multiplied by
*/
factor: number;
/**
* Outer-Map:
* Fields of this type that should be boosted if they match a given value
* For nest fields you can use the `.` as a separator. For example `academicTerms.acronym`
*
* Inner-map:
* Value of the field that should be boosted by the given number
* For example `"SS 2019": 2`
*/
fields?: SCMap<SCMap<number>>;
/**
* Type of things the factor should be applied to
*/
type: SCThingType;
}
/**
* Describes which field on which type should be aggregated
*/
export interface SCBackendAggregationConfiguration {
/**
* Field name of field which values should be aggregated
*/
fieldName: string;
/**
* A list of SC types of which the field is on
*
* If the type is not given is is assumed the field exists on every type
*/
onlyOnTypes?: SCThingType[];
}
/**
* The internal backend configuration that is hidden from the app
*/
export interface SCBackendInternalConfiguration {
/**
* A list of configurations for aggregations
*/
aggregations: SCBackendAggregationConfiguration[];
/**
* A list of configurations for search boosting
*
* The resulting scores of matching objects can be boosted (multiplied by a number) to change the order in the
* set of results
*/
boostings: SCBackendConfigurationSearchBoostingContext;
/**
* Configuration of the database
*/
database?: SCBackendConfigurationDatabaseConfiguration;
/**
* Configuration for monitoring
*/
monitoring?: SCMonitoringConfiguration;
}
/**
* Configuration of the database
*/
export interface SCBackendConfigurationDatabaseConfiguration extends SCMap<unknown> {
/**
* Name of the database used by the backend
*/
name: string;
}

44
src/config/file.ts Normal file
View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2019 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 {SCLicensePlate} from '../general/namespaces';
import {SCAppConfiguration} from './app';
import {SCBackendConfiguration, SCBackendInternalConfiguration} from './backend';
/**
* A configuration file that configures app and backend
* @validatable
*/
export interface SCConfigFile {
/**
* Configuration for the app that is visible to clients
*/
app: SCAppConfiguration;
/**
* Configuration for the backend that is visible to clients
*/
backend: SCBackendConfiguration;
/**
* Configuration that is not visible to clients
*/
internal: SCBackendInternalConfiguration;
/**
* UID of the university, e.g. the license plate
*/
uid: SCLicensePlate;
}

164
src/config/monitoring.ts Normal file
View File

@@ -0,0 +1,164 @@
/*
* Copyright (C) 2019 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/>.
*/
/**
* An abstract action that can be executed by a failed watcher
*
* This is extended by actual actions.
*/
export interface SCMonitoringAction {
/**
* Message that is used by the action
*
* Mustache syntax is supported to evaluate the query.
*/
message: string;
/**
* The type of the action
*/
type: 'log' | 'mail';
}
/**
* A log action which can be executed from a failed watcher
*/
export interface SCMonitoringLogAction extends SCMonitoringAction {
/**
* A prefix for the logged messages
*/
prefix: string;
/**
* The type of the action
*/
type: 'log';
}
/**
* A mail task which can be executed from a failed watcher
*/
export interface SCMonitoringMailAction extends SCMonitoringAction {
/**
* A list of addresses to send the mails to
*/
recipients: string[];
/**
* A subject line for all mails
*/
subject: string;
/**
* The type of the action
*/
type: 'mail';
}
/**
* A list of events to describe the execution interval of monitoring triggers
*/
export type SCMonitoringExecutionCalendarEvents = 'hourly' | 'daily' | 'weekly' | 'monthly';
/**
* A trigger which determines the execution time of a watcher
*/
export interface SCMonitoringTrigger {
/**
* A cron like syntax to describe when this trigger should be executed
*/
executionTime: SCMonitoringExecutionCalendarEvents | string;
/**
* A name of the trigger that explains when it executes
*/
name: string;
}
/**
* A condition which is met, when the result length is higher than the minimum length
*/
export interface SCMonitoringMinimumLengthCondition {
/**
* The minimum length
*/
length: number;
/**
* Type of the condition
*/
type: 'MinimumLength';
}
/**
* A condition which is met, when the result length is smaller than the maximum length
*/
export interface SCMonitoringMaximumLengthCondition {
/**
* The maximum length
*/
length: number;
/**
* Type of the condition
*/
type: 'MaximumLength';
}
/**
* A watcher that evaluates a query, when triggered
*/
export interface SCMonitoringWatcher {
/**
* A list of actions that are executed, when the watcher fails
*/
actions: Array<SCMonitoringLogAction | SCMonitoringMailAction>;
/**
* A list of conditions that have to match the result of the query
*
* If not all conditions are met, the watcher will fail and all actions are executed
*/
conditions: Array<SCMonitoringMaximumLengthCondition | SCMonitoringMinimumLengthCondition>;
/**
* A name for the watcher
*/
name: string;
/**
* Query to execute against the database
*/
query: unknown;
/**
* A list of triggers
*/
triggers: SCMonitoringTrigger[];
}
/**
* A complete monitoring configuration for the backend
*/
export interface SCMonitoringConfiguration {
/**
* A list of actions that are executed, when a watcher fails
*/
actions: Array<SCMonitoringMailAction | SCMonitoringLogAction>;
/**
* A list of watches
*/
watchers: SCMonitoringWatcher[];
}