2020-11-19 13:52:39 +01:00
|
|
|
// Actions Service Interface
|
2020-01-20 07:43:25 +01:00
|
|
|
|
|
|
|
/**
|
2020-04-03 13:24:15 +02:00
|
|
|
* Executes multiple actions in the context of the user given by the user_id.
|
2020-11-19 13:52:39 +01:00
|
|
|
* There are two modes of execution:
|
2020-11-19 15:01:49 +01:00
|
|
|
* atomic=false (default):
|
2020-11-19 13:52:39 +01:00
|
|
|
* All actions are validated in common, so if one action or one payload of
|
|
|
|
* one action fails, the request is aborted with an ActionException indicating
|
|
|
|
* the problematic action with both indices.
|
2020-11-19 15:01:49 +01:00
|
|
|
* atomic=true:
|
2020-11-19 13:52:39 +01:00
|
|
|
* Each action is validated by it's own. If there is an error, the error must
|
|
|
|
* be reported via an ActionError in the ActionsResponse. The actions result
|
|
|
|
* is not written into the Datastore. It might raise an ActionException if the
|
|
|
|
* single write request to the Datastore fails (e.g. because of locking there)
|
2020-01-20 07:43:25 +01:00
|
|
|
*
|
2020-11-10 17:28:57 +01:00
|
|
|
* For general, non specific action-related, errors an ActionException is used.
|
2020-01-21 18:05:47 +01:00
|
|
|
*
|
|
|
|
* @throws ActionException
|
2020-01-20 07:43:25 +01:00
|
|
|
*/
|
2020-11-25 12:17:01 +01:00
|
|
|
handle_request(payload: Action[], user_id: Id, atomic?: boolean): ActionsResponse
|
2020-01-20 07:43:25 +01:00
|
|
|
|
|
|
|
interface Action {
|
2020-01-21 18:05:47 +01:00
|
|
|
action: string;
|
2020-11-19 13:52:39 +01:00
|
|
|
data: object[];
|
2020-02-03 23:32:24 +01:00
|
|
|
}
|
|
|
|
|
2020-11-11 08:33:59 +01:00
|
|
|
interace ActionsResponse {
|
2020-11-10 17:28:57 +01:00
|
|
|
success: true;
|
2020-02-03 23:32:24 +01:00
|
|
|
message: string;
|
2020-11-10 17:28:57 +01:00
|
|
|
|
|
|
|
/**
|
2020-11-19 13:52:39 +01:00
|
|
|
* This is a potentially double-array with entries for each action
|
2020-11-10 17:28:57 +01:00
|
|
|
* and, if not null, an array for each data provided for each action.
|
|
|
|
*
|
2020-11-19 13:52:39 +01:00
|
|
|
* If an action does not produce a result, the inner array can be omitted and
|
2020-11-10 17:28:57 +01:00
|
|
|
* null can be used. If the inner array is given, each entry must be an object
|
|
|
|
* with the result (e.g. for a create action `{id: <the id>}`) or null.
|
2020-11-19 13:52:39 +01:00
|
|
|
*
|
2020-11-10 17:28:57 +01:00
|
|
|
* E.g. for valid arrays (two actions with two data entries each):
|
|
|
|
* - [null, null]
|
|
|
|
* - [null, [null, null]]
|
|
|
|
* - [null, [{id: 2}, null]]
|
|
|
|
* - [[{id: 2}, {id: 3}], [{id: 5}, {id: 8}]]
|
2020-11-19 13:52:39 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* To report errors, use the ActionError format!
|
2020-11-10 17:28:57 +01:00
|
|
|
**/
|
2021-02-03 10:06:16 +01:00
|
|
|
results: ((object | ActionError | null)[] | null )[]
|
2020-01-20 07:43:25 +01:00
|
|
|
}
|
2020-11-10 17:28:57 +01:00
|
|
|
|
|
|
|
interface ActionError {
|
|
|
|
success: false;
|
|
|
|
message: string;
|
2020-11-19 13:52:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JSON resonse with a status code of !=200. If a specific action raised the error,
|
|
|
|
* use the action_error_index and action_payload_error_index to indicate the errored
|
2020-11-27 10:47:02 +01:00
|
|
|
* action and payload. If there were general errors, both indices must be omitted or null.
|
2020-11-19 13:52:39 +01:00
|
|
|
*
|
2020-11-19 15:01:49 +01:00
|
|
|
* If the atomic flag was true in the request, it is not allowed to send
|
2020-11-27 10:47:02 +01:00
|
|
|
* action-specific errors with this exception. It must be responded with an
|
|
|
|
* ActionError through ActionsResponse (resulting in a status code of 200).
|
2020-11-19 13:52:39 +01:00
|
|
|
*/
|
|
|
|
Exception ActionException {
|
|
|
|
success: false;
|
|
|
|
message: string;
|
2020-11-27 10:47:02 +01:00
|
|
|
action_error_index?: number;
|
|
|
|
action_payload_error_index?: number;
|
|
|
|
}
|