@x12i/static-memorix-explorer-api 1.3.2 → 1.4.0
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 +31 -0
- package/dist/cli.d.ts +14 -0
- package/dist/cli.js +154 -0
- package/dist/engine/lists.d.ts +1 -1
- package/guides/running-the-service.md +33 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -21,6 +21,26 @@ Then open **http://localhost:5030/demo**. The command prints the Demo, API,
|
|
|
21
21
|
Health, and JSON paths when it starts. No database or additional configuration
|
|
22
22
|
is required.
|
|
23
23
|
|
|
24
|
+
To create an editable demo in your own directory instead of using the bundled
|
|
25
|
+
read-only seeds:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
memorix-explorer create-demo
|
|
29
|
+
memorix-explorer --mocks-dir ./memorix-demo
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The first command creates `./memorix-demo` with `demo.html`, seed data,
|
|
33
|
+
metadata, write descriptors, and its own README. It refuses to overwrite an
|
|
34
|
+
existing path. The second command serves that folder, and all UI create/edit/
|
|
35
|
+
delete operations persist their routed JSON files inside it.
|
|
36
|
+
|
|
37
|
+
Choose a different destination or port if needed:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
memorix-explorer create-demo --dir ./my-project-fixtures
|
|
41
|
+
memorix-explorer --mocks-dir ./my-project-fixtures --port 8080
|
|
42
|
+
```
|
|
43
|
+
|
|
24
44
|
Useful options:
|
|
25
45
|
|
|
26
46
|
```bash
|
|
@@ -299,6 +319,17 @@ and `knowledgeId`.
|
|
|
299
319
|
|
|
300
320
|
## Release history
|
|
301
321
|
|
|
322
|
+
### v1.4.0
|
|
323
|
+
- Added `memorix-explorer create-demo` to create a user-owned, writable demo.
|
|
324
|
+
- Added `--dir` for the generated demo destination and `--mocks-dir` for
|
|
325
|
+
serving any fixture directory directly from the CLI.
|
|
326
|
+
- Generated demos include UI, metadata, seed data, write descriptors, and a
|
|
327
|
+
local usage README.
|
|
328
|
+
- Demo creation is atomic, refuses overwrites, and excludes routed state that
|
|
329
|
+
may have been generated inside a previously used global installation.
|
|
330
|
+
- Installed CLI aliases now use a configuration-first launcher so fixture paths
|
|
331
|
+
are resolved before the server loads.
|
|
332
|
+
|
|
302
333
|
### v1.3.2
|
|
303
334
|
- Added the short `memorix-explorer` CLI command.
|
|
304
335
|
- Added `--help`/`-h` and `--version`/`-v` commands.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export interface CliServerOptions {
|
|
3
|
+
port?: number;
|
|
4
|
+
host?: string;
|
|
5
|
+
mocksDir?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const CLI_HELP = "Memorix Explorer static server\n\nUsage:\n memorix-explorer create-demo [--dir <path>]\n memorix-explorer [options]\n\nCommands:\n create-demo Create a writable demo folder (default: ./memorix-demo)\n\nServer options:\n --port <number> Port to listen on (default: 5030)\n --host <address> Host to bind (default: 0.0.0.0)\n --mocks-dir <path> JSON fixture directory\n -h, --help Show this help\n -v, --version Show the installed version\n\nQuick start:\n memorix-explorer create-demo\n memorix-explorer --mocks-dir ./memorix-demo\n";
|
|
8
|
+
export declare function getPackageVersion(): string;
|
|
9
|
+
export declare function parseServerArgs(args: string[]): CliServerOptions;
|
|
10
|
+
export declare function parseCreateDemoArgs(args: string[]): {
|
|
11
|
+
targetDir: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function createDemo(targetDir: string): string;
|
|
14
|
+
export declare function runCli(args: string[]): Promise<void>;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
export const CLI_HELP = `Memorix Explorer static server
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
memorix-explorer create-demo [--dir <path>]
|
|
10
|
+
memorix-explorer [options]
|
|
11
|
+
|
|
12
|
+
Commands:
|
|
13
|
+
create-demo Create a writable demo folder (default: ./memorix-demo)
|
|
14
|
+
|
|
15
|
+
Server options:
|
|
16
|
+
--port <number> Port to listen on (default: 5030)
|
|
17
|
+
--host <address> Host to bind (default: 0.0.0.0)
|
|
18
|
+
--mocks-dir <path> JSON fixture directory
|
|
19
|
+
-h, --help Show this help
|
|
20
|
+
-v, --version Show the installed version
|
|
21
|
+
|
|
22
|
+
Quick start:
|
|
23
|
+
memorix-explorer create-demo
|
|
24
|
+
memorix-explorer --mocks-dir ./memorix-demo
|
|
25
|
+
`;
|
|
26
|
+
function packageRoot() {
|
|
27
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
28
|
+
}
|
|
29
|
+
export function getPackageVersion() {
|
|
30
|
+
return JSON.parse(fs.readFileSync(path.join(packageRoot(), "package.json"), "utf8")).version;
|
|
31
|
+
}
|
|
32
|
+
export function parseServerArgs(args) {
|
|
33
|
+
const options = {};
|
|
34
|
+
for (let index = 0; index < args.length; index++) {
|
|
35
|
+
const arg = args[index];
|
|
36
|
+
if (arg === "--port") {
|
|
37
|
+
const raw = args[++index];
|
|
38
|
+
const port = Number(raw);
|
|
39
|
+
if (!raw || !Number.isInteger(port) || port < 0 || port > 65535) {
|
|
40
|
+
throw new Error("--port must be an integer from 0 to 65535");
|
|
41
|
+
}
|
|
42
|
+
options.port = port;
|
|
43
|
+
}
|
|
44
|
+
else if (arg === "--host") {
|
|
45
|
+
const host = args[++index];
|
|
46
|
+
if (!host)
|
|
47
|
+
throw new Error("--host requires a value");
|
|
48
|
+
options.host = host;
|
|
49
|
+
}
|
|
50
|
+
else if (arg === "--mocks-dir") {
|
|
51
|
+
const mocksDir = args[++index];
|
|
52
|
+
if (!mocksDir)
|
|
53
|
+
throw new Error("--mocks-dir requires a path");
|
|
54
|
+
options.mocksDir = path.resolve(mocksDir);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw new Error(`Unknown CLI argument: ${arg}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return options;
|
|
61
|
+
}
|
|
62
|
+
export function parseCreateDemoArgs(args) {
|
|
63
|
+
let targetDir = path.resolve("memorix-demo");
|
|
64
|
+
for (let index = 0; index < args.length; index++) {
|
|
65
|
+
const arg = args[index];
|
|
66
|
+
if (arg === "--dir") {
|
|
67
|
+
const value = args[++index];
|
|
68
|
+
if (!value)
|
|
69
|
+
throw new Error("--dir requires a path");
|
|
70
|
+
targetDir = path.resolve(value);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new Error(`Unknown create-demo argument: ${arg}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { targetDir };
|
|
77
|
+
}
|
|
78
|
+
export function createDemo(targetDir) {
|
|
79
|
+
const resolved = path.resolve(targetDir);
|
|
80
|
+
if (fs.existsSync(resolved)) {
|
|
81
|
+
throw new Error(`Refusing to overwrite existing path: ${resolved}`);
|
|
82
|
+
}
|
|
83
|
+
const bundledMocks = path.join(packageRoot(), "mocks");
|
|
84
|
+
if (!fs.existsSync(bundledMocks)) {
|
|
85
|
+
throw new Error(`Bundled demo fixtures not found: ${bundledMocks}`);
|
|
86
|
+
}
|
|
87
|
+
const temporary = `${resolved}.creating-${randomUUID()}`;
|
|
88
|
+
try {
|
|
89
|
+
fs.cpSync(bundledMocks, temporary, {
|
|
90
|
+
recursive: true,
|
|
91
|
+
errorOnExist: true,
|
|
92
|
+
force: false,
|
|
93
|
+
// A globally installed package may already have routed runtime files.
|
|
94
|
+
// Copy only pristine bundled seeds, never another user's generated state.
|
|
95
|
+
filter: (source) => !path.basename(source).includes("--"),
|
|
96
|
+
});
|
|
97
|
+
fs.writeFileSync(path.join(temporary, "README.md"), `# Memorix Explorer demo\n\n` +
|
|
98
|
+
`Start this demo from this directory:\n\n` +
|
|
99
|
+
"```bash\nmemorix-explorer --mocks-dir . --port 5030\n```\n\n" +
|
|
100
|
+
`Then open http://localhost:5030/demo.\n\n` +
|
|
101
|
+
`Create, edit, and delete operations update the routed JSON files here.\n`, "utf8");
|
|
102
|
+
fs.renameSync(temporary, resolved);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
fs.rmSync(temporary, { recursive: true, force: true });
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
return resolved;
|
|
109
|
+
}
|
|
110
|
+
function quote(value) {
|
|
111
|
+
return `"${value.replaceAll('"', '\\"')}"`;
|
|
112
|
+
}
|
|
113
|
+
export async function runCli(args) {
|
|
114
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
115
|
+
console.log(CLI_HELP);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (args.includes("--version") || args.includes("-v")) {
|
|
119
|
+
console.log(getPackageVersion());
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (args[0] === "create-demo") {
|
|
123
|
+
const { targetDir } = parseCreateDemoArgs(args.slice(1));
|
|
124
|
+
const created = createDemo(targetDir);
|
|
125
|
+
console.log(`\nDemo created at:\n ${created}\n`);
|
|
126
|
+
console.log("Start the server with:");
|
|
127
|
+
console.log(` memorix-explorer --mocks-dir ${quote(created)}\n`);
|
|
128
|
+
console.log("Then open:");
|
|
129
|
+
console.log(" http://localhost:5030/demo\n");
|
|
130
|
+
console.log("Create, edit, and delete operations will update JSON files in that folder.");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const options = parseServerArgs(args);
|
|
134
|
+
if (options.mocksDir)
|
|
135
|
+
process.env.MOCKS_DIR = options.mocksDir;
|
|
136
|
+
const { startServer } = await import("./server.js");
|
|
137
|
+
await startServer({ port: options.port, host: options.host });
|
|
138
|
+
}
|
|
139
|
+
function isCliEntrypoint() {
|
|
140
|
+
if (!process.argv[1])
|
|
141
|
+
return false;
|
|
142
|
+
try {
|
|
143
|
+
return fs.realpathSync(path.resolve(process.argv[1])) === fileURLToPath(import.meta.url);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (isCliEntrypoint()) {
|
|
150
|
+
runCli(process.argv.slice(2)).catch((error) => {
|
|
151
|
+
console.error(error instanceof Error ? error.message : error);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
});
|
|
154
|
+
}
|
package/dist/engine/lists.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare function executeListDescriptor(desc: ListDescriptor, params?: Exp
|
|
|
11
11
|
export declare function suggestListExtensions(entityName: string): {
|
|
12
12
|
entityName: string;
|
|
13
13
|
suggestions: {
|
|
14
|
-
contentType: "
|
|
14
|
+
contentType: "analysis" | "decisions" | "events" | "memory";
|
|
15
15
|
collection: string;
|
|
16
16
|
suggestion: string;
|
|
17
17
|
}[];
|
|
@@ -59,6 +59,39 @@ Memorix Explorer is ready
|
|
|
59
59
|
Health: http://localhost:5030/health
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
### Create a writable demo
|
|
63
|
+
|
|
64
|
+
The bundled fixtures may live inside a global npm installation. Create a
|
|
65
|
+
user-owned copy before experimenting with create/edit/delete:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
memorix-explorer create-demo
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The command creates `./memorix-demo` and prints the exact next step:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
Demo created at:
|
|
75
|
+
/your/current/directory/memorix-demo
|
|
76
|
+
|
|
77
|
+
Start the server with:
|
|
78
|
+
memorix-explorer --mocks-dir "/your/current/directory/memorix-demo"
|
|
79
|
+
|
|
80
|
+
Then open:
|
|
81
|
+
http://localhost:5030/demo
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The generated directory contains `demo.html`, `data/`, `metadata/`, and a
|
|
85
|
+
README. It is safe to edit and suitable for source control. The command refuses
|
|
86
|
+
to overwrite an existing file or directory.
|
|
87
|
+
|
|
88
|
+
Use a custom folder or port:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
memorix-explorer create-demo --dir ./fixtures
|
|
92
|
+
memorix-explorer --mocks-dir ./fixtures --port 8080
|
|
93
|
+
```
|
|
94
|
+
|
|
62
95
|
### With `npx` (no global install)
|
|
63
96
|
|
|
64
97
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x12i/static-memorix-explorer-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Static mock server providing full API parity for the Memorix Explorer API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/server.js",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"bin": {
|
|
18
|
-
"memorix-explorer": "dist/
|
|
19
|
-
"static-memorix-explorer-api": "dist/
|
|
20
|
-
"mock-memorix-explorer-api": "dist/
|
|
18
|
+
"memorix-explorer": "dist/cli.js",
|
|
19
|
+
"static-memorix-explorer-api": "dist/cli.js",
|
|
20
|
+
"mock-memorix-explorer-api": "dist/cli.js"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tsc -p tsconfig.json",
|
|
24
|
-
"start": "node dist/
|
|
25
|
-
"dev": "node --experimental-strip-types
|
|
24
|
+
"start": "node dist/cli.js",
|
|
25
|
+
"dev": "node --experimental-strip-types cli.ts",
|
|
26
26
|
"test": "npm run build && node --test tests/*.test.mjs",
|
|
27
27
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
28
28
|
"prepack": "npm run build",
|