rastack 0.0.43 → 0.0.44
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/CHANGELOG.md +7 -0
- package/admin/AdminApp.tsx +308 -0
- package/admin/adapters.ts +247 -0
- package/admin/index.tsx +88 -0
- package/admin/useAdmin.ts +299 -0
- package/dist/admin.js +81 -0
- package/dist/dev/harness.d.ts +53 -0
- package/dist/dev/harness.js +151 -0
- package/dist/rastack-dev.d.ts +18 -0
- package/dist/rastack-dev.js +197 -0
- package/dist/rastack-wasm-build.d.ts +9 -4
- package/dist/rastack-wasm-build.js +44 -33
- package/dist/rastack.d.ts +1 -2
- package/dist/rastack.js +7 -10
- package/dist/wasm/package.json +4 -0
- package/dist/wasm/rastack_wasm.d.ts +100 -0
- package/dist/wasm/rastack_wasm.js +745 -0
- package/dist/wasm/rastack_wasm_bg.wasm +0 -0
- package/dist/wasm/rastack_wasm_bg.wasm.d.ts +28 -0
- package/package.json +6 -2
- package/scripts/build-admin.js +48 -0
- package/scripts/copy-wasm.js +35 -0
- package/src/dev/harness.ts +130 -0
- package/src/rastack-dev.ts +197 -0
- package/src/rastack-wasm-build.ts +52 -41
- package/src/rastack.ts +7 -10
- package/test/dev.spec.ts +277 -0
- package/wasm/package.json +4 -0
- package/wasm/rastack_wasm.d.ts +100 -0
- package/wasm/rastack_wasm.js +745 -0
- package/wasm/rastack_wasm_bg.wasm +0 -0
- package/wasm/rastack_wasm_bg.wasm.d.ts +28 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure core of `rastack dev` — the local, always-WASM development server.
|
|
3
|
+
*
|
|
4
|
+
* `rastack dev` boots the app + admin **in the browser** over the WebAssembly
|
|
5
|
+
* engine (the same app-generic `rastack-api-core` the Lambda runs, fed the app's
|
|
6
|
+
* compiled manifest). No native server, no cargo: a dependency-free static
|
|
7
|
+
* server hands the browser the prebuilt wasm engine, the compiled schema, and
|
|
8
|
+
* the committed Iceberg warehouse, and a bundled React admin drives it.
|
|
9
|
+
*
|
|
10
|
+
* Everything decidable without IO lives here (arg parsing, MIME types, locating
|
|
11
|
+
* the wasm bundle, the HTML shell) so it is unit-tested without a socket or a
|
|
12
|
+
* filesystem; `rastack-dev.ts` is the thin IO wrapper that compiles, resolves
|
|
13
|
+
* the engine, and serves.
|
|
14
|
+
*/
|
|
15
|
+
export interface DevArgs {
|
|
16
|
+
/** Where the TypeScript resource definitions live (compiled on start). */
|
|
17
|
+
resourcesDir: string;
|
|
18
|
+
/** Where `rastack compile` writes schema.rastack.json + openapi.json. */
|
|
19
|
+
outDir: string;
|
|
20
|
+
/** The committed Iceberg warehouse served to seed the browser engine. */
|
|
21
|
+
warehouseDir: string;
|
|
22
|
+
/** Port the dev server listens on. */
|
|
23
|
+
port: number;
|
|
24
|
+
/** Open the browser on start (false with `--no-open`). */
|
|
25
|
+
open: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const DEV_DEFAULTS: DevArgs;
|
|
28
|
+
/**
|
|
29
|
+
* Parse `rastack dev` args: `--port`, `--warehouse`, `--out`, `--no-open`, and a
|
|
30
|
+
* single positional resources dir. Unknown flags are ignored (forgiving CLI).
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseDevArgs(argv: string[]): DevArgs;
|
|
33
|
+
/** MIME type for a served path, defaulting to octet-stream (Iceberg data files). */
|
|
34
|
+
export declare function contentType(filePath: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Ordered directories to look for the prebuilt wasm bundle (`rastack_wasm.js` +
|
|
37
|
+
* `rastack_wasm_bg.wasm`). The bundle is shipped inside the package
|
|
38
|
+
* (`dist/wasm/`, copied at build), so `rastack dev` works from any repo with no
|
|
39
|
+
* cargo; the repo-local `tools/wasm/` (from a source build) and a sibling of the
|
|
40
|
+
* running module are fallbacks for development. `dirnameDir` is the directory of
|
|
41
|
+
* the compiled `rastack-dev.js` (`dist/`), so `../wasm` and `./wasm` cover both
|
|
42
|
+
* `dist/rastack-dev.js` → `dist/wasm` and `dist/dev/…` layouts.
|
|
43
|
+
*/
|
|
44
|
+
export declare function wasmBundleCandidates(dirnameDir: string, cwd?: string): string[];
|
|
45
|
+
/** The name of the file that marks a directory as a usable wasm bundle. */
|
|
46
|
+
export declare const WASM_ENTRY = "rastack_wasm.js";
|
|
47
|
+
/**
|
|
48
|
+
* The HTML shell served at `/`. It loads the bundled React admin
|
|
49
|
+
* (`/dev/admin.js`), which fetches the schema/openapi, boots the wasm engine,
|
|
50
|
+
* seeds it from `/data/warehouse/`, and renders the admin. Deliberately tiny —
|
|
51
|
+
* all logic lives in the bundle — mirroring the `rastack design` studio.
|
|
52
|
+
*/
|
|
53
|
+
export declare function renderShell(title?: string): string;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Pure core of `rastack dev` — the local, always-WASM development server.
|
|
4
|
+
*
|
|
5
|
+
* `rastack dev` boots the app + admin **in the browser** over the WebAssembly
|
|
6
|
+
* engine (the same app-generic `rastack-api-core` the Lambda runs, fed the app's
|
|
7
|
+
* compiled manifest). No native server, no cargo: a dependency-free static
|
|
8
|
+
* server hands the browser the prebuilt wasm engine, the compiled schema, and
|
|
9
|
+
* the committed Iceberg warehouse, and a bundled React admin drives it.
|
|
10
|
+
*
|
|
11
|
+
* Everything decidable without IO lives here (arg parsing, MIME types, locating
|
|
12
|
+
* the wasm bundle, the HTML shell) so it is unit-tested without a socket or a
|
|
13
|
+
* filesystem; `rastack-dev.ts` is the thin IO wrapper that compiles, resolves
|
|
14
|
+
* the engine, and serves.
|
|
15
|
+
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
33
|
+
var ownKeys = function(o) {
|
|
34
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
35
|
+
var ar = [];
|
|
36
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
37
|
+
return ar;
|
|
38
|
+
};
|
|
39
|
+
return ownKeys(o);
|
|
40
|
+
};
|
|
41
|
+
return function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
45
|
+
__setModuleDefault(result, mod);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.WASM_ENTRY = exports.DEV_DEFAULTS = void 0;
|
|
51
|
+
exports.parseDevArgs = parseDevArgs;
|
|
52
|
+
exports.contentType = contentType;
|
|
53
|
+
exports.wasmBundleCandidates = wasmBundleCandidates;
|
|
54
|
+
exports.renderShell = renderShell;
|
|
55
|
+
const path = __importStar(require("path"));
|
|
56
|
+
exports.DEV_DEFAULTS = {
|
|
57
|
+
resourcesDir: "resources",
|
|
58
|
+
outDir: ".rastack",
|
|
59
|
+
warehouseDir: "data/warehouse",
|
|
60
|
+
port: 4321,
|
|
61
|
+
open: true,
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Parse `rastack dev` args: `--port`, `--warehouse`, `--out`, `--no-open`, and a
|
|
65
|
+
* single positional resources dir. Unknown flags are ignored (forgiving CLI).
|
|
66
|
+
*/
|
|
67
|
+
function parseDevArgs(argv) {
|
|
68
|
+
const positional = [];
|
|
69
|
+
let { resourcesDir, outDir, warehouseDir, port, open } = exports.DEV_DEFAULTS;
|
|
70
|
+
for (let i = 0; i < argv.length; i++) {
|
|
71
|
+
const a = argv[i];
|
|
72
|
+
if (a === "--port")
|
|
73
|
+
port = Number(argv[++i]) || port;
|
|
74
|
+
else if (a === "--warehouse")
|
|
75
|
+
warehouseDir = argv[++i] ?? warehouseDir;
|
|
76
|
+
else if (a === "--out")
|
|
77
|
+
outDir = argv[++i] ?? outDir;
|
|
78
|
+
else if (a === "--no-open")
|
|
79
|
+
open = false;
|
|
80
|
+
else if (!a.startsWith("-"))
|
|
81
|
+
positional.push(a);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
resourcesDir: positional[0] || resourcesDir,
|
|
85
|
+
outDir,
|
|
86
|
+
warehouseDir,
|
|
87
|
+
port,
|
|
88
|
+
open,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const MIME = {
|
|
92
|
+
".html": "text/html; charset=utf-8",
|
|
93
|
+
".js": "text/javascript; charset=utf-8",
|
|
94
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
95
|
+
".css": "text/css; charset=utf-8",
|
|
96
|
+
".json": "application/json; charset=utf-8",
|
|
97
|
+
// Critical: `WebAssembly.instantiateStreaming` requires this exact type.
|
|
98
|
+
".wasm": "application/wasm",
|
|
99
|
+
".text": "text/plain; charset=utf-8",
|
|
100
|
+
".parquet": "application/octet-stream",
|
|
101
|
+
};
|
|
102
|
+
/** MIME type for a served path, defaulting to octet-stream (Iceberg data files). */
|
|
103
|
+
function contentType(filePath) {
|
|
104
|
+
const ext = filePath.slice(filePath.lastIndexOf("."));
|
|
105
|
+
return MIME[ext] ?? "application/octet-stream";
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Ordered directories to look for the prebuilt wasm bundle (`rastack_wasm.js` +
|
|
109
|
+
* `rastack_wasm_bg.wasm`). The bundle is shipped inside the package
|
|
110
|
+
* (`dist/wasm/`, copied at build), so `rastack dev` works from any repo with no
|
|
111
|
+
* cargo; the repo-local `tools/wasm/` (from a source build) and a sibling of the
|
|
112
|
+
* running module are fallbacks for development. `dirnameDir` is the directory of
|
|
113
|
+
* the compiled `rastack-dev.js` (`dist/`), so `../wasm` and `./wasm` cover both
|
|
114
|
+
* `dist/rastack-dev.js` → `dist/wasm` and `dist/dev/…` layouts.
|
|
115
|
+
*/
|
|
116
|
+
function wasmBundleCandidates(dirnameDir, cwd = process.cwd()) {
|
|
117
|
+
return [
|
|
118
|
+
path.join(dirnameDir, "wasm"),
|
|
119
|
+
path.join(dirnameDir, "..", "wasm"),
|
|
120
|
+
path.join(cwd, "tools", "wasm"),
|
|
121
|
+
path.join(cwd, "wasm"),
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
/** The name of the file that marks a directory as a usable wasm bundle. */
|
|
125
|
+
exports.WASM_ENTRY = "rastack_wasm.js";
|
|
126
|
+
/**
|
|
127
|
+
* The HTML shell served at `/`. It loads the bundled React admin
|
|
128
|
+
* (`/dev/admin.js`), which fetches the schema/openapi, boots the wasm engine,
|
|
129
|
+
* seeds it from `/data/warehouse/`, and renders the admin. Deliberately tiny —
|
|
130
|
+
* all logic lives in the bundle — mirroring the `rastack design` studio.
|
|
131
|
+
*/
|
|
132
|
+
function renderShell(title = "React API Stack — dev") {
|
|
133
|
+
return `<!doctype html>
|
|
134
|
+
<html lang="en">
|
|
135
|
+
<head>
|
|
136
|
+
<meta charset="utf-8" />
|
|
137
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
138
|
+
<title>${title}</title>
|
|
139
|
+
<style>
|
|
140
|
+
html, body { margin: 0; height: 100%; }
|
|
141
|
+
#root { min-height: 100%; }
|
|
142
|
+
.rastack-boot { font: 14px system-ui, sans-serif; padding: 2rem; color: #555; }
|
|
143
|
+
</style>
|
|
144
|
+
</head>
|
|
145
|
+
<body>
|
|
146
|
+
<div id="root"><div class="rastack-boot">Loading the WASM engine…</div></div>
|
|
147
|
+
<script src="/dev/admin.js"></script>
|
|
148
|
+
</body>
|
|
149
|
+
</html>
|
|
150
|
+
`;
|
|
151
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `rastack dev` — local development, always over the WASM engine.
|
|
4
|
+
*
|
|
5
|
+
* rastack dev [resourcesDir] [--port <n>] [--warehouse <dir>] [--out <dir>] [--no-open]
|
|
6
|
+
*
|
|
7
|
+
* Compiles the resources, then boots a dependency-free static server (à la
|
|
8
|
+
* `rastack design`) that hands the browser everything it needs to run the app +
|
|
9
|
+
* admin locally over WebAssembly — no native server, no cargo:
|
|
10
|
+
* • the bundled React admin (`/dev/admin.js`),
|
|
11
|
+
* • the prebuilt WASM engine (`/wasm/…`) shipped in the package,
|
|
12
|
+
* • the compiled `schema.rastack.json` / `openapi.json`,
|
|
13
|
+
* • the committed Iceberg warehouse (`/data/warehouse/…`) to seed from.
|
|
14
|
+
*
|
|
15
|
+
* The engine is resolved from the package's prebuilt bundle; if none is present
|
|
16
|
+
* but a Rust + wasm toolchain is, it is built from source as a fallback.
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* `rastack dev` — local development, always over the WASM engine.
|
|
5
|
+
*
|
|
6
|
+
* rastack dev [resourcesDir] [--port <n>] [--warehouse <dir>] [--out <dir>] [--no-open]
|
|
7
|
+
*
|
|
8
|
+
* Compiles the resources, then boots a dependency-free static server (à la
|
|
9
|
+
* `rastack design`) that hands the browser everything it needs to run the app +
|
|
10
|
+
* admin locally over WebAssembly — no native server, no cargo:
|
|
11
|
+
* • the bundled React admin (`/dev/admin.js`),
|
|
12
|
+
* • the prebuilt WASM engine (`/wasm/…`) shipped in the package,
|
|
13
|
+
* • the compiled `schema.rastack.json` / `openapi.json`,
|
|
14
|
+
* • the committed Iceberg warehouse (`/data/warehouse/…`) to seed from.
|
|
15
|
+
*
|
|
16
|
+
* The engine is resolved from the package's prebuilt bundle; if none is present
|
|
17
|
+
* but a Rust + wasm toolchain is, it is built from source as a fallback.
|
|
18
|
+
*/
|
|
19
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
22
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
23
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
24
|
+
}
|
|
25
|
+
Object.defineProperty(o, k2, desc);
|
|
26
|
+
}) : (function(o, m, k, k2) {
|
|
27
|
+
if (k2 === undefined) k2 = k;
|
|
28
|
+
o[k2] = m[k];
|
|
29
|
+
}));
|
|
30
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
31
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
32
|
+
}) : function(o, v) {
|
|
33
|
+
o["default"] = v;
|
|
34
|
+
});
|
|
35
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
36
|
+
var ownKeys = function(o) {
|
|
37
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
38
|
+
var ar = [];
|
|
39
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
40
|
+
return ar;
|
|
41
|
+
};
|
|
42
|
+
return ownKeys(o);
|
|
43
|
+
};
|
|
44
|
+
return function (mod) {
|
|
45
|
+
if (mod && mod.__esModule) return mod;
|
|
46
|
+
var result = {};
|
|
47
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
48
|
+
__setModuleDefault(result, mod);
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
})();
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
const child_process_1 = require("child_process");
|
|
54
|
+
const fs = __importStar(require("fs"));
|
|
55
|
+
const http = __importStar(require("http"));
|
|
56
|
+
const path = __importStar(require("path"));
|
|
57
|
+
const harness_1 = require("./dev/harness");
|
|
58
|
+
const HERE = __dirname; // dist/ when installed
|
|
59
|
+
/** Compile the resources to schema.rastack.json + openapi.json in outDir. */
|
|
60
|
+
function compile(resourcesDir, outDir) {
|
|
61
|
+
const compiler = path.join(HERE, "rastack-compile.js");
|
|
62
|
+
const result = (0, child_process_1.spawnSync)(process.execPath, [compiler, "compile", resourcesDir, outDir], { stdio: "inherit" });
|
|
63
|
+
if (result.status !== 0)
|
|
64
|
+
return false;
|
|
65
|
+
return fs.existsSync(path.join(outDir, "schema.rastack.json"));
|
|
66
|
+
}
|
|
67
|
+
/** True when `cargo` is on PATH (the from-source wasm fallback needs it). */
|
|
68
|
+
function cargoAvailable() {
|
|
69
|
+
try {
|
|
70
|
+
return ((0, child_process_1.spawnSync)("cargo", ["--version"], { stdio: "ignore" }).status === 0);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Locate the prebuilt wasm bundle dir, building from source as a fallback. */
|
|
77
|
+
function resolveWasmDir() {
|
|
78
|
+
for (const dir of (0, harness_1.wasmBundleCandidates)(HERE)) {
|
|
79
|
+
if (fs.existsSync(path.join(dir, harness_1.WASM_ENTRY)))
|
|
80
|
+
return dir;
|
|
81
|
+
}
|
|
82
|
+
if (cargoAvailable()) {
|
|
83
|
+
console.log("\n▸ No prebuilt WASM engine found — building it from source (cargo)…\n");
|
|
84
|
+
try {
|
|
85
|
+
// Lazy require so a normal `dev` with a prebuilt bundle never loads it.
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
87
|
+
require("./rastack-wasm-build").buildWasm();
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
console.error(` ✗ wasm build failed: ${err.message}`);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
for (const dir of (0, harness_1.wasmBundleCandidates)(HERE)) {
|
|
94
|
+
if (fs.existsSync(path.join(dir, harness_1.WASM_ENTRY)))
|
|
95
|
+
return dir;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/** Serve one file if it exists and stays within `root`; else 404/403. */
|
|
101
|
+
function serveUnder(res, root, relPath) {
|
|
102
|
+
const safeRoot = path.resolve(root);
|
|
103
|
+
const rel = decodeURIComponent(relPath).replace(/^\/+/, "");
|
|
104
|
+
const target = path.resolve(safeRoot, rel);
|
|
105
|
+
// Path-traversal guard: the resolved target must stay inside the root.
|
|
106
|
+
if (target !== safeRoot && !target.startsWith(safeRoot + path.sep)) {
|
|
107
|
+
res.writeHead(403).end("Forbidden");
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
fs.readFile(target, (err, data) => {
|
|
111
|
+
if (err) {
|
|
112
|
+
res.writeHead(404).end("Not found");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
res.writeHead(200, { "Content-Type": (0, harness_1.contentType)(target) }).end(data);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** Serve an exact file (no traversal concern — a fixed internal artifact). */
|
|
119
|
+
function serveFile(res, file) {
|
|
120
|
+
fs.readFile(file, (err, data) => {
|
|
121
|
+
if (err) {
|
|
122
|
+
res.writeHead(404).end("Not found");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
res.writeHead(200, { "Content-Type": (0, harness_1.contentType)(file) }).end(data);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/** Best-effort open the default browser at `url`. */
|
|
129
|
+
function openBrowser(url) {
|
|
130
|
+
const cmd = process.platform === "darwin"
|
|
131
|
+
? "open"
|
|
132
|
+
: process.platform === "win32"
|
|
133
|
+
? "start"
|
|
134
|
+
: "xdg-open";
|
|
135
|
+
try {
|
|
136
|
+
(0, child_process_1.execFileSync)(cmd, [url], { stdio: "ignore" });
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
/* non-fatal — the URL is printed anyway */
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function main(argv) {
|
|
143
|
+
const args = (0, harness_1.parseDevArgs)(argv);
|
|
144
|
+
console.log(`\n rastack dev — the app + admin, in your browser over WASM\n`);
|
|
145
|
+
console.log(`▸ Compiling ${args.resourcesDir} → ${args.outDir}`);
|
|
146
|
+
if (!compile(args.resourcesDir, args.outDir)) {
|
|
147
|
+
console.error(" ✗ compile failed — fix the resource graph and re-run.");
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
const wasmDir = resolveWasmDir();
|
|
151
|
+
if (!wasmDir) {
|
|
152
|
+
console.error("\n ✗ No WASM engine available.\n" +
|
|
153
|
+
" Upgrade rastack for the prebuilt bundle (`rastack update`), or install\n" +
|
|
154
|
+
" the Rust toolchain to build it from source:\n" +
|
|
155
|
+
" rustup target add wasm32-unknown-unknown\n" +
|
|
156
|
+
" cargo install wasm-bindgen-cli\n");
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
const adminBundle = path.join(HERE, "admin.js");
|
|
160
|
+
if (!fs.existsSync(adminBundle)) {
|
|
161
|
+
console.error(" ✗ admin bundle (dist/admin.js) not found — reinstall rastack.");
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
const server = http.createServer((req, res) => {
|
|
165
|
+
const url = (req.url || "/").split("?")[0];
|
|
166
|
+
if (req.method !== "GET") {
|
|
167
|
+
res.writeHead(405).end("Method not allowed");
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (url === "/" || url === "/index.html") {
|
|
171
|
+
res
|
|
172
|
+
.writeHead(200, { "Content-Type": "text/html; charset=utf-8" })
|
|
173
|
+
.end((0, harness_1.renderShell)());
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (url === "/dev/admin.js")
|
|
177
|
+
return serveFile(res, adminBundle);
|
|
178
|
+
if (url.startsWith("/wasm/"))
|
|
179
|
+
return serveUnder(res, wasmDir, url.slice("/wasm/".length));
|
|
180
|
+
if (url === "/schema.rastack.json" || url === "/openapi.json")
|
|
181
|
+
return serveUnder(res, args.outDir, path.basename(url));
|
|
182
|
+
if (url.startsWith("/data/warehouse/"))
|
|
183
|
+
return serveUnder(res, args.warehouseDir, url.slice("/data/warehouse/".length));
|
|
184
|
+
res.writeHead(404).end("Not found");
|
|
185
|
+
});
|
|
186
|
+
server.listen(args.port, () => {
|
|
187
|
+
const url = `http://localhost:${args.port}`;
|
|
188
|
+
console.log(` ✓ WASM engine: ${path.relative(process.cwd(), wasmDir)}`);
|
|
189
|
+
console.log(`\n ▸ ${url} (admin at ${url}/#/)\n`);
|
|
190
|
+
console.log(" Press Ctrl+C to stop.\n");
|
|
191
|
+
if (args.open)
|
|
192
|
+
openBrowser(url);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (require.main === module) {
|
|
196
|
+
main(process.argv.slice(2));
|
|
197
|
+
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Compile the Rust API to WebAssembly for in-browser local dev — the engine
|
|
4
|
+
* `rastack dev` serves and `<RAStackProvider mode="local">` loads.
|
|
4
5
|
*
|
|
5
6
|
* Pipeline:
|
|
6
7
|
* 1. cargo build -p rastack-wasm --release --target wasm32-unknown-unknown
|
|
7
|
-
* 2. wasm-bindgen --target web →
|
|
8
|
+
* 2. wasm-bindgen --target web → tools/wasm/rastack_wasm.js + rastack_wasm_bg.wasm
|
|
8
9
|
* 3. wasm-opt -Oz (if available) to shrink the binary
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
+
* This is invoked by the release CI (to bundle a prebuilt engine into the npm
|
|
12
|
+
* package) and by `rastack dev` as a from-source fallback when no prebuilt
|
|
13
|
+
* bundle is present but the toolchain is. Prereqs:
|
|
11
14
|
* rustup target add wasm32-unknown-unknown
|
|
12
15
|
* cargo install wasm-bindgen-cli (version must match the wasm-bindgen crate)
|
|
13
16
|
*/
|
|
14
|
-
|
|
17
|
+
/** Run the full compile → wasm-bindgen → optimise pipeline. Throws via `run`'s
|
|
18
|
+
* `process.exit` on a missing tool or a non-zero step. */
|
|
19
|
+
export declare function buildWasm(): void;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Compile the Rust API to WebAssembly for in-browser local dev — the engine
|
|
5
|
+
* `rastack dev` serves and `<RAStackProvider mode="local">` loads.
|
|
5
6
|
*
|
|
6
7
|
* Pipeline:
|
|
7
8
|
* 1. cargo build -p rastack-wasm --release --target wasm32-unknown-unknown
|
|
8
|
-
* 2. wasm-bindgen --target web →
|
|
9
|
+
* 2. wasm-bindgen --target web → tools/wasm/rastack_wasm.js + rastack_wasm_bg.wasm
|
|
9
10
|
* 3. wasm-opt -Oz (if available) to shrink the binary
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
+
* This is invoked by the release CI (to bundle a prebuilt engine into the npm
|
|
13
|
+
* package) and by `rastack dev` as a from-source fallback when no prebuilt
|
|
14
|
+
* bundle is present but the toolchain is. Prereqs:
|
|
12
15
|
* rustup target add wasm32-unknown-unknown
|
|
13
16
|
* cargo install wasm-bindgen-cli (version must match the wasm-bindgen crate)
|
|
14
17
|
*/
|
|
@@ -16,6 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
19
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
20
|
};
|
|
18
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.buildWasm = buildWasm;
|
|
19
23
|
const child_process_1 = require("child_process");
|
|
20
24
|
const fs_1 = __importDefault(require("fs"));
|
|
21
25
|
const path_1 = __importDefault(require("path"));
|
|
@@ -49,35 +53,42 @@ function has(cmd) {
|
|
|
49
53
|
// nosemgrep: javascript.lang.security.detect-child-process.detect-child-process
|
|
50
54
|
return (0, child_process_1.spawnSync)(cmd, ["--version"], { stdio: "ignore" }).status === 0;
|
|
51
55
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"-p"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
/** Run the full compile → wasm-bindgen → optimise pipeline. Throws via `run`'s
|
|
57
|
+
* `process.exit` on a missing tool or a non-zero step. */
|
|
58
|
+
function buildWasm() {
|
|
59
|
+
console.log("→ cargo build -p rastack-wasm --release (wasm32-unknown-unknown)");
|
|
60
|
+
run("cargo", [
|
|
61
|
+
"build",
|
|
62
|
+
"-p",
|
|
63
|
+
"rastack-wasm",
|
|
64
|
+
"--release",
|
|
65
|
+
"--target",
|
|
66
|
+
"wasm32-unknown-unknown",
|
|
67
|
+
], rustDir);
|
|
68
|
+
console.log("→ wasm-bindgen → tools/wasm/");
|
|
69
|
+
run("wasm-bindgen", [
|
|
70
|
+
"--target",
|
|
71
|
+
"web",
|
|
72
|
+
"--out-dir",
|
|
73
|
+
outDir,
|
|
74
|
+
"--out-name",
|
|
75
|
+
"rastack_wasm",
|
|
76
|
+
wasmPath,
|
|
77
|
+
]);
|
|
78
|
+
// Mark the emitted bundle as ESM so Node and bundlers treat it correctly
|
|
79
|
+
// without forcing the parent rastack package to be a module.
|
|
80
|
+
fs_1.default.writeFileSync(path_1.default.join(outDir, "package.json"), JSON.stringify({ type: "module", sideEffects: false }, null, 2) + "\n");
|
|
81
|
+
if (has("wasm-opt")) {
|
|
82
|
+
console.log("→ wasm-opt -Oz");
|
|
83
|
+
const bg = path_1.default.join(outDir, "rastack_wasm_bg.wasm");
|
|
84
|
+
run("wasm-opt", ["-Oz", "-o", bg, bg]);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
console.log("· wasm-opt not found — skipping size optimisation (optional)");
|
|
88
|
+
}
|
|
89
|
+
const size = fs_1.default.statSync(path_1.default.join(outDir, "rastack_wasm_bg.wasm")).size;
|
|
90
|
+
console.log(`✓ wasm engine built: tools/wasm/ (${(size / 1024).toFixed(0)} KB)`);
|
|
78
91
|
}
|
|
79
|
-
|
|
80
|
-
|
|
92
|
+
if (require.main === module) {
|
|
93
|
+
buildWasm();
|
|
81
94
|
}
|
|
82
|
-
const size = fs_1.default.statSync(path_1.default.join(outDir, "rastack_wasm_bg.wasm")).size;
|
|
83
|
-
console.log(`✓ wasm engine built: stack/wasm/ (${(size / 1024).toFixed(0)} KB)`);
|
package/dist/rastack.d.ts
CHANGED
|
@@ -10,9 +10,8 @@
|
|
|
10
10
|
* rastack generate [--schema-only] Generate typed hooks from OpenAPI
|
|
11
11
|
* rastack tokens [input] [outDir] Compile design tokens → CSS vars + typed theme
|
|
12
12
|
* rastack design [input] [--port n] Live design-system studio (showcase + edit)
|
|
13
|
-
* rastack
|
|
13
|
+
* rastack dev [--port n] [--warehouse d] Local dev: run the app + admin in-browser over WASM
|
|
14
14
|
* rastack admin [--warehouse dir] Run the Rust admin (Django-admin-style DB browser)
|
|
15
|
-
* rastack wasm Compile the API to WebAssembly (in-browser local dev)
|
|
16
15
|
* rastack scan [files...] [--fail-on-pii] Scan CSVs for PII and schema info
|
|
17
16
|
* rastack seed [--env dev] [--source gs://] Load CSVs into Iceberg namespace
|
|
18
17
|
* rastack bootstrap [--owner o] [--repo r] Stand the tier-0 AWS account stack up (once per account+region)
|
package/dist/rastack.js
CHANGED
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
* rastack generate [--schema-only] Generate typed hooks from OpenAPI
|
|
12
12
|
* rastack tokens [input] [outDir] Compile design tokens → CSS vars + typed theme
|
|
13
13
|
* rastack design [input] [--port n] Live design-system studio (showcase + edit)
|
|
14
|
-
* rastack
|
|
14
|
+
* rastack dev [--port n] [--warehouse d] Local dev: run the app + admin in-browser over WASM
|
|
15
15
|
* rastack admin [--warehouse dir] Run the Rust admin (Django-admin-style DB browser)
|
|
16
|
-
* rastack wasm Compile the API to WebAssembly (in-browser local dev)
|
|
17
16
|
* rastack scan [files...] [--fail-on-pii] Scan CSVs for PII and schema info
|
|
18
17
|
* rastack seed [--env dev] [--source gs://] Load CSVs into Iceberg namespace
|
|
19
18
|
* rastack bootstrap [--owner o] [--repo r] Stand the tier-0 AWS account stack up (once per account+region)
|
|
@@ -90,16 +89,14 @@ switch (command) {
|
|
|
90
89
|
// rastack-compile dispatches on its own first argument, so pass the command.
|
|
91
90
|
run("rastack-compile.js", [command, ...rest]);
|
|
92
91
|
break;
|
|
93
|
-
case "
|
|
94
|
-
|
|
92
|
+
case "dev":
|
|
93
|
+
// Local development: serve the app + admin in the browser over the WASM
|
|
94
|
+
// engine (no native server, no cargo). Replaces `serve` + `wasm`.
|
|
95
|
+
run("rastack-dev.js", rest);
|
|
95
96
|
break;
|
|
96
97
|
case "admin":
|
|
97
98
|
runRust("admin");
|
|
98
99
|
break;
|
|
99
|
-
case "wasm":
|
|
100
|
-
// Compile the API to WebAssembly for in-browser local dev.
|
|
101
|
-
run("rastack-wasm-build.js", rest);
|
|
102
|
-
break;
|
|
103
100
|
case "tokens":
|
|
104
101
|
// Design tokens → CSS custom properties + typed theme.
|
|
105
102
|
run("rastack-tokens.js", rest);
|
|
@@ -150,8 +147,8 @@ switch (command) {
|
|
|
150
147
|
` rastack generate [--schema-only]\n` +
|
|
151
148
|
` rastack tokens [input] [outDir] [--prefix p] Compile design tokens → CSS vars + typed theme\n` +
|
|
152
149
|
` rastack design [input] [--port n] Live design-system studio (showcase + edit)\n` +
|
|
153
|
-
` rastack
|
|
154
|
-
` rastack
|
|
150
|
+
` rastack dev [--port n] [--warehouse dir] [--no-open] Run the app + admin in-browser over WASM (local dev)\n` +
|
|
151
|
+
` rastack admin [--warehouse dir] Run the native Rust admin (needs a built rastack-server)\n` +
|
|
155
152
|
` rastack scan [files...] [--fail-on-pii]\n` +
|
|
156
153
|
` rastack seed [--env dev|staging] [--source gs://bucket/ | ./myapp-dev/]\n` +
|
|
157
154
|
` rastack bootstrap [--owner o] [--repo r] [--region r] [--prefix p] [--reuse-oidc] [--print] Stand the AWS account stack up\n` +
|