rest-client-vue 1.0.0-a1
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/LICENSE +7 -0
- package/README.md +15 -0
- package/dist/rest-client-vue.js +1254 -0
- package/dist/rest-client-vue.umd.cjs +1 -0
- package/dist/src/config.d.ts +12 -0
- package/dist/src/errors.d.ts +5 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/queries.d.ts +95 -0
- package/dist/src/rest-collection-resources.d.ts +30 -0
- package/dist/src/rest-collection.d.ts +308 -0
- package/dist/src/rest-resource.d.ts +140 -0
- package/dist/src/rest-store-registry.d.ts +9 -0
- package/dist/src/stores/rest-collection-store.d.ts +775 -0
- package/dist/src/stores/rest-resource-store.d.ts +277 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +73 -0
@@ -0,0 +1,775 @@
|
|
1
|
+
import { SelectResourcesOptions, SetTransientDataParams } from '../rest-collection.js';
|
2
|
+
import { Resource, ResourceId } from '../rest-collection-resources.js';
|
3
|
+
import { QueryClause, QueryOrder } from '../queries.js';
|
4
|
+
import { StoreRegistry } from '../rest-store-registry.js';
|
5
|
+
/** A filter that limits the local REST collection to a subset of the remote collection. */
|
6
|
+
export interface RestCollectionFilter {
|
7
|
+
namedFilter: string | null;
|
8
|
+
query: any | null;
|
9
|
+
resourceIds: ResourceId[] | null;
|
10
|
+
}
|
11
|
+
/** Options that govern the behavior of a REST collection's data store. */
|
12
|
+
export interface RestCollectionStoreOptions {
|
13
|
+
detail: {
|
14
|
+
allowMultiple: boolean;
|
15
|
+
autoEdit: boolean;
|
16
|
+
autoFromMultipleSelection: boolean;
|
17
|
+
autoFromSingleInsertion: boolean;
|
18
|
+
autoFromSingleSelection: boolean;
|
19
|
+
constrainToSelection: boolean;
|
20
|
+
};
|
21
|
+
filter: RestCollectionFilter;
|
22
|
+
idProperty: string;
|
23
|
+
limit: number | null;
|
24
|
+
limitTransientDataToLocalCollection: boolean;
|
25
|
+
loading: {
|
26
|
+
firstPageSize?: number;
|
27
|
+
pageSize?: number;
|
28
|
+
};
|
29
|
+
order?: QueryOrder;
|
30
|
+
referencePathsToExpand?: string[];
|
31
|
+
restCollectionUrl: string;
|
32
|
+
}
|
33
|
+
/** Default options that govern the behavior of a REST collection's data store */
|
34
|
+
export declare const DEFAULT_REST_COLLECTION_STORE_OPTIONS: Omit<RestCollectionStoreOptions, 'restCollectionUrl'>;
|
35
|
+
export type RestCollectionStatus = 'Uninitialized' | 'NotLoaded' | 'Loading' | 'LoadingMore' | 'Loaded' | 'Failed';
|
36
|
+
export type RestCollectionStoreStatus = 'NotLoaded' | 'Loading' | 'LoadingMore' | 'Loaded' | 'Failed';
|
37
|
+
/** A REST collection's state, including settings and contents. */
|
38
|
+
export interface RestCollectionStoreState {
|
39
|
+
idProperty: string;
|
40
|
+
filter: RestCollectionFilter;
|
41
|
+
order: QueryOrder | null;
|
42
|
+
referencePathsToExpand: string[] | null;
|
43
|
+
resources: Resource[];
|
44
|
+
status: RestCollectionStoreStatus;
|
45
|
+
selection: Resource[];
|
46
|
+
detailSelection: Resource[];
|
47
|
+
invalidResources: Resource[];
|
48
|
+
listNavigators: {
|
49
|
+
[name: string]: any;
|
50
|
+
};
|
51
|
+
editingDetailSelection: boolean;
|
52
|
+
batchSaveAttempted: boolean;
|
53
|
+
editors: any[];
|
54
|
+
transientData: {
|
55
|
+
[id: ResourceId]: any;
|
56
|
+
};
|
57
|
+
_loadId?: string;
|
58
|
+
_loadOffset?: number;
|
59
|
+
}
|
60
|
+
interface RestCollectionLoadOptions {
|
61
|
+
firstPageSize?: number;
|
62
|
+
pageSize?: number;
|
63
|
+
}
|
64
|
+
interface RestCollectionQueryParams {
|
65
|
+
/** Name of a predefined filter. */
|
66
|
+
namedFilter?: string;
|
67
|
+
/** Deterministically JSON-serialized representation of a QueryClause. */
|
68
|
+
q?: string;
|
69
|
+
/** Deterministically JSON-serialized representation of a QueryOrder. */
|
70
|
+
o?: string;
|
71
|
+
/** Deterministically JSON-serialized array of path strings to expand. */
|
72
|
+
r?: string;
|
73
|
+
/** Page offset, the 0-based index of the first resource to return. */
|
74
|
+
offset?: number;
|
75
|
+
/** Page size, the maximum number of resources to return. */
|
76
|
+
limit?: number;
|
77
|
+
}
|
78
|
+
declare const makeStore: (storeId: string, options: RestCollectionStoreOptions) => import("pinia").StoreDefinition<string, RestCollectionStoreState, {
|
79
|
+
/**
|
80
|
+
* Get the REST query parameters that can be determined from the collection options.
|
81
|
+
*
|
82
|
+
* This includes all query parameters except offset and limit, which vary from request to request.
|
83
|
+
*/
|
84
|
+
fixedQueryParams: (state: {
|
85
|
+
idProperty: string;
|
86
|
+
filter: {
|
87
|
+
namedFilter: string | null;
|
88
|
+
query: any | null;
|
89
|
+
resourceIds: ResourceId[] | null;
|
90
|
+
};
|
91
|
+
order: ({
|
92
|
+
path: string;
|
93
|
+
sqlType?: string | undefined;
|
94
|
+
} | [{
|
95
|
+
path: string;
|
96
|
+
sqlType?: string | undefined;
|
97
|
+
}, import("../queries.js").QueryOrderDirection])[] | null;
|
98
|
+
referencePathsToExpand: string[] | null;
|
99
|
+
resources: Resource[];
|
100
|
+
status: RestCollectionStoreStatus;
|
101
|
+
selection: Resource[];
|
102
|
+
detailSelection: Resource[];
|
103
|
+
invalidResources: Resource[];
|
104
|
+
listNavigators: {
|
105
|
+
[name: string]: any;
|
106
|
+
};
|
107
|
+
editingDetailSelection: boolean;
|
108
|
+
batchSaveAttempted: boolean;
|
109
|
+
editors: any[];
|
110
|
+
transientData: {
|
111
|
+
[id: string]: any;
|
112
|
+
[id: number]: any;
|
113
|
+
};
|
114
|
+
_loadId?: string | undefined;
|
115
|
+
_loadOffset?: number | undefined;
|
116
|
+
} & import("pinia").PiniaCustomStateProperties<RestCollectionStoreState>) => RestCollectionQueryParams;
|
117
|
+
}, {
|
118
|
+
/**
|
119
|
+
* Reset the store to its initial state.
|
120
|
+
*
|
121
|
+
* Configuration is retained, but REST collection contents and contextual state are reset.
|
122
|
+
*/
|
123
|
+
reset(): void;
|
124
|
+
/**
|
125
|
+
* Reset the store to its initial state, but retain transient data if appropriate.
|
126
|
+
*
|
127
|
+
* As with {@link reset}, configuration is retained, but REST collection contents and contextual state are reset.
|
128
|
+
* Transient data are retained if options.limitTransientDataToLocalCollection is false.
|
129
|
+
*/
|
130
|
+
resetRetainingTransientData(): void;
|
131
|
+
/**
|
132
|
+
* Turn editing mode on or off for the current detail selection.
|
133
|
+
*
|
134
|
+
* Components using this store use the editingDetailSelection state property to govern whether to show an editor for
|
135
|
+
* any current detail selection.
|
136
|
+
*
|
137
|
+
* @param editingDetailSelection The new setting: true if an the detail selection should be shown in an editor,
|
138
|
+
* false if not.
|
139
|
+
*/
|
140
|
+
setEditingDetailSelection(editingDetailSelection: boolean): void;
|
141
|
+
/**
|
142
|
+
* Set the filter.
|
143
|
+
*
|
144
|
+
* This function sets the whole filter without triggering a reload of the local collection. More commonly, clients
|
145
|
+
* will call {@link setQuery} or {@link setFilterResourceIds}.
|
146
|
+
*
|
147
|
+
* @param filter The new filter.
|
148
|
+
*/
|
149
|
+
setFilter(filter: RestCollectionFilter): void;
|
150
|
+
/**
|
151
|
+
* Set the filter query.
|
152
|
+
*
|
153
|
+
* If the collection has a state other than NotLoaded, it will be reloaded.
|
154
|
+
*
|
155
|
+
* @param query The new filter query.
|
156
|
+
* @return A promise that resolves when {@link loadResources} completes, or immediately if the collection does not
|
157
|
+
* need to be reloaded.
|
158
|
+
*/
|
159
|
+
setQuery(query: QueryClause | null): Promise<void>;
|
160
|
+
/**
|
161
|
+
* Set the list if resource IDs to filter on.
|
162
|
+
*
|
163
|
+
* If the collection has a state other than NotLoaded, it will be reloaded.
|
164
|
+
*
|
165
|
+
* @param resourceIds The list of resource IDs for the new filter.
|
166
|
+
* @return A promise that resolves when {@link loadResources} completes, or immediately if the collection does not
|
167
|
+
* need to be reloaded.
|
168
|
+
*/
|
169
|
+
setFilterResourceIds(resourceIds: ResourceId[] | null): Promise<void>;
|
170
|
+
/**
|
171
|
+
* Indicate that a batch save has been attempted and failed.
|
172
|
+
*
|
173
|
+
* Setting this flag is a way of communicating with other client code. The flag should be cleared after further
|
174
|
+
* edits or when another validation or save operations is attempted.
|
175
|
+
*
|
176
|
+
* @param batchSaveAttempted A flag indicating whether a batch save has been attempted and failed.
|
177
|
+
*/
|
178
|
+
setBatchSaveAttempted(batchSaveAttempted: boolean): void;
|
179
|
+
/**
|
180
|
+
* Clear the collection's contents.
|
181
|
+
*
|
182
|
+
* Configuration and contextual state are retained, but REST collection contents are reset.
|
183
|
+
*/
|
184
|
+
clear(): void;
|
185
|
+
/**
|
186
|
+
* Clear the collection's contents, but retain transient data if appropriate.
|
187
|
+
*
|
188
|
+
* As with {@link reset}, configuration and contextual state are retained, but REST collection contents are reset.
|
189
|
+
* Transient data are retained if options.limitTransientDataToLocalCollection is false.
|
190
|
+
*/
|
191
|
+
clearRetainingTransientData(): void;
|
192
|
+
/**
|
193
|
+
* Load the collection, if it has not been loaded.
|
194
|
+
*
|
195
|
+
* The collection will be loaded if its current status is not Loaded, Loading, LoadingMore, or Failed.
|
196
|
+
*/
|
197
|
+
ensureCollectionLoaded(): Promise<void>;
|
198
|
+
/**
|
199
|
+
* Load the collection.
|
200
|
+
*
|
201
|
+
* If pagination is enabled, this may result in multiple HTTP requests. The function's Promise is resolved once
|
202
|
+
* the first page is loaded.
|
203
|
+
*
|
204
|
+
* @param loadOptions Pagination options that may override the defaults.
|
205
|
+
*/
|
206
|
+
loadResources(loadOptions?: RestCollectionLoadOptions): Promise<void>;
|
207
|
+
/**
|
208
|
+
* Load the collection, optionally starting at some offset.
|
209
|
+
*
|
210
|
+
* If pagination is enabled, this may result in multiple HTTP requests. The function's Promise is resolved once
|
211
|
+
* the first page is loaded.
|
212
|
+
*
|
213
|
+
* @param offset The offset at which to start loading. When loading a whole collection, this will be 0; but if
|
214
|
+
* there are more pages to load, the function will call itself with the next page offset.
|
215
|
+
* @param loadId A unique identifier for this load operation, which is used to detect whether results should be
|
216
|
+
* discarded because a later load operation has been issued. Before calling this method, this identifier should
|
217
|
+
* be written to the store's state property named loadId.
|
218
|
+
* @param loadOptions Pagination options that may override the defaults.
|
219
|
+
*/
|
220
|
+
_loadResources(offset: number, loadId: string, loadOptions: RestCollectionLoadOptions): Promise<void>;
|
221
|
+
/**
|
222
|
+
* Verify that a resource does not exist in the remote collection.
|
223
|
+
*
|
224
|
+
* After checking the remote collection and verifying that the resource does not exist, this function calls
|
225
|
+
* {@link recordDeletion} to delete it from the local collection.
|
226
|
+
*
|
227
|
+
* @param itemId The ID of the deleted resource to check.
|
228
|
+
* @return true if the record does not exist in the remote collection, false if it does or if an error occurred.
|
229
|
+
*/
|
230
|
+
checkForDeletedResource(itemId: ResourceId): Promise<boolean>;
|
231
|
+
/**
|
232
|
+
* Record a deletion, removing the deleted resource from the local collection.
|
233
|
+
*
|
234
|
+
* This should be called after deleting a resource from the remote collection. It is called, for instance, by
|
235
|
+
* {@link deleteResource}; but it can also be called when the application is aware of deletions from the remote
|
236
|
+
* collection made by other means.
|
237
|
+
*
|
238
|
+
* @param resourceId The ID of the resource that has been deleted.
|
239
|
+
*/
|
240
|
+
recordDeletion(resourceId: ResourceId): void;
|
241
|
+
/**
|
242
|
+
* Record an insertion, adding the inserted resource to the local collection.
|
243
|
+
*
|
244
|
+
* This should be called after inserting a resource into the remote collection. It is called, for instance, by
|
245
|
+
* {@link saveResource}; but it can also be called when the application is aware of insertions into the remote
|
246
|
+
* collection made by other means.
|
247
|
+
*
|
248
|
+
* It is important that the resources to be added to the local collection have the same object-graph
|
249
|
+
* characteristics as other resources in the local collection. (These characteristics include property inclusions
|
250
|
+
* and exclusions, as well as reference expansions.) To ensure this, you may call {@refreshResource} to fetch the
|
251
|
+
* resource using the collection's settings.
|
252
|
+
*
|
253
|
+
* @param resource The item that has been inserted.
|
254
|
+
* @param TODO
|
255
|
+
*/
|
256
|
+
recordInsertion(resource: Resource, { insertAtBeginning, transientData }?: {
|
257
|
+
insertAtBeginning?: boolean | undefined;
|
258
|
+
transientData?: any;
|
259
|
+
}): void;
|
260
|
+
/**
|
261
|
+
* Record an update, making the same changes in the local collection.
|
262
|
+
*
|
263
|
+
* This should be called after updating a resource in the remote collection. It is called, for instance, by
|
264
|
+
* {@link saveResource} and {@link refreshResource}; but it can also be called when the application is aware of
|
265
|
+
* updates in the remote collection made by other means.
|
266
|
+
*
|
267
|
+
* It is important that the resource have the same object-graph characteristics as other resources in the local
|
268
|
+
* collection. (These characteristics include property inclusions and exclusions, as well as reference
|
269
|
+
* expansions.) To ensure this, you may instead call {@refreshResource} to fetch the resource using the
|
270
|
+
* collection's settings; this will in turn call {@link recordUpdate}.
|
271
|
+
*
|
272
|
+
* @param resource The item that has been updated.
|
273
|
+
*/
|
274
|
+
recordUpdate(resource: Resource): void;
|
275
|
+
/**
|
276
|
+
* Refresh a resource by requesting it from the remote collection.
|
277
|
+
*
|
278
|
+
* If the resource already exists in the local collection, {@link recordUpdate} will be called to update it there.
|
279
|
+
* If not, this method will return the resource but will not add it to the collection.
|
280
|
+
*
|
281
|
+
* This function is called by {@link insertItem} and {@link updateItem} to ensure that the local copy of the added
|
282
|
+
* or updated resource has the same object-graph characteristics as the rest of the local collection.
|
283
|
+
*
|
284
|
+
* @param resourceId The ID of the resource to refresh.
|
285
|
+
* @return The refreshed resource, or null if refreshing failed.
|
286
|
+
*/
|
287
|
+
refreshResource(resourceId: ResourceId): Promise<Resource | null>;
|
288
|
+
/**
|
289
|
+
* Insert a new unsaved resource into the local collection and enter editing mode.
|
290
|
+
*
|
291
|
+
* @param resourceDefaults Initial properties of the new resource.
|
292
|
+
*/
|
293
|
+
addResource(resourceDefaults?: Resource): void;
|
294
|
+
/**
|
295
|
+
* Delete one resource.
|
296
|
+
*
|
297
|
+
* A delete request is sent to the REST API. If it succeeds, the resource is removed from the local collection.
|
298
|
+
*
|
299
|
+
* @param resourceId The ID of the resource to delete.
|
300
|
+
*/
|
301
|
+
deleteResource(resourceId: ResourceId): Promise<void>;
|
302
|
+
/**
|
303
|
+
* Write a new or updated resource to the remote collection, then mirror the change in the local collection.
|
304
|
+
*
|
305
|
+
* After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the
|
306
|
+
* return value) has the same object-graph characteristics as the rest of the local collection.
|
307
|
+
*
|
308
|
+
* @param resource The new or updated resource. If it has an ID, an update will be attempted; otherwise it will be
|
309
|
+
* created.
|
310
|
+
* @returns The refreshed local resource after the change has been persisted to the remote collection, or null if
|
311
|
+
* the operation failed.
|
312
|
+
*/
|
313
|
+
saveResource(resource: Resource): Promise<Resource | null>;
|
314
|
+
/**
|
315
|
+
* Write new and/or updated resources to the remote collection, and mirror the changes in the local collection.
|
316
|
+
*
|
317
|
+
* After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the
|
318
|
+
* return value) has the same object-graph characteristics as the rest of the local collection.
|
319
|
+
*
|
320
|
+
* @param resources Resources to create or update. The two operations may be mixed in the list; when a resource
|
321
|
+
* has an ID, an update will be attempted, while otherwise it will be added.
|
322
|
+
* @returns An array of refreshed local resources, one for each remote resource whose save operation succeeded.
|
323
|
+
*/
|
324
|
+
saveResources(resources: Resource[]): Promise<any[]>;
|
325
|
+
/** Clear all transient data. */
|
326
|
+
clearTransientData(): void;
|
327
|
+
/**
|
328
|
+
* Record which local resources currently fail validation.
|
329
|
+
*
|
330
|
+
* This is useful in multi-resource editing contexts.
|
331
|
+
*
|
332
|
+
* @param resourceIds The IDs of all local resources that failed validation.
|
333
|
+
*/
|
334
|
+
setInvalidResourceIds(resourceIds: ResourceId[]): void;
|
335
|
+
/**
|
336
|
+
* Set transient data.
|
337
|
+
*
|
338
|
+
* @param transientData The new transient data.
|
339
|
+
* @param merge If true, combine each resource's transient data with existing transient data; if false, replace
|
340
|
+
* the transient data for each resource ID in the keys of transientData.
|
341
|
+
*/
|
342
|
+
setTransientDataForResources(params: SetTransientDataParams): void;
|
343
|
+
/**
|
344
|
+
* Clear the selection.
|
345
|
+
*/
|
346
|
+
clearSelection(): void;
|
347
|
+
/**
|
348
|
+
* Remove resources from the selection.
|
349
|
+
*
|
350
|
+
* @param resourceIds The IDs of resources to remove from the selection.
|
351
|
+
*/
|
352
|
+
deselectResources(resourceIds: ResourceId[]): void;
|
353
|
+
/**
|
354
|
+
* Add to or replace the selection.
|
355
|
+
*
|
356
|
+
* @param recordIds The record IDs to select.
|
357
|
+
* @param addToSelection true if the existing selection should be expanded, false if it should be replaced.
|
358
|
+
* @param edit If not undefined, sets the editing mode of the new selection. If undefined, the editing mode will
|
359
|
+
* be left as is, or set to true if options.detail.autoEdit is true.
|
360
|
+
*/
|
361
|
+
selectResources(resourceIds: ResourceId[], options?: SelectResourcesOptions): void;
|
362
|
+
/**
|
363
|
+
* Set a new selection.
|
364
|
+
*
|
365
|
+
* @param selectedResourceIds The resource IDs in the new selection.
|
366
|
+
* @param edit If not undefined, sets the editing mode of the new selection. If undefined, the editing mode will
|
367
|
+
* be left as is, or set to true if options.detail.autoEdit is true.
|
368
|
+
*/
|
369
|
+
setSelection(selectedResourceIds: ResourceId[], edit?: boolean): void;
|
370
|
+
/**
|
371
|
+
* Hide the detail view.
|
372
|
+
*
|
373
|
+
* This clears detailSelection and sets the detail editing mode to false.
|
374
|
+
*/
|
375
|
+
hideDetail(): void;
|
376
|
+
/**
|
377
|
+
* Show the current selection in the detail view.
|
378
|
+
*
|
379
|
+
* If options.detail.allowMultiple is false and more than one resource is selected, the detail view will not be
|
380
|
+
* changed.
|
381
|
+
*
|
382
|
+
* @param edit If not undefined, sets the detail editing mode. If undefined, the editing mode will be left as is,
|
383
|
+
* or set to true if options.detail.autoEdit is true.
|
384
|
+
*/
|
385
|
+
showSelectionAsDetail(edit: boolean): void;
|
386
|
+
/**
|
387
|
+
* Deregister an editor.
|
388
|
+
*
|
389
|
+
* @param editor The editor to deregister.
|
390
|
+
*/
|
391
|
+
deregisterEditor(editor: any): void;
|
392
|
+
/**
|
393
|
+
* Register an editor.
|
394
|
+
*
|
395
|
+
* @param editor The editor to register.
|
396
|
+
*/
|
397
|
+
registerEditor(editor: any): void;
|
398
|
+
/**
|
399
|
+
* Deregister a list navigator.
|
400
|
+
*
|
401
|
+
* @param name The name of the list navigator to deregister.
|
402
|
+
* @param listNavigator The list navigator. If defined, the named list navigator will only be deleted if it equals
|
403
|
+
* this parameter.
|
404
|
+
*/
|
405
|
+
deregisterListNavigator({ name, listNavigator }: {
|
406
|
+
name: string;
|
407
|
+
listNavigator: any;
|
408
|
+
}): void;
|
409
|
+
/**
|
410
|
+
* Register a list navigator.
|
411
|
+
*
|
412
|
+
* Registering a component such as a list view as a list navigator can help other components with list navigation.
|
413
|
+
* For instance, code that implements a "next" button in a detail view might use the list navigator to determine
|
414
|
+
* what resource to select next.
|
415
|
+
*
|
416
|
+
* If another list navigator is registered under this name, its registration will be replaced.
|
417
|
+
*
|
418
|
+
* @param name The name under which to register the list navigator.
|
419
|
+
* @param listNavigator The list navigator.
|
420
|
+
*/
|
421
|
+
registerListNavigator({ name, listNavigator }: {
|
422
|
+
name: string;
|
423
|
+
listNavigator: any;
|
424
|
+
}): void;
|
425
|
+
}>;
|
426
|
+
export type RestCollectionStore = ReturnType<ReturnType<typeof makeStore>>;
|
427
|
+
export declare const storeRegistry: StoreRegistry<import("pinia").Store<string, RestCollectionStoreState, {
|
428
|
+
/**
|
429
|
+
* Get the REST query parameters that can be determined from the collection options.
|
430
|
+
*
|
431
|
+
* This includes all query parameters except offset and limit, which vary from request to request.
|
432
|
+
*/
|
433
|
+
fixedQueryParams: (state: {
|
434
|
+
idProperty: string;
|
435
|
+
filter: {
|
436
|
+
namedFilter: string | null;
|
437
|
+
query: any | null;
|
438
|
+
resourceIds: ResourceId[] | null;
|
439
|
+
};
|
440
|
+
order: ({
|
441
|
+
path: string;
|
442
|
+
sqlType?: string | undefined;
|
443
|
+
} | [{
|
444
|
+
path: string;
|
445
|
+
sqlType?: string | undefined;
|
446
|
+
}, import("../queries.js").QueryOrderDirection])[] | null;
|
447
|
+
referencePathsToExpand: string[] | null;
|
448
|
+
resources: Resource[];
|
449
|
+
status: RestCollectionStoreStatus;
|
450
|
+
selection: Resource[];
|
451
|
+
detailSelection: Resource[];
|
452
|
+
invalidResources: Resource[];
|
453
|
+
listNavigators: {
|
454
|
+
[name: string]: any;
|
455
|
+
};
|
456
|
+
editingDetailSelection: boolean;
|
457
|
+
batchSaveAttempted: boolean;
|
458
|
+
editors: any[];
|
459
|
+
transientData: {
|
460
|
+
[id: string]: any;
|
461
|
+
[id: number]: any;
|
462
|
+
};
|
463
|
+
_loadId?: string | undefined;
|
464
|
+
_loadOffset?: number | undefined;
|
465
|
+
} & import("pinia").PiniaCustomStateProperties<RestCollectionStoreState>) => RestCollectionQueryParams;
|
466
|
+
}, {
|
467
|
+
/**
|
468
|
+
* Reset the store to its initial state.
|
469
|
+
*
|
470
|
+
* Configuration is retained, but REST collection contents and contextual state are reset.
|
471
|
+
*/
|
472
|
+
reset(): void;
|
473
|
+
/**
|
474
|
+
* Reset the store to its initial state, but retain transient data if appropriate.
|
475
|
+
*
|
476
|
+
* As with {@link reset}, configuration is retained, but REST collection contents and contextual state are reset.
|
477
|
+
* Transient data are retained if options.limitTransientDataToLocalCollection is false.
|
478
|
+
*/
|
479
|
+
resetRetainingTransientData(): void;
|
480
|
+
/**
|
481
|
+
* Turn editing mode on or off for the current detail selection.
|
482
|
+
*
|
483
|
+
* Components using this store use the editingDetailSelection state property to govern whether to show an editor for
|
484
|
+
* any current detail selection.
|
485
|
+
*
|
486
|
+
* @param editingDetailSelection The new setting: true if an the detail selection should be shown in an editor,
|
487
|
+
* false if not.
|
488
|
+
*/
|
489
|
+
setEditingDetailSelection(editingDetailSelection: boolean): void;
|
490
|
+
/**
|
491
|
+
* Set the filter.
|
492
|
+
*
|
493
|
+
* This function sets the whole filter without triggering a reload of the local collection. More commonly, clients
|
494
|
+
* will call {@link setQuery} or {@link setFilterResourceIds}.
|
495
|
+
*
|
496
|
+
* @param filter The new filter.
|
497
|
+
*/
|
498
|
+
setFilter(filter: RestCollectionFilter): void;
|
499
|
+
/**
|
500
|
+
* Set the filter query.
|
501
|
+
*
|
502
|
+
* If the collection has a state other than NotLoaded, it will be reloaded.
|
503
|
+
*
|
504
|
+
* @param query The new filter query.
|
505
|
+
* @return A promise that resolves when {@link loadResources} completes, or immediately if the collection does not
|
506
|
+
* need to be reloaded.
|
507
|
+
*/
|
508
|
+
setQuery(query: QueryClause | null): Promise<void>;
|
509
|
+
/**
|
510
|
+
* Set the list if resource IDs to filter on.
|
511
|
+
*
|
512
|
+
* If the collection has a state other than NotLoaded, it will be reloaded.
|
513
|
+
*
|
514
|
+
* @param resourceIds The list of resource IDs for the new filter.
|
515
|
+
* @return A promise that resolves when {@link loadResources} completes, or immediately if the collection does not
|
516
|
+
* need to be reloaded.
|
517
|
+
*/
|
518
|
+
setFilterResourceIds(resourceIds: ResourceId[] | null): Promise<void>;
|
519
|
+
/**
|
520
|
+
* Indicate that a batch save has been attempted and failed.
|
521
|
+
*
|
522
|
+
* Setting this flag is a way of communicating with other client code. The flag should be cleared after further
|
523
|
+
* edits or when another validation or save operations is attempted.
|
524
|
+
*
|
525
|
+
* @param batchSaveAttempted A flag indicating whether a batch save has been attempted and failed.
|
526
|
+
*/
|
527
|
+
setBatchSaveAttempted(batchSaveAttempted: boolean): void;
|
528
|
+
/**
|
529
|
+
* Clear the collection's contents.
|
530
|
+
*
|
531
|
+
* Configuration and contextual state are retained, but REST collection contents are reset.
|
532
|
+
*/
|
533
|
+
clear(): void;
|
534
|
+
/**
|
535
|
+
* Clear the collection's contents, but retain transient data if appropriate.
|
536
|
+
*
|
537
|
+
* As with {@link reset}, configuration and contextual state are retained, but REST collection contents are reset.
|
538
|
+
* Transient data are retained if options.limitTransientDataToLocalCollection is false.
|
539
|
+
*/
|
540
|
+
clearRetainingTransientData(): void;
|
541
|
+
/**
|
542
|
+
* Load the collection, if it has not been loaded.
|
543
|
+
*
|
544
|
+
* The collection will be loaded if its current status is not Loaded, Loading, LoadingMore, or Failed.
|
545
|
+
*/
|
546
|
+
ensureCollectionLoaded(): Promise<void>;
|
547
|
+
/**
|
548
|
+
* Load the collection.
|
549
|
+
*
|
550
|
+
* If pagination is enabled, this may result in multiple HTTP requests. The function's Promise is resolved once
|
551
|
+
* the first page is loaded.
|
552
|
+
*
|
553
|
+
* @param loadOptions Pagination options that may override the defaults.
|
554
|
+
*/
|
555
|
+
loadResources(loadOptions?: RestCollectionLoadOptions): Promise<void>;
|
556
|
+
/**
|
557
|
+
* Load the collection, optionally starting at some offset.
|
558
|
+
*
|
559
|
+
* If pagination is enabled, this may result in multiple HTTP requests. The function's Promise is resolved once
|
560
|
+
* the first page is loaded.
|
561
|
+
*
|
562
|
+
* @param offset The offset at which to start loading. When loading a whole collection, this will be 0; but if
|
563
|
+
* there are more pages to load, the function will call itself with the next page offset.
|
564
|
+
* @param loadId A unique identifier for this load operation, which is used to detect whether results should be
|
565
|
+
* discarded because a later load operation has been issued. Before calling this method, this identifier should
|
566
|
+
* be written to the store's state property named loadId.
|
567
|
+
* @param loadOptions Pagination options that may override the defaults.
|
568
|
+
*/
|
569
|
+
_loadResources(offset: number, loadId: string, loadOptions: RestCollectionLoadOptions): Promise<void>;
|
570
|
+
/**
|
571
|
+
* Verify that a resource does not exist in the remote collection.
|
572
|
+
*
|
573
|
+
* After checking the remote collection and verifying that the resource does not exist, this function calls
|
574
|
+
* {@link recordDeletion} to delete it from the local collection.
|
575
|
+
*
|
576
|
+
* @param itemId The ID of the deleted resource to check.
|
577
|
+
* @return true if the record does not exist in the remote collection, false if it does or if an error occurred.
|
578
|
+
*/
|
579
|
+
checkForDeletedResource(itemId: ResourceId): Promise<boolean>;
|
580
|
+
/**
|
581
|
+
* Record a deletion, removing the deleted resource from the local collection.
|
582
|
+
*
|
583
|
+
* This should be called after deleting a resource from the remote collection. It is called, for instance, by
|
584
|
+
* {@link deleteResource}; but it can also be called when the application is aware of deletions from the remote
|
585
|
+
* collection made by other means.
|
586
|
+
*
|
587
|
+
* @param resourceId The ID of the resource that has been deleted.
|
588
|
+
*/
|
589
|
+
recordDeletion(resourceId: ResourceId): void;
|
590
|
+
/**
|
591
|
+
* Record an insertion, adding the inserted resource to the local collection.
|
592
|
+
*
|
593
|
+
* This should be called after inserting a resource into the remote collection. It is called, for instance, by
|
594
|
+
* {@link saveResource}; but it can also be called when the application is aware of insertions into the remote
|
595
|
+
* collection made by other means.
|
596
|
+
*
|
597
|
+
* It is important that the resources to be added to the local collection have the same object-graph
|
598
|
+
* characteristics as other resources in the local collection. (These characteristics include property inclusions
|
599
|
+
* and exclusions, as well as reference expansions.) To ensure this, you may call {@refreshResource} to fetch the
|
600
|
+
* resource using the collection's settings.
|
601
|
+
*
|
602
|
+
* @param resource The item that has been inserted.
|
603
|
+
* @param TODO
|
604
|
+
*/
|
605
|
+
recordInsertion(resource: Resource, { insertAtBeginning, transientData }?: {
|
606
|
+
insertAtBeginning?: boolean | undefined;
|
607
|
+
transientData?: any;
|
608
|
+
}): void;
|
609
|
+
/**
|
610
|
+
* Record an update, making the same changes in the local collection.
|
611
|
+
*
|
612
|
+
* This should be called after updating a resource in the remote collection. It is called, for instance, by
|
613
|
+
* {@link saveResource} and {@link refreshResource}; but it can also be called when the application is aware of
|
614
|
+
* updates in the remote collection made by other means.
|
615
|
+
*
|
616
|
+
* It is important that the resource have the same object-graph characteristics as other resources in the local
|
617
|
+
* collection. (These characteristics include property inclusions and exclusions, as well as reference
|
618
|
+
* expansions.) To ensure this, you may instead call {@refreshResource} to fetch the resource using the
|
619
|
+
* collection's settings; this will in turn call {@link recordUpdate}.
|
620
|
+
*
|
621
|
+
* @param resource The item that has been updated.
|
622
|
+
*/
|
623
|
+
recordUpdate(resource: Resource): void;
|
624
|
+
/**
|
625
|
+
* Refresh a resource by requesting it from the remote collection.
|
626
|
+
*
|
627
|
+
* If the resource already exists in the local collection, {@link recordUpdate} will be called to update it there.
|
628
|
+
* If not, this method will return the resource but will not add it to the collection.
|
629
|
+
*
|
630
|
+
* This function is called by {@link insertItem} and {@link updateItem} to ensure that the local copy of the added
|
631
|
+
* or updated resource has the same object-graph characteristics as the rest of the local collection.
|
632
|
+
*
|
633
|
+
* @param resourceId The ID of the resource to refresh.
|
634
|
+
* @return The refreshed resource, or null if refreshing failed.
|
635
|
+
*/
|
636
|
+
refreshResource(resourceId: ResourceId): Promise<Resource | null>;
|
637
|
+
/**
|
638
|
+
* Insert a new unsaved resource into the local collection and enter editing mode.
|
639
|
+
*
|
640
|
+
* @param resourceDefaults Initial properties of the new resource.
|
641
|
+
*/
|
642
|
+
addResource(resourceDefaults?: Resource): void;
|
643
|
+
/**
|
644
|
+
* Delete one resource.
|
645
|
+
*
|
646
|
+
* A delete request is sent to the REST API. If it succeeds, the resource is removed from the local collection.
|
647
|
+
*
|
648
|
+
* @param resourceId The ID of the resource to delete.
|
649
|
+
*/
|
650
|
+
deleteResource(resourceId: ResourceId): Promise<void>;
|
651
|
+
/**
|
652
|
+
* Write a new or updated resource to the remote collection, then mirror the change in the local collection.
|
653
|
+
*
|
654
|
+
* After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the
|
655
|
+
* return value) has the same object-graph characteristics as the rest of the local collection.
|
656
|
+
*
|
657
|
+
* @param resource The new or updated resource. If it has an ID, an update will be attempted; otherwise it will be
|
658
|
+
* created.
|
659
|
+
* @returns The refreshed local resource after the change has been persisted to the remote collection, or null if
|
660
|
+
* the operation failed.
|
661
|
+
*/
|
662
|
+
saveResource(resource: Resource): Promise<Resource | null>;
|
663
|
+
/**
|
664
|
+
* Write new and/or updated resources to the remote collection, and mirror the changes in the local collection.
|
665
|
+
*
|
666
|
+
* After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the
|
667
|
+
* return value) has the same object-graph characteristics as the rest of the local collection.
|
668
|
+
*
|
669
|
+
* @param resources Resources to create or update. The two operations may be mixed in the list; when a resource
|
670
|
+
* has an ID, an update will be attempted, while otherwise it will be added.
|
671
|
+
* @returns An array of refreshed local resources, one for each remote resource whose save operation succeeded.
|
672
|
+
*/
|
673
|
+
saveResources(resources: Resource[]): Promise<any[]>;
|
674
|
+
/** Clear all transient data. */
|
675
|
+
clearTransientData(): void;
|
676
|
+
/**
|
677
|
+
* Record which local resources currently fail validation.
|
678
|
+
*
|
679
|
+
* This is useful in multi-resource editing contexts.
|
680
|
+
*
|
681
|
+
* @param resourceIds The IDs of all local resources that failed validation.
|
682
|
+
*/
|
683
|
+
setInvalidResourceIds(resourceIds: ResourceId[]): void;
|
684
|
+
/**
|
685
|
+
* Set transient data.
|
686
|
+
*
|
687
|
+
* @param transientData The new transient data.
|
688
|
+
* @param merge If true, combine each resource's transient data with existing transient data; if false, replace
|
689
|
+
* the transient data for each resource ID in the keys of transientData.
|
690
|
+
*/
|
691
|
+
setTransientDataForResources(params: SetTransientDataParams): void;
|
692
|
+
/**
|
693
|
+
* Clear the selection.
|
694
|
+
*/
|
695
|
+
clearSelection(): void;
|
696
|
+
/**
|
697
|
+
* Remove resources from the selection.
|
698
|
+
*
|
699
|
+
* @param resourceIds The IDs of resources to remove from the selection.
|
700
|
+
*/
|
701
|
+
deselectResources(resourceIds: ResourceId[]): void;
|
702
|
+
/**
|
703
|
+
* Add to or replace the selection.
|
704
|
+
*
|
705
|
+
* @param recordIds The record IDs to select.
|
706
|
+
* @param addToSelection true if the existing selection should be expanded, false if it should be replaced.
|
707
|
+
* @param edit If not undefined, sets the editing mode of the new selection. If undefined, the editing mode will
|
708
|
+
* be left as is, or set to true if options.detail.autoEdit is true.
|
709
|
+
*/
|
710
|
+
selectResources(resourceIds: ResourceId[], options?: SelectResourcesOptions): void;
|
711
|
+
/**
|
712
|
+
* Set a new selection.
|
713
|
+
*
|
714
|
+
* @param selectedResourceIds The resource IDs in the new selection.
|
715
|
+
* @param edit If not undefined, sets the editing mode of the new selection. If undefined, the editing mode will
|
716
|
+
* be left as is, or set to true if options.detail.autoEdit is true.
|
717
|
+
*/
|
718
|
+
setSelection(selectedResourceIds: ResourceId[], edit?: boolean): void;
|
719
|
+
/**
|
720
|
+
* Hide the detail view.
|
721
|
+
*
|
722
|
+
* This clears detailSelection and sets the detail editing mode to false.
|
723
|
+
*/
|
724
|
+
hideDetail(): void;
|
725
|
+
/**
|
726
|
+
* Show the current selection in the detail view.
|
727
|
+
*
|
728
|
+
* If options.detail.allowMultiple is false and more than one resource is selected, the detail view will not be
|
729
|
+
* changed.
|
730
|
+
*
|
731
|
+
* @param edit If not undefined, sets the detail editing mode. If undefined, the editing mode will be left as is,
|
732
|
+
* or set to true if options.detail.autoEdit is true.
|
733
|
+
*/
|
734
|
+
showSelectionAsDetail(edit: boolean): void;
|
735
|
+
/**
|
736
|
+
* Deregister an editor.
|
737
|
+
*
|
738
|
+
* @param editor The editor to deregister.
|
739
|
+
*/
|
740
|
+
deregisterEditor(editor: any): void;
|
741
|
+
/**
|
742
|
+
* Register an editor.
|
743
|
+
*
|
744
|
+
* @param editor The editor to register.
|
745
|
+
*/
|
746
|
+
registerEditor(editor: any): void;
|
747
|
+
/**
|
748
|
+
* Deregister a list navigator.
|
749
|
+
*
|
750
|
+
* @param name The name of the list navigator to deregister.
|
751
|
+
* @param listNavigator The list navigator. If defined, the named list navigator will only be deleted if it equals
|
752
|
+
* this parameter.
|
753
|
+
*/
|
754
|
+
deregisterListNavigator({ name, listNavigator }: {
|
755
|
+
name: string;
|
756
|
+
listNavigator: any;
|
757
|
+
}): void;
|
758
|
+
/**
|
759
|
+
* Register a list navigator.
|
760
|
+
*
|
761
|
+
* Registering a component such as a list view as a list navigator can help other components with list navigation.
|
762
|
+
* For instance, code that implements a "next" button in a detail view might use the list navigator to determine
|
763
|
+
* what resource to select next.
|
764
|
+
*
|
765
|
+
* If another list navigator is registered under this name, its registration will be replaced.
|
766
|
+
*
|
767
|
+
* @param name The name under which to register the list navigator.
|
768
|
+
* @param listNavigator The list navigator.
|
769
|
+
*/
|
770
|
+
registerListNavigator({ name, listNavigator }: {
|
771
|
+
name: string;
|
772
|
+
listNavigator: any;
|
773
|
+
}): void;
|
774
|
+
}>>;
|
775
|
+
export default makeStore;
|