@xhub-short/core 0.1.0-beta.3 → 0.1.0-beta.5

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/index.d.ts CHANGED
@@ -170,6 +170,25 @@ declare class FeedManager {
170
170
  */
171
171
  private accessOrder;
172
172
  constructor(dataSource: IDataSource, config?: FeedConfig, storage?: IStorage, prefetchConfig?: Partial<PrefetchCacheConfig>);
173
+ /** Static memory cache for explicit prefetching */
174
+ private static globalMemoryCache;
175
+ /**
176
+ * Prefetch feed data and store in global memory cache
177
+ *
178
+ * @param dataSource - Data source to fetch from
179
+ * @param options - Prefetch options
180
+ */
181
+ static prefetch(dataSource: IDataSource, options?: {
182
+ ttl?: number;
183
+ }): Promise<void>;
184
+ /**
185
+ * Check if prefetch cache exists and is valid
186
+ */
187
+ static hasPrefetchCache(): boolean;
188
+ /**
189
+ * Clear prefetch cache
190
+ */
191
+ static clearPrefetchCache(): void;
173
192
  /**
174
193
  * Load initial feed data
175
194
  *
package/dist/index.js CHANGED
@@ -53,7 +53,7 @@ var createInitialState = () => ({
53
53
  isStale: false,
54
54
  lastFetchTime: null
55
55
  });
56
- var FeedManager = class {
56
+ var _FeedManager = class _FeedManager {
57
57
  constructor(dataSource, config = {}, storage, prefetchConfig) {
58
58
  this.dataSource = dataSource;
59
59
  /** Abort controller for cancelling in-flight requests */
@@ -73,6 +73,42 @@ var FeedManager = class {
73
73
  this.storage = storage ?? null;
74
74
  this.store = createStore(createInitialState);
75
75
  }
76
+ /**
77
+ * Prefetch feed data and store in global memory cache
78
+ *
79
+ * @param dataSource - Data source to fetch from
80
+ * @param options - Prefetch options
81
+ */
82
+ static async prefetch(dataSource, options = {}) {
83
+ if (_FeedManager.globalMemoryCache) {
84
+ const now = Date.now();
85
+ const ttl = options.ttl ?? 5 * 60 * 1e3;
86
+ if (now - _FeedManager.globalMemoryCache.timestamp < ttl) {
87
+ return;
88
+ }
89
+ }
90
+ try {
91
+ const response = await dataSource.fetchFeed(void 0);
92
+ _FeedManager.globalMemoryCache = {
93
+ items: response.items,
94
+ nextCursor: response.nextCursor,
95
+ timestamp: Date.now()
96
+ };
97
+ } catch {
98
+ }
99
+ }
100
+ /**
101
+ * Check if prefetch cache exists and is valid
102
+ */
103
+ static hasPrefetchCache() {
104
+ return !!_FeedManager.globalMemoryCache;
105
+ }
106
+ /**
107
+ * Clear prefetch cache
108
+ */
109
+ static clearPrefetchCache() {
110
+ _FeedManager.globalMemoryCache = null;
111
+ }
76
112
  // ═══════════════════════════════════════════════════════════════
77
113
  // PUBLIC API
78
114
  // ═══════════════════════════════════════════════════════════════
@@ -89,6 +125,12 @@ var FeedManager = class {
89
125
  * - Prevents duplicate API calls from rapid UI interactions
90
126
  */
91
127
  async loadInitial() {
128
+ if (_FeedManager.globalMemoryCache) {
129
+ const { items, nextCursor } = _FeedManager.globalMemoryCache;
130
+ this.hydrateFromSnapshot(items, nextCursor, { markAsStale: false });
131
+ _FeedManager.globalMemoryCache = null;
132
+ return;
133
+ }
92
134
  const dedupeKey = "__initial__";
93
135
  const existingRequest = this.inFlightRequests.get(dedupeKey);
94
136
  if (existingRequest) {
@@ -605,6 +647,12 @@ var FeedManager = class {
605
647
  };
606
648
  }
607
649
  };
650
+ // ═══════════════════════════════════════════════════════════════
651
+ // STATIC MEMORY CACHE (PREFETCH)
652
+ // ═══════════════════════════════════════════════════════════════
653
+ /** Static memory cache for explicit prefetching */
654
+ _FeedManager.globalMemoryCache = null;
655
+ var FeedManager = _FeedManager;
608
656
 
609
657
  // src/player/types.ts
610
658
  var PlayerStatus = /* @__PURE__ */ ((PlayerStatus2) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xhub-short/core",
3
3
  "sideEffects": false,
4
- "version": "0.1.0-beta.3",
4
+ "version": "0.1.0-beta.5",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -21,13 +21,13 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "zustand": "^5.0.0",
24
- "@xhub-short/contracts": "0.1.0-beta.3"
24
+ "@xhub-short/contracts": "0.1.0-beta.5"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsup": "^8.3.0",
28
28
  "typescript": "^5.7.0",
29
29
  "vitest": "^2.1.0",
30
- "@xhub-short/vitest-config": "0.0.1-beta.2",
30
+ "@xhub-short/vitest-config": "0.0.1-beta.4",
31
31
  "@xhub-short/tsconfig": "0.0.0"
32
32
  },
33
33
  "scripts": {