@rentman/rm-core 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/definitions/classes/ApiFormatter.d.ts +36 -0
- package/dist/definitions/classes/BatchStatus.d.ts +16 -0
- package/dist/definitions/classes/ChangesCompiler.d.ts +34 -0
- package/dist/definitions/classes/ChangesProcessor.d.ts +46 -0
- package/dist/definitions/classes/CollectionCache.d.ts +39 -0
- package/dist/definitions/classes/CollectionEntryService.d.ts +15 -0
- package/dist/definitions/classes/CollectionHandler.d.ts +79 -0
- package/dist/definitions/classes/CollectionResourceService.d.ts +5 -0
- package/dist/definitions/classes/ColumnCache.d.ts +18 -0
- package/dist/definitions/classes/ColumnExpansion.d.ts +16 -0
- package/dist/definitions/classes/ColumnHandler.d.ts +19 -0
- package/dist/definitions/classes/ColumnSet.d.ts +54 -0
- package/dist/definitions/classes/ColumnUtil.d.ts +80 -0
- package/dist/definitions/classes/CreateRequest.d.ts +28 -0
- package/dist/definitions/classes/ItemAdministrator.d.ts +114 -0
- package/dist/definitions/classes/ItemCache.d.ts +22 -0
- package/dist/definitions/classes/ItemEntryService.d.ts +50 -0
- package/dist/definitions/classes/ItemHandler.d.ts +70 -0
- package/dist/definitions/classes/ItemRequestService.d.ts +31 -0
- package/dist/definitions/classes/ItemResourceService.d.ts +8 -0
- package/dist/definitions/classes/KeyService.d.ts +28 -0
- package/dist/definitions/classes/LockService.d.ts +25 -0
- package/dist/definitions/classes/ModuleChangesCompiler.d.ts +18 -0
- package/dist/definitions/classes/PromiseService.d.ts +10 -0
- package/dist/definitions/classes/QueryMatcher.d.ts +14 -0
- package/dist/definitions/classes/QueryParser.d.ts +16 -0
- package/dist/definitions/classes/QueryService.d.ts +19 -0
- package/dist/definitions/classes/RequestColumnExpansion.d.ts +9 -0
- package/dist/definitions/classes/ResourceCache.d.ts +78 -0
- package/dist/definitions/classes/Util.d.ts +25 -0
- package/dist/definitions/constants.d.ts +10 -0
- package/dist/definitions/factories/BatchStatusFactory.d.ts +8 -0
- package/dist/definitions/factories/ChangesCompilerFactory.d.ts +9 -0
- package/dist/definitions/factories/ChangesProcessorFactory.d.ts +31 -0
- package/{src/factories/CollectionCacheFactory.ts → dist/definitions/factories/CollectionCacheFactory.d.ts} +3 -11
- package/dist/definitions/factories/CollectionEntryFactory.d.ts +19 -0
- package/dist/definitions/factories/CollectionResourceFactory.d.ts +18 -0
- package/dist/definitions/factories/ColumnExpansionFactory.d.ts +11 -0
- package/dist/definitions/factories/ColumnSetFactory.d.ts +9 -0
- package/dist/definitions/factories/CreateRequestFactory.d.ts +13 -0
- package/dist/definitions/factories/ItemCacheFactory.d.ts +9 -0
- package/dist/definitions/factories/ItemEntryFactory.d.ts +6 -0
- package/dist/definitions/factories/ItemResourceFactory.d.ts +12 -0
- package/{src/factories/ModuleChangesCompilerFactory.ts → dist/definitions/factories/ModuleChangesCompilerFactory.d.ts} +3 -14
- package/dist/definitions/factories/QueryMatcherFactory.d.ts +7 -0
- package/dist/definitions/factories/QueryParserFactory.d.ts +5 -0
- package/{src/factories/RequestColumnExpansionFactory.ts → dist/definitions/factories/RequestColumnExpansionFactory.d.ts} +3 -11
- package/dist/definitions/factories/ResourceCacheFactory.d.ts +33 -0
- package/dist/definitions/index.d.ts +121 -0
- package/dist/definitions/interfaces/ApiRequestServiceInterface.d.ts +10 -0
- package/dist/definitions/interfaces/AuthInterface.d.ts +4 -0
- package/{src/interfaces/ErrorHandlerInterface.ts → dist/definitions/interfaces/ErrorHandlerInterface.d.ts} +2 -2
- package/dist/definitions/interfaces/ResourceCacheInterface.d.ts +6 -0
- package/dist/definitions/models/CollectionEditResource.d.ts +23 -0
- package/dist/definitions/models/CollectionEntry.d.ts +61 -0
- package/dist/definitions/models/CollectionResource.d.ts +29 -0
- package/{src/models/CollectionViewResource.ts → dist/definitions/models/CollectionViewResource.d.ts} +6 -13
- package/dist/definitions/models/EditResource.d.ts +7 -0
- package/dist/definitions/models/ItemEntry.d.ts +18 -0
- package/dist/definitions/models/ItemResource.d.ts +14 -0
- package/dist/definitions/models/ViewResource.d.ts +7 -0
- package/dist/rm-core.js +29 -0
- package/dist/rm-core.js.map +1 -0
- package/package.json +5 -1
- package/.editorconfig +0 -23
- package/src/classes/ApiFormatter.ts +0 -338
- package/src/classes/BatchStatus.ts +0 -86
- package/src/classes/ChangesCompiler.ts +0 -161
- package/src/classes/ChangesProcessor.ts +0 -475
- package/src/classes/CollectionCache.ts +0 -234
- package/src/classes/CollectionEntryService.ts +0 -83
- package/src/classes/CollectionHandler.ts +0 -619
- package/src/classes/CollectionResourceService.ts +0 -38
- package/src/classes/ColumnCache.ts +0 -114
- package/src/classes/ColumnExpansion.ts +0 -74
- package/src/classes/ColumnHandler.ts +0 -90
- package/src/classes/ColumnSet.ts +0 -181
- package/src/classes/ColumnUtil.ts +0 -589
- package/src/classes/CreateRequest.ts +0 -158
- package/src/classes/ItemAdministrator.ts +0 -571
- package/src/classes/ItemCache.ts +0 -158
- package/src/classes/ItemEntryService.ts +0 -488
- package/src/classes/ItemHandler.ts +0 -592
- package/src/classes/ItemRequestService.ts +0 -229
- package/src/classes/ItemResourceService.ts +0 -36
- package/src/classes/KeyService.ts +0 -76
- package/src/classes/LockService.ts +0 -184
- package/src/classes/ModuleChangesCompiler.ts +0 -123
- package/src/classes/PromiseService.ts +0 -19
- package/src/classes/QueryMatcher.ts +0 -135
- package/src/classes/QueryParser.ts +0 -209
- package/src/classes/QueryService.ts +0 -35
- package/src/classes/RequestColumnExpansion.ts +0 -31
- package/src/classes/ResourceCache.ts +0 -289
- package/src/classes/Util.ts +0 -422
- package/src/constants.ts +0 -11
- package/src/factories/BatchStatusFactory.ts +0 -18
- package/src/factories/ChangesCompilerFactory.ts +0 -20
- package/src/factories/ChangesProcessorFactory.ts +0 -53
- package/src/factories/CollectionEntryFactory.ts +0 -35
- package/src/factories/CollectionResourceFactory.ts +0 -36
- package/src/factories/ColumnExpansionFactory.ts +0 -25
- package/src/factories/ColumnSetFactory.ts +0 -24
- package/src/factories/CreateRequestFactory.ts +0 -28
- package/src/factories/ItemCacheFactory.ts +0 -18
- package/src/factories/ItemEntryFactory.ts +0 -18
- package/src/factories/ItemResourceFactory.ts +0 -28
- package/src/factories/QueryMatcherFactory.ts +0 -20
- package/src/factories/QueryParserFactory.ts +0 -10
- package/src/factories/ResourceCacheFactory.ts +0 -55
- package/src/index.ts +0 -188
- package/src/interfaces/ApiRequestServiceInterface.ts +0 -17
- package/src/interfaces/AuthInterface.ts +0 -5
- package/src/interfaces/ResourceCacheInterface.ts +0 -9
- package/src/models/CollectionEditResource.ts +0 -139
- package/src/models/CollectionEntry.ts +0 -448
- package/src/models/CollectionResource.ts +0 -223
- package/src/models/EditResource.ts +0 -15
- package/src/models/ItemEntry.ts +0 -24
- package/src/models/ItemResource.ts +0 -35
- package/src/models/ViewResource.ts +0 -14
- package/tsconfig.json +0 -12
- package/tslint.json +0 -63
- package/webpack.common.js +0 -35
- package/webpack.dev.js +0 -10
- package/webpack.prod.js +0 -17
|
@@ -1,592 +0,0 @@
|
|
|
1
|
-
import { ENTRY_STATUS } from "../constants";
|
|
2
|
-
import BatchStatusFactory from "../factories/BatchStatusFactory";
|
|
3
|
-
import ColumnExpansionFactory from "../factories/ColumnExpansionFactory";
|
|
4
|
-
import ColumnSetFactory from "../factories/ColumnSetFactory";
|
|
5
|
-
import ItemCacheFactory from "../factories/ItemCacheFactory";
|
|
6
|
-
import ItemEntryFactory from "../factories/ItemEntryFactory";
|
|
7
|
-
import ApiRequestServiceInterface from '../interfaces/ApiRequestServiceInterface';
|
|
8
|
-
import AuthInterface from '../interfaces/AuthInterface';
|
|
9
|
-
import ErrorHandlerInterface from '../interfaces/ErrorHandlerInterface';
|
|
10
|
-
import ItemEntry from "../models/ItemEntry";
|
|
11
|
-
import ApiFormatter from "./ApiFormatter";
|
|
12
|
-
import ColumnHandler from './ColumnHandler';
|
|
13
|
-
import ColumnUtil from './ColumnUtil';
|
|
14
|
-
import ItemCache from "./ItemCache";
|
|
15
|
-
import ItemEntryService from "./ItemEntryService";
|
|
16
|
-
import KeyService from "./KeyService";
|
|
17
|
-
import PromiseService from "./PromiseService";
|
|
18
|
-
import { getFirstProperty, hasProperties } from './Util';
|
|
19
|
-
|
|
20
|
-
export default class ItemHandler {
|
|
21
|
-
entries: ItemCache;
|
|
22
|
-
templates = {};
|
|
23
|
-
|
|
24
|
-
constructor (
|
|
25
|
-
private apiRequestService: ApiRequestServiceInterface,
|
|
26
|
-
private authInterface: AuthInterface,
|
|
27
|
-
private errorHandler: ErrorHandlerInterface,
|
|
28
|
-
private itemEntryFactory: ItemEntryFactory,
|
|
29
|
-
private columnHandler: ColumnHandler,
|
|
30
|
-
private itemCacheFactory: ItemCacheFactory,
|
|
31
|
-
private batchStatusFactory: BatchStatusFactory,
|
|
32
|
-
private columnExpansionFactory: ColumnExpansionFactory,
|
|
33
|
-
private columnSetFactory: ColumnSetFactory,
|
|
34
|
-
private itemEntryService: ItemEntryService,
|
|
35
|
-
private apiFormatter: ApiFormatter,
|
|
36
|
-
private keyService: KeyService,
|
|
37
|
-
private promiseService: PromiseService,
|
|
38
|
-
private columnUtil: ColumnUtil
|
|
39
|
-
) {
|
|
40
|
-
this.entries = this.itemCacheFactory.construct();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
getItemId (itemEntry: ItemEntry) {
|
|
44
|
-
return itemEntry.itemId;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getPromise (itemEntry: ItemEntry) {
|
|
48
|
-
return itemEntry.deferred.promise;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
fetchItem (itemType: string, itemId: number, options: any) {
|
|
52
|
-
const entryStatus = this.getEntryStatus(itemType, itemId, options);
|
|
53
|
-
const itemEntry = entryStatus.entry;
|
|
54
|
-
const status = entryStatus.status;
|
|
55
|
-
|
|
56
|
-
if (status === ENTRY_STATUS.LOCAL) {
|
|
57
|
-
return this.fetchTemplate(itemType, options.templateOptions, options.templateColumns)
|
|
58
|
-
.then(
|
|
59
|
-
template => {
|
|
60
|
-
return this.resolveLocal(itemEntry, options.parent, template);
|
|
61
|
-
},
|
|
62
|
-
error => {
|
|
63
|
-
this.itemEntryService.reject(itemEntry, error);
|
|
64
|
-
|
|
65
|
-
return error;
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return this.resolveCached(itemEntry, status, options);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
fetchItems (itemType, itemIds, options) {
|
|
74
|
-
const batchStatus = this.batchStatusFactory.construct(
|
|
75
|
-
(itemEntry: ItemEntry) => this.getItemId(itemEntry),
|
|
76
|
-
(itemEntry: ItemEntry) => this.getPromise(itemEntry)
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const promises: any = {};
|
|
80
|
-
|
|
81
|
-
for (const itemId of itemIds)
|
|
82
|
-
batchStatus.add(this.getEntryStatus(itemType, itemId, options));
|
|
83
|
-
|
|
84
|
-
promises.entries = batchStatus.getPromises();
|
|
85
|
-
|
|
86
|
-
if (batchStatus.hasRequests())
|
|
87
|
-
promises.requests = this.requestItem(itemType, batchStatus.getRequestIds(), options.columns);
|
|
88
|
-
|
|
89
|
-
if (batchStatus.hasEntries([ENTRY_STATUS.LOCAL]))
|
|
90
|
-
promises.template = this.fetchTemplate(itemType, options.templateOptions, options.templateColumns);
|
|
91
|
-
|
|
92
|
-
return this.promiseService.all(promises).then(resolved => {
|
|
93
|
-
return this.batchResolve(itemType, batchStatus, options.columns, resolved);
|
|
94
|
-
},
|
|
95
|
-
this.errorHandler.reject
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
resolveCached (itemEntry: ItemEntry, status, options) {
|
|
100
|
-
const itemType = itemEntry.itemType;
|
|
101
|
-
const itemId = itemEntry.itemId;
|
|
102
|
-
const requestColumns = itemEntry.columns.request;
|
|
103
|
-
|
|
104
|
-
switch (status) {
|
|
105
|
-
case ENTRY_STATUS.CACHED:
|
|
106
|
-
return this.promiseService.when(itemEntry);
|
|
107
|
-
case ENTRY_STATUS.PROMISED:
|
|
108
|
-
return itemEntry.deferred.promise;
|
|
109
|
-
case ENTRY_STATUS.PROMISED_EXPAND:
|
|
110
|
-
return itemEntry.deferred.promise.then(
|
|
111
|
-
() => {
|
|
112
|
-
return this.resolveCached(
|
|
113
|
-
itemEntry,
|
|
114
|
-
this.getCachedEntryStatus(itemEntry, options),
|
|
115
|
-
options
|
|
116
|
-
);
|
|
117
|
-
},
|
|
118
|
-
this.errorHandler.reject
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (status === ENTRY_STATUS.EXPAND) {
|
|
123
|
-
const columnDifference = this.columnUtil.mergeRequestColumns(requestColumns, options.columns).difference;
|
|
124
|
-
|
|
125
|
-
this.requestItem(itemType, itemId, columnDifference).then(
|
|
126
|
-
response => {
|
|
127
|
-
this.resolveExpansion(
|
|
128
|
-
itemEntry,
|
|
129
|
-
this.columnExpansionFactory.construct(itemType, columnDifference, response.fetchColumnsObject()),
|
|
130
|
-
response
|
|
131
|
-
);
|
|
132
|
-
},
|
|
133
|
-
error => {
|
|
134
|
-
this.itemEntryService.reject(itemEntry, error);
|
|
135
|
-
}
|
|
136
|
-
);
|
|
137
|
-
} else {
|
|
138
|
-
this.requestItem(itemType, itemId, requestColumns).then(
|
|
139
|
-
response => {
|
|
140
|
-
this.resolveRemote(
|
|
141
|
-
itemEntry,
|
|
142
|
-
this.columnSetFactory.construct(itemType, requestColumns, response.fetchColumnsObject()),
|
|
143
|
-
response
|
|
144
|
-
);
|
|
145
|
-
},
|
|
146
|
-
error => {
|
|
147
|
-
this.itemEntryService.reject(itemEntry, error);
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return itemEntry.deferred.promise;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
resolveLocal (itemEntry: ItemEntry, parent, template) {
|
|
156
|
-
const itemType = itemEntry.itemType;
|
|
157
|
-
const itemId = itemEntry.itemId;
|
|
158
|
-
const conversionMap = this.createConversionMap(itemType, itemId, true, template.response);
|
|
159
|
-
|
|
160
|
-
itemEntry.columns = template.columns;
|
|
161
|
-
|
|
162
|
-
if (parent !== null)
|
|
163
|
-
this.itemEntryService.setParent(itemEntry, parent.itemType, parent.itemId); // create new object
|
|
164
|
-
|
|
165
|
-
this.itemEntryService.processLocal(
|
|
166
|
-
itemEntry,
|
|
167
|
-
template.fields,
|
|
168
|
-
{},
|
|
169
|
-
{},
|
|
170
|
-
conversionMap
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
this.setCreator(itemEntry);
|
|
174
|
-
|
|
175
|
-
this.itemEntryService.resolve(itemEntry);
|
|
176
|
-
|
|
177
|
-
return {
|
|
178
|
-
main: itemEntry,
|
|
179
|
-
linked: this.createLocalEntries(itemType, itemId, template, conversionMap)
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
resolveExpansion (itemEntry, columnExpansion, response) {
|
|
184
|
-
const itemType = itemEntry.itemType;
|
|
185
|
-
const itemId = itemEntry.itemId;
|
|
186
|
-
const expansionResult = columnExpansion(itemEntry.columns, true);
|
|
187
|
-
|
|
188
|
-
// Another request already requested the columns we need here, no need to expand the item and resolve it (already done by other request)
|
|
189
|
-
if (expansionResult === null)
|
|
190
|
-
return itemEntry;
|
|
191
|
-
|
|
192
|
-
this.itemEntryService.expand(
|
|
193
|
-
itemEntry,
|
|
194
|
-
response.fetchObject(itemType, itemId),
|
|
195
|
-
response.fetchDerivedObject(itemType, itemId, expansionResult.difference.root),
|
|
196
|
-
expansionResult
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
return this.itemEntryService.resolve(itemEntry);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
resolveRemote (itemEntry, columnInfo, response) {
|
|
203
|
-
const itemType = itemEntry.itemType;
|
|
204
|
-
const itemId = itemEntry.itemId;
|
|
205
|
-
const initial = response.fetchObject(itemType, itemId);
|
|
206
|
-
|
|
207
|
-
if (initial === undefined) { // query returned no results
|
|
208
|
-
this.itemEntryService.reject(itemEntry);
|
|
209
|
-
this.entries.clear(itemEntry);
|
|
210
|
-
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return this.resolveDeferredEntry(
|
|
215
|
-
itemEntry,
|
|
216
|
-
initial,
|
|
217
|
-
response.fetchDerivedObject(itemType, itemId, columnInfo.root),
|
|
218
|
-
columnInfo
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
fetchTemplate (itemType: string, templateOptions: any = {}, templateColumns: any = {}): Promise<any> {
|
|
223
|
-
const hasTemplateOptions = hasProperties(templateOptions);
|
|
224
|
-
const columnItemType = getFirstProperty(templateColumns); // it's possible to add columns to linked items
|
|
225
|
-
|
|
226
|
-
if (!hasTemplateOptions) {
|
|
227
|
-
const cachedTemplate = this.templates[itemType];
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
cachedTemplate !== undefined &&
|
|
231
|
-
(
|
|
232
|
-
columnItemType === null ||
|
|
233
|
-
this.columnUtil.responseColumnsAvailable(
|
|
234
|
-
columnItemType,
|
|
235
|
-
templateColumns[columnItemType],
|
|
236
|
-
cachedTemplate.responseColumns
|
|
237
|
-
)
|
|
238
|
-
)
|
|
239
|
-
) {
|
|
240
|
-
return this.promiseService.when(cachedTemplate);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return this.promiseService.all([
|
|
245
|
-
this.apiRequestService.template(itemType, templateOptions),
|
|
246
|
-
columnItemType === null ?
|
|
247
|
-
{} :
|
|
248
|
-
this.columnHandler.fetch(columnItemType, templateColumns[columnItemType])
|
|
249
|
-
]).then(
|
|
250
|
-
resolved => {
|
|
251
|
-
const templateResponse: any = resolved[0];
|
|
252
|
-
const responseColumns = this.columnUtil.mergeResponseColumns(
|
|
253
|
-
templateResponse.fetchColumnsObject(),
|
|
254
|
-
resolved[1]
|
|
255
|
-
).merged;
|
|
256
|
-
const template = {
|
|
257
|
-
fields: templateResponse.fetchObject(
|
|
258
|
-
itemType,
|
|
259
|
-
templateResponse.links[itemType][0]
|
|
260
|
-
),
|
|
261
|
-
columns: this.columnSetFactory.construct(itemType, true, responseColumns),
|
|
262
|
-
response: templateResponse,
|
|
263
|
-
responseColumns: responseColumns
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
if (!hasTemplateOptions && templateResponse.cacheable)
|
|
267
|
-
this.templates[itemType] = template;
|
|
268
|
-
|
|
269
|
-
return template;
|
|
270
|
-
},
|
|
271
|
-
this.errorHandler.reject
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
getEntryStatus (itemType: string, itemId: number, options: any) {
|
|
276
|
-
const cachedEntry: ItemEntry = this.entries.get(itemType, itemId);
|
|
277
|
-
|
|
278
|
-
if (cachedEntry === undefined) {
|
|
279
|
-
if (this.keyService.isLocalId(itemId)) {
|
|
280
|
-
return {
|
|
281
|
-
entry: this.createDeferredEntry(itemType, itemId, true, false),
|
|
282
|
-
status: ENTRY_STATUS.LOCAL
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return {
|
|
287
|
-
entry: this.createDeferredEntry(itemType, itemId, options.columns, options.deferRequest),
|
|
288
|
-
status: options.deferRequest ? ENTRY_STATUS.PROMISED : ENTRY_STATUS.RESOLVE
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return {entry: cachedEntry, status: this.getCachedEntryStatus(cachedEntry, options)};
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
getCachedEntryStatus (itemEntry: ItemEntry, options) {
|
|
296
|
-
const columns = itemEntry.columns;
|
|
297
|
-
const isColumnSubset = this.itemEntryService.isLocal(itemEntry) ||
|
|
298
|
-
this.columnUtil.isColumnSubset(options.columns, columns.request, columns.true);
|
|
299
|
-
|
|
300
|
-
if (itemEntry.deferred !== undefined) {
|
|
301
|
-
if (itemEntry.deferRequest) {
|
|
302
|
-
columns.request = this.columnUtil.mergeRequestColumns(columns.request, options.columns).merged;
|
|
303
|
-
|
|
304
|
-
return ENTRY_STATUS.RESOLVE;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return isColumnSubset ? ENTRY_STATUS.PROMISED : ENTRY_STATUS.PROMISED_EXPAND;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
if (isColumnSubset)
|
|
311
|
-
return ENTRY_STATUS.CACHED;
|
|
312
|
-
|
|
313
|
-
this.itemEntryService.defer(itemEntry, false);
|
|
314
|
-
|
|
315
|
-
return ENTRY_STATUS.EXPAND;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
createDeferredEntry (itemType: string, itemId: number, requestColumns, deferRequest) {
|
|
319
|
-
const itemEntry = this.createEntryStub(itemType, itemId);
|
|
320
|
-
|
|
321
|
-
itemEntry.columns = {
|
|
322
|
-
itemType: itemType,
|
|
323
|
-
request: requestColumns,
|
|
324
|
-
true: requestColumns === true
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
return this.itemEntryService.defer(itemEntry, deferRequest);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
createEntryStub (itemType: string, itemId: number) {
|
|
331
|
-
return this.entries.add(
|
|
332
|
-
this.itemEntryFactory.construct(
|
|
333
|
-
itemType,
|
|
334
|
-
itemId
|
|
335
|
-
)
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
createEntry (itemId: number, initial, derived, columnInfo) {
|
|
340
|
-
return this.itemEntryService.process(
|
|
341
|
-
this.entries.add(
|
|
342
|
-
this.itemEntryFactory.construct(
|
|
343
|
-
columnInfo.itemType,
|
|
344
|
-
itemId,
|
|
345
|
-
columnInfo,
|
|
346
|
-
initial,
|
|
347
|
-
derived
|
|
348
|
-
)
|
|
349
|
-
)
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
resolveDeferredEntry (itemEntry, initial, derived, columns) {
|
|
354
|
-
itemEntry.columns = columns;
|
|
355
|
-
itemEntry.initial = initial;
|
|
356
|
-
itemEntry.derived = derived;
|
|
357
|
-
|
|
358
|
-
this.itemEntryService.process(itemEntry);
|
|
359
|
-
|
|
360
|
-
return this.itemEntryService.resolve(itemEntry);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
batchResolve (itemType, batchStatus, requestColumns, resolved) {
|
|
364
|
-
const response = resolved.requests;
|
|
365
|
-
const expandStatus = [ENTRY_STATUS.EXPAND, ENTRY_STATUS.PROMISED_EXPAND];
|
|
366
|
-
const resolveStatus = [ENTRY_STATUS.RESOLVE];
|
|
367
|
-
|
|
368
|
-
let success = true;
|
|
369
|
-
|
|
370
|
-
if (batchStatus.hasEntries(expandStatus)) {
|
|
371
|
-
const columnExpansion = this.columnExpansionFactory.construct(itemType, requestColumns, response.fetchColumnsObject());
|
|
372
|
-
|
|
373
|
-
batchStatus.forEachEntry(
|
|
374
|
-
expandStatus, itemEntry => {
|
|
375
|
-
this.resolveExpansion(itemEntry, columnExpansion, response);
|
|
376
|
-
}
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
if (batchStatus.hasEntries(resolveStatus)) {
|
|
381
|
-
const columnInfo = this.columnSetFactory.construct(itemType, requestColumns, response.fetchColumnsObject());
|
|
382
|
-
|
|
383
|
-
batchStatus.forEachEntry(
|
|
384
|
-
resolveStatus, itemEntry => {
|
|
385
|
-
if (this.resolveRemote(itemEntry, columnInfo, response) === null)
|
|
386
|
-
success = false;
|
|
387
|
-
}
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
batchStatus.forEachEntry(
|
|
392
|
-
[ENTRY_STATUS.LOCAL], itemEntry => {
|
|
393
|
-
this.resolveLocal(itemEntry, null, resolved.template);
|
|
394
|
-
}
|
|
395
|
-
);
|
|
396
|
-
|
|
397
|
-
return success ? batchStatus.getArray() : this.errorHandler.reject({message: this.itemEntryService.undefinedItemError});
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
cloneItem (newItemId, itemEntry, conversionMap?) {
|
|
401
|
-
const columns = itemEntry.columns;
|
|
402
|
-
const parent = itemEntry.parent;
|
|
403
|
-
|
|
404
|
-
if (conversionMap === undefined) {
|
|
405
|
-
conversionMap = {
|
|
406
|
-
[itemEntry.itemType]: {
|
|
407
|
-
[itemEntry.itemId]: newItemId
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// we'll copy modified to result.initial (initial may be a template)
|
|
413
|
-
const result = this.createEntry(
|
|
414
|
-
newItemId,
|
|
415
|
-
this.apiFormatter.copyFields(this.itemEntryService.getFields(itemEntry), {}, columns.main),
|
|
416
|
-
this.apiFormatter.copyFields(itemEntry.derived, {}, columns.derived),
|
|
417
|
-
columns
|
|
418
|
-
);
|
|
419
|
-
|
|
420
|
-
this.itemEntryService.updateItemFields(result, conversionMap);
|
|
421
|
-
|
|
422
|
-
result.modified = this.apiFormatter.copyFields(result.initial, {}, columns.main);
|
|
423
|
-
|
|
424
|
-
if (!parent)
|
|
425
|
-
return result;
|
|
426
|
-
|
|
427
|
-
return this.itemEntryService.setParent(result, parent.itemType, parent.itemId);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
createConversionMap (itemType: string, itemId: number, extend: boolean, response) {
|
|
431
|
-
const apiItemId = response.links[itemType][0];
|
|
432
|
-
const result = {
|
|
433
|
-
[itemType]: {
|
|
434
|
-
[apiItemId]: itemId
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
if (extend)
|
|
439
|
-
this.extendConversionMap(
|
|
440
|
-
result,
|
|
441
|
-
response.items[itemType][apiItemId].links,
|
|
442
|
-
response
|
|
443
|
-
);
|
|
444
|
-
|
|
445
|
-
return result;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
createLocalEntries (parentType: string, localParentId: number, template, conversionMap) {
|
|
449
|
-
const self = this;
|
|
450
|
-
const apiResponse = template.response;
|
|
451
|
-
const columnInfoMap = {};
|
|
452
|
-
const itemEntryMap = {};
|
|
453
|
-
const result = [];
|
|
454
|
-
|
|
455
|
-
// TODO: disable caching?
|
|
456
|
-
for (const itemType in apiResponse.items) {
|
|
457
|
-
if (itemType === parentType)
|
|
458
|
-
continue;
|
|
459
|
-
|
|
460
|
-
columnInfoMap[itemType] = this.columnSetFactory.construct(
|
|
461
|
-
itemType,
|
|
462
|
-
true,
|
|
463
|
-
template.responseColumns
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
const createEntries = (parentType2, localParentId2, apiParentId) => {
|
|
468
|
-
const parent = {itemType: parentType2, itemId: localParentId2};
|
|
469
|
-
const links = apiResponse.items[parentType2][apiParentId].links;
|
|
470
|
-
|
|
471
|
-
for (const itemType in links) {
|
|
472
|
-
const idArray = links[itemType];
|
|
473
|
-
|
|
474
|
-
// the item entries should be added to the result in top-down order
|
|
475
|
-
if (itemEntryMap[itemType] === undefined)
|
|
476
|
-
result.push({itemType: itemType, itemEntries: itemEntryMap[itemType] = []});
|
|
477
|
-
|
|
478
|
-
for (const apiItemId of idArray) {
|
|
479
|
-
const localItemId = conversionMap[itemType][apiItemId];
|
|
480
|
-
const itemEntry = self.createEntryStub(itemType, localItemId);
|
|
481
|
-
|
|
482
|
-
itemEntry.columns = columnInfoMap[itemType];
|
|
483
|
-
itemEntry.parent = parent;
|
|
484
|
-
|
|
485
|
-
this.itemEntryService.processLocal(
|
|
486
|
-
itemEntry,
|
|
487
|
-
apiResponse.fetchObject(itemType, apiItemId),
|
|
488
|
-
{},
|
|
489
|
-
{},
|
|
490
|
-
conversionMap
|
|
491
|
-
);
|
|
492
|
-
|
|
493
|
-
this.setCreator(itemEntry);
|
|
494
|
-
|
|
495
|
-
itemEntryMap[itemType].push(itemEntry);
|
|
496
|
-
|
|
497
|
-
createEntries(itemType, localItemId, apiItemId);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
createEntries(parentType, localParentId, apiResponse.links[parentType][0]);
|
|
503
|
-
|
|
504
|
-
return result;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
createLocalEntry (itemId: number, template, modified, derived, parent = null) {
|
|
508
|
-
const itemType = template.columns.itemType;
|
|
509
|
-
const itemEntry = this.createEntryStub(itemType, itemId);
|
|
510
|
-
|
|
511
|
-
itemEntry.columns = template.columns;
|
|
512
|
-
|
|
513
|
-
if (parent !== null)
|
|
514
|
-
itemEntry.parent = parent;
|
|
515
|
-
|
|
516
|
-
this.itemEntryService.processLocal(
|
|
517
|
-
itemEntry,
|
|
518
|
-
template.fields,
|
|
519
|
-
modified,
|
|
520
|
-
derived,
|
|
521
|
-
this.createConversionMap(itemType, itemId, false, template.response)
|
|
522
|
-
);
|
|
523
|
-
|
|
524
|
-
this.setCreator(itemEntry);
|
|
525
|
-
|
|
526
|
-
return itemEntry;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
extendConversionMap (conversionMap, links, apiResponse) {
|
|
530
|
-
for (const itemType in links) {
|
|
531
|
-
const idArray = links[itemType];
|
|
532
|
-
|
|
533
|
-
if (conversionMap[itemType] === undefined)
|
|
534
|
-
conversionMap[itemType] = {};
|
|
535
|
-
|
|
536
|
-
for (const apiItemId of idArray) {
|
|
537
|
-
conversionMap[itemType][apiItemId] = this.keyService.getLocalId();
|
|
538
|
-
|
|
539
|
-
this.extendConversionMap(
|
|
540
|
-
conversionMap,
|
|
541
|
-
apiResponse.items[itemType][apiItemId].links,
|
|
542
|
-
apiResponse
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
fetchTitle (itemType: string, itemId: number, deferRequest = true) {
|
|
549
|
-
const titleField = this.itemEntryService.getTitleField(itemType);
|
|
550
|
-
|
|
551
|
-
return this.fetchItem(
|
|
552
|
-
itemType,
|
|
553
|
-
itemId,
|
|
554
|
-
this.itemEntryService.processOptions({
|
|
555
|
-
columns: [titleField],
|
|
556
|
-
deferRequest: deferRequest
|
|
557
|
-
})
|
|
558
|
-
).then(
|
|
559
|
-
(entry: ItemEntry | any) => {
|
|
560
|
-
// fetchItem can also return linked items
|
|
561
|
-
if (entry.main !== undefined)
|
|
562
|
-
return entry.main.initial[titleField];
|
|
563
|
-
|
|
564
|
-
if (entry.modified !== undefined)
|
|
565
|
-
return entry.modified[titleField];
|
|
566
|
-
|
|
567
|
-
return entry.initial[titleField];
|
|
568
|
-
},
|
|
569
|
-
this.errorHandler.reject
|
|
570
|
-
);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
requestItem (itemType: string, itemId: number | number[], columns) {
|
|
574
|
-
const requestColumns = {
|
|
575
|
-
[itemType]: columns
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
return this.apiRequestService.query(itemType, {id: itemId}, requestColumns);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
updateItemId (itemEntry, itemId) {
|
|
582
|
-
const oldItemId = itemEntry.itemId;
|
|
583
|
-
itemEntry.itemId = itemId;
|
|
584
|
-
|
|
585
|
-
return this.entries.updateItemId(itemEntry, oldItemId);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
private setCreator (itemEntry: ItemEntry) {
|
|
589
|
-
itemEntry.modified.creator = this.authInterface.getUserId();
|
|
590
|
-
itemEntry.derived['creator>displayname'] = this.authInterface.getUserDisplayname();
|
|
591
|
-
}
|
|
592
|
-
}
|