@simpleapps-com/augur-server 0.4.3 → 0.4.4
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/{chunk-I7EWYSPA.js → chunk-R3XKAWHN.js} +17 -1
- package/dist/chunk-R3XKAWHN.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +13 -28
- package/dist/index.js.map +1 -1
- package/dist/prefetch.js +8 -13
- package/dist/prefetch.js.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-I7EWYSPA.js.map +0 -1
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
// src/utils/batch-fetch.ts
|
|
2
|
+
async function batchFetch(params, fetchOne, getKey) {
|
|
3
|
+
if (params.length === 0) return {};
|
|
4
|
+
const results = await Promise.all(
|
|
5
|
+
params.map(
|
|
6
|
+
(p) => fetchOne(p).then((data) => [getKey(p), data]).catch(() => [getKey(p), void 0])
|
|
7
|
+
)
|
|
8
|
+
);
|
|
9
|
+
const out = {};
|
|
10
|
+
for (const [key, data] of results) {
|
|
11
|
+
if (data !== void 0) out[key] = data;
|
|
12
|
+
}
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
|
|
1
16
|
// src/server-query-client.ts
|
|
2
17
|
import { cache } from "react";
|
|
3
18
|
import { QueryClient } from "@tanstack/react-query";
|
|
@@ -21,7 +36,8 @@ var getServerQueryClient = cache(
|
|
|
21
36
|
);
|
|
22
37
|
|
|
23
38
|
export {
|
|
39
|
+
batchFetch,
|
|
24
40
|
createServerQueryClient,
|
|
25
41
|
getServerQueryClient
|
|
26
42
|
};
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
43
|
+
//# sourceMappingURL=chunk-R3XKAWHN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/batch-fetch.ts","../src/server-query-client.ts"],"sourcesContent":["/**\n * Fetches data for multiple params in parallel, returning a Record keyed by\n * `getKey(param)`. Individual failures are silently excluded from the result\n * so one bad item never takes down the entire batch.\n */\nexport async function batchFetch<TParam, TKey extends string | number, TData>(\n params: TParam[],\n fetchOne: (param: TParam) => Promise<TData>,\n getKey: (param: TParam) => TKey,\n): Promise<Record<TKey, TData>> {\n if (params.length === 0) return {} as Record<TKey, TData>;\n\n const results = await Promise.all(\n params.map((p) =>\n fetchOne(p)\n .then((data) => [getKey(p), data] as const)\n .catch(() => [getKey(p), undefined] as const),\n ),\n );\n\n const out = {} as Record<TKey, TData>;\n for (const [key, data] of results) {\n if (data !== undefined) out[key] = data;\n }\n return out;\n}\n","import { cache } from \"react\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { CACHE_CONFIG } from \"@simpleapps-com/augur-utils\";\n\n/**\n * Creates a server-side query client optimised for prefetching.\n *\n * - No persistence (server-only)\n * - Longer cache times for prefetched data\n * - No retries (fail fast on server)\n * - No refetching (server renders are one-shot)\n */\nexport function createServerQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: CACHE_CONFIG.STATIC.staleTime,\n gcTime: CACHE_CONFIG.STATIC.staleTime,\n retry: 0,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n },\n },\n });\n}\n\n/**\n * Returns a per-request singleton QueryClient for React Server Components.\n *\n * React's `cache()` deduplicates calls within a single server request,\n * so each request gets its own QueryClient while avoiding the cross-request\n * state leakage that a module-level singleton would cause.\n */\nexport const getServerQueryClient = cache(\n (): QueryClient => createServerQueryClient(),\n);\n"],"mappings":";AAKA,eAAsB,WACpB,QACA,UACA,QAC8B;AAC9B,MAAI,OAAO,WAAW,EAAG,QAAO,CAAC;AAEjC,QAAM,UAAU,MAAM,QAAQ;AAAA,IAC5B,OAAO;AAAA,MAAI,CAAC,MACV,SAAS,CAAC,EACP,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAU,EACzC,MAAM,MAAM,CAAC,OAAO,CAAC,GAAG,MAAS,CAAU;AAAA,IAChD;AAAA,EACF;AAEA,QAAM,MAAM,CAAC;AACb,aAAW,CAAC,KAAK,IAAI,KAAK,SAAS;AACjC,QAAI,SAAS,OAAW,KAAI,GAAG,IAAI;AAAA,EACrC;AACA,SAAO;AACT;;;ACzBA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAUtB,SAAS,0BAAuC;AACrD,SAAO,IAAI,YAAY;AAAA,IACrB,gBAAgB;AAAA,MACd,SAAS;AAAA,QACP,WAAW,aAAa,OAAO;AAAA,QAC/B,QAAQ,aAAa,OAAO;AAAA,QAC5B,OAAO;AAAA,QACP,gBAAgB;AAAA,QAChB,sBAAsB;AAAA,QACtB,oBAAoB;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AASO,IAAM,uBAAuB;AAAA,EAClC,MAAmB,wBAAwB;AAC7C;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,13 @@ type ActionResult<T> = {
|
|
|
78
78
|
*/
|
|
79
79
|
declare function safeAction<T>(fn: () => Promise<T>, onError?: (error: Error) => void): Promise<ActionResult<T>>;
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Fetches data for multiple params in parallel, returning a Record keyed by
|
|
83
|
+
* `getKey(param)`. Individual failures are silently excluded from the result
|
|
84
|
+
* so one bad item never takes down the entire batch.
|
|
85
|
+
*/
|
|
86
|
+
declare function batchFetch<TParam, TKey extends string | number, TData>(params: TParam[], fetchOne: (param: TParam) => Promise<TData>, getKey: (param: TParam) => TKey): Promise<Record<TKey, TData>>;
|
|
87
|
+
|
|
81
88
|
/**
|
|
82
89
|
* Creates a server-side query client optimised for prefetching.
|
|
83
90
|
*
|
|
@@ -220,4 +227,4 @@ interface FavoritesActions {
|
|
|
220
227
|
}
|
|
221
228
|
declare function createFavoritesActions(api: FavoritesApiClient, config?: FavoritesActionsConfig): FavoritesActions;
|
|
222
229
|
|
|
223
|
-
export { type ActionResult, type FavoritesActions, type FavoritesActionsConfig, type FavoritesApiClient, type PaginatedResult, type WishlistActions, type WishlistActionsConfig, type WishlistsApiClient, cacheGet, cacheSet, createFavoritesActions, createServerQueryClient, createWishlistActions, env, getCircuitState, getServerQueryClient, isDev, isProduction, isRedisConnected, isStaging, paginateOffset, safeAction, sdkCall, withServerCache };
|
|
230
|
+
export { type ActionResult, type FavoritesActions, type FavoritesActionsConfig, type FavoritesApiClient, type PaginatedResult, type WishlistActions, type WishlistActionsConfig, type WishlistsApiClient, batchFetch, cacheGet, cacheSet, createFavoritesActions, createServerQueryClient, createWishlistActions, env, getCircuitState, getServerQueryClient, isDev, isProduction, isRedisConnected, isStaging, paginateOffset, safeAction, sdkCall, withServerCache };
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,10 @@ import {
|
|
|
3
3
|
createSuspenseQueryOptions
|
|
4
4
|
} from "./chunk-I26RJDRF.js";
|
|
5
5
|
import {
|
|
6
|
+
batchFetch,
|
|
6
7
|
createServerQueryClient,
|
|
7
8
|
getServerQueryClient
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-R3XKAWHN.js";
|
|
9
10
|
|
|
10
11
|
// src/environment.ts
|
|
11
12
|
function getEnvironment() {
|
|
@@ -227,14 +228,11 @@ function createPricingActions(api, config = {}) {
|
|
|
227
228
|
);
|
|
228
229
|
}
|
|
229
230
|
async function batchGetItemPrices(itemIds, customerId, quantity = 1) {
|
|
230
|
-
|
|
231
|
-
itemIds
|
|
231
|
+
return batchFetch(
|
|
232
|
+
itemIds,
|
|
233
|
+
(id) => getItemPrice(id, customerId, quantity),
|
|
234
|
+
(id) => id
|
|
232
235
|
);
|
|
233
|
-
const out = {};
|
|
234
|
-
for (const [id, data] of results) {
|
|
235
|
-
if (data) out[id] = data;
|
|
236
|
-
}
|
|
237
|
-
return out;
|
|
238
236
|
}
|
|
239
237
|
async function getTaxEstimate(customerId, postalCode, items) {
|
|
240
238
|
const custId = resolveCustomerId(customerId, defaultCustomerId);
|
|
@@ -457,28 +455,14 @@ function createItemActions(api, config = {}) {
|
|
|
457
455
|
);
|
|
458
456
|
}
|
|
459
457
|
async function batchGetInvMastDocs(params) {
|
|
460
|
-
|
|
461
|
-
params
|
|
462
|
-
|
|
463
|
-
)
|
|
464
|
-
);
|
|
465
|
-
const out = {};
|
|
466
|
-
for (const [key, data] of results) {
|
|
467
|
-
if (data) out[key] = data;
|
|
468
|
-
}
|
|
469
|
-
return out;
|
|
458
|
+
return batchFetch(
|
|
459
|
+
params,
|
|
460
|
+
(p) => getInvMastDoc(p),
|
|
461
|
+
(p) => p.itemId ?? String(p.invMastUid)
|
|
462
|
+
);
|
|
470
463
|
}
|
|
471
464
|
async function batchGetStockData(invMastUids) {
|
|
472
|
-
|
|
473
|
-
invMastUids.map(
|
|
474
|
-
(uid) => getStock(uid).then((data) => [uid, data]).catch(() => [uid, void 0])
|
|
475
|
-
)
|
|
476
|
-
);
|
|
477
|
-
const out = {};
|
|
478
|
-
for (const [uid, data] of results) {
|
|
479
|
-
if (data) out[uid] = data;
|
|
480
|
-
}
|
|
481
|
-
return out;
|
|
465
|
+
return batchFetch(invMastUids, (uid) => getStock(uid), (uid) => uid);
|
|
482
466
|
}
|
|
483
467
|
return {
|
|
484
468
|
itemCategoryLookup,
|
|
@@ -2552,6 +2536,7 @@ function createSiteActions(api, config = {}) {
|
|
|
2552
2536
|
};
|
|
2553
2537
|
}
|
|
2554
2538
|
export {
|
|
2539
|
+
batchFetch,
|
|
2555
2540
|
cacheGet,
|
|
2556
2541
|
cacheSet,
|
|
2557
2542
|
createAgrInfoActions,
|