@akanjs/devkit 3.3.0-rc.6 → 3.3.0-rc.60
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/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +8 -2
- package/README.md +8 -3
- package/akanApp/akanApp.host.test.ts +4 -2
- package/akanApp/akanApp.host.ts +11 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +280 -19
- package/akanConfig/akanConfig.ts +96 -270
- package/akanConfig/akanWorkers.test.ts +73 -0
- package/akanConfig/akanWorkers.ts +61 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +216 -0
- package/akanConfig/index.ts +2 -0
- package/akanConfig/nativeFileSettings.ts +33 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/akanConfig/types.ts +2 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +51 -1
- package/app/applicationBuildReporter.ts +6 -1
- package/app/applicationBuildRunner.test.ts +358 -5
- package/app/applicationBuildRunner.ts +204 -30
- package/app/dictionarySizes.test.ts +40 -0
- package/app/dictionarySizes.ts +95 -0
- package/app/routeFilesReport.test.ts +59 -0
- package/app/routeFilesReport.ts +46 -0
- package/app/routeJsBudget.ts +18 -4
- package/artifact/implicitRootLayout.test.ts +19 -0
- package/artifact/implicitRootLayout.ts +16 -2
- package/artifact/implicitRootLayoutRender.test.tsx +4 -1
- package/artifact/storeBootstrap.test.ts +28 -0
- package/artifact/storeBootstrap.ts +64 -8
- package/biome.base.json +7 -5
- package/codeAgent/agent/CodeAgent.ts +36 -16
- package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
- package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
- package/codeAgent/agent/CodeAgentGate.ts +23 -4
- package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +62 -0
- package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
- package/codeAgent/agent/codeAgentContract.test.ts +117 -5
- package/codeAgent/skills/akan-agent/SKILL.md +8 -1
- package/codeAgent/skills/akan-code/SKILL.md +38 -3
- package/codeAgent/skills/akan-debug/SKILL.md +1 -1
- package/codeAgent/skills/akan-deps/SKILL.md +3 -2
- package/codeAgent/skills/akan-err/SKILL.md +13 -8
- package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
- package/codeAgent/skills/akan-module/SKILL.md +2 -2
- package/codeAgent/skills/akan-page/SKILL.md +46 -29
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-runtime/SKILL.md +21 -1
- package/codeAgent/skills/akan-service/SKILL.md +10 -11
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +16 -21
- package/commandDecorators/command.ts +28 -12
- package/commandDecorators/commandBuilder.ts +8 -1
- package/commandDecorators/commandDecorators.test.ts +70 -3
- package/commandDecorators/helpFormatter.ts +14 -12
- package/context/akanContext.ts +2 -0
- package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
- package/docs/apiReference.test.ts +9 -0
- package/docs/apiReference.ts +15 -0
- package/executors/appExecutor.ts +26 -12
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1690 -0
- package/executors/executor.ts +14 -6
- package/executors/executors.test.ts +140 -1
- package/executors/sysExecutor.ts +112 -8
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/allRoutesBuilder.ts +99 -7
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +686 -13
- package/frontendBuild/clientBuildTypes.ts +26 -0
- package/frontendBuild/clientEntriesBundler.ts +49 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
- package/frontendBuild/clientEntryDiscovery.ts +136 -14
- package/frontendBuild/clientEntryGroups.test.ts +77 -0
- package/frontendBuild/clientEntryGroups.ts +61 -0
- package/frontendBuild/csrDevArtifactWriter.ts +2 -2
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.test.ts +1 -1
- package/frontendBuild/csrDevPatcher.ts +33 -7
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +154 -0
- package/frontendBuild/devBarrelImports.ts +83 -23
- package/frontendBuild/devRegistryBundler.ts +4 -2
- package/frontendBuild/devRouteRuntime.test.ts +492 -0
- package/frontendBuild/devRouteRuntime.ts +167 -0
- package/frontendBuild/dictionaryAssetBuilder.test.ts +408 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +185 -17
- package/frontendBuild/dictionaryConstants.ts +136 -0
- package/frontendBuild/dictionaryOwnParts.ts +88 -0
- package/frontendBuild/dictionaryPackState.ts +131 -0
- package/frontendBuild/dictionaryPacking.test.ts +207 -0
- package/frontendBuild/dictionaryPacking.ts +160 -0
- package/frontendBuild/dictionaryRoutes.test.ts +251 -0
- package/frontendBuild/dictionaryRoutes.ts +227 -0
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +78 -2
- package/frontendBuild/precompressArtifacts.test.ts +22 -0
- package/frontendBuild/precompressArtifacts.ts +34 -8
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/renderedEntries.ts +144 -0
- package/frontendBuild/routeClientBuilder.ts +407 -43
- package/frontendBuild/routeHandoffs.test.ts +155 -0
- package/frontendBuild/routeHandoffs.ts +117 -0
- package/frontendBuild/routeModulePreloads.test.ts +32 -0
- package/frontendBuild/routeModulePreloads.ts +20 -11
- package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
- package/frontendBuild/routeRuntimeCheck.ts +248 -0
- package/frontendBuild/routeRuntimePays.test.ts +143 -0
- package/frontendBuild/routeRuntimePays.ts +117 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
- package/frontendBuild/ssrDevBundler.test.ts +150 -1
- package/frontendBuild/ssrDevBundler.ts +66 -11
- package/frontendBuild/vendorFileImports.test.ts +254 -0
- package/frontendBuild/vendorFileImports.ts +163 -0
- package/frontendBuild/vendorNarrowing.ts +28 -0
- package/frontendBuild/vendorSpecifiers.ts +2 -0
- package/incrementalBuilder/buildBatch.proc.ts +9 -9
- package/incrementalBuilder/buildBatchProtocol.ts +1 -1
- package/incrementalBuilder/builderBoot.ts +5 -5
- package/incrementalBuilder/builderGraphPayloads.ts +4 -4
- package/incrementalBuilder/builderLanes.ts +2 -2
- package/incrementalBuilder/builderWatch.ts +8 -8
- package/incrementalBuilder/csrRegistry.ts +4 -4
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
- package/incrementalBuilder/ssrRegistry.ts +6 -6
- package/index.ts +1 -1
- package/integration/renderAdmissionSoak.test.ts +99 -0
- package/integration/renderAdmissionSoak.ts +609 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
- package/lint/biomeBase.test.ts +50 -3
- package/lint/biomeBase.ts +1 -1
- package/lint/biomeCheck.test.ts +162 -0
- package/lint/biomeCheck.ts +131 -0
- package/lint/linter.test.ts +16 -11
- package/lint/no-arbitrary-color.grit +5 -0
- package/lint/no-conditional-st-hook.grit +5 -1
- package/lint/no-daisyui-legacy-class.grit +8 -0
- package/lint/no-document-cookie.grit +3 -0
- package/lint/no-inline-color.grit +10 -2
- package/lint/no-oversized-list-limit.grit +2 -0
- package/lint/no-raw-palette-class.grit +7 -0
- package/lint/no-unpublished-form-setter.grit +2 -0
- package/lint/no-web-only-api-outside-webkit.grit +5 -0
- package/lint/no-web-storage.grit +3 -0
- package/lint/withheldEnvFile.ts +17 -0
- package/mobile/desktopBin.ts +2 -2
- package/mobile/desktopServerStage.test.ts +18 -3
- package/mobile/desktopServerStage.ts +7 -2
- package/mobile/nativeApp.test.ts +7 -5
- package/mobile/nativeApp.ts +2 -2
- package/mobile/nativeConfig.test.ts +96 -1
- package/mobile/nativeConfig.ts +46 -12
- package/mobile/nativePublicEnv.ts +1 -1
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +20 -171
- package/packageExports.test.ts +38 -24
- package/quality/dictionaryKeys.test.ts +356 -0
- package/quality/dictionaryKeys.ts +488 -0
- package/quality/objectImportReport.test.ts +36 -0
- package/quality/objectImportReport.ts +105 -0
- package/quality/qualityScanner.ts +1 -1
- package/quality/routeRuntimeReport.test.ts +91 -0
- package/quality/routeRuntimeReport.ts +121 -0
- package/quality/runtimeConstantFacts.ts +71 -0
- package/quality/runtimeConstantGraph.ts +123 -0
- package/quality/runtimeConstantReads.ts +116 -0
- package/quality/runtimeImports.test.ts +190 -0
- package/quality/runtimeImports.ts +233 -0
- package/quality/runtimeKeyNames.ts +46 -0
- package/quality/runtimeLexicalScope.ts +132 -0
- package/quality/runtimeMarkerReach.test.ts +84 -0
- package/quality/runtimeMarkerReach.ts +255 -0
- package/quality/runtimeModuleFacts.ts +290 -0
- package/quality/runtimeNameTable.test.ts +172 -0
- package/quality/runtimeNameTable.ts +477 -0
- package/quality/runtimeScopeReport.test.ts +123 -0
- package/quality/runtimeScopeReport.ts +167 -0
- package/quality/runtimeSliceKey.ts +269 -0
- package/quality/runtimeSyntax.ts +133 -0
- package/quality/runtimeTable.fixture.ts +189 -0
- package/quality/runtimeUse.test.ts +737 -0
- package/quality/runtimeUse.ts +696 -0
- package/quality/runtimeUseReadable.test.ts +393 -0
- package/quality/ssrScanner.test.ts +13 -0
- package/quality/ssrScanner.ts +1 -1
- package/quality/translatorBindings.ts +187 -0
- package/test/secretEnvFixture.ts +134 -0
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +26 -4
- package/transforms/barrelImportsPlugin.ts +121 -32
- package/transforms/exportReach.test.ts +162 -0
- package/transforms/exportReach.ts +308 -0
- package/transforms/frameworkObjects.fixture.tsx +58 -0
- package/transforms/frameworkObjects.test.ts +54 -0
- package/transforms/modelReference.test.ts +196 -0
- package/transforms/modelReference.ts +39 -0
- package/transforms/moduleParts.test.ts +225 -0
- package/transforms/moduleParts.ts +418 -0
- package/transforms/objectImportEdits.ts +150 -0
- package/transforms/objectMemberImports.test.ts +633 -0
- package/transforms/objectMemberImports.ts +571 -0
- package/transforms/objectMemberLookup.ts +150 -0
- package/transforms/objectModule.test.ts +307 -0
- package/transforms/objectModule.ts +482 -0
- package/transforms/objectModuleAnalyzer.ts +104 -0
- package/transforms/partImports.test.ts +76 -0
- package/transforms/partImports.ts +110 -0
- package/transforms/partModules.test.ts +187 -0
- package/transforms/partModules.ts +90 -0
- package/transforms/partPurity.ts +124 -0
- package/transforms/reactIconImports.test.ts +231 -0
- package/transforms/reactIconImports.ts +325 -0
- package/transforms/routeConstants.ts +122 -0
- package/transforms/routeRuntime.test.ts +835 -0
- package/transforms/routeRuntime.ts +703 -0
- package/transforms/routeRuntimeEdits.ts +92 -0
- package/transforms/routeRuntimeGraph.ts +66 -0
- package/transforms/routeRuntimePlan.ts +244 -0
- package/transforms/secretEnvDeclaration.test.ts +208 -0
- package/transforms/secretEnvDeclaration.ts +213 -0
- package/transforms/secretEnvFile.test.ts +117 -0
- package/transforms/secretEnvFile.ts +113 -0
- package/transforms/secretEnvName.test.ts +54 -0
- package/transforms/secretEnvName.ts +29 -0
- package/transforms/secretEnvSource.test.ts +148 -0
- package/transforms/secretEnvSource.ts +166 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +2 -1
- package/transforms/serverEnvPlugin.ts +13 -0
- package/transforms/serverEnvProfile.test.ts +129 -2
- package/transforms/serverEnvProfile.ts +126 -40
- package/transforms/serverEnvSecrets.test.ts +292 -0
- package/transforms/signalDescriptors.test.ts +280 -0
- package/transforms/signalDescriptors.ts +227 -0
- package/transforms/thisFreeExports.ts +87 -0
- package/transforms/transforms.test.ts +180 -3
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
- package/tunnel/createTunnel.test.ts +29 -8
- package/tunnel/createTunnel.ts +22 -11
- package/tunnel/ssh2Module.test.ts +37 -0
- package/tunnel/ssh2Module.ts +32 -0
- package/tunnel/sshTunnel.ts +4 -2
- package/typecheck/projectTypecheck.test.ts +32 -1
- package/typecheck/projectTypecheck.ts +3 -3
- package/typecheck/typeChecker.test.ts +49 -0
- package/typecheck/typeChecker.ts +9 -7
- package/typecheck/withheldDiagnostics.ts +41 -0
- package/util/fileEditor.ts +1 -0
- package/util/selectModel.ts +1 -0
- package/workflow/executor.ts +6 -2
- package/workflow/index.ts +1 -0
- package/workflow/plan.ts +36 -7
- package/workflow/types.ts +1 -1
- package/workflow/uiTarget.ts +50 -0
- package/workspace/envSeed.test.ts +30 -1
- package/workspace/envSeed.ts +30 -1
- package/workspace/getRelatedCnsts.ts +7 -0
- package/workspace/mainCheckout.test.ts +55 -0
- package/workspace/mainCheckout.ts +38 -0
- package/workspace/scanInfo.test.ts +39 -0
- package/workspace/scanInfo.ts +55 -6
- package/workspace/slicePlanner.ts +1 -1
- package/workspace/workspaceLayout.test.ts +5 -1
- package/workspace/workspaceLayout.ts +3 -0
- package/CHANGELOG.md +0 -2717
|
@@ -5,35 +5,28 @@ description: "Write filters, slices and list loading: query descriptors, init pa
|
|
|
5
5
|
|
|
6
6
|
# Akan queries and slices
|
|
7
7
|
|
|
8
|
+
The `module` rule, loaded with every `lib/` file, holds the musts: a slice returns a query, at most 500 rows, soft
|
|
9
|
+
removal and `purge`, the hookless `updateById` / `removeById`, secret projections, the cascade direction and when a
|
|
10
|
+
search slice is safe. This skill adds what it does not say.
|
|
11
|
+
|
|
8
12
|
## Filters and slices
|
|
9
13
|
|
|
10
|
-
- A filter in `<model>.document.ts` declares its args; a slice in `<model>.signal.ts` serves it to stores.
|
|
11
|
-
`
|
|
12
|
-
limit on it.
|
|
14
|
+
- A filter in `<model>.document.ts` declares its args; a slice in `<model>.signal.ts` serves it to stores. The
|
|
15
|
+
`query<Filter>(…)` descriptor a slice returns takes no chained sort or limit.
|
|
13
16
|
- Page through the store: `initX(…, { sort, page, limit })`, then `st.do.loadMoreOf<Model>()` while
|
|
14
17
|
`hasMoreOf<Model>`. Never compare `count > page * limit`.
|
|
15
|
-
-
|
|
16
|
-
A figure over the whole set belongs in an insight or an endpoint.
|
|
17
|
-
- The root slice takes a filter name and its args, never a raw query, and its `root:` guard is always `Admin`.
|
|
18
|
+
- The root slice takes a filter name and its args, never a raw query.
|
|
18
19
|
- No value is `q.empty`, never `q.missing`.
|
|
19
|
-
- A projection is bare on the facade (`pickById(id, { secret: true })`) and under `select` on a filter accessor —
|
|
20
|
-
the only way to read a `field.secret` value.
|
|
21
20
|
|
|
22
|
-
## Writes
|
|
21
|
+
## Writes
|
|
23
22
|
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
cascade or `_postRemove` removes through `remove<Model>(id)`.
|
|
28
|
-
- Load a set once (`load<Model>Many`, one filter query) and create one with `create<Model>Many(rows)` instead of one
|
|
29
|
-
call per item in a loop — lint fails a per-item service call an endpoint reaches. `create<Model>Many` runs every
|
|
30
|
-
row's `_preCreate` before writing any, so a check there does not see the batch's own rows.
|
|
23
|
+
- A filter's `update*` runs no hooks and no cascade, like its `remove*`.
|
|
24
|
+
- `create<Model>Many(rows)` runs every row's `_preCreate` before writing any, so a check there does not see the
|
|
25
|
+
batch's own rows.
|
|
31
26
|
|
|
32
|
-
## Search
|
|
27
|
+
## Search
|
|
33
28
|
|
|
34
29
|
- `q.search(text, { prefix: true })` sits in a filter at an AND position, over fields with the `text` role. Blank
|
|
35
|
-
input matches nothing — never a passthrough.
|
|
36
|
-
- `cascade` names a direction, and the wrong one loses data: `removeRef` on the owner's relation, `removeWith` on
|
|
37
|
-
the child's reference to its owner.
|
|
30
|
+
input matches nothing — never a passthrough.
|
|
38
31
|
|
|
39
32
|
Full detail: `get_guideline` with `queryRule`, and `workspaceRecipes` for a worked slice.
|
|
@@ -15,9 +15,10 @@ the agent guide's Path Rules table.
|
|
|
15
15
|
| --- | --- |
|
|
16
16
|
| API only, or no CSR bundle for native apps | `web: false`, `web: { csr: false }` |
|
|
17
17
|
| Move the API or websocket mount | `new AkanApp({ prefix, websocketPrefix })` in `main.ts`, mirrored in `api: { … }`; read with `getApiPrefix()` / `getWsPrefix()` |
|
|
18
|
-
| The production image | `docker: string \| { image, preRuns, postRuns, command }` |
|
|
18
|
+
| The production image | `docker: string \| { image, preRuns, installRuns, postRuns, command, crossBuild, env, variants }` |
|
|
19
19
|
| iOS, Android, desktop | the `native` section; `desktop: { server: true }` carries the server |
|
|
20
20
|
| SQLite, several databases, a cluster | `database: { modes: [...] }` (`single`, `multiple`, `cluster`), picked by `AKAN_DATABASE_MODE` |
|
|
21
|
+
| A secret of `env/env.server.<env>.ts` in a deployed server | nothing to declare: `akan build` leaves it out and the server reads it from a variable named after its key path; `akan secret-env <app> --env <env>` lists them |
|
|
21
22
|
| URLs without `/<locale>/`: one language, or paths fixed from outside (OAuth callback, QR code, mail link) | `i18n: { localePrefix: "as-needed" }` — the default locale's pages and `<Link>` hrefs drop the prefix, other locales keep it |
|
|
22
23
|
|
|
23
24
|
## Running and logs
|
|
@@ -28,6 +29,25 @@ the agent guide's Path Rules table.
|
|
|
28
29
|
- Run a build without Docker with `cd dist/apps/<app> && bun main.js`: it boots with the env the Dockerfile sets,
|
|
29
30
|
read from `akan.env.json` beside it, and a variable you set yourself (`PORT=3000`) wins.
|
|
30
31
|
|
|
32
|
+
## Secrets in a deployed server
|
|
33
|
+
|
|
34
|
+
- Write secrets in `env/env.server.<env>.ts` as before. `akan build` replaces each string under a secret-named key,
|
|
35
|
+
and each URL carrying a password, with a read of an environment variable: `security.sso.google.clientSecret` is
|
|
36
|
+
`SECURITY__SSO__GOOGLE__CLIENT_SECRET`, an array holding a secret is one JSON variable, `security.jwtSecret` is
|
|
37
|
+
`JWT_SECRET`. The built files hold the names (`AKAN_ENV_NAMES` in `akan.env.json`), never the values.
|
|
38
|
+
- `akan secret-env <app> --env <env>` prints the variables, never a value. `--out <file> --format k8s --name <name>`
|
|
39
|
+
writes a Kubernetes Secret for `envFrom`, `--format dotenv` a file for `bun --env-file`. Never write it
|
|
40
|
+
under `dist/` or a tracked path, and delete it once applied.
|
|
41
|
+
- At boot a variable left unset is one warning naming it. The framework does not stop for it, though whatever reads the value may; 3.5.0 will refuse to boot.
|
|
42
|
+
- A secret the env file computes or imports stops the build, whatever its length: write the string at the key, or
|
|
43
|
+
`process.env.<NAME>` there, which the build leaves as that read. A secret string a plain key or the app's code
|
|
44
|
+
holds as well stops it too when long and mixed, and is a warning when short. A key the name rule misses
|
|
45
|
+
(`stripeKey`) stays in the image unless read from `process.env`.
|
|
46
|
+
- The build loads the env file to list the secrets, with the shell's variables only when it cannot load without
|
|
47
|
+
them; a file that throws as it loads stops the build by error class and line.
|
|
48
|
+
- `akan start`, `akan test`, `akan build --profile …` and desktop and mobile builds read the env file as written.
|
|
49
|
+
`akan build --inline-secrets` keeps the values in the image for one release, for a deployment not ready yet.
|
|
50
|
+
|
|
31
51
|
## Native and desktop
|
|
32
52
|
|
|
33
53
|
A `start-*` command loads its pages from a running `akan start`; a desktop app carrying its server starts it itself.
|
|
@@ -15,9 +15,8 @@ dictionary is a `serviceDictionary`.
|
|
|
15
15
|
- Read the module's `*.abstract.md` **before** changing it — it states the invariants the code cannot show.
|
|
16
16
|
Update it when an invariant, workflow, or public behaviour changes; not for formatting or imports.
|
|
17
17
|
- Keep the public surface in the signal layer and the decisions in the service.
|
|
18
|
-
- Service methods stay a few lines: load → chain → `return await ….save()`.
|
|
19
|
-
|
|
20
|
-
explicitly `void`-ed.
|
|
18
|
+
- Service methods stay a few lines: load → chain → `return await ….save()`. Side effects belong in
|
|
19
|
+
`_preUpdate` / `_postCreate`, not inline. Fire-and-forget is explicitly `void`-ed.
|
|
21
20
|
- Return `null` / `false` for "not allowed" or "not found" and let the signal decide whether that is an
|
|
22
21
|
error.
|
|
23
22
|
- `serve(name, { serverMode: "batch" }, …)` mounts the module, endpoints included, only in a `batch` or `all`
|
|
@@ -29,11 +28,8 @@ dictionary is a `serviceDictionary`.
|
|
|
29
28
|
|
|
30
29
|
Inside a service, in preference order: `service<srv.XService>()` for another module's service,
|
|
31
30
|
`plug(AdapterClass)` for an adapter, `use<T>()` only for an `option.ts`-registered legacy singleton, and
|
|
32
|
-
`env(...)` for config. Injection resolves by field name
|
|
33
|
-
registered under `<refName
|
|
34
|
-
|
|
35
|
-
An external API or piece of infrastructure is an `adapt()` class in `srvkit/`, injected with `plug`. It
|
|
36
|
-
self-registers, so do **not** add it to `lib/option.ts`.
|
|
31
|
+
`env(...)` for config. Injection resolves by field name: a field named `<refName>Service` finds the service
|
|
32
|
+
registered under `<refName>`. The adapter's place and the field-name suffix are the `server` rule.
|
|
37
33
|
|
|
38
34
|
## Recipe: pages backed by an external HTTP API
|
|
39
35
|
|
|
@@ -74,7 +70,7 @@ export class OpenlibraryService extends serve("openlibrary" as const, ({ plug })
|
|
|
74
70
|
}
|
|
75
71
|
}
|
|
76
72
|
|
|
77
|
-
// lib/_openlibrary/openlibrary.signal.ts — Any answers plain JSON
|
|
73
|
+
// lib/_openlibrary/openlibrary.signal.ts — Any answers plain JSON
|
|
78
74
|
import { Any } from "akanjs/base";
|
|
79
75
|
import { endpoint, internal, Public } from "akanjs/signal";
|
|
80
76
|
|
|
@@ -106,5 +102,8 @@ The page calls it as `await fetch.book(id)` (`fetch` from `@apps/<app>/client`)
|
|
|
106
102
|
`common/`, or return a scalar (`akan create-scalar`) for a typed wire shape. A query that answers `null` without
|
|
107
103
|
`nullable: true` fails the render, naming the endpoint.
|
|
108
104
|
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
The adapter turns every failure into `null`, a not-found page. One the page must show as an error throws
|
|
106
|
+
`new Err("<app>.error.<key>")`, `Err` from `"../lib/dict"` and the key in `lib/_<app>/<app>.dictionary.ts`'s
|
|
107
|
+
`.error({})`; `new Error` fails the build (`no-throw-raw-error`).
|
|
108
|
+
|
|
109
|
+
The signatures of serve, adapt, endpoint and serviceDictionary, and every import path: the `akanApi-*` references.
|
|
@@ -7,21 +7,14 @@ description: "Guard and tune endpoints on the wire: writing a Can<Verb><Model> g
|
|
|
7
7
|
|
|
8
8
|
## Guards
|
|
9
9
|
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
must work signed out (sign-up, sign-in, token refresh, an OAuth route), which also declares a `rateLimit`.
|
|
10
|
+
- Which guards each endpoint and slice names, `Public`, `static scope`, `static name`, the acting user and the
|
|
11
|
+
service's second check are the `auth` rule, loaded with every `signal.ts` and `srvkit/` file.
|
|
13
12
|
- A resource guard is a `Can<Verb><Model>` class in the model library's `srvkit/guards.ts` that fails closed:
|
|
14
13
|
no resource named, or a load that throws, is `false` (after a `logger.warn`). Admin bypass goes first.
|
|
15
|
-
- Every guard declares `static scope`: `"account"` reads only the caller (`SignedIn`, `Admin`, roles), and
|
|
16
|
-
`"resource"` needs the call's arguments (every `Can<Verb><Model>`). Keep `static name = "User";` with a comment.
|
|
17
|
-
- Guards read `context.get<T>("account")`, serve HTTP and websocket alike, and stay side-effect free. The acting
|
|
18
|
-
user comes from `.with(Self)` / `.with(CurrentUserId)` / `.with(Me)`, the address from `.with(Ip)` — never a
|
|
19
|
-
client-supplied id. The service re-checks ownership: two independent gates.
|
|
20
14
|
|
|
21
15
|
## Endpoint options
|
|
22
16
|
|
|
23
|
-
- `{ timeout: <ms> }` is the deadline on both ends
|
|
24
|
-
cancelled.
|
|
17
|
+
- `{ timeout: <ms> }` is the deadline on both ends.
|
|
25
18
|
- `{ cache }` only on a `query` with no internal argument, capped at one day; `invalidate(endpoint, args?)` drops
|
|
26
19
|
it early through a plugged `EndpointCacheControl`.
|
|
27
20
|
- `{ rateLimit: { calls, windowMs?, by? } }` per endpoint, `option.setRateLimit` per app, `plug(RateLimit)` for a
|
|
@@ -34,9 +27,7 @@ description: "Guard and tune endpoints on the wire: writing a Can<Verb><Model> g
|
|
|
34
27
|
|
|
35
28
|
## Bodies and other servers
|
|
36
29
|
|
|
37
|
-
- `.body()` / `.param()` take scalars, model refs or `enumOf(...)`;
|
|
38
|
-
|
|
39
|
-
- Server to server, `fetch.clone({ origin })` opens no socket without `connect: true`, retries through `retry`,
|
|
40
|
-
and rethrows a remote `Err` as it is — never wrap or re-key it.
|
|
30
|
+
- `.body()` / `.param()` take scalars, model refs or `enumOf(...)`; the types they refuse are the `server` rule.
|
|
31
|
+
- Server to server, `fetch.clone({ origin })` opens no socket without `connect: true` and retries through `retry`.
|
|
41
32
|
|
|
42
33
|
Full detail: `get_guideline` with `transportRule`, or `mcpRule` for what a guard's scope does to an MCP listing.
|
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: akan-ui
|
|
3
|
-
description: "
|
|
3
|
+
description: "A module's components: the Unit/View vs Template/Zone/Util split, forms, and what never to hand-roll. A page or a model-free ui/ component needs only the ssr, style and tsx rules."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Akan UI
|
|
7
7
|
|
|
8
|
-
A
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## The boundary is mechanical, not a judgement call
|
|
12
|
-
|
|
13
|
-
| role | side | directive |
|
|
14
|
-
| --- | --- | --- |
|
|
15
|
-
| `<Model>.Unit.tsx`, `<Model>.View.tsx` | server | never `"use client"` |
|
|
16
|
-
| `<Model>.Template.tsx`, `<Model>.Zone.tsx`, `<Model>.Util.tsx` | client | `"use client"` on line 1 |
|
|
17
|
-
| `page/**` | server | never |
|
|
8
|
+
A page, or a `ui/` component bound to no model, needs nothing more from here: the `ssr`, `style` and `tsx` rules
|
|
9
|
+
loaded with the file are its contract. The rest is for a module's own components, lists and forms.
|
|
18
10
|
|
|
19
11
|
**Server is the default and `"use client"` is a cost you justify per component.** A component earns the
|
|
20
12
|
directive only by using a hook, a JSX event handler, the store, a browser global, or a client-only package.
|
|
21
|
-
Rendering markup, reading a param, calling `l()`, and mapping over data are all server work.
|
|
22
|
-
`akan quality ssr`; treat 50% server share as the floor and a falling share as a regression.
|
|
13
|
+
Rendering markup, reading a param, calling `l()`, and mapping over data are all server work.
|
|
23
14
|
|
|
24
15
|
Four moves that keep markup on the server: wrap the interaction and render `children` untouched; split a
|
|
25
16
|
compound component so only the provider holds state; fetch in the route and pass the result into a `Zone` as
|
|
26
17
|
an `init` prop; push the boundary down to the leaf that needs it.
|
|
27
18
|
|
|
19
|
+
## A module's components
|
|
20
|
+
|
|
21
|
+
A new View / Unit / Template / Zone / Util for an existing module comes from the `create-ui` workflow (the
|
|
22
|
+
`akan-scaffold` skill). Edit the scaffolded component instead of authoring one from scratch. The boundary is
|
|
23
|
+
mechanical by role, not a judgement call:
|
|
24
|
+
|
|
25
|
+
| role | side | directive |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| `<Model>.Unit.tsx`, `<Model>.View.tsx` | server | never `"use client"` |
|
|
28
|
+
| `<Model>.Template.tsx`, `<Model>.Zone.tsx`, `<Model>.Util.tsx` | client | `"use client"` on line 1 |
|
|
29
|
+
| `page/**` | server | never |
|
|
30
|
+
|
|
28
31
|
## Never hand-roll these
|
|
29
32
|
|
|
30
33
|
- loading / empty / list states → `Load.Units` / `Load.View` / `Load.Edit` with `renderItem`, `renderList`,
|
|
@@ -45,14 +48,6 @@ an `init` prop; push the boundary down to the leaf that needs it.
|
|
|
45
48
|
Conditional render is `cond ? <X/> : null`. **Never `{cond && <X/>}`** — in a `className` context it renders
|
|
46
49
|
the literal string `"false"`.
|
|
47
50
|
|
|
48
|
-
## Classes
|
|
49
|
-
|
|
50
|
-
Never hand-order Tailwind classes; the formatter sorts them and its output is correct. Stay inside the
|
|
51
|
-
semantic token vocabulary — `bg-primary`, `text-foreground/70` — because a raw palette class (`bg-blue-500`),
|
|
52
|
-
an arbitrary colour (`bg-[#3b82f6]`), a daisyUI legacy class, and a colour literal in `style={{…}}` all
|
|
53
|
-
render no CSS and fail lint. Reach for `cn` only for a conditional or to merge an incoming `className`, and
|
|
54
|
-
merge the caller last.
|
|
55
|
-
|
|
56
51
|
## Forms
|
|
57
52
|
|
|
58
53
|
Store-driven end to end: `value={xForm.field}` with `onChange={st.do.setFieldOnX}`, **the setter passed by
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
import { camelToKebabCase } from "./camelToKebabCase";
|
|
34
34
|
import { CliError, type CliErrorCode } from "./cliError";
|
|
35
35
|
import { CommandContainer } from "./dependencyBuilder";
|
|
36
|
-
import { formatCommandHelp, formatHelp } from "./helpFormatter";
|
|
36
|
+
import { formatCommandHelp, formatHelp, usageArgsOf } from "./helpFormatter";
|
|
37
37
|
import {
|
|
38
38
|
type CommandCls,
|
|
39
39
|
getTargetCommandNames,
|
|
@@ -88,13 +88,17 @@ const failureReporterOf =
|
|
|
88
88
|
|
|
89
89
|
//? commander refuses a flag, an argument or a command before any action runs, having printed why to stderr.
|
|
90
90
|
//? Thrown, not exited: the failure path awaits onFailure, and an exit drops what a pipe still buffers.
|
|
91
|
-
const usageRefusalOf = (error: CommanderError) => {
|
|
91
|
+
const usageRefusalOf = (error: CommanderError, hint = "") => {
|
|
92
92
|
if (error.exitCode === 0) process.exit(0);
|
|
93
|
-
|
|
93
|
+
if (hint) process.stderr.write(`${hint}\n`);
|
|
94
|
+
const refused = new CliError("usage", `${error.message.replace(/^error: /, "")}${hint ? ` ${hint}` : ""}`);
|
|
94
95
|
loggedCliErrorObjects.add(refused);
|
|
95
96
|
return refused;
|
|
96
97
|
};
|
|
97
98
|
|
|
99
|
+
export const excessArgumentHintOf = (commandName: string, argMetas: (ArgMeta | InternalArgMeta)[]) =>
|
|
100
|
+
`\`akan ${commandName}\` takes ${usageArgsOf(argMetas).join(" ") || "no argument"}: see \`akan ${commandName} --help\`.`;
|
|
101
|
+
|
|
98
102
|
const handleOption = (programCommand: Command, argMeta: ArgMeta) => {
|
|
99
103
|
const {
|
|
100
104
|
type,
|
|
@@ -118,7 +122,7 @@ const handleOption = (programCommand: Command, argMeta: ArgMeta) => {
|
|
|
118
122
|
const handleArgument = (programCommand: Command, argMeta: ArgMeta) => {
|
|
119
123
|
const kebabName = camelToKebabCase(argMeta.name);
|
|
120
124
|
programCommand.argument(
|
|
121
|
-
`[${kebabName}]`,
|
|
125
|
+
`[${kebabName}${argMeta.argsOption.multiple ? "..." : ""}]`,
|
|
122
126
|
`${argMeta.argsOption.desc}${argMeta.argsOption.example ? ` (example: ${argMeta.argsOption.example})` : ""}`,
|
|
123
127
|
);
|
|
124
128
|
return programCommand;
|
|
@@ -257,11 +261,17 @@ export const getOptionValue = async (argMeta: ArgMeta, opt: Record<string, unkno
|
|
|
257
261
|
} else return convertArgValue(await input({ message: inputMessageOf(argMeta) }), type ?? "string");
|
|
258
262
|
};
|
|
259
263
|
|
|
260
|
-
export const getArgumentValue = async (argMeta: ArgMeta, value: string | undefined) => {
|
|
264
|
+
export const getArgumentValue = async (argMeta: ArgMeta, value: string | string[] | undefined) => {
|
|
261
265
|
const { default: defaultValue, type, nullable } = argMeta.argsOption;
|
|
262
|
-
if (
|
|
263
|
-
|
|
264
|
-
|
|
266
|
+
if (argMeta.argsOption.multiple) {
|
|
267
|
+
const values = operandListOf(value);
|
|
268
|
+
for (const each of values) assertEnumChoice(argMeta, each);
|
|
269
|
+
return values.map((each) => convertArgValue(each, type ?? "string"));
|
|
270
|
+
}
|
|
271
|
+
const given = Array.isArray(value) ? value[0] : value;
|
|
272
|
+
if (given !== undefined) {
|
|
273
|
+
assertEnumChoice(argMeta, given);
|
|
274
|
+
return convertArgValue(given, type ?? "string");
|
|
265
275
|
} else if (defaultValue !== undefined) return defaultValue;
|
|
266
276
|
else if (nullable) return null;
|
|
267
277
|
const { enum: enumChoices } = argMeta.argsOption;
|
|
@@ -326,7 +336,7 @@ export const rerunCommandOf =
|
|
|
326
336
|
const rerunRemedyOf = (rerun: RerunOf | undefined, placeholder: string) =>
|
|
327
337
|
rerun ? { remedy: `rerun it as \`${rerun(placeholder)}\`` } : {};
|
|
328
338
|
|
|
329
|
-
const
|
|
339
|
+
const operandListOf = (value: string | string[] | undefined): string[] =>
|
|
330
340
|
(Array.isArray(value) ? value : value === undefined ? [] : [value])
|
|
331
341
|
.flatMap((entry) => entry.split(","))
|
|
332
342
|
.map((entry) => entry.trim())
|
|
@@ -340,7 +350,7 @@ export const getAppsArgumentValue = async (
|
|
|
340
350
|
): Promise<AppExecutor[]> => {
|
|
341
351
|
const appNames = await workspace.getApps();
|
|
342
352
|
if (appNames.length === 0) throw new Error("No apps found in this workspace (apps/<appName>/akan.config.ts)");
|
|
343
|
-
const requested =
|
|
353
|
+
const requested = operandListOf(value);
|
|
344
354
|
if (requested.includes("all")) return appNames.map((name) => AppExecutor.from(workspace, name));
|
|
345
355
|
if (requested.length) {
|
|
346
356
|
const unknown = requested.filter((name) => !appNames.includes(name));
|
|
@@ -549,7 +559,10 @@ export const runCommands = async (...commands: CommandCls[]) => {
|
|
|
549
559
|
const { onFailure } = targetMeta.targetOption;
|
|
550
560
|
const [allArgMetas] = getArgMetas(command, targetMeta.key);
|
|
551
561
|
programCommand.exitOverride((error) => {
|
|
552
|
-
const refused = usageRefusalOf(
|
|
562
|
+
const refused = usageRefusalOf(
|
|
563
|
+
error,
|
|
564
|
+
error.code === "commander.excessArguments" ? excessArgumentHintOf(commandName, allArgMetas) : "",
|
|
565
|
+
);
|
|
553
566
|
failure.usageExitCode = targetUsageExitCode;
|
|
554
567
|
const given = givenOptionsOf(allArgMetas, programCommand.opts());
|
|
555
568
|
failure.report = failureReporterOf(asksJson(allArgMetas, given), onFailure, { usage: true, given });
|
|
@@ -607,7 +620,10 @@ export const runCommands = async (...commands: CommandCls[]) => {
|
|
|
607
620
|
if (argMeta.type === "Option")
|
|
608
621
|
commandArgs[argMeta.idx] = await getOptionValue(argMeta, opt, commandContext);
|
|
609
622
|
else if (argMeta.type === "Argument")
|
|
610
|
-
commandArgs[argMeta.idx] = await getArgumentValue(
|
|
623
|
+
commandArgs[argMeta.idx] = await getArgumentValue(
|
|
624
|
+
argMeta,
|
|
625
|
+
cmdArgs[argMeta.idx] as string | string[] | undefined,
|
|
626
|
+
);
|
|
611
627
|
else if (argMeta.type === "Apps")
|
|
612
628
|
commandArgs[argMeta.idx] = await getAppsArgumentValue(
|
|
613
629
|
cmdArgs[argMeta.idx] as string | string[] | undefined,
|
|
@@ -82,10 +82,16 @@ const argMetaOf = (
|
|
|
82
82
|
argsOption: Pick<ArgsOption, "multiple"> | undefined,
|
|
83
83
|
idx: number,
|
|
84
84
|
): ArgMeta => {
|
|
85
|
-
if (type === "Argument" && argsOption?.multiple) throw new Error(`argument '${name}' cannot be multiple`);
|
|
86
85
|
return { name, argsOption: { ...argsOption, type: normalizePrimitiveArgType(primitive) }, key: "", idx, type };
|
|
87
86
|
};
|
|
88
87
|
|
|
88
|
+
//? commander gives a variadic argument every word left on the line, and throws for one declared before another.
|
|
89
|
+
const assertListArgumentIsLast = (args: (ArgMeta | InternalArgMeta)[]) => {
|
|
90
|
+
const positionals = args.filter((arg) => arg.type !== "Option" && arg.type !== "Workspace");
|
|
91
|
+
const list = positionals.slice(0, -1).find((arg) => arg.type === "Argument" && arg.argsOption.multiple);
|
|
92
|
+
if (list?.type === "Argument") throw new Error(`argument '${list.name}' takes a list, so it must be declared last`);
|
|
93
|
+
};
|
|
94
|
+
|
|
89
95
|
class TargetBuilder<Deps extends readonly DependencyCls[], Params extends unknown[] = [], Context = object> {
|
|
90
96
|
readonly #args: (ArgMeta | InternalArgMeta)[];
|
|
91
97
|
|
|
@@ -128,6 +134,7 @@ class TargetBuilder<Deps extends readonly DependencyCls[], Params extends unknow
|
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
exec(handler: CommandHandler<Deps, Params>) {
|
|
137
|
+
assertListArgumentIsLast(this.#args);
|
|
131
138
|
return {
|
|
132
139
|
args: this.#args,
|
|
133
140
|
handler: handler as TargetMeta["handler"],
|
|
@@ -1058,7 +1058,7 @@ describe("a repeatable option", () => {
|
|
|
1058
1058
|
);
|
|
1059
1059
|
});
|
|
1060
1060
|
|
|
1061
|
-
test("types the exec parameter as a list, and a
|
|
1061
|
+
test("types the exec parameter as a list, and a list argument must be the last positional", () => {
|
|
1062
1062
|
const expectType = <Expected>(_value: Expected) => undefined;
|
|
1063
1063
|
class RepeatRunner extends runner("repeat") {}
|
|
1064
1064
|
class RepeatScript extends script("repeat", [RepeatRunner]) {}
|
|
@@ -1072,13 +1072,37 @@ describe("a repeatable option", () => {
|
|
|
1072
1072
|
}),
|
|
1073
1073
|
})) {}
|
|
1074
1074
|
expect(getTargetMetas(RepeatCommand)[0]?.key).toBe("run");
|
|
1075
|
+
class ListCommand extends command("list", [RepeatScript], ({ public: target }) => ({
|
|
1076
|
+
run: target({ desc: "run" })
|
|
1077
|
+
.arg("action", String)
|
|
1078
|
+
.arg("names", String, { multiple: true })
|
|
1079
|
+
.option("force", Boolean)
|
|
1080
|
+
.exec(async (action, names) => {
|
|
1081
|
+
expectType<string>(action);
|
|
1082
|
+
expectType<string[]>(names);
|
|
1083
|
+
}),
|
|
1084
|
+
})) {}
|
|
1085
|
+
expect(stripAnsi(formatCommandHelp(ListCommand, "run"))).toContain("akan run [action] [names...]");
|
|
1075
1086
|
expect(() =>
|
|
1076
|
-
command("
|
|
1087
|
+
command("listFirst", [RepeatScript], ({ public: target }) => ({
|
|
1077
1088
|
run: target({ desc: "run" })
|
|
1078
1089
|
.arg("names", String, { multiple: true })
|
|
1090
|
+
.arg("action", String)
|
|
1079
1091
|
.exec(async () => undefined),
|
|
1080
1092
|
})),
|
|
1081
|
-
).toThrow("argument 'names'
|
|
1093
|
+
).toThrow("argument 'names' takes a list, so it must be declared last");
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
test("a list argument reads its words space- or comma-separated, each against the choices, and none as empty", async () => {
|
|
1097
|
+
const names: ArgMeta = { ...meta, name: "names", type: "Argument" };
|
|
1098
|
+
expect(await getArgumentValue(names, ["a.test.ts", "b.test.ts,c.test.ts", " "])).toEqual([
|
|
1099
|
+
"a.test.ts",
|
|
1100
|
+
"b.test.ts",
|
|
1101
|
+
"c.test.ts",
|
|
1102
|
+
]);
|
|
1103
|
+
expect(await getArgumentValue(names, undefined)).toEqual([]);
|
|
1104
|
+
const choices = { ...names, argsOption: { ...names.argsOption, enum: ["a", "b"] } };
|
|
1105
|
+
await expect(getArgumentValue(choices, ["a", "c"])).rejects.toThrow("argument 'names' argument 'c' is invalid");
|
|
1082
1106
|
});
|
|
1083
1107
|
|
|
1084
1108
|
test("collects each time the flag is given, long or short", async () => {
|
|
@@ -1098,6 +1122,17 @@ describe("a repeatable option", () => {
|
|
|
1098
1122
|
" .exec(async function (param) {",
|
|
1099
1123
|
" process.stdout.write(JSON.stringify(param));",
|
|
1100
1124
|
" }),",
|
|
1125
|
+
' gather: target({ desc: "gathers", stdio: true })',
|
|
1126
|
+
' .arg("action", String)',
|
|
1127
|
+
' .arg("files", String, { multiple: true })',
|
|
1128
|
+
" .exec(async function (action, files) {",
|
|
1129
|
+
" process.stdout.write(JSON.stringify([action, files]));",
|
|
1130
|
+
" }),",
|
|
1131
|
+
' single: target({ desc: "takes one", stdio: true })',
|
|
1132
|
+
' .arg("action", String, { nullable: true })',
|
|
1133
|
+
' .option("format", String, { default: "text", enum: ["text", "json"] })',
|
|
1134
|
+
" .exec(async function () {}),",
|
|
1135
|
+
' bare: target({ desc: "takes none", stdio: true }).exec(async function () {}),',
|
|
1101
1136
|
"})) {}",
|
|
1102
1137
|
"await runCommands(CollectCommand);",
|
|
1103
1138
|
"",
|
|
@@ -1110,6 +1145,38 @@ describe("a repeatable option", () => {
|
|
|
1110
1145
|
};
|
|
1111
1146
|
expect(await collect("--param", "a=1", "-p", "b=x=y")).toEqual(["a=1", "b=x=y"]);
|
|
1112
1147
|
expect(await collect()).toEqual([]);
|
|
1148
|
+
|
|
1149
|
+
const run = async (...args: string[]) => {
|
|
1150
|
+
const proc = Bun.spawn(["bun", entry, ...args], { cwd: root, stdout: "pipe", stderr: "pipe" });
|
|
1151
|
+
const [stdout, stderr, code] = await Promise.all([
|
|
1152
|
+
new Response(proc.stdout).text(),
|
|
1153
|
+
new Response(proc.stderr).text(),
|
|
1154
|
+
proc.exited,
|
|
1155
|
+
]);
|
|
1156
|
+
return { stdout, stderr, code };
|
|
1157
|
+
};
|
|
1158
|
+
expect((await run("gather", "scan", "a.test.ts", "b.test.ts,c.test.ts")).stdout).toBe(
|
|
1159
|
+
'["scan",["a.test.ts","b.test.ts","c.test.ts"]]',
|
|
1160
|
+
);
|
|
1161
|
+
expect((await run("gather", "scan")).stdout).toBe('["scan",[]]');
|
|
1162
|
+
|
|
1163
|
+
const excess = await run("single", "scan", "web");
|
|
1164
|
+
expect(excess.code).toBe(2);
|
|
1165
|
+
expect(excess.stderr).toBe(
|
|
1166
|
+
[
|
|
1167
|
+
"error: too many arguments for 'single'. Expected 1 argument but got 2: scan, web.",
|
|
1168
|
+
"`akan single` takes [action]: see `akan single --help`.",
|
|
1169
|
+
"",
|
|
1170
|
+
].join("\n"),
|
|
1171
|
+
);
|
|
1172
|
+
const excessJson = await run("single", "scan", "web", "--format", "json");
|
|
1173
|
+
expect(JSON.parse(excessJson.stdout)).toEqual({
|
|
1174
|
+
ok: false,
|
|
1175
|
+
code: "usage",
|
|
1176
|
+
error:
|
|
1177
|
+
"too many arguments for 'single'. Expected 1 argument but got 2: scan, web. `akan single` takes [action]: see `akan single --help`.",
|
|
1178
|
+
});
|
|
1179
|
+
expect((await run("bare", "web")).stderr).toContain("`akan bare` takes no argument: see `akan bare --help`.");
|
|
1113
1180
|
}, 30_000);
|
|
1114
1181
|
});
|
|
1115
1182
|
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
|
|
3
|
-
import { type EnumChoice, getArgMetas } from "./argMeta";
|
|
3
|
+
import { type ArgMeta, type EnumChoice, getArgMetas, type InternalArgMeta } from "./argMeta";
|
|
4
4
|
import { camelToKebabCase } from "./camelToKebabCase";
|
|
5
5
|
import { type CommandCls, getTargetMetas } from "./targetMeta";
|
|
6
6
|
|
|
7
7
|
const formatChoice = (choice: EnumChoice) => (typeof choice === "object" ? choice.label : choice.toString());
|
|
8
8
|
|
|
9
|
+
const argumentNameOf = (arg: ArgMeta) => `${camelToKebabCase(arg.name)}${arg.argsOption.multiple ? "..." : ""}`;
|
|
10
|
+
|
|
11
|
+
export const usageArgsOf = (argMetas: (ArgMeta | InternalArgMeta)[]) =>
|
|
12
|
+
argMetas.flatMap((arg) => {
|
|
13
|
+
if (arg.type === "Option" || arg.type === "Workspace") return [];
|
|
14
|
+
if (arg.type === "Module") return ["[sys:module]"];
|
|
15
|
+
if (arg.type === "Apps") return ["[apps...]"];
|
|
16
|
+
if (arg.type === "Argument") return [`[${argumentNameOf(arg)}]`];
|
|
17
|
+
return [`[${arg.type.toLowerCase()}]`];
|
|
18
|
+
});
|
|
19
|
+
|
|
9
20
|
const groupCommands = (commands: CommandCls[]) => {
|
|
10
21
|
const groups = new Map<string, { key: string; args: string[]; desc?: string }[]>();
|
|
11
22
|
for (const command of commands) {
|
|
@@ -87,16 +98,7 @@ export const formatCommandHelp = (command: CommandCls, key: string) => {
|
|
|
87
98
|
const kebabKey = camelToKebabCase(key);
|
|
88
99
|
const commandDesc = getTargetMetas(command).find((t) => t.key === key)?.targetOption.desc;
|
|
89
100
|
const nonOptionArgs = allArgMetas.filter((arg) => arg.type !== "Option");
|
|
90
|
-
const args =
|
|
91
|
-
.map((arg) => {
|
|
92
|
-
if (arg.type === "Workspace") return "";
|
|
93
|
-
if (arg.type === "Module") return "[sys:module]";
|
|
94
|
-
if (arg.type === "Apps") return "[apps...]";
|
|
95
|
-
if (arg.type === "Argument") return `[${camelToKebabCase(arg.name)}]`;
|
|
96
|
-
return `[${arg.type.toLowerCase()}]`;
|
|
97
|
-
})
|
|
98
|
-
.filter(Boolean)
|
|
99
|
-
.join(" ");
|
|
101
|
+
const args = usageArgsOf(allArgMetas).join(" ");
|
|
100
102
|
|
|
101
103
|
const lines = ["", chalk.bold.cyan(` Command: ${kebabKey}`)];
|
|
102
104
|
if (commandDesc) lines.push(chalk.gray(` ${commandDesc}`));
|
|
@@ -115,7 +117,7 @@ export const formatCommandHelp = (command: CommandCls, key: string) => {
|
|
|
115
117
|
let argDesc: string;
|
|
116
118
|
let example = "";
|
|
117
119
|
if (arg.type === "Argument") {
|
|
118
|
-
argName =
|
|
120
|
+
argName = argumentNameOf(arg);
|
|
119
121
|
argDesc = arg.argsOption.desc ?? "";
|
|
120
122
|
example = arg.argsOption.example ? chalk.gray(` (e.g., ${String(arg.argsOption.example)})`) : "";
|
|
121
123
|
} else if (arg.type === "Module") {
|
package/context/akanContext.ts
CHANGED
|
@@ -272,8 +272,10 @@ const generatedFiles = [
|
|
|
272
272
|
"*/lib/sig.ts",
|
|
273
273
|
"*/lib/srv.ts",
|
|
274
274
|
"*/lib/st.ts",
|
|
275
|
+
"*/lib/usePage.ts",
|
|
275
276
|
"*/lib/useClient.ts",
|
|
276
277
|
"*/lib/useServer.ts",
|
|
278
|
+
"*/lib/__client/*.ts",
|
|
277
279
|
"*/lib/**/index.ts",
|
|
278
280
|
"*/ui/index.ts",
|
|
279
281
|
"*/webkit/index.ts",
|
|
@@ -360,7 +360,7 @@ describe.skipIf(!enabled)("dev HMR latency (minimal)", () => {
|
|
|
360
360
|
report.consecutive = {
|
|
361
361
|
latencies,
|
|
362
362
|
median: median(latencies),
|
|
363
|
-
shown: Object.keys(seen).sort(),
|
|
363
|
+
shown: Object.keys(seen).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)),
|
|
364
364
|
settledAfterLastSave: (seen.c9 ?? 0) - (writtenAt.at(-1) ?? 0),
|
|
365
365
|
};
|
|
366
366
|
expect(await harness().reloaded()).toBe(false);
|
|
@@ -28,6 +28,15 @@ describe("ApiReference", () => {
|
|
|
28
28
|
expect(rendered).toMatch(/^\/\*\* .+ \*\/\nserverMode\?: "batch" \| "federation";$/m);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
+
test("says what each listed subpath holds, and lists only subpaths the package exports", async () => {
|
|
32
|
+
const exports = Object.keys((await Bun.file(path.join(akanjsDir, "package.json")).json()).exports);
|
|
33
|
+
const listed = [...rendered.matchAll(/^- `akanjs\/([^`]+)` — .+\.$/gm)].map(([, subpath]) => `./${subpath}`);
|
|
34
|
+
expect(listed).toEqual(
|
|
35
|
+
["dictionary", "document", "service", "store", "client/native", "native/desktop", "test"].map((s) => `./${s}`),
|
|
36
|
+
);
|
|
37
|
+
for (const subpath of listed) expect(exports).toContain(subpath);
|
|
38
|
+
});
|
|
39
|
+
|
|
31
40
|
test("says what Link takes beyond its own props, and names its static parts", () => {
|
|
32
41
|
expect(rendered).toContain('Every prop of `Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href">`, and:');
|
|
33
42
|
expect(rendered).toMatch(/^Link\.Back\(.+\): Element$/m);
|
package/docs/apiReference.ts
CHANGED
|
@@ -39,6 +39,7 @@ const sections: Section[] = [
|
|
|
39
39
|
"replace",
|
|
40
40
|
"back",
|
|
41
41
|
"backOrFallback",
|
|
42
|
+
"backOrReplace",
|
|
42
43
|
"refresh",
|
|
43
44
|
"redirect",
|
|
44
45
|
"notFound",
|
|
@@ -118,6 +119,16 @@ const conventionImports = [
|
|
|
118
119
|
'import { signedIn } from "@libs/shared/webkit"; // a workspace created with --libs true',
|
|
119
120
|
];
|
|
120
121
|
|
|
122
|
+
const subpathPurposes = [
|
|
123
|
+
["akanjs/dictionary", "locales, translations and the dictionaries behind labels, descriptions and `Err` keys"],
|
|
124
|
+
["akanjs/document", "database documents, filters, query builders, full-text search and persistence"],
|
|
125
|
+
["akanjs/service", "services, adapters, dependency injection and the business-logic runtime"],
|
|
126
|
+
["akanjs/store", "domain state, actions and the in-page agent's `st.tool` / `st.use` surface"],
|
|
127
|
+
["akanjs/client/native", "the native bridge and the built-in plugins of iOS, Android and desktop apps"],
|
|
128
|
+
["akanjs/native/desktop", "what an app's or a lib's own native plugin builds its desktop part from"],
|
|
129
|
+
["akanjs/test", "signal-test setup, MCP catalogue checks and sample data (`sampleOf`)"],
|
|
130
|
+
] as const;
|
|
131
|
+
|
|
121
132
|
const routeInternals = ["assertPattern", "resolveArgs", "toRouteModule"];
|
|
122
133
|
|
|
123
134
|
export class ApiReference {
|
|
@@ -160,6 +171,10 @@ export class ApiReference {
|
|
|
160
171
|
...conventionImports,
|
|
161
172
|
"```",
|
|
162
173
|
"",
|
|
174
|
+
"What these subpaths hold:",
|
|
175
|
+
"",
|
|
176
|
+
...subpathPurposes.map(([from, purpose]) => `- \`${from}\` — ${purpose}.`),
|
|
177
|
+
"",
|
|
163
178
|
...body,
|
|
164
179
|
]
|
|
165
180
|
.join("\n")
|