akanjs 3.3.0-rc.25 → 3.3.0-rc.26
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 +222 -0
- package/base/utils.ts +2 -0
- package/client/dictionaryAsset.ts +103 -25
- package/client/dictionaryGroups.ts +113 -0
- package/client/dictionaryModule.ts +23 -0
- package/client/dictionaryPart.ts +113 -0
- package/client/index.ts +1 -0
- package/client/nativeBoot.ts +3 -0
- package/client/nativeErrorReport.ts +55 -0
- package/{server → client}/rscClientErrorSender.ts +13 -5
- package/client/translator.ts +7 -1
- package/client/translatorState.ts +18 -1
- package/constant/constantRegistry.ts +36 -33
- package/fetch/client/fetchClient.ts +20 -40
- package/fetch/client/modelRuntimes.ts +89 -0
- package/fetch/client/sliceInitHandle.ts +5 -3
- package/fetch/fetchType/appliedReturn.type.ts +4 -2
- package/index.ts +8 -0
- package/package.json +6 -1
- package/server/appWorker.ts +177 -0
- package/server/appWorkerError.ts +5 -0
- package/server/appWorkerPath.ts +22 -0
- package/server/artifact/builderRpc.ts +1 -0
- package/server/artifact/ipcTypes.ts +4 -0
- package/server/artifact/routeClientCache.ts +4 -0
- package/server/clientErrorReport.ts +67 -10
- package/server/hmr/clientScript.ts +4 -1
- package/server/hmr/devArtifactPruner.ts +7 -1
- package/server/hmr/wsHub.ts +1 -0
- package/server/index.ts +2 -0
- package/server/metrics/pubsubGauges.ts +7 -0
- package/server/routing/apiRouter.ts +2 -0
- package/server/routing/serverListener.ts +4 -0
- package/server/rscClient.tsx +14 -0
- package/server/rscClientErrors.ts +4 -2
- package/server/serverMetrics.ts +6 -1
- package/server/ssrInlineScripts.ts +1 -0
- package/server/types.tsx +10 -0
- package/server/vendor/akanjs-client.ts +1 -0
- package/server/webArtifact.ts +16 -5
- package/server/webDocumentRoute.ts +7 -3
- package/server/webRouteContext.ts +13 -2
- package/server/webRouter.ts +4 -0
- package/server/webRscRoute.ts +2 -2
- package/signal/browserError.ts +4 -0
- package/signal/index.ts +1 -1
- package/store/actionErrorMessage.ts +15 -1
- package/store/agent/AgentContext.ts +22 -7
- package/store/agent/AgentInline.ts +50 -0
- package/store/agent/StoreSurfaceSource.ts +26 -9
- package/store/agentic/formFields.ts +7 -2
- package/store/agentic/useFieldTool.ts +2 -1
- package/store/formUploadOf.ts +6 -3
- package/store/sliceLiveActions.ts +4 -3
- package/store/storeFacade.ts +50 -0
- package/store/storeInstance.ts +92 -72
- package/test/signalTestRuntime.ts +5 -1
- package/types/base/utils.d.ts +1 -0
- package/types/client/dictionaryAsset.d.ts +4 -1
- package/types/client/dictionaryGroups.d.ts +7 -0
- package/types/client/dictionaryModule.d.ts +10 -0
- package/types/client/dictionaryPart.d.ts +13 -0
- package/types/client/index.d.ts +1 -1
- package/types/client/nativeErrorReport.d.ts +10 -0
- package/types/client/rscClientErrorSender.d.ts +12 -0
- package/types/client/translator.d.ts +1 -0
- package/types/client/translatorState.d.ts +9 -1
- package/types/fetch/client/fetchClient.d.ts +3 -0
- package/types/fetch/client/modelRuntimes.d.ts +17 -0
- package/types/fetch/fetchType/appliedReturn.type.d.ts +4 -0
- package/types/index.d.ts +7 -0
- package/types/server/appWorker.d.ts +40 -0
- package/types/server/appWorkerError.d.ts +4 -0
- package/types/server/appWorkerPath.d.ts +9 -0
- package/types/server/artifact/ipcTypes.d.ts +4 -0
- package/types/server/artifact/routeClientCache.d.ts +1 -0
- package/types/server/hmr/wsHub.d.ts +1 -0
- package/types/server/index.d.ts +2 -0
- package/types/server/logging/rotatingLogWriter.d.ts +1 -1
- package/types/server/metrics/pubsubGauges.d.ts +1 -0
- package/types/server/routing/apiRouter.d.ts +1 -0
- package/types/server/routing/serverListener.d.ts +1 -0
- package/types/server/ssrInlineScripts.d.ts +1 -0
- package/types/server/types.d.ts +22 -0
- package/types/server/vendor/akanjs-client.d.ts +1 -0
- package/types/server/webRouteContext.d.ts +1 -1
- package/types/signal/browserError.d.ts +3 -0
- package/types/signal/index.d.ts +1 -1
- package/types/store/actionErrorMessage.d.ts +1 -0
- package/types/store/agent/AgentContext.d.ts +1 -0
- package/types/store/agent/AgentInline.d.ts +5 -0
- package/types/store/agent/StoreSurfaceSource.d.ts +1 -1
- package/types/store/storeFacade.d.ts +9 -0
- package/types/ui/Constant/schemaDoc.d.ts +1 -0
- package/types/ui/Data/Dashboard.d.ts +1 -0
- package/types/ui/Data/ListContainer.d.ts +1 -0
- package/types/ui/Data/QueryMaker.d.ts +1 -0
- package/types/ui/Data/RefPicker.d.ts +1 -0
- package/types/ui/Dialog/LazyLegacyModal.d.ts +1 -0
- package/types/ui/DismissDragGesture.d.ts +9 -0
- package/types/ui/Field/Text.d.ts +2 -2
- package/types/ui/Field/lightRefCache.d.ts +2 -1
- package/types/ui/Field/useRelationWindow.d.ts +2 -1
- package/types/ui/Load/sliceClaim.d.ts +4 -3
- package/types/ui/Model/resetModels.d.ts +1 -0
- package/types/ui/Signal/Arg.d.ts +1 -0
- package/types/ui/Signal/Doc.d.ts +1 -0
- package/types/ui/Signal/Endpoint.d.ts +1 -0
- package/types/ui/Signal/RestApi.d.ts +1 -0
- package/types/ui/Signal/WebSocket.d.ts +1 -0
- package/types/ui/Signal/endpointEntries.d.ts +1 -0
- package/types/ui/Signal/makeExample.d.ts +1 -0
- package/types/ui/Signal/useApiDescriptions.d.ts +1 -0
- package/types/ui/modelRuntime.d.ts +1 -0
- package/types/ui/useDismissDrag.d.ts +10 -3
- package/ui/Agent/fetchRunner.ts +5 -1
- package/ui/BottomSheet.tsx +3 -7
- package/ui/Constant/schemaDoc.ts +1 -0
- package/ui/Data/Dashboard.tsx +1 -0
- package/ui/Data/ListContainer.tsx +1 -0
- package/ui/Data/QueryMaker.tsx +1 -0
- package/ui/Data/RefPicker.tsx +1 -0
- package/ui/Dialog/LazyLegacyModal.tsx +5 -0
- package/ui/Dialog/LegacyModal.tsx +3 -4
- package/ui/Dialog/Modal.tsx +3 -2
- package/ui/Dialog/index.tsx +2 -2
- package/ui/DismissDragGesture.tsx +19 -0
- package/ui/Field/Text.tsx +5 -2
- package/ui/Field/index.tsx +2 -3
- package/ui/Field/lightRefCache.ts +9 -8
- package/ui/Field/useRelationOptions.ts +2 -2
- package/ui/Field/useRelationWindow.ts +9 -4
- package/ui/Input.tsx +1 -1
- package/ui/Load/Units.tsx +1 -1
- package/ui/Load/sliceClaim.ts +11 -5
- package/ui/Model/EditModal.tsx +3 -4
- package/ui/Model/EditWrapper.tsx +2 -3
- package/ui/Model/NewWrapper_Client.tsx +2 -3
- package/ui/Model/ViewEditModal.tsx +4 -5
- package/ui/Model/ViewModal.tsx +2 -3
- package/ui/Model/ViewWrapper.tsx +2 -3
- package/ui/Model/resetModels.ts +11 -0
- package/ui/Signal/Arg.tsx +4 -1
- package/ui/Signal/Doc.tsx +1 -0
- package/ui/Signal/Endpoint.tsx +4 -1
- package/ui/Signal/RestApi.tsx +1 -0
- package/ui/Signal/WebSocket.tsx +1 -0
- package/ui/Signal/endpointEntries.ts +1 -0
- package/ui/Signal/makeExample.ts +1 -0
- package/ui/Signal/useApiDescriptions.ts +10 -0
- package/ui/System/CSR.tsx +4 -1
- package/ui/System/Client.tsx +1 -2
- package/ui/System/Messages.tsx +28 -43
- package/ui/modelRuntime.ts +2 -0
- package/ui/useDismissDrag.ts +135 -5
- package/ARCHITECTURE.md +0 -200
- package/types/server/rscClientErrorSender.d.ts +0 -8
- /package/{server → client}/reportText.ts +0 -0
- /package/types/{server → client}/reportText.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -82,6 +82,123 @@
|
|
|
82
82
|
|
|
83
83
|
A chat where the user mentions a record now asks before the first change that follows. `AgentConfirm.set({ afterScreenRead: false })` turns that off together with the ask after `readScreen`.
|
|
84
84
|
|
|
85
|
+
- e5d3cac: An `Agent.Zone`'s label and a value published with `st.expose`, `st.useState` or `useAgentResource` reach the model the way route params and store keys do: ids, enum members, numbers and booleans in the turn's context, free text through a read tool.
|
|
86
|
+
|
|
87
|
+
- **A published value rides in the `screen` block only when it is the app's own kind of data.** A string rides when it is one token (the rule route params follow) or an ISO timestamp, beside numbers, booleans and `null`. A list rides when every item does and it spells at most twelve words; a list with free text in it is left out whole. An object keeps its fields of that kind, at most twelve of them and twelve words of values, under names that are tokens. A resource with anything left out is marked `withheld: true`, and one whose read threw is listed with no error text.
|
|
88
|
+
- **`readState(name)` answers a published value.** The name is the one the `screen` block lists, a zone's prefix included. The answer is the whole value, as page content, so the first change after it asks the user first. A store key the screen reads is answered before a published value of the same name.
|
|
89
|
+
- **A zone's `label` rides only when it is one token.** `readScreen` with `section` set to the zone's path, or with no `section` inside the zone's own chat, starts with a `Zone label:` line when the label was left out.
|
|
90
|
+
- `StoreSurfaceSource` takes the surface it is attached to as its second argument, `AgenticSurface.shared` by default.
|
|
91
|
+
- The agent guideline and the `akan-agent` skill describe the rule.
|
|
92
|
+
|
|
93
|
+
**Upgrading.** A model that read a sentence from `st.expose`, `st.useState`, `useAgentResource` or a zone's `label` in the turn's context now finds the resource marked `withheld` and reads it with `readState`, which makes the next change ask for approval. Where an agent should act on a value without that ask, publish an id, a count or an enum member. A host that builds its own `StoreSurfaceSource` on a surface other than `AgenticSurface.shared` passes that surface to it.
|
|
94
|
+
|
|
95
|
+
- af57986: An app declares code that runs in a process of its own, and the framework builds, finds and supervises it.
|
|
96
|
+
|
|
97
|
+
`workers` in an app's `akan.config.ts` maps a name to an entry file (`workers: { vision: "srvkit/vision.worker.ts" }`). `akan build` bundles each as its own entry to `workers/<name>.js`, with the server's externals and env handling and never as a chunk of `server.js`, so a native addon the worker imports is not loaded by the server. The image and a desktop app's server carry the folder; `akan start` and `akan test` run the worker from its declared source.
|
|
98
|
+
|
|
99
|
+
`AppWorker.spawn(name, options)` from `akanjs/server` starts it with the Bun that runs the server: stdout and stderr are relayed line by line to the server's logger, a worker that exits with an error or on a signal is started again with a doubling delay (1s to 30s; `restart: false` leaves it down, an exit with code 0 stays down), `onMessage` opens an IPC channel that `worker.send` writes to, `stop()` sends SIGTERM and then SIGKILL, and every running worker gets SIGTERM when the server process exits. The worker gets the variables a process needs to start plus `options.env`, not the server's env, unless `inheritEnv` is set. `AppWorker.pathOf(name)` returns the file for code that spawns by hand. An undeclared name throws `AppWorkerError` with the code `workerNotDeclared`, and `send` without a channel `workerNotConnected`.
|
|
100
|
+
|
|
101
|
+
The runtime guideline documents the section, and its reference files are larger: `runtimeRule-2.md` by 3430 bytes and `akanApi-app-config.md` by 138.
|
|
102
|
+
|
|
103
|
+
No upgrade step for an app. `AppConfigResult` gains a required `workers`, so code that builds one by hand adds `workers: {}`; `akanjs/server/appWorkerPath` is a new entry point the build tooling reads.
|
|
104
|
+
|
|
105
|
+
- e3f405f: A page whose server component hands a model to a framework component (`Load.Units`, `Load.View`, `Model.New`, `Model.Edit`, `Data.CardList` and the others) now loads that model's store and descriptors, not every module of the app. Before, those components loaded the whole client runtime wherever they rendered.
|
|
106
|
+
|
|
107
|
+
- `akan sync` writes `lib/__client/<model>.ref.ts` for each model with a signal and `lib/__client/refs.ts` for the app. The generated root layout imports `refs.ts`, and the server then adds the model's client reference to every slice, init, view and edit it hands to a client component, as the optional `_runtime` field of `SliceMeta`, `ServerInit`, `ServerView` and `ServerEdit`. The browser loads the reference, and with it the model's store and descriptors, before the component receiving the object renders: on the first page, inside a streamed part of it, and after a client navigation. A model the app extends loads through the app's store, which loads the lib's first. A reference loads what a client file reading `st.use.<model>` loads: the stores the model's store names come with it, and where that store picks a name at run time, the whole client runtime. On a page that already holds the whole runtime the model's store stays the one store, with its state and subscribers.
|
|
108
|
+
- `FetchClient.setModelRuntimes(references)` is the one new static. Only the generated `refs.ts` needs it.
|
|
109
|
+
- The framework components that reach a model only through such an object no longer load the whole runtime. `Data.ListContainer`, `Data.QueryMaker`, `Data.RefPicker`, the `Signal` API explorer and `Constant.Doc` still do: they follow a model named by a field or a filter argument, which no object brought. They are loaded on demand, so a page pays for them only where one renders.
|
|
110
|
+
- A relation field (`Field.Relation` and the others taking a `slice`) loads the related model through the slice it is given, not the whole runtime.
|
|
111
|
+
- A `resets` name on `Model.New`, `Model.Edit` or `Model.View` whose store the page has not loaded is passed over, since there is no state to reset.
|
|
112
|
+
- The route table of `akan build` counts, for each route, the reference files of the models its server modules hand over. Where a server module picks a `fetch` name at run time, or takes `fetch` from the `server` barrel, the route counts every model's runtime and the build names the file and the line once.
|
|
113
|
+
- A handoff object that carries no reference works as before, wherever the page already holds the model's runtime.
|
|
114
|
+
|
|
115
|
+
**Upgrading.**
|
|
116
|
+
|
|
117
|
+
Until `lib/__client/refs.ts` exists (an `akan build` or `akan sync <app>` writes it) the app builds and serves with the whole client runtime and says so once, naming the sync. A spread (`{ ...init }`) or an `Object.assign` of what `fetch` returned keeps the reference; a deep copy (`JSON.parse(JSON.stringify(init))`, `structuredClone(init)`, a cache that stores the object as JSON) leaves `_runtime` an empty object. What that means for a page that builds or copies such an object by hand is in the upgrade note of the entry that makes every app load per route.
|
|
118
|
+
|
|
119
|
+
- edf14fd: A page registers the constants of the models its client code names, not every model's. A page that keeps the whole runtime still loads `lib/cnst.ts`; the one change there is that a registered model no longer carries its type-only `_`-prefixed members as `null` values.
|
|
120
|
+
|
|
121
|
+
- `akan sync` writes one registration piece per model and scalar, `lib/__client/<model>.cnst.ts`, which imports that module's constant file and the pieces of the models the file names, then registers the model. `lib/cnst.ts` keeps its shape and exports. A model's `.fetch` and `.st` pieces load its registration piece first, and so does a handoff reference (`<model>.ref.ts`), which loads one of them. A `.fetch` piece names the pieces it needs first in its own `FetchClient.build` call, so loading them first adds no statement to a page. A registration piece that no page loading only pieces reaches (only pages that also load the whole runtime, or only a handoff) takes its model from `lib/cnst.ts` instead, so those pages keep every constant in the one chunk they already share.
|
|
122
|
+
- The build rewrites `cnst.Memo`, `cnst.memo`, `cnst.MemoStatus`, a lib's `cnst.util.File` and `const { MemoStatus } = cnst` to imports of those names from the file declaring each; a type-only use loads nothing. A file keeps the whole `lib/cnst.ts` when it passes `cnst` on (as an argument, a spread, `Object.keys(cnst)` or another variable), picks a member with a computed key, names something `cnst` does not hand out, or hides names behind a rest or nested destructuring, and so does a constant file that reads its own app's or lib's `cnst`.
|
|
123
|
+
- A framework component that walks every registered model (the API explorer, the schema page, relation pickers, query makers) loads the whole runtime, `lib/cnst.ts` included, so it sees every model on any page. So does `Data.Dashboard`, whose tiles read their filters from a model a prop names: the server registers every model, so with fewer in the browser the tiles would render differently after hydration.
|
|
124
|
+
- Registering the same model or scalar again, from its piece and from `lib/cnst.ts` in one tab, returns the first registration; another class claiming a taken name still fails. A repeat is the same name with the same classes from the same constant file: a file that registers several names registers each, and a name that comes again with other classes registers those.
|
|
125
|
+
- In development, saving a `*.constant.ts` file reloads the tab, which registers the model before its fetch and store pieces run, as a built page does. The names a saved scalar file (`lib/__scalar/<name>/<name>.constant.ts`) declares are read again, as a model's are.
|
|
126
|
+
- The agent's form tools find the setters of a model a page registers after their first lookup.
|
|
127
|
+
- `akan quality runtime` notes each client or constant file that keeps every constant (`akan.runtime.whole-constants`), with its reason, and counts them per app and lib.
|
|
128
|
+
- The build's own check also fails when a registration piece is imported back by a file it loads, or when a page built to load pieces reaches `lib/cnst.ts` other than through a file `akan quality runtime` names or a registration piece answering from it. A page that such a file or piece already makes load every constant may reach them by another path too: a handoff reference no route hands over takes its models from `lib/cnst.ts`, and their constant files stay as written.
|
|
129
|
+
|
|
130
|
+
In the sample apps the memo pages of `apps/minimal` went from 263.5 KB to 262.3 KB and from 236.1 KB to 234.8 KB (brotli); every other route stays within 0.2 KB of before.
|
|
131
|
+
|
|
132
|
+
**Upgrading.**
|
|
133
|
+
|
|
134
|
+
Until the pieces exist (an `akan build` or `akan sync <app>` writes them) the build keeps the whole `lib/cnst.ts`. `akan quality runtime` lists the files that keep every constant and why; rewriting one to `cnst.<Name>` or `const { … } = cnst` lets its pages load fewer constants. What changes for code that looks a model up by name is in the upgrade note of the entry that makes every app load per route.
|
|
135
|
+
|
|
136
|
+
- b5b4834: A production page now loads the endpoint descriptors and stores of only the modules its client code names. Before, a client module importing `fetch` or `st` from a `client` barrel brought every module of that app or lib.
|
|
137
|
+
|
|
138
|
+
- `akan build` reads each client file of the app and its libs. Where every `st.use.<key>()`, `st.do.<action>()`, `st.slice.<name>`, `fetch.<endpoint>()` and `sig.<module>` names something it can tell at build time, the file takes `fetch` and `sig` from `lib/usePage.ts`, `st` from `akanjs/store` (the tab's one store, the object a scope's `lib/st.ts` exports), and imports the `lib/__client/` pieces of the modules those names belong to, each by a name it hands to `loadedAfter` from `akanjs/base`, so the piece's chunk loads first however the build splits the code. A `*.store.ts` file gets its own module's descriptors and those of the modules its model depends on, and no store piece: a file naming a store loads the stores that store's file names.
|
|
139
|
+
- A file that picks a name at run time (`st.do[name]()`), or names something no generated piece answers, imports the app's whole runtime instead, as do the framework components that reach a model by a computed name (`Load`, `Model`, `Data` and the others importing `akanjs/ui/modelRuntime`). In development the whole runtime is assembled from the same pieces (`lib/__client/_useClient.ts`, `lib/__client/_st.ts`); in a build a client entry that needs every module keeps `lib/useClient.ts` and `lib/st.ts` as before, and the files only such entries reach are left as written. A `*.store.ts` file that picks a name at run time (spreading into the object given to its own `this.set` is not one) makes every file naming its store load the whole runtime.
|
|
140
|
+
- A lib file naming a lib module loads the app's piece of it, so a store the app extends arrives with the app's additions. The lib's own store file of that model is the exception: the app's piece is what loads it.
|
|
141
|
+
- A store piece whose model holds a file loads the upload module's descriptors first, so the piece alone has its upload action (`st.do.upload<Field>On<Model>`).
|
|
142
|
+
- An app store that extends a lib store and has no signal of its own loads the upload module's descriptors first too.
|
|
143
|
+
- An import that also takes a `client` barrel's default export (`import Kit, { st } from "@apps/<app>/client"`) is left as written and loads the whole runtime.
|
|
144
|
+
- An app store that extends a lib store answers what it answered before, whichever pieces a page loads and in whatever order: a default both declare is the lib's, an action or a `set<Key>` both declare is the app's. The store runtime itself is unchanged.
|
|
145
|
+
- The development server loads what a production page loads: a client module takes the pieces of the modules it names there too, so a name a route misses shows while you work, and the error for a store key the page has not loaded names the module whose store declares it.
|
|
146
|
+
- An app not yet synced to `lib/__client/_useClient.ts` and `_st.ts`, or whose module names cannot be read from source, builds with the whole runtime on every page, and the build says which of the two happened and names the sync to run. `akan sync` warns when it cannot read a scope's modules, and `akan build --write false` warns that it uses the `lib/__client/` files as they were last written.
|
|
147
|
+
|
|
148
|
+
**Upgrading.**
|
|
149
|
+
|
|
150
|
+
The `lib/__client/` files an earlier release wrote are written again by the sync `akan build` runs. A client module importing `fetch` or `st` no longer brings its whole app or lib; what to check for is in the upgrade note of the entry that makes every app load per route.
|
|
151
|
+
|
|
152
|
+
- 4ff5d5e: Every app loads its client runtime per route: a server-rendered page loads the stores, endpoint descriptors, constants and dictionary texts of the modules that page uses, not every module's. There is no setting for it, in `akan.config.ts` or anywhere else.
|
|
153
|
+
|
|
154
|
+
- A build or development server that cannot use the per-module files (never synced, written by an earlier release, a mounted lib not synced, a module that cannot be read) loads the whole runtime on every page, as before, and says so with the `akan sync` to run. `akan build --write false`, which skips the sync, says its files may be stale.
|
|
155
|
+
- A build that finds its own output would load a module before the piece it needs warns once, naming the files, builds every page on the whole runtime instead and succeeds. That warning is a bug in akan: report it with its text.
|
|
156
|
+
- `akan quality runtime` lists, after an `akan build`, the routes that load every text of the page dictionary under the file and line that cost it (`[dictionary] <file>:<line> <why>`); `--format json` carries every route. For an app with a build report it no longer prints the `akan.runtime.framework-marker` note, which counted every page importing a framework component that reads models by name; the build's `[reader]` line names the routes that component really holds. The `akan quality` reference page lists every rule the report prints and what to change in app code for each.
|
|
157
|
+
- A model's reference, which `fetch.slice`, `fetch.init<Model>`, `fetch.view<Model>` and `fetch.edit<Model>` hand to client components, loads that model's own store. Before, another module's store with a state field named like the model loaded with it.
|
|
158
|
+
|
|
159
|
+
**Upgrading.**
|
|
160
|
+
|
|
161
|
+
This is the one upgrade note for the per-route client runtime; the other entries of this release say what was built.
|
|
162
|
+
|
|
163
|
+
_With no action._ The first `akan build` or `akan start` after upgrading syncs the app and the libs it mounts, writing `lib/usePage.ts` and `lib/__client/` beside the other generated files, and its pages load per module. Add `apps/*/lib/usePage.ts`, `libs/*/lib/usePage.ts`, `apps/**/lib/__client` and `libs/**/lib/__client` to `.gitignore` beside `lib/useClient.ts` and `lib/__lib`. A build run with `--write false` and a lib no built app mounts need `akan sync <app-or-lib>` once; until then the pages load the whole runtime and the build says so. Server rendering, CSR bundles and native apps load everything, as before, and the development server loads what a production page loads. An app with routes to measure bundles its browser code at least twice, where it bundled once; `akan build --verbose` shows each bundle and its time.
|
|
164
|
+
|
|
165
|
+
_What can break, and how it shows._ A page no longer loads a module that no client file of its route names.
|
|
166
|
+
|
|
167
|
+
- A store or endpoint reached by a computed name without the app's or a lib's `client` barrel (the framework's base `st` or `fetch` with a string, a component library built on `akanjs/store`'s `st`, a file outside `apps/` and `libs/`) is found only on a route where a client file names that module. Outside React, `st.get().<key>` of such a store is `undefined`: a store's initial state and persisted keys appear when its code loads.
|
|
168
|
+
- An app store that extends a lib's store adds its actions, state and slices only on a route that loads the app's runtime, so code using them imports `st` from the app's `client` barrel, not the lib's.
|
|
169
|
+
- Top-level code runs only on the pages that name its file. A side effect other pages relied on because a store or a part file (`Memo.Zone.tsx`) imported it must be named by the pages that need it, or moved to where it is used. A member replaced at run time (`Obj.part = other`) is not seen by files that named the original member; read the object whole (pass it on) in the file that depends on the replacement.
|
|
170
|
+
- A slice, init, view or edit object written by hand (`{ refName, sliceName, … }`) or deep-copied (`JSON.parse(JSON.stringify(init))`, `structuredClone(init)`, a cache that stores it as JSON) carries no reference to its model, and neither does a slice parameter that is reassigned or has a default value. On a route where no client file names the model, the framework list, view or form finds no store: in development the error names the store's module and this cause, and in production the page shows nothing where the slice is read. `akan quality runtime` does not report this. Take the object from `fetch`, hand it over uncopied or spread (`{ ...init }`), or name the model in a client file of the route (`st.use.<key>()`).
|
|
171
|
+
- A model looked up by name (`ConstantRegistry.getDatabase("memo")`) is found only on a page that names it: name it in that file (`cnst.Memo`) or read `cnst` whole there. On every page, a registered model's `_`-prefixed member read as a value is `undefined`, where it was `null`; those members are types.
|
|
172
|
+
- A `"use client"` component that builds an endpoint's description key from data (`` l(`${module}.signal.${endpoint}.desc`) ``) gets the text on the server and the raw key in the browser: React reports a hydration mismatch and the key shows. Write the key out, or read the text in a server component and pass it down. A text shown once outside React, such as a toast that calls `Translator.translateByLocale`, can wait on `Translator.ready(lang, key)` so a late module's text is not shown as its key.
|
|
173
|
+
|
|
174
|
+
_How to check._ Run `akan build <app>`, then `akan quality runtime`: it names each file that keeps a page on the whole runtime or the whole dictionary, the line, the reason and the routes. `akan preview <app>` opens the pages and reports what they throw.
|
|
175
|
+
|
|
176
|
+
_How to keep a page on the whole runtime._ In app code: a route keeps the whole runtime when it renders a client file that exports the store, since any file may then read any module through it.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
// apps/<app>/ui/WholeRuntime.tsx
|
|
180
|
+
"use client";
|
|
181
|
+
import { st } from "@apps/<app>/client";
|
|
182
|
+
|
|
183
|
+
export const wholeRuntime = st;
|
|
184
|
+
|
|
185
|
+
export const WholeRuntime = () => null;
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Render `<WholeRuntime />` in one page to keep that route, or in the root layout (`page/_layout.tsx`) to keep every route. `akan quality runtime` then lists the file under `[reader]` with the routes it holds. A route kept this way loads more than before, so `akan build --check-budget` may name it; `akan build <app> --raise-budget` raises its entry. Use it to ship while the files `akan quality runtime` names are changed, or for a route that reaches a store, an endpoint or a model by a name the build cannot read.
|
|
189
|
+
|
|
190
|
+
- a708a40: A server-rendered page starts from a small page runtime, the first step toward loading a model's endpoint descriptors and store in the browser only on the routes that use them.
|
|
191
|
+
|
|
192
|
+
- Each client entry of a server-rendered page starts from `lib/usePage.ts` (`usePage`, `msg`, `Err` and a fetch client carrying only the framework's own descriptors, such as `ping`, from `lib/__client/_base.fetch.ts`) instead of `lib/useClient.ts` and `lib/st.ts`. A client module that imports `fetch` or `st` from an app or lib `client` barrel still brings that scope's descriptors and stores, and a lib's barrel brings that lib and the libs under it.
|
|
193
|
+
- The framework components that reach a store, an endpoint or a registered constant by a name they compute (`Load`, `Model`, `Data`, `Signal`, `Constant.Doc` and the relation fields) import an empty module, `akanjs/ui/modelRuntime`. A route build keeps the app's `lib/useClient.ts` and `lib/st.ts` in every client entry reaching it, so a page rendering one of them loads the app's whole runtime before the component runs. A test in `akanjs` fails when a `ui` file reaches a model that way without importing it.
|
|
194
|
+
- Server rendering, CSR bundles (MCP App views included) and native apps keep loading the whole runtime. The development server narrows imports from `akanjs/ui` as a production build does, so a missing import shows there too.
|
|
195
|
+
- An app whose generated files predate `lib/usePage.ts` or `lib/__client/_base.fetch.ts` builds with the whole runtime on every page until it is synced.
|
|
196
|
+
- `StoreBootstrap.importLines` and `StoreBootstrap.source` in `@akanjs/devkit` take an optional scope, `"whole"` (the default) or `"page"`.
|
|
197
|
+
|
|
198
|
+
**Upgrading.**
|
|
199
|
+
|
|
200
|
+
What a page stops loading, and what to check for, is in the upgrade note of the entry that makes every app load per route.
|
|
201
|
+
|
|
85
202
|
- 19c6fa7: `akan code` on the `local` profile can be told to stop asking about a command for the rest of the session, and one option turns asking off for a run.
|
|
86
203
|
|
|
87
204
|
- **A third answer.** The prompt before a shell command is now `approve? run: <command> [y/n/a]`. `a` runs the command and stops asking about it until the session ends. What is remembered is the program, and the sub-command too for `git`, `bun`, `bunx`, `npm`, `npx`, `pnpm`, `yarn`, `akan`, `docker`, `kubectl`, `helm`, `cargo` and `go`: allowing `git status` leaves `git diff` asked about, and allowing `bun test` leaves `bun x` asked about. `gh` is remembered two words deep, so allowing `gh pr view` leaves `gh pr merge` asked about. A line of several commands (`&&`, `;`, `|`, `$(…)`, a subshell) runs unasked only once every command in it is allowed. `/allowed` lists what the session has allowed and `/allowed clear` forgets it. Nothing is written to disk, so a resumed, forked or reloaded session asks again.
|
|
@@ -194,6 +311,14 @@
|
|
|
194
311
|
|
|
195
312
|
The api report lists additions only: `Device.keyboardAnimationMs`, `Device.keyboardHeight` and `Device.subscribeKeyboard`, the optional `KeyboardFrameState.avoidsContent` and `isPageKeyboardAvoidance` from `akanjs/webkit`; no upgrade step is needed. An iOS app gets the new behavior once it is built with this shell; a page that lifted its own composer by the keyboard's height under the old pan should drop that lift.
|
|
196
313
|
|
|
314
|
+
- b6f1838: An operator can graph and alert on the number of live rooms: `/_akan/app/metrics` now carries the `akan_live_rooms` gauge next to `akan_room_replay_bytes` and `akan_pubsub_buffered_messages`, and the metrics report carries it as `roomCount`.
|
|
315
|
+
|
|
316
|
+
It counts the live-query rooms one process holds, one per room id however many sockets share it. Behind a gateway each replica reports its own and the scrape adds them up per `role`, so a room that sockets on two replicas share counts once on each; the gateway's `rooms` field in the status still gives the distinct count.
|
|
317
|
+
|
|
318
|
+
- 234e31d: A native app's page now sends its errors to `/_akan/client-report` when `option.setClientReport` is on. The page is bundled into the app and loaded from `app://localhost` or `https://app.localhost`, another origin than the server, so no page view gave it a signed id and the browser listeners never ran there. At its first `window.onerror` or unhandled rejection (React's uncaught and recoverable errors and a failed native plugin call among them) it asks `GET /_akan/client-report` on the app's server for an id, which the server gives only to a shell origin, counted against `perAddress` and drawn against `sampleRate` like a page view, and asks again after 30 minutes, or after a minute when the ask did not reach the server. The route answers a shell origin with `Access-Control-Allow-Origin`, so the page's report is an ordinary cross-origin `POST` that carries its `Origin` in every webview. Its reports go through the same checks and caps as a browser page's, reach `setErrorReporter` as a `BrowserError` whose new `data.shell` (`BrowserErrorShell`, added to `akanjs/signal`) names the shell and whose `traceId` is the ask's request id, and are logged as `Native <shell> page error`. A web page loads nothing more, and a page with no error sends nothing.
|
|
319
|
+
|
|
320
|
+
Upgrade: a reporter that reads `BrowserError.data` needs no change; `shell` is `null` for every browser page. Code that builds a `BrowserErrorData` itself, such as a test fake, adds `shell: null`.
|
|
321
|
+
|
|
197
322
|
- 31097f2: A server can send its spans and log lines to an OpenTelemetry collector over OTLP/HTTP, with no package to add. Nothing is exported until an endpoint is set.
|
|
198
323
|
|
|
199
324
|
- **The settings are OpenTelemetry's.** `OTEL_EXPORTER_OTLP_ENDPOINT` is a base that `/v1/traces` is appended to, and `/v1/logs` once logs are asked for; `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` and `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` are full URLs. `OTEL_EXPORTER_OTLP_HEADERS` (and its `_TRACES_` / `_LOGS_` forms) holds credentials, which are never logged. `OTEL_SERVICE_NAME` and `OTEL_RESOURCE_ATTRIBUTES` name the service. `OTEL_TRACES_SAMPLER` takes `always_on`, `always_off`, `traceidratio` and their `parentbased_` forms, with `OTEL_TRACES_SAMPLER_ARG` as the ratio; the default is `parentbased_always_on`, and any other value is logged once and exports no spans. `OTEL_TRACES_EXPORTER=none` or `OTEL_LOGS_EXPORTER=none` turns one signal off, `OTEL_EXPORTER_OTLP_TIMEOUT` and the `OTEL_BSP_*` / `OTEL_BLRP_*` batch settings work as in the spec, and `OTEL_SDK_DISABLED=true` turns it all off. With no endpoint set, nothing is created.
|
|
@@ -282,6 +407,47 @@
|
|
|
282
407
|
- A guard's `request.path` no longer carries tracking parameters or the order they came in, so a redirect such as `/login?next=${request.path}` drops `utm_*` on the way: declare each parameter it must pass on with `.search()`, which keys the route on its query as requested, or set `.config({ canonicalQuery: false })` on the route.
|
|
283
408
|
- On the client, `usePathCtx().location` and the router state keep the sorted query without tracking parameters until the first navigation, and `usePageLocation()` until the URL's query moves: declare the parameter with `.search()` or set `canonicalQuery: false` on the route, or read `window.location` in an effect, after hydration.
|
|
284
409
|
|
|
410
|
+
- bfa67d8: The descriptions of API endpoints leave the dictionary file every page loads, and load only on a page that shows them.
|
|
411
|
+
|
|
412
|
+
- `akan build` and the development server write two files per language under `/_akan/dict`: the page dictionary, without the `.desc` and `.arg` texts of each `signal` entry, and an API file holding exactly those. The page file names the API file in an exported `parts` map. The endpoint labels stay in the page file.
|
|
413
|
+
- Each `Signal` component of `akanjs/ui` that shows an endpoint's description or argument texts, `Signal.Arg.Table` rendered on its own included, loads the API file before it shows them: a server-rendered page preloads it and carries its texts in the HTML, and a client navigation into such a page waits for it. A page showing no description never requests it. A file that fails to load is retried once; after a second failure the page shows without descriptions and logs the error, and the next navigation tries again.
|
|
414
|
+
- The server, MCP, the API and schema reference routes and a CSR build keep the whole dictionary.
|
|
415
|
+
- `TranslatorState` merges the files of a language into its dictionary, each file once. A language switch keeps each language's merged files to that language, and a file arriving after its language moved to another build is dropped. A page dictionary asked for before another of the same language but answering after it no longer replaces the newer one.
|
|
416
|
+
- `akan build` prints one line per language with the brotli size of each file: `Dictionary en: 4.9KB brotli on every page, API descriptions 836B where shown`.
|
|
417
|
+
- `DictionaryAssetBuilder.build` in `@akanjs/devkit` takes an option `{ splitApi }`.
|
|
418
|
+
|
|
419
|
+
**Upgrading.**
|
|
420
|
+
|
|
421
|
+
A `"use client"` component of your own that writes an endpoint's description or argument key out (`l("<module>.signal.<endpoint>.desc")`) brings the API file to its route. What happens to one that builds the key from data is in the upgrade note of the entry that makes every app load per route.
|
|
422
|
+
|
|
423
|
+
- 6f8f6aa: A page loads the dictionary texts it can show rather than every module's.
|
|
424
|
+
|
|
425
|
+
- **What a route can show.** `akan build` and the development server read the keys each route's client modules name: a written key, a template whose module name is written, and a key picked from literal values or property names of an object in the same file, from a typed union, or from a template type with a written module name. To those they add the models, scalars and enums whose labels and options the framework's lists, views, forms and remove dialogs build at run time, reached through the module pieces the route loads, and `base`. A route that hands the translator on or keeps it in a variable, or has a key the build cannot follow, such as one read from data, loads the whole page dictionary, and `akan build` warns with its file, line and reason. A route that renders a `Signal` or `Constant` component loads the whole page dictionary too, and so does a route that keeps the whole client runtime, whose files `akan quality runtime` names. Server components need nothing: their texts arrive rendered.
|
|
426
|
+
- **Files.** Each language's dictionary is packed into files by module, sized on the default language, so that a route loads at most four of them besides the API description file. Each file is written to `/_akan/dict` with the table naming the file of every module. A route whose client components name an endpoint's description or argument key loads the API description file with them.
|
|
427
|
+
- **Loading.** A server-rendered page preloads its route's files and merges them before hydration; a client navigation merges the next route's files before the new page commits; a language switch loads that language's files. Each file is requested once per language, and a file that fails is tried again.
|
|
428
|
+
- **Safety net.** A key of a module the route's files leave out loads that module's file, and the page renders again once it merges, so the key shows only until then. A toast from `msg`, an action error or an agent message waits for its text rather than showing the key. Development logs the first such key of each module once; production never throws.
|
|
429
|
+
- **Development.** `akan start` writes one file per module and loads what each route's build counted, so saving a `*.dictionary.ts` file updates the page as in production. The save restarts the backend, and a page open meanwhile now takes the new texts without a reload: `RenderState.dictionaryStamp` names the dictionary files the backend serves, and the development socket's greeting carries it. A route's modules are read when it builds, so a key added to a client file and saved shows as the key, with that log, until the route builds again.
|
|
430
|
+
- **Unchanged.** The server, MCP and the single-file CSR build that native apps load keep the whole dictionary inline.
|
|
431
|
+
- **Size.** In the framework's sample apps, the English dictionary a first visit downloads drops from 4.9 KB (brotli) to 2.5 KB on the median route of `minimal`, and from 5.0 KB to 4.0 KB on `akan`, in one request on the median route and at most two. The loader adds about 1.4 KB to every route's JavaScript.
|
|
432
|
+
- `akan build` prints one line per language: `Dictionary en: first visit 2.5KB / 2.5KB / 3.0KB brotli on the lightest / median / largest route (whole 5.0KB), API descriptions 846B where shown`.
|
|
433
|
+
- `Translator.ready(lang, key)` answers `null` when the key's module is loaded, or a promise settling once it is. `DictionaryAssetBuilder.buildAll` in `@akanjs/devkit` takes `{ routes, everyGroupAlone }` beside `{ splitApi }`.
|
|
434
|
+
|
|
435
|
+
**Upgrading.**
|
|
436
|
+
|
|
437
|
+
A client component whose key the build cannot follow makes its route load the whole dictionary, and `akan build` names it: writing the key out, or picking it from an object or union in the same file, lets the route load only its own files. A text shown outside React is covered in the upgrade note of the entry that makes every app load per route.
|
|
438
|
+
|
|
439
|
+
- ee302c4: A page loads less of the framework's own UI code: the icons its files name rather than whole `react-icons` sets, no agent library unless it has an agent, no spring library for a dialog, and the gesture library only when a sheet is first pressed. This applies to every app; what a page shows and how it behaves do not change.
|
|
440
|
+
|
|
441
|
+
- **Icons.** A production browser build rewrites each named import from a `react-icons/<set>` package to a module written to the app's `.akan/generated/react-icons`, and each icon lives in exactly one such module: the naming file's own when one file names it, the app's shared module for that set when only the app's files name it, or the set's module shared with the workspace's libs and the framework when one of them names it too. A page loads each icon it uses once, and can carry the other icons of a shared module it touches, never more of a set than the whole set held. A name the set does not define as a plain icon, a namespace or default import, and a re-export keep the set. The server bundle keeps the set, and both draw the same markup. The development server already loaded icons per file.
|
|
442
|
+
- **Agent.** A server-rendered page no longer loads `use-agentic` for its page gate, so a page without an agent ships only the part of it that `akanjs/store` uses. `Agent.Chat`, `useAgent` and `SessionContext` work as before.
|
|
443
|
+
- **Dialog.** `Dialog.LegacyModal` loads the first time it renders, behind its own Suspense boundary, so `<Dialog>`, `Dialog.Modal` and `Modal` no longer load it or `@react-spring/web`. `Dialog.LegacyModal` remains a member of `Dialog`.
|
|
444
|
+
- **Drag to dismiss.** `BottomSheet`, `Dialog.Modal` and `Dialog.LegacyModal` load `@use-gesture/react` on the first press of their drag handle; the events that arrive while it loads are replayed into it, so the first drag, its flick speed and a tap land as a later one does.
|
|
445
|
+
- **Field.** `Field.Text` and `Field.TextArea` are memoized in their own file, so `Field`'s file only gathers its members: a page that names `Field.Text` loads that kind's file and not every kind, and a server component that names only members can render it. In a CSR bundle `Field` stays one client module, as before.
|
|
446
|
+
|
|
447
|
+
**Upgrading.**
|
|
448
|
+
|
|
449
|
+
Nothing to do, with one change in timing: `Dialog.LegacyModal`, and the top-level `LegacyModal` that renders through it, load in a chunk of their own, with `@react-spring/web`, the first time they render. A legacy modal mounted only when it opens therefore shows its first open one chunk load later; it then springs in from transparent as a later open does, nothing is drawn in its place meanwhile, and the open is not lost. A test that expects its content in the first render must wait for it.
|
|
450
|
+
|
|
285
451
|
- 31097f2: Under `AKAN_MEMORY_LOG=1`, the RSC worker's metrics name the routes whose first render grew it most.
|
|
286
452
|
|
|
287
453
|
- `rscFirstRenderMemory` on `AkanMetricsReport`, served in `/_akan/app/metrics` beside the last render's fields, lists for each route what its first render in this worker added to `rss`, `heapUsed`, `external` and `arrayBuffers`, with the modules that render loaded. Largest RSS growth comes first, and at most 20 routes are kept. Renders running at the same time land in the same delta, so read it on a quiet replica.
|
|
@@ -355,13 +521,61 @@
|
|
|
355
521
|
|
|
356
522
|
- c44d068: A coding agent reads less to build its first app: the `akanjs` README keeps the path to a first app and links the rest on akanjs.com (17 KB to 7 KB), the `akan-page` and `akan-service` skills ship the API reference one section at a time with every entry named in the skill's index (`Link` now lists the anchor attributes it takes and `Link.Back`, `Link.Close` and `Link.Lang`), the `akan-page` skill holds what a first page looks up while `pageRule` keeps the deeper contract, and each rule is stated once across AGENTS.md, the path rules and the skills. Run `akan agent install` in a workspace to pick up the new files.
|
|
357
523
|
- 43b44ca: An Android app's page now meets the keyboard the way the iOS app's does: the keys rise over the page and only what the page moves rides up with them. In keyboard mode "none" (what akan apps ship) the Android WebView still heard of the keyboard through the window insets, shrank its visual viewport to the space above the keys and panned the whole page so the focused field showed, which lifted a chat composer far above the keys, dragged whatever sat under it (a tab bar's room) up too, and slid the top of the page under the status bar. The Android shell now hands the WebView its insets with the keyboard taken out in "none" (and its animation callbacks too), keeps the bottom safe area while the keys are up, reports the keys' whole overlap with the screen as the iOS shell does, and tells the page through `__AKAN_NATIVE__.keyboardAvoidance = "page"`. Under such a shell the frame ends the content at the keys and `KeyboardRide` carries what is marked `data-akan-keyboard-ride` with them, on the duration the shell reports and Android's IME curve (`ANDROID_KEYBOARD_ANIMATION_EASING`, added to `akanjs/client`). A page under an older shell, which still pans, keeps today's behavior; an Android app gets the new behavior once it is built with this shell.
|
|
524
|
+
- f678e80: The `akanjs` package no longer ships `ARCHITECTURE.md`. The map of the framework's processes and messages is for contributors and stays in the repository (`pkgs/akanjs/ARCHITECTURE.md`); a coding agent building an app read its 11.9 KB from the unpacked package before scaffolding. Verifying a built `akanjs` dist now fails if the file is back in it.
|
|
358
525
|
- af09c4f: `router.backOrFallback()` and `Link.Back` with a `fallback` close a browser tab the app itself opened instead of replacing to the fallback, when there is nothing to go back to. The tab counts as opened by the app when it holds one history entry and has an opener or a same-origin referrer, so a `window.open(href, "_blank", "noopener")` or `target="_blank"` link qualifies. A tab the person opened (a bookmark, a typed URL), one another site opened, and an iOS, Android or desktop shell keep going to the fallback, as does a tab the browser refuses to close.
|
|
359
526
|
- 24315d1: A page asks for its stylesheet before its client chunks. The preload tags for the chunks a page's first screen imports are written at the end of `<head>` instead of at its top, so the stylesheet link comes first; the bootstrap module, the dictionary and the import map stay at the top. On a throttled mobile connection (Lighthouse's slow 4G applied in the browser, over HTTP/2) a 56-chunk page first paints about 160 ms sooner (1.83 s to 1.67 s), and a page whose largest element is a small image shows it about 140 ms sooner; a large image still shares the connection with the chunks and arrives when it did. Every chunk still starts loading with the document, so the page hydrates when it did.
|
|
527
|
+
- 7c4143e: `akanjs/client` exports `nativeKeyboardEasing()`, the curve the keyboard of the shell a page runs in moves on: Android's (`ANDROID_KEYBOARD_ANIMATION_EASING`) in an Android app, iOS's (`IOS_KEYBOARD_ANIMATION_EASING`) anywhere else. `KeyboardRide` already used it; with the name on the barrel, a page's browser code holds the device and keyboard files once, where a build would otherwise have shipped them in two bundles.
|
|
528
|
+
- 55d1518: A production build of a workspace with several libs loads its client modules in order, and a page that needs every module weighs what it weighed before.
|
|
529
|
+
|
|
530
|
+
- Each generated piece exports a name, and a module that needs the piece imports that name and hands it to `loadedAfter` from `akanjs/base`. A piece imported only for its effect could end up in a chunk the importer's chunk did not load first; a store or an endpoint was then read before it existed.
|
|
531
|
+
- A store file, and every file a store file imports, loads no store piece. The stores its code names are loaded by each file outside that imports it or names its store, so no store file is defined through a piece that imports it back. Where the importing file is one the build leaves as written (it holds a macro import, or lies outside `apps/` and `libs/`), the page keeps the whole runtime.
|
|
532
|
+
- A store spreading a value into the object it gives its own `this.set` (`this.set({ ...patch })`) no longer counts as picking a name at run time. A value or a function handed over whole (`this.set(patch)`, `this.set(update)`) still does, since an updater may read any module's state. `fetch.ws`, `fetch.http`, `fetch.origin`, `fetch.jwt`, `fetch.logger`, `fetch.setJwt`, `fetch.setTimeout`, `fetch.connect`, `fetch.connectOnUse`, `fetch.disconnect` and `fetch.configureWs` are the fetch client's own members, not endpoint names.
|
|
533
|
+
- A client entry that reaches a file needing every module keeps the whole runtime, as does an entry held only by pages with such an entry, and one naming a module that more such pages hold than other pages. Their files are left as written, so the page loads the code it loaded before.
|
|
534
|
+
- `akan build` checks its output before it serves it: every chunk holding a module that needs a piece reaches the chunk holding that piece, no store file sits in an import cycle with a piece, and no entry built to load pieces reaches a file needing every module. On a failure the build warns once with the two source files named, builds every page on the whole runtime instead and succeeds; the warning is a bug in akan to report. The development server serves each module on its own and checks nothing, so the production build is the guard.
|
|
535
|
+
- `akan quality runtime` adds a note, `akan.runtime.framework-marker`, per file that brings a framework component reading models by name (`Field`'s relation fields, `Load`, `Model`, `Data`, `Signal`, `Constant.Doc`) onto a page: the imports from that file to the component, and the pages that load the whole runtime through it.
|
|
536
|
+
|
|
537
|
+
Nothing to do. A file outside every app and lib that imports a `lib/__client/` piece by hand should import the piece's exported name and pass it to `loadedAfter`; the build's check names it otherwise.
|
|
538
|
+
|
|
539
|
+
- 0a2f6dd: `akan sync` also writes each app's and lib's client runtime as one generated piece per module under `lib/__client/`, ready for a later release that loads a model's endpoint descriptors and store only on the routes that use them. Nothing imports the pieces yet: `lib/useClient.ts`, `lib/st.ts` and `lib/usePage.ts` are unchanged, and every route loads exactly what it loaded before.
|
|
540
|
+
|
|
541
|
+
- `<module>.fetch.ts` applies that module's endpoint descriptors onto the tab's fetch client, after the same module's piece of each lib it extends; `_base.fetch.ts` applies the descriptors every scope inherits from `akanjs/signal` itself.
|
|
542
|
+
- `<module>.st.ts` registers and builds that module's store alone, after the extended lib store's own piece.
|
|
543
|
+
- `_useClient.ts` imports every fetch piece of the scope and its libs and exports what `lib/useClient.ts` exports; `_st.ts` imports every store piece and exports `st`, `RootStore` and each store, as `lib/st.ts` does.
|
|
544
|
+
- `lib/sig.ts` exports one more build-time macro, `getSerializedSignalOf(name)`, which answers the descriptors one module brings, or with `"base"` the ones from `akanjs/signal`.
|
|
545
|
+
- `lib/__lib/lib.store.ts` imports each extended lib store from its own file instead of the lib's `client` barrel, and registers it when the lib's runtime has not yet, so an app store file imported on its own still has the lib store's actions.
|
|
546
|
+
- A server render reads a fetch piece's descriptors from the live server signal, as it does for `lib/useClient.ts`.
|
|
547
|
+
- `akan sync` removes the pieces of a module that was deleted or renamed.
|
|
548
|
+
- Adding a store root to a running store does work in proportion to the keys that root brings, not to every key already in the store, so building one root per module stays linear. A computed key that a later root adds now starts from the state as it is, so with a lib store's `count: 1` in place, an app store overriding `count: 10` and adding `tripled = computed(["count"], …)` starts at `tripled: 3` rather than 30.
|
|
549
|
+
- `lib/__client/` is listed with the other generated files: in the agent guide, the agent hook that stops hand edits, the Biome overrides, the code graph, and the `.gitignore` of a new workspace.
|
|
550
|
+
|
|
551
|
+
**Upgrading.**
|
|
552
|
+
|
|
553
|
+
Nothing to change in app code. The `.gitignore` lines for the new files are in the upgrade note of the entry that makes every app load per route.
|
|
554
|
+
|
|
555
|
+
- b5b4834: The development server now loads what a production page loads, so a page that works in development works the same once built.
|
|
556
|
+
|
|
557
|
+
- A server-rendered page in development takes the descriptors and stores of only the modules its client code names, from the same `lib/__client/` pieces a route build uses, and imports from `akanjs/ui` narrow as they do in a build. The tab keeps one store, and each piece loads once.
|
|
558
|
+
- Saving a store, signal or constant file rereads which module declares each name and recompiles the files whose names moved to another module. A store save that adds an action replaces that store's actions and keeps its state, without reloading the page.
|
|
559
|
+
- Saving a lib's store file or store piece runs the app's piece of that module and the app's assembled store again after it, and the app's store of that model too when it extends the lib's, so a lib store the app extends keeps the app's actions.
|
|
560
|
+
- A component saved to name another module loads that module's piece without reloading the page; a file saved to pick a name at run time loads the whole runtime.
|
|
561
|
+
- An app whose `lib/__client/` files, or a mounted lib's, are missing, or whose modules cannot be read, loads the whole runtime in development as a build does. The development server says which once, names the sync to run, and loads per module again on the next save after that sync, with no restart.
|
|
562
|
+
- Reading a store key the page has not loaded fails with the name of the module whose store declares it, and says to name the key in the file that reads it or import `st` from the app's `client` barrel there. The list of each store's keys behind that message exists only in development: a production bundle carries neither the list nor the message.
|
|
563
|
+
|
|
564
|
+
- 170fa28: A page downloads the framework's `akanjs/client` code once. A production build used to bundle the `akanjs/client` files that the framework's UI imports by path into the page's own chunks, beside the copy the page's server-rendering client already loaded, so a page ran two copies of them, each with its own state (`Device.instance` among it). Both now come from one browser entry for `akanjs/client`, which, like the other framework entries, holds only the names the app uses. This applies to a page loading per module and to one keeping the whole runtime alike; what a page shows and how it behaves do not change.
|
|
565
|
+
|
|
566
|
+
- **Size.** In the framework's own sample apps each route loads 9 to 17 KB (brotli) less when it loads per module and 9 to 50 KB less when it loads every module. A page loading per module can make one more request, for the `akanjs/client` entry; a page loading every module makes the same number or fewer.
|
|
567
|
+
- **Which files.** A file comes from the entry when the `akanjs/client` barrel re-exports all of it under its own names, whether the importer names `akanjs/client`, a path into it, a relative path, or a path through a linked `akanjs` install. A file the barrel leaves out or renames, such as `akanjs/client/native`, any dynamic `import()`, and a file of another framework entry imported by its path stay in the page's chunks. The native bridge behind `akanjs/client/native` is therefore still written into both builds, because the entry's `Device` and `storage` import it lazily, but only the CSR shell loads it.
|
|
568
|
+
- **Development.** `akan start` serves those files from its whole `akanjs/client` entry as well, so a development page runs one copy of the client's state; a few stateless helpers the framework's UI imports by path (`cn` among them) still load beside it from the development module registry.
|
|
569
|
+
- **Unchanged.** The single-file CSR build that native apps load and MCP App views carry one copy, as before.
|
|
570
|
+
|
|
571
|
+
Nothing to do. A workspace on an older `akanjs` without the `akanjs/client` entry builds as it did.
|
|
572
|
+
|
|
360
573
|
- bf582c1: A page stored in the HTML cache is kept as the bytes it streamed, instead of being decoded to text and encoded again before compression. Storing a 600 KB page takes about a fifth of the main-thread time it did, and the stored page and every response from it are unchanged.
|
|
361
574
|
- 8bbe7c8: Every response from `/_akan/image` carries `X-Content-Type-Options: nosniff`, `Referrer-Policy` and a sandboxing `Content-Security-Policy` (`script-src 'none'; frame-src 'none'; sandbox;`), and an image response carries `Content-Disposition: attachment` named after its source file. An SVG an app allows with `dangerouslyAllowSVG` still shows in an `<img>`, and runs no script when its URL is opened on its own.
|
|
362
575
|
|
|
363
576
|
**Upgrading.** Opening an optimized image's URL directly in a browser tab now downloads it instead of showing it; images in pages, CSS and `srcset` are unchanged. A cached passthrough image of type heic, ico, icns, bmp, jxl or tiff is now stored under its own extension instead of `.jpg`, so each one is fetched once more and its old cache file is left behind.
|
|
364
577
|
|
|
578
|
+
- 2030f6c: `Input` (and `Field.Text` over it) drops its invalid message when the value is emptied, as `Input.TextArea`, `Input.Password` and `Input.Email` already did. A form the store cleared after a successful submit kept showing the length message of the value typed before.
|
|
365
579
|
- 1a225e8: A chat list under an iOS overlay (`data-akan-keyboard-ride="inset"`) now slides down with the keys instead of dropping at once when they go down. Once the keys were up the list held its rise as bottom padding, so its box reached past what it showed by that padding; on the way down `KeyboardRide` read the box's bottom as where the list was drawn, found no distance to travel, and the list fell into place in one frame. The rise each inset rider took is now remembered and subtracted, so the list starts from where it was drawn.
|
|
366
580
|
- e9598f3: Under an iOS shell that leaves the keyboard to the page, the page box now starts moving with the keys on their first frame. It followed a store update and React's render of the frame, which on a phone started the move about 100 ms after the keys, then jumped to catch up. `Device` now sets `--akan-keyboard-cover`, `--akan-keyboard-duration`, `--akan-keyboard-easing` and `data-akan-keyboard` on the root in the shell's keyboard event itself, and the page box's height and bottom padding follow `--akan-keyboard-cover` in CSS, so the transition starts before any render. `isPageKeyboardAvoidance` and `IOS_KEYBOARD_ANIMATION_EASING` now come from `akanjs/client` too.
|
|
367
581
|
- 1885caf: A chat screen in an iOS app can now keep the whole screen while the keys are up, as a native chat does, so its tab bar and background stay drawn under the glass keyboard instead of the page ending at the keys. When the focused field sits inside an element marked `data-akan-keyboard-overlay`, `KeyboardRide` leaves the page box whole: the riders (`data-akan-keyboard-ride`) go where the shorter box would have put them and stay there, and a rider marked `data-akan-keyboard-ride="inset"` (a list's content) trades its lift for bottom padding once the keys are up, so the list still scrolls to its top. The root carries `data-akan-keyboard-overlay` meanwhile. Every other field keeps the page box ending at the keys, so a form field elsewhere is never left under them.
|
|
@@ -381,6 +595,10 @@
|
|
|
381
595
|
|
|
382
596
|
- 5c6d039: A precompressed `.br` or `.gz` asset is now streamed from disk instead of being read whole and copied on every request, which cuts the server CPU per asset request to about a quarter. In production the answer of whether a sidecar exists is remembered per path.
|
|
383
597
|
An existing zero-byte `.br` or `.gz` sibling is skipped, because an empty body is not valid brotli or gzip.
|
|
598
|
+
- b30db27: A signal test's fetch opens its socket at the first subscribe or message, so a pubsub test needs no clone.
|
|
599
|
+
|
|
600
|
+
`getOrSetupSignalTestFetch()` handed back a fetch whose socket was never opened: `fetch.subscribe<Event>(…)` on it heard nothing and warned `WebSocket is not connected. Call fetch.instance.connect()…`, and the way through was `fetch.clone({ connect: true })`. The test fetch now connects on first use, as a page's does, and the socket is closed when the test context ends. A test that never subscribes or sends a message opens no socket, as before.
|
|
601
|
+
|
|
384
602
|
- 0492e0b: The SQLite cache sweeps expired entries through an index on their expiry, a thousand at a time with a pause between, so a large backlog no longer stalls the server for hundreds of milliseconds, and `hkeys` and `hentries` no longer run a sweep on every call. They skip expired fields themselves, so they return the same fields as before. The index is built once, at the first start after upgrading.
|
|
385
603
|
- 0492e0b: On the SQLite cache, a value or hash field written by another process is no longer removed by a `get` or `hget` that saw the key's previous, expired entry.
|
|
386
604
|
- 5c7e083: On SQLite a read, count or write by a list of ids (`q.oneOf` on `id`, which is how a batched load by id reads) goes through the primary key. A model with an index that leads with `removedAt` had a list of five or more ids read every live row instead: at 20,000 rows a load of five ids took about 6 ms and now takes about 0.03 ms.
|
|
@@ -389,6 +607,10 @@
|
|
|
389
607
|
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.
|
|
390
608
|
|
|
391
609
|
- 05ef91f: The database statement metrics no longer freeze the server at 100% CPU. One statement sent by a seventeenth endpoint when no untraced call had sent it before, or a ninth text of one query shape in local dev's plan check, made the counter call itself with the same arguments forever, with no error or log. Senders past sixteen are counted in one `other` slot and texts past eight share one plan, as intended.
|
|
610
|
+
- 8720b88: `st.do.<action>` and a generated `st.do.set<Key>` stay the same function when a later store root repeats their store, so a component that holds one in an effect's dependency array no longer reruns that effect once when, for example, a lib's root and then the app's root are built. An action whose method changed, as after an edit under hot reload, is still replaced, and a later root's `static silent` still quiets an action an earlier root built. A `set<Key>` action a store declares itself also stays in place when a later root that does not declare it is added, where it was replaced by a plain setter of the same name.
|
|
611
|
+
|
|
612
|
+
In development (`NODE_ENV=development`, as under `akan start`), `st.use`, `st.do` and `st.slice` throw on a key no loaded store declares, naming it (`st.do.initMemo is not registered: …`), where they answered `undefined` and the call failed later with `… is not a function`. `in`, `Object.keys` and a symbol key still answer as before, and a production build and a test run are unchanged.
|
|
613
|
+
|
|
392
614
|
- 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.
|
|
393
615
|
|
|
394
616
|
## 3.2.0
|
package/base/utils.ts
CHANGED
|
@@ -25,3 +25,5 @@ export const applyFnToArrayObjects = <Input, Fn extends (arg: never) => unknown>
|
|
|
25
25
|
if (Array.isArray(arraiedData)) return arraiedData.map((data) => applyFnToArrayObjects(data, fn)) as Result;
|
|
26
26
|
return fn(arraiedData as never) as Result;
|
|
27
27
|
};
|
|
28
|
+
|
|
29
|
+
export const loadedAfter = (..._modules: unknown[]): void => {};
|
|
@@ -1,32 +1,110 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type DictionaryModule, importDictionaryModule } from "./dictionaryModule";
|
|
2
|
+
import { DictionaryPart } from "./dictionaryPart";
|
|
3
|
+
import { TranslatorState } from "./translatorState";
|
|
2
4
|
|
|
3
|
-
interface
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
interface DictionaryAssetState {
|
|
6
|
+
loads: Map<string, Promise<DictionaryModule>>;
|
|
7
|
+
appliedSeqByLang: Map<string, number>;
|
|
8
|
+
seq: number;
|
|
9
|
+
|
|
10
|
+
wholes: WeakSet<object>;
|
|
11
|
+
|
|
12
|
+
groupsBySnapshot: WeakMap<object, Set<string>>;
|
|
6
13
|
}
|
|
7
14
|
|
|
15
|
+
const dictionaryAssetStateKey = "__AKAN_DICTIONARY_ASSET__";
|
|
16
|
+
|
|
8
17
|
export class DictionaryAsset {
|
|
9
|
-
static
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
static #state(): DictionaryAssetState {
|
|
19
|
+
const globalScope = globalThis as typeof globalThis & { [dictionaryAssetStateKey]?: DictionaryAssetState };
|
|
20
|
+
globalScope[dictionaryAssetStateKey] ??= {
|
|
21
|
+
loads: new Map(),
|
|
22
|
+
appliedSeqByLang: new Map(),
|
|
23
|
+
seq: 0,
|
|
24
|
+
wholes: new WeakSet(),
|
|
25
|
+
groupsBySnapshot: new WeakMap(),
|
|
26
|
+
};
|
|
27
|
+
return globalScope[dictionaryAssetStateKey];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static async load(urls: string | readonly string[] | null | undefined): Promise<void> {
|
|
31
|
+
const list = (typeof urls === "string" ? urls.split(",") : (urls ?? [])).filter(Boolean);
|
|
32
|
+
if (!list.length) return;
|
|
33
|
+
const state = DictionaryAsset.#state();
|
|
34
|
+
const seq = ++state.seq;
|
|
35
|
+
TranslatorState.get().loadSeq = seq;
|
|
36
|
+
const loaded = await Promise.allSettled(list.map((url) => DictionaryAsset.#loading(url)));
|
|
37
|
+
loaded.forEach((result, idx) => {
|
|
38
|
+
const url = list[idx];
|
|
39
|
+
if (result.status === "fulfilled" && url) DictionaryAsset.#apply(url, result.value, seq);
|
|
40
|
+
});
|
|
41
|
+
const failed = loaded.find((result) => result.status === "rejected");
|
|
42
|
+
if (failed) throw failed.reason;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static async add(url: string): Promise<boolean> {
|
|
46
|
+
const dictionaryModule = await DictionaryAsset.#loading(url);
|
|
47
|
+
return DictionaryAsset.#apply(url, dictionaryModule, null);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static holdsEveryGroup(lang: string): boolean {
|
|
51
|
+
const replaced = TranslatorState.get().replacedByLang.get(lang);
|
|
52
|
+
return !!replaced && DictionaryAsset.#state().wholes.has(replaced);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static holdsGroup(lang: string, group: string): boolean {
|
|
56
|
+
const replaced = TranslatorState.get().replacedByLang.get(lang);
|
|
57
|
+
return !!replaced && !!DictionaryAsset.#state().groupsBySnapshot.get(replaced)?.has(group);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static #markGroups(snapshot: object, groups: readonly string[]) {
|
|
61
|
+
const { groupsBySnapshot } = DictionaryAsset.#state();
|
|
62
|
+
const marked = groupsBySnapshot.get(snapshot) ?? new Set<string>();
|
|
63
|
+
for (const group of groups) marked.add(group);
|
|
64
|
+
groupsBySnapshot.set(snapshot, marked);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static #apply(
|
|
68
|
+
url: string,
|
|
69
|
+
{ lang, default: dictionary, parts, table, groups, part }: DictionaryModule,
|
|
70
|
+
seq: number | null,
|
|
71
|
+
) {
|
|
72
|
+
const state = DictionaryAsset.#state();
|
|
73
|
+
const translator = TranslatorState.get();
|
|
74
|
+
const replaced = translator.replacedByLang.get(lang);
|
|
75
|
+
if (part)
|
|
76
|
+
return (
|
|
77
|
+
!!replaced && DictionaryPart.urlOf(lang, part) === url && DictionaryPart.merge(lang, url, dictionary, replaced)
|
|
78
|
+
);
|
|
79
|
+
const sameBuild = !!table && !!replaced && translator.tableByLang.get(lang) === table;
|
|
80
|
+
if (groups && sameBuild) {
|
|
81
|
+
if (!state.wholes.has(replaced) && DictionaryPart.merge(lang, url, dictionary, replaced))
|
|
82
|
+
DictionaryAsset.#markGroups(replaced, groups);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
if (seq === null || (state.appliedSeqByLang.get(lang) ?? 0) > seq) return false;
|
|
86
|
+
state.appliedSeqByLang.set(lang, seq);
|
|
87
|
+
if (!groups) {
|
|
88
|
+
state.wholes.add(dictionary);
|
|
89
|
+
TranslatorState.replace(lang, dictionary, parts, table);
|
|
90
|
+
return true;
|
|
30
91
|
}
|
|
92
|
+
const base = {};
|
|
93
|
+
TranslatorState.replace(lang, base, parts, table);
|
|
94
|
+
const merged = DictionaryPart.merge(lang, url, dictionary, base);
|
|
95
|
+
if (merged) DictionaryAsset.#markGroups(base, groups);
|
|
96
|
+
return merged;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static #loading(url: string): Promise<DictionaryModule> {
|
|
100
|
+
const { loads } = DictionaryAsset.#state();
|
|
101
|
+
const known = loads.get(url);
|
|
102
|
+
if (known) return known;
|
|
103
|
+
const loading = importDictionaryModule(url).catch((error: unknown) => {
|
|
104
|
+
loads.delete(url);
|
|
105
|
+
throw error;
|
|
106
|
+
});
|
|
107
|
+
loads.set(url, loading);
|
|
108
|
+
return loading;
|
|
31
109
|
}
|
|
32
110
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { DictionaryAsset } from "./dictionaryAsset";
|
|
2
|
+
import { importDictionaryModule } from "./dictionaryModule";
|
|
3
|
+
import { TranslatorState } from "./translatorState";
|
|
4
|
+
|
|
5
|
+
interface GroupTable {
|
|
6
|
+
files: string[];
|
|
7
|
+
default: Record<string, number>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface GroupWait {
|
|
11
|
+
load: Promise<boolean>;
|
|
12
|
+
|
|
13
|
+
rendered: boolean;
|
|
14
|
+
failedAt?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface DictionaryGroupsState {
|
|
18
|
+
tables: Map<string, Promise<GroupTable>>;
|
|
19
|
+
waits: Map<string, GroupWait>;
|
|
20
|
+
reported: Set<string>;
|
|
21
|
+
listeners: Set<() => void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const dictionaryGroupsStateKey = "__AKAN_DICTIONARY_GROUPS__";
|
|
25
|
+
|
|
26
|
+
export class DictionaryGroups {
|
|
27
|
+
static #state(): DictionaryGroupsState {
|
|
28
|
+
const globalScope = globalThis as typeof globalThis & { [dictionaryGroupsStateKey]?: DictionaryGroupsState };
|
|
29
|
+
globalScope[dictionaryGroupsStateKey] ??= {
|
|
30
|
+
tables: new Map(),
|
|
31
|
+
waits: new Map(),
|
|
32
|
+
reported: new Set(),
|
|
33
|
+
listeners: new Set(),
|
|
34
|
+
};
|
|
35
|
+
return globalScope[dictionaryGroupsStateKey];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static install(): void {
|
|
39
|
+
TranslatorState.get().groups ??= { pending: DictionaryGroups.pending, missed: DictionaryGroups.missed };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static pending(lang: string, key: string): Promise<boolean> | null {
|
|
43
|
+
return DictionaryGroups.#wait(lang, key)?.load ?? null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static missed(lang: string, key: string): void {
|
|
47
|
+
if (typeof window === "undefined") return;
|
|
48
|
+
const wait = DictionaryGroups.#wait(lang, key);
|
|
49
|
+
if (!wait) return;
|
|
50
|
+
wait.rendered = true;
|
|
51
|
+
if (process.env.NODE_ENV === "production") return;
|
|
52
|
+
const group = key.slice(0, key.indexOf("."));
|
|
53
|
+
const { reported } = DictionaryGroups.#state();
|
|
54
|
+
if (reported.has(group)) return;
|
|
55
|
+
reported.add(group);
|
|
56
|
+
const fault = new Error(
|
|
57
|
+
`[dictionary] "${key}" was shown on a route whose dictionary files leave out "${group}": its file loads late. The group was not counted for this route in its last build: a key of it added to a client file since is counted when the route builds again, and a key the build can read names the group.`,
|
|
58
|
+
);
|
|
59
|
+
void wait.load.then((merged) => merged && console.error(fault));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static onMerged(listener: () => void): () => void {
|
|
63
|
+
const { listeners } = DictionaryGroups.#state();
|
|
64
|
+
listeners.add(listener);
|
|
65
|
+
return () => listeners.delete(listener);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static #wait(lang: string, key: string): GroupWait | null {
|
|
69
|
+
const dot = key.indexOf(".");
|
|
70
|
+
const group = dot > 0 ? key.slice(0, dot) : "";
|
|
71
|
+
const translator = TranslatorState.get();
|
|
72
|
+
const table = translator.tableByLang.get(lang);
|
|
73
|
+
if (!group || !table || DictionaryAsset.holdsGroup(lang, group) || DictionaryAsset.holdsEveryGroup(lang))
|
|
74
|
+
return null;
|
|
75
|
+
const { waits } = DictionaryGroups.#state();
|
|
76
|
+
const id = `${table} ${group}`;
|
|
77
|
+
const known = waits.get(id);
|
|
78
|
+
if (known && (known.failedAt === undefined || known.failedAt === translator.loadSeq)) return known;
|
|
79
|
+
const wait: GroupWait = { load: Promise.resolve(false), rendered: false };
|
|
80
|
+
wait.load = DictionaryGroups.#load(table, group).then(
|
|
81
|
+
(merged) => {
|
|
82
|
+
if (merged && wait.rendered) for (const listener of DictionaryGroups.#state().listeners) listener();
|
|
83
|
+
return merged;
|
|
84
|
+
},
|
|
85
|
+
(error: unknown) => {
|
|
86
|
+
wait.failedAt = TranslatorState.get().loadSeq;
|
|
87
|
+
console.error(`[DictionaryGroups] "${group}" failed to load: ${String(error)}`);
|
|
88
|
+
return false;
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
waits.set(id, wait);
|
|
92
|
+
return wait;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static async #load(table: string, group: string): Promise<boolean> {
|
|
96
|
+
const { files, default: fileOf } = await DictionaryGroups.#table(table);
|
|
97
|
+
const idx = fileOf[group];
|
|
98
|
+
const url = idx === undefined ? undefined : files[idx];
|
|
99
|
+
return url ? DictionaryAsset.add(url) : false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static #table(url: string): Promise<GroupTable> {
|
|
103
|
+
const { tables } = DictionaryGroups.#state();
|
|
104
|
+
const known = tables.get(url);
|
|
105
|
+
if (known) return known;
|
|
106
|
+
const loading = importDictionaryModule<GroupTable>(url).catch((error: unknown) => {
|
|
107
|
+
tables.delete(url);
|
|
108
|
+
throw error;
|
|
109
|
+
});
|
|
110
|
+
tables.set(url, loading);
|
|
111
|
+
return loading;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Dictionary } from "./translatorState";
|
|
2
|
+
|
|
3
|
+
export interface DictionaryModule {
|
|
4
|
+
lang: string;
|
|
5
|
+
default: Dictionary;
|
|
6
|
+
parts?: Record<string, string>;
|
|
7
|
+
|
|
8
|
+
table?: string;
|
|
9
|
+
|
|
10
|
+
groups?: string[];
|
|
11
|
+
|
|
12
|
+
part?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let retrySeq = 0;
|
|
16
|
+
|
|
17
|
+
export const importDictionaryModule = async <Module = DictionaryModule>(url: string): Promise<Module> => {
|
|
18
|
+
try {
|
|
19
|
+
return (await import(url)) as Module;
|
|
20
|
+
} catch {
|
|
21
|
+
return (await import(`${url}?retry=${++retrySeq}`)) as Module;
|
|
22
|
+
}
|
|
23
|
+
};
|