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,608 @@
|
|
|
1
|
+
import { mountBranchPreview } from "./branch-preview.js";
|
|
2
|
+
import { affectsReads, mergeReads } from "./changes.js";
|
|
3
|
+
import { extractHeaders, hasHeader, headerValue } from "./http-headers.js";
|
|
4
|
+
import { isLocalRoute, parseManifest } from "./manifest.js";
|
|
5
|
+
import { watchRelease } from "./release-updates.js";
|
|
6
|
+
import { isLocalUrl } from "./server-request.js";
|
|
7
|
+
import { resolveSyncContext } from "./sync-context.js";
|
|
8
|
+
import workerUrl from "./worker.js?worker&url";
|
|
9
|
+
const manifest = parseManifest(import.meta.env.VITE_MANIFEST);
|
|
10
|
+
let releaseRequired;
|
|
11
|
+
// A built shell has already started the worker from its first inline script (WasmBuild#inject_preloads).
|
|
12
|
+
const worker = window.__worker || new Worker(workerUrl, { type: "module" });
|
|
13
|
+
const waiting = new Map();
|
|
14
|
+
let nextId = 1;
|
|
15
|
+
let historyFill = null;
|
|
16
|
+
let syncNotices = [];
|
|
17
|
+
const faults = [];
|
|
18
|
+
const notifications = [];
|
|
19
|
+
let circuitState = { state: "closed" };
|
|
20
|
+
|
|
21
|
+
function renderFaultBanner(detail) {
|
|
22
|
+
if (typeof document === "undefined" || !document.body) return;
|
|
23
|
+
const { fault, circuit, traceAvailable } = detail;
|
|
24
|
+
const isDev = import.meta.env.DEV || location.hostname === "localhost" || location.hostname === "127.0.0.1";
|
|
25
|
+
if (!isDev && circuit?.state !== "open") return;
|
|
26
|
+
|
|
27
|
+
let banner = document.getElementById("instant-record-fault-banner");
|
|
28
|
+
if (!banner) {
|
|
29
|
+
banner = document.createElement("div");
|
|
30
|
+
banner.id = "instant-record-fault-banner";
|
|
31
|
+
banner.setAttribute("role", "alert");
|
|
32
|
+
banner.style.cssText =
|
|
33
|
+
"position:fixed;bottom:12px;right:12px;z-index:2147483647;max-width:480px;background:#1f1113;color:#fde8e8;" +
|
|
34
|
+
"border:1px solid #f87171;border-radius:8px;padding:12px 14px;font:13px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;" +
|
|
35
|
+
"box-shadow:0 8px 24px rgba(0,0,0,0.45);";
|
|
36
|
+
document.body.appendChild(banner);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const stderrLines = (fault?.errors || []).slice(0, 6).join("\n");
|
|
40
|
+
const title = circuit?.state === "open"
|
|
41
|
+
? `InstantRecord circuit breaker OPEN (${fault?.exportName || "wasm"})`
|
|
42
|
+
: `InstantRecord WASM fault (${fault?.exportName || "wasm"})`;
|
|
43
|
+
|
|
44
|
+
banner.replaceChildren();
|
|
45
|
+
const heading = document.createElement("div");
|
|
46
|
+
heading.style.cssText = "font-weight:700;color:#fca5a5;margin-bottom:6px;";
|
|
47
|
+
heading.textContent = title;
|
|
48
|
+
banner.appendChild(heading);
|
|
49
|
+
|
|
50
|
+
const summary = document.createElement("div");
|
|
51
|
+
summary.textContent = `${fault?.message || "Unknown fault"} (exit=${fault?.exit})`;
|
|
52
|
+
banner.appendChild(summary);
|
|
53
|
+
|
|
54
|
+
if (stderrLines) {
|
|
55
|
+
const pre = document.createElement("pre");
|
|
56
|
+
pre.style.cssText = "margin:8px 0 0;padding:8px;background:#11090a;border-radius:4px;overflow:auto;max-height:140px;white-space:pre-wrap;font-size:12px;";
|
|
57
|
+
pre.textContent = stderrLines;
|
|
58
|
+
banner.appendChild(pre);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const actions = document.createElement("div");
|
|
62
|
+
actions.style.cssText = "display:flex;gap:8px;margin-top:10px;";
|
|
63
|
+
|
|
64
|
+
if (circuit?.state === "open") {
|
|
65
|
+
const resetBtn = document.createElement("button");
|
|
66
|
+
resetBtn.type = "button";
|
|
67
|
+
resetBtn.textContent = "Reset runtime";
|
|
68
|
+
resetBtn.style.cssText = "background:#dc2626;color:#fff;border:0;border-radius:4px;padding:4px 10px;cursor:pointer;font:inherit;";
|
|
69
|
+
resetBtn.onclick = () => {
|
|
70
|
+
window.__spinel.resetCircuit().then(() => banner.remove());
|
|
71
|
+
};
|
|
72
|
+
actions.appendChild(resetBtn);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (traceAvailable) {
|
|
76
|
+
const traceBtn = document.createElement("button");
|
|
77
|
+
traceBtn.type = "button";
|
|
78
|
+
traceBtn.textContent = "Download .irtrace";
|
|
79
|
+
traceBtn.style.cssText = "background:#374151;color:#fff;border:0;border-radius:4px;padding:4px 10px;cursor:pointer;font:inherit;";
|
|
80
|
+
traceBtn.onclick = () => window.__spinel.trace.download();
|
|
81
|
+
actions.appendChild(traceBtn);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const dismissBtn = document.createElement("button");
|
|
85
|
+
dismissBtn.type = "button";
|
|
86
|
+
dismissBtn.textContent = "Dismiss";
|
|
87
|
+
dismissBtn.style.cssText = "background:transparent;color:#fca5a5;border:1px solid #7f1d1d;border-radius:4px;padding:4px 10px;cursor:pointer;font:inherit;margin-left:auto;";
|
|
88
|
+
dismissBtn.onclick = () => banner.remove();
|
|
89
|
+
actions.appendChild(dismissBtn);
|
|
90
|
+
|
|
91
|
+
banner.appendChild(actions);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
worker.onmessage = (event) => {
|
|
95
|
+
const { id, result, error, type } = event.data;
|
|
96
|
+
if (type === "release_required") return releaseRequired?.();
|
|
97
|
+
if (type === "storage_upgrade_blocked") {
|
|
98
|
+
document.body.textContent = "Close or reload other tabs running the previous version of this app. Your saved changes will be kept.";
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (type === "instant_record.fault") {
|
|
102
|
+
const detail = {
|
|
103
|
+
fault: event.data.fault,
|
|
104
|
+
circuit: event.data.circuit,
|
|
105
|
+
trippedNow: !!event.data.trippedNow,
|
|
106
|
+
traceAvailable: !!event.data.traceAvailable,
|
|
107
|
+
};
|
|
108
|
+
circuitState = detail.circuit || circuitState;
|
|
109
|
+
faults.push(detail.fault);
|
|
110
|
+
if (faults.length > 50) faults.shift();
|
|
111
|
+
if (window.__spinel) {
|
|
112
|
+
window.__spinel.lastFault = detail.fault;
|
|
113
|
+
window.__spinel.circuit = circuitState;
|
|
114
|
+
}
|
|
115
|
+
console.error("[instant_record] WASM fault:", detail.fault, detail.circuit);
|
|
116
|
+
window.dispatchEvent(new CustomEvent("instant-record:fault", { detail }));
|
|
117
|
+
renderFaultBanner(detail);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (type === "instant_record.circuit") {
|
|
121
|
+
circuitState = event.data.circuit || circuitState;
|
|
122
|
+
if (window.__spinel) window.__spinel.circuit = circuitState;
|
|
123
|
+
window.dispatchEvent(new CustomEvent("instant-record:circuit", { detail: circuitState }));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (type === "instant_record.notification") {
|
|
127
|
+
const note = {
|
|
128
|
+
name: event.data.name,
|
|
129
|
+
payload: event.data.payload,
|
|
130
|
+
durationMs: event.data.durationMs,
|
|
131
|
+
exportName: event.data.exportName,
|
|
132
|
+
at: event.data.at,
|
|
133
|
+
};
|
|
134
|
+
notifications.push(note);
|
|
135
|
+
if (notifications.length > 150) notifications.shift();
|
|
136
|
+
window.dispatchEvent(new CustomEvent("instant-record:notification", { detail: note }));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (type === "instant_record.role") {
|
|
140
|
+
if (window.__spinel) window.__spinel.role = event.data.role;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (type === "instant_record.history") {
|
|
144
|
+
// How much of the model's history the local database holds: { done, full, rows }.
|
|
145
|
+
historyFill = event.data.state;
|
|
146
|
+
if (window.__spinel) window.__spinel.history = historyFill;
|
|
147
|
+
window.dispatchEvent(new CustomEvent("instant-record:history", { detail: historyFill }));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (type === "instant_record.sync_notices") {
|
|
151
|
+
syncNotices = Array.isArray(event.data.notices) ? event.data.notices : [];
|
|
152
|
+
if (window.__spinel) window.__spinel.notices = syncNotices;
|
|
153
|
+
window.dispatchEvent(new CustomEvent("instant-record:sync-notices", { detail: { notices: syncNotices } }));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (type === "instant_record.branch") {
|
|
157
|
+
if (window.__spinel) window.__spinel.branchState = event.data.state;
|
|
158
|
+
window.dispatchEvent(new CustomEvent("instant-record:branch-changed", { detail: event.data.state }));
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (type === "records_changed") {
|
|
162
|
+
if (event.data.reads) {
|
|
163
|
+
if (window.__spinel) window.__spinel.reads = event.data.reads;
|
|
164
|
+
}
|
|
165
|
+
if (marks.rendered) recordsChanged(event.data.changes, event.data.reads);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const entry = waiting.get(id);
|
|
169
|
+
if (!entry) return;
|
|
170
|
+
waiting.delete(id);
|
|
171
|
+
error ? entry.reject(new Error(error)) : entry.resolve(result);
|
|
172
|
+
};
|
|
173
|
+
const call = (type, payload) => new Promise((resolve, reject) => {
|
|
174
|
+
const id = nextId++;
|
|
175
|
+
waiting.set(id, { resolve, reject });
|
|
176
|
+
worker.postMessage({ id, type, payload });
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const traceApi = {
|
|
180
|
+
enable(options = {}) {
|
|
181
|
+
try { sessionStorage.setItem("instant_record.trace", "1"); } catch {}
|
|
182
|
+
return call("instant_record.trace.configure", { ...options, enabled: true });
|
|
183
|
+
},
|
|
184
|
+
disable() {
|
|
185
|
+
try { sessionStorage.removeItem("instant_record.trace"); } catch {}
|
|
186
|
+
return call("instant_record.trace.configure", { enabled: false });
|
|
187
|
+
},
|
|
188
|
+
status() {
|
|
189
|
+
return call("instant_record.trace.status");
|
|
190
|
+
},
|
|
191
|
+
clear() {
|
|
192
|
+
return call("instant_record.trace.clear");
|
|
193
|
+
},
|
|
194
|
+
export(options = {}) {
|
|
195
|
+
return call("instant_record.trace.export", options);
|
|
196
|
+
},
|
|
197
|
+
async download(filename = null, options = {}) {
|
|
198
|
+
const trace = await traceApi.export(options);
|
|
199
|
+
const name = filename || `instant-record-${new Date().toISOString().replace(/[:.]/g, "-")}.irtrace`;
|
|
200
|
+
const blob = new Blob([JSON.stringify(trace, null, 2)], { type: "application/json" });
|
|
201
|
+
const url = URL.createObjectURL(blob);
|
|
202
|
+
const link = document.createElement("a");
|
|
203
|
+
link.href = url;
|
|
204
|
+
link.download = name;
|
|
205
|
+
link.click();
|
|
206
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
207
|
+
return trace;
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const initialContext = resolveSyncContext(location.href);
|
|
212
|
+
const initialStorageKey = initialContext ? initialContext.storageKey : "";
|
|
213
|
+
const marks = { start: performance.now() };
|
|
214
|
+
// Where the sync server is and who this browser is to it, for a page that asks it for
|
|
215
|
+
// something itself: the bytes of a record that declares sync_file (frontend/files.js).
|
|
216
|
+
const syncEndpoint = import.meta.env.VITE_SYNC_ENDPOINT || "/instant_record";
|
|
217
|
+
const branchApi = {
|
|
218
|
+
fork: (name) => call("branch.create", { name }),
|
|
219
|
+
status: () => call("branch.status"),
|
|
220
|
+
approve: (options = {}) => call("branch.approve", options),
|
|
221
|
+
discard: () => call("branch.discard"),
|
|
222
|
+
};
|
|
223
|
+
window.__spinel = {
|
|
224
|
+
marks,
|
|
225
|
+
call,
|
|
226
|
+
worker,
|
|
227
|
+
history: historyFill,
|
|
228
|
+
reads: null,
|
|
229
|
+
notices: syncNotices,
|
|
230
|
+
sourceVersion: import.meta.env.VITE_SOURCE_VERSION,
|
|
231
|
+
endpoint: syncEndpoint,
|
|
232
|
+
scope: syncScope(),
|
|
233
|
+
manifest,
|
|
234
|
+
branch: branchApi,
|
|
235
|
+
branchState: { active: false },
|
|
236
|
+
faults,
|
|
237
|
+
lastFault: null,
|
|
238
|
+
circuit: circuitState,
|
|
239
|
+
notifications,
|
|
240
|
+
resetCircuit: () => call("instant_record.reset_circuit"),
|
|
241
|
+
trace: traceApi,
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// Restore the switches before even the first bootstrap can reach Rails.
|
|
245
|
+
try {
|
|
246
|
+
const ui = JSON.parse(sessionStorage.getItem("instant_record.inspector"));
|
|
247
|
+
if (ui) worker.postMessage({
|
|
248
|
+
type: "instant_record.simulate",
|
|
249
|
+
settings: { offline: !!ui.offline, latencyMs: ui.slow ? 2000 : 0 },
|
|
250
|
+
});
|
|
251
|
+
} catch { /* Storage may be unavailable. */ }
|
|
252
|
+
|
|
253
|
+
function traceOptIn() {
|
|
254
|
+
try {
|
|
255
|
+
if (new URLSearchParams(location.search).get("irtrace") === "1") return true;
|
|
256
|
+
return sessionStorage.getItem("instant_record.trace") === "1";
|
|
257
|
+
} catch {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Static assets, service worker, release/island manifests, same-origin sync/file
|
|
263
|
+
// endpoints, and non-island routes go straight to the network rather than Wasm.
|
|
264
|
+
const isLocal = (url, method = null) => isLocalUrl(url, location.origin, syncEndpoint) && isLocalRoute(manifest, url.pathname, method, syncEndpoint);
|
|
265
|
+
|
|
266
|
+
// One page request; the worker follows the app's redirects and returns the final answer.
|
|
267
|
+
const appRequest = (method, path, body, contentType, headers) =>
|
|
268
|
+
call("navigate", { method, path, body, contentType, headers });
|
|
269
|
+
|
|
270
|
+
const encodeFormData = (form) => {
|
|
271
|
+
const fields = new URLSearchParams();
|
|
272
|
+
for (const [name, value] of form.entries()) if (typeof value === "string") fields.append(name, value);
|
|
273
|
+
return fields.toString();
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const defaultBrowserHeaders = ({ referrer = location.href, referrerPolicy = "" } = {}) => {
|
|
277
|
+
const headers = { Host: location.host };
|
|
278
|
+
if (location.protocol === "https:") headers["X-Forwarded-Proto"] = "https";
|
|
279
|
+
if (referrer && referrerPolicy !== "no-referrer") headers.Referer = referrer;
|
|
280
|
+
return headers;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const withBrowserHeaders = (headers, options) => {
|
|
284
|
+
const merged = { ...headers };
|
|
285
|
+
for (const [name, value] of Object.entries(defaultBrowserHeaders(options))) {
|
|
286
|
+
if (!hasHeader(merged, name)) merged[name] = value;
|
|
287
|
+
}
|
|
288
|
+
return merged;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
async function parseFetchInput(input, init, { binary = true } = {}) {
|
|
292
|
+
const isUrlInput = typeof input === "string" || input instanceof URL;
|
|
293
|
+
let method;
|
|
294
|
+
let body;
|
|
295
|
+
let contentType;
|
|
296
|
+
let redirect;
|
|
297
|
+
let requestHeaders;
|
|
298
|
+
|
|
299
|
+
if (isUrlInput) {
|
|
300
|
+
method = (init?.method || "GET").toUpperCase();
|
|
301
|
+
redirect = init?.redirect || "follow";
|
|
302
|
+
requestHeaders = withBrowserHeaders(extractHeaders(init?.headers), { referrerPolicy: init?.referrerPolicy });
|
|
303
|
+
contentType = headerValue(init?.headers, "content-type");
|
|
304
|
+
if (method !== "GET" && method !== "HEAD" && init?.body != null) {
|
|
305
|
+
const raw = init.body;
|
|
306
|
+
if (raw instanceof FormData) {
|
|
307
|
+
body = encodeFormData(raw);
|
|
308
|
+
contentType = "application/x-www-form-urlencoded";
|
|
309
|
+
} else if (raw instanceof URLSearchParams) {
|
|
310
|
+
body = raw.toString();
|
|
311
|
+
contentType = "application/x-www-form-urlencoded";
|
|
312
|
+
} else if (typeof raw === "string") {
|
|
313
|
+
body = raw;
|
|
314
|
+
} else {
|
|
315
|
+
const res = new Response(raw);
|
|
316
|
+
body = binary ? new Uint8Array(await res.arrayBuffer()) : await res.text();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
const request = init ? new Request(input, init) : input.clone();
|
|
321
|
+
method = request.method.toUpperCase();
|
|
322
|
+
redirect = request.redirect;
|
|
323
|
+
requestHeaders = withBrowserHeaders(extractHeaders(request.headers), { referrerPolicy: request.referrerPolicy });
|
|
324
|
+
contentType = request.headers.get("content-type") || undefined;
|
|
325
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
326
|
+
if (contentType && contentType.startsWith("multipart/form-data")) {
|
|
327
|
+
body = encodeFormData(await request.formData());
|
|
328
|
+
contentType = "application/x-www-form-urlencoded";
|
|
329
|
+
} else {
|
|
330
|
+
body = binary ? new Uint8Array(await request.arrayBuffer()) : await request.text();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return { method, body, contentType, redirect, requestHeaders };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// The same seam a service worker's fetch handler is, from inside the page.
|
|
338
|
+
const networkFetch = window.fetch.bind(window);
|
|
339
|
+
window.fetch = async (input, init) => {
|
|
340
|
+
const isUrlInput = typeof input === "string" || input instanceof URL;
|
|
341
|
+
const url = isUrlInput ? new URL(input, location.href) : new URL(input.url);
|
|
342
|
+
if (url.origin === location.origin && url.searchParams.has("instant_record_network")) {
|
|
343
|
+
const { method, body, contentType } = await parseFetchInput(input, init, { binary: false });
|
|
344
|
+
const response = await call("serverRequest", { path: url.pathname + url.search, method, body, contentType });
|
|
345
|
+
if (!response.status) throw new TypeError("Sync server unreachable");
|
|
346
|
+
const responseHeaders = response.contentType ? { "Content-Type": response.contentType } : {};
|
|
347
|
+
return new Response(response.text || null, { status: response.status, headers: responseHeaders });
|
|
348
|
+
}
|
|
349
|
+
const requestMethod = isUrlInput
|
|
350
|
+
? (init?.method || "GET").toUpperCase()
|
|
351
|
+
: (init?.method || input.method || "GET").toUpperCase();
|
|
352
|
+
if (!isLocal(url, requestMethod)) return networkFetch(input, init);
|
|
353
|
+
|
|
354
|
+
const { method, body, contentType, redirect, requestHeaders } = await parseFetchInput(input, init, { binary: true });
|
|
355
|
+
const path = url.pathname + url.search;
|
|
356
|
+
|
|
357
|
+
if (redirect === "manual") {
|
|
358
|
+
// The demo's controllers post with redirect: "manual" and only need to know it went through.
|
|
359
|
+
const result = await call("request", { method, path, body, contentType, headers: requestHeaders });
|
|
360
|
+
const ok = result.status < 400;
|
|
361
|
+
return new Response(null, { status: ok ? 200 : result.status });
|
|
362
|
+
}
|
|
363
|
+
const { result, redirected, finalPath } = await appRequest(method, path, body, contentType, requestHeaders);
|
|
364
|
+
if ((method === "GET" || redirected) && result.reads) {
|
|
365
|
+
const finalParams = new URL(finalPath, location.origin).searchParams;
|
|
366
|
+
const partial = hasHeader(requestHeaders, "x-inertia-partial-data") || finalParams.has("fragment");
|
|
367
|
+
window.__spinel.reads = partial ? mergeReads(window.__spinel.reads, result.reads) : result.reads;
|
|
368
|
+
}
|
|
369
|
+
const headers = result.headers.filter(([name]) => !/^(content-length|transfer-encoding)$/i.test(name));
|
|
370
|
+
// The socket server adds this default when it writes a response; the reactor entry skips that
|
|
371
|
+
// writer, and without it Turbo treats the page as a download and falls back to a full load.
|
|
372
|
+
if (!headers.some(([name]) => name.toLowerCase() === "content-type")) headers.push(["Content-Type", "text/html; charset=utf-8"]);
|
|
373
|
+
const response = new Response(result.body, { status: result.status, headers });
|
|
374
|
+
if (typeof result.body === "string") {
|
|
375
|
+
const bodyText = result.body;
|
|
376
|
+
response.text = () => Promise.resolve(bodyText);
|
|
377
|
+
}
|
|
378
|
+
Object.defineProperty(response, "url", { value: new URL(finalPath, location.origin).href });
|
|
379
|
+
Object.defineProperty(response, "redirected", { value: redirected });
|
|
380
|
+
return response;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// The gem's worker posts records_changed to its clients; the demo's layout turns that
|
|
384
|
+
// into this window event for pages that refresh in place, and redraws the rest when
|
|
385
|
+
// the changed rows affect the tables/partitions this page read.
|
|
386
|
+
// `changes` lists structured row deltas { type, id, op, changed_columns, attrs }, or
|
|
387
|
+
// is null when the sync pass could not list them (wildcard).
|
|
388
|
+
function recordsChanged(changes, reads) {
|
|
389
|
+
const effectiveReads = reads ?? window.__spinel?.reads ?? null;
|
|
390
|
+
if (document.querySelector("[data-instant-refresh]")) {
|
|
391
|
+
window.dispatchEvent(new CustomEvent("instant-record:records-changed", {
|
|
392
|
+
detail: { changes: changes || null, reads: effectiveReads },
|
|
393
|
+
}));
|
|
394
|
+
} else if (affectsReads(changes, effectiveReads)) {
|
|
395
|
+
redraw();
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// A page with no refresh of its own is drawn again from the local database. Where Turbo drew
|
|
400
|
+
// the page, Turbo draws it again in place: a visit to the address it is on, answered by the
|
|
401
|
+
// app in this browser. A whole reload would start the app again, after every write the page
|
|
402
|
+
// itself made. Turbo refreshes nothing while a visit is under way, so this waits for its end.
|
|
403
|
+
function redraw() {
|
|
404
|
+
const turbo = window.Turbo?.session;
|
|
405
|
+
if (!turbo?.refresh) return window.location.reload();
|
|
406
|
+
if (turbo.navigator.currentVisit) return document.addEventListener("turbo:load", redraw, { once: true });
|
|
407
|
+
// Morphed, so the scroll stays where it is, and the field being typed in is left out of the
|
|
408
|
+
// morph: the page as the app draws it has that field empty, and the letters are the person's.
|
|
409
|
+
redrawing = true;
|
|
410
|
+
setTimeout(() => { redrawing = false; }, 2000);
|
|
411
|
+
turbo.refresh(document.baseURI, { method: "morph", scroll: "preserve" });
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
let redrawing = false;
|
|
415
|
+
function keepTyping(event) {
|
|
416
|
+
const field = event.target;
|
|
417
|
+
if (redrawing && field === document.activeElement && field.matches?.("input, textarea, select, [contenteditable]")) event.preventDefault();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// The shell began compiling the module before this script loaded; pass it on, and ask for the
|
|
421
|
+
// current page in the same message so boot and first render are one round trip.
|
|
422
|
+
// Who this browser is to the sync server, for models that declare sync_scope. Every tab of
|
|
423
|
+
// the browser shares it. Where storage is refused, the token lasts for this page.
|
|
424
|
+
function syncScope() {
|
|
425
|
+
const key = "instant_record.sync_scope";
|
|
426
|
+
try {
|
|
427
|
+
const saved = localStorage.getItem(key);
|
|
428
|
+
if (saved) return saved;
|
|
429
|
+
const token = crypto.randomUUID();
|
|
430
|
+
localStorage.setItem(key, token);
|
|
431
|
+
return localStorage.getItem(key) || token;
|
|
432
|
+
} catch {
|
|
433
|
+
return crypto.randomUUID();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// A form the app in this browser answers is drawn in the task its answer arrives in. Turbo would
|
|
438
|
+
// visit the page the app redirected to and wait a frame before it drew it, and the app has
|
|
439
|
+
// answered long before that frame. So the answer's page is morphed into this one at once, and
|
|
440
|
+
// the change is on screen at the next paint: the time a page takes to draw a guess, and this
|
|
441
|
+
// is no guess. A form that asks Turbo for something of its own (a frame, a stream, a question
|
|
442
|
+
// first) is left to Turbo, and so is an answer that is another page.
|
|
443
|
+
async function submitInPlace(event) {
|
|
444
|
+
const turbo = window.Turbo;
|
|
445
|
+
const form = event.target;
|
|
446
|
+
const button = event.submitter;
|
|
447
|
+
if (!turbo?.morphBodyElements || event.defaultPrevented || !(form instanceof HTMLFormElement)) return;
|
|
448
|
+
const asks = (name) => button?.hasAttribute(name) || form.hasAttribute(name);
|
|
449
|
+
if (["data-turbo-frame", "data-turbo-stream", "data-turbo-confirm", "data-turbo-action", "data-turbo-method"].some(asks)) return;
|
|
450
|
+
if (form.closest("turbo-frame, [data-turbo='false']") || button?.dataset.turbo === "false") return;
|
|
451
|
+
const target = button?.getAttribute("formtarget") || form.target;
|
|
452
|
+
const url = new URL(button?.getAttribute("formaction") || form.action, location.href);
|
|
453
|
+
const posted = (button?.getAttribute("formmethod") || form.method).toUpperCase();
|
|
454
|
+
if (posted !== "POST" || url.searchParams.has("instant_record_network") || (target && target !== "_self")) return;
|
|
455
|
+
const fields = new FormData(form, button || undefined);
|
|
456
|
+
const method = String(fields.get("_method") || posted).toUpperCase();
|
|
457
|
+
if (!isLocal(url, method) || [...fields.values()].some(value => value instanceof File && value.name)) return;
|
|
458
|
+
event.preventDefault();
|
|
459
|
+
|
|
460
|
+
// Through the page's fetch, as Turbo's own submission goes: whatever watches that sees this.
|
|
461
|
+
const answer = await window.fetch(url, { method, body: encodeFormData(fields),
|
|
462
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
463
|
+
const type = answer.headers.get("content-type") || "";
|
|
464
|
+
const body = await answer.text();
|
|
465
|
+
const path = new URL(answer.url).pathname + new URL(answer.url).search;
|
|
466
|
+
if (type.includes("turbo-stream")) return turbo.renderStreamMessage(body);
|
|
467
|
+
if (answer.redirected && path !== location.pathname + location.search) return turbo.visit(path);
|
|
468
|
+
if (!type.includes("html")) return redraw();
|
|
469
|
+
|
|
470
|
+
// The page as the app draws it has the form's fields as new. What the person typed into the
|
|
471
|
+
// field they are in since the press is theirs, and is put back after the morph.
|
|
472
|
+
const field = document.activeElement;
|
|
473
|
+
const sent = field?.form === form ? fields.get(field.name) : null;
|
|
474
|
+
const typed = typeof sent === "string" ? field.value : null;
|
|
475
|
+
turbo.morphBodyElements(document.body, new DOMParser().parseFromString(body, "text/html").body);
|
|
476
|
+
if (typed !== null && typed !== sent && typed.startsWith(sent) && field.isConnected) field.value = typed.slice(sent.length);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function reportVisibility() {
|
|
480
|
+
worker.postMessage({ type: "instant_record.visibility", visible: document.visibilityState !== "hidden" });
|
|
481
|
+
}
|
|
482
|
+
function reportPageHide(event) {
|
|
483
|
+
try { worker.postMessage({ type: "instant_record.pagehide", persisted: !!event.persisted }); } catch {}
|
|
484
|
+
}
|
|
485
|
+
function reportPageShow(event) {
|
|
486
|
+
if (event.persisted) {
|
|
487
|
+
worker.postMessage({ type: "instant_record.pageshow", visible: document.visibilityState !== "hidden" });
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function bindVisibility() {
|
|
491
|
+
document.addEventListener("visibilitychange", reportVisibility);
|
|
492
|
+
window.addEventListener("pagehide", reportPageHide);
|
|
493
|
+
window.addEventListener("pageshow", reportPageShow);
|
|
494
|
+
reportVisibility();
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// One async function, since the built shell is a classic script (vite.config.js) and cannot
|
|
498
|
+
// await at its top level.
|
|
499
|
+
async function openApp() {
|
|
500
|
+
const boot = await call("boot", {
|
|
501
|
+
module: await window.__wasm,
|
|
502
|
+
path: location.pathname + location.search,
|
|
503
|
+
scope: syncScope(),
|
|
504
|
+
visible: document.visibilityState !== "hidden",
|
|
505
|
+
headers: defaultBrowserHeaders({ referrer: document.referrer }),
|
|
506
|
+
trace: traceOptIn(),
|
|
507
|
+
}).catch(error => {
|
|
508
|
+
document.body.textContent = "The app could not open this release. Your saved database was kept. " + error.message;
|
|
509
|
+
throw error;
|
|
510
|
+
});
|
|
511
|
+
if (window.__spinel) {
|
|
512
|
+
window.__spinel.role = boot.role;
|
|
513
|
+
window.__spinel.storage = boot.storageMode;
|
|
514
|
+
if (boot.circuit) window.__spinel.circuit = circuitState = boot.circuit;
|
|
515
|
+
}
|
|
516
|
+
marks.booted = performance.now();
|
|
517
|
+
marks.compileMs = window.__wasmMs ?? boot.compileMs;
|
|
518
|
+
if (boot.first) {
|
|
519
|
+
const { result, finalPath } = boot.first;
|
|
520
|
+
if (result.reads) window.__spinel.reads = result.reads;
|
|
521
|
+
marks.firstResponse = performance.now();
|
|
522
|
+
marks.firstRequestMs = result.ms;
|
|
523
|
+
if (finalPath !== location.pathname + location.search) history.replaceState(null, "", finalPath);
|
|
524
|
+
// Hand the document to the app's own page: its importmap, Turbo and Stimulus take over from here.
|
|
525
|
+
document.open();
|
|
526
|
+
document.write(result.status === 200 ? result.body : `<pre>${result.status}\n${(result.errors || []).join("\n")}</pre>`);
|
|
527
|
+
document.close();
|
|
528
|
+
bindVisibility();
|
|
529
|
+
document.addEventListener("turbo:before-morph-element", keepTyping);
|
|
530
|
+
document.addEventListener("turbo:render", () => { redrawing = false; });
|
|
531
|
+
document.addEventListener("submit", submitInPlace);
|
|
532
|
+
} else if (window.__spinel.lastFault) {
|
|
533
|
+
renderFaultBanner({ fault: window.__spinel.lastFault, circuit: window.__spinel.circuit, traceAvailable: traceOptIn() });
|
|
534
|
+
}
|
|
535
|
+
document.addEventListener("turbo:before-visit", event => {
|
|
536
|
+
const destination = new URL(event.detail.url, location.href);
|
|
537
|
+
const next = resolveSyncContext(event.detail.url);
|
|
538
|
+
if ((next ? next.storageKey : "") !== initialStorageKey || !isLocal(destination, "GET")) {
|
|
539
|
+
event.preventDefault();
|
|
540
|
+
location.assign(event.detail.url);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
marks.rendered = performance.now();
|
|
545
|
+
if (window.__spinel.lastFault) {
|
|
546
|
+
renderFaultBanner({ fault: window.__spinel.lastFault, circuit: window.__spinel.circuit, traceAvailable: traceOptIn() });
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// Turbo and Stimulus handle their own forms first. An ordinary Rails form still
|
|
550
|
+
// submits locally in apps without either library.
|
|
551
|
+
async function submitLocalForm(event) {
|
|
552
|
+
if (event.defaultPrevented || !(event.target instanceof HTMLFormElement)) return;
|
|
553
|
+
const form = event.target;
|
|
554
|
+
const button = event.submitter;
|
|
555
|
+
const target = button?.getAttribute("formtarget") || form.target;
|
|
556
|
+
const url = new URL(button?.getAttribute("formaction") || form.action, location.href);
|
|
557
|
+
const method = (button?.getAttribute("formmethod") || form.method).toUpperCase();
|
|
558
|
+
if (!isLocal(url, method) || url.searchParams.has("instant_record_network") || method !== "POST" || (target && target !== "_self")) return;
|
|
559
|
+
event.preventDefault();
|
|
560
|
+
const fields = new FormData(form, button || undefined);
|
|
561
|
+
const file = [...fields.values()].find(value => value instanceof File && value.name);
|
|
562
|
+
if (file) {
|
|
563
|
+
window.alert("This compiled runtime does not support file uploads.");
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const response = await appRequest(
|
|
567
|
+
method,
|
|
568
|
+
url.pathname + url.search,
|
|
569
|
+
encodeFormData(fields),
|
|
570
|
+
"application/x-www-form-urlencoded",
|
|
571
|
+
withBrowserHeaders({ Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" }),
|
|
572
|
+
);
|
|
573
|
+
if (response.result.status < 400 && response.redirected) {
|
|
574
|
+
location.assign(response.finalPath);
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
const html = response.result.status >= 400 ? (response.result.body || "<p>Request failed</p>") : response.result.body;
|
|
578
|
+
if (response.result.reads) window.__spinel.reads = response.result.reads;
|
|
579
|
+
document.open();
|
|
580
|
+
document.write(html);
|
|
581
|
+
document.close();
|
|
582
|
+
window.addEventListener("submit", submitLocalForm);
|
|
583
|
+
bindVisibility();
|
|
584
|
+
window.dispatchEvent(new Event("instant-record:dom-written"));
|
|
585
|
+
}
|
|
586
|
+
window.addEventListener("submit", submitLocalForm);
|
|
587
|
+
mountBranchPreview(branchApi);
|
|
588
|
+
releaseRequired = watchRelease(networkFetch, import.meta.env.VITE_SOURCE_VERSION, () => waiting.size > 0 || !!window.__spinel?.branchState?.active);
|
|
589
|
+
|
|
590
|
+
// Resource Timing distinguishes a cached module from a network response and gives
|
|
591
|
+
// compressed and decoded byte counts without downloading the module a second time.
|
|
592
|
+
const resource = performance.getEntriesByName(new URL(import.meta.env.VITE_WASM_URL, location.origin).href).at(-1);
|
|
593
|
+
if (resource?.decodedBodySize && boot.first) {
|
|
594
|
+
const cached = resource.transferSize === 0;
|
|
595
|
+
const compileEnd = window.__wasmStart + marks.compileMs;
|
|
596
|
+
const ledger = { at: Date.now(), totalMs: marks.rendered - boot.first.result.ms, entries: [
|
|
597
|
+
{ phase: "bundle", ms: resource.responseEnd - resource.startTime, bytes: resource.decodedBodySize,
|
|
598
|
+
wireBytes: cached ? 0 : resource.encodedBodySize, cached },
|
|
599
|
+
{ phase: "compile", ms: Math.max(0, compileEnd - resource.responseEnd) },
|
|
600
|
+
{ phase: "sqlite", ms: boot.storageMs }, { phase: "vm", ms: boot.runtimeMs },
|
|
601
|
+
{ phase: "schema", ms: boot.bootstrapMs }, { phase: "render", ms: boot.first.result.ms },
|
|
602
|
+
...(boot.shell ? [{ phase: "shell", ms: boot.shell.ms, bytes: boot.shell.bytes }] : []),
|
|
603
|
+
] };
|
|
604
|
+
window.__spinel.ledger = ledger;
|
|
605
|
+
try { localStorage.setItem("instant_record.compiled.boot." + (cached ? "cache" : "network"), JSON.stringify(ledger)); } catch {}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
openApp();
|