rest-client-vue 1.0.0 → 1.1.0

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.
@@ -111,7 +111,7 @@ export type RestCollectionStoreReadyCallback = (() => void) | (() => Promise<voi
111
111
  * resources from one collection endpoint of the REST API; but filters can be added when using a REST API that supports
112
112
  * them.
113
113
  */
114
- export interface RestCollection {
114
+ export interface RestCollection<T extends Resource = Resource> {
115
115
  /**
116
116
  * The REST collection's unique ID, which is used as the ID of its Pinia store.
117
117
  *
@@ -139,17 +139,17 @@ export interface RestCollection {
139
139
  * An array of resources that have failed validation. The client must manage this list by calling
140
140
  * {@link setInvalidResourceIds}
141
141
  **/
142
- invalidResources: Ref<Resource[]>;
142
+ invalidResources: Ref<T[]>;
143
143
  /** The array of resources that have been loaded from the REST API into the local collection. */
144
- resources: Ref<Resource[]>;
144
+ resources: Ref<T[]>;
145
145
  /** Transient data that a client has associated with the resources via {@link setTransientDataForResources}. */
146
146
  transientData: Ref<any[]>;
147
147
  /** Resources in the current detail view, a sublist of {@link resources}. */
148
- detailSelection: Ref<Resource[]>;
148
+ detailSelection: Ref<T[]>;
149
149
  /** A flag indicating whether the detail selection is currently being edited or only displayed. */
150
150
  editingDetailSelection: Ref<boolean>;
151
151
  /** The current selection, a sublist of {@link resources}. */
152
- selection: Ref<Resource[]>;
152
+ selection: Ref<T[]>;
153
153
  /**
154
154
  * Apply new configuration options.
155
155
  *
@@ -226,14 +226,14 @@ export interface RestCollection {
226
226
  *
227
227
  * @param resourceDefaults An object containing initial property values for the new resource.
228
228
  */
229
- addResource: (resourceDefaults?: Resource) => void;
229
+ addResource: (resourceDefaults?: T) => void;
230
230
  checkForDeletedResource: (resourceId: ResourceId) => Promise<boolean>;
231
231
  recordDeletion: (resourceId: ResourceId) => void;
232
- recordInsertion: (resource: Resource, { insertAtBeginning, transientData }?: {
232
+ recordInsertion: (resource: T, { insertAtBeginning, transientData }?: {
233
233
  insertAtBeginning?: boolean;
234
234
  transientData?: any;
235
235
  }) => void;
236
- recordUpdate: (resource: Resource) => void;
236
+ recordUpdate: (resource: T) => void;
237
237
  /**
238
238
  * Refresh one resource by fetching it again from the REST API.
239
239
  *
@@ -241,7 +241,7 @@ export interface RestCollection {
241
241
  *
242
242
  * @param resourceId The ID of the resource to refresh.
243
243
  */
244
- refreshResource: (resourceId: ResourceId) => Promise<Resource | null | undefined>;
244
+ refreshResource: (resourceId: ResourceId) => Promise<T | null | undefined>;
245
245
  /**
246
246
  * Delete one resource.
247
247
  *
@@ -260,7 +260,7 @@ export interface RestCollection {
260
260
  *
261
261
  * @param resource The resource to create or update.
262
262
  */
263
- saveResource: (resource: Resource) => Promise<Resource | null | undefined>;
263
+ saveResource: (resource: T) => Promise<T | null | undefined>;
264
264
  /**
265
265
  * Save multiple resources (new or updated).
266
266
  *
@@ -271,7 +271,7 @@ export interface RestCollection {
271
271
  *
272
272
  * @param params TODO
273
273
  */
274
- saveResources: (resources: Resource[]) => Promise<Resource[] | undefined>;
274
+ saveResources: (resources: T[]) => Promise<T[] | undefined>;
275
275
  /**
276
276
  * Record which resources have failed validation.
277
277
  *
@@ -306,6 +306,6 @@ export interface RestCollection {
306
306
  }) => void;
307
307
  onItemsStoreReady: (callback: RestCollectionStoreReadyCallback) => void;
308
308
  }
309
- declare const _default: (params?: RestCollectionOptions) => RestCollection;
309
+ declare const _default: <T extends object = object>(params?: RestCollectionOptions) => RestCollection<T>;
310
310
  export default _default;
311
311
  export declare const clearAllRestCollections: () => void;
@@ -56,7 +56,7 @@ export interface MakeCustomApiRequestParams {
56
56
  * {@link RestResourceClient} is sometimes useful for consuming individual responses from APIs that are not really
57
57
  * RESTful.
58
58
  */
59
- export interface RestResourceClient {
59
+ export interface RestResourceClient<T extends Resource = Resource> {
60
60
  /**
61
61
  * The REST resource client's unique identifier, which is the ID of its Pinia store.
62
62
  *
@@ -77,7 +77,7 @@ export interface RestResourceClient {
77
77
  /** A status indicating whether resources have been loaded yet from the REST API. */
78
78
  status: Ref<RestResourceStatus>;
79
79
  /** The local version of the resource loaded from the REST API. */
80
- resource: Ref<Resource>;
80
+ resource: Ref<T>;
81
81
  /** The ID of the REST resource. */
82
82
  resourceId: Ref<ResourceId | null>;
83
83
  /** The URL of the REST resource. */
@@ -129,12 +129,12 @@ export interface RestResourceClient {
129
129
  */
130
130
  checkForDeletedResource: () => Promise<boolean>;
131
131
  recordDeletion: () => void;
132
- recordInsertion: (resource: Resource) => void;
133
- recordUpdate: (resource: Resource) => void;
134
- refreshResource: () => Promise<Resource | null | undefined>;
132
+ recordInsertion: (resource: T) => void;
133
+ recordUpdate: (resource: T) => void;
134
+ refreshResource: () => Promise<T | null | undefined>;
135
135
  deleteResource: () => Promise<void>;
136
- saveResource: (resource: Resource) => Promise<Resource | null | undefined>;
136
+ saveResource: (resource: T) => Promise<T | null | undefined>;
137
137
  makeCustomApiRequest: (params: MakeCustomApiRequestParams) => Promise<any>;
138
138
  }
139
- declare const _default: (params?: RestResourceOptions) => RestResourceClient;
139
+ declare const _default: <T extends object = object>(params?: RestResourceOptions) => RestResourceClient<T>;
140
140
  export default _default;
@@ -321,7 +321,7 @@ declare const makeStore: (storeId: string, options: RestCollectionStoreOptions)
321
321
  * has an ID, an update will be attempted, while otherwise it will be added.
322
322
  * @returns An array of refreshed local resources, one for each remote resource whose save operation succeeded.
323
323
  */
324
- saveResources(resources: Resource[]): Promise<any[]>;
324
+ saveResources(resources: Resource[]): Promise<Resource[]>;
325
325
  /** Clear all transient data. */
326
326
  clearTransientData(): void;
327
327
  /**
@@ -670,7 +670,7 @@ export declare const storeRegistry: StoreRegistry<import("pinia").Store<string,
670
670
  * has an ID, an update will be attempted, while otherwise it will be added.
671
671
  * @returns An array of refreshed local resources, one for each remote resource whose save operation succeeded.
672
672
  */
673
- saveResources(resources: Resource[]): Promise<any[]>;
673
+ saveResources(resources: Resource[]): Promise<Resource[]>;
674
674
  /** Clear all transient data. */
675
675
  clearTransientData(): void;
676
676
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rest-client-vue",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "author": {
5
5
  "name": "Jeremy Stone",
6
6
  "email": "stoneje@msn.com"