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