@nexushub/client 0.4.0 → 0.4.2

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,4 +1,6 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/content/local-cache-client.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
2
+
3
+ // src/content/local-cache-client.ts
2
4
  var LocalCache = class {
3
5
  constructor(customPath) {
4
6
  // Maintain private properties for type parity with the Server version
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  // src/content/local-cache-client.ts
2
4
  var LocalCache = class {
3
5
  constructor(customPath) {
@@ -1,108 +1,114 @@
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
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }"use client";
2
+
3
+ // src/content/local-cache-server.ts
2
4
  var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
3
5
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
4
6
  var LocalCache = class {
5
7
  constructor(customPath) {
6
- this.data = null;
7
- this.hasLoaded = false;
8
- this.cachePath = customPath || ".nexus/cache.json";
8
+ this.baseDir = customPath || ".nexus/local";
9
9
  }
10
- /**
11
- * Returns true if the local cache file has been successfully
12
- * loaded and parsed into memory.
13
- */
14
10
  isLoaded() {
15
- return this.hasLoaded;
11
+ return _fs2.default.existsSync(_path2.default.resolve(process.cwd(), this.baseDir));
16
12
  }
17
13
  /**
18
- * Reads the cache file from the filesystem.
19
- * Internal method called lazily by the getters.
14
+ * Retrieve a specific page directly from its file.
20
15
  */
21
- load() {
22
- if (typeof window !== "undefined") return;
23
- if (this.hasLoaded) return;
16
+ async getPage(slug) {
24
17
  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
- }
18
+ const filePath = _path2.default.resolve(
19
+ process.cwd(),
20
+ this.baseDir,
21
+ "pages",
22
+ `${slug}.json`
23
+ );
24
+ if (_fs2.default.existsSync(filePath)) {
25
+ const fileContent = _fs2.default.readFileSync(filePath, "utf-8");
26
+ const pageData = JSON.parse(fileContent);
27
+ return pageData.data !== void 0 ? pageData.data : pageData;
42
28
  }
43
29
  } catch (error) {
44
- if (this.shouldWarnAboutMissingCache(error)) {
30
+ if (process.env.NODE_ENV === "development") {
45
31
  console.warn(
46
- `\u26A0\uFE0F NexusHub: Local cache invalid at ${this.cachePath}
47
- Run \`npx nexus pull\` to fix your seed data.`
32
+ `\u26A0\uFE0F NexusHub: Failed to load local page '${slug}':`,
33
+ error
48
34
  );
49
35
  }
50
36
  }
37
+ return null;
51
38
  }
52
39
  /**
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.
40
+ * Retrieve an entire collection from its specific collection file.
69
41
  */
70
42
  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) {
43
+ try {
44
+ const filePath = _path2.default.resolve(
45
+ process.cwd(),
46
+ this.baseDir,
47
+ "collections",
48
+ `${collectionId}.json`
49
+ );
50
+ if (_fs2.default.existsSync(filePath)) {
51
+ const fileContent = _fs2.default.readFileSync(filePath, "utf-8");
52
+ return JSON.parse(fileContent);
53
+ }
54
+ } catch (error) {
75
55
  if (process.env.NODE_ENV === "development") {
76
56
  console.warn(
77
- `\u26A0\uFE0F NexusHub: Collection '${collectionId}' not found in local cache.`
57
+ `\u26A0\uFE0F NexusHub: Failed to load local collection '${collectionId}':`,
58
+ error
78
59
  );
79
60
  }
80
- return null;
81
61
  }
82
- return collection;
62
+ return null;
83
63
  }
84
64
  /**
85
- * Retrieve global settings from the local cache.
65
+ * Retrieve global settings from its file.
86
66
  */
87
67
  async getGlobals() {
88
- this.load();
89
- return _optionalChain([this, 'access', _8 => _8.data, 'optionalAccess', _9 => _9.globals]) || null;
68
+ try {
69
+ const filePath = _path2.default.resolve(
70
+ process.cwd(),
71
+ this.baseDir,
72
+ "globals.json"
73
+ );
74
+ if (_fs2.default.existsSync(filePath)) {
75
+ const fileContent = _fs2.default.readFileSync(filePath, "utf-8");
76
+ return JSON.parse(fileContent);
77
+ }
78
+ } catch (e) {
79
+ }
80
+ return null;
90
81
  }
91
82
  /**
92
- * Returns the entire raw JSON data structure from the cache file.
83
+ * Returns a merged JSON of the entire workspace structure (for dev analytics/inspectors)
93
84
  */
94
85
  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;
86
+ const pages = {};
87
+ const collections = {};
88
+ let globals = {};
89
+ try {
90
+ const pagesDir = _path2.default.resolve(process.cwd(), this.baseDir, "pages");
91
+ if (_fs2.default.existsSync(pagesDir)) {
92
+ for (const file of _fs2.default.readdirSync(pagesDir)) {
93
+ if (file.endsWith(".json")) {
94
+ const slug = _path2.default.basename(file, ".json");
95
+ pages[slug] = await this.getPage(slug);
96
+ }
97
+ }
98
+ }
99
+ const colsDir = _path2.default.resolve(process.cwd(), this.baseDir, "collections");
100
+ if (_fs2.default.existsSync(colsDir)) {
101
+ for (const file of _fs2.default.readdirSync(colsDir)) {
102
+ if (file.endsWith(".json")) {
103
+ const id = _path2.default.basename(file, ".json");
104
+ collections[id] = await this.getCollection(id) || [];
105
+ }
106
+ }
107
+ }
108
+ globals = await this.getGlobals() || {};
109
+ } catch (e2) {
110
+ }
111
+ return { pages, collections, globals };
106
112
  }
107
113
  };
108
114
 
@@ -1,40 +1,25 @@
1
1
  import { I as ILocalCache } from '../cache-types-B39iNHfE.cjs';
2
2
 
3
3
  declare class LocalCache implements ILocalCache {
4
- private data;
5
- private hasLoaded;
6
- private cachePath;
4
+ private baseDir;
7
5
  constructor(customPath?: string);
8
- /**
9
- * Returns true if the local cache file has been successfully
10
- * loaded and parsed into memory.
11
- */
12
6
  isLoaded(): boolean;
13
7
  /**
14
- * Reads the cache file from the filesystem.
15
- * Internal method called lazily by the getters.
16
- */
17
- private load;
18
- /**
19
- * Retrieve a specific page from the local pages array.
8
+ * Retrieve a specific page directly from its file.
20
9
  */
21
10
  getPage(slug: string): Promise<any>;
22
11
  /**
23
- * Retrieve an entire collection from the local collections map.
12
+ * Retrieve an entire collection from its specific collection file.
24
13
  */
25
14
  getCollection(collectionId: string): Promise<any[] | null>;
26
15
  /**
27
- * Retrieve global settings from the local cache.
16
+ * Retrieve global settings from its file.
28
17
  */
29
18
  getGlobals(): Promise<any>;
30
19
  /**
31
- * Returns the entire raw JSON data structure from the cache file.
20
+ * Returns a merged JSON of the entire workspace structure (for dev analytics/inspectors)
32
21
  */
33
22
  getAllData(): Promise<any>;
34
- /**
35
- * Helper to determine if we should bother the user with a warning.
36
- */
37
- private shouldWarnAboutMissingCache;
38
23
  }
39
24
 
40
25
  export { LocalCache };
@@ -1,40 +1,25 @@
1
1
  import { I as ILocalCache } from '../cache-types-B39iNHfE.js';
2
2
 
3
3
  declare class LocalCache implements ILocalCache {
4
- private data;
5
- private hasLoaded;
6
- private cachePath;
4
+ private baseDir;
7
5
  constructor(customPath?: string);
8
- /**
9
- * Returns true if the local cache file has been successfully
10
- * loaded and parsed into memory.
11
- */
12
6
  isLoaded(): boolean;
13
7
  /**
14
- * Reads the cache file from the filesystem.
15
- * Internal method called lazily by the getters.
16
- */
17
- private load;
18
- /**
19
- * Retrieve a specific page from the local pages array.
8
+ * Retrieve a specific page directly from its file.
20
9
  */
21
10
  getPage(slug: string): Promise<any>;
22
11
  /**
23
- * Retrieve an entire collection from the local collections map.
12
+ * Retrieve an entire collection from its specific collection file.
24
13
  */
25
14
  getCollection(collectionId: string): Promise<any[] | null>;
26
15
  /**
27
- * Retrieve global settings from the local cache.
16
+ * Retrieve global settings from its file.
28
17
  */
29
18
  getGlobals(): Promise<any>;
30
19
  /**
31
- * Returns the entire raw JSON data structure from the cache file.
20
+ * Returns a merged JSON of the entire workspace structure (for dev analytics/inspectors)
32
21
  */
33
22
  getAllData(): Promise<any>;
34
- /**
35
- * Helper to determine if we should bother the user with a warning.
36
- */
37
- private shouldWarnAboutMissingCache;
38
23
  }
39
24
 
40
25
  export { LocalCache };
@@ -1,108 +1,114 @@
1
+ "use client";
2
+
1
3
  // src/content/local-cache-server.ts
2
4
  import fs from "fs";
3
5
  import path from "path";
4
6
  var LocalCache = class {
5
7
  constructor(customPath) {
6
- this.data = null;
7
- this.hasLoaded = false;
8
- this.cachePath = customPath || ".nexus/cache.json";
8
+ this.baseDir = customPath || ".nexus/local";
9
9
  }
10
- /**
11
- * Returns true if the local cache file has been successfully
12
- * loaded and parsed into memory.
13
- */
14
10
  isLoaded() {
15
- return this.hasLoaded;
11
+ return fs.existsSync(path.resolve(process.cwd(), this.baseDir));
16
12
  }
17
13
  /**
18
- * Reads the cache file from the filesystem.
19
- * Internal method called lazily by the getters.
14
+ * Retrieve a specific page directly from its file.
20
15
  */
21
- load() {
22
- if (typeof window !== "undefined") return;
23
- if (this.hasLoaded) return;
16
+ async getPage(slug) {
24
17
  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
- }
18
+ const filePath = path.resolve(
19
+ process.cwd(),
20
+ this.baseDir,
21
+ "pages",
22
+ `${slug}.json`
23
+ );
24
+ if (fs.existsSync(filePath)) {
25
+ const fileContent = fs.readFileSync(filePath, "utf-8");
26
+ const pageData = JSON.parse(fileContent);
27
+ return pageData.data !== void 0 ? pageData.data : pageData;
42
28
  }
43
29
  } catch (error) {
44
- if (this.shouldWarnAboutMissingCache(error)) {
30
+ if (process.env.NODE_ENV === "development") {
45
31
  console.warn(
46
- `\u26A0\uFE0F NexusHub: Local cache invalid at ${this.cachePath}
47
- Run \`npx nexus pull\` to fix your seed data.`
32
+ `\u26A0\uFE0F NexusHub: Failed to load local page '${slug}':`,
33
+ error
48
34
  );
49
35
  }
50
36
  }
37
+ return null;
51
38
  }
52
39
  /**
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.
40
+ * Retrieve an entire collection from its specific collection file.
69
41
  */
70
42
  async getCollection(collectionId) {
71
- this.load();
72
- if (!this.data?.collections) return null;
73
- const collection = this.data.collections[collectionId];
74
- if (!collection) {
43
+ try {
44
+ const filePath = path.resolve(
45
+ process.cwd(),
46
+ this.baseDir,
47
+ "collections",
48
+ `${collectionId}.json`
49
+ );
50
+ if (fs.existsSync(filePath)) {
51
+ const fileContent = fs.readFileSync(filePath, "utf-8");
52
+ return JSON.parse(fileContent);
53
+ }
54
+ } catch (error) {
75
55
  if (process.env.NODE_ENV === "development") {
76
56
  console.warn(
77
- `\u26A0\uFE0F NexusHub: Collection '${collectionId}' not found in local cache.`
57
+ `\u26A0\uFE0F NexusHub: Failed to load local collection '${collectionId}':`,
58
+ error
78
59
  );
79
60
  }
80
- return null;
81
61
  }
82
- return collection;
62
+ return null;
83
63
  }
84
64
  /**
85
- * Retrieve global settings from the local cache.
65
+ * Retrieve global settings from its file.
86
66
  */
87
67
  async getGlobals() {
88
- this.load();
89
- return this.data?.globals || null;
68
+ try {
69
+ const filePath = path.resolve(
70
+ process.cwd(),
71
+ this.baseDir,
72
+ "globals.json"
73
+ );
74
+ if (fs.existsSync(filePath)) {
75
+ const fileContent = fs.readFileSync(filePath, "utf-8");
76
+ return JSON.parse(fileContent);
77
+ }
78
+ } catch {
79
+ }
80
+ return null;
90
81
  }
91
82
  /**
92
- * Returns the entire raw JSON data structure from the cache file.
83
+ * Returns a merged JSON of the entire workspace structure (for dev analytics/inspectors)
93
84
  */
94
85
  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;
86
+ const pages = {};
87
+ const collections = {};
88
+ let globals = {};
89
+ try {
90
+ const pagesDir = path.resolve(process.cwd(), this.baseDir, "pages");
91
+ if (fs.existsSync(pagesDir)) {
92
+ for (const file of fs.readdirSync(pagesDir)) {
93
+ if (file.endsWith(".json")) {
94
+ const slug = path.basename(file, ".json");
95
+ pages[slug] = await this.getPage(slug);
96
+ }
97
+ }
98
+ }
99
+ const colsDir = path.resolve(process.cwd(), this.baseDir, "collections");
100
+ if (fs.existsSync(colsDir)) {
101
+ for (const file of fs.readdirSync(colsDir)) {
102
+ if (file.endsWith(".json")) {
103
+ const id = path.basename(file, ".json");
104
+ collections[id] = await this.getCollection(id) || [];
105
+ }
106
+ }
107
+ }
108
+ globals = await this.getGlobals() || {};
109
+ } catch {
110
+ }
111
+ return { pages, collections, globals };
106
112
  }
107
113
  };
108
114
  export {