@aigne/afs-explorer 1.1.0-beta → 1.11.0-beta

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/README.md CHANGED
@@ -53,7 +53,10 @@ import path from "node:path";
53
53
 
54
54
  // For production: specify the path to the built frontend
55
55
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
56
- const distPath = path.resolve(__dirname, "node_modules/@aigne/afs-explorer/dist");
56
+ const distPath = path.resolve(
57
+ __dirname,
58
+ "node_modules/@aigne/afs-explorer/dist",
59
+ );
57
60
 
58
61
  const server = new ExplorerServer(afs, {
59
62
  port: 8080,
@@ -116,6 +119,7 @@ The explorer provides the following REST API endpoints:
116
119
  ### Backend
117
120
 
118
121
  The backend is built with Express and provides:
122
+
119
123
  - RESTful API for AFS operations
120
124
  - Static file serving for the React frontend
121
125
  - CORS support for development
@@ -123,6 +127,7 @@ The backend is built with Express and provides:
123
127
  ### Frontend
124
128
 
125
129
  The frontend is a React application built with:
130
+
126
131
  - **React 19** - Modern React with hooks
127
132
  - **TypeScript** - Type-safe development
128
133
  - **Material-UI (MUI)** - Professional UI components
package/dist/index.cjs ADDED
@@ -0,0 +1,126 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ let node_path = require("node:path");
29
+ node_path = __toESM(node_path);
30
+ let cors = require("cors");
31
+ cors = __toESM(cors);
32
+ let express = require("express");
33
+ express = __toESM(express);
34
+
35
+ //#region src/server.ts
36
+ var ExplorerServer = class {
37
+ app;
38
+ server;
39
+ constructor(afs, options = {}) {
40
+ this.afs = afs;
41
+ this.options = options;
42
+ this.app = (0, express.default)();
43
+ this.setupMiddleware();
44
+ this.setupRoutes();
45
+ }
46
+ setupMiddleware() {
47
+ this.app.use((0, cors.default)());
48
+ this.app.use(express.default.json());
49
+ }
50
+ setupRoutes() {
51
+ this.app.get("/api/list", async (req, res) => {
52
+ const path = req.query.path || "/";
53
+ const maxDepth = req.query.maxDepth ? Number.parseInt(req.query.maxDepth, 10) : 1;
54
+ const result = await this.afs.list(path, { maxDepth });
55
+ res.json(result);
56
+ });
57
+ this.app.get("/api/read", async (req, res) => {
58
+ const path = req.query.path;
59
+ if (!path) {
60
+ res.status(400).json({ error: "Path is required" });
61
+ return;
62
+ }
63
+ const result = await this.afs.read(path);
64
+ res.json(result);
65
+ });
66
+ this.app.get("/api/search", async (req, res) => {
67
+ const path = req.query.path || "/";
68
+ const query = req.query.query;
69
+ if (!query) {
70
+ res.status(400).json({ error: "Query is required" });
71
+ return;
72
+ }
73
+ const result = await this.afs.search(path, query);
74
+ res.json(result);
75
+ });
76
+ if (this.options.distPath) {
77
+ const distPath = node_path.default.resolve(this.options.distPath);
78
+ this.app.use(express.default.static(distPath));
79
+ this.app.get("/{*splat}", (_req, res) => {
80
+ res.sendFile("index.html", { root: distPath });
81
+ });
82
+ }
83
+ this.app.use((err, _req, res, _next) => {
84
+ res.status(500).json({ error: err.message || String(err) });
85
+ });
86
+ }
87
+ async start() {
88
+ const port = this.options.port || 3e3;
89
+ const host = this.options.host || "localhost";
90
+ return new Promise((resolve) => {
91
+ this.server = this.app.listen(port, host, () => {
92
+ resolve();
93
+ });
94
+ });
95
+ }
96
+ async stop() {
97
+ return new Promise((resolve, reject) => {
98
+ if (this.server) this.server.close((err) => {
99
+ if (err && err.code !== "ERR_SERVER_NOT_RUNNING") reject(err);
100
+ else {
101
+ this.server = void 0;
102
+ resolve();
103
+ }
104
+ });
105
+ else resolve();
106
+ });
107
+ }
108
+ };
109
+
110
+ //#endregion
111
+ //#region src/index.ts
112
+ /**
113
+ * Start the AFS Explorer web server
114
+ * @param afs - The AFS instance to explore
115
+ * @param options - Server options
116
+ * @returns The ExplorerServer instance
117
+ */
118
+ async function startExplorer(afs, options = {}) {
119
+ const server = new ExplorerServer(afs, options);
120
+ await server.start();
121
+ return server;
122
+ }
123
+
124
+ //#endregion
125
+ exports.ExplorerServer = ExplorerServer;
126
+ exports.startExplorer = startExplorer;
@@ -0,0 +1,35 @@
1
+ import { AFS } from "@aigne/afs";
2
+
3
+ //#region src/server.d.ts
4
+ interface ExplorerServerOptions {
5
+ port?: number;
6
+ host?: string;
7
+ /**
8
+ * Path to the dist directory containing the built frontend.
9
+ * If not provided, static file serving will be disabled.
10
+ */
11
+ distPath?: string;
12
+ }
13
+ declare class ExplorerServer {
14
+ private afs;
15
+ private options;
16
+ private app;
17
+ private server?;
18
+ constructor(afs: AFS, options?: ExplorerServerOptions);
19
+ private setupMiddleware;
20
+ private setupRoutes;
21
+ start(): Promise<void>;
22
+ stop(): Promise<void>;
23
+ }
24
+ //#endregion
25
+ //#region src/index.d.ts
26
+ /**
27
+ * Start the AFS Explorer web server
28
+ * @param afs - The AFS instance to explore
29
+ * @param options - Server options
30
+ * @returns The ExplorerServer instance
31
+ */
32
+ declare function startExplorer(afs: AFS, options?: ExplorerServerOptions): Promise<ExplorerServer>;
33
+ //#endregion
34
+ export { ExplorerServer, type ExplorerServerOptions, startExplorer };
35
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/server.ts","../src/index.ts"],"mappings":";;;UAKiB,qBAAA;EAAA,IAAA;EAAA,IAAA;EAAA;AAUjB;;;EAViB,QAAA;AAAA;AAAA,cAUJ,cAAA;EAAA,QAAA,GAAA;EAAA,QAAA,OAAA;EAAA,QAAA,GAAA;EAAA,QAAA,MAAA;EAAA,YAAA,GAAA,EAKI,GAAA,EAAA,OAAA,GACI,qBAAA;EAAA,QAAA,eAAA;EAAA,QAAA,WAAA;EAAA,MAAA,GA2DJ,OAAA;EAAA,KAAA,GAWD,OAAA;AAAA;;;;AChFhB;;;;;iBAAsB,aAAA,CAAA,GAAA,EACf,GAAA,EAAA,OAAA,GACI,qBAAA,GACR,OAAA,CAAQ,cAAA"}
@@ -0,0 +1,35 @@
1
+ import { AFS } from "@aigne/afs";
2
+
3
+ //#region src/server.d.ts
4
+ interface ExplorerServerOptions {
5
+ port?: number;
6
+ host?: string;
7
+ /**
8
+ * Path to the dist directory containing the built frontend.
9
+ * If not provided, static file serving will be disabled.
10
+ */
11
+ distPath?: string;
12
+ }
13
+ declare class ExplorerServer {
14
+ private afs;
15
+ private options;
16
+ private app;
17
+ private server?;
18
+ constructor(afs: AFS, options?: ExplorerServerOptions);
19
+ private setupMiddleware;
20
+ private setupRoutes;
21
+ start(): Promise<void>;
22
+ stop(): Promise<void>;
23
+ }
24
+ //#endregion
25
+ //#region src/index.d.ts
26
+ /**
27
+ * Start the AFS Explorer web server
28
+ * @param afs - The AFS instance to explore
29
+ * @param options - Server options
30
+ * @returns The ExplorerServer instance
31
+ */
32
+ declare function startExplorer(afs: AFS, options?: ExplorerServerOptions): Promise<ExplorerServer>;
33
+ //#endregion
34
+ export { ExplorerServer, type ExplorerServerOptions, startExplorer };
35
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/server.ts","../src/index.ts"],"mappings":";;;UAKiB,qBAAA;EAAA,IAAA;EAAA,IAAA;EAAA;AAUjB;;;EAViB,QAAA;AAAA;AAAA,cAUJ,cAAA;EAAA,QAAA,GAAA;EAAA,QAAA,OAAA;EAAA,QAAA,GAAA;EAAA,QAAA,MAAA;EAAA,YAAA,GAAA,EAKI,GAAA,EAAA,OAAA,GACI,qBAAA;EAAA,QAAA,eAAA;EAAA,QAAA,WAAA;EAAA,MAAA,GA2DJ,OAAA;EAAA,KAAA,GAWD,OAAA;AAAA;;;;AChFhB;;;;;iBAAsB,aAAA,CAAA,GAAA,EACf,GAAA,EAAA,OAAA,GACI,qBAAA,GACR,OAAA,CAAQ,cAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,96 @@
1
+ import path from "node:path";
2
+ import cors from "cors";
3
+ import express from "express";
4
+
5
+ //#region src/server.ts
6
+ var ExplorerServer = class {
7
+ app;
8
+ server;
9
+ constructor(afs, options = {}) {
10
+ this.afs = afs;
11
+ this.options = options;
12
+ this.app = express();
13
+ this.setupMiddleware();
14
+ this.setupRoutes();
15
+ }
16
+ setupMiddleware() {
17
+ this.app.use(cors());
18
+ this.app.use(express.json());
19
+ }
20
+ setupRoutes() {
21
+ this.app.get("/api/list", async (req, res) => {
22
+ const path$1 = req.query.path || "/";
23
+ const maxDepth = req.query.maxDepth ? Number.parseInt(req.query.maxDepth, 10) : 1;
24
+ const result = await this.afs.list(path$1, { maxDepth });
25
+ res.json(result);
26
+ });
27
+ this.app.get("/api/read", async (req, res) => {
28
+ const path$1 = req.query.path;
29
+ if (!path$1) {
30
+ res.status(400).json({ error: "Path is required" });
31
+ return;
32
+ }
33
+ const result = await this.afs.read(path$1);
34
+ res.json(result);
35
+ });
36
+ this.app.get("/api/search", async (req, res) => {
37
+ const path$1 = req.query.path || "/";
38
+ const query = req.query.query;
39
+ if (!query) {
40
+ res.status(400).json({ error: "Query is required" });
41
+ return;
42
+ }
43
+ const result = await this.afs.search(path$1, query);
44
+ res.json(result);
45
+ });
46
+ if (this.options.distPath) {
47
+ const distPath = path.resolve(this.options.distPath);
48
+ this.app.use(express.static(distPath));
49
+ this.app.get("/{*splat}", (_req, res) => {
50
+ res.sendFile("index.html", { root: distPath });
51
+ });
52
+ }
53
+ this.app.use((err, _req, res, _next) => {
54
+ res.status(500).json({ error: err.message || String(err) });
55
+ });
56
+ }
57
+ async start() {
58
+ const port = this.options.port || 3e3;
59
+ const host = this.options.host || "localhost";
60
+ return new Promise((resolve) => {
61
+ this.server = this.app.listen(port, host, () => {
62
+ resolve();
63
+ });
64
+ });
65
+ }
66
+ async stop() {
67
+ return new Promise((resolve, reject) => {
68
+ if (this.server) this.server.close((err) => {
69
+ if (err && err.code !== "ERR_SERVER_NOT_RUNNING") reject(err);
70
+ else {
71
+ this.server = void 0;
72
+ resolve();
73
+ }
74
+ });
75
+ else resolve();
76
+ });
77
+ }
78
+ };
79
+
80
+ //#endregion
81
+ //#region src/index.ts
82
+ /**
83
+ * Start the AFS Explorer web server
84
+ * @param afs - The AFS instance to explore
85
+ * @param options - Server options
86
+ * @returns The ExplorerServer instance
87
+ */
88
+ async function startExplorer(afs, options = {}) {
89
+ const server = new ExplorerServer(afs, options);
90
+ await server.start();
91
+ return server;
92
+ }
93
+
94
+ //#endregion
95
+ export { ExplorerServer, startExplorer };
96
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["path"],"sources":["../src/server.ts","../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { AFS } from \"@aigne/afs\";\nimport cors from \"cors\";\nimport express from \"express\";\n\nexport interface ExplorerServerOptions {\n port?: number;\n host?: string;\n /**\n * Path to the dist directory containing the built frontend.\n * If not provided, static file serving will be disabled.\n */\n distPath?: string;\n}\n\nexport class ExplorerServer {\n private app: express.Application;\n private server?: ReturnType<typeof this.app.listen>;\n\n constructor(\n private afs: AFS,\n private options: ExplorerServerOptions = {},\n ) {\n this.app = express();\n this.setupMiddleware();\n this.setupRoutes();\n }\n\n private setupMiddleware() {\n this.app.use(cors());\n this.app.use(express.json());\n }\n\n private setupRoutes() {\n // API Routes\n this.app.get(\"/api/list\", async (req, res) => {\n const path = (req.query.path as string) || \"/\";\n const maxDepth = req.query.maxDepth ? Number.parseInt(req.query.maxDepth as string, 10) : 1;\n const result = await this.afs.list(path, { maxDepth });\n res.json(result);\n });\n\n this.app.get(\"/api/read\", async (req, res) => {\n const path = req.query.path as string;\n if (!path) {\n res.status(400).json({ error: \"Path is required\" });\n return;\n }\n const result = await this.afs.read(path);\n res.json(result);\n });\n\n this.app.get(\"/api/search\", async (req, res) => {\n const path = (req.query.path as string) || \"/\";\n const query = req.query.query as string;\n if (!query) {\n res.status(400).json({ error: \"Query is required\" });\n return;\n }\n const result = await this.afs.search(path, query);\n res.json(result);\n });\n\n // Serve static files from the dist directory (if provided)\n if (this.options.distPath) {\n const distPath = path.resolve(this.options.distPath);\n this.app.use(express.static(distPath));\n this.app.get(\"/{*splat}\", (_req, res) => {\n res.sendFile(\"index.html\", { root: distPath });\n });\n }\n\n // Global error handler\n this.app.use(\n (err: Error, _req: express.Request, res: express.Response, _next: express.NextFunction) => {\n res.status(500).json({ error: err.message || String(err) });\n },\n );\n }\n\n async start(): Promise<void> {\n const port = this.options.port || 3000;\n const host = this.options.host || \"localhost\";\n\n return new Promise((resolve) => {\n this.server = this.app.listen(port, host, () => {\n resolve();\n });\n });\n }\n\n async stop(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (this.server) {\n this.server.close((err) => {\n // Ignore ERR_SERVER_NOT_RUNNING error\n if (err && (err as NodeJS.ErrnoException).code !== \"ERR_SERVER_NOT_RUNNING\") {\n reject(err);\n } else {\n this.server = undefined;\n resolve();\n }\n });\n } else {\n resolve();\n }\n });\n }\n}\n","import type { AFS } from \"@aigne/afs\";\nimport { ExplorerServer, type ExplorerServerOptions } from \"./server.js\";\n\nexport { ExplorerServer, type ExplorerServerOptions };\n\n/**\n * Start the AFS Explorer web server\n * @param afs - The AFS instance to explore\n * @param options - Server options\n * @returns The ExplorerServer instance\n */\nexport async function startExplorer(\n afs: AFS,\n options: ExplorerServerOptions = {},\n): Promise<ExplorerServer> {\n const server = new ExplorerServer(afs, options);\n await server.start();\n return server;\n}\n"],"mappings":";;;;;AAeA,IAAa,iBAAb,MAA4B;CAC1B,AAAQ;CACR,AAAQ;CAER,YACE,AAAQ,KACR,AAAQ,UAAiC,EAAE,EAC3C;EAFQ;EACA;AAER,OAAK,MAAM,SAAS;AACpB,OAAK,iBAAiB;AACtB,OAAK,aAAa;;CAGpB,AAAQ,kBAAkB;AACxB,OAAK,IAAI,IAAI,MAAM,CAAC;AACpB,OAAK,IAAI,IAAI,QAAQ,MAAM,CAAC;;CAG9B,AAAQ,cAAc;AAEpB,OAAK,IAAI,IAAI,aAAa,OAAO,KAAK,QAAQ;GAC5C,MAAMA,SAAQ,IAAI,MAAM,QAAmB;GAC3C,MAAM,WAAW,IAAI,MAAM,WAAW,OAAO,SAAS,IAAI,MAAM,UAAoB,GAAG,GAAG;GAC1F,MAAM,SAAS,MAAM,KAAK,IAAI,KAAKA,QAAM,EAAE,UAAU,CAAC;AACtD,OAAI,KAAK,OAAO;IAChB;AAEF,OAAK,IAAI,IAAI,aAAa,OAAO,KAAK,QAAQ;GAC5C,MAAMA,SAAO,IAAI,MAAM;AACvB,OAAI,CAACA,QAAM;AACT,QAAI,OAAO,IAAI,CAAC,KAAK,EAAE,OAAO,oBAAoB,CAAC;AACnD;;GAEF,MAAM,SAAS,MAAM,KAAK,IAAI,KAAKA,OAAK;AACxC,OAAI,KAAK,OAAO;IAChB;AAEF,OAAK,IAAI,IAAI,eAAe,OAAO,KAAK,QAAQ;GAC9C,MAAMA,SAAQ,IAAI,MAAM,QAAmB;GAC3C,MAAM,QAAQ,IAAI,MAAM;AACxB,OAAI,CAAC,OAAO;AACV,QAAI,OAAO,IAAI,CAAC,KAAK,EAAE,OAAO,qBAAqB,CAAC;AACpD;;GAEF,MAAM,SAAS,MAAM,KAAK,IAAI,OAAOA,QAAM,MAAM;AACjD,OAAI,KAAK,OAAO;IAChB;AAGF,MAAI,KAAK,QAAQ,UAAU;GACzB,MAAM,WAAW,KAAK,QAAQ,KAAK,QAAQ,SAAS;AACpD,QAAK,IAAI,IAAI,QAAQ,OAAO,SAAS,CAAC;AACtC,QAAK,IAAI,IAAI,cAAc,MAAM,QAAQ;AACvC,QAAI,SAAS,cAAc,EAAE,MAAM,UAAU,CAAC;KAC9C;;AAIJ,OAAK,IAAI,KACN,KAAY,MAAuB,KAAuB,UAAgC;AACzF,OAAI,OAAO,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,WAAW,OAAO,IAAI,EAAE,CAAC;IAE9D;;CAGH,MAAM,QAAuB;EAC3B,MAAM,OAAO,KAAK,QAAQ,QAAQ;EAClC,MAAM,OAAO,KAAK,QAAQ,QAAQ;AAElC,SAAO,IAAI,SAAS,YAAY;AAC9B,QAAK,SAAS,KAAK,IAAI,OAAO,MAAM,YAAY;AAC9C,aAAS;KACT;IACF;;CAGJ,MAAM,OAAsB;AAC1B,SAAO,IAAI,SAAS,SAAS,WAAW;AACtC,OAAI,KAAK,OACP,MAAK,OAAO,OAAO,QAAQ;AAEzB,QAAI,OAAQ,IAA8B,SAAS,yBACjD,QAAO,IAAI;SACN;AACL,UAAK,SAAS;AACd,cAAS;;KAEX;OAEF,UAAS;IAEX;;;;;;;;;;;;AC/FN,eAAsB,cACpB,KACA,UAAiC,EAAE,EACV;CACzB,MAAM,SAAS,IAAI,eAAe,KAAK,QAAQ;AAC/C,OAAM,OAAO,OAAO;AACpB,QAAO"}