@native-sdk/cli 0.8.4 → 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 +859 -62
- package/build.zig +543 -13
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +2 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +365 -2
- 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 +149 -0
- package/packages/core/sdk/core.ts +529 -12
- package/packages/core/sdk/events.d.ts +36 -0
- package/packages/core/sdk/events.ts +57 -0
- package/packages/core/src/checker.ts +468 -15
- package/packages/core/src/cli.ts +143 -3
- package/packages/core/src/contract.ts +26 -5
- package/packages/core/src/devhost.ts +1847 -16
- 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 +82 -16
- 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/references/project-anatomy.md +1 -1
- package/skill-data/native-ui/SKILL.md +47 -0
- package/skill-data/ts-core/SKILL.md +80 -31
- 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 +249 -8
- 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 +109 -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 +119 -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 +40 -18
- package/src/platform/macos/appkit_host.h +16 -3
- package/src/platform/macos/appkit_host.m +536 -36
- package/src/platform/macos/cef_host.mm +248 -36
- package/src/platform/macos/root.zig +244 -34
- package/src/platform/null_platform.zig +223 -19
- package/src/platform/null_platform_tests.zig +74 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +179 -15
- package/src/platform/windows/root.zig +187 -21
- package/src/platform/windows/webview2_host.cpp +293 -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 +32 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/root.zig +46 -0
- package/src/runtime/api.zig +11 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/bridge_permission_tests.zig +23 -2
- package/src/runtime/bridge_responses.zig +3 -1
- package/src/runtime/canvas_frame.zig +18 -11
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- 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 +2295 -113
- 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 +49 -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 +4 -0
- package/src/runtime/ts_core_host.zig +788 -86
- package/src/runtime/ts_core_host_tests.zig +231 -11
- package/src/runtime/ts_ui_app.zig +499 -1
- package/src/runtime/ui_app.zig +142 -16
- package/src/runtime/ui_app_tests.zig +155 -5
- package/src/runtime/validation.zig +22 -0
- package/src/runtime/view.zig +9 -0
- 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 +214 -2
- package/src/tooling/package.zig +116 -0
- package/src/tooling/raw_manifest.zig +30 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +161 -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 +378 -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/src/tooling/ts_core.zig
CHANGED
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
//! imports are real files; the resolver hook maps only the SDK names).
|
|
15
15
|
|
|
16
16
|
const std = @import("std");
|
|
17
|
+
const app_dirs = @import("app_dirs");
|
|
17
18
|
const buildgraph = @import("buildgraph.zig");
|
|
19
|
+
const debug = @import("debug");
|
|
20
|
+
const package_tool = @import("package.zig");
|
|
18
21
|
const process_tree = @import("process_tree.zig");
|
|
19
22
|
|
|
20
23
|
pub const Error = error{
|
|
@@ -403,21 +406,138 @@ pub fn ensureResolvedTranspiler(allocator: std.mem.Allocator, io: std.Io, framew
|
|
|
403
406
|
return transpilerDepsMissing(resolved);
|
|
404
407
|
}
|
|
405
408
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
409
|
+
pub const PersistRoutes = struct {
|
|
410
|
+
ok: []const u8,
|
|
411
|
+
none: []const u8,
|
|
412
|
+
err: []const u8,
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
/// Run the real-SQLite schema/query lane used by the build and return the
|
|
416
|
+
/// generated SDK core path that exposes this app's Cmd.q/Sub.q surface.
|
|
417
|
+
/// Generated outputs live under ignored .native/cache. The append-only
|
|
418
|
+
/// migration authority lives beside the authored migrations so it is visible
|
|
419
|
+
/// to version control and survives a clean checkout.
|
|
420
|
+
pub fn generateSqliteSurface(
|
|
421
|
+
allocator: std.mem.Allocator,
|
|
422
|
+
io: std.Io,
|
|
423
|
+
base_env: *std.process.Environ.Map,
|
|
424
|
+
framework_root: []const u8,
|
|
425
|
+
install_editor_surface: bool,
|
|
426
|
+
) ![]u8 {
|
|
427
|
+
const sqlite_cli = try transpilerPath(allocator, io, framework_root, "src/sqlite_cli.ts");
|
|
428
|
+
defer allocator.free(sqlite_cli);
|
|
429
|
+
const runner = try tsRunnerPath(allocator, io, framework_root);
|
|
430
|
+
defer allocator.free(runner);
|
|
431
|
+
const sdk_in = try transpilerPath(allocator, io, framework_root, "sdk/core.ts");
|
|
432
|
+
defer allocator.free(sdk_in);
|
|
433
|
+
const static_in = try transpilerPath(allocator, io, framework_root, "compile-surface/core.ts");
|
|
434
|
+
defer allocator.free(static_in);
|
|
435
|
+
try std.Io.Dir.cwd().createDirPath(io, ".native/cache/sqlite");
|
|
436
|
+
const sdk_out = try allocator.dupe(u8, ".native/cache/sqlite/core.ts");
|
|
437
|
+
errdefer allocator.free(sdk_out);
|
|
438
|
+
var child = std.process.spawn(io, .{
|
|
439
|
+
.argv = &.{
|
|
440
|
+
"node", runner, sqlite_cli,
|
|
441
|
+
"--src", "src", "--sdk-in",
|
|
442
|
+
sdk_in, "--static-in", static_in,
|
|
443
|
+
"--sdk-out", sdk_out, "--dts-out",
|
|
444
|
+
".native/cache/sqlite/core.d.ts", "--static-out", ".native/cache/sqlite/core_static.ts",
|
|
445
|
+
"--zig-out", ".native/cache/sqlite/migrations.zig", "--metadata-out",
|
|
446
|
+
".native/cache/sqlite/metadata.json", "--state", "src/schema/migrations.lock.json",
|
|
447
|
+
},
|
|
448
|
+
.stdin = .ignore,
|
|
449
|
+
.stdout = .inherit,
|
|
450
|
+
.stderr = .inherit,
|
|
451
|
+
.environ_map = base_env,
|
|
452
|
+
}) catch return nodeMissing();
|
|
453
|
+
const term = try child.wait(io);
|
|
454
|
+
switch (term) {
|
|
455
|
+
.exited => |code| if (code == 0) {
|
|
456
|
+
if (install_editor_surface) {
|
|
457
|
+
materializeSqliteEditorSurface(allocator, io, ".", sdk_out) catch {};
|
|
458
|
+
}
|
|
459
|
+
const absolute = try std.Io.Dir.cwd().realPathFileAlloc(io, ".native/cache/sqlite/core.d.ts", allocator);
|
|
460
|
+
allocator.free(sdk_out);
|
|
461
|
+
return absolute;
|
|
462
|
+
},
|
|
463
|
+
else => {},
|
|
464
|
+
}
|
|
465
|
+
std.debug.print("native check: the relational schema or declared queries failed (diagnostics above)\n", .{});
|
|
466
|
+
return error.SqliteCheckFailed;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
pub const ServicePackage = struct {
|
|
470
|
+
name: []const u8,
|
|
471
|
+
version: []const u8,
|
|
472
|
+
content_hash: []const u8,
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
/// Run the TypeScript frontend in check-only mode on src/core.ts — and,
|
|
476
|
+
/// through it, the core's whole import graph under src/ — and surface its NS
|
|
477
|
+
/// diagnostics verbatim. Manifest-owned routes ride into the same typed Msg
|
|
478
|
+
/// contract the watched dev host invokes on each of its own restarts.
|
|
479
|
+
pub fn checkCore(
|
|
480
|
+
allocator: std.mem.Allocator,
|
|
481
|
+
io: std.Io,
|
|
482
|
+
base_env: *std.process.Environ.Map,
|
|
483
|
+
framework_root: []const u8,
|
|
484
|
+
capabilities: []const []const u8,
|
|
485
|
+
permissions: []const []const u8,
|
|
486
|
+
service_packages: []const ServicePackage,
|
|
487
|
+
persist_version: ?u64,
|
|
488
|
+
persist_routes: ?PersistRoutes,
|
|
489
|
+
sdk_core_path: ?[]const u8,
|
|
490
|
+
) !void {
|
|
413
491
|
const cli_path = try transpilerPath(allocator, io, framework_root, "src/cli.ts");
|
|
414
492
|
defer allocator.free(cli_path);
|
|
415
493
|
const runner_path = try tsRunnerPath(allocator, io, framework_root);
|
|
416
494
|
defer allocator.free(runner_path);
|
|
417
495
|
try ensureResolvedTranspiler(allocator, io, framework_root);
|
|
418
496
|
|
|
497
|
+
var argv: std.ArrayList([]const u8) = .empty;
|
|
498
|
+
defer argv.deinit(allocator);
|
|
499
|
+
var persist_version_arg: ?[]u8 = null;
|
|
500
|
+
defer if (persist_version_arg) |value| allocator.free(value);
|
|
501
|
+
try argv.appendSlice(allocator, &.{ "node", runner_path, cli_path, "src/core.ts" });
|
|
502
|
+
for (capabilities) |capability| try argv.appendSlice(allocator, &.{ "--capability", capability });
|
|
503
|
+
for (permissions) |permission| try argv.appendSlice(allocator, &.{ "--permission", permission });
|
|
504
|
+
var service_package_args: std.ArrayList([]u8) = .empty;
|
|
505
|
+
defer {
|
|
506
|
+
for (service_package_args.items) |value| allocator.free(value);
|
|
507
|
+
service_package_args.deinit(allocator);
|
|
508
|
+
}
|
|
509
|
+
for (service_packages) |package_entry| {
|
|
510
|
+
const spelling = try std.fmt.allocPrint(allocator, "{s}|{s}|{s}", .{ package_entry.name, package_entry.version, package_entry.content_hash });
|
|
511
|
+
try service_package_args.append(allocator, spelling);
|
|
512
|
+
try argv.appendSlice(allocator, &.{ "--service-package", spelling });
|
|
513
|
+
}
|
|
514
|
+
if (try package_tool.projectHasTypeScriptServices(allocator, io, ".")) {
|
|
515
|
+
try argv.appendSlice(allocator, &.{ "--services-editor-client", "node_modules/@native-sdk/services/index.ts" });
|
|
516
|
+
} else {
|
|
517
|
+
std.Io.Dir.cwd().deleteTree(io, "node_modules/@native-sdk/services") catch {};
|
|
518
|
+
}
|
|
519
|
+
if (persist_version) |version| {
|
|
520
|
+
persist_version_arg = try std.fmt.allocPrint(allocator, "{d}", .{version});
|
|
521
|
+
try argv.appendSlice(allocator, &.{
|
|
522
|
+
"--persist-version",
|
|
523
|
+
persist_version_arg.?,
|
|
524
|
+
"--persist-state",
|
|
525
|
+
".native/cache/persist-schema.json",
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
if (persist_routes) |routes| {
|
|
529
|
+
try argv.appendSlice(allocator, &.{
|
|
530
|
+
"--persist-ok",
|
|
531
|
+
routes.ok,
|
|
532
|
+
"--persist-none",
|
|
533
|
+
routes.none,
|
|
534
|
+
"--persist-err",
|
|
535
|
+
routes.err,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
if (sdk_core_path) |sdk_core| try argv.appendSlice(allocator, &.{ "--sdk-core", sdk_core });
|
|
419
539
|
var child = std.process.spawn(io, .{
|
|
420
|
-
.argv =
|
|
540
|
+
.argv = argv.items,
|
|
421
541
|
.stdin = .ignore,
|
|
422
542
|
.stdout = .inherit,
|
|
423
543
|
.stderr = .inherit,
|
|
@@ -440,11 +560,15 @@ pub fn checkCore(allocator: std.mem.Allocator, io: std.Io, base_env: *std.proces
|
|
|
440
560
|
/// build verdict come from ONE compiler. Analyzer type errors fail the
|
|
441
561
|
/// check with the compiler's own diagnostics; a toolchain that cannot
|
|
442
562
|
/// reach a verdict defers to the build rather than wedging check.
|
|
443
|
-
pub fn compilerTypecheckCore(allocator: std.mem.Allocator, io: std.Io, base_env: *std.process.Environ.Map, framework_root: []const u8) !void {
|
|
563
|
+
pub fn compilerTypecheckCore(allocator: std.mem.Allocator, io: std.Io, base_env: *std.process.Environ.Map, framework_root: []const u8, sdk_core_path: ?[]const u8) !void {
|
|
444
564
|
const script_path = try transpilerPath(allocator, io, framework_root, "scripts/compiler_typecheck.mjs");
|
|
445
565
|
defer allocator.free(script_path);
|
|
566
|
+
var argv: std.ArrayList([]const u8) = .empty;
|
|
567
|
+
defer argv.deinit(allocator);
|
|
568
|
+
try argv.appendSlice(allocator, &.{ "node", script_path, "src/core.ts" });
|
|
569
|
+
if (sdk_core_path) |sdk_core| try argv.appendSlice(allocator, &.{ "--sdk-core", sdk_core });
|
|
446
570
|
var child = std.process.spawn(io, .{
|
|
447
|
-
.argv =
|
|
571
|
+
.argv = argv.items,
|
|
448
572
|
.stdin = .ignore,
|
|
449
573
|
.stdout = .inherit,
|
|
450
574
|
.stderr = .inherit,
|
|
@@ -465,11 +589,22 @@ pub fn compilerTypecheckCore(allocator: std.mem.Allocator, io: std.Io, base_env:
|
|
|
465
589
|
|
|
466
590
|
pub const DevHostOptions = struct {
|
|
467
591
|
base_env: *std.process.Environ.Map,
|
|
592
|
+
app_id: []const u8,
|
|
593
|
+
app_name: []const u8 = "app",
|
|
594
|
+
canvas_label: []const u8 = "canvas",
|
|
595
|
+
window_width: f32 = 800,
|
|
596
|
+
window_height: f32 = 600,
|
|
597
|
+
/// app.zon capabilities installed by the shipping host. The virtual host
|
|
598
|
+
/// receives the same set so capability-shed effects reject identically.
|
|
599
|
+
capabilities: []const []const u8 = &.{},
|
|
600
|
+
permissions: []const []const u8 = &.{},
|
|
468
601
|
/// NDJSON message script; null = interactive stdin.
|
|
469
602
|
script: ?[]const u8 = null,
|
|
470
603
|
/// Re-run the harness whenever any module of the core changes.
|
|
471
604
|
/// Requires a script (a re-run replays it against the edited core).
|
|
472
605
|
watch: bool = false,
|
|
606
|
+
persist_routes: ?PersistRoutes = null,
|
|
607
|
+
service_packages: []const ServicePackage = &.{},
|
|
473
608
|
};
|
|
474
609
|
|
|
475
610
|
/// `native dev --core`: the node dev-harness over src/core.ts — the
|
|
@@ -484,10 +619,42 @@ pub fn runDevHost(allocator: std.mem.Allocator, io: std.Io, framework_root: []co
|
|
|
484
619
|
defer allocator.free(devhost_path);
|
|
485
620
|
const runner_path = try tsRunnerPath(allocator, io, framework_root);
|
|
486
621
|
defer allocator.free(runner_path);
|
|
622
|
+
const app_root = try std.process.currentPathAlloc(io, allocator);
|
|
623
|
+
defer allocator.free(app_root);
|
|
624
|
+
const core_path = try std.fs.path.join(allocator, &.{ app_root, "src/core.ts" });
|
|
625
|
+
defer allocator.free(core_path);
|
|
626
|
+
var script_path: ?[]u8 = null;
|
|
627
|
+
defer if (script_path) |value| allocator.free(value);
|
|
628
|
+
if (options.script) |script| {
|
|
629
|
+
script_path = if (std.fs.path.isAbsolute(script))
|
|
630
|
+
try allocator.dupe(u8, script)
|
|
631
|
+
else
|
|
632
|
+
try std.fs.path.join(allocator, &.{ app_root, script });
|
|
633
|
+
}
|
|
634
|
+
var app_data_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
|
|
635
|
+
const app_data_dir = app_dirs.resolveOne(
|
|
636
|
+
.{ .name = options.app_id },
|
|
637
|
+
app_dirs.currentPlatform(),
|
|
638
|
+
debug.envFromMap(options.base_env),
|
|
639
|
+
.data,
|
|
640
|
+
&app_data_buffer,
|
|
641
|
+
) catch "";
|
|
642
|
+
if (app_data_dir.len > 0) std.Io.Dir.cwd().createDirPath(io, app_data_dir) catch {};
|
|
487
643
|
// The harness runs the frontend tier under node, so it needs the
|
|
488
644
|
// TypeScript toolchain to resolve exactly like check/build do.
|
|
489
645
|
try ensureResolvedTranspiler(allocator, io, framework_root);
|
|
490
646
|
|
|
647
|
+
var sqlite_declarations: ?[]u8 = null;
|
|
648
|
+
defer if (sqlite_declarations) |path_value| allocator.free(path_value);
|
|
649
|
+
var sqlite_source: ?[]u8 = null;
|
|
650
|
+
defer if (sqlite_source) |path_value| allocator.free(path_value);
|
|
651
|
+
for (options.capabilities) |capability| {
|
|
652
|
+
if (!std.mem.eql(u8, capability, "sqlite")) continue;
|
|
653
|
+
sqlite_declarations = try generateSqliteSurface(allocator, io, options.base_env, framework_root, true);
|
|
654
|
+
sqlite_source = try std.Io.Dir.cwd().realPathFileAlloc(io, ".native/cache/sqlite/core.ts", allocator);
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
|
|
491
658
|
var argv: std.ArrayList([]const u8) = .empty;
|
|
492
659
|
defer argv.deinit(allocator);
|
|
493
660
|
try argv.append(allocator, "node");
|
|
@@ -500,10 +667,58 @@ pub fn runDevHost(allocator: std.mem.Allocator, io: std.Io, framework_root: []co
|
|
|
500
667
|
}
|
|
501
668
|
try argv.append(allocator, runner_path);
|
|
502
669
|
try argv.append(allocator, devhost_path);
|
|
503
|
-
try argv.append(allocator,
|
|
504
|
-
|
|
670
|
+
try argv.append(allocator, core_path);
|
|
671
|
+
const window_width_arg = try std.fmt.allocPrint(allocator, "{d}", .{options.window_width});
|
|
672
|
+
defer allocator.free(window_width_arg);
|
|
673
|
+
const window_height_arg = try std.fmt.allocPrint(allocator, "{d}", .{options.window_height});
|
|
674
|
+
defer allocator.free(window_height_arg);
|
|
675
|
+
try argv.appendSlice(allocator, &.{
|
|
676
|
+
"--app-name",
|
|
677
|
+
options.app_name,
|
|
678
|
+
"--app-id",
|
|
679
|
+
options.app_id,
|
|
680
|
+
"--canvas-label",
|
|
681
|
+
options.canvas_label,
|
|
682
|
+
"--window-width",
|
|
683
|
+
window_width_arg,
|
|
684
|
+
"--window-height",
|
|
685
|
+
window_height_arg,
|
|
686
|
+
});
|
|
687
|
+
if (script_path) |script| {
|
|
505
688
|
try argv.appendSlice(allocator, &.{ "--script", script });
|
|
506
689
|
}
|
|
690
|
+
if (app_data_dir.len > 0) {
|
|
691
|
+
try argv.appendSlice(allocator, &.{ "--service-cwd", app_data_dir });
|
|
692
|
+
}
|
|
693
|
+
for (options.capabilities) |capability| {
|
|
694
|
+
try argv.appendSlice(allocator, &.{ "--capability", capability });
|
|
695
|
+
}
|
|
696
|
+
for (options.permissions) |permission| {
|
|
697
|
+
try argv.appendSlice(allocator, &.{ "--permission", permission });
|
|
698
|
+
}
|
|
699
|
+
if (sqlite_source) |sdk_core| {
|
|
700
|
+
try argv.appendSlice(allocator, &.{ "--sdk-core", sdk_core, "--sqlite-src", "src" });
|
|
701
|
+
}
|
|
702
|
+
if (options.persist_routes) |routes| {
|
|
703
|
+
try argv.appendSlice(allocator, &.{
|
|
704
|
+
"--persist-ok",
|
|
705
|
+
routes.ok,
|
|
706
|
+
"--persist-none",
|
|
707
|
+
routes.none,
|
|
708
|
+
"--persist-err",
|
|
709
|
+
routes.err,
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
var service_package_args: std.ArrayList([]u8) = .empty;
|
|
713
|
+
defer {
|
|
714
|
+
for (service_package_args.items) |value| allocator.free(value);
|
|
715
|
+
service_package_args.deinit(allocator);
|
|
716
|
+
}
|
|
717
|
+
for (options.service_packages) |package_entry| {
|
|
718
|
+
const spelling = try std.fmt.allocPrint(allocator, "{s}|{s}|{s}", .{ package_entry.name, package_entry.version, package_entry.content_hash });
|
|
719
|
+
try service_package_args.append(allocator, spelling);
|
|
720
|
+
try argv.appendSlice(allocator, &.{ "--service-package", spelling });
|
|
721
|
+
}
|
|
507
722
|
|
|
508
723
|
std.debug.print("native dev --core: the core-logic loop under node (update/effects, virtual clock) - not a renderer; `native dev` runs the app\n", .{});
|
|
509
724
|
var child = std.process.spawn(io, .{
|
|
@@ -551,6 +766,7 @@ pub const editor_package_dir = "node_modules/@native-sdk/core";
|
|
|
551
766
|
/// packages/core/test/package_manifest.test.ts pins the manifest to this
|
|
552
767
|
/// shape, so copy and tarball cannot drift apart.
|
|
553
768
|
const editor_package_files = [_][]const u8{ "package.json", "sdk/core.ts", "sdk/text.ts", "sdk/events.ts", "sdk/bytes_text_methods.d.ts" };
|
|
769
|
+
const sqlite_editor_overlay_marker = ".native/cache/sqlite/editor-overlay";
|
|
554
770
|
|
|
555
771
|
/// Extract the top-level "version" of a package.json. A targeted scan, not
|
|
556
772
|
/// a JSON parse: both inputs are our own manifest and npm's byte-identical
|
|
@@ -588,6 +804,8 @@ pub const EditorPackageStatus = struct {
|
|
|
588
804
|
/// The app copy's version, or null when the copy is missing or
|
|
589
805
|
/// incomplete (owned when present).
|
|
590
806
|
installed: ?[]const u8,
|
|
807
|
+
/// The package's core.ts is the current app-specific relational overlay.
|
|
808
|
+
sqlite_overlay: bool,
|
|
591
809
|
|
|
592
810
|
pub fn fresh(self: EditorPackageStatus) bool {
|
|
593
811
|
const installed = self.installed orelse return false;
|
|
@@ -602,10 +820,13 @@ pub const EditorPackageStatus = struct {
|
|
|
602
820
|
|
|
603
821
|
/// Compare `<app_root>/node_modules/@native-sdk/core` against the SDK's
|
|
604
822
|
/// bundled package. Cheap by design (the refresh trigger runs on every
|
|
605
|
-
/// check/dev/build):
|
|
823
|
+
/// check/dev/build): small manifest/source reads plus file stats.
|
|
606
824
|
pub fn editorPackageStatus(allocator: std.mem.Allocator, io: std.Io, framework_root: []const u8, app_root: []const u8) !EditorPackageStatus {
|
|
607
825
|
const bundled = try bundledSdkVersion(allocator, io, framework_root);
|
|
608
826
|
errdefer allocator.free(bundled);
|
|
827
|
+
const overlay_path = try std.fs.path.join(allocator, &.{ app_root, sqlite_editor_overlay_marker });
|
|
828
|
+
defer allocator.free(overlay_path);
|
|
829
|
+
const sqlite_overlay = buildgraph.fileExists(io, overlay_path);
|
|
609
830
|
|
|
610
831
|
const installed: ?[]const u8 = read: {
|
|
611
832
|
const manifest_path = try std.fs.path.join(allocator, &.{ app_root, editor_package_dir, "package.json" });
|
|
@@ -622,10 +843,10 @@ pub fn editorPackageStatus(allocator: std.mem.Allocator, io: std.Io, framework_r
|
|
|
622
843
|
}
|
|
623
844
|
break :read try allocator.dupe(u8, version);
|
|
624
845
|
};
|
|
625
|
-
return .{ .bundled = bundled, .installed = installed };
|
|
846
|
+
return .{ .bundled = bundled, .installed = installed, .sqlite_overlay = sqlite_overlay };
|
|
626
847
|
}
|
|
627
848
|
|
|
628
|
-
pub const EnsureOutcome = enum { fresh, materialized };
|
|
849
|
+
pub const EnsureOutcome = enum { fresh, materialized, restored_overlay };
|
|
629
850
|
|
|
630
851
|
/// Make `<app_root>/node_modules/@native-sdk/core` a current copy of the
|
|
631
852
|
/// SDK's bundled package: leave a version-matching copy alone (that is the
|
|
@@ -635,7 +856,10 @@ pub const EnsureOutcome = enum { fresh, materialized };
|
|
|
635
856
|
pub fn ensureEditorPackage(allocator: std.mem.Allocator, io: std.Io, framework_root: []const u8, app_root: []const u8) !EnsureOutcome {
|
|
636
857
|
const status = try editorPackageStatus(allocator, io, framework_root, app_root);
|
|
637
858
|
defer status.deinit(allocator);
|
|
638
|
-
|
|
859
|
+
// Restore an app-specific overlay before deciding whether sqlite still
|
|
860
|
+
// applies. A sqlite verb regenerates it immediately; a non-sqlite verb
|
|
861
|
+
// leaves the ordinary package behind.
|
|
862
|
+
if (status.fresh() and !status.sqlite_overlay) return .fresh;
|
|
639
863
|
|
|
640
864
|
for (editor_package_files) |sub_path| {
|
|
641
865
|
const source_path = try std.fs.path.join(allocator, &.{ framework_root, "packages", "core", sub_path });
|
|
@@ -650,7 +874,30 @@ pub fn ensureEditorPackage(allocator: std.mem.Allocator, io: std.Io, framework_r
|
|
|
650
874
|
}
|
|
651
875
|
try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = dest_path, .data = data });
|
|
652
876
|
}
|
|
653
|
-
|
|
877
|
+
const overlay_path = try std.fs.path.join(allocator, &.{ app_root, sqlite_editor_overlay_marker });
|
|
878
|
+
defer allocator.free(overlay_path);
|
|
879
|
+
std.Io.Dir.cwd().deleteFile(io, overlay_path) catch {};
|
|
880
|
+
return if (status.sqlite_overlay) .restored_overlay else .materialized;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/// Install the app-specific generated relational SDK where stock editor
|
|
884
|
+
/// TypeScript resolves @native-sdk/core. Build truth continues to use the
|
|
885
|
+
/// ignored cache output; this copy is only the editor overlay.
|
|
886
|
+
pub fn materializeSqliteEditorSurface(
|
|
887
|
+
allocator: std.mem.Allocator,
|
|
888
|
+
io: std.Io,
|
|
889
|
+
app_root: []const u8,
|
|
890
|
+
generated_core_path: []const u8,
|
|
891
|
+
) !void {
|
|
892
|
+
const source = try std.Io.Dir.cwd().readFileAlloc(io, generated_core_path, allocator, .limited(4 * 1024 * 1024));
|
|
893
|
+
defer allocator.free(source);
|
|
894
|
+
const overlay_path = try std.fs.path.join(allocator, &.{ app_root, sqlite_editor_overlay_marker });
|
|
895
|
+
defer allocator.free(overlay_path);
|
|
896
|
+
if (std.fs.path.dirname(overlay_path)) |parent| try std.Io.Dir.cwd().createDirPath(io, parent);
|
|
897
|
+
try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = overlay_path, .data = "generated relational editor surface\n" });
|
|
898
|
+
const destination = try std.fs.path.join(allocator, &.{ app_root, editor_package_dir, "sdk/core.ts" });
|
|
899
|
+
defer allocator.free(destination);
|
|
900
|
+
try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = destination, .data = source });
|
|
654
901
|
}
|
|
655
902
|
|
|
656
903
|
/// The self-heal hook `native check|dev|build|test` run over a TS app (cwd
|
|
@@ -753,6 +1000,25 @@ test "editor package: materialize, heal, and the npm-install handoff" {
|
|
|
753
1000
|
try std.testing.expect(buildgraph.fileExists(io, app ++ "/node_modules/@native-sdk/core/sdk/events.ts"));
|
|
754
1001
|
try std.testing.expect(buildgraph.fileExists(io, app ++ "/node_modules/@native-sdk/core/sdk/bytes_text_methods.d.ts"));
|
|
755
1002
|
|
|
1003
|
+
// A generated relational surface overlays the editor-resolved core and
|
|
1004
|
+
// deliberately makes the package stale. The next verb restores the base
|
|
1005
|
+
// first, so removing sqlite from app.zon cannot leave q<Name> APIs behind.
|
|
1006
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/generated-core.ts", .data = "// app-specific qNotes surface" });
|
|
1007
|
+
try materializeSqliteEditorSurface(allocator, io, app, root ++ "/generated-core.ts");
|
|
1008
|
+
const generated = try cwd.readFileAlloc(io, app ++ "/node_modules/@native-sdk/core/sdk/core.ts", allocator, .limited(1024));
|
|
1009
|
+
defer allocator.free(generated);
|
|
1010
|
+
try std.testing.expectEqualStrings("// app-specific qNotes surface", generated);
|
|
1011
|
+
{
|
|
1012
|
+
const overlaid = try editorPackageStatus(allocator, io, sdk, app);
|
|
1013
|
+
defer overlaid.deinit(allocator);
|
|
1014
|
+
try std.testing.expect(overlaid.fresh());
|
|
1015
|
+
try std.testing.expect(overlaid.sqlite_overlay);
|
|
1016
|
+
}
|
|
1017
|
+
try std.testing.expectEqual(EnsureOutcome.restored_overlay, try ensureEditorPackage(allocator, io, sdk, app));
|
|
1018
|
+
const restored = try cwd.readFileAlloc(io, app ++ "/node_modules/@native-sdk/core/sdk/core.ts", allocator, .limited(1024));
|
|
1019
|
+
defer allocator.free(restored);
|
|
1020
|
+
try std.testing.expectEqualStrings("// core module", restored);
|
|
1021
|
+
|
|
756
1022
|
// Current copy: untouched (this is also the post-publish handoff — a
|
|
757
1023
|
// real `npm install` writes identical content at the same version, so
|
|
758
1024
|
// user-owned node_modules stop being rewritten). Prove "untouched"
|
package/src/tooling/verbs.zig
CHANGED
|
@@ -57,6 +57,9 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
|
|
|
57
57
|
const core_tree = ts_core.detect(io);
|
|
58
58
|
if (core_tree == .both) return ts_core.failBothCores();
|
|
59
59
|
if (core_tree == .ts) {
|
|
60
|
+
const sqlite_enabled = for (metadata.capabilities) |capability| {
|
|
61
|
+
if (std.mem.eql(u8, capability, "sqlite")) break true;
|
|
62
|
+
} else false;
|
|
60
63
|
// Keep the app's editor surface fresh (node_modules/@native-sdk/core,
|
|
61
64
|
// the pre-publish copy stock tsc resolves): best-effort by design —
|
|
62
65
|
// build truth never depends on it, so an unresolvable framework here
|
|
@@ -69,6 +72,10 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
|
|
|
69
72
|
// for graphs the CLI itself generates (see the preflight's own
|
|
70
73
|
// doc for why ejected apps must flow past it).
|
|
71
74
|
try tsToolchainPreflight(allocator, io, ".", framework_root);
|
|
75
|
+
if (sqlite_enabled) {
|
|
76
|
+
const sqlite_declarations = try ts_core.generateSqliteSurface(allocator, io, options.base_env, framework_root, true);
|
|
77
|
+
allocator.free(sqlite_declarations);
|
|
78
|
+
}
|
|
72
79
|
}
|
|
73
80
|
}
|
|
74
81
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# SQLite amalgamation
|
|
2
|
+
|
|
3
|
+
This directory vendors the SQLite 3.53.4 amalgamation (`sqlite3.c` and
|
|
4
|
+
`sqlite3.h`) downloaded from the official SQLite distribution:
|
|
5
|
+
|
|
6
|
+
- archive: `sqlite-amalgamation-3530400.zip`
|
|
7
|
+
- archive SHA3-256: `628a44cfe82c66aed1ccbbe85a562d2e33ebe64b3288981ed76285612227934e`
|
|
8
|
+
- `sqlite3.c` SHA3-256: `67f423e9ebbbdc473cbc4772c872ee6b89f31fde4ed0279a5c25d5f65c043a16`
|
|
9
|
+
|
|
10
|
+
SQLite is in the public domain. See <https://sqlite.org/copyright.html>.
|
|
11
|
+
|
|
12
|
+
Only apps declaring the `store` or `sqlite` capability compile this source
|
|
13
|
+
into their artifact.
|