@ogygia/compiler 0.0.0 → 0.14.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.
Files changed (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -1
  3. package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
  4. package/dist/app-spec.d.ts +18 -0
  5. package/dist/app-spec.js +22 -0
  6. package/dist/blank-styles.d.ts +1 -0
  7. package/dist/blank-styles.js +24 -0
  8. package/dist/bom.d.ts +2 -0
  9. package/dist/bom.js +7 -0
  10. package/dist/build-cache.d.ts +13 -0
  11. package/dist/build-cache.js +65 -0
  12. package/dist/ctx.d.ts +238 -0
  13. package/dist/ctx.js +221 -0
  14. package/dist/dev/css-scope.d.ts +16 -0
  15. package/dist/dev/css-scope.js +32 -0
  16. package/dist/dev/dev-hmr.d.ts +24 -0
  17. package/dist/dev/dev-hmr.js +51 -0
  18. package/dist/dev/hmr.d.ts +34 -0
  19. package/dist/dev/hmr.js +52 -0
  20. package/dist/driver.d.ts +349 -0
  21. package/dist/driver.js +1401 -0
  22. package/dist/exports/index.d.ts +77 -0
  23. package/dist/exports/index.js +349 -0
  24. package/dist/exports/parse.d.ts +65 -0
  25. package/dist/exports/parse.js +251 -0
  26. package/dist/fouc-css.d.ts +102 -0
  27. package/dist/fouc-css.js +304 -0
  28. package/dist/free-vars.d.ts +32 -0
  29. package/dist/free-vars.js +454 -0
  30. package/dist/fs.d.ts +31 -0
  31. package/dist/fs.js +82 -0
  32. package/dist/ids.d.ts +49 -0
  33. package/dist/ids.js +52 -0
  34. package/dist/index.d.ts +23 -0
  35. package/dist/index.js +23 -0
  36. package/dist/kit.d.ts +204 -0
  37. package/dist/kit.js +554 -0
  38. package/dist/leg.d.ts +34 -0
  39. package/dist/leg.js +26 -0
  40. package/dist/link/analyses.d.ts +26 -0
  41. package/dist/link/analyses.js +237 -0
  42. package/dist/link/build-output.d.ts +47 -0
  43. package/dist/link/build-output.js +168 -0
  44. package/dist/link/caps.d.ts +32 -0
  45. package/dist/link/caps.js +39 -0
  46. package/dist/link/context-detect.d.ts +28 -0
  47. package/dist/link/context-detect.js +143 -0
  48. package/dist/link/emit-gate.d.ts +43 -0
  49. package/dist/link/emit-gate.js +55 -0
  50. package/dist/link/file-token.d.ts +11 -0
  51. package/dist/link/file-token.js +15 -0
  52. package/dist/link/island-deps.d.ts +183 -0
  53. package/dist/link/island-deps.js +802 -0
  54. package/dist/link/location-map.d.ts +24 -0
  55. package/dist/link/location-map.js +51 -0
  56. package/dist/link/own-reach.d.ts +15 -0
  57. package/dist/link/own-reach.js +188 -0
  58. package/dist/link/registry-stub.d.ts +50 -0
  59. package/dist/link/registry-stub.js +163 -0
  60. package/dist/link/relocations.d.ts +79 -0
  61. package/dist/link/relocations.js +198 -0
  62. package/dist/link/router-css.d.ts +38 -0
  63. package/dist/link/router-css.js +124 -0
  64. package/dist/link/runtime-entry.d.ts +103 -0
  65. package/dist/link/runtime-entry.js +183 -0
  66. package/dist/link/server-manifest.d.ts +25 -0
  67. package/dist/link/server-manifest.js +102 -0
  68. package/dist/link/transport.d.ts +42 -0
  69. package/dist/link/transport.js +91 -0
  70. package/dist/macros/dollar.d.ts +24 -0
  71. package/dist/macros/dollar.js +397 -0
  72. package/dist/macros/pipeline.d.ts +50 -0
  73. package/dist/macros/pipeline.js +133 -0
  74. package/dist/macros/source.d.ts +9 -0
  75. package/dist/macros/source.js +115 -0
  76. package/dist/macros/store.d.ts +22 -0
  77. package/dist/macros/store.js +217 -0
  78. package/dist/macros/wire.d.ts +17 -0
  79. package/dist/macros/wire.js +116 -0
  80. package/dist/map-chain.d.ts +18 -0
  81. package/dist/map-chain.js +42 -0
  82. package/dist/messages.d.ts +672 -0
  83. package/dist/messages.js +938 -0
  84. package/dist/ownership-stamps.d.ts +9 -0
  85. package/dist/ownership-stamps.js +101 -0
  86. package/dist/parse/oxc.d.ts +36 -0
  87. package/dist/parse/oxc.js +35 -0
  88. package/dist/parse/roots.d.ts +4 -0
  89. package/dist/parse/roots.js +27 -0
  90. package/dist/parse/scan.d.ts +65 -0
  91. package/dist/parse/scan.js +297 -0
  92. package/dist/parse/svelte-ast.d.ts +7 -0
  93. package/dist/parse/svelte-ast.js +99 -0
  94. package/dist/program.d.ts +140 -0
  95. package/dist/program.js +304 -0
  96. package/dist/queries.d.ts +105 -0
  97. package/dist/queries.js +326 -0
  98. package/dist/region/emit.d.ts +168 -0
  99. package/dist/region/emit.js +292 -0
  100. package/dist/region/identity.d.ts +32 -0
  101. package/dist/region/identity.js +46 -0
  102. package/dist/region/ir.d.ts +56 -0
  103. package/dist/region/ir.js +0 -0
  104. package/dist/region/marked-imports.d.ts +27 -0
  105. package/dist/region/marked-imports.js +265 -0
  106. package/dist/region/transform.d.ts +189 -0
  107. package/dist/region/transform.js +1565 -0
  108. package/dist/scan-facts.d.ts +36 -0
  109. package/dist/scan-facts.js +54 -0
  110. package/dist/script-request.d.ts +1 -0
  111. package/dist/script-request.js +33 -0
  112. package/dist/splice.d.ts +11 -0
  113. package/dist/splice.js +33 -0
  114. package/dist/transportables.d.ts +23 -0
  115. package/dist/transportables.js +144 -0
  116. package/dist/virtual/core.d.ts +158 -0
  117. package/dist/virtual/core.js +588 -0
  118. package/dist/virtual/resolver.d.ts +56 -0
  119. package/dist/virtual/resolver.js +249 -0
  120. package/dist/virtual/specifier.d.ts +10 -0
  121. package/dist/virtual/specifier.js +6 -0
  122. package/dist/virtual/table.d.ts +118 -0
  123. package/dist/virtual/table.js +54 -0
  124. package/dist/virtual/types.d.ts +17 -0
  125. package/dist/virtual/types.js +100 -0
  126. package/dist/virtual/value-names.d.ts +2 -0
  127. package/dist/virtual/value-names.js +18 -0
  128. package/dist/vite/definers.d.ts +16 -0
  129. package/dist/vite/definers.js +69 -0
  130. package/dist/vite/dev-maps.d.ts +34 -0
  131. package/dist/vite/dev-maps.js +91 -0
  132. package/dist/vite/index.d.ts +21 -0
  133. package/dist/vite/index.js +874 -0
  134. package/dist/vite/kit-dirs.d.ts +6 -0
  135. package/dist/vite/kit-dirs.js +53 -0
  136. package/dist/vite/late-island.d.ts +11 -0
  137. package/dist/vite/late-island.js +19 -0
  138. package/dist/vite/lazy-files.d.ts +2 -0
  139. package/dist/vite/lazy-files.js +72 -0
  140. package/dist/vite/options.d.ts +195 -0
  141. package/dist/vite/options.js +72 -0
  142. package/dist/vite/package-files.d.ts +3 -0
  143. package/dist/vite/package-files.js +88 -0
  144. package/dist/vite/paths.d.ts +14 -0
  145. package/dist/vite/paths.js +37 -0
  146. package/dist/vite/plugin-api.d.ts +316 -0
  147. package/dist/vite/plugin-api.js +328 -0
  148. package/dist/vite/session.d.ts +28 -0
  149. package/dist/vite/session.js +43 -0
  150. package/dist/vite/sourcemaps.d.ts +19 -0
  151. package/dist/vite/sourcemaps.js +75 -0
  152. package/dist/vite/style-preprocess.d.ts +2 -0
  153. package/dist/vite/style-preprocess.js +84 -0
  154. package/dist/vite/svelte-entries.d.ts +4 -0
  155. package/dist/vite/svelte-entries.js +10 -0
  156. package/package.json +87 -12
@@ -0,0 +1,140 @@
1
+ import { RuntimeMarks } from "./link/runtime-entry.js";
2
+ import { ScanFacts } from "./scan-facts.js";
3
+ /** Strip a `?query` off a module id (host vs component vs Vite watch paths). */
4
+ export declare const strip_id: (id: string) => string;
5
+ /** Canonical absolute host key (query-stripped, resolved) — the registry's cross-host dedupe key. */
6
+ export declare const host_key: (hostPath: string) => string;
7
+ /** One row in the virtual-module registry — an island's entry / wrapper / region-binding artifact.
8
+ * Loose by design: the three roles carry different legs (source vs ssrSource/clientSource). */
9
+ export interface RegistryEntry {
10
+ source?: string;
11
+ ssrSource?: string;
12
+ /** A leg-split source: a wake island's wrapper reaches its component through the lazy module on
13
+ * the client leg (served by leg at load(), like a region binding). */
14
+ clientSource?: string;
15
+ hostPath?: string | null;
16
+ id: string;
17
+ server?: boolean;
18
+ lakes?: string[];
19
+ componentPath?: string | null;
20
+ role?: "entry" | "wrapper" | "region" | "lazy";
21
+ /** A portable-snippet synth entry: AUTHORED markup (a slice of user source) the transform hook
22
+ * re-processes (nested island marks, nested snippets), unlike glue. */
23
+ portable?: boolean;
24
+ /** a server entry's render identity (identity.ts `renderId`): what its endpoint renders */
25
+ renderId?: string;
26
+ }
27
+ interface HostIndexEntry {
28
+ ids: Set<string>;
29
+ vpaths: Set<string>;
30
+ }
31
+ /** One island a file's Lower phase minted — the `register`-relevant fields of a lowered descriptor.
32
+ * Loose (most fields optional) because the three legs — entry / wrapper / region binding — differ. */
33
+ export interface IslandDescriptor {
34
+ id: string;
35
+ kind?: "hydrate" | "defer" | "lake";
36
+ server?: boolean;
37
+ fetchWhen?: string;
38
+ strategy?: string;
39
+ wakeAfter?: string;
40
+ held?: boolean;
41
+ lakes?: string[];
42
+ keep?: string;
43
+ portable?: boolean;
44
+ wrapperPath?: string;
45
+ wrapperSource?: string;
46
+ /** the wrapper's client leg (lazy component; see emit.ts `island_wrapper_client_source`) */
47
+ wrapperClientSource?: string;
48
+ /** the lazy component module the client wrapper imports (`lazyEntryVirtualId`) */
49
+ lazyPath?: string;
50
+ lazySource?: string;
51
+ bindingPath?: string;
52
+ bindingSsrSource?: string;
53
+ bindingClientSource?: string;
54
+ hostPath?: string | null;
55
+ componentPath?: string | null;
56
+ virtualPath?: string;
57
+ source?: string;
58
+ /** the region identity (identity.ts `regionIdentity`) the id was hashed from */
59
+ identity?: string;
60
+ }
61
+ /** The relevant shape of a file's transform result the linker registers. */
62
+ export interface RegisterResult {
63
+ islands?: IslandDescriptor[];
64
+ /** THE one wire question a compilation answers: can this file cross live content into an island?
65
+ * The transform owns all the evidence — static placement with children, a portable `{#snippet}`,
66
+ * a wake binding with no static placement (registry/each/`svelte:component`/prop hand-off, where
67
+ * call sites are compile-invisible), a `.ts`-minted wake region. One flag here, one rule below;
68
+ * the server encoder is not gated, so a missed case is a production app whose islands ALL fail
69
+ * with "Unknown type OgygiaRef" (the factory-registry regression). */
70
+ hasWireCrossing?: boolean;
71
+ }
72
+ export declare class Program {
73
+ #private;
74
+ /** keyed by virtual path → the island's registry row (entry / wrapper / region binding) */
75
+ readonly registry: Map<string, RegistryEntry>;
76
+ /** Absolute module ids in an island's CLIENT dependency graph. `$app/*` resolves to shims
77
+ * for these importers (virtual island module AND its transitive component imports). */
78
+ readonly island_graph: Set<string>;
79
+ /** iid -> entry virtual path (hydrate / defer / swr-lake) */
80
+ readonly by_id: Map<string, string>;
81
+ /** every region id -> kind (server manifest / emit) */
82
+ readonly region_kinds: Map<string, "hydrate" | "defer" | "lake">;
83
+ /** host abs path → region ids + virtual paths discovered on last transform of that host */
84
+ readonly host_index: Map<string, HostIndexEntry>;
85
+ /** region id → hosts still claiming it (cross-host dedupe: don't drop shared wrappers) */
86
+ readonly id_hosts: Map<string, Set<string>>;
87
+ /** BUILD, server leg: every module id Vite actually transformed (`host_key`-normalised) — the
88
+ * server bundle's real graph. Handed to the client leg, which emits island chunks only for
89
+ * islands whose HOST is in it: the prescan registers every marked import under `src/`, but a
90
+ * host nothing imports (a second route tree's pages, a retired component) must not cost a
91
+ * chunk — or drag its imports into a client build whose server pass never saw them (a
92
+ * `.remote.ts` there fails Kit's "expected to find metadata" check). */
93
+ readonly ssr_transformed: Set<string>;
94
+ /** Every scanned file's facts, and the app-wide answers folded from them (./scan-facts.ts). */
95
+ readonly scan: ScanFacts;
96
+ /** Absolute paths of app modules that define a transportable class, in scan order. */
97
+ get transportable_modules(): ReadonlySet<string>;
98
+ /** PAGE MODULES (`b.pageModules()`: importers of a page specifier such as `'@ogygia/router'`, plus
99
+ * files named directly — server-router definition sites) + every walked
100
+ * module's import specifiers — the build data `ogygia:server/router-css` computes its
101
+ * component closure from (see link/router-css.ts). */
102
+ get router_modules(): ReadonlySet<string>;
103
+ get module_specs(): ReadonlyMap<string, readonly string[]>;
104
+ /** App crosses a held region / transportable value through Kit's `transport` hook — a `.remote.*`
105
+ * file, or a `region`/`site`/content import (loads & remotes that carry regions or wired values).
106
+ * With `runtime_marks.wire` it decides whether `ogygia.transport` (the generated
107
+ * `ogygia:region/kit-transport`) carries the codec cluster or is an empty map. */
108
+ get crosses_wire(): boolean;
109
+ /** The files that make {@link crosses_wire} true. */
110
+ get wire_crossers(): ReadonlySet<string>;
111
+ /** Island code can reach Kit's page world (`$app/state` and kin, or something the island-closure
112
+ * walk could not follow — driver.ts `mark_island_closure`). Folded into `runtime_marks.page` at
113
+ * the end of the prescan, with the other ways islands the walk never saw reach the runtime. */
114
+ island_reads_page: boolean;
115
+ /** Build-time capability marks for the sticky runtime entry. Incomplete → kitchen-sink. */
116
+ readonly runtime_marks: RuntimeMarks;
117
+ /** An empty program with the same options: the next build's (`Compiler.start_leg`). */
118
+ fresh(): Program;
119
+ constructor(init: {
120
+ forms: boolean;
121
+ router: boolean;
122
+ });
123
+ /** The marks the build's runtime entry is made from, now: what it ships is fixed from here on
124
+ * (test/runtime-marks-late.test.ts). */
125
+ ship_runtime(): RuntimeMarks;
126
+ note_runtime_mark(patch: Partial<RuntimeMarks>): void;
127
+ /** Drop this host's claims; shared region ids (cross-host dedupe) stay until unused. */
128
+ unregister_host(hostPath: string): void;
129
+ /** BUILD, server leg: the server regions `ogygia:server/server-regions` was written with, each
130
+ * `() => import(<its entry>)`. A region found later gets its loader as its own emitted chunk
131
+ * (driver `emit_late_server_regions`, test/server-region-late.test.ts). Null: not written yet. */
132
+ server_regions_written: ReadonlySet<string> | null;
133
+ /** Replace this host's claims; shared ids keep one registry entry (path+strategy dedupe). */
134
+ register(result: RegisterResult, hostId: string): void;
135
+ /** A deleted component: every region of it goes, with every host's claim on it (a claim kept
136
+ * would outrank the next host to mark it: test/region-host-order.test.ts). Returns the virtual
137
+ * paths that went. */
138
+ drop_component(componentPath: string): Set<string>;
139
+ }
140
+ export {};
@@ -0,0 +1,304 @@
1
+ import { renderId } from "./region/identity.js";
2
+ import { resolveFeatures } from "./link/runtime-entry.js";
3
+ import { warn } from "./messages.js";
4
+ import { same_module_path } from "./dev/hmr.js";
5
+ import { ScanFacts } from "./scan-facts.js";
6
+ import path from "node:path";
7
+ // src/program.ts
8
+ /** Strip a `?query` off a module id (host vs component vs Vite watch paths). */
9
+ const strip_id = (id) => id ? id.split("?")[0] : id;
10
+ /** Canonical absolute host key (query-stripped, resolved) — the registry's cross-host dedupe key. */
11
+ const host_key = (hostPath) => path.resolve(strip_id(hostPath));
12
+ var Program = class Program {
13
+ /** keyed by virtual path → the island's registry row (entry / wrapper / region binding) */
14
+ registry = /* @__PURE__ */ new Map();
15
+ /** Absolute module ids in an island's CLIENT dependency graph. `$app/*` resolves to shims
16
+ * for these importers (virtual island module AND its transitive component imports). */
17
+ island_graph = /* @__PURE__ */ new Set();
18
+ /** iid -> entry virtual path (hydrate / defer / swr-lake) */
19
+ by_id = /* @__PURE__ */ new Map();
20
+ /** every region id -> kind (server manifest / emit) */
21
+ region_kinds = /* @__PURE__ */ new Map();
22
+ /** host abs path → region ids + virtual paths discovered on last transform of that host */
23
+ host_index = /* @__PURE__ */ new Map();
24
+ /** region id → hosts still claiming it (cross-host dedupe: don't drop shared wrappers) */
25
+ id_hosts = /* @__PURE__ */ new Map();
26
+ /** BUILD, server leg: every module id Vite actually transformed (`host_key`-normalised) — the
27
+ * server bundle's real graph. Handed to the client leg, which emits island chunks only for
28
+ * islands whose HOST is in it: the prescan registers every marked import under `src/`, but a
29
+ * host nothing imports (a second route tree's pages, a retired component) must not cost a
30
+ * chunk — or drag its imports into a client build whose server pass never saw them (a
31
+ * `.remote.ts` there fails Kit's "expected to find metadata" check). */
32
+ ssr_transformed = /* @__PURE__ */ new Set();
33
+ /** Every scanned file's facts, and the app-wide answers folded from them (./scan-facts.ts). */
34
+ scan = new ScanFacts();
35
+ /** Absolute paths of app modules that define a transportable class, in scan order. */
36
+ get transportable_modules() {
37
+ return this.scan.db.get(this.scan.transportable_modules, "all");
38
+ }
39
+ /** PAGE MODULES (`b.pageModules()`: importers of a page specifier such as `'@ogygia/router'`, plus
40
+ * files named directly — server-router definition sites) + every walked
41
+ * module's import specifiers — the build data `ogygia:server/router-css` computes its
42
+ * component closure from (see link/router-css.ts). */
43
+ get router_modules() {
44
+ return this.scan.db.get(this.scan.router_modules, "all");
45
+ }
46
+ get module_specs() {
47
+ return this.scan.db.get(this.scan.module_specs, "all");
48
+ }
49
+ /** App crosses a held region / transportable value through Kit's `transport` hook — a `.remote.*`
50
+ * file, or a `region`/`site`/content import (loads & remotes that carry regions or wired values).
51
+ * With `runtime_marks.wire` it decides whether `ogygia.transport` (the generated
52
+ * `ogygia:region/kit-transport`) carries the codec cluster or is an empty map. */
53
+ get crosses_wire() {
54
+ return this.wire_crossers.size > 0;
55
+ }
56
+ /** The files that make {@link crosses_wire} true. */
57
+ get wire_crossers() {
58
+ return this.scan.db.get(this.scan.wire_crossers, "all");
59
+ }
60
+ /** Island code can reach Kit's page world (`$app/state` and kin, or something the island-closure
61
+ * walk could not follow — driver.ts `mark_island_closure`). Folded into `runtime_marks.page` at
62
+ * the end of the prescan, with the other ways islands the walk never saw reach the runtime. */
63
+ island_reads_page = false;
64
+ /** Build-time capability marks for the sticky runtime entry. Incomplete → kitchen-sink. */
65
+ runtime_marks;
66
+ /** The features the build's runtime entry was made with (`ship_runtime`), once it loaded: a later
67
+ * registration that needs one more is reported (`runtime_marks_late`), once per feature. */
68
+ #runtime_shipped = null;
69
+ #late_said = /* @__PURE__ */ new Set();
70
+ #init;
71
+ /** An empty program with the same options: the next build's (`Compiler.start_leg`). */
72
+ fresh() {
73
+ return new Program(this.#init);
74
+ }
75
+ constructor(init) {
76
+ this.#init = init;
77
+ this.runtime_marks = {
78
+ complete: false,
79
+ forms: init.forms,
80
+ wire: false,
81
+ remoteSeeds: false,
82
+ hydrate: [],
83
+ defer: [],
84
+ persistKeys: [],
85
+ router: init.router,
86
+ live: false,
87
+ lakes: false
88
+ };
89
+ }
90
+ /** The marks the build's runtime entry is made from, now: what it ships is fixed from here on
91
+ * (test/runtime-marks-late.test.ts). */
92
+ ship_runtime() {
93
+ this.#runtime_shipped = new Set(resolveFeatures(this.runtime_marks));
94
+ return this.runtime_marks;
95
+ }
96
+ /** A registration of `host` after the runtime entry was made needs a feature it lacks: say so. */
97
+ #check_late(host) {
98
+ const shipped = this.#runtime_shipped;
99
+ if (!shipped) return;
100
+ const late = resolveFeatures(this.runtime_marks).filter((f) => !shipped.has(f) && !this.#late_said.has(f));
101
+ if (!late.length) return;
102
+ for (const f of late) this.#late_said.add(f);
103
+ warn("runtime_marks_late", {
104
+ file: host,
105
+ features: late.join(", ")
106
+ });
107
+ }
108
+ note_runtime_mark(patch) {
109
+ const runtime_marks = this.runtime_marks;
110
+ if (patch.hydrate) runtime_marks.hydrate = [.../* @__PURE__ */ new Set([...runtime_marks.hydrate || [], ...patch.hydrate])];
111
+ if (patch.defer) runtime_marks.defer = [.../* @__PURE__ */ new Set([...runtime_marks.defer || [], ...patch.defer])];
112
+ if (patch.persistKeys) runtime_marks.persistKeys = [.../* @__PURE__ */ new Set([...runtime_marks.persistKeys || [], ...patch.persistKeys])];
113
+ if (patch.router) runtime_marks.router = true;
114
+ if (patch.live) runtime_marks.live = true;
115
+ if (patch.persist) runtime_marks.persist = true;
116
+ if (patch.morph) runtime_marks.morph = true;
117
+ if (patch.lakes) runtime_marks.lakes = true;
118
+ if (patch.wire) runtime_marks.wire = true;
119
+ }
120
+ /** Drop this host's claims; shared region ids (cross-host dedupe) stay until unused. */
121
+ unregister_host(hostPath) {
122
+ const { registry, island_graph, by_id, region_kinds, host_index, id_hosts } = this;
123
+ const key = host_key(hostPath);
124
+ const prev = host_index.get(key);
125
+ if (prev) {
126
+ for (const id of prev.ids) {
127
+ const claims = this.#rows.get(id);
128
+ claims?.delete(key);
129
+ if (claims?.size === 0) this.#rows.delete(id);
130
+ const holders = id_hosts.get(id);
131
+ if (holders) {
132
+ holders.delete(key);
133
+ if (holders.size === 0) {
134
+ id_hosts.delete(id);
135
+ region_kinds.delete(id);
136
+ by_id.delete(id);
137
+ }
138
+ } else {
139
+ region_kinds.delete(id);
140
+ by_id.delete(id);
141
+ }
142
+ }
143
+ for (const vpath of prev.vpaths) {
144
+ const entry = registry.get(vpath);
145
+ if (entry) {
146
+ const holders = id_hosts.get(entry.id);
147
+ if (!holders || holders.size === 0) {
148
+ registry.delete(vpath);
149
+ island_graph.delete(vpath);
150
+ }
151
+ } else {
152
+ registry.delete(vpath);
153
+ island_graph.delete(vpath);
154
+ }
155
+ }
156
+ for (const id of prev.ids) this.#settle(id);
157
+ host_index.delete(key);
158
+ }
159
+ }
160
+ /** BUILD, server leg: the server regions `ogygia:server/server-regions` was written with, each
161
+ * `() => import(<its entry>)`. A region found later gets its loader as its own emitted chunk
162
+ * (driver `emit_late_server_regions`, test/server-region-late.test.ts). Null: not written yet. */
163
+ server_regions_written = null;
164
+ /** Replace this host's claims; shared ids keep one registry entry (path+strategy dedupe). */
165
+ register(result, hostId) {
166
+ const { island_graph, by_id, region_kinds, host_index, id_hosts } = this;
167
+ this.unregister_host(hostId);
168
+ const key = host_key(hostId);
169
+ if (result.hasWireCrossing) this.note_runtime_mark({ wire: true });
170
+ const idx = {
171
+ ids: /* @__PURE__ */ new Set(),
172
+ vpaths: /* @__PURE__ */ new Set()
173
+ };
174
+ for (const isl of result.islands ?? []) {
175
+ const kind = isl.kind ?? (isl.server ? "defer" : "hydrate");
176
+ region_kinds.set(isl.id, kind);
177
+ idx.ids.add(isl.id);
178
+ if (kind === "defer") this.note_runtime_mark({ defer: [isl.fetchWhen || "load"] });
179
+ if (kind === "hydrate") this.note_runtime_mark({ hydrate: [isl.strategy || "load"] });
180
+ if (isl.wakeAfter) this.note_runtime_mark({ hydrate: [isl.wakeAfter] });
181
+ if (kind === "lake") this.note_runtime_mark({
182
+ lakes: true,
183
+ hydrate: ["none"]
184
+ });
185
+ if (isl.held) this.note_runtime_mark({
186
+ live: true,
187
+ morph: true
188
+ });
189
+ if (isl.lakes?.length) this.note_runtime_mark({ lakes: true });
190
+ if (isl.keep) this.note_runtime_mark({
191
+ persist: true,
192
+ persistKeys: [isl.keep]
193
+ });
194
+ let holders = id_hosts.get(isl.id);
195
+ if (!holders) {
196
+ holders = /* @__PURE__ */ new Set();
197
+ id_hosts.set(isl.id, holders);
198
+ }
199
+ holders.add(key);
200
+ const rows = [];
201
+ if (isl.wrapperPath && isl.wrapperSource) {
202
+ rows.push([isl.wrapperPath, {
203
+ source: isl.wrapperSource,
204
+ clientSource: isl.wrapperClientSource,
205
+ hostPath: isl.hostPath,
206
+ id: isl.id,
207
+ server: false,
208
+ lakes: isl.lakes ?? [],
209
+ componentPath: isl.componentPath ?? null,
210
+ role: "wrapper"
211
+ }]);
212
+ idx.vpaths.add(isl.wrapperPath);
213
+ island_graph.add(isl.wrapperPath);
214
+ }
215
+ if (isl.lazyPath && isl.lazySource) {
216
+ rows.push([isl.lazyPath, {
217
+ source: isl.lazySource,
218
+ hostPath: isl.hostPath,
219
+ id: isl.id,
220
+ server: false,
221
+ lakes: [],
222
+ componentPath: isl.componentPath ?? null,
223
+ role: "lazy"
224
+ }]);
225
+ idx.vpaths.add(isl.lazyPath);
226
+ island_graph.add(isl.lazyPath);
227
+ }
228
+ if (isl.bindingPath && isl.bindingSsrSource) {
229
+ rows.push([isl.bindingPath, {
230
+ ssrSource: isl.bindingSsrSource,
231
+ clientSource: isl.bindingClientSource ?? isl.bindingSsrSource,
232
+ hostPath: isl.hostPath,
233
+ id: isl.id,
234
+ server: false,
235
+ lakes: [],
236
+ componentPath: isl.componentPath ?? null,
237
+ role: "region"
238
+ }]);
239
+ idx.vpaths.add(isl.bindingPath);
240
+ island_graph.add(isl.bindingPath);
241
+ }
242
+ if (isl.virtualPath && isl.source) {
243
+ rows.push([isl.virtualPath, {
244
+ source: isl.source,
245
+ hostPath: isl.hostPath,
246
+ id: isl.id,
247
+ server: !!isl.server,
248
+ lakes: [],
249
+ componentPath: isl.componentPath ?? null,
250
+ role: "entry",
251
+ portable: isl.portable === true,
252
+ ...isl.server && isl.identity ? { renderId: renderId(isl.identity) } : {}
253
+ }]);
254
+ by_id.set(isl.id, isl.virtualPath);
255
+ idx.vpaths.add(isl.virtualPath);
256
+ island_graph.add(isl.virtualPath);
257
+ } else if (isl.virtualPath) by_id.set(isl.id, isl.virtualPath);
258
+ let claims = this.#rows.get(isl.id);
259
+ if (!claims) this.#rows.set(isl.id, claims = /* @__PURE__ */ new Map());
260
+ claims.set(key, rows);
261
+ this.#settle(isl.id);
262
+ if (isl.componentPath) island_graph.add(isl.componentPath);
263
+ }
264
+ host_index.set(key, idx);
265
+ this.#check_late(hostId);
266
+ }
267
+ /** A deleted component: every region of it goes, with every host's claim on it (a claim kept
268
+ * would outrank the next host to mark it: test/region-host-order.test.ts). Returns the virtual
269
+ * paths that went. */
270
+ drop_component(componentPath) {
271
+ const gone = /* @__PURE__ */ new Set();
272
+ const ids = /* @__PURE__ */ new Set();
273
+ for (const entry of this.registry.values()) if (same_module_path(entry.componentPath, componentPath)) ids.add(entry.id);
274
+ for (const id of ids) {
275
+ for (const rows of this.#rows.get(id)?.values() ?? []) for (const [vpath] of rows) gone.add(vpath);
276
+ for (const [vpath, entry] of this.registry) if (entry.id === id) gone.add(vpath);
277
+ this.#rows.delete(id);
278
+ this.id_hosts.delete(id);
279
+ this.by_id.delete(id);
280
+ this.region_kinds.delete(id);
281
+ }
282
+ for (const vpath of gone) {
283
+ this.registry.delete(vpath);
284
+ this.island_graph.delete(vpath);
285
+ }
286
+ for (const idx of this.host_index.values()) {
287
+ for (const id of ids) idx.ids.delete(id);
288
+ for (const vpath of gone) idx.vpaths.delete(vpath);
289
+ }
290
+ return gone;
291
+ }
292
+ /** Each region id's rows, by the host that claimed them (test/region-host-order.test.ts). */
293
+ #rows = /* @__PURE__ */ new Map();
294
+ /** The registry shows a shared region's rows from its FIRST holder in host order, whatever
295
+ * order the hosts were transformed (and unregistered) in. */
296
+ #settle(id) {
297
+ const claims = this.#rows.get(id);
298
+ if (!claims || claims.size === 0) return;
299
+ let first = null;
300
+ for (const k of claims.keys()) if (first === null || k < first) first = k;
301
+ for (const [vpath, entry] of claims.get(first)) this.registry.set(vpath, entry);
302
+ }
303
+ };
304
+ export { Program, host_key, strip_id };
@@ -0,0 +1,105 @@
1
+ /** What a query's body reads other queries through. */
2
+ export interface QueryCtx {
3
+ get<A, V>(query: Query<A, V>, arg: A): V;
4
+ }
5
+ /** A query: an input (read from the outside world, changed by `set` or `refresh`) or a derived
6
+ * answer (computed from other queries, never from anything else). Plain data: `key` names an
7
+ * argument, `equal` says when a new answer is the same as the old one. */
8
+ export interface Query<A, V> {
9
+ readonly name: string;
10
+ readonly kind: "input" | "derived";
11
+ key(arg: A): string;
12
+ run(cx: QueryCtx, arg: A): V;
13
+ equal(a: V, b: V): boolean;
14
+ }
15
+ /** An input: `read` is how its value is first fetched (a file system read, say). */
16
+ export declare function input<A, V>(name: string, key: (arg: A) => string, read: (arg: A) => V, equal?: (a: V, b: V) => boolean): Query<A, V>;
17
+ /** A derived answer: `run` reads only other queries, through `cx`. */
18
+ export declare function derived<A, V>(name: string, key: (arg: A) => string, run: (cx: QueryCtx, arg: A) => V, equal?: (a: V, b: V) => boolean): Query<A, V>;
19
+ type Erased = Query<unknown, unknown>;
20
+ /** One read: which answer, and the revision it had last changed at when it was read. */
21
+ export interface Dep {
22
+ readonly slot: Slot;
23
+ /** the revision the dependency had last changed at when it was read */
24
+ seen: number;
25
+ }
26
+ /** A reader's reads, in order: an answer's, or a watched reader's. `tail` is how many of `deps` the
27
+ * run going on now has read (a recompute that reads the same answers in the same order reuses
28
+ * each `Dep` in place). */
29
+ export interface Frame {
30
+ readonly deps: Dep[];
31
+ tail: number;
32
+ }
33
+ /** What the database remembers of `query(arg)`. */
34
+ export interface Slot extends Frame {
35
+ readonly query: Erased;
36
+ readonly arg: unknown;
37
+ readonly key: string;
38
+ value: unknown;
39
+ /** the revision this answer last changed at (`NO_VALUE`: it has none yet) */
40
+ changed: number;
41
+ /** the revision this answer was last checked at; or `MUST_RUN` (it never ran, or its last run
42
+ * threw: it runs when next read), `RUNNING` (a read of it now is a cycle), `LET_GO` (the bound
43
+ * let it go: a reader that read it runs again) or `RUNNING_LET_GO` (let go while it runs: still a
44
+ * cycle to read, and let go when its run ends) */
45
+ verified: number;
46
+ }
47
+ /** What a watched reader read (`watch`), each as it was when read. */
48
+ export type Reads = Frame;
49
+ /**
50
+ * A database of queries. `name` names its store in messages; `max` is how many derived answers it
51
+ * remembers (one let go is computed again when next read). Inputs are never let go: they are the
52
+ * world an answer read, and some (`set`-only ones) have no other copy.
53
+ *
54
+ * An answer the compiler derives from the app's files is a query: a pure function of other
55
+ * queries, down to INPUTS (a file's text, a directory's listing) that only the outside world
56
+ * changes. The database remembers each answer with the queries it read, so after an input changes
57
+ * it computes again only what read it, and an answer that comes out the same stops there (early
58
+ * cutoff): its readers keep theirs. Nothing is cleared by hand, and a dev session's answers are
59
+ * always the ones a cold start on the same files gives (test/queries.test.ts checks exactly that,
60
+ * over random edits).
61
+ *
62
+ * Revisions: every input change is a new revision. An answer records the revision it last changed
63
+ * at and the one it was last checked at; a read in a later revision checks the answer's
64
+ * dependencies first (in the order they were read: a dependency read after one that changed may not
65
+ * be read at all now), and runs it again only if one of them changed. The check walks its own
66
+ * stack, so a chain of answers of any depth never grows the call stack.
67
+ *
68
+ * Internal to the compiler: not exported from the package.
69
+ */
70
+ export declare class Queries implements QueryCtx {
71
+ #private;
72
+ constructor(name: string, max?: number);
73
+ /** The current revision: one more for each input change. */
74
+ get revision(): number;
75
+ get<A, V>(query: Query<A, V>, arg: A): V;
76
+ /** Run a reader that is not a query (its answer is not kept: a generated module's load, say):
77
+ * what it reads through `cx`, and through any query it reads while it runs, is recorded in
78
+ * `reads`. `cx` records even after the reader's first await; a query read then is not. */
79
+ watch<V>(reader: (cx: QueryCtx) => V): {
80
+ value: V;
81
+ reads: Reads;
82
+ };
83
+ /** Whether anything a watched reader read is different now (each is checked, and computed again
84
+ * if what it read changed: an answer that comes out the same has not moved). */
85
+ moved(reads: Reads): boolean;
86
+ /** Give an input a value. False (and no new revision) when it equals the one it had. */
87
+ set<A, V>(query: Query<A, V>, arg: A, value: V): boolean;
88
+ /** Read an input again from the outside world, if anything read it: whether it changed. */
89
+ refresh<A, V>(typed: Query<A, V>, arg: A): boolean;
90
+ /** Whether anything read this input or answer (and it is still remembered). */
91
+ holds<A, V>(query: Query<A, V>, arg: A): boolean;
92
+ /** Whether `query(arg)` is different now from what it was at revision `since` (one not held
93
+ * is computed now, as of the current revision). */
94
+ changed_since<A, V>(typed: Query<A, V>, arg: A, since: number): boolean;
95
+ /** Whether any derived answer held now is different from what it was at revision `since`
96
+ * (each is checked, and computed again if what it read changed). */
97
+ answers_changed_since(since: number): boolean;
98
+ /** Read every input anything read again from the outside world (a new session starts from what
99
+ * is there now, not from what an earlier one saw): whether any changed. */
100
+ reread(): boolean;
101
+ }
102
+ /** Structural equality over what answers are made of: primitives, arrays, plain objects, Maps and
103
+ * Sets (in order: an answer's order is part of it). */
104
+ export declare function same(a: unknown, b: unknown): boolean;
105
+ export {};