@nexushub/client 0.0.7 → 0.0.8
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/cache-CtPpNvIZ.d.cts +11 -0
- package/dist/cache-CtPpNvIZ.d.ts +11 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-OBGZSXTJ.cjs +10 -0
- package/dist/content/local-cache-client.cjs +2 -1
- package/dist/content/local-cache-client.d.cts +4 -1
- package/dist/content/local-cache-client.d.ts +4 -1
- package/dist/content/local-cache-client.js +5 -2
- package/dist/content/local-cache-server.cjs +109 -7
- package/dist/content/local-cache-server.d.cts +3 -1
- package/dist/content/local-cache-server.d.ts +3 -1
- package/dist/content/local-cache-server.js +112 -1
- package/dist/index.cjs +189 -110
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +143 -40
- package/package.json +4 -1
- package/dist/chunk-2JRYABGG.cjs +0 -117
- package/dist/chunk-BPQMAYT3.js +0 -110
package/dist/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { createContext, useState, useCallback, useEffect, useContext, useRef, useMemo } from 'react';
|
|
5
|
-
import { usePathname, useSearchParams } from 'next/navigation';
|
|
6
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import {
|
|
2
|
+
__require
|
|
3
|
+
} from "./chunk-3RG5ZIWI.js";
|
|
7
4
|
|
|
8
5
|
// src/config.ts
|
|
9
6
|
var DEFAULT_API_URL = "http://localhost:3001";
|
|
@@ -310,6 +307,22 @@ var BrowserCache = class {
|
|
|
310
307
|
}
|
|
311
308
|
};
|
|
312
309
|
|
|
310
|
+
// src/content/cache.ts
|
|
311
|
+
var LocalCacheConstructor;
|
|
312
|
+
if (typeof window === "undefined") {
|
|
313
|
+
try {
|
|
314
|
+
const serverPath = "./local-cache-server";
|
|
315
|
+
LocalCacheConstructor = __require(serverPath).LocalCache;
|
|
316
|
+
} catch (e) {
|
|
317
|
+
LocalCacheConstructor = class Dummy {
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
const clientPath = "./local-cache-client";
|
|
322
|
+
LocalCacheConstructor = __require(clientPath).LocalCache;
|
|
323
|
+
}
|
|
324
|
+
var LocalCache = LocalCacheConstructor;
|
|
325
|
+
|
|
313
326
|
// src/content/strategies.ts
|
|
314
327
|
var RateLimiter = class {
|
|
315
328
|
constructor(config) {
|
|
@@ -321,7 +334,7 @@ var RateLimiter = class {
|
|
|
321
334
|
const windowStart = now - this.config.timeWindow;
|
|
322
335
|
this.requests = this.requests.filter((time) => time > windowStart);
|
|
323
336
|
if (this.requests.length >= this.config.maxRequests) {
|
|
324
|
-
this.requests[0];
|
|
337
|
+
const oldestRequest = this.requests[0];
|
|
325
338
|
const waitTime = windowStart + this.config.timeWindow - now;
|
|
326
339
|
if (waitTime > 0) {
|
|
327
340
|
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
@@ -557,7 +570,9 @@ var ContentEngine = class {
|
|
|
557
570
|
() => this._getPage(slug, options)
|
|
558
571
|
);
|
|
559
572
|
if (this.config.debug && duration > 100) {
|
|
560
|
-
console.warn(
|
|
573
|
+
console.warn(
|
|
574
|
+
`[NexusHub] \u26A0\uFE0F getPage("${slug}") took ${duration.toFixed(2)}ms`
|
|
575
|
+
);
|
|
561
576
|
}
|
|
562
577
|
return result;
|
|
563
578
|
}
|
|
@@ -582,11 +597,19 @@ var ContentEngine = class {
|
|
|
582
597
|
await this.rateLimiter.checkLimit();
|
|
583
598
|
const data = await this.backoff.execute(
|
|
584
599
|
async () => {
|
|
585
|
-
return this.fetchPage(
|
|
600
|
+
return this.fetchPage(
|
|
601
|
+
slug,
|
|
602
|
+
cacheKey,
|
|
603
|
+
tags,
|
|
604
|
+
revalidate,
|
|
605
|
+
forceRefresh
|
|
606
|
+
);
|
|
586
607
|
},
|
|
587
608
|
(attempt, delay, error) => {
|
|
588
609
|
if (this.config.debug) {
|
|
589
|
-
console.log(
|
|
610
|
+
console.log(
|
|
611
|
+
`[NexusHub] \u{1F504} Retry ${attempt} for '${slug}' after ${delay}ms: ${error.message}`
|
|
612
|
+
);
|
|
590
613
|
}
|
|
591
614
|
}
|
|
592
615
|
);
|
|
@@ -611,7 +634,9 @@ var ContentEngine = class {
|
|
|
611
634
|
() => this._getCollection(collectionId, query, options)
|
|
612
635
|
);
|
|
613
636
|
if (this.config.debug && duration > 100) {
|
|
614
|
-
console.warn(
|
|
637
|
+
console.warn(
|
|
638
|
+
`[NexusHub] \u26A0\uFE0F getCollection("${collectionId}") took ${duration.toFixed(2)}ms`
|
|
639
|
+
);
|
|
615
640
|
}
|
|
616
641
|
return result;
|
|
617
642
|
}
|
|
@@ -625,19 +650,30 @@ var ContentEngine = class {
|
|
|
625
650
|
} = options;
|
|
626
651
|
const queryString = buildQueryString(normalizedQuery);
|
|
627
652
|
const cacheKey = `collection:${collectionId}:${queryString}`;
|
|
628
|
-
const cached = this.checkCaches(
|
|
653
|
+
const cached = this.checkCaches(
|
|
654
|
+
cacheKey,
|
|
655
|
+
forceRefresh,
|
|
656
|
+
includeMetadata
|
|
657
|
+
);
|
|
629
658
|
if (cached) {
|
|
630
659
|
if (this.config.debug) {
|
|
631
|
-
console.log(
|
|
660
|
+
console.log(
|
|
661
|
+
`[NexusHub] \u26A1 Served collection '${collectionId}' from memory cache.`
|
|
662
|
+
);
|
|
632
663
|
}
|
|
633
664
|
return includeMetadata ? cached : cached.data;
|
|
634
665
|
}
|
|
635
666
|
if (!forceRefresh && process.env.NODE_ENV === "development") {
|
|
636
667
|
const localCollection = this.localCache.getCollection(collectionId);
|
|
637
668
|
if (localCollection) {
|
|
638
|
-
const result = this.applyLocalQuery(
|
|
669
|
+
const result = this.applyLocalQuery(
|
|
670
|
+
localCollection,
|
|
671
|
+
normalizedQuery
|
|
672
|
+
);
|
|
639
673
|
if (this.config.debug) {
|
|
640
|
-
console.log(
|
|
674
|
+
console.log(
|
|
675
|
+
`[NexusHub] \u{1F4C1} Served collection '${collectionId}' from local cache.`
|
|
676
|
+
);
|
|
641
677
|
}
|
|
642
678
|
this.memoryCache.set(cacheKey, result, {
|
|
643
679
|
tags: [...tags, CacheTags.collection(collectionId)],
|
|
@@ -650,7 +686,13 @@ var ContentEngine = class {
|
|
|
650
686
|
try {
|
|
651
687
|
await this.rateLimiter.checkLimit();
|
|
652
688
|
const result = await this.backoff.execute(async () => {
|
|
653
|
-
return this.fetchCollection(
|
|
689
|
+
return this.fetchCollection(
|
|
690
|
+
collectionId,
|
|
691
|
+
normalizedQuery,
|
|
692
|
+
cacheKey,
|
|
693
|
+
tags,
|
|
694
|
+
revalidate
|
|
695
|
+
);
|
|
654
696
|
});
|
|
655
697
|
this.circuitBreaker.recordSuccess();
|
|
656
698
|
return includeMetadata ? result : result.data;
|
|
@@ -658,10 +700,15 @@ var ContentEngine = class {
|
|
|
658
700
|
this.circuitBreaker.recordFailure();
|
|
659
701
|
const staleCache = this.memoryCache.get(cacheKey);
|
|
660
702
|
if (staleCache && !forceRefresh) {
|
|
661
|
-
console.warn(
|
|
703
|
+
console.warn(
|
|
704
|
+
`[NexusHub] \u26A0\uFE0F Using stale cache for collection '${collectionId}'`
|
|
705
|
+
);
|
|
662
706
|
return includeMetadata ? staleCache : staleCache.data;
|
|
663
707
|
}
|
|
664
|
-
throw this.normalizeError(
|
|
708
|
+
throw this.normalizeError(
|
|
709
|
+
error,
|
|
710
|
+
`Failed to fetch collection '${collectionId}'`
|
|
711
|
+
);
|
|
665
712
|
}
|
|
666
713
|
}
|
|
667
714
|
/**
|
|
@@ -677,7 +724,8 @@ var ContentEngine = class {
|
|
|
677
724
|
if (!forceRefresh && this.cacheStrategy === "memory") {
|
|
678
725
|
const cached = this.memoryCache.get(cacheKey);
|
|
679
726
|
if (cached && this.isCacheValid(cached.metadata)) {
|
|
680
|
-
if (this.config.debug)
|
|
727
|
+
if (this.config.debug)
|
|
728
|
+
console.log("[NexusHub] \u26A1 Served globals from memory cache.");
|
|
681
729
|
return cached.data;
|
|
682
730
|
}
|
|
683
731
|
}
|
|
@@ -701,13 +749,10 @@ var ContentEngine = class {
|
|
|
701
749
|
await this.rateLimiter.checkLimit();
|
|
702
750
|
const url = `${this.config.apiUrl}/content/${this.config.projectId}/globals`;
|
|
703
751
|
const params = include.length > 0 ? `?include=${include.join(",")}` : "";
|
|
704
|
-
const res = await this.fetchWithTimeout(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
headers: this.getHeaders()
|
|
709
|
-
}
|
|
710
|
-
);
|
|
752
|
+
const res = await this.fetchWithTimeout(`${url}${params}`, {
|
|
753
|
+
method: "GET",
|
|
754
|
+
headers: this.getHeaders()
|
|
755
|
+
});
|
|
711
756
|
if (!res.ok) {
|
|
712
757
|
throw new Error(`API Error ${res.status}: ${res.statusText}`);
|
|
713
758
|
}
|
|
@@ -823,7 +868,8 @@ var ContentEngine = class {
|
|
|
823
868
|
eventSource = new EventSource(url);
|
|
824
869
|
eventSource.onopen = () => {
|
|
825
870
|
retryCount = 0;
|
|
826
|
-
if (this.config.debug)
|
|
871
|
+
if (this.config.debug)
|
|
872
|
+
console.log("[NexusHub] \u{1F7E2} Real-time stream connected");
|
|
827
873
|
};
|
|
828
874
|
eventSource.onmessage = (event) => {
|
|
829
875
|
try {
|
|
@@ -844,7 +890,9 @@ var ContentEngine = class {
|
|
|
844
890
|
if (isClosed) return;
|
|
845
891
|
const timeout = Math.min(1e3 * Math.pow(2, retryCount), 1e4);
|
|
846
892
|
retryCount++;
|
|
847
|
-
console.warn(
|
|
893
|
+
console.warn(
|
|
894
|
+
`[NexusHub] \u{1F534} Stream disconnected. Reconnecting in ${timeout}ms...`
|
|
895
|
+
);
|
|
848
896
|
setTimeout(connect, timeout);
|
|
849
897
|
};
|
|
850
898
|
};
|
|
@@ -916,7 +964,9 @@ var ContentEngine = class {
|
|
|
916
964
|
invalidateCache(tags) {
|
|
917
965
|
this.memoryCache.invalidateByTags(tags);
|
|
918
966
|
if (this.config.debug) {
|
|
919
|
-
console.log(
|
|
967
|
+
console.log(
|
|
968
|
+
`[NexusHub] \u267B\uFE0F Invalidated cache for tags: ${tags.join(", ")}`
|
|
969
|
+
);
|
|
920
970
|
}
|
|
921
971
|
}
|
|
922
972
|
/**
|
|
@@ -956,7 +1006,9 @@ var ContentEngine = class {
|
|
|
956
1006
|
});
|
|
957
1007
|
if (!res.ok) {
|
|
958
1008
|
if (res.status === 404) {
|
|
959
|
-
throw new Error(
|
|
1009
|
+
throw new Error(
|
|
1010
|
+
`Page '${slug}' not found. Check your Dashboard or Seed data.`
|
|
1011
|
+
);
|
|
960
1012
|
}
|
|
961
1013
|
throw new Error(`API Error ${res.status}: ${res.statusText}`);
|
|
962
1014
|
}
|
|
@@ -973,7 +1025,11 @@ var ContentEngine = class {
|
|
|
973
1025
|
};
|
|
974
1026
|
this.writeCache(cacheKey, cacheEntry.data, {
|
|
975
1027
|
revalidate,
|
|
976
|
-
tags: [
|
|
1028
|
+
tags: [
|
|
1029
|
+
CacheTags.project(this.config.projectId),
|
|
1030
|
+
CacheTags.content(slug),
|
|
1031
|
+
...tags
|
|
1032
|
+
]
|
|
977
1033
|
});
|
|
978
1034
|
return cacheEntry;
|
|
979
1035
|
}
|
|
@@ -1003,7 +1059,11 @@ var ContentEngine = class {
|
|
|
1003
1059
|
};
|
|
1004
1060
|
this.writeCache(cacheKey, cacheEntry.data, {
|
|
1005
1061
|
revalidate,
|
|
1006
|
-
tags: [
|
|
1062
|
+
tags: [
|
|
1063
|
+
CacheTags.project(this.config.projectId),
|
|
1064
|
+
CacheTags.collection(collectionId),
|
|
1065
|
+
...tags
|
|
1066
|
+
]
|
|
1007
1067
|
});
|
|
1008
1068
|
return cacheEntry;
|
|
1009
1069
|
}
|
|
@@ -1184,6 +1244,15 @@ var getVisitorId = async () => {
|
|
|
1184
1244
|
}
|
|
1185
1245
|
return vid;
|
|
1186
1246
|
};
|
|
1247
|
+
|
|
1248
|
+
// src/analytics/vitals.ts
|
|
1249
|
+
import {
|
|
1250
|
+
onCLS,
|
|
1251
|
+
onLCP,
|
|
1252
|
+
onTTFB,
|
|
1253
|
+
onINP,
|
|
1254
|
+
onFCP
|
|
1255
|
+
} from "web-vitals";
|
|
1187
1256
|
var METRIC_KEY_MAP = {
|
|
1188
1257
|
CLS: "cls",
|
|
1189
1258
|
LCP: "lcp",
|
|
@@ -1306,10 +1375,12 @@ var EventStorage = class {
|
|
|
1306
1375
|
return new Promise((resolve, reject) => {
|
|
1307
1376
|
const transaction = this.db.transaction([STORE_NAME], "readwrite");
|
|
1308
1377
|
const store = transaction.objectStore(STORE_NAME);
|
|
1378
|
+
let processed = 0;
|
|
1379
|
+
let errors = 0;
|
|
1309
1380
|
transaction.oncomplete = () => resolve();
|
|
1310
1381
|
transaction.onerror = () => reject(transaction.error);
|
|
1311
1382
|
ids.forEach((id) => {
|
|
1312
|
-
store.delete(id);
|
|
1383
|
+
const req = store.delete(id);
|
|
1313
1384
|
});
|
|
1314
1385
|
});
|
|
1315
1386
|
}
|
|
@@ -1339,7 +1410,7 @@ var Tracker = class {
|
|
|
1339
1410
|
// FIX: Add this property
|
|
1340
1411
|
this.isFlushing = false;
|
|
1341
1412
|
this.config = config;
|
|
1342
|
-
this.config.apiUrl.replace("/v1", "").replace(/\/$/, "");
|
|
1413
|
+
const baseUrl = this.config.apiUrl.replace("/v1", "").replace(/\/$/, "");
|
|
1343
1414
|
this.endpoint = `${this.config.analyticsUrl}/api/collect`;
|
|
1344
1415
|
this.circuitBreaker = new CircuitBreaker();
|
|
1345
1416
|
this.sessionStart = Date.now();
|
|
@@ -1761,6 +1832,14 @@ var NexusClient = class {
|
|
|
1761
1832
|
};
|
|
1762
1833
|
var nexus = new NexusClient();
|
|
1763
1834
|
var createNexusClient = (config) => new NexusClient(config);
|
|
1835
|
+
|
|
1836
|
+
// src/components/NexusProvider.tsx
|
|
1837
|
+
import React2, { createContext as createContext2, useEffect as useEffect2, useRef, useMemo } from "react";
|
|
1838
|
+
import { usePathname, useSearchParams } from "next/navigation";
|
|
1839
|
+
|
|
1840
|
+
// src/auth/context.tsx
|
|
1841
|
+
import { createContext, useContext, useEffect, useState, useCallback } from "react";
|
|
1842
|
+
import { jsx } from "react/jsx-runtime";
|
|
1764
1843
|
var AuthContext = createContext(null);
|
|
1765
1844
|
var AuthProvider = ({
|
|
1766
1845
|
children,
|
|
@@ -1935,7 +2014,10 @@ async function parseError(res) {
|
|
|
1935
2014
|
};
|
|
1936
2015
|
}
|
|
1937
2016
|
}
|
|
1938
|
-
|
|
2017
|
+
|
|
2018
|
+
// src/components/NexusProvider.tsx
|
|
2019
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
2020
|
+
var NexusContext = createContext2(nexus);
|
|
1939
2021
|
var NexusProvider = ({
|
|
1940
2022
|
children,
|
|
1941
2023
|
projectId,
|
|
@@ -1951,7 +2033,7 @@ var NexusProvider = ({
|
|
|
1951
2033
|
}
|
|
1952
2034
|
return nexus.getConfig();
|
|
1953
2035
|
}, [projectId]);
|
|
1954
|
-
|
|
2036
|
+
useEffect2(() => {
|
|
1955
2037
|
if (typeof window === "undefined" || disableAnalytics) return;
|
|
1956
2038
|
if (!isInitialized.current) {
|
|
1957
2039
|
if (!nexus.analytics) {
|
|
@@ -1970,15 +2052,36 @@ var NexusProvider = ({
|
|
|
1970
2052
|
}
|
|
1971
2053
|
};
|
|
1972
2054
|
}, [disableAnalytics]);
|
|
1973
|
-
|
|
2055
|
+
useEffect2(() => {
|
|
1974
2056
|
if (nexus.analytics && !disableAnalytics) {
|
|
1975
2057
|
nexus.analytics.pageView();
|
|
1976
2058
|
}
|
|
1977
2059
|
}, [pathname, searchParams, disableAnalytics]);
|
|
1978
|
-
return /* @__PURE__ */
|
|
2060
|
+
return /* @__PURE__ */ jsx2(NexusContext.Provider, { value: nexus, children: /* @__PURE__ */ jsx2(AuthProvider, { config, children }) });
|
|
1979
2061
|
};
|
|
1980
2062
|
|
|
1981
2063
|
// src/index.ts
|
|
1982
2064
|
var VERSION = "0.0.1";
|
|
1983
|
-
|
|
1984
|
-
|
|
2065
|
+
export {
|
|
2066
|
+
AnalyticsEngine,
|
|
2067
|
+
AuthProvider,
|
|
2068
|
+
BrowserCache,
|
|
2069
|
+
CacheTags,
|
|
2070
|
+
ContentEngine,
|
|
2071
|
+
DEFAULT_ANALYTICS_URL,
|
|
2072
|
+
DEFAULT_API_URL,
|
|
2073
|
+
LOCAL_NEST_URL,
|
|
2074
|
+
LOCAL_RUST_URL,
|
|
2075
|
+
LocalCache,
|
|
2076
|
+
MemoryCache,
|
|
2077
|
+
NexusClient,
|
|
2078
|
+
NexusProvider,
|
|
2079
|
+
VERSION,
|
|
2080
|
+
createNexusClient,
|
|
2081
|
+
getEnvConfig,
|
|
2082
|
+
getFullConfig,
|
|
2083
|
+
mergeConfigs,
|
|
2084
|
+
nexus,
|
|
2085
|
+
useNexusAuth,
|
|
2086
|
+
validateConfig
|
|
2087
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexushub/client",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"description": "The God-Tier NexusHub SDK",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"nexus": "./dist/cli.cjs"
|
|
19
19
|
},
|
|
20
20
|
"browser": {
|
|
21
|
+
"fs": false,
|
|
22
|
+
"path": false,
|
|
23
|
+
"os": false,
|
|
21
24
|
"./dist/content/local-cache-server.js": "./dist/content/local-cache-client.js",
|
|
22
25
|
"./dist/content/local-cache-server.cjs": "./dist/content/local-cache-client.cjs"
|
|
23
26
|
},
|
package/dist/chunk-2JRYABGG.cjs
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
var path = require('path');
|
|
5
|
-
|
|
6
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
-
|
|
8
|
-
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
9
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
10
|
-
|
|
11
|
-
// src/content/local-cache-server.ts
|
|
12
|
-
var LocalCache = class {
|
|
13
|
-
constructor(customPath) {
|
|
14
|
-
this.data = null;
|
|
15
|
-
this.hasLoaded = false;
|
|
16
|
-
this.cachePath = customPath || ".nexus/cache.json";
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Returns true if the local cache file has been successfully
|
|
20
|
-
* loaded and parsed into memory.
|
|
21
|
-
*/
|
|
22
|
-
isLoaded() {
|
|
23
|
-
return this.hasLoaded;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Reads the cache file from the filesystem.
|
|
27
|
-
* Internal method called lazily by the getters.
|
|
28
|
-
*/
|
|
29
|
-
load() {
|
|
30
|
-
if (typeof window !== "undefined") return;
|
|
31
|
-
if (this.hasLoaded) return;
|
|
32
|
-
try {
|
|
33
|
-
const fullPath = path__default.default.resolve(process.cwd(), this.cachePath);
|
|
34
|
-
if (fs__default.default.existsSync(fullPath)) {
|
|
35
|
-
const fileContent = fs__default.default.readFileSync(fullPath, "utf-8");
|
|
36
|
-
this.data = JSON.parse(fileContent);
|
|
37
|
-
this.hasLoaded = true;
|
|
38
|
-
if (process.env.NODE_ENV === "development") {
|
|
39
|
-
console.log(
|
|
40
|
-
`\u26A1 NexusHub: Serving content from local cache (${this.cachePath})`
|
|
41
|
-
);
|
|
42
|
-
console.log(` - Pages: ${this.data.pages?.length || 0}`);
|
|
43
|
-
console.log(
|
|
44
|
-
` - Collections: ${Object.keys(this.data.collections || {}).length}`
|
|
45
|
-
);
|
|
46
|
-
console.log(
|
|
47
|
-
` - Globals: ${this.data.globals ? "Loaded" : "Not found"}`
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
if (this.shouldWarnAboutMissingCache(error)) {
|
|
53
|
-
console.warn(
|
|
54
|
-
`\u26A0\uFE0F NexusHub: Local cache not found or invalid at ${this.cachePath}
|
|
55
|
-
Run \`npx nexus pull\` to generate seed data if you want to work offline.`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Retrieve a specific page from the local pages array.
|
|
62
|
-
*/
|
|
63
|
-
getPage(slug) {
|
|
64
|
-
this.load();
|
|
65
|
-
if (!this.data?.pages) return null;
|
|
66
|
-
const page = this.data.pages.find((p) => p.slug === slug);
|
|
67
|
-
if (!page) {
|
|
68
|
-
if (process.env.NODE_ENV === "development") {
|
|
69
|
-
console.warn(`\u26A0\uFE0F NexusHub: Page '${slug}' not found in local cache.`);
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
return page.data;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Retrieve an entire collection from the local collections map.
|
|
77
|
-
*/
|
|
78
|
-
getCollection(collectionId) {
|
|
79
|
-
this.load();
|
|
80
|
-
if (!this.data?.collections) return null;
|
|
81
|
-
const collection = this.data.collections[collectionId];
|
|
82
|
-
if (!collection) {
|
|
83
|
-
if (process.env.NODE_ENV === "development") {
|
|
84
|
-
console.warn(
|
|
85
|
-
`\u26A0\uFE0F NexusHub: Collection '${collectionId}' not found in local cache.`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
return collection;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Retrieve global settings from the local cache.
|
|
94
|
-
*/
|
|
95
|
-
getGlobals() {
|
|
96
|
-
this.load();
|
|
97
|
-
return this.data?.globals || null;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Returns the entire raw JSON data structure from the cache file.
|
|
101
|
-
*/
|
|
102
|
-
getAllData() {
|
|
103
|
-
this.load();
|
|
104
|
-
return this.data;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Helper to determine if we should bother the user with a warning.
|
|
108
|
-
*/
|
|
109
|
-
shouldWarnAboutMissingCache(error) {
|
|
110
|
-
const isMissing = error.code === "ENOENT";
|
|
111
|
-
const isMalformed = error instanceof SyntaxError;
|
|
112
|
-
if (process.env.NODE_ENV !== "development") return false;
|
|
113
|
-
return !isMissing || isMalformed;
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
exports.LocalCache = LocalCache;
|
package/dist/chunk-BPQMAYT3.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
// src/content/local-cache-server.ts
|
|
5
|
-
var LocalCache = class {
|
|
6
|
-
constructor(customPath) {
|
|
7
|
-
this.data = null;
|
|
8
|
-
this.hasLoaded = false;
|
|
9
|
-
this.cachePath = customPath || ".nexus/cache.json";
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Returns true if the local cache file has been successfully
|
|
13
|
-
* loaded and parsed into memory.
|
|
14
|
-
*/
|
|
15
|
-
isLoaded() {
|
|
16
|
-
return this.hasLoaded;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Reads the cache file from the filesystem.
|
|
20
|
-
* Internal method called lazily by the getters.
|
|
21
|
-
*/
|
|
22
|
-
load() {
|
|
23
|
-
if (typeof window !== "undefined") return;
|
|
24
|
-
if (this.hasLoaded) return;
|
|
25
|
-
try {
|
|
26
|
-
const fullPath = path.resolve(process.cwd(), this.cachePath);
|
|
27
|
-
if (fs.existsSync(fullPath)) {
|
|
28
|
-
const fileContent = fs.readFileSync(fullPath, "utf-8");
|
|
29
|
-
this.data = JSON.parse(fileContent);
|
|
30
|
-
this.hasLoaded = true;
|
|
31
|
-
if (process.env.NODE_ENV === "development") {
|
|
32
|
-
console.log(
|
|
33
|
-
`\u26A1 NexusHub: Serving content from local cache (${this.cachePath})`
|
|
34
|
-
);
|
|
35
|
-
console.log(` - Pages: ${this.data.pages?.length || 0}`);
|
|
36
|
-
console.log(
|
|
37
|
-
` - Collections: ${Object.keys(this.data.collections || {}).length}`
|
|
38
|
-
);
|
|
39
|
-
console.log(
|
|
40
|
-
` - Globals: ${this.data.globals ? "Loaded" : "Not found"}`
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
} catch (error) {
|
|
45
|
-
if (this.shouldWarnAboutMissingCache(error)) {
|
|
46
|
-
console.warn(
|
|
47
|
-
`\u26A0\uFE0F NexusHub: Local cache not found or invalid at ${this.cachePath}
|
|
48
|
-
Run \`npx nexus pull\` to generate seed data if you want to work offline.`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Retrieve a specific page from the local pages array.
|
|
55
|
-
*/
|
|
56
|
-
getPage(slug) {
|
|
57
|
-
this.load();
|
|
58
|
-
if (!this.data?.pages) return null;
|
|
59
|
-
const page = this.data.pages.find((p) => p.slug === slug);
|
|
60
|
-
if (!page) {
|
|
61
|
-
if (process.env.NODE_ENV === "development") {
|
|
62
|
-
console.warn(`\u26A0\uFE0F NexusHub: Page '${slug}' not found in local cache.`);
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return page.data;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Retrieve an entire collection from the local collections map.
|
|
70
|
-
*/
|
|
71
|
-
getCollection(collectionId) {
|
|
72
|
-
this.load();
|
|
73
|
-
if (!this.data?.collections) return null;
|
|
74
|
-
const collection = this.data.collections[collectionId];
|
|
75
|
-
if (!collection) {
|
|
76
|
-
if (process.env.NODE_ENV === "development") {
|
|
77
|
-
console.warn(
|
|
78
|
-
`\u26A0\uFE0F NexusHub: Collection '${collectionId}' not found in local cache.`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
return collection;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Retrieve global settings from the local cache.
|
|
87
|
-
*/
|
|
88
|
-
getGlobals() {
|
|
89
|
-
this.load();
|
|
90
|
-
return this.data?.globals || null;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Returns the entire raw JSON data structure from the cache file.
|
|
94
|
-
*/
|
|
95
|
-
getAllData() {
|
|
96
|
-
this.load();
|
|
97
|
-
return this.data;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Helper to determine if we should bother the user with a warning.
|
|
101
|
-
*/
|
|
102
|
-
shouldWarnAboutMissingCache(error) {
|
|
103
|
-
const isMissing = error.code === "ENOENT";
|
|
104
|
-
const isMalformed = error instanceof SyntaxError;
|
|
105
|
-
if (process.env.NODE_ENV !== "development") return false;
|
|
106
|
-
return !isMissing || isMalformed;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export { LocalCache };
|