2020-03-09 12:25:35 +01:00
|
|
|
/**
|
|
|
|
* This is a chatch-all exception for some invalid parameters
|
|
|
|
*/
|
|
|
|
Exception InvalidFormat(msg: string);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This exception is thrown, when parsing model data. E.g. there is an indicated
|
|
|
|
* relation to a key, but the data are no foreign ids/fqids. The exception may
|
|
|
|
* happen, if the stream is used at runtime, because this cannot be detected
|
|
|
|
* when the caller makes the request.
|
|
|
|
*/
|
|
|
|
Exception ParsingError(msg: string);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This methods subscribes to the given request. The response is a stream
|
|
|
|
* (language dependent) updating all models according to the ModelRequest if new
|
|
|
|
* data is available. On subscription, initial data must be pushed to the caller
|
|
|
|
* as soon as possible. The stream can be closed by closing the stream (e.g. the
|
|
|
|
* underlying network connection).
|
|
|
|
*
|
|
|
|
* @throws InvalidFormat
|
|
|
|
* @throws ParsingError
|
|
|
|
*/
|
|
|
|
subscribe(request: ModelRequest): stream<ModelData>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the main interface for requesting models in a structured, nested way.
|
|
|
|
* The initial request targets some models as the root models of one collection
|
|
|
|
* with all the same fields. This build a tree of dependencies, because the
|
2020-03-16 10:41:41 +01:00
|
|
|
* value of some fields may be a GenericRelationFieldDescriptor again.
|
2020-03-09 12:25:35 +01:00
|
|
|
*
|
2020-03-16 10:41:41 +01:00
|
|
|
* For a description of `fields` and `collection`, see GenericRelationFieldDescriptor
|
|
|
|
* and RelationFieldDescriptor.
|
2020-03-09 12:25:35 +01:00
|
|
|
*
|
|
|
|
* `ids`: This is a list of ids for a collection, that should be provided. All
|
|
|
|
* models, that the user can see, must be included in the response. The model
|
2020-03-16 10:41:41 +01:00
|
|
|
* fields are handled according to `GenericRelationFieldDescriptor`.
|
2020-03-09 12:25:35 +01:00
|
|
|
*/
|
2020-03-16 10:41:41 +01:00
|
|
|
Interface ModelRequest extends Fields {
|
2020-03-09 12:25:35 +01:00
|
|
|
ids: ID[];
|
|
|
|
collection: Collection;
|
2020-03-16 10:41:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Interface Fields {
|
2020-03-09 12:25:35 +01:00
|
|
|
fields: {
|
2020-03-16 10:41:41 +01:00
|
|
|
[field: Field]: GenericRelationFieldDescriptor
|
|
|
|
| RelationFieldDescriptor
|
|
|
|
| StructuredFieldDescriptor
|
|
|
|
| null;
|
2020-03-09 12:25:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For an overview, see `ModelRequest`.
|
|
|
|
*
|
2020-03-16 10:41:41 +01:00
|
|
|
* `fields` (inherited from `Fields`, see above):
|
2020-03-09 12:25:35 +01:00
|
|
|
* Regardless of the value of a field, the restricted values are given in the
|
|
|
|
* response (multiple for structured fields). If the restricted value is null,
|
|
|
|
* the field must be included here.
|
|
|
|
*
|
|
|
|
* If the value is not null, it is indicated, that there is a reference to
|
2020-03-16 10:41:41 +01:00
|
|
|
* follow. There are three types of values:
|
|
|
|
* - GenericRelationFieldDescriptor: The reference is a generic one. This means, that
|
2020-03-09 12:25:35 +01:00
|
|
|
* the actual value from the model is a fqid or an array of fqids.
|
2020-03-16 10:41:41 +01:00
|
|
|
* - RelationFieldDescriptor: A collection is given, so it can be expected, that the
|
2020-03-09 12:25:35 +01:00
|
|
|
* actual model value is an id or an array of ids.
|
2020-03-16 10:41:41 +01:00
|
|
|
* - StructuredFieldDescriptor: The field is a template field and should be
|
|
|
|
* handled in this way.
|
2020-03-09 12:25:35 +01:00
|
|
|
*/
|
2020-03-16 10:41:41 +01:00
|
|
|
Interface GenericRelationFieldDecriptor extends Fields {
|
|
|
|
type: 'generic-relation' | 'generic-relation-list';
|
2020-03-09 12:25:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-16 10:41:41 +01:00
|
|
|
* For an overview, see `ModelRequest`. For `fields`, see GenericRelationFieldDescriptor.
|
2020-03-09 12:25:35 +01:00
|
|
|
*
|
|
|
|
* `collection`:
|
|
|
|
* This is the collection, the ids are associated to. The ids are provided with
|
|
|
|
* two different ways:
|
|
|
|
* - In a ModelRequest, the ids are given.
|
|
|
|
* - If this interface is used in a field indication a relation, the id(s) are
|
|
|
|
* given by the actual model data.
|
|
|
|
*/
|
2020-03-16 10:41:41 +01:00
|
|
|
Interface RelationFieldDescriptor extends Fields {
|
|
|
|
type: 'relation' | 'relation-list';
|
2020-03-09 12:25:35 +01:00
|
|
|
collection: Collection;
|
|
|
|
}
|
|
|
|
|
2020-03-16 10:41:41 +01:00
|
|
|
/**
|
|
|
|
* Structured Fields: A field with `$` as a placeholder can be structured. The
|
|
|
|
* `$` is a template placeholder. The `template field` holds a list of strings
|
|
|
|
* with options to insert into `$`. All these fields are the `structured
|
|
|
|
* fields`. Example:
|
|
|
|
* B_$_ids is the template field. Its value may be `["1", "test"]`, so the
|
|
|
|
* structured fields are B_1_ids and B_test_ids.
|
|
|
|
*
|
|
|
|
* This interface indicates, that there are structured fields related to the
|
|
|
|
* given template field, that should be resolved. If one would give `B_$_ids:
|
|
|
|
* null` without using this interface, the response would be just the template
|
|
|
|
* field `B_$_ids` and no structured fields.
|
|
|
|
*
|
|
|
|
* For just resolving values, leav `values` out (hence the optional parameter).
|
|
|
|
*
|
|
|
|
* If the values of all structured fields are references, use the `values`
|
|
|
|
* parameter analog to the `fields` paramter as documented in
|
|
|
|
* `GenericRelationFieldDescriptor`.
|
|
|
|
*/
|
2020-03-16 16:01:49 +01:00
|
|
|
Interface StructuredFieldDecriptor {
|
2020-03-16 10:41:41 +01:00
|
|
|
type: 'template',
|
|
|
|
values?: {
|
|
|
|
[field: Field]: GenericRelationFieldDescriptor
|
|
|
|
| RelationFieldDescriptor
|
|
|
|
| StructuredFieldDescriptor
|
|
|
|
| null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-09 12:25:35 +01:00
|
|
|
/**
|
|
|
|
* This structure holds all data given by the called service structured by
|
|
|
|
* fqids. Each fqid contains the (partial, restricted) data for the fqid.
|
|
|
|
*/
|
|
|
|
Interface ModelData {
|
|
|
|
[collection: Collection]: {
|
|
|
|
[id: Id]: {
|
|
|
|
[field: Field]: Value;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|