rastack 0.0.64 → 0.0.69
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 +25 -0
- package/README.md +19 -24
- package/admin/httpEngine.ts +5 -6
- package/admin/index.tsx +11 -91
- package/dist/admin.js +14 -22
- package/dist/compile/model.d.ts +1 -1
- package/dist/compile/run.d.ts +2 -2
- package/dist/compile/run.js +2 -2
- package/dist/define/index.d.ts +2 -3
- package/dist/deploy/workflows.js +1 -1
- package/dist/dev/harness.d.ts +19 -27
- package/dist/dev/harness.js +31 -40
- package/dist/dev/native-server.d.ts +29 -0
- package/dist/dev/native-server.js +174 -0
- package/dist/external/envelope.d.ts +1 -1
- package/dist/external/envelope.js +1 -1
- package/dist/external/service.d.ts +2 -2
- package/dist/external/service.js +2 -2
- package/dist/external/types.d.ts +1 -1
- package/dist/external/types.js +1 -1
- package/dist/rastack-admin.d.ts +6 -14
- package/dist/rastack-admin.js +60 -88
- package/dist/rastack-design.d.ts +1 -2
- package/dist/rastack-design.js +1 -2
- package/dist/rastack-dev.d.ts +7 -10
- package/dist/rastack-dev.js +68 -80
- package/dist/rastack.d.ts +1 -1
- package/dist/rastack.js +5 -6
- package/dist/validate/transitions.d.ts +1 -1
- package/dist/validate/transitions.js +1 -1
- package/hooks/query/api.ts +4 -6
- package/package.json +2 -2
- package/provider/index.ts +0 -1
- package/provider/provider.tsx +31 -157
- package/provider/types.ts +29 -77
- package/src/compile/model.ts +1 -1
- package/src/compile/run.ts +2 -2
- package/src/define/index.ts +2 -3
- package/src/deploy/workflows.ts +1 -1
- package/src/dev/harness.ts +30 -43
- package/src/dev/native-server.ts +164 -0
- package/src/external/envelope.ts +1 -1
- package/src/external/service.ts +2 -2
- package/src/external/types.ts +1 -1
- package/src/rastack-admin.ts +66 -107
- package/src/rastack-design.ts +1 -2
- package/src/rastack-dev.ts +79 -91
- package/src/rastack.ts +5 -6
- package/src/validate/transitions.ts +1 -1
- package/dist/rastack-wasm-build.d.ts +0 -19
- package/dist/rastack-wasm-build.js +0 -94
- package/dist/wasm/package.json +0 -4
- package/dist/wasm/rastack_wasm.d.ts +0 -100
- package/dist/wasm/rastack_wasm.js +0 -745
- package/dist/wasm/rastack_wasm_bg.wasm +0 -0
- package/dist/wasm/rastack_wasm_bg.wasm.d.ts +0 -28
- package/provider/wasm.ts +0 -126
- package/scripts/copy-wasm.js +0 -35
- package/src/rastack-wasm-build.ts +0 -113
|
Binary file
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
export const memory: WebAssembly.Memory;
|
|
4
|
-
export const __wbg_rastackapi_free: (a: number, b: number) => void;
|
|
5
|
-
export const rastackapi_exportWarehouse: (a: number) => any;
|
|
6
|
-
export const rastackapi_handle: (a: number, b: number, c: number, d: number, e: number, f: any, g: any) => any;
|
|
7
|
-
export const rastackapi_importWarehouse: (a: number, b: number, c: number) => any;
|
|
8
|
-
export const rastackapi_new: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
9
|
-
export const rastackapi_seedFile: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
10
|
-
export const rastackapi_setAuth: (a: number, b: number, c: number, d: any) => [number, number];
|
|
11
|
-
export const rust_zstd_wasm_shim_calloc: (a: number, b: number) => number;
|
|
12
|
-
export const rust_zstd_wasm_shim_free: (a: number) => void;
|
|
13
|
-
export const rust_zstd_wasm_shim_malloc: (a: number) => number;
|
|
14
|
-
export const rust_zstd_wasm_shim_memcmp: (a: number, b: number, c: number) => number;
|
|
15
|
-
export const rust_zstd_wasm_shim_memcpy: (a: number, b: number, c: number) => number;
|
|
16
|
-
export const rust_zstd_wasm_shim_memmove: (a: number, b: number, c: number) => number;
|
|
17
|
-
export const rust_zstd_wasm_shim_memset: (a: number, b: number, c: number) => number;
|
|
18
|
-
export const rust_zstd_wasm_shim_qsort: (a: number, b: number, c: number, d: number) => void;
|
|
19
|
-
export const wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___wasm_bindgen_ac0f9960a408a037___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_ac0f9960a408a037___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
20
|
-
export const wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
21
|
-
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
22
|
-
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
23
|
-
export const __wbindgen_exn_store: (a: number) => void;
|
|
24
|
-
export const __externref_table_alloc: () => number;
|
|
25
|
-
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
26
|
-
export const __wbindgen_destroy_closure: (a: number, b: number) => void;
|
|
27
|
-
export const __externref_table_dealloc: (a: number) => void;
|
|
28
|
-
export const __wbindgen_start: () => void;
|
package/provider/wasm.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { AxiosAdapter, AxiosError, AxiosResponse } from "axios";
|
|
2
|
-
import { RastackEngine, RastackEngineLoader, RastackWasmModule } from "./types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Default WASM loader: import the bundle `rastack wasm` generates
|
|
6
|
-
* (`rastack/wasm/rastack_wasm.js`) and run its init. The indirection through
|
|
7
|
-
* `new Function` keeps a genuine dynamic `import()` at runtime even when the
|
|
8
|
-
* package is transpiled to CommonJS, so the consumer's bundler resolves and
|
|
9
|
-
* code-splits the `.wasm`.
|
|
10
|
-
*/
|
|
11
|
-
const runtimeImport: (specifier: string) => Promise<any> =
|
|
12
|
-
// eslint-disable-next-line no-new-func
|
|
13
|
-
new Function("s", "return import(s)") as any;
|
|
14
|
-
|
|
15
|
-
export const defaultEngineLoader: RastackEngineLoader = async () => {
|
|
16
|
-
const mod: RastackWasmModule = await runtimeImport(
|
|
17
|
-
"rastack/wasm/rastack_wasm.js",
|
|
18
|
-
);
|
|
19
|
-
const init = mod.default || mod.init;
|
|
20
|
-
if (typeof init === "function") {
|
|
21
|
-
await init();
|
|
22
|
-
}
|
|
23
|
-
return mod;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Instantiate the engine from a loaded module and the compiled schema. The
|
|
28
|
-
* manifest/openapi are passed as JSON strings — the same `schema.rastack.json` /
|
|
29
|
-
* `openapi.json` the Rust server reads.
|
|
30
|
-
*/
|
|
31
|
-
export function createEngine(
|
|
32
|
-
mod: RastackWasmModule,
|
|
33
|
-
manifest: object | string,
|
|
34
|
-
openapi?: object | string,
|
|
35
|
-
): RastackEngine {
|
|
36
|
-
const manifestJson =
|
|
37
|
-
typeof manifest === "string" ? manifest : JSON.stringify(manifest);
|
|
38
|
-
const openapiJson =
|
|
39
|
-
openapi === undefined
|
|
40
|
-
? undefined
|
|
41
|
-
: typeof openapi === "string"
|
|
42
|
-
? openapi
|
|
43
|
-
: JSON.stringify(openapi);
|
|
44
|
-
return new mod.RastackApi(manifestJson, openapiJson);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const MUTATING = new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* An axios adapter that dispatches requests into the in-browser WASM engine
|
|
51
|
-
* instead of over the network. Translates an axios request into the engine's
|
|
52
|
-
* `handle(method, path, query, body)` and maps the `{ status, body }` result
|
|
53
|
-
* back to an `AxiosResponse` — rejecting on non-2xx exactly as HTTP axios does,
|
|
54
|
-
* so `react-query` error handling is unchanged.
|
|
55
|
-
*
|
|
56
|
-
* `onWrite` fires after each successful mutation so the provider can debounce a
|
|
57
|
-
* persist of the warehouse.
|
|
58
|
-
*/
|
|
59
|
-
export function createWasmAdapter(
|
|
60
|
-
engine: RastackEngine,
|
|
61
|
-
onWrite?: () => void,
|
|
62
|
-
): AxiosAdapter {
|
|
63
|
-
return async (config: any): Promise<AxiosResponse> => {
|
|
64
|
-
const method = String(config.method || "get").toUpperCase();
|
|
65
|
-
|
|
66
|
-
const rawUrl = config.url || "";
|
|
67
|
-
const [rawPath, rawQuery] = rawUrl.split("?");
|
|
68
|
-
// Strip any origin so only the `/api/...` path reaches the engine.
|
|
69
|
-
const path = rawPath.replace(/^https?:\/\/[^/]+/i, "") || "/";
|
|
70
|
-
|
|
71
|
-
const query: Record<string, string> = {};
|
|
72
|
-
if (rawQuery) {
|
|
73
|
-
new URLSearchParams(rawQuery).forEach((value, key) => {
|
|
74
|
-
query[key] = value;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
if (config.params && typeof config.params === "object") {
|
|
78
|
-
for (const [key, value] of Object.entries(config.params)) {
|
|
79
|
-
if (value !== undefined && value !== null) query[key] = String(value);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// axios has already run transformRequest, so JSON bodies arrive as strings.
|
|
84
|
-
let body: unknown;
|
|
85
|
-
if (typeof config.data === "string" && config.data.length > 0) {
|
|
86
|
-
try {
|
|
87
|
-
body = JSON.parse(config.data);
|
|
88
|
-
} catch {
|
|
89
|
-
body = config.data;
|
|
90
|
-
}
|
|
91
|
-
} else if (config.data && typeof config.data === "object") {
|
|
92
|
-
body = config.data;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const result = await engine.handle(
|
|
96
|
-
method,
|
|
97
|
-
path,
|
|
98
|
-
Object.keys(query).length ? query : undefined,
|
|
99
|
-
body,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
const response: AxiosResponse = {
|
|
103
|
-
data: result.body,
|
|
104
|
-
status: result.status,
|
|
105
|
-
statusText: String(result.status),
|
|
106
|
-
headers: {},
|
|
107
|
-
config,
|
|
108
|
-
request: null,
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const validate =
|
|
112
|
-
config.validateStatus || ((s: number) => s >= 200 && s < 300);
|
|
113
|
-
if (!validate(result.status)) {
|
|
114
|
-
throw new AxiosError(
|
|
115
|
-
`Request failed with status code ${result.status}`,
|
|
116
|
-
result.status >= 500 ? "ERR_BAD_RESPONSE" : "ERR_BAD_REQUEST",
|
|
117
|
-
config,
|
|
118
|
-
null,
|
|
119
|
-
response,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (MUTATING.has(method) && onWrite) onWrite();
|
|
124
|
-
return response;
|
|
125
|
-
};
|
|
126
|
-
}
|
package/scripts/copy-wasm.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Copy the prebuilt WASM engine (`tools/wasm/`, produced by
|
|
4
|
-
* `rastack-wasm-build.js`) into the published package at `dist/wasm/`, so
|
|
5
|
-
* `rastack dev` serves it from any repo with no cargo. A no-op when no bundle
|
|
6
|
-
* has been built yet (a normal `pnpm build` on a machine without the Rust
|
|
7
|
-
* toolchain), so ordinary builds still succeed — the release CI builds the
|
|
8
|
-
* engine before this runs, and `rastack dev` has a from-source fallback.
|
|
9
|
-
*/
|
|
10
|
-
const fs = require("fs");
|
|
11
|
-
const path = require("path");
|
|
12
|
-
|
|
13
|
-
const root = path.join(__dirname, "..");
|
|
14
|
-
const src = path.join(root, "wasm");
|
|
15
|
-
const dest = path.join(root, "dist", "wasm");
|
|
16
|
-
const entry = path.join(src, "rastack_wasm.js");
|
|
17
|
-
|
|
18
|
-
if (!fs.existsSync(entry)) {
|
|
19
|
-
console.log(
|
|
20
|
-
"copy-wasm: no prebuilt engine at wasm/ (skipping — build it with " +
|
|
21
|
-
"rastack-wasm-build.js to ship it).",
|
|
22
|
-
);
|
|
23
|
-
process.exit(0);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
27
|
-
let n = 0;
|
|
28
|
-
for (const name of fs.readdirSync(src)) {
|
|
29
|
-
const from = path.join(src, name);
|
|
30
|
-
if (fs.statSync(from).isFile()) {
|
|
31
|
-
fs.copyFileSync(from, path.join(dest, name));
|
|
32
|
-
n++;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
console.log(`copy-wasm: copied ${n} file(s) into dist/wasm`);
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Compile the Rust API to WebAssembly for in-browser local dev — the engine
|
|
5
|
-
* `rastack dev` serves and `<RAStackProvider mode="local">` loads.
|
|
6
|
-
*
|
|
7
|
-
* Pipeline:
|
|
8
|
-
* 1. cargo build -p rastack-wasm --release --target wasm32-unknown-unknown
|
|
9
|
-
* 2. wasm-bindgen --target web → wasm/rastack_wasm.js + rastack_wasm_bg.wasm
|
|
10
|
-
* 3. wasm-opt -Oz (if available) to shrink the binary
|
|
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:
|
|
15
|
-
* rustup target add wasm32-unknown-unknown
|
|
16
|
-
* cargo install wasm-bindgen-cli (version must match the wasm-bindgen crate)
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { spawnSync } from "child_process";
|
|
20
|
-
import fs from "fs";
|
|
21
|
-
import path from "path";
|
|
22
|
-
|
|
23
|
-
const repoRoot = path.resolve(__dirname, "..");
|
|
24
|
-
const rustDir = path.join(repoRoot, "engine");
|
|
25
|
-
const outDir = path.join(repoRoot, "wasm");
|
|
26
|
-
const wasmPath = path.join(
|
|
27
|
-
rustDir,
|
|
28
|
-
"target",
|
|
29
|
-
"wasm32-unknown-unknown",
|
|
30
|
-
"release",
|
|
31
|
-
"rastack_wasm.wasm",
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
function run(cmd: string, args: string[], cwd = repoRoot): void {
|
|
35
|
-
// Local build tool: `cmd`/`args` are the fixed toolchain invocations below
|
|
36
|
-
// (cargo, wasm-bindgen, wasm-opt), not untrusted input — no injection surface.
|
|
37
|
-
// nosemgrep: javascript.lang.security.detect-child-process.detect-child-process
|
|
38
|
-
const result = spawnSync(cmd, args, {
|
|
39
|
-
stdio: "inherit",
|
|
40
|
-
cwd,
|
|
41
|
-
env: process.env,
|
|
42
|
-
});
|
|
43
|
-
if (result.error) {
|
|
44
|
-
console.error(`\nCould not run \`${cmd}\`. Is it installed and on PATH?`);
|
|
45
|
-
if (cmd === "wasm-bindgen") {
|
|
46
|
-
console.error(" cargo install wasm-bindgen-cli");
|
|
47
|
-
}
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
if (result.status !== 0) {
|
|
51
|
-
process.exit(result.status ?? 1);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function has(cmd: string): boolean {
|
|
56
|
-
// Probes a fixed toolchain name (e.g. "wasm-opt") for availability; not
|
|
57
|
-
// untrusted input.
|
|
58
|
-
// nosemgrep: javascript.lang.security.detect-child-process.detect-child-process
|
|
59
|
-
return spawnSync(cmd, ["--version"], { stdio: "ignore" }).status === 0;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Run the full compile → wasm-bindgen → optimise pipeline. Throws via `run`'s
|
|
63
|
-
* `process.exit` on a missing tool or a non-zero step. */
|
|
64
|
-
export function buildWasm(): void {
|
|
65
|
-
console.log(
|
|
66
|
-
"→ cargo build -p rastack-wasm --release (wasm32-unknown-unknown)",
|
|
67
|
-
);
|
|
68
|
-
run(
|
|
69
|
-
"cargo",
|
|
70
|
-
[
|
|
71
|
-
"build",
|
|
72
|
-
"-p",
|
|
73
|
-
"rastack-wasm",
|
|
74
|
-
"--release",
|
|
75
|
-
"--target",
|
|
76
|
-
"wasm32-unknown-unknown",
|
|
77
|
-
],
|
|
78
|
-
rustDir,
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
console.log("→ wasm-bindgen → wasm/");
|
|
82
|
-
run("wasm-bindgen", [
|
|
83
|
-
"--target",
|
|
84
|
-
"web",
|
|
85
|
-
"--out-dir",
|
|
86
|
-
outDir,
|
|
87
|
-
"--out-name",
|
|
88
|
-
"rastack_wasm",
|
|
89
|
-
wasmPath,
|
|
90
|
-
]);
|
|
91
|
-
|
|
92
|
-
// Mark the emitted bundle as ESM so Node and bundlers treat it correctly
|
|
93
|
-
// without forcing the parent rastack package to be a module.
|
|
94
|
-
fs.writeFileSync(
|
|
95
|
-
path.join(outDir, "package.json"),
|
|
96
|
-
JSON.stringify({ type: "module", sideEffects: false }, null, 2) + "\n",
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
if (has("wasm-opt")) {
|
|
100
|
-
console.log("→ wasm-opt -Oz");
|
|
101
|
-
const bg = path.join(outDir, "rastack_wasm_bg.wasm");
|
|
102
|
-
run("wasm-opt", ["-Oz", "-o", bg, bg]);
|
|
103
|
-
} else {
|
|
104
|
-
console.log("· wasm-opt not found — skipping size optimisation (optional)");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const size = fs.statSync(path.join(outDir, "rastack_wasm_bg.wasm")).size;
|
|
108
|
-
console.log(`✓ wasm engine built: wasm/ (${(size / 1024).toFixed(0)} KB)`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (require.main === module) {
|
|
112
|
-
buildWasm();
|
|
113
|
-
}
|