@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.
- package/dist/cache-types-B39iNHfE.d.cts +9 -0
- package/dist/cache-types-B39iNHfE.d.ts +9 -0
- package/dist/content/local-cache-client.cjs +13 -10
- package/dist/content/local-cache-client.d.cts +9 -7
- package/dist/content/local-cache-client.d.ts +9 -7
- package/dist/content/local-cache-client.js +14 -9
- package/dist/content/local-cache-server.cjs +108 -8
- package/dist/content/local-cache-server.d.cts +7 -5
- package/dist/content/local-cache-server.d.ts +7 -5
- package/dist/content/local-cache-server.js +110 -1
- package/dist/index.cjs +218 -117
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +171 -46
- package/package.json +4 -1
- package/dist/chunk-2JRYABGG.cjs +0 -117
- package/dist/chunk-BPQMAYT3.js +0 -110
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// src/content/local-cache-client.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/content/local-cache-client.ts
|
|
4
2
|
var LocalCache = class {
|
|
5
3
|
constructor(customPath) {
|
|
4
|
+
// Maintain private properties for type parity with the Server version
|
|
6
5
|
this.data = null;
|
|
7
6
|
this.hasLoaded = false;
|
|
8
7
|
this.cachePath = customPath || ".nexus/cache.json";
|
|
@@ -15,7 +14,7 @@ var LocalCache = class {
|
|
|
15
14
|
return false;
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
|
-
* No-op method to maintain API compatibility
|
|
17
|
+
* No-op method to maintain internal API compatibility.
|
|
19
18
|
*/
|
|
20
19
|
load() {
|
|
21
20
|
return;
|
|
@@ -24,33 +23,37 @@ var LocalCache = class {
|
|
|
24
23
|
* Returns null. Browsers should fetch pages from the Remote API
|
|
25
24
|
* or the Memory/Browser cache.
|
|
26
25
|
*/
|
|
27
|
-
getPage(_slug) {
|
|
26
|
+
async getPage(_slug) {
|
|
28
27
|
return null;
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
31
30
|
* Returns null. Browsers should fetch collections from the Remote API.
|
|
32
31
|
*/
|
|
33
|
-
getCollection(_collectionId) {
|
|
32
|
+
async getCollection(_collectionId) {
|
|
34
33
|
return null;
|
|
35
34
|
}
|
|
36
35
|
/**
|
|
37
36
|
* Returns null.
|
|
38
37
|
*/
|
|
39
|
-
getGlobals() {
|
|
38
|
+
async getGlobals() {
|
|
40
39
|
return null;
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* Returns null.
|
|
44
43
|
*/
|
|
45
|
-
getAllData() {
|
|
44
|
+
async getAllData() {
|
|
46
45
|
return null;
|
|
47
46
|
}
|
|
48
47
|
/**
|
|
49
48
|
* Dummy helper to match Node implementation.
|
|
50
49
|
*/
|
|
51
|
-
shouldWarnAboutMissingCache(
|
|
52
|
-
|
|
50
|
+
shouldWarnAboutMissingCache(error) {
|
|
51
|
+
const isMissing = error.code === "ENOENT";
|
|
52
|
+
const isMalformed = error instanceof SyntaxError;
|
|
53
|
+
if (process.env.NODE_ENV !== "development") return false;
|
|
54
|
+
return !isMissing || isMalformed;
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
57
|
|
|
58
|
+
|
|
56
59
|
exports.LocalCache = LocalCache;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { I as ILocalCache } from '../cache-types-B39iNHfE.cjs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* NexusHub LocalCache (Browser Implementation)
|
|
3
5
|
*
|
|
@@ -5,10 +7,10 @@
|
|
|
5
7
|
* Since the browser has no access to the Node.js File System (fs), this
|
|
6
8
|
* implementation returns null for all operations.
|
|
7
9
|
*
|
|
8
|
-
* The real logic is located in local-cache.
|
|
10
|
+
* The real logic is located in local-cache-server.ts and is swapped
|
|
9
11
|
* automatically by the bundler via the "browser" field in package.json.
|
|
10
12
|
*/
|
|
11
|
-
declare class LocalCache {
|
|
13
|
+
declare class LocalCache implements ILocalCache {
|
|
12
14
|
private data;
|
|
13
15
|
private hasLoaded;
|
|
14
16
|
private cachePath;
|
|
@@ -19,26 +21,26 @@ declare class LocalCache {
|
|
|
19
21
|
*/
|
|
20
22
|
isLoaded(): boolean;
|
|
21
23
|
/**
|
|
22
|
-
* No-op method to maintain API compatibility
|
|
24
|
+
* No-op method to maintain internal API compatibility.
|
|
23
25
|
*/
|
|
24
26
|
private load;
|
|
25
27
|
/**
|
|
26
28
|
* Returns null. Browsers should fetch pages from the Remote API
|
|
27
29
|
* or the Memory/Browser cache.
|
|
28
30
|
*/
|
|
29
|
-
getPage(_slug: string): any
|
|
31
|
+
getPage(_slug: string): Promise<any>;
|
|
30
32
|
/**
|
|
31
33
|
* Returns null. Browsers should fetch collections from the Remote API.
|
|
32
34
|
*/
|
|
33
|
-
getCollection(_collectionId: string): any[] | null
|
|
35
|
+
getCollection(_collectionId: string): Promise<any[] | null>;
|
|
34
36
|
/**
|
|
35
37
|
* Returns null.
|
|
36
38
|
*/
|
|
37
|
-
getGlobals(): any
|
|
39
|
+
getGlobals(): Promise<any>;
|
|
38
40
|
/**
|
|
39
41
|
* Returns null.
|
|
40
42
|
*/
|
|
41
|
-
getAllData(): any
|
|
43
|
+
getAllData(): Promise<any>;
|
|
42
44
|
/**
|
|
43
45
|
* Dummy helper to match Node implementation.
|
|
44
46
|
*/
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { I as ILocalCache } from '../cache-types-B39iNHfE.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* NexusHub LocalCache (Browser Implementation)
|
|
3
5
|
*
|
|
@@ -5,10 +7,10 @@
|
|
|
5
7
|
* Since the browser has no access to the Node.js File System (fs), this
|
|
6
8
|
* implementation returns null for all operations.
|
|
7
9
|
*
|
|
8
|
-
* The real logic is located in local-cache.
|
|
10
|
+
* The real logic is located in local-cache-server.ts and is swapped
|
|
9
11
|
* automatically by the bundler via the "browser" field in package.json.
|
|
10
12
|
*/
|
|
11
|
-
declare class LocalCache {
|
|
13
|
+
declare class LocalCache implements ILocalCache {
|
|
12
14
|
private data;
|
|
13
15
|
private hasLoaded;
|
|
14
16
|
private cachePath;
|
|
@@ -19,26 +21,26 @@ declare class LocalCache {
|
|
|
19
21
|
*/
|
|
20
22
|
isLoaded(): boolean;
|
|
21
23
|
/**
|
|
22
|
-
* No-op method to maintain API compatibility
|
|
24
|
+
* No-op method to maintain internal API compatibility.
|
|
23
25
|
*/
|
|
24
26
|
private load;
|
|
25
27
|
/**
|
|
26
28
|
* Returns null. Browsers should fetch pages from the Remote API
|
|
27
29
|
* or the Memory/Browser cache.
|
|
28
30
|
*/
|
|
29
|
-
getPage(_slug: string): any
|
|
31
|
+
getPage(_slug: string): Promise<any>;
|
|
30
32
|
/**
|
|
31
33
|
* Returns null. Browsers should fetch collections from the Remote API.
|
|
32
34
|
*/
|
|
33
|
-
getCollection(_collectionId: string): any[] | null
|
|
35
|
+
getCollection(_collectionId: string): Promise<any[] | null>;
|
|
34
36
|
/**
|
|
35
37
|
* Returns null.
|
|
36
38
|
*/
|
|
37
|
-
getGlobals(): any
|
|
39
|
+
getGlobals(): Promise<any>;
|
|
38
40
|
/**
|
|
39
41
|
* Returns null.
|
|
40
42
|
*/
|
|
41
|
-
getAllData(): any
|
|
43
|
+
getAllData(): Promise<any>;
|
|
42
44
|
/**
|
|
43
45
|
* Dummy helper to match Node implementation.
|
|
44
46
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/content/local-cache-client.ts
|
|
2
2
|
var LocalCache = class {
|
|
3
3
|
constructor(customPath) {
|
|
4
|
+
// Maintain private properties for type parity with the Server version
|
|
4
5
|
this.data = null;
|
|
5
6
|
this.hasLoaded = false;
|
|
6
7
|
this.cachePath = customPath || ".nexus/cache.json";
|
|
@@ -13,7 +14,7 @@ var LocalCache = class {
|
|
|
13
14
|
return false;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
|
-
* No-op method to maintain API compatibility
|
|
17
|
+
* No-op method to maintain internal API compatibility.
|
|
17
18
|
*/
|
|
18
19
|
load() {
|
|
19
20
|
return;
|
|
@@ -22,33 +23,37 @@ var LocalCache = class {
|
|
|
22
23
|
* Returns null. Browsers should fetch pages from the Remote API
|
|
23
24
|
* or the Memory/Browser cache.
|
|
24
25
|
*/
|
|
25
|
-
getPage(_slug) {
|
|
26
|
+
async getPage(_slug) {
|
|
26
27
|
return null;
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* Returns null. Browsers should fetch collections from the Remote API.
|
|
30
31
|
*/
|
|
31
|
-
getCollection(_collectionId) {
|
|
32
|
+
async getCollection(_collectionId) {
|
|
32
33
|
return null;
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* Returns null.
|
|
36
37
|
*/
|
|
37
|
-
getGlobals() {
|
|
38
|
+
async getGlobals() {
|
|
38
39
|
return null;
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* Returns null.
|
|
42
43
|
*/
|
|
43
|
-
getAllData() {
|
|
44
|
+
async getAllData() {
|
|
44
45
|
return null;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Dummy helper to match Node implementation.
|
|
48
49
|
*/
|
|
49
|
-
shouldWarnAboutMissingCache(
|
|
50
|
-
|
|
50
|
+
shouldWarnAboutMissingCache(error) {
|
|
51
|
+
const isMissing = error.code === "ENOENT";
|
|
52
|
+
const isMalformed = error instanceof SyntaxError;
|
|
53
|
+
if (process.env.NODE_ENV !== "development") return false;
|
|
54
|
+
return !isMissing || isMalformed;
|
|
51
55
|
}
|
|
52
56
|
};
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
export {
|
|
58
|
+
LocalCache
|
|
59
|
+
};
|
|
@@ -1,10 +1,110 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/content/local-cache-server.ts
|
|
2
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
3
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
4
|
+
var LocalCache = class {
|
|
5
|
+
constructor(customPath) {
|
|
6
|
+
this.data = null;
|
|
7
|
+
this.hasLoaded = false;
|
|
8
|
+
this.cachePath = customPath || ".nexus/cache.json";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the local cache file has been successfully
|
|
12
|
+
* loaded and parsed into memory.
|
|
13
|
+
*/
|
|
14
|
+
isLoaded() {
|
|
15
|
+
return this.hasLoaded;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reads the cache file from the filesystem.
|
|
19
|
+
* Internal method called lazily by the getters.
|
|
20
|
+
*/
|
|
21
|
+
load() {
|
|
22
|
+
if (typeof window !== "undefined") return;
|
|
23
|
+
if (this.hasLoaded) return;
|
|
24
|
+
try {
|
|
25
|
+
const fullPath = _path2.default.resolve(process.cwd(), this.cachePath);
|
|
26
|
+
if (_fs2.default.existsSync(fullPath)) {
|
|
27
|
+
const fileContent = _fs2.default.readFileSync(fullPath, "utf-8");
|
|
28
|
+
this.data = JSON.parse(fileContent);
|
|
29
|
+
this.hasLoaded = true;
|
|
30
|
+
if (process.env.NODE_ENV === "development") {
|
|
31
|
+
console.log(
|
|
32
|
+
`\u26A1 NexusHub: Serving content from local cache (${this.cachePath})`
|
|
33
|
+
);
|
|
34
|
+
console.log(` - Pages: ${_optionalChain([this, 'access', _ => _.data, 'access', _2 => _2.pages, 'optionalAccess', _3 => _3.length]) || 0}`);
|
|
35
|
+
console.log(
|
|
36
|
+
` - Collections: ${Object.keys(this.data.collections || {}).length}`
|
|
37
|
+
);
|
|
38
|
+
console.log(
|
|
39
|
+
` - Globals: ${this.data.globals ? "Loaded" : "Not found"}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (this.shouldWarnAboutMissingCache(error)) {
|
|
45
|
+
console.warn(
|
|
46
|
+
`\u26A0\uFE0F NexusHub: Local cache invalid at ${this.cachePath}
|
|
47
|
+
Run \`npx nexus pull\` to fix your seed data.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Retrieve a specific page from the local pages array.
|
|
54
|
+
*/
|
|
55
|
+
async getPage(slug) {
|
|
56
|
+
this.load();
|
|
57
|
+
if (!_optionalChain([this, 'access', _4 => _4.data, 'optionalAccess', _5 => _5.pages])) return null;
|
|
58
|
+
const page = this.data.pages.find((p) => p.slug === slug);
|
|
59
|
+
if (!page) {
|
|
60
|
+
if (process.env.NODE_ENV === "development") {
|
|
61
|
+
console.warn(`\u26A0\uFE0F NexusHub: Page '${slug}' not found in local cache.`);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return page.data;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Retrieve an entire collection from the local collections map.
|
|
69
|
+
*/
|
|
70
|
+
async getCollection(collectionId) {
|
|
71
|
+
this.load();
|
|
72
|
+
if (!_optionalChain([this, 'access', _6 => _6.data, 'optionalAccess', _7 => _7.collections])) return null;
|
|
73
|
+
const collection = this.data.collections[collectionId];
|
|
74
|
+
if (!collection) {
|
|
75
|
+
if (process.env.NODE_ENV === "development") {
|
|
76
|
+
console.warn(
|
|
77
|
+
`\u26A0\uFE0F NexusHub: Collection '${collectionId}' not found in local cache.`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return collection;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Retrieve global settings from the local cache.
|
|
86
|
+
*/
|
|
87
|
+
async getGlobals() {
|
|
88
|
+
this.load();
|
|
89
|
+
return _optionalChain([this, 'access', _8 => _8.data, 'optionalAccess', _9 => _9.globals]) || null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns the entire raw JSON data structure from the cache file.
|
|
93
|
+
*/
|
|
94
|
+
async getAllData() {
|
|
95
|
+
this.load();
|
|
96
|
+
return this.data;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Helper to determine if we should bother the user with a warning.
|
|
100
|
+
*/
|
|
101
|
+
shouldWarnAboutMissingCache(error) {
|
|
102
|
+
const isMissing = error.code === "ENOENT";
|
|
103
|
+
const isMalformed = error instanceof SyntaxError;
|
|
104
|
+
if (process.env.NODE_ENV !== "development") return false;
|
|
105
|
+
return !isMissing || isMalformed;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
2
108
|
|
|
3
|
-
var chunk2JRYABGG_cjs = require('../chunk-2JRYABGG.cjs');
|
|
4
109
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "LocalCache", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () { return chunk2JRYABGG_cjs.LocalCache; }
|
|
10
|
-
});
|
|
110
|
+
exports.LocalCache = LocalCache;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { I as ILocalCache } from '../cache-types-B39iNHfE.cjs';
|
|
2
|
+
|
|
3
|
+
declare class LocalCache implements ILocalCache {
|
|
2
4
|
private data;
|
|
3
5
|
private hasLoaded;
|
|
4
6
|
private cachePath;
|
|
@@ -16,19 +18,19 @@ declare class LocalCache {
|
|
|
16
18
|
/**
|
|
17
19
|
* Retrieve a specific page from the local pages array.
|
|
18
20
|
*/
|
|
19
|
-
getPage(slug: string): any
|
|
21
|
+
getPage(slug: string): Promise<any>;
|
|
20
22
|
/**
|
|
21
23
|
* Retrieve an entire collection from the local collections map.
|
|
22
24
|
*/
|
|
23
|
-
getCollection(collectionId: string): any[] | null
|
|
25
|
+
getCollection(collectionId: string): Promise<any[] | null>;
|
|
24
26
|
/**
|
|
25
27
|
* Retrieve global settings from the local cache.
|
|
26
28
|
*/
|
|
27
|
-
getGlobals(): any
|
|
29
|
+
getGlobals(): Promise<any>;
|
|
28
30
|
/**
|
|
29
31
|
* Returns the entire raw JSON data structure from the cache file.
|
|
30
32
|
*/
|
|
31
|
-
getAllData(): any
|
|
33
|
+
getAllData(): Promise<any>;
|
|
32
34
|
/**
|
|
33
35
|
* Helper to determine if we should bother the user with a warning.
|
|
34
36
|
*/
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { I as ILocalCache } from '../cache-types-B39iNHfE.js';
|
|
2
|
+
|
|
3
|
+
declare class LocalCache implements ILocalCache {
|
|
2
4
|
private data;
|
|
3
5
|
private hasLoaded;
|
|
4
6
|
private cachePath;
|
|
@@ -16,19 +18,19 @@ declare class LocalCache {
|
|
|
16
18
|
/**
|
|
17
19
|
* Retrieve a specific page from the local pages array.
|
|
18
20
|
*/
|
|
19
|
-
getPage(slug: string): any
|
|
21
|
+
getPage(slug: string): Promise<any>;
|
|
20
22
|
/**
|
|
21
23
|
* Retrieve an entire collection from the local collections map.
|
|
22
24
|
*/
|
|
23
|
-
getCollection(collectionId: string): any[] | null
|
|
25
|
+
getCollection(collectionId: string): Promise<any[] | null>;
|
|
24
26
|
/**
|
|
25
27
|
* Retrieve global settings from the local cache.
|
|
26
28
|
*/
|
|
27
|
-
getGlobals(): any
|
|
29
|
+
getGlobals(): Promise<any>;
|
|
28
30
|
/**
|
|
29
31
|
* Returns the entire raw JSON data structure from the cache file.
|
|
30
32
|
*/
|
|
31
|
-
getAllData(): any
|
|
33
|
+
getAllData(): Promise<any>;
|
|
32
34
|
/**
|
|
33
35
|
* Helper to determine if we should bother the user with a warning.
|
|
34
36
|
*/
|
|
@@ -1 +1,110 @@
|
|
|
1
|
-
|
|
1
|
+
// src/content/local-cache-server.ts
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
var LocalCache = class {
|
|
5
|
+
constructor(customPath) {
|
|
6
|
+
this.data = null;
|
|
7
|
+
this.hasLoaded = false;
|
|
8
|
+
this.cachePath = customPath || ".nexus/cache.json";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the local cache file has been successfully
|
|
12
|
+
* loaded and parsed into memory.
|
|
13
|
+
*/
|
|
14
|
+
isLoaded() {
|
|
15
|
+
return this.hasLoaded;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reads the cache file from the filesystem.
|
|
19
|
+
* Internal method called lazily by the getters.
|
|
20
|
+
*/
|
|
21
|
+
load() {
|
|
22
|
+
if (typeof window !== "undefined") return;
|
|
23
|
+
if (this.hasLoaded) return;
|
|
24
|
+
try {
|
|
25
|
+
const fullPath = path.resolve(process.cwd(), this.cachePath);
|
|
26
|
+
if (fs.existsSync(fullPath)) {
|
|
27
|
+
const fileContent = fs.readFileSync(fullPath, "utf-8");
|
|
28
|
+
this.data = JSON.parse(fileContent);
|
|
29
|
+
this.hasLoaded = true;
|
|
30
|
+
if (process.env.NODE_ENV === "development") {
|
|
31
|
+
console.log(
|
|
32
|
+
`\u26A1 NexusHub: Serving content from local cache (${this.cachePath})`
|
|
33
|
+
);
|
|
34
|
+
console.log(` - Pages: ${this.data.pages?.length || 0}`);
|
|
35
|
+
console.log(
|
|
36
|
+
` - Collections: ${Object.keys(this.data.collections || {}).length}`
|
|
37
|
+
);
|
|
38
|
+
console.log(
|
|
39
|
+
` - Globals: ${this.data.globals ? "Loaded" : "Not found"}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (this.shouldWarnAboutMissingCache(error)) {
|
|
45
|
+
console.warn(
|
|
46
|
+
`\u26A0\uFE0F NexusHub: Local cache invalid at ${this.cachePath}
|
|
47
|
+
Run \`npx nexus pull\` to fix your seed data.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Retrieve a specific page from the local pages array.
|
|
54
|
+
*/
|
|
55
|
+
async getPage(slug) {
|
|
56
|
+
this.load();
|
|
57
|
+
if (!this.data?.pages) return null;
|
|
58
|
+
const page = this.data.pages.find((p) => p.slug === slug);
|
|
59
|
+
if (!page) {
|
|
60
|
+
if (process.env.NODE_ENV === "development") {
|
|
61
|
+
console.warn(`\u26A0\uFE0F NexusHub: Page '${slug}' not found in local cache.`);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return page.data;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Retrieve an entire collection from the local collections map.
|
|
69
|
+
*/
|
|
70
|
+
async getCollection(collectionId) {
|
|
71
|
+
this.load();
|
|
72
|
+
if (!this.data?.collections) return null;
|
|
73
|
+
const collection = this.data.collections[collectionId];
|
|
74
|
+
if (!collection) {
|
|
75
|
+
if (process.env.NODE_ENV === "development") {
|
|
76
|
+
console.warn(
|
|
77
|
+
`\u26A0\uFE0F NexusHub: Collection '${collectionId}' not found in local cache.`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return collection;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Retrieve global settings from the local cache.
|
|
86
|
+
*/
|
|
87
|
+
async getGlobals() {
|
|
88
|
+
this.load();
|
|
89
|
+
return this.data?.globals || null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns the entire raw JSON data structure from the cache file.
|
|
93
|
+
*/
|
|
94
|
+
async getAllData() {
|
|
95
|
+
this.load();
|
|
96
|
+
return this.data;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Helper to determine if we should bother the user with a warning.
|
|
100
|
+
*/
|
|
101
|
+
shouldWarnAboutMissingCache(error) {
|
|
102
|
+
const isMissing = error.code === "ENOENT";
|
|
103
|
+
const isMalformed = error instanceof SyntaxError;
|
|
104
|
+
if (process.env.NODE_ENV !== "development") return false;
|
|
105
|
+
return !isMissing || isMalformed;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
export {
|
|
109
|
+
LocalCache
|
|
110
|
+
};
|