@nexushub/client 0.0.7 → 0.0.9

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.
@@ -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 };