akanjs 3.3.0-rc.11 → 3.3.0-rc.12

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/CHANGELOG.md CHANGED
@@ -108,6 +108,7 @@
108
108
 
109
109
  **Upgrading.** `BlobStorage` now has an `onInit` that makes this check. A subclass of your own that defines `onInit` calls `super.onInit()` first. A deployment whose data directory another user owns stops at boot with the message above: run the `chown` it names once, or let the chart's `volumePermissions` init container do it.
110
110
 
111
+ - 5c7c6cf: `SignalSerializer.httpRoutesOf(EndpointClass, apiPrefix?)` from `akanjs/server` lists the HTTP routes an endpoint class declares: each query and mutation's `key`, `method` and `path`, the path being the one the route table mounts, with `apiPrefix` joined unless the endpoint opts out of the global prefix. It reads the class's declarations alone, so a test can check an endpoint's routes without booting an app or importing a file `akanjs/server` does not publish.
111
112
  - aff1ba2: An external view opens only origins the app's config lists, in `native.desktop.externalView.allowOrigins`: a view's own `allowOrigins` narrow within them, and an origin outside them is `NOT_ALLOWED`, naming that key. `evaluate` and `initScript` need their own permission, granted by `desktop.externalView.evaluate: true`, and `sendKey` its own, granted by `desktop.externalView.sendKey: true`; both are off by default. While a view is open, opening its id again keeps its origins or narrows them, and refuses one it was not opened for; once closed, the id opens again for any origins the config lists, with the same browser profile, which belongs to the id. Origins compare exactly as the URL parser reads them: scheme, host and port, the host in punycode without a trailing dot, the default port left out, and an origin with user info refused; there are no wildcards. A view loads a URL as the URL parser writes it, so the engine never reads the page's text another way. A page opens a view only over its own window. The desktop shell checks all of this itself on macOS, Windows and Linux, and grants nothing when the build carries no permission list; on Windows a view now takes only the two DevTools calls `sendKey` and `capture` make. A top-level navigation or redirect off a view's origins stays refused, as before.
112
113
 
113
114
  A plugin manifest's `scope` can say `required: true`: then every grant of the plugin, not only `<plugin>:default`, is within its `defaultScope` unless the grant gives its own `allow`, and a scope entry naming no field is a build error. `external-view` says so.
@@ -256,6 +257,8 @@
256
257
 
257
258
  The port now answers from the start of the build. A request to `localhost` or an IP address, page or API, waits for the first artifact; a build longer than the 15 s the gateway holds a request ends the wait with a 503 "Backend is starting" page that reloads itself. A request to one of the app's own domains (a custom local domain) gets that 503 at once until the backend is ready, because the build has not written the app's hosts yet; after that it is served as before, and any other Host is refused as before.
258
259
 
260
+ - 8f9d432: A page no longer shows a broken character where React's output buffer ends. React writes a page's HTML in 4 KB pieces cut by bytes; when the piece that carried the document's head ended inside a character of more than one byte (Korean, Japanese, an accented letter, an emoji), that character arrived as replacement marks and a stray one closed the document. It depended on where the text fell, so the same page could be right on one request and wrong on the next.
261
+
259
262
  ## 3.2.0
260
263
 
261
264
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.11",
3
+ "version": "3.3.0-rc.12",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -25,7 +25,15 @@ import type { DatabaseModule, ServiceModule } from "../akanLib";
25
25
  import type { DiLifecycle } from "../di/diLifecycle";
26
26
  import { SignalResolver } from "../resolver";
27
27
  import { ApiRouter } from "../routing/apiRouter";
28
- import type { EndpointNode, InternalNode, RouteRow, SignalData, SignalNode, SliceNode } from "./types";
28
+ import type {
29
+ EndpointHttpRoute,
30
+ EndpointNode,
31
+ InternalNode,
32
+ RouteRow,
33
+ SignalData,
34
+ SignalNode,
35
+ SliceNode,
36
+ } from "./types";
29
37
 
30
38
  export interface SignalSerializerContext {
31
39
  di: DiLifecycle;
@@ -213,6 +221,15 @@ export class SignalSerializer {
213
221
  });
214
222
  }
215
223
 
224
+ static httpRoutesOf(endpointCls: EndpointCls, apiPrefix = ""): EndpointHttpRoute[] {
225
+ const defaultPrefix = endpointCls.srv.cnst?.refName;
226
+ return Object.entries(SignalSerializer.#endpointMeta(endpointCls)).flatMap(([key, info]) => {
227
+ if (info.type !== "query" && info.type !== "mutation") return [];
228
+ const method = info.type === "mutation" ? (info.signalOption.method ?? "POST") : "GET";
229
+ return [{ key, method, path: SignalSerializer.#httpPath(key, info, defaultPrefix, apiPrefix) }];
230
+ });
231
+ }
232
+
216
233
  static #httpPath(key: string, info: EndpointInfo, defaultPrefix: string | undefined, apiPrefix: string): string {
217
234
  return ApiRouter.applyGlobalPrefix(apiPrefix, info.getRoutePath(key, defaultPrefix), info.signalOption);
218
235
  }
@@ -191,6 +191,12 @@ export interface RouteRow {
191
191
  fileUpload?: boolean;
192
192
  }
193
193
 
194
+ export interface EndpointHttpRoute {
195
+ key: string;
196
+ method: "GET" | HttpMutationMethod;
197
+ path: string;
198
+ }
199
+
194
200
  export interface SignalData {
195
201
  prefix: string;
196
202
  websocketPrefix: string;
@@ -0,0 +1,73 @@
1
+ interface HeadSpliceOptions {
2
+ afterOpen: string;
3
+ beforeClose: string;
4
+ rewriteOpening?: (html: string) => string;
5
+ withoutHead?: (html: string) => string;
6
+ }
7
+
8
+ export class HeadSplice {
9
+ static readonly #open = /<head(\s[^>]*)?>/i;
10
+ static readonly #close = "</head>";
11
+
12
+ static into(
13
+ stream: ReadableStream<Uint8Array>,
14
+ { afterOpen, beforeClose, rewriteOpening = (html) => html, withoutHead = rewriteOpening }: HeadSpliceOptions,
15
+ ): ReadableStream<Uint8Array> {
16
+ const encoder = new TextEncoder();
17
+ const decoder = new TextDecoder();
18
+ let buffered = "";
19
+ let awaiting: "open" | "close" | undefined = "open";
20
+
21
+ return stream.pipeThrough(
22
+ new TransformStream<Uint8Array, Uint8Array>({
23
+ transform(chunk, controller) {
24
+ if (!awaiting) {
25
+ controller.enqueue(chunk);
26
+ return;
27
+ }
28
+ buffered += decoder.decode(chunk, { stream: true });
29
+ let out = "";
30
+ if (awaiting === "open") {
31
+ const match = HeadSplice.#open.exec(buffered);
32
+ if (!match) return;
33
+ const end = match.index + match[0].length;
34
+ out = rewriteOpening(buffered.slice(0, end)) + afterOpen;
35
+ buffered = buffered.slice(end);
36
+ awaiting = "close";
37
+ }
38
+ const close = beforeClose ? buffered.indexOf(HeadSplice.#close) : 0;
39
+ if (close < 0) {
40
+ const held = Math.min(buffered.length, HeadSplice.#close.length - 1);
41
+ out += buffered.slice(0, buffered.length - held);
42
+ buffered = buffered.slice(buffered.length - held);
43
+ if (out) controller.enqueue(encoder.encode(out));
44
+ return;
45
+ }
46
+ controller.enqueue(encoder.encode(out + buffered.slice(0, close) + beforeClose + buffered.slice(close)));
47
+ buffered = "";
48
+ awaiting = undefined;
49
+
50
+ const cut = HeadSplice.#cutCharacter(chunk);
51
+ if (cut.length) controller.enqueue(cut);
52
+ },
53
+ flush(controller) {
54
+ if (!awaiting) return;
55
+
56
+ const rest = buffered + decoder.decode();
57
+ if (rest) controller.enqueue(encoder.encode(awaiting === "open" ? withoutHead(rest) : rest));
58
+ },
59
+ }),
60
+ );
61
+ }
62
+
63
+ static #cutCharacter(chunk: Uint8Array): Uint8Array {
64
+ for (let back = 1; back <= Math.min(3, chunk.length); back++) {
65
+ const byte = chunk[chunk.length - back];
66
+ if (byte === undefined || byte < 0x80) break;
67
+ if (byte < 0xc0) continue;
68
+ const length = byte >= 0xf0 ? 4 : byte >= 0xe0 ? 3 : 2;
69
+ return chunk.subarray(chunk.length - (back < length ? back : 0));
70
+ }
71
+ return chunk.subarray(chunk.length);
72
+ }
73
+ }
package/server/index.ts CHANGED
@@ -92,6 +92,7 @@ export {
92
92
  type DevtoolsRouterContext,
93
93
  type DictionaryData,
94
94
  type DictionaryModuleNode,
95
+ type EndpointHttpRoute,
95
96
  type EndpointNode,
96
97
  type EnumNode,
97
98
  type FieldType,
@@ -3,6 +3,7 @@ import {
3
3
  CookieJar,
4
4
  type Logger,
5
5
  SessionCookies,
6
+ trimSlashes,
6
7
  websocketAuthContract,
7
8
  websocketHeartbeatContract,
8
9
  } from "akanjs/common";
@@ -283,7 +284,7 @@ export class ApiRouter {
283
284
  static #normalizeRoutePath(path: string): string {
284
285
  const trimmed = path.trim();
285
286
  if (!trimmed || trimmed === "/") return "/";
286
- return `/${trimmed.replace(/^\/+|\/+$/g, "")}`;
287
+ return `/${trimSlashes(trimmed)}`;
287
288
  }
288
289
 
289
290
  static #wrapRoutesWithWebProxy(
@@ -11,6 +11,7 @@ import { createFromNodeStream } from "react-server-dom-webpack/client.node";
11
11
  import { parsePositiveInt } from "./cachePolicy";
12
12
  import { FlightModulePreloads } from "./flightModulePreloads";
13
13
  import { mapFlightLineRows } from "./flightRowReader";
14
+ import { HeadSplice } from "./headSplice";
14
15
  import type {
15
16
  SsrChunkRegistryStats,
16
17
  SsrDocumentOptions,
@@ -748,8 +749,6 @@ export class SsrFromRscRenderer {
748
749
  injectThemeInitScript?: boolean;
749
750
  },
750
751
  ): ReadableStream<Uint8Array> {
751
- const encoder = new TextEncoder();
752
- const decoder = new TextDecoder();
753
752
  const { importmap, modulePreloads, theme, injectThemeInitScript } = options;
754
753
 
755
754
  const chunkTags = SsrFromRscRenderer.#createModulePreloadTags(options.chunkPreloads);
@@ -764,10 +763,6 @@ export class SsrFromRscRenderer {
764
763
  const tags = `${themeInitTag}${importmapTag}${modulePreloadTags}`;
765
764
  if (!tags && !chunkTags && !htmlTheme) return stream;
766
765
  const htmlOpenRe = /<html(\s[^>]*)?>/i;
767
- const headOpenRe = /<head(\s[^>]*)?>/i;
768
- let buffered = "";
769
- let awaiting: "<head>" | "</head>" | undefined = "<head>";
770
-
771
766
  const withHtmlTheme = (html: string): string => {
772
767
  if (!htmlTheme) return html;
773
768
  return html.replace(htmlOpenRe, (tag) => {
@@ -775,38 +770,7 @@ export class SsrFromRscRenderer {
775
770
  return tag.replace(/>$/, ` data-theme="${escapeHtmlAttr(htmlTheme)}">`);
776
771
  });
777
772
  };
778
-
779
- return stream.pipeThrough(
780
- new TransformStream<Uint8Array, Uint8Array>({
781
- transform(chunk, controller) {
782
- if (!awaiting) {
783
- controller.enqueue(chunk);
784
- return;
785
- }
786
- buffered += decoder.decode(chunk, { stream: true });
787
- let out = "";
788
- if (awaiting === "<head>") {
789
- const m = headOpenRe.exec(buffered);
790
- if (!m) return;
791
- const end = m.index + m[0].length;
792
- out = withHtmlTheme(buffered.slice(0, end)) + tags;
793
- buffered = buffered.slice(end);
794
- awaiting = "</head>";
795
- }
796
- const close = chunkTags ? buffered.indexOf(awaiting) : 0;
797
- const cut = close >= 0 ? close : Math.max(0, buffered.length - awaiting.length + 1);
798
- out += buffered.slice(0, cut) + (close >= 0 ? chunkTags + buffered.slice(cut) : "");
799
- buffered = close >= 0 ? "" : buffered.slice(cut);
800
- if (close >= 0) awaiting = undefined;
801
- if (out) controller.enqueue(encoder.encode(out));
802
- },
803
- flush(controller) {
804
-
805
- const rest = buffered + decoder.decode();
806
- if (rest) controller.enqueue(encoder.encode(awaiting === "<head>" ? withHtmlTheme(rest) : rest));
807
- },
808
- }),
809
- );
773
+ return HeadSplice.into(stream, { afterOpen: tags, beforeClose: chunkTags, rewriteOpening: withHtmlTheme });
810
774
  }
811
775
 
812
776
  static #createModulePreloadTags(modules: string[]): string {
@@ -1,5 +1,6 @@
1
+ import type { EndpointCls } from "akanjs/signal";
1
2
  import type { DiLifecycle } from "../di/diLifecycle.d.ts";
2
- import type { SignalData } from "./types.d.ts";
3
+ import type { EndpointHttpRoute, SignalData } from "./types.d.ts";
3
4
  export interface SignalSerializerContext {
4
5
  di: DiLifecycle;
5
6
  serverMode: "federation" | "batch" | "all";
@@ -10,4 +11,5 @@ export interface SignalSerializerContext {
10
11
  export declare class SignalSerializer {
11
12
  #private;
12
13
  static serialize({ di, serverMode, prefix, websocketPrefix }: SignalSerializerContext): SignalData;
14
+ static httpRoutesOf(endpointCls: EndpointCls, apiPrefix?: string): EndpointHttpRoute[];
13
15
  }
@@ -203,6 +203,11 @@ export interface RouteRow {
203
203
  timeout?: number;
204
204
  fileUpload?: boolean;
205
205
  }
206
+ export interface EndpointHttpRoute {
207
+ key: string;
208
+ method: "GET" | HttpMutationMethod;
209
+ path: string;
210
+ }
206
211
  export interface SignalData {
207
212
  prefix: string;
208
213
  websocketPrefix: string;
@@ -0,0 +1,11 @@
1
+ interface HeadSpliceOptions {
2
+ afterOpen: string;
3
+ beforeClose: string;
4
+ rewriteOpening?: (html: string) => string;
5
+ withoutHead?: (html: string) => string;
6
+ }
7
+ export declare class HeadSplice {
8
+ #private;
9
+ static into(stream: ReadableStream<Uint8Array>, { afterOpen, beforeClose, rewriteOpening, withoutHead }: HeadSpliceOptions): ReadableStream<Uint8Array>;
10
+ }
11
+ export {};
@@ -5,7 +5,7 @@ export { AkanServer, type AkanServerConsoleInfo, type AkanServerOptions, type Ak
5
5
  export { type BuildChangesPayload, type BuilderControl, type BuilderCsrReq, type BuilderCsrRes, type BuilderEvent, type BuilderFailureKind, type BuilderGraphReq, type BuilderGraphRes, type BuilderMessage, type BuilderMetrics, type BuilderReq, type BuilderRequest, type BuilderRes, type BuilderResponse, BuilderRpc, type BuilderRpcEventHandlers, type BuilderRpcTimeout, type BuilderRpcUnavailable, type BuilderStateReason, type BuildFrameworkPayload, type BuildGraphPayload, type BuildPhase, type BuildRouteClientResult, type BuildRouteResultPayload, type ClientManifest, type ClientManifestEntry, type CsrUpdatedPayload, type CssPayload, DevBuildRecovery, type DevBuildStatus, type DevChangeAction, type DevChangePlan, type DevChangeRole, type HmrTrace, type InvalidateClientEntriesOptions, type MatchedRoute, type MergedManifest, ModulePreloadPlan, type ModulePreloadTable, type PagesBundlePayload, ROUTE_SEED_INDEX_JSON, RouteClientCache, type RouteSeedEntry, type RouteSeedIndex, RouteSeedIndexStore, type RoutesManifest, RoutesManifestStore, type SsrUpdatedPayload, } from "./artifact.d.ts";
6
6
  export { type AkanConsoleContext, type AkanConsoleOptions, assertAkanConsoleAllowed, evaluateAkanConsoleInput, getAkanConsoleMethods, isAkanConsoleInputComplete, startAkanConsole, } from "./console.d.ts";
7
7
  export { Transaction, Try } from "./decorators.d.ts";
8
- export { type ArgType, type ConstantData, type ConstantFieldKind, type ConstantFieldNode, type ConstantModelNode, type ConstantModelView, type ConstantModelViewKey, ConstantSerializer, type DepEdge, type DepEdgeKind, type DepNode, type DepNodeKind, type DepsData, DepsSerializer, type DepsSerializerContext, type DevtoolsApp, type DevtoolsEnvelope, type DevtoolsIndex, DevtoolsJson, DevtoolsRouter, type DevtoolsRouterContext, type DictionaryData, type DictionaryModuleNode, type EndpointNode, type EnumNode, type FieldType, type FilterArg, type InternalNode, type InternalType, type RelationEdge, type RouteRow, type SerializedArg, type SerializedReturns, type SignalData, type SignalNode, SignalSerializer, type SignalSerializerContext, type SliceNode, type Unserializable, } from "./devtools.d.ts";
8
+ export { type ArgType, type ConstantData, type ConstantFieldKind, type ConstantFieldNode, type ConstantModelNode, type ConstantModelView, type ConstantModelViewKey, ConstantSerializer, type DepEdge, type DepEdgeKind, type DepNode, type DepNodeKind, type DepsData, DepsSerializer, type DepsSerializerContext, type DevtoolsApp, type DevtoolsEnvelope, type DevtoolsIndex, DevtoolsJson, DevtoolsRouter, type DevtoolsRouterContext, type DictionaryData, type DictionaryModuleNode, type EndpointHttpRoute, type EndpointNode, type EnumNode, type FieldType, type FilterArg, type InternalNode, type InternalType, type RelationEdge, type RouteRow, type SerializedArg, type SerializedReturns, type SignalData, type SignalNode, SignalSerializer, type SignalSerializerContext, type SliceNode, type Unserializable, } from "./devtools.d.ts";
9
9
  export { StageFailedError } from "./di/stageFailedError.d.ts";
10
10
  export type { ChangeBatch, ChangeKind } from "./hmr/wsHub.d.ts";
11
11
  export { MachineAccount, type MachineProof, MachineToken, type MachineTokenIssueOptions, type MachineTokenVerdict, } from "./machine.d.ts";