instant_record 0.1.0 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +58 -0
- data/README.md +267 -61
- data/app/controllers/instant_record/bootstraps_controller.rb +39 -12
- data/app/controllers/instant_record/events_controller.rb +58 -6
- data/app/controllers/instant_record/files_controller.rb +116 -0
- data/app/controllers/instant_record/mutations_controller.rb +84 -5
- data/app/controllers/instant_record/native_screens_controller.rb +60 -0
- data/app/controllers/instant_record/records_controller.rb +86 -8
- data/app/controllers/instant_record/shells_controller.rb +64 -0
- data/app/controllers/instant_record/sync_notices_controller.rb +81 -0
- data/app/helpers/instant_record/sync_notices_helper.rb +41 -0
- data/app/jobs/instant_record/shell_build_job.rb +16 -0
- data/app/models/instant_record/change.rb +36 -3
- data/app/models/instant_record/mutation_applier.rb +633 -50
- data/app/views/instant_record/sync_notices/_notices.html.erb +63 -0
- data/compiled/README.md +272 -0
- data/compiled/pipeline/browser_migrations.rb +18 -0
- data/compiled/pipeline/build.rb +13 -0
- data/compiled/pipeline/build_native.rb +14 -0
- data/compiled/pipeline/native/host.c +78 -0
- data/compiled/pipeline/native/instant_record_native.h +57 -0
- data/compiled/pipeline/native_shim.c +149 -0
- data/compiled/pipeline/reactor_shim.c +66 -0
- data/compiled/pipeline/sqlite/rh_shim.c +5 -0
- data/compiled/pipeline/sqlite_release.rb +43 -0
- data/compiled/toolchain.env.example +22 -0
- data/compiled/web/index.html +20 -0
- data/compiled/web/package-lock.json +884 -0
- data/compiled/web/package.json +17 -0
- data/compiled/web/src/app-host-core.js +556 -0
- data/compiled/web/src/app-host.js +16 -0
- data/compiled/web/src/branch-manager.js +140 -0
- data/compiled/web/src/branch-preview.js +397 -0
- data/compiled/web/src/changes.js +191 -0
- data/compiled/web/src/faults.js +172 -0
- data/compiled/web/src/flight-recorder.js +347 -0
- data/compiled/web/src/history-fill.js +68 -0
- data/compiled/web/src/http-headers.js +100 -0
- data/compiled/web/src/leader-election.js +705 -0
- data/compiled/web/src/main.js +608 -0
- data/compiled/web/src/manifest.js +112 -0
- data/compiled/web/src/opfs-wasi-core.js +109 -0
- data/compiled/web/src/opfs-wasi-file.js +8 -0
- data/compiled/web/src/reactor-runtime.js +1692 -0
- data/compiled/web/src/redactor.js +518 -0
- data/compiled/web/src/release-updates.js +48 -0
- data/compiled/web/src/replay.js +338 -0
- data/compiled/web/src/schema-recovery.js +204 -0
- data/compiled/web/src/server-request.js +68 -0
- data/compiled/web/src/sha256.js +98 -0
- data/compiled/web/src/shell.js +52 -0
- data/compiled/web/src/snapshot-store.js +38 -0
- data/compiled/web/src/sqlite-redactor.js +111 -0
- data/compiled/web/src/storage-backend.js +159 -0
- data/compiled/web/src/stream-leader.js +675 -0
- data/compiled/web/src/sync-context.js +91 -0
- data/compiled/web/src/sync-drain.js +104 -0
- data/compiled/web/src/sync-schedule.js +9 -0
- data/compiled/web/src/wasi-minimal.js +275 -0
- data/compiled/web/src/worker.js +39 -0
- data/compiled/web/vite.config.js +27 -0
- data/config/routes.rb +25 -0
- data/db/migrate/20261119000201_add_scope_to_instant_record_changes.rb +7 -0
- data/db/migrate/20261121000001_create_instant_record_sync_notices.rb +21 -0
- data/db/migrate/20261121000101_add_partition_to_instant_record_changes.rb +8 -0
- data/db/migrate/20261121230300_add_delay_line_to_instant_record_outbox.rb +10 -0
- data/exe/instant_record_mcp +6 -0
- data/frontend/LiveList.js +67 -0
- data/frontend/chord.js +79 -0
- data/frontend/file.js +65 -0
- data/frontend/files.js +738 -0
- data/frontend/focus.js +10 -0
- data/frontend/held.js +192 -0
- data/frontend/http.js +76 -0
- data/frontend/index.js +53 -0
- data/frontend/keyboard.js +56 -0
- data/frontend/live.js +298 -0
- data/frontend/notices.js +118 -0
- data/frontend/package.json +15 -0
- data/frontend/range.js +10 -0
- data/frontend/selection.js +47 -0
- data/frontend/shortcuts.js +25 -0
- data/frontend/sync-notices.js +130 -0
- data/frontend/undo.js +48 -0
- data/frontend/window.js +181 -0
- data/lib/generators/instant_record/install/install_generator.rb +18 -30
- data/lib/generators/instant_record/install/templates/instant_record.rb +34 -0
- data/lib/generators/instant_record/ios/ios_generator.rb +71 -0
- data/lib/generators/instant_record/ios/templates/App.swift.tt +35 -0
- data/lib/generators/instant_record/ios/templates/Info.plist +11 -0
- data/lib/generators/instant_record/ios/templates/LibraryEngine.swift +30 -0
- data/lib/instant_record/branch/sqlite_store.rb +142 -0
- data/lib/instant_record/branch.rb +388 -0
- data/lib/instant_record/client/notifier.rb +8 -12
- data/lib/instant_record/client/rebaser.rb +565 -0
- data/lib/instant_record/client/transport.rb +64 -42
- data/lib/instant_record/client.rb +1600 -169
- data/lib/instant_record/compiled_site.rb +85 -0
- data/lib/instant_record/compiler/app_stage.rb +212 -0
- data/lib/instant_record/compiler/ast_lowerer.rb +659 -0
- data/lib/instant_record/compiler/browser_migrations.rb +161 -0
- data/lib/instant_record/compiler/entry_builder.rb +832 -0
- data/lib/instant_record/compiler/fts5_smoke.rb +205 -0
- data/lib/instant_record/compiler/gem_vendor.rb +194 -0
- data/lib/instant_record/compiler/host_adapters.rb +506 -0
- data/lib/instant_record/compiler/kotlin_codegen.rb +209 -0
- data/lib/instant_record/compiler/manifest.rb +178 -0
- data/lib/instant_record/compiler/native_build.rb +586 -0
- data/lib/instant_record/compiler/native_contracts.rb +338 -0
- data/lib/instant_record/compiler/path_scrubber.rb +31 -0
- data/lib/instant_record/compiler/reachability_tracer.rb +1188 -0
- data/lib/instant_record/compiler/route_analyzer.rb +623 -0
- data/lib/instant_record/compiler/runner.rb +42 -0
- data/lib/instant_record/compiler/schema_lock.rb +606 -0
- data/lib/instant_record/compiler/source_pages.rb +77 -0
- data/lib/instant_record/compiler/static_linter.rb +770 -0
- data/lib/instant_record/compiler/swift_codegen.rb +341 -0
- data/lib/instant_record/compiler/toolchain.rb +219 -0
- data/lib/instant_record/compiler/wasm_build.rb +704 -0
- data/lib/instant_record/compiler/wasm_tree.rb +518 -0
- data/lib/instant_record/compiler.rb +277 -0
- data/lib/instant_record/configuration.rb +104 -0
- data/lib/instant_record/engine.rb +68 -18
- data/lib/instant_record/file_store.rb +162 -0
- data/lib/instant_record/files.rb +92 -0
- data/lib/instant_record/hlc.rb +387 -0
- data/lib/instant_record/host.rb +66 -0
- data/lib/instant_record/inertia/renderer.rb +52 -0
- data/lib/instant_record/inertia.rb +222 -0
- data/lib/instant_record/mcp/cli.rb +319 -0
- data/lib/instant_record/mcp/host_process.rb +229 -0
- data/lib/instant_record/mcp/http_exchange.rb +233 -0
- data/lib/instant_record/mcp/replica.rb +556 -0
- data/lib/instant_record/mcp/runtime.rb +406 -0
- data/lib/instant_record/mcp/server.rb +429 -0
- data/lib/instant_record/mcp.rb +47 -0
- data/lib/instant_record/native/contract.rb +367 -0
- data/lib/instant_record/native/node.rb +125 -0
- data/lib/instant_record/native/screen.rb +366 -0
- data/lib/instant_record/native/xcode_project.rb +344 -0
- data/lib/instant_record/native.rb +41 -0
- data/lib/instant_record/outbox_mutation.rb +81 -9
- data/lib/instant_record/outbox_upcaster.rb +161 -0
- data/lib/instant_record/read_tracker.rb +610 -0
- data/lib/instant_record/routing.rb +33 -0
- data/lib/instant_record/runtime_scoped.rb +4 -0
- data/lib/instant_record/shell.rb +486 -0
- data/lib/instant_record/sync_actions.rb +800 -0
- data/lib/instant_record/sync_metadata.rb +17 -2
- data/lib/instant_record/sync_notice.rb +234 -0
- data/lib/instant_record/sync_partition.rb +63 -0
- data/lib/instant_record/sync_scope.rb +300 -0
- data/lib/instant_record/sync_shape.rb +102 -0
- data/lib/instant_record/sync_window.rb +92 -15
- data/lib/instant_record/syncable.rb +313 -17
- data/lib/instant_record/testing/authoritative_server.rb +547 -0
- data/lib/instant_record/testing/chaos_simulator.rb +429 -0
- data/lib/instant_record/testing/cruby_host_bridge.rb +370 -0
- data/lib/instant_record/testing/fault_network.rb +140 -0
- data/lib/instant_record/testing/parity_suite.rb +435 -0
- data/lib/instant_record/testing/runtimes/base.rb +184 -0
- data/lib/instant_record/testing/runtimes/cruby_runtime.rb +255 -0
- data/lib/instant_record/testing/runtimes/native_runtime.rb +346 -0
- data/lib/instant_record/testing/runtimes/wasm_runtime.rb +371 -0
- data/lib/instant_record/testing/wasm_host_bridge.mjs +240 -0
- data/lib/instant_record/testing.rb +333 -0
- data/lib/instant_record/trace/redactor.rb +278 -0
- data/lib/instant_record/trace/replayer.rb +126 -0
- data/lib/instant_record/trace/schema_extractor.rb +37 -0
- data/lib/instant_record/trace.rb +22 -0
- data/lib/instant_record/version.rb +1 -1
- data/lib/instant_record.rb +107 -37
- data/lib/tasks/instant_record.rake +299 -47
- data/native/ios/InstantRecordNative/Package.swift +12 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/AppHost.swift +706 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Engine.swift +64 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/FileStore.swift +1048 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/HTTPEngine.swift +36 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Icons.swift +19 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Node.swift +64 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/ScreenView.swift +481 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Screens.swift +94 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/StreamClient.swift +74 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/SyncNotice.swift +282 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/SyncSchedule.swift +153 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Theme.swift +140 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Transport.swift +108 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/TypedContracts.swift +237 -0
- data/native/ios/README.md +341 -0
- data/sig/instant_record/inertia.rbs +47 -0
- data/sig/instant_record/native.rbs +38 -0
- metadata +194 -18
- data/lib/generators/instant_record/install/templates/database.js +0 -32
- data/lib/generators/instant_record/install/templates/index.html +0 -69
- data/lib/generators/instant_record/install/templates/rails.sw.js +0 -750
- data/lib/instant_record/local_schema.rb +0 -75
- data/lib/instant_record/pglite_compat.rb +0 -40
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Canonical manifest reader shared by the browser worker and page harness.
|
|
2
|
+
// Fed from `instant_record.manifest.json` via VITE_MANIFEST at build time.
|
|
3
|
+
|
|
4
|
+
export function normalizePath(pathname) {
|
|
5
|
+
let cleaned = String(pathname || "/").trim().replace(/\/+/g, "/");
|
|
6
|
+
if (!cleaned.startsWith("/")) cleaned = `/${cleaned}`;
|
|
7
|
+
return cleaned.length > 1 ? cleaned.replace(/\/+$/, "") : cleaned || "/";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function routePatternToRegex(pattern) {
|
|
11
|
+
const normalized = normalizePath(pattern).replace(/\([^)]*\)/g, "");
|
|
12
|
+
if (normalized === "/") return /^\/$/;
|
|
13
|
+
|
|
14
|
+
const segments = normalized.slice(1).split("/").filter(Boolean).map((segment) => {
|
|
15
|
+
if (segment.startsWith("*")) return ".+";
|
|
16
|
+
if (segment.startsWith(":")) return "[^/]+";
|
|
17
|
+
return segment
|
|
18
|
+
.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
19
|
+
.replace(/:[a-zA-Z_]\w*/g, "[^/]+");
|
|
20
|
+
});
|
|
21
|
+
return new RegExp(`^/${segments.join("/")}/?$`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function compileRoutes(routes) {
|
|
25
|
+
return (Array.isArray(routes) ? routes : [])
|
|
26
|
+
.filter((route) => route && route.path)
|
|
27
|
+
.map((route) => ({
|
|
28
|
+
method: String(route.method || "GET").toUpperCase(),
|
|
29
|
+
path: normalizePath(route.path),
|
|
30
|
+
controller: route.controller || null,
|
|
31
|
+
action: route.action || null,
|
|
32
|
+
regex: routePatternToRegex(route.path),
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function parseManifest(raw) {
|
|
37
|
+
let data = {};
|
|
38
|
+
if (typeof raw === "string" && raw.trim()) {
|
|
39
|
+
try {
|
|
40
|
+
data = JSON.parse(raw);
|
|
41
|
+
} catch {
|
|
42
|
+
data = {};
|
|
43
|
+
}
|
|
44
|
+
} else if (raw && typeof raw === "object") {
|
|
45
|
+
data = raw;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
schemaVersion: data.schema_version ?? 1,
|
|
50
|
+
mode: data.mode === "island" ? "island" : "full",
|
|
51
|
+
island: data.island ?? null,
|
|
52
|
+
models: Array.isArray(data.models) ? data.models : [],
|
|
53
|
+
localRoutes: compileRoutes(data.local_routes),
|
|
54
|
+
serverRoutes: compileRoutes(data.server_routes),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function matchesRoute(compiledRoutes, method, pathname) {
|
|
59
|
+
const verb = String(method || "GET").toUpperCase();
|
|
60
|
+
const normalized = normalizePath(pathname);
|
|
61
|
+
return compiledRoutes.some((route) => route.method === verb && route.regex.test(normalized));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function matchesAnyPath(compiledRoutes, pathname) {
|
|
65
|
+
const normalized = normalizePath(pathname);
|
|
66
|
+
return compiledRoutes.some((route) => route.regex.test(normalized));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function syncBasePath(syncEndpoint = "/instant_record") {
|
|
70
|
+
try {
|
|
71
|
+
return normalizePath(new URL(syncEndpoint, "http://instant-record.local").pathname);
|
|
72
|
+
} catch {
|
|
73
|
+
return normalizePath(syncEndpoint);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isLocalSyncNotices(pathname, syncEndpoint = "/instant_record") {
|
|
78
|
+
const normalized = normalizePath(pathname);
|
|
79
|
+
const noticesBase = `${syncBasePath(syncEndpoint)}/sync_notices`;
|
|
80
|
+
return normalized === noticesBase || normalized === `${noticesBase}.json` || normalized.startsWith(`${noticesBase}/`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Match a request against the island's local_routes.
|
|
84
|
+
// When `method` is provided:
|
|
85
|
+
// - GET/HEAD match GET routes.
|
|
86
|
+
// - POST matches POST, PATCH, PUT, or DELETE routes (Rails forms tunnel
|
|
87
|
+
// PATCH/PUT/DELETE over POST with a `_method` parameter).
|
|
88
|
+
// - Explicit PATCH/PUT/DELETE match their exact HTTP verb.
|
|
89
|
+
export function isLocalRoute(manifest, pathname, method = null, syncEndpoint = "/instant_record") {
|
|
90
|
+
if (!manifest || manifest.mode !== "island" || manifest.localRoutes.length === 0) return true;
|
|
91
|
+
if (isLocalSyncNotices(pathname, syncEndpoint)) return true;
|
|
92
|
+
if (!method) return matchesAnyPath(manifest.localRoutes, pathname);
|
|
93
|
+
|
|
94
|
+
const verb = String(method).toUpperCase();
|
|
95
|
+
if (verb === "HEAD") return matchesRoute(manifest.localRoutes, "GET", pathname);
|
|
96
|
+
if (verb === "POST") {
|
|
97
|
+
return ["POST", "PATCH", "PUT", "DELETE"].some((v) => matchesRoute(manifest.localRoutes, v, pathname));
|
|
98
|
+
}
|
|
99
|
+
return matchesRoute(manifest.localRoutes, verb, pathname);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function isServerAllowed(manifest, method, pathname, syncEndpoint = "/instant_record") {
|
|
103
|
+
const verb = String(method || "GET").toUpperCase();
|
|
104
|
+
const normalized = normalizePath(pathname);
|
|
105
|
+
const syncBase = syncBasePath(syncEndpoint);
|
|
106
|
+
|
|
107
|
+
if (verb === "GET" && normalized === `${syncBase}/bootstrap`) return true;
|
|
108
|
+
if (verb === "POST" && normalized === `${syncBase}/mutations`) return true;
|
|
109
|
+
|
|
110
|
+
if (!manifest || !Array.isArray(manifest.serverRoutes)) return false;
|
|
111
|
+
return matchesRoute(manifest.serverRoutes, verb, normalized);
|
|
112
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Core factory extending @bjorn3/browser_wasi_shim's SyncOPFSFile / OpenSyncOPFSFile
|
|
2
|
+
// with page-level WASI syscalls (fd_pread, fd_pwrite, fd_tell) and consistent inode
|
|
3
|
+
// stats required by SQLite's POSIX VFS without touching SQLite's C code.
|
|
4
|
+
//
|
|
5
|
+
// Kept dependency-free so unit tests run directly in Node without node_modules.
|
|
6
|
+
export function createPagedSyncOPFSClasses({ SyncOPFSFile, OpenSyncOPFSFile, wasi }) {
|
|
7
|
+
class PagedOpenSyncOPFSFile extends OpenSyncOPFSFile {
|
|
8
|
+
constructor(file) {
|
|
9
|
+
super(file);
|
|
10
|
+
// Match the parent inode so stat() (path_filestat_get) and fstat() (fd_filestat_get)
|
|
11
|
+
// agree on st_ino for SQLite's inode identity checks.
|
|
12
|
+
this.ino = file.ino;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
fd_filestat_get() {
|
|
16
|
+
return { ret: wasi.ERRNO_SUCCESS, filestat: this.file.stat() };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
fd_read(size) {
|
|
20
|
+
if (size <= 0) return { ret: wasi.ERRNO_SUCCESS, data: new Uint8Array(0) };
|
|
21
|
+
const buf = new Uint8Array(size);
|
|
22
|
+
const n = this.file.handle.read(buf, { at: Number(this.position) });
|
|
23
|
+
this.position += BigInt(n);
|
|
24
|
+
return { ret: wasi.ERRNO_SUCCESS, data: buf.subarray(0, n) };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fd_pread(size, offset) {
|
|
28
|
+
const pos = BigInt(offset);
|
|
29
|
+
if (pos < 0n) return { ret: wasi.ERRNO_INVAL, data: new Uint8Array(0) };
|
|
30
|
+
if (size <= 0) return { ret: wasi.ERRNO_SUCCESS, data: new Uint8Array(0) };
|
|
31
|
+
const buf = new Uint8Array(size);
|
|
32
|
+
const n = this.file.handle.read(buf, { at: Number(pos) });
|
|
33
|
+
return { ret: wasi.ERRNO_SUCCESS, data: buf.subarray(0, n) };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fd_pwrite(data, offset) {
|
|
37
|
+
if (this.file.readonly) return { ret: wasi.ERRNO_BADF, nwritten: 0 };
|
|
38
|
+
const pos = BigInt(offset);
|
|
39
|
+
if (pos < 0n) return { ret: wasi.ERRNO_INVAL, nwritten: 0 };
|
|
40
|
+
const n = this.file.handle.write(data, { at: Number(pos) });
|
|
41
|
+
return { ret: wasi.ERRNO_SUCCESS, nwritten: n };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fd_tell() {
|
|
45
|
+
return { ret: wasi.ERRNO_SUCCESS, offset: this.position };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fd_sync() {
|
|
49
|
+
this.file.handle.flush();
|
|
50
|
+
return wasi.ERRNO_SUCCESS;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
fd_close() {
|
|
54
|
+
// Keep the underlying SyncAccessHandle open while the Inode stays mounted.
|
|
55
|
+
return wasi.ERRNO_SUCCESS;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class PagedSyncOPFSFile extends SyncOPFSFile {
|
|
60
|
+
path_open(oflags, fs_rights_base, fd_flags) {
|
|
61
|
+
if (this.readonly && (BigInt(fs_rights_base) & BigInt(wasi.RIGHTS_FD_WRITE)) === BigInt(wasi.RIGHTS_FD_WRITE)) {
|
|
62
|
+
return { ret: wasi.ERRNO_PERM, fd_obj: null };
|
|
63
|
+
}
|
|
64
|
+
if ((oflags & wasi.OFLAGS_TRUNC) === wasi.OFLAGS_TRUNC) {
|
|
65
|
+
if (this.readonly) return { ret: wasi.ERRNO_PERM, fd_obj: null };
|
|
66
|
+
this.handle.truncate(0);
|
|
67
|
+
}
|
|
68
|
+
const file = new PagedOpenSyncOPFSFile(this);
|
|
69
|
+
if (fd_flags & wasi.FDFLAGS_APPEND) file.fd_seek(0n, wasi.WHENCE_END);
|
|
70
|
+
return { ret: wasi.ERRNO_SUCCESS, fd_obj: file };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
byteLength() {
|
|
74
|
+
return this.handle.getSize();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
readAll() {
|
|
78
|
+
const size = this.handle.getSize();
|
|
79
|
+
if (size === 0) return new Uint8Array(0);
|
|
80
|
+
const buf = new Uint8Array(size);
|
|
81
|
+
const n = this.handle.read(buf, { at: 0 });
|
|
82
|
+
return n === size ? buf : buf.subarray(0, n);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
writeAll(bytes) {
|
|
86
|
+
if (this.readonly) throw new Error("Cannot write to a readonly SyncOPFSFile");
|
|
87
|
+
const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
88
|
+
this.handle.truncate(0);
|
|
89
|
+
if (data.byteLength > 0) this.handle.write(data, { at: 0 });
|
|
90
|
+
this.handle.flush();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
truncate(size = 0) {
|
|
94
|
+
if (this.readonly) throw new Error("Cannot truncate a readonly SyncOPFSFile");
|
|
95
|
+
this.handle.truncate(size);
|
|
96
|
+
this.handle.flush();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
flush() {
|
|
100
|
+
this.handle.flush();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
close() {
|
|
104
|
+
this.handle.close();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return { PagedSyncOPFSFile, PagedOpenSyncOPFSFile };
|
|
109
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SyncOPFSFile, OpenSyncOPFSFile, wasi } from "@bjorn3/browser_wasi_shim";
|
|
2
|
+
import { createPagedSyncOPFSClasses } from "./opfs-wasi-core.js";
|
|
3
|
+
|
|
4
|
+
export const { PagedSyncOPFSFile, PagedOpenSyncOPFSFile } = createPagedSyncOPFSClasses({
|
|
5
|
+
SyncOPFSFile,
|
|
6
|
+
OpenSyncOPFSFile,
|
|
7
|
+
wasi,
|
|
8
|
+
});
|