UNPKG

1.03 kBTypeScriptView Raw
1/** @module data */
2/**
3 * Interface for data objects that can be versioned.
4 *
5 * Versioning is often used as optimistic concurrency mechanism.
6 *
7 * The version doesn't have to be a number, but it is recommended to use sequential
8 * values to determine if one object has newer or older version than another one.
9 *
10 * It is a common pattern to use the time of change as the object version.
11 *
12 * ### Example ###
13 *
14 * export class MyData implements IStringIdentifiable, IVersioned {
15 * public id: string;
16 * public field1: string;
17 * public field2: number;
18 * public version: string;
19 * ...
20 * }
21 *
22 * public updateData(correlationId: string, item: MyData): void {
23 * ...
24 * if (item.version < oldItem.version) {
25 * throw new ConcurrencyException(null, "VERSION_CONFLICT", "The change has older version stored value");
26 * }
27 * ...
28 * }
29 */
30export interface IVersioned {
31 /** The object's version. */
32 version: string;
33}