convex-rust 0.0.0-stage → 0.1.1
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/LICENSE +201 -0
- package/README.md +137 -2
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.js +200 -0
- package/dist/cli/build.d.ts +146 -0
- package/dist/cli/build.js +902 -0
- package/dist/cli/demangle.d.ts +7 -0
- package/dist/cli/demangle.js +328 -0
- package/dist/cli/diagnostics.d.ts +34 -0
- package/dist/cli/diagnostics.js +296 -0
- package/dist/cli/generate.d.ts +29 -0
- package/dist/cli/generate.js +82 -0
- package/dist/cli/manifest.d.ts +24 -0
- package/dist/cli/manifest.js +75 -0
- package/dist/cli/rustApi.d.ts +78 -0
- package/dist/cli/rustApi.js +609 -0
- package/dist/cli/scaffold.d.ts +22 -0
- package/dist/cli/scaffold.js +114 -0
- package/dist/cli/shim.d.ts +30 -0
- package/dist/cli/shim.js +140 -0
- package/dist/cli/size.d.ts +17 -0
- package/dist/cli/size.js +73 -0
- package/dist/cli/split.d.ts +20 -0
- package/dist/cli/split.js +140 -0
- package/dist/cli/symbols.d.ts +30 -0
- package/dist/cli/symbols.js +133 -0
- package/dist/cli/toolchain.d.ts +53 -0
- package/dist/cli/toolchain.js +167 -0
- package/dist/cli/validators.d.ts +6 -0
- package/dist/cli/validators.js +66 -0
- package/dist/cli/wasisdk.d.ts +82 -0
- package/dist/cli/wasisdk.js +220 -0
- package/dist/cli/wasmHints.d.ts +29 -0
- package/dist/cli/wasmHints.js +172 -0
- package/dist/runtime/base64.d.ts +4 -0
- package/dist/runtime/base64.js +77 -0
- package/dist/runtime/crypto.d.ts +7 -0
- package/dist/runtime/crypto.js +421 -0
- package/dist/runtime/fastjson.d.ts +3 -0
- package/dist/runtime/fastjson.js +170 -0
- package/dist/runtime/host.d.ts +73 -0
- package/dist/runtime/host.js +1230 -0
- package/dist/runtime/http.d.ts +40 -0
- package/dist/runtime/http.js +157 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/intl.d.ts +5 -0
- package/dist/runtime/intl.js +69 -0
- package/dist/runtime/tmpfs.d.ts +129 -0
- package/dist/runtime/tmpfs.js +624 -0
- package/dist/runtime/wasi.d.ts +33 -0
- package/dist/runtime/wasi.js +216 -0
- package/package.json +66 -4
- package/rust/convex_fn/Cargo.toml +32 -0
- package/rust/convex_fn/LICENSE +201 -0
- package/rust/convex_fn/build.rs +3 -0
- package/rust/convex_fn/src/args.rs +416 -0
- package/rust/convex_fn/src/crypto.rs +237 -0
- package/rust/convex_fn/src/ctx.rs +1044 -0
- package/rust/convex_fn/src/dns.rs +356 -0
- package/rust/convex_fn/src/error.rs +179 -0
- package/rust/convex_fn/src/executor.rs +577 -0
- package/rust/convex_fn/src/fanout.rs +106 -0
- package/rust/convex_fn/src/fs.rs +19 -0
- package/rust/convex_fn/src/function_ref.rs +219 -0
- package/rust/convex_fn/src/http.rs +441 -0
- package/rust/convex_fn/src/intl.rs +75 -0
- package/rust/convex_fn/src/lib.rs +242 -0
- package/rust/convex_fn/src/logging.rs +222 -0
- package/rust/convex_fn/src/native.rs +360 -0
- package/rust/convex_fn/src/net.rs +122 -0
- package/rust/convex_fn/src/sys.rs +178 -0
- package/rust/convex_fn/src/values.rs +121 -0
- package/rust/convex_fn/src/wire.rs +579 -0
- package/rust/convex_fn_macros/Cargo.toml +13 -0
- package/rust/convex_fn_macros/LICENSE +201 -0
- package/rust/convex_fn_macros/src/derive.rs +632 -0
- package/rust/convex_fn_macros/src/lib.rs +338 -0
- package/rust/convex_reqwest/Cargo.toml +69 -0
- package/rust/convex_reqwest/LICENSE +201 -0
- package/rust/convex_reqwest/src/blocking.rs +287 -0
- package/rust/convex_reqwest/src/body.rs +152 -0
- package/rust/convex_reqwest/src/client.rs +359 -0
- package/rust/convex_reqwest/src/config_types.rs +150 -0
- package/rust/convex_reqwest/src/error.rs +241 -0
- package/rust/convex_reqwest/src/into_url.rs +57 -0
- package/rust/convex_reqwest/src/lib.rs +42 -0
- package/rust/convex_reqwest/src/multipart.rs +140 -0
- package/rust/convex_reqwest/src/request.rs +358 -0
- package/rust/convex_reqwest/src/response.rs +310 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { RustManifestEntry } from "./manifest.js";
|
|
2
|
+
import { WasiSdkMode } from "./wasisdk.js";
|
|
3
|
+
export type Profile = "dev" | "release";
|
|
4
|
+
export interface BuildOptions {
|
|
5
|
+
/** Project root (default: cwd). */
|
|
6
|
+
cwd: string;
|
|
7
|
+
/** Crate directory (default `<functions>/rust`). */
|
|
8
|
+
crate?: string;
|
|
9
|
+
/** Output directory (default `<functions>/rust`). */
|
|
10
|
+
out?: string;
|
|
11
|
+
profile: Profile;
|
|
12
|
+
/** Env var names the guest may read (emitted into the wrappers). */
|
|
13
|
+
env?: string[];
|
|
14
|
+
/** Compile with `-C target-feature=+simd128` (default true; `--no-simd` / `CONVEX_RUST_SIMD=0` opt out). */
|
|
15
|
+
simd?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* One wasm per Convex module (`--split` / `CONVEX_RUST_SPLIT=1`): wasm-opt drops the code only the other
|
|
18
|
+
* modules need, so each action loads (and the platform compiles, on every call) less. Needs wasm-opt.
|
|
19
|
+
*/
|
|
20
|
+
split?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Module groups (`--group name=modA,modB`): the crate is built once per group with
|
|
23
|
+
* `--no-default-features --features <prefix><module>,...` (see {@link GROUP_FEATURE_PREFIX}), so a group's
|
|
24
|
+
* wasm contains only its modules' functions and dependencies. Each module imports its group's wasm.
|
|
25
|
+
*/
|
|
26
|
+
groups?: ModuleGroup[];
|
|
27
|
+
/** Cargo feature name prefix for the group builds (default `m-`). */
|
|
28
|
+
groupFeaturePrefix?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Default true: with no explicit groups, build one wasm per Convex module: through the crate's `m-<module>`
|
|
31
|
+
* features when it defines two or more (see {@link modulesFromFeatures}), else zero-config through the
|
|
32
|
+
* `#[action]` macro's `convex_split` cfg (see {@link splitRustcArgs}). `false` (`--single` / `CONVEX_RUST_MODULES=0`)
|
|
33
|
+
* builds one shared wasm with the default features. The zero-config split (no `m-` features) is skipped in the
|
|
34
|
+
* dev profile (`convex-rust dev`: ~8x slower rebuilds) unless this is `true` (`--modules` / `CONVEX_RUST_MODULES=1`).
|
|
35
|
+
*/
|
|
36
|
+
perModule?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* C compiler for crates that build C code: "auto" (default) uses a wasi-sdk found via `WASI_SDK_PATH` or the cache dir
|
|
39
|
+
* and downloads one only when a dependency has a C build script; "always" downloads it; "never" leaves cc-rs alone.
|
|
40
|
+
*/
|
|
41
|
+
wasiSdk?: WasiSdkMode;
|
|
42
|
+
/** Total wasm size above which the smallest zero-config modules are merged (default {@link WASM_BUDGET_BYTES}). */
|
|
43
|
+
wasmBudget?: number;
|
|
44
|
+
log?: (msg: string) => void;
|
|
45
|
+
}
|
|
46
|
+
export declare class BuildError extends Error {
|
|
47
|
+
}
|
|
48
|
+
export interface ModuleGroup {
|
|
49
|
+
name: string;
|
|
50
|
+
/** Convex module names (`cpu`, `a/b`). */
|
|
51
|
+
modules: string[];
|
|
52
|
+
}
|
|
53
|
+
export declare const GROUP_FEATURE_PREFIX = "m-";
|
|
54
|
+
/** Parses `--group name=modA,modB` values. Throws {@link BuildError} on a malformed or overlapping spec. */
|
|
55
|
+
export declare function parseGroups(specs: string[]): ModuleGroup[];
|
|
56
|
+
/**
|
|
57
|
+
* Convex module names for the crate's `<prefix><module>` features (`m-a-b` -> `a/b`: Rust module names have
|
|
58
|
+
* no dashes, so a dash is a path separator). Sorted; empty when the crate has fewer than two such features
|
|
59
|
+
* (one feature gates nothing worth splitting).
|
|
60
|
+
*/
|
|
61
|
+
export declare function modulesFromFeatures(features: string[], prefix?: string): string[];
|
|
62
|
+
/** File-name stem of a module's wasm: the module with `/` as `__`. */
|
|
63
|
+
export declare function moduleFileName(module: string): string;
|
|
64
|
+
/** Rejects modules whose wasm file names collide (`a/b` and a real module `a__b` would overwrite each other). */
|
|
65
|
+
export declare function assertDistinctFileNames(modules: Iterable<string>): void;
|
|
66
|
+
/** One group per module; the group (file) name is the module with `/` as `__`. */
|
|
67
|
+
export declare function perModuleGroups(modules: string[]): ModuleGroup[];
|
|
68
|
+
/** Cargo feature args that build only a group's modules. Module `a/b` maps to feature `<prefix>a-b`. */
|
|
69
|
+
export declare function groupFeatureArgs(group: ModuleGroup, prefix?: string): string[];
|
|
70
|
+
/** Wasm size budget for all per-module wasm together: Convex bundles at most 32 MiB of code per deployment. */
|
|
71
|
+
export declare const WASM_BUDGET_BYTES: number;
|
|
72
|
+
/**
|
|
73
|
+
* Zero-config per-module build: the extra `rustc` arguments (after `cargo rustc ... --`) that make the
|
|
74
|
+
* `#[action]` macro keep only the exports of `fns` (see `crates/convex_fn_macros`). `--check-cfg` keeps
|
|
75
|
+
* the `unexpected_cfgs` lint quiet for crates that do not otherwise declare these cfgs.
|
|
76
|
+
*/
|
|
77
|
+
export declare function splitRustcArgs(fns: string[]): string[];
|
|
78
|
+
/** The two smallest entries of `sizes` (the next merge candidates when over the size budget), or undefined. */
|
|
79
|
+
export declare function smallestTwo(sizes: Map<string, number>): [string, string] | undefined;
|
|
80
|
+
/** Convex functions directory: `functions` in convex.json, default `convex`. */
|
|
81
|
+
export declare function resolveFunctionsDir(cwd: string): string;
|
|
82
|
+
export declare function cargoProfileDir(profile: Profile): string;
|
|
83
|
+
/** Cargo args and env for a profile; the dev profile is defined via env. */
|
|
84
|
+
export declare function cargoBuildConfig(profile: Profile): {
|
|
85
|
+
args: string[];
|
|
86
|
+
env: Record<string, string>;
|
|
87
|
+
};
|
|
88
|
+
/** Rust flag pair that turns on wasm SIMD. */
|
|
89
|
+
export declare const SIMD_RUSTFLAG = "target-feature=+simd128";
|
|
90
|
+
/**
|
|
91
|
+
* Extra cargo args / env for the SIMD option. With RUSTFLAGS (or CARGO_ENCODED_RUSTFLAGS) set the flag is
|
|
92
|
+
* appended to it; otherwise it goes in as `--config target.<triple>.rustflags`, which cargo joins with the
|
|
93
|
+
* rustflags of every `.cargo/config.toml` `target.<triple>.rustflags` (a config `build.rustflags` is then
|
|
94
|
+
* shadowed, as for any target-specific rustflags).
|
|
95
|
+
*/
|
|
96
|
+
export declare function simdCargoConfig(simd: boolean, env?: Record<string, string | undefined>): {
|
|
97
|
+
args: string[];
|
|
98
|
+
env: Record<string, string>;
|
|
99
|
+
};
|
|
100
|
+
/** Cargo target directory and library name of the crate, via `cargo metadata`. */
|
|
101
|
+
export declare function findCrateLayout(crateDir: string): Promise<{
|
|
102
|
+
targetDir: string;
|
|
103
|
+
libName: string;
|
|
104
|
+
features: string[];
|
|
105
|
+
}>;
|
|
106
|
+
/** Crates of the wasm32-wasip1 dependency graph whose build script drives a C compiler (`cc` / `cmake`). */
|
|
107
|
+
export declare function cBuildCrates(crateDir: string): Promise<string[]>;
|
|
108
|
+
export declare function wasmOptFlags(): string[];
|
|
109
|
+
/**
|
|
110
|
+
* `wasm-opt -O3` when available, with a content-addressed cache in
|
|
111
|
+
* `cacheDir`. Returns the bytes to ship (the input when wasm-opt is missing,
|
|
112
|
+
* fails, does not shrink the module or drops the manifest). `onNames` receives the function names
|
|
113
|
+
* (index in the returned module -> raw name) for the symbol map.
|
|
114
|
+
*/
|
|
115
|
+
export declare function optimizeWasm(input: Uint8Array, cacheDir: string, log?: (m: string) => void, onNames?: (names: Map<number, string>) => void): Uint8Array;
|
|
116
|
+
/** The stock bundler walks every file of the functions directory; cargo output there is a hazard. */
|
|
117
|
+
export declare function warnIfTargetInsideFunctions(targetDir: string, functionsDir: string, log: (m: string) => void): void;
|
|
118
|
+
export interface WriteResult {
|
|
119
|
+
written: string[];
|
|
120
|
+
removed: string[];
|
|
121
|
+
}
|
|
122
|
+
/** Writes the generated files and the wasm; removes stale generated files. */
|
|
123
|
+
export declare function writeOutput(outDir: string, wasmFile: string, wasm: Uint8Array, entries: RustManifestEntry[], functionsDir: string, env?: string[], split?: Map<string, Uint8Array>, grouped?: {
|
|
124
|
+
wasm: Map<string, Uint8Array>;
|
|
125
|
+
moduleGroup: Map<string, string>;
|
|
126
|
+
}): WriteResult;
|
|
127
|
+
export interface BuildResult extends WriteResult {
|
|
128
|
+
wasmFile: string;
|
|
129
|
+
functions: string[];
|
|
130
|
+
outDir: string;
|
|
131
|
+
}
|
|
132
|
+
/** Builds the crate and writes the generated files. Throws {@link BuildError}. */
|
|
133
|
+
export declare function buildOnce(opts: BuildOptions): Promise<BuildResult>;
|
|
134
|
+
/** Should a change to this crate-relative path trigger a rebuild? */
|
|
135
|
+
export declare function isWatchedChange(relPath: string): boolean;
|
|
136
|
+
/** Should a change to this functions-dir-relative path re-run the api.rs codegen? */
|
|
137
|
+
export declare function isTsSourceChange(relPath: string): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Initial build, then rebuild on changes to the crate sources (and re-run the api.rs codegen on
|
|
140
|
+
* TypeScript changes). Events are debounced, and only a real content change versus the state
|
|
141
|
+
* after the last build triggers a rebuild, so the build's own writes (Cargo.lock, the managed
|
|
142
|
+
* config block, api.rs) never loop. Never resolves.
|
|
143
|
+
*/
|
|
144
|
+
export declare function watch(opts: BuildOptions): Promise<never>;
|
|
145
|
+
/** Regenerates only `src/_generated/api.rs` (no cargo). Needs a previous build for the Rust functions. */
|
|
146
|
+
export declare function codegenOnly(opts: BuildOptions): Promise<boolean>;
|