@native-sdk/cli 0.8.3 → 0.9.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.
- package/build/app.zig +905 -61
- package/build.zig +674 -373
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +6 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +455 -3
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_typecheck.mjs +116 -15
- package/packages/core/scripts/gen_service_surface.mjs +268 -0
- package/packages/core/scripts/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +240 -0
- package/packages/core/scripts/stage_external_core.mjs +9 -1
- package/packages/core/scripts/stage_external_services.mjs +172 -0
- package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
- package/packages/core/scripts/vendor_service_packages.mjs +189 -0
- package/packages/core/sdk/core.d.ts +214 -2
- package/packages/core/sdk/core.ts +715 -42
- package/packages/core/sdk/events.d.ts +50 -0
- package/packages/core/sdk/events.ts +75 -0
- package/packages/core/src/checker.ts +528 -15
- package/packages/core/src/cli.ts +143 -3
- package/packages/core/src/contract.ts +26 -5
- package/packages/core/src/devhost.ts +1849 -18
- package/packages/core/src/devhost_journal.mjs +181 -0
- package/packages/core/src/devhost_resolver.mjs +17 -1
- package/packages/core/src/devhost_service_worker.mjs +90 -0
- package/packages/core/src/diagnostics.ts +84 -18
- package/packages/core/src/frontend.ts +204 -34
- package/packages/core/src/modules.ts +129 -80
- package/packages/core/src/service_contract.ts +597 -0
- package/packages/core/src/sqlite_cli.ts +93 -0
- package/packages/core/src/sqlite_codegen.ts +806 -0
- package/packages/core/src/sqlite_runtime_policy.ts +364 -0
- package/packages/core/src/typed_ast.ts +36 -8
- package/skill-data/core/SKILL.md +4 -2
- package/skill-data/core/references/project-anatomy.md +3 -2
- package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
- package/skill-data/native-ui/SKILL.md +55 -8
- package/skill-data/ts-core/SKILL.md +92 -40
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +603 -0
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/no_migrations.zig +3 -0
- package/src/app_runner/no_services.zig +20 -0
- package/src/app_runner/root.zig +104 -4
- package/src/app_runner/ts_core_main.zig +268 -4
- package/src/automation/snapshot.zig +23 -5
- package/src/embed/app_exports.zig +11 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +115 -1
- package/src/embed/root.zig +7 -0
- package/src/embed/tests.zig +213 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +121 -5
- package/src/platform/android/NativeSdkActivity.java +131 -0
- package/src/platform/android/android_host.c +182 -1
- package/src/platform/android/native_sdk_app.h +17 -0
- package/src/platform/ios/native_sdk_app.h +17 -0
- package/src/platform/ios/uikit_host.m +115 -0
- package/src/platform/linux/cef_host.cpp +1 -1
- package/src/platform/linux/gtk_host.c +89 -17
- package/src/platform/linux/gtk_host.h +3 -0
- package/src/platform/linux/root.zig +41 -18
- package/src/platform/macos/appkit_host.h +26 -3
- package/src/platform/macos/appkit_host.m +1051 -129
- package/src/platform/macos/capture_info_plist.c +25 -0
- package/src/platform/macos/cef_host.mm +270 -36
- package/src/platform/macos/root.zig +312 -34
- package/src/platform/null_platform.zig +281 -19
- package/src/platform/null_platform_tests.zig +74 -0
- package/src/platform/root.zig +16 -0
- package/src/platform/types.zig +279 -15
- package/src/platform/windows/root.zig +243 -21
- package/src/platform/windows/webview2_host.cpp +464 -46
- package/src/primitives/app_manifest/comptime_scene.zig +2 -0
- package/src/primitives/app_manifest/root.zig +4 -0
- package/src/primitives/app_manifest/tests.zig +3 -0
- package/src/primitives/app_manifest/types.zig +34 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/primitives/canvas/code_tests.zig +9 -9
- package/src/primitives/canvas/events.zig +12 -11
- package/src/primitives/canvas/frame.zig +44 -9
- package/src/primitives/canvas/icons/mic.svg +1 -0
- package/src/primitives/canvas/icons.zig +2 -0
- package/src/primitives/canvas/root.zig +8 -0
- package/src/primitives/canvas/text_span_tests.zig +39 -0
- package/src/primitives/canvas/ui.zig +23 -4
- package/src/primitives/canvas/ui_markup.zig +15 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
- package/src/primitives/canvas/ui_markup_tests.zig +5 -0
- package/src/primitives/canvas/ui_markup_view.zig +9 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
- package/src/primitives/canvas/ui_schema.zig +19 -10
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +18 -4
- package/src/primitives/canvas/widget_invalidation.zig +9 -2
- package/src/primitives/canvas/widget_render.zig +296 -114
- package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
- package/src/primitives/canvas/widget_text_input.zig +10 -10
- package/src/primitives/canvas/widget_tree.zig +1 -1
- package/src/primitives/canvas/widgets.zig +29 -5
- package/src/root.zig +56 -0
- package/src/runtime/api.zig +11 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/automation_widget_dispatch.zig +1 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/bridge_permission_tests.zig +23 -2
- package/src/runtime/bridge_responses.zig +3 -1
- package/src/runtime/canvas_frame.zig +31 -13
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
- package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
- package/src/runtime/canvas_widget_events.zig +69 -24
- package/src/runtime/canvas_widget_runtime.zig +101 -6
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
- package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
- package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +112 -3
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +133 -1
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +2568 -75
- package/src/runtime/effects_audio_capture_tests.zig +251 -0
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/flow.zig +14 -1
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +42 -0
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +52 -0
- package/src/runtime/runtime_event_tests.zig +70 -0
- package/src/runtime/service_host.zig +711 -0
- package/src/runtime/service_pool.zig +1314 -0
- package/src/runtime/session_blobs.zig +1 -1
- package/src/runtime/session_journal.zig +102 -0
- package/src/runtime/session_record.zig +177 -0
- package/src/runtime/session_replay.zig +109 -4
- package/src/runtime/shell_layout.zig +1 -0
- package/src/runtime/shell_layout_tests.zig +120 -0
- package/src/runtime/sqlite_engine.zig +474 -0
- package/src/runtime/state.zig +6 -0
- package/src/runtime/system_services.zig +49 -10
- package/src/runtime/tests.zig +5 -0
- package/src/runtime/ts_core_host.zig +1189 -118
- package/src/runtime/ts_core_host_tests.zig +638 -11
- package/src/runtime/ts_ui_app.zig +537 -1
- package/src/runtime/ui_app.zig +160 -19
- package/src/runtime/ui_app_tests.zig +203 -5
- package/src/runtime/validation.zig +22 -0
- package/src/runtime/view.zig +11 -0
- package/src/runtime/view_widget_scroll.zig +56 -5
- package/src/runtime/view_widget_text.zig +24 -5
- package/src/runtime/view_widget_tree.zig +1 -1
- package/src/runtime/window_storage.zig +1 -0
- package/src/runtime/window_view_runtime.zig +2 -3
- package/src/runtime/window_views.zig +19 -0
- package/src/tooling/android.zig +21 -16
- package/src/tooling/db.zig +160 -0
- package/src/tooling/ios.zig +7 -1
- package/src/tooling/manifest.zig +1248 -2
- package/src/tooling/package.zig +953 -6
- package/src/tooling/raw_manifest.zig +65 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +216 -4
- package/src/tooling/ts_core.zig +283 -17
- package/src/tooling/verbs.zig +7 -0
- package/third_party/sqlite/README.md +13 -0
- package/third_party/sqlite/sqlite3.c +269649 -0
- package/third_party/sqlite/sqlite3.h +14349 -0
- package/tools/corewire/core_abi.zig +14 -2
- package/tools/corewire/emit.zig +98 -29
- package/tools/corewire/emit_facade.zig +414 -23
- package/tools/corewire/emit_profile.zig +6 -2
- package/tools/corewire/emit_service.zig +924 -0
- package/tools/corewire/main.zig +122 -0
- package/tools/corewire/service_contract.zig +250 -0
- package/tools/corewire/sidecar.zig +26 -15
package/skill-data/zig/SKILL.md
CHANGED
|
@@ -12,7 +12,7 @@ Two rules resolve most failures:
|
|
|
12
12
|
- Operations on the outside world take a `std.Io` first (or right after the receiver). Get one from `init.io` in `main(init: std.process.Init)`, from `std.testing.io` in tests, or from `std.Io.Threaded` in code with no `Init` to thread through.
|
|
13
13
|
- Containers are unmanaged: initialize with `.empty` and pass the allocator to every mutating call.
|
|
14
14
|
|
|
15
|
-
In a UiApp, `update` never sees an `Io` — persistence, subprocesses, HTTP, clocks, and timers go through the typed effects channel (`fx.readFile`, `fx.spawn`, `fx.fetch`, `fx.wallMs`, `fx.startTimer`; see `native skills get native-ui`). Raw `std.Io` belongs in `main`, tests, and standalone tools. And because Zig analyzes lazily, a 0.15-ism can hide in code only one build path references: run BOTH `zig build` and `zig build test` before calling a change done.
|
|
15
|
+
In a UiApp, `update` never sees an `Io` — persistence, record and relational storage, secure credentials, subprocesses, HTTP, clocks, and timers go through the typed effects channel (`fx.persist`, `fx.storeSet`/`storeGet`/`storeDelete`/`storeScan`/`storeSetMany`, `fx.dbQuery`/`dbExec`, `fx.credentialsSet`/`credentialsGet`/`credentialsDelete`, `fx.readFile`, `fx.spawn`, `fx.fetch`, `fx.wallMs`, `fx.startTimer`; see `native skills get native-ui`). Raw `std.Io` belongs in `main`, tests, and standalone tools. Record-store apps declare `"store"`; relational apps declare `"sqlite"`; credentials require both the `"credentials"` capability and permission. Credential Msg arms carry `EffectCredentialsResult`; consume successful get bytes immediately and never retain them in Model. The engine owns database paths and app-scoped credential namespaces, while every result still returns as a Msg and crosses the replay journal (credential bytes are redacted). Use `TestHarness().createWithRelationalStore` for a hermetic in-memory relational database and `TestHarness().createWithCredentials` for a hermetic in-memory credential store. And because Zig analyzes lazily, a 0.15-ism can hide in code only one build path references: run BOTH `zig build` and `zig build test` before calling a change done.
|
|
16
16
|
|
|
17
17
|
## error: struct 'heap' has no member named 'GeneralPurposeAllocator' — allocators come from `main(init: std.process.Init)`
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ native skills get native-ui
|
|
|
20
20
|
native skills get ts-core
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Use `native skills get core` for initial orientation. For the default app-authoring path, load **both** `native-ui` (views, bindings, the app loop) and `ts-core` (the TypeScript subset, effects, subscriptions, and modules) before implementing. Use `native skills get core --full` when work reaches lower-level runtime wiring, WebViews, bridge/security, native capabilities, packaging, or debugging. Use `native skills get automation` when testing a running app, taking snapshots, requesting reloads, or using the built-in automation server. Use `native skills get zig` only for an existing Zig core, a toolkit extension, SDK implementation work, or a Zig 0.16 compile error.
|
|
23
|
+
Use `native skills get core` for initial orientation. For the default app-authoring path, load **both** `native-ui` (views, bindings, the app loop) and `ts-core` (the TypeScript subset, effects, subscriptions, and modules) before implementing. Load `ts-services` too when the tree has `src/services/` or ordinary TypeScript needs filesystem/process/JSON/regex/Map/Date/class work behind `Cmd.request`. Use `native skills get core --full` when work reaches lower-level runtime wiring, WebViews, bridge/security, native capabilities, packaging, or debugging. Use `native skills get automation` when testing a running app, taking snapshots, requesting reloads, or using the built-in automation server. Use `native skills get zig` only for an existing Zig core, a toolkit extension, SDK implementation work, or a Zig 0.16 compile error.
|
|
24
24
|
|
|
25
25
|
## Quick orientation
|
|
26
26
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//! Generated-runner stub for apps without src/services/.
|
|
2
|
+
pub const enabled = false;
|
|
3
|
+
pub const protocol_version: u8 = 3;
|
|
4
|
+
pub const compiler_version = "";
|
|
5
|
+
pub const inproc_symbol_prefix = "nsc_svc_";
|
|
6
|
+
pub const contract_fingerprint = [_]u8{0} ** 32;
|
|
7
|
+
pub const Operation = struct { name: []const u8, index: u16, deadline_ms: ?u32, cancellable: bool, streaming: bool, in_flight: u8 };
|
|
8
|
+
pub const operations = [_]Operation{};
|
|
9
|
+
pub fn indexOf(name: []const u8) ?u16 {
|
|
10
|
+
_ = name;
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
pub fn operationAt(index: u16) ?Operation {
|
|
14
|
+
_ = index;
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
pub fn isStreaming(index: u16) bool {
|
|
18
|
+
_ = index;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
package/src/app_runner/root.zig
CHANGED
|
@@ -2,6 +2,7 @@ const std = @import("std");
|
|
|
2
2
|
const build_options = @import("build_options");
|
|
3
3
|
const native_sdk = @import("native_sdk");
|
|
4
4
|
const app_manifest = @import("app_manifest_zon");
|
|
5
|
+
const built_relational_migrations = @import("relational_migrations");
|
|
5
6
|
const manifest_shortcuts = if (@hasField(@TypeOf(app_manifest), "shortcuts")) app_manifest.shortcuts else .{};
|
|
6
7
|
const manifest_windows = if (@hasField(@TypeOf(app_manifest), "windows")) app_manifest.windows else .{};
|
|
7
8
|
|
|
@@ -54,6 +55,13 @@ pub const RunOptions = struct {
|
|
|
54
55
|
security: native_sdk.SecurityPolicy = .{},
|
|
55
56
|
menus: []const native_sdk.Menu = &.{},
|
|
56
57
|
shortcuts: ?[]const native_sdk.Shortcut = null,
|
|
58
|
+
/// Filled by `runWithOptions` from the manifest capability. App entry
|
|
59
|
+
/// points do not set this themselves; the field only carries the owned
|
|
60
|
+
/// binding uniformly into each platform's runtime options.
|
|
61
|
+
record_store: ?native_sdk.RecordStoreBinding = null,
|
|
62
|
+
relational_store: ?native_sdk.RelationalStoreBinding = null,
|
|
63
|
+
credentials_enabled: bool = false,
|
|
64
|
+
relational_migrations: []const native_sdk.relational_store.Migration = &built_relational_migrations.migrations,
|
|
57
65
|
|
|
58
66
|
fn appInfo(self: RunOptions, buffers: *StateBuffers) native_sdk.AppInfo {
|
|
59
67
|
var info: native_sdk.AppInfo = .{
|
|
@@ -98,6 +106,7 @@ pub const RunOptions = struct {
|
|
|
98
106
|
info.main_window.always_on_top = manifestShellStartupBool("always_on_top", false);
|
|
99
107
|
info.main_window.click_through = manifestShellStartupBool("click_through", false);
|
|
100
108
|
info.main_window.activate_on_show = manifestShellStartupBool("activate_on_show", true);
|
|
109
|
+
info.main_window.allows_fullscreen = manifestShellStartupBool("allows_fullscreen", true);
|
|
101
110
|
// Min-size floors ride the create call like the titlebar:
|
|
102
111
|
// the scene re-applies size/title later, but the window's
|
|
103
112
|
// enforced floor is host state from the first frame on.
|
|
@@ -164,10 +173,12 @@ fn manifestWindow(comptime window: anytype, comptime index: usize) native_sdk.Wi
|
|
|
164
173
|
.restore_state = windowBool(window, "restore_state", true),
|
|
165
174
|
.restore_policy = windowRestorePolicy(window),
|
|
166
175
|
.titlebar = windowTitlebarStyle(window),
|
|
176
|
+
.show = if (windowBool(window, "initially_hidden", false)) .hidden else .immediate,
|
|
167
177
|
.transparent = windowBool(window, "transparent", false),
|
|
168
178
|
.always_on_top = windowBool(window, "always_on_top", false),
|
|
169
179
|
.click_through = windowBool(window, "click_through", false),
|
|
170
180
|
.activate_on_show = windowBool(window, "activate_on_show", true),
|
|
181
|
+
.allows_fullscreen = windowBool(window, "allows_fullscreen", true),
|
|
171
182
|
.min_width = windowMinSize(window, "min_width"),
|
|
172
183
|
.min_height = windowMinSize(window, "min_height"),
|
|
173
184
|
.close_policy = windowClosePolicy(window),
|
|
@@ -259,6 +270,7 @@ fn manifestShellStartupShowMode() native_sdk.WindowShowMode {
|
|
|
259
270
|
if (comptime !@hasField(@TypeOf(shell), "windows")) return .immediate;
|
|
260
271
|
if (comptime shell.windows.len == 0) return .immediate;
|
|
261
272
|
const window = shell.windows[0];
|
|
273
|
+
if (comptime windowBool(window, "initially_hidden", false)) return .hidden;
|
|
262
274
|
if (comptime !@hasField(@TypeOf(window), "views")) return .immediate;
|
|
263
275
|
inline for (window.views) |view| {
|
|
264
276
|
if (comptime @hasField(@TypeOf(view), "kind")) {
|
|
@@ -431,6 +443,35 @@ fn manifestDeclaresTrayCapability() bool {
|
|
|
431
443
|
return false;
|
|
432
444
|
}
|
|
433
445
|
|
|
446
|
+
/// Whether app.zon declares the Tier-2 record store. This is comptime so
|
|
447
|
+
/// apps without the capability never analyze the SQLite open/deinit path.
|
|
448
|
+
fn manifestDeclaresStore() bool {
|
|
449
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "capabilities")) return false;
|
|
450
|
+
inline for (app_manifest.capabilities) |capability| {
|
|
451
|
+
const name: []const u8 = capability;
|
|
452
|
+
if (comptime std.mem.eql(u8, name, "store")) return true;
|
|
453
|
+
}
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
fn manifestDeclaresSqlite() bool {
|
|
458
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "capabilities")) return false;
|
|
459
|
+
inline for (app_manifest.capabilities) |capability| {
|
|
460
|
+
const name: []const u8 = capability;
|
|
461
|
+
if (comptime std.mem.eql(u8, name, "sqlite")) return true;
|
|
462
|
+
}
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
fn manifestDeclaresCredentials() bool {
|
|
467
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "capabilities")) return false;
|
|
468
|
+
inline for (app_manifest.capabilities) |capability| {
|
|
469
|
+
const name: []const u8 = capability;
|
|
470
|
+
if (comptime std.mem.eql(u8, name, "credentials")) return true;
|
|
471
|
+
}
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
|
|
434
475
|
fn shortcutModifiers(comptime shortcut: anytype) native_sdk.ShortcutModifiers {
|
|
435
476
|
const values = if (@hasField(@TypeOf(shortcut), "modifiers")) shortcut.modifiers else .{};
|
|
436
477
|
var modifiers: native_sdk.ShortcutModifiers = .{};
|
|
@@ -462,14 +503,61 @@ pub fn runWithOptions(app: native_sdk.App, options: RunOptions, init: std.proces
|
|
|
462
503
|
if (init.environ_map.get("NATIVE_SDK_SESSION_REPLAY")) |journal_path| {
|
|
463
504
|
return runSessionReplay(app, options, init, journal_path);
|
|
464
505
|
}
|
|
506
|
+
const RecordStoreType = if (comptime manifestDeclaresStore()) native_sdk.RecordStore else void;
|
|
507
|
+
var record_store_value: RecordStoreType = undefined;
|
|
508
|
+
var record_store_open = false;
|
|
509
|
+
var resolved_options = options;
|
|
510
|
+
resolved_options.credentials_enabled = manifestDeclaresCredentials();
|
|
511
|
+
if (comptime manifestDeclaresStore()) {
|
|
512
|
+
var data_dir_buffer: [512]u8 = undefined;
|
|
513
|
+
const app_data_dir = native_sdk.app_dirs.resolveOne(
|
|
514
|
+
.{ .name = options.bundle_id },
|
|
515
|
+
native_sdk.app_dirs.currentPlatform(),
|
|
516
|
+
native_sdk.debug.envFromMap(init.environ_map),
|
|
517
|
+
.data,
|
|
518
|
+
&data_dir_buffer,
|
|
519
|
+
) catch return error.StoreDataDirUnavailable;
|
|
520
|
+
try std.Io.Dir.cwd().createDirPath(init.io, app_data_dir);
|
|
521
|
+
record_store_value = try native_sdk.RecordStore.open(std.heap.page_allocator, app_data_dir);
|
|
522
|
+
record_store_open = true;
|
|
523
|
+
resolved_options.record_store = record_store_value.binding();
|
|
524
|
+
}
|
|
525
|
+
defer if (comptime manifestDeclaresStore()) {
|
|
526
|
+
if (record_store_open) record_store_value.deinit();
|
|
527
|
+
};
|
|
528
|
+
const RelationalStoreType = if (comptime manifestDeclaresSqlite()) native_sdk.RelationalStore else void;
|
|
529
|
+
var relational_store_value: RelationalStoreType = undefined;
|
|
530
|
+
var relational_store_open = false;
|
|
531
|
+
if (comptime manifestDeclaresSqlite()) {
|
|
532
|
+
var data_dir_buffer: [512]u8 = undefined;
|
|
533
|
+
const app_data_dir = native_sdk.app_dirs.resolveOne(
|
|
534
|
+
.{ .name = options.bundle_id },
|
|
535
|
+
native_sdk.app_dirs.currentPlatform(),
|
|
536
|
+
native_sdk.debug.envFromMap(init.environ_map),
|
|
537
|
+
.data,
|
|
538
|
+
&data_dir_buffer,
|
|
539
|
+
) catch return error.SqliteDataDirUnavailable;
|
|
540
|
+
try std.Io.Dir.cwd().createDirPath(init.io, app_data_dir);
|
|
541
|
+
const open_result = try native_sdk.RelationalStore.openMigrated(std.heap.page_allocator, app_data_dir, options.relational_migrations);
|
|
542
|
+
switch (open_result.outcome) {
|
|
543
|
+
.ok => relational_store_value = open_result.database.?,
|
|
544
|
+
.migrate_failed => return error.SqliteMigrationFailed,
|
|
545
|
+
.version_unknown => return error.SqliteVersionUnknown,
|
|
546
|
+
}
|
|
547
|
+
relational_store_open = true;
|
|
548
|
+
resolved_options.relational_store = relational_store_value.binding();
|
|
549
|
+
}
|
|
550
|
+
defer if (comptime manifestDeclaresSqlite()) {
|
|
551
|
+
if (relational_store_open) relational_store_value.deinit();
|
|
552
|
+
};
|
|
465
553
|
if (comptime std.mem.eql(u8, build_options.platform, "macos")) {
|
|
466
|
-
try runMacos(app,
|
|
554
|
+
try runMacos(app, resolved_options, init);
|
|
467
555
|
} else if (comptime std.mem.eql(u8, build_options.platform, "linux")) {
|
|
468
|
-
try runLinux(app,
|
|
556
|
+
try runLinux(app, resolved_options, init);
|
|
469
557
|
} else if (comptime std.mem.eql(u8, build_options.platform, "windows")) {
|
|
470
|
-
try runWindows(app,
|
|
558
|
+
try runWindows(app, resolved_options, init);
|
|
471
559
|
} else {
|
|
472
|
-
try runNull(app,
|
|
560
|
+
try runNull(app, resolved_options, init);
|
|
473
561
|
}
|
|
474
562
|
}
|
|
475
563
|
|
|
@@ -525,6 +613,9 @@ fn runNull(app: native_sdk.App, options: RunOptions, init: std.process.Init) !vo
|
|
|
525
613
|
.shortcuts = shortcuts,
|
|
526
614
|
.automation = if (build_options.automation) native_sdk.automation.Server.init(init.io, ".zig-cache/native-sdk-automation", app_info.resolvedWindowTitle()) else null,
|
|
527
615
|
.window_state_store = store,
|
|
616
|
+
.record_store = options.record_store,
|
|
617
|
+
.relational_store = options.relational_store,
|
|
618
|
+
.credentials_enabled = options.credentials_enabled,
|
|
528
619
|
.environ = init.minimal.environ,
|
|
529
620
|
.session_recorder = session_recorder,
|
|
530
621
|
});
|
|
@@ -589,6 +680,9 @@ fn runMacos(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
589
680
|
.shortcuts = shortcuts,
|
|
590
681
|
.automation = if (build_options.automation) native_sdk.automation.Server.init(init.io, ".zig-cache/native-sdk-automation", app_info.resolvedWindowTitle()) else null,
|
|
591
682
|
.window_state_store = store,
|
|
683
|
+
.record_store = options.record_store,
|
|
684
|
+
.relational_store = options.relational_store,
|
|
685
|
+
.credentials_enabled = options.credentials_enabled,
|
|
592
686
|
.environ = init.minimal.environ,
|
|
593
687
|
.session_recorder = session_recorder,
|
|
594
688
|
});
|
|
@@ -650,6 +744,9 @@ fn runLinux(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
650
744
|
.shortcuts = shortcuts,
|
|
651
745
|
.automation = if (build_options.automation) native_sdk.automation.Server.init(init.io, ".zig-cache/native-sdk-automation", app_info.resolvedWindowTitle()) else null,
|
|
652
746
|
.window_state_store = store,
|
|
747
|
+
.record_store = options.record_store,
|
|
748
|
+
.relational_store = options.relational_store,
|
|
749
|
+
.credentials_enabled = options.credentials_enabled,
|
|
653
750
|
.environ = init.minimal.environ,
|
|
654
751
|
.session_recorder = session_recorder,
|
|
655
752
|
});
|
|
@@ -710,6 +807,9 @@ fn runWindows(app: native_sdk.App, options: RunOptions, init: std.process.Init)
|
|
|
710
807
|
.shortcuts = shortcuts,
|
|
711
808
|
.automation = if (build_options.automation) native_sdk.automation.Server.init(init.io, ".zig-cache/native-sdk-automation", app_info.resolvedWindowTitle()) else null,
|
|
712
809
|
.window_state_store = store,
|
|
810
|
+
.record_store = options.record_store,
|
|
811
|
+
.relational_store = options.relational_store,
|
|
812
|
+
.credentials_enabled = options.credentials_enabled,
|
|
713
813
|
.environ = init.minimal.environ,
|
|
714
814
|
.session_recorder = session_recorder,
|
|
715
815
|
});
|
|
@@ -25,8 +25,12 @@
|
|
|
25
25
|
//! from src/app.native in Debug.
|
|
26
26
|
//! menus/shortcuts a core exporting `commandMsg(name): Msg | null`
|
|
27
27
|
//! receives command events (menus, shortcuts, chrome
|
|
28
|
-
//! tabs) as ordinary Msgs; without
|
|
29
|
-
//! events stay host-handled only.
|
|
28
|
+
//! tabs, status-item rows) as ordinary Msgs; without
|
|
29
|
+
//! the export command events stay host-handled only.
|
|
30
|
+
//! status item a core exporting `statusItem(model)` supplies the
|
|
31
|
+
//! install-time icon/click hooks and live menu-bar
|
|
32
|
+
//! presentation + rows; the adapter patches the two
|
|
33
|
+
//! live parts independently after committed updates.
|
|
30
34
|
//! host events the adapter wires the core's opt-in channels from
|
|
31
35
|
//! its exports (export exists -> wired): `frameMsg`
|
|
32
36
|
//! (presented frames), `keyMsg` (the app-level key
|
|
@@ -44,7 +48,11 @@
|
|
|
44
48
|
//! variable present at launch as one journaled Msg on
|
|
45
49
|
//! its bytes arm, right after the boot command — the
|
|
46
50
|
//! core itself never reads the environment (NS1005),
|
|
47
|
-
//! and replay carries the recorded values.
|
|
51
|
+
//! and replay carries the recorded values. The runner
|
|
52
|
+
//! synthesizes `NATIVE_SDK_APP_DATA_DIR` from app_dirs
|
|
53
|
+
//! when a core requests it, so packaged apps never
|
|
54
|
+
//! depend on their process working directory for
|
|
55
|
+
//! durable files.
|
|
48
56
|
//!
|
|
49
57
|
//! Editing this file is never core-level work: it carries no app logic and
|
|
50
58
|
//! regenerates from the SDK on every build.
|
|
@@ -54,6 +62,9 @@ const runner = @import("runner");
|
|
|
54
62
|
const native_sdk = @import("native_sdk");
|
|
55
63
|
const manifest = @import("app_manifest_zon");
|
|
56
64
|
pub const core = @import("core.zig");
|
|
65
|
+
const services = @import("services.zig");
|
|
66
|
+
const service_carrier = @import("service_carrier.zig");
|
|
67
|
+
const relational_migrations = @import("migrations.zig");
|
|
57
68
|
|
|
58
69
|
pub const panic = std.debug.FullPanic(native_sdk.debug.capturePanic);
|
|
59
70
|
|
|
@@ -71,6 +82,7 @@ pub const app_markup = @embedFile("app.native");
|
|
|
71
82
|
|
|
72
83
|
const app_permissions = manifestStringList(manifest, "permissions");
|
|
73
84
|
const allowed_origins = manifestAllowedOrigins();
|
|
85
|
+
const app_data_dir_env = "NATIVE_SDK_APP_DATA_DIR";
|
|
74
86
|
|
|
75
87
|
pub fn main(init: std.process.Init) !void {
|
|
76
88
|
var options: Adapter.Options = .{
|
|
@@ -106,6 +118,68 @@ pub fn main(init: std.process.Init) !void {
|
|
|
106
118
|
.cache,
|
|
107
119
|
&cache_dir_buffer,
|
|
108
120
|
) catch "";
|
|
121
|
+
// The durable per-app data directory, resolved by the platform app-data
|
|
122
|
+
// convention and keyed by the manifest's stable bundle identity. TS cores
|
|
123
|
+
// request it through the ordinary journaled envMsgs boundary under
|
|
124
|
+
// `app_data_dir_env`; it is framework-provided rather than trusted from
|
|
125
|
+
// the ambient environment, so package launch cwd and env differences
|
|
126
|
+
// disappear.
|
|
127
|
+
var data_dir_buffer: [512]u8 = undefined;
|
|
128
|
+
const app_data_dir = native_sdk.app_dirs.resolveOne(
|
|
129
|
+
// Durable state follows the reverse-DNS bundle identity, not the
|
|
130
|
+
// mutable short machine name. Two installed apps may share a name;
|
|
131
|
+
// their manifest ids are the stable isolation boundary.
|
|
132
|
+
.{ .name = manifest.id },
|
|
133
|
+
native_sdk.app_dirs.currentPlatform(),
|
|
134
|
+
native_sdk.debug.envFromMap(init.environ_map),
|
|
135
|
+
.data,
|
|
136
|
+
&data_dir_buffer,
|
|
137
|
+
) catch "";
|
|
138
|
+
if (app_data_dir.len > 0) std.Io.Dir.cwd().createDirPath(init.io, app_data_dir) catch {};
|
|
139
|
+
|
|
140
|
+
// TypeScript services, on the build-selected carrier (service_carrier.zig).
|
|
141
|
+
// In-process (explicit opt-in): the service archive is linked into this
|
|
142
|
+
// binary and ServicePool runs one instance per worker thread. Child (the
|
|
143
|
+
// auto/default carrier): a lazily-spawned sibling executable with an
|
|
144
|
+
// explicit environment allowlist and the app data directory as its cwd.
|
|
145
|
+
// Either way, replay never calls the binding, so nothing starts under replay.
|
|
146
|
+
const use_pool = comptime (services.enabled and service_carrier.kind == .in_process);
|
|
147
|
+
const use_child = comptime (services.enabled and !use_pool);
|
|
148
|
+
var service_env = std.process.Environ.Map.init(std.heap.page_allocator);
|
|
149
|
+
defer service_env.deinit();
|
|
150
|
+
var service_path_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
|
|
151
|
+
const ChildTransport = native_sdk.ServiceHost(services);
|
|
152
|
+
const PoolTransport = native_sdk.ServicePool(services);
|
|
153
|
+
var child_transport: if (use_child) ChildTransport else void = undefined;
|
|
154
|
+
var pool_transport: if (use_pool) PoolTransport else void = undefined;
|
|
155
|
+
if (comptime use_child) {
|
|
156
|
+
const env_keys = init.environ_map.keys();
|
|
157
|
+
const env_values = init.environ_map.values();
|
|
158
|
+
for (env_keys, env_values) |key, value| {
|
|
159
|
+
if (native_sdk.serviceEnvironmentVariableAllowed(key)) service_env.put(key, value) catch {};
|
|
160
|
+
}
|
|
161
|
+
const service_path = siblingServiceHostPath(init.io, &service_path_buffer);
|
|
162
|
+
child_transport = ChildTransport.init(
|
|
163
|
+
std.heap.page_allocator,
|
|
164
|
+
init.io,
|
|
165
|
+
service_path,
|
|
166
|
+
app_data_dir,
|
|
167
|
+
&service_env,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
if (comptime use_pool) {
|
|
171
|
+
// The pool's cwd holds the cooperative-cancellation markers and
|
|
172
|
+
// stream-relay files; the service operations themselves run with the
|
|
173
|
+
// app process's own working directory.
|
|
174
|
+
pool_transport = PoolTransport.init(
|
|
175
|
+
std.heap.page_allocator,
|
|
176
|
+
init.io,
|
|
177
|
+
app_data_dir,
|
|
178
|
+
.{ .max_workers = service_carrier.pool_workers },
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
defer if (comptime use_child) child_transport.deinit();
|
|
182
|
+
defer if (comptime use_pool) pool_transport.deinit();
|
|
109
183
|
// app.zon-declared images, read once at launch (bounded; a missing or
|
|
110
184
|
// over-bound file skips its entry and the views keep their fallback)
|
|
111
185
|
// and registered by the adapter on the installing frame.
|
|
@@ -127,13 +201,77 @@ pub fn main(init: std.process.Init) !void {
|
|
|
127
201
|
var env_value_count: usize = 0;
|
|
128
202
|
if (comptime @hasDecl(core, "envMsgs")) {
|
|
129
203
|
inline for (core.envMsgs) |entry| {
|
|
130
|
-
if (
|
|
204
|
+
if (std.mem.eql(u8, entry.env, app_data_dir_env)) {
|
|
205
|
+
if (app_data_dir.len > 0) {
|
|
206
|
+
env_values_buffer[env_value_count] = .{ .msg = entry.msg, .value = app_data_dir };
|
|
207
|
+
env_value_count += 1;
|
|
208
|
+
}
|
|
209
|
+
} else if (init.environ_map.get(entry.env)) |value| {
|
|
131
210
|
env_values_buffer[env_value_count] = .{ .msg = entry.msg, .value = value };
|
|
132
211
|
env_value_count += 1;
|
|
133
212
|
}
|
|
134
213
|
}
|
|
135
214
|
}
|
|
136
215
|
|
|
216
|
+
// Model persistence is a build-time capability: without `"persist"`
|
|
217
|
+
// this branch (store, paths, binding) is not analyzed into the app. A
|
|
218
|
+
// replay launch never reads the live snapshot; its journal feeds the
|
|
219
|
+
// recorded restore result before the installing app-start event.
|
|
220
|
+
var persist_store_value: native_sdk.PersistStore = undefined;
|
|
221
|
+
var persist_coordinator_value: native_sdk.persist_store.Coordinator = undefined;
|
|
222
|
+
var persist_coordinator_started = false;
|
|
223
|
+
var persist_host_value: PersistHost = .{};
|
|
224
|
+
var persist_outcome_handle: native_sdk.ChannelHandle = .{};
|
|
225
|
+
var persist_restore_value: native_sdk.persist_store.RestoreResult = .{ .outcome = .none };
|
|
226
|
+
var persist_options: ?Adapter.PersistOptions = null;
|
|
227
|
+
if (comptime manifestDeclaresPersist()) {
|
|
228
|
+
const config = comptime manifestPersistConfig();
|
|
229
|
+
comptime Adapter.validatePersistRoutes(.{
|
|
230
|
+
.ok = config.restore.ok,
|
|
231
|
+
.none = config.restore.none,
|
|
232
|
+
.err = config.restore.err,
|
|
233
|
+
});
|
|
234
|
+
const replay = init.environ_map.get("NATIVE_SDK_SESSION_REPLAY") != null;
|
|
235
|
+
persist_store_value = native_sdk.PersistStore.init(init.io, std.heap.page_allocator, app_data_dir, .{
|
|
236
|
+
.schema_version = config.version,
|
|
237
|
+
.model_fingerprint = core.sidecar_model_fingerprint,
|
|
238
|
+
.snapshot_format = core.sidecar_snapshot_format,
|
|
239
|
+
});
|
|
240
|
+
persist_host_value.outcome_handle = &persist_outcome_handle;
|
|
241
|
+
if (!replay) {
|
|
242
|
+
persist_restore_value = persist_store_value.restore();
|
|
243
|
+
if (persist_restore_value.used_backup) {
|
|
244
|
+
std.log.warn("model persistence: primary snapshot unavailable or corrupt; restored snapshot.nsd.bak", .{});
|
|
245
|
+
}
|
|
246
|
+
try persist_coordinator_value.startWithOutcomeHandler(
|
|
247
|
+
persist_store_value,
|
|
248
|
+
manifestPersistDebounce(config),
|
|
249
|
+
.{ .context = &persist_host_value, .report_fn = PersistHost.reportOutcome },
|
|
250
|
+
);
|
|
251
|
+
persist_coordinator_started = true;
|
|
252
|
+
persist_host_value.coordinator = &persist_coordinator_value;
|
|
253
|
+
}
|
|
254
|
+
persist_options = .{
|
|
255
|
+
// Replay binds the same named service to a no-op host. The
|
|
256
|
+
// command remains on the wire for fingerprint parity but can
|
|
257
|
+
// never mutate the live snapshot.
|
|
258
|
+
.binding = persist_host_value.binding(),
|
|
259
|
+
.routes = .{
|
|
260
|
+
.ok = config.restore.ok,
|
|
261
|
+
.none = config.restore.none,
|
|
262
|
+
.err = config.restore.err,
|
|
263
|
+
},
|
|
264
|
+
.restore = .{
|
|
265
|
+
.outcome = persist_restore_value.outcome,
|
|
266
|
+
.bytes = persist_restore_value.bytes,
|
|
267
|
+
.migration_from_version = persist_restore_value.migration_from_version,
|
|
268
|
+
},
|
|
269
|
+
.outcome_handle = &persist_outcome_handle,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
defer if (comptime manifestDeclaresPersist()) persist_restore_value.deinit(std.heap.page_allocator);
|
|
273
|
+
defer if (persist_coordinator_started) persist_coordinator_value.deinit();
|
|
274
|
+
|
|
137
275
|
// The app struct (and any real model) is multi-MB: `create`
|
|
138
276
|
// heap-allocates and constructs in place, so neither rides the stack.
|
|
139
277
|
const app_state = try Adapter.create(std.heap.page_allocator, .{
|
|
@@ -144,6 +282,18 @@ pub fn main(init: std.process.Init) !void {
|
|
|
144
282
|
.image_cache_dir = audio_cache_dir,
|
|
145
283
|
.boot_images = boot_images_buffer[0..boot_image_count],
|
|
146
284
|
.env_values = env_values_buffer[0..env_value_count],
|
|
285
|
+
.host_calls = if (comptime use_pool)
|
|
286
|
+
pool_transport.binding()
|
|
287
|
+
else if (comptime use_child)
|
|
288
|
+
child_transport.binding()
|
|
289
|
+
else
|
|
290
|
+
null,
|
|
291
|
+
.service_results = if (comptime services.enabled) .{
|
|
292
|
+
.index_fn = services.indexOf,
|
|
293
|
+
.streaming_fn = services.isStreaming,
|
|
294
|
+
.decode_fn = services.resultDecoder(core),
|
|
295
|
+
} else null,
|
|
296
|
+
.persist = persist_options,
|
|
147
297
|
}, options);
|
|
148
298
|
defer app_state.destroy();
|
|
149
299
|
|
|
@@ -159,9 +309,61 @@ pub fn main(init: std.process.Init) !void {
|
|
|
159
309
|
.permissions = app_permissions,
|
|
160
310
|
.navigation = .{ .allowed_origins = allowed_origins },
|
|
161
311
|
},
|
|
312
|
+
.relational_migrations = &relational_migrations.migrations,
|
|
162
313
|
}, init);
|
|
163
314
|
}
|
|
164
315
|
|
|
316
|
+
fn siblingServiceHostPath(io: std.Io, buffer: []u8) []const u8 {
|
|
317
|
+
var executable_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
|
|
318
|
+
const len = std.process.executablePath(io, &executable_buffer) catch return "";
|
|
319
|
+
const dir = std.fs.path.dirname(executable_buffer[0..len]) orelse return "";
|
|
320
|
+
const suffix = if (@import("builtin").os.tag == .windows) ".exe" else "";
|
|
321
|
+
return std.fmt.bufPrint(buffer, "{s}/{s}_services{s}", .{ dir, manifest.name, suffix }) catch "";
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const PersistHost = struct {
|
|
325
|
+
coordinator: ?*native_sdk.persist_store.Coordinator = null,
|
|
326
|
+
outcome_handle: ?*native_sdk.ChannelHandle = null,
|
|
327
|
+
|
|
328
|
+
fn binding(self: *PersistHost) native_sdk.HostCallBinding {
|
|
329
|
+
return .{ .context = self, .send_fn = send, .request_fn = request };
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
fn send(context: *anyopaque, name: []const u8, snapshot: []const u8) void {
|
|
333
|
+
const self: *PersistHost = @ptrCast(@alignCast(context));
|
|
334
|
+
const coordinator = self.coordinator orelse return;
|
|
335
|
+
if (std.mem.eql(u8, name, "core.persist.flush")) {
|
|
336
|
+
coordinator.flush();
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (!std.mem.eql(u8, name, "core.persist")) return;
|
|
340
|
+
const outcome = coordinator.enqueue(snapshot);
|
|
341
|
+
if (outcome != .ok) reportOutcome(context, outcome);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
fn reportOutcome(context: *anyopaque, outcome: native_sdk.persist_store.Outcome) void {
|
|
345
|
+
if (outcome == .ok) return;
|
|
346
|
+
const self: *PersistHost = @ptrCast(@alignCast(context));
|
|
347
|
+
const handle = self.outcome_handle orelse {
|
|
348
|
+
std.log.err("model persistence write failed before its result channel installed: {s}", .{@tagName(outcome)});
|
|
349
|
+
return;
|
|
350
|
+
};
|
|
351
|
+
switch (handle.post(@tagName(outcome))) {
|
|
352
|
+
.accepted => {},
|
|
353
|
+
.dropped_full, .dropped_oversized, .closed => {
|
|
354
|
+
std.log.err("model persistence write failed after its result channel closed: {s}", .{@tagName(outcome)});
|
|
355
|
+
},
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
fn request(context: *anyopaque, name: []const u8, key: u64, payload: []const u8) void {
|
|
360
|
+
_ = context;
|
|
361
|
+
_ = name;
|
|
362
|
+
_ = key;
|
|
363
|
+
_ = payload;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
165
367
|
/// The startup window title: the scene's first window title, else the
|
|
166
368
|
/// manifest display name, else the app name.
|
|
167
369
|
fn windowTitle() []const u8 {
|
|
@@ -228,6 +430,68 @@ fn manifestStringList(comptime m: anytype, comptime field: []const u8) []const [
|
|
|
228
430
|
}
|
|
229
431
|
}
|
|
230
432
|
|
|
433
|
+
fn manifestDeclaresPersist() bool {
|
|
434
|
+
comptime {
|
|
435
|
+
for (manifestStringList(manifest, "capabilities")) |capability| {
|
|
436
|
+
if (std.mem.eql(u8, capability, "persist")) {
|
|
437
|
+
if (!@hasField(@TypeOf(manifest), "persist")) {
|
|
438
|
+
@compileError("app.zon declares the persist capability but has no .persist = .{ .version, .restore = .{ .ok, .none, .err } } configuration");
|
|
439
|
+
}
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (@hasField(@TypeOf(manifest), "persist")) {
|
|
444
|
+
@compileError("app.zon configures .persist but does not declare \"persist\" in .capabilities");
|
|
445
|
+
}
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
fn ManifestPersistType() type {
|
|
451
|
+
if (@hasField(@TypeOf(manifest), "persist")) return @TypeOf(manifest.persist);
|
|
452
|
+
return void;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
fn manifestPersistConfig() ManifestPersistType() {
|
|
456
|
+
comptime {
|
|
457
|
+
if (!manifestDeclaresPersist()) unreachable;
|
|
458
|
+
if (manifest.persist.version == 0 or manifest.persist.version > 9_007_199_254_740_991) {
|
|
459
|
+
@compileError("app.zon .persist.version must be a positive exact integer and monotonically increased for every Model shape change");
|
|
460
|
+
}
|
|
461
|
+
if (@hasField(@TypeOf(manifest.persist), "debounce_ms") and manifest.persist.debounce_ms > 60_000) {
|
|
462
|
+
@compileError("app.zon .persist.debounce_ms must be at most 60000");
|
|
463
|
+
}
|
|
464
|
+
validatePersistRoutes(manifest.persist.restore);
|
|
465
|
+
return manifest.persist;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
fn manifestPersistDebounce(comptime config: anytype) u32 {
|
|
470
|
+
if (@hasField(@TypeOf(config), "debounce_ms")) return config.debounce_ms;
|
|
471
|
+
return 500;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
fn validatePersistRoutes(comptime routes: anytype) void {
|
|
475
|
+
if (!persistRouteMatches(routes.ok, void)) {
|
|
476
|
+
@compileError("app.zon .persist.restore.ok must name a void Msg arm in src/core.ts");
|
|
477
|
+
}
|
|
478
|
+
if (!persistRouteMatches(routes.none, void)) {
|
|
479
|
+
@compileError("app.zon .persist.restore.none must name a void Msg arm in src/core.ts");
|
|
480
|
+
}
|
|
481
|
+
if (!persistRouteMatches(routes.err, []const u8)) {
|
|
482
|
+
@compileError("app.zon .persist.restore.err must name a one-Uint8Array-field Msg arm in src/core.ts");
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
fn persistRouteMatches(comptime name: []const u8, comptime Payload: type) bool {
|
|
487
|
+
const info = @typeInfo(core.Msg);
|
|
488
|
+
if (info != .@"union") return false;
|
|
489
|
+
inline for (info.@"union".fields) |field| {
|
|
490
|
+
if (std.mem.eql(u8, field.name, name)) return field.type == Payload;
|
|
491
|
+
}
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
|
|
231
495
|
fn manifestAllowedOrigins() []const []const u8 {
|
|
232
496
|
comptime {
|
|
233
497
|
if (!@hasField(@TypeOf(manifest), "security")) return &.{};
|