@nexushub/client 0.4.2 → 0.4.3
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/content/local-cache-client.cjs +27 -4
- package/dist/content/local-cache-client.js +0 -2
- package/dist/content/local-cache-server.cjs +59 -26
- package/dist/content/local-cache-server.js +0 -2
- package/dist/index.cjs +2509 -33
- package/dist/index.d.cts +321 -4
- package/dist/index.d.ts +321 -4
- package/dist/index.js +2457 -28
- package/dist/local-cache-client-I6UYVJJV.js +59 -0
- package/dist/local-cache-client-IGAL7SZ6.cjs +59 -0
- package/dist/local-cache-server-6DXQJFCQ.cjs +114 -0
- package/dist/local-cache-server-DBJWR7HD.js +114 -0
- package/dist/react.cjs +2610 -3
- package/dist/react.d.cts +349 -3
- package/dist/react.d.ts +349 -3
- package/dist/react.js +2615 -8
- package/package.json +1 -1
- package/dist/chunk-FMMFQP5O.cjs +0 -2643
- package/dist/chunk-G4SHBWAQ.js +0 -2643
- package/dist/react-C795ypnM.d.cts +0 -386
- package/dist/react-C795ypnM.d.ts +0 -386
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/content/local-cache-client.ts
|
|
2
|
+
var LocalCache = class {
|
|
3
|
+
constructor(customPath) {
|
|
4
|
+
// Maintain private properties for type parity with the Server version
|
|
5
|
+
this.data = null;
|
|
6
|
+
this.hasLoaded = false;
|
|
7
|
+
this.cachePath = customPath || ".nexus/cache.json";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Always returns false in the browser as local file caching
|
|
11
|
+
* is a server-side only feature.
|
|
12
|
+
*/
|
|
13
|
+
isLoaded() {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* No-op method to maintain internal API compatibility.
|
|
18
|
+
*/
|
|
19
|
+
load() {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns null. Browsers should fetch pages from the Remote API
|
|
24
|
+
* or the Memory/Browser cache.
|
|
25
|
+
*/
|
|
26
|
+
async getPage(_slug) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns null. Browsers should fetch collections from the Remote API.
|
|
31
|
+
*/
|
|
32
|
+
async getCollection(_collectionId) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns null.
|
|
37
|
+
*/
|
|
38
|
+
async getGlobals() {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns null.
|
|
43
|
+
*/
|
|
44
|
+
async getAllData() {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Dummy helper to match Node implementation.
|
|
49
|
+
*/
|
|
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;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
LocalCache
|
|
59
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/content/local-cache-client.ts
|
|
2
|
+
var LocalCache = class {
|
|
3
|
+
constructor(customPath) {
|
|
4
|
+
// Maintain private properties for type parity with the Server version
|
|
5
|
+
this.data = null;
|
|
6
|
+
this.hasLoaded = false;
|
|
7
|
+
this.cachePath = customPath || ".nexus/cache.json";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Always returns false in the browser as local file caching
|
|
11
|
+
* is a server-side only feature.
|
|
12
|
+
*/
|
|
13
|
+
isLoaded() {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* No-op method to maintain internal API compatibility.
|
|
18
|
+
*/
|
|
19
|
+
load() {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns null. Browsers should fetch pages from the Remote API
|
|
24
|
+
* or the Memory/Browser cache.
|
|
25
|
+
*/
|
|
26
|
+
async getPage(_slug) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns null. Browsers should fetch collections from the Remote API.
|
|
31
|
+
*/
|
|
32
|
+
async getCollection(_collectionId) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns null.
|
|
37
|
+
*/
|
|
38
|
+
async getGlobals() {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns null.
|
|
43
|
+
*/
|
|
44
|
+
async getAllData() {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Dummy helper to match Node implementation.
|
|
49
|
+
*/
|
|
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;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
exports.LocalCache = LocalCache;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// 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.baseDir = customPath || ".nexus/local";
|
|
7
|
+
}
|
|
8
|
+
isLoaded() {
|
|
9
|
+
return _fs2.default.existsSync(_path2.default.resolve(process.cwd(), this.baseDir));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve a specific page directly from its file.
|
|
13
|
+
*/
|
|
14
|
+
async getPage(slug) {
|
|
15
|
+
try {
|
|
16
|
+
const filePath = _path2.default.resolve(
|
|
17
|
+
process.cwd(),
|
|
18
|
+
this.baseDir,
|
|
19
|
+
"pages",
|
|
20
|
+
`${slug}.json`
|
|
21
|
+
);
|
|
22
|
+
if (_fs2.default.existsSync(filePath)) {
|
|
23
|
+
const fileContent = _fs2.default.readFileSync(filePath, "utf-8");
|
|
24
|
+
const pageData = JSON.parse(fileContent);
|
|
25
|
+
return pageData.data !== void 0 ? pageData.data : pageData;
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (process.env.NODE_ENV === "development") {
|
|
29
|
+
console.warn(
|
|
30
|
+
`\u26A0\uFE0F NexusHub: Failed to load local page '${slug}':`,
|
|
31
|
+
error
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve an entire collection from its specific collection file.
|
|
39
|
+
*/
|
|
40
|
+
async getCollection(collectionId) {
|
|
41
|
+
try {
|
|
42
|
+
const filePath = _path2.default.resolve(
|
|
43
|
+
process.cwd(),
|
|
44
|
+
this.baseDir,
|
|
45
|
+
"collections",
|
|
46
|
+
`${collectionId}.json`
|
|
47
|
+
);
|
|
48
|
+
if (_fs2.default.existsSync(filePath)) {
|
|
49
|
+
const fileContent = _fs2.default.readFileSync(filePath, "utf-8");
|
|
50
|
+
return JSON.parse(fileContent);
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (process.env.NODE_ENV === "development") {
|
|
54
|
+
console.warn(
|
|
55
|
+
`\u26A0\uFE0F NexusHub: Failed to load local collection '${collectionId}':`,
|
|
56
|
+
error
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Retrieve global settings from its file.
|
|
64
|
+
*/
|
|
65
|
+
async getGlobals() {
|
|
66
|
+
try {
|
|
67
|
+
const filePath = _path2.default.resolve(
|
|
68
|
+
process.cwd(),
|
|
69
|
+
this.baseDir,
|
|
70
|
+
"globals.json"
|
|
71
|
+
);
|
|
72
|
+
if (_fs2.default.existsSync(filePath)) {
|
|
73
|
+
const fileContent = _fs2.default.readFileSync(filePath, "utf-8");
|
|
74
|
+
return JSON.parse(fileContent);
|
|
75
|
+
}
|
|
76
|
+
} catch (e) {
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns a merged JSON of the entire workspace structure (for dev analytics/inspectors)
|
|
82
|
+
*/
|
|
83
|
+
async getAllData() {
|
|
84
|
+
const pages = {};
|
|
85
|
+
const collections = {};
|
|
86
|
+
let globals = {};
|
|
87
|
+
try {
|
|
88
|
+
const pagesDir = _path2.default.resolve(process.cwd(), this.baseDir, "pages");
|
|
89
|
+
if (_fs2.default.existsSync(pagesDir)) {
|
|
90
|
+
for (const file of _fs2.default.readdirSync(pagesDir)) {
|
|
91
|
+
if (file.endsWith(".json")) {
|
|
92
|
+
const slug = _path2.default.basename(file, ".json");
|
|
93
|
+
pages[slug] = await this.getPage(slug);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const colsDir = _path2.default.resolve(process.cwd(), this.baseDir, "collections");
|
|
98
|
+
if (_fs2.default.existsSync(colsDir)) {
|
|
99
|
+
for (const file of _fs2.default.readdirSync(colsDir)) {
|
|
100
|
+
if (file.endsWith(".json")) {
|
|
101
|
+
const id = _path2.default.basename(file, ".json");
|
|
102
|
+
collections[id] = await this.getCollection(id) || [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
globals = await this.getGlobals() || {};
|
|
107
|
+
} catch (e2) {
|
|
108
|
+
}
|
|
109
|
+
return { pages, collections, globals };
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
exports.LocalCache = LocalCache;
|
|
@@ -0,0 +1,114 @@
|
|
|
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.baseDir = customPath || ".nexus/local";
|
|
7
|
+
}
|
|
8
|
+
isLoaded() {
|
|
9
|
+
return fs.existsSync(path.resolve(process.cwd(), this.baseDir));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve a specific page directly from its file.
|
|
13
|
+
*/
|
|
14
|
+
async getPage(slug) {
|
|
15
|
+
try {
|
|
16
|
+
const filePath = path.resolve(
|
|
17
|
+
process.cwd(),
|
|
18
|
+
this.baseDir,
|
|
19
|
+
"pages",
|
|
20
|
+
`${slug}.json`
|
|
21
|
+
);
|
|
22
|
+
if (fs.existsSync(filePath)) {
|
|
23
|
+
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
24
|
+
const pageData = JSON.parse(fileContent);
|
|
25
|
+
return pageData.data !== void 0 ? pageData.data : pageData;
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (process.env.NODE_ENV === "development") {
|
|
29
|
+
console.warn(
|
|
30
|
+
`\u26A0\uFE0F NexusHub: Failed to load local page '${slug}':`,
|
|
31
|
+
error
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve an entire collection from its specific collection file.
|
|
39
|
+
*/
|
|
40
|
+
async getCollection(collectionId) {
|
|
41
|
+
try {
|
|
42
|
+
const filePath = path.resolve(
|
|
43
|
+
process.cwd(),
|
|
44
|
+
this.baseDir,
|
|
45
|
+
"collections",
|
|
46
|
+
`${collectionId}.json`
|
|
47
|
+
);
|
|
48
|
+
if (fs.existsSync(filePath)) {
|
|
49
|
+
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
50
|
+
return JSON.parse(fileContent);
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (process.env.NODE_ENV === "development") {
|
|
54
|
+
console.warn(
|
|
55
|
+
`\u26A0\uFE0F NexusHub: Failed to load local collection '${collectionId}':`,
|
|
56
|
+
error
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Retrieve global settings from its file.
|
|
64
|
+
*/
|
|
65
|
+
async getGlobals() {
|
|
66
|
+
try {
|
|
67
|
+
const filePath = path.resolve(
|
|
68
|
+
process.cwd(),
|
|
69
|
+
this.baseDir,
|
|
70
|
+
"globals.json"
|
|
71
|
+
);
|
|
72
|
+
if (fs.existsSync(filePath)) {
|
|
73
|
+
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
74
|
+
return JSON.parse(fileContent);
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns a merged JSON of the entire workspace structure (for dev analytics/inspectors)
|
|
82
|
+
*/
|
|
83
|
+
async getAllData() {
|
|
84
|
+
const pages = {};
|
|
85
|
+
const collections = {};
|
|
86
|
+
let globals = {};
|
|
87
|
+
try {
|
|
88
|
+
const pagesDir = path.resolve(process.cwd(), this.baseDir, "pages");
|
|
89
|
+
if (fs.existsSync(pagesDir)) {
|
|
90
|
+
for (const file of fs.readdirSync(pagesDir)) {
|
|
91
|
+
if (file.endsWith(".json")) {
|
|
92
|
+
const slug = path.basename(file, ".json");
|
|
93
|
+
pages[slug] = await this.getPage(slug);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const colsDir = path.resolve(process.cwd(), this.baseDir, "collections");
|
|
98
|
+
if (fs.existsSync(colsDir)) {
|
|
99
|
+
for (const file of fs.readdirSync(colsDir)) {
|
|
100
|
+
if (file.endsWith(".json")) {
|
|
101
|
+
const id = path.basename(file, ".json");
|
|
102
|
+
collections[id] = await this.getCollection(id) || [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
globals = await this.getGlobals() || {};
|
|
107
|
+
} catch {
|
|
108
|
+
}
|
|
109
|
+
return { pages, collections, globals };
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
export {
|
|
113
|
+
LocalCache
|
|
114
|
+
};
|