@clairejs/client 3.5.1 → 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 +8 -0
- package/dist/api/CrudApi.d.ts +2 -0
- package/dist/api/CrudApi.js +16 -7
- package/dist/system/AbstractStorage.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/api/CrudApi.d.ts
CHANGED
|
@@ -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>;
|
package/dist/api/CrudApi.js
CHANGED
|
@@ -73,7 +73,7 @@ export const mergeInstances = (model, target, source, syncTarget) => {
|
|
|
73
73
|
export class CrudApi {
|
|
74
74
|
model;
|
|
75
75
|
httpClient;
|
|
76
|
-
dirty =
|
|
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
|
|
86
|
-
this.dirty
|
|
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.
|
|
99
|
+
this.setDirty();
|
|
91
100
|
return await this.httpClient.put(`${this.getEndpointBaseUrl()}?${stringifyQueries(queries || {})}`, body);
|
|
92
101
|
}
|
|
93
102
|
async deleteMany(queries) {
|
|
94
|
-
this.
|
|
103
|
+
this.setDirty();
|
|
95
104
|
return await this.httpClient.delete(`${this.getEndpointBaseUrl()}?${stringifyQueries(queries || {})}`);
|
|
96
105
|
}
|
|
97
106
|
async createMany(body) {
|
|
98
|
-
this.
|
|
107
|
+
this.setDirty();
|
|
99
108
|
return await this.httpClient.post(`${this.getEndpointBaseUrl()}`, body);
|
|
100
109
|
}
|
|
101
110
|
async updateRecords(body, queries) {
|
|
102
|
-
this.
|
|
111
|
+
this.setDirty();
|
|
103
112
|
return await this.httpClient.put(`${this.getEndpointBaseUrl()}/records?${stringifyQueries(queries || {})}`, body);
|
|
104
113
|
}
|
|
105
114
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare abstract class AbstractStorage {
|
|
2
2
|
abstract getItem<T>(key: string): Promise<T | undefined>;
|
|
3
|
-
abstract setItem<T>(key: string, value: T): Promise<void>;
|
|
3
|
+
abstract setItem<T>(key: string, value: T, expirationSeconds?: number): Promise<void>;
|
|
4
4
|
abstract deleteItem(key: string): Promise<void>;
|
|
5
5
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clairejs/client",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"axios": "^1.3.4"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@clairejs/core": "^3.
|
|
16
|
+
"@clairejs/core": "^3.9.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/mocha": "^10.0.1",
|