@clairejs/client 3.5.2 → 3.5.3

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/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Change Log
2
2
 
3
+ #### 3.5.3:
4
+
5
+ - improve crud api cache
6
+
3
7
  #### 3.5.2:
4
8
 
5
9
  - update abstract storage interface
@@ -9,6 +9,8 @@ export declare class CrudApi<T extends AbstractModel> {
9
9
  private dirty;
10
10
  constructor(model: Constructor<T>, httpClient: AbstractHttpClient);
11
11
  protected getEndpointBaseUrl(): string;
12
+ private setDirty;
13
+ private clearDirty;
12
14
  getMany(queries?: GetManyQueries<T>, options?: RequestOptions): Promise<GetManyResponseBody<T> | undefined>;
13
15
  updateMany(body: UpdateManyBody<T>, queries?: UpdateManyQueries<T>): Promise<UpdateManyResponse<T> | undefined>;
14
16
  deleteMany(queries?: UpdateManyQueries<T>): Promise<UpdateManyResponse<T> | undefined>;
@@ -73,7 +73,7 @@ export const mergeInstances = (model, target, source, syncTarget) => {
73
73
  export class CrudApi {
74
74
  model;
75
75
  httpClient;
76
- dirty = true;
76
+ dirty = new Map();
77
77
  constructor(model, httpClient) {
78
78
  this.model = model;
79
79
  this.httpClient = httpClient;
@@ -81,25 +81,34 @@ export class CrudApi {
81
81
  getEndpointBaseUrl() {
82
82
  return `/${this.model.name.toLowerCase()}`;
83
83
  }
84
+ setDirty() {
85
+ for (const key of this.dirty.keys()) {
86
+ this.dirty.set(key, true);
87
+ }
88
+ }
89
+ clearDirty(key) {
90
+ this.dirty.delete(key);
91
+ }
84
92
  async getMany(queries, options) {
85
- const result = await this.httpClient.get(`${this.getEndpointBaseUrl()}?${stringifyQueries(queries || {})}`, undefined, { ...options, noCache: options?.noCache || this.dirty });
86
- this.dirty = false;
93
+ const url = `${this.getEndpointBaseUrl()}?${stringifyQueries(queries || {})}`;
94
+ const result = await this.httpClient.get(url, undefined, { ...options, noCache: options?.noCache || this.dirty.get(url) });
95
+ this.clearDirty(url);
87
96
  return result;
88
97
  }
89
98
  async updateMany(body, queries) {
90
- this.dirty = true;
99
+ this.setDirty();
91
100
  return await this.httpClient.put(`${this.getEndpointBaseUrl()}?${stringifyQueries(queries || {})}`, body);
92
101
  }
93
102
  async deleteMany(queries) {
94
- this.dirty = true;
103
+ this.setDirty();
95
104
  return await this.httpClient.delete(`${this.getEndpointBaseUrl()}?${stringifyQueries(queries || {})}`);
96
105
  }
97
106
  async createMany(body) {
98
- this.dirty = true;
107
+ this.setDirty();
99
108
  return await this.httpClient.post(`${this.getEndpointBaseUrl()}`, body);
100
109
  }
101
110
  async updateRecords(body, queries) {
102
- this.dirty = true;
111
+ this.setDirty();
103
112
  return await this.httpClient.put(`${this.getEndpointBaseUrl()}/records?${stringifyQueries(queries || {})}`, body);
104
113
  }
105
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clairejs/client",
3
- "version": "3.5.2",
3
+ "version": "3.5.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",