@native-sdk/cli 0.8.4 → 0.9.1
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 +1178 -74
- package/build.zig +715 -17
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +10 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +435 -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/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +280 -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 +224 -0
- package/packages/core/sdk/core.ts +694 -22
- package/packages/core/sdk/events.d.ts +89 -0
- package/packages/core/sdk/events.ts +128 -0
- package/packages/core/src/checker.ts +936 -15
- package/packages/core/src/cli.ts +156 -3
- package/packages/core/src/contract.ts +28 -5
- package/packages/core/src/devhost.ts +1876 -16
- package/packages/core/src/devhost_journal.mjs +183 -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 +179 -22
- package/packages/core/src/frontend.ts +210 -34
- package/packages/core/src/infer.ts +24 -0
- 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/automation/SKILL.md +1 -1
- package/skill-data/core/references/project-anatomy.md +1 -1
- package/skill-data/native-ui/SKILL.md +58 -5
- package/skill-data/ts-core/SKILL.md +123 -41
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +604 -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 +133 -4
- package/src/app_runner/ts_core_main.zig +254 -8
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +31 -11
- package/src/embed/app_exports.zig +12 -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 +8 -0
- package/src/embed/tests.zig +241 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +185 -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 +8 -2
- package/src/platform/linux/gtk_host.c +289 -22
- package/src/platform/linux/gtk_host.h +5 -1
- package/src/platform/linux/root.zig +109 -22
- package/src/platform/macos/appkit_host.h +24 -7
- package/src/platform/macos/appkit_host.m +686 -64
- package/src/platform/macos/cef_host.mm +400 -66
- package/src/platform/macos/root.zig +304 -47
- package/src/platform/null_platform.zig +435 -48
- package/src/platform/null_platform_tests.zig +113 -0
- package/src/platform/root.zig +19 -0
- package/src/platform/types.zig +281 -28
- package/src/platform/windows/root.zig +207 -27
- package/src/platform/windows/webview2_host.cpp +334 -51
- 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 +53 -0
- package/src/runtime/api.zig +19 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -20
- package/src/runtime/bridge_permission_tests.zig +58 -3
- package/src/runtime/bridge_responses.zig +4 -2
- package/src/runtime/builtin_bridge.zig +11 -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 +145 -7
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +3701 -231
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_notification_tests.zig +11 -0
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/file_access.zig +400 -0
- package/src/runtime/file_effect_crash_helper.zig +28 -0
- package/src/runtime/file_effect_crash_tests.zig +37 -0
- package/src/runtime/flow.zig +35 -10
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +86 -2
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +54 -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 +4 -1
- package/src/runtime/session_journal.zig +158 -5
- package/src/runtime/session_record.zig +215 -0
- package/src/runtime/session_replay.zig +206 -11
- package/src/runtime/session_tests.zig +81 -0
- 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 +16 -0
- package/src/runtime/system_services.zig +170 -38
- package/src/runtime/tests.zig +4 -0
- package/src/runtime/ts_core_host.zig +1067 -95
- package/src/runtime/ts_core_host_tests.zig +325 -11
- package/src/runtime/ts_ui_app.zig +953 -2
- package/src/runtime/ui_app.zig +434 -96
- package/src/runtime/ui_app_tests.zig +287 -11
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +42 -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 +189 -4
- package/src/tooling/ts_core.zig +366 -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 +442 -27
- 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
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// checker adds the subset rules on the typed AST; the emitter re-derives every
|
|
5
5
|
// rule during emission and turns any gap into a loud internal error.
|
|
6
6
|
|
|
7
|
-
import { ts, TypedAst, lineColumn, hasExportModifier, exportListBindings, type ExportListBinding } from "./typed_ast.ts";
|
|
7
|
+
import { ts, TypedAst, lineColumn, hasExportModifier, exportListBindings, sdkCoreModulePath, type ExportListBinding } from "./typed_ast.ts";
|
|
8
|
+
import path from "node:path";
|
|
8
9
|
import { makeDiagnostic, type SubsetDiagnostic, type RuleId } from "./diagnostics.ts";
|
|
9
10
|
import type { TypeTable } from "./types.ts";
|
|
10
11
|
import {
|
|
@@ -416,8 +417,8 @@ function thrownUnionOf(
|
|
|
416
417
|
|
|
417
418
|
export interface CheckResult {
|
|
418
419
|
readonly diagnostics: SubsetDiagnostic[];
|
|
419
|
-
/// Teaching notices that do NOT stop the build (today:
|
|
420
|
-
///
|
|
420
|
+
/// Teaching notices that do NOT stop the build (today: capability and
|
|
421
|
+
/// persistence-contract lints). Same shape as diagnostics, surfaced
|
|
421
422
|
/// as warnings by the CLI.
|
|
422
423
|
readonly warnings: SubsetDiagnostic[];
|
|
423
424
|
/// Local names bound to the SDK `Cmd` surface (import from
|
|
@@ -429,6 +430,15 @@ export interface CheckResult {
|
|
|
429
430
|
readonly subNames: Set<string>;
|
|
430
431
|
}
|
|
431
432
|
|
|
433
|
+
/// Manifest-owned boot routes for engine model persistence. The frontend
|
|
434
|
+
/// receives these as plain strings so it stays independent of app.zon's file
|
|
435
|
+
/// format while still checking the cross-file Msg contract.
|
|
436
|
+
export interface PersistRoutes {
|
|
437
|
+
readonly ok: string;
|
|
438
|
+
readonly none: string;
|
|
439
|
+
readonly err: string;
|
|
440
|
+
}
|
|
441
|
+
|
|
432
442
|
export class SubsetChecker {
|
|
433
443
|
private readonly diagnostics: SubsetDiagnostic[] = [];
|
|
434
444
|
private readonly warnings: SubsetDiagnostic[] = [];
|
|
@@ -445,19 +455,49 @@ export class SubsetChecker {
|
|
|
445
455
|
private readonly files: readonly ts.SourceFile[];
|
|
446
456
|
private readonly entry: ts.SourceFile;
|
|
447
457
|
private readonly fileSet: Set<ts.SourceFile>;
|
|
448
|
-
|
|
449
|
-
|
|
458
|
+
/// Null means the app has no service registry. An empty set is distinct:
|
|
459
|
+
/// service files exist, but none exported a callable operation.
|
|
460
|
+
private readonly serviceOps: ReadonlySet<string> | null;
|
|
461
|
+
private readonly capabilities: Set<string>;
|
|
462
|
+
private readonly permissions: Set<string>;
|
|
463
|
+
private readonly persistRoutes: PersistRoutes | undefined;
|
|
464
|
+
private readonly sdkCorePath: string;
|
|
465
|
+
private readonly windowViews: ReadonlySet<string> | undefined;
|
|
466
|
+
private usesPersist = false;
|
|
467
|
+
private usesStore = false;
|
|
468
|
+
private usesSqlite = false;
|
|
469
|
+
private usesCredentials = false;
|
|
470
|
+
|
|
471
|
+
constructor(
|
|
472
|
+
tast: TypedAst,
|
|
473
|
+
table: TypeTable,
|
|
474
|
+
files: readonly ts.SourceFile[] | ts.SourceFile,
|
|
475
|
+
serviceOps: ReadonlySet<string> | null = null,
|
|
476
|
+
capabilities: readonly string[] = [],
|
|
477
|
+
permissions: readonly string[] = [],
|
|
478
|
+
persistRoutes?: PersistRoutes,
|
|
479
|
+
sdkCorePath: string = sdkCoreModulePath,
|
|
480
|
+
windowViews?: readonly string[],
|
|
481
|
+
) {
|
|
450
482
|
this.tast = tast;
|
|
451
483
|
this.table = table;
|
|
452
484
|
this.files = Array.isArray(files) ? files : [files as ts.SourceFile];
|
|
453
485
|
this.entry = this.files[0];
|
|
454
486
|
this.fileSet = new Set(this.files);
|
|
487
|
+
this.serviceOps = serviceOps;
|
|
488
|
+
this.capabilities = new Set(capabilities);
|
|
489
|
+
this.permissions = new Set(permissions);
|
|
490
|
+
this.persistRoutes = persistRoutes;
|
|
491
|
+
this.sdkCorePath = sdkCorePath;
|
|
492
|
+
this.windowViews = windowViews === undefined ? undefined : new Set(windowViews);
|
|
455
493
|
}
|
|
456
494
|
|
|
457
495
|
check(): CheckResult {
|
|
458
496
|
for (const file of this.files) this.findCmdNames(file);
|
|
497
|
+
this.checkServiceCalls();
|
|
459
498
|
for (const file of this.files) this.checkModuleShape(file);
|
|
460
499
|
this.checkEntryContract();
|
|
500
|
+
this.checkPersistRoutes();
|
|
461
501
|
this.checkNameCollisions();
|
|
462
502
|
this.checkGeneratedMetadataNames();
|
|
463
503
|
this.checkModelHoldsData();
|
|
@@ -465,11 +505,27 @@ export class SubsetChecker {
|
|
|
465
505
|
this.checkCmdPurity();
|
|
466
506
|
this.checkSubPurity();
|
|
467
507
|
this.checkModelBindingSurface();
|
|
508
|
+
this.checkMigrationHook();
|
|
468
509
|
this.checkThemePackHelper();
|
|
510
|
+
this.checkStatusItemHelper();
|
|
511
|
+
this.checkStatusItemsHelper();
|
|
512
|
+
this.checkWindowsHelper();
|
|
469
513
|
this.checkViewUnbound();
|
|
470
514
|
this.checkReservedContractConsts();
|
|
471
515
|
this.checkValueRecordAliases();
|
|
472
516
|
for (const file of this.files) this.walk(file);
|
|
517
|
+
if (this.capabilities.has("persist") && !this.usesPersist) {
|
|
518
|
+
this.warn("NS1028", "app.zon declares the `persist` capability, but this core has no `Cmd.persist()` call.", this.entry);
|
|
519
|
+
}
|
|
520
|
+
if (this.capabilities.has("store") && !this.usesStore) {
|
|
521
|
+
this.warn("NS1069", "app.zon declares the `store` capability, but this core has no `Cmd.store.*` call.", this.entry);
|
|
522
|
+
}
|
|
523
|
+
if (this.capabilities.has("sqlite") && !this.usesSqlite) {
|
|
524
|
+
this.warn("NS1070", "app.zon declares the `sqlite` capability, but this core has no raw or generated relational command/subscription.", this.entry);
|
|
525
|
+
}
|
|
526
|
+
if (this.capabilities.has("credentials") && !this.usesCredentials) {
|
|
527
|
+
this.warn("NS1071", "app.zon declares the `credentials` capability, but this core has no `Cmd.credentials.*` call.", this.entry);
|
|
528
|
+
}
|
|
473
529
|
this.checkExceptions();
|
|
474
530
|
return {
|
|
475
531
|
diagnostics: this.diagnostics,
|
|
@@ -479,6 +535,72 @@ export class SubsetChecker {
|
|
|
479
535
|
};
|
|
480
536
|
}
|
|
481
537
|
|
|
538
|
+
/// NS1067 — once an app declares a service registry, every generic
|
|
539
|
+
/// Cmd.host/request literal must resolve either to that registry or to
|
|
540
|
+
/// the SDK-reserved native family. The service binding owns both command
|
|
541
|
+
/// channels, so an unknown fire-and-forget host call would otherwise be
|
|
542
|
+
/// dropped silently by ServiceHost.send.
|
|
543
|
+
private checkServiceCalls(): void {
|
|
544
|
+
if (this.serviceOps === null || this.cmdNames.size === 0) return;
|
|
545
|
+
const visit = (node: ts.Node): void => {
|
|
546
|
+
if (
|
|
547
|
+
ts.isCallExpression(node) &&
|
|
548
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
549
|
+
(node.expression.name.text === "request" || node.expression.name.text === "host") &&
|
|
550
|
+
ts.isIdentifier(node.expression.expression) &&
|
|
551
|
+
this.cmdNames.has(node.expression.expression.text) &&
|
|
552
|
+
this.isSdkReference(node.expression.expression)
|
|
553
|
+
) {
|
|
554
|
+
const name = node.arguments[0];
|
|
555
|
+
if (!name || !ts.isStringLiteral(name)) {
|
|
556
|
+
this.report("NS1067", "A service call name is not a string literal from the generated registry.", name ?? node);
|
|
557
|
+
} else if (!name.text.startsWith("native-sdk.") && !this.serviceOps.has(name.text)) {
|
|
558
|
+
this.report("NS1067", `\`${name.text}\` names no operation in services.contract.json.`, name);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
ts.forEachChild(node, visit);
|
|
562
|
+
};
|
|
563
|
+
for (const file of this.files) visit(file);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/// app.zon owns these names, while the TypeScript core owns Msg. Validate
|
|
567
|
+
/// the seam in the frontend so `native check` and the node dev host fail at
|
|
568
|
+
/// the authoring boundary instead of waiting for generated Zig to compile.
|
|
569
|
+
private checkPersistRoutes(): void {
|
|
570
|
+
const routes = this.persistRoutes;
|
|
571
|
+
if (routes === undefined) return;
|
|
572
|
+
const msg = this.table.unions.get("Msg");
|
|
573
|
+
if (msg === undefined) return; // NS1062 owns the missing-root teaching.
|
|
574
|
+
|
|
575
|
+
const checks = [
|
|
576
|
+
{ role: "ok", route: routes.ok, payload: "void" },
|
|
577
|
+
{ role: "none", route: routes.none, payload: "void" },
|
|
578
|
+
{ role: "err", route: routes.err, payload: "bytes" },
|
|
579
|
+
] as const;
|
|
580
|
+
for (const check of checks) {
|
|
581
|
+
const arm = msg.arms.find((candidate) => candidate.tag === check.route);
|
|
582
|
+
if (arm === undefined) {
|
|
583
|
+
this.report(
|
|
584
|
+
"NS1033",
|
|
585
|
+
`app.zon persistence restore route \`${check.route}\` (${check.role}) names no Msg arm.`,
|
|
586
|
+
msg.decl.name,
|
|
587
|
+
);
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
const valid =
|
|
591
|
+
check.payload === "void"
|
|
592
|
+
? arm.fields.length === 0
|
|
593
|
+
: arm.fields.length === 1 && arm.fields[0].type.k === "bytes";
|
|
594
|
+
if (!valid) {
|
|
595
|
+
this.report(
|
|
596
|
+
"NS1033",
|
|
597
|
+
`app.zon persistence restore route \`${check.route}\` (${check.role}) has the wrong Msg payload; ok/none must be void and err must carry one Uint8Array field.`,
|
|
598
|
+
arm.fields[0]?.decl ?? msg.decl.name,
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
482
604
|
private report(id: RuleId, site: string, node: ts.Node): void {
|
|
483
605
|
const file = node.getSourceFile();
|
|
484
606
|
const { line, column } = lineColumn(file, node.getStart());
|
|
@@ -511,7 +633,7 @@ export class SubsetChecker {
|
|
|
511
633
|
}
|
|
512
634
|
if (bindings && ts.isNamespaceImport(bindings)) {
|
|
513
635
|
// NS1039 (half 2): the intrinsic SDK surface is imported by name —
|
|
514
|
-
// the purity rules (NS1017/NS1025) and
|
|
636
|
+
// the purity rules (NS1017/NS1025) and byte-text folds recognize
|
|
515
637
|
// the factories by their imported names.
|
|
516
638
|
this.report("NS1039", `\`import * as ${bindings.name.text}\` aliases the intrinsic SDK module.`, bindings);
|
|
517
639
|
continue;
|
|
@@ -721,6 +843,603 @@ export class SubsetChecker {
|
|
|
721
843
|
}
|
|
722
844
|
}
|
|
723
845
|
|
|
846
|
+
/// Persistence migration is a pure entry hook, not a model helper. It
|
|
847
|
+
/// receives the previous canonical snapshot and monotonic schema version;
|
|
848
|
+
/// returning the current Model succeeds, while throwing closes as
|
|
849
|
+
/// `migrate_failed` at the host boundary.
|
|
850
|
+
private checkMigrationHook(): void {
|
|
851
|
+
let decl: ts.FunctionDeclaration | null = null;
|
|
852
|
+
for (const stmt of this.entry.statements) {
|
|
853
|
+
if (ts.isFunctionDeclaration(stmt) && stmt.name?.text === "migrate" && hasExportModifier(stmt)) {
|
|
854
|
+
decl = stmt;
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (decl === null) {
|
|
859
|
+
for (const binding of exportListBindings(this.tast, this.entry)) {
|
|
860
|
+
if (
|
|
861
|
+
binding.exportedName === "migrate" &&
|
|
862
|
+
binding.target !== null &&
|
|
863
|
+
binding.target !== undefined &&
|
|
864
|
+
ts.isFunctionDeclaration(binding.target) &&
|
|
865
|
+
binding.target.getSourceFile() === this.entry
|
|
866
|
+
) {
|
|
867
|
+
decl = binding.target;
|
|
868
|
+
break;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
if (decl === null) return;
|
|
873
|
+
const params = decl.parameters;
|
|
874
|
+
const snapshot = params[0]?.type === undefined ? null : this.table.resolveTypeNode(params[0].type);
|
|
875
|
+
const version = params[1]?.type === undefined ? null : this.table.resolveTypeNode(params[1].type);
|
|
876
|
+
const returns = decl.type === undefined ? null : this.table.resolveTypeNode(decl.type);
|
|
877
|
+
if (params.length !== 2 || snapshot?.k !== "bytes" || version?.k !== "number" || returns?.k !== "struct" || returns.name !== "Model") {
|
|
878
|
+
this.report(
|
|
879
|
+
"NS1033",
|
|
880
|
+
"`migrate` must be declared exactly as `export function migrate(snapshot: Uint8Array, fromVersion: number): Model`; throw to report `migrate_failed`.",
|
|
881
|
+
decl.name ?? decl,
|
|
882
|
+
);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/// `statusItem(model)` is the TypeScript launcher's live menu-bar
|
|
887
|
+
/// declaration. Validate both records exactly here: the Zig adapter
|
|
888
|
+
/// intentionally accepts only this one canonical, projection-safe
|
|
889
|
+
/// shape, and a source diagnostic is much more useful than generated
|
|
890
|
+
/// Zig reflection failing later.
|
|
891
|
+
private checkStatusItemHelper(): void {
|
|
892
|
+
let decl: ts.FunctionDeclaration | null = null;
|
|
893
|
+
for (const stmt of this.entry.statements) {
|
|
894
|
+
if (ts.isFunctionDeclaration(stmt) && stmt.name?.text === "statusItem" && hasExportModifier(stmt)) {
|
|
895
|
+
decl = stmt;
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
if (decl === null) {
|
|
900
|
+
for (const binding of exportListBindings(this.tast, this.entry)) {
|
|
901
|
+
if (
|
|
902
|
+
binding.exportedName === "statusItem" &&
|
|
903
|
+
binding.target !== null &&
|
|
904
|
+
binding.target !== undefined &&
|
|
905
|
+
ts.isFunctionDeclaration(binding.target) &&
|
|
906
|
+
binding.target.getSourceFile() === this.entry
|
|
907
|
+
) {
|
|
908
|
+
decl = binding.target;
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (decl === null) return;
|
|
914
|
+
|
|
915
|
+
const helper = this.table.modelHelperDecls().find(
|
|
916
|
+
(candidate) => candidate.name === "statusItem" && candidate.decl === decl,
|
|
917
|
+
);
|
|
918
|
+
if (helper === undefined || decl.type === undefined) {
|
|
919
|
+
this.report(
|
|
920
|
+
"NS1033",
|
|
921
|
+
"`statusItem` is not a single-Model-parameter helper with an explicit return type.",
|
|
922
|
+
decl.name ?? decl,
|
|
923
|
+
);
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
const returns = this.table.resolveTypeNode(decl.type);
|
|
928
|
+
const state = returns.k === "struct" ? this.table.structs.get(returns.name) : undefined;
|
|
929
|
+
const stateNames = state?.fields.map((field) => field.tsName).sort() ?? [];
|
|
930
|
+
const iconPath = state?.fields.find((field) => field.tsName === "iconPath");
|
|
931
|
+
const tooltip = state?.fields.find((field) => field.tsName === "tooltip");
|
|
932
|
+
const activationCommand = state?.fields.find((field) => field.tsName === "activationCommand");
|
|
933
|
+
const alternateActivationCommand = state?.fields.find((field) => field.tsName === "alternateActivationCommand");
|
|
934
|
+
const openCommand = state?.fields.find((field) => field.tsName === "openCommand");
|
|
935
|
+
const presentationField = state?.fields.find((field) => field.tsName === "presentation");
|
|
936
|
+
const items = state?.fields.find((field) => field.tsName === "items");
|
|
937
|
+
const presentationType = presentationField?.type.k === "struct" ? presentationField.type : null;
|
|
938
|
+
const presentation = presentationType === null ? undefined : this.table.structs.get(presentationType.name);
|
|
939
|
+
const presentationNames = presentation?.fields.map((field) => field.tsName).sort() ?? [];
|
|
940
|
+
const title = presentation?.fields.find((field) => field.tsName === "title");
|
|
941
|
+
const width = presentation?.fields.find((field) => field.tsName === "width");
|
|
942
|
+
const tone = presentation?.fields.find((field) => field.tsName === "tone");
|
|
943
|
+
const iconOpacity = presentation?.fields.find((field) => field.tsName === "iconOpacity");
|
|
944
|
+
const monospaced = presentation?.fields.find((field) => field.tsName === "monospaced");
|
|
945
|
+
const itemType = items?.type.k === "slice" && items.type.elem.k === "struct" ? items.type.elem : null;
|
|
946
|
+
const item = itemType === null ? undefined : this.table.structs.get(itemType.name);
|
|
947
|
+
const itemNames = item?.fields.map((field) => field.tsName).sort() ?? [];
|
|
948
|
+
const id = item?.fields.find((field) => field.tsName === "id");
|
|
949
|
+
const label = item?.fields.find((field) => field.tsName === "label");
|
|
950
|
+
const command = item?.fields.find((field) => field.tsName === "command");
|
|
951
|
+
const separator = item?.fields.find((field) => field.tsName === "separator");
|
|
952
|
+
const enabled = item?.fields.find((field) => field.tsName === "enabled");
|
|
953
|
+
const detail = item?.fields.find((field) => field.tsName === "detail");
|
|
954
|
+
const role = item?.fields.find((field) => field.tsName === "role");
|
|
955
|
+
const key = item?.fields.find((field) => field.tsName === "key");
|
|
956
|
+
const modifiersField = item?.fields.find((field) => field.tsName === "modifiers");
|
|
957
|
+
const modifiersType = modifiersField?.type.k === "struct" ? modifiersField.type : null;
|
|
958
|
+
const modifiers = modifiersType === null ? undefined : this.table.structs.get(modifiersType.name);
|
|
959
|
+
const modifierNames = modifiers?.fields.map((field) => field.tsName).sort() ?? [];
|
|
960
|
+
const allByteFields = [iconPath, tooltip, activationCommand, alternateActivationCommand, openCommand].every(
|
|
961
|
+
(field) => field?.type.k === "bytes",
|
|
962
|
+
);
|
|
963
|
+
const enumMembersAre = (field: typeof tone, expected: readonly string[]): boolean => {
|
|
964
|
+
if (field?.type.k !== "enum") return false;
|
|
965
|
+
const found = this.table.enums.get(field.type.name)?.members.slice().sort() ?? [];
|
|
966
|
+
return found.join(",") === expected.slice().sort().join(",");
|
|
967
|
+
};
|
|
968
|
+
const boolModifierFields = modifiers !== undefined && modifiers.fields.every((field) => field.type.k === "bool");
|
|
969
|
+
const numericId = id !== undefined && ["number", "i64", "f64", "numAlias"].includes(id.type.k);
|
|
970
|
+
const numericWidth = width !== undefined && ["number", "i64", "f64", "numAlias"].includes(width.type.k);
|
|
971
|
+
const numericOpacity = iconOpacity !== undefined && ["number", "i64", "f64", "numAlias"].includes(iconOpacity.type.k);
|
|
972
|
+
const valid =
|
|
973
|
+
stateNames.join(",") === "activationCommand,alternateActivationCommand,iconPath,items,openCommand,presentation,tooltip" &&
|
|
974
|
+
allByteFields &&
|
|
975
|
+
presentationNames.join(",") === "iconOpacity,monospaced,title,tone,width" &&
|
|
976
|
+
title?.type.k === "bytes" &&
|
|
977
|
+
numericWidth &&
|
|
978
|
+
enumMembersAre(tone, ["normal", "warning", "critical"]) &&
|
|
979
|
+
numericOpacity &&
|
|
980
|
+
monospaced?.type.k === "bool" &&
|
|
981
|
+
item !== undefined &&
|
|
982
|
+
itemNames.join(",") === "command,detail,enabled,id,key,label,modifiers,role,separator" &&
|
|
983
|
+
numericId &&
|
|
984
|
+
label?.type.k === "bytes" &&
|
|
985
|
+
command?.type.k === "bytes" &&
|
|
986
|
+
separator?.type.k === "bool" &&
|
|
987
|
+
enabled?.type.k === "bool" &&
|
|
988
|
+
detail?.type.k === "bytes" &&
|
|
989
|
+
enumMembersAre(role, ["command", "info", "header", "hero", "agent", "context"]) &&
|
|
990
|
+
key?.type.k === "bytes" &&
|
|
991
|
+
modifierNames.join(",") === "command,control,option,primary,shift" &&
|
|
992
|
+
boolModifierFields;
|
|
993
|
+
if (!valid) {
|
|
994
|
+
this.report(
|
|
995
|
+
"NS1033",
|
|
996
|
+
"`statusItem` must return the exact canonical `StatusItemState` record (live presentation, shell fields, and rich menu rows); import it from `@native-sdk/core/events`.",
|
|
997
|
+
decl.type,
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/// One entry-module function exported under its own wiring name. The
|
|
1003
|
+
/// entry-contract pass separately teaches re-exports and renames; this
|
|
1004
|
+
/// query lets related channels prove that the generated launcher will
|
|
1005
|
+
/// actually have the named callback available.
|
|
1006
|
+
private entryExportedFunction(name: string): ts.FunctionDeclaration | null {
|
|
1007
|
+
for (const stmt of this.entry.statements) {
|
|
1008
|
+
if (ts.isFunctionDeclaration(stmt) && stmt.name?.text === name && hasExportModifier(stmt)) return stmt;
|
|
1009
|
+
}
|
|
1010
|
+
for (const binding of exportListBindings(this.tast, this.entry)) {
|
|
1011
|
+
if (
|
|
1012
|
+
binding.exportedName === name &&
|
|
1013
|
+
!binding.renamed &&
|
|
1014
|
+
binding.target !== null &&
|
|
1015
|
+
binding.target !== undefined &&
|
|
1016
|
+
ts.isFunctionDeclaration(binding.target) &&
|
|
1017
|
+
binding.target.getSourceFile() === this.entry
|
|
1018
|
+
) {
|
|
1019
|
+
return binding.target;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
return null;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/// The generated launcher owns a closed, comptime-compiled registry keyed
|
|
1026
|
+
/// by direct `src/windows/<label>.native` stems. Require every possible
|
|
1027
|
+
/// descriptor to declare that identity as a literal at its canonical
|
|
1028
|
+
/// constructor call, then prove the root exists before compilation. This
|
|
1029
|
+
/// turns a would-be first-render panic into a source diagnostic in both
|
|
1030
|
+
/// `native check` and every build.
|
|
1031
|
+
private checkWindowViewRegistry(windowsDecl: ts.FunctionDeclaration): void {
|
|
1032
|
+
if (this.windowViews === undefined) return;
|
|
1033
|
+
|
|
1034
|
+
type ProducedKind = "collection" | "descriptor";
|
|
1035
|
+
let sawConstructor = false;
|
|
1036
|
+
let productionErrors = 0;
|
|
1037
|
+
const validatingCollections = new Set<ts.FunctionDeclaration>();
|
|
1038
|
+
const validatingDescriptors = new Set<ts.FunctionDeclaration>();
|
|
1039
|
+
const validatedCollections = new Set<ts.FunctionDeclaration>();
|
|
1040
|
+
const validatedDescriptors = new Set<ts.FunctionDeclaration>();
|
|
1041
|
+
|
|
1042
|
+
const unwrap = (expression: ts.Expression): ts.Expression => {
|
|
1043
|
+
let current = expression;
|
|
1044
|
+
while (
|
|
1045
|
+
ts.isParenthesizedExpression(current) ||
|
|
1046
|
+
ts.isAsExpression(current) ||
|
|
1047
|
+
ts.isSatisfiesExpression(current) ||
|
|
1048
|
+
ts.isNonNullExpression(current)
|
|
1049
|
+
) {
|
|
1050
|
+
current = current.expression;
|
|
1051
|
+
}
|
|
1052
|
+
return current;
|
|
1053
|
+
};
|
|
1054
|
+
|
|
1055
|
+
const reportProduction = (node: ts.Node, kind: ProducedKind): void => {
|
|
1056
|
+
productionErrors += 1;
|
|
1057
|
+
this.report(
|
|
1058
|
+
"NS1033",
|
|
1059
|
+
kind === "collection"
|
|
1060
|
+
? "Every value returned by `windows` must be an array literal of direct `windowDescriptor(...)` results (factored constructor helpers are fine); copied, spread, or mutable descriptor collections can replace the statically registered label."
|
|
1061
|
+
: "Every window returned by `windows` must flow directly from `windowDescriptor({...})` (or a helper whose own returns do); copying, spreading, or rebuilding a descriptor can replace its statically registered label.",
|
|
1062
|
+
node,
|
|
1063
|
+
);
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1066
|
+
const appFunctionTarget = (call: ts.CallExpression): ts.FunctionDeclaration | null => {
|
|
1067
|
+
if (!ts.isIdentifier(call.expression) && !ts.isPropertyAccessExpression(call.expression)) return null;
|
|
1068
|
+
const target = this.tast.declarationOf(
|
|
1069
|
+
ts.isIdentifier(call.expression) ? call.expression : call.expression.name,
|
|
1070
|
+
);
|
|
1071
|
+
return target && ts.isFunctionDeclaration(target) && this.fileSet.has(target.getSourceFile()) ? target : null;
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
const returnExpressions = (fn: ts.FunctionDeclaration): ts.Expression[] => {
|
|
1075
|
+
const returns: ts.Expression[] = [];
|
|
1076
|
+
const visit = (node: ts.Node): void => {
|
|
1077
|
+
if (node !== fn && (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node))) return;
|
|
1078
|
+
if (ts.isReturnStatement(node)) {
|
|
1079
|
+
if (node.expression) returns.push(node.expression);
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
ts.forEachChild(node, visit);
|
|
1083
|
+
};
|
|
1084
|
+
if (fn.body) visit(fn.body);
|
|
1085
|
+
return returns;
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1088
|
+
const validateConstructor = (call: ts.CallExpression): void => {
|
|
1089
|
+
sawConstructor = true;
|
|
1090
|
+
const spec = call.arguments[0];
|
|
1091
|
+
if (!spec || !ts.isObjectLiteralExpression(unwrap(spec))) {
|
|
1092
|
+
productionErrors += 1;
|
|
1093
|
+
this.report(
|
|
1094
|
+
"NS1033",
|
|
1095
|
+
"A model-declared window must pass an inline object to `windowDescriptor`, with a static `label: asciiBytes(\"<label>\")` property selecting its compiled view.",
|
|
1096
|
+
spec ?? call,
|
|
1097
|
+
);
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
const object = unwrap(spec) as ts.ObjectLiteralExpression;
|
|
1101
|
+
const labelProp = object.properties.find((prop): prop is ts.PropertyAssignment =>
|
|
1102
|
+
ts.isPropertyAssignment(prop) &&
|
|
1103
|
+
((ts.isIdentifier(prop.name) && prop.name.text === "label") ||
|
|
1104
|
+
(ts.isStringLiteral(prop.name) && prop.name.text === "label")),
|
|
1105
|
+
);
|
|
1106
|
+
const labelIndex = labelProp === undefined ? -1 : object.properties.indexOf(labelProp);
|
|
1107
|
+
if (object.properties.some((property, index) => ts.isSpreadAssignment(property) && index > labelIndex)) {
|
|
1108
|
+
productionErrors += 1;
|
|
1109
|
+
this.report(
|
|
1110
|
+
"NS1033",
|
|
1111
|
+
"A `windowDescriptor` spec cannot spread fields after its literal label: that spread can replace the identity after the registry check. Move the literal label after every spread.",
|
|
1112
|
+
object,
|
|
1113
|
+
);
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
const labelExpr = labelProp?.initializer;
|
|
1117
|
+
const labelArg = labelExpr && ts.isCallExpression(labelExpr) &&
|
|
1118
|
+
this.sdkRootFunctionName(labelExpr.expression) === "asciiBytes"
|
|
1119
|
+
? labelExpr.arguments[0]
|
|
1120
|
+
: undefined;
|
|
1121
|
+
if (!labelArg || !ts.isStringLiteral(labelArg)) {
|
|
1122
|
+
productionErrors += 1;
|
|
1123
|
+
this.report(
|
|
1124
|
+
"NS1033",
|
|
1125
|
+
"A model-declared window label must be a static `asciiBytes(\"<label>\")` property inside `windowDescriptor({...})`; that literal selects `src/windows/<label>.native` at build time.",
|
|
1126
|
+
labelProp ?? object,
|
|
1127
|
+
);
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
const label = labelArg.text;
|
|
1131
|
+
if (
|
|
1132
|
+
label.length === 0 ||
|
|
1133
|
+
label.length > 64 ||
|
|
1134
|
+
label === "." ||
|
|
1135
|
+
label === ".." ||
|
|
1136
|
+
label.includes("\0") ||
|
|
1137
|
+
label.includes("/") ||
|
|
1138
|
+
label.includes("\\")
|
|
1139
|
+
) {
|
|
1140
|
+
productionErrors += 1;
|
|
1141
|
+
this.report(
|
|
1142
|
+
"NS1033",
|
|
1143
|
+
"A model-declared window label must be a non-empty filename stem of at most 64 ASCII bytes, without path separators or NUL bytes.",
|
|
1144
|
+
labelArg,
|
|
1145
|
+
);
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
if (!this.windowViews.has(labelArg.text)) {
|
|
1149
|
+
productionErrors += 1;
|
|
1150
|
+
this.report(
|
|
1151
|
+
"NS1033",
|
|
1152
|
+
`Window label \`${labelArg.text}\` has no compiled view; add \`src/windows/${labelArg.text}.native\` or change the descriptor label to an existing root.`,
|
|
1153
|
+
labelArg,
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
const propertyNamed = (name: string): ts.PropertyAssignment | undefined =>
|
|
1158
|
+
object.properties.find((prop): prop is ts.PropertyAssignment =>
|
|
1159
|
+
ts.isPropertyAssignment(prop) &&
|
|
1160
|
+
((ts.isIdentifier(prop.name) && prop.name.text === name) ||
|
|
1161
|
+
(ts.isStringLiteral(prop.name) && prop.name.text === name)),
|
|
1162
|
+
);
|
|
1163
|
+
const closePolicy = propertyNamed("closePolicy")?.initializer;
|
|
1164
|
+
const alwaysHides = closePolicy !== undefined && ts.isStringLiteral(unwrap(closePolicy)) && unwrap(closePolicy).text === "hide";
|
|
1165
|
+
const closeCommand = propertyNamed("onCloseCommand")?.initializer;
|
|
1166
|
+
const closeCommandArg = closeCommand !== undefined && ts.isCallExpression(unwrap(closeCommand)) &&
|
|
1167
|
+
this.sdkRootFunctionName((unwrap(closeCommand) as ts.CallExpression).expression) === "asciiBytes"
|
|
1168
|
+
? (unwrap(closeCommand) as ts.CallExpression).arguments[0]
|
|
1169
|
+
: undefined;
|
|
1170
|
+
const definitelyEmptyCloseCommand = closeCommandArg !== undefined && ts.isStringLiteral(closeCommandArg) && closeCommandArg.text.length === 0;
|
|
1171
|
+
if (
|
|
1172
|
+
closeCommand !== undefined &&
|
|
1173
|
+
!definitelyEmptyCloseCommand &&
|
|
1174
|
+
!alwaysHides &&
|
|
1175
|
+
this.entryExportedFunction("commandMsg") === null
|
|
1176
|
+
) {
|
|
1177
|
+
productionErrors += 1;
|
|
1178
|
+
this.report(
|
|
1179
|
+
"NS1033",
|
|
1180
|
+
"A quit-close `onCloseCommand` requires `commandMsg(name: string): Msg | null`; otherwise the generated launcher cannot map the command to the Msg that removes the window declaration.",
|
|
1181
|
+
closeCommand,
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
|
|
1186
|
+
const validateFunction = (fn: ts.FunctionDeclaration, kind: ProducedKind): void => {
|
|
1187
|
+
const validating = kind === "collection" ? validatingCollections : validatingDescriptors;
|
|
1188
|
+
const validated = kind === "collection" ? validatedCollections : validatedDescriptors;
|
|
1189
|
+
if (validated.has(fn) || validating.has(fn)) return;
|
|
1190
|
+
validating.add(fn);
|
|
1191
|
+
const returns = returnExpressions(fn);
|
|
1192
|
+
if (returns.length === 0) reportProduction(fn.name ?? fn, kind);
|
|
1193
|
+
for (const expression of returns) validateExpression(expression, kind);
|
|
1194
|
+
validating.delete(fn);
|
|
1195
|
+
validated.add(fn);
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1198
|
+
const validateExpression = (raw: ts.Expression, kind: ProducedKind): void => {
|
|
1199
|
+
const expression = unwrap(raw);
|
|
1200
|
+
if (ts.isConditionalExpression(expression)) {
|
|
1201
|
+
validateExpression(expression.whenTrue, kind);
|
|
1202
|
+
validateExpression(expression.whenFalse, kind);
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
1205
|
+
if (kind === "collection" && ts.isArrayLiteralExpression(expression)) {
|
|
1206
|
+
for (const element of expression.elements) {
|
|
1207
|
+
if (ts.isSpreadElement(element)) validateExpression(element.expression, "collection");
|
|
1208
|
+
else validateExpression(element, "descriptor");
|
|
1209
|
+
}
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
if (kind === "descriptor" && ts.isIdentifier(expression)) {
|
|
1213
|
+
const declaration = this.tast.declarationOf(expression);
|
|
1214
|
+
if (
|
|
1215
|
+
declaration &&
|
|
1216
|
+
ts.isVariableDeclaration(declaration) &&
|
|
1217
|
+
declaration.initializer &&
|
|
1218
|
+
ts.isVariableDeclarationList(declaration.parent) &&
|
|
1219
|
+
(declaration.parent.flags & ts.NodeFlags.Const) !== 0
|
|
1220
|
+
) {
|
|
1221
|
+
validateExpression(declaration.initializer, "descriptor");
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
if (ts.isCallExpression(expression)) {
|
|
1226
|
+
if (kind === "descriptor" && this.sdkRootFunctionName(expression.expression) === "windowDescriptor") {
|
|
1227
|
+
validateConstructor(expression);
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
const helper = appFunctionTarget(expression);
|
|
1231
|
+
if (helper) {
|
|
1232
|
+
validateFunction(helper, kind);
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
reportProduction(expression, kind);
|
|
1237
|
+
};
|
|
1238
|
+
|
|
1239
|
+
validateFunction(windowsDecl, "collection");
|
|
1240
|
+
|
|
1241
|
+
if (!sawConstructor && productionErrors === 0) {
|
|
1242
|
+
this.report(
|
|
1243
|
+
"NS1033",
|
|
1244
|
+
"`windows` must construct each possible entry with `windowDescriptor({ label: asciiBytes(\"<label>\"), ... })` so the generated launcher can prove its `src/windows/<label>.native` view exists.",
|
|
1245
|
+
windowsDecl.name ?? windowsDecl,
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
private checkStatusItemsHelper(): void {
|
|
1251
|
+
let decl: ts.FunctionDeclaration | null = null;
|
|
1252
|
+
for (const stmt of this.entry.statements) {
|
|
1253
|
+
if (ts.isFunctionDeclaration(stmt) && stmt.name?.text === "statusItems" && hasExportModifier(stmt)) {
|
|
1254
|
+
decl = stmt;
|
|
1255
|
+
break;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
if (decl === null) {
|
|
1259
|
+
for (const binding of exportListBindings(this.tast, this.entry)) {
|
|
1260
|
+
if (
|
|
1261
|
+
binding.exportedName === "statusItems" &&
|
|
1262
|
+
binding.target !== null &&
|
|
1263
|
+
binding.target !== undefined &&
|
|
1264
|
+
ts.isFunctionDeclaration(binding.target) &&
|
|
1265
|
+
binding.target.getSourceFile() === this.entry
|
|
1266
|
+
) {
|
|
1267
|
+
decl = binding.target;
|
|
1268
|
+
break;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
if (decl === null) return;
|
|
1273
|
+
if (this.table.modelHelperDecls().some((candidate) => candidate.name === "statusItem")) {
|
|
1274
|
+
this.report("NS1033", "Export either `statusItem` or `statusItems`, not both.", decl.name ?? decl);
|
|
1275
|
+
}
|
|
1276
|
+
const helper = this.table.modelHelperDecls().find(
|
|
1277
|
+
(candidate) => candidate.name === "statusItems" && candidate.decl === decl,
|
|
1278
|
+
);
|
|
1279
|
+
if (helper === undefined || decl.type === undefined) {
|
|
1280
|
+
this.report(
|
|
1281
|
+
"NS1033",
|
|
1282
|
+
"`statusItems` must be a single-Model-parameter helper with an explicit return type.",
|
|
1283
|
+
decl.name ?? decl,
|
|
1284
|
+
);
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
const returns = this.table.resolveTypeNode(decl.type);
|
|
1288
|
+
const descriptorType = returns.k === "slice" && returns.elem.k === "struct" ? returns.elem : null;
|
|
1289
|
+
const descriptor = descriptorType === null ? undefined : this.table.structs.get(descriptorType.name);
|
|
1290
|
+
const names = descriptor?.fields.map((field) => field.tsName).sort() ?? [];
|
|
1291
|
+
const field = (name: string) => descriptor?.fields.find((candidate) => candidate.tsName === name);
|
|
1292
|
+
const id = field("id");
|
|
1293
|
+
const visible = field("visible");
|
|
1294
|
+
const byteFields = ["iconPath", "tooltip", "activationCommand", "alternateActivationCommand", "openCommand"].map(field);
|
|
1295
|
+
const presentationField = field("presentation");
|
|
1296
|
+
const presentationType = presentationField?.type.k === "struct" ? presentationField.type : null;
|
|
1297
|
+
const presentation = presentationType === null ? undefined : this.table.structs.get(presentationType.name);
|
|
1298
|
+
const presentationNames = presentation?.fields.map((candidate) => candidate.tsName).sort() ?? [];
|
|
1299
|
+
const presentationFieldNamed = (name: string) => presentation?.fields.find((candidate) => candidate.tsName === name);
|
|
1300
|
+
const title = presentationFieldNamed("title");
|
|
1301
|
+
const width = presentationFieldNamed("width");
|
|
1302
|
+
const tone = presentationFieldNamed("tone");
|
|
1303
|
+
const iconOpacity = presentationFieldNamed("iconOpacity");
|
|
1304
|
+
const monospaced = presentationFieldNamed("monospaced");
|
|
1305
|
+
const items = field("items");
|
|
1306
|
+
const itemType = items?.type.k === "slice" && items.type.elem.k === "struct" ? items.type.elem : null;
|
|
1307
|
+
const item = itemType === null ? undefined : this.table.structs.get(itemType.name);
|
|
1308
|
+
const itemNames = item?.fields.map((candidate) => candidate.tsName).sort() ?? [];
|
|
1309
|
+
const itemField = (name: string) => item?.fields.find((candidate) => candidate.tsName === name);
|
|
1310
|
+
const itemId = itemField("id");
|
|
1311
|
+
const label = itemField("label");
|
|
1312
|
+
const command = itemField("command");
|
|
1313
|
+
const separator = itemField("separator");
|
|
1314
|
+
const enabled = itemField("enabled");
|
|
1315
|
+
const detail = itemField("detail");
|
|
1316
|
+
const role = itemField("role");
|
|
1317
|
+
const key = itemField("key");
|
|
1318
|
+
const modifiersField = itemField("modifiers");
|
|
1319
|
+
const modifiersType = modifiersField?.type.k === "struct" ? modifiersField.type : null;
|
|
1320
|
+
const modifiers = modifiersType === null ? undefined : this.table.structs.get(modifiersType.name);
|
|
1321
|
+
const modifierNames = modifiers?.fields.map((candidate) => candidate.tsName).sort() ?? [];
|
|
1322
|
+
const numericId = id !== undefined && ["number", "i64", "f64", "numAlias"].includes(id.type.k);
|
|
1323
|
+
const numericItemId = itemId !== undefined && ["number", "i64", "f64", "numAlias"].includes(itemId.type.k);
|
|
1324
|
+
const numericWidth = width !== undefined && ["number", "i64", "f64", "numAlias"].includes(width.type.k);
|
|
1325
|
+
const numericOpacity = iconOpacity !== undefined && ["number", "i64", "f64", "numAlias"].includes(iconOpacity.type.k);
|
|
1326
|
+
const enumMembersAre = (candidate: typeof tone, expected: readonly string[]): boolean => {
|
|
1327
|
+
if (candidate?.type.k !== "enum") return false;
|
|
1328
|
+
const found = this.table.enums.get(candidate.type.name)?.members.slice().sort() ?? [];
|
|
1329
|
+
return found.join(",") === expected.slice().sort().join(",");
|
|
1330
|
+
};
|
|
1331
|
+
const boolModifierFields = modifiers !== undefined && modifiers.fields.every((candidate) => candidate.type.k === "bool");
|
|
1332
|
+
const valid =
|
|
1333
|
+
names.join(",") === "activationCommand,alternateActivationCommand,iconPath,id,items,openCommand,presentation,tooltip,visible" &&
|
|
1334
|
+
numericId &&
|
|
1335
|
+
visible?.type.k === "bool" &&
|
|
1336
|
+
byteFields.every((candidate) => candidate?.type.k === "bytes") &&
|
|
1337
|
+
presentationNames.join(",") === "iconOpacity,monospaced,title,tone,width" &&
|
|
1338
|
+
title?.type.k === "bytes" &&
|
|
1339
|
+
numericWidth &&
|
|
1340
|
+
enumMembersAre(tone, ["normal", "warning", "critical"]) &&
|
|
1341
|
+
numericOpacity &&
|
|
1342
|
+
monospaced?.type.k === "bool" &&
|
|
1343
|
+
itemNames.join(",") === "command,detail,enabled,id,key,label,modifiers,role,separator" &&
|
|
1344
|
+
numericItemId &&
|
|
1345
|
+
label?.type.k === "bytes" &&
|
|
1346
|
+
command?.type.k === "bytes" &&
|
|
1347
|
+
separator?.type.k === "bool" &&
|
|
1348
|
+
enabled?.type.k === "bool" &&
|
|
1349
|
+
detail?.type.k === "bytes" &&
|
|
1350
|
+
enumMembersAre(role, ["command", "info", "header", "hero", "agent", "context"]) &&
|
|
1351
|
+
key?.type.k === "bytes" &&
|
|
1352
|
+
modifierNames.join(",") === "command,control,option,primary,shift" &&
|
|
1353
|
+
boolModifierFields;
|
|
1354
|
+
if (!valid) {
|
|
1355
|
+
this.report(
|
|
1356
|
+
"NS1033",
|
|
1357
|
+
"`statusItems` must return `readonly StatusItemDescriptor[]`; import StatusItemDescriptor from `@native-sdk/core/events`.",
|
|
1358
|
+
decl.type,
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/// `windows(model)` is the TypeScript launcher's model-declared secondary
|
|
1364
|
+
/// window set. Keep the descriptor exact: the Zig adapter projects it into
|
|
1365
|
+
/// UiApp.WindowDescriptor, including close-command routing and closePolicy.
|
|
1366
|
+
private checkWindowsHelper(): void {
|
|
1367
|
+
let decl: ts.FunctionDeclaration | null = null;
|
|
1368
|
+
for (const stmt of this.entry.statements) {
|
|
1369
|
+
if (ts.isFunctionDeclaration(stmt) && stmt.name?.text === "windows" && hasExportModifier(stmt)) {
|
|
1370
|
+
decl = stmt;
|
|
1371
|
+
break;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
if (decl === null) {
|
|
1375
|
+
for (const binding of exportListBindings(this.tast, this.entry)) {
|
|
1376
|
+
if (
|
|
1377
|
+
binding.exportedName === "windows" &&
|
|
1378
|
+
binding.target !== null &&
|
|
1379
|
+
binding.target !== undefined &&
|
|
1380
|
+
ts.isFunctionDeclaration(binding.target) &&
|
|
1381
|
+
binding.target.getSourceFile() === this.entry
|
|
1382
|
+
) {
|
|
1383
|
+
decl = binding.target;
|
|
1384
|
+
break;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
if (decl === null) return;
|
|
1389
|
+
const helper = this.table.modelHelperDecls().find(
|
|
1390
|
+
(candidate) => candidate.name === "windows" && candidate.decl === decl,
|
|
1391
|
+
);
|
|
1392
|
+
if (helper === undefined || decl.type === undefined) {
|
|
1393
|
+
this.report(
|
|
1394
|
+
"NS1033",
|
|
1395
|
+
"`windows` must be a single-Model-parameter helper with an explicit `readonly WindowDescriptor[]` return type.",
|
|
1396
|
+
decl.name ?? decl,
|
|
1397
|
+
);
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
const returns = this.table.resolveTypeNode(decl.type);
|
|
1401
|
+
const descriptorType = returns.k === "slice" && returns.elem.k === "struct" ? returns.elem : null;
|
|
1402
|
+
const descriptor = descriptorType === null ? undefined : this.table.structs.get(descriptorType.name);
|
|
1403
|
+
const names = descriptor?.fields.map((field) => field.tsName).sort() ?? [];
|
|
1404
|
+
const field = (name: string) => descriptor?.fields.find((candidate) => candidate.tsName === name);
|
|
1405
|
+
const numeric = (name: string): boolean => {
|
|
1406
|
+
const candidate = field(name);
|
|
1407
|
+
return candidate !== undefined && ["number", "i64", "f64", "numAlias"].includes(candidate.type.k);
|
|
1408
|
+
};
|
|
1409
|
+
const enumMembersAre = (name: string, expected: readonly string[]): boolean => {
|
|
1410
|
+
const candidate = field(name);
|
|
1411
|
+
if (candidate?.type.k !== "enum") return false;
|
|
1412
|
+
const found = this.table.enums.get(candidate.type.name)?.members.slice().sort() ?? [];
|
|
1413
|
+
return found.join(",") === expected.slice().sort().join(",");
|
|
1414
|
+
};
|
|
1415
|
+
const optionalNumeric = (name: string): boolean => {
|
|
1416
|
+
const candidate = field(name);
|
|
1417
|
+
return candidate?.type.k === "optional" && ["number", "i64", "f64", "numAlias"].includes(candidate.type.inner.k);
|
|
1418
|
+
};
|
|
1419
|
+
const valid =
|
|
1420
|
+
names.join(",") === "activateOnShow,allowsFullscreen,alwaysOnTop,canvasLabel,clickThrough,closePolicy,height,label,minHeight,minWidth,onCloseCommand,resizable,title,titlebar,transparent,width,x,y" &&
|
|
1421
|
+
field("label")?.type.k === "bytes" &&
|
|
1422
|
+
field("canvasLabel")?.type.k === "bytes" &&
|
|
1423
|
+
field("title")?.type.k === "bytes" &&
|
|
1424
|
+
numeric("width") && numeric("height") && optionalNumeric("x") && optionalNumeric("y") &&
|
|
1425
|
+
field("resizable")?.type.k === "bool" && numeric("minWidth") && numeric("minHeight") &&
|
|
1426
|
+
enumMembersAre("titlebar", ["standard", "hidden_inset", "hidden_inset_tall", "chromeless"]) &&
|
|
1427
|
+
field("transparent")?.type.k === "bool" && field("alwaysOnTop")?.type.k === "bool" &&
|
|
1428
|
+
field("clickThrough")?.type.k === "bool" && field("activateOnShow")?.type.k === "bool" &&
|
|
1429
|
+
field("allowsFullscreen")?.type.k === "bool" && enumMembersAre("closePolicy", ["quit", "hide"]) &&
|
|
1430
|
+
field("onCloseCommand")?.type.k === "bytes";
|
|
1431
|
+
if (!valid) {
|
|
1432
|
+
const shape = descriptor?.fields.map((candidate) => `${candidate.tsName}:${candidate.type.k}${candidate.type.k === "optional" ? `(${candidate.type.inner.k}${candidate.type.inner.k === "union" ? `:${candidate.type.inner.name}` : ""})` : candidate.type.k === "enum" ? `:${candidate.type.name}` : ""}`).join(", ") ?? `missing descriptor (return=${returns.k}${returns.k === "slice" ? ` elem=${returns.elem.k}` : ""})`;
|
|
1433
|
+
this.report(
|
|
1434
|
+
"NS1033",
|
|
1435
|
+
`\`windows\` must return \`readonly WindowDescriptor[]\`; import \`WindowDescriptor\` from \`@native-sdk/core/events\` and construct entries with \`windowDescriptor(...)\`. Resolved: ${shape}`,
|
|
1436
|
+
decl.type,
|
|
1437
|
+
);
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1440
|
+
this.checkWindowViewRegistry(decl);
|
|
1441
|
+
}
|
|
1442
|
+
|
|
724
1443
|
/// NS1032 — `export const viewUnbound = [...] as const`: the dead-state
|
|
725
1444
|
/// lint opt-out. Every entry must be a string literal naming a Model
|
|
726
1445
|
/// field, an exported model helper, or a Msg kind; the emitter routes the
|
|
@@ -1151,8 +1870,8 @@ export class SubsetChecker {
|
|
|
1151
1870
|
/// the host-event channels from src/core.ts only. Imports may FEED those
|
|
1152
1871
|
/// entry points, but the exports themselves live in the entry module.
|
|
1153
1872
|
private static readonly entryOnlyExports = new Set([
|
|
1154
|
-
"update", "initialModel", "subscriptions",
|
|
1155
|
-
"commandMsg", "keyMsg", "frameMsg", "pinchMsg", "dropMsg", "appearanceMsg", "chromeMsg", "envMsgs", "themePack",
|
|
1873
|
+
"update", "initialModel", "subscriptions", "migrate",
|
|
1874
|
+
"commandMsg", "keyMsg", "frameMsg", "pinchMsg", "dropMsg", "appearanceMsg", "chromeMsg", "envMsgs", "themePack", "statusItem", "statusItems", "windows",
|
|
1156
1875
|
"viewUnbound", "modelUnbound", "msgUnbound",
|
|
1157
1876
|
]);
|
|
1158
1877
|
|
|
@@ -1273,10 +1992,13 @@ export class SubsetChecker {
|
|
|
1273
1992
|
/// module-level type-origin table and each union's payload-member table so
|
|
1274
1993
|
/// a valid TypeScript name fails with a teaching instead of duplicate Zig.
|
|
1275
1994
|
private checkGeneratedMetadataNames(): void {
|
|
1276
|
-
const
|
|
1995
|
+
const reportGeneratedName = (name: ts.Identifier): void => {
|
|
1277
1996
|
if (name.text === "type_origins") {
|
|
1278
1997
|
this.report("NS1038", "`type_origins` collides with the generated contract type-origin metadata declaration.", name);
|
|
1279
1998
|
}
|
|
1999
|
+
if (this.serviceOps !== null && name.text.startsWith("__nativeSdk")) {
|
|
2000
|
+
this.report("NS1067", "A core declaration imported by the service host uses the reserved `__nativeSdk` transport-lowering prefix.", name);
|
|
2001
|
+
}
|
|
1280
2002
|
};
|
|
1281
2003
|
for (const file of this.files) {
|
|
1282
2004
|
for (const stmt of file.statements) {
|
|
@@ -1286,10 +2008,10 @@ export class SubsetChecker {
|
|
|
1286
2008
|
ts.isClassDeclaration(stmt) ||
|
|
1287
2009
|
ts.isFunctionDeclaration(stmt)
|
|
1288
2010
|
) {
|
|
1289
|
-
if (stmt.name)
|
|
2011
|
+
if (stmt.name) reportGeneratedName(stmt.name);
|
|
1290
2012
|
} else if (ts.isVariableStatement(stmt)) {
|
|
1291
2013
|
for (const decl of stmt.declarationList.declarations) {
|
|
1292
|
-
if (ts.isIdentifier(decl.name))
|
|
2014
|
+
if (ts.isIdentifier(decl.name)) reportGeneratedName(decl.name);
|
|
1293
2015
|
}
|
|
1294
2016
|
}
|
|
1295
2017
|
}
|
|
@@ -1643,6 +2365,73 @@ export class SubsetChecker {
|
|
|
1643
2365
|
return t.isUnion() && t.types.every((m) => m.isStringLiteral());
|
|
1644
2366
|
}
|
|
1645
2367
|
|
|
2368
|
+
/// The canonical name of a function imported from the intrinsic SDK root,
|
|
2369
|
+
/// with local import renames resolved; null for app helpers and globals.
|
|
2370
|
+
private sdkRootFunctionName(expr: ts.Expression): string | null {
|
|
2371
|
+
if (!ts.isIdentifier(expr)) return null;
|
|
2372
|
+
const decl = this.tast.declarationOf(expr);
|
|
2373
|
+
if (!decl || !ts.isFunctionDeclaration(decl) || !decl.name) return null;
|
|
2374
|
+
if (path.resolve(decl.getSourceFile().fileName) !== path.resolve(this.sdkCorePath)) return null;
|
|
2375
|
+
return decl.name.text;
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
/// Find the first non-ASCII character that an expression can contribute to
|
|
2379
|
+
/// an asciiBytes result. Syntax that merely helps choose a value (for
|
|
2380
|
+
/// example a Unicode literal in a conditional's comparison) is not output;
|
|
2381
|
+
/// string-literal union values in template holes are output and must all be
|
|
2382
|
+
/// ASCII-safe.
|
|
2383
|
+
private firstNonAsciiLiteral(expr: ts.Expression): string | null {
|
|
2384
|
+
let found: string | null = null;
|
|
2385
|
+
const inspectText = (value: string): void => {
|
|
2386
|
+
if (found !== null) return;
|
|
2387
|
+
for (const ch of value) {
|
|
2388
|
+
if ((ch.codePointAt(0) ?? 0) > 0x7f) {
|
|
2389
|
+
found = ch;
|
|
2390
|
+
return;
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
};
|
|
2394
|
+
const inspectStringType = (value: ts.Expression): void => {
|
|
2395
|
+
if (found !== null) return;
|
|
2396
|
+
const type = this.tast.typeOf(value);
|
|
2397
|
+
if (type.isStringLiteral()) {
|
|
2398
|
+
inspectText(type.value);
|
|
2399
|
+
return;
|
|
2400
|
+
}
|
|
2401
|
+
if (type.isUnion()) {
|
|
2402
|
+
for (const member of type.types) {
|
|
2403
|
+
if (member.isStringLiteral()) inspectText(member.value);
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
};
|
|
2407
|
+
const inspectOutput = (value: ts.Expression): void => {
|
|
2408
|
+
if (found !== null) return;
|
|
2409
|
+
if (ts.isStringLiteralLike(value)) {
|
|
2410
|
+
inspectText(value.text);
|
|
2411
|
+
} else if (ts.isTemplateExpression(value)) {
|
|
2412
|
+
inspectText(value.head.text);
|
|
2413
|
+
for (const span of value.templateSpans) {
|
|
2414
|
+
inspectOutput(span.expression);
|
|
2415
|
+
inspectText(span.literal.text);
|
|
2416
|
+
}
|
|
2417
|
+
} else if (ts.isConditionalExpression(value)) {
|
|
2418
|
+
inspectOutput(value.whenTrue);
|
|
2419
|
+
inspectOutput(value.whenFalse);
|
|
2420
|
+
} else if (
|
|
2421
|
+
ts.isParenthesizedExpression(value) ||
|
|
2422
|
+
ts.isAsExpression(value) ||
|
|
2423
|
+
ts.isTypeAssertionExpression(value) ||
|
|
2424
|
+
ts.isNonNullExpression(value)
|
|
2425
|
+
) {
|
|
2426
|
+
inspectOutput(value.expression);
|
|
2427
|
+
} else {
|
|
2428
|
+
inspectStringType(value);
|
|
2429
|
+
}
|
|
2430
|
+
};
|
|
2431
|
+
inspectOutput(expr);
|
|
2432
|
+
return found;
|
|
2433
|
+
}
|
|
2434
|
+
|
|
1646
2435
|
private walk(root: ts.Node): void {
|
|
1647
2436
|
const visit = (node: ts.Node): void => {
|
|
1648
2437
|
// NS1002 — synchronous updates.
|
|
@@ -1811,6 +2600,23 @@ export class SubsetChecker {
|
|
|
1811
2600
|
this.report("NS1018", "A tagged template runs a function over its strings at runtime.", node);
|
|
1812
2601
|
}
|
|
1813
2602
|
|
|
2603
|
+
// NS1064 — the narrow bridge fails closed on Unicode. The check is by
|
|
2604
|
+
// resolved SDK identity (import renames honored), never by call text.
|
|
2605
|
+
if (ts.isCallExpression(node) && this.sdkRootFunctionName(node.expression) === "asciiBytes") {
|
|
2606
|
+
const arg = node.arguments[0];
|
|
2607
|
+
if (arg) {
|
|
2608
|
+
const character = this.firstNonAsciiLiteral(arg);
|
|
2609
|
+
if (character !== null) {
|
|
2610
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
2611
|
+
this.report(
|
|
2612
|
+
"NS1064",
|
|
2613
|
+
`\`asciiBytes(...)\` contains non-ASCII U+${codePoint.toString(16).toUpperCase().padStart(4, "0")}.`,
|
|
2614
|
+
arg,
|
|
2615
|
+
);
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
|
|
1814
2620
|
// NS1045 — destructuring: record fields into const locals only.
|
|
1815
2621
|
if (ts.isArrayBindingPattern(node)) {
|
|
1816
2622
|
// `for (const [i, x] of xs.entries())` keeps its own tailored
|
|
@@ -2134,9 +2940,8 @@ export class SubsetChecker {
|
|
|
2134
2940
|
}
|
|
2135
2941
|
}
|
|
2136
2942
|
|
|
2137
|
-
// NS1028 —
|
|
2138
|
-
//
|
|
2139
|
-
// the build.
|
|
2943
|
+
// NS1028 — the reserved verb compiles either way, but a shipping app
|
|
2944
|
+
// binds its host service only when app.zon declares the capability.
|
|
2140
2945
|
if (
|
|
2141
2946
|
ts.isCallExpression(node) &&
|
|
2142
2947
|
ts.isPropertyAccessExpression(node.expression) &&
|
|
@@ -2145,7 +2950,123 @@ export class SubsetChecker {
|
|
|
2145
2950
|
this.cmdNames.has(node.expression.expression.text) &&
|
|
2146
2951
|
this.isSdkReference(node.expression.expression)
|
|
2147
2952
|
) {
|
|
2148
|
-
this.
|
|
2953
|
+
this.usesPersist = true;
|
|
2954
|
+
if (!this.capabilities.has("persist")) {
|
|
2955
|
+
this.warn("NS1028", "`Cmd.persist()` requires the `persist` capability in app.zon.", node);
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
|
|
2959
|
+
// NS1074 — best-effort literal-path lint for the runtime filesystem
|
|
2960
|
+
// gate. App-dir paths normally arrive as bytes from envMsgs and remain
|
|
2961
|
+
// dynamic here; a literal absolute path or a lexical parent escape is
|
|
2962
|
+
// certainly external and should name the missing permission now.
|
|
2963
|
+
if (
|
|
2964
|
+
ts.isCallExpression(node) &&
|
|
2965
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
2966
|
+
["readFile", "writeFile", "appendFile", "statFile", "deleteFile", "readFileStream", "writeFileStream"].includes(node.expression.name.text) &&
|
|
2967
|
+
ts.isIdentifier(node.expression.expression) &&
|
|
2968
|
+
this.cmdNames.has(node.expression.expression.text) &&
|
|
2969
|
+
this.isSdkReference(node.expression.expression) &&
|
|
2970
|
+
!this.permissions.has("filesystem")
|
|
2971
|
+
) {
|
|
2972
|
+
const pathArg = node.expression.name.text === "writeFileStream" ? node.arguments[1] : node.arguments[0];
|
|
2973
|
+
if (pathArg && ts.isCallExpression(pathArg) && ["asciiBytes", "utf8Bytes"].includes(this.sdkRootFunctionName(pathArg.expression) ?? "")) {
|
|
2974
|
+
const literal = pathArg.arguments[0];
|
|
2975
|
+
if (literal && ts.isStringLiteral(literal) && (/^(?:\/|[A-Za-z]:[\\/])/.test(literal.text) || literal.text.split(/[\\/]+/).includes(".."))) {
|
|
2976
|
+
this.report("NS1074", `\`Cmd.${node.expression.name.text}\` uses a literal path outside the app-directory exemption without the \`filesystem\` permission.`, pathArg);
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2981
|
+
// NS1069 — the nested record-store factories remain capability-bound;
|
|
2982
|
+
// recognizing the SDK Cmd symbol (rather than its spelling alone) keeps
|
|
2983
|
+
// local objects named Cmd out of this cross-file contract check.
|
|
2984
|
+
if (
|
|
2985
|
+
ts.isCallExpression(node) &&
|
|
2986
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
2987
|
+
ts.isPropertyAccessExpression(node.expression.expression) &&
|
|
2988
|
+
node.expression.expression.name.text === "store" &&
|
|
2989
|
+
ts.isIdentifier(node.expression.expression.expression) &&
|
|
2990
|
+
this.cmdNames.has(node.expression.expression.expression.text) &&
|
|
2991
|
+
this.isSdkReference(node.expression.expression.expression)
|
|
2992
|
+
) {
|
|
2993
|
+
this.usesStore = true;
|
|
2994
|
+
if (!this.capabilities.has("store")) {
|
|
2995
|
+
this.warn("NS1069", "`Cmd.store.*` requires the `store` capability in app.zon.", node);
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
// NS1070 — raw relational effects are a separate capability from the
|
|
3000
|
+
// record store even though both tiers share the vendored SQLite object.
|
|
3001
|
+
if (
|
|
3002
|
+
ts.isCallExpression(node) &&
|
|
3003
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
3004
|
+
ts.isPropertyAccessExpression(node.expression.expression) &&
|
|
3005
|
+
node.expression.expression.name.text === "db" &&
|
|
3006
|
+
ts.isIdentifier(node.expression.expression.expression) &&
|
|
3007
|
+
this.cmdNames.has(node.expression.expression.expression.text) &&
|
|
3008
|
+
this.isSdkReference(node.expression.expression.expression)
|
|
3009
|
+
) {
|
|
3010
|
+
this.usesSqlite = true;
|
|
3011
|
+
if (!this.capabilities.has("sqlite")) {
|
|
3012
|
+
this.warn("NS1070", "`Cmd.db.*` requires the `sqlite` capability in app.zon.", node);
|
|
3013
|
+
}
|
|
3014
|
+
if (node.expression.name.text === "query" && ts.isStringLiteralLike(node.arguments[0])) {
|
|
3015
|
+
this.warn("NS1420", "This raw Cmd.db.query uses a string literal that native check cannot name or generate.", node.arguments[0]);
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
|
|
3019
|
+
// NS1071/NS1072 — keychain effects require both the build capability
|
|
3020
|
+
// and the runtime permission. Missing permission is a hard check error:
|
|
3021
|
+
// shipping a command guaranteed to receive `denied` is never useful.
|
|
3022
|
+
if (
|
|
3023
|
+
ts.isCallExpression(node) &&
|
|
3024
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
3025
|
+
ts.isPropertyAccessExpression(node.expression.expression) &&
|
|
3026
|
+
node.expression.expression.name.text === "credentials" &&
|
|
3027
|
+
ts.isIdentifier(node.expression.expression.expression) &&
|
|
3028
|
+
this.cmdNames.has(node.expression.expression.expression.text) &&
|
|
3029
|
+
this.isSdkReference(node.expression.expression.expression)
|
|
3030
|
+
) {
|
|
3031
|
+
this.usesCredentials = true;
|
|
3032
|
+
if (!this.capabilities.has("credentials")) {
|
|
3033
|
+
this.warn("NS1071", "`Cmd.credentials.*` requires the `credentials` capability in app.zon.", node);
|
|
3034
|
+
}
|
|
3035
|
+
if (!this.permissions.has("credentials")) {
|
|
3036
|
+
this.report("NS1072", "`Cmd.credentials.*` requires the `credentials` permission in app.zon.", node);
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
// NS1073 — the core credential wire names belong to the typed factory.
|
|
3041
|
+
// Raw Cmd.request payloads are app-controlled bytes and cannot state
|
|
3042
|
+
// the credential record contract safely at the authoring boundary.
|
|
3043
|
+
if (
|
|
3044
|
+
ts.isCallExpression(node) &&
|
|
3045
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
3046
|
+
node.expression.name.text === "request" &&
|
|
3047
|
+
ts.isIdentifier(node.expression.expression) &&
|
|
3048
|
+
this.cmdNames.has(node.expression.expression.text) &&
|
|
3049
|
+
this.isSdkReference(node.expression.expression) &&
|
|
3050
|
+
node.arguments[0] !== undefined &&
|
|
3051
|
+
ts.isStringLiteral(node.arguments[0]) &&
|
|
3052
|
+
node.arguments[0].text.startsWith("core.credentials.")
|
|
3053
|
+
) {
|
|
3054
|
+
this.usesCredentials = true;
|
|
3055
|
+
this.report("NS1073", "The `core.credentials.*` request namespace is reserved for `Cmd.credentials.*`.", node);
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
// Generated declared-query constructors and live subscriptions are the
|
|
3059
|
+
// checked relational surface, and therefore count as sqlite use too.
|
|
3060
|
+
if (
|
|
3061
|
+
ts.isCallExpression(node) &&
|
|
3062
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
3063
|
+
/^q[A-Z]/.test(node.expression.name.text) &&
|
|
3064
|
+
ts.isIdentifier(node.expression.expression) &&
|
|
3065
|
+
((this.cmdNames.has(node.expression.expression.text) || this.subNames.has(node.expression.expression.text)) &&
|
|
3066
|
+
this.isSdkReference(node.expression.expression))
|
|
3067
|
+
) {
|
|
3068
|
+
this.usesSqlite = true;
|
|
3069
|
+
if (!this.capabilities.has("sqlite")) this.warn("NS1070", "Generated `Cmd.q<Name>` and `Sub.q<Name>` require the `sqlite` capability in app.zon.", node);
|
|
2149
3070
|
}
|
|
2150
3071
|
|
|
2151
3072
|
// NS1001/NS1022/NS1051 — mutation stays inside local ownership:
|