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,341 @@
|
|
|
1
|
+
# Ruby screens on iPhone
|
|
2
|
+
|
|
3
|
+
A Rails app's screens, written in Ruby, drawn with stock iOS controls. The
|
|
4
|
+
app's models, its sync client and its screens are compiled to a C library
|
|
5
|
+
that runs inside the app. `InstantRecordNative` is a Swift package with no
|
|
6
|
+
dependencies: it runs that library, decodes each screen's JSON and draws it.
|
|
7
|
+
`Inbox` is the demo's app.
|
|
8
|
+
|
|
9
|
+
## Your own app
|
|
10
|
+
|
|
11
|
+
In a Rails app that uses InstantRecord, with screens in `app/screens` and the
|
|
12
|
+
toolchain file `compiled/README.md` describes:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
bin/rails generate instant_record:ios Shop --screen catalog
|
|
16
|
+
bin/rails "instant_record:native[iphonesimulator]"
|
|
17
|
+
xcodebuild -project native/ios/Shop/Shop.xcodeproj -scheme Shop -destination 'platform=iOS Simulator,name=iPhone 17' build
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The generator writes a thin app in `native/ios/Shop`: the first screen's
|
|
21
|
+
name, the server's address, and the Xcode project. The project file is
|
|
22
|
+
generated from the Swift files in the folder. After adding one, run the
|
|
23
|
+
generator again with `--force`. `XcodeProject.new(packages: { "Feedback" =>
|
|
24
|
+
"../../feedback" })` links another Swift package by its path from the app's
|
|
25
|
+
folder.
|
|
26
|
+
|
|
27
|
+
## The Inbox demo
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
ruby compiled/pipeline/build_native.rb iphonesimulator
|
|
31
|
+
cd demo && bin/rails db:prepare && bundle exec falcon serve --bind http://localhost:3000
|
|
32
|
+
cd native/ios/Inbox
|
|
33
|
+
xcodebuild -project Inbox.xcodeproj -scheme Inbox -destination 'platform=iOS Simulator,name=iPhone 17' -derivedDataPath build build
|
|
34
|
+
xcrun simctl boot "iPhone 17"
|
|
35
|
+
xcrun simctl install booted build/Build/Products/Debug-iphonesimulator/Inbox.app
|
|
36
|
+
xcrun simctl launch booted dev.instantrecord.Inbox -server http://localhost:3000
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`InboxApp.swift` lists the launch arguments: the member and inbox, a token,
|
|
40
|
+
the dev mode, the sync timer and a reset. The server, member, inbox and
|
|
41
|
+
token are kept in the app's settings, so the app opened again from the home
|
|
42
|
+
screen, with no arguments, goes on where it was. Launch it with other
|
|
43
|
+
values to change them. `-reset YES` still only empties the local databases.
|
|
44
|
+
The token is kept as a plain setting, which is enough for a demo token. An
|
|
45
|
+
app with real accounts keeps it in the Keychain. `ruby native/ios/Inbox/project.rb`
|
|
46
|
+
writes `Inbox.xcodeproj` again.
|
|
47
|
+
|
|
48
|
+
## A screen
|
|
49
|
+
|
|
50
|
+
A screen is one Ruby class in `app/screens`. `mailbox_screen.rb` is the
|
|
51
|
+
screen named `mailbox`. It is opened with named params, draws itself in
|
|
52
|
+
`body`, and answers taps in `perform`.
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
class MailboxScreen < InstantRecord::Native::Screen
|
|
56
|
+
def body
|
|
57
|
+
navigation title: param("inbox").capitalize do
|
|
58
|
+
list refreshable: true do
|
|
59
|
+
messages.each do |entry|
|
|
60
|
+
row id: entry.id, link: "thread", params: { "inbox" => param("inbox"), "thread" => entry.id.to_s } do
|
|
61
|
+
stack "horizontal" do
|
|
62
|
+
text entry.author, style: "headline", lines: 1
|
|
63
|
+
spacer
|
|
64
|
+
date entry.created_at.utc.iso8601(6), style: "caption", tone: "secondary"
|
|
65
|
+
end
|
|
66
|
+
text entry.subject.to_s, lines: 1
|
|
67
|
+
swipe "Archive", action: "archive", args: { "id" => entry.id.to_s }, role: "destructive", image: "archive"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
more "older:#{param("inbox")}", query: below(messages.last) if older?
|
|
71
|
+
end
|
|
72
|
+
toolbar do
|
|
73
|
+
button "View", image: "filter", position: "trailing" do
|
|
74
|
+
item "Unread", replace: "mailbox", params: { "inbox" => param("inbox"), "filter" => "unread" }
|
|
75
|
+
item "Mark as read", action: "read_all"
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def perform(action, args, values)
|
|
82
|
+
case action
|
|
83
|
+
when "archive" then archive(args.fetch("id", ""))
|
|
84
|
+
when "read_all" then read_all
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- **Values travel by name.** `params:` is what a row or item opens another
|
|
91
|
+
screen with, and `args:` is what a button or swipe hands `perform`. Names
|
|
92
|
+
and values are strings, so write `entry.id.to_s`. Nothing is packed into
|
|
93
|
+
one string and split again.
|
|
94
|
+
- **A pushed screen is told it opened**: `perform("open", {}, {})`. The
|
|
95
|
+
conversation marks its message read there.
|
|
96
|
+
- **A menu item with `replace:`** puts that screen in the first screen's
|
|
97
|
+
place, as choosing another account does. With `link:` it opens the screen
|
|
98
|
+
over this one, as a row does. With `sheet:` it brings the screen up as a
|
|
99
|
+
sheet. The screen is told it opened, like a pushed one, and is forgotten
|
|
100
|
+
when the sheet is put away. A sheet that Ruby draws gets a bar for its
|
|
101
|
+
title and buttons. One that is a single `swift` view is shown as it is,
|
|
102
|
+
since such a view brings its own bar.
|
|
103
|
+
- **Layout is in the Ruby.** `spacer` pushes what follows to the far edge,
|
|
104
|
+
and `lines:` caps a text. The renderer adds no rules of its own.
|
|
105
|
+
- **Icons are named by meaning** (`archive`, `filter`, `person`, `inbox`,
|
|
106
|
+
`unread`, `read`, `send`, `compose`), and `Icons.swift` picks the SF
|
|
107
|
+
Symbol and what it is called aloud. A name it does not know is used as an
|
|
108
|
+
SF Symbol name.
|
|
109
|
+
- **`more`** stands for the rest of a list that is still on the server. When
|
|
110
|
+
it scrolls into view the app fetches `records?<query>` from the sync
|
|
111
|
+
address and hands the page to the library, and the screen leaves it out
|
|
112
|
+
once nothing more is there.
|
|
113
|
+
|
|
114
|
+
### Forms
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
bottom do
|
|
118
|
+
field "body", label: "Reply", multiline: true
|
|
119
|
+
button "Send", action: "reply", image: "send"
|
|
120
|
+
end
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
What is typed stays on the phone, by screen, through redraws and a trip back
|
|
124
|
+
and forth. It reaches `perform` as `values["body"]` with the next action from
|
|
125
|
+
that screen and is forgotten once that action has been performed. A button
|
|
126
|
+
beside fields cannot be pressed while they are all blank. `bottom` pins its
|
|
127
|
+
contents under the screen, above the keyboard.
|
|
128
|
+
|
|
129
|
+
### A view written in SwiftUI
|
|
130
|
+
|
|
131
|
+
A screen can hand its data to a view the app wrote by hand, the way a Rails
|
|
132
|
+
action hands a React page its props with `render inertia:`.
|
|
133
|
+
|
|
134
|
+
```ruby
|
|
135
|
+
swift "ConversationView" do
|
|
136
|
+
prop "subject", entry.subject.to_s
|
|
137
|
+
flag "archived", archived?(entry)
|
|
138
|
+
number "replies", replies.size
|
|
139
|
+
time "sent", entry.created_at.utc.iso8601(6)
|
|
140
|
+
props "messages" do
|
|
141
|
+
replies.each do |reply|
|
|
142
|
+
record do
|
|
143
|
+
prop "author", reply.author
|
|
144
|
+
prop "body", reply.body
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
```swift
|
|
152
|
+
// Once at launch, handed to the AppHost
|
|
153
|
+
var views = Screens()
|
|
154
|
+
views.register("ConversationView") { props, actions in
|
|
155
|
+
ConversationView(props: props, actions: actions)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// In the view
|
|
159
|
+
props["subject"] // String
|
|
160
|
+
props.bool("archived") // Bool
|
|
161
|
+
props.int("replies") // Int
|
|
162
|
+
props.date("sent") // Date?
|
|
163
|
+
props.list("messages") // [Props]
|
|
164
|
+
actions.perform("archive") // reaches the screen's perform, like any tap
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
A prop that was not sent, or is read as another kind than it was sent as,
|
|
168
|
+
reads as empty, false, zero or nil. `actions.perform` can carry arguments:
|
|
169
|
+
`actions.perform("archive", ["id": id])`.
|
|
170
|
+
|
|
171
|
+
Used inside a list, `swift` puts one hand-written view among stock ones, as a
|
|
172
|
+
partial would. A name nobody registered shows a warning in its place.
|
|
173
|
+
|
|
174
|
+
### A view from a library: the feedback form
|
|
175
|
+
|
|
176
|
+
The Inbox's View menu ends with "Send feedback". The screen behind it is
|
|
177
|
+
four lines of Ruby (`demo/app/screens/feedback_screen.rb`) that name a Swift
|
|
178
|
+
view, `FeedbackForm`, and hand it the member and the inbox. The view is not
|
|
179
|
+
this repo's: it is the form of the `Feedback` package in
|
|
180
|
+
[EveryInc/swift-libraries](https://github.com/EveryInc/swift-libraries), which
|
|
181
|
+
files a note as a GitHub issue through a relay.
|
|
182
|
+
|
|
183
|
+
- **The package is taken by path** from a checkout beside this repo:
|
|
184
|
+
`../swift-libraries` next to `instant_record`. `project.rb` names it
|
|
185
|
+
(`packages: { "Feedback" => "../../../../swift-libraries/feedback" }`), so
|
|
186
|
+
the project holds no path of anyone's machine. Without that checkout the
|
|
187
|
+
Inbox does not build: `git clone https://github.com/EveryInc/swift-libraries`
|
|
188
|
+
beside this repo first.
|
|
189
|
+
- **`InboxApp.swift`** calls `Feedback.setUp(product: "instant-record-inbox",
|
|
190
|
+
relay:)` once and registers the form as `FeedbackForm`. The member and
|
|
191
|
+
inbox are listed under the note as "From" and "Inbox" with the rest of
|
|
192
|
+
what is sent.
|
|
193
|
+
- **It comes up as a sheet.** The menu item says `sheet: "feedback"`, and
|
|
194
|
+
the renderer presents that screen over the mailbox, the way the library
|
|
195
|
+
means its form to be used. The form has its own bar, with Cancel and Send,
|
|
196
|
+
and closes the sheet itself.
|
|
197
|
+
- **Nothing is filed yet.** The relay files only for the products in its own
|
|
198
|
+
list, and `instant-record-inbox` is not in it. Send is answered with "This
|
|
199
|
+
form is not set up to send feedback yet.", shown in red under the form, and
|
|
200
|
+
the note stays where it was. Adding the product is a line in the relay's
|
|
201
|
+
`PRODUCTS` and a deploy, which is the relay owner's to do. With no
|
|
202
|
+
connection the form says "That couldn’t be sent. Check your connection and
|
|
203
|
+
try again."
|
|
204
|
+
- `-relay http://localhost:8787` sends to another relay: `node relay/demo.js`
|
|
205
|
+
in the library's `feedback` folder runs one on this Mac that sends nothing
|
|
206
|
+
anywhere.
|
|
207
|
+
|
|
208
|
+
## What the renderer draws
|
|
209
|
+
|
|
210
|
+
| Element | Drawn as |
|
|
211
|
+
|---|---|
|
|
212
|
+
| `navigation title:` | the bar's title: large on the first screen, inline on pushed ones |
|
|
213
|
+
| `list`, `section` | `List`, `Section`; `refreshable: true` adds pull to refresh |
|
|
214
|
+
| `row` | a list row kept by its `id` and read aloud as one thing; with `link:` a `NavigationLink` |
|
|
215
|
+
| `stack`, `spacer` | `VStack` or `HStack`, `Spacer` |
|
|
216
|
+
| `text`, `date`, `image` | `Text` in a system style, a date in the phone's language, an icon |
|
|
217
|
+
| `button`, `swipe` | `Button`, a swipe action; a destructive swipe is tinted red |
|
|
218
|
+
| `toolbar` | bar buttons on the side `position:` names; a button with `item`s is a `Menu` |
|
|
219
|
+
| `field`, `bottom` | `TextField` (one that grows with `multiline:`), a bar pinned under the screen |
|
|
220
|
+
| `more` | a spinner at the foot of the list while the next page loads, or a line to tap when it could not |
|
|
221
|
+
| `swift` | the registered SwiftUI view |
|
|
222
|
+
|
|
223
|
+
## How it looks
|
|
224
|
+
|
|
225
|
+
`AppView(host: host, theme: .cora)` gives the app a look. A `Theme`
|
|
226
|
+
(`Theme.swift`) is a few colours and two faces: the page, a row's surface, a
|
|
227
|
+
quiet fill, a hairline, ink, muted ink, the tint of links and buttons, an
|
|
228
|
+
accent fill with the ink that goes on it, the face of labels and controls,
|
|
229
|
+
and the face of what is read. The stock elements use it: a list's ground,
|
|
230
|
+
rows and separators, `tone: "secondary"` and `tone: "accent"`, the status
|
|
231
|
+
line, the reply box and its bar, the foot of a list, and the bar's titles.
|
|
232
|
+
A `text` with no `style:` is running text and is set in the reading face.
|
|
233
|
+
A hand-written view reads the same value with `@Environment(\.theme)`.
|
|
234
|
+
|
|
235
|
+
With no theme the app is iOS as it comes (`Theme.system`), which is what a
|
|
236
|
+
generated app starts with.
|
|
237
|
+
|
|
238
|
+
The Inbox uses `Theme.cora`: warm paper (#FBF8F2), white rows, stone ink
|
|
239
|
+
(#302B26), one blue (#2F6CA3 for links, #86B2D9 as a fill under dark text),
|
|
240
|
+
flat, with hairlines. In the dark it is the same ramp from the other end:
|
|
241
|
+
a stone-950 page, stone-900 rows, stone-100 ink and the lighter blue.
|
|
242
|
+
Cora's own typefaces are licensed and are not in this repo. The system's
|
|
243
|
+
rounded face stands in for headlines and controls and its serif for a
|
|
244
|
+
message's subject and body. Sizes are system text styles, so Dynamic Type
|
|
245
|
+
works as before, and a test holds every text and ground pair to AA contrast
|
|
246
|
+
in both appearances.
|
|
247
|
+
|
|
248
|
+
A sheet takes the theme too: its paper, its tint and its faces. The
|
|
249
|
+
feedback form is drawn by its library, so the theme reaches the sheet
|
|
250
|
+
around it (the paper, the blue of Cancel and Send, the face), not the
|
|
251
|
+
form's own fields.
|
|
252
|
+
|
|
253
|
+
## Sync, and what the app tells you
|
|
254
|
+
|
|
255
|
+
Every call into the library runs on one thread, and none of them waits for
|
|
256
|
+
the network. A sync pass asks the library what it will want (`sync_plan`,
|
|
257
|
+
`cursor`), fetches that on another queue, and then lets the library sync
|
|
258
|
+
against those answers alone. A tap made meanwhile is performed and drawn
|
|
259
|
+
first, and what it wrote goes out with a pass of its own.
|
|
260
|
+
|
|
261
|
+
The app decides when to sync (`SyncSchedule.swift`). A tap asks for a pass,
|
|
262
|
+
and taps close together share one. A pass that could not reach the server,
|
|
263
|
+
was refused, or left writes waiting is tried again after 5 seconds, then 10,
|
|
264
|
+
up to a minute. The network coming back runs one at once. While the app is
|
|
265
|
+
in front it follows the server's events (`StreamClient.swift`): it asks
|
|
266
|
+
`events?after=<cursor>`, hands what arrives to the library, and asks again a
|
|
267
|
+
second after a clean end, so a change made elsewhere shows without a touch.
|
|
268
|
+
|
|
269
|
+
One line over the navigation bar says, in this order: what went wrong ("Could not
|
|
270
|
+
sync: POST /mutations answered 401", or what Ruby raised), that the app is
|
|
271
|
+
offline, or how many changes are waiting to send. An error stays until it is
|
|
272
|
+
dismissed or a pass succeeds. A screen that cannot be drawn keeps the last
|
|
273
|
+
one that could.
|
|
274
|
+
|
|
275
|
+
Each account has its own SQLite file, because one file syncs with one
|
|
276
|
+
address. The app says which (`AppHost.Store`). The files are kept: nothing
|
|
277
|
+
deletes one but a launch with `-reset YES`.
|
|
278
|
+
|
|
279
|
+
Switching account does not wait for the network. The host closes the
|
|
280
|
+
database being left, opens the other (`ir_open`) and draws it from what is
|
|
281
|
+
on the phone, and only then syncs it. "Getting your mail" shows only for a
|
|
282
|
+
file that has never synced. Writes still waiting in the database being left
|
|
283
|
+
get one pass first, for at most a second (`leaveWithin`). What did not go
|
|
284
|
+
out by then waits in that file until it is opened again.
|
|
285
|
+
|
|
286
|
+
## Developing: no rebuild after an edit
|
|
287
|
+
|
|
288
|
+
```sh
|
|
289
|
+
xcrun simctl launch booted dev.instantrecord.Inbox -server http://localhost:3000 -dev YES
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
In this mode the phone asks Rails for each screen and sends it each tap, so
|
|
293
|
+
an edit to a screen's Ruby shows after a pull. The same screen classes run
|
|
294
|
+
on the server. There is no database on the phone and nothing works offline.
|
|
295
|
+
|
|
296
|
+
Turn it on in the app's development environment:
|
|
297
|
+
|
|
298
|
+
```ruby
|
|
299
|
+
config.instant_record.native_dev = true
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
The endpoints run a screen's actions as whoever the params name. They answer
|
|
303
|
+
404 unless that setting is on, the environment is local, and the request
|
|
304
|
+
comes from this machine with a JSON content type, and they send no CORS
|
|
305
|
+
headers, so a web page open in the developer's browser cannot reach them.
|
|
306
|
+
|
|
307
|
+
## The token
|
|
308
|
+
|
|
309
|
+
`Transport` takes a `prepare` closure that sees every request before it
|
|
310
|
+
goes. The Inbox uses it to send `Authorization: Bearer <token>` when it is
|
|
311
|
+
launched with `-token`. `bin/rails 'inbox:token[maya]'` prints one.
|
|
312
|
+
|
|
313
|
+
In the demo this is not what keeps mail private. Its members are public
|
|
314
|
+
personas, and a request with no token is served, so that the browser demo
|
|
315
|
+
works as before. Started with `INBOX_REQUIRE_TOKEN=1` the demo refuses a
|
|
316
|
+
request without a valid token. The gem's own sync endpoints do not check
|
|
317
|
+
it. An app with private data must require the token and take the member
|
|
318
|
+
from it, not from the address. There is no sign-in screen yet.
|
|
319
|
+
|
|
320
|
+
## Tests
|
|
321
|
+
|
|
322
|
+
- `swift test` in `InstantRecordNative` runs the package's tests on the Mac.
|
|
323
|
+
- `native/ios/ui-test.sh` runs the Inbox's flows in the simulator. It
|
|
324
|
+
recreates a database of its own (`postgres:///instant_record_native_ui`),
|
|
325
|
+
seeds a fixed inbox, starts the demo with a token required, and stops it
|
|
326
|
+
afterwards, so it can be run again and again. It covers open and read,
|
|
327
|
+
reply, archive, switching inbox, unread only, the feedback form, opening
|
|
328
|
+
again with no arguments, older mail, a message
|
|
329
|
+
arriving with no touch, pull to refresh, an archive the server refuses,
|
|
330
|
+
an archive made offline that goes out when the server returns, and the
|
|
331
|
+
main controls in dark mode at the largest text size. The script refuses
|
|
332
|
+
to start when something already answers on its port.
|
|
333
|
+
|
|
334
|
+
## What has run, and what has not
|
|
335
|
+
|
|
336
|
+
On macOS arm64 with Xcode 27.2, in the iPhone 17 simulator on iOS 26.5:
|
|
337
|
+
everything above, and a fresh `rails new` app with one synced model and one
|
|
338
|
+
screen, generated, built and launched twice.
|
|
339
|
+
|
|
340
|
+
Not signed or run on a phone. No Android renderer, no tab bar, no sign-in
|
|
341
|
+
screen. In the development mode there is no paging and no event stream.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Explicit types for the compiled Inertia page responder. Roundhouse reads this
|
|
2
|
+
# file from the staged app (lib/instant_record/compiler/gem_vendor.rb) so every
|
|
3
|
+
# slot stays monomorphic (String, bool, Array[String]) and Spinel never widens a
|
|
4
|
+
# controller prop into a polymorphic Hash.
|
|
5
|
+
module InstantRecord
|
|
6
|
+
module Inertia
|
|
7
|
+
class Page
|
|
8
|
+
@component: String
|
|
9
|
+
@url: String
|
|
10
|
+
@version: String
|
|
11
|
+
@inertia: bool
|
|
12
|
+
@partial: bool
|
|
13
|
+
@only: Array[String]
|
|
14
|
+
@except: Array[String]
|
|
15
|
+
@prop_keys: Array[String]
|
|
16
|
+
@prop_values: Array[String]
|
|
17
|
+
@live_keys: Array[String]
|
|
18
|
+
@live_values: Array[String]
|
|
19
|
+
|
|
20
|
+
attr_reader component: String
|
|
21
|
+
attr_reader url: String
|
|
22
|
+
attr_reader version: String
|
|
23
|
+
|
|
24
|
+
def self.for_request: (String component, ActionDispatch::Request? request, ?version: String) -> InstantRecord::Inertia::Page
|
|
25
|
+
def self.header_list: (String value) -> Array[String]
|
|
26
|
+
def self.quote: (String value) -> String
|
|
27
|
+
def self.json_strings: (Array[String] values) -> String
|
|
28
|
+
|
|
29
|
+
def initialize: (String component, String url, bool inertia, String partial_component, String partial_data, String partial_except, ?String version) -> void
|
|
30
|
+
def inertia?: () -> bool
|
|
31
|
+
def partial?: () -> bool
|
|
32
|
+
def want?: (String name) -> bool
|
|
33
|
+
def string: (String name, String value) -> nil
|
|
34
|
+
def int: (String name, Integer value) -> nil
|
|
35
|
+
def bool: (String name, bool value) -> nil
|
|
36
|
+
def strings: (String name, Array[String] values) -> nil
|
|
37
|
+
def raw: (String name, String encoded) -> nil
|
|
38
|
+
def always_raw: (String name, String encoded) -> nil
|
|
39
|
+
def lazy: (String name) { () -> String } -> nil
|
|
40
|
+
def live: (String name, String event) { () -> String } -> nil
|
|
41
|
+
def live_many: (String name, Array[String] events) { () -> String } -> nil
|
|
42
|
+
def json: () -> String
|
|
43
|
+
def put_json: (String name, String encoded) -> nil
|
|
44
|
+
def register_live: (String name, Array[String] events) -> nil
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# The types of a screen's own parts. Ruby does not read this file. The build
|
|
2
|
+
# that compiles screens for a phone does (lib/instant_record/compiler/gem_vendor.rb):
|
|
3
|
+
# its compilers type a whole app by inference, and without these lines the
|
|
4
|
+
# hashes a screen hands to `params:` and `args:` take whatever type the app's
|
|
5
|
+
# call sites add up to. Here they are hashes of strings, so a screen that
|
|
6
|
+
# hands over anything else fails the build at that line.
|
|
7
|
+
module InstantRecord
|
|
8
|
+
module Native
|
|
9
|
+
class Node
|
|
10
|
+
attr_reader kind: String
|
|
11
|
+
attr_reader props: Hash[String, String]
|
|
12
|
+
attr_reader children: Array[untyped]
|
|
13
|
+
attr_accessor id: String
|
|
14
|
+
attr_accessor text: String
|
|
15
|
+
attr_accessor action: String
|
|
16
|
+
attr_accessor link_params: Hash[String, String]
|
|
17
|
+
attr_accessor args: Hash[String, String]
|
|
18
|
+
def self.strings: () -> Hash[String, String]
|
|
19
|
+
def set: (String name, String value) -> nil
|
|
20
|
+
def json: () -> String
|
|
21
|
+
def write: (String out) -> String
|
|
22
|
+
def self.quote: (String value) -> String
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class Screen
|
|
26
|
+
def open_with: (Hash[String, String] params) -> Hash[String, String]
|
|
27
|
+
def self.strings: (untyped parsed) -> Hash[String, String]
|
|
28
|
+
def param: (String name) -> String
|
|
29
|
+
def row: (?id: String, ?link: String, ?params: Hash[String, String]) -> InstantRecord::Native::Node
|
|
30
|
+
def button: (String label, ?action: String, ?args: Hash[String, String], ?role: String, ?image: String, ?position: String) -> InstantRecord::Native::Node
|
|
31
|
+
def item: (String title, ?action: String, ?args: Hash[String, String], ?link: String, ?replace: String, ?sheet: String, ?params: Hash[String, String], ?image: String, ?role: String, ?selected: bool) -> InstantRecord::Native::Node
|
|
32
|
+
def swipe: (String label, action: String, ?args: Hash[String, String], ?role: String, ?edge: String, ?image: String) -> InstantRecord::Native::Node
|
|
33
|
+
def field: (String name, ?label: String, ?value: String, ?multiline: bool) -> InstantRecord::Native::Node
|
|
34
|
+
def more: (String key, query: String) -> InstantRecord::Native::Node
|
|
35
|
+
def act: (InstantRecord::Native::Node node, String label, String action, Hash[String, String] args, String role) -> nil
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|