akanjs 3.0.0-beta.22 → 3.0.0-beta.24
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/client/csrTypes.ts +27 -1
- package/client/native.ts +3 -0
- package/client/route/RouteDefinition.ts +41 -1
- package/fetch/client/wsClient.ts +6 -1
- package/package.json +16 -6
- package/server/akanApp.ts +2 -3
- package/server/artifact/builderRpc.ts +5 -0
- package/server/artifact/ipcTypes.ts +10 -0
- package/server/hmr/clientScript.ts +31 -2
- package/server/hmr/csrDevManifest.ts +25 -0
- package/server/hmr/csrDevRuntime.ts +474 -0
- package/server/hmr/csrDevShell.ts +111 -0
- package/server/hmr/csrDevSourceMap.ts +142 -0
- package/server/hmr/devHmrController.ts +33 -16
- package/server/hmr/runtimeMetadataFile.ts +17 -0
- package/server/hmr/wsHub.ts +30 -4
- package/server/resolver/signal.resolver.ts +11 -5
- package/server/routing/apiRouter.ts +2 -0
- package/server/types.tsx +2 -0
- package/server/vendor/react-dom.ts +1 -0
- package/server/vendor/react-refresh-runtime.ts +13 -1
- package/server/vendor/react.ts +2 -0
- package/server/webRouter.ts +32 -2
- package/service/predefinedAdaptor/sql/QueryCompiler.ts +3 -3
- package/store/agent/ScreenTarget.ts +1 -2
- package/store/agent/StoreSurfaceSource.ts +3 -1
- package/store/liveInsert.ts +35 -13
- package/store/storeInstance.ts +28 -21
- package/types/client/csrTypes.d.ts +22 -1
- package/types/client/native.d.ts +1 -0
- package/types/client/route/RouteDefinition.d.ts +14 -0
- package/types/server/artifact/builderRpc.d.ts +2 -1
- package/types/server/artifact/ipcTypes.d.ts +11 -0
- package/types/server/hmr/csrDevManifest.d.ts +18 -0
- package/types/server/hmr/csrDevRuntime.d.ts +71 -0
- package/types/server/hmr/csrDevShell.d.ts +14 -0
- package/types/server/hmr/csrDevSourceMap.d.ts +17 -0
- package/types/server/hmr/devHmrController.d.ts +2 -1
- package/types/server/hmr/runtimeMetadataFile.d.ts +1 -0
- package/types/server/hmr/wsHub.d.ts +11 -0
- package/types/server/routing/apiRouter.d.ts +1 -0
- package/types/server/types.d.ts +2 -0
- package/types/server/vendor/react-dom.d.ts +1 -1
- package/types/server/vendor/react-refresh-runtime.d.ts +1 -1
- package/types/server/vendor/react.d.ts +1 -1
- package/types/store/storeInstance.d.ts +4 -3
- package/types/ui/System/Client.d.ts +5 -3
- package/types/vendor/@akanjs/native/plugins/app/src/index.d.ts +17 -0
- package/types/vendor/@akanjs/native/plugins/app-state/src/index.d.ts +6 -0
- package/types/vendor/use-agentic/AgentActivity.d.ts +11 -0
- package/types/vendor/use-agentic/AgentGate.d.ts +10 -0
- package/types/vendor/use-agentic/AgenticSurface.d.ts +15 -5
- package/types/vendor/use-agentic/index.d.ts +2 -0
- package/types/vendor/use-agentic/surfaceContext.d.ts +3 -0
- package/types/webkit/CsrRouteTable.d.ts +32 -0
- package/types/webkit/CsrStack.d.ts +45 -0
- package/types/webkit/RenderLayer.d.ts +2 -2
- package/types/webkit/bootCsr.d.ts +7 -8
- package/types/webkit/index.d.ts +4 -1
- package/types/webkit/nativeNavigation.d.ts +13 -0
- package/types/webkit/useCsrValues.d.ts +6 -4
- package/types/webkit/useFetch.d.ts +3 -1
- package/types/webkit/useHistory.d.ts +5 -1
- package/types/webkit/usePageActivity.d.ts +2 -0
- package/types/webkit/usePageFocusEffect.d.ts +7 -0
- package/types/webkit/usePageLocation.d.ts +13 -0
- package/ui/Data/Dashboard.tsx +2 -2
- package/ui/Data/ListContainer.tsx +2 -2
- package/ui/Layout/BottomInset.tsx +1 -1
- package/ui/Layout/Navbar.tsx +1 -1
- package/ui/Layout/TopInset.tsx +4 -3
- package/ui/System/CSR.tsx +40 -79
- package/ui/System/Client.tsx +28 -13
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeActivity.kt +53 -9
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativePlugin.kt +16 -0
- package/vendor/@akanjs/native/plugins/app/android/AppPlugin.kt +20 -0
- package/vendor/@akanjs/native/plugins/app/native-plugin.json +4 -4
- package/vendor/@akanjs/native/plugins/app/src/desktop.ts +3 -0
- package/vendor/@akanjs/native/plugins/app/src/index.ts +14 -2
- package/vendor/@akanjs/native/plugins/app-state/android/AppStatePlugin.kt +38 -2
- package/vendor/@akanjs/native/plugins/app-state/ios/AppStatePlugin.swift +19 -0
- package/vendor/@akanjs/native/plugins/app-state/native-plugin.json +1 -1
- package/vendor/@akanjs/native/plugins/app-state/src/index.ts +6 -1
- package/vendor/use-agentic/AgentActivity.tsx +26 -0
- package/vendor/use-agentic/AgentGate.ts +25 -0
- package/vendor/use-agentic/AgenticSurface.ts +92 -34
- package/vendor/use-agentic/index.ts +2 -0
- package/vendor/use-agentic/surfaceContext.ts +3 -0
- package/webkit/CsrRouteTable.ts +298 -0
- package/webkit/CsrStack.ts +98 -0
- package/webkit/RenderLayer.tsx +30 -8
- package/webkit/bootCsr.tsx +13 -217
- package/webkit/index.ts +4 -1
- package/webkit/nativeNavigation.ts +78 -5
- package/webkit/useCsrValues.ts +118 -22
- package/webkit/useFetch.ts +9 -2
- package/webkit/useHistory.ts +23 -6
- package/webkit/useLocation.ts +6 -3
- package/webkit/usePageActivity.ts +6 -0
- package/webkit/usePageFocusEffect.ts +13 -0
- package/webkit/usePageLocation.ts +17 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
export interface RawSourceMap {
|
|
2
|
+
version: 3;
|
|
3
|
+
file?: string;
|
|
4
|
+
sources: string[];
|
|
5
|
+
sourcesContent?: (string | null)[];
|
|
6
|
+
names: string[];
|
|
7
|
+
mappings: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SourceMapSection {
|
|
11
|
+
/** The line of the combined file where the section's generated line 0 lands. */
|
|
12
|
+
line: number;
|
|
13
|
+
map: RawSourceMap;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type Segment = [number] | [number, number, number, number] | [number, number, number, number, number];
|
|
17
|
+
|
|
18
|
+
export class CsrDevSourceMap {
|
|
19
|
+
static readonly #chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
20
|
+
static readonly #digits = new Map([...CsrDevSourceMap.#chars].map((char, index) => [char, index]));
|
|
21
|
+
|
|
22
|
+
static merge(file: string, sections: SourceMapSection[], lineCount: number): RawSourceMap {
|
|
23
|
+
const sources: string[] = [];
|
|
24
|
+
const sourcesContent: (string | null)[] = [];
|
|
25
|
+
const sourceIndex = new Map<string, number>();
|
|
26
|
+
const names: string[] = [];
|
|
27
|
+
const lines: Segment[][] = Array.from({ length: lineCount }, () => []);
|
|
28
|
+
for (const { line, map } of sections) {
|
|
29
|
+
const sourceOf = map.sources.map((source, index) => {
|
|
30
|
+
const known = sourceIndex.get(source);
|
|
31
|
+
if (known !== undefined) return known;
|
|
32
|
+
sourceIndex.set(source, sources.length);
|
|
33
|
+
sources.push(source);
|
|
34
|
+
sourcesContent.push(map.sourcesContent?.[index] ?? null);
|
|
35
|
+
return sources.length - 1;
|
|
36
|
+
});
|
|
37
|
+
const nameBase = names.length;
|
|
38
|
+
names.push(...map.names);
|
|
39
|
+
CsrDevSourceMap.#decode(map.mappings).forEach((segments, index) => {
|
|
40
|
+
const target = lines[line + index];
|
|
41
|
+
if (!target) return;
|
|
42
|
+
for (const segment of segments) target.push(CsrDevSourceMap.#rebase(segment, sourceOf, nameBase));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return { version: 3, file, sources, sourcesContent, names, mappings: CsrDevSourceMap.#encode(lines) };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static #rebase(segment: Segment, sourceOf: number[], nameBase: number): Segment {
|
|
49
|
+
if (segment.length === 1) return segment;
|
|
50
|
+
const source = sourceOf[segment[1]] ?? segment[1];
|
|
51
|
+
if (segment.length === 4) return [segment[0], source, segment[2], segment[3]];
|
|
52
|
+
return [segment[0], source, segment[2], segment[3], segment[4] + nameBase];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static #decode(mappings: string): Segment[][] {
|
|
56
|
+
const lines: Segment[][] = [];
|
|
57
|
+
let source = 0;
|
|
58
|
+
let originalLine = 0;
|
|
59
|
+
let originalColumn = 0;
|
|
60
|
+
let name = 0;
|
|
61
|
+
for (const lineText of mappings.split(";")) {
|
|
62
|
+
const segments: Segment[] = [];
|
|
63
|
+
let column = 0;
|
|
64
|
+
for (const segmentText of lineText.split(",")) {
|
|
65
|
+
if (!segmentText) continue;
|
|
66
|
+
const values = CsrDevSourceMap.#decodeVlq(segmentText);
|
|
67
|
+
column += values[0] ?? 0;
|
|
68
|
+
if (values.length < 4) {
|
|
69
|
+
segments.push([column]);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
source += values[1] ?? 0;
|
|
73
|
+
originalLine += values[2] ?? 0;
|
|
74
|
+
originalColumn += values[3] ?? 0;
|
|
75
|
+
if (values.length === 5) {
|
|
76
|
+
name += values[4] ?? 0;
|
|
77
|
+
segments.push([column, source, originalLine, originalColumn, name]);
|
|
78
|
+
} else segments.push([column, source, originalLine, originalColumn]);
|
|
79
|
+
}
|
|
80
|
+
lines.push(segments);
|
|
81
|
+
}
|
|
82
|
+
return lines;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static #encode(lines: Segment[][]): string {
|
|
86
|
+
let source = 0;
|
|
87
|
+
let originalLine = 0;
|
|
88
|
+
let originalColumn = 0;
|
|
89
|
+
let name = 0;
|
|
90
|
+
return lines
|
|
91
|
+
.map((segments) => {
|
|
92
|
+
let column = 0;
|
|
93
|
+
return segments
|
|
94
|
+
.map((segment) => {
|
|
95
|
+
let text = CsrDevSourceMap.#encodeVlq(segment[0] - column);
|
|
96
|
+
column = segment[0];
|
|
97
|
+
if (segment.length === 1) return text;
|
|
98
|
+
text += CsrDevSourceMap.#encodeVlq(segment[1] - source);
|
|
99
|
+
text += CsrDevSourceMap.#encodeVlq(segment[2] - originalLine);
|
|
100
|
+
text += CsrDevSourceMap.#encodeVlq(segment[3] - originalColumn);
|
|
101
|
+
[, source, originalLine, originalColumn] = segment;
|
|
102
|
+
if (segment.length === 5) {
|
|
103
|
+
text += CsrDevSourceMap.#encodeVlq(segment[4] - name);
|
|
104
|
+
name = segment[4];
|
|
105
|
+
}
|
|
106
|
+
return text;
|
|
107
|
+
})
|
|
108
|
+
.join(",");
|
|
109
|
+
})
|
|
110
|
+
.join(";");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static #decodeVlq(text: string): number[] {
|
|
114
|
+
const values: number[] = [];
|
|
115
|
+
let value = 0;
|
|
116
|
+
let shift = 0;
|
|
117
|
+
for (const char of text) {
|
|
118
|
+
const digit = CsrDevSourceMap.#digits.get(char) ?? 0;
|
|
119
|
+
value += (digit & 31) << shift;
|
|
120
|
+
if (digit & 32) {
|
|
121
|
+
shift += 5;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
values.push(value & 1 ? -(value >>> 1) : value >>> 1);
|
|
125
|
+
value = 0;
|
|
126
|
+
shift = 0;
|
|
127
|
+
}
|
|
128
|
+
return values;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static #encodeVlq(value: number): string {
|
|
132
|
+
let rest = value < 0 ? (-value << 1) | 1 : value << 1;
|
|
133
|
+
let text = "";
|
|
134
|
+
do {
|
|
135
|
+
let digit = rest & 31;
|
|
136
|
+
rest >>>= 5;
|
|
137
|
+
if (rest > 0) digit |= 32;
|
|
138
|
+
text += CsrDevSourceMap.#chars[digit];
|
|
139
|
+
} while (rest > 0);
|
|
140
|
+
return text;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { Logger } from "akanjs/common";
|
|
3
4
|
import {
|
|
@@ -10,23 +11,11 @@ import {
|
|
|
10
11
|
} from "../artifact";
|
|
11
12
|
import type { RscWorker } from "../rscWorkerHost";
|
|
12
13
|
import type { RenderState } from "../types";
|
|
14
|
+
import { CSR_DEV_DIRNAME, CSR_DEV_MANIFEST_FILE, type CsrDevManifest } from "./csrDevManifest";
|
|
15
|
+
import { isAkanRuntimeMetadataFile } from "./runtimeMetadataFile";
|
|
13
16
|
import { type ChangeKind, type HmrMessage, type HmrWsData, HmrWsHub } from "./wsHub";
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export function isAkanRuntimeMetadataFile(file: string): boolean {
|
|
18
|
-
const resolved = path.resolve(file);
|
|
19
|
-
const parts = resolved.split(/[\\/]+/).filter(Boolean);
|
|
20
|
-
const base = parts.at(-1);
|
|
21
|
-
if (!base) return false;
|
|
22
|
-
|
|
23
|
-
const parent = parts.at(-2);
|
|
24
|
-
if (parent === "lib" && APP_RUNTIME_METADATA_BASENAMES.has(base)) return true;
|
|
25
|
-
|
|
26
|
-
const libIndex = parts.lastIndexOf("lib");
|
|
27
|
-
if (libIndex < 0 || parts.length <= libIndex + 1) return false;
|
|
28
|
-
return base.endsWith(".dictionary.ts") || base.endsWith(".signal.ts");
|
|
29
|
-
}
|
|
18
|
+
export { isAkanRuntimeMetadataFile };
|
|
30
19
|
|
|
31
20
|
export function manifestClientEntriesForFiles(
|
|
32
21
|
files: string[],
|
|
@@ -109,10 +98,23 @@ export class DevHmrController {
|
|
|
109
98
|
this.#seedIndex = seedIndex;
|
|
110
99
|
this.#graphSeeds = DevHmrController.#graphSeedsOf(seedIndex);
|
|
111
100
|
this.#upgradeHmrWs = upgradeHmrWs;
|
|
101
|
+
this.#renderState.csrGeneration ??= DevHmrController.#readCsrGeneration(artifactDir);
|
|
112
102
|
this.#builderRpc = this.#createBuilderRpc();
|
|
113
103
|
this.routeCache = this.#createRouteCache();
|
|
114
104
|
}
|
|
115
105
|
|
|
106
|
+
static #readCsrGeneration(artifactDir: string): number | undefined {
|
|
107
|
+
try {
|
|
108
|
+
const manifest = JSON.parse(
|
|
109
|
+
fs.readFileSync(path.join(artifactDir, CSR_DEV_DIRNAME, CSR_DEV_MANIFEST_FILE), "utf8"),
|
|
110
|
+
) as Partial<CsrDevManifest>;
|
|
111
|
+
return typeof manifest.generation === "number" ? manifest.generation : undefined;
|
|
112
|
+
} catch {
|
|
113
|
+
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
116
118
|
get hub(): HmrWsHub {
|
|
117
119
|
return this.#hub;
|
|
118
120
|
}
|
|
@@ -126,7 +128,8 @@ export class DevHmrController {
|
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
handleWs(req: Request): Response | undefined {
|
|
129
|
-
|
|
131
|
+
const client = new URL(req.url).searchParams.get("client") === "csr" ? "csr" : "ssr";
|
|
132
|
+
if (this.#upgradeHmrWs(req, { kind: "akan-hmr", openedAt: Date.now(), client })) return;
|
|
130
133
|
return new Response("Failed to upgrade HMR WebSocket", { status: 500 });
|
|
131
134
|
}
|
|
132
135
|
|
|
@@ -197,6 +200,20 @@ export class DevHmrController {
|
|
|
197
200
|
onBuildStatus: (status) => {
|
|
198
201
|
this.#recordBuildStatus(status);
|
|
199
202
|
},
|
|
203
|
+
onCsrUpdated: (update) => {
|
|
204
|
+
this.#renderState.csrGeneration = update.generation;
|
|
205
|
+
this.#hub.broadcast({
|
|
206
|
+
type: "csr-update",
|
|
207
|
+
generation: update.generation,
|
|
208
|
+
url: update.patchUrl,
|
|
209
|
+
changedIds: update.changedIds,
|
|
210
|
+
reload: update.reload,
|
|
211
|
+
reason: update.reason,
|
|
212
|
+
});
|
|
213
|
+
this.#logger.verbose(
|
|
214
|
+
`[csr] ${update.mode} generation=${update.generation} ${update.reload ? `reload (${update.reason ?? "no reason"})` : `patch modules=${update.changedIds?.length ?? 0}`}`,
|
|
215
|
+
);
|
|
216
|
+
},
|
|
200
217
|
onCssUpdated: (css) => {
|
|
201
218
|
const started = Date.now();
|
|
202
219
|
const cssBytesByUrl = Object.fromEntries(
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
const APP_RUNTIME_METADATA_BASENAMES = new Set(["dict.ts", "sig.ts", "useClient.ts"]);
|
|
4
|
+
|
|
5
|
+
export function isAkanRuntimeMetadataFile(file: string): boolean {
|
|
6
|
+
const resolved = path.resolve(file);
|
|
7
|
+
const parts = resolved.split(/[\\/]+/).filter(Boolean);
|
|
8
|
+
const base = parts.at(-1);
|
|
9
|
+
if (!base) return false;
|
|
10
|
+
|
|
11
|
+
const parent = parts.at(-2);
|
|
12
|
+
if (parent === "lib" && APP_RUNTIME_METADATA_BASENAMES.has(base)) return true;
|
|
13
|
+
|
|
14
|
+
const libIndex = parts.lastIndexOf("lib");
|
|
15
|
+
if (libIndex < 0 || parts.length <= libIndex + 1) return false;
|
|
16
|
+
return base.endsWith(".dictionary.ts") || base.endsWith(".signal.ts");
|
|
17
|
+
}
|
package/server/hmr/wsHub.ts
CHANGED
|
@@ -8,9 +8,12 @@ export interface ChangeBatch {
|
|
|
8
8
|
kinds: Set<Exclude<ChangeKind, "ignore">>;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export type HmrClientKind = "ssr" | "csr";
|
|
12
|
+
|
|
11
13
|
export interface HmrWsData {
|
|
12
14
|
kind: "akan-hmr";
|
|
13
15
|
openedAt: number;
|
|
16
|
+
client?: HmrClientKind;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
export type HmrMessage =
|
|
@@ -18,8 +21,17 @@ export type HmrMessage =
|
|
|
18
21
|
type: "hello";
|
|
19
22
|
buildId: number;
|
|
20
23
|
cssAssets?: Record<string, { cssUrl: string; cssRelPath: string }>;
|
|
24
|
+
csrGeneration?: number;
|
|
21
25
|
}
|
|
22
26
|
| { type: "reload"; buildId: number }
|
|
27
|
+
| {
|
|
28
|
+
type: "csr-update";
|
|
29
|
+
generation: number;
|
|
30
|
+
url?: string;
|
|
31
|
+
changedIds?: string[];
|
|
32
|
+
reload?: boolean;
|
|
33
|
+
reason?: string;
|
|
34
|
+
}
|
|
23
35
|
| { type: "rsc-refresh"; buildId: number; generation?: number; changedFiles?: string[]; routeIds?: string[] }
|
|
24
36
|
| {
|
|
25
37
|
type: "client-refresh";
|
|
@@ -42,6 +54,7 @@ export type HmrMessage =
|
|
|
42
54
|
| { type: "error"; message: string };
|
|
43
55
|
|
|
44
56
|
export const HMR_WS_TOPIC = "__akan_hmr";
|
|
57
|
+
export const HMR_CSR_WS_TOPIC = "__akan_hmr_csr";
|
|
45
58
|
|
|
46
59
|
export class HmrWsHub {
|
|
47
60
|
readonly #logger = new Logger("HmrWsHub");
|
|
@@ -53,18 +66,31 @@ export class HmrWsHub {
|
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
attach(ws: Bun.ServerWebSocket<HmrWsData>): void {
|
|
56
|
-
ws.subscribe(
|
|
69
|
+
ws.subscribe(HmrWsHub.#topicOf(ws.data?.client));
|
|
57
70
|
this.#conns.add(ws);
|
|
58
|
-
this.#logger.verbose(`[hmr] ws connected (total=${this.#conns.size})`);
|
|
71
|
+
this.#logger.verbose(`[hmr] ws connected client=${ws.data?.client ?? "ssr"} (total=${this.#conns.size})`);
|
|
59
72
|
}
|
|
60
73
|
|
|
61
74
|
detach(ws: Bun.ServerWebSocket<HmrWsData>): void {
|
|
62
|
-
ws.unsubscribe(
|
|
75
|
+
ws.unsubscribe(HmrWsHub.#topicOf(ws.data?.client));
|
|
63
76
|
if (this.#conns.delete(ws)) this.#logger.verbose(`[hmr] ws disconnected (total=${this.#conns.size})`);
|
|
64
77
|
}
|
|
65
78
|
|
|
66
79
|
broadcast(msg: HmrMessage): void {
|
|
67
|
-
|
|
80
|
+
const payload = JSON.stringify(msg);
|
|
81
|
+
const audience = HmrWsHub.#audienceOf(msg);
|
|
82
|
+
if (audience !== "csr") this.#publish?.(HMR_WS_TOPIC, payload);
|
|
83
|
+
if (audience !== "ssr") this.#publish?.(HMR_CSR_WS_TOPIC, payload);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static #audienceOf(msg: HmrMessage): HmrClientKind | "all" {
|
|
87
|
+
if (msg.type === "csr-update") return "csr";
|
|
88
|
+
if (msg.type === "reload" || msg.type === "rsc-refresh" || msg.type === "client-refresh") return "ssr";
|
|
89
|
+
return "all";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static #topicOf(client: HmrClientKind | undefined): string {
|
|
93
|
+
return client === "csr" ? HMR_CSR_WS_TOPIC : HMR_WS_TOPIC;
|
|
68
94
|
}
|
|
69
95
|
|
|
70
96
|
handleMessage(message: string): void {
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type Cls,
|
|
6
6
|
ENDPOINT_META,
|
|
7
7
|
FIELD_META,
|
|
8
|
+
Float,
|
|
8
9
|
getEnv,
|
|
9
10
|
ID,
|
|
10
11
|
INTERNAL_META,
|
|
@@ -14,7 +15,7 @@ import {
|
|
|
14
15
|
SLICE_META,
|
|
15
16
|
} from "akanjs/base";
|
|
16
17
|
import { capitalize, cookieHeaderHasAuthToken, Logger } from "akanjs/common";
|
|
17
|
-
import { deserialize, resolvePageLimit, resolvePageSkip, serialize } from "akanjs/constant";
|
|
18
|
+
import { type ConstantField, deserialize, resolvePageLimit, resolvePageSkip, serialize } from "akanjs/constant";
|
|
18
19
|
import { baseDocumentColumns, documentQueryHelper, getFilterSortByKey, type QueryFieldMap } from "akanjs/document";
|
|
19
20
|
import {
|
|
20
21
|
type AkanJob,
|
|
@@ -475,9 +476,11 @@ export class SignalResolver {
|
|
|
475
476
|
}) {}
|
|
476
477
|
return SliceEndpoint;
|
|
477
478
|
}
|
|
478
|
-
|
|
479
|
+
|
|
480
|
+
static readonly #clientOrderableTypes = new Set<unknown>([Int, Float, String, ID, Boolean, Date]);
|
|
479
481
|
static #assertLiveSort(refName: string, key: string, sliceInfo: SliceInfo) {
|
|
480
|
-
const lightFields =
|
|
482
|
+
const lightFields =
|
|
483
|
+
(sliceInfo.light as unknown as { [FIELD_META]?: Record<string, ConstantField> })[FIELD_META] ?? {};
|
|
481
484
|
for (const sortKey of sliceInfo.liveOption?.sort ?? []) {
|
|
482
485
|
const sort = getFilterSortByKey(sliceInfo.filter, sortKey);
|
|
483
486
|
if (!sort)
|
|
@@ -489,9 +492,12 @@ export class SignalResolver {
|
|
|
489
492
|
`Live slice "${refName}.${key}" declares sort "${sortKey}" on "${path}", which is not in ` +
|
|
490
493
|
`Light${capitalize(refName)}. A subscriber cannot order by a field it never receives.`,
|
|
491
494
|
);
|
|
495
|
+
const { modelRef, isArray, isMap } = lightFields[path].getProps();
|
|
496
|
+
if (!isArray && !isMap && SignalResolver.#clientOrderableTypes.has(modelRef)) continue;
|
|
492
497
|
SignalResolver.logger.warn(
|
|
493
|
-
`Live slice "${refName}.${key}" sorts by "${path}", which is
|
|
494
|
-
`
|
|
498
|
+
`Live slice "${refName}.${key}" sorts "${sortKey}" by "${path}", which is not an Int, Float, String, ID, ` +
|
|
499
|
+
`Boolean or Date field, so a client placing a new row may disagree with the server. Sort by one of ` +
|
|
500
|
+
`those, or leave "${sortKey}" out of .live({ sort }) so the list refetches when a row arrives.`,
|
|
495
501
|
);
|
|
496
502
|
}
|
|
497
503
|
}
|
|
@@ -13,6 +13,7 @@ export interface HmrStateSource {
|
|
|
13
13
|
readonly state: {
|
|
14
14
|
buildId: number;
|
|
15
15
|
cssAssets?: Record<string, { cssUrl: string; cssRelPath: string }>;
|
|
16
|
+
csrGeneration?: number;
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -104,6 +105,7 @@ export class ApiRouter {
|
|
|
104
105
|
type: "hello",
|
|
105
106
|
buildId: hmrState.state.buildId,
|
|
106
107
|
cssAssets: hmrState.state.cssAssets,
|
|
108
|
+
csrGeneration: hmrState.state.csrGeneration,
|
|
107
109
|
}),
|
|
108
110
|
);
|
|
109
111
|
return;
|
package/server/types.tsx
CHANGED
|
@@ -140,4 +140,6 @@ export interface RenderState {
|
|
|
140
140
|
buildId: number;
|
|
141
141
|
cssAssets: Record<string, CssAsset>;
|
|
142
142
|
cssBytesByUrl: Record<string, Uint8Array>;
|
|
143
|
+
/** The newest CSR dev bundle generation; a CSR tab whose own generation differs has missed an update. */
|
|
144
|
+
csrGeneration?: number;
|
|
143
145
|
}
|
|
@@ -3,4 +3,16 @@
|
|
|
3
3
|
import * as m from "react-refresh/runtime";
|
|
4
4
|
|
|
5
5
|
export default m;
|
|
6
|
-
export const {
|
|
6
|
+
export const {
|
|
7
|
+
_getMountedRootCount,
|
|
8
|
+
collectCustomHooksForSignature,
|
|
9
|
+
createSignatureFunctionForTransform,
|
|
10
|
+
getFamilyByID,
|
|
11
|
+
getFamilyByType,
|
|
12
|
+
hasUnrecoverableErrors,
|
|
13
|
+
injectIntoGlobalHook,
|
|
14
|
+
isLikelyComponentType,
|
|
15
|
+
performReactRefresh,
|
|
16
|
+
register,
|
|
17
|
+
setSignature,
|
|
18
|
+
} = m;
|
package/server/vendor/react.ts
CHANGED
package/server/webRouter.ts
CHANGED
|
@@ -36,6 +36,8 @@ import {
|
|
|
36
36
|
} from "./cachePolicy";
|
|
37
37
|
import { encodedFileResponse } from "./contentEncoding";
|
|
38
38
|
import { HMR_CLIENT_SCRIPT } from "./hmr/clientScript";
|
|
39
|
+
import { CSR_DEV_ROUTE_PREFIX, resolveDevCsrMode } from "./hmr/csrDevManifest";
|
|
40
|
+
import { CsrDevShell } from "./hmr/csrDevShell";
|
|
39
41
|
import { DevHmrController } from "./hmr/devHmrController";
|
|
40
42
|
import type { HmrWsData, HmrWsHub } from "./hmr/wsHub";
|
|
41
43
|
import { ImageOptimizer } from "./imageOptimizer";
|
|
@@ -269,6 +271,7 @@ export class WebRouter {
|
|
|
269
271
|
#builderRpc: BuilderRpc | null;
|
|
270
272
|
#routeCache: RouteClientCache;
|
|
271
273
|
#devHmr: DevHmrController | null = null;
|
|
274
|
+
#csrDevShell: CsrDevShell | null = null;
|
|
272
275
|
#csrArmed = false;
|
|
273
276
|
#csrOnDemandBuild: Promise<unknown> | null = null;
|
|
274
277
|
readonly #requestStats = {
|
|
@@ -334,6 +337,7 @@ export class WebRouter {
|
|
|
334
337
|
this.#builderRpc = this.#devHmr.builderRpc;
|
|
335
338
|
this.#routeCache = this.#devHmr.routeCache;
|
|
336
339
|
this.#hub = this.#devHmr.hub;
|
|
340
|
+
if (resolveDevCsrMode() === "registry") this.#csrDevShell = new CsrDevShell(this.#artifactDir);
|
|
337
341
|
}
|
|
338
342
|
}
|
|
339
343
|
|
|
@@ -365,8 +369,9 @@ export class WebRouter {
|
|
|
365
369
|
const renderEnvRoutes: HttpRoutes = {
|
|
366
370
|
...(this.web.csr
|
|
367
371
|
? {
|
|
368
|
-
"/__csr": async () => {
|
|
372
|
+
"/__csr": async (req) => {
|
|
369
373
|
this.#requestStats.csr += 1;
|
|
374
|
+
if (this.#csrDevShell) return await this.#serveCsrDevShell(req, "/", this.#csrDevShell);
|
|
370
375
|
const csrHtml = await this.#resolveCsrHtml(csrOutputDir, "/");
|
|
371
376
|
const csrFile = csrHtml ? Bun.file(csrHtml) : null;
|
|
372
377
|
const htmlText =
|
|
@@ -387,6 +392,14 @@ export class WebRouter {
|
|
|
387
392
|
</html>`;
|
|
388
393
|
return new Response(this.#withCsrHmr(htmlText), { headers: WebRouter.#htmlResponseHeaders(200) });
|
|
389
394
|
},
|
|
395
|
+
...(this.#csrDevShell
|
|
396
|
+
? {
|
|
397
|
+
[`${CSR_DEV_ROUTE_PREFIX}*`]: async (req: Request) => {
|
|
398
|
+
this.#requestStats.staticAsset += 1;
|
|
399
|
+
return (await this.#csrDevShell?.serve(req)) ?? new Response("Not Found", { status: 404 });
|
|
400
|
+
},
|
|
401
|
+
}
|
|
402
|
+
: {}),
|
|
390
403
|
}
|
|
391
404
|
: {}),
|
|
392
405
|
[`${clientServePrefix}/*`]: async (req) => {
|
|
@@ -518,6 +531,7 @@ export class WebRouter {
|
|
|
518
531
|
const isCsr = url.searchParams.get("csr") === "true";
|
|
519
532
|
if (isCsr) {
|
|
520
533
|
this.#requestStats.csr += 1;
|
|
534
|
+
if (this.#csrDevShell) return await this.#serveCsrDevShell(req, url.pathname, this.#csrDevShell);
|
|
521
535
|
const csrHtml = await this.#resolveCsrHtml(csrOutputDir, url.pathname);
|
|
522
536
|
if (!csrHtml) return this.#csrUnavailableResponse(url.pathname);
|
|
523
537
|
const html = await Bun.file(csrHtml).text();
|
|
@@ -935,7 +949,23 @@ export class WebRouter {
|
|
|
935
949
|
}
|
|
936
950
|
#withCsrHmr(html: string): string {
|
|
937
951
|
if (this.#prodMode) return html;
|
|
938
|
-
|
|
952
|
+
const csrGeneration = this.renderState.csrGeneration ?? null;
|
|
953
|
+
const flags = `self.__AKAN_HMR_CLIENT__="csr";self.__AKAN_CSR_GENERATION__=${csrGeneration};`;
|
|
954
|
+
return WebRouter.#injectBeforeBodyEnd(html, `<script>${flags}${HMR_CLIENT_SCRIPT}</script>`);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
async #serveCsrDevShell(req: Request, pathname: string, shell: CsrDevShell): Promise<Response> {
|
|
958
|
+
await this.#armCsrArtifact(pathname);
|
|
959
|
+
const basePath =
|
|
960
|
+
getBasePathFromPathname(pathname, { basePaths: this.#artifact.basePaths, i18n: this.#artifact.i18n }) ?? "";
|
|
961
|
+
const html = await shell.render({
|
|
962
|
+
basePath,
|
|
963
|
+
lang: "en",
|
|
964
|
+
title: process.env.AKAN_PUBLIC_APP_NAME ?? "akan",
|
|
965
|
+
cssHref: this.#getStylesheetHref(req, pathname),
|
|
966
|
+
});
|
|
967
|
+
if (!html) return this.#csrUnavailableResponse(pathname);
|
|
968
|
+
return new Response(this.#withCsrHmr(html), { headers: WebRouter.#htmlResponseHeaders(200) });
|
|
939
969
|
}
|
|
940
970
|
async #resolveCsrHtml(csrOutputDir: string, pathname: string): Promise<string | null> {
|
|
941
971
|
const resolved = WebRouter.#resolveCsrHtmlPath(csrOutputDir, pathname, this.#artifact);
|
|
@@ -37,9 +37,9 @@ export class QueryCompiler {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
orderBy(sort: Record<string, 1 | -1> = { createdAt: -1 }) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const terms = Object.entries(sort);
|
|
41
|
+
if (!terms.some(([path]) => path === "id")) terms.push(["id", terms.at(-1)?.[1] ?? -1]);
|
|
42
|
+
return terms.map(([path, direction]) => this.dialect.orderTerm(this.fieldExpr(path), direction)).join(", ");
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
fieldExpr(path: string) {
|
|
@@ -99,8 +99,7 @@ export class ScreenTarget {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
static visible(el: HTMLElement) {
|
|
102
|
-
if (el.
|
|
103
|
-
if (el.closest("[data-agent-ui]")) return false;
|
|
102
|
+
if (el.closest('[hidden], [aria-hidden="true"], [inert], [data-agent-ui]')) return false;
|
|
104
103
|
return typeof el.checkVisibility === "function" ? el.checkVisibility() : true;
|
|
105
104
|
}
|
|
106
105
|
|
|
@@ -178,7 +178,9 @@ export class StoreSurfaceSource implements SurfaceSource {
|
|
|
178
178
|
|
|
179
179
|
static #zoneRoot(viewKey: string): HTMLElement | undefined {
|
|
180
180
|
if (!viewKey || typeof document === "undefined") return undefined;
|
|
181
|
-
return document.
|
|
181
|
+
return [...document.querySelectorAll<HTMLElement>(`[data-agent-zone="${CSS.escape(viewKey)}"]`)].find(
|
|
182
|
+
ScreenTarget.visible,
|
|
183
|
+
);
|
|
182
184
|
}
|
|
183
185
|
}
|
|
184
186
|
|
package/store/liveInsert.ts
CHANGED
|
@@ -30,31 +30,53 @@ export const livePlacementIndex = ({
|
|
|
30
30
|
const sort = sorts?.[sortKey];
|
|
31
31
|
if (!sort || !Object.keys(sort).length) return null;
|
|
32
32
|
const paths = Object.entries(sort);
|
|
33
|
-
if (paths.some(([path]) => comparableOf(row[path]) ===
|
|
34
|
-
|
|
33
|
+
if (paths.some(([path]) => comparableOf(row[path]) === undefined)) return null;
|
|
34
|
+
let orderable = true;
|
|
35
|
+
const index = list.findIndex((item) => {
|
|
36
|
+
const order = compareRows(row, item, paths);
|
|
37
|
+
orderable = order !== null;
|
|
38
|
+
return order === null || order < 0;
|
|
39
|
+
});
|
|
40
|
+
if (!orderable) return null;
|
|
35
41
|
if (index !== -1) return index;
|
|
36
42
|
|
|
37
43
|
if (cumulative) return hasMore ? null : list.length;
|
|
38
44
|
return list.length < limit ? list.length : null;
|
|
39
45
|
};
|
|
40
46
|
|
|
41
|
-
const compareRows = (left: LiveSortableRow, right: LiveSortableRow, paths: [string, 1 | -1][]): number => {
|
|
47
|
+
const compareRows = (left: LiveSortableRow, right: LiveSortableRow, paths: [string, 1 | -1][]): number | null => {
|
|
42
48
|
for (const [path, direction] of paths) {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
if (a === null || b === null) continue;
|
|
46
|
-
if (a === b) continue;
|
|
47
|
-
return (a < b ? -1 : 1) * direction;
|
|
49
|
+
const order = compareValues(comparableOf(left[path]), comparableOf(right[path]));
|
|
50
|
+
if (order !== 0) return order === null ? null : order * direction;
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
const order = compareValues(comparableOf(left.id), comparableOf(right.id));
|
|
53
|
+
return order === null ? null : order * (paths.at(-1)?.[1] ?? -1);
|
|
50
54
|
};
|
|
51
55
|
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
56
|
+
const compareValues = (a: Comparable | undefined, b: Comparable | undefined): number | null => {
|
|
57
|
+
if (a === undefined || b === undefined) return null;
|
|
58
|
+
if (a === b) return 0;
|
|
59
|
+
if (a === null) return -1;
|
|
60
|
+
if (b === null) return 1;
|
|
61
|
+
if (typeof a === "string" && typeof b === "string") return compareText(a, b);
|
|
62
|
+
if (typeof a === "number" && typeof b === "number") return a < b ? -1 : 1;
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const compareText = (a: string, b: string) => {
|
|
67
|
+
let idx = 0;
|
|
68
|
+
while (idx < a.length && idx < b.length && a[idx] === b[idx]) idx += 1;
|
|
69
|
+
return (a.codePointAt(idx) ?? -1) < (b.codePointAt(idx) ?? -1) ? -1 : 1;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type Comparable = number | string | null;
|
|
73
|
+
|
|
74
|
+
const comparableOf = (value: unknown): Comparable | undefined => {
|
|
75
|
+
if (value === null) return null;
|
|
54
76
|
if (typeof value === "number" || typeof value === "string") return value;
|
|
55
77
|
if (typeof value === "boolean") return value ? 1 : 0;
|
|
56
78
|
if (value instanceof Date) return value.getTime();
|
|
57
|
-
const valued: unknown = (value as { valueOf?: () => unknown })
|
|
79
|
+
const valued: unknown = (value as { valueOf?: () => unknown } | undefined)?.valueOf?.();
|
|
58
80
|
if (typeof valued === "number" || typeof valued === "string") return valued;
|
|
59
|
-
return
|
|
81
|
+
return undefined;
|
|
60
82
|
};
|