/
async-operation-processor.ts
94 lines (83 loc) · 2.62 KB
/
async-operation-processor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* eslint-disable @typescript-eslint/no-unused-vars */
import { AsyncRecordAccessor } from './record-accessor';
import { RecordOperation } from '@orbit/records';
export interface AsyncOperationProcessorClass {
new (cache: AsyncRecordAccessor): AsyncOperationProcessor;
}
/**
* Operation processors are used to identify operations that should be performed
* together to ensure that a `Cache` or other container of data remains
* consistent and correct.
*
* `OperationProcessor` is an abstract base class to be extended by specific
* operation processors.
*/
export abstract class AsyncOperationProcessor {
private _accessor: AsyncRecordAccessor;
/**
* The `AsyncRecordAccessor` that is monitored.
*/
get accessor(): AsyncRecordAccessor {
return this._accessor;
}
constructor(accessor: AsyncRecordAccessor) {
this._accessor = accessor;
}
/**
* Called when all the data in a cache has been reset.
*
* If `base` is included, the cache is being reset to match a base cache.
*/
reset(base?: AsyncRecordAccessor): Promise<void> {
return Promise.resolve();
}
/**
* Allow the processor to perform an upgrade as part of a cache upgrade.
*/
upgrade(): Promise<void> {
return Promise.resolve();
}
/**
* Validates an operation before processing it.
*/
validate(operation: RecordOperation): Promise<void> {
return Promise.resolve();
}
/**
* Called before an `operation` has been applied.
*
* Returns an array of operations to be applied **BEFORE** the `operation`
* itself is applied.
*/
before(operation: RecordOperation): Promise<RecordOperation[]> {
return Promise.resolve([]);
}
/**
* Called before an `operation` has been applied.
*
* Returns an array of operations to be applied **AFTER** the `operation`
* has been applied successfully.
*/
after(operation: RecordOperation): Promise<RecordOperation[]> {
return Promise.resolve([]);
}
/**
* Called immediately after an `operation` has been applied and before the
* `patch` event has been emitted (i.e. before any listeners have been
* notified that the operation was applied).
*
* No operations may be returned.
*/
immediate(operation: RecordOperation): Promise<void> {
return Promise.resolve();
}
/**
* Called after an `operation` _and_ any related operations have been applied.
*
* Returns an array of operations to be applied **AFTER** the `operation`
* itself and any operations returned from the `after` hook have been applied.
*/
finally(operation: RecordOperation): Promise<RecordOperation[]> {
return Promise.resolve([]);
}
}