@markwharton/liquidplanner 2.1.1 → 2.1.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/client.d.ts +1 -0
- package/dist/client.js +8 -5
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +2 -3
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -128,6 +128,7 @@ export declare class LPClient {
|
|
|
128
128
|
*
|
|
129
129
|
* This enables PWA apps to show a task picker populated from LP directly.
|
|
130
130
|
* Note: userId is not a supported filter field in the LP API, so we filter client-side.
|
|
131
|
+
* The full unfiltered dataset is cached once; all memberId queries share the same cache entry.
|
|
131
132
|
*/
|
|
132
133
|
getMyAssignments(memberId: number): Promise<Result<LPItem[]>>;
|
|
133
134
|
/**
|
package/dist/client.js
CHANGED
|
@@ -10,7 +10,7 @@ import { buildAuthHeader, hoursToMinutes, normalizeItemType, filterIs, filterIsN
|
|
|
10
10
|
import { buildTree, getTreeAncestors } from './tree.js';
|
|
11
11
|
import { parseLPErrorResponse } from './errors.js';
|
|
12
12
|
import { LP_API_BASE } from './constants.js';
|
|
13
|
-
import { TTLCache, batchMap, getErrorMessage, fetchWithRetry, ok, err, resolveRetryConfig } from '@markwharton/api-core';
|
|
13
|
+
import { TTLCache, batchMap, getErrorMessage, fetchWithRetry, ok, okVoid, err, resolveRetryConfig } from '@markwharton/api-core';
|
|
14
14
|
/** Transform raw API item to LPItem, preserving scheduling and effort fields */
|
|
15
15
|
function transformItem(raw) {
|
|
16
16
|
const item = {
|
|
@@ -158,7 +158,7 @@ export class LPClient {
|
|
|
158
158
|
* (e.g., after logging time which updates loggedHoursRollup).
|
|
159
159
|
*/
|
|
160
160
|
invalidateAssignmentsCache() {
|
|
161
|
-
this.cache?.invalidate('assignments
|
|
161
|
+
this.cache?.invalidate('assignments');
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
164
|
* Invalidate cached workspace tree snapshot only.
|
|
@@ -248,7 +248,7 @@ export class LPClient {
|
|
|
248
248
|
try {
|
|
249
249
|
const response = await this.fetch(url);
|
|
250
250
|
if (response.ok) {
|
|
251
|
-
return
|
|
251
|
+
return okVoid();
|
|
252
252
|
}
|
|
253
253
|
if (response.status === 401 || response.status === 403) {
|
|
254
254
|
return err('Invalid or expired API token', response.status);
|
|
@@ -372,17 +372,20 @@ export class LPClient {
|
|
|
372
372
|
*
|
|
373
373
|
* This enables PWA apps to show a task picker populated from LP directly.
|
|
374
374
|
* Note: userId is not a supported filter field in the LP API, so we filter client-side.
|
|
375
|
+
* The full unfiltered dataset is cached once; all memberId queries share the same cache entry.
|
|
375
376
|
*/
|
|
376
377
|
async getMyAssignments(memberId) {
|
|
377
|
-
|
|
378
|
+
const result = await this.cached('assignments', this.cacheTtl.assignmentsTtl, async () => {
|
|
378
379
|
const baseUrl = this.workspaceUrl(`items/v1?${filterIs('itemType', 'assignments')}`);
|
|
379
380
|
return paginatedFetch({
|
|
380
381
|
fetchFn: (url) => this.fetch(url),
|
|
381
382
|
baseUrl,
|
|
382
|
-
filter: (data) => data.filter(item => item.userId === memberId),
|
|
383
383
|
transform: (data) => data.map(transformItem),
|
|
384
384
|
});
|
|
385
385
|
});
|
|
386
|
+
if (!result.ok)
|
|
387
|
+
return result;
|
|
388
|
+
return ok(result.data.filter(item => item.userId === memberId));
|
|
386
389
|
}
|
|
387
390
|
/**
|
|
388
391
|
* Get assignments for a member with parent task names resolved
|
package/dist/utils.d.ts
CHANGED
|
@@ -49,8 +49,6 @@ export interface PaginateOptions<TRaw, TResult> {
|
|
|
49
49
|
baseUrl: string;
|
|
50
50
|
/** Transform raw API data to result type */
|
|
51
51
|
transform: (data: TRaw[]) => TResult[];
|
|
52
|
-
/** Optional filter to apply to each page */
|
|
53
|
-
filter?: (data: TRaw[]) => TRaw[];
|
|
54
52
|
}
|
|
55
53
|
/**
|
|
56
54
|
* Generic pagination helper for LP API endpoints
|
package/dist/utils.js
CHANGED
|
@@ -76,7 +76,7 @@ export function joinFilters(...filters) {
|
|
|
76
76
|
* Handles the continuation token pattern used by LP API.
|
|
77
77
|
*/
|
|
78
78
|
export async function paginatedFetch(options) {
|
|
79
|
-
const { fetchFn, baseUrl, transform
|
|
79
|
+
const { fetchFn, baseUrl, transform } = options;
|
|
80
80
|
const hasQueryParams = baseUrl.includes('?');
|
|
81
81
|
try {
|
|
82
82
|
const allResults = [];
|
|
@@ -93,8 +93,7 @@ export async function paginatedFetch(options) {
|
|
|
93
93
|
}
|
|
94
94
|
const result = await response.json();
|
|
95
95
|
const rawData = result.data || [];
|
|
96
|
-
const
|
|
97
|
-
const pageResults = transform(filteredData);
|
|
96
|
+
const pageResults = transform(rawData);
|
|
98
97
|
allResults.push(...pageResults);
|
|
99
98
|
continuationToken = result.continuationToken;
|
|
100
99
|
} while (continuationToken);
|