/
Update.ts
252 lines (229 loc) · 7.12 KB
/
Update.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Core
*/
import { NodeKey, NodeKeyJSON } from "./hierarchy/Key";
import { Node, NodeJSON, PartialNode, PartialNodeJSON } from "./hierarchy/Node";
/** @alpha */
export const UPDATE_FULL = "FULL";
/** @alpha */
export interface UpdateInfo {
[imodel: string]: {
[rulesetId: string]: {
hierarchy?: HierarchyUpdateInfo;
content?: ContentUpdateInfo;
};
};
}
/** @alpha */
export type HierarchyUpdateInfo = typeof UPDATE_FULL;
/** @alpha */
export type ContentUpdateInfo = typeof UPDATE_FULL;
/**
* JSON representation of [[PartialHierarchyModification]].
* @public
* @deprecated in 3.x. Use [[PartialHierarchyModification]]
*/
// eslint-disable-next-line deprecation/deprecation
export type PartialHierarchyModificationJSON = NodeInsertionInfoJSON | NodeDeletionInfoJSON | NodeUpdateInfoJSON;
/**
* Information about a hierarchy change: insertion, deletion or node update.
* @public
*/
export type PartialHierarchyModification = NodeInsertionInfo | NodeDeletionInfo | NodeUpdateInfo;
/** @public */
export namespace PartialHierarchyModification { // eslint-disable-line @typescript-eslint/no-redeclare
/**
* Serialize given object to JSON.
* @deprecated in 3.x. Use [[PartialHierarchyModification]]
*/
// eslint-disable-next-line deprecation/deprecation
export function toJSON(obj: PartialHierarchyModification): PartialHierarchyModificationJSON {
switch (obj.type) {
case "Insert":
return {
type: "Insert",
// eslint-disable-next-line deprecation/deprecation
parent: obj.parent === undefined ? undefined : NodeKey.toJSON(obj.parent),
position: obj.position,
// eslint-disable-next-line deprecation/deprecation
node: Node.toJSON(obj.node),
};
case "Update":
return {
type: "Update",
// eslint-disable-next-line deprecation/deprecation
target: NodeKey.toJSON(obj.target),
changes: Node.toPartialJSON(obj.changes),
};
case "Delete":
return {
type: "Delete",
// eslint-disable-next-line deprecation/deprecation
parent: obj.parent === undefined ? undefined : NodeKey.toJSON(obj.parent),
position: obj.position,
};
}
}
/**
* Deserialize given object from JSON
* @deprecated in 3.x. Use [[PartialHierarchyModification]]
*/
// eslint-disable-next-line deprecation/deprecation
export function fromJSON(json: PartialHierarchyModificationJSON): PartialHierarchyModification {
switch (json.type) {
case "Insert":
return {
type: "Insert",
// eslint-disable-next-line deprecation/deprecation
parent: json.parent === undefined ? undefined : NodeKey.fromJSON(json.parent),
position: json.position,
// eslint-disable-next-line deprecation/deprecation
node: Node.fromJSON(json.node),
};
case "Update":
return {
type: "Update",
// eslint-disable-next-line deprecation/deprecation
target: NodeKey.fromJSON(json.target),
changes: Node.fromPartialJSON(json.changes),
};
case "Delete":
return {
type: "Delete",
// eslint-disable-next-line deprecation/deprecation
parent: json.parent === undefined ? undefined : NodeKey.fromJSON(json.parent),
position: json.position,
};
}
}
}
/**
* Information about node insertion.
* @public
*/
export interface NodeInsertionInfo {
type: "Insert";
/** Parent node key */
parent?: NodeKey;
/** Index of the new node under its parent */
position: number;
/** Inserted node */
node: Node;
}
/**
* JSON representation of [[NodeInsertionInfo]].
* @public
* @deprecated in 3.x. Use [[NodeInsertionInfo]]
*/
export interface NodeInsertionInfoJSON {
type: "Insert";
// eslint-disable-next-line deprecation/deprecation
parent?: NodeKeyJSON;
position: number;
// eslint-disable-next-line deprecation/deprecation
node: NodeJSON;
}
/**
* Information about node deletion.
* @public
*/
export interface NodeDeletionInfo {
type: "Delete";
/** Parent of the deleted node */
parent?: NodeKey;
/** Position of the deleted node among its siblings in the initial, not updated tree */
position: number;
}
/**
* JSON representation of [[NodeDeletionInfo]].
* @public
* @deprecated in 3.x. Use [[NodeDeletionInfo]]
*/
export interface NodeDeletionInfoJSON {
type: "Delete";
/** Parent of the deleted node */
// eslint-disable-next-line deprecation/deprecation
parent?: NodeKeyJSON;
/** Position of the deleted node among its siblings in the initial, not updated tree */
position: number;
}
/**
* Information about node update.
* @public
*/
export interface NodeUpdateInfo {
type: "Update";
/** Key of the updated node */
target: NodeKey;
/** Updated node attributes */
changes: PartialNode;
}
/**
* JSON representation of [[NodeUpdateInfo]].
* @public
* @deprecated in 3.x. Use [[NodeUpdateInfo]]
*/
export interface NodeUpdateInfoJSON {
type: "Update";
// eslint-disable-next-line deprecation/deprecation
target: NodeKeyJSON;
// eslint-disable-next-line deprecation/deprecation
changes: PartialNodeJSON;
}
/**
* JSON representation of [[HierarchyCompareInfo]].
* @public
* @deprecated in 3.x. Use [[HierarchyCompareInfo]].
*/
export interface HierarchyCompareInfoJSON {
// eslint-disable-next-line deprecation/deprecation
changes: PartialHierarchyModificationJSON[];
continuationToken?: {
prevHierarchyNode: string;
currHierarchyNode: string;
};
}
/**
* Information about hierarchy modification / differences.
* @public
*/
export interface HierarchyCompareInfo {
/** A list of hierarchy changes */
changes: PartialHierarchyModification[];
/** Continuation token for requesting more changes. */
continuationToken?: {
prevHierarchyNode: string;
currHierarchyNode: string;
};
}
/** @public */
export namespace HierarchyCompareInfo {
/**
* Serialize given object to JSON.
* @deprecated in 3.x. Use [[HierarchyCompareInfo]]
*/
// eslint-disable-next-line deprecation/deprecation
export function toJSON(obj: HierarchyCompareInfo): HierarchyCompareInfoJSON {
return {
...obj,
// eslint-disable-next-line deprecation/deprecation
changes: obj.changes.map((change) => PartialHierarchyModification.toJSON(change)),
};
}
/**
* Deserialize given object from JSON
* @deprecated in 3.x. Use [[HierarchyCompareInfo]]
*/
// eslint-disable-next-line deprecation/deprecation
export function fromJSON(json: HierarchyCompareInfoJSON): HierarchyCompareInfo {
return {
...json,
// eslint-disable-next-line deprecation/deprecation
changes: json.changes.map((change) => PartialHierarchyModification.fromJSON(change)),
};
}
}