Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules/
.git/
*.log*
.env*
coverage/
target/
dist/
build/
.venv/
.Rhistory
.RData
.Ruserdata
.Rproj.user/
18 changes: 17 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ app/src/pages/metapop/cached-baseline.json
# Rust
target/

# R
.Rproj.user/
.Rhistory
.RData
.Ruserdata
*.Rproj
packrat/
renv/

# Scaffolded test projects
test-project-python/
test-project-rust/
Expand All @@ -51,7 +60,14 @@ cfasim-ui/docs/*
!cfasim-ui/docs/vitest.config.ts
!cfasim-ui/docs/drift.test.ts

/CLAUDE.md
.vscode/*
.DS_Store
.cache/

# ai + spec kit
/CLAUDE.md
/AGENTS.md
/specs
/.codex
/.agents
/.specify
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ cfasim-ui/docs/charts/
cfasim-ui/docs/shared/
cfasim-ui/docs/pyodide/
cfasim-ui/docs/wasm/
cfasim-ui/docs/rwasm/
cfasim-ui/docs/theme/
8 changes: 8 additions & 0 deletions cfasim-model-r/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Package: cfasim
Title: cfasim Model Helpers
Version: 0.3.14
Description: Minimal R helpers for returning cfasim model outputs.
License: Apache License (>= 2)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
7 changes: 7 additions & 0 deletions cfasim-model-r/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export(bool)
export(enum)
export(f64)
export(i32)
export(model_output)
export(model_outputs)
export(u32)
54 changes: 54 additions & 0 deletions cfasim-model-r/R/model-output.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
f64 <- function(x) {
list(type = "f64", values = as.numeric(x))
}

i32 <- function(x) {
list(type = "i32", values = as.integer(x))
}

u32 <- function(x) {
list(type = "u32", values = as.integer(x))
}

bool <- function(x) {
list(type = "bool", values = as.logical(x))
}

enum <- function(indices, labels) {
list(
type = "enum",
values = as.integer(indices),
enumLabels = as.character(labels)
)
}

model_output <- function(...) {
columns <- list(...)
data <- unname(lapply(columns, function(col) col$values))
lengths <- vapply(data, length, integer(1))
if (length(lengths) > 0 && length(unique(lengths)) != 1) {
stop("cfasim model output columns must have equal length")
}

descriptors <- unname(Map(
function(name, col) {
descriptor <- list(name = name, type = col$type)
if (!is.null(col$enumLabels)) {
descriptor$enumLabels <- col$enumLabels
}
descriptor
},
names(columns),
columns
))

list(
length = if (length(lengths) == 0) 0 else lengths[[1]],
columns = descriptors,
data = data
)
}

model_outputs <- function(...) {
list(`__modelOutputs` = TRUE, outputs = list(...))
}
3 changes: 3 additions & 0 deletions cfasim-ui/cfasim-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"./wasm/vite": "./src/wasm-vite.js",
"./pyodide": "./src/pyodide.ts",
"./pyodide/vite": "./src/pyodide-vite.js",
"./rwasm": "./src/rwasm.ts",
"./rwasm/vite": "./src/rwasm-vite.js",
"./shared": "./src/shared.ts",
"./theme": {
"default": "./src/theme/cfasim.css"
Expand All @@ -49,6 +51,7 @@
"@cfasim-ui/docs": "workspace:*",
"@cfasim-ui/wasm": "workspace:*",
"@cfasim-ui/pyodide": "workspace:*",
"@cfasim-ui/rwasm": "workspace:*",
"@cfasim-ui/shared": "workspace:*",
"@cfasim-ui/theme": "workspace:*"
},
Expand Down
1 change: 1 addition & 0 deletions cfasim-ui/cfasim-ui/src/rwasm-vite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "@cfasim-ui/rwasm/vite";
12 changes: 12 additions & 0 deletions cfasim-ui/cfasim-ui/src/rwasm.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, it } from "vitest";
import { existsSync } from "node:fs";
import { resolve } from "node:path";

const root = resolve(import.meta.dirname, "..");

describe("cfasim-ui rwasm subpaths", () => {
it("defines unified runtime and vite re-exports", () => {
expect(existsSync(resolve(root, "src/rwasm.ts"))).toBe(true);
expect(existsSync(resolve(root, "src/rwasm-vite.js"))).toBe(true);
});
});
1 change: 1 addition & 0 deletions cfasim-ui/cfasim-ui/src/rwasm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "@cfasim-ui/rwasm";
4 changes: 4 additions & 0 deletions cfasim-ui/docs/drift.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe("@cfasim-ui/docs generator", () => {
);
const entries = [...index.content.components, ...index.content.charts];
expect(entries.length).toBeGreaterThan(0);
expect(existsSync(resolve(PACKAGE_ROOT, "rwasm/index.ts"))).toBe(true);
expect(
readFileSync(resolve(PACKAGE_ROOT, "rwasm/vitePlugin.js"), "utf-8"),
).toContain("cfasim-model-r");

for (const entry of entries) {
for (const field of ["docs", "source"] as const) {
Expand Down
1 change: 1 addition & 0 deletions cfasim-ui/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"shared",
"pyodide",
"wasm",
"rwasm",
"theme"
]
}
36 changes: 36 additions & 0 deletions cfasim-ui/rwasm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@cfasim-ui/rwasm",
"version": "0.3.14",
"type": "module",
"description": "R/WebAssembly integration for cfasim-ui",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/CDCgov/cfa-simulator.git",
"directory": "cfasim-ui/rwasm"
},
"publishConfig": {
"access": "public"
},
"files": [
"src"
],
"scripts": {
"test": "vitest run"
},
"exports": {
".": "./src/index.ts",
"./vite": "./src/vitePlugin.js"
},
"dependencies": {
"@cfasim-ui/shared": "workspace:*",
"webr": "^0.5.5"
},
"peerDependencies": {
"vue": "^3.5.0"
},
"devDependencies": {
"happy-dom": "^20.8.9",
"vitest": "^4.1.0"
}
}
10 changes: 10 additions & 0 deletions cfasim-ui/rwasm/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expect, it } from "vitest";
import * as api from "./index.js";

describe("@cfasim-ui/rwasm exports", () => {
it("exports runtime API", () => {
expect(api.loadModel).toBeTypeOf("function");
expect(api.runR).toBeTypeOf("function");
expect(api.useModel).toBeTypeOf("function");
});
});
11 changes: 11 additions & 0 deletions cfasim-ui/rwasm/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export {
createRwasmWorkerClient,
loadModel,
runR,
type JsonValue,
type RRunOptions,
type RwasmBundleManifest,
type RWorkerRequest,
type RWorkerResponse,
} from "./rwasmWorkerApi.js";
export { useModel } from "./useModel.js";
Loading
Loading